修复设备导入卡查询失败后重复重试
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 11m46s

This commit is contained in:
2026-09-20 10:09:46 +08:00
parent 54c4ec7ba4
commit 98acc51241

View File

@@ -258,22 +258,24 @@ func (h *DeviceImportHandler) processBatch(ctx context.Context, task *model.Devi
return return
} }
var existingCards map[string]*model.IotCard existingCards := make(map[string]*model.IotCard)
var boundCards map[string]bool boundCards := make(map[string]bool)
if len(allICCIDs) > 0 { if len(allICCIDs) > 0 {
cards, err := h.iotCardStore.GetByICCIDs(ctx, allICCIDs) cards, err := h.iotCardStore.GetByICCIDs(ctx, allICCIDs)
if err != nil { if err != nil {
h.logger.Error("查询卡信息失败", zap.Error(err)) h.logger.Error("查询卡信息失败", zap.Error(err))
} else { appendDeviceImportBatchQueryFailures(batch, result)
existingCards = make(map[string]*model.IotCard) return
}
for _, card := range cards { for _, card := range cards {
existingCards[card.ICCID] = card existingCards[card.ICCID] = card
} }
}
boundCards, err = h.deviceSimBindingStore.GetBoundICCIDs(ctx, allICCIDs) boundCards, err = h.deviceSimBindingStore.GetBoundICCIDs(ctx, allICCIDs)
if err != nil { if err != nil {
h.logger.Error("查询卡绑定状态失败", zap.Error(err)) h.logger.Error("查询卡绑定状态失败", zap.Error(err))
appendDeviceImportBatchQueryFailures(batch, result)
return
} }
} }
@@ -442,6 +444,17 @@ func (h *DeviceImportHandler) processBatch(ctx context.Context, task *model.Devi
} }
} }
func appendDeviceImportBatchQueryFailures(batch []utils.DeviceRow, result *deviceImportResult) {
for _, row := range batch {
result.failedItems = append(result.failedItems, model.ImportResultItem{
Line: row.Line,
ICCID: row.VirtualNo,
Reason: "数据库查询失败",
})
result.failCount++
}
}
func (h *DeviceImportHandler) appendDeviceCreateAudit(ctx context.Context, tx *gorm.DB, task *model.DeviceImportTask, device *model.Device) error { func (h *DeviceImportHandler) appendDeviceCreateAudit(ctx context.Context, tx *gorm.DB, task *model.DeviceImportTask, device *model.Device) error {
if h.auditWriter == nil || task == nil || device == nil || device.ID == 0 { if h.auditWriter == nil || task == nil || device == nil || device.ID == 0 {
return pkgerrors.New(pkgerrors.CodeInvalidStatus, "设备导入统一审计接缝未配置或资源不完整") return pkgerrors.New(pkgerrors.CodeInvalidStatus, "设备导入统一审计接缝未配置或资源不完整")