/*
 * Author: Zev
 * 生成controller
 */
package com.tofly.gpsboot.controller.audit;

import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.common.oauth.util.SecurityUtils;
import com.tofly.gpsboot.common.system.*;
import com.tofly.gpsboot.handler.plan.PlanTimeoutRemindHandler;
import com.tofly.gpsboot.handler.plan.RepairOrderTimeOutHandler;
import com.tofly.gpsboot.handler.plan.RepairOrderTimeOutRemindHandler;
import com.tofly.gpsboot.service.mq.IReportMessageService;
import com.tofly.pojo.plan.dto.ReportAuditDto;
import com.tofly.pojo.plan.vo.AuditInfoAllVo;
import com.tofly.pojo.plan.vo.CheckhistoryVo;
import com.tofly.gpsboot.exception.BusinessException;
import com.tofly.gpsboot.service.build.BuildService;
import com.tofly.gpsboot.service.build.BulidclearService;
import com.tofly.gpsboot.service.comm.IAuditService;
import com.tofly.gpsboot.service.maintain.RepairorderService;
import com.tofly.gpsboot.service.maintain.RepairplanService;
import com.tofly.gpsboot.service.maintain.RepairrecordService;
import com.tofly.gpsboot.service.paln.CheckhistoryService;
import com.tofly.gpsboot.service.paln.month.PlanmouthService;
import com.tofly.gpsboot.service.paln.task.PlanService;
import com.tofly.gpsboot.service.paln.task.PlancancleService;
import com.tofly.gpsboot.service.paln.task.PlanstopService;
import com.tofly.gpsboot.service.paln.year.PlanyearService;
import com.tofly.gpsboot.service.trouble.ToubleclearService;
import com.tofly.gpsboot.service.trouble.TroubleService;
import com.tofly.gpsboot.strategy.context.AuditStrategyContext;
import com.tofly.pojo.build.Build;
import com.tofly.pojo.build.Bulidclear;
import com.tofly.pojo.comm.Audit;
import com.tofly.pojo.maintain.Repairorder;
import com.tofly.pojo.plan.*;
import com.tofly.pojo.trouble.Toubleclear;
import com.tofly.pojo.trouble.Trouble;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


/**
 * 审核通用接口
 *
 * @author admin
 * @date Thu Mar 18 00:00:00 CST 2021
 */
@RestController
@RequestMapping("/audit")
@Api(tags = "审核接口")
@Slf4j
public class AuditController {
    @Autowired
    private AuditStrategyContext strategyContext;

    @Autowired
    private CheckhistoryService checkhistoryService;

    @Autowired
    private PlanyearService planyearService;

    @Autowired
    private PlanmouthService planmouthService;

    @Autowired
    private TroubleService troubleService;

    @Autowired
    private ToubleclearService toubleclearService;

    @Autowired
    private BuildService buildService;

    @Autowired
    private BulidclearService bulidclearService;

    @Autowired
    private PlanstopService planstopService;

    @Autowired
    private PlancancleService plancancleService;

    @Autowired
    private RepairorderService repairorderService;

    @Autowired
    private IAuditService iAuditService;
    @Autowired
    private IReportMessageService iReportMessageService;

    @ApiOperation(value = "审核处理")
    @PostMapping("/auditDispose")
    @ToFlyAppLog(title = "审核处理")
    public ResultRespone<Object> auditDispose(@RequestBody ReportAuditDto dto) {
        ResultRespone<Object> rest = new ResultRespone<>();
        try {
            strategyContext.audit(dto.getTemplateServiceType(), dto);
            return rest;
        } catch (BusinessException e) {
            rest.setCode(e.getRetCd());
            rest.setMessage(e.getMsgDes());
            return rest;
        }

    }

