Commit 075dd83b5fa1e7b653ddbcbccf5d159780132f01
1 parent
d6775a56
工作流 Flowable 流程实例, 用户任务相关实现
Showing
9 changed files
with
212 additions
and
5 deletions
yudao-module-bpm/yudao-module-bpm-impl-flowable/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/BpmActivityController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.bpm.controller.admin.task; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 4 | +import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.activity.BpmActivityRespVO; | |
| 5 | +import cn.iocoder.yudao.module.bpm.service.task.BpmActivityService; | |
| 6 | +import io.swagger.annotations.Api; | |
| 7 | +import io.swagger.annotations.ApiImplicitParam; | |
| 8 | +import io.swagger.annotations.ApiOperation; | |
| 9 | +import org.springframework.security.access.prepost.PreAuthorize; | |
| 10 | +import org.springframework.validation.annotation.Validated; | |
| 11 | +import org.springframework.web.bind.annotation.GetMapping; | |
| 12 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 13 | +import org.springframework.web.bind.annotation.RequestParam; | |
| 14 | +import org.springframework.web.bind.annotation.RestController; | |
| 15 | + | |
| 16 | +import javax.annotation.Resource; | |
| 17 | +import java.util.List; | |
| 18 | + | |
| 19 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 20 | + | |
| 21 | +@Api(tags = "管理后台 - 流程活动实例") | |
| 22 | +@RestController | |
| 23 | +@RequestMapping("/bpm/activity") | |
| 24 | +@Validated | |
| 25 | +public class BpmActivityController { | |
| 26 | + | |
| 27 | + @Resource | |
| 28 | + private BpmActivityService activityService; | |
| 29 | + | |
| 30 | + @GetMapping("/list") | |
| 31 | + @ApiOperation(value = "生成指定流程实例的高亮流程图", | |
| 32 | + notes = "只高亮进行中的任务。不过要注意,该接口暂时没用,通过前端的 ProcessViewer.vue 界面的 highlightDiagram 方法生成") | |
| 33 | + @ApiImplicitParam(name = "processInstanceId", value = "流程实例的编号", required = true, dataTypeClass = String.class) | |
| 34 | + @PreAuthorize("@ss.hasPermission('bpm:task:query')") | |
| 35 | + public CommonResult<List<BpmActivityRespVO>> getActivityList( | |
| 36 | + @RequestParam("processInstanceId") String processInstanceId) { | |
| 37 | + return success(activityService.getActivityListByProcessInstanceId(processInstanceId)); | |
| 38 | + } | |
| 39 | +} | ... | ... |
yudao-module-bpm/yudao-module-bpm-impl-flowable/src/main/java/cn/iocoder/yudao/module/bpm/convert/task/BpmActivityConvert.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.bpm.convert.task; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.activity.BpmActivityRespVO; | |
| 4 | +import org.flowable.engine.history.HistoricActivityInstance; | |
| 5 | +import org.mapstruct.Mapper; | |
| 6 | +import org.mapstruct.Mapping; | |
| 7 | +import org.mapstruct.Mappings; | |
| 8 | +import org.mapstruct.factory.Mappers; | |
| 9 | + | |
| 10 | +import java.util.List; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * BPM 活动 Convert | |
| 14 | + * | |
| 15 | + * @author 芋道源码 | |
| 16 | + */ | |
| 17 | +@Mapper | |
| 18 | +public interface BpmActivityConvert { | |
| 19 | + | |
| 20 | + BpmActivityConvert INSTANCE = Mappers.getMapper(BpmActivityConvert.class); | |
| 21 | + | |
| 22 | + List<BpmActivityRespVO> convertList(List<HistoricActivityInstance> list); | |
| 23 | + | |
| 24 | + @Mappings({ | |
| 25 | + @Mapping(source = "activityId", target = "key"), | |
| 26 | + @Mapping(source = "activityType", target = "type") | |
| 27 | + }) | |
| 28 | + BpmActivityRespVO convert(HistoricActivityInstance bean); | |
| 29 | +} | ... | ... |
yudao-module-bpm/yudao-module-bpm-impl-flowable/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/config/BpmFlowableConfiguration.java
| ... | ... | @@ -11,10 +11,12 @@ import org.flowable.common.engine.api.delegate.event.FlowableEventListener; |
| 11 | 11 | import org.flowable.engine.runtime.ProcessInstance; |
| 12 | 12 | import org.flowable.spring.SpringProcessEngineConfiguration; |
| 13 | 13 | import org.flowable.spring.boot.EngineConfigurationConfigurer; |
| 14 | +import org.springframework.beans.factory.ObjectProvider; | |
| 14 | 15 | import org.springframework.context.annotation.Bean; |
| 15 | 16 | import org.springframework.context.annotation.Configuration; |
| 16 | 17 | |
| 17 | 18 | import java.util.ArrayList; |
| 19 | +import java.util.Iterator; | |
| 18 | 20 | import java.util.List; |
| 19 | 21 | /** |
| 20 | 22 | * BPM 模块的 Flowable 配置类 |
| ... | ... | @@ -26,14 +28,17 @@ public class BpmFlowableConfiguration { |
| 26 | 28 | |
| 27 | 29 | /** |
| 28 | 30 | * 将自定义 listener 加入全局listener |
| 29 | - * @param processInstanceListener 自定义监听 {@link ProcessInstance} | |
| 31 | + * @param listeners 自定义 listener | |
| 30 | 32 | */ |
| 31 | 33 | @Bean |
| 32 | - public EngineConfigurationConfigurer<SpringProcessEngineConfiguration> addCustomerListenerConfigurer (BpmProcessInstanceEventListener processInstanceListener, | |
| 34 | + public EngineConfigurationConfigurer<SpringProcessEngineConfiguration> addCustomerListenerConfigurer (ObjectProvider<FlowableEventListener> listeners, | |
| 33 | 35 | BpmActivityBehaviorFactory bpmActivityBehaviorFactory) { |
| 34 | 36 | return engineConfiguration -> { |
| 35 | - List<FlowableEventListener> eventListeners = new ArrayList<>(); | |
| 36 | - eventListeners.add(processInstanceListener); | |
| 37 | + List<FlowableEventListener> eventListeners = new ArrayList<>(); | |
| 38 | + Iterator<FlowableEventListener> iterator = listeners.iterator(); | |
| 39 | + while (iterator.hasNext()) { | |
| 40 | + eventListeners.add(iterator.next()); | |
| 41 | + } | |
| 37 | 42 | engineConfiguration.setEventListeners(eventListeners); |
| 38 | 43 | engineConfiguration.setActivityBehaviorFactory(bpmActivityBehaviorFactory); |
| 39 | 44 | }; | ... | ... |
yudao-module-bpm/yudao-module-bpm-impl-flowable/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/listener/BpmTaskEventListener.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.bpm.framework.flowable.core.listener; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO; | |
| 4 | +import cn.iocoder.yudao.module.bpm.service.task.BpmTaskService; | |
| 5 | +import com.google.common.collect.ImmutableSet; | |
| 6 | +import org.flowable.common.engine.api.delegate.event.FlowableEngineEntityEvent; | |
| 7 | +import org.flowable.common.engine.api.delegate.event.FlowableEngineEventType; | |
| 8 | +import org.flowable.engine.delegate.event.AbstractFlowableEngineEventListener; | |
| 9 | +import org.flowable.task.api.Task; | |
| 10 | +import org.springframework.context.annotation.Lazy; | |
| 11 | +import org.springframework.stereotype.Component; | |
| 12 | + | |
| 13 | +import javax.annotation.Resource; | |
| 14 | +import java.util.Set; | |
| 15 | + | |
| 16 | +/** | |
| 17 | + * 监听 {@link org.flowable.task.api.Task} 的开始与完成,创建与更新对应的 {@link BpmTaskExtDO} 记录 | |
| 18 | + * | |
| 19 | + * @author jason | |
| 20 | + */ | |
| 21 | +@Component | |
| 22 | +public class BpmTaskEventListener extends AbstractFlowableEngineEventListener { | |
| 23 | + | |
| 24 | + @Resource | |
| 25 | + @Lazy // 解决循环依赖 | |
| 26 | + private BpmTaskService taskService; | |
| 27 | + | |
| 28 | + public static final Set<FlowableEngineEventType> TASK_EVENTS = ImmutableSet.<FlowableEngineEventType>builder() | |
| 29 | + .add(FlowableEngineEventType.TASK_CREATED) | |
| 30 | + .add(FlowableEngineEventType.TASK_ASSIGNED) | |
| 31 | + .add(FlowableEngineEventType.TASK_COMPLETED) | |
| 32 | + .build(); | |
| 33 | + | |
| 34 | + public BpmTaskEventListener(){ | |
| 35 | + super(TASK_EVENTS); | |
| 36 | + } | |
| 37 | + | |
| 38 | + @Override | |
| 39 | + protected void taskCreated(FlowableEngineEntityEvent event) { | |
| 40 | + taskService.createTaskExt((Task) event.getEntity()); | |
| 41 | + } | |
| 42 | +} | ... | ... |
yudao-module-bpm/yudao-module-bpm-impl-flowable/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmActivityService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.bpm.service.task; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.activity.BpmActivityRespVO; | |
| 4 | + | |
| 5 | +import java.util.List; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * BPM 活动实例 Service 接口 | |
| 9 | + * | |
| 10 | + * @author 芋道源码 | |
| 11 | + */ | |
| 12 | +public interface BpmActivityService { | |
| 13 | + | |
| 14 | + /** | |
| 15 | + * 获得指定流程实例的活动实例列表 | |
| 16 | + * | |
| 17 | + * @param processInstanceId 流程实例的编号 | |
| 18 | + * @return 活动实例列表 | |
| 19 | + */ | |
| 20 | + List<BpmActivityRespVO> getActivityListByProcessInstanceId(String processInstanceId); | |
| 21 | + | |
| 22 | +} | ... | ... |
yudao-module-bpm/yudao-module-bpm-impl-flowable/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmActivityServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.bpm.service.task; | |
| 2 | + | |
| 3 | +import cn.hutool.core.io.IoUtil; | |
| 4 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 5 | +import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.activity.BpmActivityRespVO; | |
| 6 | +import cn.iocoder.yudao.module.bpm.convert.task.BpmActivityConvert; | |
| 7 | +import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService; | |
| 8 | +import lombok.extern.slf4j.Slf4j; | |
| 9 | + | |
| 10 | +import org.flowable.bpmn.model.BpmnModel; | |
| 11 | +import org.flowable.engine.HistoryService; | |
| 12 | +import org.flowable.engine.history.HistoricActivityInstance; | |
| 13 | +import org.flowable.engine.history.HistoricProcessInstance; | |
| 14 | +import org.flowable.image.ProcessDiagramGenerator; | |
| 15 | +import org.springframework.stereotype.Service; | |
| 16 | +import org.springframework.validation.annotation.Validated; | |
| 17 | + | |
| 18 | +import javax.annotation.Resource; | |
| 19 | +import java.io.InputStream; | |
| 20 | +import java.util.Collections; | |
| 21 | +import java.util.List; | |
| 22 | + | |
| 23 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 24 | +import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.PROCESS_DEFINITION_BPMN_MODEL_NOT_EXISTS; | |
| 25 | +import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.PROCESS_INSTANCE_NOT_EXISTS; | |
| 26 | + | |
| 27 | +/** | |
| 28 | + * BPM 活动实例 Service 实现类 | |
| 29 | + * | |
| 30 | + * @author 芋道源码 | |
| 31 | + */ | |
| 32 | +@Service | |
| 33 | +@Slf4j | |
| 34 | +@Validated | |
| 35 | +public class BpmActivityServiceImpl implements BpmActivityService { | |
| 36 | + | |
| 37 | + @Resource | |
| 38 | + private HistoryService historyService; | |
| 39 | + | |
| 40 | + @Override | |
| 41 | + public List<BpmActivityRespVO> getActivityListByProcessInstanceId(String processInstanceId) { | |
| 42 | + List<HistoricActivityInstance> activityList = historyService.createHistoricActivityInstanceQuery() | |
| 43 | + .processInstanceId(processInstanceId).list(); | |
| 44 | + return BpmActivityConvert.INSTANCE.convertList(activityList); | |
| 45 | + } | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | +} | ... | ... |
yudao-module-bpm/yudao-module-bpm-impl-flowable/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java
| ... | ... | @@ -76,7 +76,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService |
| 76 | 76 | private DeptApi deptApi; |
| 77 | 77 | @Override |
| 78 | 78 | public List<ProcessInstance> getProcessInstances(Set<String> ids) { |
| 79 | - return runtimeService.createProcessInstanceQuery().processDefinitionIds(ids).list(); | |
| 79 | + return runtimeService.createProcessInstanceQuery().processInstanceIds(ids).list(); | |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | @Override | ... | ... |
yudao-module-bpm/yudao-module-bpm-impl-flowable/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskService.java
| ... | ... | @@ -53,4 +53,12 @@ public interface BpmTaskService { |
| 53 | 53 | * @return 流程任务列表 |
| 54 | 54 | */ |
| 55 | 55 | List<BpmTaskRespVO> getTaskListByProcessInstanceId(String processInstanceId); |
| 56 | + | |
| 57 | + /** | |
| 58 | + * 创建 Task 拓展记录 | |
| 59 | + * | |
| 60 | + * @param task 任务实体 | |
| 61 | + */ | |
| 62 | + void createTaskExt(Task task); | |
| 63 | + | |
| 56 | 64 | } | ... | ... |
yudao-module-bpm/yudao-module-bpm-impl-flowable/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
| ... | ... | @@ -11,6 +11,7 @@ import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskTodoPage |
| 11 | 11 | import cn.iocoder.yudao.module.bpm.convert.task.BpmTaskConvert; |
| 12 | 12 | import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO; |
| 13 | 13 | import cn.iocoder.yudao.module.bpm.dal.mysql.task.BpmTaskExtMapper; |
| 14 | +import cn.iocoder.yudao.module.bpm.enums.task.BpmProcessInstanceResultEnum; | |
| 14 | 15 | import cn.iocoder.yudao.module.system.api.dept.DeptApi; |
| 15 | 16 | import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; |
| 16 | 17 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| ... | ... | @@ -124,4 +125,16 @@ public class BpmTaskServiceImpl implements BpmTaskService{ |
| 124 | 125 | // 拼接数据 |
| 125 | 126 | return BpmTaskConvert.INSTANCE.convertList3(tasks, bpmTaskExtDOMap, processInstance, userMap, deptMap); |
| 126 | 127 | } |
| 128 | + | |
| 129 | + @Override | |
| 130 | + public void createTaskExt(Task task) { | |
| 131 | + BpmTaskExtDO taskExtDO = new BpmTaskExtDO() | |
| 132 | + .setTaskId(task.getId()) | |
| 133 | + .setAssigneeUserId(task.getAssignee() == null ? null : Long.valueOf(task.getAssignee())) | |
| 134 | + .setProcessDefinitionId(task.getProcessDefinitionId()) | |
| 135 | + .setProcessInstanceId(task.getProcessInstanceId()) | |
| 136 | + .setName(task.getName()) | |
| 137 | + .setResult(BpmProcessInstanceResultEnum.PROCESS.getResult()); | |
| 138 | + taskExtMapper.insert(taskExtDO); | |
| 139 | + } | |
| 127 | 140 | } | ... | ... |