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/AreaInfService.java |  310 +++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 297 insertions(+), 13 deletions(-)

diff --git a/src/main/java/com/whyc/service/AreaInfService.java b/src/main/java/com/whyc/service/AreaInfService.java
index 19d3063..883ddb5 100644
--- a/src/main/java/com/whyc/service/AreaInfService.java
+++ b/src/main/java/com/whyc/service/AreaInfService.java
@@ -2,7 +2,9 @@
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
+import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
+import com.whyc.dto.HomeCtlGroupDto;
 import com.whyc.dto.Response;
 import com.whyc.mapper.*;
 import com.whyc.pojo.db_area.AreaInf;
@@ -10,6 +12,7 @@
 import com.whyc.pojo.db_area.KeyInf;
 import com.whyc.pojo.db_area.LockInf;
 import com.whyc.pojo.db_lock_ram.LockCtlLog;
+import com.whyc.pojo.db_lock_ram.LockReport;
 import com.whyc.pojo.db_user.UserInf;
 import com.whyc.util.ActionUtil;
 import com.whyc.util.PageInfoUtils;
@@ -21,6 +24,7 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.logging.LogRecord;
 import java.util.stream.Collectors;
 
 @Service
@@ -47,6 +51,13 @@
     @Autowired(required = false)
     private LockCtlLogService ctlLogService;
 
+    @Autowired(required = false)
+    private UserInfMapper uinfMapper;
+
+    @Autowired(required = false)
+    private LockReportService reportService;
+
+
 
     //鏌ョ湅褰撳墠鐢ㄦ埛绠$悊鐨勬墍鏈夊尯鍩�
    public List getAllAreaUser(int uid,int urole){
@@ -71,8 +82,8 @@
    }
 
     //鏌ヨ鎵�鏈夊尯鍩熶俊鎭�
