From 6e22eee1db782ccd72caecce9491f357e8cadf46 Mon Sep 17 00:00:00 2001
From: xiangpei <xiangpei@timesnew.cn>
Date: 星期五, 03 一月 2025 15:09:42 +0800
Subject: [PATCH] 剩余事项统计逻辑优化
---
flowable/src/main/java/com/ycl/service/common/TaskCommonService.java | 93 +++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 91 insertions(+), 2 deletions(-)
diff --git a/flowable/src/main/java/com/ycl/service/common/TaskCommonService.java b/flowable/src/main/java/com/ycl/service/common/TaskCommonService.java
index af2d729..0385cd7 100644
--- a/flowable/src/main/java/com/ycl/service/common/TaskCommonService.java
+++ b/flowable/src/main/java/com/ycl/service/common/TaskCommonService.java
@@ -2,6 +2,9 @@
import com.alibaba.fastjson2.JSONObject;
import com.ycl.common.constant.ProcessConstants;
+import com.ycl.common.core.domain.entity.SysUser;
+import com.ycl.common.enums.FlowComment;
+import com.ycl.common.enums.business.TaskStatusEnum;
import com.ycl.domain.entity.SysForm;
import com.ycl.domain.vo.FormDetailVO;
import com.ycl.flow.FindNextNodeUtil;
@@ -9,9 +12,14 @@
import lombok.RequiredArgsConstructor;
import org.flowable.bpmn.model.*;
import org.flowable.bpmn.model.Process;
+import org.flowable.engine.HistoryService;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
+import org.flowable.engine.TaskService;
+import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.repository.ProcessDefinition;
+import org.flowable.task.api.Task;
+import org.flowable.task.api.history.HistoricTaskInstance;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
@@ -29,9 +37,11 @@
private final RuntimeService runtimeService;
private final RepositoryService repositoryService;
+ private final TaskService taskService;
+ private final HistoryService historyService;
/**
- * 閫氳繃褰撳墠鑺傜偣瀹氫箟key锛岃幏鍙栧叾涓婁竴涓妭鐐逛互鍙婂綋鍓嶈妭鐐圭殑淇℃伅锛屽鏋滃墠闈㈡槸骞惰鐨勪細杩斿洖澶氫釜
+ * 閫氳繃褰撳墠鑺傜偣瀹氫箟key锛岃幏鍙栧叾涓婁竴涓妭鐐圭殑淇℃伅锛屽鏋滃墠闈㈡槸骞惰鐨勪細杩斿洖澶氫釜(鍖呭惈褰撳墠鑺傜偣)
*
* @param processDefId 娴佺▼瀹氫箟id
* @param currentNodeDefId 褰撳墠鑺傜偣瀹氫箟id
@@ -96,6 +106,52 @@
return defKeys;
}
+
+ /**
+ * 鑾峰彇褰撳墠鑺傜偣鐨勫墠缃妭鐐癸紝涓嶅寘鍚綋鍓嶈妭鐐�
+ *
+ * @param processDefId
+ * @param currentNodeDefId
+ * @return
+ */
+ public List<FormDetailVO> getBeforeNodeList(String processDefId, String currentNodeDefId) {
+ // 鑾峰彇娴佺▼瀹氫箟
+ ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
+ .processDefinitionId(processDefId)
+ .singleResult();
+
+ // 鑾峰彇娴佺▼妯″瀷
+ BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefId);
+ if (bpmnModel == null) {
+ throw new RuntimeException("BpmnModel not found for processDefinitionId: " + processDefId);
+ }
+
+ // 鑾峰彇娴佺▼瀵硅薄
+ Process process = bpmnModel.getProcessById(processDefinition.getKey());
+ if (process == null) {
+ throw new RuntimeException("Process not found for processDefinitionId: " + processDefId);
+ }
+
+ // 閬嶅巻娴佺▼鍏冪礌锛屾壘鍒板搴旂殑浠诲姟鑺傜偣
+ Collection<FlowElement> flowElements = process.getFlowElements();
+ UserTask currentElement = null;
+ for (FlowElement flowElement : flowElements) {
+ if (flowElement instanceof UserTask && flowElement.getId().equals(currentNodeDefId)) {
+ currentElement = (UserTask) flowElement;
+ break;
+ }
+ }
+ if (Objects.isNull(currentElement)) {
+ throw new RuntimeException("鏈壘鍒拌浠诲姟鐨勬祦绋嬪畾涔夎妭鐐�");
+ }
+
+ List<FormDetailVO> defKeys = new ArrayList<>(2);
+
+ this.beforeNodeInfo(currentElement, defKeys);
+
+ return defKeys;
+ }
+
/**
* 閫掑綊鑾峰彇褰撳墠鑺傜偣鐨勫墠涓�涓换鍔¤妭鐐逛俊鎭�
*
@@ -111,7 +167,6 @@
FormDetailVO formDetailVO = new FormDetailVO();
formDetailVO.setBeforeNodeDefId(incomingFlow.getSourceFlowElement().getId());
formDetailVO.setBeforeNodeName(incomingFlow.getSourceFlowElement().getName());
- formDetailVO.setBeforeNodeName(((UserTask) incomingFlow.getSourceFlowElement()).getOwner());
defKeys.add(formDetailVO);
} else {
beforeNodeInfo(incomingFlow.getSourceFlowElement(), defKeys);
@@ -209,4 +264,38 @@
return Boolean.FALSE;
}
+
+ /**
+ * 椹冲洖浠诲姟
+ *
+ * @param rejectedTaskDefKey 琚┏鍥炵殑浠诲姟key
+ * @param rejectTaskDefKey 鎵ц椹冲洖鎿嶄綔鎵�鍦ㄧ殑浠诲姟key
+ * @param processInsId 娴佺▼瀹炰緥id
+ * @param taskId 褰撳墠浠诲姟id
+ * @param msg 瀹℃牳鎰忚
+ */
+ public void reject(String rejectedTaskDefKey, String rejectTaskDefKey, String processInsId, String taskId, String msg) {
+ // 椹冲洖鐨勬牳蹇僡pi锛歳untimeService.createChangeActivityStateBuilder().moveXXX 鐨刟pi锛屽彲浠ヨ缃粠褰撳墠鑺傜偣绉诲姩鍒扮洰鏍囪妭鐐�
+ // 椹冲洖鐨勬牳蹇冿細闇�瑕佹壘鍒板綋鍓嶈妭鐐广�佷互鍙婅娴佽浆鍒扮殑鐩爣鑺傜偣銆傚叾涓瘮杈冮夯鐑︾殑鏄鐞嗗苟琛岀瓑姣旇緝澶嶆潅鐨勬儏鍐�
+ /**
+ * 椹冲洖鐨勬儏鍐靛垎涓轰互涓嬩笁绉嶏細
+ *
+ * 1. 濡傛灉鎵ц椹冲洖鎿嶄綔鐨勪换鍔℃槸鍦ㄥ苟琛岀粨鏉熺殑鍚庝竴涓妭鐐癸紝閭d箞琚┏鍥炵殑浠诲姟灞炰簬骞惰涓殑鏌愪釜鍒嗘敮鐨勭粨鏉熻妭鐐�
+ * 2. 濡傛灉鎵ц椹冲洖鎿嶄綔鐨勮妭鐐规槸骞惰寮�濮嬪悗鐨勬煇涓�鍒嗘敮鐨勫紑濮嬭妭鐐癸紝閭d箞璇ヨ妭鐐瑰拰琚┏鍥炶妭鐐瑰疄闄呬笂灞炰簬涓茶锛� 鍙笉杩囬渶瑕佸悓鏃舵妸鍏跺畠骞惰鍒嗘敮涔熼┏鍥炰簡锛堣繖閲屽苟涓嶉渶瑕佹墜鍔ㄥ鐞嗭級
+ * 3. 濡傛灉 琚┏鍥炶妭鐐瑰拰椹冲洖鑺傜偣灞炰簬涓茶锛屽垯鐩存帴椹冲洖鏃犻渶鑰冭檻鍏跺畠
+ */
+ // 鎵�浠ラ噸瑕佺殑鏄垽鏂袱涓换鍔′箣闂存槸鍚﹀瓨鍦ㄧ壒娈婅妭鐐癸紝鐩墠鍙厛鑰冭檻骞惰缃戝叧
+
+ // 璁剧疆涓ゆ潯璇勮
+ List<HistoricTaskInstance> rejectedTaskList = historyService.createHistoricTaskInstanceQuery().processInstanceId(processInsId).taskDefinitionKey(rejectedTaskDefKey).orderByHistoricTaskInstanceStartTime().desc().list();
+ String msg1 = "椹冲洖浜嗭細銆�" + rejectedTaskList.get(0).getName() + "銆戯紝椹冲洖鍘熷洜锛�";
+ taskService.addComment(taskId, processInsId, FlowComment.REJECT.getType(), msg1 + msg);
+ // TODO 鐩存帴浣跨敤杩欎釜api濂藉儚鏈夐棶棰�
+ runtimeService.createChangeActivityStateBuilder().processInstanceId(processInsId).moveActivityIdTo(rejectTaskDefKey, rejectedTaskDefKey).changeState();
+ runtimeService.createChangeActivityStateBuilder().processInstanceId(processInsId).moveExecutionToActivityId(rejectTaskDefKey, rejectedTaskDefKey).changeState();
+ }
+
+
+
+
}
--
Gitblit v1.8.0