package com.ruoyi.project.pssr.controller;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.document.ZipUtil;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.approve.damain.DevTask;
import com.ruoyi.project.listener.pssr.ConfirmTaskCreateListener;
import com.ruoyi.project.officeConvert.OfficeConvertController;
import com.ruoyi.project.patrol.commonuse.controller.TCommonuseTesterController;
import com.ruoyi.project.patrol.commonuse.domain.TCommonuseTester;
import com.ruoyi.project.patrol.emergency.controller.TEmergencyCabinetController;
import com.ruoyi.project.patrol.emergency.controller.TEmergencyCctvController;
import com.ruoyi.project.patrol.emergency.controller.TEmergencyEyewashController;
import com.ruoyi.project.patrol.emergency.controller.TEmergencyPagaController;
import com.ruoyi.project.patrol.emergency.domain.TEmergencyCabinet;
import com.ruoyi.project.patrol.emergency.domain.TEmergencyCctv;
import com.ruoyi.project.patrol.emergency.domain.TEmergencyEyewash;
import com.ruoyi.project.patrol.emergency.domain.TEmergencyPaga;
import com.ruoyi.project.patrol.fire.controller.*;
import com.ruoyi.project.patrol.fire.domain.*;
import com.ruoyi.project.patrol.patrol.domain.TPatrolPlan;
import com.ruoyi.project.patrol.patrol.mapper.TPatrolPlanMapper;
import com.ruoyi.project.plant.domain.TStaffmgr;
import com.ruoyi.project.pssr.domain.*;
import com.ruoyi.project.pssr.domain.dto.TPssrApproveDto;
import com.ruoyi.project.pssr.service.*;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.mapper.SysUserMapper;
import com.ruoyi.project.system.service.ISysUserService;
import org.activiti.engine.*;
import org.activiti.engine.impl.identity.Authentication;
import org.activiti.engine.impl.util.CollectionUtil;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.*;

import static com.ruoyi.framework.config.RuoYiConfig.getProfile;

/**
 * pssr审批管理Controller
 *
 * @author ssy
 * @date 2024-09-18
 */
@RestController
@RequestMapping("/pssr/approve")
public class TPssrApproveController extends BaseController {
    // region 引用
    @Resource
    private OfficeConvertController officeConvertController;
    @Resource
    private SysUserMapper userMapper;

    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private HistoryService historyService;

    @Autowired
    private TaskService taskService;

    @Autowired
    private ITPssrApproveService tPssrApproveService;

    @Autowired
    private ITPssrPatrolService tPssrPatrolService;

    @Autowired
    private ITPssrAboveallService tPssrAboveallService;

    @Autowired
    private ITPssrSubcontentService tPssrSubcontentService;

    @Autowired
    private ITPssrOverhaulExchangerService tPssrOverhaulExchangerService;

    @Autowired
    private ITPssrOverhaulFilterService tPssrOverhaulFilterService;

    @Autowired
    private ITPssrOverhaulPipeService tPssrOverhaulPipeService;

    @Autowired
    private ITPssrOverhaulTowerService tPssrOverhaulTowerService;

    @Autowired
    private ITPssrOverhaulPumpService tPssrOverhaulPumpService;

    @Autowired
    private ITPssrOverhaulValveService tPssrOverhaulValveService;

    @Autowired
    private ITPssrBlindService tPssrBlindService;

    @Autowired
    private ITPssrLockService tPssrLockService;

    @Autowired
    private ITPssrPipeService tPssrPipeService;

    @Autowired
    private ISysUserService userService;

    @Autowired
    private ITPssrHygieneService tPssrHygieneService;

    @Autowired
    private ITPssrCleaningService tPssrCleaningService;

    @Autowired
    private ITPssrAirtightService tPssrAirtightService;

    @Autowired
    private ITPssrLaboratoryService tPssrLaboratoryService;

    @Autowired
    private ITPssrMocService tPssrMocService;

    @Autowired
    private ITPssrCircuitService tPssrCircuitService;

    @Autowired
    private ITPssrPublicService tPssrPublicService;

    @Autowired
    private ITPssrSafetyBleedService tPssrSafetyBleedService;

    @Autowired
    private ITPssrSafetyBreathService tPssrSafetyBreathService;

    @Autowired
    private ITPssrSafetyBrustService tPssrSafetyBrustService;

    @Autowired
    private ITPssrSafetyFlamearresterService tPssrSafetyFlamearresterService;

    @Autowired
    private ITPssrSafetyValveService tPssrSafetyValveService;

    @Autowired
    private ITPssrFrameService tPssrFrameService;

    @Autowired
    private ITPssrMotorService tPssrMotorService;

    @Autowired
    private ITPssrInstrumentCalibrationService tPssrInstrumentCalibrationService;

    @Autowired
    private ITPssrNitrogenService tPssrNitrogenService;

    @Autowired
    private ITPssrFranklinismService tPssrFranklinismService;

    @Autowired
    private ITPssrGasdetectorService tPssrGasdetectorService;

    @Autowired
    private ITPssrAnalyzerService tPssrAnalyzerService;

    @Autowired
    private ITPssrMeasureService tPssrMeasureService;

    @Autowired
    private ITPssrProtectionService tPssrProtectionService;

    @Autowired
    private ITPssrTorchvocService tPssrTorchvocService;

    @Autowired
    private ITPssrLightingService tPssrLightingService;

    @Autowired
    private ITPssrMaterialService tPssrMaterialService;

    @Autowired
    private ITPssrMaterialRawService tPssrMaterialRawService;

    @Autowired
    private ITPssrPumpFillService tPssrPumpFillService;

    @Autowired
    private ITPssrPumpCleaningService tPssrPumpCleaningService;

    @Autowired
    private ITPssrPumpOverhaulService tPssrPumpOverhaulService;

    @Autowired
    private ITPssrInstrumentTestService tPssrInstrumentTestService;

    @Autowired
    private ITPssrAlarmService tPssrAlarmService;

    @Autowired
    private ITPssrVesselService tPssrVesselService;

    @Autowired
    private ITPssrProgrammeService tPssrProgrammeService;

    @Autowired
    private ITPssrPowerService tPssrPowerService;

    @Autowired
    private TPssrBlindController blindController;

    @Autowired
    private TPssrAirtightController airtightController;

    @Autowired
    private TPssrAnalyzerController analyzerController;

    @Autowired
    private TPssrFrameController frameController;

    @Autowired
    private TPssrPipeController pipeController;

    @Autowired
    private TPssrVesselController vesselController;

    @Autowired
    private TPssrCircuitController circuitController;

    @Autowired
    private TPssrCleaningController cleaningController;

    @Autowired
    private TPssrFranklinismController franklinismController;

    @Autowired
    private TPssrGasdetectorController gasdetectorController;

    @Autowired
    private TPssrHygieneController hygieneController;

    @Autowired
    private TPssrInstrumentCalibrationController instrumentCalibrationController;

    @Autowired
    private TPssrLaboratoryController laboratoryController;

    @Autowired
    private TPssrLockController lockController;

    @Autowired
    private TPssrMaterialController materialController;

    @Autowired
    private TPssrMaterialRawController materialRawController;

    @Autowired
    private TPssrPumpCleaningController pumpCleaningController;

    @Autowired
    private TPssrPumpFillController pumpFillController;

    @Autowired
    private TPssrPumpOverhaulController pumpOverhaulController;

    @Autowired
    private TPssrMocController mocController;

    @Autowired
    private TPssrMotorController motorController;

    @Autowired
    private TPssrLightingController lightingController;

    @Autowired
    private TPssrNitrogenController nitrogenController;

    @Autowired
    private TPssrSafetyController safetyController;

    @Autowired
    private TPssrPatrolController patrolController;

    @Autowired
    private TPssrPowerController powerController;

    @Autowired
    private TPssrProgrammeController programmeController;

    @Autowired
    private TPssrPublicController publicController;

    @Autowired
    private TCommonuseTesterController testerController;

    @Autowired
    private TEmergencyPagaController pagaController;

    @Autowired
    private TEmergencyCctvController cctvController;

    @Autowired
    private TPssrOverhaulExchangerController exchangerController;

    @Autowired
    private TPssrOverhaulFilterController filterController;

    @Autowired
    private TPssrOverhaulTowerController towerController;

    @Autowired
    private TPssrOverhaulValveController valveController;

    @Autowired
    private TPssrProtectionController protectionController;

    @Autowired
    private TPssrMeasureController measureController;

    @Autowired
    private TPssrSafetyBleedController bleedController;

    @Autowired
    private TFireAidkitController aidkitController;

    @Autowired
    private TFireAlarmController alarmController;

    @Autowired
    private TFireAnnihilatorController annihilatorController;

    @Autowired
    private TFireDoorController doorController;

    @Autowired
    private TFireGasShieldController gasShieldController;

    @Autowired
    private TEmergencyEyewashController eyewashController;

    @Autowired
    private TFireHoseBoxController hoseBoxController;

    @Autowired
    private TFirePostFireController postFireController;

    @Autowired
    private TFireSandboxController sandboxController;

    @Autowired
    private TFireSprinklerController sprinklerController;

    @Autowired
    private TEmergencyCabinetController cabinetController;

    @Autowired
    private TFireStandpipeController standpipeController;

    @Autowired
    private TFireSteamCurtainController steamCurtainController;

    @Autowired
    private TFireWaterCannonController waterCannonController;

    @Autowired
    private TFireWeathervaneController weathervaneController;

    @Autowired
    private TPssrSafetyBreathController breathController;

    @Autowired
    private TPssrSafetyBrustController brustController;

    @Autowired
    private TPssrSafetyFlamearresterController flamearresterController;

    @Autowired
    private TPssrSafetyValveController safetyValveController;

    @Autowired
    private TPssrTorchvocController torchvocController;

    @Autowired
    private TPssrSubcontentController subcontentController;
    @Autowired
    private TPatrolPlanMapper tPatrolPlanMapper;
    //endregion

    @PutMapping("/handleConfirm")
    public AjaxResult handleConfirm(@RequestBody TPssrApproveDto dto) {
        TPssrSubcontent tPssrSubcontent = tPssrSubcontentService.selectTPssrSubcontentById(dto.getSubId());
        switch (tPssrSubcontent.getForShort()) {
            case "jxxm"://检修项目
                switch (dto.getSubName()) {
                    case "exchanger":
                        TPssrOverhaulExchanger exchanger = new TPssrOverhaulExchanger();
                        exchanger.setSubId(dto.getSubId());
                        exchanger.setIds(dto.getIds());
                        return exchangerController.confirmExchanger(exchanger);
                    case "filter":
                        TPssrOverhaulFilter filter = new TPssrOverhaulFilter();
                        filter.setSubId(dto.getSubId());
                        filter.setIds(dto.getIds());
                        return filterController.confirmFilter(filter);
                    case "tower":
                        TPssrOverhaulTower tower = new TPssrOverhaulTower();
                        tower.setSubId(dto.getSubId());
                        tower.setIds(dto.getIds());
                        return towerController.confirmTower(tower);
                    case "valve":
                        TPssrOverhaulValve valve = new TPssrOverhaulValve();
                        valve.setSubId(dto.getSubId());
                        valve.setIds(dto.getIds());
                        return valveController.confirmValve(valve);
                }
                return AjaxResult.error("确认失败！");
            case "kgfa"://开工方案
                TPssrProgramme programme = new TPssrProgramme();
                programme.setSubId(dto.getSubId());
                programme.setIds(dto.getIds());
                programme.setTaskType(dto.getTaskType());
                return programmeController.confirmProgramme(programme);
            case "sjbg"://设计变更
                TPssrMoc moc = new TPssrMoc();
                moc.setSubId(dto.getSubId());
                moc.setIds(dto.getIds());
                moc.setTaskType(dto.getTaskType());
                return mocController.confirmMoc(moc);
            case "mb"://盲板
                TPssrBlind blind = new TPssrBlind();
                blind.setSubId(dto.getSubId());
                blind.setIds(dto.getIds());
                blind.setTaskType(dto.getTaskType());
                return blindController.confirmBlind(blind);
            case "xcws"://现场卫生
                TPssrHygiene hygiene = new TPssrHygiene();
                hygiene.setSubId(dto.getSubId());
                hygiene.setIds(dto.getIds());
                hygiene.setTaskType(dto.getTaskType());
                return hygieneController.confirmHygiene(hygiene);
            case "rsfh"://人身防护
                switch (dto.getSubName()) {
                    case "protection":
                        TPssrProtection protection = new TPssrProtection();
                        protection.setSubId(dto.getSubId());
                        protection.setIds(dto.getIds());
                        protection.setTaskType(dto.getTaskType());
                        return protectionController.confirmProtection(protection);
                    case "measure":
                        TPssrMeasure measure = new TPssrMeasure();
                        measure.setSubId(dto.getSubId());
                        measure.setIds(dto.getIds());
                        measure.setTaskType(dto.getTaskType());
                        return measureController.confirmMeasure(measure);
                }
                return AjaxResult.error("确认失败！");
            case "sbqjd"://设备清洁度
                TPssrCleaning cleaning = new TPssrCleaning();
                cleaning.setSubId(dto.getSubId());
                cleaning.setIds(dto.getIds());
                cleaning.setTaskType(dto.getTaskType());
                return cleaningController.confirmCleaning(cleaning);
            case "qm"://气密
                TPssrAirtight airtight = new TPssrAirtight();
                airtight.setSubId(dto.getSubId());
                airtight.setIds(dto.getIds());
                airtight.setTaskType(dto.getTaskType());
                return airtightController.confirmAirtight(airtight);
            case "sksgfmzt"://锁开锁关阀门状态
                TPssrLock lock = new TPssrLock();
                lock.setSubId(dto.getSubId());
                lock.setIds(dto.getIds());
                lock.setTaskType(dto.getTaskType());
                return lockController.confirmLock(lock);
            case "sys"://实验室
                TPssrLaboratory laboratory = new TPssrLaboratory();
                laboratory.setSubId(dto.getSubId());
                laboratory.setIds(dto.getIds());
                laboratory.setTaskType(dto.getTaskType());
                return laboratoryController.confirmLaboratory(laboratory);
            case "dj"://短接
                TPssrCircuit circuit = new TPssrCircuit();
                circuit.setSubId(dto.getSubId());
                circuit.setIds(dto.getIds());
                circuit.setTaskType(dto.getTaskType());
                return circuitController.confirmCircuit(circuit);
            case "dqzh"://氮气置换
                TPssrNitrogen nitrogen = new TPssrNitrogen();
                nitrogen.setSubId(dto.getSubId());
                nitrogen.setIds(dto.getIds());
                nitrogen.setTaskType(dto.getTaskType());
                return nitrogenController.confirmNitrogen(nitrogen);
            case "xqf"://消气防设施
                return AjaxResult.success();
            case "aqss"://安全设施
                switch (dto.getSubName()) {
                    case "bleed":
                        TPssrSafetyBleed bleed = new TPssrSafetyBleed();
                        bleed.setSubId(dto.getSubId());
                        bleed.setIds(dto.getIds());
                        bleed.setTaskType(dto.getTaskType());
                        return safetyController.confirmBleed(bleed);
                    case "breath":
                        TPssrSafetyBreath breath = new TPssrSafetyBreath();
                        breath.setSubId(dto.getSubId());
                        breath.setIds(dto.getIds());
                        breath.setTaskType(dto.getTaskType());
                        return safetyController.confirmBreath(breath);
                    case "brust":
                        TPssrSafetyBrust brust = new TPssrSafetyBrust();
                        brust.setSubId(dto.getSubId());
                        brust.setIds(dto.getIds());
                        brust.setTaskType(dto.getTaskType());
                        return safetyController.confirmBrust(brust);
                    case "flamearrester":
                        TPssrSafetyFlamearrester flamearrester = new TPssrSafetyFlamearrester();
                        flamearrester.setSubId(dto.getSubId());
                        flamearrester.setIds(dto.getIds());
                        flamearrester.setTaskType(dto.getTaskType());
                        return safetyController.confirmFlamearrester(flamearrester);
                    case "valve":
                        TPssrSafetyValve safetyValve = new TPssrSafetyValve();
                        safetyValve.setSubId(dto.getSubId());
                        safetyValve.setIds(dto.getIds());
                        safetyValve.setTaskType(dto.getTaskType());
                        return safetyController.confirmValve(safetyValve);
                }
            case "txjk"://通讯监控
                return AjaxResult.success();
            case "bxsjcy"://便携式检测仪
                return AjaxResult.success();
            case "gygc"://公用工程
                TPssrPublic pssrPublic = new TPssrPublic();
                pssrPublic.setSubId(dto.getSubId());
                pssrPublic.setIds(dto.getIds());
                pssrPublic.setTaskType(dto.getTaskType());
                return publicController.confirmPublic(pssrPublic);
            case "hbss"://环保设施
                TPssrTorchvoc torchvoc = new TPssrTorchvoc();
                torchvoc.setSubId(dto.getSubId());
                torchvoc.setIds(dto.getIds());
                torchvoc.setTaskType(dto.getTaskType());
                torchvoc.setTorchvocType(dto.getTorchvocType());
                return torchvocController.confirmTorchvoc(torchvoc);
            case "yfl"://原辅料
                switch (dto.getSubName()) {
                    case "material":
                        TPssrMaterial material = new TPssrMaterial();
                        material.setSubId(dto.getSubId());
                        material.setIds(dto.getIds());
                        material.setTaskType(dto.getTaskType());
                        return materialController.confirmMaterial(material);
                    case "raw":
                        TPssrMaterialRaw raw = new TPssrMaterialRaw();
                        raw.setSubId(dto.getSubId());
                        raw.setIds(dto.getIds());
                        raw.setTaskType(dto.getTaskType());
                        return materialRawController.confirmMaterialRaw(raw);
                }
            case "jb"://机泵
                switch (dto.getSubName()) {
                    case "cleaning":
                        TPssrPumpCleaning pumpCleaning = new TPssrPumpCleaning();
                        pumpCleaning.setSubId(dto.getSubId());
                        pumpCleaning.setIds(dto.getIds());
                        pumpCleaning.setTaskType(dto.getTaskType());
                        return pumpCleaningController.confirmPumpCleaning(pumpCleaning);
                    case "fill":
                        TPssrPumpFill pumpFill = new TPssrPumpFill();
                        pumpFill.setSubId(dto.getSubId());
                        pumpFill.setIds(dto.getIds());
                        pumpFill.setTaskType(dto.getTaskType());
                        return pumpFillController.confirmPumpFill(pumpFill);
                    case "overhaul":
                        TPssrPumpOverhaul pumpOverhaul = new TPssrPumpOverhaul();
                        pumpOverhaul.setSubId(dto.getSubId());
                        pumpOverhaul.setIds(dto.getIds());
                        pumpOverhaul.setTaskType(dto.getTaskType());
                        return pumpOverhaulController.confirmPumpOverhaul(pumpOverhaul);
                }
                return AjaxResult.error("确认失败！");
            case "zdj"://支吊架
                TPssrFrame frame = new TPssrFrame();
                frame.setSubId(dto.getSubId());
                frame.setIds(dto.getIds());
                frame.setTaskType(dto.getTaskType());
                return frameController.confirmFrame(frame);
            case "tzsb"://特种设备
                switch (dto.getSubName()) {
                    case "pipe":
                        TPssrPipe pipe = new TPssrPipe();
                        pipe.setSubId(dto.getSubId());
                        pipe.setIds(dto.getIds());
                        pipe.setTaskType(dto.getTaskType());
                        return pipeController.confirmPipe(pipe);
                    case "vessel":
                        TPssrVessel vessel = new TPssrVessel();
                        vessel.setSubId(dto.getSubId());
                        vessel.setIds(dto.getIds());
                        vessel.setTaskType(dto.getTaskType());
                        return vesselController.confirmVessel(vessel);
                }
            case "ybjy"://仪表校验
                TPssrInstrumentCalibration calibration = new TPssrInstrumentCalibration();
                calibration.setSubId(dto.getSubId());
                calibration.setIds(dto.getIds());
                calibration.setTaskType(dto.getTaskType());
                calibration.setDevType(dto.getDevType());
                return instrumentCalibrationController.confirmInstrumentCalibration(calibration);
            case "yblscs"://仪表联锁测试
                return AjaxResult.success();
            case "bjlszqr"://报警联锁值确认
                return AjaxResult.success();
            case "lsdy"://临时电源
                TPssrPower power = new TPssrPower();
                power.setSubId(dto.getSubId());
                power.setIds(dto.getIds());
                power.setTaskType(dto.getTaskType());
                return powerController.confirmPower(power);
            case "djsb"://电机设备
                TPssrMotor motor = new TPssrMotor();
                motor.setSubId(dto.getSubId());
                motor.setIds(dto.getIds());
                motor.setTaskType(dto.getTaskType());
                return motorController.confirmMotor(motor);
            case "zmdbr"://照明、电伴热
                TPssrLighting lighting = new TPssrLighting();
                lighting.setSubId(dto.getSubId());
                lighting.setIds(dto.getIds());
                lighting.setTaskType(dto.getTaskType());
                lighting.setLightingType(dto.getLightingType());
                return lightingController.Lighting(lighting);
            case "jdjdkj"://静电接地、跨接
                TPssrFranklinism franklinism = new TPssrFranklinism();
                franklinism.setSubId(dto.getSubId());
                franklinism.setIds(dto.getIds());
                franklinism.setTaskType(dto.getTaskType());
                return franklinismController.Franklinism(franklinism);
            case "qtjcy"://气体检测仪
                TPssrGasdetector gasdetector = new TPssrGasdetector();
                gasdetector.setSubId(dto.getSubId());
                gasdetector.setIds(dto.getIds());
                gasdetector.setTaskType(dto.getTaskType());
                return gasdetectorController.Gasdetector(gasdetector);
            case "zxfxy"://在线分析仪
                TPssrAnalyzer analyzer = new TPssrAnalyzer();
                analyzer.setSubId(dto.getSubId());
                analyzer.setIds(dto.getIds());
                analyzer.setTaskType(dto.getTaskType());
                return analyzerController.Analyzer(analyzer);
            default:
                return AjaxResult.error("确认失败！");
        }
    }