-    public Response getAllAreaInf() {
-        UserInf uinf= ActionUtil.getUser();
+    public Response getAllAreaInf(String uname) {
+        UserInf uinf=uinfMapper.getUinfByUname(uname);
         if(uinf.getUrole()!=2) {//褰撳墠鐢ㄦ埛涓嶆槸瓒呯骇绠$悊鍛�
             List areaList=getAllAreaUser(uinf.getUid(),uinf.getUrole());
             List<AreaInf> list1 = mapper.selectAreaByUid(areaList, 1);
@@ -221,9 +232,9 @@
         }
     }
     //鍖哄煙绠$悊鍛樼櫥褰曟煡鐪嬭嚜宸辩鐞嗗尯鍩燂紝閿佸叿鍜屽尯鍩熷搴旂殑鐢ㄦ埛--鍖哄煙绠$悊鍛�
-    public Response getInfByAreaManage() {
+    public Response getInfByAreaManage(String uname) {
         Map<String,Object> map=new HashMap<>();
-        UserInf uinf=ActionUtil.getUser();
+        UserInf uinf=uinfMapper.getUinfByUname(uname);
         List areaList=getAllAreaUser(uinf.getUid(),uinf.getUrole());
         //閫氳繃鍖哄煙id鏌ヨ鎵�鏈夌殑閿�
         QueryWrapper linfWrapper=new QueryWrapper();
@@ -237,8 +248,8 @@
         return new Response().setII(1,true,map,"鍖哄煙绠$悊鍛樼櫥褰曟煡鐪嬭嚜宸辩鐞嗗尯鍩燂紝閿佸叿鍜屽尯鍩熷搴旂殑鐢ㄦ埛--鍖哄煙绠$悊鍛�");
     }
     //鍖哄煙绠$悊鍛樼偣鍑荤鐞嗙殑鍖哄煙璺宠浆--鍖哄煙绠$悊鍛�
-    public Response getAinfByManage() {
-        UserInf uinf=ActionUtil.getUser();
+    public Response getAinfByManage(String uname) {
+        UserInf uinf=uinfMapper.getUinfByUname(uname);
         List areaList=getAllAreaUser(uinf.getUid(),uinf.getUrole());
         QueryWrapper wrapper=new QueryWrapper();
         wrapper.in("id",areaList);
@@ -260,14 +271,14 @@
     }
 
     //鍖哄煙绠$悊鍛樼偣鍑绘煡鐪嬪紑閿佹搷浣滆褰�--鍖哄煙绠$悊鍛�
-    public Response getCtlog(int pageNum, int pageSize) {
+    public Response getCtlog(int pageNum, int pageSize,String uname) {
         Map<String,Object> map=new HashMap<>();
         PageInfo pageInfo=new PageInfo();
         map.put("sumLog",0);
         //map.put("goodLogNum",0);
         map.put("errorLogNum",0);
         map.put("allLogs",pageInfo);
-        UserInf uinf= ActionUtil.getUser();
+        UserInf uinf=uinfMapper.getUinfByUname(uname);
         //鏌ョ湅鎵�鏈夊尯鍩�
         List areaList=getAllAreaUser(uinf.getUid(),uinf.getUrole());
         //鏌ョ湅鍖哄煙涓嬫墍鏈夌殑閿�
@@ -303,15 +314,14 @@
         map.put("offLineNum",0);
         map.put("openNum",0);
         map.put("closeNum",0);
+        map.put("unLoadNum",0);
         List<LockInf> linfs=new ArrayList<>();
         map.put("allLinfs",linfs);
         List areaList=new ArrayList();
         areaList.add(id);
         getAllAreaId(id,areaList);
         //鏌ョ湅鍖哄煙涓嬫墍鏈夌殑閿�
-        QueryWrapper linfWrapper=new QueryWrapper();
-        linfWrapper.in("area_id",areaList);
-        linfs=linfMapper.selectList(linfWrapper);
+        linfs=linfMapper.selectAllLockById(areaList);
         if(linfs!=null&&linfs.size()>0){
             map.put("sumLinf",linfs.size());
             Map<Integer, List<LockInf>> onlinemap = linfs.stream().collect(Collectors.groupingBy(LockInf::getLockOnline));
@@ -326,14 +336,288 @@
             Map<Integer, List<LockInf>> openmap = linfs.stream().collect(Collectors.groupingBy(LockInf::getLockState));
             for (Integer open : openmap.keySet()) {
                 if(open==0){
-                    map.put("openNum", openmap.get(0).size());//闂攣
+                    map.put("closeNum", openmap.get(0).size());//闂攣
                 }
                 if(open==1){
-                    map.put("closeNum", openmap.get(1).size());//寮�閿�
+                    map.put("openNum", openmap.get(1).size());//寮�閿�
+                }
+                if(open==-1){
+                    map.put("unLoadNum", openmap.get(-1).size());//鏈畨瑁�
                 }
             }
             map.put("allLinfs",linfs);
         }
         return new Response().setII(1,true,map,"鍖哄煙绠$悊鍛樻煡鐪嬪尯鍩熶笅鐨勯攣鐨勭姸鎬�--鍖哄煙绠$悊鍛�");
     }
+
+    //鍖哄煙绠$悊鍛樻煡鐪嬫寚瀹氬尯鍩熶笅鐨勯攣鍏峰憡璀�(澶辫触鐨�)--鍖哄煙绠$悊鍛�
+    public Response getErrLogByUid(int pageNum, int pageSize,String uname) {
+        UserInf uinf=uinfMapper.getUinfByUname(uname);
+        //鏌ョ湅鎵�鏈夊尯鍩�
+        List areaList=getAllAreaUser(uinf.getUid(),uinf.getUrole());
+        //鏌ョ湅鍖哄煙涓嬫墍鏈夌殑閿�
+        QueryWrapper linfWrapper=new QueryWrapper();
+        linfWrapper.in("area_id",areaList);
+        List<LockInf> linfs=linfMapper.selectList(linfWrapper);
+        if(linfs!=null&&linfs.size()>0){
+            List<Integer> lockIds=linfs.stream().map(LockInf::getLockId) // 鎻愬彇鐢ㄦ埛鍚�
+                    .collect(Collectors.toList()); // 杞崲涓哄垪琛�*/
+            //鑾峰彇閿佺殑鏃ュ織
+            PageHelper.startPage(pageNum,pageSize);
+            List<LockCtlLog> logList=ctlLogService.getAllErrorLog(lockIds);
+            PageInfo pageInfo=new PageInfo(logList);
+            return new Response().setII(1,true,pageInfo,"鍖哄煙绠$悊鍛樼偣鍑绘煡鐪嬪紑閿佹搷浣滆褰�--鍖哄煙绠$悊鍛�");
+        }else{
+            return new Response().set(1,false,"鍖哄煙绠$悊鍛樼偣鍑绘煡鐪嬪紑閿佹搷浣滆褰�--鍖哄煙绠$悊鍛�");
+        }
+    }
+    //鍖哄煙绠$悊鍛樻煡鐪嬫寚瀹氬尯鍩熶笅鐨勯攣鍏峰憡璀�(鍏ㄩ儴鐨勭殑)--鍖哄煙绠$悊鍛�
+    public Response getAllLogByUid(int pageNum, int pageSize,String uname) {
+        UserInf uinf=uinfMapper.getUinfByUname(uname);
+        //鏌ョ湅鎵�鏈夊尯鍩�
+        List areaList=getAllAreaUser(uinf.getUid(),uinf.getUrole());
+        //鏌ョ湅鍖哄煙涓嬫墍鏈夌殑閿�
+        QueryWrapper linfWrapper=new QueryWrapper();
+        linfWrapper.in("area_id",areaList);
+        List<LockInf> linfs=linfMapper.selectList(linfWrapper);
+        if(linfs!=null&&linfs.size()>0){
+            List<Integer> lockIds=linfs.stream().map(LockInf::getLockId) // 鎻愬彇鐢ㄦ埛鍚�
+                    .collect(Collectors.toList()); // 杞崲涓哄垪琛�*/
+            //鑾峰彇閿佺殑鏃ュ織
+            PageHelper.startPage(pageNum,pageSize);
+            List<LockCtlLog> logList=ctlLogService.getAllLog(lockIds);
+            PageInfo pageInfo=new PageInfo(logList);
+            return new Response().setII(1,true,pageInfo,"鍖哄煙绠$悊鍛樼偣鍑绘煡鐪嬪紑閿佹搷浣滆褰�--鍖哄煙绠$悊鍛�");
+        }else{
+            return new Response().set(1,false,"鍖哄煙绠$悊鍛樼偣鍑绘煡鐪嬪紑閿佹搷浣滆褰�--鍖哄煙绠$悊鍛�");
+        }
+    }
+    //鍖哄煙绠$悊鍛樿褰曟墜鏈鸿摑鐗欏紑閿佹棩蹇�--鍖哄煙绠$悊鍛�
+    public Response setLogByUid(String mac, int result,String uname) {
+        //鏍规嵁mac鑾峰彇閿佺殑id
+        QueryWrapper linfWrapper=new QueryWrapper();
+        linfWrapper.eq("lock_mac",mac);
+        linfWrapper.last("limit 1");
+        LockInf linf=linfMapper.selectOne(linfWrapper);
+        UserInf uinf=uinfMapper.getUinfByUname(uname);
+        //娣诲姞鎿嶄綔璁板綍
+        ctlLogService.setLogByUid(linf.getLockId(),result,uinf.getUname());
+        return new Response().set(1,true);
+    }
+    //鏌ヨ鎵�鏈夊尯鍩熶笅鎵�鏈夐攣淇℃伅
+    public Response getLinfById(Integer id) {
+        //鑾峰彇鑾峰彇id涓嬫墍鏈夌殑鍖哄煙id
+        List areaList=new ArrayList();
+        areaList.add(id);
+        getAllAreaId(id,areaList);
+        QueryWrapper wrapper=new QueryWrapper();
+        wrapper.in("area_id",areaList);
+        List<LockInf> list=linfMapper.selectList(wrapper);
+        return new Response().setII(1,list!=null,list,"鏌ヨ鎵�鏈夊尯鍩熶笅鎵�鏈夐攣淇℃伅");
+    }
+    //鏌ヨ鎵�鍦ㄥ尯鍩熶笅鎵�鏈夌敤鎴蜂俊鎭�
+    public Response getUinfById(Integer id) {
+        List areaList=new ArrayList();
+        areaList.add(id);
+        getAllAreaId(id,areaList);
+        List<String> unameList=areaUserService.getUserNameByAreaIds(areaList);
+        return new Response().setII(1,unameList!=null,unameList,"鏌ヨ鎵�鍦ㄥ尯鍩熶笅鎵�鏈夌敤鎴蜂俊鎭�");
+    }
+
+    //鏌ヨ寮�閿佹棩蹇�
+    public Response getLockLog(LockCtlLog log, int pageNum, int pageSize) {
+        PageHelper.startPage(pageNum,pageSize);
+        QueryWrapper wrapper=new QueryWrapper();
+        if(log.getAreaId()!=null){
+            List<Integer> areaList=new ArrayList();
+            areaList.add(log.getAreaId());
+            getAllAreaId(log.getAreaId(),areaList);
+            //鏌ヨ鍖哄煙涓嬫墍鏈夌殑閿�
+            QueryWrapper wrapper1=new QueryWrapper();
+            wrapper1.in("area_id",areaList);
+            List<LockInf> linfs=linfMapper.selectList(wrapper1);
+            if(linfs!=null&&linfs.size()>0){
+                List lockIds=linfs.stream().map(LockInf::getLockId)
+                        .collect(Collectors.toList());
+                wrapper.in("lock_id",lockIds);
+            }else{
+                wrapper.eq("lock_id",0);//褰撳尯鍩熶笅娌℃湁閿佺殑鏃跺��
+            }
+        }
+        if(log.getLockId()!=null){
+            wrapper.eq("lock_id",log.getLockId());
+        }
+        if(log.getCtlResult()!=null){
+            wrapper.eq("ctl_result",log.getCtlResult());
+        }
+        if(log.getCtlType()!=null){
+            wrapper.eq("ctl_type",log.getCtlType());
+        }
+        if(log.getCtlUname()!=null){
+            wrapper.eq("ctl_uname",log.getCtlUname());
+        }
+        if(log.getStartTime()!=null){
+            wrapper.gt("ctl_time",log.getStartTime());
+        }
+        if(log.getEndTime()!=null){
+            wrapper.lt("ctl_time",log.getEndTime());
+        }
+        wrapper.orderByDesc("ctl_time");
+        List<LockCtlLog> list=ctlLogMapper.selectList(wrapper);
+        for (LockCtlLog l:list) {
+            QueryWrapper wrapper1=new QueryWrapper();
+            wrapper1.eq("lock_id",l.getLockId());
+            wrapper1.last("limit 1");
+            LockInf linf=linfMapper.selectOne(wrapper1);
+            l.setLockName(linf.getLockName());
+        }
+        PageInfo pageInfo=new PageInfo(list);
+        return new Response().setII(1,list!=null,pageInfo,"鏌ヨ鏈�杩戠殑寮�閿佹棩蹇�");
+    }
+
+    //棣栭〉鍒嗙粍缁熻鍓�10寮�閿佹鏁�
+    public Response getGroupCtlCount(int uid,int urole) {
+        List areaList=getAllAreaUser(uid,urole);
+        QueryWrapper wrapper=new QueryWrapper();
+        wrapper.in("area_id",areaList);
+        wrapper.orderByAsc("num");
+        List<LockInf> list=linfMapper.selectList(wrapper);
+        //鏍规嵁鐢ㄦ埛id鏌ヨ绠$悊鐨勯攣鐨刬d
+        List<HomeCtlGroupDto> listGroup=ctlLogMapper.getGroupCtlCount(uid);
+        return new Response().setII(1,listGroup!=null,listGroup,"棣栭〉鍒嗙粍缁熻鍓�10寮�閿佹鏁�");
+    }
+    //棣栭〉缁熻灞忔煖绫诲瀷
+    public Response getScreenBoxType(int uid,int urole) {
+        try {
+            List areaList=getAllAreaUser(uid,urole);
+            QueryWrapper wrapper=new QueryWrapper();
+            wrapper.in("area_id",areaList);
+            wrapper.eq("screen_flag",1);//鍙彇灞忔煖
+            wrapper.orderByAsc("num");
+            List<LockInf> list=linfMapper.selectList(wrapper);
+            Map<String, List<LockInf>>  boxType = list.stream().collect(Collectors.groupingBy(LockInf::getScreenBoxType));
+            Map<String, Object> map = new HashMap<>();
+            Map<String, Object> typeMap = new HashMap<>();
+            for (String type : boxType.keySet()) {
+                typeMap.put(type, boxType.get(type).size());
+            }
+            map.put("type",typeMap);
+            Map<String, List<LockInf>>  productType = list.stream().collect(Collectors.groupingBy(LockInf::getScreenBoxProduct));
+            Map<String, Object> productMap = new HashMap<>();
+            for (String product : productType.keySet()) {
+                productMap.put(product, productType.get(product).size());
+            }
+            map.put("product",productMap);
+            return new Response().setII(1,true,map,"棣栭〉缁熻灞忔煖绫诲瀷");
+        } catch (Exception e) {
+            return new Response().set(1,false,"棣栭〉缁熻灞忔煖绫诲瀷");
+        }
+    }
+    //閿佺殑宸ヤ綔鐘舵��
+    public Response getLockState(int uid, int urole) {
+        try {
+            List areaList = getAllAreaUser(uid, urole);
+            QueryWrapper wrapper = new QueryWrapper();
+            wrapper.in("area_id", areaList);
+            wrapper.orderByAsc("num");
+            List<LockInf> list = linfMapper.selectList(wrapper);
+            Map<String, Object> map = new HashMap<>();
+            map.put("sumLinf", 0);
+            map.put("onlineNum", 0);
+            map.put("offLineNum", 0);
+            map.put("openNum", 0);
+            map.put("closeNum", 0);
+            map.put("unLoadNum", 0);
+            //鏌ョ湅鍖哄煙涓嬫墍鏈夌殑閿�
+            map.put("sumLinf", list.size());
+            Map<Integer, List<LockInf>> onlinemap = list.stream().collect(Collectors.groupingBy(LockInf::getLockOnline));
+            for (Integer state : onlinemap.keySet()) {
+                if (state == 0) {
+                    map.put("offLineNum", onlinemap.get(0).size());//绂荤嚎
+                }
+                if (state == 1) {
+                    map.put("onlineNum", onlinemap.get(1).size());//鍦ㄧ嚎
+                }
+            }
+            Map<Integer, List<LockInf>> openmap = list.stream().collect(Collectors.groupingBy(LockInf::getLockState));
+            for (Integer open : openmap.keySet()) {
+                if (open == 0) {
+                    map.put("closeNum", openmap.get(0).size());//闂攣
+                }
+                if (open == 1) {
+                    map.put("openNum", openmap.get(1).size());//寮�閿�
+                }
+                if (open == -1) {
+                    map.put("unLoadNum", openmap.get(-1).size());//鏈畨瑁�
+                }
+                map.put("allLinfs", list);
+            }
+                return new Response().setII(1, true, map, "閿佺殑宸ヤ綔鐘舵��");
+            } catch(Exception e){
+                return new Response().set(1, false, "閿佺殑宸ヤ綔鐘舵��");
+        }
+    }
+    //瀹炴椂寮�閿佷俊鎭�(鍏ㄩ儴)
+    public Response getAllCtlLog(int userId, int urole) {
+        //鏌ョ湅鎵�鏈夊尯鍩�
+        List areaList=getAllAreaUser(userId,urole);
+        //鏌ョ湅鍖哄煙涓嬫墍鏈夌殑閿�
+        QueryWrapper linfWrapper=new QueryWrapper();
+        linfWrapper.in("area_id",areaList);
+        List<LockInf> linfs=linfMapper.selectList(linfWrapper);
+        if(linfs!=null&&linfs.size()>0){
+            List<Integer> lockIds=linfs.stream().map(LockInf::getLockId) // 鎻愬彇鐢ㄦ埛鍚�
+                    .collect(Collectors.toList()); // 杞崲涓哄垪琛�*/
+            //鑾峰彇閿佺殑鏃ュ織
+            List<LockCtlLog> logList=ctlLogService.getAllLog(lockIds);
+            return new Response().setII(1,true,logList,"瀹炴椂寮�閿佷俊鎭�(鍏ㄩ儴)");
+        }
+        return new Response().set(1,false,"瀹炴椂寮�閿佷俊鎭�(鍏ㄩ儴)");
+    }
+    //瀹炴椂寮�閿佷俊鎭�(澶辫触)
+    public Response getErrorCtlog(int userId, int urole) {
+        //鏌ョ湅鎵�鏈夊尯鍩�
+        List areaList=getAllAreaUser(userId,urole);
+        //鏌ョ湅鍖哄煙涓嬫墍鏈夌殑閿�
+        QueryWrapper linfWrapper=new QueryWrapper();
+        linfWrapper.in("area_id",areaList);
+        List<LockInf> linfs=linfMapper.selectList(linfWrapper);
+        if(linfs!=null&&linfs.size()>0){
+            List<Integer> lockIds=linfs.stream().map(LockInf::getLockId) // 鎻愬彇鐢ㄦ埛鍚�
+                    .collect(Collectors.toList()); // 杞崲涓哄垪琛�*/
+            //鑾峰彇閿佺殑鏃ュ織
+            List<LockCtlLog> logList=ctlLogService.getAllErrorLog(lockIds);
+            return new Response().setII(1,true,logList,"瀹炴椂寮�閿佷俊鎭�(澶辫触)");
+        }
+        return new Response().set(1,false,"瀹炴椂寮�閿佷俊鎭�(澶辫触)");
+    }
+    //lock鐨勪娇鐢ㄩ娆�
+    public Response getReport(int userId, int urole) {
+        //鏌ョ湅鎵�鏈夊尯鍩�
+        List areaList=getAllAreaUser(userId,urole);
+        //鏌ョ湅鍖哄煙涓嬫墍鏈夌殑閿�
+        QueryWrapper linfWrapper=new QueryWrapper();
+        linfWrapper.in("area_id",areaList);
+        List<LockInf> linfs=linfMapper.selectList(linfWrapper);
+        if(linfs!=null&&linfs.size()>0){
+            List<Integer> lockIds=linfs.stream().map(LockInf::getLockId) // 鎻愬彇鐢ㄦ埛鍚�
+                    .collect(Collectors.toList()); // 杞崲涓哄垪琛�*/
+            //鑾峰彇閿佺殑棰戞
+            List<LockReport> reportList=reportService.getReport(lockIds);
+            return new Response().setII(1,true,reportList,"lock鐨勪娇鐢ㄩ娆�");
+        }
+        return new Response().set(1,false,"lock鐨勪娇鐢ㄩ娆�");
+    }
+    //鍦板浘椤堕儴鐨勭鐞嗙殑鍖哄煙鍖呭惈瀛愬尯鍩�
+    public Response getHomeAllAinf(int userId, int urole) {
+        List<Integer> list=getAllAreaUser(userId,urole);
+        if (list!=null){
+            List<Integer> disList=list.stream().distinct()
+                    .collect(Collectors.toList());
+            return new Response().setII(1,true,disList.size(),"鍦板浘椤堕儴鐨勭鐞嗙殑鍖哄煙鍖呭惈瀛愬尯鍩�");
+        }else{
+            return new Response().setII(1,false,0,"鍦板浘椤堕儴鐨勭鐞嗙殑鍖哄煙鍖呭惈瀛愬尯鍩�");
+        }
+
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.1