| | |
| | | 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; |
| | |
| | | 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; |
| | |
| | | |
| | | private final ISysUserService sysUserService; |
| | | private final ISysRoleService sysRoleService; |
| | | private final ISysDeptService sysDeptService; |
| | | private final ISysDeployFormService sysInstanceFormService; |
| | | private final ISysFormService sysFormService; |
| | | private final TaskCommonService taskCommonService; |
| | |
| | | .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) { |
| | | // 展示开始节点 |
| | |
| | | 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(","); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | 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 -> { |
| | |
| | | } |
| | | 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); |
| | | } |
| | | |
| | |
| | | @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> taskList = historyService.createHistoricTaskInstanceQuery() |
| | | .processInstanceId(procInsId) |
| | | .finished() |
| | | .list(); |
| | |
| | | FlowViewerDto flowViewerDto = new FlowViewerDto(); |
| | | flowViewerDto.setKey(s.getActivityId()); |
| | | flowViewerDto.setCompleted(true); |
| | | //扩展内容 已完成的用完成时间判断 |
| | | Date endTime = s.getEndTime(); |
| | | for (HistoricTaskInstance task : taskList) { |
| | | 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); |
| | |
| | | FlowViewerDto flowViewerDto = new FlowViewerDto(); |
| | | flowViewerDto.setKey(s.getActivityId()); |
| | | flowViewerDto.setCompleted(false); |
| | | //扩展内容 代办的通过当前时间去判断 |
| | | for (HistoricTaskInstance 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(); |
| | |
| | | } 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); |
| | | } |
| | | |
| | | @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); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取当前节点和上一节点的表单内容 |
| | | * |
| | | * @param parameters 根据任务查找出来的参数 |
| | | * @param formKey task自身关联的表单id |
| | | * @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(task.getFormKey())) { |
| | | SysForm sysForm = sysFormService.selectSysFormById(Long.parseLong(task.getFormKey())); |
| | | 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); |
| | | formDetailVO.setBeforeNodeName(task.getName()); |
| | | formDetailVO.setBeforeNodeName(taskName); |
| | | formDetailVO.setCurrent(Boolean.TRUE); |
| | | return AjaxResult.success(Arrays.asList(formDetailVO)); |
| | | return Arrays.asList(formDetailVO); |
| | | } else { |
| | | return AjaxResult.success(new ArrayList<>(1)); |
| | | return new ArrayList<>(1); |
| | | } |
| | | } |
| | | // 这里只需要查自身以及上一个节点(如果并行的有多个)的表单数据 |
| | | List<FormDetailVO> beforeNodes = taskCommonService.getBeforeNodeDefId(task.getProcessDefinitionId(), task.getTaskDefinitionKey(), sysFormService); |
| | | List<String> beforeNodeDefIds = beforeNodes.stream().filter(item -> !item.getCurrent()).map(FormDetailVO::getBeforeNodeDefId).collect(Collectors.toList()); |
| | | Map<String, Object> newP = new HashMap<>(); |
| | | if (CollectionUtils.isNotEmpty(beforeNodeDefIds)) { |
| | | for (String key : parameters.keySet()) { |
| | | // 过滤目标数据,将目标表单数据放到新map中 |
| | | if (beforeNodeDefIds.stream().anyMatch(defId -> key.startsWith(defId))) { |
| | | if (key.contains(ProcessConstants.TASK_FORM_KEY)) { |
| | | newP.put(key, parameters.get(key)); |
| | | } else { |
| | | newP.put(key.split("&")[1], parameters.get(key)); |
| | | 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()) { |
| | | // 过滤拿到目标表单数据,将目标表单数据放到新map中 |
| | | 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)); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 拿到目标表单后,再处理每个表单的数据 |
| | | for (FormDetailVO formDetailVO : beforeNodes) { |
| | | if (formDetailVO.getCurrent()) { |
| | | continue; // 跳过当前节点,因为当前节点在获取前置节点时已经设置过了 |
| | | } |
| | | Object form = newP.get(formDetailVO.getBeforeNodeDefId() + "&" + ProcessConstants.TASK_FORM_KEY); |
| | | if (Objects.nonNull(form)) { |
| | | JSONObject formJson = JSONObject.parseObject(JSON.toJSONString(form)); |
| | |
| | | formDetailVO.setFormJsonObj(newP); |
| | | } |
| | | } |
| | | |
| | | return AjaxResult.success(beforeNodes); |
| | | return beforeNodes; |
| | | } |
| | | |
| | | /** |