5
5
6
6
package apijson .orm ;
7
7
8
- import apijson .Log ;
9
- import apijson .NotNull ;
10
- import apijson .RequestMethod ;
11
- import apijson .StringUtil ;
8
+ import apijson .*;
12
9
import apijson .orm .exception .UnsupportedDataTypeException ;
13
10
import apijson .orm .script .ScriptExecutor ;
11
+ import com .alibaba .fastjson .JSONArray ;
14
12
import com .alibaba .fastjson .JSONObject ;
15
13
import com .alibaba .fastjson .parser .ParserConfig ;
16
14
import com .alibaba .fastjson .util .TypeUtils ;
17
15
18
16
import java .lang .invoke .WrongMethodTypeException ;
19
17
import java .lang .reflect .InvocationTargetException ;
20
18
import java .lang .reflect .Method ;
19
+ import java .math .BigDecimal ;
21
20
import java .util .*;
22
21
23
22
import static apijson .orm .AbstractSQLConfig .PATTERN_SCHEMA ;
@@ -44,6 +43,7 @@ public class AbstractFunctionParser implements FunctionParser {
44
43
// <isContain, <arguments:"array,key", tag:null, methods:null>>
45
44
public static Map <String , ScriptExecutor > SCRIPT_EXECUTOR_MAP ;
46
45
public static Map <String , JSONObject > FUNCTION_MAP ;
46
+
47
47
static {
48
48
FUNCTION_MAP = new HashMap <>();
49
49
SCRIPT_EXECUTOR_MAP = new HashMap <>();
@@ -53,9 +53,11 @@ public class AbstractFunctionParser implements FunctionParser {
53
53
private String tag ;
54
54
private int version ;
55
55
private JSONObject request ;
56
+
56
57
public AbstractFunctionParser () {
57
58
this (null , null , 0 , null );
58
59
}
60
+
59
61
public AbstractFunctionParser (RequestMethod method , String tag , int version , @ NotNull JSONObject request ) {
60
62
setMethod (method == null ? RequestMethod .GET : method );
61
63
setTag (tag );
@@ -64,10 +66,12 @@ public AbstractFunctionParser(RequestMethod method, String tag, int version, @No
64
66
}
65
67
66
68
private Parser <?> parser ;
69
+
67
70
@ Override
68
71
public Parser <?> getParser () {
69
72
return parser ;
70
73
}
74
+
71
75
@ Override
72
76
public AbstractFunctionParser setParser (Parser <?> parser ) {
73
77
this .parser = parser ;
@@ -78,85 +82,198 @@ public AbstractFunctionParser setParser(Parser<?> parser) {
78
82
public RequestMethod getMethod () {
79
83
return method ;
80
84
}
85
+
81
86
@ Override
82
87
public AbstractFunctionParser setMethod (RequestMethod method ) {
83
88
this .method = method ;
84
89
return this ;
85
90
}
91
+
86
92
@ Override
87
93
public String getTag () {
88
94
return tag ;
89
95
}
96
+
90
97
@ Override
91
98
public AbstractFunctionParser setTag (String tag ) {
92
99
this .tag = tag ;
93
100
return this ;
94
101
}
102
+
95
103
@ Override
96
104
public int getVersion () {
97
105
return version ;
98
106
}
107
+
99
108
@ Override
100
109
public AbstractFunctionParser setVersion (int version ) {
101
110
this .version = version ;
102
111
return this ;
103
112
}
104
-
113
+
105
114
private String key ;
115
+
106
116
@ Override
107
117
public String getKey () {
108
118
return key ;
109
119
}
120
+
110
121
@ Override
111
122
public AbstractFunctionParser setKey (String key ) {
112
123
this .key = key ;
113
124
return this ;
114
125
}
115
-
126
+
116
127
private String parentPath ;
128
+
117
129
@ Override
118
130
public String getParentPath () {
119
131
return parentPath ;
120
132
}
133
+
121
134
@ Override
122
135
public AbstractFunctionParser setParentPath (String parentPath ) {
123
136
this .parentPath = parentPath ;
124
137
return this ;
125
138
}
139
+
126
140
private String currentName ;
141
+
127
142
@ Override
128
143
public String getCurrentName () {
129
144
return currentName ;
130
145
}
146
+
131
147
@ Override
132
148
public AbstractFunctionParser setCurrentName (String currentName ) {
133
149
this .currentName = currentName ;
134
150
return this ;
135
151
}
136
-
152
+
137
153
@ NotNull
138
154
@ Override
139
155
public JSONObject getRequest () {
140
156
return request ;
141
157
}
158
+
142
159
@ Override
143
160
public AbstractFunctionParser setRequest (@ NotNull JSONObject request ) {
144
161
this .request = request ;
145
162
return this ;
146
163
}
147
-
164
+
148
165
private JSONObject currentObject ;
149
- @ NotNull
166
+
167
+ @ NotNull
150
168
@ Override
151
169
public JSONObject getCurrentObject () {
152
170
return currentObject ;
153
171
}
172
+
154
173
@ Override
155
174
public AbstractFunctionParser setCurrentObject (@ NotNull JSONObject currentObject ) {
156
175
this .currentObject = currentObject ;
157
176
return this ;
158
177
}
159
178
179
+ /**根据路径取 Boolean 值
180
+ * @param path
181
+ * @return
182
+ */
183
+ public Boolean getArgBool (String path ) {
184
+ return getArgVal (path , Boolean .class );
185
+ }
186
+
187
+ /**根据路径取 Integer 值
188
+ * @param path
189
+ * @return
190
+ */
191
+ public Integer getArgInt (String path ) {
192
+ return getArgVal (path , Integer .class );
193
+ }
194
+
195
+ /**根据路径取 Long 值
196
+ * @param path
197
+ * @return
198
+ */
199
+ public Long getArgLong (String path ) {
200
+ return getArgVal (path , Long .class );
201
+ }
202
+
203
+ /**根据路径取 Float 值
204
+ * @param path
205
+ * @return
206
+ */
207
+ public Float getArgFloat (String path ) {
208
+ return getArgVal (path , Float .class );
209
+ }
210
+
211
+ /**根据路径取 Double 值
212
+ * @param path
213
+ * @return
214
+ */
215
+ public Double getArgDouble (String path ) {
216
+ return getArgVal (path , Double .class );
217
+ }
218
+
219
+ /**根据路径取 Number 值
220
+ * @param path
221
+ * @return
222
+ */
223
+ public Number getArgNum (String path ) {
224
+ return getArgVal (path , Number .class );
225
+ }
226
+
227
+ /**根据路径取 BigDecimal 值
228
+ * @param path
229
+ * @return
230
+ */
231
+ public BigDecimal getArgDecimal (String path ) {
232
+ return getArgVal (path , BigDecimal .class );
233
+ }
234
+
235
+ /**根据路径取 String 值
236
+ * @param path
237
+ * @return
238
+ */
239
+ public String getArgStr (String path ) {
240
+ Object obj = getArgVal (path );
241
+ return JSON .toJSONString (obj );
242
+ }
243
+
244
+ /**根据路径取 JSONObject 值
245
+ * @param path
246
+ * @return
247
+ */
248
+ public JSONObject getArgObj (String path ) {
249
+ return getArgVal (path , JSONObject .class );
250
+ }
251
+
252
+ /**根据路径取 JSONArray 值
253
+ * @param path
254
+ * @return
255
+ */
256
+ public JSONArray getArgArr (String path ) {
257
+ return getArgVal (path , JSONArray .class );
258
+ }
259
+
260
+ /**根据路径取 List<T> 值
261
+ * @param path
262
+ * @return
263
+ */
264
+ public <T extends Object > List <T > getArgList (String path ) {
265
+ return getArgList (path , null );
266
+ }
267
+
268
+ /**根据路径取 List<T> 值
269
+ * @param path
270
+ * @return
271
+ */
272
+ public <T extends Object > List <T > getArgList (String path , Class <T > clazz ) {
273
+ String s = getArgStr (path );
274
+ return JSON .parseArray (s , clazz );
275
+ }
276
+
160
277
/**根据路径取值
161
278
* @param path
162
279
* @return
0 commit comments