Files
junhong_cmp_fiber/internal/routes/iot_card.go
huang a945a4f554
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m37s
feat: 实现卡和设备的套餐系列绑定功能
- 添加 Device 和 IotCard 模型的 SeriesID 字段
- 实现 DeviceService 和 IotCardService 的套餐系列绑定逻辑
- 添加 DeviceStore 和 IotCardStore 的数据库操作方法
- 更新 API 接口和路由支持套餐系列绑定
- 创建数据库迁移脚本(000027_add_series_binding_fields)
- 添加完整的单元测试和集成测试
- 更新 OpenAPI 文档
- 归档 OpenSpec 变更文档

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-01-28 19:49:45 +08:00

105 lines
3.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package routes
import (
"github.com/gofiber/fiber/v2"
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
"github.com/break/junhong_cmp_fiber/internal/model/dto"
"github.com/break/junhong_cmp_fiber/pkg/openapi"
)
func registerIotCardRoutes(router fiber.Router, handler *admin.IotCardHandler, importHandler *admin.IotCardImportHandler, doc *openapi.Generator, basePath string) {
iotCards := router.Group("/iot-cards")
groupPath := basePath + "/iot-cards"
Register(iotCards, doc, groupPath, "GET", "/standalone", handler.ListStandalone, RouteSpec{
Summary: "单卡列表(未绑定设备)",
Tags: []string{"IoT卡管理"},
Input: new(dto.ListStandaloneIotCardRequest),
Output: new(dto.ListStandaloneIotCardResponse),
Auth: true,
})
Register(iotCards, doc, groupPath, "GET", "/by-iccid/:iccid", handler.GetByICCID, RouteSpec{
Summary: "通过ICCID查询单卡详情",
Tags: []string{"IoT卡管理"},
Input: new(dto.GetIotCardByICCIDRequest),
Output: new(dto.IotCardDetailResponse),
Auth: true,
})
Register(iotCards, doc, groupPath, "POST", "/import", importHandler.Import, RouteSpec{
Summary: "批量导入IoT卡ICCID+MSISDN",
Description: `## ⚠️ 接口变更说明BREAKING CHANGE
本接口已从 ` + "`multipart/form-data`" + ` 改为 ` + "`application/json`" + `
### 完整导入流程
1. **获取上传 URL**: 调用 ` + "`POST /api/admin/storage/upload-url`" + `
2. **上传 CSV 文件**: 使用预签名 URL 上传文件到对象存储
3. **调用本接口**: 使用返回的 ` + "`file_key`" + ` 提交导入任务
### 请求示例
` + "```" + `json
{
"carrier_id": 1,
"batch_no": "BATCH-2025-01",
"file_key": "imports/2025/01/24/abc123.csv"
}
` + "```" + `
### CSV 文件格式
- 必须包含两列:` + "`iccid`" + `, ` + "`msisdn`" + `
- 首行为表头
- 编码UTF-8`,
Tags: []string{"IoT卡管理"},
Input: new(dto.ImportIotCardRequest),
Output: new(dto.ImportIotCardResponse),
Auth: true,
})
Register(iotCards, doc, groupPath, "GET", "/import-tasks", importHandler.List, RouteSpec{
Summary: "导入任务列表",
Tags: []string{"IoT卡管理"},
Input: new(dto.ListImportTaskRequest),
Output: new(dto.ListImportTaskResponse),
Auth: true,
})
Register(iotCards, doc, groupPath, "GET", "/import-tasks/:id", importHandler.GetByID, RouteSpec{
Summary: "导入任务详情",
Tags: []string{"IoT卡管理"},
Input: new(dto.GetImportTaskRequest),
Output: new(dto.ImportTaskDetailResponse),
Auth: true,
})
Register(iotCards, doc, groupPath, "POST", "/standalone/allocate", handler.AllocateCards, RouteSpec{
Summary: "批量分配单卡",
Tags: []string{"IoT卡管理"},
Input: new(dto.AllocateStandaloneCardsRequest),
Output: new(dto.AllocateStandaloneCardsResponse),
Auth: true,
})
Register(iotCards, doc, groupPath, "POST", "/standalone/recall", handler.RecallCards, RouteSpec{
Summary: "批量回收单卡",
Tags: []string{"IoT卡管理"},
Input: new(dto.RecallStandaloneCardsRequest),
Output: new(dto.RecallStandaloneCardsResponse),
Auth: true,
})
Register(iotCards, doc, groupPath, "PATCH", "/series-binding", handler.BatchSetSeriesBinding, RouteSpec{
Summary: "批量设置卡的套餐系列绑定",
Description: "批量设置或清除卡与套餐系列分配的关联关系。series_allocation_id 为 0 时表示清除关联。",
Tags: []string{"IoT卡管理"},
Input: new(dto.BatchSetCardSeriesBindngRequest),
Output: new(dto.BatchSetCardSeriesBindngResponse),
Auth: true,
})
}