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

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dxhy.common.util.StringHelper;
import com.github.pagehelper.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.dxhy.common.constant.DbConstant;
import com.dxhy.common.datasource.config.DynamicContextHolder;
import com.dxhy.common.enums.*;
import com.dxhy.common.service.impl.MpBaseServiceImpl;
import com.dxhy.common.util.AmountFormatUtil;
import com.dxhy.common.util.MathUtil;
import com.dxhy.core.dao.PoolPaperDao;
import com.dxhy.core.entity.ExtAddTaxInvoice;
import com.dxhy.core.entity.ExtOtherInvoice;
import com.dxhy.core.entity.InvoicePaperEntity;
import com.dxhy.core.model.CompanyPoolJxVO;
import com.dxhy.core.service.export.PoolPaperService;
import com.dxhy.core.util.InvoiceTypeUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

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

@SuppressWarnings("AlibabaMethodTooLong")
@Slf4j
@Service
public class PoolPaperServiceImpl extends MpBaseServiceImpl<PoolPaperDao, InvoicePaperEntity>
    implements PoolPaperService {
    @Value("${dxhy.datasource.dxhy_admin:dxhy_admin}")
    private String dxhyAdmin;
    @Value("${dxhy.datasource.dxhy_tertiary:dxhy_tertiary}")
    private String dxhyTertiary;
    @Value("${dxhy.datasource.dxhy_detail:dxhy_detail}")
    private String dxhyDetail;

    /**
     * 票据导出查询
     *
     * @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[12];
                    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 {
                        dataArray[2] = "票据采集";
                    }
                    dataArray[3] = new InvoiceTypeUtils().invoiceTypeName(pageList.get(i).getInvoiceType());
                    dataArray[4] = pageList.get(i).getInvoiceCode();
                    dataArray[5] = pageList.get(i).getInvoiceNo();
                    dataArray[6] = pageList.get(i).getInvoiceDate();
                    dataArray[7] = pageList.get(i).getBuyerName();
                    dataArray[8] = pageList.get(i).getSaleName();
                    dataArray[9] = MathUtil.round(pageList.get(i).getInvoiceAmount());
                    dataArray[10] = MathUtil.round(pageList.get(i).getTaxAmount());
                    dataArray[11] = 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[21];
                    dataArray[0] = String.valueOf((curr - 1) * size + i + 1);
                    // 发票类型
                    dataArray[1] = new InvoiceTypeUtils().invoiceTypeName(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();
                    dataArray[12] = pageList.get(i).getSnVoucherNumber();
                    dataArray[13] = pageList.get(i).getPostingTime();
                    dataArray[14] = pageList.get(i).getImageId();
                    dataArray[15] = pageList.get(i).getAccountPeriod();
                    dataArray[16] = pageList.get(i).getBzdh();
                    dataArray[17] = pageList.get(i).getBzr();
                    if(pageList.get(i).getInAccountStatus() != null && "1".equals(pageList.get(i).getInAccountStatus())){
                        dataArray[18] = "已入账";
                    }else {
                        dataArray[18] = "未入账";
                    }

                    dataArray[19] = pageList.get(i).getCompCode();
                    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);
            log.info("pageList={}",pageList.size());
            PageInfo<ExtAddTaxInvoice> pageInfo = new PageInfo<>(pageList);
            log.info("pageInfo={}",pageInfo);
            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] = new InvoiceTypeUtils().invoiceTypeName(pageList.get(i).getInvoiceType());
                    dataArray[2] = pageList.get(i).getInvoiceCode();
                    dataArray[3] = pageList.get(i).getInvoiceNo();
                    for (FpztEnum e : FpztEnum.values()) {
                        if (e.getFpztDm().equals(pageList.get(i).getInvoiceStatus())) {
                            dataArray[4] = e.getFpztMc(e.getIndex());
                        }
                    }
                    dataArray[5] = pageList.get(i).getInvoiceDate();
                    dataArray[6] = pageList.get(i).getXfmc();
                    dataArray[7] = pageList.get(i).getXfsh();
                    dataArray[8] = MathUtil.round(pageList.get(i).getInvoiceAmount());
                    dataArray[9] = 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[10] = "";
                    } else {
                        if (StringUtils.isNotBlank(pageList.get(i).getYxse())) {
                            dataArray[10] = MathUtil.round(pageList.get(i).getYxse());
                        } else {
                            dataArray[10] = MathUtil.round(pageList.get(i).getTaxAmount());
                        }
                    }
                    dataArray[11] = MathUtil.round(pageList.get(i).getTotalAmount());
                    for (RzztEnum e : RzztEnum.values()) {
                        if (e.getRzztDm().equals(pageList.get(i).getRzzt())) {
                            dataArray[12] = e.getRzztMc(e.getIndex());
                        }
                    }
                    if ("1".equals(pageList.get(i).getRzlx())) {
                        dataArray[13] = "认证抵扣";
                    } else if ("2".equals(pageList.get(i).getRzlx())) {
                        dataArray[13] = "认证不抵扣";
                    } else if ("3".equals(pageList.get(i).getRzlx())) {
                        dataArray[13] = "认证退税";
                    } else {
                        dataArray[13] = "";
                    }
                    dataArray[14] = pageList.get(i).getRzrq() == null ? "" : pageList.get(i).getRzrq();
                    for (RzfsEnum e : RzfsEnum.values()) {
                        if (e.getRzfsDm().equals(pageList.get(i).getRzfs())) {
                            dataArray[15] = e.getRzfsMc(e.getIndex());
                        }
                    }
                    dataArray[16] = pageList.get(i).getRzr();
                    if ("0".equals(pageList.get(i).getCollectStatus())) {
                        dataArray[17] = "未采集";
                    } else if ("1".equals(pageList.get(i).getCollectStatus())) {
                        dataArray[17] = "已采集";
                    }
                    dataArray[18] = pageList.get(i).getCollectDate() != null ? pageList.get(i).getCollectDate() : "";
                    if ("0".equals(pageList.get(i).getCollectFrom())) {
                        dataArray[19] = "进项采集";
                    } else if ("1".equals(pageList.get(i).getCollectFrom())) {
                        dataArray[19] = "票据采集";
                    }
                    for (QsfsEnum e : QsfsEnum.values()) {
                        if (e.getQsfsDm().equals(pageList.get(i).getQsfs())) {
                            String qsfs = e.getQsfsMc(e.getIndex());
                            if ("电票上传签收".equals(qsfs)) {
                                dataArray[20] = "电票签收";
                            } else if ("接口推送".equals(qsfs)) {
                                dataArray[20] = "接口签收";
                            } else {
                                dataArray[20] = qsfs;
                            }
                        }

                    }
                    for (FpqsjgEnum e : FpqsjgEnum.values()) {
                        if (e.getQsjgDm().equals(pageList.get(i).getQszt())) {
                            dataArray[21] = e.getQsjgMc(e.getIndex());
                        }
                    }
                    dataArray[22] = pageList.get(i).getQsrq() != null ? pageList.get(i).getQsrq() : "";
                    dataArray[23] = pageList.get(i).getQsr();
                    dataArray[24] = pageList.get(i).getInAccountMonth();
//                    if ("0".equals(pageList.get(i).getInAccountStatus())) {
//                        dataArray[25] = "未入账";
//                    } else if ("1".equals(pageList.get(i).getInAccountStatus())) {
//                        dataArray[25] = "已入账";
//                    }
//                    else {
//                        dataArray[25] = "未入账";
//                    }
                    if ("0".equals(pageList.get(i).getAmortizeStatus())) {
                        dataArray[25] = "否";
                    } else if ("1".equals(pageList.get(i).getAmortizeStatus())) {
                        dataArray[25] = "是";
                    } else {
                        dataArray[25] = "";
                    }
                    if (pageList.get(i).getAmortizeAmount() != null
                        && !"".equals(pageList.get(i).getAmortizeAmount())) {
                        dataArray[26] =
                            AmountFormatUtil.fmtMicrometer(MathUtil.round(pageList.get(i).getAmortizeAmount()));
                    } else {
                        dataArray[26] = "";
                    }
                    if (pageList.get(i).getRemainAmortizeAmount() != null
                        && !"".equals(pageList.get(i).getRemainAmortizeAmount())) {
                        dataArray[27] =
                            AmountFormatUtil.fmtMicrometer(MathUtil.round(pageList.get(i).getRemainAmortizeAmount()));
                    } else {
                        dataArray[27] = "";
                    }

                    dataArray[28] = pageList.get(i).getDocumentNumber();
                    dataArray[29] = pageList.get(i).getCreateDate();
                    dataArray[30] = pageList.get(i).getSnVoucherNumber();
                    dataArray[31] = pageList.get(i).getPostingTime();
                    String accountPeriod = pageList.get(i).getAccountPeriod();
                    if (StringUtil.isNotEmpty(accountPeriod) && accountPeriod.length() >7){
                        accountPeriod = accountPeriod.substring(0,7);
                    }
                    dataArray[32] = accountPeriod;
                    dataArray[33] = pageList.get(i).getImageId();
                    dataArray[34] = pageList.get(i).getBzdh();
                    dataArray[35] = pageList.get(i).getBzr();
//                    log.info("入账状态====>{}",pageList.get(i).getInAccountStatus());
                    if (pageList.get(i).getInAccountStatus() != null && "1".equals(pageList.get(i).getInAccountStatus())){
                        dataArray[36] = "已入账";
                    }else {
                        dataArray[36] = "未入账";
                    }
                    dataArray[37] = pageList.get(i).getCompCode();
                    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);
            pramsMap.put("dxhyAdmin", dxhyAdmin);
            pramsMap.put("dxhyDetail", dxhyDetail);
            pramsMap.put("dxhyTertiary", dxhyTertiary);
            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[34];
                    dataArray[0] = String.valueOf((curr - 1) * size + i + 1);
                    // 发票类型
                    dataArray[1] = new InvoiceTypeUtils().invoiceTypeName(pageList.get(i).getInvoiceType());
                    dataArray[2] = pageList.get(i).getInvoiceCode();
                    dataArray[3] = pageList.get(i).getInvoiceNo();
                    for (FpztEnum e : FpztEnum.values()) {
                        if (e.getFpztDm().equals(pageList.get(i).getInvoiceStatus())) {
                            dataArray[4] = e.getFpztMc(e.getIndex());
                        }
                    }
                    dataArray[5] = pageList.get(i).getInvoiceDate();
                    dataArray[6] = pageList.get(i).getGfmc();
                    dataArray[7] = pageList.get(i).getGfsh();
                    dataArray[8] = MathUtil.round(pageList.get(i).getInvoiceAmount());
                    dataArray[9] = MathUtil.round(pageList.get(i).getTaxAmount());
                    dataArray[10] = MathUtil.round(pageList.get(i).getTotalAmount());
                    if ("0".equals(pageList.get(i).getListStatus())) {
                        dataArray[11] = "否";
                    } else if ("1".equals(pageList.get(i).getListStatus())) {
                        dataArray[11] = "是";
                    }
                    dataArray[12] = pageList.get(i).getRemark();
                    dataArray[13] = pageList.get(i).getIncentiveFlag();
                    if ("0".equals(pageList.get(i).getCollectStatus())) {
                        dataArray[14] = "未采集";
                    } else if ("1".equals(pageList.get(i).getCollectStatus())) {
                        dataArray[14] = "已采集";
                    }
                    dataArray[15] = pageList.get(i).getCollectDate();
                    dataArray[16] = "票据采集";

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

                    }
                    dataArray[18] = pageList.get(i).getSystemName();
                    for (FpqsjgEnum e : FpqsjgEnum.values()) {
                        if (e.getQsjgDm().equals(pageList.get(i).getQszt())) {
                            dataArray[19] = e.getQsjgMc(e.getIndex());
                        }
                    }
                    dataArray[20] = pageList.get(i).getQsrq() != null ? pageList.get(i).getQsrq() : "";
                    dataArray[21] = pageList.get(i).getQsr();
                    dataArray[22] = pageList.get(i).getInAccountMonth();
                    dataArray[23] = pageList.get(i).getSnVoucherNumber();
                    dataArray[24] = pageList.get(i).getDocumentNumber();
                    dataArray[25] = pageList.get(i).getCreateDate();
                    dataArray[26] = pageList.get(i).getImageId();
                    dataArray[27] = pageList.get(i).getAccountPeriod();
                    dataArray[28] = pageList.get(i).getPostingTime();
                    dataArray[29] = pageList.get(i).getBzdh();
                    dataArray[30] = pageList.get(i).getBzr();
                    if ("1".equals(pageList.get(i).getInAccountStatus())) {
                        dataArray[31] = "已入账";
                    } else{
                        dataArray[31] = "未入账";
                    }
                    dataArray[32] = pageList.get(i).getCompCode();
                    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);
        return super.baseMapper.getGfName(gfsh);
    }

    @Override
    public String getblocName(String gfsh) {
        DynamicContextHolder.push(DbConstant.BASICS_READ);
        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);
            pramsMap.put("dxhyTertiary", dxhyTertiary);
            pramsMap.put("dxhyDetail", dxhyDetail);
            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);
            pramsMap.put("dxhyTertiary", dxhyTertiary);
            pramsMap.put("dxhyDetail", dxhyDetail);
            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;
    }
}
