package com.zztrapp.zztrapp.http;

import static java.util.concurrent.TimeUnit.SECONDS;

import android.content.Context;

import com.google.gson.Gson;
import com.zztrapp.zztrapp.bean.BfjPageListBean;
import com.zztrapp.zztrapp.bean.BlackWaterTasksBean;
import com.zztrapp.zztrapp.bean.ChoosePopItemBean;
import com.zztrapp.zztrapp.bean.CreateUserBean;
import com.zztrapp.zztrapp.bean.FileBean;
import com.zztrapp.zztrapp.bean.GetAppNameBean;
import com.zztrapp.zztrapp.bean.GetTreeListBean;
import com.zztrapp.zztrapp.bean.HeiChouShuiTiIndexBean;
import com.zztrapp.zztrapp.bean.HttpResult;
import com.zztrapp.zztrapp.bean.IndexBean;
import com.zztrapp.zztrapp.bean.JcjPagelistBean;
import com.zztrapp.zztrapp.bean.LoginBean;
import com.zztrapp.zztrapp.bean.MapBfjListBean;
import com.zztrapp.zztrapp.bean.MapHcstListBean;
import com.zztrapp.zztrapp.bean.MapJcjListBean;
import com.zztrapp.zztrapp.bean.MapKhdwListBean;
import com.zztrapp.zztrapp.bean.MapNcshwsclssListBean;
import com.zztrapp.zztrapp.bean.MapWrdkBean;
import com.zztrapp.zztrapp.bean.MapZdjgdwListBean;
import com.zztrapp.zztrapp.bean.MassageBean;
import com.zztrapp.zztrapp.bean.MeetListBean;
import com.zztrapp.zztrapp.bean.MeetingBean;
import com.zztrapp.zztrapp.bean.RcrwPagelistBean;
import com.zztrapp.zztrapp.bean.SewageFacilitiesTasksBean;
import com.zztrapp.zztrapp.bean.TaskDetailSpecialBean;
import com.zztrapp.zztrapp.bean.WdPageListBean;
import com.zztrapp.zztrapp.bean.WrdkInfoBean;
import com.zztrapp.zztrapp.bean.WrdkPageListBean;
import com.zztrapp.zztrapp.bean.WrwxcBean;
import com.zztrapp.zztrapp.bean.WsclssIndexBean;
import com.zztrapp.zztrapp.bean.ZdjgdwJdxxBean;
import com.zztrapp.zztrapp.bean.ZdjgdwPagelistBean;
import com.zztrapp.zztrapp.utilcode.klogs.KLog;
import com.zztrapp.zztrapp.utilcode.util.SPUtils;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.Cookie;
import okhttp3.CookieJar;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * 请求方法处理
 * Created by Bby on 2021/10/2
 * Email bby0856@163.com
 */
public class HttpMethods {

    //    private static final int DEFAULT_TIMEOUT = 12;
    private static final int DEFAULT_TIMEOUT = 20;
    //    private static final int DEFAULT_TIMEOUT = 300;
    private Retrofit retrofit;
    private static Context mContext;
    private OkHttpClient.Builder builder;

    private String language;
    private String app;
    private String lat;
    private String lon;
    private String nonce;
    private String time;
    private String sign;
    private HashMap<String, Object> map;
    private String cityId;

    public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
    private static final MediaType MEDIA_TYPE_PNG = MediaType.parse("image/png");
    private static final MediaType MEDIA_TYPE_JPG = MediaType.parse("image/jpg");
    private static final MediaType MEDIA_TYPE_FILE = MediaType.parse("file/*");

    private String deviceToken;
    private String authorization;
    private String deviceType;
    private String deviceId;
    private String model;
    private Integer os;
    private final ZztrService ZztrService;


