Commit f9e08bdc by WeiCong

完成swift报文的组报功能

parent 599cf024
...@@ -12,219 +12,203 @@ public class TagCell { ...@@ -12,219 +12,203 @@ public class TagCell {
public String content; public String content;
public int line; public int line;
public String value; public String value;
public TagCell clone()
{ public TagCell clone() {
TagCell cell = new TagCell(); TagCell cell = new TagCell();
cell.fixed = fixed; cell.fixed = fixed;
cell.length = length; cell.length = length;
cell.type = type; cell.type = type;
cell.cnt = cnt; cell.cnt = cnt;
cell.content = content; cell.content = content;
cell.line=line; cell.line = line;
cell.value = value; cell.value = value;
return cell; return cell;
} }
public void setValue(String amt)
{ public void setValue(String amt) {
if("d".equals(type) || ("AMOUNT".equals(content)&&"FUNC".equals(type))) if ("d".equals(type) || ("AMOUNT".equals(content) && "FUNC".equals(type))) {
{ if (amt.endsWith(","))
if(amt.endsWith(",")) this.value = amt.substring(0, amt.length() - 1);
this.value = amt.substring(0,amt.length() - 1);
else else
this.value = amt.replaceAll(",", "."); this.value = amt.replaceAll(",", ".");
return ; return;
} }
this.value = amt; this.value = amt;
} }
public String toReg() public String toReg() {
{
return toReg(true); return toReg(true);
} }
public String toReg(boolean useRegName) public String toReg(boolean useRegName) {
{ String cnt = "S" + this.cnt;
String cnt = "S"+this.cnt; if (CONST.equals(type)) {
if(CONST.equals(type)) if ("CRLF".equals(content))
{
if("CRLF".equals(content))
return "[\\r\\n]{1,2}"; return "[\\r\\n]{1,2}";
return content; return content;
} } else if (FUNC.equals(type)) {
else if(FUNC.equals(type)) if ("AMOUNT".equals(content)) {
{ if (useRegName)
if("AMOUNT".equals(content)) return "(?<" + cnt + ">[\\d,.]{1," + this.length + "})";
{
if(useRegName)
return "(?<"+cnt+">[\\d,]{1,"+this.length+"})";
else else
return "[\\d,]{1,"+this.length+"}"; return "[\\d,.]{1," + this.length + "}";
} } else if ("NUMBER".equals(content)) {
else if("NUMBER".equals(content)) if (useRegName)
{ return "(?<" + cnt + ">[\\d,]{1," + this.length + "})";
if(useRegName)
return "(?<"+cnt+">[\\d,]{1,"+this.length+"})";
else else
return "[\\d,]{1,"+this.length+"}"; return "[\\d,]{1," + this.length + "}";
} } else if ("HHMM".equals(content)) //hhmm
else if("HHMM".equals(content)) //hhmm
{ {
if(useRegName) if (useRegName)
return "(?<"+cnt+">\\d{4})"; return "(?<" + cnt + ">\\d{4})";
else else
return "\\d{4}"; return "\\d{4}";
} } else if ("TIME2".equals(content)) {
else if("TIME2".equals(content)) if (useRegName)
{ return "(?<" + cnt + ">\\d{6})";
if(useRegName)
return "(?<"+cnt+">\\d{6})";
else else
return "\\d{6}"; return "\\d{6}";
} } else if ("TIME3".equals(content)) {
else if("TIME3".equals(content)) if (useRegName)
{ return "(?<" + cnt + ">\\d{2}\\d{2}?)";
if(useRegName)
return "(?<"+cnt+">\\d{2}\\d{2}?)";
else else
return "\\d{2}\\d{2}?"; return "\\d{2}\\d{2}?";
} } else if ("OFFSET".equals(content))//hhmm
else if("OFFSET".equals(content))//hhmm
{ {
if(useRegName) if (useRegName)
return "(?<"+cnt+">\\d{4})"; return "(?<" + cnt + ">\\d{4})";
else else
return "\\d{4}"; return "\\d{4}";
} } else if ("SIGN".equals(content)) // +/-
else if("SIGN".equals(content)) // +/-
{ {
if(useRegName) if (useRegName)
return "(?<"+cnt+">\\+|\\-)"; return "(?<" + cnt + ">\\+|\\-)";
else else
return "\\+|\\-"; return "\\+|\\-";
} } else if ("DATE1".equals(content)) //yyMMdd
else if("DATE1".equals(content)) //yyMMdd
{ {
if(useRegName) if (useRegName)
return "(?<"+cnt+">\\d{4})"; return "(?<" + cnt + ">\\d{4})";
else else
return "\\d{4}"; return "\\d{4}";
} } else if ("DATE2".equals(content)) //yyMMdd
else if("DATE2".equals(content)) //yyMMdd
{ {
if(useRegName) if (useRegName)
return "(?<"+cnt+">\\d{6})"; return "(?<" + cnt + ">\\d{6})";
else else
return "\\d{6}"; return "\\d{6}";
} } else if ("YEAR".equals(content)) {
else if("YEAR".equals(content)) if (useRegName)
{ return "(?<" + cnt + ">\\d{4})";
if(useRegName)
return "(?<"+cnt+">\\d{4})";
else else
return "\\d{4}"; return "\\d{4}";
} } else if ("DATE4".equals(content)) //yyyyMMdd
else if("DATE4".equals(content)) //yyyyMMdd
{ {
if(useRegName) if (useRegName)
return "(?<"+cnt+">\\d{8})"; return "(?<" + cnt + ">\\d{8})";
else else
return "\\d{8}"; return "\\d{8}";
} } else if ("CUR".equals(content)) //yyyyMMdd
else if("CUR".equals(content)) //yyyyMMdd
{ {
if(useRegName) if (useRegName)
return "(?<"+cnt+">[A-Z]{3})"; return "(?<" + cnt + ">[A-Z]{3})";
else else
return "[A-Z]{3}"; return "[A-Z]{3}";
} } else if ("DC".equals(content)) //yyyyMMdd
else if("DC".equals(content)) //yyyyMMdd
{ {
if(useRegName) if (useRegName)
return "(?<"+cnt+">C|D|RC|RD)"; return "(?<" + cnt + ">C|D|RC|RD)";
else else
return "C|D|RC|RD"; return "C|D|RC|RD";
} } else if ("SWIFTBIC".equals(content)) //4!a2!a2!c3!c
else if("SWIFTBIC".equals(content)) //4!a2!a2!c3!c
{ {
if(useRegName) if (useRegName)
return "(?<"+cnt+">[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?)"; return "(?<" + cnt + ">[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?)";
else else
return "[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?"; return "[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?";
} } else if ("MT".equals(content)) {
else if("MT".equals(content)) if (useRegName)
{ return "(?<" + cnt + ">[1-9]\\d{2})";
if(useRegName)
return "(?<"+cnt+">[1-9]\\d{2})";
else else
return "[1-9]\\d{2}"; return "[1-9]\\d{2}";
} } else if ("SB-LC".equals(content)) {
else if("SB-LC".equals(content)) if (useRegName)
{ return "(?<" + cnt + ">[A-Z]{4}[A-Z0-9]{2}\\d{4}[A-Z]{4}[A-Z0-9]{2})";
if(useRegName)
return "(?<"+cnt+">[A-Z]{4}[A-Z0-9]{2}\\d{4}[A-Z]{4}[A-Z0-9]{2})";
else else
return "[A-Z]{4}[A-Z0-9]{2}\\d{4}[A-Z]{4}[A-Z0-9]{2}"; return "[A-Z]{4}[A-Z0-9]{2}\\d{4}[A-Z]{4}[A-Z0-9]{2}";
} } else if ("DM".equals(content)) {
else if("DM".equals(content)) if (useRegName)
{ return "(?<" + cnt + ">D|M)";
if(useRegName)
return "(?<"+cnt+">D|M)";
else else
return "D|M"; return "D|M";
} } else if ("CC".equals(content)) {
else if("CC".equals(content)) if (useRegName)
{ return "(?<" + cnt + ">[A-Z]{2})";
if(useRegName)
return "(?<"+cnt+">[A-Z]{2})";
else else
return "[A-Z]{2}"; return "[A-Z]{2}";
} else {
System.err.println("unknow function:" + content);
} }
else{ } else {
System.err.println("unknow function:"+content);
}
}
else
{
String type = ""; String type = "";
char c = this.type.charAt(0); char c = this.type.charAt(0);
switch(c) switch (c) {
{ case 'n':
case 'n': type = "\\d";break; type = "\\d";
case 'a': type = "[A-Z]";break; break;
case 'd': type = "[\\d,]";break; case 'a':
case 'x': type = "[\\w/\\-\\?:\\(\\)\\.,'+\\{\\} ]";break; type = "[A-Z]";
case 'y': type = "[0-9A-Z\\.,\\-\\(\\)/='\\+:\\?\\!\"%&\\*\\<\\>;\\s]";break; break;
case 'z': type = "[\\w\\.,\\-\\(\\)/='\\+:\\?!\"%&\\*\\<\\>;\\{\\s@#]";break; case 'd':
case 'c': type = "[A-Z0-9]";break; type = "[\\d,.]";
case 'h': type = "[A-F0-9]";break; break;
case 'e': type = "\\s";break; case 'x':
case 'A': type = "[A-Za-z]";break; type = "[\\w/\\-\\?:\\(\\)\\.,'+\\{\\} ]";
case 'B': type = "[A-Za-z0-9]";break; break;
default:System.err.println("unknow type:"+type); case 'y':
type = "[0-9A-Z\\.,\\-\\(\\)/='\\+:\\?\\!\"%&\\*\\<\\>;\\s]";
break;
case 'z':
type = "[\\w\\.,\\-\\(\\)/='\\+:\\?!\"%&\\*\\<\\>;\\{\\s@#]";
break;
case 'c':
type = "[A-Z0-9]";
break;
case 'h':
type = "[A-F0-9]";
break;
case 'e':
type = "\\s";
break;
case 'A':
type = "[A-Za-z]";
break;
case 'B':
type = "[A-Za-z0-9]";
break;
default:
System.err.println("unknow type:" + type);
} }
//String length = ""; //String length = "";
String nolines = ""; String nolines = "";
if(fixed || minLen==length) if (fixed || minLen == length) {
{ nolines = type + "{" + length + "}";
nolines = type+"{"+length+"}"; } else
}else nolines = type + "{" + minLen + "," + length + "}";
nolines = type+"{"+minLen+","+length+"}"; if (line > 1) {
if(line > 1) if (useRegName)
{ nolines = nolines + "([\\r\\n]{1,2}" + nolines + "){0," + (line - 1) + "}";
if(useRegName)
nolines = nolines+"([\\r\\n]{1,2}"+nolines +"){0,"+(line-1)+"}";
else //校验所用的,只转换单行 else //校验所用的,只转换单行
{ {
if(fixed || minLen==length) if (fixed || minLen == length) {
{ nolines = type + "{" + length + "}";
nolines = type+"{"+length+"}"; } else
}else nolines = type + "{" + 0 + "," + length + "}";
nolines = type+"{"+0+","+length+"}";
} }
} }
if(useRegName) if (useRegName)
return "(?<"+cnt+">"+nolines+")"; return "(?<" + cnt + ">" + nolines + ")";
else else
return nolines; return nolines;
} }
......
...@@ -5,123 +5,130 @@ import com.brilliace.swifteditor.tag.message.MessageArea; ...@@ -5,123 +5,130 @@ import com.brilliace.swifteditor.tag.message.MessageArea;
import java.util.*; import java.util.*;
public class TagLine implements MessageArea { public class TagLine implements MessageArea {
private final int type = TAG;
public List<TagCell> cellList = new ArrayList<TagCell>(); public List<TagCell> cellList = new ArrayList<TagCell>();
public List<int[]> options = new ArrayList<int[]>(); public List<int[]> options = new ArrayList<int[]>();
public MessageArea parent;
public boolean onlyOne;
String analyzeReg = null;
private String pattern; private String pattern;
private String value; private String value;
private String tagName; private String tagName;
private String status; private String status;
public MessageArea parent; private int maxCnt = 0;
public boolean onlyOne; private int tno = 0;
private String desp = "";
private List<String> suffix = new ArrayList<String>();
public String getStatus() { public String getStatus() {
return status; return status;
} }
public void setStatus(String status) { public void setStatus(String status) {
this.status = status; this.status = status;
} }
private int maxCnt = 0;
private int tno = 0;
private String desp = "";
private final int type = TAG;
private List<String> suffix = new ArrayList<String>();
public void add(TagCell cell) { public void add(TagCell cell) {
cellList.add(cell); cellList.add(cell);
} }
public void addOptions(int[] points)
{ public void addOptions(int[] points) {
options.add(points); options.add(points);
} }
public void fillOption(int index,int point)
{ public void fillOption(int index, int point) {
if(options.size() ==0) if (options.size() == 0) {
{ System.err.println("error pattern:" + this.getName() + "----" + this.getPattern());
System.err.println("error pattern:"+this.getName()+"----"+this.getPattern()); return;
return ;
} }
options.get(index)[1] = point; options.get(index)[1] = point;
} }
public void fillLastOption(int point)
{ public void fillLastOption(int point) {
if(options.size() ==0) if (options.size() == 0) {
{ System.err.println("error pattern:" + this.getName() + "----" + this.getPattern());
System.err.println("error pattern:"+this.getName()+"----"+this.getPattern()); return;
return ; }
options.get(options.size() - 1)[1] = point;
} }
options.get(options.size() -1)[1] = point;
public String getPattern() {
return pattern;
} }
public void setPattern(String pattern) { public void setPattern(String pattern) {
this.pattern = pattern; this.pattern = pattern;
} }
public String getPattern()
{ public String getSourceValue() {
return pattern; return this.value;
} }
public void setValue(String value)
{ /***
if(value == null) * 返回组装后的swift域值
{ * @return
*/
public String getValue() {
StringBuilder sb = new StringBuilder();
this.toSwfMessage(sb);
String val = sb.toString();
return val;
}
public void setValue(String value) {
if (value == null) {
this.value = null; this.value = null;
return ; return;
} }
if(this.value!=null && this.value.equals(value)) if (this.value != null && this.value.equals(value))
return; return;
this.value = value; this.value = value;
this.fillCellValue(); this.fillCellValue();
} }
public String getSourceValue()
{
return this.value;
}
/*** /***
* 返回组装后的 * 返回组装后人类查看的域
* @return * @return
*/ */
public String getValue() public String getValueForHuman() {
{
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
this.toSwfMessage(sb); this.toHumanMessage(sb);
return sb.toString(); String val = sb.toString();
return val;
} }
public String getCellValue(int position)
{ public String getCellValue(int position) {
for(TagCell cell : this.cellList) for (TagCell cell : this.cellList) {
{ if (cell.cnt == position)
if(cell.cnt == position)
return cell.value; return cell.value;
} }
return null; return null;
} }
/*** /***
* 将栏位值填充到指定的栏位中去 * 将栏位值填充到指定的栏位中去
*/ */
private void fillCellValue() private void fillCellValue() {
{ Map<Integer, String> subValues = TagAnalyzer.analyze(this, value);
Map<Integer,String> subValues = TagAnalyzer.analyze(this, value); if (subValues == null)
if(subValues == null) return;
return ; for (Map.Entry<Integer, String> entry : subValues.entrySet()) {
for(Map.Entry<Integer, String> entry : subValues.entrySet())
{
int cnt = entry.getKey(); int cnt = entry.getKey();
for(TagCell cell : cellList) for (TagCell cell : cellList) {
{ if (cell.cnt == cnt) {
if(cell.cnt == cnt) cell.setValue(entry.getValue());
{
cell.setValue( entry.getValue());
break; break;
} }
} }
} }
} }
public TagLine clone()
{ public TagLine clone() {
TagLine cp = new TagLine(); TagLine cp = new TagLine();
for(TagCell cell: cellList) for (TagCell cell : cellList) {
{
cp.add(cell.clone()); cp.add(cell.clone());
} }
for(int[] option : options) for (int[] option : options) {
{
int[] cpopt = Arrays.copyOf(option, 2); int[] cpopt = Arrays.copyOf(option, 2);
cp.addOptions(cpopt); cp.addOptions(cpopt);
} }
...@@ -136,75 +143,118 @@ public class TagLine implements MessageArea { ...@@ -136,75 +143,118 @@ public class TagLine implements MessageArea {
cp.analyzeReg = this.analyzeReg; cp.analyzeReg = this.analyzeReg;
return cp; return cp;
} }
public void toSwfMessage(StringBuilder sb) { public void toSwfMessage(StringBuilder sb) {
for(TagCell cell : this.cellList) boolean isEmpty = true;
if("CONST".equals(cell.type)) TagCell lastCell = null;
for (TagCell cell : this.cellList) {
if ("CONST".equals(cell.type)) {
lastCell = cell;
if ("CRLF".equals(cell.content)) {
sb.append("\r\n");
} else {
sb.append(cell.content); sb.append(cell.content);
else if(cell.value != null) }
} else if (cell.value != null) {
isEmpty = false;
if ("d".equals(cell.type) || ("AMOUNT".equals(cell.content) && "FUNC".equals(cell.type))) {
if (cell.value.indexOf(".") > 0) {
sb.append(cell.value.replace(".", ","));
} else {
sb.append(cell.value + ",");
}
} else {
if (lastCell != null && cell.value.startsWith(lastCell.content)) {
sb.append(cell.value.substring(lastCell.content.length()));
} else {
sb.append(cell.value); sb.append(cell.value);
} }
}
lastCell = null;
}
}
if (isEmpty) {
sb.delete(0, sb.length());
}
}
public void toHumanMessage(StringBuilder sb) {
boolean isEmpty = true;
for (TagCell cell : this.cellList) {
if ("CONST".equals(cell.type)) {
if ("CRLF".equals(cell.content)) {
sb.append("\r\n");
} else {
sb.append(cell.content);
}
} else if (cell.value != null) {
isEmpty = false;
sb.append(cell.value);
}
}
if (isEmpty) {
sb.delete(0, sb.length());
}
}
public String getName() { public String getName() {
return tagName; return tagName;
} }
public void setName(String name) {
this.tagName = name;
}
public void addSubArea(MessageArea sub) { public void addSubArea(MessageArea sub) {
} }
public boolean isEnd()
{ public boolean isEnd() {
return true; return true;
} }
public int getType() { public int getType() {
return type; return type;
} }
public void setName(String name) {
this.tagName = name;
}
/*** /***
* 返回解析字符串 * 返回解析字符串
* @return * @return
*/ */
public String toAnalyzeReg() public String toAnalyzeReg() {
{
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
int cnt = 0; int cnt = 0;
boolean hasOpen = false; boolean hasOpen = false;
for(TagCell cell : cellList) for (TagCell cell : cellList) {
{ for (int[] opt : options) {
for(int[] opt : options) if (cnt == opt[0]) {
{
if(cnt == opt[0])
{
sb.append('('); sb.append('(');
hasOpen=true; hasOpen = true;
// break; // break;
} } else if (cnt == opt[1]) {
else if(cnt == opt[1])
{
sb.append(")?"); sb.append(")?");
hasOpen=false; hasOpen = false;
// break; // break;
} }
} }
cnt++; cnt++;
sb.append(cell.toReg()); sb.append(cell.toReg());
} }
if(hasOpen) if (hasOpen)
sb.append(")?"); sb.append(")?");
return sb.toString(); return sb.toString();
} }
//分段校验信息 //分段校验信息
public Map<String,Object> toSegRegMap() public Map<String, Object> toSegRegMap() {
{ Map<String, Object> set = new HashMap<String, Object>();
Map<String,Object> set = new HashMap<String,Object>();
// int cnt = 0; // int cnt = 0;
for(int cnt =0;cnt<this.cellList.size();cnt++) for (int cnt = 0; cnt < this.cellList.size(); cnt++) {
{
TagCell cell = this.cellList.get(cnt); TagCell cell = this.cellList.get(cnt);
if(cell.cnt < 0) if (cell.cnt < 0)
continue; continue;
String key = "s"+cell.cnt; String key = "s" + cell.cnt;
HashMap<String,Object> info = new HashMap<String,Object>(); HashMap<String, Object> info = new HashMap<String, Object>();
set.put(key, info); set.put(key, info);
info.put("reg", cell.toReg(false)); info.put("reg", cell.toReg(false));
info.put("type", cell.type); info.put("type", cell.type);
...@@ -214,10 +264,8 @@ public class TagLine implements MessageArea { ...@@ -214,10 +264,8 @@ public class TagLine implements MessageArea {
info.put("length", cell.length); info.put("length", cell.length);
info.put("line", cell.line); info.put("line", cell.line);
for(int[] opt : options) for (int[] opt : options) {
{ if (cnt >= opt[0] && cnt < opt[1]) {
if(cnt >= opt[0] && cnt<opt[1])
{
info.put("option", "O"); info.put("option", "O");
} }
} }
...@@ -225,49 +273,54 @@ public class TagLine implements MessageArea { ...@@ -225,49 +273,54 @@ public class TagLine implements MessageArea {
return set; return set;
} }
String analyzeReg = null; public String getAnalyzeReg() {
public void setAnalyzeReg(String analyzeReg){ if (analyzeReg == null)
this.analyzeReg=analyzeReg;
}
public String getAnalyzeReg()
{
if(analyzeReg==null)
analyzeReg = this.toAnalyzeReg(); analyzeReg = this.toAnalyzeReg();
return analyzeReg; return analyzeReg;
} }
public void setAnalyzeReg(String analyzeReg) {
this.analyzeReg = analyzeReg;
}
public int getMaxCnt() { public int getMaxCnt() {
return maxCnt; return maxCnt;
} }
public void setMaxCnt(int maxCnt) { public void setMaxCnt(int maxCnt) {
this.maxCnt = maxCnt; this.maxCnt = maxCnt;
} }
public int getTno() { public int getTno() {
return tno; return tno;
} }
public void setTno(int tno) { public void setTno(int tno) {
this.tno = tno; this.tno = tno;
} }
public String getDesp() { public String getDesp() {
return desp; return desp;
} }
public void setDesp(String desp) { public void setDesp(String desp) {
this.desp = desp; this.desp = desp;
} }
public List<String> getSuffix() {
return this.suffix;
}
public void setSuffix(List<String> tagSuffix) { public void setSuffix(List<String> tagSuffix) {
this.suffix.clear(); this.suffix.clear();
this.suffix.addAll(tagSuffix); this.suffix.addAll(tagSuffix);
} }
public List<String> getSuffix()
{ public Map<String, String> getIndexMap() {
return this.suffix; Map<String, String> indexMap = new HashMap<String, String>();
} for (TagCell cell : cellList) {
public Map<String,String> getIndexMap() { if (cell.cnt > 0 && cell.value != null)
Map<String,String> indexMap = new HashMap<String,String>(); indexMap.put("s" + cell.cnt, cell.value);
for(TagCell cell : cellList)
{
if(cell.cnt > 0 && cell.value!=null)
indexMap.put("s"+cell.cnt, cell.value);
} }
return indexMap; return indexMap;
} }
......
...@@ -27,6 +27,10 @@ public class MessageFormat { ...@@ -27,6 +27,10 @@ public class MessageFormat {
if (swfmsg == null && mtType.charAt(1) == '9') if (swfmsg == null && mtType.charAt(1) == '9')
swfmsg = mtCache.get('n' + mtType.substring(1)); swfmsg = mtCache.get('n' + mtType.substring(1));
if (swfmsg == null) {
mtType = mtType.toUpperCase();
swfmsg = mtCache.get(mtType);
}
if (swfmsg != null) { if (swfmsg != null) {
swfmsg.setMtType(mtType); swfmsg.setMtType(mtType);
return swfmsg.clone(); return swfmsg.clone();
......
...@@ -6,6 +6,10 @@ import com.brilliace.swifteditor.tag.TagLine; ...@@ -6,6 +6,10 @@ import com.brilliace.swifteditor.tag.TagLine;
import com.brilliace.swifteditor.util.Assert; import com.brilliace.swifteditor.util.Assert;
import com.google.gson.Gson; import com.google.gson.Gson;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.*; import java.util.*;
import java.util.regex.Pattern; import java.util.regex.Pattern;
...@@ -17,6 +21,9 @@ public class SWFMessage extends AbstractMessageArea { ...@@ -17,6 +21,9 @@ public class SWFMessage extends AbstractMessageArea {
private Map<Integer, TagLine> flatModel = new HashMap<>(); private Map<Integer, TagLine> flatModel = new HashMap<>();
private Map<String, Integer> tag2No = new HashMap<>(); private Map<String, Integer> tag2No = new HashMap<>();
private Map<String, String> bscInfo; private Map<String, String> bscInfo;
private volatile String body;
private String sndbic;
private String rcvbic;
protected SWFMessage() { protected SWFMessage() {
} }
...@@ -81,6 +88,14 @@ public class SWFMessage extends AbstractMessageArea { ...@@ -81,6 +88,14 @@ public class SWFMessage extends AbstractMessageArea {
sb.append("]"); sb.append("]");
} }
public void setSndbic(String sndbic) {
this.sndbic = sndbic;
}
public void setRcvbic(String rcvbic) {
this.rcvbic = rcvbic;
}
public Map<Integer, String> getHeaders() { public Map<Integer, String> getHeaders() {
return headers; return headers;
} }
...@@ -231,7 +246,7 @@ public class SWFMessage extends AbstractMessageArea { ...@@ -231,7 +246,7 @@ public class SWFMessage extends AbstractMessageArea {
throw new IllegalArgumentException("域" + tagLine.getName() + "需要填充List集合类型的数据"); throw new IllegalArgumentException("域" + tagLine.getName() + "需要填充List集合类型的数据");
} }
} }
setGenericRepetitive((AbstractMessageArea) tagLine.parent, index, tagLine.getTno(), (List<Object>) val, 0); setGenericRepetitive((AbstractMessageArea) tagLine.parent, index, tagLine.getTno(), (List<Object>) val, 0, tagName);
} else { } else {
tagLine.setValue((String) val); tagLine.setValue((String) val);
} }
...@@ -241,7 +256,14 @@ public class SWFMessage extends AbstractMessageArea { ...@@ -241,7 +256,14 @@ public class SWFMessage extends AbstractMessageArea {
int part = Integer.parseInt(path.substring(index + 1)) + 1; int part = Integer.parseInt(path.substring(index + 1)) + 1;
Assert.state(part > 0, "索引[" + path + "]指定的域块不存在"); Assert.state(part > 0, "索引[" + path + "]指定的域块不存在");
if (tagLine.parent != null) { if (tagLine.parent != null) {
setGenericRepetitive((AbstractMessageArea) tagLine.parent, part, tagLine.getTno(), (List<Object>) val, 0); if (val instanceof String && tagLine.onlyOne) {
if (tagLine.onlyOne) {
val = Collections.singletonList(val);
} else {
throw new IllegalArgumentException("域" + tagLine.getName() + "需要填充List集合类型的数据");
}
}
setGenericRepetitive((AbstractMessageArea) tagLine.parent, part, tagLine.getTno(), (List<Object>) val, 0, tagName);
} else { } else {
for (TagCell cell : tagLine.cellList) { for (TagCell cell : tagLine.cellList) {
if (cell.cnt == part) { if (cell.cnt == part) {
...@@ -270,12 +292,13 @@ public class SWFMessage extends AbstractMessageArea { ...@@ -270,12 +292,13 @@ public class SWFMessage extends AbstractMessageArea {
} }
private boolean setGenericRepetitive(AbstractMessageArea parent, int index, int ano, List<Object> rs, int cnt) { private boolean setGenericRepetitive(AbstractMessageArea parent, int index, int ano, List<Object> rs, int cnt, String tagName) {
if (parent.getType() == MessageArea.CYC || parent.getType() == MessageArea.SEQ) { if (parent.getType() == MessageArea.CYC || parent.getType() == MessageArea.SEQ) {
for (int i = 0; i < parent.getFields().size(); i++) { for (int i = 0; i < parent.getFields().size(); i++) {
MessageArea item = parent.getFields().get(i); MessageArea item = parent.getFields().get(i);
if (item.getType() == MessageArea.TAG) { if (item.getType() == MessageArea.TAG) {
if (((TagLine) item).getTno() == ano) { if (((TagLine) item).getTno() == ano) {
checkTagLine((TagLine) item, tagName);
if (index == -1) { if (index == -1) {
((TagLine) item).setValue((String) rs.get(cnt)); ((TagLine) item).setValue((String) rs.get(cnt));
} else { } else {
...@@ -293,8 +316,8 @@ public class SWFMessage extends AbstractMessageArea { ...@@ -293,8 +316,8 @@ public class SWFMessage extends AbstractMessageArea {
continue; continue;
} }
if (parent.getType() == MessageArea.SEQ ? if (parent.getType() == MessageArea.SEQ ?
setGenericRepetitive((AbstractMessageArea) item, index, ano, (List) rs.get(cnt), 0) setGenericRepetitive((AbstractMessageArea) item, index, ano, (List) rs.get(cnt), 0, tagName)
: setGenericRepetitive((AbstractMessageArea) item, index, ano, rs, cnt)) { : setGenericRepetitive((AbstractMessageArea) item, index, ano, rs, cnt, tagName)) {
return true; return true;
} }
} }
...@@ -303,7 +326,7 @@ public class SWFMessage extends AbstractMessageArea { ...@@ -303,7 +326,7 @@ public class SWFMessage extends AbstractMessageArea {
if (((AbstractMessageArea) parent).withIn(ano)) { if (((AbstractMessageArea) parent).withIn(ano)) {
MessageArea cp = ((AbstractMessageArea) parent).getFields().get(0);//默认有一个组项 MessageArea cp = ((AbstractMessageArea) parent).getFields().get(0);//默认有一个组项
do { do {
setGenericRepetitive((AbstractMessageArea) cp, index, ano, rs, cnt++); setGenericRepetitive((AbstractMessageArea) cp, index, ano, rs, cnt++, tagName);
if (rs.size() <= cnt) if (rs.size() <= cnt)
return true; return true;
try { try {
...@@ -380,7 +403,7 @@ public class SWFMessage extends AbstractMessageArea { ...@@ -380,7 +403,7 @@ public class SWFMessage extends AbstractMessageArea {
rs = new LinkedList<Object>(); rs = new LinkedList<Object>();
getGenericRepetitive((AbstractMessageArea) tagLine.parent, index, tagLine.getTno(), (List<Object>) rs); getGenericRepetitive((AbstractMessageArea) tagLine.parent, index, tagLine.getTno(), (List<Object>) rs);
} else { } else {
rs = tagLine.getSourceValue(); rs = tagLine.getValueForHuman();
} }
} else { } else {
tagLine = this.flatModel.get(Integer.valueOf(path.substring(0, index))); tagLine = this.flatModel.get(Integer.valueOf(path.substring(0, index)));
...@@ -429,7 +452,7 @@ public class SWFMessage extends AbstractMessageArea { ...@@ -429,7 +452,7 @@ public class SWFMessage extends AbstractMessageArea {
if (item.getType() == MessageArea.TAG) { if (item.getType() == MessageArea.TAG) {
if (((TagLine) item).getTno() == ano) { if (((TagLine) item).getTno() == ano) {
if (index == -1) { if (index == -1) {
rs.add(((TagLine) item).getSourceValue()); rs.add(((TagLine) item).getValueForHuman());
} else { } else {
for (TagCell cell : ((TagLine) item).cellList) { for (TagCell cell : ((TagLine) item).cellList) {
if (cell.cnt == index) { if (cell.cnt == index) {
...@@ -509,4 +532,110 @@ public class SWFMessage extends AbstractMessageArea { ...@@ -509,4 +532,110 @@ public class SWFMessage extends AbstractMessageArea {
} }
} }
/**
* 获取swift报文体
*/
public String getMsg() {
if (body != null) {
return body;
}
StringWriter sw = null;
SwtBufferedWriter sb = null;
try {
Assert.notNull(sndbic, "发报行不能为空");
Assert.notNull(rcvbic, "收报行不能为空");
sw = new StringWriter();
sb = this.new SwtBufferedWriter(sw);
sb.write("{1:F01");
sb.write(getLogicalTerminalAddress(sndbic, "1") + "0000000000");
sb.write("}");
sb.write("{2:I" + mtType.substring(0, 3));
sb.write(getLogicalTerminalAddress(rcvbic, "2"));
sb.write("N");
sb.write("}");
if(mtType.endsWith("COV")){
sb.write("{3:{119:COV}}");
}
sb.write("{4:");
sb.newLine();
printMsgBody(this, sb);
sb.write("-}");
sb.flush();
body = sw.toString();
} catch (Exception e) {
return "获取报文体异常:" + e.getMessage();
} finally {
try {
if (sb != null)
sb.close();
} catch (IOException ioe) {
}
}
return body;
}
private String getLogicalTerminalAddress(String bic, String field) {
if (bic == null) {
return null;
}
if ((bic.length() == 8) || (bic.length() == 11) || (bic.length() == 12)) {
if (bic.length() == 11) {
if ("1".equals(field)) {
return bic.substring(0, 8) + "A" + bic.substring(8, 11);
}
return bic.substring(0, 8) + "X" + bic.substring(8, 11);
}
if (bic.length() == 8) {
if ("1".equals(field)) {
return bic.substring(0, 8) + "AXXX";
}
return bic.substring(0, 8) + "XXXX";
}
return bic;
}
throw new IllegalStateException("第"+field+"部分的bic码["+bic+"]不符合规范,需满足8、11或12位长度");
}
private void printMsgBody(AbstractMessageArea ma, SwtBufferedWriter sb) throws IOException {
for (MessageArea sma : ma.getFields()) {
if (sma.getType() == TAG) {
sb.write((TagLine) sma);
} else {
for (MessageArea ssma : ((AbstractMessageArea) sma).getFields()) {
AbstractMessageArea temp = (AbstractMessageArea) ssma;
printMsgBody(temp, sb);
}
}
}
}
class SwtBufferedWriter extends BufferedWriter {
public static final String NEW_LINE = "\r\n";
public SwtBufferedWriter(Writer arg0) {
super(arg0);
}
public void newLine() throws IOException {
write(NEW_LINE);
}
public void write(TagLine tagLine) throws IOException {
checkNullForNeedField(tagLine);
String val = tagLine.getValue();
if (!val.equals("")) {
write(":" + tagLine.getName() + ":");
write(val);
write(NEW_LINE);
}
}
private void checkNullForNeedField(TagLine tagLine) {
boolean flag = "M".equals(tagLine.getStatus()) && "".equals(tagLine.getValue()) ? true : false;
Assert.state(!flag, "域[" + tagLine.getName() + "]是必输项,不能为空");
}
}
} }
...@@ -9,18 +9,22 @@ import java.util.LinkedList; ...@@ -9,18 +9,22 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
public class ParseSwiftTest extends TestCase { public class ParseSwiftTest extends TestCase {
public void testLoadSwiftMessage() { public void testLoadSwiftMessage() {
String path = "F:\\brilliance\\jkpt-pj\\task\\南洋商业银行\\接口配置\\swift标准报文\\950.sf2"; String path = ParseSwiftTest.class.getClassLoader().getResource("103_SEND.sf2").getPath();
String msg = MessageAnalyzer.readFull(path); String msg = MessageAnalyzer.readFull(path);
SWFMessage swf = MessageAnalyzer.loadSwiftMessage(msg); SWFMessage swf = MessageAnalyzer.loadSwiftMessage(msg);
System.out.println(swf.toJSON()); System.out.println(swf.toJSON());
} }
public void testGetFlatModel() { public void testGetFlatModel() {
SWFMessage obj = MessageFormat.getSWFMessage("101"); SWFMessage obj = MessageFormat.getSWFMessage("202COV");
System.out.println(obj.getFlatModel()); System.out.println(obj.getFlatModel());
} }
/**
* 利用序号获取报文指定域和域块的值
*/
public void testGetGenericByNo() { public void testGetGenericByNo() {
String path = ParseSwiftTest.class.getClassLoader().getResource("950.sf2").getPath(); String path = ParseSwiftTest.class.getClassLoader().getResource("950.sf2").getPath();
String msg = MessageAnalyzer.readFull(path); String msg = MessageAnalyzer.readFull(path);
...@@ -40,6 +44,9 @@ public class ParseSwiftTest extends TestCase { ...@@ -40,6 +44,9 @@ public class ParseSwiftTest extends TestCase {
System.out.println("获取13域(循环的Sequence B的32B域)=" + swf.getGenericByNo("13")); System.out.println("获取13域(循环的Sequence B的32B域)=" + swf.getGenericByNo("13"));
} }
/**
* 利用域名获取报文指定域和域块的值
*/
public void testGetGenericByTag() { public void testGetGenericByTag() {
String path = ParseSwiftTest.class.getClassLoader().getResource("950.sf2").getPath(); String path = ParseSwiftTest.class.getClassLoader().getResource("950.sf2").getPath();
String msg = MessageAnalyzer.readFull(path); String msg = MessageAnalyzer.readFull(path);
...@@ -58,6 +65,9 @@ public class ParseSwiftTest extends TestCase { ...@@ -58,6 +65,9 @@ public class ParseSwiftTest extends TestCase {
assertEquals(swf.getGenericByTag("32B"), swf.getGenericByNo("13")); assertEquals(swf.getGenericByTag("32B"), swf.getGenericByNo("13"));
} }
/**
* 利用序号获取报文指定域和域块值得具体部分
*/
public void testGetGenericByNoWithIndexs() { public void testGetGenericByNoWithIndexs() {
String path = ParseSwiftTest.class.getClassLoader().getResource("950.sf2").getPath(); String path = ParseSwiftTest.class.getClassLoader().getResource("950.sf2").getPath();
String msg = MessageAnalyzer.readFull(path); String msg = MessageAnalyzer.readFull(path);
...@@ -74,6 +84,9 @@ public class ParseSwiftTest extends TestCase { ...@@ -74,6 +84,9 @@ public class ParseSwiftTest extends TestCase {
+ swf.getGenericByTag("32B.0", 0)); + swf.getGenericByTag("32B.0", 0));
} }
/**
* 利用域名获取报文指定域和域块值得具体部分
*/
public void testGetGenericByTagWithIndexs() { public void testGetGenericByTagWithIndexs() {
String path = ParseSwiftTest.class.getClassLoader().getResource("950.sf2").getPath(); String path = ParseSwiftTest.class.getClassLoader().getResource("950.sf2").getPath();
String msg = MessageAnalyzer.readFull(path); String msg = MessageAnalyzer.readFull(path);
...@@ -86,38 +99,37 @@ public class ParseSwiftTest extends TestCase { ...@@ -86,38 +99,37 @@ public class ParseSwiftTest extends TestCase {
assertEquals(swf.getGenericByTag("23E",1,2), swf.getGenericByNo("12",1,2)); assertEquals(swf.getGenericByTag("23E",1,2), swf.getGenericByNo("12",1,2));
} }
/**
* 利用序号设置域或域模块的值
*/
public void testSetGenericByNo() { public void testSetGenericByNo() {
SWFMessage swf = MessageFormat.getSWFMessage("950"); SWFMessage swf = MessageFormat.getSWFMessage("950");
//填充950的20域 //填充950的20域
swf.setGenericByNo("1", "STMMDL129058636E"); swf.setGenericByNo("1", "STMMDL129058636E");
assertEquals(swf.getGenericByNo("1"), "STMMDL129058636E"); assertEquals(swf.getGenericByNo("1"), "STMMDL129058636E");
//填充950的60a域 //填充950的60a域
swf.setGenericByNo("4", "C120330GBP94854,84", "60F"); swf.setGenericByNo("4", "C120330GBP94854.84", "60F");
assertEquals(swf.getGenericByNo("4"), "C120330GBP94854,84"); assertEquals(swf.getGenericByNo("4"), "C120330GBP94854.84");
//填充950的60a域的第二部分 //填充950的60a域的第二部分
swf.setGenericByNo("4.1", "120330", "60F"); swf.setGenericByNo("4.1", "120330", "60F");
assertEquals(swf.getGenericByNo("4.1"), "120330"); assertEquals(swf.getGenericByNo("4.1"), "120330");
//填充950的61循环域 //填充950的61循环域
List<String> sixtyone = new LinkedList<String>(); List<String> sixtyone = new LinkedList<String>();
sixtyone.add("1204120402DP10000,25S103CP23712040100007//GBS020420N8IM0HT\n" + sixtyone.add("1204120402DP10000.25S103CP23712040100007//GBS020420N8IM0HT\r\n" +
"FENG XING"); "FENG XING");
sixtyone.add("1304220402DP30000,55S103CP23712040100003//GBS02042H98IM0HS\n" + sixtyone.add("1304220402DP30000.55S103CP23712040100003//GBS02042H98IM0HS\r\n" +
"FENG ZZWE"); "FENG ZZWE");
sixtyone.add("1404320402DP20115,S103CP23712040200001//GBS020428Z8IVWJK\n" + sixtyone.add("1404320402DP20115S103CP23712040200001//GBS020428Z8IVWJK\r\n" +
"FENG EFFE"); "FENG EFFE");
swf.setGenericByNo("5", sixtyone); swf.setGenericByNo("5", sixtyone);
assertEquals(swf.getGenericByNo("5"), sixtyone); assertEquals(swf.getGenericByNo("5"), sixtyone);
//填充950的61域第5部分,Amount //填充950的61域第5部分,Amount
swf = MessageFormat.getSWFMessage("950"); swf = MessageFormat.getSWFMessage("950");
List<String> sixtyone_amount = new LinkedList<String>(); List<String> sixtyone_amount = new LinkedList<String>();
sixtyone_amount.add("10000,25");
sixtyone_amount.add("30000,55");
sixtyone_amount.add("20115,");
swf.setGenericByNo("5.4", sixtyone_amount);
sixtyone_amount = new LinkedList<String>();
sixtyone_amount.add("10000.25"); sixtyone_amount.add("10000.25");
sixtyone_amount.add("30000.55"); sixtyone_amount.add("30000.55");
sixtyone_amount.add("20115"); sixtyone_amount.add("20115");
swf.setGenericByNo("5.4", sixtyone_amount);
assertEquals(swf.getGenericByNo("5.4"), sixtyone_amount); assertEquals(swf.getGenericByNo("5.4"), sixtyone_amount);
//填充101的不可循环的Sequence A的20域 //填充101的不可循环的Sequence A的20域
swf = MessageFormat.getSWFMessage("101"); swf = MessageFormat.getSWFMessage("101");
...@@ -143,44 +155,50 @@ public class ParseSwiftTest extends TestCase { ...@@ -143,44 +155,50 @@ public class ParseSwiftTest extends TestCase {
swf.setGenericByNo("12", comList); swf.setGenericByNo("12", comList);
assertEquals(swf.getGenericByNo("12"), comList); assertEquals(swf.getGenericByNo("12"), comList);
comList = new LinkedList<>(); comList = new LinkedList<>();
comList.add("USD80000,"); comList.add("USD80000");
comList.add("USD12322,11"); comList.add("USD12322.11");
swf.setGenericByNo("13", comList); swf.setGenericByNo("13", comList);
assertEquals(swf.getGenericByNo("13"), comList); assertEquals(swf.getGenericByNo("13"), comList);
} }
/**
* 利用域名设置域或域模块的值
*/
public void testSetGenericByTag() { public void testSetGenericByTag() {
SWFMessage swf = MessageFormat.getSWFMessage("950"); SWFMessage swf = MessageFormat.getSWFMessage("950");
//填充950的20域 //填充950的20域
swf.setGenericByTag("20", "STMMDL129058636E"); swf.setGenericByTag("20", "STMMDL129058636E");
assertEquals(swf.getGenericByTag("20"), "STMMDL129058636E"); assertEquals(swf.getGenericByTag("20"), "STMMDL129058636E");
//填充950的60a域 //填充950的60a域
swf.setGenericByTag("60F", "C120330GBP94854,84"); swf.setGenericByTag("60F", "C120330GBP94854.84");
assertEquals(swf.getGenericByTag("60F"), "C120330GBP94854,84"); assertEquals(swf.getGenericByTag("60F"), "C120330GBP94854.84");
//填充950的60a域的第二部分 //填充950的60a域的第二部分
swf.setGenericByTag("60F.1", "120330"); swf.setGenericByTag("60F.1", "120330");
assertEquals(swf.getGenericByTag("60F.1"), "120330"); assertEquals(swf.getGenericByTag("60F.1"), "120330");
//填充950的61循环域 //填充950的61循环域
List<String> sixtyone = new LinkedList<String>(); List<String> sixtyone = new LinkedList<String>();
sixtyone.add("1204120402DP10000,25S103CP23712040100007//GBS020420N8IM0HT\n" + sixtyone.add("1204120402DP10000,25S103CP23712040100007//GBS020420N8IM0HT\r\n" +
"FENG XING"); "FENG XING");
sixtyone.add("1304220402DP30000,55S103CP23712040100003//GBS02042H98IM0HS\n" + sixtyone.add("1304220402DP30000,55S103CP23712040100003//GBS02042H98IM0HS\n\n" +
"FENG ZZWE"); "FENG ZZWE");
sixtyone.add("1404320402DP20115,S103CP23712040200001//GBS020428Z8IVWJK\n" + sixtyone.add("1404320402DP20115,S103CP23712040200001//GBS020428Z8IVWJK\n\n" +
"FENG EFFE"); "FENG EFFE");
swf.setGenericByTag("61", sixtyone); swf.setGenericByTag("61", sixtyone);
sixtyone = new LinkedList<String>();
sixtyone.add("1204120402DP10000.25S103CP23712040100007//GBS020420N8IM0HT\r\n" +
"FENG XING");
sixtyone.add("1304220402DP30000.55S103CP23712040100003//GBS02042H98IM0HS\r\n" +
"FENG ZZWE");
sixtyone.add("1404320402DP20115S103CP23712040200001//GBS020428Z8IVWJK\r\n" +
"FENG EFFE");
assertEquals(swf.getGenericByTag("61"), sixtyone); assertEquals(swf.getGenericByTag("61"), sixtyone);
//填充950的61域第5部分,Amount //填充950的61域第5部分,Amount
swf = MessageFormat.getSWFMessage("950"); swf = MessageFormat.getSWFMessage("950");
List<String> sixtyone_amount = new LinkedList<String>(); List<String> sixtyone_amount = new LinkedList<String>();
sixtyone_amount.add("10000,25");
sixtyone_amount.add("30000,55");
sixtyone_amount.add("20115,");
swf.setGenericByTag("61.4", sixtyone_amount);
sixtyone_amount = new LinkedList<String>();
sixtyone_amount.add("10000.25"); sixtyone_amount.add("10000.25");
sixtyone_amount.add("30000.55"); sixtyone_amount.add("30000.55");
sixtyone_amount.add("20115"); sixtyone_amount.add("20115");
swf.setGenericByTag("61.4", sixtyone_amount);
assertEquals(swf.getGenericByTag("61.4"), sixtyone_amount); assertEquals(swf.getGenericByTag("61.4"), sixtyone_amount);
//填充101的不可循环的Sequence A的20域 //填充101的不可循环的Sequence A的20域
swf = MessageFormat.getSWFMessage("101"); swf = MessageFormat.getSWFMessage("101");
...@@ -206,9 +224,96 @@ public class ParseSwiftTest extends TestCase { ...@@ -206,9 +224,96 @@ public class ParseSwiftTest extends TestCase {
swf.setGenericByTag("23E", comList); swf.setGenericByTag("23E", comList);
assertEquals(swf.getGenericByTag("23E"), comList); assertEquals(swf.getGenericByTag("23E"), comList);
comList = new LinkedList<>(); comList = new LinkedList<>();
comList.add("USD80000,"); comList.add("USD80000");
comList.add("USD12322,11"); comList.add("USD12322.11");
swf.setGenericByTag("32B", comList); swf.setGenericByTag("32B", comList);
assertEquals(swf.getGenericByTag("32B"), comList); assertEquals(swf.getGenericByTag("32B"), comList);
} }
/**
* 利用域名设置域或域模块的值,最后组成950 swift报文
*/
public void testGetMsgBodyFor950() {
SWFMessage swf = MessageFormat.getSWFMessage("950");
swf.setGenericByTag("20", "STMMDL129058636E");
swf.setGenericByTag("25", "68446375");
swf.setGenericByTag("28C.0", "00066");
swf.setGenericByTag("28C.1", "00001");
swf.setGenericByTag("60F.0", "C");
swf.setGenericByTag("60F.1", "120330");
swf.setGenericByTag("60F.2", "GBP");
swf.setGenericByTag("60F.3", "94854.84");
//填充950的61循环域
List<String> sixtyone = new LinkedList<String>();
sixtyone.add("1204120402DP10000.25S103CP23712040100007//GBS020420N8IM0HT\n" +
"FENG XING");
sixtyone.add("1304220402DP30000.55S103CP23712040100003//GBS02042H98IM0HS\n" +
"FENG ZZWE");
sixtyone.add("1404320402DP20115.S103CP23712040200001//GBS020428Z8IVWJK\n" +
"FENG EFFE");
swf.setGenericByTag("61", sixtyone);
swf.setGenericByTag("62F.0", "C");
swf.setGenericByTag("62F.1", "120402");
swf.setGenericByTag("62F.2", "GBP");
swf.setGenericByTag("62F.3", "14739.84");
swf.setGenericByTag("64", "C120402GBP14739.84");
System.out.println("开始生成950报文");
//设置收发报行
swf.setSndbic("NYCBCNSH");
swf.setRcvbic("ICBKGB2LAAAA");
System.out.println(swf.getMsg());
System.out.println("结束生成950报文");
}
/**
* 利用域名设置域或域模块的值,最后组成101 swift报文
*/
public void testGetMsgBodyFor101() {
SWFMessage swf = MessageFormat.getSWFMessage("101");
swf.setGenericByTag("20", "STMMDL129058636E");
swf.setGenericByTag("28D.0", "1");
swf.setGenericByTag("28D.1", "10");
swf.setGenericByTag("30", "191111");
List<Object> comList = new LinkedList<>();
comList.add("101651ATT000005W");
comList.add("321651ATT000005Z");
swf.setGenericByTag("21", comList);
comList = new LinkedList<>();
List<String> one = new LinkedList<>();
one.add("CHQB/HELLO");
one.add("CHQB/WORLD");
comList.add(one);
one = new LinkedList<>();
one.add("CHQB/MY");
one.add("CHQB/NAME");
one.add("CHQB/IS");
comList.add(one);
swf.setGenericByTag("23E", comList);
List<Object> b32 = new LinkedList<>();
b32.add("USD");
b32.add("USD");
swf.setGenericByTag("32B.0", b32);
b32 = new LinkedList<>();
b32.add("80000");
b32.add("12322.11");
swf.setGenericByTag("32B.1", b32);
List<Object> b59 = new LinkedList<>();
b59.add("/22222222222");
b59.add("/11111111111");
swf.setGenericByTag("59.0", b59);
b59 = new LinkedList<>();
b59.add("STRIX LIMITED\r\nFORREST HOUSE RONALDSWAY BALLASALLA\r\nISLE OF MAN UK");
b59.add("HOLLW LSHIUHIWA\r\nWZDESSS HOUSE WAWAZDR\r\nDEDFFF OF EE ZK");
swf.setGenericByTag("59.1", b59);
List<Object> b71 = new LinkedList<>();
b71.add("BEN");
b71.add("OUR");
swf.setGenericByTag("71A", b71);
//设置收发报行
swf.setSndbic("NYCBCNSH");
swf.setRcvbic("ICBKGB2LAAAA");
System.out.println("开始生成101报文");
System.out.println(swf.getMsg());
System.out.println("结束生成101报文");
}
} }
{1:F01NYCBCNSHAXXX0000000000}{2:I103BKCHHKHHAXXXN}{4:
:20:NYCBCNSH1
:23B:CRED
:32A:180608USD80020,12
:33B:USD80070,12
:36:5,11
:50K:/110000000
FOSHAN HUAXI IRON PRINTED CAN CO.,L
TD
HEJIAO INDUSTRY AREA NANZHUANG CHAN
CHENG FOSHAN CHINA
:52A:NYCBCNSH2
:53D:STRIX LIMITED
:54A:WYCBCNSH
:55D:HU LU WA
:56A:/8655221555
MdlBnkBIC
:57A:/6659823266333
AcctBnkBIC
:59:/22000000
STRIX LIMITED
FORREST HOUSE RONALDSWAY BALLASALLA
ISLE OF MAN UK
:70:RmtInfo
:71A:OUR
:71G:USD50,
:72:PstcrptDscInfo
-}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment