admin
2025-02-11 8cc47cfe4c6d6b48e62cf00f6cbd0951ec57c264
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
package com.everyday.word.service.impl.config;
 
import com.everyday.word.dao.config.SystemConfigMapper;
import com.everyday.word.entity.SystemEnum;
import com.everyday.word.entity.config.SystemConfig;
import com.everyday.word.entity.config.SystemConfigKeyEnum;
import com.everyday.word.exception.ParamsException;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import com.everyday.word.service.inter.config.*;
 
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
 
/**
 * @author hxh
 * @title: SystemConfigServiceImpl
 * @description: TODO
 * @date 2025/2/11 15:45
 */
@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(new Date());
            systemConfigMapper.updateByPrimaryKeySelective(update);
        } else {
            if (systemConfig.getUpdateTime() == null) {
                systemConfig.setUpdateTime(new Date());
            }
            systemConfigMapper.insertSelective(systemConfig);
        }
    }
 
 
    @Override
    public SystemConfig getConfig(SystemConfigKeyEnum key, SystemEnum system) {
        SystemConfigMapper.DaoQuery daoQuery =  SystemConfigMapper.DaoQuery.builder()
                .key(key.name())
                .system(system)
                .count(1)
                .build();
        List<SystemConfig> mList = systemConfigMapper.list(daoQuery);
        if(mList!=null&&mList.size()>0){
            return mList.get(0);
        }
        return null;
    }
 
 
    @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();
    }
}