FWBinfo.java
44.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
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
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
package com.tianbo.analysis.model;
import com.tianbo.analysis.exception.FFMResolveException;
import com.tianbo.analysis.tools.WaybillTools;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.util.HSSFColor;
import javax.validation.constraints.NotNull;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.Serializable;
import java.io.StringReader;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Data
@Slf4j
public class FWBinfo implements Serializable {
private String autoid;
private String waybillnomaster;
private String totalweight;
private String totalpiece;
private String productname;
private String carrier1;
private String arrivalstation1;
private String carrier2;
private String arrivalstation2;
private String carrier3;
private String arrivalstation3;
private String paymode;
private String specialgoodscode;
private String shippername;
private String shipperaddress;
private String consigneename;
private String consigneeaddress;
private Date createdate;
private String istransfer;
private String shipperCode;
private String shipperCountrycode;
private String shipperPhone;
private String shipperFax;
private String consigneeCode;
private String consigneeCountrycode;
private String consigneeFax;
private String specificConsigneename;
private String specificConsigneePhone;
private String consigneePhone;
//报文内容
public String text;
public Object tests;
public List<String> lineList;
public String order;
public String planeNo;
public int wayBillParseStartLine =0;
private static final String KEY_WORD_3 = "FWB,FLT,RTG,SHP,NAM,ADR,LOC,CNE,AGT,ATG,SSR,NFY,ACC,CVD,RTD,OTH,PPD,COL,CER,ISU,OSI,CDC,REF,COR,COI,SII,ARD,SPH,NOM,SRI,OPI,OCI";
private static final String KEY_WORD_FWB="FWB";
private static final long serialVersionUID = 1L;
private static String END_WORD= "=";
private String TEMP_KEY_WORD="";
public FWBinfo(){}
public FWBinfo(String autoid,String waybillnomaster,String totalweight,String totalpiece,String productname,String carrier1,String arrivalstation1,String carrier2,String arrivalstation2,
String specialgoodscode,String carrier3,String arrivalstation3,String paymode,String shippername,String shipperaddress,String consigneename,String consigneeaddress,
Date createdate,String istransfer,String shipperCode,String shipperCountrycode,String shipperPhone,String shipperFax,String consigneeCode,
String consigneeCountrycode,String consigneeFax,String specificConsigneename,String specificConsigneePhone,String consigneePhone){
this.autoid=autoid;
this.waybillnomaster=waybillnomaster;
this.totalweight=totalweight;
this.totalpiece=totalpiece;
this.productname=productname;
this.carrier1=carrier1;
this.arrivalstation1=arrivalstation1;
this.carrier2=carrier2;
this.arrivalstation2=arrivalstation2;
this.specialgoodscode=specialgoodscode;
this.carrier3=carrier3;
this.arrivalstation3=arrivalstation3;
this.paymode=paymode;
this.shippername=shippername;
this.shipperaddress=shipperaddress;
this.consigneename=consigneename;
this.consigneeaddress=consigneeaddress;
this.createdate=createdate;
this.istransfer=istransfer;
this.shipperCode=shipperCode;
this.shipperCountrycode=shipperCountrycode;
this.shipperPhone=shipperPhone;
this.shipperFax=shipperFax;
this.consigneeCode=consigneeCode;
this.consigneeCountrycode=consigneeCountrycode;
this.consigneeFax=consigneeFax;
this.specificConsigneename=specificConsigneename;
this.specificConsigneePhone=specificConsigneePhone;
this.consigneePhone=consigneePhone;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(" [");
sb.append("Hash = ").append(hashCode());
sb.append(", autoid=").append(autoid);
sb.append(", waybillnomaster=").append(waybillnomaster);
sb.append(", totalweight=").append(totalweight);
sb.append(", totalpiece=").append(totalpiece);
sb.append(", productname=").append(productname);
sb.append(", carrier1=").append(carrier1);
sb.append(", arrivalstation1=").append(arrivalstation1);
sb.append(", carrier2=").append(carrier2);
sb.append(", arrivalstation2=").append(arrivalstation2);
sb.append(", carrier3=").append(carrier3);
sb.append(", arrivalstation3=").append(arrivalstation3);
sb.append(", paymode=").append(paymode);
sb.append(", specialgoodscode=").append(specialgoodscode);
sb.append(", shippername=").append(shippername);
sb.append(", shipperaddress=").append(shipperaddress);
sb.append(", consigneename=").append(consigneename);
sb.append(", consigneeaddress=").append(consigneeaddress);
sb.append(", createdate=").append(createdate);
sb.append(", istransfer=").append(istransfer);
sb.append(", shipperCode=").append(shipperCode);
sb.append(", shipperCountrycode=").append(shipperCountrycode);
sb.append(", shipperPhone=").append(shipperPhone);
sb.append(", shipperFax=").append(shipperFax);
sb.append(", consigneeCode=").append(consigneeCode);
sb.append(", consigneeCountrycode=").append(consigneeCountrycode);
sb.append(", consigneeFax=").append(consigneeFax);
sb.append(", specificConsigneename=").append(specificConsigneename);
sb.append(", specificConsigneePhone=").append(specificConsigneePhone);
sb.append(", consigneePhone=").append(consigneePhone);
sb.append(", serialVersionUID=").append(serialVersionUID);
sb.append("]");
return sb.toString();
}
/**
* 校验报文结尾标识
* 将报文字符窜转换成行数组
* @return
* @throws IOException
* @throws FFMResolveException
*/
public boolean textToStringList() throws IOException, FFMResolveException {
if(StringUtils.isNotBlank(text)){
/**
* 检查报文是否为FWB报
*/
lineList = new ArrayList<>();
if(text.contains(KEY_WORD_FWB)){
BufferedReader reader = new BufferedReader(new StringReader(text));
log.info(this.toString());
for (String lineStr = reader.readLine();
lineStr != null;
lineStr = reader.readLine()) {
if (StringUtils.isNotEmpty(lineStr)){
lineList.add(lineStr);
}
}
return true;
}else{
throw new FFMResolveException("报文不是FWB报");
}
}
return false;
}
/**
* 开始解析
* * Cargo-IMP Messages may only contain the following approved characters:
* * the letters A to Z (upper case only)
* * the numerals 0 to 9
* * the special characters / -. Space < =
*/
public boolean startParse() throws FFMResolveException {
if (!lineList.isEmpty()){
int keyword_i = 0;
for (int i = 0; i < lineList.size(); i++) {
String pattern = "[^A-Z0-9/\\.\\-<=\\s]+";
Pattern r = Pattern.compile(pattern);
//根据行关键字走相应的解析逻辑
String line = lineList.get(i);
Matcher m = r.matcher(line);
if(m.find()){
log.error("[FWB] 行[{}]中包含非允许特殊字符,报文中只允许包含-[{}]等特殊字符",i," / -. Space < =");
throw new FFMResolveException("[FWB] 报文中包含特殊字符,报文中只允许包含 / -. Space < = 等特殊字符");
}
log.debug("[TEXT] 开始处理行[{}]-[{}]",i,line);
if(line.equals(END_WORD)){
log.info("[END]- 当前行为结束行,解析结束");
return true;
}
String keyword = keyword(line);
if (!"NOT_KEYWORD".equals(keyword)){
TEMP_KEY_WORD = "";
keywordParse(keyword,line,i);
}else{
log.debug("[[TEXT-LINE-{}]当前行不属于关键字解析行,根据缓存关键字解析下行信息",i);
keywordNextLineParse(line,i);
}
}
}
return false;
}
public FWBinfo resolve(){
istransfer="1";
autoid=UUID.randomUUID().toString();
return new FWBinfo(autoid, waybillnomaster, totalweight, totalpiece, productname, carrier1, arrivalstation1, carrier2, arrivalstation2,
specialgoodscode, carrier3, arrivalstation3, paymode, shippername, shipperaddress, consigneename, consigneeaddress,
new Date(), istransfer, shipperCode, shipperCountrycode, shipperPhone, shipperFax, consigneeCode,
consigneeCountrycode, consigneeFax, specificConsigneename, specificConsigneePhone, consigneePhone);
}
/**
* 根据关键字适配解析方法
* @param keyword 关键字
* @param line 当前行内容
* @param current 当前行数
*/
public void keywordParse(String keyword,String line,int current) throws FFMResolveException {
log.debug("[TEXT] 行[{}]包含关键字{},开始处理",current,keyword);
switch (keyword){
case "FWB"://BY:XYH
fwbInfoParse(line);
break;
case "FLT"://BY:XYH
fltparse(line);
break;
case "RTG"://BY:XYH
rtgparse(line);
break;
case "SHP":
shipperHasSplitParse(line,"SHP");
break;
case "CNE":
shipperHasSplitParse(line,"CNE");
break;
case "AGT":
agtParse(line);
break;
case "SSR":
ssrParse(line);
break;
case "ACC":
accParse(line);
break;
case "CVD":
cvdParse(line);
break;
case "OTH":
othParse(line);
break;
case "PDD":
ppdParse(line);
break;
case "CER":
cerParse(line);
break;
case "ISU":
ISUParse(line);
break;
case "OSI":
osiParse(line);
break;
case "CDC":
cdcParse(line);
break;
case "REF":
refParse(line);
break;
case "COR":
corParse(line);
break;
case "SII":
siiParse(line);
break;
case "ARD":
ardParse(line);
break;
case "SPH":
sphParse(line);
break;
case "NOM":
nomParse(line);
break;
case "SRI":
sriParse(line);
break;
case "OCI":
ociInfoParse(line);
break;
case "RTD":
rtdParse(line);
break;
default:
break;
}
}
/**
* 根据关键字适配解析方法
* @param line 当前行内容
* @param current 当前行数
*/
public void keywordNextLineParse(String line,int current) throws FFMResolveException {
log.info("行[{}]当前临时关键字-[{}]",current,TEMP_KEY_WORD);
switch (TEMP_KEY_WORD){
case "FWB-WAY"://by:xyh
waybill(line);
break;
case "CNE-NAM":
case "SHP-NAM":
//SHP下的第一行地址行
shipperNamV2Parse(line);
break;
case "CNE-ADR":
case "SHP-ADR":
//SHP下的第一行地址行
shipperAdrV1Parse(line);
break;
case "CNE-LOC":
case "SHP-LOC":
//SHP下的第一行地址行
shipperLocV1Parse(line);
break;
case "CNE-CON":
case "SHP-CON":
//SHP下的第一行地址行
shipperContactV1Parse(line);
break;
case "AGT-NAME":
agtNameParse(line);
break;
case "AGT-PLACE":
agtPlaceParse(line);
break;
case "PDD-DUE":
ppdDueParse(line);
break;
case "RTD-GOD":
rtdgodParse(line);
break;
default:
break;
}
}
/**
* 关键字识别
* @param text 每行的内容
* @return 识别为关键字的返回关键字,未被识别为关键字的返回NOT_KEYWORD;
* 返回的关键字 三字码关键字 机场代码关键字 文件结尾关键字 CONT,LAST
*/
public String keyword(@NotNull String text){
//取每行前三位
if (StringUtils.isNotBlank(text) && text.length()>=3){
String s_3 = text.substring(0,3);
if(KEY_WORD_3.contains(s_3)){
return s_3;
}
}
return "NOT_KEYWORD";
}
/**
* FWB信息解析
* @param verlLine FWB-报文版本行信息解析
*/
public boolean fwbInfoParse(String verlLine) throws FFMResolveException {
log.debug("[TEXT] 找到FWB开头节点");
//校验正则1,取前三位验证是否是机场代码
String pattern = "^FWB/\\d{1,3}";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(verlLine);
//格式正则校验
if(m.find()){
String ver = verlLine.split("/")[1];
log.info("[VER] 报文版本{}",ver.trim());
TEMP_KEY_WORD="FWB-WAY";
return true;
}
throw new FFMResolveException("[FLIGHT] FWB版本信息错误");
}
/**
* FWB信息解析
* @param verlLine FWB-报文运单行信息解析
* by:xyh
*/
public boolean waybill(String verlLine) throws FFMResolveException {
log.debug("[TEXT] 找到运单信息行");
//校验正则1,取前三位验证是否是机场代码
String pattern = "^(\\d{3}-\\d{8})([A-Z]{3})([A-Z]{3})/T(\\d{1,4})[A-Z0-9]([0-9\\.]{1,7})";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(verlLine);
//格式正则校验
if(m.find()){
waybillnomaster = m.group(1);
//主单模七校验
if(WaybillTools.model7Check(waybillnomaster)){
log.debug("[AWB] 运单-({})模七校验通过",waybillnomaster);
}else {
log.error("{}运单模七校验不通过",waybillnomaster);
throw new FFMResolveException(waybillnomaster+"运单模七校验不通过");
}
totalpiece=m.group(4);
totalweight = m.group(5);
log.info("[FWB]运单处理结果[{}]-[{}]-[{}]-[{}]-[{}]",waybillnomaster,arrivalstation1,arrivalstation3,totalpiece,totalweight);
return true;
}
throw new FFMResolveException("[FLIGHT] FWB运单信息节点错误");
}
/**
* FWB信息解析
* @param verlLine FLT-报文运单行信息解析
* by:xyh
*/
public boolean fltparse(String verlLine) throws FFMResolveException {
log.debug("[TEXT] 找到FLT信息行");
//校验正则1,取前三位验证是否是机场代码
String pattern = "^FLT(/[A-Z0-9]{2}[0-9]{3,4}[A-Z]?/\\d{2})+";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(verlLine);
//格式正则校验
if(m.find()){
String strList[] = verlLine.split("/");
if(strList.length>3){
carrier1=strList[1].substring(0,2);
carrier2=strList[3].substring(0,2);
}else{
carrier1=strList[1].substring(0,2);
}
log.debug("[FLT] 承运人信息,carrier1:{} , carrier2:{}", carrier1, carrier2);
return true;
}
throw new FFMResolveException("[FLIGHT] FLT运单信息节点错误");
}
/**
* FWB信息解析
* @param verlLine RTG-RTG信息解析
* by:xyh
*/
public boolean rtgparse(String verlLine)throws FFMResolveException{
log.debug("[TEXT] 找到RTG信息行");
//校验正则1,取前三位验证是否是机场代码
String pattern = "^RTG(/[A-Z0-9]{5}){0,3}";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(verlLine);
//格式正则校验
if(m.find()){
String strList[]=verlLine.split("/");
if(strList.length>2){
arrivalstation1=strList[1].substring(0,3);
arrivalstation2=strList[2].substring(0,3);
}else{
arrivalstation1=strList[1].substring(0,3);
}
log.info("[RTG]节点处理结果[{}]-[{}]",arrivalstation1,arrivalstation2);
return true;
}
throw new FFMResolveException("[FLIGHT] RTG 运单信息节点错误");
}
/**
* 发货人信息解析1版本包含分割符解析
* 节点有两种表现 一种是SHP标识后就换行发货人名称,一种是SHP/发货人名称
* @param line SHP-发货人行信息解析
*/
public void shipperHasSplitParse(String line,String SHP_OR_CNE) throws FFMResolveException {
log.debug("[TEXT] 找到SHP|CNE分单开头节点");
//SHP/发货人名称 - 正则适配
String keyword = "^(SHP|CNE)(/.{1,35})?";
// 创建 Pattern 对象
Pattern r = Pattern.compile(keyword);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
if (m.find()){
/*String strList[] = line.split("/");
if (strList.length>1){
if("SHP".equals(SHP_OR_CNE)){
shippername = strList[1];
log.debug("[SHP] 发货人信息为:{}",shippername);
TEMP_KEY_WORD= "SHP-ADR";
}else{
consigneename = strList[1];
log.debug("[CNE] 收货人信息为:{}",consigneename);
TEMP_KEY_WORD= "CNE-ADR";
}
}else {
if("SHP".equals(SHP_OR_CNE)){
log.info("[SHP]主节点为分单数据标识节点,下面几行解析具体信息");
TEMP_KEY_WORD= "SHP-NAM";
}else {
log.info("[CNE] 主节点为分单数据标识节点,下面几行解析具体信息");
TEMP_KEY_WORD= "CNE-NAM";
}
}*/
if("SHP".equals(SHP_OR_CNE)){
TEMP_KEY_WORD="SHP-NAM";
}else{
TEMP_KEY_WORD="CNE-NAM";
}
}else {
throw new FFMResolveException("[SHP|CNE] 收发货人信息格式校验错误");
}
}
/**
* 发货人名称2版本解析
* @param line NAM-发货人行信息解析
*/
public void shipperNamV2Parse(String line) throws FFMResolveException {
if ("SHP-NAM".equals(TEMP_KEY_WORD) || "CNE-NAM".equals(TEMP_KEY_WORD)){
log.debug("[TEXT] 找到收发货人名称节点");
//SHP/发货人名称 - 正则适配
String keyword = "^(NAM)?/.{1,35}";
// 创建 Pattern 对象
Pattern r = Pattern.compile(keyword);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
if (m.find()){
String strList[] = line.split("/");
if("SHP-NAM".equals(TEMP_KEY_WORD)){
shippername = strList[1];
log.info("收货人的名称打印{}-{}",strList[1],strList);
log.debug("[SHP] 发货人名称为:{}",shippername);
TEMP_KEY_WORD= "SHP-ADR";
}else{
consigneename = strList[1];
log.debug("[CNE] 收货人地址为:{}",consigneename);
TEMP_KEY_WORD= "CNE-ADR";
}
}else {
throw new FFMResolveException("[SHP|CNE] 收发货人名称格式校验错误");
}
}
}
/**
* 发货人地址1版本解析
* @param line NAM-发货人行信息解析
*/
public void shipperAdrV1Parse(String line) throws FFMResolveException {
if ("SHP-ADR".equals(TEMP_KEY_WORD)|| "CNE-ADR".equals(TEMP_KEY_WORD)){
log.debug("[TEXT] 找到发货人地址节点");
//SHP/发货人名称 - 正则适配
String keyword = "^(ADR)?/.{1,35}";
// 创建 Pattern 对象
Pattern r = Pattern.compile(keyword);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
if (m.find()){
String strList[] = line.split("/");
if("SHP-ADR".equals(TEMP_KEY_WORD)){
shipperaddress = strList[1];
log.debug("[SHP] 发货人地址为:{}",shipperaddress);
TEMP_KEY_WORD= "SHP-LOC";
}else {
consigneeaddress = strList[1];
log.debug("[CNE] 收货人地址为:{}",consigneeaddress);
TEMP_KEY_WORD= "CNE-LOC";
}
}else {
throw new FFMResolveException("[SHP|CNE] 收发货人地址格式校验错误");
}
}
}
/**
* 发货人城市省份1版本解析
* @param line LOC-发货人行信息解析
*/
public void shipperLocV1Parse(String line) throws FFMResolveException {
if ("SHP-LOC".equals(TEMP_KEY_WORD) || "CNE-LOC".equals(TEMP_KEY_WORD)){
log.debug("[TEXT] 找到发货人城市省份节点");
//SHP/发货人名称 - 正则适配
String keyword = "^(LOC)?/.{0,17}(/.{0,9})?";
// 创建 Pattern 对象
Pattern r = Pattern.compile(keyword);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
if (m.find()){
String strList[] = line.split("/");
if("SHP-LOC".equals(TEMP_KEY_WORD)){
String cityName = strList[1];
log.debug("[SHP] 发货人城市为:{}",cityName);
if (strList.length>2){
log.debug("[SHP] 发货人省份信息为:{}",strList[2]);
}
TEMP_KEY_WORD= "SHP-CON";
}else{
String cityName = strList[1];
log.debug("[CNE] 收货人城市为:{}",cityName);
if (strList.length>2){
log.debug("[CNE] 收货人省份信息为:{}",strList[2]);
}
TEMP_KEY_WORD= "CNE-CON";
}
}else {
throw new FFMResolveException("[SHP|CNE] 发货人地址格式校验错误");
}
}
}
/**
* 发货人国家及联系信息1版本解析
* @param line LOC-发货人行信息解析
*/
public void shipperContactV1Parse(String line) throws FFMResolveException {
if ("SHP-CON".equals(TEMP_KEY_WORD)||"CNE-CON".equals(TEMP_KEY_WORD)){
log.debug("[TEXT] 找到收发货人国家及联系信息节点");
//SHP/发货人名称 - 正则适配
String keyword = "^/[A-Z]{2}(/.{1,9})?((/[TEFXL]{2}/.{1,25})+)?";
// 创建 Pattern 对象
Pattern r = Pattern.compile(keyword);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
if (m.find()){
String strList[] = line.split("/");
if("SHP-CON".equals(TEMP_KEY_WORD)){
shipperCountrycode = strList[1];
log.debug("[SHP] 发货人国家为:{}",shipperCountrycode);
if (strList.length>3){
log.debug("[SHP] 发货人邮编信息为:{}",strList[2]);
if ("TE".equals(strList[3])){
shipperPhone = strList[4];
log.debug("[SHP] 发货人电话信息为:{}",shipperPhone);
}
if ("FX".equals(strList[3])){
shipperFax = strList[4];
log.debug("[SHP] 发货人传真信息为:{}",consigneeFax);
}
}
}else{
consigneeCountrycode = strList[1];
log.debug("[CNE] 收货人国家为:{}",consigneeCountrycode);
if (strList.length>3){
log.debug("[CNE] 收货人邮编信息为:{}",strList[2]);
if ("TE".equals(strList[3])){
consigneePhone = strList[4];
log.debug("[CNE] 收货人电话信息为:{}",consigneePhone);
}
if ("FX".equals(strList[3])){
consigneeFax = strList[4];
log.debug("[CNE] 收货人传真信息为:{}",consigneeFax);
}
}
}
}else {
throw new FFMResolveException("[SHP|CNE] 收发货人国家及联系信息格式校验错误");
}
}
}
/**
* AGT版本解析
* @param line AGT-代理人行信息解析
*/
public boolean agtParse(String line)throws FFMResolveException{
log.debug("[TEXT] 找到AGT信息行");
String pattern = "^AGT/?(.{0,14})/([0-9]{7})/?([0-9]{0,4})/?([A-Z0-9]{0,3})";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
//格式正则校验
if(m.find()){
TEMP_KEY_WORD="AGT-NAME";
log.info("[AGT]节点处理结果[{}]-[{}]-[{}]",m.group(2),m.group(3),m.group(4));
return true;
}
throw new FFMResolveException("[FLIGHT] AGT 运单信息节点错误");
}
/**
* AGT版本解析
* @param line AGT-NAME代理人行信息解析
*/
public boolean agtNameParse(String line)throws FFMResolveException{
log.debug("[TEXT] 找到AGT-NAME信息行");
String pattern = "^(/.{1,35})";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
//格式正则校验
if(m.find()){
TEMP_KEY_WORD="AGT-PLACE";
log.info("[AGT-NAME]节点处理结果[{}]",m.group(1));
return true;
}
throw new FFMResolveException("[FLIGHT] AGT-NAME 运单信息节点错误");
}
/**
* AGT版本解析
* @param line AGT-PLACE代理人行信息解析
*/
public boolean agtPlaceParse(String line)throws FFMResolveException{
log.debug("[TEXT] 找到AGT-PLACE信息行");
String pattern = "^(/.{1,17})";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
//格式正则校验
if(m.find()){
log.info("[AGT-PLACE]节点处理结果[{}]",m.group(1));
return true;
}
throw new FFMResolveException("[FLIGHT] AGT-PLACE 运单信息节点错误");
}
/**
* SSR版本解析
* @param line SSR特别服务请求行信息解析
*/
public boolean ssrParse(String line)throws FFMResolveException{
log.debug("[TEXT] 找到SSR信息行");
String pattern = "^SSR(/.{1,65})+";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
//格式正则校验
if(m.find()){
log.info("[SSR]节点处理结果[{}]",m.group(1));
return true;
}
throw new FFMResolveException("[FLIGHT] SSR 运单信息节点错误");
}
/**
* ACC版本解析
* @param line ACC会计信息行信息解析
*/
public boolean accParse(String line)throws FFMResolveException{
log.debug("[TEXT] 找到ACC信息行");
String pattern = "^(ACC/([A-Z]{3})/(.{1,34}))+";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
//格式正则校验
if(m.find()){
log.info("[ACC]节点处理结果[{}]-[{}]",m.group(2),m.group(3));
return true;
}
throw new FFMResolveException("[FLIGHT] ACC 运单信息节点错误");
}
/**
* CVD 计费声明节点解析
* @param line
*/
public void cvdParse(String line){
String keyword = "^CVD/([A-Z]{3})/([A-Z]{2})/([A-Z]{2})/([0-9\\.]{1,12}|NVD)/(NCV|[0-9\\.]{1,12})/(XXX|[0-9\\.]{1,11})";
// 创建 Pattern 对象
Pattern r = Pattern.compile(keyword);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
if (m.find()){
String ISO_Currency_Code = m.group(1);
paymode = m.group(3);
String Declared_Value_for_Carriage = m.group(4);
String Declared_Value_for_Customs = m.group(5);
String Declared_Value_for_Insurance = m.group(6);
log.info("[CVD]-计费声明:货币代码[{}]-付费模式[{}]-运输申报价值[{}]-海关申报价值[{}]-保险申报价值[{}]",
ISO_Currency_Code,paymode,Declared_Value_for_Carriage,Declared_Value_for_Customs,Declared_Value_for_Insurance);
}
}
/**
* OTH版本解析
* @param line OTH其它收费行信息解析
*/
public boolean othParse(String line)throws FFMResolveException{
log.debug("[TEXT] 找到OTH信息行");
String pattern = "^OTH/([A-Z]{1})/(([A-Z]{2}[A-Z]{1}[0-9\\.]{1,12}))+";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
//格式正则校验
if(m.find()){
log.info("[OTH]节点处理结果[{}]-[{}]",m.group(1),m.group(2));
return true;
}
throw new FFMResolveException("[FLIGHT] OTH 运单信息节点错误");
}
/**
* PPD版本解析
* @param line PPD预付费用汇总表行信息解析
*/
public boolean ppdParse(String line)throws FFMResolveException{
log.debug("[TEXT] 找到PPD信息行");
String pattern = "^PPD(/WT[0-9\\.]{1,12})?(/VC[0-9\\.]{0,12})?(/TX[0-9\\.]{0,12})?\n";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
//格式正则校验
if(m.find()){
TEMP_KEY_WORD="PDD-DUE";
log.info("[PPD]节点处理结果[{}]-[{}]-[{}]",m.group(1),m.group(2),m.group(3));
return true;
}
throw new FFMResolveException("[FLIGHT] PPD 运单信息节点错误");
}
/**
* PPD版本解析
* @param line PPD-DUE预付费用汇总表信息解析
*/
public boolean ppdDueParse(String line)throws FFMResolveException{
log.debug("[TEXT] 找到PPD-DUE信息行");
String pattern = "^(/OA[0-9\\.]{1,12})?(/OC[0-9\\.]{0,12})?(/CT[0-9\\.]{0,12})?";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
//格式正则校验
if(m.find()){
log.info("[PPD]节点处理结果[{}]-[{}]-[{}]",m.group(1),m.group(2),m.group(3));
return true;
}
throw new FFMResolveException("[FLIGHT] PPD-DUE 运单信息节点错误");
}
/**
* CER版本解析
* @param line CER收货人签名行信息解析
*/
public boolean cerParse(String line)throws FFMResolveException{
log.debug("[TEXT] 找到CER信息行");
String pattern = "^CER/(.{0,20})";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
//格式正则校验
if(m.find()){
log.info("[CER]节点处理结果[{}]",m.group(1));
return true;
}
throw new FFMResolveException("[FLIGHT] CER 运单信息节点错误");
}
/**
* ISU版本解析
* @param line ISU承运人行信息解析
*/
public boolean ISUParse(String line)throws FFMResolveException{
log.debug("[TEXT] 找到ISU信息行");
String pattern = "^ISU/([0-9]{2}[A-Z]{3}[0-9]{2})/(.{0,17}|[A-Z]{3})?(/.{0,20})?";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
//格式正则校验
if(m.find()){
log.info("[ISU]节点处理结果[{}]-[{}]-[{}]",m.group(1),m.group(2),m.group(3));
return true;
}
throw new FFMResolveException("[FLIGHT] ISU 运单信息节点错误");
}
/**
* OSI版本解析
* @param line OSI其他服务资料行信息解析
*/
public boolean osiParse(String line)throws FFMResolveException{
log.debug("[TEXT] 找到OSI信息行");
String pattern = "^OSI(/.{1,65})+";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
//格式正则校验
if(m.find()){
log.info("[OSI]节点处理结果[{}]",m.group(1));
return true;
}
throw new FFMResolveException("[FLIGHT] OSI 运单信息节点错误");
}
/**
* CDC版本解析
* @param line CDC目标货币的抄送费用行信息解析
*/
public boolean cdcParse(String line)throws FFMResolveException{
log.debug("[TEXT] 找到CDC信息行");
String pattern = "^CDC/([A-Z]{3}[0-9\\.]{1,11})/([0-9\\.]{1,12})/([0-9\\.]{1,12})/([0-9\\.]{1,12})";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
//格式正则校验
if(m.find()){
log.info("[CDC]节点处理结果[{}]-[{}]-[{}]-[{}]",m.group(1),m.group(2),m.group(3),m.group(4));
return true;
}
throw new FFMResolveException("[FLIGHT] CDC 运单信息节点错误");
}
/**
* REF版本解析
* @param line REF发件人参考行信息解析
*/
public boolean refParse(String line)throws FFMResolveException{
log.debug("[TEXT] 找到 REF 信息行");
String pattern = "^REF/([A-Z]{3}[A-Z0-9]{4})?/.{0,15}/([A-Z0-9]{0,3}/[A-Z0-9]{0,17}/[A-Z]{3})? |^REF/([A-Z]{3}[A-Z0-9]{4})?/.{0,15}|^REF/([A-Z]{3}[A-Z0-9]{4})?";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
//格式正则校验
if(m.find()){
log.info("[REF]节点处理结果[{}]-[{}]-[{}]-[{}]",m.group(1),m.group(2),m.group(3),m.group(4));
return true;
}
throw new FFMResolveException("[FLIGHT] REF 运单信息节点错误");
}
/**
* COR版本解析
* @param line COR发件人参考行信息解析
*/
public boolean corParse(String line)throws FFMResolveException{
log.debug("[TEXT] 找到 COR 信息行");
String pattern = "^COR/([A-Z0-9]{0,2})";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
//格式正则校验
if(m.find()){
log.info("[REF]节点处理结果[{}]",m.group(1));
return true;
}
throw new FFMResolveException("[FLIGHT] COR 运单信息节点错误");
}
/**
* sii版本解析
* @param line SII销售激励信息行信息解析
*/
public boolean siiParse(String line)throws FFMResolveException{
log.debug("[TEXT] 找到 SII 信息行");
String pattern = "^SII/([0-9./]{1,12})?/([A-Z]{0,2})?|^SII/([0-9./]{1,12})?";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
//格式正则校验
if(m.find()){
log.info("[SII]节点处理结果[{}]",m.group(1));
return true;
}
throw new FFMResolveException("[FLIGHT] SII 运单信息节点错误");
}
/**
* ard版本解析
* @param line ARD代理参考数据行信息解析
*/
public boolean ardParse(String line)throws FFMResolveException{
log.debug("[TEXT] 找到 ARD 信息行");
String pattern = "^ARD/(.{0,15})";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
//格式正则校验
if(m.find()){
log.info("[ARD]节点处理结果[{}]",m.group(1));
return true;
}
throw new FFMResolveException("[FLIGHT] ARD 运单信息节点错误");
}
/**
* SPH版本解析
* @param line SPH特别处理细节行信息解析
*/
public boolean sphParse(String line)throws FFMResolveException{
log.debug("[TEXT] 找到 SPH 信息行");
String pattern = "^SPH/([A-Z]{3})+";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
//格式正则校验
if(m.find()){
log.info("[SPH]节点处理结果[{}]",m.group(1));
specialgoodscode=m.group(1);
return true;
}
throw new FFMResolveException("[FLIGHT] SPH 运单信息节点错误");
}
/**
* NOM版本解析
* @param line NOM指定经办方行信息解析
*/
public boolean nomParse(String line)throws FFMResolveException{
log.debug("[TEXT] 找到 NOM 信息行");
String pattern = "^NOM/(.{1,35})/(.{1,17})?";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
//格式正则校验
if(m.find()){
log.info("[NOM]节点处理结果[{}]-[{}]",m.group(1),m.group(2));
return true;
}
throw new FFMResolveException("[FLIGHT] NOM 运单信息节点错误");
}
/**
* SRI版本解析
* @param line SRI装运参考信息行信息解析
*/
public boolean sriParse(String line)throws FFMResolveException{
log.debug("[TEXT] 找到 SRI 信息行");
String pattern = "^SRI/?(.{0,14})?(/.{0,12})?(/.{0,12})|^SRI/?(.{0,14})|^SRI/?(.{0,14})?(/.{0,12})";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
//格式正则校验
if(m.find()){
log.info("[SRI]节点处理结果[{}]-[{}]",m.group(1),m.group(2));
return true;
}
throw new FFMResolveException("[FLIGHT] SRI 运单信息节点错误");
}
/**
* RTD版本解析
* @param line RTD费率说明行信息解析
*/
public boolean rtdParse(String line)throws FFMResolveException{
log.debug("[TEXT] 找到 RTD 信息行");
String pattern = "^RTD/([0-9]{1,2})?(/[A-Z]{1}[0-9]{1,4})?(/[A-Z]{1}[0-9./]{1,7})?(/[A-Z]{1}[A-Z]{1})?(/[A-Z]{1}[0-9./]{4,7}|[0-9./]{1,3}|[A-Z]{1}|[0-9./]{1,2})?(|/[A-Z]{1}][0-9./]{1,7})?(/[A-Z]{1}[0-9./]{1,8})?(/[A-Z]{1}[0-9./]{1,12})";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
//格式正则校验
if(m.find()){
log.info("[RTD]节点处理结果[{}]-[{}]",m.group(2),m.group(3));
TEMP_KEY_WORD="RTD-GOD";
return true;
}
throw new FFMResolveException("[FLIGHT] RTD 运单信息节点错误");
}
/**
* RTD版本解析
* @param line RTD-GOD费率说明行信息解析
*/
public boolean rtdgodParse(String line)throws FFMResolveException{
log.debug("[TEXT] 找到 RTD-GOD 信息行");
String pattern = "^(/([A-Z]{1}[A-Z]{1})/(.{1,20}))";
// 创建 Pattern 对象
Pattern r = Pattern.compile(pattern);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
//格式正则校验
if(m.find()){
log.info("[RTD-GOD]节点处理结果[{}]",m.group(3));
productname=m.group(3);
TEMP_KEY_WORD = "";
return true;
}
throw new FFMResolveException("[FLIGHT] RTD-GOD 运单信息节点错误");
}
/**
* OCI其他海关信息节点解析
* @param line OCI行
*/
public void ociInfoParse(String line) throws FFMResolveException {
String keyword = "^(OCI)?/([A-Z]{2})?/([A-Z]{3})?/([A-Z]{0,2})?/(.{1,35})";
// 创建 Pattern 对象
Pattern r = Pattern.compile(keyword);
// 现在创建 matcher 对象
Matcher m = r.matcher(line);
if (m.find()){
//二位国家代码
String countryCode = line.split("/")[1];
//三位信息标识
String infoCode = line.split("/")[2];
//二位海关信息标识
String customsCode =line.split("/")[3];
//补充海关信息
String customMsg = line.split("/")[4];
log.debug("[AWB-OTHER-OCI] 运单OCI海关其他信息,国家代码:{} , 信息标识:{}, 海关信息标识:{}, 补充海关信息:{} ",
countryCode,
infoCode,
customsCode,
customMsg);
if (customMsg.length()>35){
throw new FFMResolveException(customMsg+"-OCI海关其他信息长度超过35,解析错误");
}
ociInfoLineParse(countryCode,infoCode,customsCode,customMsg);
TEMP_KEY_WORD= "OCI";
}else {
throw new FFMResolveException("OCI海关其他信息格式校验错误");
}
}
/**
* OCI 信息标识节点解析与判定
* @param countryCode 国家代码儿子
* @param infoCode 信息代码识别码三字码
* @param customsCode 海关标识代码
* @param customMsg 具体标识信息
*/
public boolean ociInfoLineParse(String countryCode,String infoCode,String customsCode,String customMsg){
log.info("[OCI] - 国家代码[{}],信息代码三字码[{}],海关标识代码[{}],具体标识内容[{}]",countryCode,infoCode,customsCode,customMsg);
switch (customsCode){
//具体收货人姓名
case "CP":
case "KC":
case "ST":
specificConsigneename = customMsg;
log.info("收货具体联系人名称[{}]",customMsg);
break;
//具体收货人电话
case "CT":
case "U":
specificConsigneePhone = customMsg;
log.info("收货具体联系人电话[{}]",customMsg);
break;
//海关企业注册代码
case "T":
String enterpriseCode= customMsg;
if ("CNE".equals(infoCode)){
consigneeCode = customMsg;
log.info("收货人国家[{}]企业代码[{}]",countryCode,customMsg);
}else if ("SHP".equals(infoCode)){
shipperCode = customMsg;
log.info("发货人国家[{}]企业代码[{}]",countryCode,customMsg);
}
break;
default:
break;
}
return true;
}
}