@@ -22,6 +22,7 @@ import com.njcn.syncdata.pojo.enums.DicDataEnum;
import com.njcn.syncdata.pojo.enums.DicDataTypeEnum ;
import com.njcn.syncdata.pojo.po.* ;
import com.njcn.syncdata.service.IPowerDistributionareaService ;
import com.njcn.syncdata.service.IRDisMpMeasurePhaseReportDService ;
import com.njcn.syncdata.utils.RestTemplateUtil ;
import lombok.RequiredArgsConstructor ;
import lombok.extern.slf4j.Slf4j ;
@@ -59,7 +60,7 @@ import java.util.stream.Collectors;
public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImpl < PowerDistributionareaMapper , PowerDistributionarea > implements IPowerDistributionareaService {
private final DictDataMapper dictDataMapper ;
private final IRDisMpMeasurePhaseReportDService irDisMpMeasurePhaseReportDService ;
@Override
public String LoginToken ( ) {
String token = null ;
@@ -89,7 +90,7 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
}
@Override
public List < AdsAstXbjcptGetFctgDi > adsList ( ) {
public List < AdsAstXbjcptGetFctgDi > adsList ( Integer limitValue , Integer offsetValue ) {
List < AdsAstXbjcptGetFctgDi > aas = new ArrayList < > ( ) ;
String key = " 0e3bac160fd246f181ad4fd47da6929a " ;
String secret = " 383b4b2536234d84ac909cd605762061 " ;
@@ -108,9 +109,11 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
request . setUrl ( url ) ;
//API中 header头传输的参数
request . addHeader ( " x-api-id " , apiId ) ;
request. addHeader( " Content-Type" , " Application/json" ) ;
// request. addHeader(" Content-Type", " Application/json") ;
//API中 Query传输的参数
// request. addQueryStringParam("name", "value") ;
request. addQueryStringParam( " fcgc_a " , limitValue . toString ( ) ) ;
request . addQueryStringParam ( " fcgc_b " , offsetValue . toString ( ) ) ;
log . info ( Thread . currentThread ( ) . getName ( ) + " 链接 a: " + limitValue + " , b: " + offsetValue + " 失败 " ) ;
//API中 Body体参数
//request.setBody("demo");
} catch ( Exception e ) {
@@ -141,8 +144,14 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
String s = EntityUtils . toString ( resEntity , " UTF-8 " ) ;
log . info ( System . getProperty ( " line.separator " ) + s ) ;
JSONObject jsonObject = JSON . parseObject ( s ) ;
Map data = jsonObject . getObject ( " data " , Map . class ) ;
aas = JSONArray . parseArray ( data . get ( " data " ) . toString ( ) , AdsAstXbjcptGetFctgDi . class ) ;
String errCode = jsonObject . getString ( " errCode " ) ;
if ( StrUtil . isBlank ( errCode ) ) {
Map data = jsonObject . getObject ( " data " , Map . class ) ;
aas = JSONArray . parseArray ( data . get ( " data " ) . toString ( ) , AdsAstXbjcptGetFctgDi . class ) ;
} else if ( " DLM.4094 " . equals ( errCode ) ) {
log . info ( Thread . currentThread ( ) . getName ( ) + " 数据链接超时 " + s + " 结束----! " ) ;
}
}
} catch ( Exception e ) {
log . error ( Thread . currentThread ( ) . getName ( ) + " 链接 " + apiName + " 失败 " ) ;
@@ -160,7 +169,7 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
}
@Override
public List < AdsAstXbjcptGetFctgValueDi > adsDiList ( String ds ) {
public List < AdsAstXbjcptGetFctgValueDi > adsDiList ( String ds , Integer limitValue , Integer offsetValue ) {
List < AdsAstXbjcptGetFctgValueDi > aas = new ArrayList < > ( ) ;
String key = " 0e3bac160fd246f181ad4fd47da6929a " ;
String secret = " 383b4b2536234d84ac909cd605762061 " ;
@@ -179,9 +188,10 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
request . setUrl ( url ) ;
//API中 header头传输的参数
request . addHeader ( " x-api-id " , apiId ) ;
request . addHeader ( " Content-Type " , " Application/json " ) ;
//API中 Query传输的参数
request . addQueryStringParam ( " ds " , ds ) ;
request . addQueryStringParam ( " fcgc_va " , limitValue . toString ( ) ) ;
request . addQueryStringParam ( " fcgc_vb " , offsetValue . toString ( ) ) ;
//API中 Body体参数
//request.setBody("demo");
} catch ( Exception e ) {
@@ -212,8 +222,15 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
String s = EntityUtils . toString ( resEntity , " UTF-8 " ) ;
log . info ( System . getProperty ( " line.separator " ) + s ) ;
JSONObject jsonObject = JSON . parseObject ( s ) ;
Map data = jsonObject . getObject ( " data " , Map . class ) ;
aas = JSONArray . parseArray ( data . get ( " data " ) . toString ( ) , AdsAstXbjcptGetFctgValueDi . class ) ;
String errCode = jsonObject . getString ( " errCode " ) ;
if ( StrUtil . isBlank ( errCode ) ) {
Map data = jsonObject . getObject ( " data " , Map . class ) ;
aas = JSONArray . parseArray ( data . get ( " data " ) . toString ( ) , AdsAstXbjcptGetFctgValueDi . class ) ;
log . info ( Thread . currentThread ( ) . getName ( ) + " 获取日报表数据多少条 adsDiList: " + aas . size ( ) + " 结束----! " ) ;
} else if ( " DLM.4094 " . equals ( errCode ) ) {
log . info ( Thread . currentThread ( ) . getName ( ) + " 数据链接超时 " + s + " 结束----! " ) ;
}
}
} catch ( Exception e ) {
log . error ( Thread . currentThread ( ) . getName ( ) + " 链接 " + apiName + " 失败 " ) ;
@@ -276,8 +293,19 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
//1.获取数据台账信息
//获取数据中台数据
List < AdsAstXbjcptGetFctgDi > aas = adsList ( ) ;
List < AdsAstXbjcptGetFctgDi > aas = new ArrayList < > ( ) ;
Integer numPum = 0 ;
//定义每页返回数据条数
Integer size = 20000 ;
while ( true ) {
List < AdsAstXbjcptGetFctgDi > adsList = adsList ( size , numPum * size ) ;
aas . addAll ( adsList ) ;
if ( adsList . size ( ) < size ) {
break ;
} else {
numPum + + ;
}
}
Assert . isTrue ( CollUtil . isNotEmpty ( aas ) , " 获取中台数据为空! " ) ;
//进行数据拆分查询
ArrayList < AdsAstXbjcptGetFctgDi > dome = aas . stream ( ) . collect ( Collectors . collectingAndThen (
@@ -379,7 +407,7 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
//todo 要做处理(处理)
area . setVoltageLevel ( getAlgoDescribe ( pwopTransformerPSR . getVOLTAGELEVEL_ID ( ) , devVoltage ) ) ;
//todo 要做处理(处理)
area . setRegionalism ( getAlgoDescribe ( pwopTransformerPSR . getREGION_TYPE ( ) , regional ) ) ;
area . setDev Regionalism ( getAlgoDescribe ( pwopTransformerPSR . getREGION_TYPE ( ) , regional ) ) ;
//todo 要做处理(处理)
area . setNatureOfUse ( getAlgoDescribe ( pwopTransformerPSR . getUse_nature ( ) , userNature ) ) ;
//判断数据是否为空
@@ -399,7 +427,7 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
area . setDistributedPhotovoltaicNum ( fctgDi . getFc_num ( ) ) ;
area . setPhotovoltaicCapacity ( fctgDi . getFc_sum_cap ( ) . floatValue ( ) ) ;
area . setIfBevAp ( 0 ) ;
area . setApLoadType ( photovoltaics . getId ( ) ) ;
area . setApLoadType ( " 分布式光伏 " ) ;
area . setIsUpToGrid ( 1 ) ;
area . setStatus ( 1 ) ;
area . setCreateTime ( LocalDateTime . now ( ) ) ;
@@ -436,19 +464,55 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
@Override
public String insertDataDi ( String ds ) {
List < RDisMpMeasurePhaseReportD > info = new ArrayList < > ( ) ;
//查询日报表数据
List < AdsAstXbjcptGetFctgValueDi > adsDis = adsDiList ( ds ) ;
List < PowerDistributionarea > list = this . list ( new QueryWrapper < PowerDistributionarea > ( )
. select ( " Id " )
. eq ( " input_Status " , 1 )
. eq ( " Status " , 1 ) ) ;
//获取台区id
List < String > tgId = list . stream ( ) . map ( PowerDistributionarea : : getId ) . collect ( Collectors . toList ( ) ) ;
List < String > tgId = list . stream ( ) . map ( PowerDistributionarea : : getId ) . distinct ( ) . collect( Collectors . toList ( ) ) ;
log . info ( Thread . currentThread ( ) . getName ( ) + " 1.数据添加 tgId: " + tgId . size ( ) + " 结束----! " ) ;
if ( CollUtil . isEmpty ( tgId ) ) {
return " 日报表数据导入失败!当前台区编号为空。 " ;
}
//查询日报表数据
List < AdsAstXbjcptGetFctgValueDi > adsDis = new ArrayList < > ( ) ;
//分片集合
List < AdsAstXbjcptGetFctgValueDi > dis ;
List < AdsAstXbjcptGetFctgValueDi > tgList ;
Integer num = 0 ;
//定义每页返回数据条数
Integer size = 20000 ;
while ( true ) {
dis = adsDiList ( ds , size , num * size ) ;
if ( CollUtil . isNotEmpty ( dis ) ) {
//剔除不存在的台区信息
tgList = dis . stream ( ) . filter ( x - > tgId . contains ( x . getTg_id ( ) ) ) . collect ( Collectors . toList ( ) ) ;
if ( CollUtil . isNotEmpty ( tgList ) ) {
log . info ( Thread . currentThread ( ) . getName ( ) + " 1.数据添加 tgList: " + tgList . size ( ) + " 结束----! " ) ;
adsDis . addAll ( tgList ) ;
}
}
if ( CollUtil . isEmpty ( dis ) | | dis . size ( ) < size ) {
break ;
} else {
num + + ;
}
}
log . info ( Thread . currentThread ( ) . getName ( ) + " 2.数据添加 adsDis: " + adsDis . size ( ) + " 结束----! " ) ;
JSONArray objects = new JSONArray ( Collections . singletonList ( adsDis ) ) ;
log . info ( Thread . currentThread ( ) . getName ( ) + " 2.数据添加信息 adsDis: " + objects + " 结束----! " ) ;
DateTime parse = DateUtil . parse ( ds , " yyyyMMdd " ) ;
LocalDateTime localDateTime = LocalDateTime . ofInstant ( parse . toInstant ( ) , ZoneId . systemDefault ( ) ) ;
Map < String , List < AdsAstXbjcptGetFctgValueDi > > adsMap = adsDis . stream ( ) . collect ( Collectors . groupingBy ( AdsAstXbjcptGetFctgValueDi : : getTg_id ) ) ;
OptionalDouble max , min , avg , maxP , minP , avgP , maxQ , minQ , avgQ , max715 , max15 , maxDown , maxNeg ;
BigDecimal add , addP , addQ , divide , divideP , divideQ ;
for ( Map . Entry < String , List < AdsAstXbjcptGetFctgValueDi > > stringListEntry : adsMap . entrySet ( ) ) {
String key = stringListEntry . getKey ( ) ;
if ( ! tgId . contains ( key ) ) {
@@ -462,7 +526,7 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
reportD . setDatdate ( localDateTime ) ;
reportD . setMonitoringDuration ( 24 ) ;
//max_u
OptionalDouble max = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getMax_u ( ) ) ) . mapToDouble ( temp - > {
max = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getMax_u ( ) ) ) . mapToDouble ( temp - > {
return temp . getMax_u ( ) . doubleValue ( ) ;
} ) . max ( ) ;
if ( ! max . isPresent ( ) ) {
@@ -470,23 +534,23 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
}
//min_u
OptionalDouble min = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getMin_u ( ) ) ) . mapToDouble ( temp - > {
min = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getMin_u ( ) ) ) . mapToDouble ( temp - > {
return temp . getMin_u ( ) . doubleValue ( ) ;
} ) . min ( ) ;
if ( ! min . isPresent ( ) ) {
continue ;
}
//avg_u
OptionalDouble avg = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getAvg_u ( ) ) ) . mapToDouble ( temp - > {
avg = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getAvg_u ( ) ) ) . mapToDouble ( temp - > {
return temp . getAvg_u ( ) . doubleValue ( ) ;
} ) . average ( ) ;
if ( ! avg . isPresent ( ) ) {
continue ;
}
//95
BigDecimal add = new BigDecimal ( max . getAsDouble ( ) ) . add ( new BigDecimal ( avg . getAsDouble ( ) ) ) ;
add = new BigDecimal ( max . getAsDouble ( ) ) . add ( new BigDecimal ( avg . getAsDouble ( ) ) ) ;
if ( add . floatValue ( ) ! = 0 ) {
BigDecimal divide = add . divide ( new BigDecimal ( 2 ) , 4 , BigDecimal . ROUND_UP ) ;
divide = add . divide ( new BigDecimal ( 2 ) , 4 , BigDecimal . ROUND_UP ) ;
reportD . setPhaseVoltageEffective95 ( divide . floatValue ( ) ) ;
} else {
reportD . setSpActivePower_95 ( 0 . 0f ) ;
@@ -496,31 +560,31 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
reportD . setPhaseVoltageEffectiveAvg ( ( float ) avg . getAsDouble ( ) ) ;
//---------------------------------------------------------------------------------------------------
//max_u
OptionalDouble maxP = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getMax_p ( ) ) ) . mapToDouble ( temp - > {
maxP = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getMax_p ( ) ) ) . mapToDouble ( temp - > {
return temp . getMax_p ( ) . doubleValue ( ) ;
} ) . max ( ) ;
if ( ! maxP . isPresent ( ) ) {
continue ;
}
//min_u
OptionalDouble minP = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getMin_p ( ) ) ) . mapToDouble ( temp - > {
minP = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getMin_p ( ) ) ) . mapToDouble ( temp - > {
return temp . getMin_p ( ) . doubleValue ( ) ;
} ) . min ( ) ;
if ( ! minP . isPresent ( ) ) {
continue ;
}
//avg_u
OptionalDouble avgP = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getAvg_p ( ) ) ) . mapToDouble ( temp - > {
avgP = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getAvg_p ( ) ) ) . mapToDouble ( temp - > {
return temp . getAvg_p ( ) . doubleValue ( ) ;
} ) . average ( ) ;
if ( ! avgP . isPresent ( ) ) {
continue ;
}
//95
BigDecimal addP = new BigDecimal ( maxP . getAsDouble ( ) ) . add ( new BigDecimal ( avgP . getAsDouble ( ) ) ) ;
addP = new BigDecimal ( maxP . getAsDouble ( ) ) . add ( new BigDecimal ( avgP . getAsDouble ( ) ) ) ;
if ( addP . floatValue ( ) ! = 0 ) {
BigDecimal divide = addP . divide ( new BigDecimal ( 2 ) , 4 , BigDecimal . ROUND_UP ) ;
reportD . setSpActivePower_95 ( divide . floatValue ( ) ) ;
divideP = addP . divide ( new BigDecimal ( 2 ) , 4 , BigDecimal . ROUND_UP ) ;
reportD . setSpActivePower_95 ( divideP . floatValue ( ) ) ;
} else {
reportD . setSpActivePower_95 ( 0 . 0f ) ;
}
@@ -529,31 +593,31 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
reportD . setSpActivePowerAvg ( ( float ) avgP . getAsDouble ( ) ) ;
//---------------------------------------------------------------------------------------------------
//max_Q
OptionalDouble maxQ = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getMax_q ( ) ) ) . mapToDouble ( temp - > {
maxQ = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getMax_q ( ) ) ) . mapToDouble ( temp - > {
return temp . getMax_q ( ) . doubleValue ( ) ;
} ) . max ( ) ;
if ( ! maxQ . isPresent ( ) ) {
continue ;
}
//min_Q
OptionalDouble minQ = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getMin_q ( ) ) ) . mapToDouble ( temp - > {
minQ = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getMin_q ( ) ) ) . mapToDouble ( temp - > {
return temp . getMin_q ( ) . doubleValue ( ) ;
} ) . min ( ) ;
if ( ! minQ . isPresent ( ) ) {
continue ;
}
//avg_u
OptionalDouble avgQ = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getAvg_q ( ) ) ) . mapToDouble ( temp - > {
avgQ = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getAvg_q ( ) ) ) . mapToDouble ( temp - > {
return temp . getAvg_q ( ) . doubleValue ( ) ;
} ) . average ( ) ;
if ( ! avgQ . isPresent ( ) ) {
continue ;
}
//95
BigDecimal addQ = new BigDecimal ( maxQ . getAsDouble ( ) ) . add ( new BigDecimal ( avgQ . getAsDouble ( ) ) ) ;
addQ = new BigDecimal ( maxQ . getAsDouble ( ) ) . add ( new BigDecimal ( avgQ . getAsDouble ( ) ) ) ;
if ( addQ . floatValue ( ) ! = 0 ) {
BigDecimal divide = addQ . divide ( new BigDecimal ( 2 ) , 4 , BigDecimal . ROUND_UP ) ;
reportD . setSpApparentPower95 ( divide . floatValue ( ) ) ;
divideQ = addQ . divide ( new BigDecimal ( 2 ) , 4 , BigDecimal . ROUND_UP ) ;
reportD . setSpApparentPower95 ( divideQ . floatValue ( ) ) ;
} else {
reportD . setSpApparentPower95 ( 0 . 0f ) ;
}
@@ -564,25 +628,25 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
//---------------------------------------------------------------------------------------------------
//max_Q
OptionalDouble max715 = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getUp7_over_time ( ) ) ) . mapToDouble ( temp - > {
max715 = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getUp7_over_time ( ) ) ) . mapToDouble ( temp - > {
return temp . getUp7_over_time ( ) . doubleValue ( ) ;
} ) . max ( ) ;
if ( ! max715 . isPresent ( ) ) {
continue ;
}
OptionalDouble max15 = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getUp15_over_time ( ) ) ) . mapToDouble ( temp - > {
max15 = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getUp15_over_time ( ) ) ) . mapToDouble ( temp - > {
return temp . getUp15_over_time ( ) . doubleValue ( ) ;
} ) . max ( ) ;
if ( ! max15 . isPresent ( ) ) {
continue ;
}
OptionalDouble maxDown = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getDown_over_time ( ) ) ) . mapToDouble ( temp - > {
maxDown = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getDown_over_time ( ) ) ) . mapToDouble ( temp - > {
return temp . getDown_over_time ( ) . doubleValue ( ) ;
} ) . max ( ) ;
if ( ! maxDown . isPresent ( ) ) {
continue ;
}
OptionalDouble maxNeg = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getNeg_p_time ( ) ) ) . mapToDouble ( temp - > {
maxNeg = value . stream ( ) . filter ( x - > ObjectUtil . isNotNull ( x . getNeg_p_time ( ) ) ) . mapToDouble ( temp - > {
return temp . getNeg_p_time ( ) . doubleValue ( ) ;
} ) . max ( ) ;
if ( ! maxNeg . isPresent ( ) ) {
@@ -596,8 +660,16 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
reportD . setPracticalTargetNum ( 96 ) ;
info . add ( reportD ) ;
}
log . info ( Thread . currentThread ( ) . getName ( ) + " 1.数据添加 info: " + info . size ( ) + " 结束----! " ) ;
if ( CollUtil . isNotEmpty ( info ) ) {
LambdaQueryWrapper < RDisMpMeasurePhaseReportD > lambdaQueryWrapper = new LambdaQueryWrapper < > ( ) ;
lambdaQueryWrapper . eq ( RDisMpMeasurePhaseReportD : : getDatdate , ds ) ;
irDisMpMeasurePhaseReportDService . remove ( lambdaQueryWrapper ) ;
irDisMpMeasurePhaseReportDService . insertBatchBySlice ( info , 1000 ) ;
}
return " 日报表数据导入成功 " ;
}
public < T > List < T > resourceMethod ( Integer a , String token , Integer num , String ids , Class < T > t ) {
List < T > aas = new ArrayList < > ( ) ;
switch ( a ) {
@@ -883,7 +955,8 @@ public class PowerDistributionareaServiceImpl extends ReplenishMybatisServiceImp
reportD . setFlowBackflowOverloadLoadrateMin ( 0 . 0F ) ;
reportD . setFlowBackflowOverloadLoadrateAvg ( 0 . 0F ) ;
reportD . setFlowBackflowOverloadLoadrate95 ( 0 . 0F ) ;
reportD . setHarmonicVoltageOverrunDuration ( 0 ) ;
reportD . setTpVoltageUnbalanceOverrunDuration ( 0 ) ;
reportD . setHarmonicVoltageOverrunDuration ( 0 . 0F );
reportD . setTpVoltageUnbalanceOverrunDuration ( 0 . 0F );
}
}