package cn.superdesk.uniorder.service.organisation.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import cn.superdesk.uniorder.common.enums.common.CommonEnabledEnum;
import cn.superdesk.uniorder.common.enums.common.CommonIsDefaultEnum;
import cn.superdesk.uniorder.common.enums.common.CommonSoftDeleteEnum;
import cn.superdesk.uniorder.common.exception.utils.AssertUtils;
import cn.superdesk.uniorder.common.lamda.AnLamdaUtils;
import cn.superdesk.uniorder.common.mq.redis.constants.BaseRedisConf;
import cn.superdesk.uniorder.common.mq.redis.constants.RedisKeyPrefix;
import cn.superdesk.uniorder.common.mq.redis.service.RedisService;
import cn.superdesk.uniorder.common.numerical.AnBeanUtils;
import cn.superdesk.uniorder.common.numerical.AnCollectionUtils;
import cn.superdesk.uniorder.common.numerical.AnIntegerUtils;
import cn.superdesk.uniorder.common.numerical.AnLongUtils;
import cn.superdesk.uniorder.common.rest.response.R;
import cn.superdesk.uniorder.common.security.dto.LoginSysUser;
import cn.superdesk.uniorder.dao.entity.organisation.SysCliqueXInvoice;
import cn.superdesk.uniorder.dao.entity.organisation.SysCliqueXInvoiceExample;
import cn.superdesk.uniorder.dao.entity.organisation.SysEnterpriseExtInvoice;
import cn.superdesk.uniorder.dao.entity.organisation.SysEnterpriseExtInvoiceExample;
import cn.superdesk.uniorder.dao.entity.sys.SysUser;
import cn.superdesk.uniorder.dao.mapper.organisation.SysCliqueXInvoiceMapper;
import cn.superdesk.uniorder.dao.mapper.organisation.SysEnterpriseExtInvoiceMapper;
import cn.superdesk.uniorder.dao.mapper.organisation.SysEnterpriseExtInvoiceMapperEx;
import cn.superdesk.uniorder.dto.param.organisation.SysCliqueXInvoiceCriteria;
import cn.superdesk.uniorder.dto.param.organisation.SysEnterpriseExtInvoiceQueryCriteria;
import cn.superdesk.uniorder.dto.param.organisation.SysEnterpriseExtInvoiceXCliqueParam;
import cn.superdesk.uniorder.dto.vo.organisation.SysEnterpriseExtInvoiceExtPathVo;
import cn.superdesk.uniorder.service.organisation.SysEnterpriseExtInvoiceService;
import cn.superdesk.uniorder.service.sys.SysUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * @Description: 企业信息-扩展-发票相关
 * @Author: linjinyu
 * @Email linjinyu@avic-s.com
 * @CreateDate: 2020-08-20 17:51:19
 * @UpdateUser: linjinyu
 * @UpdateDate: 2020-08-20 17:51:19
 * @UpdateRemark: 修改内容
 * @Version: 1.0
 */
@Slf4j
@Service
public class SysEnterpriseExtInvoiceServiceImpl implements SysEnterpriseExtInvoiceService {

    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private SysEnterpriseExtInvoiceMapper   sysEnterpriseExtInvoiceMapper;
    @Autowired
    private SysEnterpriseExtInvoiceMapperEx sysEnterpriseExtInvoiceMapperEx;

    @Autowired
    private SysCliqueXInvoiceMapper sysCliqueXInvoiceMapper;

    @Autowired
    private RedisService redisService;


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


    @Override
    public int insertSelective(SysEnterpriseExtInvoice entity) {
        return sysEnterpriseExtInvoiceMapper.insertSelective(entity);
    }

