|
@@ -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);
|
|
|
+ }
|
|
|
+}
|