diff --git a/renren-admin/src/main/java/io/renren/common/aspect/ActivitiNoticeAspect.java b/renren-admin/src/main/java/io/renren/common/aspect/ActivitiNoticeAspect.java index ac394e2b..5600249a 100644 --- a/renren-admin/src/main/java/io/renren/common/aspect/ActivitiNoticeAspect.java +++ b/renren-admin/src/main/java/io/renren/common/aspect/ActivitiNoticeAspect.java @@ -144,13 +144,16 @@ public class ActivitiNoticeAspect { try { String result; Boolean termination = Boolean.valueOf(kv.get("termination") != null ? kv.get("termination").toString() : Boolean.FALSE.toString()); // 直接终结 + Boolean endByUser = Boolean.valueOf(kv.get("endByUser") != null ? kv.get("endByUser").toString() : Boolean.FALSE.toString()); // 用户终止 Boolean reject = Boolean.valueOf(kv.get("reject") != null ? kv.get("reject").toString() : Boolean.FALSE.toString()); // 被拒绝 - if (Boolean.TRUE.equals(termination)) { - result = "终止被拒"; + if (Boolean.TRUE.equals(endByUser)) { + result = " 发起者终止"; + } else if (Boolean.TRUE.equals(termination)) { + result = " 终止被拒"; } else if (reject) { - result = "被拒"; + result = " 被拒"; } else { - result = "通过"; + result = " 通过"; } String finalCreator = creator; String finalResult = result; @@ -215,8 +218,11 @@ public class ActivitiNoticeAspect { try { String result; Boolean termination = Boolean.valueOf(kv.get("termination") != null ? kv.get("termination").toString() : Boolean.FALSE.toString()); // 直接终结 + Boolean endByUser = Boolean.valueOf(kv.get("endByUser") != null ? kv.get("endByUser").toString() : Boolean.FALSE.toString()); // 用户终止 Boolean reject = Boolean.valueOf(kv.get("reject") != null ? kv.get("reject").toString() : Boolean.FALSE.toString()); // 被拒绝 - if (Boolean.TRUE.equals(termination)) { + if (Boolean.TRUE.equals(endByUser)) { + result = " 发起者终止"; + } else if (Boolean.TRUE.equals(termination)) { result = "终止被拒"; } else if (Boolean.TRUE.equals(reject)) { result = "被拒"; diff --git a/renren-admin/src/main/java/io/renren/common/dto/AuditingBaseDTO.java b/renren-admin/src/main/java/io/renren/common/dto/AuditingBaseDTO.java index 4ca445b3..23e4102f 100644 --- a/renren-admin/src/main/java/io/renren/common/dto/AuditingBaseDTO.java +++ b/renren-admin/src/main/java/io/renren/common/dto/AuditingBaseDTO.java @@ -34,4 +34,9 @@ public class AuditingBaseDTO implements Serializable { */ private Boolean backPreviousTask = null; + /** + * 发起者主动终止流程 + */ + private Boolean endByUser = null; + } diff --git a/renren-admin/src/main/java/io/renren/modules/activiti/controller/ActTaskController.java b/renren-admin/src/main/java/io/renren/modules/activiti/controller/ActTaskController.java index aaec2727..4250c37d 100644 --- a/renren-admin/src/main/java/io/renren/modules/activiti/controller/ActTaskController.java +++ b/renren-admin/src/main/java/io/renren/modules/activiti/controller/ActTaskController.java @@ -9,6 +9,7 @@ import io.renren.common.utils.Result; import io.renren.modules.activiti.dto.TaskDTO; import io.renren.modules.activiti.service.ActTaskService; import io.renren.modules.security.user.SecurityUser; +import io.renren.modules.security.user.UserDetail; import io.renren.modules.sys.dto.SysUserDTO; import io.renren.modules.sys.service.SysUserService; import io.swagger.annotations.Api; @@ -295,11 +296,12 @@ public class ActTaskController { }) // @RequiresPermissions("sys:task:all") public Result endProcess(String taskId, String instanceId, String comment) { + final UserDetail user = SecurityUser.getUser(); if (!StringUtils.isEmpty(taskId)) { // 存在taskId actTaskService.endProcess(taskId, comment); } if (StringUtils.isEmpty(taskId) && !StringUtils.isEmpty(instanceId)) { // 通过实例id - actTaskService.endProcessInstanceId(taskId, comment); + actTaskService.endProcessInstanceId(instanceId, comment, user.getId().toString()); } return new Result(); } diff --git a/renren-admin/src/main/java/io/renren/modules/activiti/service/ActTaskService.java b/renren-admin/src/main/java/io/renren/modules/activiti/service/ActTaskService.java index 30bbd0ed..42a7c5df 100644 --- a/renren-admin/src/main/java/io/renren/modules/activiti/service/ActTaskService.java +++ b/renren-admin/src/main/java/io/renren/modules/activiti/service/ActTaskService.java @@ -430,6 +430,31 @@ public class ActTaskService extends BaseServiceImpl { return flag; } + private boolean isMultiInstanceByInstanceId(String instanceId, String userId) { + boolean flag = false; + Task task = taskService.createTaskQuery().processInstanceId(instanceId).taskAssignee(userId).list().stream().sorted( + Comparator.comparing(x -> { + Task index = (Task) x; + return index.getCreateTime(); + }).reversed() + ).limit(1).findAny().orElse(null); + if (task != null) { + // 获取流程定义id + String processDefinitionId = task.getProcessDefinitionId(); + ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(processDefinitionId); + // 根据活动id获取活动实例 + ActivityImpl activityImpl = processDefinitionEntity.findActivity(task.getTaskDefinitionKey()); + if ((activityImpl).getActivityBehavior() instanceof ParallelMultiInstanceBehavior) { + ParallelMultiInstanceBehavior behavior = (ParallelMultiInstanceBehavior) activityImpl.getActivityBehavior(); + if (behavior != null && behavior.getCollectionExpression() != null) { + flag = true; + } + } + } + + return flag; + } + /** * 删除任务下的所有变量 * @@ -625,12 +650,21 @@ public class ActTaskService extends BaseServiceImpl { } @Transactional(rollbackFor = Exception.class) - public void endProcessInstanceId(String instanceId, String comment) { - if (isMultiInstance(instanceId)) { + public void endProcessInstanceId(String instanceId, String comment, String userId) { + if (isMultiInstanceByInstanceId(instanceId, userId)) { throw new RenException(ErrorCode.END_PROCESS_PARALLEL_ERROR); } - Task task = taskService.createTaskQuery().processInstanceId(instanceId).singleResult(); - List tasks = taskService.createTaskQuery().processInstanceId(task.getProcessInstanceId()) + Task task = taskService.createTaskQuery().processInstanceId(instanceId).taskAssignee(userId).list().stream().sorted( + Comparator.comparing(x -> { + Task index = (Task) x; + return index.getCreateTime(); + }).reversed() + ).limit(1).findAny().orElse(null); + if (task == null) { + logger.error("查不到流程对应task"); + return; + } + List tasks = taskService.createTaskQuery().processInstanceId(task.getProcessInstanceId()).taskAssignee(userId) .taskDefinitionKey(task.getTaskDefinitionKey()).list(); if (tasks.size() > 1) { throw new RenException(ErrorCode.END_PROCESS_HANDLEING_ERROR); @@ -644,7 +678,7 @@ public class ActTaskService extends BaseServiceImpl { taskService.resolveTask(task.getId()); } taskService.addComment(task.getId(), task.getProcessInstanceId(), comment); - taskService.complete(instanceId); + taskService.complete(task.getId()); } else { ActivityImpl currActivity = findActivitiImplByInstanceId(instanceId, null); List oriPvmTransitionList = new ArrayList(); @@ -664,8 +698,9 @@ public class ActTaskService extends BaseServiceImpl { comment = message + "[" + comment + "]"; taskService.addComment(task.getId(), task.getProcessInstanceId(), comment); taskService.setVariable(task.getId(), Task_HANDLE_STATE, Task_HANDLE_STATE_STOP); + taskService.setVariable(task.getId(), "endByUser", Boolean.TRUE); // 主动终止流程 taskService.setVariable(task.getId(), "reject", Boolean.TRUE); // 存在被拒绝的批示 - taskService.complete(instanceId); + taskService.complete(task.getId()); pointActivity.getIncomingTransitions().remove(newTransition); List pvmTransitionListC = currActivity.getOutgoingTransitions(); pvmTransitionListC.clear(); @@ -701,7 +736,7 @@ public class ActTaskService extends BaseServiceImpl { } private ActivityImpl findActivitiImplByInstanceId(String instanceId, String activityId) { - Task task = taskService.createTaskQuery().processInstanceId(instanceId).singleResult(); + Task task = taskService.createTaskQuery().processInstanceId(instanceId).list().stream().findAny().orElse(null); if (task == null) { return null; }