feat(equipment): 添加设备固件升级确认功能
- 在CsEquipmentDeliveryService中新增commitUpgradeFile方法接口
- 实现CsEquipmentDeliveryServiceImpl中的升级日志记录功能
- 集成CsUpgradeLogsService用于升级状态跟踪
- 修改MQTT消息推送路径为/Web/Progress/UpgradeFile/{nDid}
- 添加设备确认升级的API端点/equipment/delivery/commitUpgradeFile
- 实现升级完成后的日志状态更新逻辑
This commit is contained in:
@@ -32,6 +32,7 @@ import java.util.List;
|
||||
@AllArgsConstructor
|
||||
@Validated
|
||||
public class CsUpgradeLogsController extends BaseController {
|
||||
|
||||
private final CsUpgradeLogsService csUpgradeLogsService;
|
||||
|
||||
@OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
|
||||
|
||||
@@ -437,10 +437,23 @@ public class EquipmentDeliveryController extends BaseController {
|
||||
@ApiImplicitParam(name = "id", value = "版本id", required = true),
|
||||
@ApiImplicitParam(name = "nDid", value = "网络设备id", required = true)
|
||||
})
|
||||
@ApiImplicitParam(name = "id", value = "版本id", required = true)
|
||||
public HttpResult<String> uploadUpgradeFile(@RequestParam("id") String id, @RequestParam("nDid") String nDid) {
|
||||
String methodDescribe = getMethodDescribe("uploadUpgradeFile");
|
||||
csEquipmentDeliveryService.uploadUpgradeFile(id,nDid);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, "文件上传中", methodDescribe);
|
||||
}
|
||||
|
||||
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
|
||||
@PostMapping("/commitUpgradeFile")
|
||||
@ApiOperation("设备确认升级")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "mid", value = "mid", required = true),
|
||||
@ApiImplicitParam(name = "nDid", value = "网络设备id", required = true),
|
||||
@ApiImplicitParam(name = "version", value = "版本", required = true)
|
||||
})
|
||||
public HttpResult<String> commitUpgradeFile(@RequestParam("mid") Integer mid, @RequestParam("nDid") String nDid, @RequestParam("version") String version) {
|
||||
String methodDescribe = getMethodDescribe("commitUpgradeFile");
|
||||
csEquipmentDeliveryService.commitUpgradeFile(mid, nDid, version);
|
||||
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.njcn.csdevice.pojo.vo.CsEquipmentDeliveryVO;
|
||||
import com.njcn.csdevice.pojo.vo.DevVersionVO;
|
||||
import com.njcn.csdevice.pojo.vo.DeviceManagerVO;
|
||||
import com.njcn.csdevice.pojo.vo.ProjectEquipmentVO;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -201,4 +202,6 @@ public interface CsEquipmentDeliveryService extends IService<CsEquipmentDelivery
|
||||
* @param id
|
||||
*/
|
||||
void uploadUpgradeFile(String id, String nDid);
|
||||
|
||||
void commitUpgradeFile(Integer mid, String nDid, String version);
|
||||
}
|
||||
|
||||
@@ -147,6 +147,7 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
private final CsTopicFeignClient csTopicFeignClient;
|
||||
private final MqttPublisher publisher;
|
||||
private final LogMessageTemplate logMessageTemplate;
|
||||
private final CsUpgradeLogsService csUpgradeLogsService;
|
||||
|
||||
@Override
|
||||
public void refreshDeviceDataCache() {
|
||||
@@ -1434,6 +1435,15 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
throw new BusinessException(AlgorithmResponseEnum.FILE_BUSY);
|
||||
}
|
||||
try {
|
||||
//记录升级日志
|
||||
CsEquipmentDeliveryVO vo = queryEquipmentByndid(nDid);
|
||||
CsUpgradeLogs csUpgradeLogs = new CsUpgradeLogs();
|
||||
csUpgradeLogs.setDevId(vo.getId());
|
||||
csUpgradeLogs.setVersionNo(po.getVersionNo());
|
||||
csUpgradeLogs.setResult(3);
|
||||
csUpgradeLogs.setUserName(RequestUtil.getUsername());
|
||||
csUpgradeLogs.setLoginName(RequestUtil.getLoginName());
|
||||
csUpgradeLogsService.save(csUpgradeLogs);
|
||||
//根据路径获取文件
|
||||
String path = po.getFilePath();
|
||||
InputStream inputStream = fileStorageUtil.getFileStream(path);
|
||||
@@ -1455,7 +1465,7 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
for (int i = 1; i <= times; i++) {
|
||||
//发送数据给前端
|
||||
String json = "{fileName:"+po.getFilePath()+",allStep:"+times+",nowStep:"+i+"}";
|
||||
publisher.send("/Web/Progress/" + nDid, new Gson().toJson(json), 1, false);
|
||||
publisher.send("/Web/Progress/UpgradeFile/" + nDid, new Gson().toJson(json), 1, false);
|
||||
LogMessage logDto = new LogMessage();
|
||||
byte[] lsBytes;
|
||||
if (length > 50*1024) {
|
||||
@@ -1486,7 +1496,7 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
}
|
||||
} else {
|
||||
String json = "{fileName:"+path+",allStep:\""+1+"\",nowStep:"+1+"}";
|
||||
publisher.send("/Web/Progress", new Gson().toJson(json), 1, false);
|
||||
publisher.send("/Web/Progress/UpgradeFile/" + nDid, new Gson().toJson(json), 1, false);
|
||||
ReqAndResDto.Req req = getPojo(1,path,length,bytes,0);
|
||||
publisher.send("/Pfm/DevFileCmd/" + version + "/" + nDid, new Gson().toJson(req), 1, false);
|
||||
LogMessage logDto = new LogMessage();
|
||||
@@ -1517,6 +1527,25 @@ public class CsEquipmentDeliveryServiceImpl extends ServiceImpl<CsEquipmentDeliv
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void commitUpgradeFile(Integer mid, String nDid, String version) {
|
||||
//修改升级日志
|
||||
CsEquipmentDeliveryVO vo = queryEquipmentByndid(nDid);
|
||||
csUpgradeLogsService.updateLogs(vo.getId(), null, 2);
|
||||
//组装报文
|
||||
ReqAndResDto.Req reqAndResParam = new ReqAndResDto.Req();
|
||||
reqAndResParam.setMid(mid);
|
||||
reqAndResParam.setDid(0);
|
||||
reqAndResParam.setPri(AccessEnum.FIRST_CHANNEL.getCode());
|
||||
reqAndResParam.setType(Integer.parseInt(TypeEnum.TYPE_32.getCode()));
|
||||
reqAndResParam.setExpire(-1);
|
||||
UpgradeDevDto upgradeDevDto = new UpgradeDevDto();
|
||||
upgradeDevDto.setChk(1);
|
||||
reqAndResParam.setMsg(upgradeDevDto);
|
||||
redisUtil.saveByKeyWithExpire("chk:" + nDid, 1, 10L);
|
||||
publisher.send("/Pfm/DevFileCmd/" + version + "/" + nDid, new Gson().toJson(reqAndResParam), 1, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上送文件至装置
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njcn.csdevice.mapper.CsUpgradeLogsMapper;
|
||||
import com.njcn.csdevice.pojo.po.CsUpgradeLogs;
|
||||
import com.njcn.csdevice.service.CsEquipmentDeliveryService;
|
||||
import com.njcn.csdevice.service.CsUpgradeLogsService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -18,8 +17,6 @@ import org.springframework.stereotype.Service;
|
||||
@RequiredArgsConstructor
|
||||
public class CsUpgradeLogsServiceImpl extends ServiceImpl<CsUpgradeLogsMapper, CsUpgradeLogs> implements CsUpgradeLogsService {
|
||||
|
||||
private final CsEquipmentDeliveryService csEquipmentDeliveryService;
|
||||
|
||||
@Override
|
||||
public boolean updateLogs(String devId, String code, Integer result) {
|
||||
CsUpgradeLogs latestLog = this.baseMapper.selectOne(
|
||||
|
||||
Reference in New Issue
Block a user