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

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.dxhy.api.model.invoice.ExtAddTaxInvoice;
import com.dxhy.api.model.invoice.ExtOtherInvoice;
import com.dxhy.api.model.invoice.InvoicePaperEntity;
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.util.MathUtil;
import com.dxhy.common.util.StringHelper;
import com.dxhy.core.dao.CorePoolPaperDao;
import com.dxhy.core.model.CompanyPoolJxVO;
import com.dxhy.core.service.export.PoolPaperService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 功能描述
 *
 * @author 陈刚扬
 * @date 2020/10/30
 */

@SuppressWarnings("AlibabaMethodTooLong")
@Service
public class PoolPaperServiceImpl extends MpBaseServiceImpl<CorePoolPaperDao, InvoicePaperEntity>
    implements PoolPaperService {

    @Resource
    private DictdetaServcice dictdetaServcice;

    /**
     * 票据导出查询
     *
     * @param pramsMap
     *            查询条件
     * @param curr
     *            分页
     * @param size
     *            条数
     * @return
     */
    @Override
    public JSONObject listPaperInvoice(Map<String, Object> pramsMap, int curr, int size) {
        DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);
        JSONObject json = new JSONObject();
        try {
            PageHelper.startPage(curr, size);
            List<InvoicePaperEntity> pageList = super.baseMapper.listPaperInvoice(pramsMap);
            PageInfo<InvoicePaperEntity> pageInfo = new PageInfo<>(pageList);
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());
            List<String[]> returnList = new ArrayList<>();
            // 用于页面返回list对象
            if (pageList != null && pageList.size() > 0) {
                for (int i = 0; i < pageList.size(); i++) {
                    String[] dataArray = new String[13];
                    dataArray[0] = String.valueOf((curr - 1) * size + i + 1);
                    // 发票类型
                    dataArray[1] = pageList.get(i).getCollectDate();
                    if ("0".equals(pageList.get(i).getCollectFrom())) {
                        dataArray[2] = "进项采集";
                    } else if ("1".equals(pageList.get(i).getCollectFrom())) {
                        dataArray[2] = "票据采集";
                    } else if ("4".equals(pageList.get(i).getCollectFrom())) {
                        dataArray[2] = "大企业归集";
                    } else {
                        dataArray[2] = "票据采集";
                    }
                    dataArray[3] = dictdetaServcice.queryDictName(DictConstant.INVOICE_TYPEALL, pageList.get(i).getInvoiceType());
                    dataArray[4] = pageList.get(i).getInvoiceCode();
                    dataArray[5] = pageList.get(i).getInvoiceNo();
                    dataArray[6] = pageList.get(i).getEleInvoiceNo();
                    dataArray[7] = pageList.get(i).getInvoiceDate();
                    dataArray[8] = pageList.get(i).getBuyerName();
                    dataArray[9] = pageList.get(i).getSaleName();
                    dataArray[10] = MathUtil.round(pageList.get(i).getInvoiceAmount());
                    dataArray[11] = MathUtil.round(pageList.get(i).getTaxAmount());
                    dataArray[12] = MathUtil.round(pageList.get(i).getTotalAmount());
                    returnList.add(dataArray);
                }
            }

            json.put("datalist", returnList);

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

        return json;
    }

    /**
     * 其他票据导出查询
     *
     * @param pramsMap
     * @param curr
     * @param size
     * @return
     */
    @Override
    public JSONObject listOtherInvoice(Map<String, Object> pramsMap, int curr, int size) {
        DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);
        JSONObject json = new JSONObject();
        try {
            PageHelper.startPage(curr, size);
            List<ExtOtherInvoice> pageList = super.baseMapper.listOtherInvoice(pramsMap);
            PageInfo<ExtOtherInvoice> pageInfo = new PageInfo<>(pageList);
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());
            List<String[]> returnList = new ArrayList<>();
            // 用于页面返回list对象
            if (pageList != null && pageList.size() > 0) {
                for (int i = 0; i < pageList.size(); i++) {
                    String[] dataArray = new String[13];
                    dataArray[0] = String.valueOf((curr - 1) * size + i + 1);
                    // 发票类型
                    dataArray[1] = dictdetaServcice.queryDictName(DictConstant.INVOICE_TYPEALL, pageList.get(i).getInvoiceType());
                    dataArray[2] = pageList.get(i).getInvoiceCode();
                    dataArray[3] = pageList.get(i).getInvoiceNo();
                    dataArray[4] = pageList.get(i).getInvoiceDate();
                    dataArray[5] = MathUtil.round(pageList.get(i).getInvoiceAmount());
                    for (FpqsjgEnum e : FpqsjgEnum.values()) {
                        if (e.getQsjgDm().equals(pageList.get(i).getQszt())) {
                            dataArray[6] = e.getQsjgMc(e.getIndex());
                        }
                    }
                    dataArray[7] = pageList.get(i).getQsrq();
                    for (QsfsEnum e : QsfsEnum.values()) {
                        if (e.getQsfsDm().equals(pageList.get(i).getQsfs())) {
                            String qsfs = e.getQsfsMc(e.getIndex());
                            if ("接口推送".equals(qsfs)) {
                                dataArray[8] = "接口签收";
                            } else {
                                dataArray[8] = qsfs;
                            }
                        }

                    }
                    dataArray[9] = pageList.get(i).getQsr();
                    dataArray[10] = pageList.get(i).getBusinessDocumentNumber();
                    dataArray[11] = pageList.get(i).getCreateDate();
                    returnList.add(dataArray);
                }
            }

            json.put("datalist", returnList);

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

        return json;
    }

    @Override
    public JSONObject listAddTaxInvoice(Map<String, Object> pramsMap, int curr, int size) {
        DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);
        JSONObject json = new JSONObject();
        try {
            PageHelper.startPage(curr, size);
            List<ExtAddTaxInvoice> pageList = super.baseMapper.listAddTaxInvoice(pramsMap);
            PageInfo<ExtAddTaxInvoice> pageInfo = new PageInfo<>(pageList);
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());
            List<String[]> returnList = new ArrayList<>();

            // 用于页面返回list对象
            if (pageList != null && pageList.size() > 0) {
                for (int i = 0; i < pageList.size(); i++) {
                    String[] dataArray = new String[40];
                    dataArray[0] = String.valueOf((curr - 1) * size + i + 1);
                    // 发票类型
                    dataArray[1] = dictdetaServcice.queryDictName(DictConstant.INVOICE_TYPEALL, pageList.get(i).getInvoiceType());
                    if(StringUtils.isBlank(pageList.get(i).getLqTdyslxDm())){
                        dataArray[2] = "非特定业务";
                    }else{
                        dataArray[2] = dictdetaServcice.queryDictName(DictConstant.TDYS_LXDM, pageList.get(i).getLqTdyslxDm());
                    }
                    dataArray[3] = pageList.get(i).getInvoiceCode();
                    dataArray[4] = pageList.get(i).getInvoiceNo();
                    dataArray[5] = pageList.get(i).getEleInvoiceNo();

                    for (FpztEnum e : FpztEnum.values()) {
                        if (e.getFpztDm().equals(pageList.get(i).getInvoiceStatus())) {
                            dataArray[6] = e.getFpztMc(e.getIndex());
                        }
                    }
                    dataArray[7] = pageList.get(i).getInvoiceDate();

                    //源文件设置   "源文件PDF", "源文件OFD", "源文件XML"
                    //源文件展示与否处理
                    String xmlFlag = pageList.get(i).getXmlFlag();
                    //pdf
                    if(xmlFlag.contains("2")||xmlFlag.contains("5")){
                        dataArray[8] = "有";
                    }else{
                        dataArray[8] = "--";
                    }
                    //ofd
                    if(xmlFlag.contains("3")||xmlFlag.contains("6")){
                        dataArray[9] = "有";
                    }else{
                        dataArray[9] = "--";
                    }
                    //xml
                    if(xmlFlag.contains("1")||xmlFlag.contains("4")){
                        dataArray[10] = "有";
                    }else{
                        dataArray[10] = "--";
                    }

                    dataArray[11] = pageList.get(i).getXfmc();
                    dataArray[12] = pageList.get(i).getXfsh();
                    dataArray[13] = MathUtil.round(pageList.get(i).getInvoiceAmount());
                    dataArray[14] = MathUtil.round(pageList.get(i).getTaxAmount());

                    if (!"01".equals(pageList.get(i).getInvoiceType()) && !"03".equals(pageList.get(i).getInvoiceType())
                        && !"08".equals(pageList.get(i).getInvoiceType())
                        && !"14".equals(pageList.get(i).getInvoiceType())
                        && !"31".equals(pageList.get(i).getInvoiceType())) {
                        dataArray[15] = "";
                    } else {
                        if (StringUtils.isNotBlank(pageList.get(i).getYxse())) {
                            dataArray[15] = MathUtil.round(pageList.get(i).getYxse());
                        } else {
                            dataArray[15] = MathUtil.round(pageList.get(i).getTaxAmount());
                        }
                    }
                    dataArray[16] = MathUtil.round(pageList.get(i).getTotalAmount());
                    for (RzztEnum e : RzztEnum.values()) {
                        if (e.getRzztDm().equals(pageList.get(i).getRzzt())) {
                            dataArray[17] = e.getRzztMc(e.getIndex());
                        }
                    }
                    dataArray[18] = pageList.get(i).getRzhBackMsg();
                    if ("1".equals(pageList.get(i).getRzlx())) {
                        dataArray[19] = "认证抵扣";
                    } else if ("2".equals(pageList.get(i).getRzlx())) {
                        dataArray[19] = "认证不抵扣";
                    } else if ("3".equals(pageList.get(i).getRzlx())) {
                        dataArray[19] = "认证退税";
                    } else {
                        dataArray[19] = "";
                    }
                    dataArray[20] = pageList.get(i).getRzrq() == null ? "" : pageList.get(i).getRzrq();
                    for (RzfsEnum e : RzfsEnum.values()) {
                        if (e.getRzfsDm().equals(pageList.get(i).getRzfs())) {
                            dataArray[21] = e.getRzfsMc(e.getIndex());
                        }
                    }
                    dataArray[22] = pageList.get(i).getRzr();
                    if ("0".equals(pageList.get(i).getCollectStatus())) {
                        dataArray[23] = "未采集";
                    } else if ("1".equals(pageList.get(i).getCollectStatus())) {
                        dataArray[23] = "已采集";
                    }
                    dataArray[24] = pageList.get(i).getCollectDate() != null ? pageList.get(i).getCollectDate() : "";
                    if ("0".equals(pageList.get(i).getCollectFrom())) {
                        dataArray[25] = "进项采集";
                    } else if ("1".equals(pageList.get(i).getCollectFrom())) {
                        dataArray[25] = "票据采集";
                    } else if ("4".equals(pageList.get(i).getCollectFrom())) {
                        dataArray[26] = "大企业归集";
                    }
                    for (QsfsEnum e : QsfsEnum.values()) {
                        if (e.getQsfsDm().equals(pageList.get(i).getQsfs())) {
                            String qsfs = e.getQsfsMc(e.getIndex());
                            if ("电票上传签收".equals(qsfs)) {
                                dataArray[26] = "电票签收";
                            } else if ("接口推送".equals(qsfs)) {
                                dataArray[26] = "接口签收";
                            } else {
                                dataArray[26] = qsfs;
                            }
                        }

                    }
                    for (FpqsjgEnum e : FpqsjgEnum.values()) {
                        if (e.getQsjgDm().equals(pageList.get(i).getQszt())) {
                            dataArray[27] = e.getQsjgMc(e.getIndex());
                        }
                    }
                    dataArray[28] = pageList.get(i).getQsrq() != null ? pageList.get(i).getQsrq() : "";
                    dataArray[29] = pageList.get(i).getQsr();

                    //局端入账
                    //入账状态
                    //已入账  02 05  未入账  01 03 04
                    String lqRzzt = pageList.get(i).getLqRzzt();
                    if("02".equals(lqRzzt)||"05".equals(lqRzzt)){
                        dataArray[30] = "已入账";
                    }else{
                        dataArray[30] = "未入账";
                    }
                    dataArray[31] = pageList.get(i).getFprzsq();

                    //财务入账
                    dataArray[32] = pageList.get(i).getInAccountMonth();
                    if ("0".equals(pageList.get(i).getInAccountStatus())) {
                        dataArray[33] = "未入账";
                    } else if ("1".equals(pageList.get(i).getInAccountStatus())) {
                        dataArray[33] = "已入账";
                    } else {
                        dataArray[33] = "未入账";
                    }
                    dataArray[34] = pageList.get(i).getVoucherNo();
                    if ("0".equals(pageList.get(i).getAmortizeStatus())) {
                        dataArray[35] = "否";
                    } else if ("1".equals(pageList.get(i).getAmortizeStatus())) {
                        dataArray[35] = "是";
                    } else {
                        dataArray[35] = "";
                    }
                    if (pageList.get(i).getAmortizeAmount() != null
                        && !"".equals(pageList.get(i).getAmortizeAmount())) {
                        dataArray[36] =
                            AmountFormatUtil.fmtMicrometer(MathUtil.round(pageList.get(i).getAmortizeAmount()));
                    } else {
                        dataArray[36] = "";
                    }
                    if (pageList.get(i).getRemainAmortizeAmount() != null
                        && !"".equals(pageList.get(i).getRemainAmortizeAmount())) {
                        dataArray[37] =
                            AmountFormatUtil.fmtMicrometer(MathUtil.round(pageList.get(i).getRemainAmortizeAmount()));
                    } else {
                        dataArray[37] = "";
                    }

                    dataArray[39] = pageList.get(i).getDocumentNumber();
                    dataArray[39] = pageList.get(i).getCreateDate();
                    returnList.add(dataArray);
                }
            }

            json.put("datalist", returnList);

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

        return json;
    }

    @Override
    public JSONObject listSaleInvoice(Map<String, Object> pramsMap, int curr, int size) {
        DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);
        JSONObject json = new JSONObject();
        try {
            PageHelper.startPage(curr, size);
            List<ExtAddTaxInvoice> pageList = super.baseMapper.listSaleInvoice(pramsMap);
            PageInfo<ExtAddTaxInvoice> pageInfo = new PageInfo<>(pageList);
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());
            List<String[]> returnList = new ArrayList<>();
            // 用于页面返回list对象
            if (pageList != null && pageList.size() > 0) {
                for (int i = 0; i < pageList.size(); i++) {
                    String[] dataArray = new String[32];
                    dataArray[0] = String.valueOf((curr - 1) * size + i + 1);
                    // 发票类型
                    dataArray[1] = dictdetaServcice.queryDictName(DictConstant.INVOICE_TYPEALL, pageList.get(i).getInvoiceType());
                    if(StringUtils.isBlank(pageList.get(i).getLqTdyslxDm())){
                        dataArray[2] = "非特定业务";
                    }else{
                        dataArray[2] = dictdetaServcice.queryDictName(DictConstant.TDYS_LXDM, pageList.get(i).getLqTdyslxDm());
                    }
                    dataArray[3] = pageList.get(i).getInvoiceCode();
                    dataArray[4] = pageList.get(i).getInvoiceNo();
                    dataArray[5] = pageList.get(i).getEleInvoiceNo();

                    for (FpztEnum e : FpztEnum.values()) {
                        if (e.getFpztDm().equals(pageList.get(i).getInvoiceStatus())) {
                            dataArray[6] = e.getFpztMc(e.getIndex());
                        }
                    }
                    dataArray[7] = pageList.get(i).getInvoiceDate();

                    //源文件设置   "源文件PDF", "源文件OFD", "源文件XML"
                    //源文件展示与否处理
                    String xmlFlag = pageList.get(i).getXmlFlag();
                    //pdf
                    if(xmlFlag.contains("2")||xmlFlag.contains("5")){
                        dataArray[8] = "有";
                    }else{
                        dataArray[8] = "--";
                    }
                    //ofd
                    if(xmlFlag.contains("3")||xmlFlag.contains("6")){
                        dataArray[9] = "有";
                    }else{
                        dataArray[9] = "--";
                    }
                    //xml
                    if(xmlFlag.contains("1")||xmlFlag.contains("4")){
                        dataArray[10] = "有";
                    }else{
                        dataArray[10] = "--";
                    }

                    dataArray[11] = pageList.get(i).getGfmc();
                    dataArray[12] = pageList.get(i).getGfsh();
                    dataArray[13] = MathUtil.round(pageList.get(i).getInvoiceAmount());
                    dataArray[14] = MathUtil.round(pageList.get(i).getTaxAmount());
                    dataArray[15] = MathUtil.round(pageList.get(i).getTotalAmount());
                    if ("0".equals(pageList.get(i).getListStatus())) {
                        dataArray[16] = "否";
                    } else if ("1".equals(pageList.get(i).getListStatus())) {
                        dataArray[16] = "是";
                    }
                    dataArray[17] = pageList.get(i).getRemark();
                    dataArray[18] = pageList.get(i).getIncentiveFlag();
                    if ("0".equals(pageList.get(i).getCollectStatus())) {
                        dataArray[19] = "未采集";
                    } else if ("1".equals(pageList.get(i).getCollectStatus())) {
                        dataArray[19] = "已采集";
                    }
                    dataArray[20] = pageList.get(i).getCollectDate();
                    if ("0".equals(pageList.get(i).getCollectFrom())) {
                        dataArray[21] = "进项采集";
                    } else if ("1".equals(pageList.get(i).getCollectFrom())) {
                        dataArray[21] = "票据采集";
                    } else if ("4".equals(pageList.get(i).getCollectFrom())) {
                        dataArray[21] = "大企业归集";
                    } else {
                        dataArray[21] = "票据采集";
                    }

                    for (QsfsEnum e : QsfsEnum.values()) {
                        if (e.getQsfsDm().equals(pageList.get(i).getQsfs())) {
                            String qsfs = e.getQsfsMc(e.getIndex());
                            if ("电票上传签收".equals(qsfs)) {
                                dataArray[22] = "电票签收";
                            } else if ("接口推送".equals(qsfs)) {
                                dataArray[22] = "接口签收";
                            } else {
                                dataArray[22] = qsfs;
                            }
                        }

                    }
                    dataArray[23] = pageList.get(i).getSystemName();
                    for (FpqsjgEnum e : FpqsjgEnum.values()) {
                        if (e.getQsjgDm().equals(pageList.get(i).getQszt())) {
                            dataArray[24] = e.getQsjgMc(e.getIndex());
                        }
                    }
                    dataArray[25] = pageList.get(i).getQsrq() != null ? pageList.get(i).getQsrq() : "";
                    dataArray[26] = pageList.get(i).getQsr();
                    dataArray[27] = pageList.get(i).getInAccountMonth();
                    if ("0".equals(pageList.get(i).getInAccountStatus())) {
                        dataArray[28] = "未入账";
                    } else if ("1".equals(pageList.get(i).getInAccountStatus())) {
                        dataArray[28] = "已入账";
                    } else {
                        dataArray[28] = "";
                    }
                    dataArray[29] = pageList.get(i).getVoucherNo();
                    dataArray[30] = pageList.get(i).getDocumentNumber();
                    dataArray[31] = pageList.get(i).getCreateDate();
                    returnList.add(dataArray);
                }
            }

            json.put("datalist", returnList);

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

        return json;
    }

    /**
     * 签收状态码统一放入map中
     */
    public static final Map<String, String> QSZT_MAP = new HashMap<String, String>(16) {
        private static final long serialVersionUID = 3195016454748903072L;

        {
            for (FpqsjgEnum en : FpqsjgEnum.values()) {
                this.put(en.getQsjgDm(), en.getQsjgMcSmb(en.getIndex()));
            }
        }
    };

    /**
     * 签收方式统一放入map中
     */
    public static final Map<String, String> QSFS_MAP = new HashMap<String, String>(16) {
        private static final long serialVersionUID = 5137143201446095218L;

        {
            for (QsfsEnum en : QsfsEnum.values()) {
                this.put(en.getQsfsDm(), en.getQsfsMc(en.getIndex()));
            }
        }
    };

    @Override
    public String getGfName(String gfsh) {
        DynamicContextHolder.push(DbConstant.BASICS_READ);
        if(ObjectUtil.isEmpty(super.baseMapper.getGfName(gfsh))){
            return "";
        }else{
            return super.baseMapper.getGfName(gfsh);
        }
    }

    @Override
    public String getblocName(String gfsh) {
        DynamicContextHolder.push(DbConstant.BASICS_READ);
        if(ObjectUtil.isEmpty(super.baseMapper.getBlocName(gfsh))){
            return "";
        }else{
            return super.baseMapper.getBlocName(gfsh);
        }
    }

    @Override
    public JSONObject listAddTaxInvoiceDetail(Map<String, Object> pramsMap, int curr, int size) {
        DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);
        JSONObject json = new JSONObject();
        try {
            PageHelper.startPage(curr, size);
            List<CompanyPoolJxVO> pageList = super.baseMapper.listAddTaxInvoiceDetail(pramsMap);
            PageInfo<CompanyPoolJxVO> pageInfo = new PageInfo<>(pageList);
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());
            List<String[]> returnList = new ArrayList<>();
            // 用于页面返回list对象
            if (pageList.size() > 0) {
                for (int i = 0; i < pageList.size(); i++) {
                    String[] dataArray = new String[30];
                    dataArray[0] = String.valueOf((curr - 1) * size + i + 1);
                    // 发票类型
                    dataArray[1] = pageList.get(i).getInvoiceCode();
                    dataArray[2] = pageList.get(i).getInvoiceNo();
                    dataArray[3] = pageList.get(i).getHlmc();
                    dataArray[4] = pageList.get(i).getGgxh();
                    dataArray[5] = pageList.get(i).getDw();
                    dataArray[6] = pageList.get(i).getNum();
                    dataArray[7] = pageList.get(i).getDj();
                    if (StringUtils.isNotBlank(pageList.get(i).getJe())) {
                        dataArray[8] = MathUtil.round(pageList.get(i).getJe());
                    } else {
                        dataArray[8] = "";
                    }
                    if (StringUtils.isNotBlank(pageList.get(i).getSe())) {
                        try {
                            dataArray[9] = MathUtil.round(pageList.get(i).getSe());
                        } catch (Exception e) {
                            dataArray[9] = pageList.get(i).getSe();
                        }
                    } else {
                        dataArray[9] = "";
                    }
                    dataArray[10] = pageList.get(i).getSl();
                    dataArray[11] = pageList.get(i).getCph();
                    dataArray[12] = pageList.get(i).getLx();
                    dataArray[13] = pageList.get(i).getTxrqq();
                    dataArray[14] = pageList.get(i).getTxrqz();

                    returnList.add(dataArray);
                }
            }

            json.put("datalist", returnList);

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

        return json;
    }

    @Override
    public JSONObject listSaleInvoiceDetail(Map<String, Object> pramsMap, int curr, int size) {
        DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);
        JSONObject json = new JSONObject();
        try {
            PageHelper.startPage(curr, size);
            List<CompanyPoolJxVO> pageList = super.baseMapper.listSaleInvoiceDetail(pramsMap);
            PageInfo<CompanyPoolJxVO> pageInfo = new PageInfo<>(pageList);
            json.put("hasNext", pageInfo.isHasNextPage());
            json.put("nextPage", pageInfo.getNextPage());
            List<String[]> returnList = new ArrayList<>();
            // 用于页面返回list对象
            if (pageList.size() > 0) {
                for (int i = 0; i < pageList.size(); i++) {
                    String[] dataArray = new String[30];
                    dataArray[0] = String.valueOf((curr - 1) * size + i + 1);
                    // 发票类型
                    dataArray[1] = pageList.get(i).getInvoiceCode();
                    dataArray[2] = pageList.get(i).getInvoiceNo();
                    dataArray[3] = pageList.get(i).getHlmc();
                    dataArray[4] = pageList.get(i).getGgxh();
                    dataArray[5] = pageList.get(i).getDw();
                    dataArray[6] = pageList.get(i).getNum();
                    dataArray[7] = pageList.get(i).getDj();
                    if (StringUtils.isNotBlank(pageList.get(i).getJe())) {
                        dataArray[8] = MathUtil.round(pageList.get(i).getJe());
                    } else {
                        dataArray[8] = "";
                    }
                    if (StringUtils.isNotBlank(pageList.get(i).getSe())) {
                        try {
                            dataArray[9] = MathUtil.round(pageList.get(i).getSe());
                        } catch (Exception e) {
                            dataArray[9] = pageList.get(i).getSe();
                        }
                    } else {
                        dataArray[9] = "";
                    }
                    String sl="";
                    if(StringUtils.isNotBlank( pageList.get(i).getSl())){
                        if (StringHelper.trimEnter(pageList.get(i).getSl()).matches("[0-9]+")) {
                            sl = pageList.get(i).getSl()+"%";
                        } else if(pageList.get(i).getSl().contains(".")){
                            String taxRate = StringHelper.trimEnter(pageList.get(i).getSl());
                            if(taxRate.contains(".")){
                                taxRate = taxRate.replace(".", "").replace("0", "");
                            }
                            sl = taxRate + "%";
                        }else {
                            sl = pageList.get(i).getSl();
                        }
                    }
                    dataArray[10] = sl;
                    dataArray[11] = pageList.get(i).getCph();
                    dataArray[12] = pageList.get(i).getLx();
                    dataArray[13] = pageList.get(i).getTxrqq();
                    dataArray[14] = pageList.get(i).getTxrqz();
                    dataArray[15] = pageList.get(i).getIncentiveFlag();
                    returnList.add(dataArray);
                }
            }

            json.put("datalist", returnList);

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

        return json;
    }
}
