This commit is contained in:
2026-10-11 23:55:02 +08:00
parent 68fede2caf
commit a2e9e020b1
4 changed files with 88 additions and 34 deletions
@@ -105,7 +105,7 @@ public class MkProcessMessageService {
bizType, processId, loginName, JSON.toJSONString(processInfo));
if (isProcessFinished(processInfo)) {
applyProcessResult(handler, bizType, bizIdText, processId, formValues, true);
} else if (isProcessRejected(processInfo)) {
} else if (MkProcessNodeHelper.isProcessRejected(processInfo)) {
applyProcessResult(handler, bizType, bizIdText, processId, formValues, false);
} else if (StringUtil.isNotBlank(bizIdText)) {
try {
@@ -123,19 +123,6 @@ public class MkProcessMessageService {
return "30".equals(firstText(asMap(processInfo), "fdProcessStatus"));
}
private static boolean isProcessRejected(Object processInfo) {
Map<String, Object> info = asMap(processInfo);
if (!"20".equals(firstText(info, "fdProcessStatus"))) {
return false;
}
Object historyHandlerInfos = asMap(info.get("fdTaskInfo")).get("historyHandlerInfos");
if (!(historyHandlerInfos instanceof List<?> historyList) || historyList.isEmpty()) {
return false;
}
Object lastHandler = historyList.get(historyList.size() - 1);
return "N6".equals(firstText(asMap(lastHandler), "nodeNumber"));
}
private void applyProcessResult(IMkProcessBizHandler handler, String bizType, String bizIdText,
String processId, Map<String, Object> formValues, boolean approved) {
String action = approved ? "审核通过" : "审核驳回";
@@ -11,20 +11,47 @@ import java.util.Map;
import java.util.stream.Collectors;
/**
* 解析 MK 流程实例详情中的当前节点、当前处理人
* 解析 MK 流程实例详情中的当前节点、当前处理人,以及流程是否驳回到起草节点。
*/
public final class MkProcessNodeHelper {
/**
* 起草节点编号。审批节点编号随流程模板变化,不能用来判断驳回。
*/
private static final String DRAFT_NODE_NUMBER = "N2";
private static final List<String> CURRENT_NODE_KEYS = List.of("handlerInfos", "drafterInfos", "adminInfos");
private MkProcessNodeHelper() {
}
/**
* 流程未结束,且当前待办已经回到起草节点时,才视为审核驳回。
* 中间审批节点通过后流程状态仍是 20,不能把历史节点编号当成驳回。
*/
public static boolean isProcessRejected(Object processInfo) {
Map<String, Object> info = asMap(processInfo);
String processStatus = text(info.get("fdProcessStatus"));
if (!"11".equals(processStatus) && !"20".equals(processStatus)) {
return false;
}
return hasActiveDraftNode(asMap(info.get("fdTaskInfo")));
}
public static String currentProcessor(Object processInfo) {
return joinDistinct(extractTexts(asMap(processInfo).get("currentHandlers"), "fdName", "name"), "、");
}
public static String currentNode(Object processInfo) {
Map<String, Object> taskInfo = asMap(asMap(processInfo).get("fdTaskInfo"));
return joinDistinct(extractTexts(taskInfo.get("handlerInfos"), "nodeName"), "、");
List<String> nodeNames = new ArrayList<>();
for (String key : CURRENT_NODE_KEYS) {
nodeNames.addAll(extractActiveNodeNames(taskInfo.get(key)));
}
if (nodeNames.isEmpty()) {
nodeNames.addAll(extractTexts(taskInfo.get("handlerInfos"), "nodeName"));
}
return joinDistinct(nodeNames, "、");
}
public static String text(String value, String fallback) {
@@ -52,6 +79,59 @@ public final class MkProcessNodeHelper {
}
}
private static boolean hasActiveDraftNode(Map<String, Object> taskInfo) {
for (String key : CURRENT_NODE_KEYS) {
Object nodes = taskInfo.get(key);
if (!(nodes instanceof Collection<?> collection)) {
continue;
}
for (Object item : collection) {
if (isActiveDraftNode(asMap(item))) {
return true;
}
}
}
return false;
}
private static boolean isActiveDraftNode(Map<String, Object> node) {
if (!"20".equals(text(node.get("status")))) {
return false;
}
String nodeNumber = text(node.get("nodeNumber"));
if (Func.isEmpty(nodeNumber)) {
nodeNumber = text(node.get("nodeId"));
}
if (DRAFT_NODE_NUMBER.equals(nodeNumber)) {
return true;
}
String activityType = text(node.get("activityType"));
return "draft".equalsIgnoreCase(activityType) || "draftTask".equalsIgnoreCase(activityType);
}
private static List<String> extractActiveNodeNames(Object listObj) {
List<String> result = new ArrayList<>();
if (!(listObj instanceof Collection<?> collection)) {
return result;
}
for (Object item : collection) {
Map<String, Object> node = asMap(item);
if (!"20".equals(text(node.get("status")))) {
continue;
}
String nodeName = text(node.get("nodeName"));
if (Func.isNotEmpty(nodeName)) {
result.add(nodeName);
}
}
return result;
}
private static String text(Object value) {
String text = Func.toStr(value, "").trim();
return "null".equalsIgnoreCase(text) ? "" : text;
}
private static List<String> extractTexts(Object listObj, String... keys) {
List<String> result = new ArrayList<>();
if (!(listObj instanceof Collection<?> collection) || keys == null) {
@@ -12,12 +12,12 @@ import org.springblade.core.tenant.annotation.TenantIgnore;
import org.springblade.core.tool.api.FR;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.process.feign.IBusinessProcessClient;
import org.springblade.transport.mk.MkProcessNodeHelper;
import org.springblade.transport.service.ICustomerArchiveService;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
@@ -97,7 +97,7 @@ public class CustomerArchivePublicProcessService {
processId, loginName, JSON.toJSONString(processInfo));
if (isProcessFinished(processInfo)) {
applyProcessResult(customerIdText, processId, formValues, true);
} else if (isProcessRejected(processInfo)) {
} else if (MkProcessNodeHelper.isProcessRejected(processInfo)) {
applyProcessResult(customerIdText, processId, formValues, false);
} else if (StringUtil.isNotBlank(customerIdText)) {
try {
@@ -115,19 +115,6 @@ public class CustomerArchivePublicProcessService {
return "30".equals(firstText(asMap(processInfo), "fdProcessStatus"));
}
private static boolean isProcessRejected(Object processInfo) {
Map<String, Object> info = asMap(processInfo);
if (!"20".equals(firstText(info, "fdProcessStatus"))) {
return false;
}
Object historyHandlerInfos = asMap(info.get("fdTaskInfo")).get("historyHandlerInfos");
if (!(historyHandlerInfos instanceof List<?> historyList) || historyList.isEmpty()) {
return false;
}
Object lastHandler = historyList.get(historyList.size() - 1);
return "N6".equals(firstText(asMap(lastHandler), "nodeNumber"));
}
private void applyProcessResult(String customerIdText, String processId, Map<String, Object> formValues,
boolean approved) {
String action = approved ? "审核通过" : "审核驳回";
@@ -33,6 +33,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.transport.mk.MkProcessNodeHelper;
import org.springblade.transport.support.TransportBusinessSupport;
import org.springblade.core.tenant.annotation.TenantIgnore;
import org.springblade.core.tool.jackson.JsonUtil;
@@ -303,9 +304,8 @@ public class CustomerArchiveServiceImpl extends BaseServiceImpl<CustomerArchiveM
log.warn("同步客商当前节点跳过,流程实例详情为空 id={}", id);
return false;
}
String currentProcessor = joinDistinct(extractTexts(info.get("currentHandlers"), "fdName", "name"), "、");
Map<String, Object> taskInfo = asStringObjectMap(info.get("fdTaskInfo"));
String currentNode = joinDistinct(extractTexts(taskInfo.get("handlerInfos"), "nodeName"), "、");
String currentProcessor = MkProcessNodeHelper.currentProcessor(processInfo);
String currentNode = MkProcessNodeHelper.currentNode(processInfo);
if (Func.isEmpty(currentNode) && Func.isEmpty(currentProcessor)) {
log.warn("同步客商当前节点跳过,未解析到节点名称或处理人 id={}", id);
return false;