提交 711bf8c2 authored 作者: hzh's avatar hzh

代码优化

上级 5fc6e583
......@@ -19,6 +19,7 @@ import org.dromara.workflow.domain.bo.FileApproveBo;
import org.dromara.workflow.domain.vo.FileApproveVo;
import org.dromara.workflow.mapper.FileApproveMapper;
import org.dromara.workflow.service.IFileApproveService;
import org.dromara.workflow.utils.QueryUtils;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -121,8 +122,7 @@ public class FileApproveServiceImpl extends AbstractBaseService<FileApproveVo, F
@EventListener(condition = "#processTaskEvent.key.startsWith('dept_file_approve')")
public void processTaskHandler(ProcessTaskEvent processTaskEvent) {
// 所有demo案例的申请人节点id
// String[] ids = workflowService.getTaskDefinitionKeyListByBusinessKey(processTaskEvent.getBusinessKey());
String[] ids = {"dept_file_approve_submit", "dept_file_download_approve"};
String[] ids = QueryUtils.getTaskDefinitionKeyListByBusinessKey(processTaskEvent.getBusinessKey()).toArray(new String[0]);
if (StringUtils.equalsAny(processTaskEvent.getTaskDefinitionKey(), ids)) {
log.info("当前任务执行了{}", processTaskEvent);
FileApprove fa = baseMapper.selectById(Long.valueOf(processTaskEvent.getBusinessKey()));
......
......@@ -21,6 +21,7 @@ import org.dromara.workflow.domain.bo.TestLeaveBo;
import org.dromara.workflow.domain.vo.TestLeaveVo;
import org.dromara.workflow.mapper.TestLeaveMapper;
import org.dromara.workflow.service.ITestLeaveService;
import org.dromara.workflow.utils.QueryUtils;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -147,8 +148,7 @@ public class TestLeaveServiceImpl implements ITestLeaveService {
@EventListener(condition = "#processTaskEvent.key.startsWith('leave')")
public void processTaskHandler(ProcessTaskEvent processTaskEvent) {
// 所有demo案例的申请人节点id
String[] ids = {"Activity_14633hx", "Activity_19b1i4j", "Activity_0uscrk3",
"Activity_0uscrk3", "Activity_0x6b71j", "Activity_0zy3g6j", "Activity_06a55t0"};
String[] ids = QueryUtils.getTaskDefinitionKeyListByBusinessKey(processTaskEvent.getBusinessKey()).toArray(new String[0]);
if (StringUtils.equalsAny(processTaskEvent.getTaskDefinitionKey(), ids)) {
log.info("当前任务执行了{}", processTaskEvent);
TestLeave testLeave = baseMapper.selectById(Long.valueOf(processTaskEvent.getBusinessKey()));
......
package org.dromara.workflow.utils;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollectionUtil;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.dromara.common.core.utils.SpringUtils;
import org.dromara.common.core.utils.StreamUtils;
import org.dromara.common.tenant.helper.TenantHelper;
import org.dromara.workflow.domain.vo.TaskVo;
import org.flowable.engine.ProcessEngine;
......@@ -16,6 +18,7 @@ import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.engine.runtime.ProcessInstanceQuery;
import org.flowable.task.api.Task;
import org.flowable.task.api.TaskQuery;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.task.api.history.HistoricTaskInstanceQuery;
import java.util.Collection;
......@@ -144,6 +147,10 @@ public class QueryUtils {
return taskQuery().processInstanceId(processInstanceId);
}
public static TaskQuery taskQueryBusinessKey(String businessKey) {
return taskQuery().processInstanceBusinessKey(businessKey);
}
public static TaskQuery taskQuery(Collection<String> processInstanceIds) {
return taskQuery().processInstanceIdIn(processInstanceIds);
}
......@@ -166,4 +173,19 @@ public class QueryUtils {
taskVo.setBusinessStatus(businessStatus);
return taskVo;
}
/**
* 根据业务id获取任务定义key集合
*
* @param businessKey 业务id
* @return 任务定义key集合
*/
public static List<String> getTaskDefinitionKeyListByBusinessKey(String businessKey) {
List<HistoricTaskInstance> historicTaskInstanceList = hisTaskBusinessKeyQuery(businessKey).list();
List<Task> taskList = taskQueryBusinessKey(businessKey).list();
List<String> hisTaskDefinitionKeyList = StreamUtils.toList(historicTaskInstanceList, HistoricTaskInstance::getTaskDefinitionKey);
List<String> taskDefinitionKeyList = StreamUtils.toList(taskList, Task::getTaskDefinitionKey);
return CollectionUtil.unionAll(hisTaskDefinitionKeyList, taskDefinitionKeyList);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论