Commit f449d2d1 by gechengyang

优化pacs00800108业务要素Element转MX报文buildRgltryRptg函数的处理逻辑

parent fa26e36f
......@@ -7,9 +7,9 @@
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="swiftMx" />
<module name="swiftCore" />
<module name="swiftMt" />
<module name="swiftMx" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
......
......@@ -26,6 +26,8 @@ public class Element2MxPacs008001Creator extends AbstractElement2MxCreator {
public void buildRgltryRptg(HashMap<String,Object> maps, Object obj) {
List<Object> objList = (List<Object>)obj;
putObj(maps, "fiToFICstmrCdtTrf.cdtTrfTxInf.rgltryRptg", objList.get(0));
/* List<Object> objList = (List<Object>)obj;
JSONArray jsonArray = (JSONArray)objList.get(0);
List<String> list = new ArrayList<String>();
for (int i=0; i<jsonArray.size(); i++) {
......@@ -39,7 +41,7 @@ public class Element2MxPacs008001Creator extends AbstractElement2MxCreator {
Map<String, Object> dtlsRptgMap = new HashMap<String, Object>();
dtlsJsonArray.add(dtlsRptgMap);
dtlsRptgMap.put("inf", list);
putObj(maps, "fiToFICstmrCdtTrf.cdtTrfTxInf.rgltryRptg", rgltryRptgJsonArray);
putObj(maps, "fiToFICstmrCdtTrf.cdtTrfTxInf.rgltryRptg", rgltryRptgJsonArray);*/
}
public void buildStrdAddtlRmtInf(HashMap<String,Object> maps, Object obj) {
......
......@@ -4,15 +4,13 @@ import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2element.AbstractMx2ElementCreator;
import com.brilliance.swift.util.StringUtil;
import com.brilliance.swift.util.XmlUtil;
import com.prowidesoftware.swift.model.mx.dic.ActiveOrHistoricCurrencyAndAmount;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
public class Mx2ElementPacs008001Creator extends AbstractMx2ElementCreator {
@Override
......@@ -52,22 +50,70 @@ public class Mx2ElementPacs008001Creator extends AbstractMx2ElementCreator {
Document document = DocumentHelper.parseText(xmlStr);
Map<String, String> parentElementMaps = XmlUtil.getParentElementMaps(document);
String bodyParentPath = parentElementMaps.get("CdtTrfTxInf");
List<String> list = new ArrayList<String>();
// List<String> list = new ArrayList<String>();
List list=new ArrayList();
int mxRegulatoryReportingCount = XmlUtil.getChildrenCount(document, bodyParentPath+".CdtTrfTxInf.RgltryRptg", null);
if (mxRegulatoryReportingCount > 0) {
for (int i=0; i<mxRegulatoryReportingCount; i++) {
Map map=new HashMap();
String dbtCdtRptgIndValue= XmlUtil.getXmlNodeValue(document, bodyParentPath+".CdtTrfTxInf.RgltryRptg("+i+").DbtCdtRptgInd");
map.put("dbtCdtRptgIndValue",dbtCdtRptgIndValue);
String nameValue= XmlUtil.getXmlNodeValue(document, bodyParentPath+".CdtTrfTxInf.RgltryRptg("+i+").Authrty.Nm");
Map authrtyMap=new HashMap();
authrtyMap.put("nm",nameValue);
map.put("authrty",authrtyMap);
int mxRegulatoryReportingDetailCount = XmlUtil.getChildrenCount(document,bodyParentPath+".CdtTrfTxInf.RgltryRptg("+i+").Dtls", null);
//对应Dtls标签的存储
List subList=new ArrayList();
//Dtls标签下的Map数据存储
Map subMap=new HashMap();
List infList=new ArrayList();
if (mxRegulatoryReportingDetailCount > 0) {
for (int j=0; j<mxRegulatoryReportingDetailCount; j++) {
//处理Dtls标签
int mxRegulatoryReportingDetailInfCount = XmlUtil.getChildrenCount(document,bodyParentPath+".CdtTrfTxInf.RgltryRptg("+i+").Dtls("+j+").Inf", null);
//处理Dtls标签下的Inf循环标签
if (mxRegulatoryReportingDetailInfCount > 0) {
for (int k=0; k<mxRegulatoryReportingDetailInfCount; k++) {
String inf = XmlUtil.getXmlNodeValue(document, bodyParentPath+".CdtTrfTxInf.RgltryRptg("+i+").Dtls("+j+").Inf("+k+")");
list.add(inf);
//list.add(inf);
infList.add(inf);
}
}
subMap.put("inf",infList);
//处理Dtls标签下的Tp循环标签
String tpValue = XmlUtil.getXmlNodeValue(document, bodyParentPath+".CdtTrfTxInf.RgltryRptg("+i+").Dtls("+j+").Tp");
subMap.put("tp",tpValue);
//处理Dtls标签下的Dt循环标签
String dtValue = XmlUtil.getXmlNodeValue(document, bodyParentPath+".CdtTrfTxInf.RgltryRptg("+i+").Dtls("+j+").Dt");
subMap.put("dt",dtValue);
//处理Dtls标签下的Ctry循环标签
String ctryValue = XmlUtil.getXmlNodeValue(document, bodyParentPath+".CdtTrfTxInf.RgltryRptg("+i+").Dtls("+j+").Ctry");
subMap.put("ctry",ctryValue);
//处理Dtls标签下的Cd循环标签
String cdValue = XmlUtil.getXmlNodeValue(document, bodyParentPath+".CdtTrfTxInf.RgltryRptg("+i+").Dtls("+j+").Cd");
subMap.put("cd",cdValue);
//处理Dtls标签下的Amt循环标签
String amtValue = XmlUtil.getXmlNodeValue(document, bodyParentPath+".CdtTrfTxInf.RgltryRptg("+i+").Dtls("+j+").Amt");
String ccyValue=XmlUtil.getXmlNodeValue(document, bodyParentPath+".CdtTrfTxInf.RgltryRptg("+i+").Dtls("+j+").Amt@Ccy");
if(StringUtil.isNotEmpty(amtValue)&&StringUtil.isNotEmpty(ccyValue)) {
ActiveOrHistoricCurrencyAndAmount activeOrHistoricCurrencyAndAmount=new ActiveOrHistoricCurrencyAndAmount();
activeOrHistoricCurrencyAndAmount.setCcy(ccyValue);
activeOrHistoricCurrencyAndAmount.setValue(new BigDecimal(amtValue));
subMap.put("amt",activeOrHistoricCurrencyAndAmount);
}
subList.add(subMap);
}
map.put("dtls",subList);
}
list.add(map);
}
}
if (list.size() > 0) {
......
......@@ -89,9 +89,42 @@ Change Log
<Ctry>BG</Ctry>
</PstlAdr>
</Cdtr>
<RmtInf>
<RgltryRptg>
<DbtCdtRptgInd>DEBT</DbtCdtRptgInd>
<Authrty>
<Ctry>US</Ctry>
<Nm>zhangsan</Nm>
</Authrty>
<Dtls>
<Tp>TEST1</Tp>
<Dt>2021-04-09T09:00:00+01:00</Dt>
<Ctry>US</Ctry>
<Cd>TEST1</Cd>
<Amt Ccy="USD">100</Amt>
<Inf>testInfo111</Inf>
</Dtls>
</RgltryRptg>
<RgltryRptg>
<DbtCdtRptgInd>CRED</DbtCdtRptgInd>
<Authrty>
<Ctry>CN</Ctry>
<Nm>lisi</Nm>
</Authrty>
<Dtls>
<Tp>TEST2</Tp>
<Dt>2022-04-09T09:00:00+01:00</Dt>
<Ctry>US</Ctry>
<Cd>TEST2</Cd>
<Amt Ccy="USD">100</Amt>
<Inf>testInfo222</Inf>
</Dtls>
</RgltryRptg>
<RmtInf>
<Ustrd>SWEEP 454-9663</Ustrd>
</RmtInf>
</RmtInf>
</CdtTrfTxInf>
</FIToFICstmrCdtTrf>
</Document>
......
......@@ -2,24 +2,42 @@ package com.brilliance;
import com.brilliance.swift.SwiftTransfer;
import com.brilliance.swift.element2mx.Element2MxCreatorManager;
import com.brilliance.swift.util.XmlUtil;
import com.prowidesoftware.swift.model.MxId;
import com.prowidesoftware.swift.model.mx.AbstractMX;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
public class Element2MxTest {
@Test
public void test() {
public void test() throws IOException {
//File file = FileUtils.toFile(Mx2MtTest.class.getResource("/swiftXml/MxCamt05300108_950.xml"));
//File file = FileUtils.toFile(Mx2MtTest.class.getResource("/swiftXml/MxPacs00800108.xml"));
// File file = FileUtils.toFile(Mx2MtTest.class.getResource("/swiftXml/MxPacs00800108.xml"));
File file = FileUtils.toFile(Mx2MtTest.class.getResource("/swiftXml/Pacs00800108.xml"));
//File file = FileUtils.toFile(Mx2MtTest.class.getResource("/swiftXml/MxPacs00900108.xml"));
//File file = FileUtils.toFile(Mx2MtTest.class.getResource("/swiftXml/MxCamt05400108_CREDIT.xml"));
//File file = FileUtils.toFile(Mx2MtTest.class.getResource("/swiftXml/MxCamt02900109_196.xml"));
File file = FileUtils.toFile(Mx2MtTest.class.getResource("/swiftXml/camt05400108_900.xml.xml"));
// File file = FileUtils.toFile(Mx2MtTest.class.getResource("/swiftXml/camt05400108_900.xml.xml"));'
String xmlStr1 = FileUtils.readFileToString(file);
MxId mxId = XmlUtil.getMxMessageType(xmlStr1);
AbstractMX abstractMX = AbstractMX.parse(file,mxId);
String json=abstractMX.toJson();
String elementStr = SwiftTransfer.mx2Element(file);
System.out.println("elementStr="+elementStr);
System.out.println("*****************************");
String xmlStr = new Element2MxCreatorManager().element2Mx(elementStr);
System.out.println(xmlStr);
String str="ABC";
try {
int length=str.getBytes("GBK").length;
} catch (java.io.UnsupportedEncodingException e) {
e.printStackTrace();
}
}
}
......@@ -15,6 +15,10 @@ import java.util.Map;
public class Mt2MxTest {
public void printSwiftTranslationReport(SwiftTranslationReport str) {
System.out.println(str.getTranslationResult());
System.out.println(str.getMtType());
System.out.println(str.getMxType());
System.out.println("***************");
if (str != null) {
String errorDsp = "";
List<SwiftTranslationErrorInfo> errorInfos = str.getErrorInfos();
......
......@@ -62,7 +62,7 @@ public class Mx2MessageTest {
}
@Test
public void testPacs009001() {test("MxPacs00900108.xml", "CN");}
public void testPacs009001() {test("Pacs00900108.xml", "US");}
@Test
public void testPacs004001() {
......
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