设备列表-单体电池的点位清单数据
This commit is contained in:
@ -29,6 +29,16 @@ public class PointDataRequest {
|
|||||||
private BigDecimal upper;
|
private BigDecimal upper;
|
||||||
/** 排序字段 */
|
/** 排序字段 */
|
||||||
private String sortData;
|
private String sortData;
|
||||||
|
/** 父类deviceId */
|
||||||
|
private String parentId;
|
||||||
|
|
||||||
|
public String getParentId() {
|
||||||
|
return parentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setParentId(String parentId) {
|
||||||
|
this.parentId = parentId;
|
||||||
|
}
|
||||||
|
|
||||||
public String getSortData() {
|
public String getSortData() {
|
||||||
return sortData;
|
return sortData;
|
||||||
|
|||||||
@ -65,28 +65,6 @@ public interface EmsBatteryDataMapper
|
|||||||
*/
|
*/
|
||||||
public int deleteEmsBatteryDataByIds(Long[] ids);
|
public int deleteEmsBatteryDataByIds(Long[] ids);
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据siteId查询站点电池实时数据
|
|
||||||
* @param siteId
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public EmsBatteryData getBatteryDataBySiteId(String siteId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 根据siteId和簇id获取单体数据
|
|
||||||
* @param siteId
|
|
||||||
* @param clusterDeviceId
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public BatteryClusterDataDetailVo getBatteryDataByClusterId(@Param("siteId")String siteId, @Param("clusterDeviceId")String clusterDeviceId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取最大最小的单体id
|
|
||||||
* @param dataVo
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public List<Map<String, Object>> getDataIdsMap(BatteryClusterDataDetailVo dataVo);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据电池簇设备id获取下面所有单体电池
|
* 根据电池簇设备id获取下面所有单体电池
|
||||||
* @param clusterDeviceId
|
* @param clusterDeviceId
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import com.xzzn.ems.domain.EmsBatteryData;
|
import com.xzzn.ems.domain.EmsBatteryData;
|
||||||
import com.xzzn.ems.domain.EmsBatteryDataMinutes;
|
import com.xzzn.ems.domain.EmsBatteryDataMinutes;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 单体电池分钟级数据Mapper接口
|
* 单体电池分钟级数据Mapper接口
|
||||||
@ -65,4 +66,9 @@ public interface EmsBatteryDataMinutesMapper
|
|||||||
int insertMinutesBatteryDataList(List<EmsBatteryDataMinutes> emsBatteryDataList);
|
int insertMinutesBatteryDataList(List<EmsBatteryDataMinutes> emsBatteryDataList);
|
||||||
|
|
||||||
public void deleteByTimeBeforeOneHour(String oneHourAgoStr);
|
public void deleteByTimeBeforeOneHour(String oneHourAgoStr);
|
||||||
|
|
||||||
|
// 获取指定站点指定电池簇下面的单体电池最新数据
|
||||||
|
public EmsBatteryData getLastBatteryData(@Param("siteId") String siteId,
|
||||||
|
@Param("clusterDeviceId") String clusterDeviceId,
|
||||||
|
@Param("deviceId") String deviceId);
|
||||||
}
|
}
|
||||||
@ -6,11 +6,13 @@ import com.alibaba.fastjson2.TypeReference;
|
|||||||
import com.xzzn.common.constant.RedisKeyConstants;
|
import com.xzzn.common.constant.RedisKeyConstants;
|
||||||
import com.xzzn.common.core.redis.RedisCache;
|
import com.xzzn.common.core.redis.RedisCache;
|
||||||
import com.xzzn.common.enums.DeviceCategory;
|
import com.xzzn.common.enums.DeviceCategory;
|
||||||
|
import com.xzzn.common.enums.SiteEnum;
|
||||||
import com.xzzn.common.utils.DateUtils;
|
import com.xzzn.common.utils.DateUtils;
|
||||||
import com.xzzn.common.utils.StringUtils;
|
import com.xzzn.common.utils.StringUtils;
|
||||||
import com.xzzn.ems.domain.EmsDevicesSetting;
|
import com.xzzn.ems.domain.EmsDevicesSetting;
|
||||||
import com.xzzn.ems.domain.vo.PointDataRequest;
|
import com.xzzn.ems.domain.vo.PointDataRequest;
|
||||||
import com.xzzn.ems.domain.vo.PointQueryResponse;
|
import com.xzzn.ems.domain.vo.PointQueryResponse;
|
||||||
|
import com.xzzn.ems.mapper.EmsBatteryDataMinutesMapper;
|
||||||
import com.xzzn.ems.mapper.EmsDevicesSettingMapper;
|
import com.xzzn.ems.mapper.EmsDevicesSettingMapper;
|
||||||
import com.xzzn.ems.mapper.EmsPointMatchMapper;
|
import com.xzzn.ems.mapper.EmsPointMatchMapper;
|
||||||
import com.xzzn.ems.service.IEmsDeviceSettingService;
|
import com.xzzn.ems.service.IEmsDeviceSettingService;
|
||||||
@ -19,6 +21,7 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,6 +39,11 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
|
|||||||
private EmsPointMatchMapper emsPointMatchMapper;
|
private EmsPointMatchMapper emsPointMatchMapper;
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisCache redisCache;
|
private RedisCache redisCache;
|
||||||
|
@Autowired
|
||||||
|
private EmsBatteryDataMinutesMapper emsBatteryDataMinutesMapper;
|
||||||
|
@Autowired
|
||||||
|
private EmsBatteryClusterServiceImpl emsBatteryClusterServiceImpl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取设备详细信息
|
* 获取设备详细信息
|
||||||
* @param id
|
* @param id
|
||||||
@ -129,14 +137,18 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
|
|||||||
|
|
||||||
List<PointQueryResponse> response = new ArrayList<>();
|
List<PointQueryResponse> response = new ArrayList<>();
|
||||||
|
|
||||||
|
String dataPointName = request.getDataPointName();
|
||||||
|
String dataPoint = request.getDataPoint();
|
||||||
|
String parentDeviceId = request.getParentId();
|
||||||
// 电动所的电池簇特殊处理-来源pcs+bmsd
|
// 电动所的电池簇特殊处理-来源pcs+bmsd
|
||||||
if (siteId.equals(DDS_SITE_ID) && DeviceCategory.CLUSTER.getCode().equals(deviceCategory)) {
|
if (siteId.equals(DDS_SITE_ID) && DeviceCategory.CLUSTER.getCode().equals(deviceCategory)) {
|
||||||
response = specialDealWithDDSCluster(siteId,deviceId,deviceCategory,
|
response = specialDealWithDDSCluster(siteId,deviceId,deviceCategory,dataPointName,dataPoint);
|
||||||
request.getDataPointName(),request.getDataPoint());
|
} else if (DeviceCategory.BATTERY.getCode().equals(deviceCategory)) {
|
||||||
|
response = specialDealWithBattery(siteId,deviceId,deviceCategory,
|
||||||
|
dataPointName,dataPoint,parentDeviceId);
|
||||||
} else {
|
} else {
|
||||||
response = emsPointMatchMapper.getSingleSiteDevicePoints(siteId,deviceCategory,
|
response = emsPointMatchMapper.getSingleSiteDevicePoints(
|
||||||
request.getDataPointName(),request.getDataPoint());
|
siteId,deviceCategory,dataPointName,dataPoint);
|
||||||
// 从redis取最新数据
|
// 从redis取最新数据
|
||||||
JSONObject mqttJson = redisCache.getCacheObject(RedisKeyConstants.ORIGINAL_MQTT_DATA + siteId + "_" + deviceId);
|
JSONObject mqttJson = redisCache.getCacheObject(RedisKeyConstants.ORIGINAL_MQTT_DATA + siteId + "_" + deviceId);
|
||||||
if(mqttJson == null){
|
if(mqttJson == null){
|
||||||
@ -220,6 +232,54 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
|
|||||||
.collect(Collectors.toList());
|
.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
|
@Override
|
||||||
public List<String> getSiteAllDeviceCategory(String siteId) {
|
public List<String> getSiteAllDeviceCategory(String siteId) {
|
||||||
return emsDevicesMapper.getAllDeviceCategoryBySiteId(siteId);
|
return emsDevicesMapper.getAllDeviceCategoryBySiteId(siteId);
|
||||||
@ -370,4 +430,19 @@ public class EmsDeviceSettingServiceImpl implements IEmsDeviceSettingService
|
|||||||
return false;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -149,4 +149,16 @@
|
|||||||
<delete id="deleteByTimeBeforeOneHour" parameterType="String">
|
<delete id="deleteByTimeBeforeOneHour" parameterType="String">
|
||||||
delete from ems_battery_data_minutes where data_timestamp < #{oneHourAgoStr}
|
delete from ems_battery_data_minutes where data_timestamp < #{oneHourAgoStr}
|
||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
|
<select id="getLastBatteryData" resultType="com.xzzn.ems.domain.EmsBatteryData">
|
||||||
|
select t.voltage,
|
||||||
|
t.temperature,
|
||||||
|
t.soc,t.soh,
|
||||||
|
t.inter_resistance
|
||||||
|
from ems_battery_data_minutes t
|
||||||
|
where t.site_id = #{siteId}
|
||||||
|
and t.cluster_device_id = #{clusterDeviceId}
|
||||||
|
and t.device_id=#{deviceId}
|
||||||
|
order by t.data_timestamp desc limit 1
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user