Originmanifestsecondary.java 33.3 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
package com.tianbo.analysis.model;


import com.tianbo.analysis.exception.FFMResolveException;
import com.tianbo.analysis.tools.WaybillTools;
import com.tianbo.util.Date.DateUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;

import javax.validation.constraints.NotNull;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Data
@Slf4j
public class Originmanifestsecondary {
    private String autoid;

    private String waybillnomaster;

    private String waybillnosecondary;

    private String weight;

    private String piece;

    private String manifestpiece;

    private String manifestweight;

    private String productname;

    private String paymode;

    private String specialgoodscode;

    private String customscode;

    private String shippername;

    private String shipperaddress;

    private String consigneename;

    private String consigneeaddress;

    private Date createdate;

    private String originmanifestmasterautoid;

    private String customsstatus;

    private String status;

    private String receiption;

    private String originatingstationBill;

    private String destinationstationBill;

    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;

    private ORIGINMANIFESTMASTER master;

    public String text;
    public List<String> lineList;

    private static final String KEY_WORD = "FHL,MBI,HBS,TXT,HTS,SHP,CNE,NAM,ADR,LOC,CVD,OSI,COR,OCI,DEG,DIM";

    private String TEMP_KEY_WORD="";

    //报文结束标识
    private static String END_WORD= "=";

    public String getAutoid() {
        return autoid;
    }

    public void setAutoid(String autoid) {
        this.autoid = autoid == null ? null : autoid.trim();
    }

    public String getWaybillnomaster() {
        return waybillnomaster;
    }

    public void setWaybillnomaster(String waybillnomaster) {
        this.waybillnomaster = waybillnomaster == null ? null : waybillnomaster.trim();
    }

    public String getWaybillnosecondary() {
        return waybillnosecondary;
    }

    public void setWaybillnosecondary(String waybillnosecondary) {
        this.waybillnosecondary = waybillnosecondary == null ? null : waybillnosecondary.trim();
    }

    public String getWeight() {
        return weight;
    }

    public void setWeight(String weight) {
        this.weight = weight == null ? null : weight.trim();
    }

    public String getPiece() {
        return piece;
    }

    public void setPiece(String piece) {
        this.piece = piece == null ? null : piece.trim();
    }

    public String getManifestpiece() {
        return manifestpiece;
    }

    public void setManifestpiece(String manifestpiece) {
        this.manifestpiece = manifestpiece == null ? null : manifestpiece.trim();
    }

    public String getManifestweight() {
        return manifestweight;
    }

    public void setManifestweight(String manifestweight) {
        this.manifestweight = manifestweight == null ? null : manifestweight.trim();
    }

    public String getProductname() {
        return productname;
    }

    public void setProductname(String productname) {
        this.productname = productname == null ? null : productname.trim();
    }

    public String getPaymode() {
        return paymode;
    }

    public void setPaymode(String paymode) {
        this.paymode = paymode == null ? null : paymode.trim();
    }

    public String getSpecialgoodscode() {
        return specialgoodscode;
    }

    public void setSpecialgoodscode(String specialgoodscode) {
        this.specialgoodscode = specialgoodscode == null ? null : specialgoodscode.trim();
    }

    public String getCustomscode() {
        return customscode;
    }

    public void setCustomscode(String customscode) {
        this.customscode = customscode == null ? null : customscode.trim();
    }

    public String getShippername() {
        return shippername;
    }

    public void setShippername(String shippername) {
        this.shippername = shippername == null ? null : shippername.trim();
    }

    public String getShipperaddress() {
        return shipperaddress;
    }

    public void setShipperaddress(String shipperaddress) {
        this.shipperaddress = shipperaddress == null ? null : shipperaddress.trim();
    }

    public String getConsigneename() {
        return consigneename;
    }

    public void setConsigneename(String consigneename) {
        this.consigneename = consigneename == null ? null : consigneename.trim();
    }

    public String getConsigneeaddress() {
        return consigneeaddress;
    }

    public void setConsigneeaddress(String consigneeaddress) {
        this.consigneeaddress = consigneeaddress == null ? null : consigneeaddress.trim();
    }

