Files

51 lines
1.3 KiB
Go

package unsub
import (
"context"
"io"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/library/batchimport"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/library/batchinput/excel"
)
func ParseExcelFileRows(ctx context.Context, filePath string) ([]batchimport.Row, error) {
parsedRows, err := excel.ParseFile(ctx, filePath, excel.ParseOptions{
RequiredHeaders: []string{"ICCID"},
})
if err != nil {
return nil, err
}
return toBatchRows(parsedRows), nil
}
func ParseExcelRows(ctx context.Context, reader io.Reader) ([]*Row, error) {
parsedRows, err := excel.ParseReader(ctx, reader, excel.ParseOptions{
RequiredHeaders: []string{"ICCID"},
})
if err != nil {
return nil, err
}
return toRows(parsedRows), nil
}
func toBatchRows(parsedRows []excel.ParsedRow) []batchimport.Row {
rows := toRows(parsedRows)
result := make([]batchimport.Row, 0, len(rows))
for _, row := range rows {
result = append(result, row)
}
return result
}
func toRows(parsedRows []excel.ParsedRow) []*Row {
rows := make([]*Row, 0, len(parsedRows))
for _, parsed := range parsedRows {
rows = append(rows, &Row{
RowNo: parsed.RowNo,
Iccid: excel.Field(parsed, "ICCID"),
Msisdn: excel.Field(parsed, "MSISDN"),
Imsi: excel.Field(parsed, "IMSI"),
})
}
return rows
}