修复当前卡不对的问题

This commit is contained in:
2026-05-06 10:19:21 +08:00
parent 21b73a750d
commit 001f8caf35
3 changed files with 34 additions and 8 deletions

View File

@@ -136,12 +136,14 @@ func (h *ClientDeviceHandler) GetDeviceCards(c *fiber.Ctx) error {
return response.Success(c, &dto.DeviceCardListResponse{Cards: []dto.DeviceCardItem{}})
}
// 收集卡 ID 并记录插槽位置映射
// 收集卡 ID并记录插槽位置与当前在用标识
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
}
// 批量查询卡详情
@@ -153,7 +155,7 @@ func (h *ClientDeviceHandler) GetDeviceCards(c *fiber.Ctx) error {
return errors.New(errors.CodeInternalError)
}
// 组装响应,slot_position == 1 视为当前激活卡
// 组装响应,当前激活卡以绑定表 is_current 为准
items := make([]dto.DeviceCardItem, 0, len(cards))
for _, card := range cards {
slot := slotMap[card.ID]
@@ -166,7 +168,8 @@ func (h *ClientDeviceHandler) GetDeviceCards(c *fiber.Ctx) error {
NetworkStatus: networkStatusText(card.NetworkStatus),
RealNameStatus: card.RealNameStatus,
SlotPosition: slot,
IsActive: slot == 1,
IsActive: isCurrentMap[card.ID],
RealnamePolicy: card.RealnamePolicy,
})
}