Skip to content

Commit

Permalink
增加nop.orm.sys-user-name配置支持
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Nov 14, 2024
1 parent c06be16 commit 54e7504
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions nop-orm/src/main/java/io/nop/orm/OrmConfigs.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,7 @@ public interface OrmConfigs {
IConfigReference<Integer> CFG_ORM_MODEL_CACHE_TENANT_CACHE_CONTAINER_SIZE = varRef(s_loc,
"nop.orm.orm-model-cache.tenant-cache-container-size", Integer.class, 100);

@Description("缺省的系统用户名,当上下文没有用户信息,且需要记录创建者时使用")
IConfigReference<String> CFG_ORM_SYS_USER_NAME = varRef(s_loc, "nop.orm.sys-user-name", String.class, OrmConstants.USER_NAME_SYS);

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import java.sql.Timestamp;

import static io.nop.orm.OrmConfigs.CFG_ORM_SYS_USER_NAME;

public class OrmTimestampHelper {
public static void onCreate(IEntityModel entityModel, IOrmEntity entity) {
if (entity.orm_disableAutoStamp())
Expand All @@ -29,9 +31,9 @@ public static void onCreate(IEntityModel entityModel, IOrmEntity entity) {
entity.orm_propValue(entityModel.getUpdaterPropId(), user);
} else {
if (entityModel.getCreaterPropId() > 0 && entity.orm_propValue(entityModel.getCreaterPropId()) == null)
entity.orm_propValue(entityModel.getCreaterPropId(), OrmConstants.USER_NAME_SYS);
entity.orm_propValue(entityModel.getCreaterPropId(), CFG_ORM_SYS_USER_NAME.get());
if (entityModel.getUpdaterPropId() > 0 && entity.orm_propValue(entityModel.getUpdaterPropId()) == null)
entity.orm_propValue(entityModel.getUpdaterPropId(), OrmConstants.USER_NAME_SYS);
entity.orm_propValue(entityModel.getUpdaterPropId(), CFG_ORM_SYS_USER_NAME.get());
}
}

Expand All @@ -56,7 +58,7 @@ public static void onUpdate(IEntityModel entityModel, IOrmEntity entity) {
if (entity.orm_propValue(entityModel.getCreaterPropId()) == null) {
String user = getCurrentUser();
if (user != null) {
user = OrmConstants.USER_NAME_SYS;
user = CFG_ORM_SYS_USER_NAME.get();
}
entity.orm_propValue(entityModel.getCreaterPropId(), user);
}
Expand All @@ -72,7 +74,7 @@ public static void onUpdate(IEntityModel entityModel, IOrmEntity entity) {
if (user != null) {
entity.orm_propValue(entityModel.getUpdaterPropId(), user);
} else {
entity.orm_propValue(entityModel.getUpdaterPropId(), OrmConstants.USER_NAME_SYS);
entity.orm_propValue(entityModel.getUpdaterPropId(), CFG_ORM_SYS_USER_NAME.get());
}
}

Expand Down

0 comments on commit 54e7504

Please sign in to comment.