From fe01f5544810db8382ac897aefa0c101c296d4d3 Mon Sep 17 00:00:00 2001 From: canonical Date: Fri, 11 Oct 2024 15:20:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9CrudBizModel=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0invokeDefaultPrepareQuery=E7=AD=89=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=8C=E6=94=AF=E6=8C=81=E5=9C=A8xbiz=E4=B8=AD?= =?UTF-8?q?=E8=A6=86=E7=9B=96java=E7=B1=BB=E4=B8=AD=E7=9A=84=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E7=82=B9=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/nop/biz/crud/CrudBizModel.java | 61 ++++++++++++++----- 1 file changed, 45 insertions(+), 16 deletions(-) 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 af4e82cfc..8f469458e 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 @@ -238,7 +238,7 @@ public long findCount(@Optional @Name("query") @Description("@i18n:biz.query|查 if (query != null) query.setDisableLogicalDelete(false); - return doFindCount0(query, getBizObjName(), this::defaultPrepareQuery, context); + return doFindCount0(query, getBizObjName(), this::invokeDefaultPrepareQuery, context); } @BizAction @@ -265,7 +265,7 @@ public PageBean findPage(@Optional @Name("query") @Description("@i18n:biz.que if (query != null) query.setDisableLogicalDelete(false); - return doFindPage(query, this::defaultPrepareQuery, selection, context); + return doFindPage(query, this::invokeDefaultPrepareQuery, selection, context); } @BizAction @@ -370,7 +370,7 @@ protected QueryBean prepareFindPageQuery(@Name("query") QueryBean query, if (queryTransformer != null) queryTransformer.transform(query, authObjName, action, this.getThisObj(), context); - BizQueryHelper.transformMapToProp(query,objMeta); + BizQueryHelper.transformMapToProp(query, objMeta); BizExprHelper.resolveBizExpr(query.getFilter(), context); return query; } @@ -417,7 +417,7 @@ public T findFirst(@Optional @Name(PARAM_QUERY) @Description("@i18n:biz.query| @Name(PARAM_SELECTION) FieldSelectionBean selection, IServiceContext context) { if (query != null) query.setDisableLogicalDelete(false); - return doFindFirst(query, this::defaultPrepareQuery, selection, context); + return doFindFirst(query, this::invokeDefaultPrepareQuery, selection, context); } @BizAction @@ -467,7 +467,7 @@ protected void defaultPrepareQuery(@Name("query") QueryBean query, IServiceConte @GraphQLReturn(bizObjName = BIZ_OBJ_NAME_THIS_OBJ) @BizMakerChecker(tryMethod = METHOD_TRY_SAVE) public T save(@Name("data") Map data, IServiceContext context) { - return doSave(data, null, this::defaultPrepareSave, context); + return doSave(data, null, this::invokeDefaultPrepareSave, context); } @BizAction @@ -642,7 +642,6 @@ Object getId(Map data, IEntityDao dao) { return values; } - @BizAction protected void checkDataAuth(@Name("action") String action, @Name("entity") T entity, IServiceContext context) { IDataAuthChecker dataAuthChecker = context.getDataAuthChecker(); if (dataAuthChecker == null) @@ -654,7 +653,6 @@ protected void checkDataAuth(@Name("action") String action, @Name("entity") T en } } - @BizAction protected void checkDataAuthAfterUpdate(@Name("entity") T entity, IServiceContext context) { IDataAuthChecker dataAuthChecker = context.getDataAuthChecker(); if (dataAuthChecker == null) @@ -666,6 +664,7 @@ protected void checkDataAuthAfterUpdate(@Name("entity") T entity, IServiceContex } } + @BizAction protected void defaultPrepareSave(@Name("entityData") EntityData entityData, IServiceContext context) { IStateMachine stm = getThisObj().getStateMachine(); @@ -674,9 +673,10 @@ protected void defaultPrepareSave(@Name("entityData") EntityData entityData, } } + @BizAction protected void defaultPrepareCopyForNew(@Name("entityData") EntityData entityData, IServiceContext context) { - this.defaultPrepareSave(entityData, context); + this.invokeDefaultPrepareSave(entityData, context); } protected void triggerStateChange(T entity, String event, IServiceContext context) { @@ -723,7 +723,7 @@ protected void invokeAction(String actionName, Map args, IServic @GraphQLReturn(bizObjName = BIZ_OBJ_NAME_THIS_OBJ) @BizMakerChecker(tryMethod = METHOD_TRY_UPDATE) public T update(@Name("data") Map data, IServiceContext context) { - return doUpdate(data, null, this::defaultPrepareUpdate, context); + return doUpdate(data, null, this::invokeDefaultPrepareUpdate, context); } @BizAction @@ -880,7 +880,7 @@ protected void checkMandatoryParam(String actionName, String paramName, Object v @BizMutation @BizMakerChecker(tryMethod = METHOD_TRY_DELETE) public boolean delete(@Name("id") @Description("@i18n:biz.id|对象的主键标识") String id, IServiceContext context) { - return doDelete(id, this.getDefaultRefNamesToCheckExists(), this::defaultPrepareDelete, context); + return doDelete(id, this.getDefaultRefNamesToCheckExists(), this::invokeDefaultPrepareDelete, context); } public Set getDefaultRefNamesToCheckExists() { @@ -1003,6 +1003,7 @@ protected IOrmEntity findRefEntity(IEntityModel entityModel, T entity, String re return refDao.findFirstByExample(example); } + @BizAction protected void defaultPrepareDelete(@Name("entity") T entity, IServiceContext context) { checkChildrenNotExistsWhenDelete(entity, context); @@ -1213,7 +1214,7 @@ public PageBean deleted_findPage(@Optional @Name("query") @Description("@i18n query.addFilter(FilterBeans.eq(deleteFlagProp, 1)); - return doFindPage(query, this::defaultPrepareQuery, selection, context); + return doFindPage(query, this::invokeDefaultPrepareQuery, selection, context); } @Description("@i18n:biz.recoverDeleted|恢复已删除记录") @@ -1243,7 +1244,7 @@ public T recoverDeleted(@Name("id") String id, IServiceContext context) { public int updateByQuery(@Name("query") QueryBean query, @Name("data") Map data, IServiceContext context) { if (query != null) query.setDisableLogicalDelete(false); - return doUpdateByQuery(query, getBizObjName(), data, null, this::defaultPrepareUpdate, context); + return doUpdateByQuery(query, getBizObjName(), data, null, this::invokeDefaultPrepareUpdate, context); } @BizAction @@ -1284,7 +1285,7 @@ public int deleteByQuery(@Name("query") QueryBean query, IServiceContext context query.setDisableLogicalDelete(false); return doDeleteByQuery(query, getBizObjName(), getDefaultRefNamesToCheckExists(), - null, this::defaultPrepareDelete, context); + null, this::invokeDefaultPrepareDelete, context); } @BizAction @@ -1348,7 +1349,7 @@ public DictBean asDict(IServiceContext context) { public List findList(@Optional @Name("query") QueryBean query, FieldSelectionBean selection, IServiceContext context) { if (query != null) query.setDisableLogicalDelete(false); - return doFindList(query, this::defaultPrepareQuery, selection, context); + return doFindList(query, this::invokeDefaultPrepareQuery, selection, context); } @BizAction @@ -1396,7 +1397,7 @@ public List findRoots(@Optional @Name("query") QueryBean query, FieldSelectio query.addFilter(FilterBeans.eq(treeModel.getParentProp(), rootParentValue)); } query.setDisableLogicalDelete(false); - return doFindList(query, this::defaultPrepareQuery, selection, context); + return doFindList(query, this::invokeDefaultPrepareQuery, selection, context); } @@ -1479,7 +1480,7 @@ protected IObjPropMeta requirePropMeta(String propName) { public T copyForNew(@Name("data") Map data, IServiceContext context) { if (CollectionHelper.isEmptyMap(data)) throw new NopException(ERR_BIZ_EMPTY_DATA_FOR_SAVE).param(ARG_BIZ_OBJ_NAME, getBizObjName()); - return doCopyForNew(data, BizConstants.SELECTION_COPY_FOR_NEW, this::defaultPrepareCopyForNew, context); + return doCopyForNew(data, BizConstants.SELECTION_COPY_FOR_NEW, this::invokeDefaultPrepareCopyForNew, context); } @BizAction @@ -1716,4 +1717,32 @@ public PageBean doFindPageForTree(@Name("query") QueryBean query, // public List exportableFields(IServiceContext context) { // return BizExportHelper.getExportableFields(getBizObjName(), getThisObj().getObjMeta(), context); // } + + + protected void invokeDefaultPrepareQuery(@Name("query") QueryBean query, IServiceContext context) { + // 通过这种方式调用,允许在xbiz文件中覆盖Java中的方法 + getThisObj().invoke("defaultPrepareQuery", Map.of("query", query), null, context); + } + + protected void invokeDefaultPrepareSave(@Name("entityData") EntityData entityData, IServiceContext context) { + // 通过这种方式调用,允许在xbiz文件中覆盖Java中的方法 + getThisObj().invoke("defaultPrepareSave", Map.of("entityData", entityData), null, context); + } + + protected void invokeDefaultPrepareCopyForNew(@Name("entityData") EntityData entityData, IServiceContext context){ + // 通过这种方式调用,允许在xbiz文件中覆盖Java中的方法 + getThisObj().invoke("defaultPrepareCopyForNew", Map.of("entityData", entityData), null, context); + } + + + protected void invokeDefaultPrepareUpdate(@Name("entityData") EntityData entityData, IServiceContext context) { + // 通过这种方式调用,允许在xbiz文件中覆盖Java中的方法 + getThisObj().invoke("defaultPrepareUpdate", Map.of("entityData", entityData), null, context); + } + + + protected void invokeDefaultPrepareDelete(@Name("entity") T entity, IServiceContext context) { + // 通过这种方式调用,允许在xbiz文件中覆盖Java中的方法 + getThisObj().invoke("defaultPrepareDelete", Map.of("entity", entity), null, context); + } }