Explorar o código

修正错误注释;工作票json填充默认密码;工作票下发结束强制结束loading,防止显示异常;修复设备取出event消息可能存在的NPE;设备bean添加深拷贝,解决设备拿走时获取不到设备具体信息

Frankensteinly hai 8 meses
pai
achega
2837c16c7d

+ 15 - 9
app/src/main/java/com/grkj/iscs/BusinessManager.kt

@@ -93,7 +93,7 @@ object BusinessManager {
             return (NEED_AUTH && loginUser != null) || !NEED_AUTH
         }
 
-    // 设备归还列表(需要报给后台的列表,等实际取完再上报)
+    // 设备待取列表(需要报给后台的列表,等实际取完再上报)
     private val mDeviceTakeList = mutableListOf<DeviceTakeUpdateBO>()
 
     /**
@@ -772,6 +772,8 @@ object BusinessManager {
         CommonUtils.getDiffHours(vo.ticketEndTime)?.let {
             bo.effectiveTime = it
         }
+        // 填充默认密码
+        bo.password = "123456"
         val dataBO = WorkTicketSendBO.DataBO(
             taskCode = vo.ticketCode,
             taskId = vo.ticketId.toString(),
@@ -895,6 +897,8 @@ object BusinessManager {
                     val dock = ModBusController.getDockByKeyMac(bleDevice.mac)
                     ModBusController.controlKeyBuckle(true, keyBean.isLeft, dock?.addr)
                 }
+                // 强制结束Loading防止有loading仍在显示
+                mEventBus.postValue(MsgEvent(MSG_EVENT_LOADING, LoadingMsg(false, null, true)))
             }
             override fun onWriteFailure(exception: BleException?) {
                 LogUtil.e("switch mode work fail : ${exception?.code} - ${exception?.description}")
@@ -991,19 +995,21 @@ object BusinessManager {
         when (deviceTakeUpdateBO.deviceType) {
             // 钥匙
             0 -> {
-                val info = mDeviceTakeList.find { it.deviceType == 0 && it.nfc == deviceTakeUpdateBO.nfc }
-                NetApi.updateKeyTake(info?.ticketId!!, info.nfc!!, MyApplication.instance?.serialNo()!!) { isSuccess ->
-                    if (isSuccess) {
-                        mDeviceTakeList.removeIf { it.deviceType == 0 && it.nfc == info.nfc }
+                mDeviceTakeList.find { it.deviceType == 0 && it.nfc == deviceTakeUpdateBO.nfc }?.let { info ->
+                    NetApi.updateKeyTake(info.ticketId, info.nfc!!, MyApplication.instance?.serialNo()!!) { isSuccess ->
+                        if (isSuccess) {
+                            mDeviceTakeList.removeIf { it.deviceType == 0 && it.nfc == info.nfc }
+                        }
                     }
                 }
             }
             // 挂锁
             1 -> {
-                val info = mDeviceTakeList.find { it.deviceType == 1 && it.nfc == deviceTakeUpdateBO.nfc }
-                NetApi.updateLockTake(mutableListOf(LockTakeUpdateReqVO(info?.ticketId, info?.nfc, MyApplication.instance?.serialNo()!!))) { isSuccess ->
-                    if (isSuccess == true) {
-                        mDeviceTakeList.removeIf { it.deviceType == 1 && it.nfc == info?.nfc }
+                mDeviceTakeList.find { it.deviceType == 1 && it.nfc == deviceTakeUpdateBO.nfc }?.let { info ->
+                    NetApi.updateLockTake(mutableListOf(LockTakeUpdateReqVO(info.ticketId, info.nfc, MyApplication.instance?.serialNo()!!))) { isSuccess ->
+                        if (isSuccess == true) {
+                            mDeviceTakeList.removeIf { it.deviceType == 1 && it.nfc == info.nfc }
+                        }
                     }
                 }
             }

+ 13 - 5
app/src/main/java/com/grkj/iscs/modbus/DockBean.kt

@@ -48,7 +48,7 @@ class DockBean(
                             if (leftHasKey != keyBean.isExist) {
                                 keyBean.isExist = leftHasKey
                                 keyBean.isCharging = isLeftCharging
-                                changeList.add(keyBean)
+                                changeList.add(keyBean.clone())
                                 // 拿走钥匙,移除钥匙信息
                                 if (!leftHasKey) {
                                     keyBean.rfid = null
@@ -59,7 +59,7 @@ class DockBean(
                             if (rightHasKey != keyBean.isExist) {
                                 keyBean.isExist = rightHasKey
                                 keyBean.isCharging = isRightCharging
-                                changeList.add(keyBean)
+                                changeList.add(keyBean.clone())
                                 // 拿走钥匙,移除钥匙信息
                                 if (!rightHasKey) {
                                     keyBean.rfid = null
@@ -89,7 +89,7 @@ class DockBean(
                     for (i in 0 until getLockList().size) {
                         if (getLockList()[i].isExist != tempList[i]) {
                             getLockList()[i].isExist = tempList[i]
-                            changeList.add(getLockList()[i])
+                            changeList.add(getLockList()[i].clone())
                             // 拿走锁具,移除锁具信息
                             if (!tempList[i]) {
                                 getLockList()[i].rfid = null
@@ -143,7 +143,7 @@ class DockBean(
                     for (i in 0 until getLockList().size) {
                         if (getLockList()[i].isExist != tempList[i]) {
                             getLockList()[i].isExist = tempList[i]
-                            changeList.add(getLockList()[i])
+                            changeList.add(getLockList()[i].clone())
                             // 拿走锁具,移除锁具信息
                             if (!tempList[i]) {
                                 getLockList()[i].rfid = null
@@ -153,7 +153,7 @@ class DockBean(
                     // 蓝牙钥匙变化
                     if (getKeyList()[0].isExist != isKeyExist) {
                         getKeyList()[0].isExist = isKeyExist
-                        changeList.add(getKeyList()[0])
+                        changeList.add(getKeyList()[0].clone())
                         // 拿走钥匙,移除钥匙信息
                         if (!isKeyExist) {
                             getKeyList()[0].rfid = null
@@ -244,6 +244,10 @@ class DockBean(
         override fun toString(): String {
             return "KeyBean(isLeft=$isLeft, isCharging=$isCharging, rfid=$rfid, mac=$mac)"
         }
+
+        fun clone(): KeyBean {
+            return KeyBean(idx, isExist, isLeft, isCharging, rfid, mac)
+        }
     }
 
     /**
@@ -259,6 +263,10 @@ class DockBean(
         override fun toString(): String {
             return "LockBean(rfid=$rfid)"
         }
+
+        fun clone(): LockBean {
+            return LockBean(idx, isExist, rfid)
+        }
     }
 
     /**