#
qlsxk
2 天以前 ab0db76dc627a63699380dc65e2773c47d12f449
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
package com.zy.asrs.controller;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.annotations.ManagerAuth;
import com.core.common.Cools;
import com.core.common.R;
import com.zy.asrs.domain.param.SystemSwitchParam;
import com.zy.asrs.entity.BasMap;
import com.zy.asrs.entity.DeviceConfig;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.service.BasMapService;
import com.zy.asrs.service.DeviceConfigService;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.utils.Utils;
import com.zy.common.model.MapNode;
import com.zy.common.model.NavigateNode;
import com.zy.common.model.enums.NavigationMapType;
import com.zy.common.utils.NavigateMapData;
import com.zy.common.utils.RedisUtil;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.RedisKeyType;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.command.ShuttleRedisCommand;
import com.zy.core.model.protocol.ShuttleProtocol;
import com.zy.core.properties.SystemProperties;
import com.zy.core.thread.ShuttleThread;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import java.util.*;
 
/**
 * 主控图接口
 * Created by vincent on 2020-06-01
 */
@Slf4j
@RestController
@RequestMapping("/console")
public class ConsoleController {
 
    @Autowired
    private BasMapService basMapService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private NavigateMapData navigateMapData;
    @Autowired
    private LocMastService locMastService;
    @Autowired
    private DeviceConfigService deviceConfigService;
 
    @PostMapping("/system/running/status")
    @ManagerAuth(memo = "系统运行状态")
    public R systemRunningStatus(){
        return R.ok().add(Cools.add("status", SystemProperties.WCS_RUNNING_STATUS.get()));
    }
 
    @PostMapping("/system/switch")
    @ManagerAuth(memo = "系统运行开关操作")
    public R systemSwitch(SystemSwitchParam param) throws InterruptedException {
        if (Cools.isEmpty(param.getOperatorType())){
            return R.error();
        }
        if (param.getOperatorType() == 0) {
            if (Cools.isEmpty(param.getPassword())){
                return R.error("请输入口令");
            }
            if (!param.getPassword().equals(SystemProperties.WCS_PASSWORD)){
                return R.error("口令错误");
            }
        }
        Thread.sleep(200L);
        SystemProperties.WCS_RUNNING_STATUS.set(param.getOperatorType()==1?Boolean.TRUE:Boolean.FALSE);
        return R.ok().add(Cools.add("status", SystemProperties.WCS_RUNNING_STATUS.get()));
    }
 
    /**
     * 获取地图楼层数据
     */
    @GetMapping("/map/lev/list")
    @ManagerAuth
    public R getMapLevList() {
        List<BasMap> basMaps = basMapService.selectList(new EntityWrapper<BasMap>().orderBy("lev", true));
        ArrayList<Integer> levList = new ArrayList<>();
        for (BasMap basMap : basMaps) {
            levList.add(basMap.getLev());
        }
        return R.ok().add(levList);
    }
 
    /**
     * 获取地图数据
     */
    @GetMapping("/map/{lev}/auth")
    @ManagerAuth
    public R getMapFromRedis(@PathVariable Integer lev) {
        Object data = redisUtil.get(RedisKeyType.MAP.key + lev);
        if (data == null) {
            return R.error();
        }
 
        List<List<MapNode>> arrayList = (List<List<MapNode>>) data;
        List<List<MapNode>> lists = navigateMapData.filterMap(NavigationMapType.getMapTypes(NavigationMapType.NONE, NavigationMapType.PATH_LOCK), arrayList, lev, null, null);//过滤地图数据
        return R.ok().add(lists);
    }
 
    /**
     * 获取库位地图数据
     */
    @GetMapping("/locMap/{lev}/auth")
    @ManagerAuth
    public R getLocMap(@PathVariable Integer lev) {
        Object data = redisUtil.get(RedisKeyType.MAP.key + lev);
        if (data == null) {
            return R.error();
        }
 
        List<List<MapNode>> arrayList = (List<List<MapNode>>) data;
        List<List<MapNode>> lists = navigateMapData.filterMap(NavigationMapType.getMapTypes(NavigationMapType.NONE), arrayList, lev, null, null);//过滤地图数据
 
        //获取当前楼层库位数据
        List<LocMast> locMasts = locMastService.selectLocByLev(lev);
        for (LocMast locMast : locMasts) {
            Integer row = locMast.getRow1();
            Integer bay = locMast.getBay1();
 
            List<MapNode> list = lists.get(row);
            MapNode mapNode = list.get(bay);
 
            mapNode.setLocSts(locMast.getLocSts());
            mapNode.setLocNo(locMast.getLocNo());
 
            //更新list
            list.set(bay, mapNode);
            lists.set(row, list);
        }
        return R.ok().add(lists);
    }
 
