Commit c4b63b74 by chengzhuoshen

增加pacs009001,camt054001报文要素展示功能

parent 289ef17e
......@@ -6,10 +6,7 @@ import com.brilliance.swift.mt2mx.Mt2MxCreatorManager;
import com.brilliance.swift.mx2element.Mx2ElementCreatorManager;
import com.brilliance.swift.mx2map.Mx2MapCreatorManager;
import com.brilliance.swift.mx2mt.Mx2MtCreatorManager;
import com.brilliance.swift.util.MxMessageReader;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.util.SwiftTransferUtil;
import com.brilliance.swift.util.XmlUtil;
import com.brilliance.swift.util.*;
import com.brilliance.swift.vo.SwiftTranslationReport;
import com.prowidesoftware.swift.model.MxId;
import com.prowidesoftware.swift.model.mx.AbstractMX;
......@@ -211,24 +208,12 @@ public class SwiftTransfer {
* @return
*/
public static String showMxElement(String xmlStr, String localCode) {
String mxElementStr = "";
StringBuilder sb = new StringBuilder();
Map<String, Object> maps = mx2Map(xmlStr, localCode);
if (maps.size() > 0) {
Set<String> keys = maps.keySet();
for (String key : keys) {
if (maps.get(key) instanceof Map) {
mxElementStr += Mx2MtConstants.NEW_LINE;
mxElementStr += key + ":" + Mx2MtConstants.NEW_LINE;
Map<String, Object> newMaps = (Map<String, Object>)maps.get(key);
for (String tmpKey : newMaps.keySet()) {
mxElementStr += tmpKey + ":" + newMaps.get(tmpKey) + Mx2MtConstants.NEW_LINE;
}
} else {
mxElementStr += key + ":" + maps.get(key) + Mx2MtConstants.NEW_LINE;
}
}
MessageUtil.showMaps(maps, sb);
}
return mxElementStr;
return sb.toString();
}
/**
* 将MX xml转换成Map<String, String>
......
package com.brilliance.swift.mx2map;
import com.alibaba.fastjson.JSONArray;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.util.MessageUtil;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.vo.common.CdtDbtCode;
import java.util.LinkedHashMap;
import java.util.Map;
......@@ -39,7 +42,7 @@ public abstract class AbstractMx2MapCreator implements Mx2MapCreator{
* @param name 表示party的名字
* @param elementMaps 平铺要素MAP
*/
protected void buildPartyInfo(String name, Map<String, Object> elementMaps) {
protected void buildPartyInfo(Map<String, Object> targetMaps, String name, Map<String, Object> elementMaps) {
String[] keys = new String[]{name+"AcctIdIban", name+"AcctId", name+"Nm", name+"OrgAnyBIC",
name+"PstlAdrCtry", name+"PstlAdrDept", name+"PstlAdrSubDept",
name+"PstlAdrStrtNm", name+"PstlAdrBldgNb", name+"PstlAdrBldgNm",
......@@ -56,7 +59,7 @@ public abstract class AbstractMx2MapCreator implements Mx2MapCreator{
}
if (existFlag) {
Map<String, Object> newMaps = new LinkedHashMap<>();
maps.put(getPropertyValue(name+"Info"), newMaps);
targetMaps.put(Mx2MtConstants.NEW_LINE + getPropertyValue(name+"Info"), newMaps);
for (String key : keys) {
if (elementMaps.get(key) != null) {
Object obj = elementMaps.get(key);
......@@ -80,7 +83,7 @@ public abstract class AbstractMx2MapCreator implements Mx2MapCreator{
* @param name 表示Agent的名字
* @param elementMaps 平铺要素MAP
*/
protected void buildAgentInfo(String name, Map<String, Object> elementMaps) {
protected void buildAgentInfo(Map<String, Object> targetMaps, String name, Map<String, Object> elementMaps) {
String[] keys = new String[]{name+"AcctIdIban", name+"AcctId", name+"Bicfi",
name+"Nm", name+"ClrSysIdType", name+"ClrSysId",
name+"PstlAdrCtry", name+"PstlAdrDept", name+"PstlAdrSubDept",
......@@ -98,7 +101,7 @@ public abstract class AbstractMx2MapCreator implements Mx2MapCreator{
}
if (existFlag) {
Map<String, Object> newMaps = new LinkedHashMap<>();
maps.put(getPropertyValue(name+"Info"), newMaps);
targetMaps.put(Mx2MtConstants.NEW_LINE + getPropertyValue(name+"Info"), newMaps);
for (String key : keys) {
if (elementMaps.get(key) != null) {
Object obj = elementMaps.get(key);
......@@ -116,4 +119,67 @@ public abstract class AbstractMx2MapCreator implements Mx2MapCreator{
}
}
}
protected void buildAgentInfo(Map<String, Object> targetMaps, String name, Map<String, Object> elementMaps, String subMapName) {
String[] keys = new String[]{name+"AcctIdIban", name+"AcctId", name+"Bicfi",
name+"Nm", name+"ClrSysIdType", name+"ClrSysId",
name+"PstlAdrCtry", name+"PstlAdrDept", name+"PstlAdrSubDept",
name+"PstlAdrStrtNm", name+"PstlAdrBldgNb", name+"PstlAdrBldgNm",
name+"PstlAdrFlr", name+"PstlAdrRoom", name+"PstlAdrTwnNm",
name+"PstlAdrPstBx", name+"PstlAdrPstCd", name+"PstlAdrCtrySubDvsn",
name+"PstlAdrDstrctNm", name+"PstlAdrTwnLctnNm", name+"AdrLines"
};
boolean existFlag = false;
for (String key : keys) {
if (elementMaps.get(key) != null) {
existFlag = true;
break;
}
}
if (existFlag) {
Map<String, Object> newMaps = new LinkedHashMap<>();
targetMaps.put(Mx2MtConstants.NEW_LINE + getPropertyValue(subMapName), newMaps);
for (String key : keys) {
if (elementMaps.get(key) != null) {
Object obj = elementMaps.get(key);
String suffixKey = key.substring(key.indexOf(name) + name.length());
if (obj instanceof String) {
newMaps.put(getPropertyValue(suffixKey.substring(0,1).toLowerCase() + suffixKey.substring(1)), obj);
} else if (obj instanceof JSONArray) {
JSONArray jsonArray = (JSONArray)obj;
for (int i=0; i<jsonArray.size(); i++) {
Object object = jsonArray.get(i);
newMaps.put(getPropertyValue(suffixKey.substring(0,1).toLowerCase() + suffixKey.substring(1)) + "(" +(i+1) + ")", object);
}
}
}
}
}
}
protected String addSuffixWithMessageType(Map<String, Object> elementMaps) {
String messageType = (String) elementMaps.get("messageType");
if (StringUtil.isNotEmpty(messageType)) {
if (messageType.startsWith("pacs008001")) {
return messageType + "(MT103)";
} else if (messageType.startsWith("pacs009001")) {
if (elementMaps.get("undrlygCstmrCdtTrf") != null) {
return messageType + "(MT202COV)";
} else {
return messageType + "(MT202)";
}
} else if (messageType.startsWith("camt054001")) {
if (CdtDbtCode.CRDT.value().equals(elementMaps.get("cdtDbtInd"))) {
return messageType + "(MT910)";
} else {
return messageType + "(MT900)";
}
} else if (messageType.startsWith("camt053001")) {
return messageType + "(MT950)";
} else {
return messageType;
}
}
return null;
}
}
......@@ -3,7 +3,9 @@ package com.brilliance.swift.mx2map;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2map.camt053.Mx2MapCamt053Creator;
import com.brilliance.swift.mx2map.camt054.Mx2MapCamt054Creator;
import com.brilliance.swift.mx2map.pacs008.Mx2MapPacs008Creator;
import com.brilliance.swift.mx2map.pacs009.Mx2MapPacs009Creator;
import com.prowidesoftware.swift.model.mx.AbstractMX;
import javax.xml.parsers.DocumentBuilder;
......@@ -33,17 +35,11 @@ public class Mx2MapCreatorManager {
return new Mx2MapCamt053Creator();
} else if("pacs.008.001".equals(messageType)){
return new Mx2MapPacs008Creator();
}/*else if("camt.029.001".equals(messageType)) {
return new Mx2MapCamt029Creator();
} else if("camt.056.001".equals(messageType)) {
return new Mx2MapCamt056Creator();
} else if("camt.052.001".equals(messageType)){
return new Mx2MapCamt052Creator();
} else if("camt.057.001".equals(messageType)){
return new Mx2MapCamt057Creator();
} else if("pacs.008.001".equals(messageType)){
return new Mx2MapPacs008Creator();
} */else {
} else if("pacs.009.001".equals(messageType)){
return new Mx2MapPacs009Creator();
} else if("camt.054.001".equals(messageType)){
return new Mx2MapCamt054Creator();
} else {
throw new SwiftException("无效的报文类型");
}
}
......
......@@ -20,8 +20,9 @@ public class Mx2MapCamt053Creator extends AbstractMx2MapCreator {
if (elementMaps.get("toBic") != null) {
maps.put(getPropertyValue("app.header.receiverBic"), elementMaps.get("toBic"));
}
if (elementMaps.get("msgDefIdr") != null) {
maps.put(getPropertyValue("app.header.msgDefId"), elementMaps.get("msgDefIdr"));
String messageType = addSuffixWithMessageType(elementMaps);
if (messageType != null) {
maps.put(getPropertyValue("app.header.msgDefId"), messageType);
}
if (elementMaps.get("bizSvc") != null) {
maps.put(getPropertyValue("app.header.bizSvc"), elementMaps.get("bizSvc"));
......
package com.brilliance.swift.mx2map.camt054;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2map.AbstractMx2MapCreator;
import com.brilliance.swift.vo.common.CdtDbtCode;
import java.math.BigDecimal;
import java.util.Map;
public class Mx2MapCamt054Creator extends AbstractMx2MapCreator {
@Override
public Map<String, Object> mx2Map() throws SwiftException {
Map<String, Object> elementMaps = SwiftTransfer.mx2ElementMaps(xmlStr);
if (elementMaps.get("frBic") != null) {
maps.put(getPropertyValue("app.header.sendBic"), elementMaps.get("frBic"));
}
if (elementMaps.get("toBic") != null) {
maps.put(getPropertyValue("app.header.receiverBic"), elementMaps.get("toBic"));
}
String messageType = addSuffixWithMessageType(elementMaps);
if (messageType != null) {
maps.put(getPropertyValue("app.header.msgDefId"), messageType);
}
if (elementMaps.get("bizSvc") != null) {
maps.put(getPropertyValue("app.header.bizSvc"), elementMaps.get("bizSvc"));
}
if (elementMaps.get("creDt") != null) {
maps.put(getPropertyValue("app.header.creDt"), elementMaps.get("creDt"));
}
if (elementMaps.get("endToEndId") != null) {
maps.put(getPropertyValue("endToEnd.id"), elementMaps.get("endToEndId"));
}
if (elementMaps.get("uetr") != null) {
maps.put(getPropertyValue("uetr"), elementMaps.get("uetr"));
}
if (elementMaps.get("cdtDbtInd") != null) {
String cdtDbtInd = (String) elementMaps.get("cdtDbtInd");
if (CdtDbtCode.CRDT.value().equals(cdtDbtInd)) {
maps.put(getPropertyValue("cdtDbtInd"), getPropertyValue("credit"));
} else {
maps.put(getPropertyValue("cdtDbtInd"), getPropertyValue("debit"));
}
}
if (elementMaps.get("sts") != null) {
maps.put(getPropertyValue("status"), elementMaps.get("sts"));
} else if (elementMaps.get("stsPrtry") != null) {
maps.put(getPropertyValue("status"), elementMaps.get("stsPrtry"));
}
if (elementMaps.get("bookgDt") != null) {
maps.put(getPropertyValue("bookingDate"), elementMaps.get("bookgDt"));
}
if (elementMaps.get("bizMsgIdr") != null) {
maps.put(getPropertyValue("message.id"), elementMaps.get("bizMsgIdr"));
}
if (elementMaps.get("valDt") != null) {
maps.put(getPropertyValue("valueDate"), elementMaps.get("valDt"));
}
if (elementMaps.get("ntryAmt") != null) {
BigDecimal amt = (BigDecimal) elementMaps.get("ntryAmt");
if (elementMaps.get("ntryCcy") != null) {
maps.put(getPropertyValue("valueAmt"), elementMaps.get("ntryCcy") + " " + amt.toPlainString());
} else {
maps.put(getPropertyValue("valueAmt"), amt.toPlainString());
}
}
if (elementMaps.get("ntfctnAcctIdIban") != null) {
maps.put(getPropertyValue("acctIdIban"), elementMaps.get("ntfctnAcctIdIban"));
}
if (elementMaps.get("ntfctnAcctId") != null) {
maps.put(getPropertyValue("acctId"), elementMaps.get("ntfctnAcctId"));
}
if (elementMaps.get("ntfctnAcctCcy") != null) {
maps.put(getPropertyValue("accountCcy"), elementMaps.get("ntfctnAcctCcy"));
}
buildPartyInfo(maps,"dbtr", elementMaps);
buildAgentInfo(maps, "dbtrAgt", elementMaps);
buildAgentInfo(maps, "intrmyAgt1", elementMaps);
if (elementMaps.get("addtlTxInf") != null) {
maps.put(Mx2MtConstants.NEW_LINE + getPropertyValue("txnRemark"), elementMaps.get("addtlTxInf"));
}
return maps;
}
}
package com.brilliance.swift.mx2map.pacs008;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2map.AbstractMx2MapCreator;
import com.brilliance.swift.util.StringUtil;
......@@ -9,6 +10,7 @@ import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
......@@ -22,8 +24,9 @@ public class Mx2MapPacs008Creator extends AbstractMx2MapCreator {
if (elementMaps.get("toBic") != null) {
maps.put(getPropertyValue("app.header.receiverBic"), elementMaps.get("toBic"));
}
if (elementMaps.get("msgDefIdr") != null) {
maps.put(getPropertyValue("app.header.msgDefId"), elementMaps.get("msgDefIdr"));
String messageType = addSuffixWithMessageType(elementMaps);
if (messageType != null) {
maps.put(getPropertyValue("app.header.msgDefId"), messageType);
}
if (elementMaps.get("bizSvc") != null) {
maps.put(getPropertyValue("app.header.bizSvc"), elementMaps.get("bizSvc"));
......@@ -31,9 +34,7 @@ public class Mx2MapPacs008Creator extends AbstractMx2MapCreator {
if (elementMaps.get("creDt") != null) {
maps.put(getPropertyValue("app.header.creDt"), elementMaps.get("creDt"));
}
if (elementMaps.get("bizMsgIdr") != null) {
maps.put(getPropertyValue("message.id"), elementMaps.get("bizMsgIdr"));
}
if (elementMaps.get("endToEndId") != null) {
maps.put(getPropertyValue("endToEnd.id"), elementMaps.get("endToEndId"));
}
......@@ -49,39 +50,44 @@ public class Mx2MapPacs008Creator extends AbstractMx2MapCreator {
if (elementMaps.get("sttlmAcctId") != null) {
maps.put(getPropertyValue("settlement.acct"), elementMaps.get("sttlmAcctId"));
}
Map<String, Object> creditTransferMaps = new LinkedHashMap<>();
maps.put(Mx2MtConstants.NEW_LINE + getPropertyValue("creditTransferInfo"), creditTransferMaps);
if (elementMaps.get("bizMsgIdr") != null) {
creditTransferMaps.put(getPropertyValue("message.id"), elementMaps.get("bizMsgIdr"));
}
if (elementMaps.get("intrBkSttlmDt") != null) {
maps.put(getPropertyValue("settlement.date"), elementMaps.get("intrBkSttlmDt"));
creditTransferMaps.put(getPropertyValue("settlement.date"), elementMaps.get("intrBkSttlmDt"));
}
if (elementMaps.get("intrBkSttlmAmt") != null) {
BigDecimal amt = (BigDecimal) elementMaps.get("intrBkSttlmAmt");
if (elementMaps.get("intrBkSttlmCcy") != null) {
maps.put(getPropertyValue("settlement.amt"), elementMaps.get("intrBkSttlmCcy") + " " + amt.toPlainString());
creditTransferMaps.put(getPropertyValue("settlement.amt"), elementMaps.get("intrBkSttlmCcy") + " " + amt.toPlainString());
} else {
maps.put(getPropertyValue("settlement.amt"), amt.toPlainString());
creditTransferMaps.put(getPropertyValue("settlement.amt"), amt.toPlainString());
}
}
if (elementMaps.get("instdAmt") != null) {
BigDecimal amt = (BigDecimal) elementMaps.get("instdAmt");
if (elementMaps.get("instdAmtCcy") != null) {
maps.put(getPropertyValue("original.settlement.amt"), elementMaps.get("instdAmtCcy") + " " + amt.toPlainString());
creditTransferMaps.put(getPropertyValue("original.settlement.amt"), elementMaps.get("instdAmtCcy") + " " + amt.toPlainString());
} else {
maps.put(getPropertyValue("original.settlement.amt"), amt.toPlainString());
creditTransferMaps.put(getPropertyValue("original.settlement.amt"), amt.toPlainString());
}
}
if (elementMaps.get("xchgRate") != null) {
BigDecimal xchgRate = (BigDecimal) elementMaps.get("xchgRate");
maps.put(getPropertyValue("exchange.rate"), xchgRate.toPlainString());
}
buildPartyInfo("dbtr", elementMaps);
buildAgentInfo("dbtrAgt", elementMaps);
buildAgentInfo("instgRmbrsmntAgt", elementMaps);
buildAgentInfo("instdRmbrsmntAgt", elementMaps);
buildAgentInfo("thrdRmbrsmntAgt", elementMaps);
buildAgentInfo("intrmyAgt1", elementMaps);
buildAgentInfo("cdtrAgt", elementMaps);
buildPartyInfo("cdtr", elementMaps);
creditTransferMaps.put(getPropertyValue("exchange.rate"), xchgRate.toPlainString());
}
buildPartyInfo(maps,"dbtr", elementMaps);
buildAgentInfo(maps, "dbtrAgt", elementMaps);
buildAgentInfo(maps, "instgRmbrsmntAgt", elementMaps);
buildAgentInfo(maps, "instdRmbrsmntAgt", elementMaps);
buildAgentInfo(maps, "thrdRmbrsmntAgt", elementMaps);
buildAgentInfo(maps, "intrmyAgt1", elementMaps);
buildAgentInfo(maps, "cdtrAgt", elementMaps);
buildPartyInfo(maps, "cdtr", elementMaps);
if (elementMaps.get("chrgBr") != null) {
maps.put(getPropertyValue("charge.by"), elementMaps.get("chrgBr"));
maps.put(Mx2MtConstants.NEW_LINE + getPropertyValue("charge.by"), elementMaps.get("chrgBr"));
}
if (elementMaps.get("chrgsInf") != null) {
List<Map<String, Object>> list = (List<Map<String, Object>>)elementMaps.get("chrgsInf");
......@@ -105,7 +111,7 @@ public class Mx2MapPacs008Creator extends AbstractMx2MapCreator {
}
tag = abstractMT.getSwiftMessage().getBlock4().getTagByName("72");
if (tag != null) {
maps.put(getPropertyValue("statement.entry.addtlTxInf"), tag.getValue());
maps.put(getPropertyValue("txnRemark"), tag.getValue());
}
tag = abstractMT.getSwiftMessage().getBlock4().getTagByName("77B");
if (tag != null) {
......
package com.brilliance.swift.mx2map.pacs009;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2map.AbstractMx2MapCreator;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.SwiftTagListBlock;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class Mx2MapPacs009Creator extends AbstractMx2MapCreator {
@Override
public Map<String, Object> mx2Map() throws SwiftException {
Map<String, Object> elementMaps = SwiftTransfer.mx2ElementMaps(xmlStr);
if (elementMaps.get("frBic") != null) {
maps.put(getPropertyValue("app.header.sendBic"), elementMaps.get("frBic"));
}
if (elementMaps.get("toBic") != null) {
maps.put(getPropertyValue("app.header.receiverBic"), elementMaps.get("toBic"));
}
String messageType = addSuffixWithMessageType(elementMaps);
if (messageType != null) {
maps.put(getPropertyValue("app.header.msgDefId"), messageType);
}
if (elementMaps.get("bizSvc") != null) {
maps.put(getPropertyValue("app.header.bizSvc"), elementMaps.get("bizSvc"));
}
if (elementMaps.get("creDt") != null) {
maps.put(getPropertyValue("app.header.creDt"), elementMaps.get("creDt"));
}
if (elementMaps.get("endToEndId") != null) {
maps.put(getPropertyValue("endToEnd.id"), elementMaps.get("endToEndId"));
}
if (elementMaps.get("uetr") != null) {
maps.put(getPropertyValue("uetr"), elementMaps.get("uetr"));
}
if (elementMaps.get("sttlmMtd") != null) {
maps.put(getPropertyValue("settlement.method"), elementMaps.get("sttlmMtd"));
}
if (elementMaps.get("sttlmAcctIdIban") != null) {
maps.put(getPropertyValue("settlement.acct"), elementMaps.get("sttlmAcctIdIban"));
}
if (elementMaps.get("sttlmAcctId") != null) {
maps.put(getPropertyValue("settlement.acct"), elementMaps.get("sttlmAcctId"));
}
Map<String, Object> creditTransferMaps = new LinkedHashMap<>();
maps.put(Mx2MtConstants.NEW_LINE + getPropertyValue("creditTransferInfo"), creditTransferMaps);
if (elementMaps.get("bizMsgIdr") != null) {
creditTransferMaps.put(getPropertyValue("message.id"), elementMaps.get("bizMsgIdr"));
}
if (elementMaps.get("intrBkSttlmDt") != null) {
creditTransferMaps.put(getPropertyValue("settlement.date"), elementMaps.get("intrBkSttlmDt"));
}
if (elementMaps.get("intrBkSttlmAmt") != null) {
BigDecimal amt = (BigDecimal) elementMaps.get("intrBkSttlmAmt");
if (elementMaps.get("intrBkSttlmCcy") != null) {
creditTransferMaps.put(getPropertyValue("settlement.amt"), elementMaps.get("intrBkSttlmCcy") + " " + amt.toPlainString());
} else {
creditTransferMaps.put(getPropertyValue("settlement.amt"), amt.toPlainString());
}
}
buildAgentInfo(maps,"dbtr", elementMaps, "dbtrAgtInfo");
buildAgentInfo(maps,"instgRmbrsmntAgt", elementMaps);
buildAgentInfo(maps,"instdRmbrsmntAgt", elementMaps);
buildAgentInfo(maps,"intrmyAgt1", elementMaps);
buildAgentInfo(maps,"cdtrAgt", elementMaps, "cdtrAgtAcctInfo");
buildAgentInfo(maps,"cdtr", elementMaps, "cdtrAgtInfo");
AbstractMT abstractMT = null;
try {
String mtMessage = SwiftTransfer.mx2Mt(xmlStr, null, null);
if (StringUtil.isNotEmpty(mtMessage)) {
abstractMT = AbstractMT.parse(mtMessage);
}
} catch (IOException e) {
throw new SwiftException(e.getMessage());
}
Tag tag = getTagByName(abstractMT, "72", "A");
if (tag != null) {
maps.put(Mx2MtConstants.NEW_LINE + getPropertyValue("txnRemark"), tag.getValue());
}
//子交易信息
if (elementMaps.get("undrlygCstmrCdtTrf") != null) {
Map<String, Object> undrlygCstmrCdtTrfMaps = (Map<String, Object>)elementMaps.get("undrlygCstmrCdtTrf");
Map<String, Object> undrlyTxnMaps = new LinkedHashMap<>();
maps.put(Mx2MtConstants.NEW_LINE + getPropertyValue("undrlygCstmrCdtTrfInfo"), undrlyTxnMaps);
buildPartyInfo(undrlyTxnMaps, "dbtr", undrlygCstmrCdtTrfMaps);
buildAgentInfo(undrlyTxnMaps, "dbtrAgt", undrlygCstmrCdtTrfMaps);
buildAgentInfo(undrlyTxnMaps, "intrmyAgt1", undrlygCstmrCdtTrfMaps);
buildAgentInfo(undrlyTxnMaps, "cdtrAgt", undrlygCstmrCdtTrfMaps);
buildPartyInfo(undrlyTxnMaps, "cdtr", undrlygCstmrCdtTrfMaps);
tag = getTagByName(abstractMT, "70", "B");
if (tag != null) {
undrlyTxnMaps.put(getPropertyValue("remittanceInformation"), tag.getValue());
}
tag = getTagByName(abstractMT, "72", "B");
if (tag != null) {
undrlyTxnMaps.put(getPropertyValue("txnRemark"), tag.getValue());
}
if (undrlygCstmrCdtTrfMaps.get("instdAmt") != null) {
BigDecimal amt = (BigDecimal) elementMaps.get("instdAmt");
if (elementMaps.get("instdAmtCcy") != null) {
undrlyTxnMaps.put(getPropertyValue("original.settlement.amt"), elementMaps.get("instdAmtCcy") + " " + amt.toPlainString());
} else {
undrlyTxnMaps.put(getPropertyValue("original.settlement.amt"), amt.toPlainString());
}
}
}
return maps;
}
protected Tag getTagByName(AbstractMT abstractMT, String tagName, String sequence) {
if (abstractMT == null || abstractMT.getSwiftMessage() == null) return null;
boolean isCov = abstractMT.getSwiftMessage().isCOV();
if (isCov) {
SwiftTagListBlock swiftTagListBlock = abstractMT.getSequence(sequence);
if (swiftTagListBlock != null) {
return swiftTagListBlock.getTagByName(tagName);
}
} else {
return abstractMT.getSwiftMessage().getBlock4().getTagByName(tagName);
}
return null;
}
}
......@@ -43,14 +43,18 @@ public class Mx2Mt940950Creator extends AbstractMx2MtCreator {
}
if (index > -1) {
String opbdCcy = getXmlNodeValue(bodyParentPath, document, "Stmt.Bal("+index+").Amt@Ccy");
for (int i=0; i<balanceTypeCount; i++) {
String balanceType = getXmlNodeValue(bodyParentPath, document, "Stmt.Bal("+i+").Tp.CdOrPrtry.Cd");
if (BalanceTypeCode.CLBD.value().equals(balanceType)
|| BalanceTypeCode.CLAV.value().equals(balanceType)
|| BalanceTypeCode.FWAV.value().equals(balanceType)) {
String balanceCcy = getXmlNodeValue(bodyParentPath, document, "Stmt.Bal("+i+").Amt@Ccy");
if (StringUtil.isNotEmpty(opbdCcy) && StringUtil.isNotEmpty(balanceCcy) && !opbdCcy.substring(0,2).equals(balanceCcy.substring(0,2))) {
buildSTErrorInfo(91, null, null);
if (StringUtil.isEmpty(opbdCcy)) {
buildSTErrorInfo(91, null, null);
} else {
for (int i=0; i<balanceTypeCount; i++) {
String balanceType = getXmlNodeValue(bodyParentPath, document, "Stmt.Bal("+i+").Tp.CdOrPrtry.Cd");
if (BalanceTypeCode.CLBD.value().equals(balanceType)
|| BalanceTypeCode.CLAV.value().equals(balanceType)
|| BalanceTypeCode.FWAV.value().equals(balanceType)) {
String balanceCcy = getXmlNodeValue(bodyParentPath, document, "Stmt.Bal("+i+").Amt@Ccy");
if (StringUtil.isEmpty(balanceCcy) || (StringUtil.isNotEmpty(balanceCcy) && !opbdCcy.substring(0,2).equals(balanceCcy.substring(0,2)))) {
buildSTErrorInfo(91, null, null);
}
}
}
}
......
......@@ -88,6 +88,11 @@ public class Field61Generate extends AbstractMx2MtTagsGenerate {
buildSTErrorInfo(93, "Block4/61/"+(i+1), amt);
}
value += NumberUtil.formatAmt(new BigDecimal(amt), ccy);
} else {
//Translation Preconditions/PREC008
if (StringUtil.isNotEmpty(acctCcy) && !acctCcy.equals(ccy)) {
buildSTErrorInfo(95, "Block4/61/"+(i+1), null);
}
}
value += "NTRF";
......
package com.brilliance.swift.util;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
public class MessageUtil {
......@@ -30,4 +32,29 @@ public class MessageUtil {
throw new SwiftException(e.getMessage());
}
}
public static void showMaps(Map<String, Object> maps, StringBuilder sb) {
Set<String> keys = maps.keySet();
for (String key : keys) {
if (maps.get(key) instanceof Map) {
sb//.append(Mx2MtConstants.NEW_LINE)
.append(key).append(":")
.append(Mx2MtConstants.NEW_LINE);
Map<String, Object> newMaps = (Map<String, Object>)maps.get(key);
showMaps(newMaps, sb);
} else {
sb.append(key).append(":").append(maps.get(key)).append(Mx2MtConstants.NEW_LINE);
}
}
}
/*public static void main(String[] args) {
TemplateEngine engine = TemplateUtil.createEngine(new TemplateConfig(CharsetUtil.CHARSET_GBK, "template", TemplateConfig.ResourceMode.CLASSPATH));
Template template = engine.getTemplate("template/pacs008001.vm");
Map<String, Object> maps = new HashMap<>();
maps.put("name", "程");
//maps.put("name1", "");
String result = template.render(maps);
System.out.println(result);
}*/
}
......@@ -41,6 +41,7 @@ settlement.amt=\u53d1\u6c47\u91d1\u989d
original.settlement.amt=\u6536\u6c47\u91d1\u989d
exchange.rate=\u6c47\u7387
ccy=\u5e01\u79cd
creditTransferInfo=\u6c47\u7968\u57fa\u7840\u4fe1\u606f
dbtrInfo=\u6c47\u6b3e\u65b9\u4fe1\u606f
dbtrAgtInfo=\u6c47\u6b3e\u884c\u4fe1\u606f
instgRmbrsmntAgtInfo=\u53d1\u62a5\u884c\u7684\u4ee3\u7406\u884c\u4fe1\u606f
......@@ -48,15 +49,23 @@ instdRmbrsmntAgtInfo=\u6536\u62a5\u884c\u7684\u4ee3\u7406\u884c\u4fe1\u606f
thrdRmbrsmntAgtInfo=\u7b2c\u4e09\u65b9\u507f\u4ed8\u884c\u4fe1\u606f
intrmyAgt1Info=\u4e2d\u95f4\u884c\u4fe1\u606f
cdtrAgtInfo=\u6536\u6b3e\u884c\u4fe1\u606f
cdtrAgtAcctInfo=\u8d26\u6237\u884c\u4fe1\u606f
cdtrInfo=\u6536\u6b3e\u65b9\u4fe1\u606f
undrlygCstmrCdtTrfInfo=\u5b50\u4ea4\u6613\u4fe1\u606f
charge.by=\u8d39\u7528\u627f\u62c5\u65b9\u5f0f
charge.info=\u8d39\u7528\u660e\u7ec6
remittanceInformation=\u6c47\u6b3e\u4fe1\u606f
regulatoryReporting=\u6cd5\u89c4\u8bf4\u660e
txnRemark=\u4ea4\u6613\u9644\u8a00
cdtDbtInd=\u501f\u8d37\u6807\u8bc6
status=\u72b6\u6001
bookingDate=\u8bb0\u8d26\u65e5\u671f
valueDate=\u8d77\u606f\u65e5
valueAmt=\u91d1\u989d
#party&agent
acctIdIban=\u8d26\u53f7
acctId=\u8d26\u53f7
accountCcy=\u8d26\u6237\u5e01\u79cd
nm=\u540d\u79f0
orgAnyBIC=\u7ec4\u7ec7\u673a\u6784\u884c\u53f7
pstlAdrCtry=\u5c45\u4f4f\u5730\u56fd\u5bb6
......
......@@ -41,6 +41,7 @@ settlement.amt=Interbank Settlement Amount
original.settlement.amt=Instructed Amount
exchange.rate=Exchange Rate
ccy=Currency
creditTransferInfo=Credit Transfer Info
dbtrInfo=Debtor
dbtrAgtInfo=Debtor Agent
instgRmbrsmntAgtInfo=Instructing Reimbursement Agent
......@@ -49,14 +50,21 @@ thrdRmbrsmntAgtInfo=Third Reimbursement Agent
intrmyAgt1Info=Intermediary Agent 1
cdtrAgtInfo=Creditor Agent
cdtrInfo=Creditor
undrlygCstmrCdtTrfInfo=Credit Transfer Transaction Information
charge.by=Charge Bearer
charge.info=Charges Information
remittanceInformation=Remittance Information
regulatoryReporting=Regulatory Reporting
txnRemark=Remark Of Transaction
cdtDbtInd=Credit Debit Indicator
status=Status
bookingDate=Booking Date
valueDate=Value Date
valueAmt=Value Amount
#party&agent
acctIdIban=Account Number(IBAN)
acctId=Account Number
accountCcy=Account Currency
nm=Name
orgAnyBIC=Organisation Identification BIC
pstlAdrCtry=Country
......
......@@ -20,7 +20,10 @@ public class Mx2ElementTest {
@Test
public void testMx2Map() throws IOException {
//File file = FileUtils.toFile(Mx2MtTest.class.getResource("/swiftXml/MxPacs00800108.xml"));
File file = FileUtils.toFile(Mx2MtTest.class.getResource("/swiftXml/MxCamt05300108_950.xml"));
File file = FileUtils.toFile(Mx2MtTest.class.getResource("/swiftXml/MxPacs00900108.xml"));
//File file = FileUtils.toFile(Mx2MtTest.class.getResource("/swiftXml/MxPacs00900108_COV.xml"));
//File file = FileUtils.toFile(Mx2MtTest.class.getResource("/swiftXml/MxCamt05300108_950.xml"));
//File file = FileUtils.toFile(Mx2MtTest.class.getResource("/swiftXml/MxCamt05400108_CREDIT.xml"));
String xmlStr = FileUtils.readFileToString(file);
String elementStr = SwiftTransfer.showMxElement(xmlStr, "CN");
System.out.println(elementStr);
......
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