chore: 并入 iotlcm-admin-svr 历史到 admin-svr/(原提交 49818c6)
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
package datacut
|
||||
|
||||
import (
|
||||
"context"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/library/batchmetadata"
|
||||
"strings"
|
||||
|
||||
"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/logic/iot/simcardbatch/common"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
type Submitter struct {
|
||||
operation Operation
|
||||
}
|
||||
|
||||
func NewSubmitter(operation Operation) *Submitter {
|
||||
return &Submitter{operation: operation}
|
||||
}
|
||||
|
||||
func (s *Submitter) Operation() Operation {
|
||||
return s.operation
|
||||
}
|
||||
|
||||
func (s *Submitter) SubmitExcel(ctx context.Context, file *ghttp.UploadFile, threshold float64, remark string) (*SubmitResult, error) {
|
||||
if err := validateThreshold(threshold); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
processor, err := NewProcessor(s.operation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req := batchimport.SubmitRequest{
|
||||
SourceChannel: batchmetadata.Console,
|
||||
ExecutionMode: batchmetadata.Bulk,
|
||||
File: file,
|
||||
BizParams: &SubmitOptions{Remark: strings.TrimSpace(remark), TrafficCutoffThreshold: threshold},
|
||||
SourceType: consts.BatchSourceTypeFile,
|
||||
Operator: common.CurrentOperator(ctx),
|
||||
}
|
||||
result, err := batchimport.CreatePendingUpload(ctx, req, processor, batchimport.PendingOptions{
|
||||
PrepareRows: func(ctx context.Context, rows []batchimport.Row) error {
|
||||
return common.PrepareAuthorizedRows(ctx, rows, func(item batchimport.Row) (*Row, error) {
|
||||
row, ok := item.(*Row)
|
||||
if !ok || row == nil {
|
||||
return nil, gerror.New("达量断网批次行类型错误")
|
||||
}
|
||||
return row, nil
|
||||
}, "达量断网批次行类型错误")
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
common.PublishBatchMessage(ctx, result, consts.QueueBatchExecute, "datacut")
|
||||
return common.PendingSubmitResult(result, consts.BatchAsyncStatusPending), nil
|
||||
}
|
||||
|
||||
func (s *Submitter) SubmitInput(ctx context.Context, input string, threshold float64, remark string) (*SubmitResult, error) {
|
||||
if err := validateThreshold(threshold); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rows, err := parseInputRows(ctx, input)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
processor, err := NewProcessor(s.operation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req := batchimport.SubmitRequest{
|
||||
SourceChannel: batchmetadata.Console,
|
||||
ExecutionMode: batchmetadata.Bulk,
|
||||
BizParams: &SubmitOptions{Remark: strings.TrimSpace(remark), TrafficCutoffThreshold: threshold},
|
||||
SourceType: consts.BatchSourceTypeBatchInput,
|
||||
Operator: common.CurrentOperator(ctx),
|
||||
}
|
||||
result, err := batchimport.CreatePendingRows(ctx, req, processor, rows, batchimport.PendingOptions{
|
||||
PrepareRows: func(ctx context.Context, rows []batchimport.Row) error {
|
||||
return common.PrepareAuthorizedRows(ctx, rows, func(item batchimport.Row) (*Row, error) {
|
||||
row, ok := item.(*Row)
|
||||
if !ok || row == nil {
|
||||
return nil, gerror.New("达量断网批次行类型错误")
|
||||
}
|
||||
return row, nil
|
||||
}, "达量断网批次行类型错误")
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
common.PublishBatchMessage(ctx, result, consts.QueueBatchExecute, "datacut")
|
||||
return common.PendingSubmitResult(result, consts.BatchAsyncStatusPending), nil
|
||||
}
|
||||
Reference in New Issue
Block a user