代码优化

This commit is contained in:
xy
2024-11-07 15:17:27 +08:00
parent c40cd44402
commit 9f6bb44b3b

View File

@@ -91,6 +91,7 @@ public class EventServiceImpl implements IEventService {
//获取设备类型 true:治理设备 false:其他类型的设备 //获取设备类型 true:治理设备 false:其他类型的设备
boolean devModel = equipmentFeignClient.judgeDevModel(appEventMessage.getId()).getData(); boolean devModel = equipmentFeignClient.judgeDevModel(appEventMessage.getId()).getData();
try { try {
lineId = appEventMessage.getId() + appEventMessage.getMsg().getClDid();
//处理事件数据 //处理事件数据
List<AppEventMessage.DataArray> dataArray = appEventMessage.getMsg().getDataArray(); List<AppEventMessage.DataArray> dataArray = appEventMessage.getMsg().getDataArray();
for (AppEventMessage.DataArray item : dataArray) { for (AppEventMessage.DataArray item : dataArray) {
@@ -112,50 +113,41 @@ public class EventServiceImpl implements IEventService {
csEvent.setType(1); csEvent.setType(1);
} else if (Objects.equals(item.getType(),"1")){ } else if (Objects.equals(item.getType(),"1")){
csEvent.setType(2); 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.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); Map<String,String> map = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.ELE_EPD_PQD)), Map.class);
if (!Objects.isNull(item.getParam())){ //判断是否有参数
List<AppEventMessage.Param> params = item.getParam();
if (CollectionUtil.isNotEmpty(params)) {
String tableName = map.get(item.getName()); String tableName = map.get(item.getName());
List<AppEventMessage.Param> params = item.getParam(); Map<String, String> tags = new HashMap<>();
tags.put(InfluxDBTableConstant.UUID,id);
Map<String,Object> fields = new HashMap<>();
for (AppEventMessage.Param param : params) { for (AppEventMessage.Param param : params) {
Map<String, String> tags = new HashMap<>(); if (Objects.equals(param.getName(),ZlConstant.EVT_PARAM_TM)){
tags.put(InfluxDBTableConstant.UUID,id); csEvent.setPersistTime(Double.parseDouble(param.getData().toString()));
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 {
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());
} }
//fixme 这边前置传递的应该是UTC时间,但是前置说是传递的北京时间,讨论了一下没太理解。这边暂时先这样处理,influx入库处理成北京时间,减去8小时。 fields.put(param.getName(),param.getData());
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());
} }
//只有治理型号的设备有监测位置
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); list1.add(csEvent);
//事件处理日志库 //事件处理日志库
CsEventLogs csEventLogs = new CsEventLogs(); CsEventLogs csEventLogs = new CsEventLogs();