admin
2024-09-27 17caebabf7a6a529b7039c71e21e5a324e31ea20
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.taoke.autopay.service.impl;
 
import com.taoke.autopay.dao.SystemConfigMapper;
import com.taoke.autopay.dto.WXAppInfoDto;
import com.taoke.autopay.entity.SystemConfig;
import com.taoke.autopay.entity.SystemConfigKeyEnum;
import com.taoke.autopay.service.SystemConfigService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
 
/**
 * @author hxh
 * @title: SystemConfigServiceImpl
 * @description: 系统配置服务实现
 * @date 2024/6/28 17:50
 */
@Service
public class SystemConfigServiceImpl implements SystemConfigService {
 
    @Resource
    private SystemConfigMapper systemConfigMapper;
 
    @Override
    public WXAppInfoDto getWxAppInfo() {
        SystemConfig c1 = get(SystemConfigKeyEnum.WX_APP_ID);
        SystemConfig c2 = get(SystemConfigKeyEnum.WX_APP_SECRET);
        if (c1 != null && c2 != null) {
            return new WXAppInfoDto(c1.getValue(), c2.getValue());
        }
        return null;
    }
 
 
    @Cacheable(value = "configCache", key = "'getWxAppInfoCache'")
    @Override
    public WXAppInfoDto getWxAppInfoCache() {
        return getWxAppInfo();
    }
 
    @Override
    public SystemConfig get(SystemConfigKeyEnum key) {
        if (key == null) {
            return null;
        }
        SystemConfigMapper.DaoQuery daoQuery = new SystemConfigMapper.DaoQuery();
        daoQuery.count = 1;
        daoQuery.start = 0;
        daoQuery.key = key.getKey();
 
        List<SystemConfig> list = systemConfigMapper.list(daoQuery);
        if (list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
 
    @Cacheable(value = "configCache", key = "'getCache-'+#key")
    @Override
    public SystemConfig getCache(SystemConfigKeyEnum key) {
 
        return get(key);
    }
 
    @Override
    public String getValue(SystemConfigKeyEnum key) {
        SystemConfig config = get(key);
        if (config != null) {
            return config.getValue();
        }
        return null;
    }
 
    @Cacheable(value = "configCache", key = "'getValueCache-'+#key")
    @Override
    public String getValueCache(SystemConfigKeyEnum key) {
        SystemConfig config = get(key);
        if (config != null) {
            return config.getValue();
        }
        return null;
    }
 
    @CacheEvict(value = "configCache", allEntries = true)
    @Override
    public void clearCache() {
 
    }
 
    @Override
    public void setValue(SystemConfigKeyEnum key, String val) {
        SystemConfig config = get(key);
        if (config != null) {
            SystemConfig update = new SystemConfig();
            update.setId(config.getId());
            update.setValue(val);
            update.setUpdateTime(new Date());
            systemConfigMapper.updateByPrimaryKeySelective(update);
        }
    }
 
 
}