package com.dxhy.core.job.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.dxhy.api.model.custom.TDxExportCustoms;
import com.dxhy.api.model.db.*;
import com.dxhy.api.model.invoice.TDxExportInvoice;
import com.dxhy.api.model.ncp.ncpCustoms.TdxCustomsNcpJjkcEntity;
import com.dxhy.api.model.ncp.ncpJjkcInvoice.TdxInvoiceNcpJjkcEntity;
import com.dxhy.api.model.rz.rzCustom.TdxLqRzCustomEntity;
import com.dxhy.api.model.rz.rzInvoice.page.TdxLqRzInvoice;
import com.dxhy.common.constant.ConfigureConstant;
import com.dxhy.common.util.HttpUtils;
import com.dxhy.common.utils.Base64FileUtil;
import com.dxhy.core.dao.TDxExportCustomsDao;
import com.dxhy.core.dao.TDxExportInvoiceDao;
import com.dxhy.core.job.service.PoolPushService;
import com.dxhy.core.model.erpPool.*;
import com.dxhy.core.util.DateUtils;
import com.dxhy.customs.dao.CustomsNcpJjkcCustomsDao;
import com.dxhy.jxpt.baseService.dao.*;
import com.dxhy.jxpt.baseService.ncpInvoice.dao.NcpJjkcRecordInvoiceDao;
import com.dxhy.jxpt.baseService.ncpInvoice.dao.TdxDkCountDao;
import com.dxhy.jxpt.baseService.rzInvoice.dao.RzRecordCustomDao;
import com.dxhy.jxpt.baseService.rzInvoice.dao.TDxLqRzInvoiceDao;
import com.dxhy.lqchannel.job.dao.TdxLqRzCustomDao;
import com.dxhy.lqchannel.job.entity.TdxLqRzCustom;
import com.dxhy.oss.service.FileService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;

/**
* @Description 推送票池业务
* @Author wangruwei
* @Date 2024/10/29 11:07
**/
@Service("PoolPushService")
@Slf4j
@SuppressWarnings({"AlibabaUndefineMagicConstant", "AlibabaMethodTooLong"})
public class PoolPushServiceImpl implements PoolPushService {
    @Resource
    private TdxRecordInvoiceDao tdxRecordInvoiceDao;
    @Resource
    private TDxRecordInvoiceDetailDao tDxRecordInvoiceDetailDao;
    @Resource
    private TdxRecordInvoiceFjysxxDao tdxRecordInvoiceFjysxxDao;
    @Resource
    private TdxRecordTspzKzxxDao tdxRecordTspzKzxxDao;
    @Resource
    private TdxTdysMhxcdCoreDao tdxTdysMhxcdCoreDao;
    @Resource
    private TdxTdysMhxcdMxCoreDao tdxTdysMhxcdMxCoreDao;
    @Resource
    private TdxTdysTldzkpCoreDao tdxTdysTldzkpCoreDao;
    @Resource
    private TdxVehicleSaleInvoiceDao tdxVehicleSaleInvoiceDao;
    @Resource
    private TDxLqRzInvoiceDao tDxLqRzInvoiceDao;
    @Resource
    private TdxPoolLogDao tdxPoolLogDao;
    @Resource
    private TDxExportInvoiceDao tDxExportInvoiceDao;
    @Resource
    private ZzsDkdjWspzDao zzsDkdjWspzDao;
    @Autowired
    private TdxDbCustomsRecordDao tdxCustomsRecordDao;

    @Autowired
    private TDxExportCustomsDao tDxExportCustomsDao;
    @Resource
    private RzRecordCustomDao rzRecordCustomDao;
    @Resource
    private TdxLqRzCustomDao tdxLqRzCustomDao;
    @Resource
    private TdxCustomsDetailDao tdxCustomsDetailDao;
    @Resource
    private TdxDkCountDao tdxDkCountDao;
    @Resource
    private TdxInvoiceFileDao tdxInvoiceFileDao;
    @Resource
    private FileService fileService;
    @Resource
    private NcpJjkcRecordInvoiceDao ncpJjkcRecordInvoiceDao;
    @Resource
    private CustomsNcpJjkcCustomsDao customsNcpJjkcCustomsDao;

    /**
     * 推送票池开关
     **/
    @Value("${jxpt.poolPush.pushUrl:}")
    private String poolPushUrl;

    /**
     * @Description 发送数据到票池
     * @param uuids
     * @param sjlx
     * @param bglx
     * @param isRecordFlag 是否全量标志，true，推送底账pool_push未0的，false，推送pool_log表的增量数据
     * @Return void
     * @Author wangruwei
     * @Date 2024/10/29 11:06
     **/
    @Override
    public void pushDataToPool(List<String> uuids, String sjlx, String bglx, boolean isRecordFlag) {

        //票据类型：1.进项发票，2.缴款书，3.代扣代缴完税凭
        //变更类型：1.数据变更，2.状态变更，3.源文件变更，4、属期状态变更
        if("1".equals(sjlx)&&"1".equals(bglx)){
            log.info("增值税发票-数据-推送");
            poolPushInvoice(uuids,isRecordFlag);
            if(isRecordFlag){
                //如果是历史全量，同步推送历史源文件
                poolPushYwj(uuids,isRecordFlag);
            }
        }else if("1".equals(sjlx)&&"2".equals(bglx)){
            log.info("增值税发票-状态-推送");
            poolPushPjzt(sjlx,uuids,isRecordFlag);
        }else if("1".equals(sjlx)&&"3".equals(bglx)){
            log.info("增值税发票源文件推送");
            poolPushYwj(uuids,isRecordFlag);
        }else if("1".equals(sjlx)&&"5".equals(bglx)){
            log.info("增值税发票-加计扣除-推送");
            poolPushFpjjkc(uuids,isRecordFlag);
        }else if("3".equals(sjlx)&&"1".equals(bglx)){
            log.info("增值税代扣代缴完税凭证-数据-推送");
            poolPushDkdj(uuids,isRecordFlag);
        }else if("3".equals(sjlx)&&"2".equals(bglx)){
            log.info("增值税代扣代缴完税凭证-状态-推送");
            poolPushDkdjZt(sjlx,uuids,isRecordFlag);
        }else if("2".equals(sjlx)&&"1".equals(bglx)){
            log.info("海关缴款书-数据-推送");
            poolPushJks(uuids,isRecordFlag);
        }else if("2".equals(sjlx)&&"2".equals(bglx)){
            log.info("海关缴款书-状态-推送");
            poolPushJksZt(sjlx,uuids,isRecordFlag);
        }else if("2".equals(sjlx)&&"5".equals(bglx)){
            log.info("海关缴款书-加计扣除-推送");
            poolPushJksJjkc(uuids,isRecordFlag);
        }else if(StringUtils.isEmpty(sjlx)&& "1".equals(bglx)){
            log.info("属期变更-数据-推送");
            poolPushSqbg(uuids,isRecordFlag);
        }else if(StringUtils.isEmpty(sjlx)&& "4".equals(bglx)){
            log.info("属期变更-状态-推送");
            poolPushSqbg(uuids,isRecordFlag);
        }else{
            log.error("没有此推送类型,sjlx:{},bglx:{}",sjlx,bglx);
        }
    }

    /**
    * @Description 海关缴款书-加计扣除-推送
    * @param uuids
    * @param isRecordFlag
    * @Return void
    * @Author wangruwei
    * @Date 2024/12/12 10:12
    **/
    private void poolPushJksJjkc(List<String> uuids, boolean isRecordFlag) {
        //定义请求数据体
        List<ErpNcpJjckCustomsMx> fpJksList = new LinkedList<>();

        uuids.stream().forEach(item->{
            try {
                //组装方法
                ErpNcpJjckCustomsMx jkcJjkc = buildErpJksJjkc(item);
                if(ObjectUtils.isNotEmpty(jkcJjkc)){
                    fpJksList.add(jkcJjkc);
                }
            }catch (Exception e){
                log.info("组装数据失败，失败的uuid:{},错误:{}",item,e);
            }
        });
        log.info("组装完成，本次发送数据条数:{}",fpJksList.size());

        List<String> reqUuids = fpJksList.stream().map(e->e.getCustomsCode()+"@"+e.getJjssq()).collect(Collectors.toList());
        if(reqUuids.size()>0){
            String reqStr = JSON.toJSONString(fpJksList);
            pushPoolAndUpdatePoolLog(reqStr,reqUuids,"NCPJJKCJKSMXTS", isRecordFlag);
        }
    }

    private ErpNcpJjckCustomsMx buildErpJksJjkc(String item) {
        String[] split = item.split("@");
        String uuid = split[0];
        String jjssq = split[1];
        ErpNcpJjckCustomsMx erpNcpJjckCustomsMx = null;
        TdxCustomsNcpJjkcEntity dbCustomsJjkc = customsNcpJjkcCustomsDao.selectOne(new LambdaQueryWrapper<TdxCustomsNcpJjkcEntity>()
                .eq(TdxCustomsNcpJjkcEntity::getCustomsCode, uuid)
                .eq(TdxCustomsNcpJjkcEntity::getJjssq, jjssq)
        );
        if(ObjectUtils.isNotEmpty(dbCustomsJjkc)){
            erpNcpJjckCustomsMx = new ErpNcpJjckCustomsMx();
            erpNcpJjckCustomsMx.setCustomsCode(dbCustomsJjkc.getCustomsCode());
            erpNcpJjckCustomsMx.setFillInDate(DateUtils.dateToStr(dbCustomsJjkc.getFillInDate(),"yyyy-MM-dd HH:mm:ss"));
            erpNcpJjckCustomsMx.setCkznxzmbh(dbCustomsJjkc.getCkznxzmbh());
            erpNcpJjckCustomsMx.setGfTaxNo(dbCustomsJjkc.getGfTaxNo());
            erpNcpJjckCustomsMx.setSqlx(dbCustomsJjkc.getSqlx());
            erpNcpJjckCustomsMx.setJjssq(dbCustomsJjkc.getJjssq());
            erpNcpJjckCustomsMx.setBcjjkcse(dbCustomsJjkc.getBcjjkcse());
            erpNcpJjckCustomsMx.setGxsj(ObjectUtils.isNotEmpty(dbCustomsJjkc.getGxsj())?DateUtils.dateToStr(dbCustomsJjkc.getGxsj(),"yyyy-MM-dd HH:mm:ss"):"");
        }
        return erpNcpJjckCustomsMx;
    }

