mirror of https://gitee.com/stylefeng/roses
【7.6.0】【config】简化:初始化配置参数接口
parent
0a2f77729a
commit
0a988d6133
|
@ -52,6 +52,7 @@ import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
||||||
import cn.stylefeng.roses.kernel.rule.enums.StatusEnum;
|
import cn.stylefeng.roses.kernel.rule.enums.StatusEnum;
|
||||||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
@ -150,6 +151,11 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
|
||||||
@Override
|
@Override
|
||||||
public PageResult<SysConfig> findPage(SysConfigParam sysConfigParam) {
|
public PageResult<SysConfig> findPage(SysConfigParam sysConfigParam) {
|
||||||
LambdaQueryWrapper<SysConfig> wrapper = this.createWrapper(sysConfigParam);
|
LambdaQueryWrapper<SysConfig> wrapper = this.createWrapper(sysConfigParam);
|
||||||
|
|
||||||
|
// 只查询列表显示的数据
|
||||||
|
wrapper.select(SysConfig::getConfigId, SysConfig::getConfigName, SysConfig::getConfigCode, SysConfig::getConfigValue,
|
||||||
|
SysConfig::getSysFlag);
|
||||||
|
|
||||||
Page<SysConfig> page = this.page(PageFactory.defaultPage(), wrapper);
|
Page<SysConfig> page = this.page(PageFactory.defaultPage(), wrapper);
|
||||||
return PageResultFactory.createPageResult(page);
|
return PageResultFactory.createPageResult(page);
|
||||||
}
|
}
|
||||||
|
@ -163,11 +169,8 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果当前已经初始化过配置,则不能初始化
|
// 如果当前已经初始化过配置,则不能初始化
|
||||||
LambdaQueryWrapper<SysConfig> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
Boolean alreadyInit = this.getInitConfigFlag();
|
||||||
lambdaQueryWrapper.eq(SysConfig::getConfigCode, RuleConstants.SYSTEM_CONFIG_INIT_FLAG_NAME);
|
if (alreadyInit) {
|
||||||
SysConfig tempSysConfig = this.getOne(lambdaQueryWrapper, false);
|
|
||||||
String alreadyInit = tempSysConfig.getConfigValue();
|
|
||||||
if (Convert.toBool(alreadyInit)) {
|
|
||||||
throw new ConfigException(ConfigExceptionEnum.CONFIG_INIT_ALREADY);
|
throw new ConfigException(ConfigExceptionEnum.CONFIG_INIT_ALREADY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,15 +193,11 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
|
||||||
String configCode = entry.getKey();
|
String configCode = entry.getKey();
|
||||||
String configValue = entry.getValue();
|
String configValue = entry.getValue();
|
||||||
|
|
||||||
// 获取库数据库这条记录
|
// 更新数据库的这条配置记录
|
||||||
LambdaQueryWrapper<SysConfig> wrapper = new LambdaQueryWrapper<>();
|
LambdaUpdateWrapper<SysConfig> sysConfigLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||||
wrapper.eq(SysConfig::getConfigCode, configCode);
|
sysConfigLambdaUpdateWrapper.eq(SysConfig::getConfigCode, configCode);
|
||||||
SysConfig sysConfig = this.getOne(wrapper, false);
|
sysConfigLambdaUpdateWrapper.set(SysConfig::getConfigValue, configValue);
|
||||||
if (sysConfig == null) {
|
this.update(sysConfigLambdaUpdateWrapper);
|
||||||
continue;
|
|
||||||
}
|
|
||||||
sysConfig.setConfigValue(configValue);
|
|
||||||
this.updateById(sysConfig);
|
|
||||||
|
|
||||||
// 更新缓存
|
// 更新缓存
|
||||||
ConfigContext.me().putConfig(configCode, configValue);
|
ConfigContext.me().putConfig(configCode, configValue);
|
||||||
|
@ -216,6 +215,7 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
|
||||||
public Boolean getInitConfigFlag() {
|
public Boolean getInitConfigFlag() {
|
||||||
LambdaQueryWrapper<SysConfig> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<SysConfig> wrapper = new LambdaQueryWrapper<>();
|
||||||
wrapper.eq(SysConfig::getConfigCode, RuleConstants.SYSTEM_CONFIG_INIT_FLAG_NAME);
|
wrapper.eq(SysConfig::getConfigCode, RuleConstants.SYSTEM_CONFIG_INIT_FLAG_NAME);
|
||||||
|
wrapper.select(SysConfig::getConfigValue);
|
||||||
SysConfig sysConfig = this.getOne(wrapper, false);
|
SysConfig sysConfig = this.getOne(wrapper, false);
|
||||||
|
|
||||||
// 配置为空,还没初始化
|
// 配置为空,还没初始化
|
||||||
|
|
Loading…
Reference in New Issue