升级任务

This commit is contained in:
waner
2026-04-08 11:10:26 +08:00
parent 57639e78a1
commit 2f81beb0d8
8 changed files with 115 additions and 10 deletions
@@ -11,6 +11,7 @@ import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
@RestControllerAdvice
public class GlobalExceptionHandler {
@@ -45,6 +46,12 @@ public class GlobalExceptionHandler {
return ApiResponse.fail(ErrorCode.VALIDATE_FAILED.getCode(), ex.getMessage()).withPath(request.getRequestURI());
}
@ExceptionHandler(MaxUploadSizeExceededException.class)
public ApiResponse<Void> handleMaxUploadSizeExceeded(MaxUploadSizeExceededException ex, HttpServletRequest request) {
return ApiResponse.fail(ErrorCode.VALIDATE_FAILED.getCode(), "upload file size exceeds limit")
.withPath(request.getRequestURI());
}
@ExceptionHandler(PcieCryptoException.class)
public ApiResponse<Void> handleCryptoCardException(PcieCryptoException ex, HttpServletRequest request) {
return ApiResponse.fail(ErrorCode.CRYPTO_CARD_ERROR.getCode(), ex.getMessage())
@@ -15,6 +15,7 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@@ -26,17 +27,13 @@ import org.springframework.web.multipart.MultipartFile;
@RestController
@RequestMapping("/api/v1")
@RequiredArgsConstructor
@Tag(name = "离线升级管理", description = "离线升级包上传、预检、任务创建、执行和升级记录查询接口")
public class UpgradeController {
private final UpgradeService upgradeService;
private final FileService fileService;
public UpgradeController(UpgradeService upgradeService, FileService fileService) {
this.upgradeService = upgradeService;
this.fileService = fileService;
}
@PostMapping("/upgrade-packages")
@Operation(summary = "上传离线升级包", description = "上传离线升级包,返回 fileId 供升级预检和任务创建使用。")
public ApiResponse<FileUploadResponse> uploadPackage(
@@ -98,8 +98,9 @@ public class UpgradeTaskRunner {
}
DeviceSoftwareVersionEntity versionEntity = new DeviceSoftwareVersionEntity();
versionEntity.setComponentCode(task.getTaskType());
versionEntity.setComponentName(componentName(task.getTaskType()));
String componentCode = componentCode(task.getTaskType());
versionEntity.setComponentCode(componentCode);
versionEntity.setComponentName(componentName(componentCode));
versionEntity.setCurrentVersion(task.getTargetVersion());
versionEntity.setSourceType("UPGRADE");
versionEntity.setDetectedAt(LocalDateTime.now());
@@ -211,12 +212,18 @@ public class UpgradeTaskRunner {
private String componentName(String componentCode) {
return switch (trim(componentCode)) {
case "TMS" -> "设备管理软件";
case "RECEIVER" -> "标准收发器";
case "FIRMWARE" -> "固件";
case "APP" -> "标准收发器";
default -> componentCode;
};
}
private String componentCode(String taskType) {
return switch (trim(taskType)) {
case "RECEIVER" -> "APP";
default -> trim(taskType);
};
}
private String trim(String value) {
return value == null ? "" : value.trim();
}
+6 -1
View File
@@ -2,6 +2,11 @@ spring:
application:
# Spring 应用名;用于日志、注册中心标识等。
name: tms-framework
servlet:
multipart:
# Spring/Tomcat multipart 解析上限;必须不小于业务上传上限,否则请求会在进入 Controller 前被拒绝。
max-file-size: ${TMS_FILE_STORAGE_MAX_FILE_SIZE_BYTES:104857600}
max-request-size: ${TMS_FILE_STORAGE_MAX_FILE_SIZE_BYTES:104857600}
profiles:
# 默认激活环境;可通过 --spring.profiles.active=prod 覆盖。
active: dev
@@ -173,7 +178,7 @@ tms:
# 升级任务统一日志目录。
log-dir: ${TMS_UPGRADE_LOG_DIR:/home/tms/tmp/tms-upgrade-logs}
# 升级包验签使用的公钥 PEM 文件路径;为空时升级预检会拒绝通过。
signature-public-key-pem-path: ${TMS_UPGRADE_SIGNATURE_PUBLIC_KEY_PEM_PATH:}
signature-public-key-pem-path: ${TMS_UPGRADE_SIGNATURE_PUBLIC_KEY_PEM_PATH:/home/tms/cert/public_key.pem}
mk:
init-identify:
# SDFE_InitIdentify 旧 PIN(Base64 编码);主密钥初始化接口会读取该值。