    /**
     * 重置redis中的地图,将占用的库位全部解除
     */
    @GetMapping("/map/resetMap/auth")
    @ManagerAuth
    public R resetMapToRedis() {
        List<BasMap> basMaps = basMapService.selectList(new EntityWrapper<BasMap>().orderBy("lev", true));
        for (BasMap basMap : basMaps) {
            Integer lev = basMap.getLev();
            redisUtil.del(RedisKeyType.MAP.key + lev);
        }
        return R.ok();
    }
 
    /**
     * 重置redis中的地图,将占用的库位全部解除
     */
    @GetMapping("/map/resetMap/{lev}")
    @ManagerAuth(memo = "重置Redis地图")
    public R resetMapToRedisByLev(@PathVariable Integer lev, HttpServletRequest request) {
        redisUtil.del(RedisKeyType.MAP.key + lev);
        return R.ok();
    }
 
    /**
     * 获取预计路径
     */
    @GetMapping("/getMoveAdvancePath/{lev}/auth")
    @ManagerAuth
    public R getMoveAdvancePath(@PathVariable Integer lev) {
        HashMap<String, Object> pathMap = new HashMap<>();
 
        List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                .eq("device_type", String.valueOf(SlaveType.Shuttle)));
        for (DeviceConfig deviceConfig : shuttleList) {
            // 获取四向穿梭车信息
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, deviceConfig.getDeviceNo());
            if (shuttleThread == null) {
                continue;
            }
            ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
            if (shuttleProtocol == null || shuttleProtocol.getShuttleNo()==null) {
                continue;
            }
 
            if (shuttleProtocol.getCurrentLocNo() == null) {
                continue;
            }
 
            if (Utils.getLev(shuttleProtocol.getCurrentLocNo()) != lev) {
                continue;
            }
 
            if (shuttleProtocol.getTaskNo() == 0) {
 
            }
 
            //存在任务,获取指令
            Object object = redisUtil.get(RedisKeyType.SHUTTLE_WORK_FLAG.key + shuttleProtocol.getTaskNo());
            if (object != null) {
                ShuttleRedisCommand redisCommand = JSON.parseObject(object.toString(), ShuttleRedisCommand.class);
                List<NavigateNode> nodes = redisCommand.getAssignCommand().getNodes();//穿梭车预计路径
 
                for (NavigateNode node : nodes) {
                    String locNo = Utils.getLocNo(node.getX(), node.getY(), node.getZ());
 
                    List<Integer> shuttleNoList = new ArrayList<>();
                    Object tmp = pathMap.get(locNo);
                    if(tmp != null) {
                        shuttleNoList = (List<Integer>) tmp;
                    }
 
                    if (!shuttleNoList.contains(shuttleProtocol.getShuttleNo())) {
                        shuttleNoList.add(shuttleProtocol.getShuttleNo());
                    }
 
                    pathMap.put(locNo, shuttleNoList);
                }
            }
        }
 
        List<HashMap<String, Object>> pathList = new ArrayList<>();
        for (Map.Entry<String, Object> entry : pathMap.entrySet()) {
            String locNo = entry.getKey();
            Object shuttleNoList = entry.getValue();
 
            HashMap<String, Object> map = new HashMap<>();
            map.put("locNo", locNo);
            map.put("x", Utils.getRow(locNo));
            map.put("y", Utils.getBay(locNo));
            map.put("z", Utils.getLev(locNo));
            map.put("shuttleNoList", shuttleNoList);
            pathList.add(map);
        }
        return R.ok().add(pathList);
    }
 
    /**
     * 获取锁定路径
     */
    @GetMapping("/getLockPath/{lev}/auth")
    @ManagerAuth
    public R getLockPath(@PathVariable Integer lev) {
        HashMap<String, Object> lockMap = new HashMap<>();
        Object o = redisUtil.get(RedisKeyType.LOCK_MAP_NODES.key + lev);
        if (o != null) {
            lockMap = (HashMap<String, Object>) o;
        }
 
        List<HashMap<String, Object>> lockList = new ArrayList<>();
        for (Map.Entry<String, Object> entry : lockMap.entrySet()) {
            String locNo = entry.getKey();
            Object shuttleNo = entry.getValue();
 
            HashMap<String, Object> map = new HashMap<>();
            map.put("locNo", locNo);
            map.put("x", Utils.getRow(locNo));
            map.put("y", Utils.getBay(locNo));
            map.put("z", Utils.getLev(locNo));
            map.put("shuttleNo", shuttleNo);
            lockList.add(map);
        }
        return R.ok().add(lockList);
    }
 
}