package org.springblade.mdm.flow.service;
|
|
import lombok.AllArgsConstructor;
|
import org.flowable.engine.TaskService;
|
import org.flowable.task.api.Task;
|
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.Date;
|
import java.util.UUID;
|
|
@AllArgsConstructor
|
@Service
|
public class FlowTransferService {
|
|
private final TaskService taskService;
|
|
/**
|
* 转派,并记录自己的备注信息
|
* @param taskId 任务id
|
* @param newAssigneeId 转派给
|
* @param comment 评论信息
|
*/
|
@Transactional
|
public void transferTask(String taskId, String newAssigneeId,String comment) {
|
|
Task currTask = taskService.createTaskQuery().taskId(taskId).singleResult();
|
|
//if (currTask != null) {
|
//1.生成历史记录
|
TaskEntity subtask = this.createSubTask(currTask, currTask.getAssignee());
|
//2.添加审批意见
|
//this.addComment(subtask.getId(), turnTaskVo.getUserCode(), turnTaskVo.getProcessInstanceId(), CommentTypeEnum.ZB.toString(), turnTaskVo.getMessage());
|
taskService.addComment(subtask.getId(), currTask.getProcessInstanceId(), comment);
|
taskService.complete(subtask.getId());
|
//3.转办
|
//taskService.setAssignee(turnTaskVo.getTaskId(), turnTaskVo.getTurnToUserId());
|
taskService.setAssignee(taskId, newAssigneeId);
|
//taskService.setOwner(taskId, currTask.getAssignee());
|
taskService.setOwner(taskId, newAssigneeId);
|
//returnVo = new ReturnVo<>(ReturnCode.SUCCESS, "转办成功");
|
//}
|
|
// 增加评论
|
//taskService.addComment(taskId, currTask.getProcessInstanceId(), comment);
|
// 完成任务
|
//taskService.setAssignee(taskId, newAssigneeId);
|
|
//自荐表增加评论数据
|
//approveRecordService.saveApproveRecords(currTask,"Y",comment);
|
}
|
|
TaskEntity createSubTask(Task ptask, String assignee) {
|
TaskEntity task = null;
|
if (ptask != null) {
|
//1.生成子任务
|
UUID uuid = UUID.randomUUID();
|
task = (TaskEntity) taskService.newTask(uuid.toString());
|
task.setCategory(ptask.getCategory());
|
task.setDescription(ptask.getDescription());
|
task.setTenantId(ptask.getTenantId());
|
task.setAssignee(assignee);
|
task.setName(ptask.getName());
|
task.setParentTaskId(ptask.getId());
|
task.setProcessDefinitionId(ptask.getProcessDefinitionId());
|
task.setProcessInstanceId(ptask.getProcessInstanceId());
|
task.setTaskDefinitionKey(ptask.getTaskDefinitionKey());
|
task.setTaskDefinitionId(ptask.getTaskDefinitionId());
|
task.setPriority(ptask.getPriority());
|
task.setCreateTime(new Date());
|
taskService.saveTask(task);
|
}
|
return task;
|
}
|
}
|