|
@@ -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
|
}
|