package com.njcn.supervision.controller.leaflet;


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.vo.leaflet.WarningLeafletVO;
import com.njcn.harmonic.pojo.dto.RMpPartHarmonicDetailDTO;
import com.njcn.supervision.pojo.param.leaflet.WarningLeafletParam;
import com.njcn.supervision.service.leaflet.IWarningLeafletService;
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 org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 预告警单表 前端控制器
 * </p>
 *
 * @author hongawen
 * @since 2024-05-21
 */
@RestController
@RequestMapping("/warningLeaflet")
@Slf4j
@Api(tags = "预告警单表")
@AllArgsConstructor
public class WarningLeafletController extends BaseController {

    private final IWarningLeafletService warningLeafletService;


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/warningPageData")
    @ApiOperation("分页查询当前用户能看到的预警单数据")
    @ApiImplicitParam(name = "warningLeafletQueryParam", value = "参数", required = true)
    public HttpResult<Page<WarningLeafletVO>> warningPageData(@RequestBody @Validated WarningLeafletParam.WarningLeafletQueryParam warningLeafletQueryParam) {
        String methodDescribe = getMethodDescribe("warningPageData");
        Page<WarningLeafletVO> out = warningLeafletService.warningPageData(warningLeafletQueryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, out, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/alarmPageData")
    @ApiOperation("分页查询当前用户能看到的告警单数据")
    @ApiImplicitParam(name = "warningLeafletQueryParam", value = "参数", required = true)
    public HttpResult<Page<WarningLeafletVO>> alarmPageData(@RequestBody @Validated WarningLeafletParam.WarningLeafletQueryParam warningLeafletQueryParam) {
        String methodDescribe = getMethodDescribe("alarmPageData");
        Page<WarningLeafletVO> out = warningLeafletService.alarmPageData(warningLeafletQueryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, out, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/allPageData")
    @ApiOperation("分页查询告警单全部数据")
    @ApiImplicitParam(name = "warningLeafletQueryParam", value = "参数", required = true)
    public HttpResult<Page<WarningLeafletVO>> allPageData(@RequestBody @Validated WarningLeafletParam.WarningLeafletQueryParam warningLeafletQueryParam) {
        String methodDescribe = getMethodDescribe("alarmPageData");
        Page<WarningLeafletVO> out = warningLeafletService.allPageData(warningLeafletQueryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, out, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/addLineOverLimitData")
    @ApiOperation("监测点超标预警单/告警单新增")
    @ApiImplicitParam(name = "rMpPartHarmonicDetailDTO", value = "参数", required = true)
    public HttpResult<String> addLineOverLimitData(@RequestBody @Validated RMpPartHarmonicDetailDTO rMpPartHarmonicDetailDTO) {
        String methodDescribe = getMethodDescribe("addLineOverLimitData");
        String out = warningLeafletService.addLineOverLimitData(rMpPartHarmonicDetailDTO);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, out, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.ADD)
    @PostMapping("/addFeedback")
    @ApiOperation("上传反馈单")
    @ApiImplicitParam(name = "warningLeafletUpdateParam", value = "实体参数", required = true)
    public HttpResult<Object> addFeedback(@RequestBody @Validated WarningLeafletParam.WarningLeafletUpdateParam warningLeafletUpdateParam) {
        String methodDescribe = getMethodDescribe("addFeedback");
        warningLeafletService.addFeedback(warningLeafletUpdateParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.UPDATE)
    @PostMapping("/update")
    @ApiOperation("重新发起反馈单申请")
    @ApiImplicitParam(name = "warningLeafletUpdateParam", value = "实体参数", required = true)
    public HttpResult<Object> updateFeedback(@RequestBody @Validated WarningLeafletParam.WarningLeafletUpdateParam warningLeafletUpdateParam) {
        String methodDescribe = getMethodDescribe("updateFeedback");
        warningLeafletService.updateFeedback(warningLeafletUpdateParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @GetMapping("/getById")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("根据id获取预告警单的详细数据")
    public HttpResult<WarningLeafletVO> getById(String id) {
        String methodDescribe = getMethodDescribe("getById");
        WarningLeafletVO warningLeafletVO = warningLeafletService.getVOById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, warningLeafletVO, methodDescribe);
    }

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

    @PostMapping(value = "/deleteWarningLeaflet")
    @ApiOperation("预告警单删除流程")
    @OperateInfo(info = LogEnum.BUSINESS_MEDIUM, operateType = OperateType.DELETE)
    public HttpResult<Boolean> deleteWarningLeaflet(@RequestBody List<String> supervisionId) {
        String methodDescribe = getMethodDescribe("deleteWarningLeaflet");
        Boolean b = warningLeafletService.deleteWarningLeaflet(supervisionId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, b, methodDescribe);
    }

}

