自动化立体仓库 - WCS系统
zjj
2023-12-04 0ed06e0a0520d9493732910d9545b1adc1a6afb9
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
package com.zy.asrs.controller;
 
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.vo.PlcErrorTableVo;
import com.zy.asrs.domain.vo.SiteTableVo;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.utils.CommandUtils;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.OutputQueue;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.DevpSlave;
import com.zy.core.model.Task;
import com.zy.core.model.protocol.StaProtocol;
import com.zy.core.properties.SlaveProperties;
import com.zy.core.DevpThread;
import com.zy.core.thread.SiemensDevpThread;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
 
/**
 * 输送设备接口
 * Created by vincent on 2020-06-01
 */
@RestController
@RequestMapping("/site")
public class SiteController {
 
    @Autowired
    private SlaveProperties slaveProperties;
    @Autowired
    private BasDevpService basDevpService;
 
 
    @GetMapping("/io/mode/info/site")
    @ManagerAuth(memo = "入出库模式")
    public R ioMode(){
        List<Map<String, Object>> res = new ArrayList<>();
        for (DevpSlave devp : slaveProperties.getDevp()) {
            SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
            Map<String, Object> map2 = new HashMap<>();
            map2.put("floor", 2);
            map2.put("modeVal", devpThread.ioModeOf2F.id);
            map2.put("modeDesc", devpThread.ioModeOf2F.desc);
            res.add(map2);
        }
        return R.ok().add(res);
    }
 
