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

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.dxhy.api.model.custom.TDxExportCustoms;
import com.dxhy.api.model.custom.TdxCustomsRecord;
import com.dxhy.api.model.db.TdxRecordInvoiceEntity;
import com.dxhy.api.model.dkdj.TdxZzsDkdjwspzEntity;
import com.dxhy.api.model.invoice.TDxExportInvoice;
import com.dxhy.api.model.ncp.ncpJjkcInvoice.TDxRecordInvoiceNcpJjkcVo;
import com.dxhy.api.model.rz.rzCustom.JkszhcxRespVO;
import com.dxhy.common.constant.DictConstant;
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.util.StringHelper;
import com.dxhy.common.utils.DateUtils;
import com.dxhy.core.dao.TDxExportCustomsDao;
import com.dxhy.core.dao.TDxExportInvoiceDao;
import com.dxhy.core.model.dkCountVo.DkCountCustomsRecordVo;
import com.dxhy.core.model.dkCountVo.DkCountExportInvoiceVo;
import com.dxhy.core.model.dkCountVo.DkCountTDxExportCustoms;
import com.dxhy.core.model.dkCountVo.DkCountZzsDkdjwspzVo;
import com.dxhy.core.service.export.DkCountExportService;
import com.dxhy.customs.dao.CustomsRecordDao;
import com.dxhy.dkdj.dao.DkdjDao;
import com.dxhy.extend.dao.ExtRzjgqdDao;
import com.dxhy.extend.model.ExtRzjgqdRespVO;
import com.dxhy.jxpt.baseService.dao.TdxRecordInvoiceDao;
import com.dxhy.jxpt.baseService.ncpInvoice.dao.NcpJjkcCustomsDao;
import com.dxhy.jxpt.baseService.ncpInvoice.dao.NcpJjkcRecordInvoiceDao;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * @Description 抵扣统计-各项明细导出
 * @Author wangruwei
 * @Date 2024年8月22日14:43:54
 **/
@SuppressWarnings("AlibabaMethodTooLong")
@Service("dkCountExportService")
@Slf4j
public class DkCountExportServiceImpl extends MpBaseServiceImpl<TdxRecordInvoiceDao, TdxRecordInvoiceEntity> implements DkCountExportService {

    @Resource
    private DictdetaServcice dictdetaServcice;

    @Resource
    private ExtRzjgqdDao extRzjgqdDao;

    @Resource
    private CustomsRecordDao customsRecordDao;

    @Resource
    private DkdjDao dkdjDao;

    @Resource
    private NcpJjkcRecordInvoiceDao ncpJjkcRecordInvoiceDao;

    @Resource
    private NcpJjkcCustomsDao ncpJjkcCustomsDao;

    @Resource
    private TDxExportInvoiceDao tDxExportInvoiceDao;

    @Resource
    private TDxExportCustomsDao tDxExportCustomsDao;

