ICSShipmentApiService.java
38.9 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
package com.huaheng.pc.u8.service;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.api.general.domain.ShipmentDomain;
import com.huaheng.api.general.service.ShipmentApiService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.DateUtils;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.Wrappers;
import com.huaheng.common.utils.http.HttpUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.config.company.domain.CompanyU8;
import com.huaheng.pc.config.company.service.CompanyU8Service;
import com.huaheng.pc.config.documentWarning.service.IDocumentWarningService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.config.warehouse.domain.WarehouseU8;
import com.huaheng.pc.config.warehouse.service.WarehouseU8Service;
import com.huaheng.pc.shipment.shipmentContainerDetail.domain.ShipmentContainerDetail;
import com.huaheng.pc.shipment.shipmentContainerDetail.service.ShipmentContainerDetailService;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
import com.huaheng.pc.system.user.domain.User;
import com.huaheng.pc.system.user.service.IUserService;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.u8.domain.ICSShipmentDetail;
import com.huaheng.pc.u8.domain.ICSShipmentHeader;
import com.huaheng.pc.u8.domain.ICSShipmentModel;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.text.ParseException;
import java.util.*;
import java.util.stream.Collectors;
@Service
public class ICSShipmentApiService {
@Resource
private IDocumentWarningService documentWarningService;
@Resource
private WarehouseU8Service warehouseU8Service;
@Resource
private ShipmentApiService shipmentApiService;
@Resource
private MaterialService materialService;
@Resource
private ICSShipmentDetailService icsShipmentDetailService;
@Resource
private ICSShipmentHeaderService icsShipmentHeaderService;
@Resource
private ShipmentHeaderService shipmentHeaderService;
@Resource
private ShipmentDetailService shipmentDetailService;
@Resource
private ShipmentContainerDetailService shipmentContainerDetailService;
@Resource
private TaskDetailService taskDetailService;
@Resource
private CompanyU8Service companyU8Service;
@Resource
private ICSReceiptAPIService icsReceiptAPIService;
@Resource
private IUserService userService;
//u8-wms出库下发
@Transactional
public AjaxResult procureShipment(ICSShipmentModel icsShipmentModel){
//获取主单和子单列
ICSShipmentHeader icsShipmentHeader=icsShipmentModel.getIcsShipmentHeader();
List<ICSShipmentDetail> icsShipmentDetails=icsShipmentModel.getIcsShipmentDetails();
String type = icsShipmentHeader.getType();
switch (type){
case "QO" :
case "MO" :
case "OO" :
case "PKO" :
case "TO" :
break;
default:
return AjaxResult.error("出库类型不匹配");
}
if(StringUtils.isEmpty(icsShipmentHeader.getIsNew())){
return AjaxResult.error("isNew为空");
}
Date date = null;
try {
date = DateUtils.parseDate(icsShipmentHeader.getDDate(), DateUtils.YYYY_MM_DD_HH_MM_SS);
} catch (ParseException e) {
e.printStackTrace();
}
//根据icsShipmentHeader生成shipmentHeader
ShipmentHeader shipmentHeader=new ShipmentHeader();
String warehouseCode=null;
switch (type){
case "PKO" :
case "TO" :
return AjaxResult.success("出库单下发成功");
case "OO" :
warehouseCode = "20";
break;
default:
warehouseCode = icsShipmentHeader.getCWHCode();
break;
}
if (StringUtils.isEmpty(warehouseCode)) {
if(icsShipmentHeader.getCCode()!= null) {
documentWarningService.ErpSendWarning(icsShipmentHeader.getCCode(), "仓库编码不存在");
}else {
documentWarningService.ErpSendWarning(icsShipmentHeader.getCTVCode(), "仓库编码不存在");
}
return AjaxResult.error("仓库编码为空");
}
//通过u8的货主和仓库匹配wms的仓库
WarehouseU8 warehouseU8 = warehouseU8Service.getOne(new LambdaQueryWrapper<WarehouseU8>()
.eq(WarehouseU8::getUCompanyCode, icsShipmentHeader.getCompanyCode())
.eq(WarehouseU8::getUWarehouseCode, warehouseCode));
if (warehouseU8 == null) {
return AjaxResult.error("系统没有此仓库");
}
String maker = icsShipmentHeader.getCMaker();
shipmentHeader.setShipmentType(type);
shipmentHeader.setId(null);
shipmentHeader.setLastUpdatedBy(maker);
shipmentHeader.setCreatedBy(maker);
shipmentHeader.setCreated(date);
shipmentHeader.setLastUpdated(date);
shipmentHeader.setCustomerCode(icsShipmentHeader.getCCusCode());
shipmentHeader.setShipmentNote(icsShipmentHeader.getCMemo());
shipmentHeader.setWarehouseCode(warehouseU8.getWarehouseCode());
shipmentHeader.setUWarehouseCode(warehouseCode);
shipmentHeader.setCompanyCode(warehouseU8.getCompanyCode());
// shipmentHeader.setcDepName(icsShipmentHeader.getcDepName());
switch (type){
case "OO" :
shipmentHeader.setReferCode(icsShipmentHeader.getMoCode());
break;
case "TO" :
shipmentHeader.setReferCode(icsShipmentHeader.getCTVCode());
break;
default:
shipmentHeader.setReferCode(icsShipmentHeader.getCCode());
break;
}
if (StringUtils.isEmpty(shipmentHeader.getReferCode())) {
documentWarningService.ErpSendWarning("", "没有单号");
throw new ServiceException("没有单号");
}
checkShipmentBill(icsShipmentHeader,shipmentHeader.getReferCode());
//将主表插入到新的接收主表里去
boolean save = icsShipmentHeaderService.save(icsShipmentHeader);
if (!save) {
documentWarningService.ErpSendWarning(shipmentHeader.getReferCode(), "出库主单传输失败");
throw new ServiceException("出库主单传输失败!");
}
//将子表插入到新的接收子表里去
for (ICSShipmentDetail item : icsShipmentDetails) {
if ("PKO".equals(icsShipmentHeader.getType())) {
item.setCCode(icsShipmentHeader.getCTVCode());
} else {
item.setCCode(icsShipmentHeader.getCCode());
}
boolean save1 = icsShipmentDetailService.save(item);
if (!save1) {
documentWarningService.ErpSendWarning(shipmentHeader.getReferCode(), "出库子单传输失败");
throw new ServiceException("出库子单传输失败!");
}
}
//根据icsShipmentDetail生成shipmentAetail
List<ShipmentDetail> shipmentDetails = new ArrayList<ShipmentDetail>();
for (ICSShipmentDetail icsShipmentDetail : icsShipmentDetails) {
//查找物料
Material material = materialService.getOne(new LambdaQueryWrapper<Material>()
.eq(Material::getCode, icsShipmentDetail.getCInvCode())
.eq(Material::getCode, warehouseU8.getWarehouseCode()));
if (material == null) {
documentWarningService.ErpSendWarning(shipmentHeader.getReferCode(), "该物料不存在:" + icsShipmentDetail.getCInvCode());
throw new ServiceException("该物料不存在:" + icsShipmentDetail.getCInvCode());
}
ShipmentDetail shipmentDetail = new ShipmentDetail();
shipmentDetail.setId(null);
shipmentDetail.setReferCode(shipmentHeader.getReferCode());
shipmentDetail.setMoCode(icsShipmentDetail.getMoCode());
shipmentDetail.setLot(icsShipmentDetail.getCDefine23());
// shipmentDetail.setAutoId(icsShipmentDetail.getAutoID());
shipmentDetail.setWarehouseCode(warehouseU8.getWarehouseCode());
shipmentDetail.setMaterialCode(icsShipmentDetail.getCInvCode());
// shipmentDetail.setZoneCode(material.getZoneCode());
shipmentDetail.setCreated(date);
// shipmentDetail.setUWarehouseCode(shipmentHeader.getUWarehouseCode());
shipmentDetail.setMaterialUnit(icsShipmentDetail.getCComUnitName());
shipmentDetail.setCreatedBy(maker);
shipmentDetail.setLastUpdated(date);
shipmentDetail.setLastUpdatedBy(maker);
if (!icsShipmentDetail.getCompanyCode().equals(icsShipmentHeader.getCompanyCode())) {
documentWarningService.ErpSendWarning(shipmentHeader.getReferCode(), "子单货主与主单不对应");
throw new ServiceException("子单货主与主单不对应");
}
shipmentDetail.setCompanyCode(warehouseU8.getCompanyCode());
shipmentDetail.setProjectNo(icsShipmentDetail.getCItemName());
shipmentDetail.setQty((icsShipmentDetail.getIQuantity()).abs());
shipmentDetail.setQtyCompleted(icsShipmentDetail.getIQuantity());
shipmentDetail.setInventorySts("good");
if (icsShipmentDetail.getIrowno() != null && StringUtils.isNotEmpty(icsShipmentDetail.getIrowno().toString())) {
shipmentDetail.setReferLineNum(icsShipmentDetail.getIrowno().toString());
}
if (icsShipmentDetail.getSortSeq() != null && StringUtils.isNotEmpty(icsShipmentDetail.getSortSeq().toString())) {
shipmentDetail.setReferLineNum(icsShipmentDetail.getSortSeq().toString());
}
shipmentDetails.add(shipmentDetail);
}
//调用公共API
ShipmentDomain shipmentDomain = new ShipmentDomain();
shipmentDomain.setShipmentHeader(shipmentHeader);
shipmentDomain.setShipmentDetails(shipmentDetails);
AjaxResult ajaxResult = shipmentApiService.shipment(shipmentDomain);
if(ajaxResult.hasErr()){
return ajaxResult;
}
if(icsShipmentHeader.getIsNew().equals("1")){
return AjaxResult.success("出库单下发成功");
}else if (icsShipmentHeader.getIsNew().equals("0")) {
return AjaxResult.success("出库单更新成功");
}
return AjaxResult.success("出库单下发成功");
}
//出库单为销售出库或采购退货单时
/**
* 出库单为 销售出库单 | 采购退货单
* @param icsShipmentModel
* @return
*/
@Transactional
public AjaxResult saleShipmentOrPurchReturn(ICSShipmentModel icsShipmentModel){
ICSShipmentHeader icsShipmentHeader=icsShipmentModel.getIcsShipmentHeader();
List<ICSShipmentDetail> icsShipmentDetails=icsShipmentModel.getIcsShipmentDetails();
if(!icsShipmentHeader.getType().equals("SO") && !icsShipmentHeader.getType().equals("PRO")){
return AjaxResult.error("出库类型不匹配");
}
if(StringUtils.isEmpty(icsShipmentHeader.getIsNew())){
throw new ServiceException("isNew为空");
}
String code=null;
if(icsShipmentHeader.getType().equals("SO")) {
code=icsShipmentHeader.getCDLCode();
}else {
code=icsShipmentHeader.getCCode();
}
if(StringUtils.isEmpty(code)){
documentWarningService.ErpSendWarning("", "没有单号");
throw new ServiceException("没有单号");
}
CompanyU8 companyWu = companyU8Service.getOne(new LambdaQueryWrapper<CompanyU8>()
.eq(CompanyU8::getUCompanyCode, icsShipmentHeader.getCompanyCode()));
if(companyWu == null){
return AjaxResult.error("单据货主不存在"+icsShipmentHeader.getCompanyCode());
}
//判断出库单是否可以更新
checkShipmentBill(icsShipmentHeader,code);
Date date = null;
try {
date = DateUtils.parseDate(icsShipmentHeader.getDPODate(), DateUtils.YYYY_MM_DD_HH_MM_SS);
} catch (ParseException e) {
e.printStackTrace();
}
String companyCode=null;
//判断仓库是否存在单据的物料编码
ShipmentHeader shipmentHeader;
List<ShipmentDetail> shipmentDetails;
Set<String> warehouseCodes=new HashSet<>();
Set<String> uwarehouseCodes = new HashSet<>();
for(ICSShipmentDetail item:icsShipmentDetails){
//通过u8的货主和仓库匹配wms的仓库
WarehouseU8 warehouseU8 = warehouseU8Service.getOne(new LambdaQueryWrapper<WarehouseU8>()
.eq(WarehouseU8::getUCompanyCode, item.getCompanyCode())
.eq(WarehouseU8::getUWarehouseCode, item.getCWHCode()));
if(warehouseU8!=null){
companyCode=warehouseU8.getCompanyCode();
uwarehouseCodes.add(item.getCWHCode());
warehouseCodes.add(warehouseU8.getWarehouseCode());
}
}
if(uwarehouseCodes == null || uwarehouseCodes.size()<1){
return AjaxResult.success("没有此仓库");
}
//将主表插入到新的接收主表里去
boolean save = icsShipmentHeaderService.save(icsShipmentHeader);
if(!save){
documentWarningService.ErpSendWarning(code, "出库主单传输失败!");
throw new ServiceException("出库主单传输失败!");
}
//将子表插入到新的接收子表里去
for(ICSShipmentDetail item : icsShipmentDetails){
item.setCCode(code);
boolean save1 = icsShipmentDetailService.save(item);
if(!save1){
documentWarningService.ErpSendWarning(code, "出库主单传输失败!");
throw new ServiceException("出库子单传输失败!");
}
}
String maker = icsShipmentHeader.getCMaker();
for (String warehouseCode : warehouseCodes) {
for (String uwarehouseCode : uwarehouseCodes) {
shipmentDetails = new ArrayList<>();
//出库主单
shipmentHeader = new ShipmentHeader();
shipmentHeader.setShipmentType(icsShipmentHeader.getType());
shipmentHeader.setId(null);
if(StringUtils.isNotEmpty(icsShipmentHeader.getFromCompanyCode())){
shipmentHeader.setUserDef3("跨账套");
}
shipmentHeader.setLastUpdatedBy(maker);
shipmentHeader.setCreatedBy(maker);
shipmentHeader.setCreated(date);
shipmentHeader.setCustomerCode(icsShipmentHeader.getCCusCode());
shipmentHeader.setLastUpdated(date);
shipmentHeader.setReferCode(code);
shipmentHeader.setCreatedBy(icsShipmentHeader.getCMemo());
shipmentHeader.setWarehouseCode(warehouseCode);
shipmentHeader.setUWarehouseCode(uwarehouseCode);
shipmentHeader.setCompanyCode(companyCode);
// shipmentHeader.setcDepName(icsShipmentHeader.getcDepName());
//销售单向wms主单存入发货信息和收货信息
// if(StringUtils.isNotEmpty(icsShipmentHeader.getcSCName())) {
// if (icsShipmentHeader.getcSCName().equals("快递") && StringUtils.isNotEmpty(icsShipmentHeader.getRecName())) {
// shipmentHeader.setRecName(icsShipmentHeader.getRecName());
// shipmentHeader.setRecMobile(icsShipmentHeader.getRecMobile());
// shipmentHeader.setRecCompany(icsShipmentHeader.getRecCompany());
// shipmentHeader.setRecAddr(icsShipmentHeader.getRecAddr());
// shipmentHeader.setSendName(icsShipmentHeader.getSendName());
// shipmentHeader.setSendMobile(icsShipmentHeader.getSendMobile());
// shipmentHeader.setSendCompany(icsShipmentHeader.getSendCompany());
// shipmentHeader.setSendAddr(icsShipmentHeader.getSendAddr());
// shipmentHeader.setKdEable(1);
// }
// }
//细单
for (ICSShipmentDetail item : icsShipmentDetails) {
//匹配仓库
if (uwarehouseCode.equals(item.getCWHCode())) {
//查找物料
Material material = materialService.getOne(new LambdaQueryWrapper<Material>()
.eq(Material::getCode, item.getCInvCode())
.eq(Material::getWarehouseCode, warehouseCode));
if(material==null){
documentWarningService.ErpSendWarning(code, "该物料不存在:"+item.getCInvCode());
throw new ServiceException("该物料不存在:"+item.getCInvCode());
}
ShipmentDetail shipmentDetail = new ShipmentDetail();
shipmentDetail.setId(null);
shipmentDetail.setReferCode(code);
// shipmentDetail.setAutoId(item.getAutoID());
shipmentDetail.setWarehouseCode(warehouseCode);
shipmentDetail.setMaterialCode(item.getCInvCode());
shipmentDetail.setZoneCode(material.getZoneCode());
shipmentDetail.setCreated(date);
shipmentDetail.setUWarehouseCode(uwarehouseCode);
shipmentDetail.setCreatedBy(maker);
shipmentDetail.setMaterialSpec(item.getCComUnitName());
shipmentDetail.setLastUpdated(date);
shipmentDetail.setLastUpdatedBy(maker);
if (!item.getCompanyCode().equals(icsShipmentHeader.getCompanyCode())) {
documentWarningService.ErpSendWarning(code, "子单货主与主单不对应");
throw new ServiceException("子单货主与主单不对应");
}
if(icsShipmentHeader.getType().equals("SO")) {
shipmentDetail.setCPoCode(item.getCSOCode());
}else {
shipmentDetail.setCPoCode(item.getPOCode());
}
shipmentDetail.setMoCode(item.getCDefine22());
shipmentDetail.setLot(item.getCDefine23());
shipmentDetail.setCompanyCode(companyCode);
shipmentDetail.setProjectNo(item.getCItemName());
shipmentDetail.setQty((item.getIQuantity()).abs());
// shipmentDetail.setQtyCompleted(item.getiQuantity());
shipmentDetail.setInventorySts(QuantityConstant.GOOD);
shipmentDetails.add(shipmentDetail);
}
}
//调用公共API
ShipmentDomain shipmentDomain = new ShipmentDomain();
shipmentDomain.setShipmentHeader(shipmentHeader);
shipmentDomain.setShipmentDetails(shipmentDetails);
AjaxResult ajaxResult = shipmentApiService.shipment(shipmentDomain);
if(ajaxResult.hasErr()){
return ajaxResult;
}
String isNew = icsShipmentHeader.getIsNew();
if("1".equals(isNew)){
return AjaxResult.success("出库单下发成功");
}else if ("0".equals(isNew)) {
return AjaxResult.success("出库单更新成功");
}else {
return ajaxResult;
}
}
}
return AjaxResult.success("下发成功");
}
//wms-u8出库回传
/**
* 出库单回传
* @param url
* @param status
* @return
*/
@Transactional
public AjaxResult shipmentReturn(String url, Integer status) {
//找出所有首状态为1000的出库单
List<ShipmentHeader> shipmentHeaders = shipmentHeaderService.list(new LambdaQueryWrapper<ShipmentHeader>()
.lt(ShipmentHeader::getFirstStatus, 1000));
//获取code集合
List<String> codeList = shipmentHeaders.stream().map(ShipmentHeader::getCode).collect(Collectors.toList());
//先找出处于完成状态的taskDetail
List<TaskDetail> taskDetails = taskDetailService.list(new LambdaQueryWrapper<TaskDetail>()
.eq(TaskDetail::getStatus, status)
.eq(TaskDetail::getInternalTaskType, QuantityConstant.SHIPMENT_CONTAINER_FINISHED)
.in(TaskDetail::getBillCode,codeList));
if(taskDetails==null || taskDetails.size()<1){
return AjaxResult.success("没有完成状态的子任务");
}
Set<String> billCodes = new HashSet<>();
final List<String> collect = taskDetails.stream().map(t -> t.getBillCode()).distinct().collect(Collectors.toList());
for(TaskDetail taskDetail:taskDetails) {
ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(new LambdaQueryWrapper<ShipmentHeader>()
.eq(ShipmentHeader::getCode, taskDetail.getBillCode()));
if(shipmentHeader==null){
continue;
}
if(shipmentHeader!=null && shipmentHeader.getFirstStatus()== 1000){
continue;
}
shipmentHeader.setFirstStatus(1000);
//更新状态为1000
shipmentHeaderService.updateById(shipmentHeader);
//修改任务明细状态
taskDetail.setStatus(200);
taskDetailService.updateById(taskDetail);
}
return AjaxResult.success();
}
@Transactional
public AjaxResult ConfirmShipment(TaskDetail taskDetail,String url,Integer status){
String currentWarehouseCode = taskDetail.getWarehouseCode();
AjaxResult ajaxResult=new AjaxResult();
//根据子任务查找主单
ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(new LambdaQueryWrapper<ShipmentHeader>()
.eq(ShipmentHeader::getCode, taskDetail.getBillCode()));
if(shipmentHeader==null){
taskDetail.setStatus(QuantityConstant.TASK_STATUS_REMOVE);
taskDetailService.updateById(taskDetail);
return AjaxResult.success("出库单已删除");
}
//查找相同单号的状态为100的子任务
List<TaskDetail> taskDetails = taskDetailService.list(new LambdaQueryWrapper<TaskDetail>()
.eq(TaskDetail::getStatus, status)
.eq(TaskDetail::getBillCode, shipmentHeader.getCode()));
if(taskDetails ==null || taskDetails.size()<1){
return AjaxResult.success("已完成");
}
//查找相同单号状态为10的子任务
List<TaskDetail> taskDetailList = taskDetailService.list(new LambdaQueryWrapper<TaskDetail>()
.eq(TaskDetail::getStatus, QuantityConstant.TASK_STATUS_RELEASE)
.eq(TaskDetail::getBillCode, shipmentHeader.getCode()));
if(taskDetailList!=null && taskDetailList.size()>0){
return AjaxResult.success("该单据还有任务未完成,请先完成该单据的任务");
}
String type=shipmentHeader.getShipmentType();
String code=shipmentHeader.getReferCode();
if (!type.equals("PRO") && !type.equals("MO") && !type.equals("QO") && !type.equals("SO") ) {
for(TaskDetail item :taskDetails) {
item.setStatus(110);
taskDetailService.updateById(item);
}
if (shipmentHeader.getFirstStatus() == 300 && shipmentHeader.getLastStatus() == 300) {
shipmentHeaderService.removeShipmentByHeaderId(shipmentHeader.getId());
}
return AjaxResult.success("该子任务所属单据无需上传");
}
//根据子任务查找子单
Set<String> uwarehouseCodes = new HashSet<>();
List<ShipmentDetail> shipmentDetails=new ArrayList<>();
Integer number =0;
for(TaskDetail item:taskDetails) {
ShipmentDetail shipmentDetail = shipmentDetailService.getById(item.getBillDetailId());
if (shipmentDetails != null && shipmentDetails.size() > 0) {
for (ShipmentDetail detail1 : shipmentDetails) {
if (shipmentDetail.getId() == detail1.getId()) {
detail1.setTaskQty(detail1.getTaskQty().add(item.getQty()));
number=1;
break;
}
}
}
if(number == 0) {
shipmentDetail.setTaskQty(item.getQty());
shipmentDetails.add(shipmentDetail);
uwarehouseCodes.add(shipmentDetail.getUWarehouseCode());
}
number=0;
}
Iterator<String> iterator=uwarehouseCodes.iterator();
String uWarehouseCode=iterator.next();
CompanyU8 companyWu = companyU8Service.getOne(new LambdaQueryWrapper<CompanyU8>()
.eq(CompanyU8::getCompanyCode, shipmentHeader.getCompanyCode()));
boolean isSameDate = icsReceiptAPIService.isSameMonth(taskDetail.getLastUpdated());
if(isSameDate == false){
for(TaskDetail item: taskDetails) {
item.setStatus(180);
taskDetailService.updateById(item);
}
documentWarningService.ErpReturnWarning(shipmentHeader.getCode(), shipmentHeader.getReferCode(),
"回传超时" + shipmentHeader.getUserDef2());
return AjaxResult.success("取消回传");
}
List<ICSShipmentDetail> icsShipmentDetails=new ArrayList<ICSShipmentDetail>();
String dt = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS_S,taskDetail.getLastUpdated());
String userName =taskDetail.getLastUpdatedBy();
User user =new User();
user = userService.selectUserByLoginName(userName);
if(user != null){
userName = user.getUserName();
}
ICSShipmentHeader icsShipmentHeader= null;
//出库类型为采购的主单和子单
switch (type){
case "PRO":
icsShipmentHeader = icsShipmentHeaderService.getOne(new LambdaQueryWrapper<ICSShipmentHeader>()
.eq(ICSShipmentHeader::getCCode, code)
.eq(ICSShipmentHeader::getCompanyCode, companyWu.getUCompanyCode()));
icsShipmentHeader.setDPODate(dt);
icsShipmentHeader.setCWHCode(uWarehouseCode);
icsShipmentHeader.setCMaker(userName);
icsShipmentHeader.setID(shipmentHeader.getId());
icsShipmentHeader.setVoucherType("CreateICSRdRecord_01_Return");
//子单
for(ShipmentDetail item:shipmentDetails) {
if (uWarehouseCode.equals(item.getUWarehouseCode())) {
ICSShipmentDetail icsShipmentDetail = icsShipmentDetailService.getOne(new LambdaQueryWrapper<ICSShipmentDetail>()
.eq(ICSShipmentDetail::getCCode, code)
.eq(ICSShipmentDetail::getCompanyCode, companyWu.getUCompanyCode())
.eq(ICSShipmentDetail::getCInvCode, item.getMaterialCode()));
icsShipmentDetail.setID(item.getId());
icsShipmentDetail.setIArrsId(icsShipmentDetail.getAutoID());
icsShipmentDetail.setIPOsID(icsShipmentDetail.getPODID());
icsShipmentDetail.setIQuantity(item.getQtyCompleted().negate());
icsShipmentDetails.add(icsShipmentDetail);
}
}
break;
case "MO":
icsShipmentHeader.setVoucherType("UpdateICSRdRecord_11_Confirm");
case "QO":
//出库类型为材料或其他的主单和子单
icsShipmentHeader = icsShipmentHeaderService.getOne(new LambdaQueryWrapper<ICSShipmentHeader>()
.eq(ICSShipmentHeader::getCCode, code)
.eq(ICSShipmentHeader::getCWHCode, shipmentHeader.getUWarehouseCode())
.eq(ICSShipmentHeader::getCompanyCode, companyWu.getUCompanyCode()));
icsShipmentHeader.setDDate(dt);
icsShipmentHeader.setCMaker(userName);
icsShipmentHeader.setVoucherType("UpdateICSRdRecord_09_Confirm");
for(ShipmentDetail item:shipmentDetails){
ICSShipmentDetail icsShipmentDetailA = icsShipmentDetailService.getOne(new LambdaQueryWrapper<ICSShipmentDetail>()
.eq(ICSShipmentDetail::getCCode, code)
.eq(ICSShipmentDetail::getCompanyCode, companyWu.getUCompanyCode())
.eq(ICSShipmentDetail::getAutoID, item.getAutoID()));
icsShipmentDetailA.setIQuantity(item.getTaskQty());
icsShipmentDetails.add(icsShipmentDetailA);
}
break;
case "SO":
icsShipmentHeader = icsShipmentHeaderService.getOne(new LambdaQueryWrapper<ICSShipmentHeader>()
.eq(ICSShipmentHeader::getCDLCode,code)
.eq(ICSShipmentHeader::getCompanyCode,companyWu.getUCompanyCode()));
icsShipmentHeader.setDDate(dt);
icsShipmentHeader.setCMaker(userName);
icsShipmentHeader.setCWHCode(shipmentHeader.getUWarehouseCode());
WarehouseU8 warehouseU8 = warehouseU8Service.getOne(new LambdaQueryWrapper<WarehouseU8>()
.eq(WarehouseU8::getUWarehouseCode, shipmentHeader.getUWarehouseCode())
.eq(WarehouseU8::getUCompanyCode, companyWu.getUCompanyCode()));
icsShipmentHeader.setCWHName(warehouseU8.getUWarehouseName());
icsShipmentHeader.setCCode(shipmentHeader.getSourceCode());
icsShipmentHeader.setVoucherType("CreateICSRdRecord_32");
icsShipmentHeader.setID(icsShipmentHeader.getDLID());
for(ShipmentDetail item:shipmentDetails){
ICSShipmentDetail icsShipmentDetailB = icsShipmentDetailService.getOne(new LambdaQueryWrapper<ICSShipmentDetail>()
.eq(ICSShipmentDetail::getCCode, code)
.eq(ICSShipmentDetail::getCompanyCode, companyWu.getUCompanyCode())
.eq(ICSShipmentDetail::getCInvCode, item.getMaterialCode())
.eq(ICSShipmentDetail::getAutoID, item.getAutoID()));
icsShipmentDetailB.setCCode(code);
icsShipmentDetailB.setID(icsShipmentDetailB.getDLID());
icsShipmentDetailB.setAutoID(icsShipmentDetailB.getAutoID());
icsShipmentDetailB.setIQuantity(item.getTaskQty());
icsShipmentDetails.add(icsShipmentDetailB);
}
break;
}
if(type.equals("MO")){
icsShipmentHeader.setVoucherType("UpdateICSRdRecord_11_Confirm");
}
if(type.equals("QO")){
icsShipmentHeader.setVoucherType("UpdateICSRdRecord_09_Confirm");
}
ICSShipmentModel model = new ICSShipmentModel();
model.setIcsShipmentHeader(icsShipmentHeader);
model.setIcsShipmentDetails(icsShipmentDetails);
String JsonParam = JSON.toJSONString(model);
String result = HttpUtils.bodypost(url, JsonParam,currentWarehouseCode);
if(StringUtils.isEmpty(result)){
throw new ServiceException("接口地址错误或服务器连接不到或返回为空");
}
ajaxResult = JSON.parseObject(result, AjaxResult.class);
if (ajaxResult.getCode() ==200 || ajaxResult.getCode() == 400) {
if(shipmentHeader.getShipmentType().equals("SO") || shipmentHeader.getShipmentType().equals("PRO")){
shipmentHeader.setUserDef2(ajaxResult.getMsg());
shipmentHeaderService.updateById(shipmentHeader);
}
for(TaskDetail item: taskDetails) {
item.setStatus(120);
taskDetailService.updateById(item);
}
/**
* 生成快递单
* 1、U8返回值为200
* 2、wms出库单快递信息存在
* 3、存在就生成快递单
*
*/
// if(ajaxResult.getCode() == 200 && shipmentHeader.getKdEable() == 1){
// AjaxResult ajaxResult1 = kuaidiHeaderService.saveKD(shipmentDetails,shipmentHeader,ajaxResult.getMsg());
// }
if(ajaxResult.getCode() == 400) {
documentWarningService.ErpReturnWarning(shipmentHeader.getCode(), shipmentHeader.getSourceCode(), ajaxResult.getMsg());
}
if (shipmentHeader.getFirstStatus() == 300 && shipmentHeader.getLastStatus() != 300) {
shipmentHeader.setUploadStatus(15);
shipmentHeaderService.updateById(shipmentHeader);
}
TaskDetail condition = new TaskDetail();
condition.setBillCode(shipmentHeader.getCode());
//select * from task_detail where billCode = #{billCode} and billId = #{billId} and (status <= 100 or status = 150 or status= 160)
LambdaQueryWrapper<TaskDetail> queryWrapper = Wrappers.lambdaQuery();
queryWrapper.eq(TaskDetail::getBillCode,shipmentHeader.getCode())
.lt(TaskDetail::getStatus,100)
.or()
.eq(TaskDetail::getStatus,100)
.or()
.eq(TaskDetail::getStatus,150)
.or()
.eq(TaskDetail::getStatus,160);
List<TaskDetail> taskDetails1 = taskDetailService.list(queryWrapper);
if (shipmentHeader.getFirstStatus() == 300 && shipmentHeader.getLastStatus() == 300 && taskDetails1.isEmpty()) {
shipmentHeader.setFirstStatus(900);
shipmentHeader.setLastStatus(900);
shipmentHeader.setUploadStatus(20);
shipmentHeaderService.updateById(shipmentHeader);
}
}
if(ajaxResult.getCode() == 300){
shipmentHeader.setUserDef2(ajaxResult.getMsg());
shipmentHeaderService.updateById(shipmentHeader);
for(TaskDetail item: taskDetails) {
item.setStatus(160);
taskDetailService.updateById(item);
}
}
return ajaxResult;
}
/**
* 判断出库单是否可以更新
* @param icsShipmentHeader U8出库单
* @param code U8单号
*/
private void checkShipmentBill(ICSShipmentHeader icsShipmentHeader,String code){
//U8单据类型
String type = icsShipmentHeader.getType();
if(type.equals("OO")){
return;
}
LambdaQueryWrapper<ICSShipmentHeader> queryWrapper = Wrappers.lambdaQuery();
if(type.equals("SO")){
queryWrapper.eq(ICSShipmentHeader::getCDLCode,icsShipmentHeader.getCDLCode());
}else if(type.equals("TO")){
queryWrapper.eq(ICSShipmentHeader::getCTVCode,icsShipmentHeader.getCTVCode());
}else{
queryWrapper.eq(ICSShipmentHeader::getCCode,icsShipmentHeader.getCCode());
}
//WMS出库单
ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(new LambdaQueryWrapper<ShipmentHeader>()
.eq(ShipmentHeader::getReferCode,code));
//U8出库单
ICSShipmentHeader referShipmentHeader = icsShipmentHeaderService.getOne(queryWrapper);
//WMS出库单 和 U8出库单 都不能为空 才能更新
if (StringUtils.isNotNull(shipmentHeader) && StringUtils.isNotNull(referShipmentHeader)) {
if(icsShipmentHeader.getIsNew().equals("1")){
throw new ServiceException("单号重复,已跳过");
}
else
if(icsShipmentHeader.getIsNew().equals("0")){
if(StringUtils.isNotNull(shipmentHeader) ){
//找出 出库单未完成的任务
List<TaskDetail> taskDetailList = taskDetailService.list(new LambdaQueryWrapper<TaskDetail>()
.eq(TaskDetail::getBillCode, shipmentHeader.getCode())
.lt(TaskDetail::getStatus,120));
if(taskDetailList!=null&&taskDetailList.size()>0){
throw new ServiceException("更新失敗,此出库单存在未完成的任务");
}
//找出库配盘明细 未配盘的单据
List<ShipmentContainerDetail> shipmentContainerDetails = shipmentContainerDetailService.list(new LambdaQueryWrapper<ShipmentContainerDetail>()
.eq(ShipmentContainerDetail::getShipmentCode, shipmentHeader.getCode())
.lt(ShipmentContainerDetail::getStatus, QuantityConstant.SHIPMENT_CONTAINER_FINISHED));
if(shipmentContainerDetails!=null&&shipmentContainerDetails.size()>0){
throw new ServiceException("更新失敗,此出库单存在未完成的组盘");
}
//删除wms出库单头表
shipmentHeaderService.removeById(shipmentHeader.getId());
//删除wms出库单明细表
shipmentDetailService.remove(new LambdaQueryWrapper<ShipmentDetail>()
.eq(ShipmentDetail::getShipmentCode,shipmentHeader.getCode()));
}
//上游单据关联头表 删除
icsShipmentHeaderService.removeById(referShipmentHeader.getID());
//上游单据关联明细表 删除
icsShipmentDetailService.remove(new LambdaQueryWrapper<ICSShipmentDetail>()
.eq(ICSShipmentDetail::getCCode, code));
}
else {
throw new ServiceException("isNew值无法识别");
}
}
}
}