package cn.superdesk.uniorder.service.invoice.customer.invoiced.impl;

import cn.hutool.core.util.StrUtil;
import cn.superdesk.uniorder.common.enums.invoice.InvoiceInvoicedIsInvalidEnum;
import cn.superdesk.uniorder.common.enums.invoice.InvoiceInvoicedIsOverdueEnum;
import cn.superdesk.uniorder.common.enums.invoice.InvoiceInvoicedIsRedWriteOffEnum;
import cn.superdesk.uniorder.common.enums.invoice.InvoiceInvoicedOperationLogOperationTypeEnum;
import cn.superdesk.uniorder.common.enums.invoice.customer.InvoiceApplyCustomerBackAccountStatusEnum;
import cn.superdesk.uniorder.common.json.AnJsonUtils;
import cn.superdesk.uniorder.common.mq.redis.service.RedisManager;
import cn.superdesk.uniorder.common.mq.redis.service.RedisService;
import cn.superdesk.uniorder.common.numerical.*;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dao.convert.Dto2EntityConvertUtils;
import cn.superdesk.uniorder.dao.entity.invoice.common.InvoiceBankInfo;
import cn.superdesk.uniorder.dao.entity.invoice.common.InvoiceType;
import cn.superdesk.uniorder.dao.entity.invoice.customer.invoiced.InvoiceInvoiced;
import cn.superdesk.uniorder.dao.entity.invoice.customer.invoiced.InvoiceInvoicedExample;
import cn.superdesk.uniorder.dao.entity.organisation.SysEnterpriseExtInvoice;
import cn.superdesk.uniorder.dao.mapper.invoice.customer.invoiced.InvoiceInvoicedMapper;
import cn.superdesk.uniorder.dao.mapper.invoice.customer.invoiced.InvoiceInvoicedMapperEx;
import cn.superdesk.uniorder.dto.param.invoice.customer.invoiced.InvoiceInvoicedQueryCriteria;
import cn.superdesk.uniorder.dto.param.invoice.excel.*;
import cn.superdesk.uniorder.dto.vo.invoice.customer.invoiced.*;
import cn.superdesk.uniorder.service.invoice.customer.invoiced.InvoiceInvoicedOperationLogService;
import cn.superdesk.uniorder.service.invoice.customer.invoiced.InvoiceInvoicedService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * @Description:
 * @Author: linjinyu
 * @Email linjinyu@avic-s.com
 * @CreateDate: 2021-03-16 17:29:47
 * @UpdateUser: linjinyu
 * @UpdateDate: 2021-03-16 17:29:47
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Service
public class InvoiceInvoicedServiceImpl implements InvoiceInvoicedService {

    @Autowired
    private InvoiceInvoicedMapper   invoiceInvoicedMapper;
    @Autowired
    private InvoiceInvoicedMapperEx invoiceInvoicedMapperEx;

    @Autowired
    private InvoiceInvoicedOperationLogService invoiceInvoicedOperationLogService;

    @Autowired
    private RedisService redisService;
    @Autowired
    private RedisManager redisManager;


    /****************************************** extends BaseService 部分 start ******************************************/

    @Override
    public int insertSelective(InvoiceInvoiced entity) {
        return invoiceInvoicedMapper.insertSelective(entity);
    }

