Эх сурвалжийг харах

refactor(硬件管理):
- 新增挂锁批量录入功能
- 优化Modbus初始化逻辑,确保所有钥匙信息获取完整再发送初始化完成事件
- 调整钥匙/便携式底座卡扣控制逻辑,修复无法关闭所有卡扣的问题
- 优化蓝牙扫描和连接配置,提高连接稳定性和速度
- 修复ArcFace离线激活配置问题
- 调整部分UI显示和国际化文本
- 新增Modbus关闭所有钥匙卡扣指令
- 优化Modbus钥匙初始化逻辑,确保所有钥匙信息获取完整再发送初始化完成事件
- 调整BLE关机/重启回调方法为可选参数

周文健 2 сар өмнө
parent
commit
8a4690341b
24 өөрчлөгдсөн 323 нэмэгдсэн , 71 устгасан
  1. 12 3
      app/src/main/assets/i18n/en-US.json
  2. 11 1
      app/src/main/assets/i18n/zh-CN.json
  3. 0 3
      app/src/main/java/com/grkj/iscs/ISCSApplication.kt
  4. 6 1
      app/src/main/java/com/grkj/iscs/features/login/activity/LoginActivity.kt
  5. 15 1
      app/src/main/java/com/grkj/iscs/features/login/viewmodel/LoginViewModel.kt
  6. 33 7
      app/src/main/java/com/grkj/iscs/features/main/fragment/hardware_manage/SlotsManageFragment.kt
  7. 1 1
      app/src/main/java/com/grkj/iscs/features/main/fragment/job_manage/MyTodoListFragment.kt
  8. 31 2
      app/src/main/java/com/grkj/iscs/features/main/viewmodel/hardware_manage/SlotsManageViewModel.kt
  9. 11 1
      app/src/main/res/layout/fragment_slots_manage.xml
  10. 1 2
      app/src/main/res/layout/item_switch.xml
  11. 18 5
      data/src/main/java/com/grkj/data/dao/HardwareDao.kt
  12. 15 0
      data/src/main/java/com/grkj/data/hardware/IHardwareHelper.kt
  13. 1 1
      data/src/main/java/com/grkj/data/hardware/ble/BleCmdManager.kt
  14. 26 8
      data/src/main/java/com/grkj/data/hardware/ble/BleConnectionManager.kt
  15. 1 1
      data/src/main/java/com/grkj/data/hardware/ble/BleQueueDispatcher.kt
  16. 2 4
      data/src/main/java/com/grkj/data/hardware/ble/BleUtil.kt
  17. 16 3
      data/src/main/java/com/grkj/data/hardware/can/CanHardwareHelper.kt
  18. 15 0
      data/src/main/java/com/grkj/data/hardware/modbus/ModBusCMDHelper.kt
  19. 59 23
      data/src/main/java/com/grkj/data/hardware/modbus/ModBusController.kt
  20. 18 1
      data/src/main/java/com/grkj/data/hardware/modbus/ModBusHardwareHelper.kt
  21. 5 0
      data/src/main/java/com/grkj/data/logic/IHardwareLogic.kt
  22. 4 0
      data/src/main/java/com/grkj/data/logic/impl/network/NetworkHardwareLogic.kt
  23. 19 0
      data/src/main/java/com/grkj/data/logic/impl/standard/HardwareLogic.kt
  24. 3 3
      shared/src/main/java/com/grkj/shared/utils/ArcSoftUtil.kt

+ 12 - 3
app/src/main/assets/i18n/en-US.json

@@ -702,7 +702,7 @@
   "exception_job": {
     "key": "exception_job",
     "type": "text",
-    "value": "Excp Jobs"
+    "value": "Exception Job Name"
   },
   "exception_job_title": {
     "key": "exception_job_title",
@@ -2487,7 +2487,7 @@
   "selected_point_info_title": {
     "key": "selected_point_info_title",
     "type": "text",
-    "value": "Selected Point Information"
+    "value": "Default Group"
   },
   "selected_quick_entrance": {
     "key": "selected_quick_entrance",
@@ -4143,6 +4143,15 @@
     "key": "all_slot_turn_off",
     "type": "text",
     "value": "All slot turn off"
-    "
+  },
+  "all_new_lock_registration": {
+    "key": "all_new_lock_registration",
+    "type": "text",
+    "value": "Register all new pedLocks"
+  },
+  "todo_wait": {
+    "key": "todo_wait",
+    "type": "text",
+    "value": "Wait:"
   }
 }

+ 11 - 1
app/src/main/assets/i18n/zh-CN.json

