From abe161669c501424e17190cc6b3f251898f1b508 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 9 Jan 2022 21:23:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20BPM=20Task=20=E7=9A=84=20c?= =?UTF-8?q?ategory=20=E8=AE=BE=E7=BD=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activiti/BpmActivitiConfiguration.java | 11 +++- .../BpmProcessDefinitionService.java | 10 ++++ .../impl/BpmProcessDefinitionServiceImpl.java | 5 ++ .../impl/BpmProcessInstanceServiceImpl.java | 15 ++---- .../service/task/impl/BpmTaskServiceImpl.java | 1 + .../BpmTackActivitiEventListener.java | 53 +++++++++++++++++++ .../task/listener/BpmTaskEventListener.java | 15 ------ .../src/views/bpm/model/modelEditor.vue | 11 +--- 8 files changed, 83 insertions(+), 38 deletions(-) create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/listener/BpmTackActivitiEventListener.java diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/BpmActivitiConfiguration.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/BpmActivitiConfiguration.java index d4e8302c6..6101d2d46 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/BpmActivitiConfiguration.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/BpmActivitiConfiguration.java @@ -1,19 +1,26 @@ package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti; +import cn.iocoder.yudao.adminserver.modules.bpm.service.task.listener.BpmTackActivitiEventListener; import org.activiti.spring.SpringProcessEngineConfiguration; import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer; import org.springframework.context.annotation.Configuration; +import javax.annotation.Resource; +import java.util.Collections; + /** * BPM 模块的 Activiti 配置类 */ @Configuration public class BpmActivitiConfiguration implements ProcessEngineConfigurationConfigurer { + @Resource + private BpmTackActivitiEventListener taskActivitiEventListener; + @Override public void configure(SpringProcessEngineConfiguration configuration) { - // 注册监听器,例如说 ActivitiEventListener 的实现类 -// configuration.setEventListeners(Arrays.asList(processInstanceEventListener)); + // 注册监听器,例如说 BpmActivitiEventListener + configuration.setEventListeners(Collections.singletonList(taskActivitiEventListener)); } } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmProcessDefinitionService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmProcessDefinitionService.java index 89198a9c5..4cabc86ab 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmProcessDefinitionService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmProcessDefinitionService.java @@ -64,6 +64,16 @@ public interface BpmProcessDefinitionService { */ ProcessDefinition getProcessDefinition(String id); + /** + * 获得编号对应的 ProcessDefinition + * + * 相比 {@link #getProcessDefinition(String)} 方法,category 的取值是正确 + * + * @param id 编号 + * @return 流程定义 + */ + ProcessDefinition getProcessDefinition2(String id); + /** * 获得 id 对应的 Deployment * diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmProcessDefinitionServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmProcessDefinitionServiceImpl.java index 382d1c56d..08400812c 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmProcessDefinitionServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmProcessDefinitionServiceImpl.java @@ -135,6 +135,11 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ return repositoryService.getProcessDefinition(id); } + @Override + public ProcessDefinition getProcessDefinition2(String id) { + return repositoryService.createProcessDefinitionQuery().processDefinitionId(id).singleResult(); + } + @Override public Deployment getDeployment(String id) { if (StrUtil.isEmpty(id)) { diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmProcessInstanceServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmProcessInstanceServiceImpl.java index e41595d9f..6f00bf5c1 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmProcessInstanceServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmProcessInstanceServiceImpl.java @@ -1,15 +1,12 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.task.impl; import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceCancelReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceCreateReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceMyPageReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstancePageItemRespVO; import cn.iocoder.yudao.adminserver.modules.bpm.convert.task.BpmProcessInstanceConvert; -import cn.iocoder.yudao.adminserver.modules.bpm.convert.task.BpmTaskConvert; import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.task.BpmProcessInstanceExtDO; -import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.task.BpmTaskExtDO; import cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.task.BpmProcessInstanceExtMapper; import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.BpmProcessInstanceDeleteReasonEnum; import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.BpmProcessInstanceResultEnum; @@ -18,15 +15,11 @@ import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmProcessDef import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmProcessInstanceService; import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmTaskService; import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; -import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import lombok.extern.slf4j.Slf4j; import org.activiti.engine.HistoryService; import org.activiti.engine.RuntimeService; -import org.activiti.engine.TaskService; import org.activiti.engine.history.HistoricProcessInstance; -import org.activiti.engine.history.HistoricProcessInstanceQuery; import org.activiti.engine.repository.ProcessDefinition; import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.task.Task; @@ -37,7 +30,6 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.*; -import java.util.function.Consumer; import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -93,9 +85,6 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService ProcessInstance instance = runtimeService.startProcessInstanceById(createReqVO.getProcessDefinitionId(), variables); // 设置流程名字 runtimeService.setProcessInstanceName(instance.getId(), definition.getName()); - // 更新流程实例拓展表的 category TODO 芋艿:暂时没好的办法,task 的 category 不正确。另外,definition 返回的 category 也不太正确,后续在解决; - processInstanceExtMapper.updateByProcessInstanceId(new BpmProcessInstanceExtDO() - .setProcessInstanceId(instance.getId()).setCategory(definition.getCategory())); // TODO 芋艿:临时使用, 保证分配 List tasks = taskService.getTasksByProcessInstanceId(instance.getId()); @@ -194,7 +183,11 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService @Override public void createProcessInstanceExt(org.activiti.api.process.model.ProcessInstance instance) { + // 获得流程定义 + ProcessDefinition definition = processDefinitionService.getProcessDefinition2(instance.getProcessDefinitionId()); + // 插入 BpmProcessInstanceExtDO 对象 BpmProcessInstanceExtDO instanceExtDO = BpmProcessInstanceConvert.INSTANCE.convert(instance) + .setCategory(definition.getCategory()) .setStatus(BpmProcessInstanceStatusEnum.RUNNING.getStatus()) .setResult(BpmProcessInstanceResultEnum.PROCESS.getResult()); processInstanceExtMapper.insert(instanceExtDO); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmTaskServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmTaskServiceImpl.java index ebf36231b..6a18eae80 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmTaskServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmTaskServiceImpl.java @@ -396,6 +396,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { @Override public void createTaskExt(org.activiti.api.task.model.Task task) { + // 插入 BpmTaskExtDO 记录 BpmTaskExtDO taskExtDO = BpmTaskConvert.INSTANCE.convert(task) .setResult(BpmProcessInstanceResultEnum.PROCESS.getResult()); taskExtMapper.insert(taskExtDO); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/listener/BpmTackActivitiEventListener.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/listener/BpmTackActivitiEventListener.java new file mode 100644 index 000000000..de46ebcd3 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/listener/BpmTackActivitiEventListener.java @@ -0,0 +1,53 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.service.task.listener; + +import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmProcessDefinitionService; +import org.activiti.api.process.runtime.events.listener.ProcessRuntimeEventListener; +import org.activiti.api.task.runtime.events.listener.TaskEventListener; +import org.activiti.engine.delegate.event.ActivitiEvent; +import org.activiti.engine.delegate.event.ActivitiEventListener; +import org.activiti.engine.delegate.event.ActivitiEventType; +import org.activiti.engine.delegate.event.impl.ActivitiEntityEventImpl; +import org.activiti.engine.impl.persistence.entity.TaskEntity; +import org.activiti.engine.repository.ProcessDefinition; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +/** + * 监听 {@link TaskEntity} 相关的事件,设置相关属性。 + * 目的:解决 {@link TaskEventListener} 无法解决的场景 + * + * @author 芋道源码 + */ +@Component +public class BpmTackActivitiEventListener implements ActivitiEventListener { + + @Resource + @Lazy // 解决循环依赖 + private BpmProcessDefinitionService processDefinitionService; + + @Override + public void onEvent(ActivitiEvent event) { + // Task 创建时,设置其分类,解决 TaskService 未提供 name 的设置方法 + if (ActivitiEventType.TASK_CREATED == event.getType()) { + TaskEntity task = ((TaskEntity) ((ActivitiEntityEventImpl) event).getEntity()); + if (StrUtil.isNotEmpty(task.getCategory())) { + return; + } + // 设置 name + ProcessDefinition processDefinition = processDefinitionService.getProcessDefinition2(task.getProcessDefinitionId()); + if (processDefinition == null) { + return; + } + task.setCategory(processDefinition.getCategory()); + } + } + + @Override + public boolean isFailOnException() { + return true; + } + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/listener/BpmTaskEventListener.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/listener/BpmTaskEventListener.java index 89d51d801..cc3b665f5 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/listener/BpmTaskEventListener.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/listener/BpmTaskEventListener.java @@ -46,19 +46,4 @@ public class BpmTaskEventListener> taskService.updateTaskExt(event.getEntity()); } -// // Task 创建时,插入拓展表 -// if (event.getType() == ActivitiEventType.TASK_CREATED) { -// System.out.println(event); -// return; -// } -// -// if (event.getType() == ActivitiEventType.TASK_COMPLETED) { -// System.out.println(event); -// // 不处理; -// } else if (event.getType() == ActivitiEventType.ENTITY_DELETED) { -// // 假设是 -// System.out.println(event); -// } -// System.out.println(event); - } diff --git a/yudao-admin-ui/src/views/bpm/model/modelEditor.vue b/yudao-admin-ui/src/views/bpm/model/modelEditor.vue index 5bc418f73..aefa96574 100644 --- a/yudao-admin-ui/src/views/bpm/model/modelEditor.vue +++ b/yudao-admin-ui/src/views/bpm/model/modelEditor.vue @@ -175,17 +175,8 @@ export default { .my-process-designer { height: calc(100vh - 84px); - //height: 800px !important; // TODO 芋艿:bjs 容器的高度不对,临时改下 - //z-index: 0 !important; - //pointer-events: none !important; } -.process-panel__container { // TODO 芋艿:右边的位置不对,临时改下 - //margin-top: -800px !important; - //float: right; - //margin-left: 800px !important; - //height: 800px; - //z-index: 2147483647 !important; - //cursor:pointer !important; +.process-panel__container { position: absolute; right: 0; top: 55px;