|
|
|
|
@@ -3,7 +3,6 @@ package com.njcn.csdevice.service.impl;
|
|
|
|
|
import cn.hutool.core.util.IdUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.njcn.common.pojo.exception.BusinessException;
|
|
|
|
|
import com.njcn.csdevice.api.CsLineFeignClient;
|
|
|
|
|
import com.njcn.csdevice.api.EquipmentFeignClient;
|
|
|
|
|
import com.njcn.csdevice.constant.DataParam;
|
|
|
|
|
import com.njcn.csdevice.enums.AlgorithmResponseEnum;
|
|
|
|
|
@@ -21,10 +20,12 @@ import com.njcn.csharmonic.offline.log.Log;
|
|
|
|
|
import com.njcn.csharmonic.offline.log.vo.NewBodyTaglogbuffer;
|
|
|
|
|
import com.njcn.csharmonic.offline.log.vo.NewHeadTaglogbuffer;
|
|
|
|
|
import com.njcn.csharmonic.offline.log.vo.NewTaglogbuffer;
|
|
|
|
|
import com.njcn.csharmonic.offline.log.vo.TagComtradeCfg;
|
|
|
|
|
import com.njcn.csharmonic.offline.mincfg.AnalyseComtradeCfg;
|
|
|
|
|
import com.njcn.csharmonic.offline.mincfg.tagComtradeCfg;
|
|
|
|
|
import com.njcn.csharmonic.offline.mincfg.vo.CmnModeCfg;
|
|
|
|
|
import com.njcn.csharmonic.offline.vo.Response;
|
|
|
|
|
import com.njcn.csharmonic.pojo.po.CsEventPO;
|
|
|
|
|
import com.njcn.influx.imapper.CommonMapper;
|
|
|
|
|
import com.njcn.influx.imapper.EvtDataMapper;
|
|
|
|
|
import com.njcn.influx.imapper.PqdDataMapper;
|
|
|
|
|
import com.njcn.influx.pojo.po.cs.EntData;
|
|
|
|
|
@@ -33,17 +34,17 @@ import com.njcn.oss.utils.FileStorageUtil;
|
|
|
|
|
import com.njcn.system.api.DicDataFeignClient;
|
|
|
|
|
import com.njcn.system.api.EleEvtFeignClient;
|
|
|
|
|
import com.njcn.system.pojo.po.DictData;
|
|
|
|
|
import com.njcn.system.pojo.po.EleEvtParm;
|
|
|
|
|
import com.njcn.web.pojo.param.BaseParam;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.apache.commons.io.FilenameUtils;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
import java.io.*;
|
|
|
|
|
import java.text.DecimalFormat;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.time.ZoneId;
|
|
|
|
|
import java.time.ZoneOffset;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
@@ -61,6 +62,9 @@ import java.util.stream.Stream;
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMapper, PortableOfflLog> implements IPortableOfflLogService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final DecimalFormat df = new DecimalFormat("#0.000");
|
|
|
|
|
|
|
|
|
|
private final FileStorageUtil fileStorageUtil;
|
|
|
|
|
|
|
|
|
|
private final DicDataFeignClient dicDataFeignClient;
|
|
|
|
|
@@ -82,8 +86,12 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
|
|
|
|
|
@Override
|
|
|
|
|
public Page<PortableOfflLog> queryPage(BaseParam baseParam) {
|
|
|
|
|
Page<PortableOfflLog> returnpage = new Page<> (baseParam.getPageNum(), baseParam.getPageSize ());
|
|
|
|
|
if(baseParam.getSearchBeginTime()!=null) baseParam.setSearchBeginTime(baseParam.getSearchBeginTime()+DataParam.startTime);
|
|
|
|
|
if(baseParam.getSearchEndTime()!=null) baseParam.setSearchEndTime(baseParam.getSearchEndTime()+DataParam.endTime);
|
|
|
|
|
if(baseParam.getSearchBeginTime()!=null) {
|
|
|
|
|
baseParam.setSearchBeginTime(baseParam.getSearchBeginTime()+DataParam.startTime);
|
|
|
|
|
}
|
|
|
|
|
if(baseParam.getSearchEndTime()!=null) {
|
|
|
|
|
baseParam.setSearchEndTime(baseParam.getSearchEndTime()+DataParam.endTime);
|
|
|
|
|
}
|
|
|
|
|
returnpage = this.getBaseMapper().queryPage(returnpage,baseParam);
|
|
|
|
|
return returnpage;
|
|
|
|
|
}
|
|
|
|
|
@@ -112,7 +120,7 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
|
|
|
|
|
Response response = new Response();
|
|
|
|
|
response.setFilename(file.getOriginalFilename());
|
|
|
|
|
if(OfflineConstant.COMTRADE.equals(type) && file.getOriginalFilename().indexOf(OfflineConstant.CFG) != -1) {
|
|
|
|
|
tagComtradeCfg tagComtradeCfg = null;
|
|
|
|
|
TagComtradeCfg tagComtradeCfg = null;
|
|
|
|
|
try {
|
|
|
|
|
tagComtradeCfg = AnalyseComtradeCfg.analyseComtradeCfg(file);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
@@ -148,7 +156,33 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = {Exception.class})
|
|
|
|
|
public void importEquipment(UploadDataParam uploadDataParam) {
|
|
|
|
|
public void importEquipment(UploadDataParam uploadDataParam){
|
|
|
|
|
String lineId = uploadDataParam.getLineId();
|
|
|
|
|
String cdid = uploadDataParam.getLineId().substring(uploadDataParam.getLineId().length() - 1);
|
|
|
|
|
//第一步解析redcord.bin文件获取监测点序号做校验
|
|
|
|
|
List<MultipartFile> record = uploadDataParam.getFiles().stream().filter(
|
|
|
|
|
temp -> temp.getOriginalFilename().contains("record.bin"))
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
if(CollectionUtils.isEmpty(record)){
|
|
|
|
|
throw new BusinessException(AlgorithmResponseEnum.RECORD_FILE_LOST);
|
|
|
|
|
}else {
|
|
|
|
|
InputStream inputStream = null;
|
|
|
|
|
try {
|
|
|
|
|
inputStream = record.get(0).getInputStream();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
CmnModeCfg cmnModeCfg = AnalyseComtradeCfg.convertRecord(inputStream);
|
|
|
|
|
//监测点序号
|
|
|
|
|
int lineIdx = cmnModeCfg.line_idx;
|
|
|
|
|
|
|
|
|
|
if(lineIdx!=Integer.valueOf(cdid)){
|
|
|
|
|
throw new BusinessException(AlgorithmResponseEnum.LINE_NUM_MISMATCH);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取离线上传对应的字典规则(字典用来控制上传的文件夹名称,其中字典的name代表名称,code代表该文件夹下对应的解析规则且code不能更改)
|
|
|
|
|
List<DictData> dictDatas = dicDataFeignClient.getDicDataByTypeCode(DataParam.wlRecordUpload).getData();
|
|
|
|
|
List<Response> responses = new ArrayList<>();
|
|
|
|
|
@@ -159,7 +193,9 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
|
|
|
|
|
List<MultipartFile> fileList = new ArrayList<>();
|
|
|
|
|
for(MultipartFile file : uploadDataParam.getFiles()){
|
|
|
|
|
//获取每个文件夹下对应的文件信息
|
|
|
|
|
if(checkPrevsFolder(file.getOriginalFilename(),dictData.getName())!=null) fileList.add(file);
|
|
|
|
|
if(checkPrevsFolder(file.getOriginalFilename(),dictData.getName())!=null) {
|
|
|
|
|
fileList.add(file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(!fileList.isEmpty()){
|
|
|
|
|
//将当前文件夹下的文件统一解析
|
|
|
|
|
@@ -197,11 +233,12 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<CsEquipmentDeliveryDTO> data1 = equipmentFeignClient.queryDeviceById(Stream.of(uploadDataParam.getDevId()).collect(Collectors.toList())).getData();
|
|
|
|
|
|
|
|
|
|
CsEquipmentDeliveryDTO csEquipmentDeliveryDTO = data1.get(0);
|
|
|
|
|
//min文件夹下的文件是否解析过
|
|
|
|
|
boolean minFlag = true;
|
|
|
|
|
//开始上传文件、记录上传日志、解析的文件结果入库
|
|
|
|
|
//最外层便利所有文件确保所有文件都上传及记录上传日志
|
|
|
|
|
|
|
|
|
|
for(MultipartFile file : uploadDataParam.getFiles()){
|
|
|
|
|
//初始上传日志基本信息
|
|
|
|
|
PortableOfflLog portableOfflLog = new PortableOfflLog();
|
|
|
|
|
@@ -213,11 +250,18 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
|
|
|
|
|
//默认总条数及入库数为0(防止解析的数据重复插入及上传的文件目录路径错误)
|
|
|
|
|
portableOfflLog.setAllCount(0);
|
|
|
|
|
portableOfflLog.setRealCount(0);
|
|
|
|
|
|
|
|
|
|
//开始匹配解析的文件结果入库
|
|
|
|
|
for(Response response : responses){
|
|
|
|
|
//min解析结果较为特殊所有的文件解析后只有一条结果
|
|
|
|
|
if(OfflineConstant.MIN.equals(response.getFilename()) && checkPrevsFolder(file.getOriginalFilename(),OfflineConstant.MIN)!=null){
|
|
|
|
|
List<PqdData> pqdData = (List<PqdData>) response.getObj();
|
|
|
|
|
pqdData.forEach(temp->{
|
|
|
|
|
temp.setClDid(cdid);
|
|
|
|
|
temp.setIsAbnormal(0);
|
|
|
|
|
temp.setProcess(data1.get(0).getProcess()+"");
|
|
|
|
|
temp.setLineId(uploadDataParam.getLineId());
|
|
|
|
|
});
|
|
|
|
|
//如果明确返回了state 那么当前文件解析出错
|
|
|
|
|
if(response.getState() != null){
|
|
|
|
|
portableOfflLog.setState(response.getState());
|
|
|
|
|
@@ -241,7 +285,7 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
|
|
|
|
|
if(response.getState() != null){
|
|
|
|
|
portableOfflLog.setState(response.getState());
|
|
|
|
|
}
|
|
|
|
|
tagComtradeCfg tagComtradeCfg = (tagComtradeCfg) response.getObj();
|
|
|
|
|
TagComtradeCfg tagComtradeCfg = (TagComtradeCfg) response.getObj();
|
|
|
|
|
if(tagComtradeCfg != null){
|
|
|
|
|
//否则正常标记为成功解析
|
|
|
|
|
portableOfflLog.setState(1);
|
|
|
|
|
@@ -268,6 +312,7 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
|
|
|
|
|
NewHeadTaglogbuffer newHeadTaglogbuffer = newTaglogbuffer.getNewHeadTaglogbuffer();
|
|
|
|
|
String strId = "";
|
|
|
|
|
String strName = newHeadTaglogbuffer.getLogCode()+"";
|
|
|
|
|
//todo 其他事件做映射
|
|
|
|
|
//中断标志
|
|
|
|
|
if(DataParam.intrStr.contains(newHeadTaglogbuffer.getLogCode())){
|
|
|
|
|
strId = DataParam.intrStrId;
|
|
|
|
|
@@ -283,28 +328,44 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
|
|
|
|
|
strId = DataParam.swlStrId;
|
|
|
|
|
strName = DataParam.swlStrName;
|
|
|
|
|
}
|
|
|
|
|
List<EleEvtParm> eleEvtParms = eleEvtFeignClient.queryByPid(strId).getData();
|
|
|
|
|
//插入事件表
|
|
|
|
|
CsEventPO csEventPO = new CsEventPO();
|
|
|
|
|
csEventPO.setId(IdUtil.simpleUUID());
|
|
|
|
|
csEventPO.setId(IdUtil.fastSimpleUUID());
|
|
|
|
|
csEventPO.setLineId(uploadDataParam.getLineId());
|
|
|
|
|
csEventPO.setDeviceId(uploadDataParam.getDevId());
|
|
|
|
|
csEventPO.setProcess(csEquipmentDeliveryDTO.getProcess());
|
|
|
|
|
//todo 做映射目前置空
|
|
|
|
|
csEventPO.setCode(null);
|
|
|
|
|
csEventPO.setStartTime(newTaglogbuffer.getStart());
|
|
|
|
|
csEventPO.setTag(strName);
|
|
|
|
|
//更具唯一索引做校验存在该事件则跳过;
|
|
|
|
|
CsEventPO data = eventFeignClient.queryByIndex(csEventPO).getData();
|
|
|
|
|
if(Objects.nonNull(data)){
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String wavePath = null;
|
|
|
|
|
//设置波形文件(去cfg结果集里面去找)
|
|
|
|
|
for (Response res : cfgResponse) {
|
|
|
|
|
String cfg = res.getFilename();
|
|
|
|
|
String dat = cfg.substring(0,cfg.lastIndexOf("."))+OfflineConstant.DAT;
|
|
|
|
|
String sharPath = OfflineConstant.COMTRADE+"/"+DataParam.wlRecordPath+uploadDataParam.getDevId()+"/"+uploadDataParam.getLineId()+"/"+getFolderName()+"/";
|
|
|
|
|
tagComtradeCfg sing = (tagComtradeCfg) res.getObj();
|
|
|
|
|
Date date = Date.from(newTaglogbuffer.getStart().atZone( ZoneId.systemDefault()).toInstant());
|
|
|
|
|
String sharPath = OfflineConstant.COMTRADE+"/"+csEquipmentDeliveryDTO.getMac()+"/";
|
|
|
|
|
TagComtradeCfg sing = (TagComtradeCfg) res.getObj();
|
|
|
|
|
//如果匹配上则需要将当前cfg文件及对应的dat文件上传到comtrade文件夹中
|
|
|
|
|
if ((sing!= null && sing.getTimeStart()!= null && sing.getTimeEnd() !=null && sing.getTimeTrigger().compareTo(date) <= 0 && sing.getTimeEnd().compareTo(date) >= 0)) {
|
|
|
|
|
if (sing!= null && sing.getTimeStart()!= null && sing.getTimeTrigger().compareTo(csEventPO.getStartTime())<=0
|
|
|
|
|
&&sing.getTimeEnd().compareTo(csEventPO.getStartTime())>=0) {
|
|
|
|
|
for(MultipartFile f : uploadDataParam.getFiles()){
|
|
|
|
|
if(f.getOriginalFilename().equals(cfg) || f.getOriginalFilename().equals(dat)){
|
|
|
|
|
fileStorageUtil.uploadMultipart(f, sharPath);
|
|
|
|
|
wavePath = sharPath;
|
|
|
|
|
int lastIndex = f.getOriginalFilename().lastIndexOf('/');
|
|
|
|
|
String fileName = f.getOriginalFilename().substring(lastIndex + 1);
|
|
|
|
|
String baseName = FilenameUtils.getBaseName(fileName);
|
|
|
|
|
String extension = FilenameUtils.getExtension(fileName);
|
|
|
|
|
try {
|
|
|
|
|
fileStorageUtil.uploadStreamSpecifyName(f.getInputStream(), sharPath, baseName + "." + extension.toUpperCase());
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
|
|
|
|
wavePath = sharPath+fileName.substring(0,fileName.lastIndexOf("."));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@@ -314,18 +375,24 @@ public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMappe
|
|
|
|
|
csEventPO.setType(0);
|
|
|
|
|
String clDid = influxDbParamUtil.getClDidByLineId(uploadDataParam.getLineId());
|
|
|
|
|
csEventPO.setClDid(clDid == null ? null : Integer.parseInt(clDid));
|
|
|
|
|
//默认告警等级2
|
|
|
|
|
csEventPO.setLevel(2);
|
|
|
|
|
//默认事件发生位置:电网侧
|
|
|
|
|
csEventPO.setLocation("grid");
|
|
|
|
|
csEventPO.setProcess(data1.get(0).getProcess());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
csEventPO.setProcess(csEquipmentDeliveryDTO.getProcess());
|
|
|
|
|
csEventPOS.add(csEventPO);
|
|
|
|
|
EntData entData = new EntData();
|
|
|
|
|
entData.setUuid(csEventPO.getId());
|
|
|
|
|
entData.setTime(new Date().toInstant());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//entData.setTime(newTaglogbuffer.getStart().toInstant(ZoneOffset.UTC));
|
|
|
|
|
for(NewBodyTaglogbuffer newBodyTaglogbuffer : newTaglogbuffer.getNewBodyTaglogbuffers()){
|
|
|
|
|
if(newBodyTaglogbuffer.getParaCode() == 0) entData.setEvtParamVVaDepth(newBodyTaglogbuffer.getParaValue()/65536D);
|
|
|
|
|
if(newBodyTaglogbuffer.getParaCode() == 1) entData.setEvtParamTm(newBodyTaglogbuffer.getParaValue()/65536D);
|
|
|
|
|
if(newBodyTaglogbuffer.getParaCode() == 0) {
|
|
|
|
|
entData.setEvtParamVVaDepth(Double.parseDouble(df.format(newBodyTaglogbuffer.getParaValue()/65536D)));
|
|
|
|
|
}
|
|
|
|
|
if(newBodyTaglogbuffer.getParaCode() == 1) {
|
|
|
|
|
entData.setEvtParamTm(Double.parseDouble(df.format(newBodyTaglogbuffer.getParaValue()/65536D)));
|
|
|
|
|
csEventPO.setPersistTime(Double.parseDouble(df.format(newBodyTaglogbuffer.getParaValue()/65536D)));
|
|
|
|
|
}
|
|
|
|
|
if(newBodyTaglogbuffer.getParaCode() == 5) {
|
|
|
|
|
int code = newBodyTaglogbuffer.getParaValue()/65536;
|
|
|
|
|
switch (code){
|
|
|
|
|
|