From f227fe3c3f03f0d5c8d40e0d9cba9d0f87fa953a Mon Sep 17 00:00:00 2001 From: xy <748613696@qq.com> Date: Thu, 26 Mar 2026 18:52:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E6=80=81=E4=BA=8B=E4=BB=B6=E5=90=8C?= =?UTF-8?q?=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../stat/service/impl/StatServiceImpl.java | 1 + .../zlevent/pojo/constant/ZlConstant.java | 5 +- .../service/impl/EventServiceImpl.java | 108 ++++++++++++++---- .../zlevent/service/impl/FileServiceImpl.java | 18 ++- 4 files changed, 101 insertions(+), 31 deletions(-) diff --git a/iot-analysis/analysis-stat/stat-boot/src/main/java/com/njcn/stat/service/impl/StatServiceImpl.java b/iot-analysis/analysis-stat/stat-boot/src/main/java/com/njcn/stat/service/impl/StatServiceImpl.java index 65d527f..cd28333 100644 --- a/iot-analysis/analysis-stat/stat-boot/src/main/java/com/njcn/stat/service/impl/StatServiceImpl.java +++ b/iot-analysis/analysis-stat/stat-boot/src/main/java/com/njcn/stat/service/impl/StatServiceImpl.java @@ -160,6 +160,7 @@ public class StatServiceImpl implements IStatService { csLineLatestDataFeignClient.addData(csLineLatestData); } } + System.gc(); } /** diff --git a/iot-analysis/analysis-zl-event/zl-event-api/src/main/java/com/njcn/zlevent/pojo/constant/ZlConstant.java b/iot-analysis/analysis-zl-event/zl-event-api/src/main/java/com/njcn/zlevent/pojo/constant/ZlConstant.java index 4fd3594..9657d64 100644 --- a/iot-analysis/analysis-zl-event/zl-event-api/src/main/java/com/njcn/zlevent/pojo/constant/ZlConstant.java +++ b/iot-analysis/analysis-zl-event/zl-event-api/src/main/java/com/njcn/zlevent/pojo/constant/ZlConstant.java @@ -41,6 +41,9 @@ public interface ZlConstant { */ String EVT_PARAM_TM = "Evt_Param_Tm"; - + /** + * 幅值 + */ + String EVT_PARAM_VVADEPTH = "Evt_Param_VVaDepth"; } 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 d6a95bc..b51e452 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 @@ -2,7 +2,9 @@ package com.njcn.zlevent.service.impl; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.ObjectUtil; import com.alibaba.nacos.shaded.com.google.gson.Gson; +import com.baomidou.dynamic.datasource.annotation.DSTransactional; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.njcn.common.pojo.exception.BusinessException; import com.njcn.csdevice.api.CsLineFeignClient; @@ -14,6 +16,8 @@ import com.njcn.csdevice.pojo.po.CsLinePO; import com.njcn.csdevice.pojo.po.WlRecord; import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO; import com.njcn.csharmonic.pojo.po.CsEventPO; +import com.njcn.event.common.mapper.WlRmpEventDetailMapper; +import com.njcn.event.pojo.po.RmpEventDetailPO; import com.njcn.influx.pojo.constant.InfluxDBTableConstant; import com.njcn.influx.utils.InfluxDbUtils; import com.njcn.mq.message.AppEventMessage; @@ -27,7 +31,6 @@ import com.njcn.system.enums.DicDataEnum; import com.njcn.system.pojo.dto.EpdDTO; import com.njcn.system.pojo.po.DictData; import com.njcn.zlevent.pojo.constant.ZlConstant; -import com.njcn.zlevent.pojo.po.CsEventLogs; import com.njcn.zlevent.service.ICsEventLogsService; import com.njcn.zlevent.service.ICsEventService; import com.njcn.zlevent.service.IEventService; @@ -49,6 +52,7 @@ import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; /** * 类的介绍: @@ -72,9 +76,10 @@ public class EventServiceImpl implements IEventService { private final ICsEventLogsService csEventLogsService; private final SendEventUtils sendEventUtils; private final WlRecordFeignClient wlRecordFeignClient; + private final WlRmpEventDetailMapper wlRmpEventDetailMapper; @Override - @Transactional(rollbackFor = Exception.class) + @DSTransactional public void analysis(AppEventMessage appEventMessage) { List list1 = new ArrayList<>(); List records = new ArrayList(); @@ -96,12 +101,21 @@ public class EventServiceImpl implements IEventService { try { if (devModel) { if (Objects.equals(appEventMessage.getDid(),1)){ - lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get("0").toString(); + Object object = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get("0"); + if (ObjectUtil.isNotNull(object)) { + lineId = object.toString(); + } } else if (Objects.equals(appEventMessage.getDid(),2)){ - lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get(appEventMessage.getMsg().getClDid().toString()).toString(); + Object object = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get(appEventMessage.getMsg().getClDid().toString()); + if (ObjectUtil.isNotNull(object)) { + lineId = object.toString(); + } } } else { - lineId = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get(appEventMessage.getMsg().getClDid().toString()).toString(); + Object object = new Gson().fromJson(String.valueOf(redisUtil.getObjectByKey(AppRedisKey.LINE_POSITION+appEventMessage.getId())), Map.class).get(appEventMessage.getMsg().getClDid().toString()); + if (ObjectUtil.isNotNull(object)) { + lineId = object.toString(); + } } //处理事件数据 @@ -111,9 +125,9 @@ public class EventServiceImpl implements IEventService { //判断事件是否存在,如果存在则不处理 LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(CsEventPO::getDeviceId,po.getId()) - .eq(CsEventPO::getTag,tag) + .eq(CsEventPO::getTag,item.getName()) .eq(CsEventPO::getStartTime,eventTime) - .eq(CsEventPO::getLineId,lineId); + .eq(ObjectUtil.isNotNull(lineId),CsEventPO::getLineId,lineId); List eventList = csEventService.list(queryWrapper); if (CollectionUtil.isEmpty(eventList)) { id = IdUtil.fastSimpleUUID(); @@ -150,6 +164,9 @@ public class EventServiceImpl implements IEventService { if (Objects.equals(param.getName(),ZlConstant.EVT_PARAM_TM)){ csEvent.setPersistTime(Double.parseDouble(param.getData().toString())); } + if (Objects.equals(param.getName(),ZlConstant.EVT_PARAM_VVADEPTH)) { + csEvent.setAmplitude(Double.parseDouble(param.getData().toString())); + } fields.put(param.getName(),param.getData()); } //只有治理型号的设备有监测位置 @@ -169,20 +186,16 @@ public class EventServiceImpl implements IEventService { records.add(batchPoints.lineProtocol()); } list1.add(csEvent); - //事件处理日志库 - CsEventLogs csEventLogs = new CsEventLogs(); - csEventLogs.setLineId(lineId); - csEventLogs.setDeviceId(po.getId()); - csEventLogs.setStartTime(timeFormat(item.getDataTimeSec(),item.getDataTimeUSec())); - csEventLogs.setTag(item.getName()); - csEventLogs.setStatus(1); - csEventLogs.setTime(LocalDateTime.now()); - csEventLogsService.save(csEventLogs); } } //cs_event入库 if (CollectionUtil.isNotEmpty(list1)){ csEventService.saveBatch(list1); + //同步数据到 r_mp_event_detail 只有暂态事件再同步 + List filterList = list1.stream().filter(csEvent -> Objects.equals(csEvent.getType(), 0)).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(filterList)) { + filterList.forEach(this::insertEvent); + } //推送事件逻辑处理 && cs_event_user入库 for (AppEventMessage.DataArray item : dataArray) { sendEventUtils.sendUser(1,item.getType(),po.getId(),item.getName(),eventTime,id,po.getNdid()); @@ -193,18 +206,63 @@ public class EventServiceImpl implements IEventService { influxDbUtils.batchInsert(influxDbUtils.getDbName(), "", InfluxDB.ConsistencyLevel.ALL, TimeUnit.MILLISECONDS, records); } } catch (Exception e) { - CsEventLogs csEventLogs = new CsEventLogs(); - csEventLogs.setLineId(lineId); - csEventLogs.setDeviceId(po.getId()); - csEventLogs.setStartTime(eventTime); - csEventLogs.setTag(tag); - csEventLogs.setStatus(0); - csEventLogs.setTime(LocalDateTime.now()); - csEventLogs.setRemark(e.getMessage()); - csEventLogsService.save(csEventLogs); + log.error("事件入库异常:{}",e.getMessage()); } } + public void insertEvent(CsEventPO item) { + RmpEventDetailPO rmpEventDetailPo = new RmpEventDetailPO(); + rmpEventDetailPo.setEventId(item.getId()); + rmpEventDetailPo.setMeasurementPointId(item.getLineId()); + rmpEventDetailPo.setStartTime(item.getStartTime()); + rmpEventDetailPo.setEventType(getEventType(item.getTag())); + rmpEventDetailPo.setFeatureAmplitude(item.getAmplitude()); + rmpEventDetailPo.setDuration(item.getPersistTime()); + rmpEventDetailPo.setEventDescribe(getTag(item.getTag())); + rmpEventDetailPo.setDealFlag(0); + rmpEventDetailPo.setFileFlag(0); + wlRmpEventDetailMapper.insert(rmpEventDetailPo); + } + + public String getEventType(String tag) { + switch (tag) { + case "Evt_Sys_DipStr": + DictData dip = dicDataFeignClient.getDicDataByCode(DicDataEnum.VOLTAGE_DIP.getCode()).getData(); + tag = dip.getId(); + break; + case "Evt_Sys_SwlStr": + DictData rise = dicDataFeignClient.getDicDataByCode(DicDataEnum.VOLTAGE_RISE.getCode()).getData(); + tag = rise.getId(); + break; + case "Evt_Sys_IntrStr": + DictData interruptions = dicDataFeignClient.getDicDataByCode(DicDataEnum.SHORT_INTERRUPTIONS.getCode()).getData(); + tag = interruptions.getId(); + break; + default: + tag = "Un_Know"; + break; + } + return tag; + } + + public String getTag(String tag) { + switch (tag) { + case "Evt_Sys_DipStr": + tag = DicDataEnum.VOLTAGE_DIP.getCode(); + break; + case "Evt_Sys_SwlStr": + tag = DicDataEnum.VOLTAGE_RISE.getCode(); + break; + case "Evt_Sys_IntrStr": + tag = DicDataEnum.SHORT_INTERRUPTIONS.getCode(); + break; + default: + tag = "Un_Know"; + break; + } + return tag; + } + @Override @Transactional(rollbackFor = Exception.class) public void getPortableData(AppEventMessage appEventMessage) { diff --git a/iot-analysis/analysis-zl-event/zl-event-boot/src/main/java/com/njcn/zlevent/service/impl/FileServiceImpl.java b/iot-analysis/analysis-zl-event/zl-event-boot/src/main/java/com/njcn/zlevent/service/impl/FileServiceImpl.java index 06fafef..ad1614f 100644 --- a/iot-analysis/analysis-zl-event/zl-event-boot/src/main/java/com/njcn/zlevent/service/impl/FileServiceImpl.java +++ b/iot-analysis/analysis-zl-event/zl-event-boot/src/main/java/com/njcn/zlevent/service/impl/FileServiceImpl.java @@ -294,9 +294,13 @@ public class FileServiceImpl implements IFileService { //波形文件关联事件 filePath = filePath.replaceAll(GeneralConstant.CFG,"").replaceAll(GeneralConstant.DAT,""); List eventList = correlateEvents(fileInfoDto,filePath,fileName); - //波形文件解析成图片 if (CollectionUtil.isNotEmpty(eventList) && devModel){ - eventList.forEach(wavePicFeignClient::getWavePics); + eventList.forEach(item -> { + //波形文件解析成图片 + wavePicFeignClient.getWavePics(item); + //同步更新r_mp_event_detail,将波形路径录入 + wavePicFeignClient.updateEventById(item); + }); } //解析完删除、处理缓存 removeInfoUtils.deleteEventInfo(appFileMessage.getId(),fileName); @@ -340,9 +344,13 @@ public class FileServiceImpl implements IFileService { //波形文件关联事件 filePath = filePath.replaceAll(GeneralConstant.CFG, "").replaceAll(GeneralConstant.DAT, ""); List eventList = correlateEvents(fileInfoDto, filePath, fileName); - //波形文件解析成图片 - if (CollectionUtil.isNotEmpty(eventList) && devModel) { - eventList.forEach(wavePicFeignClient::getWavePics); + if (CollectionUtil.isNotEmpty(eventList) && devModel){ + eventList.forEach(item -> { + //波形文件解析成图片 + wavePicFeignClient.getWavePics(item); + //同步更新r_mp_event_detail,将波形路径录入 + wavePicFeignClient.updateEventById(item); + }); } redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName())); redisUtil.delete(AppRedisKey.FILE_PART.concat(appFileMessage.getMsg().getName()));