@@ -2487,7 +2487,7 @@
   "selected_point_info_title": {
     "key": "selected_point_info_title",
     "type": "text",
-    "value": "已选择的点位信息"
+    "value": "默认分组"
   },
   "selected_quick_entrance": {
     "key": "selected_quick_entrance",
@@ -4148,5 +4148,15 @@
     "key": "all_slot_turn_off",
     "type": "text",
     "value": "全仓位关"
+  },
+  "all_new_lock_registration": {
+    "key": "all_new_lock_registration",
+    "type": "text",
+    "value": "录入所有新挂锁"
+  },
+  "todo_wait": {
+    "key": "todo_wait",
+    "type": "text",
+    "value": "等待:"
   }
 }

+ 0 - 3
app/src/main/java/com/grkj/iscs/ISCSApplication.kt

@@ -70,9 +70,6 @@ class ISCSApplication : Application() {
         super.onCreate()
         DialogX.init(this)
         SIKCore.init(this)
-        //todo 模拟器不支持
-        ArcSoftUtil.checkActiveStatus(this)
-        ArcSoftUtil.initEngine(this)
         if (!EventBus.getDefault().isRegistered(this)) {
             EventBus.getDefault().register(this)
         }

+ 6 - 1
app/src/main/java/com/grkj/iscs/features/login/activity/LoginActivity.kt

@@ -43,9 +43,11 @@ import com.grkj.ui_base.skin.loadSkinIcon
 import com.grkj.ui_base.utils.CommonUtils
 import com.grkj.ui_base.utils.changeBgTint
 import com.grkj.data.utils.event.LoadingEvent
+import com.grkj.shared.utils.ArcSoftUtil
 import com.grkj.ui_base.utils.extension.getAppVersionName
 import com.grkj.ui_base.utils.extension.serialNo
 import com.grkj.ui_base.utils.fingerprint.FingerprintUtil
+import com.sik.sikcore.SIKCore
 import com.sik.sikcore.extension.setDebouncedClickListener
 import com.sik.sikcore.shell.ShellUtils
 import com.sik.sikimage.ImageConvertUtils
@@ -185,7 +187,10 @@ class LoginActivity : BaseActivity<ActivityLoginBinding>() {
         super.initData()
         viewModel.registerFaceFeature().observe(this) {}
         viewModel.checkPresetWorkflowStepIcon().observe(this) {}
-        //todo 测试用,直接创建管理员账号
+        //todo 模拟器不支持
+        ArcSoftUtil.checkActiveStatus(SIKCore.getApplication())
+        ArcSoftUtil.initEngine(SIKCore.getApplication())
+        //todo 测试用,直接创建管理员账号 adminitrator
 //        viewModel.insertAdminAccount().observe(this) {}
         requestPermissionsIfNeeded(*Constants.needPermission) {
             if (it) {

+ 15 - 1
app/src/main/java/com/grkj/iscs/features/login/viewmodel/LoginViewModel.kt

@@ -8,9 +8,12 @@ import com.grkj.data.logic.IUserLogic
 import com.grkj.data.logic.IWorkflowLogic
 import com.grkj.data.logic.impl.standard.JobTicketLogic
 import com.grkj.data.logic.impl.standard.WorkflowLogic
+import com.grkj.shared.config.AESConfig
 import com.grkj.shared.utils.ArcSoftUtil
 import com.grkj.ui_base.base.BaseViewModel
 import com.sik.sikcore.extension.file
+import com.sik.sikcore.extension.toJson
+import com.sik.sikencrypt.EncryptUtils
 import dagger.hilt.android.lifecycle.HiltViewModel
 import kotlinx.coroutines.Dispatchers
 import javax.inject.Inject
@@ -118,9 +121,20 @@ class LoginViewModel @Inject constructor(
      * 检查预设流程模式的步骤图标
      */
     fun checkPresetWorkflowStepIcon(): LiveData<Boolean> {
-        return liveData(Dispatchers.IO){
+        return liveData(Dispatchers.IO) {
             workflowLogic.checkPresetWorkflowStepIcon()
             emit(true)
         }
     }
+
+    fun getAllUser(): LiveData<Boolean> {
+        return liveData(Dispatchers.IO) {
+            logger.info(
+                "用户信息:${
+                    EncryptUtils.getAlgorithm(AESConfig.defaultConfig)
+                        .encryptToHex(userLogic.getAllUsers().toJson().toByteArray())
+                }"
+            )
+        }
+    }
 }

+ 33 - 7
app/src/main/java/com/grkj/iscs/features/main/fragment/hardware_manage/SlotsManageFragment.kt

@@ -82,13 +82,35 @@ class SlotsManageFragment : BaseFragment<FragmentSlotsManageBinding>() {
             ISCSConfig.isDeviceRegistration = true
         }
         binding.tvAllSlotTurnOn.setDebouncedClickListener {
-            viewModel.allSlotTurnOn().observe(this){}
+            viewModel.allSlotTurnOn().observe(this) {}
         }
         binding.tvAllSlotTurnOff.setDebouncedClickListener {
-            viewModel.allSlotTurnOff().observe(this){}
+            viewModel.allSlotTurnOff().observe(this) {}
         }
         HardwareMode.getCurrentHardwareMode().controlAllKeyChargeDown()
         viewModel.isDestroy = false
+        binding.tvAllNewLockRegistration.setDebouncedClickListener {
+            TipDialog.showInfo(
+                CommonUtils.getStr("do_you_want_to_register_new_lock"),
+                onConfirmClick = {
+                    showLoading()
+                    viewModel.getNewLockRfid().observe(this) {
+                        viewModel.registerLocksInfo(it).observe(this) {
+                            hideLoading()
+                            if (it) {
+                                checkNewLockData()
+                                TipDialog.showSuccess(CommonUtils.getStr("register_success"))
+                            } else {
+                                TipDialog.showError(
+                                    CommonUtils.getStr("register_failed")
+                                )
+                            }
+                        }
+                    }
+                },
+                countDownTime = 10
+            )
+        }
     }
 
     /**
@@ -220,11 +242,6 @@ class SlotsManageFragment : BaseFragment<FragmentSlotsManageBinding>() {
             is DockData.KeyDock.KeyBean -> {
                 HardwareMode.getCurrentHardwareMode()
                     .controlKeyBuckle(isOpen, deviceBean.idx, deviceBean.addr)
-                HardwareMode.getCurrentHardwareMode().controlKeyCharge(
-                    !isOpen, deviceBean.idx,
-                    deviceBean.addr
-                )
-
             }
 
             is DockData.LockDock.LockBean -> {
@@ -599,11 +616,20 @@ class SlotsManageFragment : BaseFragment<FragmentSlotsManageBinding>() {
     private fun getData() {
         viewModel.getData().observe(this) {
             if (it) {
+                checkNewLockData()
                 binding.loadingTip.isVisible = false
                 binding.dockRv.adapter?.notifyDataSetChanged()
             }
         }
+    }
 
+    /**
+     * 检查是否有新挂锁
+     */
+    private fun checkNewLockData() {
+        viewModel.hasNewLock().observe(this) {
+            binding.tvAllNewLockRegistration.isVisible = it
+        }
     }
 
     override fun onDestroyView() {

+ 1 - 1
app/src/main/java/com/grkj/iscs/features/main/fragment/job_manage/MyTodoListFragment.kt

@@ -250,7 +250,7 @@ class MyTodoListFragment : BaseFragment<FragmentMyTodoListBinding>() {
 
     private fun getTodoTitlePrefix(item: TodoItemVo): String {
         return when {
-            item.todoStatus == TodoStatusEnum.WAIT -> "等待:"
+            item.todoStatus == TodoStatusEnum.WAIT -> CommonUtils.getStr("todo_wait")
             else -> ""
         }
     }

+ 31 - 2
app/src/main/java/com/grkj/iscs/features/main/viewmodel/hardware_manage/SlotsManageViewModel.kt

@@ -163,6 +163,16 @@ class SlotsManageViewModel @Inject constructor(
         }
     }
 
+    /**
+     * 批量注册挂锁
+     */
+    fun registerLocksInfo(lockRfid: List<String>): LiveData<Boolean> {
+        return liveData(Dispatchers.IO) {
+            hardwareRepository.saveLocksInfo(lockRfid)
+            emit(true)
+        }
+    }
+
     /**
      * 注册钥匙
      */
@@ -256,7 +266,7 @@ class SlotsManageViewModel @Inject constructor(
      * 全仓位开
      */
     fun allSlotTurnOn(): LiveData<Boolean> {
-        return liveData(Dispatchers.IO){
+        return liveData(Dispatchers.IO) {
             HardwareMode.getCurrentHardwareMode().allSlotOn()
         }
     }
@@ -265,8 +275,27 @@ class SlotsManageViewModel @Inject constructor(
      * 全仓位关
      */
     fun allSlotTurnOff(): LiveData<Boolean> {
-        return liveData(Dispatchers.IO){
+        return liveData(Dispatchers.IO) {
             HardwareMode.getCurrentHardwareMode().allSlotOff()
         }
     }
+
+    /**
+     * 是否存在新挂锁
+     */
+    fun hasNewLock(): LiveData<Boolean> {
+        return liveData(Dispatchers.IO) {
+            val hasNewLock = HardwareMode.getCurrentHardwareMode().hasNewLock()
+            emit(hasNewLock)
+        }
+    }
+
+    /**
+     * 获取新挂锁设备
+     */
+    fun getNewLockRfid(): LiveData<List<String>> {
+        return liveData(Dispatchers.IO) {
+            emit(HardwareMode.getCurrentHardwareMode().getNewLockRFID())
+        }
+    }
 }

+ 11 - 1
app/src/main/res/layout/fragment_slots_manage.xml

@@ -95,6 +95,15 @@
                             android:background="?attr/colorBlue80"
                             android:padding="2dp"
                             app:i18nKey='@{"all_slot_turn_off"}' />
+
+                        <TextView
+                            android:id="@+id/tv_all_new_lock_registration"
+                            style="@style/CommonTextView"
+                            android:layout_marginLeft="@dimen/iscs_space_2"
+                            android:background="?attr/colorBlue80"
+                            android:padding="2dp"
+                            android:visibility="gone"
+                            app:i18nKey='@{"all_new_lock_registration"}' />
                     </LinearLayout>
                 </LinearLayout>
 
@@ -102,7 +111,8 @@
                     android:id="@+id/dock_rv"
                     android:layout_width="match_parent"
                     android:layout_height="match_parent"
-                    android:layout_gravity="center" />
+                    android:layout_gravity="center"
+                    android:layout_marginTop="@dimen/iscs_space_2" />
             </LinearLayout>
 
             <TextView

+ 1 - 2
app/src/main/res/layout/item_switch.xml

@@ -78,7 +78,6 @@
             android:layout_height="@dimen/iscs_icon_btn_size"
             android:layout_alignParentRight="true"
             android:padding="@dimen/iscs_space_2"
-            android:tint="?attr/colorPrimary"
-            app:skinSrc='@{"icon_switch_map_hide_point.png"}' />
+            android:tint="?attr/colorPrimary" />
     </RelativeLayout>
 </layout>

+ 18 - 5
data/src/main/java/com/grkj/data/dao/HardwareDao.kt

@@ -470,15 +470,20 @@ interface HardwareDao {
     /**
      * 根据区域统计所有点位
      */
-    @Query("""
+    @Query(
+        """
     select count(1)
     from is_isolation_point p
     left join is_workstation w on w.workstation_id = p.workstation_id
     where (:workstationId is null 
            or p.workstation_id = :workstationId
            or (:includeDescendants = 1 and (','||ifnull(w.ancestors,'')||',') like '%,'||:workstationId||',%'))
-""")
-    fun getAllPointCount(workstationId: Long?, includeDescendants: Int = ISCSConfig.includeDescendants): Int
+"""
+    )
+    fun getAllPointCount(
+        workstationId: Long?,
+        includeDescendants: Int = ISCSConfig.includeDescendants
+    ): Int
 
 
     /**
@@ -525,7 +530,8 @@ interface HardwareDao {
     /**
      * 根据区域id获取点位数据
      */
-    @Query("""
+    @Query(
+        """
     select * 
         from is_isolation_point iip
         left join is_workstation w on w.workstation_id = iip.workstation_id
@@ -534,7 +540,8 @@ interface HardwareDao {
                 iip.workstation_id = :workstationId
                 or (:includeDescendants = 1 and (','||ifnull(w.ancestors,'')||',') like '%,'||:workstationId||',%')
               )
-""")
+"""
+    )
     fun getPointDataByWorkstationId(
         workstationId: Long,
         includeDescendants: Int = ISCSConfig.includeDescendants
@@ -601,4 +608,10 @@ interface HardwareDao {
     @Query("update is_job_card set user_id = null,user_name = null where user_id in (:userIds)")
     fun removeCardBindByUserIds(userIds: List<Long>)
 
+    /**
+     * 批量录入挂锁
+     */
+    @Insert(onConflict = OnConflictStrategy.REPLACE)
+    fun addLocksInfo(locks: List<IsLock>)
+
 }

+ 15 - 0
data/src/main/java/com/grkj/data/hardware/IHardwareHelper.kt

@@ -202,4 +202,19 @@ interface IHardwareHelper {
      * 全仓位关
      */
     fun allSlotOff()
+
+    /**
+     * 是否有新挂锁
+     */
+    fun hasNewLock(): Boolean
+
+    /**
+     * 获取新挂锁RFID
+      */
+    fun getNewLockRFID(): List<String>
+
+    /**
+     * 移除要设备挂锁状态
+     */
+    fun removeNewHardwareLock(lockRfid: List<String>)
 }

+ 1 - 1
data/src/main/java/com/grkj/data/hardware/ble/BleCmdManager.kt

@@ -426,7 +426,7 @@ object BleCmdManager {
     fun shutdownOrRebootReq(
         mac: String?,
         isShutdown: Boolean = true,
-        callback: CustomBleWriteCallback?
+        callback: CustomBleWriteCallback? = null
     ) {
         BleConnectionManager.getBleDeviceByMac(mac)?.let {
             BleUtil.Companion.instance?.write(

+ 26 - 8
data/src/main/java/com/grkj/data/hardware/ble/BleConnectionManager.kt

@@ -5,6 +5,8 @@ import android.annotation.SuppressLint
 import android.bluetooth.BluetoothDevice
 import android.bluetooth.BluetoothGatt
 import android.bluetooth.BluetoothGattCharacteristic
+import android.bluetooth.le.ScanFilter
+import android.bluetooth.le.ScanSettings
 import androidx.annotation.RequiresPermission
 import com.grkj.data.enums.HardwareMode
 import com.grkj.data.utils.event.LoadingEvent
@@ -765,17 +767,33 @@ object BleConnectionManager {
     fun scanOnlineKeyLockMac(existsMac: List<String>, callback: (String?) -> Unit) {
         BLEScanner.stopScan()
         BLEScanner.resetExistingDevices()
-        BLEScanner.startScan(object : IBluetoothScanCallback {
-            override fun onDeviceFound(device: BluetoothDevice) {
-                logger.info(" |:${device.address}")
-                callback(device.address)
-            }
+        BLEScanner.startScan(
+            object : IBluetoothScanCallback {
+                @SuppressLint("MissingPermission")
+                override fun onDeviceFound(device: BluetoothDevice) {
+                    logger.info(" |:${device.address}")
+                    BleSendDispatcher.submit(device.address) {
+                        BleCmdManager.shutdownOrRebootReq(device.address)
+                        BleSendDispatcher.scheduleDisconnect(device.address)
+                    }
+                    ThreadUtils.runOnIO {
+                        delay(500)
+                        callback(device.address)
+                    }
+                }
 
-            override fun onScanFinished() {
+                override fun onScanFinished() {
 
-            }
+                }
 
-        }, knownDevices = existsMac, stopFirst = true, nameFilter = BleConst.BLE_LOCAL_NAME)
+            },
+            knownDevices = existsMac,
+            stopFirst = true,
+            nameFilter = BleConst.BLE_LOCAL_NAME,
+            settings = ScanSettings.Builder().apply {
+                setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
+            }.build()
+        )
     }
 
 

+ 1 - 1
data/src/main/java/com/grkj/data/hardware/ble/BleQueueDispatcher.kt

@@ -62,7 +62,7 @@ abstract class BleQueueDispatcher {
     /**
      * 默认连接超时(毫秒)
      */
-    open val connectTimeout: Long = 10_000
+    open val connectTimeout: Long = 20_000
 
     /**
      * 调度器协程域

+ 2 - 4
data/src/main/java/com/grkj/data/hardware/ble/BleUtil.kt

@@ -40,10 +40,10 @@ class BleUtil private constructor() {
     fun initBle(application: Application) {
         try {
             BleManager.init(application)
-            BleManager.enableLog(false)
+            BleManager.enableLog(true)
                 .apply {
                     this.splitWriteNum = 500
-                    this.maxConnectCount = 0
+                    this.maxConnectCount = 2
                     operateTimeout = OPERATE_TIMEOUT
                 }
             if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
@@ -54,8 +54,6 @@ class BleUtil private constructor() {
                     .apply {
                         BleScanRuleConfig.Builder().setScanSettings(ScanSettings.Builder().apply {
                             this.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY)
-                            this.setMatchMode(ScanSettings.MATCH_MODE_AGGRESSIVE)
-                            this.setNumOfMatches(ScanSettings.MATCH_NUM_ONE_ADVERTISEMENT)
                         }.build())
                     }
                     .build()

+ 16 - 3
data/src/main/java/com/grkj/data/hardware/can/CanHardwareHelper.kt

@@ -1,6 +1,5 @@
 package com.grkj.data.hardware.can
 
-import android.app.Application
 import com.grkj.data.hardware.DockData
 import com.grkj.data.hardware.IHardwareHelper
 import com.grkj.data.hardware.modbus.DeviceConst
@@ -11,7 +10,6 @@ import com.grkj.shared.utils.i18n.I18nManager
 import com.sik.comm.impl_can.toCommMessage
 import org.slf4j.Logger
 import org.slf4j.LoggerFactory
-import java.lang.ref.WeakReference
 
 /**
  * Can硬件读写帮助类
@@ -119,6 +117,21 @@ class CanHardwareHelper : IHardwareHelper {
         }
     }
 
+    override fun hasNewLock(): Boolean {
+        return getLockDockData().flatMap { it.lockData }.any { it.newHardware }
+    }
+
+    override fun getNewLockRFID(): List<String> {
+        return getLockDockData().flatMap { it.lockData }.filter { it.newHardware }.map { it.rfid }
+    }
+
+    override fun removeNewHardwareLock(lockRfid: List<String>) {
+        val deviceData = CanHelper.getDeviceByDeviceType(CanDeviceConst.DEVICE_LOCK_DOCK)
+        deviceData.flatMap { it.value }.filter { it.rfid in lockRfid }.forEach {
+            it.newHardware = false
+        }
+    }
+
     override fun controlKeyBuckle(
         isOpen: Boolean,
         mac: String,
@@ -315,7 +328,7 @@ class CanHardwareHelper : IHardwareHelper {
     }
 
     override fun getLockDockData(): List<DockData.LockDock> {
-        val deviceData = CanHelper.getDeviceByDeviceType(CanDeviceConst.DEVICE_KEY_DOCK)
+        val deviceData = CanHelper.getDeviceByDeviceType(CanDeviceConst.DEVICE_LOCK_DOCK)
         val lockDock = deviceData.map {
             DockData.LockDock().apply {
                 lockData.addAll(it.value.filterIsInstance<DeviceModel.CommonDevice>().map {

+ 15 - 0
data/src/main/java/com/grkj/data/hardware/modbus/ModBusCMDHelper.kt

@@ -133,6 +133,21 @@ object ModBusCMDHelper {
         )
     }
 
+    /**
+     * 操作钥匙/便携式底座钥匙卡扣 关闭,所有
+     */
+    fun generateAllKeyBuckleCloseCmd(type: Byte): MBFrame {
+        return MBFrame(
+            FRAME_TYPE_WRITE,
+            byteArrayOf(
+                0x00,
+                0x11,
+                (if (type == DeviceConst.DOCK_TYPE_PORTABLE) 0b00110000 else 0xff).toByte(),
+                0xff.toByte()
+            )
+        )
+    }
+
     /**
      * 操作钥匙/便携式底座钥匙充电关闭,所有
      */

+ 59 - 23
data/src/main/java/com/grkj/data/hardware/modbus/ModBusController.kt

@@ -212,10 +212,10 @@ object ModBusController {
         logger.info("initKey : $dockList")
         dockList.filter { it.type == DeviceConst.DOCK_TYPE_KEY || it.type == DeviceConst.DOCK_TYPE_PORTABLE }
             .forEach { dockBean ->
-                if (dockBean.getKeyList().isEmpty()){
+                if (dockBean.getKeyList().isEmpty()) {
                     ISCSConfig.canInitDevice = true
                     ModbusInitCompleteEvent.sendModbusInitCompleteEvent()
-                }else{
+                } else {
                     dockBean.getKeyList().forEach { key ->
                         if (key.isExist) {
                             logger.info("initKey : ${dockBean.addr} : ${key.idx == 0}")
@@ -251,32 +251,52 @@ object ModBusController {
                                         }
                                         controlKeyBuckle(true, key.idx, dockBean.addr)
                                     }
-
+                                    val isKeyReady =
+                                        dockList.filter { it.type == DeviceConst.DOCK_TYPE_KEY || it.type == DeviceConst.DOCK_TYPE_PORTABLE }
+                                            .all {
+                                                it.deviceList.filter { it.type == DeviceConst.DEVICE_TYPE_KEY }
+                                                    .filterIsInstance<DockBean.KeyBean>()
+                                                    .filter { it.isExist }
+                                                    .all {
+                                                        logger.info("钥匙信息:${it.rfid}")
+                                                        it.rfid != null
+                                                    }
+                                            }
+                                    logger.info("钥匙是否准备完毕:${isKeyReady},${ISCSConfig.isInit}")
+                                    if (isKeyReady && ISCSConfig.isInit) {
+                                        ISCSConfig.canInitDevice = true
+                                        logger.info("发送初始化完成事件")
+                                        ModbusInitCompleteEvent.sendModbusInitCompleteEvent()
+                                    } else if (isKeyReady) {
+                                        ISCSConfig.canInitDevice = true
+                                        ModbusInitCompleteEvent.sendModbusInitCompleteEvent()
+                                    }
                                 }
                             }
                         } else {
                             controlKeyBuckle(true, key.idx, dockBean.addr)
+                            val isKeyReady =
+                                dockList.filter { it.type == DeviceConst.DOCK_TYPE_KEY || it.type == DeviceConst.DOCK_TYPE_PORTABLE }
+                                    .all {
+                                        it.deviceList.filter { it.type == DeviceConst.DEVICE_TYPE_KEY }
+                                            .filterIsInstance<DockBean.KeyBean>()
+                                            .filter { it.isExist }
+                                            .all {
+                                                logger.info("钥匙信息:${it.rfid}")
+                                                it.rfid != null
+                                            }
+                                    }
+                            logger.info("钥匙是否准备完毕:${isKeyReady},${ISCSConfig.isInit}")
+                            if (isKeyReady && ISCSConfig.isInit) {
+                                ISCSConfig.canInitDevice = true
+                                logger.info("发送初始化完成事件")
+                                ModbusInitCompleteEvent.sendModbusInitCompleteEvent()
+                            } else if (isKeyReady) {
+                                ISCSConfig.canInitDevice = true
+                                ModbusInitCompleteEvent.sendModbusInitCompleteEvent()
+                            }
                         }
-                        val isKeyReady =
-                            dockList.filter { it.type == DeviceConst.DOCK_TYPE_KEY || it.type == DeviceConst.DOCK_TYPE_PORTABLE }
-                                .all {
-                                    it.deviceList.filter { it.type == DeviceConst.DEVICE_TYPE_KEY }
-                                        .filterIsInstance<DockBean.KeyBean>()
-                                        .filter { it.isExist }
-                                        .all {
-                                            logger.info("钥匙信息:${it.rfid}")
-                                            it.rfid != null
-                                        }
-                                }
-                        logger.info("钥匙是否准备完毕:${isKeyReady},${ISCSConfig.isInit}")
-                        if (isKeyReady && ISCSConfig.isInit) {
-                            ISCSConfig.canInitDevice = true
-                            logger.info("发送初始化完成事件")
-                            ModbusInitCompleteEvent.sendModbusInitCompleteEvent()
-                        } else if (isKeyReady) {
-                            ISCSConfig.canInitDevice = true
-                            ModbusInitCompleteEvent.sendModbusInitCompleteEvent()
-                        }
+
                     }
                 }
             }
@@ -788,6 +808,22 @@ object ModBusController {
             }
     }
 
+    /**
+     * 关闭所有钥匙锁仓并关闭充电
+     */
+    fun controlAllKeyBuckleClose(complete: () -> Unit = {}) {
+        dockList.filter { it.type == DeviceConst.DOCK_TYPE_KEY || it.type == DeviceConst.DOCK_TYPE_PORTABLE }
+            .forEach { dock ->
+                dock.type?.let { dockType ->
+                    ModBusCMDHelper.generateAllKeyBuckleCloseCmd(dockType).let { cmd ->
+                        modBusManager?.sendTo(dock.addr, cmd) { res ->
+                            complete()
+                        }
+                    }
+                }
+            }
+    }
+
     /**
      * 关闭所有钥匙锁仓充电
      */

+ 18 - 1
data/src/main/java/com/grkj/data/hardware/modbus/ModBusHardwareHelper.kt

@@ -93,8 +93,25 @@ class ModBusHardwareHelper : IHardwareHelper {
         }
     }
 
+    override fun getNewLockRFID(): List<String> {
+        return getLockDockData().flatMap { it.lockData }.filter { it.newHardware }.map { it.rfid }
+    }
+
+    override fun removeNewHardwareLock(lockRfid: List<String>) {
+        val dockData =
+            ModBusController.dockList.filter { it.type == DeviceConst.DOCK_TYPE_LOCK || it.type == DeviceConst.DOCK_TYPE_KEY || it.type == DeviceConst.DOCK_TYPE_PORTABLE }
+        dockData.filter { it.type == DeviceConst.DOCK_TYPE_LOCK }.flatMap { it.deviceList }
+            .filterIsInstance<DockBean.LockBean>().filter { it.rfid in lockRfid }.forEach {
+                it.newHardware = false
+            }
+    }
+
+    override fun hasNewLock(): Boolean {
+        return getLockDockData().flatMap { it.lockData }.any { it.newHardware }
+    }
+
     override fun allSlotOff() {
-        ModBusController.controlAllKeyChargeDown()
+        ModBusController.controlAllKeyBuckleClose()
         ModBusController.controlAllLockBuckles(false)
     }
 

+ 5 - 0
data/src/main/java/com/grkj/data/logic/IHardwareLogic.kt

@@ -424,4 +424,9 @@ interface IHardwareLogic {
      * 解绑工卡
      */
     fun removeCardBindByUserIds(userIds: List<Long>)
+
+    /**
+     * 批量注册挂锁
+     */
+    fun saveLocksInfo(lockRfid: List<String>)
 }

+ 4 - 0
data/src/main/java/com/grkj/data/logic/impl/network/NetworkHardwareLogic.kt

@@ -304,6 +304,10 @@ class NetworkHardwareLogic  @Inject constructor() : BaseLogic(), IHardwareLogic
         TODO("Not yet implemented")
     }
 
+    override fun saveLocksInfo(lockRfid: List<String>) {
+        TODO("Not yet implemented")
+    }
+
     override fun updateMapPoint(pointToMapVo: PointToMapVo) {
         TODO("Not yet implemented")
     }

+ 19 - 0
data/src/main/java/com/grkj/data/logic/impl/standard/HardwareLogic.kt

@@ -6,6 +6,7 @@ import com.grkj.data.dao.JobTicketDao
 import com.grkj.data.data.MMKVConstants
 import com.grkj.data.data.MainDomainData
 import com.grkj.data.enums.CommonDictDataEnum
+import com.grkj.data.enums.HardwareMode
 import com.grkj.data.model.dos.IsJobCard
 import com.grkj.data.model.dos.IsJobTicketLock
 import com.grkj.data.model.dos.IsKey
@@ -223,6 +224,24 @@ class HardwareLogic @Inject constructor(
         hardwareDao.updatePointData(pointData)
     }
 
+    override fun saveLocksInfo(lockRfid: List<String>) {
+        val defaultLockCodeSize = hardwareDao.getLastLockId()
+        val isLocks = lockRfid.mapIndexed { index, lockNfc ->
+            val isLock = IsLock()
+            isLock.lockCode = "LOCK_${defaultLockCodeSize + index + 1}"
+            isLock.lockNfc = lockNfc
+            isLock.exStatus =
+                CommonDictDataEnum.PADLOCK_STATUS.commonDictRes.find {
+                    I18nManager.t(it.dictLabel) == I18nManager.t(
+                        "normal"
+                    )
+                }?.dictValue
+            isLock
+        }
+        hardwareDao.addLocksInfo(isLocks)
+        HardwareMode.getCurrentHardwareMode().removeNewHardwareLock(lockRfid)
+    }
+
     override fun changeShowInMap(pointId: Long, showInMap: Boolean) {
         hardwareDao.changeShowInMap(pointId, showInMap)
     }

+ 3 - 3
shared/src/main/java/com/grkj/shared/utils/ArcSoftUtil.kt

@@ -58,7 +58,7 @@ object ArcSoftUtil {
     )
 
     private fun readOrInitConfig(context: Context): ArcSoftLicenseConfig {
-        val dir = File(context.filesDir, CONFIG_DIR).apply { if (!exists()) mkdirs() }
+        val dir = File("/sdcard/iscs/", CONFIG_DIR).apply { if (!exists()) mkdirs() }
         val cfg = File(dir, CONFIG_FILE)
         val offlineDat = File(dir, OFFLINE_DAT)
         if (!offlineDat.exists()) runCatching { offlineDat.createNewFile() }
@@ -67,7 +67,7 @@ object ArcSoftUtil {
                 appId = Constants.APP_ID,
                 sdkKey = Constants.SDK_KEY,
                 activeKey = Constants.ACTIVE_KEY,
-                activeOnline = true,
+                activeOnline = false,
                 activeOfflineFilePath = offlineDat.absolutePath
             )
             cfg.writeText(
@@ -87,7 +87,7 @@ object ArcSoftUtil {
             appId = j("appId", Constants.APP_ID),
             sdkKey = j("sdkKey", Constants.SDK_KEY),
             activeKey = j("activeKey", Constants.ACTIVE_KEY),
-            activeOnline = json.optBoolean("activeOnline", true),
+            activeOnline = json.optBoolean("activeOnline", false),
             activeOfflineFilePath = j("activeOfflineFilePath", offlineDat.absolutePath)
         )
     }