luxiaotao1123
2024-04-17 06a9757c727c6bc15595d5f56a0e309077025741
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
package com.zy.asrs.wcs.rcs.thread;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zy.asrs.framework.common.Cools;
import com.zy.asrs.wcs.asrs.entity.param.FlowLogicCodeParam;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.codec.digest.Md5Crypt;
import org.springframework.stereotype.Component;
 
import java.util.List;
import java.util.Map;
 
@Component
public class FlowExecute {
 
    //执行流程图
    public boolean execute(List<JSONObject> list) {
        String currentId = list.get(0).getString("id");
 
        String listId = DigestUtils.md5Hex(JSON.toJSONString(list));
 
        while (currentId != null) {
            //获取流程图
            JSONObject flow = findFLow(list, currentId);
            if (flow == null) {
                break;
            }
 
            //执行
            boolean result = executeFlow(flow, listId);
 
            //执行后续流程
            if (Cools.isEmpty(flow.get("nextTrue")) && Cools.isEmpty(flow.get("nextFalse"))) {
                break;//无后续流程
            }
 
            //更新id
            currentId = result ? flow.getString("nextTrue") : flow.getString("nextFalse");
        }
 
        System.out.println("执行完成");
        return true;
    }
 
    private boolean executeFlow(JSONObject flow, String listId) {
        System.out.println(flow.getString("id") + "被执行");
        String type = flow.getString("type");
        if (type.equals("devp")) {
 
        } else if (type.equals("shuttle")) {
 
        }
        return true;
    }
 
    private JSONObject findFLow(List<JSONObject> list, String id) {
        for (JSONObject flow : list) {
            if (flow.getString("id").equals(id)) {
                return flow;
            }
        }
        return null;
    }
 
//    private boolean executeFlow(List<Map<String, Object>> list) {
//        for (Map<String, Object> map : list) {
//            JSONObject data = (JSONObject) map.get("data");
//            if (data.getString("type").equals("devp")) {
//                JSONObject devp = data.getJSONObject("devpType");
//                String devpNo = devp.getString("devpNo");//输送线PLC
//                String staNo = devp.getString("staNo");//站号
//                Boolean enableStaStatus = devp.getBoolean("enableStaStatus");//判断站点状态
//                JSONArray staStatus = devp.getJSONArray("staStatus");//站点状态列表
//                String staJudgementFailExecute = devp.getString("staJudgementFailExecute");//判断失败后是否继续执行流程
//                Boolean writeWorkNoStatus = devp.getBoolean("writeWorkNoStatus");//是否写入工作号
//                Boolean writeStaNoStatus = devp.getBoolean("writeStaNoStatus");//是否写入目标站
//                String writeWorkNo = devp.getString("writeWorkNo");//写入工作号数据
//                String writeStaNo = devp.getString("writeStaNo");//写入目标站数据
//                if (enableStaStatus) {
//                    //判断站点状态
//                    boolean statusFlag = true;//默认判断通过
//                    for (Object status : staStatus) {
//                        System.out.println(status);
//                    }
//
//                    if (!statusFlag) {
//                        //判断不通过
//                        if (staJudgementFailExecute.equals("stop")) {
//                            //判断失败后不继续执行
//                            return false;
//                        }
//                    }
//
//                }
//
//                if (writeWorkNoStatus) {
//                    //写入工作号
//                }
//
//                if (writeStaNoStatus) {
//                    //写入目标站
//                }
//                System.out.println(devp);
//            }
//            System.out.println(data);
//        }
//
//        System.out.println(list);
//        return false;
//    }
 
}