63 lines
2.0 KiB
Go
63 lines
2.0 KiB
Go
package datacut
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/consts"
|
|
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/library/batchimport"
|
|
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/model"
|
|
|
|
"github.com/gogf/gf/v2/database/gdb"
|
|
"github.com/gogf/gf/v2/encoding/gjson"
|
|
"github.com/gogf/gf/v2/errors/gerror"
|
|
)
|
|
|
|
type Processor struct {
|
|
config Config
|
|
}
|
|
|
|
func NewProcessor(operation Operation) (*Processor, error) {
|
|
cfg, err := operation.Config()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &Processor{config: cfg}, nil
|
|
}
|
|
|
|
func (p *Processor) Config() batchimport.ProcessorConfig {
|
|
return batchimport.ProcessorConfig{
|
|
Code: "sim_card_" + p.config.Code,
|
|
BatchType: p.config.BatchType,
|
|
BatchNoPrefix: p.config.BatchPrefix,
|
|
TaskName: p.config.TaskName,
|
|
ExportScene: p.config.ExportScene,
|
|
ImportDir: p.config.ImportDir,
|
|
ResultDir: p.config.ResultDir,
|
|
MaxFileSize: int64(consts.SimCardDataCutMaxFileSize),
|
|
TemplateHeaders: []string{"ICCID", "MSISDN", "IMSI"},
|
|
RequiredHeaders: []string{"ICCID"},
|
|
}
|
|
}
|
|
|
|
func (p *Processor) ParseRows(ctx context.Context, filePath string) ([]batchimport.Row, error) {
|
|
return parseExcelFileRows(ctx, filePath)
|
|
}
|
|
|
|
func (p *Processor) ValidateRows(_ context.Context, rows []batchimport.Row) error {
|
|
return validateBasicRows(rows)
|
|
}
|
|
|
|
func (p *Processor) Execute(context.Context, gdb.TX, *batchimport.SubmitRequest, []batchimport.Row) error {
|
|
return gerror.New("达量断网批次只能由异步执行器执行")
|
|
}
|
|
|
|
func (p *Processor) BuildBatchInfo(_ context.Context, req batchimport.SubmitRequest, result *batchimport.Result, importOss *model.SysOssSaveContentModel, _ *model.SysOssSaveContentModel, _ int64) *gjson.Json {
|
|
info := buildBatchInfo(req, p.config)
|
|
if result != nil && result.ImportFileOssId > 0 {
|
|
info.Set("importFileOssId", result.ImportFileOssId)
|
|
} else if importOss != nil && importOss.OssId > 0 {
|
|
info.Set("importFileOssId", importOss.OssId)
|
|
}
|
|
return info
|
|
}
|