mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 12:39:05 +08:00
refactor(flow-engine): 增强多租户支持
- 在EngineProcessInstanceController中增加tenantId过滤条件 - 在EngineFlowController中为部署和启动流程添加tenantId参数 - 优化流程查询时增加tenantId条件检查 - 统一使用TenantContextHolder获取当前租户信息
This commit is contained in:
1 parent
a970fe166a
commit
8227768849
3 files changed
+75
-56
No files matched your search
+7
-3
@@ -11,6 +11,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
|
||||
import com.pig4cloud.pigx.flow.engine.utils.ModelUtil;
|
||||
import com.pig4cloud.pigx.flow.task.dto.*;
|
||||
import com.pig4cloud.pigx.flow.task.entity.Process;
|
||||
@@ -83,7 +84,8 @@ public class EngineFlowController {
|
||||
log.debug("部署时的模型文件:{}", filename);
|
||||
FileUtil.writeBytes(bpmnBytess, filename);
|
||||
}
|
||||
repositoryService.createDeployment().addBpmnModel(StrUtil.format("{}.bpmn20.xml", "pig"), bpmnModel).deploy();
|
||||
repositoryService.createDeployment().addBpmnModel(StrUtil.format("{}.bpmn20.xml", "pig"), bpmnModel)
|
||||
.tenantId(TenantContextHolder.getTenantId().toString()).deploy();
|
||||
|
||||
return R.ok(flowId);
|
||||
}
|
||||
@@ -97,8 +99,8 @@ public class EngineFlowController {
|
||||
@PostMapping("/start")
|
||||
public R start(@RequestBody ProcessInstanceParamDto processInstanceParamDto) {
|
||||
Authentication.setAuthenticatedUserId(processInstanceParamDto.getStartUserId());
|
||||
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processInstanceParamDto.getFlowId(),
|
||||
processInstanceParamDto.getParamMap());
|
||||
ProcessInstance processInstance = runtimeService.startProcessInstanceByKeyAndTenantId(processInstanceParamDto.getFlowId(),
|
||||
processInstanceParamDto.getParamMap(), TenantContextHolder.getTenantId().toString());
|
||||
|
||||
String processInstanceId = processInstance.getProcessInstanceId();
|
||||
return R.ok(processInstanceId);
|
||||
@@ -134,6 +136,7 @@ public class EngineFlowController {
|
||||
// 查询流程实例
|
||||
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery()
|
||||
.processInstanceId(processInstanceId)
|
||||
.processInstanceTenantId(TenantContextHolder.getTenantId().toString())
|
||||
.singleResult();
|
||||
if (Optional.ofNullable(processInstance).isPresent()) {
|
||||
// 查询执行实例
|
||||
@@ -239,6 +242,7 @@ public class EngineFlowController {
|
||||
if (StrUtil.isNotBlank(taskQueryParamDto.getProcessName())) {
|
||||
List<ProcessInstance> processInstanceList = runtimeService.createProcessInstanceQuery()
|
||||
.processDefinitionName(taskQueryParamDto.getProcessName())
|
||||
.processInstanceTenantId(TenantContextHolder.getTenantId().toString())
|
||||
.list();
|
||||
if (CollUtil.isNotEmpty(processInstanceList)) {
|
||||
taskQuery.processInstanceIdIn(processInstanceList.stream()
|
||||
|
||||
+40
-33
@@ -1,6 +1,7 @@
|
||||
package com.pig4cloud.pigx.flow.engine.controller;
|
||||
|
||||
import com.pig4cloud.pigx.common.core.util.R;
|
||||
import com.pig4cloud.pigx.common.data.tenant.TenantContextHolder;
|
||||
import com.pig4cloud.pigx.flow.task.dto.IndexPageStatistics;
|
||||
import com.pig4cloud.pigx.flow.task.dto.VariableQueryParamDto;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -12,6 +13,7 @@ import org.flowable.engine.history.HistoricActivityInstanceQuery;
|
||||
import org.flowable.task.api.TaskQuery;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -23,49 +25,54 @@ import java.util.Map;
|
||||
@RequestMapping("/process-instance")
|
||||
public class EngineProcessInstanceController {
|
||||
|
||||
private final TaskService taskService;
|
||||
private final TaskService taskService;
|
||||
|
||||
private final HistoryService historyService;
|
||||
private final HistoryService historyService;
|
||||
|
||||
private final RuntimeService runtimeService;
|
||||
private final RuntimeService runtimeService;
|
||||
|
||||
/**
|
||||
* 查询首页统计数量
|
||||
* @param userId 用户ID
|
||||
* @return 统计结果
|
||||
*/
|
||||
@GetMapping("querySimpleData")
|
||||
public R<IndexPageStatistics> querySimpleData(long userId) {
|
||||
TaskQuery taskQuery = taskService.createTaskQuery();
|
||||
/**
|
||||
* 查询首页统计数量
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @return 统计结果
|
||||
*/
|
||||
@GetMapping("querySimpleData")
|
||||
public R<IndexPageStatistics> querySimpleData(long userId) {
|
||||
TaskQuery taskQuery = taskService.createTaskQuery();
|
||||
|
||||
// 待办数量
|
||||
long pendingNum = taskQuery.taskAssignee(String.valueOf(userId)).count();
|
||||
// 已完成任务
|
||||
HistoricActivityInstanceQuery historicActivityInstanceQuery = historyService
|
||||
.createHistoricActivityInstanceQuery();
|
||||
// 待办数量
|
||||
long pendingNum = taskQuery.taskAssignee(String.valueOf(userId))
|
||||
.taskTenantId(TenantContextHolder.getTenantId().toString())
|
||||
.count();
|
||||
// 已完成任务
|
||||
HistoricActivityInstanceQuery historicActivityInstanceQuery = historyService
|
||||
.createHistoricActivityInstanceQuery();
|
||||
|
||||
long completedNum = historicActivityInstanceQuery.taskAssignee(String.valueOf(userId)).finished().count();
|
||||
long completedNum = historicActivityInstanceQuery.taskAssignee(String.valueOf(userId))
|
||||
.tenantIdIn(List.of(TenantContextHolder.getTenantId().toString())).finished().count();
|
||||
|
||||
IndexPageStatistics indexPageStatistics = IndexPageStatistics.builder()
|
||||
.pendingNum(pendingNum)
|
||||
.completedNum(completedNum)
|
||||
.build();
|
||||
IndexPageStatistics indexPageStatistics = IndexPageStatistics.builder()
|
||||
.pendingNum(pendingNum)
|
||||
.completedNum(completedNum)
|
||||
.build();
|
||||
|
||||
return R.ok(indexPageStatistics);
|
||||
}
|
||||
return R.ok(indexPageStatistics);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询流程变量
|
||||
* @param paramDto 查询参数
|
||||
* @return 流程变量
|
||||
*/
|
||||
@PostMapping("queryVariables")
|
||||
public R queryVariables(@RequestBody VariableQueryParamDto paramDto) {
|
||||
/**
|
||||
* 查询流程变量
|
||||
*
|
||||
* @param paramDto 查询参数
|
||||
* @return 流程变量
|
||||
*/
|
||||
@PostMapping("queryVariables")
|
||||
public R queryVariables(@RequestBody VariableQueryParamDto paramDto) {
|
||||
|
||||
Map<String, Object> variables = runtimeService.getVariables(paramDto.getExecutionId());
|
||||
Map<String, Object> variables = runtimeService.getVariables(paramDto.getExecutionId());
|
||||
|
||||
return R.ok(variables);
|
||||
return R.ok(variables);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+28
-20
@@ -10,57 +10,65 @@ public interface ITaskService {
|
||||
|
||||
/**
|
||||
* 查询任务
|
||||
* @param taskId
|
||||
* @param view
|
||||
* @return
|
||||
*
|
||||
* @param taskId 任务ID
|
||||
* @param view 是否查看
|
||||
* @return 查询结果
|
||||
*/
|
||||
R queryTask(String taskId, boolean view);
|
||||
|
||||
/**
|
||||
* 完成任务
|
||||
* @param taskParamDto
|
||||
* @return
|
||||
*
|
||||
* @param taskParamDto 任务参数DTO
|
||||
* @return 任务执行结果
|
||||
*/
|
||||
R completeTask(TaskParamDto taskParamDto);
|
||||
|
||||
/**
|
||||
* 前加签
|
||||
* @param taskParamDto
|
||||
* @return
|
||||
* 委托任务(前加签)
|
||||
*
|
||||
* @param taskParamDto 任务参数DTO
|
||||
* @return 委托任务结果
|
||||
*/
|
||||
R delegateTask(TaskParamDto taskParamDto);
|
||||
|
||||
/**
|
||||
* 加签完成任务
|
||||
* @param taskParamDto
|
||||
* @return
|
||||
*
|
||||
* @param taskParamDto 任务参数DTO
|
||||
* @return 任务处理结果
|
||||
*/
|
||||
R resolveTask(TaskParamDto taskParamDto);
|
||||
|
||||
/**
|
||||
* 设置执行人
|
||||
* @param taskParamDto
|
||||
* @return
|
||||
* 设置任务执行人
|
||||
*
|
||||
* @param taskParamDto 任务参数DTO
|
||||
* @return 操作结果
|
||||
*/
|
||||
R setAssignee(TaskParamDto taskParamDto);
|
||||
|
||||
/**
|
||||
* 结束流程
|
||||
* @param taskParamDto
|
||||
* @return
|
||||
* 结束流程实例
|
||||
*
|
||||
* @param taskParamDto 任务参数DTO
|
||||
* @return 操作结果
|
||||
*/
|
||||
R stopProcessInstance(TaskParamDto taskParamDto);
|
||||
|
||||
/**
|
||||
* 退回
|
||||
* @param taskParamDto
|
||||
* @return
|
||||
* 退回任务
|
||||
*
|
||||
* @param taskParamDto 任务参数DTO
|
||||
* @return 操作结果
|
||||
*/
|
||||
R back(TaskParamDto taskParamDto);
|
||||
|
||||
/**
|
||||
* 查询首页数据看板
|
||||
* @return
|
||||
*
|
||||
* @return 任务数据结果
|
||||
*/
|
||||
R queryTaskData();
|
||||
|
||||
|
||||
Reference in new issue
Block a user