ソースを参照

保存事件录波动作

xusl 1 年間 前
コミット
51b91816e2

+ 20 - 0
backend/src/main/java/com/jiayue/pfr/backenum/FaultRecorderTypeEnum.java

@@ -0,0 +1,20 @@
+package com.jiayue.pfr.backenum;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+/**
+ * 录波类型枚举
+ *
+ * @author zzy
+ * @version 1.0
+ * @since 2019/8/2 11:33
+ */
+@Getter
+@AllArgsConstructor
+public enum FaultRecorderTypeEnum {
+	FR1(1, "频率异常"),
+	FR2(2, "频率正常");
+	private Integer code;
+	private String message;
+}

+ 12 - 4
backend/src/main/java/com/jiayue/pfr/constant/CacheConstants.java

@@ -23,9 +23,10 @@ public class CacheConstants {
      */
      */
     public static final String CAPTCHA_CODE_KEY = "captcha_codes:";
     public static final String CAPTCHA_CODE_KEY = "captcha_codes:";
     /**
     /**
-     * 保存所有时间点的频率和有功
+     * 保存5分钟内所有时间点的频率和有功
      */
      */
-    public static ConcurrentHashMap<Long, FmDataBeanDto> fmMap = new ConcurrentHashMap<>();
+//    public static ConcurrentHashMap<Long, FmDataBeanDto> fmMap = new ConcurrentHashMap<>();
+    public static Cache<Long,FmDataBeanDto> fmMap = CacheUtil.newFIFOCache(1500);
     /**
     /**
      * 首页频率数据
      * 首页频率数据
      */
      */
@@ -44,10 +45,17 @@ public class CacheConstants {
 
 
     // 调试时有功
     // 调试时有功
     public static BigDecimal debuggerPower = new BigDecimal("0");
     public static BigDecimal debuggerPower = new BigDecimal("0");
-    // 调频时初始值
-    public static BigDecimal fmInitPower = new BigDecimal("0");
+
 
 
     // 调频动作信号 ON: 动作信号 , OFF: 复归信号
     // 调频动作信号 ON: 动作信号 , OFF: 复归信号
     public static String fmAct = "OFF";
     public static String fmAct = "OFF";
 
 
+
+    ////////录波阶段用的///////
+    // 录波前5秒的频率数据
+    public static Cache<Long,FmDataBeanDto> recordBeforeMapCache = CacheUtil.newFIFOCache(25);
+    // 录波前5秒的频率数据
+    public static Cache<Long,FmDataBeanDto> recordAfterMapCache = CacheUtil.newFIFOCache(25);
+    // 频率异常开始时间
+    public static Long exceptionStartTime = 0L;
 }
 }

+ 32 - 0
backend/src/main/java/com/jiayue/pfr/entity/FaultRecorderData.java

@@ -0,0 +1,32 @@
+package com.jiayue.pfr.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * 录波事件
+ *
+ * @author jy
+ * @since 2023/11/14
+ */
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class FaultRecorderData extends BaseEntity {
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+    /**
+     * 录波事件名称
+     */
+    private String eventName;
+    /**
+     * 异常开始时间
+     */
+    private Long exceptionStartTime;
+    /**
+     * 恢复正常时间
+     */
+    private Long restoreTime;
+
+}

+ 37 - 0
backend/src/main/java/com/jiayue/pfr/entity/FaultRecorderDetail.java

@@ -0,0 +1,37 @@
+package com.jiayue.pfr.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import java.math.BigDecimal;
+
+/**
+ * 录波事件明细数据
+ *
+ * @author jy
+ * @since 2023/11/14
+ */
+@EqualsAndHashCode(callSuper = true)
+@Data
+public class FaultRecorderDetail extends BaseEntity {
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+    /**
+     * 录波事件名称
+     */
+    private Integer eventId;
+    /**
+     * 数据时间
+     */
+    private Long dataTime;
+    /**
+     * 频率
+     */
+    private BigDecimal fm;
+    /**
+     * 有功
+     */
+    private BigDecimal activePower;
+}

+ 18 - 0
backend/src/main/java/com/jiayue/pfr/mapper/alg/FaultRecorderDataMapper.java

