增加了针对历史数据的过滤,三分钟内的数据是可以被消费掉的

This commit is contained in:
董宏宇
2020-08-06 18:22:50 +08:00
parent 6506548086
commit 55c37faf06

View File

@@ -15,6 +15,7 @@ import com.mogo.module.service.Utils;
import com.mogo.module.v2x.V2XConst;
import com.mogo.module.v2x.V2XServiceManager;
import com.mogo.module.v2x.alarm.V2XAlarmServer;
import com.mogo.module.v2x.utils.TimeConstants;
import com.mogo.module.v2x.utils.TimeUtils;
import com.mogo.module.v2x.utils.V2XUtils;
import com.mogo.service.connection.IMogoOnMessageListener;
@@ -42,42 +43,48 @@ public class V2XMessageListener_401012 implements IMogoOnMessageListener<MarkerC
Logger.d(MODULE_NAME, "V2XMessageListener_401012==V2X服务端下发\n"
+ GsonUtil.jsonFromObject(response));
try {
if (response.getExploreWay() != null && response.getExploreWay().size() > 0) {
MarkerExploreWay markerExploreWay = response.getExploreWay().get(0);
MarkerLocation markerLocation = markerExploreWay.getLocation();
// 记录道路事件
V2XRoadEventEntity v2XRoadEventEntity = new V2XRoadEventEntity();
v2XRoadEventEntity.setLocation(markerLocation);
// 探路目前只有上报拥堵
v2XRoadEventEntity.setPoiType(markerExploreWay.getPoiType());
// 当前车辆数据
MogoLocation currentLocation = V2XServiceManager.getV2XStatusManager().getLocation();
float calculateDistance;
if (currentLocation.getLatitude() > 0 || currentLocation.getLongitude() > 0) {
calculateDistance = Utils.calculateLineDistance(
new MogoLatLng(markerLocation.getLat(), markerLocation.getLon()),
new MogoLatLng(currentLocation.getLatitude(), currentLocation.getLongitude())
);
markerExploreWay.setDistance(calculateDistance);
long timeSpan = TimeUtils.getTimeSpan(TimeUtils.getNowMills(), response.getMessageTime(), TimeConstants.MIN);
// 三分钟以内的消息才会提示用户
if (timeSpan <= 3) {
if (response.getExploreWay() != null && response.getExploreWay().size() > 0) {
MarkerExploreWay markerExploreWay = response.getExploreWay().get(0);
MarkerLocation markerLocation = markerExploreWay.getLocation();
// 记录道路事件
V2XRoadEventEntity v2XRoadEventEntity = new V2XRoadEventEntity();
v2XRoadEventEntity.setLocation(markerLocation);
// 探路目前只有上报拥堵
v2XRoadEventEntity.setPoiType(markerExploreWay.getPoiType());
// 当前车辆数据
MogoLocation currentLocation = V2XServiceManager.getV2XStatusManager().getLocation();
float calculateDistance;
if (currentLocation.getLatitude() > 0 || currentLocation.getLongitude() > 0) {
calculateDistance = Utils.calculateLineDistance(
new MogoLatLng(markerLocation.getLat(), markerLocation.getLon()),
new MogoLatLng(currentLocation.getLatitude(), currentLocation.getLongitude())
);
markerExploreWay.setDistance(calculateDistance);
}
v2XRoadEventEntity.setDistance(markerExploreWay.getDistance());
v2XRoadEventEntity.setNoveltyInfo(markerExploreWay);
v2XRoadEventEntity.setExpireTime(20000);
// 记录播报过的道路事件
V2XAlarmServer.mAlertRoadEventList.put(v2XRoadEventEntity, TimeUtils.getNowString());
V2XMessageEntity<V2XRoadEventEntity> v2xMessageEntity = new V2XMessageEntity<>();
// 控制类型
v2xMessageEntity.setType(V2XMessageEntity.V2XTypeEnum.ALERT_ROAD_WARNING);
// 设置数据
v2xMessageEntity.setContent(v2XRoadEventEntity);
// 控制展示状态
v2xMessageEntity.setShowState(true);
Intent intent = new Intent(V2XConst.BROADCAST_SCENE_HANDLER_ACTION);
intent.putExtra(V2XConst.BROADCAST_SCENE_EXTRA_KEY, v2xMessageEntity);
LocalBroadcastManager.getInstance(V2XUtils.getApp()).sendBroadcast(intent);
}
v2XRoadEventEntity.setDistance(markerExploreWay.getDistance());
v2XRoadEventEntity.setNoveltyInfo(markerExploreWay);
v2XRoadEventEntity.setExpireTime(20000);
// 记录播报过的道路事件
V2XAlarmServer.mAlertRoadEventList.put(v2XRoadEventEntity, TimeUtils.getNowString());
V2XMessageEntity<V2XRoadEventEntity> v2xMessageEntity = new V2XMessageEntity<>();
// 控制类型
v2xMessageEntity.setType(V2XMessageEntity.V2XTypeEnum.ALERT_ROAD_WARNING);
// 设置数据
v2xMessageEntity.setContent(v2XRoadEventEntity);
// 控制展示状态
v2xMessageEntity.setShowState(true);
Intent intent = new Intent(V2XConst.BROADCAST_SCENE_HANDLER_ACTION);
intent.putExtra(V2XConst.BROADCAST_SCENE_EXTRA_KEY, v2xMessageEntity);
LocalBroadcastManager.getInstance(V2XUtils.getApp()).sendBroadcast(intent);
} else {
Logger.e(MODULE_NAME, "V2XMessageListener_401012==V2X服务端下发消息已过期大于3分钟了不进行消费");
}
} catch (Exception e) {
e.printStackTrace();