暂态波形文件接收解析功能

This commit is contained in:
2023-10-08 10:46:58 +08:00
parent 29407e4389
commit 34fc978543
9 changed files with 236 additions and 96 deletions

View File

@@ -0,0 +1,16 @@
package com.njcn.zlevent.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.njcn.zlevent.pojo.po.CsWave;
/**
* <p>
* 治理波形文件记录表 Mapper 接口
* </p>
*
* @author xuyang
* @since 2023-09-27
*/
public interface CsWaveMapper extends BaseMapper<CsWave> {
}

View File

@@ -0,0 +1,23 @@
package com.njcn.zlevent.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.zlevent.pojo.po.CsWave;
/**
* <p>
* 治理波形文件记录表 服务类
* </p>
*
* @author xuyang
* @since 2023-09-27
*/
public interface ICsWaveService extends IService<CsWave> {
/**
* 根据文件名称模糊匹配文件个数
* @param fileName 文件名称
* @return
*/
int findCountByName(String fileName);
}

View File

@@ -22,6 +22,7 @@ import com.njcn.zlevent.pojo.constant.ZlConstant;
import com.njcn.zlevent.pojo.dto.WaveTimeDto;
import com.njcn.zlevent.service.ICsWaveAnalysisService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Service;
@@ -36,6 +37,7 @@ import java.util.stream.Collectors;
* @version 1.0.0
* @createTime 2023/9/5 14:52
*/
@Slf4j
@Service
@AllArgsConstructor
public class CsWaveAnalysisServiceImpl implements ICsWaveAnalysisService {
@@ -108,6 +110,7 @@ public class CsWaveAnalysisServiceImpl implements ICsWaveAnalysisService {
String json = "{Name:\""+fileName+"\"}";
JSONObject jsonObject = JSONObject.fromObject(json);
reqAndResParam.setMsg(jsonObject);
log.info("请求文件信息报文:" + new Gson().toJson(reqAndResParam));
publisher.send("/Pfm/DevFileCmd/"+version+"/"+nDid,new Gson().toJson(reqAndResParam),1,false);
}
@@ -138,7 +141,7 @@ public class CsWaveAnalysisServiceImpl implements ICsWaveAnalysisService {
waveTimeDto.setDeviceId(deviceId);
waveTimeDto.setLineId(lineId);
waveTimeDto.setLocation(location);
redisUtil.saveByKeyWithExpire(AppRedisKey.TIME+fileName,waveTimeDto,60L);
redisUtil.saveByKeyWithExpire(AppRedisKey.TIME+fileName,waveTimeDto,600L);
}
/**

View File

@@ -0,0 +1,27 @@
package com.njcn.zlevent.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.zlevent.mapper.CsWaveMapper;
import com.njcn.zlevent.pojo.po.CsWave;
import com.njcn.zlevent.service.ICsWaveService;
import org.springframework.stereotype.Service;
/**
* <p>
* 治理波形文件记录表 服务实现类
* </p>
*
* @author xuyang
* @since 2023-09-27
*/
@Service
public class CsWaveServiceImpl extends ServiceImpl<CsWaveMapper, CsWave> implements ICsWaveService {
@Override
public int findCountByName(String fileName) {
LambdaQueryWrapper<CsWave> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.like(CsWave::getRcdName,fileName);
return this.baseMapper.selectCount(lambdaQueryWrapper);
}
}

View File

@@ -24,8 +24,10 @@ import com.njcn.zlevent.pojo.dto.FileInfoDto;
import com.njcn.zlevent.pojo.dto.FileStreamDto;
import com.njcn.zlevent.pojo.dto.WaveTimeDto;
import com.njcn.zlevent.pojo.po.CsEventFileLogs;
import com.njcn.zlevent.pojo.po.CsWave;
import com.njcn.zlevent.service.ICsEventFileLogsService;
import com.njcn.zlevent.service.ICsEventService;
import com.njcn.zlevent.service.ICsWaveService;
import com.njcn.zlevent.service.IFileService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -38,6 +40,7 @@ import java.io.InputStream;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* 类的介绍:
@@ -65,6 +68,8 @@ public class FileServiceImpl implements IFileService {
private final WavePicFeignClient wavePicFeignClient;
private final ICsWaveService csWaveService;
@Override
public void analysisFileInfo(AppFileMessage appFileMessage) {
if (Objects.equals(appFileMessage.getCode(), AccessEnum.SUCCESS.getCode())){
@@ -74,18 +79,6 @@ public class FileServiceImpl implements IFileService {
String fileName = appFileMessage.getMsg().getFileInfo().getName();
//缓存文件信息用于文件流拼接
FileInfoDto fileInfoDto = new FileInfoDto();
//文件流请求 判断文件大小是否需要分片请求,单次文件大小为50k
if (fileSize <= range){
askFileStream(appFileMessage.getId(),mid,fileName,0,fileSize);
fileInfoDto.setNumber(1);
} else {
int total = (int)Math.ceil(fileSize*1.0/range) ;
for (int i = 0; i < total; i++) {
askFileStream(appFileMessage.getId(),mid,fileName,i*range,range);
mid++;
}
fileInfoDto.setNumber(mid-1);
}
//获取波形文件起始结束时间
Object fileInfo = redisUtil.getObjectByKey(AppRedisKey.TIME+fileName);
if (Objects.isNull(fileInfo)){
@@ -102,7 +95,18 @@ public class FileServiceImpl implements IFileService {
fileInfoDto.setFileCheck(appFileMessage.getMsg().getFileInfo().getFileCheck());
fileInfoDto.setFileChkType(appFileMessage.getMsg().getFileInfo().getFileChkType());
fileInfoDto.setLocation(waveTimeDto.getLocation());
redisUtil.saveByKeyWithExpire(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileInfoDto.getName()), fileInfoDto, 3600L);
//文件流请求 判断文件大小是否需要分片请求,单次文件大小为50k
if (fileSize <= range){
askFileStream(appFileMessage.getId(),mid,fileName,0,fileSize);
fileInfoDto.setNumber(1);
redisUtil.delete(AppRedisKey.FILE_PART.concat(fileInfoDto.getName() + mid));
redisUtil.saveByKey(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileInfoDto.getName()), fileInfoDto);
} else {
int total = (int)Math.ceil(fileSize*1.0/range);
fileInfoDto.setNumber(total);
redisUtil.saveByKey(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileInfoDto.getName()), fileInfoDto);
askFileStream(appFileMessage.getId(), 1, fileName, 0, range);
}
redisUtil.delete(AppRedisKey.TIME+fileName);
} else {
throw new BusinessException(AccessResponseEnum.RESPONSE_ERROR);
@@ -111,6 +115,11 @@ public class FileServiceImpl implements IFileService {
@Override
public void analysisFileStream(AppFileMessage appFileMessage) {
int range = 51200;
//波形文件上传成功后,将文件信息存储一下,方便后期查看
CsWave csWave = new CsWave();
csWave.setNdid(appFileMessage.getId());
csWave.setCreateTime(LocalDateTime.now());
//日志记录
CsEventFileLogs csEventLogs = new CsEventFileLogs();
csEventLogs.setNdid(appFileMessage.getId());
@@ -138,24 +147,36 @@ public class FileServiceImpl implements IFileService {
if(fileInfoDto.getNumber() == 1) {
//直接解析文件
filePath = fileStream(1,null,appFileMessage.getMsg().getData(),fileName,appFileMessage.getId());
redisUtil.delete(fileName);
csEventLogs.setStatus(1);
csEventLogs.setRemark("当前文件1帧,全部收到,解析成功!");
csEventLogs.setNowStep(1);
csEventLogs.setAllStep(1);
csEventLogs.setIsAll(1);
//记录文件信息
createCsWave(csWave,fileInfoDto,fmt,fileName);
//波形文件关联事件
filePath = filePath.replaceAll(GeneralConstant.CFG,"").replaceAll(GeneralConstant.DAT,"");
List<String> eventList = correlateEvents(fileInfoDto,filePath);
List<String> eventList = correlateEvents(fileInfoDto,filePath,fileName);
//波形文件解析成图片
if (CollectionUtil.isNotEmpty(eventList)){
eventList.forEach(wavePicFeignClient::getWavePics);
}
csEventLogs.setStatus(1);
csEventLogs.setRemark("当前文件1帧,全部收到,解析成功!");
//todo 记录文件信息
redisUtil.delete(fileName);
redisUtil.delete(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileInfoDto.getName()));
} else {
//缓存文件
map.put(appFileMessage.getMid(),appFileMessage.getMsg().getData());
fileStreamDto.setMap(map);
redisUtil.saveByKeyWithExpire(fileName, fileStreamDto, 3600L);
redisUtil.saveByKey(fileName, fileStreamDto);
csEventLogs.setStatus(1);
csEventLogs.setRemark("当前文件"+fileInfoDto.getNumber()+"帧,这是第"+appFileMessage.getMid()+"帧,记录成功!");
csEventLogs.setNowStep(appFileMessage.getMid());
csEventLogs.setAllStep(fileInfoDto.getNumber());
csEventLogs.setIsAll(0);
log.info("当前文件 {} 帧,这是第 {} 帧报文,记录成功", fileInfoDto.getNumber(), appFileMessage.getMid());
//收到文件后,继续请求下一帧报文
askFileStream(appFileMessage.getId(), appFileMessage.getMid()+1, fileName, appFileMessage.getMid() * range, range);
redisUtil.delete(AppRedisKey.FILE_PART.concat(fileInfoDto.getName() + appFileMessage.getMid()));
}
} else {
//分帧传递数据,需要校验收到的文件个数
@@ -165,25 +186,37 @@ public class FileServiceImpl implements IFileService {
if (l1.size() == fileInfoDto.getNumber()){
//解析文件
filePath = fileStream(fileInfoDto.getNumber(),l1,null,fileName,appFileMessage.getId());
redisUtil.delete(fileName);
csEventLogs.setStatus(1);
csEventLogs.setRemark("当前文件"+l1.size()+"帧,这是第"+l1.size()+"帧,全部收到,解析成功!");
csEventLogs.setNowStep(l1.size());
csEventLogs.setAllStep(l1.size());
csEventLogs.setIsAll(1);
log.info("当前文件 {} 帧,这是第 {} 帧报文,全部收到,解析成功!", l1.size(), l1.size());
//记录文件信息
createCsWave(csWave,fileInfoDto,fmt,fileName);
//波形文件关联事件
filePath = filePath.replaceAll(GeneralConstant.CFG,"").replaceAll(GeneralConstant.DAT,"");
List<String> eventList = correlateEvents(fileInfoDto,filePath);
List<String> eventList = correlateEvents(fileInfoDto,filePath,fileName);
//波形文件解析成图片
if (CollectionUtil.isNotEmpty(eventList)){
eventList.forEach(wavePicFeignClient::getWavePics);
}
csEventLogs.setStatus(1);
csEventLogs.setRemark("当前文件"+l1.size()+"帧,这是第"+l1.size()+"帧,全部收到,解析成功!");
//todo 记录文件信息
redisUtil.delete(fileName);
redisUtil.delete(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileInfoDto.getName()));
} else {
//缓存
fileStreamDto = new FileStreamDto();
fileStreamDto.setMap(l1);
redisUtil.saveByKeyWithExpire(fileName, fileStreamDto, 3600L);
redisUtil.saveByKey(fileName, fileStreamDto);
csEventLogs.setStatus(1);
csEventLogs.setRemark("当前文件"+fileInfoDto.getNumber()+"帧,这是第"+appFileMessage.getMid()+"帧,记录成功!");
csEventLogs.setNowStep(appFileMessage.getMid());
csEventLogs.setAllStep(fileInfoDto.getNumber());
csEventLogs.setIsAll(0);
log.info("当前文件 {} 帧,这是第 {} 帧报文,记录成功", fileInfoDto.getNumber(), appFileMessage.getMid());
//收到文件后,继续请求下一帧报文
askFileStream(appFileMessage.getId(), appFileMessage.getMid()+1, fileName, appFileMessage.getMid() * range, range);
redisUtil.delete(AppRedisKey.FILE_PART.concat(fileInfoDto.getName() + appFileMessage.getMid()));
}
}
csEventLogs.setCompleteTime(LocalDateTime.now());
@@ -302,14 +335,37 @@ public class FileServiceImpl implements IFileService {
/**
* 波形文件关联事件
*/
public List<String> correlateEvents(FileInfoDto fileInfoDto, String path) {
CsEventParam csEventParam = new CsEventParam();
csEventParam.setLineId(fileInfoDto.getLineId());
csEventParam.setDeviceId(fileInfoDto.getDeviceId());
csEventParam.setStartTime(fileInfoDto.getStartTime());
csEventParam.setEndTime(fileInfoDto.getEndTime());
csEventParam.setPath(path);
csEventParam.setLocation(fileInfoDto.getLocation());
return csEventService.updateCsEvent(csEventParam);
public List<String> correlateEvents(FileInfoDto fileInfoDto, String path, String fileName) {
List<String> list = new ArrayList<>();
String[] parts = fileName.split(StrUtil.SLASH);
fileName = parts[parts.length - 1].split("\\.")[0];
int fileCounts = csWaveService.findCountByName(fileName);
if (fileCounts >= 2){
CsEventParam csEventParam = new CsEventParam();
csEventParam.setLineId(fileInfoDto.getLineId());
csEventParam.setDeviceId(fileInfoDto.getDeviceId());
csEventParam.setStartTime(fileInfoDto.getStartTime());
csEventParam.setEndTime(fileInfoDto.getEndTime());
csEventParam.setPath(path);
csEventParam.setLocation(fileInfoDto.getLocation());
list = csEventService.updateCsEvent(csEventParam);
}
return list;
}
/**
* 生成波形记录
*/
public void createCsWave(CsWave csWave, FileInfoDto fileInfoDto, DateTimeFormatter fmt, String fileName) {
csWave.setStartTime(LocalDateTime.parse(fileInfoDto.getStartTime(), fmt));
csWave.setEndTime(LocalDateTime.parse(fileInfoDto.getEndTime(), fmt));
csWave.setRcdName(fileName);
csWave.setLocation(fileInfoDto.getLocation());
csWave.setFileSize(fileInfoDto.getFileSize());
csWave.setCheckType(fileInfoDto.getFileChkType());
csWave.setCheckNumber(fileInfoDto.getFileCheck());
csWaveService.save(csWave);
}
}