1.文件下载调整;

2.bug调整
This commit is contained in:
xy
2024-10-30 16:10:19 +08:00
parent b49b40aa8b
commit 37d369cefd
6 changed files with 46 additions and 37 deletions

View File

@@ -46,7 +46,7 @@ public class AskDeviceDataClientFallbackFactory implements FallbackFactory<AskDe
public HttpResult<Boolean> downloadFile(String nDid, String name, Integer size, String fileCheck) { public HttpResult<Boolean> downloadFile(String nDid, String name, Integer size, String fileCheck) {
log.error("{}异常,降级处理,异常为:{}","文件下载",cause.toString()); log.error("{}异常,降级处理,异常为:{}","文件下载",cause.toString());
redisUtil.delete("fileDowning:" + nDid); redisUtil.delete("fileDowning:" + nDid);
redisUtil.delete("fileCheck"+name); redisUtil.delete("fileCheck"+nDid+name);
throw new BusinessException(finalExceptionEnum); throw new BusinessException(finalExceptionEnum);
} }

View File

@@ -88,30 +88,29 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
public boolean downloadFile(String nDid, String name, Integer size, String fileCheck) { public boolean downloadFile(String nDid, String name, Integer size, String fileCheck) {
boolean result = false; boolean result = false;
try { try {
redisUtil.saveByKeyWithExpire("fileDowning:"+nDid,"fileDowning",600L); redisUtil.saveByKeyWithExpire("fileDowning:"+nDid,"fileDowning",120L);
redisUtil.saveByKeyWithExpire("fileCheck"+name,fileCheck,600L); redisUtil.saveByKeyWithExpire("fileCheck"+nDid+name,fileCheck,120L);
Object object = getDeviceMid(nDid); Object object = getDeviceMid(nDid);
if (!Objects.isNull(object)) { if (!Objects.isNull(object)) {
mid = (Integer) object; mid = (Integer) object;
} }
ReqAndResDto.Req reqAndResParam = getAllPojo(mid,name); ReqAndResDto.Req reqAndResParam = getAllPojo(mid,name);
publisher.send("/Pfm/DevFileCmd/V1/"+nDid,new Gson().toJson(reqAndResParam),1,false); publisher.send("/Pfm/DevFileCmd/V1/"+nDid,new Gson().toJson(reqAndResParam),1,false);
//这里使用简单的轮询,但建议考虑更高效的机制 // //这里使用简单的轮询,但建议考虑更高效的机制
for (int i = 0; i < 12; i++) { // for (int i = 0; i < 60; i++) {
Thread.sleep(10000); // Thread.sleep(5000);
Object object2 = redisUtil.getObjectByKey("downloadFilePath:"+name); // Object object3 = redisUtil.getObjectByKey(AppRedisKey.FILE_PART.concat(name));
if (!Objects.isNull(object2)) { // FileStreamDto dto = JSON.parseObject(JSON.toJSONString(object3), FileStreamDto.class);
result = true; // if (dto.getList().size() == dto.getTotal()) {
break; // result = true;
} else { // String json = "{fileName:"+name+",allStep:"+dto.getTotal()+",nowStep:"+ dto.getTotal() +"}";
Object object3 = redisUtil.getObjectByKey(AppRedisKey.FILE_PART.concat(name)); // publisher.send("/Web/Progress/" + nDid, new Gson().toJson(json), 1, false);
if (!Objects.isNull(object3)) { // break;
FileStreamDto dto = JSON.parseObject(JSON.toJSONString(object3), FileStreamDto.class); // } else {
String json = "{fileName:"+name+",allStep:"+dto.getTotal()+",nowStep:"+ (CollectionUtil.isEmpty(dto.getList())?0:dto.getList().size())+"}"; // String json = "{fileName:"+name+",allStep:"+dto.getTotal()+",nowStep:"+ (CollectionUtil.isEmpty(dto.getList())?0:dto.getList().size())+"}";
publisher.send("/Web/Progress/" + nDid, new Gson().toJson(json), 1, false); // publisher.send("/Web/Progress/" + nDid, new Gson().toJson(json), 1, false);
} // }
} // }
}
mid = mid + 1; mid = mid + 1;
if (mid > 10000) { if (mid > 10000) {
mid = 1; mid = 1;
@@ -119,7 +118,7 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid); redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
} catch (Exception e) { } catch (Exception e) {
redisUtil.delete("fileDowning:"+nDid); redisUtil.delete("fileDowning:"+nDid);
redisUtil.delete("fileCheck"+name); redisUtil.delete("fileCheck"+nDid+name);
throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOAD_ERROR); throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOAD_ERROR);
} }
return result; return result;

View File

@@ -1,5 +1,6 @@
package com.njcn.zlevent.pojo.dto; package com.njcn.zlevent.pojo.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
@@ -17,12 +18,16 @@ import java.util.Set;
@Data @Data
public class FileStreamDto implements Serializable { public class FileStreamDto implements Serializable {
@ApiModelProperty("总帧")
private Integer total; private Integer total;
@ApiModelProperty("nDid")
private String nDid; private String nDid;
@ApiModelProperty("帧大小")
private Integer frameLen; private Integer frameLen;
@ApiModelProperty("帧集合")
private Set<Integer> list; private Set<Integer> list;
} }

View File

@@ -98,17 +98,6 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
downloadFile(missingList,dto.getNDid(),fileName); downloadFile(missingList,dto.getNDid(),fileName);
} }
} }
// //项目重启或者接入经过120s开始处理历史录波文件
// else if (expiredKey.startsWith("startFile")) {
// List<CsEquipmentDeliveryPO> list = equipmentFeignClient.getAll().getData();
// if (CollectionUtil.isNotEmpty(list)) {
// list.forEach(item->{
// redisUtil.delete("handleEvent:" + item.getNdid());
// //处理缓存数据
// csWaveAnalysisService.channelWave(item.getNdid());
// });
// }
// }
//手动文件下载 //手动文件下载
else if (expiredKey.startsWith(AppRedisKey.FILE_DOWN_TIME)) { else if (expiredKey.startsWith(AppRedisKey.FILE_DOWN_TIME)) {
List<Integer> missingList = new ArrayList<>(); List<Integer> missingList = new ArrayList<>();

View File

@@ -20,8 +20,10 @@ import com.njcn.redis.pojo.enums.AppRedisKey;
import com.njcn.redis.utils.RedisUtil; import com.njcn.redis.utils.RedisUtil;
import com.njcn.stat.enums.StatResponseEnum; import com.njcn.stat.enums.StatResponseEnum;
import com.njcn.system.api.DicDataFeignClient; import com.njcn.system.api.DicDataFeignClient;
import com.njcn.system.api.DictTreeFeignClient;
import com.njcn.system.api.EpdFeignClient; import com.njcn.system.api.EpdFeignClient;
import com.njcn.system.enums.DicDataEnum; import com.njcn.system.enums.DicDataEnum;
import com.njcn.system.enums.DicTreeEnum;
import com.njcn.system.pojo.dto.EpdDTO; import com.njcn.system.pojo.dto.EpdDTO;
import com.njcn.system.pojo.po.DictData; import com.njcn.system.pojo.po.DictData;
import com.njcn.zlevent.pojo.constant.ZlConstant; import com.njcn.zlevent.pojo.constant.ZlConstant;
@@ -69,6 +71,7 @@ public class EventServiceImpl implements IEventService {
private final ICsEventLogsService csEventLogsService; private final ICsEventLogsService csEventLogsService;
private final SendEventUtils sendEventUtils; private final SendEventUtils sendEventUtils;
private final WlRecordFeignClient wlRecordFeignClient; private final WlRecordFeignClient wlRecordFeignClient;
private final DictTreeFeignClient dictTreeFeignClient;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@@ -88,6 +91,8 @@ public class EventServiceImpl implements IEventService {
} }
//获取装置id //获取装置id
CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(appEventMessage.getId()).getData(); CsEquipmentDeliveryPO po = equipmentFeignClient.findDevByNDid(appEventMessage.getId()).getData();
//设备型号
String code = dictTreeFeignClient.queryById(po.getDevModel()).getData().getCode();
try { try {
//处理事件数据 //处理事件数据
List<AppEventMessage.DataArray> dataArray = appEventMessage.getMsg().getDataArray(); List<AppEventMessage.DataArray> dataArray = appEventMessage.getMsg().getDataArray();
@@ -123,6 +128,7 @@ public class EventServiceImpl implements IEventService {
Map<String, String> tags = new HashMap<>(); Map<String, String> tags = new HashMap<>();
tags.put(InfluxDBTableConstant.UUID,id); tags.put(InfluxDBTableConstant.UUID,id);
Map<String,Object> fields = new HashMap<>(); Map<String,Object> fields = new HashMap<>();
//只有治理型号的设备有监测位置
if (Objects.equals(ZlConstant.EVENT_POSITION,param.getName())){ if (Objects.equals(ZlConstant.EVENT_POSITION,param.getName())){
if (Objects.equals(param.getData(),ZlConstant.GRID)){ if (Objects.equals(param.getData(),ZlConstant.GRID)){
fields.put(param.getName(),"电网侧"); fields.put(param.getName(),"电网侧");
@@ -139,8 +145,8 @@ public class EventServiceImpl implements IEventService {
csEvent.setPersistTime(Double.parseDouble(param.getData().toString())); csEvent.setPersistTime(Double.parseDouble(param.getData().toString()));
} }
lineId = appEventMessage.getId() + appEventMessage.getMsg().getClDid(); lineId = appEventMessage.getId() + appEventMessage.getMsg().getClDid();
fields.put(param.getName(),appEventMessage.getMsg().getClDid()==1?"电网侧":"负载侧"); fields.put(param.getName(),null);
csEvent.setLocation(appEventMessage.getMsg().getClDid()==1?ZlConstant.GRID:ZlConstant.LOAD); csEvent.setLocation(null);
csEvent.setClDid(appEventMessage.getMsg().getClDid()); csEvent.setClDid(appEventMessage.getMsg().getClDid());
fields.put(param.getName(),param.getData()); fields.put(param.getName(),param.getData());
} }

View File

@@ -148,7 +148,7 @@ public class FileServiceImpl implements IFileService {
Object fileInfo = redisUtil.getObjectByKey(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileName)); Object fileInfo = redisUtil.getObjectByKey(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileName));
FileInfoDto fileInfoDto = JSON.parseObject(JSON.toJSONString(fileInfo), FileInfoDto.class); FileInfoDto fileInfoDto = JSON.parseObject(JSON.toJSONString(fileInfo), FileInfoDto.class);
if (Objects.isNull(fileInfoDto)) { if (Objects.isNull(fileInfoDto)) {
String fileCheck = redisUtil.getObjectByKey("fileCheck"+fileName).toString(); String fileCheck = redisUtil.getObjectByKey("fileCheck"+appFileMessage.getId()+fileName).toString();
if (appFileMessage.getMsg().getFrameTotal() == 1) { if (appFileMessage.getMsg().getFrameTotal() == 1) {
//解析文件入库 //解析文件入库
filePath = fileStream(1,null,appFileMessage.getMsg().getData(),fileName,appFileMessage.getId(),fileCheck,"download"); filePath = fileStream(1,null,appFileMessage.getMsg().getData(),fileName,appFileMessage.getId(),fileCheck,"download");
@@ -158,8 +158,15 @@ public class FileServiceImpl implements IFileService {
csEventLogs.setAllStep(1); csEventLogs.setAllStep(1);
csEventLogs.setIsAll(1); csEventLogs.setIsAll(1);
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName())); redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName()));
redisUtil.delete(AppRedisKey.FILE_PART.concat(appFileMessage.getMsg().getName())); // redisUtil.delete(AppRedisKey.FILE_PART.concat(appFileMessage.getMsg().getName()));
redisUtil.delete(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileName)); redisUtil.delete(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileName));
//存储文件信息
fileStreamDto.setTotal(appFileMessage.getMsg().getFrameTotal());
fileStreamDto.setNDid(appFileMessage.getId());
fileStreamDto.setFrameLen(appFileMessage.getMsg().getFrameLen());
list.add(appFileMessage.getMsg().getFrameCurr());
fileStreamDto.setList(list);
redisUtil.saveByKey(AppRedisKey.FILE_PART.concat(appFileMessage.getMsg().getName()), fileStreamDto);
} else { } else {
//收到数据就刷新缓存值 //收到数据就刷新缓存值
redisUtil.saveByKeyWithExpire(AppRedisKey.FILE_DOWN_TIME.concat(appFileMessage.getMsg().getName()), null, 60L); redisUtil.saveByKeyWithExpire(AppRedisKey.FILE_DOWN_TIME.concat(appFileMessage.getMsg().getName()), null, 60L);
@@ -201,7 +208,7 @@ public class FileServiceImpl implements IFileService {
file.delete(); file.delete();
} }
redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName())); redisUtil.delete(AppRedisKey.FILE_PART_TIME.concat(appFileMessage.getMsg().getName()));
redisUtil.delete(AppRedisKey.FILE_PART.concat(appFileMessage.getMsg().getName())); // redisUtil.delete(AppRedisKey.FILE_PART.concat(appFileMessage.getMsg().getName()));
redisUtil.delete(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileName)); redisUtil.delete(AppRedisKey.RMQ_FILE_CONSUME_KEY.concat(fileName));
redisUtil.delete(AppRedisKey.FILE_DOWN_TIME.concat(appFileMessage.getMsg().getName())); redisUtil.delete(AppRedisKey.FILE_DOWN_TIME.concat(appFileMessage.getMsg().getName()));
} else { } else {
@@ -224,8 +231,11 @@ public class FileServiceImpl implements IFileService {
} }
} }
} }
//推送mqtt
String json = "{fileName:"+appFileMessage.getMsg().getName()+",allStep:"+appFileMessage.getMsg().getFrameTotal()+",nowStep:"+ appFileMessage.getMsg().getFrameCurr() +"}";
publisher.send("/Web/Progress/" + appFileMessage.getId(), new Gson().toJson(json), 1, false);
if (!Objects.isNull(filePath)){ if (!Objects.isNull(filePath)){
redisUtil.saveByKey("downloadFilePath:"+appFileMessage.getMsg().getName(),filePath); redisUtil.saveByKey("downloadFilePath:" + appFileMessage.getId() + appFileMessage.getMsg().getName(),filePath);
} }
} }
//录波文件下载 //录波文件下载