    //构造方法私有
    private HttpMethods() {
        //日志拦截器
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
            @Override
            public void log(String message) {
//                打印retrofit日志
                KLog.e("HttpLogInfo", message);
            }
        });
        loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

        File httpCacheDirectory = new File(mContext.getExternalCacheDir(), "responses");

        //手动创建一个OkHttpClient并设置超时时间
        builder = new OkHttpClient.Builder()
                .cookieJar(new CookieJar() {
                    //                    private final HashMap<HttpUrl, List<Cookie>> cookieStore = new HashMap<>();
                    private final HashMap<String, List<Cookie>> cookieStore = new HashMap<>();

                    @Override
                    public void saveFromResponse(HttpUrl httpUrl, List<Cookie> list) {
//                        Log.e("bbs", httpUrl.host());
                        cookieStore.put(httpUrl.host(), list);
                    }

                    @Override
                    public List<Cookie> loadForRequest(HttpUrl httpUrl) {
                        List<Cookie> cookies = cookieStore.get(httpUrl.host());
                        //获取需要提交的CookieStr
                        StringBuilder cookieStr = new StringBuilder();
                        //将Cookie数据弄成一行
                        if (cookies != null) {
                            for (int i = 0; i < cookies.size(); i++) {
                                cookieStr.append(cookies.get(i).name()).append("=").append(cookies.get(i).value() + ";");
                            }
                            SPUtils.getInstance().put("okhttpCookies", cookieStr.toString());
//                            Log.e("bbs:", cookieStr.toString());
                        }
                        return cookies != null ? cookies : new ArrayList<Cookie>();
                    }
                })
////                .addNetworkInterceptor(new CacheControlInterceptor())
//                .followRedirects(false)
//                .addInterceptor(new RedirectInterceptor()) //todo
//                .cache(new Cache(httpCacheDirectory, 300 * 1024 * 1024))//10 * 1024 * 1024  10M
//                .addNetworkInterceptor(new CaheInterceptor(mContext))
                .addInterceptor(loggingInterceptor)//log日志拦截
//                .addInterceptor(new CaheInterceptor(mContext))//缓存
                .connectTimeout(DEFAULT_TIMEOUT, SECONDS)
                .readTimeout(DEFAULT_TIMEOUT, SECONDS)
                .writeTimeout(DEFAULT_TIMEOUT, SECONDS);

//        builder.followRedirects(true);
        retrofit = new Retrofit.Builder()
                .client(builder.build())
