92 lines
3.0 KiB
Go
92 lines
3.0 KiB
Go
package lifecycle
|
|
|
|
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 BatchExecuteMessage = common.BatchExecuteMessage
|
|
|
|
type SubmitResult = common.SubmitResult
|
|
|
|
type Submitter struct {
|
|
operation Operation
|
|
}
|
|
|
|
func NewSubmitter(operation Operation) *Submitter {
|
|
return &Submitter{operation: operation}
|
|
}
|
|
|
|
func (s *Submitter) SubmitExcel(ctx context.Context, file *ghttp.UploadFile, remark string) (*SubmitResult, error) {
|
|
processor, err := NewProcessor(s.operation)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
req := batchimport.SubmitRequest{
|
|
SourceChannel: batchmetadata.Console,
|
|
ExecutionMode: batchmetadata.Bulk,
|
|
File: file,
|
|
BizParams: &common.SubmitOptions{Remark: strings.TrimSpace(remark)},
|
|
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, "lifecycle")
|
|
return common.PendingSubmitResult(result, consts.BatchAsyncStatusPending), nil
|
|
}
|
|
|
|
func (s *Submitter) SubmitInput(ctx context.Context, input, remark string) (*SubmitResult, error) {
|
|
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: &common.SubmitOptions{Remark: strings.TrimSpace(remark)},
|
|
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, "lifecycle")
|
|
return common.PendingSubmitResult(result, consts.BatchAsyncStatusPending), nil
|
|
}
|