yangys
2025-09-18 0d61b9bfca526e9c3da2209de8f9f367e76fd013
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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;
    }
}