@@ -1,10 +1,17 @@
package com.njcn.harmonic.service.impl ;
import cn.hutool.core.bean.BeanUtil ;
import cn.hutool.core.collection.CollUtil ;
import cn.hutool.core.collection.CollectionUtil ;
import cn.hutool.core.date.DatePattern ;
import cn.hutool.core.date.LocalDateTimeUtil ;
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 ;
import com.alibaba.fastjson.JSON ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONObject ;
import com.cloud.apigateway.sdk.utils.Client ;
import com.cloud.apigateway.sdk.utils.Request ;
import com.njcn.common.utils.PubUtils ;
import com.njcn.device.biz.commApi.CommTerminalGeneralClient ;
import com.njcn.device.biz.pojo.dto.LineDevGetDTO ;
@@ -17,6 +24,9 @@ import com.njcn.harmonic.mapper.HistoryDataMapper;
import com.njcn.harmonic.pojo.QueryResultLimitVO ;
import com.njcn.harmonic.pojo.param.HarmonicHistoryParam ;
import com.njcn.harmonic.pojo.param.HistoryParam ;
import com.njcn.harmonic.pojo.po.zt.HarmonicHistoryC ;
import com.njcn.harmonic.pojo.po.zt.HarmonicHistoryP ;
import com.njcn.harmonic.pojo.po.zt.HarmonicHistoryV ;
import com.njcn.harmonic.pojo.vo.EventDetailVO ;
import com.njcn.harmonic.pojo.vo.HistoryDataResultVO ;
import com.njcn.harmonic.service.OracleResultService ;
@@ -24,13 +34,26 @@ import com.njcn.influx.pojo.bo.HarmonicHistoryData;
import com.njcn.influx.pojo.constant.InfluxDBTableConstant ;
import com.njcn.system.api.DicDataFeignClient ;
import com.njcn.system.pojo.po.DictData ;
import lombok.All ArgsConstructor ;
import lombok.Required ArgsConstructor ;
import lombok.SneakyThrows ;
import lombok.extern.slf4j.Slf4j ;
import org.apache.http.Header ;
import org.apache.http.HttpEntity ;
import org.apache.http.HttpResponse ;
import org.apache.http.client.methods.HttpRequestBase ;
import org.apache.http.impl.client.CloseableHttpClient ;
import org.apache.http.impl.client.HttpClients ;
import org.apache.http.util.EntityUtils ;
import org.springframework.stereotype.Service ;
import java.io.IOException ;
import java.lang.reflect.Field ;
import java.math.BigDecimal ;
import java.math.RoundingMode ;
import java.time.Duration ;
import java.time.Instant ;
import java.time.LocalDateTime ;
import java.time.ZoneOffset ;
import java.time.format.DateTimeFormatter ;
import java.util.* ;
import java.util.stream.Collectors ;
@@ -41,7 +64,8 @@ import java.util.stream.Collectors;
* @date 2024/1/11 16:15
*/
@Service
@AllArgsConstructor
@Slf4j
@RequiredArgsConstructor
public class OracleResultServiceImpl implements OracleResultService {
private final EventDetailFeignClient eventDetailFeignClient ;
private final CommTerminalGeneralClient commTerminalGeneralClient ;
@@ -86,22 +110,6 @@ public class OracleResultServiceImpl implements OracleResultService {
return historyDataResultVOList ;
}
@Override
public List < HistoryDataResultVO > getHistoryResult2 ( HistoryParam historyParam ) {
HarmonicHistoryParam param = new HarmonicHistoryParam ( ) ;
param . setStartTime ( " 2023-12-01 00:00:00 " ) ;
param . setEndTime ( " 2023-12-01 23:59:59 " ) ;
param . setValueTypeName ( " " ) ;
List < HarmonicHistoryData > data_v = HistoryDataMapper . getDataFluc ( param ) ;
param . setValueTypeName ( " MAX " ) ;
List < HarmonicHistoryData > data_v2 = HistoryDataMapper . getDataFluc ( param ) ;
param . setValueTypeName ( " MIN " ) ;
List < HarmonicHistoryData > data_v3 = HistoryDataMapper . getDataFluc ( param ) ;
param . setValueTypeName ( " CP95 " ) ;
List < HarmonicHistoryData > data_v4 = HistoryDataMapper . getDataFluc ( param ) ;
return null ;
}
@SneakyThrows
private HistoryDataResultVO getCondition ( String startTime , String endTime , String lineId , String contion , Integer number , Integer valueType , Integer ptType ) {
@@ -214,7 +222,6 @@ public class OracleResultServiceImpl implements OracleResultService {
if ( ! lineId . isEmpty ( ) ) {
Float topLimit = 0f ;
Float lowerLimit = 0f ;
Integer type = 0 ;
//获取监测点信息
LineDevGetDTO lineDetailDataVO = commTerminalGeneralClient . getMonitorDetail ( lineId ) . getData ( ) ;
//获取限值
@@ -222,7 +229,6 @@ public class OracleResultServiceImpl implements OracleResultService {
if ( Objects . isNull ( overlimit ) ) {
//对配网没有限值的统一处理
DictData dictData = dicDataFeignClient . getDicDataById ( lineDetailDataVO . getVoltageLevel ( ) ) . getData ( ) ;
type = 1 ;
float voltageLevel = Float . parseFloat ( dictData . getValue ( ) ) ;
float shortVal = COverlimitUtil . getDlCapByVoltageLevel ( voltageLevel ) ;
overlimit = COverlimitUtil . globalAssemble ( voltageLevel , 10f , 10f , shortVal , 1 , 1 ) ;
@@ -615,11 +621,20 @@ public class OracleResultServiceImpl implements OracleResultService {
//2、一次查询返回一条记录, 以T相为条件, 返回某3个指标值
//3、一次查询返回一条记录, 以T相为条件, 返回某1个指标值
HarmonicHistoryParam historyParam = new HarmonicHistoryParam ( ) ;
historyParam . s etStartTime ( startTime + InfluxDBTableConstant . START_TIME ) ;
historyParam . setEndTime ( endTime + InfluxDBTableConstant . END_TIME ) ;
historyParam . setValueTypeName ( valueTypeName ) ;
historyParam . setLineId ( lineId ) ;
queryResultLimitVO . setHarmonicHistoryDataList ( setHistoryDataList ( historyParam , contion , number , type ) ) ;
if ( lineDetailDataVO . g etOracleLineId ( ) ! = null ) {
//当oracle监测点不为空说明是主网监测点
historyParam . setStartTime ( startTime + InfluxDBTableConstant . START_TIME ) ;
historyParam . setEndTime ( endTime + InfluxDBTableConstant . END_TIME ) ;
historyParam . setValueTypeName ( valueTypeName ) ;
historyParam . setLineId ( lineDetailDataVO . getOracleLineId ( ) . toString ( ) ) ;
} else {
//就是配网监测点
historyParam . setStartTime ( startTime . replace ( " - " , " " ) ) ;
historyParam . setEndTime ( endTime . replace ( " - " , " " ) ) ;
historyParam . setValueTypeName ( valueTypeName ) ;
historyParam . setLineId ( lineId ) ;
}
queryResultLimitVO . setHarmonicHistoryDataList ( setHistoryDataList ( historyParam , contion , number , lineDetailDataVO . getType ( ) ) ) ;
queryResultLimitVO . setTopLimit ( topLimit ) ;
queryResultLimitVO . setLowerLimit ( lowerLimit ) ;
queryResultLimitVO . setPhaiscType ( phasicType ) ;
@@ -645,7 +660,12 @@ public class OracleResultServiceImpl implements OracleResultService {
List < HarmonicHistoryData > harmonicHistoryData = new ArrayList < > ( ) ;
switch ( Integer . parseInt ( contion ) ) {
case 10 :
harmonicHistoryData = HistoryDataMapper . getDataFluc ( historyParam ) ;
//相电压有效值
if ( type = = 0 ) {
harmonicHistoryData = HistoryDataMapper . getDataV ( historyParam ) ;
} else {
harmonicHistoryData = ztHarmonicHistoryV ( historyParam ) ;
}
break ;
case 11 :
//线电压有效值
@@ -708,12 +728,12 @@ public class OracleResultServiceImpl implements OracleResultService {
harmonicHistoryData = HistoryDataMapper . getDataHarmphasic_i ( historyParam , number ) ;
break ;
case 46 :
//间谐波电压含有率
//todo 间谐波电压含有率
harmonicHistoryData = HistoryDataMapper . getDataInharmrateV_v ( historyParam , number ) ;
break ;
case 47 :
//间谐波电流含有率
//todo 间谐波电流含有率
harmonicHistoryData = HistoryDataMapper . getDataInharmrateI_i ( historyParam , number ) ;
break ;
case 48 :
//间谐波电压幅值
@@ -725,11 +745,19 @@ public class OracleResultServiceImpl implements OracleResultService {
break ;
case 50 :
//谐波有功功率
harmonicHistoryData = HistoryDataMapper . getDataHarmpowerP_p ( historyParam , number ) ;
if ( type = = 0 ) {
harmonicHistoryData = HistoryDataMapper . getDataHarmpowerP_p ( historyParam , number ) ;
} else {
harmonicHistoryData = ztHarmonicHistoryP ( historyParam , 1 ) ;
}
break ;
case 51 :
//谐波无功功率
harmonicHistoryData = HistoryDataMapper . getDataHarmpowerQ_q ( historyParam , number ) ;
if ( type = = 0 ) {
harmonicHistoryData = HistoryDataMapper . getDataHarmpowerQ_q ( historyParam , number ) ;
} else {
harmonicHistoryData = ztHarmonicHistoryP ( historyParam , 0 ) ;
}
break ;
case 52 :
//谐波视在功率
@@ -761,7 +789,11 @@ public class OracleResultServiceImpl implements OracleResultService {
break ;
case 59 :
//视在功率因数
harmonicHistoryData = HistoryDataMapper . getDataHarmpowerP_pf ( historyParam ) ;
if ( type = = 0 ) {
harmonicHistoryData = HistoryDataMapper . getDataHarmpowerP_pf ( historyParam ) ;
} else {
harmonicHistoryData = ztHarmonicHistoryC ( historyParam ) ;
}
break ;
case 591 :
//位移功率因数
@@ -812,4 +844,407 @@ public class OracleResultServiceImpl implements OracleResultService {
}
return ding ;
}
//电压
private List < HarmonicHistoryData > ztHarmonicHistoryV ( HarmonicHistoryParam historyParam ) {
String id = historyParam . getLineId ( ) ;
String starTime = historyParam . getStartTime ( ) ;
String endTime = historyParam . getEndTime ( ) ;
String key = " 0e3bac160fd246f181ad4fd47da6929a " ;
String secret = " 383b4b2536234d84ac909cd605762061 " ;
String url = " http://8d051549520e423ab8dccf8b3d457c74.apigw.he-region-2.sgic.sgcc.com.cn/ast/ydxxcjxt/dws/get_e_mp_TGvol_zl_ds " ;
String apiId = " 46e61646481c0146e26ba79bb5c8fa05 " ;
String apiName = " 电能质量谐波监测系统_分布式光伏台区电压日数据_e_mp_TGvol_zl_时间 " ;
List < HarmonicHistoryV > harmonicHistory = adsDiList ( HarmonicHistoryV . class , id , starTime , endTime , key , secret , url , apiId , apiName ) ;
return ztDataV ( harmonicHistory ) ;
}
//1:有功 0:无功
private List < HarmonicHistoryData > ztHarmonicHistoryP ( HarmonicHistoryParam historyParam , Integer type ) {
String id = historyParam . getLineId ( ) ;
String starTime = historyParam . getStartTime ( ) ;
String endTime = historyParam . getEndTime ( ) ;
String key = " 0e3bac160fd246f181ad4fd47da6929a " ;
String secret = " 383b4b2536234d84ac909cd605762061 " ;
String url = " http://8d051549520e423ab8dccf8b3d457c74.apigw.he-region-2.sgic.sgcc.com.cn/ast/ydxxcjxt/dws/get_e_mp_TGpower_zl_ds " ;
String apiId = " 9db49fdc30dbc3bf6fa4f5cce141416c " ;
String apiName = " get_电能质量谐波监测系统_分布式光伏台区功率日数据_e_mp_TGpower_zl_时间 " ;
List < HarmonicHistoryP > harmonicHistory = adsDiList ( HarmonicHistoryP . class , id , starTime , endTime , key , secret , url , apiId , apiName ) ;
return ztDataP ( harmonicHistory , type ) ;
}
//功率因数
private List < HarmonicHistoryData > ztHarmonicHistoryC ( HarmonicHistoryParam historyParam ) {
String id = historyParam . getLineId ( ) ;
String starTime = historyParam . getStartTime ( ) ;
String endTime = historyParam . getEndTime ( ) ;
String key = " 0e3bac160fd246f181ad4fd47da6929a " ;
String secret = " 383b4b2536234d84ac909cd605762061 " ;
String url = " http://8d051549520e423ab8dccf8b3d457c74.apigw.he-region-2.sgic.sgcc.com.cn/ast/ydxxcjxt/dws/get_e_mp_TGfactor_zl_ds " ;
String apiId = " 9c3ebd9c19dc0eb8e24385e40bd50a53 " ;
String apiName = " get_电能质量谐波监测系统_分布式光伏台区功率因数日数据_e_mp_TGfactor_zl_时间 " ;
List < HarmonicHistoryC > harmonicHistory = adsDiList ( HarmonicHistoryC . class , id , starTime , endTime , key , secret , url , apiId , apiName ) ;
return ztDataC ( harmonicHistory ) ;
}
/**
* @Description: 河北华云中台远程访问信息
* @return: java.util.List<com.njcn.harmonic.pojo.po.HarmonicHistory>
* @Author: wr
* @Date: 2024/1/15 10:20
*/
private < T > List < T > adsDiList ( Class < T > t , String id , String starTime , String endTime , String key , String secret , String url , String apiId , String apiName ) {
List < T > aas = new ArrayList < > ( ) ;
Request request = new Request ( ) ;
CloseableHttpClient client = null ;
try {
request . setKey ( key ) ;
request . setSecret ( secret ) ;
//接口访问类型
request . setMethod ( " GET " ) ;
//接口访问url
request . setUrl ( url ) ;
//API中 header头传输的参数
request . addHeader ( " x-api-id " , apiId ) ;
//API中 Query传输的参数
request . addQueryStringParam ( " tg_id " , id ) ;
request . addQueryStringParam ( " startTime " , starTime ) ;
request . addQueryStringParam ( " endTime " , starTime ) ;
//API中 Body体参数
//request.setBody("demo");
} catch ( Exception e ) {
log . error ( Thread . currentThread ( ) . getName ( ) + " 链接 " + apiName + " 失败 " ) ;
e . printStackTrace ( ) ;
}
try {
HttpRequestBase signedRequest = Client . sign ( request ) ;
Header [ ] authorization = signedRequest . getHeaders ( " Authorization " ) ;
signedRequest . addHeader ( " x-Authorization " , authorization [ 0 ] . getValue ( ) ) ;
//Send the request.
client = HttpClients . custom ( ) . build ( ) ;
HttpResponse response = client . execute ( signedRequest ) ;
//Print the status line of the response.
log . info ( response . getStatusLine ( ) . toString ( ) ) ;
//Print the header fields of the response.
Header [ ] resHeaders = response . getAllHeaders ( ) ;
for ( Header h : resHeaders ) {
log . info ( h . getName ( ) + " : " + h . getValue ( ) ) ;
}
//Print the body of the response.
HttpEntity resEntity = response . getEntity ( ) ;
if ( resEntity ! = null ) {
String s = EntityUtils . toString ( resEntity , " UTF-8 " ) ;
log . info ( System . getProperty ( " line.separator " ) + s ) ;
JSONObject jsonObject = JSON . parseObject ( s ) ;
String errCode = jsonObject . getString ( " errCode " ) ;
if ( StrUtil . isBlank ( errCode ) ) {
Map data = jsonObject . getObject ( " data " , Map . class ) ;
aas = JSONArray . parseArray ( data . get ( " data " ) . toString ( ) , t ) ;
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 + " 失败 " ) ;
e . printStackTrace ( ) ;
} finally {
try {
if ( client ! = null ) {
client . close ( ) ;
}
} catch ( IOException e ) {
e . printStackTrace ( ) ;
}
}
return aas ;
}
/**
* @Description: 中台电压信息格式转换
* @param value
* @return: java.util.List<com.njcn.influx.pojo.bo.HarmonicHistoryData>
* @Author: wr
* @Date: 2024/1/22 15:25
*/
private List < HarmonicHistoryData > ztDataV ( List < HarmonicHistoryV > value ) {
List < HarmonicHistoryData > info = new ArrayList < > ( ) ;
HarmonicHistoryData d ;
//a
List < HarmonicHistoryV > a = value . stream ( ) . filter ( x - > x . getPhase_flag ( ) = = 1 ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
//b
List < HarmonicHistoryV > b = value . stream ( ) . filter ( x - > x . getPhase_flag ( ) = = 2 ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
//c
List < HarmonicHistoryV > c = value . stream ( ) . filter ( x - > x . getPhase_flag ( ) = = 3 ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
Integer num = 97 ;
//15分钟增加信息
Duration duration = Duration . ofMinutes ( 15 ) ;
//初始化是从0点开始, 23:45结束
//A相
if ( CollUtil . isNotEmpty ( a ) ) {
for ( HarmonicHistoryV harmonicHistoryV : a ) {
String ds = harmonicHistoryV . getDs ( ) ;
LocalDateTime parse = LocalDateTimeUtil . parse ( ds , DatePattern . PURE_DATE_PATTERN ) ;
for ( Integer i = 1 ; i < num ; i + + ) {
//A相
d = new HarmonicHistoryData ( ) ;
if ( i > 1 ) {
parse = parse . plus ( duration ) ;
}
d . setTimeId ( parse . toInstant ( ZoneOffset . UTC ) ) ;
d . setPhasicType ( " A " ) ;
d . setAValue ( reflectDataV ( harmonicHistoryV , " u " + i ) ) ;
info . add ( d ) ;
}
}
}
//B相
if ( CollUtil . isNotEmpty ( b ) ) {
for ( HarmonicHistoryV harmonicHistoryV : b ) {
String ds = harmonicHistoryV . getDs ( ) ;
LocalDateTime parse = LocalDateTimeUtil . parse ( ds , DatePattern . PURE_DATE_PATTERN ) ;
for ( Integer i = 1 ; i < num ; i + + ) {
d = new HarmonicHistoryData ( ) ;
if ( i > 1 ) {
parse = parse . plus ( duration ) ;
}
d . setTimeId ( parse . toInstant ( ZoneOffset . UTC ) ) ;
d . setPhasicType ( " B " ) ;
d . setAValue ( reflectDataV ( harmonicHistoryV , " u " + i ) ) ;
info . add ( d ) ;
}
}
}
//C相
if ( CollUtil . isNotEmpty ( c ) ) {
for ( HarmonicHistoryV harmonicHistoryV : c ) {
String ds = harmonicHistoryV . getDs ( ) ;
LocalDateTime parse = LocalDateTimeUtil . parse ( ds , DatePattern . PURE_DATE_PATTERN ) ;
for ( Integer i = 1 ; i < num ; i + + ) {
d = new HarmonicHistoryData ( ) ;
if ( i > 1 ) {
parse = parse . plus ( duration ) ;
}
d . setTimeId ( parse . toInstant ( ZoneOffset . UTC ) ) ;
d . setPhasicType ( " C " ) ;
d . setAValue ( reflectDataV ( harmonicHistoryV , " u " + i ) ) ;
info . add ( d ) ;
}
}
}
return info ;
}
private static Float reflectDataV ( HarmonicHistoryV dateV , String attribute ) {
Field field ;
try {
field = dateV . getClass ( ) . getDeclaredField ( attribute ) ;
field . setAccessible ( true ) ;
Float aFloat = ( Float ) field . get ( dateV ) ;
if ( ObjectUtil . isNotNull ( aFloat ) ) {
return aFloat ;
}
} catch ( NoSuchFieldException | IllegalAccessException e ) {
throw new RuntimeException ( e ) ;
}
return 0 . 0F ;
}
/**
* 中台功率信息格式转换
* @param value
* @param type
* @return
*/
private List < HarmonicHistoryData > ztDataP ( List < HarmonicHistoryP > value , Integer type ) {
List < HarmonicHistoryData > info = new ArrayList < > ( ) ;
HarmonicHistoryData d ;
//a
List < HarmonicHistoryP > a ;
//b
List < HarmonicHistoryP > b ;
//c
List < HarmonicHistoryP > c ;
//1:有功 0:无功
if ( type = = 1 ) {
a = value . stream ( ) . filter ( x - > x . getData_type ( ) = = 2 ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
b = value . stream ( ) . filter ( x - > x . getData_type ( ) = = 3 ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
c = value . stream ( ) . filter ( x - > x . getData_type ( ) = = 4 ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
} else {
a = value . stream ( ) . filter ( x - > x . getData_type ( ) = = 6 ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
b = value . stream ( ) . filter ( x - > x . getData_type ( ) = = 7 ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
c = value . stream ( ) . filter ( x - > x . getData_type ( ) = = 8 ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
}
Integer num = 97 ;
//15分钟增加信息
Duration duration = Duration . ofMinutes ( 15 ) ;
//初始化是从0点开始, 23:45结束
//A相
if ( CollUtil . isNotEmpty ( a ) ) {
for ( HarmonicHistoryP harmonicHistoryP : a ) {
String ds = harmonicHistoryP . getDs ( ) ;
LocalDateTime parse = LocalDateTimeUtil . parse ( ds , DatePattern . PURE_DATE_PATTERN ) ;
for ( Integer i = 1 ; i < num ; i + + ) {
//A相
d = new HarmonicHistoryData ( ) ;
if ( i > 1 ) {
parse = parse . plus ( duration ) ;
}
d . setTimeId ( parse . toInstant ( ZoneOffset . UTC ) ) ;
d . setPhasicType ( " A " ) ;
d . setAValue ( reflectDataP ( harmonicHistoryP , " u " + i ) ) ;
info . add ( d ) ;
}
}
}
//B相
if ( CollUtil . isNotEmpty ( b ) ) {
for ( HarmonicHistoryP harmonicHistoryP : b ) {
String ds = harmonicHistoryP . getDs ( ) ;
LocalDateTime parse = LocalDateTimeUtil . parse ( ds , DatePattern . PURE_DATE_PATTERN ) ;
for ( Integer i = 1 ; i < num ; i + + ) {
d = new HarmonicHistoryData ( ) ;
if ( i > 1 ) {
parse = parse . plus ( duration ) ;
}
d . setTimeId ( parse . toInstant ( ZoneOffset . UTC ) ) ;
d . setPhasicType ( " B " ) ;
d . setAValue ( reflectDataP ( harmonicHistoryP , " u " + i ) ) ;
info . add ( d ) ;
}
}
}
//C相
if ( CollUtil . isNotEmpty ( c ) ) {
for ( HarmonicHistoryP harmonicHistoryP : c ) {
String ds = harmonicHistoryP . getDs ( ) ;
LocalDateTime parse = LocalDateTimeUtil . parse ( ds , DatePattern . PURE_DATE_PATTERN ) ;
for ( Integer i = 1 ; i < num ; i + + ) {
d = new HarmonicHistoryData ( ) ;
if ( i > 1 ) {
parse = parse . plus ( duration ) ;
}
d . setTimeId ( parse . toInstant ( ZoneOffset . UTC ) ) ;
d . setPhasicType ( " C " ) ;
d . setAValue ( reflectDataP ( harmonicHistoryP , " u " + i ) ) ;
info . add ( d ) ;
}
}
}
return info ;
}
private static Float reflectDataP ( HarmonicHistoryP dateP , String attribute ) {
Field field ;
try {
field = dateP . getClass ( ) . getDeclaredField ( attribute ) ;
field . setAccessible ( true ) ;
Float aFloat = ( Float ) field . get ( dateP ) ;
if ( ObjectUtil . isNotNull ( aFloat ) ) {
return aFloat ;
}
} catch ( NoSuchFieldException | IllegalAccessException e ) {
throw new RuntimeException ( e ) ;
}
return 0 . 0F ;
}
/**
* 中台功率因数信息格式转换
* @param value
* @return
*/
private List < HarmonicHistoryData > ztDataC ( List < HarmonicHistoryC > value ) {
List < HarmonicHistoryData > info = new ArrayList < > ( ) ;
HarmonicHistoryData d ;
//a
List < HarmonicHistoryC > a = value . stream ( ) . filter ( x - > x . getPhase_flag ( ) = = 1 ) . collect ( Collectors . toList ( ) ) ;
//b
List < HarmonicHistoryC > b = value . stream ( ) . filter ( x - > x . getPhase_flag ( ) = = 2 ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
//c
List < HarmonicHistoryC > c = value . stream ( ) . filter ( x - > x . getPhase_flag ( ) = = 3 ) . distinct ( ) . collect ( Collectors . toList ( ) ) ;
Integer num = 97 ;
//15分钟增加信息
Duration duration = Duration . ofMinutes ( 15 ) ;
//初始化是从0点开始, 23:45结束
//A相
if ( CollUtil . isNotEmpty ( a ) ) {
for ( HarmonicHistoryC harmonicHistoryC : a ) {
String ds = harmonicHistoryC . getDs ( ) ;
LocalDateTime parse = LocalDateTimeUtil . parse ( ds , DatePattern . PURE_DATE_PATTERN ) ;
for ( Integer i = 1 ; i < num ; i + + ) {
//A相
d = new HarmonicHistoryData ( ) ;
if ( i > 1 ) {
parse = parse . plus ( duration ) ;
}
d . setTimeId ( parse . toInstant ( ZoneOffset . UTC ) ) ;
d . setPhasicType ( " A " ) ;
d . setAValue ( reflectDataC ( harmonicHistoryC , " u " + i ) ) ;
info . add ( d ) ;
}
}
}
//B相
if ( CollUtil . isNotEmpty ( b ) ) {
for ( HarmonicHistoryC harmonicHistoryC : b ) {
String ds = harmonicHistoryC . getDs ( ) ;
LocalDateTime parse = LocalDateTimeUtil . parse ( ds , DatePattern . PURE_DATE_PATTERN ) ;
for ( Integer i = 1 ; i < num ; i + + ) {
d = new HarmonicHistoryData ( ) ;
if ( i > 1 ) {
parse = parse . plus ( duration ) ;
}
d . setTimeId ( parse . toInstant ( ZoneOffset . UTC ) ) ;
d . setPhasicType ( " B " ) ;
d . setAValue ( reflectDataC ( harmonicHistoryC , " u " + i ) ) ;
info . add ( d ) ;
}
}
}
//C相
if ( CollUtil . isNotEmpty ( c ) ) {
for ( HarmonicHistoryC harmonicHistoryC : c ) {
String ds = harmonicHistoryC . getDs ( ) ;
LocalDateTime parse = LocalDateTimeUtil . parse ( ds , DatePattern . PURE_DATE_PATTERN ) ;
for ( Integer i = 1 ; i < num ; i + + ) {
d = new HarmonicHistoryData ( ) ;
if ( i > 1 ) {
parse = parse . plus ( duration ) ;
}
d . setTimeId ( parse . toInstant ( ZoneOffset . UTC ) ) ;
d . setPhasicType ( " C " ) ;
d . setAValue ( reflectDataC ( harmonicHistoryC , " u " + i ) ) ;
info . add ( d ) ;
}
}
}
return info ;
}
private static Float reflectDataC ( HarmonicHistoryC dateC , String attribute ) {
Field field ;
try {
field = dateC . getClass ( ) . getDeclaredField ( attribute ) ;
field . setAccessible ( true ) ;
Float aFloat = ( Float ) field . get ( dateC ) ;
if ( ObjectUtil . isNotNull ( aFloat ) ) {
return aFloat ;
}
} catch ( NoSuchFieldException | IllegalAccessException e ) {
throw new RuntimeException ( e ) ;
}
return 0 . 0F ;
}
}