chore: 并入 iotlcm-admin-svr 历史到 admin-svr/(原提交 49818c6)
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user