    @ApiOperation(value = "根据类型和id获取审核历史信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "类型，00年度巡检计划审核、01月度巡检计划审核、02隐患审核、03消除隐患审核、04工地监护审核、05工地监护取消审核、06巡检任务暂停审核、07巡检任务废除审核 08: 抢维修年计划审核 09:抢维修工单派工 10:抢维修工单处理审核 11抢维修月计划审核", required = true, dataType = "String"),
            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "String")
    })
    @GetMapping("/getAuditHis")
    @ToFlyAppLog(title = "根据类型和id获取审核历史信息")
    public ResultRespone<List<CheckhistoryVo>> getAuditHis(String type, String id) {
        ResultRespone<List<CheckhistoryVo>> rest = new ResultRespone<>();
        try {
            List<CheckhistoryVo> list = checkhistoryService.viewConversion(
                    checkhistoryService.list(new QueryWrapper<Checkhistory>().lambda().eq(Checkhistory::getType, type).eq(Checkhistory::getCheckId, Long.valueOf(id))));
            rest.setResult(list);
            return rest;
        } catch (BusinessException e) {
            rest.setCode(e.getRetCd());
            rest.setMessage(e.getMsgDes());
            return rest;
        }

    }

    @ApiOperation(value = "获取审核统计信息_不用该方法")
    @PostMapping("/getAuditInfoListOld")
    @ToFlyAppLog(title = "获取审核统计信息")
    public ResultRespone<List<AuditInfoAllVo>> getAuditInfoList_Old(String flag) {
        ResultRespone<List<AuditInfoAllVo>> rest = new ResultRespone<>();
        List<AuditInfoAllVo> allVoList = new ArrayList<>();
        try {
            Long userid = SecurityUtils.getUser().getUserid();
            String code = IsSubmitEnum.IS_SUBMIT_YES.getCode();
            String auditSubmitCode = IsAuditEnum.IS_AUDIT_SUBMIT.getCode();

            // 年计划
//            AuditInfoAllVo yearInfo = new AuditInfoAllVo();
//            yearInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_YEAR_PLAN.getCode());
//            yearInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_YEAR_PLAN.getValue());
//            yearInfo.setNumber(iAuditService.list(new QueryWrapper<Audit>().lambda().eq(Audit::getAuditType, AuditTypeEnum.AUDIT_TYPE_YEAR_PLAN.getCode()).eq(Audit::getAuditUser, userid).eq(Audit::getAuditState, AuditSateEnum.AUDIT_UNCOMMITTED.getCode())).size());
            // 月计划
            AuditInfoAllVo monthInfo = new AuditInfoAllVo();
            monthInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_MONTHLY_PLAN.getCode());
            monthInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_MONTHLY_PLAN.getValue());
            monthInfo.setNumber(iAuditService.list(new QueryWrapper<Audit>().lambda().eq(Audit::getAuditType, AuditTypeEnum.AUDIT_TYPE_MONTHLY_PLAN.getCode()).eq(Audit::getAuditUser, userid).eq(Audit::getAuditState, AuditSateEnum.AUDIT_UNCOMMITTED.getCode())).size());
            // 维护计划
