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

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import lombok.Data;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.dxhy.common.constant.DbConstant;
import com.dxhy.common.constant.DictConstant;
import com.dxhy.common.datasource.config.DynamicContextHolder;
import com.dxhy.common.enums.*;
import com.dxhy.common.service.DictdetaServcice;
import com.dxhy.common.service.impl.MpBaseServiceImpl;
import com.dxhy.common.util.AmountFormatUtil;
import com.dxhy.common.vo.DictdetaModel;
import com.dxhy.core.dao.ConfirmDao;
import com.dxhy.core.dao.CustomsCollectDao;
import com.dxhy.core.dao.TDxExportCustomsDao;
import com.dxhy.core.dao.TDxExportInvoiceDao;
import com.dxhy.core.job.entity.TAcOrg;
import com.dxhy.core.model.*;
import com.dxhy.core.service.export.ICustomsCollectService;
import com.dxhy.core.util.ObjectUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import lombok.extern.slf4j.Slf4j;

/**
 * 海关缴款书发票采集业务处理接口
 *
 * @author user
 */
@SuppressWarnings({"AlibabaUndefineMagicConstant", "DuplicatedCode"})
@Service("customsCollectService")
@Slf4j

public class CustomsCollectServiceImpl extends MpBaseServiceImpl<CustomsCollectDao, CustomsCollectVO>
    implements ICustomsCollectService {

    @Resource
    private TDxExportInvoiceDao tDxExportInvoiceDao;

    @Resource
    private TDxExportCustomsDao tDxExportCustomsDao;
    @Resource
    private ConfirmDao confirmDao;
    @Resource
    private DictdetaServcice dictdetaServcice;

    @Override
    public JSONObject queryCollect(Map<String, Object> pramsMap, int curr, int size) {
        JSONObject json = new JSONObject();

        List<String> gfTaxNoList = (List<String>)pramsMap.get("gfTaxNoList");

        if (gfTaxNoList.size() == 0) {
            // 未从getUserInfo()获取到购方税号信息
            json.put("number", "0");
            json.put("taxAmountSum", "0");
            json.put("total", "0");
            json.put("datalist", new ArrayList<CustomsCollectVO>());
        } else {
            DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);
            // 合计信息,仅第一页时需要统计，减少数据库压力
            if (curr == 1) {
                String number = "0";
                String taxAmountSum = "0";
                Map<String, Object> data = super.baseMapper.sumTaxAmount(pramsMap);

                number = ObjectUtil.fixNull(data.get("number"));
                if (!"0".equals(number)) {
                    taxAmountSum = AmountFormatUtil.fmtMicrometer(ObjectUtil.fixNull(data.get("taxAmountSum")));
                }
                json.put("taxAmountSum", taxAmountSum);
                json.put("number", number);
            }

            // 查询发票上的购方信息

            PageHelper.startPage(curr, size);
            List<CustomsCollectVO> pageList = super.baseMapper.queryCollect(pramsMap);
            PageInfo<CustomsCollectVO> pageInfo = new PageInfo<>(pageList);
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());
            DynamicContextHolder.push(DbConstant.BASICS_READ);
            List<TAcOrg> orgList = confirmDao.getTaxno();
            // 用于页面展示
            List<CustomsCollectVO> resultList = pageInfo.getList();
            if (resultList != null && resultList.size() > 0) {
                int i = 1;
                for (CustomsCollectVO vo : resultList) {
                    vo.setIndex(String.valueOf((curr - 1) * size + i));
                    vo.setTaxSum(AmountFormatUtil.fmtMicrometer((vo.getTaxSum())));
                    for (TAcOrg org : orgList) {
                        if (org.getTaxno().equals(vo.getGfTaxNo())) {
                            vo.setGfName(org.getTaxname());
                        }
                    }
                    i++;
                }
            }
            json.put("datalist", resultList);
        }

        return json;
    }

    @Override
    public JSONObject queryInsertCustoms(Map<String, Object> pramsMap, int curr, int size) {

        JSONObject json = new JSONObject();

        List<String> gfTaxNoList = (List<String>)pramsMap.get("gfTaxNoList");

        if (gfTaxNoList.size() == 0) {
            // 未从getUserInfo()获取到购方税号信息
            json.put("number", "0");
            json.put("taxAmountSum", "0");
            json.put("total", "0");
            json.put("datalist", new ArrayList<CustomsCollectVO>());
        } else {
            DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);
            // 合计信息,仅第一页时需要统计，减少数据库压力
            if (curr == 1) {
                String number = "0";
                String taxAmountSum = "0";
                pramsMap.put("insertFlag", "1");
                Map<String, Object> data = super.baseMapper.sumTaxAmount(pramsMap);

                log.info("data======>{}", data);
                number = ObjectUtil.fixNull(data.get("number"));
                taxAmountSum = AmountFormatUtil.fmtMicrometer(ObjectUtil.fixNull(data.get("taxAmountSum")));
                json.put("taxAmountSum", taxAmountSum);
                json.put("number", number);
            }

            // 查询发票上的购方信息

            PageHelper.startPage(curr, size);
            List<CustomsCollectVO> pageList = super.baseMapper.queryInsertCustoms(pramsMap);
            log.info("pageList=======>{}",pageList);
            PageInfo<CustomsCollectVO> pageInfo = new PageInfo<>(pageList);
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());

            // 用于页面展示
            List<CustomsCollectVO> resultList = pageInfo.getList();
            if (resultList != null && resultList.size() > 0) {
                // List<DictdetaModel> jhModels = dictdetaServcice.selectDictdeta("AUDIT_STATUS");
                // List<DictdetaModel> sqhdModels = dictdetaServcice.selectDictdeta("APPLY_CHECK");
                // List<DictdetaModel> hcjgModels = dictdetaServcice.selectDictdeta("CHECK_STATUS");
                // List<DictdetaModel> cjfsModels = dictdetaServcice.selectDictdeta("JKSCJFS");
                List<DictdetaModel> sbyyModels = dictdetaServcice.selectDictdeta("JKSSCSBYY");
                // List<DictdetaModel> scztModels = dictdetaServcice.selectDictdeta("JKSSCZT");
                int i = 1;
                for (CustomsCollectVO vo : resultList) {
                    vo.setIndex(String.valueOf((curr - 1) * size + i));
                    vo.setTaxAmount(AmountFormatUtil.fmtMicrometer(vo.getTaxAmount()));
                    // 字典值转换
                    vo.setAuditStatus(dictdetaServcice.queryDictName(DictConstant.AUDIT_STATUS, vo.getAuditStatus()));
                    vo.setApplyCheck(dictdetaServcice.queryDictName(DictConstant.APPLY_CHECK, vo.getApplyCheck()));
                    vo.setCheckStatus(dictdetaServcice.queryDictName(DictConstant.CHECK_STATUS, vo.getCheckStatus()));
                    vo.setDataSources(dictdetaServcice.queryDictName(DictConstant.JKSCJFS, vo.getDataSources()));
                    vo.setCollectUploadStatus(
                        dictdetaServcice.queryDictName(DictConstant.JKSSCZT, vo.getCollectUploadStatus()));
                    i++;
                }
            }
            json.put("datalist", resultList);
        }
        log.info("json=====>{}",json);

        return json;
    }

    @Override
    public JSONObject queryManualSign(Map<String, Object> pramsMap, int curr, int size) {
        JSONObject json = new JSONObject();

        List<String> gfTaxNoList = (List<String>)pramsMap.get("gfTaxNoList");

        if (gfTaxNoList.size() == 0) {
            // 未从getUserInfo()获取到购方税号信息
            json.put("taxAmountSum", "0");
            json.put("total", "0");
            json.put("datalist", new ArrayList<CustomsCollectVO>());
        } else {
            DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);
            // 合计信息,仅第一页时需要统计，减少数据库压力
            if (curr == 1) {
                String number = "0";
                String taxAmountSum = "0";
                pramsMap.put("maunalSign", "1");
                Map<String, Object> data = super.baseMapper.sumTaxAmount(pramsMap);

                if (data != null) {
                    taxAmountSum = AmountFormatUtil.fmtMicrometer(ObjectUtil.fixNull(data.get("taxAmountSum")));
                    json.put("taxAmountSum", taxAmountSum);
                }

            }

            // 查询发票上的购方信息

            PageHelper.startPage(curr, size);
            List<CustomsCollectVO> pageList = super.baseMapper.queryManualSign(pramsMap);
            PageInfo<CustomsCollectVO> pageInfo = new PageInfo<>(pageList);
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());

            // 用于页面展示
            List<CustomsCollectVO> resultList = pageInfo.getList();
            if (resultList != null && resultList.size() > 0) {
                // List<DictdetaModel> jhModels = dictdetaServcice.selectDictdeta("AUDIT_STATUS");
                // List<DictdetaModel> sqhdModels = dictdetaServcice.selectDictdeta("APPLY_CHECK");
                // List<DictdetaModel> hcjgModels = dictdetaServcice.selectDictdeta("CHECK_STATUS");
                // List<DictdetaModel> cjfsModels = dictdetaServcice.selectDictdeta("JKSCJFS");
                // List<DictdetaModel> glztModels = dictdetaServcice.selectDictdeta("GLZT");
                // List<DictdetaModel> bfxModels = dictdetaServcice.selectDictdeta("entryDiscrepancy");
                int i = 1;
                for (CustomsCollectVO vo : resultList) {
                    vo.setIndex(String.valueOf((curr - 1) * size + i));
                    if (vo.getTaxAmount() == null || "".equals(vo.getTaxAmount())) {
                        vo.setTaxAmount("0.00");
                    } else {
                        vo.setTaxAmount(
                            AmountFormatUtil.fmtMicrometer(new BigDecimal(ObjectUtil.fixNull(vo.getTaxAmount()))
                                .setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString()));
                    }
                    // 字典值转换
                    vo.setDataSources(dictdetaServcice.queryDictName(DictConstant.JKSCJFS, vo.getDataSources()));
                    vo.setGlzt(dictdetaServcice.queryDictName(DictConstant.GLZT, vo.getGlzt()));
                    vo.setAuditStatus(dictdetaServcice.queryDictName(DictConstant.AUDIT_STATUS, vo.getAuditStatus()));
                    vo.setApplyCheck(dictdetaServcice.queryDictName(DictConstant.APPLY_CHECK, vo.getApplyCheck()));
                    vo.setCheckStatus(dictdetaServcice.queryDictName(DictConstant.CHECK_STATUS, vo.getCheckStatus()));
                    vo.setEntryDiscrepancy(
                        dictdetaServcice.queryDictName(DictConstant.ENTRY_DISCREPANCY, vo.getEntryDiscrepancy()));
                    i++;
                }
            }
            json.put("datalist", resultList);
        }

        return json;
    }

    @Override
    public JSONObject queryRzcxByPage(Map<String, Object> pramsMap, int curr, int size) {
        JSONObject json = new JSONObject();

        List<String> gfTaxNoList = (List<String>)pramsMap.get("gfTaxNo");

        if (gfTaxNoList.size() == 0) {
            // 未从getUserInfo()获取到购方税号信息
            json.put("number", "0");
            json.put("taxAmountSum", "0");
            json.put("total", "0");
            json.put("datalist", new ArrayList<CustomsRzcxVO>());
        } else {
            DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);
            // 查询发票上的购方信息

            PageHelper.startPage(curr, size);
            List<CustomsRzcxVO> pageList = super.baseMapper.queryRzcxByPage(pramsMap);
            log.info("pageList={}",pageList.size());
            PageInfo<CustomsRzcxVO> pageInfo = new PageInfo<>(pageList);
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());

            // 用于页面展示
            List<CustomsRzcxVO> resultList = pageInfo.getList();
            if (resultList != null && resultList.size() > 0) {
                // List<DictdetaModel> lyModels = dictdetaServcice.selectDictdeta("jksSources");
                // List<DictdetaModel> qsztModels = dictdetaServcice.selectDictdeta("qsStatus");
                // List<DictdetaModel> qsfsModels = dictdetaServcice.selectDictdeta("qsType");
                // List<DictdetaModel> glztModels = dictdetaServcice.selectDictdeta("GLZT");
                // List<DictdetaModel> rzztModels = dictdetaServcice.selectDictdeta("rzhYesorno");
                // List<DictdetaModel> rzclztModels = dictdetaServcice.selectDictdeta("authStatus");
                // List<DictdetaModel> rzlxModels = dictdetaServcice.selectDictdeta("BDK_STATUS");
                // List<DictdetaModel> cxrzModels = dictdetaServcice.selectDictdeta("CXRZ_STATUS");
                int i = 1;
                for (CustomsRzcxVO vo : resultList) {
                    vo.setXh(String.valueOf((curr - 1) * size + i));
                    vo.setTaxAmount(AmountFormatUtil.fmtMicrometer(vo.getTaxAmount()));
                    vo.setYxTaxAmount(AmountFormatUtil.fmtMicrometer(vo.getYxTaxAmount()));
                    // 字典值转换
                    vo.setGlzt(dictdetaServcice.queryDictName(DictConstant.GLZT, vo.getGlzt()));
                    vo.setDataSources(dictdetaServcice.queryDictName(DictConstant.JKSCJFS, vo.getDataSources()));
                    // if (lyModels!=null){
                    // for (DictdetaModel model : lyModels){
                    // if (model.getDictcode().equals(vo.getDataSources())){
                    // vo.setDataSources(model.getDictname());
                    // }
                    // }
                    // }
                    vo.setQsStatus(dictdetaServcice.queryDictName(DictConstant.QS_STATUS, vo.getQsStatus()));
                    String qsType = vo.getQsType();
                    vo.setQsType(dictdetaServcice.queryDictName(DictConstant.QS_TYPE, qsType));
                    vo.setRzhYesorno(dictdetaServcice.queryDictName(DictConstant.DEDU_STATUS, vo.getRzhYesorno()));
                    vo.setAuthStatus(dictdetaServcice.queryDictName(DictConstant.AUTH_STATUS_ALL, vo.getAuthStatus()));
                    vo.setBdkStatus(dictdetaServcice.queryDictName(DictConstant.BDK_STATUS, vo.getBdkStatus()));
                    vo.setCxrzStatus(dictdetaServcice.queryDictName(DictConstant.CXRZ_STATUS, vo.getCxrzStatus()));

                    i++;
                }
            }
            json.put("datalist", resultList);
        }

        return json;
    }

    @Override
    public JSONObject queryVatRzcx(Map<String, Object> pramsMap, int curr, int size) {
        JSONObject json = new JSONObject();

        List<String> gfTaxNoList = (List<String>)pramsMap.get("gfTaxNo");

        if (gfTaxNoList.size() == 0) {
            // 未从getUserInfo()获取到购方税号信息
            json.put("number", "0");
            json.put("taxAmountSum", "0");
            json.put("total", "0");
            json.put("datalist", new ArrayList<ExportInvoiceRzcxVO>());
        } else {
            DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);
            // 查询发票上的购方信息
            PageHelper.startPage(curr, size);
            List<ExportInvoiceRzcxVO> pageList = tDxExportInvoiceDao.queryVatRzcx(pramsMap);
            PageInfo<ExportInvoiceRzcxVO> pageInfo = new PageInfo<>(pageList);
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());
            // 用于页面展示
            List<ExportInvoiceRzcxVO> resultList = pageInfo.getList();
            if (resultList != null && resultList.size() > 0) {
                // List<DictdetaModel> fpztModels = dictdetaServcice.selectDictdeta("INVOICE_STATUS");
                // List<DictdetaModel> rzztModels = dictdetaServcice.selectDictdeta("rzhYesorno");
                // List<DictdetaModel> rzclztModels = dictdetaServcice.selectDictdeta("authStatus");
                // List<DictdetaModel> rzlxModels = dictdetaServcice.selectDictdeta("BDK_STATUS");
                // List<DictdetaModel> cxrzModels = dictdetaServcice.selectDictdeta("CXRZ_STATUS");
                // List<DictdetaModel> fplxModels = dictdetaServcice.selectDictdeta("INVOICE_TYPE");
                int i = 1;
                for (ExportInvoiceRzcxVO vo : resultList) {
                    vo.setXh(String.valueOf((curr - 1) * size + i));
                    // 字典值转换
                    vo.setInvoiceType(
                        dictdetaServcice.queryDictName(DictConstant.INVOICE_TYPE_VAT, vo.getInvoiceType()));
                    vo.setInvoiceStatus(
                        dictdetaServcice.queryDictName(DictConstant.INVOICE_STATUS, vo.getInvoiceStatus()));
                    vo.setRzhYesorno(dictdetaServcice.queryDictName(DictConstant.DEDU_STATUS, vo.getRzhYesorno()));
                    vo.setAuthStatus(dictdetaServcice.queryDictName(DictConstant.AUTH_STATUS_ALL, vo.getAuthStatus()));
                    vo.setBdkStatus(dictdetaServcice.queryDictName(DictConstant.BDK_STATUS, vo.getBdkStatus()));
                    vo.setCxrzStatus(dictdetaServcice.queryDictName(DictConstant.CXRZ_STATUS, vo.getCxrzStatus()));

                    vo.setExportAmount(AmountFormatUtil.fmtMicrometer(vo.getExportAmount()));
                    vo.setExportTaxAmount(AmountFormatUtil.fmtMicrometer(vo.getExportTaxAmount()));
                    vo.setExportYxse(AmountFormatUtil.fmtMicrometer(vo.getExportYxse()));

                    i++;
                }
            }
            json.put("datalist", resultList);
        }

        return json;
    }

    @Override
    public JSONObject queryCustomsRzcx(Map<String, Object> pramsMap, int curr, int size) {
        JSONObject json = new JSONObject();

        List<String> gfTaxNoList = (List<String>)pramsMap.get("gfTaxNo");

        if (gfTaxNoList.size() == 0) {
            // 未从getUserInfo()获取到购方税号信息
            json.put("number", "0");
            json.put("taxAmountSum", "0");
            json.put("total", "0");
            json.put("datalist", new ArrayList<ExportCustomsRzcxVO>());
        } else {
            DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);
            // 查询发票上的购方信息
            PageHelper.startPage(curr, size);
            List<ExportCustomsRzcxVO> pageList = tDxExportCustomsDao.queryCustomsRzcx(pramsMap);
            PageInfo<ExportCustomsRzcxVO> pageInfo = new PageInfo<>(pageList);
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());

            // 用于页面展示
            List<ExportCustomsRzcxVO> resultList = pageInfo.getList();
            if (resultList != null && resultList.size() > 0) {
                // List<DictdetaModel> lyModels = dictdetaServcice.selectDictdeta("jksSources");
                // List<DictdetaModel> glztModels = dictdetaServcice.selectDictdeta("GLZT");
                // List<DictdetaModel> rzztModels = dictdetaServcice.selectDictdeta("rzhYesorno");
                // List<DictdetaModel> rzclztModels = dictdetaServcice.selectDictdeta("authStatus");
                // List<DictdetaModel> cxrzModels = dictdetaServcice.selectDictdeta("CXRZ_STATUS");
                // List<DictdetaModel> rzlxModels = dictdetaServcice.selectDictdeta("BDK_STATUS");
                int i = 1;
                for (ExportCustomsRzcxVO vo : resultList) {
                    vo.setXh(String.valueOf((curr - 1) * size + i));
                    if (vo.getExportTaxAmount() == null || "".equals(vo.getExportTaxAmount())) {
                        vo.setExportTaxAmount("0.00");
                    } else {
                        vo.setExportTaxAmount(
                            AmountFormatUtil.fmtMicrometer(new BigDecimal(ObjectUtil.fixNull(vo.getExportTaxAmount()))
                                .setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString()));
                    }
                    if (vo.getYxExportTaxAmount() == null || "".equals(vo.getYxExportTaxAmount())) {
                        vo.setYxExportTaxAmount("0.00");
                    } else {
                        vo.setYxExportTaxAmount(
                            AmountFormatUtil.fmtMicrometer(new BigDecimal(ObjectUtil.fixNull(vo.getYxExportTaxAmount()))
                                .setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString()));
                    }

                    // 字典值转换
                    vo.setGlzt(dictdetaServcice.queryDictName(DictConstant.GLZT, vo.getGlzt()));
                    vo.setDataSources(dictdetaServcice.queryDictName(DictConstant.JKSCJFS, vo.getDataSources()));
                    vo.setRzhYesorno(dictdetaServcice.queryDictName(DictConstant.DEDU_STATUS, vo.getRzhYesorno()));
                    vo.setAuthStatus(dictdetaServcice.queryDictName(DictConstant.AUTH_STATUS_ALL, vo.getAuthStatus()));
                    vo.setCxrzStatus(dictdetaServcice.queryDictName(DictConstant.CXRZ_STATUS, vo.getCxrzStatus()));
                    vo.setBdkStatus(dictdetaServcice.queryDictName(DictConstant.BDK_STATUS, vo.getBdkStatus()));
                    i++;
                }
            }
            json.put("datalist", resultList);
        }

        return json;
    }

    @Override
    public JSONObject querySign(Map<String, Object> pramsMap, int curr, int size) {
        JSONObject json = new JSONObject();

        List<String> gfTaxNoList = (List<String>)pramsMap.get("gfTaxNoList");

        if (gfTaxNoList.size() == 0) {
            // 未从getUserInfo()获取到购方税号信息
            json.put("taxAmountSum", "0");
            json.put("total", "0");
            json.put("datalist", new ArrayList<CustomsCollectVO>());
        } else {
            DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);
            // 查询发票上的购方信息
            PageHelper.startPage(curr, size);
            List<CustomsCollectVO> pageList = super.baseMapper.querySign(pramsMap);
            PageInfo<CustomsCollectVO> pageInfo = new PageInfo<>(pageList);
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());

            // 用于页面展示
            List<CustomsCollectVO> resultList = pageInfo.getList();
            if (resultList != null && resultList.size() > 0) {
                int i = 1;
                for (CustomsCollectVO vo : resultList) {
                    vo.setIndex(String.valueOf((curr - 1) * size + i));
                    // vo.setQsStatus(JQsStatusEnum.getVal(vo.getQsStatus()));
                    vo.setQsStatus(dictdetaServcice.queryDictName(DictConstant.QS_RESULTS, vo.getQsStatus()));
                    // vo.setQsType(QsTypeEnum.getVal(vo.getQsType()));
                    vo.setQsType(dictdetaServcice.queryDictName(DictConstant.QS_TYPE, vo.getQsType()));
                    // vo.setDataSources(DataSourceEnum.getVal(vo.getDataSources()));
                    vo.setDataSources(dictdetaServcice.queryDictName(DictConstant.JKSCJFS, vo.getDataSources()));
                    // vo.setGlzt(GlztEnum.getVal(vo.getGlzt()));
                    vo.setGlzt(dictdetaServcice.queryDictName(DictConstant.GLZT, vo.getGlzt()));
                    if (vo.getTaxAmount() == null || "".equals(vo.getTaxAmount())) {
                        vo.setTaxAmount("0.00");
                    } else {
                        vo.setTaxAmount(
                            AmountFormatUtil.fmtMicrometer(new BigDecimal(ObjectUtil.fixNull(vo.getTaxAmount()))
                                .setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString()));
                    }
                    vo.setAuditStatus(AuditStatusEnum.getVal(vo.getAuditStatus()));
                    vo.setApplyCheck(ApplyCheckEnum.getVal(vo.getApplyCheck()));
                    vo.setCheckStatus(CheckStatusEnum.getVal(vo.getCheckStatus()));
                    i++;
                }
            }
            json.put("datalist", resultList);
        }

        return json;

    }

    @Override
    public JSONObject queryCustomsRefundConfirmList(Map<String, Object> pramsMap, int curr, int size) {
        JSONObject json = new JSONObject();

        List<String> gfTaxNoList = (List<String>)pramsMap.get("gfTaxNoList");
        if (gfTaxNoList.size() == 0) {
            json.put("hjse", "0");
            json.put("total", "0");
            json.put("datalist", new ArrayList<String[]>());
        } else {
            DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);

            if (curr == 1) {
                String taxAmountSum = "0";
                Map<String, Object> data = super.baseMapper.queryCustomsRefundConfirmSum(pramsMap);
                if (data != null) {
                    taxAmountSum = AmountFormatUtil.fmtMicrometer(ObjectUtil.fixNull(data.get("hjse")));
                }
                json.put("hjse", taxAmountSum);
            }

            // 查询发票上的购方信息l
            PageHelper.startPage(curr, size);
            List<CustomsRecordVO> pageList = super.baseMapper.queryCustomsRefundConfirmList(pramsMap);
            PageInfo<CustomsRecordVO> pageInfo = new PageInfo<>(pageList);
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());

            // 用于页面展示
            List<CustomsRecordVO> resultList = pageInfo.getList();
            if (resultList != null && resultList.size() > 0) {
                int i = 1;
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                for (CustomsRecordVO vo : resultList) {
                    // 页面展示需要信息
                    vo.setXh(String.valueOf((curr - 1) * size + i));
                    if (vo.getTaxAmount() == null || "".equals(vo.getTaxAmount())) {
                        vo.setTaxAmount("0.00");
                    } else {
                        vo.setTaxAmount(
                            AmountFormatUtil.fmtMicrometer(new BigDecimal(ObjectUtil.fixNull(vo.getTaxAmount()))
                                .setScale(2, RoundingMode.HALF_UP).toPlainString()));
                    }
                    // 字典值转换
                    vo.setQsStatus(dictdetaServcice.queryDictName(DictConstant.QS_STATUS, vo.getQsStatus()));
                    vo.setQsType(dictdetaServcice.queryDictName(DictConstant.QS_TYPE, vo.getQsType()));
                    vo.setGlzt(dictdetaServcice.queryDictName(DictConstant.GLZT, vo.getGlzt()));
                    vo.setRzhYesorno(dictdetaServcice.queryDictName(DictConstant.DEDU_STATUS, vo.getRzhYesorno()));
                    vo.setAuthStatus(dictdetaServcice.queryDictName(DictConstant.AUTH_STATUS_ALL, vo.getAuthStatus()));
                    vo.setRzlx(dictdetaServcice.queryDictName(DictConstant.INVOICE_RZLX, vo.getRzlx()));
                    i++;
                }
            }
            json.put("datalist", resultList);
        }

        return json;
    }

    @Override
    public JSONObject queryExportInvoiceList(Map<String, Object> pramsMap, int curr, int size) {
        JSONObject json = new JSONObject();

        List<String> gfTaxNoList = (List<String>)pramsMap.get("gfTaxNoList");
        if (gfTaxNoList.size() == 0) {
            // 未从getUserInfo()获取到购方税号信息
            json.put("hjsl", "0");
            json.put("hjje", "0");
            json.put("hjse", "0");
            json.put("total", "0");
            json.put("datalist", new ArrayList<ExportInvoiceRzcxVO>());
        } else {
            DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);
            // 查询发票上的购方信息
            PageHelper.startPage(curr, size);
            List<ExportInvoiceRzcxVO> pageList = tDxExportInvoiceDao.queryExportInvoiceList(pramsMap);
            PageInfo<ExportInvoiceRzcxVO> pageInfo = new PageInfo<>(pageList);
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());

            // 用于页面展示
            List<ExportInvoiceRzcxVO> resultList = pageInfo.getList();
            if (resultList != null && resultList.size() > 0) {
                // List<DictdetaModel> fpztModels = dictdetaServcice.selectDictdeta("INVOICE_STATUS");
                // List<DictdetaModel> rzztModels = dictdetaServcice.selectDictdeta("rzhYesorno");
                // List<DictdetaModel> rzclztModels = dictdetaServcice.selectDictdeta("authStatus");
                // List<DictdetaModel> rzlxModels = dictdetaServcice.selectDictdeta("BDK_STATUS");
                // List<DictdetaModel> fplxModels = dictdetaServcice.selectDictdeta("INVOICE_TYPE");
                int i = 1;
                for (ExportInvoiceRzcxVO vo : resultList) {
                    vo.setXh(String.valueOf((curr - 1) * size + i));

                    // 字典值转换
                    vo.setInvoiceType(
                        dictdetaServcice.queryDictName(DictConstant.INVOICE_TYPE_VAT, vo.getInvoiceType()));
                    vo.setInvoiceStatus(
                        dictdetaServcice.queryDictName(DictConstant.INVOICE_STATUS, vo.getInvoiceStatus()));
                    vo.setRzhYesorno(dictdetaServcice.queryDictName(DictConstant.DEDU_STATUS, vo.getRzhYesorno()));
                    vo.setAuthStatus(dictdetaServcice.queryDictName(DictConstant.AUTH_STATUS_ALL, vo.getAuthStatus()));
                    vo.setBdkStatus(dictdetaServcice.queryDictName(DictConstant.BDK_STATUS, vo.getBdkStatus()));

                    vo.setExportAmount(AmountFormatUtil.fmtMicrometer(vo.getExportAmount()));
                    vo.setExportTaxAmount(AmountFormatUtil.fmtMicrometer(vo.getExportTaxAmount()));
                    vo.setExportYxse(AmountFormatUtil.fmtMicrometer(vo.getExportYxse()));
                    i++;
                }
            }
            json.put("datalist", resultList);
        }

        return json;
    }

    @Override
    public JSONObject queryExportCustomsList(Map<String, Object> pramsMap, int curr, int size) {
        JSONObject json = new JSONObject();

        List<String> gfTaxNoList = (List<String>)pramsMap.get("gfTaxNoList");

        if (gfTaxNoList.size() == 0) {
            // 未从getUserInfo()获取到购方税号信息
            json.put("hjsl", "0");
            json.put("hjse", "0");
            json.put("total", "0");
            json.put("datalist", new ArrayList<ExportCustomsRzcxVO>());
        } else {
            DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);
            // 查询发票上的购方信息
            PageHelper.startPage(curr, size);
            List<ExportCustomsRzcxVO> pageList = tDxExportCustomsDao.queryExportCustomsList(pramsMap);
            PageInfo<ExportCustomsRzcxVO> pageInfo = new PageInfo<>(pageList);
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());

            // 用于页面展示
            List<ExportCustomsRzcxVO> resultList = pageInfo.getList();
            if (resultList != null && resultList.size() > 0) {
                List<DictdetaModel> fpztModels = dictdetaServcice.selectDictdeta("INVOICE_STATUS");
                // List<DictdetaModel> rzztModels = dictdetaServcice.selectDictdeta("rzhYesorno");
                // List<DictdetaModel> rzclztModels = dictdetaServcice.selectDictdeta("authStatus");
                // List<DictdetaModel> rzlxModels = dictdetaServcice.selectDictdeta("BDK_STATUS");
                List<DictdetaModel> cxrzModels = dictdetaServcice.selectDictdeta("CXRZ_STATUS");
                // List<DictdetaModel> lyModels = dictdetaServcice.selectDictdeta("jksSources");
                // List<DictdetaModel> glztModels = dictdetaServcice.selectDictdeta("GLZT");
                int i = 1;
                for (ExportCustomsRzcxVO vo : resultList) {
                    vo.setXh(String.valueOf((curr - 1) * size + i));
                    vo.setExportTaxAmount(AmountFormatUtil.fmtMicrometer(vo.getExportTaxAmount()));
                    vo.setYxExportTaxAmount(AmountFormatUtil.fmtMicrometer(vo.getYxExportTaxAmount()));
                    // 字典值转换
                    vo.setGlzt(dictdetaServcice.queryDictName(DictConstant.GLZT, vo.getGlzt()));
                    vo.setDataSources(dictdetaServcice.queryDictName(DictConstant.JKSCJFS, vo.getDataSources()));
                    vo.setRzhYesorno(dictdetaServcice.queryDictName(DictConstant.DEDU_STATUS, vo.getRzhYesorno()));
                    vo.setAuthStatus(dictdetaServcice.queryDictName(DictConstant.AUTH_STATUS_ALL, vo.getAuthStatus()));
                    vo.setBdkStatus(dictdetaServcice.queryDictName(DictConstant.BDK_STATUS, vo.getBdkStatus()));

                    i++;
                }
            }
            json.put("datalist", resultList);
        }

        return json;
    }

    private String getFpzlMc(String invoiceType) {
        String fplx = "";
        if (FplxEnum.DZP.getFplxDm().equals(invoiceType)) {
            fplx = FplxEnum.DZP.getFplxMc(FplxEnum.DZP.getIndex());
        } else if (FplxEnum.JDC.getFplxDm().equals(invoiceType)) {
            fplx = FplxEnum.JDC.getFplxMc(FplxEnum.JDC.getIndex());
        } else if (FplxEnum.JSP.getFplxDm().equals(invoiceType)) {
            fplx = FplxEnum.JSP.getFplxMc(FplxEnum.JSP.getIndex());
        } else if (FplxEnum.PP.getFplxDm().equals(invoiceType)) {
            fplx = FplxEnum.PP.getFplxMc(FplxEnum.PP.getIndex());
        } else if (FplxEnum.TXF.getFplxDm().equals(invoiceType)) {
            fplx = FplxEnum.TXF.getFplxMc(FplxEnum.TXF.getIndex());
        } else if (FplxEnum.ZP.getFplxDm().equals(invoiceType)) {
            fplx = FplxEnum.ZP.getFplxMc(FplxEnum.ZP.getIndex());
        } else if (FplxEnum.HGJKS.getFplxDm().equals(invoiceType)) {
            fplx = FplxEnum.HGJKS.getFplxMc(FplxEnum.HGJKS.getIndex());
        } else if (FplxEnum.DZZP.getFplxDm().equals(invoiceType)) {
            fplx = FplxEnum.DZZP.getFplxMc(FplxEnum.DZZP.getIndex());
        }
        return fplx;
    }

    private String getRzzt(String rzhYesorno) {
        String rzzt = "";
        if (RzztEnum.WRZ.getRzztDm().equals(rzhYesorno)) {
            rzzt = RzztEnum.WRZ.getRzztMc(RzztEnum.WRZ.getIndex());
        } else if (RzztEnum.YRZ.getRzztDm().equals(rzhYesorno)) {
            rzzt = RzztEnum.YRZ.getRzztMc(RzztEnum.YRZ.getIndex());
        } else if (RzztEnum.YRZBDK.getRzztDm().equals(rzhYesorno)) {
            rzzt = RzztEnum.YRZBDK.getRzztMc(RzztEnum.YRZBDK.getIndex());
        } else if (RzztEnum.TSRZ.getRzztDm().equals(rzhYesorno)) {
            rzzt = RzztEnum.TSRZ.getRzztMc(RzztEnum.TSRZ.getIndex());
        }
        return rzzt;
    }

}
