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

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.BdWithdrawalSpecial;
import com.hzs.system.config.mapper.BdWithdrawalSpecialMapper;
import com.hzs.system.config.service.IBdWithdrawalSpecialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 提现设置特殊配置 服务实现类
 * </p>
 *
 * @author zhangjing
 * @since 2022-09-06
 */
@Service
public class BdWithdrawalSpecialServiceImpl extends ServiceImpl<BdWithdrawalSpecialMapper, BdWithdrawalSpecial> implements IBdWithdrawalSpecialService {


    private RedisService redisService;

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


    /**
     * @description: 根据国家查询提现设置特殊配置
     * @author: zhang jing
     * @date: 2022/9/27 16:23
     * @param: [pkCountry]
     * @return: java.util.List<com.hzs.common.domain.system.config.BdWithdrawalSpecial>
     **/
    @Override
    public List<BdWithdrawalSpecial> queryWithdrawalSpecial(Integer pkCountry) {
        List<BdWithdrawalSpecial> withdrawalSpecial = redisService.getCacheObject(CacheConstants.BD_WITHDRAWAL_SPECIAL + pkCountry);
        if(null == withdrawalSpecial){
            QueryWrapper<BdWithdrawalSpecial> queryWrapper = new QueryWrapper();
            queryWrapper.eq("PK_COUNTRY",pkCountry);
            withdrawalSpecial = baseMapper.selectList(queryWrapper);
            if(null != withdrawalSpecial){
                redisService.setCacheObject(CacheConstants.BD_WITHDRAWAL_SPECIAL + pkCountry, withdrawalSpecial);
            }
        }
        return withdrawalSpecial;
    }

    /**
     * @description: 根据会员编号查询提现特殊配置
     * @author: zhang jing
     * @date: 2022/9/27 16:34
     * @param: [pkCountry, memberCode]
     * @return: com.hzs.common.domain.system.config.BdWithdrawalSpecial
     **/
    @Override
    public BdWithdrawalSpecial getWithdrawalSpecial(Integer pkCountry, String memberCode) {
        BdWithdrawalSpecial withdrawalSpecial = redisService.getCacheObject(CacheConstants.BD_WITHDRAWAL_SPECIAL_MEMBER_CODE + memberCode);
        if(null == withdrawalSpecial){
            QueryWrapper<BdWithdrawalSpecial> queryWrapper = new QueryWrapper();
            queryWrapper.eq("PK_COUNTRY",pkCountry);
            queryWrapper.eq("MEMBER_CODE",memberCode);
            withdrawalSpecial = baseMapper.selectOne(queryWrapper);
            if(null != withdrawalSpecial){
                redisService.setCacheObject(CacheConstants.BD_WITHDRAWAL_SPECIAL_MEMBER_CODE + memberCode, withdrawalSpecial);
            }
        }
        return withdrawalSpecial;
    }

}
