Commit 7ce81cf7 by gechengyang

完成查询、修改、初始化、CHECK验证

parent 302b2534
...@@ -572,6 +572,7 @@ public class Pxip ...@@ -572,6 +572,7 @@ public class Pxip
//准备目录 //准备目录
String relativeFolder = "header"; String relativeFolder = "header";
String path = ContainerUtils.catPath(ctx.getGui().getRootPath(),relativeFolder); String path = ContainerUtils.catPath(ctx.getGui().getRootPath(),relativeFolder);
log.info(getOrder(),"file path="+path);
if(!ContainerUtils.fileExists(path)) if(!ContainerUtils.fileExists(path))
{ {
ContainerUtils.fileMkdirs(path); ContainerUtils.fileMkdirs(path);
......
...@@ -14,8 +14,8 @@ public class NoUiRequest { ...@@ -14,8 +14,8 @@ public class NoUiRequest {
private String userId; private String userId;
private String terminalType;// WEB APP private String terminalType;// WEB APP
private String mappingUrl; private String mappingUrl;
private Map<String, ?> paramsMap; private Map<String, ?> paramsMap = new HashMap<String, Object>();
private Map<String, ?> dataMap; private Map<String, ?> dataMap = new HashMap<String, Object>();
public NoUiRequest(HttpServletRequest request, String mappingUrl, Map<String, ?> requestData) { public NoUiRequest(HttpServletRequest request, String mappingUrl, Map<String, ?> requestData) {
String tokenId = request.getHeader("token"); String tokenId = request.getHeader("token");
......
package org.sss.presentation.noui.controller; package org.sss.presentation.noui.controller;
import java.io.ByteArrayOutputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpServletResponse;
import log.Log; import log.Log;
import log.LogFactory; import log.LogFactory;
import org.apache.commons.io.IOUtils;
import org.sss.common.model.EventType; import org.sss.common.model.EventType;
import org.sss.common.model.IBaseObject; import org.sss.common.model.IBaseObject;
import org.sss.common.model.IDatafield; import org.sss.common.model.IDatafield;
import org.sss.common.model.IStream;
import org.sss.presentation.noui.api.exception.NoUiException; import org.sss.presentation.noui.api.exception.NoUiException;
import org.sss.presentation.noui.api.model.Alias; import org.sss.presentation.noui.api.model.Alias;
import org.sss.presentation.noui.api.request.NoUiRequest; import org.sss.presentation.noui.api.request.NoUiRequest;
...@@ -32,8 +35,11 @@ public class AbstractCommonController { ...@@ -32,8 +35,11 @@ public class AbstractCommonController {
protected static String INIT = "INIT"; protected static String INIT = "INIT";
protected static String ON_CHANGE = "ON_CHANGE"; protected static String ON_CHANGE = "ON_CHANGE";
protected static String ON_CHECK = "ON_CHECK"; protected static String ON_CHECK = "ON_CHECK";
protected static String ON_STREAM_UPLOAD = "ON_STREAM_UPLOAD";
protected static String ON_STREAM_DOWNLOAD = "ON_STREAM_DOWNLOAD";
public Object event(String mappingUrl, String eventType, Map<String, Object> dataMap, HttpServletRequest request, HttpSession session) { @SuppressWarnings("unchecked")
public Object event(String mappingUrl, String eventType, Map<String, Object> dataMap, HttpServletRequest request, HttpServletResponse response) {
try { try {
NoUiRequest noUiRequest = new NoUiRequest(request, mappingUrl, dataMap); NoUiRequest noUiRequest = new NoUiRequest(request, mappingUrl, dataMap);
NoUiContext context = NoUiContextManager.createNoUiContext(noUiRequest); NoUiContext context = NoUiContextManager.createNoUiContext(noUiRequest);
...@@ -71,6 +77,27 @@ public class AbstractCommonController { ...@@ -71,6 +77,27 @@ public class AbstractCommonController {
((IDatafield<?>) currentDataField).invokeCheckRules(context); ((IDatafield<?>) currentDataField).invokeCheckRules(context);
} }
} }
} else if (eventType.equals(ON_STREAM_UPLOAD)) {
@SuppressWarnings("rawtypes")
IDatafield dataField = (IDatafield) baseObject(context, noUiRequest, alias);
IStream stream = (IStream) dataField.getValue();
byte[] data = new byte[1024];
int bytes = 0;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while ((bytes = request.getInputStream().read(data)) != -1) {
bos.write(data, 0, bytes);
}
IOUtils.write(bos.toByteArray(), stream.getOutputStream());
IOUtils.closeQuietly(bos);
// dataField.setValue(stream);
dataField.invokeEventRules(context, EventType.ON_STREAM_UPLOAD, null);
} else if (eventType.equals(ON_STREAM_DOWNLOAD)) {
@SuppressWarnings("rawtypes")
IDatafield dataField = (IDatafield) baseObject(context, noUiRequest, alias);
IStream stream = (IStream) dataField.getValue();
byte[] data = IOUtils.readFully(stream.getInputStream(), (int) stream.size());
dataField.invokeEventRules(context, EventType.ON_STREAM_DOWNLOAD, null);
IOUtils.write(data, response.getOutputStream());
} }
// 保存新的RedisLoginInfo // 保存新的RedisLoginInfo
......
...@@ -3,7 +3,7 @@ package org.sss.presentation.noui.controller; ...@@ -3,7 +3,7 @@ package org.sss.presentation.noui.controller;
import java.util.Map; import java.util.Map;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
...@@ -16,40 +16,46 @@ public class PxiController extends AbstractCommonController { ...@@ -16,40 +16,46 @@ public class PxiController extends AbstractCommonController {
// 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, HttpServletResponse response) {
String mappingUrl = "/pxiadd/_save"; String mappingUrl = "/pxiadd/_save";
return event(mappingUrl, ON_CLICK, dataMap, request, session); return event(mappingUrl, ON_CLICK, dataMap, request, response);
} }
// OnChange 事件 // OnChange 事件
@ResponseBody @ResponseBody
@RequestMapping(value = "/pxiadd/_onchange", method = RequestMethod.POST) @RequestMapping(value = "/pxiadd/_onchange", method = RequestMethod.POST)
public Object onchange(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpSession session) { public Object onchange(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpServletResponse response) {
String mappingUrl = "/pxiadd/_onchange"; String mappingUrl = "/pxiadd/_onchange";
return event(mappingUrl, ON_CHANGE, dataMap, request, session); return event(mappingUrl, ON_CHANGE, dataMap, request, response);
} }
// Event 事件 // Event 事件
@ResponseBody @ResponseBody
@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, HttpServletResponse response) {
String mappingUrl = "/pxisel/_sel"; String mappingUrl = "/pxisel/_sel";
return event(mappingUrl, ON_CLICK, dataMap, request, session); return event(mappingUrl, ON_CLICK, dataMap, request, response);
} }
// 初始化 事件 // 初始化 事件
@ResponseBody @ResponseBody
@RequestMapping(value = "/pxiame/init", method = RequestMethod.POST) @RequestMapping(value = "/pxiame/init", method = RequestMethod.POST)
public Object init(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpSession session) { public Object init(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpServletResponse response) {
String mappingUrl = "/pxiame/init"; String mappingUrl = "/pxiame/init";
return event(mappingUrl, INIT, dataMap, request, session); return event(mappingUrl, INIT, dataMap, request, response);
} }
// 初始化 事件
@ResponseBody @ResponseBody
@RequestMapping(value = "/pxisel/check", method = RequestMethod.POST) @RequestMapping(value = "/pxisel/check", method = RequestMethod.POST)
public Object change(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpSession session) { public Object change(@RequestBody Map<String, Object> dataMap, HttpServletRequest request, HttpServletResponse response) {
String mappingUrl = "/pxisel/check"; String mappingUrl = "/pxisel/check";
return event(mappingUrl, ON_CHECK, dataMap, request, session); return event(mappingUrl, ON_CHECK, dataMap, request, response);
}
@ResponseBody
@RequestMapping(value = "/pxiadd/_upload", method = RequestMethod.POST)
public Object upload(HttpServletRequest request, HttpServletResponse response) {
String mappingUrl = "/pxiadd/_upload";
return event(mappingUrl, ON_STREAM_UPLOAD, null, request, response);
} }
} }
_save=\\pxip\\sav _save=\\pxip\\sav
_upload=\\pxip\\upload
nam=\\pxigrp\\rec\\nam nam=\\pxigrp\\rec\\nam
sex=\\pxigrp\\rec\\sex sex=\\pxigrp\\rec\\sex
univer=\\pxigrp\\rec\\univer univer=\\pxigrp\\rec\\univer
......
...@@ -20,13 +20,86 @@ public class HttpTest { ...@@ -20,13 +20,86 @@ public class HttpTest {
Map<String, Object> map2 = (Map<String, Object>) map1.get("data"); Map<String, Object> map2 = (Map<String, Object>) map1.get("data");
String token = (String) map2.get("token"); String token = (String) map2.get("token");
pxiadd(token, userId, terminalType); // pxiadd(token, userId, terminalType);
// pxisel(token, userId, terminalType); // pxisel(token, userId, terminalType);
// pxiame(token, userId, terminalType); // pxiame(token, userId, terminalType);
// check(token, userId, terminalType); // check(token, userId, terminalType);
upload(token, userId, terminalType);
} }
public static void upload(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/pxiadd/_upload");
// 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("nam", "gcy");
map.put("major", "M");
/*
* 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("data", map);
String str = "1234";
// System.out.println(JSON.toJSON(student));
out.print(str);
// 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 check(String token, String userId, String terminalType) { public static void check(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