//            AuditInfoAllVo mtInfo = new AuditInfoAllVo();
//            mtInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_PLAN_MT.getCode());
//            mtInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_PLAN_MT.getValue());
//            mtInfo.setNumber(iAuditService.list(new QueryWrapper<Audit>().lambda().eq(Audit::getAuditType, AuditTypeEnum.AUDIT_TYPE_PLAN_MT.getCode()).eq(Audit::getAuditUser, userid).eq(Audit::getAuditState, AuditSateEnum.AUDIT_UNCOMMITTED.getCode())).size());

            // 应急审核
            AuditInfoAllVo emInfo = new AuditInfoAllVo();
            emInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_EMERGENCY_DIS.getCode());
            emInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_EMERGENCY_DIS.getValue());
            emInfo.setNumber(iAuditService.list(new QueryWrapper<Audit>().lambda().eq(Audit::getAuditType, AuditTypeEnum.AUDIT_TYPE_EMERGENCY_DIS.getCode()).eq(Audit::getAuditUser, userid).eq(Audit::getAuditState, AuditSateEnum.AUDIT_UNCOMMITTED.getCode())).size());
            // 隐患
            AuditInfoAllVo troubleInfo = new AuditInfoAllVo();
            troubleInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_HIDDEN_TROUBLE.getCode());
            troubleInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_HIDDEN_TROUBLE.getValue());
            troubleInfo.setNumber(troubleService.list(new QueryWrapper<Trouble>().lambda().eq(Trouble::getIsSubmit, code).eq(Trouble::getAuditResult, auditSubmitCode).eq(Trouble::getAuditUser, userid)).size());
            // 隐患消除
            AuditInfoAllVo troubleClearInfo = new AuditInfoAllVo();
            troubleClearInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_HIDDEN_TROUBLE_ELIMINATION.getCode());
            troubleClearInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_HIDDEN_TROUBLE_ELIMINATION.getValue());
            troubleClearInfo.setNumber(toubleclearService.list(new QueryWrapper<Toubleclear>().lambda().eq(Toubleclear::getIsSubmit, code).eq(Toubleclear::getAuditResult, auditSubmitCode).eq(Toubleclear::getAuditUser, userid)).size());
            // 工地
            AuditInfoAllVo buildInfo = new AuditInfoAllVo();
            buildInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_CONSTRUCTION_SITE.getCode());
            buildInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_CONSTRUCTION_SITE.getValue());
            buildInfo.setNumber(buildService.list(new QueryWrapper<Build>().lambda().eq(Build::getIsSubmit, code).eq(Build::getAuditResult, auditSubmitCode).eq(Build::getAuditUser, userid)).size());
            // 工地监护消除
            AuditInfoAllVo buildClearInfo = new AuditInfoAllVo();
            buildClearInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_CONSTRUCTION_SITE_ELIMINATION.getCode());
            buildClearInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_CONSTRUCTION_SITE_ELIMINATION.getValue());
            buildClearInfo.setNumber(bulidclearService.list(new QueryWrapper<Bulidclear>().lambda().eq(Bulidclear::getIsSubmit, code).eq(Bulidclear::getAuditResult, auditSubmitCode).eq(Bulidclear::getAuditUser, userid)).size());
            // 任务暂停
            AuditInfoAllVo planStopInfo = new AuditInfoAllVo();
            planStopInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_PLAN_STOP.getCode());
            planStopInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_PLAN_STOP.getValue());
            planStopInfo.setNumber(planstopService.list(new QueryWrapper<Planstop>().lambda().eq(Planstop::getIsSubmit, code).eq(Planstop::getAuditResult, auditSubmitCode).eq(Planstop::getAuditUser, userid)).size());

            planStopInfo.setNumber(iAuditService.list(new QueryWrapper<Audit>().lambda().eq(Audit::getAuditType, AuditTypeEnum.AUDIT_TYPE_PLAN_STOP.getCode()).eq(Audit::getAuditUser, userid).eq(Audit::getAuditState, AuditSateEnum.AUDIT_UNCOMMITTED.getCode())).size());


            // 任务作废
            AuditInfoAllVo planDisuseInfo = new AuditInfoAllVo();
            planDisuseInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_PLAN_DISUSE.getCode());
            planDisuseInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_PLAN_DISUSE.getValue());
            planDisuseInfo.setNumber(plancancleService.list(new QueryWrapper<Plancancle>().lambda().eq(Plancancle::getIsSubmit, code).eq(Plancancle::getAuditResult, auditSubmitCode).eq(Plancancle::getAuditUser, userid)).size());
//            // 抢维修年计划
            AuditInfoAllVo repairPlanYearInfo = new AuditInfoAllVo();
            repairPlanYearInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_REPAIR_YEAR_PLAN.getCode());
            repairPlanYearInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_REPAIR_YEAR_PLAN.getValue());
            repairPlanYearInfo.setNumber(iAuditService.list(new QueryWrapper<Audit>().lambda().eq(Audit::getAuditType, AuditTypeEnum.AUDIT_TYPE_REPAIR_YEAR_PLAN.getCode()).eq(Audit::getAuditUser, userid).eq(Audit::getAuditState, AuditSateEnum.AUDIT_UNCOMMITTED.getCode())).size());
