平台侧发送和准备工作实现完成
This commit is contained in:
22
docs/docs.go
22
docs/docs.go
@@ -8399,10 +8399,6 @@ const docTemplate = `{
|
||||
}
|
||||
]
|
||||
},
|
||||
"executed_num": {
|
||||
"description": "已执行步骤数",
|
||||
"type": "integer"
|
||||
},
|
||||
"message": {
|
||||
"description": "状态消息",
|
||||
"type": "string"
|
||||
@@ -8410,10 +8406,6 @@ const docTemplate = `{
|
||||
"task_id": {
|
||||
"description": "OTA 升级任务ID",
|
||||
"type": "integer"
|
||||
},
|
||||
"total_num": {
|
||||
"description": "总步骤数",
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -10516,20 +10508,24 @@ const docTemplate = `{
|
||||
"进行中",
|
||||
"成功",
|
||||
"版本已是最新",
|
||||
"准备升级失败",
|
||||
"预检失败",
|
||||
"下载或校验失败",
|
||||
"固件回滚",
|
||||
"超时",
|
||||
"平台内部错误"
|
||||
"平台内部错误",
|
||||
"手动停止"
|
||||
],
|
||||
"x-enum-comments": {
|
||||
"OTATaskStatusAlreadyUpToDate": "设备报告版本已是最新,未执行升级",
|
||||
"OTATaskStatusFailedDownload": "设备报告文件下载或校验失败 (包括清单文件和固件文件)",
|
||||
"OTATaskStatusFailedPreCheck": "设备报告升级前检查失败 (如拒绝降级、准备分区失败)",
|
||||
"OTATaskStatusFailedPreparation": "平台在解压、生成清单等文件操作阶段发生错误",
|
||||
"OTATaskStatusFailedRollback": "新固件启动失败,设备自动回滚",
|
||||
"OTATaskStatusInProgress": "任务已下发,设备正在处理",
|
||||
"OTATaskStatusPending": "任务已创建,等待下发",
|
||||
"OTATaskStatusPlatformError": "平台处理过程中发生的非设备报告错误",
|
||||
"OTATaskStatusStopped": "手动停止",
|
||||
"OTATaskStatusSuccess": "设备报告升级成功,新固件已运行",
|
||||
"OTATaskStatusTimedOut": "平台在超时后仍未收到最终报告"
|
||||
},
|
||||
@@ -10538,22 +10534,26 @@ const docTemplate = `{
|
||||
"任务已下发,设备正在处理",
|
||||
"设备报告升级成功,新固件已运行",
|
||||
"设备报告版本已是最新,未执行升级",
|
||||
"平台在解压、生成清单等文件操作阶段发生错误",
|
||||
"设备报告升级前检查失败 (如拒绝降级、准备分区失败)",
|
||||
"设备报告文件下载或校验失败 (包括清单文件和固件文件)",
|
||||
"新固件启动失败,设备自动回滚",
|
||||
"平台在超时后仍未收到最终报告",
|
||||
"平台处理过程中发生的非设备报告错误"
|
||||
"平台处理过程中发生的非设备报告错误",
|
||||
"手动停止"
|
||||
],
|
||||
"x-enum-varnames": [
|
||||
"OTATaskStatusPending",
|
||||
"OTATaskStatusInProgress",
|
||||
"OTATaskStatusSuccess",
|
||||
"OTATaskStatusAlreadyUpToDate",
|
||||
"OTATaskStatusFailedPreparation",
|
||||
"OTATaskStatusFailedPreCheck",
|
||||
"OTATaskStatusFailedDownload",
|
||||
"OTATaskStatusFailedRollback",
|
||||
"OTATaskStatusTimedOut",
|
||||
"OTATaskStatusPlatformError"
|
||||
"OTATaskStatusPlatformError",
|
||||
"OTATaskStatusStopped"
|
||||
]
|
||||
},
|
||||
"models.Operator": {
|
||||
|
||||
@@ -8391,10 +8391,6 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"executed_num": {
|
||||
"description": "已执行步骤数",
|
||||
"type": "integer"
|
||||
},
|
||||
"message": {
|
||||
"description": "状态消息",
|
||||
"type": "string"
|
||||
@@ -8402,10 +8398,6 @@
|
||||
"task_id": {
|
||||
"description": "OTA 升级任务ID",
|
||||
"type": "integer"
|
||||
},
|
||||
"total_num": {
|
||||
"description": "总步骤数",
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -10508,20 +10500,24 @@
|
||||
"进行中",
|
||||
"成功",
|
||||
"版本已是最新",
|
||||
"准备升级失败",
|
||||
"预检失败",
|
||||
"下载或校验失败",
|
||||
"固件回滚",
|
||||
"超时",
|
||||
"平台内部错误"
|
||||
"平台内部错误",
|
||||
"手动停止"
|
||||
],
|
||||
"x-enum-comments": {
|
||||
"OTATaskStatusAlreadyUpToDate": "设备报告版本已是最新,未执行升级",
|
||||
"OTATaskStatusFailedDownload": "设备报告文件下载或校验失败 (包括清单文件和固件文件)",
|
||||
"OTATaskStatusFailedPreCheck": "设备报告升级前检查失败 (如拒绝降级、准备分区失败)",
|
||||
"OTATaskStatusFailedPreparation": "平台在解压、生成清单等文件操作阶段发生错误",
|
||||
"OTATaskStatusFailedRollback": "新固件启动失败,设备自动回滚",
|
||||
"OTATaskStatusInProgress": "任务已下发,设备正在处理",
|
||||
"OTATaskStatusPending": "任务已创建,等待下发",
|
||||
"OTATaskStatusPlatformError": "平台处理过程中发生的非设备报告错误",
|
||||
"OTATaskStatusStopped": "手动停止",
|
||||
"OTATaskStatusSuccess": "设备报告升级成功,新固件已运行",
|
||||
"OTATaskStatusTimedOut": "平台在超时后仍未收到最终报告"
|
||||
},
|
||||
@@ -10530,22 +10526,26 @@
|
||||
"任务已下发,设备正在处理",
|
||||
"设备报告升级成功,新固件已运行",
|
||||
"设备报告版本已是最新,未执行升级",
|
||||
"平台在解压、生成清单等文件操作阶段发生错误",
|
||||
"设备报告升级前检查失败 (如拒绝降级、准备分区失败)",
|
||||
"设备报告文件下载或校验失败 (包括清单文件和固件文件)",
|
||||
"新固件启动失败,设备自动回滚",
|
||||
"平台在超时后仍未收到最终报告",
|
||||
"平台处理过程中发生的非设备报告错误"
|
||||
"平台处理过程中发生的非设备报告错误",
|
||||
"手动停止"
|
||||
],
|
||||
"x-enum-varnames": [
|
||||
"OTATaskStatusPending",
|
||||
"OTATaskStatusInProgress",
|
||||
"OTATaskStatusSuccess",
|
||||
"OTATaskStatusAlreadyUpToDate",
|
||||
"OTATaskStatusFailedPreparation",
|
||||
"OTATaskStatusFailedPreCheck",
|
||||
"OTATaskStatusFailedDownload",
|
||||
"OTATaskStatusFailedRollback",
|
||||
"OTATaskStatusTimedOut",
|
||||
"OTATaskStatusPlatformError"
|
||||
"OTATaskStatusPlatformError",
|
||||
"OTATaskStatusStopped"
|
||||
]
|
||||
},
|
||||
"models.Operator": {
|
||||
|
||||
@@ -1000,18 +1000,12 @@ definitions:
|
||||
allOf:
|
||||
- $ref: '#/definitions/models.OTATaskStatus'
|
||||
description: 当前阶段
|
||||
executed_num:
|
||||
description: 已执行步骤数
|
||||
type: integer
|
||||
message:
|
||||
description: 状态消息
|
||||
type: string
|
||||
task_id:
|
||||
description: OTA 升级任务ID
|
||||
type: integer
|
||||
total_num:
|
||||
description: 总步骤数
|
||||
type: integer
|
||||
type: object
|
||||
dto.OtaUpgradeResponse:
|
||||
properties:
|
||||
@@ -2453,20 +2447,24 @@ definitions:
|
||||
- 进行中
|
||||
- 成功
|
||||
- 版本已是最新
|
||||
- 准备升级失败
|
||||
- 预检失败
|
||||
- 下载或校验失败
|
||||
- 固件回滚
|
||||
- 超时
|
||||
- 平台内部错误
|
||||
- 手动停止
|
||||
type: string
|
||||
x-enum-comments:
|
||||
OTATaskStatusAlreadyUpToDate: 设备报告版本已是最新,未执行升级
|
||||
OTATaskStatusFailedDownload: 设备报告文件下载或校验失败 (包括清单文件和固件文件)
|
||||
OTATaskStatusFailedPreCheck: 设备报告升级前检查失败 (如拒绝降级、准备分区失败)
|
||||
OTATaskStatusFailedPreparation: 平台在解压、生成清单等文件操作阶段发生错误
|
||||
OTATaskStatusFailedRollback: 新固件启动失败,设备自动回滚
|
||||
OTATaskStatusInProgress: 任务已下发,设备正在处理
|
||||
OTATaskStatusPending: 任务已创建,等待下发
|
||||
OTATaskStatusPlatformError: 平台处理过程中发生的非设备报告错误
|
||||
OTATaskStatusStopped: 手动停止
|
||||
OTATaskStatusSuccess: 设备报告升级成功,新固件已运行
|
||||
OTATaskStatusTimedOut: 平台在超时后仍未收到最终报告
|
||||
x-enum-descriptions:
|
||||
@@ -2474,21 +2472,25 @@ definitions:
|
||||
- 任务已下发,设备正在处理
|
||||
- 设备报告升级成功,新固件已运行
|
||||
- 设备报告版本已是最新,未执行升级
|
||||
- 平台在解压、生成清单等文件操作阶段发生错误
|
||||
- 设备报告升级前检查失败 (如拒绝降级、准备分区失败)
|
||||
- 设备报告文件下载或校验失败 (包括清单文件和固件文件)
|
||||
- 新固件启动失败,设备自动回滚
|
||||
- 平台在超时后仍未收到最终报告
|
||||
- 平台处理过程中发生的非设备报告错误
|
||||
- 手动停止
|
||||
x-enum-varnames:
|
||||
- OTATaskStatusPending
|
||||
- OTATaskStatusInProgress
|
||||
- OTATaskStatusSuccess
|
||||
- OTATaskStatusAlreadyUpToDate
|
||||
- OTATaskStatusFailedPreparation
|
||||
- OTATaskStatusFailedPreCheck
|
||||
- OTATaskStatusFailedDownload
|
||||
- OTATaskStatusFailedRollback
|
||||
- OTATaskStatusTimedOut
|
||||
- OTATaskStatusPlatformError
|
||||
- OTATaskStatusStopped
|
||||
models.Operator:
|
||||
enum:
|
||||
- <
|
||||
|
||||
@@ -120,7 +120,5 @@ type OtaUpgradeResponse struct {
|
||||
type OtaUpgradeProgressResponse struct {
|
||||
TaskID uint32 `json:"task_id"` // OTA 升级任务ID
|
||||
CurrentStage models.OTATaskStatus `json:"current_stage"` // 当前阶段
|
||||
ExecutedNum uint32 `json:"executed_num"` // 已执行步骤数
|
||||
TotalNum uint32 `json:"total_num"` // 总步骤数
|
||||
Message string `json:"message"` // 状态消息
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ type AreaControllerService interface {
|
||||
type areaControllerService struct {
|
||||
ctx context.Context
|
||||
areaControllerRepo repository.AreaControllerRepository
|
||||
otaRepo repository.OtaRepository
|
||||
thresholdAlarmService ThresholdAlarmService
|
||||
otaService device.OtaService
|
||||
}
|
||||
@@ -45,12 +46,14 @@ type areaControllerService struct {
|
||||
func NewAreaControllerService(
|
||||
ctx context.Context,
|
||||
areaControllerRepo repository.AreaControllerRepository,
|
||||
otaRepo repository.OtaRepository,
|
||||
thresholdAlarmService ThresholdAlarmService,
|
||||
otaService device.OtaService,
|
||||
) AreaControllerService {
|
||||
return &areaControllerService{
|
||||
ctx: ctx,
|
||||
areaControllerRepo: areaControllerRepo,
|
||||
otaRepo: otaRepo,
|
||||
thresholdAlarmService: thresholdAlarmService,
|
||||
otaService: otaService,
|
||||
}
|
||||
@@ -197,18 +200,27 @@ func (s *areaControllerService) StartUpgrade(ctx context.Context, areaController
|
||||
|
||||
// GetUpgradeProgress 用于查询指定 OTA 任务的进度。
|
||||
func (s *areaControllerService) GetUpgradeProgress(ctx context.Context, taskID uint32) (*dto.OtaUpgradeProgressResponse, error) {
|
||||
executed, total, currentStage, err := s.otaService.GetUpgradeProgress(ctx, taskID)
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "GetUpgradeProgress")
|
||||
|
||||
// 直接调用 otaRepo 查询任务状态
|
||||
task, err := s.otaRepo.FindByID(serviceCtx, taskID)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("获取升级进度失败: %w", err)
|
||||
return nil, fmt.Errorf("查找 OTA 任务失败: %w", err)
|
||||
}
|
||||
|
||||
return &dto.OtaUpgradeProgressResponse{
|
||||
TaskID: taskID,
|
||||
CurrentStage: currentStage,
|
||||
ExecutedNum: executed,
|
||||
TotalNum: total,
|
||||
Message: fmt.Sprintf("当前状态: %s", currentStage),
|
||||
}, nil
|
||||
// 构造响应 DTO
|
||||
response := &dto.OtaUpgradeProgressResponse{
|
||||
TaskID: task.ID,
|
||||
CurrentStage: task.Status,
|
||||
Message: string(task.Status), // 默认使用状态作为消息
|
||||
}
|
||||
|
||||
// 如果任务失败,使用更详细的错误信息
|
||||
if task.ErrorMessage != "" {
|
||||
response.Message = task.ErrorMessage
|
||||
}
|
||||
|
||||
return response, nil
|
||||
}
|
||||
|
||||
// StopUpgrade 用于请求停止一个正在进行的 OTA 升级任务。
|
||||
|
||||
@@ -354,6 +354,7 @@ func initAppServices(ctx context.Context, infra *Infrastructure, domainServices
|
||||
areaControllerService := service.NewAreaControllerService(
|
||||
logs.AddCompName(baseCtx, "AreaControllerService"),
|
||||
infra.repos.areaControllerRepo,
|
||||
infra.repos.otaRepo,
|
||||
thresholdAlarmService,
|
||||
domainServices.otaService,
|
||||
)
|
||||
|
||||
@@ -82,11 +82,6 @@ type OtaService interface {
|
||||
// 返回创建的 OTA 任务 ID 和可能发生的错误。
|
||||
StartUpgrade(ctx context.Context, areaControllerID uint32, firmwarePath string) (uint32, error)
|
||||
|
||||
// GetUpgradeProgress 用于查询指定 OTA 任务的进度。
|
||||
// taskID: 要查询的 OTA 任务 ID。
|
||||
// 返回 OTA 任务的已执行步骤数和总步骤数和当前阶段和可能发生的错误。
|
||||
GetUpgradeProgress(ctx context.Context, taskID uint32) (executed, total uint32, CurrentStage models.OTATaskStatus, err error)
|
||||
|
||||
// StopUpgrade 用于请求停止一个正在进行的 OTA 升级任务。
|
||||
// taskID: 要停止的 OTA 任务 ID。
|
||||
// 注意:这只是一个尽力而为的操作。如果设备已开始下载或处理,可能无法立即中止。
|
||||
|
||||
@@ -210,11 +210,6 @@ func (o *otaServiceImpl) StartUpgrade(ctx context.Context, areaControllerID uint
|
||||
return task.ID, nil
|
||||
}
|
||||
|
||||
func (o *otaServiceImpl) GetUpgradeProgress(ctx context.Context, taskID uint32) (executed, total uint32, CurrentStage models.OTATaskStatus, err error) {
|
||||
//TODO implement me
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (o *otaServiceImpl) StopUpgrade(ctx context.Context, taskID uint32) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, o.ctx, "StopUpgrade")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user