Browse Source

💡 工作流程增加租户绑定

test
smallchill 5 years ago
parent
commit
2012787eec
  1. 45
      blade-ops-api/blade-flow-api/src/main/java/org/springblade/flow/core/enums/FlowModeEnum.java
  2. 8
      blade-ops/blade-flow/src/main/java/org/springblade/flow/business/controller/WorkController.java
  3. 15
      blade-ops/blade-flow/src/main/java/org/springblade/flow/business/service/impl/FlowBusinessServiceImpl.java
  4. 8
      blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/controller/FlowFollowController.java
  5. 24
      blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/controller/FlowManagerController.java
  6. 15
      blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/controller/FlowModelController.java
  7. 6
      blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/controller/FlowProcessController.java
  8. 2
      blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/entity/FlowProcess.java
  9. 20
      blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/service/FlowEngineService.java
  10. 48
      blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/service/impl/FlowEngineServiceImpl.java

45
blade-ops-api/blade-flow-api/src/main/java/org/springblade/flow/core/enums/FlowModeEnum.java

@ -0,0 +1,45 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package org.springblade.flow.core.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* 流程类型枚举
*
* @author Chill
*/
@Getter
@AllArgsConstructor
public enum FlowModeEnum {
/**
* 通用流程
*/
COMMON("common", 1),
/**
* 定制流程
*/
CUSTOM("custom", 2),
;
final String name;
final int mode;
}

8
blade-ops/blade-flow/src/main/java/org/springblade/flow/business/controller/WorkController.java

