sync: 同步 v1.0.4 并脱敏配置与镜像

This commit is contained in:
MiFaZhan
2026-10-29 14:36:49 +08:00
parent 743e8e6e6e
commit 2206a393f7
516 changed files with 18119 additions and 2253 deletions
@@ -25,7 +25,7 @@ func (s *Service) UpdateCardsAfterRenew(ctx context.Context, tx gdb.TX, renew *R
if bind == nil {
return gerror.Newf("ICCID续费订购记录不存在:%s", iccid)
}
packageStatus := CalcPackageStatus(now, card.FlowPkgBeginAt, bind.ExpectedExpireTime)
packageStatus, _ := calcPackageStatuses(now, bind.EffectiveTime, bind.ExpectedExpireTime)
result, err := tx.Ctx(ctx).Model(dao.TSimCardInfo.Table()).
Where(dao.TSimCardInfo.Columns().Iccid, iccid).
Data(do.TSimCardInfo{
@@ -187,6 +187,7 @@ func (s *Service) RenewCurrentPackage(ctx context.Context, tx gdb.TX, in *RenewC
latestBind := latestBindsByIccid[iccid]
periodBegin := renewPeriodBeginAt(renewBaseExpireTime(card, latestBind), in.PackageBeginTime)
periodEnd := addMonths(periodBegin, durationMonths+giftDurationMonths)
_, effectiveStatus := calcPackageStatuses(now, periodBegin, periodEnd)
subscriptionNo, err := batchimport.NextRandomNo(subscriptionNoPrefix)
if err != nil {
return nil, err
@@ -201,7 +202,7 @@ func (s *Service) RenewCurrentPackage(ctx context.Context, tx gdb.TX, in *RenewC
PackageCode: pkg.PackageCode,
PreviousPackageCode: currentPackageCode,
BusinessType: consts.PackageBusinessTypeRenew,
EffectiveStatus: consts.EffectiveStatusPending,
EffectiveStatus: effectiveStatus,
HandleTime: now,
EffectiveTime: periodBegin,
ExpectedExpireTime: periodEnd,
@@ -227,7 +228,7 @@ func (s *Service) RenewCurrentPackage(ctx context.Context, tx gdb.TX, in *RenewC
PackageCode: pkg.PackageCode,
PreviousPackageCode: currentPackageCode,
BusinessType: consts.PackageBusinessTypeRenew,
EffectiveStatus: consts.EffectiveStatusPending,
EffectiveStatus: effectiveStatus,
HandleTime: now,
EffectiveTime: periodBegin,
ExpectedExpireTime: periodEnd,
@@ -0,0 +1,21 @@
package cardpackage
import (
"strings"
"testing"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/consts"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/model/entity"
)
func TestValidateRenewCardStatusRejectsStoppedCard(t *testing.T) {
err := validateRenewCardStatus("89860401788404184188", &entity.TSimCardInfo{
BossCardStatus: consts.V3ApiSimBossCardStatusStopped,
})
if err == nil {
t.Fatal("validateRenewCardStatus() error = nil, want stopped card error")
}
if !strings.Contains(err.Error(), "当前为停机状态") {
t.Fatalf("validateRenewCardStatus() error = %q, want stopped card error", err.Error())
}
}
@@ -0,0 +1,13 @@
package cardpackage
import "testing"
func TestCardPackageBindChunkSizeSupportsFiftyThousandCards(t *testing.T) {
const totalCards = 50000
if cardPackageBindInsertBatchSize <= 0 || cardPackageBindInsertBatchSize > 500 {
t.Fatalf("cardPackageBindInsertBatchSize = %d, want 1..500", cardPackageBindInsertBatchSize)
}
if chunks := (totalCards + cardPackageBindInsertBatchSize - 1) / cardPackageBindInsertBatchSize; chunks != 100 {
t.Fatalf("bind insert chunks = %d, want 100", chunks)
}
}
@@ -506,6 +506,10 @@ func CalcPackageStatus(now, beginAt, endAt *gtime.Time) int {
return consts.PackageStatusEffective
}
func calcPackageStatuses(now, beginAt, endAt *gtime.Time) (packageStatus, effectiveStatus int) {
return CalcPackageStatus(now, beginAt, endAt), CalcEffectiveStatus(now, beginAt, endAt)
}
func CalcEffectiveStatus(now, beginAt, endAt *gtime.Time) int {
if beginAt != nil && beginAt.After(now) {
return consts.EffectiveStatusPending
@@ -0,0 +1,70 @@
package cardpackage
import (
"testing"
"git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/consts"
"github.com/gogf/gf/v2/os/gtime"
)
func TestOrderTypeForBusinessType(t *testing.T) {
tests := []struct {
name string
businessType int
want int
}{
{name: "subscribe", businessType: consts.PackageBusinessTypeSubscribe, want: consts.OrderTypeCardSubscribe},
{name: "renew", businessType: consts.PackageBusinessTypeRenew, want: consts.OrderTypeCardRenew},
{name: "change", businessType: consts.PackageBusinessTypeChange, want: consts.OrderTypeCardChange},
{name: "unknown defaults to subscribe", businessType: 99, want: consts.OrderTypeCardSubscribe},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
if got := orderTypeForBusinessType(test.businessType); got != test.want {
t.Fatalf("orderTypeForBusinessType(%d) = %d, want %d", test.businessType, got, test.want)
}
})
}
}
func TestCalcPackageStatuses(t *testing.T) {
now := gtime.NewFromStr("2026-10-27 12:00:00")
tests := []struct {
name string
beginAt, endAt *gtime.Time
wantPackage, wantBind int
}{
{
name: "renew period already effective",
beginAt: gtime.NewFromStr("2026-09-30 23:59:59"),
endAt: gtime.NewFromStr("2027-09-30 23:59:59"),
wantPackage: consts.PackageStatusEffective,
wantBind: consts.EffectiveStatusEffective,
},
{
name: "renew period starts in future",
beginAt: gtime.NewFromStr("2026-11-01 23:59:59"),
endAt: gtime.NewFromStr("2027-11-01 23:59:59"),
wantPackage: consts.PackageStatusPending,
wantBind: consts.EffectiveStatusPending,
},
{
name: "renew period already expired",
beginAt: gtime.NewFromStr("2025-09-30 23:59:59"),
endAt: gtime.NewFromStr("2026-09-30 23:59:59"),
wantPackage: consts.PackageStatusExpired,
wantBind: consts.EffectiveStatusExpired,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
packageStatus, effectiveStatus := calcPackageStatuses(now, test.beginAt, test.endAt)
if packageStatus != test.wantPackage || effectiveStatus != test.wantBind {
t.Fatalf("calcPackageStatuses() = (%d, %d), want (%d, %d)", packageStatus, effectiveStatus, test.wantPackage, test.wantBind)
}
})
}
}