From 74da9dfb5fb4085d8847d4c74a97048c6c677514 Mon Sep 17 00:00:00 2001 From: xiangpei <xiangpei@timesnew.cn> Date: 星期三, 15 一月 2025 10:53:34 +0800 Subject: [PATCH] 完成任务bug(协同办理的才resolveTask)、转办前如果是指定人员删除不掉问题、提取获取运行时任务信息的方法 --- flowable/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java | 258 ++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 210 insertions(+), 48 deletions(-) diff --git a/flowable/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java b/flowable/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java index d2d5a45..0b762c0 100644 --- a/flowable/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java +++ b/flowable/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java @@ -4,9 +4,12 @@ import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.TypeReference; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ycl.common.constant.ProcessConstants; import com.ycl.common.core.domain.AjaxResult; +import com.ycl.common.core.domain.entity.SysDept; +import com.ycl.common.core.domain.entity.SysDictData; import com.ycl.common.core.domain.entity.SysRole; import com.ycl.common.core.domain.entity.SysUser; import com.ycl.common.enums.FlowComment; @@ -16,18 +19,22 @@ import com.ycl.domain.dto.FlowNextDto; import com.ycl.domain.dto.FlowTaskDto; import com.ycl.domain.dto.FlowViewerDto; +import com.ycl.domain.entity.ProcessCoding; import com.ycl.domain.entity.SysForm; import com.ycl.domain.vo.FlowQueryVo; import com.ycl.domain.vo.FlowTaskVo; +import com.ycl.domain.vo.FormDetailVO; import com.ycl.factory.FlowServiceFactory; import com.ycl.flow.CustomProcessDiagramGenerator; import com.ycl.flow.FindNextNodeUtil; import com.ycl.flow.FlowableUtils; +import com.ycl.mapper.ProcessCodingMapper; +import com.ycl.service.FlowLogService; import com.ycl.service.IFlowTaskService; import com.ycl.service.ISysDeployFormService; import com.ycl.service.ISysFormService; -import com.ycl.system.service.ISysRoleService; -import com.ycl.system.service.ISysUserService; +import com.ycl.service.common.TaskCommonService; +import com.ycl.system.service.*; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; @@ -67,6 +74,9 @@ import java.util.function.Predicate; import java.util.stream.Collectors; +import static com.ycl.common.constant.ProcessOverTimeConstants.RED; +import static com.ycl.common.constant.ProcessOverTimeConstants.YELLOW; + /** * @author Tony * @date 2021-04-03 @@ -78,8 +88,13 @@ private final ISysUserService sysUserService; private final ISysRoleService sysRoleService; + private final ISysDeptService sysDeptService; + private final ISysDictTypeService sysDictDService; private final ISysDeployFormService sysInstanceFormService; private final ISysFormService sysFormService; + private final TaskCommonService taskCommonService; + private final ProcessCodingMapper processCodingMapper; + private final FlowLogService flowLogService; /** * 瀹屾垚瀹℃牳浠诲姟 @@ -108,8 +123,8 @@ /** * 瀹屾垚琛ㄥ崟鎻愪氦浠诲姟/鏅�氫换鍔� * - * @param taskId 浠诲姟id - * @param variables 琛ㄥ崟鏁版嵁 + * @param taskId 浠诲姟id + * @param variables 琛ㄥ崟鏁版嵁 * @return */ @Override @@ -119,10 +134,30 @@ if (Objects.isNull(task)) { return AjaxResult.error("浠诲姟涓嶅瓨鍦�"); } - // 鍏堣褰撳墠鐢ㄦ埛璁ら杩欎釜浠诲姟 - taskService.claim(taskId, SecurityUtils.getUserId() + ""); + + 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)); + } + } + } + //娣诲姞娴佺▼鍙橀噺 + if(!processVariables.isEmpty()) taskService.setVariables(taskId,processVariables); taskService.addComment(taskId, task.getProcessInstanceId(), FlowComment.SUBMIT.getType(), "瀹屾垚鎻愪氦"); - taskService.complete(taskId, variables); + if (DelegationState.PENDING.equals(task.getDelegationState())) { + taskService.resolveTask(taskId, newV); + } else { + // 鍏堣褰撳墠鐢ㄦ埛璁ら杩欎釜浠诲姟 + taskService.claim(taskId, SecurityUtils.getUserId() + ""); + taskService.complete(taskId, newV); + } return AjaxResult.success("鎻愪氦鎴愬姛"); } @@ -293,7 +328,6 @@ if (!isSequential) { throw new CustomException("褰撳墠鑺傜偣鐩稿浜庣洰鏍囪妭鐐癸紝涓嶅睘浜庝覆琛屽叧绯伙紝鏃犳硶鍥為��"); } - // 鑾峰彇鎵�鏈夋甯歌繘琛岀殑浠诲姟鑺傜偣 Key锛岃繖浜涗换鍔′笉鑳界洿鎺ヤ娇鐢紝闇�瑕佹壘鍑哄叾涓渶瑕佹挙鍥炵殑浠诲姟 List<Task> runTaskList = taskService.createTaskQuery().processInstanceId(task.getProcessInstanceId()).list(); @@ -775,6 +809,10 @@ .processInstanceId(procInsId) .orderByHistoricActivityInstanceStartTime() .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) { // 灞曠ず寮�濮嬭妭鐐� @@ -817,8 +855,14 @@ stringBuilder.append(sysUser.getNickName()).append(","); } if (StringUtils.isNotBlank(identityLink.getGroupId())) { - SysRole sysRole = sysRoleService.selectRoleById(Long.parseLong(identityLink.getGroupId())); - stringBuilder.append(sysRole.getRoleName()).append(","); + if (identityLink.getGroupId().contains("dept")) { + SysDept sysDept = sysDeptService.selectDeptById(Long.parseLong(identityLink.getGroupId().split(":")[1])); + stringBuilder.append(sysDept.getDeptName()).append(","); + } else { + SysRole sysRole = sysRoleService.selectRoleById(Long.parseLong(identityLink.getGroupId())); + stringBuilder.append(sysRole.getRoleName()).append(","); + } + } } } @@ -827,6 +871,23 @@ } flowTask.setDuration(histIns.getDurationInMillis() == null || histIns.getDurationInMillis() == 0 ? null : getDate(histIns.getDurationInMillis())); + //鎵╁睍 鍒ゆ柇鏄惁瓒呮椂 + ProcessCoding processCoding = processCodingMap.get(histIns.getTaskId()); + if (processCoding != null) { + //閫氳繃鑰楁椂鍒ゆ柇鏄惁鏄唬鍔炶妭鐐� + //濡傛灉浠诲姟鏄唬鍔炶妭鐐� + if (flowTask.getDuration() == null) { + if (RED.equals(processCoding.getStatus()) || YELLOW.equals(processCoding.getStatus())) { + flowTask.setOvertime(processCoding.getStatus()); + } + } else { + //濡傛灉浠诲姟鑺傜偣灞炰簬鍘嗗彶鑺傜偣 + if (RED.equals(processCoding.getStatus())) { + flowTask.setOvertime(processCoding.getStatus()); + } + ; + } + } // 鑾峰彇鎰忚璇勮鍐呭 List<Comment> commentList = taskService.getProcessInstanceComments(histIns.getProcessInstanceId()); commentList.forEach(comment -> { @@ -839,14 +900,14 @@ } map.put("flowList", hisFlowList); } - // 绗竴娆$敵璇疯幏鍙栧垵濮嬪寲琛ㄥ崟 - if (StringUtils.isNotBlank(deployId)) { - SysForm sysForm = sysInstanceFormService.selectSysDeployFormByDeployId(deployId); - if (Objects.isNull(sysForm)) { - return AjaxResult.error("璇峰厛閰嶇疆娴佺▼琛ㄥ崟"); - } - map.put("formData", JSONObject.parseObject(sysForm.getFormContent())); - } +// // 绗竴娆$敵璇疯幏鍙栧垵濮嬪寲琛ㄥ崟 +// if (StringUtils.isNotBlank(deployId)) { +// SysForm sysForm = sysInstanceFormService.selectSysDeployFormByDeployId(deployId); +// if (Objects.isNull(sysForm)) { +// return AjaxResult.error("璇峰厛閰嶇疆娴佺▼琛ㄥ崟"); +// } +// map.put("formData", JSONObject.parseObject(sysForm.getFormContent())); +// } return AjaxResult.success(map); } @@ -1072,6 +1133,7 @@ @Override public AjaxResult flowXmlAndNode(String procInsId, String deployId) { try { + List<FlowViewerDto> flowViewerList = new ArrayList<>(); // 鑾峰彇宸茬粡瀹屾垚鐨勮妭鐐� List<HistoricActivityInstance> listFinished = historyService.createHistoricActivityInstanceQuery() @@ -1079,11 +1141,22 @@ .finished() .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())); // 淇濆瓨宸茬粡瀹屾垚鐨勬祦绋嬭妭鐐圭紪鍙� listFinished.forEach(s -> { FlowViewerDto flowViewerDto = new FlowViewerDto(); flowViewerDto.setKey(s.getActivityId()); flowViewerDto.setCompleted(true); + //鎵╁睍鍐呭 涓嶅弽overtime鍓嶇榛樿鏄豢鑹� + ProcessCoding processCoding = processCodingMap.get(s.getTaskId()); + //濡傛灉鏈夌洃鎺ф暟鎹�, 鍘嗗彶鑺傜偣鍙垽鏂孩鐮� + if (processCoding != null && RED.equals(processCoding.getStatus())) { + flowViewerDto.setOvertime(processCoding.getStatus()); + } // 閫�鍥炶妭鐐逛笉杩涜灞曠ず if (StringUtils.isBlank(s.getDeleteReason())) { flowViewerList.add(flowViewerDto); @@ -1095,7 +1168,6 @@ .processInstanceId(procInsId) .unfinished() .list(); - // 淇濆瓨闇�瑕佷唬鍔炵殑鑺傜偣缂栧彿 listUnFinished.forEach(s -> { // 鍒犻櫎宸查��鍥炶妭鐐� @@ -1103,6 +1175,12 @@ FlowViewerDto flowViewerDto = new FlowViewerDto(); flowViewerDto.setKey(s.getActivityId()); flowViewerDto.setCompleted(false); + // 鎵╁睍鍐呭 浠e姙鐨勯�氳繃褰撳墠鏃堕棿浣滀负endTime + ProcessCoding processCoding = processCodingMap.get(s.getTaskId()); + //濡傛灉鏈夌洃鎺ф暟鎹� 涓嶅弽鐨勮瘽鍓嶇榛樿鏄繘琛屼腑(钃濊壊) + if (processCoding != null && (RED.equals(processCoding.getStatus()) || YELLOW.equals(processCoding.getStatus()))) { + flowViewerDto.setOvertime(processCoding.getStatus()); + } flowViewerList.add(flowViewerDto); }); Map<String, Object> result = new HashMap(); @@ -1114,6 +1192,7 @@ result.put("xmlData", xmlData); return AjaxResult.success(result); } catch (Exception e) { + e.printStackTrace(); return AjaxResult.error("楂樹寒鍘嗗彶浠诲姟澶辫触"); } } @@ -1135,41 +1214,124 @@ } else { parameters = taskService.getVariables(taskId); } + List<FormDetailVO> beforeNodes = this.getBeforeNodeForm(parameters, task.getFormKey(), task.getName(), task.getProcessDefinitionId(), task.getTaskDefinitionKey(), Boolean.FALSE); + return AjaxResult.success(beforeNodes); + } - JSONObject oldVariables = JSONObject.parseObject(JSON.toJSONString(parameters.get("formJson"))); - if (Objects.isNull(oldVariables)) { - // 濡傛灉鏄┖鐨勶紝鐩存帴浣跨敤涓昏〃鍗曪紝鍥犱负杩欎唬琛ㄦ槸娴佺▼涓殑绗竴涓彁浜よ〃鍗曠殑浠诲姟 - String deploymentId = runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult().getDeploymentId(); - return this.flowFormData(deploymentId); + @Override + public AjaxResult detail(String taskId) { + Task task = taskService.createTaskQuery().taskId(taskId).singleResult(); + // 娴佺▼鍙橀噺 + Map<String, Object> parameters = new HashMap<>(); + if (Objects.isNull(task)) { + // 濡傛灉涓虹┖锛屽彲鑳芥槸浠诲姟宸茬粡缁撴潫 + HistoricTaskInstance hisTask = historyService.createHistoricTaskInstanceQuery().taskId(taskId).includeProcessVariables().singleResult(); + if (Objects.isNull(hisTask)) { + throw new RuntimeException("璇ヤ换鍔′笉瀛樺湪"); + } + parameters = hisTask.getProcessVariables(); + List<FormDetailVO> beforeNodes = this.getBeforeNodeForm(parameters, hisTask.getFormKey(), hisTask.getName(), hisTask.getProcessDefinitionId(), hisTask.getTaskDefinitionKey(), Boolean.TRUE); + return AjaxResult.success(beforeNodes); + } 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<JSONObject> oldFields = JSON.parseObject(JSON.toJSONString(oldVariables.get("widgetList")), new TypeReference<List<JSONObject>>() { - }); - // 璁剧疆宸插~鍐欑殑琛ㄥ崟涓虹鐢ㄧ姸鎬� - for (JSONObject oldField : oldFields) { - JSONObject options = oldField.getJSONObject("options"); - options.put("disabled", true); + } + + /** + * 鑾峰彇褰撳墠鑺傜偣鍜屼笂涓�鑺傜偣鐨勮〃鍗曞唴瀹� + * + * @param parameters 鏍规嵁浠诲姟鏌ユ壘鍑烘潵鐨勫弬鏁� + * @param formKey task鑷韩鍏宠仈鐨勮〃鍗昳d + * @param taskName task鑷韩鐨勪换鍔″悕 + * @param processDefId 娴佺▼瀹氫箟id + * @param processDefKey 娴佺▼瀹炰緥id + * @return + */ + private List<FormDetailVO> getBeforeNodeForm(Map<String, Object> parameters, String formKey, String taskName, String processDefId, String processDefKey, Boolean currentNeedData) { + if (!parameters.keySet().stream().anyMatch(key -> key.contains(ProcessConstants.TASK_FORM_KEY))) { + FormDetailVO formDetailVO = new FormDetailVO(); + formDetailVO.setBeforeNodeName(taskName); + formDetailVO.setCurrent(Boolean.TRUE); + // 濡傛灉鏄┖鐨勶紝浣跨敤formId鍘绘煡 + if (StringUtils.isNotBlank(formKey)) { + SysForm sysForm = sysFormService.selectSysFormById(Long.parseLong(formKey)); + if (Objects.isNull(sysForm)) { + throw new RuntimeException("璇ユ祦绋嬬粦瀹氱殑琛ㄥ崟涓嶅瓨鍦ㄦ垨宸茶鍒犻櫎"); + } + + Map<String, Object> data = new HashMap<>(1); + data.put(ProcessConstants.TASK_FORM_KEY, JSONObject.parseObject(sysForm.getFormContent())); + formDetailVO.setFormJsonObj(data); + return Arrays.asList(formDetailVO); + } else { + return Arrays.asList(formDetailVO); + } } - // TODO 鏆傛椂鍙鐞嗙敤鎴蜂换鍔′笂鐨勮〃鍗� - if (StringUtils.isNotBlank(task.getFormKey())) { - SysForm sysForm = sysFormService.selectSysFormById(Long.parseLong(task.getFormKey())); - JSONObject data = JSONObject.parseObject(sysForm.getFormContent()); - List<JSONObject> newFields = JSON.parseObject(JSON.toJSONString(data.get("widgetList")), new TypeReference<List<JSONObject>>() { - }); - // 琛ㄥ崟鍥炴樉鏃� 鍔犲叆瀛愯〃鍗曚俊鎭埌娴佺▼鍙橀噺涓� - for (JSONObject newField : newFields) { - String key = newField.getString("id"); - // 澶勭悊鍥剧墖涓婁紶缁勪欢鍥炴樉闂 - if ("picture-upload".equals(newField.getString("type"))) { - parameters.put(key, new ArrayList<>()); - } else { - parameters.put(key, null); + // 杩欓噷鍙渶瑕佹煡鑷韩浠ュ強涓婁竴涓妭鐐�(濡傛灉骞惰鐨勬湁澶氫釜)鐨勮〃鍗曟暟鎹� + List<FormDetailVO> beforeNodes = taskCommonService.getBeforeNodeDefInfo(processDefId, processDefKey, sysFormService, Boolean.TRUE); + List<String> beforeNodeDefIds = beforeNodes.stream().filter(item -> !item.getCurrent() || currentNeedData).map(FormDetailVO::getBeforeNodeDefId).collect(Collectors.toList()); + + // 澶勭悊姣忎釜琛ㄥ崟鐨勬暟鎹� + for (FormDetailVO formDetailVO : beforeNodes) { + if (formDetailVO.getCurrent() && !currentNeedData) { + continue; // 璺宠繃褰撳墠鑺傜偣锛屽洜涓哄綋鍓嶈妭鐐瑰湪鑾峰彇鍓嶇疆鑺傜偣鏃跺凡缁忚缃繃浜�(浣嗚〃鍗曟暟鎹病鏈夌粰) + } + + Map<String, Object> newP = new HashMap<>(); + if (CollectionUtils.isNotEmpty(beforeNodeDefIds)) { + for (String key : parameters.keySet()) { + // 杩囨护鎷垮埌鐩爣琛ㄥ崟鏁版嵁锛屽皢鐩爣琛ㄥ崟鏁版嵁鏀惧埌鏂癿ap涓� + if (key.startsWith(formDetailVO.getBeforeNodeDefId())) { + if (key.contains(ProcessConstants.TASK_FORM_KEY)) { + newP.put(key, parameters.get(key)); + } else { + newP.put(key.split("&")[1], parameters.get(key)); + } + } } } - oldFields.addAll(newFields); + + Object form = newP.get(formDetailVO.getBeforeNodeDefId() + "&" + ProcessConstants.TASK_FORM_KEY); + if (Objects.nonNull(form)) { + JSONObject formJson = JSONObject.parseObject(JSON.toJSONString(form)); + List<JSONObject> oldFields = JSON.parseObject(JSON.toJSONString(formJson.get(ProcessConstants.WIDGET_LIST)), new TypeReference<List<JSONObject>>() { + }); + + if(CollectionUtils.isNotEmpty(oldFields)) { + // 璁剧疆宸插~鍐欑殑琛ㄥ崟涓虹鐢ㄧ姸鎬� + 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); + newP.remove(formDetailVO.getBeforeNodeDefId() + "&" + ProcessConstants.TASK_FORM_KEY); + formDetailVO.setFormJsonObj(newP); + } + // TODO 鏆傛椂鍙鐞嗙敤鎴蜂换鍔′笂鐨勮〃鍗� +// if (StringUtils.isNotBlank(task.getFormKey())) { +// SysForm sysForm = sysFormService.selectSysFormById(Long.parseLong(task.getFormKey())); +// JSONObject data = JSONObject.parseObject(sysForm.getFormContent()); +// List<JSONObject> newFields = JSON.parseObject(JSON.toJSONString(data.get(ProcessConstants.WIDGET_LIST)), new TypeReference<List<JSONObject>>() { +// }); +// // 琛ㄥ崟鍥炴樉鏃� 鍔犲叆瀛愯〃鍗曚俊鎭埌娴佺▼鍙橀噺涓� +// for (JSONObject newField : newFields) { +// String key = newField.getString("id"); +// // 澶勭悊鍥剧墖涓婁紶缁勪欢鍥炴樉闂 +// if ("picture-upload".equals(newField.getString("type"))) { +// parameters.put(key, new ArrayList<>()); +// } else { +// parameters.put(key, null); +// } +// } +// oldFields.addAll(newFields); +// } + + } } - oldVariables.put("widgetList", oldFields); - parameters.put("formJson", oldVariables); - return AjaxResult.success(parameters); + return beforeNodes; } /** -- Gitblit v1.8.0