فهرست منبع

refactor(更新)
- 上锁解锁优先检查有没有待取设备和待发作业票
- 异常处理修改无效的问题
- 筛选用户无效的问题

周文健 4 ماه پیش
والد
کامیت
55998dbf92

+ 0 - 11
app/src/main/java/com/grkj/iscs/features/main/dialog/data_manage/FilterUserDialog.kt

@@ -45,17 +45,6 @@ class FilterUserDialog(
                 binding.deactivateRb.id -> false
                 else -> null
             }
-            if (name.isEmpty() || card.isEmpty() || (ISCSConfig.isWorkstationOn && station.isEmpty()) || status == null) {
-                PopTip.build().tipDialog(
-                    when {
-                        name.isEmpty() -> R.string.please_input_nickname
-                        card.isEmpty() -> R.string.please_input_card_code
-                        ISCSConfig.isWorkstationOn && station.isEmpty() -> R.string.please_select_area
-                        else -> R.string.please_select_status
-                    }
-                )
-                return@setOnClickListener
-            }
             onConfirm(UserManageFilterVo(name, card, station, status))
             dialog?.dismiss()
             clearFields()

+ 56 - 2
app/src/main/java/com/grkj/iscs/features/main/fragment/job_manage/JobExecuteFragment.kt

@@ -34,11 +34,13 @@ import com.grkj.data.data.EventConstants
 import com.grkj.data.data.MainDomainData
 import com.grkj.data.model.dos.WorkflowStep
 import com.grkj.iscs.features.main.dialog.CheckFaceDialog
+import com.grkj.ui_base.business.ModbusBusinessManager
 import com.grkj.ui_base.dialog.TipDialog
 import com.grkj.ui_base.utils.CommonUtils
 import com.grkj.ui_base.utils.event.RFIDCardReadEvent
 import com.grkj.ui_base.utils.event.UiEvent
 import com.grkj.ui_base.utils.extension.toggleExpandView
+import com.grkj.ui_base.utils.modbus.DeviceConst
 import com.kongzue.dialogx.dialogs.PopTip
 import com.sik.sikcore.data.GlobalDataTempStore
 import com.sik.sikcore.extension.setDebouncedClickListener
