59eb34976a
iotlcm-admin-svr:管理后台服务。 - Go module:iotlcm → git.5iot.com/iotlcm-public/iotlcm-admin-svr(729 文件) - 凭据与地址脱敏:JWT signingKey(含代码里的 MustGet 默认值)、 MySQL DSN、Redis 口令、告警邮件发件人邮箱全部改为占位; 私网 IP → 文档地址段;库名 xiujie_admin → iotlcm - 真实手机号/邮箱 → 合法 11 位编造号 / example.com - 移除内部资产:CI 触发器、过时 DDL(sql/db_iotlcm.sql)、 私有依赖 go get 行、明文 registry 登录口令 - 启动 banner 统一 IOTLCM 方块字 + 社区惯例署名 - Dockerfile 改用公共基础镜像 - 拼错的 RADEME.md → README.md,README 重写 - 需要真实数据库的用例改为可用 IOTLCM_TEST_WITH_DB=1 显式启用 - 补 Apache-2.0 LICENSE,LF 行尾 + .gitattributes 数据库 schema 不随本仓发布(生产 DDL 已过时),README 已说明。
140 lines
4.3 KiB
Go
140 lines
4.3 KiB
Go
package addpackage
|
|
|
|
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"
|
|
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/utility/iot_excelize"
|
|
|
|
"github.com/gogf/gf/v2/net/ghttp"
|
|
"github.com/xuri/excelize/v2"
|
|
)
|
|
|
|
type Submitter struct {
|
|
operation Operation
|
|
}
|
|
|
|
func NewCardSubmitter() *Submitter {
|
|
return &Submitter{operation: OperationCard}
|
|
}
|
|
|
|
func NewPoolSubmitter() *Submitter {
|
|
return &Submitter{operation: OperationPool}
|
|
}
|
|
|
|
func (s *Submitter) DownloadTemplate(ctx context.Context) error {
|
|
processor, err := NewProcessor(s.operation, SubmitOptions{})
|
|
if err != nil {
|
|
return err
|
|
}
|
|
f := excelize.NewFile()
|
|
defer func() { _ = f.Close() }()
|
|
|
|
headers := processor.TemplateHeaders()
|
|
if err := f.SetSheetRow("Sheet1", "A1", &headers); err != nil {
|
|
return err
|
|
}
|
|
if err := iot_excelize.ApplyHeaderColumnsTextStyle(f); err != nil {
|
|
return err
|
|
}
|
|
if err := f.SetColWidth("Sheet1", "A", "B", 24); err != nil {
|
|
return err
|
|
}
|
|
if err := f.SetColWidth("Sheet1", "C", "C", 32); err != nil {
|
|
return err
|
|
}
|
|
fileName := "sim_card_add_package_template"
|
|
if s.operation == OperationPool {
|
|
fileName = "sim_pool_add_package_template"
|
|
}
|
|
return iot_excelize.WriteHTTP(ctx, f, fileName)
|
|
}
|
|
|
|
func (s *Submitter) SubmitExcel(ctx context.Context, file *ghttp.UploadFile, options SubmitOptions) (*SubmitResult, error) {
|
|
options.AutoConfirm = !options.ManualConfirm
|
|
processor, err := NewPrepareProcessor(s.operation, options)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
req := batchimport.SubmitRequest{
|
|
SourceChannel: batchmetadata.Console,
|
|
ExecutionMode: batchmetadata.Bulk,
|
|
File: file,
|
|
BizParams: &processor.inner.options,
|
|
SourceType: consts.BatchSourceTypeFile,
|
|
Operator: common.CurrentOperator(ctx),
|
|
}
|
|
result, err := batchimport.CreatePendingUpload(ctx, req, processor, batchimport.PendingOptions{})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
common.PublishBatchMessage(ctx, result, consts.QueueBatchExecute, string(s.operation)+"_add_package_prepare")
|
|
res := pendingResultFromBatch(result, consts.BatchTypePrepare)
|
|
res.TargetBatchType = processor.targetBatchType
|
|
return res, nil
|
|
}
|
|
|
|
func (s *Submitter) SubmitInput(ctx context.Context, input string, options SubmitOptions) (*SubmitResult, error) {
|
|
// Keep the legacy input/submit endpoint from bypassing async validation.
|
|
return s.PrepareInput(ctx, input, options)
|
|
}
|
|
|
|
func (s *Submitter) PrepareInput(ctx context.Context, input string, options SubmitOptions) (*SubmitResult, error) {
|
|
if strings.TrimSpace(options.PackageCode) != "" || strings.TrimSpace(options.EffectiveMode) != "" {
|
|
options.DefaultEffectiveMode = true
|
|
}
|
|
processor, err := NewPrepareProcessor(s.operation, options)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
rows, err := parseInputRows(ctx, input, processor.inner.options)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
req := batchimport.SubmitRequest{
|
|
SourceChannel: batchmetadata.Console,
|
|
ExecutionMode: batchmetadata.Bulk,
|
|
BizParams: &processor.inner.options,
|
|
SourceType: consts.BatchSourceTypeBatchInput,
|
|
Operator: common.CurrentOperator(ctx),
|
|
}
|
|
result, err := batchimport.CreatePendingRows(ctx, req, processor, rows, batchimport.PendingOptions{})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
common.PublishBatchMessage(ctx, result, consts.QueueBatchExecute, string(s.operation)+"_add_package_prepare")
|
|
res := pendingResultFromBatch(result, consts.BatchTypePrepare)
|
|
res.TargetBatchType = processor.targetBatchType
|
|
return res, nil
|
|
}
|
|
|
|
func pendingResultFromBatch(result *batchimport.Result, batchType int) *SubmitResult {
|
|
res := &SubmitResult{
|
|
BatchType: batchType,
|
|
BatchAsyncStatus: consts.BatchAsyncStatusPending,
|
|
}
|
|
if result == nil {
|
|
return res
|
|
}
|
|
valid := result.ValidRows
|
|
if result.TotalRows > 0 && valid == 0 {
|
|
valid = result.TotalRows - result.ErrorRows
|
|
if valid < 0 {
|
|
valid = 0
|
|
}
|
|
}
|
|
res.BatchNo = result.BatchNo
|
|
res.BatchType = result.BatchType
|
|
if batchType != result.BatchType {
|
|
res.TargetBatchType = batchType
|
|
}
|
|
res.Total = result.TotalRows
|
|
res.ValidCount = valid
|
|
res.FailCount = result.ErrorRows
|
|
return res
|
|
}
|