修复 BPM Task 的 category 设置问题

This commit is contained in:
YunaiV 2022-01-09 21:23:59 +08:00
parent 9860a7d552
commit abe161669c
8 changed files with 83 additions and 38 deletions

View File

@ -1,19 +1,26 @@
package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti; 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.SpringProcessEngineConfiguration;
import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer; import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
import java.util.Collections;
/** /**
* BPM 模块的 Activiti 配置类 * BPM 模块的 Activiti 配置类
*/ */
@Configuration @Configuration
public class BpmActivitiConfiguration implements ProcessEngineConfigurationConfigurer { public class BpmActivitiConfiguration implements ProcessEngineConfigurationConfigurer {
@Resource
private BpmTackActivitiEventListener taskActivitiEventListener;
@Override @Override
public void configure(SpringProcessEngineConfiguration configuration) { public void configure(SpringProcessEngineConfiguration configuration) {
// 注册监听器例如说 ActivitiEventListener 的实现类 // 注册监听器例如说 BpmActivitiEventListener
// configuration.setEventListeners(Arrays.asList(processInstanceEventListener)); configuration.setEventListeners(Collections.singletonList(taskActivitiEventListener));
} }
} }

View File

@ -64,6 +64,16 @@ public interface BpmProcessDefinitionService {
*/ */
ProcessDefinition getProcessDefinition(String id); ProcessDefinition getProcessDefinition(String id);
/**
* 获得编号对应的 ProcessDefinition
*
* 相比 {@link #getProcessDefinition(String)} 方法category 的取值是正确
*
* @param id 编号
* @return 流程定义
*/
ProcessDefinition getProcessDefinition2(String id);
/** /**
* 获得 id 对应的 Deployment * 获得 id 对应的 Deployment
* *

View File

@ -135,6 +135,11 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
return repositoryService.getProcessDefinition(id); return repositoryService.getProcessDefinition(id);
} }
@Override
public ProcessDefinition getProcessDefinition2(String id) {
return repositoryService.createProcessDefinitionQuery().processDefinitionId(id).singleResult();
}
@Override @Override
public Deployment getDeployment(String id) { public Deployment getDeployment(String id) {
if (StrUtil.isEmpty(id)) { if (StrUtil.isEmpty(id)) {

View File

@ -1,15 +1,12 @@
package cn.iocoder.yudao.adminserver.modules.bpm.service.task.impl; package cn.iocoder.yudao.adminserver.modules.bpm.service.task.impl;
import cn.hutool.core.collection.CollUtil; 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.BpmProcessInstanceCancelReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceCreateReqVO; 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.BpmProcessInstanceMyPageReqVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstancePageItemRespVO; 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.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.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.dal.mysql.task.BpmProcessInstanceExtMapper;
import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.BpmProcessInstanceDeleteReasonEnum; import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.BpmProcessInstanceDeleteReasonEnum;
import cn.iocoder.yudao.adminserver.modules.bpm.enums.task.BpmProcessInstanceResultEnum; 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.BpmProcessInstanceService;
import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmTaskService; import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmTaskService;
import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; 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.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.HistoryService; import org.activiti.engine.HistoryService;
import org.activiti.engine.RuntimeService; import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.history.HistoricProcessInstance; import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.history.HistoricProcessInstanceQuery;
import org.activiti.engine.repository.ProcessDefinition; import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task; import org.activiti.engine.task.Task;
@ -37,7 +30,6 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.*; import java.util.*;
import java.util.function.Consumer;
import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.*; import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.*;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 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); ProcessInstance instance = runtimeService.startProcessInstanceById(createReqVO.getProcessDefinitionId(), variables);
// 设置流程名字 // 设置流程名字
runtimeService.setProcessInstanceName(instance.getId(), definition.getName()); runtimeService.setProcessInstanceName(instance.getId(), definition.getName());
// 更新流程实例拓展表的 category TODO 芋艿暂时没好的办法task category 不正确另外definition 返回的 category 也不太正确后续在解决
processInstanceExtMapper.updateByProcessInstanceId(new BpmProcessInstanceExtDO()
.setProcessInstanceId(instance.getId()).setCategory(definition.getCategory()));
// TODO 芋艿临时使用, 保证分配 // TODO 芋艿临时使用, 保证分配
List<Task> tasks = taskService.getTasksByProcessInstanceId(instance.getId()); List<Task> tasks = taskService.getTasksByProcessInstanceId(instance.getId());
@ -194,7 +183,11 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
@Override @Override
public void createProcessInstanceExt(org.activiti.api.process.model.ProcessInstance instance) { public void createProcessInstanceExt(org.activiti.api.process.model.ProcessInstance instance) {
// 获得流程定义
ProcessDefinition definition = processDefinitionService.getProcessDefinition2(instance.getProcessDefinitionId());
// 插入 BpmProcessInstanceExtDO 对象
BpmProcessInstanceExtDO instanceExtDO = BpmProcessInstanceConvert.INSTANCE.convert(instance) BpmProcessInstanceExtDO instanceExtDO = BpmProcessInstanceConvert.INSTANCE.convert(instance)
.setCategory(definition.getCategory())
.setStatus(BpmProcessInstanceStatusEnum.RUNNING.getStatus()) .setStatus(BpmProcessInstanceStatusEnum.RUNNING.getStatus())
.setResult(BpmProcessInstanceResultEnum.PROCESS.getResult()); .setResult(BpmProcessInstanceResultEnum.PROCESS.getResult());
processInstanceExtMapper.insert(instanceExtDO); processInstanceExtMapper.insert(instanceExtDO);

View File

@ -396,6 +396,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
@Override @Override
public void createTaskExt(org.activiti.api.task.model.Task task) { public void createTaskExt(org.activiti.api.task.model.Task task) {
// 插入 BpmTaskExtDO 记录
BpmTaskExtDO taskExtDO = BpmTaskConvert.INSTANCE.convert(task) BpmTaskExtDO taskExtDO = BpmTaskConvert.INSTANCE.convert(task)
.setResult(BpmProcessInstanceResultEnum.PROCESS.getResult()); .setResult(BpmProcessInstanceResultEnum.PROCESS.getResult());
taskExtMapper.insert(taskExtDO); taskExtMapper.insert(taskExtDO);

View File

@ -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;
}
}

View File

@ -46,19 +46,4 @@ public class BpmTaskEventListener<T extends TaskRuntimeEvent<? extends Task>>
taskService.updateTaskExt(event.getEntity()); 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);
} }

View File

@ -175,17 +175,8 @@ export default {
.my-process-designer { .my-process-designer {
height: calc(100vh - 84px); height: calc(100vh - 84px);
//height: 800px !important; // TODO bjs
//z-index: 0 !important;
//pointer-events: none !important;
} }
.process-panel__container { // TODO .process-panel__container {
//margin-top: -800px !important;
//float: right;
//margin-left: 800px !important;
//height: 800px;
//z-index: 2147483647 !important;
//cursor:pointer !important;
position: absolute; position: absolute;
right: 0; right: 0;
top: 55px; top: 55px;