@@ -16,6 +16,14 @@ import com.njcn.prepare.harmonic.mapper.mysql.upload.RUploadPointStatisticalData
import com.njcn.prepare.harmonic.pojo.bo.CalculatedParam ;
import com.njcn.prepare.harmonic.pojo.dto.UploadPointStatisticalParam ;
import com.njcn.prepare.harmonic.service.mysql.upload.IRUploadPointStatisticalDataDService ;
import com.njcn.system.api.DicDataFeignClient ;
import com.njcn.system.api.DictTreeFeignClient ;
import com.njcn.system.enums.DicDataEnum ;
import com.njcn.system.enums.DicDataTypeEnum ;
import com.njcn.system.enums.DicTreeEnum ;
import com.njcn.system.pojo.po.DictData ;
import com.njcn.system.pojo.po.SysDicTreePO ;
import com.njcn.system.pojo.vo.DictTreeVO ;
import com.njcn.user.api.DeptFeignClient ;
import com.njcn.user.pojo.po.Dept ;
import lombok.RequiredArgsConstructor ;
@@ -24,6 +32,7 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal ;
import java.math.RoundingMode ;
import java.util.* ;
import java.util.function.Function ;
import java.util.stream.Collectors ;
/**
@@ -42,6 +51,10 @@ public class RUploadPointStatisticalDataDServiceImpl extends MppServiceImpl<RUpl
private final ROperatingIndexDPOMapper rOperatingIndexDPOMapper ;
private final RStatIntegrityDMapper rStatIntegrityDMapper ;
private final DictTreeFeignClient dictTreeFeignClient ;
private final DicDataFeignClient dicDataFeignClient ;
/**
* 此算法用于计算底层数据,方便国网数据上送
* 1.表中存储所有单位, 没有数据的暂时设置为0
@@ -56,30 +69,86 @@ public class RUploadPointStatisticalDataDServiceImpl extends MppServiceImpl<RUpl
Dept data = deptFeignClient . getRootDept ( ) . getData ( ) ;
String provinceId = deptFeignClient . getDepSonIdByDeptId ( data . getId ( ) ) . getData ( ) . get ( 0 ) ;
Dept dept = deptFeignClient . getDeptById ( provinceId ) . getData ( ) ;
//筛选国网上送监测点
List < DeptGetChildrenMoreDTO > l1 = calculatedParam . getIdList ( ) ;
l1 . forEach ( item - > {
List < LineDevGetDTO > newList = item . getLineBaseList ( ) . stream ( ) . filter ( o - > Objects . equals ( o . getIsUpToGrid ( ) , 1 ) ) . collect ( Collectors . toList ( ) ) ;
item . setLineBaseList ( newList ) ;
UploadPointStatisticalParam uploadPointStatisticalParam = new UploadPointStatisticalParam ( ) ;
uploadPointStatisticalParam . setOrgId ( item . getUnitId ( ) ) ;
List < LineDevGetDTO > lineInfo = item . getLineBaseList ( ) ;
uploadPointStatisticalParam . setOnlineMonitorNum ( lineInfo . siz e ( ) ) ;
uploadPointStatisticalParam . setRunMonitorNum ( lineInfo . size ( ) ) ;
uploadPointStatisticalParam . setRunTerminalNum ( ( int ) lineInfo . stream ( ) . map ( LineDevGetDTO : : getDevId ) . distinct ( ) . count ( ) ) ;
paramList . add ( uploadPointStatisticalParam ) ;
} ) ;
Map < String , List < UploadPointStatisticalParam > > devMap = paramList . stream ( ) . collect ( Collectors . groupingBy ( UploadPointStatisticalParam : : getOrgId ) ) ;
//获取数据个数
List < R StatIntegrityD > dataList = getStatIntegrityData ( calculatedParam . getDataDate ( ) ) ;
//查询所有一级树字典
List < SysDicTreePO > sysDicTreePOList = dictTreeFeignClient . queryAll ( ) . getData ( ) ;
List < SysDicTreePO > temTreeList = sysDicTreePOList . stream ( ) . filter ( item - > Objects . equals ( item . getCode ( ) , DicTreeEnum . Trans_Sub . getCode ( ) )
| | Objects . equals ( item . getCode ( ) , DicTreeEnum . Converter . getCode ( ) ) | | Objects . equals ( item . getCode ( ) , DicTreeEnum . Ele_Railways . getCode ( ) )
| | Objects . equals ( item . getCode ( ) , DicTreeEnum . Wind_Farms . getCode ( ) ) | | Objects . equals ( item . getCode ( ) , DicTreeEnum . Power_Station . getCode ( ) )
| | Objects . equals ( item . getCode ( ) , DicTreeEnum . Smelting_Load . getCode ( ) ) | | Objects . equals ( item . getCode ( ) , DicTreeEnum . Imp_Users . getCod e ( ) )
) . collect ( Collectors . toList ( ) ) ;
Map < String , List < String > > mapKey = new HashMap < > ( ) ;
List < String > otherIds = new ArrayList < > ( ) ;
for ( SysDicTreePO sysDicTreePO : temTreeList ) {
List < SysDicTreePO > temList = sysDicTreePOList . stream ( ) . filter ( item - > item . getPid ( ) . equals ( sysDicTreePO . getId ( ) ) ) . collect ( Collectors . toList ( ) ) ;
List < String > ids = temList . stream ( ) . map ( SysDicTreePO : : getId ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
ids . add ( sysDicTreePO . getId ( ) ) ;
mapKey . put ( sysDicTreePO . getCode ( ) , ids ) ;
otherIds . addAll ( ids ) ;
}
List < DictData > dictDataList = dicDataFeignClient . getDicDataByTypeCode ( DicDataTypeEnum . Station_Type . getCode ( ) ) . getData ( ) ;
Map < String , DictData > dictDataMap = dictDataList . stream ( ) . collect ( Collectors . toMap ( DictData : : getCode , Function . identity ( ) ) ) ;
//获取所有单位
List < Dept > deptList = deptFeignClient . getAllDept ( ) . getData ( ) ;
Map < String , List < Dept > > deptMap = deptList . stream ( ) . collect ( Collectors . groupingBy ( Dept : : getCode ) ) ;
//筛选国网上送监测点
List < DeptGetChildrenMoreDTO > l1 = calculatedParam . getIdList ( ) ;
//获取数据个数
List < RStatIntegrityD > dataList = getStatIntegrityData ( calculatedParam . getDataDate ( ) ) ;
l1 . forEach ( item - > {
if ( Objects . equals ( Integer . parseInt ( UploadEnum . NJCN_DEPT_LEVEL_1 . getCode ( ) ) , item . getDeptLevel ( ) ) ) {
return ;
}
List < LineDevGetDTO > newList = item . getLineBaseList ( ) . stream ( ) . filter ( o - > Objects . equals ( o . getIsUpToGrid ( ) , 1 ) ) . collect ( Collectors . toList ( ) ) ;
item . setLineBaseList ( newList ) ;
List < LineDevGetDTO > otherMonitor = item . getLineBaseList ( ) . stream ( ) . filter ( me - > ! otherIds . contains ( me . getObjType ( ) ) ) . collect ( Collectors . toList ( ) ) ;
mapKey . forEach ( ( key , val ) - > {
List < LineDevGetDTO > keyItem = item . getLineBaseList ( ) . stream ( ) . filter ( o - > val . contains ( o . getObjType ( ) ) ) . collect ( Collectors . toList ( ) ) ;
RUploadPointStatisticalDataD rUploadPointStatisticalDataD = new RUploadPointStatisticalDataD ( ) ;
switch ( key ) {
case " 2100 " :
rUploadPointStatisticalDataD . setStationType ( dictDataMap . get ( DicDataEnum . Trans_Sub . getCode ( ) ) . getId ( ) ) ;
break ;
case " 1200 " :
rUploadPointStatisticalDataD . setStationType ( dictDataMap . get ( DicDataEnum . Converter . getCode ( ) ) . getId ( ) ) ;
break ;
case " 1300 " :
rUploadPointStatisticalDataD . setStationType ( dictDataMap . get ( DicDataEnum . Ele_Railways . getCode ( ) ) . getId ( ) ) ;
break ;
case " 1401 " :
rUploadPointStatisticalDataD . setStationType ( dictDataMap . get ( DicDataEnum . Wind_Farms . getCode ( ) ) . getId ( ) ) ;
break ;
case " 1402 " :
rUploadPointStatisticalDataD . setStationType ( dictDataMap . get ( DicDataEnum . Power_Station . getCode ( ) ) . getId ( ) ) ;
break ;
case " 2600 " :
rUploadPointStatisticalDataD . setStationType ( dictDataMap . get ( DicDataEnum . Smelting_Load . getCode ( ) ) . getId ( ) ) ;
break ;
case " 2400 " :
rUploadPointStatisticalDataD . setStationType ( dictDataMap . get ( DicDataEnum . Imp_Users . getCode ( ) ) . getId ( ) ) ;
break ;
}
rUploadPointStatisticalDataD . setId ( IdUtil . simpleUUID ( ) ) ;
rUploadPointStatisticalDataD . setProvinceId ( dept . getCode ( ) ) ;
rUploadPointStatisticalDataD . setProvinceName ( dept . getName ( ) ) ;
@@ -90,18 +159,17 @@ public class RUploadPointStatisticalDataDServiceImpl extends MppServiceImpl<RUpl
rUploadPointStatisticalDataD . setDistributionFlag ( UploadEnum . DISTRIBUTION_FLAG_01 . getCode ( ) ) ;
//fixme over
judgeLevel ( item . getDeptLevel ( ) , rUploadPointStatisticalDataD , item . getUnitId ( ) , item . getUnitName ( ) , deptList , deptMap ) ;
List < UploadPointStatisticalParam > l11 = devMap . get ( item . getUnitId ( ) ) ;
if ( CollectionUtil . isNotEmpty ( l11 ) ) {
UploadPointStatisticalParam po = l11 . get ( 0 ) ;
rUploadPointStatisticalDataD . setRunTerminalNu m( po . getRunTerminalNum ( ) ) ;
rUploadPointStatisticalDataD . setOnlineMonitorNum ( po . getOnlineMonitorNum ( ) ) ;
rUploadPointStatisticalDataD . setRun MonitorNum ( po . getRunMonitorNum ( ) ) ;
rUploadPointStatisticalDataD . setOnlineMonitorRate ( po . getOnlineMonitorNum ( ) = = 0 ? 0d : BigDecimal . valueOf ( po . getOnlineMonitorNum ( ) * 100 . 0 / po . getRunMonitorNum ( ) ) . setScale ( 4 , BigDecimal . ROUND_HALF_UP ) . doubleValue ( ) ) ;
}
//获取当前单位下所有的监测点,匹配监测点数据
List < LineDevGetDTO > l2 = item . getLineBaseList ( ) ;
if ( CollectionUtil . isNotEmpty ( l2 ) ) {
List < RStatIntegrityD > l3 = dataList . stream ( ) . filter ( it - > l2 . stream ( ) . map ( LineDevGetDTO : : getPointId ) . collect ( Collectors . toList ( ) ) . contains ( it . getLineIndex ( ) ) ) . collect ( Collectors . toList ( ) ) ;
long pointCount = keyItem . stream ( ) . map ( LineDevGetDTO : : getPointId ) . distinct ( ) . count ( ) ;
long devCount = keyItem . strea m( ) . map ( LineDevGetDTO : : getDevId ) . distinct ( ) . count ( ) ;
rUploadPointStatisticalDataD . setRunTerminalNum ( ( int ) devCount ) ;
rUploadPointStatisticalDataD . setOnline MonitorNum ( ( int ) pointCount ) ;
rUploadPointStatisticalDataD . setRunMonitorNum ( ( int ) pointCount ) ;
rUploadPointStatisticalDataD . setOnlineMonitorRate ( pointCount = = 0 ? 0d : BigDecimal . valueOf ( rUploadPointStatisticalDataD . getOnlineMonitorNum ( ) * 100 . 0 / rUploadPointStatisticalDataD . getRunMonitorNum ( ) ) . setScale ( 4 , RoundingMode . HALF_UP ) . doubleValue ( ) ) ;
List < RStatIntegrityD > l3 = dataList . stream ( ) . filter ( it - > keyItem . stream ( ) . map ( LineDevGetDTO : : getPointId ) . collect ( Collectors . toList ( ) ) . contains ( it . getLineIndex ( ) ) ) . collect ( Collectors . toList ( ) ) ;
int due = l3 . stream ( ) . mapToInt ( RStatIntegrityD : : getDueTime ) . sum ( ) ;
int real = l3 . stream ( ) . mapToInt ( RStatIntegrityD : : getRealTime ) . sum ( ) ;
rUploadPointStatisticalDataD . setExpectCollectNum ( due ) ;
@@ -113,30 +181,70 @@ public class RUploadPointStatisticalDataDServiceImpl extends MppServiceImpl<RUpl
rUploadPointStatisticalDataD . setDataFullRate ( BigDecimal . valueOf ( real * 100 . 0 / due ) . setScale ( 4 , RoundingMode . HALF_UP ) . doubleValue ( ) ) ;
}
rUploadPointStatisticalDataD . setStationMonitorNum ( l3 . size ( ) ) ;
}
result . add ( rUploadPointStatisticalDataD ) ;
} ) ;
//其他
RUploadPointStatisticalDataD rUploadPointStatisticalDataD = new RUploadPointStatisticalDataD ( ) ;
rUploadPointStatisticalDataD . setStationType ( dictDataMap . get ( DicDataEnum . Station_Other . getCode ( ) ) . getId ( ) ) ;
rUploadPointStatisticalDataD . setId ( IdUtil . simpleUUID ( ) ) ;
rUploadPointStatisticalDataD . setProvinceId ( dept . getCode ( ) ) ;
rUploadPointStatisticalDataD . setProvinceName ( dept . getName ( ) ) ;
rUploadPointStatisticalDataD . setStatisticalDate ( calculatedParam . getDataDate ( ) ) ;
rUploadPointStatisticalDataD . setStatisticalType ( UploadEnum . STATISTICAL_TYPE_03 . getCode ( ) ) ;
rUploadPointStatisticalDataD . setUploadStatus ( Integer . parseInt ( UploadEnum . UPLOAD_STATUS_0 . getCode ( ) ) ) ;
//fixme 主配网标识文档中没有,先随便定义一个,后期调整
rUploadPointStatisticalDataD . setDistributionFlag ( UploadEnum . DISTRIBUTION_FLAG_01 . getCode ( ) ) ;
//fixme over
judgeLevel ( item . getDeptLevel ( ) , rUploadPointStatisticalDataD , item . getUnitId ( ) , item . getUnitName ( ) , deptList , deptMap ) ;
long pointCount = otherMonitor . stream ( ) . map ( LineDevGetDTO : : getPointId ) . distinct ( ) . count ( ) ;
long devCount = otherMonitor . stream ( ) . map ( LineDevGetDTO : : getDevId ) . distinct ( ) . count ( ) ;
rUploadPointStatisticalDataD . setRunTerminalNum ( ( int ) devCount ) ;
rUploadPointStatisticalDataD . setOnlineMonitorNum ( ( int ) pointCount ) ;
rUploadPointStatisticalDataD . setRunMonitorNum ( ( int ) pointCount ) ;
rUploadPointStatisticalDataD . setOnlineMonitorRate ( pointCount = = 0 ? 0d : BigDecimal . valueOf ( rUploadPointStatisticalDataD . getOnlineMonitorNum ( ) * 100 . 0 / rUploadPointStatisticalDataD . getRunMonitorNum ( ) ) . setScale ( 4 , RoundingMode . HALF_UP ) . doubleValue ( ) ) ;
List < RStatIntegrityD > l3 = dataList . stream ( ) . filter ( it - > otherMonitor . stream ( ) . map ( LineDevGetDTO : : getPointId ) . collect ( Collectors . toList ( ) ) . contains ( it . getLineIndex ( ) ) ) . collect ( Collectors . toList ( ) ) ;
int due = l3 . stream ( ) . mapToInt ( RStatIntegrityD : : getDueTime ) . sum ( ) ;
int real = l3 . stream ( ) . mapToInt ( RStatIntegrityD : : getRealTime ) . sum ( ) ;
rUploadPointStatisticalDataD . setExpectCollectNum ( due ) ;
rUploadPointStatisticalDataD . setActualCollectNum ( real ) ;
if ( due = = 0 | | real = = 0 ) {
rUploadPointStatisticalDataD . setDataFullRate ( BigDecimal . valueOf ( 0 ) . setScale ( 4 , RoundingMode . HALF_UP ) . doubleValue ( ) ) ;
} else {
rUploadPointStatisticalDataD . setDataFullRate ( BigDecimal . valueOf ( real * 100 . 0 / due ) . setScale ( 4 , RoundingMode . HALF_UP ) . doubleValue ( ) ) ;
}
rUploadPointStatisticalDataD . setStationMonitorNum ( l3 . size ( ) ) ;
result . add ( rUploadPointStatisticalDataD ) ;
} ) ;
if ( CollectionUtil . isNotEmpty ( result ) ) {
//查询数据如果有数据,将data_id置为null,这样就保留之前的唯一id
LambdaQueryWrapper < RUploadPointStatisticalDataD > lambdaQueryWrapper = new LambdaQueryWrapper < > ( ) ;
lambdaQueryWrapper . eq ( RUploadPointStatisticalDataD : : getStatisticalDate , calculatedParam . getDataDate ( ) ) ;
List < RUploadPointStatisticalDataD > oldData = this . list ( lambdaQueryWrapper ) ;
if ( CollectionUtil . isNotEmpty ( oldData ) ) {
result . forEach ( item - > {
item . setId ( null ) ;
} ) ;
result . forEach ( it - > it . setId ( null ) ) ;
}
this . saveOrUpdateBatchByMultiId ( result ) ;
}
}
/**
* r_operating_index_d表中获取终端、监测点个数
*/
public List < ROperatingIndexDPO > getOperatingIndexData ( String time ) {
LambdaQueryWrapper < ROperatingIndexDPO > lambdaQueryWrapper = new LambdaQueryWrapper < > ( ) ;
lambdaQueryWrapper . eq ( ROperatingIndexDPO : : getDataDate , time ) ;
return rOperatingIndexDPOMapper . selectList ( lambdaQueryWrapper ) ;
}
}
/**
@@ -148,6 +256,7 @@ public class RUploadPointStatisticalDataDServiceImpl extends MppServiceImpl<RUpl
return rStatIntegrityDMapper . selectList ( lambdaQueryWrapper ) ;
}
/**
* 判断单位层级
*/