    /**
    * @Description 增值税发票-加计扣除-推送
    * @param uuids
    * @param isRecordFlag
    * @Return void
    * @Author wangruwei
    * @Date 2024/12/12 9:51
    **/
    private void poolPushFpjjkc(List<String> uuids, boolean isRecordFlag) {
        //定义请求数据体
        List<ErpNcpJjckInvoiceMx> fpJjkcList = new LinkedList<>();

        uuids.stream().forEach(item->{
            try {
                //组装方法
                ErpNcpJjckInvoiceMx fpJjkc = buildErpFpJjkc(item);
                if(ObjectUtils.isNotEmpty(fpJjkc)){
                    fpJjkcList.add(fpJjkc);
                }
            }catch (Exception e){
                log.info("组装数据失败，失败的uuid:{},错误:{}",item,e);
            }
        });
        log.info("组装完成，本次发送数据条数:{}",fpJjkcList.size());

        List<String> reqUuids = fpJjkcList.stream().map(e->e.getInvoiceCode()+e.getInvoiceNo()+"@"+e.getJjssq()).collect(Collectors.toList());
        if(reqUuids.size()>0){
            String reqStr = JSON.toJSONString(fpJjkcList);
            pushPoolAndUpdatePoolLog(reqStr,reqUuids,"NCPJJKCFPMXTS", isRecordFlag);
        }
    }

    private ErpNcpJjckInvoiceMx buildErpFpJjkc(String item) {
        String[] split = item.split("@");
        String uuid = split[0];
        String jjssq = split[1];
        ErpNcpJjckInvoiceMx erpNcpJjckInvoiceMx = null;
        TdxInvoiceNcpJjkcEntity jjkcEntity = ncpJjkcRecordInvoiceDao.selectOne(new LambdaQueryWrapper<TdxInvoiceNcpJjkcEntity>()
                .eq(TdxInvoiceNcpJjkcEntity::getUuid, uuid)
                .eq(TdxInvoiceNcpJjkcEntity::getJjssq, jjssq)
        );
        if(ObjectUtils.isNotEmpty(jjkcEntity)){
            erpNcpJjckInvoiceMx = new ErpNcpJjckInvoiceMx();
            erpNcpJjckInvoiceMx.setInvoiceCode(jjkcEntity.getInvoiceCode());
            erpNcpJjckInvoiceMx.setInvoiceNo(jjkcEntity.getInvoiceNo());
            erpNcpJjckInvoiceMx.setEleInvoiceNo(jjkcEntity.getEleInvoiceNo());
            erpNcpJjckInvoiceMx.setInvoiceType(jjkcEntity.getInvoiceType());
            erpNcpJjckInvoiceMx.setInvoiceDate(DateUtils.dateToStr(jjkcEntity.getInvoiceDate(),"yyyy-MM-dd HH:mm:ss"));
            erpNcpJjckInvoiceMx.setGfTaxNo(jjkcEntity.getGfTaxNo());
            erpNcpJjckInvoiceMx.setSqlx(jjkcEntity.getSqlx());
            erpNcpJjckInvoiceMx.setJjssq(jjkcEntity.getJjssq());
            erpNcpJjckInvoiceMx.setBcjjkcse(jjkcEntity.getBcjjkcse());
            erpNcpJjckInvoiceMx.setGxsj(ObjectUtils.isNotEmpty(jjkcEntity.getGxsj())?DateUtils.dateToStr(jjkcEntity.getInvoiceDate(),"yyyy-MM-dd HH:mm:ss"):"");
        }
        return erpNcpJjckInvoiceMx;
    }

    /**
    * @Description 增值税发票源文件推送
    * @param uuids
    * @param isRecordFlag
     * @Return void
    * @Author wangruwei
    * @Date 2024/10/30 14:45
    **/
    private void poolPushYwj(List<String> uuids, boolean isRecordFlag) {
        //定义请求数据体
        log.info("开始组源文件请求数据");
        uuids.stream().forEach(item->{
            try {
                //组装方法
                ErpPushFile erpPushFile = buildErpPushFile(item);
                if (ObjectUtils.isNotEmpty(erpPushFile)) {
                    pushPoolAndUpdatePoolLog(JSON.toJSONString(erpPushFile), Arrays.asList(item),"ZZSFPYWJTS", isRecordFlag);
                }
            }catch (Exception e){
                log.info("组装数据失败，失败的uuid:{},错误{}",item,e);
            }
        });
    }
    /**
    * @Description 组装推送文件流的数据结构
    * @param uuid
    * @Return com.dxhy.core.model.erpPool.ErpPushFile
    * @Author wangruwei
    * @Date 2024/10/30 14:46
    **/
    private ErpPushFile buildErpPushFile(String uuid) {
        
        ErpPushFile erpPushFile = null;

        //erpPushFile.setXmlPath();
        //erpPushFile.setPdfPath();
        //erpPushFile.setOfdPath();
        TDxInvoiceFileEntity dbInvoiceFile = tdxInvoiceFileDao.selectOne(new LambdaQueryWrapper<TDxInvoiceFileEntity>().eq(TDxInvoiceFileEntity::getUuid, uuid));
        if(ObjectUtils.isNotEmpty(dbInvoiceFile)){
            erpPushFile = new ErpPushFile();

            erpPushFile.setSjly(ConfigureConstant.POOL_SJLY);
            erpPushFile.setInvoiceCode(uuid.substring(0,12));
            erpPushFile.setInvoiceNo(uuid.substring(12, 20));
            //判断是否存在
            if(StringUtils.isNotBlank(dbInvoiceFile.getPdfPath())){
                erpPushFile.setPdfStream(getSjl(dbInvoiceFile.getPdfPath()));
            }
            if(StringUtils.isNotBlank(dbInvoiceFile.getOfdPath())){
                erpPushFile.setOfdStream(getSjl(dbInvoiceFile.getOfdPath()));
            }
            if(StringUtils.isNotBlank(dbInvoiceFile.getXmlPath())){
                erpPushFile.setXmlStream(getSjl(dbInvoiceFile.getXmlPath()));
            }
        }

        return erpPushFile;
    }

    /**
    * @Description 获取文件流
    * @param filePath
    * @Return java.lang.String
    * @Author wangruwei
    * @Date 2024/10/30 14:51
    **/
    private String getSjl(String filePath) {
        String localPath = fileService.getLocalPathDefault()+ filePath.substring(filePath.lastIndexOf("/") + 1);
        File localFile = new File(localPath);
        try {
            log.info("获取xml数据流开始,源文件路径：{}，临时文件路径：{}",filePath,localPath);
            fileService.downFile(filePath, localPath);
            //return Base64Encoding.encodeToString(FileUtils.readFileToByteArray(localFile));
            return Base64FileUtil.fileToBase64(localFile);
        } catch (Exception e) {
            log.info("获取xml数据流异常：{}",e);
            return null;
        }finally {
            if (localFile.exists()) {
                localFile.delete();
            }
        }
    }

    /**
    * @Description 属期变更-数据-推送
    * @Return void
    * @Author wangruwei
    * @Date 2024/10/30 14:35
    **/
    private void poolPushSqbg(List<String> uuids, boolean isRecordFlag) {
        //定义请求数据体
        log.info("开始组装数据");
        uuids.stream().forEach(item->{
            try {
                //组装方法
                ErpPushSkssqStatus erpInvoiceState = buildSkssqState(item);
                if(ObjectUtils.isNotEmpty(erpInvoiceState)){
                    pushPoolAndUpdatePoolLog(JSON.toJSONString(erpInvoiceState), Arrays.asList(item),"NSRSQZTTS", isRecordFlag);
                }
            }catch (Exception e){
                log.info("组装数据失败，失败的uuid:{},错误{}",item,e);
            }
        });
    }

    /**
    * @Description 属期变更数据
    * @param uuid
    * @Return com.dxhy.core.model.erpPool.ErpPushSkssqStatus
    * @Author wangruwei
    * @Date 2024/10/30 14:37
    **/
    private ErpPushSkssqStatus buildSkssqState(String uuid) {
        ErpPushSkssqStatus erpInvoiceState = null;
        
        String taxno = uuid.split("@")[0];
        String skssq = uuid.split("@")[1];
        TDxDkCountEntity dbDkCount = tdxDkCountDao.selectOne(new LambdaQueryWrapper<TDxDkCountEntity>()
                .eq(TDxDkCountEntity::getTaxno, taxno)
                .eq(TDxDkCountEntity::getSkssq, skssq)
        );
        if(ObjectUtils.isNotEmpty(dbDkCount)){
            erpInvoiceState = new ErpPushSkssqStatus();
            erpInvoiceState.setNsrmc(dbDkCount.getTaxname());
            erpInvoiceState.setNsrsbh(dbDkCount.getTaxno());
            erpInvoiceState.setSkssq(dbDkCount.getSkssq());
            String qsStatus = dbDkCount.getQsStatus();
            if("2".equals(qsStatus)){
                erpInvoiceState.setQrzt("1");
            }else{
                erpInvoiceState.setQrzt("0");
            }
            //erpInvoiceState.setCbszt();
            //erpInvoiceState.setSbzt();
        }
        return erpInvoiceState;
    }

