Skip to content

Commit d4be7ce

Browse files
committed
远程函数:丰富取常用类型参数值的函数
1 parent d748641 commit d4be7ce

File tree

1 file changed

+126
-9
lines changed

1 file changed

+126
-9
lines changed

APIJSONORM/src/main/java/apijson/orm/AbstractFunctionParser.java

+126-9
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@
55

66
package apijson.orm;
77

8-
import apijson.Log;
9-
import apijson.NotNull;
10-
import apijson.RequestMethod;
11-
import apijson.StringUtil;
8+
import apijson.*;
129
import apijson.orm.exception.UnsupportedDataTypeException;
1310
import apijson.orm.script.ScriptExecutor;
11+
import com.alibaba.fastjson.JSONArray;
1412
import com.alibaba.fastjson.JSONObject;
1513
import com.alibaba.fastjson.parser.ParserConfig;
1614
import com.alibaba.fastjson.util.TypeUtils;
1715

1816
import java.lang.invoke.WrongMethodTypeException;
1917
import java.lang.reflect.InvocationTargetException;
2018
import java.lang.reflect.Method;
19+
import java.math.BigDecimal;
2120
import java.util.*;
2221

2322
import static apijson.orm.AbstractSQLConfig.PATTERN_SCHEMA;
@@ -44,6 +43,7 @@ public class AbstractFunctionParser implements FunctionParser {
4443
// <isContain, <arguments:"array,key", tag:null, methods:null>>
4544
public static Map<String, ScriptExecutor> SCRIPT_EXECUTOR_MAP;
4645
public static Map<String, JSONObject> FUNCTION_MAP;
46+
4747
static {
4848
FUNCTION_MAP = new HashMap<>();
4949
SCRIPT_EXECUTOR_MAP = new HashMap<>();
@@ -53,9 +53,11 @@ public class AbstractFunctionParser implements FunctionParser {
5353
private String tag;
5454
private int version;
5555
private JSONObject request;
56+
5657
public AbstractFunctionParser() {
5758
this(null, null, 0, null);
5859
}
60+
5961
public AbstractFunctionParser(RequestMethod method, String tag, int version, @NotNull JSONObject request) {
6062
setMethod(method == null ? RequestMethod.GET : method);
6163
setTag(tag);
@@ -64,10 +66,12 @@ public AbstractFunctionParser(RequestMethod method, String tag, int version, @No
6466
}
6567

6668
private Parser<?> parser;
69+
6770
@Override
6871
public Parser<?> getParser() {
6972
return parser;
7073
}
74+
7175
@Override
7276
public AbstractFunctionParser setParser(Parser<?> parser) {
7377
this.parser = parser;
@@ -78,85 +82,198 @@ public AbstractFunctionParser setParser(Parser<?> parser) {
7882
public RequestMethod getMethod() {
7983
return method;
8084
}
85+
8186
@Override
8287
public AbstractFunctionParser setMethod(RequestMethod method) {
8388
this.method = method;
8489
return this;
8590
}
91+
8692
@Override
8793
public String getTag() {
8894
return tag;
8995
}
96+
9097
@Override
9198
public AbstractFunctionParser setTag(String tag) {
9299
this.tag = tag;
93100
return this;
94101
}
102+
95103
@Override
96104
public int getVersion() {
97105
return version;
98106
}
107+
99108
@Override
100109
public AbstractFunctionParser setVersion(int version) {
101110
this.version = version;
102111
return this;
103112
}
104-
113+
105114
private String key;
115+
106116
@Override
107117
public String getKey() {
108118
return key;
109119
}
120+
110121
@Override
111122
public AbstractFunctionParser setKey(String key) {
112123
this.key = key;
113124
return this;
114125
}
115-
126+
116127
private String parentPath;
128+
117129
@Override
118130
public String getParentPath() {
119131
return parentPath;
120132
}
133+
121134
@Override
122135
public AbstractFunctionParser setParentPath(String parentPath) {
123136
this.parentPath = parentPath;
124137
return this;
125138
}
139+
126140
private String currentName;
141+
127142
@Override
128143
public String getCurrentName() {
129144
return currentName;
130145
}
146+
131147
@Override
132148
public AbstractFunctionParser setCurrentName(String currentName) {
133149
this.currentName = currentName;
134150
return this;
135151
}
136-
152+
137153
@NotNull
138154
@Override
139155
public JSONObject getRequest() {
140156
return request;
141157
}
158+
142159
@Override
143160
public AbstractFunctionParser setRequest(@NotNull JSONObject request) {
144161
this.request = request;
145162
return this;
146163
}
147-
164+
148165
private JSONObject currentObject;
149-
@NotNull
166+
167+
@NotNull
150168
@Override
151169
public JSONObject getCurrentObject() {
152170
return currentObject;
153171
}
172+
154173
@Override
155174
public AbstractFunctionParser setCurrentObject(@NotNull JSONObject currentObject) {
156175
this.currentObject = currentObject;
157176
return this;
158177
}
159178

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+
160277
/**根据路径取值
161278
* @param path
162279
* @return

0 commit comments

Comments
 (0)