| | |
| | | import org.flowable.engine.HistoryService; |
| | | import org.flowable.engine.TaskService; |
| | | import org.flowable.engine.history.HistoricProcessInstance; |
| | | import org.flowable.engine.task.Comment; |
| | | import org.flowable.task.api.Task; |
| | | import org.flowable.task.api.TaskQuery; |
| | | import org.flowable.task.api.history.HistoricTaskInstance; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.utils.*; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.Collections; |
| | | import java.util.Date; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 流程业务实现类 |
| | |
| | | private final HistoryService historyService; |
| | | private final IUserClient userClient; |
| | | |
| | | public IPage<FlowVO> selectTodoPage(IPage<FlowVO> page, LocalDate createTimeBegin, LocalDate createTimeEnd, String keyword) { |
| | | /** |
| | | * 查询我的流程(个人待办列表) |
| | | * @param page |
| | | * @param createTimeBegin |
| | | * @param createTimeEnd |
| | | * @param keyword |
| | | * @return |
| | | */ |
| | | public IPage<FlowVO> selectTodoPage(IPage<FlowVO> page, LocalDateTime createTimeBegin, LocalDateTime createTimeEnd, String keyword) { |
| | | //String taskUser = TaskUtil.getTaskUser(); |
| | | String userId = "" + AuthUtil.getUserId(); |
| | | List<FlowVO> flowList = new LinkedList<>(); |
| | |
| | | TaskQuery todoQuery = taskService.createTaskQuery().taskAssignee(userId).active().includeProcessVariables(); |
| | | if (Func.isNotEmpty(createTimeBegin)) { |
| | | todoQuery.taskCreatedAfter(DateUtil.toDate(createTimeBegin)); |
| | | //如果查询实例的开始时间:todoQuery.taskInProgressStartDueAfter() |
| | | |
| | | ////如果查询实例的开始时间:只能用以下这个,先查出实例id来 |
| | | //todoQuery.processInstanceIdIn() |
| | | } |
| | | if (Func.isNotEmpty(createTimeEnd)) { |
| | | todoQuery.taskCreatedBefore(DateUtil.toDate(createTimeEnd)); |
| | | |
| | | //todoQuery.taskInProgressStartTimeBefore(DateUtil.toDate(createTimeEnd)); |
| | | } |
| | | if (Func.isNotEmpty(keyword)) { |
| | | addKeywordCondition(todoQuery, keyword); |
| | |
| | | if (bladeFlow.getEndDate() != null) { |
| | | taskQuery.taskCreatedBefore(bladeFlow.getEndDate()); |
| | | } |
| | | |
| | | List<Task> tasks = taskQuery.list(); |
| | | tasks.forEach(task -> { |
| | | FlowVO flow = new FlowVO(); |
| | |
| | | if(ru.isSuccess()) { |
| | | flow.setStartUserName(ru.getData().getName()); |
| | | } |
| | | ; |
| | | List<Comment> comments = lastStepComments(task);//taskService.getTaskComments(task.getId()); |
| | | if(!comments.isEmpty()){ |
| | | flow.setComment(comments.get(0).getFullMessage()); |
| | | } |
| | | |
| | | MdmFlowProcess processDefinition = MdmFlowCache.getProcessDefinition(task.getProcessDefinitionId()); |
| | | |
| | | flow.setCategory(processDefinition.getCategory()); |
| | |
| | | }); |
| | | } |
| | | |
| | | List<Comment> lastStepComments(Task currentTask){ |
| | | List<HistoricTaskInstance> previousTasks = historyService.createHistoricActivityInstanceQuery() |
| | | .processInstanceId(currentTask.getProcessInstanceId()) |
| | | .activityType("userTask") // 直接查询用户任务类型 |
| | | .orderByHistoricActivityInstanceEndTime() |
| | | .desc() |
| | | .list() |
| | | .stream() |
| | | .filter(activity -> !activity.getActivityId().equals(currentTask.getTaskDefinitionKey())) |
| | | .map(activity -> historyService.createHistoricTaskInstanceQuery() |
| | | .taskDefinitionKey(activity.getActivityId()) |
| | | .processInstanceId(activity.getProcessInstanceId()) |
| | | .orderByHistoricTaskInstanceEndTime() |
| | | .desc() |
| | | .list() |
| | | ) |
| | | .flatMap(List::stream) |
| | | .toList(); |
| | | List<Comment> comments; |
| | | if (!previousTasks.isEmpty()) { |
| | | return taskService.getTaskComments(previousTasks.get(0).getId()); |
| | | |
| | | }else{ |
| | | return Collections.emptyList(); |
| | | } |
| | | } |
| | | /** |
| | | * 获取历史流程 |
| | | * |