chore: 初始开源发布
iotlcm-worker-svr:异步执行中枢(RabbitMQ 消费者 + 全量同步编排)。 - Go module:iotlcm-worker-svr → git.5iot.com/iotlcm-public/iotlcm-worker-svr(214 文件) - 凭据与内部标识脱敏:MySQL/Redis 凭据、私网与生产 IP、内网域名、 库名 xiujie_admin → iotlcm、哨兵名占位 - 159 处真实手机号 → 合法 11 位编造号(保留号段与后 4 位,维持互异, 不破坏「校验 MSISDN 格式」等测试断言) - 移除内部资产:CI 触发器、Jenkins 触发测试文档、预演门禁与镜像 digest 记录 - Dockerfile 改用公共基础镜像(golang:1.25-alpine → alpine:3.23), 移除写死的 git 凭据 - README 重写(架构/全量同步模型/配置/已知失败),补 Apache-2.0 LICENSE,LF 行尾 + .gitattributes 已知:3 个测试包在源仓同一提交上同样失败(client/upstream、 service/allocate、service/inbound),属既有缺陷,本仓未引入亦未修复。
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
package trafficcutoffconfig
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
|
||||
"git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/consts"
|
||||
"git.5iot.com/iotlcm-public/iotlcm-worker-svr/internal/model/entity"
|
||||
)
|
||||
|
||||
const (
|
||||
noDetailsReason = "达量断网配置批次没有可处理明细"
|
||||
validationFailureReason = "部分达量断网配置校验失败"
|
||||
emptyICCIDReason = "ICCID不能为空"
|
||||
duplicateICCIDReason = "ICCID在批次内重复"
|
||||
unauthorizedReason = "ICCID不在当前操作员授权范围内"
|
||||
cardMissingReason = "ICCID不存在或不属于当前租户"
|
||||
msisdnMismatchReason = "MSISDN与卡档案不一致"
|
||||
imsiMismatchReason = "IMSI与卡档案不一致"
|
||||
flowPoolCardReason = "流量池卡不支持达量断网配置"
|
||||
packageTotalExceededReason = "达量断网阈值不能大于套餐总流量"
|
||||
)
|
||||
|
||||
type executor struct {
|
||||
repository *Repository
|
||||
}
|
||||
|
||||
const trafficCutoffConfigProcessingRetryAfter = 2 * time.Minute
|
||||
|
||||
func NewExecutor() *executor {
|
||||
return &executor{repository: NewRepository()}
|
||||
}
|
||||
|
||||
func (e *executor) CanExecuteProcessing(_ context.Context, main *entity.BatchMain) (bool, error) {
|
||||
if main == nil || main.BatchType != consts.BatchTypeTrafficCutoffConfig || main.BatchAsyncStatus != consts.BatchAsyncStatusProcessing {
|
||||
return false, nil
|
||||
}
|
||||
if main.StartTime == nil || main.StartTime.IsZero() {
|
||||
return true, nil
|
||||
}
|
||||
return gtime.Now().Sub(main.StartTime) >= trafficCutoffConfigProcessingRetryAfter, nil
|
||||
}
|
||||
|
||||
func (e *executor) Execute(ctx context.Context, batchNo string) error {
|
||||
task, err := e.repository.Load(ctx, strings.TrimSpace(batchNo))
|
||||
if err != nil {
|
||||
return gerror.Wrap(err, "load traffic cutoff config batch failed")
|
||||
}
|
||||
validateTask(task)
|
||||
return gerror.Wrap(e.repository.Commit(ctx, task), "commit traffic cutoff config batch failed")
|
||||
}
|
||||
|
||||
func validateTask(task *Task) {
|
||||
if task == nil || len(task.Details) == 0 {
|
||||
if task != nil {
|
||||
task.FailureReason = noDetailsReason
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
iccidCounts := make(map[string]int, len(task.Details))
|
||||
for _, detail := range task.Details {
|
||||
if detail == nil {
|
||||
continue
|
||||
}
|
||||
detail.ICCID = strings.TrimSpace(detail.ICCID)
|
||||
detail.MSISDN = strings.TrimSpace(detail.MSISDN)
|
||||
detail.IMSI = strings.TrimSpace(detail.IMSI)
|
||||
if detail.ICCID != "" {
|
||||
iccidCounts[detail.ICCID]++
|
||||
}
|
||||
}
|
||||
|
||||
for _, detail := range task.Details {
|
||||
validateDetail(task, detail)
|
||||
if detail != nil && detail.Reason == "" && iccidCounts[detail.ICCID] > 1 {
|
||||
detail.Reason = duplicateICCIDReason
|
||||
}
|
||||
}
|
||||
_, failCount := countResult(task)
|
||||
if failCount > 0 {
|
||||
task.FailureReason = validationFailureReason
|
||||
} else {
|
||||
task.FailureReason = ""
|
||||
}
|
||||
}
|
||||
|
||||
func validateDetail(task *Task, detail *Detail) {
|
||||
if detail == nil || detail.Reason != "" {
|
||||
return
|
||||
}
|
||||
if detail.ICCID == "" {
|
||||
detail.Reason = emptyICCIDReason
|
||||
return
|
||||
}
|
||||
if !detail.Authorized {
|
||||
detail.Reason = unauthorizedReason
|
||||
return
|
||||
}
|
||||
if detail.Card == nil {
|
||||
detail.Reason = cardMissingReason
|
||||
return
|
||||
}
|
||||
detail.Card.ICCID = strings.TrimSpace(detail.Card.ICCID)
|
||||
detail.Card.MSISDN = strings.TrimSpace(detail.Card.MSISDN)
|
||||
detail.Card.IMSI = strings.TrimSpace(detail.Card.IMSI)
|
||||
if detail.MSISDN != "" && detail.MSISDN != detail.Card.MSISDN {
|
||||
detail.Reason = msisdnMismatchReason
|
||||
return
|
||||
}
|
||||
if detail.IMSI != "" && detail.IMSI != detail.Card.IMSI {
|
||||
detail.Reason = imsiMismatchReason
|
||||
return
|
||||
}
|
||||
if detail.Card.IsFlowPool != 0 {
|
||||
detail.Reason = flowPoolCardReason
|
||||
return
|
||||
}
|
||||
if task.Config.TrafficCutoffStatus == 1 &&
|
||||
detail.Card.PackageTotalFlowMb > 0 &&
|
||||
task.Config.TrafficCutoffThreshold > detail.Card.PackageTotalFlowMb {
|
||||
detail.Reason = packageTotalExceededReason
|
||||
}
|
||||
}
|
||||
|
||||
func countResult(task *Task) (successCount, failCount int) {
|
||||
if task == nil {
|
||||
return 0, 0
|
||||
}
|
||||
for _, detail := range task.Details {
|
||||
if detail != nil && detail.Success() {
|
||||
successCount++
|
||||
} else {
|
||||
failCount++
|
||||
}
|
||||
}
|
||||
return successCount, failCount
|
||||
}
|
||||
Reference in New Issue
Block a user