@@ -0,0 +1,18 @@
+package com.jiayue.pfr.mapper.alg;
+
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+import com.jiayue.pfr.entity.FaultRecorderData;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * 录波事件Mapper
+ *
+ * @author xsl
+ * @since 2023-03-17
+ */
+@Mapper
+public interface FaultRecorderDataMapper extends BaseMapper<FaultRecorderData> {
+
+}

+ 17 - 0
backend/src/main/java/com/jiayue/pfr/mapper/alg/FaultRecorderDetailMapper.java

@@ -0,0 +1,17 @@
+package com.jiayue.pfr.mapper.alg;
+
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.jiayue.pfr.entity.FaultRecorderDetail;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * 录波明细Mapper
+ *
+ * @author xsl
+ * @since 2023-03-17
+ */
+@Mapper
+public interface FaultRecorderDetailMapper extends BaseMapper<FaultRecorderDetail> {
+
+}

+ 19 - 0
backend/src/main/java/com/jiayue/pfr/service/alg/FaultRecorderDataService.java

@@ -0,0 +1,19 @@
+package com.jiayue.pfr.service.alg;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.jiayue.pfr.dto.FmDataBeanDto;
+import com.jiayue.pfr.entity.FaultRecorderData;
+
+import java.util.Map;
+
+/**
+* 录波事件接口
+* @author xsl
+* @date 2023/2/16
+*/
+public interface FaultRecorderDataService extends IService<FaultRecorderData> {
+    /**
+     * 保存事件录波及明细
+     */
+    void saveFdAndDetail(Long exceptionStartTime, Long restoreTime);
+}

+ 13 - 0
backend/src/main/java/com/jiayue/pfr/service/alg/FaultRecorderDetailService.java

@@ -0,0 +1,13 @@
+package com.jiayue.pfr.service.alg;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.jiayue.pfr.entity.FaultRecorderDetail;
+
+/**
+* 录波明细接口
+* @author xsl
+* @date 2023/2/16
+*/
+public interface FaultRecorderDetailService extends IService<FaultRecorderDetail> {
+
+}

+ 84 - 0
backend/src/main/java/com/jiayue/pfr/service/alg/impl/FaultRecorderDataServiceImpl.java

@@ -0,0 +1,84 @@
+package com.jiayue.pfr.service.alg.impl;
+
+import cn.hutool.cache.impl.CacheObj;
+import cn.hutool.core.date.DateUtil;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.jiayue.pfr.constant.CacheConstants;
+import com.jiayue.pfr.dto.FmDataBeanDto;
+import com.jiayue.pfr.entity.FaultRecorderData;
+import com.jiayue.pfr.entity.FaultRecorderDetail;
+import com.jiayue.pfr.mapper.alg.FaultRecorderDataMapper;
+import com.jiayue.pfr.service.alg.FaultRecorderDataService;
+import com.jiayue.pfr.service.alg.FaultRecorderDetailService;
+import org.apache.commons.lang.time.DateFormatUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+* 录波事件服务类
+* @author xsl
+* @date 2023/2/16
+*/
+@Service
+public class FaultRecorderDataServiceImpl extends ServiceImpl<FaultRecorderDataMapper, FaultRecorderData> implements FaultRecorderDataService {
+    @Autowired
+    FaultRecorderDetailService faultRecorderDetailService;
+
+    /**
+     * 保存事件录波及明细
+     */
+    @Transactional(propagation = Propagation.SUPPORTS)
+    public void saveFdAndDetail(Long exceptionStartTime, Long restoreTime) {
+        Long sjxs =3*1000L;
+        // 前3秒
+        Long beforeTime = exceptionStartTime - sjxs;
+        // 后3秒
+        Long afterTime = restoreTime + sjxs;
+
+        try {
+            Thread.sleep(sjxs);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        }
+        // 记录异常结束时间
+        Iterator<CacheObj<Long, FmDataBeanDto>> iterator1 = CacheConstants.fmMap.cacheObjIterator();
+        Map<Long, FmDataBeanDto> detailMap = new ConcurrentHashMap<>();
+
+        while (iterator1.hasNext()) {
+            CacheObj<Long,FmDataBeanDto> entry = iterator1.next();
+            Long key = entry.getKey();
+            if (key>=beforeTime && key<=afterTime) {
+                // 拷贝出录波数据
+                detailMap.put(key,entry.getValue());
+            }
+        }
+
+        // 保存入库
+        FaultRecorderData faultRecorderData = new FaultRecorderData();
+        String newNum = DateFormatUtils.format(exceptionStartTime, "yyyyMMddHHmmss");
+        faultRecorderData.setEventName("录波事件"+newNum);
+        faultRecorderData.setExceptionStartTime(exceptionStartTime);
+        faultRecorderData.setRestoreTime(restoreTime);
+
+        this.save(faultRecorderData);
+        List<FaultRecorderDetail> faultRecorderDetails = new ArrayList<>();
+        for (Map.Entry<Long, FmDataBeanDto> entry : detailMap.entrySet()) {
+            FmDataBeanDto fmDataBeanDto = entry.getValue();
+            FaultRecorderDetail faultRecorderDetail = new FaultRecorderDetail();
+            faultRecorderDetail.setEventId(faultRecorderData.getId());
+            faultRecorderDetail.setDataTime(DateUtil.parse(fmDataBeanDto.getTime(),"yyyy-MM-dd HH:mm:ss.SSS").getTime());
+            faultRecorderDetail.setFm(fmDataBeanDto.getF());
+            faultRecorderDetail.setActivePower(fmDataBeanDto.getActivePower());
+            faultRecorderDetails.add(faultRecorderDetail);
+        }
+        faultRecorderDetailService.saveBatch(faultRecorderDetails);
+    }
+}