    @PutMapping("/handleTurndown")
    public AjaxResult handleTurndown(@RequestBody TPssrApproveDto dto) {
        TPssrSubcontent tPssrSubcontent = tPssrSubcontentService.selectTPssrSubcontentById(dto.getSubId());
        switch (tPssrSubcontent.getForShort()) {
            case "jxxm"://检修项目
                switch (dto.getSubName()) {
                    case "exchanger":
                        List<TPssrOverhaulExchanger> exchangers = new ArrayList<>();
                        for (TPssrApproveDto item : dto.getDataList()) {
                            TPssrOverhaulExchanger exchanger = new TPssrOverhaulExchanger();
                            exchanger.setSubId(dto.getSubId());
                            exchanger.setId(item.getId());
                            exchanger.setReason(item.getReason());
                            exchangers.add(exchanger);
                        }
                        return exchangerController.turnDownExchanger(exchangers);
                    case "filter":
                        List<TPssrOverhaulFilter> filters = new ArrayList<>();
                        for (TPssrApproveDto item : dto.getDataList()) {
                            TPssrOverhaulFilter filter = new TPssrOverhaulFilter();
                            filter.setSubId(dto.getSubId());
                            filter.setId(item.getId());
                            filter.setReason(item.getReason());
                            filters.add(filter);
                        }
                        return filterController.turnDownFilter(filters);
                    case "":
                        List<TPssrOverhaulTower> towers = new ArrayList<>();
                        for (TPssrApproveDto item : dto.getDataList()) {
                            TPssrOverhaulTower tower = new TPssrOverhaulTower();
                            tower.setSubId(dto.getSubId());
                            tower.setId(item.getId());
                            tower.setReason(item.getReason());
                            towers.add(tower);
                        }
                        return towerController.turnDownTower(towers);
                    case "valve":
                        List<TPssrOverhaulValve> valves = new ArrayList<>();
                        for (TPssrApproveDto item : dto.getDataList()) {
                            TPssrOverhaulValve valve = new TPssrOverhaulValve();
                            valve.setSubId(dto.getSubId());
                            valve.setId(item.getId());
                            valve.setReason(item.getReason());
                            valves.add(valve);
                        }
                        return valveController.turnDownValve(valves);
                }
                return AjaxResult.error("驳回失败！");
            case "kgfa"://开工方案
                List<TPssrProgramme> programmes = new ArrayList<>();
                for (TPssrApproveDto item : dto.getDataList()) {
                    TPssrProgramme programme = new TPssrProgramme();
                    programme.setSubId(dto.getSubId());
                    programme.setId(item.getId());
                    programme.setReason(item.getReason());
                    programmes.add(programme);
                }
                return programmeController.turnDownProgramme(programmes);
            case "sjbg"://设计变更
                List<TPssrMoc> mocs = new ArrayList<>();
                for (TPssrApproveDto item : dto.getDataList()) {
                    TPssrMoc moc = new TPssrMoc();
                    moc.setSubId(dto.getSubId());
                    moc.setId(item.getId());
                    moc.setReason(item.getReason());
                    mocs.add(moc);
                }
                return mocController.turnDownMoc(mocs);
            case "mb"://盲板
                List<TPssrBlind> blinds = new ArrayList<>();
                for (TPssrApproveDto item : dto.getDataList()) {
                    TPssrBlind blind = new TPssrBlind();
                    blind.setSubId(dto.getSubId());
                    blind.setId(item.getId());
                    blind.setReason(item.getReason());
                    blinds.add(blind);
                }
                return blindController.turnDownBlind(blinds);
            case "xcws"://现场卫生
                List<TPssrHygiene> hygeins = new ArrayList<>();
                for (TPssrApproveDto item : dto.getDataList()) {
                    TPssrHygiene hygien = new TPssrHygiene();
                    hygien.setSubId(dto.getSubId());
                    hygien.setId(item.getId());
                    hygien.setReason(item.getReason());
                    hygeins.add(hygien);
                }
                return hygieneController.turnDownHygiene(hygeins);
            case "rsfh"://人身防护
                switch (dto.getSubName()) {
                    case "protection":
                        List<TPssrProtection> protections = new ArrayList<>();
                        for (TPssrApproveDto item : dto.getDataList()) {
                            TPssrProtection protection = new TPssrProtection();
                            protection.setSubId(dto.getSubId());
                            protection.setId(item.getId());
                            protection.setReason(item.getReason());
                            protections.add(protection);
                        }
                        return protectionController.turnDownProtection(protections);
                    case "measure":
                        List<TPssrMeasure> measures = new ArrayList<>();
                        for (TPssrApproveDto item : dto.getDataList()) {
                            TPssrMeasure measure = new TPssrMeasure();
                            measure.setSubId(dto.getSubId());
                            measure.setId(item.getId());
                            measure.setReason(item.getReason());
                            measures.add(measure);
                        }
                        return measureController.turnDownMeasure(measures);
                }
                return AjaxResult.error("驳回失败！");
            case "sbqjd"://设备清洁度
                List<TPssrCleaning> cleans = new ArrayList<>();
                for (TPssrApproveDto item : dto.getDataList()) {
                    TPssrCleaning clean = new TPssrCleaning();
                    clean.setSubId(dto.getSubId());
                    clean.setId(item.getId());
                    clean.setReason(item.getReason());
                    cleans.add(clean);
                }
                return cleaningController.turnDownCleaning(cleans);
            case "qm"://气密
                List<TPssrAirtight> airtights = new ArrayList<>();
                for (TPssrApproveDto item : dto.getDataList()) {
                    TPssrAirtight airtight = new TPssrAirtight();
                    airtight.setSubId(dto.getSubId());
                    airtight.setId(item.getId());
                    airtight.setReason(item.getReason());
                    airtights.add(airtight);
                }
                return airtightController.turnDownAirtight(airtights);
            case "sksgfmzt"://锁开锁关阀门状态
                List<TPssrLock> locks = new ArrayList<>();
                for (TPssrApproveDto item : dto.getDataList()) {
                    TPssrLock lock = new TPssrLock();
                    lock.setSubId(dto.getSubId());
                    lock.setId(item.getId());
                    lock.setReason(item.getReason());
                    locks.add(lock);
                }
                return lockController.turnDownLock(locks);
            case "sys"://实验室
                List<TPssrLaboratory> laboratories = new ArrayList<>();
                for (TPssrApproveDto item : dto.getDataList()) {
                    TPssrLaboratory laboratory = new TPssrLaboratory();
                    laboratory.setSubId(dto.getSubId());
                    laboratory.setId(item.getId());
                    laboratory.setReason(item.getReason());
                    laboratories.add(laboratory);
                }
                return laboratoryController.turnDownLaboratory(laboratories);
            case "dj"://短接
                List<TPssrCircuit> circuits = new ArrayList<>();
                for (TPssrApproveDto item : dto.getDataList()) {
                    TPssrCircuit circuit = new TPssrCircuit();
                    circuit.setSubId(dto.getSubId());
                    circuit.setId(item.getId());
                    circuit.setReason(item.getReason());
                    circuits.add(circuit);
                }
                return circuitController.turnDownCircuit(circuits);
            case "dqzh"://氮气置换
                List<TPssrNitrogen> nitrogens = new ArrayList<>();
                for (TPssrApproveDto item : dto.getDataList()) {
                    TPssrNitrogen nitrogen = new TPssrNitrogen();
                    nitrogen.setSubId(dto.getSubId());
                    nitrogen.setId(item.getId());
                    nitrogen.setReason(item.getReason());
                    nitrogens.add(nitrogen);
                }
                return nitrogenController.turnDownNitrogen(nitrogens);
            case "xqf"://消气防设施
                return AjaxResult.success();
            case "aqss"://安全设施
                switch (dto.getSubName()) {
                    case "bleed":
                        List<TPssrSafetyBleed> bleeds = new ArrayList<>();
                        for (TPssrApproveDto item : dto.getDataList()) {
                            TPssrSafetyBleed bleed = new TPssrSafetyBleed();
                            bleed.setSubId(dto.getSubId());
                            bleed.setId(item.getId());
                            bleed.setReason(item.getReason());
                            bleeds.add(bleed);
                        }
                        return safetyController.turnDownBleed(bleeds);
                    case "breath":
                        List<TPssrSafetyBreath> breaths = new ArrayList<>();
                        for (TPssrApproveDto item : dto.getDataList()) {
                            TPssrSafetyBreath breath = new TPssrSafetyBreath();
                            breath.setSubId(dto.getSubId());
                            breath.setId(item.getId());
                            breath.setReason(item.getReason());
                            breaths.add(breath);
                        }
                        return safetyController.turnDownBreath(breaths);
                    case "brust":
                        List<TPssrSafetyBrust> brusts = new ArrayList<>();
                        for (TPssrApproveDto item : dto.getDataList()) {
                            TPssrSafetyBrust brust = new TPssrSafetyBrust();
                            brust.setSubId(dto.getSubId());
                            brust.setId(item.getId());
                            brust.setReason(item.getReason());
                            brusts.add(brust);
                        }
                        return safetyController.turnDownBrust(brusts);
                    case "flamearrester":
                        List<TPssrSafetyFlamearrester> flamearresters = new ArrayList<>();
                        for (TPssrApproveDto item : dto.getDataList()) {
                            TPssrSafetyFlamearrester flamearrester = new TPssrSafetyFlamearrester();
                            flamearrester.setSubId(dto.getSubId());
                            flamearrester.setId(item.getId());
                            flamearrester.setReason(item.getReason());
                            flamearresters.add(flamearrester);
                        }
                        return safetyController.turnDownFlamearrester(flamearresters);
                    case "valve":
                        List<TPssrSafetyValve> valves = new ArrayList<>();
                        for (TPssrApproveDto item : dto.getDataList()) {
                            TPssrSafetyValve valve = new TPssrSafetyValve();
                            valve.setSubId(dto.getSubId());
                            valve.setId(item.getId());
                            valve.setReason(item.getReason());
                            valves.add(valve);
                        }
                        return safetyController.turnDownValve(valves);
                }
                return AjaxResult.error("驳回失败！");
            case "txjk"://通讯监控
                return AjaxResult.success();
            case "bxsjcy"://便携式检测仪
                return AjaxResult.success();
            case "gygc"://公用工程
                List<TPssrPublic> publics = new ArrayList<>();
                for (TPssrApproveDto item : dto.getDataList()) {
                    TPssrPublic pssrPublic = new TPssrPublic();
                    pssrPublic.setSubId(dto.getSubId());
                    pssrPublic.setId(item.getId());
                    pssrPublic.setReason(item.getReason());
                    publics.add(pssrPublic);
                }
                return publicController.turnDownPublic(publics);
            case "hbss"://环保设施
                List<TPssrTorchvoc> torchvocs = new ArrayList<>();
                for (TPssrApproveDto item : dto.getDataList()) {
                    TPssrTorchvoc torchvoc = new TPssrTorchvoc();
                    torchvoc.setSubId(dto.getSubId());
                    torchvoc.setId(item.getId());
                    torchvoc.setReason(item.getReason());
                    torchvocs.add(torchvoc);
                }
                return torchvocController.turnDownTorchvoc(torchvocs);
            case "yfl"://原辅料
                switch (dto.getSubName()) {
                    case "material":
                        List<TPssrMaterial> materials = new ArrayList<>();
                        for (TPssrApproveDto item : dto.getDataList()) {
                            TPssrMaterial material = new TPssrMaterial();
                            material.setSubId(dto.getSubId());
                            material.setId(item.getId());
                            material.setReason(item.getReason());
                            materials.add(material);
                        }
                        return materialController.turnDownMaterial(materials);
                    case "raw":
                        List<TPssrMaterialRaw> raws = new ArrayList<>();
                        for (TPssrApproveDto item : dto.getDataList()) {
                            TPssrMaterialRaw raw = new TPssrMaterialRaw();
                            raw.setSubId(dto.getSubId());
                            raw.setId(item.getId());
                            raw.setReason(item.getReason());
                            raws.add(raw);
                        }
                        return materialRawController.turnDownMaterialRaw(raws);
                }
                return AjaxResult.error("驳回失败！");
            case "jb"://机泵
                switch (dto.getSubName()) {
                    case "cleaning":
                        List<TPssrPumpCleaning> cleanings = new ArrayList<>();
                        for (TPssrApproveDto item : dto.getDataList()) {
                            TPssrPumpCleaning cleaning = new TPssrPumpCleaning();
                            cleaning.setSubId(dto.getSubId());
                            cleaning.setId(item.getId());
                            cleaning.setReason(item.getReason());
                            cleanings.add(cleaning);
                        }
                        return pumpCleaningController.turnDownPumpCleaning(cleanings);
                    case "overhaul":
                        List<TPssrPumpOverhaul> overhauls = new ArrayList<>();
                        for (TPssrApproveDto item : dto.getDataList()) {
                            TPssrPumpOverhaul overhaul = new TPssrPumpOverhaul();
                            overhaul.setSubId(dto.getSubId());
                            overhaul.setId(item.getId());
                            overhaul.setReason(item.getReason());
                            overhauls.add(overhaul);
                        }
                        return pumpOverhaulController.turnDownPumpOverhaul(overhauls);
                    case "fill":
                        List<TPssrPumpFill> fills = new ArrayList<>();
                        for (TPssrApproveDto item : dto.getDataList()) {
                            TPssrPumpFill fill = new TPssrPumpFill();
                            fill.setSubId(dto.getSubId());
                            fill.setId(item.getId());
                            fill.setReason(item.getReason());
                            fills.add(fill);
                        }
                        return pumpFillController.turnDownPumpFill(fills);
                }
                return AjaxResult.error("驳回失败！");
            case "zdj"://支吊架
                List<TPssrFrame> frames = new ArrayList<>();
                for (TPssrApproveDto item : dto.getDataList()) {
                    TPssrFrame frame = new TPssrFrame();
                    frame.setSubId(dto.getSubId());
                    frame.setId(item.getId());
                    frame.setReason(item.getReason());
                    frames.add(frame);
                }
                return frameController.turnDownFrame(frames);
            case "tzsb"://特种设备
                switch (dto.getSubName()) {
                    case "pipe":
                        List<TPssrPipe> pipes = new ArrayList<>();
                        for (TPssrApproveDto item : dto.getDataList()) {
                            TPssrPipe pipe = new TPssrPipe();
                            pipe.setSubId(dto.getSubId());
                            pipe.setId(item.getId());
                            pipe.setReason(item.getReason());
                            pipes.add(pipe);
                        }
                        return pipeController.turnDownPipe(pipes);
                    case "vessel":
                        List<TPssrVessel> vessels = new ArrayList<>();
                        for (TPssrApproveDto item : dto.getDataList()) {
                            TPssrVessel vessel = new TPssrVessel();
                            vessel.setSubId(dto.getSubId());
                            vessel.setId(item.getId());
                            vessel.setReason(item.getReason());
                            vessels.add(vessel);
                        }
                        return vesselController.turnDownVessel(vessels);
                }
                return AjaxResult.error("驳回失败！");
            case "ybjy"://仪表校验
                List<TPssrInstrumentCalibration> calibrations = new ArrayList<>();
                for (TPssrApproveDto item : dto.getDataList()) {
                    TPssrInstrumentCalibration calibration = new TPssrInstrumentCalibration();
                    calibration.setSubId(dto.getSubId());
                    calibration.setId(item.getId());
                    calibration.setReason(item.getReason());
                    calibrations.add(calibration);
                }
                return instrumentCalibrationController.turnDownInstrumentCalibration(calibrations);
            case "yblscs"://仪表联锁测试
                return AjaxResult.success();
            case "bjlszqr"://报警联锁值确认
                return AjaxResult.success();
            case "lsdy"://临时电源
                List<TPssrPower> powers = new ArrayList<>();
                for (TPssrApproveDto item : dto.getDataList()) {
                    TPssrPower power = new TPssrPower();
                    power.setSubId(dto.getSubId());
                    power.setId(item.getId());
                    power.setReason(item.getReason());
                    powers.add(power);
                }
                return powerController.turnDownPower(powers);
            case "djsb"://电机设备
                List<TPssrMotor> motors = new ArrayList<>();
                for (TPssrApproveDto item : dto.getDataList()) {
                    TPssrMotor motor = new TPssrMotor();
                    motor.setSubId(dto.getSubId());
                    motor.setId(item.getId());
                    motor.setReason(item.getReason());
                    motors.add(motor);
                }
                return motorController.turnDownMotor(motors);
            case "zmdbr"://照明、电伴热
                List<TPssrLighting> lightings = new ArrayList<>();
                for (TPssrApproveDto item : dto.getDataList()) {
                    TPssrLighting lighting = new TPssrLighting();
                    lighting.setSubId(dto.getSubId());
                    lighting.setId(item.getId());
                    lighting.setReason(item.getReason());
                    lightings.add(lighting);
                }
                return lightingController.turnDownLighting(lightings);
            case "jdjdkj"://静电接地、跨接
                List<TPssrFranklinism> franklinisms = new ArrayList<>();
                for (TPssrApproveDto item : dto.getDataList()) {
                    TPssrFranklinism franklinism = new TPssrFranklinism();
                    franklinism.setSubId(dto.getSubId());
                    franklinism.setId(item.getId());
                    franklinism.setReason(item.getReason());
                    franklinisms.add(franklinism);
                }
                return franklinismController.turnDownFranklinism(franklinisms);
            case "qtjcy"://气体检测仪
                List<TPssrGasdetector> gasdetectors = new ArrayList<>();
                for (TPssrApproveDto item : dto.getDataList()) {
                    TPssrGasdetector gasdetector = new TPssrGasdetector();
                    gasdetector.setSubId(dto.getSubId());
                    gasdetector.setId(item.getId());
                    gasdetector.setReason(item.getReason());
                    gasdetectors.add(gasdetector);
                }
                return gasdetectorController.turnDownGasdetector(gasdetectors);
            case "zxfxy"://在线分析仪
                List<TPssrAnalyzer> analyzers = new ArrayList<>();
                for (TPssrApproveDto item : dto.getDataList()) {
                    TPssrAnalyzer analyzer = new TPssrAnalyzer();
                    analyzer.setSubId(dto.getSubId());
                    analyzer.setId(item.getId());
                    analyzer.setReason(item.getReason());
                    analyzers.add(analyzer);
                }
                return analyzerController.turnDownAnalyzer(analyzers);
            default:
                return AjaxResult.error("驳回失败！");
        }
    }

