|
31 | 31 | import org.apache.inlong.manager.common.util.Preconditions;
|
32 | 32 | import org.apache.inlong.manager.service.workflow.WorkflowTaskExecuteLog.ListenerExecutorLog;
|
33 | 33 | import org.apache.inlong.manager.service.workflow.WorkflowTaskExecuteLog.TaskExecutorLog;
|
| 34 | +import org.apache.inlong.manager.workflow.core.QueryService; |
34 | 35 | import org.apache.inlong.manager.workflow.core.WorkflowEngine;
|
35 | 36 | import org.apache.inlong.manager.workflow.exception.WorkflowNoRollbackException;
|
36 | 37 | import org.apache.inlong.manager.workflow.model.TaskState;
|
@@ -85,8 +86,8 @@ private void init() {
|
85 | 86 |
|
86 | 87 | @Override
|
87 | 88 | @Transactional(noRollbackFor = WorkflowNoRollbackException.class, rollbackFor = Exception.class)
|
88 |
| - public WorkflowResult start(ProcessName name, String applicant, ProcessForm form) { |
89 |
| - return WorkflowResult.of(workflowEngine.processService().start(name.name(), applicant, form)); |
| 89 | + public WorkflowResult start(ProcessName process, String applicant, ProcessForm form) { |
| 90 | + return WorkflowResult.of(workflowEngine.processService().start(process.name(), applicant, form)); |
90 | 91 | }
|
91 | 92 |
|
92 | 93 | @Override
|
@@ -171,27 +172,57 @@ public TaskSummaryView taskSummary(TaskSummaryQuery query) {
|
171 | 172 | }
|
172 | 173 |
|
173 | 174 | @Override
|
174 |
| - public List<WorkflowTaskExecuteLog> listTaskExecuteLogs(WorkflowTaskExecuteLogQuery query) { |
175 |
| - Preconditions.checkNotNull(query, "query params can't be null"); |
176 |
| - Preconditions.checkNotEmpty(query.getBusinessId(), "business id can't be null"); |
177 |
| - Preconditions.checkNotEmpty(query.getProcessNames(), "process names can't be null"); |
178 |
| - |
179 |
| - List<WorkflowTaskExecuteLog> workflowTaskExecuteLogs = query.getProcessNames().stream() |
180 |
| - .map(processName -> ProcessQuery.builder().businessId(query.getBusinessId()).name(processName).build()) |
181 |
| - .map(workflowEngine.queryService()::listProcess) |
182 |
| - .flatMap(List::stream) |
183 |
| - .map(WorkflowTaskExecuteLog::buildBaseInfoFromProcessInst) |
184 |
| - .collect(Collectors.toList()); |
| 175 | + public PageInfo<WorkflowTaskExecuteLog> listTaskExecuteLogs(WorkflowTaskExecuteLogQuery query) { |
| 176 | + Preconditions.checkNotNull(query, "workflow task execute log query params cannot be null"); |
| 177 | + Preconditions.checkNotEmpty(query.getBusinessId(), "business id cannot be null"); |
| 178 | + Preconditions.checkNotEmpty(query.getProcessNames(), "process name list cannot be null"); |
| 179 | + |
| 180 | + ProcessQuery processQuery = new ProcessQuery(); |
| 181 | + processQuery.setBusinessId(query.getBusinessId()); |
| 182 | + processQuery.setNameList(query.getProcessNames()); |
| 183 | + processQuery.setHidden(true); |
| 184 | + |
| 185 | + // 分页查询流程实例,构造流程执行日志 |
| 186 | + QueryService queryService = workflowEngine.queryService(); |
| 187 | + PageHelper.startPage(query.getPageNum(), query.getPageSize()); |
| 188 | + Page<ProcessInstance> instanceList = (Page<ProcessInstance>) queryService.listProcess(processQuery); |
185 | 189 |
|
186 |
| - workflowTaskExecuteLogs.forEach(executeLog -> { |
187 |
| - List<TaskExecutorLog> taskExecutorLogs = getTaskExecutorLogs(executeLog.getProcessInstId(), |
188 |
| - query.getTaskType()); |
189 |
| - taskExecutorLogs.forEach(taskExecutorLog -> taskExecutorLog |
190 |
| - .setListenerExecutorLogs(getListenerExecutorLogs(taskExecutorLog))); |
191 |
| - executeLog.setTaskExecutorLogs(taskExecutorLogs); |
192 |
| - } |
| 190 | + PageInfo<WorkflowTaskExecuteLog> pageInfo = instanceList.toPageInfo(inst -> WorkflowTaskExecuteLog.builder() |
| 191 | + .processInstId(inst.getId()) |
| 192 | + .processDisplayName(inst.getDisplayName()) |
| 193 | + .state(inst.getState()) |
| 194 | + .startTime(inst.getStartTime()) |
| 195 | + .endTime(inst.getEndTime()) |
| 196 | + .build() |
193 | 197 | );
|
194 |
| - return workflowTaskExecuteLogs; |
| 198 | + |
| 199 | + // 根据流程执行日志,查询流程中各个任务的执行日志 |
| 200 | + for (WorkflowTaskExecuteLog executeLog : pageInfo.getList()) { |
| 201 | + TaskQuery taskQuery = new TaskQuery(); |
| 202 | + taskQuery.setProcessInstId(executeLog.getProcessInstId()); |
| 203 | + taskQuery.setType(query.getTaskType()); |
| 204 | + List<TaskExecutorLog> taskExecutorLogs = queryService.listTask(taskQuery) |
| 205 | + .stream() |
| 206 | + .map(TaskExecutorLog::buildFromTaskInst) |
| 207 | + .collect(Collectors.toList()); |
| 208 | + |
| 209 | + // 设置任务的监听器的执行日志 |
| 210 | + for (TaskExecutorLog taskExecutorLog : taskExecutorLogs) { |
| 211 | + EventLogQuery eventLogQuery = new EventLogQuery(); |
| 212 | + eventLogQuery.setTaskInstId(taskExecutorLog.getTaskInstId()); |
| 213 | + List<ListenerExecutorLog> logs = queryService.listEventLog(eventLogQuery) |
| 214 | + .stream() |
| 215 | + .map(ListenerExecutorLog::fromEventLog) |
| 216 | + .collect(Collectors.toList()); |
| 217 | + taskExecutorLog.setListenerExecutorLogs(logs); |
| 218 | + } |
| 219 | + |
| 220 | + executeLog.setTaskExecutorLogs(taskExecutorLogs); |
| 221 | + } |
| 222 | + |
| 223 | + log.info("success to page list task execute logs for " + query); |
| 224 | + pageInfo.setTotal(instanceList.getTotal()); |
| 225 | + return pageInfo; |
195 | 226 | }
|
196 | 227 |
|
197 | 228 | private List<TaskExecutorLog> getTaskExecutorLogs(Integer processInstId, String taskType) {
|
@@ -241,7 +272,7 @@ private void addShowInListForEachTask(List<TaskListView> taskList) {
|
241 | 272 | List<Integer> processInstIds = taskList.stream().map(TaskListView::getProcessInstId)
|
242 | 273 | .distinct().collect(Collectors.toList());
|
243 | 274 | List<ProcessInstance> processInstances = this.workflowEngine.queryService().listProcess(
|
244 |
| - ProcessQuery.builder().ids(processInstIds).build()); |
| 275 | + ProcessQuery.builder().idList(processInstIds).build()); |
245 | 276 | Map<Integer, Map<String, Object>> process2ShowInListMap = Maps.newHashMap();
|
246 | 277 | processInstances.forEach(p -> process2ShowInListMap.put(p.getId(), getShowInList(p)));
|
247 | 278 | taskList.forEach(task -> task.setShowInList(process2ShowInListMap.get(task.getProcessInstId())));
|
|
0 commit comments