| | |
| | | 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.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.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 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 |
| | |
| | | private final ISysDeployFormService sysInstanceFormService; |
| | | private final ISysFormService sysFormService; |
| | | private final TaskCommonService taskCommonService; |
| | | private final ProcessCodingMapper processCodingMapper; |
| | | private final FlowLogService flowLogService; |
| | | |
| | | /** |
| | | * 完成审核任务 |
| | |
| | | /** |
| | | * 完成表单提交任务/普通任务 |
| | | * |
| | | * @param taskId 任务id |
| | | * @param variables 表单数据 |
| | | * @param taskId 任务id |
| | | * @param variables 表单数据 |
| | | * @return |
| | | */ |
| | | @Override |
| | |
| | | return AjaxResult.error("任务不存在"); |
| | | } |
| | | Map<String, Object> newV = new HashMap<>(2); |
| | | if (! org.springframework.util.CollectionUtils.isEmpty(variables)) { |
| | | 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.addComment(taskId, task.getProcessInstanceId(), FlowComment.SUBMIT.getType(), "完成提交"); |
| | | // 判断当前任务是不是转办过的 |
| | | Boolean delegation = flowLogService.taskDelegation(task.getProcessInstanceId(), task.getId()); |
| | | if (delegation) { |
| | | taskService.resolveTask(taskId, newV); |
| | | } |
| | | // 先让当前用户认领这个任务 |
| | | taskService.claim(taskId, SecurityUtils.getUserId() + ""); |
| | | taskService.addComment(taskId, task.getProcessInstanceId(), FlowComment.SUBMIT.getType(), "完成提交"); |
| | | taskService.complete(taskId, newV); |
| | | |
| | | return AjaxResult.success("提交成功"); |
| | | } |
| | | |
| | |
| | | if (!isSequential) { |
| | | throw new CustomException("当前节点相对于目标节点,不属于串行关系,无法回退"); |
| | | } |
| | | |
| | | |
| | | // 获取所有正常进行的任务节点 Key,这些任务不能直接使用,需要找出其中需要撤回的任务 |
| | | List<Task> runTaskList = taskService.createTaskQuery().processInstanceId(task.getProcessInstanceId()).list(); |
| | |
| | | .processInstanceId(procInsId) |
| | | .orderByHistoricActivityInstanceStartTime() |
| | | .desc().list(); |
| | | Date now =new Date(); |
| | | //扩展 |
| | | List<HistoricTaskInstance> taskList = historyService.createHistoricTaskInstanceQuery() |
| | | .processInstanceId(procInsId) |
| | | .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) { |
| | | // 展示开始节点 |
| | |
| | | } |
| | | |
| | | 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); |
| | | 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()); |
| | | }; |
| | | } |
| | | } |
| | | // 获取意见评论内容 |
| | |
| | | @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(); |
| | | |
| | | //扩展 获取这个流程实例的监控信息 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); |
| | | //扩展内容 已完成的用完成时间判断 |
| | | 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); |
| | | } |
| | | } |
| | | //扩展内容 不反overtime前端默认是绿色 |
| | | ProcessCoding processCoding = processCodingMap.get(s.getTaskId()); |
| | | //如果有监控数据, 历史节点只判断红码 |
| | | if (processCoding != null && RED.equals(processCoding.getStatus())) { |
| | | flowViewerDto.setOvertime(processCoding.getStatus()); |
| | | } |
| | | // 退回节点不进行展示 |
| | | if (StringUtils.isBlank(s.getDeleteReason())) { |
| | |
| | | .processInstanceId(procInsId) |
| | | .unfinished() |
| | | .list(); |
| | | |
| | | // 保存需要代办的节点编号 |
| | | listUnFinished.forEach(s -> { |
| | | // 删除已退回节点 |
| | |
| | | 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); |
| | | } |
| | | } |
| | | // 扩展内容 代办的通过当前时间作为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); |
| | | }); |
| | |
| | | result.put("xmlData", xmlData); |
| | | return AjaxResult.success(result); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | return AjaxResult.error("高亮历史任务失败"); |
| | | } |
| | | } |
| | |
| | | /** |
| | | * 获取当前节点和上一节点的表单内容 |
| | | * |
| | | * @param parameters 根据任务查找出来的参数 |
| | | * @param formKey task自身关联的表单id |
| | | * @param taskName task自身的任务名 |
| | | * @param processDefId 流程定义id |
| | | * @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))) { |
| | | 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("该流程绑定的表单不存在或已被删除"); |
| | | } |
| | | 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); |
| | | return Arrays.asList(formDetailVO); |
| | | } |
| | | } |
| | | // 这里只需要查自身以及上一个节点(如果并行的有多个)的表单数据 |
| | |
| | | if (key.startsWith(formDetailVO.getBeforeNodeDefId())) { |
| | | if (key.contains(ProcessConstants.TASK_FORM_KEY)) { |
| | | newP.put(key, parameters.get(key)); |
| | | } |
| | | else { |
| | | } else { |
| | | newP.put(key.split("&")[1], parameters.get(key)); |
| | | } |
| | | } |