package com.ruoyi.system.service;


import com.ruoyi.common.constant.CommonConstants;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.projectV2.*;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.mapper.projectV2.*;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.util.*;
import java.util.stream.Collectors;

@Component
public class Task {

    @Autowired
    private SysUserMapper userMapper;

    @Autowired
    private ZsyzLcjlMapper zsyzLcjlMapper;

    @Autowired
    private ZsyzShqxPzMapper zsyzShqxPzMapper;

    @Autowired
    private ZsyzShqxXmMapper zsyzShqxXmMapper;

    @Autowired
    private ZsyzDbdMapper zsyzDbdMapper;

    @Autowired
    private ZsyzSbbzbMapper zsyzSbbzbMapper;

    @Autowired
    private ZsyzProjectDeptMapper zsyzProjectDeptMapper;




    /***
     * 生成督办信息
     * */
    @Async
    //@Scheduled(cron = "0 0/2 * * * ? ")
    @Scheduled(cron = "0 1 0 * * ? ")
    public void generateDb() throws ParseException {

        List<ZsyzDbd> zsyzDbds = new ArrayList<>();

        //查询配置表配置期限
        List<ZsyzShqxPz> zsyzShqxPzList = zsyzShqxPzMapper.selectZsyzShqxPzList(new ZsyzShqxPz());
        ZsyzShqxPz zsyzShqxPzHuang = new ZsyzShqxPz();
        ZsyzShqxPz zsyzShqxPzHong = new ZsyzShqxPz();
        for (ZsyzShqxPz zsyzShqxPz : zsyzShqxPzList) {
            if ("1".equals(zsyzShqxPz.getType())) {
                zsyzShqxPzHuang = zsyzShqxPz;
            } else {
                zsyzShqxPzHong = zsyzShqxPz;
            }
        }
        //获取每个项目的配置
        List<ZsyzShqxXm> zsyzShqxXmList = zsyzShqxXmMapper.selectZsyzShqxXmList(new ZsyzShqxXm());
        //一项目id进行分组
        Map<Long, List<ZsyzShqxXm>> zsyzShqxXmcollect = zsyzShqxXmList.stream().collect(Collectors.groupingBy(ZsyzShqxXm::getXmId));

        //获取流程记录中每条项目最新的数据
        List<ZsyzLcjl> zsyzLcjlList = zsyzLcjlMapper.selectZsyzLcjlListQc();

        //获取数据库所有督办信息
        ZsyzDbd zsyzDbd = new ZsyzDbd();
        zsyzDbd.setIsHf("N");
        List<ZsyzDbd> zsyzDbdList = zsyzDbdMapper.selectZsyzDbdList(zsyzDbd);

        //查询所有项目信息
        List<ZsyzSbbzb> zsyzSbbzbList = zsyzSbbzbMapper.selectZsyzSbbzbList(new ZsyzSbbzb());
        Long deptId = null;
        String deptName = "";
        for (ZsyzLcjl zsyzLcjl : zsyzLcjlList) {
            //当项目进度为11和12时表示项目流程结束，无需再生成督办
            if (zsyzLcjl.getProgress().equals(CommonConstants.ONE)) {

                //查询招商中心
                deptId = 100L;
                deptName = "招商";
                //获取项目首谈保存时间
                String strTime = DateFormatUtils.format(zsyzLcjl.getClTime(), "yyyy-MM-dd");

                List<ZsyzShqxXm> zsyzShqxXms = zsyzShqxXmcollect.get(zsyzLcjl.getXmId());
                //黄牌
                judgmentHuangP(zsyzShqxXms,strTime,zsyzDbdList,zsyzLcjl,zsyzDbds, CommonConstants.ONE,zsyzShqxPzHuang, deptId,deptName);
                //红牌
                judgmentHongP(zsyzShqxXms,strTime,zsyzDbdList,zsyzLcjl,zsyzDbds, CommonConstants.ONE,zsyzShqxPzHuang, deptId,deptName);

            }else if (zsyzLcjl.getProgress().equals(CommonConstants.THR)) {
                //查询当前项目的要素部门
                ZsyzProjectDept zsyzProjectDept = new ZsyzProjectDept();
                zsyzProjectDept.setXmId(zsyzLcjl.getXmId());
                zsyzProjectDept.setIsHf("N");
                List<ZsyzProjectDept>  zsyzProjectDeptList = zsyzProjectDeptMapper.selectZsyzProjectDeptList(zsyzProjectDept);
                for (ZsyzProjectDept projectDept : zsyzProjectDeptList) {

                    deptId = projectDept.getDeptId();
                    deptName = projectDept.getDeptName();

                    //获取项目首谈保存时间
                    String strTime = DateFormatUtils.format(zsyzLcjl.getClTime(), "yyyy-MM-dd");

                    List<ZsyzShqxXm> zsyzShqxXms = zsyzShqxXmcollect.get(zsyzLcjl.getXmId());
                    //黄牌
                    judgmentHuangP(zsyzShqxXms,strTime,zsyzDbdList,zsyzLcjl,zsyzDbds, CommonConstants.THR,zsyzShqxPzHuang, deptId,deptName);
                    //红牌
                    judgmentHongP(zsyzShqxXms,strTime,zsyzDbdList,zsyzLcjl,zsyzDbds, CommonConstants.THR,zsyzShqxPzHuang, deptId,deptName);

                }



            }else if (zsyzLcjl.getProgress().equals(CommonConstants.FOR)) {
                //查询承接地
                for (ZsyzSbbzb zsyzSbbzb : zsyzSbbzbList) {
                    if(zsyzSbbzb.getId().equals(zsyzLcjl.getXmId())){
                        deptId = zsyzSbbzb.getCjdId();
                        deptName = zsyzSbbzb.getCjdName();
                    }
                }

                //获取项目首谈保存时间
                String strTime = DateFormatUtils.format(zsyzLcjl.getClTime(), "yyyy-MM-dd");

                List<ZsyzShqxXm> zsyzShqxXms = zsyzShqxXmcollect.get(zsyzLcjl.getXmId());
                //黄牌
                judgmentHuangP(zsyzShqxXms,strTime,zsyzDbdList,zsyzLcjl,zsyzDbds, CommonConstants.FOR,zsyzShqxPzHuang, deptId,deptName);
                //红牌
                judgmentHongP(zsyzShqxXms,strTime,zsyzDbdList,zsyzLcjl,zsyzDbds, CommonConstants.FOR,zsyzShqxPzHuang, deptId,deptName);

            }else if (zsyzLcjl.getProgress().equals(CommonConstants.FIV)) {
                //查询承接地
                for (ZsyzSbbzb zsyzSbbzb : zsyzSbbzbList) {
                    if(zsyzSbbzb.getId().equals(zsyzLcjl.getXmId())){
                        deptId = zsyzSbbzb.getCjdId();
                        deptName = zsyzSbbzb.getCjdName();
                    }
                }

                //获取项目首谈保存时间
                String strTime = DateFormatUtils.format(zsyzLcjl.getClTime(), "yyyy-MM-dd");

                List<ZsyzShqxXm> zsyzShqxXms = zsyzShqxXmcollect.get(zsyzLcjl.getXmId());
                //黄牌
                judgmentHuangP(zsyzShqxXms,strTime,zsyzDbdList,zsyzLcjl,zsyzDbds, CommonConstants.FIV,zsyzShqxPzHuang, deptId,deptName);
                //红牌
                judgmentHongP(zsyzShqxXms,strTime,zsyzDbdList,zsyzLcjl,zsyzDbds, CommonConstants.FIV,zsyzShqxPzHuang, deptId,deptName);

            }else if (zsyzLcjl.getProgress().equals(CommonConstants.SIX)) {
                //查询招商中心
                deptId = 100L;
                deptName = "招商";
                //获取项目首谈保存时间
                String strTime = DateFormatUtils.format(zsyzLcjl.getClTime(), "yyyy-MM-dd");

                List<ZsyzShqxXm> zsyzShqxXms = zsyzShqxXmcollect.get(zsyzLcjl.getXmId());
                //黄牌
                judgmentHuangP(zsyzShqxXms,strTime,zsyzDbdList,zsyzLcjl,zsyzDbds, CommonConstants.SIX,zsyzShqxPzHuang, deptId,deptName);
                //红牌
                judgmentHongP(zsyzShqxXms,strTime,zsyzDbdList,zsyzLcjl,zsyzDbds, CommonConstants.SIX,zsyzShqxPzHuang, deptId,deptName);

            }else if (zsyzLcjl.getProgress().equals(CommonConstants.SEV)) {
                //查询承接地
                for (ZsyzSbbzb zsyzSbbzb : zsyzSbbzbList) {
                    if(zsyzSbbzb.getId().equals(zsyzLcjl.getXmId())){
                        deptId = zsyzSbbzb.getCjdId();
                        deptName = zsyzSbbzb.getCjdName();
                    }
                }

                //获取项目首谈保存时间
                String strTime = DateFormatUtils.format(zsyzLcjl.getClTime(), "yyyy-MM-dd");

                List<ZsyzShqxXm> zsyzShqxXms = zsyzShqxXmcollect.get(zsyzLcjl.getXmId());
                //黄牌
                judgmentHuangP(zsyzShqxXms,strTime,zsyzDbdList,zsyzLcjl,zsyzDbds, CommonConstants.SEV,zsyzShqxPzHuang, deptId,deptName);
                //红牌
                judgmentHongP(zsyzShqxXms,strTime,zsyzDbdList,zsyzLcjl,zsyzDbds, CommonConstants.SEV,zsyzShqxPzHuang, deptId,deptName);

            }else if (zsyzLcjl.getProgress().equals(CommonConstants.EIG)) {
                //查询招商中心
                deptId = 100L;
                deptName = "招商";


                //获取项目首谈保存时间
                String strTime = DateFormatUtils.format(zsyzLcjl.getClTime(), "yyyy-MM-dd");

                List<ZsyzShqxXm> zsyzShqxXms = zsyzShqxXmcollect.get(zsyzLcjl.getXmId());
                //黄牌
                judgmentHuangP(zsyzShqxXms,strTime,zsyzDbdList,zsyzLcjl,zsyzDbds, CommonConstants.EIG,zsyzShqxPzHuang, deptId,deptName);
                //红牌
                judgmentHongP(zsyzShqxXms,strTime,zsyzDbdList,zsyzLcjl,zsyzDbds, CommonConstants.EIG,zsyzShqxPzHuang, deptId,deptName);

            }else if (zsyzLcjl.getProgress().equals(CommonConstants.NIN)) {
                //查询承接地
                for (ZsyzSbbzb zsyzSbbzb : zsyzSbbzbList) {
                    if(zsyzSbbzb.getId().equals(zsyzLcjl.getXmId())){
                        deptId = zsyzSbbzb.getCjdId();
                        deptName = zsyzSbbzb.getCjdName();
                    }
                }

                //获取项目首谈保存时间
                String strTime = DateFormatUtils.format(zsyzLcjl.getClTime(), "yyyy-MM-dd");

                List<ZsyzShqxXm> zsyzShqxXms = zsyzShqxXmcollect.get(zsyzLcjl.getXmId());
                //黄牌
                judgmentHuangP(zsyzShqxXms,strTime,zsyzDbdList,zsyzLcjl,zsyzDbds, CommonConstants.NIN,zsyzShqxPzHuang, deptId,deptName);
                //红牌
                judgmentHongP(zsyzShqxXms,strTime,zsyzDbdList,zsyzLcjl,zsyzDbds, CommonConstants.NIN,zsyzShqxPzHuang, deptId,deptName);

            }else if (zsyzLcjl.getProgress().equals(CommonConstants.TEN)) {
                //查询招商中心
                deptId = 100L;
                deptName = "招商";

                //获取项目首谈保存时间
                String strTime = DateFormatUtils.format(zsyzLcjl.getClTime(), "yyyy-MM-dd");

                List<ZsyzShqxXm> zsyzShqxXms = zsyzShqxXmcollect.get(zsyzLcjl.getXmId());
                //黄牌
                judgmentHuangP(zsyzShqxXms,strTime,zsyzDbdList,zsyzLcjl,zsyzDbds, CommonConstants.TEN,zsyzShqxPzHuang, deptId,deptName);
                //红牌
                judgmentHongP(zsyzShqxXms,strTime,zsyzDbdList,zsyzLcjl,zsyzDbds, CommonConstants.TEN,zsyzShqxPzHuang, deptId,deptName);

            }
        }


    }

