[Feat]新增消息盒子数据中心

This commit is contained in:
chenfufeng
2022-11-22 16:32:20 +08:00
parent 64c448a4d6
commit 0c0ff743bb
21 changed files with 482 additions and 0 deletions

View File

@@ -0,0 +1 @@
/build

View File

@@ -0,0 +1,76 @@
plugins {
id 'com.android.library'
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
id 'com.alibaba.arouter'
}
android {
compileSdkVersion rootProject.ext.android.compileSdkVersion
defaultConfig {
minSdkVersion rootProject.ext.android.minSdkVersion
targetSdkVersion rootProject.ext.android.targetSdkVersion
versionCode Integer.valueOf(VERSION_CODE)
versionName getValueFromRootProperties("${project.name.replace("-", "_").toUpperCase()}_VERSION")
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'consumer-rules.pro'
//ARouter apt 参数
kapt {
useBuildCache = false
arguments {
arg("AROUTER_MODULE_NAME", project.getName())
}
}
javaCompileOptions {
annotationProcessorOptions {
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation rootProject.ext.dependencies.androidxccorektx
implementation rootProject.ext.dependencies.androidxappcompat
implementation rootProject.ext.dependencies.arouter
implementation rootProject.ext.dependencies.rxandroid
kapt rootProject.ext.dependencies.aroutercompiler
implementation rootProject.ext.dependencies.androidxroomruntime
kapt rootProject.ext.dependencies.androidxroomcompiler
implementation rootProject.ext.dependencies.androidxroomktx
if (Boolean.valueOf(USE_MAVEN_PACKAGE)) {
// implementation rootProject.ext.dependencies.modulecommon
// implementation rootProject.ext.dependencies.moduleservice
implementation rootProject.ext.dependencies.mogo_core_data
implementation rootProject.ext.dependencies.mogo_core_utils
implementation rootProject.ext.dependencies.mogo_core_function_api
implementation rootProject.ext.dependencies.mogo_core_function_call
implementation rootProject.ext.dependencies.mogo_core_res
} else {
// implementation project(':modules:mogo-module-common')
// implementation project(':modules:mogo-module-service')
implementation project(':core:mogo-core-data')
implementation project(':core:mogo-core-utils')
implementation project(':core:mogo-core-function-api')
implementation project(':core:mogo-core-function-call')
implementation project(':core:mogo-core-res')
}
}
apply from: new File(rootProject.rootDir, "gradle/upload.gradle").toString()

View File

@@ -0,0 +1,3 @@
GROUP=com.mogo.eagle.core.function.impl
POM_ARTIFACT_ID=msgbox
VERSION_CODE=1

View File

@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mogo.eagle.core.function.msgbox">
<application>
</application>
</manifest>

View File

@@ -0,0 +1,95 @@
package com.mogo.eagle.core.function.msgbox
import android.os.Looper
import com.mogo.eagle.core.data.msgbox.MsgBoxBean
import com.mogo.eagle.core.data.msgbox.MsgBoxType
import com.mogo.eagle.core.data.msgbox.MsgCategory
import com.mogo.eagle.core.function.call.msgbox.CallerMsgBoxListenerManager
import com.mogo.eagle.core.utilcode.kotlin.lifeCycleScope
import com.mogo.eagle.core.utilcode.util.Utils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
object DataManager {
// private val msgBoxMap: EnumMap<MsgBoxType, MutableList<MsgBoxBean>> = EnumMap(MsgBoxType::class.java)
private val notifyList by lazy {
mutableListOf<MsgBoxBean>()
}
private val sysInfoList by lazy {
mutableListOf<MsgBoxBean>()
}
private val recordBagList by lazy {
mutableListOf<MsgBoxBean>()
}
@Volatile
private var isUpdate = false
private val scope by lazy {
Utils.getApp().lifeCycleScope
}
/**
* 存储时保证按时序排列
*/
fun saveMsg(bean: MsgBoxBean) {
if (Thread.currentThread() == Looper.getMainLooper().thread) {
scope.launch(Dispatchers.Default) {
realSaveMsg(bean)
}
} else {
realSaveMsg(bean)
}
}
fun realSaveMsg(bean: MsgBoxBean) {
val type = bean.type
bean.timestamp = System.currentTimeMillis()
when(type) {
MsgBoxType.V2X, MsgBoxType.OBU, MsgBoxType.NOTICE, MsgBoxType.OPERATION -> {
synchronized(this) {
notifyList.add(bean)
}
CallerMsgBoxListenerManager.invokeListener(MsgCategory.NOTICE, bean)
}
MsgBoxType.REPORT -> {
synchronized(this) {
sysInfoList.add(bean)
}
CallerMsgBoxListenerManager.invokeListener(MsgCategory.SYS_INFO, bean)
}
MsgBoxType.RECORD -> {
synchronized(this) {
recordBagList.add(bean)
}
CallerMsgBoxListenerManager.invokeListener(MsgCategory.RECORD_BAG, bean)
}
else -> {}
}
}
/**
* 通知消息V2X、云公告、运营信息
*/
fun getNotifyData(): List<MsgBoxBean> {
return notifyList
}
/**
* 工控机Report信息
*/
fun getSysInfoData(): List<MsgBoxBean> {
return sysInfoList
}
/**
* 录包信息
*/
fun getRecordBagData(): List<MsgBoxBean> {
return recordBagList
}
}

View File

@@ -0,0 +1,38 @@
package com.mogo.eagle.core.function.msgbox
import android.content.Context
import com.alibaba.android.arouter.facade.annotation.Route
import com.mogo.eagle.core.data.constants.MogoServicePaths.PATH_MSG_BOX_MODULE
import com.mogo.eagle.core.data.msgbox.MsgBoxBean
import com.mogo.eagle.core.function.api.msgbox.IMsgBoxProvider
@Route(path = PATH_MSG_BOX_MODULE)
class MsgBoxProvider : IMsgBoxProvider {
override val functionName: String
get() = "MsgBoxProvider"
override fun init(context: Context) {
context
}
override fun saveMsg(bean: MsgBoxBean) {
DataManager.saveMsg(bean)
}
override fun getNotifyData(): List<MsgBoxBean> {
return DataManager.getNotifyData()
}
override fun getSysInfoData(): List<MsgBoxBean> {
return DataManager.getSysInfoData()
}
override fun getRecordBagData(): List<MsgBoxBean> {
return DataManager.getRecordBagData()
}
override fun onDestroy() {
}
}

View File

@@ -0,0 +1,9 @@
package com.mogo.eagle.core.function.msgbox.db
import androidx.room.*
@Dao
interface MsgBoxDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun saveMsg(info: MsgBoxInfo)
}

View File

@@ -0,0 +1,27 @@
package com.mogo.eagle.core.function.msgbox.db
import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
@Database(entities = [MsgBoxInfo::class], version = 1, exportSchema = false)
abstract class MsgBoxDb: RoomDatabase() {
abstract fun monitorDao(): MsgBoxDao
companion object {
const val INTERNAL_DB_NAME = "msg_box.db"
private var db: MsgBoxDb? = null
@JvmStatic
fun getDb(context: Context): MsgBoxDb {
if (db == null) {
db = Room.databaseBuilder(context.applicationContext, MsgBoxDb::class.java, INTERNAL_DB_NAME)
.fallbackToDestructiveMigration()
.build()
}
return db!!
}
}
}

View File

@@ -0,0 +1,15 @@
package com.mogo.eagle.core.function.msgbox.db
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey
@Entity(tableName = "t_msg_box")
data class MsgBoxInfo(
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
val uuid: Long = 0,
@ColumnInfo(name = "obj_str")
val objString: String
)

View File

@@ -150,4 +150,7 @@ public class MogoServicePaths {
*/
@Keep
public static final String PATH_TELEMATIC_PROVIDER = "/telematic/api";
@Keep
public static final String PATH_MSG_BOX_MODULE = "/msg_box/api";
}

View File

@@ -0,0 +1,3 @@
package com.mogo.eagle.core.data.msgbox
data class MsgBoxBean(val type: MsgBoxType, val bean: Any, var timestamp: Long = 0)

View File

@@ -0,0 +1,5 @@
package com.mogo.eagle.core.data.msgbox
enum class MsgBoxType {
OPERATION, NOTICE, V2X, OBU, REPORT, RECORD, TRAFFIC
}

View File

@@ -0,0 +1,5 @@
package com.mogo.eagle.core.data.msgbox
enum class MsgCategory {
NOTICE, SYS_INFO, RECORD_BAG
}

View File

@@ -0,0 +1,6 @@
package com.mogo.eagle.core.data.msgbox
/**
* 运营消息:-1表示初始值
*/
data class OperationMsg(val timestamp : Long, val content: String, val type: Int = -1)

View File

@@ -0,0 +1,13 @@
package com.mogo.eagle.core.function.api.msgbox
import com.mogo.eagle.core.data.msgbox.MsgBoxBean
import com.mogo.eagle.core.data.msgbox.MsgCategory
/**
* @author chenfufeng
* @date 2022/11/21
* 消息盒子的数据回调
*/
interface IMsgBoxListener {
fun onDataChanged(category: MsgCategory, msgBoxList: MsgBoxBean)
}

View File

@@ -0,0 +1,22 @@
package com.mogo.eagle.core.function.api.msgbox
import com.mogo.eagle.core.data.msgbox.MsgBoxBean
import com.mogo.eagle.core.function.api.base.IMoGoFunctionServerProvider
interface IMsgBoxProvider: IMoGoFunctionServerProvider {
fun saveMsg(bean: MsgBoxBean)
/**
* 通知消息V2X、云公告、运营信息
*/
fun getNotifyData(): List<MsgBoxBean>
/**
* 工控机Report信息
*/
fun getSysInfoData(): List<MsgBoxBean>
/**
* 录包信息
*/
fun getRecordBagData(): List<MsgBoxBean>
}

View File

@@ -0,0 +1,87 @@
package com.mogo.eagle.core.function.call.msgbox
import androidx.annotation.Nullable
import com.mogo.eagle.core.data.msgbox.MsgBoxBean
import com.mogo.eagle.core.data.msgbox.MsgCategory
import com.mogo.eagle.core.function.api.msgbox.IMsgBoxListener
import com.mogo.eagle.core.function.call.base.CallerBase
import java.util.concurrent.ConcurrentHashMap
/**
* @author chenfufeng
* @date 2022/11/17
* 消息盒子数据监听管理
*/
object CallerMsgBoxListenerManager : CallerBase() {
private val statusListeners: ConcurrentHashMap<String, IMsgBoxListener> =
ConcurrentHashMap()
// private val key2CategoryMap by lazy {
// ConcurrentHashMap<String, MsgCategory>()
// }
/**
* 添加数据监听
* @param tag 标记,用来注销监听使用
* @param listener 监听回调
*/
fun addListener(
@Nullable tag: String,
@Nullable listener: IMsgBoxListener
) {
if (statusListeners.containsKey(tag)) {
return
}
statusListeners[tag] = listener
}
// fun addListenerByCategory(
// @Nullable tag: String,
// @Nullable category: MsgCategory,
// @Nullable listener: IMsgBoxListener
// ) {
// addListener(tag, listener)
// key2CategoryMap[tag] = category
// }
/**
* 删除 OBU状态 监听
* @param tag 标记,用来注销监听使用
*/
fun removeListener(@Nullable tag: String) {
if (!statusListeners.containsKey(tag)) {
return
}
statusListeners.remove(tag)
}
/**
* 删除 OBU状态 监听
* @param listener 要删除的监听对象
*/
fun removeListener(@Nullable listener: IMsgBoxListener) {
if (!statusListeners.containsValue(listener)) {
return
}
var tag = ""
statusListeners.forEach {
if (it.value == listener) {
tag = it.key
statusListeners.remove(it.key)
}
}
// key2CategoryMap.remove(tag)
}
/**
* 触发监听
*/
fun invokeListener(category: MsgCategory, msgBox: MsgBoxBean) {
statusListeners.forEach {
val tag = it.key
val listener = it.value
listener.onDataChanged(category, msgBox)
}
}
}

View File

@@ -0,0 +1,45 @@
package com.mogo.eagle.core.function.call.msgbox
import com.mogo.eagle.core.data.constants.MogoServicePaths
import com.mogo.eagle.core.data.msgbox.MsgBoxBean
import com.mogo.eagle.core.function.api.msgbox.IMsgBoxProvider
import com.mogo.eagle.core.function.call.base.CallerBase
object CallerMsgBoxManager {
private val TAG = "CallerMsgBoxManager"
private val providerApi: IMsgBoxProvider?
get() = CallerBase.getApiInstance(
IMsgBoxProvider::class.java,
MogoServicePaths.PATH_MSG_BOX_MODULE
)
/**
* 存储数据到消息盒子
*/
fun saveMsgBox(bean: MsgBoxBean) {
providerApi?.saveMsg(bean)
}
/**
* 通知消息V2X、云公告、运营信息
*/
fun getNotifyData(): List<MsgBoxBean>? {
return providerApi?.getNotifyData()
}
/**
* 工控机Report信息
*/
fun getSysInfoData(): List<MsgBoxBean>? {
return providerApi?.getSysInfoData()
}
/**
* 录包信息
*/
fun getRecordBagData(): List<MsgBoxBean>? {
return providerApi?.getRecordBagData()
}
}

View File

@@ -48,6 +48,8 @@ include ':core:function-impl:mogo-core-function-dispatch'
include ':core:function-impl:mogo-core-function-bindingcar'
// 车聊聊业务
include ':core:function-impl:mogo-core-function-chat'
// 消息盒子
include ':core:function-impl:mogo-core-function-msgbox'
// 服务
include ':services:mogo-service-api'