package com.dxhy.jxpt.baseService.ncpInvoice.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.dxhy.api.model.config.UserInfo;
import com.dxhy.api.model.config.sys.SysEnterpriseConfigEntity;
import com.dxhy.api.model.ncp.ncpInvoice.TDxRecordInvoiceNcpVo;
import com.dxhy.api.model.ncp.ncpInvoice.TdxInvoiceNcpEntity;
import com.dxhy.api.model.ncp.ncpInvoice.TdxNcpSpbm;
import com.dxhy.api.model.ncp.ncpInvoice.ncpDkInvoice.NcpDkInvoiceLrReq;
import com.dxhy.api.model.ncp.ncpInvoice.ncpDkInvoice.NcpDkInvoiceReqExcel;
import com.dxhy.api.model.ncp.ncpInvoice.ncpXsInvoice.NcpXsQrInvoice;
import com.dxhy.api.model.ncp.ncpInvoice.ncpXsInvoice.NcpXsQrInvoiceReq;
import com.dxhy.api.model.ncp.ncpInvoice.ncpXsInvoice.NcpXsQrInvoiceReqExcel;
import com.dxhy.api.model.ncp.ncpInvoice.ncpXsInvoice.NcpXsQrInvoiceReqExcelSave;
import com.dxhy.api.model.invoice.TDxRecordInvoice;
import com.dxhy.api.model.sign.TDxRecordInvoiceDetail;
import com.dxhy.common.constant.CommonConstants;
import com.dxhy.common.constant.DbConstant;
import com.dxhy.common.constant.DictConstant;
import com.dxhy.common.datasource.config.DynamicContextHolder;
import com.dxhy.common.enums.NcpQrlxEnum;
import com.dxhy.common.service.DictdetaServcice;
import com.dxhy.common.service.impl.MpBaseServiceImpl;
import com.dxhy.common.util.AmountFormatUtil;
import com.dxhy.common.util.MathUtil;
import com.dxhy.common.utils.DateUtils;
import com.dxhy.jxpt.baseService.config.dao.SysEnterpriseConfigDao;
import com.dxhy.jxpt.baseService.ncpInvoice.dao.NcpRecordInvoiceDao;
import com.dxhy.jxpt.baseService.ncpInvoice.dao.NcpTDxRecordInvoiceDetailDao;
import com.dxhy.jxpt.baseService.ncpInvoice.dao.NcpTdxNcpSpbmDao;
import com.dxhy.jxpt.baseService.ncpInvoice.service.NcpInvoiceService;
import com.dxhy.jxpt.baseService.rzInvoice.dao.BaseServiceTdxInvoiceNcpDao;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

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

/**
* @Description 农产品页面功能业务
* @Author wangruwei
* @Date 2023/9/21 16:20
**/
@Service("ncpInvoiceService")
@Slf4j
public class NcpInvoiceServiceImpl extends MpBaseServiceImpl<NcpRecordInvoiceDao, TDxRecordInvoice> implements NcpInvoiceService {

    @Resource
    private DictdetaServcice dictdetaServcice;

    @Resource
    private BaseServiceTdxInvoiceNcpDao baseServiceTdxInvoiceNcpDao;

    @Resource
    private SysEnterpriseConfigDao sysEnterpriseConfigDao;

    @Resource
    private NcpTDxRecordInvoiceDetailDao ncpTDxRecordInvoiceDetailDao;

    @Resource
    private NcpTdxNcpSpbmDao ncpTdxNcpSpbmDao;

    /**
     * @Description 筛选出税号里开通了农产品的
     * @param gfshList
     * @Author wangruwei
     * @Date 2023/10/16 15:43
     **/
    @Override
    public List<String> getGfshNcp(List<String> gfshList) {
        if(gfshList.size()==0){
            return new ArrayList<>();
        }
        //判断购方税号是否开通农产品
        List<SysEnterpriseConfigEntity> sysEnterpriseConfigEntities = sysEnterpriseConfigDao.selectList(new LambdaQueryWrapper<SysEnterpriseConfigEntity>()
                .in(gfshList.size()>0,SysEnterpriseConfigEntity::getNsrsbh,gfshList).eq(SysEnterpriseConfigEntity::getSfqyncpdk, "1"));
        if(sysEnterpriseConfigEntities.size()>0){
            return sysEnterpriseConfigEntities.stream().map(e->e.getNsrsbh()).collect(Collectors.toList());
        }else{
            return new ArrayList<>();
        }
    }

    /**
    * @Description 筛选出税号里开通了农产品加计扣除的
    * @param gfshList
    * @Return java.util.List<java.lang.String>
    * @Author wangruwei
    * @Date 2023/10/20 17:24
    **/
    @Override
    public List<String> getGfshNcpJjkc(List<String> gfshList) {
        if(gfshList.size()==0){
            return new ArrayList<>();
        }
        //判断购方税号是否开通农产品
        List<SysEnterpriseConfigEntity> sysEnterpriseConfigEntities = sysEnterpriseConfigDao.selectList(new LambdaQueryWrapper<SysEnterpriseConfigEntity>()
                .in(gfshList.size()>0,SysEnterpriseConfigEntity::getNsrsbh,gfshList).eq(SysEnterpriseConfigEntity::getSfqyncpdk, "1")
                .eq(SysEnterpriseConfigEntity::getSfqyncpjjkc, "1")
        );
        if(sysEnterpriseConfigEntities.size()>0){
            return sysEnterpriseConfigEntities.stream().map(e->e.getNsrsbh()).collect(Collectors.toList());
        }else{
            return new ArrayList<>();
        }
    }

    /**
     * @Description 农产品销售列表
     * @Author wangruwei
     * @Date 2023/10/9 17:05
     **/
    @Override
    public Object ncpXsInvoice(Map<String, Object> pramsMap, int curr, int size) {
        JSONObject json = new JSONObject();
        DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);

