From c0948102eda828d4eae62d18392adaca56e345e0 Mon Sep 17 00:00:00 2001 From: Houjie <714924425@qq.com> Date: 星期三, 09 七月 2025 09:19:24 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- lxzn-module-flowable/src/main/java/org/jeecg/modules/flowable/service/impl/FlowTaskServiceImpl.java | 93 ++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 88 insertions(+), 5 deletions(-) diff --git a/lxzn-module-flowable/src/main/java/org/jeecg/modules/flowable/service/impl/FlowTaskServiceImpl.java b/lxzn-module-flowable/src/main/java/org/jeecg/modules/flowable/service/impl/FlowTaskServiceImpl.java index 99738f1..95ac97a 100644 --- a/lxzn-module-flowable/src/main/java/org/jeecg/modules/flowable/service/impl/FlowTaskServiceImpl.java +++ b/lxzn-module-flowable/src/main/java/org/jeecg/modules/flowable/service/impl/FlowTaskServiceImpl.java @@ -19,6 +19,7 @@ import org.flowable.common.engine.api.FlowableObjectNotFoundException; import org.flowable.common.engine.impl.identity.Authentication; import org.flowable.engine.ProcessEngineConfiguration; +import org.flowable.engine.TaskService; import org.flowable.engine.history.HistoricActivityInstance; import org.flowable.engine.history.HistoricProcessInstance; import org.flowable.engine.history.HistoricProcessInstanceQuery; @@ -34,6 +35,7 @@ import org.flowable.task.api.TaskQuery; import org.flowable.task.api.history.HistoricTaskInstance; import org.jeecg.common.api.vo.Result; +import org.jeecg.common.exception.JeecgBootException; import org.jeecg.common.system.vo.LoginUser; import org.jeecg.common.util.SpringContextUtils; import org.jeecg.modules.flowable.apithird.business.dto.FlowMyBusinessDto; @@ -50,6 +52,7 @@ import org.jeecg.modules.flowable.domain.dto.FlowTaskDto; import org.jeecg.modules.flowable.domain.dto.FlowViewerDto; import org.jeecg.modules.flowable.domain.vo.FlowTaskVo; +import org.jeecg.modules.flowable.domain.vo.WorkTaskDataVo; import org.jeecg.modules.flowable.factory.FlowServiceFactory; import org.jeecg.modules.flowable.flow.CustomProcessDiagramGenerator; import org.jeecg.modules.flowable.flow.FindNextNodeUtil; @@ -78,6 +81,8 @@ private IFlowThirdService iFlowThirdService; @Autowired FlowMyBusinessServiceImpl flowMyBusinessService; + @Autowired + private TaskService taskService; /** * 瀹屾垚浠诲姟 * @@ -668,6 +673,30 @@ flowTaskVo.setTaskId(business.getTaskId()); return findReturnTaskList(flowTaskVo); } + + /** + * 缁撴潫娴佺▼ + * @param processInstanceId 娴佺▼瀹炰緥 ID + * @param deleteReason 瀹氫箟鍒犻櫎鍘熷洜 + */ + public Result<?> end(String processInstanceId, String deleteReason) { + try { + // 寮哄埗缁撴潫娴佺▼瀹炰緥 + runtimeService.deleteProcessInstance(processInstanceId, deleteReason); + // 鍒犻櫎鍏宠仈娴佺▼鐨勪笟鍔� + FlowMyBusiness flowMyBusiness=flowMyBusinessService.getFlowMyBusiness(processInstanceId); + flowMyBusinessService.removeById(flowMyBusiness.getId()); + System.out.println("Process instance with ID " + processInstanceId + " has been forcefully ended."); + } catch (Exception e) { + System.err.println("Failed to force end process instance: " + e.getMessage()); + } + + // 鍏抽棴娴佺▼寮曟搸 + processEngine.close(); + return Result.OK("娴佺▼宸茬粨鏉�"); + } + + /** * 鑾峰彇鎵�鏈夊彲鍥為��鐨勮妭鐐� * @@ -1045,11 +1074,18 @@ HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery() .processInstanceId(flowTaskDto.getProcInsId()) .singleResult(); - SysUser startUser = iFlowThirdService.getUserByUsername(historicProcessInstance.getStartUserId()); - flowTaskDto.setStartUserId(startUser.getUsername()); - flowTaskDto.setStartUserName(startUser.getRealname()); - List<String> departNamesByUsername = iFlowThirdService.getDepartNamesByUsername(historicProcessInstance.getStartUserId()); - flowTaskDto.setStartDeptName(CollUtil.join(departNamesByUsername,"锛�")); + if(historicProcessInstance != null) { + SysUser startUser = iFlowThirdService.getUserByUsername(historicProcessInstance.getStartUserId()); + if(startUser == null) { + flowTaskDto.setStartUserId(""); + flowTaskDto.setStartUserName(""); + }else { + flowTaskDto.setStartUserId(startUser.getUsername()); + flowTaskDto.setStartUserName(startUser.getRealname()); + } + List<String> departNamesByUsername = iFlowThirdService.getDepartNamesByUsername(historicProcessInstance.getStartUserId()); + flowTaskDto.setStartDeptName(CollUtil.join(departNamesByUsername,"锛�")); + } }); IPage<FlowTaskDto> flowTaskDtoIPage = new Page<>(); flowTaskDtoIPage.setRecords(list); @@ -1350,6 +1386,53 @@ return Result.OK(flowNextDto); } + @Override + public WorkTaskDataVo getPreviousFlowInfo(String dataId) { + FlowMyBusiness flowMyBusiness = flowMyBusinessService.getByDataId(dataId); + if (flowMyBusiness == null) { + throw new JeecgBootException("鏈壘鍒版祦绋嬫暟鎹紒"); + } + + String taskId = flowMyBusiness.getTaskId(); + String processInstanceId = flowMyBusiness.getProcessInstanceId(); + WorkTaskDataVo taskDataVo = new WorkTaskDataVo(); + // 濡傛灉褰撳墠浠诲姟ID涓虹┖锛屽垯灏濊瘯浠庡巻鍙蹭换鍔′腑鑾峰彇鏈�鍚庝竴涓畬鎴愮殑浠诲姟 + if (StringUtils.isBlank(taskId)) { + List<HistoricTaskInstance> historicTasks = historyService + .createHistoricTaskInstanceQuery() + .processInstanceId(processInstanceId) + .orderByTaskCreateTime() + .desc() + .list(); + + if (CollectionUtils.isEmpty(historicTasks)) { + throw new JeecgBootException("鎵句笉鍒板巻鍙蹭换鍔¤褰�"); + } + + HistoricTaskInstance lastTask = historicTasks.get(0); + buildWorkTaskDataVo(taskDataVo, lastTask.getId(), lastTask.getName(), lastTask.getCreateTime()); + } else { + Task task = taskService.createTaskQuery().taskId(taskId).active().singleResult(); + if (task == null) { + throw new JeecgBootException("鎵句笉鍒板搴斾换鍔�"); + } else { + buildWorkTaskDataVo(taskDataVo, task.getId(), task.getName(), task.getCreateTime()); + } + } + return taskDataVo; + } + + private void buildWorkTaskDataVo(WorkTaskDataVo taskDataVo, String id, String name, Date createTime) { + taskDataVo.setId(id); + taskDataVo.setName(name); + taskDataVo.setCreateTime(createTime); + HistoricActivityInstance previousNode = flowMyBusinessService.getPreviousNode(id); + if (previousNode != null) { + taskDataVo.setPreNode(previousNode.getActivityName()); + taskDataVo.setPreNodeAssignee(previousNode.getAssignee()); + } + } + /** * 鑾峰彇涓嬩竴涓妭鐐逛俊鎭�,娴佺▼瀹氫箟涓婄殑鑺傜偣淇℃伅 * @param taskId 褰撳墠鑺傜偣id -- Gitblit v1.9.3