package com.casic.dcms.utils.retrofit;

import android.util.Log;

import com.casic.dcms.bean.ActionResultBean;
import com.casic.dcms.bean.AlarmDataBean;
import com.casic.dcms.bean.AuthorizeOrAdjustBean;
import com.casic.dcms.bean.CaseCheckBean;
import com.casic.dcms.bean.CaseDetailBean;
import com.casic.dcms.bean.CaseHandleBean;
import com.casic.dcms.bean.CaseHandledBean;
import com.casic.dcms.bean.CaseLargeClassBean;
import com.casic.dcms.bean.CaseListResultBean;
import com.casic.dcms.bean.CaseNextNodeBean;
import com.casic.dcms.bean.CaseProcessBean;
import com.casic.dcms.bean.CaseSmallClassBean;
import com.casic.dcms.bean.CaseStatusBean;
import com.casic.dcms.bean.CaseVerifyBean;
import com.casic.dcms.bean.CleanRecordBean;
import com.casic.dcms.bean.ComSentenceBean;
import com.casic.dcms.bean.DelayedOrPostBean;
import com.casic.dcms.bean.DeptTreeBean;
import com.casic.dcms.bean.EventSourceBean;
import com.casic.dcms.bean.HighEventBean;
import com.casic.dcms.bean.HomePageBean;
import com.casic.dcms.bean.LightListBean;
import com.casic.dcms.bean.LightMapBean;
import com.casic.dcms.bean.LoginResultBean;
import com.casic.dcms.bean.MaintainContentBean;
import com.casic.dcms.bean.MaintainRecordBean;
import com.casic.dcms.bean.MapConfigBean;
import com.casic.dcms.bean.NewVersionBean;
import com.casic.dcms.bean.OnlinePersonBean;
import com.casic.dcms.bean.OvertimeCaseBean;
import com.casic.dcms.bean.PackageOrDeptBean;
import com.casic.dcms.bean.PhoneBookBean;
import com.casic.dcms.bean.ProcessPersonBean;
import com.casic.dcms.bean.PublicKeyBean;
import com.casic.dcms.bean.ToiletListBean;
import com.casic.dcms.bean.UrgentCaseBean;
import com.casic.dcms.bean.UserBean;
import com.casic.dcms.bean.WellDetailBean;
import com.casic.dcms.bean.WellListBean;
import com.casic.dcms.utils.AuthenticationHelper;
import com.casic.dcms.utils.Constant;
import com.casic.dcms.utils.SaveKeyValues;

import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.util.List;
import java.util.concurrent.TimeUnit;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import rx.Observable;

public class RetrofitServiceManager {
    private static final String TAG = "RetrofitServiceManager";

    private static Retrofit createRetrofit() {
        String ip = (String) SaveKeyValues.getValue(Constant.IP_KEY, "http://111.198.10.15:11414");
//        String ip = (String) SaveKeyValues.getValue(Constant.IP_KEY, "http://223.82.47.232:11401");
        return new Retrofit.Builder()
                .baseUrl(ip)
                .addConverterFactory(GsonConverterFactory.create())//Gson转换器
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .client(createOKHttpClient())//log拦截器
                .build();
    }

