作者 朱兆平

部分报文格式生成及验证

package com.sunyo.wlpt.base.model.efreight.fwb;
import com.sunyo.wlpt.base.model.efreight.BASE;
import com.sunyo.wlpt.base.model.efreight.fwb.exception.FWBException;
import com.sunyo.wlpt.base.model.efreight.fwb.exception.FWBExceptionType;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* OTH
* Other Charges
... ... @@ -11,7 +18,19 @@ package com.sunyo.wlpt.base.model.efreight.fwb;
* OTH/P/NEC14
* CRLF
*/
public class FWB_OTH {
public class FWB_OTH extends BASE implements FWB_BASE {
/**
* NODE:P OR C
* Other Charges
* 其他费用
* [PC]{1}
* M (主节点存在则子节点必须有)
* DEMO:
* NE
*/
private String oth_charges;
/**
* NODE:P OR C
* Other Charge Code
... ... @@ -24,6 +43,7 @@ public class FWB_OTH {
private String oth_charge_code;
/**
* 13.3 PARENT: OTHER CHARGE ITEMS 此子节点可最多出现3次
* NODE:P OR C
* Entitlement Code
* 授权代码
... ... @@ -31,6 +51,7 @@ public class FWB_OTH {
* M (主节点存在则子节点必须有)
* DEMO:
* C
*
*/
private String oth_entitlement_code;
... ... @@ -45,4 +66,85 @@ public class FWB_OTH {
* 22.73
*/
private String oth_amount;
public String getOth_charges() throws FWBException {
String patternStr = "^[PC]{1}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(oth_charges);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.OTH_CHARGES_ERROR);
}
return oth_charges;
}
public void setOth_charges(String oth_charges) {
this.oth_charges = oth_charges;
}
public String getOth_charge_code() throws FWBException {
String patternStr = "^[A-Z]{2}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(oth_charge_code);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.OTH_CHARGE_CODE_ERROR);
}
return oth_charge_code;
}
public void setOth_charge_code(String oth_charge_code) {
this.oth_charge_code = oth_charge_code;
}
public String getOth_entitlement_code() throws FWBException {
String patternStr = "^[A-Z]{1}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(oth_entitlement_code);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.OTH_ENTITLEMENT_CODE_ERROR);
}
return oth_entitlement_code;
}
public void setOth_entitlement_code(String oth_entitlement_code) {
this.oth_entitlement_code = oth_entitlement_code;
}
public String getOth_amount() throws FWBException {
String patternStr = "^[1-9\\.]{12}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(oth_amount);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.OTH_AMOUNT_ERROR);
}
return oth_amount;
}
public void setOth_amount(String oth_amount) {
this.oth_amount = oth_amount;
}
@Override
public String getFWBNodeText() throws FWBException {
String SPLIT_CODE = "/";
String CRLF = "\n";
StringBuilder sb = new StringBuilder("");
if (hasText(oth_amount)){
sb.append(getNodeName())
.append(SPLIT_CODE).append(getOth_charges())
.append(SPLIT_CODE)
.append(getOth_charge_code()).append(getOth_entitlement_code()) .append(getOth_amount());
sb.append(CRLF);
}
return sb.toString();
}
@Override
public String getNodeName() {
return "OTH";
}
}
... ...
... ... @@ -82,6 +82,10 @@ public enum FWBExceptionType {
FWB_CVD_VID_ERR("11112","保险声明价值格式有误"),
OTH_CHARGES_ERROR("1322", "其他费用信息格式有误"),
OTH_CHARGE_CODE_ERROR("1331", "其他费用代码信息格式有误"),
OTH_ENTITLEMENT_CODE_ERROR("1332", "授权代码信息格式有误"),
OTH_AMOUNT_ERROR("1333", "其他费用收费金额信息格式有误"),
CER_ERROR("1613", "托运人认证签名信息格式有误"),
... ...