完成了V2X过期数据清理工作,只保留当天的数据
This commit is contained in:
@@ -4,6 +4,8 @@ import com.mogo.utils.sqlite.annotation.DbDatabase;
|
||||
import com.mogo.utils.sqlite.annotation.DbField;
|
||||
import com.mogo.utils.sqlite.annotation.DbTable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* V2X 道路历史事件
|
||||
*
|
||||
|
||||
@@ -15,7 +15,6 @@ import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.mogo.map.MogoLatLng;
|
||||
import com.mogo.map.listener.IMogoMapListener;
|
||||
import com.mogo.map.location.IMogoLocationListener;
|
||||
import com.mogo.map.marker.IMogoMarker;
|
||||
import com.mogo.map.marker.IMogoMarkerClickListener;
|
||||
import com.mogo.map.model.MogoPoi;
|
||||
import com.mogo.map.navi.IMogoNaviListener;
|
||||
@@ -34,6 +33,7 @@ import com.mogo.module.v2x.scenario.scene.park.V2XIllegalParkWindow;
|
||||
import com.mogo.module.v2x.scenario.scene.test.V2XTestConsoleWindow;
|
||||
import com.mogo.module.v2x.utils.FatigueDrivingUtils;
|
||||
import com.mogo.module.v2x.utils.TimeUtils;
|
||||
import com.mogo.module.v2x.utils.V2XSQLiteUtils;
|
||||
import com.mogo.module.v2x.utils.V2XUtils;
|
||||
import com.mogo.module.v2x.voice.V2XVoiceManager;
|
||||
import com.mogo.service.module.IMogoModuleLifecycle;
|
||||
@@ -126,13 +126,10 @@ public class V2XModuleProvider implements
|
||||
|
||||
V2XUtils.init(context);
|
||||
V2XServiceManager.init(context);
|
||||
initVoice(context);
|
||||
handleAdas();
|
||||
V2XVoiceManager.INSTANCE.init(context);
|
||||
registerListener();
|
||||
initData();
|
||||
|
||||
|
||||
V2XServiceManager.getMogoRegisterCenter().registerMogoMapListener(V2XConst.MODULE_NAME, this);
|
||||
|
||||
// 注册广播接收场景弹窗使用的
|
||||
SceneBroadcastReceiver localReceiver = new SceneBroadcastReceiver();
|
||||
LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);
|
||||
@@ -148,10 +145,6 @@ public class V2XModuleProvider implements
|
||||
}
|
||||
}
|
||||
|
||||
private void initVoice(Context context) {
|
||||
V2XVoiceManager.INSTANCE.init(context);
|
||||
}
|
||||
|
||||
private void initData() {
|
||||
try {
|
||||
// 查询ACC状态
|
||||
@@ -171,33 +164,14 @@ public class V2XModuleProvider implements
|
||||
}
|
||||
// 刷新配置文件
|
||||
refreshStrategyConfig();
|
||||
|
||||
// 响应违章停车的POI点击
|
||||
V2XServiceManager
|
||||
.getMogoRegisterCenter()
|
||||
.registerMogoMarkerClickListener(V2XConst.MODULE_NAME,
|
||||
new IMogoMarkerClickListener() {
|
||||
@Override
|
||||
public boolean onMarkerClicked(IMogoMarker marker) {
|
||||
try {
|
||||
MarkerExploreWay markerExploreWay =
|
||||
(MarkerExploreWay) ((MarkerShowEntity) marker.getObject()).getBindObj();
|
||||
Logger.d(V2XConst.MODULE_NAME,
|
||||
"V2X===违章停车:onMarkerClicked=" + markerExploreWay);
|
||||
|
||||
((V2XIllegalParkWindow) V2XIllegalParkScenario.getInstance()
|
||||
.getV2XWindow())
|
||||
.show(markerExploreWay, false);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
// 清除V2X事件数据库中过期的数据,数据有效期为24小时
|
||||
V2XSQLiteUtils.clearYesterdayScenarioHistoryData();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取疲劳驾驶的配置
|
||||
*/
|
||||
private void refreshStrategyConfig() {
|
||||
// 获取疲劳驾驶的配置
|
||||
V2XServiceManager
|
||||
.getV2XRefreshModel()
|
||||
.getStrategyPush(new V2XRefreshCallback<V2XStrategyPushRes>() {
|
||||
@@ -219,12 +193,39 @@ public class V2XModuleProvider implements
|
||||
});
|
||||
}
|
||||
|
||||
private void handleAdas() {
|
||||
/**
|
||||
* 注册各种监听
|
||||
*/
|
||||
private void registerListener() {
|
||||
// 初始化监听
|
||||
V2XServiceManager.getMogoRegisterCenter()
|
||||
.registerMogoMapListener(V2XConst.MODULE_NAME, this);
|
||||
V2XServiceManager.getMoGoStatusManager()
|
||||
.registerStatusChangedListener(MODULE_NAME, StatusDescriptor.ACC_STATUS, this);
|
||||
V2XServiceManager.getMoGoStatusManager()
|
||||
.registerStatusChangedListener(MODULE_NAME, StatusDescriptor.SEEK_HELPING, this);
|
||||
|
||||
|
||||
// 响应违章停车的POI点击
|
||||
V2XServiceManager
|
||||
.getMogoRegisterCenter()
|
||||
.registerMogoMarkerClickListener(V2XConst.MODULE_NAME,
|
||||
marker -> {
|
||||
try {
|
||||
MarkerExploreWay markerExploreWay =
|
||||
(MarkerExploreWay) ((MarkerShowEntity) marker.getObject()).getBindObj();
|
||||
Logger.d(V2XConst.MODULE_NAME,
|
||||
"V2X===违章停车:onMarkerClicked=" + markerExploreWay);
|
||||
|
||||
((V2XIllegalParkWindow) V2XIllegalParkScenario.getInstance()
|
||||
.getV2XWindow())
|
||||
.show(markerExploreWay, false);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
// 注册V2X场景Socket
|
||||
V2XServiceManager.getV2XSocketManager().registerSocketMessage();
|
||||
// 开启自动刷新
|
||||
@@ -233,7 +234,12 @@ public class V2XModuleProvider implements
|
||||
V2XServiceManager.getMapUIController().recoverLockMode();
|
||||
}
|
||||
|
||||
private void handleSeekHelp(boolean isTrue) {
|
||||
/**
|
||||
* 刷新自车求助状态
|
||||
*
|
||||
* @param isTrue
|
||||
*/
|
||||
private void refreshMeSeekHelp(boolean isTrue) {
|
||||
V2XMessageEntity<Boolean> entity = new V2XMessageEntity<>();
|
||||
entity.setType(V2XMessageEntity.V2XTypeEnum.ALERT_CAR_FOR_HELP);
|
||||
entity.setContent(isTrue);
|
||||
@@ -256,16 +262,24 @@ public class V2XModuleProvider implements
|
||||
.putString(V2XConst.V2X_ACC_OFF_TIME_STR, TimeUtils.getNowString());
|
||||
}
|
||||
} else if (descriptor == StatusDescriptor.SEEK_HELPING) {
|
||||
handleSeekHelp(isTrue);
|
||||
refreshMeSeekHelp(isTrue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是ACC ON操作
|
||||
*
|
||||
* @return true-ACC ON | false - ACC OFF
|
||||
*/
|
||||
public boolean isAccOn() {
|
||||
int accState = Settings.System.getInt(mContext.getContentResolver(), "mcu_state", -0x02);
|
||||
Logger.d(MODULE_NAME, "状态发生改变\ndescriptor:ACC_STSTUS" + "\nisTrue:" + accState);
|
||||
return accState == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新自车求助状态
|
||||
*/
|
||||
private void initCarForHelpStatus() {
|
||||
//本地查询是否超时
|
||||
V2XServiceManager.getV2XRefreshModel().getHelpSignal(new V2XRefreshCallback<V2XSeekHelpRes>() {
|
||||
@@ -278,12 +292,12 @@ public class V2XModuleProvider implements
|
||||
//故障车
|
||||
if (vehicleType == 4) {
|
||||
if (!V2XServiceManager.getMoGoStatusManager().isSeekHelping()) {
|
||||
handleSeekHelp(true);
|
||||
refreshMeSeekHelp(true);
|
||||
V2XServiceManager.getMoGoStatusManager().setSeekHelping(MODULE_NAME, true);
|
||||
}
|
||||
} else {
|
||||
if (V2XServiceManager.getMoGoStatusManager().isSeekHelping()) {
|
||||
handleSeekHelp(false);
|
||||
refreshMeSeekHelp(false);
|
||||
V2XServiceManager.getMoGoStatusManager().setSeekHelping(MODULE_NAME, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,10 @@ import com.mogo.module.v2x.scenario.scene.road.V2XRoadEventScenario;
|
||||
import com.mogo.module.v2x.scenario.scene.seek.V2XSeekHelpScenario;
|
||||
import com.mogo.module.v2x.utils.TimeUtils;
|
||||
import com.mogo.module.v2x.utils.ToastUtils;
|
||||
import com.mogo.module.v2x.utils.V2XSQLiteUtils;
|
||||
import com.mogo.module.v2x.utils.V2XUtils;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.network.utils.GsonUtil;
|
||||
import com.mogo.utils.sqlite.BaseDaoFactory;
|
||||
import com.mogo.utils.sqlite.IBaseDao;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -40,11 +39,6 @@ public class V2XScenarioManager implements IV2XScenarioManager {
|
||||
private AbsV2XScenario mV2XScenario;
|
||||
private HashMap<Integer, AbsV2XScenario> mV2XScenarioSet = new HashMap<>();
|
||||
|
||||
/**
|
||||
* 场景数据管理
|
||||
*/
|
||||
private static IBaseDao<V2XHistoryScenarioData> mScenarioDao;
|
||||
|
||||
private V2XScenarioManager() {
|
||||
}
|
||||
|
||||
@@ -53,13 +47,13 @@ public class V2XScenarioManager implements IV2XScenarioManager {
|
||||
synchronized (V2XScenarioManager.class) {
|
||||
if (mV2XScenarioManager == null) {
|
||||
mV2XScenarioManager = new V2XScenarioManager();
|
||||
mScenarioDao = BaseDaoFactory.Companion.getInstance().getBaseDao(V2XUtils.getApp(), V2XHistoryScenarioData.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
return mV2XScenarioManager;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void handlerMessage(V2XMessageEntity v2XMessageEntity) {
|
||||
Logger.d(MODULE_NAME, "处理V2X场景:" + GsonUtil.jsonFromObject(v2XMessageEntity));
|
||||
@@ -68,16 +62,16 @@ public class V2XScenarioManager implements IV2XScenarioManager {
|
||||
V2XUtils.runOnUiThread(() -> {
|
||||
// 提取之前存储的场景
|
||||
if (v2XMessageEntity != null) {
|
||||
/*try {
|
||||
try {
|
||||
// 进行数据库存储
|
||||
V2XHistoryScenarioData v2XHistoryScenarioData = new V2XHistoryScenarioData();
|
||||
v2XHistoryScenarioData.setScenarioType(v2XMessageEntity.getType());
|
||||
v2XHistoryScenarioData.setTriggerTime(TimeUtils.getNowMills());
|
||||
v2XHistoryScenarioData.setEventJsonData(GsonUtil.jsonFromObject(v2XMessageEntity.getContent()));
|
||||
mScenarioDao.insert(v2XHistoryScenarioData);
|
||||
V2XSQLiteUtils.getScenarioHistoryDao().insert(v2XHistoryScenarioData);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
}
|
||||
|
||||
// 广播给应用内部其它模块
|
||||
Intent intent = new Intent(V2XConst.BROADCAST_SCENE_ACTION);
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.mogo.module.v2x.utils;
|
||||
|
||||
import com.mogo.module.common.entity.V2XHistoryScenarioData;
|
||||
import com.mogo.module.v2x.V2XConst;
|
||||
import com.mogo.utils.logger.Logger;
|
||||
import com.mogo.utils.sqlite.BaseDaoFactory;
|
||||
import com.mogo.utils.sqlite.IBaseDao;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据库操作工具类
|
||||
*
|
||||
* @author donghongyu
|
||||
*/
|
||||
public class V2XSQLiteUtils {
|
||||
/**
|
||||
* 场景数据管理
|
||||
*/
|
||||
private static IBaseDao<V2XHistoryScenarioData> mScenarioHistoryDao;
|
||||
|
||||
/**
|
||||
* 场景数据管理
|
||||
*/
|
||||
public static IBaseDao<V2XHistoryScenarioData> getScenarioHistoryDao() {
|
||||
if (mScenarioHistoryDao == null) {
|
||||
synchronized (V2XSQLiteUtils.class) {
|
||||
if (mScenarioHistoryDao == null) {
|
||||
mScenarioHistoryDao = BaseDaoFactory.Companion.getInstance()
|
||||
.getBaseDao(V2XUtils.getApp(), V2XHistoryScenarioData.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
return mScenarioHistoryDao;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除数据库中存储的昨天的数据
|
||||
*/
|
||||
public static void clearYesterdayScenarioHistoryData() {
|
||||
try {
|
||||
List<V2XHistoryScenarioData> historyScenarioData = getScenarioHistoryDao().query(new V2XHistoryScenarioData());
|
||||
for (V2XHistoryScenarioData historyScenarioDatum : historyScenarioData) {
|
||||
Long triggerTime = historyScenarioDatum.getTriggerTime();
|
||||
if (!TimeUtils.isToday(triggerTime)) {
|
||||
int result = getScenarioHistoryDao().delete(historyScenarioDatum);
|
||||
if (result > 0) {
|
||||
Logger.d(V2XConst.MODULE_NAME, "删除过期数据成功");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user