yangys
2025-08-13 44b55dd34d09090fe6fdeb7d2428efe9e775424c
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package org.springblade.mdm.flow.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.SerializationException;
import org.apache.commons.lang3.StringUtils;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.support.Kv;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.mdm.flow.constants.FlowContants;
import org.springblade.mdm.flow.entity.ApproveRecord;
import org.springblade.mdm.flow.excution.StartDispatcher;
import org.springblade.mdm.flow.service.ApproveRecordService;
import org.springblade.mdm.flow.service.FlowCommonService;
import org.springblade.mdm.flow.service.FlowProgramFileService;
import org.springblade.mdm.flow.service.TaskDispatchService;
import org.springblade.mdm.flow.service.execute.AbstractFlowCompleteService;
import org.springblade.mdm.flow.service.execute.BatchDispatchService;
import org.springblade.mdm.flow.service.execute.DefaultFlowCompleteService;
import org.springblade.mdm.flow.service.execute.TryFlowCompleteService;
import org.springblade.mdm.flow.vo.BatchDispatchVO;
import org.springblade.mdm.flow.vo.TaskAssignVO;
import org.springblade.mdm.program.entity.ProcessProgRef;
import org.springblade.mdm.program.service.NcNodeAutoCreateService;
import org.springblade.mdm.program.service.ProcessProgRefService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
 
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/flow/dispatch")
@Tag(name = "派工流程", description = "派工流程")
public class DispatchController {
 
    private final StartDispatcher dispatcher;
 
    private final TaskService taskService;
    private final RuntimeService runtimeService;
    private final ProcessProgRefService processProgRefService;
 
    private final ApproveRecordService approveRecordService;
    private final FlowProgramFileService flowProgramFileService;
 
 
    private final TryFlowCompleteService tryFlowCompleteService;
    private final DefaultFlowCompleteService defaultFlowCompleteService;
    private final TaskDispatchService taskDispatchService;
    private final BatchDispatchService dispatchService;
 
    /**
     * 发起派工流程
     */
    @PostMapping("/start")
    @Operation(summary = "任务计划(派工流程)", description = "启动派工流程")
    public R<Boolean> start(@RequestBody TaskAssignVO startVO) {
        try {
            long id= taskDispatchService.saveTask(startVO);
            String instId = dispatcher.start(startVO);
            taskDispatchService.updateSuccess(id,instId);
            return R.data(true);
        }catch(Exception e){
            return R.fail(e.getMessage());
        }
 
    }
 
    AbstractFlowCompleteService getActualService(String processInstanceId){
        ProcessInstance inst = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
        if(inst.getProcessDefinitionKey().equals(FlowContants.TRY_PROCESS_KEY) || inst.getProcessDefinitionKey().equals(FlowContants.CURE_PROCESS_KEY) || inst.getProcessDefinitionKey().equals(FlowContants.REPLACE_PROCESS_KEY)){
            return tryFlowCompleteService;
        }else{
            return defaultFlowCompleteService;
        }
    }
    @Operation(summary = "完成任务", description = "流向下一个节点")
    @PostMapping("completeTask")
    public R<Void> completeTask(String taskId, String processInstanceId, String comment,@Parameter(name = "variables", description = "任务变量") @RequestBody Map<String, Object> variables) {
        try {
            AbstractFlowCompleteService completeService = getActualService(processInstanceId);
            completeService.completeTask(taskId, processInstanceId, comment, variables);
 
 
            return R.success("流程提交成功");
        }catch(Exception e){
            return R.fail(e.getMessage());
        }
 
 
    }
 
    @Operation(summary = "手动批量派工", description = "组长手动批量派工")
    @PostMapping("batchDispatch")
    public R<Void> batchDispatch(@RequestBody BatchDispatchVO batchDispatchVO) {
        try {
            dispatchService.batchDispatchTask(batchDispatchVO);
            return R.success("流程提交成功");
        }catch(Exception e){
            return R.fail(e.getMessage());
        }
 
    }
 
    @Operation(summary = "自动批量派工", description = "组长批量派工,后端自动查找处理人")
    @PostMapping("batchDispatchAuto")
    public R<Void> batchDispatchAuto(@RequestBody BatchDispatchVO batchDispatchVO) {
        try {
            dispatchService.batchAutoDispatchTask(batchDispatchVO);
            return R.success("流程提交成功");
        }catch(Exception e){
            return R.fail(e.getMessage());
        }
 
    }
 
    @Operation(summary = "批量审批", description = "高师批量审批")
    @PostMapping("batchApprove")
    public R<Void> batchApprove(@RequestBody BatchDispatchVO batchDispatchVO) {
        try {
            dispatchService.batchApprove(batchDispatchVO);
            return R.success("流程提交成功");
        }catch(Exception e){
            return R.fail(e.getMessage());
        }
 
    }
    /*
    void addApproveRecord(String taskId,String comment,Map<String, Object> variables){
        String operateResult = variables.get("approve")+"";
 
        Task task = taskService.createTaskQuery()
            .taskId(taskId)
            .singleResult();
        approveRecordService.saveApproveRecords(task,operateResult,comment);
 
    }*/
}