chore: 并入 iotlcm-admin-svr 历史到 admin-svr/(原提交 49818c6)
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
package dataswitch
|
||||
|
||||
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 {
|
||||
maxFile := consts.SimCardDataStartMaxFileSize
|
||||
if p.config.BatchType == consts.BatchTypeDataStop {
|
||||
maxFile = consts.SimCardDataStopMaxFileSize
|
||||
}
|
||||
if p.config.BatchType == consts.BatchTypeDataCut {
|
||||
maxFile = consts.SimCardDataCutMaxFileSize
|
||||
}
|
||||
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(maxFile),
|
||||
MaxRows: consts.SimCardBatchMaxRows,
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user