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.dto.result.SystemGrdoupBatt;
|
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 javax.annotation.Resource;
|
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;
|
|
@Resource
|
BadbattMonMapper badbattMonMapper;
|
@Resource
|
AlarmParamMapper alarmParamMapper;
|
|
//插入站点
|
public Response insertStation(StationInf stationInf) {
|
int flag = mapper.insert(stationInf);
|
return new Response().set(1, flag > 0, "插入站点");
|
}
|
|
//查询所有的站点
|
public Response searchStationAll(int pageCurr, int pageSize, String stationName1, String stationName2, String stationName5) {
|
PageHelper.startPage(pageCurr, pageSize);
|
QueryWrapper wrapper = new QueryWrapper();
|
if (!(stationName1 == null || stationName1.isEmpty())) {
|
wrapper.eq("stationName1", stationName1);
|
}
|
if (!(stationName2 == null || stationName2.isEmpty())) {
|
wrapper.eq("stationName2", stationName2);
|
}
|
if (!(stationName5 == null || stationName5.isEmpty())) {
|
wrapper.eq("stationName5", stationName5);
|
}
|
List<StationInf> list = mapper.selectList(wrapper);
|
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) {
|
try {
|
Map<String, Object> map = new HashMap();
|
//头部统计数据
|
int stationNum = mapper.getStation(userId);
|
map.put("stationNum", stationNum);
|
//浮充/充电
|
List<BattRtstate> stateList = rtstateMapper.getBattStateStatic(userId);
|
Map<String, Integer> statemap = new HashMap();
|
statemap.put("batt1", 0);
|
statemap.put("batt2", 0);
|
Map<Integer, List<BattRtstate>> battstateMap = stateList.stream().collect(Collectors.groupingBy(BattRtstate::getBattState));
|
for (Integer state : battstateMap.keySet()) {
|
if (state == 1 || state == 2) {
|
statemap.put("batt" + state, battstateMap.get(state).size());
|
}
|
}
|
map.put("battState", statemap);
|
//整流器故障/负载熔断
|
List<PwrdevAcdcdata> acdcList = acdcMapper.getAcdcStatic(userId);
|
Map<String, Integer> errmap = new HashMap();
|
Map<Integer, List<PwrdevAcdcdata>> aderrMap = acdcList.stream().collect(Collectors.groupingBy(PwrdevAcdcdata::getAcdcErr));
|
errmap.put("err0", 0);
|
errmap.put("err1", 0);
|
for (Integer acdcerr : aderrMap.keySet()) {
|
errmap.put("err" + acdcerr, aderrMap.get(acdcerr).size());
|
}
|
map.put("errmap", errmap);
|
Map<String, Integer> fusemap = new HashMap();
|
fusemap.put("fuse0", 0);
|
fusemap.put("fuse1", 0);
|
Map<Integer, List<PwrdevAcdcdata>> adfuseMap = acdcList.stream().collect(Collectors.groupingBy(PwrdevAcdcdata::getIsLoaderFuse));
|
for (Integer fuse : adfuseMap.keySet()) {
|
fusemap.put("fuse" + fuse, adfuseMap.get(fuse).size());
|
}
|
map.put("fusemap", fusemap);
|
List<StationInf> list = mapper.getSystemAll(userId);
|
for (StationInf inf : list) {
|
String stationId = inf.getStationId();
|
//查询分组电池信息
|
List<SystemGrdoupBatt> sgblist = rtstateMapper.selectSystemGrdoupBatt(stationId);
|
for (int i = 0; i < sgblist.size(); i++) {
|
int battGroupId = sgblist.get(i).getBattGroupId();
|
//查询机房下最大的单体电压和单体
|
BattRtdata maxData = rtdataMapper.maxData(battGroupId);
|
sgblist.get(i).setMaxVol(maxData.getMonVol());
|
sgblist.get(i).setMaxNum(maxData.getMonNum());
|
//查询机房下最低的单体电压和单体
|
BattRtdata minData = rtdataMapper.minData(battGroupId);
|
sgblist.get(i).setMinVol(maxData.getMonVol());
|
sgblist.get(i).setMinNum(maxData.getMonNum());
|
//查询实时告警总数
|
int battAlm = battAlmMapper.getbattAlm(battGroupId);
|
sgblist.get(i).setBattAlm(battAlm);
|
}
|
inf.setSgbList(sgblist);
|
int devAlm = devAlmMapper.getdevAlm(stationId);
|
inf.setDevAlm(devAlm);
|
int pwrAlm = pwrAlmMapper.getpwrAlm(stationId);
|
inf.setPwrAlm(pwrAlm);
|
}
|
map.put("data", list);
|
return new Response().setII(1, true, map, "站点实时数据推送");
|
} catch (Exception e) {
|
return new Response().set(1, false, "发生异常:" + e.getCause());
|
}
|
}
|
|
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, Object> 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());
|
//站点地图
|
List<StationInf> mapAndWorkStateList = getStationMapAndWorkState(userId);
|
stationInfoMap.put("stationMap",mapAndWorkStateList);
|
return new Response().setII(1,true,stationInfoMap,null);
|
}catch (Exception e){
|
return new Response().set(1,false,"发生异常:"+e.getCause());
|
}
|
}
|
|
public List<StationInf> getStationMapAndWorkState(int userId) {
|
return mapper.getStationMapAndWorkState(userId);
|
}
|
|
//运维层首页:站点实时数据推送
|
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) {
|
//查询分组电池信息
|
List<SystemGrdoupBatt> sgblist = rtstateMapper.selectSystemGrdoupBatt(stationId);
|
for (int i = 0; i < sgblist.size(); i++) {
|
int battGroupId = sgblist.get(i).getBattGroupId();
|
//查询机房下最大的单体电压和单体
|
BattRtdata maxData = rtdataMapper.maxData(battGroupId);
|
sgblist.get(i).setMaxVol(maxData.getMonVol());
|
sgblist.get(i).setMaxNum(maxData.getMonNum());
|
//查询机房下最低的单体电压和单体
|
BattRtdata minData = rtdataMapper.minData(battGroupId);
|
sgblist.get(i).setMinVol(maxData.getMonVol());
|
sgblist.get(i).setMinNum(maxData.getMonNum());
|
//查询实时告警总数
|
int battAlm = battAlmMapper.getbattAlm(battGroupId);
|
sgblist.get(i).setBattAlm(battAlm);
|
}
|
inf.setSgbList(sgblist);
|
int devAlm = devAlmMapper.getdevAlm(stationId);
|
inf.setDevAlm(devAlm);
|
int pwrAlm = pwrAlmMapper.getpwrAlm(stationId);
|
inf.setPwrAlm(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);
|
//站点统计
|
List<StationInf> stationInfList = mapper.getStationInfList(userId);
|
//站点数
|
map.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) {
|
map.put(stationType, stationTypeMap.get(stationType).size());
|
}
|
//节点站和普通站
|
List<Battinf> stationList = battInfService.getSateAnalysis(userId);
|
Map<Integer, List<Battinf>> nodeStationMap = stationList.stream().collect(Collectors.groupingBy(Battinf::getNodeStation));
|
|
map.put("nomalStation", nodeStationMap.get(0) == null ? 0 : nodeStationMap.get(0).size());
|
map.put("nodeStation", nodeStationMap.get(1) == null ? 0 : nodeStationMap.get(1).size());
|
|
//停电站和核容放电站
|
List<Fbs9100State> f9100stateList = fbs9100StateService.getStateList(userId);
|
Map<Integer, List<Fbs9100State>> stateMap = f9100stateList.stream().collect(Collectors.groupingBy(Fbs9100State::getDevWorkstate));
|
map.put("checkCapDischarge", stateMap.get(2) == null ? 0 : stateMap.get(2).size());
|
map.put("powerOff", stateMap.get(3) == null ? 0 : stateMap.get(3).size());
|
|
//1.查询劣化(告警)和损坏(更换)的阈值
|
QueryWrapper<AlarmParam> alarmWrapper = new QueryWrapper();
|
alarmWrapper.and(wrapper -> {
|
return wrapper.eq("alm_name", "Batt_Alarm_Type_CapAlarm").or().eq("alm_name", "Batt_Alarm_Type_CapChange");
|
});
|
alarmWrapper.orderByAsc("alm_id");
|
List<AlarmParam> paramList = alarmParamMapper.selectList(alarmWrapper);
|
float capAlarm = paramList.get(0).getAlmLowCoe();//劣化参数0.8
|
float capChange = paramList.get(1).getAlmLowCoe();//损坏参数0.6
|
//劣化数量(包含损坏)
|
int alarmNum = badbattMonMapper.getQualityAnalysis(userId, capAlarm);
|
//损坏数量
|
int changeNum = badbattMonMapper.getQualityAnalysis(userId, capChange);
|
map.put("alarmNum", (alarmNum - changeNum));
|
map.put("changeNum", changeNum);
|
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) {
|
//查询分组电池信息
|
List<SystemGrdoupBatt> sgblist = rtstateMapper.selectSystemGrdoupBatt(stationId);
|
if (sgblist != null && sgblist.size() > 0) {
|
for (int i = 0; i < sgblist.size(); i++) {
|
//判断是否落后
|
int battGroupId = sgblist.get(i).getBattGroupId();
|
int badbattFlag = badMapper.judgeBatt(battGroupId);
|
sgblist.get(i).setBadbattFlag(badbattFlag);
|
}
|
inf.setSgbList(sgblist);
|
}
|
//查询停电续航时间
|
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, "指定站点详情");
|
}
|
}
|
|
//查询省
|
public Response searchAllStationName1(int uId) {
|
List<String> list = mapper.getStationName1ByUserId(uId);
|
return new Response().set(1, list, "查询成功");
|
}
|
|
public Response searchAllStationName2(Integer uId, String stationName1) {
|
List<String> list = mapper.getStationName2ByUseridAndSt1(uId, stationName1);
|
return new Response().set(1, list, "查询成功");
|
}
|
|
public Response searchAllStationName5(Integer uId, String stationName1, String stationName2) {
|
List<String> list = mapper.getStationName5ByUseridAndSt1AndSt2(stationName1, stationName2, uId);
|
return new Response().set(1, list, "查询成功");
|
}
|
}
|