优化参数管理,缓存中不存在,则从数据库读取
This commit is contained in:
parent
1a97405a3c
commit
e796e8ac1c
|
@ -17,4 +17,8 @@ public interface SysParamsDao extends BaseDao<SysParamsEntity> {
|
|||
default boolean isExist(String paramKey) {
|
||||
return this.exists(new QueryWrapper<SysParamsEntity>().eq("param_key", paramKey));
|
||||
}
|
||||
|
||||
default SysParamsEntity get(String paramKey) {
|
||||
return this.selectOne(new QueryWrapper<SysParamsEntity>().eq("param_key", paramKey));
|
||||
}
|
||||
}
|
|
@ -7,9 +7,9 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.maku.framework.common.exception.ServerException;
|
||||
import net.maku.framework.common.utils.JsonUtils;
|
||||
import net.maku.framework.common.utils.PageResult;
|
||||
import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
|
||||
import net.maku.framework.common.utils.JsonUtils;
|
||||
import net.maku.system.cache.SysParamsCache;
|
||||
import net.maku.system.convert.SysParamsConvert;
|
||||
import net.maku.system.dao.SysParamsDao;
|
||||
|
@ -116,11 +116,20 @@ public class SysParamsServiceImpl extends BaseServiceImpl<SysParamsDao, SysParam
|
|||
@Override
|
||||
public String getString(String paramKey) {
|
||||
String value = sysParamsCache.get(paramKey);
|
||||
if (StrUtil.isBlank(value)) {
|
||||
throw new ServerException("参数不能为空,paramKey:" + paramKey);
|
||||
if (StrUtil.isNotBlank(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return value;
|
||||
// 如果缓存没有,则查询数据库
|
||||
SysParamsEntity entity = baseMapper.get(paramKey);
|
||||
if (entity == null) {
|
||||
throw new ServerException("参数值不存在,paramKey:" + paramKey);
|
||||
}
|
||||
|
||||
// 保存到缓存
|
||||
sysParamsCache.save(entity.getParamKey(), entity.getParamValue());
|
||||
|
||||
return entity.getParamValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue
Block a user