//            // 抢维修月计划
            AuditInfoAllVo repairPlanMonthInfo = new AuditInfoAllVo();
            repairPlanMonthInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_REPAIR_MONTH_PLAN.getCode());
           repairPlanMonthInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_REPAIR_MONTH_PLAN.getValue());
            repairPlanMonthInfo.setNumber(iAuditService.list(new QueryWrapper<Audit>().lambda().eq(Audit::getAuditType, AuditTypeEnum.AUDIT_TYPE_REPAIR_MONTH_PLAN.getCode()).eq(Audit::getAuditUser, userid).eq(Audit::getAuditState, AuditSateEnum.AUDIT_UNCOMMITTED.getCode())).size());
//            // 抢维修计划
            AuditInfoAllVo planOrderInfo = new AuditInfoAllVo();
           planOrderInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_REPAIR_PLAN.getCode());
            planOrderInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_REPAIR_PLAN.getValue());
           List<Repairorder> planList = repairorderService.list(new QueryWrapper<Repairorder>().lambda().eq(Repairorder::getDispatchingId, userid).eq(Repairorder::getState, OrderStateEnum.ORDER_STATE_NOT_WORK.getCode()));
           planOrderInfo.setNumber(planList.size());
            // 抢维修工单处理审核
            AuditInfoAllVo orderOverInfo = new AuditInfoAllVo();
            orderOverInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_REPAIR_RECORD.getCode());
            orderOverInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_REPAIR_RECORD.getValue());
            orderOverInfo.setNumber(iAuditService.list(new QueryWrapper<Audit>().lambda().eq(Audit::getAuditType, AuditTypeEnum.AUDIT_TYPE_REPAIR_RECORD.getCode()).eq(Audit::getAuditUser, userid).eq(Audit::getAuditState, AuditSateEnum.AUDIT_UNCOMMITTED.getCode())).size());
            if (StringUtils.isEmpty(flag)) {
//                allVoList.add(yearInfo);
                allVoList.add(monthInfo);
                allVoList.add(repairPlanYearInfo);
                allVoList.add(repairPlanMonthInfo);
            }
