Commit 45675193 by chengzhuoshen

1.修改swift dto生成MT报文的block1,block2,block3,

block5代码
2.根据配置文件把MX模型转SwiftDto,目前实现了PACS008001
parent be410ce5
......@@ -84,5 +84,10 @@
<artifactId>eibs-ext</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.24</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -5,7 +5,6 @@ import com.brilliance.swift.mt2SwiftDto.Mt2SwiftDtoCreateManager;
import com.brilliance.swift.mx2swiftdto.Mx2SwiftDtoCreatorManager;
import com.brilliance.swift.swiftdto2mt.SwiftDto2MtCreatorManager;
import com.brilliance.swift.swiftdto2mx.SwiftDto2MxCreatorManager;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.vo.SwiftDto;
import com.prowidesoftware.swift.model.mx.AbstractMX;
import org.apache.commons.io.FileUtils;
......@@ -20,23 +19,23 @@ public class SwiftTransfer {
* SWIFTDTO transfer MT
* @param file
* @param fileOutputPath
* @param mtIoType
* @param extraMap
* @return
* @throws SwiftException
*/
public static String swiftDto2Mt(File file, String fileOutputPath, String mtIoType) throws SwiftException {
public static String swiftDto2Mt(File file, String fileOutputPath, Map<String, Object> extraMap) throws SwiftException {
try {
String gsonStr = FileUtils.readFileToString(file);
SwiftDto swiftDto = SwiftDto.fromJson(gsonStr);
return new SwiftDto2MtCreatorManager().swiftDto2Mt(swiftDto, fileOutputPath, StringUtil.isEmpty(mtIoType)?"O":mtIoType);
return new SwiftDto2MtCreatorManager().swiftDto2Mt(swiftDto, fileOutputPath, extraMap);
} catch (IOException e) {
throw new SwiftException("ERROR", e.getMessage());
}
}
public static String swiftDto2Mt(String gsonStr, String fileOutputPath, String mtIoType) throws SwiftException{
public static String swiftDto2Mt(String gsonStr, String fileOutputPath, Map<String, Object> extraMap) throws SwiftException{
SwiftDto swiftDto = SwiftDto.fromJson(gsonStr);
return new SwiftDto2MtCreatorManager().swiftDto2Mt(swiftDto, fileOutputPath, StringUtil.isEmpty(mtIoType)?"O":mtIoType);
return new SwiftDto2MtCreatorManager().swiftDto2Mt(swiftDto, fileOutputPath, extraMap);
}
/**
......@@ -119,17 +118,7 @@ public class SwiftTransfer {
public static String mx2Mt(String xmlStr, String outPutFilePath, Map<String, Object> extraMap) throws SwiftException {
SwiftDto swiftDto = new Mx2SwiftDtoCreatorManager().convert(xmlStr, outPutFilePath, extraMap);
String bnkBic = null;
String mtIoType = "O";//代表是收报,默认值
if (extraMap != null) {
bnkBic = (String)extraMap.get("bnkBic");
}
if (StringUtil.isNotEmpty(bnkBic)) {
if (bnkBic.equals(swiftDto.getSwiftHeader().getSenderBic())) {
mtIoType = "I";//如果发报行和本行bic一样,表示是发报
}
}
return new SwiftDto2MtCreatorManager().swiftDto2Mt(swiftDto, outPutFilePath, mtIoType);
return new SwiftDto2MtCreatorManager().swiftDto2Mt(swiftDto, outPutFilePath, extraMap);
}
/**
......@@ -160,17 +149,7 @@ public class SwiftTransfer {
*/
public static Map<String, String> mx2MtMap(String xmlStr, Map<String, Object> extraMap) throws SwiftException {
SwiftDto swiftDto = new Mx2SwiftDtoCreatorManager().convert(xmlStr, null, null);
String bnkBic = null;
String mtIoType = "O";//代表是收报,默认值
if (extraMap != null) {
bnkBic = (String)extraMap.get("bnkBic");//得到本行的bicCode
}
if (StringUtil.isNotEmpty(bnkBic)) {
if (bnkBic.equals(swiftDto.getSwiftHeader().getSenderBic())) {
mtIoType = "I";//如果发报行和本行bic一样,表示是发报
}
}
String mtStr = new SwiftDto2MtCreatorManager().swiftDto2Mt(swiftDto, null, mtIoType);
String mtStr = new SwiftDto2MtCreatorManager().swiftDto2Mt(swiftDto, null, extraMap);
Map<String, String> maps = MessageReader.getSwfMsgInfoViaMsg(mtStr);
maps.put("std", "MX");
AbstractMX abstractMx = AbstractMX.parse(xmlStr);
......
......@@ -88,4 +88,33 @@ public class Mx2MtConstants {
public static final String MT_21_DEFAULT_VALUE = "NONREF";
public static final String MX_END_TO_END_ID_DEFAULT_VALUE = "NOTPROVIDED";
/**
* 外部参数名称
*/
public static final String APPLICATION_MODE = "ApplicationMode";
public static final String RECEIVERS_ADDRESS = "ReceiversAddress";
public static final String SENDERS_ADDRESS = "SendersAddress";
public static final String OUTPUT_DATE = "OutputDate";
public static final String INTPUT_DATE = "IntputDate";
public static final String MESSAGE_PRIORITY = "MessagePriority";
public static final String BLOCK3_103 = "Block3_103";
public static final String BLOCK3_108 = "Block3_108";
public static final String BLOCK3_165 = "Block3_165";
public static final String BLOCK3_433 = "Block3_433";
public static final String BLOCK3_434 = "Block3_434";
public static final String BLOCK5_TNG = "Block5_TNG";
public static final String BLOCK5_PDE = "Block5_PDE";
}
......@@ -6,16 +6,17 @@ import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.util.XmlUtil;
import com.brilliance.swift.vo.SwiftHeader;
import com.brilliance.swift.vo.common.*;
import org.apache.commons.io.FileUtils;
import org.dom4j.Document;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.*;
public abstract class AbstractMx2SwiftDtoCreator implements Mx2SwiftDtoCreator{
......@@ -39,6 +40,8 @@ public abstract class AbstractMx2SwiftDtoCreator implements Mx2SwiftDtoCreator{
protected String defaultDateFormate = "yyyy-MM-dd";
protected Map<String, Object> maps = new HashMap<>();
@Override
public void appHeader() throws SwiftException {
try {
......@@ -310,4 +313,119 @@ public abstract class AbstractMx2SwiftDtoCreator implements Mx2SwiftDtoCreator{
throw new SwiftException("ERROR", e.getMessage());
}
}
public Object getXmlPathValue(Document document, String xmlPath) {
try {
xmlPath = xmlPath.replace("#APP", appHdrParentElementName).replace("#GRP", grpHdrParentElementName).replace("#BODY", bodyHdrParentElementName);
Object value = null;
if (xmlPath.indexOf("*") > -1) { //出现多个值
String beginPath = xmlPath.substring(0, xmlPath.indexOf("*"));
String endPath = xmlPath.substring(xmlPath.indexOf("*")+1);
String type = "String";
if (endPath.indexOf("&") > -1) {
type = endPath.substring(endPath.indexOf("&")+1);
endPath = endPath.substring(0, endPath.indexOf("&"));
}
int count = XmlUtil.getChildrenCount(document, beginPath, null);
if (count > 0) {
if ("String".equalsIgnoreCase(type)) {
List<String> list = new ArrayList<>();
for (int i=0; i<count; i++) {
String xmlValue = XmlUtil.getXmlNodeValue(document, beginPath+"("+i+")."+endPath);
list.add(xmlValue);
}
value = list;
} else if ("BigDecimal".equalsIgnoreCase(type)) {
List<BigDecimal> list = new ArrayList<>();
for (int i=0; i<count; i++) {
String xmlValue = XmlUtil.getXmlNodeValue(document, beginPath+"("+i+")."+endPath);
list.add(new BigDecimal(xmlValue));
}
value = list;
}
}
} else if (xmlPath.indexOf("&") > -1) { //数据类型
String type = xmlPath.substring(xmlPath.indexOf("&")+1);
xmlPath = xmlPath.substring(0, xmlPath.indexOf("&"));
String xmlValue = XmlUtil.getXmlNodeValue(document, xmlPath);
if ("DATE".equalsIgnoreCase(type) && StringUtil.isNotEmpty(xmlValue)) {
XMLGregorianCalendar dtTm = DatatypeFactory.newInstance().newXMLGregorianCalendar(xmlValue);
value = DateUtil.format(dtTm.toGregorianCalendar().getTime(), defaultFormate);
} else if ("BigDecimal".equalsIgnoreCase(type) && StringUtil.isNotEmpty(xmlValue)) {
value = new BigDecimal(xmlValue);
} else if ("List<String>".equalsIgnoreCase(type) && StringUtil.isNotEmpty(xmlValue)) {
int count = XmlUtil.getChildrenCount(document, xmlPath, null);
if (count > 0) {
List<String> list = new ArrayList<>();
for (int i=0; i<count; i++) {
xmlValue = XmlUtil.getXmlNodeValue(document, xmlPath+"("+i+")");
list.add(xmlValue);
}
value = list;
}
}
} else {
value = XmlUtil.getXmlNodeValue(document, xmlPath);
}
return value;
} catch (DatatypeConfigurationException e) {
throw new SwiftException("ERROR", e.getMessage());
}
}
/**
* 传配置文件名称,
* 根据配置文件将MX 模型转换成Swift Dto JSON map
* @param fileName
*/
protected void readPropertyFile(String fileName) {
try {
File propertyFile = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\template\\mx2swiftdto\\"+ fileName);
List<String> properties = FileUtils.readLines(propertyFile);
if (properties.size() > 0) {
for (String property : properties) {
if (property.startsWith("#")) {
continue;//过滤注释
}
String[] strArr = property.split("=");
if (strArr.length != 2) {
continue;//过滤掉不符合规则的配置
}
String key = strArr[0];
String xmlPath = strArr[1];
String[] xmlPaths = xmlPath.split("\\?");
Object xmlValue = null;
for (String path : xmlPaths) {
xmlValue = getXmlPathValue(document, path);//?表示优先级,如果取到值就跳出循环
if (xmlValue != null) break;
}
if (xmlValue == null) continue;
String[] keys = key.split("\\.");
if (keys.length == 1) {
maps.put(keys[0], xmlValue); //如果只有一个节点,直接put值
} else { //如果节点值超过1个,先赋值第一个节点,再循环赋值,最后一个节点直接put值。
Map<String, Object> keyMap = null;
if (maps.containsKey(keys[0])) {
keyMap = (Map<String, Object>)maps.get(keys[0]);
} else {
keyMap = new HashMap<>();
maps.put(keys[0], keyMap);
}
for (int i=1; i<keys.length; i++) {
if (i == keys.length-1) {
keyMap.put(keys[i], xmlValue);
break;
}
if (!keyMap.containsKey(keys[i])) {
keyMap.put(keys[i], new HashMap<>());
}
keyMap = (Map<String, Object>)keyMap.get(keys[i]);
}
}
}
}
} catch (IOException e) {
throw new SwiftException("ERROR", e.getMessage());
}
}
}
......@@ -8,11 +8,7 @@ public class Mx2SwiftDtoContextIdentifier {
public static final String MX_VERSION = "mx.version";
public static final String APPHDR_PARENT_ELEMENT_NAME = "apphdr.parent.element.name";
public static final String GRPHDR_PARENT_ELEMENT_NAME = "grphdr.parent.element.name";
public static final String BODY_PARENT_ELEMENT_NAME = "body.parent.element.name";
public static final String MX_MESSAGETYPE = "mx.messageType";
public static final String MX_TO_SWIFTDTO_OUTPUT_FILE_PATH = "m.to.swiftdto.output.filepath";
......
......@@ -26,11 +26,12 @@ public class Mx2SwiftDtoCreatorManager {
public void init(String xmlStr) {
AbstractMX abstractMX = AbstractMX.parse(xmlStr);
msgType = (abstractMX.getMxId().getBusinessProcess().name()
+ "."
+ abstractMX.getMxId().getFunctionality()
+ "."
+ abstractMX.getMxId().getVariant())
//+ abstractMX.getMxId().getVersion())
.trim()
.replace(".", "");
.trim();
mxObj = abstractMX;
this.xmlStr = xmlStr;
version = abstractMX.getMxId().getVersion();
......@@ -46,6 +47,7 @@ public class Mx2SwiftDtoCreatorManager {
context.set(Mx2SwiftDtoContextIdentifier.MX_XMl_DOCUMENT, document);
context.set(Mx2SwiftDtoContextIdentifier.MX_OBJ, mxObj);
context.set(Mx2SwiftDtoContextIdentifier.MX_VERSION, version);
context.set(Mx2SwiftDtoContextIdentifier.MX_MESSAGETYPE, msgType);
AbstractMx2SwiftDtoCreator creator = getMx2SwiftDtoCreator(msgType);
creator.setContext(context);
creator.preProcess();
......@@ -60,13 +62,13 @@ public class Mx2SwiftDtoCreatorManager {
}
public AbstractMx2SwiftDtoCreator getMx2SwiftDtoCreator(String msgType) throws SwiftException {
if ("pacs008001".equals(msgType)) {
if ("pacs.008.001".equals(msgType)) {
return new Mx2SwiftDtoCCTCreator();
} else if ("pacs009001".equals(msgType)){
} else if ("pacs.009.001".equals(msgType)){
return new Mx2SwiftDtoFICTCreator();
}else if("camt054001".equals(msgType)){
}else if("camt.054.001".equals(msgType)){
return new Mx2SwiftDtoBTCDCNCreator();
} else if("camt053001".equals(msgType)){
} else if("camt.053.001".equals(msgType)){
return new Mx2SwiftDtoBTCSCreator();
} else {
throw new SwiftException("Invalid message type");
......
package com.brilliance.swift.mx2swiftdto.custcdttsf;
import com.alibaba.fastjson.JSONObject;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2swiftdto.AbstractMx2SwiftDtoCreator;
import com.brilliance.swift.mx2swiftdto.Mx2SwiftDtoContextIdentifier;
import com.brilliance.swift.util.DateUtil;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.util.XmlUtil;
import com.brilliance.swift.vo.SwiftDto;
import com.brilliance.swift.vo.VoCustomerCreditTransfer;
import com.brilliance.swift.vo.common.*;
import com.prowidesoftware.swift.model.mx.dic.Instruction4Code;
import com.brilliance.swift.vo.common.CcyFormatAmount;
import com.brilliance.swift.vo.common.ChargeInfo;
import org.dom4j.Document;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.io.File;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Date;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
......@@ -27,8 +26,6 @@ public class Mx2SwiftDtoCCTCreator extends AbstractMx2SwiftDtoCreator {
private VoCustomerCreditTransfer customerCreditTransfer = null;
private String defaultFormate = "yyyy-MM-dd HH:mm:ss,SSS";
@Override
public void preProcess() throws SwiftException {
document = (Document)context.get(Mx2SwiftDtoContextIdentifier.MX_XMl_DOCUMENT, true);
......@@ -36,151 +33,26 @@ public class Mx2SwiftDtoCCTCreator extends AbstractMx2SwiftDtoCreator {
appHdrParentElementName = parentElementMaps.get("AppHdr");
grpHdrParentElementName = parentElementMaps.get("GrpHdr");
bodyHdrParentElementName = parentElementMaps.get("CdtTrfTxInf");
customerCreditTransfer = new VoCustomerCreditTransfer();
}
@Override
public void appHeader() throws SwiftException {
super.appHeader();
swiftHeader.setMessageType("pacs.008.001");
String version = (String)context.get(Mx2SwiftDtoContextIdentifier.MX_VERSION, true);
swiftHeader.setVersion(StringUtil.isEmpty(version)?"09":version);
customerCreditTransfer.setSwiftHeader(swiftHeader);
}
@Override
public void groupHeader() throws SwiftException {
PartyDto instgAgtParty = agtConvertPartyDto(grpHdrParentElementName, document, "GrpHdr.SttlmInf.InstgRmbrsmntAgt", "GrpHdr.SttlmInf.InstgRmbrsmntAgtAcct");
PartyDto instdAgtParty = agtConvertPartyDto(grpHdrParentElementName, document, "GrpHdr.SttlmInf.InstdRmbrsmntAgt", "GrpHdr.SttlmInf.InstdRmbrsmntAgtAcct");
PartyDto thridAgtParty = agtConvertPartyDto(grpHdrParentElementName, document, "GrpHdr.SttlmInf.ThrdRmbrsmntAgt", "GrpHdr.SttlmInf.ThrdRmbrsmntAgtAcct");
PartyAccount settleAccount = acctConvertPartyAcct(grpHdrParentElementName, document, "GrpHdr.SttlmInf.SttlmAcct");
customerCreditTransfer.setInstgAgtParty(instgAgtParty);
customerCreditTransfer.setInstdAgtParty(instdAgtParty);
customerCreditTransfer.setThridAgtParty(thridAgtParty);
customerCreditTransfer.setSettleAccount(settleAccount);
}
@Override
public void messageBody() throws SwiftException {
try {
TransactionReference txnRef = new TransactionReference();
txnRef.setInstructionId(getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.PmtId.InstrId"));
txnRef.setEndToEndId(getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.PmtId.EndToEndId"));
txnRef.setUetr(getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.PmtId.UETR"));
customerCreditTransfer.setTxnRef(txnRef);
//party
PartyDto debitParty = convertPartyDto(bodyHdrParentElementName, document, "CdtTrfTxInf.Dbtr", "CdtTrfTxInf.DbtrAcct");
PartyDto debitAgtParty = agtConvertPartyDto(bodyHdrParentElementName, document, "CdtTrfTxInf.DbtrAgt", "CdtTrfTxInf.DbtrAgtAcct");
PartyDto intrmyAgtParty = agtConvertPartyDto(bodyHdrParentElementName, document, "CdtTrfTxInf.IntrmyAgt1", "CdtTrfTxInf.IntrmyAgt1Acct");
PartyDto creditAgtParty = agtConvertPartyDto(bodyHdrParentElementName, document, "CdtTrfTxInf.CdtrAgt", "CdtTrfTxInf.CdtrAgtAcct");
PartyDto creditParty = convertPartyDto(bodyHdrParentElementName, document, "CdtTrfTxInf.Cdtr", "CdtTrfTxInf.CdtrAcct");
PartyDto preInstgAgtParty = agtConvertPartyDto(bodyHdrParentElementName, document, "CdtTrfTxInf.PrvsInstgAgt1", "CdtTrfTxInf.PrvsInstgAgt1Acct");
customerCreditTransfer.setDebitParty(debitParty);
customerCreditTransfer.setDebitAgtParty(debitAgtParty);
customerCreditTransfer.setIntrmyAgtParty(intrmyAgtParty);
customerCreditTransfer.setCreditAgtParty(creditAgtParty);
customerCreditTransfer.setCreditParty(creditParty);
customerCreditTransfer.setPreInstgAgtParty(preInstgAgtParty);
//debitDate
String dbtDtTmStr = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.SttlmTmIndctn.DbtDtTm");
if (StringUtil.isNotEmpty(dbtDtTmStr)) {
XMLGregorianCalendar dbtDtTm = DatatypeFactory.newInstance().newXMLGregorianCalendar(dbtDtTmStr);
Date debitDate = DateUtil.formatAndParseDate(dbtDtTm.toGregorianCalendar().getTime(), defaultFormate);
customerCreditTransfer.setDebitDate(debitDate);
}
//creditDate
String cdtDtTmStr = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.SttlmTmIndctn.CdtDtTm");
if (StringUtil.isNotEmpty(cdtDtTmStr)) {
XMLGregorianCalendar cdtDtTm = DatatypeFactory.newInstance().newXMLGregorianCalendar(cdtDtTmStr);
Date creditDate = DateUtil.formatAndParseDate(cdtDtTm.toGregorianCalendar().getTime(), defaultFormate);
customerCreditTransfer.setCreditDate(creditDate);
}
//clsDate
String clsDtTmStr = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.SttlmTmReq.CLSTm");
if (StringUtil.isNotEmpty(clsDtTmStr)) {
XMLGregorianCalendar clsDtTm = DatatypeFactory.newInstance().newXMLGregorianCalendar(clsDtTmStr);
Date clsDate = DateUtil.formatAndParseDate(clsDtTm.toGregorianCalendar().getTime(), defaultFormate);
customerCreditTransfer.setClsDate(clsDate);
}
//serviceLevel;
String svcLvlCode = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.PmtTpInf.SvcLvl.Cd");
String svcLvlPrtry = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.PmtTpInf.SvcLvl.Prtry");
if (StringUtil.isNotEmpty(svcLvlCode) || StringUtil.isNotEmpty(svcLvlPrtry)) {
ServiceLevel serviceLevel = new ServiceLevel();
if (StringUtil.isNotEmpty(svcLvlCode)) {
serviceLevel.setCode(ServiceLevelCode.valueOf(svcLvlCode));
}
serviceLevel.setProprietary(svcLvlPrtry);
customerCreditTransfer.setServiceLevel(serviceLevel);
}
//CategoryPurpose
String ctgyPurpCode = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.PmtTpInf.CtgyPurp.Cd");
String ctgyPurpPrtry = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.PmtTpInf.CtgyPurp.Prtry");
if (StringUtil.isNotEmpty(ctgyPurpCode) || StringUtil.isNotEmpty(ctgyPurpPrtry)) {
CategoryPurpose categoryPurpose = new CategoryPurpose();
if (StringUtil.isNotEmpty(ctgyPurpCode)) {
categoryPurpose.setCode(CategoryPurposeCode.valueOf(ctgyPurpCode));
}
categoryPurpose.setProprietary(ctgyPurpPrtry);
customerCreditTransfer.setCategoryPurpose(categoryPurpose);
}
//PurposeChoice
String purpCode = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.Purp.Cd");
String purpPrtry = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.Purp.Prtry");
if (StringUtil.isNotEmpty(purpCode) || StringUtil.isNotEmpty(purpPrtry)) {
PurposeChoice purposeChoice = new PurposeChoice();
purposeChoice.setCode(purpCode);
purposeChoice.setProprietary(purpPrtry);
customerCreditTransfer.setPurposeChoice(purposeChoice);
}
//settledDate settledCcyFormatAmount
String intrBkSttlmDtStr = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.IntrBkSttlmDt");
if (StringUtil.isNotEmpty(intrBkSttlmDtStr)) {
XMLGregorianCalendar intrBkSttlmDt = DatatypeFactory.newInstance().newXMLGregorianCalendar(intrBkSttlmDtStr);
Date settledDate = DateUtil.formatAndParseDate(intrBkSttlmDt.toGregorianCalendar().getTime(), defaultFormate);
customerCreditTransfer.setSettledDate(settledDate);
}
String intrBkSttlmCcy = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.IntrBkSttlmAmt@Ccy");
String intrBkSttlmAmtStr = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.IntrBkSttlmAmt");
if (StringUtil.isNotEmpty(intrBkSttlmCcy) && StringUtil.isNotEmpty(intrBkSttlmAmtStr)) {
CcyFormatAmount settledCfa = new CcyFormatAmount();
settledCfa.setCcy(intrBkSttlmCcy);
settledCfa.setAmt(new BigDecimal(intrBkSttlmAmtStr));
customerCreditTransfer.setSettledCcyFormatAmount(settledCfa);
}
//InstructedCcyFormatAmount
String instdAmtCcy = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.InstdAmt@Ccy");
String instdAmtStr = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.InstdAmt");
if (StringUtil.isNotEmpty(instdAmtCcy) && StringUtil.isNotEmpty(instdAmtStr)) {
CcyFormatAmount instdCfa = new CcyFormatAmount();
instdCfa.setCcy(instdAmtCcy);
instdCfa.setAmt(new BigDecimal(instdAmtStr));
customerCreditTransfer.setInstructedCcyFormatAmount(instdCfa);
}
//exchangeRate
String exchangeRateStr = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.XchgRate");
if (StringUtil.isNotEmpty(exchangeRateStr)) {
customerCreditTransfer.setExchangeRate(new BigDecimal(exchangeRateStr));
}
//RemittanceInformation
int ustrdCounts = getXmlNodeCounts(bodyHdrParentElementName, document, "CdtTrfTxInf.RmtInf.Ustrd");
if (ustrdCounts > 0) {
RemittanceInformation remittanceInformation = new RemittanceInformation();
for (int i=0; i<ustrdCounts; i++) {
String ustrd = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.RmtInf.Ustrd("+i+")");
remittanceInformation.addUnstructured(ustrd);
}
customerCreditTransfer.setRemittanceInfo(remittanceInformation);
}
//chargeFor chargeCcyFormatAmount
String chrgBr = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.ChrgBr");
if (StringUtil.isNotEmpty(chrgBr)) {
customerCreditTransfer.setChargeFor(ChargeForEnum.valueOf(chrgBr));
}
private void fillChargeInfos() {
int chargeInfoCount = getXmlNodeCounts(bodyHdrParentElementName, document, "CdtTrfTxInf.ChrgsInf");
if (chargeInfoCount > 0) {
List<ChargeInfo> chargeInfos = new ArrayList<>();
for (int i=0; i<chargeInfoCount; i++) {
ChargeInfo chargeInfo = new ChargeInfo();
String chrgAmtStr = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.ChrgsInf("+i+").Amt");
......@@ -192,49 +64,26 @@ public class Mx2SwiftDtoCCTCreator extends AbstractMx2SwiftDtoCreator {
chargeInfo.setAmt(chrgCfa);
}
chargeInfo.setPartyDto(agtConvertPartyDto(bodyHdrParentElementName, document, "CdtTrfTxInf.ChrgsInf("+i+").Agt", null));
customerCreditTransfer.addChargeInfo(chargeInfo);
}
}
//InstructionForCreditAgent
String instForCdtAgentCode = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.InstrForCdtrAgt.Cd");
String instForCdtAgentInstrInf = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.InstrForCdtrAgt.InstrInf");
if (StringUtil.isNotEmpty(instForCdtAgentCode) || StringUtil.isNotEmpty(instForCdtAgentInstrInf)) {
InstructionForCreditAgent instForCdtAgt = new InstructionForCreditAgent();
if (StringUtil.isNotEmpty(instForCdtAgentCode)) {
instForCdtAgt.setCode(ExternalCreditorAgentInstructionCode.valueOf(instForCdtAgentCode));
}
instForCdtAgt.setInstrInf(instForCdtAgentInstrInf);
customerCreditTransfer.setInstForCrdAgt(instForCdtAgt);
}
//InstructionForNextAgent
String instForNxtAgentCode = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.InstrForNxtAgt.Cd");
String instForNxtAgentInstrInf = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.InstrForNxtAgt.InstrInf");
if (StringUtil.isNotEmpty(instForNxtAgentCode) || StringUtil.isNotEmpty(instForNxtAgentInstrInf)) {
InstructionForNextAgent instForNxtAgt = new InstructionForNextAgent();
if (StringUtil.isNotEmpty(instForNxtAgentCode)) {
instForNxtAgt.setCode(Instruction4Code.valueOf(instForNxtAgentCode));
chargeInfos.add(chargeInfo);
}
instForNxtAgt.setInstrInf(instForNxtAgentInstrInf);
customerCreditTransfer.setInstForNxtAgt(instForNxtAgt);
}
//regulatoryReportings
int size = getXmlNodeCounts(bodyHdrParentElementName, document, "CdtTrfTxInf.RgltryRptg");
if (size > 0) {
for (int i=0; i<size; i++) {
String dtlsInf = getXmlNodeValue(bodyHdrParentElementName, document, "CdtTrfTxInf.RgltryRptg("+i+").Dtls.Inf");
customerCreditTransfer.addRegulatoryReporting(dtlsInf);
}
}
} catch (DatatypeConfigurationException e) {
throw new SwiftException("ERROR", e.getMessage());
} catch (ParseException e) {
throw new SwiftException("ERROR", e.getMessage());
maps.put("chargeInfos", chargeInfos);
}
}
@Override
public void postProcess() throws SwiftException {
try {
Map<String, Object> swiftHeader = new HashMap<>();
String messageType = (String)context.get(Mx2SwiftDtoContextIdentifier.MX_MESSAGETYPE, true);
swiftHeader.put("messageType", messageType);
String version = (String)context.get(Mx2SwiftDtoContextIdentifier.MX_VERSION, true);
swiftHeader.put("version", StringUtil.isEmpty(version)?"09":version);
maps.put("swiftHeader", swiftHeader);
String propertyFileName = messageType.replace(".", "") + ".Properties";
readPropertyFile(propertyFileName);
fillChargeInfos();//配置文件无法满足Charge Info的赋值,写函数方法特殊处理
String swiftGsonStr = new JSONObject(maps).toJSONString();
customerCreditTransfer = (VoCustomerCreditTransfer) SwiftDto.fromJson(swiftGsonStr);
context.set(Mx2SwiftDtoContextIdentifier.MX_TO_SWIFTDTO_OBJ, customerCreditTransfer);
String outputFilePath = (String)context.get(Mx2SwiftDtoContextIdentifier.MX_TO_SWIFTDTO_OUTPUT_FILE_PATH, true);
if (StringUtil.isNotEmpty(outputFilePath)) {
......@@ -244,6 +93,4 @@ public class Mx2SwiftDtoCCTCreator extends AbstractMx2SwiftDtoCreator {
throw new SwiftException("ERROR", e.getMessage());
}
}
}
......@@ -15,7 +15,6 @@ import org.apache.commons.lang3.Validate;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.*;
public abstract class AbstractSwiftDto2MtCreator implements SwiftDto2MtCreator{
......@@ -69,51 +68,99 @@ public abstract class AbstractSwiftDto2MtCreator implements SwiftDto2MtCreator{
public void withBlock1() throws SwiftException {
SwiftBlock1 block1 = new SwiftBlock1();
SwiftDto swiftDto = (SwiftDto)context.get(SwiftDto2MtContextIdentifier.SWIFT_DTO_OBJ);
String mtIoType = (String)context.get(SwiftDto2MtContextIdentifier.MT_IO_TYPE, true);
if ("O".equalsIgnoreCase(mtIoType)) {
block1.setLogicalTerminal(processBicCode(swiftDto.getSwiftHeader().getReceiverBic()));
String senderBic = (String)context.get(Mx2MtConstants.SENDERS_ADDRESS, true);
if (StringUtil.isEmpty(senderBic) && swiftDto.getSwiftHeader() != null) {
senderBic = swiftDto.getSwiftHeader().getSenderBic();
}
String receiverBic = (String)context.get(Mx2MtConstants.RECEIVERS_ADDRESS, true);
if (StringUtil.isEmpty(receiverBic) && swiftDto.getSwiftHeader() != null) {
receiverBic = swiftDto.getSwiftHeader().getReceiverBic();
}
String applicationMode = (String)context.get(Mx2MtConstants.APPLICATION_MODE, true);
if ("O".equalsIgnoreCase(applicationMode)) {
block1.setLogicalTerminal(processBicCode(receiverBic));
} else {
block1.setLogicalTerminal(processBicCode(swiftDto.getSwiftHeader().getSenderBic()));
block1.setLogicalTerminal(processBicCode(senderBic));
}
block1.setSessionNumber(getRandomNumber(4));
block1.setSequenceNumber(getRandomNumber(6));
block1.setSessionNumber(getRandomNumber(4));//mapping文档中给的是0000
block1.setSequenceNumber(getRandomNumber(6));//mapping文档中给的是000000
context.get(SwiftMessage.class).setBlock1(block1);
}
@Override
public void withBlock2() throws SwiftException {
SwiftDto swiftDto = (SwiftDto)context.get(SwiftDto2MtContextIdentifier.SWIFT_DTO_OBJ);
String mtIoType = (String)context.get(SwiftDto2MtContextIdentifier.MT_IO_TYPE, true);
String messagePriority = MessagePriority.NORM.equals(swiftDto.getSwiftHeader().getMessagePriority()) ? "N" : "U";
if ("O".equalsIgnoreCase(mtIoType)) {
String senderBic = (String)context.get(Mx2MtConstants.SENDERS_ADDRESS, true);
if (StringUtil.isEmpty(senderBic) && swiftDto.getSwiftHeader() != null) {
senderBic = swiftDto.getSwiftHeader().getSenderBic();
}
String receiverBic = (String)context.get(Mx2MtConstants.RECEIVERS_ADDRESS, true);
if (StringUtil.isEmpty(receiverBic) && swiftDto.getSwiftHeader() != null) {
receiverBic = swiftDto.getSwiftHeader().getReceiverBic();
}
String messagePriority = (String)context.get(Mx2MtConstants.MESSAGE_PRIORITY, true);
if (StringUtil.isEmpty(messagePriority) && swiftDto.getSwiftHeader() != null) {
messagePriority = MessagePriority.NORM.equals(swiftDto.getSwiftHeader().getMessagePriority()) ? "N" : "U";
}
Date inputDate = (Date)context.get(Mx2MtConstants.INTPUT_DATE, true);
if (inputDate == null && swiftDto.getSwiftHeader() != null) {
inputDate = swiftDto.getSwiftHeader().getCreateDate();
}
Date outputDate = (Date)context.get(Mx2MtConstants.OUTPUT_DATE, true);
if (outputDate == null) {
outputDate = new Date();
}
String applicationMode = (String)context.get(Mx2MtConstants.APPLICATION_MODE, true);
if ("O".equalsIgnoreCase(applicationMode)) {
SwiftBlock2Output block2 = new SwiftBlock2Output();
block2.setMessageType(getMtType());
block2.setSenderInputTime(DateUtil.format(swiftDto.getSwiftHeader().getCreateDate(), "HHmm"));
block2.setMIRDate(DateUtil.format(swiftDto.getSwiftHeader().getCreateDate(), "yyMMdd"));
block2.setMIRLogicalTerminal(processBicCode(swiftDto.getSwiftHeader().getSenderBic()));
block2.setSenderInputTime(DateUtil.format(inputDate, "HHmm"));
block2.setMIRDate(DateUtil.format(inputDate, "yyMMdd"));
block2.setMIRLogicalTerminal(processBicCode(senderBic));
block2.setMIRSessionNumber(getRandomNumber(4));
block2.setMIRSequenceNumber(getRandomNumber(6));
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date());
calendar.setTime(outputDate);
block2.setReceiverOutputDateTime(calendar);
block2.setMessagePriority(messagePriority);
context.get(SwiftMessage.class).setBlock2(block2);
} else {
SwiftBlock2Input block2 = new SwiftBlock2Input();
block2.setMessageType(getMtType());
block2.setReceiverAddress(processBicCode(swiftDto.getSwiftHeader().getReceiverBic()));
block2.setReceiverAddress(processBicCode(receiverBic));
block2.setMessagePriority(messagePriority);
if ("U".equalsIgnoreCase(messagePriority)) {
block2.setDeliveryMonitoring("1");
}
context.get(SwiftMessage.class).setBlock2(block2);
}
}
@Override
public void withBlock3() throws SwiftException {
SwiftDto swiftDto = (SwiftDto)context.get(SwiftDto2MtContextIdentifier.SWIFT_DTO_OBJ);
List<Tag> tags = new ArrayList<>();
SwiftBlock3 block3 = new SwiftBlock3();
tags.add(new Tag("108", new SimpleDateFormat("yyMMddHHmmssSSSS").format(Calendar.getInstance().getTime())));
block3.setTags(tags);
String block3_103 = (String)context.get(Mx2MtConstants.BLOCK3_103, true);
if (StringUtil.isNotEmpty(block3_103)) {
tags.add(new Tag("103", block3_103));
}
String block3_108 = (String)context.get(Mx2MtConstants.BLOCK3_108, true);
if (StringUtil.isNotEmpty(block3_108)) {
tags.add(new Tag("108", block3_108));
}
String block3_165 = (String)context.get(Mx2MtConstants.BLOCK3_165, true);
if (StringUtil.isNotEmpty(block3_165)) {
tags.add(new Tag("165", block3_165));
}
String block3_433 = (String)context.get(Mx2MtConstants.BLOCK3_433, true);
if (StringUtil.isNotEmpty(block3_433)) {
tags.add(new Tag("433", block3_433));
}
String block3_434 = (String)context.get(Mx2MtConstants.BLOCK3_434, true);
if (StringUtil.isNotEmpty(block3_434)) {
tags.add(new Tag("434", block3_434));
}
context.get(SwiftMessage.class).setBlock3(block3);
}
......@@ -133,7 +180,20 @@ public abstract class AbstractSwiftDto2MtCreator implements SwiftDto2MtCreator{
@Override
public void withBlock5() throws SwiftException {
SwiftBlock5 swiftBlock5 = new SwiftBlock5();
Boolean block5_TNG = (Boolean)context.get(Mx2MtConstants.BLOCK5_TNG, true);
if (Boolean.TRUE.equals(block5_TNG)) {
swiftBlock5.setTag(SwiftBlock5Field.TNG, null);
}
Boolean block5_PDE = (Boolean)context.get(Mx2MtConstants.BLOCK5_PDE, true);
SwiftDto swiftDto = (SwiftDto)context.get(SwiftDto2MtContextIdentifier.SWIFT_DTO_OBJ);
if (!Boolean.TRUE.equals(block5_PDE) && swiftDto.getSwiftHeader() != null) {
block5_PDE = swiftDto.getSwiftHeader().getPossibleDuplicate();
}
if (Boolean.TRUE.equals(block5_PDE)) {
swiftBlock5.setPDE();
}
context.get(SwiftMessage.class).setBlock5(swiftBlock5);
}
@Override
......
......@@ -8,8 +8,6 @@ public class SwiftDto2MtContextIdentifier {
public static final String SWIFT_DTO_OBJ = "swift.dto.obj";
public static final String MT_IO_TYPE = "mt.io.type";
public static final String CD_60F = "PRCD";
public static final String CD_60M = "ITBD";
......
package com.brilliance.swift.swiftdto2mt;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.swiftdto2mt.mt103.SwiftDto2Mt103Creator;
import com.brilliance.swift.swiftdto2mt.mt202.SwiftDto2Mt202Creator;
......@@ -8,13 +9,28 @@ import com.brilliance.swift.swiftdto2mt.mt940950.SwiftDto2Mt940950Creator;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.vo.SwiftDto;
import java.util.Map;
public class SwiftDto2MtCreatorManager {
public String swiftDto2Mt(SwiftDto swiftDto, String fileOutputPath, String mtIoType) throws SwiftException {
public String swiftDto2Mt(SwiftDto swiftDto, String fileOutputPath, Map<String, Object> extraMap) throws SwiftException {
SwiftDto2MtContext context = new SwiftDto2MtContext();
context.set(SwiftDto2MtContextIdentifier.SWIFT_DTO_OBJ, swiftDto);
context.set(SwiftDto2MtContextIdentifier.MT_OUTPUT_FILE_PATH, fileOutputPath);
context.set(SwiftDto2MtContextIdentifier.MT_IO_TYPE, StringUtil.isEmpty(mtIoType)?"O":mtIoType);
String applicationMode = "O";//代表是收报,默认值
if (extraMap != null) {
applicationMode = (String) extraMap.get(Mx2MtConstants.APPLICATION_MODE);
if (StringUtil.isEmpty(applicationMode)) {
String bnkBic = (String)extraMap.get("bnkBic");//得到本行的bicCode
if (StringUtil.isNotEmpty(bnkBic)) {
if (bnkBic.equals(swiftDto.getSwiftHeader().getSenderBic())) {
applicationMode = "I";//如果发报行和本行bic一样,表示是发报
}
}
}
}
context.putAll(extraMap);
context.set(Mx2MtConstants.APPLICATION_MODE, applicationMode);
AbstractSwiftDto2MtCreator creator = getCreator(swiftDto.getSwiftHeader().getMessageType());
creator.setContext(context);
creator.preProcess();
......
......@@ -7,6 +7,8 @@ import com.brilliance.swift.swiftdto2mt.SwiftDto2MtTagGenerate;
import com.brilliance.swift.swiftdto2mt.mt103.impl.*;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.vo.VoCustomerCreditTransfer;
import com.brilliance.swift.vo.common.ServiceLevel;
import com.brilliance.swift.vo.common.ServiceLevelCode;
import com.brilliance.swift.vo.common.TransactionReference;
import com.prowidesoftware.swift.model.SwiftBlock3;
import com.prowidesoftware.swift.model.SwiftMessage;
......@@ -22,6 +24,15 @@ public class SwiftDto2Mt103Creator extends AbstractSwiftDto2MtCreator {
super.withBlock3();
SwiftBlock3 block3 = context.get(SwiftMessage.class).getBlock3();
VoCustomerCreditTransfer customerCreditTransfer = (VoCustomerCreditTransfer)context.get(SwiftDto2MtContextIdentifier.SWIFT_DTO_OBJ, true);
ServiceLevel serviceLevel = customerCreditTransfer.getServiceLevel();
if (serviceLevel != null) {
if (ServiceLevelCode.G001.equals(serviceLevel.getCode())
|| ServiceLevelCode.G002.equals(serviceLevel.getCode())
|| ServiceLevelCode.G003.equals(serviceLevel.getCode())
|| ServiceLevelCode.G004.equals(serviceLevel.getCode())) {
block3.getTags().add(new Tag("111", serviceLevel.getCode().value().substring(1)));
}
}
TransactionReference txnRef = customerCreditTransfer.getTxnRef();
if (txnRef != null && StringUtil.isNotEmpty(txnRef.getUetr())) {
block3.getTags().add(new Tag("121", txnRef.getUetr()));
......
......@@ -19,7 +19,14 @@ public class Tag36Generate extends AbstractSwiftDto2MtTagGenerate {
SwiftMessage swiftMessage = context.get(SwiftMessage.class);
List<Tag> tags = swiftMessage.getBlock4().getTags();
if (customerCreditTransfer.getExchangeRate() != null) {
String exchangeRateStr = String.valueOf(customerCreditTransfer.getExchangeRate()).replace(".", ",");
String exchangeRateStr = String.valueOf(customerCreditTransfer.getExchangeRate());
if (exchangeRateStr.startsWith("-")) {
exchangeRateStr = exchangeRateStr.replace("-", "");
}
if(exchangeRateStr.indexOf(".") > 0){//去掉小数点后不需要的0
exchangeRateStr = exchangeRateStr.replaceAll("0+?$", "");
}
exchangeRateStr = exchangeRateStr.replace(".", ",");//小数点替换成,
tags.add(new Tag(name, exchangeRateStr));
}
}
......
......@@ -26,6 +26,8 @@ public class SwiftHeader {
private MessagePriority messagePriority;
private Boolean possibleDuplicate;
private List<SwiftHeader> relatedSwiftHeaders;
public String getSenderBic() {
......@@ -110,6 +112,14 @@ public class SwiftHeader {
this.messagePriority = messagePriority;
}
public Boolean getPossibleDuplicate() {
return possibleDuplicate;
}
public void setPossibleDuplicate(Boolean possibleDuplicate) {
this.possibleDuplicate = possibleDuplicate;
}
public List<SwiftHeader> getRelatedSwiftHeaderList() {
if (relatedSwiftHeaders == null) {
relatedSwiftHeaders = new ArrayList<>();
......
......@@ -30,7 +30,7 @@ public class VoCustomerCreditTransfer extends SwiftDto {
protected CcyFormatAmount settledCcyFormatAmount;
protected CcyFormatAmount InstructedCcyFormatAmount;
protected CcyFormatAmount instructedCcyFormatAmount;
protected BigDecimal exchangeRate;
......@@ -115,11 +115,11 @@ public class VoCustomerCreditTransfer extends SwiftDto {
}
public CcyFormatAmount getInstructedCcyFormatAmount() {
return InstructedCcyFormatAmount;
return instructedCcyFormatAmount;
}
public void setInstructedCcyFormatAmount(CcyFormatAmount instructedCcyFormatAmount) {
InstructedCcyFormatAmount = instructedCcyFormatAmount;
instructedCcyFormatAmount = instructedCcyFormatAmount;
}
public BigDecimal getExchangeRate() {
......
......@@ -22,7 +22,7 @@
"ccy": "USD",
"amt": 23453.127
},
"InstructedCcyFormatAmount": {
"instructedCcyFormatAmount": {
"ccy": "EUR",
"amt": 1345.12
},
......
......@@ -18,7 +18,8 @@
<BizMsgIdr>TBEXO12345</BizMsgIdr>
<MsgDefIdr>pacs.008.001.09</MsgDefIdr>
<BizSvc>swift.cbprplus.02</BizSvc>
<CreDt>2020-09-08T10:10:47+08:00</CreDt>
<CreDt>2020-09-08T10:10:47+07:00</CreDt>
<PssblDplct>true</PssblDplct>
</AppHdr>
<Doc:Document xmlns:Doc="urn:iso:std:iso:20022:tech:xsd:pacs.008.001.09">
<Doc:FIToFICstmrCdtTrf>
......@@ -68,7 +69,7 @@
<Doc:CdtDtTm>2022-03-13T22:30:42.112+07:00</Doc:CdtDtTm>
</Doc:SttlmTmIndctn>
<Doc:SttlmTmReq>
<Doc:CLSTm>2022-03-13T21:21:42.112+07:00</Doc:CLSTm>
<Doc:CLSTm>21:21:42.112+07:00</Doc:CLSTm>
</Doc:SttlmTmReq>
<Doc:InstrForCdtrAgt>
<Doc:Cd>TELB</Doc:Cd>
......@@ -95,7 +96,7 @@
<Doc:IntrBkSttlmAmt Ccy="USD">23453.127</Doc:IntrBkSttlmAmt>
<Doc:IntrBkSttlmDt>2022-03-13+08:00</Doc:IntrBkSttlmDt>
<Doc:InstdAmt Ccy="EUR">1345.12</Doc:InstdAmt>
<Doc:XchgRate>17.4357135422</Doc:XchgRate>
<Doc:XchgRate>10.124500</Doc:XchgRate>
<Doc:ChrgBr>DEBT</Doc:ChrgBr>
<Doc:ChrgsInf>
<Doc:Amt Ccy="USD">12.43</Doc:Amt>
......
#MX Model convert SwiftDto JSON
swiftHeader.senderBic=#APP.AppHdr.Fr.FIId.FinInstnId.BICFI?#APP.AppHdr.Fr.OrgId.Id.OrgId.AnyBIC
swiftHeader.receiverBic=#APP.AppHdr.To.FIId.FinInstnId.BICFI?#APP.AppHdr.To.OrgId.Id.OrgId.AnyBIC
swiftHeader.messageId=#APP.AppHdr.BizMsgIdr
swiftHeader.messageDefId=#APP.AppHdr.MsgDefIdr
swiftHeader.businessService=#APP.AppHdr.BizSvc
swiftHeader.createDate=#APP.AppHdr.CreDt&DATE
swiftHeader.messagePriority=#APP.AppHdr.Prty
swiftHeader.possibleDuplicate=#APP.AppHdr.PssblDplct
txnRef.instructionId=#BODY.CdtTrfTxInf.PmtId.InstrId
txnRef.endToEndId=#BODY.CdtTrfTxInf.PmtId.EndToEndId
txnRef.uetr=#BODY.CdtTrfTxInf.PmtId.UETR
debitDate=#BODY.CdtTrfTxInf.SttlmTmIndctn.DbtDtTm&DATE
creditDate=#BODY.CdtTrfTxInf.SttlmTmIndctn.CdtDtTm&DATE
clsDate=#BODY.CdtTrfTxInf.SttlmTmReq.CLSTm&DATE
serviceLevel.code=#BODY.CdtTrfTxInf.PmtTpInf.SvcLvl.Cd
serviceLevel.proprietary=#BODY.CdtTrfTxInf.PmtTpInf.SvcLvl.Prtry
categoryPurpose.code=#BODY.CdtTrfTxInf.PmtTpInf.CtgyPurp.Cd
categoryPurpose.proprietary=#BODY.CdtTrfTxInf.PmtTpInf.CtgyPurp.Prtry
purposeChoice.code=#BODY.CdtTrfTxInf.Purp.Cd
purposeChoice.proprietary=#BODY.CdtTrfTxInf.Purp.Prtry
settledDate=#BODY.CdtTrfTxInf.IntrBkSttlmDt&DATE
settledCcyFormatAmount.ccy=#BODY.CdtTrfTxInf.IntrBkSttlmAmt@Ccy
settledCcyFormatAmount.amt=#BODY.CdtTrfTxInf.IntrBkSttlmAmt&BigDecimal
instructedCcyFormatAmount.ccy=#BODY.CdtTrfTxInf.InstdAmt@Ccy
instructedCcyFormatAmount.amt=#BODY.CdtTrfTxInf.InstdAmt&BigDecimal
exchangeRate=#BODY.CdtTrfTxInf.XchgRate&BigDecimal
###settleAccount
settleAccount.account=#GRP.GrpHdr.SttlmInf.SttlmAcct.Id.Othr.Id
settleAccount.ibanAcct=#GRP.GrpHdr.SttlmInf.SttlmAcct.Id.IBAN
settleAccount.acctCcy=#GRP.GrpHdr.SttlmInf.SttlmAcct.Ccy
settleAccount.acctName=#GRP.GrpHdr.SttlmInf.SttlmAcct.Nm
settleAccount.acctType.code=#GRP.GrpHdr.SttlmInf.SttlmAcct.Tp.Cd
settleAccount.acctType.proprietary=#GRP.GrpHdr.SttlmInf.SttlmAcct.Tp.Prtry
settleAccount.acctSehemeType.code=#GRP.GrpHdr.SttlmInf.SttlmAcct.Id.Othr.SchmeNm.Cd
settleAccount.acctSehemeType.proprietary=#GRP.GrpHdr.SttlmInf.SttlmAcct.Id.Othr.SchmeNm.Prtry
###debitParty
debitParty.partyBic=#BODY.CdtTrfTxInf.Dbtr.Id.OrgId.AnyBIC
debitParty.partyName=#BODY.CdtTrfTxInf.Dbtr.Nm
debitParty.addressList=#BODY.CdtTrfTxInf.Dbtr.PstlAdr.AdrLine&List<String>
debitParty.partyAcct.account=#BODY.CdtTrfTxInf.DbtrAcct.Id.Othr.Id
debitParty.partyAcct.ibanAcct=#BODY.CdtTrfTxInf.DbtrAcct.Id.IBAN
debitParty.partyAcct.acctCcy=#BODY.CdtTrfTxInf.DbtrAcct.Ccy
debitParty.partyAcct.acctName=#BODY.CdtTrfTxInf.DbtrAcct.Nm
debitParty.partyAcct.acctType.code=#BODY.CdtTrfTxInf.DbtrAcct.Tp.Cd
debitParty.partyAcct.acctType.proprietary=#BODY.CdtTrfTxInf.DbtrAcct.Tp.Prtry
debitParty.partyAcct.acctSehemeType.code=#BODY.CdtTrfTxInf.DbtrAcct.Id.Othr.SchmeNm.Cd
debitParty.partyAcct.acctSehemeType.proprietary=#BODY.CdtTrfTxInf.DbtrAcct.Id.Othr.SchmeNm.Prtry
###debitAgtParty
debitAgtParty.partyBic=#BODY.CdtTrfTxInf.DbtrAgt.FinInstnId.BICFI
debitAgtParty.partyName=#BODY.CdtTrfTxInf.DbtrAgt.FinInstnId.Nm
debitAgtParty.addressList=#BODY.CdtTrfTxInf.DbtrAgt.FinInstnId.PstlAdr.AdrLine&List<String>
debitAgtParty.partyAcct.account=#BODY.CdtTrfTxInf.DbtrAgtAcct.Id.Othr.Id
debitAgtParty.partyAcct.ibanAcct=#BODY.CdtTrfTxInf.DbtrAgtAcct.Id.IBAN
debitAgtParty.partyAcct.acctCcy=#BODY.CdtTrfTxInf.DbtrAgtAcct.Ccy
debitAgtParty.partyAcct.acctName=#BODY.CdtTrfTxInf.DbtrAgtAcct.Nm
debitAgtParty.partyAcct.acctType.code=#BODY.CdtTrfTxInf.DbtrAgtAcct.Tp.Cd
debitAgtParty.partyAcct.acctType.proprietary=#BODY.CdtTrfTxInf.DbtrAgtAcct.Tp.Prtry
debitAgtParty.partyAcct.acctSehemeType.code=#BODY.CdtTrfTxInf.DbtrAgtAcct.Id.Othr.SchmeNm.Cd
debitAgtParty.partyAcct.acctSehemeType.proprietary=#BODY.CdtTrfTxInf.DbtrAgtAcct.Id.Othr.SchmeNm.Prtry
debitAgtParty.clrSysMmb.code=#BODY.CdtTrfTxInf.DbtrAgt.FinInstnId.ClrSysMmbId.ClrSysId.Cd
debitAgtParty.clrSysMmb.proprietary=#BODY.CdtTrfTxInf.DbtrAgt.FinInstnId.ClrSysMmbId.ClrSysId.Prtry
debitAgtParty.clrSysMmb.id=#BODY.CdtTrfTxInf.DbtrAgt.FinInstnId.ClrSysMmbId.MmbId
###instgAgtParty
instgAgtParty.partyBic=#GRP.GrpHdr.SttlmInf.InstgRmbrsmntAgt.FinInstnId.BICFI
instgAgtParty.partyName=#GRP.GrpHdr.SttlmInf.InstgRmbrsmntAgt.FinInstnId.Nm
instgAgtParty.addressList=#GRP.GrpHdr.SttlmInf.InstgRmbrsmntAgt.FinInstnId.PstlAdr.AdrLine&List<String>
instgAgtParty.partyAcct.account=#GRP.GrpHdr.SttlmInf.InstgRmbrsmntAgtAcct.Id.Othr.Id
instgAgtParty.partyAcct.ibanAcct=#GRP.GrpHdr.SttlmInf.InstgRmbrsmntAgtAcct.Id.IBAN
instgAgtParty.partyAcct.acctCcy=#GRP.GrpHdr.SttlmInf.InstgRmbrsmntAgtAcct.Ccy
instgAgtParty.partyAcct.acctName=#GRP.GrpHdr.SttlmInf.InstgRmbrsmntAgtAcct.Nm
instgAgtParty.partyAcct.acctType.code=#GRP.GrpHdr.SttlmInf.InstgRmbrsmntAgtAcct.Tp.Cd
instgAgtParty.partyAcct.acctType.proprietary=#GRP.GrpHdr.SttlmInf.InstgRmbrsmntAgtAcct.Tp.Prtry
instgAgtParty.partyAcct.acctSehemeType.code=#GRP.GrpHdr.SttlmInf.InstgRmbrsmntAgtAcct.Id.Othr.SchmeNm.Cd
instgAgtParty.partyAcct.acctSehemeType.proprietary=#GRP.GrpHdr.SttlmInf.InstgRmbrsmntAgtAcct.Id.Othr.SchmeNm.Prtry
instgAgtParty.clrSysMmb.code=#GRP.GrpHdr.SttlmInf.InstgRmbrsmntAgt.FinInstnId.ClrSysMmbId.ClrSysId.Cd
instgAgtParty.clrSysMmb.proprietary=#GRP.GrpHdr.SttlmInf.InstgRmbrsmntAgt.FinInstnId.ClrSysMmbId.ClrSysId.Prtry
instgAgtParty.clrSysMmb.id=#GRP.GrpHdr.SttlmInf.InstgRmbrsmntAgt.FinInstnId.ClrSysMmbId.MmbId
###instdAgtParty
instdAgtParty.partyBic=#GRP.GrpHdr.SttlmInf.InstdRmbrsmntAgt.FinInstnId.BICFI
instdAgtParty.partyName=#GRP.GrpHdr.SttlmInf.InstdRmbrsmntAgt.FinInstnId.Nm
instdAgtParty.addressList=#GRP.GrpHdr.SttlmInf.InstdRmbrsmntAgt.FinInstnId.PstlAdr.AdrLine&List<String>
instdAgtParty.partyAcct.account=#GRP.GrpHdr.SttlmInf.InstdRmbrsmntAgtAcct.Id.Othr.Id
instdAgtParty.partyAcct.ibanAcct=#GRP.GrpHdr.SttlmInf.InstdRmbrsmntAgtAcct.Id.IBAN
instdAgtParty.partyAcct.acctCcy=#GRP.GrpHdr.SttlmInf.InstdRmbrsmntAgtAcct.Ccy
instdAgtParty.partyAcct.acctName=#GRP.GrpHdr.SttlmInf.InstdRmbrsmntAgtAcct.Nm
instdAgtParty.partyAcct.acctType.code=#GRP.GrpHdr.SttlmInf.InstdRmbrsmntAgtAcct.Tp.Cd
instdAgtParty.partyAcct.acctType.proprietary=#GRP.GrpHdr.SttlmInf.InstdRmbrsmntAgtAcct.Tp.Prtry
instdAgtParty.partyAcct.acctSehemeType.code=#GRP.GrpHdr.SttlmInf.InstdRmbrsmntAgtAcct.Id.Othr.SchmeNm.Cd
instdAgtParty.partyAcct.acctSehemeType.proprietary=#GRP.GrpHdr.SttlmInf.InstdRmbrsmntAgtAcct.Id.Othr.SchmeNm.Prtry
instdAgtParty.clrSysMmb.code=#GRP.GrpHdr.SttlmInf.InstdRmbrsmntAgt.FinInstnId.ClrSysMmbId.ClrSysId.Cd
instdAgtParty.clrSysMmb.proprietary=#GRP.GrpHdr.SttlmInf.InstdRmbrsmntAgt.FinInstnId.ClrSysMmbId.ClrSysId.Prtry
instdAgtParty.clrSysMmb.id=#GRP.GrpHdr.SttlmInf.InstdRmbrsmntAgt.FinInstnId.ClrSysMmbId.MmbId
###thridAgtParty
thridAgtParty.partyBic=#GRP.GrpHdr.SttlmInf.ThrdRmbrsmntAgt.FinInstnId.BICFI
thridAgtParty.partyName=#GRP.GrpHdr.SttlmInf.ThrdRmbrsmntAgt.FinInstnId.Nm
thridAgtParty.addressList=#GRP.GrpHdr.SttlmInf.ThrdRmbrsmntAgt.FinInstnId.PstlAdr.AdrLine&List<String>
thridAgtParty.partyAcct.account=#GRP.GrpHdr.SttlmInf.ThrdRmbrsmntAgtAcct.Id.Othr.Id
thridAgtParty.partyAcct.ibanAcct=#GRP.GrpHdr.SttlmInf.ThrdRmbrsmntAgtAcct.Id.IBAN
thridAgtParty.partyAcct.acctCcy=#GRP.GrpHdr.SttlmInf.ThrdRmbrsmntAgtAcct.Ccy
thridAgtParty.partyAcct.acctName=#GRP.GrpHdr.SttlmInf.ThrdRmbrsmntAgtAcct.Nm
thridAgtParty.partyAcct.acctType.code=#GRP.GrpHdr.SttlmInf.ThrdRmbrsmntAgtAcct.Tp.Cd
thridAgtParty.partyAcct.acctType.proprietary=#GRP.GrpHdr.SttlmInf.ThrdRmbrsmntAgtAcct.Tp.Prtry
thridAgtParty.partyAcct.acctSehemeType.code=#GRP.GrpHdr.SttlmInf.ThrdRmbrsmntAgtAcct.Id.Othr.SchmeNm.Cd
thridAgtParty.partyAcct.acctSehemeType.proprietary=#GRP.GrpHdr.SttlmInf.ThrdRmbrsmntAgtAcct.Id.Othr.SchmeNm.Prtry
thridAgtParty.clrSysMmb.code=#GRP.GrpHdr.SttlmInf.ThrdRmbrsmntAgt.FinInstnId.ClrSysMmbId.ClrSysId.Cd
thridAgtParty.clrSysMmb.proprietary=#GRP.GrpHdr.SttlmInf.ThrdRmbrsmntAgt.FinInstnId.ClrSysMmbId.ClrSysId.Prtry
thridAgtParty.clrSysMmb.id=#GRP.GrpHdr.SttlmInf.ThrdRmbrsmntAgt.FinInstnId.ClrSysMmbId.MmbId
###intrmyAgtParty
intrmyAgtParty.partyBic=#BODY.CdtTrfTxInf.IntrmyAgt1.FinInstnId.BICFI
intrmyAgtParty.partyName=#BODY.CdtTrfTxInf.IntrmyAgt1.FinInstnId.Nm
intrmyAgtParty.addressList=#BODY.CdtTrfTxInf.IntrmyAgt1.FinInstnId.PstlAdr.AdrLine&List<String>
intrmyAgtParty.partyAcct.account=#BODY.CdtTrfTxInf.IntrmyAgt1Acct.Id.Othr.Id
intrmyAgtParty.partyAcct.ibanAcct=#BODY.CdtTrfTxInf.IntrmyAgt1Acct.Id.IBAN
intrmyAgtParty.partyAcct.acctCcy=#BODY.CdtTrfTxInf.IntrmyAgt1Acct.Ccy
intrmyAgtParty.partyAcct.acctName=#BODY.CdtTrfTxInf.IntrmyAgt1Acct.Nm
intrmyAgtParty.partyAcct.acctType.code=#BODY.CdtTrfTxInf.IntrmyAgt1Acct.Tp.Cd
intrmyAgtParty.partyAcct.acctType.proprietary=#BODY.CdtTrfTxInf.IntrmyAgt1Acct.Tp.Prtry
intrmyAgtParty.partyAcct.acctSehemeType.code=#BODY.CdtTrfTxInf.IntrmyAgt1Acct.Id.Othr.SchmeNm.Cd
intrmyAgtParty.partyAcct.acctSehemeType.proprietary=#BODY.CdtTrfTxInf.IntrmyAgt1Acct.Id.Othr.SchmeNm.Prtry
intrmyAgtParty.clrSysMmb.code=#BODY.CdtTrfTxInf.IntrmyAgt1.FinInstnId.ClrSysMmbId.ClrSysId.Cd
intrmyAgtParty.clrSysMmb.proprietary=#BODY.CdtTrfTxInf.IntrmyAgt1.FinInstnId.ClrSysMmbId.ClrSysId.Prtry
intrmyAgtParty.clrSysMmb.id=#BODY.CdtTrfTxInf.IntrmyAgt1.FinInstnId.ClrSysMmbId.MmbId
###creditAgtParty
creditAgtParty.partyBic=#BODY.CdtTrfTxInf.CdtrAgt.FinInstnId.BICFI
creditAgtParty.partyName=#BODY.CdtTrfTxInf.CdtrAgt.FinInstnId.Nm
creditAgtParty.addressList=#BODY.CdtTrfTxInf.CdtrAgt.FinInstnId.PstlAdr.AdrLine&List<String>
creditAgtParty.partyAcct.account=#BODY.CdtTrfTxInf.CdtrAgtAcct.Id.Othr.Id
creditAgtParty.partyAcct.ibanAcct=#BODY.CdtTrfTxInf.CdtrAgtAcct.Id.IBAN
creditAgtParty.partyAcct.acctCcy=#BODY.CdtTrfTxInf.CdtrAgtAcct.Ccy
creditAgtParty.partyAcct.acctName=#BODY.CdtTrfTxInf.CdtrAgtAcct.Nm
creditAgtParty.partyAcct.acctType.code=#BODY.CdtTrfTxInf.CdtrAgtAcct.Tp.Cd
creditAgtParty.partyAcct.acctType.proprietary=#BODY.CdtTrfTxInf.CdtrAgtAcct.Tp.Prtry
creditAgtParty.partyAcct.acctSehemeType.code=#BODY.CdtTrfTxInf.CdtrAgtAcct.Id.Othr.SchmeNm.Cd
creditAgtParty.partyAcct.acctSehemeType.proprietary=#BODY.CdtTrfTxInf.CdtrAgtAcct.Id.Othr.SchmeNm.Prtry
creditAgtParty.clrSysMmb.code=#BODY.CdtTrfTxInf.CdtrAgt.FinInstnId.ClrSysMmbId.ClrSysId.Cd
creditAgtParty.clrSysMmb.proprietary=#BODY.CdtTrfTxInf.CdtrAgt.FinInstnId.ClrSysMmbId.ClrSysId.Prtry
creditAgtParty.clrSysMmb.id=#BODY.CdtTrfTxInf.CdtrAgt.FinInstnId.ClrSysMmbId.MmbId
###creditParty
creditParty.partyBic=#BODY.CdtTrfTxInf.Cdtr.Id.OrgId.AnyBIC
creditParty.partyName=#BODY.CdtTrfTxInf.Cdtr.Nm
creditParty.addressList=#BODY.CdtTrfTxInf.Cdtr.PstlAdr.AdrLine&List<String>
creditParty.partyAcct.account=#BODY.CdtTrfTxInf.CdtrAcct.Id.Othr.Id
creditParty.partyAcct.ibanAcct=#BODY.CdtTrfTxInf.CdtrAcct.Id.IBAN
creditParty.partyAcct.acctCcy=#BODY.CdtTrfTxInf.CdtrAcct.Ccy
creditParty.partyAcct.acctName=#BODY.CdtTrfTxInf.CdtrAcct.Nm
creditParty.partyAcct.acctType.code=#BODY.CdtTrfTxInf.CdtrAcct.Tp.Cd
creditParty.partyAcct.acctType.proprietary=#BODY.CdtTrfTxInf.CdtrAcct.Tp.Prtry
creditParty.partyAcct.acctSehemeType.code=#BODY.CdtTrfTxInf.CdtrAcct.Id.Othr.SchmeNm.Cd
creditParty.partyAcct.acctSehemeType.proprietary=#BODY.CdtTrfTxInf.CdtrAcct.Id.Othr.SchmeNm.Prtry
remittanceInfo.unstructured=#BODY.CdtTrfTxInf.RmtInf.Ustrd&List<String>
chargeFor=#BODY.CdtTrfTxInf.ChrgBr
###################################
###preInstgAgtParty
preInstgAgtParty.partyBic=#BODY.CdtTrfTxInf.PrvsInstgAgt1.FinInstnId.BICFI
preInstgAgtParty.partyName=#BODY.CdtTrfTxInf.PrvsInstgAgt1.FinInstnId.Nm
preInstgAgtParty.addressList=#BODY.CdtTrfTxInf.PrvsInstgAgt1.FinInstnId.PstlAdr.AdrLine&List<String>
preInstgAgtParty.partyAcct.account=#BODY.CdtTrfTxInf.PrvsInstgAgt1Acct.Id.Othr.Id
preInstgAgtParty.partyAcct.ibanAcct=#BODY.CdtTrfTxInf.PrvsInstgAgt1Acct.Id.IBAN
preInstgAgtParty.partyAcct.acctCcy=#BODY.CdtTrfTxInf.PrvsInstgAgt1Acct.Ccy
preInstgAgtParty.partyAcct.acctName=#BODY.CdtTrfTxInf.PrvsInstgAgt1Acct.Nm
preInstgAgtParty.partyAcct.acctType.code=#BODY.CdtTrfTxInf.PrvsInstgAgt1Acct.Tp.Cd
preInstgAgtParty.partyAcct.acctType.proprietary=#BODY.CdtTrfTxInf.PrvsInstgAgt1Acct.Tp.Prtry
preInstgAgtParty.partyAcct.acctSehemeType.code=#BODY.CdtTrfTxInf.PrvsInstgAgt1Acct.Id.Othr.SchmeNm.Cd
preInstgAgtParty.partyAcct.acctSehemeType.proprietary=#BODY.CdtTrfTxInf.PrvsInstgAgt1Acct.Id.Othr.SchmeNm.Prtry
preInstgAgtParty.clrSysMmb.code=#BODY.CdtTrfTxInf.PrvsInstgAgt1.FinInstnId.ClrSysMmbId.ClrSysId.Cd
preInstgAgtParty.clrSysMmb.proprietary=#BODY.CdtTrfTxInf.PrvsInstgAgt1.FinInstnId.ClrSysMmbId.ClrSysId.Prtry
preInstgAgtParty.clrSysMmb.id=#BODY.CdtTrfTxInf.PrvsInstgAgt1.FinInstnId.ClrSysMmbId.MmbId
instForCrdAgt.code=#BODY.CdtTrfTxInf.InstrForCdtrAgt.Cd
instForCrdAgt.instrInf=#BODY.CdtTrfTxInf.InstrForCdtrAgt.InstrInf
instForNxtAgt.code=#BODY.CdtTrfTxInf.InstrForNxtAgt.Cd
instForNxtAgt.instrInf=#BODY.CdtTrfTxInf.InstrForNxtAgt.InstrInf
regulatoryReportings=#BODY.CdtTrfTxInf.RgltryRptg*Dtls.Inf&String
package com.brilliance.mt2mx.pacs008001;
import com.alibaba.fastjson.JSONObject;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.util.DateUtil;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.util.XmlUtil;
import com.brilliance.swift.vo.common.CcyFormatAmount;
import com.brilliance.swift.vo.common.ChargeInfo;
import org.apache.commons.io.FileUtils;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Test {
static String appHdr = "Envelope";
static String grpHdr = "Envelope.Document.FIToFICstmrCdtTrf";
static String bodyHdr = "Envelope.Document.FIToFICstmrCdtTrf";
static String defaultFormate = "yyyy-MM-dd HH:mm:ss,SSS";
public static Object getXmlPathValue(Document document, String xmlPath) throws DatatypeConfigurationException, IOException {
xmlPath = xmlPath.replace("#APP", appHdr).replace("#GRP", grpHdr).replace("#BODY", bodyHdr);
Object value = null;
if (xmlPath.indexOf("*") > -1) { //出现多个值
String beginPath = xmlPath.substring(0, xmlPath.indexOf("*"));
String endPath = xmlPath.substring(xmlPath.indexOf("*")+1);
String type = "String";
if (endPath.indexOf("&") > -1) {
type = endPath.substring(endPath.indexOf("&")+1);
endPath = endPath.substring(0, endPath.indexOf("&"));
}
int count = XmlUtil.getChildrenCount(document, beginPath, null);
if (count > 0) {
if ("String".equalsIgnoreCase(type)) {
List<String> list = new ArrayList<>();
for (int i=0; i<count; i++) {
String xmlValue = XmlUtil.getXmlNodeValue(document, beginPath+"("+i+")."+endPath);
list.add(xmlValue);
}
value = list;
} else if ("BigDecimal".equalsIgnoreCase(type)) {
List<BigDecimal> list = new ArrayList<>();
for (int i=0; i<count; i++) {
String xmlValue = XmlUtil.getXmlNodeValue(document, beginPath+"("+i+")."+endPath);
list.add(new BigDecimal(xmlValue));
}
value = list;
}
}
} else if (xmlPath.indexOf("&") > -1) { //数据类型
String type = xmlPath.substring(xmlPath.indexOf("&")+1);
xmlPath = xmlPath.substring(0, xmlPath.indexOf("&"));
String xmlValue = XmlUtil.getXmlNodeValue(document, xmlPath);
if ("DATE".equalsIgnoreCase(type) && StringUtil.isNotEmpty(xmlValue)) {
XMLGregorianCalendar dtTm = DatatypeFactory.newInstance().newXMLGregorianCalendar(xmlValue);
value = DateUtil.format(dtTm.toGregorianCalendar().getTime(), defaultFormate);
} else if ("BigDecimal".equalsIgnoreCase(type) && StringUtil.isNotEmpty(xmlValue)) {
value = new BigDecimal(xmlValue);
} else if ("List<String>".equalsIgnoreCase(type) && StringUtil.isNotEmpty(xmlValue)) {
int count = XmlUtil.getChildrenCount(document, xmlPath, null);
if (count > 0) {
List<String> list = new ArrayList<>();
for (int i=0; i<count; i++) {
xmlValue = XmlUtil.getXmlNodeValue(document, xmlPath+"("+i+")");
list.add(xmlValue);
}
value = list;
}
}
} else {
value = XmlUtil.getXmlNodeValue(document, xmlPath);
}
return value;
}
public static void main(String[] args) throws Exception {
String mt103 = SwiftTransfer.mt2Mx(
/*String mt103 = SwiftTransfer.mt2Mx(
new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\Mt103.txt"),
"d:/test/pacs00800109.xml", null);
System.out.println(mt103);
System.out.println(mt103);*/
String xmlStr = FileUtils.readFileToString(new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftXml\\MxPacs00800109.xml"));
Document document = DocumentHelper.parseText(xmlStr);
Map<String, Object> maps = new HashMap<>();
Map<String, Object> swiftHeader = new HashMap<>();
swiftHeader.put("messageType", "pacs.008.001");
swiftHeader.put("version", "09");
maps.put("swiftHeader", swiftHeader);
File propertyFile = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\template\\mx2swiftdto\\pacs008001.Properties");
List<String> properties = FileUtils.readLines(propertyFile);
if (properties.size() > 0) {
for (String property : properties) {
if (property.startsWith("#")) {
continue;//过滤注释
}
String[] strArr = property.split("=");
if (strArr.length != 2) {
continue;//过滤掉不符合规则的配置
}
String key = strArr[0];
String xmlPath = strArr[1];
Object xmlValue = getXmlPathValue(document, xmlPath);
if (xmlValue == null) continue;
String[] keys = key.split("\\.");
if (keys.length == 1) {
maps.put(keys[0], xmlValue); //如果只有一个节点,直接put值
} else { //如果节点值超过1个,先赋值第一个节点,再循环赋值,最后一个节点直接put值。
Map<String, Object> keyMap = null;
if (maps.containsKey(keys[0])) {
keyMap = (Map<String, Object>)maps.get(keys[0]);
} else {
keyMap = new HashMap<>();
maps.put(keys[0], keyMap);
}
for (int i=1; i<keys.length; i++) {
if (i == keys.length-1) {
keyMap.put(keys[i], xmlValue);
break;
}
if (!keyMap.containsKey(keys[i])) {
keyMap.put(keys[i], new HashMap<>());
}
keyMap = (Map<String, Object>)keyMap.get(keys[i]);
}
}
}
}
List<ChargeInfo> chargeInfos = new ArrayList<>();
CcyFormatAmount ccyFormatAmount = new CcyFormatAmount();
ccyFormatAmount.setCcy("USD");
ccyFormatAmount.setAmt(new BigDecimal("13.45"));
ChargeInfo chargeInfo = new ChargeInfo();
chargeInfo.setAmt(ccyFormatAmount);
CcyFormatAmount ccyFormatAmount1 = new CcyFormatAmount();
ccyFormatAmount1.setCcy("USD");
ccyFormatAmount1.setAmt(new BigDecimal("23.56"));
ChargeInfo chargeInfo1 = new ChargeInfo();
chargeInfo1.setAmt(ccyFormatAmount1);
chargeInfos.add(chargeInfo);
chargeInfos.add(chargeInfo1);
maps.put("chargeInfos", chargeInfos);
/*Map<String, Object> resultMap = new HashMap<>();
Map<String, Object> txnRef = new HashMap<>();
txnRef.put("instructionId", "GTBEXO12345");
txnRef.put("endToEndId", "GTBEXO12345");
txnRef.put("uetr", "8a562c67-ca16-48ba-b074-65581be6f001");
resultMap.put("txnRef", txnRef);
Map<String, Object> swiftHeader = new HashMap<>();
swiftHeader.put("messageType", "pacs.008.001");
swiftHeader.put("version", "09");
resultMap.put("swiftHeader", swiftHeader);*/
//SwiftDto swiftDto = SwiftDto.fromJson(new JSONObject(maps).toJSONString());
System.out.println(new JSONObject(maps).toJSONString());
String mt = SwiftTransfer.swiftDto2Mt(new JSONObject(maps).toJSONString(), null, null);
System.out.println(mt);
}
}
......@@ -10,6 +10,7 @@ public class Test {
public static void main(String[] args) {
SwiftDto swiftDto = SwiftTransfer.mx2SwiftDto(new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftXml\\MxPacs00800109.xml"), "d:/test/CustomerCreditTransfer.json", null);
System.out.println(swiftDto);
String mt = SwiftTransfer.swiftDto2Mt(swiftDto.toJson(), null, null);
System.out.println(mt);
}
}
......@@ -8,7 +8,7 @@ public class Test {
public static void main(String[] args) {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftJson\\CustomerCreditTransfer.json");
String mtStr = SwiftTransfer.swiftDto2Mt(file, null, "I");
String mtStr = SwiftTransfer.swiftDto2Mt(file, null, null);
System.out.println(mtStr);
}
}
......@@ -8,13 +8,13 @@ public class Test {
public static void test202() {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftJson\\FinancialInstitutionCreditTransfer.json");
String mtStr = SwiftTransfer.swiftDto2Mt(file, null, "O");
String mtStr = SwiftTransfer.swiftDto2Mt(file, null, null);
System.out.println(mtStr);
}
public static void test202Cov() {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftJson\\FinancialInstitutionCreditTransfer_COV.json");
String mtStr = SwiftTransfer.swiftDto2Mt(file, null, "O");
String mtStr = SwiftTransfer.swiftDto2Mt(file, null, null);
System.out.println(mtStr);
}
......
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