    /**
    * @Description 海关缴款书-状态-推送
    * @param sjlx
    * @param uuids
    * @param isRecordFlag
     * @Return void
    * @Author wangruwei
    * @Date 2024/10/30 14:21
    **/
    private void poolPushJksZt(String sjlx, List<String> uuids, boolean isRecordFlag) {
        //定义请求数据体
        ErpPushInvoiceState erpPushInvoiceState = new ErpPushInvoiceState();
        erpPushInvoiceState.setPjlx(sjlx);
        erpPushInvoiceState.setSjly(ConfigureConstant.POOL_SJLY);
        log.info("开始组装数据");
        List<ErpInvoiceState> invoiceStates = new LinkedList();
        uuids.stream().forEach(item->{
            try {
                //组装方法
                ErpInvoiceState erpInvoiceState = buildErpJksState(item);
                if(ObjectUtils.isNotEmpty(erpInvoiceState)){
                    invoiceStates.add(erpInvoiceState);
                }
            }catch (Exception e){
                log.info("组装数据失败，失败的uuid:{},错误{}",item,e);
            }
        });
        erpPushInvoiceState.setInvoiceState(invoiceStates);
        log.info("组装完成，本次发送数据条数:{}",invoiceStates.size());

        List<String> reqUuids = invoiceStates.stream().map(e->e.getInvoiceNo()).collect(Collectors.toList());
        if(reqUuids.size()>0){
            String reqStr = JSON.toJSONString(erpPushInvoiceState);
            pushPoolAndUpdatePoolLog(reqStr,reqUuids,"PJZTTS", isRecordFlag);
        }
    }
    /**
    * @Description 缴款书状态
    * @param uuid
    * @Return com.dxhy.core.model.erpPool.ErpInvoiceState
    * @Author wangruwei
    * @Date 2024/10/30 14:22
    **/
    private ErpInvoiceState buildErpJksState(String uuid) {
        ErpInvoiceState erpInvoiceState = null;


        TdxCustomsRecordEntity dbCustoms = tdxCustomsRecordDao.selectOne(new LambdaQueryWrapper<TdxCustomsRecordEntity>().eq(TdxCustomsRecordEntity::getCustomsCode, uuid));
        if(ObjectUtils.isNotEmpty(dbCustoms)) {
            erpInvoiceState = new ErpInvoiceState();
            //erpInvoiceState.setInvoiceCode();
            erpInvoiceState.setInvoiceNo(dbCustoms.getCustomsCode());
            //erpInvoiceState.setInvoiceStatus(dbCustoms.get);
            erpInvoiceState.setGlzt(dbCustoms.getGlzt());

            if("0".equals(dbCustoms.getExportMark())){
                String rzhYesorno = dbCustoms.getRzhYesorno();
                String rzlx = dbCustoms.getRzlx();
                if("0".equals(rzhYesorno)){
                    erpInvoiceState.setFpyt("0");
                }else if("1".equals(rzhYesorno)){
                    //认证抵扣
                    if("1".equals(rzlx)){
                        erpInvoiceState.setFpyt("1");
                    }
                    if("2".equals(rzlx)){
                        erpInvoiceState.setFpyt("3");
                    }
                    if("3".equals(rzlx)){
                        erpInvoiceState.setFpyt("4");
                    }
                }else if("2".equals(rzhYesorno)){
                    erpInvoiceState.setFpyt("2");
                }else{
                    log.info("发票用途不赋值，没有对应条件。uuid:{},rzhyesorno:{},rzlx:{}",uuid,rzhYesorno,rzlx);
                }
                erpInvoiceState.setRzssq(dbCustoms.getRzhBelongDate());
            }else if("1".equals(dbCustoms.getExportMark())){
                TDxExportCustoms tDxExportCustoms = tDxExportCustomsDao.selectOne(new LambdaQueryWrapper<TDxExportCustoms>().eq(TDxExportCustoms::getCustomsCode, dbCustoms.getCustomsCode()));
                String rzhYesorno = tDxExportCustoms.getRzhYesorno();
                String rzlx = tDxExportCustoms.getRzlx();
                if("0".equals(rzhYesorno)){
                    erpInvoiceState.setFpyt("0");
                }else if("1".equals(rzhYesorno)){
                    //认证抵扣
                    if("1".equals(rzlx)){
                        erpInvoiceState.setFpyt("1");
                    }
                    if("2".equals(rzlx)){
                        erpInvoiceState.setFpyt("3");
                    }
                    if("3".equals(rzlx)){
                        erpInvoiceState.setFpyt("4");
                    }
                }else if("2".equals(rzhYesorno)){
                    erpInvoiceState.setFpyt("2");
                }else{
                    log.info("发票用途不赋值，没有对应条件。uuid:{},rzhyesorno:{},rzlx:{}",uuid,rzhYesorno,rzlx);
                }
                erpInvoiceState.setRzssq(tDxExportCustoms.getRzhBelongDate());
            }

            erpInvoiceState.setDkTaxAmount(dbCustoms.getYxTaxAmount());
            erpInvoiceState.setBdkyy(dbCustoms.getBdkYy());
            erpInvoiceState.setBdkMessage(dbCustoms.getBdkMessage());
            //erpInvoiceState.setHzsdbs(dbCustoms.get);
            TdxLqRzCustomEntity tdxLqRzCustomEntity = rzRecordCustomDao.selectOne(new LambdaQueryWrapper<TdxLqRzCustomEntity>().eq(TdxLqRzCustomEntity::getCustomsCode, uuid));
            if(ObjectUtils.isNotEmpty(tdxLqRzCustomEntity)){
                if("01".equals(tdxLqRzCustomEntity.getJksrzlx())||"06".equals(tdxLqRzCustomEntity.getJksrzlx())){
                    //不设置入账类型
                }else{
                    erpInvoiceState.setInAccountType(tdxLqRzCustomEntity.getJksrzlx());
                }
                erpInvoiceState.setInAccountSsq(tdxLqRzCustomEntity.getJksrzsq());
                //入账状态
                String fprzauthStatus = tdxLqRzCustomEntity.getJksrzAuthStatus();
                //入账申请状态：1申请入账，2发送入账请求，3入账失败，4入账成功，5申请撤销，6发送撤销申请，7撤销失败，8撤销成功
                //4 5 6 7 属于入账成功
                //1 2 3 8 属于入账失败
                if("4".equals(fprzauthStatus)||"5".equals(fprzauthStatus)||"6".equals(fprzauthStatus)||"7".equals(fprzauthStatus)){
                    erpInvoiceState.setInAccountStatus("1");
                }else{
                    erpInvoiceState.setInAccountStatus("0");
                }
            }
            //erpInvoiceState.setCpyycbs(dbCustoms.get);
            erpInvoiceState.setXfsyt(dbCustoms.getLqXfsyt());
            //erpInvoiceState.setJdcycbs(dbCustoms.get);
            erpInvoiceState.setCwrzzt(dbCustoms.getInAccountStatus());
            erpInvoiceState.setCwrzssq(dbCustoms.getInAccountDate());
        }
        return erpInvoiceState;
    }

    /**
    * @Description 海关缴款书-数据-推送
    * @param uuids
    * @param isRecordFlag
     * @Return void
    * @Author wangruwei
    * @Date 2024/10/30 13:58
    **/
    private void poolPushJks(List<String> uuids, boolean isRecordFlag) {
        //定义请求数据体
        ErpPushCustoms erpPushCustoms = new ErpPushCustoms();
        String pch = UUID.randomUUID().toString().replace("-", "");
        erpPushCustoms.setPch(pch);

        erpPushCustoms.setSjly(ConfigureConstant.POOL_SJLY);
        List<ErpCustoms> reqData = new LinkedList<>();

        log.info("开始组装数据，当前pch:{}",pch);
        uuids.stream().forEach(item->{
            try {
                //组装方法
                ErpCustoms erpReqInvoice = buildErpCustoms(item);
                if(ObjectUtils.isNotEmpty(erpReqInvoice)){
                    reqData.add(erpReqInvoice);
                }
            }catch (Exception e){
                log.info("组装数据失败，批次号:{}失败的uuid:{}，错误:{}",pch,item,e);
            }
        });
        erpPushCustoms.setData(reqData);
        log.info("组装完成，本次发送数据条数:{}",reqData.size());

        List<String> reqUuids = reqData.stream().map(e->e.getCustomsCode()).collect(Collectors.toList());
        if(reqUuids.size()>0){
            String reqStr = JSON.toJSONString(erpPushCustoms);
            pushPoolAndUpdatePoolLog(reqStr,reqUuids,"HGJKSTS", isRecordFlag);
        }
    }

    /**
    * @Description 组装缴款书数据
    * @param uuid
    * @Return com.dxhy.core.model.erpPool.ErpCustoms
    * @Author wangruwei
    * @Date 2024/10/30 14:00
    **/
    private ErpCustoms buildErpCustoms(String uuid) {
        ErpCustoms erpCustoms = null;

        TdxCustomsRecordEntity dbCustoms = tdxCustomsRecordDao.selectOne(new LambdaQueryWrapper<TdxCustomsRecordEntity>().eq(TdxCustomsRecordEntity::getCustomsCode, uuid));
        if(ObjectUtils.isNotEmpty(dbCustoms)){
            erpCustoms = new ErpCustoms();
            erpCustoms.setGfName(dbCustoms.getGfName());
            erpCustoms.setGfTaxNo(dbCustoms.getGfTaxNo());
            erpCustoms.setCustomsCode(dbCustoms.getCustomsCode());
            erpCustoms.setFillInDate(ObjectUtils.isNotEmpty(dbCustoms.getFillInDate())?DateUtils.dateToStr(dbCustoms.getFillInDate(), "yyyy-MM-dd HH:mm:ss"):"");
            erpCustoms.setTaxAmount(dbCustoms.getTaxAmount());
            //erpCustoms.setByzd1();
            //erpCustoms.setByzd2();
            //erpCustoms.setByzd3();
            //erpCustoms.setByzd4();
            //状态
            ErpCustomsState hgjksState = new ErpCustomsState();
            hgjksState.setGlzt(dbCustoms.getGlzt());

            if("0".equals(dbCustoms.getExportMark())){
                String rzhYesorno = dbCustoms.getRzhYesorno();
                String rzlx = dbCustoms.getRzlx();
                if("0".equals(rzhYesorno)){
                    hgjksState.setRzzt("0");
                }else if("1".equals(rzhYesorno)){
                    //认证抵扣
                    if("1".equals(rzlx)){
                        hgjksState.setRzzt("1");
                    }
                    if("2".equals(rzlx)){
                        hgjksState.setRzzt("3");
                    }
                    if("3".equals(rzlx)){
                        hgjksState.setRzzt("4");
                    }
                }else if("2".equals(rzhYesorno)){
                    hgjksState.setRzzt("2");
                }else{
                    log.info("发票用途不赋值，没有对应条件。uuid:{},rzhyesorno:{},rzlx:{}",uuid,rzhYesorno,rzlx);
                }
                hgjksState.setRzssq(dbCustoms.getRzhBelongDate());
            }else if("1".equals(dbCustoms.getExportMark())){
                TDxExportCustoms tDxExportCustoms = tDxExportCustomsDao.selectOne(new LambdaQueryWrapper<TDxExportCustoms>().eq(TDxExportCustoms::getCustomsCode, dbCustoms.getCustomsCode()));
                String rzhYesorno = tDxExportCustoms.getRzhYesorno();
                String rzlx = tDxExportCustoms.getRzlx();
                if("0".equals(rzhYesorno)){
                    hgjksState.setRzzt("0");
                }else if("1".equals(rzhYesorno)){
                    //认证抵扣
                    if("1".equals(rzlx)){
                        hgjksState.setRzzt("1");
                    }
                    if("2".equals(rzlx)){
                        hgjksState.setRzzt("3");
                    }
                    if("3".equals(rzlx)){
                        hgjksState.setRzzt("4");
                    }
                }else if("2".equals(rzhYesorno)){
                    hgjksState.setRzzt("2");
                }else{
                    log.info("发票用途不赋值，没有对应条件。uuid:{},rzhyesorno:{},rzlx:{}",uuid,rzhYesorno,rzlx);
                }
                hgjksState.setRzssq(tDxExportCustoms.getRzhBelongDate());
                if(ObjectUtils.isNotEmpty(tDxExportCustoms)){
                    erpCustoms.setCkznxzmbh(tDxExportCustoms.getExportNo());
                }
            }

            hgjksState.setDkTaxAmount(dbCustoms.getYxTaxAmount());
            hgjksState.setBdkyy(dbCustoms.getBdkYy());
            hgjksState.setBdkMessage(dbCustoms.getBdkMessage());
            hgjksState.setSfchsd(dbCustoms.getLqSfchsd());

            TdxLqRzCustom tdxLqRzCustom = tdxLqRzCustomDao.selectOne(new LambdaQueryWrapper<TdxLqRzCustom>().eq(TdxLqRzCustom::getCustomsCode, uuid));
            if(ObjectUtils.isNotEmpty(tdxLqRzCustom)){
                if("01".equals(tdxLqRzCustom.getJksrzlx())||"06".equals(tdxLqRzCustom.getJksrzlx())){
                    //不设置入账类型
                }else{
                    hgjksState.setInAccountType(tdxLqRzCustom.getJksrzlx());
                }
                hgjksState.setInAccountSsq(tdxLqRzCustom.getJksrzsq());
                //入账状态
                String fprzauthStatus = tdxLqRzCustom.getJksrzAuthStatus();
                //入账申请状态：1申请入账，2发送入账请求，3入账失败，4入账成功，5申请撤销，6发送撤销申请，7撤销失败，8撤销成功
                //4 5 6 7 属于入账成功
                //1 2 3 8 属于入账失败
                if("4".equals(fprzauthStatus)||"5".equals(fprzauthStatus)||"6".equals(fprzauthStatus)||"7".equals(fprzauthStatus)){
                    hgjksState.setInAccountStatus("1");
                }else{
                    hgjksState.setInAccountStatus("0");
                }
            }
            hgjksState.setXfsyt(dbCustoms.getLqXfsyt());
            erpCustoms.setHgjksState(hgjksState);

            //明细
            List<TdxCustomsDetailEntity> tdxCustomsDetailEntities = tdxCustomsDetailDao.selectList(new LambdaQueryWrapper<TdxCustomsDetailEntity>().eq(TdxCustomsDetailEntity::getCustomsCode, uuid));
            if(!CollectionUtils.isEmpty(tdxCustomsDetailEntities)){
                List<ErpCustomsItems> jksmx = new LinkedList<>();
                for (int i = 0; i < tdxCustomsDetailEntities.size(); i++) {
                    TdxCustomsDetailEntity tdxCustomsDetailEntity = tdxCustomsDetailEntities.get(i);
                    ErpCustomsItems erpItem = new ErpCustomsItems();
                    erpItem.setTaxno(tdxCustomsDetailEntity.getTaxno());
                    erpItem.setGoodsName(tdxCustomsDetailEntity.getGoodsName());
                    erpItem.setNum(tdxCustomsDetailEntity.getNum());
                    erpItem.setDetailAmount(tdxCustomsDetailEntity.getDetailAmount());
                    erpItem.setUnit(tdxCustomsDetailEntity.getUnit());
                    erpItem.setTaxRate(tdxCustomsDetailEntity.getTaxRate());
                    erpItem.setTaxAmount(tdxCustomsDetailEntity.getTaxAmount());
                    jksmx.add(erpItem);
                }
                erpCustoms.setJksmx(jksmx);
            }
        }
        return erpCustoms;
    }

