|
@@ -2,6 +2,7 @@ package com.flow.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.flow.common.core.exception.BaseException;
|
|
|
import com.flow.common.core.model.PageResult;
|
|
@@ -16,22 +17,19 @@ import com.flow.entity.node.FormProperty;
|
|
|
import com.flow.entity.node.Node;
|
|
|
import com.flow.entity.node.StartNode;
|
|
|
import com.flow.enums.ProcessStatus;
|
|
|
-import com.flow.flowable.cmd.GetLoopCharacteristics;
|
|
|
-import com.flow.flowable.cmd.GetMultiInstanceRootExecution;
|
|
|
+import com.flow.flowable.cmd.AddMultiInstanceExecutionCmd;
|
|
|
+import com.flow.flowable.cmd.DeleteMultiInstanceExecutionCmd;
|
|
|
import com.flow.flowable.cmd.JumpActivityCmd;
|
|
|
import com.flow.flowable.utils.ProcessElementUtil;
|
|
|
import com.flow.model.*;
|
|
|
import com.flow.service.FlowDefineService;
|
|
|
import com.flow.service.FlowInstanceService;
|
|
|
import com.flow.service.FlowTaskService;
|
|
|
-import com.google.common.collect.ImmutableMap;
|
|
|
import org.flowable.bpmn.model.BpmnModel;
|
|
|
-import org.flowable.bpmn.model.MultiInstanceLoopCharacteristics;
|
|
|
import org.flowable.bpmn.model.UserTask;
|
|
|
import org.flowable.common.engine.impl.identity.Authentication;
|
|
|
import org.flowable.engine.*;
|
|
|
import org.flowable.engine.runtime.ActivityInstance;
|
|
|
-import org.flowable.engine.runtime.Execution;
|
|
|
import org.flowable.engine.task.Attachment;
|
|
|
import org.flowable.engine.task.Comment;
|
|
|
import org.flowable.task.api.DelegationState;
|
|
@@ -244,77 +242,22 @@ public class FlowTaskServiceImpl extends BaseServiceImpl<FlowTaskDao, FlowTask>
|
|
|
@Override
|
|
|
public void addSign(AddSignTaskForm taskForm) {
|
|
|
Task taskInfo = this.comment(taskForm);
|
|
|
- String collectionName = String.format("%sCollection", taskInfo.getTaskDefinitionKey());
|
|
|
- List<String> assigneeList = runtimeService.getVariable(
|
|
|
+ managementService.executeCommand(new AddMultiInstanceExecutionCmd(
|
|
|
taskInfo.getProcessInstanceId(),
|
|
|
- collectionName,
|
|
|
- List.class
|
|
|
+ taskInfo.getTaskDefinitionKey(),
|
|
|
+ taskForm.getAssignee())
|
|
|
);
|
|
|
- if (Objects.nonNull(assigneeList) && assigneeList.contains(taskForm.getAssignee())) {
|
|
|
- throw new BaseException("加签人员已存在");
|
|
|
- }
|
|
|
- int index = assigneeList.indexOf(taskInfo.getAssignee());
|
|
|
- if (index != -1) {
|
|
|
- assigneeList.add(index + 1, taskForm.getAssignee());
|
|
|
- } else {
|
|
|
- assigneeList.add(taskForm.getAssignee());
|
|
|
- }
|
|
|
- runtimeService.setVariable(taskInfo.getProcessInstanceId(), collectionName, assigneeList);
|
|
|
- Execution miExecution = managementService.executeCommand(new GetMultiInstanceRootExecution(taskInfo.getProcessInstanceId(), taskInfo.getTaskDefinitionKey()));
|
|
|
- Integer nrOfInstances = runtimeService.getVariableLocal(miExecution.getId(), "nrOfInstances", Integer.class);
|
|
|
- runtimeService.setVariableLocal(miExecution.getId(), "nrOfInstances", nrOfInstances + 1);
|
|
|
- MultiInstanceLoopCharacteristics loopCharacteristics = managementService.executeCommand(new GetLoopCharacteristics(taskInfo.getProcessInstanceId(), taskInfo.getTaskDefinitionKey()));
|
|
|
- if (!loopCharacteristics.isSequential()) {
|
|
|
- Integer nrOfActiveInstances = runtimeService.getVariableLocal(miExecution.getId(), "nrOfActiveInstances", Integer.class);
|
|
|
- runtimeService.setVariableLocal(miExecution.getId(), "nrOfActiveInstances", nrOfActiveInstances + 1);
|
|
|
- runtimeService.addMultiInstanceExecution(
|
|
|
- taskInfo.getTaskDefinitionKey(),
|
|
|
- taskInfo.getProcessInstanceId(),
|
|
|
- ImmutableMap.of(loopCharacteristics.getElementVariable(), taskForm.getAssignee())
|
|
|
- );
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
public void removeSign(AddSignTaskForm taskForm) {
|
|
|
- TaskInfo taskInfo = this.getTask(taskForm.getTaskId());
|
|
|
- String collectionName = String.format("%sCollection", taskInfo.getTaskDefinitionKey());
|
|
|
- Execution miExecution = managementService.executeCommand(new GetMultiInstanceRootExecution(taskInfo.getProcessInstanceId(), taskInfo.getTaskDefinitionKey()));
|
|
|
- Integer nrOfInstances = runtimeService.getVariableLocal(miExecution.getId(), "nrOfInstances", Integer.class);
|
|
|
- runtimeService.setVariableLocal(miExecution.getId(), "nrOfInstances", nrOfInstances - 1);
|
|
|
- MultiInstanceLoopCharacteristics loopCharacteristics = managementService.executeCommand(new GetLoopCharacteristics(taskInfo.getProcessInstanceId(), taskInfo.getTaskDefinitionKey()));
|
|
|
- List<String> assigneeList = runtimeService.getVariable(taskInfo.getProcessInstanceId(), collectionName, List.class);
|
|
|
- if (assigneeList.size() == 1) {
|
|
|
- throw new BaseException("会签必须保留一个用户");
|
|
|
- }
|
|
|
- if (loopCharacteristics.isSequential()) {
|
|
|
- Integer loopCounter = runtimeService.getVariableLocal(taskInfo.getExecutionId(), "loopCounter", Integer.class);
|
|
|
- if (!assigneeList.subList(loopCounter, assigneeList.size() - 1).contains(taskForm.getAssignee())) {
|
|
|
- throw new BaseException(String.format("会签后续办理者中没有用户:%s", taskForm.getAssignee()));
|
|
|
- }
|
|
|
- } else {
|
|
|
- List<Task> tasks = taskService.createTaskQuery()
|
|
|
- .processInstanceId(taskInfo.getProcessInstanceId())
|
|
|
- .taskDefinitionKey(taskInfo.getTaskDefinitionKey())
|
|
|
- .active()
|
|
|
- .list();
|
|
|
- if (tasks.stream().noneMatch(task -> task.getAssignee().equals(taskForm.getAssignee()))) {
|
|
|
- throw new BaseException(String.format("会签后续办理者中没有用户:%s", taskForm.getAssignee()));
|
|
|
- }
|
|
|
- Integer nrOfActiveInstances = runtimeService.getVariableLocal(miExecution.getId(), "nrOfActiveInstances", Integer.class);
|
|
|
- runtimeService.setVariableLocal(miExecution.getId(), "nrOfActiveInstances", nrOfActiveInstances - 1);
|
|
|
- List<Task> deleteTasks = taskService.createTaskQuery()
|
|
|
- .processInstanceId(taskInfo.getProcessInstanceId())
|
|
|
- .taskDefinitionKey(taskInfo.getTaskDefinitionKey())
|
|
|
- .taskAssignee(taskForm.getAssignee())
|
|
|
- .list();
|
|
|
- for (Task deleteTask : deleteTasks) {
|
|
|
- runtimeService.deleteMultiInstanceExecution(deleteTask.getExecutionId(), false);
|
|
|
- }
|
|
|
- }
|
|
|
- assigneeList.remove(taskForm.getAssignee());
|
|
|
- runtimeService.setVariable(taskInfo.getProcessInstanceId(), collectionName, assigneeList);
|
|
|
+ Task taskInfo = this.comment(taskForm);
|
|
|
+ managementService.executeCommand(new DeleteMultiInstanceExecutionCmd(
|
|
|
+ taskInfo.getProcessInstanceId(),
|
|
|
+ taskInfo.getTaskDefinitionKey(),
|
|
|
+ taskInfo.getAssignee()
|
|
|
+ ));
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -412,6 +355,11 @@ public class FlowTaskServiceImpl extends BaseServiceImpl<FlowTaskDao, FlowTask>
|
|
|
}
|
|
|
Authentication.setAuthenticatedUserId(SecurityContextUtil.getUserId());
|
|
|
FlowComment flowComment = taskForm.getComment();
|
|
|
+ List<FlowAttachment> attachments = flowComment.getAttachments();
|
|
|
+ String content = flowComment.getContent();
|
|
|
+ if (CollectionUtils.isEmpty(attachments) && StringUtils.isBlank(content)) {
|
|
|
+ return task;
|
|
|
+ }
|
|
|
// 评论
|
|
|
Comment comment = taskService.addComment(
|
|
|
task.getId(),
|