Files
junhong_cmp_fiber/openspec/changes/archive/2026-01-23-iot-card-standalone-management/tasks.md
huang a924e63e68
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 4m42s
feat: 实现物联网卡独立管理和批量导入功能
新增物联网卡独立管理模块,支持单卡查询、批量导入和状态管理。主要变更包括:

功能特性:
- 新增物联网卡 CRUD 接口(查询、分页列表、删除)
- 支持 CSV/Excel 批量导入物联网卡
- 实现异步导入任务处理和进度跟踪
- 新增 ICCID 号码格式校验器(支持 Luhn 算法)
- 新增 CSV 文件解析工具(支持编码检测和错误处理)

数据库变更:
- 移除 iot_card 和 device 表的 owner_id/owner_type 字段
- 新增 iot_card_import_task 导入任务表
- 为导入任务添加运营商类型字段

测试覆盖:
- 新增 IoT 卡 Store 层单元测试
- 新增 IoT 卡导入任务单元测试
- 新增 IoT 卡集成测试(包含导入流程测试)
- 新增 CSV 工具和 ICCID 校验器测试

文档更新:
- 更新 OpenAPI 文档(新增 7 个 IoT 卡接口)
- 归档 OpenSpec 变更提案
- 更新 API 文档规范和生成器指南

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-24 11:03:43 +08:00

76 lines
2.9 KiB
Markdown
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.
# Tasks: IoT 卡单卡管理与所有权模型重构
## 1. 模型重构(清理 Owner 字段)
- [x] 1.1 修改 IotCard 模型:移除 OwnerType、OwnerID 字段
- [x] 1.2 修改 Device 模型:移除 OwnerType、OwnerID 字段
- [x] 1.3 创建数据库迁移:删除 tb_iot_card 的 owner_type、owner_id 列
- [x] 1.4 创建数据库迁移:删除 tb_device 的 owner_type、owner_id 列
- [x] 1.5 更新相关 DTO移除 OwnerType、OwnerID 相关字段
- [x] 1.6 更新相关 Service/Store移除 Owner 相关逻辑,改用 ShopID
## 2. 导入任务模型
- [x] 2.1 创建 IotCardImportTask 模型
- [x] 2.2 创建数据库迁移tb_iot_card_import_task 表
- [x] 2.3 创建 IotCardImportTaskStore
- [x] 2.4 创建导入任务相关 DTO
## 3. ICCID 校验逻辑
- [x] 3.1 在 pkg/validator 中添加 ICCID 校验函数
- [x] 3.2 实现根据运营商校验 ICCID 长度电信19位其他20位
- [x] 3.3 支持字母数字混合校验(移动有字母)
- [x] 3.4 更新现有导入逻辑使用新校验函数
## 4. 单卡列表 API
- [x] 4.1 创建单卡列表查询 DTO请求/响应)
- [x] 4.2 实现 IotCardStore.ListStandalone 方法(未绑定设备的卡)
- [x] 4.3 实现 IotCardService.ListStandalone 方法
- [x] 4.4 实现 IotCardHandler.ListStandalone 方法
- [x] 4.5 注册路由 GET /api/admin/iot-cards/standalone
## 5. 批量导入 API
- [x] 5.1 创建导入请求 DTO含 CSV 文件上传)
- [x] 5.2 实现 CSV 解析逻辑
- [x] 5.3 实现 IotCardImportService.CreateImportTask 方法
- [x] 5.4 实现 IotCardImportHandler.Import 方法
- [x] 5.5 注册路由 POST /api/admin/iot-cards/import
## 6. 异步导入 Worker
- [x] 6.1 创建 IotCardImportTask Asynq 任务类型
- [x] 6.2 实现 IotCardImportHandlerWorker 处理器)
- [x] 6.3 实现分批处理逻辑1000条/批)
- [x] 6.4 实现 ICCID 去重检查
- [x] 6.5 实现进度更新和结果记录
## 7. 导入任务查询 API
- [x] 7.1 创建导入任务列表查询 DTO
- [x] 7.2 创建导入任务详情 DTO
- [x] 7.3 实现 IotCardImportTaskService.List 方法
- [x] 7.4 实现 IotCardImportTaskService.GetByID 方法
- [x] 7.5 实现 IotCardImportTaskHandler.List 方法
- [x] 7.6 实现 IotCardImportTaskHandler.GetByID 方法
- [x] 7.7 注册路由 GET /api/admin/iot-cards/import-tasks
- [x] 7.8 注册路由 GET /api/admin/iot-cards/import-tasks/:id
## 8. 测试
- [x] 8.1 IotCardStore.ListStandalone 单元测试
- [x] 8.2 ICCID 校验函数单元测试
- [x] 8.3 CSV 解析逻辑单元测试
- [x] 8.4 导入 Worker 单元测试
- [x] 8.5 单卡列表 API 集成测试
- [x] 8.6 批量导入 API 集成测试
## 9. 文档和规范更新
- [x] 9.1 更新 iot-card/spec.md同步 delta 变更)
- [x] 9.2 更新 iot-device/spec.md同步 delta 变更)
- [x] 9.3 创建 iot-card-import-task/spec.md
- [x] 9.4 更新 API 文档(通过 openspec archive 自动完成)