暂降模块代码合并

终端运行管理接口调整
This commit is contained in:
2022-09-15 10:56:22 +08:00
parent 07775513a0
commit e3d77c23a8
92 changed files with 17262 additions and 500 deletions

View File

@@ -3,6 +3,7 @@ package com.njcn.event.service;
import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.device.pojo.vo.TerminalBaseVO;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.event.pojo.po.EventDetailNew;
import com.njcn.event.pojo.vo.AreaSubLineVO;
import java.util.List;
@@ -35,5 +36,12 @@ public interface AreaInfoService {
* @author cdf
* @date 2022/6/29
*/
List<EventDetail> getNoDealEvents(DeviceInfoParam.BusinessParam deviceInfoParam);
List<EventDetailNew> getNoDealEvents(DeviceInfoParam deviceInfoParam);
/**
* 获取监测点下未处理的暂降事件
* @author cdf
* @date 2022/6/29
*/
List<EventDetailNew> getNoDealEventsByLineId(String id);
}

View File

@@ -2,7 +2,6 @@ package com.njcn.event.service;
import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.event.pojo.po.BalanceInfo;
import com.njcn.event.pojo.vo.*;
import java.util.List;
@@ -43,11 +42,4 @@ public interface AreaLineService {
*/
TerminalRunningStatisticsVO getTerminalRunningStatistics(DeviceInfoParam.BusinessParam deviceInfoParam);
/**
* 获取区域暂降综合评估
* @param deviceInfoParam 参数
* @return 结果
*/
List<BalanceInfo> getBalanceInfo(DeviceInfoParam.BusinessParam deviceInfoParam);
}

View File

@@ -1,8 +1,14 @@
package com.njcn.event.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.event.pojo.param.EventBaseParam;
import com.njcn.common.pojo.dto.wave.WaveDataDTO;
import com.njcn.event.pojo.param.*;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.event.pojo.vo.*;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.util.List;
/**
* pqs-event
@@ -18,4 +24,78 @@ public interface EventAnalysisService {
* @date 2022/6/23
*/
Page<EventDetail> getEventAnalyse(EventBaseParam eventBaseParam);
/**
* 获取坐标
* @param statisticsParam
* @return
*/
List<CoordsVO> getCoords(StatisticsParam statisticsParam);
/**
*获取Disdip表格
* @param statisticsParam
* @return
*/
List<DISDIPVO> eventDisdip(StatisticsParam statisticsParam);
/**
* 获取IEC411数据
* @param statisticsParam
* @return
*/
List<IEC411VO> IEC411(StatisticsParam statisticsParam);
/**
* 获取IEC28数据
* @param statisticsParam
* @return
*/
List<IEC28VO> IEC28(StatisticsParam statisticsParam);
/**
* 获取时间列表
* @param statisticsParam
* @return
*/
List<TimeVO> getReasonTypeTime(StatisticsParam statisticsParam) throws ParseException;
/**
* 获取详细数据对象
* @param statisticsParam
* @return
*/
StatisticVO getStatistic(StatisticsParam statisticsParam);
ProbabilityVO getProbabilityDistribution(StatisticsParam statisticsParam);
/**
* 获取点状表格数据
* @param statisticsParam
* @return
*/
List<EventDetail> getPlot(StatisticsParam statisticsParam);
/**
*监测点暂降事件分析查询
* @author zbj
* @date 2022/7/25
*/
Page<WaveTypeVO> getMonitorEventAnalyseQuery(EventBaseParam eventBaseParam);
/**
*监测点事件波形分析
* @author zbj
* @date 2022/7/27
*/
WaveDataDTO getMonitorEventAnalyseWave(String timeId, String lineId);
/**
*监测点事件波形下载
* @author zbj
* @date 2022/7/28
*/
HttpServletResponse downloadMonitorEventWaveFile(WaveFileParam waveFileParam, HttpServletResponse response) throws Exception;
}

View File

