-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix:Gitee#I8326Z * fix: 删除时不生效 * fix: tag fillback * v3.4.4 * frontjs-sdk-demo * bk: getActualMaximum
- Loading branch information
1 parent
188cbf7
commit 41d33a4
Showing
10 changed files
with
320 additions
and
22 deletions.
There are no files selected for viewing
Submodule @rbv
updated
from e83ed9 to 0ace77
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
160 changes: 160 additions & 0 deletions
160
src/main/java/com/rebuild/core/service/trigger/impl/AutoHoldTriggerAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/*! | ||
Copyright (c) Ruifang Tech <http://ruifang-tech.com/> and/or its owners. All rights reserved. | ||
*/ | ||
|
||
package com.rebuild.core.service.trigger.impl; | ||
|
||
import cn.devezhao.persist4j.Entity; | ||
import cn.devezhao.persist4j.Field; | ||
import cn.devezhao.persist4j.dialect.FieldType; | ||
import cn.devezhao.persist4j.engine.ID; | ||
import com.alibaba.fastjson.JSONArray; | ||
import com.alibaba.fastjson.JSONObject; | ||
import com.rebuild.core.Application; | ||
import com.rebuild.core.metadata.EntityHelper; | ||
import com.rebuild.core.metadata.MetadataHelper; | ||
import com.rebuild.core.privileges.bizz.InternalPermission; | ||
import com.rebuild.core.service.approval.ApprovalHelper; | ||
import com.rebuild.core.service.approval.ApprovalState; | ||
import com.rebuild.core.service.general.OperatingContext; | ||
import com.rebuild.core.service.trigger.ActionContext; | ||
import com.rebuild.core.service.trigger.TriggerAction; | ||
import com.rebuild.core.service.trigger.TriggerException; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author devezhao | ||
* @since 2023/9/27 | ||
*/ | ||
@Slf4j | ||
public abstract class AutoHoldTriggerAction extends TriggerAction { | ||
|
||
private Set<ID> willRecords; | ||
|
||
protected AutoHoldTriggerAction(ActionContext actionContext) { | ||
super(actionContext); | ||
} | ||
|
||
// 删除前保持 | ||
@Override | ||
protected void prepare(OperatingContext operatingContext) throws TriggerException { | ||
if (operatingContext.getAction() == InternalPermission.DELETE_BEFORE) { | ||
willRecords = getRelatedRecords( | ||
actionContext, operatingContext.getAnyRecord().getPrimary()); | ||
} | ||
} | ||
|
||
/** | ||
* 获取待处理记录 | ||
* | ||
* @param operatingContext | ||
* @return | ||
*/ | ||
protected Set<ID> getWillRecords(OperatingContext operatingContext) { | ||
if (willRecords == null) { | ||
willRecords = getRelatedRecords( | ||
actionContext, operatingContext.getAnyRecord().getPrimary()); | ||
} | ||
return willRecords; | ||
} | ||
|
||
/** | ||
* 获取相关记录 | ||
* | ||
* @param actionContext | ||
* @param sourceRecordId | ||
* @return | ||
*/ | ||
protected static Set<ID> getRelatedRecords(ActionContext actionContext, ID sourceRecordId) { | ||
// 共享的需要使用记录 ID | ||
if (sourceRecordId.getEntityCode() == EntityHelper.ShareAccess) { | ||
Object[] o = Application.getQueryFactory().uniqueNoFilter(sourceRecordId, "recordId"); | ||
if (o == null) return Collections.emptySet(); | ||
sourceRecordId = (ID) o[0]; | ||
} | ||
|
||
final JSONObject actionContent = (JSONObject) actionContext.getActionContent(); | ||
|
||
Entity sourceEntity = actionContext.getSourceEntity(); | ||
JSONArray fs = actionContent.getJSONArray("fields"); | ||
|
||
List<String> fieldsSelf = new ArrayList<>(); | ||
List<Field> fieldsRefto = new ArrayList<>(); | ||
boolean hasSelf = false; | ||
|
||
for (Object o : fs) { | ||
String field = (String) o; | ||
if (field.contains(".")) { | ||
String[] fieldAndEntity = field.split("\\."); | ||
if (MetadataHelper.containsField(fieldAndEntity[1], fieldAndEntity[0])) { | ||
fieldsRefto.add(MetadataHelper.getField(fieldAndEntity[1], fieldAndEntity[0])); | ||
} | ||
|
||
} else { | ||
if (SOURCE_SELF.equals(field)) { | ||
fieldsSelf.add(sourceEntity.getPrimaryField().getName()); | ||
hasSelf = true; | ||
} if (sourceEntity.containsField(field)) { | ||
fieldsSelf.add(field); | ||
} | ||
} | ||
} | ||
|
||
final Set<ID> relateds = new HashSet<>(); | ||
|
||
if (!fieldsSelf.isEmpty()) { | ||
fieldsSelf.add(sourceEntity.getPrimaryField().getName()); | ||
Object[] o = Application.getQueryFactory().uniqueNoFilter(sourceRecordId, fieldsSelf.toArray(new String[0])); | ||
if (o != null) { | ||
for (Object id : o) { | ||
if (id != null) { | ||
if (id instanceof ID[]) Collections.addAll(relateds, (ID[]) id); | ||
else relateds.add((ID) id); | ||
} | ||
} | ||
} | ||
} | ||
|
||
for (Field refto : fieldsRefto) { | ||
Entity ownEntity = refto.getOwnEntity(); | ||
String sql = String.format("select %s from %s where ", | ||
ownEntity.getPrimaryField().getName(), ownEntity.getName()); | ||
|
||
// N2N | ||
if (refto.getType() == FieldType.REFERENCE_LIST) { | ||
sql += String.format( | ||
"exists (select recordId from NreferenceItem where ^%s = recordId and belongField = '%s' and referenceId = '%s')", | ||
ownEntity.getPrimaryField().getName(), refto.getName(), sourceRecordId); | ||
} else { | ||
sql += String.format("%s = '%s'", refto.getName(), sourceRecordId); | ||
} | ||
|
||
Object[][] array = Application.createQueryNoFilter(sql).array(); | ||
for (Object[] o : array) relateds.add((ID) o[0]); | ||
} | ||
|
||
// 不含自己 | ||
if (!hasSelf) relateds.remove(sourceRecordId); | ||
|
||
return relateds; | ||
} | ||
|
||
/** | ||
* 获取审核状态 | ||
* | ||
* @param recordId | ||
* @return | ||
* @see ApprovalHelper#getApprovalState(ID) | ||
*/ | ||
protected static ApprovalState getApprovalState(ID recordId) { | ||
Entity entity = MetadataHelper.getEntity(recordId.getEntityCode()); | ||
if (MetadataHelper.hasApprovalField(entity)) return ApprovalHelper.getApprovalState(recordId); | ||
else return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.