作者 朱兆平

部分报文格式生成及验证

@@ -61,6 +61,14 @@ @@ -61,6 +61,14 @@
61 <verbose>true</verbose> 61 <verbose>true</verbose>
62 </configuration> 62 </configuration>
63 </plugin> 63 </plugin>
  64 + <plugin>
  65 + <groupId>org.apache.maven.plugins</groupId>
  66 + <artifactId>maven-compiler-plugin</artifactId>
  67 + <configuration>
  68 + <source>6</source>
  69 + <target>6</target>
  70 + </configuration>
  71 + </plugin>
64 </plugins> 72 </plugins>
65 </build> 73 </build>
66 74
@@ -8,4 +8,8 @@ public class BASE { @@ -8,4 +8,8 @@ public class BASE {
8 return StringUtils.hasText(var); 8 return StringUtils.hasText(var);
9 } 9 }
10 10
  11 + final public String SPLIT_CODE = "/";
  12 + final public String CRLF = "\n";
  13 +
  14 +
11 } 15 }
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.List;
  9 +import java.util.regex.Matcher;
  10 +import java.util.regex.Pattern;
  11 +
4 /** 12 /**
5 * SPH 13 * SPH
6 * Special Handing Details 14 * Special Handing Details
@@ -11,7 +19,7 @@ package com.sunyo.wlpt.base.model.efreight.fwb; @@ -11,7 +19,7 @@ package com.sunyo.wlpt.base.model.efreight.fwb;
11 * SPH/ECC/ELI 19 * SPH/ECC/ELI
12 * CRLF 20 * CRLF
13 */ 21 */
14 -public class FWB_SPH { 22 +public class FWB_SPH extends BASE implements FWB_BASE {
15 23
16 /** 24 /**
17 * NODE:SPH 25 * NODE:SPH
@@ -23,5 +31,47 @@ public class FWB_SPH { @@ -23,5 +31,47 @@ public class FWB_SPH {
23 * DEMO: 31 * DEMO:
24 * /ELI 32 * /ELI
25 */ 33 */
26 - private String sph_code; 34 + private List<String> sph_code;
  35 +
  36 + public List<String> getSph_code() {
  37 + return sph_code;
  38 + }
  39 +
  40 + public void setSph_code(List<String> sph_code) {
  41 + this.sph_code = sph_code;
  42 + }
  43 +
  44 + public boolean codeCheck(String code) throws FWBException {
  45 + String patternStr = "^[A-Z]{3}$";
  46 + Pattern pattern = Pattern.compile(patternStr);
  47 + Matcher matcher = pattern.matcher(code);
  48 + if (!matcher.find()){
  49 + throw new FWBException(FWBExceptionType.SPH_CODE_FAILD);
  50 + }
  51 + return true;
  52 + }
  53 +
  54 + @Override
  55 + public String getFWBNodeText() throws FWBException {
  56 + StringBuilder sb = new StringBuilder("");
  57 + if (sph_code!=null && !sph_code.isEmpty()){
  58 + if (sph_code.size()>9){
  59 + throw new FWBException(FWBExceptionType.SPH_LENGTH_FAILD);
  60 + }
  61 + sb.append(getNodeName());
  62 + for (String code : sph_code) {
  63 + if(codeCheck(code)){
  64 + sb.append(SPLIT_CODE).append(code);
  65 + }
  66 + }
  67 + sb.append(CRLF);
  68 + }
  69 +
  70 + return sb.toString();
  71 + }
  72 +
  73 + @Override
  74 + public String getNodeName() {
  75 + return "SPH";
  76 + }
27 } 77 }
@@ -99,6 +99,9 @@ public enum FWBExceptionType { @@ -99,6 +99,9 @@ public enum FWBExceptionType {
99 REF_SOMA_REGEX_FAILD("2031", "REF- Sender Office Message Address RegEx Faild"), 99 REF_SOMA_REGEX_FAILD("2031", "REF- Sender Office Message Address RegEx Faild"),
100 REF_SPID_REGEX_FAILD("206", "REF- Sender Participant Idenfitication RegEx Faild,缺少关联节点信息"), 100 REF_SPID_REGEX_FAILD("206", "REF- Sender Participant Idenfitication RegEx Faild,缺少关联节点信息"),
101 101
  102 + SPH_LENGTH_FAILD("2520", "SPH-最多只支持9个操作代码信息"),
  103 + SPH_CODE_FAILD("2522", "SPH-代码格式信息有误"),
  104 +
102 OCI_CSRC_ERROR("297", "缺少 Other Customs,Security And Regulatory Control Information Identifier"); 105 OCI_CSRC_ERROR("297", "缺少 Other Customs,Security And Regulatory Control Information Identifier");
103 106
104 /** 107 /**