@@ -15,9 +15,14 @@ import com.njcn.event.service.AreaAnalysisService;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.enums.DicDataTypeEnum;
import com.njcn.system.pojo.po.DictData;
import io.swagger.models.auth.In;
import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.units.qual.A;
import org.influxdb.querybuilder.clauses.Clause;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -25,6 +30,7 @@ import java.util.stream.Collectors;
import static com.njcn.event.influxdb.PqsEventDetailQuery.lineIdOr;
import static com.njcn.event.influxdb.PqsEventDetailQuery.timeAndType;
import static com.njcn.event.influxdb.QueryBuilder.*;
import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.eq;
/**
* pqs-event
@@ -36,12 +42,12 @@ import static com.njcn.event.influxdb.QueryBuilder.*;
@RequiredArgsConstructor
public class AreaAnalysisServiceImpl implements AreaAnalysisService {
private final GeneralDeviceInfoClient generalDeviceInfoClient;
private final DicDataFeignClient dicDataFeignClient;
private final LineFeignClient lineFeignClient;
private final PqsEventDetailQuery pqsEventDetailQuery;
@Override
public AreaAnalysisVO getEventReason(DeviceInfoParam.BusinessParam deviceInfoParam) {
AreaAnalysisVO areaAnalysisVO = new AreaAnalysisVO();
@@ -50,14 +56,31 @@ public class AreaAnalysisServiceImpl implements AreaAnalysisService {
// 获取指定部门下的监测点集合
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
List<String> lineIds = getAllLineIdList(generalDeviceDTOList);
List<AreaAnalysisVO.Children> reasonList = assData(dicReasonList, lineIds, deviceInfoParam.getSearchBeginTime(), deviceInfoParam.getSearchEndTime(), "event_reason");
List<AreaAnalysisVO.Children> typeList = assData(dicTypeList, lineIds, deviceInfoParam.getSearchBeginTime(), deviceInfoParam.getSearchEndTime(), "event_type");
//暂降类型特殊处理
DictData dictData = dicReasonList.stream().filter(item->"短路故障".equals(item.getName())).findFirst().get();
List<String> dicIdsXi = dicTypeList.stream().filter(item->item.getName().contains("相间")).map(DictData::getId).collect(Collectors.toList());
List<String> dicIdsOne = dicTypeList.stream().filter(item->"A相".equals(item.getName())||"B相".equals(item.getName())||"C相".equals(item.getName())).map(DictData::getId).collect(Collectors.toList());
List<String> dicIdsThree = dicTypeList.stream().filter(item->item.getName().contains("三相接地")).map(DictData::getId).collect(Collectors.toList());
List<String> dicIdsOther = dicTypeList.stream().filter(item->item.getName().contains("其他")).map(DictData::getId).collect(Collectors.toList());
List<String> dicIdsDouble = dicTypeList.stream().filter(item->item.getName().contains("双相接地")).map(DictData::getId).collect(Collectors.toList());
Map<String, List<String>> stringListMap = new HashMap<>();
stringListMap.put("单相接地",dicIdsOne);
stringListMap.put("双相接地",dicIdsDouble);
stringListMap.put("三相短路",dicIdsThree);
stringListMap.put("相间故障",dicIdsXi);
stringListMap.put("未知",dicIdsOther);
List<AreaAnalysisVO.Children> typeList = assReason(stringListMap,lineIds,deviceInfoParam.getSearchBeginTime(), deviceInfoParam.getSearchEndTime(),dictData.getId());
areaAnalysisVO.setReason(reasonList);
areaAnalysisVO.setType(typeList);
return areaAnalysisVO;
}
/**
* 获取电压容忍度曲线兼容性统计
*
@@ -71,47 +94,47 @@ public class AreaAnalysisServiceImpl implements AreaAnalysisService {
if (CollUtil.isEmpty(generalDeviceDTOList)) {
return VoltageToleranceCurveVO.empty();
}
List<String> lineIds = getAllLineIdList(generalDeviceDTOList);
if (CollUtil.isEmpty(lineIds)) {
return VoltageToleranceCurveVO.empty();
}
List<AreaLineInfoVO> getBaseLineAreaInfo = lineFeignClient.getBaseLineAreaInfo(lineIds).getData();
if (CollUtil.isEmpty(getBaseLineAreaInfo)) {
return VoltageToleranceCurveVO.empty();
}
Map<String, AreaLineInfoVO> areaLineInfoVOMap =
getBaseLineAreaInfo.parallelStream().collect(Collectors.toConcurrentMap(AreaLineInfoVO::getLineId,
Function.identity()));
List<EventDetail> eventDetailList = pqsEventDetailQuery.selectList(Arrays.asList("line_id", "persist_time", "event_value", "create_time"),
List<EventDetail> eventDetailList = pqsEventDetailQuery.selectList(Arrays.asList("time","line_id", "persist_time", "event_value"),
lineIdOr(lineIds), timeAnd(beginOfDay(deviceInfoParam.getSearchBeginTime()),
endOfDay(deviceInfoParam.getSearchEndTime())));
if (CollUtil.isEmpty(eventDetailList)) {
return VoltageToleranceCurveVO.empty();
}
List<VoltageToleranceCurveDataList> curveDataList = eventDetailList.parallelStream()
.map(dto -> {
AreaLineInfoVO info = areaLineInfoVOMap.get(dto.getLineId());
VoltageToleranceCurveDataList voltageToleranceCurve = new VoltageToleranceCurveDataList();
voltageToleranceCurve.setLineId(dto.getLineId());
voltageToleranceCurve.setPersistTime(dto.getPersistTime());
voltageToleranceCurve.setEventValue(dto.getEventValue());
voltageToleranceCurve.setTime(dto.getCreateTime());
voltageToleranceCurve.setTime(LocalDateTime.ofInstant(dto.getTimeId(), ZoneId.systemDefault()));
voltageToleranceCurve.setGdName(info.getGdName());
voltageToleranceCurve.setSubName(info.getSubName());
return voltageToleranceCurve;
})
.sorted(VoltageToleranceCurveDataList.sortAscTime())
//.sorted(VoltageToleranceCurveDataList.sortAscTime())
.collect(Collectors.toCollection(() -> Collections.synchronizedList(new ArrayList<>())));
return VoltageToleranceCurveVO.buildVO(eventDetailList.size(), curveDataList);
}
/**
* 获取全部的LineID
*
@@ -121,8 +144,8 @@ public class AreaAnalysisServiceImpl implements AreaAnalysisService {
private List<String> getAllLineIdList(List<GeneralDeviceDTO> generalDeviceDTOList) {
return generalDeviceDTOList.stream().flatMap(dto -> dto.getLineIndexes().stream()).collect(Collectors.toList());
}
private List<AreaAnalysisVO.Children> assData(List<DictData> dicList, List<String> lineIds, String startTime, String endTime, String type) {
List<AreaAnalysisVO.Children> reasonList = new ArrayList<>();
Integer allCount = 0;
@@ -131,7 +154,7 @@ public class AreaAnalysisServiceImpl implements AreaAnalysisService {
Integer count = pqsEventDetailQuery.selectCount(Collections.singletonList(type),
lineIdOr(lineIds), timeAndType(beginOfDay(startTime),
endOfDay(endTime), type, reason.getId()));
AreaAnalysisVO.Children children = new AreaAnalysisVO.Children();
children.setName(reason.getName());
children.setValue(count);
@@ -144,4 +167,36 @@ public class AreaAnalysisServiceImpl implements AreaAnalysisService {
reasonList.add(allType);
return reasonList;
}
private List<AreaAnalysisVO.Children> assReason(Map<String, List<String>> stringListMap, List<String> lineIds, String startTime, String endTime, String typeId){
List<AreaAnalysisVO.Children> reasonList = new ArrayList<>();
Integer allCount = 0;
for (Map.Entry<String, List<String>> stringListEntry : stringListMap.entrySet()) {
// 暂降原因类型次数
List<List<Clause>> clauseList = new ArrayList<>();
List<Clause> clauses = new ArrayList<>();
for (String id : stringListEntry.getValue()) {
clauses.add(eq("event_reason", id));
}
clauseList.add(lineIdOr(lineIds));
clauseList.add(clauses);
Integer count = pqsEventDetailQuery.selectCountUp(Collections.singletonList("event_type"), clauseList
, timeAndType(beginOfDay(startTime),
endOfDay(endTime), "event_reason", typeId));
AreaAnalysisVO.Children children = new AreaAnalysisVO.Children();
children.setName(stringListEntry.getKey());
children.setValue(count);
allCount += count;
reasonList.add(children);
}
AreaAnalysisVO.Children allType = new AreaAnalysisVO.Children();
allType.setName("总计");
allType.setValue(allCount);
reasonList.add(allType);
return reasonList;
}
}

View File

@@ -11,10 +11,14 @@ import com.njcn.device.pojo.vo.AreaLineInfoVO;
import com.njcn.device.pojo.vo.TerminalBaseVO;
import com.njcn.event.pojo.constant.Param;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.event.pojo.po.EventDetailNew;
import com.njcn.event.pojo.vo.AreaLineVO;
import com.njcn.event.pojo.vo.AreaSubLineVO;
import com.njcn.event.service.AreaInfoService;
import com.njcn.event.utils.CommUtil;
import com.njcn.influxdb.mapper.InfluxDBResultMapperCn;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDBCommUtils;
import com.njcn.influxdb.utils.InfluxDbUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -26,6 +30,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* pqs-event
@@ -56,21 +61,24 @@ public class AreaInfoServiceImpl implements AreaInfoService {
if (CollectionUtil.isNotEmpty(lineIds)) {
List<AreaLineInfoVO> resList = lineFeignClient.getBaseLineAreaInfo(lineIds).getData();
//查询监测点未处理暂态事件
StringBuilder lineIdsStr = CommUtil.assToInfluxParam(lineIds);
StringBuilder lineIdsStr = InfluxDBCommUtils.assToInfluxParam(lineIds);
String stringResult = "SELECT count(eventass_index) FROM " + Param.EVENT_DETAIL + Param.WHERE + "time >= '" + deviceInfoParam.getSearchBeginTime() + InfluxDBPublicParam.START_TIME + "' and " + "time <= '" + deviceInfoParam.getSearchEndTime() + InfluxDBPublicParam.END_TIME + "' and " + lineIdsStr + " and eventass_index = '' group by line_id" + InfluxDBPublicParam.TIME_ZONE;
// 结果集
QueryResult result = influxDbUtils.query(stringResult);
if (!result.hasError()) {
List<QueryResult.Series> list = result.getResults().get(0).getSeries();
for (AreaLineInfoVO areaLineInfoVO : resList) {
boolean flag = false;
for (QueryResult.Series tem : list) {
String lineId = tem.getTags().get("line_id");
if (areaLineInfoVO.getLineId().equals(lineId)) {
areaLineInfoVO.setNoDealCount(Double.valueOf(tem.getValues().get(0).get(1).toString()).intValue());
flag = true;
break;
if(CollectionUtil.isNotEmpty(list)) {
for (QueryResult.Series tem : list) {
String lineId = tem.getTags().get("line_id");
if (areaLineInfoVO.getLineId().equals(lineId)) {
areaLineInfoVO.setNoDealCount(Double.valueOf(tem.getValues().get(0).get(1).toString()).intValue());
flag = true;
break;
}
}
}
if (!flag) {
@@ -107,28 +115,30 @@ public class AreaInfoServiceImpl implements AreaInfoService {
}
@Override
public List<EventDetail> getNoDealEvents(DeviceInfoParam.BusinessParam deviceInfoParam) {
List<EventDetail> resList = new ArrayList<>();
public List<EventDetailNew> getNoDealEvents(DeviceInfoParam deviceInfoParam) {
List<EventDetailNew> resList = new ArrayList<>();
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
List<String> lineIds = generalDeviceDTOList.stream().flatMap(dto -> dto.getLineIndexes().stream()).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(lineIds)) {
List<Line> lineList = lineFeignClient.getBaseLineList(lineIds).getData();
List<AreaLineInfoVO> lineList = lineFeignClient.getBaseLineAreaInfo(lineIds).getData();
//查询监测点未处理暂态事件
StringBuilder lineIdsStr = CommUtil.assToInfluxParam(lineIds);
StringBuilder lineIdsStr = InfluxDBCommUtils.assToInfluxParam(lineIds);
String stringResult = "SELECT * FROM " + Param.EVENT_DETAIL + Param.WHERE + "time >= '" + deviceInfoParam.getSearchBeginTime() + Param.BEGIN + "' and " + "time <= '" + deviceInfoParam.getSearchEndTime() + Param.END + "' and " + lineIdsStr + "and eventass_index = '' " + InfluxDBPublicParam.TIME_ZONE;
String stringResult = "SELECT * FROM " + Param.EVENT_DETAIL + Param.WHERE + lineIdsStr + "and eventass_index = '' order by time desc limit 100" + InfluxDBPublicParam.TIME_ZONE;
// 结果集
QueryResult result = influxDbUtils.query(stringResult);
// 结果集映射到对象中
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
resList = influxDBResultMapper.toPOJO(result, EventDetail.class);
InfluxDBResultMapperCn influxDBResultMapper = new InfluxDBResultMapperCn();
resList = influxDBResultMapper.toPOJO(result, EventDetailNew.class);
//对未处理暂降事件的监测点替换成中文名称
if (CollectionUtil.isNotEmpty(resList)) {
for (EventDetail eventDetail : resList) {
for (Line tem : lineList) {
if (eventDetail.getLineId().equals(tem.getId())) {
eventDetail.setLineId(tem.getName());
for (EventDetailNew eventDetail : resList) {
for (AreaLineInfoVO tem : lineList) {
if (eventDetail.getLineId().equals(tem.getLineId())) {
eventDetail.setLineName(tem.getLineName());
eventDetail.setLng(tem.getLng());
eventDetail.setLat(tem.getLat());
break;
}
}
@@ -138,5 +148,26 @@ public class AreaInfoServiceImpl implements AreaInfoService {
return resList;
}
@Override
public List<EventDetailNew> getNoDealEventsByLineId(String id) {
String stringResult = "SELECT * FROM " + Param.EVENT_DETAIL + Param.WHERE + "line_id = '"+id+"' and eventass_index = '' order by time desc limit 100" + InfluxDBPublicParam.TIME_ZONE;
// 结果集
QueryResult result = influxDbUtils.query(stringResult);
// 结果集映射到对象中
InfluxDBResultMapperCn influxDBResultMapper = new InfluxDBResultMapperCn();
List<EventDetailNew> resList = influxDBResultMapper.toPOJO(result, EventDetailNew.class);
List<AreaLineInfoVO> lineList = lineFeignClient.getBaseLineAreaInfo(Stream.of(id).collect(Collectors.toList())).getData();
if(CollectionUtil.isNotEmpty(lineList)){
resList = resList.stream().peek(item->{
item.setGdName(lineList.get(0).getGdName());
item.setSubName(lineList.get(0).getSubName());
item.setLineName(lineList.get(0).getLineName());
}).collect(Collectors.toList());
}
return resList;
}
}

View File

@@ -3,23 +3,24 @@ package com.njcn.event.service.Impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ArrayUtil;
import com.njcn.common.pojo.enums.common.ServerEnum;
import com.njcn.device.api.GeneralDeviceInfoClient;
import com.njcn.device.api.LineFeignClient;
import com.njcn.device.pojo.dto.GeneralDeviceDTO;
import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.device.pojo.vo.LineDetailDataVO;
import com.njcn.device.pojo.vo.AreaLineInfoVO;
import com.njcn.device.pojo.vo.LineDetailVO;
import com.njcn.device.pojo.vo.LineDeviceStateVO;
import com.njcn.device.pojo.vo.SubstationDetailVO;
import com.njcn.event.influxdb.PqsOnlinerateQuery;
import com.njcn.event.mapper.PqDeviceMapper;
import com.njcn.event.pojo.po.*;
import com.njcn.event.pojo.po.PqDevice;
import com.njcn.event.pojo.po.PqsOnlinerate;
import com.njcn.event.pojo.vo.*;
import com.njcn.event.pojo.vo.TerminalRunningStatisticsVO.TerminalRunningInfoVO;
import com.njcn.event.pojo.vo.TerminalRunningStatisticsVO.TerminalRunningVO;
import com.njcn.event.service.AreaLineService;
import com.njcn.event.service.EventDetailService;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.system.pojo.enums.StatisticsEnum;
@@ -39,8 +40,6 @@ import java.util.stream.Collectors;
import static com.njcn.event.influxdb.PqsOnlinerateQuery.devIdOr;
import static com.njcn.event.influxdb.QueryBuilder.*;
import com.njcn.event.pojo.po.BalanceInfo.PointInfo;
/**
* @author denghuajun
* @version 1.0.0
@@ -61,8 +60,6 @@ public class AreaLineServiceImpl implements AreaLineService {
private final PqDeviceMapper pqDeviceMapper;
private final EventDetailService eventDetailService;
@Override
public AreaLineVO getAreaLineVO(DeviceInfoParam deviceInfoParam) {
AreaLineVO areaLineVO = new AreaLineVO();
@@ -154,15 +151,14 @@ public class AreaLineServiceImpl implements AreaLineService {
@Override
public EventHeatMapVO getEventHeatMap(DeviceInfoParam.BusinessParam deviceInfoParam) {
EventHeatMapVO eventHeatMapVO = new EventHeatMapVO();
List<EventHeatMapDetailVO> eventHeatMapDetailList = new ArrayList<>();
List<List<Object>> eventHeatMapDetailList = new ArrayList<>();
deviceInfoParam.setServerName(ServerEnum.EVENT.getName());
List<List<Object>> listObject = new ArrayList<>();
List<BaseVO> listObject = new ArrayList<>();
// 获取暂降监测点
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
List<String> lineIndexs;
int i = 0, generalDeviceListSize = generalDeviceDTOList.size();
while (i < generalDeviceListSize) {
List<Object> objectList = new ArrayList<>();
GeneralDeviceDTO generalDeviceDTO = generalDeviceDTOList.get(i);
lineIndexs = generalDeviceDTO.getLineIndexes();
// 获取暂降数据
@@ -170,18 +166,33 @@ public class AreaLineServiceImpl implements AreaLineService {
int tail = 0;
List<EventHeatDeatilVO> eventdetailList = getContion(deviceInfoParam, lineIndexs);
if (eventdetailList.size() > 0) {
for (int eventNum = 0; eventNum < eventdetailList.size(); eventNum++) {
EventHeatMapDetailVO eventHeatMapDetailVO = new EventHeatMapDetailVO();
LineDetailVO lineDetailVO = lineFeignClient.getLineSubGdDetail(eventdetailList.get(eventNum).getLineId()).getData();
BeanUtil.copyProperties(lineDetailVO, eventHeatMapDetailVO);
eventHeatMapDetailVO.setEventNum(eventdetailList.get(eventNum).getCount());
tail += eventdetailList.get(eventNum).getCount();
eventHeatMapDetailList.add(eventHeatMapDetailVO);
List<String> lineIds = eventdetailList.stream().map(EventHeatDeatilVO::getLineId).collect(Collectors.toList());
List<AreaLineInfoVO> areaAnalysisVOList = lineFeignClient.getBaseLineAreaInfo(lineIds).getData();
for (EventHeatDeatilVO eventHeat : eventdetailList) {
for(AreaLineInfoVO areaLineInfoVO : areaAnalysisVOList){
if(eventHeat.getLineId().equals(areaLineInfoVO.getLineId())){
List<Object> ev = new ArrayList<>();
tail += eventHeat.getCount();
ev.add(areaLineInfoVO.getLng());
ev.add(areaLineInfoVO.getLat());
ev.add(tail);
eventHeatMapDetailList.add(ev);
break;
}
}
}
objectList.add(generalDeviceDTO.getName() + "\n(" + lineIndexs.size() + ")");
objectList.add(tail);
listObject.add(objectList);
BaseVO baseVO = new BaseVO();
baseVO.setName(generalDeviceDTO.getName());
baseVO.setValue(BigDecimal.valueOf(lineIndexs.size()));
listObject.add(baseVO);
}
} else {
BaseVO baseVO = new BaseVO();
baseVO.setName(generalDeviceDTO.getName());
baseVO.setValue(BigDecimal.valueOf(3.141592));
listObject.add(baseVO);
}
i++;
}
@@ -247,62 +258,17 @@ public class AreaLineServiceImpl implements AreaLineService {
return TerminalRunningStatisticsVO.buildVO(area, factory);
}
@Override
public List<BalanceInfo> getBalanceInfo(DeviceInfoParam.BusinessParam deviceInfoParam) {
List<BalanceInfo> balanceInfos = new ArrayList<>();
//获取符合条件的监测点
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
if (CollUtil.isEmpty(generalDeviceDTOList)) {
return balanceInfos;
}
for (GeneralDeviceDTO generalDeviceDTO : generalDeviceDTOList) {
BalanceInfo balanceInfo = new BalanceInfo();
balanceInfo.setAreaName(generalDeviceDTO.getName());
balanceInfo.setAreaIndex(generalDeviceDTO.getIndex());
//监测点
List<String> lineList = generalDeviceDTO.getLineIndexes();
List<PointInfo> list = new ArrayList<>();
for (String lineIndex : lineList) {
PointInfo pointInfo = balanceInfo.new PointInfo();
Float value = getSarfiValue(deviceInfoParam.getSearchBeginTime(), deviceInfoParam.getSearchEndTime(), 0.9f, lineIndex);
pointInfo.getQtIdx().r_esm = (value == null ? 0f : value);
pointInfo.getQtIdx().sarfi_90 = getSarfiCount(deviceInfoParam.getSearchBeginTime(), deviceInfoParam.getSearchEndTime(), 0.9f, lineIndex); // 统计小于0.9的总数
pointInfo.getQtIdx().sarifi_50 = getSarfiCount(deviceInfoParam.getSearchBeginTime(), deviceInfoParam.getSearchEndTime(), 0.5f, lineIndex); // 统计小于0.9的总数 // 统计小于0.5的总数
//获取当前监测点的暂降信息
List<EventDetail> eventDetailList = getEventDetailInfo(lineIndex, 0.9f, deviceInfoParam.getSearchBeginTime(), deviceInfoParam.getSearchEndTime());
if(eventDetailList.size()>0) {
//获取监测点信息
LineDetailDataVO lineDetailVO = lineFeignClient.getLineDetailData(lineIndex).getData();
List<Sarifi> sarifis = new ArrayList<>();
for (EventDetail eventDetail:eventDetailList){
Sarifi sarifi = new Sarifi();
sarifi.setTime(eventDetail.getPersistTime().floatValue());
}
}
}
}
return balanceInfos;
}
private TerminalRunningVO analyzeTerminalRun(DeviceInfoParam.BusinessParam deviceInfoParam) {
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
if (CollUtil.isEmpty(generalDeviceDTOList)) {
return TerminalRunningVO.empty();
}
List<String> deviceIndexList =
generalDeviceDTOList.stream().flatMap(dto -> dto.getDeviceIndexes().stream()).collect(Collectors.toList());
List<String> deviceIndexList = generalDeviceDTOList.stream().flatMap(dto -> dto.getDeviceIndexes().stream()).collect(Collectors.toList());
if (CollUtil.isEmpty(deviceIndexList)) {
return TerminalRunningVO.empty();
}
List<PqsOnlinerate> pqsOnlinerateList =
pqsOnlinerateQuery.selectList(Arrays.asList("dev_id", "offlinemin", "onlinemin"),
devIdOr(deviceIndexList),
timeAnd(beginOfDay(deviceInfoParam.getSearchBeginTime()), endOfDay(deviceInfoParam.getSearchEndTime())));
List<PqsOnlinerate> pqsOnlinerateList = pqsOnlinerateQuery.selectList(Arrays.asList("dev_id", "offlinemin", "onlinemin"),
devIdOr(deviceIndexList),
timeAnd(beginOfDay(deviceInfoParam.getSearchBeginTime()), endOfDay(deviceInfoParam.getSearchEndTime())));
List<PqDevice> pqDeviceList = pqDeviceMapper.queryRunFlagByDeviceIndexs(deviceIndexList);
@@ -316,9 +282,9 @@ public class AreaLineServiceImpl implements AreaLineService {
terminalRunningInfoVO.setBreaks(countDeviceRunStatus(pqDeviceList).apply(1, deviceIndexes));
terminalRunningInfoVO.setShutdown(countDeviceRunStatus(pqDeviceList).apply(2, deviceIndexes));
if (deviceIndexes.size() == 0) {
terminalRunningInfoVO.setNormalRate(0.0);
terminalRunningInfoVO.setBreaksRate(0.0);
terminalRunningInfoVO.setShutdownRate(0.0);
terminalRunningInfoVO.setNormalRate(3.14159);
terminalRunningInfoVO.setBreaksRate(3.14159);
terminalRunningInfoVO.setShutdownRate(3.14159);
} else {
double normalRate = terminalRunningInfoVO.getNormal().doubleValue() / terminalRunningInfoVO.getNumberOfTerminals() * 100;
terminalRunningInfoVO.setNormalRate(new BigDecimal(normalRate).setScale(2, RoundingMode.HALF_UP).doubleValue());
@@ -340,7 +306,7 @@ public class AreaLineServiceImpl implements AreaLineService {
.sum();
Long shutdownSum = terminalRun.stream().mapToLong(TerminalRunningInfoVO::getShutdown)
.sum();
Double normalRateSum = 0.0, breaksRateSum = 0.0, shutdownRateSum = 0.0;
Double normalRateSum = 3.14159, breaksRateSum = 3.14159, shutdownRateSum = 3.14159;
if (terminalSum != 0) {
normalRateSum = new BigDecimal(normalSum.doubleValue() / terminalSum * 100).setScale(2, RoundingMode.HALF_UP).doubleValue();
breaksRateSum = new BigDecimal(breaksSum.doubleValue() / terminalSum * 100).setScale(2, RoundingMode.HALF_UP).doubleValue();
@@ -370,7 +336,7 @@ public class AreaLineServiceImpl implements AreaLineService {
BigDecimal b2 = new BigDecimal(offlineSum);
BigDecimal c = new BigDecimal(100);
if (b1.compareTo(BigDecimal.ZERO) == 0) {
return 0.00D;
return 3.14159D;
}
return b1.divide(b1.add(b2), 4, RoundingMode.HALF_UP).multiply(c).doubleValue();
};
@@ -403,7 +369,7 @@ public class AreaLineServiceImpl implements AreaLineService {
}
j++;
}
stringBuilder.append(" group by line_id");
stringBuilder.append(" group by line_id").append(InfluxDBPublicParam.TIME_ZONE);
// 获取暂降事件
String sql = "select count(file_flag) from pqs_eventdetail where " + stringBuilder.toString();
QueryResult result = influxDbUtils.query(sql);
@@ -411,69 +377,4 @@ public class AreaLineServiceImpl implements AreaLineService {
List<EventHeatDeatilVO> eventdetailList = influxDBResultMapper.toPOJO(result, EventHeatDeatilVO.class);
return eventdetailList;
}
public Float getSarfiValue(String startTime, String endTime, Float fvalue, String id) {
Float retList = 0f;
//组装sql语句
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("time >= '").append(DateUtil.beginOfDay(DateUtil.parse(startTime))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(endTime))).append("' and ");
stringBuilder.append("line_id = '").append(id).append("'").append(" and event_value <=").append(fvalue).append(InfluxDBPublicParam.TIME_ZONE);
String sql = "select mean(event_value) from " + InfluxDBPublicParam.PQS_EVENT_DETAIL + " where " + stringBuilder.toString();
QueryResult queryResult = influxDbUtils.query(sql);
List<QueryResult.Result> results = queryResult.getResults();
if (results == null || results.isEmpty()) {
return retList;
}
QueryResult.Result result = results.get(0);
List<QueryResult.Series> seriess = result.getSeries();
if (seriess == null || seriess.isEmpty()) {
return retList;
}
QueryResult.Series series = seriess.get(0);
List<List<Object>> values = series.getValues();
for (List<Object> columnValue : values) {
retList = BigDecimal.valueOf(Float.parseFloat(columnValue.get(1).toString())).setScale(4, BigDecimal.ROUND_HALF_UP).floatValue();
}
return retList;
}
public Integer getSarfiCount(String startTime, String endTime, Float fvalue, String id) {
Integer retList = 0;
//组装sql语句
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("time >= '").append(DateUtil.beginOfDay(DateUtil.parse(startTime))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(endTime))).append("' and ");
stringBuilder.append("line_id = '").append(id).append("'").append(" and event_value <=").append(fvalue).append(" and persist_time<6000").append(InfluxDBPublicParam.TIME_ZONE);
String sql = "select count(*) from " + InfluxDBPublicParam.PQS_EVENT_DETAIL + " where " + stringBuilder.toString();
QueryResult queryResult = influxDbUtils.query(sql);
List<QueryResult.Result> results = queryResult.getResults();
if (results == null || results.isEmpty()) {
return retList;
}
QueryResult.Result result = results.get(0);
List<QueryResult.Series> seriess = result.getSeries();
if (seriess == null || seriess.isEmpty()) {
return retList;
}
QueryResult.Series series = seriess.get(0);
List<List<Object>> values = series.getValues();
for (List<Object> columnValue : values) {
retList = (Integer) columnValue.get(1);
}
return retList;
}
public List<EventDetail> getEventDetailInfo(String id, Float fvalue, String startTime, String endTime) {
//组装sql语句
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("time >= '").append(DateUtil.beginOfDay(DateUtil.parse(startTime))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(endTime))).append("' and ");
//sql语句
stringBuilder.append("line_id ='").append(id).append("'").append(" and event_value <=").append(fvalue).append(" and persist_time < 60000").append(" tz('Asia/Shanghai')");
String sql = "select * from pqs_eventdetail where " + stringBuilder;
//获取暂降事件
QueryResult result = influxDbUtils.query(sql);
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
List<EventDetail> eventDetailList = influxDBResultMapper.toPOJO(result, EventDetail.class);
return eventDetailList;
}
}

View File

@@ -20,6 +20,7 @@ import com.njcn.event.pojo.vo.VoltageLevelCalculationVO;
import com.njcn.event.service.AreaStatisticalService;
import com.njcn.system.pojo.enums.StatisticsEnum;
import lombok.RequiredArgsConstructor;
import org.influxdb.querybuilder.clauses.Clause;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@@ -30,6 +31,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.njcn.event.influxdb.PqsEventDetailQuery.*;
import static org.influxdb.querybuilder.BuiltQuery.QueryBuilder.ne;
/**
* 区域统计
@@ -42,9 +44,9 @@ import static com.njcn.event.influxdb.PqsEventDetailQuery.*;
@RequiredArgsConstructor
public class AreaStatisticalServiceImpl implements AreaStatisticalService {
private final GeneralDeviceInfoClient generalDeviceInfoClient;
private final PqsEventDetailQuery pqsEventDetailQuery;
/**
* 获取暂降区域 电压等级 月份统计
*
@@ -62,26 +64,27 @@ public class AreaStatisticalServiceImpl implements AreaStatisticalService {
if (CollUtil.isEmpty(lineIds)) {
return AreaStatisticalVO.empty();
}
List<Clause> clauseList = new ArrayList<>(timeAnd(beginOfDay(deviceInfoParam.getSearchBeginTime()), endOfDay(deviceInfoParam.getSearchEndTime())));
clauseList.add(ne("wave_type",5));
List<EventDetail> eventDetailList = pqsEventDetailQuery.selectList(Arrays.asList("line_id", "eventass_index"),
lineIdOr(lineIds),
timeAnd(beginOfDay(deviceInfoParam.getSearchBeginTime()), endOfDay(deviceInfoParam.getSearchEndTime())));
lineIdOr(lineIds),clauseList);
if (CollUtil.isEmpty(eventDetailList)) {
return AreaStatisticalVO.empty();
}
AreaStatisticsVO areaStatisticsVO = statisticsAreaInfo(generalDeviceDTOList, eventDetailList);
MonthlyStatisticsVO monthCalculationVOS = statisticsMonthInfo(deviceInfoParam, eventDetailList);
deviceInfoParam.getStatisticalType().setCode(StatisticsEnum.VOLTAGE_LEVEL.getCode());
List<GeneralDeviceDTO> voltageLevelList = generalDeviceInfoClient.getPracticalAllDeviceInfo(deviceInfoParam).getData();
VoltageStatisticsVO voltageStatisticsVO = statisticalVoltageLevelInfo(voltageLevelList, eventDetailList);
return AreaStatisticalVO.buildVO(areaStatisticsVO, voltageStatisticsVO, monthCalculationVOS);
}
/**
* 统计月份信息
*
@@ -91,34 +94,49 @@ public class AreaStatisticalServiceImpl implements AreaStatisticalService {
*/
private MonthlyStatisticsVO statisticsMonthInfo(DeviceInfoParam.BusinessParam deviceInfoParam, List<EventDetail> eventDetailList) {
List<DateTime> timeLimit = calculateTheTimePeriodRange(deviceInfoParam);
List<DateTime> monthStartAndEnd = calculateMonthStartAndEnd(timeLimit);
List<DateTime> monthStartAndEnd = new ArrayList<>();
if(deviceInfoParam.getTimeFlag()==0){
//月
monthStartAndEnd = calculateMonthStartAndEnd(timeLimit,0);
}else {
//天
monthStartAndEnd = calculateMonthStartAndEnd(timeLimit,1);
}
List<MonthCalculationVO> monthCalculationVOList = new ArrayList<>(monthStartAndEnd.size());
MonthCalculationVO monthCalculationVO;
for (int i = 0; i < monthStartAndEnd.size(); i += 2) {
DateTime beginMon = monthStartAndEnd.get(i);
DateTime endMon = monthStartAndEnd.get(i + 1);
List<EventDetail> eventDetails = getBetweenTimeEventDetailList(eventDetailList).apply(beginMon, endMon);
// 时间段内总记录数
Long count = (long) eventDetails.size();
// 时间段内非空记录数,剔除等于空的
Long linkedCount = countEventassIndexIsNoEmpty().apply(eventDetails);
monthCalculationVO = new MonthCalculationVO();
monthCalculationVO.setMonth(beginMon.toDateStr().substring(0, 7));
if(deviceInfoParam.getTimeFlag()==0){
//月
monthCalculationVO.setMonth(beginMon.toDateStr().substring(0, 7));
}else {
//日
monthCalculationVO.setMonth(beginMon.toDateStr());
}
monthCalculationVO.setNotAssociated(count - linkedCount);
monthCalculationVO.setLinked(linkedCount);
monthCalculationVOList.add(monthCalculationVO);
}
Long notAssociatedSum = monthCalculationVOList.stream().mapToLong(MonthCalculationVO::getNotAssociated).sum();
return MonthlyStatisticsVO.buildVO(notAssociatedSum, monthCalculationVOList);
}
/**
* 统计电压等级信息
*
@@ -134,14 +152,14 @@ public class AreaStatisticalServiceImpl implements AreaStatisticalService {
voltageLevelCalculationVO.setFrequency(countLineIndexes(eventDetailList).apply(t.getLineIndexes()));
return voltageLevelCalculationVO;
}).collect(Collectors.toCollection(() -> Collections.synchronizedList(new ArrayList<>())));
// 求和暂降次数
Long frequencySum = voltageLevelCalculation.stream().mapToLong(VoltageLevelCalculationVO::getFrequency).sum();
// 求装置数量
Integer monitoringPointSum = voltageLevelCalculation.stream().mapToInt(VoltageLevelCalculationVO::getMonitoringPoints).sum();
return VoltageStatisticsVO.buildVO(frequencySum, monitoringPointSum, voltageLevelCalculation);
}
/**
* 统计区域信息
*
@@ -154,35 +172,47 @@ public class AreaStatisticalServiceImpl implements AreaStatisticalService {
AreaCalculationVO calculationVO = new AreaCalculationVO();
calculationVO.setAreaName(t.getName());
calculationVO.setMonitoringPoints(t.getLineIndexes().size());
calculationVO.setFrequency(countLineIndexes(eventDetailList).apply(t.getLineIndexes()));
calculationVO.computeSarfi90();
return calculationVO;
}).sorted(AreaCalculationVO.sortAscAreaName()).collect(Collectors.toCollection(() -> Collections.synchronizedList(new ArrayList<>())));
// 求和暂降次数
Long frequencySum = areaCalculation.stream().mapToLong(AreaCalculationVO::getFrequency).sum();
// 求装置数量
Integer monitoringPointSum = areaCalculation.stream().mapToInt(AreaCalculationVO::getMonitoringPoints).sum();
return AreaStatisticsVO.buildVO(frequencySum, monitoringPointSum, areaCalculation);
}
/**
* 计算出月的开始时间和结束时间
*
* @param timeLimit 查询参数
* @param timeFlag 0.月 1.天
* @return 月的开始时间和结束时间
*/
private List<DateTime> calculateMonthStartAndEnd(List<DateTime> timeLimit) {
return timeLimit.stream().flatMap(dateTime -> {
DateTime dateTime1 = DateUtil.beginOfMonth(dateTime);
DateTime dateTime2 = DateUtil.endOfMonth(dateTime);
return Stream.of(dateTime1, dateTime2);
}).collect(Collectors.toList());
private List<DateTime> calculateMonthStartAndEnd(List<DateTime> timeLimit,Integer timeFlag) {
if(timeFlag == 0){
return timeLimit.stream().flatMap(dateTime -> {
DateTime dateTime1 = DateUtil.beginOfMonth(dateTime);
DateTime dateTime2 = DateUtil.endOfMonth(dateTime);
return Stream.of(dateTime1, dateTime2);
}).collect(Collectors.toList());
}else {
return timeLimit.stream().flatMap(dateTime -> {
DateTime dateTime1 = DateUtil.beginOfDay(dateTime);
DateTime dateTime2 = DateUtil.endOfDay(dateTime);
return Stream.of(dateTime1, dateTime2);
}).collect(Collectors.toList());
}
}
/**
* 根据开始时间结束时间, 获取时间年月范围
*
@@ -190,9 +220,18 @@ public class AreaStatisticalServiceImpl implements AreaStatisticalService {
* @return 获取时间年月范围
*/
private List<DateTime> calculateTheTimePeriodRange(DeviceInfoParam.BusinessParam deviceInfoParam) {
DateTime beginTime = DateUtil.parse(deviceInfoParam.getSearchBeginTime(), DatePattern.NORM_DATE_PATTERN);
DateTime endTime = DateUtil.parse(deviceInfoParam.getSearchEndTime(), DatePattern.NORM_DATE_PATTERN);
return DateUtil.rangeToList(beginTime, endTime, DateField.MONTH);
if(deviceInfoParam.getTimeFlag() == 0){
//月
DateTime beginTime = DateUtil.parse(deviceInfoParam.getSearchBeginTime(), DatePattern.NORM_DATE_PATTERN);
DateTime endTime = DateUtil.parse(deviceInfoParam.getSearchEndTime(), DatePattern.NORM_DATE_PATTERN);
return DateUtil.rangeToList(beginTime, endTime, DateField.MONTH);
}else {
DateTime beginTime = DateUtil.parse(deviceInfoParam.getSearchBeginTime(), DatePattern.NORM_DATE_PATTERN);
DateTime endTime = DateUtil.parse(deviceInfoParam.getSearchEndTime(), DatePattern.NORM_DATE_PATTERN);
return DateUtil.rangeToList(beginTime, endTime, DateField.DAY_OF_MONTH);
}
}
}

