Skip to content

Commit

Permalink
修改CrudBizModel,增加invokeDefaultPrepareQuery等方法,支持在xbiz中覆盖java类中的扩展点方法
Browse files Browse the repository at this point in the history
  • Loading branch information
entropy-cloud committed Oct 11, 2024
1 parent fb57a1b commit fe01f55
Showing 1 changed file with 45 additions and 16 deletions.
61 changes: 45 additions & 16 deletions nop-biz/src/main/java/io/nop/biz/crud/CrudBizModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -265,7 +265,7 @@ public PageBean<T> 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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<String, Object> data, IServiceContext context) {
return doSave(data, null, this::defaultPrepareSave, context);
return doSave(data, null, this::invokeDefaultPrepareSave, context);
}

@BizAction
Expand Down Expand Up @@ -642,7 +642,6 @@ Object getId(Map<String, Object> data, IEntityDao<T> dao) {
return values;
}

@BizAction
protected void checkDataAuth(@Name("action") String action, @Name("entity") T entity, IServiceContext context) {
IDataAuthChecker dataAuthChecker = context.getDataAuthChecker();
if (dataAuthChecker == null)
Expand All @@ -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)
Expand All @@ -666,6 +664,7 @@ protected void checkDataAuthAfterUpdate(@Name("entity") T entity, IServiceContex
}
}


@BizAction
protected void defaultPrepareSave(@Name("entityData") EntityData<T> entityData, IServiceContext context) {
IStateMachine stm = getThisObj().getStateMachine();
Expand All @@ -674,9 +673,10 @@ protected void defaultPrepareSave(@Name("entityData") EntityData<T> entityData,
}
}


@BizAction
protected void defaultPrepareCopyForNew(@Name("entityData") EntityData<T> entityData, IServiceContext context) {
this.defaultPrepareSave(entityData, context);
this.invokeDefaultPrepareSave(entityData, context);
}

protected void triggerStateChange(T entity, String event, IServiceContext context) {
Expand Down Expand Up @@ -723,7 +723,7 @@ protected void invokeAction(String actionName, Map<String, Object> args, IServic
@GraphQLReturn(bizObjName = BIZ_OBJ_NAME_THIS_OBJ)
@BizMakerChecker(tryMethod = METHOD_TRY_UPDATE)
public T update(@Name("data") Map<String, Object> data, IServiceContext context) {
return doUpdate(data, null, this::defaultPrepareUpdate, context);
return doUpdate(data, null, this::invokeDefaultPrepareUpdate, context);
}

@BizAction
Expand Down Expand Up @@ -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<String> getDefaultRefNamesToCheckExists() {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1213,7 +1214,7 @@ public PageBean<T> 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|恢复已删除记录")
Expand Down Expand Up @@ -1243,7 +1244,7 @@ public T recoverDeleted(@Name("id") String id, IServiceContext context) {
public int updateByQuery(@Name("query") QueryBean query, @Name("data") Map<String, Object> 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1348,7 +1349,7 @@ public DictBean asDict(IServiceContext context) {
public List<T> 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
Expand Down Expand Up @@ -1396,7 +1397,7 @@ public List<T> 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);
}


Expand Down Expand Up @@ -1479,7 +1480,7 @@ protected IObjPropMeta requirePropMeta(String propName) {
public T copyForNew(@Name("data") Map<String, Object> 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
Expand Down Expand Up @@ -1716,4 +1717,32 @@ public PageBean<T> doFindPageForTree(@Name("query") QueryBean query,
// public List<DictOptionBean> 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<T> entityData, IServiceContext context) {
// 通过这种方式调用,允许在xbiz文件中覆盖Java中的方法
getThisObj().invoke("defaultPrepareSave", Map.of("entityData", entityData), null, context);
}

protected void invokeDefaultPrepareCopyForNew(@Name("entityData") EntityData<T> entityData, IServiceContext context){
// 通过这种方式调用,允许在xbiz文件中覆盖Java中的方法
getThisObj().invoke("defaultPrepareCopyForNew", Map.of("entityData", entityData), null, context);
}


protected void invokeDefaultPrepareUpdate(@Name("entityData") EntityData<T> 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);
}
}

0 comments on commit fe01f55

Please sign in to comment.