设备导入卡槽不对的问题
This commit is contained in:
@@ -196,7 +196,9 @@ func (h *DeviceImportHandler) processBatch(ctx context.Context, task *model.Devi
|
||||
|
||||
for _, row := range batch {
|
||||
deviceNos = append(deviceNos, row.VirtualNo)
|
||||
allICCIDs = append(allICCIDs, row.ICCIDs...)
|
||||
for _, slotICCID := range row.SlotICCIDs {
|
||||
allICCIDs = append(allICCIDs, slotICCID.ICCID)
|
||||
}
|
||||
}
|
||||
|
||||
existingDevices, err := h.deviceStore.ExistsByDeviceNoBatch(ctx, deviceNos)
|
||||
@@ -243,27 +245,49 @@ func (h *DeviceImportHandler) processBatch(ctx context.Context, task *model.Devi
|
||||
continue
|
||||
}
|
||||
|
||||
var validCardIDs []uint
|
||||
var cardIssues []string
|
||||
|
||||
for _, iccid := range row.ICCIDs {
|
||||
card, exists := existingCards[iccid]
|
||||
if !exists {
|
||||
cardIssues = append(cardIssues, iccid+"不存在")
|
||||
rowFailed := false
|
||||
for _, slotICCID := range row.SlotICCIDs {
|
||||
if slotICCID.SlotPosition <= row.MaxSimSlots {
|
||||
continue
|
||||
}
|
||||
if boundCards[iccid] {
|
||||
cardIssues = append(cardIssues, iccid+"已绑定其他设备")
|
||||
|
||||
result.failedItems = append(result.failedItems, model.ImportResultItem{
|
||||
Line: row.Line,
|
||||
ICCID: row.VirtualNo,
|
||||
Reason: "卡槽填写超出最大SIM槽数",
|
||||
})
|
||||
result.failCount++
|
||||
rowFailed = true
|
||||
break
|
||||
}
|
||||
if rowFailed {
|
||||
continue
|
||||
}
|
||||
|
||||
var validCards []utils.DeviceSlotICCID
|
||||
var cardIssues []string
|
||||
|
||||
for _, slotICCID := range row.SlotICCIDs {
|
||||
card, exists := existingCards[slotICCID.ICCID]
|
||||
if !exists {
|
||||
cardIssues = append(cardIssues, slotICCID.ICCID+"不存在")
|
||||
continue
|
||||
}
|
||||
if boundCards[slotICCID.ICCID] {
|
||||
cardIssues = append(cardIssues, slotICCID.ICCID+"已绑定其他设备")
|
||||
continue
|
||||
}
|
||||
if card.ShopID != nil {
|
||||
cardIssues = append(cardIssues, iccid+"已分配给店铺,不能绑定到平台库存设备")
|
||||
cardIssues = append(cardIssues, slotICCID.ICCID+"已分配给店铺,不能绑定到平台库存设备")
|
||||
continue
|
||||
}
|
||||
validCardIDs = append(validCardIDs, card.ID)
|
||||
validCards = append(validCards, utils.DeviceSlotICCID{
|
||||
SlotPosition: slotICCID.SlotPosition,
|
||||
ICCID: slotICCID.ICCID,
|
||||
})
|
||||
}
|
||||
|
||||
if len(row.ICCIDs) > 0 && len(cardIssues) > 0 {
|
||||
if len(row.SlotICCIDs) > 0 && len(cardIssues) > 0 {
|
||||
result.failedItems = append(result.failedItems, model.ImportResultItem{
|
||||
Line: row.Line,
|
||||
ICCID: row.VirtualNo,
|
||||
@@ -303,11 +327,15 @@ func (h *DeviceImportHandler) processBatch(ctx context.Context, task *model.Devi
|
||||
}
|
||||
|
||||
now := time.Now()
|
||||
for i, cardID := range validCardIDs {
|
||||
validCardIDs := make([]uint, 0, len(validCards))
|
||||
for _, slotICCID := range validCards {
|
||||
cardID := existingCards[slotICCID.ICCID].ID
|
||||
validCardIDs = append(validCardIDs, cardID)
|
||||
|
||||
binding := &model.DeviceSimBinding{
|
||||
DeviceID: device.ID,
|
||||
IotCardID: cardID,
|
||||
SlotPosition: i + 1,
|
||||
SlotPosition: slotICCID.SlotPosition,
|
||||
BindStatus: 1,
|
||||
BindTime: &now,
|
||||
}
|
||||
@@ -354,9 +382,9 @@ func (h *DeviceImportHandler) processBatch(ctx context.Context, task *model.Devi
|
||||
continue
|
||||
}
|
||||
|
||||
for _, iccid := range row.ICCIDs {
|
||||
if card, exists := existingCards[iccid]; exists && !boundCards[iccid] && card.ShopID == nil {
|
||||
boundCards[iccid] = true
|
||||
for _, slotICCID := range row.SlotICCIDs {
|
||||
if card, exists := existingCards[slotICCID.ICCID]; exists && !boundCards[slotICCID.ICCID] && card.ShopID == nil {
|
||||
boundCards[slotICCID.ICCID] = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user