SQL结果封装到JSONObject,多条JSONObject封装到一条JSONArray,
JSONArray再将里面的JSONObject一条一条取出,把value值放在ArrayList中,
最终把ArrayList Add到JSONArray。
/**
* 组别人均产出率统计
* @return
*/
public JSONArray getGroupOutputRate(){
String processId = ResourceUtil.getString("improvementProcessId", "sys-operationPortal").trim();
String itDepartmentId = ResourceUtil.getString("itDepartmentId", "sys-operationPortal").trim();
String sql = "SELECT D.FD_ID,D.FD_NAME,D.TOTAL_NUM,D.FINISH_NUM,E.PERSON_NUM,"
+ " ROUND(D.TOTAL_NUM/E.PERSON_NUM,2)PERSON_AVERAGE FROM"
+ " (SELECT B.FD_ID,B.FD_NAME,COUNT(*) TOTAL_NUM,"
+ " NVL(SUM(CASE WHEN A.DOC_STATUS='30'THEN 1 ELSE 0 END),0)FINISH_NUM"
+ " FROM KM_REVIEW_MAIN A"
+ " LEFT JOIN SYS_ORG_ELEMENT B"
+ " ON A.FD_DEPARTMENT_ID = B.FD_ID"
+ " LEFT JOIN KM_REVIEW_TEMPLATE C"
+ " ON A.FD_TEMPLATE_ID = C.FD_ID"
+ " WHERE C.FD_ID = '"+processId+"' AND A.DOC_STATUS != '10' AND A.DOC_STATUS != '00'"
+ " GROUP BY A.FD_DEPARTMENT_ID,B.FD_NAME,B.FD_ID)D LEFT JOIN"
+ " (SELECT A.FD_NAME,A.FD_ID,COUNT(*) PERSON_NUM FROM SYS_ORG_ELEMENT A"
+ " LEFT JOIN SYS_ORG_ELEMENT B"
+ " ON A.FD_PARENTID = B.FD_ID"
+ " LEFT JOIN SYS_ORG_ELEMENT C"
+ " ON C.FD_PARENTID = A.FD_ID"
+ " WHERE B.FD_ID='"+itDepartmentId+"' AND C.FD_ORG_TYPE='8'"
+ " GROUP BY A.FD_ID,A.FD_NAME)E"
+ " ON D.FD_ID = E.FD_ID";
Query query = getBaseDao().getHibernateSession().createSQLQuery(sql);
@SuppressWarnings("unchecked")
List
获取JSONObject数据{"dayRange":[{"TOTAL":1,"DATE":"07-18"},{"TOTAL":2,"DATE":"07-19"}]}
取出dayRange对应的数组数据放入List
将其中的value取出,放入List
最后将List
//根据url接口获取JSON数据,并返回字符串数据 [[Value1.1 , V1.2...],[V2.1 , V2.2...]...]
public static String getJsonList(String Package,String key,String url,String item){
//从Package包下的ApplicationResources.properties中取key的值拼接成地址
String wholeUrl = ResourceUtil.getString(key, Package) + url;// 请求地址
//从URL中获取JSON数据
String result = HttpRequest.sendGet(wholeUrl, "");
//取出JSON数据{"dayRange":[{"TOTAL":1,"DATE":"07-18"},{"TOTAL":2,"DATE":"07-19"}]}
JSONObject json = JSONObject.fromObject(result);
//取出dayRange对应的数组[{},{}]
//JSONArray itemData = (JSONArray) json.get(item);
//取出的数组放在list中[{key1=value1,key2=value2},{}]
List
JSONObject通过List
优化方法:
//优化方法
//根据url接口获取JSON数据,并返回字符串数据 [[Value1.1 , V1.2...],[V2.1 , V2.2...]...]
public static String getJsonString(String Package,String key,String url,String item){
//从Package包下的ApplicationResources.properties中取key的值拼接成地址
String wholeUrl = ResourceUtil.getString(key, Package) + url;// 请求地址
//从URL中获取JSON数据
String result = HttpRequest.sendGet(wholeUrl, "");
//取出JSON数据{"dayRange":[{"TOTAL":1,"DATE":"07-18"},{"TOTAL":2,"DATE":"07-19"}]}
JSONObject json = JSONObject.fromObject(result);
//取出dayRange对应的数组[{},{}]
JSONArray itemData = (JSONArray) json.get(item);
List totalList = new ArrayList();
List responseTimeList = new ArrayList();
List receiveTimeList = new ArrayList();
List scoreList = new ArrayList();
List dateList = new ArrayList();
for(int i=0;i