平台侧发送和准备工作实现完成

This commit is contained in:
2025-12-07 18:05:21 +08:00
parent 35c19d0495
commit c8b32d542d
8 changed files with 52 additions and 49 deletions

View File

@@ -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"` // 状态消息
}

View File

@@ -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 升级任务。

View File

@@ -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,
)

View File

@@ -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。
// 注意:这只是一个尽力而为的操作。如果设备已开始下载或处理,可能无法立即中止。

View File

@@ -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")