    @Override
    public int updateByPrimaryKeySelective(SysEnterpriseExtInvoice entity) {
        return sysEnterpriseExtInvoiceMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public void deleteObj(Long id) {
    }

    @Override
    public SysEnterpriseExtInvoice findById(Long id) {
        return sysEnterpriseExtInvoiceMapper.selectByPrimaryKey(id);
    }

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

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

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


    public void addSysEnterpriseExtInvoiceXCliqueParam(SysEnterpriseExtInvoiceXCliqueParam param, LoginSysUser loginSysUser) {

        SysEnterpriseExtInvoice sysEnterpriseExtInvoice = AnBeanUtils.copy(param.getInvoice(), SysEnterpriseExtInvoice.class);

        sysEnterpriseExtInvoice.setCreateUserId(loginSysUser.getSysUserId());
        sysEnterpriseExtInvoice.setCreateTime(DateUtil.date());

        sysEnterpriseExtInvoiceMapper.insertSelective(sysEnterpriseExtInvoice);

        param.getPath().forEach(AnLamdaUtils.consumerWithIndex((str, index) -> {
            SysCliqueXInvoice sysCliqueXInvoiceEntity = new SysCliqueXInvoice();
            sysCliqueXInvoiceEntity.setPath(param.getPath().get(index));
            sysCliqueXInvoiceEntity.setEffect(param.getEffect().get(index));
            sysCliqueXInvoiceEntity.setSysEnterpriseExtInvoiceId(sysEnterpriseExtInvoice.getId());
            sysCliqueXInvoiceMapper.insertSelective(sysCliqueXInvoiceEntity);
        }));
    }


    public void updateSysEnterpriseExtInvoiceXCliqueParam(SysEnterpriseExtInvoiceXCliqueParam param, LoginSysUser loginSysUser) {

        SysEnterpriseExtInvoice sysEnterpriseExtInvoice = AnBeanUtils.copy(param.getInvoice(), SysEnterpriseExtInvoice.class);

        sysEnterpriseExtInvoice.setUpdateUserId(loginSysUser.getSysUserId());
        sysEnterpriseExtInvoice.setUpdateTime(DateUtil.date());

        sysEnterpriseExtInvoiceMapper.updateByPrimaryKeySelective(sysEnterpriseExtInvoice);

        SysCliqueXInvoiceExample sysCliqueXInvoiceExample = new SysCliqueXInvoiceExample();
        sysCliqueXInvoiceExample.createCriteria()
                .andSysEnterpriseExtInvoiceIdEqualTo(sysEnterpriseExtInvoice.getId());
        sysCliqueXInvoiceMapper.deleteByExample(sysCliqueXInvoiceExample);

        param.getPath().forEach(AnLamdaUtils.consumerWithIndex((str, index) -> {
            SysCliqueXInvoice sysCliqueXInvoiceEntity = new SysCliqueXInvoice();
            sysCliqueXInvoiceEntity.setPath(param.getPath().get(index));
            sysCliqueXInvoiceEntity.setEffect(param.getEffect().get(index));
            sysCliqueXInvoiceEntity.setSysEnterpriseExtInvoiceId(sysEnterpriseExtInvoice.getId());
            sysCliqueXInvoiceMapper.insertSelective(sysCliqueXInvoiceEntity);
        }));
    }


    public int addSysEnterpriseExtInvoice(SysEnterpriseExtInvoice entity, LoginSysUser loginSysUser) {

        SysEnterpriseExtInvoiceExample example = new SysEnterpriseExtInvoiceExample();
        example.createCriteria()
                .andOutVirtIdEqualTo(entity.getOutVirtId())
                .andSysVirtIdEqualTo(entity.getSysVirtId());


        List<SysEnterpriseExtInvoice> result = sysEnterpriseExtInvoiceMapper.selectByExample(example);
        if (AnCollectionUtils.isEmpty(result)) {
            entity.setIsDefault(1);
        }

        entity.setCreateTime(DateTime.now());
        entity.setCreateUserId(loginSysUser.getSysUserId());
        entity.setUpdateTime(DateTime.now());
        entity.setUpdateUserId(loginSysUser.getSysUserId());

        return sysEnterpriseExtInvoiceMapper.insertSelective(entity);
    }

    public int updateSysEnterpriseExtInvoice(SysEnterpriseExtInvoice entity, LoginSysUser loginSysUser) {

        SysEnterpriseExtInvoice originEntity = sysEnterpriseExtInvoiceMapper.selectByPrimaryKey(entity.getId());

        AssertUtils.notNull(originEntity);
        AnBeanUtils.copy(entity, originEntity);

        entity.setUpdateTime(DateTime.now());
        entity.setUpdateUserId(loginSysUser.getSysUserId());

        return sysEnterpriseExtInvoiceMapper.updateByPrimaryKey(originEntity);
    }

    @Override
    public int updateSysEnterpriseExtInvoiceByTaxpayersIDCode(SysEnterpriseExtInvoice entity) {

        if (null == entity.getTaxpayersIDCode()) {
            return 0;
        }

        SysEnterpriseExtInvoiceExample example = new SysEnterpriseExtInvoiceExample();
        example.createCriteria()
                .andTaxpayersIDCodeEqualTo(entity.getTaxpayersIDCode());

        return sysEnterpriseExtInvoiceMapper.updateByExampleSelective(entity, example);

    }

    /**
     * 关联发票信息 设置默认
     *
     * @param entity
     * @param loginSysUser
     * @return
     */
    public int opSetDefault(SysEnterpriseExtInvoice entity, LoginSysUser loginSysUser) {

        int ret1 = 0;
        int ret2 = 0;
        int ret  = 0;

        DateTime now = DateTime.now();

        SysEnterpriseExtInvoiceExample example = new SysEnterpriseExtInvoiceExample();
        example.createCriteria()
                .andOutVirtIdEqualTo(entity.getOutVirtId())
                .andSysVirtIdEqualTo(entity.getSysVirtId());
        SysEnterpriseExtInvoice forUpdate = new SysEnterpriseExtInvoice();
        forUpdate.setIsDefault(CommonIsDefaultEnum.正常.getKey());
        forUpdate.setUpdateTime(now);
        forUpdate.setUpdateUserId(loginSysUser.getSysUserId());
        ret1 = sysEnterpriseExtInvoiceMapper.updateByExampleSelective(forUpdate, example);

        entity.setIsDefault(CommonIsDefaultEnum.默认.getKey());
        entity.setUpdateTime(now);
        entity.setUpdateUserId(loginSysUser.getSysUserId());
        ret2 = sysEnterpriseExtInvoiceMapper.updateByPrimaryKeySelective(entity);

        if (ret1 > 0 && ret2 > 0) {
            ret = 1;
        }

        return ret;

    }

    public int opSetNormal(SysEnterpriseExtInvoice entity, LoginSysUser loginSysUser) {

        int ret = 0;

        DateTime now = DateTime.now();

        SysEnterpriseExtInvoice forUpdateEntity = new SysEnterpriseExtInvoice();
        forUpdateEntity.setId(entity.getId());
        forUpdateEntity.setIsDefault(CommonIsDefaultEnum.正常.getKey());
        forUpdateEntity.setUpdateTime(now);
        forUpdateEntity.setUpdateUserId(loginSysUser.getSysUserId());

        ret = sysEnterpriseExtInvoiceMapper.updateByPrimaryKeySelective(forUpdateEntity);

        return ret;
    }

    public void deleteSysEnterpriseExtInvoice(Long id, LoginSysUser loginSysUser) {

//		sysEnterpriseExtInvoiceMapper.deleteByPrimaryKey(id);

        SysEnterpriseExtInvoice processEntity = findById(id);

        if (null != processEntity) {

            SysEnterpriseExtInvoice forUpdateEntity = new SysEnterpriseExtInvoice();
            forUpdateEntity.setId(id);
            forUpdateEntity.setDeleted(CommonSoftDeleteEnum.删除.getKey());
            forUpdateEntity.setUpdateTime(DateUtil.date());
            forUpdateEntity.setUpdateUserId(loginSysUser.getSysUserId());

            sysEnterpriseExtInvoiceMapper.updateByPrimaryKeySelective(forUpdateEntity);
        }

    }


    @Override
    public SysEnterpriseExtInvoice findBySysVirtId(Long id) {

//		SysEnterpriseExtInvoice entity = sysEnterpriseExtInvoiceMapper.selectByPrimaryKey(id);
//		AssertUtil.notNull(entity);

        SysEnterpriseExtInvoice        entity  = null;
        SysEnterpriseExtInvoiceExample example = new SysEnterpriseExtInvoiceExample();
        example.createCriteria()
                .andSysVirtIdEqualTo(id);
        List<SysEnterpriseExtInvoice> result = sysEnterpriseExtInvoiceMapper.selectByExample(example);

        if (CollUtil.isNotEmpty(result)) {
            entity = result.get(0);
        }

        return entity;
    }

    @Override
    public SysEnterpriseExtInvoice getByCompanyName(String companyName) {

        SysEnterpriseExtInvoice        entity  = null;
        SysEnterpriseExtInvoiceExample example = new SysEnterpriseExtInvoiceExample();
        example.createCriteria()
                .andCompanyNameEqualTo(companyName);
        List<SysEnterpriseExtInvoice> result = sysEnterpriseExtInvoiceMapper.selectByExample(example);

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

        return entity;
    }

    @Override
    public SysEnterpriseExtInvoice getByTaxpayersIDCode(String taxpayersIDCode) {

        SysEnterpriseExtInvoice        entity  = null;
        SysEnterpriseExtInvoiceExample example = new SysEnterpriseExtInvoiceExample();
        example.createCriteria()
                .andTaxpayersIDCodeEqualTo(taxpayersIDCode);
        List<SysEnterpriseExtInvoice> result = sysEnterpriseExtInvoiceMapper.selectByExample(example);

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

        return entity;

    }

    /**
     * @param outVirtIds
     * @return
     */
    @Override
    public List<SysEnterpriseExtInvoice> findByOutVirtIds(List<Long> outVirtIds) {

        SysEnterpriseExtInvoiceExample example = new SysEnterpriseExtInvoiceExample();
        example.createCriteria()
                .andOutVirtIdIn(outVirtIds);

        List<SysEnterpriseExtInvoice> result = sysEnterpriseExtInvoiceMapper.selectByExample(example);

        return result;
    }

    @Override
    public Map<Long, SysEnterpriseExtInvoice> findByOutVirtIdsConvertKV(List<Long> outVirtIds) {

        Map<Long, SysEnterpriseExtInvoice> result = new HashMap<>();

        if (AnCollectionUtils.isNotEmpty(outVirtIds)) {

            List<SysEnterpriseExtInvoice> sysEnterpriseExtInvoiceList = findByOutVirtIds(outVirtIds);

            if (AnCollectionUtils.isNotEmpty(sysEnterpriseExtInvoiceList)) {
//				result.put(sysEnterpriseExtInvoice.getOutVirtId(), sysEnterpriseExtInvoice);
                result = sysEnterpriseExtInvoiceList.stream().collect(Collectors.toMap(SysEnterpriseExtInvoice::getOutVirtId, v -> v, (k, v) -> v));
            }
        }

        return result;


    }

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

        // 样例 保留
//		SysEnterpriseExtInvoice sysEnterpriseExtInvoiceConditions = BeanUtils.mapToBean(conditions,SysEnterpriseExtInvoice.class);

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

        if (ObjectUtil.isNotNull(conditions.get("outVirtId"))) {
            Long virtId = AnLongUtils.getLong(conditions.get("outVirtId"));
            criteria.andOutVirtIdEqualTo(virtId);
        }

        // 是否删除
        if (ObjectUtil.isNotNull(conditions.get("deleted"))) {
            Integer deleted = AnIntegerUtils.getInteger(conditions.get("deleted"));
            criteria.andDeletedEqualTo(deleted);
        } else {
            criteria.andDeletedEqualTo(CommonSoftDeleteEnum.正常.getKey());
        }

        // 是否启用:1-启用;0-禁用;
        if (ObjectUtil.isNotNull(conditions.get("enabled"))) {
            Integer enabled = AnIntegerUtils.getInteger(conditions.get("enabled"));
            criteria.andEnabledEqualTo(enabled);
        } else {
            criteria.andEnabledEqualTo(CommonEnabledEnum.启用.getKey());
        }


        example.setOrderByClause("is_default DESC , update_time DESC");

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

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

    }

