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

import android.content.Context;

import com.alibaba.fastjson.JSONObject;
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.mgq.base.utils.string.StringUtil;
import com.tofly.ghrq_route.base.BaseApp;
import com.tofly.ghrq_route.base.url.NetRequestURL;
import com.tofly.ghrq_route.base.url.NetRequestURL.newApi_dyrq;
import com.tofly.ghrq_route.base.URLResponseCode;
import com.tofly.ghrq_route.module.planPointRepair.controller.PointRepairCallBack;
import com.tofly.ghrq_route.module.planPointRepair.domain.AdjustRepairContent;
import com.tofly.ghrq_route.module.planPointRepair.domain.DeviceRouteData;
import com.tofly.ghrq_route.module.planPointRepair.domain.DeviceRouteParam;
import com.tofly.ghrq_route.module.planPointRepair.domain.MaintainAdjustParam;
import com.tofly.ghrq_route.module.planPointRepair.domain.MaintainCommonParam;
import com.tofly.ghrq_route.module.planPointRepair.domain.NFCInfoBean;
import com.tofly.ghrq_route.module.planPointRepair.domain.PlanPointRepair;
import com.tofly.ghrq_route.module.planPointRepair.domain.RouteDeviceType;
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.uploadFile.domain.FileBean;
import com.tofly.ghrq_route.module.user.domain.UserBean;
import com.tofly.ghrq_route.common.util.date.DateUtils;
import com.tofly.ghrq_route.common.util.file.FileUtil;
import com.tofly.ghrq_route.common.util.file.MimeUtil;
import com.tofly.ghrq_route.common.util.net.volley.MultiPartStringRequest;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;

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

public class PointRepairServiceImpl implements IPointRepairService {
    private Context mContext;
    private DBDaoHelper dbDaoHelper;

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