    /**
     * @Description 查询发票sheet
     * @Author wangruwei
     * @Date 2024/8/22 14:56
     **/
    @Override
    public JSONObject selectFpByPramsMap(Map<String, Object> pramsMap, int curr, int size) {
        JSONObject json = new JSONObject();
        log.info("查询发票sheet");
        try {
            PageHelper.startPage(curr, size);
            List<ExtRzjgqdRespVO> pageList = extRzjgqdDao.rzjgByGfshAndSkssq(pramsMap);
            PageInfo<ExtRzjgqdRespVO> pageInfo = new PageInfo<>(pageList);
            List<ExtRzjgqdRespVO> resultList = pageInfo.getList();
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());

            if (resultList != null && resultList.size() > 0) {
                int start = (int)pageInfo.getStartRow();
                for (int i = 0; i < resultList.size(); i++) {
                    if (!StringHelper.isBlank(resultList.get(i).getJe())) {
                        resultList.get(i).setJe(AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getJe())));
                    }
                    if (!StringHelper.isBlank(resultList.get(i).getSe())) {
                        resultList.get(i).setSe(AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getSe())));
                    }
                    if (StringUtils.isNotBlank(resultList.get(i).getDkse())) {
                        resultList.get(i)
                                .setDkse(AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getDkse())));
                    } else {
                        if(StringUtils.isNotEmpty(resultList.get(i).getSe())){
                            resultList.get(i).setDkse(resultList.get(i).getSe());
                        }

                    }
                    //字典值转换
                    String fplx = resultList.get(i).getFplx();
                    resultList.get(i).setFplx(dictdetaServcice.queryDictName(DictConstant.INVOICE_TYPEALL,fplx));
                    String dklx = resultList.get(i).getDklx();
                    resultList.get(i).setDklx(dictdetaServcice.queryDictName(DictConstant.FPDK_TYPE,dklx));

                    String glzt = resultList.get(i).getGlzt();
                    resultList.get(i).setGlzt(dictdetaServcice.queryDictName(DictConstant.GLZT, glzt));

                    //特定要素
                    if(StringUtils.isBlank(resultList.get(i).getLqTdyslxDm())){
                        resultList.get(i)
                                .setLqTdyslxDm("非特定业务");
                    }else{
                        resultList.get(i)
                                .setLqTdyslxDm(dictdetaServcice.queryDictName(DictConstant.TDYS_LXDM, resultList.get(i).getLqTdyslxDm()));
                    }

                    String invoiceStatus = resultList.get(i).getInvoiceStatus();
                    resultList.get(i).setInvoiceStatus(dictdetaServcice.queryDictName(DictConstant.INVOICE_STATUS, invoiceStatus));
                    String lqHzsdbs = resultList.get(i).getLqHzsdbs();
                    resultList.get(i).setLqHzsdbs(dictdetaServcice.queryDictName(DictConstant.HZSDZT, lqHzsdbs));
                    String lqCpyycbs = resultList.get(i).getLqCpyycbs();
                    resultList.get(i).setLqCpyycbs(dictdetaServcice.queryDictName(DictConstant.CPY_YCBS, lqCpyycbs));
                    String lqJdcycbs = resultList.get(i).getLqJdcycbs();
                    resultList.get(i).setLqJdcycbs(dictdetaServcice.queryDictName(DictConstant.JDC_YCBS, lqJdcycbs));
                    resultList.get(i).setRzlx(dictdetaServcice.queryDictName(DictConstant.INVOICE_RZLX, resultList.get(i).getRzlx()));

                    resultList.get(i).setXh(String.valueOf(start + i));
                }
                // 设置记录总数
                json.put("total", pageInfo.getTotal());
                json.put("datalist", resultList);
            }
        } catch (Exception e) {
            // 统一设置操作异常标识
            json = super.errorResult(e);
        }

        return json;
    }

    /**
     * @Description 查询缴款书sheet
     * @Author wangruwei
     * @Date 2024/8/22 14:56
     **/
    @Override
    public JSONObject selectHgjksByPramsMap(Map<String, Object> pramsMap, int curr, int size) {
        JSONObject json = new JSONObject();
        log.info("查询缴款书sheet");
        try {
            PageHelper.startPage(curr, size);
            List<TdxCustomsRecord> tdxCustomsRecords = customsRecordDao.selectList(new LambdaQueryWrapper<TdxCustomsRecord>()
                    .eq(TdxCustomsRecord::getCompany, pramsMap.get("company"))
                    .eq(TdxCustomsRecord::getGfTaxNo, pramsMap.get("gfsh"))
                    .eq(TdxCustomsRecord::getRzhBelongDate, pramsMap.get("skssq"))
                    .eq(TdxCustomsRecord::getRzlx, pramsMap.get("rzlx"))
                    .eq(TdxCustomsRecord::getAuthStatus, "4")
            );
            PageInfo<TdxCustomsRecord> pageInfo = new PageInfo<>(tdxCustomsRecords);
            List<TdxCustomsRecord> resultList = pageInfo.getList();
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());

            if (resultList != null && resultList.size() > 0) {
                int start = (int)pageInfo.getStartRow();
                List<DkCountCustomsRecordVo> showlist = new LinkedList();
                for (int i = 0; i < resultList.size(); i++) {
                    DkCountCustomsRecordVo item = new DkCountCustomsRecordVo();
                    BeanUtils.copyProperties(resultList.get(i), item);
                    if (!StringHelper.isBlank(item.getTaxAmount())) {
                        item.setTaxAmount(AmountFormatUtil.fmtMicrometer(MathUtil.round(item.getTaxAmount())));
                    }
                    if (!StringHelper.isBlank(item.getYxTaxAmount())) {
                        item.setYxTaxAmount(AmountFormatUtil.fmtMicrometer(MathUtil.round(item.getYxTaxAmount())));
                    }
                    item.setRzlx(dictdetaServcice.queryDictName(DictConstant.INVOICE_RZLX, item.getRzlx()));

                    item.setFillInDateShow(item.getFillInDate() == null ? "" : DateUtils.dateToStr(item.getFillInDate()));
                    item.setRzhDateShow(item.getRzhDate() == null ? "" : DateUtils.dateToStr(item.getRzhDate()));

                    item.setXh(String.valueOf(start + i));
                    showlist.add(item);
                }
                // 设置记录总数
                json.put("total", pageInfo.getTotal());
                json.put("datalist", showlist);
            }
        } catch (Exception e) {
            // 统一设置操作异常标识
            json = super.errorResult(e);
        }

        return json;
    }

    /**
     * @Description 代扣代缴sheet
     * @Author wangruwei
     * @Date 2024/8/22 14:56
     **/
    @Override
    public JSONObject selectDkdjByPramsMap(Map<String, Object> pramsMap, int curr, int size) {
        JSONObject json = new JSONObject();
        log.info("代扣代缴sheet");
        try {
            PageHelper.startPage(curr, size);
            String gfsh = pramsMap.get("gfsh").toString();
            pramsMap.put("kjywrsbh", Arrays.asList(gfsh));
            pramsMap.put("rzssq", pramsMap.get("skssq").toString());
            pramsMap.put("rzzt", "1");
            pramsMap.put("rzclzt", pramsMap.get("authStatus").toString());
            pramsMap.put("rzlx", "01");
            /**
             * rzzt  1  rzlx 01   rzclzt  4
             * rzzt  认证状态：0未认证，1认证抵扣，2认证不抵扣
             * rzlx 认证类型：01申请抵扣，02撤销抵扣，03申请不抵扣，04撤销不抵扣
             * rzclzt 认证处理状态：0未申请，1申请认证，2发送申请认证请求，3申请认证失败，4申请认证成功，5申请撤销，6发送撤销请求，7撤销失败，8，撤销成功
             **/

            List<TdxZzsDkdjwspzEntity> pageList = dkdjDao.selectDkdjAuthPageList(pramsMap);
            PageInfo<TdxZzsDkdjwspzEntity> pageInfo = new PageInfo<>(pageList);
            List<TdxZzsDkdjwspzEntity> resultList = pageInfo.getList();
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());

            if (resultList != null && resultList.size() > 0) {
                int start = (int)pageInfo.getStartRow();
                List<DkCountZzsDkdjwspzVo> showlist = new LinkedList();
                for (int i = 0; i < resultList.size(); i++) {
                    DkCountZzsDkdjwspzVo item = new DkCountZzsDkdjwspzVo();
                    BeanUtils.copyProperties(resultList.get(i), item);

                    item.setXh(String.valueOf(start + i));

                    if (!StringHelper.isBlank(item.getJsje())) {
                        item.setJsje(AmountFormatUtil.fmtMicrometer(MathUtil.round(item.getJsje())));
                    }
                    if (!StringHelper.isBlank(item.getSjje())) {
                        item.setSjje(AmountFormatUtil.fmtMicrometer(MathUtil.round(item.getSjje())));
                    }
                    if (!StringHelper.isBlank(item.getYxse())) {
                        item.setYxse(AmountFormatUtil.fmtMicrometer(MathUtil.round(item.getYxse())));
                    }
                    if(ObjectUtil.isNotEmpty(item.getRzsj())&&item.getRzsj().length()>=10){
                        item.setRzsjShow(item.getRzsj().substring(0,10));
                    }
                    item.setTfrqShow(item.getTfrq() == null ? "" : DateUtils.dateToStr(item.getTfrq()));
                    item.setRzlx(dictdetaServcice.queryDictName(DictConstant.DKDJ_RZLX, item.getRzlx()));
                    showlist.add(item);
                }
                // 设置记录总数
                json.put("total", pageInfo.getTotal());
                json.put("datalist", showlist);
            }
        } catch (Exception e) {
            // 统一设置操作异常标识
            json = super.errorResult(e);
        }

        return json;
    }

    /**
     * @Description 农产品加计扣除发票sheet
     * @param pramsMap
     * @param curr
     * @Return boolean
     * @Author wangruwei
     * @Date 2024/8/22 14:55
     **/
    @Override
    public JSONObject selectJjkcFpByPramsMap(Map<String, Object> pramsMap, int curr, int size) {
        log.info("农产品加计扣除发票sheet");
        JSONObject json = new JSONObject();
        try {
            PageHelper.startPage(curr, size);
            pramsMap.put("gfsh", Arrays.asList(pramsMap.get("gfsh")));
            pramsMap.put("clzt", "4");
            pramsMap.put("sqlx", "18");
            List<TDxRecordInvoiceNcpJjkcVo> pageList = ncpJjkcRecordInvoiceDao.selectNcpJjkcResultList(pramsMap);
            PageInfo<TDxRecordInvoiceNcpJjkcVo> pageInfo = new PageInfo<>(pageList);
            List<TDxRecordInvoiceNcpJjkcVo> resultList = pageInfo.getList();
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());

            if (resultList != null && resultList.size() > 0) {
                int start = (int)pageInfo.getStartRow();
                for (int i = 0; i < resultList.size(); i++) {
                    resultList.get(i).setXh(String.valueOf(start + i));

                    if (!StringHelper.isBlank(resultList.get(i).getInvoiceAmount())) {
                        resultList.get(i).setInvoiceAmount(AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getInvoiceAmount())));
                    }
                    if (!StringHelper.isBlank(resultList.get(i).getKjjkcse())) {
                        resultList.get(i).setKjjkcse(AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getKjjkcse())));
                    }
                    if (!StringHelper.isBlank(resultList.get(i).getBcjjkcse())) {
                        resultList.get(i).setBcjjkcse(AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getBcjjkcse())));
                    }
                    if (!StringHelper.isBlank(resultList.get(i).getSykjjkcse())) {
                        resultList.get(i).setSykjjkcse(AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getSykjjkcse())));
                    }

                    resultList.get(i).setInvoiceType(dictdetaServcice.queryDictName(DictConstant.INVOICE_TYPEALL, resultList.get(i).getInvoiceType()));
                    //特定要素
                    if(StringUtils.isBlank(resultList.get(i).getLqTdyslxDm())){
                        resultList.get(i)
                                .setLqTdyslxDm("非特定业务");
                    }else{
                        resultList.get(i)
                                .setLqTdyslxDm(dictdetaServcice.queryDictName(DictConstant.TDYS_LXDM, resultList.get(i).getLqTdyslxDm()));
                    }
                    resultList.get(i).setSqlx(dictdetaServcice.queryDictName(DictConstant.NCPJJKC_SQLX, resultList.get(i).getSqlx()));
                    resultList.get(i).setInvoiceStatus(dictdetaServcice.queryDictName(DictConstant.INVOICE_STATUS, resultList.get(i).getInvoiceStatus()));
                    resultList.get(i).setGlzt(dictdetaServcice.queryDictName(DictConstant.GLZT, resultList.get(i).getGlzt()));
                    resultList.get(i).setLqHzsdbs(dictdetaServcice.queryDictName(DictConstant.HZSDZT, resultList.get(i).getLqHzsdbs()));
                    resultList.get(i).setLqCpyycbs(dictdetaServcice.queryDictName(DictConstant.CPY_YCBS, resultList.get(i).getLqCpyycbs()));
                    resultList.get(i).setLqJdcycbs(dictdetaServcice.queryDictName(DictConstant.JDC_YCBS, resultList.get(i).getLqJdcycbs()));
                }
                // 设置记录总数
                json.put("total", pageInfo.getTotal());
                json.put("datalist", resultList);
            }
        } catch (Exception e) {
            // 统一设置操作异常标识
            json = super.errorResult(e);
        }

        return json;
    }

    /**
     * @Description 农产品加计扣除缴款书sheet
     * @Author wangruwei
     * @Date 2024/8/22 14:56
     **/
    @Override
    public JSONObject selectJjkcJksByPramsMap(Map<String, Object> pramsMap, int curr, int size) {
        JSONObject json = new JSONObject();
        log.info("农产品加计扣除缴款书sheet");
        try {
            PageHelper.startPage(curr, size);
            pramsMap.put("gfsh", Arrays.asList(pramsMap.get("gfsh")));
            pramsMap.put("clzt", "4");
            pramsMap.put("sqlx", "18");
            List<JkszhcxRespVO> pageList = ncpJjkcCustomsDao.selectResultByPramsMap(pramsMap);
            PageInfo<JkszhcxRespVO> pageInfo = new PageInfo<>(pageList);
            List<JkszhcxRespVO> resultList = pageInfo.getList();
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());

            if (resultList != null && resultList.size() > 0) {
                int start = (int)pageInfo.getStartRow();
                for (int i = 0; i < resultList.size(); i++) {
                    resultList.get(i).setXh(String.valueOf(start + i));

                    if (!StringHelper.isBlank(resultList.get(i).getTaxAmount())) {
                        resultList.get(i).setTaxAmount(AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getTaxAmount())));
                    }
                    if (!StringHelper.isBlank(resultList.get(i).getKjjkcse())) {
                        resultList.get(i).setKjjkcse(AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getKjjkcse())));
                    }
                    if (!StringHelper.isBlank(resultList.get(i).getBcjjkcse())) {
                        resultList.get(i).setBcjjkcse(AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getBcjjkcse())));
                    }
                    if (!StringHelper.isBlank(resultList.get(i).getSykjjkcse())) {
                        resultList.get(i).setSykjjkcse(AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getSykjjkcse())));
                    }

                    resultList.get(i).setSqlx(dictdetaServcice.queryDictName(DictConstant.NCPJJKC_SQLX, resultList.get(i).getSqlx()));
                }
                // 设置记录总数
                json.put("total", pageInfo.getTotal());
                json.put("datalist", resultList);
            }
        } catch (Exception e) {
            // 统一设置操作异常标识
            json = super.errorResult(e);
        }

        return json;
    }

    /**
     * @Description 出口转内销发票sheet
     * @Author wangruwei
     * @Date 2024/8/22 14:56
     **/
    @Override
    public JSONObject selectCkznxFpByPramsMap(Map<String, Object> pramsMap, int curr, int size) {
        log.info("出口转内销发票sheet");
        JSONObject json = new JSONObject();
        try {
            PageHelper.startPage(curr, size);
            List<TDxExportInvoice> pageList = tDxExportInvoiceDao.selectList(new LambdaQueryWrapper<TDxExportInvoice>()
                    .eq(TDxExportInvoice::getCompany, pramsMap.get("company"))
                    .eq(TDxExportInvoice::getGfTaxNo, pramsMap.get("gfsh"))
                    .eq(TDxExportInvoice::getRzhBelongDate, pramsMap.get("skssq"))
                    .eq(TDxExportInvoice::getRzlx, pramsMap.get("rzlx"))
                    .eq(TDxExportInvoice::getAuthStatus, pramsMap.get("authStatus"))
            );
            PageInfo<TDxExportInvoice> pageInfo = new PageInfo<>(pageList);
            List<TDxExportInvoice> resultList = pageInfo.getList();
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());

            if (resultList != null && resultList.size() > 0) {
                int start = (int)pageInfo.getStartRow();
                List<DkCountExportInvoiceVo> showList = new LinkedList();
                for (int i = 0; i < resultList.size(); i++) {
                    DkCountExportInvoiceVo item = new DkCountExportInvoiceVo();
                    BeanUtils.copyProperties(resultList.get(i),item);

                    item.setXh(String.valueOf(start + i));

                    if (!StringHelper.isBlank(item.getExportAmount())) {
                        item.setExportAmount(AmountFormatUtil.fmtMicrometer(MathUtil.round(item.getExportAmount())));
                    }
                    if (!StringHelper.isBlank(item.getExportTaxAmount())) {
                        item.setExportTaxAmount(AmountFormatUtil.fmtMicrometer(MathUtil.round(item.getExportTaxAmount())));
                    }
                    if (!StringHelper.isBlank(item.getExportYxse())) {
                        item.setExportYxse(AmountFormatUtil.fmtMicrometer(MathUtil.round(item.getExportYxse())));
                    }

                    item.setInvoiceType(dictdetaServcice.queryDictName(DictConstant.INVOICE_TYPEALL, item.getInvoiceType()));
                    item.setRzlx(dictdetaServcice.queryDictName(DictConstant.INVOICE_RZLX, item.getRzlx()));

                    item.setInvoiceDateShow(item.getInvoiceDate() == null ? "" : DateUtils.dateToStr(item.getInvoiceDate()));
                    item.setRzhDateShow(item.getRzhDate() == null ? "" : DateUtils.dateToStr(item.getRzhDate()));

                    showList.add(item);
                }
                // 设置记录总数
                json.put("total", pageInfo.getTotal());
                json.put("datalist", showList);
            }
        } catch (Exception e) {
            // 统一设置操作异常标识
            json = super.errorResult(e);
        }

        return json;
    }

    /**
     * @Description 出口转内销缴款书sheet
     * @Author wangruwei
     * @Date 2024/8/22 14:56
     **/
    @Override
    public JSONObject selectCkznxJksByPramsMap(Map<String, Object> pramsMap, int curr, int size) {
        log.info("出口转内销缴款书sheet");
        JSONObject json = new JSONObject();
        try {
            PageHelper.startPage(curr, size);
            List<TDxExportCustoms> pageList = tDxExportCustomsDao.selectList(new LambdaQueryWrapper<TDxExportCustoms>()
                .eq(TDxExportCustoms::getCompany, pramsMap.get("company"))
                .eq(TDxExportCustoms::getGfTaxNo, pramsMap.get("gfsh"))
                .eq(TDxExportCustoms::getRzhBelongDate, pramsMap.get("skssq"))
                .eq(TDxExportCustoms::getRzlx, pramsMap.get("rzlx"))
                .eq(TDxExportCustoms::getAuthStatus, pramsMap.get("authStatus"))
            );
            PageInfo<TDxExportCustoms> pageInfo = new PageInfo<>(pageList);
            List<TDxExportCustoms> resultList = pageInfo.getList();
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());

            if (resultList != null && resultList.size() > 0) {
                int start = (int)pageInfo.getStartRow();
                List<DkCountTDxExportCustoms> showlist = new LinkedList();
                for (int i = 0; i < resultList.size(); i++) {
                    DkCountTDxExportCustoms item = new DkCountTDxExportCustoms();
                    BeanUtils.copyProperties(resultList.get(i), item);

                    item.setXh(String.valueOf(start + i));

                    if (!StringHelper.isBlank(item.getExportTaxAmount())) {
                        item.setExportTaxAmount(AmountFormatUtil.fmtMicrometer(MathUtil.round(item.getExportTaxAmount())));
                    }
                    if (!StringHelper.isBlank(item.getYxExportTaxAmount())) {
                        item.setYxExportTaxAmount(AmountFormatUtil.fmtMicrometer(MathUtil.round(item.getYxExportTaxAmount())));
                    }

                    item.setRzlx(dictdetaServcice.queryDictName(DictConstant.INVOICE_RZLX, item.getRzlx()));

                    item.setFillInDateShow(item.getFillInDate() == null ? "" : DateUtils.dateToStr(item.getFillInDate()));
                    item.setRzhDateShow(item.getRzhDate() == null ? "" : DateUtils.dateToStr(item.getRzhDate()));

                    showlist.add(item);
                }
                // 设置记录总数
                json.put("total", pageInfo.getTotal());
                json.put("datalist", showlist);
            }
        } catch (Exception e) {
            // 统一设置操作异常标识
            json = super.errorResult(e);
        }

        return json;
    }

    /**
     * @Description 异常发票sheet
     * @Author wangruwei
     * @Date 2024/8/22 14:56
     **/
    @Override
    public JSONObject selectYcFpByPramsMap(Map<String, Object> pramsMap, int curr, int size) {
        log.info("异常发票sheet");
        JSONObject json = new JSONObject();

        try {
            PageHelper.startPage(curr, size);
            pramsMap.put("ycfpFlag","show");
            List<ExtRzjgqdRespVO> pageList = extRzjgqdDao.rzjgByGfshAndSkssq(pramsMap);
            PageInfo<ExtRzjgqdRespVO> pageInfo = new PageInfo<>(pageList);
            List<ExtRzjgqdRespVO> resultList = pageInfo.getList();
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());

            if (resultList != null && resultList.size() > 0) {
                int start = (int)pageInfo.getStartRow();
                for (int i = 0; i < resultList.size(); i++) {
                    if (!StringHelper.isBlank(resultList.get(i).getJe())) {
                        resultList.get(i).setJe(AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getJe())));
                    }
                    if (!StringHelper.isBlank(resultList.get(i).getSe())) {
                        resultList.get(i).setSe(AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getSe())));
                    }
                    if (StringUtils.isNotBlank(resultList.get(i).getDkse())) {
                        resultList.get(i)
                                .setDkse(AmountFormatUtil.fmtMicrometer(MathUtil.round(resultList.get(i).getDkse())));
                    } else {
                        if(StringUtils.isNotEmpty(resultList.get(i).getSe())){
                            resultList.get(i).setDkse(resultList.get(i).getSe());
                        }

                    }
                    //字典值转换
                    String fplx = resultList.get(i).getFplx();
                    resultList.get(i).setFplx(dictdetaServcice.queryDictName(DictConstant.INVOICE_TYPEALL,fplx));
                    String dklx = resultList.get(i).getDklx();
                    resultList.get(i).setDklx(dictdetaServcice.queryDictName(DictConstant.FPDK_TYPE,dklx));

                    String glzt = resultList.get(i).getGlzt();
                    resultList.get(i).setGlzt(dictdetaServcice.queryDictName(DictConstant.GLZT, glzt));

                    //特定要素
                    if(StringUtils.isBlank(resultList.get(i).getLqTdyslxDm())){
                        resultList.get(i)
                                .setLqTdyslxDm("非特定业务");
                    }else{
                        resultList.get(i)
                                .setLqTdyslxDm(dictdetaServcice.queryDictName(DictConstant.TDYS_LXDM, resultList.get(i).getLqTdyslxDm()));
                    }

                    String invoiceStatus = resultList.get(i).getInvoiceStatus();
                    resultList.get(i).setInvoiceStatus(dictdetaServcice.queryDictName(DictConstant.INVOICE_STATUS, invoiceStatus));
                    String lqHzsdbs = resultList.get(i).getLqHzsdbs();
                    resultList.get(i).setLqHzsdbs(dictdetaServcice.queryDictName(DictConstant.HZSDZT, lqHzsdbs));
                    String lqCpyycbs = resultList.get(i).getLqCpyycbs();
                    resultList.get(i).setLqCpyycbs(dictdetaServcice.queryDictName(DictConstant.CPY_YCBS, lqCpyycbs));
                    String lqJdcycbs = resultList.get(i).getLqJdcycbs();
                    resultList.get(i).setLqJdcycbs(dictdetaServcice.queryDictName(DictConstant.JDC_YCBS, lqJdcycbs));
                    resultList.get(i).setRzlx(dictdetaServcice.queryDictName(DictConstant.INVOICE_RZLX, resultList.get(i).getRzlx()));

                    resultList.get(i).setXh(String.valueOf(start + i));
                }
                // 设置记录总数
                json.put("total", pageInfo.getTotal());
                json.put("datalist", resultList);
            }
        } catch (Exception e) {
            // 统一设置操作异常标识
            json = super.errorResult(e);
        }

        return json;
    }


}