    /**
    * @Description 增值税代扣代缴完税凭证-状态-推送
    * @param sjlx
    * @param uuids
    * @param isRecordFlag
     * @Return void
    * @Author wangruwei
    * @Date 2024/10/30 11:44
    **/
    private void poolPushDkdjZt(String sjlx, List<String> uuids, boolean isRecordFlag) {
        //定义请求数据体
        ErpPushInvoiceState erpPushInvoiceState = new ErpPushInvoiceState();
        erpPushInvoiceState.setPjlx(sjlx);
        erpPushInvoiceState.setSjly(ConfigureConstant.POOL_SJLY);
        log.info("开始组装数据");
        List<ErpInvoiceState> invoiceStates = new LinkedList();
        uuids.stream().forEach(item->{
            try {
                //组装方法
                ErpInvoiceState erpInvoiceState = buildErpDkdjState(item);
                if(ObjectUtils.isNotEmpty(erpInvoiceState)){
                    invoiceStates.add(erpInvoiceState);
                }
            }catch (Exception e){
                log.info("组装数据失败，失败的uuid:{},错误{}",item,e);
            }
        });
        erpPushInvoiceState.setInvoiceState(invoiceStates);
        log.info("组装完成，本次发送数据条数:{}",invoiceStates.size());

        List<String> reqUuids = invoiceStates.stream().map(e->e.getInvoiceNo()).collect(Collectors.toList());
        if(reqUuids.size()>0){
            String reqStr = JSON.toJSONString(erpPushInvoiceState);
            pushPoolAndUpdatePoolLog(reqStr,reqUuids,"PJZTTS", isRecordFlag);
        }
    }
    /**
    * @Description 获取代扣代缴状态
    * @param uuid
    * @Return com.dxhy.core.model.erpPool.ErpInvoiceState
    * @Author wangruwei
    * @Date 2024/10/30 11:45
    **/
    private ErpInvoiceState buildErpDkdjState(String uuid) {
        ErpInvoiceState erpInvoiceState = null;

        
        TDxZzsDkdjWspzEntity dbDkdj = zzsDkdjWspzDao.selectOne(new LambdaQueryWrapper<TDxZzsDkdjWspzEntity>().eq(TDxZzsDkdjWspzEntity::getDkdjwspzh, uuid));
        if(ObjectUtils.isNotEmpty(dbDkdj)){
            erpInvoiceState = new ErpInvoiceState();
            //erpInvoiceState.setInvoiceCode(dbDkdj.getInvoiceCode());
            erpInvoiceState.setInvoiceNo(dbDkdj.getDkdjwspzh());
            //erpInvoiceState.setInvoiceStatus(dbDkdj.getInvoiceStatus());
            //erpInvoiceState.setGlzt(dbDkdj.getGlzt());
            String rzhYesorno = dbDkdj.getRzzt();
            String rzlx = dbDkdj.getRzlx();
            if("0".equals(rzhYesorno)){
                erpInvoiceState.setFpyt("0");
            }else if("1".equals(rzhYesorno)){
                //认证抵扣
                if("01".equals(rzlx)){
                    erpInvoiceState.setFpyt("1");
                }
            }else if("2".equals(rzhYesorno)){
                erpInvoiceState.setFpyt("2");
            }else{
                log.info("发票用途不赋值，没有对应条件。uuid:{},rzhyesorno:{},rzlx:{}",uuid,rzhYesorno,rzlx);
            }
            erpInvoiceState.setRzssq(dbDkdj.getRzssq());
            erpInvoiceState.setDkTaxAmount(ObjectUtils.isEmpty(dbDkdj.getYxse())?"":dbDkdj.getYxse().toString());
            erpInvoiceState.setBdkyy(dbDkdj.getBdkyy());
            erpInvoiceState.setBdkMessage(dbDkdj.getBdklx());
            //erpInvoiceState.setHzsdbs(dbDkdj.gethz);
            //erpInvoiceState.setInAccountStatus(dbDkdj.getLqRzzt());
            //查入账表
            //TdxLqRzInvoice tdxLqRzInvoice = tDxLqRzInvoiceDao.selectOne(new LambdaQueryWrapper<TdxLqRzInvoice>().eq(TdxLqRzInvoice::getUuid, uuid));
            //if(ObjectUtils.isNotEmpty(tdxLqRzInvoice)){
            //    erpInvoiceState.setInAccountType(tdxLqRzInvoice.getFprzlx());
            //    erpInvoiceState.setInAccountSsq(tdxLqRzInvoice.getFprzsq());
            //}
            //erpInvoiceState.setCpyycbs(dbDkdj.getLqCpyycbs());
            //erpInvoiceState.setXfsyt(dbDkdj.getLqXfsyt());
            //erpInvoiceState.setJdcycbs(dbDkdj.getLqJdcycbs());
            //erpInvoiceState.setCwrzzt(dbDkdj.getInAccountStatus());
            //erpInvoiceState.setCwrzssq(ObjectUtils.isNotEmpty(dbDkdj.getInAccountDate())? DateUtils.dateToStr(dbDkdj.getInAccountDate(), "yyyyMM") :"");
        }

        return erpInvoiceState;
    }

    /**
    * @Description 增值税代扣代缴完税凭证-数据-推送
    * @param uuids
    * @param isRecordFlag
     * @Return void
    * @Author wangruwei
    * @Date 2024/10/30 11:12
    **/
    private void poolPushDkdj(List<String> uuids, boolean isRecordFlag) {
        //定义请求数据体
        ErpPushDkdj erpPushDkdj = new ErpPushDkdj();
        String pch = UUID.randomUUID().toString().replace("-", "");
        erpPushDkdj.setPch(pch);

        erpPushDkdj.setSjly(ConfigureConstant.POOL_SJLY);
        List<ErpReqDkdj> reqData = new LinkedList<>();

        log.info("开始组装代扣代缴数据，当前pch:{}",pch);
        uuids.stream().forEach(item->{
            try {
                //组装方法
                ErpReqDkdj erpReqDkdj = buildErpReqDkdj(item);
                if(ObjectUtils.isNotEmpty(erpReqDkdj)){
                    reqData.add(erpReqDkdj);
                }
            }catch (Exception e){
                log.info("组装数据失败，批次号:{}失败的uuid:{}，错误:{}",pch,item,e);
            }
        });
        erpPushDkdj.setData(reqData);
        log.info("组装完成，本次发送数据条数:{}",reqData.size());

        List<String> reqUuids = reqData.stream().map(e->e.getDkdjwspzh()).collect(Collectors.toList());
        if(reqUuids.size()>0){
            String reqStr = JSON.toJSONString(erpPushDkdj);
            pushPoolAndUpdatePoolLog(reqStr,reqUuids,"ZZSDKDJWSPZTS", isRecordFlag);
        }

    }
    /**
     * @Description 组装请求的发票数据
     * @param uuid
     * @Return com.dxhy.core.model.erpPool.ErpReqInvoice
     * @Author wangruwei
     * @Date 2024/10/30 10:07
     **/
    private ErpReqDkdj buildErpReqDkdj(String uuid) {
        ErpReqDkdj erpReqInvoice = null;

        
        TDxZzsDkdjWspzEntity dbDkdj = zzsDkdjWspzDao.selectOne(new LambdaQueryWrapper<TDxZzsDkdjWspzEntity>().eq(TDxZzsDkdjWspzEntity::getDkdjwspzh, uuid));
        if(ObjectUtils.isNotEmpty(dbDkdj)){
            erpReqInvoice = new ErpReqDkdj();
            erpReqInvoice.setDkdjwspzh(dbDkdj.getDkdjwspzh());
            erpReqInvoice.setTfrq(ObjectUtils.isEmpty(dbDkdj.getTfrq())?"":DateUtils.dateToStr(dbDkdj.getTfrq(), "yyyy-MM-dd HH:mm:ss"));
            erpReqInvoice.setKjywrsbh(dbDkdj.getKjywrsbh());
            erpReqInvoice.setKjywrmc(dbDkdj.getKjywrmc());
            erpReqInvoice.setBkjnsrsbh(dbDkdj.getBkjnsrsbh());
            erpReqInvoice.setBkjnsrmc(dbDkdj.getBkjnsrmc());
            erpReqInvoice.setJsje(ObjectUtils.isEmpty(dbDkdj.getJsje())?"":dbDkdj.getJsje().toString());
            erpReqInvoice.setSjje(ObjectUtils.isEmpty(dbDkdj.getSjje())?"":dbDkdj.getSjje().toString());
            //erpReqInvoice.setByzd1();
            //erpReqInvoice.setByzd2();
            //erpReqInvoice.setByzd3();
            //erpReqInvoice.setByzd4();
            ErpZzsdkdjwspzState zzsdkdjwspzState = new ErpZzsdkdjwspzState();

            String rzhYesorno = dbDkdj.getRzzt();
            String rzlx = dbDkdj.getRzlx();
            if("0".equals(rzhYesorno)){
                zzsdkdjwspzState.setRzzt("0");
            }else if("1".equals(rzhYesorno)){
                //认证抵扣
                if("01".equals(rzlx)){
                    zzsdkdjwspzState.setRzzt("1");
                }
            }else if("2".equals(rzhYesorno)){
                zzsdkdjwspzState.setRzzt("2");
            }else{
                log.info("发票用途不赋值，没有对应条件。uuid:{},rzhyesorno:{},rzlx:{}",uuid,rzhYesorno,rzlx);
            }
            zzsdkdjwspzState.setRzssq(dbDkdj.getRzssq());
            zzsdkdjwspzState.setDkTaxAmount(ObjectUtils.isEmpty(dbDkdj.getYxse())?"":dbDkdj.getYxse().toString());
            zzsdkdjwspzState.setBdkyy(dbDkdj.getBdkyy());
            zzsdkdjwspzState.setBdkMessage(dbDkdj.getBdkyy());
            //zzsdkdjwspzState.setHzsdbs(dbDkdj.get);
            //zzsdkdjwspzState.setInAccountStatus(dbDkdj.get);
            //zzsdkdjwspzState.setInAccountType(dbDkdj.get);
            //zzsdkdjwspzState.setInAccountSsq(dbDkdj.get);

            erpReqInvoice.setZzsdkdjwspzState(zzsdkdjwspzState);
        }
        return erpReqInvoice;
    }

