From 3cbfc1624bb7a23a4dfa62ec4558578b00be56b3 Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期二, 04 三月 2025 21:59:55 +0800 Subject: [PATCH] 流程日志查询bug、督办日志bug --- business/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java | 200 +++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 183 insertions(+), 17 deletions(-) diff --git a/business/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java b/business/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java index ca2edcc..c41b7db 100644 --- a/business/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java +++ b/business/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java @@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.ycl.common.base.Result; import com.ycl.common.constant.ProcessConstants; import com.ycl.common.core.domain.AjaxResult; import com.ycl.common.core.domain.entity.SysDept; @@ -15,6 +16,7 @@ import com.ycl.common.core.domain.entity.SysUser; import com.ycl.common.enums.FlowComment; import com.ycl.common.enums.business.ProcessLogEventTypeEnum; +import com.ycl.common.enums.business.TaskStatusEnum; import com.ycl.common.exception.CustomException; import com.ycl.common.utils.SecurityUtils; import com.ycl.domain.dto.FlowCommentDto; @@ -22,12 +24,12 @@ import com.ycl.domain.dto.FlowTaskDto; import com.ycl.domain.dto.FlowViewerDto; import com.ycl.domain.entity.ProcessCoding; +import com.ycl.domain.entity.ProcessLog; import com.ycl.domain.entity.ProjectProcess; import com.ycl.domain.entity.SysForm; import com.ycl.domain.json.RejectData; -import com.ycl.domain.vo.FlowQueryVo; -import com.ycl.domain.vo.FlowTaskVo; -import com.ycl.domain.vo.FormDetailVO; +import com.ycl.domain.query.ProcessLogQuery; +import com.ycl.domain.vo.*; import com.ycl.event.event.TaskLogEvent; import com.ycl.factory.FlowServiceFactory; import com.ycl.flow.CustomProcessDiagramGenerator; @@ -67,12 +69,14 @@ import org.flowable.task.api.TaskQuery; import org.flowable.task.api.history.HistoricTaskInstance; import org.flowable.task.api.history.HistoricTaskInstanceQuery; +import org.springframework.beans.BeanUtils; import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.InputStream; import java.lang.reflect.Field; +import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -149,21 +153,19 @@ if (Objects.isNull(projectProcess)) { return AjaxResult.error("椤圭洰娴佺▼鏈粦瀹�"); } - Map<String, Object> processVariables = new HashMap<>(); - //鏌ュ嚭瀛楀吀涓渶瑕佹敞鍏ョ殑瀛楁淇℃伅 + + // 鏌ュ嚭瀛楀吀涓渶瑕佹敞鍏ョ殑瀛楁淇℃伅 List<String> dictList = sysDictDService.selectDictDataByType("flow_variables").stream().map(SysDictData::getDictValue).collect(Collectors.toList()); Map<String, Object> newV = new HashMap<>(2); if (!org.springframework.util.CollectionUtils.isEmpty(variables)) { for (String key : variables.keySet()) { newV.put(task.getTaskDefinitionKey() + "&" + key, variables.get(key)); - //瀛楀吀閲屾湁灏辨斁鍏ユ祦绋嬪彉閲忎腑 + // 瀛楀吀閲屾湁灏变笉鍋氬鐞� if (!CollectionUtils.isEmpty(dictList) && dictList.contains(key)) { - processVariables.put(key,variables.get(key)); + newV.put(key,variables.get(key)); } } } - //娣诲姞娴佺▼鍙橀噺 - if(!processVariables.isEmpty()) taskService.setVariables(taskId,processVariables); taskService.addComment(taskId, task.getProcessInstanceId(), FlowComment.SUBMIT.getType(), "瀹屾垚鎻愪氦"); if (DelegationState.PENDING.equals(task.getDelegationState())) { taskService.resolveTask(taskId, newV); @@ -178,6 +180,8 @@ projectProcess.getProjectId(), projectProcess.getProcessInsId(), taskId, + task.getTaskDefinitionKey(), + task.getName(), ProcessLogEventTypeEnum.FINISHED, null)); return AjaxResult.success("鎻愪氦鎴愬姛"); @@ -318,6 +322,8 @@ projectProcess.getProjectId(), projectProcess.getProcessInsId(), flowTaskVo.getTaskId(), + task.getTaskDefinitionKey(), + task.getName(), ProcessLogEventTypeEnum.REJECT, new RejectData(flowTaskVo.getComment()))); } @@ -1179,8 +1185,9 @@ .list(); //鎵╁睍 鑾峰彇杩欎釜娴佺▼瀹炰緥鐨勭洃鎺т俊鎭� key:TaskId value:瀹炰綋绫� - Map<String, ProcessCoding> processCodingMap = processCodingMapper - .selectList(new QueryWrapper<ProcessCoding>().eq("process_ins_id", procInsId)) + Map<String, ProcessCoding> processCodingMap = new LambdaQueryChainWrapper<>(processCodingMapper) + .eq(ProcessCoding::getProcessInsId, procInsId) + .list() .stream() .collect(Collectors.toMap(ProcessCoding::getTaskId, Function.identity())); // 淇濆瓨宸茬粡瀹屾垚鐨勬祦绋嬭妭鐐圭紪鍙� @@ -1245,14 +1252,70 @@ Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); // 娴佺▼鍙橀噺 Map<String, Object> parameters = new HashMap<>(); + List<FormDetailVO> beforeNodes = new ArrayList<>(); + String processInsId = ""; HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().includeProcessVariables().finished().taskId(taskId).singleResult(); if (Objects.nonNull(historicTaskInstance)) { parameters = historicTaskInstance.getProcessVariables(); + processInsId = historicTaskInstance.getProcessInstanceId(); + beforeNodes = this.getBeforeNodeForm(parameters, historicTaskInstance.getFormKey(), historicTaskInstance.getName(), historicTaskInstance.getProcessDefinitionId(), historicTaskInstance.getTaskDefinitionKey(), Boolean.FALSE); } else { parameters = taskService.getVariables(taskId); + processInsId = task.getProcessInstanceId(); + beforeNodes = this.getBeforeNodeForm(parameters, task.getFormKey(), task.getName(), task.getProcessDefinitionId(), task.getTaskDefinitionKey(), Boolean.FALSE); } - List<FormDetailVO> beforeNodes = this.getBeforeNodeForm(parameters, task.getFormKey(), task.getName(), task.getProcessDefinitionId(), task.getTaskDefinitionKey(), Boolean.FALSE); - return AjaxResult.success(beforeNodes); + // 鍒ゆ柇鍓嶇疆浠诲姟鏄笉鏄拰褰撳墠浠诲姟涓哄悓涓�涓猠xecuteId + // 鍒ゆ柇褰撳墠浠诲姟鏄惁琚寕璧蜂腑 + String finalProcessInsId = processInsId; + List<FormDetailVO> dataList = new ArrayList<>(2); + Map<String, List<FormDetailVO>> map = new HashMap<>(2); + beforeNodes.stream().forEach(node -> { + if (node.getCurrent()) { + dataList.add(node); + } else { + List<HistoricTaskInstance> beforeTasks = historyService.createHistoricTaskInstanceQuery() + .processInstanceId(finalProcessInsId) + .finished() + .taskDefinitionKey(node.getBeforeNodeDefId()) + .orderByTaskCreateTime() + .desc() + .list(); + if (CollectionUtils.isNotEmpty(beforeTasks) && Objects.nonNull(beforeTasks.get(0))) { + List<FormDetailVO> l = map.get(beforeTasks.get(0)); + if (CollectionUtils.isEmpty(l)) { + map.put(beforeTasks.get(0).getExecutionId(), Arrays.asList(node)); + } else { + l.add(node); + } + } + } + }); + for (String key : map.keySet()) { + if (StringUtils.isNotBlank(key)) { + // 鍚屼竴鎵ц鍣ㄤ笂鍙彇鏈�杩戠殑涓�涓� + dataList.add(map.get(key).get(0)); + } + } + List<DoFormDetailVO> vos = dataList.stream().map(node -> { + if (node.getCurrent()) { + if (processLogService.taskIsHangup(taskId, finalProcessInsId)) { + node.setTaskStatus(TaskStatusEnum.HANGUP); + } + } + // 鍒ゆ柇浠诲姟鏄惁瀛樺湪鐗规畩鎿嶄綔(濡傝烦杩囥�佽浆鍔炵瓑)锛岄渶瑕佸湪鍓嶇灞曠ず鍑烘潵 + ProcessLogQuery query = new ProcessLogQuery(); + query.setTaskDefKey(node.getUserTask().getId()); + query.setProcessInsId(finalProcessInsId); + Result result = processLogService.projectProcessLogPage(query); + List<ProcessLogVO> logList = (List<ProcessLogVO>) result.get("data"); + DoFormDetailVO vo = new DoFormDetailVO(); + BeanUtils.copyProperties(node, vo); + if (CollectionUtils.isNotEmpty(logList)) { + vo.setEvents(logList); + } + return vo; + }).collect(Collectors.toList()); + return AjaxResult.success(vos); } @Override @@ -1262,17 +1325,120 @@ Map<String, Object> parameters = new HashMap<>(); if (Objects.isNull(task)) { // 濡傛灉涓虹┖锛屽彲鑳芥槸浠诲姟宸茬粡缁撴潫 - HistoricTaskInstance hisTask = historyService.createHistoricTaskInstanceQuery().taskId(taskId).includeProcessVariables().singleResult(); - if (Objects.isNull(hisTask)) { + List<HistoricTaskInstance> hisTasks = historyService.createHistoricTaskInstanceQuery() + .taskId(taskId) + .finished() + .includeProcessVariables() + .orderByTaskCreateTime() + .desc() + .list(); + if (CollectionUtils.isNotEmpty(hisTasks) && Objects.isNull(hisTasks.get(0))) { throw new RuntimeException("璇ヤ换鍔′笉瀛樺湪"); } + HistoricTaskInstance hisTask = hisTasks.get(0); parameters = hisTask.getProcessVariables(); List<FormDetailVO> beforeNodes = this.getBeforeNodeForm(parameters, hisTask.getFormKey(), hisTask.getName(), hisTask.getProcessDefinitionId(), hisTask.getTaskDefinitionKey(), Boolean.TRUE); - return AjaxResult.success(beforeNodes); + List<FormDetailVO> dataList = new ArrayList<>(2); + Map<String, List<FormDetailVO>> map = new HashMap<>(2); + beforeNodes.stream().forEach(node -> { + if (node.getCurrent()) { + dataList.add(node); + } else { + List<HistoricTaskInstance> beforeTasks = historyService.createHistoricTaskInstanceQuery() + .processInstanceId(hisTask.getProcessInstanceId()) + .finished() + .taskDefinitionKey(node.getBeforeNodeDefId()) + .orderByTaskCreateTime() + .desc() + .list(); + if (CollectionUtils.isNotEmpty(beforeTasks) && Objects.nonNull(beforeTasks.get(0))) { + List<FormDetailVO> l = map.get(beforeTasks.get(0)); + if (CollectionUtils.isEmpty(l)) { + map.put(beforeTasks.get(0).getExecutionId(), Arrays.asList(node)); + } else { + l.add(node); + } + } + } + }); + for (String key : map.keySet()) { + if (StringUtils.isNotBlank(key)) { + // 鍚屼竴鎵ц鍣ㄤ笂鍙彇鏈�杩戠殑涓�涓� + dataList.add(map.get(key).get(0)); + } + } + List<DoFormDetailVO> vos = dataList.stream().map(node -> { + if (node.getCurrent()) { + if (processLogService.taskIsHangup(taskId, hisTask.getProcessInstanceId())) { + node.setTaskStatus(TaskStatusEnum.HANGUP); + } + } + // 鍒ゆ柇浠诲姟鏄惁瀛樺湪鐗规畩鎿嶄綔(濡傝烦杩囥�佽浆鍔炵瓑)锛岄渶瑕佸湪鍓嶇灞曠ず鍑烘潵 + ProcessLogQuery query = new ProcessLogQuery(); + query.setTaskDefKey(node.getUserTask().getId()); + query.setProcessInsId(hisTask.getProcessInstanceId()); + Result result = processLogService.projectProcessLogPage(query); + List<ProcessLogVO> logList = (List<ProcessLogVO>) result.get("data"); + DoFormDetailVO vo = new DoFormDetailVO(); + BeanUtils.copyProperties(node, vo); + if (CollectionUtils.isNotEmpty(logList)) { + vo.setEvents(logList); + } + return vo; + }).collect(Collectors.toList()); + return AjaxResult.success(vos); } else { parameters = taskService.getVariables(taskId); List<FormDetailVO> beforeNodes = this.getBeforeNodeForm(parameters, task.getFormKey(), task.getName(), task.getProcessDefinitionId(), task.getTaskDefinitionKey(), Boolean.TRUE); - return AjaxResult.success(beforeNodes); + List<FormDetailVO> dataList = new ArrayList<>(2); + Map<String, List<FormDetailVO>> map = new HashMap<>(2); + beforeNodes.stream().forEach(node -> { + if (node.getCurrent()) { + dataList.add(node); + } else { + List<HistoricTaskInstance> beforeTasks = historyService.createHistoricTaskInstanceQuery() + .processInstanceId(task.getProcessInstanceId()) + .finished() + .taskDefinitionKey(node.getBeforeNodeDefId()) + .orderByTaskCreateTime() + .desc() + .list(); + if (CollectionUtils.isNotEmpty(beforeTasks) && Objects.nonNull(beforeTasks.get(0))) { + List<FormDetailVO> l = map.get(beforeTasks.get(0)); + if (CollectionUtils.isEmpty(l)) { + map.put(beforeTasks.get(0).getExecutionId(), Arrays.asList(node)); + } else { + l.add(node); + } + } + } + }); + for (String key : map.keySet()) { + if (StringUtils.isNotBlank(key)) { + // 鍚屼竴鎵ц鍣ㄤ笂鍙彇鏈�杩戠殑涓�涓� + dataList.add(map.get(key).get(0)); + } + } + List<DoFormDetailVO> vos = dataList.stream().map(node -> { + if (node.getCurrent()) { + if (processLogService.taskIsHangup(taskId, task.getProcessInstanceId())) { + node.setTaskStatus(TaskStatusEnum.HANGUP); + } + } + // 鍒ゆ柇浠诲姟鏄惁瀛樺湪鐗规畩鎿嶄綔(濡傝烦杩囥�佽浆鍔炵瓑)锛岄渶瑕佸湪鍓嶇灞曠ず鍑烘潵 + ProcessLogQuery query = new ProcessLogQuery(); + query.setTaskDefKey(node.getUserTask().getId()); + query.setProcessInsId(task.getProcessInstanceId()); + Result result = processLogService.projectProcessLogPage(query); + List<ProcessLogVO> logList = (List<ProcessLogVO>) result.get("data"); + DoFormDetailVO vo = new DoFormDetailVO(); + BeanUtils.copyProperties(node, vo); + if (CollectionUtils.isNotEmpty(logList)) { + vo.setEvents(logList); + } + return vo; + }).collect(Collectors.toList()); + return AjaxResult.success(vos); } } -- Gitblit v1.8.0