    public Date getCreatedate() {
        return createdate;
    }

    public void setCreatedate(Date createdate) {
        this.createdate = createdate;
    }

    public String getOriginmanifestmasterautoid() {
        return originmanifestmasterautoid;
    }

    public void setOriginmanifestmasterautoid(String originmanifestmasterautoid) {
        this.originmanifestmasterautoid = originmanifestmasterautoid == null ? null : originmanifestmasterautoid.trim();
    }

    public String getCustomsstatus() {
        return customsstatus;
    }

    public void setCustomsstatus(String customsstatus) {
        this.customsstatus = customsstatus == null ? null : customsstatus.trim();
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status == null ? null : status.trim();
    }

    public String getReceiption() {
        return receiption;
    }

    public void setReceiption(String receiption) {
        this.receiption = receiption == null ? null : receiption.trim();
    }

    public String getOriginatingstationBill() {
        return originatingstationBill;
    }

    public void setOriginatingstationBill(String originatingstationBill) {
        this.originatingstationBill = originatingstationBill == null ? null : originatingstationBill.trim();
    }

    public String getDestinationstationBill() {
        return destinationstationBill;
    }

    public void setDestinationstationBill(String destinationstationBill) {
        this.destinationstationBill = destinationstationBill == null ? null : destinationstationBill.trim();
    }

    public String getShipperCode() {
        return shipperCode;
    }

    public void setShipperCode(String shipperCode) {
        this.shipperCode = shipperCode == null ? null : shipperCode.trim();
    }

    public String getShipperCountrycode() {
        return shipperCountrycode;
    }

    public void setShipperCountrycode(String shipperCountrycode) {
        this.shipperCountrycode = shipperCountrycode == null ? null : shipperCountrycode.trim();
    }

    public String getShipperPhone() {
        return shipperPhone;
    }

    public void setShipperPhone(String shipperPhone) {
        this.shipperPhone = shipperPhone == null ? null : shipperPhone.trim();
    }

    public String getShipperFax() {
        return shipperFax;
    }

    public void setShipperFax(String shipperFax) {
        this.shipperFax = shipperFax == null ? null : shipperFax.trim();
    }

    public String getConsigneeCode() {
        return consigneeCode;
    }

    public void setConsigneeCode(String consigneeCode) {
        this.consigneeCode = consigneeCode == null ? null : consigneeCode.trim();
    }

    public String getConsigneeCountrycode() {
        return consigneeCountrycode;
    }

    public void setConsigneeCountrycode(String consigneeCountrycode) {
        this.consigneeCountrycode = consigneeCountrycode == null ? null : consigneeCountrycode.trim();
    }

    public String getConsigneeFax() {
        return consigneeFax;
    }

    public void setConsigneeFax(String consigneeFax) {
        this.consigneeFax = consigneeFax == null ? null : consigneeFax.trim();
    }

    public String getSpecificConsigneename() {
        return specificConsigneename;
    }

    public void setSpecificConsigneename(String specificConsigneename) {
        this.specificConsigneename = specificConsigneename == null ? null : specificConsigneename.trim();
    }

    public String getSpecificConsigneePhone() {
        return specificConsigneePhone;
    }

    public void setSpecificConsigneePhone(String specificConsigneePhone) {
        this.specificConsigneePhone = specificConsigneePhone == null ? null : specificConsigneePhone.trim();
    }

    public String getConsigneePhone() {
        return consigneePhone;
    }

    public void setConsigneePhone(String consigneePhone) {
        this.consigneePhone = consigneePhone == null ? null : consigneePhone.trim();
    }

    public Originmanifestsecondary(){

    }

    public Originmanifestsecondary(String waybillnomaster, String waybillnosecondary, String originmanifestmasterautoid) {
        this.waybillnomaster = waybillnomaster;
        this.waybillnosecondary = waybillnosecondary;
        this.originmanifestmasterautoid = originmanifestmasterautoid;
    }


