| package com.ruoyi.health.client; | 
|   | 
| import com.alibaba.fastjson.JSON; | 
| import okhttp3.FormBody.Builder; | 
| import okhttp3.*; | 
|   | 
| import java.io.IOException; | 
| import java.util.HashMap; | 
| import java.util.Map; | 
|   | 
| public class EquipmentsHealthClient { | 
|     public static Map<String,Object> getToken(String url,String account,String password){//获取token | 
|         OkHttpClient okHttpClient = new OkHttpClient(); | 
|         RequestBody formBody = new Builder() | 
|                 .add("account", account) | 
|                 .add("password", password) | 
|                 .build(); | 
|   | 
|         Request request = new Request.Builder().url(url).post(formBody).build(); | 
|   | 
|         Response response = null; | 
|         try { | 
|             response = okHttpClient.newCall(request).execute(); | 
|         } catch (IOException e1) { | 
|             // TODO Auto-generated catch block | 
|             e1.printStackTrace(); | 
|         } | 
|   | 
|         ResponseBody responseBody = response.body(); | 
|   | 
|         try { | 
|             String message = responseBody.string(); | 
|             Map<String,Object> result = (Map<String, Object>) JSON.parse(message); | 
|             return result; | 
|         } catch (IOException e) { | 
|             // TODO Auto-generated catch block | 
|             e.printStackTrace(); | 
|             return new HashMap(); | 
|         } | 
|     } | 
|   | 
|     public static Map<String,Object> getMeasureStatisticsList(String url,String token){//所有传感器统计信息 | 
|         MediaType mediaType = MediaType.parse("application/json; charset=utf-8"); | 
|         OkHttpClient okHttpClient = new OkHttpClient(); | 
|   | 
|         RequestBody body = RequestBody.create(mediaType, ""); | 
|         Request request = new Request.Builder().url(url).post(body).addHeader("roadflow-token",token).build(); | 
|   | 
|         Response response = null; | 
|         try { | 
|             response = okHttpClient.newCall(request).execute(); | 
|         } catch (IOException e1) { | 
|             // TODO Auto-generated catch block | 
|             e1.printStackTrace(); | 
|         } | 
|   | 
|         ResponseBody responseBody = response.body(); | 
|   | 
|         try { | 
|             String message = responseBody.string();// 响应体 | 
|             Map<String,Object> map0 = (Map<String, Object>) JSON.parse(message); | 
|             return map0; | 
|         } catch (IOException e) { | 
|             // TODO Auto-generated catch block | 
|             e.printStackTrace(); | 
|             return new HashMap(); | 
|         } | 
|     } | 
|   | 
|     public static Map<String,Object> GetEquipInfo(String url,String token,Integer equipId){//获取单台油井信息和测点 | 
|         OkHttpClient okHttpClient = new OkHttpClient(); | 
|         RequestBody formBody = new Builder() | 
|                 .add("equipId", String.valueOf(equipId)) | 
|                 .build(); | 
|          | 
|         Request request = new Request.Builder().url(url).post(formBody).addHeader("roadflow-token",token).build(); | 
|         | 
|         Response response = null; | 
|         try { | 
|             response = okHttpClient.newCall(request).execute(); | 
|         } catch (IOException e1) { | 
|             // TODO Auto-generated catch block | 
|             e1.printStackTrace(); | 
|         } | 
|   | 
|         ResponseBody responseBody = response.body(); | 
|   | 
|         try { | 
|             String message = responseBody.string(); | 
|             System.out.println(message); | 
|             Map<String,Object> result = (Map<String, Object>) JSON.parse(message); | 
|             return result; | 
|         } catch (IOException e) { | 
|             // TODO Auto-generated catch block | 
|             e.printStackTrace(); | 
|             return new HashMap(); | 
|         } | 
|     } | 
|   | 
|     public static Map<String,Object> GetPartsAlertLeve(String url,String token,Integer id){ | 
|         OkHttpClient okHttpClient = new OkHttpClient(); | 
| //        MediaType mediaType = MediaType.parse("application/json; charset=utf-8"); | 
| //        RequestBody formBody = RequestBody.create(mediaType, ""); | 
|         RequestBody formBody = new Builder() | 
|                 .add("equipId", String.valueOf(id)) | 
|                 .build(); | 
|         Request request = new Request.Builder().url(url).post(formBody).addHeader("roadflow-token",token).build(); | 
|         Response response = null; | 
|         try { | 
|             response = okHttpClient.newCall(request).execute(); | 
|         } catch (IOException e1) { | 
|             // TODO Auto-generated catch block | 
|             e1.printStackTrace(); | 
|         } | 
|   | 
|         ResponseBody responseBody = response.body(); | 
|   | 
|         try { | 
|             String message = responseBody.string(); | 
|             System.out.println(message); | 
|             Map<String,Object> result = (Map<String, Object>) JSON.parse(message); | 
|             return result; | 
|         } catch (IOException e) { | 
|             // TODO Auto-generated catch block | 
|             e.printStackTrace(); | 
|             return new HashMap(); | 
|         } | 
|     } | 
|   | 
|     public static Map<String,Object> GetEquipmentAlertInfo(String url,String token,Integer id){ | 
|         OkHttpClient okHttpClient = new OkHttpClient(); | 
| //        MediaType mediaType = MediaType.parse("application/json; charset=utf-8"); | 
| //        RequestBody formBody = RequestBody.create(mediaType, ""); | 
|         RequestBody formBody = new Builder() | 
|                 .add("partid", String.valueOf(id)) | 
|                 .build(); | 
|         Request request = new Request.Builder().url(url).post(formBody).addHeader("roadflow-token",token).build(); | 
|         Response response = null; | 
|         try { | 
|             response = okHttpClient.newCall(request).execute(); | 
|         } catch (IOException e1) { | 
|             // TODO Auto-generated catch block | 
|             e1.printStackTrace(); | 
|         } | 
|   | 
|         ResponseBody responseBody = response.body(); | 
|   | 
|         try { | 
|             String message = responseBody.string(); | 
|             System.out.println(message); | 
|             Map<String,Object> result = (Map<String, Object>) JSON.parse(message); | 
|             return result; | 
|         } catch (IOException e) { | 
|             // TODO Auto-generated catch block | 
|             e.printStackTrace(); | 
|             return new HashMap(); | 
|         } | 
|     } | 
| } |