作者 朱兆平

部分报文格式生成及验证

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;
/**
* Accounting Information
* 财务信息
... ... @@ -9,7 +16,7 @@ package com.sunyo.wlpt.base.model.efreight.fwb;
* ACC/GEN/FREIGHT PREPAID
* CRLF
*/
public class FWB_ACC {
public class FWB_ACC extends BASE implements FWB_BASE {
/**
*
* 财务信息ID标识
... ... @@ -28,4 +35,53 @@ public class FWB_ACC {
* /GEN/FREIGHT PREPAID
*/
private String acc_info;
public String getAcc_info_id() throws FWBException {
String patternStr = "^[A-Z]{3}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(acc_info_id);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_ACC_ID_ERR);
}
return acc_info_id;
}
public void setAcc_info_id(String acc_info_id) {
this.acc_info_id = acc_info_id;
}
public String getAcc_info() throws FWBException {
String patternStr = "^[A-Z0-9-<=/\\s\\.]{1,34}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(acc_info);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_ACC_INFO_ERR);
}
return acc_info;
}
public void setAcc_info(String acc_info) {
this.acc_info = acc_info;
}
@Override
public String getFWBNodeText() throws FWBException {
String SPLIT_CODE = "/";
String CRLF = "\n";
StringBuilder sb = new StringBuilder("");
if (hasText(acc_info) || hasText(acc_info_id)){
sb.append(getNodeName()).append(SPLIT_CODE);
sb.append(getAcc_info_id()).append(SPLIT_CODE).append(getAcc_info());
sb.append(CRLF);
}
return sb.toString();
}
@Override
public String getNodeName() {
return "ACC";
}
}
... ...
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;
/**
* 代理人信息
* 代理人信息有IATA代码 则名称与地址也为必填项
... ... @@ -7,7 +14,7 @@ package com.sunyo.wlpt.base.model.efreight.fwb;
* (满足指定条件必须包含在内)
* (中性运单包含代理人IATA信息 则必填)
*/
public class FWB_AGT {
public class FWB_AGT extends BASE implements FWB_BASE {
/**
* 代理人账号信息
... ... @@ -44,4 +51,128 @@ public class FWB_AGT {
* [A-Z0-9-<=/\s\.]{1,17}
*/
private String agt_ADR;
public String getAgt_account_number() throws FWBException {
String patternStr = "^[A-Z0-9-<=/\\s\\.]{0,14}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(agt_account_number);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_AGT_ACC_ERR);
}
return agt_account_number;
}
public void setAgt_account_number(String agt_account_number) {
this.agt_account_number = agt_account_number;
}
public String getAgt_IATA_number() throws FWBException {
String patternStr = "^\\d{7}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(agt_IATA_number);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_AGT_IATA_ERR);
}
return agt_IATA_number;
}
public void setAgt_IATA_number(String agt_IATA_number) {
this.agt_IATA_number = agt_IATA_number;
}
public String getAgt_CASS_ADR() throws FWBException {
String patternStr = "^\\d{0,4}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(agt_CASS_ADR);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_AGT_CASS_ERR);
}
return agt_CASS_ADR;
}
public void setAgt_CASS_ADR(String agt_CASS_ADR) {
this.agt_CASS_ADR = agt_CASS_ADR;
}
public String getAgt_participant_id() throws FWBException {
String patternStr = "^[A-Z0-9]{0,3}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(agt_participant_id);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_AGT_PID_ERR);
}
return agt_participant_id;
}
public void setAgt_participant_id(String agt_participant_id) {
this.agt_participant_id = agt_participant_id;
}
public String getAgt_name() throws FWBException {
String patternStr = "^[A-Z0-9-<=/\\s\\.]{0,35}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(agt_name);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_AGT_NAME_ERR);
}
return agt_name;
}
public void setAgt_name(String agt_name) {
this.agt_name = agt_name;
}
public String getAgt_ADR() throws FWBException {
String patternStr = "^[A-Z0-9-<=/\\s\\.]{0,17}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(agt_ADR);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_AGT_ADR_ERR);
}
return agt_ADR;
}
public void setAgt_ADR(String agt_ADR) {
this.agt_ADR = agt_ADR;
}
@Override
public String getFWBNodeText() throws FWBException {
String SPLIT_CODE = "/";
String CRLF = "\n";
StringBuilder sb = new StringBuilder("");
//代理人信息中有IATA代码时才生成
if (hasText(agt_IATA_number)){
sb.append(getNodeName());
sb.append(SPLIT_CODE);
if (hasText(agt_account_number)){
sb.append(getAgt_account_number());
}
sb.append(SPLIT_CODE).append(getAgt_IATA_number());
if (hasText(agt_CASS_ADR)){
sb.append(SPLIT_CODE).append(getAgt_CASS_ADR());
}
if (hasText(agt_participant_id)){
sb.append(SPLIT_CODE).append(getAgt_participant_id());
}
sb.append(CRLF);
sb.append(SPLIT_CODE).append(getAgt_name()).append(CRLF)
.append(SPLIT_CODE).append(getAgt_ADR());
sb.append(CRLF);
}
return sb.toString();
}
@Override
public String getNodeName() {
return "AGT";
}
}
... ...
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;
/**
* 主单收货人
* mandatory (must be included);M
*/
public class FWB_CNE {
public class FWB_CNE extends BASE implements FWB_BASE {
/**
* 收货人账号信息
... ... @@ -57,6 +64,182 @@ public class FWB_CNE {
*/
private String cne_contact_number;
public String getCne_account_number() throws FWBException {
String patternStr = "^[A-Z0-9-<=/\\s\\.]{0,14}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(cne_account_number);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_CNE_ACC_ERR);
}
return cne_account_number;
}
public void setCne_account_number(String cne_account_number) {
this.cne_account_number = cne_account_number;
}
public String getCne_name() throws FWBException {
String patternStr = "^[A-Z0-9-<=/\\s\\.]{0,35}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(cne_name);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_CNE_NAME_ERR);
}
return cne_name;
}
public void setCne_name(String cne_name) {
this.cne_name = cne_name;
}
public String getCne_adr() throws FWBException {
String patternStr = "^[A-Z0-9-<=/\\s\\.]{0,35}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(cne_adr);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_CNE_ADR_ERR);
}
return cne_adr;
}
public void setCne_adr(String cne_adr) {
this.cne_adr = cne_adr;
}
public String getCne_loc_place() throws FWBException {
String patternStr = "^[A-Z0-9-<=/\\s\\.]{0,17}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(cne_loc_place);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_CNE_PLC_ERR);
}
return cne_loc_place;
}
public void setCne_loc_place(String cne_loc_place) {
this.cne_loc_place = cne_loc_place;
}
public String getCne_loc_province() throws FWBException {
String patternStr = "^[A-Z0-9-<=/\\s\\.]{0,9}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(cne_loc_province);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_CNE_PVC_ERR);
}
return cne_loc_province;
}
public void setCne_loc_province(String cne_loc_province) {
this.cne_loc_province = cne_loc_province;
}
public String getCne_country() throws FWBException {
String patternStr = "^[A-Z]{2}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(cne_country);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_CNE_CNT_ERR);
}
return cne_country;
}
public void setCne_country(String cne_country) {
this.cne_country = cne_country;
}
public String getCne_postcode() throws FWBException {
String patternStr = "^[A-Z0-9-<=/\\s\\.]{0,9}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(cne_postcode);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_CNE_PC_ERR);
}
return cne_postcode;
}
public void setCne_postcode(String cne_postcode) {
this.cne_postcode = cne_postcode;
}
public String getCne_contact_id() throws FWBException {
String patternStr = "^FX|TE|TL$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(cne_contact_id);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_CNE_CID_ERR);
}
return cne_contact_id;
}
public void setCne_contact_id(String cne_contact_id) {
this.cne_contact_id = cne_contact_id;
}
public String getCne_contact_number() throws FWBException {
String patternStr = "^[A-Z0-9]{1,25}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(cne_contact_number);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_CNE_CN_ERR);
}
return cne_contact_number;
}
public void setCne_contact_number(String cne_contact_number) {
this.cne_contact_number = cne_contact_number;
}
@Override
public String getFWBNodeText() throws FWBException {
String SPLIT_CODE = "/";
String CRLF = "\n";
StringBuilder sb = new StringBuilder("");
if (hasText(cne_account_number)){
sb.append(SPLIT_CODE).append(getCne_account_number());
}
sb.append(CRLF);
sb.append(SPLIT_CODE).append(getCne_name()).append(CRLF);
sb.append(SPLIT_CODE).append(getCne_adr()).append(CRLF);
sb.append(SPLIT_CODE).append(getCne_loc_place());
if (hasText(getCne_loc_province())){
sb.append(SPLIT_CODE).append(getCne_loc_province());
}
sb.append(CRLF);
sb.append(SPLIT_CODE).append(getCne_country());
if (hasText(getCne_postcode())) {
sb.append(SPLIT_CODE).append(getCne_postcode());
}else {
if (hasText(getCne_contact_number())){
sb.append(SPLIT_CODE);
}
}
//联系方式可重复不限次数,todo:处理这种联系方式 有多个信息的
if (hasText(getCne_contact_number())){
sb.append(SPLIT_CODE).append(getCne_contact_id()).append(SPLIT_CODE).append(getCne_contact_number());
}
//todo:此节点循环的报文内容获取方式
sb.append(CRLF);
return sb.toString();
}
@Override
public String getNodeName() {
return "CNE";
}
}
... ...
package com.sunyo.wlpt.base.model.efreight.fwb;
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
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;
/**
* CVD
* Charge Declarations
... ... @@ -9,11 +18,11 @@ package com.sunyo.wlpt.base.model.efreight.fwb;
* CVD/CNY/(PX)/PP/NVD/NCV/XXX
* CRLF
*/
public class FWB_CVD {
public class FWB_CVD extends BASE implements FWB_BASE{
/**
* 货币单位
* [A-Z]{1,3}
* [A-Z]{3}
* M
* DEMO:
* CNY
... ... @@ -64,10 +73,120 @@ public class FWB_CVD {
/**
* Value For insurance Declaration
* 保险声明价值
* [0-9.]{1,11}
* [0-9.]{1,11}|XXX
* M 必填
* DEMO:
* 123.05 OR XXX
*/
private String getCvd_value_for_customs;
private String cvd_amount_of_insurance;
public String getCvd_currency_code() throws FWBException {
String patternStr = "^[A-Z]{3}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(cvd_currency_code);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_CVD_CUR_ERR);
}
return cvd_currency_code;
}
public void setCvd_currency_code(String cvd_currency_code) {
this.cvd_currency_code = cvd_currency_code;
}
public String getCvd_charge_code() throws FWBException {
String patternStr = "^[A-Z]{2}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(cvd_charge_code);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_CVD_CC_ERR);
}
return cvd_charge_code;
}
public void setCvd_charge_code(String cvd_charge_code) {
this.cvd_charge_code = cvd_charge_code;
}
public String getCvd_charge_prepaid() throws FWBException {
String patternStr = "^PP|CC$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(cvd_charge_prepaid);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_CVD_PCCD_ERR);
}
return cvd_charge_prepaid;
}
public void setCvd_charge_prepaid(String cvd_charge_prepaid) {
this.cvd_charge_prepaid = cvd_charge_prepaid;
}
public String getCvd_value_for_carriage() throws FWBException {
String patternStr = "^[0-9\\.]{1,12}|NVD$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(cvd_value_for_carriage);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_CVD_VCD_ERR);
}
return cvd_value_for_carriage;
}
public void setCvd_value_for_carriage(String cvd_value_for_carriage) {
this.cvd_value_for_carriage = cvd_value_for_carriage;
}
public String getCvd_value_for_customs() throws FWBException {
String patternStr = "^[0-9\\.]{1,12}|NCV$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(cvd_value_for_customs);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_CVD_DVC_ERR);
}
return cvd_value_for_customs;
}
public void setCvd_value_for_customs(String cvd_value_for_customs) {
this.cvd_value_for_customs = cvd_value_for_customs;
}
public String getCvd_amount_of_insurance() throws FWBException {
String patternStr = "^[0-9\\.]{1,11}|XXX$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(cvd_amount_of_insurance);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_CVD_VID_ERR);
}
return cvd_amount_of_insurance;
}
public void setCvd_amount_of_insurance(String cvd_amount_of_insurance) {
this.cvd_amount_of_insurance = cvd_amount_of_insurance;
}
@Override
public String getFWBNodeText() throws FWBException {
String SPLIT_CODE = "/";
String CRLF = "\n";
StringBuilder sb = new StringBuilder("");
sb.append(getNodeName()).append(SPLIT_CODE).append(getCvd_currency_code()).append(SPLIT_CODE);
if (hasText(cvd_charge_code)){
sb.append(getCvd_charge_code());
}
sb.append(SPLIT_CODE).append(getCvd_charge_prepaid());
sb.append(SPLIT_CODE).append(getCvd_value_for_carriage()).append(SPLIT_CODE).append(getCvd_value_for_customs());
sb.append(SPLIT_CODE).append(getCvd_amount_of_insurance());
sb.append(CRLF);
return sb.toString();
}
@Override
public String getNodeName() {
return "CVD";
}
}
... ...
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;
/**
* NFY
* Also Notify
... ... @@ -9,7 +16,7 @@ package com.sunyo.wlpt.base.model.efreight.fwb;
* DEMO:
* /NFY/
*/
public class FWB_NFY {
public class FWB_NFY extends BASE implements FWB_BASE {
/**
* 被通知人名称
* [A-Z0-9-<=/\s\.]{1,35}
... ... @@ -68,4 +75,158 @@ public class FWB_NFY {
* M
*/
private String nfy_contact_NUM;
public String getNfy_name() throws FWBException {
String patternStr = "^[A-Z0-9-<=/\\s\\.]{0,35}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(nfy_name);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_NFY_NAME_ERR);
}
return nfy_name;
}
public void setNfy_name(String nfy_name) {
this.nfy_name = nfy_name;
}
public String getNfy_ADR() throws FWBException {
String patternStr = "^[A-Z0-9-<=/\\s\\.]{0,35}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(nfy_ADR);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_NFY_ADR_ERR);
}
return nfy_ADR;
}
public void setNfy_ADR(String nfy_ADR) {
this.nfy_ADR = nfy_ADR;
}
public String getNfy_LOC_city() throws FWBException {
String patternStr = "^[A-Z0-9-<=/\\s\\.]{0,17}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(nfy_LOC_city);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_NFY_PLC_ERR);
}
return nfy_LOC_city;
}
public void setNfy_LOC_city(String nfy_LOC_city) {
this.nfy_LOC_city = nfy_LOC_city;
}
public String getNfy_LOC_province() throws FWBException {
String patternStr = "^[A-Z0-9-<=/\\s\\.]{0,9}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(nfy_LOC_province);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_NFY_PVC_ERR);
}
return nfy_LOC_province;
}
public void setNfy_LOC_province(String nfy_LOC_province) {
this.nfy_LOC_province = nfy_LOC_province;
}
public String getNfy_country() throws FWBException {
String patternStr = "^[A-Z]{2}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(nfy_country);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_NFY_CNT_ERR);
}
return nfy_country;
}
public void setNfy_country(String nfy_country) {
this.nfy_country = nfy_country;
}
public String getNfy_postcode() throws FWBException {
String patternStr = "^[A-Z0-9-<=/\\s\\.]{0,9}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(nfy_postcode);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_NFY_PC_ERR);
}
return nfy_postcode;
}
public void setNfy_postcode(String nfy_postcode) {
this.nfy_postcode = nfy_postcode;
}
public String getNfy_contact_id() throws FWBException {
String patternStr = "^FX|TE|TL$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(nfy_contact_id);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_NFY_CID_ERR);
}
return nfy_contact_id;
}
public void setNfy_contact_id(String nfy_contact_id) {
this.nfy_contact_id = nfy_contact_id;
}
public String getNfy_contact_NUM() throws FWBException {
String patternStr = "^[A-Z0-9]{1,25}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(nfy_contact_NUM);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_NFY_CN_ERR);
}
return nfy_contact_NUM;
}
public void setNfy_contact_NUM(String nfy_contact_NUM) {
this.nfy_contact_NUM = nfy_contact_NUM;
}
@Override
public String getFWBNodeText() throws FWBException {
String SPLIT_CODE = "/";
String CRLF = "\n";
StringBuilder sb = new StringBuilder("");
if (hasText(nfy_name) || hasText(nfy_ADR) || hasText(nfy_LOC_city) || hasText(nfy_country)){
sb.append(getNodeName());
sb.append(SPLIT_CODE).append(getNfy_name()).append(CRLF);
sb.append(SPLIT_CODE).append(getNfy_ADR()).append(CRLF);
sb.append(SPLIT_CODE).append(getNfy_LOC_city());
if (hasText(nfy_LOC_province)){
sb.append(SPLIT_CODE).append(getNfy_LOC_province());
}
sb.append(CRLF);
sb.append(SPLIT_CODE).append(getNfy_country());
if (hasText(nfy_postcode)){
sb.append(SPLIT_CODE).append(getNfy_postcode());
}else {
if (hasText(nfy_contact_NUM)){
sb.append(SPLIT_CODE);
}
}
if (hasText(nfy_contact_NUM)){
sb.append(SPLIT_CODE).append(getNfy_contact_id()).append(SPLIT_CODE).append(getNfy_contact_NUM());
}
sb.append(CRLF);
}
return sb.toString();
}
@Override
public String getNodeName() {
return "NFY";
}
}
... ...
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;
/**
* 主单发货人
* mandatory (must be included); M
*/
public class FWB_SHP {
public class FWB_SHP extends BASE implements FWB_BASE {
/**
* 发货人账号信息
... ... @@ -57,5 +64,175 @@ public class FWB_SHP {
private String shp_contact_number;
public String getShp_account_number() throws FWBException {
String patternStr = "^[A-Z0-9-<=/\\s\\.]{0,14}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(shp_account_number);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_SHP_ACC_ERR);
}
return shp_account_number;
}
public void setShp_account_number(String shp_account_number) {
this.shp_account_number = shp_account_number;
}
public String getShp_name() throws FWBException {
String patternStr = "^[A-Z0-9-<=/\\s\\.]{0,35}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(shp_name);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_SHP_NAME_ERR);
}
return shp_name;
}
public void setShp_name(String shp_name) {
this.shp_name = shp_name;
}
public String getShp_adr() throws FWBException {
String patternStr = "^[A-Z0-9-<=/\\s\\.]{0,35}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(shp_adr);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_SHP_ADR_ERR);
}
return shp_adr;
}
public void setShp_adr(String shp_adr) {
this.shp_adr = shp_adr;
}
public String getShp_loc_place() throws FWBException {
String patternStr = "^[A-Z0-9-<=/\\s\\.]{0,17}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(shp_loc_place);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_SHP_PLC_ERR);
}
return shp_loc_place;
}
public void setShp_loc_place(String shp_loc_place) {
this.shp_loc_place = shp_loc_place;
}
public String getShp_loc_province() throws FWBException {
String patternStr = "^[A-Z0-9-<=/\\s\\.]{0,9}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(shp_loc_province);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_SHP_PVC_ERR);
}
return shp_loc_province;
}
public void setShp_loc_province(String shp_loc_province) {
this.shp_loc_province = shp_loc_province;
}
public String getShp_country() throws FWBException {
String patternStr = "^[A-Z]{2}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(shp_country);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_SHP_CNT_ERR);
}
return shp_country;
}
public void setShp_country(String shp_country) {
this.shp_country = shp_country;
}
public String getShp_postcode() throws FWBException {
String patternStr = "^[A-Z0-9-<=/\\s\\.]{0,9}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(shp_postcode);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_SHP_PC_ERR);
}
return shp_postcode;
}
public void setShp_postcode(String shp_postcode) {
this.shp_postcode = shp_postcode;
}
public String getShp_contact_id() throws FWBException {
String patternStr = "^FX|TE|TL$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(shp_contact_id);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_SHP_CID_ERR);
}
return shp_contact_id;
}
public void setShp_contact_id(String shp_contact_id) {
this.shp_contact_id = shp_contact_id;
}
public String getShp_contact_number() throws FWBException {
String patternStr = "^[A-Z0-9]{1,25}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(shp_contact_number);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_SHP_CN_ERR);
}
return shp_contact_number;
}
public void setShp_contact_number(String shp_contact_number) {
this.shp_contact_number = shp_contact_number;
}
@Override
public String getFWBNodeText() throws FWBException {
String SPLIT_CODE = "/";
String CRLF = "\n";
StringBuilder sb = new StringBuilder("");
if (hasText(shp_account_number)){
sb.append(SPLIT_CODE).append(getShp_account_number());
}
sb.append(CRLF);
sb.append(SPLIT_CODE).append(getShp_name()).append(CRLF);
sb.append(SPLIT_CODE).append(getShp_adr()).append(CRLF);
sb.append(SPLIT_CODE).append(getShp_loc_place());
if (hasText(shp_loc_province)){
sb.append(SPLIT_CODE).append(getShp_loc_province());
}
sb.append(CRLF);
sb.append(SPLIT_CODE).append(getShp_country());
if (hasText(shp_postcode)) {
sb.append(SPLIT_CODE).append(getShp_postcode());
}else {
if (hasText(shp_contact_number)){
sb.append(SPLIT_CODE);
}
}
//联系方式可重复不限次数,todo:处理这种联系方式 有多个信息的
if (hasText(shp_contact_number)){
sb.append(SPLIT_CODE).append(getShp_contact_id()).append(SPLIT_CODE).append(getShp_contact_number());
}
//todo:此节点循环的报文内容获取方式
sb.append(CRLF);
return sb.toString();
}
@Override
public String getNodeName() {
return "SHP";
}
}
... ...
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;
/**
* SSR
* special service request
* Special Service Request
* 特殊服务请求
* optional (may be included) 可选(有可能包含)
* 请求最多可重复3次
* DEMO:
* /SSR/RQUEST TXT/REQUST TXT/REQUEST TXT
*/
public class FWB_SSR {
public class FWB_SSR extends BASE implements FWB_BASE {
/**
* 特殊服务请求内容
* [A-Z0-9-<=/\s\.]{0,65}
*/
private String ssr_request_content;
public String getSsr_request_content() throws FWBException {
String patternStr = "^[A-Z0-9-<=/\\s\\.]{0,65}$";
Pattern pattern = Pattern.compile(patternStr);
Matcher matcher = pattern.matcher(ssr_request_content);
if (!matcher.find()){
throw new FWBException(FWBExceptionType.FWB_SSR_CONT_ERR);
}
return ssr_request_content;
}
public void setSsr_request_content(String ssr_request_content) {
this.ssr_request_content = ssr_request_content;
}
@Override
public String getFWBNodeText() throws FWBException {
String SPLIT_CODE = "/";
String CRLF = "\n";
StringBuilder sb = new StringBuilder("");
if (hasText(ssr_request_content)){
sb.append(getNodeName());
sb.append(SPLIT_CODE).append(getSsr_request_content());
sb.append(CRLF);
}
return sb.toString();
}
@Override
public String getNodeName() {
return "SSR";
}
}
... ...
... ... @@ -32,6 +32,56 @@ public enum FWBExceptionType {
FWB_RTG_AIRPORT_ERR("422","涉及航站信息有误"),
FWB_RTG_CARRIER_ERR("422","涉及承运人信息有误"),
FWB_SHP_ACC_ERR("522","发货人账号信息格式有误"),
FWB_SHP_NAME_ERR("543","发货人名称信息格式有误"),
FWB_SHP_ADR_ERR("553","发货人地址信息格式有误"),
FWB_SHP_PLC_ERR("563","发货人城市信息格式有误"),
FWB_SHP_PVC_ERR("565","发货人省份信息格式有误"),
FWB_SHP_CNT_ERR("572","发货人国家信息格式有误"),
FWB_SHP_PC_ERR("573","发货人邮编信息格式有误"),
FWB_SHP_CID_ERR("582","发货人联系方式代码格式有误"),
FWB_SHP_CN_ERR("584","发货人联系方式信息格式有误"),
FWB_CNE_ACC_ERR("622","收货人账号信息格式有误"),
FWB_CNE_NAME_ERR("643","收货人名称信息格式有误"),
FWB_CNE_ADR_ERR("653","收货人地址信息格式有误"),
FWB_CNE_PLC_ERR("663","收货人城市信息格式有误"),
FWB_CNE_PVC_ERR("665","收货人省份信息格式有误"),
FWB_CNE_CNT_ERR("672","收货人国家信息格式有误"),
FWB_CNE_PC_ERR("673","收货人邮编信息格式有误"),
FWB_CNE_CID_ERR("682","收货人联系方式代码格式有误"),
FWB_CNE_CN_ERR("684","收货人联系方式信息格式有误"),
FWB_AGT_ACC_ERR("722","代理人账号信息格式有误"),
FWB_AGT_IATA_ERR("724","代理人IATA注册号信息格式有误"),
FWB_AGT_CASS_ERR("726","代理人CASS注册号信息格式有误"),
FWB_AGT_PID_ERR("728","代理人参与者标识符信息格式有误"),
FWB_AGT_NAME_ERR("742","代理人名称信息格式有误"),
FWB_AGT_ADR_ERR("752","代理人地址信息格式有误"),
FWB_SSR_CONT_ERR("883","SSR特殊服务请求内容信息格式有误"),
FWB_NFY_NAME_ERR("933","被通知人名称信息格式有误"),
FWB_NFY_ADR_ERR("943"," 被通知人地址信息格式有误"),
FWB_NFY_PLC_ERR("953"," 被通知人城市信息格式有误"),
FWB_NFY_PVC_ERR("955"," 被通知人省份信息格式有误"),
FWB_NFY_CNT_ERR("962"," 被通知人国家信息格式有误"),
FWB_NFY_PC_ERR("964"," 被通知人邮编信息格式有误"),
FWB_NFY_CID_ERR("972"," 被通知人联系方式代码格式有误"),
FWB_NFY_CN_ERR("974"," 被通知人联系方式信息格式有误"),
FWB_ACC_ID_ERR ("1022","ACC财务信息ID格式有误"),
FWB_ACC_INFO_ERR("1024","ACC财务信息内容格式有误"),
FWB_CVD_CUR_ERR("1130","CVD收费声明货币单位格式有误"),
FWB_CVD_CC_ERR("1150","CVD收费代码格式有误"),
FWB_CVD_PCCD_ERR("1170","CVD预付/到付声明格式有误"),
FWB_CVD_VCD_ERR("1180","运费申报价值对承运人声明格式有误"),
FWB_CVD_DVC_ERR("11101","海关声明价值格式有误"),
FWB_CVD_VID_ERR("11112","保险声明价值格式有误"),
REF_ERROR("203", "缺少 REF Sender Reference - Sender Office Message Address"),
REF_SOMA_REGEX_FAILD("2031", "REF- Sender Office Message Address RegEx Faild"),
... ...
import com.sun.org.apache.regexp.internal.RE;
import com.sunyo.wlpt.base.model.efreight.fwb.*;
import com.sunyo.wlpt.base.model.efreight.fwb.exception.FWBException;
public class FWBTest {
public static void main(String[] args) {
FWB_WAYBILL_TEST();
// FWB_FLT_TEST();
FWB_RTG_TEST();
REF_TEST();
// OCI_TEST();
}
System.out.println(
FWB_WAYBILL_TEST()
+ FWB_FLT_TEST()
+ FWB_RTG_TEST()
+ FWB_SHP_TEST()
+ FWB_AGT_TEST()
+ FWB_SSR_TEST()
+ FWB_NFY_TEST()
+ FWB_ACC_TEST()
+ FWB_CVD_TEST()
);
// REF_TEST();
static void OCI_TEST(){
FWB_OCI fwb_oci = new FWB_OCI();
fwb_oci.setOci_csrc_id("T");
fwb_oci.setOci_csrc_info("USCI91440101MA9Y9E79XG");
fwb_oci.setOci_country_code("CN");
fwb_oci.setOci_information_id("SHP");
try {
String oci = fwb_oci.getFWBNodeText();
System.out.println(oci);
} catch (FWBException e) {
e.printStackTrace();
}
}
// OCI_TEST();
static void REF_TEST(){
FWB_REF fwb_ref = new FWB_REF();
fwb_ref.setRef_address("CGOFDIE");
fwb_ref.setRef_file_reference("EC1A2C4CBC3D1");
fwb_ref.setRef_participant_id("AGT");
fwb_ref.setRef_participant_code("MECCGO01");
fwb_ref.setRef_participant_airport("CGO");
try {
String oci = fwb_ref.getNodeName() + fwb_ref.getFWBNodeText();
System.out.println(oci);
} catch (FWBException e) {
e.printStackTrace();
}
}
static String FWB_WAYBILL_TEST(){
... ... @@ -67,7 +46,7 @@ public class FWBTest {
return "";
}
static void FWB_FLT_TEST(){
static String FWB_FLT_TEST(){
FWB_FLT flt = new FWB_FLT();
flt.setCariier("CV");
flt.setFlightNumber("732");
... ... @@ -75,24 +54,165 @@ public class FWBTest {
try {
String nodeText = flt.getNodeName() + flt.getFWBNodeText() + "\n";
System.out.println(FWB_WAYBILL_TEST()+nodeText);
return nodeText;
// System.out.println(FWB_WAYBILL_TEST()+nodeText);
} catch (FWBException e) {
e.printStackTrace();
}
return "";
}
static void FWB_RTG_TEST(){
static String FWB_RTG_TEST(){
FWB_RTG var = new FWB_RTG();
// var.setDestinationAirport("ICN");
var.setDestinationCarrier("F5");
var.setOnwardAirport("SIN");
var.setDestinationAirport("ICN");
var.setDestinationCarrier("CV");
// var.setOnwardAirport("SIN");
// var.setOnwardCarrier("K9");
try {
String nodeText = var.getNodeName() + var.getFWBNodeText() + "\n";
System.out.println(FWB_WAYBILL_TEST()+nodeText);
// System.out.println(FWB_WAYBILL_TEST()+nodeText);
return nodeText;
} catch (FWBException e) {
e.printStackTrace();
}
return "";
}
static String FWB_SHP_TEST(){
FWB_SHP var = new FWB_SHP();
var.setShp_name("HENAN CIVIL AVIATION DEVELOPMENT");
var.setShp_account_number("ABC");
var.setShp_adr("HNCA BUILDING YUHONG WORLD");
var.setShp_loc_place("ZHENGZHOU");
var.setShp_loc_province("HENAN");
var.setShp_country("CN");
var.setShp_postcode("");
var.setShp_contact_id("TE");
var.setShp_contact_number("450000");
try {
String nodeText = var.getNodeName() + var.getFWBNodeText();
return nodeText;
} catch (FWBException e) {
e.printStackTrace();
}
return "";
}
static String FWB_AGT_TEST(){
FWB_AGT var = new FWB_AGT();
var.setAgt_account_number("");
var.setAgt_IATA_number("0831714");
var.setAgt_CASS_ADR("0215");
// var.setAgt_participant_id("CAG");
var.setAgt_name("BOLLORE LOGISTICS CHINA CO LTD ");
var.setAgt_ADR("SHANGHAI");
try {
String nodeText = var.getFWBNodeText() ;
return nodeText;
} catch (FWBException e) {
e.printStackTrace();
}
return "";
}
static String FWB_SSR_TEST(){
FWB_SSR var = new FWB_SSR();
var.setSsr_request_content("ALSO CNEE OPERATIONAL CODE 086500 NETTING CODE 0462 VAT NO 486017");
try {
String nodeText = var.getFWBNodeText() ;
return nodeText;
} catch (FWBException e) {
e.printStackTrace();
}
return "";
}
static String FWB_NFY_TEST(){
FWB_NFY var = new FWB_NFY();
var.setNfy_name("DSV AIR SEA AB - I200");
var.setNfy_ADR("NO.3 UNIT 2F-W2 WAREHOUSE NO.83 SH");
var.setNfy_LOC_city("SHANGHAI");
var.setNfy_LOC_province("");
var.setNfy_country("CN");
var.setNfy_postcode("");
var.setNfy_contact_id("TE");
var.setNfy_contact_NUM("TE00862160278315");
try {
String nodeText = var.getFWBNodeText() ;
return nodeText;
} catch (FWBException e) {
e.printStackTrace();
}
return "";
}
static String FWB_ACC_TEST(){
FWB_ACC var = new FWB_ACC();
var.setAcc_info_id("GEN");
var.setAcc_info("FREIGHT PREPAID");
try {
String nodeText = var.getFWBNodeText() ;
return nodeText;
} catch (FWBException e) {
e.printStackTrace();
}
return "";
}
static String FWB_CVD_TEST(){
FWB_CVD var = new FWB_CVD();
var.setCvd_currency_code("INR");
// var.setCvd_charge_code("PX");
var.setCvd_charge_prepaid("PP");
var.setCvd_value_for_carriage("NVD");
var.setCvd_value_for_customs("NCV");
var.setCvd_amount_of_insurance("XXX");
try {
String nodeText = var.getFWBNodeText() ;
return nodeText;
} catch (FWBException e) {
e.printStackTrace();
}
return "";
}
static void OCI_TEST(){
FWB_OCI fwb_oci = new FWB_OCI();
fwb_oci.setOci_csrc_id("T");
fwb_oci.setOci_csrc_info("USCI91440101MA9Y9E79XG");
fwb_oci.setOci_country_code("CN");
fwb_oci.setOci_information_id("SHP");
try {
String oci = fwb_oci.getFWBNodeText();
System.out.println(oci);
} catch (FWBException e) {
e.printStackTrace();
}
}
static void REF_TEST(){
FWB_REF fwb_ref = new FWB_REF();
fwb_ref.setRef_address("CGOFDIE");
fwb_ref.setRef_file_reference("EC1A2C4CBC3D1");
fwb_ref.setRef_participant_id("AGT");
fwb_ref.setRef_participant_code("MECCGO01");
fwb_ref.setRef_participant_airport("CGO");
try {
String oci = fwb_ref.getNodeName() + fwb_ref.getFWBNodeText();
System.out.println(oci);
} catch (FWBException e) {
e.printStackTrace();
}
}
}
... ...