作者 朱兆平

部分报文格式生成及验证

1 package com.sunyo.wlpt.base.model.efreight.fwb; 1 package com.sunyo.wlpt.base.model.efreight.fwb;
2 2
3 3
  4 +import com.sunyo.wlpt.base.model.efreight.BASE;
  5 +import com.sunyo.wlpt.base.model.efreight.fwb.exception.FWBException;
  6 +import com.sunyo.wlpt.base.model.efreight.fwb.exception.FWBExceptionType;
  7 +
  8 +import java.util.regex.Matcher;
  9 +import java.util.regex.Pattern;
  10 +
4 /** 11 /**
5 * OTH 12 * OTH
6 * Other Charges 13 * Other Charges
@@ -11,7 +18,19 @@ package com.sunyo.wlpt.base.model.efreight.fwb; @@ -11,7 +18,19 @@ package com.sunyo.wlpt.base.model.efreight.fwb;
11 * OTH/P/NEC14 18 * OTH/P/NEC14
12 * CRLF 19 * CRLF
13 */ 20 */
14 -public class FWB_OTH { 21 +public class FWB_OTH extends BASE implements FWB_BASE {
  22 +
  23 + /**
  24 + * NODE:P OR C
  25 + * Other Charges
  26 + * 其他费用
  27 + * [PC]{1}
  28 + * M (主节点存在则子节点必须有)
  29 + * DEMO:
  30 + * NE
  31 + */
  32 + private String oth_charges;
  33 +
15 /** 34 /**
16 * NODE:P OR C 35 * NODE:P OR C
17 * Other Charge Code 36 * Other Charge Code
@@ -24,6 +43,7 @@ public class FWB_OTH { @@ -24,6 +43,7 @@ public class FWB_OTH {
24 private String oth_charge_code; 43 private String oth_charge_code;
25 44
26 /** 45 /**
  46 + * 13.3 PARENT: OTHER CHARGE ITEMS 此子节点可最多出现3次
27 * NODE:P OR C 47 * NODE:P OR C
28 * Entitlement Code 48 * Entitlement Code
29 * 授权代码 49 * 授权代码
@@ -31,6 +51,7 @@ public class FWB_OTH { @@ -31,6 +51,7 @@ public class FWB_OTH {
31 * M (主节点存在则子节点必须有) 51 * M (主节点存在则子节点必须有)
32 * DEMO: 52 * DEMO:
33 * C 53 * C
  54 + *
34 */ 55 */
35 private String oth_entitlement_code; 56 private String oth_entitlement_code;
36 57
@@ -45,4 +66,85 @@ public class FWB_OTH { @@ -45,4 +66,85 @@ public class FWB_OTH {
45 * 22.73 66 * 22.73
46 */ 67 */
47 private String oth_amount; 68 private String oth_amount;
  69 +
  70 + public String getOth_charges() throws FWBException {
  71 +
  72 + String patternStr = "^[PC]{1}$";
  73 + Pattern pattern = Pattern.compile(patternStr);
  74 + Matcher matcher = pattern.matcher(oth_charges);
  75 + if (!matcher.find()){
  76 + throw new FWBException(FWBExceptionType.OTH_CHARGES_ERROR);
  77 + }
  78 +
  79 + return oth_charges;
  80 + }
  81 +
  82 + public void setOth_charges(String oth_charges) {
  83 + this.oth_charges = oth_charges;
  84 + }
  85 +
  86 + public String getOth_charge_code() throws FWBException {
  87 +
  88 + String patternStr = "^[A-Z]{2}$";
  89 + Pattern pattern = Pattern.compile(patternStr);
  90 + Matcher matcher = pattern.matcher(oth_charge_code);
  91 + if (!matcher.find()){
  92 + throw new FWBException(FWBExceptionType.OTH_CHARGE_CODE_ERROR);
  93 + }
  94 + return oth_charge_code;
  95 + }
  96 +
  97 + public void setOth_charge_code(String oth_charge_code) {
  98 + this.oth_charge_code = oth_charge_code;
  99 + }
  100 +
  101 + public String getOth_entitlement_code() throws FWBException {
  102 + String patternStr = "^[A-Z]{1}$";
  103 + Pattern pattern = Pattern.compile(patternStr);
  104 + Matcher matcher = pattern.matcher(oth_entitlement_code);
  105 + if (!matcher.find()){
  106 + throw new FWBException(FWBExceptionType.OTH_ENTITLEMENT_CODE_ERROR);
  107 + }
  108 + return oth_entitlement_code;
  109 + }
  110 +
  111 + public void setOth_entitlement_code(String oth_entitlement_code) {
  112 + this.oth_entitlement_code = oth_entitlement_code;
  113 + }
  114 +
  115 + public String getOth_amount() throws FWBException {
  116 + String patternStr = "^[1-9\\.]{12}$";
  117 + Pattern pattern = Pattern.compile(patternStr);
  118 + Matcher matcher = pattern.matcher(oth_amount);
  119 + if (!matcher.find()){
  120 + throw new FWBException(FWBExceptionType.OTH_AMOUNT_ERROR);
  121 + }
  122 + return oth_amount;
  123 + }
  124 +
  125 + public void setOth_amount(String oth_amount) {
  126 + this.oth_amount = oth_amount;
  127 + }
  128 +
  129 + @Override
  130 + public String getFWBNodeText() throws FWBException {
  131 + String SPLIT_CODE = "/";
  132 + String CRLF = "\n";
  133 + StringBuilder sb = new StringBuilder("");
  134 +
  135 + if (hasText(oth_amount)){
  136 + sb.append(getNodeName())
  137 + .append(SPLIT_CODE).append(getOth_charges())
  138 + .append(SPLIT_CODE)
  139 + .append(getOth_charge_code()).append(getOth_entitlement_code()) .append(getOth_amount());
  140 + sb.append(CRLF);
  141 + }
  142 +
  143 + return sb.toString();
  144 + }
  145 +
  146 + @Override
  147 + public String getNodeName() {
  148 + return "OTH";
  149 + }
48 } 150 }
@@ -82,6 +82,10 @@ public enum FWBExceptionType { @@ -82,6 +82,10 @@ public enum FWBExceptionType {
82 FWB_CVD_VID_ERR("11112","保险声明价值格式有误"), 82 FWB_CVD_VID_ERR("11112","保险声明价值格式有误"),
83 83
84 84
  85 + OTH_CHARGES_ERROR("1322", "其他费用信息格式有误"),
  86 + OTH_CHARGE_CODE_ERROR("1331", "其他费用代码信息格式有误"),
  87 + OTH_ENTITLEMENT_CODE_ERROR("1332", "授权代码信息格式有误"),
  88 + OTH_AMOUNT_ERROR("1333", "其他费用收费金额信息格式有误"),
85 89
86 CER_ERROR("1613", "托运人认证签名信息格式有误"), 90 CER_ERROR("1613", "托运人认证签名信息格式有误"),
87 91