From 809cb2b8a8d59349f873ccacde8370858c74b53a Mon Sep 17 00:00:00 2001 From: huang Date: Fri, 27 Mar 2026 22:49:40 +0800 Subject: [PATCH] =?UTF-8?q?fix(01-05):=20=E8=AE=BE=E5=A4=87=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E8=A1=A5=E5=85=85=20IMEI=20=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=EF=BC=88CRITICAL-07=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - DeviceRow struct 新增 IMEI string 字段 - buildDeviceColumnIndex 支持 imei/设备imei/imei号 列名映射 - ParseDeviceExcel 解析数据行时填充 row.IMEI - device_import.go processBatch 创建 model.Device 时赋值 IMEI: row.IMEI --- internal/task/device_import.go | 1 + pkg/utils/excel.go | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/internal/task/device_import.go b/internal/task/device_import.go index 23d103d..2111e44 100644 --- a/internal/task/device_import.go +++ b/internal/task/device_import.go @@ -264,6 +264,7 @@ func (h *DeviceImportHandler) processBatch(ctx context.Context, task *model.Devi device := &model.Device{ VirtualNo: row.VirtualNo, + IMEI: row.IMEI, DeviceName: row.DeviceName, DeviceModel: row.DeviceModel, DeviceType: row.DeviceType, diff --git a/pkg/utils/excel.go b/pkg/utils/excel.go index ed9c433..65458e5 100644 --- a/pkg/utils/excel.go +++ b/pkg/utils/excel.go @@ -35,6 +35,7 @@ type CSVParseError struct { type DeviceRow struct { Line int VirtualNo string + IMEI string // 设备IMEI,对应 Excel IMEI 列,用于 Gateway API 调用 DeviceName string DeviceModel string DeviceType string @@ -132,6 +133,9 @@ func ParseDeviceExcel(filePath string) ([]DeviceRow, int, error) { if idx := colIndex["virtual_no"]; idx >= 0 && idx < len(record) { row.VirtualNo = strings.TrimSpace(record[idx]) } + if idx := colIndex["imei"]; idx >= 0 && idx < len(record) { + row.IMEI = strings.TrimSpace(record[idx]) + } if idx := colIndex["device_name"]; idx >= 0 && idx < len(record) { row.DeviceName = strings.TrimSpace(record[idx]) } @@ -317,9 +321,11 @@ func findCardColumns(header []string) (iccidCol, msisdnCol, virtualNoCol int) { // buildDeviceColumnIndex 构建设备导入列索引 // 识别表头中的列名,返回列名到列索引的映射 +// IMEI 列支持多种列名格式:imei/IMEI/设备IMEI/IMEI号 func buildDeviceColumnIndex(header []string) map[string]int { index := map[string]int{ "virtual_no": -1, + "imei": -1, "device_name": -1, "device_model": -1, "device_type": -1, @@ -332,9 +338,17 @@ func buildDeviceColumnIndex(header []string) map[string]int { } for i, col := range header { - col = strings.ToLower(strings.TrimSpace(col)) - if _, exists := index[col]; exists { - index[col] = i + normalized := strings.ToLower(strings.TrimSpace(col)) + // 支持 IMEI 多种列名格式 + switch normalized { + case "imei", "设备imei", "imei号": + if index["imei"] == -1 { + index["imei"] = i + } + default: + if _, exists := index[normalized]; exists { + index[normalized] = i + } } }