From a7fef2846505b08e0711345b17902e7381612d23 Mon Sep 17 00:00:00 2001
From: whyclxw <810412026@qq.com>
Date: 星期二, 25 三月 2025 14:02:16 +0800
Subject: [PATCH] 查询锁的蓝牙开启时间段记录添加area_path

---
 src/main/java/com/whyc/service/SubTableService.java |   83 +++++++++++++++++++++++++++++++++++++++--
 1 files changed, 78 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/whyc/service/SubTableService.java b/src/main/java/com/whyc/service/SubTableService.java
index f29dbef..12d3dcd 100644
--- a/src/main/java/com/whyc/service/SubTableService.java
+++ b/src/main/java/com/whyc/service/SubTableService.java
@@ -78,16 +78,67 @@
         return list;
     }
 
-
+    //閿佺殑鍘嗗彶璁板綍
+    public List<LockHis> getLockHisWithReal(LockHis his) {
+        String sql="SELECT * FROM db_lock_his."+ his.getRecordYear()+" history " +
+                " where history.lock_id="+  his.getLockId() ;
+        if(his.getStartTime()!=null){
+            sql+=" and record_time  >='"+ ThreadLocalUtil.format(his.getStartTime(),1)+"' ";
+        }
+        if(his.getEndTime()!=null){
+            sql+=" and record_time  <='"+ThreadLocalUtil.format(his.getEndTime(),1)+"' ";
+        }
+        sql+="  ORDER BY record_time asc ";
+        List<LockHis> list=sqlExecuteService.executeQuery_call(sql, new CallBack() {
+            @Override
+            public List getResults(ResultSet rs) throws SQLException {
+                List list=new ArrayList();
+                while (rs.next()){
+                    LockHis data=new LockHis();
+                    data.setNum(rs.getInt("num"));
+                    data.setLockId(rs.getInt("lock_id"));
+                    data.setRecordTime(rs.getTimestamp("record_time"));
+                    data.setLockState(rs.getInt("lock_state"));
+                    data.setUnlockType(rs.getInt("unlock_type"));
+                    data.setUnlockId(rs.getString("unlock_id"));
+                    list.add(data);
+                }
+                return list;
+            }
+        });
+        return list;
+    }
     //閿佺殑鍛婅鍘嗗彶璁板綍鎬绘暟
     public int getLockAlmHisCount(LockAlarmHis his) {
         String sql="SELECT  count(*) as number FROM db_lock_alarm."+ his.getRecordYear()+" history " +
-                " where history.lock_id="+ his.getLockId() ;
+                " where  1=1 ";
+        if(his.getLids()!=null&&his.getLids().size()>0){
+            List<Integer> lids=his.getLids();
+            sql+=" and  history.lock_id in (";
+            for (int i=0;i<lids.size();i++) {
+                if(i==lids.size()-1){
+                    sql=sql+lids.get(i)+") ";
+                }else{
+                    sql=sql+lids.get(i)+",";
+                }
+            }
+        }
         if(his.getStartTime()!=null){
             sql+=" and alm_start_time  >='"+ ThreadLocalUtil.format(his.getStartTime(),1)+"' ";
         }
         if(his.getEndTime()!=null){
             sql+=" and alm_start_time  <='"+ThreadLocalUtil.format(his.getEndTime(),1)+"' ";
+        }
+        if(his.getAlmIds()!=null){
+            String[] almId=his.getAlmIds().split(",");
+            sql+=" and  history.alm_id in (";
+            for (int i=0;i<almId.length;i++) {
+                if(i==almId.length-1){
+                    sql=sql+almId[i]+") ";
+                }else{
+                    sql=sql+almId[i]+",";
+                }
+            }
         }
         List list = sqlExecuteService.executeQuery_call(sql, new CallBack() {
             @Override
@@ -109,17 +160,39 @@
         return num;
     }
     //閿佺殑鍛婅鍘嗗彶璁板綍
-    public List<LockHis> getLockAlmHisList(LockAlarmHis his) {
+    public List<LockAlarmHis> getLockAlmHisList(LockAlarmHis his) {
         String sql="SELECT * FROM db_lock_alarm."+ his.getRecordYear()+" history " +
-                " where history.lock_id="+  his.getLockId() ;
+                " where 1=1 " ;
+        if(his.getLids()!=null&&his.getLids().size()>0){
+            List<Integer> lids=his.getLids();
+            sql+=" and  history.lock_id in (";
+            for (int i=0;i<lids.size();i++) {
+                if(i==lids.size()-1){
+                    sql=sql+lids.get(i)+") ";
+                }else{
+                    sql=sql+lids.get(i)+",";
+                }
+            }
+        }
         if(his.getStartTime()!=null){
             sql+=" and alm_start_time  >='"+ ThreadLocalUtil.format(his.getStartTime(),1)+"' ";
         }
         if(his.getEndTime()!=null){
             sql+=" and alm_start_time  <='"+ThreadLocalUtil.format(his.getEndTime(),1)+"' ";
         }
+        if(his.getAlmIds()!=null){
+            String[] almId=his.getAlmIds().split(",");
+            sql+=" and  history.alm_id in (";
+            for (int i=0;i<almId.length;i++) {
+                if(i==almId.length-1){
+                    sql=sql+almId[i]+") ";
+                }else{
+                    sql=sql+almId[i]+",";
+                }
+            }
+        }
         sql+="  ORDER BY alm_start_time asc  limit "+ his.getLimitStart()+","+ his.getLimitEnd()+" ";
-        List<LockHis> list=sqlExecuteService.executeQuery_call(sql, new CallBack() {
+        List<LockAlarmHis> list=sqlExecuteService.executeQuery_call(sql, new CallBack() {
             @Override
             public List getResults(ResultSet rs) throws SQLException {
                 List list=new ArrayList();

--
Gitblit v1.9.1