    /***
     *  进行红牌判定
     * @param zsyzShqxXms
     * @param strTime
     * @param zsyzDbdList
     * @param zsyzLcjl
     * @param zsyzDbds
     * @param type
     * @param zsyzShqxPzHuang
     */
    private void judgmentHongP(List<ZsyzShqxXm> zsyzShqxXms, String strTime, List<ZsyzDbd> zsyzDbdList, ZsyzLcjl zsyzLcjl,
                               List<ZsyzDbd> zsyzDbds, String type, ZsyzShqxPz zsyzShqxPzHuang,Long deptId,String deptName) throws ParseException {

        //黄牌
        if (zsyzShqxXms != null && zsyzShqxXms.size() > 0) {
            Boolean bls = true;
            for (ZsyzShqxXm zsyzShqxXm : zsyzShqxXms) {
                if ("2".equals(zsyzShqxXm.getType())) {
                    String endTime = DateUtils.getDate();
                    //计算strTime和endTime之间的工作日
                    int count = DateUtils.calc(strTime, endTime) - 1;
                    //如果超过时间并且督办中不存在则录入督办
                    String ts = "";
                    if(CommonConstants.ONE.equals(type)){
                        ts = zsyzShqxXm.getStshqx();
                        if (Integer.parseInt(zsyzShqxXm.getStshqx()) > count) {
                            break;
                        }
                    }else if(CommonConstants.THR.equals(type)){
                        ts = zsyzShqxXm.getYsbmshqx();
                        if (Integer.parseInt(zsyzShqxXm.getYsbmshqx()) > count) {
                            break;
                        }
                    }else if(CommonConstants.FOR.equals(type)){
                        ts = zsyzShqxXm.getCjdcjqx();
                        if (Integer.parseInt(zsyzShqxXm.getCjdcjqx()) > count) {
                            break;
                        }
                    }else if(CommonConstants.FIV.equals(type)){
                        ts = zsyzShqxXm.getQylrqx();
                        if (Integer.parseInt(zsyzShqxXm.getQylrqx()) > count) {
                            break;
                        }
                    }else if(CommonConstants.SIX.equals(type)){
                        ts = zsyzShqxXm.getQyshqx();
                        if (Integer.parseInt(zsyzShqxXm.getQyshqx()) > count) {
                            break;
                        }
                    }else if(CommonConstants.SEV.equals(type)){
                        ts = zsyzShqxXm.getKglrqx();
                        if (Integer.parseInt(zsyzShqxXm.getKglrqx()) > count) {
                            break;
                        }
                    }else if(CommonConstants.EIG.equals(type)){
                        ts = zsyzShqxXm.getKgshqx();
                        if (Integer.parseInt(zsyzShqxXm.getKgshqx()) > count) {
                            break;
                        }
                    }else if(CommonConstants.NIN.equals(type)){
                        ts = zsyzShqxXm.getTclrqx();
                        if (Integer.parseInt(zsyzShqxXm.getTclrqx()) > count) {
                            break;
                        }
                    }else if(CommonConstants.TEN.equals(type)){
                        ts = zsyzShqxXm.getTcshqx();
                        if (Integer.parseInt(zsyzShqxXm.getTcshqx()) > count) {
                            break;
                        }
                    }

                    Boolean bl = true;
                    for (ZsyzDbd dbd : zsyzDbdList) {
                        if ("2".equals(dbd.getDbType()) && zsyzLcjl.getXmId().equals(dbd.getXmId()) && type.equals(dbd.getProgress())) {
                            //存在数据
                            bl = false;
                            break;
                        }
                    }
                    if (bl) {
                        //录入系统
                        ZsyzDbd zsyzDb = new ZsyzDbd();
                        zsyzDb.setDh(sjs());
                        zsyzDb.setXmId(zsyzLcjl.getXmId());
                        zsyzDb.setXmbh(zsyzLcjl.getXmbh());
                        zsyzDb.setXmbh(zsyzLcjl.getXmmc());
                        //todo 查询督办部门
                        zsyzDb.setDeptId(deptId);
                        zsyzDb.setDeptName(deptName);

                        zsyzDb.setIsHf("N");
                        zsyzDb.setDbTime(DateUtils.getNowDate());
                        zsyzDb.setBlsx(ts);
                        zsyzDb.setDbsx("该项目已超过" + ts + "天未填报进展，请予以说明。");
                        zsyzDb.setDbType("2");
                        zsyzDb.setProgress(type);
                        zsyzDbds.add(zsyzDb);
                    }
                    bls = false;
                }
            }
            if(bls){
                String endTime = DateUtils.getDate();
                //计算strTime和endTime之间的工作日
                int count = DateUtils.calc(strTime, endTime) - 1;
                //如果超过时间并且督办中不存在则录入督办

                String ts = "";
                if(CommonConstants.ONE.equals(type)){
                    ts = zsyzShqxPzHuang.getStshqx();
                    if (Integer.parseInt(zsyzShqxPzHuang.getStshqx()) > count) {
                        return;
                    }
                }else if(CommonConstants.THR.equals(type)){
                    ts = zsyzShqxPzHuang.getYsbmshqx();
                    if (Integer.parseInt(zsyzShqxPzHuang.getYsbmshqx()) > count) {
                        return;
                    }
                }else if(CommonConstants.FOR.equals(type)){
                    ts = zsyzShqxPzHuang.getCjdcjqx();
                    if (Integer.parseInt(zsyzShqxPzHuang.getCjdcjqx()) > count) {
                        return;
                    }
                }else if(CommonConstants.FIV.equals(type)){
                    ts = zsyzShqxPzHuang.getQylrqx();
                    if (Integer.parseInt(zsyzShqxPzHuang.getQylrqx()) > count) {
                        return;
                    }
                }else if(CommonConstants.SIX.equals(type)){
                    ts = zsyzShqxPzHuang.getQyshqx();
                    if (Integer.parseInt(zsyzShqxPzHuang.getQyshqx()) > count) {
                        return;
                    }
                }else if(CommonConstants.SEV.equals(type)){
                    ts = zsyzShqxPzHuang.getKglrqx();
                    if (Integer.parseInt(zsyzShqxPzHuang.getKglrqx()) > count) {
                        return;
                    }
                }else if(CommonConstants.EIG.equals(type)){
                    ts = zsyzShqxPzHuang.getKgshqx();
                    if (Integer.parseInt(zsyzShqxPzHuang.getKgshqx()) > count) {
                        return;
                    }
                }else if(CommonConstants.NIN.equals(type)){
                    ts = zsyzShqxPzHuang.getTclrqx();
                    if (Integer.parseInt(zsyzShqxPzHuang.getTclrqx()) > count) {
                        return;
                    }
                }else if(CommonConstants.TEN.equals(type)){
                    ts = zsyzShqxPzHuang.getTcshqx();
                    if (Integer.parseInt(zsyzShqxPzHuang.getTcshqx()) > count) {
                        return;
                    }
                }

                Boolean bl = true;
                for (ZsyzDbd dbd : zsyzDbdList) {
                    if ("2".equals(dbd.getDbType()) && zsyzLcjl.getXmId().equals(dbd.getXmId()) && CommonConstants.ONE.equals(dbd.getProgress())) {
                        //存在数据
                        bl = false;
                        break;
                    }
                }
                if (bl) {
                    //录入系统
                    ZsyzDbd zsyzDb = new ZsyzDbd();
                    zsyzDb.setDh(sjs());
                    zsyzDb.setXmId(zsyzLcjl.getXmId());
                    zsyzDb.setXmbh(zsyzLcjl.getXmbh());
                    zsyzDb.setXmbh(zsyzLcjl.getXmmc());
                    //todo 查询督办部门
                    zsyzDb.setDeptId(deptId);
                    zsyzDb.setDeptName(deptName);

                    zsyzDb.setIsHf("N");
                    zsyzDb.setDbTime(DateUtils.getNowDate());
                    zsyzDb.setBlsx(ts);
                    zsyzDb.setDbsx("该项目已超过" + ts + "天未填报进展，请予以说明。");
                    zsyzDb.setDbType("2");
                    zsyzDb.setProgress(type);
                    zsyzDbds.add(zsyzDb);
                }
            }

        } else {
            String endTime = DateUtils.getDate();
            //计算strTime和endTime之间的工作日
            int count = DateUtils.calc(strTime, endTime) - 1;
            //如果超过时间并且督办中不存在则录入督办

            String ts = "";
            if(CommonConstants.ONE.equals(type)){
                ts = zsyzShqxPzHuang.getStshqx();
                if (Integer.parseInt(zsyzShqxPzHuang.getStshqx()) > count) {
                    return;
                }
            }else if(CommonConstants.THR.equals(type)){
                ts = zsyzShqxPzHuang.getYsbmshqx();
                if (Integer.parseInt(zsyzShqxPzHuang.getYsbmshqx()) > count) {
                    return;
                }
            }else if(CommonConstants.FOR.equals(type)){
                ts = zsyzShqxPzHuang.getCjdcjqx();
                if (Integer.parseInt(zsyzShqxPzHuang.getCjdcjqx()) > count) {
                    return;
                }
            }else if(CommonConstants.FIV.equals(type)){
                ts = zsyzShqxPzHuang.getQylrqx();
                if (Integer.parseInt(zsyzShqxPzHuang.getQylrqx()) > count) {
                    return;
                }
            }else if(CommonConstants.SIX.equals(type)){
                ts = zsyzShqxPzHuang.getQyshqx();
                if (Integer.parseInt(zsyzShqxPzHuang.getQyshqx()) > count) {
                    return;
                }
            }else if(CommonConstants.SEV.equals(type)){
                ts = zsyzShqxPzHuang.getKglrqx();
                if (Integer.parseInt(zsyzShqxPzHuang.getKglrqx()) > count) {
                    return;
                }
            }else if(CommonConstants.EIG.equals(type)){
                ts = zsyzShqxPzHuang.getKgshqx();
                if (Integer.parseInt(zsyzShqxPzHuang.getKgshqx()) > count) {
                    return;
                }
            }else if(CommonConstants.NIN.equals(type)){
                ts = zsyzShqxPzHuang.getTclrqx();
                if (Integer.parseInt(zsyzShqxPzHuang.getTclrqx()) > count) {
                    return;
                }
            }else if(CommonConstants.TEN.equals(type)){
                ts = zsyzShqxPzHuang.getTcshqx();
                if (Integer.parseInt(zsyzShqxPzHuang.getTcshqx()) > count) {
                    return;
                }
            }

            Boolean bl = true;
            for (ZsyzDbd dbd : zsyzDbdList) {
                if ("1".equals(dbd.getDbType()) && zsyzLcjl.getXmId().equals(dbd.getXmId()) && CommonConstants.ONE.equals(dbd.getProgress())) {
                    //存在数据
                    bl = false;
                    break;
                }
            }
            if (bl) {
                //录入系统
                ZsyzDbd zsyzDb = new ZsyzDbd();
                zsyzDb.setDh(sjs());
                zsyzDb.setXmId(zsyzLcjl.getXmId());
                zsyzDb.setXmbh(zsyzLcjl.getXmbh());
                zsyzDb.setXmbh(zsyzLcjl.getXmmc());
                //todo 查询督办部门
                zsyzDb.setDeptId(deptId);
                zsyzDb.setDeptName(deptName);

                zsyzDb.setIsHf("N");
                zsyzDb.setDbTime(DateUtils.getNowDate());
                zsyzDb.setBlsx(ts);
                zsyzDb.setDbsx("该项目已超过" + ts + "天未填报进展，请予以说明。");
                zsyzDb.setDbType("2");
                zsyzDb.setProgress(type);
                zsyzDbds.add(zsyzDb);
            }
        }
    }

