|
@@ -2,18 +2,12 @@ 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.cmd.GetLoopCharacteristics;
|
|
|
-import com.flow.cmd.GetMultiInstanceRootExecution;
|
|
|
-import com.flow.cmd.JumpActivityCmd;
|
|
|
import com.flow.common.core.exception.BaseException;
|
|
|
import com.flow.common.core.model.PageResult;
|
|
|
import com.flow.common.core.util.SecurityContextUtil;
|
|
|
-import com.flow.common.mybatis.constant.SqlConstant;
|
|
|
import com.flow.common.mybatis.service.impl.BaseServiceImpl;
|
|
|
import com.flow.dao.FlowTaskDao;
|
|
|
-import com.flow.entity.FlowActivity;
|
|
|
import com.flow.entity.FlowDefine;
|
|
|
import com.flow.entity.FlowInstance;
|
|
|
import com.flow.entity.FlowTask;
|
|
@@ -22,20 +16,25 @@ 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.JumpActivityCmd;
|
|
|
+import com.flow.flowable.utils.ProcessUtil;
|
|
|
import com.flow.model.*;
|
|
|
import com.flow.service.FlowActivityService;
|
|
|
import com.flow.service.FlowDefineService;
|
|
|
import com.flow.service.FlowInstanceService;
|
|
|
import com.flow.service.FlowTaskService;
|
|
|
-import com.flow.utils.ProcessUtil;
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
-import com.google.common.collect.Lists;
|
|
|
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;
|
|
|
import org.flowable.task.api.Task;
|
|
|
import org.flowable.task.api.TaskInfo;
|
|
@@ -186,42 +185,16 @@ public class FlowTaskServiceImpl extends BaseServiceImpl<FlowTaskDao, FlowTask>
|
|
|
public void reject(RejectTaskForm taskForm) {
|
|
|
Task task = this.comment(taskForm);
|
|
|
this.updateStatus(task.getId(), ProcessStatus.REJECT);
|
|
|
- flowActivityService.lambdaUpdate()
|
|
|
- .eq(FlowActivity::getTaskId, taskForm.getTaskId())
|
|
|
- .set(FlowActivity::getStatus, ProcessStatus.REJECT)
|
|
|
- .set(FlowActivity::getUserId, task.getAssignee())
|
|
|
- .update();
|
|
|
// 回退节点
|
|
|
- List<String> executionIds = managementService.executeCommand(new JumpActivityCmd(
|
|
|
+ managementService.executeCommand(new JumpActivityCmd(
|
|
|
task.getProcessInstanceId(),
|
|
|
taskForm.getTargetNode()
|
|
|
));
|
|
|
- // 删除进行中节点
|
|
|
- if (CollectionUtils.isNotEmpty(executionIds)) {
|
|
|
- flowActivityService.lambdaUpdate()
|
|
|
- .eq(FlowActivity::getInstanceId, task.getProcessInstanceId())
|
|
|
- .eq(FlowActivity::getStatus, ProcessStatus.RUNNING)
|
|
|
- .in(FlowActivity::getParentId, executionIds)
|
|
|
- .remove();
|
|
|
- }
|
|
|
- // 操作记录
|
|
|
- Optional<FlowActivity> optional = flowActivityService.lambdaQuery()
|
|
|
- .eq(FlowActivity::getTaskId, taskForm.getTaskId())
|
|
|
- .oneOpt();
|
|
|
- if (optional.isPresent()) {
|
|
|
- FlowDefine define = flowDefineService.getDefine(task.getProcessDefinitionId());
|
|
|
- Node node = define.getNode(taskForm.getTargetNode(), Node.class);
|
|
|
- FlowActivity flowActivity = optional.get();
|
|
|
- List<Comment> comments = Optional.ofNullable(flowActivity.getComment()).orElse(Lists.newArrayList());
|
|
|
- Comment comment = new Comment();
|
|
|
- comment.setUserId(SecurityContextUtil.getUserId());
|
|
|
- comment.setTime(LocalDateTime.now());
|
|
|
- comment.setContent(String.format("<span>退回至 <span class='color-error'>%s</span></span>", node.getName()));
|
|
|
- comment.setAttachments(Lists.newArrayList());
|
|
|
- comments.add(comment);
|
|
|
- flowActivity.setComment(comments);
|
|
|
- flowActivityService.updateById(flowActivity);
|
|
|
- }
|
|
|
+ taskService.addComment(
|
|
|
+ task.getId(),
|
|
|
+ task.getProcessInstanceId(),
|
|
|
+ String.format("<span>退回至 <span class='color-error'>%s</span></span>", task.getName())
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -229,11 +202,6 @@ public class FlowTaskServiceImpl extends BaseServiceImpl<FlowTaskDao, FlowTask>
|
|
|
public void refuse(TaskForm taskForm) {
|
|
|
Task task = this.comment(taskForm);
|
|
|
this.updateStatus(task.getId(), ProcessStatus.REFUSE);
|
|
|
- flowActivityService.lambdaUpdate()
|
|
|
- .eq(FlowActivity::getTaskId, taskForm.getTaskId())
|
|
|
- .set(FlowActivity::getStatus, ProcessStatus.REFUSE)
|
|
|
- .set(FlowActivity::getUserId, task.getAssignee())
|
|
|
- .update();
|
|
|
flowInstanceService.reject(task.getProcessInstanceId());
|
|
|
}
|
|
|
|
|
@@ -254,11 +222,11 @@ public class FlowTaskServiceImpl extends BaseServiceImpl<FlowTaskDao, FlowTask>
|
|
|
TaskForm taskForm = new TaskForm();
|
|
|
taskForm.setTaskId(task.getId());
|
|
|
taskForm.setValues(variables);
|
|
|
- Comment comment = new Comment();
|
|
|
- comment.setUserId("admin");
|
|
|
- comment.setTime(LocalDateTime.now());
|
|
|
- comment.setContent(String.format("<span><span class='color-error'>自动拒绝</span>%s</span>", Optional.ofNullable(content).orElse("")));
|
|
|
- taskForm.setComment(comment);
|
|
|
+ FlowComment flowComment = new FlowComment();
|
|
|
+ flowComment.setUserId("admin");
|
|
|
+ flowComment.setTime(new Date());
|
|
|
+ flowComment.setContent(String.format("<span><span class='color-error'>自动拒绝</span>%s</span>", Optional.ofNullable(content).orElse("")));
|
|
|
+ taskForm.setComment(flowComment);
|
|
|
this.refuse(taskForm);
|
|
|
}
|
|
|
|
|
@@ -267,15 +235,6 @@ public class FlowTaskServiceImpl extends BaseServiceImpl<FlowTaskDao, FlowTask>
|
|
|
public void transfer(TransferTaskForm taskForm) {
|
|
|
Task task = this.comment(taskForm);
|
|
|
taskService.setAssignee(task.getId(), taskForm.getAssignee());
|
|
|
- Optional<FlowActivity> optional = flowActivityService.lambdaQuery()
|
|
|
- .eq(FlowActivity::getTaskId, taskForm.getTaskId())
|
|
|
- .last(SqlConstant.LIMIT1)
|
|
|
- .oneOpt();
|
|
|
- if (optional.isPresent()) {
|
|
|
- FlowActivity flowActivity = optional.get();
|
|
|
- flowActivity.setUserId(taskForm.getAssignee());
|
|
|
- flowActivityService.updateById(flowActivity);
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -353,12 +312,6 @@ public class FlowTaskServiceImpl extends BaseServiceImpl<FlowTaskDao, FlowTask>
|
|
|
}
|
|
|
assigneeList.remove(taskForm.getAssignee());
|
|
|
runtimeService.setVariable(taskInfo.getProcessInstanceId(), collectionName, assigneeList);
|
|
|
- flowActivityService.lambdaUpdate()
|
|
|
- .eq(FlowActivity::getInstanceId, taskInfo.getProcessInstanceId())
|
|
|
- .eq(FlowActivity::getNodeId, taskInfo.getTaskDefinitionKey())
|
|
|
- .eq(FlowActivity::getUserId, taskForm.getAssignee())
|
|
|
- // .isNull(FlowActivity::getEndTime)
|
|
|
- .remove();
|
|
|
}
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -436,11 +389,11 @@ public class FlowTaskServiceImpl extends BaseServiceImpl<FlowTaskDao, FlowTask>
|
|
|
TaskForm taskForm = new TaskForm();
|
|
|
taskForm.setTaskId(task.getId());
|
|
|
taskForm.setValues(variables);
|
|
|
- Comment comment = new Comment();
|
|
|
- comment.setUserId("admin");
|
|
|
- comment.setTime(LocalDateTime.now());
|
|
|
- comment.setContent(String.format("<span><span class='color-primary'>自动通过</span>%s</span>", Optional.ofNullable(content).orElse("")));
|
|
|
- taskForm.setComment(comment);
|
|
|
+ FlowComment flowComment = new FlowComment();
|
|
|
+ flowComment.setUserId("admin");
|
|
|
+ flowComment.setTime(new Date());
|
|
|
+ flowComment.setContent(String.format("<span><span class='color-primary'>自动通过</span>%s</span>", Optional.ofNullable(content).orElse("")));
|
|
|
+ taskForm.setComment(flowComment);
|
|
|
this.complete(taskForm);
|
|
|
}
|
|
|
|
|
@@ -454,27 +407,43 @@ public class FlowTaskServiceImpl extends BaseServiceImpl<FlowTaskDao, FlowTask>
|
|
|
if (task.isSuspended()) {
|
|
|
throw new BaseException("任务已挂起");
|
|
|
}
|
|
|
- Comment comment = taskForm.getComment();
|
|
|
- if (Objects.nonNull(comment)) {
|
|
|
- if (StringUtils.isNotBlank(comment.getContent()) || CollectionUtils.isNotEmpty(comment.getAttachments())) {
|
|
|
- comment.setUserId(SecurityContextUtil.getUserId());
|
|
|
- comment.setTime(LocalDateTime.now());
|
|
|
- Optional<FlowActivity> optional = flowActivityService.lambdaQuery()
|
|
|
- .eq(FlowActivity::getTaskId, task.getId())
|
|
|
- .last("limit 1")
|
|
|
- .oneOpt();
|
|
|
- if (optional.isPresent()) {
|
|
|
- FlowActivity flowActivity = optional.get();
|
|
|
- List<Comment> comments = Optional.ofNullable(flowActivity.getComment()).orElse(Lists.newArrayList());
|
|
|
- comments.add(comment);
|
|
|
- flowActivity.setComment(comments);
|
|
|
- flowActivityService.updateById(flowActivity);
|
|
|
- }
|
|
|
- }
|
|
|
+ Authentication.setAuthenticatedUserId(SecurityContextUtil.getUserId());
|
|
|
+ FlowComment flowComment = taskForm.getComment();
|
|
|
+ // 评论
|
|
|
+ Comment comment = taskService.addComment(
|
|
|
+ task.getId(),
|
|
|
+ task.getProcessInstanceId(),
|
|
|
+ flowComment.getContent()
|
|
|
+ );
|
|
|
+ // 附件
|
|
|
+ List<FlowAttachment> flowAttachments = flowComment.getAttachments();
|
|
|
+ for (FlowAttachment flowAttachment : flowAttachments) {
|
|
|
+ taskService.createAttachment(
|
|
|
+ flowAttachment.getType(),
|
|
|
+ task.getId(),
|
|
|
+ task.getProcessInstanceId(),
|
|
|
+ flowAttachment.getName(),
|
|
|
+ comment.getId(),
|
|
|
+ flowAttachment.getUrl()
|
|
|
+ );
|
|
|
}
|
|
|
return task;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<FlowComment> getComments(String taskId) {
|
|
|
+ List<Comment> taskComments = taskService.getTaskComments(taskId);
|
|
|
+ List<Attachment> taskAttachments = taskService.getTaskAttachments(taskId);
|
|
|
+ return taskComments.stream()
|
|
|
+ .map(comment -> {
|
|
|
+ List<Attachment> attachments = taskAttachments.stream()
|
|
|
+ .filter(a -> comment.getId().equals(a.getDescription()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ return new FlowComment(comment, attachments);
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<Node> getParentNodes(String taskId) {
|
|
|
TaskInfo taskInfo = this.getTask(taskId);
|