新增云协议设备实时数据功能
This commit is contained in:
@@ -14,6 +14,12 @@ public class BaseRealDataSet implements Serializable {
|
||||
@ApiModelProperty("用户ID")
|
||||
private String userId;
|
||||
|
||||
@ApiModelProperty("结果(仅超时使用)")
|
||||
private boolean result = true;
|
||||
|
||||
@ApiModelProperty("描述")
|
||||
private String content;
|
||||
|
||||
@ApiModelProperty("监测点id")
|
||||
private String lineId;
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package com.njcn.rt.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
|
||||
import com.njcn.access.utils.ChannelObjectUtil;
|
||||
import com.njcn.access.utils.RedisSetUtil;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.utils.PubUtils;
|
||||
import com.njcn.csdevice.api.CsLineFeignClient;
|
||||
@@ -21,6 +23,7 @@ import com.njcn.rt.pojo.dto.HarmRealDataSet;
|
||||
import com.njcn.rt.service.IRtService;
|
||||
import com.njcn.web.utils.FloatUtils;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@@ -36,6 +39,7 @@ import java.util.stream.Collectors;
|
||||
/**
|
||||
* @author xy
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class RtServiceImpl implements IRtService {
|
||||
@@ -46,14 +50,14 @@ public class RtServiceImpl implements IRtService {
|
||||
private final RedisUtil redisUtil;
|
||||
private final ChannelObjectUtil channelObjectUtil;
|
||||
private final MqttPublisher publisher;
|
||||
private final RedisSetUtil redisSetUtil;
|
||||
|
||||
@Override
|
||||
public void analysis(AppAutoDataMessage appAutoDataMessage) {
|
||||
List<CsDataArray> dataArrayList;
|
||||
//监测点id
|
||||
String lineId = appAutoDataMessage.getId() + appAutoDataMessage.getMsg().getClDid();
|
||||
//用户Id
|
||||
String userId = redisUtil.getObjectByKey("rtDataUserId:"+lineId).toString();
|
||||
redisUtil.delete("cldRtDataOverTime:"+lineId);
|
||||
//获取监测点基础信息
|
||||
CsLinePO po = csLineFeignClient.getById(lineId).getData();
|
||||
//获取数据集 dataSet
|
||||
@@ -73,6 +77,8 @@ public class RtServiceImpl implements IRtService {
|
||||
//fixme 这边先根据数据集的名称来返回对应实体,这边感觉不太合适,后期有好方案再调整
|
||||
//基础数据
|
||||
if (dataSet.getName().contains("Ds$Pqd$Rt$Basic$")) {
|
||||
//用户Id
|
||||
String userId = redisUtil.getObjectByKey("rtDataUserId:"+lineId).toString();
|
||||
BaseRealDataSet baseRealDataSet = assembleData(dataArrayList,item,po.getConType());
|
||||
baseRealDataSet.setUserId(userId);
|
||||
baseRealDataSet.setLineId(lineId);
|
||||
@@ -82,9 +88,28 @@ public class RtServiceImpl implements IRtService {
|
||||
long timestamp = item.getDataTimeSec() - 8*3600;
|
||||
baseRealDataSet.setDataTime(getTime(timestamp));
|
||||
publisher.send("/Web/RealData/" + lineId, new Gson().toJson(baseRealDataSet), 1, false);
|
||||
} else if (dataSet.getName().contains("实时数据集合")) {
|
||||
//用户Id
|
||||
Object redisObject = redisUtil.getObjectByKey("rtDataUserId:"+lineId);
|
||||
if (ObjectUtil.isNotNull(redisObject)) {
|
||||
Set<String> userSet = redisSetUtil.convertToSet(redisObject);
|
||||
userSet.forEach(userId->{
|
||||
BaseRealDataSet baseRealDataSet = assembleData(dataArrayList,item,po.getConType());
|
||||
baseRealDataSet.setUserId(userId);
|
||||
baseRealDataSet.setLineId(lineId);
|
||||
baseRealDataSet.setPt(po.getPtRatio().floatValue());
|
||||
baseRealDataSet.setCt(po.getCtRatio().floatValue());
|
||||
baseRealDataSet.setDataLevel(dataSet.getDataLevel());
|
||||
long timestamp = item.getDataTimeSec();
|
||||
baseRealDataSet.setDataTime(getTime(timestamp));
|
||||
publisher.send("/Web/RealData/" + lineId, new Gson().toJson(baseRealDataSet), 1, false);
|
||||
});
|
||||
}
|
||||
}
|
||||
//fixme 目前实时数据只有基础数据和谐波数据,后期拓展,这边需要再判断
|
||||
else {
|
||||
//用户Id
|
||||
String userId = redisUtil.getObjectByKey("rtDataUserId:"+lineId).toString();
|
||||
HarmRealDataSet harmRealDataSet = harmData(dataArrayList,item,dataSet.getDataLevel(),po.getCtRatio());
|
||||
harmRealDataSet.setUserId(userId);
|
||||
harmRealDataSet.setLineId(lineId);
|
||||
@@ -322,4 +347,26 @@ public class RtServiceImpl implements IRtService {
|
||||
return harmRealDataSet;
|
||||
}
|
||||
|
||||
private Set<String> convertObjectToSetSafe(Object obj) {
|
||||
if (obj == null) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
if (obj instanceof Set) {
|
||||
// 类型安全的转换
|
||||
Set<?> rawSet = (Set<?>) obj;
|
||||
return rawSet.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.toSet());
|
||||
} else if (obj instanceof Collection) {
|
||||
return ((Collection<?>) obj).stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.toSet());
|
||||
} else {
|
||||
log.warn("Redis中的对象类型不是Set或Collection: {}", obj.getClass().getName());
|
||||
return new HashSet<>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user