刘光辉
昨天 bb638871a7fb692d80f1b7a758f991dc0879002c
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
package jnpf.limsController;
 
import cn.dev33.satoken.annotation.SaCheckLogin;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jnpf.exception.DataException;
import jnpf.flowable.WorkFlowApi;
import jnpf.flowable.entity.TaskEntity;
import jnpf.limsEntity.LimsSxtFlowEventParam;
import jnpf.limsService.LimsSxtJihuaService;
import jnpf.util.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
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;
 
/**
 * 工作流节点事件接口。站内数据接口会透传流程操作者令牌,故不允许匿名调用。
 */
@Slf4j
@Tag(name = "水系统计划流程事件", description = "")
@RestController
@SaCheckLogin
@RequestMapping("/lims/biz/sxt/flow-status")
public class LimsSxtFlowStatusController {
 
    @Autowired
    private LimsSxtJihuaService jihuaService;
    @Autowired
    private WorkFlowApi workFlowApi;
 
    @Operation(summary = "水系统计划流程发起事件")
    @PostMapping("/start")
    public R<Object> syncFlowStarted(@RequestBody LimsSxtFlowEventParam param) {
        String validationMessage = validateFlowEventParam(param);
        if (validationMessage != null) {
            return R.error(validationMessage);
        }
        try {
            jihuaService.syncFlowStarted(param.getFlowId(), param.getTaskId());
            return R.success();
        } catch (DataException e) {
            log.warn("水系统流程发起状态同步失败,flowId={}, taskId={}", param.getFlowId(), param.getTaskId(), e);
            return R.error(e.getMessage());
        }
    }
 
    @Operation(summary = "水系统计划流程结束事件")
    @PostMapping("/end")
    public R<Object> syncFlowEnded(@RequestBody LimsSxtFlowEventParam param) {
        String validationMessage = validateFlowEventParam(param);
        if (validationMessage != null) {
            return R.error(validationMessage);
        }
        TaskEntity task = workFlowApi.getInfoSubmit(param.getTaskId());
        if (task == null) {
            return R.error("未找到流程任务:" + param.getTaskId());
        }
        if (!param.getTaskId().equals(task.getId())) {
            return R.error("流程任务与传入任务ID不匹配");
        }
        try {
            jihuaService.syncFlowEnded(param.getFlowId(), param.getTaskId(), task.getStatus());
            return R.success();
        } catch (DataException e) {
            log.warn("水系统流程结束状态同步失败,flowId={}, taskId={}, status={}",
                    param.getFlowId(), param.getTaskId(), task.getStatus(), e);
            return R.error(e.getMessage());
        }
    }
 
    private String validateFlowEventParam(LimsSxtFlowEventParam param) {
        if (param == null) {
            return "请求参数不能为空";
        }
        if (!StringUtils.hasText(param.getFlowId())) {
            return "流程id(flow_id)不能为空";
        }
        if (!StringUtils.hasText(param.getTaskId())) {
            return "流程任务id(task_id)不能为空";
        }
        return null;
    }
}