    /**
     * 子项内容确认
     */
    public static void handleConfirmApprove(TPssrApprove approve, String userId) {
        String processInstancesId = approve.getProcessId();
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        TaskService taskService = processEngine.getTaskService();
        Task task = processEngine.getTaskService()//获取任务service
                .createTaskQuery()//创建查询对象
                .taskAssignee(userId)
                .processInstanceId(processInstancesId).singleResult();
        String taskId = task.getId();
        if(task.getName().contains("检查内容负责人")){
            return;
        }
        //处理流程节点
        Map<String, Object> param = new HashMap<>();
        param.put("condition", "0");
        //认领任务
        processEngine.getTaskService().claim(taskId, userId);
        taskService.addComment(taskId, processInstancesId, "通过");
        taskService.complete(taskId, param);
    }

    /**
     * 查询pssr审批管理列表
     */
    @PreAuthorize("@ss.hasPermi('pssr:approve:list')")
    @GetMapping("/list")
    public TableDataInfo list(TPssrApprove tPssrApprove) {
        startPage();
        List<TPssrApprove> list = tPssrApproveService.selectTPssrApproveList(tPssrApprove);
        return getDataTable(list);
    }

    /**
     * 导出pssr审批管理列表
     */
    @PreAuthorize("@ss.hasPermi('pssr:approve:export')")
    @Log(title = "pssr审批管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TPssrApprove tPssrApprove) {
        List<TPssrApprove> list = tPssrApproveService.selectTPssrApproveList(tPssrApprove);
        ExcelUtil<TPssrApprove> util = new ExcelUtil<TPssrApprove>(TPssrApprove.class);
        return util.exportExcel(list, "approve");
    }

    /**
     * 获取pssr审批管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('pssr:approve:query')")
    @GetMapping(value = "/{approveId}")
    public AjaxResult getInfo(@PathVariable("approveId") Long approveId) {
        return AjaxResult.success(tPssrApproveService.selectTPssrApproveById(approveId));
    }

    /**
     * 新增pssr审批管理
     */
    @PreAuthorize("@ss.hasPermi('pssr:approve:add')")
    @Log(title = "pssr审批管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TPssrApprove tPssrApprove) {
        return toAjax(tPssrApproveService.insertTPssrApprove(tPssrApprove));
    }

    /**
     * 修改pssr审批管理
     */
    @PreAuthorize("@ss.hasPermi('pssr:approve:edit')")
    @Log(title = "pssr审批管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TPssrApprove tPssrApprove) {
        return toAjax(tPssrApproveService.updateTPssrApprove(tPssrApprove));
    }

    /**
     * 删除pssr审批管理
     */
    @PreAuthorize("@ss.hasPermi('pssr:approve:remove')")
    @Log(title = "pssr审批管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{approveIds}")
    public AjaxResult remove(@PathVariable Long[] approveIds) {
        return toAjax(tPssrApproveService.deleteTPssrApproveByIds(approveIds));
    }