//            allVoList.add(mtInfo);
            //allVoList.add(emInfo);
            allVoList.add(troubleInfo);
            allVoList.add(troubleClearInfo);
            allVoList.add(buildInfo);
            allVoList.add(buildClearInfo);
            allVoList.add(planStopInfo);
            allVoList.add(planDisuseInfo);
           allVoList.add(planOrderInfo);
           allVoList.add(orderOverInfo);
            rest.setResult(allVoList);
            return rest;
        } catch (BusinessException e) {
            rest.setCode(e.getRetCd());
            rest.setMessage(e.getMsgDes());
            return rest;
        }

    }


    @ApiOperation(value = "获取审核统计信息")
    @PostMapping("/getAuditInfoList")
    @ToFlyAppLog(title = "获取审核统计信息,马边方法")
    public ResultRespone<List<AuditInfoAllVo>> getAuditInfoList(String flag) {
        ResultRespone<List<AuditInfoAllVo>> rest = new ResultRespone<>();
        List<AuditInfoAllVo> allVoList = new ArrayList<>();
        try {
            Long userid = SecurityUtils.getUser().getUserid();
            String code = IsSubmitEnum.IS_SUBMIT_YES.getCode();
            String auditSubmitCode = IsAuditEnum.IS_AUDIT_SUBMIT.getCode();

            // 年计划
          /*  AuditInfoAllVo yearInfo = new AuditInfoAllVo();
            yearInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_YEAR_PLAN.getCode());
            yearInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_YEAR_PLAN.getValue());
            yearInfo.setNumber(iAuditService.list(new QueryWrapper<Audit>().lambda().eq(Audit::getAuditType, AuditTypeEnum.AUDIT_TYPE_YEAR_PLAN.getCode()).eq(Audit::getAuditUser, userid).eq(Audit::getAuditState, AuditSateEnum.AUDIT_UNCOMMITTED.getCode())).size());
           */
            // 月计划
            AuditInfoAllVo monthInfo = new AuditInfoAllVo();
            monthInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_MONTHLY_PLAN.getCode());
            monthInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_MONTHLY_PLAN.getValue());
            monthInfo.setNumber(iAuditService.list(new QueryWrapper<Audit>().lambda().eq(Audit::getAuditType, AuditTypeEnum.AUDIT_TYPE_MONTHLY_PLAN.getCode()).eq(Audit::getAuditUser, userid).eq(Audit::getAuditState, AuditSateEnum.AUDIT_UNCOMMITTED.getCode())).size());

            // 隐患
            AuditInfoAllVo troubleInfo = new AuditInfoAllVo();
            troubleInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_HIDDEN_TROUBLE.getCode());
            troubleInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_HIDDEN_TROUBLE.getValue());
            troubleInfo.setNumber(troubleService.list(new QueryWrapper<Trouble>().lambda()
                    .eq(Trouble::getIsSubmit, code)
                    .eq(Trouble::getAuditResult, auditSubmitCode)
                    .eq(Trouble::getAuditUser, userid)).size());

            // 隐患消除
            AuditInfoAllVo troubleClearInfo = new AuditInfoAllVo();
            troubleClearInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_HIDDEN_TROUBLE_ELIMINATION.getCode());
            troubleClearInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_HIDDEN_TROUBLE_ELIMINATION.getValue());
            troubleClearInfo.setNumber(toubleclearService.list(new QueryWrapper<Toubleclear>().lambda().eq(Toubleclear::getIsSubmit, code).eq(Toubleclear::getAuditResult, auditSubmitCode).eq(Toubleclear::getAuditUser, userid)).size());
            // 工地
            AuditInfoAllVo buildInfo = new AuditInfoAllVo();
            buildInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_CONSTRUCTION_SITE.getCode());
            buildInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_CONSTRUCTION_SITE.getValue());
            buildInfo.setNumber(buildService.list(new QueryWrapper<Build>().lambda().eq(Build::getIsSubmit, code).eq(Build::getAuditResult, auditSubmitCode).eq(Build::getAuditUser, userid)).size());
            // 工地监护消除
            AuditInfoAllVo buildClearInfo = new AuditInfoAllVo();
            buildClearInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_CONSTRUCTION_SITE_ELIMINATION.getCode());
            buildClearInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_CONSTRUCTION_SITE_ELIMINATION.getValue());
            buildClearInfo.setNumber(bulidclearService.list(new QueryWrapper<Bulidclear>().lambda().eq(Bulidclear::getIsSubmit, code).eq(Bulidclear::getAuditResult, auditSubmitCode).eq(Bulidclear::getAuditUser, userid)).size());
            // 任务暂停
            AuditInfoAllVo planStopInfo = new AuditInfoAllVo();
            planStopInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_PLAN_STOP.getCode());
            planStopInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_PLAN_STOP.getValue());
            planStopInfo.setNumber(planstopService.list(new QueryWrapper<Planstop>().lambda().eq(Planstop::getIsSubmit, code).eq(Planstop::getAuditResult, auditSubmitCode).eq(Planstop::getAuditUser, userid)).size());
            // 任务作废
            AuditInfoAllVo planDisuseInfo = new AuditInfoAllVo();
            planDisuseInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_PLAN_DISUSE.getCode());
            planDisuseInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_PLAN_DISUSE.getValue());
            planDisuseInfo.setNumber(plancancleService.list(new QueryWrapper<Plancancle>().lambda().eq(Plancancle::getIsSubmit, code).eq(Plancancle::getAuditResult, auditSubmitCode).eq(Plancancle::getAuditUser, userid)).size());
            // 抢维修年计划
            AuditInfoAllVo repairPlanYearInfo = new AuditInfoAllVo();
            repairPlanYearInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_REPAIR_YEAR_PLAN.getCode());
            repairPlanYearInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_REPAIR_YEAR_PLAN.getValue());
            repairPlanYearInfo.setNumber(iAuditService.list(new QueryWrapper<Audit>().lambda().eq(Audit::getAuditType, AuditTypeEnum.AUDIT_TYPE_REPAIR_YEAR_PLAN.getCode()).eq(Audit::getAuditUser, userid).eq(Audit::getAuditState, AuditSateEnum.AUDIT_UNCOMMITTED.getCode())).size());
            // 抢维修月计划
            AuditInfoAllVo repairPlanMonthInfo = new AuditInfoAllVo();
            repairPlanMonthInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_REPAIR_MONTH_PLAN.getCode());
            repairPlanMonthInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_REPAIR_MONTH_PLAN.getValue());
            repairPlanMonthInfo.setNumber(iAuditService.list(new QueryWrapper<Audit>().lambda().eq(Audit::getAuditType, AuditTypeEnum.AUDIT_TYPE_REPAIR_MONTH_PLAN.getCode()).eq(Audit::getAuditUser, userid).eq(Audit::getAuditState, AuditSateEnum.AUDIT_UNCOMMITTED.getCode())).size());
            // 抢维修计划
            AuditInfoAllVo planOrderInfo = new AuditInfoAllVo();
            planOrderInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_REPAIR_PLAN.getCode());
            planOrderInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_REPAIR_PLAN.getValue());
            List<Repairorder> planList = repairorderService.list(new QueryWrapper<Repairorder>().lambda().eq(Repairorder::getDispatchingId, userid).eq(Repairorder::getState, OrderStateEnum.ORDER_STATE_NOT_WORK.getCode()));
            planOrderInfo.setNumber(planList.size());
            // 抢维修工单处理审核
            AuditInfoAllVo orderOverInfo = new AuditInfoAllVo();
            orderOverInfo.setAuditTypeCode(AuditTypeEnum.AUDIT_TYPE_REPAIR_RECORD.getCode());
            orderOverInfo.setAuditTypeName(AuditTypeEnum.AUDIT_TYPE_REPAIR_RECORD.getValue());
            orderOverInfo.setNumber(iAuditService.list(new QueryWrapper<Audit>().lambda().eq(Audit::getAuditType, AuditTypeEnum.AUDIT_TYPE_REPAIR_RECORD.getCode()).eq(Audit::getAuditUser, userid).eq(Audit::getAuditState, AuditSateEnum.AUDIT_UNCOMMITTED.getCode())).size());
            if (StringUtils.isEmpty(flag)) {
                //allVoList.add(yearInfo);
                allVoList.add(monthInfo);
                allVoList.add(repairPlanYearInfo);
                allVoList.add(repairPlanMonthInfo);
            }

            allVoList.add(troubleInfo);
            allVoList.add(troubleClearInfo);
            allVoList.add(buildInfo);
            allVoList.add(buildClearInfo);
            allVoList.add(planStopInfo);
            allVoList.add(planDisuseInfo);
            allVoList.add(planOrderInfo);
            allVoList.add(orderOverInfo);
            rest.setResult(allVoList);
            return rest;
        } catch (BusinessException e) {
            rest.setCode(e.getRetCd());
            rest.setMessage(e.getMsgDes());
            return rest;
        }

    }


    @ApiOperation(value = "新增审核信息")
    @PostMapping(value = "/save")
    @ToFlyAppLog(title = "新增审核信息")
    public ResultRespone save(@RequestParam(value = "json") String json) {
        List<Audit> auditList = JSONArray.parseArray(json, Audit.class);
        auditList.forEach(info -> iAuditService.save(info));
        return ResultRespone.success();
    }

    @ApiOperation(value = "获取审核链信息")
    @PostMapping(value = "/getAuditInfo")
    @ToFlyAppLog(title = "获取审核链信息")
    public ResultRespone<List<Audit>> getAuditInfo(@RequestBody Audit audit) {
        ResultRespone<List<Audit>> rest = new ResultRespone<>();
        List<Audit> list = iAuditService.list(new QueryWrapper<>(audit));
        rest.setResult(list);
        return rest;
    }


    @ApiOperation(value = "修改审核信息")
    @PostMapping(value = "/update")
    @ToFlyAppLog(title = "修改审核信息")
    public ResultRespone<Object> update(@RequestBody Audit audit) {
        ResultRespone<Object> rest = new ResultRespone<>();
        boolean b = iAuditService.updateById(audit);
        // 发送消息通知该审批人
        ReportAuditDto auditDto = new ReportAuditDto();

        auditDto.setId(audit.getId());
        // 判断当前类审核类型 分发消息
        String auditType = audit.getAuditType();
        if (AuditTypeEnum.AUDIT_TYPE_YEAR_PLAN.getCode().equals(auditType)) {
            iReportMessageService.reportTypeYearPlan(auditDto, audit.getAuditUser());
        } else if (AuditTypeEnum.AUDIT_TYPE_MONTHLY_PLAN.getCode().equals(auditType)) {
            iReportMessageService.reportTypeMonthlyPlan(auditDto, audit.getAuditUser());
        } else if (AuditTypeEnum.AUDIT_TYPE_REPAIR_YEAR_PLAN.getCode().equals(auditType)) {
            iReportMessageService.reportRepairYearPlan(auditDto, audit.getAuditUser());
        } else if (AuditTypeEnum.AUDIT_TYPE_REPAIR_MONTH_PLAN.getCode().equals(auditType)) {
            iReportMessageService.reportRepairMonthPlan(auditDto, audit.getAuditUser());
        }
        rest.setResult(b);
        return rest;
    }

    @ApiOperation(value = "删除对应审核信息")
    @PostMapping(value = "/delete")
    @ToFlyAppLog(title = "删除对应审核信息")
    public ResultRespone<Object> delete(@RequestParam(value = "type") String type, @RequestParam(value = "planId") Long planId) {
        ResultRespone<Object> rest = new ResultRespone<>();
        Audit audit = new Audit();
        audit.setAuditType(type);
        audit.setAuditPlanId(planId);
        log.info("删除对应审核信息 类型:{},计划id{}", type, planId);
        boolean b = iAuditService.remove(new QueryWrapper<Audit>().setEntity(audit));
        rest.setResult(b);
        return rest;
    }

    @ApiOperation(value = "新增审核记录信息")
    @PostMapping(value = "/saveAuditHisInfo")
    @ToFlyAppLog(title = "新增审核记录信息")
    public ResultRespone<Object> saveAuditHisInfo(@RequestBody Checkhistory checkhistory) {
        ResultRespone<Object> rest = new ResultRespone<>();

        boolean save = checkhistoryService.recordHis(checkhistory.getType(), checkhistory.getCheckId(), checkhistory.getAuditResult(), checkhistory.getAuditNotes(), checkhistory.getAuditUser(), checkhistory.getAuditTime());
        rest.setResult(save);
        return rest;
    }

    @ApiOperation(value = "获取审核历史信息")
    @PostMapping(value = "/getAuditHisInfo")
    @ToFlyAppLog(title = "获取审核历史信息")
    public ResultRespone<Object> getAuditHisInfo(@RequestBody Checkhistory checkhistory) {
        ResultRespone<Object> rest = new ResultRespone<>();
        List<Checkhistory> list = checkhistoryService.list(new QueryWrapper<>(checkhistory));
        rest.setResult(list);
        return rest;
    }

}