    @Override
    public void addPointRepair(final String token, final PlanPointRepair pointRepair, final PointRepairCallBack repairCallBack) {
        String url = NetRequestURL.getAddPlanPointRepairUrl();
        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 responseResult = responseCode.getResult();
                    int resCode = -1;
                    boolean result = false;
                    String parseErrMsg = "用户解析失败";
                    PlanPointRepair planPointRepair = null;
                    if (responseResult != null){
                        try {
                            Gson gson = new Gson();
                            PlanPointRepair repair = gson.fromJson(responseResult, PlanPointRepair.class);
                            if (repair != null){
                                planPointRepair = repair;
                                resCode = responseCode.getCode();
                                parseErrMsg = responseCode.getMessage();
                                result = true;
                            }
                        }catch (Exception e){
                            repairCallBack.onAddPointRepair(false, resCode, parseErrMsg, null);
                        }
                    }
                    repairCallBack.onAddPointRepair(true, responseCode.getCode(), responseCode.getMessage(), planPointRepair);
                }else {
                    repairCallBack.onAddPointRepair(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");
                        repairCallBack.onAddPointRepair(
                                false, error.networkResponse.statusCode, errString, null);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        repairCallBack.onAddPointRepair(false, error.networkResponse.statusCode, null, null);
                    }
                }else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    repairCallBack.onAddPointRepair(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null);
                }
            }
        }){
            @Override
            protected Map<String, String> getParams(){
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<String, String>();
                params.put("pointid", pointRepair.getPoint_id());
                params.put("lng", pointRepair.getLng() + "");
                params.put(("lat"), pointRepair.getLat() + "");
                params.put(("address"), pointRepair.getAddress());
                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 getPointRepairList(final String token, final int pageindex, final int pagesize, final PointRepairCallBack repairCallBack) {
        //Http post请求
        String url = NetRequestURL.getPlanPointRepairListUrl();
        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<PlanPointRepair> pointRepairList = 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<PlanPointRepair> repairs = gson.fromJson(rowsArray, new TypeToken<List<PlanPointRepair>>(){}.getType());
                            if (repairs != null && repairs.size() >= 0){
                                pointRepairList = repairs;
                                resCode = responseCode.getCode();
                                parseErrMsg = responseCode.getMessage();
                                result = true;
                            }
                        }catch (Exception e){
                            repairCallBack.onGetPointRepairList(false, resCode, parseErrMsg, null, 0);
                        }
                    }
                    repairCallBack.onGetPointRepairList(result, resCode, parseErrMsg, pointRepairList, total);
                }else {
                    repairCallBack.onGetPointRepairList(
                            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");
                        repairCallBack.onGetPointRepairList(
                                false, error.networkResponse.statusCode, errString, null, 0);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        repairCallBack.onGetPointRepairList(
                                false, error.networkResponse.statusCode, null, null, 0);
                    }
                }else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    repairCallBack.onGetPointRepairList(
                            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);
    }

    @Override
    public void removePointRepair(final String token, final String repairid, boolean ischild, final PointRepairCallBack repairCallBack) {
        String url = NetRequestURL.getDeletePlanPointRepairUrl() + repairid;
        if (ischild){
            url = NetRequestURL.getDeletePlanChildPointRepairUrl() + repairid;
        }
        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){
                    repairCallBack.onRemovePointRepair(true, responseCode.getCode(), responseCode.getMessage());
                }else {
                    repairCallBack.onRemovePointRepair(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");
                        repairCallBack.onRemovePointRepair(
                                false, error.networkResponse.statusCode, errString);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        repairCallBack.onRemovePointRepair(false, error.networkResponse.statusCode, null);
                    }
                }else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    repairCallBack.onRemovePointRepair(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 updatePointRepair(final String token, final PlanPointRepair pointRepair, final PointRepairCallBack repairCallBack) {
        String url = NetRequestURL.getUpdatePlanPointRepairUrl();
        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){
                    repairCallBack.onUpdatePointRepair(true, responseCode.getCode(), responseCode.getMessage());
                }else {
                    repairCallBack.onUpdatePointRepair(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");
                        repairCallBack.onUpdatePointRepair(
                                false, error.networkResponse.statusCode, errString);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        repairCallBack.onUpdatePointRepair(false, error.networkResponse.statusCode, null);
                    }
                }else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    repairCallBack.onUpdatePointRepair(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString);
                }
            }
        }){
            @Override
            protected Map<String, String> getParams(){
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<String, String>();
                params.put("id", pointRepair.getTemp_id());
                String notes = pointRepair.getNotes();
                if (notes != null && !notes.isEmpty()){
                    params.put("notes", notes);
                }
                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 getPointRepairInfo(final String token, final String pointid, final String childplanid, final PointRepairCallBack repairCallBack) {
        String url = NetRequestURL.getPlanPointChildRepairInfoUrl();
        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 responseResult = responseCode.getResult();
                    PlanPointRepair pointRepair = null;
                    int resCode = -1;
                    boolean result = false;
                    String parseErrMsg = "用户解析失败";
                    if (responseResult != null){
                        try {
                            Gson gson = new Gson();
                            PlanPointRepair repair = gson.fromJson(responseResult, PlanPointRepair.class);
                            if (repair != null){
                                pointRepair = repair;
                                resCode = responseCode.getCode();
                                parseErrMsg = responseCode.getMessage();
                                result = true;
                            }
                        }catch (Exception e){
                            repairCallBack.onGetPointRepairInfo(false, resCode, parseErrMsg, null);
                        }
                    }
                    repairCallBack.onGetPointRepairInfo(result, resCode, parseErrMsg, pointRepair);
                }else {
                    repairCallBack.onGetPointRepairInfo(
                            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");
                        repairCallBack.onGetPointRepairInfo(
                                false, error.networkResponse.statusCode, errString, null);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        repairCallBack.onGetPointRepairInfo(
                                false, error.networkResponse.statusCode, null, null);
                    }
                }else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    repairCallBack.onGetPointRepairInfo(
                            false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null);
                }
            }
        }){
            @Override
            protected Map<String, String> getParams(){
                Map<String, String> params = new HashMap<String, String>();
                params.put("child_plan_id", childplanid);
                params.put("point_id", pointid);
                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 addPointChildRepair(final String token, final String child_plan_id, final PlanPointRepair pointRepair, final List<TroublePictureBean> photos, final PointRepairCallBack repairCallBack) {
        String url = NetRequestURL.getAddPlanPointChildRepairUrl();
        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){
                    /*int resCode = -1;
                    boolean result = false;
                    String parseErrMsg = "用户解析失败";
                    String repairid = null;
                    if (responseCode.getResult() != null){
                        try {
                            repairid = responseCode.queryResult("id");
                            resCode = responseCode.getCode();
                            parseErrMsg = responseCode.getMessage();
                            result = true;
                        }catch (Exception e){
                            repairCallBack.onAddPointChildRepair(false, resCode, parseErrMsg, null);
                        }
                    }*/
                    repairCallBack.onAddPointChildRepair(true, responseCode.getCode(), responseCode.getMessage());
                }else {
                    repairCallBack.onAddPointChildRepair(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");
                        repairCallBack.onAddPointChildRepair(false, error.networkResponse.statusCode, errString);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        repairCallBack.onAddPointChildRepair(false, error.networkResponse.statusCode, null);
                    }
                }else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    repairCallBack.onAddPointChildRepair(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString);
                }
            }
        }){
            @Override
            protected Map<String, String> getParams(){
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<String, String>();
                params.put("child_plan_id", child_plan_id);
                params.put("pointid", pointRepair.getPoint_id());
                String lon = Double.toString(pointRepair.getLng());
                params.put("lng", lon);
                String lat = Double.toString(pointRepair.getLat());
                params.put("lat", lat);
                String addr = pointRepair.getAddress();
                if (addr != null && !addr.isEmpty()){
                    params.put("address", addr);
                }
                String notes = pointRepair.getNotes();
                if (notes != null && !notes.isEmpty()){
                    params.put("notes", notes);
                }
                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 addAdjustPressDeviceChildRepair(final Context context, final PlanPointRepair pointRepair,
                                                final List<TroublePictureBean> photos, boolean isUpdate, final PointRepairCallBack repairCallBack) {
        String url = newApi_dyrq.getAdjustDeviceMaintainUrl();
        int post_method = isUpdate ? Request.Method.PUT : Request.Method.POST;
        MultiPartStringRequest postRequest = new MultiPartStringRequest(post_method,
                url, response -> {
                    URLResponseCode.URLResponse responseCode = new URLResponseCode.URLResponse(response);
                    if (responseCode.getCode() == URLResponseCode.ErrorCode.SUCCESS){
                        repairCallBack.onAddPointChildRepair(true, responseCode.getCode(), responseCode.getMessage());
                    }else {
                        repairCallBack.onAddPointChildRepair(false, responseCode.getCode(), responseCode.getMessage());
                    }
                }, error -> {
                    //登录失败
                    if (error.networkResponse != null) {
                        try {
                            String errString = new String(error.networkResponse.data, "UTF-8");
                            repairCallBack.onAddPointChildRepair(false, error.networkResponse.statusCode, errString);
                        } catch (UnsupportedEncodingException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            repairCallBack.onAddPointChildRepair(false, error.networkResponse.statusCode, null);
                        }
                    }else {
                        String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                        repairCallBack.onAddPointChildRepair(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString);
                    }
                }){
            @Override
            public Map<String, String> getStringUploads(){
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<String, String>();
                params.put("childPlanId", pointRepair.getPlan_id());
                params.put("planTempPointId", pointRepair.getPoint_id());
                String lon = Double.toString(pointRepair.getLng());
                params.put("x", lon);
                String lat = Double.toString(pointRepair.getLat());
                params.put("y", lat);
                UserBean userBean = BaseApp.getInstance().getLoginUser();
                if (userBean != null) {
                    params.put("userid", userBean.getUserid());
                }
                List<AdjustRepairContent> contents = pointRepair.getContents();
                if (contents != null) {
                    //List<AdjustRepairContent> validContents = new ArrayList<>();
                    int index = 0;
                    for (AdjustRepairContent repairContent : contents) {
                        List<String> content = repairContent.getMenuIds();
                        if (!repairContent.getNote().isEmpty() || (content != null && content.size() > 0)) {
                            String key = String.format(Locale.CHINA, "content[%d].menuIds", index);
                            String value = "";
                            if (content != null && content.size() > 0) {
                                value = StringUtil.listToString(content, ',');
                            }
                            params.put(key, value);

                            key = String.format(Locale.CHINA, "content[%d].parentId", index);
                            params.put(key, repairContent.getParentId());

                            key = String.format(Locale.CHINA, "content[%d].note", index);
                            params.put(key, repairContent.getNote());
                            index++;
                        }
                    }
/*                    if (validContents != null && validContents.size() > 0) {
                        Gson gson = new Gson();
                        String strJson = gson.toJson(contents);
                        params.put("content", strJson);
                    }*/
                }
                params.put("region", pointRepair.getCheckRegion());
/*                params.put("checkBeginDate", pointRepair.getCheckBeginDate());
                params.put("checkEndDate", pointRepair.getCheckEndDate());*/
                if (isUpdate) {
                    params.put("id", pointRepair.getId() + "");
                }
                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();
                        long second = pictureBean.getSecond() / 1000;
                        String key = "file" + count + "," + second + "," + time;
                        if (file != null && !file.isEmpty()) {
                            if (FileUtil.fileExists(file)) {
                                params.put(key, new File(file));
                            }
                        }
                    }
                }
                return params;
            }

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

    /*阀门设备巡检录入*/
    @Override
    public void addCommonDeviceRepairRecord(final Context context, final PlanPointRepair pointRepair,
                                            final List<TroublePictureBean> photos, boolean isUpdate, final PointRepairCallBack repairCallBack) {
        String url = newApi_dyrq.getCommonDeviceMaintainUrl();
        int post_method = isUpdate ? Request.Method.PUT : Request.Method.POST;
        MultiPartStringRequest postRequest = new MultiPartStringRequest(post_method,
                url, response -> {
                    URLResponseCode.URLResponse responseCode = new URLResponseCode.URLResponse(response);
                    if (responseCode.getCode() == URLResponseCode.ErrorCode.SUCCESS){
                        repairCallBack.onAddPointChildRepair(true, responseCode.getCode(), responseCode.getMessage());
                    }else {
                        repairCallBack.onAddPointChildRepair(false, responseCode.getCode(), responseCode.getMessage());
                    }
                }, error -> {
                    //登录失败
                    if (error.networkResponse != null) {
                        try {
                            String errString = new String(error.networkResponse.data, "UTF-8");
                            repairCallBack.onAddPointChildRepair(false, error.networkResponse.statusCode, errString);
                        } catch (UnsupportedEncodingException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            repairCallBack.onAddPointChildRepair(false, error.networkResponse.statusCode, null);
                        }
                    }else {
                        String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                        repairCallBack.onAddPointChildRepair(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString);
                    }
                }){
            @Override
            public Map<String, String> getStringUploads(){
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<String, String>();
                params.put("childPlanId", pointRepair.getPlan_id());
                params.put("planTempPointId", pointRepair.getPoint_id());
                String lon = Double.toString(pointRepair.getLng());
                params.put("x", lon);
                String lat = Double.toString(pointRepair.getLat());
                params.put("y", lat);
                String deviceUser = pointRepair.getDeviceUser() ;
                params.put("deviceUser", deviceUser);
                List<String> listContent = pointRepair.getContent();
                if (listContent != null && listContent.size() > 0) {
                    String content = StringUtil.listToString(listContent, ',');
                    params.put("content", content);
                }
                String notes = pointRepair.getNotes();
                if (notes != null && !notes.isEmpty()){
                    params.put("repairContent", notes);
                }
                if (isUpdate) {
                    params.put("id", pointRepair.getId() + "");
                }
                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();
                        long second = pictureBean.getSecond() / 1000;
                        String key = "file" + count + "," + second + "," + time;
                        if (file != null && !file.isEmpty()) {
                            if (FileUtil.fileExists(file)) {
                                params.put(key, new File(file));
                            }
                        }
                    }
                }
                return params;
            }

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

    @Override
    public void getPointChildRepairList(final String token, final String child_plan_id, final PlanPointRepair pointRepair, final int pageindex, final int pagesize, final PointRepairCallBack repairCallBack) {
        String url = NetRequestURL.getPlanPointChildRepairListUrl();
        StringRequest postRequest = new StringRequest(Request.Method.POST,
                url, response -> {
                    URLResponseCode.URLResponse responseCode = new URLResponseCode.URLResponse(response);
                    if (responseCode.getCode() == URLResponseCode.ErrorCode.SUCCESS){
                        String rowsArray = responseCode.queryResult("rows");
                        List<PlanPointRepair> pointRepairList = 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<PlanPointRepair> repairs = gson.fromJson(rowsArray, new TypeToken<List<PlanPointRepair>>(){}.getType());
                                if (repairs != null && repairs.size() >= 0){
                                    pointRepairList = repairs;
                                    resCode = responseCode.getCode();
                                    parseErrMsg = responseCode.getMessage();
                                    result = true;
                                }
                            }catch (Exception e){
                                repairCallBack.onGetPointChildRepairList(false, resCode, parseErrMsg, null, 0);
                            }
                        }
                        repairCallBack.onGetPointChildRepairList(result, resCode, parseErrMsg, pointRepairList, total);
                    }else {
                        repairCallBack.onGetPointChildRepairList(
                                false, responseCode.getCode(), responseCode.getMessage(), null, 0);
                    }
                }, error -> {
                    //登录失败
                    if (error.networkResponse != null) {
                        try {
                            String errString = new String(error.networkResponse.data, "UTF-8");
                            repairCallBack.onGetPointChildRepairList(
                                    false, error.networkResponse.statusCode, errString, null, 0);
                        } catch (UnsupportedEncodingException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            repairCallBack.onGetPointChildRepairList(
                                    false, error.networkResponse.statusCode, null, null, 0);
                        }
                    }else {
                        String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                        repairCallBack.onGetPointChildRepairList(
                                false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null, 0);
                    }
                }){
            @Override
            protected Map<String, String> getParams(){
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<String, String>();
                params.put("child_plan_id", child_plan_id);
                params.put("point_id", pointRepair.getPoint_id());
                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 getAdjustDeviceChildRepairList(final Context context, String user_id, final String plan_id, final String point_id, final int pageindex, final int pagesize, final PointRepairCallBack repairCallBack) {
        String url = newApi_dyrq.getAdjustDeviceRepairListUrl() + "?current=" + pageindex + "&size="
                + pagesize + "&createUser=" + user_id + "&childPlanId=" + plan_id + "&planTempPointId=" + point_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.queryResult("records");
                        List<PlanPointRepair> pointRepairList = 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 = PlanPointRepair.getGsonAdjustContentNaming();
                                List<PlanPointRepair> repairs = gson.fromJson(rowsArray, new TypeToken<List<PlanPointRepair>>(){}.getType());
                                if (repairs != null && repairs.size() >= 0){
                                    pointRepairList = repairs;
                                    resCode = responseCode.getCode();
                                    parseErrMsg = responseCode.getMessage();
                                    result = true;
                                    savePointRepairRecords(repairs);
                                }
                            }catch (Exception e){
                                repairCallBack.onGetPointChildRepairList(false, resCode, parseErrMsg, null, 0);
                            }
                        }
                        repairCallBack.onGetPointChildRepairList(result, resCode, parseErrMsg, pointRepairList, total);
                    }else {
                        repairCallBack.onGetPointChildRepairList(
                                false, responseCode.getCode(), responseCode.getMessage(), null, 0);
                    }
                }, error -> {
                    //登录失败
                    if (error.networkResponse != null) {
                        try {
                            String errString = new String(error.networkResponse.data, "UTF-8");
                            repairCallBack.onGetPointChildRepairList(
                                    false, error.networkResponse.statusCode, errString, null, 0);
                        } catch (UnsupportedEncodingException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            repairCallBack.onGetPointChildRepairList(
                                    false, error.networkResponse.statusCode, null, null, 0);
                        }
                    }else {
                        String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                        repairCallBack.onGetPointChildRepairList(
                                false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null, 0);
                    }
                }){
            @Override
            public Map<String, String> getHeaders(){
                //参数拼装:表单提交方式
                return newApi_dyrq.getHeaderParams();
            }
        };
        BaseApp.addRequest(context.getClass().getName(), postRequest);
    }

    @Override
    public void getCommonDeviceChildRepairList(Context context, String user_id, final String plan_id, final String point_id, final int pageindex, final int pagesize, final PointRepairCallBack repairCallBack) {
        String url = newApi_dyrq.getCommonDeviceRepairListUrl() + "?current=" + pageindex + "&size="
                + pagesize /*+ "&createUser=" + user_id */+ "&childPlanId=" + plan_id + "&planTempPointId=" + point_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.queryResult("records");
                        List<PlanPointRepair> pointRepairList = 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<PlanPointRepair> repairs = gson.fromJson(rowsArray, new TypeToken<List<PlanPointRepair>>(){}.getType());
                                if (repairs != null && repairs.size() >= 0){
                                    pointRepairList = repairs;
                                    resCode = responseCode.getCode();
                                    parseErrMsg = responseCode.getMessage();
                                    result = true;
                                    savePointRepairRecords(repairs);
                                }
                            }catch (Exception e){
                                repairCallBack.onGetPointChildRepairList(false, resCode, parseErrMsg, null, 0);
                            }
                        }
                        repairCallBack.onGetPointChildRepairList(result, resCode, parseErrMsg, pointRepairList, total);
                    }else {
                        repairCallBack.onGetPointChildRepairList(
                                false, responseCode.getCode(), responseCode.getMessage(), null, 0);
                    }
                }, error -> {
                    //登录失败
                    if (error.networkResponse != null) {
                        try {
                            String errString = new String(error.networkResponse.data, "UTF-8");
                            repairCallBack.onGetPointChildRepairList(
                                    false, error.networkResponse.statusCode, errString, null, 0);
                        } catch (UnsupportedEncodingException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            repairCallBack.onGetPointChildRepairList(
                                    false, error.networkResponse.statusCode, null, null, 0);
                        }
                    }else {
                        String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                        repairCallBack.onGetPointChildRepairList(
                                false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null, 0);
                    }
                }){
            @Override
            public Map<String, String> getHeaders(){
                //参数拼装:表单提交方式
                return newApi_dyrq.getHeaderParams();
            }
        };
        BaseApp.addRequest(context.getClass().getName(), postRequest);
    }

    private void savePointRepairRecords(List<PlanPointRepair> pointRepairs){
        if (pointRepairs != null && pointRepairs.size() > 0){
            for (PlanPointRepair pointRepair : pointRepairs){
                PlanPointRepair localPointRepair = dbDaoHelper.getLocalRepairInfo(pointRepair.getPlan_id(), pointRepair.getPoint_id());
                if (localPointRepair == null) {
                    String temp_id = UUID.randomUUID().toString();
                    pointRepair.setTemp_id(temp_id);
                    pointRepair.setState(TroubleBean.SERVER_STATE);
                    dbDaoHelper.insertOrUpdateRepairRecord(pointRepair);
                }else {
                    pointRepair.setTemp_id(localPointRepair.getTemp_id());
                }

                saveRepairPhotos(pointRepair);
            }
        }
    }

    /**
     * 保存从服务器上获取的工单图片，先删除本地的图片(不包括未提交的工单)
     * @param pointRepair 维修记录
     * */
    private void saveRepairPhotos(PlanPointRepair pointRepair) {
        if (pointRepair != null) {
            String record_id = pointRepair.getTemp_id();
            List<FileBean> photos = pointRepair.getFiles();
            for (FileBean fileBean : photos) {
                String fileName = fileBean.getFileName();
                String fileUrl = fileBean.getFilePath();
                if (fileUrl != null && !fileUrl.isEmpty()) {
                    TroublePictureBean savedPicture = dbDaoHelper.queryTroublePictureByUrl(fileUrl);
                    if (savedPicture == null) {
                        TroublePictureBean pictureBean = new TroublePictureBean();
                        String pictureid = UUID.randomUUID().toString();
                        String filetype = MimeUtil.getMimeType(fileUrl);
                        String time = DateUtils.getDate(new Date().getTime());
                        pictureBean.setId(pictureid);
                        pictureBean.setTroubleid(record_id);
                        pictureBean.setFileurl(fileUrl);
                        pictureBean.setFile(fileName);
                        pictureBean.setFiletype(filetype);
                        pictureBean.setStatus(TroubleBean.SERVER_STATE);
                        pictureBean.setCreateTime(time);
                        dbDaoHelper.insertTroublePicture(pictureBean);
                    }
                }
            }
        }
    }

    /**
     * 获取调压设备检修需要录入的参数配置
     */
    public void getAdjustDeviceSettingList(Context context, int pageindex, int pagesize, PointRepairCallBack repairCallBack) {
        String url = newApi_dyrq.getAdjustDeviceParamListUrl() + "?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<MaintainAdjustParam> paramList = 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<MaintainAdjustParam> params = gson.fromJson(rowsArray, new TypeToken<List<MaintainAdjustParam>>(){}.getType());
                                if (params != null && params.size() >= 0){
                                    paramList = params;
                                    resCode = responseCode.getCode();
                                    parseErrMsg = responseCode.getMessage();
                                    result = true;
                                    saveAdjustDeviceSettings(paramList);
                                }
                            }catch (Exception e){
                                repairCallBack.onGetAdjustDeviceSettingList(false, resCode, parseErrMsg, null, 0);
                            }
                        }
                        repairCallBack.onGetAdjustDeviceSettingList(result, resCode, parseErrMsg, paramList, total);
                    }else {
                        repairCallBack.onGetAdjustDeviceSettingList(false, responseCode.getCode(), responseCode.getMessage(), null, 0);
                    }
                }, error -> {
                    //登录失败
                    if (error.networkResponse != null) {
                        try {
                            String errString = new String(error.networkResponse.data, "UTF-8");
                            repairCallBack.onGetAdjustDeviceSettingList(false, error.networkResponse.statusCode, errString, null, 0);
                        } catch (UnsupportedEncodingException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                            repairCallBack.onGetAdjustDeviceSettingList(false, error.networkResponse.statusCode, null, null, 0);
                        }
                    }else {
                        String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                        repairCallBack.onGetAdjustDeviceSettingList(
                                false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null, 0);
                    }
                }){
            @Override
            public Map<String, String> getHeaders(){
                //参数拼装:表单提交方式
                return newApi_dyrq.getHeaderParams();
            }
        };
        BaseApp.addRequest(context.getClass().getName(), postRequest);
    }

    private void saveAdjustDeviceSettings(List<MaintainAdjustParam> params){
        if (params != null && params.size() > 0){
            dbDaoHelper.deleteAdjustDeviceSettings();
            dbDaoHelper.insertAdjustDeviceSettings(params);
        }
    }

    /**
     * 获取阀井设备检修需要录入的参数配置
     */
    public void getCommonDeviceSettingList(Context context, int pageindex, int pagesize, PointRepairCallBack repairCallBack) {
        String url = newApi_dyrq.getCommonDeviceParamListUrl()+ "?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<MaintainCommonParam> paramList = 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<MaintainCommonParam> params = gson.fromJson(rowsArray, new TypeToken<List<MaintainCommonParam>>(){}.getType());
                        if (params != null && params.size() >= 0){
                            paramList = params;
                            resCode = responseCode.getCode();
                            parseErrMsg = responseCode.getMessage();
                            result = true;
                            saveCommonDeviceSettings(paramList);
                        }
                    }catch (Exception e){
                        repairCallBack.onGetCommonDeviceSettingList(false, resCode, parseErrMsg, null, 0);
                    }
                }
                repairCallBack.onGetCommonDeviceSettingList(result, resCode, parseErrMsg, paramList, total);
            }else {
                repairCallBack.onGetCommonDeviceSettingList(false, responseCode.getCode(), responseCode.getMessage(), null, 0);
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    repairCallBack.onGetCommonDeviceSettingList(false, error.networkResponse.statusCode, errString, null, 0);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    repairCallBack.onGetCommonDeviceSettingList(false, error.networkResponse.statusCode, null, null, 0);
                }
            }else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                repairCallBack.onGetCommonDeviceSettingList(
                        false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null, 0);
            }
        }){
            @Override
            public Map<String, String> getHeaders(){
                //参数拼装:表单提交方式
                return newApi_dyrq.getHeaderParams();
            }
        };
        BaseApp.addRequest(context.getClass().getName(), postRequest);
    }

    private void saveCommonDeviceSettings(List<MaintainCommonParam> params){
        if (params != null && params.size() > 0){
            dbDaoHelper.deleteValveDeviceSettings();
            dbDaoHelper.insertCommonDeviceSettings(params);
        }
    }

    @Override
    public void getRepairNFCInfo(final String token, final String rfid, final int device_type_id, final PointRepairCallBack repairCallBack) {
        String url = NetRequestURL.getRepairNfcInfoUrl();
        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("nfc");
                    NFCInfoBean nfcInfoBean = null;
                    int resCode = -1;
                    boolean result = false;
                    String parseErrMsg = "用户解析失败";
                    if (rowsArray != null){
                        try {
                            Gson gson = new Gson();
                            NFCInfoBean infoBean = gson.fromJson(rowsArray, new TypeToken<NFCInfoBean>(){}.getType());
                            if (infoBean != null){
                                nfcInfoBean = infoBean;
                                resCode = responseCode.getCode();
                                parseErrMsg = responseCode.getMessage();
                                result = true;
                            }
                        }catch (Exception e){
                            repairCallBack.onGetRepairNFCInfo(false, resCode, parseErrMsg, null);
                        }
                    }
                    repairCallBack.onGetRepairNFCInfo(result, resCode, parseErrMsg, nfcInfoBean);
                }else {
                    repairCallBack.onGetRepairNFCInfo(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");
                        repairCallBack.onGetRepairNFCInfo(false, error.networkResponse.statusCode, errString, null);
                    } catch (UnsupportedEncodingException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                        repairCallBack.onGetRepairNFCInfo(false, error.networkResponse.statusCode, null, null);
                    }
                }else {
                    String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                    repairCallBack.onGetRepairNFCInfo(
                            false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null);
                }
            }
        }){
            @Override
            protected Map<String, String> getParams(){
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<String, String>();
                params.put("rfid", rfid);
                params.put("device_type_id", device_type_id + "");
                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 getRouteDeviceTypeList(Context context, String typeIds, int pageindex, int pagesize, PointRepairCallBack repairCallBack) {
        String url = newApi_dyrq.getDeviceTypeListUrl()+ "?current=" + pageindex + "&size=" + pagesize + "&ids=" + typeIds;
        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<RouteDeviceType> deviceList = 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<RouteDeviceType> deviceTypes = gson.fromJson(rowsArray, new TypeToken<List<RouteDeviceType>>(){}.getType());
                        if (deviceTypes != null && deviceTypes.size() >= 0){
                            deviceList = deviceTypes;
                            resCode = responseCode.getCode();
                            parseErrMsg = responseCode.getMessage();
                            result = true;
                        }
                    }catch (Exception e){
                        repairCallBack.onGetDatas(false, resCode, parseErrMsg, null, total);
                    }
                }
                repairCallBack.onGetDatas(result, resCode, parseErrMsg, deviceList, total);
            }else {
                repairCallBack.onGetDatas(false, responseCode.getCode(), responseCode.getMessage(), null, 0);
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    repairCallBack.onGetDatas(false, error.networkResponse.statusCode, errString, null, 0);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    repairCallBack.onGetDatas(false, error.networkResponse.statusCode, null, null, 0);
                }
            }else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                repairCallBack.onGetDatas(
                        false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null, 0);
            }
        }){
            @Override
            public Map<String, String> getHeaders(){
                //参数拼装:表单提交方式
                return newApi_dyrq.getHeaderParams();
            }
        };
        BaseApp.addRequest(context.getClass().getName(), postRequest);
    }

    @Override
    public void getDeviceRouteParamList(Context context, String deviceId, int pageindex, int pagesize, PointRepairCallBack repairCallBack) {
        String url = newApi_dyrq.getRouteParamListUrl() + "?current=" + pageindex + "&size=" + pagesize + "&typeId=" + deviceId;
        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<DeviceRouteParam> paramList = 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<DeviceRouteParam> routeParams = gson.fromJson(rowsArray, new TypeToken<List<DeviceRouteParam>>(){}.getType());
                        if (routeParams != null && routeParams.size() >= 0){
                            paramList = routeParams;
                            resCode = responseCode.getCode();
                            parseErrMsg = responseCode.getMessage();
                            result = true;
                        }
                    }catch (Exception e){
                        repairCallBack.onGetDatas(false, resCode, parseErrMsg, null, total);
                    }
                }
                repairCallBack.onGetDatas(result, resCode, parseErrMsg, paramList, total);
            }else {
                repairCallBack.onGetDatas(false, responseCode.getCode(), responseCode.getMessage(), null, 0);
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    repairCallBack.onGetDatas(false, error.networkResponse.statusCode, errString, null, 0);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    repairCallBack.onGetDatas(false, error.networkResponse.statusCode, null, null, 0);
                }
            }else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                repairCallBack.onGetDatas(
                        false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null, 0);
            }
        }){
            @Override
            public Map<String, String> getHeaders(){
                //参数拼装:表单提交方式
                return newApi_dyrq.getHeaderParams();
            }
        };
        BaseApp.addRequest(context.getClass().getName(), postRequest);
    }

    @Override
    public void uploadDeviceRouteRecord(Context context, JSONObject jsonObject,
                                        List<TroublePictureBean> photos, List<TroubleAudioBean> audios, boolean isUpdate, PointRepairCallBack repairCallBack) {
        String url = newApi_dyrq.getDeviceRouteCheckUrl();
        int post_method = isUpdate ? Request.Method.PUT : Request.Method.POST;
        MultiPartStringRequest postRequest = new MultiPartStringRequest(post_method,
                url, response -> {
            URLResponseCode.URLResponse responseCode = new URLResponseCode.URLResponse(response);
            if (responseCode.getCode() == URLResponseCode.ErrorCode.SUCCESS){
                repairCallBack.onSetData(true, responseCode.getCode(), responseCode.getMessage());
            }else {
                repairCallBack.onSetData(false, responseCode.getCode(), responseCode.getMessage());
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    repairCallBack.onSetData(false, error.networkResponse.statusCode, errString);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    repairCallBack.onSetData(false, error.networkResponse.statusCode, null);
                }
            }else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                repairCallBack.onSetData(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString);
            }
        }){
            @Override
            public Map<String, String> getStringUploads(){
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<>();
                for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
                    String key = entry.getKey();
                    Object value = entry.getValue();
                    if (value != null) {
                        params.put(key, value.toString());
                    }
                }
                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 = "photo" + count + "," + 0 + "," + time;
                        if (file != null && !file.isEmpty()) {
                            if (FileUtil.fileExists(file)) {
                                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 = "audio" + count + "," + second + "," + time;;
                        if (file != null && !file.isEmpty()){
                            if (FileUtil.fileExists(file)) {
                                params.put(key, new File(file));
                            }
                        }
                    }
                }
                return params;
            }

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

    @Override
    public void getDeviceRouteRecordList(Context context, String plan_id, String point_id, int pageindex, int pagesize, PointRepairCallBack repairCallBack) {
        String url = newApi_dyrq.getDeviceRouteCheckListUrl() + "?current=" + pageindex + "&size="
                + pagesize + "&childPlanId=" + plan_id + "&planTempPointId=" + point_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.queryResult("records");
                List<DeviceRouteData> routeList = 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<DeviceRouteData> routeDatas = gson.fromJson(rowsArray, new TypeToken<List<DeviceRouteData>>(){}.getType());
                        if (routeDatas != null && routeDatas.size() >= 0){
                            routeList = routeDatas;
                            resCode = responseCode.getCode();
                            parseErrMsg = responseCode.getMessage();
                            result = true;
                        }
                    }catch (Exception e){
                        repairCallBack.onGetDatas(false, resCode, parseErrMsg, null, 0);
                    }
                }
                repairCallBack.onGetDatas(result, resCode, parseErrMsg, routeList, total);
            }else {
                repairCallBack.onGetDatas(
                        false, responseCode.getCode(), responseCode.getMessage(), null, 0);
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    repairCallBack.onGetDatas(
                            false, error.networkResponse.statusCode, errString, null, 0);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    repairCallBack.onGetDatas(
                            false, error.networkResponse.statusCode, null, null, 0);
                }
            }else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                repairCallBack.onGetDatas(
                        false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString, null, 0);
            }
        }){
            @Override
            public Map<String, String> getHeaders(){
                //参数拼装:表单提交方式
                return newApi_dyrq.getHeaderParams();
            }
        };
        BaseApp.addRequest(context.getClass().getName(), postRequest);
    }
}