    /**
    * @Description 增值税发票-状态-推送
    * @param sjlx  票据类型：1.进项发票，2.缴款书，3.代扣代缴完税凭
     * @param uuids
     * @param isRecordFlag
     * @Return void
    * @Author wangruwei
    * @Date 2024/10/30 10:03
    **/
    private void poolPushPjzt(String sjlx, List<String> uuids, boolean isRecordFlag) {
        //定义请求数据体
        ErpPushInvoiceState erpPushInvoiceState = new ErpPushInvoiceState();
        erpPushInvoiceState.setPjlx(sjlx);
        erpPushInvoiceState.setSjly(ConfigureConstant.POOL_SJLY);
        log.info("开始组装发票状态数据");
        List<ErpInvoiceState> invoiceStates = new LinkedList();
        uuids.stream().forEach(item->{
            try {
                //组装方法
                ErpInvoiceState erpInvoiceState = buildErpInvoiceState(item);
                if(ObjectUtils.isNotEmpty(erpInvoiceState)){
                    invoiceStates.add(erpInvoiceState);
                }
            }catch (Exception e){
                log.info("组装数据失败，失败的uuid:{},错误{}",item,e);
            }
        });
        erpPushInvoiceState.setInvoiceState(invoiceStates);
        log.info("组装完成，本次发送数据条数:{}",invoiceStates.size());

        List<String> reqUuids = invoiceStates.stream().map(e->e.getInvoiceCode()+e.getInvoiceNo()).collect(Collectors.toList());
        if(reqUuids.size()>0){
            String reqStr = JSON.toJSONString(erpPushInvoiceState);
            pushPoolAndUpdatePoolLog(reqStr,reqUuids,"PJZTTS", isRecordFlag);
        }
    }

    /**
    * @Description 组装请求的状态数据
    * @param uuid
    * @Return com.dxhy.core.model.erpPool.ErpInvoiceState
    * @Author wangruwei
    * @Date 2024/10/30 10:07
    **/
    private ErpInvoiceState buildErpInvoiceState(String uuid) {
        ErpInvoiceState erpInvoiceState = null;

        
        TdxRecordInvoiceEntity dbInvoice = tdxRecordInvoiceDao.selectOne(new LambdaQueryWrapper<TdxRecordInvoiceEntity>().eq(TdxRecordInvoiceEntity::getUuid, uuid));
        if(ObjectUtils.isNotEmpty(dbInvoice)){
            //
            erpInvoiceState = new ErpInvoiceState();
            erpInvoiceState.setInvoiceCode(dbInvoice.getInvoiceCode());
            erpInvoiceState.setInvoiceNo(dbInvoice.getInvoiceNo());
            erpInvoiceState.setInvoiceStatus(dbInvoice.getInvoiceStatus());
            erpInvoiceState.setGlzt(dbInvoice.getGlzt());

            if("0".equals(dbInvoice.getExportMark())){
                //是否认证 0-未认证 1-已认证抵扣 2-已认证不抵扣
                String rzhYesorno = dbInvoice.getRzhYesorno();
                //认证类型(1-抵扣 2-退税 3-代办退税 4-不抵扣 5-撤销抵扣 6-撤销不抵扣）
                String rzlx = dbInvoice.getRzlx();
                if("0".equals(rzhYesorno)){
                    erpInvoiceState.setFpyt("0");
                }else if("1".equals(rzhYesorno)){
                    //认证抵扣
                    if("1".equals(rzlx)){
                        erpInvoiceState.setFpyt("1");
                    }
                    if("2".equals(rzlx)){
                        erpInvoiceState.setFpyt("3");
                    }
                    if("3".equals(rzlx)){
                        erpInvoiceState.setFpyt("4");
                    }
                }else if("2".equals(rzhYesorno)){
                    erpInvoiceState.setFpyt("2");
                }else{
                    log.info("发票用途不赋值，没有对应条件。uuid:{},rzhyesorno:{},rzlx:{}",uuid,rzhYesorno,rzlx);
                }
                erpInvoiceState.setRzssq(dbInvoice.getRzhBelongDate());
            }else if("1".equals(dbInvoice.getExportMark())){
                //出口转内销发票
                TDxExportInvoice tDxExportInvoice = tDxExportInvoiceDao.selectOne(new LambdaQueryWrapper<TDxExportInvoice>().eq(TDxExportInvoice::getUuid, dbInvoice.getUuid()));

                //是否认证 0-未认证 1-已认证抵扣 2-已认证不抵扣
                String rzhYesorno = tDxExportInvoice.getRzhYesorno();
                //认证类型(1-抵扣 2-退税 3-代办退税 4-不抵扣 5-撤销抵扣 6-撤销不抵扣）
                String rzlx = tDxExportInvoice.getRzlx();
                if("0".equals(rzhYesorno)){
                    erpInvoiceState.setFpyt("0");
                }else if("1".equals(rzhYesorno)){
                    //认证抵扣
                    if("1".equals(rzlx)){
                        erpInvoiceState.setFpyt("1");
                    }
                    if("2".equals(rzlx)){
                        erpInvoiceState.setFpyt("3");
                    }
                    if("3".equals(rzlx)){
                        erpInvoiceState.setFpyt("4");
                    }
                }else if("2".equals(rzhYesorno)){
                    erpInvoiceState.setFpyt("2");
                }else{
                    log.info("发票用途不赋值，没有对应条件。uuid:{},rzhyesorno:{},rzlx:{}",uuid,rzhYesorno,rzlx);
                }
                erpInvoiceState.setRzssq(tDxExportInvoice.getRzhBelongDate());
            }

            erpInvoiceState.setDkTaxAmount(ObjectUtils.isEmpty(dbInvoice.getDkTaxAmount())?"":dbInvoice.getDkTaxAmount().toString());
            erpInvoiceState.setBdkyy(dbInvoice.getBdkYy());
            erpInvoiceState.setBdkMessage(dbInvoice.getBdkMessage());
            erpInvoiceState.setHzsdbs(dbInvoice.getLqHzsdbs());
            //查入账表
            TdxLqRzInvoice tdxLqRzInvoice = tDxLqRzInvoiceDao.selectOne(new LambdaQueryWrapper<TdxLqRzInvoice>().eq(TdxLqRzInvoice::getUuid, uuid));
            if(ObjectUtils.isNotEmpty(tdxLqRzInvoice)){
                if("01".equals(tdxLqRzInvoice.getFprzlx())||"06".equals(tdxLqRzInvoice.getFprzlx())){
                    //不设置入账类型
                }else{
                    erpInvoiceState.setInAccountType(tdxLqRzInvoice.getFprzlx());
                }
                erpInvoiceState.setInAccountSsq(tdxLqRzInvoice.getFprzsq());
                //入账状态
                String fprzauthStatus = tdxLqRzInvoice.getFprzAuthStatus();
                //入账申请状态：1申请入账，2发送入账请求，3入账失败，4入账成功，5申请撤销，6发送撤销申请，7撤销失败，8撤销成功
                //4 5 6 7 属于入账成功
                //1 2 3 8 属于入账失败
                if("4".equals(fprzauthStatus)||"5".equals(fprzauthStatus)||"6".equals(fprzauthStatus)||"7".equals(fprzauthStatus)){
                    erpInvoiceState.setInAccountStatus("1");
                }else{
                    erpInvoiceState.setInAccountStatus("0");
                }
            }
            erpInvoiceState.setCpyycbs(dbInvoice.getLqCpyycbs());
            erpInvoiceState.setXfsyt(dbInvoice.getLqXfsyt());
            erpInvoiceState.setJdcycbs(dbInvoice.getLqJdcycbs());
            erpInvoiceState.setCwrzzt(dbInvoice.getInAccountStatus());
            erpInvoiceState.setCwrzssq(ObjectUtils.isNotEmpty(dbInvoice.getInAccountDate())? DateUtils.dateToStr(dbInvoice.getInAccountDate(), "yyyyMM") :"");

        }
        return erpInvoiceState;
    }