    @PostMapping("/table/site")
    @ManagerAuth(memo = "站点信息表")
    public R siteTable(){
        List<SiteTableVo> list = new ArrayList<>();
        // 内存数据
        Map<Integer, StaProtocol> station = new HashMap<>();
        for (DevpSlave devp : slaveProperties.getDevp()) {
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
            station.putAll(devpThread.getStation());
        }
        // 持久数据
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<BasDevp>().orderBy("dev_no"));
        for (BasDevp devp : basDevps) {
            SiteTableVo vo = new SiteTableVo();
            vo.setDevNo(devp.getDevNo());    // 站点编号
            list.add(vo);
            StaProtocol staProtocol = station.get(devp.getDevNo());
            if (null == staProtocol) { continue; }
            vo.setWorkNo(staProtocol.getWorkNo());   //  工作号
            vo.setAutoing(staProtocol.isAutoing()?"Y":"N");     //  自动
            vo.setLoading(staProtocol.isLoading()?"Y":"N");     // 有物
            vo.setInEnable(staProtocol.isInEnable()?"Y":"N");   // 可入
            vo.setOutEnable(staProtocol.isOutEnable()?"Y":"N"); // 可出
            vo.setPakMk(staProtocol.isPakMk()?"Y":"N");       // 入库标记
            vo.setEmptyMk(staProtocol.isEmptyMk()?"Y":"N");     // 空板信号
            vo.setStaNo(staProtocol.getStaNo());                // 目标站
//            vo.setLocType1(staProtocol.isHigh() != staProtocol.isLow() && staProtocol.isLow() ? "低" : "高");     //高低库位
            vo.setLocType1(devp.getDevNo()==102 ? "高" : "低");
        }
        return R.ok().add(list);
    }
 
    @GetMapping("/list/auth")
    @ManagerAuth(memo = "站点信息表")
    public R crnList(){
        List<SiteTableVo> list = new ArrayList<>();
        // 内存数据
        Map<Integer, StaProtocol> station = new HashMap<>();
        for (DevpSlave devp : slaveProperties.getDevp()) {
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
            station.putAll(devpThread.getStation());
        }
        // 持久数据
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<BasDevp>().orderBy("dev_no"));
        for (BasDevp devp : basDevps) {
            SiteTableVo vo = new SiteTableVo();
            vo.setDevNo(devp.getDevNo());    // 站点编号
            list.add(vo);
            StaProtocol staProtocol = station.get(devp.getDevNo());
            if (null == staProtocol) { continue; }
            vo.setWorkNo(staProtocol.getWorkNo());   //  工作号
            vo.setAutoing(staProtocol.isAutoing()?"Y":"N");     //  自动
            vo.setLoading(staProtocol.isLoading()?"Y":"N");     // 有物
            vo.setInEnable(staProtocol.isInEnable()?"Y":"N");   // 可入
            vo.setOutEnable(staProtocol.isOutEnable()?"Y":"N"); // 可出
            vo.setPakMk(staProtocol.isPakMk()?"Y":"N");       // 入库标记
            vo.setEmptyMk(staProtocol.isEmptyMk()?"Y":"N");     // 空板信号
            vo.setStaNo(staProtocol.getStaNo());                // 目标站
//            vo.setLocType1(staProtocol.isHigh() != staProtocol.isLow() && staProtocol.isLow() ? "低" : "高");     //高低库位
            vo.setLocType1(devp.getDevNo()==102 ? "高" : "低");
        }
        return R.ok().add(list);
    }
 
    @PostMapping("/table/plc/errors")
    @ManagerAuth(memo = "输送设备plc异常信息表")
    public R plcErrorTable(){
        List<PlcErrorTableVo> list = new ArrayList<>();
        for (DevpSlave devp : slaveProperties.getDevp()) {
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
            Map<Integer, StaProtocol> station = devpThread.getStation();
 
            for(Map.Entry<Integer, StaProtocol> entry : station.entrySet()) {
                list = staPlcErr(entry);
            }
        }
        return R.ok().add(list);
    }
 
    @PostMapping("/output/site")
    @ManagerAuth(memo = "站点设备报文日志输出")
    public R siteOutput(){
        StringBuilder str = new StringBuilder();
        String s;
        int i = 0;
        while((s = OutputQueue.DEVP.poll()) != null && i <=10) {
            str.append("\n").append(s);
            i++;
        }
        return R.ok().add(str.toString());
    }
 
    /****************************************************************/
    /************************** 详情操作 ******************************/
    /****************************************************************/
 
    @GetMapping("/detl/{siteId}")
    public R siteDetl(@PathVariable("siteId") Integer siteId){
        SiteTableVo vo = new SiteTableVo();
        for (DevpSlave devp : slaveProperties.getDevp()) {
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
            Map<Integer, StaProtocol> station = devpThread.getStation();
            for (Map.Entry<Integer, StaProtocol> entry : station.entrySet()) {
                if (siteId.equals(entry.getKey())) {
                    StaProtocol staProtocol = entry.getValue();
                    vo.setDevNo(entry.getKey());    // 站点编号
                    vo.setWorkNo(staProtocol.getWorkNo());   //  工作号
                    vo.setAutoing(staProtocol.isAutoing()?"Y":"N");     //  自动
                    vo.setLoading(staProtocol.isLoading()?"Y":"N");     // 有物
                    vo.setInEnable(staProtocol.isInEnable()?"Y":"N");   // 可入
                    vo.setOutEnable(staProtocol.isOutEnable()?"Y":"N"); // 可出
                    vo.setPakMk(staProtocol.isPakMk()?"Y":"N");       // 需求1
                    vo.setEmptyMk(staProtocol.isEmptyMk()?"Y":"N");     // 空板信号
                    vo.setStaNo(staProtocol.getStaNo());                // 目标站
                    vo.setLocType1(staProtocol.isHigh() != staProtocol.isLow() && staProtocol.isLow() ? "低" : "高");     //高低库位
                    vo.setCar(staProtocol.isCar() ? "有": "无");
                    return R.ok().add(vo);
                }
            }
        }
        return R.error("plc已掉线");
    }
 
    @PostMapping("/detl/update")
    @ManagerAuth(memo = "修改站点数据")
    public R siteDetlUpdate(@RequestParam Integer devNo,
                            @RequestParam Short workNo,
                            @RequestParam Short staNo,
                            @RequestParam(required = false) String pakMk,
                            @RequestParam(required = false) Boolean inEnable,
                            @RequestParam(required = false) Boolean outEnable
    ) {
        BasDevp basDevp = basDevpService.selectById(devNo);
        if (basDevp == null) {
            return R.error("站点不存在");
        }
        for (DevpSlave devp : slaveProperties.getDevp()) {
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
            Map<Integer, StaProtocol> station = devpThread.getStation();
            for (Map.Entry<Integer, StaProtocol> entry : station.entrySet()) {
                if (devNo.equals(entry.getKey())) {
                    StaProtocol staProtocol = entry.getValue();
                    if (staProtocol == null) {
                        continue;
                    } else {
                        staProtocol = staProtocol.clone();
                    }
                    if (workNo != null) {
                        staProtocol.setWorkNo(workNo);
                    }
                    if (staNo != null) {
                        staProtocol.setStaNo(staNo);
                    }
                    if (pakMk != null) {
                        staProtocol.setPakMk(pakMk.equals("Y"));
                    }
                    if (inEnable != null) {
                        staProtocol.setInEnable(inEnable);
                        basDevp.setInEnable(inEnable ? "Y" : "N");
                    }
                    if (outEnable != null) {
                        staProtocol.setOutEnable(outEnable);
                        basDevp.setOutEnable(outEnable ? "Y" : "N");
                    }
                    basDevpService.updateById(basDevp);
                    boolean result = CommandUtils.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol), false);
                    if (result) {
                        return R.ok();
                    } else {
                        return R.error("下发命令失败");
                    }
                }
            }
        }
        return R.error("更新失败");
    }
 
    public List<PlcErrorTableVo> staPlcErr(Map.Entry<Integer, StaProtocol> entry){
        List<PlcErrorTableVo> list = new ArrayList<>();
        StaProtocol staProtocol = entry.getValue();
        if (staProtocol.getBreakerErr()){
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
            vo.setPlcDesc("断路器故障");
            vo.setError("断路器故障");
            list.add(vo);
        }
        if (staProtocol.getInfraredErr()){
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
            vo.setPlcDesc("光电异常");
            vo.setError("光电异常");
            list.add(vo);
        }
        if (staProtocol.getOutTimeErr()){
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
 
            vo.setPlcDesc("运行超时");
            vo.setError("运行超时");
            list.add(vo);
        }
        if (staProtocol.getSeizeSeatErr()){
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
 
            vo.setPlcDesc("占位超时");
            vo.setError("占位超时");
            list.add(vo);
        }
        if (staProtocol.getWrkYgoodsN()){
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
 
            vo.setPlcDesc("有任务无货故障");
            vo.setError("有任务无货故障");
            list.add(vo);
        }
        if (staProtocol.getInverterErr()){
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
 
            vo.setPlcDesc("变频器故障");
            vo.setError("变频器故障");
            list.add(vo);
        }
        if (staProtocol.getContactErr()){
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
 
            vo.setPlcDesc("电机接触器故障");
            vo.setError("电机接触器故障");
            list.add(vo);
        }
        if (staProtocol.getUpcontactErr()){
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
 
            vo.setPlcDesc("顶升电机接触器故障");
            vo.setError("顶升电机接触器故障");
            list.add(vo);
        }
        if (staProtocol.isFrontErr()){
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
            vo.setPlcDesc("前超限");
            vo.setError("前超限");
            list.add(vo);
        }
        if (staProtocol.isBackErr()){
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
            vo.setPlcDesc("后超限");
            vo.setError("后超限");
            list.add(vo);
        }
        if (staProtocol.isHighErr()){
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
            vo.setPlcDesc("高超限");
            vo.setError("高超限");
            list.add(vo);
        }
        if (staProtocol.isLeftErr()){
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
            vo.setPlcDesc("左超限");
            vo.setError("左超限");
            list.add(vo);
        }
        if (staProtocol.isRightErr()){
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
            vo.setPlcDesc("右超限");
            vo.setError("右超限");
            list.add(vo);
        }
        if (staProtocol.isBarcodeErr()){
            PlcErrorTableVo vo = new PlcErrorTableVo();
            vo.setNo(entry.getKey());   //  序号
            vo.setPlcDesc("扫码失败");
            vo.setError("扫码失败");
            list.add(vo);
        }
 
 
        return list;
    }
 
}