package com.ruoyi.web.v2.controller;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.v2.model.JsInstrumentMaintenance;
import com.ruoyi.web.v2.service.IJsInstrumentMaintenanceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.Map;

import static com.ruoyi.common.core.domain.AjaxResult.success;
import static com.ruoyi.common.utils.SecurityUtils.getUsername;

/**
 * <p>
 * v2.0检验仪器维护登记 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-05-23
 */
@RestController
@RequestMapping("/js-instrument-maintenance")
@Api("2.0检验仪器维护登记")
public class JsInstrumentMaintenanceController {

    @Autowired
    private IJsInstrumentMaintenanceService maintenanceService;


    @ApiOperation("检验仪器维护登记添加")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody JsInstrumentMaintenance deviceMaintenance) {
        deviceMaintenance.setCreateBy(getUsername());
        deviceMaintenance.setCreateTime(LocalDateTime.now());
        deviceMaintenance.setUpdateBy(getUsername());
        deviceMaintenance.setUpdateTime(LocalDateTime.now());
        return maintenanceService.add(deviceMaintenance);
    }

    @ApiOperation("检验仪器维护登记修改")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody JsInstrumentMaintenance deviceMaintenance) {
        deviceMaintenance.setUpdateBy(getUsername());
        deviceMaintenance.setUpdateTime(LocalDateTime.now());
        return maintenanceService.edit(deviceMaintenance);
    }

    @ApiOperation("检验仪器维护登记删除")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody Map<String, String> paramsMap) {
        String ids = paramsMap.get("ids");
        return maintenanceService.delete(ids);
    }

    @ApiOperation("检验仪器维护登记列表")
    @PostMapping("/list")
    public AjaxResult listAll() {
        return maintenanceService.listAll();
    }

    @ApiOperation("检验仪器维护登记分页")
    @GetMapping("/page")
    public AjaxResult page(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize
            , @RequestParam(value = "startTime", required = false) String startTime
            , @RequestParam(value = "endTime", required = false) String endTime
            , @RequestParam(value = "deviceNum", required = false) String deviceNum
            , @RequestParam(value = "deviceName", required = false) String deviceName) {

        return maintenanceService.page(pageNum, pageSize, startTime, endTime, deviceNum,deviceName);
    }

    @ApiOperation("检验仪器维护登记详情")
    @PostMapping("/listById")
    public AjaxResult listById(@RequestBody Map<String, String> paramsMap) {
        String id = paramsMap.get("id");
        return success(maintenanceService.getById(id));
    }
}