    /**
    * @Description 增值税发票推送接口
    * @param uuids
    * @param isRecordFlag
     * @Return void
    * @Author wangruwei
    * @Date 2024/10/29 11:19
    **/
    private void poolPushInvoice(List<String> uuids, boolean isRecordFlag) {
        //定义请求数据体
        ErpPushInvoice erpPushInvoice = new ErpPushInvoice();
        String pch = UUID.randomUUID().toString().replace("-", "");
        erpPushInvoice.setPch(pch);

        erpPushInvoice.setSjly(ConfigureConstant.POOL_SJLY);
        List<ErpReqInvoice> reqData = new LinkedList<>();

        log.info("开始组装发票数据，当前pch:{}",pch);
        uuids.stream().forEach(item->{
            try {
                //组装方法
                ErpReqInvoice erpReqInvoice = buildErpReqInvoice(item);
                if(ObjectUtils.isNotEmpty(erpReqInvoice)){
                    reqData.add(erpReqInvoice);
                }
            }catch (Exception e){
                log.info("组装数据失败，批次号:{}失败的uuid:{},错误:{}",pch,item,e);
            }
        });
        erpPushInvoice.setData(reqData);
        log.info("组装完成，本次发送数据条数:{}",reqData.size());

        List<String> reqUuids = reqData.stream().map(e->e.getInvoiceCode()+e.getInvoiceNo()).collect(Collectors.toList());
        if(reqUuids.size()>0){
            String reqStr = JSON.toJSONString(erpPushInvoice);
            pushPoolAndUpdatePoolLog(reqStr,reqUuids,"ZZSFPTS", isRecordFlag);
        }

    }

    /**
    * @Description 推送票池，并更新对应pool_log数据
    * @param uuids
    * @param isRecordFlag 是否全量标志，true，推送底账pool_push未0的，false，推送pool_log表的增量数据
     * @Return void
    * @Author wangruwei
    * @Date 2024/10/30 10:00
    **/
    private void pushPoolAndUpdatePoolLog(String reqStr, List<String> uuids, String interfaceName, boolean isRecordFlag) {

        log.info("当前接口:{}",interfaceName);
        log.info("请求参数:{}",reqStr);
        String result = HttpUtils.doPost( poolPushUrl+interfaceName, reqStr);
        log.info("请求返回:{}",result);
        ErpReturn erpReturn = JSON.parseObject(result, ErpReturn.class);
        if("0000".equals(erpReturn.getCode())){
            log.info("推送成功");
            if(isRecordFlag){
                log.info("推送全量历史数据成功，更新对应底账表状态");
                //根据接口名称判断更新对应表
                if("ZZSFPTS".equals(interfaceName)){
                    tdxRecordInvoiceDao.update(null, new LambdaUpdateWrapper<TdxRecordInvoiceEntity>()
                            .set(TdxRecordInvoiceEntity::getPushPool, "1")
                            .in(TdxRecordInvoiceEntity::getUuid, uuids)
                    );
                }
                if("HGJKSTS".equals(interfaceName)){
                    tdxCustomsRecordDao.update(null, new LambdaUpdateWrapper<TdxCustomsRecordEntity>()
                            .set(TdxCustomsRecordEntity::getPushPool, "1")
                            .in(TdxCustomsRecordEntity::getCustomsCode, uuids)
                    );
                }
                if("ZZSDKDJWSPZTS".equals(interfaceName)){
                    zzsDkdjWspzDao.update(null, new LambdaUpdateWrapper<TDxZzsDkdjWspzEntity>()
                            .set(TDxZzsDkdjWspzEntity::getPushPool, "1")
                            .in(TDxZzsDkdjWspzEntity::getDkdjwspzh, uuids)
                    );
                }
                //加计扣除要取uuid和jjssq来更新
                if("NCPJJKCFPMXTS".equals(interfaceName)){
                    uuids.stream().forEach(e->{
                        String[] split = e.split("@");
                        String uuid = split[0];
                        String jjssq = split[1];
                        ncpJjkcRecordInvoiceDao.update(null, new LambdaUpdateWrapper<TdxInvoiceNcpJjkcEntity>()
                                .set(TdxInvoiceNcpJjkcEntity::getPushPool, "1")
                                .eq(TdxInvoiceNcpJjkcEntity::getUuid, uuid)
                                .eq(TdxInvoiceNcpJjkcEntity::getJjssq, jjssq)
                        );
                    });

                }
                if("NCPJJKCJKSMXTS".equals(interfaceName)){
                    uuids.stream().forEach(e->{
                        String[] split = e.split("@");
                        String uuid = split[0];
                        String jjssq = split[1];
                        customsNcpJjkcCustomsDao.update(null, new LambdaUpdateWrapper<TdxCustomsNcpJjkcEntity>()
                                .set(TdxCustomsNcpJjkcEntity::getPushPool, "1")
                                .eq(TdxCustomsNcpJjkcEntity::getCustomsCode, uuid)
                                .eq(TdxCustomsNcpJjkcEntity::getJjssq, jjssq)
                        );
                    });
                }
            }else{
                log.info("推送增量里是数据成功，更新pool_log表状态");
                LambdaUpdateWrapper<TdxPoolLogEntity> updateWrapper = new LambdaUpdateWrapper();
                updateWrapper.set(TdxPoolLogEntity::getClzt, "1");
                updateWrapper.set(TdxPoolLogEntity::getClsj, new Date());
                updateWrapper.in(TdxPoolLogEntity::getUuid, uuids);
                tdxPoolLogDao.update(null, updateWrapper);
            }
        }else {
            log.info("推送失败，本地数据不做处理");
        }
    }

