Commit 12c8e7ef7b57ee78cbe1e84e04758156e430bb85
1 parent
32edd863
m
Showing
1 changed file
with
246 additions
and
0 deletions
trash-common/src/main/java/com/trash/common/utils/RemoteServerUtils.java
| @@ -39,6 +39,8 @@ public class RemoteServerUtils { | @@ -39,6 +39,8 @@ public class RemoteServerUtils { | ||
| 39 | public static String TruckInfo = "/api/gpsservice/cs/basevehicle/"; | 39 | public static String TruckInfo = "/api/gpsservice/cs/basevehicle/"; |
| 40 | public static String EarthSitesInfo = "/api/siteservice/cs/earthsites/"; | 40 | public static String EarthSitesInfo = "/api/siteservice/cs/earthsites/"; |
| 41 | 41 | ||
| 42 | + public static String EarthSitesList = "//api/siteservice/cs/earthsites/ledger/list"; | ||
| 43 | + | ||
| 42 | public static String ConstructionInfo = "/api/siteservice/cs/constructionsites/"; | 44 | public static String ConstructionInfo = "/api/siteservice/cs/constructionsites/"; |
| 43 | 45 | ||
| 44 | public static String UpdateConstruction= "/api/siteservice/cs/constructionsites/status"; | 46 | public static String UpdateConstruction= "/api/siteservice/cs/constructionsites/status"; |
| @@ -53,6 +55,17 @@ public class RemoteServerUtils { | @@ -53,6 +55,17 @@ public class RemoteServerUtils { | ||
| 53 | public static String UpdateConractRequestPath = "/api/siteservice/cs/sitecontract/audit/status"; | 55 | public static String UpdateConractRequestPath = "/api/siteservice/cs/sitecontract/audit/status"; |
| 54 | 56 | ||
| 55 | 57 | ||
| 58 | + public static JSONArray getEarthSitesList(Map map){ | ||
| 59 | + JSONArray list=null; | ||
| 60 | + Object object = post(EarthSitesList,map); | ||
| 61 | + | ||
| 62 | + if(object != null){ | ||
| 63 | + JSONObject jsonObject = JSON.parseObject(object.toString()); | ||
| 64 | + list = jsonObject.getJSONArray("list"); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + return list; | ||
| 68 | + } | ||
| 56 | 69 | ||
| 57 | public static JSONArray getTruckOnline(Map map){ | 70 | public static JSONArray getTruckOnline(Map map){ |
| 58 | JSONArray turckList=null; | 71 | JSONArray turckList=null; |
| @@ -197,6 +210,151 @@ public class RemoteServerUtils { | @@ -197,6 +210,151 @@ public class RemoteServerUtils { | ||
| 197 | return object; | 210 | return object; |
| 198 | } | 211 | } |
| 199 | 212 | ||
| 213 | + | ||
| 214 | + | ||
| 215 | + public static JSONArray getTruckOnline(Map map,String token){ | ||
| 216 | + JSONArray turckList=null; | ||
| 217 | + Object object = post(TruckStatusListRequestPath,map,token); | ||
| 218 | + | ||
| 219 | + if(object != null){ | ||
| 220 | + JSONObject jsonObject = JSON.parseObject(object.toString()); | ||
| 221 | + turckList = jsonObject.getJSONArray("list"); | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + return turckList; | ||
| 225 | + } | ||
| 226 | + | ||
| 227 | + public static Object updateConstationCreditAndStatus(List<Map> map,String token){ | ||
| 228 | + JSONArray turckList=null; | ||
| 229 | + Object object = post(UpdateConstruction,map,token); | ||
| 230 | + | ||
| 231 | + return object; | ||
| 232 | + } | ||
| 233 | + | ||
| 234 | + public static Object updateEarthSitesCreditAndStatus(List<Map> map,String token){ | ||
| 235 | + JSONArray turckList=null; | ||
| 236 | + Object object = post(UpdateEarthSiteRequestPath,map,token); | ||
| 237 | + | ||
| 238 | + return object; | ||
| 239 | + } | ||
| 240 | + | ||
| 241 | + public static Object updateConractStatus(List<Map> map,String token){ | ||
| 242 | + JSONArray turckList=null; | ||
| 243 | + Object object = post(UpdateConractRequestPath,map,token); | ||
| 244 | + | ||
| 245 | + return object; | ||
| 246 | + } | ||
| 247 | + | ||
| 248 | + | ||
| 249 | + | ||
| 250 | + | ||
| 251 | + public static JSONObject getEarthSitesInfo(String id,String token) { | ||
| 252 | + JSONObject json=null; | ||
| 253 | + Object object = get(EarthSitesInfo + id,null,token); | ||
| 254 | + | ||
| 255 | + if(object != null){ | ||
| 256 | + json = JSON.parseObject(object.toString()); | ||
| 257 | + return json; | ||
| 258 | + } | ||
| 259 | + | ||
| 260 | + return json; | ||
| 261 | + } | ||
| 262 | + | ||
| 263 | + | ||
| 264 | + | ||
| 265 | + public static JSONObject getTruckInfo(String id,String token){ | ||
| 266 | + JSONObject turckList=null; | ||
| 267 | + Object object = get(TruckInfo + id,null,token); | ||
| 268 | + | ||
| 269 | + if(object != null){ | ||
| 270 | + turckList = JSON.parseObject(object.toString()); | ||
| 271 | + return turckList; | ||
| 272 | + } | ||
| 273 | + | ||
| 274 | + return turckList; | ||
| 275 | + } | ||
| 276 | + | ||
| 277 | + | ||
| 278 | + public static JSONObject getConstructionInfo(String id,String token) { | ||
| 279 | + JSONObject turckList=null; | ||
| 280 | + Object object = get(ConstructionInfo + id,null,token); | ||
| 281 | + | ||
| 282 | + if(object != null){ | ||
| 283 | + turckList = JSON.parseObject(object.toString()); | ||
| 284 | + return turckList; | ||
| 285 | + } | ||
| 286 | + | ||
| 287 | + return turckList; | ||
| 288 | + | ||
| 289 | + } | ||
| 290 | + | ||
| 291 | + | ||
| 292 | + public static JSONArray getCompanyList(Map params,String token){ | ||
| 293 | + JSONArray turckList=null; | ||
| 294 | + Object object = post(CompanyListRequestPath,params,token); | ||
| 295 | + | ||
| 296 | + if(object != null){ | ||
| 297 | + JSONObject jsonObject = JSON.parseObject(object.toString()); | ||
| 298 | + turckList = jsonObject.getJSONArray("list"); | ||
| 299 | + } | ||
| 300 | + | ||
| 301 | + return turckList; | ||
| 302 | + } | ||
| 303 | + | ||
| 304 | + public static Object updateCompanyList(List<Map> updateList,String token) { | ||
| 305 | + JSONArray turckList=null; | ||
| 306 | + Object object = post(UpdateCompanyRequestPath,updateList); | ||
| 307 | + | ||
| 308 | + | ||
| 309 | + return object; | ||
| 310 | + } | ||
| 311 | + | ||
| 312 | + | ||
| 313 | + public static JSONArray getAreas(String token){ | ||
| 314 | + JSONArray array=null; | ||
| 315 | + Object object = get("/api/gpsservice/cs/area",null,token); | ||
| 316 | + | ||
| 317 | + if(object != null){ | ||
| 318 | + array = JSON.parseArray(object.toString()); | ||
| 319 | + } | ||
| 320 | + | ||
| 321 | + return array; | ||
| 322 | + } | ||
| 323 | + | ||
| 324 | + public static JSONArray getDict(Map params,String token){ | ||
| 325 | + JSONArray array=null; | ||
| 326 | + Object object = get("/api/gpsservice/cs/dataDict",params,token); | ||
| 327 | + | ||
| 328 | + if(object != null){ | ||
| 329 | + array = JSON.parseArray(object.toString()); | ||
| 330 | + } | ||
| 331 | + | ||
| 332 | + return array; | ||
| 333 | + } | ||
| 334 | + | ||
| 335 | + | ||
| 336 | + public static JSONArray getTruckList(Map params,String token){ | ||
| 337 | + JSONArray turckList=null; | ||
| 338 | + Object object = post(TruckListRequestPath,params,token); | ||
| 339 | + | ||
| 340 | + if(object != null){ | ||
| 341 | + JSONObject jsonObject = JSON.parseObject(object.toString()); | ||
| 342 | + turckList = jsonObject.getJSONArray("list"); | ||
| 343 | + } | ||
| 344 | + | ||
| 345 | + return turckList; | ||
| 346 | + } | ||
| 347 | + | ||
| 348 | + | ||
| 349 | + | ||
| 350 | + public static Object updateTruckList(List<Map> updateList,String token) { | ||
| 351 | + JSONArray turckList=null; | ||
| 352 | + Object object = post(UpdateTruckRequestPath,updateList,token); | ||
| 353 | + | ||
| 354 | + | ||
| 355 | + return object; | ||
| 356 | + } | ||
| 357 | + | ||
| 200 | public static Object post(String url,Object obj){ | 358 | public static Object post(String url,Object obj){ |
| 201 | if(okHttpClient == null){ | 359 | if(okHttpClient == null){ |
| 202 | okHttpClient = new OkHttpClient.Builder() | 360 | okHttpClient = new OkHttpClient.Builder() |
| @@ -289,6 +447,94 @@ public class RemoteServerUtils { | @@ -289,6 +447,94 @@ public class RemoteServerUtils { | ||
| 289 | 447 | ||
| 290 | return null; | 448 | return null; |
| 291 | } | 449 | } |
| 450 | + public static Object post(String url,Object obj,String token){ | ||
| 451 | + if(okHttpClient == null){ | ||
| 452 | + okHttpClient = new OkHttpClient.Builder() | ||
| 453 | + .connectTimeout(20, TimeUnit.SECONDS) | ||
| 454 | + .writeTimeout(20, TimeUnit.SECONDS) | ||
| 455 | + .readTimeout(30, TimeUnit.SECONDS) | ||
| 456 | + .build(); | ||
| 457 | + } | ||
| 458 | + | ||
| 459 | + token = "Bearer "+ token; | ||
| 460 | + | ||
| 461 | + String param = JSON.toJSON(obj).toString(); | ||
| 462 | + | ||
| 463 | + RequestBody body = RequestBody.create(MediaType.parse("application/json"), param ); | ||
| 464 | + | ||
| 465 | + Request request = new Request.Builder().url(remote+url).addHeader("Authorization",token ).post(body).build(); | ||
| 466 | + | ||
| 467 | + try { | ||
| 468 | + okhttp3.Response response = okHttpClient.newCall(request).execute(); | ||
| 469 | + String result = response.body().string(); | ||
| 470 | + | ||
| 471 | + if(result != null){ | ||
| 472 | + JSONObject json = JSON.parseObject(result); | ||
| 473 | + if(json.getInteger("code") == 200){ | ||
| 474 | + return json.get("result"); | ||
| 475 | + } | ||
| 476 | + | ||
| 477 | + }else{ | ||
| 478 | + return null; | ||
| 479 | + } | ||
| 480 | + | ||
| 481 | + }catch (Exception e) { | ||
| 482 | + e.printStackTrace(); | ||
| 483 | + return null; | ||
| 484 | + } | ||
| 485 | + | ||
| 486 | + return null; | ||
| 487 | + } | ||
| 488 | + | ||
| 489 | + public static Object get(String url,Map<String,String> obj,String token){ | ||
| 490 | + if(okHttpClient == null){ | ||
| 491 | + okHttpClient = new OkHttpClient.Builder() | ||
| 492 | + .connectTimeout(20, TimeUnit.SECONDS) | ||
| 493 | + .writeTimeout(20, TimeUnit.SECONDS) | ||
| 494 | + .readTimeout(30, TimeUnit.SECONDS) | ||
| 495 | + .build(); | ||
| 496 | + } | ||
| 497 | + | ||
| 498 | + token = "Bearer "+ token; | ||
| 499 | + String params = ""; | ||
| 500 | + | ||
| 501 | + | ||
| 502 | + if(obj != null){ | ||
| 503 | + | ||
| 504 | + params += "?"; | ||
| 505 | + | ||
| 506 | + for(String key:obj.keySet()){ | ||
| 507 | + params += key + "=" + obj.get(key) + "&"; | ||
| 508 | + } | ||
| 509 | + | ||
| 510 | + params = params.substring(0,params.length()-1); | ||
| 511 | + } | ||
| 512 | + | ||
| 513 | + | ||
| 514 | + url += params; | ||
| 515 | + | ||
| 516 | + Request request = new Request.Builder().url(remote+url).addHeader("Authorization",token ).get().build(); | ||
| 517 | + | ||
| 518 | + try { | ||
| 519 | + okhttp3.Response response = okHttpClient.newCall(request).execute(); | ||
| 520 | + String result = response.body().string(); | ||
| 521 | + | ||
| 522 | + if(result != null){ | ||
| 523 | + JSONObject json = JSON.parseObject(result); | ||
| 524 | + if("success".equals(json.getString("message"))){ | ||
| 525 | + return json.get("result"); | ||
| 526 | + } | ||
| 527 | + }else{ | ||
| 528 | + return null; | ||
| 529 | + } | ||
| 530 | + | ||
| 531 | + }catch (Exception e) { | ||
| 532 | + e.printStackTrace(); | ||
| 533 | + return null; | ||
| 534 | + } | ||
| 535 | + | ||
| 536 | + return null; | ||
| 537 | + } | ||
| 292 | 538 | ||
| 293 | 539 | ||
| 294 | 540 |