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.SupervisionTempLineDebugParam;
import com.njcn.supervision.pojo.vo.device.SupervisionTempLineDebugVO;
import com.njcn.supervision.service.device.SupervisionTempLineDebugPOService;
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.*;

import java.util.List;

/**
 * 干扰源用户管理
 *
 * @author qijian
 * @version 1.0.0
 * @createTime 2022/11/11 - 9:20
 */
@Slf4j
@RestController
@RequestMapping("/tempLinedebug")
@Api(tags = "临时监测点调试管理")
@AllArgsConstructor
public class TempLineDebugController extends BaseController {


    private final SupervisionTempLineDebugPOService supervisionTempLineDebugPOService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType= OperateType.ADD)
    @PostMapping("/add")
    @ApiOperation("新增临时监测点调试管理")
    @ApiImplicitParam(name = "supervisionTempLineReportParam", value = "实体参数", required = true)
    public HttpResult<String> addTempLineDebug(@RequestBody @Validated SupervisionTempLineDebugParam supervisionTempLineReportParam){
        String methodDescribe = getMethodDescribe("addTempLineDebug");
        String tempLineId = supervisionTempLineDebugPOService.addTempLineDebug(supervisionTempLineReportParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, tempLineId, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType= OperateType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("新增临时监测点调试管理")
    @ApiImplicitParam(name = "supervisionTempLineReportParam", value = "实体参数", required = true)
    public HttpResult<String> updateTempLineDebug(@RequestBody @Validated SupervisionTempLineDebugParam.SupervisionTempLineDebugUpdateParam supervisionTempLineReportParam){
        String methodDescribe = getMethodDescribe("updateTempLineDebug");
        String tempLineId = supervisionTempLineDebugPOService.updateTempLineDebug(supervisionTempLineReportParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, tempLineId, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/list")
    @ApiOperation("查询联调监测点")
    @ApiImplicitParam(name = "supervisionTempLineDebugQuery", value = "参数", required = true)
    public HttpResult<Page<SupervisionTempLineDebugVO>> getTempLineDeug(@RequestBody @Validated SupervisionTempLineDebugParam.SupervisionTempLineDebugQuery supervisionTempLineDebugQuery) {
        String methodDescribe = getMethodDescribe("getTempLineDeug");
        Page<SupervisionTempLineDebugVO> out = supervisionTempLineDebugPOService.getTempLineDeug(supervisionTempLineDebugQuery);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, out, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/pageHasDebug")
    @ApiOperation("查询已完成联调监测点")
    @ApiImplicitParam(name = "supervisionTempLineDebugQuery", value = "参数", required = true)
    public HttpResult<Page<SupervisionTempLineDebugVO>> pageHasDebug(@RequestBody @Validated SupervisionTempLineDebugParam.SupervisionTempLineDebugQuery supervisionTempLineDebugQuery) {
        String methodDescribe = getMethodDescribe("pageHasDebug");
        Page<SupervisionTempLineDebugVO> out = supervisionTempLineDebugPOService.pageHasDebug(supervisionTempLineDebugQuery);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, out, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getDetail")
    @ApiOperation("查询详情")
    public HttpResult<SupervisionTempLineDebugVO> getDetailTempLine(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getDetailTempLine");
        SupervisionTempLineDebugVO out = supervisionTempLineDebugPOService.getDetailTempLineDebug(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, out, methodDescribe);
    }
    @GetMapping("/updateStatus")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("更改表单状态")
    public HttpResult<Object> updateStatus(String businessKey,Integer status) {
        String methodDescribe = getMethodDescribe("updateStatus");
        supervisionTempLineDebugPOService.updateProcessStatus(businessKey,status);
        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> cancelTempLineReport(@Validated @RequestBody BpmProcessInstanceCancelParam cancelReqVO) {
        String methodDescribe = getMethodDescribe("cancelTempLineReport");
        String id = supervisionTempLineDebugPOService.cancel(cancelReqVO);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, id, methodDescribe);
    }
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/ledgerSync")
    @ApiOperation("台账同步")
    public HttpResult<String> ledgerSync(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("ledgerSync");
        String out = supervisionTempLineDebugPOService.ledgerSync(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, out, methodDescribe);
    }

    @PostMapping(value = "/deleteTempLineDebugReport")
    @ApiOperation("监测点联调列表删除流程")
    @OperateInfo(info = LogEnum.BUSINESS_MEDIUM, operateType = OperateType.DELETE)
    public HttpResult<Boolean> deleteTempLineDebugReport(@RequestBody List<String> supervisionId) {
        String methodDescribe = getMethodDescribe("deleteTempLineDebugReport");
        Boolean b = supervisionTempLineDebugPOService.deleteTempLineDebugReport(supervisionId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, b, methodDescribe);
    }

}
