【7.6.0】更新常量引用方式

pull/55/head
fengshuonan 2023-05-06 23:56:25 +08:00
parent 4cddbe8e22
commit 9a0bad60d8
3 changed files with 34 additions and 34 deletions

View File

@ -27,6 +27,7 @@ package cn.stylefeng.roses.kernel.db.mp.fieldfill;
import cn.hutool.core.util.ClassUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
import cn.stylefeng.roses.kernel.db.api.constants.DbFieldConstants;
import cn.stylefeng.roses.kernel.rule.enums.StatusEnum;
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
@ -37,7 +38,6 @@ import org.apache.ibatis.reflection.ReflectionException;
import java.lang.reflect.Field;
import java.util.Date;
import static cn.stylefeng.roses.kernel.db.api.constants.DbFieldConstants.*;
/**
* mybatis-plus create_time
@ -53,10 +53,10 @@ public class CustomMetaObjectHandler implements MetaObjectHandler {
try {
// 设置createUserBaseEntity)
setValue(metaObject, CREATE_USER, this.getUserUniqueId());
setValue(metaObject, DbFieldConstants.CREATE_USER, this.getUserUniqueId());
// 设置createTimeBaseEntity)
setValue(metaObject, CREATE_TIME, new Date());
setValue(metaObject, DbFieldConstants.CREATE_TIME, new Date());
// 设置删除标记 默认N-删除
setDelFlagDefaultValue(metaObject);
@ -65,10 +65,10 @@ public class CustomMetaObjectHandler implements MetaObjectHandler {
setStatusDefaultValue(metaObject);
// 设置乐观锁字段从0开始
setValue(metaObject, VERSION_FLAG, 0L);
setValue(metaObject, DbFieldConstants.VERSION_FLAG, 0L);
// 设置组织id
setValue(metaObject, ORG_ID, this.getUserOrgId());
setValue(metaObject, DbFieldConstants.ORG_ID, this.getUserOrgId());
} catch (ReflectionException e) {
log.warn("CustomMetaObjectHandler处理过程中无相关字段不做处理");
@ -81,10 +81,10 @@ public class CustomMetaObjectHandler implements MetaObjectHandler {
try {
// 设置updateUserBaseEntity)
setValue(metaObject, UPDATE_USER, this.getUserUniqueId());
setValue(metaObject, DbFieldConstants.UPDATE_USER, this.getUserUniqueId());
// 设置updateTimeBaseEntity)
setValue(metaObject, UPDATE_TIME, new Date());
setValue(metaObject, DbFieldConstants.UPDATE_TIME, new Date());
} catch (ReflectionException e) {
log.warn("CustomMetaObjectHandler处理过程中无相关字段不做处理");
}
@ -145,18 +145,18 @@ public class CustomMetaObjectHandler implements MetaObjectHandler {
* @since 2022/9/7 17:23
*/
private void setDelFlagDefaultValue(MetaObject metaObject) {
Object originalAttr = getFieldValByName(DEL_FLAG, metaObject);
Object originalAttr = getFieldValByName(DbFieldConstants.DEL_FLAG, metaObject);
if (ObjectUtil.isNotEmpty(originalAttr)) {
return;
}
Object originalObject = metaObject.getOriginalObject();
try {
// 获取delFlag字段的类型如果是枚举类型则设置枚举
Field declaredField = originalObject.getClass().getDeclaredField(DEL_FLAG);
Field declaredField = originalObject.getClass().getDeclaredField(DbFieldConstants.DEL_FLAG);
if (ClassUtil.isEnum(declaredField.getType())) {
setFieldValByName(DEL_FLAG, YesOrNotEnum.N, metaObject);
setFieldValByName(DbFieldConstants.DEL_FLAG, YesOrNotEnum.N, metaObject);
} else {
setFieldValByName(DEL_FLAG, YesOrNotEnum.N.getCode(), metaObject);
setFieldValByName(DbFieldConstants.DEL_FLAG, YesOrNotEnum.N.getCode(), metaObject);
}
} catch (NoSuchFieldException ignored) {
// 没有字段,忽略
@ -170,18 +170,18 @@ public class CustomMetaObjectHandler implements MetaObjectHandler {
* @since 2022/9/7 17:23
*/
private void setStatusDefaultValue(MetaObject metaObject) {
Object originalAttr = getFieldValByName(STATUS_FLAG, metaObject);
Object originalAttr = getFieldValByName(DbFieldConstants.STATUS_FLAG, metaObject);
if (ObjectUtil.isNotEmpty(originalAttr)) {
return;
}
Object originalObject = metaObject.getOriginalObject();
try {
// 获取statusFlag字段的类型如果是枚举类型则设置枚举
Field declaredField = originalObject.getClass().getDeclaredField(STATUS_FLAG);
Field declaredField = originalObject.getClass().getDeclaredField(DbFieldConstants.STATUS_FLAG);
if (ClassUtil.isEnum(declaredField.getType())) {
setFieldValByName(STATUS_FLAG, StatusEnum.ENABLE, metaObject);
setFieldValByName(DbFieldConstants.STATUS_FLAG, StatusEnum.ENABLE, metaObject);
} else {
setFieldValByName(STATUS_FLAG, StatusEnum.ENABLE.getCode(), metaObject);
setFieldValByName(DbFieldConstants.STATUS_FLAG, StatusEnum.ENABLE.getCode(), metaObject);
}
} catch (NoSuchFieldException ignored) {
// 没有字段,忽略

View File

@ -33,6 +33,7 @@ import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.druid.DruidProperties;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.dsctn.api.exception.DatasourceContainerException;
import cn.stylefeng.roses.kernel.dsctn.api.exception.enums.DatasourceContainerExceptionEnum;
import cn.stylefeng.roses.kernel.dsctn.api.pojo.DataBaseInfoDto;
import cn.stylefeng.roses.kernel.dsctn.api.pojo.DataSourceDto;
import cn.stylefeng.roses.kernel.dsctn.api.pojo.request.DatabaseInfoRequest;
@ -67,7 +68,6 @@ import java.util.stream.Collectors;
import static cn.stylefeng.roses.kernel.dsctn.api.constants.DatasourceContainerConstants.DATASOURCE_GROUP_CODE;
import static cn.stylefeng.roses.kernel.dsctn.api.constants.DatasourceContainerConstants.MASTER_DATASOURCE_NAME;
import static cn.stylefeng.roses.kernel.dsctn.api.exception.enums.DatasourceContainerExceptionEnum.*;
/**
*
@ -139,12 +139,12 @@ public class DatabaseInfoServiceImpl extends ServiceImpl<DatabaseInfoMapper, Dat
// 如果是租户数据库不能删除
if (databaseInfo.getDbName().startsWith(RuleConstants.TENANT_DB_PREFIX)) {
throw new DatasourceContainerException(TENANT_DATASOURCE_CANT_DELETE);
throw new DatasourceContainerException(DatasourceContainerExceptionEnum.TENANT_DATASOURCE_CANT_DELETE);
}
// 不能删除主数据源
if (MASTER_DATASOURCE_NAME.equals(databaseInfo.getDbName())) {
throw new DatasourceContainerException(MASTER_DATASOURCE_CANT_DELETE);
throw new DatasourceContainerException(DatasourceContainerExceptionEnum.MASTER_DATASOURCE_CANT_DELETE);
}
// 删除库中的数据源记录
@ -165,7 +165,7 @@ public class DatabaseInfoServiceImpl extends ServiceImpl<DatabaseInfoMapper, Dat
// 不能修改数据源的名称
if (!databaseInfoRequest.getDbName().equals(databaseInfo.getDbName())) {
throw new DatasourceContainerException(EDIT_DATASOURCE_NAME_ERROR, databaseInfo.getDbName());
throw new DatasourceContainerException(DatasourceContainerExceptionEnum.EDIT_DATASOURCE_NAME_ERROR, databaseInfo.getDbName());
}
// 判断数据库连接是否可用
@ -236,7 +236,7 @@ public class DatabaseInfoServiceImpl extends ServiceImpl<DatabaseInfoMapper, Dat
Class.forName(param.getJdbcDriver());
conn = DriverManager.getConnection(param.getJdbcUrl(), param.getUsername(), param.getPassword());
} catch (Exception e) {
throw new DatasourceContainerException(VALIDATE_DATASOURCE_ERROR, param.getJdbcUrl(), e.getMessage());
throw new DatasourceContainerException(DatasourceContainerExceptionEnum.VALIDATE_DATASOURCE_ERROR, param.getJdbcUrl(), e.getMessage());
} finally {
if (conn != null) {
try {
@ -275,8 +275,8 @@ public class DatabaseInfoServiceImpl extends ServiceImpl<DatabaseInfoMapper, Dat
// 先判断context中是否有了这个数据源
DataSource dataSource = DataSourceContext.getDataSources().get(databaseInfo.getDbName());
if (dataSource != null) {
String userTip = StrUtil.format(DATASOURCE_NAME_REPEAT.getUserTip(), databaseInfo.getDbName());
throw new DatasourceContainerException(DATASOURCE_NAME_REPEAT, userTip);
String userTip = StrUtil.format(DatasourceContainerExceptionEnum.DATASOURCE_NAME_REPEAT.getUserTip(), databaseInfo.getDbName());
throw new DatasourceContainerException(DatasourceContainerExceptionEnum.DATASOURCE_NAME_REPEAT, userTip);
}
}
@ -290,8 +290,8 @@ public class DatabaseInfoServiceImpl extends ServiceImpl<DatabaseInfoMapper, Dat
druidDataSource.init();
} catch (SQLException exception) {
log.error("初始化数据源异常!", exception);
String userTip = StrUtil.format(INIT_DATASOURCE_ERROR.getUserTip(), exception.getMessage());
throw new DatasourceContainerException(INIT_DATASOURCE_ERROR, userTip);
String userTip = StrUtil.format(DatasourceContainerExceptionEnum.INIT_DATASOURCE_ERROR.getUserTip(), exception.getMessage());
throw new DatasourceContainerException(DatasourceContainerExceptionEnum.INIT_DATASOURCE_ERROR, userTip);
}
}
@ -304,7 +304,7 @@ public class DatabaseInfoServiceImpl extends ServiceImpl<DatabaseInfoMapper, Dat
private DatabaseInfo queryDatabaseInfoById(DatabaseInfoRequest databaseInfoRequest) {
DatabaseInfo databaseInfo = this.getById(databaseInfoRequest.getDbId());
if (databaseInfo == null) {
throw new DatasourceContainerException(DATASOURCE_INFO_NOT_EXISTED, databaseInfoRequest.getDbId());
throw new DatasourceContainerException(DatasourceContainerExceptionEnum.DATASOURCE_INFO_NOT_EXISTED, databaseInfoRequest.getDbId());
}
return databaseInfo;
}

View File

@ -29,6 +29,7 @@ import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.StrUtil;
import cn.stylefeng.roses.kernel.db.api.pojo.druid.DruidProperties;
import cn.stylefeng.roses.kernel.dsctn.api.exception.DatasourceContainerException;
import cn.stylefeng.roses.kernel.dsctn.api.exception.enums.DatasourceContainerExceptionEnum;
import cn.stylefeng.roses.kernel.dsctn.persist.sqladapter.AddDatabaseInfoSql;
import cn.stylefeng.roses.kernel.dsctn.persist.sqladapter.DatabaseListSql;
import cn.stylefeng.roses.kernel.dsctn.persist.sqladapter.DeleteDatabaseInfoSql;
@ -41,7 +42,6 @@ import java.util.HashMap;
import java.util.Map;
import static cn.stylefeng.roses.kernel.dsctn.api.constants.DatasourceContainerConstants.MASTER_DATASOURCE_NAME;
import static cn.stylefeng.roses.kernel.dsctn.api.exception.enums.DatasourceContainerExceptionEnum.*;
/**
@ -86,8 +86,8 @@ public class DataBaseInfoPersistence {
} catch (Exception exception) {
log.error("查询数据源信息错误!", exception);
String userTip = StrUtil.format(QUERY_DBS_DAO_ERROR.getUserTip(), exception.getMessage());
throw new DatasourceContainerException(QUERY_DBS_DAO_ERROR, userTip);
String userTip = StrUtil.format(DatasourceContainerExceptionEnum.QUERY_DBS_DAO_ERROR.getUserTip(), exception.getMessage());
throw new DatasourceContainerException(DatasourceContainerExceptionEnum.QUERY_DBS_DAO_ERROR, userTip);
} finally {
IoUtil.close(conn);
}
@ -122,8 +122,8 @@ public class DataBaseInfoPersistence {
log.info("初始化master的databaseInfo信息初始化" + i + "条!");
} catch (Exception exception) {
log.error("初始化master的databaseInfo信息错误", exception);
String userTip = StrUtil.format(INSERT_DBS_DAO_ERROR.getUserTip(), exception.getMessage());
throw new DatasourceContainerException(INSERT_DBS_DAO_ERROR, userTip);
String userTip = StrUtil.format(DatasourceContainerExceptionEnum.INSERT_DBS_DAO_ERROR.getUserTip(), exception.getMessage());
throw new DatasourceContainerException(DatasourceContainerExceptionEnum.INSERT_DBS_DAO_ERROR, userTip);
} finally {
IoUtil.close(conn);
}
@ -148,8 +148,8 @@ public class DataBaseInfoPersistence {
log.info("删除master的databaseInfo信息删除" + i + "条!");
} catch (Exception exception) {
log.info("删除master的databaseInfo信息失败", exception);
String userTip = StrUtil.format(DELETE_DBS_DAO_ERROR.getUserTip(), exception.getMessage());
throw new DatasourceContainerException(DELETE_DBS_DAO_ERROR, userTip);
String userTip = StrUtil.format(DatasourceContainerExceptionEnum.DELETE_DBS_DAO_ERROR.getUserTip(), exception.getMessage());
throw new DatasourceContainerException(DatasourceContainerExceptionEnum.DELETE_DBS_DAO_ERROR, userTip);
} finally {
IoUtil.close(conn);
}
@ -175,8 +175,8 @@ public class DataBaseInfoPersistence {
druidProperties.setPassword(resultSet.getString("password"));
} catch (SQLException exception) {
log.info("根据数据库查询结果创建DruidProperties失败", exception);
String userTip = StrUtil.format(CREATE_PROP_DAO_ERROR.getUserTip(), exception.getMessage());
throw new DatasourceContainerException(CREATE_PROP_DAO_ERROR, userTip);
String userTip = StrUtil.format(DatasourceContainerExceptionEnum.CREATE_PROP_DAO_ERROR.getUserTip(), exception.getMessage());
throw new DatasourceContainerException(DatasourceContainerExceptionEnum.CREATE_PROP_DAO_ERROR, userTip);
}
return druidProperties;