diff --git a/libraries/tanlulib/build.gradle b/libraries/tanlulib/build.gradle index 3d9ca5d051..9cb0c7210b 100644 --- a/libraries/tanlulib/build.gradle +++ b/libraries/tanlulib/build.gradle @@ -66,6 +66,8 @@ dependencies { implementation rootProject.ext.dependencies.arouter kapt rootProject.ext.dependencies.aroutercompiler + implementation rootProject.ext.dependencies.uploadroadinfo + if (Boolean.valueOf(RELEASE)) { implementation rootProject.ext.dependencies.mogocommons diff --git a/libraries/tanlulib/src/main/java/com/zhidao/roadcondition/service/CarCorderController.kt b/libraries/tanlulib/src/main/java/com/zhidao/roadcondition/service/CarCorderController.kt index 01cf1c4d5b..2f824402d2 100644 --- a/libraries/tanlulib/src/main/java/com/zhidao/roadcondition/service/CarCorderController.kt +++ b/libraries/tanlulib/src/main/java/com/zhidao/roadcondition/service/CarCorderController.kt @@ -3,13 +3,19 @@ package com.zhidao.roadcondition.service import android.text.TextUtils import android.util.Log import com.hw.videoprocessor.VideoProcessor +import com.mogo.cloud.network.BaseData +import com.mogo.cloud.tanlu.api.ITanluUploadCallback +import com.mogo.cloud.tanlu.api.MogoUploadManager +import com.mogo.cloud.tanlu.bean.UploadInfo +import com.mogo.cloud.tanlu.bean.UploadResult import com.mogo.commons.AbsMogoApplication import com.mogo.commons.debug.DebugConfig +import com.mogo.commons.network.Utils import com.mogo.utils.NetworkUtils import com.zhidao.auto.carcorder.callback.TakePhotoCallback import com.zhidao.auto.carcorder.callback.TakeVideoCallback import com.zhidao.auto.carcorder.controller.ZdCarCoderController -import com.zhidao.roadcondition.constant.* +import com.zhidao.roadcondition.constant.STRATEGY_UPLOAD_TYPE_ARRAY import com.zhidao.roadcondition.event.GetImageSuccessEvent import com.zhidao.roadcondition.event.LatLngStickyEventBus import com.zhidao.roadcondition.model.proxy.INFO_TYPE_IMG @@ -127,17 +133,19 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { videoAndThumbMap["video"] = "" videoAndThumbMap["thumb"] = "" - CosStatusController().sendInformationDirectly( - INFO_TYPE_VIDEO, - videoAndThumbMap, - mType, - entity, - mainInfoId, - mLongitude, - mLatitude, - mSpeed, - mFromType - ) +// CosStatusController().sendInformationDirectly( +// INFO_TYPE_VIDEO, +// videoAndThumbMap, +// mType, +// entity, +// mainInfoId, +// mLongitude, +// mLatitude, +// mSpeed, +// mFromType +// ) + + getInfo("", "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, CarCorderController.mainInfoId)?.let { uploadRoadInfo(it) } //地图上打点 taskAsync(3_000) { @@ -168,17 +176,20 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { Log.e(TAG, "onTakePhotoFail -----mType = $mType --- isCustom = $isCustom") //获取图片失败也上报,图片不打点 if (isCustom) { - CosStatusController().sendInformationDirectly( - INFO_TYPE_IMG, - mutableMapOf("pic" to ""), - mType, - entity, - mainInfoId, - mLongitude, - mLatitude, - mSpeed, - mFromType - ) +// CosStatusController().sendInformationDirectly( +// INFO_TYPE_IMG, +// mutableMapOf("pic" to ""), +// mType, +// entity, +// mainInfoId, +// mLongitude, +// mLatitude, +// mSpeed, +// mFromType +// ) + + getInfo("", "", mLongitude, mLatitude, mType, 1.0f, "", "", 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + } } @@ -219,8 +230,13 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { if (!TextUtils.isEmpty(mType)) { Log.d(TAG, "onTakePhotoSuccess mType != null") - CosStatusController().uploadFile(mutableListOf(photoPath as String), entity, mType, mainInfoId, mFromType, mLongitude, - mLatitude, mSpeed) +// CosStatusController().uploadFile(mutableListOf(photoPath as String), entity, mType, mainInfoId, mFromType, mLongitude, +// mLatitude, mSpeed) + + if (photoPath != null) { + getInfo(photoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + } + } else { Log.d(TAG, "onTakePhotoSuccess mType == null") Log.d( @@ -230,32 +246,41 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { if (maxSpeedPic == -1) { if (speed >= (abs(minSpeedPic) / 3.6f)) { Log.d(TAG, "onTakePhotoSuccess abs =" + (abs(minSpeedPic) / 3.6f)) - CosStatusController().uploadFile( - mutableListOf(photoPath as String), - entity, - mType, - mainInfoId, - mFromType, - mLongitude, - mLatitude, - mSpeed - ) +// CosStatusController().uploadFile( +// mutableListOf(photoPath as String), +// entity, +// mType, +// mainInfoId, +// mFromType, +// mLongitude, +// mLatitude, +// mSpeed +// ) + + if (photoPath != null) { + getInfo(photoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + } } } if (minSpeedPic > 0 && maxSpeedPic > 0) { Log.d(TAG, "onTakePhotoSuccess minSpeedPic > 0 -- speed = $speed") if ((speed >= (minSpeedPic / 3.6f)) && speed <= (maxSpeedPic / 3.6f)) { - CosStatusController().uploadFile( - mutableListOf(photoPath as String), - entity, - mType, - mainInfoId, - mFromType, - mLongitude, - mLatitude, - mSpeed - ) +// CosStatusController().uploadFile( +// mutableListOf(photoPath as String), +// entity, +// mType, +// mainInfoId, +// mFromType, +// mLongitude, +// mLatitude, +// mSpeed +// ) + + if (photoPath != null) { + getInfo(photoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 0, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + } + } } } @@ -293,10 +318,14 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { entity?.let { if (it.isCustom) { - compressVideo(videoPath, thumbnailPath, it) +// compressVideo(videoPath, thumbnailPath, it) + getInfo(videoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + } else if (entity.fromType in STRATEGY_UPLOAD_TYPE_ARRAY) { // 属于策略上报 - compressVideo(videoPath, thumbnailPath, it) +// compressVideo(videoPath, thumbnailPath, it) + getInfo(videoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + } else { Log.d( TAG, @@ -306,15 +335,19 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { Log.d(TAG, "onTakeVideoSuccess 111 abs =" + (abs(minSpeedVideo) / 3.6f)) if (speed >= (abs(minSpeedVideo) / 3.6f)) { //获取视频以及缩略图成功,开始上报 - compressVideo(videoPath, thumbnailPath, it) +// compressVideo(videoPath, thumbnailPath, it) + getInfo(videoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } } } if (minSpeedVideo > 0 && maxSpeedVideo > 0) { Log.d(TAG, "onTakeVideoSuccess minSpeedVideo > 0 -- speed = $speed") if ((speed >= (minSpeedVideo / 3.6f)) && speed <= (maxSpeedVideo / 3.6f)) { - compressVideo(videoPath, thumbnailPath, it) +// compressVideo(videoPath, thumbnailPath, it) + getInfo(videoPath, "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + } else { } + } else { } } } @@ -327,34 +360,36 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { //获取视频失败 override fun onTakeVideoFail(camera: Int) { - trackGetVideo(3) - Log.e(TAG, "getVideo onTakeVideoFail") - getVideoFailed?.invoke() - val entity = CustomStatusHandler.pollVideoStatus() - - entity?.let { - InformationUploadController.release(it.id) - Log.e(TAG, "getVideo onTakeVideoFail entity?.isCustom =" + it.isCustom) -// if (it.isCustom) { -// sendGetInfoFailedReceiver(mType) -// } - } +// trackGetVideo(3) +// Log.e(TAG, "getVideo onTakeVideoFail") +// getVideoFailed?.invoke() +// val entity = CustomStatusHandler.pollVideoStatus() +// +// entity?.let { +// InformationUploadController.release(it.id) +// Log.e(TAG, "getVideo onTakeVideoFail entity?.isCustom =" + it.isCustom) +//// if (it.isCustom) { +//// sendGetInfoFailedReceiver(mType) +//// } +// } //失败了,传空地址,发起请求 - videoAndThumbMap["video"] = "" - videoAndThumbMap["thumb"] = "" +// videoAndThumbMap["video"] = "" +// videoAndThumbMap["thumb"] = "" - CosStatusController().sendInformationDirectly( - INFO_TYPE_VIDEO, - videoAndThumbMap, - mType, - entity, - mainInfoId, - mLongitude, - mLatitude, - mSpeed, - mFromType - ) +// CosStatusController().sendInformationDirectly( +// INFO_TYPE_VIDEO, +// videoAndThumbMap, +// mType, +// entity, +// mainInfoId, +// mLongitude, +// mLatitude, +// mSpeed, +// mFromType +// ) + + getInfo("", "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } //地图上打点 taskAsync(3_000) { @@ -369,43 +404,83 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { /** * 压缩视频并且上传 */ - private fun compressVideo(videoPath: String, thumbnailPath: String, entity: TakeEntity) { - Log.d( - TAG, - "outputVideoPath = " + outputVideoPath + ">> videoPath=" + videoPath + " isCustom = ${entity.isCustom}" - ) - val startTime = System.currentTimeMillis() - Thread(Runnable { - try { - VideoProcessor.processor(AbsMogoApplication.getApp().applicationContext) - .input(videoPath) - .output(outputVideoPath) - .removeAudio(true) - .outWidth(1920) - .outHeight(1080) - .bitrate(2000 * 1024) - .frameRate(25) - .process() - Log.d(TAG, "compress cost time =" + (System.currentTimeMillis() - startTime)) - CosStatusController().uploadFile( - mutableListOf(outputVideoPath, thumbnailPath), - entity, - mType, - mainInfoId, - mFromType, - mLongitude, - mLatitude, - mSpeed - ) - //删除压缩前的视频 - deletePicFile(videoPath) - } catch (e: Exception) { - Log.e(TAG, "compressVideo e = $e") - //删除压缩前的视频 - deletePicFile(videoPath) - e.printStackTrace() +// private fun compressVideo(videoPath: String, thumbnailPath: String, entity: TakeEntity) { +// Log.d( +// TAG, +// "outputVideoPath = " + outputVideoPath + ">> videoPath=" + videoPath + " isCustom = ${entity.isCustom}" +// ) +// val startTime = System.currentTimeMillis() +// Thread(Runnable { +// try { +// VideoProcessor.processor(AbsMogoApplication.getApp().applicationContext) +// .input(videoPath) +// .output(outputVideoPath) +// .removeAudio(true) +// .outWidth(1920) +// .outHeight(1080) +// .bitrate(2000 * 1024) +// .frameRate(25) +// .process() +// Log.d(TAG, "compress cost time =" + (System.currentTimeMillis() - startTime)) +// CosStatusController().uploadFile( +// mutableListOf(outputVideoPath, thumbnailPath), +// entity, +// mType, +// mainInfoId, +// mFromType, +// mLongitude, +// mLatitude, +// mSpeed +// ) +// +// //删除压缩前的视频 +// deletePicFile(videoPath) +// } catch (e: Exception) { +// Log.e(TAG, "compressVideo e = $e") +// //删除压缩前的视频 +// deletePicFile(videoPath) +// e.printStackTrace() +// } +// }).start() +// } + + /** + * 上报路况的视频和图片 + */ + fun uploadRoadInfo(info: UploadInfo) { + MogoUploadManager.getInstance(AbsMogoApplication.getApp().applicationContext).uploadInfo(info, object : ITanluUploadCallback { + override fun onSuccess(result: BaseData) { + } - }).start() + + override fun onFailure(code: Int) { + + } + + override fun onError(e: Throwable) { + + } + }) + } + + private fun getInfo(filePath: String, addr: String, lon: Double, lat: Double, poiType: String, + direction: Float, areaCode: String, cityCode: String, type: Int, fromType: String + , mainInfoId: Long): UploadInfo? { + val info = UploadInfo() + info.filePath = filePath + info.addr = addr + info.longitude = lon + info.latitude = lat + info.poiType = poiType + info.direction = direction + info.areaCode = areaCode + info.cityCode = cityCode + info.sn = Utils.getSn() + info.type = type //0为图片, 1为视频 + info.fromType = fromType + info.mainInfoId = mainInfoId + + return info } override fun onTakePhotoCancel(photoType: Int, camera: Int) { @@ -419,17 +494,20 @@ object CarCorderController : TakePhotoCallback, TakeVideoCallback { videoAndThumbMap["video"] = "" videoAndThumbMap["thumb"] = "" - CosStatusController().sendInformationDirectly( - INFO_TYPE_VIDEO, - videoAndThumbMap, - mType, - entity, - mainInfoId, - mLongitude, - mLatitude, - mSpeed, - mFromType - ) +// CosStatusController().sendInformationDirectly( +// INFO_TYPE_VIDEO, +// videoAndThumbMap, +// mType, +// entity, +// mainInfoId, +// mLongitude, +// mLatitude, +// mSpeed, +// mFromType +// ) + + getInfo("", "", mLongitude, mLatitude, mType, 1.0f, "", "", 1, mFromType, mainInfoId)?.let { uploadRoadInfo(it) } + } //获取图片 diff --git a/modules/mogo-module-share/build.gradle b/modules/mogo-module-share/build.gradle index 7b46014173..ff0ca393b8 100644 --- a/modules/mogo-module-share/build.gradle +++ b/modules/mogo-module-share/build.gradle @@ -46,6 +46,7 @@ dependencies { kapt rootProject.ext.dependencies.aroutercompiler implementation rootProject.ext.dependencies.rxjava implementation rootProject.ext.dependencies.rxandroid + implementation rootProject.ext.dependencies.uploadroadinfo if (Boolean.valueOf(RELEASE)) { implementation rootProject.ext.dependencies.mogoutils diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/TanluManager.java b/modules/mogo-module-share/src/main/java/com/mogo/module/share/TanluManager.java index 395a1ea61b..6707683ea8 100644 --- a/modules/mogo-module-share/src/main/java/com/mogo/module/share/TanluManager.java +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/TanluManager.java @@ -287,7 +287,7 @@ public class TanluManager implements IMogoMarkerClickListener, } if (voiceData != null) { - mTanluModelData.queryRodeInfo(voiceData, new RoadInfoCallback() { + mTanluModelData.queryRodeInfo(mContext, mKeywords, voiceData, new RoadInfoCallback() { @Override public void onQueryRoadInfoSuccess(@NotNull List roadInfoList) { if (roadInfoList == null || (roadInfoList != null && roadInfoList.size() <= 0)) { diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/callback/RoadInfoCallback.kt b/modules/mogo-module-share/src/main/java/com/mogo/module/share/callback/RoadInfoCallback.kt index 17b708a5b7..8a1486b276 100644 --- a/modules/mogo-module-share/src/main/java/com/mogo/module/share/callback/RoadInfoCallback.kt +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/callback/RoadInfoCallback.kt @@ -1,6 +1,7 @@ package com.mogo.module.share.callback -import com.mogo.module.common.entity.MarkerExploreWay +import com.mogo.cloud.tanlu.bean.MarkerExploreWay + interface RoadInfoCallback { fun onLocatSuccess(lat: Double, lon: Double) diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/net/TanluModelData.java b/modules/mogo-module-share/src/main/java/com/mogo/module/share/net/TanluModelData.java index 8c113d45fd..ca4d04b41e 100644 --- a/modules/mogo-module-share/src/main/java/com/mogo/module/share/net/TanluModelData.java +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/net/TanluModelData.java @@ -1,7 +1,12 @@ package com.mogo.module.share.net; import android.content.Context; + import com.alibaba.android.arouter.launcher.ARouter; +import com.google.gson.Gson; +import com.mogo.cloud.network.BaseData; +import com.mogo.cloud.tanlu.api.IRoadInfoSearchCallback; +import com.mogo.cloud.tanlu.api.MogoRoadSearchManager; import com.mogo.commons.debug.DebugConfig; import com.mogo.commons.network.ParamsProvider; import com.mogo.commons.network.SubscribeImpl; @@ -27,6 +32,7 @@ import com.mogo.utils.logger.Logger; import com.mogo.utils.network.RequestOptions; import com.mogo.utils.network.utils.GsonUtil; +import java.util.ArrayList; import java.util.Map; import io.reactivex.Observable; @@ -73,111 +79,148 @@ public class TanluModelData { * * @param voiceCmdData 语音提供的语义封装 */ - public void queryRodeInfo(final VoiceCmdData voiceCmdData, final RoadInfoCallback callback) { + public void queryRodeInfo(Context context, String key, final VoiceCmdData voiceCmdData, final RoadInfoCallback callback) { Logger.d(TAG, "queryRodeInfo: " + voiceCmdData); - if (voiceCmdData.isHere()) { - // 搜索附近路况,只需要拿到当前位置信息,就可以请求服务端 - MogoLocation l = TanluServiceManager.getServiceApis().getMapServiceApi().getSingletonLocationClient(mContext).getLastKnowLocation(); - Location location = new Location(l.getLatitude(), l.getLongitude()); - callback.onLocatSuccess(l.getLatitude(), l.getLongitude()); - RoadInfoRequest request; - if (voiceCmdData.getObj().equals(TYPE_NAME_BLOCK)) { - // 拥堵和路况同时查 - request = new RoadInfoRequest(location, new String[]{TANLU_ROAD_CONGESTION_COMPAT, TANLU_ROAD_CURRENT}, false, false); - }else{ - request = new RoadInfoRequest(location, new String[]{voiceCmdData.getType()}, false, false); + + ArrayList list = new ArrayList(); + list.add(voiceCmdData.getType()); + + //北京市朝阳区小黄庄北街2号, 经纬度和地理位置必须有一个 + MogoLocation mogoLocation = TanluServiceManager.getServiceApis().getMapServiceApi().getSingletonLocationClient(mContext).getLastKnowLocation(); + com.mogo.cloud.tanlu.bean.location.Location location = new com.mogo.cloud.tanlu.bean.location.Location(); + location.setLatitude(mogoLocation.getLatitude()); + location.setLongitude(mogoLocation.getLongitude()); + com.mogo.cloud.tanlu.bean.RoadInfoRequest request = new com.mogo.cloud.tanlu.bean.RoadInfoRequest(location, key, list, false, false); + + MogoRoadSearchManager.getInstance(context).init(); + MogoRoadSearchManager.getInstance(context).queryRoadInfo(request, new IRoadInfoSearchCallback() { + @Override + public void onSuccess(BaseData result) { + if (result != null) { + if (result.getResult() != null) { + Logger.d(TAG, "搜索附近路况信息成功: " + result.getResult()); + callback.onQueryRoadInfoSuccess(result.getResult().getData()); + } else { + callback.onQueryRoadInfoFail(result.getMsg(), result.getCode()); + } + } } - Map params = new ParamsProvider.Builder(mContext) - .append("sn", Utils.getSn()) - .append("data", GsonUtil.jsonFromObject(request)) - .build(); + @Override + public void onFailure(int code) { + callback.onQueryRoadInfoFail("", code); + } - mShareApiService.queryRoadInfos(params) - .subscribeOn(Schedulers.io()) - .observeOn(AndroidSchedulers.mainThread()) - .subscribe(new SubscribeImpl>(RequestOptions.create(mContext)) { - @Override - public void onError(Throwable e) { - super.onError(e); - } + @Override + public void onError(Throwable e) { - @Override - public void onSuccess(BaseDataCompat o) { - super.onSuccess(o); - Logger.d(TAG, "搜索附近路况信息成功: " + o); - callback.onQueryRoadInfoSuccess(o.getResult().getData()); - Logger.d(TAG, "搜索附近路况信息成功2: " + o); - } + } + }); - @Override - public void onError(String message, int code) { - super.onError(message, code); - callback.onQueryRoadInfoFail(message, code); - } - }); - } else { - // 查询的不是附近的信息,所以需要查询一下目标地址的经纬度,然后再请求服务端 - Observable.create(new ObservableOnSubscribe() { - @Override - public void subscribe(ObservableEmitter emitter) throws Exception { - // 根据传入的地址,转成经纬度 - IMogoMapService mapService = TanluServiceManager.getServiceApis().getMapServiceApi(); - String cityCode = mapService.getSingletonLocationClient(mContext).getLastKnowLocation().getCityCode(); - MogoPoiSearchQuery poiSearchQuery = new MogoPoiSearchQuery(voiceCmdData.getLocation(), "", cityCode); - IMogoPoiSearch poiSearch = mapService.getPoiSearch(mContext, poiSearchQuery); - MogoPoiResult result = poiSearch.searchPOI(); - if (result != null && result.getPois() != null && result.getPois().size() > 0) { - emitter.onNext(result); - } else { - emitter.onError(new IllegalArgumentException("没有根据地址查询到对应的经纬度")); - } - } - }).subscribeOn(Schedulers.io()).observeOn(Schedulers.io()) - .flatMap(new Function>>() { - @Override - public Observable> apply(MogoPoiResult mogoPoiResult) throws Exception { - // 转成经纬度后,整理参数,进行接口请求 - Logger.d(TAG, "查询目标地址经纬度成功===" + Thread.currentThread().getName()); - MogoPoiItem poiItem = mogoPoiResult.getPois().get(0); - Location location = new Location(poiItem.getPoint().lat, poiItem.getPoint().lon); - callback.onLocatSuccess(location.getLat(), location.getLon()); - RoadInfoRequest request; - if (voiceCmdData.getObj().equals(TYPE_NAME_BLOCK)) { - // 拥堵和路况同时查 - request = new RoadInfoRequest(location, new String[]{TANLU_ROAD_CONGESTION_COMPAT, TANLU_ROAD_CURRENT}, false, false); - }else{ - request = new RoadInfoRequest(location, new String[]{voiceCmdData.getType()}, false, false); - } - Map params = new ParamsProvider.Builder(mContext) - .append("sn", Utils.getSn()) - .append("data", GsonUtil.jsonFromObject(request)) - .build(); - return mShareApiService.queryRoadInfos(params); - } - }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) - .subscribe(new SubscribeImpl>(RequestOptions.create(mContext)) { - @Override - public void onError(Throwable e) { - super.onError(e); - callback.onQueryRoadInfoFail(e.getMessage(), -1); - } - - @Override - public void onSuccess(BaseDataCompat o) { - super.onSuccess(o); - Logger.d(TAG, "当前线程为"+Thread.currentThread().getName()+" 搜索目标地址路况信息成功: " + o); - callback.onQueryRoadInfoSuccess(o.getResult().getData()); - } - - @Override - public void onError(String message, int code) { - super.onError(message, code); - callback.onQueryRoadInfoFail(message, code); - } - }); - } +// if (voiceCmdData.isHere()) { +// // 搜索附近路况,只需要拿到当前位置信息,就可以请求服务端 +// MogoLocation l = TanluServiceManager.getServiceApis().getMapServiceApi().getSingletonLocationClient(mContext).getLastKnowLocation(); +// Location location = new Location(l.getLatitude(), l.getLongitude()); +// callback.onLocatSuccess(l.getLatitude(), l.getLongitude()); +// RoadInfoRequest request; +// if (voiceCmdData.getObj().equals(TYPE_NAME_BLOCK)) { +// // 拥堵和路况同时查 +// request = new RoadInfoRequest(location, new String[]{TANLU_ROAD_CONGESTION_COMPAT, TANLU_ROAD_CURRENT}, false, false); +// }else{ +// request = new RoadInfoRequest(location, new String[]{voiceCmdData.getType()}, false, false); +// } +// +// Map params = new ParamsProvider.Builder(mContext) +// .append("sn", Utils.getSn()) +// .append("data", GsonUtil.jsonFromObject(request)) +// .build(); +// +// mShareApiService.queryRoadInfos(params) +// .subscribeOn(Schedulers.io()) +// .observeOn(AndroidSchedulers.mainThread()) +// .subscribe(new SubscribeImpl>(RequestOptions.create(mContext)) { +// @Override +// public void onError(Throwable e) { +// super.onError(e); +// } +// +// @Override +// public void onSuccess(BaseDataCompat o) { +// super.onSuccess(o); +// Logger.d(TAG, "搜索附近路况信息成功: " + o); +// callback.onQueryRoadInfoSuccess(o.getResult().getData()); +// Logger.d(TAG, "搜索附近路况信息成功2: " + o); +// } +// +// @Override +// public void onError(String message, int code) { +// super.onError(message, code); +// callback.onQueryRoadInfoFail(message, code); +// } +// }); +// } else { +// // 查询的不是附近的信息,所以需要查询一下目标地址的经纬度,然后再请求服务端 +// Observable.create(new ObservableOnSubscribe() { +// @Override +// public void subscribe(ObservableEmitter emitter) throws Exception { +// // 根据传入的地址,转成经纬度 +// IMogoMapService mapService = TanluServiceManager.getServiceApis().getMapServiceApi(); +// String cityCode = mapService.getSingletonLocationClient(mContext).getLastKnowLocation().getCityCode(); +// MogoPoiSearchQuery poiSearchQuery = new MogoPoiSearchQuery(voiceCmdData.getLocation(), "", cityCode); +// IMogoPoiSearch poiSearch = mapService.getPoiSearch(mContext, poiSearchQuery); +// MogoPoiResult result = poiSearch.searchPOI(); +// if (result != null && result.getPois() != null && result.getPois().size() > 0) { +// emitter.onNext(result); +// } else { +// emitter.onError(new IllegalArgumentException("没有根据地址查询到对应的经纬度")); +// } +// } +// }).subscribeOn(Schedulers.io()).observeOn(Schedulers.io()) +// .flatMap(new Function>>() { +// @Override +// public Observable> apply(MogoPoiResult mogoPoiResult) throws Exception { +// // 转成经纬度后,整理参数,进行接口请求 +// Logger.d(TAG, "查询目标地址经纬度成功===" + Thread.currentThread().getName()); +// MogoPoiItem poiItem = mogoPoiResult.getPois().get(0); +// Location location = new Location(poiItem.getPoint().lat, poiItem.getPoint().lon); +// callback.onLocatSuccess(location.getLat(), location.getLon()); +// RoadInfoRequest request; +// if (voiceCmdData.getObj().equals(TYPE_NAME_BLOCK)) { +// // 拥堵和路况同时查 +// request = new RoadInfoRequest(location, new String[]{TANLU_ROAD_CONGESTION_COMPAT, TANLU_ROAD_CURRENT}, false, false); +// }else{ +// request = new RoadInfoRequest(location, new String[]{voiceCmdData.getType()}, false, false); +// } +// +// Map params = new ParamsProvider.Builder(mContext) +// .append("sn", Utils.getSn()) +// .append("data", GsonUtil.jsonFromObject(request)) +// .build(); +// return mShareApiService.queryRoadInfos(params); +// } +// }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()) +// .subscribe(new SubscribeImpl>(RequestOptions.create(mContext)) { +// @Override +// public void onError(Throwable e) { +// super.onError(e); +// callback.onQueryRoadInfoFail(e.getMessage(), -1); +// } +// +// @Override +// public void onSuccess(BaseDataCompat o) { +// super.onSuccess(o); +// Logger.d(TAG, "当前线程为"+Thread.currentThread().getName()+" 搜索目标地址路况信息成功: " + o); +// callback.onQueryRoadInfoSuccess(o.getResult().getData()); +// } +// +// @Override +// public void onError(String message, int code) { +// super.onError(message, code); +// callback.onQueryRoadInfoFail(message, code); +// } +// }); +// } } }