设备导入卡槽不对的问题
This commit is contained in:
@@ -92,9 +92,11 @@ func registerDeviceRoutes(router fiber.Router, handler *admin.DeviceHandler, imp
|
||||
- ` + "`device_name`" + `: 设备名称
|
||||
- ` + "`device_model`" + `: 设备型号
|
||||
- ` + "`device_type`" + `: 设备类型
|
||||
- ` + "`max_sim_slots`" + `: 最大插槽数(默认4)
|
||||
- ` + "`imei`" + `: 设备 IMEI
|
||||
- ` + "`manufacturer`" + `: 制造商
|
||||
- ` + "`iccid_1`" + ` ~ ` + "`iccid_4`" + `: 绑定的卡 ICCID(卡必须已存在且未绑定)
|
||||
- ` + "`max_sim_slots`" + `: 最大插槽数(默认4,范围1-4)
|
||||
- ` + "`iccid_1`" + ` ~ ` + "`iccid_4`" + `: 固定槽位的卡 ICCID(` + "`iccid_1`" + `=槽1,` + "`iccid_2`" + `=槽2,` + "`iccid_3`" + `=槽3,` + "`iccid_4`" + `=槽4;卡必须已存在且未绑定)
|
||||
- 槽位规则:中间留空不会触发前移补位;如果 ` + "`max_sim_slots=2`" + `,则 ` + "`iccid_3`" + `、` + "`iccid_4`" + ` 必须留空,否则该行失败
|
||||
- 列格式:设置为文本格式(避免长数字被转为科学记数法)`,
|
||||
Tags: []string{"设备管理"},
|
||||
Input: new(dto.ImportDeviceRequest),
|
||||
|
||||
@@ -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