From 571ec3d3aef0ab51cc4e95f816082fbe0dc68456 Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期二, 08 四月 2025 18:11:09 +0800 Subject: [PATCH] 修改任务彻底实现,查询表单数据不使用任务上的流程变量,单独去查流程变量 --- business/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java | 608 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 512 insertions(+), 96 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 8c3ec5f..a891ed1 100644 --- a/business/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java +++ b/business/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java @@ -6,7 +6,9 @@ import com.alibaba.fastjson2.TypeReference; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper; 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; @@ -26,11 +28,10 @@ import com.ycl.domain.entity.ProcessLog; import com.ycl.domain.entity.ProjectProcess; import com.ycl.domain.entity.SysForm; +import com.ycl.domain.form.EditFinishedTaskForm; import com.ycl.domain.json.RejectData; -import com.ycl.domain.vo.DoFormDetailVO; -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; @@ -53,6 +54,7 @@ import org.flowable.bpmn.model.*; import org.flowable.common.engine.api.FlowableException; import org.flowable.common.engine.api.FlowableObjectNotFoundException; +import org.flowable.common.engine.impl.persistence.StrongUuidGenerator; import org.flowable.engine.ProcessEngineConfiguration; import org.flowable.engine.history.HistoricActivityInstance; import org.flowable.engine.history.HistoricProcessInstance; @@ -75,9 +77,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.io.InputStream; +import java.io.*; import java.lang.reflect.Field; -import java.math.BigDecimal; import java.nio.charset.StandardCharsets; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -138,11 +139,12 @@ * * @param taskId 浠诲姟id * @param variables 琛ㄥ崟鏁版嵁 + * @param addLog * @return */ @Override @Transactional(rollbackFor = Exception.class) - public AjaxResult completeSubmitForm(String taskId, Map<String, Object> variables) { + public AjaxResult completeSubmitForm(String taskId, Map<String, Object> variables, Boolean addLog) { Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); if (Objects.isNull(task)) { return AjaxResult.error("浠诲姟涓嶅瓨鍦�"); @@ -155,28 +157,18 @@ 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)) { - if ("money".equals(key)) { - // 涓囧厓杞厓 - Object w = variables.get(key); - BigDecimal y = new BigDecimal(w.toString()).multiply(new BigDecimal(10000)); - processVariables.put(key, y); - } else { - 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); @@ -184,6 +176,123 @@ // 鍏堣褰撳墠鐢ㄦ埛璁ら杩欎釜浠诲姟 taskService.claim(taskId, SecurityUtils.getUserId() + ""); taskService.complete(taskId, newV); + } + // 淇濆瓨鏃ュ織 + if (addLog) { + publisher.publishEvent(new TaskLogEvent(this, null, + SecurityUtils.getUserId(), + projectProcess.getProjectId(), + projectProcess.getProcessInsId(), + taskId, + task.getTaskDefinitionKey(), + task.getName(), + ProcessLogEventTypeEnum.FINISHED, + null)); + } + return AjaxResult.success("鎻愪氦鎴愬姛"); + } + + + /** + * 瀹圭己琛ヤ氦 + * + * @param taskId 浠诲姟id + * @param variables 琛ㄥ崟鏁版嵁 + * @param addLog + * @return + */ + @Override + @Transactional(rollbackFor = Exception.class) + public AjaxResult waitCompleteSubmitForm(String taskId, Map<String, Object> variables, Boolean addLog) throws IOException { + List<HistoricTaskInstance> hisTasks = historyService.createHistoricTaskInstanceQuery().taskId(taskId).orderByHistoricTaskInstanceStartTime().desc().list(); + if (CollectionUtils.isEmpty(hisTasks) || Objects.isNull(hisTasks.get(0))) { + return AjaxResult.error("浠诲姟涓嶅瓨鍦�"); + } + HistoricTaskInstance task = hisTasks.get(0); + ProjectProcess projectProcess = new LambdaQueryChainWrapper<>(projectProcessMapper) + .eq(ProjectProcess::getProcessInsId, task.getProcessInstanceId()) + .eq(ProjectProcess::getProcessDefId, task.getProcessDefinitionId()) + .one(); + if (Objects.isNull(projectProcess)) { + return AjaxResult.error("椤圭洰娴佺▼鏈粦瀹�"); + } + // 鏌ュ嚭瀛楀吀涓渶瑕佹敞鍏ョ殑瀛楁淇℃伅 + 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)) { + newV.put(key,variables.get(key)); + } + } + } + ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult(); + Date now = new Date(); + for (String key : newV.keySet()) { + FlowableVarVO var = null; + if (Objects.isNull(processInstance)) { + // 鏌ヨ鍘嗗彶娴佺▼鍙橀噺 + var = projectProcessMapper.getHisByteId(projectProcess.getProcessInsId(), key); + } else { + // 鏌ヨ杩愯鏃舵祦绋嬪彉閲� + var = projectProcessMapper.getRuByteId(projectProcess.getProcessInsId(), key); + } + + if (Objects.isNull(var)) { + // 娌℃湁杩欎釜鍙橀噺鏂板鍗冲彲 + FlowableVarVO run = new FlowableVarVO(); + FlowableVarVO v = new FlowableVarVO(); + v.setNAME_(key); + v.setPROC_INST_ID_(task.getProcessInstanceId()); + v.setEXECUTION_ID_(task.getProcessInstanceId()); + v.setCREATE_TIME_(now); + v.setLAST_UPDATED_TIME_(now); + v.setID_(new StrongUuidGenerator().getNextId()); + + BeanUtils.copyProperties(v, run); + run.setID_(new StrongUuidGenerator().getNextId()); + if (newV.get(key) instanceof String) { + v.setVAR_TYPE_("string"); + v.setTEXT_((String) newV.get(key)); + run.setVAR_TYPE_("string"); + run.setTEXT_((String) newV.get(key)); + } else if (newV.get(key) instanceof Integer) { + v.setVAR_TYPE_("integer"); + v.setLONG_((Long) newV.get(key)); + v.setTEXT_((String) newV.get(key)); + run.setVAR_TYPE_("integer"); + run.setLONG_((Long) newV.get(key)); + run.setTEXT_((String) newV.get(key)); + } else if (newV.get(key) instanceof Long) { + v.setVAR_TYPE_("long"); + v.setLONG_((Long) newV.get(key)); + v.setTEXT_((String) newV.get(key)); + run.setVAR_TYPE_("long"); + run.setLONG_((Long) newV.get(key)); + run.setTEXT_((String) newV.get(key)); + } else if (newV.get(key) instanceof Boolean) { + v.setVAR_TYPE_("boolean"); + v.setLONG_((Long) newV.get(key)); + v.setTEXT_((String) newV.get(key)); + run.setVAR_TYPE_("boolean"); + run.setLONG_((Long) newV.get(key)); + run.setTEXT_((String) newV.get(key)); + } else { + // 鍏跺畠绫诲瀷鐨勮〃鍗曟暟鎹細濡傚浘鐗囥�佹枃浠跺崟鐙瓨琛ㄧ殑銆傚巻鍙层�佽繍琛屼腑鐨勬祦绋嬮渶鍚勫瓨涓�浠� + v.setVAR_TYPE_("serializable"); + v.setBYTEARRAY_ID_(new StrongUuidGenerator().getNextId()); + projectProcessMapper.insertByteArray(v.getBYTEARRAY_ID_(), 1, "hist.var-" + key, newV.get(key)); + + run.setVAR_TYPE_("serializable"); + run.setBYTEARRAY_ID_(new StrongUuidGenerator().getNextId()); + projectProcessMapper.insertByteArray(run.getBYTEARRAY_ID_(), 1, "var-" + key, newV.get(key)); + } + + projectProcessMapper.insertHisFlowableVar(v); + projectProcessMapper.insertRunFlowableVar(run); + } } // 淇濆瓨鏃ュ織 publisher.publishEvent(new TaskLogEvent(this, null, @@ -195,7 +304,21 @@ task.getName(), ProcessLogEventTypeEnum.FINISHED, null)); + return AjaxResult.success("鎻愪氦鎴愬姛"); + } + + // 灏嗗璞¤浆鎹负 byte[] + public static byte[] objectToBytes(Object obj) throws IOException { + if (Objects.isNull(obj)) { + return null; + } + try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos)) { + oos.writeObject(obj); // 搴忓垪鍖栧璞� + oos.flush(); + return bos.toByteArray(); // 杩斿洖瀛楄妭鏁扮粍 + } } /** @@ -209,8 +332,18 @@ if (taskService.createTaskQuery().taskId(flowTaskVo.getTaskId()).singleResult().isSuspended()) { throw new CustomException("浠诲姟澶勪簬鎸傝捣鐘舵��!"); } + // 褰撳墠浠诲姟 task Task task = taskService.createTaskQuery().taskId(flowTaskVo.getTaskId()).singleResult(); + + ProjectProcess projectProcess = new LambdaQueryChainWrapper<>(projectProcessMapper) + .eq(ProjectProcess::getProcessInsId, task.getProcessInstanceId()) + .eq(ProjectProcess::getProcessDefId, task.getProcessDefinitionId()) + .one(); + if (Objects.isNull(projectProcess)) { + throw new CustomException("椤圭洰娴佺▼鏈粦瀹�"); + } + // 鑾峰彇娴佺▼瀹氫箟淇℃伅 ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(task.getProcessDefinitionId()).singleResult(); // 鑾峰彇鎵�鏈夎妭鐐逛俊鎭� @@ -303,6 +436,21 @@ try { // 濡傛灉鐖剁骇浠诲姟澶氫簬 1 涓紝璇存槑褰撳墠鑺傜偣涓嶆槸骞惰鑺傜偣锛屽師鍥犱负涓嶈�冭檻澶氬澶氭儏鍐� if (targetIds.size() > 1) { + // 鍒犻櫎琚┏鍥炰换鍔$殑鎵�鏈夋棩蹇� + for (String targetId : targetIds) { + List<HistoricTaskInstance> rejectHisTaskList = historyService.createHistoricTaskInstanceQuery() + .taskDefinitionKey(targetId) + .processInstanceId(projectProcess.getProcessInsId()) + .orderByHistoricTaskInstanceStartTime() + .desc() + .list(); + if (CollectionUtils.isNotEmpty(rejectHisTaskList)) { + new LambdaUpdateChainWrapper<>(processLogService.getBaseMapper()) + .eq(ProcessLog::getTaskId, rejectHisTaskList.get(0).getId()) + .eq(ProcessLog::getProcessInsId, projectProcess.getProcessInsId()) + .remove(); + } + } // 1 瀵� 澶氫换鍔¤烦杞紝currentIds 褰撳墠鑺傜偣(1)锛宼argetIds 璺宠浆鍒扮殑鑺傜偣(澶�) runtimeService.createChangeActivityStateBuilder() .processInstanceId(task.getProcessInstanceId()). @@ -310,22 +458,30 @@ } // 濡傛灉鐖剁骇浠诲姟鍙湁涓�涓紝鍥犳褰撳墠浠诲姟鍙兘涓虹綉鍏充腑鐨勪换鍔� if (targetIds.size() == 1) { + // 鍒犻櫎琚┏鍥炰换鍔$殑鎵�鏈夋棩蹇� + List<HistoricTaskInstance> rejectHisTaskList = historyService.createHistoricTaskInstanceQuery() + .taskDefinitionKey(targetIds.get(0)) + .processInstanceId(projectProcess.getProcessInsId()) + .orderByHistoricTaskInstanceStartTime() + .desc() + .list(); + if (CollectionUtils.isNotEmpty(rejectHisTaskList)) { + new LambdaUpdateChainWrapper<>(processLogService.getBaseMapper()) + .eq(ProcessLog::getTaskId, rejectHisTaskList.get(0).getId()) + .eq(ProcessLog::getProcessInsId, projectProcess.getProcessInsId()) + .remove(); + } + // 1 瀵� 1 鎴� 澶� 瀵� 1 鎯呭喌锛宑urrentIds 褰撳墠瑕佽烦杞殑鑺傜偣鍒楄〃(1鎴栧)锛宼argetIds.get(0) 璺宠浆鍒扮殑鑺傜偣(1) runtimeService.createChangeActivityStateBuilder() .processInstanceId(task.getProcessInstanceId()) .moveActivityIdsToSingleActivityId(currentIds, targetIds.get(0)).changeState(); } + historyService.deleteHistoricTaskInstance(flowTaskVo.getTaskId()); } catch (FlowableObjectNotFoundException e) { throw new CustomException("鏈壘鍒版祦绋嬪疄渚嬶紝娴佺▼鍙兘宸插彂鐢熷彉鍖�"); } catch (FlowableException e) { throw new CustomException("鏃犳硶鍙栨秷鎴栧紑濮嬫椿鍔�"); - } - ProjectProcess projectProcess = new LambdaQueryChainWrapper<>(projectProcessMapper) - .eq(ProjectProcess::getProcessInsId, task.getProcessInstanceId()) - .eq(ProjectProcess::getProcessDefId, task.getProcessDefinitionId()) - .one(); - if (Objects.isNull(projectProcess)) { - throw new CustomException("椤圭洰娴佺▼鏈粦瀹�"); } // 淇濆瓨鏃ュ織 publisher.publishEvent(new TaskLogEvent(this, null, @@ -858,17 +1014,17 @@ public AjaxResult flowRecord(String procInsId) { Map<String, Object> map = new HashMap<String, Object>(); if (StringUtils.isNotBlank(procInsId)) { - List<HistoricActivityInstance> list = historyService - .createHistoricActivityInstanceQuery() + List<HistoricTaskInstance> list = historyService + .createHistoricTaskInstanceQuery() .processInstanceId(procInsId) - .orderByHistoricActivityInstanceStartTime() + .orderByHistoricTaskInstanceStartTime() .desc().list(); //鎵╁睍 鑾峰彇杩欎釜娴佺▼瀹炰緥鐨勭洃鎺т俊鎭� key:TaskId value:瀹炰綋绫� Map<String, ProcessCoding> processCodingMap = processCodingMapper.selectList(new QueryWrapper<ProcessCoding>().eq("process_ins_id", procInsId)) .stream() .collect(Collectors.toMap(ProcessCoding::getTaskId, Function.identity())); List<FlowTaskDto> hisFlowList = new ArrayList<>(); - for (HistoricActivityInstance histIns : list) { + for (HistoricTaskInstance histIns : list) { // 灞曠ず寮�濮嬭妭鐐� // if ("startEvent".equals(histIns.getActivityType())) { // FlowTaskDto flowTask = new FlowTaskDto(); @@ -886,10 +1042,10 @@ // flowTask.setFinishTime(histIns.getEndTime()); // hisFlowList.add(flowTask); // } else - if (StringUtils.isNotBlank(histIns.getTaskId())) { + if (StringUtils.isNotBlank(histIns.getId())) { FlowTaskDto flowTask = new FlowTaskDto(); - flowTask.setTaskId(histIns.getTaskId()); - flowTask.setTaskName(histIns.getActivityName()); + flowTask.setTaskId(histIns.getId()); + flowTask.setTaskName(histIns.getName()); flowTask.setCreateTime(histIns.getStartTime()); flowTask.setFinishTime(histIns.getEndTime()); if (StringUtils.isNotBlank(histIns.getAssignee())) { @@ -899,7 +1055,7 @@ flowTask.setDeptName(Objects.nonNull(sysUser.getDept()) ? sysUser.getDept().getDeptName() : ""); } // 灞曠ず瀹℃壒浜哄憳 - List<HistoricIdentityLink> linksForTask = historyService.getHistoricIdentityLinksForTask(histIns.getTaskId()); + List<HistoricIdentityLink> linksForTask = historyService.getHistoricIdentityLinksForTask(histIns.getId()); StringBuilder stringBuilder = new StringBuilder(); for (HistoricIdentityLink identityLink : linksForTask) { // 鑾烽�変汉,鍊欓�夌粍/瑙掕壊(澶氫釜) @@ -926,7 +1082,7 @@ flowTask.setDuration(histIns.getDurationInMillis() == null || histIns.getDurationInMillis() == 0 ? null : getDate(histIns.getDurationInMillis())); //鎵╁睍 鍒ゆ柇鏄惁瓒呮椂 - ProcessCoding processCoding = processCodingMap.get(histIns.getTaskId()); + ProcessCoding processCoding = processCodingMap.get(histIns.getId()); if (processCoding != null) { //閫氳繃鑰楁椂鍒ゆ柇鏄惁鏄唬鍔炶妭鐐� //濡傛灉浠诲姟鏄唬鍔炶妭鐐� @@ -945,7 +1101,7 @@ // 鑾峰彇鎰忚璇勮鍐呭 List<Comment> commentList = taskService.getProcessInstanceComments(histIns.getProcessInstanceId()); commentList.forEach(comment -> { - if (histIns.getTaskId().equals(comment.getTaskId())) { + if (histIns.getId().equals(comment.getTaskId())) { flowTask.setComment(FlowCommentDto.builder().type(comment.getType()).comment(comment.getFullMessage()).build()); } }); @@ -1194,6 +1350,7 @@ .processInstanceId(procInsId) .finished() .list(); + listFinished = this.distinctHisActivity(listFinished); //鎵╁睍 鑾峰彇杩欎釜娴佺▼瀹炰緥鐨勭洃鎺т俊鎭� key:TaskId value:瀹炰綋绫� Map<String, ProcessCoding> processCodingMap = new LambdaQueryChainWrapper<>(processCodingMapper) @@ -1216,6 +1373,8 @@ if (StringUtils.isBlank(s.getDeleteReason())) { flowViewerList.add(flowViewerDto); } + flowViewerDto.setHasJump(processLogService.taskIsJump(s.getTaskId(), procInsId)); + flowViewerDto.setHasWait(processLogService.taskIsWait(s.getTaskId(), procInsId)); }); // 鑾峰彇浠e姙鑺傜偣 @@ -1233,8 +1392,10 @@ // 鎵╁睍鍐呭 浠e姙鐨勯�氳繃褰撳墠鏃堕棿浣滀负endTime ProcessCoding processCoding = processCodingMap.get(s.getTaskId()); //濡傛灉鏈夌洃鎺ф暟鎹� 涓嶅弽鐨勮瘽鍓嶇榛樿鏄繘琛屼腑(钃濊壊) - if (processCoding != null && (RED.equals(processCoding.getStatus()) || YELLOW.equals(processCoding.getStatus()))) { - flowViewerDto.setOvertime(processCoding.getStatus()); + if (Objects.nonNull(processCoding)) { + if (RED.equals(processCoding.getStatus()) || YELLOW.equals(processCoding.getStatus())) { + flowViewerDto.setOvertime(processCoding.getStatus()); + } } flowViewerList.add(flowViewerDto); }); @@ -1253,6 +1414,99 @@ } /** + * 鏍规嵁浠诲姟key鍘婚噸鍘嗗彶浠诲姟锛岀浉鍚屾儏鍐典笅鍙栨渶鏂扮殑涓�鏉� + * + * @param hisTaskList + * @return + */ + private List<HistoricActivityInstance> distinctHisActivity(List<HistoricActivityInstance> hisTaskList) { + Map<String, HistoricActivityInstance> uniqueTasks = new HashMap<>(); + for (HistoricActivityInstance task : hisTaskList) { + String taskDefinitionKey = task.getActivityId(); + HistoricActivityInstance existingTask = uniqueTasks.get(taskDefinitionKey); + + // 濡傛灉浠诲姟key閲嶅锛堝彲鑳借椹冲洖杩囷紝閲嶆柊鎻愪氦瀵艰嚧key閲嶅锛夛紝鍙栨渶杩戠殑涓�鏉� + if (existingTask == null || task.getStartTime().after(existingTask.getStartTime())) { + uniqueTasks.put(taskDefinitionKey, task); + } + } + // 鏈�缁堝幓閲嶅悗鐨勪换鍔″垪琛� + return new ArrayList<>(uniqueTasks.values()); + } + + /** + * 鏌ヨ褰撳墠浠诲姟鐨勮〃鍗曟暟鎹� + * + * @param taskId + * @return + * @throws Exception + */ + @Override + public AjaxResult currentFlowTaskForm(String taskId) { + // 娴佺▼鍙橀噺 + List<HistoricTaskInstance> hisTaskList = historyService.createHistoricTaskInstanceQuery() + .finished() + .taskId(taskId) + .orderByHistoricTaskInstanceStartTime() + .desc() + .list(); + if (CollectionUtils.isEmpty(hisTaskList) || Objects.isNull(hisTaskList.get(0))) { + return AjaxResult.error("鏈壘鍒拌浠诲姟淇℃伅"); + } + HistoricTaskInstance historicTaskInstance = hisTaskList.get(0); + ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables().processInstanceId(historicTaskInstance.getProcessInstanceId()).singleResult(); + Map<String, Object> parameters = new HashMap<>(); + if (Objects.nonNull(processInstance)) { + parameters = processInstance.getProcessVariables(); + } else { + // 濡傛灉涓虹┖锛岃〃鏄庢祦绋嬪凡缁忕粨鏉� + HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().processInstanceId(historicTaskInstance.getProcessInstanceId()).singleResult(); + if (Objects.isNull(historicProcessInstance)) { + throw new RuntimeException("娴佺▼涓嶅瓨鍦�"); + } + parameters = historicProcessInstance.getProcessVariables(); + } + + String processInsId = historicTaskInstance.getProcessInstanceId(); + List<FormDetailVO> beforeNodes = this.getBeforeNodeForm(parameters, + historicTaskInstance.getFormKey(), + historicTaskInstance.getName(), + historicTaskInstance.getProcessDefinitionId(), + historicTaskInstance.getTaskDefinitionKey(), + Boolean.TRUE, Boolean.FALSE); + + + String finalProcessInsId = processInsId; + List<DoFormDetailVO> vos = beforeNodes.stream() + .filter(FormDetailVO::getCurrent) + .map(node -> { + // 鍒ゆ柇浠诲姟鏄惁瀛樺湪鐗规畩鎿嶄綔(濡傝烦杩囥�佽浆鍔炵瓑)锛岄渶瑕佸湪鍓嶇灞曠ず鍑烘潵 + ProcessLogQuery query = new ProcessLogQuery(); + query.setTaskId(taskId); + query.setProcessInsId(finalProcessInsId); + Result result = processLogService.projectProcessLogList(query); + List<ProcessLogVO> logList = (List<ProcessLogVO>) result.get("data"); + DoFormDetailVO vo = new DoFormDetailVO(); + BeanUtils.copyProperties(node, vo); + if (CollectionUtils.isNotEmpty(logList)) { + vo.setEvents(logList); + } + // 鏍规嵁鏃ュ織鍒ゆ柇褰撳墠浠诲姟鐨勭姸鎬� + if (logList.stream().anyMatch(log -> ProcessLogEventTypeEnum.FINISHED.equals(log.getEventType()))) { + vo.setTaskStatus(TaskStatusEnum.FINISHED); + } else if (logList.stream().anyMatch(log -> ProcessLogEventTypeEnum.JUMP.equals(log.getEventType()))) { + vo.setTaskStatus(TaskStatusEnum.JUMP); + } else if (processLogService.taskIsWait(taskId, processInsId)) { + vo.setTaskStatus(TaskStatusEnum.WAIT); + } else if (processLogService.taskIsHangup(taskId, processInsId)) { + vo.setTaskStatus(TaskStatusEnum.HANGUP); + } + return vo; + }).collect(Collectors.toList()); + return AjaxResult.success(vos.get(0)); + } + + /** * 娴佺▼鑺傜偣琛ㄥ崟 * * @param taskId 娴佺▼浠诲姟缂栧彿 @@ -1261,42 +1515,101 @@ @Override public AjaxResult flowTaskForm(String taskId) throws Exception { Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); - // 娴佺▼鍙橀噺 - Map<String, Object> parameters = new HashMap<>(); - List<FormDetailVO> beforeNodes = new ArrayList<>(); + // 1. 鑾峰彇鍒板彉閲忎俊鎭紝鍥犱负浠诲姟鍙兘鏄繍琛屼腑鐨勪篃鍙兘鏄巻鍙蹭换鍔� 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); + String processDefId = ""; + String formKey = ""; + String taskName = ""; + String taskDefKey = ""; + if (Objects.isNull(task)) { + List<HistoricTaskInstance> hisTaskList = historyService.createHistoricTaskInstanceQuery() + .finished() + .taskId(taskId) + .orderByHistoricTaskInstanceStartTime() + .desc() + .list(); + if (CollectionUtils.isEmpty(hisTaskList) || Objects.isNull(hisTaskList.get(0))) { + return AjaxResult.error("浠诲姟涓嶅瓨鍦�"); + } + HistoricTaskInstance hisTask = hisTaskList.get(0); + processInsId = hisTask.getProcessInstanceId(); + processDefId = hisTask.getProcessDefinitionId(); + formKey = hisTask.getFormKey(); + taskName = hisTask.getName(); + taskDefKey = hisTask.getTaskDefinitionKey(); } else { - parameters = taskService.getVariables(taskId); processInsId = task.getProcessInstanceId(); - beforeNodes = this.getBeforeNodeForm(parameters, task.getFormKey(), task.getName(), task.getProcessDefinitionId(), task.getTaskDefinitionKey(), Boolean.FALSE); + processDefId = task.getProcessDefinitionId(); + formKey = task.getFormKey(); + taskName = task.getName(); + taskDefKey = task.getTaskDefinitionKey(); } + // 2. 鑾峰彇娴佺▼鍙橀噺 + ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables().processInstanceId(processInsId).singleResult(); + Map<String, Object> parameters = new HashMap<>(); + if (Objects.nonNull(processInstance)) { + parameters = processInstance.getProcessVariables(); + } else { + // 濡傛灉涓虹┖锛岃〃鏄庢祦绋嬪凡缁忕粨鏉� + HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().processInstanceId(processInsId).singleResult(); + if (Objects.isNull(historicProcessInstance)) { + throw new RuntimeException("娴佺▼涓嶅瓨鍦�"); + } + parameters = historicProcessInstance.getProcessVariables(); + } + List<FormDetailVO> beforeNodes = new ArrayList<>(); + beforeNodes = this.getBeforeNodeForm(parameters, + formKey, + taskName, + processDefId, + taskDefKey, + Boolean.TRUE, Boolean.TRUE); // 鍒ゆ柇鍓嶇疆浠诲姟鏄笉鏄拰褰撳墠浠诲姟涓哄悓涓�涓猠xecuteId // 鍒ゆ柇褰撳墠浠诲姟鏄惁琚寕璧蜂腑 String finalProcessInsId = processInsId; - beforeNodes = beforeNodes.stream().filter(node -> { + List<FormDetailVO> dataList = new ArrayList<>(2); + Map<String, List<FormDetailVO>> map = new HashMap<>(2); + beforeNodes.stream().forEach(node -> { if (node.getCurrent()) { - return Boolean.TRUE; + node.setTaskId(taskId); + 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))) { + node.setTaskId(beforeTasks.get(0).getId()); + 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); + } + } } - HistoricTaskInstance beforeTask = historyService.createHistoricTaskInstanceQuery().processInstanceId(finalProcessInsId).finished().taskDefinitionKey(node.getBeforeNodeDefId()).singleResult(); - return Objects.nonNull(beforeTask); - }).collect(Collectors.toList()); - List<DoFormDetailVO> vos = beforeNodes.stream().map(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); } } // 鍒ゆ柇浠诲姟鏄惁瀛樺湪鐗规畩鎿嶄綔(濡傝烦杩囥�佽浆鍔炵瓑)锛岄渶瑕佸湪鍓嶇灞曠ず鍑烘潵 - List<ProcessLog> logList = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper()) - .eq(ProcessLog::getTaskDefKey, node.getBeforeNodeDefId()) - .eq(ProcessLog::getProcessInsId, finalProcessInsId) - .orderByDesc(ProcessLog::getGmtCreate) - .list(); + ProcessLogQuery query = new ProcessLogQuery(); + query.setTaskId(node.getTaskId()); + query.setProcessInsId(finalProcessInsId); + Result result = processLogService.projectProcessLogList(query); + List<ProcessLogVO> logList = (List<ProcessLogVO>) result.get("data"); DoFormDetailVO vo = new DoFormDetailVO(); BeanUtils.copyProperties(node, vo); if (CollectionUtils.isNotEmpty(logList)) { @@ -1308,25 +1621,67 @@ } @Override - public AjaxResult detail(String taskId) { - Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); + public AjaxResult detail(String processInsId, String taskId) { + ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().includeProcessVariables().processInstanceId(processInsId).singleResult(); // 娴佺▼鍙橀噺 Map<String, Object> parameters = new HashMap<>(); - if (Objects.isNull(task)) { - // 濡傛灉涓虹┖锛屽彲鑳芥槸浠诲姟宸茬粡缁撴潫 - HistoricTaskInstance hisTask = historyService.createHistoricTaskInstanceQuery().taskId(taskId).includeProcessVariables().singleResult(); - if (Objects.isNull(hisTask)) { + if (Objects.isNull(processInstance)) { + + // 濡傛灉涓虹┖锛岃〃鏄庢祦绋嬪凡缁忕粨鏉� + HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().includeProcessVariables().processInstanceId(processInsId).singleResult(); + if (Objects.isNull(historicProcessInstance)) { + throw new RuntimeException("娴佺▼涓嶅瓨鍦�"); + } + + List<HistoricTaskInstance> hisTasks = historyService.createHistoricTaskInstanceQuery() + .taskId(taskId) + .finished() + .includeProcessVariables() + .orderByHistoricTaskInstanceStartTime() + .desc() + .list(); + if (CollectionUtils.isNotEmpty(hisTasks) && Objects.isNull(hisTasks.get(0))) { throw new RuntimeException("璇ヤ换鍔′笉瀛樺湪"); } - parameters = hisTask.getProcessVariables(); - List<FormDetailVO> beforeNodes = this.getBeforeNodeForm(parameters, hisTask.getFormKey(), hisTask.getName(), hisTask.getProcessDefinitionId(), hisTask.getTaskDefinitionKey(), Boolean.TRUE); - List<FormDetailVO> dataList = beforeNodes.stream().filter(node -> { + HistoricTaskInstance hisTask = hisTasks.get(0); + parameters = historicProcessInstance.getProcessVariables(); + List<FormDetailVO> beforeNodes = this.getBeforeNodeForm(parameters, + hisTask.getFormKey(), + hisTask.getName(), + hisTask.getProcessDefinitionId(), + hisTask.getTaskDefinitionKey(), + Boolean.TRUE, Boolean.TRUE); + List<FormDetailVO> dataList = new ArrayList<>(2); + Map<String, List<FormDetailVO>> map = new HashMap<>(2); + beforeNodes.stream().forEach(node -> { if (node.getCurrent()) { - return Boolean.TRUE; + node.setTaskId(taskId); + 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))) { + node.setTaskId(beforeTasks.get(0).getId()); + 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); + } + } } - HistoricTaskInstance beforeTask = historyService.createHistoricTaskInstanceQuery().processInstanceId(hisTask.getProcessInstanceId()).finished().taskDefinitionKey(node.getBeforeNodeDefId()).singleResult(); - return Objects.nonNull(beforeTask); - }).collect(Collectors.toList()); + }); + 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())) { @@ -1334,11 +1689,11 @@ } } // 鍒ゆ柇浠诲姟鏄惁瀛樺湪鐗规畩鎿嶄綔(濡傝烦杩囥�佽浆鍔炵瓑)锛岄渶瑕佸湪鍓嶇灞曠ず鍑烘潵 - List<ProcessLog> logList = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper()) - .eq(ProcessLog::getTaskId, hisTask.getId()) - .eq(ProcessLog::getProcessInsId, hisTask.getProcessInstanceId()) - .orderByDesc(ProcessLog::getGmtCreate) - .list(); + ProcessLogQuery query = new ProcessLogQuery(); + query.setTaskId(node.getTaskId()); + query.setProcessInsId(hisTask.getProcessInstanceId()); + Result result = processLogService.projectProcessLogList(query); + List<ProcessLogVO> logList = (List<ProcessLogVO>) result.get("data"); DoFormDetailVO vo = new DoFormDetailVO(); BeanUtils.copyProperties(node, vo); if (CollectionUtils.isNotEmpty(logList)) { @@ -1348,27 +1703,78 @@ }).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); - List<FormDetailVO> dataList = beforeNodes.stream().filter(node -> { - if (node.getCurrent()) { - return Boolean.TRUE; + parameters = processInstance.getProcessVariables(); + Task task = taskService.createTaskQuery().taskId(taskId).processInstanceId(processInsId).singleResult(); + List<FormDetailVO> beforeNodes = new ArrayList<>(); + if (Objects.nonNull(task)) { + beforeNodes = this.getBeforeNodeForm(parameters, + task.getFormKey(), + task.getName(), + task.getProcessDefinitionId(), + task.getTaskDefinitionKey(), + Boolean.TRUE, Boolean.TRUE); + } else { + List<HistoricTaskInstance> hisTasks = historyService.createHistoricTaskInstanceQuery() + .taskId(taskId) + .finished() + .includeProcessVariables() + .orderByHistoricTaskInstanceStartTime() + .desc() + .list(); + if (CollectionUtils.isNotEmpty(hisTasks) && Objects.isNull(hisTasks.get(0))) { + throw new RuntimeException("璇ヤ换鍔′笉瀛樺湪"); } - HistoricTaskInstance beforeTask = historyService.createHistoricTaskInstanceQuery().processInstanceId(task.getProcessInstanceId()).finished().taskDefinitionKey(node.getBeforeNodeDefId()).singleResult(); - return Objects.nonNull(beforeTask); - }).collect(Collectors.toList()); + HistoricTaskInstance hisTask = hisTasks.get(0); + beforeNodes = this.getBeforeNodeForm(parameters, + hisTask.getFormKey(), + hisTask.getName(), + hisTask.getProcessDefinitionId(), + hisTask.getTaskDefinitionKey(), + Boolean.TRUE, Boolean.TRUE); + } + List<FormDetailVO> dataList = new ArrayList<>(2); + Map<String, List<FormDetailVO>> map = new HashMap<>(2); + beforeNodes.stream().forEach(node -> { + if (node.getCurrent()) { + node.setTaskId(taskId); + dataList.add(node); + } else { + List<HistoricTaskInstance> beforeTasks = historyService.createHistoricTaskInstanceQuery() + .processInstanceId(processInsId) + .finished() + .taskDefinitionKey(node.getBeforeNodeDefId()) + .orderByTaskCreateTime() + .desc() + .list(); + if (CollectionUtils.isNotEmpty(beforeTasks) && Objects.nonNull(beforeTasks.get(0))) { + node.setTaskId(beforeTasks.get(0).getId()); + 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())) { + if (processLogService.taskIsHangup(taskId, processInsId)) { node.setTaskStatus(TaskStatusEnum.HANGUP); } } // 鍒ゆ柇浠诲姟鏄惁瀛樺湪鐗规畩鎿嶄綔(濡傝烦杩囥�佽浆鍔炵瓑)锛岄渶瑕佸湪鍓嶇灞曠ず鍑烘潵 - List<ProcessLog> logList = new LambdaQueryChainWrapper<>(processLogService.getBaseMapper()) - .eq(ProcessLog::getTaskId, task.getId()) - .eq(ProcessLog::getProcessInsId, task.getProcessInstanceId()) - .orderByDesc(ProcessLog::getGmtCreate) - .list(); + ProcessLogQuery query = new ProcessLogQuery(); + query.setTaskId(node.getTaskId()); + query.setProcessInsId(processInsId); + Result result = processLogService.projectProcessLogList(query); + List<ProcessLogVO> logList = (List<ProcessLogVO>) result.get("data"); DoFormDetailVO vo = new DoFormDetailVO(); BeanUtils.copyProperties(node, vo); if (CollectionUtils.isNotEmpty(logList)) { @@ -1388,9 +1794,16 @@ * @param taskName 浠诲姟 * @param processDefId 娴佺▼瀹氫箟id * @param processDefKey 娴佺▼瀹炰緥id + * @param disableInput 鏄惁绂佺敤宸茬粡鏈夊�肩殑杈撳叆椤� * @return */ - private List<FormDetailVO> getBeforeNodeForm(Map<String, Object> parameters, String formKey, String taskName, String processDefId, String processDefKey, Boolean currentNeedData) { + private List<FormDetailVO> getBeforeNodeForm(Map<String, Object> parameters, + String formKey, + String taskName, + String processDefId, + String processDefKey, + Boolean currentNeedData, + Boolean disableInput) { // 杩欓噷鍙渶瑕佹煡鑷韩浠ュ強涓婁竴涓妭鐐�(濡傛灉骞惰鐨勬湁澶氫釜)鐨勮〃鍗曟暟鎹� List<FormDetailVO> beforeNodes = taskCommonService.getBeforeNodeDefInfo(processDefId, processDefKey, sysFormService, Boolean.TRUE); @@ -1424,9 +1837,11 @@ if(CollectionUtils.isNotEmpty(oldFields)) { // 璁剧疆宸插~鍐欑殑琛ㄥ崟涓虹鐢ㄧ姸鎬� - for (JSONObject oldField : oldFields) { - JSONObject options = oldField.getJSONObject("options"); - options.put("disabled", true); + if (disableInput) { + for (JSONObject oldField : oldFields) { + JSONObject options = oldField.getJSONObject("options"); + options.put("disabled", true); + } } formJson.put(ProcessConstants.WIDGET_LIST, oldFields); newP.put(ProcessConstants.TASK_FORM_KEY, formJson); @@ -1457,6 +1872,7 @@ return beforeNodes; } + /** * 娴佺▼鑺傜偣淇℃伅 * -- Gitblit v1.8.0