1.录波文件下载处理;

2.装置异常告警事件处理
This commit is contained in:
xy
2024-09-13 20:41:18 +08:00
parent bb298501eb
commit 335997cdf6
28 changed files with 567 additions and 184 deletions

View File

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

View File

@@ -70,6 +70,10 @@ public class AutoDataDto {
@ApiModelProperty("数据是否参与合格率统计")
private Integer dataTag;
@SerializedName("Code")
@ApiModelProperty("事件码")
private Integer code;
@SerializedName("Data")
private String data;

View File

@@ -76,6 +76,10 @@ public class EventDto {
@ApiModelProperty("告警故障编码一般显示为Hex")
private String code;
@SerializedName("DataTag")
@ApiModelProperty("数据标识1-标识数据异常")
private Integer dataTag;
@SerializedName("Parm")
private List<Param> param;
}

View File

@@ -638,6 +638,27 @@ public class MqttMessageHandler {
}
}
/**
* 装置异常事件记录
* @param topic
* @param message
* @param version
* @param nDid
* @param payload
*/
@MqttSubscribe(value = "/Dev/Error/{edgeId}",qos = 1)
@Transactional(rollbackFor = Exception.class)
public void devErrorInfo(String topic, MqttMessage message, @NamedValue("version") String version, @NamedValue("edgeId") String nDid, @Payload String payload) {
//解析数据
Gson gson = new Gson();
log.info(nDid + "事件报文为:" + new String(message.getPayload(), StandardCharsets.UTF_8));
EventDto eventDto = gson.fromJson(new String(message.getPayload(), StandardCharsets.UTF_8), EventDto.class);
JSONObject jsonObject0 = JSONObject.parseObject(JSON.toJSONString(eventDto));
AppEventMessage appEventMessage = JSONObject.toJavaObject(jsonObject0, AppEventMessage.class);
appEventMessage.setId(nDid);
appEventMessageTemplate.sendMember(appEventMessage);
}
private void saveDirectoryInfo(List<FileDto.DirInfo> dirInfo, String key) {
if (!CollectionUtil.isEmpty(dirInfo)) {
redisUtil.saveByKeyWithExpire(key, dirInfo, 10L);

View File

@@ -167,17 +167,17 @@ public class RedisKeyExpirationListener extends KeyExpirationEventMessageListene
return;
} else {
logDto.setResult(0);
//重连三次仍未成功,则推送告警消息
//一个小时未连接上,则推送告警消息
MAX_WARNING_TIMES++;
if (MAX_WARNING_TIMES == 3) {
if (MAX_WARNING_TIMES == 30) {
NoticeUserDto dto2 = sendConnectFail(nDid);
sendEventToUser(dto2);
}
}
} else {
//重连三次仍未成功,则推送告警消息
//一个小时未连接上,则推送告警消息
MAX_WARNING_TIMES++;
if (MAX_WARNING_TIMES == 3) {
if (MAX_WARNING_TIMES == 30) {
NoticeUserDto dto2 = sendConnectFail(nDid);
sendEventToUser(dto2);
}

View File

@@ -84,7 +84,7 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
@Override
public boolean downloadFile(String nDid, String name, Integer size, String fileCheck) {
boolean result = true;
redisUtil.saveByKeyWithExpire("fileDowning","fileDowning",300L);
redisUtil.saveByKeyWithExpire("fileDowning:"+nDid,"fileDowning",300L);
redisUtil.saveByKeyWithExpire("fileCheck"+name,fileCheck,300L);
int length = size/51200 + 1;
try {
@@ -110,7 +110,7 @@ public class AskDeviceDataServiceImpl implements AskDeviceDataService {
redisUtil.saveByKey(AppRedisKey.DEVICE_MID + nDid,mid);
}
} catch (Exception e) {
redisUtil.delete("fileDowning");
redisUtil.delete("fileDowning:"+nDid);
redisUtil.delete("fileCheck"+name);
throw new BusinessException(AlgorithmResponseEnum.FILE_DOWNLOAD_ERROR);
}

View File

@@ -170,7 +170,7 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
if (Objects.nonNull(object)) {
throw new BusinessException(AlgorithmResponseEnum.FILE_UPLOADING);
}
Object object2 = redisUtil.getObjectByKey("fileDowning");
Object object2 = redisUtil.getObjectByKey("fileDowning:" + id);
if (Objects.nonNull(object2)) {
throw new BusinessException(AlgorithmResponseEnum.FILE_BUSY);
}
@@ -190,6 +190,9 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
//需要循环的次数
int times = bytes.length / cap + 1;
for (int i = 1; i <= times; i++) {
//发送数据给前端
String json = "{allStep:\""+times+"\",nowStep:"+i+"}";
publisher.send("/Web/Progress", new Gson().toJson(json), 1, false);
DeviceLogDTO logDto = new DeviceLogDTO();
byte[] lsBytes;
if (length > 50*1024) {
@@ -219,6 +222,8 @@ public class CsDevModelServiceImpl implements ICsDevModelService {
csLogsFeignClient.addUserLog(logDto);
}
} else {
String json = "{allStep:\""+1+"\",nowStep:"+1+"}";
publisher.send("/Web/Progress", new Gson().toJson(json), 1, false);
ReqAndResDto.Req req = getPojo(1,path,file,length,bytes,0,hexString);
publisher.send("/Pfm/DevFileCmd/" + version + "/" + id, new Gson().toJson(req), 1, false);
DeviceLogDTO logDto = new DeviceLogDTO();