1.暂降事件归集功能调整

This commit is contained in:
2024-12-06 16:40:24 +08:00
parent da3e897fc2
commit 7e130e9eb0
18 changed files with 712 additions and 166 deletions

View File

@@ -1,36 +1,17 @@
package com.njcn.advance.pojo.dto.relevent;
import com.njcn.advance.pojo.dto.SagEvent;
import lombok.Data;
@Data
public class EntityGroupEvtData implements Cloneable,Comparable<EntityGroupEvtData> {
//逻辑节点序号
private int node;
//事件开始时间时标
private int start_time;
//类别
private int cata;
//标注类别
private int cata2;
//物理节点
private String nodePhysics;
private int node;//逻辑节点序号
private int start_time;//事件开始时间时标
private int cata;//类别
private int cata2;//标注类别
private String nodePhysics; //物理节点
private SagEvent sagEvent;
private String sagReason;
public Object objClone() {
try {
return clone();
} catch (CloneNotSupportedException e) {
return new EntityGroupEvtData(null, -1, -1, -1,null,null);
}
}
public EntityGroupEvtData(String nodePhysics, int start_time, int cata, int cata2, SagEvent sagEvent, String sagReason) {
public EntityGroupEvtData(String nodePhysics, int start_time, int cata, int cata2,SagEvent sagEvent,String sagReason) {
this.nodePhysics = nodePhysics;
this.start_time = start_time;
this.cata = cata;
@@ -39,6 +20,144 @@ public class EntityGroupEvtData implements Cloneable,Comparable<EntityGroupEvtDa
this.sagReason = sagReason;
}
public SagEvent getSagEvent() {
return sagEvent;
}
public void setSagEvent(SagEvent sagEvent) {
this.sagEvent = sagEvent;
}
public String getNodePhysics() {
return nodePhysics;
}
public void setNodePhysics(String nodePhysics) {
this.nodePhysics = nodePhysics;
}
public int getNode() {
return node;
}
public void setNode(int node) {
this.node = node;
}
public int getStart_time() {
return start_time;
}
public void setStart_time(int start_time) {
this.start_time = start_time;
}
public int getCata() {
return cata;
}
public void setCata(int cata) {
this.cata = cata;
}
public int getCata2() {
return cata2;
}
public void setCata2(int cata2) {
this.cata2 = cata2;
}
public String getSagReason() {
return sagReason;
}
public void setSagReason(String sagReason) {
this.sagReason = sagReason;
}
/**
* Creates and returns a copy of this object. The precise meaning
* of "copy" may depend on the class of the object. The general
* intent is that, for any object {@code x}, the expression:
* <blockquote>
* <pre>
* x.clone() != x</pre></blockquote>
* will be true, and that the expression:
* <blockquote>
* <pre>
* x.clone().getClass() == x.getClass()</pre></blockquote>
* will be {@code true}, but these are not absolute requirements.
* While it is typically the case that:
* <blockquote>
* <pre>
* x.clone().equals(x)</pre></blockquote>
* will be {@code true}, this is not an absolute requirement.
*
* By convention, the returned object should be obtained by calling
* {@code super.clone}. If a class and all of its superclasses (except
* {@code Object}) obey this convention, it will be the case that
* {@code x.clone().getClass() == x.getClass()}.
*
* By convention, the object returned by this method should be independent
* of this object (which is being cloned). To achieve this independence,
* it may be necessary to modify one or more fields of the object returned
* by {@code super.clone} before returning it. Typically, this means
* copying any mutable objects that comprise the internal "deep structure"
* of the object being cloned and replacing the references to these
* objects with references to the copies. If a class contains only
* primitive fields or references to immutable objects, then it is usually
* the case that no fields in the object returned by {@code super.clone}
* need to be modified.
*
* The method {@code clone} for class {@code Object} performs a
* specific cloning operation. First, if the class of this object does
* not implement the interface {@code Cloneable}, then a
* {@code CloneNotSupportedException} is thrown. Note that all arrays
* are considered to implement the interface {@code Cloneable} and that
* the return type of the {@code clone} method of an array type {@code T[]}
* is {@code T[]} where T is any reference or primitive type.
* Otherwise, this method creates a new instance of the class of this
* object and initializes all its fields with exactly the contents of
* the corresponding fields of this object, as if by assignment; the
* contents of the fields are not themselves cloned. Thus, this method
* performs a "shallow copy" of this object, not a "deep copy" operation.
*
* The class {@code Object} does not itself implement the interface
* {@code Cloneable}, so calling the {@code clone} method on an object
* whose class is {@code Object} will result in throwing an
* exception at run time.
*
* @return a clone of this instance.
* @throws CloneNotSupportedException if the object's class does not
* support the {@code Cloneable} interface. Subclasses
* that override the {@code clone} method can also
* throw this exception to indicate that an instance cannot
* be cloned.
* @see Cloneable
*/
@Override
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
public Object objClone() {
try {
return clone();
} catch (CloneNotSupportedException e) {
return new EntityGroupEvtData("-1", -1, -1, -1,null,null);
}
}
@Override
public String toString() {
return "EntityGroupEvtData{" +
"node=" + node +
", start_time=" + start_time +
", cata=" + cata +
", cata2=" + cata2 +
'}';
}
@Override
public int compareTo(EntityGroupEvtData obj) {
@@ -50,4 +169,4 @@ public class EntityGroupEvtData implements Cloneable,Comparable<EntityGroupEvtDa
return 0;
}
}
}

