Commit c10662a1 by gechengyang

修复相关缺陷

parent 037558c4
package org.sss.presentation.noui.controller;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import log.Log;
import log.LogFactory;
import org.sss.common.model.EventType;
import org.sss.common.model.IBaseObject;
import org.sss.common.model.IDatafield;
import org.sss.presentation.noui.api.exception.NoUiException;
import org.sss.presentation.noui.api.model.Alias;
import org.sss.presentation.noui.api.request.NoUiRequest;
import org.sss.presentation.noui.api.response.ErrorCodes;
import org.sss.presentation.noui.api.response.ResultUtil;
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.jwt.RedisLoginInfo;
import org.sss.presentation.noui.util.NoUiPresentationUtil;
import org.sss.presentation.noui.util.RedisUtil;
import org.sss.presentation.noui.util.StringUtil;
public class AbstractCommonController {
protected static final Log log = LogFactory.getLog(AbstractCommonController.class);
protected static String ON_CLICK = "ON_CLICK";
protected static String INIT = "INIT";
protected static String ON_CHANGE = "ON_CHANGE";
protected static String ON_CHECK = "ON_CHECK";
public Object event(String mappingUrl, String eventType, Map<String, Object> dataMap, HttpServletRequest request, HttpSession session) {
NoUiRequest noUiRequest = new NoUiRequest(request, mappingUrl, dataMap);
NoUiContext context = NoUiContextManager.createNoUiContext(noUiRequest);
Alias alias = new Alias(mappingUrl);
String trnName = alias.getTrnName();
// 交易参数赋值
Map<String, ?> paramsMap = noUiRequest.getParamsMap();
for (String key : paramsMap.keySet()) {
context.getSession().storeData(key, paramsMap.get(key));
}
// 设置old sysmod
RedisLoginInfo redisLoginInfo = (RedisLoginInfo) RedisUtil.get(StringUtil.userUniqueId(noUiRequest));
NoUiPresentationUtil.setSysmod(context, (byte[]) redisLoginInfo.getSysmod());
// 交易跳转
context.getSession().chain(true, trnName);
try {
// 模型赋值
NoUiPresentationUtil.hanleInput(context, noUiRequest, alias);
// 不为初始化事件
if (eventType != null && (!eventType.equals(INIT))) {
String aliasActionUrl = alias.getAliasActionUrl();
String actionUrl = alias.getRel().get(aliasActionUrl);
IBaseObject dataField = context.getSession().getBaseObject(context.getRoot(), actionUrl);
if (null == dataField)
throw new NoUiException("onClickUrl :" + actionUrl + "is not exsit");
else {
if (dataField instanceof IDatafield)
if (eventType.equals(ON_CLICK)) {
((IDatafield<?>) dataField).invokeEventRules(context, EventType.ON_CLICK, null);
} else if (eventType.equals(ON_CHANGE)) {
((IDatafield<?>) dataField).invokeEventRules(context, EventType.ON_CHANGE, null);
} else if (eventType.equals(ON_CHECK)) {
for (String aliasKey : alias.getRel().keySet()) {
if (aliasKey.startsWith("_")) {
continue;
}
String realPath = alias.getRelPath(aliasKey);
IBaseObject currentDataField = (IDatafield<?>) context.getSession().getBaseObject(context.getRoot(), realPath);
if (currentDataField instanceof IDatafield<?>) {
((IDatafield<?>) currentDataField).invokeCheckRules(context);
}
}
}
}
}
// 保存新的RedisLoginInfo
byte[] sysmodBytes = NoUiPresentationUtil.sysmodToBytes(context);
redisLoginInfo.setSysmod(sysmodBytes);
RedisUtil.set(StringUtil.userUniqueId(noUiRequest), redisLoginInfo);
return ResultUtil.result(ErrorCodes.SUCCESS, NoUiPresentationUtil.retMsg(context),
handleReturnData(eventType, context, noUiRequest, alias), NoUiPresentationUtil.handleErrorReturnData(context, alias),
NoUiPresentationUtil.handleCodeTableReturnData(context, alias));
} catch (Exception e) {
log.error("OnClick command error", e);
}
return ResultUtil.result(ErrorCodes.ERROR, "提交处理异常", null);
}
private Map<String, Object> handleReturnData(String eventType, NoUiContext context, NoUiRequest request, Alias alias) {
Map<String, Object> data = new HashMap<String, Object>();
// 初始化事件
if (eventType.equals(INIT)) {
for (String aliasKey : alias.getRel().keySet()) {
if (aliasKey.startsWith("_")) {
continue;
}
String realPath = alias.getRelPath(aliasKey);
IBaseObject baseObject = context.getSession().getBaseObject(context.getRoot(), realPath);
data.put(aliasKey, NoUiPresentationUtil.handIBaseObject(context, baseObject, realPath));
}
return data;
}
NoUiPresentation gui = (NoUiPresentation) context.getGui();
Map<String, Object> modifyMap = gui.getModifyMap();
for (Map.Entry<String, Object> modifyEntry : modifyMap.entrySet()) {
for (Map.Entry<String, String> aliasEntry : alias.getRel().entrySet()) {
String aliasKey = aliasEntry.getKey();
String aliasPath = aliasEntry.getValue();
if (aliasPath.startsWith(modifyEntry.getKey())) {
Object val = modifyEntry.getValue();
data.put(aliasKey, NoUiPresentationUtil.handIBaseObject(context, val, aliasEntry.getValue()));
}
}
}
return data;
}
}
...@@ -5,83 +5,28 @@ import java.util.Map; ...@@ -5,83 +5,28 @@ import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import log.Log;
import log.LogFactory;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.sss.common.model.EventType;
import org.sss.common.model.IDatafield;
import org.sss.presentation.noui.api.exception.NoUiException;
import org.sss.presentation.noui.api.model.Alias;
import org.sss.presentation.noui.api.request.NoUiRequest;
import org.sss.presentation.noui.api.response.ErrorCodes;
import org.sss.presentation.noui.api.response.ResultUtil;
import org.sss.presentation.noui.context.NoUiContext;
import org.sss.presentation.noui.context.NoUiContextManager;
import org.sss.presentation.noui.jwt.RedisLoginInfo;
import org.sss.presentation.noui.util.NoUiPresentationUtil;
import org.sss.presentation.noui.util.RedisUtil;
import org.sss.presentation.noui.util.StringUtil;
@Controller @Controller
public class PxiController { public class PxiController extends AbstractCommonController {
private static final Log log = LogFactory.getLog(LoginController.class);
// Event 事件 // Event 事件
@ResponseBody @ResponseBody
@RequestMapping(value = "/pxiadd/_save", method = RequestMethod.POST) @RequestMapping(value = "/pxiadd/_save", method = RequestMethod.POST)
public Object save(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpSession session) { public Object save(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpSession session) {
String mappingUrl = "/pxiadd/_save"; String mappingUrl = "/pxiadd/_save";
NoUiRequest noUiRequest = new NoUiRequest(request, mappingUrl, dataMap); return event(mappingUrl, ON_CLICK, dataMap, request, session);
NoUiContext context = NoUiContextManager.createNoUiContext(noUiRequest);
Alias alias = new Alias(mappingUrl);
String trnName = alias.getTrnName();
// 交易参数赋值
Map<String, ?> paramsMap = noUiRequest.getParamsMap();
for (String key : paramsMap.keySet()) {
context.getSession().storeData(key, paramsMap.get(key));
} }
// 设置old sysmod
RedisLoginInfo redisLoginInfo = (RedisLoginInfo) RedisUtil.get(StringUtil.userUniqueId(noUiRequest));
NoUiPresentationUtil.setSysmod(context, (byte[]) redisLoginInfo.getSysmod());
// 交易跳转
context.getSession().chain(true, trnName);
try {
// 模型赋值
NoUiPresentationUtil.hanleInput(context, noUiRequest, alias);
String aliasActionUrl = alias.getAliasActionUrl();
String actionUrl = alias.getRel().get(aliasActionUrl);
// context.getRoot().bindEvents(context);
IDatafield<?> dataField = (IDatafield<?>) context.getSession().getBaseObject(context.getRoot(), actionUrl); // OnChange 事件
if (null == dataField) @ResponseBody
throw new NoUiException("onClickUrl :" + actionUrl + "is not exsit"); @RequestMapping(value = "/pxiadd/_onchange", method = RequestMethod.POST)
else { public Object onchange(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpSession session) {
if (dataField instanceof IDatafield) String mappingUrl = "/pxiadd/_onchange";
((IDatafield<?>) dataField).invokeEventRules(context, EventType.ON_CLICK, null); return event(mappingUrl, ON_CHANGE, dataMap, request, session);
}
// 保存新的RedisLoginInfo
byte[] sysmodBytes = NoUiPresentationUtil.sysmodToBytes(context);
// IBaseObject sysmod =
// context.getSession().getBaseObject(context.getRoot(), "sysmod");
redisLoginInfo.setSysmod(sysmodBytes);
RedisUtil.set(StringUtil.userUniqueId(noUiRequest), redisLoginInfo);
return ResultUtil.result(ErrorCodes.SUCCESS, NoUiPresentationUtil.retMsg(context),
NoUiPresentationUtil.handleEventReturnData(context, noUiRequest, alias),
NoUiPresentationUtil.handleErrorReturnData(context, alias), NoUiPresentationUtil.handleCodeTableReturnData(context, alias));
} catch (Exception e) {
log.error("OnClick command error", e);
}
return ResultUtil.result(ErrorCodes.ERROR, "提交处理异常", null);
} }
// Event 事件 // Event 事件
...@@ -89,51 +34,14 @@ public class PxiController { ...@@ -89,51 +34,14 @@ public class PxiController {
@RequestMapping(value = "/pxisel/_sel", method = RequestMethod.POST) @RequestMapping(value = "/pxisel/_sel", method = RequestMethod.POST)
public Object sel(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpSession session) { public Object sel(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpSession session) {
String mappingUrl = "/pxisel/_sel"; String mappingUrl = "/pxisel/_sel";
NoUiRequest noUiRequest = new NoUiRequest(request, mappingUrl, dataMap); return event(mappingUrl, ON_CLICK, dataMap, request, session);
NoUiContext context = NoUiContextManager.createNoUiContext(noUiRequest);
Alias alias = new Alias(mappingUrl);
String trnName = alias.getTrnName();
// 交易参数赋值
Map<String, ?> paramsMap = noUiRequest.getParamsMap();
for (String key : paramsMap.keySet()) {
context.getSession().storeData(key, paramsMap.get(key));
} }
// 设置old sysmod
RedisLoginInfo redisLoginInfo = (RedisLoginInfo) RedisUtil.get(StringUtil.userUniqueId(noUiRequest));
NoUiPresentationUtil.setSysmod(context, (byte[]) redisLoginInfo.getSysmod());
// 交易跳转
context.getSession().chain(true, trnName);
try {
// 模型赋值
NoUiPresentationUtil.hanleInput(context, noUiRequest, alias);
String aliasActionUrl = alias.getAliasActionUrl();
String actionUrl = alias.getRel().get(aliasActionUrl);
// context.getRoot().bindEvents(context); // 初始化 事件
@ResponseBody
IDatafield<?> dataField = (IDatafield<?>) context.getSession().getBaseObject(context.getRoot(), actionUrl); @RequestMapping(value = "/pxiame/init", method = RequestMethod.POST)
if (null == dataField) public Object ame(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpSession session) {
throw new NoUiException("onClickUrl :" + actionUrl + "is not exsit"); String mappingUrl = "/pxiame/init";
else { return event(mappingUrl, INIT, dataMap, request, session);
if (dataField instanceof IDatafield)
((IDatafield<?>) dataField).invokeEventRules(context, EventType.ON_CLICK, null);
}
// 保存新的RedisLoginInfo
byte[] sysmodBytes = NoUiPresentationUtil.sysmodToBytes(context);
// IBaseObject sysmod =
// context.getSession().getBaseObject(context.getRoot(), "sysmod");
redisLoginInfo.setSysmod(sysmodBytes);
RedisUtil.set(StringUtil.userUniqueId(noUiRequest), redisLoginInfo);
return ResultUtil.result(ErrorCodes.SUCCESS, NoUiPresentationUtil.retMsg(context),
NoUiPresentationUtil.handleEventReturnData(context, noUiRequest, alias),
NoUiPresentationUtil.handleErrorReturnData(context, alias), NoUiPresentationUtil.handleCodeTableReturnData(context, alias));
} catch (Exception e) {
log.error("OnClick command error", e);
}
return ResultUtil.result(ErrorCodes.ERROR, "提交处理异常", null);
} }
} }
...@@ -18,6 +18,7 @@ import log.LogFactory; ...@@ -18,6 +18,7 @@ import log.LogFactory;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.sss.common.impl.StreamImpl; import org.sss.common.impl.StreamImpl;
import org.sss.common.model.EventType;
import org.sss.common.model.IBaseObject; import org.sss.common.model.IBaseObject;
import org.sss.common.model.IContext; import org.sss.common.model.IContext;
import org.sss.common.model.IDatafield; import org.sss.common.model.IDatafield;
...@@ -164,8 +165,22 @@ public class NoUiPresentationUtil { ...@@ -164,8 +165,22 @@ public class NoUiPresentationUtil {
return StringUtil.isEmpty(gui.getMessage()) ? ErrorCodes.SUCCESS_INFO : gui.getMessage(); return StringUtil.isEmpty(gui.getMessage()) ? ErrorCodes.SUCCESS_INFO : gui.getMessage();
} }
public static Map<String, Object> handleEventReturnData(NoUiContext context, NoUiRequest request, Alias alias) { public static Map<String, Object> handleEventReturnData(EventType eventType, NoUiContext context, NoUiRequest request, Alias alias) {
Map<String, Object> data = new HashMap<String, Object>(); Map<String, Object> data = new HashMap<String, Object>();
// 初始化事件
if (eventType == null) {
for (String aliasKey : alias.getRel().keySet()) {
if (aliasKey.startsWith("_")) {
continue;
}
String realPath = alias.getRelPath(aliasKey);
IBaseObject baseObject = context.getSession().getBaseObject(context.getRoot(), realPath);
data.put(aliasKey, NoUiPresentationUtil.handIBaseObject(context, baseObject, realPath));
}
return data;
}
NoUiPresentation gui = (NoUiPresentation) context.getGui(); NoUiPresentation gui = (NoUiPresentation) context.getGui();
Map<String, Object> modifyMap = gui.getModifyMap(); Map<String, Object> modifyMap = gui.getModifyMap();
for (Map.Entry<String, Object> modifyEntry : modifyMap.entrySet()) { for (Map.Entry<String, Object> modifyEntry : modifyMap.entrySet()) {
...@@ -182,7 +197,7 @@ public class NoUiPresentationUtil { ...@@ -182,7 +197,7 @@ public class NoUiPresentationUtil {
return data; return data;
} }
private static Object handIBaseObject(NoUiContext context, Object val, String path) { public static Object handIBaseObject(NoUiContext context, Object val, String path) {
if (val == null) if (val == null)
return null; return null;
if (val instanceof IModuleList<?>) { if (val instanceof IModuleList<?>) {
......
_save=\\pxip\\sav
nam=\\pxigrp\\rec\\nam
sex=\\pxigrp\\rec\\sex
univer=\\pxigrp\\rec\\univer
major=\\pxigrp\\rec\\major
tel=\\pxigrp\\rec\\tel
headimg=\\pxigrp\\rec\\headimg
age=\\pxigrp\\rec\\age
balance=\\pxigrp\\rec\\balance
\ No newline at end of file
...@@ -22,6 +22,7 @@ public class HttpTest { ...@@ -22,6 +22,7 @@ public class HttpTest {
pxiadd(token, userId, terminalType); pxiadd(token, userId, terminalType);
pxisel(token, userId, terminalType); pxisel(token, userId, terminalType);
pxiame(token, userId, terminalType);
} }
...@@ -95,6 +96,76 @@ public class HttpTest { ...@@ -95,6 +96,76 @@ public class HttpTest {
System.out.println("result=" + result); System.out.println("result=" + result);
} }
public static void pxiame(String token, String userId, String terminalType) {
PrintWriter out = null;
BufferedReader in = null;
String result = "";
try {
// "http://172.17.2.100:8080/oauth/token?username=user_1&password=123456&grant_type=password&client_id=client&client_secret=123456"
URL realUrl = new URL("http://localhost:8080/business/service/pxiame/init");
// URL realUrl = new
// URL("http://localhost:8080/healthServer/getMacSeq");
// 打开和URL之间的连接
URLConnection conn = realUrl.openConnection();
// 设置通用的请求属性
conn.setRequestProperty("accept", "application/json");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("Content-Type", "application/json;charset=utf-8");
conn.addRequestProperty("token", token);
conn.addRequestProperty("userId", userId);
conn.addRequestProperty("terminalType", terminalType);
// 发送POST请求必须设置如下两行
conn.setDoOutput(true);
conn.setDoInput(true);
// 获取URLConnection对象对应的输出流
out = new PrintWriter(conn.getOutputStream());
// 发送请求参数
Map<String, Object> map = new HashMap<String, Object>();
map.put("pxiinr", "00000023");
/*
* map.put("sex", "F"); map.put("univer", "湖北大学"); map.put("major",
* "计算机"); map.put("headimg", "NO IMAGE"); map.put("age", 20);
* map.put("tel", "18912345678"); map.put("balance", 10000);
*/
Map<String, Object> map2 = new HashMap<String, Object>();
map2.put("params", map);
// System.out.println(JSON.toJSON(student));
out.print(new Gson().toJson(map2));
// out.print("abc");
// flush输出流的缓冲
out.flush();
// 定义BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println("发送 POST 请求出现异常!" + e);
e.printStackTrace();
}
// 使用finally块来关闭输出流、输入流
finally {
try {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
System.out.println("result=" + result);
}
public static void pxiadd(String token, String userId, String terminalType) { public static void pxiadd(String token, String userId, String terminalType) {
PrintWriter out = null; PrintWriter out = null;
......
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