@ -30,7 +30,7 @@ import org.springblade.flow.business.service.FlowBusinessService;
import org.springblade.flow.core.entity.BladeFlow;
import org.springblade.flow.core.utils.TaskUtil;
import org.springblade.flow.engine.entity.FlowProcess;
import org.springblade.flow.engine.service.FlowService;
import org.springblade.flow.engine.service.FlowEngineService;
import org.springframework.web.bind.annotation.*;
/**
@ -45,7 +45,7 @@ import org.springframework.web.bind.annotation.*;
public class WorkController {
private TaskService taskService;
private FlowService flowService;
private FlowEngineService flowEngineService;
private FlowBusinessService flowBusinessService;
/**
@ -54,8 +54,8 @@ public class WorkController {
@GetMapping("start-list")
@ApiOperationSupport(order = 1)
@ApiOperation(value = "发起事务列表页", notes = "传入流程类型")
public R<IPage<FlowProcess>> startList(@ApiParam("流程类型") String category, Query query) {
IPage<FlowProcess> pages = flowService.selectProcessPage(Condition.getPage(query), category);
public R<IPage<FlowProcess>> startList(@ApiParam("流程类型") String category, Query query, @RequestParam(required = false, defaultValue = "1") Integer mode) {
IPage<FlowProcess> pages = flowEngineService.selectProcessPage(Condition.getPage(query), category, mode);
return R.data(pages);
}

15
blade-ops/blade-flow/src/main/java/org/springblade/flow/business/service/impl/FlowBusinessServiceImpl.java

@ -26,6 +26,7 @@ import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.task.api.TaskQuery;
import org.flowable.task.api.history.HistoricTaskInstance;
import org.flowable.task.api.history.HistoricTaskInstanceQuery;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.support.Kv;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringPool;
@ -60,19 +61,23 @@ public class FlowBusinessServiceImpl implements FlowBusinessService {
String taskGroup = TaskUtil.getCandidateGroup();
List<BladeFlow> flowList = new LinkedList<>();
// 等待签收的任务
// 个人等待签收的任务
TaskQuery claimUserQuery = taskService.createTaskQuery().taskCandidateUser(taskUser)
.includeProcessVariables().active().orderByTaskCreateTime().desc();
// 等待签收的任务
TaskQuery claimRoleQuery = taskService.createTaskQuery().taskCandidateGroup(taskGroup)
// 定制流程等待签收的任务
TaskQuery claimRoleWithTenantIdQuery = taskService.createTaskQuery().taskTenantId(AuthUtil.getTenantId()).taskCandidateGroup(taskGroup)
.includeProcessVariables().active().orderByTaskCreateTime().desc();
// 通用流程等待签收的任务
TaskQuery claimRoleWithoutTenantIdQuery = taskService.createTaskQuery().taskWithoutTenantId().taskCandidateGroup(taskGroup)
.includeProcessVariables().active().orderByTaskCreateTime().desc();
// 构建列表数据
buildFlowTaskList(bladeFlow, flowList, claimUserQuery, FlowEngineConstant.STATUS_CLAIM);
buildFlowTaskList(bladeFlow, flowList, claimRoleQuery, FlowEngineConstant.STATUS_CLAIM);
buildFlowTaskList(bladeFlow, flowList, claimRoleWithTenantIdQuery, FlowEngineConstant.STATUS_CLAIM);
buildFlowTaskList(bladeFlow, flowList, claimRoleWithoutTenantIdQuery, FlowEngineConstant.STATUS_CLAIM);
// 计算总数
long count = claimUserQuery.count() + claimRoleQuery.count();
long count = claimUserQuery.count() + claimRoleWithTenantIdQuery.count() + claimRoleWithoutTenantIdQuery.count();
// 设置页数
page.setSize(count);
// 设置总数

8
blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/controller/FlowFollowController.java

@ -27,7 +27,7 @@ import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.flow.engine.entity.FlowExecution;
import org.springblade.flow.engine.service.FlowService;
import org.springblade.flow.engine.service.FlowEngineService;
import org.springframework.web.bind.annotation.*;
/**
@ -41,7 +41,7 @@ import org.springframework.web.bind.annotation.*;
@PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR)
public class FlowFollowController {
private FlowService flowService;
private FlowEngineService flowEngineService;
/**
* 流程状态列表
@ -50,7 +50,7 @@ public class FlowFollowController {
@ApiOperationSupport(order = 1)
@ApiOperation(value = "分页", notes = "传入notice")
public R<IPage<FlowExecution>> list(Query query, @ApiParam(value = "流程实例id") String processInstanceId, @ApiParam(value = "流程key") String processDefinitionKey) {
IPage<FlowExecution> pages = flowService.selectFollowPage(Condition.getPage(query), processInstanceId, processDefinitionKey);
IPage<FlowExecution> pages = flowEngineService.selectFollowPage(Condition.getPage(query), processInstanceId, processDefinitionKey);
return R.data(pages);
}
@ -61,7 +61,7 @@ public class FlowFollowController {
@ApiOperationSupport(order = 2)
@ApiOperation(value = "删除", notes = "传入主键集合")
public R deleteProcessInstance(@ApiParam(value = "流程实例id") @RequestParam String processInstanceId, @ApiParam(value = "删除原因") @RequestParam String deleteReason) {
boolean temp = flowService.deleteProcessInstance(processInstanceId, deleteReason);
boolean temp = flowEngineService.deleteProcessInstance(processInstanceId, deleteReason);
return R.status(temp);
}

24
blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/controller/FlowManagerController.java

@ -17,9 +17,9 @@
package org.springblade.flow.engine.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.Condition;
@ -28,9 +28,10 @@ import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.core.tool.support.Kv;
import org.springblade.core.tool.utils.Func;
import org.springblade.flow.engine.constant.FlowEngineConstant;
import org.springblade.flow.engine.entity.FlowProcess;
import org.springblade.flow.engine.service.FlowService;
import org.springblade.flow.engine.service.FlowEngineService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@ -49,7 +50,7 @@ import java.util.Objects;
@PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR)
public class FlowManagerController {
private FlowService flowService;
private FlowEngineService flowEngineService;
/**
* 分页
@ -57,11 +58,12 @@ public class FlowManagerController {
@GetMapping("list")
@ApiOperationSupport(order = 1)
@ApiOperation(value = "分页", notes = "传入流程类型")
public R<IPage<FlowProcess>> list(@ApiParam("流程类型") String category, Query query) {
IPage<FlowProcess> pages = flowService.selectProcessPage(Condition.getPage(query), category);
public R<IPage<FlowProcess>> list(@ApiParam("流程类型") String category, Query query, @RequestParam(required = false, defaultValue = "1") Integer mode) {
IPage<FlowProcess> pages = flowEngineService.selectProcessPage(Condition.getPage(query), category, mode);
return R.data(pages);
}
/**
* 变更流程状态
*
@ -72,7 +74,7 @@ public class FlowManagerController {
@ApiOperationSupport(order = 2)
@ApiOperation(value = "变更流程状态", notes = "传入state,processId")
public R changeState(@RequestParam String state, @RequestParam String processId) {
String msg = flowService.changeState(state, processId);
String msg = flowEngineService.changeState(state, processId);
return R.success(msg);
}
@ -85,13 +87,13 @@ public class FlowManagerController {
@ApiOperationSupport(order = 3)
@ApiOperation(value = "删除部署流程", notes = "部署流程id集合")
public R deleteDeployment(String deploymentIds) {
return R.status(flowService.deleteDeployment(deploymentIds));
return R.status(flowEngineService.deleteDeployment(deploymentIds));
}
/**
* 检查流程文件格式
*
* @param file 流程文件
* @param file 流程文件
*/
@PostMapping("check-upload")
@ApiOperationSupport(order = 4)
@ -110,8 +112,10 @@ public class FlowManagerController {
@PostMapping("deploy-upload")
@ApiOperationSupport(order = 5)
@ApiOperation(value = "上传部署流程文件", notes = "传入文件")
public R deployUpload(@RequestParam List<MultipartFile> files, @RequestParam String category) {
return R.status(flowService.deployUpload(files, category));
public R deployUpload(@RequestParam List<MultipartFile> files,
@RequestParam String category,
@RequestParam(required = false, defaultValue = "") String tenantIds) {
return R.status(flowEngineService.deployUpload(files, category, Func.toStrList(tenantIds)));
}
}

15
blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/controller/FlowModelController.java

@ -30,7 +30,7 @@ import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.RoleConstant;
import org.springblade.core.tool.utils.Func;
import org.springblade.flow.engine.entity.FlowModel;
import org.springblade.flow.engine.service.FlowService;
import org.springblade.flow.engine.service.FlowEngineService;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
@ -47,7 +47,7 @@ import java.util.Map;
@PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR)
public class FlowModelController {
private FlowService flowService;
private FlowEngineService flowEngineService;
/**
* 分页
@ -60,7 +60,7 @@ public class FlowModelController {
@ApiOperationSupport(order = 1)
@ApiOperation(value = "分页", notes = "传入notice")
public R<IPage<FlowModel>> list(@ApiIgnore @RequestParam Map<String, Object> flow, Query query) {
IPage<FlowModel> pages = flowService.page(Condition.getPage(query), Condition.getQueryWrapper(flow, FlowModel.class));
IPage<FlowModel> pages = flowEngineService.page(Condition.getPage(query), Condition.getQueryWrapper(flow, FlowModel.class));
return R.data(pages);
}
@ -71,7 +71,7 @@ public class FlowModelController {
@ApiOperationSupport(order = 2)
@ApiOperation(value = "删除", notes = "传入主键集合")
public R remove(@ApiParam(value = "主键集合") @RequestParam String ids) {
boolean temp = flowService.removeByIds(Func.toStrList(ids));
boolean temp = flowEngineService.removeByIds(Func.toStrList(ids));
return R.status(temp);
}
@ -81,9 +81,10 @@ public class FlowModelController {
@PostMapping("/deploy")
@ApiOperationSupport(order = 3)
@ApiOperation(value = "部署", notes = "传入模型id和分类")
public R deploy(@ApiParam(value = "模型id") @RequestParam String modelId, @ApiParam(value = "工作流分类") @RequestParam String category) {
boolean temp = flowService.deployModel(modelId, category);
public R deploy(@ApiParam(value = "模型id") @RequestParam String modelId,
@ApiParam(value = "工作流分类") @RequestParam String category,
@ApiParam(value = "租户ID") @RequestParam(required = false, defaultValue = "") String tenantIds) {
boolean temp = flowEngineService.deployModel(modelId, category, Func.toStrList(tenantIds));
return R.status(temp);
}
}

6
blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/controller/FlowProcessController.java

@ -29,7 +29,7 @@ import org.flowable.image.ProcessDiagramGenerator;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.flow.core.entity.BladeFlow;
import org.springblade.flow.engine.service.FlowService;
import org.springblade.flow.engine.service.FlowEngineService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@ -61,7 +61,7 @@ public class FlowProcessController {
private RuntimeService runtimeService;
private HistoryService historyService;
private ProcessEngine processEngine;
private FlowService flowService;
private FlowEngineService flowEngineService;
/**
* 获取流转历史列表
@ -72,7 +72,7 @@ public class FlowProcessController {
*/
@GetMapping(value = "history-flow-list")
public R<List<BladeFlow>> historyFlowList(@RequestParam String processInstanceId, String startActivityId, String endActivityId) {
return R.data(flowService.historyFlowList(processInstanceId, startActivityId, endActivityId));
return R.data(flowEngineService.historyFlowList(processInstanceId, startActivityId, endActivityId));
}
/**

2
blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/entity/FlowProcess.java

@ -32,6 +32,7 @@ import java.util.Date;
public class FlowProcess implements Serializable {
private String id;
private String tenantId;
private String name;
private String key;
private String category;
@ -45,6 +46,7 @@ public class FlowProcess implements Serializable {
public FlowProcess(ProcessDefinitionEntityImpl entity) {
this.id = entity.getId();
this.tenantId = entity.getTenantId();
this.name = entity.getName();
this.key = entity.getKey();
this.category = entity.getCategory();

20
blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/service/FlowService.java → blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/service/FlowEngineService.java

@ -31,7 +31,7 @@ import java.util.List;
*
* @author Chill
*/
public interface FlowService extends IService<FlowModel> {
public interface FlowEngineService extends IService<FlowModel> {
/**
* 自定义分页
@ -47,9 +47,10 @@ public interface FlowService extends IService<FlowModel> {
*
* @param page 分页工具
* @param category 分类
* @param mode 形态
* @return
*/
IPage<FlowProcess> selectProcessPage(IPage<FlowProcess> page, String category);
IPage<FlowProcess> selectProcessPage(IPage<FlowProcess> page, String category, Integer mode);
/**
* 流程管理列表
@ -87,23 +88,26 @@ public interface FlowService extends IService<FlowModel> {
* @return
*/
boolean deleteDeployment(String deploymentIds);
/**
* 上传部署流程
*
* @param files 流程配置文件
* @param category 流程分类
* @param files 流程配置文件
* @param category 流程分类
* @param tenantIdList 租户id集合
* @return
*/
boolean deployUpload(List<MultipartFile> files, String category);
boolean deployUpload(List<MultipartFile> files, String category, List<String> tenantIdList);
/**
* 部署流程
*
* @param modelId 模型id
* @param category 分类
* @param modelId 模型id
* @param category 分类
* @param tenantIdList 租户id集合
* @return
*/
boolean deployModel(String modelId, String category);
boolean deployModel(String modelId, String category, List<String> tenantIdList);
/**
* 删除流程实例

48
blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/service/impl/FlowServiceImpl.java → blade-ops/blade-flow/src/main/java/org/springblade/flow/engine/service/impl/FlowEngineServiceImpl.java

@ -42,17 +42,20 @@ import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.engine.runtime.ProcessInstanceQuery;
import org.flowable.engine.task.Comment;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.FileUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.flow.core.entity.BladeFlow;
import org.springblade.flow.core.enums.FlowModeEnum;
import org.springblade.flow.core.utils.TaskUtil;
import org.springblade.flow.engine.constant.FlowEngineConstant;
import org.springblade.flow.engine.entity.FlowExecution;
import org.springblade.flow.engine.entity.FlowModel;
import org.springblade.flow.engine.entity.FlowProcess;
import org.springblade.flow.engine.mapper.FlowMapper;
import org.springblade.flow.engine.service.FlowService;
import org.springblade.flow.engine.service.FlowEngineService;
import org.springblade.flow.engine.utils.FlowCache;
import org.springblade.system.user.cache.UserCache;
import org.springblade.system.user.entity.User;
@ -71,9 +74,7 @@ import java.util.*;
@Slf4j
@Service
@AllArgsConstructor
public class FlowServiceImpl extends ServiceImpl<FlowMapper, FlowModel> implements FlowService {
private static final String IMAGE_NAME = "image";
private static final String XML_NAME = "xml";
public class FlowEngineServiceImpl extends ServiceImpl<FlowMapper, FlowModel> implements FlowEngineService {
private static BpmnJsonConverter bpmnJsonConverter = new BpmnJsonConverter();
private static BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
private ObjectMapper objectMapper;
@ -88,8 +89,16 @@ public class FlowServiceImpl extends ServiceImpl<FlowMapper, FlowModel> implemen
}
@Override
public IPage<FlowProcess> selectProcessPage(IPage<FlowProcess> page, String category) {
public IPage<FlowProcess> selectProcessPage(IPage<FlowProcess> page, String category, Integer mode) {
ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery().latestVersion().orderByProcessDefinitionKey().asc();
// 通用流程
if (mode == FlowModeEnum.COMMON.getMode()) {
processDefinitionQuery.processDefinitionWithoutTenantId();
}
// 定制流程
else if (!AuthUtil.isAdministrator()) {
processDefinitionQuery.processDefinitionTenantId(AuthUtil.getTenantId());
}
if (StringUtils.isNotEmpty(category)) {
processDefinitionQuery.processDefinitionCategory(category);
}
@ -247,13 +256,21 @@ public class FlowServiceImpl extends ServiceImpl<FlowMapper, FlowModel> implemen
}
@Override
public boolean deployUpload(List<MultipartFile> files, String category) {
public boolean deployUpload(List<MultipartFile> files, String category, List<String> tenantIdList) {
files.forEach(file -> {
try {
String fileName = file.getOriginalFilename();
InputStream fileInputStream = file.getInputStream();
Deployment deployment = repositoryService.createDeployment().addInputStream(fileName, fileInputStream).deploy();
deploy(deployment, category);
byte[] bytes = FileUtil.copyToByteArray(fileInputStream);
if (Func.isNotEmpty(tenantIdList)) {
tenantIdList.forEach(tenantId -> {
Deployment deployment = repositoryService.createDeployment().addBytes(fileName, bytes).tenantId(tenantId).deploy();
deploy(deployment, category);
});
} else {
Deployment deployment = repositoryService.createDeployment().addBytes(fileName, bytes).deploy();
deploy(deployment, category);
}
} catch (IOException e) {
e.printStackTrace();
}
@ -262,7 +279,7 @@ public class FlowServiceImpl extends ServiceImpl<FlowMapper, FlowModel> implemen
}
@Override
public boolean deployModel(String modelId, String category) {
public boolean deployModel(String modelId, String category, List<String> tenantIdList) {
FlowModel model = this.getById(modelId);
if (model == null) {
throw new ServiceException("No model found with the given id: " + modelId);
@ -272,8 +289,17 @@ public class FlowServiceImpl extends ServiceImpl<FlowMapper, FlowModel> implemen
if (!StringUtil.endsWithIgnoreCase(processName, FlowEngineConstant.SUFFIX)) {
processName += FlowEngineConstant.SUFFIX;
}
Deployment deployment = repositoryService.createDeployment().addBytes(processName, bytes).name(model.getName()).key(model.getModelKey()).deploy();
return deploy(deployment, category);
String finalProcessName = processName;
if (Func.isNotEmpty(tenantIdList)) {
tenantIdList.forEach(tenantId -> {
Deployment deployment = repositoryService.createDeployment().addBytes(finalProcessName, bytes).name(model.getName()).key(model.getModelKey()).tenantId(tenantId).deploy();
deploy(deployment, category);
});
} else {
Deployment deployment = repositoryService.createDeployment().addBytes(finalProcessName, bytes).name(model.getName()).key(model.getModelKey()).deploy();
deploy(deployment, category);
}
return true;
}
@Override
Loading…
Cancel
Save