装置文件夹新建、删除
This commit is contained in:
@@ -2,6 +2,7 @@ package com.njcn.zlevent.service.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||
@@ -56,37 +57,46 @@ public class CsAlarmServiceImpl extends ServiceImpl<CsEventMapper, CsEventPO> im
|
||||
try {
|
||||
List<AppEventMessage.DataArray> dataArray = appEventMessage.getMsg().getDataArray();
|
||||
for (AppEventMessage.DataArray item : dataArray) {
|
||||
//事件入库
|
||||
CsEventPO csEvent = new CsEventPO();
|
||||
csEvent.setId(id);
|
||||
csEvent.setDeviceId(po.getId());
|
||||
csEvent.setProcess(po.getProcess());
|
||||
csEvent.setCode(item.getCode());
|
||||
eventTime = eventService.timeFormat(item.getDataTimeSec(),item.getDataTimeUSec());
|
||||
csEvent.setStartTime(eventTime);
|
||||
tag = item.getName();
|
||||
csEvent.setTag(tag);
|
||||
csEvent.setType(3);
|
||||
csEvent.setClDid(appEventMessage.getMsg().getClDid());
|
||||
csEvent.setLevel(Integer.parseInt(item.getType()));
|
||||
csEvent.setCode(item.getCode());
|
||||
list1.add(csEvent);
|
||||
LambdaQueryWrapper<CsEventPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(CsEventPO::getDeviceId,po.getId())
|
||||
.eq(CsEventPO::getProcess,po.getProcess())
|
||||
.eq(CsEventPO::getCode,item.getCode())
|
||||
.eq(CsEventPO::getStartTime,eventTime)
|
||||
.eq(CsEventPO::getTag,item.getName());
|
||||
List<CsEventPO> list = csEventService.list(wrapper);
|
||||
if (CollectionUtil.isEmpty(list)) {
|
||||
//事件入库
|
||||
CsEventPO csEvent = new CsEventPO();
|
||||
csEvent.setId(id);
|
||||
csEvent.setDeviceId(po.getId());
|
||||
csEvent.setProcess(po.getProcess());
|
||||
csEvent.setCode(item.getCode());
|
||||
csEvent.setStartTime(eventTime);
|
||||
tag = item.getName();
|
||||
csEvent.setTag(tag);
|
||||
csEvent.setType(3);
|
||||
csEvent.setClDid(appEventMessage.getMsg().getClDid());
|
||||
csEvent.setLevel(Integer.parseInt(item.getType()));
|
||||
csEvent.setCode(item.getCode());
|
||||
list1.add(csEvent);
|
||||
}
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(list1)){
|
||||
csEventService.saveBatch(list1);
|
||||
}
|
||||
//推送事件逻辑处理 && cs_event_user入库 && 修改字典中告警事件的编码
|
||||
for (AppEventMessage.DataArray item : dataArray) {
|
||||
if (Objects.isNull(item.getCode())){
|
||||
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getName(),eventTime,id);
|
||||
} else {
|
||||
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getCode(),eventTime,id);
|
||||
//更新字典信息
|
||||
EleEpdPqd eleEpdPqd = epdFeignClient.findByName(item.getName()).getData();
|
||||
EleEpdPqdParam.EleEpdPqdUpdateParam updateParam = new EleEpdPqdParam.EleEpdPqdUpdateParam();
|
||||
BeanUtils.copyProperties(eleEpdPqd,updateParam);
|
||||
updateParam.setDefaultValue(item.getCode());
|
||||
epdFeignClient.update(updateParam);
|
||||
//推送事件逻辑处理 && cs_event_user入库 && 修改字典中告警事件的编码
|
||||
for (AppEventMessage.DataArray item : dataArray) {
|
||||
if (Objects.isNull(item.getCode())){
|
||||
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getName(),eventTime,id);
|
||||
} else {
|
||||
sendEventUtils.sendUser(2,item.getType(),po.getId(),item.getCode(),eventTime,id);
|
||||
//更新字典信息
|
||||
EleEpdPqd eleEpdPqd = epdFeignClient.findByName(item.getName()).getData();
|
||||
EleEpdPqdParam.EleEpdPqdUpdateParam updateParam = new EleEpdPqdParam.EleEpdPqdUpdateParam();
|
||||
BeanUtils.copyProperties(eleEpdPqd,updateParam);
|
||||
updateParam.setDefaultValue(item.getCode());
|
||||
epdFeignClient.update(updateParam);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.njcn.zlevent.service.impl;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.nacos.shaded.com.google.gson.Gson;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.njcn.common.pojo.exception.BusinessException;
|
||||
import com.njcn.csdevice.api.CsLineFeignClient;
|
||||
import com.njcn.csdevice.api.EquipmentFeignClient;
|
||||
@@ -92,88 +93,99 @@ public class EventServiceImpl implements IEventService {
|
||||
//处理事件数据
|
||||
List<AppEventMessage.DataArray> dataArray = appEventMessage.getMsg().getDataArray();
|
||||
for (AppEventMessage.DataArray item : dataArray) {
|
||||
id = IdUtil.fastSimpleUUID();
|
||||
//事件入库
|
||||
CsEventPO csEvent = new CsEventPO();
|
||||
csEvent.setId(id);
|
||||
csEvent.setDeviceId(po.getId());
|
||||
csEvent.setProcess(po.getProcess());
|
||||
csEvent.setCode(item.getCode());
|
||||
eventTime = timeFormat(item.getDataTimeSec(),item.getDataTimeUSec());
|
||||
csEvent.setStartTime(eventTime);
|
||||
tag = item.getName();
|
||||
csEvent.setTag(tag);
|
||||
if (Objects.equals(item.getType(),"2")){
|
||||
csEvent.setType(0);
|
||||
} else if (Objects.equals(item.getType(),"3")){
|
||||
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("0").toString();
|
||||
csEvent.setClDid(appEventMessage.getMsg().getClDid());
|
||||
}
|
||||
csEvent.setLevel(Integer.parseInt(item.getType()));
|
||||
//参数入库
|
||||
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) {
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
tags.put(InfluxDBTableConstant.UUID,id);
|
||||
Map<String,Object> fields = new HashMap<>();
|
||||
if (Objects.equals(ZlConstant.EVENT_POSITION,param.getName())){
|
||||
if (Objects.equals(param.getData(),ZlConstant.GRID)){
|
||||
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);
|
||||
} else if (Objects.equals(param.getData(),ZlConstant.LOAD)){
|
||||
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(param.getData().toString());
|
||||
} 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(),appEventMessage.getMsg().getClDid()==1?"电网侧":"负载侧");
|
||||
csEvent.setLocation(appEventMessage.getMsg().getClDid()==1?ZlConstant.GRID:ZlConstant.LOAD);
|
||||
csEvent.setClDid(appEventMessage.getMsg().getClDid());
|
||||
fields.put(param.getName(),param.getData());
|
||||
}
|
||||
//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());
|
||||
//此处做限制,如果已有事件则不在记录通知
|
||||
LambdaQueryWrapper<CsEventPO> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(CsEventPO::getDeviceId,po.getId())
|
||||
.eq(CsEventPO::getProcess,po.getProcess())
|
||||
.eq(CsEventPO::getCode,item.getCode())
|
||||
.eq(CsEventPO::getStartTime,eventTime)
|
||||
.eq(CsEventPO::getTag,item.getName());
|
||||
List<CsEventPO> list = csEventService.list(wrapper);
|
||||
if (CollectionUtil.isEmpty(list)) {
|
||||
id = IdUtil.fastSimpleUUID();
|
||||
//事件入库
|
||||
CsEventPO csEvent = new CsEventPO();
|
||||
csEvent.setId(id);
|
||||
csEvent.setDeviceId(po.getId());
|
||||
csEvent.setProcess(po.getProcess());
|
||||
csEvent.setCode(item.getCode());
|
||||
eventTime = timeFormat(item.getDataTimeSec(),item.getDataTimeUSec());
|
||||
csEvent.setStartTime(eventTime);
|
||||
tag = item.getName();
|
||||
csEvent.setTag(tag);
|
||||
if (Objects.equals(item.getType(),"2")){
|
||||
csEvent.setType(0);
|
||||
} else if (Objects.equals(item.getType(),"3")){
|
||||
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("0").toString();
|
||||
csEvent.setClDid(appEventMessage.getMsg().getClDid());
|
||||
}
|
||||
csEvent.setLevel(Integer.parseInt(item.getType()));
|
||||
//参数入库
|
||||
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) {
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
tags.put(InfluxDBTableConstant.UUID,id);
|
||||
Map<String,Object> fields = new HashMap<>();
|
||||
if (Objects.equals(ZlConstant.EVENT_POSITION,param.getName())){
|
||||
if (Objects.equals(param.getData(),ZlConstant.GRID)){
|
||||
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);
|
||||
} else if (Objects.equals(param.getData(),ZlConstant.LOAD)){
|
||||
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(param.getData().toString());
|
||||
} 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(),appEventMessage.getMsg().getClDid()==1?"电网侧":"负载侧");
|
||||
csEvent.setLocation(appEventMessage.getMsg().getClDid()==1?ZlConstant.GRID:ZlConstant.LOAD);
|
||||
csEvent.setClDid(appEventMessage.getMsg().getClDid());
|
||||
fields.put(param.getName(),param.getData());
|
||||
}
|
||||
//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();
|
||||
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);
|
||||
}
|
||||
csEvent.setLineId(lineId);
|
||||
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);
|
||||
//推送事件逻辑处理 && cs_event_user入库
|
||||
for (AppEventMessage.DataArray item : dataArray) {
|
||||
sendEventUtils.sendUser(1,item.getType(),po.getId(),item.getName(),eventTime,id);
|
||||
}
|
||||
}
|
||||
//evt_data入库
|
||||
if (CollectionUtil.isNotEmpty(records)) {
|
||||
influxDbUtils.batchInsert(influxDbUtils.getDbName(), "", InfluxDB.ConsistencyLevel.ALL, TimeUnit.MILLISECONDS, records);
|
||||
}
|
||||
//推送事件逻辑处理 && cs_event_user入库
|
||||
for (AppEventMessage.DataArray item : dataArray) {
|
||||
sendEventUtils.sendUser(1,item.getType(),po.getId(),item.getName(),eventTime,id);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CsEventLogs csEventLogs = new CsEventLogs();
|
||||
csEventLogs.setLineId(lineId);
|
||||
|
||||
@@ -258,11 +258,8 @@ public class FileServiceImpl implements IFileService {
|
||||
csEventLogs.setAllStep(appFileMessage.getMsg().getFrameTotal());
|
||||
csEventLogs.setIsAll(0);
|
||||
redisUtil.saveByKey(AppRedisKey.FILE_PART.concat(appFileMessage.getMsg().getName()), dto);
|
||||
long time1 = System.currentTimeMillis();
|
||||
//将数据写入临时文件
|
||||
appendFile(lsFileName, appFileMessage.getMsg().getFrameCurr(), appFileMessage.getMsg().getData());
|
||||
long time2 = System.currentTimeMillis();
|
||||
System.out.println("time==:" + (time2 - time1));
|
||||
log.info("当前文件 {} 帧,这是第 {} 帧报文,记录成功", appFileMessage.getMsg().getFrameTotal(), appFileMessage.getMsg().getFrameCurr());
|
||||
if (Objects.isNull(object2)) {
|
||||
redisUtil.saveByKeyWithExpire(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName()), null, 10L);
|
||||
|
||||
Reference in New Issue
Block a user