333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
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
import BaseService from "../baseService";
import { TMSWayBill } from "../../entity/express/tms/tmsWayBill";
import { TMSWayBillAbnormal } from "../../entity/express/tms/tmsWayBillAbnormal";
import { TMSPort } from "../../entity/express/tms/tmsPort";
import moment = require("moment");
import { TMSWayBillList } from "../../entity/express/tms/tmsWayBillList";
import { TMSAbnormal } from "../../entity/express/tms/tmsAbnormal";
import { TMSIdCard } from "../../entity/express/tms/tmsIdCard";
import { TMSWayBillReceive } from "../../entity/express/tms/tmsWayBillReceive";
 
export default class SortingHelperService extends BaseService {
  public async checkRule(wayBillCode: string, type: string) {
    let redis = await this.app.redis.clients.get("fenjianji");
    try {
      //#region 校验信息
      if (!wayBillCode) {
        this.info.result = false;
        this.info.msg = "运单Id不能为空";
 
        return this.info;
      }
      //#endregion
      let waybill = await this.dbRead.findOne(TMSWayBill, {
        wayBillCode: wayBillCode
      });
      this.info.result = true;
      if (waybill) {
        //单据数据验证,1、异常件维护校验
        let abnormalList = await this.dbRead.find(TMSAbnormal, {
          portName: waybill.portName,
          panelType: "普通组板"
        });
        for (let abInfo of abnormalList) {
          if (abInfo.dataType == "运单拦截") {
            let abnormalData = abInfo.abnormalData;
            let abnormalDataList = abnormalData.replace("\r", "").split(/;|,|,|\\n/g);
            if (abnormalDataList.indexOf(waybill.wayBillCode) >= 0) {
              let msg = abInfo.dataType + ":" + waybill.wayBillCode + "被强制拦截";
              //#region
              waybill.actualDropOffPort = "0";
              waybill.groupBoard = "运单拦截";
              waybill.orderStatus = "组板异常";
              waybill.abnormalReason = msg;
              this.info.data = waybill;
              this.info.msg = msg;
              this.info.result = false;
              let abnormal = new TMSWayBillAbnormal();
              abnormal.abnormal = waybill.abnormalReason;
              abnormal.abnormalDate = new Date();
              abnormal.abnormalStatus = waybill.groupBoard;
              abnormal.wayBillCode = waybill.wayBillCode;
              abnormal.wayBill_Id = waybill.wayBill_Id;
              await this.dbWrite.save(abnormal);
 
              await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
                actualDropOffPort: waybill.actualDropOffPort,
                groupBoard: waybill.groupBoard,
                orderStatus: waybill.orderStatus,
                abnormalReason: waybill.abnormalReason
              });
 
              return this.info;
              //#endregion
            }
          }
        }
 
        if ("已组板,已退货,航空已发运,清关中,航班到达".indexOf(waybill.orderStatus) >= 0) {
          let msg = waybill.orderStatus + "运单不可组板";
          this.info.data = waybill;
          this.info.msg = msg;
          this.info.result = false;
          let abnormal = new TMSWayBillAbnormal();
          abnormal.abnormal = waybill.abnormalReason;
          abnormal.abnormalDate = new Date();
          abnormal.abnormalStatus = "组板失败";
          abnormal.wayBillCode = waybill.wayBillCode;
          abnormal.wayBill_Id = waybill.wayBill_Id;
          await this.dbWrite.save(abnormal);
          await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
            actualDropOffPort: "0",
            abnormalReason: waybill.abnormalReason
          });
 
