package com.hzs.system.config.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzs.common.core.constant.CacheConstants;
import com.hzs.common.core.service.RedisService;
import com.hzs.common.domain.system.config.BdTransferSpecial;
import com.hzs.common.domain.system.config.BdTransferSpecial;
import com.hzs.system.config.mapper.BdTransferSpecialMapper;
import com.hzs.system.config.service.IBdTransferSpecialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 转账特殊设置表 服务实现类
 * </p>
 *
 * @author zhangjing
 * @since 2022-09-07
 */
@Service
public class BdTransferSpecialServiceImpl extends ServiceImpl<BdTransferSpecialMapper, BdTransferSpecial> implements IBdTransferSpecialService {


    private RedisService redisService;

    @Autowired
    public void setRedisService(RedisService redisService) {
        this.redisService = redisService;
    }


    /**
     * @description: 根据国家查询转账特殊配置列表
     * @author: zhang jing
     * @date: 2022/9/28 10:46
     * @param: [pkCountry]
     * @return: java.util.List<com.hzs.common.domain.system.config.BdTransferSpecial>
     **/
    @Override
    public List<BdTransferSpecial> queryTransferSpecial(Integer pkCountry) {
        List<BdTransferSpecial> transferSpecial = redisService.getCacheObject(CacheConstants.BD_TRANSFER_SPECIAL + pkCountry);
        if(CollectionUtil.isEmpty(transferSpecial)){
            QueryWrapper<BdTransferSpecial> queryWrapper = new QueryWrapper();
            queryWrapper.eq("PK_COUNTRY",pkCountry);
            transferSpecial = baseMapper.selectList(queryWrapper);
            if(CollectionUtil.isNotEmpty(transferSpecial)){
                redisService.setCacheObject(CacheConstants.BD_TRANSFER_SPECIAL + pkCountry, transferSpecial);
            }
        }
        return transferSpecial;
    }

    /**
     * @description: 根据会员查询转账特殊配置
     * @author: zhang jing
     * @date: 2022/9/28 10:46
     * @param: [pkCountry, memberCode]
     * @return: com.hzs.common.domain.system.config.BdTransferSpecial
     **/
    @Override
    public BdTransferSpecial getTransferSpecial(Long pkMember) {
        BdTransferSpecial transferSpecial = redisService.getCacheObject(CacheConstants.BD_TRANSFER_SPECIAL_MEMBER_CODE + pkMember);
        if(null == transferSpecial){
            QueryWrapper<BdTransferSpecial> queryWrapper = new QueryWrapper();
            queryWrapper.eq("PK_MEMBER",pkMember);
            transferSpecial = baseMapper.selectOne(queryWrapper);
            if(null != transferSpecial){
                redisService.setCacheObject(CacheConstants.BD_TRANSFER_SPECIAL_MEMBER_CODE + pkMember, transferSpecial);
            }
        }
        return transferSpecial;
    }

}
