package com.police.policedatasystem.http;

import static com.police.policedatasystem.util.UaCredentialApi.PARAMS_KEY_UA_APP_CREDENTIAL;
import static com.police.policedatasystem.util.UaCredentialApi.PARAMS_KEY_UA_RET_CODE;
import static com.police.policedatasystem.util.UaCredentialApi.PARAMS_KEY_UA_RET_SUCCESS;
import static com.police.policedatasystem.util.UaCredentialApi.PARAMS_KEY_UA_USER_CREDENTIAL;

import android.net.Uri;
import android.os.Bundle;

import androidx.annotation.NonNull;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.police.policedatasystem.App;
import com.police.policedatasystem.http.requestparams.GetKeyPersonDetailParams;
import com.police.policedatasystem.http.requestparams.GetKeyPersonListParams;
import com.police.policedatasystem.http.requestparams.GetKeyPersonMessageCountParams;
import com.police.policedatasystem.http.requestparams.GetOrgKeyPersonListParams;
import com.police.policedatasystem.http.requestparams.GetPoliceEmergencyDetailParams;
import com.police.policedatasystem.http.requestparams.GetPoliceEmergencyListParams;
import com.police.policedatasystem.http.requestparams.RequestParams;
import com.police.policedatasystem.http.requestparams.ResponseParams;
import com.police.policedatasystem.indexActivity;
import com.police.policedatasystem.model.DataCount;
import com.police.policedatasystem.model.KeyPerson;
import com.police.policedatasystem.model.KeyPersonDetail;
import com.police.policedatasystem.model.PoliceEmergency;
import com.police.policedatasystem.model.PoliceEmergencyDetail;
import com.police.policedatasystem.model.ResourceList;
import com.police.policedatasystem.model.UserCredential;
import com.police.policedatasystem.util.Constants;
import com.police.policedatasystem.util.UiUtils;

import java.io.IOException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.logging.HttpLoggingInterceptor;

public class RequestClient {
    private final indexActivity activity;
    private OkHttpClient okHttpClient;

    public RequestClient(indexActivity activity) {
        this.activity = activity;
    }

