fix(01-05): 设备导入补充 IMEI 字段(CRITICAL-07)
- DeviceRow struct 新增 IMEI string 字段 - buildDeviceColumnIndex 支持 imei/设备imei/imei号 列名映射 - ParseDeviceExcel 解析数据行时填充 row.IMEI - device_import.go processBatch 创建 model.Device 时赋值 IMEI: row.IMEI
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user