yujian
2019-10-28 31e26f7d023a651c18fa3a0e69fc637a2189ba8a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.yeshi.fanli.service.impl.redpack;
 
import java.util.Date;
 
import javax.annotation.Resource;
 
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
 
import com.yeshi.fanli.dao.mybatis.redpack.RedPackConfigMapper;
import com.yeshi.fanli.entity.redpack.RedPackConfig;
import com.yeshi.fanli.service.inter.redpack.RedPackConfigService;
 
@Service
public class RedPackConfigServiceImpl implements RedPackConfigService {
 
    @Resource
    private RedPackConfigMapper redPackConfigMapper;
 
    @Override
    public RedPackConfig getByKey(String key) {
        return redPackConfigMapper.getByKey(key, new Date());
    }
 
    @Override
    @Cacheable(value = "redpackCache", key = "'getValueByKey-' + #key")
    public String getValueByKey(String key) {
        RedPackConfig config = redPackConfigMapper.getByKey(key, new Date());
        if (config != null) {
            return config.getValue();
        }
        return null;
    }
 
    @Override
    public RedPackConfig getByKey(String key, Date date) {
        if (date == null)
            return getByKey(key);
        return redPackConfigMapper.getByKey(key, date);
    }
 
    @Override
    public String getValueByKey(String key, Date date) {
        if (date == null)
            return getValueByKey(key);
        RedPackConfig config = redPackConfigMapper.getByKey(key, date);
        if (config != null) {
            return config.getValue();
        }
        return null;
    }
 
}