修复当前卡不对的问题
This commit is contained in:
@@ -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,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user