Commit fc76d9fb by chengzhuoshen

mt103rejt,mt202rejt转pacs002

parent 4d0c20e9
...@@ -7,6 +7,7 @@ import com.brilliance.swift.exception.SwiftException; ...@@ -7,6 +7,7 @@ import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.util.DateUtil; import com.brilliance.swift.util.DateUtil;
import com.brilliance.swift.util.StringUtil; import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.util.SwiftTransferUtil; import com.brilliance.swift.util.SwiftTransferUtil;
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.VoSettlementMethodHelper; import com.brilliance.swift.vo.VoSettlementMethodHelper;
...@@ -1893,6 +1894,121 @@ public abstract class AbstractMt2MxParseField implements Mt2MxParseField { ...@@ -1893,6 +1894,121 @@ public abstract class AbstractMt2MxParseField implements Mt2MxParseField {
cxlRsnInfMaps.put("addtlInf",addtlInfJSONArray); cxlRsnInfMaps.put("addtlInf",addtlInfJSONArray);
addtlInfJSONArray.addAll(list); addtlInfJSONArray.addAll(list);
} }
protected void mt_to_mxReject72(String mt72, Map<String, Object> maps) {
if (StringUtil.isEmpty(mt72)) {
return;
}
JSONArray stsRsnInfJsonArray = null;
if (maps.containsKey("stsRsnInf")) {
stsRsnInfJsonArray = (JSONArray)maps.get("stsRsnInf");
} else {
stsRsnInfJsonArray = new JSONArray();
}
Map<String, Object> stsRsnInfMap = new HashMap<>();
String mxReasonCodeOrProprietary = "";
String additionalInformation = "";
int maxLength = 0;
String mtReasonCode = "";
String[] mt72s = mt72.split(Mx2MtConstants.NEW_LINE);
String line2 = "";
if (mt72s.length >= 2) {
line2 = mt72s[1];
}
String regex = "/XT99/(.*)/(.*)";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(line2);
if (m.find()) {
mxReasonCodeOrProprietary = m.group(1);
additionalInformation = m.group(2);
maxLength = 35 - 6 - mxReasonCodeOrProprietary.length() - 1;
} else {
regex = "/([0-9A-Z]{2}[0-9]{2})/(.*)";
p = Pattern.compile(regex);
m = p.matcher(line2);
if (m.find()) {
mtReasonCode = m.group(1);
additionalInformation = m.group(2);
maxLength = 29;
}
}
String line6 = "";
String refreshMt72 = refreshValue(mt72, "//", 35).replace(Mx2MtConstants.NEW_LINE + "//", "");
String[] refreshMt72s = refreshMt72.split(Mx2MtConstants.NEW_LINE);
for (int i=0; i<refreshMt72s.length; i++) {
if (refreshMt72s[i].startsWith("/TEXT/")) {
line6 = refreshMt72s[i].substring(6);
break;
}
}
if (line6.length() > 0) {
if (additionalInformation.length() > 0) {
if (additionalInformation.length() < maxLength) {
additionalInformation += " " + line6;
} else {
additionalInformation += line6;
}
} else {
additionalInformation = line6;
}
}
if (additionalInformation.length() > 0) {
if (additionalInformation.length() > 210) {
buildSTErrorInfo(ERROR.T0000T, "TxInfAndSts/StsRsnInf/AddtlInf", additionalInformation);
additionalInformation = additionalInformation.substring(0, 209) + "+";
}
List<String> list = new ArrayList<>();
if (additionalInformation.length() > 105) {
String addInf1 = additionalInformation.substring(0, 105);
String addInf2 = additionalInformation.substring(105);
list.add(addInf1);
list.add(addInf2);
} else {
list.add(additionalInformation);
}
stsRsnInfMap.put("addtlInf", list);
}
Map<String, Object> rsnMaps = new HashMap<>();
if (mxReasonCodeOrProprietary.length() > 0) {
StatusReasonCode code = SwiftTransferUtil.getStatusReasonCodeByCode(mxReasonCodeOrProprietary);
if (code != null) {
rsnMaps.put("cd", mxReasonCodeOrProprietary);
} else {
rsnMaps.put("prtry", mxReasonCodeOrProprietary);
}
} else if (mtReasonCode.length() > 0) {
List<MxMtReasonCodeInfo> mxMtReasonCodeInfos = SwiftTransferUtil.getMxMtReasonCodes();
String mxReasonCode = "";
boolean isMxErrorCodePresent = false;
if (mxMtReasonCodeInfos != null && mxMtReasonCodeInfos.size() > 0) {
for (int i=0; i<mxMtReasonCodeInfos.size(); i++) {
MxMtReasonCodeInfo mxMtReasonCodeInfo = mxMtReasonCodeInfos.get(i);
if (mtReasonCode.equals(mxMtReasonCodeInfo.getMtCode())) {
isMxErrorCodePresent = mxMtReasonCodeInfo.isMxErrorCodePresent();
mxReasonCode = mxMtReasonCodeInfo.getIsoCode();
break;
}
}
}
if (isMxErrorCodePresent) {
rsnMaps.put("cd", mxReasonCode);
} else {
rsnMaps.put("prtry", mtReasonCode);
}
} else {
rsnMaps.put("cd", StatusReasonCode.NARR.value());
}
if (rsnMaps.size() > 0) {
stsRsnInfMap.put("rsn", rsnMaps);
}
if (stsRsnInfMap.size() > 0) {
stsRsnInfJsonArray.add(stsRsnInfMap);
}
if (stsRsnInfJsonArray.size() > 0) {
maps.put("stsRsnInf", stsRsnInfJsonArray);
}
}
/** /**
* MT 转 MX 转换函数结束 * MT 转 MX 转换函数结束
*/ */
......
...@@ -4,6 +4,7 @@ import com.brilliance.swift.exception.SwiftException; ...@@ -4,6 +4,7 @@ import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2mx.camt029001.Mt2MxCamt029001Creator; import com.brilliance.swift.mt2mx.camt029001.Mt2MxCamt029001Creator;
import com.brilliance.swift.mt2mx.camt054001.Mt2MxCamt054001Creator; import com.brilliance.swift.mt2mx.camt054001.Mt2MxCamt054001Creator;
import com.brilliance.swift.mt2mx.camt056001.Mt2MxCamt056001Creator; import com.brilliance.swift.mt2mx.camt056001.Mt2MxCamt056001Creator;
import com.brilliance.swift.mt2mx.pacs002001.Mt2MxPacs002001Creator;
import com.brilliance.swift.mt2mx.pacs008001.Mt2MxPacs008001Creator; import com.brilliance.swift.mt2mx.pacs008001.Mt2MxPacs008001Creator;
import com.brilliance.swift.mt2mx.pacs009001.Mt2MxPacs009001Creator; import com.brilliance.swift.mt2mx.pacs009001.Mt2MxPacs009001Creator;
import com.brilliance.swift.util.StringUtil; import com.brilliance.swift.util.StringUtil;
...@@ -48,13 +49,13 @@ public class Mt2MxCreatorManager { ...@@ -48,13 +49,13 @@ public class Mt2MxCreatorManager {
} }
public AbstractMt2MxCreator getMt2MxCreator() throws SwiftException { public AbstractMt2MxCreator getMt2MxCreator() throws SwiftException {
String messageType = abstractMT.getMessageType(); String messageType = processMessageType(abstractMT.getMessageType());
if ("103".equals(messageType)) { if ("103".equals(messageType)) {
return new Mt2MxPacs008001Creator(); return new Mt2MxPacs008001Creator();
} else if ("202".equals(messageType) || "205".equals(messageType)) { } else if ("202".equals(messageType) || "205".equals(messageType)) {
return new Mt2MxPacs009001Creator(); return new Mt2MxPacs009001Creator();
} else if ("103REJT".equals(messageType) || "202REJT".equals(messageType) || "205REJT".equals(messageType)) { } else if ("103REJT".equals(messageType) || "202REJT".equals(messageType) || "205REJT".equals(messageType)) {
return new Mt2MxPacs009001Creator(); return new Mt2MxPacs002001Creator();
} else if ("103RETN".equals(messageType) || "202RETN".equals(messageType) || "205RETN".equals(messageType)) { } else if ("103RETN".equals(messageType) || "202RETN".equals(messageType) || "205RETN".equals(messageType)) {
return new Mt2MxPacs009001Creator(); return new Mt2MxPacs009001Creator();
} else if("196".equals(messageType) || "296".equals(messageType)) { } else if("196".equals(messageType) || "296".equals(messageType)) {
......
...@@ -23,6 +23,7 @@ public class Mt2MxPacs002001Creator extends AbstractMt2MxCreator { ...@@ -23,6 +23,7 @@ public class Mt2MxPacs002001Creator extends AbstractMt2MxCreator {
jsonMaps.put("identifier", "pacs.002.001.10"); jsonMaps.put("identifier", "pacs.002.001.10");
Map<String, Object> appHdrMaps = (Map<String, Object>)jsonMaps.get("appHdr"); Map<String, Object> appHdrMaps = (Map<String, Object>)jsonMaps.get("appHdr");
appHdrMaps.put("msgDefIdr", "pacs.002.001.10"); appHdrMaps.put("msgDefIdr", "pacs.002.001.10");
appHdrMaps.put("bizSvc", "swift.cbprplus.02");
AbstractMT abstractMT = context.get(AbstractMT.class); AbstractMT abstractMT = context.get(AbstractMT.class);
//初始化转换和不需要BLOCK4的转换 //初始化转换和不需要BLOCK4的转换
...@@ -58,7 +59,7 @@ public class Mt2MxPacs002001Creator extends AbstractMt2MxCreator { ...@@ -58,7 +59,7 @@ public class Mt2MxPacs002001Creator extends AbstractMt2MxCreator {
Map<String, Object> orgnlGrpInfMaps = new HashMap<>(); Map<String, Object> orgnlGrpInfMaps = new HashMap<>();
String messageType = "MT" + abstractMT.getMessageType(); String messageType = "MT" + abstractMT.getMessageType();
if (abstractMT.getSwiftMessage().isCOV()) { if (abstractMT.getSwiftMessage().isCOV()) {
messageType += "COVE"; messageType += " COVE";
} }
orgnlGrpInfMaps.put("orgnlMsgNmId", messageType); orgnlGrpInfMaps.put("orgnlMsgNmId", messageType);
txInfAndStsMaps.put("orgnlGrpInf", orgnlGrpInfMaps); txInfAndStsMaps.put("orgnlGrpInf", orgnlGrpInfMaps);
......
...@@ -15,6 +15,7 @@ public class Pacs002001Parse20Field extends AbstractMt2MxPacs002001ParseField { ...@@ -15,6 +15,7 @@ public class Pacs002001Parse20Field extends AbstractMt2MxPacs002001ParseField {
Tag tag20 = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME); Tag tag20 = abstractMT.getSwiftMessage().getBlock4().getTagByName(NAME);
if (tag20 != null) { if (tag20 != null) {
grpHdrMaps.put("msgId", tag20.getValue()); grpHdrMaps.put("msgId", tag20.getValue());
appHdrMaps.put("bizMsgIdr", tag20.getValue());
} }
} }
} }
package com.brilliance.swift.mt2mx.pacs002001.impl; package com.brilliance.swift.mt2mx.pacs002001.impl;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.mt2mx.pacs002001.AbstractMt2MxPacs002001ParseField; import com.brilliance.swift.mt2mx.pacs002001.AbstractMt2MxPacs002001ParseField;
import com.brilliance.swift.vo.common.PaymentTransactionStatusCode;
import com.prowidesoftware.swift.model.SwiftTagListBlock;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.util.HashMap;
import java.util.Map;
public class Pacs002001Parse72Field extends AbstractMt2MxPacs002001ParseField { public class Pacs002001Parse72Field extends AbstractMt2MxPacs002001ParseField {
@Override @Override
public void parseField() { public void parseField() {
Tag tag72 = null;
AbstractMT abstractMT = context.get(AbstractMT.class);
boolean isCov = abstractMT.getSwiftMessage().isCOV();
if (isCov) {
SwiftTagListBlock swiftTagListBlock = abstractMT.getSequence("A");
if (swiftTagListBlock != null) {
tag72 = swiftTagListBlock.getTagByName("72");
}
} else {
tag72 = abstractMT.getSwiftMessage().getBlock4().getTagByName("72");
}
if (tag72 != null) {
txInfAndStsMaps.put("txSts", PaymentTransactionStatusCode.RJCT.value());
String mt72 = tag72.getValue();
String[] mt72s = mt72.split(Mx2MtConstants.NEW_LINE);
String mRef = "";
String tRef = "";
for (String value : mt72s) {
if (value.startsWith("/MREF/")) {
mRef = value.substring(6);
}
if (value.startsWith("/TREF/")) {
tRef = value.substring(6);
}
}
Map<String, Object> orgnlGrpInfMaps = null;
if (txInfAndStsMaps.containsKey("orgnlGrpInf")) {
orgnlGrpInfMaps = (Map<String, Object>)txInfAndStsMaps.get("orgnlGrpInf");
} else {
orgnlGrpInfMaps = new HashMap<>();
txInfAndStsMaps.put("orgnlGrpInf", orgnlGrpInfMaps);
}
if (mRef.length() > 0) {
orgnlGrpInfMaps.put("orgnlMsgId", mRef);
txInfAndStsMaps.put("orgnlInstrId", mRef);
} else {
orgnlGrpInfMaps.put("orgnlMsgId", Mx2MtConstants.MX_TO_MT_DEFAULT_VALUE);
txInfAndStsMaps.put("orgnlInstrId", Mx2MtConstants.MX_TO_MT_DEFAULT_VALUE);
}
if ("103".equals(abstractMT.getMessageType())) {
if (tRef.length() > 0) {
txInfAndStsMaps.put("orgnlEndToEndId", tRef);
} else {
txInfAndStsMaps.put("orgnlEndToEndId", Mx2MtConstants.MX_TO_MT_DEFAULT_VALUE);
}
}
mt_to_mxReject72(mt72, txInfAndStsMaps);
}
} }
} }
...@@ -695,6 +695,21 @@ public class SwiftTransferUtil { ...@@ -695,6 +695,21 @@ public class SwiftTransferUtil {
} }
/** /**
* 根据mxcode取StatusReasonCode
*/
public static StatusReasonCode getStatusReasonCodeByCode(String mxCode) {
StatusReasonCode code = null;
StatusReasonCode[] values = StatusReasonCode.values();
for (StatusReasonCode tmpCode : values) {
if (tmpCode.value().equals(mxCode)) {
code = tmpCode;
break;
}
}
return code;
}
/**
* 根据ErrorCodesRETNREJT.xlsx文件返回 * 根据ErrorCodesRETNREJT.xlsx文件返回
* List<MxMtReasonCodeInfo> * List<MxMtReasonCodeInfo>
*/ */
......
package com.brilliance.mt2mx.pacs009001; package com.brilliance.mt2mx.pacs009001;
import com.brilliance.swift.SwiftTransfer; import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.vo.SwiftTranslationErrorInfo;
import com.brilliance.swift.vo.SwiftTranslationReport;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List;
public class Test { public class Test {
private static void test202() throws IOException { private static void test202() throws IOException {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\Mt202.txt"); //File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\Mt103.txt");
File file = new File("d:/test/MT202.txt");
String mtStr = FileUtils.readFileToString(file); String mtStr = FileUtils.readFileToString(file);
String mxXml = SwiftTransfer.mt2Mx(mtStr, "D:/test/mt2mx/pacs00900108.xml", null); SwiftTranslationReport str = SwiftTransfer.mt2MxPlus(mtStr, "D:/test/mt2mx/pacs00900108.xml", null);
System.out.println(mxXml); if (str != null) {
List<SwiftTranslationErrorInfo> errorInfos = str.getErrorInfos();
if (errorInfos != null && errorInfos.size() > 0) {
for (int i=0; i<errorInfos.size(); i++) {
SwiftTranslationErrorInfo errorInfo = errorInfos.get(i);
String location = errorInfo.getLocation();
String errorType = errorInfo.getErrorType();
String description = errorInfo.getDescription();
System.out.println(location + Mx2MtConstants.NEW_LINE + "-" + errorType + ":" + description);
String originalValue = errorInfo.getOriginalValue();
if (StringUtil.isNotEmpty(originalValue)) {
System.out.println(originalValue);
}
}
}
System.out.println(str.getMessage());
}
} }
private static void test202Cov() throws IOException { private static void test202Cov() throws IOException {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\Mt202_COV.txt"); //File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\Mt103.txt");
File file = new File("d:/test/MT202Cov.txt");
String mtStr = FileUtils.readFileToString(file); String mtStr = FileUtils.readFileToString(file);
String mxXml = SwiftTransfer.mt2Mx(mtStr, "D:/test/mt2mx/pacs00900108.xml", null); SwiftTranslationReport str = SwiftTransfer.mt2MxPlus(mtStr, "D:/test/mt2mx/pacs00900108.xml", null);
System.out.println(mxXml); if (str != null) {
List<SwiftTranslationErrorInfo> errorInfos = str.getErrorInfos();
if (errorInfos != null && errorInfos.size() > 0) {
for (int i=0; i<errorInfos.size(); i++) {
SwiftTranslationErrorInfo errorInfo = errorInfos.get(i);
String location = errorInfo.getLocation();
String errorType = errorInfo.getErrorType();
String description = errorInfo.getDescription();
System.out.println(location + Mx2MtConstants.NEW_LINE + "-" + errorType + ":" + description);
String originalValue = errorInfo.getOriginalValue();
if (StringUtil.isNotEmpty(originalValue)) {
System.out.println(originalValue);
}
}
}
System.out.println(str.getMessage());
}
} }
......
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