Search in sources :

Example 1 with SpzTrend

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

the class SpzModel method getTrendData.

@Override
public void getTrendData(final ValueCallBack<String> callBack, int position) {
    spzTrends = new ArrayList<SpzTrend>();
    if (Constants.testData) {
        SpzEchartsBean spzBean = new SpzEchartsBean();
        if (position == 0) {
            for (int i = 0; i < 9; i++) {
                spzTrends.add(new SpzTrend(Float.parseFloat("10" + i), "03-2" + i + " 08:00"));
            }
        } else if (position == 1) {
            for (int i = 0; i < 9; i++) {
                spzTrends.add(new SpzTrend(Float.parseFloat("8" + i), "03-2" + i + " 08:00"));
            }
        } else if (position == 2) {
            for (int i = 0; i < 9; i++) {
                spzTrends.add(new SpzTrend(Float.parseFloat("7" + i), "03-2" + i + " 08:00"));
            }
        }
        List<String> time = new ArrayList<>();
        for (int i = 0; i < spzTrends.size(); i++) {
            time.add(spzTrends.get(i).getStorageTime());
        }
        spzBean.xData = time;
        List<Float> lineDatas = new ArrayList<>();
        for (int i = 0; i < spzTrends.size(); i++) {
            lineDatas.add(spzTrends.get(i).getTypeData());
        }
        spzBean.seriesData = lineDatas;
        callBack.onSuccess(gson.toJson(spzBean));
    } else {
        // Form表单格式的参数传递
        FormBody formBody = new FormBody.Builder().add("bridgeCode", spzWarnings.get(position).getBridgeCode()).add("type", spzWarnings.get(position).getType()).add("storageTime", Constants.MONTH).build();
        Request request = new Request.Builder().post(formBody).url(Constants.getAppSoundBarrierInfo).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();
                System.out.println("getAppSoundBarrierInfo:" + res);
                try {
                    JSONObject js = new JSONObject(res);
                    if (js.getBoolean("success")) {
                        spzTrends = gson.fromJson(js.getString("data"), new TypeToken<ArrayList<SpzTrend>>() {
                        }.getType());
                        SpzEchartsBean spzBean = new SpzEchartsBean();
                        // bridgeBean.initValue =;
                        List<String> time = new ArrayList<>();
                        for (int i = 0; i < spzTrends.size(); i++) {
                            time.add(spzTrends.get(i).getStorageTime());
                        }
                        spzBean.xData = time;
                        List<Float> lineDatas = new ArrayList<>();
                        for (int i = 0; i < spzTrends.size(); i++) {
                            lineDatas.add(spzTrends.get(i).getTypeData());
                        }
                        spzBean.seriesData = lineDatas;
                        callBack.onSuccess(gson.toJson(spzBean));
                    } 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) TypeToken(com.google.gson.reflect.TypeToken) SpzEchartsBean(itor.topnetwork.com.dxditor.hybrid.bean.spz.SpzEchartsBean) ArrayList(java.util.ArrayList) List(java.util.List) SpzTrend(itor.topnetwork.com.dxditor.bean.SpzTrend)

Aggregations

TypeToken (com.google.gson.reflect.TypeToken)1 SpzTrend (itor.topnetwork.com.dxditor.bean.SpzTrend)1 SpzEchartsBean (itor.topnetwork.com.dxditor.hybrid.bean.spz.SpzEchartsBean)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