chore: 初始开源发布
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 已说明。
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
package trafficcutoff
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/consts"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/dao"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/library/batchimport"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/library/batchmetadata"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/logic/iot/simcardbatch/common"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/logic/iot/simcardbatch/dataswitch"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/model/do"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
)
|
||||
|
||||
func submitCutoffBatch(ctx context.Context, key cutoffBatchGroupKey, items []lockedCutoffCard, runTime time.Time) (*batchimport.Result, error) {
|
||||
if len(items) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
processor, err := dataswitch.NewProcessor(dataswitch.OperationDataCut)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rows := make([]batchimport.Row, 0, len(items))
|
||||
for index, item := range items {
|
||||
rows = append(rows, cutoffDataSwitchRow(index+1, item.Card, runTime))
|
||||
}
|
||||
req := batchimport.SubmitRequest{
|
||||
SourceChannel: batchmetadata.System,
|
||||
ExecutionMode: batchmetadata.Bulk,
|
||||
BizParams: &common.SubmitOptions{Remark: fmt.Sprintf("达量断网自动触发,触发卡数:%d", len(rows))},
|
||||
SourceType: consts.BatchSourceTypeScheduled,
|
||||
Operator: batchimport.OperatorContext{
|
||||
TenantId: key.TenantId,
|
||||
DeptId: key.CreatedDept,
|
||||
UserId: key.CreatedBy,
|
||||
},
|
||||
}
|
||||
result, err := batchimport.CreatePendingRows(ctx, req, processor, rows, batchimport.PendingOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = common.PublishBatchMessageStrict(ctx, result, consts.QueueBatchExecute, "traffic_cutoff"); err != nil {
|
||||
if markErr := markCutoffBatchPublishFailed(ctx, result, err); markErr != nil {
|
||||
return nil, gerror.Wrapf(markErr, "publish cutoff batch failed: %v", err)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func markCutoffBatchPublishFailed(ctx context.Context, result *batchimport.Result, publishErr error) error {
|
||||
if result == nil || result.BatchNo == "" {
|
||||
return nil
|
||||
}
|
||||
reason := "publish batch message failed"
|
||||
if publishErr != nil {
|
||||
reason += ": " + publishErr.Error()
|
||||
}
|
||||
return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
|
||||
if _, err := tx.Ctx(ctx).Model(dao.BatchMain.Table()).
|
||||
Where(dao.BatchMain.Columns().BatchNo, result.BatchNo).
|
||||
Where(dao.BatchMain.Columns().BatchAsyncStatus, consts.BatchAsyncStatusPending).
|
||||
Data(do.BatchMain{
|
||||
BatchAsyncStatus: consts.BatchAsyncStatusFailed,
|
||||
RunResult: consts.BatchRunResultFailed,
|
||||
FailReason: reason,
|
||||
EndTime: gtime.Now(),
|
||||
}).Update(); err != nil {
|
||||
return gerror.Wrap(err, "mark cutoff batch publish failure")
|
||||
}
|
||||
if _, err := tx.Ctx(ctx).Model(dao.BatchDetail.Table()).
|
||||
Where(dao.BatchDetail.Columns().BatchNo, result.BatchNo).
|
||||
Where(dao.BatchDetail.Columns().DetailStatus, consts.BatchDetailStatusPending).
|
||||
Data(do.BatchDetail{
|
||||
DetailStatus: consts.BatchDetailStatusFailed,
|
||||
ErrorReason: reason,
|
||||
}).Update(); err != nil {
|
||||
return gerror.Wrap(err, "mark cutoff batch detail publish failure")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func cutoffDataSwitchRow(rowNo int, card cutoffCard, runTime time.Time) *dataswitch.Row {
|
||||
triggerReason := "达量断网:已用流量达到配置阈值,系统自动停用数据服务"
|
||||
if card.isCrossMonthHoldReapply() {
|
||||
triggerReason = "达量断网:跨月保持断网,系统重新停用已恢复的数据服务"
|
||||
}
|
||||
return &dataswitch.Row{
|
||||
RowNo: rowNo,
|
||||
Iccid: card.Iccid,
|
||||
Msisdn: card.Msisdn,
|
||||
Imsi: card.Imsi,
|
||||
Authorized: true,
|
||||
CardID: card.Id,
|
||||
CutoffThreshold: roundCutoffFlow(card.TrafficCutoffThreshold),
|
||||
UsedFlowMb: roundCutoffFlow(card.UsedFlowMb),
|
||||
PackageTotalFlowMb: roundCutoffFlow(cutoffTotalFlowMb(card)),
|
||||
RemainFlowMb: roundCutoffFlow(cutoffRemainFlowMb(card)),
|
||||
DataServiceStatusBefore: card.DataServiceStatus,
|
||||
TrafficCutoffCrossMonthHold: card.TrafficCutoffCrossMonthHold,
|
||||
TriggeredAt: runTime.Format("2006-01-02 15:04:05"),
|
||||
TriggerReason: triggerReason,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user