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 |  540 ++++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 457 insertions(+), 83 deletions(-)

diff --git a/src/main/java/com/whyc/service/AreaInfService.java b/src/main/java/com/whyc/service/AreaInfService.java
index 8f42e64..883ddb5 100644
--- a/src/main/java/com/whyc/service/AreaInfService.java
+++ b/src/main/java/com/whyc/service/AreaInfService.java
@@ -2,12 +2,17 @@
 
 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;
+import com.whyc.pojo.db_area.AreaUser;
 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;
@@ -19,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
@@ -39,26 +45,47 @@
     @Autowired(required = false)
     private LockCtlLogMapper ctlLogMapper;
 
+    @Autowired(required = false)
+    private AreaUserService areaUserService;
+
+    @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){
+       //鑾峰彇鐢ㄦ埛鎵�绠$悊鐨勫尯鍩�
+       List<Integer> list =areaUserService.setAreaId(uid);
+       List areaList=new ArrayList();
+       areaList.addAll(list);
+       if (urole==1) {
+           for (Integer aid:list) {
+               List list1=new ArrayList();
+               getAllAreaId(aid, list1);
+               areaList.addAll(list1);
+           }
+       }
+       if (urole==2) {
+          List<AreaInf> allList=mapper.selectList(null);
+          List<Integer> idList=allList.stream().map(AreaInf::getId)
+                   .collect(Collectors.toList());
+           areaList.addAll(idList);
+       }
+       return areaList;
+   }
 
     //鏌ヨ鎵�鏈夊尯鍩熶俊鎭�
-    public Response getAllAreaInf() {
-        /*UserInf uinf=new UserInf();
-        uinf.setUname("test_admin");
-        uinf.setUid(105);
-        uinf.setUrole(2);
-        uinf.setAreaId(3);*/
-        UserInf uinf= ActionUtil.getUser();
+    public Response getAllAreaInf(String uname) {
+        UserInf uinf=uinfMapper.getUinfByUname(uname);
         if(uinf.getUrole()!=2) {//褰撳墠鐢ㄦ埛涓嶆槸瓒呯骇绠$悊鍛�
-            //鏌ヨ鍑哄綋鍓嶇敤鎴锋墍鍦ㄥ尯鍩�
-            QueryWrapper wrapper = new QueryWrapper();
-            wrapper.eq("id", uinf.getAreaId());
-            wrapper.last("limit 1");
-            AreaInf ainf = mapper.selectOne(wrapper);
-            List areaList = new ArrayList();
-            if (ainf != null) {
-                areaList.add(ainf.getId());
-                getAllAreaId(ainf.getId(), areaList);
-            }
+            List areaList=getAllAreaUser(uinf.getUid(),uinf.getUrole());
             List<AreaInf> list1 = mapper.selectAreaByUid(areaList, 1);
             return new Response().setII(1, list1 != null, list1, "鏌ヨ褰撳墠鐢ㄦ埛鐨勬墍鏈変俊鎭�");
         }else {
@@ -67,7 +94,8 @@
         }
     }
     //娣诲姞鍖哄煙
-    public Response addArea(Integer parentId, String areaName,String areaDescript) {
+    @Transactional
+    public Response addArea(Integer parentId, List<AreaUser> areaUserList, String areaName,String areaDescript) {
         AreaInf ainf=new AreaInf();
         ainf.setParentId(0);
         ainf.setAreaLevel(1);
@@ -88,10 +116,40 @@
             ainf.setIdPath(painf.getIdPath()+"_"+parentId);
         }
         int flag= mapper.insert(ainf);
+
+        if(areaUserList!=null&&areaUserList.size()>0){
+            //灏嗗搴斿叧绯绘坊鍔犲埌areauser涓�
+            QueryWrapper ainfWrapper=new QueryWrapper();
+            ainfWrapper.eq("parent_id",parentId);
+            ainfWrapper.eq("area_name",areaName);
+            ainfWrapper.last("limit 1");
+            AreaInf area=mapper.selectOne(ainfWrapper);
+            areaUserService.insertAreaUser(area.getId(),areaUserList);
+            //灏嗙敤鎴穟role鏀逛负1
+            List<Integer> uidList=areaUserList.stream().map(AreaUser::getUid) // 鎻愬彇鐢ㄦ埛鍚�
+                .collect(Collectors.toList());
+            UpdateWrapper userWrapper=new UpdateWrapper();
+            userWrapper.set("urole",1);
+            userWrapper.in("uid",uidList);
+            userWrapper.eq("urole",0);
+            uInfMapper.update(null,userWrapper);
+        }
         return new Response().set(1,flag>0);
     }
     //鍒犻櫎鍖哄煙
     public Response delArea(Integer id) {
+        //楠岃瘉鍖哄煙鏄惁琚敤鎴风鐞�
+        List<AreaUser> listUser=areaUserService.getAreaUser(id);
+        if(listUser!=null&&listUser.size()>0){
+            return  new Response().set(1,false,"鍖哄煙涓嬪瓨鍦ㄧ敤鎴�,鎷掔粷鍒犻櫎");
+        }
+        //楠岃瘉鍖哄煙鏄惁瀛樺湪閿�
+        QueryWrapper wrapperLock=new QueryWrapper();
+        wrapperLock.eq("area_id",id);
+        List<LockInf> listLock=linfMapper.selectList(wrapperLock);
+        if(listLock!=null&&listLock.size()>0){
+            return  new Response().set(1,false,"鍖哄煙涓嬪瓨鍦ㄩ攣,鎷掔粷鍒犻櫎");
+        }
         delAll(id);
         return new Response().set(1,true);
     }
@@ -111,7 +169,9 @@
         mapper.delete(wrapper1);
     }
     //淇敼鍖哄煙
