liusuyi
2026-05-18 b5cd784d0cde5b7c82ea78aef4ac0e5a161d8c5d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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();
        }
    }
 
 
}