diff --git a/internal/service/device/service.go b/internal/service/device/service.go index 4184aeb..5ea58c1 100644 --- a/internal/service/device/service.go +++ b/internal/service/device/service.go @@ -973,7 +973,7 @@ func (s *Service) StartDevice(ctx context.Context, deviceID uint) error { // 全部失败时返回 error if successCount == 0 && lastErr != nil { - return errors.Wrap(errors.CodeInternalError, lastErr, "设备复机失败") + return errors.Wrap(errors.CodeGatewayError, lastErr, "设备复机失败,所有卡均复机失败") } return nil diff --git a/internal/service/iot_card/stop_resume_service.go b/internal/service/iot_card/stop_resume_service.go index f297180..342cdd9 100644 --- a/internal/service/iot_card/stop_resume_service.go +++ b/internal/service/iot_card/stop_resume_service.go @@ -264,15 +264,18 @@ func (s *StopResumeService) ManualStopCard(ctx context.Context, iccid string) er } if err := s.stopCardWithRetry(ctx, card); err != nil { - return errors.Wrap(errors.CodeInternalError, err, "调网关停机失败") + return errors.Wrap(errors.CodeGatewayError, err, "调用运营商停机失败,请稍后重试") } now := time.Now() - return s.db.WithContext(ctx).Model(card).Updates(map[string]any{ + if err := s.db.WithContext(ctx).Model(card).Updates(map[string]any{ "network_status": constants.NetworkStatusOffline, "stopped_at": now, "stop_reason": constants.StopReasonManual, - }).Error + }).Error; err != nil { + return errors.Wrap(errors.CodeDatabaseError, err, "更新卡状态失败") + } + return nil } // ManualStartCard 手动复机单张卡(通过ICCID) @@ -300,13 +303,16 @@ func (s *StopResumeService) ManualStartCard(ctx context.Context, iccid string) e } if err := s.resumeCardWithRetry(ctx, card); err != nil { - return errors.Wrap(errors.CodeInternalError, err, "调网关复机失败") + return errors.Wrap(errors.CodeGatewayError, err, "调用运营商复机失败,请稍后重试") } now := time.Now() - return s.db.WithContext(ctx).Model(card).Updates(map[string]any{ + if err := s.db.WithContext(ctx).Model(card).Updates(map[string]any{ "network_status": constants.NetworkStatusOnline, "resumed_at": now, "stop_reason": "", - }).Error + }).Error; err != nil { + return errors.Wrap(errors.CodeDatabaseError, err, "更新卡状态失败") + } + return nil }