haha600 5 years ago
parent
commit
3e2b6e59b6

+ 8 - 2
src/main/java/com/kingkong/bljs/service/QueryService.java

@@ -232,7 +232,10 @@ public class QueryService {
232
         JObject params = querier.getJObject("params");
232
         JObject params = querier.getJObject("params");
233
         strSQL = this.parserCondition(strSQL,params);
233
         strSQL = this.parserCondition(strSQL,params);
234
 
234
 
235
-        String tmp =  this.parserSort(strSQL,querier.get("sort"));
235
+
236
+        String tmp = strSQL;
237
+        if(querier.containsKey("sort"))
238
+            tmp =  this.parserSort(strSQL,querier.get("sort"));
236
 
239
 
237
         int[] pages = this.parserPagination(tmp,querier.get("page"));
240
         int[] pages = this.parserPagination(tmp,querier.get("page"));
238
 
241
 
@@ -410,7 +413,10 @@ public class QueryService {
410
     private int[] parserPagination(String strSQL,Object page){
413
     private int[] parserPagination(String strSQL,Object page){
411
         int pi = 1;
414
         int pi = 1;
412
         int ps = 10;
415
         int ps = 10;
413
-        if(page instanceof  String){
416
+        if(null == page){
417
+
418
+        }
419
+        else if(page instanceof  String){
414
             String[] arr = page.toString().split(",");
420
             String[] arr = page.toString().split(",");
415
             pi = Integer.parseInt(arr[0]);
421
             pi = Integer.parseInt(arr[0]);
416
             ps = Integer.parseInt(arr[1]);
422
             ps = Integer.parseInt(arr[1]);

+ 43 - 2
src/main/java/com/kingkong/bljs/service/RestService.java

@@ -1,8 +1,10 @@
1
 package com.kingkong.bljs.service;
1
 package com.kingkong.bljs.service;
2
 
2
 
3
 
3
 
4
+import com.alibaba.fastjson.JSONObject;
4
 import com.kingkong.bljs.dao.UserApiMapper;
5
 import com.kingkong.bljs.dao.UserApiMapper;
5
 import com.kingkong.bljs.entity.UserApi;
6
 import com.kingkong.bljs.entity.UserApi;
7
+import org.apache.catalina.User;
6
 import org.springframework.beans.factory.annotation.Autowired;
8
 import org.springframework.beans.factory.annotation.Autowired;
7
 import org.springframework.stereotype.Service;
9
 import org.springframework.stereotype.Service;
8
 
10
 
@@ -12,6 +14,12 @@ public class RestService {
12
     @Autowired
14
     @Autowired
13
     private UserApiMapper userApiMapper;
15
     private UserApiMapper userApiMapper;
14
 
16
 
17
+    @Autowired
18
+    private QueryService queryService;
19
+
20
+    @Autowired
21
+    private ModuleService moduleService;
22
+
15
     /**
23
     /**
16
      * 资源查询
24
      * 资源查询
17
      * @param code  资源标志
25
      * @param code  资源标志
@@ -19,16 +27,34 @@ public class RestService {
19
      * @return
27
      * @return
20
      */
28
      */
21
     public Object getData(String code,String request) throws Exception{
29
     public Object getData(String code,String request) throws Exception{
22
-        UserApi api = userApiMapper.findByCodeAndType(code,1);
30
+        UserApi api = userApiMapper.findByCodeAndType(code,0);
23
         if(null == api)
31
         if(null == api)
24
             throw new Exception("未找到操作 " + code);
32
             throw new Exception("未找到操作 " + code);
25
 
33
 
26
 
34
 
27
-
35
+        if(0 == api.getType()) {
36
+            return sqlAction(api,request);
37
+        }
38
+        else if(1 == api.getType()){ //存储过程
39
+            throw new Exception("未实现的的操作!");
40
+        }
41
+        else if(2 == api.getType()) { //JS
42
+            return jsAction(api,request);
43
+        }
28
 
44
 
29
         return null;
45
         return null;
30
     }
46
     }
31
 
47
 
48
+    private Object jsAction(UserApi api,String request) throws Exception{
49
+        JSONObject object = JSONObject.parseObject(request);
50
+        return moduleService.batchOperation(api.getContent(),object);
51
+    }
52
+
53
+    private Object sqlAction(UserApi api,String request) {
54
+        String strSQL = api.getContent();
55
+        return queryService.quickQuery(strSQL,request);
56
+    }
57
+
32
 
58
 
33
     /**
59
     /**
34
      * 更新操作
60
      * 更新操作
@@ -38,6 +64,21 @@ public class RestService {
38
      * @throws Exception
64
      * @throws Exception
39
      */
65
      */
40
     public Object post(String code,String request) throws Exception{
66
     public Object post(String code,String request) throws Exception{
67
+        UserApi api = userApiMapper.findByCodeAndType(code,1);
68
+        if(null == api)
69
+            throw new Exception("未找到操作 " + code);
70
+
71
+        if(0 == api.getType()) {
72
+            //return sqlAction(api,request);
73
+            throw new Exception("未实现的的操作!");
74
+        }
75
+        else if(1 == api.getType()){ //存储过程
76
+            //TODO
77
+        }
78
+        else if(2 == api.getType()) { //JS
79
+            return jsAction(api,request);
80
+        }
81
+
41
         return null;
82
         return null;
42
     }
83
     }
43
 }
84
 }