From b8247bd8da2afa5be97f83e5a8fb05affb9c9f3a Mon Sep 17 00:00:00 2001 From: canonical Date: Sun, 27 Oct 2024 23:03:53 +0800 Subject: [PATCH] =?UTF-8?q?CrudBizModel.afterEntityChange=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0action=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/service/entity/NopAuthResourceBizModel.java | 6 ++++-- .../src/main/java/io/nop/biz/crud/CrudBizModel.java | 12 +++++++++--- .../service/entity/NopDynFunctionMetaBizModel.java | 6 ++++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/nop-auth/nop-auth-service/src/main/java/io/nop/auth/service/entity/NopAuthResourceBizModel.java b/nop-auth/nop-auth-service/src/main/java/io/nop/auth/service/entity/NopAuthResourceBizModel.java index 8428fd62d..8182e5d9e 100644 --- a/nop-auth/nop-auth-service/src/main/java/io/nop/auth/service/entity/NopAuthResourceBizModel.java +++ b/nop-auth/nop-auth-service/src/main/java/io/nop/auth/service/entity/NopAuthResourceBizModel.java @@ -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; @@ -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); diff --git a/nop-biz/src/main/java/io/nop/biz/crud/CrudBizModel.java b/nop-biz/src/main/java/io/nop/biz/crud/CrudBizModel.java index 8f469458e..f3ad53347 100644 --- a/nop-biz/src/main/java/io/nop/biz/crud/CrudBizModel.java +++ b/nop-biz/src/main/java/io/nop/biz/crud/CrudBizModel.java @@ -698,10 +698,16 @@ protected void doSaveEntity(@Name("entityData") EntityData 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) { } @@ -833,7 +839,7 @@ protected void defaultPrepareUpdate(@Name("entityData") EntityData entityData @BizAction protected void doUpdateEntity(@Name("entityData") EntityData entityData, IServiceContext context) { dao().updateEntity(entityData.getEntity()); - afterEntityChange(entityData.getEntity(), context); + afterEntityChange(entityData.getEntity(), context, BizConstants.METHOD_UPDATE); } @Description("@i18n:biz.get|根据id获取单条数据") @@ -1729,7 +1735,7 @@ protected void invokeDefaultPrepareSave(@Name("entityData") EntityData entity getThisObj().invoke("defaultPrepareSave", Map.of("entityData", entityData), null, context); } - protected void invokeDefaultPrepareCopyForNew(@Name("entityData") EntityData entityData, IServiceContext context){ + protected void invokeDefaultPrepareCopyForNew(@Name("entityData") EntityData entityData, IServiceContext context) { // 通过这种方式调用,允许在xbiz文件中覆盖Java中的方法 getThisObj().invoke("defaultPrepareCopyForNew", Map.of("entityData", entityData), null, context); } diff --git a/nop-dyn/nop-dyn-service/src/main/java/io/nop/dyn/service/entity/NopDynFunctionMetaBizModel.java b/nop-dyn/nop-dyn-service/src/main/java/io/nop/dyn/service/entity/NopDynFunctionMetaBizModel.java index 70f5df0a9..6abd2bd80 100644 --- a/nop-dyn/nop-dyn-service/src/main/java/io/nop/dyn/service/entity/NopDynFunctionMetaBizModel.java +++ b/nop-dyn/nop-dyn-service/src/main/java/io/nop/dyn/service/entity/NopDynFunctionMetaBizModel.java @@ -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; @@ -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()); }