在线监测
1.数据生成 2.分页查询 3.预告警单下发
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package com.njcn.supervision.service.device;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.njcn.supervision.pojo.param.device.OnlineParam;
|
||||
import com.njcn.supervision.pojo.po.device.LineWarning;
|
||||
import com.njcn.supervision.pojo.vo.device.OnlineVo;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 监测点每日稳态指标超标天数统计表 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2024-06-17
|
||||
*/
|
||||
public interface ILineWarningService extends IService<LineWarning> {
|
||||
|
||||
/**
|
||||
* 每天定时计算各监测点各个指标超标情况
|
||||
*/
|
||||
void addLineWarning();
|
||||
|
||||
/**
|
||||
* 获取在线监测的数据列表
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
Page<OnlineVo> getLineWarningList(OnlineParam param);
|
||||
|
||||
/**
|
||||
* 发起预告警单
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
void startReport(OnlineParam.ReportParam param);
|
||||
|
||||
}
|
||||
@@ -101,7 +101,7 @@ public class CheckDeviceServiceImpl extends MppServiceImpl<CheckDeviceMapper, Ch
|
||||
//查询参数不为空,进行条件填充
|
||||
if (StrUtil.isNotBlank(param.getSearchValue())) {
|
||||
queryWrapper
|
||||
.and(par -> par.like("B.Name", param.getSearchValue()));
|
||||
.and(par -> par.like("B.Name", param.getSearchValue()).or().like("B1.Name", param.getSearchValue()));
|
||||
}
|
||||
//排序
|
||||
if (ObjectUtil.isAllNotEmpty(param.getSortBy(), param.getOrderBy())) {
|
||||
|
||||
@@ -0,0 +1,328 @@
|
||||
package com.njcn.supervision.service.device.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.nacos.common.utils.UuidUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl;
|
||||
import com.njcn.device.biz.commApi.CommTerminalGeneralClient;
|
||||
import com.njcn.device.biz.pojo.param.DeptGetLineParam;
|
||||
import com.njcn.harmonic.api.RStatLimitRateDClient;
|
||||
import com.njcn.harmonic.pojo.param.RStatLimitQueryParam;
|
||||
import com.njcn.harmonic.pojo.po.day.RStatLimitTargetDPO;
|
||||
import com.njcn.supervision.enums.ProblemTypeEnum;
|
||||
import com.njcn.supervision.mapper.device.LineWarningMapper;
|
||||
import com.njcn.supervision.pojo.param.device.OnlineParam;
|
||||
import com.njcn.supervision.pojo.po.device.LineWarning;
|
||||
import com.njcn.supervision.pojo.vo.device.OnlineVo;
|
||||
import com.njcn.supervision.service.device.ILineWarningService;
|
||||
import com.njcn.supervision.service.leaflet.IWarningLeafletService;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.enums.DicDataTypeEnum;
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import com.njcn.web.factory.PageFactory;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 监测点每日稳态指标超标天数统计表 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author xy
|
||||
* @since 2024-06-17
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class LineWarningServiceImpl extends MppServiceImpl<LineWarningMapper, LineWarning> implements ILineWarningService {
|
||||
|
||||
private final DicDataFeignClient dicDataFeignClient;
|
||||
private final RStatLimitRateDClient limitRateDClient;
|
||||
private final CommTerminalGeneralClient commTerminalGeneralClient;
|
||||
private final IWarningLeafletService warningLeafletService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void addLineWarning() {
|
||||
List<LineWarning> addList = new ArrayList<>();
|
||||
List<LineWarning> updateList = new ArrayList<>();
|
||||
//获取指标集合(10个指标,包含总指标)
|
||||
List<DictData> dataList = dicDataFeignClient.getDicDataByTypeCode(DicDataTypeEnum.STEADY_STATIS.getCode()).getData();
|
||||
Map<String, DictData> targetMap = dataList.stream().collect(Collectors.toMap(DictData::getCode, Function.identity()));
|
||||
//获取当前表的数据
|
||||
List<LineWarning> lineWarningList = this.baseMapper.selectList(null);
|
||||
Map<String, List<LineWarning>> lineWarningMap = lineWarningList.stream().collect(Collectors.groupingBy(LineWarning::getLineId));
|
||||
//获取所有监测点id
|
||||
List<String> lineList = commTerminalGeneralClient.getRunMonitorIds().getData();
|
||||
RStatLimitQueryParam param = new RStatLimitQueryParam();
|
||||
String date = DateUtil.format(LocalDateTime.now().minusDays(1), DatePattern.NORM_DATE_PATTERN);
|
||||
param.setDate(date);
|
||||
param.setIds(lineList);
|
||||
//获取监测点越限信息
|
||||
List<RStatLimitTargetDPO> limitTarget = limitRateDClient.monitorIdsGetLimitTargetInfo(param).getData();
|
||||
Map<String, RStatLimitTargetDPO> limitMap = limitTarget.stream().collect(Collectors.toMap(RStatLimitTargetDPO::getLineId, Function.identity()));
|
||||
|
||||
for (RStatLimitTargetDPO item : limitTarget) {
|
||||
List<LineWarning> lineWarnings = lineWarningMap.get(item.getLineId());
|
||||
if (CollUtil.isEmpty(lineWarnings)) {
|
||||
addList.addAll(getTargetInfo(item.getLineId(),targetMap,limitMap));
|
||||
} else {
|
||||
//1.查询各指标越限时间不超过10天,超标则每天递增,不超标则清零
|
||||
//2.越限时间超过10天未超过15天,超标则每天递增,不超标保存当前记录,新增一条记录
|
||||
//3.越限时间超过15天,超标则每天递增,不超标保存当前记录,新增一条记录
|
||||
//4.发过告警单,则重新生成一条数据
|
||||
RStatLimitTargetDPO dpo = limitMap.get(item.getLineId());
|
||||
//频率偏差
|
||||
targetInfo(lineWarnings,targetMap,DicDataEnum.FREQUENCY_DEV.getCode(),dpo,item.getLineId(),addList,updateList);
|
||||
//电压偏差
|
||||
targetInfo(lineWarnings,targetMap,DicDataEnum.VOLTAGE_DEV.getCode(),dpo,item.getLineId(),addList,updateList);
|
||||
//长时闪变
|
||||
targetInfo(lineWarnings,targetMap,DicDataEnum.FLICKER.getCode(),dpo,item.getLineId(),addList,updateList);
|
||||
//谐波电压
|
||||
targetInfo(lineWarnings,targetMap,DicDataEnum.HARMONIC_VOLTAGE.getCode(),dpo,item.getLineId(),addList,updateList);
|
||||
//谐波电流
|
||||
targetInfo(lineWarnings,targetMap,DicDataEnum.HARMONIC_CURRENT.getCode(),dpo,item.getLineId(),addList,updateList);
|
||||
//间谐波电压
|
||||
targetInfo(lineWarnings,targetMap,DicDataEnum.INTERHARMONIC_VOLTAGE.getCode(),dpo,item.getLineId(),addList,updateList);
|
||||
//负序电压不平衡度
|
||||
targetInfo(lineWarnings,targetMap,DicDataEnum.phase_Voltage.getCode(),dpo,item.getLineId(),addList,updateList);
|
||||
//负序电流
|
||||
targetInfo(lineWarnings,targetMap,DicDataEnum.NEG_CURRENT.getCode(),dpo,item.getLineId(),addList,updateList);
|
||||
//电压总谐波畸变率
|
||||
targetInfo(lineWarnings,targetMap,DicDataEnum.THD_V.getCode(),dpo,item.getLineId(),addList,updateList);
|
||||
//总稳态指标
|
||||
targetInfo(lineWarnings,targetMap,DicDataEnum.TOTAL_INDICATOR.getCode(),dpo,item.getLineId(),addList,updateList);
|
||||
}
|
||||
}
|
||||
this.saveBatch(addList);
|
||||
this.updateBatchById(updateList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<OnlineVo> getLineWarningList(OnlineParam param) {
|
||||
DeptGetLineParam deptGetLineParam = new DeptGetLineParam();
|
||||
deptGetLineParam.setDeptId(param.getDeptId());
|
||||
List<String> lineList = commTerminalGeneralClient.deptGetLineList(deptGetLineParam)
|
||||
.getData()
|
||||
.stream()
|
||||
.flatMap(item -> item.getLineIds().stream())
|
||||
.distinct()
|
||||
.collect(Collectors.toList());;
|
||||
QueryWrapper<LineWarning> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.between("A.alarm_time", param.getSearchBeginTime(),param.getSearchEndTime());
|
||||
queryWrapper.le("A.alert_threshold", param.getAlertThreshold());
|
||||
if (CollUtil.isNotEmpty(lineList)) {
|
||||
queryWrapper.in("A.line_id",lineList);
|
||||
}
|
||||
if (!Objects.isNull(param.getTargetId())) {
|
||||
queryWrapper.eq("A.target_type", param.getTargetId());
|
||||
}
|
||||
return this.baseMapper.page(new Page<>(PageFactory.getPageNum(param), PageFactory.getPageSize(param)), queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void startReport(OnlineParam.ReportParam param) {
|
||||
//下发预告警单
|
||||
warningLeafletService.createLeaflet(ProblemTypeEnum.ONLINE.getName(), IdUtil.fastSimpleUUID(), param.getId(), ProblemTypeEnum.ONLINE.getCode(),param.getType(),param.getIssueDetail());
|
||||
//更新supervision_line_warning表字段信
|
||||
LineWarning lineWarning = this.baseMapper.selectById(param.getId());
|
||||
if (lineWarning.getThresholdResource() == 0) {
|
||||
lineWarning.setInitiateWarningFlag(1);
|
||||
lineWarning.setAlertThreshold(10);
|
||||
lineWarning.setAlarmThreshold(15);
|
||||
} else {
|
||||
lineWarning.setInitiateWarningFlag(1);
|
||||
lineWarning.setThresholdResource(1);
|
||||
lineWarning.setAlertThreshold(param.getAlertThreshold());
|
||||
lineWarning.setAlarmThreshold(param.getAlarmThreshold());
|
||||
}
|
||||
this.baseMapper.updateById(lineWarning);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取监测点各指标的超标天数
|
||||
*/
|
||||
public List<LineWarning> getTargetInfo(String lineId, Map<String, DictData> map, Map<String, RStatLimitTargetDPO> limitMap) {
|
||||
List<LineWarning> result = new ArrayList<>();
|
||||
map.forEach((k,v)->{
|
||||
LineWarning lineWarning = new LineWarning();
|
||||
lineWarning.setAlarmTime(LocalDate.now().minusDays(1));
|
||||
lineWarning.setLineId(lineId);
|
||||
lineWarning.setTargetType(v.getId());
|
||||
lineWarning.setOverLimitDay(overDay(k,limitMap.get(lineId)));
|
||||
lineWarning.setInitiateWarningFlag(0);
|
||||
lineWarning.setStep(0);
|
||||
result.add(lineWarning);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
public int overDay(String code, RStatLimitTargetDPO limitTarget) {
|
||||
int result = 0;
|
||||
try {
|
||||
//频率偏差
|
||||
if (Objects.equals(code,DicDataEnum.FREQUENCY_DEV.getCode())) {
|
||||
result = limitTarget.getFreqDevOvertime();
|
||||
}
|
||||
//电压偏差
|
||||
else if (Objects.equals(code,DicDataEnum.VOLTAGE_DEV.getCode())) {
|
||||
result = limitTarget.getVoltageDevOvertime();
|
||||
}
|
||||
//长时闪变
|
||||
else if (Objects.equals(code,DicDataEnum.FLICKER.getCode())) {
|
||||
result = limitTarget.getFlickerOvertime();
|
||||
}
|
||||
//谐波电压
|
||||
else if (Objects.equals(code,DicDataEnum.HARMONIC_VOLTAGE.getCode())) {
|
||||
int sum = 0;
|
||||
Class<?> clazz = limitTarget.getClass();
|
||||
for (int i = 2; i <= 25; i++) {
|
||||
String methodName = "getUharm" + i + "Overtime";
|
||||
Method method = clazz.getMethod(methodName);
|
||||
int value = (int) method.invoke(limitTarget);
|
||||
sum += value;
|
||||
}
|
||||
result = limitTarget.getUaberranceOvertime() + sum;
|
||||
}
|
||||
//谐波电流
|
||||
else if (Objects.equals(code,DicDataEnum.HARMONIC_CURRENT.getCode())) {
|
||||
int sum = 0;
|
||||
Class<?> clazz = limitTarget.getClass();
|
||||
for (int i = 2; i <= 25; i++) {
|
||||
String methodName = "getIharm" + i + "Overtime";
|
||||
Method method = clazz.getMethod(methodName);
|
||||
int value = (int) method.invoke(limitTarget);
|
||||
sum += value;
|
||||
}
|
||||
result = sum;
|
||||
}
|
||||
//间谐波电压
|
||||
else if (Objects.equals(code,DicDataEnum.INTERHARMONIC_VOLTAGE.getCode())) {
|
||||
int sum = 0;
|
||||
Class<?> clazz = limitTarget.getClass();
|
||||
for (int i = 1; i <= 16; i++) {
|
||||
String methodName = "getInuharm" + i + "Overtime";
|
||||
Method method = clazz.getMethod(methodName);
|
||||
int value = (int) method.invoke(limitTarget);
|
||||
sum += value;
|
||||
}
|
||||
result = sum;
|
||||
}
|
||||
//负序电压不平衡度
|
||||
else if (Objects.equals(code,DicDataEnum.PHASE_VOLTAGE.getCode())) {
|
||||
result = limitTarget.getUbalanceOvertime();
|
||||
}
|
||||
//负序电流
|
||||
else if (Objects.equals(code,DicDataEnum.NEG_CURRENT.getCode())) {
|
||||
result = limitTarget.getINegOvertime();
|
||||
}
|
||||
//电压总谐波畸变率
|
||||
else if (Objects.equals(code,DicDataEnum.THD_V.getCode())) {
|
||||
result = limitTarget.getUaberranceOvertime();
|
||||
}
|
||||
//总稳态指标
|
||||
else if (Objects.equals(code,DicDataEnum.TOTAL_INDICATOR.getCode())) {
|
||||
int sum1 = 0,sum2 = 0,sum3 = 0;
|
||||
Class<?> clazz = limitTarget.getClass();
|
||||
for (int i = 2; i <= 25; i++) {
|
||||
String methodName1 = "getUharm" + i + "Overtime";
|
||||
Method method1 = clazz.getMethod(methodName1);
|
||||
int value1 = (int) method1.invoke(limitTarget);
|
||||
sum1 += value1;
|
||||
|
||||
String methodName2 = "getIharm" + i + "Overtime";
|
||||
Method method2 = clazz.getMethod(methodName2);
|
||||
int value2 = (int) method2.invoke(limitTarget);
|
||||
sum2 += value2;
|
||||
}
|
||||
for (int i = 1; i <= 16; i++) {
|
||||
String methodName = "getInuharm" + i + "Overtime";
|
||||
Method method = clazz.getMethod(methodName);
|
||||
int value = (int) method.invoke(limitTarget);
|
||||
sum3 += value;
|
||||
}
|
||||
result = limitTarget.getFreqDevOvertime()
|
||||
+ limitTarget.getVoltageDevOvertime()
|
||||
+ limitTarget.getFlickerOvertime()
|
||||
+ sum1
|
||||
+ sum2
|
||||
+ sum3
|
||||
+ limitTarget.getUbalanceOvertime()
|
||||
+ limitTarget.getINegOvertime()
|
||||
+ limitTarget.getUaberranceOvertime();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return result > 0 ? 1:0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 各指标计算 系统默认阈值:预警单10天 告警单15天
|
||||
*/
|
||||
public void targetInfo(List<LineWarning> lineWarnings, Map<String, DictData> targetMap, String target, RStatLimitTargetDPO dpo, String item, List<LineWarning> addList, List<LineWarning> updateList) {
|
||||
List<LineWarning> l1 = lineWarnings.stream().filter(o->Objects.equals(o.getTargetType(),targetMap.get(target).getId())).collect(Collectors.toList());
|
||||
//获取最新的一条记录
|
||||
LineWarning line = l1.stream().max(Comparator.comparing(LineWarning::getAlarmTime)).orElse(null);
|
||||
//当前监测点连续越限天数
|
||||
int day = line.getOverLimitDay();
|
||||
//当天是否越限 0:未越限 1:越限
|
||||
int result = overDay(target,dpo);
|
||||
if (result == 0) {
|
||||
if (day < 10) {
|
||||
line.setOverLimitDay(0);
|
||||
updateList.add(line);
|
||||
} else {
|
||||
LineWarning lineWarning = new LineWarning();
|
||||
lineWarning.setAlarmTime(LocalDate.now().minusDays(1));
|
||||
lineWarning.setLineId(item);
|
||||
lineWarning.setTargetType(targetMap.get(target).getId());
|
||||
lineWarning.setOverLimitDay(0);
|
||||
lineWarning.setInitiateWarningFlag(0);
|
||||
lineWarning.setStep(0);
|
||||
addList.add(lineWarning);
|
||||
}
|
||||
} else {
|
||||
if (day < 9) {
|
||||
line.setOverLimitDay(day + 1);
|
||||
} else if (day < 14) {
|
||||
line.setOverLimitDay(day + 1);
|
||||
line.setStep(1);
|
||||
line.setAlertThreshold(10);
|
||||
line.setAlarmThreshold(15);
|
||||
line.setThresholdResource(0);
|
||||
} else {
|
||||
//已发告警单,重新生成记录
|
||||
if (line.getInitiateWarningFlag() == 1 && line.getStep() == 2) {
|
||||
LineWarning lineWarning = new LineWarning();
|
||||
lineWarning.setAlarmTime(LocalDate.now().minusDays(1));
|
||||
lineWarning.setLineId(item);
|
||||
lineWarning.setTargetType(targetMap.get(target).getId());
|
||||
lineWarning.setOverLimitDay(result);
|
||||
lineWarning.setInitiateWarningFlag(0);
|
||||
lineWarning.setStep(0);
|
||||
addList.add(lineWarning);
|
||||
}
|
||||
//未发告警单,继续添加越限天数
|
||||
else {
|
||||
line.setOverLimitDay(day + 1);
|
||||
line.setStep(2);
|
||||
}
|
||||
}
|
||||
updateList.add(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user