          return this.info;
        }
        if (
          !waybill.provinceName ||
          !waybill.cityName ||
          !waybill.consigneeName ||
          !waybill.regionName ||
          !waybill.consigneeAddress ||
          waybill.consigneeAddress == waybill.provinceName + waybill.cityName + waybill.regionName
        ) {
          waybill.actualDropOffPort = "2";
          waybill.groupBoard = "组板失败";
          waybill.abnormalReason = "收货地址信息不完善";
          if (!waybill.consigneeName) {
            waybill.abnormalReason = "收货人姓名信息不完善";
          }
          if (waybill.makeWay == "TMS录入") {
            waybill.orderStatus = "录入异常";
          } else {
            waybill.orderStatus = "组板异常";
          }
          this.info.data = waybill;
          this.info.msg = waybill.abnormalReason;
          this.info.result = false;
          let abnormal = new TMSWayBillAbnormal();
          abnormal.abnormal = waybill.abnormalReason;
          abnormal.abnormalDate = new Date();
          abnormal.abnormalStatus = waybill.groupBoard;
          abnormal.wayBillCode = waybill.wayBillCode;
          abnormal.wayBill_Id = waybill.wayBill_Id;
 
          await this.dbWrite.save(abnormal);
          await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
            actualDropOffPort: waybill.actualDropOffPort,
            groupBoard: waybill.groupBoard,
            orderStatus: waybill.orderStatus,
            abnormalReason: waybill.abnormalReason
          });
 
          return this.info;
        }
 
        if (
          waybill.orderStatus == "新建" ||
          waybill.orderStatus == "面单已上传" ||
          waybill.orderStatus == "已提交" ||
          waybill.orderStatus == "终止"
        ) {
          waybill.actualDropOffPort = "2";
          waybill.groupBoard = "组板失败";
          waybill.abnormalReason = "运单未审核不可组板";
          this.info.data = waybill;
          this.info.msg = "运单未审核不可组板";
          this.info.result = false;
          let abnormal = new TMSWayBillAbnormal();
          abnormal.abnormal = waybill.abnormalReason;
          abnormal.abnormalDate = new Date();
          abnormal.abnormalStatus = waybill.groupBoard;
          abnormal.wayBillCode = waybill.wayBillCode;
          abnormal.wayBill_Id = waybill.wayBill_Id;
          await this.dbWrite.save(abnormal);
          await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
            actualDropOffPort: waybill.actualDropOffPort,
            groupBoard: waybill.groupBoard,
            orderStatus: waybill.orderStatus,
            abnormalReason: waybill.abnormalReason
          });
 
          return this.info;
        }
 
        //#region 计划口岸为空
        if (!waybill.planDropOffPort) {
          this.info.msg = "计划口岸为空,不可组板";
          this.info.result = false;
 
          return this.info;
        }
        //#endregion
 
        //#region 验证口岸不能为空
        if (waybill.portName == null) {
          waybill.actualDropOffPort = "2";
          waybill.groupBoard = "组板失败";
          waybill.orderStatus = "组板异常";
          waybill.abnormalReason = "口岸为空不可组板";
          this.info.data = waybill;
          this.info.msg = "口岸为空不可组板";
          this.info.result = false;
          let abnormal = new TMSWayBillAbnormal();
          abnormal.abnormal = "口岸为空不可组板";
          abnormal.abnormalDate = new Date();
          abnormal.abnormalStatus = "组板失败";
          abnormal.wayBillCode = waybill.wayBillCode;
          abnormal.wayBill_Id = waybill.wayBill_Id;
          await this.dbWrite.save(abnormal);
 
          await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
            actualDropOffPort: waybill.actualDropOffPort,
            groupBoard: waybill.groupBoard,
            orderStatus: waybill.orderStatus,
            abnormalReason: waybill.abnormalReason
          });
 
          return this.info;
        }
        //#endregion
 
        //#region 生成托盘号
        let port = await this.dbRead.findOne(TMSPort, {
          portName: waybill.portName
        });
        let rule = port.plateRule; //口岸组板规则
        if (port) {
          let Year = moment(new Date()).format("YYYY"); //获取年份
          let month = moment(new Date()).format("MM"); //获取月份
          let day = moment(new Date()).format("DD"); //获取月份
          let hour = moment(new Date()).format("HH"); //获取小时   // 20
          if (rule) {
            if (rule.indexOf("[yyyy]") > -1) {
              rule = rule.replace("[yyyy]", Year);
            }
            if (rule.indexOf("[MM]") > -1) {
              rule = rule.replace("[MM]", month);
            }
            if (rule.indexOf("[dd]") > -1) {
              rule = rule.replace("[dd]", day);
            }
            if (rule.indexOf("[hh]") > -1) {
              rule = rule.replace("[hh]", hour);
            }
          }
        }
        //#endregion
 
        //将数据写入redis
        let key = `${rule}_${waybill.wayBillCode}_${waybill.consigneeMobile}_${waybill.consigneeIdcard}_${waybill.consigneeAddress}_${waybill.consigneeName}_`;
        try {
          this.info.state = key;
          await redis.set(key, JSON.stringify(waybill));
          await redis.expire(key, 60 * 60 * 8);
        } catch (ex) {
          console.log("扫描数据redis错误:" + ex.message);
        }
 
        //#region 校验明细
        let detailList = await this.dbRead.find(TMSWayBillList, {
          wayBill_Id: waybill.wayBill_Id
        });
        if (detailList.length == 0) {
          //#region
          waybill.actualDropOffPort = "2";
          waybill.groupBoard = "组板失败";
          if (waybill.makeWay == "TMS录入") {
            waybill.orderStatus = "录入异常";
          } else {
            waybill.orderStatus = "组板异常";
          }
          waybill.abnormalReason = "无物料信息,物料(明细)信息不完整";
          this.info.data = waybill;
          this.info.msg = "无物料信息,物料(明细)信息不完整";
          this.info.result = false;
          let abnormal = new TMSWayBillAbnormal();
          abnormal.abnormal = waybill.abnormalReason;
          abnormal.abnormalDate = new Date();
          abnormal.abnormalStatus = waybill.groupBoard;
          abnormal.wayBillCode = waybill.wayBillCode;
          abnormal.wayBill_Id = waybill.wayBill_Id;
          await this.dbWrite.save(abnormal);
 
          await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
            actualDropOffPort: waybill.actualDropOffPort,
            groupBoard: waybill.groupBoard,
            orderStatus: waybill.orderStatus,
            abnormalReason: waybill.abnormalReason
          });
 
          return this.info;
          //#endregion
        }
        for (let item of detailList) {
          if (!item.productCode || !item.productModel || !item.productName) {
            //#region
            waybill.actualDropOffPort = "2";
            waybill.groupBoard = "组板失败";
            if (waybill.makeWay == "TMS录入") {
              waybill.orderStatus = "录入异常";
            } else {
              waybill.orderStatus = "组板异常";
            }
            waybill.abnormalReason = "物料明细信息不完整";
            this.info.data = waybill;
            this.info.msg = "物料明细信息不完整";
            this.info.result = false;
            let abnormal = new TMSWayBillAbnormal();
            abnormal.abnormal = waybill.abnormalReason;
            abnormal.abnormalDate = new Date();
            abnormal.abnormalStatus = waybill.groupBoard;
            abnormal.wayBillCode = waybill.wayBillCode;
            abnormal.wayBill_Id = waybill.wayBill_Id;
            await this.dbWrite.save(abnormal);
 
            await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
              actualDropOffPort: waybill.actualDropOffPort,
              groupBoard: waybill.groupBoard,
              orderStatus: waybill.orderStatus,
              abnormalReason: waybill.abnormalReason
            });
 
            return this.info;
            //#endregion
          }
        }
        //#endregion
 
        if (waybill.collectStatus != "已揽收") {
          waybill.actualDropOffPort = "0";
          waybill.abnormalReason = "运单未揽收,不可组板";
          this.info.data = waybill;
          this.info.msg = "运单未揽收,不可组板";
          this.info.result = false;
          let abnormal = new TMSWayBillAbnormal();
          abnormal.abnormal = "运单未揽收,不可组板";
          abnormal.abnormalDate = new Date();
          abnormal.abnormalStatus = "组板失败";
          abnormal.wayBillCode = waybill.wayBillCode;
          abnormal.wayBill_Id = waybill.wayBill_Id;
          await this.dbWrite.save(abnormal);
 
          await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
            actualDropOffPort: waybill.actualDropOffPort,
            groupBoard: waybill.groupBoard,
            orderStatus: waybill.orderStatus,
            abnormalReason: waybill.abnormalReason
          });
 
          return this.info;
        }
        if (waybill.orderStatus == "录入异常") {
          waybill.actualDropOffPort = "2";
          waybill.abnormalReason = "录入异常,不可组板";
          this.info.data = waybill;
          this.info.msg = "录入异常,不可组板";
          this.info.result = false;
          let abnormal = new TMSWayBillAbnormal();
          abnormal.abnormal = "录入异常,不可组板";
          abnormal.abnormalDate = new Date();
          abnormal.abnormalStatus = "组板失败";
          abnormal.wayBillCode = waybill.wayBillCode;
          abnormal.wayBill_Id = waybill.wayBill_Id;
          await this.dbWrite.save(abnormal);
 
          await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
            actualDropOffPort: waybill.actualDropOffPort,
            groupBoard: waybill.groupBoard,
            orderStatus: waybill.orderStatus,
            abnormalReason: waybill.abnormalReason
          });
 
          return this.info;
        }
 
        if (!waybill.expressCode) {
          waybill.actualDropOffPort = "2";
          waybill.abnormalReason = "国内快递单号不能为空";
          this.info.data = waybill;
          this.info.msg = "国内快递单号不能为空";
          this.info.result = false;
          let abnormal = new TMSWayBillAbnormal();
          abnormal.abnormal = "国内快递单号不能为空";
          abnormal.abnormalDate = new Date();
          abnormal.abnormalStatus = "组板失败";
          abnormal.wayBillCode = waybill.wayBillCode;
          abnormal.wayBill_Id = waybill.wayBill_Id;
          await this.dbWrite.save(abnormal);
 
          await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
            actualDropOffPort: waybill.actualDropOffPort,
            groupBoard: waybill.groupBoard,
            orderStatus: waybill.orderStatus,
            abnormalReason: waybill.abnormalReason
          });
 
          return this.info;
        }
        if (!waybill.expressCorpName) {
          waybill.actualDropOffPort = "2";
          waybill.groupBoard = "组板失败";
          waybill.orderStatus = "组板异常";
          waybill.abnormalReason = "国内快递公司为空不可组板";
          this.info.data = waybill;
          this.info.msg = "国内快递公司为空不可组板";
          this.info.result = false;
          let abnormal = new TMSWayBillAbnormal();
          abnormal.abnormal = "国内快递公司为空不可组板";
          abnormal.abnormalDate = new Date();
          abnormal.abnormalStatus = "组板失败";
          abnormal.wayBillCode = waybill.wayBillCode;
          abnormal.wayBill_Id = waybill.wayBill_Id;
          await this.dbWrite.save(abnormal);
 
          await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
            actualDropOffPort: waybill.actualDropOffPort,
            groupBoard: waybill.groupBoard,
            orderStatus: waybill.orderStatus,
            abnormalReason: waybill.abnormalReason
          });
 
          return this.info;
        }
        if (waybill.consigneeIdcard == null) {
          waybill.actualDropOffPort = "3";
          waybill.groupBoard = "组板失败";
          waybill.orderStatus = "组板异常";
          waybill.abnormalReason = "无身份证";
          this.info.data = waybill;
          this.info.msg = "无身份证";
          this.info.result = false;
          let abnormal = new TMSWayBillAbnormal();
          abnormal.abnormal = "无身份证";
          abnormal.abnormalDate = new Date();
          abnormal.abnormalStatus = "组板失败";
          abnormal.wayBillCode = waybill.wayBillCode;
          abnormal.wayBill_Id = waybill.wayBill_Id;
          await this.dbWrite.save(abnormal);
 
          await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
            actualDropOffPort: waybill.actualDropOffPort,
            groupBoard: waybill.groupBoard,
            orderStatus: waybill.orderStatus,
            abnormalReason: waybill.abnormalReason
          });
 
          //#region 无身份证组板失败发送短信 不用了
          try {
            // 无身份证组板失败发送短信
            //let msgInfo = new OA_CommonMessage();
            //msgInfo.MsgType = "无身份证";
            //msgInfo.ModuleName = "分拣机组板";
            //msgInfo.CreateID = 1;
            //msgInfo.Creator = "分拣机";
            //msgInfo.MainInnerCode = waybill.consigneeMobile;
            //msgInfo.message = waybill.wayBillCode;
            //msgInfo.MainId = 2828614; //短信编码
            //msgInfo.MsgStatus = "未发送";
            //OA_CommonMessageRepository.Instance.Add(msgInfo);
            //AoDeUcpaasHelper.SendYPZB(waybill.consigneeMobile, waybill.wayBillCode, 2828614);
          } catch (ex) {}
          //#endregion
 
          return this.info;
        }
        //单据数据验证,1、异常件维护校验
        for (let abInfo of abnormalList) {
          if (abInfo.dataType == "身份证号") {
            let abnormalData = abInfo.abnormalData;
            let abnormalDataList = abnormalData.replace("\r", "").split(/;|,|,|\\n/g);
            if (abnormalDataList.indexOf(waybill.consigneeIdcard) >= 0) {
              //#region
              waybill.actualDropOffPort = "2";
              waybill.groupBoard = "组板失败";
              waybill.orderStatus = "组板异常";
              waybill.abnormalReason = abInfo.dataType + ":" + waybill.consigneeIdcard + "被" + abInfo.abnormalType;
              this.info.data = waybill;
              this.info.msg = abInfo.dataType + ":" + waybill.consigneeIdcard + "被" + abInfo.abnormalType;
              this.info.result = false;
              let abnormal = new TMSWayBillAbnormal();
              abnormal.abnormal = waybill.abnormalReason;
              abnormal.abnormalDate = new Date();
              abnormal.abnormalStatus = waybill.groupBoard;
              abnormal.wayBillCode = waybill.wayBillCode;
              abnormal.wayBill_Id = waybill.wayBill_Id;
              await this.dbWrite.save(abnormal);
 
              await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
                actualDropOffPort: waybill.actualDropOffPort,
                groupBoard: waybill.groupBoard,
                orderStatus: waybill.orderStatus,
                abnormalReason: waybill.abnormalReason
              });
 
              return this.info;
              //#endregion
            }
          }
          if (abInfo.dataType == "物料条码") {
            for (let item of detailList) {
              let abnormalData = abInfo.abnormalData;
              let abnormalDataList = abnormalData.replace("\r", "").split(/;|,|,|\\n/g);
              if (abnormalDataList.indexOf(item.productModel) >= 0) {
                //#region
                waybill.actualDropOffPort = "2";
                waybill.groupBoard = "组板失败";
                waybill.orderStatus = "组板异常";
                waybill.abnormalReason = abInfo.dataType + ":" + item.productModel + "被" + abInfo.abnormalType;
                this.info.data = waybill;
                this.info.msg = abInfo.dataType + ":" + item.productModel + "被" + abInfo.abnormalType;
                this.info.result = false;
                let abnormal = new TMSWayBillAbnormal();
                abnormal.abnormal = waybill.abnormalReason;
                abnormal.abnormalDate = new Date();
                abnormal.abnormalStatus = waybill.groupBoard;
                abnormal.wayBillCode = waybill.wayBillCode;
                abnormal.wayBill_Id = waybill.wayBill_Id;
                await this.dbWrite.save(abnormal);
 
                await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
                  actualDropOffPort: waybill.actualDropOffPort,
                  groupBoard: waybill.groupBoard,
                  orderStatus: waybill.orderStatus,
                  abnormalReason: waybill.abnormalReason
                });
 
                return this.info;
                //#endregion
              }
            }
          }
        }
 
        //单据数据验证,2、异常件维护校验(综合组板)
        let portName = waybill.portName || waybill.portName;
        let storageName = waybill.storageName || waybill.storageName;
        let expressCorpName = waybill.expressCorpName || waybill.expressCorpName;
        let where = `portName='${portName}' and panelType='综合组板' And storageName='${storageName}' And expressCorpName='${expressCorpName}' 
                        And (BeginTime IS NULL OR BeginTime<=getdate()) And (EndTime IS NULL OR EndTime>=getdate())`;
        let colligateabnormalList = await this.dbRead.find(TMSAbnormal, {
          where: where
        });
        for (let abInfo of colligateabnormalList) {
          if (abInfo.dataType == "身份证号") {
            if (abInfo.abnormalData && abInfo.abnormalData.indexOf(waybill.consigneeIdcard) >= 0) {
              waybill.actualDropOffPort = "2";
              waybill.groupBoard = "组板失败";
              waybill.orderStatus = "组板异常";
              waybill.abnormalReason = abInfo.dataType + ":" + waybill.consigneeIdcard + "被" + abInfo.abnormalType;
              this.info.data = waybill;
              this.info.msg = abInfo.dataType + ":" + waybill.consigneeIdcard + "被" + abInfo.abnormalType;
              this.info.result = false;
              let abnormal = new TMSWayBillAbnormal();
              abnormal.abnormal = waybill.abnormalReason;
              abnormal.abnormalDate = new Date();
              abnormal.abnormalStatus = waybill.groupBoard;
              abnormal.wayBillCode = waybill.wayBillCode;
              abnormal.wayBill_Id = waybill.wayBill_Id;
              await this.dbWrite.save(abnormal);
 
              await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
                actualDropOffPort: waybill.actualDropOffPort,
                groupBoard: waybill.groupBoard,
                orderStatus: waybill.orderStatus,
                abnormalReason: waybill.abnormalReason
              });
 
              return this.info;
            }
          }
          if (abInfo.addressee) {
            // 是否包含,目前只有包含
            let AddresseeContain = true; // abInfo.AddresseeContain == "1";
            let addList = JSON.parse(abInfo.addressee);
            for (let item of addList) {
              let provinceName = "";
              let cityName = "";
              let regionName = "";
              try {
                provinceName = item.provinceName;
                cityName = item.cityName;
                regionName = item.regionName;
              } catch {}
              let isExist = false;
              let msg = "";
              if (waybill.provinceName == provinceName) {
                if (cityName) {
                  if (regionName) {
                    isExist = waybill.cityName == cityName && waybill.regionName == regionName;
                    msg = provinceName + cityName + regionName + "在" + waybill.portName + "被禁止";
                  } else {
                    isExist = waybill.cityName == cityName;
                    msg = provinceName + cityName + "在" + waybill.portName + "被禁止";
                  }
                } else {
                  isExist = true;
                  msg = provinceName + "在" + waybill.portName + "被禁止";
                }
              } else {
                // 不包含
                if (!AddresseeContain) {
                  isExist = true;
                }
              }
 
              // (isExist && AddresseeContain)=为包含省市区禁止组板,标记为组板异常
              // (!isExist && !AddresseeContain)=为不包含省市区禁止组板,标记为组板异常
              if ((isExist && AddresseeContain) || (!isExist && !AddresseeContain)) {
                waybill.actualDropOffPort = "2";
                waybill.groupBoard = "组板失败";
                waybill.orderStatus = "组板异常";
                waybill.abnormalReason = msg;
                this.info.data = waybill;
                this.info.msg = msg;
                this.info.result = false;
                let abnormal = new TMSWayBillAbnormal();
                abnormal.abnormal = waybill.abnormalReason;
                abnormal.abnormalDate = new Date();
                abnormal.abnormalStatus = waybill.groupBoard;
                abnormal.wayBillCode = waybill.wayBillCode;
                abnormal.wayBill_Id = waybill.wayBill_Id;
                await this.dbWrite.save(abnormal);
 
                await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
                  actualDropOffPort: waybill.actualDropOffPort,
                  groupBoard: waybill.groupBoard,
                  orderStatus: waybill.orderStatus,
                  abnormalReason: waybill.abnormalReason
                });
 
                return this.info;
              }
            }
          }
        }
 
        //#region 口岸规则
        if (port.portRule != "[]") {
          let portRule = JSON.parse(port.portRule);
          for (let item of portRule.checkRule) {
            // ["相同托盘号下相同的信息存在", "单个包裹申报货值不差过", "单个包裹重量不超过"],
            if (item == "相同托盘号下相同的信息存在") {
              let existNumber = portRule.existNumber;
 
              //根据预先生成的托盘号且主单为空的运单
              for (let term of portRule.checkWhere) {
                // ["手机号", "身份证号"]
                if (term == "手机号") {
                  //先从Redis中获取数据验证
                  let keys = await redis.keys("*" + rule + "_*" + waybill.consigneeMobile + "_*");
                  let redisDataList = keys.filter(w => w.indexOf(waybill.wayBillCode) < 0);
                  if (redisDataList.length > existNumber) {
                    //#region
                    waybill.abnormalReason = "同一主单号下手机号已存在重复" + existNumber + "次限制(redis)";
                    waybill.actualDropOffPort = "3"; //异常口
                    waybill.groupBoard = "组板失败";
                    waybill.orderStatus = "组板异常";
                    this.info.msg = waybill.abnormalReason;
                    this.info.result = false;
                    this.info.data = waybill;
                    let abnormal = new TMSWayBillAbnormal();
                    abnormal.abnormal = waybill.abnormalReason;
                    abnormal.abnormalDate = new Date();
                    abnormal.abnormalStatus = waybill.groupBoard;
                    abnormal.wayBillCode = waybill.wayBillCode;
                    abnormal.wayBill_Id = waybill.wayBill_Id;
                    await this.dbWrite.save(abnormal);
 
                    await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
                      actualDropOffPort: waybill.actualDropOffPort,
                      groupBoard: waybill.groupBoard,
                      orderStatus: waybill.orderStatus,
                      abnormalReason: waybill.abnormalReason
                    });
 
                    return this.info;
                    //#endregion
                  }
 
                  //#region
                  let _wayBillList = await this.dbRead.find(TMSWayBill, {
                    select: ["wayBill_Id"],
                    where: {
                      orderStatus: "已组板",
                      plateCode: rule,
                      consigneeMobile: waybill.consigneeMobile
                    }
                  });
                  let cnt = _wayBillList.length;
                  if (cnt > existNumber) {
                    //#region
                    waybill.abnormalReason = "同一主单号下手机号已存在重复" + portRule.existNumber + "次限制";
                    waybill.actualDropOffPort = "3"; //异常口
                    waybill.groupBoard = "组板失败";
                    waybill.orderStatus = "组板异常";
                    this.info.msg = "同一主单号下手机号已存在重复" + portRule.existNumber + "次限制";
                    this.info.result = false;
                    this.info.data = waybill;
                    let abnormal = new TMSWayBillAbnormal();
                    abnormal.abnormal = waybill.abnormalReason;
                    abnormal.abnormalDate = new Date();
                    abnormal.abnormalStatus = waybill.groupBoard;
                    abnormal.wayBillCode = waybill.wayBillCode;
                    abnormal.wayBill_Id = waybill.wayBill_Id;
                    await this.dbWrite.save(abnormal);
 
                    await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
                      actualDropOffPort: waybill.actualDropOffPort,
                      groupBoard: waybill.groupBoard,
                      orderStatus: waybill.orderStatus,
                      abnormalReason: waybill.abnormalReason
                    });
 
                    return this.info;
                    //#endregion
                  }
                  //#endregion
                }
                if (term == "身份证号") {
                  //先从Redis中获取数据验证
                  let keys = await redis.keys("*" + rule + "_*" + waybill.consigneeIdcard + "_*");
                  let redisDataList = keys.filter(w => w.indexOf(waybill.wayBillCode) < 0);
                  if (redisDataList.length > existNumber) {
                    //#region
                    waybill.actualDropOffPort = "3"; //异常口
                    waybill.groupBoard = "组板失败";
                    waybill.orderStatus = "组板异常";
                    waybill.abnormalReason = "同一主单号下身份证已存在重复" + portRule.existNumber + "次限制(redis)";
                    this.info.result = false;
                    this.info.msg = waybill.abnormalReason;
                    this.info.data = waybill;
                    let abnormal = new TMSWayBillAbnormal();
                    abnormal.abnormal = waybill.abnormalReason;
                    abnormal.abnormalDate = new Date();
                    abnormal.abnormalStatus = waybill.groupBoard;
                    abnormal.wayBillCode = waybill.wayBillCode;
                    abnormal.wayBill_Id = waybill.wayBill_Id;
                    await this.dbWrite.save(abnormal);
 
                    await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
                      actualDropOffPort: waybill.actualDropOffPort,
                      groupBoard: waybill.groupBoard,
                      orderStatus: waybill.orderStatus,
                      abnormalReason: waybill.abnormalReason
                    });
 
                    return this.info;
                    //#endregion
                  }
 
                  //#region
                  let _wayBillList = await this.dbRead.find(TMSWayBill, {
                    select: ["wayBill_Id"],
                    where: {
                      orderStatus: "已组板",
                      plateCode: rule,
                      consigneeIdcard: waybill.consigneeIdcard
                    }
                  });
                  let cnt = _wayBillList.length;
                  if (cnt > existNumber) {
                    //#region
                    waybill.actualDropOffPort = "3"; //异常口
                    waybill.groupBoard = "组板失败";
                    waybill.orderStatus = "组板异常";
                    waybill.abnormalReason = "同一主单号下身份证已存在重复" + portRule.existNumber + "次限制";
                    this.info.result = false;
                    this.info.msg = "同一主单号下身份证已存在重复" + portRule.existNumber + "次限制";
                    this.info.data = waybill;
                    let abnormal = new TMSWayBillAbnormal();
                    abnormal.abnormal = waybill.abnormalReason;
                    abnormal.abnormalDate = new Date();
                    abnormal.abnormalStatus = waybill.groupBoard;
                    abnormal.wayBillCode = waybill.wayBillCode;
                    abnormal.wayBill_Id = waybill.wayBill_Id;
                    await this.dbWrite.save(abnormal);
 
                    await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
                      actualDropOffPort: waybill.actualDropOffPort,
                      groupBoard: waybill.groupBoard,
                      orderStatus: waybill.orderStatus,
                      abnormalReason: waybill.abnormalReason
                    });
 
                    return this.info;
                    //#endregion
                  }
                  //#endregion
                }
                if (term == "姓名") {
                  //#region
                  let _wayBillList = await this.dbRead.find(TMSWayBill, {
                    select: ["wayBill_Id"],
                    where: {
                      orderStatus: "已组板",
                      plateCode: rule,
                      consigneeName: waybill.consigneeName
                    }
                  });
                  let cnt = _wayBillList.length;
                  if (cnt > existNumber) {
                    //#region
                    waybill.actualDropOffPort = "3"; //异常口
                    waybill.groupBoard = "组板失败";
                    waybill.orderStatus = "组板异常";
                    waybill.abnormalReason = "同一主单号下姓名已存在重复" + portRule.existNumber + "次限制";
                    this.info.result = false;
                    this.info.msg = "同一主单号下姓名已存在重复" + portRule.existNumber + "次限制";
                    this.info.data = waybill;
                    let abnormal = new TMSWayBillAbnormal();
                    abnormal.abnormal = waybill.abnormalReason;
                    abnormal.abnormalDate = new Date();
                    abnormal.abnormalStatus = waybill.groupBoard;
                    abnormal.wayBillCode = waybill.wayBillCode;
                    abnormal.wayBill_Id = waybill.wayBill_Id;
                    await this.dbWrite.save(abnormal);
 
                    await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
                      actualDropOffPort: waybill.actualDropOffPort,
                      groupBoard: waybill.groupBoard,
                      orderStatus: waybill.orderStatus,
                      abnormalReason: waybill.abnormalReason
                    });
 
                    return this.info;
                    //#endregion
                  }
                  //#endregion
                }
                if (term == "地址") {
                  //先从Redis中获取数据验证
                  let keys = await redis.keys("*" + rule + "_*" + waybill.consigneeAddress + "_*");
                  let redisDataList = keys.filter(w => w.indexOf(waybill.wayBillCode) < 0);
                  if (redisDataList.length > existNumber) {
                    //#region
                    waybill.actualDropOffPort = "3"; //异常口
                    waybill.groupBoard = "组板失败";
                    waybill.orderStatus = "组板异常";
                    waybill.abnormalReason = "同一主单号下地址已存在重复" + portRule.existNumber + "次限制(redis)";
                    this.info.result = false;
                    this.info.msg = waybill.abnormalReason;
                    this.info.data = waybill;
                    let abnormal = new TMSWayBillAbnormal();
                    abnormal.abnormal = waybill.abnormalReason;
                    abnormal.abnormalDate = new Date();
                    abnormal.abnormalStatus = waybill.groupBoard;
                    abnormal.wayBillCode = waybill.wayBillCode;
                    abnormal.wayBill_Id = waybill.wayBill_Id;
                    await this.dbWrite.save(abnormal);
 
                    await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
                      actualDropOffPort: waybill.actualDropOffPort,
                      groupBoard: waybill.groupBoard,
                      orderStatus: waybill.orderStatus,
                      abnormalReason: waybill.abnormalReason
                    });
 
                    return this.info;
                    //#endregion
                  }
 
                  //#region
                  let _wayBillList = await this.dbRead.find(TMSWayBill, {
                    select: ["wayBill_Id"],
                    where: {
                      orderStatus: "已组板",
                      plateCode: rule,
                      consigneeAddress: waybill.consigneeAddress
                    }
                  });
                  let cnt = _wayBillList.length;
                  if (cnt > existNumber) {
                    //#region
                    waybill.actualDropOffPort = "3"; //异常口
                    waybill.groupBoard = "组板失败";
                    waybill.orderStatus = "组板异常";
                    waybill.abnormalReason = "同一主单号下地址已存在重复" + portRule.existNumber + "次限制";
                    this.info.result = false;
                    this.info.msg = "同一主单号下地址已存在重复" + portRule.existNumber + "次限制";
                    this.info.data = waybill;
                    let abnormal = new TMSWayBillAbnormal();
                    abnormal.abnormal = waybill.abnormalReason;
                    abnormal.abnormalDate = new Date();
                    abnormal.abnormalStatus = waybill.groupBoard;
                    abnormal.wayBillCode = waybill.wayBillCode;
                    abnormal.wayBill_Id = waybill.wayBill_Id;
                    await this.dbWrite.save(abnormal);
 
                    await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
                      actualDropOffPort: waybill.actualDropOffPort,
                      groupBoard: waybill.groupBoard,
                      orderStatus: waybill.orderStatus,
                      abnormalReason: waybill.abnormalReason
                    });
 
                    return this.info;
                    //#endregion
                  }
                  //#endregion
                }
              }
            }
            if (item == "单个包裹重量不超过") {
              let existWeight = portRule.existWeight;
              let weight = waybill.grossWeight || 0;
              if (weight > existWeight) {
                waybill.actualDropOffPort = "2";
                waybill.groupBoard = "组板失败";
                waybill.orderStatus = "组板异常";
                waybill.abnormalReason = "单个包裹重量不超过" + existWeight;
                this.info.data = waybill;
                this.info.msg = "单个包裹重量不超过" + existWeight;
                this.info.result = false;
                let abnormal = new TMSWayBillAbnormal();
                abnormal.abnormal = waybill.abnormalReason;
                abnormal.abnormalDate = new Date();
                abnormal.abnormalStatus = waybill.groupBoard;
                abnormal.wayBillCode = waybill.wayBillCode;
                abnormal.wayBill_Id = waybill.wayBill_Id;
                await this.dbWrite.save(abnormal);
 
                await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
                  actualDropOffPort: waybill.actualDropOffPort,
                  groupBoard: waybill.groupBoard,
                  orderStatus: waybill.orderStatus,
                  abnormalReason: waybill.abnormalReason
                });
 
                return this.info;
              }
            }
            if (item == "单个包裹申报货值不差过") {
              //let existMoney = portRule.ExistMoney;
              //let Money
            }
            if (item == "需身份证正反面照片") {
              let cardInfo = await this.dbRead.findOne(TMSIdCard, {
                idCardCode: waybill.consigneeIdcard
              });
              if (!cardInfo || !cardInfo.positiveServerUrl || !cardInfo.negativeServerUrl) {
                waybill.abnormalReason = "需身份证正反面照片";
                waybill.actualDropOffPort = "3"; //异常口
                waybill.groupBoard = "组板失败";
                waybill.orderStatus = "组板异常";
 
                this.info.data = waybill;
                this.info.msg = waybill.wayBillCode + "需身份证正反面照片";
                this.info.result = false;
                let abnormal = new TMSWayBillAbnormal();
                abnormal.abnormal = waybill.abnormalReason;
                abnormal.abnormalDate = new Date();
                abnormal.abnormalStatus = waybill.groupBoard;
                abnormal.wayBillCode = waybill.wayBillCode;
                abnormal.wayBill_Id = waybill.wayBill_Id;
                await this.dbWrite.save(abnormal);
 
                await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
                  actualDropOffPort: waybill.actualDropOffPort,
                  groupBoard: waybill.groupBoard,
                  orderStatus: waybill.orderStatus,
                  abnormalReason: waybill.abnormalReason
                });
 
                return this.info;
              }
            }
          }
        }
        //#endregion
 
        //#region 更新组板结果
        if (this.info.result) {
          waybill.actualDropOffPort = waybill.planDropOffPort;
          waybill.groupBoard = "组板成功";
          waybill.abnormalReason = null;
          waybill.orderStatus = "已组板";
          waybill.groupBoardDate = new Date();
          waybill.panelWay = type;
          // 已生成好的托盘规则
          waybill.plateCode = rule;
          //WayBillHelper.SetStatusHistory(waybill, "分拣机组板", "已组板", "出库扫描完毕,等待发往机场");
        } else {
          waybill.groupBoard = "组板失败";
          if (waybill.orderStatus != "已提交") {
            //状态已提交的不改变状态
            waybill.orderStatus = "组板异常";
          }
          waybill.panelWay = type;
          waybill.abnormalReason = this.info.msg;
          //WayBillHelper.SetStatusHistory(waybill, "分拣机组板", "组板异常," + this.info.msg);
        }
 
        await this.dbWrite.update(TMSWayBill, waybill.wayBill_Id, {
          actualDropOffPort: waybill.actualDropOffPort,
          groupBoard: waybill.groupBoard,
          orderStatus: waybill.orderStatus,
          abnormalReason: waybill.abnormalReason
        });
 
        //#endregion
 
        this.info.result = true;
        this.info.data = waybill;
 
        return this.info;
      } else {
        let wayReceiveInfo = await this.dbRead.findOne(TMSWayBillReceive, {
          wayBillCode: wayBillCode
        });
        if (wayReceiveInfo) {
          if (wayReceiveInfo.collectStatus == "已退货") {
            //#region
            let msg = "已退货运单不可组板";
            waybill = new TMSWayBill();
            waybill.wayBillCode = wayReceiveInfo.wayBillCode;
            waybill.actualDropOffPort = "0";
            waybill.abnormalReason = msg;
            this.info.data = waybill;
            this.info.msg = msg;
            this.info.result = false;
            let abnormal = new TMSWayBillAbnormal();
            abnormal.abnormal = waybill.abnormalReason;
            abnormal.abnormalDate = new Date();
            abnormal.abnormalStatus = "组板失败";
            abnormal.wayBillCode = waybill.wayBillCode;
            abnormal.wayBill_Id = wayReceiveInfo.wayBillReceive_Id;
            abnormal.abnormalRemark = msg;
            await this.dbWrite.save(abnormal);
 
            //WayBillHelper.SetStatusHistory(waybill, "分拣机组板", "组板异常");
 
            return this.info;
            //#endregion
          } else if (wayReceiveInfo.collectStatus == "待揽收" || wayReceiveInfo.collectStatus == "未揽收") {
            //#region
            let msg = "未揽收运单不可组板";
            waybill = new TMSWayBill();
            waybill.wayBillCode = wayReceiveInfo.wayBillCode;
            waybill.actualDropOffPort = "0";
            waybill.abnormalReason = msg;
            this.info.data = waybill;
            this.info.msg = msg;
            this.info.result = false;
            let abnormal = new TMSWayBillAbnormal();
            abnormal.abnormal = waybill.abnormalReason;
            abnormal.abnormalDate = new Date();
            abnormal.abnormalStatus = "组板失败";
            abnormal.wayBillCode = waybill.wayBillCode;
            abnormal.wayBill_Id = wayReceiveInfo.wayBillReceive_Id;
            abnormal.abnormalRemark = msg;
            await this.dbWrite.save(abnormal);
 
            //WayBillHelper.SetStatusHistory(waybill, "分拣机组板", "组板异常");
 
            return this.info;
            //#endregion
          } else if (wayReceiveInfo.collectStatus == "已揽收") {
            //#region
            let msg = "已揽收但未录入运单不可组板";
            waybill = new TMSWayBill();
            waybill.wayBillCode = wayReceiveInfo.wayBillCode;
            waybill.actualDropOffPort = "2";
            waybill.abnormalReason = msg;
            this.info.data = waybill;
            this.info.msg = msg;
            this.info.result = false;
            let abnormal = new TMSWayBillAbnormal();
            abnormal.abnormal = waybill.abnormalReason;
            abnormal.abnormalDate = new Date();
            abnormal.abnormalStatus = "组板失败";
            abnormal.wayBillCode = waybill.wayBillCode;
            abnormal.wayBill_Id = wayReceiveInfo.wayBillReceive_Id;
            abnormal.abnormalRemark = msg;
            await this.dbWrite.save(abnormal);
 
            //WayBillHelper.SetStatusHistory(waybill, "分拣机组板", "组板异常");
 
            return this.info;
            //#endregion
          } else {
            //#region
            let msg = wayReceiveInfo.collectStatus + "运单不可组板";
            waybill = new TMSWayBill();
            waybill.wayBillCode = wayReceiveInfo.wayBillCode;
            waybill.actualDropOffPort = "0";
            waybill.abnormalReason = msg;
            this.info.data = waybill;
            this.info.msg = msg;
            this.info.result = false;
            let abnormal = new TMSWayBillAbnormal();
            abnormal.abnormal = waybill.abnormalReason;
            abnormal.abnormalDate = new Date();
            abnormal.abnormalStatus = "组板失败";
            abnormal.wayBillCode = waybill.wayBillCode;
            abnormal.wayBill_Id = wayReceiveInfo.wayBillReceive_Id;
            abnormal.abnormalRemark = msg;
            await this.dbWrite.save(abnormal);
 
            //WayBillHelper.SetStatusHistory(waybill, "分拣机组板", "组板异常");
 
            return this.info;
            //#endregion
          }
        } else {
          this.info.result = false;
          this.info.msg = "运单不存在";
 
          return this.info;
        }
      }
    } catch (ex) {
      this.info.result = false;
      this.info.msg = ex.message;
 
      return this.info;
    }
  }
}