#
Junjie
2 天以前 379f39703eff09d5cf083a9267971ecbb7726f05
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
package com.zy.core.plugin;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zy.asrs.domain.param.CreateInTaskParam;
import com.zy.asrs.domain.param.CreateOutTaskParam;
import com.zy.asrs.entity.*;
import com.zy.asrs.service.*;
import com.zy.asrs.utils.Utils;
import com.zy.common.model.StartupDto;
import com.zy.common.service.CommonService;
import com.zy.common.utils.HttpHandler;
import com.zy.common.utils.RedisUtil;
import com.zy.core.News;
import com.zy.core.cache.MessageQueue;
import com.zy.core.cache.SlaveConnection;
import com.zy.core.enums.*;
import com.zy.core.model.StationObjModel;
import com.zy.core.model.Task;
import com.zy.core.model.command.CrnCommand;
import com.zy.core.model.command.StationCommand;
import com.zy.core.model.protocol.CrnProtocol;
import com.zy.core.model.protocol.StationProtocol;
import com.zy.core.thread.CrnThread;
import com.zy.core.thread.StationThread;
import com.zy.core.utils.CrnOperateProcessUtils;
import com.zy.core.utils.StationOperateProcessUtils;
import com.zy.system.entity.Config;
import com.zy.system.service.ConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.*;
 
@Slf4j
@Component
public class FakeProcess implements MainProcessPluginApi {
 
    private static Map<Integer,Long> stationStayTimeMap = new HashMap<>();
    private static String enableFake = "N";
    private static String fakeRealTaskRequestWms = "N";
 
    @Autowired
    private WrkMastService wrkMastService;
    @Autowired
    private BasDevpService basDevpService;
    @Autowired
    private ConfigService configService;
    @Autowired
    private LocMastService locMastService;
    @Autowired
    private CommonService commonService;
    @Autowired
    private BasCrnpService basCrnpService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private CrnOperateProcessUtils crnOperateUtils;
    @Autowired
    private StationOperateProcessUtils stationOperateProcessUtils;
    @Autowired
    private HttpRequestLogService httpRequestLogService;
 