    /**
     * 校验报文结尾标识
     * 将报文字符窜转换成行数组
     * @return
     * @throws IOException
     * @throws FFMResolveException
     */
    public boolean textToStringList() throws IOException, FFMResolveException {
        if (StringUtils.isNotBlank(text) && text.contains("FHL/")) {
            lineList = new ArrayList<>();

                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;
        }
        log.error("[FHL]-{}->报文不属于分单报",text);
        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("[FHL] 行[{}]中包含非允许特殊字符,报文中只允许包含-[{}]等特殊字符",i," / -. Space < =");
                    throw new FFMResolveException("[FHL] 报文中包含特殊字符,报文中只允许包含 / -. 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;
    }

    /**
     * 根据关键字适配解析方法
     * @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 "FHL":
                fhlInfoParse(line);
                break;
            case "MBI":
                mbiInfoParse(line);
                break;
            case "HBS":
                hbsInfoParse(line);
                break;
            case "TXT":
                textInfoParse(line);
                break;
            case "HTS":
                htsInfoParse(line);
                break;
            case "SHP":
                shipperHasSplitParse(line,"SHP");
                break;
            case "CNE":
                shipperHasSplitParse(line,"CNE");
                break;
            case "OCI":
                ociInfoParse(line);
                break;
            case "CVD":
                cvdParse(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 "HBS-SHC":
                hbsOtherInfoParse(line);
                break;
            case "TXT":
                textInfoParse(line);
                break;
            case "HTS":
                htsInfoParse(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 "OCI":
                ociInfoParse(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.contains(s_3)){
                return s_3;
            }
        }
        return "NOT_KEYWORD";
    }

    /**
     * FHL信息解析
     * @param verlLine FHL-报文版本行信息解析
     */
    public boolean fhlInfoParse(String verlLine) throws FFMResolveException {
        log.debug("[TEXT] 找到FHL开头节点");
        //校验正则1,取前三位验证是否是机场代码
        String pattern = "^FHL/\\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());
            return true;
        }
        throw new FFMResolveException("[FLIGHT] FHL版本信息错误");
    }

    /**
     * 主单行信息解析
     * @param mbiLine MBI-主单行信息解析
     */
    public boolean mbiInfoParse(String mbiLine) throws FFMResolveException {
        log.debug("[TEXT] 找到MBI主单开头节点");
        //校验正则1,取前三位验证是否是机场代码
        String pattern = "^MBI/(\\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(mbiLine);
        //格式正则校验
        if(m.find()){
            waybillnomaster = m.group(1);

            //主单模七校验
            if(WaybillTools.model7Check(waybillnomaster)){
                log.debug("[AWB] 运单-({})模七校验通过",waybillnomaster);
            }else {
                log.error("{}运单模七校验不通过",waybillnomaster);
                throw new FFMResolveException(waybillnomaster+"运单模七校验不通过");
            }

            String masterOringStation = m.group(2);
            String  masterDestinationStation = m.group(3);
            String  masterTotalPiece = m.group(4);
            String  masterTotalWeight = m.group(5);
            return true;
        }
        throw new FFMResolveException("[MBI] MBI主单节点信息错误");
    }

    /**
     * 分单行信息解析,分单信息可以重复,要考虑重复解析如果报文中不存在收发货人的话,目前按单一分单信息解析
     * @param fhlLine HBS-分单行信息解析,
     */
    public boolean hbsInfoParse(String fhlLine) throws FFMResolveException {

        log.debug("[TEXT] 找到HBS分单开头节点");
        //校验正则1,取前三位验证是否是机场代码
        String pattern = "^HBS/([A-Z0-9]{1,12})/([A-Z]{3})([A-Z]{3})/(\\d{1,4})/[A-Z0-9]([0-9\\.]{1,7})/(\\d{1,5})?/(.{1,15})";
        // 创建 Pattern 对象
        Pattern r = Pattern.compile(pattern);
        // 现在创建 matcher 对象
        Matcher m = r.matcher(fhlLine);
        //格式正则校验
        if(m.find()){
            String strList[] = fhlLine.split("/");
           waybillnosecondary = m.group(1);
           originatingstationBill = m.group(2);
           destinationstationBill = m.group(3);
           piece = manifestpiece = m.group(4);
           weight = manifestweight = m.group(5);
           String  SLAC  = strList[5];
           productname =  strList[6];

            log.debug("[HBS] 分单信息节点解析完毕");
            TEMP_KEY_WORD = "HBS-SHC";
            return true;
        }
        throw new FFMResolveException("[HBS] HBS分单节点信息错误");
    }

