Преглед изворни кода

:bulb: 工作流程增加租户绑定

smallchill пре 6 година
родитељ
комит
a2e3c46580

+ 2 - 2
src/main/java/org/springblade/flow/business/controller/WorkController.java

@@ -55,8 +55,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 = flowEngineService.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);
 	}
 

+ 10 - 5
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);
 		// 设置总数

+ 45 - 0
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 - 5
src/main/java/org/springblade/flow/engine/controller/FlowManagerController.java

@@ -29,6 +29,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.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.FlowEngineService;
@@ -60,8 +61,8 @@ public class FlowManagerController {
 	@GetMapping("list")
 	@ApiOperationSupport(order = 1)
 	@ApiOperation(value = "分页", notes = "传入流程类型")
-	public R<IPage<FlowProcess>> list(@ApiParam("流程类型") String category, Query query) {
-		IPage<FlowProcess> pages = flowEngineService.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);
 	}
 
@@ -94,7 +95,7 @@ public class FlowManagerController {
 	/**
 	 * 检查流程文件格式
 	 *
-	 * @param file    流程文件
+	 * @param file 流程文件
 	 */
 	@PostMapping("check-upload")
 	@ApiOperationSupport(order = 4)
@@ -113,8 +114,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(flowEngineService.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)));
 	}
 
 }

+ 4 - 2
src/main/java/org/springblade/flow/engine/controller/FlowModelController.java

@@ -83,8 +83,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 = flowEngineService.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);
 	}
 

+ 2 - 0
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();

+ 10 - 7
src/main/java/org/springblade/flow/engine/service/FlowEngineService.java

@@ -47,9 +47,10 @@ public interface FlowEngineService 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);
 
 	/**
 	 * 流程管理列表
@@ -91,20 +92,22 @@ public interface FlowEngineService extends IService<FlowModel> {
 	/**
 	 * 上传部署流程
 	 *
-	 * @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);
 
 	/**
 	 * 删除流程实例

+ 35 - 7
src/main/java/org/springblade/flow/engine/service/impl/FlowEngineServiceImpl.java

@@ -43,10 +43,13 @@ import org.flowable.engine.runtime.ProcessInstanceQuery;
 import org.flowable.engine.task.Comment;
 import org.springblade.common.cache.UserCache;
 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;
@@ -88,8 +91,16 @@ public class FlowEngineServiceImpl extends ServiceImpl<FlowMapper, FlowModel> im
 	}
 
 	@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 +258,21 @@ public class FlowEngineServiceImpl extends ServiceImpl<FlowMapper, FlowModel> im
 	}
 
 	@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 +281,7 @@ public class FlowEngineServiceImpl extends ServiceImpl<FlowMapper, FlowModel> im
 	}
 
 	@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 +291,17 @@ public class FlowEngineServiceImpl extends ServiceImpl<FlowMapper, FlowModel> im
 		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