【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; 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.config.api.constants.ConfigConstants;
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum; import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException; 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 class ConfigException extends ServiceException {
public ConfigException(String errorCode, String userTip) { public ConfigException(AbstractExceptionEnum exception, Object... params) {
super(ConfigConstants.CONFIG_MODULE_NAME, errorCode, userTip); super(ConfigConstants.CONFIG_MODULE_NAME, exception.getErrorCode(), StrUtil.format(exception.getUserTip(), params));
} }
public ConfigException(AbstractExceptionEnum exception) { public ConfigException(AbstractExceptionEnum exception) {
super(ConfigConstants.CONFIG_MODULE_NAME, 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获取常量 // 1.根据id获取常量
SysConfig sysConfig = this.querySysConfig(sysConfigParam); SysConfig sysConfig = this.querySysConfig(sysConfigParam);
if (sysConfig == null) { if (sysConfig == null) {
String userTip = StrUtil.format(ConfigExceptionEnum.CONFIG_NOT_EXIST.getUserTip(), "id: " + sysConfigParam.getConfigId()); throw new ConfigException(ConfigExceptionEnum.CONFIG_NOT_EXIST, "id: " + sysConfigParam.getConfigId());
throw new ConfigException(ConfigExceptionEnum.CONFIG_NOT_EXIST, userTip);
} }
// 2.不能删除系统参数 // 2.不能删除系统参数
@ -102,10 +101,8 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
throw new ConfigException(ConfigExceptionEnum.CONFIG_SYS_CAN_NOT_DELETE); throw new ConfigException(ConfigExceptionEnum.CONFIG_SYS_CAN_NOT_DELETE);
} }
// 3.设置状态为已删除 // 3.逻辑删除
sysConfig.setStatusFlag(StatusEnum.DISABLE.getCode()); this.removeById(sysConfig.getConfigId());
sysConfig.setDelFlag(YesOrNotEnum.Y.getCode());
this.updateById(sysConfig);
// 4.删除对应context // 4.删除对应context
ConfigContext.me().deleteConfig(sysConfigParam.getConfigCode()); ConfigContext.me().deleteConfig(sysConfigParam.getConfigCode());
@ -280,8 +277,7 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
public SysConfig querySysConfig(SysConfigParam sysConfigParam) { public SysConfig querySysConfig(SysConfigParam sysConfigParam) {
SysConfig sysConfig = this.getById(sysConfigParam.getConfigId()); SysConfig sysConfig = this.getById(sysConfigParam.getConfigId());
if (ObjectUtil.isEmpty(sysConfig) || sysConfig.getDelFlag().equals(YesOrNotEnum.Y.getCode())) { 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, "id: " + sysConfigParam.getConfigId());
throw new ConfigException(ConfigExceptionEnum.CONFIG_NOT_EXIST, userTip);
} }
return sysConfig; return sysConfig;
} }

View File

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

View File

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