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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
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;

/**
 * 转账设置主表
 * 服务实现类
 */
@Service
public class BdTransferServiceImpl extends ServiceImpl<BdTransferMapper, BdTransfer> implements IBdTransferService {

    @Autowired
    private RedisService redisService;

    @Override
    public BdTransfer queryTransfer(Integer pkCountry) {
        BdTransfer transfer = redisService.getCacheObject(CacheConstants.BD_TRANSFER + pkCountry);
        if (null == transfer) {
            LambdaQueryWrapper<BdTransfer> queryWrapper = new LambdaQueryWrapper<>();
            queryWrapper.eq(BdTransfer::getPkCountry, pkCountry);
            queryWrapper.eq(BdTransfer::getDelFlag, EDelFlag.UN_DELETE.getValue());
            queryWrapper.le(BdTransfer::getEffectiveDate, new Date());
            transfer = baseMapper.selectOne(queryWrapper);
            if (null != transfer) {
                redisService.setCacheObject(CacheConstants.BD_TRANSFER + pkCountry, transfer);
            }
        }
        return transfer;
    }

    @Override
    public Integer checkTransfer(BdTransfer transfer) {
        return baseMapper.checkTransfer(transfer);
    }

}
