代码优化
This commit is contained in:
@@ -91,6 +91,7 @@ public class EventServiceImpl implements IEventService {
|
||||
//获取设备类型 true:治理设备 false:其他类型的设备
|
||||
boolean devModel = equipmentFeignClient.judgeDevModel(appEventMessage.getId()).getData();
|
||||
try {
|
||||
lineId = appEventMessage.getId() + appEventMessage.getMsg().getClDid();
|
||||
//处理事件数据
|
||||
List<AppEventMessage.DataArray> dataArray = appEventMessage.getMsg().getDataArray();
|
||||
for (AppEventMessage.DataArray item : dataArray) {
|
||||
@@ -112,50 +113,41 @@ public class EventServiceImpl implements IEventService {
|
||||
csEvent.setType(1);
|
||||
} else if (Objects.equals(item.getType(),"1")){
|
||||
csEvent.setType(2);
|
||||
//lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get(appEventMessage.getId()).toString();
|
||||
csEvent.setClDid(appEventMessage.getMsg().getClDid());
|
||||
}
|
||||
csEvent.setLevel(Integer.parseInt(item.getType()));
|
||||
csEvent.setClDid(appEventMessage.getMsg().getClDid());
|
||||
csEvent.setLineId(lineId);
|
||||
//参数入库
|
||||
Map<String,String> map = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.ELE_EPD_PQD)), Map.class);
|
||||
if (!Objects.isNull(item.getParam())){
|
||||
String tableName = map.get(item.getName());
|
||||
//判断是否有参数
|
||||
List<AppEventMessage.Param> params = item.getParam();
|
||||
for (AppEventMessage.Param param : params) {
|
||||
if (CollectionUtil.isNotEmpty(params)) {
|
||||
String tableName = map.get(item.getName());
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
tags.put(InfluxDBTableConstant.UUID,id);
|
||||
Map<String,Object> fields = new HashMap<>();
|
||||
//只有治理型号的设备有监测位置
|
||||
if (devModel) {
|
||||
if (appEventMessage.getMsg().getClDid() == 1) {
|
||||
fields.put(param.getName(),"电网侧");
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get("1").toString();
|
||||
csEvent.setClDid(1);
|
||||
csEvent.setLocation("grid");
|
||||
} else if (appEventMessage.getMsg().getClDid() == 2) {
|
||||
fields.put(param.getName(),"负载侧");
|
||||
lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get("2").toString();
|
||||
csEvent.setClDid(2);
|
||||
csEvent.setLocation("load");
|
||||
}
|
||||
} else {
|
||||
for (AppEventMessage.Param param : params) {
|
||||
if (Objects.equals(param.getName(),ZlConstant.EVT_PARAM_TM)){
|
||||
csEvent.setPersistTime(Double.parseDouble(param.getData().toString()));
|
||||
}
|
||||
lineId = appEventMessage.getId() + appEventMessage.getMsg().getClDid();
|
||||
fields.put(param.getName(),null);
|
||||
csEvent.setLocation(null);
|
||||
csEvent.setClDid(appEventMessage.getMsg().getClDid());
|
||||
fields.put(param.getName(),param.getData());
|
||||
}
|
||||
//只有治理型号的设备有监测位置
|
||||
if (devModel) {
|
||||
if (appEventMessage.getMsg().getClDid() == 1) {
|
||||
fields.put("Evt_Param_Position","电网侧");
|
||||
csEvent.setLocation("grid");
|
||||
} else if (appEventMessage.getMsg().getClDid() == 2) {
|
||||
fields.put("Evt_Param_Position","负载侧");
|
||||
csEvent.setLocation("load");
|
||||
}
|
||||
}
|
||||
//fixme 这边前置传递的应该是UTC时间,但是前置说是传递的北京时间,讨论了一下没太理解。这边暂时先这样处理,influx入库处理成北京时间,减去8小时。
|
||||
Point point = influxDbUtils.pointBuilder(tableName, item.getDataTimeSec()-8*3600, TimeUnit.SECONDS, tags, fields);
|
||||
BatchPoints batchPoints = BatchPoints.database(influxDbUtils.getDbName()).retentionPolicy("").consistency(InfluxDB.ConsistencyLevel.ALL).build();
|
||||
batchPoints.point(point);
|
||||
records.add(batchPoints.lineProtocol());
|
||||
}
|
||||
}
|
||||
csEvent.setLineId(lineId);
|
||||
list1.add(csEvent);
|
||||
//事件处理日志库
|
||||
CsEventLogs csEventLogs = new CsEventLogs();
|
||||
|
||||
Reference in New Issue
Block a user