Browse Source

补充本地钥匙、锁具数量检查和分配逻辑

Frankensteinly 11 months ago
parent
commit
2ba383c5cc

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

@@ -90,6 +90,8 @@ object BusinessManager {
                                     NetApi.getKeyInfo(rfid) {
                                         if (it != null && !it.macAddress.isNullOrEmpty()) {
                                             ModBusController.updateKeyMac(dockBean.addr.toInt(), keyBean.isLeft, it.macAddress)
+                                        } else {
+                                            ToastUtils.tip(R.string.get_key_info_fail)
                                         }
                                     }
                                     // TODO 蓝牙通信
@@ -210,8 +212,12 @@ object BusinessManager {
 
     /**
      * 检查钥匙和锁具数量
+     *
+     * @param needLockCount 需要的锁具的数量(可能在别的机柜取过)
+     *
+     * @return 返回能提供的锁具和钥匙的数量 Pair<锁具数量,钥匙数量>
      */
-    fun checkEquipCount(pointCount: Int) {
+    fun checkEquipCount(needLockCount: Int): Pair<Int, Int> {
         var lockCount = 0
         var keyCount = 0
         val lockDockList = ModBusController.dockList.filter { it.type == DOCK_TYPE_LOCK || it.type == DOCK_TYPE_PORTABLE }
@@ -223,7 +229,7 @@ object BusinessManager {
             keyCount += it.getKeyList().size
         }
         var tipStr = ""
-        if (lockCount < pointCount) {
+        if (lockCount < needLockCount) {
             val msg = MyApplication.instance!!.applicationContext.resources.getString(R.string.lock_is_not_enough)
             LogUtil.w(msg)
             tipStr = msg
@@ -240,7 +246,7 @@ object BusinessManager {
         if (tipStr.isNotEmpty()) {
             ToastUtils.tip(tipStr)
         }
-        // TODO 弹出锁、弹出钥匙
+        return Pair(lockCount, keyCount)
     }
 
     /**

+ 16 - 10
app/src/main/java/com/grkj/iscs/fragment/TicketListFragment.kt

@@ -11,8 +11,6 @@ import com.grkj.iscs.model.Constants.TICKET_STATUS_READY_TO_LOCK
 import com.grkj.iscs.model.Constants.TICKET_STATUS_READY_TO_UNLOCK
 import com.grkj.iscs.model.vo.ticket.TicketPageRespVO
 import com.grkj.iscs.presenter.TicketListPresenter
-import com.grkj.iscs.util.SPUtils
-import com.grkj.iscs.util.ToastUtils
 import com.zhy.adapter.recyclerview.CommonAdapter
 import com.zhy.adapter.recyclerview.base.ViewHolder
 
@@ -35,13 +33,13 @@ class TicketListFragment(var type: Int) :
         mBinding?.loTitile?.tvEndTime?.text = resources.getString(R.string.end_time)
 
         mBinding?.rvCurrent?.adapter = object : CommonAdapter<TicketPageRespVO.Record>(context, R.layout.item_rv_sop, dataList) {
-            override fun convert(holder: ViewHolder, ticket: TicketPageRespVO.Record?, position: Int) {
-                holder.setText(R.id.tv_number, "${ticket?.ticketCode}")
-                holder.setText(R.id.tv_name, ticket?.ticketName)
-                holder.setText(R.id.tv_type, presenter?.getTicketTypeName(ticket?.ticketType))
-                holder.setText(R.id.tv_start_time, ticket?.ticketStartTime)
-                holder.setText(R.id.tv_end_time, ticket?.ticketEndTime)
-                holder.setText(R.id.tv_action, when(ticket?.ticketStatus) {
+            override fun convert(holder: ViewHolder, record: TicketPageRespVO.Record?, position: Int) {
+                holder.setText(R.id.tv_number, "${record?.ticketCode}")
+                holder.setText(R.id.tv_name, record?.ticketName)
+                holder.setText(R.id.tv_type, presenter?.getTicketTypeName(record?.ticketType))
+                holder.setText(R.id.tv_start_time, record?.ticketStartTime)
+                holder.setText(R.id.tv_end_time, record?.ticketEndTime)
+                holder.setText(R.id.tv_action, when(record?.ticketStatus) {
                     TICKET_STATUS_NOT_STARTED -> resources.getString(R.string.not_started)
                     TICKET_STATUS_READY_TO_LOCK -> resources.getString(R.string.ready_to_lock)
                     TICKET_STATUS_PROCESSING -> resources.getString(R.string.on_process)
@@ -50,7 +48,15 @@ class TicketListFragment(var type: Int) :
                     else -> ""
                 })
                 holder.setOnClickListener(R.id.tv_action) {
-
+                    when(record?.ticketStatus) {
+                        // TODO 数量待修改
+                        TICKET_STATUS_NOT_STARTED -> presenter?.startTicket(record.pointCount)
+                        TICKET_STATUS_READY_TO_LOCK -> resources.getString(R.string.ready_to_lock)
+                        TICKET_STATUS_PROCESSING -> resources.getString(R.string.on_process)
+                        TICKET_STATUS_READY_TO_UNLOCK -> resources.getString(R.string.ready_to_unlock)
+                        TICKET_STATUS_FINISHED -> resources.getString(R.string.finished)
+                        else -> ""
+                    }
                 }
             }
         }

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

@@ -180,19 +180,19 @@ class DockBean(
     }
 
     fun getKeyList(): MutableList<KeyBean> {
-        return deviceList.filter { it.type == 0 } as MutableList<KeyBean>
+        return deviceList.filter { it.type == DEVICE_TYPE_KEY } as MutableList<KeyBean>
     }
 
     fun getLockList() : MutableList<LockBean> {
-        return deviceList.filter { it.type == 1 } as MutableList<LockBean>
+        return deviceList.filter { it.type == DEVICE_TYPE_LOCK } as MutableList<LockBean>
     }
 
     fun getCardList(): MutableList<CardBean> {
-        return deviceList.filter { it.type == 2 } as MutableList<CardBean>
+        return deviceList.filter { it.type == DEVICE_TYPE_CARD } as MutableList<CardBean>
     }
 
     fun getFingerPrintList(): MutableList<FingerPrintBean> {
-        return deviceList.filter { it.type == 3 } as MutableList<FingerPrintBean>
+        return deviceList.filter { it.type == DEVICE_TYPE_FINGERPRINT } as MutableList<FingerPrintBean>
     }
 
     fun getBit(by: Byte): String {

+ 37 - 0
app/src/main/java/com/grkj/iscs/modbus/ModBusController.kt

@@ -1,6 +1,7 @@
 package com.grkj.iscs.modbus
 
 import android.content.Context
+import com.grkj.iscs.R
 import com.grkj.iscs.extentions.removeLeadingZeros
 import com.grkj.iscs.extentions.toHexStrings
 import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_ELEC_LOCK_BOARD
@@ -8,6 +9,7 @@ import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_KEY
 import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_LOCK
 import com.grkj.iscs.model.DeviceConst.DOCK_TYPE_PORTABLE
 import com.grkj.iscs.util.Executor
+import com.grkj.iscs.util.ToastUtils
 import com.grkj.iscs.util.log.LogUtil
 import java.util.concurrent.Executors
 import java.util.stream.Collectors
@@ -445,4 +447,39 @@ object ModBusController {
             println("____________________________________")
         }
     }
+
+    /**
+     * 打开一个钥匙卡扣(基于钥匙柜和便携柜不存在接一起的情况)
+     *
+     * @return 打开的钥匙RFID
+     */
+    fun openOneKeyBuckle(): String? {
+        val keyDockList = dockList.filter { it.type == DOCK_TYPE_KEY || it.type == DOCK_TYPE_PORTABLE }
+        val keyList = keyDockList.flatMap { it.getKeyList() }.filter { it.isExist }
+        if (keyList.isEmpty()) {
+            ToastUtils.tip(R.string.key_is_not_enough)
+            return null
+        }
+        return keyList[0].rfid
+    }
+
+    /**
+     * 根据数量打开锁具卡扣(基于锁柜和便携柜不存在接一起的情况)
+     *
+     * @param lockCount 需要打开的锁具数量
+     *
+     * @return 打开的锁具RFID列表
+     */
+    fun openLockBuckle(lockCount: Int): MutableList<String> {
+        val lockDockList = dockList.filter { it.type == DOCK_TYPE_LOCK || it.type == DOCK_TYPE_PORTABLE }
+        val lockList = lockDockList.flatMap { it.getLockList() }.filter { it.isExist }
+        if (lockList.size < lockCount) {
+            ToastUtils.tip(R.string.lock_is_not_enough)
+        }
+        val rfidList = mutableListOf<String>()
+        for (i in 0 until lockCount.coerceAtMost(lockList.size)) {
+            lockList[i].rfid?.let { rfidList.add(it) }
+        }
+        return rfidList
+    }
 }

+ 0 - 1
app/src/main/java/com/grkj/iscs/model/Constants.kt

@@ -16,5 +16,4 @@ object Constants {
     const val TICKET_STATUS_PROCESSING = "2"          // 进行中
     const val TICKET_STATUS_READY_TO_UNLOCK = "3"     // 待解锁
     const val TICKET_STATUS_FINISHED = "4"            // 已结束
-    const val TICKET_STATUS_EXPIRED = "5"             // 已失效
 }

+ 14 - 0
app/src/main/java/com/grkj/iscs/presenter/TicketListPresenter.kt

@@ -1,5 +1,6 @@
 package com.grkj.iscs.presenter
 
+import com.grkj.iscs.BusinessManager
 import com.grkj.iscs.R
 import com.grkj.iscs.base.BasePresenter
 import com.grkj.iscs.iview.ITicketListView
@@ -52,4 +53,17 @@ class TicketListPresenter : BasePresenter<ITicketListView>() {
             
         }
     }
+
+    /**
+     * @param needLockCount 需要的锁具的数量(可能在别的机柜取过)
+     */
+    fun startTicket(needLockCount: Int) {
+        val equipCountPair = BusinessManager.checkEquipCount(needLockCount)
+        val lockCount = equipCountPair.first
+        val keyCount = equipCountPair.second
+
+        if (lockCount in 1..needLockCount) {
+
+        }
+    }
 }

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

@@ -59,7 +59,7 @@
     <string name="ticket_id_is_null">作业票编号不能为空</string>
     <string name="lock_is_not_enough">锁具数量不足</string>
     <string name="key_is_not_enough">钥匙数量不足</string>
-
+    <string name="get_key_info_fail">获取钥匙信息失败</string>
 
     <!--  演示页  -->
     <string name="presentation_select_sop">选择SOP</string>