[6.4.0][Feat]FM数据入库并增加查询接口

This commit is contained in:
chenfufeng
2024-04-08 16:21:09 +08:00
parent 152d3a9d89
commit 2883ed51a4
5 changed files with 42 additions and 2 deletions

View File

@@ -130,6 +130,9 @@ object DataManager {
CallerMsgBoxListenerManager.invokeListener(MsgCategory.NOTICE, msg)
}
MsgBoxType.FMINFO -> {
synchronized(this) {
fmInfoList.add(msg)
}
CallerMsgBoxListenerManager.invokeListener(MsgCategory.FM_INFO, msg)
}
MsgBoxType.VOICE -> {
@@ -250,7 +253,7 @@ object DataManager {
}
}
private suspend fun getCacheMessages(context: Context): List<MsgBoxBean> =
private suspend fun getCacheMessages(context: Context): List<MsgBoxBean?> =
withContext(Dispatchers.IO) {
delay(2000)
return@withContext MsgBoxDb.getDb(context)
@@ -326,7 +329,7 @@ object DataManager {
}
}
else -> {
return@map MsgBoxBean(MsgBoxType.V2X, V2XMsg())
return@map null
}
}
}
@@ -368,6 +371,13 @@ object DataManager {
recordBagList.clear()
}
if (fmInfoList.isNotEmpty()) {
fmInfoList.forEach {
msgInfoList.add(MsgBoxInfo(it.bean2Json, it.type.ordinal, it.timestamp))
}
fmInfoList.clear()
}
if (msgInfoList.isNotEmpty()) {
MsgBoxDb.getDb(context)
.monitorDao()
@@ -387,4 +397,14 @@ object DataManager {
}
}
}
fun queryFMInfoList(context: Context, startTime: Long, endTime: Long): List<MsgBoxBean> {
return MsgBoxDb.getDb(context).monitorDao()
.getFMInfoList(MsgBoxType.FMINFO.ordinal, startTime, endTime)
.map { boxInfo ->
MsgBoxBean(MsgBoxType.FMINFO, GsonUtils.fromJson(boxInfo.bean2Json, FMInfoMsg::class.java)).apply {
timestamp = boxInfo.timeStamp
}
}
}
}

View File

@@ -50,6 +50,14 @@ class MsgBoxProvider : IMsgBoxProvider {
return DataManager.getRecordBagData()
}
override fun queryFMInfoList(
context: Context,
startTime: Long,
endTime: Long
): List<MsgBoxBean> {
return DataManager.queryFMInfoList(context, startTime, endTime)
}
override fun removeRecordInfo(context: Context, msgBoxBean: MsgBoxBean, key: String) {
DataManager.removeRecordInfo(key, key)
DataManager.delMsgBoxBean(context, msgBoxBean)

View File

@@ -16,6 +16,9 @@ interface MsgBoxDao {
@Query("SELECT * FROM t_msg_box")
fun getAllCachedMessages(): List<MsgBoxInfo>
@Query("SELECT * FROM t_msg_box WHERE json_obj_type == (:fmType) AND time_stamp >= (:startTime) AND time_stamp <= (:endTime)")
fun getFMInfoList(fmType: Int, startTime: Long, endTime: Long): List<MsgBoxInfo>
@Query("DELETE FROM t_msg_box")
fun deleteMsgTable()
}