刘光辉
117 分钟以前 06f314545ac3514d7ce28939920866ae8188d31c
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
package jnpf.flowable.controller;
 
import jnpf.base.ActionResult;
import jnpf.flowable.entity.TaskEntity;
import jnpf.flowable.enums.EventEnum;
import jnpf.flowable.enums.TaskStatusEnum;
import jnpf.flowable.model.task.AuditModel;
import jnpf.flowable.model.task.FlowModel;
import jnpf.flowable.model.task.TaskTo;
import jnpf.flowable.service.TaskService;
import jnpf.flowable.util.OperatorUtil;
import jnpf.flowable.TaskApi;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
 
 
/**
 * 类的描述
 *
 * @author JNPF@YinMai Info. Co., Ltd
 * @version 5.0.x
 * @since 2024/5/28 14:32
 */
@RestController
@RequestMapping("/task")
@RequiredArgsConstructor
public class TaskForFileController implements TaskApi {
 
    private final TaskService taskService;
 
    private final  OperatorUtil operatorUtil;
 
    @Override
    @PostMapping("/saveDraft")
    public ActionResult<AuditModel> saveDraft(@RequestBody FlowModel flowModel) {
        try {
            flowModel.setServerAutoDraft(true);
            taskService.batchSaveOrSubmit(flowModel);
            operatorUtil.handleOperator();
            if (TaskStatusEnum.RUNNING.getCode().equals(flowModel.getStatus())) {
                operatorUtil.handleTaskStatusThenEvent(flowModel, EventEnum.INIT.getStatus());
            }
            TaskEntity taskEntity = flowModel.getTaskEntity();
            if (taskEntity.getRejectDataId() == null) {
                operatorUtil.autoAudit(flowModel);
                operatorUtil.launchTrigger(flowModel);
                operatorUtil.handleOperator();
                operatorUtil.handleTaskStatusThenEvent();
            } else {
                operatorUtil.handleTaskStatus();
            }
            TaskEntity savedTask = taskService.getById(taskEntity.getId());
            AuditModel model = operatorUtil.getAuditModel(
                    savedTask == null ? taskEntity.getId() : savedTask.getId(), flowModel, null);
            return ActionResult.success(model);
        } catch (Exception exception) {
            return ActionResult.fail(exception.getMessage());
        }
    }
 
    @Override
    @PostMapping("/launchFlow")
    public ActionResult launchFlow(@RequestBody FlowModel flowModel) {
        try {
            return operatorUtil.launchFlow(flowModel);
        } catch (Exception e) {
            e.printStackTrace();
            return ActionResult.fail(e.getMessage());
        }
    }
 
    @Override
    @PostMapping("/getFlowTodoCount")
    public TaskTo getFlowTodoCount(@RequestBody TaskTo taskTo) {
        return taskService.getFlowTodoCount(taskTo);
    }
 
}