Commit 04b50ee3 by cjh

更新ESB适配报文格式

parent 5a63f002
......@@ -10,7 +10,10 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.sss.common.model.*;
import org.sss.module.hibernate.HibernateUtils;
import org.sss.presentation.noui.api.exception.NoUiException;
import org.sss.presentation.noui.api.model.Alias;
import org.sss.presentation.noui.api.model.FileIn;
......@@ -25,6 +28,7 @@ import org.sss.presentation.noui.context.NoUiContext;
import org.sss.presentation.noui.context.NoUiContextManager;
import org.sss.presentation.noui.context.NoUiPresentation;
import org.sss.presentation.noui.util.CacheUtil;
import org.sss.presentation.noui.util.ESBUtil;
import org.sss.presentation.noui.util.NoUiPresentationUtil;
import org.sss.presentation.noui.util.StringUtil;
......@@ -53,7 +57,7 @@ public class ServiceImpl implements Service {
}
@SuppressWarnings("unchecked")
public Object event(String mappingUrl, String eventType, Map<String, Object> dataMap, FileIn file, String userId, FileOut fileOut) {
public Result event(String mappingUrl, String eventType, Map<String, Object> dataMap, FileIn file, String userId, FileOut fileOut) {
NoUiContext context = null;
Result ret = null;
......@@ -61,7 +65,8 @@ public class ServiceImpl implements Service {
try {
NoUiRequest noUiRequest = new NoUiRequest(userId, mappingUrl, dataMap);
context = NoUiContextManager.createNoUiContext(noUiRequest);
Alias alias = new Alias(mappingUrl);
Alias alias = new Alias(mappingUrl,Constants.REQ);
Alias alias_resp = new Alias(mappingUrl,Constants.RESP);
String trnName = alias.getTrnName();
// 交易参数赋值
Map<String, ?> paramsMap = noUiRequest.getParamsMap();
......@@ -135,10 +140,10 @@ public class ServiceImpl implements Service {
}
Map<String, Object> afterReturnData = handleReturnData(eventType, context, noUiRequest, alias);
Map<String, Object> afterReturnData = handleReturnData(eventType, context, noUiRequest, alias_resp);
ret = ResultUtil.result(NoUiPresentationUtil.retCode(context), NoUiPresentationUtil.retMsg(context), afterReturnData,
NoUiPresentationUtil.handleErrorReturnData(context, alias), NoUiPresentationUtil.handleCodeTableReturnData(context, alias));
NoUiPresentationUtil.handleErrorReturnData(context, alias_resp), NoUiPresentationUtil.handleCodeTableReturnData(context, alias));
} catch (Exception e) {
log.error("OnClick command error", e);
ret = ResultUtil.result(ErrorCodes.ERROR, "hander error", e.getMessage());
......@@ -174,7 +179,7 @@ public class ServiceImpl implements Service {
String realPath = alias.getRelPath(aliasKey);
IBaseObject baseObject = context.getSession().getBaseObject(context.getRoot(), realPath);
data.put(aliasKey, NoUiPresentationUtil.handIBaseObject(context, baseObject, realPath));
data.put(aliasKey, NoUiPresentationUtil.handIBaseObject(context, baseObject, realPath,alias));
}
return data;
}
......@@ -203,75 +208,51 @@ public class ServiceImpl implements Service {
continue;
if(aliasPath.length() > modKeyLen && val instanceof IModule){
IBaseObject obj = context.getSession().getBaseObject((IModule)val,aliasPath.substring(modKeyLen));
IBaseObject obj = context.getSession().getBaseObject((IModule)val,aliasPath);
if(!(obj instanceof IModule))
data.put(aliasKey, NoUiPresentationUtil.handIBaseObject(context, obj, aliasEntry.getValue()));
data.put(aliasKey, NoUiPresentationUtil.handIBaseObject(context, obj, aliasEntry.getValue(),alias));
}else
data.put(aliasKey, NoUiPresentationUtil.handIBaseObject(context, val, aliasEntry.getValue()));
data.put(aliasKey, NoUiPresentationUtil.handIBaseObject(context, val, aliasEntry.getValue(),alias));
containsKeys.add(modifyEntry.getKey());
}
}
}
// 不能修改
for (String key : modifyMap.keySet()) {
if (!containsKeys.contains(key)) {
System.out.println("modify test:" + modifyMap.get(key).getClass());
System.out.println("modify datafield:" + (modifyMap.get(key) instanceof IDatafield));
System.out.println("modify module:" + (modifyMap.get(key) instanceof IModule));
System.out.println("modify moduleList:" + (modifyMap.get(key) instanceof IModuleList));
if(key == null)
continue;
if(!(modifyMap.get(key) instanceof IModule))
data.put(key, NoUiPresentationUtil.handIBaseObject(context, modifyMap.get(key), key));
}
}
// for (String key : modifyMap.keySet()) {
// if (!containsKeys.contains(key)) {
// System.out.println("modify test:" + modifyMap.get(key).getClass());
// System.out.println("modify datafield:" + (modifyMap.get(key) instanceof IDatafield));
// System.out.println("modify module:" + (modifyMap.get(key) instanceof IModule));
// System.out.println("modify moduleList:" + (modifyMap.get(key) instanceof IModuleList));
// if(key == null)
// continue;
// if(!(modifyMap.get(key) instanceof IModule))
// data.put(key, NoUiPresentationUtil.handIBaseObject(context, modifyMap.get(key), key,alias));
// }
// }
return data;
}
public CompositeData exec(CompositeData reqData) {
CompositeData respData = new CompositeData();
try {
Gson gson = new Gson();
Map<String, Object> request_data = null;
CompositeData body = reqData.getStruct(Constants.BODY);
Field f_request_data_map = body.getField(Constants.REQUEST_DATA);
if(f_request_data_map != null){
request_data = gson.fromJson((String) f_request_data_map.getValue(), Map.class);
}
if(body.getField(Constants.USER_ID) == null)throw new Exception("用户ID不能为空");
if(body.getField(Constants.MAPPING_URL) == null)throw new Exception("请求url不能为空");
if(body.getField(Constants.EVENT_TYPE) == null)throw new Exception("事件类型不能为空");
String userId = (String) body.getField(Constants.USER_ID).getValue();
String mappingUrl = (String) body.getField(Constants.MAPPING_URL).getValue();
String eventType = (String) body.getField(Constants.EVENT_TYPE).getValue();
String userId = ESBUtil.getUserId(reqData);
String mappingUrl = ESBUtil.getMappingUrl(reqData);
Map body_map = ESBUtil.bodyToMap(reqData.getStruct(Constants.BODY));
Map request_data = new HashMap();
request_data.put(Constants.DATA,body_map);
Field f_file_in = body.getField(Constants.FILE_IN);
FileIn fileIn = null;
if(f_file_in != null){
fileIn = gson.fromJson((String) f_file_in.getValue(), FileIn.class);
}
FileOut fileOut = new FileOut();
Result result = event(mappingUrl, ON_CLICK, request_data, null, userId, null);
Object result = event(mappingUrl, eventType, request_data, fileIn, userId, fileOut);
CompositeData BODY= new CompositeData();
ESBUtil.mapToBody(BODY,(Map<String, Object>)result.getData());
respData.addStruct(Constants.BODY, BODY);
FieldType type = FieldType.getEnum("string");
FieldAttr fieldAttr = new FieldAttr(type,20,0);
Field field_result = new Field(fieldAttr);
field_result.setValue(gson.toJson(result));
BODY.addField(Constants.RESULT, field_result);
if (eventType.equals(ON_STREAM_DOWNLOAD)){
Field field_file = new Field(fieldAttr);
field_file.setValue(gson.toJson(fileOut));
BODY.addField(Constants.FILE_OUT, field_file);
}
}catch (Exception e){
log.error(e);
}
return respData;
}
}
......@@ -14,14 +14,11 @@ public class Constants {
public final static String MAPPING_PRE = "_";
public final static String BODY = "BODY";
public final static String REQUEST_DATA = "requestData";
public final static String USER_ID = "userid";
public final static String EVENT_TYPE = "eventType";
public final static String MAPPING_URL = "mappingUrl";
public final static String RESULT = "result";
public final static String FILE_IN = "fileIn";
public final static String FILE_OUT = "fileOut";
public final static String SYS_HEAD = "SYS_HEAD";
public final static String APP_HEAD = "APP_HEAD";
public final static String USER_ID = "USER_ID";
public final static String SERVICE_SCENE = "SERVICE_SCENE";
public final static String SERVICE_CODE = "SERVICE_CODE";
public final static String REQ = "req";
public final static String RESP = "resp";
}
package org.sss.presentation.noui.util;
import com.dc.eai.data.*;
import org.sss.presentation.noui.common.Constants;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
public class ESBUtil {
static Map serviceMap;
static {
try {
serviceMap = new HashMap<String, String>((Map) PropertyUtil.load("service_mapping.properties"));
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getUserId(CompositeData reqData){
CompositeData sys_head = reqData.getStruct(Constants.SYS_HEAD);
return (String) sys_head.getField(Constants.USER_ID).getValue();
}
public static String getMappingUrl(CompositeData reqData){
CompositeData sys_head = reqData.getStruct(Constants.SYS_HEAD);
String code = (String) sys_head.getField(Constants.SERVICE_CODE).getValue();
String scene = (String) sys_head.getField(Constants.SERVICE_SCENE).getValue();
return (String) serviceMap.get(code+"."+scene);
}
public static Map bodyToMap(CompositeData body){
Iterator<String> iterator = body.iterator();
Map map = new HashMap<>();
while(iterator.hasNext()){
String child = iterator.next();
AtomData atomData = body.getObject(child);
if(atomData.isField()){
Object value = ((Field)atomData).getValue();
map.put(child,value);
}else if(atomData.isArray()){
List list = new ArrayList<>();
Array lst = (Array)atomData;
for(int i=0;i<lst.size();i++){
AtomData atomData1 = lst.getObject(i);
if(atomData1.isField()){
list.add(((Field)atomData1).getValue());
}else if(atomData1.isStruct()){
CompositeData lst_bd = ((CompositeData)atomData1);
Iterator<String> lst_iterator = lst_bd.iterator();
Map lst_map = new HashMap<>();
while(lst_iterator.hasNext()){
String lst_child = lst_iterator.next();
Object lst_value = lst_bd.getField(lst_child);
lst_map.put(lst_child,lst_value);
}
list.add(lst_map);
}
}
map.put(child,list);
}
}
return map;
}
public static void mapToBody(CompositeData BODY,Map<String,Object> map){
for(Map.Entry<String,Object> entry:map.entrySet()){
Object value = entry.getValue();
if(value instanceof List){
Array array = new Array();
List lst_value = (List) value;
if(lst_value.size()==0)continue;
if(lst_value.get(0) instanceof Map){
for(Object obj : lst_value){
Map<String,Object> lst_map = (Map) obj;
CompositeData struct= new CompositeData();
for(Map.Entry<String,Object> lst_entry:lst_map.entrySet()){
Object value1 = lst_entry.getValue();
if(value1 instanceof String){
FieldType type = FieldType.getEnum("string");
FieldAttr fieldAttr = new FieldAttr(type,20);
Field field = new Field(fieldAttr);
field.setValue((String)value1);
struct.addField(lst_entry.getKey(),field);
}else if(value1 instanceof BigDecimal){
if(((BigDecimal)value1).scale() == 0){
FieldType type = FieldType.getEnum("long");
FieldAttr fieldAttr = new FieldAttr(type,20);
Field field = new Field(fieldAttr);
field.setValue(((BigDecimal)value1).longValue());
struct.addField(lst_entry.getKey(),field);
}else{
FieldType type = FieldType.getEnum("double");
FieldAttr fieldAttr = new FieldAttr(type,20,((BigDecimal)value1).scale());
Field field = new Field(fieldAttr);
field.setValue(((BigDecimal)value1).doubleValue());
struct.addField(lst_entry.getKey(),field);
}
}
}
array.addStruct(struct);
}
BODY.addArray(entry.getKey(),array);
}else if(lst_value.get(0) instanceof String){
for(Object obj : lst_value){
FieldType type = FieldType.getEnum("string");
FieldAttr fieldAttr = new FieldAttr(type,20);
Field field = new Field(fieldAttr);
field.setValue((String)obj);
array.addField(field);
}
BODY.addArray(entry.getKey(),array);
}else if(lst_value.get(0) instanceof BigDecimal){
for(Object obj : lst_value){
if(((BigDecimal)obj).scale() == 0){
FieldType type = FieldType.getEnum("long");
FieldAttr fieldAttr = new FieldAttr(type,20);
Field field = new Field(fieldAttr);
field.setValue(((BigDecimal)obj).longValue());
array.addField(field);
}else{
FieldType type = FieldType.getEnum("double");
FieldAttr fieldAttr = new FieldAttr(type,20,((BigDecimal)obj).scale());
Field field = new Field(fieldAttr);
field.setValue(((BigDecimal)obj).doubleValue());
array.addField(field);
}
}
BODY.addArray(entry.getKey(),array);
}
}else if(value instanceof String){
FieldType type = FieldType.getEnum("string");
FieldAttr fieldAttr = new FieldAttr(type,20);
Field field = new Field(fieldAttr);
field.setValue((String)value);
BODY.addField(entry.getKey(),field);
}else if(value instanceof BigDecimal){
if(((BigDecimal)value).scale() == 0){
FieldType type = FieldType.getEnum("long");
FieldAttr fieldAttr = new FieldAttr(type,20);
Field field = new Field(fieldAttr);
field.setValue(((BigDecimal)value).longValue());
BODY.addField(entry.getKey(),field);
}else{
FieldType type = FieldType.getEnum("double");
FieldAttr fieldAttr = new FieldAttr(type,20,((BigDecimal)value).scale());
Field field = new Field(fieldAttr);
field.setValue(((BigDecimal)value).doubleValue());
BODY.addField(entry.getKey(),field);
}
}
}
}
}
......@@ -41,9 +41,9 @@
initMethodName="init" deinitMethodName="deinit">
<property name="debugMode" value="false" class="boolean" />
<!-- WAR包本身的目录为变量$ROOT,WAR/WEB-INF/classes目录为变量$HOME -->
<property name="rootPath" value="$ROOT" />
<property name="rootPath" value="f:/resource" />
<!-- 外部资源目录 -->
<property name="resourcePath" value="$ROOT/upload" />
<property name="resourcePath" value="f:/resource/data/loginfile/" />
<!-- 代码转换的实现(可替换,但必须实现ICodetable接口) -->
<property name="tbl" class="org.sss.common.impl.CodetableImpl"
methodName="getInstance">
......@@ -69,53 +69,4 @@
<property name="millises" value="5000,5000" class="long[]" />
<property name="timeouts" value="600000,600000" class="long[]" />
</service>
<!-- <service class="org.sss.presentation.zk.ZkUtils" initMethodName="init" deinitMethodName="deinit">
切换交易是否自动更新整个页面
<property name="autoRefresh" value="true" class="boolean" />
模型仅匹配唯一的UI控件
<property name="distinctID" value="true" class="boolean" />
页面访问是否可缓存
<property name="noCache" value="true" class="boolean" />
应用是否固定标题
<property name="fixTitle" value="false" class="boolean" />
多页面支持时是否固定标题/不随交易变化
<property name="fixTabTitle" value="false" class="boolean" />
通过Enter切换输入焦点
<property name="nextByEnter" value="false" class="boolean" />
交易访问是否做控制
<property name="checkAccess" value="false" class="boolean" />
多页面形式时最大可开数量
<property name="maxTabCount" value="5" class="int" />
是否为调试状态
<property name="debugMode" value="false" class="boolean" />
是否为压力测试状态
<property name="batchTesting" value="false" class="boolean" />
WAR包本身的目录为变量$ROOT,WAR/WEB-INF/classes目录为变量$HOME
<property name="rootPath" value="$ROOT" />
外部资源目录
<property name="resourcePath" value="$ROOT/upload" />
代码转换的实现(可替换,但必须实现ICodetable接口)
<property name="tbl" class="org.sss.common.impl.CodetableImpl" methodName="getInstance">
<property name="homePath" value="$HOME" direct="false" />
</property>
国际化的实现(可替换,但必须实现II18n接口)
<property name="i18n" class="org.sss.common.impl.I18nImpl" />
密码编解码的实现(可替换,但必须实现IFilter接口)
<property name="passwordFilter" class="org.sss.common.impl.PasswordFilter" />
Module工厂实现(不可替换)
<property name="factory" class="org.sss.module.hibernate.ModuleSessionFactory" />
后台应用服务启动用户名
<property name="userName" value="bgUser" />
后台应用服务中断重启间隙时间(单位:毫秒)
<property name="millis" value="5000" class="long" />
后台应用服务超时时间(单位:毫秒)
<property name="timeout" value="600000" class="long" />
关闭时等待后台应用服务退出时间(单位:毫秒)
<property name="waitExit" value="60000" class="long" />
服务列表(以逗号隔开多个服务名,服务名前加下划线忽略后台应用服务超时时间)
<property name="serviceNames" value="" class="java.lang.String[]" />
<property name="userNames" value="bgUser1,bgUser2" class="java.lang.String[]" />
<property name="millises" value="5000,5000" class="long[]" />
<property name="timeouts" value="600000,600000" class="long[]" />
</service> -->
</configuration>
\ No newline at end of file
own_ref=ownref
rem_cur=remcur
\ No newline at end of file
_esytp_select=\\esytp\\select
CLIENT_NO=\\esytp\\dn
CLIENT_NAME=\\esytp\\dnnam
\ No newline at end of file
_tsktp_select=tsktp\\select
_tsktp_tohistory=tsktp\\tohistory
tsktp_jshlst=\\tsktp\\jshlst
CLIENT_NO=tsktp\\dn
CLIENT_NAME=tsktp\\dnnam
BUSS_STATUS=tsktp\\cptsta
START_DATE=tsktp\\stadat
END_DATE=tsktp\\enddat
TRAN_TYPE=tsktp\\tratyp
BUSS_REF_NO=tsktp\\cptref
TRAN_TIME=tsktp\\tradat
\ No newline at end of file
esytp_esslst=\\esytp\\esslst
\ No newline at end of file
tsktp_jshlst=\\tsktp\\jshlst
\ No newline at end of file
ETS_REF_NO=\\tsktp\\jshlst\\ownref
TRAN_CCY=\\tsktp\\jshlst\\relcur
AMT=\\tsktp\\jshlst\\relamt
CLIENT_NAME=\\tsktp\\jshlst\\nam
TRAN_TYPE=\\tsktp\\jshlst\\inifrm
ORI_TRAN_DATE=\\tsktp\\jshlst\\inidattim
BUSS_STATUS=\\tsktp\\jshlst\\sta
\ No newline at end of file
#Fri Jun 05 17:26:13 CST 2020
PD000000=\u4E3B\u9875\u9762
BT000001=\u67E5\u8BE2
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