feat: 添加环境变量管理工具和部署配置改版
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m33s

主要改动:
- 新增交互式环境配置脚本 (scripts/setup-env.sh)
- 新增本地启动快捷脚本 (scripts/run-local.sh)
- 新增环境变量模板文件 (.env.example)
- 部署模式改版:使用嵌入式配置 + 环境变量覆盖
- 添加对象存储功能支持
- 改进 IoT 卡片导入任务
- 优化 OpenAPI 文档生成
- 删除旧的配置文件,改用嵌入式默认配置
This commit is contained in:
2026-01-26 10:28:29 +08:00
parent 194078674a
commit 45aa7deb87
94 changed files with 6532 additions and 1967 deletions

View File

@@ -22,7 +22,7 @@ func TestIotCardImportHandler_ProcessImport(t *testing.T) {
importTaskStore := postgres.NewIotCardImportTaskStore(tx, rdb)
iotCardStore := postgres.NewIotCardStore(tx, rdb)
handler := NewIotCardImportHandler(tx, rdb, importTaskStore, iotCardStore, logger)
handler := NewIotCardImportHandler(tx, rdb, importTaskStore, iotCardStore, nil, logger)
ctx := context.Background()
t.Run("成功导入新ICCID", func(t *testing.T) {
@@ -30,8 +30,12 @@ func TestIotCardImportHandler_ProcessImport(t *testing.T) {
CarrierID: 1,
CarrierType: constants.CarrierCodeCMCC,
BatchNo: "TEST_BATCH_001",
ICCIDList: model.ICCIDListJSON{"89860012345678905001", "89860012345678905002", "89860012345678905003"},
TotalCount: 3,
CardList: model.CardListJSON{
{ICCID: "89860012345678905001", MSISDN: "13800000001"},
{ICCID: "89860012345678905002", MSISDN: "13800000002"},
{ICCID: "89860012345678905003", MSISDN: "13800000003"},
},
TotalCount: 3,
}
task.Creator = 1
@@ -43,6 +47,9 @@ func TestIotCardImportHandler_ProcessImport(t *testing.T) {
exists, _ := iotCardStore.ExistsByICCID(ctx, "89860012345678905001")
assert.True(t, exists)
card, _ := iotCardStore.GetByICCID(ctx, "89860012345678905001")
assert.Equal(t, "13800000001", card.MSISDN)
})
t.Run("跳过已存在的ICCID", func(t *testing.T) {
@@ -58,8 +65,11 @@ func TestIotCardImportHandler_ProcessImport(t *testing.T) {
CarrierID: 1,
CarrierType: constants.CarrierCodeCMCC,
BatchNo: "TEST_BATCH_002",
ICCIDList: model.ICCIDListJSON{"89860012345678906001", "89860012345678906002"},
TotalCount: 2,
CardList: model.CardListJSON{
{ICCID: "89860012345678906001", MSISDN: "13800000011"},
{ICCID: "89860012345678906002", MSISDN: "13800000012"},
},
TotalCount: 2,
}
task.Creator = 1
@@ -70,6 +80,7 @@ func TestIotCardImportHandler_ProcessImport(t *testing.T) {
assert.Equal(t, 0, result.failCount)
assert.Len(t, result.skippedItems, 1)
assert.Equal(t, "89860012345678906001", result.skippedItems[0].ICCID)
assert.Equal(t, "13800000011", result.skippedItems[0].MSISDN)
assert.Equal(t, "ICCID 已存在", result.skippedItems[0].Reason)
})
@@ -78,8 +89,11 @@ func TestIotCardImportHandler_ProcessImport(t *testing.T) {
CarrierID: 1,
CarrierType: constants.CarrierCodeCTCC,
BatchNo: "TEST_BATCH_003",
ICCIDList: model.ICCIDListJSON{"89860312345678907001", "898603123456789070"},
TotalCount: 2,
CardList: model.CardListJSON{
{ICCID: "89860312345678907001", MSISDN: "13900000001"},
{ICCID: "898603123456789070", MSISDN: "13900000002"},
},
TotalCount: 2,
}
task.Creator = 1
@@ -89,6 +103,7 @@ func TestIotCardImportHandler_ProcessImport(t *testing.T) {
assert.Equal(t, 0, result.skipCount)
assert.Equal(t, 2, result.failCount)
assert.Len(t, result.failedItems, 2)
assert.Equal(t, "13900000001", result.failedItems[0].MSISDN)
})
t.Run("混合场景-成功跳过和失败", func(t *testing.T) {
@@ -104,10 +119,10 @@ func TestIotCardImportHandler_ProcessImport(t *testing.T) {
CarrierID: 1,
CarrierType: constants.CarrierCodeCMCC,
BatchNo: "TEST_BATCH_004",
ICCIDList: model.ICCIDListJSON{
"89860012345678908001",
"89860012345678908002",
"invalid!iccid",
CardList: model.CardListJSON{
{ICCID: "89860012345678908001", MSISDN: "13800000021"},
{ICCID: "89860012345678908002", MSISDN: "13800000022"},
{ICCID: "invalid!iccid", MSISDN: "13800000023"},
},
TotalCount: 3,
}
@@ -120,12 +135,12 @@ func TestIotCardImportHandler_ProcessImport(t *testing.T) {
assert.Equal(t, 1, result.failCount)
})
t.Run("空ICCID列表", func(t *testing.T) {
t.Run("空列表", func(t *testing.T) {
task := &model.IotCardImportTask{
CarrierID: 1,
CarrierType: constants.CarrierCodeCMCC,
BatchNo: "TEST_BATCH_005",
ICCIDList: model.ICCIDListJSON{},
CardList: model.CardListJSON{},
TotalCount: 0,
}
@@ -146,10 +161,10 @@ func TestIotCardImportHandler_ProcessBatch(t *testing.T) {
importTaskStore := postgres.NewIotCardImportTaskStore(tx, rdb)
iotCardStore := postgres.NewIotCardStore(tx, rdb)
handler := NewIotCardImportHandler(tx, rdb, importTaskStore, iotCardStore, logger)
handler := NewIotCardImportHandler(tx, rdb, importTaskStore, iotCardStore, nil, logger)
ctx := context.Background()
t.Run("验证行号正确记录", func(t *testing.T) {
t.Run("验证行号和MSISDN正确记录", func(t *testing.T) {
existingCard := &model.IotCard{
ICCID: "89860012345678909002",
CardType: "data_card",
@@ -165,10 +180,10 @@ func TestIotCardImportHandler_ProcessBatch(t *testing.T) {
}
task.Creator = 1
batch := []string{
"89860012345678909001",
"89860012345678909002",
"invalid",
batch := []model.CardItem{
{ICCID: "89860012345678909001", MSISDN: "13800000031"},
{ICCID: "89860012345678909002", MSISDN: "13800000032"},
{ICCID: "invalid", MSISDN: "13800000033"},
}
result := &importResult{
skippedItems: make(model.ImportResultItems, 0),
@@ -182,6 +197,8 @@ func TestIotCardImportHandler_ProcessBatch(t *testing.T) {
assert.Equal(t, 1, result.failCount)
assert.Equal(t, 101, result.skippedItems[0].Line)
assert.Equal(t, "13800000032", result.skippedItems[0].MSISDN)
assert.Equal(t, 102, result.failedItems[0].Line)
assert.Equal(t, "13800000033", result.failedItems[0].MSISDN)
})
}