-    public Response updateArea(Integer id, String areaName, String areaDescript) {
+    @Transactional
+    public Response updateArea(Integer id, String areaName, List<AreaUser> areaUserList, String areaDescript) {
+        //鏀瑰尯鍩�
         QueryWrapper wrapper=new QueryWrapper();
         wrapper.eq("id",id);
         wrapper.last("limit 1");
@@ -124,6 +184,12 @@
         wrapper1.eq("id",id);
         mapper.update(ainf,wrapper1);
         updateAll(id,newPath);
+        //鍒犻櫎鏃х殑鍖哄煙瀵瑰簲鍏崇郴
+        areaUserService.delteAreaUser(id);
+        if(areaUserList!=null&&areaUserList.size()>0){
+            //灏嗘柊鐨勬彃鍏�
+            areaUserService.insertAreaUser(id,areaUserList);
+        }
         return new Response().set(1,true);
     }
     public void updateAll(Integer id, String newPath) {
@@ -166,84 +232,392 @@
         }
     }
     //鍖哄煙绠$悊鍛樼櫥褰曟煡鐪嬭嚜宸辩鐞嗗尯鍩燂紝閿佸叿鍜屽尯鍩熷搴旂殑鐢ㄦ埛--鍖哄煙绠$悊鍛�
-    public Response getInfByAreaManage() {
+    public Response getInfByAreaManage(String uname) {
         Map<String,Object> map=new HashMap<>();
-        UserInf uinf=ActionUtil.getUser();
-        List areaList=new ArrayList();
-        areaList.add(uinf.getAreaId());
-        getAllAreaId(uinf.getAreaId(),areaList);
+        UserInf uinf=uinfMapper.getUinfByUname(uname);
+        List areaList=getAllAreaUser(uinf.getUid(),uinf.getUrole());
         //閫氳繃鍖哄煙id鏌ヨ鎵�鏈夌殑閿�
         QueryWrapper linfWrapper=new QueryWrapper();
         linfWrapper.in("area_id",areaList);
         List<LockInf> linfs=linfMapper.selectList(linfWrapper);
         //閫氳繃鍖哄煙id鏌ヨ鎵�鏈夌殑鐢ㄦ埛
-        QueryWrapper uinfWrapper=new QueryWrapper();
-        uinfWrapper.in("area_id",areaList);
-        List<UserInf> uinfs=uInfMapper.selectList(linfWrapper);
+        List<String> uids=areaUserService.selectUidByAreaId(areaList);
         map.put("areaNum",areaList.size());
         map.put("lockNum",linfs.size());
-        map.put("userNum",uinfs.size());
+        map.put("userNum",uids.size());
         return new Response().setII(1,true,map,"鍖哄煙绠$悊鍛樼櫥褰曟煡鐪嬭嚜宸辩鐞嗗尯鍩燂紝閿佸叿鍜屽尯鍩熷搴旂殑鐢ㄦ埛--鍖哄煙绠$悊鍛�");
     }
-
-    //鏌ヨ鎵�鏈夊尯鍩熶笅鎵�鏈夌敤鎴蜂俊鎭�
-/*    public Response getUinfById(Integer id, int pageNum, int pageSize) {
-        //鑾峰彇鑾峰彇id涓嬫墍鏈夌殑鍖哄煙id
-        List uinfList=new ArrayList();
+    //鍖哄煙绠$悊鍛樼偣鍑荤鐞嗙殑鍖哄煙璺宠浆--鍖哄煙绠$悊鍛�
+    public Response getAinfByManage(String uname) {
+        UserInf uinf=uinfMapper.getUinfByUname(uname);
+        List areaList=getAllAreaUser(uinf.getUid(),uinf.getUrole());
         QueryWrapper wrapper=new QueryWrapper();
-        wrapper.eq("id",id);
-        wrapper.last("limit 1");
-        AreaInf ainf=mapper.selectOne(wrapper);
-        if(ainf!=null){
-            uinfList.add(ainf.getAreaUname());
-        }
-        getAllUinfId(id,uinfList);
-        QueryWrapper wrapper1=new QueryWrapper();
-        wrapper1.select("uid","uname","CREATE_TIME");
-        wrapper1.in("uname",uinfList);
-        List<UserInf> list=uInfMapper.selectList(wrapper1);
-        PageInfo pageInfo=PageInfoUtils.list2PageInfo(list,pageNum,pageSize);
-        return new Response().setII(1,list!=null,pageInfo,"鏌ヨ鎵�鏈夊尯鍩熶笅鎵�鏈夌敤鎴蜂俊鎭�");
-    }*/
-
-   /* //鑾峰彇鑾峰彇id涓嬫墍鏈夌殑鍖哄煙鐢ㄦ埛鍚�
-    private void getAllUinfId(Integer id,List uinfList) {
-        QueryWrapper wrapper=new QueryWrapper();
-        wrapper.eq("parent_id",id);
+        wrapper.in("id",areaList);
+        wrapper.orderByAsc("id");
         List<AreaInf> list=mapper.selectList(wrapper);
-        if(list!=null){
-            for (AreaInf painf:list) {
-                uinfList.add(painf.getAreaUname());
-                getAllUinfId(painf.getId(),uinfList);
+        return new Response().setII(1,list!=null,list,"鍖哄煙绠$悊鍛樼偣鍑荤鐞嗙殑鍖哄煙璺宠浆--鍖哄煙绠$悊鍛�");
+    }
+    //鍖哄煙绠$悊鍛樼偣鍑绘寚瀹氬尯鍩熸煡鐪嬫墍鏈夌殑閿佷俊鎭�--鍖哄煙绠$悊鍛�
+    public Response getlinfByAid(int id) {
+        List areaList=new ArrayList();
+        areaList.add(id);
+        getAllAreaId(id,areaList);
+        //鏌ヨ鍖哄煙涓嬬殑閿�
+        //閫氳繃鍖哄煙id鏌ヨ鎵�鏈夌殑閿�
+        QueryWrapper linfWrapper=new QueryWrapper();
+        linfWrapper.in("area_id",areaList);
+        List<LockInf> linfs=linfMapper.selectList(linfWrapper);
+        return new Response().setII(1,linfs!=null,linfs,"鍖哄煙绠$悊鍛樼偣鍑绘寚瀹氬尯鍩熸煡鐪嬫墍鏈夌殑閿佷俊鎭�--鍖哄煙绠$悊鍛�");
+    }
+
+    //鍖哄煙绠$悊鍛樼偣鍑绘煡鐪嬪紑閿佹搷浣滆褰�--鍖哄煙绠$悊鍛�
+    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=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()); // 杞崲涓哄垪琛�*/
+            //鑾峰彇閿佺殑鏃ュ織
+            List<LockCtlLog> logList=ctlLogService.getAllErrorLog(lockIds);
+            if(logList!=null&&logList.size()>0){
+                map.put("sumLog",logList.size());
+                Map<Integer, List<LockCtlLog>> logmap = logList.stream().collect(Collectors.groupingBy(LockCtlLog::getCtlResult));
+                for (Integer result : logmap.keySet()) {
+                    if(result==0){
+                        map.put("errorLogNum", logmap.get(0).size());//澶辫触
+                    }
+                }
+                pageInfo=PageInfoUtils.list2PageInfo(logList,pageNum,pageSize);
+                map.put("allLogs",pageInfo);
+            }
+
+        }
+        return new Response().setII(1,true,map,"鍖哄煙绠$悊鍛樼偣鍑绘煡鐪嬪紑閿佹搷浣滆褰�--鍖哄煙绠$悊鍛�");
+    }
+
+    //鍖哄煙绠$悊鍛樻煡鐪嬪尯鍩熶笅鐨勯攣鐨勭姸鎬�--鍖哄煙绠$悊鍛�
+    public Response getAreaLockById(int id) {
+        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);
+        List<LockInf> linfs=new ArrayList<>();
+        map.put("allLinfs",linfs);
+        List areaList=new ArrayList();
+        areaList.add(id);
+        getAllAreaId(id,areaList);
+        //鏌ョ湅鍖哄煙涓嬫墍鏈夌殑閿�
+        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));
+            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 = linfs.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",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);//褰撳尯鍩熶笅娌℃湁閿佺殑鏃跺��
             }
         }