+ 16 - 0
backend/src/main/java/com/jiayue/pfr/service/alg/impl/FaultRecorderDetailServiceImpl.java

@@ -0,0 +1,16 @@
+package com.jiayue.pfr.service.alg.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.jiayue.pfr.entity.FaultRecorderDetail;
+import com.jiayue.pfr.mapper.alg.FaultRecorderDetailMapper;
+import com.jiayue.pfr.service.alg.FaultRecorderDetailService;
+import org.springframework.stereotype.Service;
+
+/**
+* 录波事件服务类
+* @author xsl
+* @date 2023/2/16
+*/
+@Service
+public class FaultRecorderDetailServiceImpl extends ServiceImpl<FaultRecorderDetailMapper, FaultRecorderDetail> implements FaultRecorderDetailService {
+}

+ 12 - 0
backend/src/main/java/com/jiayue/pfr/service/alg/listener/CoreAlgListener.java

@@ -1,6 +1,8 @@
 package com.jiayue.pfr.service.alg.listener;
 package com.jiayue.pfr.service.alg.listener;
 
 
+import cn.hutool.core.date.DateUtil;
 import com.jiayue.pfr.backenum.ActionResetEnum;
 import com.jiayue.pfr.backenum.ActionResetEnum;
+import com.jiayue.pfr.backenum.FaultRecorderTypeEnum;
 import com.jiayue.pfr.constant.CacheConstants;
 import com.jiayue.pfr.constant.CacheConstants;
 import com.jiayue.pfr.dto.FmDataBeanDto;
 import com.jiayue.pfr.dto.FmDataBeanDto;
 import com.jiayue.pfr.dto.SagFormulaDto;
 import com.jiayue.pfr.dto.SagFormulaDto;
@@ -75,6 +77,9 @@ public class CoreAlgListener implements ApplicationListener<GetFmEvent> {
                             System.out.println(fmDataBeanDto.getActivePower().toString());
                             System.out.println(fmDataBeanDto.getActivePower().toString());
                             System.out.println(CacheConstants.debuggerPower.toString());
                             System.out.println(CacheConstants.debuggerPower.toString());
                         }
                         }
+                        // 开启录波
+                        applicationEventPublisher.publishEvent(new FaultRecorderEvent(fmDataBeanDto, FaultRecorderTypeEnum.FR1.name(),DateUtil.parse(fmDataBeanDto.getTime(),"yyyy-MM-dd HH:mm:ss.SSS").getTime()));
+
                         // 给AGC闭锁调用104
                         // 给AGC闭锁调用104
                         applicationEventPublisher.publishEvent(new AgcEvent(ActionResetEnum.ACTION.getCode(),bizYaoData));
                         applicationEventPublisher.publishEvent(new AgcEvent(ActionResetEnum.ACTION.getCode(),bizYaoData));
                         // 上传PMU、EMS数据
                         // 上传PMU、EMS数据
