@ -17,6 +17,7 @@ import com.xzzn.ems.domain.vo.EnergyPriceVo;
import com.xzzn.ems.mapper.* ;
import com.xzzn.ems.mapper.* ;
import com.xzzn.ems.service.IDDSDataProcessService ;
import com.xzzn.ems.service.IDDSDataProcessService ;
import com.xzzn.ems.service.IEmsAlarmRecordsService ;
import com.xzzn.ems.service.IEmsAlarmRecordsService ;
import com.xzzn.ems.service.IEmsDeviceSettingService ;
import com.xzzn.ems.utils.AbstractBatteryDataProcessor ;
import com.xzzn.ems.utils.AbstractBatteryDataProcessor ;
import org.apache.commons.logging.Log ;
import org.apache.commons.logging.Log ;
import org.apache.commons.logging.LogFactory ;
import org.apache.commons.logging.LogFactory ;
@ -81,6 +82,8 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
private IEmsAlarmRecordsService iEmsAlarmRecordsService ;
private IEmsAlarmRecordsService iEmsAlarmRecordsService ;
@Autowired
@Autowired
private EmsDailyEnergyDataMapper emsDailyEnergyDataMapper ;
private EmsDailyEnergyDataMapper emsDailyEnergyDataMapper ;
@Autowired
private IEmsDeviceSettingService iEmsDeviceSettingService ;
public DDSDataProcessServiceImpl ( ObjectMapper objectMapper ) {
public DDSDataProcessServiceImpl ( ObjectMapper objectMapper ) {
super ( objectMapper ) ;
super ( objectMapper ) ;
@ -92,6 +95,8 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
String deviceId = obj . get ( " Device " ) . toString ( ) ;
String deviceId = obj . get ( " Device " ) . toString ( ) ;
String jsonData = obj . get ( " Data " ) . toString ( ) ;
String jsonData = obj . get ( " Data " ) . toString ( ) ;
Long timestamp = Long . valueOf ( obj . get ( " timestamp " ) . toString ( ) ) ;
Date dataUpdateTime = DateUtils . convertUpdateTime ( timestamp ) ;
log . info ( " deviceId: " + deviceId ) ;
log . info ( " deviceId: " + deviceId ) ;
boolean isEmpty = checkJsonDataEmpty ( jsonData ) ;
boolean isEmpty = checkJsonDataEmpty ( jsonData ) ;
@ -108,7 +113,7 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
if ( deviceId . contains ( " BMSD " ) ) {
if ( deviceId . contains ( " BMSD " ) ) {
batteryStackDataProcess ( deviceId , jsonData ) ;
batteryStackDataProcess ( deviceId , jsonData ) ;
batteryGroupDataProcess ( deviceId , jsonData ) ;
batteryGroupDataProcess ( deviceId , jsonData ) ;
batteryDataProcess ( deviceId , jsonData ) ;
batteryDataProcess ( deviceId , jsonData , dataUpdateTime );
} else if ( deviceId . contains ( " PCS " ) ) {
} else if ( deviceId . contains ( " PCS " ) ) {
pcsDataProcess ( deviceId , jsonData ) ;
pcsDataProcess ( deviceId , jsonData ) ;
pcsBranchDataProcess ( deviceId , jsonData ) ;
pcsBranchDataProcess ( deviceId , jsonData ) ;
@ -293,7 +298,7 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
break ;
break ;
}
}
}
}
private void batteryDataProcess ( String deviceId , String dataJson ) {
private void batteryDataProcess ( String deviceId , String dataJson , Date dataUpdateTime ) {
//电池组
//电池组
Map < String , Object > obj = JSON . parseObject ( dataJson , new TypeReference < Map < String , Object > > ( ) {
Map < String , Object > obj = JSON . parseObject ( dataJson , new TypeReference < Map < String , Object > > ( ) {
} ) ;
} ) ;
@ -308,6 +313,7 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
Map < String , EmsBatteryDataDailyLatest > dailyMap = new HashMap < > ( ) ;
Map < String , EmsBatteryDataDailyLatest > dailyMap = new HashMap < > ( ) ;
Map < String , EmsBatteryDataMinutes > minutesMap = new HashMap < > ( ) ;
Map < String , EmsBatteryDataMinutes > minutesMap = new HashMap < > ( ) ;
String clusterId = getClusterDeviceIdByParentDeviceId ( deviceId ) ;
for ( Map . Entry < String , Object > entry : obj . entrySet ( ) ) {
for ( Map . Entry < String , Object > entry : obj . entrySet ( ) ) {
String key = entry . getKey ( ) ;
String key = entry . getKey ( ) ;
@ -319,10 +325,10 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
EmsBatteryData data = dataMap . getOrDefault ( batteryCellId , new EmsBatteryData ( ) ) ;
EmsBatteryData data = dataMap . getOrDefault ( batteryCellId , new EmsBatteryData ( ) ) ;
if ( StringUtils . isNotEmpty ( batteryCellId ) ) {
if ( StringUtils . isNotEmpty ( batteryCellId ) ) {
data . setDataTimestamp ( D ateUtils . getNowDate ( ) ) ;
data . setDataTimestamp ( d ataUpdateTime ) ;
data . setBatteryPack ( deviceId ) ;
data . setBatteryPack ( deviceId ) ;
data . setBatteryCluster ( " BMSC01 " ) ; // 写死
data . setBatteryCluster ( clusterId ) ;
data . setClusterDeviceId ( " BMSC01 " ) ;
data . setClusterDeviceId ( clusterId ) ;
data . setBatteryCellId ( batteryCellId ) ;
data . setBatteryCellId ( batteryCellId ) ;
data . setSiteId ( SITE_ID ) ;
data . setSiteId ( SITE_ID ) ;
data . setDeviceId ( batteryCellId ) ;
data . setDeviceId ( batteryCellId ) ;
@ -352,8 +358,8 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
dataList = new ArrayList < > ( dataMap . values ( ) ) ;
dataList = new ArrayList < > ( dataMap . values ( ) ) ;
emsBatteryDataMapper . insertEmsBatteryDataList ( new ArrayList < > ( dataList ) ) ;
emsBatteryDataMapper . insertEmsBatteryDataList ( new ArrayList < > ( dataList ) ) ;
redisCache . deleteList ( RedisKeyConstants . BATTERY + SITE_ID + " _ " + " BMSC01 " ) ;
redisCache . deleteList ( RedisKeyConstants . BATTERY + SITE_ID + " _ " + clusterId ) ;
redisCache . setCacheList ( RedisKeyConstants . BATTERY + SITE_ID + " _ " + " BMSC01 " , dataList ) ;
redisCache . setCacheList ( RedisKeyConstants . BATTERY + SITE_ID + " _ " + clusterId , dataList ) ;
}
}
// 批量处理每日最新数据
// 批量处理每日最新数据
List < EmsBatteryDataDailyLatest > dailyList = new ArrayList < > ( dailyMap . values ( ) ) ;
List < EmsBatteryDataDailyLatest > dailyList = new ArrayList < > ( dailyMap . values ( ) ) ;
@ -376,6 +382,26 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
}
}
}
}
private String getClusterDeviceIdByParentDeviceId ( String deviceId ) {
String clusterId = " BMSC01 " ;
Map < String , List < EmsDevicesSetting > > map = redisCache . getCacheObject ( RedisKeyConstants . INIT_DEVICE_INFO ) ;
if ( map = = null | | map . isEmpty ( ) ) {
map = iEmsDeviceSettingService . initDeviceInfo ( ) ;
}
// 不为空, 则查找子类的簇id
if ( map ! = null & & ! map . isEmpty ( ) ) {
List < EmsDevicesSetting > list = map . get ( SITE_ID ) ;
if ( list ! = null & & list . size ( ) > 0 ) {
for ( EmsDevicesSetting emsDevicesSetting : list ) {
if ( deviceId . equals ( emsDevicesSetting . getParentId ( ) ) ) {
clusterId = emsDevicesSetting . getDeviceId ( ) ;
}
}
}
}
return clusterId ;
}
private void setDTDCPropertyValue ( EmsBatteryData data , String property , Object value ) {
private void setDTDCPropertyValue ( EmsBatteryData data , String property , Object value ) {
BigDecimal numberValue = null ;
BigDecimal numberValue = null ;
if ( value instanceof Number ) {
if ( value instanceof Number ) {
@ -416,7 +442,7 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
data . setSiteId ( SITE_ID ) ;
data . setSiteId ( SITE_ID ) ;
// BMSC02 电流电压功率
// BMSC02 电流电压功率
deviceId = " BMSC02 " ;
deviceId = " BMSC02 " ;
String stackDeviceId = getDeviceParent ( deviceId , SITE_ID );
String stackDeviceId = getDeviceParent ( deviceId ) ;
if ( StringUtils . isNotBlank ( stackDeviceId ) ) {
if ( StringUtils . isNotBlank ( stackDeviceId ) ) {
data . setStackDeviceId ( stackDeviceId ) ;
data . setStackDeviceId ( stackDeviceId ) ;
} else {
} else {
@ -438,7 +464,7 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
// BMSC01 电流电压功率
// BMSC01 电流电压功率
deviceId = " BMSC01 " ;
deviceId = " BMSC01 " ;
stackDeviceId = getDeviceParent ( deviceId , SITE_ID );
stackDeviceId = getDeviceParent ( deviceId ) ;
if ( StringUtils . isNotBlank ( stackDeviceId ) ) {
if ( StringUtils . isNotBlank ( stackDeviceId ) ) {
data . setStackDeviceId ( stackDeviceId ) ;
data . setStackDeviceId ( stackDeviceId ) ;
} else {
} else {
@ -469,16 +495,27 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
redisCache . setCacheObject ( RedisKeyConstants . CLUSTER + SITE_ID + " _ " + deviceId , data ) ;
redisCache . setCacheObject ( RedisKeyConstants . CLUSTER + SITE_ID + " _ " + deviceId , data ) ;
}
}
private String getDeviceParent ( String deviceId , String siteId ) {
private String getDeviceParent ( String deviceId ) {
EmsDevicesSetting joken = new EmsDevicesSetting ( ) ;
Map < String , List < EmsDevicesSetting > > map = redisCache . getCacheObject ( RedisKeyConstants . INIT_DEVICE_INFO ) ;
joken . setDeviceId ( deviceId ) ;
if ( map = = null | | map . isEmpty ( ) ) {
joken . setSiteId ( siteId ) ;
map = iEmsDeviceSettingService . initDeviceInfo ( ) ;
List < EmsDevicesSetting > up = emsDevicesSettingMapper . selectEmsDevicesSettingList ( joken ) ;
}
String stackDeviceId = " " ;
// 不为空,则查找父类
if ( up ! = null & & up . size ( ) > 0 ) {
String stackDeviceId = " 1 " ;
stackDeviceId = up . get ( 0 ) . getParentId ( ) ;
if ( map ! = null & & ! map . isEmpty ( ) ) {
List < EmsDevicesSetting > list = map . get ( SITE_ID ) ;
if ( list = = null | | list . isEmpty ( ) ) {
EmsDevicesSetting deviceInfo = new EmsDevicesSetting ( ) ;
deviceInfo . setDeviceId ( deviceId ) ;
deviceInfo . setSiteId ( SITE_ID ) ;
list = emsDevicesSettingMapper . selectEmsDevicesSettingList ( deviceInfo ) ;
if ( list = = null | | list . isEmpty ( ) ) {
return stackDeviceId ;
}
}
stackDeviceId = list . get ( 0 ) . getParentId ( ) ;
if ( stackDeviceId = = null | | stackDeviceId . isEmpty ( ) ) {
if ( stackDeviceId = = null | | stackDeviceId . isEmpty ( ) ) {
stackDeviceId = " 1 " ;
return stackDeviceId ;
}
}
}
}
return stackDeviceId ;
return stackDeviceId ;