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.enums.EDelFlag;
import com.hzs.common.core.service.RedisService;
import com.hzs.common.domain.system.config.BdTransfer;
import com.hzs.system.config.mapper.BdTransferMapper;
import com.hzs.system.config.service.IBdTransferService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 *  转账设置主表
 服务实现类
 * </p>
 *
 * @author zhangjing
 * @since 2022-09-07
 */
@Service
public class BdTransferServiceImpl extends ServiceImpl<BdTransferMapper, BdTransfer> implements IBdTransferService {


    private RedisService redisService;

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


    /**
     * @description: 根据国家查询转账配置列表
     * @author: zhang jing
     * @date: 2022/9/28 10:34
     * @param: [pkCountry]
     * @return: java.util.List<com.hzs.common.domain.system.config.BdTransfer>
     **/
    @Override
    public BdTransfer queryTransfer(Integer pkCountry) {
        BdTransfer transfer = redisService.getCacheObject(CacheConstants.BD_TRANSFER + pkCountry);
        if(null == transfer){
            QueryWrapper<BdTransfer> queryWrapper = new QueryWrapper();
            queryWrapper.eq("PK_COUNTRY",pkCountry);
            queryWrapper.eq("DEL_FLAG", EDelFlag.UN_DELETE.getValue());
            queryWrapper.le("EFFECTIVE_DATE",new Date());
            transfer = baseMapper.selectOne(queryWrapper);
            if(null != transfer){
                redisService.setCacheObject(CacheConstants.BD_TRANSFER + pkCountry, transfer);
            }
        }
        return transfer;
    }

    /**
     * @description: 查询会员是否有转账数据
     * @author: zhang jing
     * @date: 2023/3/15 19:42
     * @param: [transfer]
     * @return: java.lang.Integer
     **/
    @Override
    public Integer checkTransfer(BdTransfer transfer) {
        return baseMapper.checkTransfer(transfer);
    }
}
