diff --git a/iot-analysis/analysis-zl-event/zl-event-boot/src/main/java/com/njcn/zlevent/service/impl/EventServiceImpl.java b/iot-analysis/analysis-zl-event/zl-event-boot/src/main/java/com/njcn/zlevent/service/impl/EventServiceImpl.java index 2c4f7d1..66592ab 100644 --- a/iot-analysis/analysis-zl-event/zl-event-boot/src/main/java/com/njcn/zlevent/service/impl/EventServiceImpl.java +++ b/iot-analysis/analysis-zl-event/zl-event-boot/src/main/java/com/njcn/zlevent/service/impl/EventServiceImpl.java @@ -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 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 map = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.ELE_EPD_PQD)), Map.class); - if (!Objects.isNull(item.getParam())){ + //判断是否有参数 + List params = item.getParam(); + if (CollectionUtil.isNotEmpty(params)) { String tableName = map.get(item.getName()); - List params = item.getParam(); + Map tags = new HashMap<>(); + tags.put(InfluxDBTableConstant.UUID,id); + Map fields = new HashMap<>(); for (AppEventMessage.Param param : params) { - Map tags = new HashMap<>(); - tags.put(InfluxDBTableConstant.UUID,id); - Map 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()); + if (Objects.equals(param.getName(),ZlConstant.EVT_PARAM_TM)){ + csEvent.setPersistTime(Double.parseDouble(param.getData().toString())); } - //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()); + 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();