| | |
| | | upgradeDTOS.forEach(upgradeDevice -> { |
| | | boolean exist = deviceRedisService.checkDeviceOnline(upgradeDevice.getSn()); |
| | | if (!exist) { |
| | | throw new IllegalArgumentException("Device is offline."); |
| | | throw new IllegalArgumentException("设备离线"); |
| | | } |
| | | Optional<DeviceFirmwareDTO> firmwareOpt = this.getFirmware( |
| | | workspaceId, upgradeDevice.getDeviceName(), upgradeDevice.getProductVersion()); |
| | | if (firmwareOpt.isEmpty()) { |
| | | throw new IllegalArgumentException("This firmware version does not exist or is not available."); |
| | | throw new IllegalArgumentException("此固件版本不存在或不可用"); |
| | | } |
| | | DeviceOtaCreateParam ota = dto2OtaCreateDto(firmwareOpt.get()); |
| | | ota.setSn(upgradeDevice.getSn()); |
| | |
| | | String key = RedisConst.FILE_UPLOADING_PREFIX + workspaceId; |
| | | String existKey = key + file.getOriginalFilename(); |
| | | if (RedisOpsUtils.getExpire(existKey) > 0) { |
| | | throw new RuntimeException("Please try again later."); |
| | | throw new RuntimeException("请稍后再试"); |
| | | } |
| | | RedisOpsUtils.setWithExpire(existKey, true, RedisConst.DEVICE_ALIVE_SECOND); |
| | | try (InputStream is = file.getInputStream()) { |
| | |
| | | key += md5; |
| | | boolean exist = checkFileExist(workspaceId, md5); |
| | | if (exist) { |
| | | throw new RuntimeException("The file already exists."); |
| | | throw new RuntimeException("文件已存在"); |
| | | } |
| | | RedisOpsUtils.set(key, System.currentTimeMillis()); |
| | | Optional<DeviceFirmwareDTO> firmwareOpt = verifyFirmwareFile(file); |
| | | if (firmwareOpt.isEmpty()) { |
| | | throw new RuntimeException("The file format is incorrect."); |
| | | throw new RuntimeException("文件格式不正确"); |
| | | } |
| | | |
| | | String firmwareId = UUID.randomUUID().toString(); |