yangys
2025-08-14 33e6270d2d3a40591e58d45fd8435d2f3eaf66b2
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
package org.springblade.mdm.flow.service.execute;
 
import io.swagger.v3.oas.annotations.Parameter;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.task.api.Task;
import org.springblade.mdm.flow.service.ApproveRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
 
import java.util.Map;
 
/**
 * 任务完成接口
 */
@Service
public abstract class AbstractFlowCompleteService {
    @Autowired
    protected TaskService taskService;
    @Autowired
    protected RuntimeService runtimeService;
    @Autowired
    protected ApproveRecordService approveRecordService;
    @Transactional
    public abstract void completeTask(String taskId, String processInstanceId, String comment, @Parameter(name = "variables", description = "流程变量") @RequestBody Map<String, Object> variables);
 
    /**
     * 获取审批结果 Y/N
     * @param variables 前端提交的变量map
     * @return Y/N 字符串
     */
    protected String getApproveResult(Map<String, Object> variables){
        return  variables.get("approve")+"";
    }
    /**
     * 获取当前正在执行的任务
     * @param taskId 任务id
     * @return 任务实体
     */
    Task currentTask(String taskId) {
        return taskService.createTaskQuery()
            .taskId(taskId)
            .singleResult();
    }
    void addApproveRecord(String taskId,String comment,Map<String, Object> variables){
        String operateResult = variables.get("approve")+"";
        approveRecordService.saveApproveRecords(currentTask(taskId),operateResult,comment);
    }
}