feat: 补全网关停复机调用的关键日志(调用前/成功后均输出 INFO)
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled
This commit is contained in:
@@ -835,6 +835,9 @@ func (s *Service) StopDevice(ctx context.Context, deviceID uint) (*dto.DeviceSus
|
||||
}
|
||||
|
||||
if s.gatewayClient != nil {
|
||||
log.Info("调用网关停机(设备)",
|
||||
zap.Uint("device_id", deviceID),
|
||||
zap.String("iccid", card.ICCID))
|
||||
if gwErr := s.gatewayClient.StopCard(ctx, &gateway.CardOperationReq{CardNo: card.ICCID}); gwErr != nil {
|
||||
log.Error("设备停机-调网关停机失败",
|
||||
zap.Uint("device_id", deviceID),
|
||||
@@ -846,6 +849,9 @@ func (s *Service) StopDevice(ctx context.Context, deviceID uint) (*dto.DeviceSus
|
||||
})
|
||||
continue
|
||||
}
|
||||
log.Info("网关停机成功(设备)",
|
||||
zap.Uint("device_id", deviceID),
|
||||
zap.String("iccid", card.ICCID))
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
@@ -936,6 +942,9 @@ func (s *Service) StartDevice(ctx context.Context, deviceID uint) error {
|
||||
}
|
||||
|
||||
if s.gatewayClient != nil {
|
||||
log.Info("调用网关复机(设备)",
|
||||
zap.Uint("device_id", deviceID),
|
||||
zap.String("iccid", card.ICCID))
|
||||
if gwErr := s.gatewayClient.StartCard(ctx, &gateway.CardOperationReq{CardNo: card.ICCID}); gwErr != nil {
|
||||
log.Error("设备复机-调网关复机失败",
|
||||
zap.Uint("device_id", deviceID),
|
||||
@@ -944,6 +953,9 @@ func (s *Service) StartDevice(ctx context.Context, deviceID uint) error {
|
||||
lastErr = gwErr
|
||||
continue
|
||||
}
|
||||
log.Info("网关复机成功(设备)",
|
||||
zap.Uint("device_id", deviceID),
|
||||
zap.String("iccid", card.ICCID))
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/gateway"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// validateCardAccess 通过 ICCID 验证卡存在且当前用户有权限访问
|
||||
@@ -62,9 +63,15 @@ func (s *Service) GatewayStopCard(ctx context.Context, iccid string) error {
|
||||
if err := s.validateCardAccess(ctx, iccid); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.gatewayClient.StopCard(ctx, &gateway.CardOperationReq{
|
||||
s.logger.Info("调用网关停机(手动)", zap.String("iccid", iccid))
|
||||
if err := s.gatewayClient.StopCard(ctx, &gateway.CardOperationReq{
|
||||
CardNo: iccid,
|
||||
})
|
||||
}); err != nil {
|
||||
s.logger.Error("网关停机失败(手动)", zap.String("iccid", iccid), zap.Error(err))
|
||||
return err
|
||||
}
|
||||
s.logger.Info("网关停机成功(手动)", zap.String("iccid", iccid))
|
||||
return nil
|
||||
}
|
||||
|
||||
// GatewayStartCard 恢复卡服务(通过 Gateway API)
|
||||
@@ -72,7 +79,13 @@ func (s *Service) GatewayStartCard(ctx context.Context, iccid string) error {
|
||||
if err := s.validateCardAccess(ctx, iccid); err != nil {
|
||||
return err
|
||||
}
|
||||
return s.gatewayClient.StartCard(ctx, &gateway.CardOperationReq{
|
||||
s.logger.Info("调用网关复机(手动)", zap.String("iccid", iccid))
|
||||
if err := s.gatewayClient.StartCard(ctx, &gateway.CardOperationReq{
|
||||
CardNo: iccid,
|
||||
})
|
||||
}); err != nil {
|
||||
s.logger.Error("网关复机失败(手动)", zap.String("iccid", iccid), zap.Error(err))
|
||||
return err
|
||||
}
|
||||
s.logger.Info("网关复机成功(手动)", zap.String("iccid", iccid))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -237,6 +237,10 @@ func (s *StopResumeService) stopCardWithRetry(ctx context.Context, card *model.I
|
||||
return errors.New(errors.CodeInternalError, "Gateway 未配置,停复机操作不可用")
|
||||
}
|
||||
|
||||
s.logger.Info("调用网关停机",
|
||||
zap.Uint("card_id", card.ID),
|
||||
zap.String("iccid", card.ICCID))
|
||||
|
||||
var lastErr error
|
||||
for i := 0; i < s.maxRetries; i++ {
|
||||
if i > 0 {
|
||||
@@ -250,12 +254,16 @@ func (s *StopResumeService) stopCardWithRetry(ctx context.Context, card *model.I
|
||||
CardNo: card.ICCID,
|
||||
})
|
||||
if err == nil {
|
||||
s.logger.Info("网关停机成功",
|
||||
zap.Uint("card_id", card.ID),
|
||||
zap.String("iccid", card.ICCID))
|
||||
return nil
|
||||
}
|
||||
|
||||
lastErr = err
|
||||
s.logger.Warn("调用停机接口失败,准备重试",
|
||||
zap.Int("attempt", i+1),
|
||||
zap.String("iccid", card.ICCID),
|
||||
zap.Error(err))
|
||||
}
|
||||
|
||||
@@ -268,6 +276,10 @@ func (s *StopResumeService) resumeCardWithRetry(ctx context.Context, card *model
|
||||
return errors.New(errors.CodeInternalError, "Gateway 未配置,停复机操作不可用")
|
||||
}
|
||||
|
||||
s.logger.Info("调用网关复机",
|
||||
zap.Uint("card_id", card.ID),
|
||||
zap.String("iccid", card.ICCID))
|
||||
|
||||
var lastErr error
|
||||
for i := 0; i < s.maxRetries; i++ {
|
||||
if i > 0 {
|
||||
@@ -281,12 +293,16 @@ func (s *StopResumeService) resumeCardWithRetry(ctx context.Context, card *model
|
||||
CardNo: card.ICCID,
|
||||
})
|
||||
if err == nil {
|
||||
s.logger.Info("网关复机成功",
|
||||
zap.Uint("card_id", card.ID),
|
||||
zap.String("iccid", card.ICCID))
|
||||
return nil
|
||||
}
|
||||
|
||||
lastErr = err
|
||||
s.logger.Warn("调用复机接口失败,准备重试",
|
||||
zap.Int("attempt", i+1),
|
||||
zap.String("iccid", card.ICCID),
|
||||
zap.Error(err))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user