
package com.ruoyi.hywz.utils;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.hywz.common.constants.StampWarningCheckRule;
import com.ruoyi.hywz.common.enums.StampWarningTypeEnum;
import com.ruoyi.hywz.entity.*;
import com.ruoyi.hywz.service.*;
import com.ruoyi.system.service.ISysUserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;


@Slf4j
@Configuration
@EnableScheduling
public class ScheduleTaskUtils {

    @Resource
    private IAdsMatHyxtTaskSendMsgDService adsMatHyxtTaskSendMsgDService;

    @Resource
    private IAdsMatHyxtIAppService adsMatHyxtIAppService;

    @Resource
    private IAdsMatHyxtInvoiceDService adsMatHyxtInvoiceDService;

    @Resource
    private IAdsMatHyxtInvoiceApplyDService adsMatHyxtInvoiceApplyDService;

    @Resource
    private IAdsMatHyxtMoneyVoucherDService adsMatHyxtMoneyVoucherDService;

    @Resource
    private IAdsMatHyxtStampTaxInvoiceDService adsMatHyxtStampTaxInvoiceDService;

    @Resource
    private IAdsMatHyxtStampTaxContractDService adsMatHyxtStampTaxContractDService;

    @Resource
    private IAdsMatHyxtStampTaxWarningDService adsMatHyxtStampTaxWarningDService;

    @Resource
    private IAdsMatHyxtStampTaxZhptInvoiceDService adsMatHyxtStampTaxZhptInvoiceDService;

    @Resource
    private IAdsMatHyxtStampTaxZhptInvoiceItemDService adsMatHyxtStampTaxZhptInvoiceItemDService;

    @Resource
    private ISysUserService sysUserService;


    /**
     * 合同/发票预警
     */
    @Resource
    private IAdsMatHyxtStampTaxContractInvoiceDService iAdsMatHyxtStampTaxContractInvoiceDService;

    /**
     * 定时 i国网提醒
     * 0 0 8 * * ?  每天早上8点执行
     */
    @Scheduled(cron = "0 0 8 * * ?")
    public void sendIAppMsg() {
        List<AdsMatHyxtTaskSendMsgD> taskList = adsMatHyxtTaskSendMsgDService.getTask(1);

        for (AdsMatHyxtTaskSendMsgD sendMsgD : taskList) {
            adsMatHyxtIAppService.sendApp(sendMsgD, true);
        }
    }

    /**
     * 定时更新开票申请单单位信息
     * 0 0/1 * * * ?  每分钟执行一次
     */
    @Scheduled(cron = "0 0/1 * * * ?")
    public void batchUpdateOrgInfo() {
        log.info("[开始==》同步更新开票申请单的单位信息][]");
        LambdaQueryWrapper<AdsMatHyxtInvoiceApplyD> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.isNull(AdsMatHyxtInvoiceApplyD::getCreateUserOrgNo);
        List<AdsMatHyxtInvoiceApplyD> list = adsMatHyxtInvoiceApplyDService.list(queryWrapper);
        for (AdsMatHyxtInvoiceApplyD applyD : list) {
            Long createUserId = applyD.getCreateUserId();
            SysUser sysUser = sysUserService.selectUserById(createUserId);
            if (ObjectUtils.isNotEmpty(sysUser) && StringUtils.isNotBlank(sysUser.getOrgNo())) {
                applyD.setCreateUserOrgNo(sysUser.getOrgNo());
                applyD.setCreateUserOrgName(sysUser.getOrgName());
                adsMatHyxtInvoiceApplyDService.updateById(applyD);
            }
        }
        log.info("[结束==》同步更新开票申请单的单位信息][]");
    }

