@ -67,6 +67,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime ;
import java.time.LocalTime ;
import java.time.YearMonth ;
import java.time.ZoneId ;
import java.time.format.DateTimeFormatter ;
import java.time.temporal.ChronoUnit ;
import java.util.ArrayDeque ;
@ -131,6 +132,18 @@ public class DeviceDataProcessServiceImpl extends AbstractBatteryDataProcessor i
private static final String AUTO_HOUR_DIFF_CONTEXT_PREFIX = " __AUTO_HOUR_DIFF__ " ;
private static final String MONITOR_FIELD_PREFIX_HOME = " home__ " ;
private static final String MONITOR_FIELD_PREFIX_TJBB_DBBB = " tjbb_dbbb__ " ;
private static final String FIELD_CODE_TOTAL_CHARGE = " home__totalChargedCap " ;
private static final String FIELD_CODE_TOTAL_DISCHARGE = " home__totalDischargedCap " ;
private static final String FIELD_CODE_DAY_CHARGE = " home__dayChargedCap " ;
private static final String FIELD_CODE_DAY_DISCHARGE = " home__dayDisChargedCap " ;
private static final String FIELD_CODE_PEAK_CHARGE = " tjbb_dbbb__activePeakKwh " ;
private static final String FIELD_CODE_PEAK_DISCHARGE = " tjbb_dbbb__reActivePeakKwh " ;
private static final String FIELD_CODE_HIGH_CHARGE = " tjbb_dbbb__activeHighKwh " ;
private static final String FIELD_CODE_HIGH_DISCHARGE = " tjbb_dbbb__reActiveHighKwh " ;
private static final String FIELD_CODE_FLAT_CHARGE = " tjbb_dbbb__activeFlatKwh " ;
private static final String FIELD_CODE_FLAT_DISCHARGE = " tjbb_dbbb__reActiveFlatKwh " ;
private static final String FIELD_CODE_VALLEY_CHARGE = " tjbb_dbbb__activeValleyKwh " ;
private static final String FIELD_CODE_VALLEY_DISCHARGE = " tjbb_dbbb__reActiveValleyKwh " ;
private static final String [ ] FIELD_SUFFIX_TOTAL_CHARGE = {
" activeTotalKwh " , " totalChargeData " , " totalCharge " , " totalChargedCap " , " chargedCap "
} ;
@ -401,8 +414,8 @@ public class DeviceDataProcessServiceImpl extends AbstractBatteryDataProcessor i
dayChargePointId ,
dayDischargeMatch = = null ? " null " : StringUtils . defaultString ( dayDischargeMatch . getFieldCode ( ) ) ,
dayDischargePointId ) ;
BigDecimal nowTotalCharge = getPointValueById ( normalizedPointValueMap , totalChargePointId ) ;
BigDecimal nowTotalDischarge = getPointValueById ( normalizedPointValueMap , totalDischargePointId ) ;
BigDecimal nowTotalCharge = getPointValueByIdRaw ( normalizedPointValueMap , totalChargePointId ) ;
BigDecimal nowTotalDischarge = getPointValueByIdRaw ( normalizedPointValueMap , totalDischargePointId ) ;
BigDecimal nowDayCharge = getLatestPointValueFromRedis ( dayChargePointId ) ;
BigDecimal nowDayDischarge = getLatestPointValueFromRedis ( dayDischargePointId ) ;
if ( nowTotalCharge = = null | | nowTotalDischarge = = null ) {
@ -476,75 +489,109 @@ public class DeviceDataProcessServiceImpl extends AbstractBatteryDataProcessor i
Date queryEndTime = DateUtils . getNowDate ( ) ;
Date queryStartTime = new Date ( queryEndTime . getTime ( ) - DAILY_CHARGE_INFLUX_QUERY_WINDOW_MS ) ;
EmsSiteMonitorPointMatch totalChargeMatch = firstNonBlankMatch ByFieldSuffix IgnoreDevice(
mappingList , FIELD_SUFFIX _TOTAL_CHARGE
) ;
EmsSiteMonitorPointMatch total DischargeMatch = firstNonBlankMatch ByFieldSuffix IgnoreDevice(
mappingList , FIELD_SUFFIX_TOTAL_DISCHARGE
) ;
String totalChargePointId = totalChargeMatch = = null ? null : StringUtils . trimToNull ( totalChargeMatch . getDataPoint ( ) ) ;
String totalDischargePointId = totalDischargeMatch = = null ? null : StringUtils . trimToNull ( totalDischargeMatch . getData Point( ) ) ;
log . info ( " Quartz同步日充放电自检, siteId: {}, totalCharge: {}->{} , totalDischarge: {}->{} " ,
String totalChargePointId = resolvePointId ByFieldCode IgnoreDevice( mappingList , FIELD_CODE_TOTAL_CHARGE ) ;
String totalDischargePointId = resolvePointIdByFieldCodeIgnoreDevice ( mappingList , FIELD_CODE _TOTAL_DIS CHARGE ) ;
String dayChargePointId = resolvePointIdByFieldCodeIgnoreDevice ( mappingList , FIELD_CODE_DAY_CHARGE ) ;
String day DischargePointId = resolvePointId ByFieldCode IgnoreDevice( mappingList , FIELD_CODE_DAY_DISCHARGE ) ;
if ( StringUtils . isBlank ( dayChargePointId ) ) {
dayChargePointId = firstNonBlankPointByFieldSuffixIgnoreDevice ( mappingList , FIELD_SUFFIX_DAY_CHARGE ) ;
}
if ( StringUtils . isBlank ( dayDischarge PointId ) ) {
dayDischargePointId = firstNonBlankPointByFieldSuffixIgnoreDevice ( mappingList , FIELD_SUFFIX_DAY_DISCHARGE ) ;
}
log . info ( " Quartz同步日充放电日累自检, siteId: {}, dayChargePoint: {}, dayDischargePoint: {} " ,
siteId ,
dayChargePointId ,
dayDischargePointId ) ;
String peakChargePointId = resolvePointIdByFieldCodeIgnoreDevice ( mappingList , FIELD_CODE_PEAK_CHARGE ) ;
String peakDischargePointId = resolvePointIdByFieldCodeIgnoreDevice ( mappingList , FIELD_CODE_PEAK_DISCHARGE ) ;
String highChargePointId = resolvePointIdByFieldCodeIgnoreDevice ( mappingList , FIELD_CODE_HIGH_CHARGE ) ;
String highDischargePointId = resolvePointIdByFieldCodeIgnoreDevice ( mappingList , FIELD_CODE_HIGH_DISCHARGE ) ;
String flatChargePointId = resolvePointIdByFieldCodeIgnoreDevice ( mappingList , FIELD_CODE_FLAT_CHARGE ) ;
String flatDischargePointId = resolvePointIdByFieldCodeIgnoreDevice ( mappingList , FIELD_CODE_FLAT_DISCHARGE ) ;
String valleyChargePointId = resolvePointIdByFieldCodeIgnoreDevice ( mappingList , FIELD_CODE_VALLEY_CHARGE ) ;
String valleyDischargePointId = resolvePointIdByFieldCodeIgnoreDevice ( mappingList , FIELD_CODE_VALLEY_DISCHARGE ) ;
log . info ( " Quartz同步日充放电自检, siteId: {}, totalCharge: {} , totalDischarge: {}, dayCharge: {}, dayDischarge: {}, peak: {} / {}, high: {} / {}, flat: {} / {}, valley: {} / {} " ,
siteId ,
totalChargeMatch = = null ? " null " : StringUtils . defaultString ( totalChargeMatch . getFieldCode ( ) ) ,
totalChargePointId ,
totalDischargeMatch = = null ? " null " : StringUtils . defaultString ( totalDischargeMatch . getFieldCode ( ) ) ,
totalDisc hargePointId) ;
if ( StringUtils . isBlank ( totalChargePointId ) & & StringUtils . isBlank ( total DischargePointId ) ) {
log . info ( " Quartz同步日充放电跳过, 未找到总充/总放点位, siteId: {} " , siteId ) ;
return ;
}
totalDischargePointId ,
dayC hargePointId,
day DischargePointId ,
peakChargePointId ,
peakDischargePointId ,
highChargePointId ,
highDischargePointId ,
flatChargePointId ,
flatDischargePointId ,
valleyChargePointId ,
valleyDischargePointId ) ;
Map < String , BigDecimal > p ointId ValueMap = new HashMap < > ( ) ;
Date d ataUpd ate Time = null ;
i f ( StringUtils . isNotBlank ( totalChargeP ointId ) ) {
InfluxPointDataWriter . PointValue totalChargePoint = influxPointDataWriter . queryLatestPointValueBy PointKey (
siteId , totalChargePointId , queryStartTime , queryEndTime
) ;
if ( totalChargePoint ! = null & & totalChargePoint . getPointValue ( ) ! = null ) {
pointIdValueMap . put ( totalChargePointId . trim ( ) . toUpperCase ( ) , totalChargePoint . getPointValue ( ) ) ;
dataUpdateTime = totalChargePoint . getDataTime ( ) ;
} else {
log . info ( " Quartz同步日充放电未获取到总充点最新值, siteId: {}, pointId: {}, range: {} ~ {} " ,
siteId , totalChargePointId ,
DateUtils . parseDateToStr ( DateUtils . YYYY_MM_DD_HH_MM_SS , queryStartTime ) ,
DateUtils . parseDateToStr ( DateUtils . YYYY_MM_DD_HH_MM_SS , queryEndTime ) ) ;
Map < String , LatestPointValue > latestP ointValues = new HashMap < > ( ) ;
Date l atestD ata Time = null ;
for ( String p ointId : Arrays . asList (
totalChargePointId , totalDischarge PointId ,
dayChargePointId , dayDischargePointId ,
peakChargePointId , peakDischargePointId ,
highChargePointId , highDischargePointId ,
flatChargePointId , flatDischargePointId ,
valleyChargePointId , valleyDischargePointId ) ) {
if ( StringUtils . isBlank ( pointId ) ) {
continue ;
}
}
if ( StringUtils . isNotBlank ( totalDischargePointId ) ) {
InfluxPointDataWriter . PointValue totalDischargePoint = influxPointDataWriter . queryLatestPointValueByPointKey (
siteId , totalDischargePointId , queryStartTime , queryEndTime
) ;
if ( totalDischargePoint ! = null & & totalDischargePoint . getPointValu e( ) ! = null ) {
pointIdValueMap . put ( totalDischargePointId . tr im ( ) . toUpperCase ( ) , totalDischargePoint . getPointValu e( ) ) ;
if ( dataUpd ate Time = = null
| | ( totalDischargePoint . getDataTime ( ) ! = null
& & totalDischargePoint . getDataTime ( ) . after ( dataUpdateTime ) ) ) {
dataUpdateTime = totalDischargePoint . getDataTime ( ) ;
}
} else {
log . info ( " Quartz同步日充放电未获取到总放点最新值, siteId: {}, pointId: {}, range: {} ~ {} " ,
siteId , totalDischargePointId ,
DateUtils . parseDateToStr ( DateUtils . YYYY_MM_DD_HH_MM_SS , queryStartTime ) ,
DateUtils . parseDateToStr ( DateUtils . YYYY_MM_DD_HH_MM_SS , queryEndTime ) ) ;
LatestPointValue latestPointValue = getLatestPointValuePreferRedis ( siteId , pointId , queryStartTime , queryEndTime ) ;
if ( latestPointValue = = null | | latestPointValue . getValue ( ) = = null ) {
continue ;
}
latestPointValues . put ( pointId . trim ( ) . toUpperCase ( ) , latestPointValue ) ;
if ( latestPointValue . getDataTim e( ) ! = null
& & ( latestDataTime = = null | | latestPointValue . getDataT ime ( ) . after ( latestDataTim e) ) ) {
latestD ata Time = latestPointValue . getDataTime ( ) ;
}
}
if ( org . apache . commons . collections4 . MapUtils . isEmpty ( pointIdValueMap ) ) {
if ( latestPointValues . isEmpty ( ) ) {
log . info ( " Quartz同步日充放电跳过, 点位最新值为空, siteId: {} " , siteId ) ;
return ;
}
if ( dataUpdateTime = = null ) {
log . info ( " Quartz同步日充放电点位值存在但时间为空, siteId: {}, pointIds: {} " ,
siteId , p ointId ValueMap . keySet ( ) ) ;
Date recordDateTime = latestDataTime = = null ? DateUtils . getNowDate ( ) : latestDataTime ;
BigDecimal totalChargeValue = getPointValueById ( latestP ointValues , totalChargePointId ) ;
BigDecimal totalDischargeValue = getPointValueById ( latestPointValues , totalDischargePointId ) ;
BigDecimal dayChargeValue = getPointValueById ( latestPointValues , dayChargePointId ) ;
BigDecimal dayDischargeValue = getPointValueById ( latestPointValues , dayDischargePointId ) ;
log . info ( " 单站点位值汇总, siteId: {}, totalCharge: {}({}), totalDischarge: {}({}), dayCharge: {}({}), dayDischarge: {}({}), dataTime: {} " ,
siteId ,
totalChargeValue ,
totalDischargeValue ,
dayChargeValue ,
dayDischargeValue ,
pointValueSource ( latestPointValues , totalChargePointId ) ,
pointValueSource ( latestPointValues , totalDischargePointId ) ,
pointValueSource ( latestPointValues , dayChargePointId ) ,
pointValueSource ( latestPointValues , dayDischargePointId ) ,
DateUtils . parseDateToStr ( DateUtils . YYYY_MM_DD_HH_MM_SS , recordDateTime ) ) ;
if ( totalChargeValue = = null & & totalDischargeValue = = null ) {
log . info ( " Quartz同步日充放电跳过, 总充/总放值为空, siteId: {} " , siteId ) ;
} else {
log . info ( " Quartz同步日充放电准备落库, siteId: {}, dataUpdateTime: {}, pointIds: {} " ,
siteId , DateUtils . parseDateToStr ( DateUtils . YYYY_MM_DD_HH_MM_SS , dataUpdateTime ) ,
pointIdValueMap . keySet ( ) ) ;
upsertDailyChargeData ( siteId , recordDateTime , totalChargeValue , totalDischargeValue , dayChargeValue , dayDischargeValue ) ;
}
updateDailyChargeDataByQuartz ( siteId , pointIdValueMap , dataUpdateTime ) ;
updateDailyEnergyHourlyDataByQuartz ( siteId , dataUpdateTime ) ;
syncDailyChargeRevenueByQuartz ( siteId , dataUpdateTime ) ;
updateDailyEnergyHourlyDataByQuartz (
siteId ,
recordDateTime ,
peakChargePointId ,
peakDischargePointId ,
highChargePointId ,
highDischargePointId ,
flatChargePointId ,
flatDischargePointId ,
valleyChargePointId ,
valleyDischargePointId ,
queryStartTime ,
queryEndTime
) ;
syncDailyChargeRevenueByQuartz ( siteId , recordDateTime ) ;
}
private void syncDailyChargeRevenueByQuartz ( String siteId , Date dataUpdateTime ) {
@ -576,7 +623,18 @@ public class DeviceDataProcessServiceImpl extends AbstractBatteryDataProcessor i
siteId , day , dayRevenue , totalRevenue ) ;
}
private void updateDailyEnergyHourlyDataByQuartz ( String siteId , Date dataUpdateTime ) {
private void updateDailyEnergyHourlyDataByQuartz ( String siteId ,
Date dataUpdateTime ,
String peakChargePointId ,
String peakDischargePointId ,
String highChargePointId ,
String highDischargePointId ,
String flatChargePointId ,
String flatDischargePointId ,
String valleyChargePointId ,
String valleyDischargePointId ,
Date queryStartTime ,
Date queryEndTime ) {
log . info ( " Quartz日电量小时落库入口, siteId: {}, dataTime: {} " ,
siteId ,
dataUpdateTime = = null ? " null " : DateUtils . parseDateToStr ( DateUtils . YYYY_MM_DD_HH_MM_SS , dataUpdateTime ) ) ;
@ -584,15 +642,12 @@ public class DeviceDataProcessServiceImpl extends AbstractBatteryDataProcessor i
return ;
}
List < EmsSiteMonitorPointMatch > mappingList = getPointMatchesBySiteId ( siteId ) ;
if ( CollectionUtils . isEmpty ( mappingList ) ) {
return ;
}
Date recordDateTime = dataUpdateTime = = null ? DateUtils . getNowDate ( ) : dataUpdateTime ;
Integer dataHour = resolveHourOfDay ( recordDateTime ) ;
String priceKey = RedisKeyConstants . ENERGY_PRICE_TIME + siteId + " _ " + LocalDate . now ( ) . getYear ( ) + LocalDate . now ( ) . getMonthValue ( ) ;
LocalDateTime recordLocalTime = LocalDateTime . ofInstant ( recordDateTime . toInstant ( ) , ZoneId . systemDefault ( ) ) ;
String priceKey = RedisKeyConstants . ENERGY_PRICE_TIME + siteId + " _ " + recordLocalTime . getYear ( )
+ recordLocalTime . getMonthValue ( ) ;
EnergyPriceVo priceVo = redisCache . getCacheObject ( priceKey ) ;
if ( priceVo = = null ) {
priceVo = emsEnergyPriceConfigService . getCurrentMonthPrice ( siteId ) ;
@ -619,55 +674,15 @@ public class DeviceDataProcessServiceImpl extends AbstractBatteryDataProcessor i
return ;
}
EmsSiteMonitorPointMatch peakChargeMatch = firstNonBlankMatchByFieldSuffixIgnoreDevice (
mappingList , FIELD_SUFFIX_PEAK_CHARGE , MONITOR_FIELD_PREFIX_TJBB_DBBB
) ;
EmsSiteMonitorPointMatch peakDischargeMatch = firstNonBlankMatchByFieldSuffixIgnoreDevice (
mappingList , FIELD_SUFFIX_PEAK_DISCHARGE , MONITOR_FIELD_PREFIX_TJBB_DBBB
) ;
EmsSiteMonitorPointMatch highChargeMatch = firstNonBlankMatchByFieldSuffixIgnoreDevice (
mappingList , FIELD_SUFFIX_HIGH_CHARGE , MONITOR_FIELD_PREFIX_TJBB_DBBB
) ;
EmsSiteMonitorPointMatch highDischargeMatch = firstNonBlankMatchByFieldSuffixIgnoreDevice (
mappingList , FIELD_SUFFIX_HIGH_DISCHARGE , MONITOR_FIELD_PREFIX_TJBB_DBBB
) ;
EmsSiteMonitorPointMatch flatChargeMatch = firstNonBlankMatchByFieldSuffixIgnoreDevice (
mappingList , FIELD_SUFFIX_FLAT_CHARGE , MONITOR_FIELD_PREFIX_TJBB_DBBB
) ;
EmsSiteMonitorPointMatch flatDischargeMatch = firstNonBlankMatchByFieldSuffixIgnoreDevice (
mappingList , FIELD_SUFFIX_FLAT_DISCHARGE , MONITOR_FIELD_PREFIX_TJBB_DBBB
) ;
EmsSiteMonitorPointMatch valleyChargeMatch = firstNonBlankMatchByFieldSuffixIgnoreDevice (
mappingList , FIELD_SUFFIX_VALLEY_CHARGE , MONITOR_FIELD_PREFIX_TJBB_DBBB
) ;
EmsSiteMonitorPointMatch valleyDischargeMatch = firstNonBlankMatchByFieldSuffixIgnoreDevice (
mappingList , FIELD_SUFFIX_VALLEY_DISCHARGE , MONITOR_FIELD_PREFIX_TJBB_DBBB
) ;
String peakChargePointId = peakChargeMatch = = null ? null : StringUtils . trimToNull ( peakChargeMatch . getDataPoint ( ) ) ;
String peakDischargePointId = peakDischargeMatch = = null ? null : StringUtils . trimToNull ( peakDischargeMatch . getDataPoint ( ) ) ;
String highChargePointId = highChargeMatch = = null ? null : StringUtils . trimToNull ( highChargeMatch . getDataPoint ( ) ) ;
String highDischargePointId = highDischargeMatch = = null ? null : StringUtils . trimToNull ( highDischargeMatch . getDataPoint ( ) ) ;
String flatChargePointId = flatChargeMatch = = null ? null : StringUtils . trimToNull ( flatChargeMatch . getDataPoint ( ) ) ;
String flatDischargePointId = flatDischargeMatch = = null ? null : StringUtils . trimToNull ( flatDischargeMatch . getDataPoint ( ) ) ;
String valleyChargePointId = valleyChargeMatch = = null ? null : StringUtils . trimToNull ( valleyChargeMatch . getDataPoint ( ) ) ;
String valleyDischargePointId = valleyDischargeMatch = = null ? null : StringUtils . trimToNull ( valleyDischargeMatch . getDataPoint ( ) ) ;
log . info ( " Quartz日电量小时自检, siteId: {}, peak: {}->{} / {}->{} , high: {}->{} / {}->{} , flat: {}->{} / {}->{} , valley: {}->{} / {}->{} " ,
log . info ( " Quartz日电量小时自检, siteId: {}, peak: {} / {} , high: {} / {} , flat: {} / {} , valley: {} / {} " ,
siteId ,
peakChargeMatch = = null ? " null " : StringUtils . defaultString ( peakChargeMatch . getFieldCode ( ) ) ,
peakChargePointId ,
peakDischargeMatch = = null ? " null " : StringUtils . defaultString ( peakDischargeMatch . getFieldCode ( ) ) ,
peakDischargePointId ,
highChargeMatch = = null ? " null " : StringUtils . defaultString ( highChargeMatch . getFieldCode ( ) ) ,
highChargePointId ,
highDischargeMatch = = null ? " null " : StringUtils . defaultString ( highDischargeMatch . getFieldCode ( ) ) ,
highDischargePointId ,
flatChargeMatch = = null ? " null " : StringUtils . defaultString ( flatChargeMatch . getFieldCode ( ) ) ,
flatChargePointId ,
flatDischargeMatch = = null ? " null " : StringUtils . defaultString ( flatDischargeMatch . getFieldCode ( ) ) ,
flatDischargePointId ,
valleyChargeMatch = = null ? " null " : StringUtils . defaultString ( valleyChargeMatch . getFieldCode ( ) ) ,
valleyChargePointId ,
valleyDischargeMatch = = null ? " null " : StringUtils . defaultString ( valleyDischargeMatch . getFieldCode ( ) ) ,
valleyDischargePointId ) ;
String currentChargePointId ;
String currentDischargePointId ;
@ -677,26 +692,26 @@ public class DeviceDataProcessServiceImpl extends AbstractBatteryDataProcessor i
case " peak " :
currentChargePointId = peakChargePointId ;
currentDischargePointId = peakDischargePointId ;
currentCharge = getLatestPointValueFromRedis ( peakChargePointId ) ;
currentDischarge = getLatestPointValueFromRedis ( peakDischargePointId ) ;
currentCharge = getLatestPointValuePreferRedisValue ( siteId , peakChargePointId , queryStartTime , queryEndTime ) ;
currentDischarge = getLatestPointValuePreferRedisValue ( siteId , peakDischargePointId , queryStartTime , queryEndTime ) ;
break ;
case " high " :
currentChargePointId = highChargePointId ;
currentDischargePointId = highDischargePointId ;
currentCharge = getLatestPointValueFromRedis ( highChargePointId ) ;
currentDischarge = getLatestPointValueFromRedis ( highDischargePointId ) ;
currentCharge = getLatestPointValuePreferRedisValue ( siteId , highChargePointId , queryStartTime , queryEndTime ) ;
currentDischarge = getLatestPointValuePreferRedisValue ( siteId , highDischargePointId , queryStartTime , queryEndTime ) ;
break ;
case " flat " :
currentChargePointId = flatChargePointId ;
currentDischargePointId = flatDischargePointId ;
currentCharge = getLatestPointValueFromRedis ( flatChargePointId ) ;
currentDischarge = getLatestPointValueFromRedis ( flatDischargePointId ) ;
currentCharge = getLatestPointValuePreferRedisValue ( siteId , flatChargePointId , queryStartTime , queryEndTime ) ;
currentDischarge = getLatestPointValuePreferRedisValue ( siteId , flatDischargePointId , queryStartTime , queryEndTime ) ;
break ;
case " valley " :
currentChargePointId = valleyChargePointId ;
currentDischargePointId = valleyDischargePointId ;
currentCharge = getLatestPointValueFromRedis ( valleyChargePointId ) ;
currentDischarge = getLatestPointValueFromRedis ( valleyDischargePointId ) ;
currentCharge = getLatestPointValuePreferRedisValue ( siteId , valleyChargePointId , queryStartTime , queryEndTime ) ;
currentDischarge = getLatestPointValuePreferRedisValue ( siteId , valleyDischargePointId , queryStartTime , queryEndTime ) ;
break ;
default :
log . info ( " Quartz日电量小时落库跳过, 未知电价时段类型, siteId: {}, costType: {} " , siteId , costType ) ;
@ -751,9 +766,17 @@ public class DeviceDataProcessServiceImpl extends AbstractBatteryDataProcessor i
return false ;
}
try {
String normalizedStartTime = startTime . trim ( ) ;
String normalizedEndTime = endTime . trim ( ) ;
LocalTime current = LocalTime . parse ( DateUtils . parseDateToStr ( " HH:mm " , dataUpdateTime ) ) ;
LocalTime start = LocalTime . parse ( s tartTime) ;
LocalTime end = LocalTime . parse ( endTime ) ;
LocalTime start = LocalTime . parse ( normalizedS tartTime) ;
// 兼容配置中的 24:00, 将其视为次日 00:00。
if ( " 24:00 " . equals ( normalizedEndTime ) | | " 24:00:00 " . equals ( normalizedEndTime ) ) {
return ! current . isBefore ( start ) ;
}
LocalTime end = LocalTime . parse ( normalizedEndTime ) ;
if ( start . equals ( end ) ) {
return true ;
}
@ -997,18 +1020,38 @@ public class DeviceDataProcessServiceImpl extends AbstractBatteryDataProcessor i
return parsed = = null ? new LinkedHashMap < > ( ) : new LinkedHashMap < > ( parsed ) ;
}
private BigDecimal getPointValueById ( Map < String , BigDecimal > pointIdValueMap , String pointId ) {
private BigDecimal getPointValueById ( Map < String , LatestPointValue > pointIdValueMap , String pointId ) {
if ( pointIdValueMap = = null | | pointIdValueMap . isEmpty ( ) | | StringUtils . isBlank ( pointId ) ) {
return null ;
}
LatestPointValue latestPointValue = pointIdValueMap . get ( pointId . trim ( ) . toUpperCase ( ) ) ;
return latestPointValue = = null ? null : latestPointValue . getValue ( ) ;
}
private BigDecimal getPointValueByIdRaw ( Map < String , BigDecimal > pointIdValueMap , String pointId ) {
if ( pointIdValueMap = = null | | pointIdValueMap . isEmpty ( ) | | StringUtils . isBlank ( pointId ) ) {
return null ;
}
return pointIdValueMap . get ( pointId . trim ( ) . toUpperCase ( ) ) ;
}
private String pointValueSource ( Map < String , LatestPointValue > pointIdValueMap , String pointId ) {
if ( pointIdValueMap = = null | | pointIdValueMap . isEmpty ( ) | | StringUtils . isBlank ( pointId ) ) {
return " - " ;
}
LatestPointValue latestPointValue = pointIdValueMap . get ( pointId . trim ( ) . toUpperCase ( ) ) ;
if ( latestPointValue = = null ) {
return " - " ;
}
return latestPointValue . isFromRedis ( ) ? " Redis " : " Influx " ;
}
private BigDecimal getLatestPointValueFromRedis ( String pointId ) {
String normalizedPointId = StringUtils . trimToNull ( pointId ) ;
if ( normalizedPointId = = null ) {
return null ;
}
log . info ( " 点位值自检-Redis读取, pointId: {} " , normalizedPointId ) ;
List < String > candidates = new ArrayList < > ( ) ;
candidates . add ( normalizedPointId ) ;
String upperPointId = normalizedPointId . toUpperCase ( ) ;
@ -1037,6 +1080,7 @@ public class DeviceDataProcessServiceImpl extends AbstractBatteryDataProcessor i
pointValue = readBigDecimalField ( raw , " pointValue " ) ;
}
if ( pointValue ! = null ) {
log . info ( " 点位值自检-Redis命中, pointId: {}, redisKey: {} " , normalizedPointId , candidate ) ;
return pointValue ;
}
} catch ( Exception ex ) {
@ -1046,6 +1090,110 @@ public class DeviceDataProcessServiceImpl extends AbstractBatteryDataProcessor i
return null ;
}
private LatestPointValue getLatestPointValuePreferRedis ( String siteId , String pointId , Date queryStartTime , Date queryEndTime ) {
if ( StringUtils . isBlank ( siteId ) | | StringUtils . isBlank ( pointId ) ) {
return null ;
}
BigDecimal redisValue = getLatestPointValueFromRedis ( pointId ) ;
if ( redisValue ! = null ) {
return new LatestPointValue ( redisValue , null , true ) ;
}
log . info ( " 点位值自检-Influx读取, siteId: {}, pointId: {}, range: {} ~ {} " ,
siteId , pointId ,
DateUtils . parseDateToStr ( DateUtils . YYYY_MM_DD_HH_MM_SS , queryStartTime ) ,
DateUtils . parseDateToStr ( DateUtils . YYYY_MM_DD_HH_MM_SS , queryEndTime ) ) ;
InfluxPointDataWriter . PointValue influxPointValue = influxPointDataWriter . queryLatestPointValueByPointKey (
siteId , pointId , queryStartTime , queryEndTime
) ;
if ( influxPointValue = = null | | influxPointValue . getPointValue ( ) = = null ) {
return null ;
}
return new LatestPointValue ( influxPointValue . getPointValue ( ) , influxPointValue . getDataTime ( ) , false ) ;
}
private BigDecimal getLatestPointValuePreferRedisValue ( String siteId , String pointId , Date queryStartTime , Date queryEndTime ) {
LatestPointValue value = getLatestPointValuePreferRedis ( siteId , pointId , queryStartTime , queryEndTime ) ;
return value = = null ? null : value . getValue ( ) ;
}
private String resolvePointIdByFieldCodeIgnoreDevice ( List < EmsSiteMonitorPointMatch > mappingList , String fieldCode ) {
if ( CollectionUtils . isEmpty ( mappingList ) | | StringUtils . isBlank ( fieldCode ) ) {
return null ;
}
String normalized = fieldCode . trim ( ) . toLowerCase ( ) ;
for ( EmsSiteMonitorPointMatch mapping : mappingList ) {
if ( mapping = = null | | StringUtils . isBlank ( mapping . getFieldCode ( ) ) ) {
continue ;
}
String dataPoint = StringUtils . defaultString ( mapping . getDataPoint ( ) ) . trim ( ) ;
if ( StringUtils . isBlank ( dataPoint ) | | DELETED_FIELD_MARK . equalsIgnoreCase ( dataPoint ) ) {
continue ;
}
if ( mapping . getFieldCode ( ) . trim ( ) . toLowerCase ( ) . equals ( normalized ) ) {
return dataPoint ;
}
}
return null ;
}
private void upsertDailyChargeData ( String siteId ,
Date recordDateTime ,
BigDecimal totalChargeValue ,
BigDecimal totalDischargeValue ,
BigDecimal dayChargeValue ,
BigDecimal dayDischargeValue ) {
if ( StringUtils . isBlank ( siteId ) ) {
return ;
}
Date persistTime = recordDateTime = = null ? DateUtils . getNowDate ( ) : recordDateTime ;
EmsDailyChargeData dailyChargeData = new EmsDailyChargeData ( ) ;
dailyChargeData . setSiteId ( siteId ) ;
dailyChargeData . setDateTime ( persistTime ) ;
dailyChargeData . setTotalChargeData ( totalChargeValue ) ;
dailyChargeData . setTotalDischargeData ( totalDischargeValue ) ;
dailyChargeData . setChargeData ( dayChargeValue ) ;
dailyChargeData . setDischargeData ( dayDischargeValue ) ;
EmsDailyChargeData existedDailyData = emsDailyChargeDataMapper . selectBySiteIdAndDateTime ( siteId , persistTime ) ;
if ( existedDailyData ! = null & & existedDailyData . getId ( ) ! = null ) {
dailyChargeData . setId ( existedDailyData . getId ( ) ) ;
dailyChargeData . setDateTime ( existedDailyData . getDateTime ( ) ) ;
}
Date now = DateUtils . getNowDate ( ) ;
dailyChargeData . setCreateBy ( " system " ) ;
dailyChargeData . setCreateTime ( now ) ;
dailyChargeData . setUpdateBy ( " system " ) ;
dailyChargeData . setUpdateTime ( now ) ;
emsDailyChargeDataMapper . insertOrUpdateData ( dailyChargeData ) ;
log . info ( " 日充放电累计落库完成, siteId: {}, totalCharge: {}, totalDischarge: {}, dayCharge: {}, dayDischarge: {} " ,
siteId , totalChargeValue , totalDischargeValue , dayChargeValue , dayDischargeValue ) ;
}
private static class LatestPointValue {
private final BigDecimal value ;
private final Date dataTime ;
private final boolean fromRedis ;
LatestPointValue ( BigDecimal value , Date dataTime , boolean fromRedis ) {
this . value = value ;
this . dataTime = dataTime ;
this . fromRedis = fromRedis ;
}
public BigDecimal getValue ( ) {
return value ;
}
public Date getDataTime ( ) {
return dataTime ;
}
public boolean isFromRedis ( ) {
return fromRedis ;
}
}
private BigDecimal readBigDecimalField ( Object source , String fieldName ) {
Object fieldValue = readFieldValue ( source , fieldName ) ;
return StringUtils . getBigDecimal ( fieldValue ) ;
@ -1165,9 +1313,11 @@ public class DeviceDataProcessServiceImpl extends AbstractBatteryDataProcessor i
}
String normalizedSiteId = siteId . trim ( ) ;
String redisKey = RedisKeyConstants . SITE_MONITOR_POINT_MATCH + normalizedSiteId ;
log . info ( " 单站映射自检-读取, siteId: {}, redisKey: {} " , normalizedSiteId , redisKey ) ;
Object cacheObj = redisCache . getCacheObject ( redisKey ) ;
List < EmsSiteMonitorPointMatch > cached = parsePointMatchCache ( cacheObj ) ;
if ( cached ! = null ) {
log . info ( " 单站映射自检-命中缓存, siteId: {}, size: {} " , normalizedSiteId , cached . size ( ) ) ;
return cached ;
}
List < EmsSiteMonitorPointMatch > latest = emsSiteMonitorPointMatchMapper . selectBySiteId ( normalizedSiteId ) ;
@ -1175,6 +1325,7 @@ public class DeviceDataProcessServiceImpl extends AbstractBatteryDataProcessor i
latest = Collections . emptyList ( ) ;
}
redisCache . setCacheObject ( redisKey , latest , MONITOR_POINT_MATCH_REDIS_TTL_SECONDS , TimeUnit . SECONDS ) ;
log . info ( " 单站映射自检-落库后写缓存, siteId: {}, size: {} " , normalizedSiteId , latest . size ( ) ) ;
return latest ;
}