@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime ;
import cn.hutool.core.date.DateUtil ;
import cn.hutool.core.util.NumberUtil ;
import cn.hutool.core.util.ObjectUtil ;
import cn.hutool.core.util.StrUtil ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
@@ -13,25 +14,23 @@ import com.njcn.common.pojo.param.StatisticsBizBaseParam;
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.mapper.LineDetailMapper ;
import com.njcn.device.pq.mapper.RStatIntegrityDMapper ;
import com.njcn.device.pq.mapper.RStatOnlinerateDMapper ;
import com.njcn.device.pq.pojo.dto.GeneralDeviceDTO ;
import com.njcn.device.pq.pojo.param.GridDiagramParam ;
import com.njcn.device.pq.pojo.param.LineBaseQueryParam ;
import com.njcn.device.pq.pojo.param.OnlineRateParam ;
import com.njcn.device.pq.pojo.po.Device ;
import com.njcn.device.pq.pojo.p o.Line ;
import com.njcn.device.pq.pojo.po.RStatIntegrityD ;
import com.njcn.device.pq.pojo.po.RStatOnlinerateD ;
import com.njcn.device.pq.pojo.po.* ;
import com.njcn.device.pq.pojo.v o.GridDiagramProVO ;
import com.njcn.device.pq.pojo.vo.GridDiagramVO ;
import com.njcn.device.pq.service.CommTerminalService ;
import com.njcn.device.pq.service.GridDiagramService ;
import com.njcn.device.pq.service.IDeviceService ;
import com.njcn.device.pq.service.LineService ;
import com.njcn.device.pq.service.* ;
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.user.api.DeptFeignClient ;
import com.njcn.user.pojo.dto.DeptDTO ;
import com.njcn.user.pojo.po.Dept ;
import java.time.ZoneId ;
@@ -40,6 +39,7 @@ import java.util.function.Function;
import java.util.stream.Collectors ;
import java.util.stream.Stream ;
import com.njcn.web.utils.WebUtil ;
import lombok.RequiredArgsConstructor ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.stereotype.Service ;
@@ -63,6 +63,8 @@ public class GridDiagramServiceImpl implements GridDiagramService {
private final IDeviceService deviceService ;
private final GeneralDeviceService generalDeviceService ;
private final LineService lineService ;
private final DeptLineService deptLineService ;
private final LineDetailMapper lineDetailMapper ;
@Override
public GridDiagramVO getGridDiagramMonitor ( GridDiagramParam param ) {
@@ -188,7 +190,7 @@ public class GridDiagramServiceImpl implements GridDiagramService {
//监测点集合
List < String > lineIds = lineBaseList . stream ( ) . filter ( x - > value . equals ( x . getVoltageLevel ( ) ) ) . filter ( x - > 1 = = x . getIsUpToGrid ( ) ) . map ( LineDevGetDTO : : getPointId ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
List < String > onLineNumIds = lineBaseList . stream ( ) . filter ( x - > value . equals ( x . getVoltageLevel ( ) ) & & 1 = = x . getComFlag ( ) )
. filter ( x - > 1 = = x . getIsUpToGrid ( ) )
. filter ( x - > 1 = = x . getIsUpToGrid ( ) )
. map ( LineDevGetDTO : : getPointId ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
//终端id集合
List < String > devIds = lineBaseList . stream ( ) . filter ( x - > value . equals ( x . getVoltageLevel ( ) ) ) . filter ( x - > 1 = = x . getIsUpToGrid ( ) ) . map ( LineDevGetDTO : : getDevId ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
@@ -212,7 +214,7 @@ public class GridDiagramServiceImpl implements GridDiagramService {
if ( CollUtil . isNotEmpty ( integrityDS ) ) {
double realTime = integrityDS . stream ( ) . mapToDouble ( RStatIntegrityD : : getRealTime ) . sum ( ) ;
double dueTime = integrityDS . stream ( ) . mapToDouble ( RStatIntegrityD : : getDueTime ) . sum ( ) ;
lineStatisticsData . setIntegrityRate ( Math . min ( NumberUtil . round ( realTime * 100 / dueTime , 2 ) . floatValue ( ) , 100 ) ) ;
lineStatisticsData . setIntegrityRate ( Math . min ( NumberUtil . round ( realTime * 100 / dueTime , 2 ) . floatValue ( ) , 100 ) ) ;
} else {
lineStatisticsData . setIntegrityRate ( 0 . 0f ) ;
}
@@ -221,7 +223,7 @@ public class GridDiagramServiceImpl implements GridDiagramService {
if ( CollUtil . isNotEmpty ( onlineRateDS ) ) {
double onlineTime = onlineRateDS . stream ( ) . mapToDouble ( RStatOnlinerateD : : getOnlineMin ) . sum ( ) ;
double offlineTime = onlineRateDS . stream ( ) . mapToDouble ( RStatOnlinerateD : : getOfflineMin ) . sum ( ) ;
lineStatisticsData . setOnLineRate ( Math . min ( NumberUtil . round ( onlineTime * 100 . 0 / ( onlineTime + offlineTime ) , 2 ) . floatValue ( ) , 100 ) ) ;
lineStatisticsData . setOnLineRate ( Math . min ( NumberUtil . round ( onlineTime * 100 . 0 / ( onlineTime + offlineTime ) , 2 ) . floatValue ( ) , 100 ) ) ;
} else {
lineStatisticsData . setOnLineRate ( 0 . 0f ) ;
}
@@ -347,7 +349,7 @@ public class GridDiagramServiceImpl implements GridDiagramService {
if ( CollUtil . isNotEmpty ( onlineRateDS ) ) {
double onlineTime = onlineRateDS . stream ( ) . mapToDouble ( RStatOnlinerateD : : getOnlineMin ) . sum ( ) ;
double offlineTime = onlineRateDS . stream ( ) . mapToDouble ( RStatOnlinerateD : : getOfflineMin ) . sum ( ) ;
data . setOnlineEvaluate ( Math . min ( NumberUtil . round ( onlineTime * 100 . 0 / ( onlineTime + offlineTime ) , 2 ) . doubleValue ( ) , 100 ) ) ;
data . setOnlineEvaluate ( Math . min ( NumberUtil . round ( onlineTime * 100 . 0 / ( onlineTime + offlineTime ) , 2 ) . doubleValue ( ) , 100 ) ) ;
} else {
data . setOnlineEvaluate ( 0 . 0 ) ;
}
@@ -358,12 +360,12 @@ public class GridDiagramServiceImpl implements GridDiagramService {
@Override
public List < GridDiagramVO . DevData > getGridDiagramDevDataList ( GridDiagramParam param ) {
List < GridDiagramVO . DevData > info = new ArrayList < > ( ) ;
List < GridDiagramVO . DevData > info = new ArrayList < > ( ) ;
List < GeneralDeviceDTO > generalDeviceDTOList = generalDeviceService . getDeviceInfoAsDept ( param . getDeviceInfoParam ( ) , null , Stream . of ( 1 ) . collect ( Collectors . toList ( ) ) ) ;
List < String > devIds = generalDeviceDTOList . stream ( ) . flatMap ( x - > x . getDeviceIndexes ( ) . stream ( ) ) . collect ( Collectors . toList ( ) ) ;
//终端信息
List < Device > devList = new ArrayList < > ( ) ;
if ( CollUtil . isNotEmpty ( devIds ) ) {
List < Device > devList = new ArrayList < > ( ) ;
if ( CollUtil . isNotEmpty ( devIds ) ) {
devList = deviceService . list ( new LambdaQueryWrapper < Device > ( ) . in ( CollUtil . isNotEmpty ( devIds ) , Device : : getId , devIds ) ) ;
}
GridDiagramVO . DevData data ;
@@ -375,7 +377,7 @@ public class GridDiagramServiceImpl implements GridDiagramService {
for ( int i = 0 ; i < 3 ; i + + ) {
int finalI = i ;
List < String > devices = devList . stream ( )
. filter ( x - > dto . getDeviceIndexes ( ) . contains ( x . getId ( ) ) )
. filter ( x - > dto . getDeviceIndexes ( ) . contains ( x . getId ( ) ) )
. filter ( x - > finalI = = x . getRunFlag ( ) )
. map ( Device : : getId ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
list . add ( String . valueOf ( devices . size ( ) ) ) ;
@@ -386,7 +388,7 @@ public class GridDiagramServiceImpl implements GridDiagramService {
list . add ( String . valueOf ( 3 . 14159 ) ) ;
}
}
data = new GridDiagramVO . DevData ( ) ;
data = new GridDiagramVO . DevData ( ) ;
data . setOrgId ( dto . getIndex ( ) ) ;
data . setOrgName ( dto . getName ( ) ) ;
data . setRunNum ( Long . valueOf ( list . get ( 0 ) ) ) ;
@@ -398,14 +400,69 @@ public class GridDiagramServiceImpl implements GridDiagramService {
return info ;
}
@Override
public GridDiagramProVO getGridDiagramStatistics ( StatisticsBizBaseParam param ) {
GridDiagramProVO vo = new GridDiagramProVO ( ) ;
// 获取包括当前部门的后代所有部门信息
List < String > deptIds = deptFeignClient . getDepSonIdtByDeptId ( param . getId ( ) ) . getData ( ) ;
// 根据部门ids集合查询是否绑定监测点 部门和监测点关联关系中间表: pq_dept_line 可以一对多
List < DeptLine > deptLines = deptLineService . selectDeptBindLines ( deptIds ) ;
List < String > lineIds = deptLines . stream ( ) . map ( DeptLine : : getLineId ) . collect ( Collectors . toList ( ) ) ;
List < LineDetail > lines = lineDetailMapper . getLineDetailByIds ( lineIds ) ;
LineBaseQueryParam baseQueryParam = new LineBaseQueryParam ( ) ;
baseQueryParam . setStartTime ( param . getStartTime ( ) ) ;
baseQueryParam . setEndTime ( param . getEndTime ( ) ) ;
//开始组装总信息
List < GridDiagramProVO . Details > data = new ArrayList < > ( ) ;
data . add ( add ( lines , baseQueryParam , null , 0 ) ) ;
data . add ( add ( lines , baseQueryParam , null , 1 ) ) ;
//开始组装国网信息
List < GridDiagramProVO . Details > gwData = new ArrayList < > ( ) ;
gwData . add ( add ( lines , baseQueryParam , 1 , 0 ) ) ;
vo . setData ( data ) ;
vo . setGwData ( gwData ) ;
return vo ;
}
private GridDiagramProVO . Details add ( List < LineDetail > lines ,
LineBaseQueryParam baseQueryParam ,
Integer gwType ,
Integer powerFlag ) {
GridDiagramProVO . Details details = new GridDiagramProVO . Details ( ) ;
Stream < LineDetail > stream = lines . stream ( ) ;
Stream < LineDetail > stream2 = lines . stream ( ) ;
if ( gwType ! = null ) {
stream = stream . filter ( x - > x . getMonitorFlag ( ) = = gwType ) ;
stream2 = stream2 . filter ( x - > x . getMonitorFlag ( ) = = gwType ) ;
}
if ( powerFlag ! = null ) {
stream = stream . filter ( x - > x . getPowerFlag ( ) = = powerFlag ) ;
stream2 = stream2 . filter ( x - > x . getPowerFlag ( ) = = powerFlag ) ;
}
//总监测点
List < String > ids = stream . map ( LineDetail : : getId ) . collect ( Collectors . toList ( ) ) ;
//在线监测点
List < String > onIds = stream2 . filter ( x - > x . getComFlag ( ) = = 1 )
. map ( LineDetail : : getId )
. collect ( Collectors . toList ( ) ) ;
details . setNum ( ids . size ( ) ) ;
details . setNumList ( ids ) ;
details . setOnLineNum ( onIds . size ( ) ) ;
details . setOnLineNumList ( onIds ) ;
baseQueryParam . setLineIds ( ids ) ;
details . setIntegrityRate ( integrityDMapper . selectTotalIntegrityByLineIds ( baseQueryParam ) ) ;
return details ;
}
@Override
public List < String > getGridDiagramCityDev ( GridDiagramParam param ) {
List < GeneralDeviceDTO > generalDeviceDTOList = generalDeviceService . getDeviceInfoAsDept ( param . getDeviceInfoParam ( ) , null , Stream . of ( 1 ) . collect ( Collectors . toList ( ) ) ) ;
List < String > devIds = generalDeviceDTOList . stream ( ) . flatMap ( x - > x . getDeviceIndexes ( ) . stream ( ) ) . collect ( Collectors . toList ( ) ) ;
//终端信息
List < Device > devList = new ArrayList < > ( ) ;
if ( CollUtil . isNotEmpty ( devIds ) ) {
devList = deviceService . list ( new LambdaQueryWrapper < Device > ( ) . in ( CollUtil . isNotEmpty ( devIds ) , Device : : getId , devIds ) ) ;
List < Device > devList = new ArrayList < > ( ) ;
if ( CollUtil . isNotEmpty ( devIds ) ) {
devList = deviceService . list ( new LambdaQueryWrapper < Device > ( ) . in ( CollUtil . isNotEmpty ( devIds ) , Device : : getId , devIds ) ) ;
}
OnlineRateParam onlineRateParam = new OnlineRateParam ( ) ;
onlineRateParam . setStartTime ( param . getSearchBeginTime ( ) ) ;
@@ -477,13 +534,13 @@ public class GridDiagramServiceImpl implements GridDiagramService {
statisticsData . add ( data ) ;
data = new GridDiagramVO . StatisticsData ( ) ;
data . setNumOne ( lineBaseList . stream ( )
. filter ( x - > 1 = = x . getIsUpToGrid ( ) ) . map ( LineDevGetDTO : : getDevId ) . distinct ( ) . count ( ) ) ;
. filter ( x - > 1 = = x . getIsUpToGrid ( ) ) . map ( LineDevGetDTO : : getDevId ) . distinct ( ) . count ( ) ) ;
data . setNumOneList ( lineBaseList . stream ( )
. filter ( x - > 1 = = x . getIsUpToGrid ( ) ) . map ( LineDevGetDTO : : getPointId ) . distinct ( ) . collect ( Collectors . toList ( ) ) ) ;
. filter ( x - > 1 = = x . getIsUpToGrid ( ) ) . map ( LineDevGetDTO : : getPointId ) . distinct ( ) . collect ( Collectors . toList ( ) ) ) ;
data . setNumTwo ( lineBaseList . stream ( )
. filter ( x - > 1 = = x . getComFlag ( ) & & 1 = = x . getIsUpToGrid ( ) ) . map ( LineDevGetDTO : : getDevId ) . distinct ( ) . count ( ) ) ;
. filter ( x - > 1 = = x . getComFlag ( ) & & 1 = = x . getIsUpToGrid ( ) ) . map ( LineDevGetDTO : : getDevId ) . distinct ( ) . count ( ) ) ;
data . setNumTwoList ( lineBaseList . stream ( )
. filter ( x - > 1 = = x . getComFlag ( ) & & 1 = = x . getIsUpToGrid ( ) ) . map ( LineDevGetDTO : : getPointId ) . distinct ( ) . collect ( Collectors . toList ( ) ) ) ;
. filter ( x - > 1 = = x . getComFlag ( ) & & 1 = = x . getIsUpToGrid ( ) ) . map ( LineDevGetDTO : : getPointId ) . distinct ( ) . collect ( Collectors . toList ( ) ) ) ;
gwStatisticsData . add ( data ) ;
}