| | |
| | | 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.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; |
| | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.logging.LogRecord; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | |
| | | @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){ |
| | |
| | | } |
| | | |
| | | //查询所有区域信息 |
| | | 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); |
| | |
| | | } |
| | | } |
| | | //区域管理员登录查看自己管理区域,锁具和区域对应的用户--区域管理员 |
| | | 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(); |
| | |
| | | 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); |
| | |
| | | } |
| | | |
| | | //区域管理员点击查看开锁操作记录--区域管理员 |
| | | 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()); |
| | | //查看区域下所有的锁 |
| | |
| | | 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("unLoadNum", openmap.get(-1).size());//未安装 |
| | | } |
| | | } |
| | | map.put("allLinfs",linfs); |
| | |
| | | } |
| | | |
| | | //区域管理员查看指定区域下的锁具告警(失败的)--区域管理员 |
| | | public Response getErrLogByUid(int pageNum, int pageSize) { |
| | | UserInf uinf= ActionUtil.getUser(); |
| | | public Response getErrLogByUid(int pageNum, int pageSize,String uname) { |
| | | UserInf uinf=uinfMapper.getUinfByUname(uname); |
| | | //查看所有区域 |
| | | List areaList=getAllAreaUser(uinf.getUid(),uinf.getUrole()); |
| | | //查看区域下所有的锁 |
| | |
| | | } |
| | | } |
| | | //区域管理员查看指定区域下的锁具告警(全部的的)--区域管理员 |
| | | public Response getAllLogByUid(int pageNum, int pageSize) { |
| | | UserInf uinf= ActionUtil.getUser(); |
| | | public Response getAllLogByUid(int pageNum, int pageSize,String uname) { |
| | | UserInf uinf=uinfMapper.getUinfByUname(uname); |
| | | //查看所有区域 |
| | | List areaList=getAllAreaUser(uinf.getUid(),uinf.getUrole()); |
| | | //查看区域下所有的锁 |
| | |
| | | return new Response().set(1,false,"区域管理员点击查看开锁操作记录--区域管理员"); |
| | | } |
| | | } |
| | | //区域管理员蓝牙开锁记录日志--区域管理员 |
| | | public Response setLogByUid(String mac, int result) { |
| | | //区域管理员记录手机蓝牙开锁日志--区域管理员 |
| | | 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 userInf=ActionUtil.getUser(); |
| | | UserInf uinf=uinfMapper.getUinfByUname(uname); |
| | | //添加操作记录 |
| | | ctlLogService.setLogByUid(linf.getLockId(),result,userInf.getUname()); |
| | | ctlLogService.setLogByUid(linf.getLockId(),result,uinf.getUname()); |
| | | return new Response().set(1,true); |
| | | } |
| | | //查询所有区域下所有锁信息 |
| | |
| | | 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查询管理的锁的id |
| | | 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,"地图顶部的管理的区域包含子区域"); |
| | | } |
| | | |
| | | } |
| | | } |