暂态波形文件接收解析功能
This commit is contained in:
@@ -43,6 +43,7 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@@ -52,6 +53,8 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -361,6 +364,7 @@ public class MqttMessageHandler {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 装置心跳 && 主动数据上送
|
* 装置心跳 && 主动数据上送
|
||||||
|
* fixme 这边由于接收文件数据时间跨度会很长,途中有其他请求进来会中断之前的程序,目前是记录中断的位置,等处理完成再继续请求接收文件
|
||||||
* @param topic
|
* @param topic
|
||||||
* @param message
|
* @param message
|
||||||
* @param version
|
* @param version
|
||||||
@@ -388,7 +392,7 @@ public class MqttMessageHandler {
|
|||||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_29.getCode()));
|
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_29.getCode()));
|
||||||
reqAndResParam.setCode(200);
|
reqAndResParam.setCode(200);
|
||||||
//fixme 前置处理的时间应该是UTC时间,所以需要加8小时。
|
//fixme 前置处理的时间应该是UTC时间,所以需要加8小时。
|
||||||
String json = "{Time:\""+(System.currentTimeMillis()/1000+8*3600)+"\"}";
|
String json = "{Time:"+(System.currentTimeMillis()/1000+8*3600)+"}";
|
||||||
net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(json);
|
net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(json);
|
||||||
reqAndResParam.setMsg(jsonObject);
|
reqAndResParam.setMsg(jsonObject);
|
||||||
publisher.send("/Dev/DataRsp/"+version+"/"+nDid,gson.toJson(reqAndResParam),1,false);
|
publisher.send("/Dev/DataRsp/"+version+"/"+nDid,gson.toJson(reqAndResParam),1,false);
|
||||||
@@ -407,6 +411,18 @@ public class MqttMessageHandler {
|
|||||||
break;
|
break;
|
||||||
case 4866:
|
case 4866:
|
||||||
AutoDataDto dataDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), AutoDataDto.class);
|
AutoDataDto dataDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), AutoDataDto.class);
|
||||||
|
//mid大于0,则需要应答设备侧
|
||||||
|
if (dataDto.getMid() > 0){
|
||||||
|
ReqAndResDto.Res response = new ReqAndResDto.Res();
|
||||||
|
response.setMid(dataDto.getMid());
|
||||||
|
response.setDid(dataDto.getDid());
|
||||||
|
response.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||||
|
response.setType(Integer.parseInt(TypeEnum.TYPE_15.getCode()));
|
||||||
|
response.setCode(200);
|
||||||
|
log.info("应答事件:" + new Gson().toJson(response));
|
||||||
|
publisher.send("/Dev/DataRsp/"+version+"/"+nDid,new Gson().toJson(response),1,false);
|
||||||
|
}
|
||||||
|
//判断事件类型
|
||||||
switch (dataDto.getMsg().getDataAttr()) {
|
switch (dataDto.getMsg().getDataAttr()) {
|
||||||
//暂态事件、录波处理
|
//暂态事件、录波处理
|
||||||
case 0:
|
case 0:
|
||||||
@@ -433,17 +449,6 @@ public class MqttMessageHandler {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//mid大于0,则需要应答设备侧
|
|
||||||
if (dataDto.getMid() > 0){
|
|
||||||
ReqAndResDto.Res response = new ReqAndResDto.Res();
|
|
||||||
response.setMid(dataDto.getMid());
|
|
||||||
response.setDid(dataDto.getDid());
|
|
||||||
response.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
|
||||||
response.setType(Integer.parseInt(TypeEnum.TYPE_15.getCode()));
|
|
||||||
response.setCode(200);
|
|
||||||
log.info("应答事件:" + new Gson().toJson(response));
|
|
||||||
publisher.send("/Dev/DataRsp/"+version+"/"+nDid,new Gson().toJson(response),1,false);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@@ -471,15 +476,16 @@ public class MqttMessageHandler {
|
|||||||
switch (fileDto.getType()){
|
switch (fileDto.getType()){
|
||||||
case 4657:
|
case 4657:
|
||||||
log.info("获取文件信息");
|
log.info("获取文件信息");
|
||||||
|
log.info("文件信息响应:" + fileDto);
|
||||||
appFileMessageTemplate.sendMember(appFileMessage);
|
appFileMessageTemplate.sendMember(appFileMessage);
|
||||||
break;
|
break;
|
||||||
case 4658:
|
case 4658:
|
||||||
log.info("获取文件流信息");
|
log.info("获取文件流信息");
|
||||||
|
redisUtil.saveByKeyWithExpire(AppRedisKey.FILE_PART.concat(appFileMessage.getMsg().getName() + appFileMessage.getMid()), appFileMessage.getMid(),3600L);
|
||||||
appFileStreamMessageTemplate.sendMember(appFileMessage);
|
appFileStreamMessageTemplate.sendMember(appFileMessage);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +1,47 @@
|
|||||||
//package com.njcn.access.runner;
|
package com.njcn.access.runner;
|
||||||
//
|
|
||||||
//import com.njcn.access.service.ICsEquipmentDeliveryService;
|
import com.njcn.access.service.ICsEquipmentDeliveryService;
|
||||||
//import com.njcn.access.service.ICsTopicService;
|
import com.njcn.access.service.ICsTopicService;
|
||||||
//import com.njcn.access.service.impl.CsDeviceServiceImpl;
|
import com.njcn.access.service.impl.CsDeviceServiceImpl;
|
||||||
//import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
import com.njcn.csdevice.pojo.po.CsEquipmentDeliveryPO;
|
||||||
//import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
//import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationArguments;
|
||||||
//import org.springframework.boot.ApplicationRunner;
|
import org.springframework.boot.ApplicationRunner;
|
||||||
//import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
//
|
|
||||||
//import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
//import java.util.List;
|
import java.util.List;
|
||||||
//import java.util.Objects;
|
import java.util.Objects;
|
||||||
//
|
|
||||||
///**
|
/**
|
||||||
// * 类的介绍:用来重新发起设备的接入,存在程序意外停止了,缓存失效导致无法更新装置的状态,所以需要在程序启动时发起设备的接入
|
* 类的介绍:用来重新发起设备的接入,存在程序意外停止了,缓存失效导致无法更新装置的状态,所以需要在程序启动时发起设备的接入
|
||||||
// *
|
*
|
||||||
// * @author xuyang
|
* @author xuyang
|
||||||
// * @version 1.0.0
|
* @version 1.0.0
|
||||||
// * @createTime 2023/8/28 13:57
|
* @createTime 2023/8/28 13:57
|
||||||
// */
|
*/
|
||||||
//@Component
|
@Component
|
||||||
//@Slf4j
|
@Slf4j
|
||||||
//public class AccessApplicationRunner implements ApplicationRunner {
|
public class AccessApplicationRunner implements ApplicationRunner {
|
||||||
//
|
|
||||||
// @Resource
|
@Resource
|
||||||
// private CsDeviceServiceImpl csDeviceService;
|
private CsDeviceServiceImpl csDeviceService;
|
||||||
//
|
|
||||||
// @Resource
|
@Resource
|
||||||
// private ICsTopicService csTopicService;
|
private ICsTopicService csTopicService;
|
||||||
//
|
|
||||||
// @Resource
|
@Resource
|
||||||
// private ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
private ICsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||||
//
|
|
||||||
// @Override
|
@Override
|
||||||
// public void run(ApplicationArguments args){
|
public void run(ApplicationArguments args){
|
||||||
// List<CsEquipmentDeliveryPO> list = csEquipmentDeliveryService.getAll();
|
List<CsEquipmentDeliveryPO> list = csEquipmentDeliveryService.getAll();
|
||||||
// list.forEach(item->{
|
list.forEach(item->{
|
||||||
// String version = csTopicService.getVersion(item.getNdid());
|
String version = csTopicService.getVersion(item.getNdid());
|
||||||
// if (!Objects.isNull(version)){
|
if (!Objects.isNull(version)){
|
||||||
// csDeviceService.devAccess(item.getNdid(),version);
|
csDeviceService.devAccess(item.getNdid(),version);
|
||||||
// }
|
}
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
//}
|
}
|
||||||
|
|||||||
@@ -68,4 +68,10 @@ public class CsEventFileLogs {
|
|||||||
*/
|
*/
|
||||||
private String location;
|
private String location;
|
||||||
|
|
||||||
|
private Integer nowStep;
|
||||||
|
|
||||||
|
private Integer allStep;
|
||||||
|
|
||||||
|
private Integer isAll;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.annotation.TableName;
|
|||||||
import com.njcn.db.bo.BaseEntity;
|
import com.njcn.db.bo.BaseEntity;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
@@ -15,6 +17,7 @@ import lombok.Setter;
|
|||||||
* @author xuyang
|
* @author xuyang
|
||||||
* @since 2023-09-27
|
* @since 2023-09-27
|
||||||
*/
|
*/
|
||||||
|
@Data
|
||||||
@TableName("cs_wave")
|
@TableName("cs_wave")
|
||||||
public class CsWave {
|
public class CsWave {
|
||||||
|
|
||||||
|
|||||||
@@ -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> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -22,6 +22,7 @@ import com.njcn.zlevent.pojo.constant.ZlConstant;
|
|||||||
import com.njcn.zlevent.pojo.dto.WaveTimeDto;
|
import com.njcn.zlevent.pojo.dto.WaveTimeDto;
|
||||||
import com.njcn.zlevent.service.ICsWaveAnalysisService;
|
import com.njcn.zlevent.service.ICsWaveAnalysisService;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.sf.json.JSONObject;
|
import net.sf.json.JSONObject;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -36,6 +37,7 @@ import java.util.stream.Collectors;
|
|||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
* @createTime 2023/9/5 14:52
|
* @createTime 2023/9/5 14:52
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class CsWaveAnalysisServiceImpl implements ICsWaveAnalysisService {
|
public class CsWaveAnalysisServiceImpl implements ICsWaveAnalysisService {
|
||||||
@@ -108,6 +110,7 @@ public class CsWaveAnalysisServiceImpl implements ICsWaveAnalysisService {
|
|||||||
String json = "{Name:\""+fileName+"\"}";
|
String json = "{Name:\""+fileName+"\"}";
|
||||||
JSONObject jsonObject = JSONObject.fromObject(json);
|
JSONObject jsonObject = JSONObject.fromObject(json);
|
||||||
reqAndResParam.setMsg(jsonObject);
|
reqAndResParam.setMsg(jsonObject);
|
||||||
|
log.info("请求文件信息报文:" + new Gson().toJson(reqAndResParam));
|
||||||
publisher.send("/Pfm/DevFileCmd/"+version+"/"+nDid,new Gson().toJson(reqAndResParam),1,false);
|
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.setDeviceId(deviceId);
|
||||||
waveTimeDto.setLineId(lineId);
|
waveTimeDto.setLineId(lineId);
|
||||||
waveTimeDto.setLocation(location);
|
waveTimeDto.setLocation(location);
|
||||||
redisUtil.saveByKeyWithExpire(AppRedisKey.TIME+fileName,waveTimeDto,60L);
|
redisUtil.saveByKeyWithExpire(AppRedisKey.TIME+fileName,waveTimeDto,600L);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,8 +24,10 @@ import com.njcn.zlevent.pojo.dto.FileInfoDto;
|
|||||||
import com.njcn.zlevent.pojo.dto.FileStreamDto;
|
import com.njcn.zlevent.pojo.dto.FileStreamDto;
|
||||||
import com.njcn.zlevent.pojo.dto.WaveTimeDto;
|
import com.njcn.zlevent.pojo.dto.WaveTimeDto;
|
||||||
import com.njcn.zlevent.pojo.po.CsEventFileLogs;
|
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.ICsEventFileLogsService;
|
||||||
import com.njcn.zlevent.service.ICsEventService;
|
import com.njcn.zlevent.service.ICsEventService;
|
||||||
|
import com.njcn.zlevent.service.ICsWaveService;
|
||||||
import com.njcn.zlevent.service.IFileService;
|
import com.njcn.zlevent.service.IFileService;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -38,6 +40,7 @@ import java.io.InputStream;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 类的介绍:
|
* 类的介绍:
|
||||||
@@ -65,6 +68,8 @@ public class FileServiceImpl implements IFileService {
|
|||||||
|
|
||||||
private final WavePicFeignClient wavePicFeignClient;
|
private final WavePicFeignClient wavePicFeignClient;
|
||||||
|
|
||||||
|
private final ICsWaveService csWaveService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void analysisFileInfo(AppFileMessage appFileMessage) {
|
public void analysisFileInfo(AppFileMessage appFileMessage) {
|
||||||
if (Objects.equals(appFileMessage.getCode(), AccessEnum.SUCCESS.getCode())){
|
if (Objects.equals(appFileMessage.getCode(), AccessEnum.SUCCESS.getCode())){
|
||||||
@@ -74,18 +79,6 @@ public class FileServiceImpl implements IFileService {
|
|||||||
String fileName = appFileMessage.getMsg().getFileInfo().getName();
|
String fileName = appFileMessage.getMsg().getFileInfo().getName();
|
||||||
//缓存文件信息用于文件流拼接
|
//缓存文件信息用于文件流拼接
|
||||||
FileInfoDto fileInfoDto = new FileInfoDto();
|
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);
|
Object fileInfo = redisUtil.getObjectByKey(AppRedisKey.TIME+fileName);
|
||||||
if (Objects.isNull(fileInfo)){
|
if (Objects.isNull(fileInfo)){
|
||||||
@@ -102,7 +95,18 @@ public class FileServiceImpl implements IFileService {
|
|||||||
fileInfoDto.setFileCheck(appFileMessage.getMsg().getFileInfo().getFileCheck());
|
fileInfoDto.setFileCheck(appFileMessage.getMsg().getFileInfo().getFileCheck());
|
||||||
fileInfoDto.setFileChkType(appFileMessage.getMsg().getFileInfo().getFileChkType());
|
fileInfoDto.setFileChkType(appFileMessage.getMsg().getFileInfo().getFileChkType());
|
||||||
fileInfoDto.setLocation(waveTimeDto.getLocation());
|
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);
|
redisUtil.delete(AppRedisKey.TIME+fileName);
|
||||||
} else {
|
} else {
|
||||||
throw new BusinessException(AccessResponseEnum.RESPONSE_ERROR);
|
throw new BusinessException(AccessResponseEnum.RESPONSE_ERROR);
|
||||||
@@ -111,6 +115,11 @@ public class FileServiceImpl implements IFileService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void analysisFileStream(AppFileMessage appFileMessage) {
|
public void analysisFileStream(AppFileMessage appFileMessage) {
|
||||||
|
int range = 51200;
|
||||||
|
//波形文件上传成功后,将文件信息存储一下,方便后期查看
|
||||||
|
CsWave csWave = new CsWave();
|
||||||
|
csWave.setNdid(appFileMessage.getId());
|
||||||
|
csWave.setCreateTime(LocalDateTime.now());
|
||||||
//日志记录
|
//日志记录
|
||||||
CsEventFileLogs csEventLogs = new CsEventFileLogs();
|
CsEventFileLogs csEventLogs = new CsEventFileLogs();
|
||||||
csEventLogs.setNdid(appFileMessage.getId());
|
csEventLogs.setNdid(appFileMessage.getId());
|
||||||
@@ -138,24 +147,36 @@ public class FileServiceImpl implements IFileService {
|
|||||||
if(fileInfoDto.getNumber() == 1) {
|
if(fileInfoDto.getNumber() == 1) {
|
||||||
//直接解析文件
|
//直接解析文件
|
||||||
filePath = fileStream(1,null,appFileMessage.getMsg().getData(),fileName,appFileMessage.getId());
|
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,"");
|
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)){
|
if (CollectionUtil.isNotEmpty(eventList)){
|
||||||
eventList.forEach(wavePicFeignClient::getWavePics);
|
eventList.forEach(wavePicFeignClient::getWavePics);
|
||||||
}
|
}
|
||||||
csEventLogs.setStatus(1);
|
redisUtil.delete(fileName);
|
||||||
csEventLogs.setRemark("当前文件1帧,全部收到,解析成功!");
|
redisUtil.delete(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileInfoDto.getName()));
|
||||||
//todo 记录文件信息
|
|
||||||
} else {
|
} else {
|
||||||
//缓存文件
|
//缓存文件
|
||||||
map.put(appFileMessage.getMid(),appFileMessage.getMsg().getData());
|
map.put(appFileMessage.getMid(),appFileMessage.getMsg().getData());
|
||||||
fileStreamDto.setMap(map);
|
fileStreamDto.setMap(map);
|
||||||
redisUtil.saveByKeyWithExpire(fileName, fileStreamDto, 3600L);
|
redisUtil.saveByKey(fileName, fileStreamDto);
|
||||||
csEventLogs.setStatus(1);
|
csEventLogs.setStatus(1);
|
||||||
csEventLogs.setRemark("当前文件"+fileInfoDto.getNumber()+"帧,这是第"+appFileMessage.getMid()+"帧,记录成功!");
|
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 {
|
} else {
|
||||||
//分帧传递数据,需要校验收到的文件个数
|
//分帧传递数据,需要校验收到的文件个数
|
||||||
@@ -165,25 +186,37 @@ public class FileServiceImpl implements IFileService {
|
|||||||
if (l1.size() == fileInfoDto.getNumber()){
|
if (l1.size() == fileInfoDto.getNumber()){
|
||||||
//解析文件
|
//解析文件
|
||||||
filePath = fileStream(fileInfoDto.getNumber(),l1,null,fileName,appFileMessage.getId());
|
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,"");
|
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)){
|
if (CollectionUtil.isNotEmpty(eventList)){
|
||||||
eventList.forEach(wavePicFeignClient::getWavePics);
|
eventList.forEach(wavePicFeignClient::getWavePics);
|
||||||
}
|
}
|
||||||
csEventLogs.setStatus(1);
|
redisUtil.delete(fileName);
|
||||||
csEventLogs.setRemark("当前文件"+l1.size()+"帧,这是第"+l1.size()+"帧,全部收到,解析成功!");
|
redisUtil.delete(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileInfoDto.getName()));
|
||||||
//todo 记录文件信息
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
//缓存
|
//缓存
|
||||||
fileStreamDto = new FileStreamDto();
|
fileStreamDto = new FileStreamDto();
|
||||||
fileStreamDto.setMap(l1);
|
fileStreamDto.setMap(l1);
|
||||||
redisUtil.saveByKeyWithExpire(fileName, fileStreamDto, 3600L);
|
redisUtil.saveByKey(fileName, fileStreamDto);
|
||||||
csEventLogs.setStatus(1);
|
csEventLogs.setStatus(1);
|
||||||
csEventLogs.setRemark("当前文件"+fileInfoDto.getNumber()+"帧,这是第"+appFileMessage.getMid()+"帧,记录成功!");
|
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());
|
csEventLogs.setCompleteTime(LocalDateTime.now());
|
||||||
@@ -302,14 +335,37 @@ public class FileServiceImpl implements IFileService {
|
|||||||
/**
|
/**
|
||||||
* 波形文件关联事件
|
* 波形文件关联事件
|
||||||
*/
|
*/
|
||||||
public List<String> correlateEvents(FileInfoDto fileInfoDto, String path) {
|
public List<String> correlateEvents(FileInfoDto fileInfoDto, String path, String fileName) {
|
||||||
CsEventParam csEventParam = new CsEventParam();
|
List<String> list = new ArrayList<>();
|
||||||
csEventParam.setLineId(fileInfoDto.getLineId());
|
String[] parts = fileName.split(StrUtil.SLASH);
|
||||||
csEventParam.setDeviceId(fileInfoDto.getDeviceId());
|
fileName = parts[parts.length - 1].split("\\.")[0];
|
||||||
csEventParam.setStartTime(fileInfoDto.getStartTime());
|
int fileCounts = csWaveService.findCountByName(fileName);
|
||||||
csEventParam.setEndTime(fileInfoDto.getEndTime());
|
if (fileCounts >= 2){
|
||||||
csEventParam.setPath(path);
|
CsEventParam csEventParam = new CsEventParam();
|
||||||
csEventParam.setLocation(fileInfoDto.getLocation());
|
csEventParam.setLineId(fileInfoDto.getLineId());
|
||||||
return csEventService.updateCsEvent(csEventParam);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user