Commit 7d0515d6 by fukai

支持分页

parent 1bf77695
......@@ -16,8 +16,10 @@ public class NoUiRequest {
private String mappingUrl;
private boolean openSource;
private Map<String, ?> paramsMap = new HashMap<String, Object>();
private Map<String, ?> paginationMap = new HashMap<String, Object>();
private Map<String, ?> dataMap = new HashMap<String, Object>();
private Map<String, ?> saveDisplayMap = new HashMap<String, Object>();
private boolean isSecurity=false;
private String reqUrl;
private String trnName;
......@@ -56,12 +58,15 @@ public class NoUiRequest {
this.paramsMap = (Map<String, ?>) requestData.get(Constants.PARAMS);
this.dataMap = (Map<String, ?>) requestData.get(Constants.DATA);
this.saveDisplayMap = (Map<String, ?>) requestData.get(Constants.DISPLAY);
this.paginationMap = (Map<String, ?>) requestData.get(Constants.PAGINATION);
if (this.paramsMap == null)
this.paramsMap = new HashMap<String, Object>();
if (this.dataMap == null)
this.dataMap = new HashMap<String, Object>();
if (this.saveDisplayMap == null)
this.saveDisplayMap = new HashMap<String, Object>();
if (this.paginationMap == null)
this.paginationMap = new HashMap<>();
}
}
......@@ -144,4 +149,12 @@ public class NoUiRequest {
public String getTrnName() {
return trnName;
}
public Map<String, ?> getPaginationMap() {
return paginationMap;
}
public void setPaginationMap(Map<String, ?> paginationMap) {
this.paginationMap = paginationMap;
}
}
......@@ -8,6 +8,7 @@ public class Result {
private String retmsg;
private Map<String, Object> error;// 错误信息
private Map<String, Object> codetable;
private Object pagination;
private Object data;
private String verison;
private static final String EMPTY="";
......@@ -79,4 +80,12 @@ public class Result {
public void setCodetable(Map<String, Object> codetable) {
this.codetable = codetable;
}
public Object getPagination() {
return pagination;
}
public void setPagination(Object pagination) {
this.pagination = pagination;
}
}
......@@ -12,6 +12,13 @@ public class ResultUtil {
return new Result(retcod, retmsg, error, codetable, data,version);
}
public static Result result(String retcod, String retmsg, Map<String, Object> data,Map<String, Object> paginationData, Map<String, Object> error, Map<String, Object> codetable,String version) {
Result result = new Result(retcod, retmsg, error, codetable, data,version);
if(!paginationData.isEmpty())
result.setPagination(paginationData);
return result;
}
public static Result result(String retcod, String retmsg, Object data) {
return new Result(retcod, retmsg, data,DEFAULT_VERSION);
}
......
......@@ -19,4 +19,8 @@ public class Constants {
public final static String SESSION = "session";
public final static String BACKGROUND_FLAG = "BackGroundRequest-";
public static final String PAGINATION = "pagination";
public static final String PAGINATION_INDEX = "index";
public static final String PAGINATION_PAGESIZE = "pageSize";
public static final String PAGINATION_TOTAL = "total";
}
......@@ -163,9 +163,8 @@ public abstract class AbstractCommonController {
redisLoginInfo.setSysmod(sysmodBytes);
RedisUtil.set(StringUtil.userUniqueId(noUiRequest), redisLoginInfo);
}
Map<String, Object> afterReturnData = handleReturnData(eventType, context, noUiRequest, alias);
Map<String, Object> paginationData = new HashMap<>();
Map<String, Object> afterReturnData = handleReturnData(eventType, context, noUiRequest, alias,paginationData);
//数据安全性拦截-篡改数据加密
if (DataSecurityUtil.isSafeMode() && noUiRequest.isSecurity()) {
if (DataSecurityUtil.needEncrypt(noUiRequest.getReqUrl())) {
......@@ -176,7 +175,7 @@ public abstract class AbstractCommonController {
}
}
ret = ResultUtil.result(NoUiPresentationUtil.retCode(context), NoUiPresentationUtil.retMsg(context), afterReturnData,
ret = ResultUtil.result(NoUiPresentationUtil.retCode(context), NoUiPresentationUtil.retMsg(context), afterReturnData,paginationData,
NoUiPresentationUtil.handleErrorReturnData(context, alias), NoUiPresentationUtil.handleCodeTableReturnData(context, alias), noUiVersion.getVersion());
} catch (Exception e) {
log.error("OnClick command error", e);
......@@ -200,7 +199,19 @@ public abstract class AbstractCommonController {
return baseObject;
}
private Map<String, Object> handleReturnData(String eventType, NoUiContext context, NoUiRequest noUiRequest, Alias alias) {
private void putModuleListPagination(String aliasKey,Map<String,Object> paginationMap,IModuleList moduleList)
{
//没有做分页
if(moduleList.getPageSize() == 0)
return;
int total = moduleList.fullSize();
int index = moduleList.getPage();
Map<String,Integer> map = new HashMap<>();
map.put("total",total);
map.put("index",index);
paginationMap.put(aliasKey,map);
}
private Map<String, Object> handleReturnData(String eventType, NoUiContext context, NoUiRequest noUiRequest, Alias alias, Map<String,Object> paginationMap) {
Map<String, Object> data = new HashMap<String, Object>();
// 初始化事件
......@@ -211,7 +222,10 @@ public abstract class AbstractCommonController {
}
String realPath = alias.getRelPath(aliasKey);
IBaseObject baseObject = context.getSession().getBaseObject(context.getRoot(), realPath);
if( baseObject instanceof IModuleList)
{
putModuleListPagination( aliasKey,paginationMap,(IModuleList)baseObject);
}
data.put(aliasKey, NoUiPresentationUtil.handIBaseObject(context, baseObject, realPath));
}
return data;
......@@ -240,6 +254,10 @@ public abstract class AbstractCommonController {
Object val = modifyEntry.getValue();
if (aliasKey == null)
continue;
if( val instanceof IModuleList)
{
putModuleListPagination(aliasKey,paginationMap,(IModuleList)val);
}
data.put(aliasKey, NoUiPresentationUtil.handIBaseObject(context, val, aliasEntry.getValue()));
containsKeys.add(modifyEntry.getKey());
}
......@@ -256,7 +274,12 @@ public abstract class AbstractCommonController {
System.out.println("modify moduleList:" + (modifyMap.get(key) instanceof IModuleList));
if (key == null)
continue;
data.put(key, NoUiPresentationUtil.handIBaseObject(context, modifyMap.get(key), key));
Object baseObject = modifyMap.get(key);
if( baseObject instanceof IModuleList)
{
putModuleListPagination(key,paginationMap,(IModuleList)baseObject);
}
data.put(key, NoUiPresentationUtil.handIBaseObject(context, baseObject, key));
}
}
......
......@@ -73,6 +73,34 @@ public class NoUiPresentationUtil {
}
//处理分页信息
Map<String,?> paginationMap = request.getPaginationMap();
for (String aliasKey : paginationMap.keySet()) {
String url = alias.getRelPath(aliasKey);
if (StringUtils.isEmpty(url)) {
url = aliasKey;
}
IBaseObject baseObject = null;
try {
System.out.println("url=" + url);
baseObject = context.getSession().getBaseObject(context.getRoot(), url);
if (null == baseObject) {
throw new NoUiException("not found url :" + url + " ,alias name is:" + aliasKey);
}
if(!(baseObject instanceof IModuleList))
throw new NoUiException( url + " is not a moduleList");
//处理分页信息
IModuleList moduleList = (IModuleList) baseObject;
Map<String,Integer> paginationItem = (Map<String,Integer>)paginationMap.get(aliasKey);
moduleList.setPageSize(paginationItem.get(Constants.PAGINATION_PAGESIZE));
moduleList.setPage(paginationItem.get(Constants.PAGINATION_INDEX));
} catch (Exception e) {
log.error("Pagination command error", e);
throw new NoUiException("Pagination command error", e);
}
}
}
private static void handleDatafield(IContext context, IDatafield<Object> dataField, Object value) {
......@@ -236,42 +264,24 @@ public class NoUiPresentationUtil {
public static Object handIBaseObject(IContext context, Object val, String path) {
if (val == null)
return null;
if (val instanceof IModuleList<?>) {
List<Map<String, Object>> list = new ArrayList<>();
IModuleList<?> moduleList = (IModuleList<?>) val;
List<String> cacheRecord = new ArrayList<>();
String paramsKey[] = BizKeySetManager.getParamKeys(moduleList);
String params[] = new String[paramsKey.length];
//是否需要缓存
boolean needCache = BizKeySetManager.isModueListNeedCache(context.getSession().getTransName(),path);
if ((val instanceof IModuleList)) {
List list = new ArrayList();
IModuleList moduleList = (IModuleList)val;
for (int index = 0; index < moduleList.size(); index++) {
Map<String, Object> map = new HashMap<>();
IModule module = moduleList.get(index);
Map map = new HashMap();
IModule module = (IModule)moduleList.get(index);
Collection<IDatafield> datafields = module.getDatafields();
for (IDatafield<Object> datafield : datafields) {
String value = handle(datafield.getValue(), datafield);
String colName = datafield.getName();
map.put(changeForELCS(colName), value);
if(needCache) { //拷贝值进入params
copyValueToParamsArr(paramsKey,params,colName,value);
}
}
if(needCache)
{
cacheRecord.add(transParamsToString(params));
for (IDatafield datafield : datafields) {
map.put(changeForELCS(datafield.getName()), handle(datafield.getValue(), datafield));
}
list.add(map);
}
if(needCache) //进入redis缓存
BizKeySetManager.cacheDataKeys(cacheRecord.toArray(new String[0]));
return list;
} else if (val instanceof IModule) {
}if ((val instanceof IModule)) {
val = context.getSession().getBaseObject(context.getRoot(), path);
return handIBaseObject(context, val, path);
} else if (val instanceof IDatafield) {
IDatafield datafield = (IDatafield) val;
}if ((val instanceof IDatafield)) {
IDatafield datafield = (IDatafield)val;
return handle(datafield.getValue(), datafield);
}
return 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