    /**
     * 印花税，定时预警基础数据（合同信息、发票信息）
     * 0 0/3 * * * ?  每3分钟执行一次
     */
    @Scheduled(cron = "0 0/3 * * * ?")
    public void stampTaxBaseDataWarning() {
        log.info("[印花税][定时预警][开始]");
        List<AdsMatHyxtStampTaxContractInvoiceD> contractInvoiceDS = new ArrayList<>();

        // 合同数据
        LambdaQueryWrapper<AdsMatHyxtStampTaxContractD> queryWrapper1 = Wrappers.lambdaQuery();
        queryWrapper1.isNull(AdsMatHyxtStampTaxContractD::getWarningStatusDesc).or().ne(AdsMatHyxtStampTaxContractD::getWarningStatusDesc, "已处理");
        List<AdsMatHyxtStampTaxContractD> contractList = adsMatHyxtStampTaxContractDService.list(queryWrapper1);
        for (AdsMatHyxtStampTaxContractD contractD : contractList) {
            if (StringUtils.isNotBlank(contractD.getWarningStatusDesc()) && "已处理".equals(contractD.getWarningStatusDesc())) {
                continue;
            }
            if (StringUtils.isBlank(contractD.getContractAmount()) || "0".equals(contractD.getContractAmount())) {
                continue;
            }
            String contractWarning = "";

            String contractName = contractD.getContractName();
            String contractType = contractD.getContractType();
            String contractAmount = contractD.getContractAmount();
            String taxationFlag = contractD.getTaxationFlag();
            String taxRate = contractD.getTaxRate();
            BigDecimal convertAmount = AmountUtil.convert(contractAmount);
            String stampTaxItemId = contractD.getStampTaxItemId();

            String contractOrgNo = contractD.getCreateUserOrgNo();
            String contractOrgName = contractD.getCreateUserOrgName();

            // 已计税的跳过
            if (StringUtils.isBlank(taxationFlag) || taxationFlag.equals("Y") || StringUtils.isBlank(stampTaxItemId)) {
                continue;
            }

            // 1、“合同信息表”“合同名称”含有（融资）（回购）字段，“印花税税基计算表”税目为“融资租赁合同”的“合同取数”金额为0【✔】
//            if (StringUtils.isNotBlank(contractName) && (contractName.contains("融资") || contractName.contains("回购")) && convertAmount.compareTo(new BigDecimal(0)) <= 0) {
            if (StringUtils.isNotBlank(contractName) && (contractName.contains("融资") || contractName.contains("回购")) && convertAmount.compareTo(new BigDecimal(0)) <= 0) {
                  this.setContractWarning(contractD, StampWarningTypeEnum.RULE_1.getCode());
                AdsMatHyxtStampTaxContractInvoiceD contractInvoice = this.setContractInvoice(contractD.getId(), StampWarningTypeEnum.RULE_1.getCode(), "强控");
                contractInvoiceDS.add(contractInvoice);
            }

            // 2、“合同信息表”“合同类型”为（租赁服务）的合同，已计税标识为“N”【✔】
            if (StringUtils.isNotBlank(contractType) && contractType.contains("租赁服务") && taxationFlag.equals("N")) {
                AdsMatHyxtStampTaxContractInvoiceD contractInvoice = this.setContractInvoice(contractD.getId(), StampWarningTypeEnum.RULE_2.getCode(), "强控");
                contractInvoiceDS.add(contractInvoice);
            }

            // 3、“合同信息表”“合同类型”为（仓储运输）的合同，已计税标识为“N”【✔】
            if (StringUtils.isNotBlank(contractType) && contractType.contains("仓储运输") && taxationFlag.equals("N")) {
                AdsMatHyxtStampTaxContractInvoiceD contractInvoice = this.setContractInvoice(contractD.getId(), StampWarningTypeEnum.RULE_3.getCode(), "强控");
                contractInvoiceDS.add(contractInvoice);
            }

            // 4、“合同信息表”“合同类型”为（物资买卖类合同），已计税标识为“N”【✔】
            if (StringUtils.isNotBlank(contractType) && contractType.contains("物资买卖") && taxationFlag.equals("N")) {
                AdsMatHyxtStampTaxContractInvoiceD contractInvoice = this.setContractInvoice(contractD.getId(), StampWarningTypeEnum.RULE_4.getCode(), "强控");
                contractInvoiceDS.add(contractInvoice);
            }

            // TODO 5、“合同信息表”“合同类型”为（物资买卖类合同）字段且金额为0，“印花税税基计算表”“增值税发票取数”为0（要查发票表）
//            if (StringUtils.isNotBlank(contractType) && contractType.contains("物资买卖") && convertAmount.compareTo(new BigDecimal(0)) <= 0) {
//                AdsMatHyxtStampTaxContractInvoiceD contractInvoice = this.setContractInvoice(contractD.getId(), StampWarningTypeEnum.RULE_5.getCode(), "强控");
//                contractInvoiceDS.add(contractInvoice);
//            }

            // 6、“合同信息表”“税率”为（0.09）已计税标识为“N”【✔】
            if (StringUtils.isNotBlank(taxRate) && taxRate.trim().equals("0.09") && taxationFlag.equals("N")) {
                AdsMatHyxtStampTaxContractInvoiceD contractInvoice = this.setContractInvoice(contractD.getId(), StampWarningTypeEnum.RULE_6.getCode(), "强控");
                contractInvoiceDS.add(contractInvoice);
            }

            // 7、“合同信息表”“合同名称”含有（勘察）（设计）字样，已计税标识为“N”（此规则删除）【✔】
//            if (StringUtils.isNotBlank(contractName) && (contractName.contains("勘察") || contractName.contains("设计")) && taxationFlag.equals("N")) {
//                AdsMatHyxtStampTaxContractInvoiceD contractInvoice = this.setContractInvoice(contractD.getId(), StampWarningTypeEnum.RULE_7.getCode(), "强控");
//                contractInvoiceDS.add(contractInvoice);
//            }

            // 8、“合同信息表”“合同名称”含有（检测）（测试）（检验）（修理）（维修）字样，已计税标识为“N”【✔】
            if (StringUtils.isNotBlank(contractName) && (contractName.contains("检测") || contractName.contains("测试") || contractName.contains("检验") || contractName.contains("修理") || contractName.contains("维修")) && taxationFlag.equals("N")) {
                AdsMatHyxtStampTaxContractInvoiceD contractInvoice = this.setContractInvoice(contractD.getId(), StampWarningTypeEnum.RULE_8.getCode(), "强控");
                contractInvoiceDS.add(contractInvoice);
            }

            // 9、“合同信息表”“合同类型”为（技术服务类合同_研发）、（技术服务类合同_实施服务）、（技术服务类合同_其他），已计税标识为“N”【✔】
            if (StringUtils.isNotBlank(contractType) && (contractType.contains("技术服务类合同_研发") || contractType.contains("技术服务类合同_实施服务") || contractType.contains("技术服务类合同_其他")) && taxationFlag.equals("N")) {
                AdsMatHyxtStampTaxContractInvoiceD contractInvoice = this.setContractInvoice(contractD.getId(), StampWarningTypeEnum.RULE_9.getCode(), "强控");
                contractInvoiceDS.add(contractInvoice);
            }

            // 15、“合同信息表”“合同类型”为（后勤服务类合同_物业服务）、（公共关系与宣传类合同）、（并网调度类合同）、（咨询委托类合同），已计税标识为N【✔】
            if (StringUtils.isNotBlank(contractType) && (contractType.contains("后勤服务类合同_物业服务") || contractType.contains("公共关系与宣传类合同") || contractType.contains("并网调度类合同") || contractType.contains("咨询委托类合同")) && taxationFlag.equals("N")) {
                AdsMatHyxtStampTaxContractInvoiceD contractInvoice = this.setContractInvoice(contractD.getId(), StampWarningTypeEnum.RULE_15.getCode(), "强控");
                contractInvoiceDS.add(contractInvoice);
            }
//            if (StringUtils.isNotBlank(contractWarning)) {
//                this.setContractWarning(contractD, contractWarning);
//                contractWarningList.add(contractD);
//            }

        }

        // 发票数据
        LambdaQueryWrapper<AdsMatHyxtStampTaxInvoiceD> queryWrapper2 = Wrappers.lambdaQuery();
        queryWrapper2.isNull(AdsMatHyxtStampTaxInvoiceD::getWarningStatusDesc).or().ne(AdsMatHyxtStampTaxInvoiceD::getWarningStatusDesc, "已处理");
        List<AdsMatHyxtStampTaxInvoiceD> invoiceList = adsMatHyxtStampTaxInvoiceDService.list(queryWrapper2);

        for (AdsMatHyxtStampTaxInvoiceD invoiceD : invoiceList) {
            String itemDesc = invoiceD.getItemDesc();   // 货物或应税劳务名称
            String spBusinessType = invoiceD.getSpBusinessType();   // 特定业务类型
            String amount = invoiceD.getAmount();
            BigDecimal convertAmount = AmountUtil.convert(amount);

            boolean waning1Flag = false;
            String invoiceType = invoiceD.getInvoiceType();
            // 16.“发票信息表”“发票票种”含有“专用发票”且“货物或应税劳务名称”含有（米、面、油、护肤品、洗发水、沐浴露、餐椅、餐桌、衣柜、微波炉、洗衣机、冰箱）或“备注”含有（食堂、宿舍），如果是“成品油发票”，不预警
            if (StringUtils.isNotBlank(invoiceType) && invoiceType.contains("专用发票")) {
                if (StringUtils.isNotBlank(spBusinessType) && spBusinessType.contains("成品油发票")) {
                    continue;
                }
                if (StringUtils.isNotBlank(itemDesc)) {
                    if (itemDesc.contains("米") || itemDesc.contains("面") || itemDesc.contains("油") || itemDesc.contains("护肤品")
                            || itemDesc.contains("洗发水") || itemDesc.contains("沐浴露") || itemDesc.contains("餐椅") || itemDesc.contains("餐桌") || itemDesc.contains("衣柜")
                            || itemDesc.contains("微波炉") || itemDesc.contains("洗衣机") || itemDesc.contains("冰箱")) {
                        waning1Flag = true;
                    }
                }
                String remark = invoiceD.getRemark();
                if (StringUtils.isNotBlank(remark)) {
                    if (remark.contains("食堂") || remark.contains("宿舍")) {
                        waning1Flag = true;
                    }
                }
                if (waning1Flag) {
                    AdsMatHyxtStampTaxContractInvoiceD contractInvoice = this.setContractInvoice(invoiceD.getId(), StampWarningTypeEnum.RULE_16.getCode(), "弱控");
                    contractInvoiceDS.add(contractInvoice);
                }
            }

            // 17.“发票信息表”“货物或应税劳务名称”含有（劳务报酬），通过“数电票号码”、“发票号码”查找“全票种发票池（智慧中台）”"发票号码”，查到有数据的提示“请核实是否代扣代缴个人所得税”
            if (StringUtils.isNotBlank(itemDesc) && itemDesc.contains("劳务报酬")) {
                boolean isExist = adsMatHyxtStampTaxZhptInvoiceDService.checkIsWarning1(invoiceD.getInvoiceNumber());

                if (!isExist) {
                    AdsMatHyxtStampTaxContractInvoiceD contractInvoice = this.setContractInvoice(invoiceD.getId(), StampWarningTypeEnum.RULE_17.getCode(), "弱控");
                    contractInvoiceDS.add(contractInvoice);
                }
            }
        }

        // 同一公司如果既在合同信息表取数，又在发票信息表取数，则需要手工检查是否出现重付计算印花税的情况
        for (AdsMatHyxtStampTaxContractD contractD : contractList) {
            if (StringUtils.isNotBlank(contractD.getWarningStatusDesc()) && "已处理".equals(contractD.getWarningStatusDesc())) {
                continue;
            }
            if (StringUtils.isBlank(contractD.getContractAmount()) || "0".equals(contractD.getContractAmount())) {
                continue;
            }

            // 未计税的合同跳过
            if (StringUtils.isBlank(contractD.getTaxationFlag()) || contractD.getTaxationFlag().equals("N")) {
                continue;
            }

            boolean b = false;
            //发票
            for (AdsMatHyxtStampTaxInvoiceD invoiceD : invoiceList) {
                String invoiceWarnings = invoiceD.getWarningType();
                if (contractD.getCounterparty().equals(invoiceD.getSellerName())) {
                    b = true;
                    AdsMatHyxtStampTaxContractInvoiceD contractInvoice = this.setContractInvoice(invoiceD.getId(), StampWarningTypeEnum.RULE_18.getCode(), "弱控");
                    contractInvoiceDS.add(contractInvoice);
                }
            }
            if (b) {
                AdsMatHyxtStampTaxContractInvoiceD contractInvoice = this.setContractInvoice(contractD.getId(), StampWarningTypeEnum.RULE_18.getCode(), "弱控");
                contractInvoiceDS.add(contractInvoice);
            }
        }

        //添加合同、发票预警信息，对已有的已处理过的预警不重复添加，否则会造成重复
        iAdsMatHyxtStampTaxContractInvoiceDService.clearTable();
        iAdsMatHyxtStampTaxContractInvoiceDService.saveBatch(contractInvoiceDS);
        iAdsMatHyxtStampTaxContractInvoiceDService.deleteErrorData();

        //添加合同、发票状态为【预警】
        Set<String> idSet = new HashSet<>();
        for(AdsMatHyxtStampTaxContractInvoiceD aci : contractInvoiceDS){
            idSet.add(aci.getBusinessId());
        }
        List<AdsMatHyxtStampTaxContractD> astcs = new ArrayList<>();
        List<AdsMatHyxtStampTaxInvoiceD> astis = new ArrayList<>();
        for(String id : idSet){
            AdsMatHyxtStampTaxContractD astc = new AdsMatHyxtStampTaxContractD();
            AdsMatHyxtStampTaxInvoiceD asti = new AdsMatHyxtStampTaxInvoiceD();
            astc.setId(id);
            astc.setIsWarning(2);
            astc.setWarningStatusDesc("未处理");
            astcs.add(astc);
            asti.setId(id);
            asti.setIsWarning(2);
            asti.setWarningStatusDesc("未处理");
            astis.add(asti);
        }
        adsMatHyxtStampTaxContractDService.updateBatchById(astcs);
        adsMatHyxtStampTaxInvoiceDService.updateBatchById(astis);

        //合同、发票如果其所有预警均处理则更改状态【非预警】
        List<String> ids = iAdsMatHyxtStampTaxContractInvoiceDService.findContractIdByStatu();
        if(ids!=null && ids.size()>0){
            UpdateWrapper<AdsMatHyxtStampTaxContractD> updateWrapper = new UpdateWrapper<>();
            updateWrapper.notIn("id",ids);
            updateWrapper.set("is_warning",0);
            updateWrapper.set("warning_status_desc","已处理");
            adsMatHyxtStampTaxContractDService.update(updateWrapper);
        }

//        if (!contractWarningList.isEmpty()) {
//            log.info("{} 条合同预警数据", contractWarningList.size());
//            adsMatHyxtStampTaxContractDService.updateBatchById(contractWarningList);
//        }
//        if (!invoiceWarningList.isEmpty()) {
//            log.info("{} 条发票预警数据", invoiceWarningList.size());
//            .updateBatchById(invoiceWarningList);
//        }

//        this.stampTaxBaseDataWarningRole_18();

        log.info("[印花税][定时预警][结束]");
    }

