فهرست منبع

refactor(更新)
- 首页数据统计增加

周文健 4 ماه پیش
والد
کامیت
55e977bc2f

+ 8 - 1
app/src/main/java/com/grkj/iscs/features/main/viewmodel/home/HomeViewModel.kt

@@ -70,7 +70,14 @@ class HomeViewModel @Inject constructor(
         return liveData(Dispatchers.IO) {
             inProgressJobNum =
                 jobTicketRepository.getInProgressJobSize(realTimeDataZoneId, selectedWorkflowMode)
-            allJobNum = jobTicketRepository.getAllJobSize(realTimeDataZoneId, startTime, endTime)
+            lockedPointNum =
+                jobTicketRepository.getLockedPointsCount(realTimeDataZoneId, selectedWorkflowMode)
+            usedHardwareNum = jobTicketRepository.getUsedHardwareCount(realTimeDataZoneId, selectedWorkflowMode)
+            allJobNum = jobTicketRepository.getAllJobSize(overviewDataZoneId, startTime, endTime)
+            allPointNum =
+                hardwareRepository.getAllPointCount(overviewDataZoneId)
+            allHardwareNum =
+                hardwareRepository.getAllHardwareCount()
             emit(true)
         }
     }

+ 30 - 0
data/src/main/java/com/grkj/data/dao/HardwareDao.kt

@@ -483,4 +483,34 @@ interface HardwareDao {
     @Update
     fun updateSlotsInfo(slots: IsLockCabinetSlots)
 
+    /**
+     * 统计所有硬件
+     */
+    @Query("""
+        SELECT
+          COUNT(*) AS total_count
+        FROM is_key k
+        INNER JOIN is_lock l
+          ON k.hardware_id = l.hardware_id
+        INNER JOIN is_rfid_token r
+          ON k.hardware_id = r.hardware_id
+        WHERE
+          -- 钥匙、挂锁 外部状态正常
+          (k.ex_status   IS NULL or (:keyStatus IS NULL OR trim(:keyStatus) = '' OR k.ex_status=:keyStatus))
+          AND  (l.ex_status   IS NULL or (:lockStatus IS NULL OR trim(:lockStatus) = '' OR l.ex_status=:lockStatus))
+          AND (r.status   IS NULL or (:rfidTokenStatus IS NULL OR trim(:rfidTokenStatus) = '' OR r.status=:rfidTokenStatus))
+        ;
+    """)
+    fun getAllHardwareCount(lockStatus: String?, keyStatus: String?, rfidTokenStatus: String?): Int
+
+    /**
+     * 根据区域统计所有点位
+     */
+    @Query("""
+        select count(1) 
+        from is_isolation_point iip
+        where (:workstationId IS NULL OR trim(:workstationId) = '' OR iip.workstation_id = :workstationId)
+    """)
+    fun getAllPointCount(workstationId: Long?): Int
+
 }

+ 27 - 0
data/src/main/java/com/grkj/data/dao/JobTicketDao.kt