-    }*/
-   //鏌ヨ鎵�鏈夊尯鍩熶笅鎵�鏈夐挜鍖欎俊鎭�
-   /* public Response getKinfById(Integer id, int pageNum, int pageSize) {
-        //鑾峰彇鑾峰彇id涓嬫墍鏈夌殑鍖哄煙id
-        List areaList=new ArrayList();
-        areaList.add(id);
-        getAllAreaId(id,areaList);
+        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);
-        List<KeyInf> list=kinfMapper.selectList(wrapper);
-        PageInfo pageInfo=PageInfoUtils.list2PageInfo(list,pageNum,pageSize);
-        return new Response().setII(1,list!=null,pageInfo,"鏌ヨ鎵�鏈夊尯鍩熶笅鎵�鏈夐挜鍖欎俊鎭�");
-    }*/
-   /* //鏌ヨ鎵�鍦ㄥ尯鍩熶笅鎵�鏈夊紑閿佹棩蹇�
-    public Response getLogById(Integer id, int pageNum, int pageSize) {
-        //鑾峰彇鑾峰彇id涓嬫墍鏈夌殑鍖哄煙id
-        List areaList=new ArrayList();
-        areaList.add(id);
-        getAllAreaId(id,areaList);
-        QueryWrapper wrapper=new QueryWrapper();
-        wrapper.in("area_id",areaList);
-        List<LockInf> lockList=linfMapper.selectList(wrapper);
-        List<Integer> lockIdList=lockList.stream().map(LockInf::getLockId).collect(Collectors.toList());
-        QueryWrapper logwrapper=new QueryWrapper();
-        wrapper.in("lock_id",lockIdList);
-        List<KeyInf> list=ctlLogMapper.selectList(logwrapper);
-        PageInfo pageInfo=PageInfoUtils.list2PageInfo(list,pageNum,pageSize);
-        return new Response().setII(1,list!=null,pageInfo,"鏌ヨ鎵�鍦ㄥ尯鍩熶笅鎵�鏈夊紑閿佹棩蹇�");
-    }*/
+        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