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 | 1 | package cn.iocoder.yudao.framework.tenant.core.context; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.util.StrUtil; | |
| 3 | 4 | import cn.iocoder.yudao.framework.common.enums.DocumentEnum; |
| 4 | 5 | import com.alibaba.ttl.TransmittableThreadLocal; |
| 5 | 6 | |
| ... | ... | @@ -21,7 +22,7 @@ public class TenantContextHolder { |
| 21 | 22 | private static final ThreadLocal<Boolean> IGNORE = new TransmittableThreadLocal<>(); |
| 22 | 23 | |
| 23 | 24 | /** |
| 24 | - * 获得租户编号。 | |
| 25 | + * 获得租户编号 | |
| 25 | 26 | * |
| 26 | 27 | * @return 租户编号 |
| 27 | 28 | */ |
| ... | ... | @@ -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 | 44 | * 获得租户编号。如果不存在,则抛出 NullPointerException 异常 |
| 34 | 45 | * |
| 35 | 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 | 3 | import cn.iocoder.yudao.framework.common.enums.WebFilterOrderEnum; |
| 4 | 4 | import cn.iocoder.yudao.framework.flowable.core.web.FlowableWebFilter; |
| 5 | 5 | import org.springframework.boot.autoconfigure.AutoConfiguration; |
| 6 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | |
| 6 | 7 | import org.springframework.boot.web.servlet.FilterRegistrationBean; |
| 7 | 8 | import org.springframework.context.annotation.Bean; |
| 8 | 9 | import org.springframework.core.task.AsyncListenableTaskExecutor; |
| ... | ... | @@ -17,6 +18,7 @@ public class YudaoFlowableConfiguration { |
| 17 | 18 | * 如果不创建,会导致项目启动时,Flowable 报错的问题 |
| 18 | 19 | */ |
| 19 | 20 | @Bean |
| 21 | + @ConditionalOnMissingBean | |
| 20 | 22 | public AsyncListenableTaskExecutor taskExecutor() { |
| 21 | 23 | ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); |
| 22 | 24 | executor.setCorePoolSize(8); |
| ... | ... | @@ -40,4 +42,5 @@ public class YudaoFlowableConfiguration { |
| 40 | 42 | registrationBean.setOrder(WebFilterOrderEnum.FLOWABLE_FILTER); |
| 41 | 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 | 7 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 8 | 8 | import cn.iocoder.yudao.framework.common.util.object.PageUtils; |
| 9 | 9 | import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils; |
| 10 | +import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder; | |
| 10 | 11 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.*; |
| 11 | 12 | import cn.iocoder.yudao.module.bpm.convert.definition.BpmModelConvert; |
| 12 | 13 | import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO; |
| ... | ... | @@ -71,7 +72,8 @@ public class BpmModelServiceImpl implements BpmModelService { |
| 71 | 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 | 77 | .listPage(PageUtils.getStart(pageVO), pageVO.getPageSize()); |
| 76 | 78 | |
| 77 | 79 | // 获得 Form Map |
| ... | ... | @@ -107,6 +109,7 @@ public class BpmModelServiceImpl implements BpmModelService { |
| 107 | 109 | // 创建流程定义 |
| 108 | 110 | Model model = repositoryService.newModel(); |
| 109 | 111 | BpmModelConvert.INSTANCE.copy(model, createReqVO); |
| 112 | + model.setTenantId(TenantContextHolder.getTenantIdStr()); | |
| 110 | 113 | // 保存流程定义 |
| 111 | 114 | repositoryService.saveModel(model); |
| 112 | 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 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | 7 | import cn.iocoder.yudao.framework.common.util.object.PageUtils; |
| 8 | 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 | 11 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionListReqVO; |
| 10 | 12 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionPageItemRespVO; |
| 11 | 13 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionPageReqVO; |
| ... | ... | @@ -124,6 +126,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ |
| 124 | 126 | Deployment deploy = repositoryService.createDeployment() |
| 125 | 127 | .key(createReqDTO.getKey()).name(createReqDTO.getName()).category(createReqDTO.getCategory()) |
| 126 | 128 | .addBytes(createReqDTO.getKey() + BPMN_FILE_SUFFIX, createReqDTO.getBpmnBytes()) |
| 129 | + .tenantId(TenantContextHolder.getTenantIdStr()) | |
| 127 | 130 | .deploy(); |
| 128 | 131 | |
| 129 | 132 | // 设置 ProcessDefinition 的 category 分类 |
| ... | ... | @@ -234,6 +237,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ |
| 234 | 237 | definitionQuery.active(); |
| 235 | 238 | } |
| 236 | 239 | // 执行查询 |
| 240 | + definitionQuery.processDefinitionTenantId(TenantContextHolder.getTenantIdStr()); | |
| 237 | 241 | List<ProcessDefinition> processDefinitions = definitionQuery.list(); |
| 238 | 242 | if (CollUtil.isEmpty(processDefinitions)) { |
| 239 | 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; |