Commit 599bbbed by chengzhuoshen

重写subFunctionInstructionForNextAgent转换函数

parent 0e1a6921
...@@ -7,6 +7,7 @@ import com.brilliance.swift.vo.MxMtReasonCodeInfo; ...@@ -7,6 +7,7 @@ import com.brilliance.swift.vo.MxMtReasonCodeInfo;
import com.brilliance.swift.vo.SwiftTranslationErrorInfo; import com.brilliance.swift.vo.SwiftTranslationErrorInfo;
import com.brilliance.swift.vo.SwiftTranslationReport; import com.brilliance.swift.vo.SwiftTranslationReport;
import com.brilliance.swift.vo.common.*; import com.brilliance.swift.vo.common.*;
import com.prowidesoftware.swift.model.SwiftMessage;
import com.prowidesoftware.swift.model.Tag; import com.prowidesoftware.swift.model.Tag;
import org.dom4j.Document; import org.dom4j.Document;
...@@ -970,7 +971,7 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate { ...@@ -970,7 +971,7 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate {
* @return * @return
*/ */
protected String mx_to_mt53A(String path) { protected String mx_to_mt53A(String path) {
String bicCode = ""; String bicCode53 = "";
int pathCount = XmlUtil.getChildrenCount(document, path, null); int pathCount = XmlUtil.getChildrenCount(document, path, null);
if (pathCount > 0) { if (pathCount > 0) {
String mtInstruction = getXmlNodeValue(null, document, path + "(0).InstrInf"); String mtInstruction = getXmlNodeValue(null, document, path + "(0).InstrInf");
...@@ -979,26 +980,42 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate { ...@@ -979,26 +980,42 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate {
String instrInf = getXmlNodeValue(null, document, path + "("+i+").InstrInf"); String instrInf = getXmlNodeValue(null, document, path + "("+i+").InstrInf");
if (StringUtil.isNotEmpty(instrInf)) { if (StringUtil.isNotEmpty(instrInf)) {
if (instrInf.length() < 35 && !instrInf.matches("/[A-Z0-9]{1,8}/.*")) { if (instrInf.length() < 35 && !instrInf.matches("/[A-Z0-9]{1,8}/.*")) {
mtInstruction += "/TempREC/" + instrInf; mtInstruction += "/TEMPREC/" + instrInf;
} else { } else {
mtInstruction += instrInf; mtInstruction += instrInf;
} }
} }
} }
String regex = "(/[A-Z0-9]{0,8}/[0-9a-zA-Z\\-\\?:\\(\\)\\.,'\\+]*)"; if (!mtInstruction.matches("/[A-Z0-9]{1,8}/.*")) {
Pattern p = Pattern.compile(regex); mtInstruction = "/TEMPREC/" + mtInstruction;
Matcher m = p.matcher(mtInstruction);
while (m.find()) {
/**
* group(0)就是指的整个串,group(1)指的是第一个括号里的东西,group(2)指的第二个括号里的东西
*/
if (m.group(1).startsWith("/FIN53/")) {
bicCode = m.group(1).substring(7);
} }
//提取 /GenericMax8c/
String mtType = context.get(SwiftMessage.class).getBlock2().getMessageType();
String[] mxInstrInfs = StringUtil.splitAndKeepSeparator(mtInstruction, "/[A-Z0-9]{1,8}/");
for (int i=0; i<mxInstrInfs.length; i++) {
String mxIns = mxInstrInfs[i];
if (mxIns.startsWith("/FIN53/")) {
String bicCode = mxIns.substring(7);
if (Mx2MtConstants.MT_TYPE_103.equals(mtType)) {
String acccount = mx_to_mtAccount(grpHdrParentElementName + ".GrpHdr.SttlmInf.SttlmAcct");
if (StringUtil.isEmpty(acccount)) {
String senderBic = (String)context.get(Mx2MtContextIdentifier.MX_SENDER_BIC, true);
String receiverBic = (String)context.get(Mx2MtContextIdentifier.MX_RECEIVER_BIC, true);
if ((StringUtil.isNotEmpty(senderBic) && senderBic.substring(0, 6).equals(bicCode.substring(0, 6)))
|| (StringUtil.isNotEmpty(receiverBic) && receiverBic.substring(0, 6).equals(bicCode.substring(0, 6)))) {
bicCode53 = bicCode;
} }
} else {
bicCode53 = bicCode;
} }
if (StringUtil.isNotEmpty(bicCode) && SwiftTransferUtil.isBIC(bicCode)) { } else {
return bicCode; bicCode53 = bicCode;
}
}
}
}
if (StringUtil.isNotEmpty(bicCode53) && SwiftTransferUtil.isBIC(bicCode53)) {
return bicCode53;
} else { } else {
return null; return null;
} }
...@@ -1409,13 +1426,11 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate { ...@@ -1409,13 +1426,11 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate {
} }
//提取 /GenericMax8c/ //提取 /GenericMax8c/
List<String> list = new ArrayList<>(); List<String> list = new ArrayList<>();
String regex = "(/[A-Z0-9]{0,8}/[0-9a-zA-Z\\-\\?:\\(\\)\\.,'\\+]*)"; String[] mxInstrInfs = StringUtil.splitAndKeepSeparator(mxInstrInf, "/[A-Z0-9]{1,8}/");
Pattern p = Pattern.compile(regex); for (int i=0; i<mxInstrInfs.length; i++) {
Matcher m = p.matcher(mxInstrInf); String mxIns = mxInstrInfs[i];
while (m.find()){ if (mxIns.startsWith("/FIN53/")) {
String mtInstrInf = m.group(1); String bicCode = mxIns.substring(7);
if (mtInstrInf.startsWith("/FIN53/")) {
String bicCode = mtInstrInf.substring(7);
boolean bicCodeFlag = false; boolean bicCodeFlag = false;
if (SwiftTransferUtil.isBIC(bicCode) if (SwiftTransferUtil.isBIC(bicCode)
&& (SettlementMethodCode.INGA.value().equals(settlementMethod) && (SettlementMethodCode.INGA.value().equals(settlementMethod)
...@@ -1433,27 +1448,47 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate { ...@@ -1433,27 +1448,47 @@ public abstract class AbstractMx2MtTagsGenerate implements Mx2MtTagsGenerate {
} }
} }
if (!bicCodeFlag) { if (!bicCodeFlag) {
list.add(mtInstrInf); list.add(mxIns);
} }
} else { } else {
list.add(mtInstrInf); list.add(mxIns);
} }
} }
String recStr = ""; String tempRecStr = "";
//找到以TEMPREC 开头的信息
for (int i=0; i<list.size(); i++) { for (int i=0; i<list.size(); i++) {
String str = list.get(i); String str = list.get(i);
if (str.startsWith(tmpRec)) { if (str.startsWith(tmpRec)) {
if (StringUtil.isEmpty(recStr)) { if (StringUtil.isEmpty(tempRecStr)) {
recStr += "/REC/" + str.substring(9); tempRecStr += "/REC/" + str.substring(9);
} else { } else {
recStr += " " + str.substring(9); tempRecStr += " " + str.substring(9);
} }
} else { }
}
//过滤掉以TEMPREC 开头的信息
for (int i=0; i<list.size(); i++) {
String str = list.get(i);
if (!str.startsWith(tmpRec)) {
mtInstrInfs.add(str); mtInstrInfs.add(str);
} }
} }
if (recStr.length() > 0) { //是否包含/REC/信息
mtInstrInfs.add(recStr); int recIndex = -1;
for (int i=0; i<mtInstrInfs.size(); i++) {
if (mtInstrInfs.get(i).startsWith("/REC/")) {
recIndex = i;
break;
}
}
if (StringUtil.isNotEmpty(tempRecStr)) {
if (recIndex > -1) {
String tmpStr = mtInstrInfs.get(recIndex);
mtInstrInfs.remove(recIndex);
mtInstrInfs.add(recIndex, tmpStr + " " + tempRecStr.substring(5));
} else {
mtInstrInfs.add(tempRecStr);
}
} }
} }
return mtInstrInfs; return mtInstrInfs;
......
...@@ -418,10 +418,37 @@ public abstract class StringUtil { ...@@ -418,10 +418,37 @@ public abstract class StringUtil {
return list; return list;
} }
public static void main(String[] args) { /**
String str = "/INS/qwerqwertrewertdfgrfrhfsedfgyhokjoknksdnkqwerqwertrewertdfgrfrhfsedfgyhokjoknksdnk"; * 分隔字符串并保留分隔符
List<String> list = outStringList(str, 35, "//"); * @param str
list.forEach(str0 -> System.out.println(str0)); * @param separator
* @return
*/
public static String[] splitAndKeepSeparator(String str, String separator) {
String[] strs = str.split(separator);
List<String> list = new ArrayList<>();
Pattern p = Pattern.compile("/[A-Z0-9]{1,8}/");
Matcher m = p.matcher(str);
while (m.find()) {
list.add(m.group());
}
//过滤掉空字符串
List<String> newList = new ArrayList<>();
for (String s : strs) {
if (StringUtil.isNotEmpty(s)) {
newList.add(s);
}
}
//split出来的LIST 和 正则提取出来的LIST size一样 则进行字符串连接
if (newList.size() == list.size()) {
String[] newStrs = new String[newList.size()];
for (int i=0; i<newList.size(); i++) {
newStrs[i] = list.get(i) + newList.get(i);
}
return newStrs;
} else {
return newList.toArray(new String[newList.size()]);
}
} }
} }
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