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 + } } }