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();
|
}
|
}
|