#
Junjie
昨天 253e9b3735533c4d8c69cf5e6983d5fa1e984ae9
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
package com.zy.asrs.controller;
 
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.R;
import com.zy.asrs.domain.ShuttleGatherResult;
import com.zy.asrs.domain.enums.NotifyMsgType;
import com.zy.asrs.domain.param.*;
import com.zy.asrs.entity.ApiLog;
import com.zy.asrs.entity.DeviceConfig;
import com.zy.asrs.entity.LocMast;
import com.zy.asrs.entity.WrkMast;
import com.zy.asrs.service.ApiLogService;
import com.zy.asrs.service.DeviceConfigService;
import com.zy.asrs.service.LocMastService;
import com.zy.asrs.service.WrkMastService;
import com.zy.asrs.utils.NotifyUtils;
import com.zy.common.annotations.OpenApiLog;
import com.zy.common.service.CommonService;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.dispatcher.ShuttleDispatchUtils;
import com.zy.core.enums.SlaveType;
import com.zy.core.enums.WrkIoType;
import com.zy.core.model.protocol.ForkLiftProtocol;
import com.zy.core.model.protocol.LiftProtocol;
import com.zy.core.model.protocol.ShuttleProtocol;
import com.zy.core.thread.ForkLiftThread;
import com.zy.core.thread.LiftThread;
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 java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
 
@Slf4j
@RestController
@RequestMapping("/openapi")
public class OpenController {
 
    @Autowired
    private CommonService commonService;
    @Autowired
    private ShuttleDispatchUtils shuttleDispatchUtils;
    @Autowired
    private NotifyUtils notifyUtils;
    @Autowired
    private ApiLogService apiLogService;
    @Autowired
    private LocMastService locMastService;
    @Autowired
    private WrkMastService wrkMastService;
    @Autowired
    private DeviceConfigService deviceConfigService;
 
    @PostMapping("/createMoveTask")
    @OpenApiLog(memo = "小车移动任务")
    public R createMoveTask(@RequestBody CreateMoveTaskParam param) {
        if (param == null) {
            return R.error("参数不能为空");
        }
        boolean dispatchShuttle = shuttleDispatchUtils.dispatchShuttle(null, param.getLocNo(), param.getShuttleNo());
        if (dispatchShuttle) {
            return R.ok();
        }
        return R.error("生成失败");
    }
 
    //移库任务
    @PostMapping("/createLocMoveTask")
    @OpenApiLog(memo = "移库任务")
    public R createLocMoveTask(@RequestBody CreateLocMoveTaskParam param) {
        if (param == null) {
            return R.error("参数不能为空");
        }
        boolean result = commonService.createLocMoveTask(param);
        if (result) {
            return R.ok();
        }
        return R.error("生成移库任务失败");
    }
 
    //入库任务
    @PostMapping("/createInTask")
    @OpenApiLog(memo = "入库任务")
    public synchronized R createInTask(@RequestBody CreateInTaskParam param) {
        if (param == null) {
            return R.error("参数不能为空");
        }
        boolean result = commonService.createInTask(param);
        if (result) {
            return R.ok();
        }
        return R.error("生成入库任务失败");
    }
 
    //出库任务
    @PostMapping("/createOutTask")
    @OpenApiLog(memo = "出库任务")
    public synchronized R createOutTask(@RequestBody CreateOutTaskParam param) {
        if (param == null) {
            return R.error("参数不能为空");
        }
        boolean result = commonService.createOutTask(param);
        if (result) {
            return R.ok();
        }
        return R.error("生成出库任务失败");
    }
 
    @PostMapping("/completeTask")
    @OpenApiLog(memo = "任务完成")
    public R completeTask(@RequestBody CompleteTaskParam param) {
        if (param == null) {
            return R.error("参数不能为空");
        }
        boolean completeTask = commonService.completeTask(param);
        if (completeTask) {
            return R.ok();
        }
        return R.error("任务完成失败");
    }
 
    @PostMapping("/cancelTask")
    @OpenApiLog(memo = "任务取消")
    public R cancelTask(@RequestBody CancelTaskParam param) {
        if (param == null) {
            return R.error("参数不能为空");
        }
        boolean completeTask = commonService.cancelTask(param);
        if (completeTask) {
            return R.ok();
        }
        return R.error("任务取消失败");
    }
 
