ChmConsignmentService.java
33.5 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
package com.erry.iclear.dateInterface.service;
//import cn.hutool.core.date.DateUtil;
import com.erry.iclear.dateInterface.api.request.FedexMawb;
import com.erry.iclear.dateInterface.api.request.FedexReceipt;
import com.erry.iclear.dateInterface.api.request.Mawb;
import com.erry.iclear.dateInterface.api.response.ResultRS;
import com.erry.iclear.dateInterface.common.Constant;
import com.erry.iclear.dateInterface.entity.*;
import com.erry.iclear.dateInterface.repository.ChmConsignmentRepository;
import com.erry.iclear.dateInterface.repository.DictionaryEntriesRepository;
import com.erry.iclear.dateInterface.repository.SysUserRepository;
import com.erry.iclear.dateInterface.util.DateUtils;
import com.erry.iclear.dateInterface.util.NumberUtils;
import com.erry.iclear.dateInterface.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/**
* @author Administrator
*/
@Service
@Slf4j
@Transactional(rollbackOn = Exception.class)
public class ChmConsignmentService {
@Autowired
private ChmConsignmentRepository chmConsignmentRepository;
@Autowired
private ChmConsignmentDetailService chmConsignmentDetailService;
@Autowired
private DictionaryEntriesRepository dictionaryEntriesRepository;
@Autowired
private DeclaredInfoService declaredInfoService;
@Autowired
private SysUserRepository sysUserRepository;
/**
* 转换主单
* @return
*/
public ChmConsignment convertToChmConsignment(Mawb mawb,Date pushTime,String creator){
ChmConsignment result = new ChmConsignment();
try{
//进出口标志:固定值 E
//TODO 报关类型:填写固定值EX,但字典表里没有这个值
// result.setDeclaredDocTypeDic();
// result.setDeclaredCode();
//申报单位代码:固定值 1111980005
result.setDeclaredUnitName(mawb.getAgentName());
//申报单位名称:固定值 联邦快递(中国)有限公司
//提单号:有总单号则取值“总单号_运单号”,没有总单号则取值“运单号”
String[] billNo=mawb.getBillNo().split("_");
if(billNo.length==1){
result.setConsignmentCode(billNo[0]);
}
if(billNo.length==2){
result.setConsignmentHeadCode(billNo[0]);
result.setConsignmentCode(billNo[1]);
}
//合同号
result.setContractCode(mawb.getContrNo());
//主管海关(申报地海关)
if (!StringUtil.isEmptyWithTrim(mawb.getCustomMaster())){
//wy on 2021年9月7日15:12 ,根据申报地海关编码判断口岸
result.setCustomsNo(mawb.getCustomMaster());
DictionaryEntries dictionaryEntries = dictionaryEntriesRepository.findDictionaryEntriesByDicCode(Constant.CUSTOMSNO,mawb.getCustomMaster());
if (dictionaryEntries != null){
//添加TSN口岸
DictionaryEntries portTSN = Constant.dictionaryEntriesCache.get(dictionaryEntries.getExt2());
if (!Objects.equals(portTSN,null)){
result.setPortId(portTSN);
result.setPortName(portTSN.getChineseName());
//申报口岸
result.setDeclaredPort(portTSN.getChineseName());
}
}
}
//征免性质
DictionaryEntries levyTypeDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.NATURE_EXEMPTION+mawb.getCutMode());
if(!Objects.equals(levyTypeDictionaryEntries,null)){
result.setTaxNatureDic(levyTypeDictionaryEntries);
result.setTaxNature(levyTypeDictionaryEntries.getChineseName());
}
//报关/转关关系标志:固定值0 ,但数据字典里没有0
//经停港/指运港
ChmCarryPort chmCarryPort =Constant.chmCarryPortCache.get(mawb.getDistinatePort());
if(!Objects.equals(chmCarryPort,null)){
result.setThroughStopPortDic(chmCarryPort);
result.setThroughStopPort(chmCarryPort.getPortNo());
}
//TODO 报关标志【已确认】,IDE传递的是1,Export中是001,需要进行转换,如果是空,则转换成1
if(mawb.getEdiId() == null){
mawb.setEdiId("1");
}
DictionaryEntries declaredDocTypeDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.DECLARED_DOC_TYPE + Constant.DECLARED_DOC_TYPE_ZERO + mawb.getEdiId());
if(!Objects.equals(declaredDocTypeDictionaryEntries,null)){
result.setDeclaredDocTypeDic(declaredDocTypeDictionaryEntries);
result.setDeclaredDocType(declaredDocTypeDictionaryEntries.getChineseName());
}
//海关编号
result.setCustomsNo(mawb.getEntryId());
//运费币制
DictionaryEntries currencyDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.CURRENCY_SYSTEM+mawb.getFeeCurr());
if(!Objects.equals(currencyDictionaryEntries,null)){
result.setTransCurrencyDic(currencyDictionaryEntries);
result.setTransCurrency(currencyDictionaryEntries.getChineseName());
}
//TODO 运费标记:固定值 3 【iclear中, 和成交方式相关,只有成交方式 1、2 时,才能传 3 】
//运费总价
result.setTransCost(mawb.getFeeRate());
//毛重
result.setGrossWeight(mawb.getGrossWet());
//出入境关闭:固定值 0101
//录入人名称:固定值 必填项,但填的值是空值
//保险费币制
DictionaryEntries insuranceDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.CURRENCY_SYSTEM+mawb.getInsurCurr());
if(!Objects.equals(insuranceDictionaryEntries,null)){
result.setInsuranceCostCurrencyDic(insuranceDictionaryEntries);
result.setInsuranceCostCurrency(insuranceDictionaryEntries.getChineseName());
}
//保险费标记 ,根据transMode决定
//保险费/率
result.setInsuranceCost(mawb.getInsurRate());
//备案号
result.setRecordCode(mawb.getManualNo());
//净重
result.setNetWeight(mawb.getNetWt());
//杂费币制
DictionaryEntries otherDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.CURRENCY_SYSTEM+mawb.getOtherCurr());
if(!Objects.equals(otherDictionaryEntries,null)){
result.setOtherCurrencyDic(otherDictionaryEntries);
result.setOtherCurrency(otherDictionaryEntries.getChineseName());
}
//杂费/率
result.setOtherCost(mawb.getOtherRate());
//杂费标志
//TODO 消费使用/生产销售单位代码
result.setOwnerCode(mawb.getOwnerCode());
//TODO 消费使用/生产销售单位名称
result.setOwnerName(mawb.getOwnerName());
//件数
result.setCounts(mawb.getPackNo().longValue());
//预录入编号
result.setEnteringNo(mawb.getPreEntryId());
//启运国/运抵国
DictionaryEntries fromCountryDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.COUNTRY+mawb.getTradeCountry());
if(!Objects.equals(fromCountryDictionaryEntries,null)){
result.setFromCountryDic(fromCountryDictionaryEntries);
result.setFromCountry(fromCountryDictionaryEntries.getChineseName());
}
//运单类型
DictionaryEntries consType = Constant.dictionaryEntriesCache.get(Constant.consType_D);
if(consType != null){
result.setConsTypeId(consType);
result.setConsType(consType.getChineseName());
}
//监管方式
DictionaryEntries tradeModeDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.SUPERVISION_MODE+Integer.parseInt(mawb.getTradeMode()));
if(!Objects.equals(tradeModeDictionaryEntries,null)){
result.setTradeModeDic(tradeModeDictionaryEntries);
result.setTradeMode(tradeModeDictionaryEntries.getChineseName());
}
//境内收发货人编号
result.setTradeCoSCC(mawb.getTradeCode());
//境内发货人(经营单位编码)
result.setOperateUnitCode(mawb.getTradeCode());
//运输方式代码
DictionaryEntries vehicleWayDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.VEHICLE_WAY_CODE+mawb.getTrafMode());
if(!Objects.equals(vehicleWayDictionaryEntries,null)){
result.setVehicleWay(vehicleWayDictionaryEntries);
result.setVehicleWayCode(vehicleWayDictionaryEntries.getCode());
}
//境内收发货人名称
result.setOperateUnitName(mawb.getTradeName());
//成交方式
DictionaryEntries dealModeDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.CLINCH_TYPE+mawb.getTransMode());
if(!Objects.equals(dealModeDictionaryEntries,null)){
result.setDealModeDic(dealModeDictionaryEntries);
result.setDealMode(dealModeDictionaryEntries.getChineseName());
}
//包装种类
DictionaryEntries packageTypeDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.NEW_PACKAGE_TYPE+mawb.getWrapType());
if(!Objects.equals(packageTypeDictionaryEntries,null)){
result.setPackageTypeDic(packageTypeDictionaryEntries);
result.setPackageType(packageTypeDictionaryEntries.getChineseName());
}
//TODO 生产核销单位统一信用代码---报关形式类型
result.setTradeCoSCC(mawb.getTradeCodeScc());
//TODO 消费使用/生产销售单位单位统一编码
result.setOwnerCodeScc(mawb.getOwnerCodeScc());
//贸易国别
DictionaryEntries tradeAreaCodeDictionaryEntries=Constant.dictionaryEntriesCache.get(Constant.COUNTRY+mawb.getTradeAreaCode());
if(!Objects.equals(tradeAreaCodeDictionaryEntries,null)){
result.setTradeAreaCodeDic(tradeAreaCodeDictionaryEntries);
result.setTradeAreaCode(tradeAreaCodeDictionaryEntries.getChineseName());
}
//标记及号码
result.setDeclaredRemark(mawb.getMarkNo());
//入境口岸代码:固定值 310302
//存放地点:固定值 空值
//申报人员姓名---报关员证号
result.setDeclaredUnitName(mawb.getDeclareName());
//境外发货人代码
//境外收货人编码
result.setOverseasConsignorCode(mawb.getOverseasConsigneeCode());
//境外收货人名称(外文)
result.setOverseasConsignorFnCname(mawb.getOverseasConsigneeEname());
//运单状态: 待申报海关
DictionaryEntries transferWaybillStatusDictionaryEntries=Constant.dictionaryEntriesCache.get(Constant.TRANSFER_WAY_BILL_STATUS+"5");
if(!Objects.equals(transferWaybillStatusDictionaryEntries,null)){
result.setConsStatusDic(transferWaybillStatusDictionaryEntries);
result.setConsStatus(transferWaybillStatusDictionaryEntries.getChineseName());
}
//推送时间作为创建时间,可以用来校验数据的有序性,如果新的推送时间小于已有的创建时间,就不更新数据
result.setCreateTime(new Date());
result.setUpdateTime(pushTime);
result.setCreator(creator);
}catch (Exception e){
result=null;
log.error(e.getMessage(),e);
log.error("convertToChmConsignment() error:"+e.getMessage());
}
return result;
}
public ChmConsignment convertToChmConsignmentFedex(FedexMawb mawb, Date pushTime, String creator,AppInfo appInfo){
ChmConsignment result = new ChmConsignment();
try{
//运单号
result.setConsignmentCode(mawb.getBillNo());
//运单类型
DictionaryEntries consType = Constant.dictionaryEntriesCache.get(Constant.consType_C);
if(consType != null){
result.setConsTypeId(consType);
result.setConsType(consType.getChineseName());
}
//监管方式
/*DictionaryEntries tradeModeDictionaryEntries = Constant.dictionaryEntriesCache.get(Constant.SUPERVISION_MODE+Integer.parseInt(mawb.getTradeMode()));
if(!Objects.equals(tradeModeDictionaryEntries,null)){
result.setTradeModeDic(tradeModeDictionaryEntries);
result.setTradeMode(tradeModeDictionaryEntries.getChineseName());
}*/
if(appInfo != null){
//C类校验是否校验运单号,非空则不校验
result.setCodeCheck(appInfo.getCodeCheck());
}
//境内收发货人社会信用证代码
result.setTradeCoSCC(mawb.getTradeCodeScc());
//境内发货人(经营单位编码)
result.setOperateUnitCode(mawb.getTradeCode());
//境内收发货人名称
result.setOperateUnitName(mawb.getTradeName());
//经营单位
result.setOwnerName(mawb.getOwnerName());
//经营单位海关编码
result.setOwnerCode(mawb.getOwnerCode());
//经营单位社会信用证代码
result.setOwnerCodeScc(mawb.getOwnerCodeScc());
//EANNO
result.setEanNo(mawb.getEanNo());
/*//TODO 生产核销单位统一信用代码---报关形式类型
result.setTradeCoSCC(mawb.getTradeCodeScc());
//TODO 消费使用/生产销售单位单位统一编码
result.setOwnerCodeScc(mawb.getOwnerCodeScc());*/
//运单状态: C类待申报
DictionaryEntries transferWaybillStatusDictionaryEntries=Constant.dictionaryEntriesCache.get(Constant.TRANSFER_WAY_BILL_STATUS+"16");
if(!Objects.equals(transferWaybillStatusDictionaryEntries,null)){
result.setConsStatusDic(transferWaybillStatusDictionaryEntries);
result.setConsStatus(transferWaybillStatusDictionaryEntries.getChineseName());
}
//推送时间作为创建时间,可以用来校验数据的有序性,如果新的推送时间小于已有的创建时间,就不更新数据
result.setCreateTime(new Date());
result.setUpdateTime(pushTime);
if (!creator.equals("IDE-ICLEAR-API")){
SysUser sysUser = sysUserRepository.findUserByLoginName(creator);
result.setCreatorId(sysUser);
result.setCreator(sysUser.getLoginName());
}
}catch (Exception e){
result=null;
log.error(e.getMessage(),e);
log.error("convertToChmConsignmentFedex() error:"+e.getMessage());
}
return result;
}
/**
* 运单转换主单
* @return
*/
public Mawb convertToChmConsignment(ChmConsignment consignment){
Mawb result = new Mawb();
try{
//将运单ID赋值,作为排查数据依据
result.setId(consignment.getId());
//进出口标志:固定值 E
result.setIeFlag("E");
//申报类型:固定值 EX
result.setType("EX");
//申报单位代码:固定值 1111980005
result.setAgentCode("1111980005");
//申报单位名称:固定值 联邦快递(中国)有限公司
result.setAgentName("联邦快递(中国)有限公司");
//运单号
result.setBillNo(consignment.getConsignmentCode());
//合同号 最大长度32
result.setContrNo(consignment.getContractCode());
//主管海关(申报地海关) 固定值 0101
result.setCustomMaster("0101");
//征免性质 数字三字码
if(!Objects.equals(consignment.getTaxNatureDic(),null)){
result.setCutMode(consignment.getTaxNatureDic().getExt2());
}
//经停港/指运港 固定值:0
result.setDeclTrnRel("0");
//经停港/指运港 6位港口代码 ASM000、Mar-51、996102
if(!Objects.equals(consignment.getThroughStopPortDic(),null)){
result.setDistinatePort(consignment.getThroughStopPortDic().getPcCode());
}
//TODO 报关标志【已确认】,IDE传递的是1,Export中是001,需要进行转换 数字三字码或英文二字码
if(!Objects.equals(consignment.getDeclaredDocTypeDic(),null)){
Integer ediid = Integer.parseInt(consignment.getDeclaredDocTypeDic().getExt2());
result.setEdiId(ediid.toString());
}
//报关单编号
result.setEntryId(consignment.getCustomsNo());
//运费币制 英文三字码
if(!Objects.equals(consignment.getTransCurrencyDic(),null)){
result.setFeeCurr(consignment.getTransCurrencyDic().getExt2());
}
//TODO 运费标记:固定值 3 【iclear中, 和成交方式相关,只有成交方式 1、2 时,才能传 3 】
result.setFeeMark("3");
//运费总价 保留2位小数
result.setFeeRate(NumberUtils.bigDecimalFormat(consignment.getTransCost(),2));
//毛重 保留5位小数
result.setGrossWet(NumberUtils.bigDecimalFormat(consignment.getGrossWeight(),5));
//出入境关闭:固定值 0101
result.setIePort("0101");
//录入人名称:固定值 必填项,但填的值是空值
result.setInputerName("");
//保险费币制
if(!Objects.equals(consignment.getInsuranceCostCurrencyDic(),null)){
result.setInsurCurr(consignment.getInsuranceCostCurrencyDic().getExt2());
}
//保险费标记 ,根据transMode决定
result.setInsurMark("");
//保险费/率 保留2位小数
result.setInsurRate(NumberUtils.bigDecimalFormat(consignment.getInsuranceCost(),2));
//备案号
result.setManualNo(consignment.getRecordCode());
//净重 保留5位小数
result.setNetWt(NumberUtils.bigDecimalFormat(consignment.getNetWeight(),5));
//杂费币制 数字三字码
if(!Objects.equals(consignment.getOtherCurrencyDic(),null)){
result.setOtherCurr(consignment.getOtherCurrencyDic().getExt6());
}
//杂费/率
result.setOtherRate(NumberUtils.bigDecimalFormat(consignment.getOtherCost(),2));
//杂费标志
result.setOtherMark("");
//TODO 消费使用/生产销售单位代码
result.setOwnerCode(consignment.getOwnerCode());
//TODO 消费使用/生产销售单位名称
result.setOwnerName(consignment.getOwnerName());
//件数
result.setPackNo(consignment.getCounts().intValue());
//预录入编号
result.setPreEntryId(consignment.getEnteringNo());
//启运国/运抵国 英文三字码
if(!Objects.equals(consignment.getFromCountryDic(),null)){
result.setTradeCountry(consignment.getFromCountryDic().getExt3());
}
//监管方式 数字四字码
if(!Objects.equals(consignment.getTradeModeDic(),null)){
result.setTradeMode(consignment.getTradeModeDic().getExt2());
}
//境内收发货人编号
result.setTradeCode(consignment.getTradeCoSCC());
//运输方式代码 一字码,数字或大写英文字母
if(!Objects.equals(consignment.getVehicleWay(),null)){
result.setTrafMode(consignment.getVehicleWay().getExt2());
}
//境内收发货人名称
result.setTradeName(consignment.getOperateUnitName());
//成交方式 数字一字码,从1~4,共4个
if(!Objects.equals(consignment.getDealModeDic(),null)){
result.setTransMode(consignment.getDealModeDic().getExt6());
}
//包装种类 取值范围(0,1,4,6,22,29,32,33,39,92,93,99)
if(!Objects.equals(consignment.getPackageTypeDic(),null)){
result.setWrapType(consignment.getPackageTypeDic().getExt2());
}
//TODO 生产核销单位统一信用代码---报关形式类型
result.setTradeCodeScc(consignment.getTradeCoSCC());
//TODO 消费使用/生产销售单位单位统一编码
result.setOwnerCodeScc(consignment.getOwnerCodeScc());
//贸易国别 英文三字码
if(!Objects.equals(consignment.getTradeAreaCodeDic(),null)){
result.setTradeAreaCode(consignment.getTradeAreaCodeDic().getExt3());
}
//标记及号码
result.setMarkNo(consignment.getDeclaredRemark());
//入境口岸代码:固定值 110101
result.setEntyPortCode("110101");
//存放地点:固定值 空值
result.setGoodsPlace("");
//申报人员姓名---报关员证号
result.setDeclareName(consignment.getDeclaredUnitName());
//境外发货人代码
result.setOverseasConsignorCode("");
//境外收货人编码
result.setOverseasConsigneeCode(consignment.getOverseasConsignorCode());
//境外收货人名称(外文)
result.setOverseasConsigneeEname(consignment.getOverseasConsignorFnCname());
}catch (Exception e){
result=null;
log.error(e.getMessage(),e);
log.error("convertToChmConsignment() error:"+e.getMessage());
}
return result;
}
/**
* 保存主单
* @param chmConsignment
* @return
*/
public ChmConsignment saveChmConsignment(ChmConsignment chmConsignment){
try{
return chmConsignmentRepository.save(chmConsignment);
}catch (Exception e){
log.error("saveChmConsignment() error:"+e.getMessage());
}
return null;
}
/**
* 保存主单
* @param chmConsignment
* @return
*/
public ChmConsignment updateChmConsignment(ChmConsignment chmConsignment){
try{
return chmConsignmentRepository.save(chmConsignment);
}catch (Exception e){
log.error("updateChmConsignment() error:"+e.getMessage());
}
return null;
}
/**
* 根据运单号查找数据
* @param consignmentCode
* @return
*/
public ChmConsignment findChmConsignmentByConsignmentCode(String consignmentCode, Date startDate){
try {
return chmConsignmentRepository.findChmConsignmentByConsignmentCode(consignmentCode,startDate);
}catch (Exception e){
log.error("findChmConsignmentByConsignmentCode() error:"+ e.getMessage());
}
return null;
}
/**
* 保存或更新 iclear中的运单信息
* @param mawb
* @param timeStamp
*/
public ResultRS processChmConsignment(Mawb mawb, String timeStamp, String creator) {
ResultRS result = new ResultRS(Boolean.FALSE,null,null);
try {
Date pushTime = DateUtils.timeStampToDate(Long.valueOf(timeStamp));
ChmConsignment chmConsignment=this.convertToChmConsignment(mawb,pushTime,creator);
if(Objects.equals(chmConsignment,null)){
result.setCode("30001");
result.setMsg("数据格式不正确");
return result;
}
List<ChmConsignmentDetail> chmConsignmentDetailList = new ArrayList<>();
mawb.getMawbDetailList().forEach(detail ->{
chmConsignmentDetailList.add(chmConsignmentDetailService.convertToChmConsignmentDetail(detail, chmConsignment));
});
chmConsignment.setChmConsignmentDetailList(chmConsignmentDetailList);
//2、校验 7天+运单 ,如果有数据并且 还未报关就更新,如果数据就插入
ChmConsignment chmConsignmentDB=this.findChmConsignmentByConsignmentCode(chmConsignment.getConsignmentCode(), DateUtils.addDate(DateUtils.getCurrentDate(),-7));
//获取用户账号信息
SysUser sysUser = sysUserRepository.findByLoginName("CUSTOMS");
//设置当前运单创建人ID
chmConsignment.setCreatorId(sysUser);
//设置创建人名称
chmConsignment.setCreator(sysUser.getUserName());
//3、新增或更新
//新增:如果没有就插入
if (Objects.equals(chmConsignmentDB,null)){
log.info("新增主单"+ mawb.getBillNo());
ChmConsignment chmConsignmentSaveResult = this.saveChmConsignment(chmConsignment);
if(!Objects.equals(chmConsignmentSaveResult,null)){
log.info("主单"+ mawb.getBillNo()+" 保存成功,chmConsignmentId:"+chmConsignmentSaveResult.getId());
}else{
log.info("主单"+ mawb.getBillNo()+" 保存失败");
result.setCode("30002");
result.setMsg("主单"+ mawb.getBillNo()+" 保存失败");
return result;
}
//更新:
//如果有数据并且满足条件后才能更新数据
//条件1、状态为 待申报海关
//条件2、本次推送时间 > 上次推送的时间
}else if(!Objects.equals(chmConsignmentDB,null)
&& Objects.equals(chmConsignmentDB.getConsStatusDic().getCode(),"transferWaybillStatus_5")
//TODO 提交时需要打开
&& pushTime.getTime()>chmConsignmentDB.getUpdateTime().getTime()
){
//更新数据
log.info("更新主单"+ mawb.getBillNo());
for(ChmConsignmentDetail newDetail:chmConsignment.getChmConsignmentDetailList()){
for(ChmConsignmentDetail oldDetail: chmConsignmentDB.getChmConsignmentDetailList()){
if(Objects.equals(newDetail.getDetailId(),oldDetail.getDetailId())){
//newDetail.setChmConsignment(chmConsignmentDB);
newDetail.setId(oldDetail.getId());
}
}
}
chmConsignment.setId(chmConsignmentDB.getId());
chmConsignment.setCreateTime(chmConsignmentDB.getCreateTime());
chmConsignment.setUpdateTime(pushTime);
ChmConsignment updateResult = this.saveChmConsignment(chmConsignment);
if(!Objects.equals(updateResult,null)){
log.info("主单"+ mawb.getBillNo()+" 更新成功,chmConsignmentId:"+updateResult.getId());
}else{
log.info("主单"+ mawb.getBillNo()+" 更新失败");
result.setCode("30003");
result.setMsg("主单"+ mawb.getBillNo()+" 更新失败");
return result;
}
}
}catch (Exception e){
log.error(""+e.getMessage());
}
result.setSuccess(Boolean.TRUE);
return result;
}
/**
* 保存或更新 iclear中的运单信息
* @param fedexMawb
* @param timeStamp
*/
public ResultRS processChmConsignmentFedex(FedexMawb fedexMawb, String timeStamp, String creator) {
ResultRS result = new ResultRS(Boolean.FALSE,null,null);
try {
Date pushTime = DateUtils.timeStampToDate(Long.valueOf(timeStamp));
ChmConsignment chmConsignment = this.convertToChmConsignmentFedex(fedexMawb,pushTime,creator,null);
if(Objects.equals(chmConsignment,null)){
result.setCode("30001");
result.setMsg("数据格式不正确");
return result;
}
List<ChmConsignmentDetail> chmConsignmentDetailList = new ArrayList<>();
fedexMawb.getMawbDetailList().forEach(detail ->{
chmConsignmentDetailList.add(chmConsignmentDetailService.convertToChmConsignmentDetailFedex(detail, chmConsignment));
});
chmConsignment.setChmConsignmentDetailList(chmConsignmentDetailList);
//2、校验 7天+运单 ,如果有数据并且 还未报关就更新,如果数据就插入
ChmConsignment chmConsignmentDB=this.findChmConsignmentByConsignmentCode(chmConsignment.getConsignmentCode(), DateUtils.addDate(DateUtils.getCurrentDate(),-7));
//3、新增或更新
//新增:如果没有就插入
if (Objects.equals(chmConsignmentDB,null)){
log.info("新增主单"+ fedexMawb.getBillNo());
ChmConsignment chmConsignmentSaveResult = this.saveChmConsignment(chmConsignment);
if(!Objects.equals(chmConsignmentSaveResult,null)){
log.info("主单"+ fedexMawb.getBillNo()+" 保存成功,chmConsignmentId:"+chmConsignmentSaveResult.getId());
}else{
log.info("主单"+ fedexMawb.getBillNo()+" 保存失败");
result.setCode("30002");
result.setMsg("主单"+ fedexMawb.getBillNo()+" 保存失败");
return result;
}
//更新:
//如果有数据并且满足条件后才能更新数据
//条件1、状态为 C类待申报
//条件2、本次推送时间 > 上次推送的时间
}else if(!Objects.equals(chmConsignmentDB,null)
&& Objects.equals(chmConsignmentDB.getConsStatusDic().getCode(),"transferWaybillStatus_16")
//TODO 提交时需要打开
&& pushTime.getTime()>chmConsignmentDB.getUpdateTime().getTime()
){
//更新数据
log.info("更新主单"+ fedexMawb.getBillNo());
for(ChmConsignmentDetail newDetail:chmConsignment.getChmConsignmentDetailList()){
for(ChmConsignmentDetail oldDetail: chmConsignmentDB.getChmConsignmentDetailList()){
if(Objects.equals(newDetail.getDetailId(),oldDetail.getDetailId())){
//newDetail.setChmConsignment(chmConsignmentDB);
newDetail.setId(oldDetail.getId());
}
}
}
chmConsignment.setId(chmConsignmentDB.getId());
chmConsignment.setCreateTime(chmConsignmentDB.getCreateTime());
chmConsignment.setUpdateTime(pushTime);
ChmConsignment updateResult = this.saveChmConsignment(chmConsignment);
if(!Objects.equals(updateResult,null)){
log.info("主单"+ fedexMawb.getBillNo()+" 更新成功,chmConsignmentId:"+updateResult.getId());
}else{
log.info("主单"+ fedexMawb.getBillNo()+" 更新失败");
result.setCode("30003");
result.setMsg("主单"+ fedexMawb.getBillNo()+" 更新失败");
return result;
}
}
}catch (Exception e){
log.error(""+e.getMessage());
}
result.setSuccess(Boolean.TRUE);
return result;
}
public List<FedexReceipt> getConsignmentCode(String[] consignmentCode, String creator) throws ParseException {
DictionaryEntries consTypeC = dictionaryEntriesRepository.findDictionaryEntriesByCode(Constant.consType_C);
SysUser sysUser = sysUserRepository.findUserByLoginName(creator);
List<String> stringList = declaredInfoService.stringList(consignmentCode);
List<Object[]> chmByConsignmentCode = chmConsignmentRepository.findChmByConsignmentCode(stringList, consTypeC.getId(),sysUser.getId());
List<FedexReceipt> fedexcReceiptList = new ArrayList<>();
if(chmByConsignmentCode.size()>0){
for (int i = 0; i < chmByConsignmentCode.size(); i++) {
Object[] objs = chmByConsignmentCode.get(i);
FedexReceipt fedexcReceipt = new FedexReceipt();
fedexcReceipt.setConsignmentId(Long.valueOf(objs[0].toString()));
fedexcReceipt.setConsignmentCode(objs[1].toString());
fedexcReceipt.setConsignmentType("C");
fedexcReceipt.setCustomsReceiptStatus(objs[2].toString());
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
String str = objs[4].toString();
System.out.println(str);
Date date = sdf.parse(objs[4].toString());
fedexcReceipt.setCustomsReceiptTime(date);
fedexcReceiptList.add(fedexcReceipt);
}
}
return fedexcReceiptList;
}
}