diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/BpmTaskAssignRuleController.http b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/BpmTaskAssignRuleController.http new file mode 100644 index 000000000..e5d8fe966 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/BpmTaskAssignRuleController.http @@ -0,0 +1,4 @@ +### 请求 /bpm/task-assign-rule/list 接口 => 成功 +GET {{baseUrl}}/bpm/task-assign-rule/list?processDefinitionId=leave:9:59689ba0-7284-11ec-965c-a2380e71991a +tenant-id: 1 +Authorization: Bearer {{token}} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/BpmTaskAssignRuleController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/BpmTaskAssignRuleController.java new file mode 100644 index 000000000..39e8b545e --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/BpmTaskAssignRuleController.java @@ -0,0 +1,36 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.controller.definition; + +import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule.BpmTaskAssignRuleRespVO; +import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskAssignRuleService; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import io.swagger.annotations.Api; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.util.Collections; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Api(tags = "任务分配规则") +@RestController +@RequestMapping("/bpm/task-assign-rule") +@Validated +public class BpmTaskAssignRuleController { + + @Resource + private BpmTaskAssignRuleService taskAssignRuleService; + + @GetMapping("/list") + public CommonResult> getTaskAssignRuleList( + @RequestParam(value = "modelId", required = false) String modelId, + @RequestParam(value = "processDefinitionId", required = false) String processDefinitionId) { + return success(taskAssignRuleService.getTaskAssignRules(modelId, processDefinitionId)); + } + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/vo/rule/BpmTaskAssignRuleBaseVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/vo/rule/BpmTaskAssignRuleBaseVO.java new file mode 100644 index 000000000..392351508 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/vo/rule/BpmTaskAssignRuleBaseVO.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule; + +import lombok.Data; + +import java.util.Set; + +@Data +public class BpmTaskAssignRuleBaseVO { + + private Integer type; + + private Set options; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/vo/rule/BpmTaskAssignRuleCreateReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/vo/rule/BpmTaskAssignRuleCreateReqVO.java new file mode 100644 index 000000000..d9a130b7d --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/vo/rule/BpmTaskAssignRuleCreateReqVO.java @@ -0,0 +1,11 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule; + +import java.util.Set; + +public class BpmTaskAssignRuleCreateReqVO extends BpmTaskAssignRuleBaseVO { + + private String modelId; + + private String taskDefinitionKey; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/vo/rule/BpmTaskAssignRuleRespVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/vo/rule/BpmTaskAssignRuleRespVO.java new file mode 100644 index 000000000..cf7608fcf --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/vo/rule/BpmTaskAssignRuleRespVO.java @@ -0,0 +1,17 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule; + +import lombok.Data; + +@Data +public class BpmTaskAssignRuleRespVO extends BpmTaskAssignRuleBaseVO { + + private Long id; + + private String modelId; + + private String processDefinitionId; + + private String taskDefinitionKey; + private String taskDefinitionName; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/vo/rule/BpmTaskAssignRuleUpdateReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/vo/rule/BpmTaskAssignRuleUpdateReqVO.java new file mode 100644 index 000000000..8918a1c8f --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/definition/vo/rule/BpmTaskAssignRuleUpdateReqVO.java @@ -0,0 +1,9 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule; + +import java.util.Set; + +public class BpmTaskAssignRuleUpdateReqVO extends BpmTaskAssignRuleBaseVO { + + private Long id; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/definition/BpmDefinitionConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/definition/BpmProcessDefinitionConvert.java similarity index 96% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/definition/BpmDefinitionConvert.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/definition/BpmProcessDefinitionConvert.java index 2938adb79..48ea21cc9 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/definition/BpmDefinitionConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/definition/BpmProcessDefinitionConvert.java @@ -23,9 +23,9 @@ import java.util.Map; * @author yunlong.li */ @Mapper -public interface BpmDefinitionConvert { +public interface BpmProcessDefinitionConvert { - BpmDefinitionConvert INSTANCE = Mappers.getMapper(BpmDefinitionConvert.class); + BpmProcessDefinitionConvert INSTANCE = Mappers.getMapper(BpmProcessDefinitionConvert.class); default List convertList(List list, Map deploymentMap, Map processDefinitionDOMap, Map formMap) { diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/definition/BpmTaskAssignRuleConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/definition/BpmTaskAssignRuleConvert.java new file mode 100644 index 000000000..2793165db --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/definition/BpmTaskAssignRuleConvert.java @@ -0,0 +1,36 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.convert.definition; + +import cn.hutool.core.collection.CollUtil; +import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule.BpmTaskAssignRuleRespVO; +import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import org.activiti.bpmn.model.UserTask; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; +import java.util.Map; +import java.util.function.Function; + +@Mapper +public interface BpmTaskAssignRuleConvert { + + BpmTaskAssignRuleConvert INSTANCE = Mappers.getMapper(BpmTaskAssignRuleConvert.class); + + default List convertList(List tasks, List rules) { + Map ruleMap = CollectionUtils.convertMap(rules, BpmTaskAssignRuleDO::getTaskDefinitionKey); + // 以 UserTask 为主维度,原因是:流程图编辑后,一些规则实际就没用了。 + return CollectionUtils.convertList(tasks, task -> { + BpmTaskAssignRuleRespVO respVO = convert(ruleMap.get(task.getId())); + if (respVO == null) { + respVO = new BpmTaskAssignRuleRespVO(); + respVO.setTaskDefinitionKey(task.getId()); + } + respVO.setTaskDefinitionName(task.getName()); + return respVO; + }); + } + + BpmTaskAssignRuleRespVO convert(BpmTaskAssignRuleDO bean); + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmTaskRuleDO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmTaskAssignRuleDO.java similarity index 72% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmTaskRuleDO.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmTaskAssignRuleDO.java index 0f91a64f2..9770ada69 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmTaskRuleDO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmTaskAssignRuleDO.java @@ -1,23 +1,21 @@ package cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition; import cn.iocoder.yudao.adminserver.modules.bpm.enums.definition.BpmTaskRuleScriptEnum; -import cn.iocoder.yudao.adminserver.modules.bpm.enums.definition.BpmTaskRuleTypeEnum; +import cn.iocoder.yudao.adminserver.modules.bpm.enums.definition.BpmTaskAssignRuleTypeEnum; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.framework.mybatis.core.type.JsonLongSetTypeHandler; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler; import lombok.*; import org.activiti.engine.repository.Model; import org.activiti.engine.repository.ProcessDefinition; import org.activiti.engine.task.Task; -import java.util.List; import java.util.Set; /** - * Bpm 任务规则表,用于自定义配置每个任务的负责人的分配规则。 + * Bpm 任务分配的规则表,用于自定义配置每个任务的负责人、候选人的分配规则。 * 也就是说,废弃 BPMN 原本的 UserTask 设置的 assignee、candidateUsers 等配置,而是通过使用该规则进行计算对应的负责人。 * * 1. 默认情况下,{@link #processDefinitionId} 为 {@link #PROCESS_DEFINITION_ID_NULL} 值,表示贵改则与流程模型关联 @@ -25,19 +23,19 @@ import java.util.Set; * * @author 芋道源码 */ -@TableName(value = "bpm_task_rule", autoResultMap = true) +@TableName(value = "bpm_task_assign_rule", autoResultMap = true) @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) @Builder @NoArgsConstructor @AllArgsConstructor -public class BpmTaskRuleDO extends BaseDO { +public class BpmTaskAssignRuleDO extends BaseDO { /** * {@link #processDefinitionId} 空串,用于标识属于流程模型,而不属于流程定义 */ - private static final String PROCESS_DEFINITION_ID_NULL = ""; + public static final String PROCESS_DEFINITION_ID_NULL = ""; /** * 编号 @@ -67,7 +65,7 @@ public class BpmTaskRuleDO extends BaseDO { /** * 规则类型 * - * 枚举 {@link BpmTaskRuleTypeEnum} + * 枚举 {@link BpmTaskAssignRuleTypeEnum} */ @TableField("`type`") private Integer type; @@ -75,12 +73,12 @@ public class BpmTaskRuleDO extends BaseDO { * 规则值数组,一般关联指定表的编号 * 根据 type 不同,对应的值是不同的: * - * 1. {@link BpmTaskRuleTypeEnum#ROLE} 时:角色编号 - * 2. {@link BpmTaskRuleTypeEnum#DEPT} 时:部门编号 - * 3. {@link BpmTaskRuleTypeEnum#DEPT_LEADER} 时:部门编号 - * 4. {@link BpmTaskRuleTypeEnum#USER} 时:用户编号 - * 5. {@link BpmTaskRuleTypeEnum#USER_GROUP} 时:用户组编号 - * 6. {@link BpmTaskRuleTypeEnum#SCRIPT} 时:脚本编号,目前通过 {@link BpmTaskRuleScriptEnum#getId()} 标识 + * 1. {@link BpmTaskAssignRuleTypeEnum#ROLE} 时:角色编号 + * 2. {@link BpmTaskAssignRuleTypeEnum#DEPT} 时:部门编号 + * 3. {@link BpmTaskAssignRuleTypeEnum#DEPT_LEADER} 时:部门编号 + * 4. {@link BpmTaskAssignRuleTypeEnum#USER} 时:用户编号 + * 5. {@link BpmTaskAssignRuleTypeEnum#USER_GROUP} 时:用户组编号 + * 6. {@link BpmTaskAssignRuleTypeEnum#SCRIPT} 时:脚本编号,目前通过 {@link BpmTaskRuleScriptEnum#getId()} 标识 */ @TableField(typeHandler = JsonLongSetTypeHandler.class) private Set options; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmTaskMessageRuleDO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmTaskMessageRuleDO.java new file mode 100644 index 000000000..04f357931 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmTaskMessageRuleDO.java @@ -0,0 +1,5 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition; + +// TODO 芋艿:先埋个坑。任务消息的配置规则。说白了,就是不同的 +public class BpmTaskMessageRuleDO { +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/definition/BpmTaskAssignRuleMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/definition/BpmTaskAssignRuleMapper.java new file mode 100644 index 000000000..6bf5b6cab --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/definition/BpmTaskAssignRuleMapper.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.definition; + +import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; +import org.apache.ibatis.annotations.Mapper; +import org.springframework.lang.Nullable; + +import java.util.List; + +@Mapper +public interface BpmTaskAssignRuleMapper extends BaseMapperX { + + default List selectListByProcessDefinitionId(String processDefinitionId, + @Nullable String taskDefinitionKey) { + return selectList(new QueryWrapperX() + .eq("process_definition_id", processDefinitionId) + .eqIfPresent("task_definition_key", taskDefinitionKey)); + } + + default List selectListByModelId(String modelId) { + return selectList(new QueryWrapperX() + .eq("model_id", modelId) + .eq("process_definition_id", BpmTaskAssignRuleDO.PROCESS_DEFINITION_ID_NULL)); + } + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/definition/BpmTaskRuleMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/definition/BpmTaskRuleMapper.java deleted file mode 100644 index 4ba2c282c..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/definition/BpmTaskRuleMapper.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.definition; - -import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmTaskRuleDO; -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.QueryWrapperX; -import org.apache.ibatis.annotations.Mapper; -import org.springframework.lang.Nullable; - -import java.util.List; - -@Mapper -public interface BpmTaskRuleMapper extends BaseMapperX { - - default List selectListByProcessDefinitionId(String processDefinitionId, - @Nullable String taskDefinitionKey) { - return selectList(new QueryWrapperX() - .eq("process_definition_id", processDefinitionId) - .eqIfPresent("task_definition_key", taskDefinitionKey)); - } - -} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/definition/BpmTaskRuleTypeEnum.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/definition/BpmTaskAssignRuleTypeEnum.java similarity index 89% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/definition/BpmTaskRuleTypeEnum.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/definition/BpmTaskAssignRuleTypeEnum.java index 16cf1dc7c..e7cf89ab6 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/definition/BpmTaskRuleTypeEnum.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/definition/BpmTaskAssignRuleTypeEnum.java @@ -4,13 +4,13 @@ import lombok.AllArgsConstructor; import lombok.Getter; /** - * BPM 任务规则的类型枚举 + * BPM 任务分配规则的类型枚举 * * @author 芋道源码 */ @Getter @AllArgsConstructor -public enum BpmTaskRuleTypeEnum { +public enum BpmTaskAssignRuleTypeEnum { ROLE(10, "指定角色"), diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/config/BpmActivitiConfiguration.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/config/BpmActivitiConfiguration.java index 5f7918424..eacba0ba7 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/config/BpmActivitiConfiguration.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/config/BpmActivitiConfiguration.java @@ -2,7 +2,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.config; import cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.behavior.BpmActivityBehaviorFactory; import cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.listener.BpmTackActivitiEventListener; -import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskRuleService; +import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskAssignRuleService; import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -45,7 +45,7 @@ public class BpmActivitiConfiguration { } @Bean - public BpmActivityBehaviorFactory bpmActivityBehaviorFactory(BpmTaskRuleService taskRuleService) { + public BpmActivityBehaviorFactory bpmActivityBehaviorFactory(BpmTaskAssignRuleService taskRuleService) { BpmActivityBehaviorFactory bpmActivityBehaviorFactory = new BpmActivityBehaviorFactory(); bpmActivityBehaviorFactory.setBpmTaskRuleService(taskRuleService); return bpmActivityBehaviorFactory; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/core/behavior/BpmActivityBehaviorFactory.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/core/behavior/BpmActivityBehaviorFactory.java index a6b9e5fae..b9a4035ff 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/core/behavior/BpmActivityBehaviorFactory.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/core/behavior/BpmActivityBehaviorFactory.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.behavior; -import cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.behavior.BpmUserTaskActivitiBehavior; -import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskRuleService; +import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskAssignRuleService; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.Setter; @@ -22,7 +21,7 @@ import org.activiti.engine.impl.bpmn.parser.factory.DefaultActivityBehaviorFacto public class BpmActivityBehaviorFactory extends DefaultActivityBehaviorFactory { @Setter - private BpmTaskRuleService bpmTaskRuleService; + private BpmTaskAssignRuleService bpmTaskRuleService; @Override public UserTaskActivityBehavior createUserTaskActivityBehavior(UserTask userTask) { diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/core/behavior/BpmUserTaskActivitiBehavior.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/core/behavior/BpmUserTaskActivitiBehavior.java index 71f76e207..9858c39cb 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/core/behavior/BpmUserTaskActivitiBehavior.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/core/behavior/BpmUserTaskActivitiBehavior.java @@ -3,11 +3,10 @@ package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.behavio import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.StrUtil; -import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmTaskRuleDO; -import cn.iocoder.yudao.adminserver.modules.bpm.enums.definition.BpmTaskRuleTypeEnum; -import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskRuleService; +import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO; +import cn.iocoder.yudao.adminserver.modules.bpm.enums.definition.BpmTaskAssignRuleTypeEnum; +import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskAssignRuleService; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; -import cn.iocoder.yudao.framework.common.util.collection.SetUtils; import lombok.Setter; import org.activiti.bpmn.model.UserTask; import org.activiti.engine.ActivitiException; @@ -29,7 +28,7 @@ import java.util.Set; public class BpmUserTaskActivitiBehavior extends UserTaskActivityBehavior { @Setter - private BpmTaskRuleService bpmTaskRuleService; + private BpmTaskAssignRuleService bpmTaskRuleService; public BpmUserTaskActivitiBehavior(UserTask userTask) { super(userTask); @@ -40,7 +39,7 @@ public class BpmUserTaskActivitiBehavior extends UserTaskActivityBehavior { String assignee, String owner, List candidateUsers, List candidateGroups, TaskEntity task, ExpressionManager expressionManager, DelegateExecution execution) { // 获得任务的规则 - BpmTaskRuleDO rule = getTaskRule(task); + BpmTaskAssignRuleDO rule = getTaskRule(task); // 获得任务的候选用户们 Set candidateUserIds = calculateTaskCandidateUsers(task, rule); // 设置负责人 @@ -53,8 +52,8 @@ public class BpmUserTaskActivitiBehavior extends UserTaskActivityBehavior { } } - private BpmTaskRuleDO getTaskRule(TaskEntity task) { - List taskRules = bpmTaskRuleService.getTaskRulesByProcessDefinitionId(task.getProcessDefinitionId(), + private BpmTaskAssignRuleDO getTaskRule(TaskEntity task) { + List taskRules = bpmTaskRuleService.getTaskAssignRulesByProcessDefinitionId(task.getProcessDefinitionId(), task.getTaskDefinitionKey()); if (CollUtil.isEmpty(taskRules)) { throw new ActivitiException(StrUtil.format("流程任务({}/{}/{}) 找不到符合的任务规则", @@ -73,17 +72,17 @@ public class BpmUserTaskActivitiBehavior extends UserTaskActivityBehavior { return CollUtil.get(candidateUserIds, index); } - private Set calculateTaskCandidateUsers(TaskEntity task, BpmTaskRuleDO rule) { + private Set calculateTaskCandidateUsers(TaskEntity task, BpmTaskAssignRuleDO rule) { Set assigneeUserIds = null; - if (Objects.equals(BpmTaskRuleTypeEnum.ROLE.getType(), rule.getType())) { + if (Objects.equals(BpmTaskAssignRuleTypeEnum.ROLE.getType(), rule.getType())) { assigneeUserIds = calculateTaskCandidateUsersByRole(task, rule); - } else if (Objects.equals(BpmTaskRuleTypeEnum.DEPT.getType(), rule.getType())) { + } else if (Objects.equals(BpmTaskAssignRuleTypeEnum.DEPT.getType(), rule.getType())) { assigneeUserIds = calculateTaskCandidateUsersByDept(task, rule); - } else if (Objects.equals(BpmTaskRuleTypeEnum.DEPT_LEADER.getType(), rule.getType())) { + } else if (Objects.equals(BpmTaskAssignRuleTypeEnum.DEPT_LEADER.getType(), rule.getType())) { assigneeUserIds = calculateTaskCandidateUsersByDept(task, rule); - } else if (Objects.equals(BpmTaskRuleTypeEnum.USER.getType(), rule.getType())) { + } else if (Objects.equals(BpmTaskAssignRuleTypeEnum.USER.getType(), rule.getType())) { assigneeUserIds = calculateTaskCandidateUsersByUser(task, rule); - } else if (Objects.equals(BpmTaskRuleTypeEnum.USER_GROUP.getType(), rule.getType())) { + } else if (Objects.equals(BpmTaskAssignRuleTypeEnum.USER_GROUP.getType(), rule.getType())) { assigneeUserIds = calculateTaskCandidateUsersByUser(task, rule); } @@ -96,28 +95,28 @@ public class BpmUserTaskActivitiBehavior extends UserTaskActivityBehavior { return assigneeUserIds; } - private Set calculateTaskCandidateUsersByRole(TaskEntity task, BpmTaskRuleDO rule) { + private Set calculateTaskCandidateUsersByRole(TaskEntity task, BpmTaskAssignRuleDO rule) { throw new UnsupportedOperationException("暂不支持该任务规则"); } - private Set calculateTaskCandidateUsersByDept(TaskEntity task, BpmTaskRuleDO rule) { + private Set calculateTaskCandidateUsersByDept(TaskEntity task, BpmTaskAssignRuleDO rule) { throw new UnsupportedOperationException("暂不支持该任务规则"); } - private Set calculateTaskCandidateUsersByDeptLeader(TaskEntity task, BpmTaskRuleDO rule) { + private Set calculateTaskCandidateUsersByDeptLeader(TaskEntity task, BpmTaskAssignRuleDO rule) { throw new UnsupportedOperationException("暂不支持该任务规则"); } - private Set calculateTaskCandidateUsersByUser(TaskEntity task, BpmTaskRuleDO rule) { + private Set calculateTaskCandidateUsersByUser(TaskEntity task, BpmTaskAssignRuleDO rule) { return rule.getOptions(); } - private Set calculateTaskCandidateUsersByUserGroup(TaskEntity task, BpmTaskRuleDO rule) { + private Set calculateTaskCandidateUsersByUserGroup(TaskEntity task, BpmTaskAssignRuleDO rule) { throw new UnsupportedOperationException("暂不支持该任务规则"); } - private Set calculateTaskCandidateUsersByScript(TaskEntity task, BpmTaskRuleDO rule) { + private Set calculateTaskCandidateUsersByScript(TaskEntity task, BpmTaskAssignRuleDO rule) { throw new UnsupportedOperationException("暂不支持该任务规则"); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmModelService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmModelService.java index f13d5e1ad..496f9a45f 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmModelService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmModelService.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.definition; import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.model.*; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import org.activiti.bpmn.model.BpmnModel; import javax.validation.Valid; @@ -66,4 +67,12 @@ public interface BpmModelService { */ void updateModelState(String id, Integer state); + /** + * 获得流程模型编号对应的 BPMN Model + * + * @param id 流程模型编号 + * @return BPMN Model + */ + BpmnModel getBpmnModel(String id); + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmTaskAssignRuleService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmTaskAssignRuleService.java new file mode 100644 index 000000000..b5fff6878 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmTaskAssignRuleService.java @@ -0,0 +1,47 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.service.definition; + +import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule.BpmTaskAssignRuleRespVO; +import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO; +import org.springframework.lang.Nullable; + +import java.util.List; + +/** + * BPM 任务分配规则 Service 接口 + * + * @author 芋道源码 + */ +public interface BpmTaskAssignRuleService { + + /** + * 获得流程定义的任务分配规则数组 + * + * @param processDefinitionId 流程定义的编号 + * @param taskDefinitionKey 流程任务定义的 Key。允许空 + * @return 任务规则数组 + */ + List getTaskAssignRulesByProcessDefinitionId(String processDefinitionId, + @Nullable String taskDefinitionKey); + + /** + * 获得流程模型的任务规则数组 + * + * @param modelId 流程模型的编号 + * @return 任务规则数组 + */ + List getTaskAssignRulesByModelId(String modelId); + + + /** + * 获得流程定义的任务分配规则数组 + * + * @param processDefinitionId 流程模型的编号 + * @param processDefinitionId 流程定义的编号 + * @return 任务规则数组 + */ + List getTaskAssignRules(String modelId, String processDefinitionId); + + // TODO 芋艿:创建任务规则 + // TODO 芋艿:复制任务规则 + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmTaskRuleService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmTaskRuleService.java deleted file mode 100644 index 6e93903a8..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmTaskRuleService.java +++ /dev/null @@ -1,36 +0,0 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.service.definition; - -import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmTaskRuleDO; -import org.springframework.lang.Nullable; - -import java.util.List; - -/** - * BPM 任务规则 Service 接口 - * - * @author 芋道源码 - */ -public interface BpmTaskRuleService { - - /** - * 获得流程定义的任务规则数组 - * - * @param processDefinitionId 流程定义的编号 - * @param taskDefinitionKey 流程任务定义的 Key。允许空 - * @return 任务规则数组 - */ - List getTaskRulesByProcessDefinitionId(String processDefinitionId, - @Nullable String taskDefinitionKey); - - /** - * 获得流程模型的任务规则数组 - * - * @param modelId 流程模型的编号 - * @return 任务规则数组 - */ - List getTaskRulesByModelId(Long modelId); - - // TODO 芋艿:创建任务规则 - // TODO 芋艿:复制任务规则 - -} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmModelServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmModelServiceImpl.java index a12ef5880..348bee105 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmModelServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmModelServiceImpl.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.definition.impl; +import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.model.*; import cn.iocoder.yudao.adminserver.modules.bpm.convert.definition.BpmModelConvert; @@ -9,6 +10,7 @@ import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmDefini import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmFormService; import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmModelService; import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmModelMetaInfoRespDTO; +import cn.iocoder.yudao.framework.activiti.core.util.ActivitiUtils; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; @@ -210,6 +212,15 @@ public class BpmModelServiceImpl implements BpmModelService { bpmProcessDefinitionService.updateProcessDefinitionState(definition.getId(), state); } + @Override + public BpmnModel getBpmnModel(String id) { + byte[] bpmnBytes = repositoryService.getModelEditorSource(id); + if (ArrayUtil.isEmpty(bpmnBytes)) { + return null; + } + return ActivitiUtils.buildBpmnModel(bpmnBytes); + } + private Model getModelByKey(String key) { return repositoryService.createModelQuery().modelKey(key).singleResult(); } 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 df9499011..8ab85ed79 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 @@ -6,7 +6,7 @@ import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.process import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.process.BpmProcessDefinitionPageItemRespVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.process.BpmProcessDefinitionPageReqVO; import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.process.BpmProcessDefinitionRespVO; -import cn.iocoder.yudao.adminserver.modules.bpm.convert.definition.BpmDefinitionConvert; +import cn.iocoder.yudao.adminserver.modules.bpm.convert.definition.BpmProcessDefinitionConvert; import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmProcessDefinitionExtDO; import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmFormDO; import cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.definition.BpmProcessDefinitionExtMapper; @@ -90,7 +90,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ // 拼接结果 long definitionCount = definitionQuery.count(); - return new PageResult<>(BpmDefinitionConvert.INSTANCE.convertList(processDefinitions, deploymentMap, + return new PageResult<>(BpmProcessDefinitionConvert.INSTANCE.convertList(processDefinitions, deploymentMap, processDefinitionDOMap, formMap), definitionCount); } @@ -112,7 +112,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ Map processDefinitionDOMap = CollectionUtils.convertMap(processDefinitionDOs, BpmProcessDefinitionExtDO::getProcessDefinitionId); // 执行查询,并返回 - return BpmDefinitionConvert.INSTANCE.convertList3(processDefinitions, processDefinitionDOMap); + return BpmProcessDefinitionConvert.INSTANCE.convertList3(processDefinitions, processDefinitionDOMap); } @Override @@ -196,7 +196,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ } // 插入拓展表 - BpmProcessDefinitionExtDO definitionDO = BpmDefinitionConvert.INSTANCE.convert2(createReqDTO) + BpmProcessDefinitionExtDO definitionDO = BpmProcessDefinitionConvert.INSTANCE.convert2(createReqDTO) .setProcessDefinitionId(definition.getId()); processDefinitionMapper.insert(definitionDO); return definition.getId(); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmTaskAssignRuleServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmTaskAssignRuleServiceImpl.java new file mode 100644 index 000000000..a39bc8792 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmTaskAssignRuleServiceImpl.java @@ -0,0 +1,79 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.service.definition.impl; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule.BpmTaskAssignRuleRespVO; +import cn.iocoder.yudao.adminserver.modules.bpm.convert.definition.BpmTaskAssignRuleConvert; +import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO; +import cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.definition.BpmTaskAssignRuleMapper; +import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmModelService; +import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmProcessDefinitionService; +import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskAssignRuleService; +import cn.iocoder.yudao.framework.activiti.core.util.ActivitiUtils; +import lombok.extern.slf4j.Slf4j; +import org.activiti.bpmn.model.BpmnModel; +import org.activiti.bpmn.model.UserTask; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.util.Collections; +import java.util.List; + +/** + * BPM 任务分配规则 Service 实现类 + */ +@Service +@Validated +@Slf4j +public class BpmTaskAssignRuleServiceImpl implements BpmTaskAssignRuleService { + + @Resource + private BpmTaskAssignRuleMapper taskRuleMapper; + + @Resource + @Lazy // 解决循环依赖 + private BpmModelService modelService; + @Resource + @Lazy // 解决循环依赖 + private BpmProcessDefinitionService processDefinitionService; + + @Override + public List getTaskAssignRulesByProcessDefinitionId(String processDefinitionId, + String taskDefinitionKey) { + return taskRuleMapper.selectListByProcessDefinitionId(processDefinitionId, taskDefinitionKey); + } + + @Override + public List getTaskAssignRulesByModelId(String modelId) { + return taskRuleMapper.selectListByModelId(modelId); + } + + @Override + public List getTaskAssignRules(String modelId, String processDefinitionId) { + // 获得规则 + List rules = Collections.emptyList(); + BpmnModel model = null; + if (StrUtil.isNotEmpty(modelId)) { + rules = getTaskAssignRulesByModelId(modelId); + model = modelService.getBpmnModel(modelId); + } else if (StrUtil.isNotEmpty(processDefinitionId)) { + rules = getTaskAssignRulesByProcessDefinitionId(processDefinitionId, null); + model = processDefinitionService.getBpmnModel(processDefinitionId); + } + if (CollUtil.isEmpty(rules) || model == null) { + return Collections.emptyList(); + } + + // 获得用户任务,只有用户任务才可以设置分配规则 + List userTasks = ActivitiUtils.getBpmnModelElements(model, UserTask.class); + if (CollUtil.isEmpty(userTasks)) { + return Collections.emptyList(); + } + + // 转换数据 + return BpmTaskAssignRuleConvert.INSTANCE.convertList(userTasks, rules); + } + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmTaskRuleServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmTaskRuleServiceImpl.java deleted file mode 100644 index 89f655381..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmTaskRuleServiceImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.service.definition.impl; - -import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.definition.BpmTaskRuleDO; -import cn.iocoder.yudao.adminserver.modules.bpm.dal.mysql.definition.BpmTaskRuleMapper; -import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmTaskRuleService; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; - -import javax.annotation.Resource; -import java.util.List; - -/** - * BPM 任务规则 Service 实现类 - */ -@Service -@Validated -@Slf4j -public class BpmTaskRuleServiceImpl implements BpmTaskRuleService { - - @Resource - private BpmTaskRuleMapper taskRuleMapper; - - @Override - public List getTaskRulesByProcessDefinitionId(String processDefinitionId, - String taskDefinitionKey) { - return taskRuleMapper.selectListByProcessDefinitionId(processDefinitionId, taskDefinitionKey); - } - - @Override - public List getTaskRulesByModelId(Long modelId) { - return null; - } - -} diff --git a/yudao-framework/yudao-spring-boot-starter-activiti/src/main/java/cn/iocoder/yudao/framework/activiti/core/util/ActivitiUtils.java b/yudao-framework/yudao-spring-boot-starter-activiti/src/main/java/cn/iocoder/yudao/framework/activiti/core/util/ActivitiUtils.java index df229a8ba..465094331 100644 --- a/yudao-framework/yudao-spring-boot-starter-activiti/src/main/java/cn/iocoder/yudao/framework/activiti/core/util/ActivitiUtils.java +++ b/yudao-framework/yudao-spring-boot-starter-activiti/src/main/java/cn/iocoder/yudao/framework/activiti/core/util/ActivitiUtils.java @@ -4,11 +4,15 @@ import cn.hutool.core.util.ReflectUtil; import com.alibaba.ttl.TransmittableThreadLocal; import org.activiti.bpmn.converter.BpmnXMLConverter; import org.activiti.bpmn.model.BpmnModel; -import org.activiti.engine.history.HistoricProcessInstance; +import org.activiti.bpmn.model.FlowElement; +import org.activiti.bpmn.model.Process; import org.activiti.engine.impl.identity.Authentication; -import org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntityImpl; -import org.activiti.engine.impl.persistence.entity.HistoricScopeInstanceEntityImpl; -import org.activiti.engine.impl.util.io.StringStreamSource; +import org.activiti.engine.impl.util.io.BytesStreamSource; + +import javax.xml.bind.Element; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; /** * Activiti 工具类 @@ -42,4 +46,29 @@ public class ActivitiUtils { // ========== BPMN XML 相关 ========== + + /** + * 构建对应的 BPMN Model + * + * @param bpmnBytes 原始的 BPMN XML 字节数组 + * @return BPMN Model + */ + public static BpmnModel buildBpmnModel(byte[] bpmnBytes) { + // 转换成 BpmnModel 对象 + BpmnXMLConverter converter = new BpmnXMLConverter(); + return converter.convertToBpmnModel(new BytesStreamSource(bpmnBytes), true, true); + } + + public static List getBpmnModelElements(BpmnModel model, Class clazz) { + List result = new ArrayList<>(); + model.getProcesses().forEach(process -> { + process.getFlowElements().forEach(flowElement -> { + if (flowElement.getClass().isAssignableFrom(clazz)) { + result.add((T) flowElement); + } + }); + }); + return result; + } + }