Commit 9a03f1a7966abac5828583986ce3849068be938a
1 parent
b5e19c63
🐛 BPM:多租户的工作流隔离
Showing
5 changed files
with
23 additions
and
3 deletions
yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/context/TenantContextHolder.java
| 1 | package cn.iocoder.yudao.framework.tenant.core.context; | 1 | package cn.iocoder.yudao.framework.tenant.core.context; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.util.StrUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.DocumentEnum; | 4 | import cn.iocoder.yudao.framework.common.enums.DocumentEnum; |
| 4 | import com.alibaba.ttl.TransmittableThreadLocal; | 5 | import com.alibaba.ttl.TransmittableThreadLocal; |
| 5 | 6 | ||
| @@ -21,7 +22,7 @@ public class TenantContextHolder { | @@ -21,7 +22,7 @@ public class TenantContextHolder { | ||
| 21 | private static final ThreadLocal<Boolean> IGNORE = new TransmittableThreadLocal<>(); | 22 | private static final ThreadLocal<Boolean> IGNORE = new TransmittableThreadLocal<>(); |
| 22 | 23 | ||
| 23 | /** | 24 | /** |
| 24 | - * 获得租户编号。 | 25 | + * 获得租户编号 |
| 25 | * | 26 | * |
| 26 | * @return 租户编号 | 27 | * @return 租户编号 |
| 27 | */ | 28 | */ |
| @@ -30,6 +31,16 @@ public class TenantContextHolder { | @@ -30,6 +31,16 @@ public class TenantContextHolder { | ||
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | /** | 33 | /** |
| 34 | + * 获得租户编号 String | ||
| 35 | + * | ||
| 36 | + * @return 租户编号 | ||
| 37 | + */ | ||
| 38 | + public static String getTenantIdStr() { | ||
| 39 | + Long tenantId = getTenantId(); | ||
| 40 | + return StrUtil.toStringOrNull(tenantId); | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + /** | ||
| 33 | * 获得租户编号。如果不存在,则抛出 NullPointerException 异常 | 44 | * 获得租户编号。如果不存在,则抛出 NullPointerException 异常 |
| 34 | * | 45 | * |
| 35 | * @return 租户编号 | 46 | * @return 租户编号 |
yudao-framework/yudao-spring-boot-starter-flowable/src/main/java/cn/iocoder/yudao/framework/flowable/config/YudaoFlowableConfiguration.java
| @@ -3,6 +3,7 @@ package cn.iocoder.yudao.framework.flowable.config; | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.framework.flowable.config; | ||
| 3 | import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum; | 3 | import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum; |
| 4 | import cn.iocoder.yudao.framework.flowable.core.web.FlowableWebFilter; | 4 | import cn.iocoder.yudao.framework.flowable.core.web.FlowableWebFilter; |
| 5 | import org.springframework.boot.autoconfigure.AutoConfiguration; | 5 | import org.springframework.boot.autoconfigure.AutoConfiguration; |
| 6 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
| 6 | import org.springframework.boot.web.servlet.FilterRegistrationBean; | 7 | import org.springframework.boot.web.servlet.FilterRegistrationBean; |
| 7 | import org.springframework.context.annotation.Bean; | 8 | import org.springframework.context.annotation.Bean; |
| 8 | import org.springframework.core.task.AsyncListenableTaskExecutor; | 9 | import org.springframework.core.task.AsyncListenableTaskExecutor; |
| @@ -17,6 +18,7 @@ public class YudaoFlowableConfiguration { | @@ -17,6 +18,7 @@ public class YudaoFlowableConfiguration { | ||
| 17 | * 如果不创建,会导致项目启动时,Flowable 报错的问题 | 18 | * 如果不创建,会导致项目启动时,Flowable 报错的问题 |
| 18 | */ | 19 | */ |
| 19 | @Bean | 20 | @Bean |
| 21 | + @ConditionalOnMissingBean | ||
| 20 | public AsyncListenableTaskExecutor taskExecutor() { | 22 | public AsyncListenableTaskExecutor taskExecutor() { |
| 21 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); | 23 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
| 22 | executor.setCorePoolSize(8); | 24 | executor.setCorePoolSize(8); |
| @@ -40,4 +42,5 @@ public class YudaoFlowableConfiguration { | @@ -40,4 +42,5 @@ public class YudaoFlowableConfiguration { | ||
| 40 | registrationBean.setOrder(WebFilterOrderEnum.FLOWABLE_FILTER); | 42 | registrationBean.setOrder(WebFilterOrderEnum.FLOWABLE_FILTER); |
| 41 | return registrationBean; | 43 | return registrationBean; |
| 42 | } | 44 | } |
| 45 | + | ||
| 43 | } | 46 | } |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmModelServiceImpl.java
| @@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | @@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | ||
| 7 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | 7 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 8 | import cn.iocoder.yudao.framework.common.util.object.PageUtils; | 8 | import cn.iocoder.yudao.framework.common.util.object.PageUtils; |
| 9 | import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils; | 9 | import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils; |
| 10 | +import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; | ||
| 10 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.*; | 11 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.*; |
| 11 | import cn.iocoder.yudao.module.bpm.convert.definition.BpmModelConvert; | 12 | import cn.iocoder.yudao.module.bpm.convert.definition.BpmModelConvert; |
| 12 | import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO; | 13 | import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO; |
| @@ -71,7 +72,8 @@ public class BpmModelServiceImpl implements BpmModelService { | @@ -71,7 +72,8 @@ public class BpmModelServiceImpl implements BpmModelService { | ||
| 71 | modelQuery.modelCategory(pageVO.getCategory()); | 72 | modelQuery.modelCategory(pageVO.getCategory()); |
| 72 | } | 73 | } |
| 73 | // 执行查询 | 74 | // 执行查询 |
| 74 | - List<Model> models = modelQuery.orderByCreateTime().desc() | 75 | + List<Model> models = modelQuery.modelTenantId(TenantContextHolder.getTenantIdStr()) |
| 76 | + .orderByCreateTime().desc() | ||
| 75 | .listPage(PageUtils.getStart(pageVO), pageVO.getPageSize()); | 77 | .listPage(PageUtils.getStart(pageVO), pageVO.getPageSize()); |
| 76 | 78 | ||
| 77 | // 获得 Form Map | 79 | // 获得 Form Map |
| @@ -107,6 +109,7 @@ public class BpmModelServiceImpl implements BpmModelService { | @@ -107,6 +109,7 @@ public class BpmModelServiceImpl implements BpmModelService { | ||
| 107 | // 创建流程定义 | 109 | // 创建流程定义 |
| 108 | Model model = repositoryService.newModel(); | 110 | Model model = repositoryService.newModel(); |
| 109 | BpmModelConvert.INSTANCE.copy(model, createReqVO); | 111 | BpmModelConvert.INSTANCE.copy(model, createReqVO); |
| 112 | + model.setTenantId(TenantContextHolder.getTenantIdStr()); | ||
| 110 | // 保存流程定义 | 113 | // 保存流程定义 |
| 111 | repositoryService.saveModel(model); | 114 | repositoryService.saveModel(model); |
| 112 | // 保存 BPMN XML | 115 | // 保存 BPMN XML |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/definition/BpmProcessDefinitionServiceImpl.java
| @@ -6,6 +6,8 @@ import cn.hutool.core.util.StrUtil; | @@ -6,6 +6,8 @@ import cn.hutool.core.util.StrUtil; | ||
| 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | import cn.iocoder.yudao.framework.common.util.object.PageUtils; | 7 | import cn.iocoder.yudao.framework.common.util.object.PageUtils; |
| 8 | import cn.iocoder.yudao.framework.flowable.core.util.BpmnModelUtils; | 8 | import cn.iocoder.yudao.framework.flowable.core.util.BpmnModelUtils; |
| 9 | +import cn.iocoder.yudao.framework.flowable.core.util.FlowableUtils; | ||
| 10 | +import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; | ||
| 9 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionListReqVO; | 11 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionListReqVO; |
| 10 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionPageItemRespVO; | 12 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionPageItemRespVO; |
| 11 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionPageReqVO; | 13 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionPageReqVO; |
| @@ -124,6 +126,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ | @@ -124,6 +126,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ | ||
| 124 | Deployment deploy = repositoryService.createDeployment() | 126 | Deployment deploy = repositoryService.createDeployment() |
| 125 | .key(createReqDTO.getKey()).name(createReqDTO.getName()).category(createReqDTO.getCategory()) | 127 | .key(createReqDTO.getKey()).name(createReqDTO.getName()).category(createReqDTO.getCategory()) |
| 126 | .addBytes(createReqDTO.getKey() + BPMN_FILE_SUFFIX, createReqDTO.getBpmnBytes()) | 128 | .addBytes(createReqDTO.getKey() + BPMN_FILE_SUFFIX, createReqDTO.getBpmnBytes()) |
| 129 | + .tenantId(TenantContextHolder.getTenantIdStr()) | ||
| 127 | .deploy(); | 130 | .deploy(); |
| 128 | 131 | ||
| 129 | // 设置 ProcessDefinition 的 category 分类 | 132 | // 设置 ProcessDefinition 的 category 分类 |
| @@ -234,6 +237,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ | @@ -234,6 +237,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ | ||
| 234 | definitionQuery.active(); | 237 | definitionQuery.active(); |
| 235 | } | 238 | } |
| 236 | // 执行查询 | 239 | // 执行查询 |
| 240 | + definitionQuery.processDefinitionTenantId(TenantContextHolder.getTenantIdStr()); | ||
| 237 | List<ProcessDefinition> processDefinitions = definitionQuery.list(); | 241 | List<ProcessDefinition> processDefinitions = definitionQuery.list(); |
| 238 | if (CollUtil.isEmpty(processDefinitions)) { | 242 | if (CollUtil.isEmpty(processDefinitions)) { |
| 239 | return Collections.emptyList(); | 243 | return Collections.emptyList(); |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/package-info.java deleted
| 1 | -package cn.iocoder.yudao.module.bpm.service.task; |