//                .addConverterFactory(ScalarsConverterFactory.create())
//                .addConverterFactory(GsonConverterFactory.create())//JSON解析返回JSON字符串，JSON字符串处理
                .addConverterFactory(ResponseConvertFactory.create()) // 对http请求结果进行统一的预处理 GosnResponseBodyConvert，Bean对象处理
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .baseUrl(HttpApi.BASE_URL)
                .build();
        ZztrService = retrofit.create(ZztrService.class);


    }


    //在访问HttpMethods时创建单例
    private static class SingletonHolder {
        private static final HttpMethods INSTANCE = new HttpMethods();
    }

    //获取单例
    public static HttpMethods getInstance(Context context) {
        if (context != null) {
            mContext = context;
        }
        return SingletonHolder.INSTANCE;
    }


    private <T> void toSubscribe(Observable<T> o, Subscriber<T> s) {
        o.subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(s);
    }

    /*-------------------------------------------------------数据请求方法------------------------------------------------*/


    //-------------------首页-------------------
    //首页-列表
    public void indexList(ProgressSubscriber<HttpResult<List<IndexBean>>> subscriber, String countyCode) {
        initCommonParameter();
        map.put("countyCode", countyCode);
        Observable observable = ZztrService.indexList(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void hcstPagelist(ProgressSubscriber<HttpResult<HeiChouShuiTiIndexBean>> subscriber, int pageNo, int pageSize, String countyCode, String name) {
        initCommonParameter();
        map.put("pageNo", pageNo);
        map.put("pageSize", pageSize);
        map.put("countyCode", countyCode);
        map.put("name", name);
        Observable observable = ZztrService.hcstPagelist(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void wsclssPagelist(ProgressSubscriber<HttpResult<WsclssIndexBean>> subscriber, int pageNo, int pageSize, String countyCode, String name) {
        initCommonParameter();
        map.put("pageNo", pageNo);
        map.put("pageSize", pageSize);
        map.put("countyCode", countyCode);
        map.put("name", name);
        Observable observable = ZztrService.wsclssPagelist(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void rcrwPagelist(ProgressSubscriber<HttpResult<RcrwPagelistBean>> subscriber, int pageNo, int pageSize, String pid, String rwmc) {
        initCommonParameter();
        map.put("pageNo", pageNo);
        map.put("pageSize", pageSize);
        map.put("pid", pid);
        map.put("rwmc", rwmc);
        Observable observable = ZztrService.rcrwPagelist(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void addRcrw(ProgressSubscriber<HttpResult<String>> subscriber, HashMap<String, Object> mapNew) {
        initCommonParameter();
        RequestBody body = getBody(mapNew);
        Observable observable = ZztrService.addRcrw(authorization, body);
        toSubscribe(observable, subscriber);
    }

    public void editRcrw(ProgressSubscriber<HttpResult<String>> subscriber, HashMap<String, Object> mapNew) {
        initCommonParameter();
        RequestBody body = getBody(mapNew);
        Observable observable = ZztrService.editRcrw(authorization, body);
        toSubscribe(observable, subscriber);
    }

    public void editHcst(ProgressSubscriber<HttpResult<String>> subscriber, HashMap<String, Object> mapNew) {
        initCommonParameter();
        RequestBody body = getBody(mapNew);
        Observable observable = ZztrService.editHcst(authorization, body);
        toSubscribe(observable, subscriber);
    }

    public void editWsclss(ProgressSubscriber<HttpResult<String>> subscriber, HashMap<String, Object> mapNew) {
        initCommonParameter();
        RequestBody body = getBody(mapNew);
        Observable observable = ZztrService.editWsclss(authorization, body);
        toSubscribe(observable, subscriber);
    }

    public void zdjgdwPagelist(ProgressSubscriber<HttpResult<ZdjgdwPagelistBean>> subscriber, int pageNo, int pageSize, String countyCode, String name) {
        initCommonParameter();
        map.put("pageNo", pageNo);
        map.put("pageSize", pageSize);
        map.put("countyCode", countyCode);
        map.put("name", name);
        Observable observable = ZztrService.zdjgdwPagelist(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void zdjgdwJdxxList(ProgressSubscriber<HttpResult<ZdjgdwJdxxBean>> subscriber, int pageNo, int pageSize, String countyCode, String startTime, String endTime) {
        initCommonParameter();
        map.put("pageNo", pageNo);
        map.put("pageSize", pageSize);
        map.put("trzdwryJgdwmlId", countyCode);
        map.put("startTime", startTime);
        map.put("endTime", endTime);
        Observable observable = ZztrService.zdjgdwJdxxList(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void zdjgdwJdxxAdd(ProgressSubscriber<HttpResult<String>> subscriber, HashMap<String, Object> mapNew) {
        initCommonParameter();
        RequestBody body = getBody(mapNew);
        Observable observable = ZztrService.zdjgdwJdxxAdd(authorization, body);
        toSubscribe(observable, subscriber);
    }

    public void zdjgdwJdxxEdit(ProgressSubscriber<HttpResult<String>> subscriber, HashMap<String, Object> mapNew) {
        initCommonParameter();
        RequestBody body = getBody(mapNew);
        Observable observable = ZztrService.zdjgdwJdxxEdit(authorization, body);
        toSubscribe(observable, subscriber);
    }

    public void wrdkPagelist(ProgressSubscriber<HttpResult<WrdkPageListBean>> subscriber, int pageNo, int pageSize, String countyCode, String name) {
        initCommonParameter();
        map.put("pageNo", pageNo);
        map.put("pageSize", pageSize);
        map.put("countyCode", countyCode);
        map.put("name", name);
        Observable observable = ZztrService.wrdkPagelist(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void editZdjgdw(ProgressSubscriber<HttpResult<String>> subscriber, HashMap<String, Object> mapNew) {
        initCommonParameter();
        RequestBody body = getBody(mapNew);
        Observable observable = ZztrService.editZdjgdw(authorization, body);
        toSubscribe(observable, subscriber);
    }

    public void jcjPagelist(ProgressSubscriber<HttpResult<JcjPagelistBean>> subscriber, int pageNo, int pageSize, String countyCode, String name) {
        initCommonParameter();
        map.put("pageNo", pageNo);
        map.put("pageSize", pageSize);
        map.put("countyCode", countyCode);
        map.put("name", name);
        Observable observable = ZztrService.jcjPagelist(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void bfjPagelist(ProgressSubscriber<HttpResult<BfjPageListBean>> subscriber, int pageNo, int pageSize, String countyCode, String name) {
        initCommonParameter();
        map.put("pageNo", pageNo);
        map.put("pageSize", pageSize);
        map.put("countyCode", countyCode);
        map.put("name", name);
        Observable observable = ZztrService.bfjPagelist(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void editJcj(ProgressSubscriber<HttpResult<String>> subscriber, HashMap<String, Object> mapNew) {
        initCommonParameter();
        RequestBody body = getBody(mapNew);
        Observable observable = ZztrService.editJcj(authorization, body);
        toSubscribe(observable, subscriber);
    }

    public void xzbmAreaList(ProgressSubscriber<HttpResult<List<ChoosePopItemBean>>> subscriber) {
        initCommonParameter();
        map.put("_t", "1656320410");
        map.put("parentCode", "410100000000");
        Observable observable = ZztrService.xzbmAreaList(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void getSyqdlx(ProgressSubscriber<HttpResult<List<String>>> subscriber) {
        initCommonParameter();
        Observable observable = ZztrService.getSyqdlx(authorization);
        toSubscribe(observable, subscriber);
    }

    public void getSyqdmc(ProgressSubscriber<HttpResult<List<String>>> subscriber, HashMap<String, Object> mapNew) {
        initCommonParameter();
        RequestBody body = getBody(mapNew);
        Observable observable = ZztrService.getSyqdmc(authorization, body);
        toSubscribe(observable, subscriber);
    }

    //-------------------地图-------------------
    public void mapBfj(ProgressSubscriber<HttpResult<List<MapBfjListBean>>> subscriber, String mc) {
        initCommonParameter();
        map.put("mc", mc);
        Observable observable = ZztrService.mapBfj(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void mapJcj(ProgressSubscriber<HttpResult<List<MapJcjListBean>>> subscriber, String mc) {
        initCommonParameter();
        map.put("mc", mc);
        Observable observable = ZztrService.mapJcj(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void mapKhdw(ProgressSubscriber<HttpResult<List<MapKhdwListBean>>> subscriber, String mc) {
        initCommonParameter();
        map.put("mc", mc);
        Observable observable = ZztrService.mapKhdw(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void mapZdjgdw(ProgressSubscriber<HttpResult<List<MapZdjgdwListBean>>> subscriber, String mc) {
        initCommonParameter();
        map.put("mc", mc);
        Observable observable = ZztrService.mapZdjgdw(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void mapWrdk(ProgressSubscriber<HttpResult<List<MapWrdkBean>>> subscriber, String mc) {
        initCommonParameter();
        map.put("mc", mc);
        Observable observable = ZztrService.mapWrdk(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void getGISWrdkInfo(ProgressSubscriber<HttpResult<List<WrdkInfoBean>>> subscriber, String wrdkbm) {
        initCommonParameter();
        map.put("wrdkbm", wrdkbm);
        Observable observable = ZztrService.getGISWrdkInfo(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void mapHcst(ProgressSubscriber<HttpResult<List<MapHcstListBean>>> subscriber, String mc) {
        initCommonParameter();
        map.put("mc", mc);
        Observable observable = ZztrService.mapHcst(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void mapNcshwsclss(ProgressSubscriber<HttpResult<List<MapNcshwsclssListBean>>> subscriber, String mc) {
        initCommonParameter();
        map.put("mc", mc);
        Observable observable = ZztrService.mapNcshwsclss(authorization, map);
        toSubscribe(observable, subscriber);
    }

    //-------------------通用-------------------
    public void queryPageHcstList(ProgressSubscriber<HttpResult<BlackWaterTasksBean>> subscriber, int pageNo, int pageSize, String searchText, int isKfbj) {
        initCommonParameter();
        map.put("pageNo", pageNo);
        map.put("pageSize", pageSize);
        map.put("stmc", searchText);
        map.put("isKfbj", isKfbj);
        Observable observable = ZztrService.queryPageHcstList(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void queryPageShwsclList(ProgressSubscriber<HttpResult<SewageFacilitiesTasksBean>> subscriber, int pageNo, int pageSize, String searchText, int isKfbj) {
        initCommonParameter();
        map.put("pageNo", pageNo);
        map.put("pageSize", pageSize);
        map.put("sbmc", searchText);
        map.put("isKfbj", isKfbj);
        Observable observable = ZztrService.queryPageShwsclList(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void queryById(ProgressSubscriber<HttpResult<TaskDetailSpecialBean>> subscriber, String id) {
        initCommonParameter();
        map.put("id", id);
        Observable observable = ZztrService.queryById(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void saveZxrwgl(ProgressSubscriber<HttpResult<String>> subscriber, HashMap<String, Object> mapNew) {
        initCommonParameter();
        RequestBody body = getBody(mapNew);
        Observable observable = ZztrService.saveZxrwgl(authorization, body);
        toSubscribe(observable, subscriber);
    }

    public void commitZxrwgl(ProgressSubscriber<HttpResult<String>> subscriber, HashMap<String, Object> mapNew) {
        initCommonParameter();
        RequestBody body = getBody(mapNew);
        Observable observable = ZztrService.commitZxrwgl(authorization, body);
        toSubscribe(observable, subscriber);
    }

    public void getTreeList(ProgressSubscriber<HttpResult<List<GetTreeListBean>>> subscriber) {
        initCommonParameter();
        Observable observable = ZztrService.getTreeList(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void wdPageList(ProgressSubscriber<HttpResult<WdPageListBean>> subscriber, int pageNo, int pageSize, String id, String name) {
        initCommonParameter();
        map.put("pageNo", pageNo);
        map.put("pageSize", pageSize);
        map.put("ownerId", id);
        map.put("name", name);
        Observable observable = ZztrService.wdPageList(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void createUser(ProgressSubscriber<HttpResult<CreateUserBean>> subscriber) {
//        initCommonParameter();
//        Observable observable = ZztrService.createUser(authorization, map);
//        toSubscribe(observable, subscriber);

        initCommonParameter();
        Observable observable = ZztrService.createUser(authorization);
        toSubscribe(observable, subscriber);
    }

    public void createSphy(ProgressSubscriber<HttpResult<MeetingBean>> subscriber, HashMap<String, Object> mapNew) {
        initCommonParameter();
        RequestBody body = getBody(mapNew);
        Observable observable = ZztrService.createSphy(authorization, body);
        toSubscribe(observable, subscriber);
    }

    public void jrhy(ProgressSubscriber<HttpResult<String>> subscriber, HashMap<String, Object> mapNew) {
        initCommonParameter();
        RequestBody body = getBody(mapNew);
        Observable observable = ZztrService.jrhy(authorization, body);
        toSubscribe(observable, subscriber);
    }

    public void closeHy(ProgressSubscriber<HttpResult<String>> subscriber, HashMap<String, Object> mapNew) {
        initCommonParameter();
        RequestBody body = getBody(mapNew);
        Observable observable = ZztrService.closeHy(authorization, body);
        toSubscribe(observable, subscriber);
    }

    public void sphyPageList(ProgressSubscriber<HttpResult<MeetListBean>> subscriber, int pageNo, int pageSize, int zt) {
        initCommonParameter();
        map.put("pageNo", pageNo);
        map.put("pageSize", pageSize);
        map.put("zt", zt);
        Observable observable = ZztrService.sphyPageList(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void wrwxjPagelist(ProgressSubscriber<HttpResult<WrwxcBean>> subscriber, int pageNo, int pageSize, String wrwlb) {
        initCommonParameter();
        map.put("pageNo", pageNo);
        map.put("pageSize", pageSize);
        map.put("wrwlb", wrwlb);
        Observable observable = ZztrService.wrwxjPagelist(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void addWrwxj(ProgressSubscriber<HttpResult<String>> subscriber, HashMap<String, Object> mapNew) {
        initCommonParameter();
        RequestBody body = getBody(mapNew);
        Observable observable = ZztrService.addWrwxj(authorization, body);
        toSubscribe(observable, subscriber);
    }

    public void editWrwxj(ProgressSubscriber<HttpResult<String>> subscriber, HashMap<String, Object> mapNew) {
        initCommonParameter();
        RequestBody body = getBody(mapNew);
        Observable observable = ZztrService.editWrwxj(authorization, body);
        toSubscribe(observable, subscriber);
    }

    //-------------------我的-------------------

    public void getAppName(ProgressSubscriber<HttpResult<GetAppNameBean>> subscriber) {
        initCommonParameter();
        Observable observable = ZztrService.getAppName();
        toSubscribe(observable, subscriber);
    }

    public void login(ProgressSubscriber<HttpResult<LoginBean>> subscriber, String username, String password, String captcha, String checkKey) {
        initCommonParameter();
        map.put("username", username);
        map.put("password", password);
        map.put("captcha", captcha);
        map.put("checkKey", checkKey);
        RequestBody body = getBody(map);
        Observable observable = ZztrService.login(body);
        toSubscribe(observable, subscriber);
    }

    public void findUserMessage(ProgressSubscriber<HttpResult<MassageBean>> subscriber, int pageNo, int pageSize, String titile, int readFlag) {
        initCommonParameter();
        map.put("pageNo", pageNo);
        map.put("pageSize", pageSize);
        map.put("titile", titile);
        map.put("readFlag", readFlag);
        Observable observable = ZztrService.findUserMessage(authorization, map);
        toSubscribe(observable, subscriber);
    }

    public void messageRead(ProgressSubscriber<HttpResult<String>> subscriber, HashMap<String, Object> mapNew) {
        initCommonParameter();
        RequestBody body = getBody(mapNew);
        Observable observable = ZztrService.messageRead(authorization, body);
        toSubscribe(observable, subscriber);
    }

    public void randomImage(ProgressSubscriber<HttpResult<String>> subscriber, String time) {
        initCommonParameter();
        HashMap<String, Object> map = new HashMap<>();
        map.put("_t", time.substring(0, 10));
        Observable observable = ZztrService.randomImage(time, map);
        toSubscribe(observable, subscriber);
    }

    //-------------------公共接口-------------------
    //上传图片
    public void uploadftp(ProgressSubscriber<HttpResult<FileBean>> subscriber, File file) {
        initCommonParameter();
        RequestBody body = getMultipartBody(file);
        Observable observable = ZztrService.uploadftp(authorization, body);
        toSubscribe(observable, subscriber);
    }

    public MultipartBody getMultipartBody(File file) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
        Date date = new Date(System.currentTimeMillis());
        MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);
//        builder.addFormDataPart("file", file.getName(), RequestBody.create(MEDIA_TYPE_JPG, file));
        builder.addFormDataPart("file", file.getName(), RequestBody.create(MEDIA_TYPE_FILE, file));
        builder.addFormDataPart("biz", "tmp/" + simpleDateFormat.format(date));

        MultipartBody body = builder.build();
        return body;
    }

    /**
     * 初始化公共请求参数
     */
    private void initCommonParameter() {
        authorization = SPUtils.getInstance().getString("authorization", "");
        map = new HashMap<>();
        //公共参数
    }


    /**
     * map集合生成post请求体RequestBody（含sign）
     *
     * @return 返回post请求的请求体
     */
    private RequestBody getBody(Map<String, Object> map) {
        Gson gson = new Gson();
        String jsonStr = gson.toJson(map);
        RequestBody body = RequestBody.create(JSON, jsonStr);
        return body;
    }

}