    private void stampTaxBaseDataWarningRole_18() {

        List<AdsMatHyxtStampTaxContractD> contractWarningList = new ArrayList<>();
        List<AdsMatHyxtStampTaxInvoiceD> invoiceWarningList = new ArrayList<>();

        LambdaQueryWrapper<AdsMatHyxtStampTaxContractD> queryWrapper1 = Wrappers.lambdaQuery();
        queryWrapper1.isNull(AdsMatHyxtStampTaxContractD::getWarningStatusDesc).or().ne(AdsMatHyxtStampTaxContractD::getWarningStatusDesc, "已处理");
        List<AdsMatHyxtStampTaxContractD> contractList = adsMatHyxtStampTaxContractDService.list(queryWrapper1);
        LambdaQueryWrapper<AdsMatHyxtStampTaxInvoiceD> queryWrapper2 = Wrappers.lambdaQuery();
        queryWrapper2.isNull(AdsMatHyxtStampTaxInvoiceD::getWarningStatusDesc).or().ne(AdsMatHyxtStampTaxInvoiceD::getWarningStatusDesc, "已处理");
        List<AdsMatHyxtStampTaxInvoiceD> invoiceList = adsMatHyxtStampTaxInvoiceDService.list(queryWrapper2);
        //合同
        for (AdsMatHyxtStampTaxContractD adsMatHyxtStampTaxContractD : contractList) {
            String contractWarning = adsMatHyxtStampTaxContractD.getWarningType();
            boolean b = false;
            //发票
            for (AdsMatHyxtStampTaxInvoiceD invoiceD : invoiceList) {
                String invoiceWarnings = invoiceD.getWarningType();
                if (adsMatHyxtStampTaxContractD.getCounterparty().equals(invoiceD.getSellerName())) {
                    b = true;
//                    this.setInvoiceWarning(invoiceD, StampWarningTypeEnum.RULE_18.getCode());
//                    invoiceWarningList.add(invoiceD);
                    invoiceWarnings = (StringUtils.isNotBlank(invoiceWarnings) ? invoiceWarnings + "," : "") + StampWarningTypeEnum.RULE_18.getCode();
                }
                //发票
                if (StringUtils.isNotBlank(invoiceWarnings)) {

                    String[] split = invoiceWarnings.split(",");
                    Set<String> set = new HashSet<>(Arrays.asList(split));
                    String join = String.join(",", set);

                    this.setInvoiceWarning(invoiceD, join);
                    invoiceWarningList.add(invoiceD);
                }
            }
            if (b) {
//                this.setContractWarning(adsMatHyxtStampTaxContractD, StampWarningTypeEnum.RULE_18.getCode());
//                contractWarningList.add(adsMatHyxtStampTaxContractD);
                contractWarning = (StringUtils.isNotBlank(contractWarning) ? contractWarning + "," : "") + StampWarningTypeEnum.RULE_18.getCode();
            }
            if (StringUtils.isNotBlank(contractWarning)) {

                String[] split = contractWarning.split(",");
                Set<String> set = new HashSet<>(Arrays.asList(split));
                String join = String.join(",", set);

                this.setContractWarning(adsMatHyxtStampTaxContractD, contractWarning);
                contractWarningList.add(adsMatHyxtStampTaxContractD);
            }
        }

        if (!contractWarningList.isEmpty()) {
            log.info("{} 条合同预警数据", contractWarningList.size());
            adsMatHyxtStampTaxContractDService.updateBatchById(contractWarningList);
        }
        if (!invoiceWarningList.isEmpty()) {
            log.info("{} 条发票预警数据", invoiceWarningList.size());
            adsMatHyxtStampTaxInvoiceDService.updateBatchById(invoiceWarningList);
        }

    }