    /***
     *  进行黄牌判定
     * @param zsyzShqxXms
     * @param strTime
     * @param zsyzDbdList
     * @param zsyzLcjl
     * @param zsyzDbds
     * @param type
     * @param zsyzShqxPzHuang
     */
    public void judgmentHuangP(List<ZsyzShqxXm>zsyzShqxXms,String strTime,List<ZsyzDbd> zsyzDbdList,ZsyzLcjl zsyzLcjl,
                               List<ZsyzDbd> zsyzDbds,String type,ZsyzShqxPz zsyzShqxPzHuang,Long deptId,String deptName ) throws ParseException {
        //黄牌
        if (zsyzShqxXms != null && zsyzShqxXms.size() > 0) {
            Boolean bls = true;
            for (ZsyzShqxXm zsyzShqxXm : zsyzShqxXms) {
                if ("1".equals(zsyzShqxXm.getType())) {
                    String endTime = DateUtils.getDate();
                    //计算strTime和endTime之间的工作日
                    int count = DateUtils.calc(strTime, endTime) - 1;
                    //如果超过时间并且督办中不存在则录入督办
                    String ts = "";
                    if(CommonConstants.ONE.equals(type)){
                        ts = zsyzShqxXm.getStshqx();
                        if (Integer.parseInt(zsyzShqxXm.getStshqx()) > count) {
                            break;
                        }

                    }else if(CommonConstants.THR.equals(type)){
                        ts = zsyzShqxXm.getYsbmshqx();
                        if (Integer.parseInt(zsyzShqxXm.getYsbmshqx()) > count) {
                            break;
                        }
                        //查询要素部门
                    }else if(CommonConstants.FOR.equals(type)){
                        ts = zsyzShqxXm.getCjdcjqx();
                        if (Integer.parseInt(zsyzShqxXm.getCjdcjqx()) > count) {
                            break;
                        }
                    }else if(CommonConstants.FIV.equals(type)){
                        ts = zsyzShqxXm.getQylrqx();
                        if (Integer.parseInt(zsyzShqxXm.getQylrqx()) > count) {
                            break;
                        }
                    }else if(CommonConstants.SIX.equals(type)){
                        ts = zsyzShqxXm.getQyshqx();
                        if (Integer.parseInt(zsyzShqxXm.getQyshqx()) > count) {
                            break;
                        }
                    }else if(CommonConstants.SEV.equals(type)){
                        ts = zsyzShqxXm.getKglrqx();
                        if (Integer.parseInt(zsyzShqxXm.getKglrqx()) > count) {
                            break;
                        }
                    }else if(CommonConstants.EIG.equals(type)){
                        ts = zsyzShqxXm.getKgshqx();
                        if (Integer.parseInt(zsyzShqxXm.getKgshqx()) > count) {
                            break;
                        }
                    }else if(CommonConstants.NIN.equals(type)){
                        ts = zsyzShqxXm.getTclrqx();
                        if (Integer.parseInt(zsyzShqxXm.getTclrqx()) > count) {
                            break;
                        }
                    }else if(CommonConstants.TEN.equals(type)){
                        ts = zsyzShqxXm.getTcshqx();
                        if (Integer.parseInt(zsyzShqxXm.getTcshqx()) > count) {
                            break;
                        }
                    }

                    Boolean bl = true;
                    for (ZsyzDbd dbd : zsyzDbdList) {
                        if ("1".equals(dbd.getDbType()) && zsyzLcjl.getXmId().equals(dbd.getXmId()) && type.equals(dbd.getProgress())) {
                            //存在数据
                            bl = false;
                            break;
                        }
                    }
                    if (bl) {
                        //录入系统
                        ZsyzDbd zsyzDb = new ZsyzDbd();
                        zsyzDb.setDh(sjs());
                        zsyzDb.setXmId(zsyzLcjl.getXmId());
                        zsyzDb.setXmbh(zsyzLcjl.getXmbh());
                        zsyzDb.setXmbh(zsyzLcjl.getXmmc());
                        //todo 查询督办部门
                        zsyzDb.setDeptId(deptId);
                        zsyzDb.setDeptName(deptName);

                        zsyzDb.setIsHf("N");
                        zsyzDb.setDbTime(DateUtils.getNowDate());
                        zsyzDb.setBlsx(ts);
                        zsyzDb.setDbsx("该项目已超过" + ts + "天未填报进展，请予以说明。");
                        zsyzDb.setDbType("1");
                        zsyzDb.setProgress(type);
                        zsyzDbds.add(zsyzDb);
                    }
                    bls = false;
                }
            }
            if(bls){
                String endTime = DateUtils.getDate();
                //计算strTime和endTime之间的工作日
                int count = DateUtils.calc(strTime, endTime) - 1;
                //如果超过时间并且督办中不存在则录入督办

                String ts = "";
                if(CommonConstants.ONE.equals(type)){
                    ts = zsyzShqxPzHuang.getStshqx();
                    if (Integer.parseInt(zsyzShqxPzHuang.getStshqx()) > count) {
                        return;
                    }
                }else if(CommonConstants.THR.equals(type)){
                    ts = zsyzShqxPzHuang.getYsbmshqx();
                    if (Integer.parseInt(zsyzShqxPzHuang.getYsbmshqx()) > count) {
                        return;
                    }
                }else if(CommonConstants.FOR.equals(type)){
                    ts = zsyzShqxPzHuang.getCjdcjqx();
                    if (Integer.parseInt(zsyzShqxPzHuang.getCjdcjqx()) > count) {
                        return;
                    }
                }else if(CommonConstants.FIV.equals(type)){
                    ts = zsyzShqxPzHuang.getQylrqx();
                    if (Integer.parseInt(zsyzShqxPzHuang.getQylrqx()) > count) {
                        return;
                    }
                }else if(CommonConstants.SIX.equals(type)){
                    ts = zsyzShqxPzHuang.getQyshqx();
                    if (Integer.parseInt(zsyzShqxPzHuang.getQyshqx()) > count) {
                        return;
                    }
                }else if(CommonConstants.SEV.equals(type)){
                    ts = zsyzShqxPzHuang.getKglrqx();
                    if (Integer.parseInt(zsyzShqxPzHuang.getKglrqx()) > count) {
                        return;
                    }
                }else if(CommonConstants.EIG.equals(type)){
                    ts = zsyzShqxPzHuang.getKgshqx();
                    if (Integer.parseInt(zsyzShqxPzHuang.getKgshqx()) > count) {
                        return;
                    }
                }else if(CommonConstants.NIN.equals(type)){
                    ts = zsyzShqxPzHuang.getTclrqx();
                    if (Integer.parseInt(zsyzShqxPzHuang.getTclrqx()) > count) {
                        return;
                    }
                }else if(CommonConstants.TEN.equals(type)){
                    ts = zsyzShqxPzHuang.getTcshqx();
                    if (Integer.parseInt(zsyzShqxPzHuang.getTcshqx()) > count) {
                        return;
                    }
                }

                Boolean bl = true;
                for (ZsyzDbd dbd : zsyzDbdList) {
                    if ("1".equals(dbd.getDbType()) && zsyzLcjl.getXmId().equals(dbd.getXmId()) && CommonConstants.ONE.equals(dbd.getProgress())) {
                        //存在数据
                        bl = false;
                        break;
                    }
                }
                if (bl) {
                    //录入系统
                    ZsyzDbd zsyzDb = new ZsyzDbd();
                    zsyzDb.setDh(sjs());
                    zsyzDb.setXmId(zsyzLcjl.getXmId());
                    zsyzDb.setXmbh(zsyzLcjl.getXmbh());
                    zsyzDb.setXmbh(zsyzLcjl.getXmmc());
                    //todo 查询督办部门
                    zsyzDb.setDeptId(deptId);
                    zsyzDb.setDeptName(deptName);

                    zsyzDb.setIsHf("N");
                    zsyzDb.setDbTime(DateUtils.getNowDate());
                    zsyzDb.setBlsx(ts);
                    zsyzDb.setDbsx("该项目已超过" + ts + "天未填报进展，请予以说明。");
                    zsyzDb.setDbType("1");
                    zsyzDb.setProgress(type);
                    zsyzDbds.add(zsyzDb);
                }
            }

        } else {
            String endTime = DateUtils.getDate();
            //计算strTime和endTime之间的工作日
            int count = DateUtils.calc(strTime, endTime) - 1;
            //如果超过时间并且督办中不存在则录入督办

            String ts = "";
            if(CommonConstants.ONE.equals(type)){
                ts = zsyzShqxPzHuang.getStshqx();
                if (Integer.parseInt(zsyzShqxPzHuang.getStshqx()) > count) {
                    return;
                }
            }else if(CommonConstants.THR.equals(type)){
                ts = zsyzShqxPzHuang.getYsbmshqx();
                if (Integer.parseInt(zsyzShqxPzHuang.getYsbmshqx()) > count) {
                    return;
                }
            }else if(CommonConstants.FOR.equals(type)){
                ts = zsyzShqxPzHuang.getCjdcjqx();
                if (Integer.parseInt(zsyzShqxPzHuang.getCjdcjqx()) > count) {
                    return;
                }
            }else if(CommonConstants.FIV.equals(type)){
                ts = zsyzShqxPzHuang.getQylrqx();
                if (Integer.parseInt(zsyzShqxPzHuang.getQylrqx()) > count) {
                    return;
                }
            }else if(CommonConstants.SIX.equals(type)){
                ts = zsyzShqxPzHuang.getQyshqx();
                if (Integer.parseInt(zsyzShqxPzHuang.getQyshqx()) > count) {
                    return;
                }
            }else if(CommonConstants.SEV.equals(type)){
                ts = zsyzShqxPzHuang.getKglrqx();
                if (Integer.parseInt(zsyzShqxPzHuang.getKglrqx()) > count) {
                    return;
                }
            }else if(CommonConstants.EIG.equals(type)){
                ts = zsyzShqxPzHuang.getKgshqx();
                if (Integer.parseInt(zsyzShqxPzHuang.getKgshqx()) > count) {
                    return;
                }
            }else if(CommonConstants.NIN.equals(type)){
                ts = zsyzShqxPzHuang.getTclrqx();
                if (Integer.parseInt(zsyzShqxPzHuang.getTclrqx()) > count) {
                    return;
                }
            }else if(CommonConstants.TEN.equals(type)){
                ts = zsyzShqxPzHuang.getTcshqx();
                if (Integer.parseInt(zsyzShqxPzHuang.getTcshqx()) > count) {
                    return;
                }
            }

            Boolean bl = true;
            for (ZsyzDbd dbd : zsyzDbdList) {
                if ("1".equals(dbd.getDbType()) && zsyzLcjl.getXmId().equals(dbd.getXmId()) && CommonConstants.ONE.equals(dbd.getProgress())) {
                    //存在数据
                    bl = false;
                    break;
                }
            }
            if (bl) {
                //录入系统
                ZsyzDbd zsyzDb = new ZsyzDbd();
                zsyzDb.setDh(sjs());
                zsyzDb.setXmId(zsyzLcjl.getXmId());
                zsyzDb.setXmbh(zsyzLcjl.getXmbh());
                zsyzDb.setXmbh(zsyzLcjl.getXmmc());
                //todo 查询督办部门
                zsyzDb.setDeptId(deptId);
                zsyzDb.setDeptName(deptName);

                zsyzDb.setIsHf("N");
                zsyzDb.setDbTime(DateUtils.getNowDate());
                zsyzDb.setBlsx(ts);
                zsyzDb.setDbsx("该项目已超过" + ts + "天未填报进展，请予以说明。");
                zsyzDb.setDbType("1");
                zsyzDb.setProgress(type);
                zsyzDbds.add(zsyzDb);
            }
        }
    }


    public String sjs() {
        return "DB" + String.valueOf(System.currentTimeMillis() / 1000) + String.valueOf(Math.round((Math.random() + 1) * 1000));
    }



}
