ccc před 1 měsícem
rodič
revize
2b723ca658

+ 1 - 0
lib_common/src/main/java/com/quyunshuo/sbm10/common/constant/MqName.kt

@@ -70,5 +70,6 @@ object MqName {
      * 订单上传成功
      */
     var UPLOADORDER= "uploadOrder"
+    val DIVORCE_SYSTEM = "divorce_system"
 
 }

+ 3 - 1
module_backstage/src/main/java/com/module/backstage/activity/setting/SettingActivity.kt

@@ -245,7 +245,7 @@ class SettingActivity : BaseActivity<BackstageActivitySettingBinding, SettingVie
         observeLiveData(mViewModel.isM3Success, ::closeDialog)
         observeLiveData(mViewModel.connectState, ::connectState)
         observeLiveData(mViewModel.apkInfo, ::updateApp)
-        observeLiveData(mViewModel.connectOut, ::connectOut)
+//        observeLiveData(mViewModel.connectOut, ::connectOut)
 
         lifecycle.addObserver(this)
 
@@ -426,6 +426,8 @@ class SettingActivity : BaseActivity<BackstageActivitySettingBinding, SettingVie
         Log.d(TAG, "event: " + messageEvent.name)
         when (messageEvent.name) {
             MqName.TUO_JI -> {
+                Log.d(TAG, "event: TUO_JI"+messageEvent.data)
+                connectOut(true)
                 //设置连接状态
                 connectState(
                     SpUtils.getString(

+ 17 - 15
module_backstage/src/main/java/com/module/backstage/activity/setting/SettingViewModel.kt

@@ -16,12 +16,13 @@ import com.hboxs.serialport.sbc.frame.VboxCommand
 import com.hboxs.serialport.sbc.frame.VboxWriteCommand
 import com.module.backstage.model.ApkInfoBean
 import com.quyunshuo.sbm10.base.BaseApplication
-import com.quyunshuo.sbm10.base.addressenum.PlcSettingAddressEnum
 import com.quyunshuo.sbm10.base.ktx.launchIO
 import com.quyunshuo.sbm10.base.mvvm.vm.BaseViewModel
 import com.quyunshuo.sbm10.base.utils.SpUtils
 import com.quyunshuo.sbm10.common.constant.Heartbeat
 import com.quyunshuo.sbm10.common.constant.MMKVName
+import com.quyunshuo.sbm10.common.constant.MqName
+import com.quyunshuo.sbm10.common.constant.event.ApiMessageEvent
 import com.quyunshuo.sbm10.common.enums.ConnectStateEnum
 import com.quyunshuo.sbm10.common.util.ToastUtil
 import dagger.hilt.android.lifecycle.HiltViewModel
@@ -31,6 +32,7 @@ import kotlinx.coroutines.Job
 import kotlinx.coroutines.delay
 import kotlinx.coroutines.flow.catch
 import kotlinx.coroutines.launch
+import org.greenrobot.eventbus.EventBus
 import javax.inject.Inject
 
 /**
@@ -100,24 +102,24 @@ class SettingViewModel @Inject constructor(private val mRepo: SettingRepository)
     }
 
     fun initOutSystem() {
-        if (Heartbeat.clientId == null || Heartbeat.clientId == ""&&SpUtils.getString(
-                MMKVName.MANAGER_ID,
-                "")!="2855") {
+//        if (Heartbeat.clientId == null || Heartbeat.clientId == "" && SpUtils.getString(MMKVName.MANAGER_ID, "") != "2855") {
+        if (SpUtils.getString(MMKVName.MANAGER_ID, "") != "2855"&&SpUtils.getString(MMKVName.MANAGER_ID, "") != "39034") {
             ToastUtil.switchToastStyleToWarn("无法脱离系统")
             return
         }
+        EventBus.getDefault().post(ApiMessageEvent(MqName.DIVORCE_SYSTEM, ""))
+
         //脱离系统
-        viewModelScope.launch(Dispatchers.IO) {
-            mRepo.initOutSystem().catch {
-                Log.d(TAG, "initDev onerror: " + it)
-            }.collect {
-                CoroutineScope(Dispatchers.Main).launch {
-                    Log.d(TAG, "initDev onnext: " + it)
-                    ToastUtil.switchToastStyleToSuccess(it)
-                    _connectOut.value=true
-                }
-            }
-        }
+//        viewModelScope.launch(Dispatchers.IO) {
+//            mRepo.initOutSystem().catch {
+//                Log.d(TAG, "initDev onerror: " + it)
+//            }.collect {
+//                CoroutineScope(Dispatchers.Main).launch {
+//                    Log.d(TAG, "initDev onnext: " + it)
+//                    _connectOut.value=true
+//                }
+//            }
+//        }
     }
 
     fun initDev(text: String?) {

+ 12 - 0
module_home/src/main/java/com/quyunshuo/module/home/service/GlobalService.kt

@@ -587,6 +587,18 @@ class GlobalService : LifecycleService() {
                 Log.d(TAG, "OFFLINE_ORDERevent: " + messageEvent.data.toString())
                 mqttHelper.sendData("response", messageEvent.data.toString())
             }
+            MqName.DIVORCE_SYSTEM->{
+                val map = mapOf(
+                    "responseContent" to "0",
+                    "statusCode" to 200,
+                    "clientId" to Heartbeat.deviceId,
+                    "timestamp" to System.currentTimeMillis(),
+                    "operation" to "tuoji",
+                    "direction" to 2
+                )
+                Log.d(TAG, "TUOJIevent: " + Gson().toJson(map))
+                mqttHelper.sendData("response",  Gson().toJson(map))
+            }
         }
     }
 

+ 12 - 0
module_home/src/main/java/com/quyunshuo/module/home/service/ManageMqtt.kt

@@ -10,7 +10,12 @@ import android.util.Log
 import com.quyunshuo.sbm10.common.constant.Heartbeat
 import com.hboxs.serialport.plc.message.MqttMessageBean
 import com.hboxs.serialport.sbc.SBCHeartbeat
+import com.quyunshuo.sbm10.base.utils.SpUtils
+import com.quyunshuo.sbm10.common.constant.MMKVName
 import com.quyunshuo.sbm10.common.constant.MqName
+import com.quyunshuo.sbm10.common.constant.event.ApiMessageEvent
+import com.quyunshuo.sbm10.common.enums.ConnectStateEnum
+import com.quyunshuo.sbm10.common.util.ToastUtil
 import org.eclipse.paho.android.service.MqttAndroidClient
 import org.eclipse.paho.client.mqttv3.IMqttActionListener
 import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken
@@ -189,6 +194,13 @@ class ManageMqtt @Inject constructor() {
             client?.publish(topic, message, null, object : IMqttActionListener {
                 override fun onSuccess(asyncActionToken: IMqttToken?) {
                     Log.d(TAG, "$msg published to $topic")
+                    if(msg.contains("tuoji")){
+                        ToastUtil.switchToastStyleToSuccess("已脱离系统")
+                        Heartbeat.managerId = ""
+                        SpUtils.putString(MMKVName.CONNECT_STATE, ConnectStateEnum.DEFAULT.name)
+                        SpUtils.putString(MMKVName.MANAGER_ID, "")
+                        EventBus.getDefault().post(ApiMessageEvent(MqName.TUO_JI,""))
+                    }
                 }
 
                 override fun onFailure(asyncActionToken: IMqttToken?, exception: Throwable?) {

+ 5 - 2
module_home/src/main/java/com/quyunshuo/module/home/utils/RemotePushUtil.kt

@@ -177,8 +177,7 @@ class RemotePushUtil @Inject constructor() {
             }
 
             MqName.TUO_JI -> {
-                deviceTuoji(kind)
-
+//                deviceTuoji(kind)
             }
 
             MqName.ALARM_CLOCK -> {
@@ -366,6 +365,10 @@ class RemotePushUtil @Inject constructor() {
                     deleteOrdersByTimestamp(timestamp)
                 }
             }
+            MqName.TUO_JI -> {
+                deviceTuoji(kind)
+            }
+
         }
     }