    @Override
    public void run() {
        Config enableFakeConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "enableFake"));
        if (enableFakeConfig != null) {
            enableFake = enableFakeConfig.getValue();
        }
 
        Config fakeRealTaskRequestWmsConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "fakeRealTaskRequestWms"));
        if (fakeRealTaskRequestWmsConfig != null) {
            fakeRealTaskRequestWms = fakeRealTaskRequestWmsConfig.getValue();
        }
 
        //检测入库站是否有任务生成,并仿真生成模拟入库站点数据
        checkInStationHasTask();
        //生成仿真模拟入库任务
        generateFakeInTask();
        //生成仿真模拟出库任务
        generateFakeOutTask();
        //计算所有站点停留时间
        calcAllStationStayTime();
        //检测出库站点停留是否超时
        checkOutStationStayTimeOut();
        //检测入库站点堆垛机是否取走货物
        checkInStationCrnTake();
 
        //请求生成入库任务
        generateStoreWrkFile();
        //执行堆垛机任务
        crnOperateUtils.crnIoExecute();
        //堆垛机任务执行完成-具备仿真能力
        crnIoExecuteFinish();
        //执行输送站点入库任务
        stationOperateProcessUtils.stationInExecute();
        //执行输送站点出库任务
        stationOperateProcessUtils.stationOutExecute();
        //检测输送站点出库任务执行完成
        stationOperateProcessUtils.stationOutExecuteFinish();
    }
 
    //检测入库站是否有任务生成,并仿真生成模拟入库站点数据
    private synchronized void checkInStationHasTask() {
        if (!enableFake.equals("Y")) {
            return;
        }
 
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
        for (BasDevp basDevp : basDevps) {
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
            if(stationThread == null){
                continue;
            }
 
            Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
 
            List<StationObjModel> list = basDevp.getInStationList$();
            for (StationObjModel entity : list) {
                Integer stationId = entity.getStationId();
                if(!stationMap.containsKey(stationId)){
                    continue;
                }
 
                StationProtocol stationProtocol = stationMap.get(stationId);
                if (stationProtocol == null) {
                    continue;
                }
 
                Object object = redisUtil.get(RedisKeyType.GENERATE_FAKE_IN_STATION_DATA_LIMIT.key + stationId);
                if (object != null) {
                    continue;
                }
 
                //满足自动、无物、工作号0,生成入库数据
                if (stationProtocol.isAutoing()
                        && !stationProtocol.isLoading()
                        && stationProtocol.getTaskNo() == 0
                ) {
                    StationCommand command = stationThread.getMoveCommand(9999, stationId, 0, 0);
                    MessageQueue.offer(SlaveType.Devp, basDevp.getDevpNo(), new Task(2, command));
                    redisUtil.set(RedisKeyType.GENERATE_FAKE_IN_STATION_DATA_LIMIT.key + stationId, "lock", 10);
                }
            }
        }
    }
 
    //生成仿真模拟入库任务
    private synchronized void generateFakeInTask() {
        if (!enableFake.equals("Y")) {
            return;
        }
 
        if (fakeRealTaskRequestWms.equals("Y")) {
            return;
        }
 
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
        for (BasDevp basDevp : basDevps) {
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
            if(stationThread == null){
                continue;
            }
 
            Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
 
            List<StationObjModel> list = basDevp.getInStationList$();
            for (StationObjModel model : list) {
                Integer stationId = model.getStationId();
                if(!stationMap.containsKey(stationId)){
                    continue;
                }
 
                StationProtocol stationProtocol = stationMap.get(stationId);
                if (stationProtocol == null) {
                    continue;
                }
 
                Object object = redisUtil.get(RedisKeyType.GENERATE_FAKE_IN_TASK_LIMIT.key + stationId);
                if (object != null) {
                    return;
                }
 
                //满足自动、有物、工作号9999,生成入库数据
                if (stationProtocol.isAutoing()
                        && stationProtocol.isLoading()
                        && stationProtocol.getTaskNo() == 9999
                ) {
                    //检测任务是否生成
                    List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
                    if (!wrkMasts.isEmpty()) {
                        continue;
                    }
 
                    List<LocMast> locMastList = locMastService.selectList(new EntityWrapper<LocMast>().eq("loc_sts", String.valueOf(LocStsType.O)));
                    if (locMastList.isEmpty()) {
                        continue;
                    }
 
                    int nextInt = new Random().nextInt(locMastList.size());
                    LocMast locMast = locMastList.get(nextInt);
 
                    Integer crnNo = commonService.findCrnNoByLocNo(locMast.getLocNo());
                    if (crnNo == null) {
                        continue;
                    }
 
                    Integer targetStationId = commonService.findInStationId(crnNo, stationId);
                    if (targetStationId == null) {
                        continue;
                    }
 
                    CreateInTaskParam taskParam = new CreateInTaskParam();
                    taskParam.setTaskNo(String.valueOf(commonService.getWorkNo(WrkIoType.IN.id)));
                    taskParam.setSourceStaNo(stationId);
                    taskParam.setStaNo(targetStationId);
                    taskParam.setLocNo(locMast.getLocNo());
                    taskParam.setBarcode(stationProtocol.getBarcode());
                    boolean result = commonService.createInTask(taskParam);
 
                    redisUtil.set(RedisKeyType.GENERATE_FAKE_IN_TASK_LIMIT.key + stationId, "lock", 5);
                }
            }
        }
    }
 
    //生成仿真模拟出库任务
    private synchronized void generateFakeOutTask() {
        if (!enableFake.equals("Y")) {
            return;
        }
 
        if (fakeRealTaskRequestWms.equals("Y")) {
            return;
        }
 
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
        for (BasDevp basDevp : basDevps) {
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
            if(stationThread == null){
                continue;
            }
 
            Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
 
            List<StationObjModel> list = basDevp.getOutStationList$();
            for (StationObjModel entity : list) {
                Integer stationId = entity.getStationId();
                if(!stationMap.containsKey(stationId)){
                    continue;
                }
 
                StationProtocol stationProtocol = stationMap.get(stationId);
                if (stationProtocol == null) {
                    continue;
                }
 
                Object object = redisUtil.get(RedisKeyType.GENERATE_FAKE_OUT_TASK_LIMIT.key + stationId);
                if(object != null){
                    return;
                }
 
                //满足自动、无物、工作号0,生成出库数据
                if (stationProtocol.isAutoing()
                        && !stationProtocol.isLoading()
                        && stationProtocol.getTaskNo() == 0
                ) {
                    List<LocMast> locMastList = locMastService.selectList(new EntityWrapper<LocMast>().eq("loc_sts", String.valueOf(LocStsType.F)));
                    if (locMastList.isEmpty()) {
                        continue;
                    }
 
                    LocMast locMast = locMastList.get(0);
 
                    Integer crnNo = commonService.findCrnNoByLocNo(locMast.getLocNo());
                    if (crnNo == null) {
                        continue;
                    }
 
                    CreateOutTaskParam taskParam = new CreateOutTaskParam();
                    taskParam.setTaskNo(String.valueOf(commonService.getWorkNo(WrkIoType.OUT.id)));
                    taskParam.setStaNo(stationId);
                    taskParam.setLocNo(locMast.getLocNo());
                    boolean result = commonService.createOutTask(taskParam);
                    redisUtil.set(RedisKeyType.GENERATE_FAKE_OUT_TASK_LIMIT.key + stationId, "lock", 15);
                }
            }
        }
    }
 
    /**
     * 请求生成入库任务
     * 入库站,根据条码扫描生成入库工作档
     */
    public synchronized void generateStoreWrkFile() {
        if (fakeRealTaskRequestWms.equals("N")) {
            return;
        }
 
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
        for (BasDevp basDevp : basDevps) {
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
            if(stationThread == null){
                continue;
            }
 
            Map<Integer, StationProtocol> stationMap = stationThread.getStatusMap();
 
            List<StationObjModel> list = basDevp.getInStationList$();
            for (StationObjModel entity : list) {
                Integer stationId = entity.getStationId();
                if(!stationMap.containsKey(stationId)){
                    continue;
                }
 
                StationProtocol stationProtocol = stationMap.get(stationId);
                if (stationProtocol == null) {
                    continue;
                }
 
                //满足自动、有物、工作号9999,生成入库数据
                if (stationProtocol.isAutoing()
                        && stationProtocol.isLoading()
                        && stationProtocol.getTaskNo() == 9999
                ) {
                    //检测任务是否生成
                    List<WrkMast> wrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>().eq("barcode", stationProtocol.getBarcode()));
                    if (!wrkMasts.isEmpty()) {
                        continue;
                    }
 
                    String wmsUrl = null;
                    Config wmsSystemUriConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemUri"));
                    if (wmsSystemUriConfig != null) {
                        wmsUrl = wmsSystemUriConfig.getValue();
                    }
 
                    if(wmsUrl == null){
                        News.error("未配置WMS系统URI,配置文件Code编码:wmsSystemUri");
                        return;
                    }
 
                    String wmsSystemInUrl = null;
                    Config wmsSystemInUrlConfig = configService.selectOne(new EntityWrapper<Config>().eq("code", "wmsSystemInUrl"));
                    if (wmsSystemInUrlConfig != null) {
                        wmsSystemInUrl = wmsSystemInUrlConfig.getValue();
                    }
 
                    if(wmsSystemInUrlConfig == null){
                        News.error("未配置WMS入库接口地址,配置文件Code编码:wmsSystemInUrl");
                        return;
                    }
 
                    Object lock = redisUtil.get(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId);
                    if (lock != null) {
                        continue;
                    }
 
                    HashMap<String, Object> requestParam = new HashMap<>();
                    String response = null;
                    try {
                        requestParam.put("barcode", stationProtocol.getBarcode());
                        requestParam.put("sourceStaNo", stationProtocol.getStationId());
                        requestParam.put("locType1", stationProtocol.getPalletHeight());
                        requestParam.put("row", Utils.getInTaskEnableRow());
 
                        response = new HttpHandler.Builder()
                                .setUri(wmsUrl)
                                .setPath(wmsSystemInUrl)
                                .setJson(JSON.toJSONString(requestParam))
                                .build()
                                .doPost();
                        JSONObject jsonObject = JSON.parseObject(response);
                        if (jsonObject.getInteger("code").equals(200)) {
                            StartupDto dto = jsonObject.getObject("data", StartupDto.class);
 
                            CreateInTaskParam taskParam = new CreateInTaskParam();
                            taskParam.setTaskNo(String.valueOf(dto.getTaskNo()));
                            taskParam.setLocNo(dto.getLocNo());
                            taskParam.setTaskPri(dto.getTaskPri());
                            taskParam.setBarcode(stationProtocol.getBarcode());
                            boolean result = commonService.createInTask(taskParam);
 
                            News.info("请求WMS接口成功!!!url:{};request:{};response:{}", wmsUrl + wmsSystemInUrl, JSON.toJSONString(requestParam), response);
                        } else {
                            News.error("请求WMS接口失败!!!url:{};request:{};response:{}", wmsUrl + wmsSystemInUrl, JSON.toJSONString(requestParam), response);
                        }
 
                        redisUtil.set(RedisKeyType.GENERATE_IN_TASK_LIMIT.key + stationId, "lock", 10);
                    } catch (Exception e) {
                        e.printStackTrace();
                    } finally {
                        HttpRequestLog httpRequestLog = new HttpRequestLog();
                        httpRequestLog.setName(wmsUrl + wmsSystemInUrl);
                        httpRequestLog.setRequest(JSON.toJSONString(requestParam));
                        httpRequestLog.setResponse(response);
                        httpRequestLog.setCreateTime(new Date());
                        httpRequestLogService.insert(httpRequestLog);
                    }
                }
            }
        }
    }
 
    //计算所有站点停留时间
    public synchronized void calcAllStationStayTime() {
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
        for (BasDevp basDevp : basDevps) {
            StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, basDevp.getDevpNo());
            if (stationThread == null) {
                continue;
            }
 
            List<StationProtocol> list = stationThread.getStatus();
            for (StationProtocol stationProtocol : list) {
                if (stationProtocol.getTaskNo() > 0 && !stationStayTimeMap.containsKey(stationProtocol.getStationId())) {
                    stationStayTimeMap.put(stationProtocol.getStationId(), System.currentTimeMillis());
                }
 
                if(stationProtocol.getTaskNo() <= 0 && stationStayTimeMap.containsKey(stationProtocol.getStationId())) {
                    stationStayTimeMap.remove(stationProtocol.getStationId());
                }
            }
        }
    }
 
    //检测出库站点停留是否超时
    public synchronized void checkOutStationStayTimeOut() {
        List<BasDevp> basDevps = basDevpService.selectList(new EntityWrapper<>());
        for (BasDevp basDevp : basDevps) {
            List<StationObjModel> outStationList = basDevp.getOutStationList$();
            if(outStationList.isEmpty()){
                News.info("输送线:{} 出库站点未设置", basDevp.getDevpNo());
                continue;
            }
 
            for (StationObjModel stationObjModel : outStationList) {
                Object lock = redisUtil.get(RedisKeyType.CHECK_OUT_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId());
                if(lock != null){
                    continue;
                }
 
                Long stayTime = stationStayTimeMap.get(stationObjModel.getStationId());
                if (stayTime == null) {
                    continue;
                }
 
                if(System.currentTimeMillis() - stayTime > 1000 * 15) {
                    StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
                    if(stationThread == null){
                        continue;
                    }
 
                    StationCommand command = stationThread.getMoveCommand(0, stationObjModel.getStationId(), 0, 0);
                    if(command == null){
                        continue;
                    }
 
                    MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
                    redisUtil.set(RedisKeyType.CHECK_OUT_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(), "lock",10);
                    News.info("输送站点重置命令下发成功,站点号={},命令数据={}", stationObjModel.getStationId(), JSON.toJSONString(command));
                }
            }
        }
    }
 
    //检测入库站点堆垛机是否取走货物
    public synchronized void checkInStationCrnTake() {
        List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>());
        for (BasCrnp basCrnp : basCrnps) {
            List<StationObjModel> inStationList = basCrnp.getInStationList$();
            if(inStationList.isEmpty()){
                News.info("堆垛机:{} 入库站点未设置", basCrnp.getCrnNo());
                continue;
            }
 
            for (StationObjModel stationObjModel : inStationList) {
                Object lock = redisUtil.get(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId());
                if(lock != null){
                    continue;
                }
 
                StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
                if(stationThread == null){
                    continue;
                }
 
                StationCommand command = stationThread.getMoveCommand(0, stationObjModel.getStationId(), 0, 0);
                if(command == null){
                    continue;
                }
 
                Map<Integer, StationProtocol> statusMap = stationThread.getStatusMap();
                StationProtocol stationProtocol = statusMap.get(stationObjModel.getStationId());
                if (stationProtocol == null) {
                    continue;
                }
 
                if(stationProtocol.getTaskNo() > 0) {
                    WrkMast wrkMast = wrkMastService.selectByWorkNo(stationProtocol.getTaskNo());
                    if (wrkMast == null) {
                        MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
                        redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(), "lock",10);
                        News.info("输送站点重置命令下发成功,站点号={},命令数据={}", stationObjModel.getStationId(), JSON.toJSONString(command));
                    }else {
                        if (wrkMast.getWrkSts() != WrkStsType.NEW_INBOUND.sts && wrkMast.getWrkSts() != WrkStsType.INBOUND_DEVICE_RUN.sts) {
                            Integer crnNo = wrkMast.getCrnNo();
                            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crnNo);
                            if (crnThread == null) {
                                continue;
                            }
                            CrnProtocol crnProtocol = crnThread.getStatus();
                            if (crnProtocol.getStatusType().equals(CrnStatusType.FETCH_MOVING) || crnProtocol.getStatusType().equals(CrnStatusType.FETCHING)) {
                                continue;
                            }
 
                            MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
                            redisUtil.set(RedisKeyType.CHECK_IN_STATION_STAY_TIME_OUT_LIMIT.key + stationObjModel.getStationId(), "lock",10);
                            News.info("输送站点重置命令下发成功,站点号={},命令数据={}", stationObjModel.getStationId(), JSON.toJSONString(command));
                        }
                    }
                }
            }
        }
    }
 
    //堆垛机任务执行完成
    public synchronized void crnIoExecuteFinish() {
        List<BasCrnp> basCrnps = basCrnpService.selectList(new EntityWrapper<>());
        for (BasCrnp basCrnp : basCrnps) {
            CrnThread crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, basCrnp.getCrnNo());
            if(crnThread == null){
                continue;
            }
 
            CrnProtocol crnProtocol = crnThread.getStatus();
            if(crnProtocol == null){
                continue;
            }
 
            if (crnProtocol.getMode() == CrnModeType.AUTO.id
                    && crnProtocol.getTaskNo() > 0
                    && crnProtocol.getStatus() == CrnStatusType.WAITING.id
            ) {
                Object lock = redisUtil.get(RedisKeyType.CRN_IO_EXECUTE_FINISH_LIMIT.key + basCrnp.getCrnNo());
                if(lock != null){
                    continue;
                }
 
                // 获取待确认工作档
                WrkMast wrkMast = wrkMastService.selectByWorkNo(crnProtocol.getTaskNo());
                if (wrkMast == null) {
                    News.error("堆垛机处于等待确认且任务完成状态,但未找到工作档。堆垛机号={},工作号={}", basCrnp.getCrnNo(), crnProtocol.getTaskNo());
                    continue;
                }
 
                Long updateWrkSts = null;
                if(wrkMast.getWrkSts() == WrkStsType.INBOUND_RUN.sts){
                    updateWrkSts = WrkStsType.COMPLETE_INBOUND.sts;
                }else if(wrkMast.getWrkSts() == WrkStsType.OUTBOUND_RUN.sts){
                    updateWrkSts = WrkStsType.OUTBOUND_RUN_COMPLETE.sts;
 
                    //生成仿真站点数据
                    List<StationObjModel> outStationList = basCrnp.getOutStationList$();
                    if(outStationList.isEmpty()){
                        News.info("堆垛机:{} 出库站点未设置", basCrnp.getCrnNo());
                        continue;
                    }
 
                    for (StationObjModel stationObjModel : outStationList) {
                        if (!stationObjModel.getStationId().equals(wrkMast.getSourceStaNo())) {
                            continue;
                        }
 
                        StationThread stationThread = (StationThread) SlaveConnection.get(SlaveType.Devp, stationObjModel.getDeviceNo());
                        if (stationThread == null) {
                            continue;
                        }
                        //生成仿真站点数据
                        StationCommand command = stationThread.getMoveCommand(9998, wrkMast.getSourceStaNo(), 0, 0);
                        MessageQueue.offer(SlaveType.Devp, stationObjModel.getDeviceNo(), new Task(2, command));
                    }
                }else{
                    News.error("堆垛机处于等待确认且任务完成状态,但工作状态异常。堆垛机号={},工作号={}", basCrnp.getCrnNo(), crnProtocol.getTaskNo());
                    continue;
                }
 
                wrkMast.setWrkSts(updateWrkSts);
                wrkMast.setSystemMsg("");
                wrkMast.setIoTime(new Date());
                if (wrkMastService.updateById(wrkMast)) {
                    CrnCommand resetCommand = crnThread.getResetCommand(crnProtocol.getCrnNo());
                    MessageQueue.offer(SlaveType.Crn, crnProtocol.getCrnNo(), new Task(2, resetCommand));
                    News.info("堆垛机任务状态更新成功,堆垛机号={},工作号={}", basCrnp.getCrnNo(), crnProtocol.getTaskNo());
                }
 
                redisUtil.set(RedisKeyType.CRN_IO_EXECUTE_FINISH_LIMIT.key + basCrnp.getCrnNo(), "lock",10);
            }
        }
    }
 
}