sync: 同步 OneLink 模拟服务 v1.0.4 并脱敏

This commit is contained in:
MiFaZhan
2026-10-29 14:25:38 +08:00
parent 4e2cd43a55
commit 5299c13c1a
9 changed files with 170 additions and 58 deletions
+1 -27
View File
@@ -3,7 +3,6 @@ package service
import (
"fmt"
"strconv"
"sync"
"time"
)
@@ -51,31 +50,6 @@ var inboundExportHeaders = func() []string {
return headers
}()
// 生成序号分配器。
//
// 序号直接来自毫秒时间戳时,同一毫秒内的两次生成会得到完全相同的 seq,
// 进而生成重复的 ICCID/IMSI,触发 mock_t_sim_card 的唯一约束冲突
// (表现为「一键生成」连点两次或两个分组连续生成时报
// UNIQUE constraint failed: mock_t_sim_card.imsi)。
//
// 这里用进程内单调递增的上界保证 seq 严格递增:时间戳只决定起点,
// 真正的唯一性由 nextGeneratedSeq 保证。
var (
generatedSeqMu sync.Mutex
generatedSeqLast int64
)
// nextGeneratedSeq 返回严格大于上一次分配值的序号。
func nextGeneratedSeq(candidate int64) int64 {
generatedSeqMu.Lock()
defer generatedSeqMu.Unlock()
if candidate <= generatedSeqLast {
candidate = generatedSeqLast + 1
}
generatedSeqLast = candidate
return candidate
}
func GenerateSIMCards(batchTime time.Time, count int) []SIMCard {
if count <= 0 {
return []SIMCard{}
@@ -84,7 +58,7 @@ func GenerateSIMCards(batchTime time.Time, count int) []SIMCard {
base := batchTime.UnixMilli()
dbTime := batchTime.Format("2006-01-02 15:04:05")
for i := 0; i < count; i++ {
seq := nextGeneratedSeq(base + int64(i+1))
seq := base + int64(i+1)
card := SIMCard{
MSISDN: fmt.Sprintf("141%08d", seq%100000000),
ICCID: fmt.Sprintf("898604%014d", seq%100000000000000),