@@ -94,9 +99,16 @@ public class CoreAlgListener implements ApplicationListener<GetFmEvent> {
                         bizYaoData = bizYaoDataService.update(bizYaoData);
                         bizYaoData = bizYaoDataService.update(bizYaoData);
                         fLogger.info("频率恢复,当前频率:"+fmDataBeanDto.getF()+" 时间:"+fmDataBeanDto.getTime());
                         fLogger.info("频率恢复,当前频率:"+fmDataBeanDto.getF()+" 时间:"+fmDataBeanDto.getTime());
                         applicationEventPublisher.publishEvent(new AgcEvent(ActionResetEnum.RESET.getCode(),bizYaoData));
                         applicationEventPublisher.publishEvent(new AgcEvent(ActionResetEnum.RESET.getCode(),bizYaoData));
+
+                        // 结束录波
+                        applicationEventPublisher.publishEvent(new FaultRecorderEvent(fmDataBeanDto, FaultRecorderTypeEnum.FR2.name(), DateUtil.parse(fmDataBeanDto.getTime(),"yyyy-MM-dd HH:mm:ss.SSS").getTime()));
+
                         // 做复归通知,AGC和PMU
                         // 做复归通知,AGC和PMU
 //                        CacheConstants.fmAct = "OFF";
 //                        CacheConstants.fmAct = "OFF";
                     }
                     }
+
+                    // 判断
+
                 }
                 }
             }
             }
         }
         }

+ 23 - 0
backend/src/main/java/com/jiayue/pfr/service/alg/listener/FaultRecorderEvent.java

@@ -0,0 +1,23 @@
+package com.jiayue.pfr.service.alg.listener;
+
+import lombok.Getter;
+import org.springframework.context.ApplicationEvent;
+
+/**
+ * 录波事件
+ *
+ * @author jy
+ * @since 2023/11/14
+ */
+public class FaultRecorderEvent extends ApplicationEvent {
+    @Getter
+    private final String eventType;
+    @Getter
+    private final Long sj;
+
+    public FaultRecorderEvent(Object source, String eventType,Long sj) {
+        super(source);
+        this.eventType = eventType;
+        this.sj = sj;
+    }
+}

+ 63 - 0
backend/src/main/java/com/jiayue/pfr/service/alg/listener/FaultRecorderListener.java

@@ -0,0 +1,63 @@
+package com.jiayue.pfr.service.alg.listener;
+
+
+import cn.hutool.cache.impl.CacheObj;
+import com.jiayue.pfr.backenum.FaultRecorderTypeEnum;
+import com.jiayue.pfr.constant.CacheConstants;
+import com.jiayue.pfr.dto.FmDataBeanDto;
+import com.jiayue.pfr.entity.ElectricField;
+import com.jiayue.pfr.entity.FaultRecorderData;
+import com.jiayue.pfr.service.alg.FaultRecorderDataService;
+import com.jiayue.pfr.service.cmf.SysParameterService;
+
+import org.apache.commons.lang.time.DateFormatUtils;
+import org.checkerframework.checker.units.qual.A;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationListener;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Component;
+
+import java.text.SimpleDateFormat;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+
+/**
+ * 故障录波监听
+ *
+ * @author xsl
+ * @since 2023/11/09
+ */
+@Component
+public class FaultRecorderListener implements ApplicationListener<FaultRecorderEvent> {
+    @Autowired
+    SysParameterService sysParameterService;
+    @Autowired
+    FaultRecorderDataService faultRecorderDataService;
+
+    private static final Logger fLogger = LoggerFactory.getLogger("FLogger");
+
+    @Async
+    @Override
+    public void onApplicationEvent(FaultRecorderEvent faultRecorderEvent) {
+        String ieSignal = sysParameterService.queryByKey("ieSignal","ON");
+        if ("ON".equals(ieSignal)) {
+            String eventType = faultRecorderEvent.getEventType();
+            Long sj = faultRecorderEvent.getSj();
+            if (FaultRecorderTypeEnum.valueOf(eventType).getCode().intValue()==1){// 频率异常
+                // 记录异常开始时间
+                CacheConstants.exceptionStartTime = sj;
+            }
+            else{
+                // 频率正常
+                if (CacheConstants.exceptionStartTime.longValue()>0) {
+                    faultRecorderDataService.saveFdAndDetail(CacheConstants.exceptionStartTime,sj);
+                    CacheConstants.exceptionStartTime = 0L;
+                }
+            }
+        }
+    }
+}