data.jsp 3.83 KB
<%@page import="com.weaver.formmodel.util.StringHelper"%>
<%@page import="net.sf.json.JSONArray"%>
<%@page import="net.sf.json.JSONObject"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.List"%>
<%@page import="weaver.general.Util"%>
<%@ page import="java.net.URLDecoder" %>
<%@ page import="java.io.UnsupportedEncodingException" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ include file="/mobilemode/mobile/base.jsp"%>
<%
int pageNo = Util.getIntValue(request.getParameter("pageNo"), 1);
int pageSize = Util.getIntValue(request.getParameter("pageSize"), 10);
int ctype = Util.getIntValue(request.getParameter("ctype"), -1);
String searchKey = Util.null2String(request.getParameter("searchKey"));
try {
	searchKey = URLDecoder.decode(searchKey, "utf-8");
} catch (UnsupportedEncodingException e1) {
	e1.printStackTrace();
}

List<JSONObject> originDatas = new ArrayList<JSONObject>();
originDatas.add(JSONObject.fromObject("{'id':'1','type':'1','avatar':'/mobilemode/mobile/demo/plugin/UserAvatar/avatar.jpg', 'title':'热烈欢迎朱锟加入EBU技术中心','content':'2015梦想羊帆起航,EBU携手SME共创未来…', 'cat':'人事新闻', 'date':'2017-08-09','tel':'18888888888', 'email':'admin@admin.com'}"));
originDatas.add(JSONObject.fromObject("{'id':'2','type':'2','avatar':'/mobilemode/mobile/demo/plugin/UserAvatar/avatar.jpg', 'title':'2012年6月份泛微销售业绩排行榜','content':'EBU携手SME共创未来…', 'cat':'公司新闻', 'date':'2017-07-09','tel':'18888888888', 'email':'admin@admin.com'}"));
originDatas.add(JSONObject.fromObject("{'id':'3','type':'1','avatar':'/mobilemode/mobile/demo/plugin/UserAvatar/avatar.jpg', 'title':'热烈欢迎靳志远加入SME事业本部','content':'2015梦想羊帆起航,EBU携手SME共创未来…', 'cat':'人事新闻', 'date':'2017-06-09','tel':'18888888888', 'email':'admin@admin.com'}"));
originDatas.add(JSONObject.fromObject("{'id':'4','type':'2','avatar':'/mobilemode/mobile/demo/plugin/UserAvatar/avatar.jpg', 'title':'2012年3月份泛微销售业绩排行榜','content':'', 'cat':'公司新闻', 'date':'2017-08-09','tel':'18888888888', 'email':'admin@admin.com'}"));
originDatas.add(JSONObject.fromObject("{'id':'5','type':'0','avatar':'/mobilemode/mobile/demo/plugin/UserAvatar/avatar.jpg', 'title':'泛微OA签约上海电驱动股份有限公司','content':'梦想羊帆起航,EBU携手SME共创未来…', 'cat':'签约新闻', 'date':'2017-08-10','tel':'18888888888', 'email':'admin@admin.com'}"));
originDatas.add(JSONObject.fromObject("{'id':'6','type':'2','avatar':'/mobilemode/mobile/demo/plugin/UserAvatar/avatar.jpg', 'title':'2012年4月份泛微销售业绩排行榜','content':'', 'cat':'公司新闻', 'date':'2017-07-22'}"));
originDatas.add(JSONObject.fromObject("{'id':'7','type':'3','avatar':'/mobilemode/mobile/demo/plugin/UserAvatar/avatar.jpg', 'title':'2015年5月产品改进建议奖','content':'最多建议奖:奖金总额500元, 由每个月建议数(未经处理的客户建议不计)最多者获取', 'cat':'产品建议', 'date':'2017-08-09','tel':'18888888888', 'email':'admin@admin.com'}"));

int startIndex = (pageNo - 1) * pageSize;
int endIndex = startIndex + pageSize;

List<JSONObject> datas = new ArrayList<JSONObject>();
for(JSONObject obj : originDatas){
	int type = obj.getInt("type");
	if(ctype == -1){
		datas.add(obj);
	}else if(ctype == type){
		datas.add(obj);
	}
}

List<JSONObject> result = new ArrayList<JSONObject>();
for(JSONObject obj : datas){
	String title = obj.getString("title");
	if(StringHelper.isNotEmpty(searchKey)){
		if(title.indexOf(searchKey) != -1){
			result.add(obj);
		}
	}else{
		result.add(obj);
	}
}
int size = result.size();
JSONObject json = new JSONObject();
json.put("totalSize", size);
json.put("datas", JSONArray.fromObject(result.subList(startIndex, endIndex > size ? size : endIndex)));
out.print(json);
%>