#
Junjie
2025-04-21 edf5eb33c88d88062e295db466a654ac0a646ded
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
package com.zy.asrs.wcs.asrs.controller;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zy.asrs.framework.common.R;
import com.zy.asrs.wcs.asrs.entity.FlowGraph;
import com.zy.asrs.wcs.asrs.entity.param.FlowLogicCodeParam;
import com.zy.asrs.wcs.asrs.service.FlowGraphService;
import com.zy.asrs.wcs.asrs.execute.FlowExecute;
import com.zy.asrs.wcs.system.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
 
@RestController
@RequestMapping("/api")
public class FlowController extends BaseController {
 
    @Autowired
    private FlowGraphService flowGraphService;
    @Autowired
    private FlowExecute flowExecute;
 
    @PostMapping("/flow/analysisExportData")
    public R analysisExportData(@RequestBody HashMap<String, Object> param) {
        List<LinkedHashMap<String, Object>> data = (List<LinkedHashMap<String, Object>>) param.get("data");
 
        ArrayList<FlowLogicCodeParam> list = new ArrayList<>();
 
        FlowLogicCodeParam first = new FlowLogicCodeParam();
        first.setId("1");
        list.add(first);
        for (LinkedHashMap<String, Object> map : data) {
            LinkedHashMap<String, Object> mapData = (LinkedHashMap<String, Object>) map.get("data");
            String id = map.get("id").toString();
            Boolean isLogic = Boolean.parseBoolean(mapData.get("isLogic").toString());
            String searchLogicId = mapData.get("searchLogicId").toString();
            Boolean searchLogicBool = Boolean.parseBoolean(mapData.get("searchLogicBool").toString());
            String codeContent = mapData.get("codeContent") == null ? "" : mapData.get("codeContent").toString();
            if (isLogic) {
                FlowLogicCodeParam flowLogicCodeParam = new FlowLogicCodeParam();
                flowLogicCodeParam.setId(id);
                flowLogicCodeParam.setLogic(codeContent);
 
                FlowLogicCodeParam last = list.get(list.size() - 1);
                if (searchLogicBool) {
                    last.getLogicTrue().add(map);
                }else {
                    last.getLogicFalse().add(map);
                }
 
                list.add(flowLogicCodeParam);
            }else {
                for (FlowLogicCodeParam codeParam : list) {
                    if (codeParam.getId().equals(searchLogicId)) {
                        if (searchLogicBool) {
                            codeParam.getLogicTrue().add(map);
                        }else {
                            codeParam.getLogicFalse().add(map);
                        }
                    }
                }
            }
 
        }
 
        FlowGraph flowGraph = new FlowGraph();
        if (param.get("id") != null) {
            flowGraph.setId(Integer.parseInt(param.get("id").toString()));
        }else {
            flowGraph.setCreateTime(new Date());
            flowGraph.setStatus(0);
        }
        flowGraph.setName(param.get("name").toString());
        flowGraph.setMemo(param.get("memo") == null ? "" : param.get("memo").toString());
        flowGraph.setOriginData(param.get("originData").toString());
        flowGraph.setProcessData(JSON.toJSONString(param.get("data")));
        flowGraph.setUpdateTime(new Date());
        flowGraphService.saveOrUpdate(flowGraph);
 
        return R.ok();
    }
 
    @PostMapping("/flow/mockRun")
    public R mockRun(@RequestBody HashMap<String, Object> param) {
        FlowGraph flowGraph = flowGraphService.getById(param.get("id").toString());
        if (flowGraph == null) {
            return R.error("流程图不存在");
        }
 
        //开始模拟执行
        String processData = flowGraph.getProcessData();
//        List<FlowLogicCodeParam> list = JSON.parseArray(processData, FlowLogicCodeParam.class);
        List<JSONObject> list = JSON.parseArray(processData, JSONObject.class);
        boolean execute = flowExecute.execute(list);
        return R.ok().add(execute);
    }
 
}