平台侧发送和准备工作实现完成
This commit is contained in:
@@ -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 升级任务。
|
||||
|
||||
Reference in New Issue
Block a user