    private void setContractWarning(AdsMatHyxtStampTaxContractD contractD, String warningType) {
        contractD.setWarningLevel("强控");
        contractD.setWarningStatusDesc("未处理");
        contractD.setWarningTime(new Date());
        contractD.setWarningType(warningType);
        contractD.setIsWarning(1);
    }

    private void setInvoiceWarning(AdsMatHyxtStampTaxInvoiceD invoiceD, String warningType) {
        invoiceD.setWarningLevel("弱控");
        invoiceD.setWarningStatusDesc("未处理");
        invoiceD.setWarningTime(new Date());
        invoiceD.setWarningType(warningType);
        invoiceD.setIsWarning(2);
    }


    /**
     *
     * @param businessId 业务id
     * @param warningType 预警类型
     * @param ContractCode 合同编码
     * @param warningLevel 风险等级
     */
    private AdsMatHyxtStampTaxContractInvoiceD setContractInvoice(String businessId,String warningType,String warningLevel) {
        AdsMatHyxtStampTaxContractInvoiceD contractInvoice = new AdsMatHyxtStampTaxContractInvoiceD();
        contractInvoice.setBusinessId(businessId);
        contractInvoice.setWarningType(warningType);
        contractInvoice.setWarningStatusDesc("未处理");
        contractInvoice.setWarningLevel(warningLevel);
        contractInvoice.setWarningTime(new Date());
        return contractInvoice;
    }

