【7.6.0】【config】更新删除配置模块,调整config模块异常

pull/57/head
fengshuonan 2023-06-27 21:51:40 +08:00
parent 7f4940a299
commit c7a438df03
4 changed files with 11 additions and 26 deletions

View File

@ -24,6 +24,7 @@
*/
package cn.stylefeng.roses.kernel.config.api.exception;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.roses.kernel.config.api.constants.ConfigConstants;
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
@ -36,16 +37,12 @@ import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
*/
public class ConfigException extends ServiceException {
public ConfigException(String errorCode, String userTip) {
super(ConfigConstants.CONFIG_MODULE_NAME, errorCode, userTip);
public ConfigException(AbstractExceptionEnum exception, Object... params) {
super(ConfigConstants.CONFIG_MODULE_NAME, exception.getErrorCode(), StrUtil.format(exception.getUserTip(), params));
}
public ConfigException(AbstractExceptionEnum exception) {
super(ConfigConstants.CONFIG_MODULE_NAME, exception);
}
public ConfigException(AbstractExceptionEnum exception, String userTip) {
super(ConfigConstants.CONFIG_MODULE_NAME, exception.getErrorCode(), userTip);
}
}

View File

@ -93,8 +93,7 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
// 1.根据id获取常量
SysConfig sysConfig = this.querySysConfig(sysConfigParam);
if (sysConfig == null) {
String userTip = StrUtil.format(ConfigExceptionEnum.CONFIG_NOT_EXIST.getUserTip(), "id: " + sysConfigParam.getConfigId());
throw new ConfigException(ConfigExceptionEnum.CONFIG_NOT_EXIST, userTip);
throw new ConfigException(ConfigExceptionEnum.CONFIG_NOT_EXIST, "id: " + sysConfigParam.getConfigId());
}
// 2.不能删除系统参数
@ -102,10 +101,8 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
throw new ConfigException(ConfigExceptionEnum.CONFIG_SYS_CAN_NOT_DELETE);
}
// 3.设置状态为已删除
sysConfig.setStatusFlag(StatusEnum.DISABLE.getCode());
sysConfig.setDelFlag(YesOrNotEnum.Y.getCode());
this.updateById(sysConfig);
// 3.逻辑删除
this.removeById(sysConfig.getConfigId());
// 4.删除对应context
ConfigContext.me().deleteConfig(sysConfigParam.getConfigCode());
@ -280,8 +277,7 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
public SysConfig querySysConfig(SysConfigParam sysConfigParam) {
SysConfig sysConfig = this.getById(sysConfigParam.getConfigId());
if (ObjectUtil.isEmpty(sysConfig) || sysConfig.getDelFlag().equals(YesOrNotEnum.Y.getCode())) {
String userTip = StrUtil.format(ConfigExceptionEnum.CONFIG_NOT_EXIST.getUserTip(), "id: " + sysConfigParam.getConfigId());
throw new ConfigException(ConfigExceptionEnum.CONFIG_NOT_EXIST, userTip);
throw new ConfigException(ConfigExceptionEnum.CONFIG_NOT_EXIST, "id: " + sysConfigParam.getConfigId());
}
return sysConfig;
}

View File

@ -83,16 +83,12 @@ public class ConfigContainer implements ConfigApi {
public <T> T getConfigValue(String configCode, Class<T> clazz) throws ConfigException {
String configValue = CONFIG_CONTAINER.getStr(configCode);
if (ObjectUtil.isEmpty(configValue)) {
String format = StrUtil.format(ConfigExceptionEnum.CONFIG_NOT_EXIST.getUserTip(), configCode);
log.warn(format);
throw new ConfigException(ConfigExceptionEnum.CONFIG_NOT_EXIST.getErrorCode(), format);
throw new ConfigException(ConfigExceptionEnum.CONFIG_NOT_EXIST, configCode);
} else {
try {
return Convert.convert(clazz, configValue);
} catch (Exception e) {
String format = StrUtil.format(ConfigExceptionEnum.CONVERT_ERROR.getUserTip(), configCode, configValue, clazz.toString());
log.warn(format);
throw new ConfigException(ConfigExceptionEnum.CONVERT_ERROR.getErrorCode(), format);
throw new ConfigException(ConfigExceptionEnum.CONVERT_ERROR, configCode, configValue, clazz.toString());
}
}
}

View File

@ -156,16 +156,12 @@ public class RedisConfigContainer implements ConfigApi {
try (Jedis jedis = pool.getResource()) {
String configValue = jedis.get(CONFIG_PREFIX + configCode);
if (ObjectUtil.isEmpty(configValue)) {
String format = StrUtil.format(ConfigExceptionEnum.CONFIG_NOT_EXIST.getUserTip(), configCode);
log.warn(format);
throw new ConfigException(ConfigExceptionEnum.CONFIG_NOT_EXIST.getErrorCode(), format);
throw new ConfigException(ConfigExceptionEnum.CONFIG_NOT_EXIST, configCode);
} else {
try {
return Convert.convert(clazz, configValue);
} catch (Exception e) {
String format = StrUtil.format(ConfigExceptionEnum.CONVERT_ERROR.getUserTip(), configCode, configValue, clazz.toString());
log.warn(format);
throw new ConfigException(ConfigExceptionEnum.CONVERT_ERROR.getErrorCode(), format);
throw new ConfigException(ConfigExceptionEnum.CONVERT_ERROR, configCode, configValue, clazz.toString());
}
}
}