feat(consumer): 添加设备软件信息更新和升级处理功能

- 在CommonConsumer中新增多个Feign客户端依赖注入,包括设备、软件信息、数据管理等服务
- 实现设备软件版本信息的解析、存储和更新逻辑,支持版本信息的动态维护
- 添加设备升级响应处理机制,根据升级结果更新升级日志状态
- 新增设备重启消息发送功能,支持升级成功后自动重启设备
- 修改DeviceServiceImpl中的upgrade方法返回类型为String并优化升级流程
- 更新控制器接口返回值类型以匹配新的升级处理逻辑
- 移除原有的轮询等待响应机制,改为异步处理方式提升性能
This commit is contained in:
xy
2026-07-17 13:44:58 +08:00
parent 3c369d0244
commit 759a811247
5 changed files with 135 additions and 56 deletions

View File

@@ -54,10 +54,10 @@ public class DeviceController extends BaseController {
@ApiImplicitParam(name = "devId", value = "设备ID", required = true),
@ApiImplicitParam(name = "edDataId", value = "程序版本Id", required = true)
})
public HttpResult<Boolean> upgrade(@RequestParam("devId") String devId, @RequestParam("edDataId") String edDataId) {
public HttpResult<String> upgrade(@RequestParam("devId") String devId, @RequestParam("edDataId") String edDataId) {
String methodDescribe = getMethodDescribe("upgrade");
boolean res = deviceService.upgrade(devId, edDataId);
return HttpResultUtil.assembleCommonResponseResult(res ? CommonResponseEnum.SUCCESS : CommonResponseEnum.FAIL, res, methodDescribe);
String res = deviceService.upgrade(devId, edDataId);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, res, methodDescribe);
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)

View File

@@ -56,7 +56,7 @@ public interface IDeviceService {
* @param devId
* @param edDataId
*/
boolean upgrade(String devId, String edDataId);
String upgrade(String devId, String edDataId);
/**
* 重启设备

View File

@@ -1,7 +1,6 @@
package com.njcn.zlevent.service.impl;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.github.tocrhz.mqtt.publisher.MqttPublisher;
import com.njcn.access.enums.TypeEnum;
@@ -12,7 +11,6 @@ import com.njcn.csdevice.api.CsUpgradeLogsFeignClient;
import com.njcn.csdevice.api.EquipmentFeignClient;
import com.njcn.csdevice.pojo.dto.CsEquipmentDeliveryDTO;
import com.njcn.csdevice.pojo.po.CsEdDataPO;
import com.njcn.csdevice.pojo.po.CsSoftInfoPO;
import com.njcn.csdevice.pojo.po.CsUpgradeLogs;
import com.njcn.middle.rocket.domain.BaseMessage;
import com.njcn.oss.utils.FileStorageUtil;
@@ -176,10 +174,7 @@ public class DeviceServiceImpl implements IDeviceService {
}
@Override
public boolean upgrade(String devId, String edDataId) {
// 先获取旧的版本信息
//DevVersionResponeDTO.VersionInfo oldVersionInfo = this.getDeviceVersion(devId);
public String upgrade(String devId, String edDataId) {
List<CsEquipmentDeliveryDTO> listHttpResult = equipmentFeignClient.queryDeviceById(Collections.singletonList(devId)).getData();
CsEquipmentDeliveryDTO csEquipmentDeliveryDTO = listHttpResult.get(0);
@@ -190,7 +185,6 @@ public class DeviceServiceImpl implements IDeviceService {
CsUpgradeLogs csUpgradeLogs = new CsUpgradeLogs();
csUpgradeLogs.setDevId(devId);
csUpgradeLogs.setVersionNo(csEdDataPO.getVersionNo());
csUpgradeLogs.setResult(0);
UpgradeRequestDTO requestDTO = new UpgradeRequestDTO();
requestDTO.setDevId(devId);
@@ -204,54 +198,16 @@ public class DeviceServiceImpl implements IDeviceService {
msg.setName(filePath);
detail1.setMsg(msg);
requestDTO.setDetail(detail1);
BaseMessage message = new BaseMessage();
message.setMessageBody(JSON.toJSONString(requestDTO));
// 使用 Redis 存储 guid 用于后续查询
redisUtil.saveByKeyWithExpire(AppRedisKey.COMMON_REQUEST + requestDTO.getGuid(), "pending", 120L);
// 发送
commonProducer.send(message, requestDTO.getFrontId());
// 轮询 Redis 等待响应
UpgradeResponeDTO responeDTO = JSON.parseObject(sendMessageUtil.waitForResponse(requestDTO.getGuid(), 10), UpgradeResponeDTO.class);
UpgradeResponeDTO.Detail detail2 = responeDTO.getDetail();
if (detail2.getCode() == 200) {
// 修改数据库记录
String softinfoId = csEquipmentDeliveryDTO.getSoftinfoId();
if (StrUtil.isNotBlank(softinfoId)) {
csSoftInfoFeignClient.removeSoftInfo(softinfoId);
}
CsSoftInfoPO softInfoPO = new CsSoftInfoPO();
softInfoPO.setId(IdUtil.fastSimpleUUID());
softInfoPO.setAppCheck(csEdDataPO.getCrc());
softInfoPO.setAppDate(csEdDataPO.getVersionDate());
softInfoPO.setAppVersion(csEdDataPO.getVersionNo());
softInfoPO.setOpAttr("r");
softInfoPO.setOsName("VxWorks");
softInfoPO.setOsVersion("VxWorks");
softInfoPO.setSoftUpdate("yes");
csSoftInfoFeignClient.saveSoftInfo(softInfoPO);
equipmentFeignClient.updateSoftInfo(csEquipmentDeliveryDTO.getNdid(), softInfoPO.getId());
// 重新获取升级后的版本信息
DevVersionResponeDTO.VersionInfo newVersionInfo = this.getDeviceVersion(devId);
if (newVersionInfo.getAppVersion().equals(csEdDataPO.getVersionNo()) && newVersionInfo.getCloudProtocolVer().equals(csEdDataPO.getVersionAgreement())) {
// 修改数据库记录
equipmentFeignClient.updateSoftInfo(csEquipmentDeliveryDTO.getNdid(), softInfoPO.getId());
csUpgradeLogs.setResult(1);
csUpgradeLogsFeignClient.add(csUpgradeLogs);
return true;
}
csUpgradeLogsFeignClient.add(csUpgradeLogs);
return false;
}
// 记录升级日志
csUpgradeLogs.setResult(3);
csUpgradeLogsFeignClient.add(csUpgradeLogs);
return false;
return "指令下发成功";
}
@Override