| | |
| | | |
| | | 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.AreaInfMapper; |
| | | 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; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.logging.LogRecord; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class AreaInfService { |
| | | |
| | | @Autowired(required = false) |
| | | private AreaInfMapper mapper; |
| | | |
| | | @Autowired(required = false) |
| | | private LockInfMapper linfMapper; |
| | | |
| | | @Autowired(required = false) |
| | | private KeyInfMapper kinfMapper; |
| | | |
| | | @Autowired(required = false) |
| | | private UserInfMapper uInfMapper; |
| | | |
| | | @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() { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.like("area_path","武汉源畅%"); |
| | | wrapper.orderByAsc("area_path"); |
| | | List<AreaInf> list=mapper.selectList(wrapper); |
| | | return new Response().setII(1,list!=null,list,"查询所有区域信息"); |
| | | 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); |
| | | return new Response().setII(1, list1 != null, list1, "查询当前用户的所有信息"); |
| | | }else { |
| | | List<AreaInf> list2=mapper.selectAreaByUid(null,-1); |
| | | return new Response().setII(1,list2!=null,list2,"查询所有区域信息"); |
| | | } |
| | | } |
| | | //添加区域 |
| | | public Response addArea(Integer parentId, String areaName,String areaUname,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); |
| | | ainf.setAreaPath(areaName); |
| | | ainf.setAreaName(areaName); |
| | | if(areaUname!=null){ |
| | | ainf.setAreaUname(areaUname); |
| | | } |
| | | if(areaDescript!=null){ |
| | | ainf.setAreaDescript(areaDescript); |
| | | } |
| | |
| | | ainf.setParentId(parentId); |
| | | ainf.setAreaLevel(painf.getAreaLevel()+1); |
| | | ainf.setAreaPath(painf.getAreaName()+"_"+areaName); |
| | | 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); |
| | | //将用户urole改为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); |
| | | } |
| | |
| | | //获取上一级信息 |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("parent_id",id); |
| | | wrapper.last("limit 1"); |
| | | AreaInf painf=mapper.selectOne(wrapper); |
| | | if(painf!=null){ |
| | | delAll(painf.getId()); |
| | | List<AreaInf> list=mapper.selectList(wrapper); |
| | | if(list!=null){ |
| | | for (AreaInf painf:list) { |
| | | delAll(painf.getId()); |
| | | } |
| | | } |
| | | UpdateWrapper wrapper1=new UpdateWrapper(); |
| | | wrapper1.eq("id",id); |
| | | mapper.delete(wrapper1); |
| | | } |
| | | //修改区域 |
| | | public Response updateArea(Integer id, String areaName, String areaUname, 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"); |
| | | AreaInf ainf=mapper.selectOne(wrapper); |
| | | ainf.setAreaUname(areaUname); |
| | | ainf.setAreaDescript(areaDescript); |
| | | ainf.setAreaName(areaName); |
| | | String oldPath=ainf.getAreaPath(); |
| | |
| | | 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) { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("parent_id",id); |
| | | wrapper.last("limit 1"); |
| | | AreaInf painf=mapper.selectOne(wrapper); |
| | | if(painf!=null){ |
| | | String path=newPath+"_"+painf.getAreaName(); |
| | | updateAll(painf.getId(),path); |
| | | List<AreaInf> list=mapper.selectList(wrapper); |
| | | if(list!=null){ |
| | | for (AreaInf painf:list) { |
| | | String path=newPath+"_"+painf.getAreaName(); |
| | | updateAll(painf.getId(),path); |
| | | } |
| | | } |
| | | UpdateWrapper wrapper2=new UpdateWrapper(); |
| | | wrapper2.set("area_path",newPath); |
| | | wrapper2.eq("id",id); |
| | | mapper.update(null,wrapper2); |
| | | } |
| | | /* //查询所有区域下所有锁信息 |
| | | public Response getLinfById(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> list=linfMapper.selectList(wrapper); |
| | | PageInfo pageInfo=PageInfoUtils.list2PageInfo(list,pageNum,pageSize); |
| | | return new Response().setII(1,list!=null,pageInfo,"查询所有区域下所有锁信息"); |
| | | }*/ |
| | | //获取获取id下所有的区域id |
| | | public void getAllAreaId(Integer id,List areaList) { |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("parent_id",id); |
| | | List<AreaInf> list=mapper.selectList(wrapper); |
| | | if(list!=null){ |
| | | for (AreaInf painf:list) { |
| | | areaList.add(painf.getId()); |
| | | getAllAreaId(painf.getId(),areaList); |
| | | } |
| | | } |
| | | } |
| | | //区域管理员登录查看自己管理区域,锁具和区域对应的用户--区域管理员 |
| | | public Response getInfByAreaManage(String uname) { |
| | | Map<String,Object> map=new HashMap<>(); |
| | | 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查询所有的用户 |
| | | List<String> uids=areaUserService.selectUidByAreaId(areaList); |
| | | map.put("areaNum",areaList.size()); |
| | | map.put("lockNum",linfs.size()); |
| | | map.put("userNum",uids.size()); |
| | | return new Response().setII(1,true,map,"区域管理员登录查看自己管理区域,锁具和区域对应的用户--区域管理员"); |
| | | } |
| | | //区域管理员点击管理的区域跳转--区域管理员 |
| | | 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); |
| | | wrapper.orderByAsc("id"); |
| | | List<AreaInf> list=mapper.selectList(wrapper); |
| | | 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);//当区域下没有锁的时候 |
| | | } |
| | | } |
| | | 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,"地图顶部的管理的区域包含子区域"); |
| | | } |
| | | |
| | | } |
| | | } |