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

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

import com.android.volley.Request;
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.domain.BuildFileBean;
import com.tofly.ghrq_route.module.buildManage.domain.BuildManagerBean;
import com.tofly.ghrq_route.module.buildManage.domain.VoiceBeans;
import com.tofly.ghrq_route.module.rushrepair.controller.RushRepairCallback;
import com.tofly.ghrq_route.module.rushrepair.domain.RushRepairBean;
import com.tofly.ghrq_route.module.rushrepair.domain.RushRepairBeanList;
import com.tofly.ghrq_route.module.rushrepair.domain.RushRepairExamineBean;
import com.tofly.ghrq_route.module.rushrepair.domain.RushRepairExamineList;
import com.tofly.ghrq_route.module.rushrepair.domain.RushRepairFileBean;
import com.tofly.ghrq_route.module.rushrepair.domain.RushRepairProcessBean;
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.TroublePictureBean;
import com.tofly.ghrq_route.common.util.date.DateUtils;
import com.tofly.ghrq_route.common.util.net.volley.JsonRequestConstant;
import com.tofly.ghrq_route.common.util.net.volley.MultiPartStringRequest;

import org.json.JSONException;
import org.json.JSONObject;

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

public class RushRepairServiceImpl implements IRushRepairService {

    private Context mContext;
    private DBDaoHelper dbDaoHelper;

    public RushRepairServiceImpl(Context mContext) {
        this.mContext = mContext;
        dbDaoHelper = DBDaoHelper.getInstance();
    }