    /*

     */
    private void call(String url, RequestParams params, Callback callback) {
        try {
            RequestBody body = RequestBody.create(new Gson().toJson(params), MediaType.parse("application/json; charset=utf-8"));
            Request request = new Request.Builder()
                    .url(url)
                    .post(body)
                    .addHeader("userCredential", URLEncoder.encode(Constants.USER_CREDENTIAL, "UTF-8"))
                    .addHeader("appCredential", URLEncoder.encode(Constants.APP_CREDENTIAL, "UTF-8"))
                    .build();
            okHttpClient.newCall(request).enqueue(callback);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public void init() {
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); // 设置日志级别，例如打印请求和响应的body
        okHttpClient = new OkHttpClient.Builder()
                .addInterceptor(loggingInterceptor) // 添加日志拦截器
                .callTimeout(30, TimeUnit.SECONDS)
                .connectTimeout(30, TimeUnit.SECONDS)
                .build();
        //获取接口需要用到的凭证
        getInterface();
    }

    //获取接口需要用到的凭证
    private void getInterface() {
        Uri uri = Uri.parse("content://com.ydjw.ua.getCredential");
        Bundle params = new Bundle();
        String paramsMessageId = UiUtils.uuid();
        //构建参数
        params.putString("messageId", paramsMessageId);//消息id
        params.putString("version", "1");//接口版本号，当前为1
        params.putString("appId", Constants.APP_ID);//
        params.putString("orgId", Constants.ORG_ID);//
        params.putString("networkAreaCode", "3");//
        params.putString("packageName", "com.police.policedatasystem");//应用包名，可空
        //获取票据
        Bundle bundle = App.getApp().getContentResolver().call(uri, "", null, params);
        //解析结果
        if (bundle == null) {
            UiUtils.toast("获取应用凭证失败，bundle为空！");
            return;
        }
        String messageId = bundle.getString("messageId");
        if (paramsMessageId.equals(messageId)) {
            int resultCode = bundle.getInt(PARAMS_KEY_UA_RET_CODE);
            if (PARAMS_KEY_UA_RET_SUCCESS == resultCode) {
                Constants.APP_CREDENTIAL = bundle.getString(PARAMS_KEY_UA_APP_CREDENTIAL);
                Constants.USER_CREDENTIAL = bundle.getString(PARAMS_KEY_UA_USER_CREDENTIAL);
                Constants.USER_ID = new Gson().fromJson(Constants.USER_CREDENTIAL, UserCredential.class).getCredential().getLoad().getUserInfo().getJh();
                Constants.SFZH = new Gson().fromJson(Constants.USER_CREDENTIAL, UserCredential.class).getCredential().getLoad().getUserInfo().getSfzh();
                Constants.USER_ORG_ID = new Gson().fromJson(Constants.USER_CREDENTIAL, UserCredential.class).getCredential().getLoad().getUserInfo().getOrgId();
                //根据票据寻址
                findAddress();
            } else {
                UiUtils.toast(bundle.getString("message") + ",resultCode:" + resultCode);
            }
        } else {
            UiUtils.toast("获取应用凭证失败，messageId不一致！");
        }
    }

    //第二步，寻址
    private void findAddress() {
        Thread thread = new Thread(() -> {
            // 在这里执行耗时任务
            Uri uri = Uri.parse("content://com.ydjw.rsb.getResourceAddress");
            Bundle bundle = new Bundle();
            String paramsMessageId = UiUtils.uuid();
            bundle.putString("appCredential", Constants.APP_CREDENTIAL);//应用凭证，由上一步获得
            bundle.putString("userCredential", Constants.USER_CREDENTIAL);//用户凭证，由上一步获得
            bundle.putString("version", "1");//服务总线接口版本号，当前为1
            bundle.putString("messageId", paramsMessageId);//消息 ID
            Bundle callBack = App.getApp().getContentResolver().call(uri, "", null, bundle);
            if (callBack == null) {
                UiUtils.toast("获取应用资源地址失败,bundle为空");
                return;
            }
            String messageId = callBack.getString("messageId");
            String resourceList = callBack.getString("resourceList");
            if (paramsMessageId.equals(messageId)) {
                int resultCode = callBack.getInt("resultCode");
                if (resultCode == 0) {
                    if (UiUtils.isEmpty(resourceList)) {
                        UiUtils.toast("寻址失败，resourceList为空！");
                        return;
                    }
                    List<ResourceList> resourceLists = new Gson().fromJson(resourceList, new TypeToken<List<ResourceList>>() {
                    }.getType());
                    for (ResourceList item : resourceLists) {
                        Constants.resourceListsMap.put(item.getResourceId(), item);
                    }
                    //2.发起请求，获取重点人数据
                    activity.initData();
                } else {
                    if (UiUtils.isEmpty(resourceList)) {
                        UiUtils.toast("寻址失败，错误码：" + resultCode);
                    }
                }
            }
        });
        thread.start();
    }

    /**
     * 获取重点人
     *
     * @param params   参数对象
     * @param callback 回调函数
     */
    public void getKeyPerson(GetKeyPersonListParams params, CustomCallBack<List<KeyPerson>> callback) {
        ResourceList resourceList = Constants.resourceListsMap.get(Constants.KEY_PERSON_ID);
        RequestParams.Condition condition = new RequestParams.Condition();
        condition.setLogicalOperate("and");
        RequestParams.KeyValues keyValues = new RequestParams.KeyValues();
        keyValues.setKey("injson");
        params.setJybh(Constants.USER_ID);
        params.setSfhm(Constants.SFZH);
        params.setPageSize(Constants.PAGE_SIZE + "");
        keyValues.setValue(new Gson().toJson(params));
        List<RequestParams.KeyValues> keyValuesList = new ArrayList<>();
        keyValuesList.add(keyValues);
        condition.setKeyValueList(keyValuesList);
        RequestParams.Parameter parameter = new RequestParams.Parameter();
        parameter.setCondition(condition);
        parameter.setPage(new RequestParams.Page());
        parameter.setFields("outjson");
        parameter.setNetworkCode("3");
        parameter.setOrderBy(null);
        parameter.setRegionalismCode(Constants.ORG_ID);
        parameter.setDataObjId(Constants.KEY_PERSON_ID);
        RequestParams requestParams = new RequestParams();
        requestParams.setMessageId(UiUtils.uuid());
        requestParams.setVersion("1.0");
        requestParams.setParameter(parameter);
        if (resourceList == null) return;
        call(resourceList.getResourceAddress(), requestParams, new Callback() {
            @Override
            public void onFailure(@NonNull Call call, @NonNull IOException e) {
                activity.runOnUiThread(() -> callback.onError(call, e));
                // 请求失败
                e.printStackTrace();
            }

            @Override
            public void onResponse(@NonNull Call call, @NonNull Response response) {
                try {
                    // 请求成功，处理响应数据
                    String responseBody = response.body().string();
                    activity.runOnUiThread(() -> {
                        if (!response.isSuccessful()) {
                            callback.onError(call, new IOException("Unexpected code " + response));
                            return;
                        }
                        ResponseParams responseParams = new Gson().fromJson(responseBody, ResponseParams.class);
                        if ("200".equals(responseParams.getCode())) {
                            for (ResponseParams.FieldData item : responseParams.getData().getDataList()) {
                                for (ResponseParams.FieldValues i : item.getFieldValues()) {
                                    List<KeyPerson> keyPersonList = new Gson().fromJson(i.getValue(), new TypeToken<List<KeyPerson>>() {
                                    }.getType());
                                    callback.onSuccess(keyPersonList);
                                }
                            }
                        } else {
                            callback.onError(call, new IOException(responseParams.getMessage()));
                        }
                    });
                } catch (Exception e) {
                    callback.onError(call, e);
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * 获取组织重点人数据
     *
     * @param params   搜索关键字姓名
     * @param callBack 回调函数
     */
    public void getOrgKeyPerson(GetOrgKeyPersonListParams params, CustomCallBack<List<KeyPerson>> callBack) {
        ResourceList resourceList = Constants.resourceListsMap.get(Constants.ORG_KEY_PERSON_ID);
        RequestParams.Condition condition = new RequestParams.Condition();
        condition.setLogicalOperate("and");
        RequestParams.KeyValues keyValues = new RequestParams.KeyValues();
        keyValues.setKey("injson");
        params.setSfhm(Constants.SFZH);
        params.setDept(Constants.USER_ORG_ID);
        params.setPageSize(Constants.PAGE_SIZE + "");
        keyValues.setValue(new Gson().toJson(params));
        List<RequestParams.KeyValues> keyValuesList = new ArrayList<>();
        keyValuesList.add(keyValues);
        condition.setKeyValueList(keyValuesList);
        RequestParams.Parameter parameter = new RequestParams.Parameter();
        parameter.setCondition(condition);
        parameter.setPage(new RequestParams.Page());
        parameter.setFields("outjson");
        parameter.setNetworkCode("3");
        parameter.setOrderBy(null);
        parameter.setRegionalismCode(Constants.ORG_ID);
        parameter.setDataObjId(Constants.ORG_KEY_PERSON_ID);
        RequestParams requestParams = new RequestParams();
        requestParams.setMessageId(UiUtils.uuid());
        requestParams.setVersion("1.0");
        requestParams.setParameter(parameter);
        if (resourceList == null) {
            callBack.onError(null, new Exception("寻址数据为空"));
            return;
        }

        call(resourceList.getResourceAddress(), requestParams, new Callback() {
            @Override
            public void onFailure(@NonNull Call call, @NonNull IOException e) {
                activity.runOnUiThread(() -> callBack.onError(call, e));
                // 请求失败
                e.printStackTrace();
            }

            @Override
            public void onResponse(@NonNull Call call, @NonNull Response response) {
                if (!response.isSuccessful()) {
                    activity.runOnUiThread(() -> callBack.onError(call, new IOException("Unexpected code " + response)));
                    return;
                }
                try {
                    // 请求成功，处理响应数据
                    String responseBody = response.body().string();
                    activity.runOnUiThread(() -> {
                        ResponseParams responseParams = new Gson().fromJson(responseBody, ResponseParams.class);
                        if ("200".equals(responseParams.getCode())) {
                            for (ResponseParams.FieldData item : responseParams.getData().getDataList()) {
                                for (ResponseParams.FieldValues i : item.getFieldValues()) {
                                    List<KeyPerson> keyPersonList = new Gson().fromJson(i.getValue(), new TypeToken<List<KeyPerson>>() {
                                    }.getType());
                                    callBack.onSuccess(keyPersonList);
                                }
                            }
                        } else {
                            callBack.onError(call, new Exception(responseParams.getMessage()));
                        }
                    });
                } catch (Exception e) {
                    activity.runOnUiThread(() -> callBack.onError(call, e));
                    e.printStackTrace();
                }

            }
        });
    }


    /**
     * 获取重点人详情数据
     *
     * @param str 身份证号
     */
    public void keyPersonDetail(String str, CustomCallBack<KeyPersonDetail> callBack) {
        ResourceList resourceList = Constants.resourceListsMap.get(Constants.KEY_PERSON_DETAIL_ID);
        RequestParams.Condition condition = new RequestParams.Condition();
        condition.setLogicalOperate("and");
        RequestParams.KeyValues keyValues = new RequestParams.KeyValues();
        keyValues.setKey("injson");
        GetKeyPersonDetailParams params = new GetKeyPersonDetailParams();
        params.setSfzh(str);//      params.setSfzh("220104197307276911");
        params.setSfhm(Constants.SFZH);
        keyValues.setValue(new Gson().toJson(params));
        List<RequestParams.KeyValues> keyValuesList = new ArrayList<>();
        keyValuesList.add(keyValues);
        condition.setKeyValueList(keyValuesList);
        RequestParams.Parameter parameter = new RequestParams.Parameter();
        parameter.setCondition(condition);
        parameter.setPage(new RequestParams.Page());
        parameter.setFields("outjson");
        parameter.setNetworkCode("3");
        parameter.setOrderBy(null);
        parameter.setRegionalismCode(Constants.ORG_ID);
        parameter.setDataObjId(Constants.KEY_PERSON_DETAIL_ID);
        RequestParams requestParams = new RequestParams();
        requestParams.setMessageId(UiUtils.uuid());
        requestParams.setVersion("1.0");
        requestParams.setParameter(parameter);
        call(resourceList.getResourceAddress(), requestParams, new Callback() {
            @Override
            public void onFailure(@NonNull Call call, @NonNull IOException e) {
                // 请求失败
                e.printStackTrace();
                activity.runOnUiThread(() -> callBack.onError(call, e));
            }

            @Override
            public void onResponse(@NonNull Call call, @NonNull Response response) {
                if (!response.isSuccessful()) {
                    activity.runOnUiThread(() -> callBack.onError(call, new IOException("Unexpected code " + response)));
                    return;
                }
                try {
                    // 请求成功，处理响应数据
                    String responseBody = response.body().string();
                    ResponseParams responseParams = new Gson().fromJson(responseBody, ResponseParams.class);
                    if (!"200".equals(responseParams.getCode())) {
                        activity.runOnUiThread(() -> callBack.onError(call, new Exception("服务器异常，请联系开发人员或稍后重试！")));
                        return;
                    }
                    for (ResponseParams.FieldData item : responseParams.getData().getDataList()) {
                        for (ResponseParams.FieldValues i : item.getFieldValues()) {
                            KeyPersonDetail keyPersonDetail = new Gson().fromJson(i.getValue(), KeyPersonDetail.class);
                            activity.runOnUiThread(() -> callBack.onSuccess(keyPersonDetail));
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    activity.runOnUiThread(() -> callBack.onError(call, e));
                }
            }
        });
    }

    /**
     * 获取警情列表数据
     *
     * @param params   参数
     * @param callBack 回调函数
     */
    public void getPoliceEmergency(GetPoliceEmergencyListParams params, CustomCallBack<List<PoliceEmergency>> callBack) {
        ResourceList resourceList = Constants.resourceListsMap.get(Constants.POLICE_EMERGENCY_ID);
        RequestParams.Condition condition = new RequestParams.Condition();
        condition.setLogicalOperate("and");
        RequestParams.KeyValues keyValues = new RequestParams.KeyValues();
        keyValues.setKey("injson");
        params.setSfhm(Constants.SFZH);
//        params.setSfhm("220104198105200331");
        params.setPageSize(Constants.PAGE_SIZE + "");
        keyValues.setValue(new Gson().toJson(params));
        List<RequestParams.KeyValues> keyValuesList = new ArrayList<>();
        keyValuesList.add(keyValues);
        condition.setKeyValueList(keyValuesList);
        RequestParams.Parameter parameter = new RequestParams.Parameter();
        parameter.setCondition(condition);
        parameter.setPage(new RequestParams.Page());
        parameter.setFields("outjson");
        parameter.setNetworkCode("3");
        parameter.setOrderBy(null);
        parameter.setRegionalismCode(Constants.ORG_ID);
        parameter.setDataObjId(Constants.POLICE_EMERGENCY_ID);
        RequestParams requestParams = new RequestParams();
        requestParams.setMessageId(UiUtils.uuid());
        requestParams.setVersion("1.0");
        requestParams.setParameter(parameter);
        if (resourceList == null) {
            callBack.onError(null, new Exception("寻址数据为空"));
            return;
        }

        call(resourceList.getResourceAddress(), requestParams, new Callback() {
            @Override
            public void onFailure(@NonNull Call call, @NonNull IOException e) {
                activity.runOnUiThread(() -> callBack.onError(call, e));
                // 请求失败
                e.printStackTrace();
            }

            @Override
            public void onResponse(@NonNull Call call, @NonNull Response response) {
                if (!response.isSuccessful()) {
                    activity.runOnUiThread(() -> callBack.onError(call, new IOException("Unexpected code " + response)));
                    return;
                }
                try {
                    // 请求成功，处理响应数据
                    String responseBody = response.body().string();
                    activity.runOnUiThread(() -> {
                        ResponseParams responseParams = new Gson().fromJson(responseBody, ResponseParams.class);
                        if ("200".equals(responseParams.getCode())) {
                            for (ResponseParams.FieldData item : responseParams.getData().getDataList()) {
                                for (ResponseParams.FieldValues i : item.getFieldValues()) {
                                    List<PoliceEmergency> keyPersonList = new Gson().fromJson(i.getValue(), new TypeToken<List<PoliceEmergency>>() {
                                    }.getType());
                                    callBack.onSuccess(keyPersonList);
                                }
                            }
                        } else {
                            callBack.onError(call, new Exception(responseParams.getMessage()));
                        }
                    });
                } catch (Exception e) {
                    activity.runOnUiThread(() -> callBack.onError(call, e));
                    e.printStackTrace();
                }

            }
        });
    }


    /**
     * 获取重点人详情数据
     *
     * @param str 身份证号
     */
    public void getPoliceEmergencyDetail(String str, CustomCallBack<PoliceEmergencyDetail> callBack) {
        ResourceList resourceList = Constants.resourceListsMap.get(Constants.POLICE_EMERGENCY_DETAIL_ID);
        RequestParams.Condition condition = new RequestParams.Condition();
        condition.setLogicalOperate("and");
        RequestParams.KeyValues keyValues = new RequestParams.KeyValues();
        keyValues.setKey("injson");
        GetPoliceEmergencyDetailParams params = new GetPoliceEmergencyDetailParams();
        params.setJcjbh(str);//      params.setSfzh("220104197307276911");
        params.setSfhm(Constants.SFZH);
        keyValues.setValue(new Gson().toJson(params));
        List<RequestParams.KeyValues> keyValuesList = new ArrayList<>();
        keyValuesList.add(keyValues);
        condition.setKeyValueList(keyValuesList);
        RequestParams.Parameter parameter = new RequestParams.Parameter();
        parameter.setCondition(condition);
        parameter.setPage(new RequestParams.Page());
        parameter.setFields("outjson");
        parameter.setNetworkCode("3");
        parameter.setOrderBy(null);
        parameter.setRegionalismCode(Constants.ORG_ID);
        parameter.setDataObjId(Constants.POLICE_EMERGENCY_DETAIL_ID);
        RequestParams requestParams = new RequestParams();
        requestParams.setMessageId(UiUtils.uuid());
        requestParams.setVersion("1.0");
        requestParams.setParameter(parameter);
        call(resourceList.getResourceAddress(), requestParams, new Callback() {
            @Override
            public void onFailure(@NonNull Call call, @NonNull IOException e) {
                // 请求失败
                e.printStackTrace();
                activity.runOnUiThread(() -> callBack.onError(call, e));
            }

            @Override
            public void onResponse(@NonNull Call call, @NonNull Response response) {
                if (!response.isSuccessful()) {
                    activity.runOnUiThread(() -> callBack.onError(call, new IOException("Unexpected code " + response)));
                    return;
                }
                try {
                    // 请求成功，处理响应数据
                    String responseBody = response.body().string();
                    ResponseParams responseParams = new Gson().fromJson(responseBody, ResponseParams.class);
                    if (!"200".equals(responseParams.getCode())) {
                        activity.runOnUiThread(() -> callBack.onError(call, new Exception("服务器异常，请联系开发人员或稍后重试！")));
                        return;
                    }
                    for (ResponseParams.FieldData item : responseParams.getData().getDataList()) {
                        for (ResponseParams.FieldValues i : item.getFieldValues()) {
                            PoliceEmergencyDetail keyPersonDetail = new Gson().fromJson(i.getValue(), PoliceEmergencyDetail.class);
                            activity.runOnUiThread(() -> callBack.onSuccess(keyPersonDetail));
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    activity.runOnUiThread(() -> callBack.onError(call, e));
                }
            }
        });
    }

    /**
     * 获取重点人数据统计
     */
    public void getKeyPersonMessageCount(CustomCallBack<DataCount> callBack) {
        ResourceList resourceList = Constants.resourceListsMap.get(Constants.KEY_PERSON_MESSAGE_COUNT_ID);
        RequestParams.Condition condition = new RequestParams.Condition();
        condition.setLogicalOperate("and");
        RequestParams.KeyValues keyValues = new RequestParams.KeyValues();
        keyValues.setKey("injson");
        GetKeyPersonMessageCountParams params = new GetKeyPersonMessageCountParams();
        params.setSfhm(Constants.SFZH);
        params.setJybh(Constants.USER_ID);
        params.setDept(Constants.USER_ORG_ID);
//        params.setSfhm("220104198105200331");
//        params.setDept(Constants.USER_ORG_ID);
//        params.setJybh("106222");
        keyValues.setValue(new Gson().toJson(params));
        List<RequestParams.KeyValues> keyValuesList = new ArrayList<>();
        keyValuesList.add(keyValues);
        condition.setKeyValueList(keyValuesList);
        RequestParams.Parameter parameter = new RequestParams.Parameter();
        parameter.setCondition(condition);
        parameter.setPage(new RequestParams.Page());
        parameter.setFields("outjson");
        parameter.setNetworkCode("3");
        parameter.setOrderBy(null);
        parameter.setRegionalismCode(Constants.ORG_ID);
        parameter.setDataObjId(Constants.KEY_PERSON_MESSAGE_COUNT_ID);
        RequestParams requestParams = new RequestParams();
        requestParams.setMessageId(UiUtils.uuid());
        requestParams.setVersion("1.0");
        requestParams.setParameter(parameter);
        call(resourceList.getResourceAddress(), requestParams, new Callback() {
            @Override
            public void onFailure(@NonNull Call call, @NonNull IOException e) {
                // 请求失败
                e.printStackTrace();
                activity.runOnUiThread(() -> callBack.onError(call, e));
            }

            @Override
            public void onResponse(@NonNull Call call, @NonNull Response response) {
                if (!response.isSuccessful()) {
                    activity.runOnUiThread(() -> callBack.onError(call, new IOException("Unexpected code " + response)));
                    return;
                }
                try {
                    // 请求成功，处理响应数据
                    String responseBody = response.body().string();
                    ResponseParams responseParams = new Gson().fromJson(responseBody, ResponseParams.class);
                    if (!"200".equals(responseParams.getCode())) {
                        activity.runOnUiThread(() -> callBack.onError(call, new Exception("服务器异常，请联系开发人员或稍后重试！")));
                        return;
                    }
                    for (ResponseParams.FieldData item : responseParams.getData().getDataList()) {
                        for (ResponseParams.FieldValues i : item.getFieldValues()) {
                            DataCount dataCount = new Gson().fromJson(i.getValue(), DataCount.class);
                            activity.runOnUiThread(() -> callBack.onSuccess(dataCount));
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                    activity.runOnUiThread(() -> callBack.onError(call, e));
                }
            }
        });
    }
}
