diff --git a/blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/constant/ProcessConstant.java b/blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/constant/ProcessConstant.java index 098fe970..dc100413 100644 --- a/blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/constant/ProcessConstant.java +++ b/blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/constant/ProcessConstant.java @@ -33,6 +33,16 @@ public interface ProcessConstant { */ String Expense_KEY = "Expense"; + /** + * 同意标识 + */ + String PASS_KEY = "pass"; + + /** + * 同意代号 + */ + String PASS_ALIAS = "ok"; + /** * 同意默认批复 */ diff --git a/blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/entity/BladeFlow.java b/blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/entity/BladeFlow.java index 5da13566..c1d56378 100644 --- a/blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/entity/BladeFlow.java +++ b/blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/entity/BladeFlow.java @@ -152,10 +152,6 @@ public class BladeFlow implements Serializable { * 是否通过代号 */ private String flag; - /** - * 批复名 - */ - private String passComment; /** * 开始查询日期 */ @@ -169,18 +165,11 @@ public class BladeFlow implements Serializable { */ private Map variables; - /** - * 获取批复名 - */ - public String getPassComment() { - return isPass() ? ProcessConstant.PASS_COMMENT : ProcessConstant.NOT_PASS_COMMENT; - } - /** * 获取是否通过 */ public boolean isPass() { - return "ok".equals(flag); + return ProcessConstant.PASS_ALIAS.equals(flag) || ProcessConstant.PASS_COMMENT.equals(comment); } } diff --git a/blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/utils/FlowUtil.java b/blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/utils/FlowUtil.java index 3561052e..ab9e0926 100644 --- a/blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/utils/FlowUtil.java +++ b/blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/utils/FlowUtil.java @@ -35,9 +35,6 @@ public class FlowUtil { */ private final static Map BUSINESS_TABLE = new HashMap<>(); - /** - * 初始化加载 - */ static { BUSINESS_TABLE.put(ProcessConstant.LEAVE_KEY, "blade_process_leave"); } diff --git a/blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/utils/TaskUtil.java b/blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/utils/TaskUtil.java new file mode 100644 index 00000000..4565840d --- /dev/null +++ b/blade-ops-api/blade-flow-api/src/main/java/org/springblade/flowable/core/utils/TaskUtil.java @@ -0,0 +1,69 @@ +/* + * 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.flowable.core.utils; + +import org.springblade.core.secure.utils.SecureUtil; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.StringUtil; + +/** + * 工作流任务工具类 + * + * @author Chill + */ +public class TaskUtil { + + /** + * 获取任务用户格式 + * + * @return taskUser + */ + public static String getTaskUser() { + return StringUtil.format("taskUser_{}", SecureUtil.getUserId()); + } + + /** + * 获取任务用户格式 + * + * @param userId 用户id + * @return taskUser + */ + public static String getTaskUser(String userId) { + return StringUtil.format("taskUser_{}", userId); + } + + + /** + * 获取用户主键 + * + * @param taskUser 任务用户 + * @return userId + */ + public static Integer getUserId(String taskUser) { + return Func.toInt(StringUtil.removePrefix(taskUser, "taskUser_")); + } + + /** + * 获取用户组格式 + * + * @return candidateGroup + */ + public static String getCandidateGroup() { + return SecureUtil.getUserRole(); + } + +} diff --git a/blade-ops/blade-flow/src/main/java/org/springblade/flowable/business/controller/WorkController.java b/blade-ops/blade-flow/src/main/java/org/springblade/flowable/business/controller/WorkController.java index 7f009434..4c2ec18a 100644 --- a/blade-ops/blade-flow/src/main/java/org/springblade/flowable/business/controller/WorkController.java +++ b/blade-ops/blade-flow/src/main/java/org/springblade/flowable/business/controller/WorkController.java @@ -24,16 +24,13 @@ import lombok.AllArgsConstructor; import org.flowable.engine.TaskService; import org.springblade.core.mp.support.Condition; import org.springblade.core.mp.support.Query; -import org.springblade.core.secure.BladeUser; import org.springblade.core.tool.api.R; import org.springblade.flowable.business.service.FlowBusinessService; import org.springblade.flowable.core.entity.BladeFlow; +import org.springblade.flowable.core.utils.TaskUtil; import org.springblade.flowable.engine.entity.FlowProcess; import org.springblade.flowable.engine.service.FlowService; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; /** * 流程事务通用接口 @@ -104,15 +101,24 @@ public class WorkController { * 签收事务 * * @param taskId 任务id - * @param user 用户 */ @PostMapping("claim-task") @ApiOperation(value = "签收事务", notes = "传入流程信息", position = 6) - public R claimTask(@ApiParam("任务id") String taskId, BladeUser user) { - taskService.claim(taskId, String.valueOf(user.getAccount())); + public R claimTask(@ApiParam("任务id") String taskId) { + taskService.claim(taskId, TaskUtil.getTaskUser()); return R.success("签收事务成功"); } + /** + * 完成任务 + * + * @param flow 请假信息 + */ + @PostMapping("complete-task") + public R completeTask(@ApiParam("任务信息") @RequestBody BladeFlow flow) { + return R.status(flowBusinessService.completeTask(flow)); + } + /** * 删除任务 * diff --git a/blade-ops/blade-flow/src/main/java/org/springblade/flowable/business/feign/FlowClient.java b/blade-ops/blade-flow/src/main/java/org/springblade/flowable/business/feign/FlowClient.java index 8538cfff..1cb7ec81 100644 --- a/blade-ops/blade-flow/src/main/java/org/springblade/flowable/business/feign/FlowClient.java +++ b/blade-ops/blade-flow/src/main/java/org/springblade/flowable/business/feign/FlowClient.java @@ -21,13 +21,13 @@ import org.flowable.engine.IdentityService; import org.flowable.engine.RuntimeService; import org.flowable.engine.TaskService; import org.flowable.engine.runtime.ProcessInstance; -import org.springblade.core.secure.utils.SecureUtil; import org.springblade.core.tool.api.R; import org.springblade.core.tool.support.Kv; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.StringUtil; import org.springblade.flowable.core.entity.BladeFlow; import org.springblade.flowable.core.feign.IFlowClient; +import org.springblade.flowable.core.utils.TaskUtil; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -52,7 +52,7 @@ public class FlowClient implements IFlowClient { @PostMapping(START_PROCESS_INSTANCE_BY_ID) public R startProcessInstanceById(String processDefinitionId, String businessKey, @RequestBody Map variables) { // 设置流程启动用户 - identityService.setAuthenticatedUserId(String.valueOf(SecureUtil.getUserAccount())); + identityService.setAuthenticatedUserId(TaskUtil.getTaskUser()); // 开启流程 ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinitionId, businessKey, variables); // 组装流程通用类 @@ -65,7 +65,7 @@ public class FlowClient implements IFlowClient { @PostMapping(START_PROCESS_INSTANCE_BY_KEY) public R startProcessInstanceByKey(String processDefinitionKey, String businessKey, @RequestBody Map variables) { // 设置流程启动用户 - identityService.setAuthenticatedUserId(String.valueOf(SecureUtil.getUserAccount())); + identityService.setAuthenticatedUserId(TaskUtil.getTaskUser()); // 开启流程 ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey, variables); // 组装流程通用类 diff --git a/blade-ops/blade-flow/src/main/java/org/springblade/flowable/business/service/FlowBusinessService.java b/blade-ops/blade-flow/src/main/java/org/springblade/flowable/business/service/FlowBusinessService.java index 72ef73ed..61cd718c 100644 --- a/blade-ops/blade-flow/src/main/java/org/springblade/flowable/business/service/FlowBusinessService.java +++ b/blade-ops/blade-flow/src/main/java/org/springblade/flowable/business/service/FlowBusinessService.java @@ -61,4 +61,12 @@ public interface FlowBusinessService { * @return */ IPage selectDonePage(IPage page, BladeFlow bladeFlow); + + /** + * 完成任务 + * + * @param leave 请假信息 + * @return boolean + */ + boolean completeTask(BladeFlow leave); } diff --git a/blade-ops/blade-flow/src/main/java/org/springblade/flowable/business/service/impl/FlowBusinessServiceImpl.java b/blade-ops/blade-flow/src/main/java/org/springblade/flowable/business/service/impl/FlowBusinessServiceImpl.java index 17444d03..e1ab7f75 100644 --- a/blade-ops/blade-flow/src/main/java/org/springblade/flowable/business/service/impl/FlowBusinessServiceImpl.java +++ b/blade-ops/blade-flow/src/main/java/org/springblade/flowable/business/service/impl/FlowBusinessServiceImpl.java @@ -26,17 +26,21 @@ 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.SecureUtil; +import org.springblade.core.tool.support.Kv; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.StringPool; +import org.springblade.core.tool.utils.StringUtil; import org.springblade.flowable.business.service.FlowBusinessService; +import org.springblade.flowable.core.constant.ProcessConstant; import org.springblade.flowable.core.entity.BladeFlow; +import org.springblade.flowable.core.utils.TaskUtil; import org.springblade.flowable.engine.constant.FlowConstant; import org.springblade.flowable.engine.utils.FlowCache; import org.springframework.stereotype.Service; import java.util.LinkedList; import java.util.List; +import java.util.Map; /** * 流程业务实现类 @@ -52,8 +56,8 @@ public class FlowBusinessServiceImpl implements FlowBusinessService { @Override public IPage selectClaimPage(IPage page, BladeFlow bladeFlow) { - String taskUser = String.valueOf(SecureUtil.getUserAccount()); - String taskRole = String.valueOf(SecureUtil.getUserRole()); + String taskUser = TaskUtil.getTaskUser(); + String taskRole = TaskUtil.getCandidateGroup(); List flowList = new LinkedList<>(); // 等待签收的任务 @@ -80,7 +84,7 @@ public class FlowBusinessServiceImpl implements FlowBusinessService { @Override public IPage selectTodoPage(IPage page, BladeFlow bladeFlow) { - String taskUser = String.valueOf(SecureUtil.getUserAccount()); + String taskUser = TaskUtil.getTaskUser(); List flowList = new LinkedList<>(); // 已签收的任务 @@ -103,7 +107,7 @@ public class FlowBusinessServiceImpl implements FlowBusinessService { @Override public IPage selectSendPage(IPage page, BladeFlow bladeFlow) { - String taskUser = String.valueOf(SecureUtil.getUserAccount()); + String taskUser = TaskUtil.getTaskUser(); List flowList = new LinkedList<>(); HistoricProcessInstanceQuery historyQuery = historyService.createHistoricProcessInstanceQuery().startedBy(taskUser).orderByProcessInstanceStartTime().desc(); @@ -158,7 +162,7 @@ public class FlowBusinessServiceImpl implements FlowBusinessService { @Override public IPage selectDonePage(IPage page, BladeFlow bladeFlow) { - String taskUser = String.valueOf(SecureUtil.getUserAccount()); + String taskUser = TaskUtil.getTaskUser(); List flowList = new LinkedList<>(); HistoricTaskInstanceQuery doneQuery = historyService.createHistoricTaskInstanceQuery().taskAssignee(taskUser).finished() @@ -216,6 +220,26 @@ public class FlowBusinessServiceImpl implements FlowBusinessService { return page; } + @Override + public boolean completeTask(BladeFlow flow) { + String taskId = flow.getTaskId(); + String processInstanceId = flow.getProcessInstanceId(); + String comment = Func.toStr(flow.getComment(), ProcessConstant.PASS_COMMENT); + // 增加评论 + if (StringUtil.isNoneBlank(processInstanceId, comment)) { + taskService.addComment(taskId, processInstanceId, comment); + } + // 创建变量 + Map variables = flow.getVariables(); + if (variables == null) { + variables = Kv.create(); + } + variables.put(ProcessConstant.PASS_KEY, flow.isPass()); + // 完成任务 + taskService.complete(taskId, variables); + return true; + } + /** * 构建流程 * diff --git a/blade-ops/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java b/blade-ops/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java index 53c15cc6..46910eec 100644 --- a/blade-ops/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java +++ b/blade-ops/blade-flow/src/main/java/org/springblade/flowable/engine/service/impl/FlowServiceImpl.java @@ -45,6 +45,7 @@ import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.StringPool; import org.springblade.core.tool.utils.StringUtil; import org.springblade.flowable.core.entity.BladeFlow; +import org.springblade.flowable.core.utils.TaskUtil; import org.springblade.flowable.engine.constant.FlowConstant; import org.springblade.flowable.engine.entity.FlowModel; import org.springblade.flowable.engine.entity.FlowProcess; @@ -138,8 +139,8 @@ public class FlowServiceImpl extends ServiceImpl implemen List processInstanceList = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).orderByProcessInstanceStartTime().asc().list(); if (processInstanceList.size() > 0) { if (StringUtil.isNotBlank(processInstanceList.get(0).getStartUserId())) { - String userId = processInstanceList.get(0).getStartUserId(); - User user = UserCache.getUser(Func.toInt(userId)); + String taskUser = processInstanceList.get(0).getStartUserId(); + User user = UserCache.getUser(TaskUtil.getUserId(taskUser)); if (user != null) { flow.setAssignee(historicActivityInstance.getAssignee()); flow.setAssigneeName(user.getName()); @@ -149,7 +150,7 @@ public class FlowServiceImpl extends ServiceImpl implemen } // 获取任务执行人名称 if (StringUtil.isNotBlank(historicActivityInstance.getAssignee())) { - User user = UserCache.getUser(Func.toInt(historicActivityInstance.getAssignee())); + User user = UserCache.getUser(TaskUtil.getUserId(historicActivityInstance.getAssignee())); if (user != null) { flow.setAssignee(historicActivityInstance.getAssignee()); flow.setAssigneeName(user.getName()); diff --git a/blade-ops/blade-flow/src/main/resources/processes/LeaveProcess.bpmn20.xml b/blade-ops/blade-flow/src/main/resources/processes/LeaveProcess.bpmn20.xml index 8504f800..6b5d70d3 100644 --- a/blade-ops/blade-flow/src/main/resources/processes/LeaveProcess.bpmn20.xml +++ b/blade-ops/blade-flow/src/main/resources/processes/LeaveProcess.bpmn20.xml @@ -10,7 +10,7 @@ - + diff --git a/blade-service/blade-desk/src/main/java/org/springblade/desk/controller/LeaveController.java b/blade-service/blade-desk/src/main/java/org/springblade/desk/controller/LeaveController.java index 2b455948..bd1212ed 100644 --- a/blade-service/blade-desk/src/main/java/org/springblade/desk/controller/LeaveController.java +++ b/blade-service/blade-desk/src/main/java/org/springblade/desk/controller/LeaveController.java @@ -22,7 +22,6 @@ import org.springblade.core.boot.ctrl.BladeController; import org.springblade.core.tool.api.R; import org.springblade.desk.entity.ProcessLeave; import org.springblade.desk.service.ILeaveService; -import org.springblade.flowable.core.entity.BladeFlow; import org.springblade.system.user.cache.UserCache; import org.springframework.web.bind.annotation.*; import springfox.documentation.annotations.ApiIgnore; @@ -62,14 +61,4 @@ public class LeaveController extends BladeController implements CacheNames { return R.status(leaveService.startProcess(leave)); } - /** - * 完成任务 - * - * @param flow 请假信息 - */ - @PostMapping("complete-task") - public R completeTask(@RequestBody BladeFlow flow) { - return R.status(leaveService.completeTask(flow)); - } - } diff --git a/blade-service/blade-desk/src/main/java/org/springblade/desk/service/ILeaveService.java b/blade-service/blade-desk/src/main/java/org/springblade/desk/service/ILeaveService.java index 3eea4ee6..06a55e2f 100644 --- a/blade-service/blade-desk/src/main/java/org/springblade/desk/service/ILeaveService.java +++ b/blade-service/blade-desk/src/main/java/org/springblade/desk/service/ILeaveService.java @@ -35,12 +35,4 @@ public interface ILeaveService extends BaseService { */ boolean startProcess(ProcessLeave leave); - /** - * 完成任务 - * - * @param leave 请假信息 - * @return boolean - */ - boolean completeTask(BladeFlow leave); - } diff --git a/blade-service/blade-desk/src/main/java/org/springblade/desk/service/impl/LeaveServiceImpl.java b/blade-service/blade-desk/src/main/java/org/springblade/desk/service/impl/LeaveServiceImpl.java index 431f79fa..4263ad06 100644 --- a/blade-service/blade-desk/src/main/java/org/springblade/desk/service/impl/LeaveServiceImpl.java +++ b/blade-service/blade-desk/src/main/java/org/springblade/desk/service/impl/LeaveServiceImpl.java @@ -31,6 +31,7 @@ import org.springblade.flowable.core.constant.ProcessConstant; import org.springblade.flowable.core.entity.BladeFlow; import org.springblade.flowable.core.feign.IFlowClient; import org.springblade.flowable.core.utils.FlowUtil; +import org.springblade.flowable.core.utils.TaskUtil; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -60,7 +61,7 @@ public class LeaveServiceImpl extends BaseServiceImpl // 启动流程 Kv variables = Kv.create() .set(ProcessConstant.TASK_VARIABLE_CREATE_USER, SecureUtil.getUserName()) - .set("taskUser", leave.getTaskUser()) + .set("taskUser", TaskUtil.getTaskUser(leave.getTaskUser())) .set("days", Duration.between(leave.getStartTime(), leave.getEndTime()).toDays()); R result = flowClient.startProcessInstanceById(leave.getProcessDefinitionId(), FlowUtil.getBusinessKey(businessTable, String.valueOf(leave.getId())), variables); if (result.isSuccess()) { @@ -78,9 +79,4 @@ public class LeaveServiceImpl extends BaseServiceImpl return true; } - @Override - public boolean completeTask(BladeFlow flow) { - R result = flowClient.completeTask(flow.getTaskId(), flow.getProcessInstanceId(), flow.getPassComment(), Kv.create().set("pass", flow.isPass())); - return result.isSuccess(); - } }