package com.dxhy.extend.service.pool;

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.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.extend.dao.ExtInvoicePoolDao;
import com.dxhy.extend.entity.AmortizeRecordEntity;
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.List;
import java.util.Map;

/**
 * @author dxhy
 */
@SuppressWarnings({"AlibabaUndefineMagicConstant", "AlibabaMethodTooLong"})
@Service
public class ExtInvoicePoolServiceImpl extends MpBaseServiceImpl<ExtInvoicePoolDao, ExtAddTaxInvoice>
    implements ExtInvoicePoolService {

    @Resource
    private DictdetaServcice dictdetaServcice;

    @Override
    public String listAddTax(Map<String, Object> pramsMap, int curr, int size) {
        JSONObject json = new JSONObject();
        DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);
        try {
            String[] titlelist = {"序号", "发票类型", "特定业务","发票代码", "发票号码","数电号码", "发票状态", "开票日期", "源文件PDF", "源文件OFD", "源文件XML", "销方名称", "销方税号", "金额", "税额", "有效税额",
                "价税合计", "认证状态","认证处理状态说明", "认证类型", "认证日期", "认证方式", "认证人", "采集状态", "底账库采集时间", "采集来源", "签收方式", "签收状态", "签收日期", "签收人","局端入账状","局端入账属期",
                "财务入账月份", "财务入账状态", "凭证号", "是否末次摊销", "摊销金额", "剩余金额", "业务单号", "入池时间"};

            String[] titleprop = {"xh", "invoiceType", "lqTdyslxDm", "invoiceCode", "invoiceNo","eleInvoiceNo","invoiceStatus", "invoiceDate","sourcePdf","sourceOfd","sourceXml",
                "xfmc", "xfsh", "invoiceAmount", "taxAmount", "yxse", "totalAmount", "rzzt","rzhBackMsg", "rzlx", "rzrq", "rzfs",
                "rzr", "collectStatus", "collectDate", "collectFrom", "qsfs", "qszt", "qsrq", "qsr","lqRzzt", "fprzsq",  "inAccountMonth",
                "inAccountStatus", "voucherNo", "amortizeStatus", "amortizeAmount", "remainAmortizeAmount",
                "documentNumber", "createDate"};
            // 需要设置返回列表标题时调用
            json = super.setTitleList(titlelist, titleprop);
            // 合计信息,仅第一页时需要统计，减少数据库压力
            if (curr == 1) {
                String hjsl = "0";
                String hjje = "0.00";
                String hjse = "0.00";
                ExtAddTaxInvoice hjxx = super.baseMapper.selectAddTaxHj(pramsMap);
                if(ObjectUtil.isNotNull(hjxx)){
                    hjsl = hjxx.getId();
                    if (!"0".equals(hjsl)) {
                        hjje = AmountFormatUtil.fmtMicrometer(MathUtil.round(hjxx.getInvoiceAmount()));
                        hjse = AmountFormatUtil.fmtMicrometer(MathUtil.round(hjxx.getTaxAmount()));
                    }
                }

                json.put("hjsl", hjsl);
                json.put("hjje", hjje);
                json.put("hjse", hjse);
            }
            PageHelper.startPage(curr, size);
            List<ExtAddTaxInvoice> pageList = super.baseMapper.listAddTaxInvoice(pramsMap);
            PageInfo<ExtAddTaxInvoice> pageInfo = new PageInfo<>(pageList);
            // 用于页面返回list对象
            if (pageList != null && pageList.size() > 0) {

                int start = (int)pageInfo.getStartRow();
                for (int i = 0; i < pageList.size(); i++) {
                    pageList.get(i).setXh(String.valueOf(i + start));
                    pageList.get(i).setInvoiceAmount(
                        AmountFormatUtil.fmtMicrometer(MathUtil.round(pageList.get(i).getInvoiceAmount())));
                    pageList.get(i).setTotalAmount(
                        AmountFormatUtil.fmtMicrometer(MathUtil.round(pageList.get(i).getTotalAmount())));
                    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())
                        && !"161".equals(pageList.get(i).getInvoiceType())
                        && !"183".equals(pageList.get(i).getInvoiceType())
                        && !"185".equals(pageList.get(i).getInvoiceType())
                        && !"283".equals(pageList.get(i).getInvoiceType())
                        ) {
                        pageList.get(i).setYxse("--");
                    } else {
                        if (pageList.get(i).getYxse() != null && !"".equals(pageList.get(i).getYxse())) {
                            pageList.get(i)
                                .setYxse(AmountFormatUtil.fmtMicrometer(MathUtil.round(pageList.get(i).getYxse())));
                        } else {
                            pageList.get(i).setYxse(
                                AmountFormatUtil.fmtMicrometer(MathUtil.round(pageList.get(i).getTaxAmount())));
                        }
                    }
                    pageList.get(i)
                        .setTaxAmount(AmountFormatUtil.fmtMicrometer(MathUtil.round(pageList.get(i).getTaxAmount())));
                    if (pageList.get(i).getAmortizeAmount() != null
                        && !"".equals(pageList.get(i).getAmortizeAmount())) {
                        pageList.get(i).setAmortizeAmount(
                            AmountFormatUtil.fmtMicrometer(MathUtil.round(pageList.get(i).getAmortizeAmount())));
                    } else {
                        pageList.get(i).setAmortizeAmount("--");
                    }
                    if (pageList.get(i).getRemainAmortizeAmount() != null
                        && !"".equals(pageList.get(i).getRemainAmortizeAmount())) {
                        pageList.get(i).setRemainAmortizeAmount(
                            AmountFormatUtil.fmtMicrometer(MathUtil.round(pageList.get(i).getRemainAmortizeAmount())));
                    } else {
                        pageList.get(i).setRemainAmortizeAmount("--");
                    }
                    for (FpztEnum e : FpztEnum.values()) {
                        if (e.getFpztDm().equals(pageList.get(i).getInvoiceStatus())) {
                            pageList.get(i).setInvoiceStatus(e.getFpztMc(e.getIndex()));
                        }
                    }
                    for (FpqsjgEnum e : FpqsjgEnum.values()) {
                        if (e.getQsjgDm().equals(pageList.get(i).getQszt())) {
                            pageList.get(i).setQszt(e.getQsjgMc(e.getIndex()));
                        }
                    }
                    for (RzztEnum e : RzztEnum.values()) {
                        if (e.getRzztDm().equals(pageList.get(i).getRzzt())) {
                            pageList.get(i).setRzzt(e.getRzztMc(e.getIndex()));
                        }
                    }
                    for (QsfsEnum e : QsfsEnum.values()) {
                        if (e.getQsfsDm().equals(pageList.get(i).getQsfs())) {
                            pageList.get(i).setQsfs(e.getQsfsMc(e.getIndex()));
                        }
                    }
                    if ("电票上传签收".equals(pageList.get(i).getQsfs())) {
                        pageList.get(i).setQsfs("电票签收");
                    }
                    if ("接口推送".equals(pageList.get(i).getQsfs())) {
                        pageList.get(i).setQsfs("接口签收");
                    }
                    if ("1".equals(pageList.get(i).getRzlx())) {
                        pageList.get(i).setRzlx("认证抵扣");
                    } else if ("2".equals(pageList.get(i).getRzlx())) {
                        pageList.get(i).setRzlx("--");
                    } else if ("3".equals(pageList.get(i).getRzlx())) {
                        pageList.get(i).setRzlx("认证代办退税");
                    } else if ("4".equals(pageList.get(i).getRzlx())) {
                        pageList.get(i).setRzlx("认证不抵扣");
                    } else {
                        pageList.get(i).setRzlx("");
                    }
                    if ("0".equals(pageList.get(i).getInAccountStatus())) {
                        pageList.get(i).setInAccountStatus("未入账");
                    } else if ("1".equals(pageList.get(i).getInAccountStatus())) {
                        pageList.get(i).setInAccountStatus("已入账");
                    } else {
                        pageList.get(i).setInAccountStatus("未入账");
                    }

                    if ("0".equals(pageList.get(i).getCollectFrom())) {
                        pageList.get(i).setCollectFrom("进项采集");
                    } else if ("1".equals(pageList.get(i).getCollectFrom())) {
                        pageList.get(i).setCollectFrom("票据采集");
                    } else if ("4".equals(pageList.get(i).getCollectFrom())) {
                        pageList.get(i).setCollectFrom("大企业归集");
                    }
                    pageList.get(i).setInvoiceType(dictdetaServcice.queryDictName(DictConstant.INVOICE_TYPEALL, pageList.get(i).getInvoiceType()));
                    pageList.get(i).setQsrq(pageList.get(i).getQsrq() == null ? "" : pageList.get(i).getQsrq());
                    pageList.get(i).setRzrq(pageList.get(i).getRzrq() == null ? "" : pageList.get(i).getRzrq());
                    pageList.get(i).setScanId(pageList.get(i).getScanId() == null ? "" : pageList.get(i).getScanId());
                    pageList.get(i).setInAccountMonth(
                        pageList.get(i).getInAccountMonth() == null ? "" : pageList.get(i).getInAccountMonth());
                    if ("0".equals(pageList.get(i).getAmortizeStatus())) {
                        pageList.get(i).setAmortizeStatus("否");
                    } else if ("1".equals(pageList.get(i).getAmortizeStatus())) {
                        pageList.get(i).setAmortizeStatus("是");
                    }
                    for (RzfsEnum e : RzfsEnum.values()) {
                        if (e.getRzfsDm().equals(pageList.get(i).getRzfs())) {
                            pageList.get(i).setRzfs(e.getRzfsMc(e.getIndex()));
                        }
                    }
                    if ("0".equals(pageList.get(i).getCollectStatus())) {
                        pageList.get(i).setCollectStatus("未采集");
                    } else if ("1".equals(pageList.get(i).getCollectStatus())) {
                        pageList.get(i).setCollectStatus("已采集");
                    }

                    String selected = "0";
                    //源文件展示与否处理
                    String xmlFlag = pageList.get(i).getXmlFlag();
                    //xml
                    if(xmlFlag.contains("1")||xmlFlag.contains("4")){
                        pageList.get(i).setSourceXml("有");
                        selected = "1";
                    }else{
                        pageList.get(i).setSourceXml("--");
                    }
                    //pdf
                    if(xmlFlag.contains("2")||xmlFlag.contains("5")){
                        pageList.get(i).setSourcePdf("有");
                        selected = "1";
                    }else{
                        pageList.get(i).setSourcePdf("--");
                    }
                    //ofd
                    if(xmlFlag.contains("3")||xmlFlag.contains("6")){
                        pageList.get(i).setSourceOfd("有");
                        selected = "1";
                    }else{
                        pageList.get(i).setSourceOfd("--");
                    }
                    pageList.get(i).setSelected(selected);

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

                    //入账状态
                    //已入账  02 05  未入账  01 03 04
                    String lqRzzt = pageList.get(i).getLqRzzt();
                    if("02".equals(lqRzzt)||"05".equals(lqRzzt)){
                        pageList.get(i)
                                .setLqRzzt("已入账");
                    }else{
                        pageList.get(i)
                                .setLqRzzt("未入账");
                    }
                }
            }

            // 设置记录总数
            json.put("total", pageInfo.getTotal());
            List<ExtAddTaxInvoice> resultList = pageInfo.getList();
            json.put("datalist", resultList);
        } catch (Exception e) {
            // 统一设置操作异常标识
            json = super.errorResult(e);
        }
        return super.responseResult(json);
    }

    @Override
    public Object listOther(Map<String, Object> pramsMap, int curr, int size) {
        JSONObject json = new JSONObject();
        DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);
        try {
            String[] titlelist =
                {"序号", "发票类型", "发票代码", "发票号码", "开票日期", "金额", "签收状态", "签收日期", "签收方式", "签收人", "业务单号", "入池时间"};
            String[] titleprop = {"xh", "invoiceTypeString", "invoiceCode", "invoiceNo", "invoiceDate", "invoiceAmount",
                "qszt", "qsrq", "qsfs", "qsr", "businessDocumentNumber", "createDate"};
            // 需要设置返回列表标题时调用
            json = super.setTitleList(titlelist, titleprop);
            PageHelper.startPage(curr, size);
            // 合计信息,仅第一页时需要统计，减少数据库压力
            if (curr == 1) {
                String hjsl = "0";
                String hjje = "0.00";
                String hjse = "0.00";
                List<ExtOtherInvoice> hjList = super.baseMapper.selectOtherHj(pramsMap);
                if (hjList.size() > 0) {
                    ExtOtherInvoice hjxx = hjList.get(0);
                    hjsl = hjxx.getId();
                    if (!"0".equals(hjsl)) {
                        hjje = AmountFormatUtil.fmtMicrometer(MathUtil.round(hjxx.getInvoiceAmount()));
                        hjse = AmountFormatUtil.fmtMicrometer(MathUtil.round(hjxx.getTaxAmount()));
                    }
                }

                json.put("hjsl", hjsl);
                json.put("hjje", hjje);
                json.put("hjse", hjse);
            }
            PageHelper.startPage(curr, size);
            List<ExtOtherInvoice> pageList = super.baseMapper.listOtherInvoice(pramsMap);
            PageInfo<ExtOtherInvoice> pageInfo = new PageInfo<>(pageList);
            // 用于页面返回list对象
            if (pageList != null && pageList.size() > 0) {
                int start = (int)pageInfo.getStartRow();
                for (int i = 0; i < pageList.size(); i++) {
                    pageList.get(i).setXh(String.valueOf(i + start));
                    pageList.get(i).setInvoiceAmount(
                        AmountFormatUtil.fmtMicrometer(MathUtil.round(pageList.get(i).getInvoiceAmount())));
                    for (FpqsjgEnum e : FpqsjgEnum.values()) {
                        if (e.getQsjgDm().equals(pageList.get(i).getQszt())) {
                            pageList.get(i).setQszt(e.getQsjgMc(e.getIndex()));
                        }
                    }
                    for (QsfsEnum e : QsfsEnum.values()) {
                        if (e.getQsfsDm().equals(pageList.get(i).getQsfs())) {
                            pageList.get(i).setQsfs(e.getQsfsMc(e.getIndex()));
                        }
                    }
                    if ("电票上传签收".equals(pageList.get(i).getQsfs())) {
                        pageList.get(i).setQsfs("电票签收");
                    }
                    if ("接口推送".equals(pageList.get(i).getQsfs())) {
                        pageList.get(i).setQsfs("接口签收");
                    }
                    pageList.get(i).setQsrq(pageList.get(i).getQsrq() == null ? "" : pageList.get(i).getQsrq());
                    pageList.get(i).setScanId(pageList.get(i).getScanId() == null ? "" : pageList.get(i).getScanId());
                    pageList.get(i)
                        .setInvoiceTypeString(dictdetaServcice.queryDictName(DictConstant.INVOICE_TYPEALL, pageList.get(i).getInvoiceType()));
                }

            }

            // 设置记录总数
            json.put("total", pageInfo.getTotal());
            List<ExtOtherInvoice> resultList = pageInfo.getList();
            json.put("datalist", resultList);
        } catch (Exception e) {
            // 统一设置操作异常标识
            json = super.errorResult(e);
        }

        return super.responseResult(json);
    }

    @Override
    public Object listSaleInvoice(Map<String, Object> pramsMap, int curr, int size) {
        JSONObject json = new JSONObject();
        DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);
        try {
            String[] titlelist = {"序号", "发票类型", "特定业务", "发票代码", "发票号码","数电号码","发票状态", "开票日期", "源文件PDF", "源文件OFD", "源文件XML",  "购方名称", "购方税号", "金额", "税额", "价税合计",
                "清单标志", "备注", "优惠政策类型", "采集状态", "采集时间", "采集来源", "签收方式", "对接系统", "签收状态", "签收日期", "签收人","财务入账月份", "财务入账状态",
                "凭证号", "业务单号", "入池时间"};

            String[] titleprop = {"xh", "invoiceType", "lqTdyslxDm","invoiceCode", "invoiceNo","eleInvoiceNo", "invoiceStatus", "invoiceDate","sourcePdf","sourceOfd","sourceXml",
                "gfmc", "gfsh", "invoiceAmount", "taxAmount", "totalAmount", "listStatus", "remark", "incentiveFlag",
                "collectStatus", "collectDate", "collectFrom", "qsfs", "systemName", "qszt", "qsrq", "qsr",
                "inAccountMonth", "inAccountStatus", "voucherNo", "documentNumber", "createDate"};
            // 需要设置返回列表标题时调用
            json = super.setTitleList(titlelist, titleprop);
            PageHelper.startPage(curr, size);
            // 合计信息,仅第一页时需要统计，减少数据库压力
            if (curr == 1) {
                String hjsl = "0";
                String hjje = "0.00";
                String hjse = "0.00";
                List<ExtAddTaxInvoice> hjList = super.baseMapper.selectSaleHj(pramsMap);
                if (hjList.size() > 0) {
                    ExtAddTaxInvoice hjxx = hjList.get(0);
                    hjsl = hjxx.getId();
                    if (!"0".equals(hjsl)) {
                        hjje = AmountFormatUtil.fmtMicrometer(MathUtil.round(hjxx.getInvoiceAmount()));
                        hjse = AmountFormatUtil.fmtMicrometer(MathUtil.round(hjxx.getTaxAmount()));
                    }
                }

                json.put("hjsl", hjsl);
                json.put("hjje", hjje);
                json.put("hjse", hjse);
            }
            PageHelper.startPage(curr, size);
            List<ExtAddTaxInvoice> pageList = super.baseMapper.listSaleInvoice(pramsMap);
            PageInfo<ExtAddTaxInvoice> pageInfo = new PageInfo<>(pageList);
            // 用于页面返回list对象
            if (pageList.size() > 0) {

                int start = (int)pageInfo.getStartRow();
                for (int i = 0; i < pageList.size(); i++) {
                    pageList.get(i).setXh(String.valueOf(i + start));
                    pageList.get(i).setInvoiceAmount(
                        AmountFormatUtil.fmtMicrometer(MathUtil.round(pageList.get(i).getInvoiceAmount())));
                    if (pageList.get(i).getYxse() != null || !"".equals(pageList.get(i).getYxse())) {
                        pageList.get(i)
                            .setYxse(AmountFormatUtil.fmtMicrometer(MathUtil.round(pageList.get(i).getYxse())));
                    }
                    pageList.get(i).setTotalAmount(
                        AmountFormatUtil.fmtMicrometer(MathUtil.round(pageList.get(i).getTotalAmount())));
                    pageList.get(i)
                        .setTaxAmount(AmountFormatUtil.fmtMicrometer(MathUtil.round(pageList.get(i).getTaxAmount())));
                    for (FpztEnum e : FpztEnum.values()) {
                        if (e.getFpztDm().equals(pageList.get(i).getInvoiceStatus())) {
                            pageList.get(i).setInvoiceStatus(e.getFpztMc(e.getIndex()));
                        }
                    }
                    for (FpqsjgEnum e : FpqsjgEnum.values()) {
                        if (e.getQsjgDm().equals(pageList.get(i).getQszt())) {
                            pageList.get(i).setQszt(e.getQsjgMc(e.getIndex()));
                        }
                    }
                    for (RzztEnum e : RzztEnum.values()) {
                        if (e.getRzztDm().equals(pageList.get(i).getRzzt())) {
                            pageList.get(i).setRzzt(e.getRzztMc(e.getIndex()));
                        }
                    }
                    for (QsfsEnum e : QsfsEnum.values()) {
                        if (e.getQsfsDm().equals(pageList.get(i).getQsfs())) {
                            pageList.get(i).setQsfs(e.getQsfsMc(e.getIndex()));
                        }
                    }
                    if ("电票上传签收".equals(pageList.get(i).getQsfs())) {
                        pageList.get(i).setQsfs("电票签收");
                    }
                    if ("接口推送".equals(pageList.get(i).getQsfs())) {
                        pageList.get(i).setQsfs("接口签收");
                    }
                    if ("1".equals(pageList.get(i).getRzlx())) {
                        pageList.get(i).setRzlx("认证抵扣");
                    } else if ("2".equals(pageList.get(i).getRzlx())) {
                        pageList.get(i).setRzlx("认证退税");
                    } else if ("3".equals(pageList.get(i).getRzlx())) {
                        pageList.get(i).setRzlx("认证代办退税");
                    } else if ("4".equals(pageList.get(i).getRzlx())) {
                        pageList.get(i).setRzlx("认证不抵扣");
                    } else {
                        pageList.get(i).setRzlx("");
                    }
                    if ("0".equals(pageList.get(i).getInAccountStatus())) {
                        pageList.get(i).setInAccountStatus("未入账");
                    } else if ("1".equals(pageList.get(i).getInAccountStatus())) {
                        pageList.get(i).setInAccountStatus("已入账");
                    } else {
                        pageList.get(i).setInAccountStatus("");
                    }
                    if ("0".equals(pageList.get(i).getListStatus())) {
                        pageList.get(i).setListStatus("否");
                    } else if ("1".equals(pageList.get(i).getListStatus())) {
                        pageList.get(i).setListStatus("是");
                    } else {
                        pageList.get(i).setListStatus("");
                    }
                    if ("0".equals(pageList.get(i).getCollectFrom())) {
                        pageList.get(i).setCollectFrom("进项采集");
                    } else if ("1".equals(pageList.get(i).getCollectFrom())) {
                        pageList.get(i).setCollectFrom("票据采集");
                    } else if ("4".equals(pageList.get(i).getCollectFrom())) {
                        pageList.get(i).setCollectFrom("大企业归集");
                    }
                    if ("0".equals(pageList.get(i).getCollectStatus())) {
                        pageList.get(i).setCollectStatus("未采集");
                    } else if ("1".equals(pageList.get(i).getCollectStatus())) {
                        pageList.get(i).setCollectStatus("已采集");
                    }
                    pageList.get(i).setQsrq(pageList.get(i).getQsrq() == null ? "" : pageList.get(i).getQsrq());
                    pageList.get(i).setInAccountMonth(
                        pageList.get(i).getInAccountMonth() == null ? "" : pageList.get(i).getInAccountMonth());
                    pageList.get(i).setScanId(pageList.get(i).getScanId() == null ? "" : pageList.get(i).getScanId());
                    pageList.get(i).setInvoiceType(dictdetaServcice.queryDictName(DictConstant.INVOICE_TYPEALL, pageList.get(i).getInvoiceType()));

                    String selected = "0";
                    //源文件展示与否处理
                    String xmlFlag = pageList.get(i).getXmlFlag();
                    //xml
                    if(xmlFlag.contains("1")||xmlFlag.contains("4")){
                        pageList.get(i).setSourceXml("有");
                        selected = "1";
                    }else{
                        pageList.get(i).setSourceXml("--");
                    }
                    //pdf
                    if(xmlFlag.contains("2")||xmlFlag.contains("5")){
                        pageList.get(i).setSourcePdf("有");
                        selected = "1";
                    }else{
                        pageList.get(i).setSourcePdf("--");
                    }
                    //ofd
                    if(xmlFlag.contains("3")||xmlFlag.contains("6")){
                        pageList.get(i).setSourceOfd("有");
                        selected = "1";
                    }else{
                        pageList.get(i).setSourceOfd("--");
                    }
                    pageList.get(i).setSelected(selected);

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

                }
            }

            // 设置记录总数
            json.put("total", pageInfo.getTotal());
            List<ExtAddTaxInvoice> resultList = pageInfo.getList();
            json.put("datalist", resultList);
        } catch (Exception e) {
            // 统一设置操作异常标识
            json = super.errorResult(e);
        }
        return super.responseResult(json);
    }

    /**
     * 摊销记录
     *
     * @param pramsMap
     *            查询条件
     * @return 返回
     */
    @Override
    public Object amortizeRecord(Map<String, Object> pramsMap) {
        JSONObject json = new JSONObject();
        DynamicContextHolder.push(pramsMap.get("dbName") + DbConstant.BUSINESS_READ);
        try {
            String[] titlelist = {"序号", "业务单号", "已摊销金额", "剩余金额", "报销人"};
            String[] titleprop = {"xh", "amortizeDocumentNumber", "amortizeAmount", "remainAmortizeAmount", "bxr"};
            // 需要设置返回列表标题时调用
            json = super.setTitleList(titlelist, titleprop);
            List<AmortizeRecordEntity> pageList = super.baseMapper.listAmortizeRecord(pramsMap);
            PageInfo<AmortizeRecordEntity> pageInfo = new PageInfo<>(pageList);
            // 用于页面返回list对象
            if (pageList != null && pageList.size() > 0) {
                for (int i = 0; i < pageList.size(); i++) {
                    pageList.get(i).setXh(String.valueOf(i + 1));
                    pageList.get(i).setAmortizeAmount(
                        AmountFormatUtil.fmtMicrometer(MathUtil.round(pageList.get(i).getAmortizeAmount())));
                    pageList.get(i).setRemainAmortizeAmount(
                        AmountFormatUtil.fmtMicrometer(MathUtil.round(pageList.get(i).getRemainAmortizeAmount())));

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

    @Override
    public Object incentiveFlagList(String dbName) {
        JSONObject json = new JSONObject();
        DynamicContextHolder.push(dbName + DbConstant.DETAIL_READ);
        List<String> incentiveFlagList = super.baseMapper.listIncentiveFlag();
        json.put("incentiveFlagList", incentiveFlagList);
        return super.responseResult(json);
    }
}
