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.SupervisionTempLineReportParam;
import com.njcn.supervision.pojo.vo.device.SupervisionTempLineReportVO;
import com.njcn.supervision.service.device.SupervisionTempLineReportService;
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 springfox.documentation.annotations.ApiIgnore;

import java.util.List;

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


    private final SupervisionTempLineReportService supervisionTempLineReportService;

    /**
     * 监测点新增
     * @param supervisionTempLineReportParam 参数
     */
    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType= OperateType.ADD)
    @PostMapping("/add")
    @ApiOperation("新增临时监测点管理")
    @ApiImplicitParam(name = "supervisionTempLineReportParam", value = "实体参数", required = true)
    public HttpResult<String> addTempLineReport(@RequestBody @Validated SupervisionTempLineReportParam supervisionTempLineReportParam){
        String methodDescribe = getMethodDescribe("addTempLineReport");
        String tempLineId = supervisionTempLineReportService.addTempLineReport(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> updateLineReport(@RequestBody @Validated SupervisionTempLineReportParam.SupervisionTempLineReportUpdate supervisionTempLineReportParam){
        String methodDescribe = getMethodDescribe("updateLineReport");
        String devReportId = supervisionTempLineReportService.updateLineReport(supervisionTempLineReportParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, devReportId, methodDescribe);

    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/list")
    @ApiOperation("分页查询当前用户能看到的接入监测装置设备")
    @ApiImplicitParam(name = "supervisionTempLineReportQuery", value = "参数", required = true)
    public HttpResult<Page<SupervisionTempLineReportVO>> getTempLineReport(@RequestBody @Validated SupervisionTempLineReportParam.SupervisionTempLineReportQuery supervisionTempLineReportQuery) {
        String methodDescribe = getMethodDescribe("getTempLineReport");
        Page<SupervisionTempLineReportVO> out = supervisionTempLineReportService.getTempLineReport(supervisionTempLineReportQuery);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, out, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getDetail")
    @ApiOperation("查询详情")
    public HttpResult<SupervisionTempLineReportVO> getDetailTempLine(@RequestParam("id") String id) {
        String methodDescribe = getMethodDescribe("getDetailTempLine");
        SupervisionTempLineReportVO out = supervisionTempLineReportService.getDetailTempLine(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, out, methodDescribe);
    }

    @ApiIgnore
    @GetMapping("/updateStatus")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("更改表单状态")
    public HttpResult<Object> updateStatus(String businessKey,Integer status) {
        String methodDescribe = getMethodDescribe("updateStatus");
        supervisionTempLineReportService.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 = supervisionTempLineReportService.cancelTempLineReport(cancelReqVO);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, id, methodDescribe);
    }

    @PostMapping(value = "/deleteTempLineReport")
    @ApiOperation("监测点台账录入删除流程")
    @OperateInfo(info = LogEnum.BUSINESS_MEDIUM, operateType = OperateType.DELETE)
    public HttpResult<Boolean> deleteTempLineReport(@RequestBody List<String> supervisionId) {
        String methodDescribe = getMethodDescribe("deleteDevReport");
        Boolean b = supervisionTempLineReportService.deleteTempLineReport(supervisionId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, b, methodDescribe);
    }
}
