package com.njcn.supervision.controller.device;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.bpm.pojo.param.instance.BpmProcessInstanceCancelParam;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.supervision.pojo.param.device.CheckDeviceParam;
import com.njcn.supervision.pojo.vo.device.CheckDeviceVo;
import com.njcn.supervision.service.device.ICheckDeviceService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 终端周期检测表 前端控制器
 * </p>
 *
 * @author xy
 * @since 2024-06-13
 */
@Slf4j
@RestController
@RequestMapping("/checkDevice")
@Api(tags = "终端周期检测")
@AllArgsConstructor
public class CheckDeviceController extends BaseController {

    private final ICheckDeviceService checkDeviceService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/add")
    @ApiOperation("新增需要检测的终端表")
    public HttpResult<String> add() {
        String methodDescribe = getMethodDescribe("add");
        checkDeviceService.addCheckDevice();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/list")
    @ApiOperation("分页查询当前用户需要检测的终端表")
    @ApiImplicitParam(name = "param", value = "参数", required = true)
    public HttpResult<Page<CheckDeviceVo>> checkDeviceList(@RequestBody @Validated CheckDeviceParam param) {
        String methodDescribe = getMethodDescribe("checkDeviceList");
        Page<CheckDeviceVo> list = checkDeviceService.getCheckDeviceList(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getInfoById")
    @ApiOperation("根据id查询详情")
    @ApiImplicitParam(name = "id", value = "参数", required = true)
    public HttpResult<CheckDeviceVo> getInfoById(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getInfoById");
        CheckDeviceVo vo = checkDeviceService.getInfoById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, vo, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/submit")
    @ApiOperation("提交检测报告")
    public HttpResult<String> submit(@RequestBody @Validated CheckDeviceParam param) {
        String methodDescribe = getMethodDescribe("submit");
        checkDeviceService.submitReport(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/reload")
    @ApiOperation("重新发起")
    public HttpResult<String> reload(@RequestBody @Validated CheckDeviceParam param) {
        String methodDescribe = getMethodDescribe("reload");
        checkDeviceService.reloadReport(param);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @PostMapping("/cancel")
    @ApiOperation("取消流程")
    @ApiImplicitParam(name = "cancelReqVO", value = "取消原因", required = true)
    public HttpResult<String> cancel(@Validated @RequestBody BpmProcessInstanceCancelParam cancelReqVO) {
        String methodDescribe = getMethodDescribe("cancel");
        String result = checkDeviceService.cancel(cancelReqVO);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

}

