# Tasks: 单卡资产分配功能 ## 1. DTO 定义 - [x] 1.1 创建 AllocateStandaloneCardsRequest DTO(支持三种选卡方式) - [x] 1.2 创建 AllocateStandaloneCardsResponse DTO(返回成功/失败统计) - [x] 1.3 创建 RecallStandaloneCardsRequest DTO - [x] 1.4 创建 RecallStandaloneCardsResponse DTO - [x] 1.5 创建 ListAssetAllocationRecordRequest DTO - [x] 1.6 创建 AssetAllocationRecordResponse DTO - [x] 1.7 创建 ListAssetAllocationRecordResponse DTO ## 2. Store 层 - [x] 2.1 创建 AssetAllocationRecordStore - [x] 2.1.1 实现 Create 方法 - [x] 2.1.2 实现 BatchCreate 方法 - [x] 2.1.3 实现 GetByID 方法 - [x] 2.1.4 实现 List 方法(支持筛选和分页) - [x] 2.2 实现 IotCardStore.BatchUpdateShopIDAndStatus 方法 - [x] 2.3 实现 IotCardStore.GetStandaloneByICCIDRange 方法(号段查询) - [x] 2.4 实现 IotCardStore.GetStandaloneByFilters 方法(筛选条件查询,排除已绑定设备的卡) - [x] 2.5 实现 IotCardStore.GetByICCIDs 方法 - [x] 2.6 实现 IotCardStore.GetBoundCardIDs 方法 ## 3. Service 层 - [x] 3.1 创建 AssetAllocationRecordService - [x] 3.1.1 实现 List 方法 - [x] 3.1.2 实现 GetByID 方法 - [x] 3.2 实现 IotCardService.AllocateCards 方法 - [x] 3.2.1 校验目标店铺是当前用户的直属下级 - [x] 3.2.2 根据选卡方式获取待分配的卡列表 - [x] 3.2.3 校验卡是单卡(未绑定设备) - [x] 3.2.4 校验卡状态和所有权 - [x] 3.2.5 批量更新 shop_id 和 status - [x] 3.2.6 创建分配记录 - [x] 3.3 实现 IotCardService.RecallCards 方法 - [x] 3.3.1 校验来源店铺是当前用户的直属下级 - [x] 3.3.2 根据选卡方式获取待回收的卡列表 - [x] 3.3.3 校验卡是单卡(未绑定设备) - [x] 3.3.4 批量更新 shop_id(平台→NULL,店铺→回收方ID)和 status - [x] 3.3.5 创建回收记录 ## 4. Handler 层 - [x] 4.1 创建 AssetAllocationRecordHandler - [x] 4.1.1 实现 List 方法 - [x] 4.1.2 实现 GetByID 方法 - [x] 4.2 实现 IotCardHandler.AllocateCards 方法 - [x] 4.3 实现 IotCardHandler.RecallCards 方法 ## 5. 路由注册 - [x] 5.1 注册 POST /api/admin/iot-cards/standalone/allocate - [x] 5.2 注册 POST /api/admin/iot-cards/standalone/recall - [x] 5.3 注册 GET /api/admin/asset-allocation-records - [x] 5.4 注册 GET /api/admin/asset-allocation-records/:id - [x] 5.5 更新 Bootstrap(handlers.go、services.go、stores.go、types.go) - [x] 5.6 更新文档生成器(cmd/api/docs.go 和 cmd/gendocs/main.go) ## 6. 测试 - [x] 6.1 AssetAllocationRecordStore 单元测试 - [x] 6.2 IotCardStore.BatchUpdateShopIDAndStatus 单元测试 - [x] 6.3 IotCardStore.GetStandaloneByICCIDRange 单元测试 - [x] 6.4 IotCardStore.GetStandaloneByFilters 单元测试 - [x] 6.5 IotCardStore.GetByICCIDs 单元测试 - [x] 6.6 IotCardStore.GetBoundCardIDs 单元测试 - [x] 6.7 分配 API 集成测试(TestStandaloneCardAllocation_AllocateByList) - [x] 6.8 回收 API 集成测试(TestStandaloneCardAllocation_Recall) - [x] 6.9 分配记录查询 API 集成测试(TestAssetAllocationRecord_List) ## 7. 文档更新 - [x] 7.1 同步 delta spec 到主规范