Commit 06393a03 by zhanghou

修改了camt05300108的Mx2ElementCamt053001Creator方法,实现了通过配置文件实现循环节点取值

parent bd2b93c8
......@@ -13,6 +13,7 @@ import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.util.*;
......@@ -54,8 +55,21 @@ public class Mx2ElementCamt053001Creator extends AbstractMx2ElementCreator {
}
return maps;
}
private Object invokeHere(String methodName, Object where) {
try {
Method method = getClass().getMethod(methodName);
return method.invoke(where);
} catch (final NoSuchMethodException e) {
throw new SwiftException("Method " + methodName + " does not exist in " + getClass());
} catch (Exception e) {
throw new SwiftException(e.getMessage());
}
}
protected Object getXmlValue(Map<String, Object> jsonMaps, String path,int count) {
Object value = null;
if (path.startsWith("@")) { //如果以@开始 表示取值规则采用的函数
return invokeHere(path.substring(1), this);
}
if (path.indexOf("?") > 0) {
String[] childPaths = path.split("\\?");
for (String childPath : childPaths) {
......@@ -65,6 +79,49 @@ public class Mx2ElementCamt053001Creator extends AbstractMx2ElementCreator {
}
}
}
if(path.lastIndexOf("#")>0){
JSONArray array = (JSONArray)getXmlValue(jsonMaps, path.split("#")[0], 0);
String key = path.substring(path.indexOf("#")+1);
String fileName = "/template/"+key+".properties";
InputStream resourceAsStream = AbstractMx2ElementCreator.class.getResourceAsStream(fileName);
List<String> properties = StringUtil.inputStreamToLines(resourceAsStream);
List<Map<String,Object>> list = new ArrayList<>();
List<String> keyList = new ArrayList<>();
List<String> valueList = new ArrayList<>();
if (properties.size() > 0) {
for (String property : properties) {
if (property.startsWith("#")) {
continue;//过滤注释
}
String[] strArr = property.split("=");
if (strArr.length != 2) {
continue;//过滤掉不符合规则的配置
}
String key1 = strArr[0];
String value1 = strArr[1];
if(StringUtil.isNotEmpty(key1)&&StringUtil.isNotEmpty(value1)){
keyList.add(key1);
valueList.add(value1);
}
}
}
for (int i = 0; i < array.size(); i++) {
Map<String,Object> entryMaps = new LinkedHashMap<>();
for (int j = 0; j < valueList.size(); j++) {
Object xmlValue = getXmlValue((Map<String, Object>) array.get(i), valueList.get(j), 0);
if(xmlValue!=null){
entryMaps.put(keyList.get(j),xmlValue);
}
}
list.add(entryMaps);
}
if(list.size()>0){
return list;
}else {
return null;
}
//清空ntry中的值将list存入ntry中
}
//获取数据类型,&分隔,默认是string
String type = "string";
if (path.indexOf("&") > -1) {
......@@ -82,7 +139,7 @@ public class Mx2ElementCamt053001Creator extends AbstractMx2ElementCreator {
for (int i=0; i<paths.length; i++) {
int j = 0;
String p = paths[i];
if(p.contains("(")){
if(p.contains("(")&&p.contains(")")){
JSONArray array = (JSONArray) tmpMaps.get(p.substring(0,p.indexOf("(")));
String[] split = p.split(":");
String path1 = split[0].substring(p.indexOf("(")+1).replace("-",".");
......
......@@ -23,7 +23,8 @@ lastPgInd=bkToCstmrStmt.stmt.stmtPgntn.lastPgInd&boolean
#60
#opbdBal=@buildOpbdBalance
#61
ntry=@bulidNtry
#ntry=@bulidNtry
ntry=bkToCstmrStmt.stmt.ntry#ntry
#62
#clbdBal=@buildClbdBalance
#64
......
ntryRef=ntryRef
ntryAmt=amt.value&bigdecimal
ntryCcy=amt.ccy
ntryCdtDbtInd=cdtDbtInd
ntryRvslInd=rvslInd&boolean
ntrySts=sts.cd
ntryStsPrtry=sts.prtry
ntryBookgDt=bookgDt.dt
ntryValDt=valDt.dt
ntryAcctSvcrRef=acctSvcrRef
ntryBkTxCdDomnCd=bkTxCd.domn.cd
ntryBkTxCdFmlyCd=bkTxCd.domn.fmly.cd
ntryBkTxCdFmlySubFmlyCd=bkTxCd.domn.fmly.subFmlyCd
ntryBkTxCdPrtryCd=bkTxCd.prtry.cd
endToEndId=ntryDtls.txDtls.refs.endToEndId
addtlTxInf=ntryDtls.txDtls.addtlTxInf
\ No newline at end of file
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