新增道路拥堵上报功能
This commit is contained in:
@@ -1,16 +1,27 @@
|
||||
package com.mogo.module.share;
|
||||
|
||||
import android.content.Context;
|
||||
import android.nfc.Tag;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.alibaba.android.arouter.facade.template.IProvider;
|
||||
import com.amap.api.services.nearby.UploadInfoCallback;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.navi.IMogoAimlessModeListener;
|
||||
import com.mogo.map.navi.MogoCongestionInfo;
|
||||
import com.mogo.map.navi.MogoCongestionLink;
|
||||
import com.mogo.map.navi.MogoTraffic;
|
||||
import com.mogo.module.common.MogoApisHandler;
|
||||
import com.mogo.module.common.entity.RoadTrafficSegment;
|
||||
import com.mogo.module.common.entity.RoadTrafficStatus;
|
||||
import com.mogo.module.share.net.TrafficModelData;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* TODO 高德巡航信息监听,并将拥堵信息上报到服务端
|
||||
@@ -18,10 +29,18 @@ import com.mogo.utils.network.utils.GsonUtil;
|
||||
@Route(path = MogoServicePaths.PATH_GAODE_AIMLESS_SHARE)
|
||||
public class GaoDeAimlessProvider implements IProvider {
|
||||
private final String TAG = "GaoDeAimlessProvider";
|
||||
private TrafficModelData mTanluModelData;
|
||||
List<RoadTrafficSegment> mlist = new ArrayList<>();
|
||||
RoadTrafficSegment roadTrafficSegment = new RoadTrafficSegment();
|
||||
|
||||
@Override
|
||||
public void init(Context context) {
|
||||
|
||||
Log.d(TAG, "provider init……");
|
||||
if (mTanluModelData == null) {
|
||||
mTanluModelData = new TrafficModelData();
|
||||
}
|
||||
|
||||
// 开启巡航监听
|
||||
MogoApisHandler.getInstance()
|
||||
.getApis()
|
||||
@@ -36,16 +55,41 @@ public class GaoDeAimlessProvider implements IProvider {
|
||||
.registerMogoAimlessModeListener(TAG, new IMogoAimlessModeListener() {
|
||||
@Override
|
||||
public void onUpdateTraffic2(MogoTraffic traffic) {
|
||||
|
||||
Log.d(TAG, "onUpdateTraffic2 back……");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdateCongestion(MogoCongestionInfo info) {
|
||||
// TODO 上报给服务器
|
||||
Log.d(TAG, GsonUtil.jsonFromObject(info));
|
||||
|
||||
UploadInfo(info);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 上报拥堵信息
|
||||
*
|
||||
* @param info
|
||||
*/
|
||||
private void UploadInfo(MogoCongestionInfo info) {
|
||||
RoadTrafficStatus mStatusBean = new RoadTrafficStatus();
|
||||
mStatusBean.setLength(info.getLength());
|
||||
mStatusBean.setRoadName(info.getRoadName());
|
||||
mStatusBean.setStatus(info.getCongestionStatus());
|
||||
mStatusBean.setSegment(true);
|
||||
|
||||
if (info.getCongestionLinks() != null && info.getCongestionLinks().size() > 0) {
|
||||
mlist.clear();
|
||||
for (MogoCongestionLink data : info.getCongestionLinks()
|
||||
) {
|
||||
roadTrafficSegment.setStatus(data.getCongestionStatus());
|
||||
roadTrafficSegment.setMogoLatLngList(data.getCoords());
|
||||
mlist.add(roadTrafficSegment);
|
||||
}
|
||||
mStatusBean.setRoadTrafficSegmentList(mlist);
|
||||
}
|
||||
mTanluModelData.UploadCongestionInfo(mStatusBean);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,10 @@ class HttpConstant {
|
||||
const val HOST_DEMO = "http://dzt-show.zhidaohulian.com"
|
||||
const val HOST_PRODUCT = "https://dzt.zhidaohulian.com"
|
||||
|
||||
const val TMC_HOST_TEST="http://dzt-test.zhidaozhixing.com"
|
||||
const val TMC_HOST_DEMO="http://dzt-show.zhidaozhixing.com"
|
||||
const val TMC_HOST_PRODUCT="http://dzt.zhidaozhixing.com"
|
||||
|
||||
@JvmStatic
|
||||
fun getNetHost(): String {
|
||||
return when (DebugConfig.getNetMode()) {
|
||||
@@ -19,6 +23,16 @@ class HttpConstant {
|
||||
else -> HOST_PRODUCT
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun getTMCHost(): String {
|
||||
return when (DebugConfig.getNetMode()) {
|
||||
DebugConfig.NET_MODE_DEV -> TMC_HOST_TEST
|
||||
DebugConfig.NET_MODE_QA -> TMC_HOST_TEST
|
||||
DebugConfig.NET_MODE_DEMO -> TMC_HOST_DEMO
|
||||
else -> TMC_HOST_PRODUCT
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,21 @@
|
||||
package com.mogo.module.share.net;
|
||||
|
||||
import com.mogo.commons.data.BaseData;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import retrofit2.http.FieldMap;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface TrafficApiService {
|
||||
/**
|
||||
* 上报路况拥堵情况
|
||||
*
|
||||
*/
|
||||
@FormUrlEncoded
|
||||
@POST("/yycp-tmcServer/tmcServer/car/reportTraffic/v1")
|
||||
Observable<BaseData> UploadCongestionInfo(@FieldMap Map<String, Object> parames);
|
||||
|
||||
}
|
||||
|
||||
@@ -2,32 +2,76 @@ package com.mogo.module.share.net;
|
||||
|
||||
import com.alibaba.android.arouter.launcher.ARouter;
|
||||
import com.mogo.commons.AbsMogoApplication;
|
||||
import com.mogo.commons.data.BaseData;
|
||||
import com.mogo.commons.network.ParamsProvider;
|
||||
import com.mogo.commons.network.SubscribeImpl;
|
||||
import com.mogo.commons.network.Utils;
|
||||
import com.mogo.module.common.entity.RoadTrafficStatus;
|
||||
import com.mogo.module.common.entity.UploadTrafficEntity;
|
||||
import com.mogo.module.share.constant.HttpConstant;
|
||||
import com.mogo.service.MogoServicePaths;
|
||||
import com.mogo.service.network.IMogoNetwork;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.network.RequestOptions;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
import static com.mogo.commons.AbsMogoApplication.getApp;
|
||||
|
||||
public class TrafficModelData {
|
||||
|
||||
private static final String TAG = "TrafficModelData";
|
||||
private TrafficApiService mTrafficApiService;
|
||||
|
||||
public TrafficModelData() {
|
||||
IMogoNetwork network = (IMogoNetwork) ARouter.getInstance().build(MogoServicePaths.PATH_SERVICES_NETWORK).navigation(AbsMogoApplication.
|
||||
getApp().getApplicationContext());
|
||||
mTrafficApiService = network.create(TrafficApiService.class, HttpConstant.getNetHost());
|
||||
IMogoNetwork network = (IMogoNetwork) ARouter.getInstance().build(MogoServicePaths.PATH_SERVICES_NETWORK).navigation(getApp().getApplicationContext());
|
||||
mTrafficApiService = network.create(TrafficApiService.class, HttpConstant.getTMCHost());
|
||||
}
|
||||
|
||||
public void uploadTrafficInfo(UploadTrafficEntity uploadTrafficEntity) {
|
||||
Map<String, Object> params = new ParamsProvider.Builder(AbsMogoApplication.
|
||||
getApp().getApplicationContext())
|
||||
Map<String, Object> params = new ParamsProvider.Builder(getApp().getApplicationContext())
|
||||
.append("sn", Utils.getSn())
|
||||
.append("data", GsonUtil.jsonFromObject(uploadTrafficEntity))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 拥堵信息上报
|
||||
*
|
||||
* @param info 高的返回的拥堵信息对象
|
||||
* @param
|
||||
*/
|
||||
public void UploadCongestionInfo(RoadTrafficStatus info) {
|
||||
|
||||
final ParamsProvider.Builder builder = new ParamsProvider.Builder( getApp().getApplicationContext());
|
||||
//TODO 添加参数
|
||||
Map<String, Object> parameters = builder.build();
|
||||
parameters.put("sn", Utils.getSn());
|
||||
parameters.put("data",GsonUtil.jsonFromObject(info));
|
||||
mTrafficApiService.UploadCongestionInfo(parameters)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(new SubscribeImpl<BaseData>(RequestOptions.create( getApp().getApplicationContext())) {
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
super.onError(e);
|
||||
Logger.d(TAG, "拥堵上报失败" + e.toString());
|
||||
// callback.UploadFail(e.getMessage(), -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(BaseData o) {
|
||||
super.onSuccess(o);
|
||||
Logger.d(TAG, "拥堵上报成功" + o.toString());
|
||||
// callback.UpLoadSuccess(o.msg.toString(), o.code);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user