package com.whyc.service;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageInfo;
|
import com.whyc.dto.Response;
|
import com.whyc.mapper.*;
|
import com.whyc.pojo.*;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Lazy;
|
import org.springframework.stereotype.Service;
|
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
@Service
|
public class StationInfService {
|
@Autowired(required = false)
|
private StationInfMapper mapper;
|
|
@Autowired(required = false)
|
private BattRtdataMapper rtdataMapper;
|
|
@Autowired(required = false)
|
private BattRtstateMapper rtstateMapper;
|
|
@Autowired(required = false)
|
private PwrdevAcdcdataMapper acdcMapper;
|
|
@Autowired(required = false)
|
private BattalarmDataMapper battAlmMapper;
|
|
@Autowired(required = false)
|
private DevalarmDataMapper devAlmMapper;
|
|
@Autowired(required = false)
|
private PwrdevAlarmMapper pwrAlmMapper;
|
|
@Autowired(required = false)
|
private BadbattMonMapper badMapper;
|
|
@Autowired(required = false)
|
private BattEnduranceMapper endMapper;
|
@Autowired
|
@Lazy
|
private BattInfService battInfService;
|
@Autowired
|
private Fbs9100StateService fbs9100StateService;
|
@Autowired
|
private BattalarmDataService battAlarmDataService;
|
@Autowired
|
private DevalarmDataService devAlarmDataService;
|
@Autowired
|
private PwrdevAlarmService powerAlarmService;
|
|
//插入站点
|
public Response insertStation(StationInf stationInf) {
|
int flag = mapper.insert(stationInf);
|
return new Response().set(1, flag > 0, "插入站点");
|
}
|
|
//查询所有的站点
|
public Response searchStationAll(int pageCurr, int pageSize) {
|
PageHelper.startPage(pageCurr, pageSize);
|
List<StationInf> list = mapper.selectList(null);
|
PageInfo pageInfo = new PageInfo(list);
|
return new Response().setII(1, list.size() > 0, pageInfo, "查询站点");
|
}
|
|
//删除总站点
|
public Response deleteStation(int num) {
|
UpdateWrapper wrapper = new UpdateWrapper();
|
wrapper.eq("num", num);
|
int flag = mapper.delete(wrapper);
|
return new Response().set(1, flag > 0, "插入站点");
|
}
|
|
//管理员首页:站点实时数据推送
|
public Response getSystemAll(int userId) {
|
List<StationInf> list = mapper.getSystemAll(userId);
|
for (StationInf inf : list) {
|
String stationId = inf.getStationId();
|
//查询机房下最大的单体电压和单体
|
BattRtdata maxData = rtdataMapper.maxData(stationId);
|
inf.setMaxVol(maxData.getMonVol());
|
inf.setMaxNum(maxData.getMonNum());
|
//查询机房下最低的单体电压和单体
|
BattRtdata minData = rtdataMapper.minData(stationId);
|
inf.setMinVol(maxData.getMonVol());
|
inf.setMinNum(maxData.getMonNum());
|
//查询实时告警总数
|
int battAlm = battAlmMapper.getbattAlm(stationId);
|
inf.setBattAlm(battAlm);
|
int devAlm = devAlmMapper.getdevAlm(stationId);
|
inf.setDevAlm(devAlm);
|
int pwrAlm = pwrAlmMapper.getpwrAlm(stationId);
|
inf.setPwrAlm(pwrAlm);
|
inf.setAlarmNum(battAlm + devAlm + pwrAlm);
|
}
|
return new Response().setII(1, list.size() > 0, list, "站点实时数据推送");
|
}
|
|
public String getMaxStationId() {
|
QueryWrapper<StationInf> query = Wrappers.query();
|
query.select("stationId").orderByDesc("num").last(" limit 1");
|
StationInf stationInf = mapper.selectOne(query);
|
if (stationInf == null) {
|
return "42000000";
|
} else {
|
return stationInf.getStationId();
|
}
|
}
|
|
/**
|
*
|
* @param userId
|
* @return
|
* 站点数:
|
* 110v/35v:
|
* 节点站:
|
* 普通站:
|
* 停点站: tb_fbs9100_state.dev_workstate=3
|
* 核容放电站:tb_fbs9100_state.dev_workstate=2
|
* 故障告警站:
|
*
|
*/
|
public Response getStationStatistic(int userId) {
|
try {
|
Map<String, Integer> stationInfoMap = new HashMap<>();
|
List<StationInf> stationInfList = mapper.getStationInfList(userId);
|
//站点数
|
stationInfoMap.put("stationCount", stationInfList.size());
|
//110v/35v/...
|
Map<String, List<StationInf>> stationTypeMap = stationInfList.stream().filter(stationInf -> !stationInf.getStationType().equals("")).collect(Collectors.groupingBy(StationInf::getStationType));
|
Set<String> stationTypeSet = stationTypeMap.keySet();
|
for (String stationType : stationTypeSet) {
|
stationInfoMap.put(stationType, stationTypeMap.get(stationType).size());
|
}
|
//节点站和普通站
|
List<Battinf> stationList = battInfService.getSateAnalysis(userId);
|
Map<Integer, List<Battinf>> nodeStationMap = stationList.stream().collect(Collectors.groupingBy(Battinf::getNodeStation));
|
|
stationInfoMap.put("nomalStation", nodeStationMap.get(0) == null ? 0 : nodeStationMap.get(0).size());
|
stationInfoMap.put("nodeStation", nodeStationMap.get(1) == null ? 0 : nodeStationMap.get(1).size());
|
|
//停电站和核容放电站
|
List<Fbs9100State> stateList = fbs9100StateService.getStateList(userId);
|
Map<Integer, List<Fbs9100State>> stateMap = stateList.stream().collect(Collectors.groupingBy(Fbs9100State::getDevWorkstate));
|
stationInfoMap.put("checkCapDischarge", stateMap.get(2) == null ? 0 : stateMap.get(2).size());
|
stationInfoMap.put("powerOff", stateMap.get(3) == null ? 0 : stateMap.get(3).size());
|
//故障告警站: 电池/设备/电源告警
|
List<Integer> battStationList = battAlarmDataService.getStationList(userId);
|
List<Integer> devStationList = devAlarmDataService.getStationList(userId);
|
List<Integer> powerStationList = powerAlarmService.getStationList(userId);
|
List<Integer> stationIdList = new LinkedList<>(battStationList);
|
for (Integer integer : devStationList) {
|
if (!stationIdList.contains(integer)) {
|
stationIdList.add(integer);
|
}
|
}
|
for (Integer integer : powerStationList) {
|
if (!stationIdList.contains(integer)) {
|
stationIdList.add(integer);
|
}
|
}
|
stationInfoMap.put("alarmStationCount", stationIdList.size());
|
return new Response().setII(1,true,stationInfoMap,null);
|
}catch (Exception e){
|
return new Response().set(1,false,"发生异常:"+e.getCause());
|
}
|
}
|
|
//运维层首页:站点实时数据推送
|
public Object getDevOpAll(int userId) {
|
try {
|
Map<String, Object> map = new HashMap();
|
//头部统计数据
|
int stationNum = mapper.getStation(userId);
|
map.put("stationNum", stationNum);
|
//浮充/充电
|
List<BattRtstate> stateList = rtstateMapper.getBattStateStatic(userId);
|
Map<Integer, Integer> statemap = new HashMap();
|
Map<Integer, List<BattRtstate>> battstateMap = stateList.stream().collect(Collectors.groupingBy(BattRtstate::getBattState));
|
for (Integer state : battstateMap.keySet()) {
|
statemap.put(state, battstateMap.get(state).size());
|
}
|
map.put("battState", statemap);
|
//整流器故障/负载熔断
|
List<PwrdevAcdcdata> acdcList = acdcMapper.getAcdcStatic(userId);
|
Map<Integer, Integer> errmap = new HashMap();
|
Map<Integer, List<PwrdevAcdcdata>> aderrMap = acdcList.stream().collect(Collectors.groupingBy(PwrdevAcdcdata::getAcdcErr));
|
for (Integer acdcerr : aderrMap.keySet()) {
|
errmap.put(acdcerr, aderrMap.get(acdcerr).size());
|
}
|
map.put("errmap", errmap);
|
Map<Integer, Integer> fusemap = new HashMap();
|
Map<Integer, List<PwrdevAcdcdata>> adfuseMap = acdcList.stream().collect(Collectors.groupingBy(PwrdevAcdcdata::getIsLoaderFuse));
|
for (Integer fuse : adfuseMap.keySet()) {
|
fusemap.put(fuse, adfuseMap.get(fuse).size());
|
}
|
map.put("fusemap", fusemap);
|
//下面各个站点数据
|
List<StationInf> list = mapper.getSystemAll(userId);
|
map.put("data", list);
|
return new Response().setII(1, true, map, "站点实时数据推送");
|
} catch (Exception e) {
|
return new Response().set(1, false, "发生异常:" + e.getCause());
|
}
|
|
}
|
|
//总机房
|
public int getStation(int userId) {
|
return mapper.getStation(userId);
|
}
|
|
//监控层首页:站点实时数据推送
|
public Object getMonitorAll(int userId) {
|
return new Response().set(1, true, "站点实时数据推送");
|
}
|
|
//管理员首页:头部统计
|
public Response getSystemSkipHead(int userId) {
|
try {
|
Map<String, Object> map = new HashMap();
|
//头部统计数据
|
int stationNum = mapper.getStation(userId);
|
map.put("stationNum", stationNum);
|
//浮充/充电
|
List<BattRtstate> stateList = rtstateMapper.getBattStateStatic(userId);
|
Map<Integer, Integer> statemap = new HashMap();
|
Map<Integer, List<BattRtstate>> battstateMap = stateList.stream().collect(Collectors.groupingBy(BattRtstate::getBattState));
|
for (Integer state : battstateMap.keySet()) {
|
statemap.put(state, battstateMap.get(state).size());
|
}
|
map.put("battState", statemap);
|
return new Response().setII(1, true, map, "管理员首页:头部统计");
|
} catch (Exception e) {
|
return new Response().set(1, false, "发生异常:" + e.getCause());
|
}
|
}
|
|
//指定站点详情第一次跳转机房id为0:message
|
public Response getSystemSkipStation(int userId, String stationId) {
|
//查询指定机房信息
|
StationInf inf = mapper.getSystemSkipStation(userId, stationId);
|
if (inf != null) {
|
//查询机房下最大的单体电压和单体
|
BattRtdata maxData = rtdataMapper.maxData(stationId);
|
inf.setMaxVol(maxData.getMonVol());
|
inf.setMaxNum(maxData.getMonNum());
|
//查询机房下最低的单体电压和单体
|
BattRtdata minData = rtdataMapper.minData(stationId);
|
inf.setMinVol(maxData.getMonVol());
|
inf.setMinNum(maxData.getMonNum());
|
//查询实时告警总数
|
int battAlm = battAlmMapper.getbattAlm(stationId);
|
inf.setBattAlm(battAlm);
|
int devAlm = devAlmMapper.getdevAlm(stationId);
|
inf.setDevAlm(devAlm);
|
int pwrAlm = pwrAlmMapper.getpwrAlm(stationId);
|
inf.setPwrAlm(pwrAlm);
|
inf.setAlarmNum(battAlm + devAlm + pwrAlm);
|
return new Response().setII(1, true, inf, "指定站点详情");
|
} else {
|
return new Response().set(1, false, "指定站点详情");
|
}
|
|
}
|
|
//运维层首页:头部统计
|
public Response getDevOpSkipHead(int userId) {
|
try {
|
Map<String, Object> map = new HashMap();
|
//头部统计数据
|
int stationNum = mapper.getStation(userId);
|
map.put("stationNum", stationNum);
|
//浮充/充电
|
List<BattRtstate> stateList = rtstateMapper.getBattStateStatic(userId);
|
Map<Integer, Integer> statemap = new HashMap();
|
Map<Integer, List<BattRtstate>> battstateMap = stateList.stream().collect(Collectors.groupingBy(BattRtstate::getBattState));
|
for (Integer state : battstateMap.keySet()) {
|
statemap.put(state, battstateMap.get(state).size());
|
}
|
map.put("battState", statemap);
|
//整流器故障/负载熔断
|
List<PwrdevAcdcdata> acdcList = acdcMapper.getAcdcStatic(userId);
|
Map<Integer, Integer> errmap = new HashMap();
|
Map<Integer, List<PwrdevAcdcdata>> aderrMap = acdcList.stream().collect(Collectors.groupingBy(PwrdevAcdcdata::getAcdcErr));
|
for (Integer acdcerr : aderrMap.keySet()) {
|
errmap.put(acdcerr, aderrMap.get(acdcerr).size());
|
}
|
map.put("errmap", errmap);
|
Map<Integer, Integer> fusemap = new HashMap();
|
Map<Integer, List<PwrdevAcdcdata>> adfuseMap = acdcList.stream().collect(Collectors.groupingBy(PwrdevAcdcdata::getIsLoaderFuse));
|
for (Integer fuse : adfuseMap.keySet()) {
|
fusemap.put(fuse, adfuseMap.get(fuse).size());
|
}
|
map.put("fusemap", fusemap);
|
//站点统计
|
|
return new Response().setII(1, true, map, "站点实时数据推送");
|
} catch (Exception e) {
|
return new Response().set(1, false, "发生异常:" + e.getCause());
|
}
|
|
}
|
|
//指定站点详情第一次跳转机房id为0:message
|
public Response getDevOpSkipStation(int userId, String stationId) {
|
//查询指定机房信息
|
StationInf inf = mapper.getSystemSkipStation(userId, stationId);
|
if (inf != null) {
|
if (inf.getRtlist() != null && inf.getRtlist().size() > 0) {
|
for (int i = 0; i < inf.getRtlist().size(); i++) {
|
//判断是否落后
|
int battGroupId = inf.getRtlist().get(i).getBattGroupId();
|
int badbattFlag = badMapper.judgeBatt(battGroupId);
|
inf.getRtlist().get(i).setBadbattFlag(badbattFlag);
|
}
|
}
|
//查询停电续航时间
|
QueryWrapper wrapper = new QueryWrapper();
|
wrapper.eq("stationid", stationId);
|
BattEndurance endurance = endMapper.selectOne(wrapper);
|
if (endurance != null) {
|
inf.setEndurance(endurance);
|
}
|
return new Response().setII(1, true, inf, "指定站点详情");
|
} else {
|
return new Response().set(1, false, "指定站点详情");
|
}
|
}
|
}
|