    public R<List<SysEnterpriseExtInvoiceExtPathVo>> pageQuery(SysEnterpriseExtInvoiceQueryCriteria queryCriteria, LoginSysUser loginSysUser) {

        PageHelper.startPage(queryCriteria.getPageNumber(), queryCriteria.getPageSize());
        List<SysEnterpriseExtInvoiceExtPathVo>     resultList = query(queryCriteria, loginSysUser);
        PageInfo<SysEnterpriseExtInvoiceExtPathVo> page       = new PageInfo<SysEnterpriseExtInvoiceExtPathVo>(resultList);
        PageHelper.clearPage();

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

    public List<SysEnterpriseExtInvoiceExtPathVo> query(SysEnterpriseExtInvoiceQueryCriteria queryCriteria, LoginSysUser loginSysUser) {

        List<SysEnterpriseExtInvoiceExtPathVo> resultList = sysEnterpriseExtInvoiceMapperEx.findAll(queryCriteria);

        additionalInfoPageQuerySysCliqueXInvoice(resultList);

        return resultList;
    }

    /**
     * @param conditions
     * @param pageNun
     * @param pageSize
     * @return
     */
    public R<List<SysEnterpriseExtInvoiceExtPathVo>> pageQuerySysCliqueXInvoice(SysCliqueXInvoiceCriteria conditions, int pageNun, int pageSize) {

        log.info("\nSysEnterpriseExtInvoiceServiceImpl.pageQuerySysCliqueXInvoice\n -> \n{}\n", JSONUtil.toJsonStr(conditions));

        List<SysEnterpriseExtInvoiceExtPathVo> resultList = new ArrayList<>();

        // 非搜索框
        if (null != conditions && StringUtils.isNotBlank(conditions.getPath())) {

            PageHelper.startPage(pageNun, pageSize);

            log.info("sysEnterpriseExtInvoiceMapperEx.pageQuerySysCliqueXInvoice -> {}", JSONUtil.toJsonStr(conditions));
            resultList = sysEnterpriseExtInvoiceMapperEx.pageQuerySysCliqueXInvoice(conditions);

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

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

        }
        // 搜索框
        else {


            PageHelper.startPage(pageNun, pageSize);

//			SysEnterpriseExtInvoiceExample          example  = new SysEnterpriseExtInvoiceExample();
//			SysEnterpriseExtInvoiceExample.Criteria criteria = example.createCriteria();
//
//			if (StringUtils.isNotBlank(conditions.getCompanyName())) {
//				criteria.andCompanyNameLike("%" + conditions.getCompanyName() + "%" );
//			}
//
//			if (StringUtils.isNotBlank(conditions.getTaxpayersIDCode())) {
//				criteria.andTaxpayersIDCodeLike("%" + conditions.getTaxpayersIDCode() + "%" );
//			}
//
//			if (null != conditions.getDeleted()) {
//				criteria.andDeletedEqualTo(conditions.getDeleted());
//			}
//
//			if (null != conditions.getEnabled()) {
//				criteria.andEnabledEqualTo(conditions.getEnabled());
//			}
//
//			List<SysEnterpriseExtInvoice> resultListSource = sysEnterpriseExtInvoiceMapper.selectByExample(example);
//
//			PageInfo<SysEnterpriseExtInvoice> page = new PageInfo<SysEnterpriseExtInvoice>(resultListSource);
//			PageHelper.clearPage();
//
//			resultList = AnBeanUtils.copy(resultListSource, SysEnterpriseExtInvoiceExtPathVo.class);

            log.info("sysEnterpriseExtInvoiceMapperEx.pageQueryInvoiceXSysClique -> {}", JSONUtil.toJsonStr(conditions));
            resultList = sysEnterpriseExtInvoiceMapperEx.pageQueryInvoiceXSysClique(conditions);
            PageInfo<SysEnterpriseExtInvoiceExtPathVo> page = new PageInfo<SysEnterpriseExtInvoiceExtPathVo>(resultList);
            PageHelper.clearPage();

            additionalInfoPageQuerySysCliqueXInvoice(resultList);

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


    }

    public void additionalInfoPageQuerySysCliqueXInvoice(List<SysEnterpriseExtInvoiceExtPathVo> resultList) {

        /****************************************** 补充信息 start ******************************************/

        List<Long> sysUserIds = new ArrayList<>();

        List<Long> createUserIds = resultList.stream().filter(o -> o.getCreateUserId() != null).filter(AnLamdaUtils.distinctByKey(o -> o.getCreateUserId())).map(o -> o.getCreateUserId()).collect(Collectors.toList());
        List<Long> updateUserIds = resultList.stream().filter(o -> o.getUpdateUserId() != null).filter(AnLamdaUtils.distinctByKey(o -> o.getUpdateUserId())).map(o -> o.getUpdateUserId()).collect(Collectors.toList());

        sysUserIds.addAll(createUserIds);
        sysUserIds.addAll(updateUserIds);

        sysUserIds = sysUserIds.stream().distinct().collect(Collectors.toList());

        log.info("\n{}", JSONUtil.toJsonStr(sysUserIds));

        Map<Long, SysUser> sysUserMap = sysUserService.convertSysUserIds2MapSysUserId2Entity(sysUserIds);

        log.info("\n{}", JSONUtil.toJsonStr(sysUserMap));

        resultList.forEach(vo -> {

            if (sysUserMap.get(vo.getCreateUserId()) != null) {
                vo.setCreateUserName(sysUserMap.get(vo.getCreateUserId()).getFullname());
            } else if (null == vo.getCreateUserId() || vo.getCreateUserId().equals(1L)) {
                vo.setCreateUserName("系统");
            }

            if (sysUserMap.get(vo.getUpdateUserId()) != null) {
                vo.setUpdateUserName(sysUserMap.get(vo.getUpdateUserId()).getFullname());
            } else if (null == vo.getUpdateUserId() || vo.getUpdateUserId().equals(1L)) {
                vo.setUpdateUserName("系统");
            }

            vo.setDeletedName(CommonSoftDeleteEnum.get(vo.getDeleted()).getDesc());
            vo.setEnabledName(CommonEnabledEnum.get(vo.getEnabled()).getDesc());

        });

    }

    /******************************************  start ******************************************/

//	void saveOrUpdate4TaxationAisinoTxtRowParamListByPurchaserTaxpayersIDCode(TaxationAisinoTxtRowParam taxationAisinoTxtRowParamList, LoginSysUser loginSysUser) {
//
//	}
//
//	void saveOrUpdate4TaxationAisinoTxtRowParamListByPurchaserTaxpayersIDCode(List<TaxationAisinoTxtRowParam> taxationAisinoTxtRowParamList, LoginSysUser loginSysUser) {
//
//	}


    /****************************************** 工具方法 start ******************************************/

    public Map<String, SysEnterpriseExtInvoiceExtPathVo> convertToMapStringVo(SysCliqueXInvoiceCriteria conditions) {

        Map<String, SysEnterpriseExtInvoiceExtPathVo> result = new HashMap<>();

        List<SysEnterpriseExtInvoiceExtPathVo> resultList = sysEnterpriseExtInvoiceMapperEx.pageQueryInvoiceXSysClique(conditions);

        if (AnCollectionUtils.isNotEmpty(resultList)) {

            result = resultList.stream().collect(Collectors.toMap(SysEnterpriseExtInvoiceExtPathVo::getCompanyName, v -> v, (k, v) -> v));
        }


        return result;

    }


    public Map<String, String> convertToMapStringString(SysCliqueXInvoiceCriteria conditions) {

        Map<String, String> result = new HashMap<>();

        Map<String, SysEnterpriseExtInvoiceExtPathVo> tmp = convertToMapStringVo(conditions);

        tmp.forEach((companyName, entity) -> {
            result.put(companyName, JSONUtil.toJsonStr(entity));
//			result.put(URLUtil.encode((companyName)), JsonUtils.toJson(entity));

        });

        return result;

    }


    /****************************************** 工具方法   end ******************************************/

    /****************************************** 缓存 start ******************************************/

    public void cacheInit() {

        SysCliqueXInvoiceCriteria conditions = new SysCliqueXInvoiceCriteria();

        Map<String, String> mapValue = convertToMapStringString(conditions);

        // 验证
        redisService.hashSave(mapValue, RedisKeyPrefix.关联性校验_前缀, RedisKeyPrefix.关联性校验_购方主体_发票抬头.getKey(), BaseRedisConf.REFRESH_TOKEN_EXPIRE_TIME);

        // 测试过 结果与上边一个样
//		mapValue.forEach((companyName, entityJsonString) -> {
//			cacheService.hashSet(RedisKeyPrefix.关联性校验_前缀.getKey() + ":" + RedisKeyPrefix.关联性校验_发票抬头.getKey(), companyName, entityJsonString);
//		});
    }

    public void cacheRefresh() {

        redisService.deleteKey(RedisKeyPrefix.关联性校验_前缀, RedisKeyPrefix.关联性校验_购方主体_发票抬头.getKey());
        cacheInit();
    }

    public void cacheRemove() {

        redisService.deleteKey(RedisKeyPrefix.关联性校验_前缀, RedisKeyPrefix.关联性校验_购方主体_发票抬头.getKey());
    }

    public String cacheGet(String hashTable, String keyField) {
//		return (String) cacheService.hashGetByKey(hashTable, URLUtil.encode(keyField));

        log.info("hashTable@{}@field@{}@cacheService@{}", hashTable, keyField, redisService);

//		hashTable@relation:sys_enterprise_ext_invoice:company_name@field@中航物业管理有限公司成都分公司@cacheService@cn.superdesk.uniorder.common.cache.impl.RedisServiceImpl@4435b6b
//		hashTable@relation:sys_enterprise_ext_invoice:company_name@field@中航物业管理有限公司济南分公司@cacheService@cn.superdesk.uniorder.common.cache.impl.RedisServiceImpl@643f6179
        return (String) redisService.hashGetByKey(hashTable, keyField);
    }

    /****************************************** 缓存   end ******************************************/

}
