Commit bd2b93c8 by zhanghou

修改了camt05300108的Mx2ElementCamt053001Creator方法

parent ca1f9a42
package com.brilliance.swift.mx2element.camt053001;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.brilliance.swift.exception.SwiftException;
import com.brilliance.swift.mx2element.AbstractMx2ElementCreator;
import com.brilliance.swift.util.StringUtil;
......@@ -9,13 +12,118 @@ import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.*;
public class Mx2ElementCamt053001Creator extends AbstractMx2ElementCreator {
@Override
public Map<String, Object> buildElement() {
return super.buildElement();
String messageType = abstractMX.getMxId().getBusinessProcess().name()
+ abstractMX.getMxId().getFunctionality()
+ abstractMX.getMxId().getVariant()
+ abstractMX.getMxId().getVersion();
maps.put("messageType", messageType);
String gsonStr = abstractMX.toJson();
Map<String, Object> mxGsonMaps = JSON.parseObject(gsonStr);
String fileName = "/template/"+messageType+".properties";
InputStream resourceAsStream = AbstractMx2ElementCreator.class.getResourceAsStream(fileName);
if (resourceAsStream == null) {
int versionLength = abstractMX.getMxId().getVersion().length();
fileName = "/template/"+messageType.substring(0, messageType.length()-versionLength)+".properties";
resourceAsStream = AbstractMx2ElementCreator.class.getResourceAsStream(fileName);
}
List<String> properties = StringUtil.inputStreamToLines(resourceAsStream);
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 path = strArr[1];
Object value = getXmlValue(mxGsonMaps, path,0);
if (value != null) {
maps.put(key, value);
}
}
}
return maps;
}
protected Object getXmlValue(Map<String, Object> jsonMaps, String path,int count) {
Object value = null;
if (path.indexOf("?") > 0) {
String[] childPaths = path.split("\\?");
for (String childPath : childPaths) {
value = getXmlValue(jsonMaps, childPath);
if (value != null) {
return value;
}
}
}
//获取数据类型,&分隔,默认是string
String type = "string";
if (path.indexOf("&") > -1) {
type = path.substring(path.indexOf("&")+1);
path = path.substring(0, path.indexOf("&"));
}
//需要用. split,然后循环遍历json获取值
int index1 = path.indexOf("(");
int index2 = path.indexOf(")");
if(index1>0&&index2>0){
path = path.substring(0,index1)+path.substring(index1,index2).replace(".","-")+path.substring(index2);
}
String[] paths = path.split("\\.");
Map<String, Object> tmpMaps = jsonMaps;
for (int i=0; i<paths.length; i++) {
int j = 0;
String p = paths[i];
if(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("-",".");
String value1 = split[1].substring(0,split[1].length()-1);
for (;j<array.size();j++){
String xmlValue = (String)getXmlValue((Map<String, Object>) array.get(j), path1,j);
if(StringUtil.isNotEmpty(xmlValue)&&xmlValue.equals(value1)){
int index = p.indexOf("(");
p = p.substring(0,index);
break;
}
}
}
Object obj = tmpMaps.get(p);
if (obj == null) return null;
if (obj instanceof JSONArray) {
JSONArray jsonArray = (JSONArray)obj;
if (i == paths.length-1) {
return jsonArray;
} else {
obj = jsonArray.get(j);
if (obj instanceof JSONObject) {
tmpMaps = (Map<String, Object>)obj; //不是最后一层
} else {
return jsonArray;
}
}
} else if (obj instanceof JSONObject) {
tmpMaps = (Map<String, Object>)obj;
} else {
if ("bigdecimal".equals(type)) {
value = new BigDecimal(String.valueOf(obj));
} else if ("boolean".equals(type)) {
value = Boolean.valueOf(String.valueOf(obj));
} else {
value = String.valueOf(obj);
}
break;
}
}
return value;
}
public Object buildOpbdBalance(){
......
......@@ -21,10 +21,28 @@ lglSeqNb=bkToCstmrStmt.stmt.lglSeqNb&bigdecimal?bkToCstmrStmt.stmt.elctrncSeqNb&
pgNb=bkToCstmrStmt.stmt.stmtPgntn.pgNb
lastPgInd=bkToCstmrStmt.stmt.stmtPgntn.lastPgInd&boolean
#60
opbdBal=@buildOpbdBalance
#opbdBal=@buildOpbdBalance
#61
ntry=@bulidNtry
#62
clbdBal=@buildClbdBalance
#clbdBal=@buildClbdBalance
#64
clavBal=@buildClavBalance
\ No newline at end of file
#clavBal=@buildClavBalance
opbdBalSubType=bkToCstmrStmt.stmt.bal(tp.cdOrPrtry.cd:OPBD).tp.subTp.cd
opbdBalSubTypePrtry=bkToCstmrStmt.stmt.bal(tp.cdOrPrtry.cd:OPBD).tp.subTp.prtry
opbdBalAmt=bkToCstmrStmt.stmt.bal(tp.cdOrPrtry.cd:OPBD).amt.value&bigdecimal
opbdBalCcy=bkToCstmrStmt.stmt.bal(tp.cdOrPrtry.cd:OPBD).amt.ccy
opbdBalCdtDbtInd=bkToCstmrStmt.stmt.bal(tp.cdOrPrtry.cd:OPBD).cdtDbtInd
opbdBalDt=bkToCstmrStmt.stmt.bal(tp.cdOrPrtry.cd:OPBD).dt.dt
clbdBalSubType=bkToCstmrStmt.stmt.bal(tp.cdOrPrtry.cd:CLBD).tp.subTp.cd
clbdBalSubTypePrtry=bkToCstmrStmt.stmt.bal(tp.cdOrPrtry.cd:CLBD).tp.subTp.prtry
clbdBalAmt=bkToCstmrStmt.stmt.bal(tp.cdOrPrtry.cd:CLBD).amt.value&bigdecimal
clbdBalCcy=bkToCstmrStmt.stmt.bal(tp.cdOrPrtry.cd:CLBD).amt.ccy
clbdBalCdtDbtInd=bkToCstmrStmt.stmt.bal(tp.cdOrPrtry.cd:CLBD).cdtDbtInd
clbdBalDt=bkToCstmrStmt.stmt.bal(tp.cdOrPrtry.cd:CLBD).dt.dt
clavBalSubType=bkToCstmrStmt.stmt.bal(tp.cdOrPrtry.cd:CLAV).tp.subTp.cd
clavBalSubTypePrtry=bkToCstmrStmt.stmt.bal(tp.cdOrPrtry.cd:CLAV).tp.subTp.prtry
clavBalAmt=bkToCstmrStmt.stmt.bal(tp.cdOrPrtry.cd:CLAV).amt.value&bigdecimal
clavBalCcy=bkToCstmrStmt.stmt.bal(tp.cdOrPrtry.cd:CLAV).amt.ccy
clavBalCdtDbtInd=bkToCstmrStmt.stmt.bal(tp.cdOrPrtry.cd:CLAV).cdtDbtInd
clavBalDt=bkToCstmrStmt.stmt.bal(tp.cdOrPrtry.cd:CLAV).dt.dt
\ 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