|
@@ -9,12 +9,9 @@ import android.content.Intent
|
|
|
import android.content.IntentFilter
|
|
|
import android.media.AudioManager
|
|
|
import android.os.Build
|
|
|
-import android.os.Bundle
|
|
|
import android.os.IBinder
|
|
|
import android.util.Log
|
|
|
import android.view.WindowManager
|
|
|
-import androidx.navigation.fragment.NavHostFragment.findNavController
|
|
|
-import androidx.navigation.fragment.findNavController
|
|
|
import com.google.gson.Gson
|
|
|
import com.google.gson.JsonObject
|
|
|
import com.google.gson.reflect.TypeToken
|
|
@@ -23,6 +20,8 @@ import com.hboxs.serialport.sbc.VboxSerialPortSendQueue
|
|
|
import com.hboxs.serialport.sbc.frame.VboxCommand
|
|
|
import com.hboxs.serialport.sbc.frame.VboxWriteCommand
|
|
|
import com.hjq.http.lifecycle.LifecycleService
|
|
|
+import com.module.database.room.SZDatabase
|
|
|
+import com.module.database.room.entity.OfflineOrderBean
|
|
|
import com.module.pay.common.PayAgreementUtil
|
|
|
import com.module.pay.nayax.CreditCardPresenter
|
|
|
import com.module.pay.strategy.PaySendDataFactory
|
|
@@ -32,10 +31,10 @@ import com.quyunshuo.module.home.dialog.CountDownDialogFragment
|
|
|
import com.quyunshuo.module.home.dialog.WarringDialog
|
|
|
import com.quyunshuo.module.home.receiver.MqttHelper
|
|
|
import com.quyunshuo.module.home.receiver.TimedCleaningTaskAlarmReceiver
|
|
|
+import com.quyunshuo.sbm10.base.BaseApplication
|
|
|
import com.quyunshuo.sbm10.base.DialogClickListener
|
|
|
import com.quyunshuo.sbm10.base.ktx.observeLiveData
|
|
|
import com.quyunshuo.sbm10.base.utils.GsonUtil
|
|
|
-import com.quyunshuo.sbm10.base.utils.JsonUtils
|
|
|
import com.quyunshuo.sbm10.base.utils.SpUtils
|
|
|
import com.quyunshuo.sbm10.base.utils.TimeUtil
|
|
|
import com.quyunshuo.sbm10.base.utils.XLogUtil
|
|
@@ -120,8 +119,8 @@ class GlobalService : LifecycleService() {
|
|
|
}
|
|
|
initPayIctMdb()
|
|
|
|
|
|
- if (SpUtils.getString(MMKVName.OPEN_DEV,"0")!="0"){
|
|
|
- SpUtils.putString(MMKVName.OPEN_DEV,"0")
|
|
|
+ if (SpUtils.getString(MMKVName.OPEN_DEV, "0") != "0") {
|
|
|
+ SpUtils.putString(MMKVName.OPEN_DEV, "0")
|
|
|
}
|
|
|
showTipsDialog(UiUtil.getStringRes(R.string.initializing))//是否开机
|
|
|
observeLiveData(globalServiceViewModel.initIsSuccess, ::initIsSuccess)
|
|
@@ -129,15 +128,30 @@ class GlobalService : LifecycleService() {
|
|
|
globalServiceViewModel.sendBackData()//心跳上传
|
|
|
// globalServiceViewModel.forceBackToApp()
|
|
|
initMaterial()
|
|
|
+ initUpLoadOrder()
|
|
|
|
|
|
}
|
|
|
|
|
|
+ private fun initUpLoadOrder() {
|
|
|
+ CoroutineScope(Dispatchers.Main).launch {
|
|
|
+ while (true) {
|
|
|
+ val list = offlineOrderDao.getAll()
|
|
|
+ Log.d(TAG, "initUpLoadOrder: "+list)
|
|
|
+ if (list.size<=0){
|
|
|
+ return@launch
|
|
|
+ }
|
|
|
+ EventBus.getDefault().post(ApiMessageEvent(MMKVName.OFFLINE_ORDER, list[0].map))
|
|
|
+ delay(1000 * 60*3)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private fun initMaterial() {
|
|
|
- val isMaterial = SpUtils.getBoolean(MMKVName.MATERIAL,false)
|
|
|
- if (isMaterial==true){
|
|
|
- EventBus.getDefault().post(ApiMessageEvent(MMKVName.MATERIAL,"1"))
|
|
|
- }else{
|
|
|
- EventBus.getDefault().post(ApiMessageEvent(MMKVName.MATERIAL,"0"))
|
|
|
+ val isMaterial = SpUtils.getBoolean(MMKVName.MATERIAL, false)
|
|
|
+ if (isMaterial == true) {
|
|
|
+ EventBus.getDefault().post(ApiMessageEvent(MMKVName.MATERIAL, "1"))
|
|
|
+ } else {
|
|
|
+ EventBus.getDefault().post(ApiMessageEvent(MMKVName.MATERIAL, "0"))
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -279,16 +293,16 @@ class GlobalService : LifecycleService() {
|
|
|
if (sweet <= 0) {
|
|
|
//这里是缺甜玉米,那么将隐藏甜玉米这个商品
|
|
|
// list[0].isSelected = false
|
|
|
- sweetType=2
|
|
|
+ sweetType = 2
|
|
|
warnBean = WarningBean(
|
|
|
- "No.4" + UiUtil.getStringRes( R.string.alarm_message_04),
|
|
|
+ "No.4" + UiUtil.getStringRes(R.string.alarm_message_04),
|
|
|
Heartbeat.clientId.toString(),
|
|
|
TimeUtil.getStrCurTime(),
|
|
|
1,
|
|
|
""
|
|
|
)
|
|
|
} else {
|
|
|
- if (sweetType==0) {
|
|
|
+ if (sweetType == 0) {
|
|
|
sweetType = 1
|
|
|
warnBean = WarningBean(
|
|
|
"No.4" + UiUtil.getStringRes(R.string.sweet_corn_remain) + ": " + sweet + "g",
|
|
@@ -305,9 +319,9 @@ class GlobalService : LifecycleService() {
|
|
|
if (salty < 400) {
|
|
|
if (salty <= 0) {
|
|
|
//这里是缺咸玉米,那么将隐藏咸玉米这个商品
|
|
|
- saltyType=2
|
|
|
+ saltyType = 2
|
|
|
warnBean = WarningBean(
|
|
|
- "No.3" + UiUtil.getStringRes( R.string.alarm_message_03),
|
|
|
+ "No.3" + UiUtil.getStringRes(R.string.alarm_message_03),
|
|
|
Heartbeat.clientId.toString(),
|
|
|
TimeUtil.getStrCurTime(),
|
|
|
1,
|
|
@@ -315,7 +329,7 @@ class GlobalService : LifecycleService() {
|
|
|
)
|
|
|
// list[1].isSelected = false
|
|
|
} else {
|
|
|
- if (saltyType==0) {
|
|
|
+ if (saltyType == 0) {
|
|
|
saltyType = 1
|
|
|
warnBean = WarningBean(
|
|
|
"No.3" + UiUtil.getStringRes(R.string.salty_corn_remain) + ": " + salty + "g",
|
|
@@ -333,7 +347,7 @@ class GlobalService : LifecycleService() {
|
|
|
if (box <= 0) {
|
|
|
showWarringDialog("No.2", R.string.alarm_message_02)
|
|
|
} else {
|
|
|
- if (boxType==0) {
|
|
|
+ if (boxType == 0) {
|
|
|
boxType = 1
|
|
|
warnBean = WarningBean(
|
|
|
"No.2" + UiUtil.getStringRes(R.string.box_remain) + ": " + box,
|
|
@@ -425,27 +439,31 @@ class GlobalService : LifecycleService() {
|
|
|
mqttHelper.sendData("response", Gson().toJson(map))
|
|
|
XLogUtil.d("本地主动消除报警")
|
|
|
}
|
|
|
+
|
|
|
MqName.MATERIAL -> {
|
|
|
mqttHelper.sendData("response", Gson().toJson(messageEvent.data))
|
|
|
- Log.d(TAG, "event:MATERIAL "+Gson().toJson(messageEvent.data))
|
|
|
+ Log.d(TAG, "event:MATERIAL " + Gson().toJson(messageEvent.data))
|
|
|
}
|
|
|
- MqName.SLEEP ->{
|
|
|
+
|
|
|
+ MqName.SLEEP -> {
|
|
|
mqttHelper.sendData("response", Gson().toJson(messageEvent.data))
|
|
|
}
|
|
|
- MqName.PASSWORD->{
|
|
|
+
|
|
|
+ MqName.PASSWORD -> {
|
|
|
val map = Gson().fromJson(messageEvent.data.toString(), JsonObject::class.java)
|
|
|
- val response= map.getAsJsonObject("responseContent")
|
|
|
+ val response = map.getAsJsonObject("responseContent")
|
|
|
val password = response["password"].toString()
|
|
|
val type = response["type"].toString()
|
|
|
- Log.d(TAG, "event:PASSWORD "+password+":"+type)
|
|
|
- if (type=="0"){
|
|
|
+ Log.d(TAG, "event:PASSWORD " + password + ":" + type)
|
|
|
+ if (type == "0") {
|
|
|
SpUtils.putString(MqName.ADMIN_PWD, password)
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
SpUtils.putString(MqName.GUEST_PWD, password)
|
|
|
}
|
|
|
mqttHelper.sendData("response", Gson().toJson(messageEvent.data))
|
|
|
}
|
|
|
- MqName.VOLUME->{
|
|
|
+
|
|
|
+ MqName.VOLUME -> {
|
|
|
val map = Gson().fromJson(messageEvent.data.toString(), JsonObject::class.java)
|
|
|
val progress = map.get("responseContent").asInt
|
|
|
val audioManager =
|
|
@@ -459,44 +477,44 @@ class GlobalService : LifecycleService() {
|
|
|
XLogUtil.d("远程修改了音量$progress")
|
|
|
}
|
|
|
|
|
|
- MqName.UPDATEPRODUCT->{
|
|
|
+ MqName.UPDATEPRODUCT -> {
|
|
|
val map = Gson().fromJson(messageEvent.data.toString(), JsonObject::class.java)
|
|
|
- Log.d(TAG, "eventUPDATEPRODUCT: "+map)
|
|
|
- val response= map.getAsJsonObject("responseContent")
|
|
|
+ Log.d(TAG, "eventUPDATEPRODUCT: " + map)
|
|
|
+ val response = map.getAsJsonObject("responseContent")
|
|
|
// val no = JsonUtils.getValue<String>(response.toString(),"no").toString()
|
|
|
// val productName = JsonUtils.getValue<String>(response.toString(),"productName")
|
|
|
// val codePrice = response["codePrice"].asDouble
|
|
|
// val sellStatus = response["sellStatus"].asBoolean
|
|
|
- val no = GsonUtil.getAsString(response,"no","")
|
|
|
- val productName = GsonUtil.getAsString(response,"productName","")
|
|
|
- val codePrice = GsonUtil.getAsDouble(response,"codePrice",0.0)
|
|
|
- val sellStatus = GsonUtil.getAsBoolean(response,"sellStatus",true)
|
|
|
- val productData= SpUtils.getString(MMKVName.PRODUCT_DATA,"")
|
|
|
- Log.d(TAG, "eventproductData1: "+productData)
|
|
|
+ val no = GsonUtil.getAsString(response, "no", "")
|
|
|
+ val productName = GsonUtil.getAsString(response, "productName", "")
|
|
|
+ val codePrice = GsonUtil.getAsDouble(response, "codePrice", 0.0)
|
|
|
+ val sellStatus = GsonUtil.getAsBoolean(response, "sellStatus", true)
|
|
|
+ val productData = SpUtils.getString(MMKVName.PRODUCT_DATA, "")
|
|
|
+ Log.d(TAG, "eventproductData1: " + productData)
|
|
|
val list: ArrayList<ProductDataBean> = Gson().fromJson(
|
|
|
productData,
|
|
|
object : TypeToken<ArrayList<ProductDataBean?>?>() {}.type
|
|
|
)
|
|
|
- for (i in list.indices){
|
|
|
- if (list[i].productNo==no){
|
|
|
- list[i].price=codePrice
|
|
|
- list[i].customName=productName
|
|
|
- list[i].isSelected=sellStatus
|
|
|
+ for (i in list.indices) {
|
|
|
+ if (list[i].productNo == no) {
|
|
|
+ list[i].price = codePrice
|
|
|
+ list[i].customName = productName
|
|
|
+ list[i].isSelected = sellStatus
|
|
|
}
|
|
|
}
|
|
|
- XLogUtil.d("远程修改了商品:"+Gson().toJson(list))
|
|
|
- SpUtils.putString(MMKVName.PRODUCT_DATA,Gson().toJson(list))
|
|
|
- Log.d(TAG, "eventPRODUCT_DATA: "+SpUtils.getString(MMKVName.PRODUCT_DATA,""))
|
|
|
+ XLogUtil.d("远程修改了商品:" + Gson().toJson(list))
|
|
|
+ SpUtils.putString(MMKVName.PRODUCT_DATA, Gson().toJson(list))
|
|
|
+ Log.d(TAG, "eventPRODUCT_DATA: " + SpUtils.getString(MMKVName.PRODUCT_DATA, ""))
|
|
|
mqttHelper.sendData("response", Gson().toJson(messageEvent.data))
|
|
|
}
|
|
|
|
|
|
- MqName.EQESTATUS->{
|
|
|
- Log.d(TAG, " MqName.EQESTATUSevent: "+messageEvent.data)
|
|
|
+ MqName.EQESTATUS -> {
|
|
|
+ Log.d(TAG, " MqName.EQESTATUSevent: " + messageEvent.data)
|
|
|
val map = Gson().fromJson(messageEvent.data.toString(), JsonObject::class.java)
|
|
|
- val response= map.getAsJsonObject("responseContent")
|
|
|
- val eqeStatus = GsonUtil.getAsString(response,"eqeStatus","0")
|
|
|
- Log.d(TAG, "eventeqeStatus: "+eqeStatus)
|
|
|
- if (eqeStatus=="1"){
|
|
|
+ val response = map.getAsJsonObject("responseContent")
|
|
|
+ val eqeStatus = GsonUtil.getAsString(response, "eqeStatus", "0")
|
|
|
+ Log.d(TAG, "eventeqeStatus: " + eqeStatus)
|
|
|
+ if (eqeStatus == "1") {
|
|
|
globalServiceViewModel.threadGlobalParam.stopUp()
|
|
|
globalServiceViewModel.threadGlobalParam.startUp()
|
|
|
Log.d(TAG, "event: startUp")
|
|
@@ -504,10 +522,10 @@ class GlobalService : LifecycleService() {
|
|
|
mqttHelper.sendData("response", Gson().toJson(messageEvent.data))
|
|
|
}
|
|
|
|
|
|
- MqName.OPENDOOR->{
|
|
|
+ MqName.OPENDOOR -> {
|
|
|
val map = Gson().fromJson(messageEvent.data.toString(), JsonObject::class.java)
|
|
|
- val response= map.getAsJsonObject("responseContent")
|
|
|
- val productName = GsonUtil.getAsString(response,"status","0")
|
|
|
+ val response = map.getAsJsonObject("responseContent")
|
|
|
+ val productName = GsonUtil.getAsString(response, "status", "0")
|
|
|
VboxSerialPortSendQueue.getInstance()
|
|
|
.sendCommand(
|
|
|
VboxWriteCommand(
|
|
@@ -518,49 +536,63 @@ class GlobalService : LifecycleService() {
|
|
|
mqttHelper.sendData("response", Gson().toJson(messageEvent.data))
|
|
|
}
|
|
|
|
|
|
- MqName.PHONE->{
|
|
|
+ MqName.PHONE -> {
|
|
|
val map = Gson().fromJson(messageEvent.data.toString(), JsonObject::class.java)
|
|
|
- val response= map.getAsJsonObject("responseContent")
|
|
|
- val contactName = GsonUtil.getAsString(response,"contactName","")
|
|
|
- val contactPhone = GsonUtil.getAsString(response,"contactPhone","")
|
|
|
- SpUtils.putString(MMKVName.CONTACT,contactName)
|
|
|
- SpUtils.putString(MMKVName.CONTACT_WAY,contactPhone)
|
|
|
+ val response = map.getAsJsonObject("responseContent")
|
|
|
+ val contactName = GsonUtil.getAsString(response, "contactName", "")
|
|
|
+ val contactPhone = GsonUtil.getAsString(response, "contactPhone", "")
|
|
|
+ SpUtils.putString(MMKVName.CONTACT, contactName)
|
|
|
+ SpUtils.putString(MMKVName.CONTACT_WAY, contactPhone)
|
|
|
mqttHelper.sendData("response", Gson().toJson(messageEvent.data))
|
|
|
}
|
|
|
|
|
|
- MqName.SLEEPDESC->{
|
|
|
+ MqName.SLEEPDESC -> {
|
|
|
val map = Gson().fromJson(messageEvent.data.toString(), JsonObject::class.java)
|
|
|
- val responseContent= map.getAsJsonObject("responseContent")
|
|
|
- val sleepDesc = GsonUtil.getAsString(responseContent,"sleepDesc",UiUtil.getStringRes(R.string.device_sleep))
|
|
|
- SpUtils.putString(MMKVName.SLEEP_TEXT,sleepDesc)
|
|
|
- EventBus.getDefault().post(ApiMessageEvent(MMKVName.SLEEP_TEXT,sleepDesc))
|
|
|
- Log.d(TAG, "eventqName.SLEEPDESC: "+messageEvent.data)
|
|
|
+ val responseContent = map.getAsJsonObject("responseContent")
|
|
|
+ val sleepDesc = GsonUtil.getAsString(
|
|
|
+ responseContent,
|
|
|
+ "sleepDesc",
|
|
|
+ UiUtil.getStringRes(R.string.device_sleep)
|
|
|
+ )
|
|
|
+ SpUtils.putString(MMKVName.SLEEP_TEXT, sleepDesc)
|
|
|
+ EventBus.getDefault().post(ApiMessageEvent(MMKVName.SLEEP_TEXT, sleepDesc))
|
|
|
+ Log.d(TAG, "eventqName.SLEEPDESC: " + messageEvent.data)
|
|
|
mqttHelper.sendData("response", Gson().toJson(messageEvent.data))
|
|
|
}
|
|
|
- MqName.BATCHUPDATEPRICE->{
|
|
|
+
|
|
|
+ MqName.BATCHUPDATEPRICE -> {
|
|
|
val map = Gson().fromJson(messageEvent.data.toString(), JsonObject::class.java)
|
|
|
- val response= GsonUtil.getAsString(map,"responseContent","")
|
|
|
- Log.d(TAG, "MqName.BATCHUPDATEPRICE:event: "+response)
|
|
|
- Log.d(TAG, " MqName.BATCHUPDATEPRICE: "+messageEvent.data)
|
|
|
- val productData= SpUtils.getString(MMKVName.PRODUCT_DATA,"")
|
|
|
+ val response = GsonUtil.getAsString(map, "responseContent", "")
|
|
|
+ Log.d(TAG, "MqName.BATCHUPDATEPRICE:event: " + response)
|
|
|
+ Log.d(TAG, " MqName.BATCHUPDATEPRICE: " + messageEvent.data)
|
|
|
+ val productData = SpUtils.getString(MMKVName.PRODUCT_DATA, "")
|
|
|
val list: ArrayList<ProductDataBean> = Gson().fromJson(
|
|
|
productData,
|
|
|
object : TypeToken<ArrayList<ProductDataBean?>?>() {}.type
|
|
|
)
|
|
|
- for (i in list.indices){
|
|
|
- list[i].price= response.toDouble()
|
|
|
- }
|
|
|
- XLogUtil.d("远程一键修改商品价格:"+Gson().toJson(list))
|
|
|
- SpUtils.putString(MMKVName.PRODUCT_DATA,Gson().toJson(list))
|
|
|
+ for (i in list.indices) {
|
|
|
+ list[i].price = response.toDouble()
|
|
|
+ }
|
|
|
+ XLogUtil.d("远程一键修改商品价格:" + Gson().toJson(list))
|
|
|
+ SpUtils.putString(MMKVName.PRODUCT_DATA, Gson().toJson(list))
|
|
|
mqttHelper.sendData("response", Gson().toJson(messageEvent.data))
|
|
|
}
|
|
|
- MqName.PRODUCEGOODS->{
|
|
|
- Log.d(TAG, "PRODUCEGOODSevent:1 "+messageEvent.data.toString())
|
|
|
+
|
|
|
+ MqName.PRODUCEGOODS -> {
|
|
|
+ Log.d(TAG, "PRODUCEGOODSevent:1 " + messageEvent.data.toString())
|
|
|
+ mqttHelper.sendData("response", messageEvent.data.toString())
|
|
|
+ }
|
|
|
+
|
|
|
+ MMKVName.OFFLINE_ORDER -> {
|
|
|
+ Log.d(TAG, "OFFLINE_ORDERevent: " + messageEvent.data.toString())
|
|
|
mqttHelper.sendData("response", messageEvent.data.toString())
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private val offlineOrderDao =
|
|
|
+ SZDatabase.getDatabase(BaseApplication.context).getOfflineOrderDao()
|
|
|
+
|
|
|
override fun onDestroy() {
|
|
|
super.onDestroy()
|
|
|
EventBus.getDefault().unregister(this)
|