#
Junjie
2024-10-17 d835d1b51f832889929cdf69010034a30ef44d02
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
package com.zy.asrs.wcs.asrs.execute;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.zy.asrs.framework.common.Cools;
import com.zy.asrs.wcs.core.entity.Motion;
import com.zy.asrs.wcs.core.entity.Task;
import com.zy.asrs.wcs.core.service.TaskService;
import com.zy.asrs.wcs.core.utils.RedisUtil;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.ArrayList;
import java.util.List;
 
@Component
public class FlowExecute extends BaseExecute {
 
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private TaskService taskService;
    @Autowired
    private ShuttleExecute shuttleExecute;
    @Autowired
    private LiftExecute liftExecute;
    @Autowired
    private DevpExecute devpExecute;
 
    //执行流程图
    public boolean execute(List<JSONObject> list) {
        String currentId = list.get(0).getString("id");
 
        JSONObject devpType = list.get(0).getJSONObject("data").getJSONObject("devpType");
        String staNo = devpType.getString("staNo");
        //搜索工作档
        List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>()
                .eq(Task::getOriginSite, staNo)
                .eq(Task::getStatus, 1));
 
        for (Task task : tasks) {
            String redisKey = DigestUtils.md5Hex(JSON.toJSONString(list));
 
            redisSet(redisKey, "motionList", new ArrayList<Motion>());
            while (currentId != null) {
                //获取流程图
                JSONObject flow = findFLow(list, currentId);
                if (flow == null) {
                    break;
                }
 
                //执行
                boolean result = executeFlow(task, flow, redisKey);
 
                //执行后续流程
                if (Cools.isEmpty(flow.get("nextTrue")) && Cools.isEmpty(flow.get("nextFalse"))) {
                    break;//无后续流程
                }
 
                //更新id
                currentId = result ? flow.getString("nextTrue") : flow.getString("nextFalse");
            }
 
            System.out.println("执行完成");
            redisUtil.del(redisKey);//释放缓存
        }
        return true;
    }
 
    private boolean executeFlow(Task task, JSONObject flow, String redisKey) {
        System.out.println(flow.getString("id") + "被执行");
        JSONObject data = flow.getJSONObject("data");
        String type = data.getString("type");
        boolean result = false;
        if (type.equals("devp")) {
            result = devpExecute.execute(task, data, redisKey);
        } else if (type.equals("shuttle")) {
            result = shuttleExecute.execute(task, data, redisKey);
        } else if (type.equals("lift")) {
            result = liftExecute.execute(task, data, redisKey);
        }
        return result;
    }
 
 
//    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;
//    }
 
}