    @Log(title = "pssr发起审批", businessType = BusinessType.INSERT)
    @PostMapping("/doPssrApprove/{subId}")
    public AjaxResult doApprove(@PathVariable Long subId) {
        TPssrSubcontent tPssrSubcontent = tPssrSubcontentService.selectTPssrSubcontentById(subId);
        if (judgmentOrder(tPssrSubcontent)) {
            return AjaxResult.error("请先完成前置审批流程");
        }
        switch (tPssrSubcontent.getForShort()) {
            case "jxxm"://检修项目
                if (tPssrOverhaulExchangerService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doJxxmApprove(tPssrSubcontent);
                break;
            case "kgfa"://开工方案
                if (tPssrProgrammeService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doKgfaApprove(tPssrSubcontent);
                break;
            case "sjbg"://设计变更
                if (tPssrMocService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doMocApprove(tPssrSubcontent);
                break;
            case "mb"://盲板
                if (tPssrBlindService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doMbApprove(tPssrSubcontent);
                break;
            case "xcws"://现场卫生
                if (tPssrHygieneService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doXcwsApprove(tPssrSubcontent);
                break;
            case "rsfh"://人身防护
                if (tPssrProtectionService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0
                        || tPssrMeasureService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doRsfhApprove(tPssrSubcontent);
                break;
            case "sbqjd"://设备清洁度
                if (tPssrCleaningService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doSbqjdApprove(tPssrSubcontent);
                break;
            case "qm"://气密
                if (tPssrAirtightService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                try {
                    doQmApprove(tPssrSubcontent);
                } catch (Exception e) {
                    return AjaxResult.error(e.getMessage());
                }
                break;
            case "sksgfmzt"://锁开锁关阀门状态
                if (tPssrLockService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doSksgApprove(tPssrSubcontent);
                break;
            case "sys"://实验室
                if (tPssrLaboratoryService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doSysApprove(tPssrSubcontent);
                break;
            case "dj"://短接
                if (tPssrCircuitService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doDjApprove(tPssrSubcontent);
                break;
            case "dqzh"://氮气置换
                if (tPssrNitrogenService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                try {
                    doDqzhApprove(tPssrSubcontent);
                } catch (Exception e) {
                    return AjaxResult.error(e.getMessage());
                }
                break;
            case "xqf"://消气防设施
                if (tPssrPatrolService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有巡检都已确认！");
                }
                doPatrolApprove(tPssrSubcontent);
                break;
            case "aqss"://安全设施
                if (tPssrSafetyBleedService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doAqssApprove(tPssrSubcontent);
                break;
            case "txjk"://通讯监控
                if (tPssrPatrolService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有巡检都已确认！");
                }
                doPatrolApprove(tPssrSubcontent);
                break;
            case "bxsjcy"://便携式检测仪
                if (tPssrPatrolService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有巡检都已确认！");
                }
                doPatrolApprove(tPssrSubcontent);
                break;
            case "gygc"://公用工程
                if (tPssrPublicService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                try {
                    doGygcApprove(tPssrSubcontent);
                } catch (Exception e) {
                    return AjaxResult.error(e.getMessage());
                }
                break;
            case "hbss"://环保设施
                if (tPssrTorchvocService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doHbssApprove(tPssrSubcontent);
                break;
            case "yfl"://原辅料
                if (tPssrMaterialService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0
                        || tPssrMaterialRawService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doYflApprove(tPssrSubcontent);
                break;
            case "jb"://机泵
                if (tPssrPumpCleaningService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doJbApprove(tPssrSubcontent);
                break;
            case "zdj"://支吊架
                if (tPssrFrameService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doZdjApprove(tPssrSubcontent);
                break;
            case "tzsb"://特种设备
                if (tPssrPipeService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0
                        || tPssrVesselService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doTzsbApprove(tPssrSubcontent);
                break;
            case "ybjy"://仪表校验
                if (tPssrInstrumentCalibrationService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doYbjyApprove(tPssrSubcontent);
                break;
            case "yblscs"://仪表联锁测试
                doYblscsApprove(tPssrSubcontent);
                break;
            case "bjlszqr"://报警联锁值确认
                doBjlszqrApprove(tPssrSubcontent);
                break;
            case "lsdy"://临时电源
                if (tPssrPowerService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doLsdyApprove(tPssrSubcontent);
                break;
            case "djsb"://电机设备
                if (tPssrMotorService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doDjsbApprove(tPssrSubcontent);
                break;
            case "zmdbr"://照明、电伴热
                if (tPssrLightingService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doZmdbrApprove(tPssrSubcontent);
                break;
            case "jdjdkj"://静电接地、跨接
                if (tPssrFranklinismService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doJdjdkjApprove(tPssrSubcontent);
                break;
            case "qtjcy"://气体检测仪
                if (tPssrGasdetectorService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doQtjcyApprove(tPssrSubcontent);
                break;
            case "zxfxy"://在线分析仪
                if (tPssrAnalyzerService.selectNoConfirmCount(tPssrSubcontent.getId()) > 0) {
                    return AjaxResult.error("请确认所有确认人都已选择！");
                }
                doZxfxyApprove(tPssrSubcontent);
                break;
            default:
                return AjaxResult.error("申请发起失败！");
        }
        tPssrSubcontent.setApproveStatus(1L);
        tPssrSubcontentService.updateTPssrSubcontent(tPssrSubcontent);
        return AjaxResult.success();
    }

    /**
     * 判断当前发起的审批是否满足前置条件
     */
    private boolean judgmentOrder(TPssrSubcontent sub) {
        TPssrSubcontent subcontent = new TPssrSubcontent();
        subcontent.setAboveallId(sub.getAboveallId());
        List<String> forShorts = new ArrayList<>();
        if ("jb,ybjy".contains(sub.getForShort())) {
        } else if ("sbqjd".contains(sub.getForShort())) {
            forShorts.add("jb");
            forShorts.add("ybjy");
        } else if ("jxxm,sjbg".contains(sub.getForShort())) {
            forShorts.add("sbqjd");
        } else if ("kgfa".contains(sub.getForShort())) {
            forShorts.add("sjbg");
            forShorts.add("jxxm");
        } else if ("mb".contains(sub.getForShort())) {
            forShorts.add("kgfa");
        } else if ("dj,aqss,sksgfmzt,zdj,tzsb".contains(sub.getForShort())) {
            forShorts.add("mb");
        } else if ("xcws,rsfh,xqf,txjk,bxsjcy,hbss".contains(sub.getForShort())) {
            forShorts.add("dj");
            forShorts.add("aqss");
            forShorts.add("zdj");
            forShorts.add("tzsb");
            forShorts.add("sksgfmzt");
        } else if ("sys,gygc,yfl".contains(sub.getForShort())) {
            forShorts.add("xcws");
            forShorts.add("rsfh");
            forShorts.add("xqf");
            forShorts.add("txjk");
            forShorts.add("bxsjcy");
            forShorts.add("hbss");
        } else if ("qm,dqzh".contains(sub.getForShort())) {
            forShorts.add("ssy");
            forShorts.add("gygc");
            forShorts.add("yfl");
        } else if ("djsb".contains(sub.getForShort())) {
            forShorts.add("qm");
            forShorts.add("dqzh");
        } else if ("yblscs".contains(sub.getForShort())) {
            forShorts.add("djsb");
        } else if ("bjlszqr,lsdy,zmdbr,jdjdkj,qtjcy,zxfxy".contains(sub.getForShort())) {
            forShorts.add("yblscs");
        }
        if (CollectionUtils.isNotEmpty(forShorts)) {
            subcontent.setForShorts(forShorts);
            for (TPssrSubcontent tPssrSubcontent : tPssrSubcontentService.selectTPssrSubcontentListByForShort(subcontent)) {
                if (tPssrSubcontent.getApproveStatus() != 2) {
                    return true;
                }
            }
        }
        return false;
    }

    @Log(title = "pssr负责人审批", businessType = BusinessType.UPDATE)
    @PutMapping("/handlePssrApprove")
    public AjaxResult handlePssrApprove(@RequestBody DevTask devTask) {
        TPssrApprove approve = devTask.gettPssrApprove();
        //使用任务服务完成任务(提交任务)
        String taskId = devTask.getTaskId();
        // 使用任务id,获取任务对象，获取流程实例id
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
        //利用任务对象，获取流程实例id
        String taskName = task.getName();//实例名
        String processInstancesId = task.getProcessInstanceId();
        String userId = getUserId().toString();

        String condition = devTask.getCondition();
        boolean allDone = false;
        TPssrSubcontent tPssrSubcontent = tPssrSubcontentService.selectTPssrSubcontentById(approve.getSubId());
        String remark = "";
        if (condition.equals("0")) {
            approve.setApproveStatus(2L);
            tPssrSubcontent.setApproveStatus(2L);
            tPssrSubcontent.setConfirmationDate(new Date());
            tPssrSubcontentService.updateTPssrSubcontent(tPssrSubcontent);
            tPssrApproveService.updateTPssrApprove(approve);
            TPssrSubcontent subcontent = new TPssrSubcontent();
            subcontent.setAboveallId(tPssrSubcontent.getAboveallId());
            for (TPssrSubcontent pssrSubcontent : tPssrSubcontentService.selectTPssrSubcontentList(subcontent)) {
                if (pssrSubcontent.getApproveStatus() != 2) {
                    allDone = false;
                    break;
                }
                allDone = true;
            }
        }
        //处理流程节点
        Map<String, Object> param = new HashMap<>();
        param.put("condition", condition);
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        TaskService taskService = processEngine.getTaskService();
        //认领任务
        processEngine.getTaskService().claim(taskId, userId);
        taskService.addComment(taskId, processInstancesId, remark);
        taskService.complete(taskId, param);

        // 所有流程都结束时，发起经理审批
        if (allDone)
            doMgrApprove(tPssrSubcontent.getAboveallId());
        return AjaxResult.success();
    }

    // pssr发起经理审批
    public void doMgrApprove(Long aboveallId) {
        String userId = getUserId().toString();
        TPssrAboveall aboveall = tPssrAboveallService.selectTPssrAboveallById(aboveallId);

        TStaffmgr tStaffmgr = new TStaffmgr();
        tStaffmgr.setActualposts("24");//装置经理
        tStaffmgr.setDeptId(103L);
        for (SysUser user : userService.selectUserPostPssr(tStaffmgr)) {
            aboveall.setPlantMgr(user.getUserId());
            aboveall.setConfirm(user.getUserId().toString());
        }

        tStaffmgr.setActualposts("40");//ctm经理
        for (SysUser user : userService.selectUserPostPssr(tStaffmgr)) {
            aboveall.setCtmMgr(user.getUserId());
        }

        tStaffmgr.setActualposts("42");//cta经理
        for (SysUser user : userService.selectUserPostPssr(tStaffmgr)) {
            aboveall.setCtaMgr(user.getUserId());
        }
        List<String> executor = new ArrayList<>();
        executor.add(aboveall.getPlantMgr().toString());
        executor.add(aboveall.getCtmMgr().toString());
        executor.add(aboveall.getCtaMgr().toString());

        //设置当前申请人
        Map<String, Object> variables = new HashMap<>();
        variables.put("applyUser", userId);
        variables.put("allJlUsers", executor);
        variables.put("confirmTaskCreateListener", new ConfirmTaskCreateListener());//发送邮件
        variables.put("jlUser", aboveall.getPlantMgr());

        TPssrApprove exist = tPssrApproveService.selectTPssrApproveByAboveallId(aboveallId);
        if (exist == null) {

            TPssrApprove approve = new TPssrApprove();
            approve.setAboveallId(aboveallId);
            approve.setApproveStatus(1L);
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            // 开始申请流程
            long businessKey = approve.getApproveId();
            //开始工作流、监听
            Authentication.setAuthenticatedUserId(userId);
            //采用key来启动流程定义并设置流程变量，返回流程实例
            ProcessInstance pi = runtimeService.startProcessInstanceByKey("pssrMgrConfirm", String.valueOf(businessKey), variables);
            approve.setProcessId(pi.getProcessInstanceId());
            tPssrApproveService.updateTPssrApprove(approve);

        } else {
            delProcess(exist.getProcessId(), "pssrMgrConfirm");

            // 开始申请流程
            long businessKey = exist.getApproveId();
            //开始工作流、监听
            Authentication.setAuthenticatedUserId(userId);
            //采用key来启动流程定义并设置流程变量，返回流程实例
            ProcessInstance pi = runtimeService.startProcessInstanceByKey("pssrMgrConfirm", String.valueOf(businessKey), variables);
            exist.setProcessId(pi.getProcessInstanceId());
            tPssrApproveService.updateTPssrApprove(exist);

        }
        aboveall.setApproveStatus(1L);
        tPssrAboveallService.updateTPssrAboveall(aboveall);
    }

    @PutMapping("/handleMgrApprove")
    public AjaxResult handleMgrApprove(@RequestBody DevTask devTask) throws Exception {
        TPssrApprove approve = devTask.gettPssrApprove();
        //使用任务服务完成任务(提交任务)
        String taskId = devTask.getTaskId();
        // 使用任务id,获取任务对象，获取流程实例id
        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
        //利用任务对象，获取流程实例id
        String taskName = task.getName();//实例名
        String processInstancesId = task.getProcessInstanceId();
        String userId = getUserId().toString();


        String condition = devTask.getCondition();
        TPssrAboveall aboveall = tPssrAboveallService.selectTPssrAboveallById(approve.getAboveallId());

        if (taskName.equals("部门经理")) {
            if (condition.equals("0")) {
                if (userId.equals(aboveall.getPlantMgr().toString())) {
                    aboveall.setPlantConfirmdate(new Date());
                } else if (userId.equals(aboveall.getCtmMgr().toString())) {
                    aboveall.setCtmConfirmdate(new Date());
                } else if (userId.equals(aboveall.getCtaMgr().toString())) {
                    aboveall.setCtaConfirmdate(new Date());
                }
            }
        }
        if (taskName.equals("装置经理")) {
            if (condition.equals("0")) {
                aboveall.setApproveStatus(2L);
                aboveall.setConfirmationDate(new Date());

                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        TPssrApproveController controller = new TPssrApproveController();
                        try {
                            controller.genZip(aboveall);//生成子项文件压缩包
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }).start();
            }
        }
        tPssrAboveallService.updateTPssrAboveall(aboveall);
        //处理流程节点
        Map<String, Object> param = new HashMap<>();
        param.put("condition", condition);
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        TaskService taskService = processEngine.getTaskService();
        //认领任务
        processEngine.getTaskService().claim(taskId, userId);
        taskService.complete(taskId, param);

        return AjaxResult.success();
    }

    /**
     * 生成子项文件压缩包
     */
    @GetMapping("/genZip")
    public void genZip(TPssrAboveall aboveall) throws Exception {
        Long id = aboveall.getId();//主表id
        AjaxResult result = null;
        String msg = "";//导出方法文件名
        String downloadPath = getProfile() + "/download/";//导出方法默认目录
        String path = "";//导出方法默认文件路径=msg+downloadPath
        String rootPath = getProfile() + "/download/pssr_" + id + "_" + UUID.randomUUID().toString() + "/";//即将被打包的根目录
        String subTitle = "";//子表目录字符串
        List<File> files = new ArrayList<>();//文件路径集合
        TPssrSubcontent queryParams = new TPssrSubcontent();
        queryParams.setAboveallId(id);
        List<TPssrSubcontent> tPssrSubcontents = tPssrSubcontentService.selectTPssrSubcontentList(queryParams);//子表集合
        this.createSubitemDirectory(rootPath);//创建子表目录

        subTitle = "00主清单/";//主清单
        TPssrSubcontent subcontent = new TPssrSubcontent();
        subcontent.setAboveallId(aboveall.getId());
        result = subcontentController.export(subcontent);
        msg = (String) result.get("msg");
        msg = msg.replace(File.separator,"/");
        path = getProfile() + msg.replace("/profile", "");
//        this.copyFileIgnoreException(path, rootPath + subTitle + msg.replace("/profile/pssr/", ""), files, rootPath + subTitle + msg);
//        Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg.replace("/profile/pssr/", "")), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//        files.add(new File(rootPath + subTitle + msg));

        // word转pdf
//        String fdfFile = officeConvertController.wordTransPdf(msg);
//        fdfFile = fdfFile.replace(File.separator,"/");
        this.copyFileIgnoreException(getProfile()+msg.replace("/profile", ""), rootPath + subTitle + msg.replace("/profile/temp/", ""), files, rootPath + subTitle + msg);

        for (TPssrSubcontent tPssrSubcontent : tPssrSubcontents) {
            TPssrPatrol patrol = new TPssrPatrol();
            patrol.setSubId(tPssrSubcontent.getId());
            List<TPssrPatrol> tPssrPatrols = tPssrPatrolService.selectTPssrPatrolList(patrol);//巡检集合
            switch (tPssrSubcontent.getForShort()) {
                case "jxxm"://检修项目
                    subTitle = "01检修项目/";
                    TPssrOverhaulFilter filter = new TPssrOverhaulFilter();//过滤器
                    filter.setSubId(tPssrSubcontent.getId());//子表id
                    result = filterController.export(filter);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));

                    TPssrOverhaulTower tower = new TPssrOverhaulTower();//塔罐
                    tower.setSubId(tPssrSubcontent.getId());//子表id
                    result = towerController.export(tower);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));

                    TPssrOverhaulValve valve = new TPssrOverhaulValve();//阀门
                    valve.setSubId(tPssrSubcontent.getId());//子表id
                    result = valveController.export(valve);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));

                    TPssrOverhaulExchanger exchanger = new TPssrOverhaulExchanger();//换热器
                    exchanger.setSubId(tPssrSubcontent.getId());//子表id
                    exchanger.setDevType(1L);
                    result = exchangerController.export(exchanger);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));

                    exchanger.setDevType(2L);
                    result = exchangerController.export(exchanger);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));

                    exchanger.setDevType(3L);
                    result = exchangerController.export(exchanger);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));

                    exchanger.setDevType(4L);
                    result = exchangerController.export(exchanger);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));

                    exchanger.setDevType(5L);
                    result = exchangerController.export(exchanger);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "kgfa"://开工方案
                    subTitle = "02开工方案/";
                    TPssrProgramme programme = new TPssrProgramme();
                    programme.setSubId(tPssrSubcontent.getId());//子表id
                    result = programmeController.export(programme);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    //附件
                    List<TPssrProgramme> tPssrProgrammes = tPssrProgrammeService.selectTPssrProgrammeList(programme);
                    for (TPssrProgramme tPssrProgramme : tPssrProgrammes) {
                        String fileUrl = tPssrProgramme.getFileUrl();
                        String newFileUrl = getProfile() + fileUrl.replace("/profile", "");
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
//                        Files.copy(Paths.get(newFileUrl), Paths.get(rootPath + subTitle + fileUrl.substring(fileUrl.lastIndexOf("/"))), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
                    }
                    break;
                case "sjbg"://设计变更
                    subTitle = "03设计变更/";
                    TPssrMoc moc = new TPssrMoc();
                    moc.setSubId(tPssrSubcontent.getId());//子表id
                    result = mocController.export(moc);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        files.add(new File(path));
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "mb"://盲板
                    subTitle = "04盲板/";
                    TPssrBlind blind = new TPssrBlind();
                    blind.setSubId(tPssrSubcontent.getId());//子表id
                    result = blindController.export(blind);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "xcws"://现场卫生
                    subTitle = "05现场卫生/";
                    TPssrHygiene hygiene = new TPssrHygiene();
                    hygiene.setSubId(tPssrSubcontent.getId());//子表id
                    result = hygieneController.export(hygiene);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "rsfh"://人身防护
                    subTitle = "06人身防护/";
                    TPssrProtection protection = new TPssrProtection();
                    protection.setSubId(tPssrSubcontent.getId());//子表id
                    result = protectionController.export(protection);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
                        files.add(new File(rootPath + subTitle + msg));
                    }

                    TPssrMeasure measure = new TPssrMeasure();
                    measure.setSubId(tPssrSubcontent.getId());//子表id
                    result = measureController.export(measure);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "sbqjd"://设备清洁度
                    subTitle = "07设备清洁度/";
                    TPssrCleaning cleaning = new TPssrCleaning();
                    cleaning.setSubId(tPssrSubcontent.getId());//子表id
                    result = cleaningController.export(cleaning);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "qm"://气密
                    subTitle = "08气密/";
                    TPssrAirtight airtight = new TPssrAirtight();
                    airtight.setSubId(tPssrSubcontent.getId());//子表id
                    result = airtightController.export(airtight);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "sksgfmzt"://锁开锁关阀门状态
                    subTitle = "09锁开锁关阀门状态/";
                    TPssrLock lock = new TPssrLock();
                    lock.setSubId(tPssrSubcontent.getId());//子表id
                    result = lockController.export(lock);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "sys"://实验室
                    subTitle = "10实验室/";
                    TPssrLaboratory laboratory = new TPssrLaboratory();
                    laboratory.setSubId(tPssrSubcontent.getId());//子表id
                    result = laboratoryController.export(laboratory);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "dj"://短接
                    subTitle = "11短接/";
                    TPssrCircuit circuit = new TPssrCircuit();
                    circuit.setSubId(tPssrSubcontent.getId());//子表id
                    result = circuitController.export(circuit);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "dqzh"://氮气置换
                    subTitle = "12氮气置换/";
                    TPssrNitrogen nitrogen = new TPssrNitrogen();
                    nitrogen.setSubId(tPssrSubcontent.getId());//子表id
                    result = nitrogenController.export(nitrogen);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "xqf"://消气防设施（巡检）
                    subTitle = "13消气防设施/";
                    for (TPssrPatrol tPssrPatrol : tPssrPatrols) {
                        String planType = tPssrPatrol.getPlanType().toString();
                        Long planId = tPssrPatrol.getPlanId();
                        TPatrolPlan plan = tPatrolPlanMapper.selectTPatrolPlanById(planId);
                        switch (planType) {
                            case "1"://手提式/小推车式灭火器/灭火器材箱检查记录
                                TFireAnnihilator annihilator = new TFireAnnihilator();
                                annihilator.setPlanId(planId);
                                annihilator.setYear(plan.getPlanYear());
                                result = annihilatorController.export(annihilator);
                                if (result != null) {
                                    msg = (String) result.get("msg");
                                    path = downloadPath + msg;
                                    this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                                }
//                                Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                                files.add(new File(rootPath + subTitle + msg));
                                break;
                            case "2"://消防水炮检查记录
                                TFireWaterCannon waterCannon = new TFireWaterCannon();
                                waterCannon.setPlanId(planId);
                                waterCannon.setYear(plan.getPlanYear());
                                result = waterCannonController.export(waterCannon);
                                if (result != null) {
                                    msg = (String) result.get("msg");
                                    path = downloadPath + msg;
                                    this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                                }
//                                Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                                files.add(new File(rootPath + subTitle + msg));
                                break;
                            case "3"://地上消火栓检查记录
                                TFirePostFire postFire = new TFirePostFire();
                                postFire.setPlanId(planId);
                                postFire.setYear(plan.getPlanYear());
                                result = postFireController.export(postFire);
                                if (result != null) {
                                    msg = (String) result.get("msg");
                                    path = downloadPath + msg;
                                    this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                                }
//                                Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                                files.add(new File(rootPath + subTitle + msg));
                                break;
                            case "4"://消防水带箱检查记录
                                TFireHoseBox hoseBox = new TFireHoseBox();
                                hoseBox.setPlanId(planId);
                                hoseBox.setYear(plan.getPlanYear());
                                result = hoseBoxController.export(hoseBox);
                                if (result != null) {
                                    msg = (String) result.get("msg");
                                    path = downloadPath + msg;
                                    this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                                }
//                                Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                                files.add(new File(rootPath + subTitle + msg));
                                break;
                            case "5"://消防竖管检查记录
                                TFireStandpipePatrol standpipe = new TFireStandpipePatrol();
                                standpipe.setPlanId(planId);
                                standpipe.setYear(plan.getPlanYear());
                                result = standpipeController.export(standpipe);
                                if (result != null) {
                                    msg = (String) result.get("msg");
                                    path = downloadPath + msg;
                                    this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                                }
//                                Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                                files.add(new File(rootPath + subTitle + msg));
                                break;
                            case "6"://自动喷淋灭火系统检查记录
                                TFireSprinkler sprinkler = new TFireSprinkler();
                                sprinkler.setPlanId(planId);
                                sprinkler.setYear(plan.getPlanYear());
                                result = sprinklerController.export(sprinkler);
                                if (result != null) {
                                    msg = (String) result.get("msg");
                                    path = downloadPath + msg;
                                    this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                                }
//                                Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                                files.add(new File(rootPath + subTitle + msg));
                                break;
                            case "7"://应急事故柜检查记录
                                TEmergencyCabinet cabinet = new TEmergencyCabinet();
                                cabinet.setPlanId(planId);
                                cabinet.setYear(plan.getPlanYear());
                                result = cabinetController.export(cabinet);
                                if (result != null) {
                                    msg = (String) result.get("msg");
                                    path = downloadPath + msg;
                                    this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                                }
//                                Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                                files.add(new File(rootPath + subTitle + msg));
                                break;
                            case "8"://现场可燃气体检测器/火灾报警系统检查记录
                                TFireAlarm alarm = new TFireAlarm();
                                alarm.setPlanId(planId);
                                alarm.setYear(plan.getPlanYear());
                                result = alarmController.export(alarm);
                                if (result != null) {
                                    msg = (String) result.get("msg");
                                    path = downloadPath + msg;
                                    this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                                }
//                                Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                                files.add(new File(rootPath + subTitle + msg));
                                break;
                            case "9"://CO2气体保护系统检查记录
                                TFireGasShield gasShield = new TFireGasShield();
                                gasShield.setPlanId(planId);
                                result = gasShieldController.export(gasShield);
                                if (result != null) {
                                    msg = (String) result.get("msg");
                                    path = downloadPath + msg;
                                    this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                                }
//                                Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                                files.add(new File(rootPath + subTitle + msg));
                                break;
                            case "12"://淋浴洗眼器检查记录
                                TEmergencyEyewash eyewash = new TEmergencyEyewash();
                                eyewash.setPlanId(planId);
                                eyewash.setYear(plan.getPlanYear());
                                result = eyewashController.export(eyewash);
                                if (result != null) {
                                    msg = (String) result.get("msg");
                                    path = downloadPath + msg;
                                    this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                                }
//                                Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                                files.add(new File(rootPath + subTitle + msg));
                                break;
                            case "13"://应急沙箱检查记录
                                TFireSandbox sandbox = new TFireSandbox();
                                sandbox.setPlanId(planId);
                                sandbox.setYear(plan.getPlanYear());
                                result = sandboxController.export(sandbox);
                                if (result != null) {
                                    msg = (String) result.get("msg");
                                    path = downloadPath + msg;
                                    this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                                }
//                                Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                                files.add(new File(rootPath + subTitle + msg));
                                break;
                            case "14"://常闭式防爆门/防火门检查记录
                                TFireDoor door = new TFireDoor();
                                door.setPlanId(planId);
                                door.setYear(plan.getPlanYear());
                                result = doorController.export(door);
                                if (result != null) {
                                    msg = (String) result.get("msg");
                                    path = downloadPath + msg;
                                    this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                                }
//                                Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                                files.add(new File(rootPath + subTitle + msg));
                                break;
                            case "15"://风向标/风向袋/新风系统正压计检查记录
                                TFireWeathervane weathervane = new TFireWeathervane();
                                weathervane.setPlanId(planId);
                                weathervane.setYear(plan.getPlanYear());
                                result = weathervaneController.export(weathervane);
                                if (result != null) {
                                    msg = (String) result.get("msg");
                                    path = downloadPath + msg;
                                    this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                                }
//                                Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                                files.add(new File(rootPath + subTitle + msg));
                                break;
                            case "16"://蒸汽幕检查记录
                                TFireSteamCurtain steamCurtain = new TFireSteamCurtain();
                                steamCurtain.setPlanId(planId);
                                steamCurtain.setYear(plan.getPlanYear());
                                result = steamCurtainController.export(steamCurtain);
                                if (result != null) {
                                    msg = (String) result.get("msg");
                                    path = downloadPath + msg;
                                    this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                                }
//                                Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                                files.add(new File(rootPath + subTitle + msg));
                                break;
                            case "27"://急救箱检查记录
                                TFireAidkit aidkit = new TFireAidkit();
                                aidkit.setPlanId(planId);
                                aidkit.setYear(plan.getPlanYear());
                                result = aidkitController.export(aidkit);
                                if (result != null) {
                                    msg = (String) result.get("msg");
                                    path = downloadPath + msg;
                                    this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                                }
//                                Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                                files.add(new File(rootPath + subTitle + msg));
                                break;
                        }
                    }
                    break;
                case "aqss"://安全设施
                    subTitle = "14安全设施/";
                    TPssrSafetyBleed bleed = new TPssrSafetyBleed();
                    bleed.setSubId(tPssrSubcontent.getId());//子表id
                    result = bleedController.export(bleed);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));

                    TPssrSafetyBreath breath = new TPssrSafetyBreath();
                    breath.setSubId(tPssrSubcontent.getId());//子表id
                    result = breathController.export(breath);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));

                    TPssrSafetyBrust brust = new TPssrSafetyBrust();
                    brust.setSubId(tPssrSubcontent.getId());//子表id
                    result = brustController.export(brust);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));

                    TPssrSafetyFlamearrester flamearrester = new TPssrSafetyFlamearrester();
                    flamearrester.setSubId(tPssrSubcontent.getId());//子表id
                    result = flamearresterController.export(flamearrester);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));

                    TPssrSafetyValve safetyValve = new TPssrSafetyValve();
                    safetyValve.setSubId(tPssrSubcontent.getId());//子表id
                    result = safetyValveController.export(safetyValve);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "txjk"://通讯监控（巡检）
                    subTitle = "15通讯监控/";
                    for (TPssrPatrol tPssrPatrol : tPssrPatrols) {
                        String planType = tPssrPatrol.getPlanType().toString();
                        Long planId = tPssrPatrol.getPlanId();
                        TPatrolPlan plan = tPatrolPlanMapper.selectTPatrolPlanById(planId);
                        switch (planType) {
                            case "10"://PAGA系统检查记录
                                TEmergencyPaga paga = new TEmergencyPaga();
                                paga.setPlanId(planId);
                                paga.setYear(plan.getPlanYear());
                                result = pagaController.export(paga);
                                if (result != null) {
                                    msg = (String) result.get("msg");
                                    path = downloadPath + msg;
                                    this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                                }
//                                Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                                files.add(new File(rootPath + subTitle + msg));
                                break;
                            case "11"://CCTV系统检查记录
                                TEmergencyCctv cctv = new TEmergencyCctv();
                                cctv.setPlanId(planId);
                                cctv.setYear(plan.getPlanYear());
                                result = cctvController.export(cctv);
                                if (result != null) {
                                    msg = (String) result.get("msg");
                                    path = downloadPath + msg;
                                    this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                                }
//                                Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                                files.add(new File(rootPath + subTitle + msg));
                                break;
                        }
                    }
                    break;
                case "bxsjcy"://便携式检测仪（巡检）
                    subTitle = "16便携式检测仪/";
                    for (TPssrPatrol tPssrPatrol : tPssrPatrols) {
                        String planType = tPssrPatrol.getPlanType().toString();
                        Long planId = tPssrPatrol.getPlanId();
                        TPatrolPlan plan = tPatrolPlanMapper.selectTPatrolPlanById(planId);
                        switch (planType) {
                            case "18"://四合一/苯系物/硫化氢/二氧化碳/射线一氧化碳检测仪检查记录
                                TCommonuseTester tester = new TCommonuseTester();
                                tester.setPlanId(planId);
                                tester.setYear(plan.getPlanYear());
                                result = testerController.export(tester);
                                if (result != null) {
                                    msg = (String) result.get("msg");
                                    path = downloadPath + msg;
                                    this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                                }
//                                Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                                files.add(new File(rootPath + subTitle + msg));
                                break;
                        }
                    }
                    break;
                case "gygc"://公用工程
                    subTitle = "17公用工程/";
                    TPssrPublic tPssrPublic = new TPssrPublic();
                    tPssrPublic.setSubId(tPssrSubcontent.getId());//子表id
                    result = publicController.export(tPssrPublic);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "hbss"://环保设施
                    subTitle = "18环保设施/";
                    TPssrTorchvoc torchvoc = new TPssrTorchvoc();
                    torchvoc.setSubId(tPssrSubcontent.getId());//子表id
                    torchvoc.setTorchvocType("1");
                    result = torchvocController.export(torchvoc);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));

                    torchvoc.setTorchvocType("2");
                    result = torchvocController.export(torchvoc);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "yfl"://原辅料
                    subTitle = "19原辅料/";
                    TPssrMaterial material = new TPssrMaterial();
                    material.setSubId(tPssrSubcontent.getId());//子表id
                    result = materialController.export(material);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));

//                    TPssrMaterialRaw materialRaw = new TPssrMaterialRaw();
//                    materialRaw.setSubId(tPssrSubcontent.getId());//子表id
//                    result = materialRawController.export(materialRaw);
//                    msg = (String) result.get("msg");
//                    path = downloadPath + msg;
//                    this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "jb"://机泵
                    subTitle = "20机泵/";
                    TPssrPumpCleaning pumpCleaning = new TPssrPumpCleaning();
                    pumpCleaning.setSubId(tPssrSubcontent.getId());//子表id
                    result = pumpCleaningController.export(pumpCleaning);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));

                    TPssrPumpFill pumpFill = new TPssrPumpFill();
                    pumpFill.setSubId(tPssrSubcontent.getId());//子表id
                    result = pumpFillController.export(pumpFill);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));

                    TPssrPumpOverhaul pumpOverhaul = new TPssrPumpOverhaul();
                    pumpOverhaul.setSubId(tPssrSubcontent.getId());//子表id
                    result = pumpOverhaulController.export(pumpOverhaul);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "zdj"://支吊架
                    subTitle = "21支吊架/";
                    TPssrFrame frame = new TPssrFrame();
                    frame.setSubId(tPssrSubcontent.getId());//子表id
                    result = frameController.export(frame);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "tzsb"://压力管道/压力容器
                    subTitle = "22压力管道、压力容器/";
                    TPssrPipe pipe = new TPssrPipe();
                    pipe.setSubId(tPssrSubcontent.getId());//子表id
                    result = pipeController.export(pipe);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));

                    TPssrVessel vessel = new TPssrVessel();
                    vessel.setSubId(tPssrSubcontent.getId());//子表id
                    result = vesselController.export(vessel);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "ybjy"://仪表校验
                    subTitle = "23仪表校验/";
                    TPssrInstrumentCalibration calibration = new TPssrInstrumentCalibration();
                    calibration.setSubId(tPssrSubcontent.getId());//子表id
                    //调节阀
                    calibration.setDevType("1");
                    result = instrumentCalibrationController.export(calibration);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
                    //液位计
                    calibration.setDevType("2");
                    result = instrumentCalibrationController.export(calibration);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
                    //流量计
                    calibration.setDevType("3");
                    result = instrumentCalibrationController.export(calibration);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    try {
//                        Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    } catch (IOException e) {
//                        throw new Exception(e);
//                    }
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "yblscs"://仪表联锁测试
                    subTitle = "24仪表联锁测试/";
                    TPssrInstrumentTest instrumentTest = new TPssrInstrumentTest();
                    instrumentTest.setSubId(tPssrSubcontent.getId());//子表id
                    //附件
                    List<TPssrInstrumentTest> instrumentTests = tPssrInstrumentTestService.selectTPssrInstrumentTestList(instrumentTest);
                    for (TPssrInstrumentTest test : instrumentTests) {
                        String fileUrl = test.getFileUrl();
                        String newFileUrl = getProfile() + fileUrl.replace("/profile", "");
//                        this.copyFileIgnoreException(newFileUrl, rootPath + subTitle + fileUrl.substring(fileUrl.lastIndexOf("/")), files, rootPath + subTitle + msg);
                        try {
                            Files.copy(Paths.get(newFileUrl), Paths.get(rootPath + subTitle + fileUrl.substring(fileUrl.lastIndexOf("/"))), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
                        } catch (IOException e) {
                            logger.error(e.getMessage());
                        }
                    }
                    break;
                case "bjlszqr"://报警/联锁值确认
                    subTitle = "25报警、联锁值确认/";
                    TPssrAlarm pssrAlarm = new TPssrAlarm();
                    pssrAlarm.setSubId(tPssrSubcontent.getId());//子表id
                    //附件
                    List<TPssrAlarm> alarms = tPssrAlarmService.selectTPssrAlarmList(pssrAlarm);
                    for (TPssrAlarm a : alarms) {
                        String fileUrl = a.getFileUrl();
                        String newFileUrl = getProfile() + fileUrl.replace("/profile", "");
//                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                        try {
                            Files.copy(Paths.get(newFileUrl), Paths.get(rootPath + subTitle + fileUrl.substring(fileUrl.lastIndexOf("/"))), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
                        } catch (IOException e) {
                            logger.error(e.getMessage());
                        }
                    }
                    break;
                case "lsdy"://临时电源
                    subTitle = "26临时电源/";
                    TPssrPower power = new TPssrPower();
                    power.setSubId(tPssrSubcontent.getId());//子表id
                    result = powerController.export(power);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "djsb"://电机设备
                    subTitle = "27电机设备/";
                    TPssrMotor motor = new TPssrMotor();
                    motor.setSubId(tPssrSubcontent.getId());//子表id
                    result = motorController.export(motor);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "zmdbr"://照明、电伴热
                    subTitle = "28照明、电伴热/";
                    TPssrLighting lighting = new TPssrLighting();
                    lighting.setSubId(tPssrSubcontent.getId());//子表id
                    lighting.setLightingType("1");
                    result = lightingController.export(lighting);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));

                    lighting.setLightingType("2");
                    result = lightingController.export(lighting);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "jdjdkj"://静电接地/跨接
                    subTitle = "29静电接地、跨接/";
                    TPssrFranklinism franklinism = new TPssrFranklinism();
                    franklinism.setSubId(tPssrSubcontent.getId());//子表id
                    result = franklinismController.export(franklinism);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "qtjcy"://气体检测仪
                    subTitle = "30气体检测仪/";
                    TPssrGasdetector gasdetector = new TPssrGasdetector();
                    gasdetector.setSubId(tPssrSubcontent.getId());//子表id
                    result = gasdetectorController.export(gasdetector);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
                case "zxfxy"://在线分析仪
                    subTitle = "31在线分析仪/";
                    TPssrAnalyzer analyzer = new TPssrAnalyzer();
                    analyzer.setSubId(tPssrSubcontent.getId());//子表id
                    result = analyzerController.export(analyzer);
                    if (result != null) {
                        msg = (String) result.get("msg");
                        path = downloadPath + msg;
                        this.copyFileIgnoreException(path, rootPath + subTitle + msg, files, rootPath + subTitle + msg);
                    }
