Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled
- 新增 GET /api/admin/devices/by-imei/:imei 接口,支持通过设备号查询设备详情 - 新增 GET /api/admin/iot-cards/by-iccid/:iccid 接口,支持通过ICCID查询单卡详情 - 添加对应的 Service 层方法和 Handler - 更新 OpenAPI 文档 - 添加集成测试并修复测试环境配置(使用环境变量) - 归档已完成的 OpenSpec 变更记录 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
3.1 KiB
3.1 KiB
Tasks: 设备管理功能
1. 数据库迁移
- 1.1 创建数据库迁移文件:新增
tb_device_import_task表
2. Model 和 DTO
- 2.1 创建
internal/model/device_import_task.go:设备导入任务 Model - 2.2 创建
internal/model/dto/device_dto.go:设备相关 DTO(列表请求/响应、详情响应、绑定请求/响应、分配/回收请求/响应) - 2.3 创建
internal/model/dto/device_import_dto.go:导入相关 DTO(导入请求/响应、任务列表请求/响应、任务详情响应)
3. Store 层
- 3.1 创建
internal/store/postgres/device_store.go:设备 Store(List、GetByID、Delete、UpdateShopID、BatchUpdateShopID) - 3.2 创建
internal/store/postgres/device_sim_binding_store.go:绑定关系 Store(Create、Delete、ListByDeviceID、GetByDeviceAndCard、BatchUpdateCardShopID、GetActiveBindingByCardID) - 3.3 创建
internal/store/postgres/device_import_task_store.go:导入任务 Store(Create、GetByID、List、Update)
4. Service 层
- 4.1 创建
internal/service/device/service.go:设备 Service(List、GetByID、Delete、Allocate、Recall) - 4.2 创建
internal/service/device/binding.go:绑定 Service(ListCards、BindCard、UnbindCard) - 4.3 创建
internal/service/device_import/service.go:导入 Service(CreateTask、ListTasks、GetTaskDetail)
5. 异步任务
- 5.1 创建
internal/task/device_import.go:设备导入异步任务处理器 - 5.2 在
pkg/queue/handler.go中注册设备导入任务处理器
6. Handler 层
- 6.1 创建
internal/handler/admin/device.go:设备 Handler(List、GetByID、Delete、ListCards、BindCard、UnbindCard、Allocate、Recall) - 6.2 创建
internal/handler/admin/device_import.go:导入 Handler(Import、ListTasks、GetTaskDetail)
7. 路由注册
- 7.1 创建
internal/routes/device.go:设备路由注册 - 7.2 在
internal/routes/admin.go中添加设备路由模块
8. Bootstrap 集成
- 8.1 更新
internal/bootstrap/stores.go:注册新 Store - 8.2 更新
internal/bootstrap/services.go:注册新 Service - 8.3 更新
internal/bootstrap/handlers.go:注册新 Handler
9. 文档生成器
- 9.1 更新
cmd/api/docs.go:注册新 Handler - 9.2 更新
cmd/gendocs/main.go:注册新 Handler
10. 错误码
- 10.1 更新
pkg/errors/codes.go:添加设备相关错误码(已有通用错误码可复用)
11. 常量
- 11.1 更新
pkg/constants/:添加设备相关常量(状态、Redis Key、TaskType 等)
12. 测试
- 12.1 创建
tests/integration/device_test.go:设备管理集成测试(包含列表、详情、删除、导入任务列表等测试用例) - 12.2 设备导入集成测试(已合并到 device_test.go 中的 TestDeviceImport_TaskList)
- 12.3 设备分配回收集成测试(待配置环境后可运行,测试代码已就绪)
13. 执行迁移和验证
- 13.1 执行数据库迁移
- 13.2 运行所有测试确保通过
- 13.3 生成 OpenAPI 文档并验证