    /**
     * TODO 定时同步入账凭证号
     * 0 0 * * * ? 每小时执行一次
     * 0 0/1 * * * ? 每分钟执行一次
     */
    @Scheduled(cron = "0 0 * * * ?")
    public void syncVoucherCode() {
//        // 1.查询停留在最后一步的数据
//        List<AdsMatHyxtInvoiceD> list = adsMatHyxtInvoiceDService.selectNode12List();
//
//        // 2.匹配
//        for (AdsMatHyxtInvoiceD invoiceD : list) {
//            // 是否是项目类
//            if (invoiceD.getApplyType().equals(ApplyTypeEnum.XM.getType())) {
//                // 主业wbs编码-名称
//                String projectNo = invoiceD.getProjectNo();
//                String projectName = invoiceD.getProjectName();
////                String zy = projectNo+"-"+projectName;
//                AdsMatHyxtMoneyVoucherD zyProject = adsMatHyxtMoneyVoucherDService.getBySingleProject(projectNo, projectName, "付款");
//                boolean zyFlag = false;
//                if (null != zyProject && StringUtils.isNotEmpty(zyProject.getVoucherCode())) {
//                    zyFlag = true;
//                    invoiceD.setVoucherCode(zyProject.getVoucherCode());
//                }
//
//                // 产业项目编码-名称
//                String ynProjectNo = invoiceD.getYnProjectNo();
//                String ynProjectName = invoiceD.getYnProjectName();
////                String yn = ynProjectNo+"-"+ynProjectName;
//                AdsMatHyxtMoneyVoucherD ynProject = adsMatHyxtMoneyVoucherDService.getBySingleProject(ynProjectNo, ynProjectName, "收款");
//                boolean ynFlag = false;
//                if (null != ynProject && StringUtils.isNotEmpty(ynProject.getVoucherCode())) {
//                    ynFlag = true;
//                    invoiceD.setYnVoucherCode(ynProject.getVoucherCode());
//                }
//
//                boolean isGenerateCode = zyFlag && ynFlag;
//                if (zyFlag || ynFlag) {
//                    if (isGenerateCode) {
//                        invoiceD.setIsGenerateCode(1);
//                    }
//                    invoiceD.setUpdateTime(new Date());
//                    adsMatHyxtInvoiceDService.updateById(invoiceD);
//                }
//
//                // 自动闭环流程
//                if (isGenerateCode) {
//                    // TODO
//                }
//
//            }
//        }
    }

}

