Commit f9e08bdc by WeiCong

完成swift报文的组报功能

parent 599cf024
package com.brilliace.swifteditor.tag; package com.brilliace.swifteditor.tag;
public class TagCell { public class TagCell {
public final static String CONST = "CONST"; public final static String CONST = "CONST";
public final static String FUNC = "FUNC"; public final static String FUNC = "FUNC";
public boolean fixed; public boolean fixed;
public int length; public int length;
public int minLen; public int minLen;
public String type; public String type;
public int cnt; public int cnt;
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) {
String cnt = "S" + this.cnt;
public String toReg(boolean useRegName) if (CONST.equals(type)) {
{ if ("CRLF".equals(content))
String cnt = "S"+this.cnt; return "[\\r\\n]{1,2}";
if(CONST.equals(type)) return content;
{ } else if (FUNC.equals(type)) {
if("CRLF".equals(content)) if ("AMOUNT".equals(content)) {
return "[\\r\\n]{1,2}"; if (useRegName)
return content; return "(?<" + cnt + ">[\\d,.]{1," + this.length + "})";
} else
else if(FUNC.equals(type)) return "[\\d,.]{1," + this.length + "}";
{ } else if ("NUMBER".equals(content)) {
if("AMOUNT".equals(content)) if (useRegName)
{ return "(?<" + cnt + ">[\\d,]{1," + this.length + "})";
if(useRegName) else
return "(?<"+cnt+">[\\d,]{1,"+this.length+"})"; return "[\\d,]{1," + this.length + "}";
else } else if ("HHMM".equals(content)) //hhmm
return "[\\d,]{1,"+this.length+"}"; {
} if (useRegName)
else if("NUMBER".equals(content)) return "(?<" + cnt + ">\\d{4})";
{ else
if(useRegName) return "\\d{4}";
return "(?<"+cnt+">[\\d,]{1,"+this.length+"})"; } else if ("TIME2".equals(content)) {
else if (useRegName)
return "[\\d,]{1,"+this.length+"}"; return "(?<" + cnt + ">\\d{6})";
} else
else if("HHMM".equals(content)) //hhmm return "\\d{6}";
{ } else if ("TIME3".equals(content)) {
if(useRegName) if (useRegName)
return "(?<"+cnt+">\\d{4})"; return "(?<" + cnt + ">\\d{2}\\d{2}?)";
else else
return "\\d{4}"; return "\\d{2}\\d{2}?";
} } else if ("OFFSET".equals(content))//hhmm
else if("TIME2".equals(content)) {
{ if (useRegName)
if(useRegName) return "(?<" + cnt + ">\\d{4})";
return "(?<"+cnt+">\\d{6})"; else
else return "\\d{4}";
return "\\d{6}"; } else if ("SIGN".equals(content)) // +/-
} {
else if("TIME3".equals(content)) if (useRegName)
{ return "(?<" + cnt + ">\\+|\\-)";
if(useRegName) else
return "(?<"+cnt+">\\d{2}\\d{2}?)"; return "\\+|\\-";
else } else if ("DATE1".equals(content)) //yyMMdd
return "\\d{2}\\d{2}?"; {
} if (useRegName)
else if("OFFSET".equals(content))//hhmm return "(?<" + cnt + ">\\d{4})";
{ else
if(useRegName) return "\\d{4}";
return "(?<"+cnt+">\\d{4})"; } else if ("DATE2".equals(content)) //yyMMdd
else {
return "\\d{4}"; if (useRegName)
} return "(?<" + cnt + ">\\d{6})";
else if("SIGN".equals(content)) // +/- else
{ return "\\d{6}";
if(useRegName) } else if ("YEAR".equals(content)) {
return "(?<"+cnt+">\\+|\\-)"; if (useRegName)
else return "(?<" + cnt + ">\\d{4})";
return "\\+|\\-"; else
} return "\\d{4}";
else if("DATE1".equals(content)) //yyMMdd } else if ("DATE4".equals(content)) //yyyyMMdd
{ {
if(useRegName) if (useRegName)
return "(?<"+cnt+">\\d{4})"; return "(?<" + cnt + ">\\d{8})";
else else
return "\\d{4}"; return "\\d{8}";
} } else if ("CUR".equals(content)) //yyyyMMdd
else if("DATE2".equals(content)) //yyMMdd {
{ if (useRegName)
if(useRegName) return "(?<" + cnt + ">[A-Z]{3})";
return "(?<"+cnt+">\\d{6})"; else
else return "[A-Z]{3}";
return "\\d{6}"; } else if ("DC".equals(content)) //yyyyMMdd
} {
else if("YEAR".equals(content)) if (useRegName)
{ return "(?<" + cnt + ">C|D|RC|RD)";
if(useRegName) else
return "(?<"+cnt+">\\d{4})"; return "C|D|RC|RD";
else } else if ("SWIFTBIC".equals(content)) //4!a2!a2!c3!c
return "\\d{4}"; {
} if (useRegName)
else if("DATE4".equals(content)) //yyyyMMdd return "(?<" + cnt + ">[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?)";
{ else
if(useRegName) return "[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?";
return "(?<"+cnt+">\\d{8})"; } else if ("MT".equals(content)) {
else if (useRegName)
return "\\d{8}"; return "(?<" + cnt + ">[1-9]\\d{2})";
} else
else if("CUR".equals(content)) //yyyyMMdd return "[1-9]\\d{2}";
{ } else if ("SB-LC".equals(content)) {
if(useRegName) if (useRegName)
return "(?<"+cnt+">[A-Z]{3})"; return "(?<" + cnt + ">[A-Z]{4}[A-Z0-9]{2}\\d{4}[A-Z]{4}[A-Z0-9]{2})";
else else
return "[A-Z]{3}"; return "[A-Z]{4}[A-Z0-9]{2}\\d{4}[A-Z]{4}[A-Z0-9]{2}";
} } else if ("DM".equals(content)) {
else if("DC".equals(content)) //yyyyMMdd if (useRegName)
{ return "(?<" + cnt + ">D|M)";
if(useRegName) else
return "(?<"+cnt+">C|D|RC|RD)"; return "D|M";
else } else if ("CC".equals(content)) {
return "C|D|RC|RD"; if (useRegName)
} return "(?<" + cnt + ">[A-Z]{2})";
else if("SWIFTBIC".equals(content)) //4!a2!a2!c3!c else
{ return "[A-Z]{2}";
if(useRegName) } else {
return "(?<"+cnt+">[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?)"; System.err.println("unknow function:" + content);
else }
return "[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?"; } else {
} String type = "";
else if("MT".equals(content)) char c = this.type.charAt(0);
{ switch (c) {
if(useRegName) case 'n':
return "(?<"+cnt+">[1-9]\\d{2})"; type = "\\d";
else break;
return "[1-9]\\d{2}"; case 'a':
} type = "[A-Z]";
else if("SB-LC".equals(content)) break;
{ case 'd':
if(useRegName) type = "[\\d,.]";
return "(?<"+cnt+">[A-Z]{4}[A-Z0-9]{2}\\d{4}[A-Z]{4}[A-Z0-9]{2})"; break;
else case 'x':
return "[A-Z]{4}[A-Z0-9]{2}\\d{4}[A-Z]{4}[A-Z0-9]{2}"; type = "[\\w/\\-\\?:\\(\\)\\.,'+\\{\\} ]";
} break;
else if("DM".equals(content)) case 'y':
{ type = "[0-9A-Z\\.,\\-\\(\\)/='\\+:\\?\\!\"%&\\*\\<\\>;\\s]";
if(useRegName) break;
return "(?<"+cnt+">D|M)"; case 'z':
else type = "[\\w\\.,\\-\\(\\)/='\\+:\\?!\"%&\\*\\<\\>;\\{\\s@#]";
return "D|M"; break;
} case 'c':
else if("CC".equals(content)) type = "[A-Z0-9]";
{ break;
if(useRegName) case 'h':
return "(?<"+cnt+">[A-Z]{2})"; type = "[A-F0-9]";
else break;
return "[A-Z]{2}"; case 'e':
} type = "\\s";
else{ break;
System.err.println("unknow function:"+content); case 'A':
} type = "[A-Za-z]";
} break;
else case 'B':
{ type = "[A-Za-z0-9]";
String type = ""; break;
char c = this.type.charAt(0); default:
switch(c) System.err.println("unknow type:" + type);
{ }
case 'n': type = "\\d";break; //String length = "";
case 'a': type = "[A-Z]";break; String nolines = "";
case 'd': type = "[\\d,]";break; if (fixed || minLen == length) {
case 'x': type = "[\\w/\\-\\?:\\(\\)\\.,'+\\{\\} ]";break; nolines = type + "{" + length + "}";
case 'y': type = "[0-9A-Z\\.,\\-\\(\\)/='\\+:\\?\\!\"%&\\*\\<\\>;\\s]";break; } else
case 'z': type = "[\\w\\.,\\-\\(\\)/='\\+:\\?!\"%&\\*\\<\\>;\\{\\s@#]";break; nolines = type + "{" + minLen + "," + length + "}";
case 'c': type = "[A-Z0-9]";break; if (line > 1) {
case 'h': type = "[A-F0-9]";break; if (useRegName)
case 'e': type = "\\s";break; nolines = nolines + "([\\r\\n]{1,2}" + nolines + "){0," + (line - 1) + "}";
case 'A': type = "[A-Za-z]";break; else //校验所用的,只转换单行
case 'B': type = "[A-Za-z0-9]";break; {
default:System.err.println("unknow type:"+type); if (fixed || minLen == length) {
} nolines = type + "{" + length + "}";
//String length = ""; } else
String nolines = ""; nolines = type + "{" + 0 + "," + length + "}";
if(fixed || minLen==length) }
{
nolines = type+"{"+length+"}"; }
}else if (useRegName)
nolines = type+"{"+minLen+","+length+"}"; return "(?<" + cnt + ">" + nolines + ")";
if(line > 1) else
{ return nolines;
if(useRegName) }
nolines = nolines+"([\\r\\n]{1,2}"+nolines +"){0,"+(line-1)+"}"; return null;
else //校验所用的,只转换单行 }
{
if(fixed || minLen==length)
{
nolines = type+"{"+length+"}";
}else
nolines = type+"{"+0+","+length+"}";
}
}
if(useRegName)
return "(?<"+cnt+">"+nolines+")";
else
return nolines;
}
return null;
}
} }
...@@ -5,271 +5,324 @@ import com.brilliace.swifteditor.tag.message.MessageArea; ...@@ -5,271 +5,324 @@ import com.brilliace.swifteditor.tag.message.MessageArea;
import java.util.*; import java.util.*;
public class TagLine implements MessageArea { public class TagLine implements MessageArea {
public List<TagCell> cellList = new ArrayList<TagCell>(); private final int type = TAG;
public List<int[]> options = new ArrayList<int[]>(); public List<TagCell> cellList = new ArrayList<TagCell>();
private String pattern; public List<int[]> options = new ArrayList<int[]>();
private String value; public MessageArea parent;
private String tagName; public boolean onlyOne;
private String status; String analyzeReg = null;
public MessageArea parent; private String pattern;
public boolean onlyOne; private String value;
private String tagName;
public String getStatus() { private String status;
return status; private int maxCnt = 0;
} private int tno = 0;
public void setStatus(String status) { private String desp = "";
this.status = status; private List<String> suffix = new ArrayList<String>();
}
private int maxCnt = 0; public String getStatus() {
private int tno = 0; return status;
private String desp = ""; }
private final int type = TAG;
private List<String> suffix = new ArrayList<String>(); public void setStatus(String status) {
public void add(TagCell cell) { this.status = status;
cellList.add(cell); }
}
public void addOptions(int[] points) public void add(TagCell cell) {
{ cellList.add(cell);
options.add(points); }
}
public void fillOption(int index,int point) public void addOptions(int[] points) {
{ options.add(points);
if(options.size() ==0) }
{
System.err.println("error pattern:"+this.getName()+"----"+this.getPattern()); public void fillOption(int index, int point) {
return ; if (options.size() == 0) {
} System.err.println("error pattern:" + this.getName() + "----" + this.getPattern());
options.get(index)[1] = point; return;
} }
public void fillLastOption(int point) options.get(index)[1] = point;
{ }
if(options.size() ==0)
{ public void fillLastOption(int point) {
System.err.println("error pattern:"+this.getName()+"----"+this.getPattern()); if (options.size() == 0) {
return ; System.err.println("error pattern:" + this.getName() + "----" + this.getPattern());
} return;
options.get(options.size() -1)[1] = point; }
} options.get(options.size() - 1)[1] = point;
public void setPattern(String pattern) { }
this.pattern = pattern;
} public String getPattern() {
public String getPattern() return pattern;
{ }
return pattern;
} public void setPattern(String pattern) {
public void setValue(String value) this.pattern = pattern;
{ }
if(value == null)
{ public String getSourceValue() {
this.value = null; return this.value;
return ; }
}
if(this.value!=null && this.value.equals(value)) /***
return; * 返回组装后的swift域值
this.value = value; * @return
this.fillCellValue(); */
} public String getValue() {
public String getSourceValue() StringBuilder sb = new StringBuilder();
{ this.toSwfMessage(sb);
return this.value; String val = sb.toString();
} return val;
/*** }
* 返回组装后的值
* @return public void setValue(String value) {
*/ if (value == null) {
public String getValue() this.value = null;
{ return;
StringBuilder sb = new StringBuilder(); }
this.toSwfMessage(sb); if (this.value != null && this.value.equals(value))
return sb.toString(); return;
} this.value = value;
public String getCellValue(int position) this.fillCellValue();
{ }
for(TagCell cell : this.cellList)
{ /***
if(cell.cnt == position) * 返回组装后人类查看的域值
return cell.value; * @return
} */
return null; public String getValueForHuman() {
} StringBuilder sb = new StringBuilder();
/*** this.toHumanMessage(sb);
* 将栏位值填充到指定的栏位中去 String val = sb.toString();
*/ return val;
private void fillCellValue() }
{
Map<Integer,String> subValues = TagAnalyzer.analyze(this, value); public String getCellValue(int position) {
if(subValues == null) for (TagCell cell : this.cellList) {
return ; if (cell.cnt == position)
for(Map.Entry<Integer, String> entry : subValues.entrySet()) return cell.value;
{ }
int cnt = entry.getKey(); return null;
for(TagCell cell : cellList) }
{
if(cell.cnt == cnt) /***
{ * 将栏位值填充到指定的栏位中去
cell.setValue( entry.getValue()); */
break; private void fillCellValue() {
} Map<Integer, String> subValues = TagAnalyzer.analyze(this, value);
} if (subValues == null)
} return;
} for (Map.Entry<Integer, String> entry : subValues.entrySet()) {
public TagLine clone() int cnt = entry.getKey();
{ for (TagCell cell : cellList) {
TagLine cp = new TagLine(); if (cell.cnt == cnt) {
for(TagCell cell: cellList) cell.setValue(entry.getValue());
{ break;
cp.add(cell.clone()); }
} }
for(int[] option : options) }
{ }
int[] cpopt = Arrays.copyOf(option, 2);
cp.addOptions(cpopt); public TagLine clone() {
} TagLine cp = new TagLine();
cp.setValue(value); for (TagCell cell : cellList) {
cp.setPattern(pattern); cp.add(cell.clone());
cp.setDesp(desp); }
cp.setMaxCnt(maxCnt); for (int[] option : options) {
cp.setSuffix(this.suffix); int[] cpopt = Arrays.copyOf(option, 2);
cp.setTno(tno); cp.addOptions(cpopt);
cp.setName(this.getName()); }
cp.setStatus(this.getStatus()); cp.setValue(value);
cp.analyzeReg = this.analyzeReg; cp.setPattern(pattern);
return cp; cp.setDesp(desp);
} cp.setMaxCnt(maxCnt);
public void toSwfMessage(StringBuilder sb) { cp.setSuffix(this.suffix);
for(TagCell cell : this.cellList) cp.setTno(tno);
if("CONST".equals(cell.type)) cp.setName(this.getName());
sb.append(cell.content); cp.setStatus(this.getStatus());
else if(cell.value != null) cp.analyzeReg = this.analyzeReg;
sb.append(cell.value); return cp;
} }
public String getName() {
return tagName; public void toSwfMessage(StringBuilder sb) {
} boolean isEmpty = true;
public void addSubArea(MessageArea sub) { TagCell lastCell = null;
for (TagCell cell : this.cellList) {
} if ("CONST".equals(cell.type)) {
public boolean isEnd() lastCell = cell;
{ if ("CRLF".equals(cell.content)) {
return true; sb.append("\r\n");
} } else {
public int getType() { sb.append(cell.content);
return type; }
} } else if (cell.value != null) {
public void setName(String name) { isEmpty = false;
this.tagName = name; if ("d".equals(cell.type) || ("AMOUNT".equals(cell.content) && "FUNC".equals(cell.type))) {
} if (cell.value.indexOf(".") > 0) {
/*** sb.append(cell.value.replace(".", ","));
* 返回解析字符串 } else {
* @return sb.append(cell.value + ",");
*/ }
public String toAnalyzeReg() } else {
{ if (lastCell != null && cell.value.startsWith(lastCell.content)) {
StringBuilder sb = new StringBuilder(); sb.append(cell.value.substring(lastCell.content.length()));
int cnt = 0; } else {
boolean hasOpen = false; sb.append(cell.value);
for(TagCell cell : cellList) }
{ }
for(int[] opt : options) lastCell = null;
{ }
if(cnt == opt[0]) }
{ if (isEmpty) {
sb.append('('); sb.delete(0, sb.length());
hasOpen=true; }
}
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() {
return tagName;
}
public void setName(String name) {
this.tagName = name;
}
public void addSubArea(MessageArea sub) {
}
public boolean isEnd() {
return true;
}
public int getType() {
return type;
}
/***
* 返回解析字符串
* @return
*/
public String toAnalyzeReg() {
StringBuilder sb = new StringBuilder();
int cnt = 0;
boolean hasOpen = false;
for (TagCell cell : cellList) {
for (int[] opt : options) {
if (cnt == opt[0]) {
sb.append('(');
hasOpen = true;
// break; // break;
} } else if (cnt == opt[1]) {
else if(cnt == opt[1]) sb.append(")?");
{ hasOpen = false;
sb.append(")?");
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); info.put("content", cell.content);
info.put("content", cell.content); info.put("option", "M");
info.put("option", "M"); info.put("fixed", cell.fixed);
info.put("fixed", cell.fixed); 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]) {
{ info.put("option", "O");
if(cnt >= opt[0] && cnt<opt[1]) }
{ }
info.put("option", "O"); }
} return set;
} }
}
return set; public String getAnalyzeReg() {
} if (analyzeReg == null)
analyzeReg = this.toAnalyzeReg();
String analyzeReg = null; return analyzeReg;
public void setAnalyzeReg(String analyzeReg){ }
this.analyzeReg=analyzeReg;
} public void setAnalyzeReg(String analyzeReg) {
public String getAnalyzeReg() this.analyzeReg = analyzeReg;
{ }
if(analyzeReg==null)
analyzeReg = this.toAnalyzeReg(); public int getMaxCnt() {
return analyzeReg; return maxCnt;
} }
public int getMaxCnt() {
return maxCnt; public void setMaxCnt(int maxCnt) {
} this.maxCnt = maxCnt;
public void setMaxCnt(int 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() {
return desp; public String getDesp() {
} return desp;
public void setDesp(String desp) { }
this.desp = desp;
} public void setDesp(String desp) {
this.desp = desp;
public void setSuffix(List<String> tagSuffix) { }
this.suffix.clear();
this.suffix.addAll(tagSuffix); public List<String> getSuffix() {
} return this.suffix;
public List<String> getSuffix() }
{
return this.suffix; public void setSuffix(List<String> tagSuffix) {
} this.suffix.clear();
public Map<String,String> getIndexMap() { this.suffix.addAll(tagSuffix);
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)
return indexMap; indexMap.put("s" + cell.cnt, cell.value);
} }
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