feat: 实现卡和设备的套餐系列绑定功能
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m37s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m37s
- 添加 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>
This commit is contained in:
@@ -106,6 +106,9 @@ func (s *DeviceStore) List(ctx context.Context, opts *store.QueryOptions, filter
|
||||
if createdAtEnd, ok := filters["created_at_end"].(time.Time); ok && !createdAtEnd.IsZero() {
|
||||
query = query.Where("created_at <= ?", createdAtEnd)
|
||||
}
|
||||
if seriesAllocationID, ok := filters["series_allocation_id"].(uint); ok && seriesAllocationID > 0 {
|
||||
query = query.Where("series_allocation_id = ?", seriesAllocationID)
|
||||
}
|
||||
|
||||
if err := query.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
@@ -181,3 +184,22 @@ func (s *DeviceStore) GetByDeviceNos(ctx context.Context, deviceNos []string) ([
|
||||
}
|
||||
return devices, nil
|
||||
}
|
||||
|
||||
// BatchUpdateSeriesAllocation 批量更新设备的套餐系列分配
|
||||
func (s *DeviceStore) BatchUpdateSeriesAllocation(ctx context.Context, deviceIDs []uint, seriesAllocationID *uint) error {
|
||||
if len(deviceIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.db.WithContext(ctx).Model(&model.Device{}).
|
||||
Where("id IN ?", deviceIDs).
|
||||
Update("series_allocation_id", seriesAllocationID).Error
|
||||
}
|
||||
|
||||
// ListBySeriesAllocationID 根据套餐系列分配ID查询设备列表
|
||||
func (s *DeviceStore) ListBySeriesAllocationID(ctx context.Context, seriesAllocationID uint) ([]*model.Device, error) {
|
||||
var devices []*model.Device
|
||||
if err := s.db.WithContext(ctx).Where("series_allocation_id = ?", seriesAllocationID).Find(&devices).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return devices, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user