    /**
     * 分单其他信息解析
     * @param line HBS-分单其他行信息解析
     */
    public boolean hbsOtherInfoParse(String line) throws FFMResolveException {
        if (line.startsWith("/") && "HBS-SHC".equals(TEMP_KEY_WORD)){
            log.debug("适配到分单特货代码节点");

            //校验正则1,取前三位验证是否是机场代码
            String pattern = "(/[A-Z]{3})+";
            // 创建 Pattern 对象
            Pattern r = Pattern.compile(pattern);
            // 现在创建 matcher 对象
            Matcher m = r.matcher(line);
            if (m.find()){
                String strList[] = line.split("/");
                log.info("[HBS-SHC]-特货代码为-{}",line);
                return true;
            }

            throw new FFMResolveException("[HBS] HBS-分单特货代码节点信息错误");
        }else{
            return false;
        }


    }

    /**
     * 分单备注描述信息解析
     * @param line TXT
     */
    public boolean textInfoParse(String line) throws FFMResolveException {
        log.debug("[TEXT] 找到TXT开头节点");
        //校验正则1,取前三位验证是否是机场代码
        String pattern = "(TXT)?/(.{1,65})";
        // 创建 Pattern 对象
        Pattern r = Pattern.compile(pattern);
        // 现在创建 matcher 对象
        Matcher m = r.matcher(line);
        //格式正则校验
        if(m.find()){
            String strList[] = line.split("/");
            String freeText =  strList[1].trim();
            log.info("[TXT]-{}",freeText);
            TEMP_KEY_WORD = "TXT";
            return true;
        }
        throw new FFMResolveException("[TXT] TXT节点信息错误,字数不能超过65");
    }

    /**
     * HTS国际协调关税表信息解析
     * @param line HTS
     */
    public boolean htsInfoParse(String line) throws FFMResolveException {
        log.debug("[TEXT] 找到HTS开头节点");
        //校验正则1,取前三位验证是否是机场代码
        String pattern = "^(HTS)?/[A-Z0-9]{6,18}";
        // 创建 Pattern 对象
        Pattern r = Pattern.compile(pattern);
        // 现在创建 matcher 对象
        Matcher m = r.matcher(line);
        //格式正则校验
        if(m.find()){
            String strList[] = line.split("/");
            String htsText =  strList[1];
            log.debug("[HTS] 信息为:{}",htsText);
            TEMP_KEY_WORD = "HTS";
            return true;
        }
        throw new FFMResolveException("[HTS] HTS国际协调关税表信息错误,字数为6-18位,最多9次");
    }

    /**
     * 收货人信息解析
     * @param consigneLine CNE-收货人行信息解析
     */
    public void consigneeInfoParse(String consigneLine){

    }

    /**
     * 发货人信息解析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";
                }

            }
        }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.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] 收发货人国家及联系信息格式校验错误");
            }
        }
    }

    /**
     * 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;
    }

    /**
     * CVD  计费声明节点解析
     * @param line
     */
    public void cvdParse(String line) throws FFMResolveException {
        String keyword = "^CVD/([A-Z]{3})/([PC]{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(2);
            String Declared_Value_for_Carriage  = m.group(3);
            String Declared_Value_for_Customs  = m.group(4);
            String Declared_Value_for_Insurance  = m.group(5);
            log.info("[CVD]-计费声明:货币代码[{}]-付费模式[{}]-运输申报价值[{}]-海关申报价值[{}]-保险申报价值[{}]",
                    ISO_Currency_Code,paymode,Declared_Value_for_Carriage,Declared_Value_for_Customs,Declared_Value_for_Insurance);
        }else{
            throw new FFMResolveException("CVD节点格式校验错误");
        }
    }


}