@@ -502,4 +502,31 @@ interface JobTicketDao {
     """
     )
     fun getAllLockedPointDataWithExceptionJob(workstationPointIds: List<Long>): List<IsJobTicketPoints>
+
+    /**
+     * 获取锁定中的点位
+     */
+    @Query("""
+        select count(1) from is_job_ticket_points ijtp 
+        left join is_job_ticket ijt on ijtp.ticket_id = ijt.ticket_id
+        where ijtp.point_status = "1" 
+        and ijt.ticket_status in ('1','2','3','4','7')
+        and (:selectedWorkflowMode IS NULL OR trim(:selectedWorkflowMode) = '' OR ijt.mode_id=:selectedWorkflowMode)
+        and (:realTimeDataZoneId IS NULL OR trim(:realTimeDataZoneId) = '' OR ijt.workstation_id = :realTimeDataZoneId)
+        group by ijtp.point_id
+    """)
+    fun getLockedPointsCount(realTimeDataZoneId: Long?, selectedWorkflowMode: Long?): Int
+
+    /**
+     * 获取使用中的硬件数量
+     */
+    @Query("""
+        select count(1) from is_job_ticket_points ijtp
+        left join is_job_ticket ijt on ijtp.ticket_id = ijt.ticket_id
+        where ijt.ticket_status in ('1','2','3','4','7')
+        and (:workflowModeId IS NULL OR trim(:workflowModeId) = '' OR ijt.mode_id = :workflowModeId)
+        and (:workstationId IS NULL OR trim(:workstationId) = '' OR ijt.workstation_id = :workstationId)
+        group by ijtp.lock_id
+    """)
+    fun getUsedHardwareCount(workstationId: Long?, workflowModeId: Long?): Int
 }

+ 10 - 0
data/src/main/java/com/grkj/data/repository/IHardwareRepository.kt

@@ -345,4 +345,14 @@ interface IHardwareRepository {
      * 更新锁仓状态
      */
     fun updateSlotsInfo(slots: IsLockCabinetSlots)
+
+    /**
+     * 获取所有点位根据地区和时间过滤
+     */
+    fun getAllPointCount(overviewWorkstationId: Long?): Int
+
+    /**
+     * 获取所有硬件数量
+     */
+    fun getAllHardwareCount(): Int
 }

+ 10 - 0
data/src/main/java/com/grkj/data/repository/IJobTicketRepository.kt

@@ -233,4 +233,14 @@ interface IJobTicketRepository {
      * 根据作业id获取异常id
      */
     fun getExceptionIdByTicketId(ticketId: Long): Long
+
+    /**
+     * 获取锁定中的点位
+     */
+    fun getLockedPointsCount(realTimeDataZoneId: Long?, selectedWorkflowMode: Long?): Int
+
+    /**
+     * 获取正在使用中的硬件数量
+     */
+    fun getUsedHardwareCount(workstationId: Long?, workflowModeId: Long?): Int
 }

+ 8 - 0
data/src/main/java/com/grkj/data/repository/impl/network/NetworkHardwareRepository.kt

@@ -311,4 +311,12 @@ class NetworkHardwareRepository  @Inject constructor() : BaseRepository(), IHard
     override fun updateSlotsInfo(slots: IsLockCabinetSlots) {
         TODO("Not yet implemented")
     }
+
+    override fun getAllPointCount(overviewWorkstationId: Long?): Int {
+        TODO("Not yet implemented")
+    }
+
+    override fun getAllHardwareCount(): Int {
+        TODO("Not yet implemented")
+    }
 }

+ 8 - 0
data/src/main/java/com/grkj/data/repository/impl/network/NetworkJobTicketRepository.kt

@@ -229,4 +229,12 @@ class NetworkJobTicketRepository  @Inject constructor() : BaseRepository(), IJob
     override fun getExceptionIdByTicketId(ticketId: Long): Long {
         TODO("Not yet implemented")
     }
+
+    override fun getLockedPointsCount(realTimeDataZoneId: Long?, selectedWorkflowMode: Long?): Int {
+        TODO("Not yet implemented")
+    }
+
+    override fun getUsedHardwareCount(workstationId: Long?, workflowModeId: Long?): Int {
+        TODO("Not yet implemented")
+    }
 }

+ 11 - 0
data/src/main/java/com/grkj/data/repository/impl/standard/HardwareRepository.kt

@@ -511,4 +511,15 @@ class HardwareRepository @Inject constructor(
     override fun updateSlotsInfo(slots: IsLockCabinetSlots) {
         return hardwareDao.updateSlotsInfo(slots)
     }
+
+    override fun getAllHardwareCount(): Int {
+        val lockStatus = CommonDictDataEnum.PADLOCK_STATUS.commonDictRes.find { it.dictLabel == "正常" }?.dictValue
+        val keyStatus = CommonDictDataEnum.KEY_STATUS.commonDictRes.find { it.dictLabel == "正常" }?.dictValue
+        val rfidTokenStatus = CommonDictDataEnum.RFID_TOKEN_STATUS.commonDictRes.find { it.dictLabel == "正常" }?.dictValue
+        return hardwareDao.getAllHardwareCount(lockStatus,keyStatus,rfidTokenStatus)
+    }
+
+    override fun getAllPointCount(overviewWorkstationId: Long?): Int {
+        return hardwareDao.getAllPointCount(overviewWorkstationId)
+    }
 }

+ 8 - 0
data/src/main/java/com/grkj/data/repository/impl/standard/JobTicketRepository.kt

@@ -560,4 +560,12 @@ class JobTicketRepository @Inject constructor(
     override fun getExceptionIdByTicketId(ticketId: Long): Long {
         return exceptionDao.getExceptionIdByTicketId(ticketId)
     }
+
+    override fun getLockedPointsCount(realTimeDataZoneId: Long?, selectedWorkflowMode: Long?): Int {
+        return jobTicketDao.getLockedPointsCount(realTimeDataZoneId, selectedWorkflowMode)
+    }
+
+    override fun getUsedHardwareCount(workstationId: Long?, workflowModeId: Long?): Int {
+        return jobTicketDao.getUsedHardwareCount(workstationId, workflowModeId)
+    }
 }