View File

@@ -1,8 +1,12 @@
package com.njcn.event.service.Impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.db.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.event.service.EventDetailService;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDBCommUtils;
import com.njcn.influxdb.utils.InfluxDbUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -110,7 +114,6 @@ public class EventDetailServiceImpl implements EventDetailService {
InfluxDBResultMapper influxDBResultMapper = new InfluxDBResultMapper();
List<EventDetail> eventDetailList = influxDBResultMapper.toPOJO(result, EventDetail.class);
return eventDetailList;
}

View File

@@ -1,5 +1,8 @@
package com.njcn.event.service.Impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.config.GeneralInfo;
import com.njcn.common.pojo.dto.wave.WaveDataDTO;
@@ -10,17 +13,29 @@ import com.njcn.common.utils.wave.AnalyWave;
import com.njcn.device.api.GeneralDeviceInfoClient;
import com.njcn.device.api.LineFeignClient;
import com.njcn.device.pojo.dto.GeneralDeviceDTO;
import com.njcn.device.pojo.vo.AreaLineInfoVO;
import com.njcn.device.pojo.vo.LineDetailDataVO;
import com.njcn.event.config.EventBaseConfig;
import com.njcn.event.enums.EventResponseEnum;
import com.njcn.event.mapper.TransientMapper;
import com.njcn.event.pojo.param.TransientParam;
import com.njcn.event.pojo.param.WaveFileParam;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.event.pojo.po.EventDetailNew;
import com.njcn.event.pojo.vo.AreaLineVO;
import com.njcn.event.pojo.vo.TransientVO;
import com.njcn.event.service.EventDetailService;
import com.njcn.event.service.TransientService;
import com.njcn.influxdb.mapper.InfluxDBResultMapperCn;
import com.njcn.influxdb.param.InfluxDBPublicParam;
import com.njcn.influxdb.utils.InfluxDBCommUtils;
import com.njcn.influxdb.utils.InfluxDbUtils;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.enums.DicDataTypeEnum;
import com.njcn.system.pojo.po.DictData;
import io.swagger.models.auth.In;
import lombok.AllArgsConstructor;
import org.influxdb.dto.QueryResult;
import org.influxdb.impl.InfluxDBResultMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@@ -52,12 +67,16 @@ public class TransientServiceImpl implements TransientService {
private final LineFeignClient lineFeignClient;
private final DicDataFeignClient dicDataFeignClient;
private final TransientMapper transientMapper;
private final EventDetailService eventDetailService;
private final GeneralInfo generalInfo;
private final InfluxDbUtils influxDbUtils;
@Override
public Page<TransientVO> getTransientData(TransientParam transientParam) {
Page<TransientVO> page = new Page<>();
@@ -117,7 +136,7 @@ public class TransientServiceImpl implements TransientService {
transientVO.setTrigType("暂降");
break;
case 2:
transientVO.setTrigType("");
transientVO.setTrigType("");
break;
case 3:
transientVO.setTrigType("中断");
@@ -231,6 +250,187 @@ public class TransientServiceImpl implements TransientService {
return response;
}
@Override
public Page<EventDetailNew> getTransientValue(TransientParam transientParam){
Page<EventDetailNew> page = new Page<>();
page.setSize(transientParam.getPageSize());
page.setCurrent(transientParam.getPageNum());
//List<TransientVO> transientVos = new ArrayList<>();
//transientParam.setServerName(ServerEnum.HARMONIC.getName());
//按部门分类的实际运行终端综合信息
List<GeneralDeviceDTO> generalDeviceDTOList = generalDeviceInfoClient.getPracticalRunDeviceInfo(transientParam).getData();
if (!CollectionUtils.isEmpty(generalDeviceDTOList)) {
//获取按终端分类的监测点索引集合
List<String> lineList = generalDeviceDTOList.stream().flatMap(dto -> dto.getLineIndexes().stream()).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(lineList)) {
StringBuilder stringBuilder = InfluxDBCommUtils.assToInfluxParam(lineList);
//influxDB查询待分页数据总量
Long total = getTransientDetail(stringBuilder,transientParam);
page.setTotal(total);
//分页总页数
int pages = (int) Math.ceil(transientParam.getPageNum() * 1.0 / transientParam.getPageSize());
page.setPages(pages);
//influxDB分页查询
List<EventDetailNew> eventDetailData = getTransientDetailLimit(lineList, transientParam);
if (CollUtil.isNotEmpty(eventDetailData)) {
List<String> lineIds = eventDetailData.stream().map(EventDetailNew::getLineId).collect(Collectors.toList());
lineIds = lineIds.stream().distinct().collect(Collectors.toList());
List<AreaLineInfoVO> r = lineFeignClient.getBaseLineAreaInfo(lineIds).getData();
List<DictData> reasonList = dicDataFeignClient.getDicDataByTypeName(DicDataTypeEnum.EVENT_REASON.getName()).getData();
List<DictData> typeList = dicDataFeignClient.getDicDataByTypeName(DicDataTypeEnum.EVENT_TYPE.getName()).getData();
//List<TransientVO> transientData = transientMapper.getTransientData(lineIds);
for (EventDetailNew eventDetail : eventDetailData) {
for(AreaLineInfoVO areaLineInfoVO : r){
if(eventDetail.getLineId().equals(areaLineInfoVO.getLineId())){
eventDetail.setLineId(areaLineInfoVO.getLineId());
eventDetail.setLineName(areaLineInfoVO.getLineName());
eventDetail.setGdName(areaLineInfoVO.getGdName());
eventDetail.setSubName(areaLineInfoVO.getSubName());
eventDetail.setIp(areaLineInfoVO.getIp());
eventDetail.setScale(areaLineInfoVO.getVoltageScale());
break;
}
}
for (DictData dictData : reasonList) {
if (eventDetail.getEventReason().equals(dictData.getId())) {
eventDetail.setEventReason(dictData.getName());
break;
}
}
for (DictData dictData : typeList) {
if (eventDetail.getEventType().equals(dictData.getId())) {
eventDetail.setEventType(dictData.getName());
break;
}
}
}
//当前页数据
page.setRecords(eventDetailData);
}
}
}
return page;
}
/**
* 查询数据库
*/
private Long getTransientDetail(StringBuilder stringBuilder,TransientParam transientParam) {
Long total = 0L;
//组装sql语句
stringBuilder.append(" and time >= '").append(DateUtil.beginOfDay(DateUtil.parse(transientParam.getSearchBeginTime()))).append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(transientParam.getSearchEndTime()))).append("'").append(InfluxDBPublicParam.TIME_ZONE);
//sql语句
String sql = "SELECT count(wave_type) FROM pqs_eventdetail WHERE " + stringBuilder;
System.out.println("sql------------->>>"+sql);
//结果集
QueryResult result = influxDbUtils.query(sql);
//结果集映射到对象中
List<QueryResult.Series> series = result.getResults().get(0).getSeries();
if(CollUtil.isNotEmpty(series)){
Double tem =(Double)series.get(0).getValues().get(0).get(1);
total = tem.longValue();
}
return total;
}
/**
* 根据条件拼接sql语句
*/
private List<EventDetailNew> getTransientDetailLimit(List<String> lineIndexes, TransientParam transientParam) {
//查询数据是否为空不为空拼接sql语句
StringBuilder querySql = new StringBuilder();
if(Objects.nonNull(transientParam.getEventValueMin())){
querySql.append(" and event_value >=").append(transientParam.getEventValueMin());
}
if(Objects.nonNull(transientParam.getEventValueMax())){
querySql.append(" and event_value <=").append(transientParam.getEventValueMax());
}
if(Objects.nonNull(transientParam.getPersistMin())){
querySql.append(" and persist_time >=").append(transientParam.getPersistMin());
}
if(Objects.nonNull(transientParam.getEventValueMax())){
querySql.append(" and persist_time <=").append(transientParam.getPersistMax());
}
if(Objects.nonNull(transientParam.getSeverityMin())){
querySql.append(" and severity >=").append(transientParam.getSeverityMin());
}
if(Objects.nonNull(transientParam.getSeverityMax())){
querySql.append(" and severity <=").append(transientParam.getSeverityMax());
}
if(Objects.nonNull(transientParam.getFileFlag())){
querySql.append(" and file_flag = ").append(transientParam.getFileFlag());
}
if(CollUtil.isNotEmpty(transientParam.getWaveType())) {
querySql.append(" and ( ");
for (int i = 0; i < transientParam.getWaveType().size(); i++) {
if (transientParam.getWaveType().size() - i != 1) {
querySql.append("wave_type =").append(transientParam.getWaveType().get(i)).append(" or ");
} else {
querySql.append("wave_type =").append(transientParam.getWaveType().get(i)).append(") ");
}
}
}
if(CollUtil.isNotEmpty(transientParam.getEventReason())) {
querySql.append(" and ( ");
for (int i = 0; i < transientParam.getEventReason().size(); i++) {
if (transientParam.getWaveType().size() - i != 1) {
querySql.append("event_reason =").append(transientParam.getEventReason().get(i)).append(" or ");
} else {
querySql.append("event_reason =").append(transientParam.getEventReason().get(i)).append(") ");
}
}
}
if(CollUtil.isNotEmpty(transientParam.getEventType())) {
querySql.append(" and ( ");
for (int i = 0; i < transientParam.getEventType().size(); i++) {
if (transientParam.getEventType().size() - i != 1) {
querySql.append("event_type =").append(transientParam.getEventType().get(i)).append(" or ");
} else {
querySql.append("event_type =").append(transientParam.getEventType().get(i)).append(") ");
}
}
}
//组装sql语句
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("time >= '").append(DateUtil.beginOfDay(DateUtil.parse(transientParam.getSearchBeginTime())))
.append("' and ").append("time <= '").append(DateUtil.endOfDay(DateUtil.parse(transientParam.getSearchEndTime()))).append("'")
.append(querySql);
stringBuilder.append(" and (");
for (int i = 0; i < lineIndexes.size(); i++) {
if (lineIndexes.size() - i != 1) {
stringBuilder.append("line_id ='").append(lineIndexes.get(i)).append("' or ");
} else {
stringBuilder.append("line_id ='").append(lineIndexes.get(i)).append("') ");
}
}
int i = (transientParam.getPageNum() - 1)*transientParam.getPageSize();
stringBuilder.append("LIMIT ").append(transientParam.getPageSize()).append(" OFFSET ").append(i).append(" tz('Asia/Shanghai')");
//sql语句
String sql = "SELECT * FROM pqs_eventdetail WHERE " + stringBuilder;
System.out.println("sql====================="+sql);
//结果集
QueryResult queryresult = influxDbUtils.query(sql);
//结果集映射到对象中
InfluxDBResultMapperCn influxDBResultMapper = new InfluxDBResultMapperCn();
List<EventDetailNew> eventDetailList = influxDBResultMapper.toPOJO(queryresult, EventDetailNew.class);
return eventDetailList;
}
/**
* 复制保存文件
*/
@@ -459,7 +659,7 @@ public class TransientServiceImpl implements TransientService {
try {
String filePath = filePathAndName;
filePath = filePath.toString();
java.io.File myDelFile = new java.io.File(filePath);
File myDelFile = new File(filePath);
myDelFile.delete();
} catch (Exception e) {
System.out.println("删除文件操作出错");

View File

@@ -0,0 +1,61 @@
package com.njcn.event.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.device.pojo.param.DeviceInfoParam;
import com.njcn.event.pojo.param.*;
import com.njcn.event.pojo.vo.DetailVO;
import com.njcn.event.pojo.vo.GeneralVO;
import com.njcn.event.pojo.vo.ReasonsVO;
import com.njcn.event.pojo.vo.WaveTypeVO;
import freemarker.template.TemplateException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;
/**
* @author xxy
* @version 1.0.0
* @date 2022年07月28日 13:32
*/
public interface ReportService {
List<GeneralVO> getGeneralSituation(DeviceInfoParam.BusinessParam businessParam);
List<GeneralVO> getVoltage(DeviceInfoParam.BusinessParam businessParam);
List<WaveTypeVO> getSeverity(DeviceInfoParam.BusinessParam businessParam);
List<ReasonsVO> getReason(DeviceInfoParam.BusinessParam businessParam);
Page<DetailVO> getContinueTime(WaveTypeParam waveTypeParam);
Page<DetailVO> getSagTimes(WaveTypeParam waveTypeParam);
Page<DetailVO> getUpTimes(WaveTypeParam waveTypeParam);
Page<DetailVO> getBreakTimes(WaveTypeParam waveTypeParam);
void getExport(DeviceInfoParam.BusinessParam businessParam, HttpServletResponse response) throws IOException, TemplateException;
void getLineExport(ExportParam exportParam, HttpServletResponse response) throws InvalidFormatException, IOException, TemplateException, ParseException;
/**
*获取事件报告
* @author zbj
* @date 2022/7/29
*/
Page<WaveTypeVO> getEventReport(WaveTypeParam deviceInfoParam);
/**
*获取区域报告
* @author zbj
* @date 2022/8/4
*/
void getAreaReport(AreaReportParam areaReportParam, HttpServletResponse response) throws Exception;
}

View File

@@ -4,9 +4,12 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.dto.wave.WaveDataDTO;
import com.njcn.event.pojo.param.TransientParam;
import com.njcn.event.pojo.param.WaveFileParam;
import com.njcn.event.pojo.po.EventDetail;
import com.njcn.event.pojo.po.EventDetailNew;
import com.njcn.event.pojo.vo.TransientVO;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
* @author: chenchao
@@ -34,5 +37,10 @@ public interface TransientService {
* @return
*/
HttpServletResponse downloadWaveFile(WaveFileParam waveFileParam, HttpServletResponse response) throws Exception;
/**
* 功能描述: 根据条件查询暂态事件
* @param transientParam
* @return
*/
Page<EventDetailNew> getTransientValue(TransientParam transientParam);
}