package com.dxhy.base.service.sqdktj;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dxhy.api.model.config.Tax;
import com.dxhy.base.dao.BaseTDxDkCountDetailDao;
import com.dxhy.base.entity.BaseTDxDkCountDetail;
import com.dxhy.base.model.BaseTDxDkCountDetailRespVO;
import com.dxhy.common.constant.DbConstant;
import com.dxhy.common.datasource.config.DynamicContextHolder;
import com.dxhy.common.enums.DktjmxzjEnum;
import com.dxhy.common.enums.FplxEnum;
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 org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 抵扣统计明细service实现类
 *
 * @author kangzq
 * @date 2019年5月11日
 * @version 1.0
 */

@SuppressWarnings({"AlibabaLowerCamelCaseVariableNaming", "AlibabaUndefineMagicConstant", "AlibabaMethodTooLong",
    "AlibabaClassNamingShouldBeCamel"})
@Service("baseDktjService")
public class BaseDKtjServiceImpl extends MpBaseServiceImpl<BaseTDxDkCountDetailDao, BaseTDxDkCountDetail>
    implements BaseDktjService {

    @Override
    public String selectByGfsbhAndSkssq(Map<String, Object> pramsMap) {
        JSONObject json;
        DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);

        try {

            String[] titlelist =
                {"序号", "购方税号", "所属月份", "发票类型", "抵扣发票份数", "抵扣总金额", "抵扣总有效税额", "不抵扣发票份数", "不抵扣总金额", "不抵扣总有效税额"};
            String[] titleprop = {"xh", "taxno", "skssq", "invoiceType", "dkInvoiceCount", "dkAmountCount",
                "dkTaxAmountCount", "bdkInvoiceCount", "bdkAmountCount", "bdkTaxAmountCount"};

            // 需要设置返回列表标题时调用
            json = super.setTitleList(titlelist, titleprop);
            List<Tax> taxList = (List<Tax>)pramsMap.get("taxList");
            String gfsh = (String)pramsMap.get("gfsh");
            String skssq = pramsMap.get("skssq").toString().substring(0, 4) + "年"
                    + pramsMap.get("skssq").toString().substring(4, 6) + "月";
            json.put("skssq", skssq);

            String tjdate = "";
            String tjmonth = "";
            String taxName = "";
            String taxNo = "";

            //统计结果--正常
            List<BaseTDxDkCountDetailRespVO> tjjgZc = selectTjjgDetail("1",pramsMap,gfsh,taxList);
            //统计结果--异常信息
            List<BaseTDxDkCountDetailRespVO> tjjgYc = selectTjjgDetail("2",pramsMap,gfsh,taxList);

            //加计扣除统计信息
            List<BaseTDxDkCountDetail> jjkcZc = selectJjkcTjjgDetail("4",pramsMap,gfsh,taxList);

            //增值税申报进项抵扣汇总
            List<BaseTDxDkCountDetail> shenBaoTj = selectShenBaoTjjgDetail("6",pramsMap,gfsh,taxList);


            QueryWrapper<BaseTDxDkCountDetail> queryWrapper = new QueryWrapper<>();
            if (pramsMap.containsKey("gfsh") && !StringHelper.isBlank(String.valueOf(pramsMap.get("gfsh")))) {
                queryWrapper.eq("taxno", pramsMap.get("gfsh"));
            }
            if (pramsMap.containsKey("skssq") && !StringHelper.isBlank(String.valueOf(pramsMap.get("skssq")))) {
                queryWrapper.eq("tj_month", pramsMap.get("skssq"));
            }
            queryWrapper.orderByAsc("invoice_type");
            List<BaseTDxDkCountDetail> detailList = list(queryWrapper);
            if(detailList.size()>0){
                tjdate = tjjgYc.get(0).getTjDate();
                tjmonth = tjjgYc.get(0).getTjMonth();
                taxName = tjjgYc.get(0).getTaxName();
                taxNo = tjjgYc.get(0).getTaxno();
            }

            Map<String,Object> resultMap = new HashMap();
            resultMap.put("tjjgZc", tjjgZc);
            resultMap.put("tjjgYc", tjjgYc);
            resultMap.put("jjkcZc", jjkcZc);
            resultMap.put("shenBaoTj", shenBaoTj);

            resultMap.put("tjDate", tjdate);
            resultMap.put("tjMonth", tjmonth);
            resultMap.put("taxName", taxName);
            resultMap.put("taxNo", taxNo);

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

        return super.responseResult(json);
    }


    /**
     * @Description 加计扣除返回
     * @Return java.util.List<com.dxhy.base.entity.BaseTDxDkCountDetail>
     * @Author wangruwei
     * @Date 2024/1/16 15:17
     **/
    private List<BaseTDxDkCountDetail> selectJjkcTjjgDetail(String tjjglx, Map<String, Object> pramsMap, String gfsh, List<Tax> taxList) {
        //---------------------------------------加计扣除统计结果------------------------------------------
        String[] jjkctitlelist = {"发票类型", "正数发票份数", "正数发票税额","负数发票份数", "负数发票税额"};
        String[] jjkctitleprop = {"invoiceType", "zsfpfs", "zsfpse","fsfpfs", "fsfpse"};
        LambdaQueryWrapper<BaseTDxDkCountDetail> dkcountDetailWrapper = new LambdaQueryWrapper();
        //异常凭证转入统计结果
        if (pramsMap.containsKey("gfsh") && !StringHelper.isBlank(String.valueOf(pramsMap.get("gfsh")))) {
            dkcountDetailWrapper.eq(BaseTDxDkCountDetail::getTaxno, pramsMap.get("gfsh"));
        }
        if (pramsMap.containsKey("skssq") && !StringHelper.isBlank(String.valueOf(pramsMap.get("skssq")))) {
            dkcountDetailWrapper.eq(BaseTDxDkCountDetail::getTjMonth, pramsMap.get("skssq"));
        }
        dkcountDetailWrapper.eq(BaseTDxDkCountDetail::getTjjglx, tjjglx);
        List<BaseTDxDkCountDetail> ycpzJjkcTjjg = baseMapper.selectList(dkcountDetailWrapper);
        JSONObject jjkcTjjgJson = super.setTitleList(jjkctitlelist, jjkctitleprop);
        for (int i = 0; i < ycpzJjkcTjjg.size() ; i++) {
            ycpzJjkcTjjg.get(i).setInvoiceType(getInvoiceTypeName(ycpzJjkcTjjg.get(i).getInvoiceType()));
            if(ObjectUtil.isNotEmpty(ycpzJjkcTjjg.get(i).getZsfpfs())){
                ycpzJjkcTjjg.get(i).setZsfpfs(ycpzJjkcTjjg.get(i).getZsfpfs());
            }else{
                ycpzJjkcTjjg.get(i).setZsfpfs("--");
            }

            if(ObjectUtil.isNotEmpty(ycpzJjkcTjjg.get(i).getZsfpse())){
                ycpzJjkcTjjg.get(i).setZsfpse(AmountFormatUtil.fmtMicrometer(MathUtil.round(ycpzJjkcTjjg.get(i).getZsfpse())));
            }else{
                ycpzJjkcTjjg.get(i).setZsfpse("--");
            }
            if(ObjectUtil.isNotEmpty(ycpzJjkcTjjg.get(i).getFsfpfs())){
                ycpzJjkcTjjg.get(i).setFsfpfs(ycpzJjkcTjjg.get(i).getFsfpfs());
            }else{
                ycpzJjkcTjjg.get(i).setFsfpfs("--");
            }


            if(ObjectUtil.isNotEmpty(ycpzJjkcTjjg.get(i).getFsfpse())){
                ycpzJjkcTjjg.get(i).setFsfpse(AmountFormatUtil.fmtMicrometer(MathUtil.round(ycpzJjkcTjjg.get(i).getFsfpse())));
            }else{
                ycpzJjkcTjjg.get(i).setFsfpse("--");
            }

        }

        ycpzJjkcTjjg = makeJjkcTjjkShowList(ycpzJjkcTjjg);
        return ycpzJjkcTjjg;

    }

    /**
     * @Description 获取加计扣除tab页数据
     * @param jjkc
     * @Return java.util.List<com.dxhy.lqchannel.job.entity.LqTDxDkCountDetail>
     * @Author wangruwei
     * @Date 2023/11/20 17:32
     **/
    private List<BaseTDxDkCountDetail> makeJjkcTjjkShowList(List<BaseTDxDkCountDetail> jjkc) {
        List<BaseTDxDkCountDetail> resultList = new LinkedList();
        List<String> invoiceTypelist = new LinkedList();
        invoiceTypelist.add("增值税专用发票");
        invoiceTypelist.add("收购发票");
        invoiceTypelist.add("免税自产农产品普通发票");
        invoiceTypelist.add("海关缴款书");
        invoiceTypelist.add("录入本期有效抵扣税额");
        invoiceTypelist.add("总计");
        for (int i = 0; i < invoiceTypelist.size(); i++) {
            String invoiceType = invoiceTypelist.get(i);
            List<BaseTDxDkCountDetail> collect = jjkc.stream().filter(e -> invoiceType.equals(e.getInvoiceType())).collect(Collectors.toList());
            //如果有，放入值
            if(collect.size()>0){
                resultList.add(collect.get(0));
            }else{
                BaseTDxDkCountDetail detail = new BaseTDxDkCountDetail();
                detail.setInvoiceType(invoiceType);
                detail.setZsfpfs("0");
                detail.setZsfpse(AmountFormatUtil.fmtMicrometer("0.00"));
                detail.setFsfpfs("0");
                detail.setFsfpse(AmountFormatUtil.fmtMicrometer("0.00 "));
                resultList.add(detail);
            }
        }
        return resultList;
    }

    /**
     * @Description 申报数据返回
     * @Return java.util.List<com.dxhy.base.entity.BaseTDxDkCountDetail>
     * @Author wangruwei
     * @Date 2024/1/16 15:17
     **/
    private List<BaseTDxDkCountDetail> selectShenBaoTjjgDetail(String tjjglx, Map<String, Object> pramsMap, String gfsh, List<Tax> taxList) {
        //---------------------------------------加计扣除统计结果------------------------------------------
        String[] jjkctitlelist = {"发票类型", "份数", "金额","税额"};
        String[] jjkctitleprop = {"invoiceType", "dkInvoiceCount", "dkAmountCount","dkTaxAmountCount"};
        LambdaQueryWrapper<BaseTDxDkCountDetail> dkcountDetailWrapper = new LambdaQueryWrapper();
        //异常凭证转入统计结果
        if (pramsMap.containsKey("gfsh") && !StringHelper.isBlank(String.valueOf(pramsMap.get("gfsh")))) {
            dkcountDetailWrapper.eq(BaseTDxDkCountDetail::getTaxno, pramsMap.get("gfsh"));
        }
        if (pramsMap.containsKey("skssq") && !StringHelper.isBlank(String.valueOf(pramsMap.get("skssq")))) {
            dkcountDetailWrapper.eq(BaseTDxDkCountDetail::getTjMonth, pramsMap.get("skssq"));
        }
        dkcountDetailWrapper.eq(BaseTDxDkCountDetail::getTjjglx, tjjglx);
        List<BaseTDxDkCountDetail> ycpzJjkcTjjg = baseMapper.selectList(dkcountDetailWrapper);
        for (int i = 0; i < ycpzJjkcTjjg.size() ; i++) {
            ycpzJjkcTjjg.get(i).setInvoiceType(getInvoiceTypeName(ycpzJjkcTjjg.get(i).getInvoiceType()));
            ycpzJjkcTjjg.get(i).setDkInvoiceCount(ycpzJjkcTjjg.get(i).getDkInvoiceCount());
            if(ObjectUtil.isNotEmpty(ycpzJjkcTjjg.get(i).getDkAmountCount())){
                ycpzJjkcTjjg.get(i).setDkAmountCount(AmountFormatUtil.fmtMicrometer(MathUtil.round(ycpzJjkcTjjg.get(i).getDkAmountCount())));
            }else{
                ycpzJjkcTjjg.get(i).setDkAmountCount("--");
            }
            if(ObjectUtil.isNotEmpty(ycpzJjkcTjjg.get(i).getDkTaxAmountCount())){
                ycpzJjkcTjjg.get(i).setDkTaxAmountCount(AmountFormatUtil.fmtMicrometer(MathUtil.round(ycpzJjkcTjjg.get(i).getDkTaxAmountCount())));
            }else{
                ycpzJjkcTjjg.get(i).setDkTaxAmountCount("--");
            }


        }

        ycpzJjkcTjjg = makeShenBaoTjjkShowList(ycpzJjkcTjjg);
        return ycpzJjkcTjjg;
    }

    private List<BaseTDxDkCountDetail> makeShenBaoTjjkShowList(List<BaseTDxDkCountDetail> ycpzJjkcTjjg) {
        List<BaseTDxDkCountDetail> resultList = new LinkedList();
        List<String> invoiceTypelist = new LinkedList();
        invoiceTypelist.add("本期认证相符的增值税专用发票（第2行）");
        invoiceTypelist.add("海关进口增值税缴款书（第5行）");
        invoiceTypelist.add("农产品收购发票或者销售发票（第6行）");
        invoiceTypelist.add("代扣代缴税收缴款凭证（第7行）");
        invoiceTypelist.add("加计扣除农产品进项税额（第8a行）");
        invoiceTypelist.add("外贸企业进项税额抵扣证明（第11行）");
        invoiceTypelist.add("本期认证相符的解除异常凭证（23a）");
        for (int i = 0; i < invoiceTypelist.size(); i++) {
            String invoiceType = invoiceTypelist.get(i);
            List<BaseTDxDkCountDetail> collect = ycpzJjkcTjjg.stream().filter(e -> invoiceType.equals(e.getInvoiceType())).collect(Collectors.toList());
            //如果有，放入值
            if(collect.size()>0){
                resultList.add(collect.get(0));
            }else{
                BaseTDxDkCountDetail detail = new BaseTDxDkCountDetail();
                detail.setInvoiceType(invoiceType);
                detail.setDkInvoiceCount("0");
                detail.setDkAmountCount(AmountFormatUtil.fmtMicrometer("0.00"));
                detail.setDkTaxAmountCount(AmountFormatUtil.fmtMicrometer("0.00"));
                resultList.add(detail);
            }
        }
        return resultList;
    }


    private String getInvoiceTypeName(String invoiceType) {
        String invoiceName = "";
        switch (invoiceType){
            case "1":
                invoiceName = "收购发票";
                break;
            case "2":
                invoiceName = "免税自产农产品普通发票";
                break;
            case "4":
                invoiceName = "其他普通发票";
                break;
            case "01":
                invoiceName = "增值税专用发票";
                break;
            case "03":
                invoiceName = "机动车销售统一发票";
                break;
            case "7":
                invoiceName = "代扣代缴完税凭证";
                break;
            case "08":
                invoiceName = "增值税专用电子发票";
                break;
            case "13":
                invoiceName = "录入本期有效抵扣税额";
                break;
            case "14":
                invoiceName = "通行费发票";
                break;
            case "17":
                invoiceName = "海关缴款书";
                break;
            case "24":
                invoiceName = "出口转内销";
                break;
            case "30":
                invoiceName = "出口转内销海关缴款书";
                break;
            case "80":
                invoiceName = "出口转内销专用电子发票";
                break;
            case "61":
                invoiceName = "电子发票（航空运输电子客票行程单）";
                break;
            case "83":
                invoiceName = "电子发票（铁路电子客票）";
                break;
            case "104":
                invoiceName = "其他普通发票";
                break;
            case "107":
                invoiceName = "代扣代缴完税凭证";
                break;
            case "113":
                invoiceName = "录入本期有效抵扣税额";
                break;
            case "114":
                invoiceName = "合计";
                break;
            case "tax15":
                invoiceName = "本期认证相符的增值税专用发票（第2行）";
                break;
            case "tax16":
                invoiceName = "海关进口增值税缴款书（第5行）";
                break;
            case "tax17":
                invoiceName = "农产品收购发票或者销售发票（第6行）";
                break;
            case "tax18":
                invoiceName = "代扣代缴税收缴款凭证（第7行）";
                break;
            case "tax19":
                invoiceName = "加计扣除农产品进项税额（第8a行）";
                break;
            case "tax20":
                invoiceName = "外贸企业进项税额抵扣证明（第11行）";
                break;
            case "taxyc15":
                invoiceName = "本期认证相符的解除异常凭证（23a）";
                break;
            case "99":
                invoiceName = "总计";
                break;
        }
        return invoiceName;
    }


    private List<BaseTDxDkCountDetailRespVO> selectTjjgDetail(String tjjglx, Map<String, Object> pramsMap, String gfsh, List<Tax> taxList) throws ParseException {
        QueryWrapper<BaseTDxDkCountDetail> queryWrapper = new QueryWrapper<>();
        if (pramsMap.containsKey("gfsh") && !StringHelper.isBlank(String.valueOf(pramsMap.get("gfsh")))) {
            queryWrapper.eq("taxno", pramsMap.get("gfsh"));
        }
        if (pramsMap.containsKey("skssq") && !StringHelper.isBlank(String.valueOf(pramsMap.get("skssq")))) {
            queryWrapper.eq("tj_month", pramsMap.get("skssq"));
        }
        queryWrapper.eq("tjjglx", tjjglx);
        queryWrapper.orderByAsc("invoice_type");


        List<BaseTDxDkCountDetail> dkList = list(queryWrapper);
        // 页面展示对象
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");
        //StringBuilder sb = new StringBuilder();
        List<String> sb = new LinkedList<>();
        String tjdate = "";
        String tjmonth = "";
        String taxName = "";
        for (BaseTDxDkCountDetail baseTDxDkCountDetail : dkList) {
            sb.add(baseTDxDkCountDetail.getInvoiceType());
            String tjDate = baseTDxDkCountDetail.getTjDate();
            Date date = sdf.parse(tjDate);
            tjdate = sdf1.format(date);
            tjmonth = baseTDxDkCountDetail.getTjMonth();
            for (Tax t : taxList) {
                String taxno = t.getTaxno();
                if (gfsh.equals(taxno)) {
                    taxName = t.getTaxname();
                }
            }
        }

        List<BaseTDxDkCountDetailRespVO> list = new ArrayList<>();
        if (sb.indexOf("01") < 0) {
            BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
            td.setBdkAmountCount("0.00");
            td.setBdkInvoiceCount("0");
            td.setBdkTaxAmountCount("0.00");
            td.setDkAmountCount("0.00");
            td.setDkInvoiceCount("0");
            td.setDkTaxAmountCount("0.00");
            td.setTaxno((String)pramsMap.get("gfsh"));
            td.setTjDate(tjdate);
            td.setTjMonth(tjmonth);
            td.setTaxName(taxName);
            td.setInvoiceType("增值税专用发票");
            list.add(td);
        } else {
            for (BaseTDxDkCountDetail baseTDxDkCountDetail : dkList) {
                if ("01".equals(baseTDxDkCountDetail.getInvoiceType())) {
                    BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
                    sb.add(baseTDxDkCountDetail.getInvoiceType());
                    String bdkAmountCount;
                    try {
                        bdkAmountCount = baseTDxDkCountDetail.getBdkAmountCount();
                        BigDecimal amountCount = new BigDecimal(bdkAmountCount);
                        bdkAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        bdkAmountCount = "-";
                    }
                    td.setBdkAmountCount(bdkAmountCount);
                    String bdkInvoiceCount;
                    try {
                        bdkInvoiceCount = baseTDxDkCountDetail.getBdkInvoiceCount();
                        BigDecimal amountCount = new BigDecimal(bdkInvoiceCount);
                        bdkInvoiceCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
                    } catch (Exception e) {
                        bdkInvoiceCount = "-";
                    }
                    td.setBdkInvoiceCount(bdkInvoiceCount);
                    String bdkTaxAmountCount;
                    try {
                        bdkTaxAmountCount = baseTDxDkCountDetail.getBdkTaxAmountCount();
                        BigDecimal amountCount = new BigDecimal(bdkTaxAmountCount);
                        bdkTaxAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        bdkTaxAmountCount = "-";
                    }
                    td.setBdkTaxAmountCount(bdkTaxAmountCount);
                    String dkAmountCount;
                    try {
                        dkAmountCount = baseTDxDkCountDetail.getDkAmountCount();
                        BigDecimal amountCount = new BigDecimal(dkAmountCount);
                        dkAmountCount = AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        dkAmountCount = "-";
                    }
                    td.setDkAmountCount(dkAmountCount);
                    String dkInvoiceCount;
                    try {
                        dkInvoiceCount = baseTDxDkCountDetail.getDkInvoiceCount();
                        BigDecimal amountCount = new BigDecimal(dkInvoiceCount);
                        dkInvoiceCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
                    } catch (Exception e) {
                        dkInvoiceCount = "-";
                    }
                    td.setDkInvoiceCount(dkInvoiceCount);
                    String dkTaxAmountCount;
                    try {
                        dkTaxAmountCount = baseTDxDkCountDetail.getDkTaxAmountCount();
                        BigDecimal amountCount = new BigDecimal(dkTaxAmountCount);
                        dkTaxAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        dkTaxAmountCount = "-";
                    }
                    td.setDkTaxAmountCount(dkTaxAmountCount);
                    td.setTaxno(baseTDxDkCountDetail.getTaxno());
                    String tjDate = baseTDxDkCountDetail.getTjDate();
                    Date date = sdf.parse(tjDate);
                    td.setTjDate(sdf1.format(date));
                    tjdate = sdf1.format(date);
                    td.setTjMonth(baseTDxDkCountDetail.getTjMonth());
                    tjmonth = baseTDxDkCountDetail.getTjMonth();
                    for (Tax t : taxList) {
                        String taxno = t.getTaxno();
                        if (td.getTaxno().equals(taxno)) {
                            td.setTaxName(t.getTaxname());
                            taxName = t.getTaxname();
                        }
                    }
                    if (baseTDxDkCountDetail.getInvoiceType().equals(DktjmxzjEnum.ZJ.getDktjmxzjDm())) {
                        td.setInvoiceType(DktjmxzjEnum.ZJ.getDktjmxzjMc(DktjmxzjEnum.ZJ.getIndex()));
                    } else {
                        for (FplxEnum e : FplxEnum.values()) {
                            if (e.getFplxDm().equals(baseTDxDkCountDetail.getInvoiceType())) {
                                td.setInvoiceType(e.getFplxMc(e.getIndex()));
                            }
                        }
                    }
                    list.add(td);
                }
            }
        }
        if (sb.indexOf("03") < 0) {
            BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
            td.setBdkAmountCount("0.00");
            td.setBdkInvoiceCount("0");
            td.setBdkTaxAmountCount("0.00");
            td.setDkAmountCount("0.00");
            td.setDkInvoiceCount("0");
            td.setDkTaxAmountCount("0.00");
            td.setTaxno((String)pramsMap.get("gfsh"));
            td.setTjDate(tjdate);
            td.setTjMonth(tjmonth);
            td.setTaxName(taxName);
            td.setInvoiceType("机动车销售统一发票");
            list.add(td);
        } else {
            for (BaseTDxDkCountDetail baseTDxDkCountDetail : dkList) {
                if ("03".equals(baseTDxDkCountDetail.getInvoiceType())) {
                    BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
                    sb.add(baseTDxDkCountDetail.getInvoiceType());
                    String bdkAmountCount;
                    try {
                        bdkAmountCount = baseTDxDkCountDetail.getBdkAmountCount();
                        BigDecimal amountCount = new BigDecimal(bdkAmountCount);
                        bdkAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        bdkAmountCount = "-";
                    }
                    td.setBdkAmountCount(bdkAmountCount);
                    String bdkInvoiceCount;
                    try {
                        bdkInvoiceCount = baseTDxDkCountDetail.getBdkInvoiceCount();
                        BigDecimal amountCount = new BigDecimal(bdkInvoiceCount);
                        bdkInvoiceCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
                    } catch (Exception e) {
                        bdkInvoiceCount = "-";
                    }
                    td.setBdkInvoiceCount(bdkInvoiceCount);
                    String bdkTaxAmountCount;
                    try {
                        bdkTaxAmountCount = baseTDxDkCountDetail.getBdkTaxAmountCount();
                        BigDecimal amountCount = new BigDecimal(bdkTaxAmountCount);
                        bdkTaxAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        bdkTaxAmountCount = "-";
                    }
                    td.setBdkTaxAmountCount(bdkTaxAmountCount);
                    String dkAmountCount;
                    try {
                        dkAmountCount = baseTDxDkCountDetail.getDkAmountCount();
                        BigDecimal amountCount = new BigDecimal(dkAmountCount);
                        dkAmountCount = AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        dkAmountCount = "-";
                    }
                    td.setDkAmountCount(dkAmountCount);
                    String dkInvoiceCount;
                    try {
                        dkInvoiceCount = baseTDxDkCountDetail.getDkInvoiceCount();
                        BigDecimal amountCount = new BigDecimal(dkInvoiceCount);
                        dkInvoiceCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
                    } catch (Exception e) {
                        dkInvoiceCount = "-";
                    }
                    td.setDkInvoiceCount(dkInvoiceCount);
                    String dkTaxAmountCount;
                    try {
                        dkTaxAmountCount = baseTDxDkCountDetail.getDkTaxAmountCount();
                        BigDecimal amountCount = new BigDecimal(dkTaxAmountCount);
                        dkTaxAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        dkTaxAmountCount = "-";
                    }
                    td.setDkTaxAmountCount(dkTaxAmountCount);
                    td.setTaxno(baseTDxDkCountDetail.getTaxno());
                    String tjDate = baseTDxDkCountDetail.getTjDate();
                    Date date = sdf.parse(tjDate);
                    td.setTjDate(sdf1.format(date));
                    tjdate = sdf1.format(date);
                    td.setTjMonth(baseTDxDkCountDetail.getTjMonth());
                    tjmonth = baseTDxDkCountDetail.getTjMonth();
                    for (Tax t : taxList) {
                        String taxno = t.getTaxno();
                        if (td.getTaxno().equals(taxno)) {
                            td.setTaxName(t.getTaxname());
                            taxName = t.getTaxname();
                        }
                    }
                    if (baseTDxDkCountDetail.getInvoiceType().equals(DktjmxzjEnum.ZJ.getDktjmxzjDm())) {
                        td.setInvoiceType(DktjmxzjEnum.ZJ.getDktjmxzjMc(DktjmxzjEnum.ZJ.getIndex()));
                    } else {
                        for (FplxEnum e : FplxEnum.values()) {
                            if (e.getFplxDm().equals(baseTDxDkCountDetail.getInvoiceType())) {
                                td.setInvoiceType(e.getFplxMc(e.getIndex()));
                            }
                        }
                    }
                    list.add(td);
                }
            }
        }

        if (sb.indexOf("08") < 0) {
            BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
            td.setBdkAmountCount("0.00");
            td.setBdkInvoiceCount("0");
            td.setBdkTaxAmountCount("0.00");
            td.setDkAmountCount("0.00");
            td.setDkInvoiceCount("0");
            td.setDkTaxAmountCount("0.00");
            td.setTaxno((String)pramsMap.get("gfsh"));
            td.setTjDate(tjdate);
            td.setTjMonth(tjmonth);
            td.setTaxName(taxName);
            td.setInvoiceType("增值税电子专用发票");
            list.add(td);
        } else {
            for (BaseTDxDkCountDetail baseTDxDkCountDetail : dkList) {
                if ("08".equals(baseTDxDkCountDetail.getInvoiceType())) {
                    BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
                    sb.add(baseTDxDkCountDetail.getInvoiceType());
                    String bdkAmountCount;
                    try {
                        bdkAmountCount = baseTDxDkCountDetail.getBdkAmountCount();
                        BigDecimal amountCount = new BigDecimal(bdkAmountCount);
                        bdkAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        bdkAmountCount = "-";
                    }
                    td.setBdkAmountCount(bdkAmountCount);
                    String bdkInvoiceCount;
                    try {
                        bdkInvoiceCount = baseTDxDkCountDetail.getBdkInvoiceCount();
                        BigDecimal amountCount = new BigDecimal(bdkInvoiceCount);
                        bdkInvoiceCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
                    } catch (Exception e) {
                        bdkInvoiceCount = "-";
                    }
                    td.setBdkInvoiceCount(bdkInvoiceCount);
                    String bdkTaxAmountCount;
                    try {
                        bdkTaxAmountCount = baseTDxDkCountDetail.getBdkTaxAmountCount();
                        BigDecimal amountCount = new BigDecimal(bdkTaxAmountCount);
                        bdkTaxAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        bdkTaxAmountCount = "-";
                    }
                    td.setBdkTaxAmountCount(bdkTaxAmountCount);
                    String dkAmountCount;
                    try {
                        dkAmountCount = baseTDxDkCountDetail.getDkAmountCount();
                        BigDecimal amountCount = new BigDecimal(dkAmountCount);
                        dkAmountCount = AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        dkAmountCount = "-";
                    }
                    td.setDkAmountCount(dkAmountCount);
                    String dkInvoiceCount;
                    try {
                        dkInvoiceCount = baseTDxDkCountDetail.getDkInvoiceCount();
                        BigDecimal amountCount = new BigDecimal(dkInvoiceCount);
                        dkInvoiceCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
                    } catch (Exception e) {
                        dkInvoiceCount = "-";
                    }
                    td.setDkInvoiceCount(dkInvoiceCount);
                    String dkTaxAmountCount;
                    try {
                        dkTaxAmountCount = baseTDxDkCountDetail.getDkTaxAmountCount();
                        BigDecimal amountCount = new BigDecimal(dkTaxAmountCount);
                        dkTaxAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        dkTaxAmountCount = "-";
                    }
                    td.setDkTaxAmountCount(dkTaxAmountCount);
                    td.setTaxno(baseTDxDkCountDetail.getTaxno());
                    String tjDate = baseTDxDkCountDetail.getTjDate();
                    Date date = sdf.parse(tjDate);
                    td.setTjDate(sdf1.format(date));
                    tjdate = sdf1.format(date);
                    td.setTjMonth(baseTDxDkCountDetail.getTjMonth());
                    tjmonth = baseTDxDkCountDetail.getTjMonth();
                    for (Tax t : taxList) {
                        String taxno = t.getTaxno();
                        if (td.getTaxno().equals(taxno)) {
                            td.setTaxName(t.getTaxname());
                            taxName = t.getTaxname();
                        }
                    }
                    if (baseTDxDkCountDetail.getInvoiceType().equals(DktjmxzjEnum.ZJ.getDktjmxzjDm())) {
                        td.setInvoiceType(DktjmxzjEnum.ZJ.getDktjmxzjMc(DktjmxzjEnum.ZJ.getIndex()));
                    } else {
                        td.setInvoiceType("增值税电子专用发票");

                    }
                    list.add(td);
                }
            }
        }

//            if (sb.indexOf("31") < 0) {
//                BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
//                td.setBdkAmountCount("0.00");
//                td.setBdkInvoiceCount("0");
//                td.setBdkTaxAmountCount("0.00");
//                td.setDkAmountCount("0.00");
//                td.setDkInvoiceCount("0");
//                td.setDkTaxAmountCount("0.00");
//                td.setTaxno((String)pramsMap.get("gfsh"));
//                td.setTjDate(tjdate);
//                td.setTjMonth(tjmonth);
//                td.setTaxName(taxName);
//                td.setInvoiceType("电子发票（增值税专用发票）");
//                list.add(td);
//            } else {
//                for (BaseTDxDkCountDetail baseTDxDkCountDetail : dkList) {
//                    if ("31".equals(baseTDxDkCountDetail.getInvoiceType())) {
//                        BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
//                        sb.add(baseTDxDkCountDetail.getInvoiceType());
//                        String bdkAmountCount;
//                        try {
//                            bdkAmountCount = baseTDxDkCountDetail.getBdkAmountCount();
//                            BigDecimal amountCount = new BigDecimal(bdkAmountCount);
//                            bdkAmountCount =
//                                    AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
//                        } catch (Exception e) {
//                            bdkAmountCount = "-";
//                        }
//                        td.setBdkAmountCount(bdkAmountCount);
//                        String bdkInvoiceCount;
//                        try {
//                            bdkInvoiceCount = baseTDxDkCountDetail.getBdkInvoiceCount();
//                            BigDecimal amountCount = new BigDecimal(bdkInvoiceCount);
//                            bdkInvoiceCount =
//                                    AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
//                        } catch (Exception e) {
//                            bdkInvoiceCount = "-";
//                        }
//                        td.setBdkInvoiceCount(bdkInvoiceCount);
//                        String bdkTaxAmountCount;
//                        try {
//                            bdkTaxAmountCount = baseTDxDkCountDetail.getBdkTaxAmountCount();
//                            BigDecimal amountCount = new BigDecimal(bdkTaxAmountCount);
//                            bdkTaxAmountCount =
//                                    AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
//                        } catch (Exception e) {
//                            bdkTaxAmountCount = "-";
//                        }
//                        td.setBdkTaxAmountCount(bdkTaxAmountCount);
//                        String dkAmountCount;
//                        try {
//                            dkAmountCount = baseTDxDkCountDetail.getDkAmountCount();
//                            BigDecimal amountCount = new BigDecimal(dkAmountCount);
//                            dkAmountCount = AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
//                        } catch (Exception e) {
//                            dkAmountCount = "-";
//                        }
//                        td.setDkAmountCount(dkAmountCount);
//                        String dkInvoiceCount;
//                        try {
//                            dkInvoiceCount = baseTDxDkCountDetail.getDkInvoiceCount();
//                            BigDecimal amountCount = new BigDecimal(dkInvoiceCount);
//                            dkInvoiceCount =
//                                    AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
//                        } catch (Exception e) {
//                            dkInvoiceCount = "-";
//                        }
//                        td.setDkInvoiceCount(dkInvoiceCount);
//                        String dkTaxAmountCount;
//                        try {
//                            dkTaxAmountCount = baseTDxDkCountDetail.getDkTaxAmountCount();
//                            BigDecimal amountCount = new BigDecimal(dkTaxAmountCount);
//                            dkTaxAmountCount =
//                                    AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
//                        } catch (Exception e) {
//                            dkTaxAmountCount = "-";
//                        }
//                        td.setDkTaxAmountCount(dkTaxAmountCount);
//                        td.setTaxno(baseTDxDkCountDetail.getTaxno());
//                        String tjDate = baseTDxDkCountDetail.getTjDate();
//                        Date date = sdf.parse(tjDate);
//                        td.setTjDate(sdf1.format(date));
//                        tjdate = sdf1.format(date);
//                        td.setTjMonth(baseTDxDkCountDetail.getTjMonth());
//                        tjmonth = baseTDxDkCountDetail.getTjMonth();
//                        for (Tax t : taxList) {
//                            String taxno = t.getTaxno();
//                            if (td.getTaxno().equals(taxno)) {
//                                td.setTaxName(t.getTaxname());
//                                taxName = t.getTaxname();
//                            }
//                        }
//                        if (baseTDxDkCountDetail.getInvoiceType().equals(DktjmxzjEnum.ZJ.getDktjmxzjDm())) {
//                            td.setInvoiceType(DktjmxzjEnum.ZJ.getDktjmxzjMc(DktjmxzjEnum.ZJ.getIndex()));
//                        } else {
//                            td.setInvoiceType("电子发票（增值税专用发票）");
//
//                        }
//                        list.add(td);
//                    }
//                }
//            }
        if (sb.indexOf("14") < 0) {
            BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
            td.setBdkAmountCount("0.00");
            td.setBdkInvoiceCount("0");
            td.setBdkTaxAmountCount("0.00");
            td.setDkAmountCount("0.00");
            td.setDkInvoiceCount("0");
            td.setDkTaxAmountCount("0.00");
            td.setTaxno((String)pramsMap.get("gfsh"));
            td.setTjDate(tjdate);
            td.setTjMonth(tjmonth);
            td.setTaxName(taxName);
            td.setInvoiceType("通行费电子发票");
            list.add(td);
        } else {
            for (BaseTDxDkCountDetail baseTDxDkCountDetail : dkList) {
                if ("14".equals(baseTDxDkCountDetail.getInvoiceType())) {
                    BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
                    sb.add(baseTDxDkCountDetail.getInvoiceType());
                    String bdkAmountCount;
                    try {
                        bdkAmountCount = baseTDxDkCountDetail.getBdkAmountCount();
                        BigDecimal amountCount = new BigDecimal(bdkAmountCount);
                        bdkAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        bdkAmountCount = "-";
                    }
                    td.setBdkAmountCount(bdkAmountCount);
                    String bdkInvoiceCount;
                    try {
                        bdkInvoiceCount = baseTDxDkCountDetail.getBdkInvoiceCount();
                        BigDecimal amountCount = new BigDecimal(bdkInvoiceCount);
                        bdkInvoiceCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
                    } catch (Exception e) {
                        bdkInvoiceCount = "-";
                    }
                    td.setBdkInvoiceCount(bdkInvoiceCount);
                    String bdkTaxAmountCount;
                    try {
                        bdkTaxAmountCount = baseTDxDkCountDetail.getBdkTaxAmountCount();
                        BigDecimal amountCount = new BigDecimal(bdkTaxAmountCount);
                        bdkTaxAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        bdkTaxAmountCount = "-";
                    }
                    td.setBdkTaxAmountCount(bdkTaxAmountCount);
                    String dkAmountCount;
                    try {
                        dkAmountCount = baseTDxDkCountDetail.getDkAmountCount();
                        BigDecimal amountCount = new BigDecimal(dkAmountCount);
                        dkAmountCount = AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        dkAmountCount = "-";
                    }
                    td.setDkAmountCount(dkAmountCount);
                    String dkInvoiceCount;
                    try {
                        dkInvoiceCount = baseTDxDkCountDetail.getDkInvoiceCount();
                        BigDecimal amountCount = new BigDecimal(dkInvoiceCount);
                        dkInvoiceCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
                    } catch (Exception e) {
                        dkInvoiceCount = "-";
                    }
                    td.setDkInvoiceCount(dkInvoiceCount);
                    String dkTaxAmountCount;
                    try {
                        dkTaxAmountCount = baseTDxDkCountDetail.getDkTaxAmountCount();
                        BigDecimal amountCount = new BigDecimal(dkTaxAmountCount);
                        dkTaxAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        dkTaxAmountCount = "-";
                    }
                    td.setDkTaxAmountCount(dkTaxAmountCount);
                    td.setTaxno(baseTDxDkCountDetail.getTaxno());
                    String tjDate = baseTDxDkCountDetail.getTjDate();
                    Date date = sdf.parse(tjDate);
                    td.setTjDate(sdf1.format(date));
                    tjdate = sdf1.format(date);
                    td.setTjMonth(baseTDxDkCountDetail.getTjMonth());
                    tjmonth = baseTDxDkCountDetail.getTjMonth();
                    for (Tax t : taxList) {
                        String taxno = t.getTaxno();
                        if (td.getTaxno().equals(taxno)) {
                            td.setTaxName(t.getTaxname());
                            taxName = t.getTaxname();
                        }
                    }
                    if (baseTDxDkCountDetail.getInvoiceType().equals(DktjmxzjEnum.ZJ.getDktjmxzjDm())) {
                        td.setInvoiceType(DktjmxzjEnum.ZJ.getDktjmxzjMc(DktjmxzjEnum.ZJ.getIndex()));
                    } else {
                        td.setInvoiceType("通行费电子发票");

                    }
                    list.add(td);
                }
            }
        }
        if (sb.indexOf("17") < 0) {
            BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
            td.setBdkAmountCount("-");
            td.setBdkInvoiceCount("0");
            td.setBdkTaxAmountCount("0.00");
            td.setDkAmountCount("-");
            td.setDkInvoiceCount("0");
            td.setDkTaxAmountCount("0.00");
            td.setTaxno((String)pramsMap.get("gfsh"));
            td.setTjDate(tjdate);
            td.setTjMonth(tjmonth);
            td.setTaxName(taxName);
            td.setInvoiceType("海关缴款书");
            list.add(td);
        } else {
            for (BaseTDxDkCountDetail baseTDxDkCountDetail : dkList) {
                if ("17".equals(baseTDxDkCountDetail.getInvoiceType())) {
                    BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
                    sb.add(baseTDxDkCountDetail.getInvoiceType());
                    String bdkAmountCount;
                    try {
                        bdkAmountCount = baseTDxDkCountDetail.getBdkAmountCount();
                        BigDecimal amountCount = new BigDecimal(bdkAmountCount);
                        bdkAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        bdkAmountCount = "-";
                    }
                    td.setBdkAmountCount(bdkAmountCount);
                    String bdkInvoiceCount;
                    try {
                        bdkInvoiceCount = baseTDxDkCountDetail.getBdkInvoiceCount();
                        BigDecimal amountCount = new BigDecimal(bdkInvoiceCount);
                        bdkInvoiceCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
                    } catch (Exception e) {
                        bdkInvoiceCount = "-";
                    }
                    td.setBdkInvoiceCount(bdkInvoiceCount);
                    String bdkTaxAmountCount;
                    try {
                        bdkTaxAmountCount = baseTDxDkCountDetail.getBdkTaxAmountCount();
                        BigDecimal amountCount = new BigDecimal(bdkTaxAmountCount);
                        bdkTaxAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        bdkTaxAmountCount = "-";
                    }
                    td.setBdkTaxAmountCount(bdkTaxAmountCount);
                    String dkAmountCount;
                    try {
                        dkAmountCount = baseTDxDkCountDetail.getDkAmountCount();
                        BigDecimal amountCount = new BigDecimal(dkAmountCount);
                        dkAmountCount = AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        dkAmountCount = "-";
                    }
                    td.setDkAmountCount(dkAmountCount);
                    String dkInvoiceCount;
                    try {
                        dkInvoiceCount = baseTDxDkCountDetail.getDkInvoiceCount();
                        BigDecimal amountCount = new BigDecimal(dkInvoiceCount);
                        dkInvoiceCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
                    } catch (Exception e) {
                        dkInvoiceCount = "-";
                    }
                    td.setDkInvoiceCount(dkInvoiceCount);
                    String dkTaxAmountCount;
                    try {
                        dkTaxAmountCount = baseTDxDkCountDetail.getDkTaxAmountCount();
                        BigDecimal amountCount = new BigDecimal(dkTaxAmountCount);
                        dkTaxAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        dkTaxAmountCount = "-";
                    }
                    td.setDkTaxAmountCount(dkTaxAmountCount);
                    td.setTaxno(baseTDxDkCountDetail.getTaxno());
                    String tjDate = baseTDxDkCountDetail.getTjDate();
                    Date date = sdf.parse(tjDate);
                    td.setTjDate(sdf1.format(date));
                    tjdate = sdf1.format(date);
                    td.setTjMonth(baseTDxDkCountDetail.getTjMonth());
                    tjmonth = baseTDxDkCountDetail.getTjMonth();
                    for (Tax t : taxList) {
                        String taxno = t.getTaxno();
                        if (td.getTaxno().equals(taxno)) {
                            td.setTaxName(t.getTaxname());
                            taxName = t.getTaxname();
                        }
                    }
                    td.setInvoiceType("海关缴款书");
                    list.add(td);
                }
            }
        }
        if (sb.indexOf("24") < 0) {
            BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
            td.setBdkAmountCount("0.00");
            td.setBdkInvoiceCount("0");
            td.setBdkTaxAmountCount("0.00");
            td.setDkAmountCount("0.00");
            td.setDkInvoiceCount("0");
            td.setDkTaxAmountCount("0.00");
            td.setTaxno((String)pramsMap.get("gfsh"));
            td.setTjDate(tjdate);
            td.setTjMonth(tjmonth);
            td.setTaxName(taxName);
            td.setInvoiceType("出口转内销发票");
            list.add(td);
        } else {
            for (BaseTDxDkCountDetail baseTDxDkCountDetail : dkList) {
                if ("24".equals(baseTDxDkCountDetail.getInvoiceType())) {
                    BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
                    sb.add(baseTDxDkCountDetail.getInvoiceType());
                    String bdkAmountCount;
                    try {
                        bdkAmountCount = baseTDxDkCountDetail.getBdkAmountCount();
                        BigDecimal amountCount = new BigDecimal(bdkAmountCount);
                        bdkAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        bdkAmountCount = "-";
                    }
                    td.setBdkAmountCount(bdkAmountCount);
                    String bdkInvoiceCount;
                    try {
                        bdkInvoiceCount = baseTDxDkCountDetail.getBdkInvoiceCount();
                        BigDecimal amountCount = new BigDecimal(bdkInvoiceCount);
                        bdkInvoiceCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
                    } catch (Exception e) {
                        bdkInvoiceCount = "-";
                    }
                    td.setBdkInvoiceCount(bdkInvoiceCount);
                    String bdkTaxAmountCount;
                    try {
                        bdkTaxAmountCount = baseTDxDkCountDetail.getBdkTaxAmountCount();
                        BigDecimal amountCount = new BigDecimal(bdkTaxAmountCount);
                        bdkTaxAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        bdkTaxAmountCount = "-";
                    }
                    td.setBdkTaxAmountCount(bdkTaxAmountCount);
                    String dkAmountCount;
                    try {
                        dkAmountCount = baseTDxDkCountDetail.getDkAmountCount();
                        BigDecimal amountCount = new BigDecimal(dkAmountCount);
                        dkAmountCount = AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        dkAmountCount = "-";
                    }
                    td.setDkAmountCount(dkAmountCount);
                    String dkInvoiceCount;
                    try {
                        dkInvoiceCount = baseTDxDkCountDetail.getDkInvoiceCount();
                        BigDecimal amountCount = new BigDecimal(dkInvoiceCount);
                        dkInvoiceCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
                    } catch (Exception e) {
                        dkInvoiceCount = "-";
                    }
                    td.setDkInvoiceCount(dkInvoiceCount);
                    String dkTaxAmountCount;
                    try {
                        dkTaxAmountCount = baseTDxDkCountDetail.getDkTaxAmountCount();
                        BigDecimal amountCount = new BigDecimal(dkTaxAmountCount);
                        dkTaxAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        dkTaxAmountCount = "-";
                    }
                    td.setDkTaxAmountCount(dkTaxAmountCount);
                    td.setTaxno(baseTDxDkCountDetail.getTaxno());
                    String tjDate = baseTDxDkCountDetail.getTjDate();
                    Date date = sdf.parse(tjDate);
                    td.setTjDate(sdf1.format(date));
                    tjdate = sdf1.format(date);
                    td.setTjMonth(baseTDxDkCountDetail.getTjMonth());
                    tjmonth = baseTDxDkCountDetail.getTjMonth();
                    for (Tax t : taxList) {
                        String taxno = t.getTaxno();
                        if (td.getTaxno().equals(taxno)) {
                            td.setTaxName(t.getTaxname());
                            taxName = t.getTaxname();
                        }
                    }
                    td.setInvoiceType("出口转内销发票");
                    list.add(td);
                }
            }
        }
        if (sb.indexOf("30") < 0) {
            BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
            td.setBdkAmountCount("-");
            td.setBdkInvoiceCount("0");
            td.setBdkTaxAmountCount("0.00");
            td.setDkAmountCount("-");
            td.setDkInvoiceCount("0");
            td.setDkTaxAmountCount("0.00");
            td.setTaxno((String)pramsMap.get("gfsh"));
            td.setTjDate(tjdate);
            td.setTjMonth(tjmonth);
            td.setTaxName(taxName);
            td.setInvoiceType("出口转内销海关缴款书");
            list.add(td);
        } else {
            for (BaseTDxDkCountDetail baseTDxDkCountDetail : dkList) {
                if ("30".equals(baseTDxDkCountDetail.getInvoiceType())) {
                    BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
                    sb.add(baseTDxDkCountDetail.getInvoiceType());
                    String bdkAmountCount;
                    try {
                        bdkAmountCount = baseTDxDkCountDetail.getBdkAmountCount();
                        BigDecimal amountCount = new BigDecimal(bdkAmountCount);
                        bdkAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        bdkAmountCount = "-";
                    }
                    td.setBdkAmountCount(bdkAmountCount);
                    String bdkInvoiceCount;
                    try {
                        bdkInvoiceCount = baseTDxDkCountDetail.getBdkInvoiceCount();
                        BigDecimal amountCount = new BigDecimal(bdkInvoiceCount);
                        bdkInvoiceCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
                    } catch (Exception e) {
                        bdkInvoiceCount = "-";
                    }
                    td.setBdkInvoiceCount(bdkInvoiceCount);
                    String bdkTaxAmountCount;
                    try {
                        bdkTaxAmountCount = baseTDxDkCountDetail.getBdkTaxAmountCount();
                        BigDecimal amountCount = new BigDecimal(bdkTaxAmountCount);
                        bdkTaxAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        bdkTaxAmountCount = "-";
                    }
                    td.setBdkTaxAmountCount(bdkTaxAmountCount);
                    String dkAmountCount;
                    try {
                        dkAmountCount = baseTDxDkCountDetail.getDkAmountCount();
                        BigDecimal amountCount = new BigDecimal(dkAmountCount);
                        dkAmountCount = AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        dkAmountCount = "-";
                    }
                    td.setDkAmountCount(dkAmountCount);
                    String dkInvoiceCount;
                    try {
                        dkInvoiceCount = baseTDxDkCountDetail.getDkInvoiceCount();
                        BigDecimal amountCount = new BigDecimal(dkInvoiceCount);
                        dkInvoiceCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
                    } catch (Exception e) {
                        dkInvoiceCount = "-";
                    }
                    td.setDkInvoiceCount(dkInvoiceCount);
                    String dkTaxAmountCount;
                    try {
                        dkTaxAmountCount = baseTDxDkCountDetail.getDkTaxAmountCount();
                        BigDecimal amountCount = new BigDecimal(dkTaxAmountCount);
                        dkTaxAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        dkTaxAmountCount = "-";
                    }
                    td.setDkTaxAmountCount(dkTaxAmountCount);
                    td.setTaxno(baseTDxDkCountDetail.getTaxno());
                    String tjDate = baseTDxDkCountDetail.getTjDate();
                    Date date = sdf.parse(tjDate);
                    td.setTjDate(sdf1.format(date));
                    tjdate = sdf1.format(date);
                    td.setTjMonth(baseTDxDkCountDetail.getTjMonth());
                    tjmonth = baseTDxDkCountDetail.getTjMonth();
                    for (Tax t : taxList) {
                        String taxno = t.getTaxno();
                        if (td.getTaxno().equals(taxno)) {
                            td.setTaxName(t.getTaxname());
                            taxName = t.getTaxname();
                        }
                    }
                    td.setInvoiceType("出口转内销海关缴款书");
                    list.add(td);
                }
            }
        }

        if (sb.indexOf("80") < 0) {
            BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
            td.setBdkAmountCount("0.00");
            td.setBdkInvoiceCount("0");
            td.setBdkTaxAmountCount("0.00");
            td.setDkAmountCount("0.00");
            td.setDkInvoiceCount("0");
            td.setDkTaxAmountCount("0.00");
            td.setTaxno((String)pramsMap.get("gfsh"));
            td.setTjDate(tjdate);
            td.setTjMonth(tjmonth);
            td.setTaxName(taxName);
            td.setInvoiceType("出口转内销专用电子发票");
            list.add(td);
        } else {
            for (BaseTDxDkCountDetail baseTDxDkCountDetail : dkList) {
                if ("80".equals(baseTDxDkCountDetail.getInvoiceType())) {
                    BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
                    sb.add(baseTDxDkCountDetail.getInvoiceType());
                    String bdkAmountCount;
                    try {
                        bdkAmountCount = baseTDxDkCountDetail.getBdkAmountCount();
                        BigDecimal amountCount = new BigDecimal(bdkAmountCount);
                        bdkAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        bdkAmountCount = "-";
                    }
                    td.setBdkAmountCount(bdkAmountCount);
                    String bdkInvoiceCount;
                    try {
                        bdkInvoiceCount = baseTDxDkCountDetail.getBdkInvoiceCount();
                        BigDecimal amountCount = new BigDecimal(bdkInvoiceCount);
                        bdkInvoiceCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
                    } catch (Exception e) {
                        bdkInvoiceCount = "-";
                    }
                    td.setBdkInvoiceCount(bdkInvoiceCount);
                    String bdkTaxAmountCount;
                    try {
                        bdkTaxAmountCount = baseTDxDkCountDetail.getBdkTaxAmountCount();
                        BigDecimal amountCount = new BigDecimal(bdkTaxAmountCount);
                        bdkTaxAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        bdkTaxAmountCount = "-";
                    }
                    td.setBdkTaxAmountCount(bdkTaxAmountCount);
                    String dkAmountCount;
                    try {
                        dkAmountCount = baseTDxDkCountDetail.getDkAmountCount();
                        BigDecimal amountCount = new BigDecimal(dkAmountCount);
                        dkAmountCount = AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        dkAmountCount = "-";
                    }
                    td.setDkAmountCount(dkAmountCount);
                    String dkInvoiceCount;
                    try {
                        dkInvoiceCount = baseTDxDkCountDetail.getDkInvoiceCount();
                        BigDecimal amountCount = new BigDecimal(dkInvoiceCount);
                        dkInvoiceCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
                    } catch (Exception e) {
                        dkInvoiceCount = "-";
                    }
                    td.setDkInvoiceCount(dkInvoiceCount);
                    String dkTaxAmountCount;
                    try {
                        dkTaxAmountCount = baseTDxDkCountDetail.getDkTaxAmountCount();
                        BigDecimal amountCount = new BigDecimal(dkTaxAmountCount);
                        dkTaxAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        dkTaxAmountCount = "-";
                    }
                    td.setDkTaxAmountCount(dkTaxAmountCount);
                    td.setTaxno(baseTDxDkCountDetail.getTaxno());
                    String tjDate = baseTDxDkCountDetail.getTjDate();
                    Date date = sdf.parse(tjDate);
                    td.setTjDate(sdf1.format(date));
                    td.setTjMonth(baseTDxDkCountDetail.getTjMonth());
                    for (Tax t : taxList) {
                        String taxno = t.getTaxno();
                        if (td.getTaxno().equals(taxno)) {
                            td.setTaxName(t.getTaxname());
                        }
                    }
                    td.setInvoiceType("出口转内销专用电子发票");
                    list.add(td);
                }
            }
        }

        if (sb.indexOf("1") < 0) {
            BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
            td.setBdkAmountCount("0.00");
            td.setBdkInvoiceCount("0");
            td.setBdkTaxAmountCount("0.00");
            td.setDkAmountCount("0.00");
            td.setDkInvoiceCount("0");
            td.setDkTaxAmountCount("0.00");
            td.setTaxno((String)pramsMap.get("gfsh"));
            td.setTjDate(tjdate);
            td.setTjMonth(tjmonth);
            td.setTaxName(taxName);
            td.setInvoiceType("收购发票");
            list.add(td);
        } else {
            for (BaseTDxDkCountDetail baseTDxDkCountDetail : dkList) {
                if ("1".equals(baseTDxDkCountDetail.getInvoiceType())) {
                    createAddTd(sb,baseTDxDkCountDetail,taxList,list,"收购发票");
                }
            }
        }

        if (sb.indexOf("2") < 0) {
            BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
            td.setBdkAmountCount("0.00");
            td.setBdkInvoiceCount("0");
            td.setBdkTaxAmountCount("0.00");
            td.setDkAmountCount("0.00");
            td.setDkInvoiceCount("0");
            td.setDkTaxAmountCount("0.00");
            td.setTaxno((String)pramsMap.get("gfsh"));
            td.setTjDate(tjdate);
            td.setTjMonth(tjmonth);
            td.setTaxName(taxName);
            td.setInvoiceType("免税自产农产品普通发票");
            list.add(td);
        } else {
            for (BaseTDxDkCountDetail baseTDxDkCountDetail : dkList) {
                if ("2".equals(baseTDxDkCountDetail.getInvoiceType())) {
                    createAddTd(sb,baseTDxDkCountDetail,taxList,list,"免税自产农产品普通发票");
                }
            }
        }

        if (sb.indexOf("4") < 0) {
            BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
            td.setBdkAmountCount("0.00");
            td.setBdkInvoiceCount("0");
            td.setBdkTaxAmountCount("0.00");
            td.setDkAmountCount("0.00");
            td.setDkInvoiceCount("0");
            td.setDkTaxAmountCount("0.00");
            td.setTaxno((String)pramsMap.get("gfsh"));
            td.setTjDate(tjdate);
            td.setTjMonth(tjmonth);
            td.setTaxName(taxName);
            td.setInvoiceType("其他普通发票");
            list.add(td);
        } else {
            for (BaseTDxDkCountDetail baseTDxDkCountDetail : dkList) {
                if ("4".equals(baseTDxDkCountDetail.getInvoiceType())) {
                    createAddTd(sb,baseTDxDkCountDetail,taxList,list,"其他普通发票");
                }
            }
        }

        if (sb.indexOf("7") < 0) {
            BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
            td.setBdkAmountCount("0.00");
            td.setBdkInvoiceCount("0");
            td.setBdkTaxAmountCount("0.00");
            td.setDkAmountCount("0.00");
            td.setDkInvoiceCount("0");
            td.setDkTaxAmountCount("0.00");
            td.setTaxno((String)pramsMap.get("gfsh"));
            td.setTjDate(tjdate);
            td.setTjMonth(tjmonth);
            td.setTaxName(taxName);
            td.setInvoiceType("代扣代缴完税凭证");
            list.add(td);
        } else {
            for (BaseTDxDkCountDetail baseTDxDkCountDetail : dkList) {
                if ("7".equals(baseTDxDkCountDetail.getInvoiceType())) {
                    createAddTd(sb,baseTDxDkCountDetail,taxList,list,"代扣代缴完税凭证");
                }
            }
        }

        if (sb.indexOf("61") < 0) {
            BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
            td.setBdkAmountCount("0.00");
            td.setBdkInvoiceCount("0");
            td.setBdkTaxAmountCount("0.00");
            td.setDkAmountCount("0.00");
            td.setDkInvoiceCount("0");
            td.setDkTaxAmountCount("0.00");
            td.setTaxno((String)pramsMap.get("gfsh"));
            td.setTjDate(tjdate);
            td.setTjMonth(tjmonth);
            td.setTaxName(taxName);
            td.setInvoiceType("数电票（航空运输电子客票行程单）");
            list.add(td);
        } else {
            for (BaseTDxDkCountDetail baseTDxDkCountDetail : dkList) {
                if ("61".equals(baseTDxDkCountDetail.getInvoiceType())) {
                    BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
                    sb.add(baseTDxDkCountDetail.getInvoiceType());
                    String bdkAmountCount;
                    try {
                        bdkAmountCount = baseTDxDkCountDetail.getBdkAmountCount();
                        BigDecimal amountCount = new BigDecimal(bdkAmountCount);
                        bdkAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        bdkAmountCount = "-";
                    }
                    td.setBdkAmountCount(bdkAmountCount);
                    String bdkInvoiceCount;
                    try {
                        bdkInvoiceCount = baseTDxDkCountDetail.getBdkInvoiceCount();
                        BigDecimal amountCount = new BigDecimal(bdkInvoiceCount);
                        bdkInvoiceCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
                    } catch (Exception e) {
                        bdkInvoiceCount = "-";
                    }
                    td.setBdkInvoiceCount(bdkInvoiceCount);
                    String bdkTaxAmountCount;
                    try {
                        bdkTaxAmountCount = baseTDxDkCountDetail.getBdkTaxAmountCount();
                        BigDecimal amountCount = new BigDecimal(bdkTaxAmountCount);
                        bdkTaxAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        bdkTaxAmountCount = "-";
                    }
                    td.setBdkTaxAmountCount(bdkTaxAmountCount);
                    String dkAmountCount;
                    try {
                        dkAmountCount = baseTDxDkCountDetail.getDkAmountCount();
                        BigDecimal amountCount = new BigDecimal(dkAmountCount);
                        dkAmountCount = AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        dkAmountCount = "-";
                    }
                    td.setDkAmountCount(dkAmountCount);
                    String dkInvoiceCount;
                    try {
                        dkInvoiceCount = baseTDxDkCountDetail.getDkInvoiceCount();
                        BigDecimal amountCount = new BigDecimal(dkInvoiceCount);
                        dkInvoiceCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
                    } catch (Exception e) {
                        dkInvoiceCount = "-";
                    }
                    td.setDkInvoiceCount(dkInvoiceCount);
                    String dkTaxAmountCount;
                    try {
                        dkTaxAmountCount = baseTDxDkCountDetail.getDkTaxAmountCount();
                        BigDecimal amountCount = new BigDecimal(dkTaxAmountCount);
                        dkTaxAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        dkTaxAmountCount = "-";
                    }
                    td.setDkTaxAmountCount(dkTaxAmountCount);
                    td.setTaxno(baseTDxDkCountDetail.getTaxno());
                    String tjDate = baseTDxDkCountDetail.getTjDate();
                    Date date = sdf.parse(tjDate);
                    td.setTjDate(sdf1.format(date));
                    tjdate = sdf1.format(date);
                    td.setTjMonth(baseTDxDkCountDetail.getTjMonth());
                    tjmonth = baseTDxDkCountDetail.getTjMonth();
                    for (Tax t : taxList) {
                        String taxno = t.getTaxno();
                        if (td.getTaxno().equals(taxno)) {
                            td.setTaxName(t.getTaxname());
                            taxName = t.getTaxname();
                        }
                    }
                    if (baseTDxDkCountDetail.getInvoiceType().equals(DktjmxzjEnum.ZJ.getDktjmxzjDm())) {
                        td.setInvoiceType(DktjmxzjEnum.ZJ.getDktjmxzjMc(DktjmxzjEnum.ZJ.getIndex()));
                    } else {
                        td.setInvoiceType("数电票（航空运输电子客票行程单）");

                    }
                    list.add(td);
                }
            }
        }
        if (sb.indexOf("83") < 0) {
            BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
            td.setBdkAmountCount("0.00");
            td.setBdkInvoiceCount("0");
            td.setBdkTaxAmountCount("0.00");
            td.setDkAmountCount("0.00");
            td.setDkInvoiceCount("0");
            td.setDkTaxAmountCount("0.00");
            td.setTaxno((String)pramsMap.get("gfsh"));
            td.setTjDate(tjdate);
            td.setTjMonth(tjmonth);
            td.setTaxName(taxName);
            td.setInvoiceType("电子发票（铁路电子客票）");
            list.add(td);
        } else {
            for (BaseTDxDkCountDetail baseTDxDkCountDetail : dkList) {
                if ("83".equals(baseTDxDkCountDetail.getInvoiceType())) {
                    BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
                    sb.add(baseTDxDkCountDetail.getInvoiceType());
                    String bdkAmountCount;
                    try {
                        bdkAmountCount = baseTDxDkCountDetail.getBdkAmountCount();
                        BigDecimal amountCount = new BigDecimal(bdkAmountCount);
                        bdkAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        bdkAmountCount = "-";
                    }
                    td.setBdkAmountCount(bdkAmountCount);
                    String bdkInvoiceCount;
                    try {
                        bdkInvoiceCount = baseTDxDkCountDetail.getBdkInvoiceCount();
                        BigDecimal amountCount = new BigDecimal(bdkInvoiceCount);
                        bdkInvoiceCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
                    } catch (Exception e) {
                        bdkInvoiceCount = "-";
                    }
                    td.setBdkInvoiceCount(bdkInvoiceCount);
                    String bdkTaxAmountCount;
                    try {
                        bdkTaxAmountCount = baseTDxDkCountDetail.getBdkTaxAmountCount();
                        BigDecimal amountCount = new BigDecimal(bdkTaxAmountCount);
                        bdkTaxAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        bdkTaxAmountCount = "-";
                    }
                    td.setBdkTaxAmountCount(bdkTaxAmountCount);
                    String dkAmountCount;
                    try {
                        dkAmountCount = baseTDxDkCountDetail.getDkAmountCount();
                        BigDecimal amountCount = new BigDecimal(dkAmountCount);
                        dkAmountCount = AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        dkAmountCount = "-";
                    }
                    td.setDkAmountCount(dkAmountCount);
                    String dkInvoiceCount;
                    try {
                        dkInvoiceCount = baseTDxDkCountDetail.getDkInvoiceCount();
                        BigDecimal amountCount = new BigDecimal(dkInvoiceCount);
                        dkInvoiceCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
                    } catch (Exception e) {
                        dkInvoiceCount = "-";
                    }
                    td.setDkInvoiceCount(dkInvoiceCount);
                    String dkTaxAmountCount;
                    try {
                        dkTaxAmountCount = baseTDxDkCountDetail.getDkTaxAmountCount();
                        BigDecimal amountCount = new BigDecimal(dkTaxAmountCount);
                        dkTaxAmountCount =
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                    } catch (Exception e) {
                        dkTaxAmountCount = "-";
                    }
                    td.setDkTaxAmountCount(dkTaxAmountCount);
                    td.setTaxno(baseTDxDkCountDetail.getTaxno());
                    String tjDate = baseTDxDkCountDetail.getTjDate();
                    Date date = sdf.parse(tjDate);
                    td.setTjDate(sdf1.format(date));
                    tjdate = sdf1.format(date);
                    td.setTjMonth(baseTDxDkCountDetail.getTjMonth());
                    tjmonth = baseTDxDkCountDetail.getTjMonth();
                    for (Tax t : taxList) {
                        String taxno = t.getTaxno();
                        if (td.getTaxno().equals(taxno)) {
                            td.setTaxName(t.getTaxname());
                            taxName = t.getTaxname();
                        }
                    }
                    if (baseTDxDkCountDetail.getInvoiceType().equals(DktjmxzjEnum.ZJ.getDktjmxzjDm())) {
                        td.setInvoiceType(DktjmxzjEnum.ZJ.getDktjmxzjMc(DktjmxzjEnum.ZJ.getIndex()));
                    } else {
                        td.setInvoiceType("电子发票（铁路电子客票）");

                    }
                    list.add(td);
                }
            }
        }

        for (BaseTDxDkCountDetail baseTDxDkCountDetail : dkList) {
            if ("99".equals(baseTDxDkCountDetail.getInvoiceType())) {
                BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
                sb.add(baseTDxDkCountDetail.getInvoiceType());
                String bdkAmountCount;
                try {
                    bdkAmountCount = baseTDxDkCountDetail.getBdkAmountCount();
                    BigDecimal amountCount = new BigDecimal(bdkAmountCount);
                    bdkAmountCount = AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                } catch (Exception e) {
                    bdkAmountCount = "-";
                }
                td.setBdkAmountCount(bdkAmountCount);
                String bdkInvoiceCount;
                try {
                    bdkInvoiceCount = baseTDxDkCountDetail.getBdkInvoiceCount();
                    BigDecimal amountCount = new BigDecimal(bdkInvoiceCount);
                    bdkInvoiceCount =
                            AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
                } catch (Exception e) {
                    bdkInvoiceCount = "-";
                }
                td.setBdkInvoiceCount(bdkInvoiceCount);
                String bdkTaxAmountCount;
                try {
                    bdkTaxAmountCount = baseTDxDkCountDetail.getBdkTaxAmountCount();
                    BigDecimal amountCount = new BigDecimal(bdkTaxAmountCount);
                    bdkTaxAmountCount = AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                } catch (Exception e) {
                    bdkTaxAmountCount = "-";
                }
                td.setBdkTaxAmountCount(bdkTaxAmountCount);
                String dkAmountCount;
                try {
                    dkAmountCount = baseTDxDkCountDetail.getDkAmountCount();
                    BigDecimal amountCount = new BigDecimal(dkAmountCount);
                    dkAmountCount = AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                } catch (Exception e) {
                    dkAmountCount = "-";
                }
                td.setDkAmountCount(dkAmountCount);
                String dkInvoiceCount;
                try {
                    dkInvoiceCount = baseTDxDkCountDetail.getDkInvoiceCount();
                    BigDecimal amountCount = new BigDecimal(dkInvoiceCount);
                    dkInvoiceCount = AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
                } catch (Exception e) {
                    dkInvoiceCount = "-";
                }
                td.setDkInvoiceCount(dkInvoiceCount);
                String dkTaxAmountCount;
                try {
                    dkTaxAmountCount = baseTDxDkCountDetail.getDkTaxAmountCount();
                    BigDecimal amountCount = new BigDecimal(dkTaxAmountCount);
                    dkTaxAmountCount = AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
                } catch (Exception e) {
                    dkTaxAmountCount = "-";
                }
                td.setDkTaxAmountCount(dkTaxAmountCount);
                td.setTaxno(baseTDxDkCountDetail.getTaxno());
                String tjDate = baseTDxDkCountDetail.getTjDate();
                Date date = sdf.parse(tjDate);
                td.setTjDate(sdf1.format(date));
                td.setTjMonth(baseTDxDkCountDetail.getTjMonth());
                for (Tax t : taxList) {
                    String taxno = t.getTaxno();
                    if (td.getTaxno().equals(taxno)) {
                        td.setTaxName(t.getTaxname());
                    }
                }
                if (baseTDxDkCountDetail.getInvoiceType().equals(DktjmxzjEnum.ZJ.getDktjmxzjDm())) {
                    td.setInvoiceType(DktjmxzjEnum.ZJ.getDktjmxzjMc(DktjmxzjEnum.ZJ.getIndex()));
                } else {
                    for (FplxEnum e : FplxEnum.values()) {
                        if (e.getFplxDm().equals(baseTDxDkCountDetail.getInvoiceType())) {
                            td.setInvoiceType(e.getFplxMc(e.getIndex()));
                        }
                    }
                }
                list.add(td);
            }
        }
        return list;
    }

    private void createAddTd(List<String> sb, BaseTDxDkCountDetail baseTDxDkCountDetail, List<Tax> taxList, List<BaseTDxDkCountDetailRespVO> list, String invoiceTypeName) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy年MM月dd日HH时mm分ss秒");
        BaseTDxDkCountDetailRespVO td = new BaseTDxDkCountDetailRespVO();
        sb.add(baseTDxDkCountDetail.getInvoiceType());
        String bdkAmountCount;
        try {
            bdkAmountCount = baseTDxDkCountDetail.getBdkAmountCount();
            BigDecimal amountCount = new BigDecimal(bdkAmountCount);
            bdkAmountCount =
                    AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
        } catch (Exception e) {
            bdkAmountCount = "-";
        }
        td.setBdkAmountCount(bdkAmountCount);
        String bdkInvoiceCount;
        try {
            bdkInvoiceCount = baseTDxDkCountDetail.getBdkInvoiceCount();
            BigDecimal amountCount = new BigDecimal(bdkInvoiceCount);
            bdkInvoiceCount =
                    AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
        } catch (Exception e) {
            bdkInvoiceCount = "-";
        }
        td.setBdkInvoiceCount(bdkInvoiceCount);
        String bdkTaxAmountCount;
        try {
            bdkTaxAmountCount = baseTDxDkCountDetail.getBdkTaxAmountCount();
            BigDecimal amountCount = new BigDecimal(bdkTaxAmountCount);
            bdkTaxAmountCount =
                    AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
        } catch (Exception e) {
            bdkTaxAmountCount = "-";
        }
        td.setBdkTaxAmountCount(bdkTaxAmountCount);
        String dkAmountCount;
        try {
            dkAmountCount = baseTDxDkCountDetail.getDkAmountCount();
            BigDecimal amountCount = new BigDecimal(dkAmountCount);
            dkAmountCount = AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
        } catch (Exception e) {
            dkAmountCount = "-";
        }
        td.setDkAmountCount(dkAmountCount);
        String dkInvoiceCount;
        try {
            dkInvoiceCount = baseTDxDkCountDetail.getDkInvoiceCount();
            BigDecimal amountCount = new BigDecimal(dkInvoiceCount);
            dkInvoiceCount =
                    AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString(), 0));
        } catch (Exception e) {
            dkInvoiceCount = "-";
        }
        td.setDkInvoiceCount(dkInvoiceCount);
        String dkTaxAmountCount;
        try {
            dkTaxAmountCount = baseTDxDkCountDetail.getDkTaxAmountCount();
            BigDecimal amountCount = new BigDecimal(dkTaxAmountCount);
            dkTaxAmountCount =
                    AmountFormatUtil.fmtMicrometer(MathUtil.round(amountCount.toPlainString()));
        } catch (Exception e) {
            dkTaxAmountCount = "-";
        }
        td.setDkTaxAmountCount(dkTaxAmountCount);
        td.setTaxno(baseTDxDkCountDetail.getTaxno());
        String tjDate = baseTDxDkCountDetail.getTjDate();
        Date date = sdf.parse(tjDate);
        td.setTjDate(sdf1.format(date));
        td.setTjMonth(baseTDxDkCountDetail.getTjMonth());
        for (Tax t : taxList) {
            String taxno = t.getTaxno();
            if (td.getTaxno().equals(taxno)) {
                td.setTaxName(t.getTaxname());
            }
        }
        td.setInvoiceType(invoiceTypeName);
        list.add(td);
    }

    @Override
    public JSONObject selectCxtjHjxx(Map<String, Object> pramsMap) {

        JSONObject json = new JSONObject();

        String[] gfshs = pramsMap.get("gfshs").toString().split(",");
        String[] skssqs = pramsMap.get("skssqs").toString().split(",");

        String hjsl = "0";
        String hjje = "0.00";
        String hjse = "0.00";
        String sl = "0";
        String je = "0";
        String se = "0";

        for (int i = 0; i < gfshs.length; i++) {

            Map<String, Object> pramMap = new HashMap<>(16);
            pramMap.put("gfsh", gfshs[i]);
            pramMap.put("skssq", skssqs[i]);

            QueryWrapper<BaseTDxDkCountDetail> queryWrapper = new QueryWrapper<>();
            if (pramMap.containsKey("gfsh") && !StringHelper.isBlank(String.valueOf(pramMap.get("gfsh")))) {
                queryWrapper.eq("taxno", pramMap.get("gfsh"));
            }
            if (pramMap.containsKey("skssq") && !StringHelper.isBlank(String.valueOf(pramMap.get("skssq")))) {
                queryWrapper.eq("tj_month", pramMap.get("skssq"));
            }
            queryWrapper.eq("invoice_type", DktjmxzjEnum.ZJ.getDktjmxzjDm());
            List<BaseTDxDkCountDetail> dkList = list(queryWrapper);
            if (dkList != null && dkList.size() > 0) {
                String bdkAmount;
                String dkAmount;
                try {
                    bdkAmount = new BigDecimal(dkList.get(0).getBdkAmountCount()).toPlainString();
                } catch (Exception e) {
                    bdkAmount = "0";
                }
                try {
                    dkAmount = new BigDecimal(dkList.get(0).getDkAmountCount()).toPlainString();
                } catch (Exception e) {
                    dkAmount = "0";
                }
                sl = MathUtil.add(bdkAmount, dkAmount);
                String bdkInvoiceCount;
                String dkInvoiceCount;
                try {
                    bdkInvoiceCount = new BigDecimal(dkList.get(0).getBdkInvoiceCount()).toPlainString();
                } catch (Exception e) {
                    bdkInvoiceCount = "0";
                }
                try {
                    dkInvoiceCount = new BigDecimal(dkList.get(0).getDkInvoiceCount()).toPlainString();
                } catch (Exception e) {
                    dkInvoiceCount = "0";
                }
                je = MathUtil.add(bdkInvoiceCount, dkInvoiceCount);
                String bdkTaxAmount;
                String dkTaxAmount;
                try {
                    bdkTaxAmount = new BigDecimal(dkList.get(0).getBdkTaxAmountCount()).toPlainString();
                } catch (Exception e) {
                    bdkTaxAmount = "0";
                }
                try {
                    dkTaxAmount = new BigDecimal(dkList.get(0).getDkTaxAmountCount()).toPlainString();
                } catch (Exception e) {
                    dkTaxAmount = "0";
                }
                se = MathUtil.add(bdkTaxAmount, dkTaxAmount);
            }

        }
        hjsl = MathUtil.add(hjsl, sl).substring(0, 1);
        hjje = AmountFormatUtil.fmtMicrometer(MathUtil.round(MathUtil.add(hjje, je)));
        hjse = AmountFormatUtil.fmtMicrometer(MathUtil.round(MathUtil.add(hjse, se)));

        json.put("hjsl", hjsl);
        json.put("hjje", hjje);
        json.put("hjse", hjse);

        return json;
    }

}
