[6.4.0]
[局域网内网络通讯、发送业务模式和check消息]
This commit is contained in:
@@ -2,15 +2,20 @@ package com.mogo.och.biz.login.model
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.commons.storage.SharedPrefsMgr
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant
|
||||
import com.mogo.commons.storage.SharedPrefsMgr
|
||||
import com.mogo.eagle.core.utilcode.util.GsonUtils
|
||||
import com.mogo.och.biz.login.bean.DriverStatusQueryRespBean
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.BusCacheKey
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.LoginCacheStatus
|
||||
import com.mogo.och.common.module.biz.lansocket.LoginLanSocket
|
||||
import com.mogo.och.common.module.biz.login.LoginStatusManager
|
||||
import com.mogo.och.common.module.manager.socket.lan.LanSocketManager
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.AppConnectMsg
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.BusCacheKey
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.ChangeBusinessType
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.LoginCacheStatus
|
||||
import com.mogo.och.common.module.utils.DateTimeUtil
|
||||
import com.mogo.och.common.module.utils.ProjectUtils
|
||||
import com.mogo.och.data.manager.cache.CacheDataManager
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
package com.mogo.och.common.module.biz.lansocket
|
||||
|
||||
import com.mogo.commons.debug.DebugConfig
|
||||
import com.mogo.eagle.core.data.config.FunctionBuildConfig
|
||||
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils
|
||||
import com.mogo.och.common.module.biz.login.ILoginCallback
|
||||
import com.mogo.och.common.module.biz.login.LoginStatusEnum
|
||||
import com.mogo.och.common.module.biz.login.LoginStatusManager
|
||||
import com.mogo.och.common.module.manager.loop.BizLoopManager
|
||||
import com.mogo.och.common.module.manager.loop.LoopInfo
|
||||
import com.mogo.och.common.module.manager.socket.lan.LanSocketManager
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.BusinessType
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.ChangeBusinessType
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.EnvCheck
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.EnvType
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.ProjectType
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.VehicleType
|
||||
import com.mogo.och.common.module.utils.Project
|
||||
import com.mogo.och.common.module.utils.ProjectUtils
|
||||
|
||||
object LoginLanSocket : ILoginCallback {
|
||||
private const val TAG = "LoginLanSocket"
|
||||
|
||||
var vehicleType:VehicleType?=null
|
||||
var businessType:BusinessType?=null
|
||||
var projectType:ProjectType?=null
|
||||
var envType:EnvType?=null
|
||||
|
||||
fun load(){
|
||||
|
||||
}
|
||||
|
||||
init {
|
||||
LoginStatusManager.addListener(TAG, this)
|
||||
}
|
||||
|
||||
override fun onStatusChange(currentStatus: LoginStatusEnum?) {
|
||||
super.onStatusChange(currentStatus)
|
||||
when (currentStatus) {
|
||||
LoginStatusEnum.None -> {}
|
||||
LoginStatusEnum.Login -> {
|
||||
getEnvCheck()
|
||||
val msg = ChangeBusinessType(vehicleType!!, businessType!!, projectType!!, envType!!)
|
||||
LanSocketManager.sendMsgToClient(msg)
|
||||
BizLoopManager.setLoopFunction(TAG, LoopInfo(60*5, ::loopCheck))
|
||||
}
|
||||
LoginStatusEnum.Logout -> {
|
||||
BizLoopManager.removeLoopFunction(TAG)
|
||||
val msg = ChangeBusinessType(vehicleType!!, BusinessType.none, projectType!!, envType!!)
|
||||
LanSocketManager.sendMsgToClient(msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun loopCheck() {
|
||||
getEnvCheck()
|
||||
val msg = EnvCheck(vehicleType!!, businessType!!, projectType!!, envType!!)
|
||||
LanSocketManager.sendMsgToClient(msg)
|
||||
}
|
||||
|
||||
private fun getEnvCheck(){
|
||||
vehicleType =
|
||||
if (AppIdentityModeUtils.isT1T2(FunctionBuildConfig.appIdentityMode)) {
|
||||
VehicleType.T1T2
|
||||
} else if (AppIdentityModeUtils.isM1(FunctionBuildConfig.appIdentityMode)) {
|
||||
VehicleType.M1
|
||||
} else if (AppIdentityModeUtils.isB1(FunctionBuildConfig.appIdentityMode)) {
|
||||
VehicleType.B1
|
||||
} else if (AppIdentityModeUtils.isB2(FunctionBuildConfig.appIdentityMode)) {
|
||||
VehicleType.B2
|
||||
} else {
|
||||
VehicleType.C1
|
||||
}
|
||||
businessType =
|
||||
when (AppIdentityModeUtils.getProduct(FunctionBuildConfig.appIdentityMode)) {
|
||||
AppIdentityModeUtils.Product.BUS -> {
|
||||
BusinessType.bus
|
||||
}
|
||||
|
||||
AppIdentityModeUtils.Product.TAXI -> {
|
||||
BusinessType.taxi
|
||||
}
|
||||
|
||||
AppIdentityModeUtils.Product.SWEEPER -> {
|
||||
BusinessType.none
|
||||
}
|
||||
|
||||
AppIdentityModeUtils.Product.SHUTTLE -> {
|
||||
BusinessType.shuttle
|
||||
}
|
||||
|
||||
AppIdentityModeUtils.Product.CHARTER -> {
|
||||
BusinessType.charter
|
||||
}
|
||||
|
||||
else -> {
|
||||
BusinessType.none
|
||||
}
|
||||
}
|
||||
projectType = when (ProjectUtils.getProjectType()) {
|
||||
Project.SAAS -> ProjectType.saas
|
||||
Project.DALI -> ProjectType.dali
|
||||
Project.MOGO -> ProjectType.mogo
|
||||
Project.YANTAI -> ProjectType.yantai
|
||||
}
|
||||
envType = when (DebugConfig.getNetMode()) {
|
||||
1 -> {
|
||||
EnvType.demo
|
||||
}
|
||||
|
||||
2 -> {
|
||||
EnvType.qa
|
||||
}
|
||||
|
||||
3 -> {
|
||||
EnvType.online
|
||||
}
|
||||
|
||||
else -> {
|
||||
EnvType.qa
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.mogo.och.common.module.manager.socket.lan
|
||||
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.BaseDPMsg
|
||||
|
||||
/**
|
||||
* @author congtaowang
|
||||
* @since 2019-12-31
|
||||
*
|
||||
*
|
||||
* 消息回调
|
||||
*/
|
||||
interface ILanMessageListener<T:BaseDPMsg> {
|
||||
|
||||
fun target(): Class<T>
|
||||
|
||||
fun <T> onMsgReceived(obj: T)
|
||||
|
||||
}
|
||||
@@ -1,15 +1,23 @@
|
||||
package com.mogo.och.common.module.manager.socket.lan
|
||||
|
||||
import com.mogo.eagle.core.function.api.telematic.IReceivedMsgListener
|
||||
import com.mogo.eagle.core.function.call.telematic.CallerTelematicListenerManager
|
||||
import com.mogo.eagle.core.function.call.telematic.CallerTelematicManager
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger
|
||||
import com.mogo.eagle.core.utilcode.util.GsonUtils
|
||||
import com.mogo.och.common.module.constant.OchCommonConst
|
||||
import com.mogo.och.common.module.manager.logchainanalytic.OchChainLogManager
|
||||
import com.mogo.och.common.module.manager.socket.lan.bean.BaseDPMsg
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
object LanSocketManager {
|
||||
|
||||
object LanSocketManager : IReceivedMsgListener {
|
||||
private const val TAG = "LanSocketManager"
|
||||
|
||||
init {
|
||||
CallerTelematicListenerManager.addListener(TAG, this)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun sendMsgToClient(msg: BaseDPMsg?) {
|
||||
val message = GsonUtils.toJson(msg)
|
||||
@@ -26,5 +34,52 @@ object LanSocketManager {
|
||||
CallerTelematicManager.sendMsgToServer(OchCommonConst.BUSINESS_STRING, message.toByteArray())
|
||||
}
|
||||
|
||||
override fun onReceivedMsg(type: Int, byteArray: ByteArray) {
|
||||
CallerLogger.d(TAG, "收到数据:_type:${type},byteArray:${String(byteArray)}")
|
||||
OchChainLogManager.writeChainLogLanSocket("收到数据","type:${type},byteArray:${String(byteArray)}")
|
||||
if (OchCommonConst.BUSINESS_STRING == type) {
|
||||
try {
|
||||
val baseMsg = GsonUtils.fromJson(String(byteArray), BaseDPMsg::class.java)
|
||||
baseMsg?.let {
|
||||
mListeners.forEach { action ->
|
||||
if(action.key==it.type){
|
||||
action.value.let {keyAndListenerMap->
|
||||
var fromJson:BaseDPMsg?=null
|
||||
keyAndListenerMap.forEach {listeners->
|
||||
if(fromJson==null) {
|
||||
val target = listeners.value.target()
|
||||
fromJson = GsonUtils.fromJson(
|
||||
String(byteArray), target
|
||||
)
|
||||
}
|
||||
listeners.value.onMsgReceived(fromJson)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch (e:Exception){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
fun <T:BaseDPMsg> registerSocketMessageListener(msgType:Int, tag:String ,mogoOnMessageListener : ILanMessageListener<T>){
|
||||
val typeMap = mListeners[msgType]
|
||||
if (typeMap==null) {
|
||||
val concurrentHashMap = ConcurrentHashMap<String, ILanMessageListener<*>>()
|
||||
concurrentHashMap[tag] = mogoOnMessageListener
|
||||
mListeners[msgType] = concurrentHashMap
|
||||
}else{
|
||||
if (!typeMap.contains(tag)) {
|
||||
typeMap[tag] = mogoOnMessageListener
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val mListeners: ConcurrentHashMap<Int, ConcurrentHashMap<String, ILanMessageListener<out BaseDPMsg>>> =
|
||||
ConcurrentHashMap()
|
||||
|
||||
|
||||
}
|
||||
@@ -81,7 +81,7 @@ data class ChangeBusinessType(
|
||||
val businessType: BusinessType,
|
||||
val projectType: ProjectType,
|
||||
val envType: EnvType,
|
||||
) : BaseDPMsg(DPMsgType.TYPE_WRITEOFF_DEVICES_INFO.type)
|
||||
) : BaseDPMsg(DPMsgType.TYPE_CHANGE_BUSINESS_TYPE.type)
|
||||
|
||||
// 检测环境
|
||||
data class EnvCheck(
|
||||
@@ -89,7 +89,7 @@ data class EnvCheck(
|
||||
val businessType: BusinessType,
|
||||
val projectType: ProjectType,
|
||||
val envType: EnvType,
|
||||
) : BaseDPMsg(DPMsgType.TYPE_WRITEOFF_DEVICES_INFO.type)
|
||||
) : BaseDPMsg(DPMsgType.TYPE_ENV_CHECK.type)
|
||||
|
||||
// 车辆类型
|
||||
enum class VehicleType {
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.mogo.eagle.core.function.hmi.ui.setting.ToggleDebugView
|
||||
import com.mogo.eagle.core.function.hmi.ui.widget.StatusBarView
|
||||
import com.mogo.eagle.core.utilcode.mogo.AppIdentityModeUtils
|
||||
import com.mogo.eagle.core.utilcode.mogo.logger.CallerLogger.d
|
||||
import com.mogo.och.common.module.biz.lansocket.LoginLanSocket
|
||||
import com.mogo.och.common.module.constant.OchCommonConst
|
||||
import com.mogo.och.common.module.biz.login.BusinessEnum
|
||||
import com.mogo.och.common.module.biz.login.ILoginCallback
|
||||
@@ -39,6 +40,7 @@ abstract class FacadeProvider : IMoGoFunctionProvider, ILoginCallback {
|
||||
override fun init(context: Context) {
|
||||
d(TAG, "FacadeProvider:init")
|
||||
LoginStatusManager.addListener(TAG, this)
|
||||
LoginLanSocket.load()
|
||||
if (AppIdentityModeUtils.isDriver(FunctionBuildConfig.appIdentityMode)){
|
||||
LoginStatusManager.queryLoginStatusByNet()
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ object AppIdentityModeUtils {
|
||||
|
||||
|
||||
@JvmStatic
|
||||
fun isDFHQ(appIdentityMode: String): Boolean {
|
||||
fun isT1T2(appIdentityMode: String): Boolean {
|
||||
val (_, _, model) = getInfo(appIdentityMode)
|
||||
if (model.isNotEmpty()) {
|
||||
return model == T1T2
|
||||
@@ -296,12 +296,12 @@ object AppIdentityModeUtils {
|
||||
SWEEPER -> Product.SWEEPER
|
||||
SHUTTLE -> Product.SHUTTLE
|
||||
CHARTER -> Product.CHARTER
|
||||
else -> Product.TAXI
|
||||
else -> Product.NONE
|
||||
}
|
||||
}
|
||||
|
||||
enum class Product {
|
||||
BUS, TAXI, SWEEPER, SHUTTLE, CHARTER
|
||||
NONE, BUS, TAXI, SWEEPER, SHUTTLE, CHARTER
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user