View File

@@ -8,9 +8,9 @@ public class EntityLogic {
//物理隔绝变压器策略GUID
private String tPIndex;
//变压器逻辑上节点
private String node_h;
private Integer node_h;
//变压器逻辑下节点
private String node_l;
private Integer node_l;
// 变压器连接方式
private Integer type;
//变压器物理上节点

View File

@@ -16,10 +16,10 @@ public class EntityMtrans implements Serializable {
public EntityMtrans() {
super();
Mtrans = new int[FinalData.NODE_NUM][FinalData.NODE_NUM];
Matrixcata0 = new int[FinalData.EVT_TYPE_NUM][FinalData.NODE_NUM];
Matrixcata1 = new int[FinalData.EVT_TYPE_NUM][FinalData.NODE_NUM];
possiable_path = new int[FinalData.MAX_PATH_NUM][FinalData.NODE_NUM + 1];
path_num = 0;
Matrixcata0 = new int[FinalData.EVT_TYPE_NUM][FinalData.NODE_NUM];
Matrixcata1 = new int[FinalData.EVT_TYPE_NUM][FinalData.NODE_NUM];
possiable_path = new int[FinalData.MAX_PATH_NUM][FinalData.NODE_NUM + 1];
path_num = 0;
}
public int[][] getMatrixcata0() {
@@ -69,3 +69,4 @@ public class EntityMtrans implements Serializable {
+ Arrays.toString(possiable_path) + ", path_num=" + path_num + "]";
}
}

View File

@@ -1,6 +1,6 @@
package com.njcn.advance.pojo.dto.relevent;
import com.njcn.advance.pojo.dto.SagEvent;
import lombok.Data;
import java.io.Serializable;

View File

@@ -1,4 +1,4 @@
package com.njcn.advance.pojo.dto;
package com.njcn.advance.pojo.dto.relevent;
import com.njcn.advance.pojo.dto.relevent.PlantInfo;

View File

@@ -0,0 +1,71 @@
package com.njcn.advance.utils;
import cn.hutool.core.codec.Base64;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.io.*;
@Component
public class InstantiateUtil<E> {
private static final Logger logger= LoggerFactory.getLogger(InstantiateUtil.class);
public byte[] instantiate(E e) {
if (e == null) {
return null;
}
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(e);
objectOutputStream.close();
return byteArrayOutputStream.toByteArray();
} catch (IOException e1) {
logger.error("发生异常,"+e1.getMessage());
}
return null;
}
public <E> E deInstantiate(byte[] bytes) {
if (bytes == null) {
return null;
}
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
try {
ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
try {
return (E) objectInputStream.readObject();
} catch (ClassNotFoundException e) {
logger.error("发生异常,"+e.getMessage());
}
} catch (IOException e) {
logger.error("发生异常,"+e.getMessage());
}
return null;
}
public String stringInstantiate(E e) { //序列化对象的byte[]数组转为字符串(包装类可不调用)
byte[] bytes = instantiate(e);
if (bytes != null && bytes.length>0 ) {
return Base64.encode(bytes);
}
return "";
}
public byte[] stringDeInstantiate(String str) { //stringInstantiate方法还原为byte[]数组
if (!StringUtils.isEmpty(str)) {
return Base64.decode(str);
}
return null;
}
}

View File

@@ -188,4 +188,12 @@ public class EventRelevantAnalysisController extends BaseController {
boolean flag = eventRelevantAnalysisService.delRelevantLog(id);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, flag, methodDescribe);
}
}

View File

@@ -0,0 +1,25 @@
package com.njcn.advance.controller.eventGui;
import com.njcn.common.utils.PubUtils;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.io.DataInputStream;
import java.net.URLDecoder;
import java.time.LocalDateTime;
import java.util.List;
@RestController
@RequestMapping("process")
@Api(tags = "暂降事件关联分析")
@RequiredArgsConstructor
@Slf4j
public class EventGuiController {
}

View File

@@ -0,0 +1,9 @@
package com.njcn.advance.mapper;
public interface RelevanceMapper {
// 查询监测点的线路ID
String queryLineIdbyPointId(String pointId);
}

View File

@@ -1,7 +1,7 @@
package com.njcn.advance.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.advance.pojo.dto.SagEvent;
import com.njcn.event.pojo.po.RmpEventDetailPO;
import org.apache.ibatis.annotations.Param;

View File

@@ -1,7 +1,7 @@
package com.njcn.advance.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.advance.pojo.dto.SagEvent;
import com.njcn.advance.pojo.dto.relevent.EventAssObj;
import com.njcn.event.pojo.po.RmpEventDetailAssPO;
import org.apache.ibatis.annotations.Param;

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.njcn.advance.mapper.RelevanceMapper">
<select id="queryLineIdbyPointId" resultType="string" parameterType="string">
select pid from pq_line where id = #{pointId}
</select>
<select id="queryCodebyGuid" resultType="java.lang.Integer" parameterType="java.lang.String">
select triphase from sys_dict_data where id = #{guid}
</select>
</mapper>

View File

