卡不激活的问题

This commit is contained in:
2026-04-23 16:58:16 +08:00
parent a7f2c4480a
commit c250a47651
4 changed files with 82 additions and 22 deletions

View File

@@ -881,13 +881,11 @@ func (s *Service) StopDevice(ctx context.Context, deviceID uint) (*dto.DeviceSus
}
now := time.Now()
if dbErr := s.db.WithContext(ctx).Model(&model.IotCard{}).
Where("id = ?", card.ID).
Updates(map[string]any{
"network_status": constants.NetworkStatusOffline,
"stopped_at": now,
"stop_reason": constants.StopReasonManual,
}).Error; dbErr != nil {
if dbErr := s.iotCardStore.UpdateFields(ctx, card.ID, map[string]any{
"network_status": constants.NetworkStatusOffline,
"stopped_at": now,
"stop_reason": constants.StopReasonManual,
}); dbErr != nil {
log.Error("设备停机-更新卡状态失败",
zap.Uint("card_id", card.ID),
zap.Error(dbErr))
@@ -986,13 +984,11 @@ func (s *Service) StartDevice(ctx context.Context, deviceID uint) error {
}
now := time.Now()
if dbErr := s.db.WithContext(ctx).Model(&model.IotCard{}).
Where("id = ?", card.ID).
Updates(map[string]any{
"network_status": constants.NetworkStatusOnline,
"resumed_at": now,
"stop_reason": "",
}).Error; dbErr != nil {
if dbErr := s.iotCardStore.UpdateFields(ctx, card.ID, map[string]any{
"network_status": constants.NetworkStatusOnline,
"resumed_at": now,
"stop_reason": "",
}); dbErr != nil {
log.Error("设备复机-更新卡状态失败",
zap.Uint("card_id", card.ID),
zap.Error(dbErr))

View File

@@ -373,7 +373,7 @@ func (s *Service) updateCardNetworkStatus(ctx context.Context, enterpriseID, car
return errors.New(errors.CodeForbidden, "无权限操作此卡")
}
return s.db.WithContext(ctx).Model(&model.IotCard{}).
Where("id = ?", cardID).
Update("network_status", networkStatus).Error
return s.iotCardStore.UpdateFields(ctx, cardID, map[string]any{
"network_status": networkStatus,
})
}

View File

@@ -877,9 +877,7 @@ func (s *Service) RefreshCardDataFromGateway(ctx context.Context, iccid string)
}
}
if err := s.db.WithContext(ctx).Model(&model.IotCard{}).
Where("id = ?", card.ID).
Updates(updates).Error; err != nil {
if err := s.iotCardStore.UpdateFields(ctx, card.ID, updates); err != nil {
return errors.Wrap(errors.CodeInternalError, err, "更新卡数据失败")
}