package com.tofly.ghrq_route.module.buildManage.service;

import android.content.Context;
import android.text.TextUtils;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.tofly.ghrq_route.base.BaseApp;
import com.tofly.ghrq_route.base.url.NetRequestURL;
import com.tofly.ghrq_route.base.URLResponseCode;
import com.tofly.ghrq_route.module.buildManage.BuildExamineBean;
import com.tofly.ghrq_route.module.buildManage.BuildExaminesBean;
import com.tofly.ghrq_route.module.buildManage.controller.BuildManageCallback;
import com.tofly.ghrq_route.module.buildManage.domain.BuildFileBean;
import com.tofly.ghrq_route.module.buildManage.domain.BuildHandleBean;
import com.tofly.ghrq_route.module.buildManage.domain.BuildHandleDataBean;
import com.tofly.ghrq_route.module.buildManage.domain.BuildManageBean;
import com.tofly.ghrq_route.module.buildManage.domain.BuildManageBeans;
import com.tofly.ghrq_route.module.buildManage.domain.BuildManageFileBean;
import com.tofly.ghrq_route.module.buildManage.domain.BuildManagerBean;
import com.tofly.ghrq_route.module.buildManage.domain.BuildProcessManageBean;
import com.tofly.ghrq_route.module.buildManage.domain.BuildProjectTypeBean;
import com.tofly.ghrq_route.module.buildManage.domain.BuildReportBean;
import com.tofly.ghrq_route.module.buildManage.domain.DepartmentBean;
import com.tofly.ghrq_route.module.buildManage.domain.UserListBean;
import com.tofly.ghrq_route.module.buildManage.domain.VoiceBeans;
import com.tofly.ghrq_route.module.buildManage.domain.BuildTypeBean;
import com.tofly.ghrq_route.module.sqlite.DBDaoHelper;
import com.tofly.ghrq_route.module.trouble.domain.TroubleAudioBean;
import com.tofly.ghrq_route.module.trouble.domain.TroubleBean;
import com.tofly.ghrq_route.module.trouble.domain.TroublePictureBean;
import com.tofly.ghrq_route.module.user.domain.MessageUserBean;
import com.tofly.ghrq_route.common.util.net.volley.MultiPartStringRequest;


import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Amu on 2017/5/22.
 */

public class BuildManageServiceImpl implements IBuildManageService {
    private Context mContext;

    private DBDaoHelper dbDaoHelper;

    public BuildManageServiceImpl(Context context) {
        mContext = context;
        dbDaoHelper = DBDaoHelper.getInstance();
    }