//                    Files.copy(Paths.get(path), Paths.get(rootPath + subTitle + msg), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
//                    files.add(new File(rootPath + subTitle + msg));
                    break;
            }
        }
        try {
            String zipName = "pssr_" + id + ".zip";
            ZipUtil.toZipWithDirectory(rootPath, downloadPath + zipName);//打包
            aboveall.setZipUrl(zipName);
            tPssrAboveallService.updateTPssrAboveall(aboveall);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void copyFileIgnoreException(String source, String target, List<File> files, String fileName) {
        try {
            Files.copy(Paths.get(source), Paths.get(target), StandardCopyOption.REPLACE_EXISTING);//拷贝导出的文件
            files.add(new File(fileName));
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private void createSubitemDirectory(String rootPath) {
        boolean mkdir0 = new File(rootPath + "00主清单").mkdirs();//子项文件目录
        boolean mkdir1 = new File(rootPath + "01检修项目").mkdirs();//子项文件目录
        boolean mkdir2 = new File(rootPath + "02开工方案").mkdirs();
        boolean mkdir3 = new File(rootPath + "03设计变更").mkdirs();
        boolean mkdir4 = new File(rootPath + "04盲板").mkdirs();
        boolean mkdir5 = new File(rootPath + "05现场卫生").mkdirs();
        boolean mkdir6 = new File(rootPath + "06人身防护").mkdirs();
        boolean mkdir7 = new File(rootPath + "07设备清洁度").mkdirs();
        boolean mkdir8 = new File(rootPath + "08气密").mkdirs();
        boolean mkdir9 = new File(rootPath + "09锁开锁关阀门状态").mkdirs();
        boolean mkdir10 = new File(rootPath + "10实验室").mkdirs();
        boolean mkdir11 = new File(rootPath + "11短接").mkdirs();
        boolean mkdir12 = new File(rootPath + "12氮气置换").mkdirs();
        boolean mkdir13 = new File(rootPath + "13消气防设施").mkdirs();
        boolean mkdir14 = new File(rootPath + "14安全设施").mkdirs();
        boolean mkdir15 = new File(rootPath + "15通讯监控").mkdirs();
        boolean mkdir16 = new File(rootPath + "16便携式检测仪").mkdirs();
        boolean mkdir17 = new File(rootPath + "17公用工程").mkdirs();
        boolean mkdir18 = new File(rootPath + "18环保设施").mkdirs();
        boolean mkdir19 = new File(rootPath + "19原辅料").mkdirs();
        boolean mkdir20 = new File(rootPath + "20机泵").mkdirs();
        boolean mkdir21 = new File(rootPath + "21支吊架").mkdirs();
        boolean mkdir22 = new File(rootPath + "22压力管道、压力容器").mkdirs();
        boolean mkdir23 = new File(rootPath + "23仪表校验").mkdirs();
        boolean mkdir24 = new File(rootPath + "24仪表联锁测试").mkdirs();
        boolean mkdir25 = new File(rootPath + "25报警、联锁值确认").mkdirs();
        boolean mkdir26 = new File(rootPath + "26临时电源").mkdirs();
        boolean mkdir27 = new File(rootPath + "27电机设备").mkdirs();
        boolean mkdir28 = new File(rootPath + "28照明、电伴热").mkdirs();
        boolean mkdir29 = new File(rootPath + "29静电接地、跨接").mkdirs();
        boolean mkdir30 = new File(rootPath + "30气体检测仪").mkdirs();
        boolean mkdir31 = new File(rootPath + "31在线分析仪").mkdirs();
    }

    /**
     * 氮气置换审批流程发起申请
     *
     * @param sub
     */
    private void doDqzhApprove(TPssrSubcontent sub) throws Exception {
        String userId = getUserId().toString();
        //修改状态
        TPssrNitrogen tPssrNitrogen = new TPssrNitrogen();
        tPssrNitrogen.setApproveStatus(0L);
        tPssrNitrogen.setSubId(sub.getId());
        Set<String> confirm1 = new HashSet<>();
        Set<String> confirm2 = new HashSet<>();
        List<TPssrNitrogen> tPssrNitrogens = tPssrNitrogenService.selectTPssrNitrogenList(tPssrNitrogen);
        for (TPssrNitrogen item : tPssrNitrogens) {
            if (!"是".equals(item.getStandard())) {
                throw new Exception("氮气置换检查结果不符合要求，请重新填写！");
            }
        }
        for (TPssrNitrogen item : tPssrNitrogens) {
            item.setApproveStatus(1L);
            item.setUpdatedate(new Date());
            item.setUpdaterCode(userId);
            tPssrNitrogenService.updateTPssrNitrogen(item);

            // 确认人1
            confirm1.add(item.getConfirm1());

            //确认人2
            confirm2.add(item.getConfirm2());
        }

        TPssrApprove exist = new TPssrApprove();
        exist.setSubId(sub.getId());
        List<TPssrApprove> tPssrApproves = tPssrApproveService.selectTPssrApproveList(exist);
        if (CollectionUtil.isEmpty(tPssrApproves)) {
            //新增审批数据
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr2confirm(approve, new ArrayList<>(confirm1), new ArrayList<>(confirm2), sub.getConfirm());
        } else {
            // 已存在流程时，删除旧流程，重新发起
            TPssrApprove approve = tPssrApproves.get(0);
            delProcess(approve.getProcessId(), "pssr2confirm");

            tPssrNitrogen = new TPssrNitrogen();
            tPssrNitrogen.setApproveStatus(1L);
            tPssrNitrogen.setSubId(sub.getId());
            for (TPssrNitrogen item : tPssrNitrogenService.selectTPssrNitrogenList(tPssrNitrogen)) {
                // 确认人1
                confirm1.add(item.getConfirm1());

                //确认人2
                confirm2.add(item.getConfirm2());
            }

            pssr2confirm(approve, new ArrayList<>(confirm1), new ArrayList<>(confirm2), sub.getConfirm());
        }
    }

    // 检修项目审批流程发起申请
    public void doJxxmApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();
        //修改所有表的审批状态
        TPssrOverhaulExchanger exchanger = new TPssrOverhaulExchanger();
        exchanger.setSubId(sub.getId());
        exchanger.setApproveStatus(1L);
        exchanger.setUpdaterCode(userId);
        exchanger.setUpdatedate(new Date());
        tPssrOverhaulExchangerService.updateAllBySubId(exchanger);
        TPssrOverhaulFilter filter = new TPssrOverhaulFilter();
        filter.setSubId(sub.getId());
        filter.setApproveStatus(1L);
        filter.setUpdaterCode(userId);
        filter.setUpdatedate(new Date());
        tPssrOverhaulFilterService.updateAllBySubId(filter);
        TPssrOverhaulPipe pipe = new TPssrOverhaulPipe();
        pipe.setSubId(sub.getId());
        pipe.setApproveStatus(1L);
        pipe.setUpdaterCode(userId);
        pipe.setUpdatedate(new Date());
        tPssrOverhaulPipeService.updateAllBySubId(pipe);
        TPssrOverhaulPump pump = new TPssrOverhaulPump();
        pump.setSubId(sub.getId());
        pump.setApproveStatus(1L);
        pump.setUpdaterCode(userId);
        pump.setUpdatedate(new Date());
        tPssrOverhaulPumpService.updateAllBySubId(pump);
        TPssrOverhaulTower tower = new TPssrOverhaulTower();
        tower.setSubId(sub.getId());
        tower.setApproveStatus(1L);
        tower.setUpdaterCode(userId);
        tower.setUpdatedate(new Date());
        tPssrOverhaulTowerService.updateAllBySubId(tower);
        TPssrOverhaulValve valve = new TPssrOverhaulValve();
        valve.setSubId(sub.getId());
        valve.setApproveStatus(1L);
        valve.setUpdaterCode(userId);
        valve.setUpdatedate(new Date());
        tPssrOverhaulValveService.updateAllBySubId(valve);

        //查询所有确认人
        exchanger = new TPssrOverhaulExchanger();
        exchanger.setSubId(sub.getId());
        exchanger.setApproveStatus(1L);
        TPssrOverhaulExchanger tPssrOverhaulExchanger = tPssrOverhaulExchangerService.selectAllConfirmedPersonBySubId(exchanger);
        String confirmers = null;
        if (tPssrOverhaulExchanger != null) {
            confirmers = tPssrOverhaulExchanger.getConfirmedPerson();
        }
        logger.info("=======================confirmers:{}", confirmers);

        List<String> confirmersList = new ArrayList<>();
        if (StringUtils.isNotEmpty(confirmers)) {
            confirmersList.addAll(Arrays.asList(confirmers.split(",")));
        }

        TPssrApprove exist = new TPssrApprove();
        exist.setSubId(sub.getId());
        List<TPssrApprove> tPssrApproves = tPssrApproveService.selectTPssrApproveList(exist);
        //如果当前子项没有审批数据
        if (CollectionUtil.isEmpty(tPssrApproves)) {
            //新增审批数据
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);
            pssr1confirm(approve, confirmersList, sub.getConfirm());
        } else {
            // 已存在流程时，删除旧流程，重新发起
            TPssrApprove approve = tPssrApproves.get(0);
            delProcess(approve.getProcessId(), "pssr1confirm");
            pssr1confirm(approve, confirmersList, sub.getConfirm());
        }
    }

    // 盲板审批流程发起申请
    public void doMbApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();
        //修改状态
        TPssrBlind tPssrBlind = new TPssrBlind();
        tPssrBlind.setApproveStatus(0L);
        tPssrBlind.setSubId(sub.getId());
        Set<String> installer = new HashSet<>();
        Set<String> remover = new HashSet<>();
        for (TPssrBlind item : tPssrBlindService.selectTPssrBlindList(tPssrBlind)) {
            item.setApproveStatus(1L);
            item.setUpdatedate(new Date());
            item.setUpdaterCode(userId);
            tPssrBlindService.updateTPssrBlind(item);

            // 拆装人员
            installer.add(item.getInConfirm1());
            //确认人
            remover.add(item.getInConfirm2());
        }

        TPssrApprove exist = new TPssrApprove();
        exist.setSubId(sub.getId());
        List<TPssrApprove> tPssrApproves = tPssrApproveService.selectTPssrApproveList(exist);
        if (CollectionUtil.isEmpty(tPssrApproves)) {
            //新增审批数据
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);
            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        } else {
            // 已存在流程时，删除旧流程，重新发起
            TPssrApprove approve = tPssrApproves.get(0);
            delProcess(approve.getProcessId(), "pssr2confirm");

            tPssrBlind = new TPssrBlind();
            tPssrBlind.setApproveStatus(1L);
            tPssrBlind.setSubId(sub.getId());
            for (TPssrBlind item : tPssrBlindService.selectTPssrBlindList(tPssrBlind)) {
                // 拆装人员
                installer.add(item.getInConfirm1());
                //确认人
                remover.add(item.getInConfirm2());
            }
            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        }

    }

    // 锁开锁关审批流程发起申请
    public void doSksgApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();
        //修改状态
        TPssrLock tPssrLock = new TPssrLock();
        tPssrLock.setApproveStatus(0L);
        tPssrLock.setSubId(sub.getId());
        Set<String> lockeders = new HashSet<>();
        Set<String> confirmers = new HashSet<>();
        for (TPssrLock item : tPssrLockService.selectTPssrLockList(tPssrLock)) {
            item.setApproveStatus(1L);
            item.setUpdatedate(new Date());
            item.setUpdaterCode(userId);
            tPssrLockService.updateTPssrLock(item);

            // 确认人1
            lockeders.add(item.getLockeder());

            // 确认人2
            confirmers.add(item.getConfirm());
        }

        TPssrApprove exist = new TPssrApprove();
        exist.setSubId(sub.getId());
        List<TPssrApprove> tPssrApproves = tPssrApproveService.selectTPssrApproveList(exist);
        if (CollectionUtil.isEmpty(tPssrApproves)) {
            //新增审批数据
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);
            pssr2confirm(approve, new ArrayList<>(lockeders), new ArrayList<>(confirmers), sub.getConfirm());
        } else {
            // 已存在流程时，删除旧流程，重新发起
            TPssrApprove approve = tPssrApproves.get(0);
            delProcess(approve.getProcessId(), "pssr2confirm");

            tPssrLock = new TPssrLock();
            tPssrLock.setApproveStatus(1L);
            tPssrLock.setSubId(sub.getId());
            for (TPssrLock item : tPssrLockService.selectTPssrLockList(tPssrLock)) {

                // 确认人1
                lockeders.add(item.getLockeder());

                // 确认人2
                confirmers.add(item.getConfirm());
            }
            pssr2confirm(approve, new ArrayList<>(lockeders), new ArrayList<>(confirmers), sub.getConfirm());
        }

    }

    // 管道审批流程发起申请
    public void doTzsbApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();


        TPssrPipe pipe = new TPssrPipe();
        pipe.setSubId(sub.getId());
        pipe.setApproveStatus(1L);
        pipe.setUpdatedate(new Date());
        pipe.setUpdaterCode(userId);
        tPssrPipeService.updateAllBySubId(pipe);
        TPssrVessel vessel = new TPssrVessel();
        vessel.setSubId(sub.getId());
        vessel.setApproveStatus(1L);
        vessel.setUpdatedate(new Date());
        vessel.setUpdaterCode(userId);
        tPssrVesselService.updateAllBySubId(vessel);

        //查询确认人
        TPssrPipe entity = new TPssrPipe();
        entity.setSubId(sub.getId());
        entity.setApproveStatus(1L);
        TPssrPipe tPssrPipe = tPssrPipeService.selectAllConfirmedPersonBySubId(entity);
        String confirmer1s = null;
        String confirmer2s = null;
        if (tPssrPipe != null) {
            confirmer1s = tPssrPipe.getConfirmer1();
            confirmer2s = tPssrPipe.getConfirmer2();
        }
        logger.info("=======================confirmer1s:{}", confirmer1s);
        logger.info("=======================confirmer2s:{}", confirmer2s);

        Set<String> confirmerUsers1 = new HashSet<>();
        Set<String> confirmerUsers2 = new HashSet<>();
        if (StringUtils.isNotEmpty(confirmer1s)) {
            confirmerUsers1.addAll(Arrays.asList(confirmer1s.split(",")));
        }
        if (StringUtils.isNotEmpty(confirmer2s)) {
            confirmerUsers2.addAll(Arrays.asList(confirmer2s.split(",")));
        }

        TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(sub.getId());
        if (tPssrApprove == null) {
            //新增审批数据
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr2confirm(approve, new ArrayList<>(confirmerUsers1), new ArrayList<>(confirmerUsers2), sub.getConfirm());
        } else {
            // 已存在流程时，删除旧流程，重新发起
            delProcess(tPssrApprove.getProcessId(), "pssr2confirm");
            entity.setApproveStatus(3L);
            tPssrPipe = tPssrPipeService.selectAllConfirmedPersonBySubId(entity);
            if (tPssrPipe != null) {
                confirmer1s = tPssrPipe.getConfirmer1();
                confirmer2s = tPssrPipe.getConfirmer2();
            }

            if (StringUtils.isNotEmpty(confirmer1s)) {
                confirmerUsers1.addAll(Arrays.asList(confirmer1s.split(",")));
            }
            if (StringUtils.isNotEmpty(confirmer2s)) {
                confirmerUsers2.addAll(Arrays.asList(confirmer2s.split(",")));
            }
            pssr2confirm(tPssrApprove, new ArrayList<>(confirmerUsers1), new ArrayList<>(confirmerUsers2), sub.getConfirm());
        }

    }

    //巡检审批流程发起申请
    public void doPatrolApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();
        TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(sub.getId());
        if (tPssrApprove == null) {
            TPssrApprove approve = new TPssrApprove();//新增审批数据
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr1confirm(approve, new ArrayList<>(), sub.getConfirm());
        } else {
            delProcess(tPssrApprove.getProcessId(), "pssr1confirm");

            pssr1confirm(tPssrApprove, new ArrayList<>(), sub.getConfirm());

        }
    }

    /**
     * 安全设施审批流程发起申请
     */
    private void doAqssApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();

        //修改各表状态
        TPssrSafetyBleed bleed = new TPssrSafetyBleed();
        bleed.setSubId(sub.getId());
        bleed.setApproveStatus(1L);
        bleed.setUpdatedate(new Date());
        bleed.setUpdaterCode(userId);
        tPssrSafetyBleedService.updateAllBySubId(bleed);
        TPssrSafetyBreath breath = new TPssrSafetyBreath();
        breath.setSubId(sub.getId());
        breath.setApproveStatus(1L);
        breath.setUpdatedate(new Date());
        breath.setUpdaterCode(userId);
        tPssrSafetyBreathService.updateAllBySubId(breath);
        TPssrSafetyBrust brust = new TPssrSafetyBrust();
        brust.setSubId(sub.getId());
        brust.setApproveStatus(1L);
        brust.setUpdatedate(new Date());
        brust.setUpdaterCode(userId);
        tPssrSafetyBrustService.updateAllBySubId(brust);
        TPssrSafetyFlamearrester flamearrester = new TPssrSafetyFlamearrester();
        flamearrester.setSubId(sub.getId());
        flamearrester.setApproveStatus(1L);
        flamearrester.setUpdatedate(new Date());
        flamearrester.setUpdaterCode(userId);
        tPssrSafetyFlamearresterService.updateAllBySubId(flamearrester);
        TPssrSafetyValve valve = new TPssrSafetyValve();
        valve.setSubId(sub.getId());
        valve.setApproveStatus(1L);
        valve.setUpdatedate(new Date());
        valve.setUpdaterCode(userId);
        tPssrSafetyValveService.updateAllBySubId(valve);

        // 查询确认人
        TPssrSafetyBleed entity = new TPssrSafetyBleed();
        entity.setSubId(sub.getId());
        entity.setApproveStatus(1L);
        TPssrSafetyBleed tPssrSafetyBleed = tPssrSafetyBleedService.selectAllConfirmedPersonBySubId(entity);
        String confirmer1s = null;
        String confirmer2s = null;
        if (tPssrSafetyBleed != null) {
            confirmer1s = tPssrSafetyBleed.getConfirmer1();
            confirmer2s = tPssrSafetyBleed.getConfirmer2();
        }
        logger.info("=======================confirmer1s:{}", confirmer1s);
        logger.info("=======================confirmer2s:{}", confirmer2s);

        Set<String> confirmerUsers1 = new HashSet<>();
        Set<String> confirmerUsers2 = new HashSet<>();
        if (StringUtils.isNotEmpty(confirmer1s)) {
            confirmerUsers1.addAll(Arrays.asList(confirmer1s.split(",")));
        }
        if (StringUtils.isNotEmpty(confirmer2s)) {
            confirmerUsers2.addAll(Arrays.asList(confirmer2s.split(",")));
        }
        //查询是否已存在审批流程
        TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(sub.getId());
        if (tPssrApprove == null) {
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr2confirm(approve, new ArrayList<>(confirmerUsers1), new ArrayList<>(confirmerUsers2), sub.getConfirm());
        } else {
            delProcess(tPssrApprove.getProcessId(), "pssr2confirm");
            entity.setSubId(sub.getId());
            entity.setApproveStatus(3L);
            tPssrSafetyBleed = tPssrSafetyBleedService.selectAllConfirmedPersonBySubId(entity);
            if (tPssrSafetyBleed != null) {
                confirmer1s = tPssrSafetyBleed.getConfirmer1();
                confirmer2s = tPssrSafetyBleed.getConfirmer2();
            }

            if (StringUtils.isNotEmpty(confirmer1s)) {
                confirmerUsers1.addAll(Arrays.asList(confirmer1s.split(",")));
            }
            if (StringUtils.isNotEmpty(confirmer2s)) {
                confirmerUsers2.addAll(Arrays.asList(confirmer2s.split(",")));
            }
            pssr2confirm(tPssrApprove, new ArrayList<>(confirmerUsers1), new ArrayList<>(confirmerUsers2), sub.getConfirm());
        }
    }

    // 现场卫生流程发起申请
    public void doXcwsApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();
        //修改状态
        TPssrHygiene tPssrHygiene = new TPssrHygiene();
        tPssrHygiene.setApproveStatus(0L);
        tPssrHygiene.setSubId(sub.getId());
        Set<String> installer = new HashSet<>();
        Set<String> remover = new HashSet<>();
        for (TPssrHygiene item : tPssrHygieneService.selectTPssrHygieneList(tPssrHygiene)) {
            item.setApproveStatus(1L);
            item.setUpdatedate(new Date());
            item.setUpdaterCode(userId);
            tPssrHygieneService.updateTPssrHygiene(item);

            // 安装人员
            installer.add(item.getConfirm1());

            //拆除人员
            remover.add(item.getConfirm2());
        }

        TPssrApprove exist = new TPssrApprove();
        exist.setSubId(sub.getId());
        List<TPssrApprove> tPssrApproves = tPssrApproveService.selectTPssrApproveList(exist);
        if (CollectionUtil.isEmpty(tPssrApproves)) {
            //新增审批数据
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        } else {
            // 已存在流程时，删除旧流程，重新发起
            TPssrApprove approve = tPssrApproves.get(0);
            delProcess(approve.getProcessId(), "pssr2confirm");

            tPssrHygiene = new TPssrHygiene();
            tPssrHygiene.setApproveStatus(1L);
            tPssrHygiene.setSubId(sub.getId());
            for (TPssrHygiene item : tPssrHygieneService.selectTPssrHygieneList(tPssrHygiene)) {
                // 安装人员
                installer.add(item.getConfirm1());

                //拆除人员
                remover.add(item.getConfirm2());
            }
            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        }

    }

    // 设备清洁度流程发起申请
    public void doSbqjdApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();
        //修改状态
        TPssrCleaning tPssrCleaning = new TPssrCleaning();
        tPssrCleaning.setApproveStatus(0L);
        tPssrCleaning.setSubId(sub.getId());
        Set<String> installer = new HashSet<>();
        Set<String> remover = new HashSet<>();
        for (TPssrCleaning item : tPssrCleaningService.selectTPssrCleaningList(tPssrCleaning)) {
            item.setApproveStatus(1L);
            item.setUpdatedate(new Date());
            item.setUpdaterCode(userId);
            tPssrCleaningService.updateTPssrCleaning(item);

            // 安装人员
            installer.add(item.getConfirm1());

            //拆除人员
            remover.add(item.getConfirm2());
        }

        TPssrApprove exist = new TPssrApprove();
        exist.setSubId(sub.getId());
        List<TPssrApprove> tPssrApproves = tPssrApproveService.selectTPssrApproveList(exist);
        if (CollectionUtil.isEmpty(tPssrApproves)) {
            //新增审批数据
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);
            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        } else {
            // 已存在流程时，删除旧流程，重新发起
            TPssrApprove approve = tPssrApproves.get(0);
            delProcess(approve.getProcessId(), "pssr2confirm");

            tPssrCleaning = new TPssrCleaning();
            tPssrCleaning.setApproveStatus(1L);
            tPssrCleaning.setSubId(sub.getId());
            for (TPssrCleaning item : tPssrCleaningService.selectTPssrCleaningList(tPssrCleaning)) {
                // 安装人员
                installer.add(item.getConfirm1());

                //拆除人员
                remover.add(item.getConfirm2());
            }
            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        }

    }

    // 气密流程发起申请
    public void doQmApprove(TPssrSubcontent sub) throws Exception {
        String userId = getUserId().toString();
        //修改状态
        TPssrAirtight tPssrAirtight = new TPssrAirtight();
        tPssrAirtight.setApproveStatus(0L);
        tPssrAirtight.setSubId(sub.getId());
        Set<String> installer = new HashSet<>();
        Set<String> remover = new HashSet<>();
        List<TPssrAirtight> tPssrAirtights = tPssrAirtightService.selectTPssrAirtightList(tPssrAirtight);
        for (TPssrAirtight item : tPssrAirtights) {
            if (!"是".equals(item.getUptoStandard())) {
                throw new Exception("气密性测试标准为否，请重新检查！");
            }
        }
        for (TPssrAirtight item : tPssrAirtights) {
            item.setApproveStatus(1L);
            item.setUpdatedate(new Date());
            item.setUpdaterCode(userId);
            tPssrAirtightService.updateTPssrAirtight(item);

            // 安装人员
            installer.add(item.getConfirm1());

            //拆除人员
            remover.add(item.getConfirm2());
        }

        TPssrApprove exist = new TPssrApprove();
        exist.setSubId(sub.getId());
        List<TPssrApprove> tPssrApproves = tPssrApproveService.selectTPssrApproveList(exist);
        if (CollectionUtil.isEmpty(tPssrApproves)) {
            //新增审批数据
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);
            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        } else {
            // 已存在流程时，删除旧流程，重新发起
            TPssrApprove approve = tPssrApproves.get(0);
            delProcess(approve.getProcessId(), "pssr2confirm");

            tPssrAirtight = new TPssrAirtight();
            tPssrAirtight.setApproveStatus(1L);
            tPssrAirtight.setSubId(sub.getId());
            for (TPssrAirtight item : tPssrAirtightService.selectTPssrAirtightList(tPssrAirtight)) {
                // 安装人员
                installer.add(item.getConfirm1());

                //拆除人员
                remover.add(item.getConfirm2());
            }
            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        }

    }

    // 实验室流程发起申请
    public void doSysApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();
        //修改状态
        TPssrLaboratory tPssrLaboratory = new TPssrLaboratory();
        tPssrLaboratory.setApproveStatus(0L);
        tPssrLaboratory.setSubId(sub.getId());
        Set<String> installer = new HashSet<>();
        Set<String> remover = new HashSet<>();
        for (TPssrLaboratory item : tPssrLaboratoryService.selectTPssrLaboratoryList(tPssrLaboratory)) {
            item.setApproveStatus(1L);
            item.setUpdatedate(new Date());
            item.setUpdaterCode(userId);
            tPssrLaboratoryService.updateTPssrLaboratory(item);

            // 安装人员
            installer.add(item.getConfirm1());

            //拆除人员
            remover.add(item.getConfirm2());
        }

        TPssrApprove exist = new TPssrApprove();
        exist.setSubId(sub.getId());
        List<TPssrApprove> tPssrApproves = tPssrApproveService.selectTPssrApproveList(exist);
        if (CollectionUtil.isEmpty(tPssrApproves)) {
            //新增审批数据
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);
            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        } else {
            // 已存在流程时，删除旧流程，重新发起
            TPssrApprove approve = tPssrApproves.get(0);
            delProcess(approve.getProcessId(), "pssr2confirm");

            tPssrLaboratory = new TPssrLaboratory();
            tPssrLaboratory.setApproveStatus(1L);
            tPssrLaboratory.setSubId(sub.getId());
            for (TPssrLaboratory item : tPssrLaboratoryService.selectTPssrLaboratoryList(tPssrLaboratory)) {
                // 安装人员
                installer.add(item.getConfirm1());

                //拆除人员
                remover.add(item.getConfirm2());
            }
            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        }

    }

    // 短接流程发起申请
    public void doDjApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();
        //修改状态
        TPssrCircuit tPssrCircuit = new TPssrCircuit();
        tPssrCircuit.setApproveStatus(0L);
        tPssrCircuit.setSubId(sub.getId());
        Set<String> installer = new HashSet<>();
        Set<String> remover = new HashSet<>();
        for (TPssrCircuit item : tPssrCircuitService.selectTPssrCircuitList(tPssrCircuit)) {
            item.setApproveStatus(1L);
            item.setUpdatedate(new Date());
            item.setUpdaterCode(userId);
            tPssrCircuitService.updateTPssrCircuit(item);

            // 安装人员
            installer.add(item.getConfirm1());

            //拆除人员
            remover.add(item.getConfirm2());
        }

        TPssrApprove exist = new TPssrApprove();
        exist.setSubId(sub.getId());
        List<TPssrApprove> tPssrApproves = tPssrApproveService.selectTPssrApproveList(exist);
        if (CollectionUtil.isEmpty(tPssrApproves)) {
            //新增审批数据
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        } else {
            // 已存在流程时，删除旧流程，重新发起
            TPssrApprove approve = tPssrApproves.get(0);
            delProcess(approve.getProcessId(), "pssr2confirm");

            tPssrCircuit = new TPssrCircuit();
            tPssrCircuit.setApproveStatus(1L);
            tPssrCircuit.setSubId(sub.getId());
            for (TPssrCircuit item : tPssrCircuitService.selectTPssrCircuitList(tPssrCircuit)) {
                // 安装人员
                installer.add(item.getConfirm1());

                //拆除人员
                remover.add(item.getConfirm2());
            }

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        }
    }

    // 公用工程流程发起申请
    public void doGygcApprove(TPssrSubcontent sub) throws Exception {
        String userId = getUserId().toString();
        //修改状态
        TPssrPublic tPssrPublic = new TPssrPublic();
        tPssrPublic.setApproveStatus(0L);
        tPssrPublic.setSubId(sub.getId());
        Set<String> installer = new HashSet<>();
        Set<String> remover = new HashSet<>();
        List<TPssrPublic> tPssrPublics = tPssrPublicService.selectTPssrPublicList(tPssrPublic);
        for (TPssrPublic item : tPssrPublics) {
            if (!"✔".equals(item.getCheckResult())) {
                throw new Exception("公用工程检查结果不合规！请重新检查！");
            }
        }
        for (TPssrPublic item : tPssrPublics) {
            item.setApproveStatus(1L);
            item.setUpdatedate(new Date());
            item.setUpdaterCode(userId);
            tPssrPublicService.updateTPssrPublic(item);

            // 安装人员
            installer.add(item.getConfirm1());

            //拆除人员
            remover.add(item.getConfirm2());
        }

        TPssrApprove exist = new TPssrApprove();
        exist.setSubId(sub.getId());
        List<TPssrApprove> tPssrApproves = tPssrApproveService.selectTPssrApproveList(exist);
        if (CollectionUtil.isEmpty(tPssrApproves)) {
            //新增审批数据
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        } else {
            // 已存在流程时，删除旧流程，重新发起
            TPssrApprove approve = tPssrApproves.get(0);
            delProcess(approve.getProcessId(), "pssr2confirm");

            tPssrPublic = new TPssrPublic();
            tPssrPublic.setApproveStatus(1L);
            tPssrPublic.setSubId(sub.getId());
            for (TPssrPublic item : tPssrPublicService.selectTPssrPublicList(tPssrPublic)) {
                // 安装人员
                installer.add(item.getConfirm1());

                //拆除人员
                remover.add(item.getConfirm2());
            }

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        }
    }

    // 环保设施流程发起申请
    public void doHbssApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();
        //修改状态
        TPssrTorchvoc tPssrTorchvoc = new TPssrTorchvoc();
        tPssrTorchvoc.setApproveStatus(0L);
        tPssrTorchvoc.setSubId(sub.getId());
        Set<String> installer = new HashSet<>();
        Set<String> remover = new HashSet<>();
        for (TPssrTorchvoc item : tPssrTorchvocService.selectTPssrTorchvocList(tPssrTorchvoc)) {
            item.setApproveStatus(1L);
            item.setUpdatedate(new Date());
            item.setUpdaterCode(userId);
            tPssrTorchvocService.updateTPssrTorchvoc(item);

            // 安装人员
            installer.add(item.getConfirm1());

            //拆除人员
            remover.add(item.getConfirm2());
        }

        TPssrApprove exist = new TPssrApprove();
        exist.setSubId(sub.getId());
        List<TPssrApprove> tPssrApproves = tPssrApproveService.selectTPssrApproveList(exist);
        if (CollectionUtil.isEmpty(tPssrApproves)) {
            //新增审批数据
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        } else {
            // 已存在流程时，删除旧流程，重新发起
            TPssrApprove approve = tPssrApproves.get(0);
            delProcess(approve.getProcessId(), "pssr2confirm");

            tPssrTorchvoc = new TPssrTorchvoc();
            tPssrTorchvoc.setApproveStatus(1L);
            tPssrTorchvoc.setSubId(sub.getId());
            for (TPssrTorchvoc item : tPssrTorchvocService.selectTPssrTorchvocList(tPssrTorchvoc)) {
                // 安装人员
                installer.add(item.getConfirm1());

                //拆除人员
                remover.add(item.getConfirm2());
            }

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        }
    }

    // 照明、电伴热流程发起申请
    public void doZmdbrApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();
        //修改状态
        TPssrLighting tPssrLighting = new TPssrLighting();
        tPssrLighting.setApproveStatus(0L);
        tPssrLighting.setSubId(sub.getId());
        Set<String> installer = new HashSet<>();
        Set<String> remover = new HashSet<>();
        for (TPssrLighting item : tPssrLightingService.selectTPssrLightingList(tPssrLighting)) {
            item.setApproveStatus(1L);
            item.setUpdatedate(new Date());
            item.setUpdaterCode(userId);
            tPssrLightingService.updateTPssrLighting(item);

            // 安装人员
            installer.add(item.getConfirm1());

            //拆除人员
            remover.add(item.getConfirm2());
        }

        TPssrApprove exist = new TPssrApprove();
        exist.setSubId(sub.getId());
        List<TPssrApprove> tPssrApproves = tPssrApproveService.selectTPssrApproveList(exist);
        if (CollectionUtil.isEmpty(tPssrApproves)) {
            //新增审批数据
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        } else {
            // 已存在流程时，删除旧流程，重新发起
            TPssrApprove approve = tPssrApproves.get(0);
            delProcess(approve.getProcessId(), "pssr2confirm");

            tPssrLighting = new TPssrLighting();
            tPssrLighting.setApproveStatus(1L);
            tPssrLighting.setSubId(sub.getId());
            for (TPssrLighting item : tPssrLightingService.selectTPssrLightingList(tPssrLighting)) {
                // 安装人员
                installer.add(item.getConfirm1());

                //拆除人员
                remover.add(item.getConfirm2());
            }

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        }
    }

    // 支吊架流程发起申请
    public void doZdjApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();
        //修改状态
        TPssrFrame tPssrFrame = new TPssrFrame();
        tPssrFrame.setApproveStatus(0L);
        tPssrFrame.setSubId(sub.getId());
        Set<String> installer = new HashSet<>();
        Set<String> remover = new HashSet<>();
        for (TPssrFrame item : tPssrFrameService.selectTPssrFrameList(tPssrFrame)) {
            item.setApproveStatus(1L);
            item.setUpdatedate(new Date());
            item.setUpdaterCode(userId);
            tPssrFrameService.updateTPssrFrame(item);

            // 安装人员
            installer.add(item.getConfirm1());

            //拆除人员
            remover.add(item.getConfirm2());
        }

        TPssrApprove exist = new TPssrApprove();
        exist.setSubId(sub.getId());
        List<TPssrApprove> tPssrApproves = tPssrApproveService.selectTPssrApproveList(exist);
        if (CollectionUtil.isEmpty(tPssrApproves)) {
            //新增审批数据
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        } else {
            // 已存在流程时，删除旧流程，重新发起
            TPssrApprove approve = tPssrApproves.get(0);
            delProcess(approve.getProcessId(), "pssr2confirm");

            tPssrFrame = new TPssrFrame();
            tPssrFrame.setApproveStatus(1L);
            tPssrFrame.setSubId(sub.getId());
            for (TPssrFrame item : tPssrFrameService.selectTPssrFrameList(tPssrFrame)) {
                // 安装人员
                installer.add(item.getConfirm1());

                //拆除人员
                remover.add(item.getConfirm2());
            }

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        }
    }

    // 仪表校验流程发起申请
    public void doYbjyApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();
        //修改状态
        TPssrInstrumentCalibration tPssrInstrumentCalibration = new TPssrInstrumentCalibration();
        tPssrInstrumentCalibration.setApproveStatus(0L);
        tPssrInstrumentCalibration.setSubId(sub.getId());
        Set<String> installer = new HashSet<>();
        Set<String> remover = new HashSet<>();
        for (TPssrInstrumentCalibration item : tPssrInstrumentCalibrationService.selectTPssrInstrumentCalibrationList(tPssrInstrumentCalibration)) {
            item.setApproveStatus(1L);
            item.setUpdatedate(new Date());
            item.setUpdaterCode(userId);
            tPssrInstrumentCalibrationService.updateTPssrInstrumentCalibration(item);

            // 安装人员
            installer.add(item.getConfirm1());

            //拆除人员
            remover.add(item.getConfirm2());
        }

        TPssrApprove exist = new TPssrApprove();
        exist.setSubId(sub.getId());
        List<TPssrApprove> tPssrApproves = tPssrApproveService.selectTPssrApproveList(exist);
        if (CollectionUtil.isEmpty(tPssrApproves)) {
            //新增审批数据
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        } else {
            // 已存在流程时，删除旧流程，重新发起
            TPssrApprove approve = tPssrApproves.get(0);
            delProcess(approve.getProcessId(), "pssr2confirm");

            tPssrInstrumentCalibration = new TPssrInstrumentCalibration();
            tPssrInstrumentCalibration.setApproveStatus(1L);
            tPssrInstrumentCalibration.setSubId(sub.getId());
            for (TPssrInstrumentCalibration item : tPssrInstrumentCalibrationService.selectTPssrInstrumentCalibrationList(tPssrInstrumentCalibration)) {
                // 安装人员
                installer.add(item.getConfirm1());

                //拆除人员
                remover.add(item.getConfirm2());
            }

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        }
    }

    //临时电源流程发起申请
    public void doLsdyApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();
        //修改状态
        TPssrPower tPssrPower = new TPssrPower();
        tPssrPower.setApproveStatus(0L);
        tPssrPower.setSubId(sub.getId());
        Set<String> installer = new HashSet<>();
        Set<String> remover = new HashSet<>();
        for (TPssrPower item : tPssrPowerService.selectTPssrPowerList(tPssrPower)) {
            item.setApproveStatus(1L);
            item.setUpdatedate(new Date());
            item.setUpdaterCode(userId);
            tPssrPowerService.updateTPssrPower(item);

            // 安装人员
            installer.add(item.getConfirm1());

            //拆除人员
            remover.add(item.getConfirm2());
        }

        TPssrApprove exist = new TPssrApprove();
        exist.setSubId(sub.getId());
        List<TPssrApprove> tPssrApproves = tPssrApproveService.selectTPssrApproveList(exist);
        if (CollectionUtil.isEmpty(tPssrApproves)) {
            //新增审批数据
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        } else {
            // 已存在流程时，删除旧流程，重新发起
            TPssrApprove approve = tPssrApproves.get(0);
            delProcess(approve.getProcessId(), "pssr2confirm");

            tPssrPower = new TPssrPower();
            tPssrPower.setApproveStatus(1L);
            tPssrPower.setSubId(sub.getId());
            for (TPssrPower item : tPssrPowerService.selectTPssrPowerList(tPssrPower)) {
                // 安装人员
                installer.add(item.getConfirm1());

                //拆除人员
                remover.add(item.getConfirm2());
            }

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        }
    }

    //电机设备流程发起申请
    public void doDjsbApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();
        //修改状态
        TPssrMotor tPssrMotor = new TPssrMotor();
        tPssrMotor.setApproveStatus(0L);
        tPssrMotor.setSubId(sub.getId());
        Set<String> installer = new HashSet<>();
        Set<String> remover = new HashSet<>();
        for (TPssrMotor item : tPssrMotorService.selectTPssrMotorList(tPssrMotor)) {
            item.setApproveStatus(1L);
            item.setUpdatedate(new Date());
            item.setUpdaterCode(userId);
            tPssrMotorService.updateTPssrMotor(item);

            // 安装人员
            installer.add(item.getConfirm1());

            //拆除人员
            remover.add(item.getConfirm2());
        }

        TPssrApprove exist = new TPssrApprove();
        exist.setSubId(sub.getId());
        List<TPssrApprove> tPssrApproves = tPssrApproveService.selectTPssrApproveList(exist);
        if (CollectionUtil.isEmpty(tPssrApproves)) {
            //新增审批数据
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        } else {
            // 已存在流程时，删除旧流程，重新发起
            TPssrApprove approve = tPssrApproves.get(0);
            delProcess(approve.getProcessId(), "pssr2confirm");

            tPssrMotor = new TPssrMotor();
            tPssrMotor.setApproveStatus(1L);
            tPssrMotor.setSubId(sub.getId());
            for (TPssrMotor item : tPssrMotorService.selectTPssrMotorList(tPssrMotor)) {
                // 安装人员
                installer.add(item.getConfirm1());

                //拆除人员
                remover.add(item.getConfirm2());
            }

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        }
    }

    //静电接地、跨接流程发起申请
    public void doJdjdkjApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();
        //修改状态
        TPssrFranklinism tPssrFranklinism = new TPssrFranklinism();
        tPssrFranklinism.setApproveStatus(0L);
        tPssrFranklinism.setSubId(sub.getId());
        Set<String> installer = new HashSet<>();
        Set<String> remover = new HashSet<>();
        for (TPssrFranklinism item : tPssrFranklinismService.selectTPssrFranklinismList(tPssrFranklinism)) {
            item.setApproveStatus(1L);
            item.setUpdatedate(new Date());
            item.setUpdaterCode(userId);
            tPssrFranklinismService.updateTPssrFranklinism(item);

            // 安装人员
            installer.add(item.getConfirm1());

            //拆除人员
            remover.add(item.getConfirm2());
        }

        TPssrApprove exist = new TPssrApprove();
        exist.setSubId(sub.getId());
        List<TPssrApprove> tPssrApproves = tPssrApproveService.selectTPssrApproveList(exist);
        if (CollectionUtil.isEmpty(tPssrApproves)) {
            //新增审批数据
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        } else {
            // 已存在流程时，删除旧流程，重新发起
            TPssrApprove approve = tPssrApproves.get(0);
            delProcess(approve.getProcessId(), "pssr2confirm");

            tPssrFranklinism = new TPssrFranklinism();
            tPssrFranklinism.setApproveStatus(1L);
            tPssrFranklinism.setSubId(sub.getId());
            for (TPssrFranklinism item : tPssrFranklinismService.selectTPssrFranklinismList(tPssrFranklinism)) {
                // 安装人员
                installer.add(item.getConfirm1());

                //拆除人员
                remover.add(item.getConfirm2());
            }

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        }
    }

    //气体检测仪流程发起申请
    public void doQtjcyApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();
        //修改状态
        TPssrGasdetector tPssrGasdetector = new TPssrGasdetector();
        tPssrGasdetector.setApproveStatus(0L);
        tPssrGasdetector.setSubId(sub.getId());
        Set<String> installer = new HashSet<>();
        Set<String> remover = new HashSet<>();
        for (TPssrGasdetector item : tPssrGasdetectorService.selectTPssrGasdetectorList(tPssrGasdetector)) {
            item.setApproveStatus(1L);
            item.setUpdatedate(new Date());
            item.setUpdaterCode(userId);
            tPssrGasdetectorService.updateTPssrGasdetector(item);

            // 安装人员
            installer.add(item.getConfirm1());

            //拆除人员
            remover.add(item.getConfirm2());
        }

        TPssrApprove exist = new TPssrApprove();
        exist.setSubId(sub.getId());
        List<TPssrApprove> tPssrApproves = tPssrApproveService.selectTPssrApproveList(exist);
        if (CollectionUtil.isEmpty(tPssrApproves)) {
            //新增审批数据
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        } else {
            // 已存在流程时，删除旧流程，重新发起
            TPssrApprove approve = tPssrApproves.get(0);
            delProcess(approve.getProcessId(), "pssr2confirm");

            tPssrGasdetector = new TPssrGasdetector();
            tPssrGasdetector.setApproveStatus(1L);
            tPssrGasdetector.setSubId(sub.getId());
            for (TPssrGasdetector item : tPssrGasdetectorService.selectTPssrGasdetectorList(tPssrGasdetector)) {
                // 安装人员
                installer.add(item.getConfirm1());

                //拆除人员
                remover.add(item.getConfirm2());
            }

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        }
    }

    //在线分析仪流程发起申请
    public void doZxfxyApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();
        //修改状态
        TPssrAnalyzer tPssrAnalyzer = new TPssrAnalyzer();
        tPssrAnalyzer.setApproveStatus(0L);
        tPssrAnalyzer.setSubId(sub.getId());
        Set<String> installer = new HashSet<>();
        Set<String> remover = new HashSet<>();
        for (TPssrAnalyzer item : tPssrAnalyzerService.selectTPssrAnalyzerList(tPssrAnalyzer)) {
            item.setApproveStatus(1L);
            item.setUpdatedate(new Date());
            item.setUpdaterCode(userId);
            tPssrAnalyzerService.updateTPssrAnalyzer(item);

            // 安装人员
            installer.add(item.getConfirm1());

            //拆除人员
            remover.add(item.getConfirm2());
        }

        TPssrApprove exist = new TPssrApprove();
        exist.setSubId(sub.getId());
        List<TPssrApprove> tPssrApproves = tPssrApproveService.selectTPssrApproveList(exist);
        if (CollectionUtil.isEmpty(tPssrApproves)) {
            //新增审批数据
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        } else {
            // 已存在流程时，删除旧流程，重新发起
            TPssrApprove approve = tPssrApproves.get(0);
            delProcess(approve.getProcessId(), "pssr2confirm");

            tPssrAnalyzer = new TPssrAnalyzer();
            tPssrAnalyzer.setApproveStatus(1L);
            tPssrAnalyzer.setSubId(sub.getId());
            for (TPssrAnalyzer item : tPssrAnalyzerService.selectTPssrAnalyzerList(tPssrAnalyzer)) {
                // 安装人员
                installer.add(item.getConfirm1());

                //拆除人员
                remover.add(item.getConfirm2());
            }

            pssr2confirm(approve, new ArrayList<>(installer), new ArrayList<>(remover), sub.getConfirm());
        }
    }

    // 开工方案流程发起申请
    public void doKgfaApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();
        //修改状态
        TPssrProgramme tPssrProgramme = new TPssrProgramme();
        tPssrProgramme.setApproveStatus(0L);
        tPssrProgramme.setSubId(sub.getId());
        Set<String> confirm1 = new HashSet<>();
        Set<String> confirm2 = new HashSet<>();
        for (TPssrProgramme item : tPssrProgrammeService.selectTPssrProgrammeList(tPssrProgramme)) {
            item.setApproveStatus(1L);
            item.setUpdatedate(new Date());
            item.setUpdaterCode(userId);
            tPssrProgrammeService.updateTPssrProgramme(item);

            // 安装人员
            confirm1.add(item.getConfirm1());

            //拆除人员
            confirm2.add(item.getConfirm2());
        }

        TPssrApprove exist = new TPssrApprove();
        exist.setSubId(sub.getId());
        List<TPssrApprove> tPssrApproves = tPssrApproveService.selectTPssrApproveList(exist);
        if (CollectionUtil.isEmpty(tPssrApproves)) {
            //新增审批数据
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr2confirm(approve, new ArrayList<>(confirm1), new ArrayList<>(confirm2), sub.getConfirm());
        } else {
            // 已存在流程时，删除旧流程，重新发起
            TPssrApprove approve = tPssrApproves.get(0);
            delProcess(approve.getProcessId(), "pssr2confirm");

            tPssrProgramme = new TPssrProgramme();
            tPssrProgramme.setApproveStatus(1L);
            tPssrProgramme.setSubId(sub.getId());
            for (TPssrProgramme item : tPssrProgrammeService.selectTPssrProgrammeList(tPssrProgramme)) {
                // 安装人员
                confirm1.add(item.getConfirm1());

                //拆除人员
                confirm2.add(item.getConfirm2());
            }

            pssr2confirm(approve, new ArrayList<>(confirm1), new ArrayList<>(confirm2), sub.getConfirm());
        }
    }

    /**
     * 设计变更发起流程
     */
    private void doMocApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();
        //修改状态
        TPssrMoc tPssrMoc = new TPssrMoc();
        tPssrMoc.setApproveStatus(0L);
        tPssrMoc.setSubId(sub.getId());
        Set<String> confirm1 = new HashSet<>();
        Set<String> confirm2 = new HashSet<>();
        for (TPssrMoc item : tPssrMocService.selectTPssrMocList(tPssrMoc)) {
            item.setApproveStatus(1L);
            item.setUpdatedate(new Date());
            item.setUpdaterCode(userId);
            tPssrMocService.updateTPssrMoc(item);

            // 安装人员
            confirm1.add(item.getConfirm1());

            //拆除人员
            confirm2.add(item.getConfirm2());
        }

        TPssrApprove exist = new TPssrApprove();
        exist.setSubId(sub.getId());
        List<TPssrApprove> tPssrApproves = tPssrApproveService.selectTPssrApproveList(exist);
        if (CollectionUtil.isEmpty(tPssrApproves)) {
            //新增审批数据
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr2confirm(approve, new ArrayList<>(confirm1), new ArrayList<>(confirm2), sub.getConfirm());
        } else {
            // 已存在流程时，删除旧流程，重新发起
            TPssrApprove approve = tPssrApproves.get(0);
            delProcess(approve.getProcessId(), "pssr2confirm");

            tPssrMoc = new TPssrMoc();
            tPssrMoc.setApproveStatus(1L);
            tPssrMoc.setSubId(sub.getId());
            for (TPssrMoc item : tPssrMocService.selectTPssrMocList(tPssrMoc)) {
                // 安装人员
                confirm1.add(item.getConfirm1());

                //拆除人员
                confirm2.add(item.getConfirm2());
            }

            pssr2confirm(approve, new ArrayList<>(confirm1), new ArrayList<>(confirm2), sub.getConfirm());
        }
    }

    /**
     * 人身防护审批流程发起申请
     *
     * @param sub 子表对象
     */
    private void doRsfhApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();

        //修改各表状态
        TPssrMeasure measure = new TPssrMeasure();
        measure.setSubId(sub.getId());
        measure.setApproveStatus(1L);
        measure.setUpdatedate(new Date());
        measure.setUpdaterCode(userId);
        tPssrMeasureService.updateAllBySubId(measure);
        TPssrProtection protection = new TPssrProtection();
        protection.setSubId(sub.getId());
        protection.setApproveStatus(1L);
        protection.setUpdatedate(new Date());
        protection.setUpdaterCode(userId);
        tPssrProtectionService.updateAllBySubId(protection);

        // 查询确认人
        TPssrProtection entity = new TPssrProtection();
        entity.setSubId(sub.getId());
        entity.setApproveStatus(1L);
        TPssrProtection tPssrProtection = tPssrProtectionService.selectAllConfirmedPersonBySubId(entity);
        String confirmer1s = null;
        String confirmer2s = null;
        if (tPssrProtection != null) {
            confirmer1s = tPssrProtection.getConfirm1();
            confirmer2s = tPssrProtection.getConfirm2();
        }
        logger.info("=======================confirmer1s:{}", confirmer1s);
        logger.info("=======================confirmer2s:{}", confirmer2s);

        Set<String> confirmerUsers1 = new HashSet<>();
        Set<String> confirmerUsers2 = new HashSet<>();
        if (StringUtils.isNotEmpty(confirmer1s)) {
            confirmerUsers1.addAll(Arrays.asList(confirmer1s.split(",")));
        }
        if (StringUtils.isNotEmpty(confirmer2s)) {
            confirmerUsers2.addAll(Arrays.asList(confirmer2s.split(",")));
        }
        //查询是否已存在审批流程
        TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(sub.getId());
        if (tPssrApprove == null) {
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr2confirm(approve, new ArrayList<>(confirmerUsers1), new ArrayList<>(confirmerUsers2), sub.getConfirm());
        } else {
            delProcess(tPssrApprove.getProcessId(), "pssr2confirm");
            entity.setSubId(sub.getId());
            entity.setApproveStatus(3L);
            tPssrProtection = tPssrProtectionService.selectAllConfirmedPersonBySubId(entity);
            if (tPssrProtection != null) {
                confirmer1s = tPssrProtection.getConfirm1();
                confirmer2s = tPssrProtection.getConfirm2();
            }

            if (StringUtils.isNotEmpty(confirmer1s)) {
                confirmerUsers1.addAll(Arrays.asList(confirmer1s.split(",")));
            }
            if (StringUtils.isNotEmpty(confirmer2s)) {
                confirmerUsers2.addAll(Arrays.asList(confirmer2s.split(",")));
            }
            pssr2confirm(tPssrApprove, new ArrayList<>(confirmerUsers1), new ArrayList<>(confirmerUsers2), sub.getConfirm());
        }
    }

    /**
     * 原辅料审批发起申请
     */
    private void doYflApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();

        //修改各表状态
        TPssrMaterial material = new TPssrMaterial();
        material.setSubId(sub.getId());
        material.setApproveStatus(1L);
        material.setUpdatedate(new Date());
        material.setUpdaterCode(userId);
        tPssrMaterialService.updateAllBySubId(material);
        TPssrMaterialRaw materialRaw = new TPssrMaterialRaw();
        materialRaw.setSubId(sub.getId());
        materialRaw.setApproveStatus(1L);
        materialRaw.setUpdatedate(new Date());
        materialRaw.setUpdaterCode(userId);
        tPssrMaterialRawService.updateAllBySubId(materialRaw);

        // 查询确认人
        TPssrMaterial entity = new TPssrMaterial();
        entity.setSubId(sub.getId());
        entity.setApproveStatus(1L);
        TPssrMaterial tPssrMaterial = tPssrMaterialService.selectAllConfirmedPersonBySubId(entity);
        String confirmer1s = null;
        if (tPssrMaterial != null) {
            confirmer1s = tPssrMaterial.getConfirm1();
        }
        logger.info("=======================confirmer1s:{}", confirmer1s);

        Set<String> confirmerUsers1 = new HashSet<>();
        if (StringUtils.isNotEmpty(confirmer1s)) {
            confirmerUsers1.addAll(Arrays.asList(confirmer1s.split(",")));
        }
        //查询是否已存在审批流程
        TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(sub.getId());
        if (tPssrApprove == null) {
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr1confirm(approve, new ArrayList<>(confirmerUsers1), sub.getConfirm());
        } else {
            delProcess(tPssrApprove.getProcessId(), "pssr1confirm");
            entity.setSubId(sub.getId());
            entity.setApproveStatus(3L);
            tPssrMaterial = tPssrMaterialService.selectAllConfirmedPersonBySubId(entity);
            if (tPssrMaterial != null) {
                confirmer1s = tPssrMaterial.getConfirm1();
            }

            if (StringUtils.isNotEmpty(confirmer1s)) {
                confirmerUsers1.addAll(Arrays.asList(confirmer1s.split(",")));
            }
            pssr1confirm(tPssrApprove, new ArrayList<>(confirmerUsers1), sub.getConfirm());
        }
    }

    /**
     * 机泵审批发起申请
     */
    private void doJbApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();

        //修改各表状态
        TPssrPumpCleaning cleaning = new TPssrPumpCleaning();
        cleaning.setSubId(sub.getId());
        cleaning.setApproveStatus(1L);
        cleaning.setUpdatedate(new Date());
        cleaning.setUpdaterCode(userId);
        tPssrPumpCleaningService.updateAllBySubId(cleaning);
        TPssrPumpFill fill = new TPssrPumpFill();
        fill.setSubId(sub.getId());
        fill.setApproveStatus(1L);
        fill.setUpdatedate(new Date());
        fill.setUpdaterCode(userId);
        tPssrPumpFillService.updateAllBySubId(fill);
        TPssrPumpOverhaul overhaul = new TPssrPumpOverhaul();
        overhaul.setSubId(sub.getId());
        overhaul.setApproveStatus(1L);
        overhaul.setUpdatedate(new Date());
        overhaul.setUpdaterCode(userId);
        tPssrPumpOverhaulService.updateAllBySubId(overhaul);

        // 查询确认人
        TPssrPumpFill entity = new TPssrPumpFill();
        entity.setSubId(sub.getId());
        entity.setApproveStatus(1L);
        TPssrPumpFill queryData = tPssrPumpFillService.selectAllConfirmedPersonBySubId(entity);
        String confirmer1s = null;
        String confirmer2s = null;
        if (queryData != null) {
            confirmer1s = queryData.getConfirmer1();
            confirmer2s = queryData.getConfirmer2();
        }
        logger.info("=======================confirmer1s:{}", confirmer1s);
        logger.info("=======================confirmer2s:{}", confirmer2s);

        Set<String> confirmerUsers1 = new HashSet<>();
        Set<String> confirmerUsers2 = new HashSet<>();
        if (StringUtils.isNotEmpty(confirmer1s)) {
            confirmerUsers1.addAll(Arrays.asList(confirmer1s.split(",")));
        }
        if (StringUtils.isNotEmpty(confirmer2s)) {
            confirmerUsers2.addAll(Arrays.asList(confirmer2s.split(",")));
        }
        //查询是否已存在审批流程
        TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(sub.getId());
        if (tPssrApprove == null) {
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr2confirm(approve, new ArrayList<>(confirmerUsers1), new ArrayList<>(confirmerUsers2), sub.getConfirm());
        } else {
            delProcess(tPssrApprove.getProcessId(), "pssr2confirm");
            entity.setSubId(sub.getId());
            entity.setApproveStatus(3L);
            queryData = tPssrPumpFillService.selectAllConfirmedPersonBySubId(entity);
            if (queryData != null) {
                confirmer1s = queryData.getConfirmer1();
                confirmer2s = queryData.getConfirmer2();
            }

            if (StringUtils.isNotEmpty(confirmer1s)) {
                confirmerUsers1.addAll(Arrays.asList(confirmer1s.split(",")));
            }
            if (StringUtils.isNotEmpty(confirmer2s)) {
                confirmerUsers2.addAll(Arrays.asList(confirmer2s.split(",")));
            }
            pssr2confirm(tPssrApprove, new ArrayList<>(confirmerUsers1), new ArrayList<>(confirmerUsers2), sub.getConfirm());
        }
    }

    /**
     * 仪表联锁测试审批发起申请
     */
    private void doYblscsApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();

        //修改表状态
        TPssrInstrumentTest instrumentTest = new TPssrInstrumentTest();
        instrumentTest.setSubId(sub.getId());
        for (TPssrInstrumentTest test : tPssrInstrumentTestService.selectTPssrInstrumentTestList(instrumentTest)) {
            test.setApproveStatus(2L);
            test.setUpdatedate(new Date());
            test.setUpdaterCode(userId);
            tPssrInstrumentTestService.updateTPssrInstrumentTest(test);
        }
        //查询是否已存在审批流程
        TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(sub.getId());
        if (tPssrApprove == null) {
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr1confirm(approve, new ArrayList<>(), sub.getConfirm());
        } else {
            delProcess(tPssrApprove.getProcessId(), "pssr1confirm");
            pssr1confirm(tPssrApprove, new ArrayList<>(), sub.getConfirm());
        }

    }

    /**
     * 仪表联锁测试审批发起申请
     */
    private void doBjlszqrApprove(TPssrSubcontent sub) {
        String userId = getUserId().toString();

        //修改表状态
        TPssrAlarm alarm = new TPssrAlarm();
        alarm.setSubId(sub.getId());
        for (TPssrAlarm test : tPssrAlarmService.selectTPssrAlarmList(alarm)) {
            test.setApproveStatus(2L);
            test.setUpdatedate(new Date());
            test.setUpdaterCode(userId);
            tPssrAlarmService.updateTPssrAlarm(test);
        }
        //查询是否已存在审批流程
        TPssrApprove tPssrApprove = tPssrApproveService.selectTPssrApproveBySubId(sub.getId());
        if (tPssrApprove == null) {
            TPssrApprove approve = new TPssrApprove();
            approve.setSubId(sub.getId());
            approve.setApNo(DateUtils.dateTimeNow() + userId);
            approve.setApproveStatus(1L);
            approve.setSubCharge(sub.getConfirm());
            approve.setCreaterCode(userId);
            approve.setCreatedate(new Date());
            tPssrApproveService.insertTPssrApprove(approve);

            pssr1confirm(approve, new ArrayList<>(), sub.getConfirm());
        } else {
            delProcess(tPssrApprove.getProcessId(), "pssr1confirm");
            pssr1confirm(tPssrApprove, new ArrayList<>(), sub.getConfirm());
        }

    }

    /**
     * 单确认人发起流程
     */
    private void pssr1confirm(TPssrApprove approve, List<String> confirmUsers, String confirm) {
        String userId = getUserId().toString();

        // 开始申请流程
        long businessKey = approve.getApproveId();
        //开始工作流、监听
        Authentication.setAuthenticatedUserId(userId);//设置当前申请人
        Map<String, Object> variables = new HashMap<>();
        variables.put("applyUser", userId);
        variables.put("confirmUsers", confirmUsers);
        variables.put("confirmTaskCreateListener", new ConfirmTaskCreateListener());//发送邮件
        variables.put("chargePerson", confirm);
        //采用key来启动流程定义并设置流程变量，返回流程实例
        ProcessInstance pi = runtimeService.startProcessInstanceByKey("pssr1confirm", String.valueOf(businessKey), variables);
        approve.setProcessId(pi.getProcessInstanceId());
        tPssrApproveService.updateTPssrApprove(approve);
    }

    /**
     * 双确认人发起流程
     */
    private void pssr2confirm(TPssrApprove approve, List<String> confirmUsers1, List<String> confirmUsers2, String confirm) {
        String userId = getUserId().toString();

        // 开始申请流程
        long businessKey = approve.getApproveId();
        //开始工作流、监听
        Authentication.setAuthenticatedUserId(userId);//设置当前申请人
        Map<String, Object> variables = new HashMap<>();
        variables.put("applyUser", userId);
        variables.put("confirmUsers1", confirmUsers1);
        variables.put("confirmUsers2", confirmUsers2);
        variables.put("confirmTaskCreateListener", new ConfirmTaskCreateListener());//发送邮件
        variables.put("chargePerson", confirm);
        //采用key来启动流程定义并设置流程变量，返回流程实例
        ProcessInstance pi = runtimeService.startProcessInstanceByKey("pssr2confirm", String.valueOf(businessKey), variables);
        approve.setProcessId(pi.getProcessInstanceId());
        tPssrApproveService.updateTPssrApprove(approve);
    }

    /**
     * 三确认人发起流程
     */
    private void pssr3confirm(TPssrApprove approve, List<String> confirmUsers1, List<String> confirmUsers2, List<String> confirmUsers3, String confirm) {
        String userId = getUserId().toString();

        // 开始申请流程
        long businessKey = approve.getApproveId();
        //开始工作流、监听
        Authentication.setAuthenticatedUserId(userId);//设置当前申请人
        Map<String, Object> variables = new HashMap<>();
        variables.put("applyUser", userId);
        variables.put("confirmUsers1", confirmUsers1);
        variables.put("confirmUsers2", confirmUsers2);
        variables.put("confirmUsers3", confirmUsers3);
        variables.put("confirmTaskCreateListener", new ConfirmTaskCreateListener());//发送邮件
        variables.put("chargePerson", confirm);
        //采用key来启动流程定义并设置流程变量，返回流程实例
        ProcessInstance pi = runtimeService.startProcessInstanceByKey("pssr3confirm", String.valueOf(businessKey), variables);
        approve.setProcessId(pi.getProcessInstanceId());
        tPssrApproveService.updateTPssrApprove(approve);
    }

    /**
     * 删除已存在流程
     */
    private void delProcess(String processId, String processName) {
        try {
            runtimeService.deleteProcessInstance(processId, processName);
            historyService.deleteHistoricProcessInstance(processId);
        } catch (Exception e) {
            logger.info("无运行时流程");
        }
    }

}
