Browse Source

refactor(流程优化):
- 新增锁具不足的弹窗
- 新增注释
- 修改portmanager为可空类型防止连接失败返回直接报错闪退

周文健 6 months ago
parent
commit
d129b77b09

+ 14 - 4
app/src/main/java/com/grkj/iscs/BusinessManager.kt

@@ -216,7 +216,9 @@ object BusinessManager {
     }
 
     /****************************************** ModBus ******************************************/
-
+    /**
+     * 链接底座
+     */
     fun connectDock(isNeedInit: Boolean = false) {
         ModBusController.interruptReadTrashBinStatus(false)
         ModBusController.start(MyApplication.instance!!.applicationContext)
@@ -227,14 +229,23 @@ object BusinessManager {
         }
     }
 
+    /**
+     * 断开底座链接
+     */
     fun disconnectDock() {
         ModBusController.stop()
     }
 
+    /**
+     * 注册状态监听
+     */
     fun registerStatusListener(key: Any, listener: (DockBean) -> Unit) {
         listeners.add(DeviceListener(key, listener))
     }
 
+    /**
+     * 取消注册状态监听
+     */
     fun unregisterListener(key: Any) {
         val it = listeners.iterator()
         while (it.hasNext()) {
@@ -416,7 +427,6 @@ object BusinessManager {
                                         }
                                         // TODO 蓝牙通信
                                     }
-//                                        ModBusController.controlKeyBuckle(false, isLeft = true, dockBean.addr.toInt() - 1)
                                 }
 
                                 DEVICE_TYPE_LOCK -> {
@@ -486,7 +496,7 @@ object BusinessManager {
     /**
      * 更新所有锁仓状态
      */
-    fun updateAllBuckleStatus(done: () -> Unit){
+    fun updateAllBuckleStatus(done: () -> Unit) {
         ModBusController.updateAllBuckleStatus(done)
     }
 
@@ -591,7 +601,7 @@ object BusinessManager {
             val msg =
                 MyApplication.instance!!.applicationContext.resources.getString(R.string.lock_is_not_enough)
             LogUtil.w(msg)
-            tipStr = msg
+            lockMap.clear()
         }
 
         var key: Pair<Byte, DockBean.KeyBean?>? = null

+ 24 - 8
app/src/main/java/com/grkj/iscs/modbus/ModBusManager.kt

@@ -17,14 +17,16 @@ import kotlinx.coroutines.channels.Channel
  */
 class ModBusManager(
     // 底层串口管理器
-    val portManager: PortManager,
+    val portManager: PortManager?,
     // 是否输出详细信息
     val verbose: Boolean = false
 ) {
-    @Volatile private var running = true
+    @Volatile
+    private var running = true
 
     /** 正在发送的任务 */
-    @Volatile private var sending: FrameTask? = null
+    @Volatile
+    private var sending: FrameTask? = null
 
     /** 等待发送队列 */
     private val pendings = Channel<FrameTask>(Channel.UNLIMITED)
@@ -39,7 +41,7 @@ class ModBusManager(
 
     init {
         // 串口监听,回调在单独线程中执行
-        portManager.listen { res ->
+        portManager?.listen { res ->
             if (verbose) LogUtil.i("接收:${res.toHexStrings()}")
             synchronized(lock) {
                 sending?.run {
@@ -74,7 +76,7 @@ class ModBusManager(
         synchronized(lock) {
             sending?.run {
                 if (shouldSend()) {
-                    if (portManager.send(req)) {
+                    if (portManager?.send(req) == true) {
                         afterSent()
                         if (verbose) LogUtil.i("发送:${req.toHexStrings()}")
                     } else {
@@ -110,7 +112,7 @@ class ModBusManager(
     fun stop() {
         running = false
         job?.cancel()
-        portManager.close()
+        portManager?.close()
     }
 
     /**
@@ -182,11 +184,25 @@ class ModBusManager(
             sendToAll(frame) {
                 if (running) {
                     listener(it)
-                    Executor.delayOnIO({ if (running) repeatSendToAll(frame, interrupt, listener, delayMills) }, delayMills)
+                    Executor.delayOnIO({
+                        if (running) repeatSendToAll(
+                            frame,
+                            interrupt,
+                            listener,
+                            delayMills
+                        )
+                    }, delayMills)
                 }
             }
         } else {
-            Executor.delayOnIO({ if (running) repeatSendToAll(frame, interrupt, listener, delayMills) }, delayMills)
+            Executor.delayOnIO({
+                if (running) repeatSendToAll(
+                    frame,
+                    interrupt,
+                    listener,
+                    delayMills
+                )
+            }, delayMills)
         }
         return this
     }

+ 21 - 1
app/src/main/java/com/grkj/iscs/view/presenter/JobProgressPresenter.kt

@@ -147,7 +147,27 @@ class JobProgressPresenter : BasePresenter<IJobProgressView>() {
                                 && BusinessManager.mDeviceTakeList.none { it.deviceType == DEVICE_TYPE_KEY && it.ticketId == ticketId }
                     LogUtil.i("needLockCount = $needLockCount , readyLockCount = $readyLockCount, realCount = $realCount, isNeedKey = $isNeedKey")
                     BusinessManager.checkEquipCount(realCount, isNeedKey) { keyPair, lockMap ->
-                        if (keyPair == null) {
+                        if (lockMap.isEmpty()) {
+                            Executor.runOnMain {
+                                val dialog = TipDialog(mContext!!)
+                                dialog.setTip(mContext!!.getString(R.string.lock_is_not_enough_stop_issue_ticket))
+                                var state = 0
+                                dialog.setConfirmListener {
+                                    state = 1
+                                    BusinessManager.sendLoadingEventMsg(null, false)
+                                }
+                                dialog.setOnCancelListener {
+                                    state = 2
+                                    BusinessManager.sendLoadingEventMsg(null, false)
+                                }
+                                dialog.setOnDismissListener {
+                                    if (state == 0) {
+                                        BusinessManager.sendLoadingEventMsg(null, false)
+                                    }
+                                }
+                                dialog.show()
+                            }
+                        } else if (keyPair == null) {
                             Executor.runOnMain {
                                 val dialog = TipDialog(mContext!!)
                                 dialog.setTip(mContext!!.getString(R.string.no_key_available_dialog_tip))

+ 1 - 0
app/src/main/res/values-en/strings.xml

@@ -332,4 +332,5 @@
     <string name="current_user_does_not_have_the_authority_to_colock">The current user does not have the authority to colock</string>
     <string name="current_user_does_not_have_the_authority_to_unlock_colock">The current user does not have the authority to unlock colock</string>
     <string name="all_point_have_other_job_not_finish">all point have other job not finish,do you want to continue?</string>
+    <string name="lock_is_not_enough_stop_issue_ticket">lock is not enough, stop issue ticket</string>
 </resources>

+ 1 - 0
app/src/main/res/values-zh/strings.xml

@@ -332,4 +332,5 @@
     <string name="current_user_does_not_have_the_authority_to_colock">当前用户无权共锁</string>
     <string name="current_user_does_not_have_the_authority_to_unlock_colock">当前用户无权解除共锁</string>
     <string name="all_point_have_other_job_not_finish">所有隔离点存在其他作业未完成,是否继续拆锁恢复?</string>
+    <string name="lock_is_not_enough_stop_issue_ticket">锁具数量不足,停止下发作业票</string>
 </resources>

+ 1 - 0
app/src/main/res/values/strings.xml

@@ -332,4 +332,5 @@
     <string name="current_user_does_not_have_the_authority_to_colock">当前用户无权共锁</string>
     <string name="current_user_does_not_have_the_authority_to_unlock_colock">当前用户无权解除共锁</string>
     <string name="all_point_have_other_job_not_finish">所有隔离点存在其他作业未完成,是否继续拆锁恢复?</string>
+    <string name="lock_is_not_enough_stop_issue_ticket">锁具数量不足,停止下发作业票</string>
 </resources>