@@ -3,7 +3,7 @@ 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.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page ;
import com.github.jeffreyning.mybatisplus.service.MppServiceImpl ;
@@ -13,11 +13,14 @@ import com.njcn.device.biz.pojo.dto.DeptGetChildrenMoreDTO;
import com.njcn.device.biz.pojo.dto.LineDevGetDTO ;
import com.njcn.device.biz.pojo.param.DeptGetLineParam ;
import com.njcn.device.pq.api.DeptLineFeignClient ;
import com.njcn.device.pq.api.LineFeignClient ;
import com.njcn.device.pq.pojo.po.DeptLine ;
import com.njcn.device.pq.pojo.vo.LineDetailVO ;
import com.njcn.device.pq.pojo.vo.ReportLineInfoVo ;
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.harmonic.pojo.vo.RStatLimitTargetVO ;
import com.njcn.supervision.mapper.device.LineWarningMapper ;
import com.njcn.supervision.pojo.param.device.OnlineParam ;
import com.njcn.supervision.pojo.po.device.LineWarning ;
@@ -33,9 +36,11 @@ import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import javax.servlet.http.HttpServletResponse ;
import java.lang.reflect.Method ;
import java.time.LocalDate ;
import java.time.LocalDateTime ;
import java.time.temporal.TemporalAdjusters ;
import java.util.* ;
import java.util.function.Function ;
import java.util.stream.Collectors ;
@@ -57,6 +62,7 @@ public class LineWarningServiceImpl extends MppServiceImpl<LineWarningMapper, Li
private final CommTerminalGeneralClient commTerminalGeneralClient ;
private final IWarningLeafletService warningLeafletService ;
private final DeptLineFeignClient deptLineFeignClient ;
private final LineFeignClient lineFeignClient ;
@Override
@Transactional ( rollbackFor = Exception . class )
@@ -117,6 +123,68 @@ public class LineWarningServiceImpl extends MppServiceImpl<LineWarningMapper, Li
this . updateBatchById ( updateList ) ;
}
@Override
@Transactional ( rollbackFor = Exception . class )
public void addHeBeiNorthLineWarning ( ) {
List < LineWarning > result = 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 < DeptLine > deptLines = deptLineFeignClient . getAllData ( ) . getData ( ) ;
Map < String , List < DeptLine > > deptLineMap = deptLines . stream ( ) . collect ( Collectors . groupingBy ( DeptLine : : getLineId ) ) ;
//获取监测点按时间统计越限天数
LocalDate firstDayOfMonth = LocalDate . now ( ) . minusDays ( 1 ) . with ( TemporalAdjusters . firstDayOfMonth ( ) ) ;
String date = DateUtil . format ( firstDayOfMonth . atStartOfDay ( ) , DatePattern . NORM_DATE_PATTERN ) ;
String endDate = DateUtil . format ( LocalDateTime . now ( ) . minusDays ( 1 ) , DatePattern . NORM_DATE_PATTERN ) ;
RStatLimitQueryParam rStatLimitQueryParam = new RStatLimitQueryParam ( null , date , endDate ) ;
List < RStatLimitTargetVO > limitTarget = limitRateDClient . monitorOverLimitDays ( rStatLimitQueryParam ) . getData ( ) ;
//按各指标统计越限天数
if ( CollUtil . isNotEmpty ( limitTarget ) ) {
limitTarget . forEach ( item - > {
String deptId = Objects . isNull ( deptLineMap . get ( item . getLineId ( ) ) ) ? null : deptLineMap . get ( item . getLineId ( ) ) . get ( 0 ) . getId ( ) ;
//频率偏差
LineWarning l1 = overData ( firstDayOfMonth , item . getLineId ( ) , deptId , targetMap . get ( DicDataEnum . FREQUENCY_DEV . getCode ( ) ) . getId ( ) , item . getFreqDevOvertime ( ) ) ;
//电压偏差
LineWarning l2 = overData ( firstDayOfMonth , item . getLineId ( ) , deptId , targetMap . get ( DicDataEnum . VOLTAGE_DEV . getCode ( ) ) . getId ( ) , item . getVoltageDevOvertime ( ) ) ;
//长时闪变
LineWarning l3 = overData ( firstDayOfMonth , item . getLineId ( ) , deptId , targetMap . get ( DicDataEnum . FLICKER . getCode ( ) ) . getId ( ) , item . getFlickerOvertime ( ) ) ;
//谐波电压
LineWarning l4 = overData ( firstDayOfMonth , item . getLineId ( ) , deptId , targetMap . get ( DicDataEnum . HARMONIC_VOLTAGE . getCode ( ) ) . getId ( ) , item . getUharmOvertime ( ) ) ;
//谐波电流
LineWarning l5 = overData ( firstDayOfMonth , item . getLineId ( ) , deptId , targetMap . get ( DicDataEnum . HARMONIC_CURRENT . getCode ( ) ) . getId ( ) , item . getIharmOvertime ( ) ) ;
//间谐波电压
LineWarning l6 = overData ( firstDayOfMonth , item . getLineId ( ) , deptId , targetMap . get ( DicDataEnum . INTERHARMONIC_VOLTAGE . getCode ( ) ) . getId ( ) , item . getInuharmOvertime ( ) ) ;
//负序电压不平衡度
LineWarning l7 = overData ( firstDayOfMonth , item . getLineId ( ) , deptId , targetMap . get ( DicDataEnum . PHASE_VOLTAGE . getCode ( ) ) . getId ( ) , item . getUbalanceOvertime ( ) ) ;
//负序电流
LineWarning l8 = overData ( firstDayOfMonth , item . getLineId ( ) , deptId , targetMap . get ( DicDataEnum . NEG_CURRENT . getCode ( ) ) . getId ( ) , item . getINegOvertime ( ) ) ;
//电压总谐波畸变率
LineWarning l9 = overData ( firstDayOfMonth , item . getLineId ( ) , deptId , targetMap . get ( DicDataEnum . THD_V . getCode ( ) ) . getId ( ) , item . getUaberranceOvertime ( ) ) ;
//总稳态指标
LineWarning l10 = overData ( firstDayOfMonth , item . getLineId ( ) , deptId , targetMap . get ( DicDataEnum . TOTAL_INDICATOR . getCode ( ) ) . getId ( ) , item . getAllOvertime ( ) ) ;
result . addAll ( Arrays . asList ( l1 , l2 , l3 , l4 , l5 , l6 , l7 , l8 , l9 , l10 ) ) ;
} ) ;
}
//将装置无数据的统计入库 按运维要求,判断装置的最新数据不是当天,则认为装置无数据
List < LineDetailVO . noDataLineInfo > noDataLineInfo = lineFeignClient . getNoDataLine ( ) . getData ( ) ;
if ( CollUtil . isNotEmpty ( noDataLineInfo ) ) {
LambdaQueryWrapper < LineWarning > lambdaQueryWrapper = new LambdaQueryWrapper < > ( ) ;
lambdaQueryWrapper . eq ( LineWarning : : getTargetType , " 0 " ) . eq ( LineWarning : : getAlarmTime , LocalDate . now ( ) . minusDays ( 1 ) ) ;
this . baseMapper . delete ( lambdaQueryWrapper ) ;
noDataLineInfo . forEach ( item - > {
String deptId = Objects . isNull ( deptLineMap . get ( item . getLineId ( ) ) ) ? null : deptLineMap . get ( item . getLineId ( ) ) . get ( 0 ) . getId ( ) ;
LineWarning lineWarning = new LineWarning ( ) ;
lineWarning . setAlarmTime ( firstDayOfMonth ) ;
lineWarning . setDeptId ( deptId ) ;
lineWarning . setLineId ( item . getLineId ( ) ) ;
lineWarning . setTargetType ( " 0 " ) ;
result . add ( lineWarning ) ;
} ) ;
}
this . saveOrUpdateBatchByMultiId ( result ) ;
}
@Override
public Page < OnlineVo > getLineWarningList ( OnlineParam param ) {
DeptGetLineParam deptGetLineParam = new DeptGetLineParam ( ) ;
@@ -129,35 +197,66 @@ public class LineWarningServiceImpl extends MppServiceImpl<LineWarningMapper, Li
. collect ( Collectors . toList ( ) ) ;
QueryWrapper < LineWarning > queryWrapper = new QueryWrapper < > ( ) ;
queryWrapper . between ( " A.alarm_time " , param . getSearchBeginTime ( ) , param . getSearchEndTime ( ) ) ;
queryWrapper . ge ( " A.over_limit_day " , param . getAlertThreshold ( ) ) ;
if ( CollUtil . isNotEmpty ( lineList ) ) {
queryWrapper . in ( " A.line_id " , lineList ) ;
//查询无数据的监测点
if ( Objects . equals ( param . getDataType ( ) , 0 ) ) {
queryWrapper . eq ( " A.target_type " , " 0 " ) ;
}
if ( ! Objects . isNull ( param . getTargetId ( ) ) ) {
queryWrapper . eq ( " A.target_type " , param . getTargetId ( ) ) ;
//查询指标超标的监测点
else {
queryWrapper . ge ( " A.over_limit_day " , param . getAlertThreshold ( ) ) ;
if ( CollUtil . isNotEmpty ( lineList ) ) {
queryWrapper . in ( " A.line_id " , lineList ) ;
}
if ( CollUtil . isNotEmpty ( param . getTargetList ( ) ) ) {
queryWrapper . in ( " A.target_type " , param . getTargetList ( ) ) ;
}
}
queryWrapper . orderBy ( true , true , " D.Name " , " p4.Name " , " p3.Name " ) ;
return this . baseMapper . page ( new Page < > ( PageFactory . getPageNum ( param ) , PageFactory . getPageSize ( param ) ) , queryWrapper ) ;
}
@Override
@Transactional ( rollbackFor = Exception . class )
public void startReport ( OnlineParam . ReportParam param ) {
String dept = this . baseMapper . selectById ( param . getId ( ) ) . getDeptId ( ) ;
//下发预告警单
warningLeafletService . createLeaflet ( ProblemTypeEnum . ONLINE . getName ( ) , dept , 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 . s etInitiateWarningFlag ( 1 ) ;
lineWarning . s etAlertThreshold ( 10 ) ;
lineWarning . setAlarmThreshold ( 15 ) ;
public void startReport ( OnlineParam . ReportParam param , HttpServletResponse response ) {
//获取无数据监测点集合
List < ReportLineInfoVo > list1 = getReportLineInfo ( true , param . getIdList ( ) , null , param . getSearchBeginTime ( ) , param . getSearchEndTime ( ) , param . getDeptId ( ) ) ;
//获取谐波电压超标监测点集合
String vCode = dicDataFeignClient . getDicDataByCode ( DicDataEnum . HARMONIC_VOLTAGE . getCode ( ) ) . getData ( ) . getId ( ) ;
List < ReportLineInfoVo > list2 = getReportLineInfo ( false , param . getIdList ( ) , vCode , param . getSearchBeginTime ( ) , param . getSearchEndTime ( ) , null ) ;
//获取谐波电流超标监测点集合
String iCode = dicDataFeignClient . g etDicDataByCode ( DicDataEnum . HARMONIC_CURRENT . getCode ( ) ) . getData ( ) . getId ( ) ;
List < ReportLineInfoVo > list3 = getReportLineInfo ( false , param . getIdList ( ) , iCode , param . g etSearchBeginTime ( ) , param . getSearchEndTime ( ) , null ) ;
}
public List < ReportLineInfoVo > getReportLineInfo ( boolean type , List < String > idList , String codeId , String startTime , String endTime , String deptId ) {
List < ReportLineInfoVo > list = new ArrayList < > ( ) ;
LambdaQueryWrapper < LineWarning > lambdaQueryWrapper = new LambdaQueryWrapper < > ( ) ;
if ( type ) {
lambdaQueryWrapper . eq ( LineWarning : : getTargetType , " 0 " )
. eq ( LineWarning : : getDeptId , deptId )
. between ( LineWarning : : getAlarmTime , startTime , endTime ) ;
} else {
lineWarning . setInitiateWarningFlag ( 1 ) ;
l ineWarning. setThresholdResource ( 1 ) ;
l ineWarning. setAlertThreshold ( param . getAlertThreshold ( ) ) ;
lineWarning . setAlarmThreshold ( param . getAlarmThreshold ( ) ) ;
lambdaQueryWrapper . eq ( LineWarning : : getTargetType , codeId )
. in ( L ineWarning: : getId , idList )
. between ( L ineWarning: : getAlarmTime , startTime , endTime ) ;
}
this . baseMapper . updateById ( lineWarning ) ;
List < LineWarning > warnings = this . baseMapper . selectList ( lambdaQueryWrapper ) ;
if ( CollUtil . isNotEmpty ( warnings ) ) {
List < String > lineList = warnings . stream ( ) . map ( LineWarning : : getLineId ) . collect ( Collectors . toList ( ) ) ;
list = lineFeignClient . getReportLineInfo ( lineList ) . getData ( ) ;
if ( ! type ) {
Map < String , Integer > lineIdOverLimitDayMap = warnings . stream ( ) . collect ( Collectors . toMap ( LineWarning : : getLineId , LineWarning : : getOverLimitDay ) ) ;
list . forEach ( item1 - > {
String lineId = item1 . getLineId ( ) ;
Integer overLimitDay = lineIdOverLimitDayMap . getOrDefault ( lineId , null ) ;
if ( overLimitDay ! = null ) {
item1 . setOverDays ( overLimitDay ) ;
}
} ) ;
}
}
return list ;
}
/**
@@ -179,6 +278,16 @@ public class LineWarningServiceImpl extends MppServiceImpl<LineWarningMapper, Li
return result ;
}
public LineWarning overData ( LocalDate date , String lineId , String deptId , String codeId , Integer overDays ) {
LineWarning lineWarning = new LineWarning ( ) ;
lineWarning . setAlarmTime ( date ) ;
lineWarning . setDeptId ( deptId ) ;
lineWarning . setLineId ( lineId ) ;
lineWarning . setTargetType ( codeId ) ;
lineWarning . setOverLimitDay ( overDays ) ;
return lineWarning ;
}
public int overDay ( String code , RStatLimitTargetDPO limitTarget ) {
int result = 0 ;
try {