|
@@ -1,13 +1,18 @@
|
1
|
1
|
package com.kingkong.bljs.service;
|
2
|
2
|
|
3
|
3
|
|
|
4
|
+import com.alibaba.fastjson.JSONArray;
|
4
|
5
|
import com.alibaba.fastjson.JSONObject;
|
5
|
6
|
import com.kingkong.bljs.dao.UserApiMapper;
|
6
|
7
|
import com.kingkong.bljs.entity.UserApi;
|
|
8
|
+import com.kingkong.bljs.util.ListUtil;
|
7
|
9
|
import org.apache.catalina.User;
|
8
|
10
|
import org.springframework.beans.factory.annotation.Autowired;
|
9
|
11
|
import org.springframework.stereotype.Service;
|
10
|
12
|
|
|
13
|
+import java.util.ArrayList;
|
|
14
|
+import java.util.List;
|
|
15
|
+
|
11
|
16
|
@Service
|
12
|
17
|
public class RestService {
|
13
|
18
|
|
|
@@ -39,15 +44,15 @@ public class RestService {
|
39
|
44
|
throw new Exception("未实现的的操作!");
|
40
|
45
|
}
|
41
|
46
|
else if(2 == api.getType()) { //JS
|
42
|
|
- return jsAction(api,request);
|
|
47
|
+ JSONObject object = JSONObject.parseObject(request);
|
|
48
|
+ return jsAction(api,object);
|
43
|
49
|
}
|
44
|
50
|
|
45
|
51
|
return null;
|
46
|
52
|
}
|
47
|
53
|
|
48
|
|
- private Object jsAction(UserApi api,String request) throws Exception{
|
49
|
|
- JSONObject object = JSONObject.parseObject(request);
|
50
|
|
- return moduleService.batchOperation(api.getContent(),object);
|
|
54
|
+ private Object jsAction(UserApi api,Object request) throws Exception{
|
|
55
|
+ return moduleService.batchOperation(api.getContent(),request);
|
51
|
56
|
}
|
52
|
57
|
|
53
|
58
|
private Object sqlAction(UserApi api,String request) {
|
|
@@ -76,7 +81,40 @@ public class RestService {
|
76
|
81
|
//TODO
|
77
|
82
|
}
|
78
|
83
|
else if(2 == api.getType()) { //JS
|
79
|
|
- return jsAction(api,request);
|
|
84
|
+ JSONObject object = JSONObject.parseObject(request);
|
|
85
|
+ return jsAction(api,object);
|
|
86
|
+ }
|
|
87
|
+
|
|
88
|
+ return null;
|
|
89
|
+ }
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+ /**
|
|
93
|
+ * 删除操作
|
|
94
|
+ * @param code api
|
|
95
|
+ * @param params 参数
|
|
96
|
+ * @return
|
|
97
|
+ */
|
|
98
|
+ public Object delete(String code,String params) throws Exception{
|
|
99
|
+ UserApi api = userApiMapper.findByCodeAndType(code,2);
|
|
100
|
+ if(null == api)
|
|
101
|
+ throw new Exception("未找到操作 " + code);
|
|
102
|
+
|
|
103
|
+ if(0 == api.getType()) { //SQL
|
|
104
|
+ throw new Exception("未实现的的操作!");
|
|
105
|
+ }
|
|
106
|
+ else if(1 == api.getType()){ //存储过程,要求参数为数组
|
|
107
|
+ JSONArray arr = JSONObject.parseArray(params);
|
|
108
|
+
|
|
109
|
+ List<Object> ps = new ArrayList<Object>();
|
|
110
|
+ for(int i = 0;i < arr.size() ;i ++)
|
|
111
|
+ ps.add(arr.get(i));
|
|
112
|
+
|
|
113
|
+ this.queryService.executeProc(api.getContent(),ps);
|
|
114
|
+ return null;
|
|
115
|
+ }
|
|
116
|
+ else if(2 == api.getType()) { //JS
|
|
117
|
+ return jsAction(api,params);
|
80
|
118
|
}
|
81
|
119
|
|
82
|
120
|
return null;
|