    @Override
    public void addBuildJobManage(RushRepairBean buildJobBean, List<TroublePictureBean> photos, List<TroubleAudioBean> audios, List<BuildFileBean> filesList, RushRepairCallback rushRepairCallback) {
        String url = NetRequestURL.getUpLoadRepairUrl();
        MultiPartStringRequest postRequest = new MultiPartStringRequest(Request.Method.POST, url, response -> {
            URLResponseCode.URLResponse urlResponse = new URLResponseCode.URLResponse(response);
            if (urlResponse.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                rushRepairCallback.onAddBuildManage(true, urlResponse.getCode(), urlResponse.getMessage());
            } else {
                rushRepairCallback.onAddBuildManage(false, urlResponse.getCode(), urlResponse.getMessage());
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    rushRepairCallback.onAddBuildManage(false, error.networkResponse.statusCode, errString);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    rushRepairCallback.onAddBuildManage(false, error.networkResponse.statusCode, null);
                }
            } else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                rushRepairCallback.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(buildJobBean.getAddress())) {
                    params.put("address", buildJobBean.getAddress());
                }
                if (!TextUtils.isEmpty(buildJobBean.getContact())) {
                    params.put("contact", buildJobBean.getContact());
                }
                if (!TextUtils.isEmpty(buildJobBean.getContactPhone())) {
                    params.put("contactPhone", buildJobBean.getContactPhone());
                }
                if (!TextUtils.isEmpty(buildJobBean.getDescription())) {
                    params.put("description", buildJobBean.getDescription());
                }
                if (!TextUtils.isEmpty(buildJobBean.getWorkOrderSource())) {
                    params.put("workOrderSource", buildJobBean.getWorkOrderSource());
                }
                if (!TextUtils.isEmpty(buildJobBean.getWorkOrderType())) {
                    params.put("workOrderType", buildJobBean.getWorkOrderType());
                }
                if (buildJobBean.getX() != 0.0) {
                    params.put("x", String.valueOf(buildJobBean.getX()));
                }
                if (buildJobBean.getY() != 0.0) {
                    params.put("y", String.valueOf(buildJobBean.getY()));
                }
                if (!TextUtils.isEmpty(buildJobBean.getDispatchUserId())) {
                    params.put("dispatchUserId", buildJobBean.getDispatchUserId());
                }
                if (!TextUtils.isEmpty(buildJobBean.getWorkOrderId())) {
                    params.put("workOrderId", buildJobBean.getWorkOrderId());
                }
                if (!TextUtils.isEmpty(buildJobBean.getDepartment())) {
                    params.put("department", buildJobBean.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();
                        int count = i + 1;
                        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 count = i + 1;
                        String key = "audio" + count;
                        if (file != null && !file.isEmpty()) {
                            params.put(key, new File(file));
                        }
                    }
                }
                if (filesList != null && filesList.size() > 0) {
                    for (int i = 0; i < filesList.size(); i++) {
                        BuildFileBean buildFileBean = filesList.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 getRushRepairList(int pageindex, int pagesize, RushRepairCallback repairCallback) {
        String userid = BaseApp.getInstance().getLoginUser().getUserid();
        String url = NetRequestURL.getRepairListUrl() + "?current=" + pageindex + "&size=" + pagesize + "&userIds=" + userid + "&workOrderStates=2,4";
        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<RushRepairBeanList> buildManages = null;
                List<RushRepairBean> 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<RushRepairBeanList>>() {
                        }.getType());
                        dataList = gson.fromJson(rowsArray, new TypeToken<List<RushRepairBean>>() {
                        }.getType());
                        if (buildManages != null) {
                            buildManages.size();
                            resCode = responseCode.getCode();
                            parseErrMsg = responseCode.getMessage();
                            result = true;
                            saveRushRepair(buildManages, dataList);
                        }
                    } catch (Exception e) {
                        repairCallback.onRepairList(false, resCode, parseErrMsg, null, 0);
                    }
                }
                repairCallback.onRepairList(result, resCode, parseErrMsg, dataList, total);
            } else {
                repairCallback.onRepairList(false, responseCode.getCode(), responseCode.getMessage(), null, 0);
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    repairCallback.onRepairList(
                            false, error.networkResponse.statusCode, errString, null, 0);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    repairCallback.onRepairList(
                            false, error.networkResponse.statusCode, null, null, 0);
                }
            } else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                repairCallback.onRepairList(
                        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 getDataList(int state, int pageindex, int pagesize, RushRepairCallback repairCallback) {
        String userid = BaseApp.getInstance().getLoginUser().getUserid();
        String url = NetRequestURL.getRepairListUrl1() + "?current=" + pageindex + "&size=" + pagesize + "&userIds=" + userid + "&workOrderState=" + 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<RushRepairBean> 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<RushRepairBean>>() {
                        }.getType());
                        if (buildManages != null) {
                            resCode = responseCode.getCode();
                            parseErrMsg = responseCode.getMessage();
                            repairCallback.onRepairList(true, resCode, parseErrMsg, buildManages, total);
                        }
                    } catch (Exception e) {
                        repairCallback.onRepairList(false, resCode, parseErrMsg, null, 0);
                    }
                }
                repairCallback.onRepairList(false, resCode, parseErrMsg, buildManages, total);
            } else {
                repairCallback.onRepairList(false, responseCode.getCode(), responseCode.getMessage(), null, 0);
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    repairCallback.onRepairList(false, error.networkResponse.statusCode, errString, null, 0);
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                    repairCallback.onRepairList(false, error.networkResponse.statusCode, null, null, 0);
                }
            } else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                repairCallback.onRepairList(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, RushRepairCallback repairCallback) {
        String url;
        if (!TextUtils.isEmpty(keyWord)) {
            String content = "";
            try {
                content = URLEncoder.encode(keyWord, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            url = NetRequestURL.getRepairListUrl() + "?current=" + pageindex + "&size=" + pagesize + "&adsOrIdOrSocOrDesc=" + content;
        } else {
            url = NetRequestURL.getRepairListUrl() + "?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<RushRepairBean> 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<RushRepairBean>>() {
                        }.getType());
                        if (buildManages != null) {
                            resCode = responseCode.getCode();
                            parseErrMsg = responseCode.getMessage();
                            repairCallback.onRepairList(true, resCode, parseErrMsg, buildManages, total);
                        }
                    } catch (Exception e) {
                        repairCallback.onRepairList(false, resCode, parseErrMsg, null, 0);
                    }
                }
                repairCallback.onRepairList(false, resCode, parseErrMsg, buildManages, total);
            } else {
                repairCallback.onRepairList(false, responseCode.getCode(), responseCode.getMessage(), null, 0);
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    repairCallback.onRepairList(false, error.networkResponse.statusCode, errString, null, 0);
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                    repairCallback.onRepairList(false, error.networkResponse.statusCode, null, null, 0);
                }
            } else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                repairCallback.onRepairList(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 getDataDetail(String id, RushRepairCallback rushRepairCallback) {
        String url = NetRequestURL.getRepairDetailUrl() + 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();
                RushRepairBeanList 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<RushRepairBeanList>() {
                        }.getType());
                        if (buildManages != null) {
                            resCode = responseCode.getCode();
                            parseErrMsg = responseCode.getMessage();
                            rushRepairCallback.onRepairDetail(true, resCode, parseErrMsg, buildManages, total);
                        }
                    } catch (Exception e) {
                        rushRepairCallback.onRepairDetail(false, resCode, parseErrMsg, null, 0);
                    }
                }
                rushRepairCallback.onRepairDetail(false, resCode, parseErrMsg, buildManages, total);
            } else {
                rushRepairCallback.onRepairDetail(false, responseCode.getCode(), responseCode.getMessage(), null, 0);
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    rushRepairCallback.onRepairDetail(false, error.networkResponse.statusCode, errString, null, 0);
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                    rushRepairCallback.onRepairDetail(false, error.networkResponse.statusCode, null, null, 0);
                }
            } else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                rushRepairCallback.onRepairDetail(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 addRushProcessManage(RushRepairProcessBean buildManage, List<TroublePictureBean> photos, List<TroubleAudioBean> audios, List<BuildFileBean> fileBeanList, RushRepairCallback repairCallback) {
        String url = NetRequestURL.getRushRepairProcessManageUrl();
        MultiPartStringRequest postRequest = new MultiPartStringRequest(Request.Method.POST,
                url, response -> {
            URLResponseCode.URLResponse urlResponse = new URLResponseCode.URLResponse(response);
            if (urlResponse.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                repairCallback.onAddBuildManage(true, urlResponse.getCode(), urlResponse.getMessage());
            } else {
                repairCallback.onAddBuildManage(false, urlResponse.getCode(), urlResponse.getMessage());
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    repairCallback.onAddBuildManage(false, error.networkResponse.statusCode, errString);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    repairCallback.onAddBuildManage(false, error.networkResponse.statusCode, null);
                }
            } else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                repairCallback.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.getX() > 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();
                        int count = i + 1;
                        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);
    }

    private void saveRushRepair(List<RushRepairBeanList> dataList, List<RushRepairBean> repairBeanLists) {
        dbDaoHelper.deleteAllRushRepair();
        dbDaoHelper.deleteAllRushProcess();
        dbDaoHelper.deleteAllRushExamine();
        dbDaoHelper.deleAllRushRepairFile();
        if (repairBeanLists != null && repairBeanLists.size() > 0) {
            for (RushRepairBean rushRepairBean : repairBeanLists) {
                dbDaoHelper.insertOrUpdateRushRepair(rushRepairBean);
            }
            if (dataList.size() > 0) {
                for (RushRepairBeanList data : dataList) {
                    if (data.getVoice() != null && data.getVoice().size() > 0) {
                        for (VoiceBeans voiceBeans : data.getVoice()) {
                            RushRepairFileBean rushRepairFileBean = new RushRepairFileBean();
                            if (!TextUtils.isEmpty(data.getId())) {
                                rushRepairFileBean.setBuildId(data.getId());
                            }
                            if (!TextUtils.isEmpty(voiceBeans.getFileName())) {
                                rushRepairFileBean.setVoiceName(voiceBeans.getFileName());
                            }
                            if (!TextUtils.isEmpty(voiceBeans.getPath())) {
                                rushRepairFileBean.setVoicePath(voiceBeans.getPath());
                            }
                            dbDaoHelper.insertOrUpdateRushRepairFile(rushRepairFileBean);
                        }
                    }
                    if (data.getFiles() != null && data.getFiles().size() > 0) {
                        for (VoiceBeans voiceBeans : data.getFiles()) {
                            RushRepairFileBean rushRepairFileBean = new RushRepairFileBean();
                            if (!TextUtils.isEmpty(data.getId())) {
                                rushRepairFileBean.setBuildId(data.getId());
                            }
                            if (!TextUtils.isEmpty(voiceBeans.getFileName())) {
                                rushRepairFileBean.setFileName(voiceBeans.getFileName());
                            }
                            if (!TextUtils.isEmpty(voiceBeans.getPath())) {
                                rushRepairFileBean.setFilePath(voiceBeans.getPath());
                            }
                            dbDaoHelper.insertOrUpdateRushRepairFile(rushRepairFileBean);
                        }
                    }
                    if (data.getAuditList() != null && data.getAuditList().size() > 0) {
                        for (RushRepairExamineList rushRepairExamineList : data.getAuditList()) {
                            RushRepairExamineBean repairExamineBean = new RushRepairExamineBean();
                            if (!TextUtils.isEmpty(rushRepairExamineList.getWorkOrderId())) {
                                repairExamineBean.setWorkOrderId("" + rushRepairExamineList.getWorkOrderId());
                            }
                            if (!TextUtils.isEmpty(rushRepairExamineList.getId())) {
                                repairExamineBean.setId(rushRepairExamineList.getId());
                            }
                            if (!TextUtils.isEmpty(rushRepairExamineList.getAuditDescription())) {
                                repairExamineBean.setAuditDescription(rushRepairExamineList.getAuditDescription());
                            }
                            if (!TextUtils.isEmpty(rushRepairExamineList.getAuditmind())) {
                                repairExamineBean.setAuditmind(rushRepairExamineList.getAuditmind());
                            }
                            if (!TextUtils.isEmpty(rushRepairExamineList.getAuditmindname())) {
                                repairExamineBean.setAuditmindname(rushRepairExamineList.getAuditmindname());
                            }
                            if (!TextUtils.isEmpty(rushRepairExamineList.getAuditTime())) {
                                repairExamineBean.setAuditTime(rushRepairExamineList.getAuditTime());
                            }
                            if (!TextUtils.isEmpty(rushRepairExamineList.getDelFlag())) {
                                repairExamineBean.setDelFlag(rushRepairExamineList.getDelFlag());
                            }
                            if (!TextUtils.isEmpty(rushRepairExamineList.getAuditor())) {
                                repairExamineBean.setAuditor("" + rushRepairExamineList.getAuditor());
                            }
                            if (!TextUtils.isEmpty(rushRepairExamineList.getAuditorname())) {
                                repairExamineBean.setAuditorname(rushRepairExamineList.getAuditorname());
                            }
                            dbDaoHelper.insertOrUpdateRushExamine(repairExamineBean);
                            if (rushRepairExamineList.getAuditEndFiles() != null && rushRepairExamineList.getAuditEndFiles().size() > 0) {
                                for (VoiceBeans voiceBeans : rushRepairExamineList.getAuditEndFiles()) {
                                    RushRepairFileBean repairFileBean = new RushRepairFileBean();
                                    if (!TextUtils.isEmpty(data.getId())) {
                                        repairFileBean.setBuildId(data.getId());
                                    }
                                    if (!TextUtils.isEmpty(rushRepairExamineList.getId())) {
                                        repairFileBean.setExamineId(rushRepairExamineList.getId());
                                    }
                                    if (!TextUtils.isEmpty(voiceBeans.getFileName())) {
                                        repairFileBean.setAuditEndFilesName(voiceBeans.getFileName());
                                    }
                                    if (!TextUtils.isEmpty(voiceBeans.getPath())) {
                                        repairFileBean.setAuditEndFilesPath(voiceBeans.getPath());
                                    }
                                    dbDaoHelper.insertOrUpdateRushRepairFile(repairFileBean);
                                }
                            }
                        }
                    }
                    if (data.getProcessManages() != null && data.getProcessManages().size() > 0) {
                        for (RushRepairBeanList.ProcssManageBean procssManageBean : data.getProcessManages()) {
                            RushRepairProcessBean rushRepairProcessBean = new RushRepairProcessBean();
                            if (!TextUtils.isEmpty(data.getId())) {
                                rushRepairProcessBean.setWorkOrderId(data.getId());
                            }
                            if (!TextUtils.isEmpty(procssManageBean.getId())) {
                                rushRepairProcessBean.setId(procssManageBean.getId());
                            }
                            if (!TextUtils.isEmpty(procssManageBean.getDescription())) {
                                rushRepairProcessBean.setDescription(procssManageBean.getDescription());
                            }
                            if (!TextUtils.isEmpty(procssManageBean.getWorkOrderId())) {
                                rushRepairProcessBean.setWorkOrderId(procssManageBean.getWorkOrderId());
                            }
                            if (!TextUtils.isEmpty(procssManageBean.getManageDate())) {
                                rushRepairProcessBean.setManageDate(procssManageBean.getManageDate());
                            }
                            if (procssManageBean.getX() != 0.0) {
                                rushRepairProcessBean.setX(procssManageBean.getX());
                            }
                            if (procssManageBean.getY() != 0.0) {
                                rushRepairProcessBean.setY(procssManageBean.getY());
                            }
                            dbDaoHelper.insertOrUpdateRushRepairProcess(rushRepairProcessBean);
                            if (procssManageBean.getProcessVoice() != null && procssManageBean.getProcessVoice().size() > 0) {
                                for (VoiceBeans voiceBeans : procssManageBean.getProcessVoice()) {
                                    RushRepairFileBean rushRepairFileBean = new RushRepairFileBean();
                                    if (!TextUtils.isEmpty(procssManageBean.getId())) {
                                        rushRepairFileBean.setProcessId(procssManageBean.getId());
                                    }
                                    if (!TextUtils.isEmpty(data.getId())) {
                                        rushRepairFileBean.setBuildId(data.getId());
                                    }
                                    if (!TextUtils.isEmpty((voiceBeans.getPath()))) {
                                        rushRepairFileBean.setProcessVoicePath(voiceBeans.getPath());
                                    }
                                    if (!TextUtils.isEmpty(voiceBeans.getFileName())) {
                                        rushRepairFileBean.setProcessVoiceName(voiceBeans.getFileName());
                                    }
                                    dbDaoHelper.insertOrUpdateRushRepairFile(rushRepairFileBean);
                                }
                            }
                            if (procssManageBean.getProcessFiles() != null && procssManageBean.getProcessFiles().size() > 0) {
                                for (VoiceBeans voiceBeans : procssManageBean.getProcessFiles()) {
                                    RushRepairFileBean repairFileBean = new RushRepairFileBean();
                                    if (!TextUtils.isEmpty(procssManageBean.getId())) {
                                        repairFileBean.setProcessId(procssManageBean.getId());
                                    }
                                    if (!TextUtils.isEmpty(data.getId())) {
                                        repairFileBean.setBuildId(data.getId());
                                    }
                                    if (!TextUtils.isEmpty((voiceBeans.getPath()))) {
                                        repairFileBean.setProcessFilePath(voiceBeans.getPath());
                                    }
                                    if (!TextUtils.isEmpty(voiceBeans.getFileName())) {
                                        repairFileBean.setProcessFileName(voiceBeans.getFileName());
                                    }
                                    dbDaoHelper.insertOrUpdateRushRepairFile(repairFileBean);
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    @Override
    public void updateRushProcessState(RushRepairBean repairBean, RushRepairCallback repairCallback) {
        String url = NetRequestURL.getUpdateProcessUrl();
        StringRequest postRequest = new StringRequest(Request.Method.POST,
                url, response -> {
            URLResponseCode.URLResponse urlResponse = new URLResponseCode.URLResponse(response);
            if (urlResponse.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                repairCallback.onRushBack(true, urlResponse.getCode(), urlResponse.getMessage());
            } else {
                repairCallback.onRushBack(false, urlResponse.getCode(), urlResponse.getMessage());
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    repairCallback.onRushBack(false, error.networkResponse.statusCode, errString);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    repairCallback.onRushBack(false, error.networkResponse.statusCode, null);
                }
            } else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                repairCallback.onRushBack(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString);
            }
        }) {
            @Override
            public Map<String, String> getParams() {
                //参数拼装:表单提交方式
                Map<String, String> params = new HashMap<>();
                params.put("id", repairBean.getId());
                params.put("workOrderState", "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 getRushrenList(RushRepairCallback repairCallback) {
        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;
                        }
                    } catch (Exception e) {
                        repairCallback.onRushrenList(false, resCode, parseErrMsg, null);
                    }
                }
                repairCallback.onRushrenList(result, resCode, parseErrMsg, buildManagerBeanList);
            } else {
                repairCallback.onRushrenList(
                        false, responseCode.getCode(), responseCode.getMessage(), null);
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    repairCallback.onRushrenList(
                            false, error.networkResponse.statusCode, errString, null);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    repairCallback.onRushrenList(
                            false, error.networkResponse.statusCode, null, null);
                }
            } else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                repairCallback.onRushrenList(
                        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 getRushDispatch(RushRepairBeanList rushRepairBean, RushRepairCallback repairCallback) {
        String url = NetRequestURL.getRushDispatch();
        StringRequest postRequest = new StringRequest(Request.Method.PUT,
                url, response -> {
            URLResponseCode.URLResponse urlResponse = new URLResponseCode.URLResponse(response);
            if (urlResponse.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                repairCallback.onRushBack(true, urlResponse.getCode(), urlResponse.getMessage());
            } else {
                repairCallback.onRushBack(false, urlResponse.getCode(), urlResponse.getMessage());
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    repairCallback.onRushBack(false, error.networkResponse.statusCode, errString);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    repairCallback.onRushBack(false, error.networkResponse.statusCode, null);
                }
            } else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                repairCallback.onRushBack(false, URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT, errString);
            }
        }) {
            //            @Override
//            public Map<String, String> getParams() {
//                //参数拼装:表单提交方式
//                Map<String, String> params = new HashMap<>();
//                params.put("workOrderId", rushRepairBean.getId());
//                params.put("rushRepairResponsible", rushRepairBean.getRushRepairResponsible());
//                params.put("dispatchDate", rushRepairBean.getDispatchDate());
//                params.put("workOrderState", "2");
//                return params;
//            }
            @Override
            public byte[] getBody() {
                JSONObject jsonObject = new JSONObject();
                try {
                    if (!TextUtils.isEmpty(rushRepairBean.getId())) {
                        jsonObject.put("id", rushRepairBean.getId());
                    }
                    if (!TextUtils.isEmpty(rushRepairBean.getRushRepairResponsible())) {
                        jsonObject.put("rushRepairResponsible", rushRepairBean.getRushRepairResponsible());
                    }
                    if (!TextUtils.isEmpty(rushRepairBean.getDispatchDate())) {
                        jsonObject.put("dispatchDate", DateUtils.formatTime(rushRepairBean.getDispatchDate(), "yyyy-MM-dd"));
                    }
                    if (!TextUtils.isEmpty(rushRepairBean.getRushRepairPersons())) {
                        jsonObject.put("rushRepairPersons", rushRepairBean.getRushRepairPersons());
                    }
                    if (!TextUtils.isEmpty(rushRepairBean.getIntroduction())) {
                        jsonObject.put("introduction", rushRepairBean.getIntroduction());
                    }
                    if (!TextUtils.isEmpty(rushRepairBean.getDepartment())) {
                        jsonObject.put("department", rushRepairBean.getDepartment());
                    }
                    jsonObject.put("workOrderState", "2");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                String content = jsonObject.toString();
                return content.getBytes();
            }

            @Override
            public String getBodyContentType() {
                return JsonRequestConstant.PROTOCOL_CONTENT_TYPE;
            }

            @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 getRushExamine(RushRepairExamineList examinesBean, List<BuildFileBean> data, RushRepairCallback repairCallback) {
        String url = NetRequestURL.getExamineRushUrl();
        MultiPartStringRequest postRequest = new MultiPartStringRequest(Request.Method.POST, url, response -> {
            URLResponseCode.URLResponse urlResponse = new URLResponseCode.URLResponse(response);
            if (urlResponse.getCode() == URLResponseCode.ErrorCode.SUCCESS) {
                repairCallback.onRushBack(true, urlResponse.getCode(), urlResponse.getMessage());
            } else {
                repairCallback.onRushBack(false, urlResponse.getCode(), urlResponse.getMessage());
            }
        }, error -> {
            //登录失败
            if (error.networkResponse != null) {
                try {
                    String errString = new String(error.networkResponse.data, "UTF-8");
                    repairCallback.onRushBack(false, error.networkResponse.statusCode, errString);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    repairCallback.onRushBack(false, error.networkResponse.statusCode, null);
                }
            } else {
                String errString = URLResponseCode.ErrorCode.getErrorMessage(URLResponseCode.ErrorCode.HTTPCONN_TIMEOUT);
                repairCallback.onRushBack(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("workOrderState", "5");
                } else {
                    params.put("workOrderState", "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);
    }


}
