package com.njcn.supervision.controller.plan;

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.plan.SupervisionPlanParam;
import com.njcn.supervision.pojo.vo.plan.SupervisionPlanVO;
import com.njcn.supervision.service.plan.SupervisionPlanPOService;
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.*;

/**
 * 干扰源用户管理
 *
 * @author qijian
 * @version 1.0.0
 * @createTime 2022/11/11 - 9:20
 */
@Slf4j
@RestController
@RequestMapping("/superPlan")
@Api(tags = "技术监督计划")
@AllArgsConstructor
public class SupervisionPlanController extends BaseController {


    private final SupervisionPlanPOService supervisionPlanPOService;

    @PostMapping("addPlan")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @ApiOperation("新增技术监督计划")
    @ApiImplicitParam(name = "supvPlanParam", value = "请求体", required = true)
    public HttpResult<Object> addPlan(@RequestBody @Validated SupervisionPlanParam supvPlanParam) {
        String methodDescribe = getMethodDescribe("addPlan");
        String id = supervisionPlanPOService.addPlan(supvPlanParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, id, methodDescribe);
    }


    @PostMapping("update")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
    @ApiOperation("新增技术监督计划")
    @ApiImplicitParam(name = "supvPlanParam", value = "请求体", required = true)
    public HttpResult<Object> updatePlan(@RequestBody @Validated SupervisionPlanParam.UpdateSupvPlanParam supvPlanParam) {
        String methodDescribe = getMethodDescribe("updatePlan");
        String id = supervisionPlanPOService.updatePlan(supvPlanParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, id, methodDescribe);
    }


    @PostMapping("pagePlan")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("分页查询监督计划")
    @ApiImplicitParam(name = "supvPlanParam", value = "请求体", required = true)
    public HttpResult<Page<SupervisionPlanVO>> pagePlan(@RequestBody SupervisionPlanParam supvPlanParam) {
        String methodDescribe = getMethodDescribe("pagePlan");
        Page<SupervisionPlanVO> page = supervisionPlanPOService.pagePlan(supvPlanParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, page, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/initiateAudit")
    @ApiOperation("发起审核")
    public HttpResult<String> initiateAudit(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("initiateAudit");
        String processId = supervisionPlanPOService.initiateAudit(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, processId, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getDetail")
    @ApiOperation("查询详情")
    public HttpResult<SupervisionPlanVO> getDetailPlan(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getDetailPlan");
        SupervisionPlanVO out = supervisionPlanPOService.getDetailPlan(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");
        supervisionPlanPOService.updateProcessStatus(businessKey, status);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @Deprecated
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/initiateWarningLeaflet")
    @ApiOperation("针对技术监督问题发起告警单")
    public HttpResult<Boolean> initiateWarningLeaflet(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("initiateWarningLeaflet");
        supervisionPlanPOService.initiateWarningLeaflet(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, Boolean.TRUE, methodDescribe);
    }

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

}
