Commit 40143947 by gechengyang

修改缺陷

parent 5695a96a
package com.brilliace.swifteditor.tag.message;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
......@@ -9,68 +8,75 @@ import com.google.gson.Gson;
public class SWFMessage extends AbstractMessageArea {
private String mtType;
private Map<Integer,String> headers;
private Map<Integer, String> headers;
public Map<Integer, String> getHeaders() {
return headers;
}
public void setHeaders(Map<Integer, String> headers) {
Map<Integer,String> clone = new HashMap<Integer,String>();
Map<Integer, String> clone = new HashMap<Integer, String>();
clone.putAll(headers);
clone.remove(4);
this.headers = clone;
}
public Map<String, String> getBscInfo() {
return bscInfo;
}
public void setBscInfo(Map<String, String> bscInfo) {
this.bscInfo = bscInfo;
}
private Map<String,String> bscInfo;
private Map<String, String> bscInfo;
public String getMtType() {
return mtType;
}
public void setMtType(String mtType) {
this.mtType = mtType;
}
protected SWFMessage()
{
protected SWFMessage() {
}
public static SWFMessage loadMTTemp(String mt)
{
public static SWFMessage loadMTTemp(String mt) {
return null;
}
/***
*
* @param sb 缓存4文首域名
* @param sb
* 缓存4文首域名
*/
public void toSwfMessage(StringBuilder sb)
{
public void toSwfMessage(StringBuilder sb) {
sb.append("{4:\r\n");
for(MessageArea sub : this.getFields())
for (MessageArea sub : this.getFields())
sub.toSwfMessage(sb);
sb.append("\r\n}");
}
public String toSwfMessage()
{
public String toSwfMessage() {
StringBuilder sb = new StringBuilder();
toSwfMessage(sb);
return sb.toString();
}
public SWFMessage clone()
{
public SWFMessage clone() {
SWFMessage msg = new SWFMessage();
msg.mtType = this.mtType;
for(MessageArea field : this.getFields())
{
for (MessageArea field : this.getFields()) {
msg.addSubArea(field.clone());
}
msg.setName(this.getName());
msg.setAnlyReg(this.getAnlyReg());
return msg;
}
public String toJSON()
{
Map<String,Object> rs = new HashMap<String,Object>();
public String toJSON() {
Map<String, Object> rs = new HashMap<String, Object>();
rs.put("title", this.getName());
rs.put("mty", this.mtType);
rs.put("snd_bic", bscInfo.get("sndbic"));
......@@ -79,93 +85,86 @@ public class SWFMessage extends AbstractMessageArea {
rs.put("headers", headers);
rs.put("swift_message", toFormatJSON());
return new Gson().toJson(rs);
// return String.format("{\r\ntitle:\"%s\",\r\nmty:'%s',\r\nrcv_bic:'%s',\r\ntdheader:'%s',\r\nheaders:%s,\r\nswift_message:%s\r\n}",
// this.getName(),
// this.mtType,
// this.bscInfo.get("rcvbic"),
// this.bscInfo.get("tdmsgHead")==null?null:URLEncoder.encode(this.bscInfo.get("tdmsgHead")),
// new Gson().toJson( headers),
// this.toFormatJSON()
// );
}
public String toFormatJSON()
{
// return
// String.format("{\r\ntitle:\"%s\",\r\nmty:'%s',\r\nrcv_bic:'%s',\r\ntdheader:'%s',\r\nheaders:%s,\r\nswift_message:%s\r\n}",
// this.getName(),
// this.mtType,
// this.bscInfo.get("rcvbic"),
// this.bscInfo.get("tdmsgHead")==null?null:URLEncoder.encode(this.bscInfo.get("tdmsgHead")),
// new Gson().toJson( headers),
// this.toFormatJSON()
// );
}
public String toFormatJSON() {
StringBuilder sb = new StringBuilder();
// sb.append("const M='M' \r\n");
// sb.append("const O='O' \r\n");
// sb.append("const Tags=");
// sb.append("const M='M' \r\n");
// sb.append("const O='O' \r\n");
// sb.append("const Tags=");
toSubJson(this,sb);
toSubJson(this, sb);
// sb.append("\r\nconst Title=\""+this.getName()+"\"");
// sb.append("\r\n\r\nexport default { Tags,Title}");
// sb.append("\r\nconst Title=\""+this.getName()+"\"");
// sb.append("\r\n\r\nexport default { Tags,Title}");
return sb.toString();
}
private static void toSubJson(AbstractMessageArea ma,StringBuilder sb)
{
private static void toSubJson(AbstractMessageArea ma, StringBuilder sb) {
sb.append("[\r\n");
for(MessageArea sma :ma.getFields())
{
if(sma.getType() == TAG)
{
for (MessageArea sma : ma.getFields()) {
if (sma.getType() == TAG) {
TagLine tag = (TagLine) sma;
sb.append(String.format("\t{\"tag\":\"%s\",\"status\":\"%s\",\"tno\":%d,\"letter\":%s,\"label\":\"%s\",\"tagValue\":%s},\r\n",
tag.getSuffix().size() > 0 ?tag.getSuffix().get(0) :tag.getName(),
tag.getStatus(),
tag.getTno(),
new Gson().toJson(tag.getSuffix()),
tag.getDesp(),
new Gson().toJson(new Object[]{tag.getIndexMap(),tag.getSourceValue()})
)
);
}
else if(sma.getType() == CYCLIST)
{
if (tag.getName().startsWith("50")) {
System.out.println(111);
}
sb.append(String.format("\t{\"tag\":\"%s\",\"status\":\"%s\",\"tno\":%d,\"letter\":%s,\"label\":\"%s\",\"tagValue\":%s},\r\n", tag
.getSuffix().size() > 0 && tag.getName().endsWith("a") ? tag.getSuffix().get(0) : tag.getName(), tag.getStatus(),
tag.getTno(), new Gson().toJson(tag.getSuffix()), tag.getDesp(),
new Gson().toJson(new Object[] { tag.getIndexMap(), tag.getSourceValue() })));
} else if (sma.getType() == CYCLIST) {
StringBuilder buff = new StringBuilder();
// int first = 9999;
for(MessageArea ssma : ((AbstractMessageArea)sma).getFields() )
{
AbstractMessageArea temp = (AbstractMessageArea)ssma ;
toSubJson(temp,buff);
// int first = 9999;
for (MessageArea ssma : ((AbstractMessageArea) sma).getFields()) {
AbstractMessageArea temp = (AbstractMessageArea) ssma;
toSubJson(temp, buff);
buff.append(',');
}
sb.append(String.format("\t{\"cyclist\":\"%s\",\"cycs\":[",sma.getName()));
//String temp = buff.toString().trim();
sb.append(buff.subSequence(0, buff.length()-1));
sb.append(String.format("\t{\"cyclist\":\"%s\",\"cycs\":[", sma.getName()));
// String temp = buff.toString().trim();
sb.append(buff.subSequence(0, buff.length() - 1));
sb.append("],\r\n\t\"pattern\":");
buff = new StringBuilder();
toSubJson((AbstractMessageArea)((AbstractMessageArea)sma).getPattern(),buff);
toSubJson((AbstractMessageArea) ((AbstractMessageArea) sma).getPattern(), buff);
sb.append(buff);
sb.append("\t},\r\n");
}
else if(sma.getType() == SEQLIST)
{
} else if (sma.getType() == SEQLIST) {
StringBuilder buff = new StringBuilder();
// int first = 9999;
for(MessageArea ssma : ((AbstractMessageArea)sma).getFields() )
{
AbstractMessageArea temp = (AbstractMessageArea)ssma ;
toSubJson(temp,buff);
// int first = 9999;
for (MessageArea ssma : ((AbstractMessageArea) sma).getFields()) {
AbstractMessageArea temp = (AbstractMessageArea) ssma;
toSubJson(temp, buff);
buff.append(',');
}
SEQList seqlst = (SEQList)sma;
sb.append(String.format("\t{\"seqlist\":\"%s\",\"cyccnt\":%d,\"status\":\"%s\",\"seqs\":[",sma.getName(),seqlst.getCyc(),seqlst.getOm()));
//String temp = buff.toString().trim();
sb.append(buff.subSequence(0, buff.length()-1));
SEQList seqlst = (SEQList) sma;
sb.append(String.format("\t{\"seqlist\":\"%s\",\"cyccnt\":%d,\"status\":\"%s\",\"seqs\":[", sma.getName(), seqlst.getCyc(),
seqlst.getOm()));
// String temp = buff.toString().trim();
sb.append(buff.subSequence(0, buff.length() - 1));
sb.append("],\r\n\t\"pattern\":");
buff = new StringBuilder();
toSubJson((AbstractMessageArea)((AbstractMessageArea)sma).getPattern(),buff);
toSubJson((AbstractMessageArea) ((AbstractMessageArea) sma).getPattern(), buff);
sb.append(buff);
sb.append(String.format(",\r\n\t\"desp\":\"%s\"",seqlst.getDesp() ));
sb.append(String.format(",\r\n\t\"desp\":\"%s\"", seqlst.getDesp()));
sb.append("\t},\r\n");
}
}
if(sb.length() > 3 && sb.charAt(sb.length()-3)==',')
sb.setCharAt(sb.length()-3, ' ');
if (sb.length() > 3 && sb.charAt(sb.length() - 3) == ',')
sb.setCharAt(sb.length() - 3, ' ');
sb.append("]");
}
@Override
public int getType() {
return MESSAGE;
......
package com.brilliance.black.util;
import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import com.brilliace.swifteditor.tag.message.MessageAnalyzer;
import com.brilliace.swifteditor.tag.message.SWFMessage;
import com.google.gson.Gson;
import com.google.gson.internal.LinkedTreeMap;
public class BlackListUtil {
private static List<SwiftTagInfo> swiftTagBlacks = new ArrayList<SwiftTagInfo>();
private static List<SwiftTagInfo> getSwiftTagBlacks(String blackTagPath) {
try {
if (swiftTagBlacks.size() == 0) {
List<String> fileList = IOUtils.readLines(new FileInputStream(new File(blackTagPath)), "utf-8");
for (String str : fileList) {
if (str == null || str.trim().equals(""))
continue;
String arr[] = str.split("\t");
SwiftTagInfo swiftTagBlack = new SwiftTagInfo();
swiftTagBlack.setMty(arr[0]);
swiftTagBlack.setTag(arr[1]);
swiftTagBlack.setDataPosition(arr[2]);
swiftTagBlack.setShootType(arr[3]);
swiftTagBlacks.add(swiftTagBlack);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return swiftTagBlacks;
}
private static List<SwiftTagInfo> getSwiftTagBlacksByMty(String blackTagPath, String mty) {
getSwiftTagBlacks(blackTagPath);
List<SwiftTagInfo> lswiftTagBlacks = new ArrayList<SwiftTagInfo>();
for (SwiftTagInfo swiftTagBlack : swiftTagBlacks) {
if (swiftTagBlack.getMty().equals(mty)) {
lswiftTagBlacks.add(swiftTagBlack);
}
}
return lswiftTagBlacks;
}
@SuppressWarnings("rawtypes")
public static List<Map<String, Object>> detailsOfTags(String msg, String blackTagPath) {
List<Map<String, Object>> ret = new ArrayList<Map<String, Object>>();
SWFMessage swf = MessageAnalyzer.loadSwiftMessage(msg);
System.out.println("swiftType=" + swf.getMtType());
List<SwiftTagInfo> swiftTagBlacks = getSwiftTagBlacksByMty(blackTagPath, swf.getMtType());
@SuppressWarnings("rawtypes")
List<LinkedTreeMap> list = new Gson().fromJson(swf.toFormatJSON(), List.class);
System.out.println(swf.toJSON());
for (SwiftTagInfo swiftTagBlack : swiftTagBlacks) {
String tag = swiftTagBlack.getTag();
for (LinkedTreeMap map : list) {
if (map.get("tag") != null && map.get("tag").equals(tag)) {
Map<String, Object> retMap = new HashMap<String, Object>();
retMap.put("tag", tag);
retMap.put("label", map.get("label"));
if (map.get("tagValue") != null) {
List tagValueList = (List) map.get("tagValue");
for (Object obj : tagValueList) {
if (obj instanceof Map) {
retMap.put("tagValue", ((Map) obj).get(swiftTagBlack.getDataPosition()));
retMap.put("shootType", swiftTagBlack.getShootType());
}
}
}
ret.add(retMap);
}
}
}
return ret;
}
public static void main(String[] args) throws Exception {
String swiftMsg = IOUtils.toString(new FileInputStream(new File("d:/black/103.sf2")), "utf-8");
List<Map<String, Object>> list = detailsOfTags(swiftMsg, "C:/Users/ge/Desktop/blackList.txt");
System.out.println("list=" + list);
}
}
package com.brilliance.black.util;
public class SwiftTagInfo {
private String mty;// 报文类型
private String tag;
private String dataPosition;// 数据域位置 S1 S2 S3 S4 ...
private String shootType;// 1:BIC检查 2:名称地址检查
public String getMty() {
return mty;
}
public String getTag() {
return tag;
}
public String getShootType() {
return shootType;
}
public void setMty(String mty) {
this.mty = mty;
}
public void setTag(String tag) {
this.tag = tag;
}
public void setShootType(String shootType) {
this.shootType = shootType;
}
public String getDataPosition() {
return dataPosition;
}
public void setDataPosition(String dataPosition) {
this.dataPosition = dataPosition;
}
}
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