    @RequestMapping("/deviceStatus")
//    @OpenApiLog(memo = "获取设备状态")
    public R getDeviceStatus() {
        HashMap<String, Object> map = new HashMap<>();
        //获取小车数据
        ArrayList<ShuttleProtocol> shuttleProtocols = new ArrayList<>();
        List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                .eq("device_type", String.valueOf(SlaveType.Shuttle)));
        for (DeviceConfig device : shuttleList) {
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo());
            if (shuttleThread == null) {
                continue;
            }
 
            ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
            if (shuttleProtocol == null) {
                continue;
            }
            shuttleProtocols.add(shuttleProtocol);
        }
 
        //获取货叉提升机数据
        ArrayList<ForkLiftProtocol> forkLiftProtocols = new ArrayList<>();
        List<DeviceConfig> forkLiftList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                .eq("device_type", String.valueOf(SlaveType.ForkLift)));
        for (DeviceConfig device : forkLiftList) {
            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, device.getDeviceNo());
            if (forkLiftThread == null) {
                continue;
            }
 
            ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus();
            if (forkLiftProtocol == null) {
                continue;
            }
            forkLiftProtocols.add(forkLiftProtocol);
        }
 
        //获取提升机数据
        ArrayList<LiftProtocol> liftProtocols = new ArrayList<>();
        List<DeviceConfig> liftList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                .eq("device_type", String.valueOf(SlaveType.Lift)));
        for (DeviceConfig device : liftList) {
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, device.getDeviceNo());
            if (liftThread == null) {
                continue;
            }
 
            LiftProtocol liftProtocol = liftThread.getStatus();
            if (liftProtocol == null) {
                continue;
            }
            liftProtocols.add(liftProtocol);
        }
 
        map.put("shuttle", shuttleProtocols);
        map.put("forkLift", forkLiftProtocols);
        map.put("lift", liftProtocols);
 
        return R.ok().add(map);
    }
 
    @RequestMapping("/liftDeviceOriginData")
    public R getLiftDeviceOriginData() {
        HashMap<Integer, String> map = new HashMap<>();
 
        //获取提升机数据
        List<DeviceConfig> liftList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                .eq("device_type", String.valueOf(SlaveType.Lift)));
        for (DeviceConfig device : liftList) {
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, device.getDeviceNo());
            if (liftThread == null) {
                continue;
            }
 
            map.put(device.getDeviceNo(), liftThread.getRealtimeOriginData());
        }
 
        return R.ok().add(map);
    }
 
    @PostMapping("/getLocInformation")
    @OpenApiLog(memo = "获取指定库位信息")
    public R getLocInformation(@RequestBody GetLocInformationParam param) {
        if (param == null) {
            return R.error("参数不能为空");
        }
        LocMast locMast = locMastService.queryByLoc(param.getLocNo());
        if (locMast == null) {
            return R.error("库位信息不存在");
        }
 
        HashMap<String, Object> map = new HashMap<>();
        map.put("locNo", locMast.getLocNo());
        map.put("locSts", locMast.getLocSts());
 
        return R.ok().add(map);
    }
 
    @PostMapping("/getAllLocInformation")
    @OpenApiLog(memo = "获取全部库位信息")
    public R getAllLocInformation() {
        List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>());
        if (locMasts.isEmpty()) {
            return R.error("库位信息不存在");
        }
 
        ArrayList<HashMap<String, Object>> list = new ArrayList<>();
        for (LocMast locMast : locMasts) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("locNo", locMast.getLocNo());
            map.put("locSts", locMast.getLocSts());
            list.add(map);
        }
 
        return R.ok().add(list);
    }
 
    @PostMapping("/shuttleGather")
    @OpenApiLog(memo = "小车集合")
    public R shuttleGather(@RequestBody ShuttleGatherParam param) {
        List<ShuttleGatherResult> shuttleGather = shuttleDispatchUtils.shuttleGather(param);
        return R.ok().add(shuttleGather);
    }
 
    @PostMapping("/shuttleDemo")
    @OpenApiLog(memo = "小车演示")
    public R shuttleDemo(@RequestBody ShuttleDemoParam param) {
        shuttleDispatchUtils.shuttleDemo(param);
        return R.ok();
    }
 
    @PostMapping("/queryTask")
    @OpenApiLog(memo = "查询任务")
    public R queryTask(@RequestBody QueryTaskParam param) {
        EntityWrapper<WrkMast> wrapper = new EntityWrapper<>();
        if(param.getTaskNo() != null) {
            wrapper.eq("wms_wrk_no", param.getTaskNo());
        }
 
        if(param.getTaskType() != null) {
            WrkIoType ioType = WrkIoType.get(param.getTaskType());
            if(ioType == null) {
                return R.error("任务类型不存在");
            }
            wrapper.eq("io_type", ioType.id);
        }
        List<WrkMast> wrkMasts = wrkMastService.selectList(wrapper);
        return R.ok().add(wrkMasts);
    }
 
    @GetMapping("/systemStatus")
    public R systemStatus() {
        return R.ok();
    }
 
    @GetMapping("/test")
    public R test() {
        notifyUtils.notify("task", 1, "9999", "W9999", NotifyMsgType.SHUTTLE_MOVING, "data");
        notifyUtils.notify(String.valueOf(SlaveType.Shuttle), 2, "9999", "W9999", NotifyMsgType.SHUTTLE_MOVE_COMPLETE);
        return R.ok();
    }
 
}