package com.whyc.service;
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.whyc.dto.Response;
|
import com.whyc.mapper.BaojigroupLockMapper;
|
import com.whyc.mapper.LockInfMapper;
|
import com.whyc.pojo.plus_inf.LockInf;
|
import com.whyc.pojo.plus_lock_ram.LockCtlLog;
|
import com.whyc.pojo.plus_lock_ram.LockReport;
|
import com.whyc.pojo.plus_user.BaojigroupLock;
|
import com.whyc.util.ActionUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
@Service
|
public class HomeService {
|
@Autowired(required = false)
|
private LockInfMapper linfMapper;
|
|
@Autowired(required = false)
|
private LockReportService reportService;
|
|
@Autowired(required = false)
|
private LockCtlLogService ctlLogService;
|
|
@Autowired(required = false)
|
private BaojigroupLockMapper bjLockMapper;
|
|
//锁的工作状态
|
public Response getLockState(int uid) {
|
try {
|
//查询用户管理的锁id集合
|
List<Integer> lockidList = bjLockMapper.getLockIdByUid(uid);
|
QueryWrapper wrapper = new QueryWrapper();
|
wrapper.in("lock_id", lockidList);
|
wrapper.eq("del_flag", 0);
|
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 getScreenBoxType(int uid) {
|
try {
|
//查询用户管理的锁id集合
|
List<Integer> lockidList = bjLockMapper.getLockIdByUid(uid);
|
QueryWrapper wrapper = new QueryWrapper();
|
wrapper.in("lock_id", lockidList);
|
wrapper.eq("screen_flag",1);//只取屏柜
|
wrapper.eq("del_flag", 0);
|
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,"首页统计屏柜类型");
|
}
|
}
|
|
//lock的使用频次
|
public Response getReport(int uid) {
|
//查询用户管理的锁id集合
|
List<Integer> lockidList = bjLockMapper.getLockIdByUid(uid);
|
if(lockidList.size()>0){
|
//获取锁的频次
|
List<LockReport> reportList=reportService.getReport(lockidList);
|
return new Response().setII(1,true,reportList,"lock的使用频次");
|
}
|
return new Response().set(1,false,"lock的使用频次");
|
}
|
|
//实时开锁信息(失败)
|
public Response getErrorCtlog(int uid) {
|
//查询用户管理的锁id集合
|
List<Integer> lockidList = bjLockMapper.getLockIdByUid(uid);
|
if(lockidList.size()>0){
|
//获取锁的日志
|
List<LockCtlLog> logList=ctlLogService.getAllErrorLog(lockidList);
|
return new Response().setII(1,true,logList,"实时开锁信息(失败)");
|
}
|
return new Response().set(1,false,"实时开锁信息(失败)");
|
}
|
|
//实时开锁信息(全部)
|
public Response getAllCtlLog(int uid) {
|
//查询用户管理的锁id集合
|
List<Integer> lockidList = bjLockMapper.getLockIdByUid(uid);
|
if(lockidList.size()>0){
|
//获取锁的日志
|
List<LockCtlLog> logList=ctlLogService.getAllLog(lockidList);
|
return new Response().setII(1,true,logList,"实时开锁信息(全部)");
|
}
|
return new Response().set(1,false,"实时开锁信息(全部)");
|
}
|
|
//地图顶部的管理的站点和设备(锁)
|
public Response getHomeStationAndLock(int uid) {
|
Map<String, Object> map = new HashMap<>();
|
map.put("stationNum",0);
|
map.put("lockNum",0);
|
List<BaojigroupLock> list=bjLockMapper.getHomeStationAndLock(uid);
|
Map<Integer, List<BaojigroupLock>> stationmap = list.stream().collect(Collectors.groupingBy(BaojigroupLock::getStationId));
|
map.put("stationNum",stationmap.size());
|
Map<Integer, List<BaojigroupLock>> lockmap = list.stream().collect(Collectors.groupingBy(BaojigroupLock::getLockId));
|
map.put("lockNum",lockmap.size());
|
if (list!=null){
|
return new Response().setII(1,true,map,"地图顶部的管理的站点和设备");
|
}else{
|
return new Response().setII(1,false,0,"地图顶部的管理的站点和设备");
|
}
|
|
}
|
}
|