    /**
    * @Description 组装请求的发票数据
    * @Return com.dxhy.core.model.erpPool.ErpReqInvoice
    * @Author wangruwei
    * @Date 2024/10/30 10:07
    **/
    private ErpReqInvoice buildErpReqInvoice(String uuid) {
        ErpReqInvoice erpReqInvoice = null;

        
        TdxRecordInvoiceEntity dbInvoice = tdxRecordInvoiceDao.selectOne(new LambdaQueryWrapper<TdxRecordInvoiceEntity>().eq(TdxRecordInvoiceEntity::getUuid, uuid));
        if(ObjectUtils.isNotEmpty(dbInvoice)){
            //
            erpReqInvoice = new ErpReqInvoice();
            erpReqInvoice.setInvoiceType(dbInvoice.getInvoiceType());
            erpReqInvoice.setInvoiceCode(dbInvoice.getInvoiceCode());
            erpReqInvoice.setInvoiceNo(dbInvoice.getInvoiceNo());
            erpReqInvoice.setEleInvoiceNo(dbInvoice.getEleInvoiceNo());
            erpReqInvoice.setInvoiceDate(DateUtils.dateToStr(dbInvoice.getInvoiceDate(),"yyyy-MM-dd HH:mm:ss"));
            erpReqInvoice.setGfTaxNo(dbInvoice.getGfTaxNo());
            erpReqInvoice.setGfName(dbInvoice.getGfName());
            erpReqInvoice.setGfAddress(dbInvoice.getGfAddressAndPhone());
            //erpReqInvoice.setGfPhone();
            erpReqInvoice.setGfBank(dbInvoice.getGfBankAndNo());
            //erpReqInvoice.setGfAcount();
            erpReqInvoice.setXfTaxNo(dbInvoice.getXfTaxNo());
            erpReqInvoice.setXfName(dbInvoice.getXfName());
            erpReqInvoice.setXfAddress(dbInvoice.getXfAddressAndPhone());
            //erpReqInvoice.setXfPhone();
            erpReqInvoice.setXfBank(dbInvoice.getXfBankAndNo());
            //erpReqInvoice.setXfAcount();
            erpReqInvoice.setInvoiceAmount(ObjectUtils.isEmpty(dbInvoice.getInvoiceAmount())?"":dbInvoice.getInvoiceAmount().toString());
            erpReqInvoice.setTaxAmount(ObjectUtils.isEmpty(dbInvoice.getTaxAmount())?"":dbInvoice.getTaxAmount().toString());
            erpReqInvoice.setTotalAmount(ObjectUtils.isEmpty(dbInvoice.getTotalAmount())?"":dbInvoice.getTotalAmount().toString());
            erpReqInvoice.setRemark(dbInvoice.getRemark());
            erpReqInvoice.setCheckCode(dbInvoice.getCheckCode());
            erpReqInvoice.setMw(dbInvoice.getMw());
            erpReqInvoice.setJqbm(dbInvoice.getMachinecode());
            erpReqInvoice.setPrintor(dbInvoice.getPrintor());
            erpReqInvoice.setPayee(dbInvoice.getPayee());
            erpReqInvoice.setReviewer(dbInvoice.getReviewer());
            //erpReqInvoice.setSkm(dbInvoice.get);
            erpReqInvoice.setExportMark(dbInvoice.getExportMark());
            erpReqInvoice.setIsRed(dbInvoice.getIsRed());
            erpReqInvoice.setBlueCode(dbInvoice.getBlueCode());
            erpReqInvoice.setBlueNo(dbInvoice.getBlueNo());
            erpReqInvoice.setBlueEleNo(dbInvoice.getBlueEleNo());
            erpReqInvoice.setDkStatus(dbInvoice.getDkStatus());
            erpReqInvoice.setDkTaxno(dbInvoice.getDkTaxno());
            erpReqInvoice.setDkTaxname(dbInvoice.getDkTaxname());
            erpReqInvoice.setTspz(dbInvoice.getLqTspz());
            erpReqInvoice.setTdyslxDm(dbInvoice.getLqTdyslxDm());
            //erpReqInvoice.setCwpzh(dbInvoice.get);
            //erpReqInvoice.setByzd1(dbInvoice.get);
            //erpReqInvoice.setByzd2();
            //erpReqInvoice.setByzd3();
            //erpReqInvoice.setByzd4();
            //--------以下都是对象

            //发票状态
            ErpInvoiceState erpInvoiceState = new ErpInvoiceState();
            erpInvoiceState.setInvoiceStatus(dbInvoice.getInvoiceStatus());
            erpInvoiceState.setGlzt(dbInvoice.getGlzt());

            if("0".equals(dbInvoice.getExportMark())){
                //是否认证 0-未认证 1-已认证抵扣 2-已认证不抵扣
                String rzhYesorno = dbInvoice.getRzhYesorno();
                //认证类型(1-抵扣 2-退税 3-代办退税 4-不抵扣 5-撤销抵扣 6-撤销不抵扣）
                String rzlx = dbInvoice.getRzlx();
                if("0".equals(rzhYesorno)){
                    erpInvoiceState.setFpyt("0");
                }else if("1".equals(rzhYesorno)){
                    //认证抵扣
                    if("1".equals(rzlx)){
                        erpInvoiceState.setFpyt("1");
                    }
                    if("2".equals(rzlx)){
                        erpInvoiceState.setFpyt("3");
                    }
                    if("3".equals(rzlx)){
                        erpInvoiceState.setFpyt("4");
                    }
                }else if("2".equals(rzhYesorno)){
                    erpInvoiceState.setFpyt("2");
                }else{
                    log.info("发票用途不赋值，没有对应条件。uuid:{},rzhyesorno:{},rzlx:{}",uuid,rzhYesorno,rzlx);
                }
                erpInvoiceState.setRzssq(dbInvoice.getRzhBelongDate());
            }else if("1".equals(dbInvoice.getExportMark())){
                //出口转内销发票
                TDxExportInvoice tDxExportInvoice = tDxExportInvoiceDao.selectOne(new LambdaQueryWrapper<TDxExportInvoice>().eq(TDxExportInvoice::getUuid, dbInvoice.getUuid()));

                //是否认证 0-未认证 1-已认证抵扣 2-已认证不抵扣
                String rzhYesorno = tDxExportInvoice.getRzhYesorno();
                //认证类型(1-抵扣 2-退税 3-代办退税 4-不抵扣 5-撤销抵扣 6-撤销不抵扣）
                String rzlx = tDxExportInvoice.getRzlx();
                if("0".equals(rzhYesorno)){
                    erpInvoiceState.setFpyt("0");
                }else if("1".equals(rzhYesorno)){
                    //认证抵扣
                    if("1".equals(rzlx)){
                        erpInvoiceState.setFpyt("1");
                    }
                    if("2".equals(rzlx)){
                        erpInvoiceState.setFpyt("3");
                    }
                    if("3".equals(rzlx)){
                        erpInvoiceState.setFpyt("4");
                    }
                }else if("2".equals(rzhYesorno)){
                    erpInvoiceState.setFpyt("2");
                }else{
                    log.info("发票用途不赋值，没有对应条件。uuid:{},rzhyesorno:{},rzlx:{}",uuid,rzhYesorno,rzlx);
                }
                erpInvoiceState.setRzssq(tDxExportInvoice.getRzhBelongDate());

                if(ObjectUtils.isNotEmpty(tDxExportInvoice)){
                    erpReqInvoice.setCkznxzmbh(tDxExportInvoice.getExportNo());
                }
            }

            erpInvoiceState.setDkTaxAmount(ObjectUtils.isEmpty(dbInvoice.getDkTaxAmount())?"":dbInvoice.getDkTaxAmount().toString());
            erpInvoiceState.setBdkyy(dbInvoice.getBdkYy());
            erpInvoiceState.setBdkMessage(dbInvoice.getBdkMessage());
            erpInvoiceState.setHzsdbs(dbInvoice.getLqHzsdbs());
            //查入账表
            TdxLqRzInvoice tdxLqRzInvoice = tDxLqRzInvoiceDao.selectOne(new LambdaQueryWrapper<TdxLqRzInvoice>().eq(TdxLqRzInvoice::getUuid, uuid));
            if(ObjectUtils.isNotEmpty(tdxLqRzInvoice)){
                if("01".equals(tdxLqRzInvoice.getFprzlx())||"06".equals(tdxLqRzInvoice.getFprzlx())){
                    //不设置入账类型
                }else{
                    erpInvoiceState.setInAccountType(tdxLqRzInvoice.getFprzlx());
                }
                erpInvoiceState.setInAccountSsq(tdxLqRzInvoice.getFprzsq());
                //入账状态
                String fprzauthStatus = tdxLqRzInvoice.getFprzAuthStatus();
                //入账申请状态：1申请入账，2发送入账请求，3入账失败，4入账成功，5申请撤销，6发送撤销申请，7撤销失败，8撤销成功
                //4 5 6 7 属于入账成功
                //1 2 3 8 属于入账失败
                if("4".equals(fprzauthStatus)||"5".equals(fprzauthStatus)||"6".equals(fprzauthStatus)||"7".equals(fprzauthStatus)){
                    erpInvoiceState.setInAccountStatus("1");
                }else{
                    erpInvoiceState.setInAccountStatus("0");
                }
            }
            erpInvoiceState.setCpyycbs(dbInvoice.getLqCpyycbs());
            erpInvoiceState.setXfsyt(dbInvoice.getLqXfsyt());
            erpInvoiceState.setJdcycbs(dbInvoice.getLqJdcycbs());
            erpInvoiceState.setCwrzzt(dbInvoice.getInAccountStatus());
            erpInvoiceState.setCwrzssq(ObjectUtils.isNotEmpty(dbInvoice.getInAccountDate())? DateUtils.dateToStr(dbInvoice.getInAccountDate(), "yyyyMM") :"");
            erpReqInvoice.setInvoiceState(erpInvoiceState);

            //发票明细
            List<TdxRecordInvoiceDetailEntity> detailList = tDxRecordInvoiceDetailDao.selectList(new LambdaQueryWrapper<TdxRecordInvoiceDetailEntity>().eq(TdxRecordInvoiceDetailEntity::getUuid, uuid));
            List<ErpInvoiceItem> invoiceItemList = new LinkedList<>();
            for (int i = 0; i < detailList.size(); i++) {
                TdxRecordInvoiceDetailEntity detailEntity = detailList.get(i);
                ErpInvoiceItem erpInvoiceItem = new ErpInvoiceItem();
                erpInvoiceItem.setDetailNo(detailEntity.getDetailNo());
                erpInvoiceItem.setGoodsName(detailEntity.getGoodsName());
                erpInvoiceItem.setGoodsNum(detailEntity.getGoodsNum());
                erpInvoiceItem.setModel(detailEntity.getModel());
                erpInvoiceItem.setUnit(detailEntity.getUnit());
                erpInvoiceItem.setNum(detailEntity.getNum());
                erpInvoiceItem.setUnitPrice(detailEntity.getUnitPrice());
                erpInvoiceItem.setDetailAmount(detailEntity.getDetailAmount());
                erpInvoiceItem.setTaxRate(detailEntity.getTaxRate());
                erpInvoiceItem.setTaxAmount(detailEntity.getTaxAmount());
                erpInvoiceItem.setKce(detailEntity.getKce());
                erpInvoiceItem.setLslbs(detailEntity.getLslbs());
                erpInvoiceItem.setYhzcbs(detailEntity.getYhzcbs());
                erpInvoiceItem.setZzstsgl(detailEntity.getZzstsgl());
                invoiceItemList.add(erpInvoiceItem);
            }
            erpReqInvoice.setInvoiceItem(invoiceItemList);

            //附加要素
            List<TdxRecordInvoiceFjysxxEntity> fjysxx = tdxRecordInvoiceFjysxxDao.selectList(new LambdaQueryWrapper<TdxRecordInvoiceFjysxxEntity>().eq(TdxRecordInvoiceFjysxxEntity::getUuid, uuid));
            List<ErpFjys> fjysList = new LinkedList();
            for (int i = 0; i < fjysxx.size(); i++) {
                TdxRecordInvoiceFjysxxEntity fjysxxEntity = fjysxx.get(i);
                ErpFjys erpFjys = new ErpFjys();
                erpFjys.setSjlx(fjysxxEntity.getSjlx());
                erpFjys.setFjysKey(fjysxxEntity.getFjysKey());
                erpFjys.setFjysValue(fjysxxEntity.getFjysValue());
                fjysList.add(erpFjys);
            }
            erpReqInvoice.setFjysList(fjysList);

            //特定要素
            TdxRecordTspzKzxxEntity tspzKzxxEntity = tdxRecordTspzKzxxDao.selectOne(new LambdaQueryWrapper<TdxRecordTspzKzxxEntity>().eq(TdxRecordTspzKzxxEntity::getUuid, uuid));
            ErpTdys tdys = new ErpTdys();
            if(ObjectUtils.isNotEmpty(tspzKzxxEntity)){
                tdys.setZxx(tspzKzxxEntity.getKzZxx());
                tdys.setMxxx(tspzKzxxEntity.getKzMxxx());
            }
            erpReqInvoice.setTdys(tdys);

            //机动车
            if("03".equals(dbInvoice.getInvoiceType())||"183".equals(dbInvoice.getInvoiceType())||"187".equals(dbInvoice.getInvoiceType())||"383".equals(dbInvoice.getInvoiceType())){
                TdxVehicleSaleInvoiceEntity dbVehicle = tdxVehicleSaleInvoiceDao.selectOne(new LambdaQueryWrapper<TdxVehicleSaleInvoiceEntity>().eq(TdxVehicleSaleInvoiceEntity::getUuid, uuid));
                if(ObjectUtils.isNotEmpty(dbVehicle)){
                    ErpJdc jdc = new ErpJdc();
                    jdc.setBuyerIdNum(dbVehicle.getBuyerIdNum());
                    jdc.setVehicleType(dbVehicle.getVehicleType());
                    jdc.setFactoryModel(dbVehicle.getFactoryModel());
                    jdc.setProductPlace(dbVehicle.getProductPlace());
                    jdc.setCertificate(dbVehicle.getCertificate());
                    jdc.setCertificateImport(dbVehicle.getCertificateImport());
                    jdc.setInspectionNum(dbVehicle.getInspectionNum());
                    jdc.setEngineNo(dbVehicle.getEngineNo());
                    jdc.setVehicleNo(dbVehicle.getVehicleNo());
                    jdc.setTaxRate(dbVehicle.getTaxRate());
                    jdc.setTaxBureauName(dbVehicle.getTaxBureauName());
                    jdc.setTaxBureauCode(dbVehicle.getTaxBureauCode());
                    jdc.setTaxRecords(dbVehicle.getTaxRecords());
                    jdc.setLimitPeople(dbVehicle.getLimitPeople());
                    jdc.setTonnage(dbVehicle.getTonnage());
                    jdc.setBmbbbh(dbVehicle.getLqBmbbbh());
                    jdc.setSpbm(dbVehicle.getSpbm());
                    jdc.setZxbm(dbVehicle.getZxbm());
                    jdc.setYhzcbs(dbVehicle.getYhzcbs());
                    jdc.setZzstsgl(dbVehicle.getZzstsgl());
                    jdc.setLslbs(dbVehicle.getLslbs());
                    jdc.setSyslbs(dbVehicle.getSyslbs());
                    jdc.setSslkjly(dbVehicle.getSslkjly());
                    jdc.setZfr(dbVehicle.getLqZfr());
                    jdc.setJsrmc(dbVehicle.getLqJsrmc());
                    jdc.setJsrdm(dbVehicle.getLqJsrdm());
                    jdc.setJssj(ObjectUtils.isEmpty(dbVehicle.getLqJssj())?"":DateUtils.dateToStr(dbVehicle.getLqJssj(), "yyyy-MM-dd HH:mm:ss"));
                    jdc.setJsswjgdm(dbVehicle.getLqJsswjgdm());
                    jdc.setBsfs(dbVehicle.getLqBsfs());

                    erpReqInvoice.setJdc(jdc);
                }
            }

            //二手车
            if("15".equals(dbInvoice.getInvoiceType())||"188".equals(dbInvoice.getInvoiceType())||"184".equals(dbInvoice.getInvoiceType())) {
                TdxVehicleSaleInvoiceEntity dbVehicle = tdxVehicleSaleInvoiceDao.selectOne(new LambdaQueryWrapper<TdxVehicleSaleInvoiceEntity>().eq(TdxVehicleSaleInvoiceEntity::getUuid, uuid));
                if (ObjectUtils.isNotEmpty(dbVehicle)) {
                    ErpEsc esc = new ErpEsc();
                    esc.setBuyerIdNum(dbVehicle.getBuyerIdNum());
                    esc.setVehicleType(dbVehicle.getVehicleType());
                    esc.setFactoryModel(dbVehicle.getFactoryModel());
                    esc.setVehicleNo(dbVehicle.getVehicleNo());
                    esc.setPlateNo(dbVehicle.getPlateNo());
                    esc.setRegistrationNo(dbVehicle.getRegistrationNo());
                    esc.setAuctionUnit(dbVehicle.getAuctionUnit());
                    esc.setAuctionAddress(dbVehicle.getAuctionAddress());
                    esc.setAuctionTaxNo(dbVehicle.getAuctionTaxNo());
                    esc.setAuctionBank(dbVehicle.getAuctionBank());
                    esc.setAuctionPhone(dbVehicle.getAuctionPhone());
                    esc.setCarMarket(dbVehicle.getCarMarket());
                    esc.setCarMarketTaxNo(dbVehicle.getCarMarketTaxNo());
                    esc.setCarMarketAddress(dbVehicle.getCarMarketAddress());
                    esc.setCarMarketBank(dbVehicle.getCarMarketBank());
                    esc.setCarMarketPhone(dbVehicle.getCarMarketPhone());
                    esc.setGfPhone(dbVehicle.getGfPhone());
                    esc.setCarPrice(dbVehicle.getCarPrice());
                    esc.setBuyerUnit(dbVehicle.getBuyerUnit());
                    esc.setBuyerUnitCode(dbVehicle.getBuyerUnitCode());
                    esc.setBuyerUnitAddress(dbVehicle.getBuyerUnitAddress());
                    esc.setBuyerPhone(dbVehicle.getBuyerPhone());
                    esc.setSellerUnit(dbVehicle.getSellerUnit());
                    esc.setSellerUnitCode(dbVehicle.getSellerUnitCode());
                    esc.setSellerUnitAddress(dbVehicle.getSellerUnitAddress());
                    esc.setSellerPhone(dbVehicle.getSellerPhone());
                    esc.setSpbm(dbVehicle.getSpbm());
                    esc.setZxbm(dbVehicle.getZxbm());
                    esc.setYhzcbs(dbVehicle.getYhzcbs());
                    esc.setZzstsgl(dbVehicle.getZzstsgl());
                    esc.setLslbs(dbVehicle.getLslbs());
                    esc.setSyslbs(dbVehicle.getSyslbs());
                    esc.setVehicleAdminOffice(dbVehicle.getVehicleAdminOffice());

                    erpReqInvoice.setEsc(esc);
                }
            }

            if("161".equals(dbInvoice.getInvoiceType())){
                TdxTdysMhxcdEntity dbMhxcd = tdxTdysMhxcdCoreDao.selectOne(new LambdaQueryWrapper<TdxTdysMhxcdEntity>().eq(TdxTdysMhxcdEntity::getUuid, uuid));
                if(ObjectUtils.isNotEmpty(dbMhxcd)){
                    //航空行程单
                    ErpHkyskpdzxcd hkyskpdzxcd = new ErpHkyskpdzxcd();
                    hkyskpdzxcd.setGmfjbr(dbMhxcd.getGmfjbr());
                    hkyskpdzxcd.setPj(dbMhxcd.getTicketPrice());
                    hkyskpdzxcd.setRyfjf(dbMhxcd.getFuelSurcharge());
                    hkyskpdzxcd.setZzsse(dbMhxcd.getValueAddedTaxAmount());
                    hkyskpdzxcd.setZzssl(dbMhxcd.getVatRate());
                    hkyskpdzxcd.setMhfzjj(dbMhxcd.getAviationDevelopmentFund());
                    hkyskpdzxcd.setQtsf(dbMhxcd.getOtherTaxes());
                    hkyskpdzxcd.setJbrsfzjhm(dbMhxcd.getJbrsfzjhm());
                    hkyskpdzxcd.setJbrlxdh(dbMhxcd.getJbrlxdh());
                    hkyskpdzxcd.setKprsrrzdzxx(dbMhxcd.getKprsrrzdzxx());
                    hkyskpdzxcd.setSjkpdzxx(dbMhxcd.getSjkpdzxx());
                    hkyskpdzxcd.setHtbh(dbMhxcd.getHtbh());
                    hkyskpdzxcd.setNsywfssj(dbMhxcd.getNsywfssj());
                    hkyskpdzxcd.setJbrsfzjzlDm(dbMhxcd.getJbrsfzjzlDm());
                    hkyskpdzxcd.setSpsl(dbMhxcd.getSpsl());
                    hkyskpdzxcd.setGngjbz(dbMhxcd.getGngjbz());
                    hkyskpdzxcd.setGpdh(dbMhxcd.getGpdh());
                    hkyskpdzxcd.setXm(dbMhxcd.getXm());
                    hkyskpdzxcd.setZjhm(dbMhxcd.getZjhm());
                    hkyskpdzxcd.setQz(dbMhxcd.getQz());
                    hkyskpdzxcd.setDzkphm(dbMhxcd.getDzkphm());
                    hkyskpdzxcd.setYzm(dbMhxcd.getYzm());
                    hkyskpdzxcd.setTsxx(dbMhxcd.getTsxx());
                    hkyskpdzxcd.setBxf(dbMhxcd.getBxf());
                    hkyskpdzxcd.setXswddh(dbMhxcd.getXswddh());
                    hkyskpdzxcd.setTkdw(dbMhxcd.getTkdw());
                    hkyskpdzxcd.setKprq(dbMhxcd.getKprq());

                    List<TdxTdysMhxcdMxEntity> mhxcdMxList = tdxTdysMhxcdMxCoreDao.selectList(new LambdaQueryWrapper<TdxTdysMhxcdMxEntity>().eq(TdxTdysMhxcdMxEntity::getTdysId, uuid));
                    List<ErpXcdmx> xcdmx = new LinkedList<>();
                    for (int i = 0; i < mhxcdMxList.size(); i++) {
                        ErpXcdmx erpXcdmx = new ErpXcdmx();
                        TdxTdysMhxcdMxEntity dbMhxcdMxEntity = mhxcdMxList.get(i);
                        erpXcdmx.setSfz(dbMhxcdMxEntity.getSfz());
                        erpXcdmx.setMdz(dbMhxcdMxEntity.getMdz());
                        erpXcdmx.setHd(dbMhxcdMxEntity.getHd());
                        erpXcdmx.setCyr(dbMhxcdMxEntity.getCyr());
                        erpXcdmx.setHbh(dbMhxcdMxEntity.getHbh());
                        erpXcdmx.setZwdj(dbMhxcdMxEntity.getZwdj());
                        erpXcdmx.setCyrq(dbMhxcdMxEntity.getCyrq());
                        erpXcdmx.setQfsj(dbMhxcdMxEntity.getQfsj());
                        erpXcdmx.setKpjbkplb(dbMhxcdMxEntity.getKpjbkplb());
                        erpXcdmx.setKpsxrq(dbMhxcdMxEntity.getKpsxrq());
                        erpXcdmx.setYxjzrq(dbMhxcdMxEntity.getYxjzrq());
                        erpXcdmx.setMfxle(dbMhxcdMxEntity.getMfxle());
                        xcdmx.add(erpXcdmx);
                    }
                    hkyskpdzxcd.setXcdmx(xcdmx);

                    erpReqInvoice.setHkyskpdzxcd(hkyskpdzxcd);
                }
            }

            //铁路客票
            if("283".equals(dbInvoice.getInvoiceType())){
                TdxTdysTldzkpEntity dbTldzkp = tdxTdysTldzkpCoreDao.selectOne(new LambdaQueryWrapper<TdxTdysTldzkpEntity>().eq(TdxTdysTldzkpEntity::getUuid, uuid));
                if(ObjectUtils.isNotEmpty(dbTldzkp)){
                    ErpTldzkp tldzkp = new ErpTldzkp();
                    tldzkp.setGmfjbr(dbTldzkp.getGmfjbr());
                    tldzkp.setJbrsfzjhm(dbTldzkp.getJbrsfzjhm());
                    tldzkp.setJbrlxdh(dbTldzkp.getJbrlxdh());
                    tldzkp.setKprsrrzdzxx(dbTldzkp.getKprsrrzdzxx());
                    tldzkp.setSjkpdzxx(dbTldzkp.getSjkpdzxx());
                    tldzkp.setHtbh(dbTldzkp.getHtbh());
                    tldzkp.setNsywfssj(dbTldzkp.getNsywfssj());
                    tldzkp.setJbrsfzjzlDm(dbTldzkp.getJbrsfzjzlDm());
                    tldzkp.setSpsl(dbTldzkp.getSpsl());
                    tldzkp.setZjhm(dbTldzkp.getZjhm());
                    tldzkp.setYwlxmc(dbTldzkp.getYwlxmc());
                    tldzkp.setCfz(dbTldzkp.getCfz());
                    tldzkp.setCfzpy(dbTldzkp.getCfzpy());
                    tldzkp.setDdz(dbTldzkp.getDdz());
                    tldzkp.setDdzpy(dbTldzkp.getDdzpy());
                    tldzkp.setCccc(dbTldzkp.getCccc());
                    tldzkp.setRq(dbTldzkp.getRq());
                    tldzkp.setCfsjl(dbTldzkp.getCfsjl());
                    tldzkp.setTldzkppzmc(dbTldzkp.getTldzkppzmc());
                    tldzkp.setKttz(dbTldzkp.getKttz());
                    tldzkp.setXbl(dbTldzkp.getXbl());
                    tldzkp.setCx(dbTldzkp.getCx());
                    tldzkp.setXw(dbTldzkp.getXw());
                    tldzkp.setZfje(dbTldzkp.getZfje());
                    tldzkp.setYtje(dbTldzkp.getYtje());
                    tldzkp.setYppj(dbTldzkp.getYppj());
                    tldzkp.setTaxRate(dbTldzkp.getTaxRate());
                    tldzkp.setYpcfz(dbTldzkp.getYpcfz());
                    tldzkp.setYpddz(dbTldzkp.getYpddz());
                    tldzkp.setDzkph(dbTldzkp.getDzkph());
                    tldzkp.setXm(dbTldzkp.getXm());
                    tldzkp.setTlkpyhlx(dbTldzkp.getTlkpyhlx());
                    tldzkp.setYfphm(dbTldzkp.getYfphm());

                    erpReqInvoice.setTldzkp(tldzkp);
                }
            }

        }

        return erpReqInvoice;
    }

    public static void main(String[] args) {


    }
}
