From 3b54850f1bd40bf47753648ae2423c80d7d0a4f7 Mon Sep 17 00:00:00 2001 From: huang Date: Sat, 28 Mar 2026 13:19:09 +0800 Subject: [PATCH] =?UTF-8?q?feat(03.1-01):=20=E4=BF=AE=E5=A4=8D=E9=9D=99?= =?UTF-8?q?=E6=80=81=20DTO=20=E6=98=A0=E5=B0=84=E7=BC=BA=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - toDeviceResponse() 补全 5 个 DB 缓存字段(OnlineStatus/LastOnlineTime/SoftwareVersion/SwitchMode/LastGatewaySyncAt) - ListBindings() 补全 IsCurrent 字段映射 - buildDeviceResolveResponse() 补全 isCurrentMap + BoundCardInfo.IsCurrent + 5 个 DB 缓存字段 - GetRealtimeStatus() device case 补全 isCurrentMap + BoundCardInfo.IsCurrent --- internal/service/asset/service.go | 11 +++++++++++ internal/service/device/binding.go | 1 + internal/service/device/service.go | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/internal/service/asset/service.go b/internal/service/asset/service.go index 1239e66..ff2e58d 100644 --- a/internal/service/asset/service.go +++ b/internal/service/asset/service.go @@ -114,6 +114,11 @@ func (s *Service) buildDeviceResolveResponse(ctx context.Context, device *model. DeviceType: device.DeviceType, MaxSimSlots: device.MaxSimSlots, Manufacturer: device.Manufacturer, + OnlineStatus: device.OnlineStatus, + LastOnlineTime: device.LastOnlineTime, + SoftwareVersion: device.SoftwareVersion, + SwitchMode: device.SwitchMode, + LastGatewaySyncAt: device.LastGatewaySyncAt, } // 查绑定卡 @@ -122,9 +127,11 @@ func (s *Service) buildDeviceResolveResponse(ctx context.Context, device *model. resp.BoundCardCount = len(bindings) cardIDs := make([]uint, 0, len(bindings)) slotMap := make(map[uint]int, len(bindings)) + isCurrentMap := make(map[uint]bool, len(bindings)) for _, b := range bindings { cardIDs = append(cardIDs, b.IotCardID) slotMap[b.IotCardID] = b.SlotPosition + isCurrentMap[b.IotCardID] = b.IsCurrent } cards, _ := s.iotCardStore.GetByIDs(ctx, cardIDs) for _, c := range cards { @@ -135,6 +142,7 @@ func (s *Service) buildDeviceResolveResponse(ctx context.Context, device *model. NetworkStatus: c.NetworkStatus, RealNameStatus: c.RealNameStatus, SlotPosition: slotMap[c.ID], + IsCurrent: isCurrentMap[c.ID], }) } } @@ -271,9 +279,11 @@ func (s *Service) GetRealtimeStatus(ctx context.Context, assetType string, id ui if err == nil && len(bindings) > 0 { cardIDs := make([]uint, 0, len(bindings)) slotMap := make(map[uint]int, len(bindings)) + isCurrentMap := make(map[uint]bool, len(bindings)) for _, b := range bindings { cardIDs = append(cardIDs, b.IotCardID) slotMap[b.IotCardID] = b.SlotPosition + isCurrentMap[b.IotCardID] = b.IsCurrent } cards, _ := s.iotCardStore.GetByIDs(ctx, cardIDs) for _, c := range cards { @@ -284,6 +294,7 @@ func (s *Service) GetRealtimeStatus(ctx context.Context, assetType string, id ui NetworkStatus: c.NetworkStatus, RealNameStatus: c.RealNameStatus, SlotPosition: slotMap[c.ID], + IsCurrent: isCurrentMap[c.ID], }) } } diff --git a/internal/service/device/binding.go b/internal/service/device/binding.go index a632cc5..619f2db 100644 --- a/internal/service/device/binding.go +++ b/internal/service/device/binding.go @@ -57,6 +57,7 @@ func (s *Service) ListBindings(ctx context.Context, deviceID uint) (*dto.ListDev CarrierName: card.CarrierName, // 直接使用 IotCard 的冗余字段 Status: card.Status, BindTime: binding.BindTime, + IsCurrent: binding.IsCurrent, } responses = append(responses, resp) } diff --git a/internal/service/device/service.go b/internal/service/device/service.go index 5ea58c1..321eb96 100644 --- a/internal/service/device/service.go +++ b/internal/service/device/service.go @@ -556,6 +556,11 @@ func (s *Service) toDeviceResponse(device *model.Device, shopMap map[uint]string ActivatedAt: device.ActivatedAt, CreatedAt: device.CreatedAt, UpdatedAt: device.UpdatedAt, + OnlineStatus: device.OnlineStatus, + LastOnlineTime: device.LastOnlineTime, + SoftwareVersion: device.SoftwareVersion, + SwitchMode: device.SwitchMode, + LastGatewaySyncAt: device.LastGatewaySyncAt, } if device.ShopID != nil && *device.ShopID > 0 {