From 645fd7624b8238ae251bb7f36acbeaf84b3dcc14 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 10 Jan 2022 21:02:13 +0800 Subject: [PATCH 01/24] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20BpmUserTaskActivitiB?= =?UTF-8?q?ehavior=20=E8=87=AA=E5=AE=9A=E4=B9=89=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=EF=BC=8C=E4=B8=BA=E5=90=8E=E7=BB=AD=E5=81=9A=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E7=9A=84=E4=BB=BB=E5=8A=A1=E5=88=86=E9=85=8D=E6=9C=BA?= =?UTF-8?q?=E5=88=B6=E5=81=9A=E5=87=86=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../activiti/BpmActivitiConfiguration.java | 26 ---------- .../config/BpmActivitiConfiguration.java | 51 +++++++++++++++++++ .../behavior/BpmActivityBehaviorFactory.java | 31 +++++++++++ .../behavior/BpmUserTaskActivitiBehavior.java | 31 +++++++++++ .../BpmProcessInstanceEventListener.java | 2 +- .../BpmTackActivitiEventListener.java | 2 +- .../core}/listener/BpmTaskEventListener.java | 19 +++++-- .../model/impl/BpmModelServiceImpl.java | 12 +++++ .../impl/BpmProcessInstanceServiceImpl.java | 4 +- 9 files changed, 144 insertions(+), 34 deletions(-) delete mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/BpmActivitiConfiguration.java create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/config/BpmActivitiConfiguration.java create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/core/behavior/BpmActivityBehaviorFactory.java create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/core/behavior/BpmUserTaskActivitiBehavior.java rename yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/{service/task => framework/activiti/core}/listener/BpmProcessInstanceEventListener.java (96%) rename yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/{service/task => framework/activiti/core}/listener/BpmTackActivitiEventListener.java (95%) rename yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/{service/task => framework/activiti/core}/listener/BpmTaskEventListener.java (65%) 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 deleted file mode 100644 index 6101d2d46..000000000 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/BpmActivitiConfiguration.java +++ /dev/null @@ -1,26 +0,0 @@ -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) { - // 注册监听器,例如说 BpmActivitiEventListener - configuration.setEventListeners(Collections.singletonList(taskActivitiEventListener)); - } - -} 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 new file mode 100644 index 000000000..9a02efc6d --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/config/BpmActivitiConfiguration.java @@ -0,0 +1,51 @@ +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 org.activiti.spring.boot.ProcessEngineConfigurationConfigurer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import java.util.Collections; + +import static org.activiti.spring.boot.ProcessEngineAutoConfiguration.BEHAVIOR_FACTORY_MAPPING_CONFIGURER; + +/** + * BPM 模块的 Activiti 配置类 + */ +@Configuration +public class BpmActivitiConfiguration { + + /** + * BPM 模块的 ProcessEngineConfigurationConfigurer 实现类,主要设置各种监听器 + */ + @Bean + public ProcessEngineConfigurationConfigurer bpmProcessEngineConfigurationConfigurer( + BpmTackActivitiEventListener taskActivitiEventListener) { + return configuration -> { + // 注册监听器,例如说 BpmActivitiEventListener + configuration.setEventListeners(Collections.singletonList(taskActivitiEventListener)); + }; + } + + /** + * 用于设置自定义的 ActivityBehaviorFactory 实现的 ProcessEngineConfigurationConfigurer 实现类 + * + * 目的:覆盖 {@link org.activiti.spring.boot.ProcessEngineAutoConfiguration} 的 + * defaultActivityBehaviorFactoryMappingConfigurer 方法创建的 Bean + */ + @Bean(name = BEHAVIOR_FACTORY_MAPPING_CONFIGURER) + public ProcessEngineConfigurationConfigurer defaultActivityBehaviorFactoryMappingConfigurer( + BpmActivityBehaviorFactory bpmActivityBehaviorFactory) { + return configuration -> { + // 设置 ActivityBehaviorFactory 实现类,用于流程任务的审核人的自定义 + configuration.setActivityBehaviorFactory(bpmActivityBehaviorFactory); + }; + } + + @Bean + public BpmActivityBehaviorFactory bpmActivityBehaviorFactory() { + return new 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 new file mode 100644 index 000000000..bbf652833 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/core/behavior/BpmActivityBehaviorFactory.java @@ -0,0 +1,31 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.behavior; + +import cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.behavior.BpmUserTaskActivitiBehavior; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; +import org.activiti.bpmn.model.UserTask; +import org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior; +import org.activiti.engine.impl.bpmn.parser.factory.DefaultActivityBehaviorFactory; + +/** + * 自定义的 ActivityBehaviorFactory 实现类,目的如下: + * 1. 自定义 {@link #createUserTaskActivityBehavior(UserTask)}:实现自定义的流程任务的 assignee 负责人的分配 + * + * @author 芋道源码 + */ +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class BpmActivityBehaviorFactory extends DefaultActivityBehaviorFactory { + + @Override + public UserTaskActivityBehavior createUserTaskActivityBehavior(UserTask userTask) { + return new BpmUserTaskActivitiBehavior(userTask); + } + + // TODO 芋艿:并行任务 ParallelMultiInstanceBehavior + + // TODO 芋艿:并行任务 SequentialMultiInstanceBehavior + +} 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 new file mode 100644 index 000000000..e66b4b336 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/core/behavior/BpmUserTaskActivitiBehavior.java @@ -0,0 +1,31 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.behavior; + +import org.activiti.bpmn.model.UserTask; +import org.activiti.engine.delegate.DelegateExecution; +import org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior; +import org.activiti.engine.impl.el.ExpressionManager; +import org.activiti.engine.impl.persistence.entity.TaskEntity; +import org.activiti.engine.impl.persistence.entity.TaskEntityManager; + +import java.util.List; + +/** + * 自定义的流程任务的 assignee 负责人的分配 + * + * @author 芋道源码 + */ +public class BpmUserTaskActivitiBehavior extends UserTaskActivityBehavior { + + public BpmUserTaskActivitiBehavior(UserTask userTask) { + super(userTask); + } + + @Override + protected void handleAssignments(TaskEntityManager taskEntityManager, + String assignee, String owner, List candidateUsers, List candidateGroups, + TaskEntity task, ExpressionManager expressionManager, DelegateExecution execution) { + System.out.println(""); + taskEntityManager.changeTaskAssignee(task, "1"); + } + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/listener/BpmProcessInstanceEventListener.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/core/listener/BpmProcessInstanceEventListener.java similarity index 96% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/listener/BpmProcessInstanceEventListener.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/core/listener/BpmProcessInstanceEventListener.java index 3b1268a29..0fe462bf5 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/listener/BpmProcessInstanceEventListener.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/core/listener/BpmProcessInstanceEventListener.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.service.task.listener; +package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.listener; import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.task.BpmProcessInstanceExtDO; import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmProcessInstanceService; 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/framework/activiti/core/listener/BpmTackActivitiEventListener.java similarity index 95% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/listener/BpmTackActivitiEventListener.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/core/listener/BpmTackActivitiEventListener.java index de46ebcd3..307263e0c 100644 --- 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/framework/activiti/core/listener/BpmTackActivitiEventListener.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.service.task.listener; +package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.listener; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmProcessDefinitionService; 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/framework/activiti/core/listener/BpmTaskEventListener.java similarity index 65% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/listener/BpmTaskEventListener.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/core/listener/BpmTaskEventListener.java index cc3b665f5..241782a87 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/framework/activiti/core/listener/BpmTaskEventListener.java @@ -1,10 +1,14 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.service.task.listener; +package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.listener; import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.task.BpmTaskExtDO; import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmTaskService; +import org.activiti.api.model.shared.event.RuntimeEvent; +import org.activiti.api.process.model.ProcessInstance; +import org.activiti.api.process.model.events.ProcessRuntimeEvent; import org.activiti.api.task.model.Task; import org.activiti.api.task.model.events.TaskRuntimeEvent; import org.activiti.api.task.runtime.events.listener.TaskEventListener; +import org.activiti.api.task.runtime.events.listener.TaskRuntimeEventListener; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; @@ -16,15 +20,22 @@ import javax.annotation.Resource; * @author 芋道源码 */ @Component -public class BpmTaskEventListener> - implements TaskEventListener { +public class BpmTaskEventListener> + implements TaskRuntimeEventListener { @Resource @Lazy // 解决循环依赖 private BpmTaskService taskService; @Override - public void onEvent(T event) { + @SuppressWarnings("unchecked") + public void onEvent(T rawEvent) { + // 由于 TaskRuntimeEventListener 无法保证只监听 TaskRuntimeEvent 事件,所以通过这样的方式 + if (!(rawEvent instanceof TaskRuntimeEvent)) { + return; + } + TaskRuntimeEvent event = (TaskRuntimeEvent) rawEvent; + // 创建时,插入拓展表 if (event.getEventType() == TaskRuntimeEvent.TaskEvents.TASK_CREATED) { taskService.createTaskExt(event.getEntity()); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/impl/BpmModelServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/impl/BpmModelServiceImpl.java index 29b72efdc..1900457ba 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/impl/BpmModelServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/impl/BpmModelServiceImpl.java @@ -15,8 +15,11 @@ import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.common.util.object.PageUtils; import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils; import lombok.extern.slf4j.Slf4j; +import org.activiti.bpmn.converter.BpmnXMLConverter; +import org.activiti.bpmn.model.BpmnModel; import org.activiti.engine.RepositoryService; import org.activiti.engine.impl.persistence.entity.SuspensionState; +import org.activiti.engine.impl.util.io.StringStreamSource; import org.activiti.engine.repository.Deployment; import org.activiti.engine.repository.Model; import org.activiti.engine.repository.ModelQuery; @@ -27,6 +30,8 @@ import org.springframework.util.ObjectUtils; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -211,4 +216,11 @@ public class BpmModelServiceImpl implements BpmModelService { } } +// public static void main(String[] args) { +// // 创建转换对象 +// BpmnXMLConverter converter = new BpmnXMLConverter(); +// BpmnModel bpmnModel = converter.convertToBpmnModel(new StringStreamSource(""), true, true); +// bpmnModel.getProcesses() +// } + } 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 6f00bf5c1..e738da0a6 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 @@ -87,8 +87,8 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService runtimeService.setProcessInstanceName(instance.getId(), definition.getName()); // TODO 芋艿:临时使用, 保证分配 - List tasks = taskService.getTasksByProcessInstanceId(instance.getId()); - tasks.forEach(task -> taskService.updateTaskAssign(task.getId(), userId)); +// List tasks = taskService.getTasksByProcessInstanceId(instance.getId()); +// tasks.forEach(task -> taskService.updateTaskAssign(task.getId(), userId)); // 添加初始的评论 TODO 芋艿:在思考下 // Task task = taskService.createTaskQuery().processInstanceId(instance.getId()).singleResult(); From 8999b7db3bd31604681fa96a15b5b38bf858faf5 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 11 Jan 2022 01:10:52 +0800 Subject: [PATCH 02/24] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=9A=84=E8=A7=84=E5=88=99=20BpmTaskRuleDO?= =?UTF-8?q?=20=E8=A1=A8=E7=9A=84=E8=AE=BE=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/model/BpmModelController.java | 2 +- .../bpm/convert/model/BpmModelConvert.java | 2 +- .../dataobject/definition/BpmTaskRuleDO.java | 76 +++++++++++++++++++ .../definition/BpmTaskRuleScriptEnum.java | 27 +++++++ .../enums/definition/BpmTaskRuleTypeEnum.java | 36 +++++++++ .../BpmModelService.java | 2 +- .../dto/BpmModelMetaInfoRespDTO.java | 2 +- .../impl/BpmModelServiceImpl.java | 20 +++-- 8 files changed, 152 insertions(+), 15 deletions(-) create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmTaskRuleDO.java create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/definition/BpmTaskRuleScriptEnum.java create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/definition/BpmTaskRuleTypeEnum.java rename yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/{model => definition}/BpmModelService.java (95%) rename yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/{model => definition}/dto/BpmModelMetaInfoRespDTO.java (83%) rename yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/{model => definition}/impl/BpmModelServiceImpl.java (93%) diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java index 9da0a7166..ecd1c430c 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java @@ -2,7 +2,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.controller.model; import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.*; import cn.iocoder.yudao.adminserver.modules.bpm.convert.model.BpmModelConvert; -import cn.iocoder.yudao.adminserver.modules.bpm.service.model.BpmModelService; +import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmModelService; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.io.IoUtils; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/BpmModelConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/BpmModelConvert.java index d52118da5..17343f106 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/BpmModelConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/BpmModelConvert.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.adminserver.modules.bpm.convert.model; import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.*; import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO; import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmDefinitionCreateReqDTO; -import cn.iocoder.yudao.adminserver.modules.bpm.service.model.dto.BpmModelMetaInfoRespDTO; +import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmModelMetaInfoRespDTO; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import org.activiti.engine.impl.persistence.entity.SuspensionState; 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/BpmTaskRuleDO.java new file mode 100644 index 000000000..3494c79b1 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmTaskRuleDO.java @@ -0,0 +1,76 @@ +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.framework.mybatis.core.dataobject.BaseDO; +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; + +/** + * Bpm 任务规则表 + * + * @author 芋道源码 + */ +@TableName(value = "bpm_task_rule", autoResultMap = true) +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class BpmTaskRuleDO extends BaseDO { + + /** + * 编号 + */ + @TableId + private Long id; + + /** + * 流程模型编号 + * + * 关联 {@link Model#getId()} + */ + private String modelId; + /** + * 流程定义编号 + * + * 关联 {@link ProcessDefinition#getId()} + */ + private String processDefinitionId; + /** + * 流程任务的定义 Key + * + * 关联 {@link Task#getTaskDefinitionKey()} + */ + private String taskDefinitionKey; + + /** + * 规则类型 + * + * 枚举 {@link BpmTaskRuleTypeEnum} + */ + private Integer type; + /** + * 规则值数组,一般关联指定表的编号 + * 根据 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()} 标识 + */ + @TableField(typeHandler = JacksonTypeHandler.class) + private List values; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/definition/BpmTaskRuleScriptEnum.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/definition/BpmTaskRuleScriptEnum.java new file mode 100644 index 000000000..0f49d2191 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/definition/BpmTaskRuleScriptEnum.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.enums.definition; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * BPM 任务规则的脚本枚举 + * 目前暂时通过 TODO 硬编码,未来可以考虑 Groovy 动态脚本的方式 + * + * @author 芋道源码 + */ +@Getter +@AllArgsConstructor +public class BpmTaskRuleScriptEnum { + + ; + + /** + * 脚本编号 + */ + private final Long id; + /** + * 脚本描述 + */ + private final String desc; + +} 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/BpmTaskRuleTypeEnum.java new file mode 100644 index 000000000..16cf1dc7c --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/definition/BpmTaskRuleTypeEnum.java @@ -0,0 +1,36 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.enums.definition; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * BPM 任务规则的类型枚举 + * + * @author 芋道源码 + */ +@Getter +@AllArgsConstructor +public enum BpmTaskRuleTypeEnum { + + ROLE(10, "指定角色"), + + DEPT(20, "指定部门"), + DEPT_LEADER(21, "指定部门的负责人"), + + USER(30, "指定用户"), + + USER_GROUP(40, "指定用户组"), // TODO 芋艿:预留,暂未实现 + + SCRIPT(50, "指定脚本"), // 例如说,发起人所在部门的领导、发起人所在部门的领导的领导 + ; + + /** + * 类型 + */ + private final Integer type; + /** + * 描述 + */ + private final String desc; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmModelService.java similarity index 95% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmModelService.java index 1d1d2fd1d..48e715458 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/BpmModelService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmModelService.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.service.model; +package cn.iocoder.yudao.adminserver.modules.bpm.service.definition; import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.*; import cn.iocoder.yudao.framework.common.pojo.PageResult; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/dto/BpmModelMetaInfoRespDTO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/dto/BpmModelMetaInfoRespDTO.java similarity index 83% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/dto/BpmModelMetaInfoRespDTO.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/dto/BpmModelMetaInfoRespDTO.java index a3f97002c..f52bbb2c3 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/dto/BpmModelMetaInfoRespDTO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/dto/BpmModelMetaInfoRespDTO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.service.model.dto; +package cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto; import lombok.Data; diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/impl/BpmModelServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmModelServiceImpl.java similarity index 93% rename from yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/impl/BpmModelServiceImpl.java rename to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmModelServiceImpl.java index 1900457ba..bf0654377 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/model/impl/BpmModelServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmModelServiceImpl.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.adminserver.modules.bpm.service.model.impl; +package cn.iocoder.yudao.adminserver.modules.bpm.service.definition.impl; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.adminserver.modules.bpm.controller.model.vo.*; @@ -7,8 +7,8 @@ import cn.iocoder.yudao.adminserver.modules.bpm.dal.dataobject.form.BpmFormDO; import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.BpmProcessDefinitionService; import cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto.BpmDefinitionCreateReqDTO; import cn.iocoder.yudao.adminserver.modules.bpm.service.form.BpmFormService; -import cn.iocoder.yudao.adminserver.modules.bpm.service.model.BpmModelService; -import cn.iocoder.yudao.adminserver.modules.bpm.service.model.dto.BpmModelMetaInfoRespDTO; +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.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; @@ -30,8 +30,6 @@ import org.springframework.util.ObjectUtils; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamReader; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -216,11 +214,11 @@ public class BpmModelServiceImpl implements BpmModelService { } } -// public static void main(String[] args) { -// // 创建转换对象 -// BpmnXMLConverter converter = new BpmnXMLConverter(); -// BpmnModel bpmnModel = converter.convertToBpmnModel(new StringStreamSource(""), true, true); -// bpmnModel.getProcesses() -// } + public static void main(String[] args) { + // 创建转换对象 + BpmnXMLConverter converter = new BpmnXMLConverter(); + BpmnModel bpmnModel = converter.convertToBpmnModel(new StringStreamSource(""), true, true); + bpmnModel.getProcesses().get(0).getId() + } } From e863b603005e4450d4b9e4f0c7965a9790e7333d Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 11 Jan 2022 13:24:57 +0800 Subject: [PATCH 03/24] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=AE=9E=E7=8E=B0=20Bp?= =?UTF-8?q?mUserTaskActivitiBehavior=20=E7=9A=84=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bpm/convert/model/BpmModelConvert.java | 1 + .../definition/BpmProcessDefinitionExtDO.java | 7 ++ .../dataobject/definition/BpmTaskRuleDO.java | 18 +++- .../mysql/definition/BpmTaskRuleMapper.java | 21 ++++ .../config/BpmActivitiConfiguration.java | 7 +- .../behavior/BpmActivityBehaviorFactory.java | 9 +- .../behavior/BpmUserTaskActivitiBehavior.java | 97 ++++++++++++++++++- .../definition/BpmTaskRuleService.java | 36 +++++++ .../dto/BpmDefinitionCreateReqDTO.java | 5 + .../definition/impl/BpmModelServiceImpl.java | 12 +-- .../impl/BpmTaskRuleServiceImpl.java | 35 +++++++ 11 files changed, 234 insertions(+), 14 deletions(-) create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/definition/BpmTaskRuleMapper.java create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmTaskRuleService.java create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmTaskRuleServiceImpl.java diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/BpmModelConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/BpmModelConvert.java index 17343f106..25c643a90 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/BpmModelConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/BpmModelConvert.java @@ -80,6 +80,7 @@ public interface BpmModelConvert { default BpmDefinitionCreateReqDTO convert2(Model model) { BpmDefinitionCreateReqDTO createReqDTO = new BpmDefinitionCreateReqDTO(); + createReqDTO.setModelId(model.getId()); createReqDTO.setName(model.getName()); createReqDTO.setKey(model.getKey()); createReqDTO.setCategory(model.getCategory()); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmProcessDefinitionExtDO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmProcessDefinitionExtDO.java index 63b5e3382..80f3073f7 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmProcessDefinitionExtDO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/definition/BpmProcessDefinitionExtDO.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.*; +import org.activiti.engine.repository.Model; import org.activiti.engine.repository.ProcessDefinition; /** @@ -33,6 +34,12 @@ public class BpmProcessDefinitionExtDO extends BaseDO { * 关联 {@link ProcessDefinition#getId()} */ private String processDefinitionId; + /** + * 流程模型的编号 + * + * 关联 {@link Model#getId()} + */ + private String modelId; /** * 描述 */ 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/BpmTaskRuleDO.java index 3494c79b1..0f91a64f2 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/BpmTaskRuleDO.java @@ -3,6 +3,7 @@ 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.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; @@ -13,9 +14,14 @@ 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} 值,表示贵改则与流程模型关联 + * 2. 在流程模型部署后,会将他的所有规则记录,复制出一份新部署出来的流程定义,通过设置 {@link #processDefinitionId} 为新的流程定义的编号进行关联 * * @author 芋道源码 */ @@ -28,6 +34,11 @@ import java.util.List; @AllArgsConstructor public class BpmTaskRuleDO extends BaseDO { + /** + * {@link #processDefinitionId} 空串,用于标识属于流程模型,而不属于流程定义 + */ + private static final String PROCESS_DEFINITION_ID_NULL = ""; + /** * 编号 */ @@ -58,6 +69,7 @@ public class BpmTaskRuleDO extends BaseDO { * * 枚举 {@link BpmTaskRuleTypeEnum} */ + @TableField("`type`") private Integer type; /** * 规则值数组,一般关联指定表的编号 @@ -70,7 +82,7 @@ public class BpmTaskRuleDO extends BaseDO { * 5. {@link BpmTaskRuleTypeEnum#USER_GROUP} 时:用户组编号 * 6. {@link BpmTaskRuleTypeEnum#SCRIPT} 时:脚本编号,目前通过 {@link BpmTaskRuleScriptEnum#getId()} 标识 */ - @TableField(typeHandler = JacksonTypeHandler.class) - private List values; + @TableField(typeHandler = JsonLongSetTypeHandler.class) + private Set options; } 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 new file mode 100644 index 000000000..4ba2c282c --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/definition/BpmTaskRuleMapper.java @@ -0,0 +1,21 @@ +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/framework/activiti/config/BpmActivitiConfiguration.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/framework/activiti/config/BpmActivitiConfiguration.java index 9a02efc6d..5f7918424 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,6 +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 org.activiti.spring.boot.ProcessEngineConfigurationConfigurer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -44,8 +45,10 @@ public class BpmActivitiConfiguration { } @Bean - public BpmActivityBehaviorFactory bpmActivityBehaviorFactory() { - return new BpmActivityBehaviorFactory(); + public BpmActivityBehaviorFactory bpmActivityBehaviorFactory(BpmTaskRuleService 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 bbf652833..a6b9e5fae 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,8 +1,10 @@ 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 lombok.Data; import lombok.EqualsAndHashCode; +import lombok.Setter; import lombok.ToString; import org.activiti.bpmn.model.UserTask; import org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior; @@ -19,9 +21,14 @@ import org.activiti.engine.impl.bpmn.parser.factory.DefaultActivityBehaviorFacto @ToString(callSuper = true) public class BpmActivityBehaviorFactory extends DefaultActivityBehaviorFactory { + @Setter + private BpmTaskRuleService bpmTaskRuleService; + @Override public UserTaskActivityBehavior createUserTaskActivityBehavior(UserTask userTask) { - return new BpmUserTaskActivitiBehavior(userTask); + BpmUserTaskActivitiBehavior userTaskActivityBehavior = new BpmUserTaskActivitiBehavior(userTask); + userTaskActivityBehavior.setBpmTaskRuleService(bpmTaskRuleService); + return userTaskActivityBehavior; } // TODO 芋艿:并行任务 ParallelMultiInstanceBehavior 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 e66b4b336..71f76e207 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 @@ -1,6 +1,16 @@ package cn.iocoder.yudao.adminserver.modules.bpm.framework.activiti.core.behavior; +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.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; import org.activiti.engine.delegate.DelegateExecution; import org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior; import org.activiti.engine.impl.el.ExpressionManager; @@ -8,6 +18,8 @@ import org.activiti.engine.impl.persistence.entity.TaskEntity; import org.activiti.engine.impl.persistence.entity.TaskEntityManager; import java.util.List; +import java.util.Objects; +import java.util.Set; /** * 自定义的流程任务的 assignee 负责人的分配 @@ -16,6 +28,9 @@ import java.util.List; */ public class BpmUserTaskActivitiBehavior extends UserTaskActivityBehavior { + @Setter + private BpmTaskRuleService bpmTaskRuleService; + public BpmUserTaskActivitiBehavior(UserTask userTask) { super(userTask); } @@ -24,8 +39,86 @@ public class BpmUserTaskActivitiBehavior extends UserTaskActivityBehavior { protected void handleAssignments(TaskEntityManager taskEntityManager, String assignee, String owner, List candidateUsers, List candidateGroups, TaskEntity task, ExpressionManager expressionManager, DelegateExecution execution) { - System.out.println(""); - taskEntityManager.changeTaskAssignee(task, "1"); + // 获得任务的规则 + BpmTaskRuleDO rule = getTaskRule(task); + // 获得任务的候选用户们 + Set candidateUserIds = calculateTaskCandidateUsers(task, rule); + // 设置负责人 + Long assigneeUserId = chooseTaskAssignee(candidateUserIds); + taskEntityManager.changeTaskAssignee(task, String.valueOf(assigneeUserId)); + // 设置候选人们 + candidateUserIds.remove(assigneeUserId); // 已经成为负责人了,就不要在扮演候选人了 + if (CollUtil.isNotEmpty(candidateUserIds)) { + task.addCandidateUsers(CollectionUtils.convertSet(candidateUserIds, String::valueOf)); + } + } + + private BpmTaskRuleDO getTaskRule(TaskEntity task) { + List taskRules = bpmTaskRuleService.getTaskRulesByProcessDefinitionId(task.getProcessDefinitionId(), + task.getTaskDefinitionKey()); + if (CollUtil.isEmpty(taskRules)) { + throw new ActivitiException(StrUtil.format("流程任务({}/{}/{}) 找不到符合的任务规则", + task.getId(), task.getProcessDefinitionId(), task.getTaskDefinitionKey())); + } + if (taskRules.size() > 1) { + throw new ActivitiException(StrUtil.format("流程任务({}/{}/{}) 找到过多任务规则({})", + task.getId(), task.getProcessDefinitionId(), task.getTaskDefinitionKey(), taskRules.size())); + } + return taskRules.get(0); + } + + private Long chooseTaskAssignee(Set candidateUserIds) { + // TODO 芋艿:未来可以优化下,改成轮询的策略 + int index = RandomUtil.randomInt(candidateUserIds.size()); + return CollUtil.get(candidateUserIds, index); + } + + private Set calculateTaskCandidateUsers(TaskEntity task, BpmTaskRuleDO rule) { + Set assigneeUserIds = null; + if (Objects.equals(BpmTaskRuleTypeEnum.ROLE.getType(), rule.getType())) { + assigneeUserIds = calculateTaskCandidateUsersByRole(task, rule); + } else if (Objects.equals(BpmTaskRuleTypeEnum.DEPT.getType(), rule.getType())) { + assigneeUserIds = calculateTaskCandidateUsersByDept(task, rule); + } else if (Objects.equals(BpmTaskRuleTypeEnum.DEPT_LEADER.getType(), rule.getType())) { + assigneeUserIds = calculateTaskCandidateUsersByDept(task, rule); + } else if (Objects.equals(BpmTaskRuleTypeEnum.USER.getType(), rule.getType())) { + assigneeUserIds = calculateTaskCandidateUsersByUser(task, rule); + } else if (Objects.equals(BpmTaskRuleTypeEnum.USER_GROUP.getType(), rule.getType())) { + assigneeUserIds = calculateTaskCandidateUsersByUser(task, rule); + } + + // TODO 芋艿:统一过滤掉被禁用的用户 + // 如果候选人为空,抛出异常 TODO 芋艿:没候选人的策略选择。1 - 挂起;2 - 直接结束;3 - 强制一个兜底人 + if (CollUtil.isEmpty(assigneeUserIds)) { + throw new ActivitiException(StrUtil.format("流程任务({}/{}/{}) 任务规则({}) 找不到候选人", + task.getId(), task.getProcessDefinitionId(), task.getTaskDefinitionKey())); + } + return assigneeUserIds; + } + + private Set calculateTaskCandidateUsersByRole(TaskEntity task, BpmTaskRuleDO rule) { + throw new UnsupportedOperationException("暂不支持该任务规则"); + } + + + private Set calculateTaskCandidateUsersByDept(TaskEntity task, BpmTaskRuleDO rule) { + throw new UnsupportedOperationException("暂不支持该任务规则"); + } + + private Set calculateTaskCandidateUsersByDeptLeader(TaskEntity task, BpmTaskRuleDO rule) { + throw new UnsupportedOperationException("暂不支持该任务规则"); + } + + private Set calculateTaskCandidateUsersByUser(TaskEntity task, BpmTaskRuleDO rule) { + return rule.getOptions(); + } + + private Set calculateTaskCandidateUsersByUserGroup(TaskEntity task, BpmTaskRuleDO rule) { + throw new UnsupportedOperationException("暂不支持该任务规则"); + } + + private Set calculateTaskCandidateUsersByScript(TaskEntity task, BpmTaskRuleDO rule) { + throw new UnsupportedOperationException("暂不支持该任务规则"); } } 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 new file mode 100644 index 000000000..6e93903a8 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/BpmTaskRuleService.java @@ -0,0 +1,36 @@ +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/dto/BpmDefinitionCreateReqDTO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/dto/BpmDefinitionCreateReqDTO.java index 69948366f..501157af3 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/dto/BpmDefinitionCreateReqDTO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/dto/BpmDefinitionCreateReqDTO.java @@ -10,6 +10,11 @@ import javax.validation.constraints.NotEmpty; @Data public class BpmDefinitionCreateReqDTO { + /** + * 流程模型的编号 + */ + @NotEmpty(message = "流程模型编号不能为空") + private String modelId; /** * 流程标识 */ 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 bf0654377..d27ac9460 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 @@ -214,11 +214,11 @@ public class BpmModelServiceImpl implements BpmModelService { } } - public static void main(String[] args) { - // 创建转换对象 - BpmnXMLConverter converter = new BpmnXMLConverter(); - BpmnModel bpmnModel = converter.convertToBpmnModel(new StringStreamSource(""), true, true); - bpmnModel.getProcesses().get(0).getId() - } +// public static void main(String[] args) { +// // 创建转换对象 +// BpmnXMLConverter converter = new BpmnXMLConverter(); +// BpmnModel bpmnModel = converter.convertToBpmnModel(new StringStreamSource(""), true, true); +// bpmnModel.getProcesses().get(0).getId() +// } } 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 new file mode 100644 index 000000000..89f655381 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/impl/BpmTaskRuleServiceImpl.java @@ -0,0 +1,35 @@ +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; + } + +} From c4950e1b135d31f6678af3e9ca6fe8a47cbf3291 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 11 Jan 2022 20:17:01 +0800 Subject: [PATCH 04/24] =?UTF-8?q?BPM=20=E6=A8=A1=E5=9E=8B=E9=87=8D?= =?UTF-8?q?=E6=9E=84=201=EF=BC=9A=E6=96=B0=E5=BB=BA=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=8F=AA=E5=A1=AB=E5=86=99=20name=E3=80=81de?= =?UTF-8?q?scription=E3=80=81key?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/model/BpmModelController.java | 2 +- .../model/vo/BpmModelCreateReqVO.java | 17 ++- .../model/vo/BpmModelUpdateReqVO.java | 13 ++- .../bpm/convert/model/BpmModelConvert.java | 3 +- .../definition/BpmModelFormTypeEnum.java | 21 ++++ .../dto/BpmModelMetaInfoRespDTO.java | 16 +++ .../definition/impl/BpmModelServiceImpl.java | 3 - .../src/main/resources/application-dev.yaml | 10 +- yudao-admin-ui/src/views/bpm/model/index.vue | 104 +++++++++++------- 9 files changed, 132 insertions(+), 57 deletions(-) create mode 100644 yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/definition/BpmModelFormTypeEnum.java diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java index ecd1c430c..1f58beff7 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/BpmModelController.java @@ -56,7 +56,7 @@ public class BpmModelController { public CommonResult importModel(@Valid BpmModeImportReqVO importReqVO) throws IOException { BpmModelCreateReqVO createReqVO = BpmModelConvert.INSTANCE.convert(importReqVO); // 读取文件 - createReqVO.setBpmnXml(IoUtils.readUtf8(importReqVO.getBpmnFile().getInputStream(), false)); +// createReqVO.setBpmnXml(IoUtils.readUtf8(importReqVO.getBpmnFile().getInputStream(), false)); return success(bpmModelService.createModel(createReqVO)); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelCreateReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelCreateReqVO.java index 871fb2859..94a53a34d 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelCreateReqVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelCreateReqVO.java @@ -10,12 +10,17 @@ import javax.validation.constraints.NotEmpty; @ApiModel("流程模型的创建 Request VO") @Data -@EqualsAndHashCode(callSuper = true) -@ToString(callSuper = true) -public class BpmModelCreateReqVO extends BpmModelBaseVO { +public class BpmModelCreateReqVO { - @ApiModelProperty(value = "BPMN XML", required = true) - @NotEmpty(message = "BPMN XML 不能为空") - private String bpmnXml; + @ApiModelProperty(value = "流程标识", required = true, example = "process_yudao") + @NotEmpty(message = "流程标识不能为空") + private String key; + + @ApiModelProperty(value = "流程名称", required = true, example = "芋道") + @NotEmpty(message = "流程名称不能为空") + private String name; + + @ApiModelProperty(value = "流程描述", example = "我是描述") + private String description; } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelUpdateReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelUpdateReqVO.java index fb1d2a185..5cc6f03ec 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelUpdateReqVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/model/vo/BpmModelUpdateReqVO.java @@ -18,8 +18,19 @@ public class BpmModelUpdateReqVO extends BpmModelBaseVO { @NotEmpty(message = "编号不能为空") private String id; + @ApiModelProperty(value = "流程名称", example = "芋道") + private String name; + + @ApiModelProperty(value = "流程描述", example = "我是描述") + private String description; + + @ApiModelProperty(value = "流程分类", notes = "参见 bpm_model_category 数据字典", example = "1") + private String category; + + @ApiModelProperty(value = "表单编号", example = "1024") + private Long formId; + @ApiModelProperty(value = "BPMN XML", required = true) - @NotEmpty(message = "BPMN XML 不能为空") private String bpmnXml; } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/BpmModelConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/BpmModelConvert.java index 25c643a90..aacf1e17a 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/BpmModelConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/model/BpmModelConvert.java @@ -95,8 +95,7 @@ public interface BpmModelConvert { default void copy(Model model, BpmModelCreateReqVO bean) { model.setName(bean.getName()); model.setKey(bean.getKey()); - model.setCategory(bean.getCategory()); - model.setMetaInfo(JsonUtils.toJsonString(this.buildMetaInfo(bean.getDescription(), bean.getFormId()))); + model.setMetaInfo(JsonUtils.toJsonString(this.buildMetaInfo(bean.getDescription(), null))); } default void copy(Model model, BpmModelUpdateReqVO bean) { diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/definition/BpmModelFormTypeEnum.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/definition/BpmModelFormTypeEnum.java new file mode 100644 index 000000000..917ec0f29 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/definition/BpmModelFormTypeEnum.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.adminserver.modules.bpm.enums.definition; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * BPM 模型的表单类型的枚举 + * + * @author 芋道源码 + */ +@Getter +@AllArgsConstructor +public enum BpmModelFormTypeEnum { + + NORMAL(10, "流程表单"), // 对应 BpmFormDO + CUSTOM(20, "业务表单") // 业务自己定义的表单,自己进行数据的存储 + ; + + private final Integer type; + private final String desc; +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/dto/BpmModelMetaInfoRespDTO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/dto/BpmModelMetaInfoRespDTO.java index f52bbb2c3..651fbf9ca 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/dto/BpmModelMetaInfoRespDTO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/definition/dto/BpmModelMetaInfoRespDTO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.definition.dto; +import cn.iocoder.yudao.adminserver.modules.bpm.enums.definition.BpmModelFormTypeEnum; import lombok.Data; /** @@ -15,9 +16,24 @@ public class BpmModelMetaInfoRespDTO { * 流程描述 */ private String description; + /** + * 表单类型 + */ + private Long formType; /** * 表单编号 + * 在表单类型为 {@link BpmModelFormTypeEnum#NORMAL} 时 */ private Long formId; + /** + * 自定义表单的提交路径,使用 Vue 的路由地址 + * 在表单类型为 {@link BpmModelFormTypeEnum#CUSTOM} 时 + */ + private String formCustomSubmitPath; + /** + * 自定义表单的查看路径,使用 Vue 的路由地址 + * 在表单类型为 {@link BpmModelFormTypeEnum#CUSTOM} 时 + */ + private String formCustomViewPath; } 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 d27ac9460..b0b184138 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 @@ -121,15 +121,12 @@ public class BpmModelServiceImpl implements BpmModelService { BpmModelConvert.INSTANCE.copy(model, createReqVO); // 保存流程定义 repositoryService.saveModel(model); - // 添加 BPMN XML - repositoryService.addModelEditorSource(model.getId(), StrUtil.utf8Bytes(createReqVO.getBpmnXml())); return model.getId(); } @Override @Transactional(rollbackFor = Exception.class) // 因为进行多个 activiti 操作,所以开启事务 public void updateModel(BpmModelUpdateReqVO updateReqVO) { - checkKeyNCName(updateReqVO.getKey()); // 校验流程模型存在 Model model = repositoryService.getModel(updateReqVO.getId()); if (model == null) { diff --git a/yudao-admin-server/src/main/resources/application-dev.yaml b/yudao-admin-server/src/main/resources/application-dev.yaml index e349e3239..57026afec 100644 --- a/yudao-admin-server/src/main/resources/application-dev.yaml +++ b/yudao-admin-server/src/main/resources/application-dev.yaml @@ -63,12 +63,12 @@ spring: # 工作流 Activiti 配置 activiti: - #1.false:默认值,activiti启动时,对比数据库表中保存的版本,如果不匹配。将抛出异常 - #2.true:启动时会对数据库中所有表进行更新操作,如果表存在,不做处理,反之,自动创建表 - #3.create_drop:启动时自动创建表,关闭时自动删除表 - #4.drop_create:启动时,删除旧表,再创建新表 + # 1. false:默认值,activiti启动时,对比数据库表中保存的版本,如果不匹配。将抛出异常 + # 2. true:启动时会对数据库中所有表进行更新操作,如果表存在,不做处理,反之,自动创建表 + # 3. create_drop:启动时自动创建表,关闭时自动删除表 + # 4. drop_create:启动时,删除旧表,再创建新表 database-schema-update: true - #activiti7默认不生成历史信息表,需手动设置开启 + # activiti7 默认不生成历史信息表,需手动设置开启 db-history-used: true check-process-definitions: true #full:保存历史数据的最高级别,可保存全部流程相关细节,包括流程流转各节点参数 diff --git a/yudao-admin-ui/src/views/bpm/model/index.vue b/yudao-admin-ui/src/views/bpm/model/index.vue index 469184fe5..ca9e78b9c 100644 --- a/yudao-admin-ui/src/views/bpm/model/index.vue +++ b/yudao-admin-ui/src/views/bpm/model/index.vue @@ -109,51 +109,50 @@ + + + + + + + + + + + + + + + + + + + - +
将文件拖到此处,或 点击上传
提示:仅允许导入“bpm”或“xml”格式文件!
- - - - -
- + + + + - - - - - - - - - - @@ -169,14 +168,12 @@ From 3f6a5f06fa660f49d492f6511bfece64442b076d Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 13 Jan 2022 10:16:28 +0800 Subject: [PATCH 13/24] =?UTF-8?q?BPM=20=E6=A8=A1=E5=9E=8B=E9=87=8D?= =?UTF-8?q?=E6=9E=84=207=EF=BC=9A=E5=A2=9E=E5=8A=A0=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=88=86=E9=85=8D=E8=A7=84=E5=88=99=E7=9A=84=E5=88=97=E8=A1=A8?= =?UTF-8?q?=20UI=20=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BpmTaskAssignRuleController.java | 17 ++++-- yudao-admin-ui/src/api/bpm/taskAssignRule.js | 16 ++++++ yudao-admin-ui/src/views/bpm/model/index.vue | 55 +++++++++++++++++-- 3 files changed, 79 insertions(+), 9 deletions(-) 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 index 4333f889f..643a5cae5 100644 --- 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 @@ -1,16 +1,15 @@ package cn.iocoder.yudao.adminserver.modules.bpm.controller.definition; +import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule.BpmTaskAssignRuleCreateReqVO; 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 org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.validation.Valid; import java.util.List; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @@ -31,4 +30,14 @@ public class BpmTaskAssignRuleController { return success(taskAssignRuleService.getTaskAssignRuleList(modelId, processDefinitionId)); } + @PostMapping("/create") + public CommonResult createTaskAssignRule(@Valid @RequestBody BpmTaskAssignRuleCreateReqVO reqVO) { + return success("1024"); + } + + @PutMapping("/update") + public CommonResult updateTaskAssignRule(@Valid @RequestBody BpmTaskAssignRuleCreateReqVO reqVO) { + return success(true); + } + } diff --git a/yudao-admin-ui/src/api/bpm/taskAssignRule.js b/yudao-admin-ui/src/api/bpm/taskAssignRule.js index 4c24e3285..a3e60663a 100644 --- a/yudao-admin-ui/src/api/bpm/taskAssignRule.js +++ b/yudao-admin-ui/src/api/bpm/taskAssignRule.js @@ -7,3 +7,19 @@ export function getTaskAssignRuleList(query) { params: query }) } + +export function createTaskAssignRule(data) { + return request({ + url: '/bpm/task-assign-rule/create', + method: 'post', + data: data + }) +} + +export function updateTaskAssignRule(data) { + return request({ + url: '/bpm/task-assign-rule/update', + method: 'put', + data: data + }) +} diff --git a/yudao-admin-ui/src/views/bpm/model/index.vue b/yudao-admin-ui/src/views/bpm/model/index.vue index 2fb73052b..b402a6837 100644 --- a/yudao-admin-ui/src/views/bpm/model/index.vue +++ b/yudao-admin-ui/src/views/bpm/model/index.vue @@ -222,7 +222,7 @@ - + @@ -235,14 +235,14 @@ - +
@@ -263,7 +263,7 @@ import {getForm, getSimpleForms} from "@/api/bpm/form"; import {decodeFields} from "@/utils/formGenerator"; import Parser from '@/components/parser/Parser' import {getBaseHeader} from "@/utils/request"; -import {getTaskAssignRuleList} from "@/api/bpm/taskAssignRule"; +import {createTaskAssignRule, getTaskAssignRuleList, updateTaskAssignRule} from "@/api/bpm/taskAssignRule"; import {listSimpleRoles} from "@/api/system/role"; export default { @@ -597,6 +597,9 @@ export default { }, /** 处理修改任务分配规则的按钮操作 */ handleUpdateTaskAssignRule(row) { + // 先重置标识 + this.resetAssignRuleForm(); + // 设置表单 this.taskAssignRule.form = { ...row, options: [] @@ -606,6 +609,48 @@ export default { this.taskAssignRule.form.role = row.options; } this.taskAssignRule.open = true; + }, + /** 提交任务分配规则的表单 */ + submitAssignRuleForm() { + this.$refs["taskAssignRuleForm"].validate(valid => { + if (valid) { + // 构建表单 + let form = { + ...this.taskAssignRule.form, + taskDefinitionName: undefined, + }; + if (form.type === 10) { + form.options = form.roleIds; + } + form.roleIds = undefined; + // 新增 + if (!form.id) { + createTaskAssignRule(form).then(response => { + this.msgSuccess("修改成功"); + this.taskAssignRule.open = false; + this.doGetTaskAssignRuleList(); + }); + // 修改 + } else { + form.taskDefinitionKey = undefined; // 无法修改 + updateTaskAssignRule(form).then(response => { + this.msgSuccess("修改成功"); + this.taskAssignRule.open = false; + this.doGetTaskAssignRuleList(); + }); + } + } + }); + }, + /** 取消任务分配规则的表单 */ + cancelAssignRuleForm() { + this.taskAssignRule.open = false; + this.resetAssignRuleForm(); + }, + // 表单重置 + resetAssignRuleForm() { + this.taskAssignRule.form = {}; + this.resetForm("taskAssignRuleForm"); } } }; From 9f0cd04fa6bce4ad34bbbc2ba606c66810a4b500 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 13 Jan 2022 13:21:54 +0800 Subject: [PATCH 14/24] =?UTF-8?q?BPM=20=E6=A8=A1=E5=9E=8B=E9=87=8D?= =?UTF-8?q?=E6=9E=84=207=EF=BC=9A=E5=A2=9E=E5=8A=A0=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=88=86=E9=85=8D=E8=A7=84=E5=88=99=E7=9A=84=E5=88=97=E8=A1=A8?= =?UTF-8?q?=20UI=20=E7=95=8C=E9=9D=A2=EF=BC=88=E5=A2=9E=E5=8A=A0=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E7=9A=84=E8=A7=84=E5=88=99=E9=85=8D=E7=BD=AE)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BpmTaskAssignRuleController.java | 4 +- .../vo/rule/BpmTaskAssignRuleCreateReqVO.java | 5 ++- .../definition/BpmTaskAssignRuleConvert.java | 3 ++ .../definition/BpmTaskAssignRuleMapper.java | 8 ++++ .../bpm/enums/BpmErrorCodeConstants.java | 5 ++- .../definition/BpmTaskAssignRuleService.java | 13 ++++++- .../impl/BpmTaskAssignRuleServiceImpl.java | 38 ++++++++++++++++++ .../permission/SysRoleController.java | 2 +- .../system/enums/SysErrorCodeConstants.java | 1 + .../service/permission/SysRoleService.java | 11 +++++- .../permission/impl/SysRoleServiceImpl.java | 39 +++++++++++++------ yudao-admin-ui/src/views/bpm/model/index.vue | 26 +++++++++++-- 12 files changed, 132 insertions(+), 23 deletions(-) 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 index 643a5cae5..4a17d9fc2 100644 --- 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 @@ -31,8 +31,8 @@ public class BpmTaskAssignRuleController { } @PostMapping("/create") - public CommonResult createTaskAssignRule(@Valid @RequestBody BpmTaskAssignRuleCreateReqVO reqVO) { - return success("1024"); + public CommonResult createTaskAssignRule(@Valid @RequestBody BpmTaskAssignRuleCreateReqVO reqVO) { + return success(taskAssignRuleService.createTaskAssignRule(reqVO)); } @PutMapping("/update") 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 index d9a130b7d..13536ea9b 100644 --- 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 @@ -1,7 +1,10 @@ package cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule; -import java.util.Set; +import lombok.Data; +import lombok.EqualsAndHashCode; +@Data +@EqualsAndHashCode(callSuper = true) public class BpmTaskAssignRuleCreateReqVO extends BpmTaskAssignRuleBaseVO { private String modelId; 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 index 2793165db..09d056e1c 100644 --- 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 @@ -1,6 +1,7 @@ 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.BpmTaskAssignRuleCreateReqVO; 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; @@ -33,4 +34,6 @@ public interface BpmTaskAssignRuleConvert { BpmTaskAssignRuleRespVO convert(BpmTaskAssignRuleDO bean); + BpmTaskAssignRuleDO convert(BpmTaskAssignRuleCreateReqVO bean); + } 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 index 6bf5b6cab..14459c80c 100644 --- 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 @@ -24,4 +24,12 @@ public interface BpmTaskAssignRuleMapper extends BaseMapperX() + .eq("model_id", modelId) + .eq("process_definition_id", BpmTaskAssignRuleDO.PROCESS_DEFINITION_ID_NULL) + .eq("task_definition_key", taskDefinitionKey)); + } + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java index 5519347ec..c54131a12 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/enums/BpmErrorCodeConstants.java @@ -37,9 +37,12 @@ public interface BpmErrorCodeConstants { ErrorCode PROCESS_INSTANCE_CANCEL_FAIL_NOT_EXISTS = new ErrorCode(1009004001, "流程取消失败,流程不处于运行中"); ErrorCode PROCESS_INSTANCE_CANCEL_FAIL_NOT_SELF = new ErrorCode(1009004002, "流程取消失败,该流程不是你发起的"); - // ========== 流程实例 1-009-005-000 ========== + // ========== 流程任务 1-009-005-000 ========== ErrorCode TASK_COMPLETE_FAIL_NOT_EXISTS = new ErrorCode(1009004000, "审批任务失败,原因:该任务不处于未审批"); + // ========== 流程任务分配规则 1-009-006-000 ========== + ErrorCode TASK_ASSIGN_RULE_EXISTS = new ErrorCode(1009006000, "流程({}) 的任务({}) 已经存在分配规则"); + // ========== 动态表单模块 1-009-010-000 ========== ErrorCode FORM_NOT_EXISTS = new ErrorCode(1009010000, "动态表单不存在"); ErrorCode FORM_FIELD_REPEAT = new ErrorCode(1009010000, "表单项({}) 和 ({}) 使用了相同的字段名({})"); 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 index 172298808..3c04bfc0b 100644 --- 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 @@ -1,9 +1,11 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.definition; +import cn.iocoder.yudao.adminserver.modules.bpm.controller.definition.vo.rule.BpmTaskAssignRuleCreateReqVO; 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 javax.validation.Valid; import java.util.List; /** @@ -35,13 +37,20 @@ public interface BpmTaskAssignRuleService { /** * 获得流程定义的任务分配规则数组 * - * @param processDefinitionId 流程模型的编号 + * @param modelId 流程模型的编号 * @param processDefinitionId 流程定义的编号 * @return 任务规则数组 */ List getTaskAssignRuleList(String modelId, String processDefinitionId); - // TODO 芋艿:创建任务规则 + /** + * 创建任务分配规则 + * + * @param reqVO 创建信息 + * @return 规则编号 + */ + Long createTaskAssignRule(@Valid BpmTaskAssignRuleCreateReqVO reqVO); + // TODO 芋艿:复制任务规则 } 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 index 8c8d0e3d5..8fcc607e8 100644 --- 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 @@ -2,14 +2,19 @@ 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.BpmTaskAssignRuleCreateReqVO; 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.enums.BpmErrorCodeConstants; +import cn.iocoder.yudao.adminserver.modules.bpm.enums.definition.BpmTaskAssignRuleTypeEnum; 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.adminserver.modules.system.service.permission.SysRoleService; import cn.iocoder.yudao.framework.activiti.core.util.ActivitiUtils; +import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; import lombok.extern.slf4j.Slf4j; import org.activiti.bpmn.model.BpmnModel; import org.activiti.bpmn.model.UserTask; @@ -20,6 +25,10 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.Collections; import java.util.List; +import java.util.Objects; +import java.util.Set; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; /** * BPM 任务分配规则 Service 实现类 @@ -38,6 +47,8 @@ public class BpmTaskAssignRuleServiceImpl implements BpmTaskAssignRuleService { @Resource @Lazy // 解决循环依赖 private BpmProcessDefinitionService processDefinitionService; + @Resource + private SysRoleService roleService; @Override public List getTaskAssignRuleListByProcessDefinitionId(String processDefinitionId, @@ -76,4 +87,31 @@ public class BpmTaskAssignRuleServiceImpl implements BpmTaskAssignRuleService { return BpmTaskAssignRuleConvert.INSTANCE.convertList(userTasks, rules); } + @Override + public Long createTaskAssignRule(BpmTaskAssignRuleCreateReqVO reqVO) { + // 校验参数 + validTaskAssignRuleOptions(reqVO.getType(), reqVO.getOptions()); + // 校验是否已经配置 + BpmTaskAssignRuleDO existRule = taskRuleMapper.selectListByModelIdAndTaskDefinitionKey( + reqVO.getModelId(), reqVO.getTaskDefinitionKey()); + if (existRule != null) { + throw exception(BpmErrorCodeConstants.TASK_ASSIGN_RULE_EXISTS, + reqVO.getModelId(), reqVO.getTaskDefinitionKey()); + } + + // 存储 + BpmTaskAssignRuleDO rule = BpmTaskAssignRuleConvert.INSTANCE.convert(reqVO) + .setProcessDefinitionId(BpmTaskAssignRuleDO.PROCESS_DEFINITION_ID_NULL); // 只有流程模型,才允许新建 + taskRuleMapper.insert(rule); + return rule.getId(); + } + + private void validTaskAssignRuleOptions(Integer type, Set options) { + if (Objects.equals(type, BpmTaskAssignRuleTypeEnum.ROLE.getType())) { + roleService.validRoles(options); + return; + } + + } + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/permission/SysRoleController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/permission/SysRoleController.java index 0fb7d45d9..15d7fa3f8 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/permission/SysRoleController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/permission/SysRoleController.java @@ -97,7 +97,7 @@ public class SysRoleController { @OperateLog(type = EXPORT) @PreAuthorize("@ss.hasPermission('system:role:export')") public void export(HttpServletResponse response, @Validated SysRoleExportReqVO reqVO) throws IOException { - List list = roleService.getRoles(reqVO); + List list = roleService.getRoleList(reqVO); List data = SysRoleConvert.INSTANCE.convertList03(list); // 输出 ExcelUtils.write(response, "角色数据.xls", "角色列表", SysRoleExcelVO.class, data); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/SysErrorCodeConstants.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/SysErrorCodeConstants.java index fed445b9c..b7576c344 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/SysErrorCodeConstants.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/enums/SysErrorCodeConstants.java @@ -31,6 +31,7 @@ public interface SysErrorCodeConstants { ErrorCode ROLE_NAME_DUPLICATE = new ErrorCode(1002003001, "已经存在名为【{}】的角色"); ErrorCode ROLE_CODE_DUPLICATE = new ErrorCode(1002003002, "已经存在编码为【{}】的角色"); ErrorCode ROLE_CAN_NOT_UPDATE_SYSTEM_TYPE_ROLE = new ErrorCode(1002003004, "不能操作类型为系统内置的角色"); + ErrorCode ROLE_IS_DISABLE = new ErrorCode(1002003004, "名字为【{}】的角色已被禁用"); // ========== 用户模块 1002004000 ========== ErrorCode USER_USERNAME_EXISTS = new ErrorCode(1002004000, "用户账号已经存在"); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/permission/SysRoleService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/permission/SysRoleService.java index 4f2672118..4272bab78 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/permission/SysRoleService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/permission/SysRoleService.java @@ -127,6 +127,15 @@ public interface SysRoleService { * @param reqVO 列表查询 * @return 角色列表 */ - List getRoles(SysRoleExportReqVO reqVO); + List getRoleList(SysRoleExportReqVO reqVO); + + /** + * 校验角色们是否有效。如下情况,视为无效: + * 1. 角色编号不存在 + * 2. 角色被禁用 + * + * @param ids 角色编号数组 + */ + void validRoles(Collection ids); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/permission/impl/SysRoleServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/permission/impl/SysRoleServiceImpl.java index 0e82c5051..0c271c3a2 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/permission/impl/SysRoleServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/permission/impl/SysRoleServiceImpl.java @@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollectionUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; import cn.iocoder.yudao.adminserver.modules.system.controller.permission.vo.role.SysRoleCreateReqVO; import cn.iocoder.yudao.adminserver.modules.system.controller.permission.vo.role.SysRoleExportReqVO; @@ -33,9 +34,11 @@ import org.springframework.util.StringUtils; import javax.annotation.PostConstruct; import javax.annotation.Resource; import java.util.*; +import java.util.function.Consumer; import java.util.stream.Collectors; import static cn.iocoder.yudao.adminserver.modules.system.enums.SysErrorCodeConstants.*; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; /** * 角色 Service 实现类 @@ -234,10 +237,30 @@ public class SysRoleServiceImpl implements SysRoleService { } @Override - public List getRoles(SysRoleExportReqVO reqVO) { + public List getRoleList(SysRoleExportReqVO reqVO) { return roleMapper.listRoles(reqVO); } + @Override + public void validRoles(Collection ids) { + if (CollUtil.isEmpty(ids)) { + return; + } + // 获得角色信息 + List roles = roleMapper.selectBatchIds(ids); + Map roleMap = CollectionUtils.convertMap(roles, SysRoleDO::getId); + // 校验 + ids.forEach(id -> { + SysRoleDO role = roleMap.get(id); + if (role == null) { + throw exception(ROLE_NOT_EXISTS); + } + if (!CommonStatusEnum.ENABLE.getStatus().equals(role.getStatus())) { + throw exception(ROLE_IS_DISABLE, role.getName()); + } + }); + } + /** * 校验角色的唯一字段是否重复 * @@ -253,7 +276,7 @@ public class SysRoleServiceImpl implements SysRoleService { // 1. 该 name 名字被其它角色所使用 SysRoleDO role = roleMapper.selectByName(name); if (role != null && !role.getId().equals(id)) { - throw ServiceExceptionUtil.exception(ROLE_NAME_DUPLICATE, name); + throw exception(ROLE_NAME_DUPLICATE, name); } // 2. 是否存在相同编码的角色 if (!StringUtils.hasText(code)) { @@ -262,7 +285,7 @@ public class SysRoleServiceImpl implements SysRoleService { // 该 code 编码被其它角色所使用 role = roleMapper.selectByCode(code); if (role != null && !role.getId().equals(id)) { - throw ServiceExceptionUtil.exception(ROLE_CODE_DUPLICATE, code); + throw exception(ROLE_CODE_DUPLICATE, code); } } @@ -275,18 +298,12 @@ public class SysRoleServiceImpl implements SysRoleService { public void checkUpdateRole(Long id) { SysRoleDO roleDO = roleMapper.selectById(id); if (roleDO == null) { - throw ServiceExceptionUtil.exception(ROLE_NOT_EXISTS); + throw exception(ROLE_NOT_EXISTS); } // 内置角色,不允许删除 if (SysRoleTypeEnum.SYSTEM.getType().equals(roleDO.getType())) { - throw ServiceExceptionUtil.exception(ROLE_CAN_NOT_UPDATE_SYSTEM_TYPE_ROLE); + throw exception(ROLE_CAN_NOT_UPDATE_SYSTEM_TYPE_ROLE); } } -// @Override -// @DataScope(deptAlias = "d") -// public List selectRoleList(SysRole role) { -// return roleMapper.selectRoleList(role); -// } - } diff --git a/yudao-admin-ui/src/views/bpm/model/index.vue b/yudao-admin-ui/src/views/bpm/model/index.vue index b402a6837..22df3d1ed 100644 --- a/yudao-admin-ui/src/views/bpm/model/index.vue +++ b/yudao-admin-ui/src/views/bpm/model/index.vue @@ -210,7 +210,13 @@ {{ getDictDataLabel(DICT_TYPE.BPM_TASK_ASSIGN_RULE_TYPE, scope.row.type) }} - + + +