From 83c80c4be845c6ddb5f1385201e74289d0262598 Mon Sep 17 00:00:00 2001
From: wuxw7 <wuxw7@asiainfo.com>
Date: 星期三, 09 五月 2018 22:39:55 +0800
Subject: [PATCH] 完成 配置方式 页面数据显示

---
 java110-service/src/main/java/com/java110/service/smo/impl/QueryServiceSMOImpl.java |   54 ++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/java110-service/src/main/java/com/java110/service/smo/impl/QueryServiceSMOImpl.java b/java110-service/src/main/java/com/java110/service/smo/impl/QueryServiceSMOImpl.java
index 1ce0ebf..abdf56b 100644
--- a/java110-service/src/main/java/com/java110/service/smo/impl/QueryServiceSMOImpl.java
+++ b/java110-service/src/main/java/com/java110/service/smo/impl/QueryServiceSMOImpl.java
@@ -11,6 +11,7 @@
 import com.java110.common.factory.DataTransactionFactory;
 import com.java110.common.log.LoggerEngine;
 import com.java110.common.util.Assert;
+import com.java110.common.util.StringUtil;
 import com.java110.entity.service.DataQuery;
 import com.java110.entity.service.ServiceSql;
 import com.java110.service.dao.IQueryServiceDAO;
@@ -189,15 +190,11 @@
         JSONArray currentJsonArr = null;
         for(String key:templateParams.keySet()){
             template = templateParams.getString(key);
-            if(!template.startsWith("$.")){
-                throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"template 閰嶇疆 涓嶆纭紝value 蹇呴』浠�$.寮�澶�");
-            }
-            values = template.split("#");
 
-            if(values == null || values.length != 3){
-                throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"template 閰嶇疆 涓嶆纭紝value 蹇呴』鏈変袱涓�#鍙�");
-            }
-            Object o = JSONPath.eval(business,values[0]);
+            values = judgeResponseTemplate(template);
+
+            Object o = JSONPath.eval(business, values[0]);
+
             dataQuery.setTemplateKey(key);
             if(o instanceof JSONObject){
                 currentJsonObj = (JSONObject)o;
@@ -260,12 +257,26 @@
             List<Map<String,Object>> results = queryServiceDAOImpl.executeSql(currentSqlNew, currentParams.toArray());
 
             if (results == null || results.size() == 0) {
+                if(StringUtil.isNullOrNone(values[1])){
+                    return ;
+                }
                 obj.put(values[1], new JSONObject());
                 return;
             }
             if (values[2].equals("Object")) {
+                if(StringUtil.isNullOrNone(values[1])){
+                    obj.putAll(JSONObject.parseObject(JSONObject.toJSONString(results.get(0))));
+                    return ;
+                }
                 obj.put(values[1], JSONObject.parseObject(JSONObject.toJSONString(results.get(0))));
             } else if (values[2].equals("Array")) {
+                if(StringUtil.isNullOrNone(values[1])){
+                    JSONArray datas = JSONArray.parseArray(JSONArray.toJSONString(results));
+                    for(int dataIndex = 0;dataIndex < datas.size();dataIndex ++){
+                        obj.putAll(datas.getJSONObject(dataIndex));
+                    }
+                    return ;
+                }
                 obj.put(values[1], JSONArray.parseArray(JSONArray.toJSONString(results)));
             }
         }catch (Exception e){
@@ -310,6 +321,33 @@
 
 
     /**
+     * 鏍¢獙 杩斿洖妯℃澘
+     * @param template
+     * @return
+     * @throws BusinessException
+     */
+    private String[] judgeResponseTemplate(String template) throws BusinessException{
+
+
+        if(!template.startsWith("$.")){
+            throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"template 閰嶇疆 涓嶆纭紝value 蹇呴』浠�$.寮�澶�");
+        }
+
+        String[] values = template.split("#");
+
+        if(values == null || values.length != 3){
+            throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"template 閰嶇疆 涓嶆纭紝value 蹇呴』鏈変袱涓�#鍙�");
+        }
+
+        if(StringUtil.isNullOrNone(values[1]) && !"$.##Object".equals(template) && !"$.##Array".equals(template)){
+            throw new BusinessException(ResponseConstant.RESULT_CODE_INNER_ERROR,"template 閰嶇疆 涓嶆纭紝鐩墠鍙敮鎸� $.##Object 鍜� $.##Array ");
+        }
+
+        return values;
+    }
+
+
+    /**
      * 鎵ц瀛樺偍
      * @param dataQuery
      */

--
Gitblit v1.8.0