    @Override
    public void getBuildManageList(final String constructionState, final int pageindex, final int pagesize, final BuildManageCallback buildManageCallback) {
        //Http post请求,获取隐患列表
        String userId = BaseApp.getInstance().getLoginUser().getUserid();
        String url = NetRequestURL.getBuildManageListUrl() + "?current=" + pageindex + "&size=" + pagesize + "&userIds=" + userId + "&constructionStates=2,4"
        + "&orders[0].asc=false&orders[0].column=dispatch_date";
        StringRequest postRequest = new StringRequest(Request.Method.GET,
                url, response -> {
            URLResponseCode.URLResponse responseCode = new URLResponseCode.URLResponse(response);
            if (responseCode.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                String rowsArray = responseCode.queryResult("records");
                List<BuildManageBeans> buildManages = null;
                List<BuildManageBean> dataList = null;
                int resCode = -1;
                boolean result = false;
                String parseErrMsg = "用户解析失败";
                int total = 0;
                String strTotal = responseCode.queryResult("total");
                if (strTotal != null && !strTotal.isEmpty()) {
                    total = Integer.parseInt(strTotal);
                }
                if (rowsArray != null) {
                    try {
                        Gson gson = new Gson();
                        buildManages = gson.fromJson(rowsArray, new TypeToken<List<BuildManageBeans>>() {
                        }.getType());
                        dataList = gson.fromJson(rowsArray, new TypeToken<List<BuildManageBean>>() {
                        }.getType());
                        if (buildManages != null && buildManages.size() >= 0) {
                            resCode = responseCode.getCode();
                            parseErrMsg = responseCode.getMessage();
                            result = true;
                            saveBuildManages(buildManages, dataList);
                        }
                    } catch (Exception e) {
                        buildManageCallback.onGetBuildManageList(false, resCode, parseErrMsg, null, 0);
                    }
                }
                buildManageCallback.onGetBuildManageList(result, resCode, parseErrMsg, dataList, total);
            } else {
                buildManageCallback.onGetBuildManageList(
                        false, responseCode.getCode(), responseCode.getMessage(), null, 0);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                //登录失败
                if (error.networkResponse != null) {
                    try {
                        String errString = new String(error.networkResponse.data, "UTF-8");
                        buildManageCallback.onGetBuildManageList(
                                false, error.networkResponse.statusCode, errString, null, 0);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        buildManageCallback.onGetBuildManageList(
                                false, error.networkResponse.statusCode, null, null, 0);
                    }
                } else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    buildManageCallback.onGetBuildManageList(
                            false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null, 0);
                }
            }
        }) {
//            @Override
//            protected Map<String, String> getParams() {
//                //参数拼装:表单提交方式
//                Map<String, String> params = new HashMap<String, String>();
//                params.put("pageindex", pageindex + "");
//                params.put("pagesize", pagesize + "");
//                if (state != -1) {
//                    params.put("state", state + "");
//                }
//                if (type != null && !type.isEmpty()) {
//                    params.put("project_type_id", type);
//                }
//                params.put("is_start", "1");
//                return params;
//            }

            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = NetRequestURL.newApi_dyrq.getHeaderParams();
                return params;
            }
        };
        BaseApp.addRequest(mContext.getClass().getName(), postRequest);
    }

    @Override
    public void getDataList(int state, int pageindex, int pagesize, BuildManageCallback buildManageCallback) {
        String userid = BaseApp.getInstance().getLoginUser().getUserid();
        String url = NetRequestURL.getBuildListUrl() + "?current=" + pageindex + "&size=" + pagesize + "&userIds=" + userid + "&constructionStates=" + state;
        StringRequest postRequest = new StringRequest(Request.Method.GET, url, response -> {
            URLResponseCode.URLResponse responseCode = new URLResponseCode.URLResponse(response);
            if (responseCode.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                String rowsArray = responseCode.queryResult("records");
                List<BuildManageBean> buildManages = null;
                int resCode = -1;
                String parseErrMsg = "用户解析失败";
                int total = 0;
                String strTotal = responseCode.queryResult("total");
                if (strTotal != null && !strTotal.isEmpty()) {
                    total = Integer.parseInt(strTotal);
                }
                if (rowsArray != null) {
                    try {
                        Gson gson = new Gson();
                        buildManages = gson.fromJson(rowsArray, new TypeToken<List<BuildManageBean>>() {
                        }.getType());
                        if (buildManages != null) {
                            resCode = responseCode.getCode();
                            parseErrMsg = responseCode.getMessage();
                            buildManageCallback.onGetBuildManageList(true, resCode, parseErrMsg, buildManages, total);
                        }
                    } catch (Exception e) {
                        buildManageCallback.onGetBuildManageList(false, resCode, parseErrMsg, null, 0);
                    }
                }
                buildManageCallback.onGetBuildManageList(false, resCode, parseErrMsg, buildManages, total);
            } else {
                buildManageCallback.onGetBuildManageList(false, responseCode.getCode(), responseCode.getMessage(), null, 0);
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    buildManageCallback.onGetBuildManageList(false, error.networkResponse.statusCode, errString, null, 0);
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                    buildManageCallback.onGetBuildManageList(false, error.networkResponse.statusCode, null, null, 0);
                }
            } else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                buildManageCallback.onGetBuildManageList(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null, 0);
            }
        }) {

            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = NetRequestURL.newApi_dyrq.getHeaderParams();
                return params;
            }
        };
        BaseApp.addRequest(mContext.getClass().getName(), postRequest);
    }

    @Override
    public void searchData(String keyWord, int pageindex, int pagesize, BuildManageCallback buildManageCallback) {
        String url;
        if (!TextUtils.isEmpty(keyWord)) {
            String content = "";
            try {
                content = URLEncoder.encode(keyWord, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            url = NetRequestURL.getBuildManageListUrl() + "?current=" + pageindex + "&size=" + pagesize + "&nameOrAdsOrDesc=" + content;
        } else {
            url = NetRequestURL.getBuildManageListUrl() + "?current=" + pageindex + "&size=" + pagesize;
        }
        StringRequest postRequest = new StringRequest(Request.Method.GET, url, response -> {
            URLResponseCode.URLResponse responseCode = new URLResponseCode.URLResponse(response);
            if (responseCode.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                String rowsArray = responseCode.queryResult("records");
                List<BuildManageBean> buildManages = null;
                int resCode = -1;
                String parseErrMsg = "用户解析失败";
                int total = 0;
                String strTotal = responseCode.queryResult("total");
                if (strTotal != null && !strTotal.isEmpty()) {
                    total = Integer.parseInt(strTotal);
                }
                if (rowsArray != null) {
                    try {
                        Gson gson = new Gson();
                        buildManages = gson.fromJson(rowsArray, new TypeToken<List<BuildManageBean>>() {
                        }.getType());
                        if (buildManages != null) {
                            resCode = responseCode.getCode();
                            parseErrMsg = responseCode.getMessage();
                            buildManageCallback.onGetBuildManageList(true, resCode, parseErrMsg, buildManages, total);
                        }
                    } catch (Exception e) {
                        buildManageCallback.onGetBuildManageList(false, resCode, parseErrMsg, null, 0);
                    }
                }
                buildManageCallback.onGetBuildManageList(false, resCode, parseErrMsg, buildManages, total);
            } else {
                buildManageCallback.onGetBuildManageList(false, responseCode.getCode(), responseCode.getMessage(), null, 0);
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    buildManageCallback.onGetBuildManageList(false, error.networkResponse.statusCode, errString, null, 0);
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                    buildManageCallback.onGetBuildManageList(false, error.networkResponse.statusCode, null, null, 0);
                }
            } else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                buildManageCallback.onGetBuildManageList(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null, 0);
            }
        }) {

            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = NetRequestURL.newApi_dyrq.getHeaderParams();
                return params;
            }
        };
        BaseApp.addRequest(mContext.getClass().getName(), postRequest);
    }

    @Override
    public void getBuildDetail(String id, BuildManageCallback buildManageCallback) {
        String url = NetRequestURL.getBuildDetailUrl() + id;
        StringRequest postRequest = new StringRequest(Request.Method.GET, url, response -> {
            URLResponseCode.URLResponse responseCode = new URLResponseCode.URLResponse(response);
            if (responseCode.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                String rowsArray = responseCode.getResult();
                BuildManageBeans buildManages = null;
                int resCode = -1;
                String parseErrMsg = "用户解析失败";
                int total = 0;
                String strTotal = responseCode.queryResult("total");
                if (strTotal != null && !strTotal.isEmpty()) {
                    total = Integer.parseInt(strTotal);
                }
                if (rowsArray != null) {
                    try {
                        Gson gson = new Gson();
                        buildManages = gson.fromJson(rowsArray, new TypeToken<BuildManageBeans>() {
                        }.getType());
                        if (buildManages != null) {
                            resCode = responseCode.getCode();
                            parseErrMsg = responseCode.getMessage();
                            buildManageCallback.onBuildDataDetail(true, resCode, parseErrMsg, buildManages, total);
                        }
                    } catch (Exception e) {
                        buildManageCallback.onBuildDataDetail(false, resCode, parseErrMsg, null, 0);
                    }
                }
                buildManageCallback.onBuildDataDetail(false, resCode, parseErrMsg, buildManages, total);
            } else {
                buildManageCallback.onBuildDataDetail(false, responseCode.getCode(), responseCode.getMessage(), null, 0);
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    buildManageCallback.onBuildDataDetail(false, error.networkResponse.statusCode, errString, null, 0);
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                    buildManageCallback.onBuildDataDetail(false, error.networkResponse.statusCode, null, null, 0);
                }
            } else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                buildManageCallback.onBuildDataDetail(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null, 0);
            }
        }) {

            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = NetRequestURL.newApi_dyrq.getHeaderParams();
                return params;
            }
        };
        BaseApp.addRequest(mContext.getClass().getName(), postRequest);
    }

    private void saveBuildManages(List<BuildManageBeans> dataList, List<BuildManageBean> buildManages) {
        dbDaoHelper.deleteAllBuildManages();
        dbDaoHelper.deleteAllBuildProcess();
        dbDaoHelper.deleteAllBuildExamine();
        dbDaoHelper.deleteAllBuildFile();
        if (buildManages != null && buildManages.size() > 0) {
            for (BuildManageBean buildManageBean : buildManages) {
                dbDaoHelper.insertOrUpdateBuildManage(buildManageBean);
            }
            if (dataList != null && dataList.size() > 0) {
                for (BuildManageBeans data : dataList) {
                    if (data.getVoice() != null && data.getVoice().size() > 0) {
                        for (VoiceBeans voiceBeans : data.getVoice()) {
                            BuildManageFileBean buildManageFileBean = new BuildManageFileBean();
                            if (!TextUtils.isEmpty(data.getId())) {
                                buildManageFileBean.setBuildId(data.getId());
                            }
                            if (!TextUtils.isEmpty(voiceBeans.getFileName())) {
                                buildManageFileBean.setVoiceName(voiceBeans.getFileName());
                            }
                            if (!TextUtils.isEmpty(voiceBeans.getPath())) {
                                buildManageFileBean.setVoicePath(voiceBeans.getPath());
                            }
                            dbDaoHelper.insertOrUpdateBuildManageFile(buildManageFileBean);
                        }
                    }
                    if (data.getFiles() != null && data.getFiles().size() > 0) {
                        for (VoiceBeans voiceBeans : data.getFiles()) {
                            BuildManageFileBean buildManageFileBean = new BuildManageFileBean();
                            if (!TextUtils.isEmpty(data.getId())) {
                                buildManageFileBean.setBuildId(data.getId());
                            }
                            if (!TextUtils.isEmpty(voiceBeans.getFileName())) {
                                buildManageFileBean.setFileName(voiceBeans.getFileName());
                            }
                            if (!TextUtils.isEmpty(voiceBeans.getPath())) {
                                buildManageFileBean.setFilePath(voiceBeans.getPath());
                            }
                            dbDaoHelper.insertOrUpdateBuildManageFile(buildManageFileBean);
                        }
                    }
                    if (data.getAuditList() != null && data.getAuditList().size() > 0) {
                        for (BuildExaminesBean buildExaminesBean : data.getAuditList()) {
                            BuildExamineBean buildExamineBean = new BuildExamineBean();
                            if (!TextUtils.isEmpty(buildExaminesBean.getWorkOrderId())) {
                                buildExamineBean.setWorkOrderId("" + buildExaminesBean.getWorkOrderId());
                            }
                            if (!TextUtils.isEmpty(buildExaminesBean.getId())) {
                                buildExamineBean.setId(buildExaminesBean.getId());
                            }
                            if (!TextUtils.isEmpty(buildExaminesBean.getAuditDescription())) {
                                buildExamineBean.setAuditDescription(buildExaminesBean.getAuditDescription());
                            }
                            if (!TextUtils.isEmpty(buildExaminesBean.getAuditmind())) {
                                buildExamineBean.setAuditmind(buildExaminesBean.getAuditmind());
                            }
                            if (!TextUtils.isEmpty(buildExaminesBean.getAuditMindName())) {
                                buildExamineBean.setAuditMindName(buildExaminesBean.getAuditMindName());
                            }
                            if (!TextUtils.isEmpty(buildExaminesBean.getAuditTime())) {
                                buildExamineBean.setAuditTime(buildExaminesBean.getAuditTime());
                            }
                            if (!TextUtils.isEmpty(buildExaminesBean.getDelFlag())) {
                                buildExamineBean.setDelFlag(buildExaminesBean.getDelFlag());
                            }
                            if (!TextUtils.isEmpty(buildExaminesBean.getAuditor())) {
                                buildExamineBean.setAuditor("" + buildExaminesBean.getAuditor());
                            }
                            if (!TextUtils.isEmpty(buildExaminesBean.getAuditorName())) {
                                buildExamineBean.setAuditorName(buildExaminesBean.getAuditorName());
                            }
                            dbDaoHelper.insertOrUpdateExamine(buildExamineBean);
                            if (buildExaminesBean.getAuditEndFiles() != null && buildExaminesBean.getAuditEndFiles().size() > 0) {
                                for (VoiceBeans voiceBeans : buildExaminesBean.getAuditEndFiles()) {
                                    BuildManageFileBean fileBean = new BuildManageFileBean();
                                    if (!TextUtils.isEmpty(data.getId())) {
                                        fileBean.setBuildId(data.getId());
                                    }
                                    if (!TextUtils.isEmpty(buildExaminesBean.getId())) {
                                        fileBean.setExamineId(buildExaminesBean.getId());
                                    }
                                    if (!TextUtils.isEmpty(voiceBeans.getFileName())) {
                                        fileBean.setAuditEndFilesName(voiceBeans.getFileName());
                                    }
                                    if (!TextUtils.isEmpty(voiceBeans.getPath())) {
                                        fileBean.setAuditEndFilesPath(voiceBeans.getPath());
                                    }
                                    dbDaoHelper.insertOrUpdateBuildManageFile(fileBean);
                                }
                            }
                        }
                    }
                    if (data.getProcessManages() != null && data.getProcessManages().size() > 0) {
                        for (BuildManageBeans.ProcssManageBean procssManageBean : data.getProcessManages()) {
                            BuildProcessManageBean buildProcessManageBean = new BuildProcessManageBean();
                            if (!TextUtils.isEmpty(data.getId())) {
                                buildProcessManageBean.setWorkOrderId(data.getId());
                            }
                            if (!TextUtils.isEmpty(procssManageBean.getId())) {
                                buildProcessManageBean.setId(procssManageBean.getId());
                            }
                            if (!TextUtils.isEmpty(procssManageBean.getDescription())) {
                                buildProcessManageBean.setDescription(procssManageBean.getDescription());
                            }
                            if (!TextUtils.isEmpty(procssManageBean.getWorkOrderId())) {
                                buildProcessManageBean.setWorkOrderId(procssManageBean.getWorkOrderId());
                            }
                            if (!TextUtils.isEmpty(procssManageBean.getManageDate())) {
                                buildProcessManageBean.setManageDate(procssManageBean.getManageDate());
                            }
                            if (procssManageBean.getX() != 0.0) {
                                buildProcessManageBean.setX(procssManageBean.getX());
                            }
                            if (procssManageBean.getY() != 0.0) {
                                buildProcessManageBean.setY(procssManageBean.getY());
                            }
                            dbDaoHelper.insertOrUpdateProcessManage(buildProcessManageBean);
                            if (procssManageBean.getProcessVoice() != null && procssManageBean.getProcessVoice().size() > 0) {
                                for (VoiceBeans voiceBeans : procssManageBean.getProcessVoice()) {
                                    BuildManageFileBean buildManageFileBean1 = new BuildManageFileBean();
                                    if (!TextUtils.isEmpty(procssManageBean.getId())) {
                                        buildManageFileBean1.setProcessId(procssManageBean.getId());
                                    }
                                    if (!TextUtils.isEmpty(data.getId())) {
                                        buildManageFileBean1.setBuildId(data.getId());
                                    }
                                    if (!TextUtils.isEmpty((voiceBeans.getPath()))) {
                                        buildManageFileBean1.setProcessVoicePath(voiceBeans.getPath());
                                    }
                                    if (!TextUtils.isEmpty(voiceBeans.getFileName())) {
                                        buildManageFileBean1.setProcessVoiceName(voiceBeans.getFileName());
                                    }
                                    dbDaoHelper.insertOrUpdateBuildManageFile(buildManageFileBean1);
                                }
                            }
                            if (procssManageBean.getProcessFiles() != null && procssManageBean.getProcessFiles().size() > 0) {
                                for (VoiceBeans voiceBeans : procssManageBean.getProcessFiles()) {
                                    BuildManageFileBean buildManageFileBean2 = new BuildManageFileBean();
                                    if (!TextUtils.isEmpty(procssManageBean.getId())) {
                                        buildManageFileBean2.setProcessId(procssManageBean.getId());
                                    }
                                    if (!TextUtils.isEmpty(data.getId())) {
                                        buildManageFileBean2.setBuildId(data.getId());
                                    }
                                    if (!TextUtils.isEmpty((voiceBeans.getPath()))) {
                                        buildManageFileBean2.setProcessFilePath(voiceBeans.getPath());
                                    }
                                    if (!TextUtils.isEmpty(voiceBeans.getFileName())) {
                                        buildManageFileBean2.setProcessFileName(voiceBeans.getFileName());
                                    }
                                    dbDaoHelper.insertOrUpdateBuildManageFile(buildManageFileBean2);
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    @Override
    public void getBuildProjectTypeList(final String token, final int pageindex, final int pagesize, final BuildManageCallback buildManageCallback) {
        //Http post请求,获取隐患列表
        String url = NetRequestURL.getBuildProjectTypeListUrl();
        StringRequest postRequest = new StringRequest(Request.Method.POST,
                url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                URLResponseCode.URLResponse responseCode = new URLResponseCode.URLResponse(response);
                if (responseCode.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                    String rowsArray = responseCode.queryResult("rows");
                    List<BuildProjectTypeBean> buildProjectTypeList = null;
                    int resCode = -1;
                    boolean result = false;
                    String parseErrMsg = "用户解析失败";
                    int total = 0;
                    String strTotal = responseCode.queryResult("total");
                    if (strTotal != null && !strTotal.isEmpty()) {
                        total = Integer.parseInt(strTotal);
                    }
                    if (rowsArray != null) {
                        try {
                            Gson gson = new Gson();
                            List<BuildProjectTypeBean> buildProjectTypes = gson.fromJson(rowsArray, new TypeToken<List<BuildProjectTypeBean>>() {
                            }.getType());
                            if (buildProjectTypes != null && buildProjectTypes.size() >= 0) {
                                buildProjectTypeList = buildProjectTypes;
                                resCode = responseCode.getCode();
                                parseErrMsg = responseCode.getMessage();
                                result = true;
                                saveBuildProjectTypes(buildProjectTypes);
                            }
                        } catch (Exception e) {
                            buildManageCallback.onGetBuildProjectTypeList(false, resCode, parseErrMsg, null, 0);
                        }
                    }
                    buildManageCallback.onGetBuildProjectTypeList(result, resCode, parseErrMsg, buildProjectTypeList, total);
                } else {
                    buildManageCallback.onGetBuildProjectTypeList(
                            false, responseCode.getCode(), responseCode.getMessage(), null, 0);
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                //登录失败
                if (error.networkResponse != null) {
                    try {
                        String errString = new String(error.networkResponse.data, "UTF-8");
                        buildManageCallback.onGetBuildProjectTypeList(
                                false, error.networkResponse.statusCode, errString, null, 0);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        buildManageCallback.onGetBuildProjectTypeList(
                                false, error.networkResponse.statusCode, null, null, 0);
                    }
                } else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    buildManageCallback.onGetBuildProjectTypeList(
                            false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null, 0);
                }
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<String, String>();
                params.put("pageindex", pageindex + "");
                params.put("pagesize", pagesize + "");
                return params;
            }

            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<String, String>();
                params.put("token", token);
                return params;
            }
        };
        BaseApp.addRequest(mContext.getClass().getName(), postRequest);
    }

    private void saveBuildProjectTypes(List<BuildProjectTypeBean> buildTypes) {
        if (buildTypes != null && buildTypes.size() > 0) {
            dbDaoHelper.deleteAllBuildProjectTypes();
            dbDaoHelper.saveBuildProjectTypes(buildTypes);
        }
    }

    @Override
    public void getManagerList(final BuildManageCallback buildManageCallback) {
        //Http post请求,获取隐患列表
        String url = NetRequestURL.getSysMsgUserList();
        StringRequest postRequest = new StringRequest(Request.Method.GET,
                url, response -> {
            URLResponseCode.URLResponse responseCode = new URLResponseCode.URLResponse(response);
            if (responseCode.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                String rowsArray = responseCode.getResult();
                List<BuildManagerBean> buildManagerBeanList = null;
                int resCode = -1;
                boolean result = false;
                String parseErrMsg = "用户解析失败";
                if (rowsArray != null) {
                    try {
                        Gson gson = new Gson();
                        List<BuildManagerBean> buildManagerBeans = gson.fromJson(rowsArray, new TypeToken<List<BuildManagerBean>>() {
                        }.getType());
                        if (buildManagerBeans != null && buildManagerBeans.size() >= 0) {
                            buildManagerBeanList = buildManagerBeans;
                            resCode = responseCode.getCode();
                            parseErrMsg = responseCode.getMessage();
                            result = true;
                            saveUserList(buildManagerBeans);
                        }
                    } catch (Exception e) {
                        buildManageCallback.onGetManagerList(false, resCode, parseErrMsg, null);
                    }
                }
                buildManageCallback.onGetManagerList(result, resCode, parseErrMsg, buildManagerBeanList);
            } else {
                buildManageCallback.onGetManagerList(
                        false, responseCode.getCode(), responseCode.getMessage(), null);
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    buildManageCallback.onGetManagerList(
                            false, error.networkResponse.statusCode, errString, null);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    buildManageCallback.onGetManagerList(
                            false, error.networkResponse.statusCode, null, null);
                }
            } else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                buildManageCallback.onGetManagerList(
                        false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null);
            }
        }) {

            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = NetRequestURL.newApi_dyrq.getHeaderParams();
                return params;
            }
        };
        BaseApp.addRequest(mContext.getClass().getName(), postRequest);
    }

    @Override
    public void getBuildTye(BuildManageCallback buildManageCallback) {
        String url = NetRequestURL.getBuildTypeListUrl();
        StringRequest postRequest = new StringRequest(Request.Method.GET,
                url, response -> {
            URLResponseCode.URLResponse responseCode = new URLResponseCode.URLResponse(response);
            if (responseCode.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                String rowsArray = responseCode.queryResult("records");
                List<BuildTypeBean> buildTypeBeans = null;
                int resCode = -1;
                boolean result = false;
                String parseErrMsg = "用户解析失败";
                if (rowsArray != null) {
                    try {
                        Gson gson = new Gson();
                        List<BuildTypeBean> beans = gson.fromJson(rowsArray, new TypeToken<List<BuildTypeBean>>() {
                        }.getType());
                        if (beans != null && beans.size() >= 0) {
                            buildTypeBeans = beans;
                            resCode = responseCode.getCode();
                            parseErrMsg = responseCode.getMessage();
                            result = true;
                            saveBuildTypeList(buildTypeBeans);
                        }
                    } catch (Exception e) {
                        buildManageCallback.onGetBuildTypeList(false, resCode, parseErrMsg, null);
                    }
                }
                buildManageCallback.onGetBuildTypeList(result, resCode, parseErrMsg, buildTypeBeans);
            } else {
                buildManageCallback.onGetBuildTypeList(
                        false, responseCode.getCode(), responseCode.getMessage(), null);
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    buildManageCallback.onGetBuildTypeList(
                            false, error.networkResponse.statusCode, errString, null);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    buildManageCallback.onGetBuildTypeList(
                            false, error.networkResponse.statusCode, null, null);
                }
            } else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                buildManageCallback.onGetBuildTypeList(
                        false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null);
            }
        }) {


            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = NetRequestURL.newApi_dyrq.getHeaderParams();
                return params;
            }
        };
        BaseApp.addRequest(mContext.getClass().getName(), postRequest);
    }

    private void saveBuildTypeList(List<BuildTypeBean> buildTypeBeans) {
        dbDaoHelper.deleteDepartAndUser();
        if (buildTypeBeans != null && buildTypeBeans.size() > 0) {
            for (BuildTypeBean buildTypeBean : buildTypeBeans) {
                if (buildTypeBean != null) {
                    dbDaoHelper.upBuildType(buildTypeBean);
                }
            }
        }
    }

    private void saveUserList(List<BuildManagerBean> buildManagerBeans) {
        dbDaoHelper.deleteDepartmentAndUser();
        if (buildManagerBeans != null && buildManagerBeans.size() > 0) {
            for (BuildManagerBean buildManagerBean : buildManagerBeans) {
                DepartmentBean departmentBean = new DepartmentBean();
                if (!TextUtils.isEmpty(buildManagerBean.getId())) {
                    departmentBean.setId(buildManagerBean.getId());
                }
                if (!TextUtils.isEmpty(buildManagerBean.getName())) {
                    departmentBean.setName(buildManagerBean.getName());
                }
                dbDaoHelper.insertOrUpdateDepartmentBean(departmentBean);
                if (buildManagerBean.getUsers() != null && buildManagerBean.getUsers().size() > 0) {
                    for (MessageUserBean messageUserBean : buildManagerBean.getUsers()) {
                        UserListBean userListBean = new UserListBean();
                        if (!TextUtils.isEmpty(buildManagerBean.getId())) {
                            userListBean.setDepartmentId(buildManagerBean.getId());
                        }
                        if (messageUserBean.getId() != 0) {
                            userListBean.setId("" + messageUserBean.getId());
                        }
                        if (!TextUtils.isEmpty(messageUserBean.getRealName())) {
                            userListBean.setRealName(messageUserBean.getRealName());
                        }
                        dbDaoHelper.insertOrUpdateUserListBean(userListBean);
                    }
                }
            }
        }
    }

    @Override
    public void getBuildReportList(final String token, final String buildid, final int pageindex, final int pagesize, final BuildManageCallback buildManageCallback) {
        //Http post请求
        String url = NetRequestURL.getBuildReportListUrl();
        StringRequest postRequest = new StringRequest(Request.Method.POST,
                url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                URLResponseCode.URLResponse responseCode = new URLResponseCode.URLResponse(response);
                if (responseCode.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                    String rowsArray = responseCode.queryResult("rows");
                    List<BuildReportBean> buildReportList = null;
                    int resCode = -1;
                    boolean result = false;
                    String parseErrMsg = "用户解析失败";
                    int total = 0;
                    String strTotal = responseCode.queryResult("total");
                    if (strTotal != null && !strTotal.isEmpty()) {
                        total = Integer.parseInt(strTotal);
                    }
                    if (rowsArray != null) {
                        try {
                            Gson gson = new Gson();
                            List<BuildReportBean> buildReports = gson.fromJson(rowsArray, new TypeToken<List<BuildReportBean>>() {
                            }.getType());
                            if (buildReports != null && buildReports.size() >= 0) {
                                buildReportList = buildReports;
                                resCode = responseCode.getCode();
                                parseErrMsg = responseCode.getMessage();
                                result = true;
                                saveBuildReports(buildReports);
                            }
                        } catch (Exception e) {
                            buildManageCallback.onGetBuildReportList(false, resCode, parseErrMsg, null, 0);
                        }
                    }
                    buildManageCallback.onGetBuildReportList(result, resCode, parseErrMsg, buildReportList, total);
                } else {
                    buildManageCallback.onGetBuildReportList(
                            false, responseCode.getCode(), responseCode.getMessage(), null, 0);
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                //登录失败
                if (error.networkResponse != null) {
                    try {
                        String errString = new String(error.networkResponse.data, "UTF-8");
                        buildManageCallback.onGetBuildReportList(
                                false, error.networkResponse.statusCode, errString, null, 0);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        buildManageCallback.onGetBuildReportList(
                                false, error.networkResponse.statusCode, null, null, 0);
                    }
                } else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    buildManageCallback.onGetBuildReportList(
                            false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null, 0);
                }
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<String, String>();
                params.put("build_id", buildid);
                params.put("pageindex", pageindex + "");
                params.put("pagesize", pagesize + "");
                return params;
            }

            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<String, String>();
                params.put("token", token);
                return params;
            }
        };
        BaseApp.addRequest(mContext.getClass().getName(), postRequest);
    }

    private void saveBuildReports(List<BuildReportBean> buildReports) {
        if (buildReports != null && buildReports.size() > 0) {
            for (BuildReportBean reportBean : buildReports) {
                reportBean.setSave_state(TroubleBean.SERVER_STATE);
                dbDaoHelper.insertOrUpdateBuildReport(reportBean);
            }
        }
    }

    @Override
    public void uploadBuildReport(final String token, final String userid, final BuildReportBean reportBean, final List<TroublePictureBean> photos, final List<TroubleAudioBean> audios, final BuildManageCallback buildManageCallback) {
        String url = NetRequestURL.getAddBuildReportUrl();
        MultiPartStringRequest postRequest = new MultiPartStringRequest(Request.Method.POST,
                url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                URLResponseCode.URLResponse responseCode = new URLResponseCode.URLResponse(response);
                if (responseCode.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                    buildManageCallback.onUploadBuildReport(true, responseCode.getCode(), responseCode.getMessage());
                } else {
                    buildManageCallback.onUploadBuildReport(false, responseCode.getCode(), responseCode.getMessage());
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                //登录失败
                if (error.networkResponse != null) {
                    try {
                        String errString = new String(error.networkResponse.data, "UTF-8");
                        buildManageCallback.onUploadBuildReport(false, error.networkResponse.statusCode, errString);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        buildManageCallback.onUploadBuildReport(false, error.networkResponse.statusCode, null);
                    }
                } else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    buildManageCallback.onUploadBuildReport(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString);
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<String, String>();
                params.put("token", token);
                params.put("userid", userid);
                return params;
            }

            @Override
            public Map<String, String> getStringUploads() {
                Map<String, String> params = new HashMap<>();
                params.put("build_id", reportBean.getBuild_id());
                params.put("address", reportBean.getAddress());
                params.put("lng", reportBean.getLng());
                params.put("lat", reportBean.getLat());
                params.put("is_safemark", reportBean.getIs_safemark() + "");
                params.put("is_safedistance", reportBean.getIs_safedistance() + "");
                params.put("is_notification", reportBean.getIs_notification() + "");
                params.put("is_pipeline", reportBean.getIs_pipeline() + "");
                params.put("is_leak", reportBean.getIs_leak() + "");
                params.put("build_state", reportBean.getReport_state() + "");
                params.put("flag", reportBean.getGps_flag() + "");
                String notes = reportBean.getNotes();
                if (notes != null && !notes.isEmpty()) {
                    params.put("notes", notes);
                }
                return params;
            }

            @Override
            public Map<String, File> getFileUploads() {
                Map<String, File> params = new HashMap<>();
                int count = 1;
                if (photos != null && photos.size() > 0) {
                    for (int i = 0; i < photos.size(); i++, count++) {
                        TroublePictureBean pictureBean = photos.get(i);
                        String file = pictureBean.getFilepath();
                        String time = pictureBean.getCreateTime();
                        String key = "file" + count + "," + 0 + "," + time;
                        if (file != null && !file.isEmpty())
                            params.put(key, new File(file));
                    }
                }
                if (audios != null && audios.size() > 0) {
                    for (int i = 0; i < audios.size(); i++, count++) {
                        TroubleAudioBean audioBean = audios.get(i);
                        String file = audioBean.getPath();
                        int second = audioBean.getSecond();
                        String time = audioBean.getCreateTime();
                        String key = "file" + count + "," + second + "," + time;
                        if (file != null && !file.isEmpty()) {
                            params.put(key, new File(file));
                        }
                    }
                }
                return params;
            }
        };

        BaseApp.addMultiStatckRequest(mContext.getClass().getName(), postRequest);
    }

    @Override
    public void removeBuildReport(final String token, String reportid, final BuildManageCallback buildManageCallback) {
        String url = NetRequestURL.getDeleteBuildReportUrl() + reportid;
        StringRequest postRequest = new StringRequest(Request.Method.POST,
                url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                URLResponseCode.URLResponse urlResponse = new URLResponseCode.URLResponse(response);
                if (urlResponse.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                    buildManageCallback.onRemoveBuildReport(true, urlResponse.getCode(), urlResponse.getMessage());
                } else {
                    buildManageCallback.onRemoveBuildReport(
                            false, urlResponse.getCode(), urlResponse.getMessage());
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                //登录失败
                if (error.networkResponse != null) {
                    try {
                        String errString = new String(error.networkResponse.data, "UTF-8");
                        buildManageCallback.onRemoveBuildReport(false, error.networkResponse.statusCode, errString);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        buildManageCallback.onRemoveBuildReport(false, error.networkResponse.statusCode, null);
                    }
                } else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    buildManageCallback.onRemoveBuildReport(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString);
                }
            }
        }) {

            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<String, String>();
                params.put("token", token);
                return params;
            }
        };
        BaseApp.addRequest(mContext.getClass().getName(), postRequest);
    }

    @Override
    public void getBuildHandleList(final String token, final String buildid, final int pageindex, final int pagesize, final BuildManageCallback buildManageCallback) {
        //Http post请求
        String url = NetRequestURL.getBuildHandleListUrl();
        StringRequest postRequest = new StringRequest(Request.Method.POST,
                url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                URLResponseCode.URLResponse responseCode = new URLResponseCode.URLResponse(response);
                if (responseCode.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                    String rowsArray = responseCode.queryResult("rows");
                    List<BuildHandleBean> buildHandleList = null;
                    int resCode = -1;
                    boolean result = false;
                    String parseErrMsg = "用户解析失败";
                    int total = 0;
                    String strTotal = responseCode.queryResult("total");
                    if (strTotal != null && !strTotal.isEmpty()) {
                        total = Integer.parseInt(strTotal);
                    }
                    if (rowsArray != null) {
                        try {
                            Gson gson = new Gson();
                            List<BuildHandleBean> buildHandles = gson.fromJson(rowsArray, new TypeToken<List<BuildHandleBean>>() {
                            }.getType());
                            if (buildHandles != null && buildHandles.size() >= 0) {
                                buildHandleList = buildHandles;
                                resCode = responseCode.getCode();
                                parseErrMsg = responseCode.getMessage();
                                result = true;
                            }
                        } catch (Exception e) {
                            buildManageCallback.onGetBuildHandleList(false, resCode, parseErrMsg, null, 0);
                        }
                    }
                    buildManageCallback.onGetBuildHandleList(result, resCode, parseErrMsg, buildHandleList, total);
                } else {
                    buildManageCallback.onGetBuildHandleList(
                            false, responseCode.getCode(), responseCode.getMessage(), null, 0);
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                //登录失败
                if (error.networkResponse != null) {
                    try {
                        String errString = new String(error.networkResponse.data, "UTF-8");
                        buildManageCallback.onGetBuildHandleList(
                                false, error.networkResponse.statusCode, errString, null, 0);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        buildManageCallback.onGetBuildHandleList(
                                false, error.networkResponse.statusCode, null, null, 0);
                    }
                } else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    buildManageCallback.onGetBuildHandleList(
                            false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null, 0);
                }
            }
        }) {
            @Override
            protected Map<String, String> getParams() {
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<String, String>();
                params.put("build_id", buildid);
                params.put("pageindex", pageindex + "");
                params.put("pagesize", pagesize + "");
                return params;
            }

            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<String, String>();
                params.put("token", token);
                return params;
            }
        };
        BaseApp.addRequest(mContext.getClass().getName(), postRequest);
    }

    @Override
    public void uploadBuildHandle(final String token, final BuildHandleBean handleBean, final BuildManageCallback buildManageCallback) {
        String url = NetRequestURL.getAddBuildHandleUrl();
        MultiPartStringRequest postRequest = new MultiPartStringRequest(Request.Method.POST,
                url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                URLResponseCode.URLResponse responseCode = new URLResponseCode.URLResponse(response);
                if (responseCode.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                    buildManageCallback.onUploadBuildHandle(true, responseCode.getCode(), responseCode.getMessage());
                } else {
                    buildManageCallback.onUploadBuildHandle(false, responseCode.getCode(), responseCode.getMessage());
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                //登录失败
                if (error.networkResponse != null) {
                    try {
                        String errString = new String(error.networkResponse.data, "UTF-8");
                        buildManageCallback.onUploadBuildHandle(false, error.networkResponse.statusCode, errString);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        buildManageCallback.onUploadBuildHandle(false, error.networkResponse.statusCode, null);
                    }
                } else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    buildManageCallback.onUploadBuildHandle(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString);
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<String, String>();
                params.put("token", token);
                return params;
            }

            @Override
            public Map<String, String> getStringUploads() {
                Map<String, String> params = new HashMap<>();
                params.put("build_id", handleBean.getBuild_id());
                params.put("project_state", handleBean.getProject_state() + "");
                String notes = handleBean.getHandle_note();
                if (notes != null && !notes.isEmpty()) {
                    params.put("handle_note", notes);
                }
                return params;
            }

            @Override
            public Map<String, File> getFileUploads() {
                Map<String, File> params = new HashMap<>();
                String strFiles = handleBean.getFile();
                if (strFiles != null && !strFiles.isEmpty()) {
                    String[] files = strFiles.split(",");
                    if (files != null && files.length > 0) {
                        for (int i = 0; i < files.length; i++) {
                            String key = "file" + i;
                            String value = files[i];
                            params.put(key, new File(value));
                        }
                    }
                }
                return params;
            }
        };

        BaseApp.addMultiStatckRequest(mContext.getClass().getName(), postRequest);
    }

    @Override
    public void removeBuildHandle(final String token, String handleid, final BuildManageCallback buildManageCallback) {
        String url = NetRequestURL.getDeleteBuildHandleUrl() + handleid;
        StringRequest postRequest = new StringRequest(Request.Method.POST,
                url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                URLResponseCode.URLResponse urlResponse = new URLResponseCode.URLResponse(response);
                if (urlResponse.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                    buildManageCallback.onRemoveBuildHandle(true, urlResponse.getCode(), urlResponse.getMessage());
                } else {
                    buildManageCallback.onRemoveBuildHandle(
                            false, urlResponse.getCode(), urlResponse.getMessage());
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                //登录失败
                if (error.networkResponse != null) {
                    try {
                        String errString = new String(error.networkResponse.data, "UTF-8");
                        buildManageCallback.onRemoveBuildHandle(false, error.networkResponse.statusCode, errString);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        buildManageCallback.onRemoveBuildHandle(false, error.networkResponse.statusCode, null);
                    }
                } else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    buildManageCallback.onRemoveBuildHandle(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString);
                }
            }
        }) {

            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<String, String>();
                params.put("token", token);
                return params;
            }
        };
        BaseApp.addRequest(mContext.getClass().getName(), postRequest);
    }

    @Override
    public void addBuildManage(final String token, final BuildManageBean buildManage, final List<TroublePictureBean> photos, final List<TroubleAudioBean> audios, final List<BuildFileBean> fileBeanList, final BuildManageCallback buildManageCallback) {
        String url = NetRequestURL.getAddBuildManage1Url();
        MultiPartStringRequest postRequest = new MultiPartStringRequest(Request.Method.POST,
                url, response -> {
            URLResponseCode.URLResponse urlResponse = new URLResponseCode.URLResponse(response);
            if (urlResponse.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                buildManageCallback.onAddBuildManage(true, urlResponse.getCode(), urlResponse.getMessage());
            } else {
                buildManageCallback.onAddBuildManage(false, urlResponse.getCode(), urlResponse.getMessage());
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    buildManageCallback.onAddBuildManage(false, error.networkResponse.statusCode, errString);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    buildManageCallback.onAddBuildManage(false, error.networkResponse.statusCode, null);
                }
            } else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                buildManageCallback.onAddBuildManage(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString);
            }
        }) {
            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = NetRequestURL.newApi_dyrq.getHeaderParams();
                return params;
            }

            @Override
            public Map<String, String> getStringUploads() {
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<>();
                /*工地监护名称[必填]*/
                String buildName = buildManage.getSiteName();
                if (buildName != null && !buildName.isEmpty())
                    params.put("siteName", buildName);
                /*工地监护地址[必填]*/
                if (!TextUtils.isEmpty(buildManage.getConstructionAddress())) {
                    params.put("constructionAddress", buildManage.getConstructionAddress());
                }
                /* 经度[必填]*/
                String lng = "";
                if (buildManage.getX() > 0.0) {
                    lng = String.valueOf(buildManage.getX());
                }
                params.put("x", lng);
                /*纬度[必填]*/
                String lat = "";
                if (buildManage.getY() > 0.0) {
                    lat = String.valueOf(buildManage.getY());
                }
                params.put("y", lat);
                /*工程建设类别[必填]*/
                params.put("siteType", buildManage.getSiteType());
                /*施工单位名称[选填]*/
                String buildCompany = buildManage.getConstructionUnit();
                if (buildCompany != null && !buildCompany.isEmpty()) {
                    params.put("constructionUnit", buildCompany);
                }
                /*施工监护人姓名[选填]*/
                String sceneCharegeName = buildManage.getDispatchUserId();
                if (sceneCharegeName != null && !sceneCharegeName.isEmpty()) {
                    params.put("dispatchUserId", sceneCharegeName);
                }
                /*施工负责人[选填]*/
                String charege = buildManage.getPersonInCharge();
                if (charege != null && !charege.isEmpty()) {
                    params.put("personInCharge", charege);
                }
                /*施工负责人电话[选填]*/
                String charegePhone = buildManage.getPersonInChargePhone();
                if (charegePhone != null && !charegePhone.isEmpty()) {
                    params.put("personInChargePhone", charegePhone);
                }
                /*主管人姓名[选填]*/
                String charegeUsername = buildManage.getManager();
                if (charegeUsername != null && !charegeUsername.isEmpty()) {
                    params.put("manager", charegeUsername);
                }
                /*主管单位名字[选填]*/
                String chargeCompany = buildManage.getManageUnit();
                if (chargeCompany != null && !chargeCompany.isEmpty()) {
                    params.put("manageUnit", chargeCompany);
                }
                if (!TextUtils.isEmpty(buildManage.getDescription())) {
                    params.put("description", buildManage.getDescription());
                }
                if (!TextUtils.isEmpty(buildManage.getDepartment())) {
                    params.put("department", buildManage.getDepartment());
                }
                return params;
            }

            @Override
            public Map<String, File> getFileUploads() {
                Map<String, File> params = new HashMap<>();
                if (photos != null && photos.size() > 0) {
                    for (int i = 0; i < photos.size(); i++) {
                        TroublePictureBean pictureBean = photos.get(i);
                        String file = pictureBean.getFilepath();
                        String time = pictureBean.getCreateTime();
                        long second = pictureBean.getSecond() / 1000;
                        int count = i + 1;
                        String key = "photo" + count + "," + second + "," + time;
                        //String key = "photo" + count;
                        if (file != null && !file.isEmpty())
                            params.put(key, new File(file));
                    }
                }
                if (audios != null && audios.size() > 0) {
                    for (int i = 0; i < audios.size(); i++) {
                        TroubleAudioBean audioBean = audios.get(i);
                        String file = audioBean.getPath();
//                        int second = audioBean.getSecond();
                        int count = i + 1;
                        //                   String time = audioBean.getCreateTime();
                        String key = "audio" + count;
                        if (file != null && !file.isEmpty()) {
                            params.put(key, new File(file));
                        }
                    }
                }
                if (fileBeanList != null && fileBeanList.size() > 0) {
                    for (int i = 0; i < fileBeanList.size(); i++) {
                        BuildFileBean buildFileBean = fileBeanList.get(i);
                        String file = buildFileBean.getFilePath();
                        int count = i + 1;
                        String key = "other" + count;
                        if (file != null && !file.isEmpty()) {
                            params.put(key, new File(file));
                        }
                    }
                }
                return params;
            }
        };
        BaseApp.addMultiStatckRequest(mContext.getClass().getName(), postRequest);
    }

    @Override
    public void addBuildProcessManage(final BuildProcessManageBean buildManage, final List<TroublePictureBean> photos, final List<TroubleAudioBean> audios,
                                      final List<BuildFileBean> fileBeanList, final BuildManageCallback buildManageCallback) {
        String url = NetRequestURL.getAddBuildProcessManageUrl();
        MultiPartStringRequest postRequest = new MultiPartStringRequest(Request.Method.POST,
                url, response -> {
            URLResponseCode.URLResponse urlResponse = new URLResponseCode.URLResponse(response);
            if (urlResponse.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                buildManageCallback.onAddBuildManage(true, urlResponse.getCode(), urlResponse.getMessage());
            } else {
                buildManageCallback.onAddBuildManage(false, urlResponse.getCode(), urlResponse.getMessage());
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    buildManageCallback.onAddBuildManage(false, error.networkResponse.statusCode, errString);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    buildManageCallback.onAddBuildManage(false, error.networkResponse.statusCode, null);
                }
            } else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                buildManageCallback.onAddBuildManage(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString);
            }
        }) {
            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = NetRequestURL.newApi_dyrq.getHeaderParams();
                return params;
            }

            @Override
            public Map<String, String> getStringUploads() {
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<>();
                if (!TextUtils.isEmpty(buildManage.getDescription()))
                    params.put("description", buildManage.getDescription());
                /*工地监护地址[必填]*/
                if (!TextUtils.isEmpty(buildManage.getWorkOrderId())) {
                    params.put("workOrderId", buildManage.getWorkOrderId());
                }
                /* 经度[必填]*/
                String lng = "";
                if (buildManage.getX() > 0.0) {
                    lng = String.valueOf(buildManage.getX());
                }
                params.put("x", lng);
                /*纬度[必填]*/
                String lat = "";
                if (buildManage.getY() > 0.0) {
                    lat = String.valueOf(buildManage.getY());
                }
                params.put("y", lat);
                return params;
            }

            @Override
            public Map<String, File> getFileUploads() {
                Map<String, File> params = new HashMap<>();
                if (photos != null && photos.size() > 0) {
                    for (int i = 0; i < photos.size(); i++) {
                        TroublePictureBean pictureBean = photos.get(i);
                        String file = pictureBean.getFilepath();
                        String time = pictureBean.getCreateTime();
                        long second = pictureBean.getSecond() / 1000;
                        int count = i + 1;
                        String key = "photo" + count + "," + second + "," + time;
                        //String key = "photo" + count;
                        if (file != null && !file.isEmpty())
                            params.put(key, new File(file));
                    }
                }
                if (audios != null && audios.size() > 0) {
                    for (int i = 0; i < audios.size(); i++) {
                        TroubleAudioBean audioBean = audios.get(i);
                        String file = audioBean.getPath();
//                        int second = audioBean.getSecond();
                        int count = i + 1;
                        //                   String time = audioBean.getCreateTime();
                        String key = "audio" + count;
                        if (file != null && !file.isEmpty()) {
                            params.put(key, new File(file));
                        }
                    }
                }
                if (fileBeanList != null && fileBeanList.size() > 0) {
                    for (int i = 0; i < fileBeanList.size(); i++) {
                        BuildFileBean buildFileBean = fileBeanList.get(i);
                        String file = buildFileBean.getFilePath();
                        int count = i + 1;
                        String key = "other" + count;
                        if (file != null && !file.isEmpty()) {
                            params.put(key, new File(file));
                        }
                    }
                }
                return params;
            }
        };
        BaseApp.addMultiStatckRequest(mContext.getClass().getName(), postRequest);
    }

    @Override
    public void updateBuildLog(BuildManageBean buildManageBean, final BuildManageCallback buildManageCallback) {
        String url = NetRequestURL.getUpdateBuildLogUrl();
        StringRequest postRequest = new StringRequest(Request.Method.POST,
                url, response -> {
            URLResponseCode.URLResponse urlResponse = new URLResponseCode.URLResponse(response);
            if (urlResponse.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                buildManageCallback.onUpdateBuildLog(true, urlResponse.getCode(), urlResponse.getMessage());
            } else {
                buildManageCallback.onUpdateBuildLog(false, urlResponse.getCode(), urlResponse.getMessage());
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    buildManageCallback.onUpdateBuildLog(false, error.networkResponse.statusCode, errString);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    buildManageCallback.onUpdateBuildLog(false, error.networkResponse.statusCode, null);
                }
            } else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                buildManageCallback.onUpdateBuildLog(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString);
            }
        }) {
            @Override
            public Map<String, String> getParams() {
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<>();
                params.put("id", buildManageBean.getId());
                params.put("constructionState", "3");
                return params;
            }

            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = NetRequestURL.newApi_dyrq.getHeaderParams();
                return params;
            }
        };
        BaseApp.addRequest(mContext.getClass().getName(), postRequest);
    }

    @Override
    public void getBuildLogList(final String token, final BuildManageCallback buildManageCallback) {
        //Http post请求
        String url = NetRequestURL.getBuildLogListUrl();
        StringRequest postRequest = new StringRequest(Request.Method.POST,
                url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                URLResponseCode.URLResponse responseCode = new URLResponseCode.URLResponse(response);
                if (responseCode.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                    String rowsArray = responseCode.getResult();
                    List<BuildHandleDataBean> buildLogList = null;
                    int resCode = -1;
                    boolean result = false;
                    String parseErrMsg = "用户解析失败";
                    if (rowsArray != null) {
                        try {
                            Gson gson = new Gson();
                            List<BuildHandleDataBean> buildLogs = gson.fromJson(rowsArray, new TypeToken<List<BuildHandleDataBean>>() {
                            }.getType());
                            if (buildLogs != null && buildLogs.size() >= 0) {
                                buildLogList = buildLogs;
                                resCode = responseCode.getCode();
                                parseErrMsg = responseCode.getMessage();
                                result = true;
                                saveBuildHandles(buildLogs);
                            }
                        } catch (Exception e) {
                            buildManageCallback.onGetBuildLogList(false, resCode, parseErrMsg, null);
                        }
                    }
                    buildManageCallback.onGetBuildLogList(result, resCode, parseErrMsg, buildLogList);
                } else {
                    buildManageCallback.onGetBuildLogList(false, responseCode.getCode(), responseCode.getMessage(), null);
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                //登录失败
                if (error.networkResponse != null) {
                    try {
                        String errString = new String(error.networkResponse.data, "UTF-8");
                        buildManageCallback.onGetBuildLogList(false, error.networkResponse.statusCode, errString, null);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        buildManageCallback.onGetBuildLogList(false, error.networkResponse.statusCode, null, null);
                    }
                } else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    buildManageCallback.onGetBuildLogList(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null);
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<String, String>();
                params.put("token", token);
                return params;
            }
        };
        BaseApp.addRequest(mContext.getClass().getName(), postRequest);
    }

    @Override
    public void getBuildDispatch(BuildManageBeans buildManageBean, BuildManageCallback buildManageCallback) {
        String url = NetRequestURL.getUpdateBuildLogUrl();
        StringRequest postRequest = new StringRequest(Request.Method.POST,
                url, response -> {
            URLResponseCode.URLResponse urlResponse = new URLResponseCode.URLResponse(response);
            if (urlResponse.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                buildManageCallback.onUpdateBuildLog(true, urlResponse.getCode(), urlResponse.getMessage());
            } else {
                buildManageCallback.onUpdateBuildLog(false, urlResponse.getCode(), urlResponse.getMessage());
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    buildManageCallback.onUpdateBuildLog(false, error.networkResponse.statusCode, errString);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    buildManageCallback.onUpdateBuildLog(false, error.networkResponse.statusCode, null);
                }
            } else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                buildManageCallback.onUpdateBuildLog(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString);
            }
        }) {
            @Override
            public Map<String, String> getParams() {
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<>();
                params.put("id", buildManageBean.getId());
                params.put("constructionPerson", buildManageBean.getConstructionPerson());
                params.put("dispatchDate", buildManageBean.getDispatchDate());
                params.put("note", buildManageBean.getNote());
                params.put("constructionState", "2");
                params.put("department", buildManageBean.getDepartment());
                return params;
            }

            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = NetRequestURL.newApi_dyrq.getHeaderParams();
                return params;
            }
        };
        BaseApp.addRequest(mContext.getClass().getName(), postRequest);
    }

    @Override
    public void getBuildExamine(BuildExaminesBean examinesBean, List<BuildFileBean> data, BuildManageCallback buildManageCallback) {
        String url = NetRequestURL.getExamineBuildUrl();
        MultiPartStringRequest postRequest = new MultiPartStringRequest(Request.Method.POST, url, response -> {
            URLResponseCode.URLResponse urlResponse = new URLResponseCode.URLResponse(response);
            if (urlResponse.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                buildManageCallback.onUpdateBuildLog(true, urlResponse.getCode(), urlResponse.getMessage());
            } else {
                buildManageCallback.onUpdateBuildLog(false, urlResponse.getCode(), urlResponse.getMessage());
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    buildManageCallback.onUpdateBuildLog(false, error.networkResponse.statusCode, errString);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    buildManageCallback.onUpdateBuildLog(false, error.networkResponse.statusCode, null);
                }
            } else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                buildManageCallback.onUpdateBuildLog(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString);
            }
        }) {
            @Override
            public Map<String, String> getHeaders() {
                //参数拼装:表单提交方式
                Map<String, String> params = NetRequestURL.newApi_dyrq.getHeaderParams();
                return params;
            }

            @Override
            public Map<String, String> getStringUploads() {
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<>();
                params.put("workOrderId", examinesBean.getWorkOrderId());
                params.put("auditDescription", examinesBean.getAuditDescription());
                params.put("auditTime", examinesBean.getAuditTime());
                params.put("auditmind", examinesBean.getAuditmind());
                params.put("auditor", examinesBean.getAuditor());
                if (examinesBean.getAuditmind().equals("0")) {
                    params.put("constructionState", "5");
                } else {
                    params.put("constructionState", "4");
                }
                return params;
            }

            @Override
            public Map<String, File> getFileUploads() {
                Map<String, File> params = new HashMap<>();
                if (data != null && data.size() > 0) {
                    for (int i = 0; i < data.size(); i++) {
                        BuildFileBean buildFileBean = data.get(i);
                        String file = buildFileBean.getFilePath();
                        int count = i + 1;
                        String key = "other" + count;
                        if (file != null && !file.isEmpty()) {
                            params.put(key, new File(file));
                        }
                    }
                }
                return params;
            }
        };
        BaseApp.addMultiStatckRequest(mContext.getClass().getName(), postRequest);
    }

    private void saveBuildHandles(List<BuildHandleDataBean> buildHandles) {
        if (buildHandles != null && buildHandles.size() > 0) {
            dbDaoHelper.insertBuildHandleList(buildHandles);
        }
    }


}
