admin
2025-02-25 30d8e227e8d823b6c38c3b9c90ac2df03b63befe
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
package com.yeshi.fanli.service.impl.config;
 
import com.ks.lib.common.exception.ParamsException;
import com.yeshi.fanli.dao.mybatis.SystemConfigMapper;
import com.yeshi.fanli.entity.SystemEnum;
import com.yeshi.fanli.entity.config.SystemConfigKeyEnum;
import com.yeshi.fanli.entity.system.SystemConfig;
import com.yeshi.fanli.service.inter.config.SystemConfigService;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
 
@Service
public class SystemConfigServiceImpl implements SystemConfigService {
 
    @Resource
    private SystemConfigMapper systemConfigMapper;
 
 
    @Override
    public void save(SystemConfig systemConfig) throws ParamsException {
 
        if (systemConfig == null || systemConfig.getSystem() == null || systemConfig.getKey() == null) {
            throw new ParamsException(1, "参数不完整");
        }
 
 
        SystemConfig old = getConfig(SystemConfigKeyEnum.valueOf(systemConfig.getKey()), systemConfig.getSystem());
        if (old != null) {
            SystemConfig update = new SystemConfig();
            update.setId(old.getId());
            update.setValue(systemConfig.getValue());
            update.setUpdatetime(System.currentTimeMillis());
            systemConfigMapper.updateByPrimaryKeySelective(update);
        } else {
            if (systemConfig.getUpdatetime() == null) {
                systemConfig.setUpdatetime(System.currentTimeMillis());
            }
            systemConfigMapper.insertSelective(systemConfig);
        }
    }
 
 
    @Override
    public SystemConfig getConfig(SystemConfigKeyEnum key, SystemEnum system) {
        return systemConfigMapper.selectByKeyAndSystem(key.name(), system);
    }
 
 
    @Cacheable(value = "systemConfig", key = "'getConfig-'+#key+'-'+#system")
    @Override
    public SystemConfig getConfigCache(SystemConfigKeyEnum key, SystemEnum system) {
        return getConfig(key, system);
    }
 
    @Cacheable(value = "systemConfig", key = "'getValue-'+#key+'-'+#system")
    @Override
    public String getValueCache(SystemConfigKeyEnum key, SystemEnum system) {
        SystemConfig config = getConfig(key, system);
        if (config == null) {
            return null;
        }
        return config.getValue();
    }
}