@@ -90,11 +92,63 @@ class JobExecuteFragment : BaseFragment<FragmentJobExecuteBinding>() {
             }
         }
         binding.toLock.setDebouncedClickListener {
+            if (ModbusBusinessManager.hasAnyDeviceWaitTakeByTicketId(
+                    DeviceConst.DEVICE_TYPE_LOCK,
+                    viewModel.ticketId
+                )
+            ) {
+                showLoading(getString(com.grkj.ui_base.R.string.please_take_out_ready_device_first))
+                return@setDebouncedClickListener
+            }
+            if (ModbusBusinessManager.hasAnyDeviceWaitTakeByTicketId(
+                    DeviceConst.DEVICE_TYPE_KEY,
+                    viewModel.ticketId
+                )
+            ) {
+                showLoading(getString(com.grkj.ui_base.R.string.check_key_and_lock))
+                val rfid = ModbusBusinessManager.getWaitTakeDeviceByTicketId(
+                    DeviceConst.DEVICE_TYPE_KEY,
+                    viewModel.ticketId
+                )?.nfc
+                rfid?.let {
+                    val keyMac = ModbusBusinessManager.getKeyMacByRfid(it)
+                    ModbusBusinessManager.checkTicketAndSendTicket(keyMac)
+                    return@setDebouncedClickListener
+                } ?: run {
+                    hideLoading()
+                }
+            }
             viewModel.toLock().observe(this) {
 
             }
         }
         binding.toUnlock.setDebouncedClickListener {
+            if (ModbusBusinessManager.hasAnyDeviceWaitTakeByTicketId(
+                    DeviceConst.DEVICE_TYPE_LOCK,
+                    viewModel.ticketId
+                )
+            ) {
+                showLoading(getString(com.grkj.ui_base.R.string.please_take_out_ready_device_first))
+                return@setDebouncedClickListener
+            }
+            if (ModbusBusinessManager.hasAnyDeviceWaitTakeByTicketId(
+                    DeviceConst.DEVICE_TYPE_KEY,
+                    viewModel.ticketId
+                )
+            ) {
+                showLoading(getString(com.grkj.ui_base.R.string.check_key_and_lock))
+                val rfid = ModbusBusinessManager.getWaitTakeDeviceByTicketId(
+                    DeviceConst.DEVICE_TYPE_KEY,
+                    viewModel.ticketId
+                )?.nfc
+                rfid?.let {
+                    val keyMac = ModbusBusinessManager.getKeyMacByRfid(it)
+                    ModbusBusinessManager.checkTicketAndSendTicket(keyMac)
+                    return@setDebouncedClickListener
+                } ?: run {
+                    hideLoading()
+                }
+            }
             viewModel.toUnLock().observe(this) {
 
             }
@@ -408,7 +462,7 @@ class JobExecuteFragment : BaseFragment<FragmentJobExecuteBinding>() {
                                         TipDialog.showInfo(
                                             msg = CommonUtils.getStr(
                                                 com.grkj.ui_base.R.string.confirm_to_colock,
-                                                colocker.nickName
+                                                colocker.nickName?:""
                                             ).toString(), countDownTime = 10, onConfirmClick = {
                                                 colocker.jobStatus = "1"
                                                 viewModel.colockerStatusChange(colocker)
@@ -427,7 +481,7 @@ class JobExecuteFragment : BaseFragment<FragmentJobExecuteBinding>() {
                                         TipDialog.showInfo(
                                             msg = CommonUtils.getStr(
                                                 com.grkj.ui_base.R.string.confirm_to_uncolock,
-                                                colocker.nickName
+                                                colocker.nickName?:""
                                             ).toString(), countDownTime = 10, onConfirmClick = {
                                                 colocker.jobStatus = "2"
                                                 viewModel.colockerStatusChange(colocker)

+ 3 - 0
app/src/main/java/com/grkj/iscs/features/main/fragment/user_info/UserInfoFragment.kt

@@ -107,6 +107,9 @@ class UserInfoFragment : BaseFragment<FragmentUserInfoBinding>() {
     override fun initData() {
         super.initData()
         MainDomainData.userInfo?.avatar?.let {
+            if (it.isEmpty()){
+                return
+            }
             if (it.file().exists()) {
                 val avatar = ImageConvertUtils.base64ToBitmap(it.file().readText())
                 binding.avatar.load(avatar)

+ 5 - 1
data/src/main/java/com/grkj/data/model/dos/IsExceptionStandard.kt

@@ -10,7 +10,7 @@ class IsExceptionStandard : BaseBean() {
 
     @PrimaryKey(autoGenerate = true)
     @ColumnInfo(name = "exception_id")
-    var exceptionId: Int = 0
+    var exceptionId: Long = 0
 
     @ColumnInfo(name = "exception_type")
     var exceptionType: Int = 0
@@ -33,5 +33,9 @@ class IsExceptionStandard : BaseBean() {
 
     @ColumnInfo(name = "release_time")
     var releaseTime: String? = null
+    override fun toString(): String {
+        return "IsExceptionStandard(exceptionId=$exceptionId, exceptionType=$exceptionType, exceptionStatus=$exceptionStatus, exceptionDescription=$exceptionDescription, processApplication=$processApplication, reporterId=$reporterId, occurrenceTime=$occurrenceTime, releaseTime=$releaseTime)"
+    }
+
 
 }

+ 1 - 1
data/src/main/java/com/grkj/data/model/vo/IsJobTicketUserDataVo.kt

@@ -6,5 +6,5 @@ import com.grkj.data.model.dos.IsJobTicketUser
  * 作业人员详细数据实体
  */
 class IsJobTicketUserDataVo : IsJobTicketUser() {
-    var nickName: String = ""
+    var nickName: String? = ""
 }

+ 4 - 2
data/src/main/java/com/grkj/data/repository/impl/standard/ExceptionRepository.kt

@@ -77,7 +77,8 @@ class ExceptionRepository @Inject constructor(
             it.releaseTime = TimeUtils.nowString(TimeUtils.DEFAULT_DATE_HOUR_MIN_SEC_FORMAT)
         }
         isExceptionData?.let {
-            exceptionDao.updateException(isExceptionData)
+            logger.info("已取消的异常:${it}")
+            exceptionDao.updateException(it)
         }
     }
 
@@ -137,7 +138,8 @@ class ExceptionRepository @Inject constructor(
             it.releaseTime = TimeUtils.nowString(TimeUtils.DEFAULT_DATE_HOUR_MIN_SEC_FORMAT)
         }
         isExceptionData?.let {
-            exceptionDao.updateException(isExceptionData)
+            logger.info("已处理的异常:${it}")
+            exceptionDao.updateException(it)
         }
     }
 

+ 24 - 28
data/src/main/java/com/grkj/data/repository/impl/standard/JobTicketRepository.kt

@@ -580,37 +580,33 @@ class JobTicketRepository @Inject constructor(
             jobTicketDao.getTicketDataByTicketId(ticketId) ?: return NextJobPrompt.NO_NEW_JOB
         val modeId = ticketData.modeId ?: return NextJobPrompt.NO_NEW_JOB
 
-        // 2. 取所有点位;无点位无法补单
+        // 2. 取流程定义,只考虑同时含“上锁”和“解锁”的模式
+        val stepDefs = workflowStepDao.getStepsByMode(modeId)
+        if (stepDefs.none { it.enableLock } || stepDefs.none { it.enableUnlock }) {
+            // 纯上锁或纯解锁,不在本逻辑范围内
+            return NextJobPrompt.NO_NEW_JOB
+        }
+
+        // 3. 取所有点位;无点位无法补单
         val points = jobTicketDao.getTicketPointsByTicketId(ticketId)
         if (points.isEmpty()) return NextJobPrompt.NO_NEW_JOB
 
-        // 3. 从 workflow 里找所有“上锁”和“解锁”步骤的索引
-        val stepDefs = workflowStepDao.getStepsByMode(modeId)
-        val lockIndices = stepDefs.filter { it.enableLock }.map { it.stepIndex }
-        val unlockIndices = stepDefs.filter { it.enableUnlock }.map { it.stepIndex }
-
-        // 4. 根据最大的索引值决定“最后一次”语义是上锁还是解锁
-        val lastLockIdx = lockIndices.maxOrNull()
-        val lastUnlockIdx = unlockIndices.maxOrNull()
-        val finalActionIsLock = when {
-            lastLockIdx == null && lastUnlockIdx == null -> return NextJobPrompt.NO_NEW_JOB
-            lastUnlockIdx == null -> true   // 只有上锁
-            lastLockIdx == null -> false  // 只有解锁
-            lastLockIdx > lastUnlockIdx -> true   // 上锁在后
-            else -> false  // 解锁在后
-        }
-
-        // 5. 判断点位现状:假设 pointStatus == "1" 表示已上锁
-        val allLocked = points.all { it.pointStatus == "1" }
-        val allUnlocked = points.all { it.pointStatus != "1" }
-
-        // 6. 最终提示逻辑
-        return if (finalActionIsLock) {
-            // 如果“最后要做”的是上锁,且没都上锁,就补上锁作业;全上锁了就不补
-            if (!allLocked) NextJobPrompt.CREATE_LOCK_JOB else NextJobPrompt.NO_NEW_JOB
-        } else {
-            // 如果“最后要做”的是解锁,且没都解锁,就补解锁作业;全解锁了就不补
-            if (!allUnlocked) NextJobPrompt.CREATE_UNLOCK_JOB else NextJobPrompt.NO_NEW_JOB
+        // 4. 取已完成的步骤(stepStatus == "1" 表示已做过)
+        val doneStepIds = jobTicketDao.getJobTicketStepDataByTicketId(ticketId)
+            .filter { it.stepStatus == "1" }
+            .map { it.workflowStepId }
+            .toSet()
+
+        // 5. 判断“上锁”/“解锁”哪一步已执行过
+        val hasDoneLock = stepDefs.any { it.enableLock && doneStepIds.contains(it.stepId) }
+        val hasDoneUnlock = stepDefs.any { it.enableUnlock && doneStepIds.contains(it.stepId) }
+
+        // 6. 根据完成情况决定下一步
+        return when {
+            !hasDoneLock && !hasDoneUnlock -> NextJobPrompt.NO_NEW_JOB // 上锁+解锁都没作业,就不做
+            !hasDoneLock -> NextJobPrompt.CREATE_LOCK_JOB    // 还没上锁,就先上锁
+            !hasDoneUnlock -> NextJobPrompt.CREATE_UNLOCK_JOB// 上锁做了,但没解锁,就去解锁
+            else -> NextJobPrompt.NO_NEW_JOB                  // 上锁+解锁都做过了,或已扫尾
         }
     }
 

+ 17 - 3
ui-base/src/main/java/com/grkj/ui_base/business/ModbusBusinessManager.kt

@@ -103,6 +103,13 @@ object ModbusBusinessManager {
         return mDeviceTakeList.find { it.deviceType == deviceType && rfid == it.nfc }
     }
 
+    /**
+     * 获取待取设备
+     */
+    fun getWaitTakeDeviceByTicketId(deviceType: Int, ticketId: Long): DeviceTakeUpdate? {
+        return mDeviceTakeList.find { it.deviceType == deviceType && ticketId == it.ticketId }
+    }
+
     /**
      * 根据作业票获取是否有指定设备未取
      */
@@ -275,9 +282,9 @@ object ModbusBusinessManager {
                             (keyPage?.records?.filter { it.exStatus == keyStatusList.find { d -> d.dictLabel == "异常" }?.dictValue }
                                 ?.map { it.keyNfc ?: "" }?.toMutableList()
                                 ?: mutableListOf()).apply {
-                                    addAll(mDeviceTakeList.filter { it.deviceType == DeviceConst.DEVICE_TYPE_KEY && it.ticketId != ticketId }
-                                        .map { it.nfc })
-                                }
+                                addAll(mDeviceTakeList.filter { it.deviceType == DeviceConst.DEVICE_TYPE_KEY && it.ticketId != ticketId }
+                                    .map { it.nfc })
+                            }
                         )
                     }
                     if (keyPair == null) {
@@ -588,4 +595,11 @@ object ModbusBusinessManager {
             BleBusinessManager.handleGiveKey(itKey)
         }
     }
+
+    /**
+     * 根据rfid获取mac地址
+     */
+    fun getKeyMacByRfid(rfid: String): String {
+        return ModBusController.getKeyByRfid(rfid)?.mac ?: ""
+    }
 }

+ 3 - 3
ui-base/src/main/java/com/grkj/ui_base/utils/ble/BleConnectionManager.kt

@@ -106,11 +106,11 @@ object BleConnectionManager {
                     }
                     if (power < 50) {//如果电量小于50就打开仓位充电
                         ModBusController.controlKeyCharge(true, bleBean.bleDevice.mac) {
-                            logger.info("钥匙: ${bleBean.bleDevice.mac} 开始充电")
+                            logger.debug("钥匙: ${bleBean.bleDevice.mac} 开始充电")
                         }
                     } else {
                         ModBusController.controlKeyCharge(false, bleBean.bleDevice.mac) {
-                            logger.info("钥匙: ${bleBean.bleDevice.mac} 关闭充电")
+                            logger.debug("钥匙: ${bleBean.bleDevice.mac} 关闭充电")
                         }
                     }
                 }
@@ -502,7 +502,7 @@ object BleConnectionManager {
      * 获取电池电量
      */
     fun getBatteryPower(bleDevice: BleDevice, isHeartBeat: Boolean = false) {
-        logger.info("获取电池电量:${bleDevice.mac},是否为心跳:${isHeartBeat}")
+        logger.debug("获取电池电量:${bleDevice.mac},是否为心跳:${isHeartBeat}")
         BleCmdManager.getPower(bleDevice.mac, object : CustomBleWriteCallback() {
             override fun onWriteSuccess(p0: Int, p1: Int, p2: ByteArray?) {
             }