package com.njcn.supervision.controller.survey;

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.survey.SupervisionGeneralSurveyPlanParm;
import com.njcn.supervision.pojo.vo.survey.DeptSubstationVO;
import com.njcn.supervision.pojo.vo.survey.SupervisionGeneralSurveyPlanDetailVO;
import com.njcn.supervision.pojo.vo.survey.SupervisionGeneralSurveyPlanVO;
import com.njcn.supervision.service.survey.SupervisionGeneralSurveyPlanPOService;
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("/generalSurvey")
@Api(tags = "谐波普测计划")
@AllArgsConstructor
@Deprecated
public class GeneralSurveyController extends BaseController {

    private final SupervisionGeneralSurveyPlanPOService supervisionGeneralSurveyPlanPOService;

    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType= OperateType.ADD)
    @PostMapping("/addSurvey")
    @ApiOperation("新增普测计划")
    @ApiImplicitParam(name = "supervisionGeneralSurveyPlanParm", value = "实体参数", required = true)
    public HttpResult<String> addSurvey(@RequestBody @Validated SupervisionGeneralSurveyPlanParm supervisionGeneralSurveyPlanParm){
        String methodDescribe = getMethodDescribe("addSurvey");
        String planNo = supervisionGeneralSurveyPlanPOService.addDevReport(supervisionGeneralSurveyPlanParm);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, planNo, methodDescribe);

    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON,operateType= OperateType.ADD)
    @PostMapping("/auditSurvey")
    @ApiOperation("修改普测计划")
    @ApiImplicitParam(name = "supervisionGeneralSurveyPlanUpdate", value = "实体参数", required = true)
    public HttpResult<Boolean> auditSurvey(@RequestBody @Validated SupervisionGeneralSurveyPlanParm.SupervisionGeneralSurveyPlanUpdate supervisionGeneralSurveyPlanUpdate){
        String methodDescribe = getMethodDescribe("auditDevReport");
        boolean res = supervisionGeneralSurveyPlanPOService.auditSurvey(supervisionGeneralSurveyPlanUpdate);

        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);

    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/removeSurvey")
    @ApiOperation("移除普测计划")
    public HttpResult<Boolean> removeSurvey(@RequestParam("ids") List<String> ids){
        String methodDescribe = getMethodDescribe("removeSurvey");
        Boolean flag = supervisionGeneralSurveyPlanPOService.removeSurvey(ids);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/getSurvey")
    @ApiOperation("分页查询当前用户能看到的普测计划")
    @ApiImplicitParam(name = "generalSurveyPlanQueryParam", value = "参数", required = true)
    public HttpResult<Page<SupervisionGeneralSurveyPlanVO>> getSurvey(@RequestBody @Validated SupervisionGeneralSurveyPlanParm.GeneralSurveyPlanQueryParam generalSurveyPlanQueryParam ){
        String methodDescribe = getMethodDescribe("getSurvey");
        Page<SupervisionGeneralSurveyPlanVO> out = supervisionGeneralSurveyPlanPOService.getSurvey(generalSurveyPlanQueryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, out, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/querySurveyDetail")
    @ApiOperation("查询普测计划详情")
    public HttpResult<SupervisionGeneralSurveyPlanVO> querySurveyDetail(@RequestParam("id") String id){
        String methodDescribe = getMethodDescribe("querySurveyDetail");
        SupervisionGeneralSurveyPlanVO vo = supervisionGeneralSurveyPlanPOService.querySurveyDetail(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, vo, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/initDetpStataionTree")
    @ApiOperation("初始化部门")
    @ApiImplicitParam(name = "orgId", value = "部门号", required = true)
    public HttpResult<List<DeptSubstationVO>> initDetpStataionTree(@RequestParam("orgId") String orgId) {
        String methodDescribe = getMethodDescribe("initDetpStataionTree");
        List<DeptSubstationVO> list = supervisionGeneralSurveyPlanPOService.initDetpStataionTree(orgId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
    }

    @GetMapping("/updateStatus")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("更改普测计划状态")
    public HttpResult<Object> updateStatus(String businessKey,Integer status) {
        String methodDescribe = getMethodDescribe("updateStatus");
        supervisionGeneralSurveyPlanPOService.updateProcessStatus(businessKey,status);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON, operateType = OperateType.DELETE)
    @PostMapping("/cancel")
    @ApiOperation("取消普测计划")
    @ApiImplicitParam(name = "cancelReqVO", value = "取消原因", required = true)
    public HttpResult<String> cancelGeneralSurvey(@Validated @RequestBody BpmProcessInstanceCancelParam cancelReqVO) {
        String methodDescribe = getMethodDescribe("cancelGeneralSurvey");
        String id = supervisionGeneralSurveyPlanPOService.cancelGeneralSurvey(cancelReqVO);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, id, methodDescribe);
    }


    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @PostMapping("/pageProblemSubstationBySurvey")
    @ApiOperation("分页查询当前用户能看到的普测计划中存在超标问题")
    @ApiImplicitParam(name = "generalSurveyPlanQueryParam", value = "参数", required = true)
    public HttpResult<Page<SupervisionGeneralSurveyPlanDetailVO>> getPageProblemSubstationBySurvey(@RequestBody @Validated SupervisionGeneralSurveyPlanParm.GeneralSurveyPlanQueryParam generalSurveyPlanQueryParam ){
        String methodDescribe = getMethodDescribe("pageProblemSubstationBySurvey");
        Page<SupervisionGeneralSurveyPlanDetailVO> out = supervisionGeneralSurveyPlanPOService.pageProblemSubstationBySurvey(generalSurveyPlanQueryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, out, methodDescribe);
    }

    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @GetMapping("/initiateWarningLeaflet")
    @ApiOperation("针对有问题的现场测试发起告警单")
    public HttpResult<Boolean> initiateWarningLeaflet(@RequestParam("id") String id,@RequestParam("subId") String subId){
        String methodDescribe = getMethodDescribe("initiateWarningLeaflet");
        supervisionGeneralSurveyPlanPOService.initiateWarningLeaflet(id,subId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, Boolean.TRUE, methodDescribe);
    }



}
