haha600 преди 5 години
родител
ревизия
3e2b6e59b6
променени са 2 файла, в които са добавени 51 реда и са изтрити 4 реда
  1. 8 2
      src/main/java/com/kingkong/bljs/service/QueryService.java
  2. 43 2
      src/main/java/com/kingkong/bljs/service/RestService.java

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

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

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

@@ -1,8 +1,10 @@
1 1
 package com.kingkong.bljs.service;
2 2
 
3 3
 
4
+import com.alibaba.fastjson.JSONObject;
4 5
 import com.kingkong.bljs.dao.UserApiMapper;
5 6
 import com.kingkong.bljs.entity.UserApi;
7
+import org.apache.catalina.User;
6 8
 import org.springframework.beans.factory.annotation.Autowired;
7 9
 import org.springframework.stereotype.Service;
8 10
 
@@ -12,6 +14,12 @@ public class RestService {
12 14
     @Autowired
13 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 25
      * @param code  资源标志
@@ -19,16 +27,34 @@ public class RestService {
19 27
      * @return
20 28
      */
21 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 31
         if(null == api)
24 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 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 64
      * @throws Exception
39 65
      */
40 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 82
         return null;
42 83
     }
43 84
 }