63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package warningconfig
|
|
|
|
import (
|
|
"context"
|
|
|
|
"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, itemType int) ([]batchimport.Row, error) {
|
|
parsedRows, err := excel.ParseFile(ctx, filePath, excel.ParseOptions{
|
|
RequiredHeaders: requiredHeaders(itemType),
|
|
SingleSheet: true,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
baseOptions, err := NormalizeContextOptions(itemType, defaultWarnUnit(itemType))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
rows := make([]batchimport.Row, 0, len(parsedRows))
|
|
for _, parsed := range parsedRows {
|
|
if itemType == warnItemTypeFlowPool {
|
|
row := &Row{
|
|
RowNo: parsed.RowNo,
|
|
ItemType: warnItemTypeFlowPool,
|
|
FlowPoolCode: excel.Field(parsed, poolHeaderCode),
|
|
Config: baseOptions,
|
|
ConfigSet: true,
|
|
}
|
|
row.Config, err = parseExcelRowOptions(parsed, itemType, baseOptions.WarnUnit)
|
|
if err != nil {
|
|
row.AddErrorReason(err.Error())
|
|
}
|
|
rows = append(rows, row)
|
|
continue
|
|
}
|
|
row := &Row{
|
|
RowNo: parsed.RowNo,
|
|
ItemType: warnItemTypeCard,
|
|
Iccid: excel.Field(parsed, cardHeaderIccid),
|
|
Msisdn: excel.Field(parsed, cardHeaderMsisdn),
|
|
Imsi: excel.Field(parsed, cardHeaderImsi),
|
|
Config: baseOptions,
|
|
ConfigSet: true,
|
|
}
|
|
row.Config, err = parseExcelRowOptions(parsed, itemType, baseOptions.WarnUnit)
|
|
if err != nil {
|
|
row.AddErrorReason(err.Error())
|
|
}
|
|
rows = append(rows, row)
|
|
}
|
|
return rows, nil
|
|
}
|
|
|
|
func defaultWarnUnit(itemType int) int {
|
|
if itemType == warnItemTypeFlowPool {
|
|
return warnUnitPercent
|
|
}
|
|
return warnUnitMb
|
|
}
|