        try {
            //json = tabulateRedisService.getTabulateMenu(company, menuId);

            // 合计信息,仅第一页时需要统计，减少数据库压力
            if (curr == 1) {
                String hjsl = "0";
                String hjje = "0.00";
                String hjse = "0.00";
                List<TDxRecordInvoiceNcpVo> hjList = super.baseMapper.selectNcpXsInvoiceHj(pramsMap);
                TDxRecordInvoiceNcpVo hjxx = hjList.get(0);
                hjsl = hjxx.getId();
                if (!"0".equals(hjsl)) {
                    hjje = AmountFormatUtil.fmtMicrometer(MathUtil.round(hjxx.getInvoiceAmount()));
                    hjse = AmountFormatUtil.fmtMicrometer(MathUtil.round(hjxx.getTaxAmount()));
                }
                json.put("hjsl", hjsl);
                json.put("hjje", hjje);
                json.put("hjse", hjse);
            }

            PageHelper.startPage(curr, size);
            List<TDxRecordInvoiceNcpVo> pageList = super.baseMapper.selectNcpXsInvoiceList(pramsMap);
            PageInfo<TDxRecordInvoiceNcpVo> pageInfo = new PageInfo<>(pageList);
            List<TDxRecordInvoiceNcpVo> resultList = pageInfo.getList();
            String searchPageType = pramsMap.get("searchPageType").toString();
            // 用于页面返回list对象
            if (resultList.size() > 0) {
                int start = (int)pageInfo.getStartRow();
                log.info("可勾选条件：1、认证状态 0 5 6。 2、农产品确认状态  0 3 4。 3、如果是代开农产品的话，只能是确认失败的才可勾选");
                for (int i = 0; i < resultList.size(); i++) {
                    resultList.get(i).setXh(String.valueOf(i + start));
                    /*
                    * @Description 可勾选条件
                    * 1、 认证状态 0 5 6
                    * 2、 金额大于农产品金额
                    * 3、 农产品确认状态  0 3 4
                    *
                    **/
                    //认证处理状态  认证处理状态  0-未认证 1-已勾选未确认，2已确认 3 已发送认证 4 认证成功 5 认证失败 6已撤销认证
                    String rzclzt = resultList.get(i).getRzclzt();
                    //当前申请确认处理状态：0未确认，1申请确认，2发送确认请求，3确认失败，4确认成功
                    String dqsqqrclzt =  resultList.get(i).getDqsqqrclzt();
                    if(("0".equals(rzclzt)||"5".equals(rzclzt)||"6".equals(rzclzt))
                            //&&new BigDecimal(resultList.get(i).getDkTaxAmount()).compareTo(new BigDecimal("0"))>0
                            &&("0".equals(dqsqqrclzt)||"3".equals(dqsqqrclzt)||"4".equals(dqsqqrclzt))
                    ){
                        pageList.get(i)
                                .setSelect(true);
                    }else{
                        //1234不允许勾
                        pageList.get(i)
                                .setSelect(false);
                    }

                    //4、 如果是代开农产品的话，只能是确认失败的才可勾选
                    if("2".equals(searchPageType)){
                        if(("0".equals(rzclzt)||"5".equals(rzclzt)||"6".equals(rzclzt))
                                //&&new BigDecimal(resultList.get(i).getDkTaxAmount()).compareTo(new BigDecimal("0"))>0
                                &&"3".equals(resultList.get(i).getDqsqqrclzt())){
                            pageList.get(i)
                                    .setSelect(true);
                        }else{
                            pageList.get(i)
                                    .setSelect(false);
                        }
                    }



                    if (!"01".equals(resultList.get(i).getInvoiceType())
                            && !"03".equals(resultList.get(i).getInvoiceType())
                            && !"08".equals(resultList.get(i).getInvoiceType())
                            && !"14".equals(resultList.get(i).getInvoiceType())
                            && !"31".equals(resultList.get(i).getInvoiceType())) {
                        resultList.get(i).setDkTaxAmount(null);
                    } else {
                        if (StringUtils.isNotBlank(resultList.get(i).getDkTaxAmount())) {
                            resultList.get(i).setDkTaxAmount(
                                    AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getDkTaxAmount())));
                        } else {
                            resultList.get(i).setDkTaxAmount(
                                    AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getTaxAmount())));
                        }
                    }
                    //格式化农产品部分金额和农产品可抵扣税额
                    if(StringUtils.isNotEmpty(resultList.get(i).getNcpbfje())){
                        resultList.get(i).setNcpbfje(
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getNcpbfje())));
                    }
                    if(StringUtils.isNotEmpty(resultList.get(i).getNcpbfse())){
                        resultList.get(i).setNcpbfse(
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getNcpbfse())));
                    }
                    if(StringUtils.isNotEmpty(resultList.get(i).getYxdkse())){
                        resultList.get(i).setYxdkse(
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getYxdkse())));
                    }
                    if(StringUtils.isNotEmpty(resultList.get(i).getInvoiceAmount())){
                        resultList.get(i).setInvoiceAmount(
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getInvoiceAmount())));
                    }

                    if(StringUtils.isNotEmpty(resultList.get(i).getTaxAmount())){
                        resultList.get(i)
                                .setTaxAmount(AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getTaxAmount())));
                    }
                    if(StringUtils.isNotEmpty(resultList.get(i).getTotalAmount())){
                        resultList.get(i).setTotalAmount(
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getTotalAmount())));
                    }


                    String glzt = resultList.get(i).getGlzt();
                    resultList.get(i).setGlzt(dictdetaServcice.queryDictName(DictConstant.GLZT, glzt));
                    String settlementStatus = resultList.get(i).getSettlementStatus();
                    resultList.get(i).setSettlementStatus(
                            dictdetaServcice.queryDictName(DictConstant.SETTLEMENT_STATUS, settlementStatus));
                    String invoiceStatus = resultList.get(i).getInvoiceStatus();
                    resultList.get(i)
                            .setInvoiceStatus(dictdetaServcice.queryDictName(DictConstant.INVOICE_STATUS, invoiceStatus));
                    String rzzt = resultList.get(i).getRzzt();
                    resultList.get(i).setRzzt(dictdetaServcice.queryDictName(DictConstant.DEDU_STATUS, rzzt));
                    resultList.get(i).setRzclzt(dictdetaServcice.queryDictName(DictConstant.AUTH_STATUS_ALL, rzclzt));
                    String qszt = resultList.get(i).getQszt();
                    resultList.get(i).setQszt(dictdetaServcice.queryDictName(DictConstant.QS_STATUS, qszt));
                    String qsfs = resultList.get(i).getQsfs();
                    resultList.get(i).setQsfs(dictdetaServcice.queryDictName(DictConstant.QS_TYPE, qsfs));
                    String bdkStatus = resultList.get(i).getBdkStatus();
                    resultList.get(i).setBdkStatus(dictdetaServcice.queryDictName(DictConstant.BDK_STATUS, bdkStatus));
                    String inAccountStatus = resultList.get(i).getInAccountStatus();
                    resultList.get(i)
                            .setInAccountStatus(dictdetaServcice.queryDictName(DictConstant.DK_STATUS, inAccountStatus));


                    //农产品
                    //申请确认状态  当前申请确认处理状态：0未确认，1申请确认，2发送确认请求，3确认失败，4确认成功
                    resultList.get(i)
                            .setDqsqqrclzt(dictdetaServcice.queryDictName(DictConstant.NCPFPQR_SQQRZT, dqsqqrclzt));

                    //申请确认类型 1：待确认自产农产品销售发票，13：全部自产，14：不属于自产，15：部分属于自产，
                    //2：待确认从小规模处获取的 3%税率的专票，16：按票面金额和基础扣除率确认，17：按票面税额确认，
                    //3：代开农产品发票录入，4：农产品发票
                    String ncpSqqrlx = resultList.get(i).getNcpfpcllx();
                    resultList.get(i)
                            .setNcpfpcllx(dictdetaServcice.queryDictName(DictConstant.NCPFPCLLX_ALL, ncpSqqrlx));

                    //申请确认状态
                    String Jdqrzt = resultList.get(i).getJdqrzt();
                    resultList.get(i)
                            .setJdqrzt(dictdetaServcice.queryDictName(DictConstant.NCPFPQR_FPQRZT, Jdqrzt));

                    //申请确认类型
                    String Jdqrlx = resultList.get(i).getJdqrlx();
                    resultList.get(i)
                            .setJdqrlx(dictdetaServcice.queryDictName(DictConstant.NCPFPCLLX_ALL, Jdqrlx));


                }
            }

            // 设置记录总数
            json.put("total", pageInfo.getTotal());
            json.put("datalist", resultList);

        } catch (Exception e) {
            // 统一设置操作异常标识
            json = super.errorResult(e);
        }

        return super.responseResult(json);
    }

    /**
     * @Description 农产品销售发票确认
     * @Author wangruwei
     * @Date 2023/10/10 17:53
     **/
    @Override
    public String ncpXsInvoiceQr(NcpXsQrInvoiceReq req, UserInfo userInfo) {
        List<NcpXsQrInvoice> invoiceList = req.getInvoiceList();
        String dbName = userInfo.getDbName();
        String type = req.getType();
        JSONObject json = new JSONObject();
        DynamicContextHolder.push("business" + DbConstant.BUSINESS_READ);
        String code = "0000";
        if(NcpQrlxEnum.NCP_QR_TYPE_QBZC_13.getKey().equals(type)){
            log.info("发票属于全部农产品自产，发票金额 给 农产品部分金额，农产品部分金额*0.09=农产品有效抵扣税额");
            for (int i = 0; i < invoiceList.size(); i++) {
                NcpXsQrInvoice ncpXsQrInvoice = invoiceList.get(i);
                TdxInvoiceNcpEntity updateEntity = new TdxInvoiceNcpEntity();
                if (ncpXsQrInvoice.getInvoiceAmount() != null) {
                    updateEntity.setNcpbfje(ncpXsQrInvoice.getInvoiceAmount());
                    updateEntity.setYxdkse(MathUtil.round(MathUtil.multi(ncpXsQrInvoice.getInvoiceAmount().replace(",", ""), CommonConstants.NCP_JCKCL),2));
                }

                updateEntity.setNcpfpcllx(type);
                updateEntity.setDqsqqrclzt("1");
                updateEntity.setCzsj(new Date());
                updateEntity.setUpdateTime(new Date());
                updateEntity.setQrr(userInfo.getUsername());

                //更新 t_dx_invoice_ncp 表
                baseServiceTdxInvoiceNcpDao.update(updateEntity,new LambdaUpdateWrapper<TdxInvoiceNcpEntity>().eq(TdxInvoiceNcpEntity::getUuid, ncpXsQrInvoice.getUuid()));
            }
        }else if(NcpQrlxEnum.NCP_QR_TYPE_BSYZC_14.getKey().equals(type)){
            log.info("发票不属于农产品自产，只改申请状态，农产品部分金额和农产品有效抵扣税额设置为0");
            for (int i = 0; i < invoiceList.size(); i++) {
                NcpXsQrInvoice ncpXsQrInvoice = invoiceList.get(i);

                TdxInvoiceNcpEntity updateEntity = new TdxInvoiceNcpEntity();
                updateEntity.setNcpbfje("0");
                updateEntity.setYxdkse("0");
                updateEntity.setNcpfpcllx(type);
                updateEntity.setDqsqqrclzt("1");
                updateEntity.setCzsj(new Date());
                updateEntity.setUpdateTime(new Date());
                updateEntity.setQrr(userInfo.getUsername());

                //更新 t_dx_invoice_ncp 表
                baseServiceTdxInvoiceNcpDao.update(updateEntity,new LambdaUpdateWrapper<TdxInvoiceNcpEntity>().eq(TdxInvoiceNcpEntity::getUuid, ncpXsQrInvoice.getUuid()));
            }
        }else if(NcpQrlxEnum.NCP_QR_TYPE_BFSY_15.getKey().equals(type)){
            log.info("发票部分属于自产，把客户输入的 农产品部分金额保存进去，农产品有效抵扣税额是 农产品部分金额*0.09");
            for (int i = 0; i < invoiceList.size(); i++) {
                NcpXsQrInvoice ncpXsQrInvoice = invoiceList.get(i);

                TdxInvoiceNcpEntity updateEntity = new TdxInvoiceNcpEntity();
                if (ncpXsQrInvoice.getNcpbfje() != null) {
                    updateEntity.setNcpbfje(ncpXsQrInvoice.getNcpbfje());
                    updateEntity.setYxdkse(MathUtil.round(MathUtil.multi(ncpXsQrInvoice.getNcpbfje().replace(",", ""), CommonConstants.NCP_JCKCL),2));
                }

                updateEntity.setNcpfpcllx(type);
                updateEntity.setDqsqqrclzt("1");
                updateEntity.setCzsj(new Date());
                updateEntity.setUpdateTime(new Date());
                updateEntity.setQrr(userInfo.getUsername());

                //更新 t_dx_invoice_ncp 表
                baseServiceTdxInvoiceNcpDao.update(updateEntity,new LambdaUpdateWrapper<TdxInvoiceNcpEntity>().eq(TdxInvoiceNcpEntity::getUuid, ncpXsQrInvoice.getUuid()));
            }
        }else if(NcpQrlxEnum.NCP_QR_TYPE_JE_KCL_16.getKey().equals(type)){
            log.info("发票部分属于"+NcpQrlxEnum.NCP_QR_TYPE_JE_KCL_16.getValue()+"，直接改装填");
            for (int i = 0; i < invoiceList.size(); i++) {
                NcpXsQrInvoice ncpXsQrInvoice = invoiceList.get(i);
                TdxInvoiceNcpEntity ncpInfo = baseServiceTdxInvoiceNcpDao.selectOne(new LambdaQueryWrapper<TdxInvoiceNcpEntity>().eq(TdxInvoiceNcpEntity::getUuid, ncpXsQrInvoice.getUuid()));
                DynamicContextHolder.push(dbName + DbConstant.DETAIL_READ);
                List<TDxRecordInvoiceDetail> detailList = ncpTDxRecordInvoiceDetailDao.selectList(new QueryWrapper<TDxRecordInvoiceDetail>().eq("uuid", ncpXsQrInvoice.getUuid()));
                DynamicContextHolder.push(dbName + DbConstant.BUSINESS_WRITE);
                TdxInvoiceNcpEntity updateEntity = new TdxInvoiceNcpEntity();
                if (!CollectionUtils.isEmpty(detailList)) {
                    //List<TDxRecordInvoiceDetail> bfzsNcpmx = getNcpfpMx(detailList).stream().filter(e -> CommonConstants.ZZS_SL_03.equals(e.getTaxRate())).collect(Collectors.toList());
                    BigDecimal qbncpbfje = null;
                    BigDecimal bfzsncpbfje = null;
                    BigDecimal bfzsncpbfse = null;
                    BigDecimal yxdkse = null;
                    BigDecimal ncpbfje = null;

                    for (TDxRecordInvoiceDetail tid: getNcpfpMx(detailList)) {
                        if (qbncpbfje == null) {
                            qbncpbfje = new BigDecimal(0.00);
                        }
                        if (bfzsncpbfje == null) {
                            bfzsncpbfje = new BigDecimal(0.00);
                        }
                        if (bfzsncpbfse == null) {
                            bfzsncpbfse = new BigDecimal(0.00);
                        }
                        if (CommonConstants.ZZS_SL_03.equals(tid.getTaxRate())) {
                            bfzsncpbfje = bfzsncpbfje.add(new BigDecimal(tid.getDetailAmount()));
                            bfzsncpbfse = bfzsncpbfse.add(new BigDecimal(tid.getTaxAmount()));
                        }
                        qbncpbfje = qbncpbfje.add(new BigDecimal(tid.getDetailAmount()));
                    }
                    if (qbncpbfje == null) {
                        qbncpbfje = new BigDecimal(0.00);
                    }
                    if (bfzsncpbfje == null) {
                        bfzsncpbfje = new BigDecimal(0.00);
                    }
                    if (bfzsncpbfse == null) {
                        bfzsncpbfse = new BigDecimal(0.00);
                    }
                    yxdkse = bfzsncpbfje
                            .multiply(new BigDecimal(CommonConstants.NCP_JCKCL))
                            .add(ncpInfo.getTaxAmount().subtract(bfzsncpbfse))
                            .setScale(2, BigDecimal.ROUND_HALF_UP);
                    ncpbfje = qbncpbfje;
                    updateEntity.setYxdkse(yxdkse.toPlainString());
                    updateEntity.setNcpbfje(ncpbfje.toPlainString());

                    //非 不属于自产农产品和按票面税额确认 计算农产品可加计扣除金额
                    if (ObjectUtil.isNotEmpty(ncpbfje)) {
                        String kjjkcje = ncpbfje.multiply(new BigDecimal(CommonConstants.NCP_JJCK_KCL)).setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString();
                        updateEntity.setKjjkcse(kjjkcje);
                        updateEntity.setSykjjkcse(kjjkcje);
                    }
                }



                updateEntity.setNcpfpcllx(type);
                updateEntity.setDqsqqrclzt("1");
                updateEntity.setCzsj(new Date());
                updateEntity.setUpdateTime(new Date());
                updateEntity.setQrr(userInfo.getUsername());

                //更新 t_dx_invoice_ncp 表
                baseServiceTdxInvoiceNcpDao.update(updateEntity,new LambdaUpdateWrapper<TdxInvoiceNcpEntity>().eq(TdxInvoiceNcpEntity::getUuid, ncpXsQrInvoice.getUuid()));
            }
        }else if(NcpQrlxEnum.NCP_QR_TYPE_PMSE_17.getKey().equals(type)){
            log.info("发票部分属于"+NcpQrlxEnum.NCP_QR_TYPE_PMSE_17.getValue()+"，直接改装填");
            for (int i = 0; i < invoiceList.size(); i++) {
                NcpXsQrInvoice ncpXsQrInvoice = invoiceList.get(i);
                TdxInvoiceNcpEntity ncpInfo = baseServiceTdxInvoiceNcpDao.selectOne(new LambdaQueryWrapper<TdxInvoiceNcpEntity>().eq(TdxInvoiceNcpEntity::getUuid, ncpXsQrInvoice.getUuid()));
                TdxInvoiceNcpEntity updateEntity = new TdxInvoiceNcpEntity();
                updateEntity.setNcpfpcllx(type);
                updateEntity.setDqsqqrclzt("1");
                updateEntity.setYxdkse(ncpInfo.getTaxAmount().toPlainString());
                updateEntity.setCzsj(new Date());
                updateEntity.setUpdateTime(new Date());
                updateEntity.setQrr(userInfo.getUsername());

                //更新 t_dx_invoice_ncp 表
                baseServiceTdxInvoiceNcpDao.update(updateEntity,new LambdaUpdateWrapper<TdxInvoiceNcpEntity>().eq(TdxInvoiceNcpEntity::getUuid, ncpXsQrInvoice.getUuid()));
            }
        }else{
            log.info("申请确认里没有此类型");
            json.put("code", "9999");
            json.put("msg", "销售申请里没有此类型");
            return super.responseResult(json);
        }
        json.put("code", code);
        json.put("msg", "发票确认成功");
        return super.responseResult(json);
    }

    /**
     * @description  获取农产品发票明细
     * @author  Allen
     * @date    2023/10/18 17:09
     */
    private List<TDxRecordInvoiceDetail> getNcpfpMx(List<TDxRecordInvoiceDetail> invoiceDetails) {
        List<TDxRecordInvoiceDetail> ncpMxList = new ArrayList<>();
        for (TDxRecordInvoiceDetail detail : invoiceDetails) {
            if (ncpSbpp(detail.getSphfwssflhbbm())) {
                ncpMxList.add(detail);
            }
        }
        return ncpMxList;
    }

    /**
     * @description  农产品税编匹配
     * @author  Allen
     * @date    2023/10/18 16:36
     */
    private boolean ncpSbpp(String sphfwssflhbbm) {
        boolean flag = false;
        List<TdxNcpSpbm> ncpbmList = ncpTdxNcpSpbmDao.selectList(new QueryWrapper<TdxNcpSpbm>());
        for (TdxNcpSpbm e : ncpbmList) {
            if (e.getSpbm().equals(sphfwssflhbbm)) {
                flag = true;
                break;
            }
        }
        return flag;
    }

    /**
     * @Description 农产品销售发票确认-excel导入
     * @Author wangruwei
     * @Date 2023/10/11 9:29
     **/
    @Override
    public Object ncpXsInvoiceQrExcel(List<NcpXsQrInvoiceReqExcel> reqExcelList, List<String> gfshAll) {
        log.info("导入规则验证");
        JSONObject json = new JSONObject();
        //验证导入的数据是否符合验证
        CheckExcelData checkExcelData = checkExcelData(reqExcelList, gfshAll);
        DynamicContextHolder.push("business" + DbConstant.BUSINESS_READ);
        //只要errlist大于0，就是有不符合规矩的
        if(checkExcelData.getErrMap().size()>0){
            json.put("code", "9999");
            json.put("msg", "导入确认失败");
            json.put("errList", new TreeMap<>(checkExcelData.getErrMap()));
            return super.responseResult(json);
        }else{
            //直接给前端返回转化后的数据
            json.put("code", "0000");
            json.put("msg", "导入成功");
            List<TDxRecordInvoiceNcpVo> resultList = checkExcelData.getExcelToInvoiceList();

            for (int i = 0; i < resultList.size(); i++) {
                resultList.get(i).setXh(String.valueOf(i + 1));


                resultList.get(i).setInvoiceAmount(
                        AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getInvoiceAmount())));
                if (!"01".equals(resultList.get(i).getInvoiceType())
                        && !"03".equals(resultList.get(i).getInvoiceType())
                        && !"08".equals(resultList.get(i).getInvoiceType())
                        && !"14".equals(resultList.get(i).getInvoiceType())
                        && !"31".equals(resultList.get(i).getInvoiceType())) {
                    resultList.get(i).setDkTaxAmount(null);
                } else {
                    if (StringUtils.isNotBlank(resultList.get(i).getDkTaxAmount())) {
                        resultList.get(i).setDkTaxAmount(
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getDkTaxAmount())));
                    } else {
                        resultList.get(i).setDkTaxAmount(
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getTaxAmount())));
                    }
                }
                //格式化农产品部分金额和农产品可抵扣税额
                if(StringUtils.isNotEmpty(resultList.get(i).getNcpbfje())){
                    resultList.get(i).setNcpbfje(
                            AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getNcpbfje())));
                }
                if(StringUtils.isNotEmpty(resultList.get(i).getYxdkse())){
                    resultList.get(i).setYxdkse(
                            AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getYxdkse())));
                }


                resultList.get(i)
                        .setTaxAmount(AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getTaxAmount())));
                resultList.get(i).setTotalAmount(
                        AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getTotalAmount())));

                String glzt = resultList.get(i).getGlzt();
                resultList.get(i).setGlzt(dictdetaServcice.queryDictName(DictConstant.GLZT, glzt));
                String settlementStatus = resultList.get(i).getSettlementStatus();
                resultList.get(i).setSettlementStatus(
                        dictdetaServcice.queryDictName(DictConstant.SETTLEMENT_STATUS, settlementStatus));
                String invoiceStatus = resultList.get(i).getInvoiceStatus();
                resultList.get(i)
                        .setInvoiceStatus(dictdetaServcice.queryDictName(DictConstant.INVOICE_STATUS, invoiceStatus));
                String rzzt = resultList.get(i).getRzzt();
                resultList.get(i).setRzzt(dictdetaServcice.queryDictName(DictConstant.DEDU_STATUS, rzzt));
                String rzclzt = resultList.get(i).getRzclzt();
                resultList.get(i).setRzclzt(dictdetaServcice.queryDictName(DictConstant.AUTH_STATUS_ALL, rzclzt));
                String qszt = resultList.get(i).getQszt();
                resultList.get(i).setQszt(dictdetaServcice.queryDictName(DictConstant.QS_STATUS, qszt));
                String qsfs = resultList.get(i).getQsfs();
                resultList.get(i).setQsfs(dictdetaServcice.queryDictName(DictConstant.QS_TYPE, qsfs));
                String bdkStatus = resultList.get(i).getBdkStatus();
                resultList.get(i).setBdkStatus(dictdetaServcice.queryDictName(DictConstant.BDK_STATUS, bdkStatus));
                String inAccountStatus = resultList.get(i).getInAccountStatus();
                resultList.get(i)
                        .setInAccountStatus(dictdetaServcice.queryDictName(DictConstant.DK_STATUS, inAccountStatus));

                //农产品部分

                // 农产品发票处理类型：
                //1：待确认自产农产品销售发票，13：全部自产，14：不属于自产，15：部分属于自产，
                //2：待确认从小规模处获取的 3%税率的专票，16：按票面金额和基础扣除率确认，17：按票面税额确认，
                //3：代开农产品发票录入，4：农产品发票
                String ncpfpcllx = resultList.get(i).getNcpfpcllx();
                resultList.get(i)
                        .setNcpfpcllx(dictdetaServcice.queryDictName(DictConstant.NCPFPCLLX_ALL, ncpfpcllx));

                if(NcpQrlxEnum.NCP_QR_TYPE_QBZC_13.getKey().equals(ncpfpcllx)){
                    resultList.get(i)
                        .setNcpbfje(resultList.get(i).getInvoiceAmount());
                    resultList.get(i).setYxdkse(MathUtil.round(MathUtil.multi(resultList.get(i).getInvoiceAmount().replace(",", ""), "0.09"),2));
                }
                if(NcpQrlxEnum.NCP_QR_TYPE_BSYZC_14.getKey().equals(ncpfpcllx)){
                    resultList.get(i).setNcpbfje("0");
                    resultList.get(i).setYxdkse("0");
                }
                if(NcpQrlxEnum.NCP_QR_TYPE_BFSY_15.getKey().equals(ncpfpcllx)){
                    resultList.get(i)
                            .setNcpbfje(resultList.get(i).getNcpbfje());
                    resultList.get(i).setYxdkse(MathUtil.round(MathUtil.multi(resultList.get(i).getNcpbfje().replace(",", ""), "0.09"),2));
                }

                String dqsqqrclzt =  resultList.get(i).getDqsqqrclzt();
                //农产品
                //申请确认状态  当前申请确认处理状态：0未确认，1申请确认，2发送确认请求，3确认失败，4确认成功
                resultList.get(i)
                        .setDqsqqrclzt(dictdetaServcice.queryDictName(DictConstant.NCPFPQR_SQQRZT, dqsqqrclzt));

                //申请确认类型 1：待确认自产农产品销售发票，13：全部自产，14：不属于自产，15：部分属于自产，
                //2：待确认从小规模处获取的 3%税率的专票，16：按票面金额和基础扣除率确认，17：按票面税额确认，
                //3：代开农产品发票录入，4：农产品发票

                //申请确认状态
                String Jdqrzt = resultList.get(i).getJdqrzt();
                resultList.get(i)
                        .setJdqrzt(dictdetaServcice.queryDictName(DictConstant.NCPFPQR_FPQRZT, Jdqrzt));

                //申请确认类型
                String Jdqrlx = resultList.get(i).getJdqrlx();
                resultList.get(i)
                        .setJdqrlx(dictdetaServcice.queryDictName(DictConstant.NCPFPCLLX_ALL, Jdqrlx));
            }

            json.put("data", resultList);
            json.put("errList", new ArrayList<>());
            return super.responseResult(json);
        }
    }

    /**
     * @Description 农产品销售发票确认-excel导入-入库
     * 此方法的 qrlx 传入的是中文
     * @Author wangruwei
     * @Date 2023/10/11 9:29
     **/
    @Override
    public Object ncpXsInvoiceQrExcelSave(List<NcpXsQrInvoiceReqExcelSave> reqExcelList, List<String> gfshAll, UserInfo userInfo) {
        JSONObject json = new JSONObject();
        DynamicContextHolder.push("business" + DbConstant.BUSINESS_READ);
        //筛选，并分批调确认接口
        Map<String, List<NcpXsQrInvoiceReqExcelSave>> groupMap = reqExcelList.stream().collect(Collectors.groupingBy(NcpXsQrInvoiceReqExcel::getQrlx));
        groupMap.keySet().forEach(key -> {
            List<NcpXsQrInvoiceReqExcelSave> ncpXsQrInvoiceReqExcels = groupMap.get(key);
            //---------------------------------农产品销售普票部分开始---------------------------------
            if(NcpQrlxEnum.NCP_QR_TYPE_QBZC_13.getValue().equals(key)){
                log.info(NcpQrlxEnum.NCP_QR_TYPE_QBZC_13.getValue()+"部分数据保存");
                for (int i = 0; i < ncpXsQrInvoiceReqExcels.size(); i++) {
                    TdxInvoiceNcpEntity updateEntity = new TdxInvoiceNcpEntity();
                    updateEntity.setNcpbfje(ncpXsQrInvoiceReqExcels.get(i).getNcpbfje());
                    updateEntity.setYxdkse(ncpXsQrInvoiceReqExcels.get(i).getYxdkse());
                    updateEntity.setNcpfpcllx(NcpQrlxEnum.NCP_QR_TYPE_QBZC_13.getKey());
                    updateEntity.setDqsqqrclzt("1");
                    updateEntity.setQrr(userInfo.getUsername());
                    updateEntity.setCzsj(new Date());
                    updateEntity.setUpdateTime(new Date());

                    //更新 t_dx_invoice_ncp 表
                    baseServiceTdxInvoiceNcpDao.update(updateEntity,new LambdaUpdateWrapper<TdxInvoiceNcpEntity>().eq(TdxInvoiceNcpEntity::getUuid, ncpXsQrInvoiceReqExcels.get(i).getUuid()));
                }
            }
            if(NcpQrlxEnum.NCP_QR_TYPE_BSYZC_14.getValue().equals(key)){
                log.info(NcpQrlxEnum.NCP_QR_TYPE_BSYZC_14.getValue()+"部分数据保存");
                for (int i = 0; i < ncpXsQrInvoiceReqExcels.size(); i++) {
                    TdxInvoiceNcpEntity updateEntity = new TdxInvoiceNcpEntity();
                    updateEntity.setNcpbfje("0");
                    updateEntity.setYxdkse("0");
                    updateEntity.setNcpfpcllx(NcpQrlxEnum.NCP_QR_TYPE_BSYZC_14.getKey());
                    updateEntity.setDqsqqrclzt("1");
                    updateEntity.setQrr(userInfo.getUsername());
                    updateEntity.setCzsj(new Date());
                    updateEntity.setUpdateTime(new Date());

                    //更新 t_dx_invoice_ncp 表
                    baseServiceTdxInvoiceNcpDao.update(updateEntity,new LambdaUpdateWrapper<TdxInvoiceNcpEntity>().eq(TdxInvoiceNcpEntity::getUuid, ncpXsQrInvoiceReqExcels.get(i).getUuid()));
                }
            }

            if(NcpQrlxEnum.NCP_QR_TYPE_BFSY_15.getValue().equals(key)){
                log.info(NcpQrlxEnum.NCP_QR_TYPE_BFSY_15.getValue()+"部分数据保存");
                List<NcpXsQrInvoice> invoiceList = new LinkedList<>();
                for (int i = 0; i < ncpXsQrInvoiceReqExcels.size(); i++) {
                    TdxInvoiceNcpEntity updateEntity = new TdxInvoiceNcpEntity();
                    updateEntity.setNcpbfje(ncpXsQrInvoiceReqExcels.get(i).getNcpbfje());
                    updateEntity.setYxdkse(ncpXsQrInvoiceReqExcels.get(i).getYxdkse());
                    updateEntity.setNcpfpcllx(NcpQrlxEnum.NCP_QR_TYPE_BFSY_15.getKey());
                    updateEntity.setDqsqqrclzt("1");
                    updateEntity.setQrr(userInfo.getUsername());
                    updateEntity.setCzsj(new Date());
                    updateEntity.setUpdateTime(new Date());

                    //更新 t_dx_invoice_ncp 表
                    baseServiceTdxInvoiceNcpDao.update(updateEntity,new LambdaUpdateWrapper<TdxInvoiceNcpEntity>().eq(TdxInvoiceNcpEntity::getUuid, ncpXsQrInvoiceReqExcels.get(i).getUuid()));
                }
            }
            //---------------------------------农产品销售普票部分结束---------------------------------

            //---------------------------------3%农产品部分开始---------------------------------
            if(NcpQrlxEnum.NCP_QR_TYPE_JE_KCL_16.getValue().equals(key)){
                log.info(NcpQrlxEnum.NCP_QR_TYPE_JE_KCL_16.getValue()+"部分数据保存");
                List<NcpXsQrInvoice> invoiceList = new LinkedList<>();
                for (int i = 0; i < ncpXsQrInvoiceReqExcels.size(); i++) {
                    TdxInvoiceNcpEntity updateEntity = new TdxInvoiceNcpEntity();
                    updateEntity.setNcpfpcllx(NcpQrlxEnum.NCP_QR_TYPE_JE_KCL_16.getKey());
                    updateEntity.setDqsqqrclzt("1");
                    updateEntity.setQrr(userInfo.getUsername());
                    updateEntity.setCzsj(new Date());
                    updateEntity.setUpdateTime(new Date());

                    //更新 t_dx_invoice_ncp 表
                    baseServiceTdxInvoiceNcpDao.update(updateEntity,new LambdaUpdateWrapper<TdxInvoiceNcpEntity>().eq(TdxInvoiceNcpEntity::getUuid, ncpXsQrInvoiceReqExcels.get(i).getUuid()));
                }
            }

            if(NcpQrlxEnum.NCP_QR_TYPE_PMSE_17.getValue().equals(key)){
                log.info(NcpQrlxEnum.NCP_QR_TYPE_PMSE_17.getValue()+"部分数据保存");
                List<NcpXsQrInvoice> invoiceList = new LinkedList<>();
                for (int i = 0; i < ncpXsQrInvoiceReqExcels.size(); i++) {
                    TdxInvoiceNcpEntity updateEntity = new TdxInvoiceNcpEntity();
                    updateEntity.setNcpfpcllx(NcpQrlxEnum.NCP_QR_TYPE_PMSE_17.getKey());
                    updateEntity.setDqsqqrclzt("1");
                    updateEntity.setQrr(userInfo.getUsername());
                    updateEntity.setCzsj(new Date());
                    updateEntity.setUpdateTime(new Date());

                    //更新 t_dx_invoice_ncp 表
                    baseServiceTdxInvoiceNcpDao.update(updateEntity,new LambdaUpdateWrapper<TdxInvoiceNcpEntity>().eq(TdxInvoiceNcpEntity::getUuid, ncpXsQrInvoiceReqExcels.get(i).getUuid()));
                }
            }
            //---------------------------------3%农产品部分结束---------------------------------

            //---------------------------------代开农产品部分开始---------------------------------

            if(NcpQrlxEnum.NCP_QR_TYPE_DKNCP_3.getValue().equals(key)){
                log.info(NcpQrlxEnum.NCP_QR_TYPE_DKNCP_3.getValue()+"部分数据保存");
                List<NcpXsQrInvoice> invoiceList = new LinkedList<>();
                for (int i = 0; i < ncpXsQrInvoiceReqExcels.size(); i++) {
                    TdxInvoiceNcpEntity updateEntity = new TdxInvoiceNcpEntity();
                    updateEntity.setNcpfpcllx(NcpQrlxEnum.NCP_QR_TYPE_DKNCP_3.getKey());
                    updateEntity.setDqsqqrclzt("1");
                    updateEntity.setQrr(userInfo.getUsername());
                    updateEntity.setCzsj(new Date());
                    updateEntity.setUpdateTime(new Date());

                    //农产品部分金额，税额，有效抵扣税额
                    if(StringUtils.isNotEmpty(ncpXsQrInvoiceReqExcels.get(i).getNcpbfje())){
                        updateEntity.setNcpbfje(ncpXsQrInvoiceReqExcels.get(i).getNcpbfje());
                    }
                    if(StringUtils.isNotEmpty(ncpXsQrInvoiceReqExcels.get(i).getNcpbfse())){
                        updateEntity.setNcpbfse(ncpXsQrInvoiceReqExcels.get(i).getNcpbfse());
                    }
                    if(StringUtils.isNotEmpty(ncpXsQrInvoiceReqExcels.get(i).getYxdkse())){
                        updateEntity.setYxdkse(ncpXsQrInvoiceReqExcels.get(i).getYxdkse());
                    }

                    //更新 t_dx_invoice_ncp 表
                    baseServiceTdxInvoiceNcpDao.update(updateEntity,new LambdaUpdateWrapper<TdxInvoiceNcpEntity>().eq(TdxInvoiceNcpEntity::getUuid, ncpXsQrInvoiceReqExcels.get(i).getUuid()));
                }
            }

            //---------------------------------代开农产品部分结束---------------------------------
        });

        json.put("code", "0000");
        json.put("msg", "导入确认成功");
        return super.responseResult(json);

    }



    /**
    * @Description 验证导入的数据是否符合验证
    * @Author wangruwei
    * @Date 2023/10/11 15:43
    **/
    private CheckExcelData checkExcelData(List<NcpXsQrInvoiceReqExcel> reqExcelList, List<String> gfshAll) {
        CheckExcelData checkExcelData = new CheckExcelData();
        //定义触发规则的数据
        Map<Integer, String> errMap = new HashMap<>();

        List<TDxRecordInvoiceNcpVo> excelToInvoiceList = new LinkedList<>();
        //初始化行号
        for (int i = 0; i < reqExcelList.size(); i++) {
            reqExcelList.get(i).setRowNum(i+1);
        }
        //筛选出开通农产品的税号
        List<String> gfshNcp = getGfshNcp(gfshAll);
        DynamicContextHolder.push("business" + DbConstant.BUSINESS_READ);
        log.info("1.判断必填项（确认类型、发票号码）是否填写");
        List<NcpXsQrInvoiceReqExcel> qrlxFphmIsnull = reqExcelList.stream().filter(e -> StringUtils.isEmpty(e.getQrlx()) || StringUtils.isEmpty(e.getFphm())).collect(Collectors.toList());
        if(qrlxFphmIsnull.size()>0){
            log.info("确认类型、发票号码）有未填写的数据:{}", JSON.toJSONString(qrlxFphmIsnull));
            for (NcpXsQrInvoiceReqExcel item: qrlxFphmIsnull){
                createErrMsg(errMap,item.getRowNum(),"确认类型、发票号码必填");
            }
        }

        log.info("2.判断确认类型值是否正确（"+NcpQrlxEnum.NCP_QR_TYPE_QBZC_13.getValue()+"、"+NcpQrlxEnum.NCP_QR_TYPE_BSYZC_14.getValue()+"、"+NcpQrlxEnum.NCP_QR_TYPE_BFSY_15.getValue()+"）");
        List<NcpXsQrInvoiceReqExcel> qrlxTypeErrList = reqExcelList.stream()
                .filter(e -> !NcpQrlxEnum.NCP_QR_TYPE_QBZC_13.getValue().equals(e.getQrlx())
                        &&!NcpQrlxEnum.NCP_QR_TYPE_BSYZC_14.getValue().equals(e.getQrlx())
                        &&!NcpQrlxEnum.NCP_QR_TYPE_BFSY_15.getValue().equals(e.getQrlx())
                )
                .collect(Collectors.toList());
        if(qrlxTypeErrList.size()>0){
            log.info("确认类型只能选择 "+NcpQrlxEnum.NCP_QR_TYPE_QBZC_13.getValue()+"、"+NcpQrlxEnum.NCP_QR_TYPE_BSYZC_14.getValue()+"、"+NcpQrlxEnum.NCP_QR_TYPE_BFSY_15.getValue()+"。以下数据不符合:{}",JSON.toJSONString(qrlxTypeErrList));
            for (NcpXsQrInvoiceReqExcel item: qrlxTypeErrList){
                createErrMsg(errMap,item.getRowNum(),"确认类型错误");
            }
        }

        log.info("3.当确认类型为“部分属于自产农产品销售发票”校验农产品金额是否有值，且为数值，如果数值为多位小数仅保留两位小数。非当前确认条件中农产品部分金额中值忽略");
        List<NcpXsQrInvoiceReqExcel> bfNcpList = reqExcelList.stream()
                .filter(e -> NcpQrlxEnum.NCP_QR_TYPE_BFSY_15.getValue().equals(e.getQrlx())
                )
                .collect(Collectors.toList());
        //验证是否不为空且是数字
        for (NcpXsQrInvoiceReqExcel item : bfNcpList) {
            if(StringUtils.isEmpty(item.getNcpbfje())){
                createErrMsg(errMap,item.getRowNum(),"未录入农产品金额");
                continue;
            }
            if(!MathUtil.isNumberLessTwo(item.getNcpbfje())){
                createErrMsg(errMap,item.getRowNum(),"农产品金额数值格式错误，需保留两位小数");
                continue;
            }
        }


        log.info("4.本excel中数据不允许重复。根据发票代码、号码查询抵账库是否存在。在系统中申请确认状态为未确认、确认失败、确认成功；且判断发票是否当前用户权限数据的。5.校验农产品部分金额是否小于等于发票金额,(申请确认，发送确认请求)的数据不让进");
        Map<String, List<NcpXsQrInvoiceReqExcel>> collect = reqExcelList.stream().collect(Collectors.groupingBy(e -> e.getFpdm() + e.getFphm()));
        collect.keySet().forEach(key -> {
            List<NcpXsQrInvoiceReqExcel> ncpDkInvoiceLrReqs = collect.get(key);
            if(ncpDkInvoiceLrReqs.size()>1){
                createErrMsg(errMap,ncpDkInvoiceLrReqs.get(0).getRowNum(),"当前请求数据中发票代码号码存在重复。代码:"+key.substring(0, 12)+"号码:"+key.substring(12, key.length()));
            }
        });

        for (NcpXsQrInvoiceReqExcel item:
                reqExcelList ) {
            String uuid = (StringUtils.isEmpty(item.getFpdm())?"":item.getFpdm()) + item.getFphm();
            TDxRecordInvoiceNcpVo tDxRecordInvoice = this.baseMapper.selectNcpXsInvoiceByUuid(uuid);
            if(ObjectUtil.isEmpty(tDxRecordInvoice)){
                createErrMsg(errMap,item.getRowNum(),"发票为非农产品销售发票");
                continue;
            }

            if(!gfshNcp.contains(tDxRecordInvoice.getGfsh())){
                createErrMsg(errMap,item.getRowNum(),"企业未开通农产品功能权限");
                continue;
            }
            if(!gfshAll.contains(tDxRecordInvoice.getGfsh())){
                createErrMsg(errMap,item.getRowNum(),"无发票所属税号操作权限");
                continue;
            }
            //认证处理状态  认证处理状态  0-未认证 1-已勾选未确认，2已确认 3 已发送认证 4 认证成功 5 认证失败 6已撤销认证
            String rzclzt = tDxRecordInvoice.getRzclzt();
            if("1".equals(rzclzt)||"2".equals(rzclzt)||"3".equals(rzclzt)){
                createErrMsg(errMap,item.getRowNum(),"发票已认证不允许确认");
                continue;
            }
            if(!"0".equals(tDxRecordInvoice.getDqsqqrclzt())&&!"3".equals(tDxRecordInvoice.getDqsqqrclzt())&&!"4".equals(tDxRecordInvoice.getDqsqqrclzt())){
                createErrMsg(errMap,item.getRowNum(),"发票已在确认中不允许发起确认");
                continue;
            }
            if(new BigDecimal(tDxRecordInvoice.getInvoiceAmount()).compareTo(new BigDecimal(item.getNcpbfje()))<0){
                createErrMsg(errMap,item.getRowNum(),"农产品部分金额必须小于等于发票金额");
                continue;
            }
            tDxRecordInvoice.setNcpbfje(item.getNcpbfje());
            String ncpfpcllx = item.getQrlx();
            if(NcpQrlxEnum.NCP_QR_TYPE_QBZC_13.getValue().equals(ncpfpcllx)){
                ncpfpcllx = NcpQrlxEnum.NCP_QR_TYPE_QBZC_13.getKey();
            }
            if(NcpQrlxEnum.NCP_QR_TYPE_BSYZC_14.getValue().equals(ncpfpcllx)){
                ncpfpcllx = NcpQrlxEnum.NCP_QR_TYPE_BSYZC_14.getKey();
            }
            if(NcpQrlxEnum.NCP_QR_TYPE_BFSY_15.getValue().equals(ncpfpcllx)){
                ncpfpcllx = NcpQrlxEnum.NCP_QR_TYPE_BFSY_15.getKey();
            }
            tDxRecordInvoice.setNcpfpcllx(ncpfpcllx);
            excelToInvoiceList.add(tDxRecordInvoice);
        }
        checkExcelData.setErrMap(errMap);
        checkExcelData.setExcelToInvoiceList(excelToInvoiceList);
        return checkExcelData;
    }

    public static void main(String[] args) {
        String a = "{\"errList\":[\"第1行 确认类型、发票号码必须填写\",\"第2行 确认类型、发票号码必须填写\",\"第1行 确认类型只能选择属于自产农产品销售发票,不属于自产农产品销售发票,部分属于自产农产品销售发票\",\"第2行 部分属于自产农产品销售发票，农产品金额必须填写且为数字\",\"第1行 在抵账库和农产品确认中没有，无法导入\",\"第2行 在抵账库和农产品确认中没有，无法导入\"],\"excelToInvoiceList\":[]}\n";

        CheckExcelData checkExcelData = JSON.parseObject(a,CheckExcelData.class);
        System.out.println(checkExcelData);

        Map<String,Object> map = new HashMap();

        List<ErrorMsg> list = new LinkedList();
    }


    public static void createErrMsg(Map errMap,int rowNum,String msg){
        if(errMap.containsKey(rowNum)){
            errMap.put(rowNum, errMap.get(rowNum)+msg+"。");
        }else{
            errMap.put(rowNum, msg+"。");
        }
    }

    /**
    * @Description 返回带有ncp表数据的实体。ncp表有数据的情况用这个
    * @Return
    * @Author wangruwei
    * @Date 2023/10/17 9:43
    **/
    @Data
    public class CheckExcelData{
        /**
         * 给前端返回的验证住的信息
         **/
        private Map errMap;
        /**
         * 校验成功后，excel转化为底账表关联农产品表具体信息
         **/
        private List<TDxRecordInvoiceNcpVo> excelToInvoiceList;
    }

    /**
    * @Description 返回验证错误实体
    * @Author wangruwei
    * @Date 2023/10/17 16:19
    **/
    @Data
    public class ErrorMsg{
        /**
         * 第几行
         **/
        private int rowNum;
        /**
         * 验证住的消息
         **/
        private String msg;
    }

    /**
     * @Description 返回带有底账表数据，代开导入，ncp表还没数据
     * @Return
     * @Author wangruwei
     * @Date 2023/10/17 9:43
     **/
    @Data
    public class CheckExcelDataRecord{
        /**
         * 给前端返回的验证住的信息
         **/
        private Map<Integer, String> errList;
        /**
         * 校验成功后，excel转化为底账表关联农产品表具体信息
         **/
        private List<TDxRecordInvoice> excelToInvoiceList;
    }



    /**
     * @Description 通过代码号码找到底账表数据
     * @Author wangruwei
     * @Date 2023/10/13 14:55
     **/
    @Override
    public JSONObject selRecordInvoiceByDmHm(Map<String, String> pramsMap) {
        DynamicContextHolder.push("business" + DbConstant.BUSINESS_READ);
        String fpdm = StringUtils.isEmpty(pramsMap.get("fpdm"))?"":pramsMap.get("fpdm");
        String fphm = pramsMap.get("fphm");
        String uuid = fpdm + fphm;
        JSONObject json = new JSONObject();
        TDxRecordInvoiceNcpVo tDxRecordInvoice = this.baseMapper.selectRecordInvoiceByUuid(uuid);
        if(ObjectUtil.isEmpty(tDxRecordInvoice)){
            json.put("code", "9999");
            json.put("msg", "底账中没有此发票，请确认");
        }else{
            log.info("验证可录入规则");
            log.info("条件需满足 xf_tax_no like '%DK%' and invoice_status in ('0','7') and lq_hzsdbs = 'N' and glzt = '0' and auth_status in ('0','5','6')");
            if(!tDxRecordInvoice.getXfsh().contains("DK")){
                json.put("code", "9999");
                json.put("msg", "请录入代开发票");
                return json;
            }
            if(!Arrays.asList("0","7").contains(tDxRecordInvoice.getInvoiceStatus())
                ||!"N".equals(tDxRecordInvoice.getLqHzsdbs())

            ){
                json.put("code", "9999");
                json.put("msg", "发票状态异常");
                return json;
            }
            if(!"0".equals(tDxRecordInvoice.getGlzt())){
                json.put("code", "9999");
                json.put("msg", "管理状态异常");
                return json;
            }

            if(!Arrays.asList("0","5","6").contains(tDxRecordInvoice.getRzclzt())){
                json.put("code", "9999");
                json.put("msg", "发票已认证不允许再次确认");
                return json;
            }
            if(ObjectUtil.isNotEmpty(tDxRecordInvoice.getInvoiceAmount())){
                if(MathUtil.compare(tDxRecordInvoice.getInvoiceAmount(),"0")<0){
                    json.put("code", "9999");
                    json.put("msg", "负数发票不允许确认");
                    return json;
                }
            }


            //查询农产品表
            TDxRecordInvoiceNcpVo ncpVo = this.baseMapper.selectNcpXsInvoiceByUuid(uuid);
            if(ObjectUtil.isNotEmpty(ncpVo)){
                if(!"3".equals(ncpVo.getDqsqqrclzt())){
                    json.put("code", "9999");
                    json.put("msg", "确认列表已存在");
                    return json;
                }
            }

            if(ObjectUtil.isNotEmpty(tDxRecordInvoice.getInvoiceAmount())){
                tDxRecordInvoice.setInvoiceAmount(AmountFormatUtil.fmtMicrometer(tDxRecordInvoice.getInvoiceAmount()));
            }
            if(ObjectUtil.isNotEmpty(tDxRecordInvoice.getTaxAmount())){
                tDxRecordInvoice.setTaxAmount(AmountFormatUtil.fmtMicrometer(tDxRecordInvoice.getTaxAmount()));
            }


            json.put("code", "0000");
            json.put("data", tDxRecordInvoice);
        }
        return json;
    }

    /**
     * @Description 农产品3%专票确认-excel导入-展示给前端数据
     * @Author wangruwei
     * @Date 2023/10/11 9:29
     **/
    @Override
    public Object ncpZpInvoiceQrExcel(List<NcpXsQrInvoiceReqExcel> reqExcelList, List<String> gfshAll) {
        log.info("导入规则验证");
        JSONObject json = new JSONObject();
        //验证导入的数据是否符合验证
        CheckExcelData checkExcelData = checkZpExcelData(reqExcelList, gfshAll);
        DynamicContextHolder.push("business" + DbConstant.BUSINESS_READ);
        //只要errlist大于0，就是有不符合规矩的
        if(checkExcelData.getErrMap().size()>0){
            json.put("code", "9999");
            json.put("msg", "导入确认失败");
            json.put("errList", new TreeMap<>(checkExcelData.getErrMap()));
            return super.responseResult(json);
        }else{
            //直接给前端返回转化后的数据
            json.put("code", "0000");
            json.put("msg", "导入成功");
            List<TDxRecordInvoiceNcpVo> resultList = checkExcelData.getExcelToInvoiceList();

            for (int i = 0; i < resultList.size(); i++) {
                resultList.get(i).setXh(String.valueOf(i + 1));


                resultList.get(i).setInvoiceAmount(
                        AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getInvoiceAmount())));
                if (!"01".equals(resultList.get(i).getInvoiceType())
                        && !"03".equals(resultList.get(i).getInvoiceType())
                        && !"08".equals(resultList.get(i).getInvoiceType())
                        && !"14".equals(resultList.get(i).getInvoiceType())
                        && !"31".equals(resultList.get(i).getInvoiceType())) {
                    resultList.get(i).setDkTaxAmount(null);
                } else {
                    if (StringUtils.isNotBlank(resultList.get(i).getDkTaxAmount())) {
                        resultList.get(i).setDkTaxAmount(
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getDkTaxAmount())));
                    } else {
                        resultList.get(i).setDkTaxAmount(
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getTaxAmount())));
                    }
                }
                //格式化农产品部分金额和农产品可抵扣税额
                if(StringUtils.isNotEmpty(resultList.get(i).getNcpbfje())){
                    resultList.get(i).setNcpbfje(
                            AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getNcpbfje())));
                }
                if(StringUtils.isNotEmpty(resultList.get(i).getYxdkse())){
                    resultList.get(i).setYxdkse(
                            AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getYxdkse())));
                }


                resultList.get(i)
                        .setTaxAmount(AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getTaxAmount())));
                resultList.get(i).setTotalAmount(
                        AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getTotalAmount())));

                String glzt = resultList.get(i).getGlzt();
                resultList.get(i).setGlzt(dictdetaServcice.queryDictName(DictConstant.GLZT, glzt));
                String settlementStatus = resultList.get(i).getSettlementStatus();
                resultList.get(i).setSettlementStatus(
                        dictdetaServcice.queryDictName(DictConstant.SETTLEMENT_STATUS, settlementStatus));
                String invoiceStatus = resultList.get(i).getInvoiceStatus();
                resultList.get(i)
                        .setInvoiceStatus(dictdetaServcice.queryDictName(DictConstant.INVOICE_STATUS, invoiceStatus));
                String rzzt = resultList.get(i).getRzzt();
                resultList.get(i).setRzzt(dictdetaServcice.queryDictName(DictConstant.DEDU_STATUS, rzzt));
                String rzclzt = resultList.get(i).getRzclzt();
                resultList.get(i).setRzclzt(dictdetaServcice.queryDictName(DictConstant.AUTH_STATUS_ALL, rzclzt));
                String qszt = resultList.get(i).getQszt();
                resultList.get(i).setQszt(dictdetaServcice.queryDictName(DictConstant.QS_STATUS, qszt));
                String qsfs = resultList.get(i).getQsfs();
                resultList.get(i).setQsfs(dictdetaServcice.queryDictName(DictConstant.QS_TYPE, qsfs));
                String bdkStatus = resultList.get(i).getBdkStatus();
                resultList.get(i).setBdkStatus(dictdetaServcice.queryDictName(DictConstant.BDK_STATUS, bdkStatus));
                String inAccountStatus = resultList.get(i).getInAccountStatus();
                resultList.get(i)
                        .setInAccountStatus(dictdetaServcice.queryDictName(DictConstant.DK_STATUS, inAccountStatus));

                //农产品部分

                // 农产品发票处理类型：
                //1：待确认自产农产品销售发票，13：全部自产，14：不属于自产，15：部分属于自产，
                //2：待确认从小规模处获取的 3%税率的专票，16：按票面金额和基础扣除率确认，17：按票面税额确认，
                //3：代开农产品发票录入，4：农产品发票
                String ncpfpcllx = resultList.get(i).getNcpfpcllx();
                resultList.get(i)
                        .setNcpfpcllx(dictdetaServcice.queryDictName(DictConstant.NCPFPCLLX_ALL, ncpfpcllx));

                if(NcpQrlxEnum.NCP_QR_TYPE_QBZC_13.getKey().equals(ncpfpcllx)){
                    resultList.get(i)
                            .setNcpbfje(resultList.get(i).getInvoiceAmount());
                    resultList.get(i).setYxdkse(MathUtil.round(MathUtil.multi(resultList.get(i).getInvoiceAmount().replace(",", ""), "0.09"),2));
                }
                if(NcpQrlxEnum.NCP_QR_TYPE_BSYZC_14.getKey().equals(ncpfpcllx)){
                    resultList.get(i).setNcpbfje("0");
                    resultList.get(i).setYxdkse("0");
                }
                if(NcpQrlxEnum.NCP_QR_TYPE_BFSY_15.getKey().equals(ncpfpcllx)){
                    resultList.get(i)
                            .setNcpbfje(resultList.get(i).getNcpbfje());
                    resultList.get(i).setYxdkse(MathUtil.round(MathUtil.multi(resultList.get(i).getNcpbfje().replace(",", ""), "0.09"),2));
                }

                String dqsqqrclzt =  resultList.get(i).getDqsqqrclzt();
                //农产品
                //申请确认状态  当前申请确认处理状态：0未确认，1申请确认，2发送确认请求，3确认失败，4确认成功
                resultList.get(i)
                        .setDqsqqrclzt(dictdetaServcice.queryDictName(DictConstant.NCPFPQR_SQQRZT, dqsqqrclzt));

                //申请确认状态
                String Jdqrzt = resultList.get(i).getJdqrzt();
                resultList.get(i)
                        .setJdqrzt(dictdetaServcice.queryDictName(DictConstant.NCPFPQR_FPQRZT, Jdqrzt));

                //申请确认类型
                String Jdqrlx = resultList.get(i).getJdqrlx();
                resultList.get(i)
                        .setJdqrlx(dictdetaServcice.queryDictName(DictConstant.NCPFPCLLX_ALL, Jdqrlx));
            }

            json.put("data", resultList);
            json.put("errList", new ArrayList<>());
            return super.responseResult(json);
        }
    }

    /**
     * @Description 代开农产品录入保存
     * @Author wangruwei
     * @Date 2023/10/13 15:44
     **/
    @Override
    public JSONObject dkNcpInvoiceLr(List<NcpDkInvoiceLrReq> list, List<String> gfshAll, UserInfo userInfo) {
        DynamicContextHolder.push("business" + DbConstant.BUSINESS_READ);
        for (int i = 0; i < list.size(); i++) {
            list.get(i).setRowNum(i+1);
        }
        JSONObject json = new JSONObject();
        //校验录入的数据是否合规
        Map<Integer, String> errMap = checkDkLrData(list, gfshAll);
        if(errMap.size()>0){
            json.put("code", "9999");
            json.put("msg", "保存数据不符合规范");
            json.put("errList", new TreeMap<>(errMap));
            return json;
        }
        for (int i = 0; i < list.size(); i++) {
            NcpDkInvoiceLrReq item = list.get(i);
            String invoiceUuid = getInvoiceUuid(item.getFpdm(), item.getFphm());
            //底账发票
            TDxRecordInvoice tDxRecordInvoice = this.baseMapper.selectOne(new LambdaQueryWrapper<TDxRecordInvoice>().eq(TDxRecordInvoice::getUuid, invoiceUuid));
            //判断如果农产品表有，更新。如果没有，入库
            TdxInvoiceNcpEntity selNcpEntity = baseServiceTdxInvoiceNcpDao.selectOne(new LambdaQueryWrapper<TdxInvoiceNcpEntity>().eq(TdxInvoiceNcpEntity::getUuid, invoiceUuid));
            if(ObjectUtil.isEmpty(selNcpEntity)){
                //定义要生成的ncp发票表数据
                TdxInvoiceNcpEntity ncpEntity = new TdxInvoiceNcpEntity();
                ncpEntity.setInvoiceType(tDxRecordInvoice.getInvoiceType());
                ncpEntity.setInvoiceCode(tDxRecordInvoice.getInvoiceCode());
                ncpEntity.setInvoiceNo(tDxRecordInvoice.getInvoiceNo());
                ncpEntity.setEleInvoiceNo(tDxRecordInvoice.getEleInvoiceNo());
                ncpEntity.setUuid(tDxRecordInvoice.getUuid());
                ncpEntity.setInvoiceDate(tDxRecordInvoice.getInvoiceDate());
                ncpEntity.setGfTaxNo(tDxRecordInvoice.getGfTaxNo());
                ncpEntity.setGfName(tDxRecordInvoice.getGfName());
                ncpEntity.setXfTaxNo(tDxRecordInvoice.getXfTaxNo());
                ncpEntity.setXfName(tDxRecordInvoice.getXfName());
                ncpEntity.setInvoiceAmount(tDxRecordInvoice.getInvoiceAmount());
                ncpEntity.setTaxAmount(tDxRecordInvoice.getTaxAmount());
                ncpEntity.setTotalAmount(tDxRecordInvoice.getTotalAmount());
                ncpEntity.setNcpbfje(item.getNcpbfje());
                ncpEntity.setNcpbfse(item.getNcpbfse());
                ncpEntity.setYxdkse(item.getYxdkse());
                ncpEntity.setNcpfpcllx("3");
                ncpEntity.setDqsqqrclzt("1");
                ncpEntity.setQrsbyy("");
                ncpEntity.setJdqrzt("");
                ncpEntity.setJdqrlx("");
                ncpEntity.setQrr(userInfo.getUsername());
                ncpEntity.setCzsj(new Date());
                ncpEntity.setUpdateTime(new Date());
                ncpEntity.setCreateTime(new Date());
                baseServiceTdxInvoiceNcpDao.insert(ncpEntity);
            }else{
                TdxInvoiceNcpEntity ncpUpdateEntity = new TdxInvoiceNcpEntity();
                ncpUpdateEntity.setYxdkse(item.getYxdkse());
                ncpUpdateEntity.setNcpbfje(item.getNcpbfje());
                ncpUpdateEntity.setNcpbfse(item.getNcpbfse());
                ncpUpdateEntity.setNcpfpcllx("3");
                ncpUpdateEntity.setDqsqqrclzt("1");
                ncpUpdateEntity.setQrsbyy("");
                ncpUpdateEntity.setJdqrzt("");
                ncpUpdateEntity.setJdqrlx("");
                ncpUpdateEntity.setQrr(userInfo.getUsername());
                ncpUpdateEntity.setCzsj(new Date());
                ncpUpdateEntity.setUpdateTime(new Date());
                ncpUpdateEntity.setId(selNcpEntity.getId());
                baseServiceTdxInvoiceNcpDao.updateById(ncpUpdateEntity);
            }
        }
        json.put("code", "0000");
        json.put("msg", "保存成功");
        return json;
    }



    /**
    * @Description 校验代开录入数据是否合规
    * @Author wangruwei
    * @Date 2023/10/13 16:35
    **/
    private Map<Integer, String> checkDkLrData(List<NcpDkInvoiceLrReq> list, List<String> gfshAll) {
        //定义触发规则的数据
        Map<Integer, String> errMap = new HashMap<>();

        log.info("1.判断发票代码号码，农产品发票金额，农产品发票税额，有效抵扣税额是否有空");
        List<NcpDkInvoiceLrReq> jsIsNullList = list.stream().filter(e -> StringUtils.isEmpty(e.getFpdm()) || StringUtils.isEmpty(e.getFphm()) || StringUtils.isEmpty(e.getNcpbfje()) || StringUtils.isEmpty(e.getNcpbfse()) || StringUtils.isEmpty(e.getYxdkse())).collect(Collectors.toList());
        if(jsIsNullList.size()>0){
            log.info("判断发票代码号码，农产品发票金额，农产品发票税额，有效抵扣税额未填写的数据:{}", JSON.toJSONString(jsIsNullList));
            for (NcpDkInvoiceLrReq item: jsIsNullList){
                createErrMsg(errMap,item.getRowNum(),"确认类型、发票号码必填");
            }
        }
        log.info("2.农产品部分金额，农产品部分税额，有效抵扣税额必须是数字");
        List<NcpDkInvoiceLrReq> jsIsDoubleList = list.stream().filter(e -> !MathUtil.isNumberLessTwo(e.getNcpbfje()) || !MathUtil.isNumberLessTwo(e.getNcpbfse()) || !MathUtil.isNumberLessTwo(e.getYxdkse())).collect(Collectors.toList());
        if(jsIsDoubleList.size()>0){
            log.info("农产品部分金额，农产品部分税额，有效抵扣税额 不是数字的数据:{}", JSON.toJSONString(jsIsDoubleList));
            for (NcpDkInvoiceLrReq item: jsIsNullList){
                createErrMsg(errMap,item.getRowNum(),"农产品部分金额，农产品部分税额，有效抵扣税额数值格式错误，需保留两位小数");
            }
        }
        list.stream().forEach(e->{
            if(StringUtils.isNotEmpty(e.getInvoiceAmount())){
                e.setInvoiceAmount(e.getInvoiceAmount().replace(",", ""));
            }
        });
        log.info("3.农产品发票金额，农产品发票税额，有效抵扣税额必须大于0");
        List<NcpDkInvoiceLrReq> jsDyZeroList = list.stream().filter(e ->
                MathUtil.compare(e.getNcpbfje(),"0")<=0 || MathUtil.compare(e.getNcpbfse(),"0")<=0 || MathUtil.compare(e.getYxdkse(),"0")<=0).collect(Collectors.toList());
        if(jsDyZeroList.size()>0){
            log.info("农产品发票金额，农产品发票税额，有效抵扣税额 小于等于0的数据:{}", JSON.toJSONString(jsDyZeroList));
            for (NcpDkInvoiceLrReq item: jsIsNullList){
                createErrMsg(errMap,item.getRowNum(),"农产品发票金额，农产品发票税额，有效抵扣税额必须大于0");
            }
        }

        log.info("4.有效抵扣税额 大于等于 农产品部分税额；且 农产品部分金额 小于等于 发票金额；且 农产品部分税额 小于 农产品部分金额");
        /* 这个条件是查出来符合的，要验证，用反的来  List<NcpDkInvoiceLrReq> jeCompareList = list.stream().filter(e ->
                MathUtil.compare(e.getYxdkse(),e.getNcpbfse())>=0 && MathUtil.compare(e.getNcpbfje(),e.getInvoiceAmount())<=0 && MathUtil.compare(e.getNcpbfse(),e.getNcpbfje())<0).collect(Collectors.toList());*/
        List<NcpDkInvoiceLrReq> jeCompareList = list.stream().filter(e ->
                MathUtil.compare(e.getYxdkse(),e.getNcpbfse())<0 || MathUtil.compare(e.getNcpbfje(),e.getInvoiceAmount())>0 || MathUtil.compare(e.getNcpbfse(),e.getNcpbfje())>=0).collect(Collectors.toList());
        if(jeCompareList.size()>0){
            log.info("不符合4规则的数据:{}", JSON.toJSONString(jeCompareList));
            for (NcpDkInvoiceLrReq item: jsIsNullList){
                createErrMsg(errMap,item.getRowNum(),"有效抵扣税额需 大于等于 农产品部分税额；且 农产品部分金额需 小于等于 发票金额；且 农产品部分税额需 小于 农产品部分金额");
            }
        }

        log.info("5.传入的发票不允许重复。根据发票代码、号码查询抵账库是否存在。在系统中申请确认状态为未确认、确认失败；且判断发票是否当前用户权限数据的。");
        Map<String, List<NcpDkInvoiceLrReq>> collect = list.stream().collect(Collectors.groupingBy(e -> e.getFpdm() + e.getFphm()));
        collect.keySet().forEach(key -> {
            List<NcpDkInvoiceLrReq> ncpDkInvoiceLrReqs = collect.get(key);
            if(ncpDkInvoiceLrReqs.size()>1){
                createErrMsg(errMap,ncpDkInvoiceLrReqs.get(0).getRowNum(),"当前请求数据中发票代码号码存在重复。代码:"+key.substring(0, 12)+"号码:"+key.substring(12, key.length()));
            }
        });

        for (NcpDkInvoiceLrReq item:
                list ) {
            String uuid = (StringUtils.isEmpty(item.getFpdm())?"":item.getFpdm()) + item.getFphm();
            TDxRecordInvoice tDxRecordInvoice = this.baseMapper.selectOne(new LambdaQueryWrapper<TDxRecordInvoice>().eq(TDxRecordInvoice::getUuid, uuid));
            if(ObjectUtil.isEmpty(tDxRecordInvoice)){
                createErrMsg(errMap,item.getRowNum(),"发票不存在");
                continue;
            }
            if(!gfshAll.contains(tDxRecordInvoice.getGfTaxNo())){
                createErrMsg(errMap,item.getRowNum(),"无发票所属税号操作权限");
            }
            log.info("条件需满足 xf_tax_no like '%DK%' and invoice_status in ('0','7') and lq_hzsdbs = 'N' and glzt = '0' and auth_status in ('0','5','6')");

            if(!tDxRecordInvoice.getXfTaxNo().contains("DK")){
                createErrMsg(errMap,item.getRowNum(),"发票为非代开发票");
            }
            if(!Arrays.asList("0","7").contains(tDxRecordInvoice.getInvoiceStatus())
                    ||!"N".equals(tDxRecordInvoice.getLqHzsdbs())
            ){
                createErrMsg(errMap,item.getRowNum(),"发票状态异常");
            }
            if(!"0".equals(tDxRecordInvoice.getGlzt())){
                createErrMsg(errMap,item.getRowNum(),"管理状态异常");
            }
            if(MathUtil.compare(tDxRecordInvoice.getInvoiceAmount().toPlainString(),"0")<0){
                createErrMsg(errMap,item.getRowNum(),"负数发票不允许确认");
            }
            if(!Arrays.asList("0","5","6").contains(tDxRecordInvoice.getAuthStatus())){
                createErrMsg(errMap,item.getRowNum(),"发票已认证不允许再次确认");
            }

            //查询农产品表
            TDxRecordInvoiceNcpVo ncpVo = this.baseMapper.selectNcpXsInvoiceByUuid(uuid);
            if(ObjectUtil.isNotEmpty(ncpVo)){
                if(!"3".equals(ncpVo.getDqsqqrclzt())){
                    createErrMsg(errMap,item.getRowNum(),"确认列表已存在");
                }
            }

        }
        return errMap;
    }

    /**
    * @Description 3%专票农产品导入验证
    * @Return com.dxhy.jxpt.baseService.ncpInvoice.service.impl.NcpInvoiceServiceImpl.CheckExcelData
    * @Author wangruwei
    * @Date 2023/10/12 18:10
    **/
    private CheckExcelData checkZpExcelData(List<NcpXsQrInvoiceReqExcel> reqExcelList, List<String> gfshAll) {
        CheckExcelData checkExcelData = new CheckExcelData();
        //定义触发规则的数据
        Map<Integer, String> errMap = new HashMap<>();
        List<TDxRecordInvoiceNcpVo> excelToInvoiceList = new LinkedList<>();
        //初始化行号
        for (int i = 0; i < reqExcelList.size(); i++) {
            reqExcelList.get(i).setRowNum(i+1);
        }

        List<String> gfshNcp = getGfshNcp(gfshAll);
        DynamicContextHolder.push("business" + DbConstant.BUSINESS_READ);
        log.info("1.判断必填项（确认类型、发票号码）是否填写");
        List<NcpXsQrInvoiceReqExcel> qrlxFphmIsnull = reqExcelList.stream().filter(e -> StringUtils.isEmpty(e.getQrlx()) || StringUtils.isEmpty(e.getFphm())).collect(Collectors.toList());
        if(qrlxFphmIsnull.size()>0){
            log.info("确认类型、发票号码）有未填写的数据:{}", JSON.toJSONString(qrlxFphmIsnull));
            for (NcpXsQrInvoiceReqExcel item: qrlxFphmIsnull){
                createErrMsg(errMap,item.getRowNum(),"确认类型、发票号码必填");
            }
        }

        log.info("2.判断确认类型值是否正确（"+NcpQrlxEnum.NCP_QR_TYPE_JE_KCL_16.getValue()+"、"+NcpQrlxEnum.NCP_QR_TYPE_PMSE_17.getValue()+"）");
        List<NcpXsQrInvoiceReqExcel> qrlxTypeErrList = reqExcelList.stream()
                .filter(e -> !NcpQrlxEnum.NCP_QR_TYPE_JE_KCL_16.getValue().equals(e.getQrlx())
                        &&!NcpQrlxEnum.NCP_QR_TYPE_PMSE_17.getValue().equals(e.getQrlx())
                )
                .collect(Collectors.toList());
        if(qrlxTypeErrList.size()>0){
            log.info("确认类型只能选择 "+NcpQrlxEnum.NCP_QR_TYPE_JE_KCL_16.getValue()+"、"+NcpQrlxEnum.NCP_QR_TYPE_PMSE_17.getValue()+"。以下数据不符合:{}",JSON.toJSONString(qrlxTypeErrList));
            for (NcpXsQrInvoiceReqExcel item: qrlxTypeErrList){
                createErrMsg(errMap,item.getRowNum(),"确认类型错误");
            }
        }

        log.info("3.当前发票不允许重复。根据发票代码、号码查询抵账库是否存在。在系统中申请确认状态为未确认、确认失败、确认成功；且判断发票是否当前用户权限数据的。5.校验农产品部分金额是否小于等于发票金额,(申请确认，发送确认请求)的数据不让进");

        Map<String, List<NcpXsQrInvoiceReqExcel>> collect = reqExcelList.stream().collect(Collectors.groupingBy(e -> e.getFpdm() + e.getFphm()));
        collect.keySet().forEach(key -> {
            List<NcpXsQrInvoiceReqExcel> ncpDkInvoiceReqExcel = collect.get(key);
            if(ncpDkInvoiceReqExcel.size()>1){
                createErrMsg(errMap,ncpDkInvoiceReqExcel.get(0).getRowNum(),"当前请求数据中发票代码号码存在重复。代码:"+key.substring(0, 12)+"号码:"+key.substring(12, key.length()));
            }
        });

        for (NcpXsQrInvoiceReqExcel item:
                reqExcelList ) {
            String uuid = (StringUtils.isEmpty(item.getFpdm())?"":item.getFpdm()) + item.getFphm();
            TDxRecordInvoiceNcpVo tDxRecordInvoice = this.baseMapper.selectNcpXsInvoiceByUuid(uuid);
            if(ObjectUtil.isEmpty(tDxRecordInvoice)){
                createErrMsg(errMap,item.getRowNum(),"发票为非3%农产品专用发票");
                continue;
            }
            if(!gfshNcp.contains(tDxRecordInvoice.getGfsh())){
                createErrMsg(errMap,item.getRowNum(),"企业未开通农产品功能权限");
                continue;
            }
            if(!gfshAll.contains(tDxRecordInvoice.getGfsh())){
                createErrMsg(errMap,item.getRowNum(),"无发票所属税号操作权限");
                continue;
            }
            //认证处理状态  认证处理状态  0-未认证 1-已勾选未确认，2已确认 3 已发送认证 4 认证成功 5 认证失败 6已撤销认证
            String rzclzt = tDxRecordInvoice.getRzclzt();
            if("1".equals(rzclzt)||"2".equals(rzclzt)||"3".equals(rzclzt)){
                createErrMsg(errMap,item.getRowNum(),"发票已认证不允许确认");
                continue;
            }
            if(!"0".equals(tDxRecordInvoice.getDqsqqrclzt())&&!"3".equals(tDxRecordInvoice.getDqsqqrclzt())&&!"4".equals(tDxRecordInvoice.getDqsqqrclzt())){
                createErrMsg(errMap,item.getRowNum(),"发票已在确认中不允许发起确认");
                continue;
            }
            tDxRecordInvoice.setNcpbfje(item.getNcpbfje());
            String ncpfpcllx = item.getQrlx();
            if(NcpQrlxEnum.NCP_QR_TYPE_JE_KCL_16.getValue().equals(ncpfpcllx)){
                ncpfpcllx = NcpQrlxEnum.NCP_QR_TYPE_JE_KCL_16.getKey();
            }
            if(NcpQrlxEnum.NCP_QR_TYPE_PMSE_17.getValue().equals(ncpfpcllx)){
                ncpfpcllx = NcpQrlxEnum.NCP_QR_TYPE_PMSE_17.getKey();
            }
            tDxRecordInvoice.setNcpfpcllx(ncpfpcllx);
            excelToInvoiceList.add(tDxRecordInvoice);
        }
        checkExcelData.setErrMap(errMap);
        checkExcelData.setExcelToInvoiceList(excelToInvoiceList);
        return checkExcelData;
    }


    //----------------------------------------------------代开农产品部分--------------------------------------------------------------------
    /**
     * @Description 代开农产品确认-excel导入-展示给前端数据
     * @Author wangruwei
     * @Date 2023/10/11 9:29
     **/
    @Override
    public Object ncpDkInvoiceExcel(List<NcpDkInvoiceReqExcel> reqExcelList, List<String> gfshAll) {
        log.info("导入规则验证");
        JSONObject json = new JSONObject();

        for (int i = 0; i < reqExcelList.size(); i++) {
            reqExcelList.get(i).setRowNum(i+1);
        }
        //验证导入的数据是否符合验证
        CheckExcelDataRecord checkExcelDataRecord = checkDkExcelData(reqExcelList, gfshAll);
        DynamicContextHolder.push("business" + DbConstant.BUSINESS_READ);
        if(checkExcelDataRecord.getErrList().size()>0){
            json.put("code", "9999");
            json.put("msg", "保存数据不符合规范");
            json.put("errList", new TreeMap<>(checkExcelDataRecord.getErrList()));
            return super.responseResult(json);
        }

        List<TDxRecordInvoiceNcpVo> resultList = new LinkedList();
        for (int i = 0; i < checkExcelDataRecord.getExcelToInvoiceList().size(); i++) {
            TDxRecordInvoice item = checkExcelDataRecord.getExcelToInvoiceList().get(i);

            TDxRecordInvoiceNcpVo showItem = new TDxRecordInvoiceNcpVo();
            showItem.setXh((i+1)+"");
            showItem.setInvoiceCode(item.getInvoiceCode());
            showItem.setInvoiceNo(item.getInvoiceNo());
            showItem.setEleInvoiceNo(item.getEleInvoiceNo());
            showItem.setInvoiceType(dictdetaServcice.queryDictName(DictConstant.INVOICE_TYPEALL, item.getInvoiceType()));
            showItem.setInvoiceDate(DateUtils.dateToStr(item.getInvoiceDate()));
            showItem.setGfsh(item.getGfTaxNo());
            showItem.setGfmc(item.getGfName());
            showItem.setXfsh(item.getXfTaxNo());
            showItem.setXfmc(item.getXfName());
            if(ObjectUtil.isNotEmpty(item.getInvoiceAmount())){
                showItem.setInvoiceAmount(AmountFormatUtil.fmtMicrometer(MathUtil.round(item.getInvoiceAmount().toPlainString())));
            }
            if(ObjectUtil.isNotEmpty(item.getTaxAmount())){
                showItem.setTaxAmount(AmountFormatUtil.fmtMicrometer(MathUtil.round(item.getTaxAmount().toPlainString())));
            }
            if(ObjectUtil.isNotEmpty(reqExcelList.get(i).getYxdkse())){
                showItem.setYxdkse(AmountFormatUtil.fmtMicrometer(MathUtil.round(reqExcelList.get(i).getYxdkse())));
            }

            showItem.setTaxAmount(AmountFormatUtil.fmtMicrometer(MathUtil.round(item.getTaxAmount().toPlainString())));
            showItem.setTotalAmount(AmountFormatUtil.fmtMicrometer(MathUtil.round(item.getTotalAmount().toPlainString())));


            showItem.setNcpbfje(AmountFormatUtil.fmtMicrometer(MathUtil.round(reqExcelList.get(i).getNcpbfje())));
            showItem.setNcpbfse(AmountFormatUtil.fmtMicrometer(MathUtil.round(reqExcelList.get(i).getNcpbfse())));

            resultList.add(showItem);

            //底账发票
            /*TDxRecordInvoice tDxRecordInvoice = this.baseMapper.selectOne(new LambdaQueryWrapper<TDxRecordInvoice>().eq(TDxRecordInvoice::getUuid, invoiceUuid));

            //定义要生成的ncp发票表数据

            TdxInvoiceNcpEntity ncpEntity = new TdxInvoiceNcpEntity();
            ncpEntity.setInvoiceType(tDxRecordInvoice.getInvoiceType());
            ncpEntity.setInvoiceCode(tDxRecordInvoice.getInvoiceCode());
            ncpEntity.setInvoiceNo(tDxRecordInvoice.getInvoiceNo());
            ncpEntity.setEleInvoiceNo(tDxRecordInvoice.getEleInvoiceNo());
            ncpEntity.setUuid(tDxRecordInvoice.getUuid());
            ncpEntity.setInvoiceDate(tDxRecordInvoice.getInvoiceDate());
            ncpEntity.setGfTaxNo(tDxRecordInvoice.getGfTaxNo());
            ncpEntity.setGfName(tDxRecordInvoice.getGfName());
            ncpEntity.setXfTaxNo(tDxRecordInvoice.getXfTaxNo());
            ncpEntity.setXfName(tDxRecordInvoice.getXfName());
            ncpEntity.setInvoiceAmount(tDxRecordInvoice.getInvoiceAmount());
            ncpEntity.setTaxAmount(tDxRecordInvoice.getTaxAmount());
            ncpEntity.setTotalAmount(tDxRecordInvoice.getTotalAmount());
            ncpEntity.setNcpbfje(item.getNcpbfje());
            ncpEntity.setNcpbfse(item.getNcpbfse());
            ncpEntity.setYxdkse(item.getYxdkse());
            ncpEntity.setNcpfpcllx("3");
            ncpEntity.setDqsqqrclzt("1");
            ncpEntity.setQrsbyy("");
            ncpEntity.setJdqrzt("");
            ncpEntity.setJdqrlx("");
            ncpEntity.setQrr("");
            ncpEntity.setUpdateTime(new Date());
            ncpEntity.setCreateTime(new Date());
            tdxInvoiceNcpDao.insert(ncpEntity);*/
        }

        json.put("code", "0000");
        json.put("msg", "读取成功");
        json.put("data", resultList);
        return super.responseResult(json);
    }

    /**
     * @Description 代开农产品批量修改
     * @Author wangruwei
     * @Date 2023/10/16 11:29
     **/
    @Override
    public Object ncpDkInvoiceBatchUpdate(List<NcpDkInvoiceReqExcel> reqExcelList, List<String> gfshAll, UserInfo userInfo) {
        JSONObject json = new JSONObject();
        for (int i = 0; i < reqExcelList.size(); i++) {
            reqExcelList.get(i).setRowNum(i+1);
        }
        //验证钱是否正确
        CheckExcelDataRecord checkExcelDataRecord = checkDkExcelData(reqExcelList,gfshAll);
        DynamicContextHolder.push("business" + DbConstant.BUSINESS_READ);
        if(checkExcelDataRecord.getErrList().size()>0){
            json.put("code", "9999");
            json.put("msg", "保存数据不符合规范");
            json.put("errList", new TreeMap<>(checkExcelDataRecord.getErrList()));
            return json;
        }

        List<NcpXsQrInvoiceReqExcelSave> saveList = new LinkedList<>();
        for (NcpDkInvoiceReqExcel item:reqExcelList ) {
            NcpXsQrInvoiceReqExcelSave newItem = new NcpXsQrInvoiceReqExcelSave();
            BeanUtils.copyProperties(item,newItem);
            newItem.setQrlx(NcpQrlxEnum.NCP_QR_TYPE_DKNCP_3.getValue());
            saveList.add(newItem);
        }
        log.info("调统一保存方法");
        return ncpXsInvoiceQrExcelSave(saveList, gfshAll, userInfo);
    }

    @Override
    public Object ncpDkInvoiceBatchDel(List<NcpDkInvoiceReqExcel> reqExcelList, List<String> gfshAll) {
        DynamicContextHolder.push("business" + DbConstant.BUSINESS_READ);
        List<String> uuids = reqExcelList.stream().map(e -> e.getUuid()).collect(Collectors.toList());
        baseServiceTdxInvoiceNcpDao.delete(new LambdaQueryWrapper<TdxInvoiceNcpEntity>().in(TdxInvoiceNcpEntity::getUuid, uuids));
        JSONObject json = new JSONObject();
        json.put("code", "0000");
        json.put("msg", "删除成功");
        return super.responseResult(json);
    }


    /**
    * @Description 代开农产品excel验证方法
    * @Author wangruwei
    * @Date 2023/10/16 10:07
    **/
    private CheckExcelDataRecord checkDkExcelData(List<NcpDkInvoiceReqExcel> list, List<String> gfshAll) {
        CheckExcelDataRecord checkExcelData = new CheckExcelDataRecord();
        //定义触发规则的数据
        Map<Integer, String> errMap = new HashMap<>();
        List<String> gfshNcp = getGfshNcp(gfshAll);
        DynamicContextHolder.push("business" + DbConstant.BUSINESS_READ);
        log.info("1.判断发票代码号码，农产品发票金额，农产品发票税额，有效抵扣税额是否有空");
        List<NcpDkInvoiceReqExcel> jsIsNullList = list.stream().filter(e -> StringUtils.isEmpty(e.getFpdm()) || StringUtils.isEmpty(e.getFphm()) || StringUtils.isEmpty(e.getNcpbfje()) || StringUtils.isEmpty(e.getNcpbfse()) || StringUtils.isEmpty(e.getYxdkse())).collect(Collectors.toList());
        if(jsIsNullList.size()>0){
            log.info("判断发票代码号码，农产品发票金额，农产品发票税额，有效抵扣税额未填写的数据:{}", JSON.toJSONString(jsIsNullList));
            for (NcpDkInvoiceReqExcel item: jsIsNullList){
                createErrMsg(errMap,item.getRowNum(),"发票代码号码，农产品发票金额，农产品发票税额，有效抵扣税额必须填写");
            }
        }
        if(errMap.size()>0){
            checkExcelData.setErrList(errMap);
            return checkExcelData;
        }
        log.info("2.农产品发票金额，农产品发票税额，有效抵扣税额必须是数字");
        List<NcpDkInvoiceReqExcel> jsIsDoubleList = list.stream().filter(e -> MathUtil.isNumberLessTwo(e.getNcpbfje()) || MathUtil.isNumberLessTwo(e.getNcpbfse()) || MathUtil.isNumberLessTwo(e.getYxdkse())).collect(Collectors.toList());
        if(jsIsDoubleList.size()>0){
            log.info("农产品发票金额，农产品发票税额，有效抵扣税额 不是数字的数据:{}", JSON.toJSONString(jsIsDoubleList));
            for (NcpDkInvoiceReqExcel item: jsIsNullList){
                createErrMsg(errMap,item.getRowNum(),"农产品发票金额，农产品发票税额，有效抵扣税额数值格式错误，需保留两位小数");
            }
        }
        if(errMap.size()>0){
            checkExcelData.setErrList(errMap);
            return checkExcelData;
        }
        log.info("3.农产品发票金额，农产品发票税额，有效抵扣税额必须大于0");
        List<NcpDkInvoiceReqExcel> jsDyZeroList = list.stream().filter(e ->
                MathUtil.compare(e.getNcpbfje(),"0")<=0 || MathUtil.compare(e.getNcpbfse(),"0")<=0 || MathUtil.compare(e.getYxdkse(),"0")<=0).collect(Collectors.toList());
        if(jsDyZeroList.size()>0){
            log.info("农产品发票金额，农产品发票税额，有效抵扣税额 小于等于0的数据:{}", JSON.toJSONString(jsDyZeroList));
            for (NcpDkInvoiceReqExcel item: jsIsNullList){
                createErrMsg(errMap,item.getRowNum(),"农产品发票金额，农产品发票税额，有效抵扣税额必须大于0");
            }
        }

        if(errMap.size()>0){
            checkExcelData.setErrList(errMap);
            return checkExcelData;
        }

        log.info("4.有效抵扣税额 大于等于 农产品部分税额；且 农产品部分金额 小于等于 发票金额；且 农产品部分税额 小于 农产品部分金额");
        log.info("4和5在一个方法里判断，需查底账");
        log.info("5.当前请求数据不可重复。根据发票代码、号码查询抵账库是否存在。在系统中申请确认状态为未确认、确认失败；且判断发票是否当前用户权限数据的。");

        Map<String, List<NcpDkInvoiceReqExcel>> collect = list.stream().collect(Collectors.groupingBy(e -> e.getFpdm() + e.getFphm()));
        collect.keySet().forEach(key -> {
            List<NcpDkInvoiceReqExcel> ncpDkInvoiceReqExcel = collect.get(key);
            if(ncpDkInvoiceReqExcel.size()>1){
                createErrMsg(errMap,ncpDkInvoiceReqExcel.get(0).getRowNum(),"当前请求数据中发票代码号码存在重复。代码:"+key.substring(0, 12)+"号码:"+key.substring(12, key.length()));
            }
        });


        List<TDxRecordInvoice> recordlist = new LinkedList();
        for (NcpDkInvoiceReqExcel item:
                list ) {
            String uuid = (StringUtils.isEmpty(item.getFpdm())?"":item.getFpdm()) + item.getFphm();
            TDxRecordInvoice tDxRecordInvoice = this.baseMapper.selectOne(new LambdaQueryWrapper<TDxRecordInvoice>().eq(TDxRecordInvoice::getUuid, uuid));
            if(ObjectUtil.isEmpty(tDxRecordInvoice)){
                createErrMsg(errMap,item.getRowNum(),"发票不存在");
                continue;
            }

            if(MathUtil.compare(item.getYxdkse(),item.getNcpbfse())<0 || MathUtil.compare(item.getNcpbfje(),tDxRecordInvoice.getInvoiceAmount().toPlainString())>0 || MathUtil.compare(item.getNcpbfse(),item.getNcpbfje())>=0){
                createErrMsg(errMap,item.getRowNum(),"有效抵扣税额需 大于等于 农产品部分税额；且 农产品部分金额需 小于等于 发票金额；且 农产品部分税额需 小于 农产品部分金额");
                continue;
            }
            if(!gfshNcp.contains(tDxRecordInvoice.getGfTaxNo())){
                createErrMsg(errMap,item.getRowNum(),"企业未开通农产品功能权限");
                continue;
            }
            if(!gfshAll.contains(tDxRecordInvoice.getGfTaxNo())){
                createErrMsg(errMap,item.getRowNum(),"无发票所属税号操作权限");
                continue;
            }

            log.info("条件需满足 xf_tax_no like '%DK%' and invoice_status in ('0','7') and lq_hzsdbs = 'N' and glzt = '0' and auth_status in ('0','5','6')");

            if(!tDxRecordInvoice.getXfTaxNo().contains("DK")){
                createErrMsg(errMap,item.getRowNum(),"发票为非代开发票");
            }
            if(!Arrays.asList("0","7").contains(tDxRecordInvoice.getInvoiceStatus())
                    ||!"N".equals(tDxRecordInvoice.getLqHzsdbs())
            ){
                createErrMsg(errMap,item.getRowNum(),"发票状态异常");
            }

            if(!"0".equals(tDxRecordInvoice.getGlzt())){
                createErrMsg(errMap,item.getRowNum(),"发票管理状态异常");
            }

            if(!Arrays.asList("0","5","6").contains(tDxRecordInvoice.getAuthStatus())){
                createErrMsg(errMap,item.getRowNum(),"发票已认证不允许再次确认");
            }

            if(MathUtil.compare(tDxRecordInvoice.getInvoiceAmount().toPlainString(),"0")<0){
                createErrMsg(errMap,item.getRowNum(),"负数发票不允许确认");
            }

            //查询农产品表
            TDxRecordInvoiceNcpVo ncpVo = this.baseMapper.selectNcpXsInvoiceByUuid(uuid);
            if(ObjectUtil.isNotEmpty(ncpVo)){
                if(!"3".equals(ncpVo.getDqsqqrclzt())){
                    createErrMsg(errMap,item.getRowNum(),"确认列表已存在");
                }
            }

            recordlist.add(tDxRecordInvoice);
        }
        checkExcelData.setErrList(errMap);
        checkExcelData.setExcelToInvoiceList(recordlist);

        return checkExcelData;
    }


}
