Search in sources :

Example 1 with BridgeTrend

use of itor.topnetwork.com.dxditor.bean.BridgeTrend in project Dxditor by kimi2009.

the class BridgeModel method getTrendData.

@Override
public void getTrendData(final ValueCallBack<String> callBack, final int position) {
    if (Constants.testData) {
        BridgeBean bridgeBean = new BridgeBean();
        ArrayList<String> x = new ArrayList<String>();
        for (int i = 0; i < 8; i++) {
            x.add("03-2" + i + " 08:00");
        }
        bridgeBean.xData = x;
        ArrayList<Float> f = new ArrayList<Float>();
        if (position == 0) {
            for (int i = 0; i < 8; i++) {
                f.add(Float.parseFloat("2." + i));
            }
        } else if (position == 1) {
            for (int i = 0; i < 8; i++) {
                f.add(Float.parseFloat("1.0" + i));
            }
            ;
        } else if (position == 2) {
            for (int i = 1; i < 9; i++) {
                f.add(Float.parseFloat("0.8" + i));
            }
        }
        bridgeBean.seriesData = f;
        if (position == 0) {
            bridgeBean.initValue = 2.3f;
        } else if (position == 1) {
            bridgeBean.initValue = 1.1f;
        } else if (position == 2) {
            bridgeBean.initValue = 0.8f;
        }
        callBack.onSuccess(gson.toJson(bridgeBean));
    } else {
        bridgeTrends = new ArrayList<BridgeTrend>();
        // Form表单格式的参数传递
        FormBody formBody = new FormBody.Builder().add("bridgeCode", bridgeWarnings.get(position).getBridgeCode()).add("monitotObjectCode", bridgeWarnings.get(position).getMonitorObjectCode()).add("monitorItemCode", bridgeWarnings.get(position).getMonitorItemCode()).add("storageTime", Constants.MONTH).build();
        Request request = new Request.Builder().post(formBody).url(Constants.getAppBridgeMonthDisplacementInfo).build();
        okHttpClient.newCall(request).enqueue(new Callback() {

            @Override
            public void onFailure(Call call, IOException e) {
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String res = response.body().string();
                try {
                    JSONObject js = new JSONObject(res);
                    if (js.getBoolean("success")) {
                        bridgeTrends = gson.fromJson(js.getString("data"), new TypeToken<ArrayList<BridgeTrend>>() {
                        }.getType());
                        BridgeBean bridgeBean = new BridgeBean();
                        List<String> time = new ArrayList<>();
                        for (int i = 0; i < bridgeTrends.size(); i++) {
                            time.add(bridgeTrends.get(i).getStorageTime());
                        }
                        bridgeBean.xData = time;
                        List<Float> lineDatas = new ArrayList<>();
                        for (int i = 0; i < bridgeTrends.size(); i++) {
                            lineDatas.add(Float.parseFloat(bridgeTrends.get(i).getValue()));
                        }
                        bridgeBean.seriesData = lineDatas;
                        bridgeBean.initValue = Float.parseFloat(bridgeWarnings.get(position).getInitValue());
                        callBack.onSuccess(gson.toJson(bridgeBean));
                    } else {
                        callBack.onFail("01");
                    }
                } catch (Exception e) {
                    callBack.onFail("01");
                    e.printStackTrace();
                }
            }
        });
    }
}
Also used : Call(okhttp3.Call) ArrayList(java.util.ArrayList) FormBody(okhttp3.FormBody) Request(okhttp3.Request) IOException(java.io.IOException) IOException(java.io.IOException) Response(okhttp3.Response) Callback(okhttp3.Callback) JSONObject(org.json.JSONObject) BridgeTrend(itor.topnetwork.com.dxditor.bean.BridgeTrend) TypeToken(com.google.gson.reflect.TypeToken) ArrayList(java.util.ArrayList) List(java.util.List) BridgeBean(itor.topnetwork.com.dxditor.hybrid.bean.bridge.BridgeBean)

Aggregations

TypeToken (com.google.gson.reflect.TypeToken)1 BridgeTrend (itor.topnetwork.com.dxditor.bean.BridgeTrend)1 BridgeBean (itor.topnetwork.com.dxditor.hybrid.bean.bridge.BridgeBean)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Call (okhttp3.Call)1 Callback (okhttp3.Callback)1 FormBody (okhttp3.FormBody)1 Request (okhttp3.Request)1 Response (okhttp3.Response)1 JSONObject (org.json.JSONObject)1