    private static OkHttpClient createOKHttpClient() {
        //日志显示级别
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
            @Override
            public void log(@NotNull String message) {
                Log.d(TAG, "log: " + message);
            }
        });
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient.Builder builder = new OkHttpClient.Builder()
                .readTimeout(Constant.HTTP_TIMEOUT, TimeUnit.SECONDS)
                .connectTimeout(Constant.HTTP_TIMEOUT, TimeUnit.SECONDS)
                .writeTimeout(Constant.HTTP_TIMEOUT, TimeUnit.SECONDS);
        return builder.addInterceptor(interceptor).build();
    }

    /**
     * 验证PublicKey
     */
    public static Observable<PublicKeyBean> authenticate() {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainPublicKey();
    }

    /**
     * 登录并获取Token
     */
    public static Observable<LoginResultBean> getTokenData(String username, String key) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.login(username, key);
    }

    /**
     * 获取用户信息
     */
    public static Observable<UserBean> getUserData() {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainUser(AuthenticationHelper.getToken());
    }

    /**
     * 获取地图地址
     */
    public static Observable<MapConfigBean> getMapConfig() {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainMapConfig(AuthenticationHelper.getToken());
    }

    /**
     * 大类列表查询
     */
    public static Observable<CaseLargeClassBean> getCaseLargeClass(String eorc) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainLargeClass(AuthenticationHelper.getToken(), eorc);
    }

    /**
     * 大类列表查询
     */
    public static Observable<CaseSmallClassBean> getCaseSmallClass(String eorc, String typeId) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainLargeClass(AuthenticationHelper.getToken(), eorc, typeId);
    }

    /**
     * 提交案卷
     */
    public static Observable<ActionResultBean> getSubmitCaseResult(String isNeedVerify, String isNeedRevisit,
                                                                   String longitude, String latitude,
                                                                   String source, String caseLevel,
                                                                   String eorc, String casetypeCode,
                                                                   String casetypeDetailCode, String areaCode,
                                                                   String streetCode, String communityCode,
                                                                   String gridId, String description,
                                                                   String fieldintro, String fileIdVerify,
                                                                   String audioIdVerify, String videoIdVerify,
                                                                   int bzhours, int bzminis) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.submitCase(AuthenticationHelper.getToken(), isNeedVerify, isNeedRevisit, longitude,
                latitude, source, caseLevel, eorc, casetypeCode, casetypeDetailCode, areaCode, streetCode,
                communityCode, gridId, description, fieldintro, fileIdVerify, audioIdVerify, videoIdVerify,
                bzhours, bzminis);
    }

    /**
     * 退出登录
     */
    public static Observable<ActionResultBean> getLoginOutResult() {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.loginOut(AuthenticationHelper.getToken());
    }

    /**
     * 修改密码
     */
    public static Observable<ActionResultBean> getChangePasswordResult(String oldPwd, String newPwd) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.changePassword(AuthenticationHelper.getToken(), oldPwd, newPwd);
    }

    /**
     * 获取部门树
     */
    public static Observable<DeptTreeBean> getDeptTreeResult(String pid) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainDeptTree(AuthenticationHelper.getToken(), pid);
    }

    /**
     * 获取通讯录
     */
    public static Observable<PhoneBookBean> getPhoneBookResult(String deptid) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainPhoneBook(AuthenticationHelper.getToken(), deptid);
    }

    /**
     * 获取高发问题
     */
    public static Observable<HighEventBean> getHighEventResult(String begTime, String endTime) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainHighEvent(AuthenticationHelper.getToken(), begTime, endTime);
    }

    /**
     * 获取问题来源
     */
    public static Observable<EventSourceBean> getEventSourceResult(String begTime, String endTime) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainEventSource(AuthenticationHelper.getToken(), begTime, endTime);
    }

    /**
     * 获取案件状态
     */
    public static Observable<CaseStatusBean> getCaseStatusResult() {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainCaseStatus(AuthenticationHelper.getToken());
    }

    /**
     * 根据时间查询案卷列表
     */
    public static Observable<CaseListResultBean> getCaseListResult(String eorc, String casetypeCode,
                                                                   String casetypeDetailCode, String caseState,
                                                                   String registerTimeBegin, String registerTimeEnd,
                                                                   String isShopCase, int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainCaseList(AuthenticationHelper.getToken(), eorc, casetypeCode, casetypeDetailCode,
                caseState, registerTimeBegin, registerTimeEnd, isShopCase, Constant.PAGE_LIMIT, offset);
    }

    /**
     * 获取案件详情
     */
    public static Observable<CaseDetailBean> getCaseDetailResult(String id) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainCaseDetail(AuthenticationHelper.getToken(), id);
    }

    /**
     * 获取案件流转记录
     */
    public static Observable<CaseProcessBean> getCaseProcessResult(String processId) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainCaseProcess(AuthenticationHelper.getToken(), processId);
    }

    /**
     * 更新版本
     */
    public static Observable<NewVersionBean> getVersionResult() {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainVersion(AuthenticationHelper.getToken());
    }

    /**
     * 获取核实待办案卷
     */
    public static Observable<CaseVerifyBean> getCaseVerifyListResult(int limit, int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainCaseVerifyList(AuthenticationHelper.getToken(), limit, offset);
    }

    /**
     * 获取核实已办案卷
     */
    public static Observable<CaseVerifyBean> getCaseVerifiedListResult(int limit, int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainCaseVerifiedList(AuthenticationHelper.getToken(), limit, offset);
    }

    /**
     * 获取核查待办案卷
     */
    public static Observable<CaseCheckBean> getCaseCheckListResult(int limit, int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainCaseCheckList(AuthenticationHelper.getToken(), limit, offset);
    }

    /**
     * 获取核查已办案卷
     */
    public static Observable<CaseCheckBean> getCaseCheckedListResult(int limit, int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainCaseCheckedList(AuthenticationHelper.getToken(), limit, offset);
    }

    /**
     * 上传案卷图片
     * <p>
     * 系统路径static拼接图片返回路径
     * http://xx.com/static/2019-10/8050891248624f2bbefedcb196ce89cb.jpeg
     */
    public static Observable<ActionResultBean> getImageUploadResult(File image) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        RequestBody requestBody = RequestBody.create(MediaType.parse("image/png"), image);
        MultipartBody.Part imagePart = MultipartBody.Part.createFormData("file", image.getName(), requestBody);
        return service.uploadImage(AuthenticationHelper.getToken(), imagePart);
    }

    /**
     * 上传案卷音频
     */
    public static Observable<ActionResultBean> getAudioUploadResult(File audio) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        RequestBody requestBody = RequestBody.create(MediaType.parse("audio/m4a"), audio);
        MultipartBody.Part imagePart = MultipartBody.Part.createFormData("file", audio.getName(), requestBody);
        return service.uploadAudio(AuthenticationHelper.getToken(), imagePart);
    }

    /**
     * 上传案卷视频
     */
    public static Observable<ActionResultBean> getVideoUploadResult(File video) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        RequestBody requestBody = RequestBody.create(MediaType.parse("video/mp4"), video);
        MultipartBody.Part imagePart = MultipartBody.Part.createFormData("file", video.getName(), requestBody);
        return service.uploadVideo(AuthenticationHelper.getToken(), imagePart);
    }

    /**
     * 五包上报
     */
    public static Observable<ActionResultBean> getSubmitShopCaseResult(String isNeedVerify, String isNeedRevisit,
                                                                       String longitude, String latitude,
                                                                       String source, String caseLevel,
                                                                       String areaCode, String streetCode,
                                                                       String communityCode, String gridId,
                                                                       String description, String fieldintro,
                                                                       String fileIdVerify, int bzhours,
                                                                       int bzminis, String shopId,
                                                                       String shopkeeperName, String shopPhone) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.submitShopCase(AuthenticationHelper.getToken(), isNeedVerify, isNeedRevisit,
                longitude, latitude, source, caseLevel, areaCode, streetCode, communityCode, gridId,
                description, fieldintro, fileIdVerify, bzhours, bzminis, shopId, shopkeeperName, shopPhone);
    }

    /**
     * 案卷处理分页查询，去掉三包类型的案卷
     */
    public static Observable<CaseHandleBean> getCaseHandleListResult(String isOvertime, String isEmergent,
                                                                     int limit, int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainHandleCase(AuthenticationHelper.getToken(), isOvertime, isEmergent,
                "0", limit, offset);
    }

    /**
     * 处理已办分页查询
     */
    public static Observable<CaseHandledBean> getCaseHandledListResult(int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainHandledCase(AuthenticationHelper.getToken(), Constant.PAGE_LIMIT, offset);
    }

    /**
     * 紧急案件分页查询
     */
    public static Observable<UrgentCaseBean> getUrgentCaseListResult(String isSupervise, int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainUrgentCase(AuthenticationHelper.getToken(), isSupervise,
                Constant.PAGE_LIMIT, offset);
    }

    /**
     * 超时案件分页查询
     */
    public static Observable<OvertimeCaseBean> getOvertimeCaseListResult(String isSupervise, int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainOvertimeCase(AuthenticationHelper.getToken(), isSupervise,
                Constant.PAGE_LIMIT, offset);
    }

    /**
     * 在线人员查询
     */
    public static Observable<OnlinePersonBean> getOnlinePersonResult(String deptid, String roleTips, String isOnLine) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainOnlinePerson(AuthenticationHelper.getToken(), deptid, roleTips, isOnLine);
    }

    /**
     * 设备定位信息上传
     */
    public static Observable<ActionResultBean> getPositionUploadResult(String imei, String positionLat, String positionLng) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.uploadDevicePosition(AuthenticationHelper.getToken(), imei, positionLat, positionLng);
    }

    /**
     * 获取流转下级节点
     *
     * @param caseState 字典值
     */
    public static Observable<CaseNextNodeBean> getProcessNextNodeResult(String caseState) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainProcessNextNode(AuthenticationHelper.getToken(), caseState);
    }

    /**
     * 获取常见语句
     */
    public static Observable<ComSentenceBean> getCommonSentenceResult() {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainCommonSentence(AuthenticationHelper.getToken());
    }

    /**
     * 案卷处理
     * <p>
     * 案卷核实-仅添加核实意见/核实情况/核实图片
     */
    public static Observable<ActionResultBean> getHandleCaseResult(String processId, String bizId,
                                                                   String currState, String changeState,
                                                                   String remarks, String fileId) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.handleCase(AuthenticationHelper.getToken(), processId, bizId, currState,
                changeState, remarks, fileId);
    }

    /**
     * 案卷处理
     * <p>
     * 超时案卷
     */
    public static Observable<ActionResultBean> getHandleCaseResult(String processId, String bizId,
                                                                   String currState, String changeState,
                                                                   String remarks, String fileId,
                                                                   String approvalResult) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.handleCase(AuthenticationHelper.getToken(), processId, bizId, currState,
                changeState, remarks, fileId, approvalResult);
    }

    /**
     * 案卷处理
     * <p>
     * 案卷核实-热线电话和微信公众号提交的数据，需要补全信息
     * 案卷核查
     */
    public static Observable<ActionResultBean> getHandleCaseResult(String processId, String bizId,
                                                                   String currState, String changeState,
                                                                   String remarks, String fileId,
                                                                   String eorc, String casetypeCode,
                                                                   String casetypeDetailCode, String lng,
                                                                   String lat, String caseLevel,
                                                                   String areaCode, String streetCode,
                                                                   String communityCode, String gridId,
                                                                   String fieldintro) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.handleCase(AuthenticationHelper.getToken(), processId, bizId, currState,
                changeState, remarks, fileId, eorc, casetypeCode, casetypeDetailCode, lng, lat,
                caseLevel, areaCode, streetCode, communityCode, gridId, fieldintro);
    }

    /**
     * 案卷处理
     * <p>
     * 派遣员处理
     */
    public static Observable<ActionResultBean> getDispatcherHandleCaseResult(String processId, String bizId,
                                                                             String currState, String changeState,
                                                                             String remarks, String operationKey,
                                                                             String taskUserId) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.dispatcherHandleCase(AuthenticationHelper.getToken(), processId, bizId, currState,
                changeState, remarks, operationKey, taskUserId);
    }

    /**
     * 紧急要件-超时督办
     */
    public static Observable<ActionResultBean> getUpdateSuperviseResult(String id, String superviseRemarks) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.updateSuperviseRemarks(AuthenticationHelper.getToken(), id, superviseRemarks);
    }

    /**
     * 获取首页九宫格数据
     */
    public static Observable<HomePageBean> getHomePageResult(String resourceType) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainHomePage(AuthenticationHelper.getToken(), resourceType);
    }

    /**
     * 个推推送cid注册
     */
    public static Observable<ActionResultBean> getRegisterResult(String clientId) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.registerPush(AuthenticationHelper.getToken(), clientId);
    }

    /**
     * 公厕列表
     */
    public static Observable<ToiletListBean> getToiletListResult() {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainToiletList(AuthenticationHelper.getToken());
    }

    /**
     * 公厕打扫签到
     */
    public static Observable<ActionResultBean> getCleanToiletResult(String toiletId, String userId,
                                                                    String lng, String lat,
                                                                    String startTime, String endTime,
                                                                    String photo, String workContent) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.cleanToilet(AuthenticationHelper.getToken(), toiletId, userId, lng, lat,
                startTime, endTime, photo, workContent);
    }

    /**
     * 公厕打扫记录
     */
    public static Observable<CleanRecordBean> getCleanRecordResult(String userId, String keywords,
                                                                   String beginDate, String endDate,
                                                                   int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainToiletCleanRecord(AuthenticationHelper.getToken(), userId, keywords,
                beginDate, endDate, Constant.PAGE_LIMIT, offset);
    }

    /**
     * 三包待办
     */
    public static Observable<PackageOrDeptBean> getPackageWorkListResult(String isShop, int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainPackageWorkListPage(AuthenticationHelper.getToken(), isShop,
                Constant.PAGE_LIMIT, offset);
    }

    /**
     * 三包已办
     */
    public static Observable<PackageOrDeptBean> getCompletedListResult(String isShop, int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainCompletedListPage(AuthenticationHelper.getToken(), isShop,
                Constant.PAGE_LIMIT, offset);
    }

    /**
     * 三包处罚
     */
    public static Observable<ActionResultBean> getHandlePackageResult(String id, String punishType,
                                                                      String punishRemarks, String punishTime,
                                                                      String punishImage) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.handlePackageCase(AuthenticationHelper.getToken(), id, punishType, punishRemarks,
                punishTime, punishImage);
    }

    /**
     * 商铺变更
     */
    public static Observable<ActionResultBean> getShopChangeResult(String merchantId, String merchantName,
                                                                   String contactName, String contactPhone,
                                                                   String images) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.changeShopInfo(AuthenticationHelper.getToken(), merchantId, "1",
                merchantName, contactName, contactPhone, images, "1");
    }

    /**
     * 二级派遣员待办案卷
     */
    public static Observable<PackageOrDeptBean> getWorkListResult(int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainWorkListPage(AuthenticationHelper.getToken(), Constant.PAGE_LIMIT, offset);
    }

    /**
     * 二级派遣员待处理案卷
     */
    public static Observable<PackageOrDeptBean> getProcessListResult(int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainProcessListPage(AuthenticationHelper.getToken(), Constant.PAGE_LIMIT, offset);
    }

    /**
     * 二级派遣员已办案卷
     */
    public static Observable<PackageOrDeptBean> getCompletedListResult(int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainCompletedListPage(AuthenticationHelper.getToken(), Constant.PAGE_LIMIT, offset);
    }

    /**
     * 二级缓办待处理
     */
    public static Observable<DelayedOrPostBean> getPostponeListResult(int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainPostponeListPage(AuthenticationHelper.getToken(), Constant.PAGE_LIMIT, offset);
    }

    /**
     * 二级延期待处理
     */
    public static Observable<DelayedOrPostBean> getDelayedListResult(int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainDelayedListPage(AuthenticationHelper.getToken(), Constant.PAGE_LIMIT, offset);
    }

    /**
     * 部门授权审核
     */
    public static Observable<AuthorizeOrAdjustBean> getCaseAuthorizeResult(int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainCaseAuthorizeListPage(AuthenticationHelper.getToken(), Constant.PAGE_LIMIT, offset);
    }

    /**
     * 部门调整批示
     */
    public static Observable<AuthorizeOrAdjustBean> getCaseAdjustResult(int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainCaseAdjustListPage(AuthenticationHelper.getToken(), Constant.PAGE_LIMIT, offset);
    }

    /**
     * 获取下级处置员
     */
    public static Observable<ProcessPersonBean> getProcessPersonResult() {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainNextProcessPerson(AuthenticationHelper.getToken(), "process");
    }

    /**
     * 根据养护类型获取养护内容
     */
    public static Observable<MaintainContentBean> getMaintainContentResult(String type) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainMaintainContent(AuthenticationHelper.getToken(), type);
    }

    /**
     * 桥梁新增打卡记录
     */
    public static Observable<ActionResultBean> getAddMaintainRecordResult(String bridgeId, String content,
                                                                          String maintainTime, String personId,
                                                                          String longitude, String latitude,
                                                                          String description) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.addMaintainRecord(AuthenticationHelper.getToken(), bridgeId, content, maintainTime,
                personId, longitude, latitude, description);
    }

    /**
     * 桥梁养护记录
     */
    public static Observable<MaintainRecordBean> getMaintainRecordResult(String startDate, String endDate, int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainMaintainRecord(AuthenticationHelper.getToken(), startDate, endDate, Constant.PAGE_LIMIT,
                offset);
    }

    /**
     * 路灯分页列表
     */
    public static Observable<LightListBean> getLightListResult(int limit, int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainLightList(AuthenticationHelper.getToken(), limit, offset);
    }

    /**
     * 全部路灯
     */
    public static Observable<LightMapBean> getLightListResult() {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainLightList(AuthenticationHelper.getToken());
    }

    /**
     * 路灯详情
     * 因为返回的数据会出现结构不一致的问题，不能用实体类接收改为ResponseBody接收，然后在手动解析
     */
    public static Observable<ResponseBody> getLightDetailResult(String lampId) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainLightDetail(AuthenticationHelper.getToken(), lampId);
    }

    /**
     * 控制路灯开关
     */
    public static Observable<ActionResultBean> getLightControlResult(List<Long> lampIds, String controlType) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.controlStreetLight(AuthenticationHelper.getToken(), lampIds, controlType);
    }

    /**
     * 报警列表
     */
    public static Observable<AlarmDataBean> getAlarmListResult(int limit, int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainAlarmList(AuthenticationHelper.getToken(), "1", limit, offset);
    }

    /**
     * 单个取消报警
     */
    public static Observable<ActionResultBean> getCancelAlarmResult(String id, String jobStatus, String handleMessage) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.cancelAlarm(AuthenticationHelper.getToken(), id, jobStatus, handleMessage);
    }

    /**
     * 一键取消报警
     */
    public static Observable<ActionResultBean> getCancelAlarmResult(String jobStatus, String handleMessage) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.cancelAlarm(AuthenticationHelper.getToken(), jobStatus, handleMessage);
    }

    /**
     * 窨井列表
     */
    public static Observable<WellListBean> getWellListResult(int offset) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainWellList(AuthenticationHelper.getToken(), "wellCode", "asc",
                Constant.PAGE_LIMIT, offset);
    }

    /**
     * 单个撤防/布防
     */
    public static Observable<ActionResultBean> getSingleOptionWellResult(String wellId, String bfzt) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.optionWellStatus(AuthenticationHelper.getToken(), wellId, bfzt);
    }

    /**
     * 一键撤防/布防
     */
    public static Observable<ActionResultBean> getBatchOptionWellResult(String bfzt) {
        Retrofit retrofit = createRetrofit();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.optionWellStatus(AuthenticationHelper.getToken(), bfzt);
    }

    /**
     * 报警窨井详情
     */
    public static Observable<WellDetailBean> getWellDetailResult(String where) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://111.198.10.15:13002")
                .addConverterFactory(GsonConverterFactory.create())//Gson转换器
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .client(createOKHttpClient())//log拦截器
                .build();
        RetrofitService service = retrofit.create(RetrofitService.class);
        return service.obtainWellDetail("json", "4326", "4326", "*",
                true, where);
    }
}
