初始化设备信息存入redis
This commit is contained in:
@ -7,6 +7,7 @@ import com.xzzn.ems.domain.vo.PointDataRequest;
|
||||
import com.xzzn.ems.domain.vo.PointQueryResponse;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 设备信息 服务层
|
||||
@ -28,4 +29,6 @@ public interface IEmsDeviceSettingService
|
||||
public List<PointQueryResponse> getSingleSiteDevicePoints(PointDataRequest request);
|
||||
|
||||
public List<String> getSiteAllDeviceCategory(String siteId);
|
||||
// 初始化设备信息
|
||||
public Map<String, List<EmsDevicesSetting>> initDeviceInfo();
|
||||
}
|
||||
|
||||
@ -17,6 +17,7 @@ import com.xzzn.ems.domain.vo.EnergyPriceVo;
|
||||
import com.xzzn.ems.mapper.*;
|
||||
import com.xzzn.ems.service.IDDSDataProcessService;
|
||||
import com.xzzn.ems.service.IEmsAlarmRecordsService;
|
||||
import com.xzzn.ems.service.IEmsDeviceSettingService;
|
||||
import com.xzzn.ems.utils.AbstractBatteryDataProcessor;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@ -81,6 +82,8 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
private IEmsAlarmRecordsService iEmsAlarmRecordsService;
|
||||
@Autowired
|
||||
private EmsDailyEnergyDataMapper emsDailyEnergyDataMapper;
|
||||
@Autowired
|
||||
private IEmsDeviceSettingService iEmsDeviceSettingService;
|
||||
|
||||
public DDSDataProcessServiceImpl(ObjectMapper objectMapper) {
|
||||
super(objectMapper);
|
||||
@ -92,6 +95,8 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
|
||||
String deviceId = obj.get("Device").toString();
|
||||
String jsonData = obj.get("Data").toString();
|
||||
Long timestamp = Long.valueOf(obj.get("timestamp").toString());
|
||||
Date dataUpdateTime = DateUtils.convertUpdateTime(timestamp);
|
||||
|
||||
log.info("deviceId:" + deviceId);
|
||||
boolean isEmpty = checkJsonDataEmpty(jsonData);
|
||||
@ -108,7 +113,7 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
if (deviceId.contains("BMSD")) {
|
||||
batteryStackDataProcess(deviceId, jsonData);
|
||||
batteryGroupDataProcess(deviceId, jsonData);
|
||||
batteryDataProcess(deviceId, jsonData);
|
||||
batteryDataProcess(deviceId, jsonData, dataUpdateTime);
|
||||
} else if (deviceId.contains("PCS")) {
|
||||
pcsDataProcess(deviceId, jsonData);
|
||||
pcsBranchDataProcess(deviceId, jsonData);
|
||||
@ -293,7 +298,7 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
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>>() {
|
||||
});
|
||||
@ -308,6 +313,7 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
Map<String, EmsBatteryDataDailyLatest> dailyMap = new HashMap<>();
|
||||
Map<String, EmsBatteryDataMinutes> minutesMap = new HashMap<>();
|
||||
|
||||
String clusterId = getClusterDeviceIdByParentDeviceId(deviceId);
|
||||
for (Map.Entry<String, Object> entry : obj.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
|
||||
@ -319,10 +325,10 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
|
||||
EmsBatteryData data = dataMap.getOrDefault(batteryCellId, new EmsBatteryData());
|
||||
if (StringUtils.isNotEmpty(batteryCellId)) {
|
||||
data.setDataTimestamp(DateUtils.getNowDate());
|
||||
data.setDataTimestamp(dataUpdateTime);
|
||||
data.setBatteryPack(deviceId);
|
||||
data.setBatteryCluster("BMSC01");// 写死
|
||||
data.setClusterDeviceId("BMSC01");
|
||||
data.setBatteryCluster(clusterId);
|
||||
data.setClusterDeviceId(clusterId);
|
||||
data.setBatteryCellId(batteryCellId);
|
||||
data.setSiteId(SITE_ID);
|
||||
data.setDeviceId(batteryCellId);
|
||||
@ -352,8 +358,8 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
dataList = new ArrayList<>(dataMap.values());
|
||||
emsBatteryDataMapper.insertEmsBatteryDataList(new ArrayList<>(dataList));
|
||||
|
||||
redisCache.deleteList(RedisKeyConstants.BATTERY + SITE_ID + "_" + "BMSC01");
|
||||
redisCache.setCacheList(RedisKeyConstants.BATTERY + SITE_ID + "_" + "BMSC01" , dataList);
|
||||
redisCache.deleteList(RedisKeyConstants.BATTERY + SITE_ID + "_" + clusterId);
|
||||
redisCache.setCacheList(RedisKeyConstants.BATTERY + SITE_ID + "_" + clusterId , dataList);
|
||||
}
|
||||
// 批量处理每日最新数据
|
||||
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) {
|
||||
BigDecimal numberValue = null;
|
||||
if (value instanceof Number) {
|
||||
@ -416,7 +442,7 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
data.setSiteId(SITE_ID);
|
||||
// BMSC02 电流电压功率
|
||||
deviceId = "BMSC02";
|
||||
String stackDeviceId = getDeviceParent(deviceId, SITE_ID);
|
||||
String stackDeviceId = getDeviceParent(deviceId);
|
||||
if (StringUtils.isNotBlank(stackDeviceId)) {
|
||||
data.setStackDeviceId(stackDeviceId);
|
||||
} else {
|
||||
@ -438,7 +464,7 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
|
||||
// BMSC01 电流电压功率
|
||||
deviceId = "BMSC01";
|
||||
stackDeviceId = getDeviceParent(deviceId, SITE_ID);
|
||||
stackDeviceId = getDeviceParent(deviceId);
|
||||
if (StringUtils.isNotBlank(stackDeviceId)) {
|
||||
data.setStackDeviceId(stackDeviceId);
|
||||
} else {
|
||||
@ -469,16 +495,27 @@ public class DDSDataProcessServiceImpl extends AbstractBatteryDataProcessor impl
|
||||
redisCache.setCacheObject(RedisKeyConstants.CLUSTER + SITE_ID + "_" +deviceId, data);
|
||||
}
|
||||
|
||||
private String getDeviceParent(String deviceId,String siteId) {
|
||||
EmsDevicesSetting joken = new EmsDevicesSetting();
|
||||
joken.setDeviceId(deviceId);
|
||||
joken.setSiteId(siteId);
|
||||
List<EmsDevicesSetting> up = emsDevicesSettingMapper.selectEmsDevicesSettingList(joken);
|
||||
String stackDeviceId = "";
|
||||
if (up != null && up.size() >0) {
|
||||
stackDeviceId = up.get(0).getParentId();
|
||||
private String getDeviceParent(String deviceId) {
|
||||
Map<String, List<EmsDevicesSetting>> map = redisCache.getCacheObject(RedisKeyConstants.INIT_DEVICE_INFO);
|
||||
if (map == null || map.isEmpty()) {
|
||||
map = iEmsDeviceSettingService.initDeviceInfo();
|
||||
}
|
||||
// 不为空,则查找父类
|
||||
String stackDeviceId = "1";
|
||||
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()) {
|
||||
stackDeviceId = "1";
|
||||
return stackDeviceId;
|
||||
}
|
||||
}
|
||||
return stackDeviceId;
|
||||
|
||||
Reference in New Issue
Block a user