Commit 57dda6f4 by chengzhuoshen

MX2MT:camt06000105转mt920

parent 8d648a52
...@@ -4,8 +4,6 @@ import com.brilliance.swift.exception.SwiftException; ...@@ -4,8 +4,6 @@ import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2SwiftDto.Mt2SwiftDtoCreateManager; import com.brilliance.swift.mt2SwiftDto.Mt2SwiftDtoCreateManager;
import com.brilliance.swift.mx2map.Mx2MapCreatorManager; import com.brilliance.swift.mx2map.Mx2MapCreatorManager;
import com.brilliance.swift.mx2mt.Mx2MtCreatorManager; import com.brilliance.swift.mx2mt.Mx2MtCreatorManager;
import com.brilliance.swift.mx2swiftdto.Mx2SwiftDtoCreatorManager;
import com.brilliance.swift.swiftdto2mt.SwiftDto2MtCreatorManager;
import com.brilliance.swift.swiftdto2mx.SwiftDto2MxCreatorManager; import com.brilliance.swift.swiftdto2mx.SwiftDto2MxCreatorManager;
import com.brilliance.swift.util.StringUtil; import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.util.XmlUtil; import com.brilliance.swift.util.XmlUtil;
...@@ -23,94 +21,6 @@ import java.util.Map; ...@@ -23,94 +21,6 @@ import java.util.Map;
public class SwiftTransfer { public class SwiftTransfer {
/** /**
* SWIFTDTO transfer MT
* @param file
* @param fileOutputPath
* @param extraMap
* @return
* @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, extraMap);
} catch (IOException e) {
throw new SwiftException("ERROR", e.getMessage());
}
}
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, extraMap);
}
/**
* MT transfer SWIFTDTO
* @param file
* @param outPutFilePath
* @param extraMap
* @return
* @throws SwiftException
*/
public static SwiftDto mt2SwiftDto(File file, String outPutFilePath, Map<String, Object> extraMap) throws SwiftException {
try{
String mtStr = FileUtils.readFileToString(file);
return new Mt2SwiftDtoCreateManager().convert(mtStr, outPutFilePath, extraMap);
} catch (IOException e) {
throw new SwiftException("ERROR", e.getMessage());
}
}
public static SwiftDto mt2SwiftDto(String mtStr, String outPutFilePath, Map<String, Object> extraMap) throws SwiftException {
return new Mt2SwiftDtoCreateManager().convert(mtStr, outPutFilePath, extraMap);
}
/**
* MX transfer SWIFTDTO
* @param file
* @param outPutFilePath
* @param extraMap
* @return
* @throws SwiftException
*/
public static SwiftDto mx2SwiftDto(File file, String outPutFilePath, Map<String, Object> extraMap) throws SwiftException {
try{
String xmlStr = FileUtils.readFileToString(file);
return new Mx2SwiftDtoCreatorManager().convert(xmlStr, outPutFilePath, extraMap);
} catch (IOException e) {
throw new SwiftException("ERROR", e.getMessage());
}
}
public static SwiftDto mx2SwiftDto(String xmlStr, String outPutFilePath, Map<String, Object> extraMap) throws SwiftException {
return new Mx2SwiftDtoCreatorManager().convert(xmlStr, outPutFilePath, extraMap);
}
/**
* SWIFTDTO transfer MX
* @param file
* @param fileOutputPath
* @return
* @throws SwiftException
*/
public static String swiftDto2Mx(File file, String fileOutputPath) throws SwiftException {
try {
String gsonStr = FileUtils.readFileToString(file);
SwiftDto swiftDto = SwiftDto.fromJson(gsonStr);
return new SwiftDto2MxCreatorManager().swiftDto2Mx(swiftDto, fileOutputPath);
} catch (IOException e) {
throw new SwiftException("ERROR", e.getMessage());
}
}
public static String swiftDto2Mx(String gsonStr, String fileOutputPath) throws SwiftException{
SwiftDto swiftDto = SwiftDto.fromJson(gsonStr);
return new SwiftDto2MxCreatorManager().swiftDto2Mx(swiftDto, fileOutputPath);
}
/**
* MX TRANSFER MT * MX TRANSFER MT
*/ */
public static String mx2Mt(File file, String outPutFilePath, Map<String, Object> extraMap) throws SwiftException { public static String mx2Mt(File file, String outPutFilePath, Map<String, Object> extraMap) throws SwiftException {
......
...@@ -41,6 +41,8 @@ public class Mx2MtConstants { ...@@ -41,6 +41,8 @@ public class Mx2MtConstants {
public static final String MT_TYPE_296 = "296"; public static final String MT_TYPE_296 = "296";
public static final String MT_TYPE_920 = "920";
public static final String MT_TYPE_942 = "942"; public static final String MT_TYPE_942 = "942";
public static final String MT_TYPE_941 = "941"; public static final String MT_TYPE_941 = "941";
......
...@@ -3,7 +3,6 @@ package com.brilliance.swift.mt2SwiftDto.camt053001.impl; ...@@ -3,7 +3,6 @@ package com.brilliance.swift.mt2SwiftDto.camt053001.impl;
import com.brilliance.swift.exception.SwiftException; import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mt2SwiftDto.AbstractMt2SwiftDtoParseFields; import com.brilliance.swift.mt2SwiftDto.AbstractMt2SwiftDtoParseFields;
import com.brilliance.swift.util.DateUtil; import com.brilliance.swift.util.DateUtil;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.vo.BankToCustomerStatement; import com.brilliance.swift.vo.BankToCustomerStatement;
import com.brilliance.swift.vo.common.BankTransactionCodeStructure; import com.brilliance.swift.vo.common.BankTransactionCodeStructure;
import com.brilliance.swift.vo.common.CcyFormatAmount; import com.brilliance.swift.vo.common.CcyFormatAmount;
...@@ -13,14 +12,9 @@ import com.prowidesoftware.swift.model.Tag; ...@@ -13,14 +12,9 @@ import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field61; import com.prowidesoftware.swift.model.field.Field61;
import com.prowidesoftware.swift.model.field.Field86; import com.prowidesoftware.swift.model.field.Field86;
import com.prowidesoftware.swift.model.mt.AbstractMT; import com.prowidesoftware.swift.model.mt.AbstractMT;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author zh * @author zh
...@@ -67,7 +61,7 @@ public class Camt053001Parse61Field extends AbstractMt2SwiftDtoParseFields { ...@@ -67,7 +61,7 @@ public class Camt053001Parse61Field extends AbstractMt2SwiftDtoParseFields {
String txnType = field61.getTransactionType(); String txnType = field61.getTransactionType();
String identificationCode = field61.getIdentificationCode(); String identificationCode = field61.getIdentificationCode();
String mxCode = getDomainCodeByIdentyCode(identificationCode); /*String mxCode = getDomainCodeByIdentyCode(identificationCode);
if (StringUtil.isNotEmpty(mxCode)) { if (StringUtil.isNotEmpty(mxCode)) {
BankTransactionCodeStructure bankTransactionCodeStructure = new BankTransactionCodeStructure(); BankTransactionCodeStructure bankTransactionCodeStructure = new BankTransactionCodeStructure();
String[] mxCodes = mxCode.split("_"); String[] mxCodes = mxCode.split("_");
...@@ -75,11 +69,11 @@ public class Camt053001Parse61Field extends AbstractMt2SwiftDtoParseFields { ...@@ -75,11 +69,11 @@ public class Camt053001Parse61Field extends AbstractMt2SwiftDtoParseFields {
bankTransactionCodeStructure.setFamilyCode(mxCodes[1]); bankTransactionCodeStructure.setFamilyCode(mxCodes[1]);
bankTransactionCodeStructure.setSubFamilyCode(mxCodes[2]); bankTransactionCodeStructure.setSubFamilyCode(mxCodes[2]);
reportEntry.setBankTransactionCodeStructure(bankTransactionCodeStructure); reportEntry.setBankTransactionCodeStructure(bankTransactionCodeStructure);
} else { } else {*/
BankTransactionCodeStructure bankTransactionCodeStructure = new BankTransactionCodeStructure(); BankTransactionCodeStructure bankTransactionCodeStructure = new BankTransactionCodeStructure();
bankTransactionCodeStructure.setCode(txnType + identificationCode); bankTransactionCodeStructure.setCode(txnType + identificationCode);
reportEntry.setBankTransactionCodeStructure(bankTransactionCodeStructure); reportEntry.setBankTransactionCodeStructure(bankTransactionCodeStructure);
} /*}*/
reportEntry.setEndToEndId(field61.getReferenceForTheAccountOwner()); reportEntry.setEndToEndId(field61.getReferenceForTheAccountOwner());
reportEntry.setAcctSvcrRef(field61.getReferenceOfTheAccountServicingInstitution()); reportEntry.setAcctSvcrRef(field61.getReferenceOfTheAccountServicingInstitution());
reportEntry.setAddtlTxInf(field61.getSupplementaryDetails()); reportEntry.setAddtlTxInf(field61.getSupplementaryDetails());
...@@ -95,35 +89,4 @@ public class Camt053001Parse61Field extends AbstractMt2SwiftDtoParseFields { ...@@ -95,35 +89,4 @@ public class Camt053001Parse61Field extends AbstractMt2SwiftDtoParseFields {
throw new SwiftException("ERROR", e.getMessage()); throw new SwiftException("ERROR", e.getMessage());
} }
} }
/**
* 得到Domain FamilyCode SubFamilyCode,从BankTransactionCode.Properties文件获取
* @return
*/
private String getDomainCodeByIdentyCode(String identyCode) {
try {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\BankTransactionCode.Properties");
List<String> strings = FileUtils.readLines(file);
Map<String, String> maps = new HashMap<>();
for (String s : strings) {
if (!s.startsWith("#")) {
String[] arr = s.split("=");
if (arr.length == 2) {
maps.put(arr[0].trim(), arr[1].trim());
}
}
}
String mxCode = "";
for (String key : maps.keySet()) {
if (maps.get(key).equals(identyCode)) {
mxCode = key;
break;
}
}
return mxCode;
} catch (IOException e) {
throw new SwiftException("ERROR", e.getMessage());
}
}
} }
package com.brilliance.swift.mx2map; package com.brilliance.swift.mx2map;
import com.brilliance.swift.util.StringUtil; import com.brilliance.swift.util.MessageUtil;
import com.brilliance.swift.util.SwiftTransferUtil;
import com.prowidesoftware.swift.model.mx.AbstractMX; import com.prowidesoftware.swift.model.mx.AbstractMX;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.Properties;
public abstract class AbstractMx2MapCreator implements Mx2MapCreator{ public abstract class AbstractMx2MapCreator implements Mx2MapCreator{
...@@ -14,8 +12,6 @@ public abstract class AbstractMx2MapCreator implements Mx2MapCreator{ ...@@ -14,8 +12,6 @@ public abstract class AbstractMx2MapCreator implements Mx2MapCreator{
protected AbstractMX abstractMX; protected AbstractMX abstractMX;
protected Properties keyProperties;
protected String localCode; protected String localCode;
protected Map<String, String> maps = new LinkedHashMap<>(); protected Map<String, String> maps = new LinkedHashMap<>();
...@@ -45,14 +41,6 @@ public abstract class AbstractMx2MapCreator implements Mx2MapCreator{ ...@@ -45,14 +41,6 @@ public abstract class AbstractMx2MapCreator implements Mx2MapCreator{
} }
protected String getPropertyValue(String key) { protected String getPropertyValue(String key) {
if (keyProperties == null) { return MessageUtil.getPropertyValue(localCode, key);
keyProperties = SwiftTransferUtil.getProperty(localCode);
}
String value = keyProperties.getProperty(key);
if (StringUtil.isEmpty(value)) {
return key;
} else {
return value;
}
} }
} }
...@@ -11,6 +11,7 @@ import com.brilliance.swift.mx2mt.mt202Retn.Mx2Mt205RetnCreator; ...@@ -11,6 +11,7 @@ import com.brilliance.swift.mx2mt.mt202Retn.Mx2Mt205RetnCreator;
import com.brilliance.swift.mx2mt.mt202cov202.Mx2Mt202Creator; import com.brilliance.swift.mx2mt.mt202cov202.Mx2Mt202Creator;
import com.brilliance.swift.mx2mt.mt210.Mx2Mt210Creator; import com.brilliance.swift.mx2mt.mt210.Mx2Mt210Creator;
import com.brilliance.swift.mx2mt.mt900910.Mx2Mt900910Creator; import com.brilliance.swift.mx2mt.mt900910.Mx2Mt900910Creator;
import com.brilliance.swift.mx2mt.mt920.Mx2Mt920Creator;
import com.brilliance.swift.mx2mt.mt940950.Mx2Mt940950Creator; import com.brilliance.swift.mx2mt.mt940950.Mx2Mt940950Creator;
import com.brilliance.swift.mx2mt.mt941942.Mx2Mt941942Creator; import com.brilliance.swift.mx2mt.mt941942.Mx2Mt941942Creator;
import com.brilliance.swift.mx2mt.mtn99.Mx2MtN99Creator; import com.brilliance.swift.mx2mt.mtn99.Mx2MtN99Creator;
...@@ -95,6 +96,8 @@ public class Mx2MtCreatorManager { ...@@ -95,6 +96,8 @@ public class Mx2MtCreatorManager {
return new Mx2Mt210Creator(); return new Mx2Mt210Creator();
} else if("pacs.002.001".equals(messageType)){ } else if("pacs.002.001".equals(messageType)){
return new Mx2MtN99Creator(); return new Mx2MtN99Creator();
} else if("camt.060.001".equals(messageType)){
return new Mx2Mt920Creator();
} else { } else {
throw new SwiftException("ERROR", "Invalid message type"); throw new SwiftException("ERROR", "Invalid message type");
} }
......
package com.brilliance.swift.mx2mt.mt920;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.mx2mt.AbstractMx2MtCreator;
import com.brilliance.swift.mx2mt.Mx2MtContextIdentifier;
import com.brilliance.swift.mx2mt.Mx2MtTagsGenerate;
import com.brilliance.swift.mx2mt.mt920.impl.*;
import com.brilliance.swift.util.XmlUtil;
import org.dom4j.Document;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class Mx2Mt920Creator extends AbstractMx2MtCreator {
@Override
public void preProcess() {
super.preProcess();
Document document = (Document)context.get(Mx2MtContextIdentifier.MX_XMl_DOCUMENT, true);
Map<String, String> parentElementMaps = XmlUtil.getParentElementMaps(document);
context.set(Mx2MtContextIdentifier.APPHDR_PARENT_ELEMENT_NAME, parentElementMaps.get("AppHdr"));
context.set(Mx2MtContextIdentifier.GRPHDR_PARENT_ELEMENT_NAME, parentElementMaps.get("GrpHdr"));
context.set(Mx2MtContextIdentifier.BODY_PARENT_ELEMENT_NAME, parentElementMaps.get("RptgReq"));
}
@Override
public List<Mx2MtTagsGenerate> getGenerateTagList() {
List<Mx2MtTagsGenerate> fieldsGenerateList = new ArrayList<>();
fieldsGenerateList.add(new Field20Generate());
Document document = (Document)context.get(Mx2MtContextIdentifier.MX_XMl_DOCUMENT, true);
String parentPath = (String)context.get(Mx2MtContextIdentifier.BODY_PARENT_ELEMENT_NAME, true);
int count = getXmlNodeCounts(parentPath, document, "RptgReq");
if (count > 0) {
for (int i=0; i<count; i++) {
fieldsGenerateList.add(new Field12Generate(i));
fieldsGenerateList.add(new Field25Generate(i));
fieldsGenerateList.add(new Field34DGenerate(i));
fieldsGenerateList.add(new Field34CGenerate(i));
}
}
return fieldsGenerateList;
}
@Override
protected String getMtType() {
return Mx2MtConstants.MT_TYPE_920;
}
}
package com.brilliance.swift.mx2mt.mt920.impl;
import com.brilliance.swift.constants.Mx2MtConstants;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtTagsGenerate;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.SwiftMessage;
import com.prowidesoftware.swift.model.Tag;
import java.util.List;
public class Field12Generate extends AbstractMx2MtTagsGenerate {
private static String NAME = "12";
private int index = -1; //存在多个域循环, 表示xml节点的下标.
public Field12Generate(int index) {
this.index = index;
}
@Override
public void tagGenerate() throws SwiftException {
if (index > -1) {
SwiftMessage swiftMessage = context.get(SwiftMessage.class);
List<Tag> tags = swiftMessage.getBlock4().getTags();
String msgNameId = getXmlNodeValue(bodyHdrParentElementName, document, "RptgReq(" + index + ").ReqdMsgNmId");
if (StringUtil.isNotEmpty(msgNameId)) {
String value = "";
if (msgNameId.startsWith("camt.053")) {
value = Mx2MtConstants.MT_TYPE_950;
} else if (msgNameId.startsWith("camt.052")) {
value = Mx2MtConstants.MT_TYPE_942;
} else if (msgNameId.contains(Mx2MtConstants.MT_TYPE_941)) {
value = Mx2MtConstants.MT_TYPE_941;
} else if (msgNameId.contains(Mx2MtConstants.MT_TYPE_942)) {
value = Mx2MtConstants.MT_TYPE_942;
} else if (msgNameId.contains(Mx2MtConstants.MT_TYPE_940)) {
value = Mx2MtConstants.MT_TYPE_940;
} else if (msgNameId.contains(Mx2MtConstants.MT_TYPE_950)) {
value = Mx2MtConstants.MT_TYPE_950;
}
if (StringUtil.isNotEmpty(value)) {
tags.add(new Tag(NAME, value));
}
}
}
}
}
package com.brilliance.swift.mx2mt.mt920.impl;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtTagsGenerate;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.SwiftMessage;
import com.prowidesoftware.swift.model.Tag;
import java.util.List;
public class Field20Generate extends AbstractMx2MtTagsGenerate {
private final static String NAME = "20";
@Override
public void tagGenerate() throws SwiftException {
SwiftMessage swiftMessage = context.get(SwiftMessage.class);
List<Tag> tags = swiftMessage.getBlock4().getTags();
String messageId = getXmlNodeValue(grpHdrParentElementName, document, "GrpHdr.MsgId");
if (StringUtil.isEmpty(messageId)) {
messageId = getXmlNodeValue(appHdrParentElementName, document, "AppHdr.BizMsgIdr");
}
if (StringUtil.isNotEmpty(messageId)) {
tags.add(new Tag(NAME, messageId));
}
}
}
package com.brilliance.swift.mx2mt.mt920.impl;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtTagsGenerate;
import com.brilliance.swift.util.StringUtil;
import com.prowidesoftware.swift.model.SwiftMessage;
import com.prowidesoftware.swift.model.Tag;
import java.util.List;
public class Field25Generate extends AbstractMx2MtTagsGenerate {
private static String NAME = "25";
private int index = -1; //存在多个域循环, 表示xml节点的下标.
public Field25Generate(int index) {
this.index = index;
}
@Override
public void tagGenerate() throws SwiftException {
if (index > -1) {
SwiftMessage swiftMessage = context.get(SwiftMessage.class);
List<Tag> tags = swiftMessage.getBlock4().getTags();
String iban = getXmlNodeValue(bodyHdrParentElementName, document, "RptgReq("+index+").Acct.Id.IBAN");
String acctId = getXmlNodeValue(bodyHdrParentElementName, document, "RptgReq("+index+").Acct.Id.Othr.Id");
String account = StringUtil.isNotEmpty(iban) ? iban : acctId;
if (StringUtil.isNotEmpty(account)) {
tags.add(new Tag(NAME, account));
}
}
}
}
package com.brilliance.swift.mx2mt.mt920.impl;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtTagsGenerate;
import com.brilliance.swift.util.NumberUtil;
import com.prowidesoftware.swift.model.SwiftMessage;
import com.prowidesoftware.swift.model.Tag;
import java.math.BigDecimal;
import java.util.List;
public class Field34CGenerate extends AbstractMx2MtTagsGenerate {
private static String NAME = "34";
private int index = -1; //存在多个域循环, 表示xml节点的下标.
public Field34CGenerate(int index) {
this.index = index;
}
@Override
public void tagGenerate() throws SwiftException {
if (index > -1) {
SwiftMessage swiftMessage = context.get(SwiftMessage.class);
List<Tag> tags = swiftMessage.getBlock4().getTags();
int floorLimtCount = getXmlNodeCounts(bodyHdrParentElementName, document, "RptgReq("+index+").ReqdTxTp.FlrLmt");
if (floorLimtCount > 0) {
for (int i=0; i<floorLimtCount; i++) {
String crdrIndicator = getXmlNodeValue(bodyHdrParentElementName, document, "RptgReq("+index+").ReqdTxTp.FlrLmt("+i+").CdtDbtInd");
String amt = getXmlNodeValue(bodyHdrParentElementName, document, "RptgReq("+index+").ReqdTxTp.FlrLmt("+i+").Amt");
String ccy = getXmlNodeValue(bodyHdrParentElementName, document, "RptgReq("+index+").ReqdTxTp.FlrLmt("+i+").Amt@Ccy");
if ("CRED".equals(crdrIndicator)) {
String value = ccy + "C" + NumberUtil.formatAmt(new BigDecimal(amt), ccy);
tags.add(new Tag(NAME, value));
break;
}
}
}
}
}
}
package com.brilliance.swift.mx2mt.mt920.impl;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2mt.AbstractMx2MtTagsGenerate;
import com.brilliance.swift.util.NumberUtil;
import com.prowidesoftware.swift.model.SwiftMessage;
import com.prowidesoftware.swift.model.Tag;
import java.math.BigDecimal;
import java.util.List;
public class Field34DGenerate extends AbstractMx2MtTagsGenerate {
private static String NAME = "34";
private int index = -1; //存在多个域循环, 表示xml节点的下标.
public Field34DGenerate(int index) {
this.index = index;
}
@Override
public void tagGenerate() throws SwiftException {
if (index > -1) {
SwiftMessage swiftMessage = context.get(SwiftMessage.class);
List<Tag> tags = swiftMessage.getBlock4().getTags();
int floorLimtCount = getXmlNodeCounts(bodyHdrParentElementName, document, "RptgReq("+index+").ReqdTxTp.FlrLmt");
if (floorLimtCount > 0) {
for (int i=0; i<floorLimtCount; i++) {
String crdrIndicator = getXmlNodeValue(bodyHdrParentElementName, document, "RptgReq("+index+").ReqdTxTp.FlrLmt("+i+").CdtDbtInd");
String amt = getXmlNodeValue(bodyHdrParentElementName, document, "RptgReq("+index+").ReqdTxTp.FlrLmt("+i+").Amt");
String ccy = getXmlNodeValue(bodyHdrParentElementName, document, "RptgReq("+index+").ReqdTxTp.FlrLmt("+i+").Amt@Ccy");
if ("DEBT".equals(crdrIndicator) || "BOTH".equals(crdrIndicator)) {
String value = ccy + "D" + NumberUtil.formatAmt(new BigDecimal(amt), ccy);
tags.add(new Tag(NAME, value));
break;
}
}
}
}
}
}
...@@ -8,19 +8,13 @@ import com.brilliance.swift.util.DateUtil; ...@@ -8,19 +8,13 @@ import com.brilliance.swift.util.DateUtil;
import com.brilliance.swift.util.NumberUtil; import com.brilliance.swift.util.NumberUtil;
import com.brilliance.swift.util.StringUtil; import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.vo.BankToCustomerStatement; import com.brilliance.swift.vo.BankToCustomerStatement;
import com.brilliance.swift.vo.common.BankTransactionCodeStructure;
import com.brilliance.swift.vo.common.CcyFormatAmount; import com.brilliance.swift.vo.common.CcyFormatAmount;
import com.brilliance.swift.vo.common.CdtDbtCode; import com.brilliance.swift.vo.common.CdtDbtCode;
import com.brilliance.swift.vo.common.ReportEntry; import com.brilliance.swift.vo.common.ReportEntry;
import com.prowidesoftware.swift.model.SwiftMessage; import com.prowidesoftware.swift.model.SwiftMessage;
import com.prowidesoftware.swift.model.Tag; import com.prowidesoftware.swift.model.Tag;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
public class Tag61Generate extends AbstractSwiftDto2MtTagGenerate { public class Tag61Generate extends AbstractSwiftDto2MtTagGenerate {
...@@ -42,7 +36,7 @@ public class Tag61Generate extends AbstractSwiftDto2MtTagGenerate { ...@@ -42,7 +36,7 @@ public class Tag61Generate extends AbstractSwiftDto2MtTagGenerate {
String drCrMark = ""; String drCrMark = "";
String amt = ""; String amt = "";
String ccy = ""; String ccy = "";
String txnCode = getTxnCode(reportEntry.getBankTransactionCodeStructure()); String txnCode = "NTRF";
String endToEndId = reportEntry.getEndToEndId(); String endToEndId = reportEntry.getEndToEndId();
String addtlTxInf = reportEntry.getAddtlTxInf(); String addtlTxInf = reportEntry.getAddtlTxInf();
String acctSvcrRef = reportEntry.getAcctSvcrRef(); String acctSvcrRef = reportEntry.getAcctSvcrRef();
...@@ -95,42 +89,4 @@ public class Tag61Generate extends AbstractSwiftDto2MtTagGenerate { ...@@ -95,42 +89,4 @@ public class Tag61Generate extends AbstractSwiftDto2MtTagGenerate {
throw new SwiftException("ERROR", e.getMessage()); throw new SwiftException("ERROR", e.getMessage());
} }
} }
/**
* 得到txntype+txnCode,从BankTransactionCode.Properties文件获取
* @return
*/
private String getTxnCode(BankTransactionCodeStructure bankTransactionCodeStructure) {
try {
if (bankTransactionCodeStructure == null) return "";
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\BankTransactionCode.Properties");
List<String> strings = FileUtils.readLines(file);
Map<String, String> maps = new HashMap<>();
for (String s : strings) {
if (!s.startsWith("#")) {
String[] arr = s.split("=");
if (arr.length == 2) {
maps.put(arr[0].trim(), arr[1].trim());
}
}
}
String txnCode = maps.get(bankTransactionCodeStructure.getDomianCode()
+ "_"
+ bankTransactionCodeStructure.getFamilyCode()
+ "_"
+ bankTransactionCodeStructure.getSubFamilyCode());
if (StringUtil.isNotEmpty(txnCode)) {
return "F"+txnCode;
} else {
String code = bankTransactionCodeStructure.getCode();
if (StringUtil.isNotEmpty(code) && code.length() > 4) {
return code.substring(0, 4);
}
//TODO
return "S940";
}
} catch (IOException e) {
throw new SwiftException("ERROR", e.getMessage());
}
}
} }
package com.brilliance.swift.util;
import com.brilliance.swift.exception.SwiftException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class MessageUtil {
private static Properties properties = null;
public static String getPropertyValue(String localCode, String key) {
try {
if (properties == null) {
String fileName = "/Messages_CN.properties";
if ("US".equals(localCode)) {
fileName = "/Messages_US.properties";
}
InputStream resourceAsStream = SwiftTransferUtil.class.getResourceAsStream(fileName);
properties = new Properties();
properties.load(resourceAsStream);
}
if (properties != null) {
return properties.getProperty(key, key);
}
return key;
} catch (IOException e) {
throw new SwiftException("ERROR", e.getMessage());
}
}
}
package com.brilliance.swift.util; package com.brilliance.swift.util;
import com.brilliance.swift.exception.SwiftException;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.FieldPosition; import java.text.FieldPosition;
import java.util.Properties;
public class NumberUtil { public class NumberUtil {
private static Properties properties = null;
public static String decimalFormat(String decimal) { public static String decimalFormat(String decimal) {
return NumberUtil.decimalFormat(decimal, 2); return NumberUtil.decimalFormat(decimal, 2);
...@@ -69,11 +77,20 @@ public class NumberUtil { ...@@ -69,11 +77,20 @@ public class NumberUtil {
return s.replace(".", ""); return s.replace(".", "");
} }
public static BigDecimal round(BigDecimal amt, int scale) {
if (amt == null)
amt = BigDecimal.ZERO;
if (scale < 0)
throw new IllegalArgumentException("The scale must be a positive integer or zero");
return amt.divide(BigDecimal.ONE, scale, 4);
}
public static String formatAmt(BigDecimal amt, String ccy) { public static String formatAmt(BigDecimal amt, String ccy) {
if (amt == null) { if (amt == null) {
throw new RuntimeException("Source Amt cannot be null."); throw new RuntimeException("Source Amt cannot be null.");
} }
int ccyDecimalNum = getCcyDecimalNum(ccy); int ccyDecimalNum = getCcyDecimalNum(ccy);
amt = round(amt, ccyDecimalNum);
String s = NumberUtil.decimalFormat(amt.toString(), ccyDecimalNum); String s = NumberUtil.decimalFormat(amt.toString(), ccyDecimalNum);
String pointSuffiex = "."; String pointSuffiex = ".";
for (int i=0; i<ccyDecimalNum; i++) { for (int i=0; i<ccyDecimalNum; i++) {
...@@ -86,10 +103,29 @@ public class NumberUtil { ...@@ -86,10 +103,29 @@ public class NumberUtil {
} }
} }
/**
* 从币种小数位数配置文件中获取币种对应的小数点位数
* 默认值是2
* @param ccy
* @return
*/
private static int getCcyDecimalNum(String ccy) { private static int getCcyDecimalNum(String ccy) {
int decimalNum = 2; try {
//TODO if (properties == null) {
return decimalNum; String fileName = "/CurrencyDecimalDigits.properties";
InputStream resourceAsStream = NumberUtil.class.getResourceAsStream(fileName);
properties = new Properties();
properties.load(resourceAsStream);
}
if (properties != null) {
String decimalNumStr = properties.getProperty(ccy, "2");
return Integer.parseInt(decimalNumStr);
}
return 2;
} catch (
IOException e) {
throw new SwiftException("ERROR", e.getMessage());
}
} }
} }
...@@ -2,7 +2,6 @@ package com.brilliance.swift.util; ...@@ -2,7 +2,6 @@ package com.brilliance.swift.util;
import cn.hutool.poi.excel.ExcelReader; import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil; import cn.hutool.poi.excel.ExcelUtil;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.vo.MxMtReasonCodeInfo; import com.brilliance.swift.vo.MxMtReasonCodeInfo;
import com.brilliance.swift.vo.SwiftTransferErrorInfo; import com.brilliance.swift.vo.SwiftTransferErrorInfo;
import com.brilliance.swift.vo.common.ClearingSystemMemberCode; import com.brilliance.swift.vo.common.ClearingSystemMemberCode;
...@@ -12,7 +11,6 @@ import com.brilliance.swift.vo.common.PersonIdentificationCode; ...@@ -12,7 +11,6 @@ import com.brilliance.swift.vo.common.PersonIdentificationCode;
import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
...@@ -677,19 +675,4 @@ public class SwiftTransferUtil { ...@@ -677,19 +675,4 @@ public class SwiftTransferUtil {
} }
return list; return list;
} }
public static Properties getProperty(String localCode) {
try {
String fileName = "/Messages_CN.properties";
if ("US".equals(localCode)) {
fileName = "/Messages_US.properties";
}
InputStream resourceAsStream = SwiftTransferUtil.class.getResourceAsStream(fileName);
Properties properties = new Properties();
properties.load(resourceAsStream);
return properties;
} catch (IOException e) {
throw new SwiftException("ERROR", e.getMessage());
}
}
} }
#DOMIANCODE_FAMILYCODE_SUBFAMILYCODE = MT TRANSACTION CODE
SECU_CASH_BKFE = BNK
SECU_CASH_BROK = BRF
SECU_CORP_CSLI = CAS
PMNT_ICHQ_CCHQ = CHK
PMNT_RCHQ_CASH = CLR
SECU_CASH_CLAI = CMP
CAMT_ACCB_SWEP = CMS
CAMT_ACCB_TOPG = CMT
CAMT_ACCB_ZABA = CMZ
SECU_CUST_CAPG = DIS
SECU_CUST_DVCA = DIV
SECU_NSET_OWNE = EXT
SECU_COLL_MARG = MAR
SECU_CORP_REDM = MAT
SECU_CASH_MNFE = MGT
SECU_CASH_OVCH = ODC
SECU_NSET_PRUD = PRN
SECU_CORP_TREC = REC
SECU_CASH_GEN1 = RED
SECU_CORP_RHTS = RIG
SECU_CORP_ODLT = SAL
PMNT_ICDT_STDO = STO
SECU_CASH_STAM = STP
SECU_NSET_SUBS = SUB
SECU_CASH_SWAP = SWP
SECU_CASH_WITH = TAX
PMNT_CNTR_TCDP = TCK
PMNT_CNTR_TCWD = TCK
SECU_SETT_OWNI = TRA
SECU_NSET_OWNI = TRA
SECU_CASH_TRFE = TRN
SECU_CASH_UNCO = UWC
SECU_CORP_EXWA = WAR
SECU_CUST_EXWA = WAR
\ No newline at end of file
#??=????
CNY=2
USD=2
EUR=2
GBP=2
KWR=0
JPY=0
AUD=2
HKD=2
MOP=2
TWD=2
AED=2
CAD=2
CHF=2
EGP=2
IDR=2
INR=2
KWD=3
SGD=2
THB=2
VND=0
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--
THE MESSAGE WILL WORK “AS IS” IN THE READINESS PORTAL. IT IS ESSENTIAL THAT USERS REMOVE THE ENVELOPE AND REPLACE IT WITH THEIR OWN TRANSPORT HEADER (FOR EXAMPLE FOR ALLIANCE ACCESS YOU WOULD USE THE XML V2 HEADERS).
=========================================================================================================================================================================================
SWIFT © 2020. All rights reserved.
This publication contains SWIFT or third-party confidential information. Do not disclose this publication outside your organisation without SWIFT’s prior written consent.
The use of this document is governed by the legal notices appearing at the end of this document. By using this document, you will be deemed to have accepted those legal notices.
====================================================================================================================================================================
Use Case c.57.4.1 Agent B ABN Amro Amsterdam also sends a notification to receive on behalf of Agent D ANZ Paris to notify Agent C CITI Bank a credit is expect on their account.
============================================================================================================================================================
Change Log
2021-06-30 - Original version
=============================
-->
<Envelope xmlns="urn:swift:xsd:envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:swift:xsd:envelope ../../../../Schemas/Translator_envelope.xsd">
<AppHdr xmlns="urn:iso:std:iso:20022:tech:xsd:head.001.001.02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Fr>
<FIId>
<FinInstnId>
<BICFI>ABNANL2A</BICFI>
</FinInstnId>
</FIId>
</Fr>
<To>
<FIId>
<FinInstnId>
<BICFI>ANZBAU3M</BICFI>
</FinInstnId>
</FIId>
</To>
<BizMsgIdr>cmt060bizmsgidr-001</BizMsgIdr>
<MsgDefIdr>camt.060.001.05</MsgDefIdr>
<BizSvc>swift.cbprplus.02</BizSvc>
<CreDt>2021-02-17T09:09:05+01:00</CreDt>
</AppHdr>
<Document xmlns="urn:iso:std:iso:20022:tech:xsd:camt.060.001.05">
<AcctRptgReq>
<GrpHdr>
<MsgId>cmt060bizmsgidr-001</MsgId>
<CreDtTm>2021-02-17T09:09:05+01:00</CreDtTm>
<MsgSndr>
<Agt>
<FinInstnId>
<BICFI>ABNANL2A</BICFI>
</FinInstnId>
</Agt>
</MsgSndr>
</GrpHdr>
<RptgReq>
<Id>cmt060bizmsgidr-001</Id>
<ReqdMsgNmId>camt.053.001.08</ReqdMsgNmId>
<Acct>
<Id>
<Othr>
<Id>123456</Id>
</Othr>
</Id>
</Acct>
<ReqdTxTp>
<Sts>
<Cd>PDNG</Cd>
</Sts>
<CdtDbtInd>CRDT</CdtDbtInd>
<FlrLmt>
<Amt Ccy="KWR">123.45</Amt>
<CdtDbtInd>DEBT</CdtDbtInd>
</FlrLmt>
<FlrLmt>
<Amt Ccy="KWR">3456.50</Amt>
<CdtDbtInd>CRED</CdtDbtInd>
</FlrLmt>
</ReqdTxTp>
</RptgReq>
<RptgReq>
<Id>cmt060bizmsgidr-001</Id>
<ReqdMsgNmId>camt.052.001.08</ReqdMsgNmId>
<Acct>
<Id>
<Othr>
<Id>81939316</Id>
</Othr>
</Id>
</Acct>
<ReqdTxTp>
<Sts>
<Cd>PDNG</Cd>
</Sts>
<CdtDbtInd>CRDT</CdtDbtInd>
<FlrLmt>
<Amt Ccy="KWD">7878.5687</Amt>
<CdtDbtInd>DEBT</CdtDbtInd>
</FlrLmt>
<FlrLmt>
<Amt Ccy="KWD">1234.4563</Amt>
<CdtDbtInd>CRED</CdtDbtInd>
</FlrLmt>
</ReqdTxTp>
</RptgReq>
</AcctRptgReq>
</Document>
</Envelope>
package com.brilliance.mt2mx.camt053001;
import com.prowidesoftware.swift.model.Tag;
import com.prowidesoftware.swift.model.field.Field61;
import com.prowidesoftware.swift.model.field.Field86;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.io.File;
import java.util.List;
public class Test940Camt053001 {
public static void main(String[] args) throws Exception {
//File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\MT940.txt");
//String xmlStr = new Mt2MxCreateManager().mt2mx(file, "d:/test/pacs008.xml", null);
//System.out.println(xmlStr);
//SwiftDto swiftDto = new Mt2SwiftDtoCreateManager().mt2SwiftDto(file, "d:/test/940camt0530.txt", null);
//System.out.println(swiftDto.toString());
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\MT940.txt");
AbstractMT abstractMT = AbstractMT.parse(file);
List<Tag> tagsList = abstractMT.getSwiftMessage().getBlock4().getTags();
for (int i=0; i< tagsList.size(); i++) {
Tag tag = tagsList.get(i);
if ("61".equals(tag.getName())) {
Field61 field61 = new Field61(tag.getValue());
System.out.println(field61.getDCMark());
System.out.println(field61.getFundsCode());
System.out.println(field61.getReferenceForTheAccountOwner());
System.out.println(field61.getReferenceOfTheAccountServicingInstitution());
System.out.println(field61.getSupplementaryDetails());
if ("86".equals(tagsList.get(i+1).getName())) {
Field86 field86 = new Field86(tagsList.get(i+1).getValue());
System.out.println(field86.getValue().replace("\r\n", ""));
}
}
}
}
}
package com.brilliance.mt2mx.camt053001;
public class Test950Camt053001 {
public static void main(String[] args) throws Exception {
//File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\MT950.txt");
//String xmlStr = new Mt2MxCreateManager().mt2mx(file, "d:/test/pacs008.xml", null);
//System.out.println(xmlStr);
//SwiftDto swiftDto = new Mt2SwiftDtoCreateManager().mt2SwiftDto(file, "d:/test/950camt0530.txt", null);
// System.out.println(swiftDto.toString());
}
}
package com.brilliance.mt2mx.camt054001;
public class Test900Camt054001 {
public static void main(String[] args) throws Exception {
//File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\MT900.txt");
//String xmlStr = new Mt2MxCreateManager().mt2mx(file, "d:/test/pacs008.xml", null);
//System.out.println(xmlStr);
//SwiftDto swiftDto = new Mt2SwiftDtoCreateManager().mt2SwiftDto(file, "d:/test/900camt0540.txt", null);
// System.out.println(swiftDto.toString());
}
}
package com.brilliance.mt2mx.camt054001;
public class Test910Camt054001 {
public static void main(String[] args) throws Exception {
//File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\MT910.txt");
//String xmlStr = new Mt2MxCreateManager().mt2mx(file, "d:/test/pacs008.xml", null);
//System.out.println(xmlStr);
//SwiftDto swiftDto = new Mt2SwiftDtoCreateManager().mt2SwiftDto(file, "d:/test/910camt0540.txt", null);
//System.out.println(swiftDto.toString());
}
}
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(
new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\Mt103.txt"),
"d:/test/pacs00800109.xml", null);
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);
}
}
package com.brilliance.mt2mx.pacs009001;
import com.brilliance.swift.SwiftTransfer;
import java.io.File;
public class Test {
private static void test202() {
String mx = SwiftTransfer.mt2Mx(
new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\Mt202.txt"),
"d:/test/pacs00900109.xml", null);
System.out.println(mx);
}
private static void test202Cov() {
String mx = SwiftTransfer.mt2Mx(
new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\Mt202_COV.txt"),
"d:/test/pacs00900109.xml", null);
System.out.println(mx);
}
public static void main(String[] args) throws Exception {
//test202();
//test202Cov();
String messageId = "camt.053.001.08";
String[] messageIds = messageId.split("\\.");
if (messageIds.length == 4) {
System.out.println(messageId.substring(messageId.lastIndexOf(".")+1));
System.out.println(messageId.substring(0, messageId.lastIndexOf(".")));
}
}
}
package com.brilliance.mt2swiftdto.camt053001;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.vo.SwiftDto;
import java.io.File;
public class Test940Camt053001 {
public static void main(String[] args) {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\MT940.txt");
SwiftDto swiftDto = new SwiftTransfer().mt2SwiftDto(file, "D:/test/BankToCustomerStatement.json", null);
System.out.println(swiftDto.toString());
}
}
package com.brilliance.mt2swiftdto.camt053001;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.vo.SwiftDto;
import java.io.File;
public class Test950Camt053001 {
public static void main(String[] args) {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\MT950.txt");
SwiftDto swiftDto = new SwiftTransfer().mt2SwiftDto(file, "D:/test/BankToStatement.json", null);
System.out.println(swiftDto.toString());
}
}
package com.brilliance.mt2swiftdto.camt054001;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.vo.SwiftDto;
import java.io.File;
public class Test900Camt054001 {
public static void main(String[] args) {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\MT900.txt");
SwiftDto swiftDto = new SwiftTransfer().mt2SwiftDto(file, "D:/MtToSwift/BankToCustomerDebitNotification.json", null);
System.out.println(swiftDto.toString());
}
}
package com.brilliance.mt2swiftdto.camt054001;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.vo.SwiftDto;
import java.io.File;
public class Test910Camt054001 {
public static void main(String[] args) {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\MT910.txt");
SwiftDto swiftDto = new SwiftTransfer().mt2SwiftDto(file, "D:/MtToSwift/BankToCustomerCreditNotification.json", null);
System.out.println(swiftDto.toString());
}
}
package com.brilliance.mt2swiftdto.pacs008001;
import com.prowidesoftware.swift.model.mt.AbstractMT;
import java.io.File;
public class TestPacs008001 {
public static void main(String[] args) throws Exception {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\MT950.txt");
//SwiftTransfer.mt2SwiftDto(file, "D:/test/CustomerCreditTransfer.json", null);
AbstractMT abstractMT = AbstractMT.parse(file);
//MT103 mt103 = (MT103)abstractMT;
String value = abstractMT.getSwiftMessage().getBlock4().getTagValue("61");
String[] values = abstractMT.getSwiftMessage().getBlock4().getTagValues("61");
System.out.println(values.length);
}
}
package com.brilliance.mt2swiftdto.pacs009001;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.vo.SwiftDto;
import java.io.File;
public class TestPacs009001 {
public static void testMt202() throws Exception {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\MT202.txt");
SwiftDto swiftDto = new SwiftTransfer().mt2SwiftDto(file, "D:/test/FinancialInstitutionCreditTransfer.json", null);
System.out.println(swiftDto.toString());
}
public static void testMt202Cov() throws Exception {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftTxt\\MT202_COV.txt");
SwiftDto swiftDto = new SwiftTransfer().mt2SwiftDto(file, "D:/test/FinancialInstitutionCreditTransfer.json", null);
System.out.println(swiftDto.toString());
}
public static void main(String[] args) throws Exception {
//testMt202();
testMt202Cov();
}
}
package com.brilliance.mx2mt.mt920;
import com.brilliance.swift.mx2mt.Mx2MtCreatorManager;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
public class Test {
public static void main(String[] args) throws IOException {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftXml\\MxCamt06000105.xml");
String xmlStr = FileUtils.readFileToString(file);
String mt920 = new Mx2MtCreatorManager().mx2Mt(xmlStr, null, null);
System.out.println(mt920);
}
}
package com.brilliance.mx2swiftdto.bankcdbcdnf;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.vo.SwiftDto;
import java.io.File;
public class Test900 {
public static void main(String[] args) {
SwiftDto swiftDto = SwiftTransfer.mx2SwiftDto(new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftXml\\MxCamt05400108_DEBIT.xml"), "D:/MxToSwift/BankToCustomerDebitNotification.json", null);
System.out.println(swiftDto);
}
}
package com.brilliance.mx2swiftdto.bankcdbcdnf;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.vo.SwiftDto;
import java.io.File;
public class Test910 {
public static void main(String[] args) {
SwiftDto swiftDto = SwiftTransfer.mx2SwiftDto(new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftXml\\MxCamt05400108_CREDIT.xml"), "D:/MxToSwift/BankToCustomerCreditNotification.json", null);
System.out.println(swiftDto);
}
}
package com.brilliance.mx2swiftdto.bankcusta;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.vo.SwiftDto;
import java.io.File;
public class Test940 {
public static void main(String[] args) {
SwiftDto swiftDto = SwiftTransfer.mx2SwiftDto(new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftXml\\MxCamt05300108_940.xml"), "D:/test/BankToCustomerStatement.json", null);
System.out.println(swiftDto);
}
}
package com.brilliance.mx2swiftdto.bankcusta;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.vo.SwiftDto;
import java.io.File;
public class Test950 {
public static void main(String[] args) {
SwiftDto swiftDto = SwiftTransfer.mx2SwiftDto(new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftXml\\MxCamt05300108_950.xml"), "D:/test/BankToStatement.json", null);
System.out.println(swiftDto);
}
}
package com.brilliance.mx2swiftdto.custcdttsf;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.vo.SwiftDto;
import java.io.File;
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);
String mt = SwiftTransfer.swiftDto2Mt(swiftDto.toJson(), null, null);
System.out.println(mt);
}
}
package com.brilliance.mx2swiftdto.fininstcdttsf;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.vo.SwiftDto;
import java.io.File;
public class Test {
private static void test202() {
SwiftDto swiftDto = SwiftTransfer.mx2SwiftDto(new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftXml\\MxPacs00900109.xml"), "d:/test/FinancialInstitutionCreditTransfer.json", null);
System.out.println(swiftDto);
}
private static void test202Cov() {
SwiftDto swiftDto = SwiftTransfer.mx2SwiftDto(new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftXml\\MxPacs00900109_COV.xml"), "d:/test/FinancialInstitutionCreditTransfer.json", null);
System.out.println(swiftDto);
}
public static void main(String[] args) {
test202();
//test202Cov();
}
}
package com.brilliance.swiftdto2mt.mt103;
import com.brilliance.swift.util.SwiftTransferUtil;
import com.brilliance.swift.vo.MxMtReasonCodeInfo;
import java.util.List;
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, null);
//System.out.println(mtStr);
List<MxMtReasonCodeInfo> list = SwiftTransferUtil.getMxMtReasonCodes();
list.forEach(x -> System.out.println(x.getMtCode() + "=" + x.getMtDescription() + "=" + x.getIsoCode() + "=" + x.isMtErrorCodePresent()));
}
}
\ No newline at end of file
package com.brilliance.swiftdto2mt.mt202;
import com.brilliance.swift.SwiftTransfer;
import java.io.File;
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, 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, null);
System.out.println(mtStr);
}
public static void main(String[] args) {
test202();
//test202Cov();
}
}
package com.brilliance.swiftdto2mt.mt900;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.swiftdto2mt.SwiftDto2MtCreatorManager;
import java.io.File;
public class Test {
public static void main(String[] args) {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftJson\\BankToCustomerDebitNotification.json");
String mtStr = SwiftTransfer.swiftDto2Mt(file, "D:/SwiftToMt/MT900.txt", null);
System.out.println(mtStr);
}
}
package com.brilliance.swiftdto2mt.mt910;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.swiftdto2mt.SwiftDto2MtCreatorManager;
import java.io.File;
public class Test {
public static void main(String[] args) {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftJson\\BankToCustomerCreditNotification.json");
String mtStr = SwiftTransfer.swiftDto2Mt(file, "D:/SwiftToMt/MT910.txt", null);
System.out.println(mtStr);
}
}
package com.brilliance.swiftdto2mt.mt940;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Test {
public static void main(String[] args) throws IOException {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\BankTransactionCode.Properties");
List<String> strings = FileUtils.readLines(file);
Map<String, String> maps = new HashMap<>();
for (String s : strings) {
if (!s.startsWith("#")) {
String[] arr = s.split("=");
if (arr.length == 2) {
maps.put(arr[0], arr[1]);
}
}
}
maps.forEach((k,v)->System.out.println(k + "=" + v));
}
}
package com.brilliance.swiftdto2mt.mt950;
import com.brilliance.swift.SwiftTransfer;
import java.io.File;
public class Test {
public static void main(String[] args) {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftJson\\BankToStatement.json");
String mtStr = SwiftTransfer.swiftDto2Mt(file, "D:/test/MT950.txt", null);
System.out.println(mtStr);
}
}
package com.brilliance.swiftdto2mx.camt053001;
import com.brilliance.swift.SwiftTransfer;
import java.io.File;
/**
* @author zh
* @create 2022-04-29 10:12
*/
public class Text940camt053001 {
public static void main(String[] args) {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftJson\\BankToCustomerStatement.json");
String mtStr = SwiftTransfer.swiftDto2Mx(file,"D:/test/MxCamt05300108_940.xml");
System.out.println(mtStr);
}
}
package com.brilliance.swiftdto2mx.camt053001;
import com.brilliance.swift.SwiftTransfer;
import java.io.File;
/**
* @author zh
* @create 2022-04-29 10:12
*/
public class Text950camt053001 {
public static void main(String[] args) {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftJson\\BankToStatement.json");
String mtStr = SwiftTransfer.swiftDto2Mx(file,"D:/SwiftToMx/MxCamt05300108_950.xml");
System.out.println(mtStr);
}
}
package com.brilliance.swiftdto2mx.camt054001;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.swiftdto2mt.SwiftDto2MtCreatorManager;
import com.brilliance.swift.swiftdto2mx.SwiftDto2MxCreatorManager;
import com.prowidesoftware.swift.model.mt9xx.MT900;
import java.io.File;
/**
* @author zh
* @create 2022-04-29 10:12
*/
public class Text900camt054001 {
public static void main(String[] args) {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftJson\\BankToCustomerDebitNotification.json");
String mtStr = SwiftTransfer.swiftDto2Mx(file,"D:/SwiftToMx/MxCamt05400108_DEBIT.xml");
System.out.println(mtStr);
}
}
package com.brilliance.swiftdto2mx.camt054001;
import com.brilliance.swift.SwiftTransfer;
import java.io.File;
/**
* @author zh
* @create 2022-04-29 10:12
*/
public class Text910camt054001 {
public static void main(String[] args) {
File file = new File(System.getProperty("user.dir")+"\\swiftCore\\src\\main\\resources\\swiftJson\\BankToCustomerCreditNotification.json");
String mtStr = SwiftTransfer.swiftDto2Mx(file,"D:/SwiftToMx/MxCamt05400108_CREDIT.xml");
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