InquiryShelfBean.java
31.7 KB
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
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
package com.myproject.bean.qisda;
import com.myproject.bean.update.DataLog;
import com.myproject.bean.update.qisda.OutItem;
import com.myproject.util.StorageConstants;
import com.myproject.webapp.controller.webService.QisdaCache;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.util.Strings;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
*
* 出库需求单使用料架情况
* Created by sunke on 2019/12/15.
*/
public class InquiryShelfBean {
protected final static Logger log = LogManager.getLogger(InquiryShelfBean.class);
/**
* 紧急料Shelf Key
*/
public static final String URGENT_SHELF_MAP_KEY = "1";
/**
* 分盘料Shelf Key
*/
public static final String CUT_SHELF_MAP_KEY = "2";
/**
* 料架管理Map, key为 hSerial, value的key为 tempRfid, value为料架
*/
public static Map<String,Map<String,ShelfInfo>> hSerialShelfMap;
public static void initShelfMap(){
if(hSerialShelfMap == null){
hSerialShelfMap = QisdaCache.loadShelfMap();
}
}
/**
* 清理使用过的料架
*/
public static void clearShelf(String hSerial){
if(hSerial != null){
Map<String, ShelfInfo> shelfMap = hSerialShelfMap.get(hSerial);
if(shelfMap != null){
log.info("清理["+hSerial+"]使用过的料架");
hSerialShelfMap.remove(hSerial);
QisdaCache.saveShelfMap(hSerialShelfMap);
}
}
}
public static boolean clearShelf(String hSerial, String rfid){
boolean clearResult = false;
if(hSerial != null){
log.info("清理["+hSerial+"]使用的过料架["+rfid+"]");
Map<String, ShelfInfo> shelfMap = hSerialShelfMap.get(hSerial);
if(shelfMap != null){
ShelfInfo shelfInfo = findSameShelf(hSerial, rfid);
if(shelfInfo != null){
String tempRfid = shelfInfo.tempRfid();
shelfMap.remove(tempRfid);
hSerialShelfMap.put(hSerial, shelfMap);
clearResult = true;
QisdaCache.saveShelfMap(hSerialShelfMap);
}
}
}
return clearResult;
}
private static List<ShelfInfo> getSortedCAndDShelfList(DataLog task){
AppendInfo taskAppendInfo = task.getAppendInfo();
String hSerial = taskAppendInfo.gethSerial();
Map<String, ShelfInfo> shelfMap = hSerialShelfMap.get(hSerial);
//C和D料架列表
List<ShelfInfo> cAndDShelfList = new ArrayList<>();
for (ShelfInfo shelfInfo : shelfMap.values()) {
if(shelfInfo.isDShelf() || shelfInfo.isCShelf()) {
cAndDShelfList.add(shelfInfo);
}
}
//排序1D=>3D=>6D=>2C=>4C=5C
cAndDShelfList.sort(new Comparator<ShelfInfo>() {
public int compare(ShelfInfo shelf1, ShelfInfo shelf2) {
if(shelf1.getShelfType().equals(shelf2.getShelfType())){
return shelf1.getRfidIndex() - shelf2.getRfidIndex();
}else{
return shelf2.getShelfType().compareTo(shelf1.getShelfType());
}
}
});
return cAndDShelfList;
}
public static boolean canCheckOutTailActionTask(DataLog task, int unFinishedBigTaskCount){
AppendInfo taskAppendInfo = task.getAppendInfo();
if(taskAppendInfo.isTailAction()){
if(task.isSmallReel()){
return true;
}else{
//大料任务,只有当小料架只剩下一个未满时才可以出
List<ShelfInfo> cAndDShelfList = getSortedCAndDShelfList(task);
for (int i = 0; i < cAndDShelfList.size(); i++) {
ShelfInfo shelfInfo = cAndDShelfList.get(i);
if(!shelfInfo.isFull()){
if(shelfInfo.isCShelf()){
//小料架已经放满,大料可以随便出
return true;
}else if(shelfInfo.isDShelf()){
//小料架还未放满
if(i+1<cAndDShelfList.size()){
ShelfInfo nextShelf = cAndDShelfList.get(i + 1);
if(nextShelf.isDShelf()){
//下一个料架如果是小料架,不允许出
//log.info("还有两个小料架["+shelfInfo.tempRfid()+"," + nextShelf.tempRfid()+"]未放满,大料任务["+task.getBarcode()+"]暂停出库");
return false;
}else{
//下一个料架是大料架,最多只能出一个料架的大料
int emptyLocCount = nextShelf.getEmptyLocCount();
boolean canOut = unFinishedBigTaskCount + 1 <= emptyLocCount;
if(!canOut){
//log.info("未完成的大料数量["+unFinishedBigTaskCount+"]已可放满下一料架"+nextShelf.tempRfid()+"["+emptyLocCount+"],大料任务["+task.getBarcode()+"]暂停出库");
}
return canOut;
}
}
}
break;
}
}
}
}
return false;
}
/**
* 判断首盘任务是否可以出库
*/
public static boolean canCheckOutFistActionTask(DataLog task){
//保证双层线上最多只能有两个料架
List<ShelfInfo> cAndDShelfList = getSortedCAndDShelfList(task);
AppendInfo taskAppendInfo = task.getAppendInfo();
if(taskAppendInfo.isFirstReelAction() && !task.isLessSendReel()){
//如果任务是在最小(有空位)和次小的料架当中,可以出库
ShelfInfo firstEmptyShelf = null;
ShelfInfo secondEmptyShelf = null;
for (int i = 0; i < cAndDShelfList.size(); i++) {
ShelfInfo shelfInfo = cAndDShelfList.get(i);
if(!shelfInfo.isFull()){
firstEmptyShelf = shelfInfo;
if(i+1<cAndDShelfList.size()){
secondEmptyShelf = cAndDShelfList.get(i + 1);
}
break;
}
}
String shelfNameStr = "";
if(firstEmptyShelf != null){
if(firstEmptyShelf.tempRfid().equals(task.getTempRfid())){
//与最小的料架号相同,可以出库
return true;
};
shelfNameStr = firstEmptyShelf.tempRfid();
}
if(secondEmptyShelf != null){
if(secondEmptyShelf.tempRfid().equals(task.getTempRfid())){
//与最次小的料架号相同,可以出库
return true;
};
shelfNameStr = shelfNameStr + "," + secondEmptyShelf.tempRfid();
}
log.info("任务"+task.getBarcode()+"["+task.getTempRfid()+"]不在两个料架"+shelfNameStr+"当中,暂不出库");
}
return false;
}
/**
* 添加限制库位(即库位中只能放入某个条码)
* @param task
* @param outItem
* @return
*/
public static DataLog addLimitLoc(DataLog task, OutItem outItem){
return addLoc(task, outItem, task.getBarcode());
}
/**
* 首盘料时,缺料站位空出一个架位
*/
public static void addEmptyLoc(OutItem outItem, String shelfType){
String hSerial = outItem.gethSerial();
ShelfInfo emptyShelfInfo = getOrAddShelfInfo(hSerial,shelfType);
if(emptyShelfInfo != null){
int loc = emptyShelfInfo.addEmptyLoc();
log.info("工单"+outItem.getSo()+"["+outItem.getSlotlocation()+"]"+outItem.getPn()+"预留架位"+emptyShelfInfo.tempRfid()+"["+ loc +"]");
updateShelfInfo(emptyShelfInfo);
}
}
/**
* 添加不限制的库位,即库位对条码不作限制
* @param task
* @param outItem
* @return
*/
public static DataLog addUnlimitLoc(DataLog task, OutItem outItem){
return addLoc(task, outItem, "");
}
public static String getShelfType(DataLog task){
//空位预留
if(task == null){
//根据尺寸确定预留种架位
return StorageConstants.SHEFL_TYPE.D;
}
String shelfType = "";
//包装料架
if(task.isPackageReel()){
shelfType = StorageConstants.SHEFL_TYPE.A;
}else {
//需要分盘的料或紧急料或者缺料补发的料,且不是包装料,统一都放到料串上
if(task.isCutReel() || task.isUrgentReel() || task.isLessSendReel() || task.getAppendInfo().isUrgentAction()){
//B料串
return StorageConstants.SHEFL_TYPE.B;
}else{
if(task.isSmallReel()){
//D料架
shelfType = StorageConstants.SHEFL_TYPE.D;
}else{
shelfType = StorageConstants.SHEFL_TYPE.C;
}
}
}
return shelfType;
}
/**
* 获取未达最大数量的料架,或者添加一个新的料架
* @param shelfType
* @return
*/
private static ShelfInfo getOrAddShelfInfo(String hSerial, String shelfType){
Map<String, ShelfInfo> shelfMap = hSerialShelfMap.get(hSerial);
int rfidIndex = 0;
if(shelfMap != null){
for (ShelfInfo shelfInfo : shelfMap.values()) {
if(StorageConstants.SHEFL_TYPE.judgeType(shelfInfo.getShelfType(), shelfType)){
if(shelfInfo != null && !shelfInfo.reachMaxLoc()){
return shelfInfo;
}
}
}
rfidIndex = shelfMap.size();
}
ShelfInfo newShelf = null;
if(StorageConstants.SHEFL_TYPE.isAShelf(shelfType)){
newShelf = ShelfInfo.newAShelf();
}else if(StorageConstants.SHEFL_TYPE.isBShelf(shelfType)){
newShelf = ShelfInfo.newBShelf();
}if(StorageConstants.SHEFL_TYPE.isCShelf(shelfType)){
newShelf = ShelfInfo.newCShelf();
}else if(StorageConstants.SHEFL_TYPE.isDShelf(shelfType)){
newShelf = ShelfInfo.newDShelf();
}
if(newShelf != null){
newShelf.setRfidIndex(rfidIndex);
newShelf.sethSerial(hSerial);
log.info("添加新料架["+newShelf.tempRfid() + "]");
updateShelfInfo(newShelf);
}
return newShelf;
}
/**
* 更新料架缓存信息
*/
public static void updateShelfInfo(ShelfInfo shelfInfo){
String hSerial = shelfInfo.gethSerial();
Map<String, ShelfInfo> shelfMap = hSerialShelfMap.get(hSerial);
if(shelfMap == null){
shelfMap = new ConcurrentHashMap<>();
}
shelfMap.put(shelfInfo.tempRfid(), shelfInfo);
hSerialShelfMap.put(hSerial, shelfMap);
QisdaCache.saveShelfMap(hSerialShelfMap);
}
private static synchronized DataLog addLoc(DataLog task, OutItem outItem, String barcode){
String shelfType = getShelfType(task);
String hSerial = outItem.gethSerial();
if(task.isUrgentReel()){
//紧急料放在同一个料串或包装料架上,需求单号使用1
hSerial = "1";
}else if(task.isCutReel()){
//分盘料放在同一个料串或包装料架上,需求单号使用2
hSerial = "2";
}
ShelfInfo emptyShelfInfo = getOrAddShelfInfo(hSerial,shelfType);
if(emptyShelfInfo != null){
if(task != null){
int loc = -1;
AppendInfo appendInfo = task.getAppendInfo();
if(task.isPackageReel()){
//包装料,固定库位
loc = emptyShelfInfo.addLimitLoc(task.getBarcode(),task.getReelType());
appendInfo.setRfidLoc(loc);
}else{
loc = emptyShelfInfo.addLimitLoc(barcode,task.getReelType());
}
log.info("工单"+outItem.getSo()+"["+outItem.getSlotlocation()+"]"+outItem.getPn()+"为["+task.getBarcode()+"]添加架位["+emptyShelfInfo.tempRfid() + "]["+ loc +"]=" + barcode);
appendInfo.setRfidIndex(emptyShelfInfo.getRfidIndex());
appendInfo.setShelfType(shelfType);
appendInfo.sethSerial(outItem.gethSerial());
if(barcode != null && !barcode.isEmpty()){
appendInfo.setRfidLoc(loc);
}
String location = shelfType;
if(outItem.isFirstReelAction() && !task.isLessSendReel()){
location = emptyShelfInfo.getRfidIndex() + shelfType + "_" + loc;
}else if(task.isLessSendReel()){
int showLoc = task.resolveRfidLoc(loc+"");
location = shelfType + "_" + showLoc;
}
task.setSubSourceInfo(location);
task.setAppendInfo(appendInfo);
//非分盘和非紧急料和非缺料补发的包装料需要在C型料架上预留位置
if(task.isPackageReel() && !task.isCutReel() && !task.isUrgentReel() && !task.isLessSendReel()){
String cShelf = StorageConstants.SHEFL_TYPE.C;
ShelfInfo packageCShelf = getOrAddShelfInfo(hSerial, cShelf);
int packageCLoc = packageCShelf.addLimitLoc(barcode, StorageConstants.REEL_TYPE.PACKAGE);
log.info("包装料["+barcode+"]预留C型料架:工单"+outItem.getSo()+"["+outItem.getSlotlocation()+"]"+outItem.getPn()+"添加架位["+packageCShelf.tempRfid() + "]["+ packageCLoc +"]=["+emptyShelfInfo.tempRfid() + "]["+ loc +"]=" + barcode);
}
}else{
int loc = emptyShelfInfo.addEmptyLoc();
log.info("工单"+outItem.getSo()+"["+outItem.getSlotlocation()+"]"+outItem.getPn()+"预留架位"+emptyShelfInfo.tempRfid()+"["+ loc +"]");
}
updateShelfInfo(emptyShelfInfo);
}
return task;
}
/**
* 根据tempRfid编号获取料架信息
*/
public static ShelfInfo findSameShelf(String hSerial, String rfid){
if(hSerial != null && !hSerial.isEmpty()){
Map<String, ShelfInfo> shelfMap = hSerialShelfMap.get(hSerial);
if(shelfMap != null){
for (ShelfInfo shelf : shelfMap.values()) {
String shelfRFID = shelf.getRealRfid();
log.debug(shelf.tempRfid() + "判断料架["+shelfRFID+"] = " + rfid);
if(shelfRFID != null && rfid != null){
if(shelfRFID.equals(rfid)){
//已经绑定过该Temp料架
return shelf;
}
}
}
}else{
//log.error("未找到需求单["+hSerial+"]料架["+rfid+"]");
}
}
return null;
}
/**
* 查找料架相同RFID的料架,用于AGV判断是否还有任务
*/
public static ShelfInfo findShelf(String rfid){
if(Strings.isEmpty(rfid)){
return null;
}
ShelfInfo minIndexShelf = null;
for (Map<String, ShelfInfo> shelfInfoMap : hSerialShelfMap.values()) {
for (ShelfInfo shelf : shelfInfoMap.values()) {
String shelfRFID = shelf.getRealRfid();
if(shelfRFID.equals(rfid)){
//已经绑定过该Temp料架
return shelf;
}
}
}
return null;
}
/**
* 3号机器人放入时查找包装料架上的物料信息(肯定会存在)
* @param packageRfid
* @return
*/
public static ShelfInfo findPackageShelf(String hSerial, String packageRfid){
if(packageRfid == null || packageRfid.isEmpty()){
return null;
}
Map<String, ShelfInfo> shSerialShelfInfoMap = hSerialShelfMap.get(hSerial);
if(shSerialShelfInfoMap == null ){
return null;
}
for (ShelfInfo shelf : shSerialShelfInfoMap.values()) {
String shelfRFID = shelf.getRealRfid();
if(shelfRFID.equals(packageRfid)){
//已经绑定过该Temp料架
return shelf;
}
}
return null;
}
/**
* 获取某个需求单已经绑定的RFID
* @param hSerial 需求单号
*/
public static List<String> getUsedRfidList(String hSerial){
List<String> usedRfidList = new ArrayList<>();
Map<String, ShelfInfo> shelfMap = hSerialShelfMap.get(hSerial);
if(shelfMap != null){
for (ShelfInfo shelfInfo : shelfMap.values()) {
String realRfid = shelfInfo.getRealRfid();
if(!realRfid.isEmpty()){
usedRfidList.add(realRfid);
}
}
}
return usedRfidList;
}
/**
* 首套料,获取分配好的库位
*/
public static ShelfLoc getLimitLoc(DataLog task){
AppendInfo appendInfo = task.getAppendInfo();
String barcode = task.getBarcode();
String hSerial = appendInfo.gethSerial();
Map<String, ShelfInfo> shelfMap = hSerialShelfMap.get(hSerial);
if(shelfMap != null){
for (ShelfInfo shelfInfo : shelfMap.values()) {
int loc = shelfInfo.getBarcodeLoc(barcode, appendInfo.getShelfType());
if(loc != -1){
ShelfLoc shelfLoc = new ShelfLoc();
shelfLoc.setLoc(loc);
shelfLoc.setTempRfid(shelfInfo.tempRfid());
shelfLoc.setRealRfid(shelfInfo.getRealRfid());
log.info("查找到["+barcode+"]分配的库位" + shelfInfo.tempRfid()+"["+loc+"] Task库位"+appendInfo.getRfid()+"["+appendInfo.getRfidLoc()+"]");
return shelfLoc;
}
}
}
return null;
}
public static ShelfInfo findMaxUsedShelf(String hSerial, String shelfType){
Map<String, ShelfInfo> shelfMap = hSerialShelfMap.get(hSerial);
if(shelfMap == null){
return null;
}
ShelfInfo minIndexShelf = null;
for (ShelfInfo shelf : shelfMap.values()) {
if(StorageConstants.SHEFL_TYPE.judgeType(shelfType, shelf.getShelfType())){
if(shelf.isFull()){
//已经放满,查找下一个
continue;
}
//同一种料架
if(minIndexShelf == null){
minIndexShelf = shelf;
}
if(shelf.getRfidIndex() < minIndexShelf.getRfidIndex()){
minIndexShelf = shelf;
}
}
}
if(minIndexShelf != null){
log.info("找到类型为["+shelfType+"]最小序号未绑定同种料架["+minIndexShelf.tempRfid()+"]");
}else{
log.info("已没有与["+shelfType+"]类型相同的料架");;
}
return minIndexShelf;
}
/**
* 锁定架位
*/
public static synchronized ShelfLoc lockShelfLoc(DataLog task, String rfid, String robotIndex){
AppendInfo appendInfo = task.getAppendInfo();
String hSerial = appendInfo.gethSerial();
ShelfInfo shelfInfo = null;
if(hSerial != null){
Map<String, ShelfInfo> shelfMap = hSerialShelfMap.get(hSerial);
if(shelfMap != null){
//先判断任务料架是否与双层线上的实际料架类型是否一致,如果不一致,直接使用新的料架
if(rfid != null && !rfid.isEmpty()){
if(StorageConstants.SHEFL_TYPE.judgeType(rfid, task.getAppendInfo().getShelfType())){
//任务与当前料架一致,使用已经绑定过的料架
shelfInfo = findSameShelf(hSerial, rfid);
}
}
if(shelfInfo != null){
//找到与实际料架相同的料架,但料架上已经满了,查找其他同类型料架
if(shelfInfo.isFull()){
log.info("料架["+shelfInfo.getRealRfid()+"]="+shelfInfo.tempRfid()+"已满,查找新的料架");
shelfInfo = null;
}
}
//未找到已经有实际RFID的料架,查找库位最多的料架
if(shelfInfo == null){
log.info(task.getBarcode() + "未找到实际绑定的["+rfid+"]料架,开始查找序号最小的同种料架["+task.getAppendInfo().getShelfType()+"]");
ShelfInfo minIndexShelf = null;
for (ShelfInfo shelf : shelfMap.values()) {
if(StorageConstants.SHEFL_TYPE.judgeType(task.getAppendInfo().getShelfType(), shelf.getShelfType())){
if(shelf.isFull()){
//已经放满,查找下一个
continue;
}
//同一种料架
if(minIndexShelf == null){
minIndexShelf = shelf;
}
if(shelf.getRfidIndex() < minIndexShelf.getRfidIndex()){
minIndexShelf = shelf;
}
}
}
shelfInfo = minIndexShelf;
if(shelfInfo != null){
log.info(task.getBarcode() + "["+ task.getTempRfid()+"]未找到rfid=["+rfid+"]的空料架,使用序号最小的同种料架["+shelfInfo.tempRfid()+"]");
}else{
log.info("已没有与["+rfid+"]类型相同的料架");;
}
}
}
}
if(shelfInfo == null){
log.error("任务条码["+task.getBarcode()+"]未找到对应的料架" + rfid);
return null;
}
ShelfLoc lockLoc = shelfInfo.lockOneEmptyLoc(task.getBarcode(), task.getReelType(), robotIndex);
if(lockLoc != null){
log.info("为["+task.getBarcode()+"]锁定架位:" + shelfInfo.tempRfid() + "[" +shelfInfo.getRealRfid()+"]["+lockLoc.getLoc()+"]原来分配架位:" + task.getTempRfid() + "[" + appendInfo.getRfidLoc() + "]");
// ShelfLoc shelfLoc = new ShelfLoc();
// shelfLoc.setLoc(lockLoc);
// shelfLoc.setRfid(rfid);
if(shelfInfo.getRealRfid() == null || shelfInfo.getRealRfid().isEmpty()){
//未绑定过的,使用TempRFID
lockLoc.setTempRfid(shelfInfo.tempRfid());
lockLoc.setRealRfid("");
}else{
//绑定过的使用RealRfid
lockLoc.setRealRfid(shelfInfo.getRealRfid());
lockLoc.setTempRfid(shelfInfo.tempRfid());
}
updateShelfInfo(shelfInfo);
return lockLoc;
}
return null;
}
/**
* 取消任务,解除料盘对料架的占用
*/
public static void cancelReelTask(DataLog task){
AppendInfo appendInfo = task.getAppendInfo();
String barcode = task.getBarcode();
String hSerial = appendInfo.gethSerial();
Map<String, ShelfInfo> shelfMap = hSerialShelfMap.get(hSerial);
if(shelfMap == null){
log.warn("["+task.getBarcode()+"]任务取消时未找到对应需求单["+hSerial+"]的料架缓存信息");
return;
}
if(appendInfo.isFirstReelAction()){
//首盘料,解除绑定的位置
for (ShelfInfo shelfInfo : shelfMap.values()) {
boolean result = shelfInfo.cancelLimitLoc(barcode);
if(result){
log.info("首盘料["+task.getBarcode()+"]任务取消,解除料架" + shelfInfo.tempRfid() +"锁定架位绑定");
updateShelfInfo(shelfInfo);
}
}
}else if(appendInfo.isTailAction()){
//补料盘,解除最后一个料架上的位置
ShelfInfo maxShelf = null;
String taskShelfType = appendInfo.getShelfType();
String targetShelfType = taskShelfType;
for (ShelfInfo shelfInfo : shelfMap.values()) {
int limitLoc = shelfInfo.getBarcodeLoc(barcode, taskShelfType);
if(limitLoc > 0){
//已经锁定过
boolean result = shelfInfo.cancelLimitLoc(barcode);
if(result){
log.info("补料盘["+task.getBarcode()+"]任务取消,解除料架" + shelfInfo.tempRfid() +"的锁定架位绑定");
updateShelfInfo(shelfInfo);
if(!task.isPackageReel()){
//非包装料,只取消一个架位就可以了(理论上非包装料也进入不到这里)
return;
}
}
}else{
if(task.isPackageReel()){
//包装料还需要取消C料架
targetShelfType = StorageConstants.SHEFL_TYPE.C;
}
if(shelfInfo.getShelfType().equals(targetShelfType) && !shelfInfo.isFull()){
if(maxShelf == null || shelfInfo.getRfidIndex() > maxShelf.getRfidIndex()){
maxShelf = shelfInfo;
}
}
}
}
if(maxShelf != null){
boolean result =maxShelf.cancelLoc(targetShelfType, barcode);
if(result){
log.info("补料盘["+task.getBarcode()+"]任务取消,同类型最大料架" + maxShelf.tempRfid() +"架位置空");
updateShelfInfo(maxShelf);
}
}
}
}
/**
* 紧急料/分盘料放入料架或料串
*/
public static synchronized ShelfLoc putInCutReel(DataLog task, String rfid, int loc){
String barcode = task.getBarcode();
String shelfMapKey = task.getShelfMapKey();
Map<String, ShelfInfo> shelfMap = hSerialShelfMap.get(shelfMapKey);
if(shelfMap != null){
//该料架是否已经绑定过
ShelfInfo bindedShelf = findSameShelf(shelfMapKey,rfid);
if(bindedShelf != null){
if(task.isPackageReel()){
//包装料架
}else{
//料串
loc = bindedShelf.addLimitLoc(barcode, task.getReelType());
}
boolean putInResult = bindedShelf.putInLimitLoc(rfid,loc,barcode);
if(putInResult){
updateShelfInfo(bindedShelf);
log.info("紧急/分盘料["+task.getBarcode()+"]放入料架" + rfid +"["+loc+"]缓存更新成功");
return new ShelfLoc(rfid,loc);
}
}else{
if(task.isPackageReel()){
//包装料架
for (ShelfInfo shelfInfo : shelfMap.values()) {
boolean putInResult = shelfInfo.putInLimitLoc(rfid,loc, barcode);
if(putInResult){
updateShelfInfo(shelfInfo);
log.info("紧急/分盘料["+task.getBarcode()+"]使用新料架" + rfid +"["+loc+"]缓存更新成功");
return new ShelfLoc(rfid,loc);
}
}
}else{
//添加一个新的料串,并放入
ShelfInfo newBShelf = ShelfInfo.newBShelf();
int rfidIndex = shelfMap.size();
newBShelf.setRfidIndex(rfidIndex);
newBShelf.sethSerial(shelfMapKey);
log.info("添加新料架["+newBShelf.tempRfid() + "]");
loc = newBShelf.addLimitLoc(barcode, task.getReelType());
boolean putInResult = newBShelf.putInLimitLoc(rfid,loc,barcode);
if(putInResult){
updateShelfInfo(newBShelf);
log.info("紧急/分盘料["+task.getBarcode()+"]放入料架" + rfid +"["+loc+"]缓存更新成功");
return new ShelfLoc(rfid,loc);
}
}
}
}else{
log.info("未找到["+shelfMapKey+"]相关料架");
}
log.error("物料["+task.getBarcode()+"]("+task.getTempRfid()+"["+task.getAppendInfo().getRfidLoc()+"])料架" + rfid +"["+loc+"]缓存更新失败");
return null;
}
public static synchronized boolean putInShelf(DataLog task, String rfid, int loc){
AppendInfo appendInfo = task.getAppendInfo();
String barcode = task.getBarcode();
String hSerial = appendInfo.gethSerial();
Map<String, ShelfInfo> shelfMap = hSerialShelfMap.get(hSerial);
if(shelfMap != null){
//该料架是否已经绑定过
ShelfInfo bindedShelf = findSameShelf(hSerial,rfid);
if(appendInfo.isFirstReelAction()){
//首盘料,要按位置放
if(bindedShelf != null){
//已经绑定过
boolean putInResult = bindedShelf.putInLimitLoc(rfid,loc, barcode);
if(putInResult){
updateShelfInfo(bindedShelf);
log.info("首盘料["+task.getBarcode()+"]使用料架" + rfid +"["+loc+"]缓存更新成功");
return true;
}
}else{
for (ShelfInfo shelfInfo : shelfMap.values()) {
boolean putInResult = shelfInfo.putInLimitLoc(rfid,loc, barcode);
if(putInResult){
updateShelfInfo(shelfInfo);
log.info("首盘料["+task.getBarcode()+"]使用新料架" + rfid +"["+loc+"]缓存更新成功");
return true;
}
}
}
}else{
//非首盘
if(bindedShelf != null){
//已经绑定过
boolean putInResult = bindedShelf.putInLoc(rfid,loc, barcode);
if(putInResult){
updateShelfInfo(bindedShelf);
log.info("物料["+task.getBarcode()+"]使用料架" + rfid +"["+loc+"]缓存更新成功");
return true;
}
}else{
for (ShelfInfo shelfInfo : shelfMap.values()) {
boolean putInResult = shelfInfo.putInLoc(rfid,loc, barcode);
if(putInResult){
updateShelfInfo(shelfInfo);
log.info("物料["+task.getBarcode()+"]使用新料架" + rfid +"["+loc+"]缓存更新成功");
return true;
}
}
}
}
}else{
log.info("未找到["+hSerial+"]相关料架");
}
log.error("物料["+task.getBarcode()+"]("+task.getTempRfid()+"["+task.getAppendInfo().getRfidLoc()+"])料架" + rfid +"["+loc+"]缓存更新失败");
return false;
}
}