Skip to content

Commit

Permalink
CrudBizModel.afterEntityChange增加action参数
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Oct 27, 2024
1 parent 4cc6ec1 commit b8247bd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package io.nop.auth.service.entity;

import io.nop.api.core.annotations.biz.BizAction;
import io.nop.api.core.annotations.biz.BizModel;
import io.nop.api.core.annotations.biz.BizQuery;
import io.nop.api.core.annotations.core.Name;
Expand All @@ -33,9 +34,10 @@ public NopAuthResourceBizModel() {
setEntityName(NopAuthResource.class.getName());
}

@BizAction
@Override
protected void afterEntityChange(NopAuthResource entity, IServiceContext context) {
super.afterEntityChange(entity, context);
protected void afterEntityChange(NopAuthResource entity, IServiceContext context, String action) {
super.afterEntityChange(entity, context, action);
// 顶层菜单不应该具有parent
if (entity.isTopMenu()) {
entity.setParentId(null);
Expand Down
12 changes: 9 additions & 3 deletions nop-biz/src/main/java/io/nop/biz/crud/CrudBizModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -698,10 +698,16 @@ protected void doSaveEntity(@Name("entityData") EntityData<T> entityData, IServi
} else {
dao().saveEntity(entityData.getEntity());
}
afterEntityChange(entityData.getEntity(), context);
afterEntityChange(entityData.getEntity(), context, BizConstants.METHOD_SAVE);
}

@BizAction
protected void afterEntityChange(@Name("entity") T entity, IServiceContext context, String action) {
afterEntityChange(entity, context);
}

// 使用afterEntityChage(entity, context, action)方法来代替
@Deprecated
protected void afterEntityChange(@Name("entity") T entity, IServiceContext context) {

}
Expand Down Expand Up @@ -833,7 +839,7 @@ protected void defaultPrepareUpdate(@Name("entityData") EntityData<T> entityData
@BizAction
protected void doUpdateEntity(@Name("entityData") EntityData<T> entityData, IServiceContext context) {
dao().updateEntity(entityData.getEntity());
afterEntityChange(entityData.getEntity(), context);
afterEntityChange(entityData.getEntity(), context, BizConstants.METHOD_UPDATE);
}

@Description("@i18n:biz.get|根据id获取单条数据")
Expand Down Expand Up @@ -1729,7 +1735,7 @@ protected void invokeDefaultPrepareSave(@Name("entityData") EntityData<T> entity
getThisObj().invoke("defaultPrepareSave", Map.of("entityData", entityData), null, context);
}

protected void invokeDefaultPrepareCopyForNew(@Name("entityData") EntityData<T> entityData, IServiceContext context){
protected void invokeDefaultPrepareCopyForNew(@Name("entityData") EntityData<T> entityData, IServiceContext context) {
// 通过这种方式调用,允许在xbiz文件中覆盖Java中的方法
getThisObj().invoke("defaultPrepareCopyForNew", Map.of("entityData", entityData), null, context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package io.nop.dyn.service.entity;

import io.nop.api.core.annotations.biz.BizAction;
import io.nop.api.core.annotations.biz.BizModel;
import io.nop.biz.crud.CrudBizModel;
import io.nop.core.context.IServiceContext;
Expand All @@ -24,9 +25,10 @@ public NopDynFunctionMetaBizModel() {
setEntityName(NopDynFunctionMeta.class.getName());
}

@BizAction
@Override
protected void afterEntityChange(NopDynFunctionMeta entity, IServiceContext context) {
super.afterEntityChange(entity, context);
protected void afterEntityChange(NopDynFunctionMeta entity, IServiceContext context, String action) {
super.afterEntityChange(entity, context, action);

codeGen.generateBizModel(entity.getEntityMeta());
}
Expand Down

0 comments on commit b8247bd

Please sign in to comment.