package com.ard.work.health.client;
|
|
import com.alibaba.fastjson.JSON;
|
import okhttp3.FormBody;
|
import okhttp3.OkHttpClient;
|
import okhttp3.Request;
|
import okhttp3.RequestBody;
|
import okhttp3.Response;
|
import okhttp3.ResponseBody;
|
|
import java.io.IOException;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
public class EquipmentsHealthClient {
|
|
/**
|
* 获取token
|
*/
|
public static Map<String,Object> getToken(String url,String account,String password){
|
RequestBody formBody = new FormBody.Builder()
|
.add("account", account)
|
.add("password", password)
|
.build();
|
return getOkHttpClientResult(url,formBody);
|
}
|
|
public static Map<String,Object> GetPartsAlertLeve(String url,String token,Integer id){
|
RequestBody formBody = new FormBody.Builder()
|
.add("equipId", String.valueOf(id))
|
.build();
|
return getOkHttpClientResult(url,formBody,token);
|
}
|
|
public static Map<String,Object> GetEquipmentAlertInfo(String url,String token,Integer id){
|
RequestBody formBody = new FormBody.Builder()
|
.add("partid", String.valueOf(id))
|
.build();
|
return getOkHttpClientResult(url,formBody,token);
|
}
|
|
public static Map<String,Object> GetTreeJsonX(String url,String token){
|
RequestBody formBody = new FormBody.Builder().build();
|
return getOkHttpClientResult(url,formBody,token);
|
}
|
|
public static Map<String,Object> getOkHttpClientResult(String url,RequestBody formBody){
|
OkHttpClient okHttpClient = new OkHttpClient();
|
Request request = new Request.Builder().url(url).post(formBody).build();
|
Response response = null;
|
try {
|
response = okHttpClient.newCall(request).execute();
|
} catch (IOException e1) {
|
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) {
|
e.printStackTrace();
|
return new HashMap();
|
}
|
}
|
|
public static Map<String,Object> getOkHttpClientResult(String url,RequestBody formBody,String token){
|
OkHttpClient okHttpClient = new OkHttpClient();
|
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) {
|
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) {
|
e.printStackTrace();
|
return new HashMap();
|
}
|
}
|
|
|
}
|