From d2494798aa5077bc6ebbb9484acee5196626c724 Mon Sep 17 00:00:00 2001 From: huang Date: Thu, 19 Mar 2026 18:37:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E5=81=9C=E5=A4=8D?= =?UTF-8?q?=E6=9C=BA=E6=8E=A5=E5=8F=A3=E9=94=99=E8=AF=AF=E7=A0=81=EF=BC=8C?= =?UTF-8?q?=E7=BD=91=E5=85=B3=E5=A4=B1=E8=B4=A5=E4=B8=8D=E5=86=8D=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E6=A8=A1=E7=B3=8A=E7=9A=84=E5=86=85=E9=83=A8=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=99=A8=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 单卡停复机:网关错误从 CodeInternalError(2001) 改为 CodeGatewayError(1110),前端可看到具体失败原因 - 单卡停复机:DB 更新裸返 GORM error 改为 CodeDatabaseError(2002) 包装 - 设备复机:全部卡失败时错误码从 CodeInternalError 改为 CodeGatewayError --- internal/service/device/service.go | 2 +- .../service/iot_card/stop_resume_service.go | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) 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 }