    @Override
    public int updateByPrimaryKeySelective(InvoiceInvoiced entity) {
        return invoiceInvoicedMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public void deleteObj(Long id) {
    }

    @Override
    public InvoiceInvoiced findById(Long id) {
        return invoiceInvoicedMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<InvoiceInvoiced> findByPaging(Map<String, Object> conditions, Integer pageNun, Integer pageSize) {
        return null;
    }

    @Override
    public List<InvoiceInvoiced> findAll(Map<String, Object> queryMap) {
        return null;
    }

    /****************************************** extends BaseService 部分   end ******************************************/


    public void addInvoiceInvoiced(InvoiceInvoiced entity) {
        invoiceInvoicedMapper.insertSelective(entity);
    }

    public void updateInvoiceInvoiced(InvoiceInvoiced entity) {

//		InvoiceInvoiced originEntity = invoiceInvoicedMapper.selectByPrimaryKey(entity.getId());

        InvoiceInvoiced originEntity = findInvoiceInvoicedByInvoiceNumber(entity.getInvoiceNumber());

//		AssertUtil.notNull(originEntity);
        AnBeanUtils.copy(entity, originEntity);
        invoiceInvoicedMapper.updateByPrimaryKeySelective(originEntity);
    }

    public void updateInvoiceInvoicedByPrimaryKeySelective(InvoiceInvoiced entity) {
        invoiceInvoicedMapper.updateByPrimaryKeySelective(entity);
    }

    public void deleteInvoiceInvoiced(Long id) {
        invoiceInvoicedMapper.deleteByPrimaryKey(id);
    }

    public InvoiceInvoiced findInvoiceInvoicedById(Long id) {
        InvoiceInvoiced entity = invoiceInvoicedMapper.selectByPrimaryKey(id);
//		AssertUtil.notNull(entity);
        return entity;
    }

    public InvoiceInvoiced findInvoiceInvoicedByInvoiceNumber(String invoiceNumber) {

        InvoiceInvoiced invoiceInvoiced = null;

        InvoiceInvoicedExample example = new InvoiceInvoicedExample();
        example.createCriteria()
                .andInvoiceNumberEqualTo(invoiceNumber);

        List<InvoiceInvoiced> result = invoiceInvoicedMapper.selectByExample(example);

        if (AnCollectionUtils.isNotEmpty(result)) {
            invoiceInvoiced = result.get(0);
        }

        return invoiceInvoiced;

    }

    public R<List<InvoiceInvoiced>> pageQuery(Map<String, Object> conditions, int pageNun, int pageSize) {

        // 样例 保留
//		InvoiceInvoiced invoiceInvoicedConditions = AnBeanUtils.mapToBean(conditions,InvoiceInvoiced.class);

        InvoiceInvoicedExample          example  = new InvoiceInvoicedExample();
        InvoiceInvoicedExample.Criteria criteria = example.createCriteria();

        example.setOrderByClause("invoiced_date DESC");

        PageHelper.startPage(pageNun, pageSize);
        List<InvoiceInvoiced>     resultList = invoiceInvoicedMapper.selectByExample(example);
        PageInfo<InvoiceInvoiced> page       = new PageInfo<InvoiceInvoiced>(resultList);
        PageHelper.clearPage();

        return new R<List<InvoiceInvoiced>>(page.getPageNum(), page.getPageSize(), (int) page.getTotal(), resultList);

    }

    public R<List<InvoiceInvoicedExcelExportVo>> pageQueryByCriteria(InvoiceInvoicedQueryCriteria queryCriteria) {


//		InvoiceInvoicedExample          example  = new InvoiceInvoicedExample();
//		InvoiceInvoicedExample.Criteria criteria = example.createCriteria();
        // 还是不要这样写
//		if(null != queryCriteria.getSellerMainId()){
//
//		}
//		if(null != queryCriteria.getSellerCompanyName()){
//
//		}
//
//		if(null != queryCriteria.getIsOverdue()){
//
//		}
//		if(null != queryCriteria.getOverdueDays()){
//
//		}

//		example.setOrderByClause("invoiced_date DESC");

        PageHelper.startPage(queryCriteria.getPageNumber(), queryCriteria.getPageSize());

//		List<InvoiceInvoiced>     resultList = invoiceInvoicedMapper.selectByExample(example);

        List<InvoiceInvoicedExcelExportVo> resultList = invoiceInvoicedMapperEx.pageQueryByCriteria(queryCriteria);

        // 附加信息 call
        additionalInfoInvoiceInvoicedExcelExportVo(resultList);

        PageInfo<InvoiceInvoicedExcelExportVo> page = new PageInfo<InvoiceInvoicedExcelExportVo>(resultList);
        PageHelper.clearPage();

        return new R<List<InvoiceInvoicedExcelExportVo>>(page.getPageNum(), page.getPageSize(), (int) page.getTotal(), resultList);
    }

    public List<InvoiceInvoicedExcelExportVo> queryByCriteria(InvoiceInvoicedQueryCriteria queryCriteria) {
        List<InvoiceInvoicedExcelExportVo> resultList = invoiceInvoicedMapperEx.pageQueryByCriteria(queryCriteria);

        // 附加信息 call
        additionalInfoInvoiceInvoicedExcelExportVo(resultList);

        return resultList;
    }

    /**
     * 附加信息 方法体
     *
     * @param resultList
     */
    private void additionalInfoInvoiceInvoicedExcelExportVo(List<InvoiceInvoicedExcelExportVo> resultList) {

        resultList.forEach(item -> {

            // yyyy-MM-dd HH:mm:ss yyyy/MM/dd
            item.setInvoicedDateFormatStr(AnDateUtils.format(item.getInvoicedDate(), "yyyy年MM月dd日"));

            item.setTotalAmountFormatStr(AnBigDecimalUtils.getBigDecimalFormat(item.getTotalAmount()));
            item.setTotalTaxFormatStr(AnBigDecimalUtils.getBigDecimalFormat(item.getTotalTax()));
            item.setTotalAmountIncludingTaxFormatStr(AnBigDecimalUtils.getBigDecimalFormat(item.getTotalAmountIncludingTax()));
            item.setReceivableAmountFormatStr(AnBigDecimalUtils.getBigDecimalFormat(item.getReceivableAmount()));

            // 是否红冲:0-否;1-是;
            item.setIsRedWriteOffName(InvoiceInvoicedIsRedWriteOffEnum.get(AnIntegerUtils.getInteger(item.getIsRedWriteOff(), 0)).getDesc());


            item.setRedWriteOffAmountFormatStr(AnBigDecimalUtils.getBigDecimalFormat(item.getRedWriteOffAmount()));

            // 是否回款_回款状态:0-未回款;1-部分回款;2-全部回款;69-红冲发票;
            item.setIsBackCollectionName(InvoiceApplyCustomerBackAccountStatusEnum.get(AnIntegerUtils.getInteger(item.getIsBackCollection(), 0)).getDesc());

            item.setBackCollectionTimeFormatStr(AnDateUtils.format(item.getBackCollectionTime(), "yyyy年MM月dd日"));

            item.setBackCollectionAmountAlreadyFormatStr(AnBigDecimalUtils.getBigDecimalFormat(item.getBackCollectionAmountAlready()));
            item.setBackCollectionAmountWaitForFormatStr(AnBigDecimalUtils.getBigDecimalFormat(item.getBackCollectionAmountWaitFor()));

            // 是否作废:0-正常;1-作废
            item.setIsInvalidName(InvoiceInvoicedIsInvalidEnum.get(AnIntegerUtils.getInteger(item.getIsInvalid(), 0)).getDesc());

            // 是否逾期 0<=逾期天数 =IF(0<=B917,已逾期,未逾期):0-未逾期;1-已逾期;
            item.setIsOverdueName(InvoiceInvoicedIsOverdueEnum.get(AnIntegerUtils.getInteger(item.getIsOverdue(), 0)).getDesc());


        });

    }

    public R<InvoiceInvoicedHeadSum> headSumInvoiceInvoiceds(InvoiceInvoicedQueryCriteria criteria) {

        InvoiceInvoicedHeadSumAmount                 invoiceInvoicedHeadSumAmount               = invoiceInvoicedMapperEx.headSumAmount(criteria);
        List<InvoiceInvoicedHeadSumIsBackCollection> invoiceInvoicedHeadSumIsBackCollectionList = invoiceInvoicedMapperEx.headSumIsBackCollection(criteria);
        List<InvoiceInvoicedHeadSumIsOverdue>        invoiceInvoicedHeadSumIsOverdueList        = invoiceInvoicedMapperEx.headSumIsOverdue(criteria);


        Map<Integer, InvoiceApplyCustomerBackAccountStatusEnum> integerInvoiceApplyBackAccountStatusEnumMap = AnEnumUtils.invoiceApplyBackAccountStatusEnumConvertToMap();
        for (Map.Entry<Integer, InvoiceApplyCustomerBackAccountStatusEnum> _iterator01 : integerInvoiceApplyBackAccountStatusEnumMap.entrySet()) {

            log.info("entry {} {}", _iterator01.getKey(), _iterator01.getValue());

            Optional<InvoiceInvoicedHeadSumIsBackCollection> invoiceInvoicedHeadSumIsBackCollectionOptional = invoiceInvoicedHeadSumIsBackCollectionList
                    .stream()
                    .filter(item -> item.getIsBackCollection().equals(_iterator01.getKey()))
                    .findFirst();

            // 不存在 补刀
            if (invoiceInvoicedHeadSumIsBackCollectionOptional.isPresent()) {
                InvoiceInvoicedHeadSumIsBackCollection _bmp = invoiceInvoicedHeadSumIsBackCollectionOptional.get();
                _bmp.setIsBackCollectionName(_iterator01.getValue().getDesc());
            } else {
                InvoiceInvoicedHeadSumIsBackCollection _tmp = new InvoiceInvoicedHeadSumIsBackCollection();
                _tmp.setCountIsBackCollection(0);
                _tmp.setIsBackCollection(_iterator01.getKey());
                _tmp.setIsBackCollectionName(_iterator01.getValue().getDesc());

                invoiceInvoicedHeadSumIsBackCollectionList.add(_tmp);
            }

        }

        Map<Integer, InvoiceInvoicedIsOverdueEnum> integerInvoiceInvoicedIsOverdueEnumMap = AnEnumUtils.invoiceInvoicedIsOverdueEnumConvertToMap();
        for (Map.Entry<Integer, InvoiceInvoicedIsOverdueEnum> _iterator02 : integerInvoiceInvoicedIsOverdueEnumMap.entrySet()) {

            log.info("entry {} {}", _iterator02.getKey(), _iterator02.getValue());

            Optional<InvoiceInvoicedHeadSumIsOverdue> invoicedHeadSumIsOverdueOptional = invoiceInvoicedHeadSumIsOverdueList
                    .stream()
                    .filter(item -> item.getIsOverdue().equals(_iterator02.getKey()))
                    .findFirst();

            // 不存在 补刀
            if (invoicedHeadSumIsOverdueOptional.isPresent()) {
                InvoiceInvoicedHeadSumIsOverdue _bmp = invoicedHeadSumIsOverdueOptional.get();
                _bmp.setIsOverdueName(_iterator02.getValue().getDesc());
            } else {
                InvoiceInvoicedHeadSumIsOverdue _tmp = new InvoiceInvoicedHeadSumIsOverdue();
                _tmp.setCountIsOverdue(0);
                _tmp.setIsOverdue(_iterator02.getKey());
                _tmp.setIsOverdueName(_iterator02.getValue().getDesc());

                invoiceInvoicedHeadSumIsOverdueList.add(_tmp);
            }
        }

        InvoiceInvoicedHeadSum headSum = new InvoiceInvoicedHeadSum();

        headSum.setHeadSumAmount(invoiceInvoicedHeadSumAmount);
        headSum.setHeadSumIsBackCollectionList(invoiceInvoicedHeadSumIsBackCollectionList);
        headSum.setHeadSumIsOverdueList(invoiceInvoicedHeadSumIsOverdueList);

        return new R<InvoiceInvoicedHeadSum>(headSum);

    }


    /****************************************** excel import start ******************************************/

    /**
     * 基于 税局的 发票号码 来作唯一处理
     *
     * @param excelRow
     * @param loginSysUser
     */
    @Override
    public void saveOrUpdate4ThirdPartTaxationSzhtxxE6ExcelRowByInvoiceNumber(TaxationSzhtxxE6ExcelRow excelRow, LoginSysUser loginSysUser) {


//		@ExcelProperty(value = "发票号码", index = 4)
//		private String invoiceNumber;
        if (null == excelRow) {
            return;
        }

        InvoiceInvoiced entity       = AnBeanUtils.copy(excelRow, InvoiceInvoiced.class);
        InvoiceInvoiced checkIsExist = findInvoiceInvoicedByInvoiceNumber(entity.getInvoiceNumber());

        if (null == checkIsExist) {
            addInvoiceInvoiced(entity);
        } else {
            updateInvoiceInvoiced(entity);
        }

    }

    @Override
    public void saveOrUpdate4ThirdPartTaxationSzhtxxE6ExcelRowListByInvoiceNumber(List<TaxationSzhtxxE6ExcelRow> excelRowList, LoginSysUser loginSysUser) {

        excelRowList.forEach(excelRow -> {
            saveOrUpdate4ThirdPartTaxationSzhtxxE6ExcelRowByInvoiceNumber(excelRow, loginSysUser);
        });
    }

    @Override
    public void saveOrUpdate4ThirdPartTaxationYqzs17WinV30ExcelRowByInvoiceNumber(TaxationYqzs17WinV30ExcelRow excelRow, LoginSysUser loginSysUser) {

        if (null == excelRow) {
            return;
        }

        InvoiceInvoiced entity = new InvoiceInvoiced();
        Dto2EntityConvertUtils.taxationYqzs17WinV30ExcelRow2InvoiceInvoicedEntity(excelRow, entity);

        log.info("saveOrUpdate4ThirdPartTaxationYqzs17WinListByInvoiceNumber\n{}\n{}", AnJsonUtils.toJson(excelRow), AnJsonUtils.toJson(entity));

        InvoiceInvoiced checkIsExist = findInvoiceInvoicedByInvoiceNumber(entity.getInvoiceNumber());

        if (null == checkIsExist) {
            addInvoiceInvoiced(entity);
        } else {
            updateInvoiceInvoiced(entity);
        }

    }

    @Override
    public void saveOrUpdate4ThirdPartTaxationYqzs17WinV30ExcelRowListByInvoiceNumber(List<TaxationYqzs17WinV30ExcelRow> excelRowList, LoginSysUser loginSysUser) {

        excelRowList.forEach(excelRow -> {
            saveOrUpdate4ThirdPartTaxationYqzs17WinV30ExcelRowByInvoiceNumber(excelRow, loginSysUser);
        });
    }

    @Override
    public void saveOrUpdate4SuperdeskFinanceArtificial001ExcelRowByInvoiceNumber(SuperdeskFinanceArtificial001ExcelRow excelRow, LoginSysUser loginSysUser) {

        if (null == excelRow) {
            return;
        }

        InvoiceInvoiced entity = new InvoiceInvoiced();
        Dto2EntityConvertUtils.superdeskFinanceArtificial001ExcelRow2InvoiceInvoicedEntity(excelRow, entity);

        log.info("saveOrUpdate4SuperdeskFinanceArtificial001ExcelRowByInvoiceNumber\n{}\n{}", AnJsonUtils.toJson(excelRow), AnJsonUtils.toJson(entity));

        InvoiceInvoiced checkIsExist = findInvoiceInvoicedByInvoiceNumber(entity.getInvoiceNumber());

        if (null == checkIsExist) {
            addInvoiceInvoiced(entity);
        } else {
            updateInvoiceInvoiced(entity);
        }
    }

    @Override
    public void saveOrUpdate4SuperdeskFinanceArtificial001ExcelRowListByInvoiceNumber(List<SuperdeskFinanceArtificial001ExcelRow> excelRowList, LoginSysUser loginSysUser) {


        // 数据转换

        //	所属公司 ---- 销方名称 是要转换的
//		@ExcelProperty(value = "所属公司", index = 0)
//		private String sellerCompanyName;
//		超级前台
//		楼宇云仓
//		云仓前台
//		云仓前台-大闸蟹
//		云仓前台-水站
//		云仓前台
//		云仓前台-水


//		@ExcelProperty(value = "是否逾期:已逾期;未逾期;是;", index = 2)
//		private String  isOverdueName;
//		private Integer isOverdue;

//		@ExcelProperty(value = "物业公司", index = 3)
//		private String propertyCompanyName;
//		private Long   propertyCompanyId;// 物业公司-Id-统一订单 sys_user_id ---- add

//		@ExcelProperty(value = "客户经理", index = 4)
//		private String customerManagerName;
//		private Long   customerManagerId;// 客户经理-Id-统一订单 sys_user_id ---- add

        //	重点推进 --- 目前数据库是没有这个字段的, 只有 是否重点推进:0-否;1-是; private Integer isPushHardly;
//		@ExcelProperty(value = "重点推进", index = 12)
//		private String     isPushHardlyName;
//		private Integer    isPushHardly;


        excelRowList.forEach(excelRow -> {
            saveOrUpdate4SuperdeskFinanceArtificial001ExcelRowByInvoiceNumber(excelRow, loginSysUser);
        });
    }


    @Override
    public void saveOrUpdate4InvoiceInvoicedHistoryExcelRowByInvoiceNumber(InvoiceInvoicedHistoryExcelRow excelRow, LoginSysUser loginSysUser) {

        if (null == excelRow) {
            return;
        }

        InvoiceInvoiced forUpdate = new InvoiceInvoiced();
        Dto2EntityConvertUtils.invoiceInvoicedHistoryExcelRow2InvoiceInvoicedEntity(excelRow, forUpdate);
        log.info("saveOrUpdate4InvoiceInvoicedHistoryExcelRowByInvoiceNumber\n{}\n{}", AnJsonUtils.toJson(excelRow), AnJsonUtils.toJson(forUpdate));
        InvoiceInvoiced checkIsExist = findInvoiceInvoicedByInvoiceNumber(forUpdate.getInvoiceNumber());

        // TODO 附加信息
        // ...
        additionalInfoSeller(forUpdate, checkIsExist);
        additionalInfoPurchaser(forUpdate, checkIsExist);
        additionalInfoInvoiceType(forUpdate, checkIsExist);

        // 操作日志
        invoiceInvoicedOperationLogService.commonOperationLog(checkIsExist, forUpdate, excelRow, loginSysUser, InvoiceInvoicedOperationLogOperationTypeEnum.导入操作_导入历史);

        if (null == checkIsExist) {
            addInvoiceInvoiced(forUpdate);
        } else {
            updateInvoiceInvoiced(forUpdate);
        }
    }

    @Override
    public void saveOrUpdate4InvoiceInvoicedHistoryExcelRowListByInvoiceNumber(List<InvoiceInvoicedHistoryExcelRow> excelRowList, LoginSysUser loginSysUser) {
        excelRowList.forEach(excelRow -> {
            saveOrUpdate4InvoiceInvoicedHistoryExcelRowByInvoiceNumber(excelRow, loginSysUser);
        });
    }

    @Override
    public void saveOrUpdate4InvoiceInvoicedNormalExcelRowByInvoiceNumber(InvoiceInvoicedNormalExcelRow excelRow, LoginSysUser loginSysUser) {

        if (null == excelRow) {
            return;
        }

        InvoiceInvoiced forUpdate = new InvoiceInvoiced();
        Dto2EntityConvertUtils.invoiceInvoicedNormalExcelRow2InvoiceInvoicedEntity(excelRow, forUpdate);
        log.info("saveOrUpdate4InvoiceInvoicedNormalExcelRowByInvoiceNumber\n{}\n{}", AnJsonUtils.toJson(excelRow), AnJsonUtils.toJson(forUpdate));
        InvoiceInvoiced checkIsExist = findInvoiceInvoicedByInvoiceNumber(forUpdate.getInvoiceNumber());

        // TODO 附加信息
        // ...
        additionalInfoSeller(forUpdate, checkIsExist);
        additionalInfoPurchaser(forUpdate, checkIsExist);
        additionalInfoInvoiceType(forUpdate, checkIsExist);

        // 操作日志
        invoiceInvoicedOperationLogService.commonOperationLog(checkIsExist, forUpdate, excelRow, loginSysUser, InvoiceInvoicedOperationLogOperationTypeEnum.导入操作_导入应收);

        if (null == checkIsExist) {
            addInvoiceInvoiced(forUpdate);
        } else {
            updateInvoiceInvoiced(forUpdate);
        }
    }

    @Override
    public void saveOrUpdate4InvoiceInvoicedNormalExcelRowListByInvoiceNumber(List<InvoiceInvoicedNormalExcelRow> excelRowList, LoginSysUser loginSysUser) {
        excelRowList.forEach(excelRow -> {
            saveOrUpdate4InvoiceInvoicedNormalExcelRowByInvoiceNumber(excelRow, loginSysUser);
        });
    }

    /**
     * 销方信息
     *
     * @param entity
     * @param checkIsExist
     */
    public void additionalInfoSeller(InvoiceInvoiced entity, InvoiceInvoiced checkIsExist) {

        // 新增的情况
        if (null == checkIsExist) {
            String cacehJson = redisManager.getHashTableRelationInvoiceBankInfoCompanyName(entity.getInvoiceType());
            if (StrUtil.isNotBlank(cacehJson)) {
                InvoiceBankInfo invoiceBankInfo = AnJsonUtils.toObject(cacehJson, InvoiceBankInfo.class);
                if (null != invoiceBankInfo) {
                    entity.setSellerMainId(invoiceBankInfo.getId());
//					entity.setSellerCompanyName(excelRow.getSellerCompanyName());
                    entity.setSellerTaxpayersIDCode(invoiceBankInfo.getTaxpayersIDCode());
//					entity.setSellerAddressPhone();
//					entity.setSellerPhone(invoiceBankInfo.get);
//					entity.setSellerAddress();
//					entity.setSellerBankAccountNumber();
                    entity.setSellerBankAccount(invoiceBankInfo.getBankAccount());
                    entity.setSellerBankName(invoiceBankInfo.getBankName());
                }
            }

        }
    }

    /**
     * 购方信息
     *
     * @param entity
     * @param checkIsExist
     */
    public void additionalInfoPurchaser(InvoiceInvoiced entity, InvoiceInvoiced checkIsExist) {

        // 新增的情况
        if (null == checkIsExist) {
            String cacehJson = redisManager.getHashTableRelationSysEnterpriseExtInvoiceCompanyName(entity.getPurchaserCompanyName());
            if (StrUtil.isNotBlank(cacehJson)) {
                SysEnterpriseExtInvoice sysEnterpriseExtInvoice = AnJsonUtils.toObject(cacehJson, SysEnterpriseExtInvoice.class);
                if (null != sysEnterpriseExtInvoice) {
                    entity.setPurchaserMainId(sysEnterpriseExtInvoice.getId());
//					entity.setPurchaserCompanyName(excelRow.getPurchaserCompanyName());
//		            entity.setPurchaserTaxpayersIDCode(excelRow.getPurchaserTaxpayersIDCode());
                    entity.setPurchaserAddressPhone(sysEnterpriseExtInvoice.getInvoiceAddressPhone());
                    entity.setPurchaserPhone(sysEnterpriseExtInvoice.getInvoicePhone());
                    entity.setPurchaserAddress(sysEnterpriseExtInvoice.getInvoiceAddress());
                    entity.setPurchaserBankAccountNumber(sysEnterpriseExtInvoice.getInvoiceBankAccountNumber());
                    entity.setPurchaserBankAccount(sysEnterpriseExtInvoice.getInvoiceBank());
                    entity.setPurchaserBankName(sysEnterpriseExtInvoice.getInvoiceAccount());
                }
            }

        }
    }

    public void additionalInfoInvoiceType(InvoiceInvoiced entity, InvoiceInvoiced checkIsExist) {

        // 新增的情况
        if (null == checkIsExist) {
            String cacehJson = redisManager.getHashTableRelationInvoiceTypeTypeName(entity.getInvoiceType());
            if (StrUtil.isNotBlank(cacehJson)) {
                InvoiceType invoiceType = AnJsonUtils.toObject(cacehJson, InvoiceType.class);
                if (null != invoiceType) {
                    entity.setInvoiceTypeId(invoiceType.getId());
                }
            }

        }
    }

}
