Commit bdfecb7c by fukai

提交更改

parent 7b2d8e63
......@@ -21,8 +21,11 @@ public class App
{
public static void main( String[] args ) throws IOException
{
TagFormat.WalkTagCell("61", "6!n[4!n]2a[1!a]15d1!a3!c16x['//'16x]['CRLF'34x]");
// System.out.println( TagFormat.TagMap.get("71F").toAnalyzeReg() );
// generMTFormat();
// TagFormat.WalkTagCell("33G", "<CUR><NUMBER>15[5!c]");
String reg = TagFormat.TagMap.get("79").toAnalyzeReg();
System.out.println(reg);
System.out.println( "XS:D:\r\n:\r\nSD:\r\nSDSD".matches(reg) );
// TagLine t59 = TagFormat.TagMap.get("79");
// t59.setValue("14314321\n423424234\nasdgfasdgfasf\nafdagfadsf\r\nasdfasdfsaf");
// System.out.println(t59);
......@@ -42,6 +45,10 @@ public class App
// SWFMessage swf = MessageFormat.getSWFMessage("940");
// System.out.println(swf.toFormatJSON());
}
public static void generMTJS()
{
}
public static void generMTFormat() throws IOException
{
File path = new File("/Volumes/FUKAI/MT/bak");
......@@ -54,7 +61,11 @@ public class App
{
File item = new File(path,"MT"+entry.getKey()+".js");
FileOutputStream fos = new FileOutputStream(item);
fos.write(entry.getValue().toFormatJSON().getBytes());
SWFMessage swf = entry.getValue();
fos.write("const Tags = ".getBytes());
fos.write(swf.toFormatJSON().getBytes());
fos.write(("\r\nconst Title=\""+swf.getName()+"\"").getBytes());
fos.write("\r\n\r\nexport default { Tags,Title}".getBytes());
fos.close();
if(entry.getKey().matches("n\\d{2}"))
sb.append("\tif(/mt"+entry.getKey().replace("n", "\\d")+"/.test(mty))\r\n");
......
......@@ -26,6 +26,16 @@ public class TagFormat {
e.printStackTrace();
}
}
public static boolean validateTagValue(String tag,String value)
{
if(value == null || tag == null)
return false;
TagLine tl = TagMap.get(tag);
if(tl == null)
return false;
String reg = tl.getAnalyzeReg();
return value.matches(reg);
}
public static TagLine getTagLine(String tag)
{
TagLine tl = TagMap.get(tag);
......@@ -59,7 +69,7 @@ public class TagFormat {
//函数表示长度
if(len.length() > 0)
cell.length = Integer.parseInt(len.toString());
else
//else
cell = null ; //清理
len.delete(0, len.length());
}
......
......@@ -69,7 +69,7 @@ public class MessageAnalyzer {
{
if(mt.startsWith(":"))
mt = "\r\n"+mt;
String[] tags = mt.split("[\\r\\n]{1,2}:");
String[] tags = mt.split("[\\r\\n]{1,2}:(?=\\d{2}[A-Z]?:)");
List<String[]> list = new ArrayList<String[]>();
for (String tv : tags)
{
......@@ -88,19 +88,23 @@ public class MessageAnalyzer {
if (list.size() > 0)
{
String[] lstOne = list.get(list.size() - 1);
int i = lstOne[1].lastIndexOf("\r\n");
String lstStr = lstOne[1].trim();
int i = lstStr.lastIndexOf("\r\n");
if (i < 0)
{
i = lstOne[1].lastIndexOf("\r");
i = lstStr.lastIndexOf("\r");
}
if (i < 0)
{
i = lstOne[1].lastIndexOf("\n");
i = lstStr.lastIndexOf("\n");
}
if (i > -1)
{
lstOne[1] = lstOne[1].substring(0, i);
list.set(list.size() - 1, lstOne);
//清除末尾横线
String lstLine = lstStr.substring( i).trim();
if("-".equals(lstLine))
lstOne[1] = lstStr.substring(0, i);
}
}
return list;
......@@ -267,6 +271,8 @@ public class MessageAnalyzer {
List<String[]> kv = msgTxtAnly(hd4);
for (String[] strArr : kv)
{
if(strArr[1].trim().length()==0)
continue;
if (strArr[0].endsWith("20"))// 业务编号
{
if (!infMap.containsKey("ref")) // 如果没有填入20栏,则将20栏填入,已填入则不进行覆盖。为nXX系列报文附带原报的情况
......@@ -399,7 +405,7 @@ public class MessageAnalyzer {
infMap.put("comref", strArr[1]);
}
}
if (strArr[0].endsWith("33B"))
if (strArr[0].endsWith("33B") && strArr[1].length()>0)
{
String cur = strArr[1].substring(0, 3);
String amt = strArr[1].substring(3);
......@@ -453,6 +459,9 @@ public class MessageAnalyzer {
Map<Integer,String> headers = anlyMsgHead(msg);
return getSwfMsgInfoViaMsg(headers);
}
/***
* 解析TD的格式报文
* @param msg
......@@ -469,9 +478,27 @@ public class MessageAnalyzer {
bscInfo.put("sndbic", m.group(3));
bscInfo.put("rcvbic", m.group(2));
bscInfo.put("prt", m.group(4));
int idx = msg.indexOf(":EOH:", m.end());
String tdmsgHead= msg.substring(0,idx);
int begIndex = m.end(4);
reg = ":111:(\\d{3})(?=\\r|\\n)";
String restStr = tdmsgHead.substring(begIndex);
Matcher m2 = Pattern.compile(reg).matcher(restStr);
if(m2.find())
{
bscInfo.put("t111", m2.group(1).trim());
}
reg = ":121:([\\s\\S]+)(?=\\r|\\n)";
m2 = Pattern.compile(reg).matcher(restStr);
if(m2.find())
{
bscInfo.put("t121", m2.group(1).trim());
}
bscInfo.put("tdmsgHead", tdmsgHead);//存头,方便前端组报
//取111,121
if(tdmsgHead.indexOf(":119:COV")> -1)
{
bscInfo.put("mty", m.group(1)+"COV");
......@@ -753,11 +780,14 @@ public class MessageAnalyzer {
// SWFMessage swf = MessageFormat.getSWFMessage("202COV");
// System.out.println(swf.toFormatJSON());
// MessageFormat.loadSWFMessage();
String path = "/Volumes/FUKAI/00026202.TXT";
String path = "/Volumes/FUKAI/00034868.txt";
String msg = readFull(path);
SWFMessage swf =loadSwiftMessage(msg);
System.out.print(swf.toJSON());
// String value =((TagLine)swf.getFields().get(2)).getValue();
// System.out.println(value);
System.out.println(swf.toJSON());
//System.out.println(value.matches(TagFormat.TagMap.get("79").toAnalyzeReg()));
}
}
......@@ -75,6 +75,10 @@ public class SWFMessage extends AbstractMessageArea {
rs.put("mty", this.mtType);
rs.put("snd_bic", bscInfo.get("sndbic"));
rs.put("rcv_bic", bscInfo.get("rcvbic"));
if(bscInfo.containsKey("t111"))
rs.put("t111", bscInfo.get("t111"));
if(bscInfo.containsKey("t121"))
rs.put("t121", bscInfo.get("t121"));
rs.put("tdheaders", bscInfo.get("tdmsgHead"));
rs.put("headers", headers);
rs.put("swift_message", toFormatJSON());
......
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