|
@@ -0,0 +1,190 @@
|
|
|
+package com.aidex.common.gps.common;
|
|
|
+
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import com.aidex.common.exception.SysException;
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class GpsRequest<T> {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private GeneratorGspApi generatorGspApi;
|
|
|
+
|
|
|
+
|
|
|
+ public List<T> postArray(Map<String,Object> params, JSONObject body, Integer timeOut){
|
|
|
+ JSONObject res = postRequest(params,body,timeOut);
|
|
|
+ Boolean status = res.getBoolean("success");
|
|
|
+ Integer code = res.getInteger("errorCode");
|
|
|
+ String msg = res.getString("errorDescribe");
|
|
|
+
|
|
|
+ if(status){
|
|
|
+ return (ArrayList<T>) JSONObject.parseObject(res.getString("data"),List.class);
|
|
|
+ }
|
|
|
+ throw new SysException(code,msg);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<T> postArray(Map<String,Object> params, JSONObject body){
|
|
|
+ JSONObject res = postRequest(params,body,1000);
|
|
|
+ Boolean status = res.getBoolean("success");
|
|
|
+ Integer code = res.getInteger("errorCode");
|
|
|
+ String msg = res.getString("errorDescribe");
|
|
|
+
|
|
|
+ if(status){
|
|
|
+ return (ArrayList<T>) JSONObject.parseObject(res.getString("data"),List.class);
|
|
|
+ }
|
|
|
+ throw new SysException(code,msg);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<T> postArray(Map<String,Object> params){
|
|
|
+ JSONObject res = postRequest(params,null,1000);
|
|
|
+ Boolean status = res.getBoolean("success");
|
|
|
+ Integer code = res.getInteger("errorCode");
|
|
|
+ String msg = res.getString("errorDescribe");
|
|
|
+
|
|
|
+ if(status){
|
|
|
+ return (ArrayList<T>) JSONObject.parseObject(res.getString("data"),List.class);
|
|
|
+ }
|
|
|
+ throw new SysException(code,msg);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public T post(Map<String,Object> params, JSONObject body, Integer timeOut){
|
|
|
+ JSONObject res = postRequest(params,body,timeOut);
|
|
|
+ Boolean status = res.getBoolean("success");
|
|
|
+ Integer code = res.getInteger("errorCode");
|
|
|
+ String msg = res.getString("errorDescribe");
|
|
|
+
|
|
|
+ if(status){
|
|
|
+ return (T) JSONObject.parseObject(res.getString("data"), Map.class);
|
|
|
+ }
|
|
|
+ throw new SysException(code,msg);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public T post(Map<String,Object> params, JSONObject body){
|
|
|
+ JSONObject res = postRequest(params,body,1000);
|
|
|
+ Boolean status = res.getBoolean("success");
|
|
|
+ Integer code = res.getInteger("errorCode");
|
|
|
+ String msg = res.getString("errorDescribe");
|
|
|
+
|
|
|
+ if(status){
|
|
|
+ return (T) JSONObject.parseObject(res.getString("data"), Map.class);
|
|
|
+ }
|
|
|
+ throw new SysException(code,msg);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public T post(Map<String,Object> params){
|
|
|
+ JSONObject res = postRequest(params,null,1000);
|
|
|
+ Boolean status = res.getBoolean("success");
|
|
|
+ Integer code = res.getInteger("errorCode");
|
|
|
+ String msg = res.getString("errorDescribe");
|
|
|
+
|
|
|
+ if(status){
|
|
|
+ return (T) JSONObject.parseObject(res.getString("data"), Map.class);
|
|
|
+ }
|
|
|
+ throw new SysException(code,msg);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<T> getArray(Map<String,Object> params, JSONObject body, Integer timeOut){
|
|
|
+ JSONObject res = postRequest(params,body,timeOut);
|
|
|
+ Boolean status = res.getBoolean("success");
|
|
|
+ Integer code = res.getInteger("errorCode");
|
|
|
+ String msg = res.getString("errorDescribe");
|
|
|
+
|
|
|
+ if(status){
|
|
|
+ return (ArrayList<T>) JSONObject.parseObject(res.getString("data"),List.class);
|
|
|
+ }
|
|
|
+ throw new SysException(code,msg);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<T> getArray(Map<String,Object> params, JSONObject body){
|
|
|
+ JSONObject res = postRequest(params,body,1000);
|
|
|
+ Boolean status = res.getBoolean("success");
|
|
|
+ Integer code = res.getInteger("errorCode");
|
|
|
+ String msg = res.getString("errorDescribe");
|
|
|
+
|
|
|
+ if(status){
|
|
|
+ return (ArrayList<T>) JSONObject.parseObject(res.getString("data"),List.class);
|
|
|
+ }
|
|
|
+ throw new SysException(code,msg);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<T> getArray(Map<String,Object> params){
|
|
|
+ JSONObject res = postRequest(params,null,1000);
|
|
|
+ Boolean status = res.getBoolean("success");
|
|
|
+ Integer code = res.getInteger("errorCode");
|
|
|
+ String msg = res.getString("errorDescribe");
|
|
|
+
|
|
|
+ if(status){
|
|
|
+ return (ArrayList<T>) JSONObject.parseObject(res.getString("data"),List.class);
|
|
|
+ }
|
|
|
+ throw new SysException(code,msg);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public T get(Map<String,Object> params, JSONObject body, Integer timeOut){
|
|
|
+ JSONObject res = postRequest(params,body,timeOut);
|
|
|
+ Boolean status = res.getBoolean("success");
|
|
|
+ Integer code = res.getInteger("errorCode");
|
|
|
+ String msg = res.getString("errorDescribe");
|
|
|
+
|
|
|
+ if(status){
|
|
|
+ return (T) JSONObject.parseObject(res.getString("data"), Map.class);
|
|
|
+ }
|
|
|
+ throw new SysException(code,msg);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public T get(Map<String,Object> params, JSONObject body){
|
|
|
+ JSONObject res = postRequest(params,body,1000);
|
|
|
+ Boolean status = res.getBoolean("success");
|
|
|
+ Integer code = res.getInteger("errorCode");
|
|
|
+ String msg = res.getString("errorDescribe");
|
|
|
+
|
|
|
+ if(status){
|
|
|
+ return (T) JSONObject.parseObject(res.getString("data"), Map.class);
|
|
|
+ }
|
|
|
+ throw new SysException(code,msg);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public T get(Map<String,Object> params){
|
|
|
+ JSONObject res = postRequest(params,null,1000);
|
|
|
+ Boolean status = res.getBoolean("success");
|
|
|
+ Integer code = res.getInteger("errorCode");
|
|
|
+ String msg = res.getString("errorDescribe");
|
|
|
+
|
|
|
+ if(status){
|
|
|
+ return (T) JSONObject.parseObject(res.getString("data"), Map.class);
|
|
|
+ }
|
|
|
+ throw new SysException(code,msg);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private JSONObject postRequest(Map<String,Object> params, JSONObject body, Integer timeOut){
|
|
|
+ String api = generatorGspApi.GeneratorApi();
|
|
|
+ String res = HttpRequest.post(api).form(params).body(body.toString()).timeout(timeOut).execute().body();
|
|
|
+ return JSON.parseObject(res);
|
|
|
+ }
|
|
|
+
|
|
|
+ private JSONObject getRequest(Map<String,Object> params, JSONObject body, Integer timeOut){
|
|
|
+ String api = generatorGspApi.GeneratorApi();
|
|
|
+ String res = HttpRequest.get(api).form(params).body(body.toString()).timeout(timeOut).execute().body();
|
|
|
+ return JSON.parseObject(res);
|
|
|
+ }
|
|
|
+}
|