@@ -5,7 +5,9 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.date.TimeInterval;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.SerializeUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
@@ -15,7 +17,7 @@ import com.njcn.advance.enums.AdvanceResponseEnum;
import com.njcn.advance.mapper.RelevantLogMapper;
import com.njcn.advance.mapper.RmpEventAdvanceMapper;
import com.njcn.advance.mapper.RmpEventDetailAssMapper;
import com.njcn.advance.pojo.dto.SagEvent;
import com.njcn.advance.pojo.dto.relevent.*;
import com.njcn.advance.pojo.po.PqsRelevanceLog;
import com.njcn.advance.service.EventRelevantAnalysisService;
@@ -26,10 +28,12 @@ import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.utils.PubUtils;
import com.njcn.device.pq.api.GeneralDeviceInfoClient;
import com.njcn.device.pq.api.LineFeignClient;
import com.njcn.device.pq.pojo.po.PqsTflgployass;
import com.njcn.device.pq.pojo.vo.AreaLineInfoVO;
import com.njcn.event.pojo.po.RmpEventDetailAssPO;
import com.njcn.event.pojo.po.RmpEventDetailPO;
import com.njcn.event.pojo.vo.AdvanceEventDetailVO;
import com.njcn.redis.utils.RedisUtil;
import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.enums.DicDataTypeEnum;
@@ -40,8 +44,10 @@ import com.njcn.user.pojo.po.User;
import com.njcn.web.factory.PageFactory;
import com.njcn.web.pojo.param.BaseParam;
import com.njcn.web.utils.RequestUtil;
import io.swagger.models.auth.In;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -63,6 +69,8 @@ import java.util.stream.Collectors;
@Slf4j
public class EventRelevantAnalysisServiceImpl extends ServiceImpl<RmpEventAdvanceMapper, RmpEventDetailPO> implements EventRelevantAnalysisService {
private final String redisSortKey = "NODESORT";
private final DicDataFeignClient dicDataFeignClient;
@@ -78,6 +86,8 @@ public class EventRelevantAnalysisServiceImpl extends ServiceImpl<RmpEventAdvanc
private final UserFeignClient userFeignClient;
private final RedisUtil redisUtil;
@Override
@Transactional(rollbackFor = Exception.class)
@@ -85,11 +95,6 @@ public class EventRelevantAnalysisServiceImpl extends ServiceImpl<RmpEventAdvanc
TimeInterval timeInterval = new TimeInterval();
DictData dictData = dicDataFeignClient.getDicDataByNameAndTypeName(DicDataTypeEnum.EVENT_REASON.getName(), DicDataEnum.SHORT_TROUBLE.getName()).getData();
if (Objects.isNull(dictData)) {
throw new BusinessException(SystemResponseEnum.ADVANCE_REASON);
}
LocalDateTime date = LocalDateTime.now();
HandleEvent handleEvent = new HandleEvent();
@@ -98,85 +103,84 @@ public class EventRelevantAnalysisServiceImpl extends ServiceImpl<RmpEventAdvanc
if (CollectionUtil.isEmpty(baseList)) {
throw new BusinessException("当前时间段暂无可分析事件");
}
List<EntityGroupEvtData> list3 = new ArrayList<>(baseList);
// 传入的处理事件根据物理隔绝进行分组
List<EntityLogic> strategyList = relevantLogMapper.getLogic();
if (CollectionUtil.isNotEmpty(strategyList)) {
List<SagEvent> listSagEvent = new ArrayList<>();
List<EventAssObj> listEventAssObj = new ArrayList<>();
Map<String, EntityMtrans> entityMtransMap = getNodeInfo();
Set<Map.Entry<String, EntityMtrans>> setMtrans = entityMtransMap.entrySet();
Map<String, List<String>> strategyToBusBarMap = new HashMap<>(32);
List<SagEvent> listSagEvent = new ArrayList<>();
List<EventAssObj> listEventAssObj = new ArrayList<>();
Map<String, EntityMtrans> mapRedis = new HashMap<>(32);
Map<String, Map<String, Integer>> nodeMap = (Map<String, Map<String, Integer>>)redisUtil.getObjectByKey(redisSortKey);
Set<Map.Entry<String, Map<String, Integer>>> nodeSort = nodeMap.entrySet();
Map<String, List<EntityLogic>> strategyMap = strategyList.stream().collect(Collectors.groupingBy(EntityLogic::getTPIndex));
strategyMap.forEach((key, list) -> {
List<String> before = list.stream().map(EntityLogic::getNodeBefore).distinct().collect(Collectors.toList());
List<String> after = list.stream().map(EntityLogic::getNodeNext).distinct().collect(Collectors.toList());
before.addAll(after);
before = before.stream().distinct().collect(Collectors.toList());
strategyToBusBarMap.put(key, before);
FinalData.NODE_NUM = before.size();
EntityMtrans entityMtrans = new EntityMtrans();
handleEvent.create_matrixcata(list, entityMtrans);
DictData dictData = dicDataFeignClient.getDicDataByNameAndTypeName(DicDataTypeEnum.EVENT_REASON.getName(), DicDataEnum.SHORT_TROUBLE.getName()).getData();
if (Objects.isNull(dictData)) {
throw new BusinessException(SystemResponseEnum.ADVANCE_REASON);
}
mapRedis.put(key, entityMtrans);
});
for (Map.Entry<String, Map<String, Integer>> m : nodeSort) {
List<EntityGroupEvtData> list = new ArrayList<EntityGroupEvtData>();
Set<Map.Entry<String, Integer>> mapValue = m.getValue().entrySet();
FinalData.NODE_NUM = m.getValue().size();
strategyToBusBarMap.forEach((lastKey, lastVal) -> {
int index = 1;
List<EntityGroupEvtData> list = new ArrayList<>();
for (EntityGroupEvtData entityGroupEvtData : baseList) {
if (lastVal.contains(entityGroupEvtData.getNodePhysics()) && dictData.getId().equals(entityGroupEvtData.getSagReason())) {
entityGroupEvtData.setNode(index++);
list.add(entityGroupEvtData);
for (Map.Entry<String, Integer> mm : mapValue) {
for (EntityGroupEvtData groupEvtData : baseList) {
if (groupEvtData.getNodePhysics().equals(mm.getKey()) && dictData.getId().equals(groupEvtData.getSagReason())) {
groupEvtData.setNode(mm.getValue());
list.add(groupEvtData);
}
}
baseList.removeIf(entityGroupEvtData -> lastVal.contains(entityGroupEvtData.getNodePhysics()) && dictData.getId().equals(entityGroupEvtData.getSagReason()));
// 筛选不在矩阵中的事件id
list3.removeIf(entityGroupEvtData -> entityGroupEvtData.getNodePhysics().equals(mm.getKey()) && dictData.getId().equals(entityGroupEvtData.getSagReason()));
}
EntityGroupEvtData[] entityGroupEvtData = new EntityGroupEvtData[list.size()];
Collections.sort(list);
list.toArray(entityGroupEvtData);
EntityGroupEvtData[] entityGroupEvtData = new EntityGroupEvtData[list.size()];
Collections.sort(list);
list.toArray(entityGroupEvtData);
for (Map.Entry<String, EntityMtrans> mEntry : setMtrans) {
if (mEntry.getKey().equals(m.getKey())) {
mapRedis.forEach((mKey, mVal) -> {
if (mKey.equals(lastKey)) {
/********************************************************************
* 算法最多处理1000条数据超过限制需分批处理 先将数据根据某种方式进行升序/降序排序,然后分段处理 加入循环处理
*********************************************************************/
int circulation = entityGroupEvtData.length % FinalData.MAX_EVT_NUM == 0
? entityGroupEvtData.length / FinalData.MAX_EVT_NUM
: entityGroupEvtData.length / FinalData.MAX_EVT_NUM + 1;
//算法最多处理1000条数据超过限制需分批处理 先将数据根据某种方式进行升序/降序排序,然后分段处理 加入循环处理
for (int i = 0; i < circulation; i++) {
int to;
if (i == circulation - 1) {
to = entityGroupEvtData.length % FinalData.MAX_EVT_NUM > 0
? entityGroupEvtData.length
: (i + 1) * FinalData.MAX_EVT_NUM - 1;
} else {
to = (i + 1) * FinalData.MAX_EVT_NUM - 1;
}
int circulation = entityGroupEvtData.length % FinalData.MAX_EVT_NUM == 0
? entityGroupEvtData.length / FinalData.MAX_EVT_NUM
: entityGroupEvtData.length / FinalData.MAX_EVT_NUM + 1;
EntityGroupEvtData[] arrayObj = Arrays.copyOfRange(entityGroupEvtData,
i * FinalData.MAX_EVT_NUM, to);
EntityGroupData entityGroupData = handleEvent.translate(arrayObj, mVal);
// 处理分析结果
handleEvent.show_group_info(entityGroupData, listSagEvent, listEventAssObj, date);
for (int i = 0; i < circulation; i++) {
int to = 0;
if (i == circulation - 1) {
to = entityGroupEvtData.length % FinalData.MAX_EVT_NUM > 0
? entityGroupEvtData.length
: (i + 1) * FinalData.MAX_EVT_NUM - 1;
} else {
to = (i + 1) * FinalData.MAX_EVT_NUM - 1;
}
EntityGroupEvtData[] arrayObj = Arrays.copyOfRange(entityGroupEvtData,
i * FinalData.MAX_EVT_NUM, to);
EntityMtrans entityMtrans = mEntry.getValue();
EntityGroupData entityGroupData = handleEvent.translate(arrayObj,entityMtrans);
// 处理分析结果
handleEvent.show_group_info(entityGroupData, listSagEvent, listEventAssObj, date);
}
});
});
}
}
}
/******************************************************************************
* 事件ID不在矩阵中结果集为基础以时标为标准进行归集处理 注意:三相与(单相/两相)互斥
*****************************************************************************/
disposeNonStandardData(handleEvent, baseList, listEventAssObj, listSagEvent, date);
@@ -216,13 +220,232 @@ public class EventRelevantAnalysisServiceImpl extends ServiceImpl<RmpEventAdvanc
entityPqsRelevance.setTimeId(date);
relevantLogMapper.insert(entityPqsRelevance);
} else {
throw new BusinessException("当前无变压器策略,请先配置策略");
}
log.info("事件关联分析用时:" + timeInterval.interval() / 1000 + "");
}
// @Override
// @Transactional(rollbackFor = Exception.class)
// public void processEvents(LocalDateTime startTime, LocalDateTime endTime) {
//
// TimeInterval timeInterval = new TimeInterval();
//
//
// Map<String, Map<String, Integer>> nodeSort = new HashMap<>();
// Map<String, EntityMtrans> entityMtransMap = getNodeInfo();
//
//
//
//
//
// for (Map.Entry<String, Map<String, Integer>> m : nodeSort) {
// List<EntityGroupEvtData> list = new ArrayList<EntityGroupEvtData>();
// Set<Map.Entry<String, Integer>> mapValue = m.getValue().entrySet();
// FinalData.NODE_NUM = m.getValue().size();
//
// for (Map.Entry<String, Integer> mm : mapValue) {
// for (int i = 0; i < entityGroupEvtDatas.length; i++) {
// if (entityGroupEvtDatas[i].getNodePhysics() == mm.getKey().intValue() && "短路故障".equals(entityGroupEvtDatas[i].getSagReason())) {
// entityGroupEvtDatas[i].setNode(mm.getValue());
// list.add(entityGroupEvtDatas[i]);
// }
// }
//
// // 筛选不在矩阵中的事件id
// Iterator<EntityGroupEvtData> iterator = list3.iterator();
// while (iterator.hasNext()) {
// EntityGroupEvtData entityGroupEvtData = iterator.next();
//
// if (entityGroupEvtData.getNodePhysics() == mm.getKey().intValue() && "短路故障".equals(entityGroupEvtData.getSagReason())) {
// iterator.remove();
// }
// }
// }
//
// EntityGroupEvtData[] entityGroupEvtData = new EntityGroupEvtData[list.size()];
// Collections.sort(list);
// list.toArray(entityGroupEvtData);
//
// for (Map.Entry<String, JSONObject> mEntry : setMtrans) {
// if (mEntry.getKey().equals(m.getKey())) {
// *//**//********************************************************************
// * 算法最多处理1000条数据超过限制需分批处理 先将数据根据某种方式进行升序/降序排序,然后分段处理 加入循环处理
// *********************************************************************//**//*
// int circulation = entityGroupEvtData.length % FinalData.MAX_EVT_NUM == 0
// ? entityGroupEvtData.length / FinalData.MAX_EVT_NUM
// : entityGroupEvtData.length / FinalData.MAX_EVT_NUM + 1;
//
// for (int i = 0; i < circulation; i++) {
// int to = 0;
//
// if (i == circulation - 1) {
// to = entityGroupEvtData.length % FinalData.MAX_EVT_NUM > 0
// ? entityGroupEvtData.length
// : (i + 1) * FinalData.MAX_EVT_NUM - 1;
// } else {
// to = (i + 1) * FinalData.MAX_EVT_NUM - 1;
// }
//
// EntityGroupEvtData[] arrayObj = Arrays.copyOfRange(entityGroupEvtData,
// i * FinalData.MAX_EVT_NUM, to);
// JSONObject entityMtrans = mEntry.getValue();
// EntityGroupData entityGroupData = handleEvent.translate(arrayObj, (EntityMtrans) JSONObject.toBean(entityMtrans, EntityMtrans.class));
// // 处理分析结果
// handleEvent.show_group_info(entityGroupData, listSagEvent, listEventAssObj, date);
// }
// }
// }
// }
//
//
// DictData dictData = dicDataFeignClient.getDicDataByNameAndTypeName(DicDataTypeEnum.EVENT_REASON.getName(), DicDataEnum.SHORT_TROUBLE.getName()).getData();
// if (Objects.isNull(dictData)) {
// throw new BusinessException(SystemResponseEnum.ADVANCE_REASON);
// }
//
//
// LocalDateTime date = LocalDateTime.now();
// HandleEvent handleEvent = new HandleEvent();
// // 分析的事件进行处理
// List<EntityGroupEvtData> baseList = handleEvent.getData(startTime, endTime);
// if (CollectionUtil.isEmpty(baseList)) {
// throw new BusinessException("当前时间段暂无可分析事件");
// }
//
// // 传入的处理事件根据物理隔绝进行分组
//
// List<EntityLogic> strategyList = relevantLogMapper.getLogic();
//
// if (CollectionUtil.isNotEmpty(strategyList)) {
// List<SagEvent> listSagEvent = new ArrayList<>();
// List<EventAssObj> listEventAssObj = new ArrayList<>();
//
// Map<String, List<String>> strategyToBusBarMap = new HashMap<>(32);
//
// Map<String, EntityMtrans> mapRedis = new HashMap<>(32);
//
// Map<String, List<EntityLogic>> strategyMap = strategyList.stream().collect(Collectors.groupingBy(EntityLogic::getTPIndex));
// strategyMap.forEach((key, list) -> {
// List<String> before = list.stream().map(EntityLogic::getNodeBefore).distinct().collect(Collectors.toList());
// List<String> after = list.stream().map(EntityLogic::getNodeNext).distinct().collect(Collectors.toList());
// before.addAll(after);
// before = before.stream().distinct().collect(Collectors.toList());
// strategyToBusBarMap.put(key, before);
//
// FinalData.NODE_NUM = before.size();
// EntityMtrans entityMtrans = new EntityMtrans();
// handleEvent.create_matrixcata(list, entityMtrans);
//
// mapRedis.put(key, entityMtrans);
// });
//
// strategyToBusBarMap.forEach((lastKey, lastVal) -> {
// int index = 1;
// List<EntityGroupEvtData> list = new ArrayList<>();
// for (EntityGroupEvtData entityGroupEvtData : baseList) {
// if (lastVal.contains(entityGroupEvtData.getNodePhysics()) && dictData.getId().equals(entityGroupEvtData.getSagReason())) {
// entityGroupEvtData.setNode(index++);
// list.add(entityGroupEvtData);
// }
// }
//
// baseList.removeIf(entityGroupEvtData -> lastVal.contains(entityGroupEvtData.getNodePhysics()) && dictData.getId().equals(entityGroupEvtData.getSagReason()));
//
//
// EntityGroupEvtData[] entityGroupEvtData = new EntityGroupEvtData[list.size()];
// Collections.sort(list);
// list.toArray(entityGroupEvtData);
//
// mapRedis.forEach((mKey, mVal) -> {
// if (mKey.equals(lastKey)) {
// //算法最多处理1000条数据超过限制需分批处理 先将数据根据某种方式进行升序/降序排序,然后分段处理 加入循环处理
// int circulation = entityGroupEvtData.length % FinalData.MAX_EVT_NUM == 0
// ? entityGroupEvtData.length / FinalData.MAX_EVT_NUM
// : entityGroupEvtData.length / FinalData.MAX_EVT_NUM + 1;
//
// for (int i = 0; i < circulation; i++) {
// int to;
// if (i == circulation - 1) {
// to = entityGroupEvtData.length % FinalData.MAX_EVT_NUM > 0
// ? entityGroupEvtData.length
// : (i + 1) * FinalData.MAX_EVT_NUM - 1;
// } else {
// to = (i + 1) * FinalData.MAX_EVT_NUM - 1;
// }
//
// EntityGroupEvtData[] arrayObj = Arrays.copyOfRange(entityGroupEvtData,
// i * FinalData.MAX_EVT_NUM, to);
// EntityGroupData entityGroupData = handleEvent.translate(arrayObj, mVal);
// // 处理分析结果
// handleEvent.show_group_info(entityGroupData, listSagEvent, listEventAssObj, date);
// }
// }
// });
//
// });
//
//
//
// //事件ID不在矩阵中结果集为基础以时标为标准进行归集处理 注意:三相与(单相/两相)互斥
//
// disposeNonStandardData(handleEvent, baseList, listEventAssObj, listSagEvent, date);
//
//
// int listSize = listEventAssObj.size();
// int toIndex = 1000;
// for (int i = 0; i < listSize; i += 1000) {
// //作用为toIndex最后没有toIndex条数据则剩余几条newList中就装几条
// if (i + 1000 > listSize) {
// toIndex = listSize - i;
// }
// //分割lst
// List<EventAssObj> newList = listEventAssObj.subList(i, i + toIndex);
// //写入添加方法,需要写你的新增方法把newList分切后的数据新增进入数据库。
// rmpEventDetailAssMapper.insertEventAssData(newList);
// }
//
// List<RmpEventDetailPO> eventUpdateList = new ArrayList<>();
// for (int i = 0; i < listSagEvent.size(); i++) {
// RmpEventDetailPO rmp = new RmpEventDetailPO();
// rmp.setEventId(listSagEvent.get(i).getIndexEventDetail());
// rmp.setEventassIndex(listSagEvent.get(i).getIndexEventAss());
// rmp.setDealTime(listSagEvent.get(i).getDealTime());
// eventUpdateList.add(rmp);
// if ((i + 1) % 1000 == 0) {
// this.updateBatchById(eventUpdateList);
// eventUpdateList.clear();
// } else if (i == listSagEvent.size() - 1) {
// this.updateBatchById(eventUpdateList);
// }
// }
//
// // 增加策略记录
// String describe = "用户" + RequestUtil.getUserNickname() + "进行了关联分析";
// PqsRelevanceLog entityPqsRelevance = new PqsRelevanceLog();
// entityPqsRelevance.setContentDes(describe);
// entityPqsRelevance.setState(DataStateEnum.ENABLE.getCode());
// entityPqsRelevance.setTimeId(date);
// relevantLogMapper.insert(entityPqsRelevance);
//
// } else {
// throw new BusinessException("当前无变压器策略,请先配置策略");
// }
//
// log.info("事件关联分析用时:" + timeInterval.interval() / 1000 + "秒");
// }
@Override
public Page<AdvanceEventDetailVO> querySagEventsPage(BaseParam baseParam) {
List<String> lineIds = generalDeviceInfoClient.deptGetRunLineEvent(RequestUtil.getDeptIndex()).getData();
@@ -635,31 +858,116 @@ public class EventRelevantAnalysisServiceImpl extends ServiceImpl<RmpEventAdvanc
/*************************************************************************************
* 获取变压器信息并生成矩阵
*************************************************************************************/
@Deprecated
public void getNodeInfo(HandleEvent handleEvent) {
public Map<String, EntityMtrans> getNodeInfo( ) {
Map<String, EntityMtrans> entityMtranMap = new HashMap<>(32);
HandleEvent handleEvent = new HandleEvent();
List<EntityLogic> list = relevantLogMapper.getLogic();
if (CollectionUtil.isNotEmpty(list)) {
Map<String, List<EntityLogic>> tfMap = list.stream().collect(Collectors.groupingBy(EntityLogic::getTPIndex));
Map<String, List<String>> tfBusBarMap = new HashMap<>(32);
Map<String, EntityMtrans> entityMtranMap = new HashMap<>(32);
Map<String, List<String>> map = getLogicInfo(list);
Map<String, Map<String, Integer>> setNodeSort = nodeSort(map);
redisUtil.saveByKeyWithExpire(redisSortKey,setNodeSort,-1L);
tfMap.forEach((key, val) -> {
List<String> tem = new ArrayList<>();
val.forEach(it -> {
tem.add(it.getNodeBefore());
tem.add(it.getNodeNext());
});
tfBusBarMap.put(key, tem);
setNodeSort.forEach((key, val) -> {
FinalData.NODE_NUM = val.size();
List<EntityLogic> listNew = new ArrayList<>();
for (EntityLogic entityLogic : list) {
if (entityLogic.getTPIndex().equals(key)) {
entityLogic.setNode_h(val.get(entityLogic.getNodeBefore()));
entityLogic.setNode_l(val.get(entityLogic.getNodeNext()));
listNew.add(entityLogic);
}
}
EntityMtrans entityMtrans = new EntityMtrans();
handleEvent.create_matrixcata(val, entityMtrans);
handleEvent.create_matrixcata(listNew, entityMtrans);
entityMtranMap.put(key, entityMtrans);
});
}
return entityMtranMap;
}
/*******************************************
* 增加排序功能并缓存进redis
*******************************************/
public Map<String, Map<String, Integer>> nodeSort(Map<String, List<String>> mapList) {
Set<Map.Entry<String, List<String>>> sets = mapList.entrySet();
Map<String, Map<String, Integer>> map = new HashMap<>();
for (Map.Entry<String, List<String>> m : sets) {
int index = 1;
Map<String, Integer> map2 = new HashMap<>();
for (String item : m.getValue()) {
map2.put(item, index++);
}
map.put(m.getKey(), map2);
}
return map;
}
/**
* 抽取物理隔绝信息与母线的关系并放入map集合中
* 与getTflgPloyInfo()方法功能类似
*/
public Map<String, List<String>> getLogicInfo(List<EntityLogic> list) {
if (list.size() > 0) {
Iterator<String> iterator = getAreaInfo(list).iterator();
Map<String, List<String>> map = new HashMap<>();
while (iterator.hasNext()) {
List<String> listLogic = new ArrayList<>();
String areaString = iterator.next();
for (EntityLogic entityLogic : list) {
if (entityLogic.getTPIndex().equals(areaString)) {
listLogic.add(entityLogic.getNodeBefore());
listLogic.add(entityLogic.getNodeNext());
}
}
//去除list中重复数据
Set<String> set = new TreeSet<>(listLogic);
map.put(areaString, new ArrayList<>(set));
}
return map;
}
return null;
}
/**
* 获取物理隔绝编码信息
* 供getInfo()、getLogicInfo()方法使用
* 先从list数组中去重然后获取物理隔绝编码
*/
public <T> Set<String> getAreaInfo(List<T> list) {
Set<T> set = new HashSet<T>(list);
Iterator<T> iterator = set.iterator();
Set<String> setReturn = new HashSet<String>();
while (iterator.hasNext()) {
Object object = iterator.next();
if (object instanceof PqsTflgployass) {
setReturn.add(((PqsTflgployass) object).getTpIndex());
continue;
}
setReturn.add(((EntityLogic) object).getTPIndex());
}
return setReturn;
}
@@ -697,3 +1005,4 @@ public class EventRelevantAnalysisServiceImpl extends ServiceImpl<RmpEventAdvanc
return new ArrayList<>();
}
}

View File

@@ -4,28 +4,33 @@ package com.njcn.advance.utils;
import com.njcn.advance.pojo.dto.relevent.*;
public class UtilNormalization {
public static void matrixcata_pro(EntityLogic[] transformer, EntityMtrans entityMtrans, int len) {
int i, j, k, con;
String node1, node2;
public static void matrixcata_pro(EntityLogic[] transformer,EntityMtrans entityMtrans, int len) {
int i, j, k;
int node1, node2, con;
int src_node[] = new int[] { 0 };
// 连接方式转化为矩阵形式,行、列表示所有节点
// inf表示两个节点不相连0表示与自身相连其他数值表示变压器连接类型
// 将初始矩阵的元素设为inf,对角线元素设为0
for (i = 0; i < FinalData.NODE_NUM; i++) {
for (j = 0; j < FinalData.NODE_NUM; j++) {
for (j = 0; j < FinalData.NODE_NUM; j++)
entityMtrans.getMtrans()[i][j] = FinalData.DATA_INF;
}
entityMtrans.getMtrans()[i][i] = 0;
}
// 根据transformer设置元素
for (i = 0; i < len; i++) {
node1 = transformer[i].getNode_h();
node2 = transformer[i].getNode_l();
con = transformer[i].getType();
entityMtrans.getMtrans()[node1 - 1][node2 - 1] = con;
entityMtrans.getMtrans()[node2 - 1][node1 - 1] = con;
}
StringBuilder str = new StringBuilder();
for (i = 0; i < FinalData.NODE_NUM; i++) {
for (j = 0; j < FinalData.NODE_NUM; j++) {
str.append(entityMtrans.getMtrans()[i][j]).append(" ");
if (j == (FinalData.NODE_NUM - 1)) {
if (j == (FinalData.NODE_NUM - 1))
str.append("\r\n");
}
}
}
@@ -33,60 +38,52 @@ public class UtilNormalization {
// Matrixcata模式匹配矩阵列为节点数行为总类别数元素为第一个节点分别是1-6类别情况下其他节点类别情况。
// 元素1,2,34,5,6 分别对应 Dc,Cb,Da,Cc,Db,Ca
// 设置矩阵第一行元素
for (i = 0; i < FinalData.NODE_NUM; i++) {
for (i = 0; i < FinalData.NODE_NUM; i++)
entityMtrans.getMatrixcata0()[0][i] = 0;
}
for (i = 1; i < FinalData.NODE_NUM; i++) {
// 路径缓存清空
for (j = 0; j < FinalData.MAX_PATH_NUM; j++) {
for (k = 0; k < (FinalData.NODE_NUM + 1); k++) {
for (k = 0; k < (FinalData.NODE_NUM + 1); k++)
entityMtrans.getPossiable_path()[j][k] = 0;
}
}
entityMtrans.setPath_num(0);
// 寻找路径
src_node[0] = 0;
findPath(entityMtrans, src_node, i, 0, 1, FinalData.NODE_NUM);
if (entityMtrans.getPath_num() != 0) {
if (entityMtrans.getPath_num() != 0)
entityMtrans.getMatrixcata0()[0][i] = entityMtrans.getPossiable_path()[0][FinalData.NODE_NUM]; // 采用第一条路径
} else {
else
entityMtrans.getMatrixcata0()[0][i] = FinalData.DATA_INF; // 找不到路径填大值表示不通
}
}
// 构造矩阵其他行元素
for (i = 1; i < FinalData.EVT_TYPE_NUM; i++) {
for (j = 0; j < FinalData.NODE_NUM; j++)
// EntityGroupData.Matrixcata0[i][j] =
// EntityGroupData.Matrixcata0[0][j] + i;
{
if (entityMtrans.getMatrixcata0()[0][j] == FinalData.DATA_INF) {
entityMtrans.getMatrixcata0()[i][j] = FinalData.DATA_INF;
} else {
entityMtrans.getMatrixcata0()[i][j] = entityMtrans.getMatrixcata0()[0][j] + i;
}
}
}
// 将数据归类到0-5
for (i = 0; i < FinalData.EVT_TYPE_NUM; i++) {
for (j = 0; j < FinalData.NODE_NUM; j++) {
for (j = 0; j < FinalData.NODE_NUM; j++)
entityMtrans.getMatrixcata1()[i][j] = entityMtrans.getMatrixcata0()[i][j] % 6;
}
}
// 0换成6将数据归类到1-6
for (i = 0; i < FinalData.EVT_TYPE_NUM; i++) {
for (j = 0; j < FinalData.NODE_NUM; j++) {
if (entityMtrans.getMatrixcata1()[i][j] == 0) {
if (entityMtrans.getMatrixcata1()[i][j] == 0)
entityMtrans.getMatrixcata1()[i][j] = 6;
}
}
}
str.delete(0, str.length());
for (i = 0; i < FinalData.EVT_TYPE_NUM; i++) {
for (j = 0; j < FinalData.NODE_NUM; j++) {
str.append(entityMtrans.getMatrixcata1()[i][j]).append(" ");
if (j == (FinalData.NODE_NUM - 1)) {
if (j == (FinalData.NODE_NUM - 1))
str.append("\r\n");
}
}
}

View File

@@ -1,12 +1,5 @@
FROM eclipse-temurin:8-jdk-centos7
MAINTAINER hongawen_13914774158@163.com
ENV JAVA_OPTS="-Xms1024m -Xmx1024m"
# 挂载时区的目录
VOLUME /usr/share/zoneinfo
# 设置时区为上海
ENV TZ=Asia/Shanghai
# 设置时区信息
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
FROM openjdk:8-jdk-alpine
ADD target/gateway.jar gateway.jar
ENTRYPOINT java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -jar /gateway.jar
EXPOSE 10215
ENTRYPOINT ["java","-jar","/gateway.jar"]
EXPOSE 10215
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \&& echo 'Asia/Shanghai' >/etc/timezone

View File

@@ -231,6 +231,7 @@ whitelist:
- /bpm-boot/**
- /harmonic-boot/comAccess/getComAccessData
- /harmonic-boot/harmonic/getHistoryResult
- /event-boot/transient/getTransientAnalyseWave
#开始
# - /advance-boot/**
# - /device-boot/**

View File

@@ -24,9 +24,13 @@ spring:
ip: @service.server.url@
server-addr: @nacos.url@
namespace: @nacos.namespace@
username: @nacos.username@
password: @nacos.password@
config:
server-addr: @nacos.url@
namespace: @nacos.namespace@
username: @nacos.username@
password: @nacos.password@
file-extension: yaml
shared-configs:
- data-id: share-config.yaml
@@ -42,15 +46,17 @@ liteflow:
dataId: prepare_liteflow
group: DEFAULT_GROUP
namespace: @nacos.namespace@
username: @nacos.username@
password: @nacos.password@
when-max-wait-time: 600000
print-banner: false
#项目日志的配置
logging:
config: http://@nacos.url@/nacos/v1/cs/configs?tenant=@nacos.namespace@&group=DEFAULT_GROUP&dataId=logback.xml
#config: http://@nacos.url@/nacos/v1/cs/configs?tenant=@nacos.namespace@&group=DEFAULT_GROUP&dataId=logback.xml
level:
root: error
root: info
##mybatis配置信息

View File

@@ -1,15 +1,8 @@
FROM openjdk:8-jdk-alpine
FROM eclipse-temurin:8-jdk-ubi9-minimal
MAINTAINER hongawen_13914774158@163.com
ENV JAVA_OPTS="-Xms1024m -Xmx1024m"
# 挂载时区的目录
VOLUME /usr/share/zoneinfo
# 设置时区为上海
ENV TZ=Asia/Shanghai
# 设置时区信息
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
ADD target/systemboot.jar systemboot.jar
ENTRYPOINT ["java","-jar","/systemboot.jar"]
ENTRYPOINT java ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -jar /systemboot.jar
EXPOSE 10207
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \&& echo 'Asia/Shanghai' >/etc/timezone
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \&& echo 'Asia/Shanghai' >/etc/timezone
#下面是审计日志备份现场环境缺少字体库
#RUN apk add --update ttf-dejavu fontconfig && rm -rf /var/cache/apk/*