feat: 实现运营商模块重构,添加冗余字段优化查询性能
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m16s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m16s
主要变更: - 新增 Carrier CRUD API(创建、列表、详情、更新、删除、状态更新) - IotCard/IotCardImportTask 添加 carrier_type/carrier_name 冗余字段 - 移除 Carrier 表的 channel_name/channel_code 字段 - 查询时直接使用冗余字段,避免 JOIN Carrier 表 - 添加数据库迁移脚本(000021-000023) - 添加单元测试和集成测试 - 同步更新 OpenAPI 文档和 specs
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
## 1. 数据库迁移
|
||||
|
||||
- [x] 1.1 创建迁移文件:Carrier 表移除 channel_name、channel_code 字段及 idx_carrier_type_channel 索引
|
||||
- [x] 1.2 创建迁移文件:IotCard 表添加 carrier_type、carrier_name 冗余字段,并从 Carrier 表填充现有数据
|
||||
- [x] 1.3 创建迁移文件:IotCardImportTask 表添加 carrier_name 冗余字段,并从 Carrier 表填充现有数据
|
||||
- [x] 1.4 执行迁移,验证数据完整性
|
||||
|
||||
## 2. Model 层修改
|
||||
|
||||
- [x] 2.1 修改 `internal/model/carrier.go`:移除 ChannelName、ChannelCode 字段
|
||||
- [x] 2.2 修改 `internal/model/iot_card.go`:添加 CarrierType、CarrierName 字段
|
||||
- [x] 2.3 修改 `internal/model/iot_card_import_task.go`:添加 CarrierName 字段
|
||||
|
||||
## 3. DTO 层
|
||||
|
||||
- [x] 3.1 创建 `internal/model/dto/carrier_dto.go`:定义 CreateCarrierRequest、UpdateCarrierRequest、CarrierListRequest、UpdateCarrierStatusRequest、CarrierResponse
|
||||
- [x] 3.2 修改 `internal/model/dto/iot_card_dto.go`:响应结构添加 carrier_type 字段(如果缺失)
|
||||
- [x] 3.3 修改 `internal/model/dto/iot_card_import_dto.go`:响应结构确认包含 carrier_name 字段
|
||||
|
||||
## 4. Store 层
|
||||
|
||||
- [x] 4.1 创建 `internal/store/postgres/carrier_store.go`:实现 Create、GetByID、Update、Delete、List、GetByCode 方法
|
||||
|
||||
## 5. Service 层
|
||||
|
||||
- [x] 5.1 创建 `internal/service/carrier/service.go`:实现 Create、Get、Update、Delete、List、UpdateStatus 业务逻辑
|
||||
- [x] 5.2 修改 `internal/service/iot_card_import/service.go`:创建导入任务时填充 carrier_name;处理卡片时填充 carrier_type、carrier_name
|
||||
- [x] 5.3 修改 `internal/service/iot_card/service.go`:移除 loadCarrierData / loadRelatedData 中的 Carrier JOIN 逻辑,直接使用 IotCard 自身字段
|
||||
- [x] 5.4 修改 `internal/service/device/binding.go`:移除 loadCarrierData 方法,直接使用 IotCard 的 carrier_name 字段
|
||||
|
||||
## 6. Handler 层
|
||||
|
||||
- [x] 6.1 创建 `internal/handler/admin/carrier.go`:实现 Create、Get、Update、Delete、List、UpdateStatus 接口
|
||||
|
||||
## 7. 路由注册
|
||||
|
||||
- [x] 7.1 创建 `internal/routes/carrier.go`:注册 /api/admin/carriers 路由组
|
||||
- [x] 7.2 更新 `internal/routes/admin.go`:调用 Carrier 路由注册
|
||||
|
||||
## 8. Bootstrap 注册
|
||||
|
||||
- [x] 8.1 修改 `internal/bootstrap/stores.go`:注册 CarrierStore
|
||||
- [x] 8.2 修改 `internal/bootstrap/services.go`:注册 CarrierService
|
||||
- [x] 8.3 修改 `internal/bootstrap/handlers.go`:注册 CarrierHandler
|
||||
|
||||
## 9. 常量定义
|
||||
|
||||
- [x] 9.1 在 `pkg/constants/` 中添加 CarrierType 枚举常量
|
||||
- [x] 9.2 在 `pkg/errors/codes.go` 中添加 Carrier 相关错误码(CodeCarrierNotFound、CodeCarrierCodeExists 等)
|
||||
|
||||
## 10. 测试
|
||||
|
||||
- [x] 10.1 编写 CarrierStore 单元测试
|
||||
- [x] 10.2 编写 CarrierService 单元测试
|
||||
- [x] 10.3 编写 Carrier API 集成测试
|
||||
- [x] 10.4 验证 IotCard 导入流程正确填充冗余字段(通过 TestIotCard_CarrierRedundantFields 验证)
|
||||
- [x] 10.5 验证 IotCard 查询响应正确返回冗余字段(通过 TestIotCard_GetByICCID 验证)
|
||||
|
||||
## 11. 文档更新
|
||||
|
||||
- [x] 11.1 更新 API 文档生成器(docs.go / gendocs/main.go)注册 CarrierHandler
|
||||
- [x] 11.2 运行 `go run cmd/gendocs/main.go` 生成 OpenAPI 文档
|
||||
Reference in New Issue
Block a user