物解析功能
This commit is contained in:
@@ -76,6 +76,10 @@
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.njcn.stat.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.njcn.access.enums.AccessResponseEnum;
|
||||
import com.njcn.access.pojo.dto.CsModelDto;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.common.pojo.response.HttpResult;
|
||||
import com.njcn.common.utils.PubUtils;
|
||||
import com.njcn.csdevice.api.CsLineFeignClient;
|
||||
import com.njcn.csdevice.api.DataArrayFeignClient;
|
||||
@@ -14,24 +14,20 @@ import com.njcn.csdevice.pojo.po.CsLinePO;
|
||||
import com.njcn.influx.pojo.constant.InfluxDBTableConstant;
|
||||
import com.njcn.influxdb.utils.InfluxDbUtils;
|
||||
import com.njcn.mq.message.AppAutoDataMessage;
|
||||
import com.njcn.redis.pojo.enums.AppRedisKey;
|
||||
import com.njcn.redis.utils.RedisUtil;
|
||||
import com.njcn.stat.enums.StatResponseEnum;
|
||||
import com.njcn.stat.service.IStatService;
|
||||
import com.njcn.system.api.DicDataFeignClient;
|
||||
import com.njcn.system.api.EpdFeignClient;
|
||||
import com.njcn.system.enums.DicDataEnum;
|
||||
import com.njcn.system.enums.SystemResponseEnum;
|
||||
import com.njcn.system.pojo.dto.EpdDTO;
|
||||
import com.njcn.system.pojo.po.Dic;
|
||||
import com.njcn.system.pojo.po.DictData;
|
||||
import com.njcn.system.pojo.po.EleEpdPqd;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -73,11 +69,23 @@ public class StatServiceImpl implements IStatService {
|
||||
dataArrayParam.setCldId(appAutoDataMessage.getMsg().getClDid());
|
||||
List<AppAutoDataMessage.DataArray> list = appAutoDataMessage.getMsg().getDataArray();
|
||||
//获取监测点id
|
||||
String lineId = lineInfo(appAutoDataMessage.getId(),appAutoDataMessage.getMsg().getClDid());
|
||||
String lineId = null;
|
||||
Object object1 = redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appAutoDataMessage.getId());
|
||||
if (Objects.isNull(object1)){
|
||||
lineInfo(appAutoDataMessage.getId());
|
||||
}
|
||||
if (Objects.equals(appAutoDataMessage.getDid(),1)){
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appAutoDataMessage.getId())), Map.class).get("0").toString();
|
||||
} else if (Objects.equals(appAutoDataMessage.getDid(),2)){
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appAutoDataMessage.getId())), Map.class).get(appAutoDataMessage.getMsg().getClDid().toString()).toString();
|
||||
}
|
||||
//缓存指标和influxDB表关系
|
||||
saveData();
|
||||
Object object2 = redisUtil.getObjectByKey(AppRedisKey.ELE_EPD_PQD);
|
||||
if(Objects.isNull(object2)) {
|
||||
saveData();
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(list)){
|
||||
list.forEach(item->{
|
||||
for (AppAutoDataMessage.DataArray item : list) {
|
||||
switch (item.getDataAttr()) {
|
||||
case 1:
|
||||
log.info("处理最大值");
|
||||
@@ -98,21 +106,28 @@ public class StatServiceImpl implements IStatService {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
insertData(lineId,dataArrayParam,item);
|
||||
});
|
||||
Object object = redisUtil.getObjectByKey(appAutoDataMessage.getId() + appAutoDataMessage.getDid() + appAutoDataMessage.getMsg().getClDid());
|
||||
List<CsDataArray> dataArrayList;
|
||||
if (Objects.isNull(object)){
|
||||
dataArrayList = saveModelData(dataArrayParam);
|
||||
} else {
|
||||
dataArrayList = objectToList(object);
|
||||
}
|
||||
insertData(lineId,dataArrayList,item,appAutoDataMessage.getMsg().getClDid(),dataArrayParam.getStatMethod());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取监测点相关信息
|
||||
* 缓存监测点相关信息
|
||||
*/
|
||||
public String lineInfo(String id, Integer clDid) {
|
||||
public void lineInfo(String id) {
|
||||
Map<Integer,String> map = new HashMap<>();
|
||||
List<CsLinePO> lineList = csLineFeignClient.findByNdid(id).getData();
|
||||
if (CollectionUtil.isEmpty(lineList)){
|
||||
throw new BusinessException(StatResponseEnum.LINE_NULL);
|
||||
}
|
||||
lineList.forEach(item->{
|
||||
for (CsLinePO item : lineList) {
|
||||
DictData dictData = dicDataFeignClient.getDicDataById(item.getPosition()).getData();
|
||||
if (Objects.isNull(dictData)){
|
||||
throw new BusinessException(StatResponseEnum.DICT_NULL);
|
||||
@@ -124,8 +139,8 @@ public class StatServiceImpl implements IStatService {
|
||||
} else if (Objects.equals(dictData.getCode(), DicDataEnum.GRID_SIDE.getCode())){
|
||||
map.put(2,item.getLineId());
|
||||
}
|
||||
});
|
||||
return map.get(clDid);
|
||||
}
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.LINE_POSITION+id,map,600L);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,19 +155,27 @@ public class StatServiceImpl implements IStatService {
|
||||
list.forEach(item->{
|
||||
map.put(item.getDictName(),item.getTableName());
|
||||
});
|
||||
redisUtil.saveByKeyWithExpire("ELEEPDPQD",map,180L);
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.ELE_EPD_PQD,map,600L);
|
||||
}
|
||||
|
||||
/**
|
||||
* 缓存设备模板信息
|
||||
*/
|
||||
public List<CsDataArray> saveModelData(DataArrayParam dataArrayParam) {
|
||||
String key = dataArrayParam.getId() + dataArrayParam.getDid() + dataArrayParam.getCldId();
|
||||
List<CsDataArray> dataArrayList = dataArrayFeignClient.findListByParam(dataArrayParam).getData();
|
||||
if (CollectionUtil.isEmpty(dataArrayList)){
|
||||
throw new BusinessException(StatResponseEnum.DATA_ARRAY_NULL);
|
||||
}
|
||||
redisUtil.saveByKeyWithExpire(key,dataArrayList,600L);
|
||||
return dataArrayList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* influxDB数据入库
|
||||
*/
|
||||
public void insertData(String lineId,DataArrayParam dataArrayParam,AppAutoDataMessage.DataArray item) {
|
||||
//获取详细数据
|
||||
List<CsDataArray> dataArrayList = dataArrayFeignClient.findListByParam(dataArrayParam).getData();
|
||||
if (CollectionUtil.isEmpty(dataArrayList)){
|
||||
throw new BusinessException(StatResponseEnum.DATA_ARRAY_NULL);
|
||||
}
|
||||
public void insertData(String lineId,List<CsDataArray> dataArrayList,AppAutoDataMessage.DataArray item,Integer clDid,String statMethod) {
|
||||
//解码
|
||||
List<Float> floats = PubUtils.byteArrayToFloatList(Base64.getDecoder().decode(item.getData()));
|
||||
if (CollectionUtil.isEmpty(floats)){
|
||||
@@ -163,14 +186,12 @@ public class StatServiceImpl implements IStatService {
|
||||
throw new BusinessException(StatResponseEnum.ARRAY_DATA_NOT_MATCH);
|
||||
}
|
||||
for (int i = 0; i < dataArrayList.size(); i++) {
|
||||
if (Objects.isNull(redisUtil.getObjectByKey("ELEEPDPQD"))){
|
||||
saveData();
|
||||
}
|
||||
String tableName = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey("ELEEPDPQD")), Map.class).get(dataArrayList.get(i).getName()).toString();
|
||||
String tableName = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.ELE_EPD_PQD)), Map.class).get(dataArrayList.get(i).getName()).toString();
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
tags.put(InfluxDBTableConstant.LINE_ID,lineId);
|
||||
tags.put(InfluxDBTableConstant.PHASIC_TYPE,dataArrayList.get(i).getPhase());
|
||||
tags.put(InfluxDBTableConstant.VALUE_TYPE,dataArrayList.get(i).getStatMethod());
|
||||
tags.put(InfluxDBTableConstant.VALUE_TYPE,statMethod);
|
||||
tags.put(InfluxDBTableConstant.CL_DID,clDid.toString());
|
||||
Map<String,Object> fields = new HashMap<>();
|
||||
fields.put(dataArrayList.get(i).getName(),floats.get(i));
|
||||
fields.put(InfluxDBTableConstant.IS_ABNORMAL,item.getDataTag());
|
||||
@@ -178,4 +199,16 @@ public class StatServiceImpl implements IStatService {
|
||||
}
|
||||
}
|
||||
|
||||
public List<CsDataArray> objectToList(Object object) {
|
||||
List<CsDataArray> urlList = new ArrayList<>();
|
||||
if (object != null) {
|
||||
if (object instanceof ArrayList<?>) {
|
||||
for (Object o : (List<?>) object) {
|
||||
urlList.add((CsDataArray) o);
|
||||
}
|
||||
}
|
||||
}
|
||||
return urlList;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user