RobotController.java
46.4 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
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
package com.huaheng.api.robot.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.api.R;
import com.huaheng.api.general.domain.InventoryQueryDomain;
import com.huaheng.api.robot.domain.RobotInfo;
import com.huaheng.api.robot.service.RobotService;
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.api.wcs.service.emptyOutHandle.EmptyOutHandleService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.container.domain.Container;
import com.huaheng.pc.config.container.service.ContainerService;
import com.huaheng.pc.config.containerType.service.ContainerTypeService;
import com.huaheng.pc.config.location.domain.Location;
import com.huaheng.pc.config.location.domain.LocationStatus;
import com.huaheng.pc.config.location.service.LocationService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.config.station.domain.Station;
import com.huaheng.pc.config.station.service.StationService;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
import com.huaheng.pc.inventory.InventoryMaterialSummary.domain.InventoryMaterialSummary;
import com.huaheng.pc.inventory.InventoryMaterialSummary.service.InventoryMaterialSummaryService;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.inventory.inventoryHeader.domain.InventoryHeader;
import com.huaheng.pc.inventory.inventoryHeader.service.InventoryHeaderService;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.ReceiptTaskService;
import com.huaheng.pc.task.taskHeader.service.ShipmentTaskService;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import com.huaheng.pc.task.taskHeader.service.WorkTaskService;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import javafx.concurrent.Task;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/API/WMS/v2")
public class RobotController extends BaseController {
@Resource
private EmptyOutHandleService emptyOutHandleService;
@Resource
private ZoneService zoneService;
@Resource
private InventoryDetailService inventoryDetailService;
@Resource
private ContainerService containerService;
@Resource
private ContainerTypeService containerTypeService;
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private StationService stationService;
@Resource
private ReceiptTaskService receiptTaskService;
@Resource
private ShipmentTaskService shipmentTaskService;
@Resource
private InventoryHeaderService inventoryHeaderService;
@Resource
private InventoryMaterialSummaryService inventoryMaterialSummaryService;
@Resource
private TaskDetailService taskDetailService;
@Resource
private MaterialService materialService;
@Resource
private RobotService robotService;
@Resource
private LocationService locationService;
@Resource
private WorkTaskService workTaskService;
@PostMapping("/callReceipt")
@ApiOperation("生产入库")
@ApiLogger(apiName = "生产入库", from = "ROBOT")
@ResponseBody
public AjaxResult callReceipt(@RequestBody Map<String, String> map) {
String materialCodePLC = map.get("materialCodePLC");
String orderNo = map.get("orderNo");
String line = map.get("line");
String materialCode = map.get("materialCode");
String qty = map.get("qty");
String area = map.get("area");
String qcc = map.get("qc");
String typee = map.get("type");
int qc = QuantityConstant.QC_NOCHECK;
if(StringUtils.isNotEmpty(qcc)) {
qc = Integer.parseInt(qcc);
}
int type = QuantityConstant.QC_NOCHECK;
if(StringUtils.isNotEmpty(typee)) {
type = Integer.parseInt(typee);
}
if (line == null) {
return AjaxResult.error("没有line");
}
if (materialCode == null) {
return AjaxResult.error("没有materialCode");
}
if (qty == null) {
return AjaxResult.error("没有qty");
}
if (area == null) {
return AjaxResult.error("没有area");
}
if (materialCodePLC == null) {
return AjaxResult.error("没有materialCodePLC");
}
if (orderNo == null) {
return AjaxResult.error("没有orderNo");
}
int materialCodePLCint = Integer.parseInt(materialCodePLC);
int finalQc = qc;
int finalType = type;
AjaxResult ajaxResult = handleMultiProcess(new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
AjaxResult ajaxResult = robotService.innerCallReceipt(line,
materialCode, qty, area, materialCodePLCint, orderNo, finalQc, finalType);
return ajaxResult;
}
});
return ajaxResult;
}
@PostMapping("/callShipment")
@ApiOperation("生产叫料")
@ApiLogger(apiName = "生产叫料", from = "ROBOT")
@ResponseBody
public AjaxResult callShipment(@RequestBody Map<String, String> map) {
String materialCodePLC = map.get("materialCodePLC");
String orderNo = map.get("orderNo");
String line = map.get("line");
String materialCode = map.get("materialCode");
String qty = map.get("qty");
String area = map.get("area");
String qc = map.get("qc");
if (line == null) {
return AjaxResult.error("没有line");
}
if (materialCode == null) {
return AjaxResult.error("没有materialCode");
}
if (qty == null) {
return AjaxResult.error("没有qty");
}
if (area == null) {
return AjaxResult.error("没有area");
}
if (materialCodePLC == null) {
return AjaxResult.error("没有materialCodePLC");
}
if (orderNo == null) {
return AjaxResult.error("没有orderNo");
}
int materialCodePLCint = Integer.parseInt(materialCodePLC);
AjaxResult ajaxResult = handleMultiProcess(new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
AjaxResult ajaxResult = robotService.innerCallShipment(line, materialCode, qty,
area, materialCodePLCint, orderNo);
return ajaxResult;
}
});
return ajaxResult;
}
/**
* 查询托盘库存
*/
@PostMapping("/searchContainerInventory")
@ApiOperation("查询托盘库存")
@ApiLogger(apiName = "查询托盘库存", from = "ROBOT")
@ResponseBody
public AjaxResult searchContainerInventory(@RequestBody InventoryQueryDomain inventoryQueryDomain) {
LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
inventoryDetailLambdaQueryWrapper.eq(StringUtils.isNotEmpty(inventoryQueryDomain.getWarehouseCode()),
InventoryDetail::getWarehouseCode, inventoryQueryDomain.getWarehouseCode())
.eq(StringUtils.isNotEmpty(inventoryQueryDomain.getContainerCode()),
InventoryDetail::getContainerCode, inventoryQueryDomain.getContainerCode())
.eq(StringUtils.isNotEmpty(inventoryQueryDomain.getLocationCode()),
InventoryDetail::getLocationCode, inventoryQueryDomain.getLocationCode())
.eq(StringUtils.isNotEmpty(inventoryQueryDomain.getCompanyCode()),
InventoryDetail::getCompanyCode, inventoryQueryDomain.getCompanyCode())
.eq(StringUtils.isNotEmpty(inventoryQueryDomain.getZoneCode()),
InventoryDetail::getZoneCode, inventoryQueryDomain.getZoneCode())
.eq(StringUtils.isNotEmpty(inventoryQueryDomain.getMaterialCode()),
InventoryDetail::getMaterialCode, inventoryQueryDomain.getMaterialCode());
List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
return AjaxResult.success(inventoryDetailList);
}
/**
* 查询托盘库存
*/
@PostMapping("/searchContainer")
@ApiOperation("查询托盘库存")
@ApiLogger(apiName = "查询托盘库存", from = "ROBOT")
@ResponseBody
public AjaxResult searchContainer(@RequestBody InventoryQueryDomain inventoryQueryDomain) {
LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
inventoryDetailLambdaQueryWrapper.eq(StringUtils.isNotEmpty(inventoryQueryDomain.getWarehouseCode()),
InventoryDetail::getWarehouseCode, inventoryQueryDomain.getWarehouseCode())
.eq(StringUtils.isNotEmpty(inventoryQueryDomain.getContainerCode()),
InventoryDetail::getContainerCode, inventoryQueryDomain.getContainerCode())
.eq(StringUtils.isNotEmpty(inventoryQueryDomain.getLocationCode()),
InventoryDetail::getLocationCode, inventoryQueryDomain.getLocationCode())
.eq(StringUtils.isNotEmpty(inventoryQueryDomain.getCompanyCode()),
InventoryDetail::getCompanyCode, inventoryQueryDomain.getCompanyCode())
.eq(StringUtils.isNotEmpty(inventoryQueryDomain.getZoneCode()),
InventoryDetail::getZoneCode, inventoryQueryDomain.getZoneCode())
.eq(StringUtils.isNotEmpty(inventoryQueryDomain.getMaterialCode()),
InventoryDetail::getMaterialCode, inventoryQueryDomain.getMaterialCode());
List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
List<InventoryDetail> removeInventoryDetailList = new ArrayList<>();
if (inventoryDetailList != null && inventoryDetailList.size() > 0) {
for (InventoryDetail inventoryDetail : inventoryDetailList) {
String zoneCode = inventoryDetail.getZoneCode();
if (zoneCode.equals("H") || zoneCode.equals("I")) {
int taskQty = inventoryDetail.getTaskQty().intValue();
if (taskQty != 0) {
removeInventoryDetailList.add(inventoryDetail);
}
}
}
inventoryDetailList.removeAll(removeInventoryDetailList);
}
return AjaxResult.success(inventoryDetailList);
}
@PostMapping("/back")
@ApiOperation("wcs托盘回库")
@ResponseBody
public AjaxResult back(@RequestBody WcsTask wcsTask) {
AjaxResult ajaxResult = handleMultiProcess(new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
AjaxResult ajaxResult = robotService.innerBack(wcsTask);
return ajaxResult;
}
});
return ajaxResult;
}
/**
* 查询库存
*/
@PostMapping("/searchInventory")
@ApiOperation("查询库存")
@ResponseBody
@ApiLogger(apiName = "查询库存", from = "ROBOT")
public AjaxResult searchInventory(@RequestBody InventoryMaterialSummary inventoryMaterialSummary) {
String area = inventoryMaterialSummary.getArea();
if (StringUtils.isNotEmpty(area)) {
LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
zoneLambdaQueryWrapper.eq(Zone::getArea, area);
Zone zone = zoneService.getOne(zoneLambdaQueryWrapper);
inventoryMaterialSummary.setZoneCode(zone.getCode());
}
LambdaQueryWrapper<InventoryMaterialSummary> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper
.eq(StringUtils.isNotEmpty(inventoryMaterialSummary.getWarehouseCode()),
InventoryMaterialSummary::getWarehouseCode, inventoryMaterialSummary.getWarehouseCode())
//物料编码
.eq(StringUtils.isNotEmpty(inventoryMaterialSummary.getMaterialCode()),
InventoryMaterialSummary::getMaterialCode, inventoryMaterialSummary.getMaterialCode())
//物料名称
.eq(StringUtils.isNotEmpty(inventoryMaterialSummary.getMaterialName()),
InventoryMaterialSummary::getMaterialName, inventoryMaterialSummary.getMaterialName())
.eq(StringUtils.isNotEmpty(inventoryMaterialSummary.getZoneCode()),
InventoryMaterialSummary::getZoneCode, inventoryMaterialSummary.getZoneCode())
.eq(InventoryMaterialSummary::getTaskQty, 0)
//货主
.eq(!StringUtils.isEmpty(inventoryMaterialSummary.getCompanyCode()),
InventoryMaterialSummary::getCompanyCode, inventoryMaterialSummary.getCompanyCode());
List<InventoryMaterialSummary> list = inventoryMaterialSummaryService.list(lambdaQueryWrapper);
if (list == null) {
list = Collections.emptyList();
}
//筛选库存汇总数据的专用方法
List<InventoryMaterialSummary> details = inventoryMaterialSummaryService.duplicateRemoval(list);
return AjaxResult.success(details);
}
/**
* 查询是否满足自动出库
*/
@PostMapping("/searchShipmentTask")
@ApiOperation("查询出库任务")
@ResponseBody
@ApiLogger(apiName = "查询出库任务", from = "ROBOT")
public AjaxResult searchShipmentTask(@RequestBody Map<String, String> map) {
String area = map.get("area");
String line = map.get("line");
if (line == null) {
return AjaxResult.error("没有line");
}
if (area == null) {
return AjaxResult.error("没有area");
}
LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
zoneLambdaQueryWrapper.eq(Zone::getArea,area);
Zone zoneServiceOne = zoneService.getOne(zoneLambdaQueryWrapper);
LambdaQueryWrapper<Station> stationLambdaQueryWrapper = Wrappers.lambdaQuery();
stationLambdaQueryWrapper.eq(Station::getArea, area)
.eq(Station::getLine, line);
List<Station> stationList = stationService.list(stationLambdaQueryWrapper);
if (stationList == null || stationList.size() == 0) {
return AjaxResult.error("区域和线体不正确");
}
List<String> portCodeList = stationList.stream().map(t -> t.getCode()).collect(Collectors.toList());
if (portCodeList == null || portCodeList.size() == 0) {
return AjaxResult.error("线体编码或者区域不正确,没有找到对应出口");
}
if (portCodeList.size() > 1) {
for (String portCode : portCodeList) {
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getPort, portCode)
.eq(TaskHeader::getZoneCode,zoneServiceOne.getCode())
.isNull(TaskHeader::getOrderNo)
.in(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_SORTINGSHIPMENT,
QuantityConstant.TASK_TYPE_WHOLESHIPMENT)
.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
List<TaskHeader> taskHeaders = taskHeaderService.list(taskHeaderLambdaQueryWrapper);
if (taskHeaders != null && !taskHeaders.isEmpty()) {
return AjaxResult.error("还存在手动任务,无法下发自动任务!");
}
}
} else {
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getPort, portCodeList.get(0))
.eq(TaskHeader::getZoneCode,zoneServiceOne.getCode())
.isNull(TaskHeader::getOrderNo)
.in(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_SORTINGSHIPMENT,
QuantityConstant.TASK_TYPE_WHOLESHIPMENT)
.lt(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
List<TaskHeader> taskHeaders = taskHeaderService.list(taskHeaderLambdaQueryWrapper);
if (taskHeaders != null && !taskHeaders.isEmpty()) {
return AjaxResult.error("还存在手动任务,无法下发自动任务!");
}
}
return AjaxResult.success();
}
/**
* 出库抓取信息
*/
@PostMapping("/addShipmentDetail")
@ApiOperation("出库抓取信息")
@ResponseBody
@ApiLogger(apiName = "出库抓取信息", from="ROBOT")
public AjaxResult addShipmentDetail(@RequestBody Map<String,String> map)
{
String containerCode = map.get("containerCode");
String port = map.get("port");
String materialCode = map.get("materialCode");
String qty = map.get("qty");
String sn = map.get("sn");
String isPrint = map.get("isPrint");
String position = map.get("position");
String area = map.get("area");
String qcc = map.get("qc");
if(containerCode == null) {
return AjaxResult.error("没有containerCode");
}
if(port == null) {
return AjaxResult.error("没有port");
}
if(materialCode == null) {
return AjaxResult.error("没有materialCode");
}
if(qty == null) {
return AjaxResult.error("没有qty");
}
if(sn == null) {
return AjaxResult.error("没有sn");
}
if(position == null) {
return AjaxResult.error("没有position");
}
AjaxResult ajaxResult = handleMultiProcess(new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
AjaxResult ajaxResult = robotService.innerAddShipmentDetail(containerCode,
materialCode, port, qty, sn, position, isPrint, area);
return ajaxResult;
}
});
return ajaxResult;
}
/**
* 入库抓取信息
*/
@PostMapping("/addReceiptDetail")
@ApiOperation("入库抓取信息")
@ResponseBody
@ApiLogger(apiName = "入库抓取信息", from="ROBOT")
public AjaxResult addReceiptDetail(@RequestBody Map<String,String> map)
{
String containerCode = map.get("containerCode");
String port = map.get("port");
String materialCode = map.get("materialCode");
String qty = map.get("qty");
String sn = map.get("sn");
String isPrint = map.get("isPrint");
String position = map.get("position");
String area = map.get("area");
String qcc = map.get("qc");
String typee = map.get("type");
int qc = QuantityConstant.QC_NOCHECK;
if(StringUtils.isNotEmpty(qcc)) {
qc = Integer.parseInt(qcc);
}
int type = QuantityConstant.QC_NOCHECK;
if(StringUtils.isNotEmpty(typee)) {
type = Integer.parseInt(typee);
}
if(containerCode == null) {
return AjaxResult.error("没有containerCode");
}
if(port == null) {
return AjaxResult.error("没有port");
}
if(materialCode == null) {
return AjaxResult.error("没有materialCode");
}
if(qty == null) {
return AjaxResult.error("没有qty");
}
if(position == null) {
return AjaxResult.error("没有position");
}
int finalQc = qc;
int finalType = type;
AjaxResult ajaxResult = handleMultiProcess(new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
AjaxResult ajaxResult = robotService.innerAddReceiptDetail(containerCode,
materialCode, port, qty, sn, position, isPrint, area, finalQc, finalType);
return ajaxResult;
}
});
return ajaxResult;
}
/**
* 查询库位列表
*/
@PostMapping("/getAllLocation")
@ApiOperation("查询库位列表")
@ResponseBody
@ApiLogger(apiName = "查询库位列表", from="ROBOT")
public AjaxResult getAllLocation (@RequestBody Map<String,String> map) {
String area = map.get("area");
if(StringUtils.isEmpty(area)) {
return AjaxResult.error("area不能为空");
}
LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
zoneLambdaQueryWrapper.in(Zone::getArea, area);
Zone zone = zoneService.getOne(zoneLambdaQueryWrapper);
String type = zone.getCode();
String warehouseCode = "CS0001";
String row = null, line = null, layer = null;
/* 查询库位信息*/
LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
locationLambdaQueryWrapper.eq(com.huaheng.common.utils.StringUtils.isNotEmpty(row), Location::getIRow, row)
.eq(com.huaheng.common.utils.StringUtils.isNotEmpty(line), Location::getIColumn, line)
.eq(com.huaheng.common.utils.StringUtils.isNotEmpty(layer), Location::getILayer, layer)
.eq(Location::getIGrid, 1) //
.eq(com.huaheng.common.utils.StringUtils.isNotEmpty(type), Location::getLocationType, type)
.eq(Location::getWarehouseCode, warehouseCode)
.eq(com.huaheng.common.utils.StringUtils.isNotEmpty(type), Location::getZoneCode, type);
List<Location> locations = locationService.list(locationLambdaQueryWrapper);
List<Location> locationList = new ArrayList<>();
/* 查询库存明细*/
LambdaQueryWrapper<InventoryDetail> inventoryDetailLambda = Wrappers.lambdaQuery();
inventoryDetailLambda.eq(InventoryDetail::getWarehouseCode, warehouseCode);
List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambda);
for (Location location1 : locations) {
InventoryDetail inventoryDetail = null;
String materialName = null;
for (InventoryDetail inventoryDetail2 : inventoryDetailList) {
if(location1.getCode().equals(inventoryDetail2.getLocationCode())) {
inventoryDetail = inventoryDetail2;
}
}
List<InventoryDetail> inventoryDetails = inventoryDetailList.stream().filter(inventoryDetail1 ->
inventoryDetail1.getLocationCode().equals(location1.getCode())).collect(Collectors.toList());
int userDef3 = 0;
String status = location1.getStatus();
String containerCode = location1.getContainerCode();
List<String> materialNameList = inventoryDetails.stream().map(InventoryDetail::getMaterialName).collect(Collectors.toList());
List<String> batchList = inventoryDetails.stream().map(InventoryDetail::getBatch).collect(Collectors.toList());
List<String> materialCodeList = inventoryDetails.stream().map(InventoryDetail::getMaterialCode).collect(Collectors.toList());
List<BigDecimal> qtyList = inventoryDetails.stream().map(InventoryDetail::getQty).collect(Collectors.toList());
List<String> snList = inventoryDetails.stream().map(InventoryDetail::getSn).collect(Collectors.toList());
String matreialName = null;
String matreialCode = null;
int qty = 0;
if(qtyList != null && qtyList.size() > 0) {
qty = qtyList.size();
}
if(materialCodeList != null && materialCodeList.size() > 0) {
matreialCode = materialCodeList.get(0);
}
if(materialNameList != null && materialNameList.size() > 0) {
matreialName = materialNameList.get(0);
}
if(QuantityConstant.STATUS_LOCATION_EMPTY.equals(status)) {
if(StringUtils.isEmpty(containerCode)) {
userDef3 = LocationStatus.IDLE_EMPTY_LOCATION;
} else {
if(inventoryDetail == null) {
userDef3 = LocationStatus.IDLE_EMPTY_CONTAINER;
location1.setContainerStatus(QuantityConstant.STATUS_CONTAINER_EMPTY);
} else {
location1.setMaterialName2(matreialName);
location1.setMaterialCode2(matreialCode);
location1.setBatch(batchList);
location1.setSnList(snList);
location1.setQty2(qty);
userDef3 = LocationStatus.IDLE_FULL_CONTAINER;
if(StringUtils.isNotEmpty(matreialCode)) {
Material material = materialService.findAllByCode(matreialCode, warehouseCode);
int max = material.getMaxContainer();
if(area.equals("4")) {
max = material.getMax();
}
if(qty < max) {
location1.setContainerStatus(QuantityConstant.STATUS_CONTAINER_SOME);
} else {
location1.setContainerStatus(QuantityConstant.STATUS_CONTAINER_FULL);
}
}
}
}
} else if(QuantityConstant.STATUS_LOCATION_LOCK.equals(status)) {
if(StringUtils.isEmpty(containerCode)) {
userDef3 = LocationStatus.LOCK_EMPTY_LOCATION;
} else {
if(inventoryDetail == null) {
userDef3 = LocationStatus.LOCK_EMPTY_CONTAINER;
location1.setContainerStatus(QuantityConstant.STATUS_CONTAINER_LOCK);
} else {
location1.setMaterialName2(matreialName);
location1.setMaterialCode2(matreialCode);
location1.setBatch(batchList);
location1.setSnList(snList);
location1.setQty2(qty);
userDef3 = LocationStatus.LOCK_FULL_CONTAINER;
if(StringUtils.isNotEmpty(matreialCode)) {
Material material = materialService.findAllByCode(matreialCode, warehouseCode);
int max = material.getMaxContainer();
if(area.equals("4")) {
max = material.getMax();
}
if(qty < max) {
location1.setContainerStatus(QuantityConstant.STATUS_CONTAINER_LOCK);
} else {
location1.setContainerStatus(QuantityConstant.STATUS_CONTAINER_LOCK);
}
}
}
}
}
if(location1.getDeleted()) {
if(StringUtils.isEmpty(containerCode)) {
userDef3 = LocationStatus.DISABLE_EMPTY_LOCATION;
} else {
if(inventoryDetail == null) {
userDef3 = LocationStatus.DISABLE_EMPTY_CONTAINER;
location1.setContainerStatus(QuantityConstant.STATUS_CONTAINER_EMPTY);
} else {
location1.setMaterialName2(matreialName);
location1.setMaterialCode2(matreialCode);
location1.setBatch(batchList);
location1.setSnList(snList);
location1.setQty2(qty);
userDef3 = LocationStatus.DISABLE_FULL_CONTAINER;
if(StringUtils.isNotEmpty(matreialCode)) {
Material material = materialService.findAllByCode(matreialCode, warehouseCode);
int max = material.getMaxContainer();
if(area.equals("4")) {
max = material.getMax();
}
if(qty < max) {
location1.setContainerStatus(QuantityConstant.STATUS_CONTAINER_SOME);
} else {
location1.setContainerStatus(QuantityConstant.STATUS_CONTAINER_FULL);
}
}
}
}
}
location1.setUserDef3(String.valueOf(userDef3));
locationList.add(location1);
}
return AjaxResult.success(locations);
}
/**
* 查询库位列表
*/
@PostMapping("/getAllLocationInPage")
@ApiOperation("查询库位列表")
@ResponseBody
@ApiLogger(apiName = "查询库位列表", from="ROBOT")
public AjaxResult getAllLocationInPage (@RequestBody Map<String,String> map) {
String area = map.get("area");
if(StringUtils.isEmpty(area)) {
return AjaxResult.error("area不能为空");
}
LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
zoneLambdaQueryWrapper.in(Zone::getArea, area);
Zone zone = zoneService.getOne(zoneLambdaQueryWrapper);
String type = zone.getCode();
String warehouseCode = "CS0001";
String row = null, line = null, layer = null;
/* 查询库位信息*/
LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
locationLambdaQueryWrapper.eq(com.huaheng.common.utils.StringUtils.isNotEmpty(row), Location::getIRow, row)
.eq(com.huaheng.common.utils.StringUtils.isNotEmpty(line), Location::getIColumn, line)
.eq(com.huaheng.common.utils.StringUtils.isNotEmpty(layer), Location::getILayer, layer)
.eq(Location::getIGrid, 1) //
.eq(com.huaheng.common.utils.StringUtils.isNotEmpty(type), Location::getLocationType, type)
.eq(Location::getWarehouseCode, warehouseCode)
.eq(com.huaheng.common.utils.StringUtils.isNotEmpty(type), Location::getZoneCode, type);
List<Location> locations = locationService.list(locationLambdaQueryWrapper);
List<Location> locationList = new ArrayList<>();
/* 查询库存明细*/
LambdaQueryWrapper<InventoryDetail> inventoryDetailLambda = Wrappers.lambdaQuery();
inventoryDetailLambda.eq(InventoryDetail::getWarehouseCode, warehouseCode);
List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambda);
for (Location location1 : locations) {
InventoryDetail inventoryDetail = null;
String materialName = null;
for (InventoryDetail inventoryDetail2 : inventoryDetailList) {
if(location1.getCode().equals(inventoryDetail2.getLocationCode())) {
inventoryDetail = inventoryDetail2;
}
}
List<InventoryDetail> inventoryDetails = inventoryDetailList.stream().filter(inventoryDetail1 ->
inventoryDetail1.getLocationCode().equals(location1.getCode())).collect(Collectors.toList());
int userDef3 = 0;
String status = location1.getStatus();
String containerCode = location1.getContainerCode();
List<String> materialNameList = inventoryDetails.stream().map(InventoryDetail::getMaterialName).collect(Collectors.toList());
List<String> batchList = inventoryDetails.stream().map(InventoryDetail::getBatch).collect(Collectors.toList());
List<String> materialCodeList = inventoryDetails.stream().map(InventoryDetail::getMaterialCode).collect(Collectors.toList());
List<BigDecimal> qtyList = inventoryDetails.stream().map(InventoryDetail::getQty).collect(Collectors.toList());
List<String> snList = inventoryDetails.stream().map(InventoryDetail::getSn).collect(Collectors.toList());
String matreialName = null;
String matreialCode = null;
int qty = 0;
if(qtyList != null && qtyList.size() > 0) {
qty = qtyList.size();
}
if(materialCodeList != null && materialCodeList.size() > 0) {
matreialCode = materialCodeList.get(0);
}
if(materialNameList != null && materialNameList.size() > 0) {
matreialName = materialNameList.get(0);
}
if(QuantityConstant.STATUS_LOCATION_EMPTY.equals(status)) {
if(StringUtils.isEmpty(containerCode)) {
userDef3 = LocationStatus.IDLE_EMPTY_LOCATION;
} else {
if(inventoryDetail == null) {
userDef3 = LocationStatus.IDLE_EMPTY_CONTAINER;
location1.setContainerStatus(QuantityConstant.STATUS_CONTAINER_EMPTY);
} else {
location1.setMaterialName2(matreialName);
location1.setMaterialCode2(matreialCode);
location1.setBatch(batchList);
location1.setSnList(snList);
location1.setQty2(qty);
userDef3 = LocationStatus.IDLE_FULL_CONTAINER;
if(StringUtils.isNotEmpty(matreialCode)) {
Material material = materialService.findAllByCode(matreialCode, warehouseCode);
int max = material.getMaxContainer();
if(area.equals("4")) {
max = material.getMax();
}
if(qty < max) {
location1.setContainerStatus(QuantityConstant.STATUS_CONTAINER_SOME);
} else {
location1.setContainerStatus(QuantityConstant.STATUS_CONTAINER_FULL);
}
}
}
}
} else if(QuantityConstant.STATUS_LOCATION_LOCK.equals(status)) {
if(StringUtils.isEmpty(containerCode)) {
userDef3 = LocationStatus.LOCK_EMPTY_LOCATION;
} else {
if(inventoryDetail == null) {
userDef3 = LocationStatus.LOCK_EMPTY_CONTAINER;
location1.setContainerStatus(QuantityConstant.STATUS_CONTAINER_LOCK);
} else {
location1.setMaterialName2(matreialName);
location1.setMaterialCode2(matreialCode);
location1.setBatch(batchList);
location1.setSnList(snList);
location1.setQty2(qty);
userDef3 = LocationStatus.LOCK_FULL_CONTAINER;
if(StringUtils.isNotEmpty(matreialCode)) {
Material material = materialService.findAllByCode(matreialCode, warehouseCode);
int max = material.getMaxContainer();
if(area.equals("4")) {
max = material.getMax();
}
if(qty < max) {
location1.setContainerStatus(QuantityConstant.STATUS_CONTAINER_LOCK);
} else {
location1.setContainerStatus(QuantityConstant.STATUS_CONTAINER_LOCK);
}
}
}
}
}
if(location1.getDeleted()) {
if(StringUtils.isEmpty(containerCode)) {
userDef3 = LocationStatus.DISABLE_EMPTY_LOCATION;
} else {
if(inventoryDetail == null) {
userDef3 = LocationStatus.DISABLE_EMPTY_CONTAINER;
location1.setContainerStatus(QuantityConstant.STATUS_CONTAINER_EMPTY);
} else {
location1.setMaterialName2(matreialName);
location1.setMaterialCode2(matreialCode);
location1.setBatch(batchList);
location1.setSnList(snList);
location1.setQty2(qty);
userDef3 = LocationStatus.DISABLE_FULL_CONTAINER;
if(StringUtils.isNotEmpty(matreialCode)) {
Material material = materialService.findAllByCode(matreialCode, warehouseCode);
int max = material.getMaxContainer();
if(area.equals("4")) {
max = material.getMax();
}
if(qty < max) {
location1.setContainerStatus(QuantityConstant.STATUS_CONTAINER_SOME);
} else {
location1.setContainerStatus(QuantityConstant.STATUS_CONTAINER_FULL);
}
}
}
}
}
location1.setUserDef3(String.valueOf(userDef3));
locationList.add(location1);
}
return AjaxResult.success(locations);
}
/**
* agv入库
*/
@PostMapping("/agvReceipt")
@ApiOperation("agv入库")
@ResponseBody
@ApiLogger(apiName = "agv入库", from="ROBOT")
public AjaxResult agvReceipt (@RequestBody Map<String,String> map) {
String area = map.get("area");
String type = map.get("type");
String containerCode = map.get("containerCode");
String qty = map.get("qty");
String materialCode = map.get("materialCode");
String taskIndex = map.get("taskIndex");
if(containerCode == null) {
return AjaxResult.error("没有containerCode");
}
if(area == null) {
return AjaxResult.error("没有area");
}
if(type == null) {
return AjaxResult.error("没有type");
}
int areaInt = Integer.parseInt(area);
if(areaInt != 4) {
return AjaxResult.error("AGV只有4号区");
}
AjaxResult ajaxResult = workTaskService.createEmptyIn(containerCode, null);
if(!ajaxResult.hasErr()) {
String taskId = (String)ajaxResult.getData();
TaskHeader taskHeader = taskHeaderService.getById(taskId);
if(taskHeader != null) {
taskHeader.setTaskIndex(taskIndex);
}
taskHeaderService.updateById(taskHeader);
ajaxResult.setData("P5001");
}
return ajaxResult;
}
/**
* agv出库
*/
@PostMapping("/agvShipment")
@ApiOperation("agv出库")
@ResponseBody
@ApiLogger(apiName = "agv出库", from="ROBOT")
public AjaxResult agvShipment (@RequestBody Map<String,Object> map) {
String area = String.valueOf( (Integer) map.get("area"));
String type =String.valueOf( (Integer) map.get("type"));
List<String> containerCodeList = (List<String>) map.get("containerCodeList");
// String stationCode = (String) map.get("stationCode");
String taskIndex = (String) map.get("taskIndex");
if(containerCodeList == null) {
return AjaxResult.error("没有containerCodeList");
}
if(area == null) {
return AjaxResult.error("没有area");
}
if(type == null) {
return AjaxResult.error("没有type");
}
// if(stationCode == null) {
// return AjaxResult.error("没有stationCode");
// }
if(taskIndex == null) {
return AjaxResult.error("没有taskIndex");
}
AjaxResult ajaxResult = null;
int areaInt = Integer.parseInt(area);
if(areaInt != 4) {
return AjaxResult.error("AGV只有4号区");
}
String stationCode = "P15001";
for(String containerCode : containerCodeList) {
String line = "15001";
String warehouseCode = "CS0001";
Container container = containerService.getContainerByCode(containerCode, warehouseCode);
String locationCode = container.getLocationCode();
String orderNo = "AGV";
int materialCodePlc = 0;
String materialCode = null;
LambdaQueryWrapper<InventoryDetail> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
inventoryDetailLambdaQueryWrapper.eq(InventoryDetail::getContainerCode, containerCode)
.eq(InventoryDetail::getTaskQty, 0);
List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambdaQueryWrapper);
if (inventoryDetailList != null && inventoryDetailList.size() > 0) {
InventoryDetail inventoryDetail = inventoryDetailList.get(0);
materialCode = inventoryDetail.getMaterialCode();
} else {
return AjaxResult.error("没有找到库存");
}
ajaxResult = shipmentTaskService.createWholeShipmentTask(containerCode, locationCode, materialCode,
warehouseCode, stationCode, materialCodePlc, orderNo, line, 1);
if (!ajaxResult.hasErr()) {
Integer taskId = (Integer) ajaxResult.getData();
TaskHeader taskHeader = taskHeaderService.getById(taskId);
if (taskHeader != null) {
taskHeader.setTaskIndex(taskIndex);
}
taskHeaderService.updateById(taskHeader);
ajaxResult.setData("P1501");
}
}
return ajaxResult;
}
/**
* 查询最近的一条记录
*/
@GetMapping("/list")
@ApiOperation("查询最近的一条记录")
@ResponseBody
@ApiLogger(apiName = "查询最近的一条记录", from="ROBOT")
public AjaxResult search (@RequestBody Map<String, String> map) {
String warehouseCode = "CS0001";
List<String> areaList = new ArrayList<>();
areaList.add("1");
areaList.add("2");
areaList.add("3");
areaList.add("4");
areaList.add("5");
areaList.add("6");
areaList.add("7");
areaList.add("8");
areaList.add("9");
List<RobotInfo> robotInfoList = new ArrayList<>();
for(String area : areaList) {
LambdaQueryWrapper<Zone> zoneLambdaQueryWrapper = Wrappers.lambdaQuery();
zoneLambdaQueryWrapper.eq(Zone::getArea, area)
.eq(Zone::getWarehouseCode, warehouseCode);
Zone zone = zoneService.getOne(zoneLambdaQueryWrapper);
LambdaQueryWrapper<Container> containerEmptyLambdaQueryWrapper = Wrappers.lambdaQuery();
containerEmptyLambdaQueryWrapper.eq(Container::getArea, area)
.eq(Container::getStatus, QuantityConstant.STATUS_CONTAINER_EMPTY)
.ne(Container::getLocationCode, "");
List<Container> containerEmptyList = containerService.list(containerEmptyLambdaQueryWrapper);
int containerEmptySize = containerEmptyList.size();
LambdaQueryWrapper<InventoryHeader> inventoryHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
inventoryHeaderLambdaQueryWrapper.eq(InventoryHeader::getZoneCode, zone.getCode());
List<InventoryHeader> inventoryHeaderList = inventoryHeaderService.list(inventoryHeaderLambdaQueryWrapper);
int containerSomeSize = inventoryHeaderList.size();
LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery();
locationLambdaQueryWrapper.eq(Location::getArea, area);
List<Location> totalLocation = locationService.list(locationLambdaQueryWrapper);
RobotInfo robotInfo = new RobotInfo();
//总库位
int allLocation = totalLocation.size();
robotInfo.setEmptyLocation(allLocation - containerSomeSize);
robotInfo.setSomeLocation(containerSomeSize);
robotInfo.setArea(Integer.parseInt(area));
//库位利用率
robotInfo.setStorageUtilization(((float) containerSomeSize / (float) allLocation) * 100 + "%");
LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery();
taskHeaderLambdaQueryWrapper.eq(TaskHeader::getArea, area)
.orderByAsc(TaskHeader::getStatus)
.orderByDesc(TaskHeader::getId)
.eq(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED);
List<TaskHeader> list = taskHeaderService.list(taskHeaderLambdaQueryWrapper);
TaskHeader taskHeader = list.get(0);
Integer id = taskHeader.getId();
Date created = taskHeader.getCreated();
Date lastUpdated = taskHeader.getLastUpdated();
robotInfo.setTaskId(id);
robotInfo.setTaskStartTime(created);
robotInfo.setTaskEndTime(lastUpdated);
LambdaQueryWrapper<TaskDetail> taskDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
taskDetailLambdaQueryWrapper.eq(TaskDetail::getTaskId, id);
List<TaskDetail> taskDetailList = taskDetailService.list(taskDetailLambdaQueryWrapper);
if (taskDetailList.size() > 0) {
TaskDetail taskDetail = taskDetailList.get(0);
robotInfo.setMaterialName(taskDetail.getMaterialName());
robotInfo.setMaterialCode(taskDetail.getMaterialCode());
robotInfo.setQty(taskDetailList.size());
}
robotInfoList.add(robotInfo);
}
return AjaxResult.success(robotInfoList);
}
}