|
|
|
|
@ -6,11 +6,13 @@ import com.alibaba.fastjson2.TypeReference;
|
|
|
|
|
import com.xzzn.common.constant.RedisKeyConstants;
|
|
|
|
|
import com.xzzn.common.core.redis.RedisCache;
|
|
|
|
|
import com.xzzn.common.enums.DeviceCategory;
|
|
|
|
|
import com.xzzn.common.enums.SiteEnum;
|
|
|
|
|
import com.xzzn.common.utils.DateUtils;
|
|
|
|
|
import com.xzzn.common.utils.StringUtils;
|
|
|
|
|
import com.xzzn.ems.domain.EmsDevicesSetting;
|
|
|
|
|
import com.xzzn.ems.domain.vo.PointDataRequest;
|
|
|
|
|
import com.xzzn.ems.domain.vo.PointQueryResponse;
|
|
|
|
|
import com.xzzn.ems.mapper.EmsBatteryDataMinutesMapper;
|
|
|
|
|
import com.xzzn.ems.mapper.EmsDevicesSettingMapper;
|
|
|
|
|
import com.xzzn.ems.mapper.EmsPointMatchMapper;
|
|
|
|
|
import com.xzzn.ems.service.IEmsDeviceSettingService;
|
|
|
|
|
@ -19,6 +21,7 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -36,6 +39,11 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
|
|
|
|
|
private EmsPointMatchMapper emsPointMatchMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private RedisCache redisCache;
|
|
|
|
|
@Autowired
|
|
|
|
|
private EmsBatteryDataMinutesMapper emsBatteryDataMinutesMapper;
|
|
|
|
|
@Autowired
|
|
|
|
|
private EmsBatteryClusterServiceImpl emsBatteryClusterServiceImpl;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取设备详细信息
|
|
|
|
|
* @param id
|
|
|
|
|
@ -129,14 +137,18 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
|
|
|
|
|
|
|
|
|
|
List<PointQueryResponse> response = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String dataPointName = request.getDataPointName();
|
|
|
|
|
String dataPoint = request.getDataPoint();
|
|
|
|
|
String parentDeviceId = request.getParentId();
|
|
|
|
|
// 电动所的电池簇特殊处理-来源pcs+bmsd
|
|
|
|
|
if (siteId.equals(DDS_SITE_ID) && DeviceCategory.CLUSTER.getCode().equals(deviceCategory)) {
|
|
|
|
|
response = specialDealWithDDSCluster(siteId,deviceId,deviceCategory,
|
|
|
|
|
request.getDataPointName(),request.getDataPoint());
|
|
|
|
|
response = specialDealWithDDSCluster(siteId,deviceId,deviceCategory,dataPointName,dataPoint);
|
|
|
|
|
} else if (DeviceCategory.BATTERY.getCode().equals(deviceCategory)) {
|
|
|
|
|
response = specialDealWithBattery(siteId,deviceId,deviceCategory,
|
|
|
|
|
dataPointName,dataPoint,parentDeviceId);
|
|
|
|
|
} else {
|
|
|
|
|
response = emsPointMatchMapper.getSingleSiteDevicePoints(siteId,deviceCategory,
|
|
|
|
|
request.getDataPointName(),request.getDataPoint());
|
|
|
|
|
response = emsPointMatchMapper.getSingleSiteDevicePoints(
|
|
|
|
|
siteId,deviceCategory,dataPointName,dataPoint);
|
|
|
|
|
// 从redis取最新数据
|
|
|
|
|
JSONObject mqttJson = redisCache.getCacheObject(RedisKeyConstants.ORIGINAL_MQTT_DATA + siteId + "_" + deviceId);
|
|
|
|
|
if(mqttJson == null){
|
|
|
|
|
@ -220,6 +232,54 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<PointQueryResponse> specialDealWithBattery(String siteId, String deviceId, String deviceCategory,
|
|
|
|
|
String dataPointName, String dataPoint, String parentDeviceId) {
|
|
|
|
|
List<PointQueryResponse> response = emsPointMatchMapper.getSingleSiteDevicePoints(siteId,deviceCategory,
|
|
|
|
|
dataPointName,dataPoint);
|
|
|
|
|
|
|
|
|
|
// 获取redis同步最新数据
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
if (SiteEnum.DDS.getCode().equals(siteId)) {
|
|
|
|
|
// dds单体电池数据来源于BMSD
|
|
|
|
|
EmsDevicesSetting clusterDevice = emsDevicesMapper.getDeviceBySiteAndDeviceId(parentDeviceId,siteId);
|
|
|
|
|
String bmsdDeviceId = clusterDevice == null ? "" :clusterDevice.getParentId();
|
|
|
|
|
if (StringUtils.isEmpty(bmsdDeviceId)) {
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
jsonObject = redisCache.getCacheObject(RedisKeyConstants.ORIGINAL_MQTT_DATA + siteId + "_" + bmsdDeviceId);
|
|
|
|
|
} else if (SiteEnum.FX.getCode().equals(siteId)) {
|
|
|
|
|
// fx单体电池数据来源于父类簇BMSC
|
|
|
|
|
jsonObject = redisCache.getCacheObject(RedisKeyConstants.ORIGINAL_MQTT_DATA + siteId + "_" + parentDeviceId);
|
|
|
|
|
}
|
|
|
|
|
if (jsonObject != null) {
|
|
|
|
|
// 填充数据
|
|
|
|
|
fillBatteryData(jsonObject,siteId, deviceId, response);
|
|
|
|
|
}
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void fillBatteryData(JSONObject jsonObject, String siteId, String deviceId, List<PointQueryResponse> response) {
|
|
|
|
|
String jsonData = jsonObject.get("Data").toString();
|
|
|
|
|
if (StringUtils.isEmpty(jsonData)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Map<String, Object> obj = JSON.parseObject(jsonData, new TypeReference<Map<String, Object>>() {
|
|
|
|
|
});
|
|
|
|
|
Long updateTime = Long.valueOf(jsonObject.get("timestamp").toString());
|
|
|
|
|
Date dataUpdateTime = DateUtils.convertUpdateTime(updateTime);
|
|
|
|
|
// 遍历点位数据,设最新值
|
|
|
|
|
for (PointQueryResponse pointInfo : response) {
|
|
|
|
|
String dataKey = "";
|
|
|
|
|
if (SiteEnum.DDS.getCode().equals(siteId)) {
|
|
|
|
|
dataKey = "DTDC" + deviceId + pointInfo.getDataPoint();
|
|
|
|
|
} else if (SiteEnum.FX.getCode().equals(siteId)) {
|
|
|
|
|
dataKey = pointInfo.getDataPoint() + deviceId;
|
|
|
|
|
}
|
|
|
|
|
pointInfo.setPointValue(obj.get(dataKey));
|
|
|
|
|
pointInfo.setUpdateTime(dataUpdateTime);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<String> getSiteAllDeviceCategory(String siteId) {
|
|
|
|
|
return emsDevicesMapper.getAllDeviceCategoryBySiteId(siteId);
|
|
|
|
|
@ -370,4 +430,19 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String, List<EmsDevicesSetting>> initDeviceInfo() {
|
|
|
|
|
List<EmsDevicesSetting> settingList = emsDevicesMapper.selectEmsDevicesSettingList(null);
|
|
|
|
|
// 按siteId分组
|
|
|
|
|
Map<String, List<EmsDevicesSetting>> map = settingList.stream()
|
|
|
|
|
.collect(Collectors.groupingBy(
|
|
|
|
|
EmsDevicesSetting::getSiteId,
|
|
|
|
|
HashMap::new,
|
|
|
|
|
Collectors.toList()
|
|
|
|
|
));
|
|
|
|
|
// 存redis
|
|
|
|
|
redisCache.setCacheObject(RedisKeyConstants.INIT_DEVICE_INFO, map, 30, TimeUnit.DAYS);
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|