package com.njcn.supervision.controller.device;


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.SupervisionTempLineRunTestParam;
import com.njcn.supervision.pojo.vo.device.SupervisionTempLineRunTestVO;
import com.njcn.supervision.service.device.ISupervisionTempLineRunTestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.njcn.web.controller.BaseController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 *  监测点试运行前端控制器
 * </p>
 *
 * @author cdf
 * @since 2024-05-21
 */
@RestController
@RequestMapping("/supervisionTempLineRunTest")
@RequiredArgsConstructor
@Api(tags = "监测点联调后的试运行")
public class SupervisionTempLineRunTestController extends BaseController {

    private final ISupervisionTempLineRunTestService iSupervisionTempLineRunTestService;


    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType= OperateType.ADD)
    @PostMapping("/add")
    @ApiOperation("新增监测点试运行")
    @ApiImplicitParam(name = "supervisionTempLineRunTestParam", value = "实体参数", required = true)
    public HttpResult<Object> addRunTest(@RequestBody @Validated SupervisionTempLineRunTestParam supervisionTempLineRunTestParam){
        String methodDescribe = getMethodDescribe("addTempLineReport");
        iSupervisionTempLineRunTestService.addRunTest(supervisionTempLineRunTestParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType= OperateType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("重新发送监测点试运行")
    @ApiImplicitParam(name = "supervisionTempLineRunTestParam", value = "实体参数", required = true)
    public HttpResult<Object> updateRunTest(@RequestBody @Validated SupervisionTempLineRunTestParam.SupervisionTempLineRunTestUpdateParam supervisionTempLineRunTestParam){
        String methodDescribe = getMethodDescribe("updateRunTest");
        iSupervisionTempLineRunTestService.updateRunTest(supervisionTempLineRunTestParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }

    /**
     * 判断是否已经开始试运行，或者试运行结束
     * @author cdf
     * @date 2024/5/22
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/isTestRunStartOrEnd")
    @ApiOperation("每日判断试运行是否结束")
    public void isTestRunStartOrEnd(HttpServletResponse response){
        iSupervisionTempLineRunTestService.isTestRunStartOrEnd(response);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType = OperateType.UPDATE)
    @GetMapping("/updateStatus")
    @ApiOperation("修改业务审核状态")
    public HttpResult<Object> updateStatus(@RequestParam("businessKey") String businessKey, @RequestParam("status")Integer status){
        String methodDescribe = getMethodDescribe("updateLineRunTestStatus");
        iSupervisionTempLineRunTestService.updateProcessStatus(businessKey,null,status);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/getRunTestById")
    @ApiOperation("查询试运行详情")
    public HttpResult<SupervisionTempLineRunTestVO> getRunTestById(@RequestParam("id") String id){
        String methodDescribe = getMethodDescribe("getRunTestById");
        SupervisionTempLineRunTestVO supervisionTempLineRunTestVO = iSupervisionTempLineRunTestService.getRunTestById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, supervisionTempLineRunTestVO, 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 id = iSupervisionTempLineRunTestService.cancel(cancelReqVO);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, id, methodDescribe);
    }

    @PostMapping(value = "/deleteTempLineRunTestReport")
    @ApiOperation("试运行评估删除流程")
    @OperateInfo(info = LogEnum.BUSINESS_MEDIUM, operateType = OperateType.DELETE)
    public HttpResult<Boolean> deleteTempLineRunTestReport(@RequestBody List<String> supervisionId) {
        String methodDescribe = getMethodDescribe("deleteTempLineRunTestReport");
        Boolean b = iSupervisionTempLineRunTestService.deleteTempLineRunTestReport(supervisionId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, b, methodDescribe);
    }
}

