@@ -5,7 +5,6 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil ;
import cn.hutool.core.collection.CollectionUtil ;
import cn.hutool.core.date.DatePattern ;
import cn.hutool.core.date.DatePattern ;
import cn.hutool.core.date.DateUtil ;
import cn.hutool.core.date.DateUtil ;
import cn.hutool.core.date.StopWatch ;
import cn.hutool.core.util.StrUtil ;
import cn.hutool.core.util.StrUtil ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
@@ -38,7 +37,6 @@ import com.njcn.device.userledger.service.UserLedgerService;
import com.njcn.supervision.pojo.param.user.UserReportParam ;
import com.njcn.supervision.pojo.param.user.UserReportParam ;
import com.njcn.supervision.pojo.vo.user.UserLedgerVO ;
import com.njcn.supervision.pojo.vo.user.UserLedgerVO ;
import lombok.RequiredArgsConstructor ;
import lombok.RequiredArgsConstructor ;
import lombok.extern.slf4j.Slf4j ;
import org.apache.commons.lang.StringUtils ;
import org.apache.commons.lang.StringUtils ;
import org.springframework.stereotype.Service ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.transaction.annotation.Transactional ;
@@ -62,7 +60,6 @@ import java.util.stream.Collectors;
*/
*/
@Service
@Service
@RequiredArgsConstructor
@RequiredArgsConstructor
@Slf4j
public class RStatIntegrityDServiceImpl extends MppServiceImpl < RStatIntegrityDMapper , RStatIntegrityD > implements IRStatIntegrityDService {
public class RStatIntegrityDServiceImpl extends MppServiceImpl < RStatIntegrityDMapper , RStatIntegrityD > implements IRStatIntegrityDService {
private final RStatOnlinerateDMapper onlineRateMapper ;
private final RStatOnlinerateDMapper onlineRateMapper ;
@@ -71,8 +68,6 @@ public class RStatIntegrityDServiceImpl extends MppServiceImpl<RStatIntegrityDMa
private final LineDetailMapper lineDetailMapper ;
private final LineDetailMapper lineDetailMapper ;
private final GeneralDeviceService deviceService ;
private final GeneralDeviceService deviceService ;
private final LineService lineService ;
private final LineService lineService ;
private final UserLedgerService userLedgerService ;
private final CommLineClient commLineClient ;
@Override
@Override
public Float getTotalIntegrityByLineIds ( LineBaseQueryParam param ) {
public Float getTotalIntegrityByLineIds ( LineBaseQueryParam param ) {
@@ -153,98 +148,25 @@ public class RStatIntegrityDServiceImpl extends MppServiceImpl<RStatIntegrityDMa
@Override
@Override
public DeviceOnlineRate getData ( DeviceInfoParam . BusinessParam param ) {
public DeviceOnlineRate getData ( DeviceInfoParam . BusinessParam param ) {
DeviceOnlineRate rate = new DeviceOnlineRate ( ) ;
DeviceOnlineRate rate = new DeviceOnlineRate ( ) ;
//BusinessParam的searchvalue只匹配监测点名称现在要匹配电站, 监测点, 监测点对象名称, 所以穿空再添加过滤逻辑
String tempSearchValue = param . getSearchValue ( ) ;
param . setSearchValue ( " " ) ;
StopWatch sw = new StopWatch ( ) ;
sw . start ( " 获取设备台账 " ) ;
//获取终端台账类信息
//获取终端台账类信息
List < GeneralDeviceDTO > deviceInfo = deviceService . getDeviceInfo ( param , null , Collections . singletonList ( 1 ) ) ;
List < GeneralDeviceDTO > deviceInfo = deviceService . getDeviceInfo ( param , null , Collections . singletonList ( 1 ) ) ;
sw . stop ( ) ;
if ( CollUtil . isNotEmpty ( deviceInfo ) ) {
if ( CollUtil . isNotEmpty ( deviceInfo ) ) {
List < String > lineIds = deviceInfo . stream ( )
List < String > lineIds = deviceInfo . stream ( )
. flatMap ( x - > x . getLineIndexes ( ) . stream ( ) ) . collect ( Collectors . toList ( ) )
. flatMap ( x - > x . getLineIndexes ( ) . stream ( ) ) . collect ( Collectors . toList ( ) )
. stream ( )
. stream ( )
. distinct ( )
. distinct ( )
. collect ( Collectors . toList ( ) ) ;
. collect ( Collectors . toList ( ) ) ;
List < String > filterLineList = new ArrayList < > ( ) ;
//获取所有监测点的数据完整性
List < RStatIntegrityVO > lineIntegrityRateInfo = rStatIntegrityDMapper . getLineIntegrityRateInfo ( lineIds , param . getSearchBeginTime ( ) , param . getSearchEndTime ( ) ) ;
if ( CollectionUtil . isNotEmpty ( lineIds ) ) {
//根据searchvalue过滤
sw . start ( " 获取线路详情远程调用 " ) ;
List < LineALLInfoDTO > data = commLineClient . getLineAllDetailList ( lineIds ) . getData ( ) ;
sw . stop ( ) ;
sw . start ( " 内存过滤线路 " ) ;
filterLineList = data . stream ( )
. filter ( dto - > {
LineALLInfoDTO . LineLineDTO lineDTO = dto . getLineLineDTO ( ) ;
String linename = lineDTO ! = null ? lineDTO . getLinename ( ) : null ;
String objName2 = lineDTO ! = null ? lineDTO . getObjName2 ( ) : null ;
LineALLInfoDTO . LineSubStationDTO subStationDTO = dto . getLineSubStationDTO ( ) ;
String subStationName = subStationDTO ! = null ? subStationDTO . getSubStationName ( ) : null ;
// 大小写敏感的模糊匹配(相当于 MySQL 的 LIKE '%keyword%')
return ( linename ! = null & & linename . contains ( tempSearchValue ) )
| | ( objName2 ! = null & & objName2 . contains ( tempSearchValue ) )
| | ( subStationName ! = null & & subStationName . contains ( tempSearchValue ) ) ;
} ) . map ( dto - > dto . getLineLineDTO ( ) ! = null ? dto . getLineLineDTO ( ) . getLineId ( ) : null )
. collect ( Collectors . toList ( ) ) ;
}
sw . stop ( ) ;
rate . setTotalNum ( filterLineList . size ( ) ) ;
List < String > finalFilterLineList = filterLineList ;
//根据过滤后监测点过滤
sw . start ( " 过滤后重新组装 " ) ;
deviceInfo = deviceInfo . stream ( )
. filter ( dto - > {
List < String > original = dto . getLineIndexes ( ) ;
if ( original = = null | | original . isEmpty ( ) ) {
return false ;
}
// 计算交集
List < String > intersection = original . stream ( )
. filter ( finalFilterLineList : : contains )
. collect ( Collectors . toList ( ) ) ;
if ( intersection . isEmpty ( ) ) {
return false ;
}
// 更新当前 DTO 的 lineIndexes 为交集
dto . setLineIndexes ( intersection ) ;
return true ;
} )
. collect ( Collectors . toList ( ) ) ; //获取所有监测点的数据完整性
sw . stop ( ) ;
sw . start ( " 查询完整性率 " ) ;
List < RStatIntegrityVO > lineIntegrityRateInfo = rStatIntegrityDMapper . getLineIntegrityRateInfo ( filterLineList , param . getSearchBeginTime ( ) , param . getSearchEndTime ( ) ) ;
sw . stop ( ) ;
sw . start ( " 查询线路详情 " ) ;
//获取所有监测点信息信息
//获取所有监测点信息信息
List < LineDetailVO . Detail > LineInfoByIds = lineService . getLineDetailByIds ( filterLineList ) ;
List < LineDetailVO . Detail > LineInfoByIds = lineService . getLineDetailByIds ( lineIds ) ;
sw . stop ( ) ;
rate . setBelowNum ( CollUtil . isNotEmpty ( lineIntegrityRateInfo ) ? calculateIntegrityRate ( lineIntegrityRateInfo , 90 , filterLineList . size ( ) ) : lineIds . size ( ) ) ;
rate . setTotalNum ( lineIds . size ( ) ) ;
rate . setTotalOnlineRate ( calculateIntegrityRate ( lineIntegrityRateInfo , filterLineList ) . doubleValue ( ) > 100 . 0 ? BigDecimal . valueOf ( 100 . 0 ) : calculateIntegrityRate ( lineIntegrityRateInfo , lineIds ) ) ;
rate . setBelowNum ( CollUtil . isNotEmpty ( lineIntegrityRateInfo ) ? calculateIntegrityRate ( lineIntegrityRateInfo , 90 , lineIds . size ( ) ) : lineIds . size ( ) ) ;
rate . setTotalOnlineRate ( calculateIntegrityRate ( lineIntegrityRateInfo , lineIds ) . doubleValue ( ) > 100 . 0 ? BigDecimal . valueOf ( 100 . 0 ) : calculateIntegrityRate ( lineIntegrityRateInfo , lineIds ) ) ;
List < DeviceOnlineRate . CitDetail > citDetailList = new ArrayList < > ( ) ;
List < DeviceOnlineRate . CitDetail > citDetailList = new ArrayList < > ( ) ;
DeviceOnlineRate . CitDetail citDetail ;
DeviceOnlineRate . CitDetail citDetail ;
DeviceOnlineRate . LineDetail detail ;
DeviceOnlineRate . LineDetail detail ;
//用户侧监测点 监测对象
sw . start ( " 查询用户台账 " ) ;
List < UserLedgerVO > userLedgerVOS = userLedgerService . selectUserList ( new UserReportParam ( ) ) ;
sw . stop ( ) ;
sw . start ( " 组装响应 " ) ;
Map < String , String > objMap = userLedgerVOS . stream ( ) . collect ( Collectors . toMap ( UserLedgerVO : : getId , UserLedgerVO : : getProjectName ) ) ;
for ( GeneralDeviceDTO dto : deviceInfo ) {
for ( GeneralDeviceDTO dto : deviceInfo ) {
//获取部门终端集合
//获取部门终端集合
List < RStatIntegrityVO > citDevOnRate = lineIntegrityRateInfo . stream ( ) . filter ( x - > dto . getLineIndexes ( ) . contains ( x . getLineIndex ( ) ) ) . collect ( Collectors . toList ( ) ) ;
List < RStatIntegrityVO > citDevOnRate = lineIntegrityRateInfo . stream ( ) . filter ( x - > dto . getLineIndexes ( ) . contains ( x . getLineIndex ( ) ) ) . collect ( Collectors . toList ( ) ) ;
@@ -252,11 +174,10 @@ public class RStatIntegrityDServiceImpl extends MppServiceImpl<RStatIntegrityDMa
. collect ( Collectors . toMap ( RStatIntegrityVO : : getLineIndex , RStatIntegrityVO : : getIntegrityRate ) ) ;
. collect ( Collectors . toMap ( RStatIntegrityVO : : getLineIndex , RStatIntegrityVO : : getIntegrityRate ) ) ;
citDetail = new DeviceOnlineRate . CitDetail ( ) ;
citDetail = new DeviceOnlineRate . CitDetail ( ) ;
List < LineDetailVO . Detail > lineDetail = LineInfoByIds . stream ( ) . filter ( x - > dto . getLineIndexes ( ) . contains ( x . getLineId ( ) ) ) . collect ( Collectors . toList ( ) ) ;
List < LineDetailVO . Detail > lineDetail = LineInfoByIds . stream ( ) . filter ( x - > dto . getLineIndexes ( ) . contains ( x . getLineId ( ) ) ) . collect ( Collectors . toList ( ) ) ;
citDetail . setCitName ( dto . getName ( ) ) ;
citDetail . setCitName ( dto . getName ( ) ) ;
citDetail . setCitTotalNum ( dto . getLineIndexes ( ) . size ( ) ) ;
citDetail . setCitTotalNum ( dto . getLineIndexes ( ) . size ( ) ) ;
citDetail . setCitBelowNum ( CollUtil . isNotEmpty ( citDevOnRate ) ? calculateIntegrityRate ( citDevOnRate , 90 , dto . getLineIndexes ( ) . size ( ) ) : dto . getLineIndexes ( ) . size ( ) ) ;
citDetail . setCitBelowNum ( CollUtil . isNotEmpty ( citDevOnRate ) ? calculateIntegrityRate ( citDevOnRate , 90 , dto . getLineIndexes ( ) . size ( ) ) : dto . getLineIndexes ( ) . size ( ) ) ;
citDetail . setCitTotalOnlineRate ( calculateIntegrityRate ( lineIntegrityRateInfo , dto . getLineIndexes ( ) ) . doubleValue ( ) > 100 . 0 ? BigDecimal . valueOf ( 100 . 0 ) : calculateIntegrityRate ( lineIntegrityRateInfo , dto . getLineIndexes ( ) ) ) ;
citDetail . setCitTotalOnlineRate ( calculateIntegrityRate ( lineIntegrityRateInfo , dto . getLineIndexes ( ) ) . doubleValue ( ) > 100 . 0 ? BigDecimal . valueOf ( 100 . 0 ) : calculateIntegrityRate ( lineIntegrityRateInfo , dto . getLineIndexes ( ) ) ) ;
List < DeviceOnlineRate . LineDetail > detailList = new ArrayList < > ( ) ;
List < DeviceOnlineRate . LineDetail > detailList = new ArrayList < > ( ) ;
for ( LineDetailVO . Detail line : lineDetail ) {
for ( LineDetailVO . Detail line : lineDetail ) {
detail = new DeviceOnlineRate . LineDetail ( ) ;
detail = new DeviceOnlineRate . LineDetail ( ) ;
@@ -271,9 +192,9 @@ public class RStatIntegrityDServiceImpl extends MppServiceImpl<RStatIntegrityDMa
detail . setLineId ( line . getLineId ( ) ) ;
detail . setLineId ( line . getLineId ( ) ) ;
detail . setLineName ( line . getLineName ( ) ) ;
detail . setLineName ( line . getLineName ( ) ) ;
//用户侧监测点 监测对象
//用户侧监测点 监测对象
detail . setObjName ( StringUtils . isBlank ( line . getObjId ( ) ) ? " / " : objMap . get ( line . getObjId ( ) ) ) ;
detail . setObjName ( StringUtils . isBlank ( line . getObjName ( ) ) ? " / " : line . getObjName ( ) ) ;
detail . setLatestTime ( line . getTimeID ( ) ) ;
detail . setLatestTime ( line . getTimeID ( ) ) ;
detail . setIntegrity ( onlineRateByDevMap . getOrDefault ( line . getLineId ( ) , BigDecimal . valueOf ( 0 ) ) . doubleValue ( ) > 100 . 0 ? BigDecimal . valueOf ( 100 . 0 ) : onlineRateByDevMap . getOrDefault ( line . getLineId ( ) , BigDecimal . valueOf ( 0 ) ) ) ;
detail . setIntegrity ( onlineRateByDevMap . getOrDefault ( line . getLineId ( ) , BigDecimal . valueOf ( 0 ) ) . doubleValue ( ) > 100 . 0 ? BigDecimal . valueOf ( 100 . 0 ) : onlineRateByDevMap . getOrDefault ( line . getLineId ( ) , BigDecimal . valueOf ( 0 ) ) ) ;
detailList . add ( detail ) ;
detailList . add ( detail ) ;
}
}
citDetail . setDetailList ( detailList ) ;
citDetail . setDetailList ( detailList ) ;
@@ -281,9 +202,7 @@ public class RStatIntegrityDServiceImpl extends MppServiceImpl<RStatIntegrityDMa
}
}
rate . setCitDetailList ( citDetailList ) ;
rate . setCitDetailList ( citDetailList ) ;
}
}
sw . stop ( ) ;
return rate ;
log . info ( " 耗时总结 " + sw . prettyPrint ( ) ) ;
return rate ;
}
}
@Override
@Override