From 2a5a028e5f5d1cbab9a0bdb26ce6c48a5184ef49 Mon Sep 17 00:00:00 2001 From: luohairen <3399054449@qq.com> Date: 星期四, 26 十二月 2024 18:11:55 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- flowable/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java | 233 ++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 192 insertions(+), 41 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..09202bf 100644 --- a/flowable/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java +++ b/flowable/src/main/java/com/ycl/service/impl/FlowTaskServiceImpl.java @@ -7,6 +7,7 @@ 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.SysRole; import com.ycl.common.core.domain.entity.SysUser; import com.ycl.common.enums.FlowComment; @@ -19,6 +20,7 @@ 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; @@ -26,6 +28,8 @@ import com.ycl.service.IFlowTaskService; import com.ycl.service.ISysDeployFormService; import com.ycl.service.ISysFormService; +import com.ycl.service.common.TaskCommonService; +import com.ycl.system.service.ISysDeptService; import com.ycl.system.service.ISysRoleService; import com.ycl.system.service.ISysUserService; import lombok.RequiredArgsConstructor; @@ -78,8 +82,10 @@ private final ISysUserService sysUserService; private final ISysRoleService sysRoleService; + private final ISysDeptService sysDeptService; private final ISysDeployFormService sysInstanceFormService; private final ISysFormService sysFormService; + private final TaskCommonService taskCommonService; /** * 瀹屾垚瀹℃牳浠诲姟 @@ -119,10 +125,21 @@ if (Objects.isNull(task)) { return AjaxResult.error("浠诲姟涓嶅瓨鍦�"); } + 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 (ProcessConstants.TASK_FORM_KEY.equals(key)) { +// newV.put(task.getTaskDefinitionKey() + "_" + ProcessConstants.TASK_FORM_KEY, variables.get(key)); +// } else if (ProcessConstants.WIDGET_LIST.equals(key)){ +// newV.put(task.getTaskDefinitionKey() + "_" + ProcessConstants.WIDGET_LIST, variables.get(key)); +// } + } + } // 鍏堣褰撳墠鐢ㄦ埛璁ら杩欎釜浠诲姟 taskService.claim(taskId, SecurityUtils.getUserId() + ""); taskService.addComment(taskId, task.getProcessInstanceId(), FlowComment.SUBMIT.getType(), "瀹屾垚鎻愪氦"); - taskService.complete(taskId, variables); + taskService.complete(taskId, newV); return AjaxResult.success("鎻愪氦鎴愬姛"); } @@ -775,6 +792,11 @@ .processInstanceId(procInsId) .orderByHistoricActivityInstanceStartTime() .desc().list(); + Date now =new Date(); + //鎵╁睍 + List<HistoricTaskInstance> taskList = historyService.createHistoricTaskInstanceQuery() + .processInstanceId(procInsId) + .list(); List<FlowTaskDto> hisFlowList = new ArrayList<>(); for (HistoricActivityInstance histIns : list) { // 灞曠ず寮�濮嬭妭鐐� @@ -817,8 +839,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 +855,23 @@ } flowTask.setDuration(histIns.getDurationInMillis() == null || histIns.getDurationInMillis() == 0 ? null : getDate(histIns.getDurationInMillis())); + String taskId = histIns.getTaskId(); + + //鎵╁睍 鍒ゆ柇鏄惁瓒呮椂 + for (HistoricTaskInstance taskInstance : taskList) { + Date dueDate = taskInstance.getDueDate(); + //鎵惧埌瀵瑰簲浠诲姟鑺傜偣 + if(dueDate!=null && taskInstance.getId().equals(taskId) ) { + //濡傛灉浠诲姟杩樻病瀹屾垚 + if(flowTask.getDuration()==null) { + //鍒ゆ柇褰撳墠鏃堕棿鏄惁瓒呰繃鍒版湡鏃堕棿 + if (now.after(dueDate)) flowTask.setOvertime(Boolean.TRUE); + }else { + //濡傛灉浠诲姟鑺傜偣宸茬粡瀹屾垚浜嗭紝鐢ㄥ畬鎴愭椂闂村垽鏂� + if(histIns.getEndTime().after(dueDate)) flowTask.setOvertime(Boolean.TRUE); + } + } + } // 鑾峰彇鎰忚璇勮鍐呭 List<Comment> commentList = taskService.getProcessInstanceComments(histIns.getProcessInstanceId()); commentList.forEach(comment -> { @@ -839,14 +884,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,18 +1117,36 @@ @Override public AjaxResult flowXmlAndNode(String procInsId, String deployId) { try { + Date now = new Date(); List<FlowViewerDto> flowViewerList = new ArrayList<>(); // 鑾峰彇宸茬粡瀹屾垚鐨勮妭鐐� List<HistoricActivityInstance> listFinished = historyService.createHistoricActivityInstanceQuery() .processInstanceId(procInsId) .finished() .list(); - + //鑾峰彇鎵�鏈夊巻鍙蹭换鍔¤妭鐐逛俊鎭�(鎵╁睍) + List<HistoricTaskInstance> taskHistoryList = historyService.createHistoricTaskInstanceQuery() + .processInstanceId(procInsId) + .finished() + .list(); + //鑾峰彇鎵�鏈夊綋鍓嶄换鍔¤妭鐐逛俊鎭�(鎵╁睍) + List<Task> taskList = taskService.createTaskQuery() + .processInstanceId(procInsId) + .list(); // 淇濆瓨宸茬粡瀹屾垚鐨勬祦绋嬭妭鐐圭紪鍙� listFinished.forEach(s -> { FlowViewerDto flowViewerDto = new FlowViewerDto(); flowViewerDto.setKey(s.getActivityId()); flowViewerDto.setCompleted(true); + //鎵╁睍鍐呭 宸插畬鎴愮殑鐢ㄥ畬鎴愭椂闂村垽鏂� + Date endTime = s.getEndTime(); + for (HistoricTaskInstance task : taskHistoryList) { + if(s.getTaskId()!=null && s.getTaskId().equals(task.getId())){ + if(task.getDueDate()!=null && endTime.after(task.getDueDate())){ + flowViewerDto.setOvertime(true); + } + } + } // 閫�鍥炶妭鐐逛笉杩涜灞曠ず if (StringUtils.isBlank(s.getDeleteReason())) { flowViewerList.add(flowViewerDto); @@ -1103,6 +1166,14 @@ FlowViewerDto flowViewerDto = new FlowViewerDto(); flowViewerDto.setKey(s.getActivityId()); flowViewerDto.setCompleted(false); + //鎵╁睍鍐呭 浠e姙鐨勯�氳繃褰撳墠鏃堕棿鍘诲垽鏂� + for (Task task : taskList) { + if(s.getTaskId()!=null && s.getTaskId().equals(task.getId())){ + if(task.getDueDate()!=null && now.after(task.getDueDate())){ + flowViewerDto.setOvertime(true); + } + } + } flowViewerList.add(flowViewerDto); }); Map<String, Object> result = new HashMap(); @@ -1135,41 +1206,121 @@ } 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))) { + // 濡傛灉鏄┖鐨勶紝浣跨敤formId鍘绘煡 + if (StringUtils.isNotBlank(formKey)) { + SysForm sysForm = sysFormService.selectSysFormById(Long.parseLong(formKey)); + if (Objects.isNull(sysForm)) { + throw new RuntimeException("璇ユ祦绋嬬粦瀹氱殑琛ㄥ崟涓嶅瓨鍦ㄦ垨宸茶鍒犻櫎"); + } + FormDetailVO formDetailVO = new FormDetailVO(); + Map<String, Object> data = new HashMap<>(1); + data.put(ProcessConstants.TASK_FORM_KEY, JSONObject.parseObject(sysForm.getFormContent())); + formDetailVO.setFormJsonObj(data); + formDetailVO.setBeforeNodeName(taskName); + formDetailVO.setCurrent(Boolean.TRUE); + return Arrays.asList(formDetailVO); + } else { + return new ArrayList<>(1); + } } - // 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>>() { + }); + + // 璁剧疆宸插~鍐欑殑琛ㄥ崟涓虹鐢ㄧ姸鎬� + for (JSONObject oldField : oldFields) { + JSONObject options = oldField.getJSONObject("options"); + options.put("disabled", true); + } + // 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); +// } + formJson.put(ProcessConstants.WIDGET_LIST, oldFields); + newP.put(ProcessConstants.TASK_FORM_KEY, formJson); + newP.remove(formDetailVO.getBeforeNodeDefId() + "&" + ProcessConstants.TASK_FORM_KEY); + formDetailVO.setFormJsonObj(newP); + } } - oldVariables.put("widgetList", oldFields); - parameters.put("formJson", oldVariables); - return AjaxResult.success(parameters); + return beforeNodes; } /** -- Gitblit v1.8.0