This commit is contained in:
@@ -142,6 +142,23 @@ func (s *DeviceStore) List(ctx context.Context, opts *store.QueryOptions, filter
|
||||
return devices, total, nil
|
||||
}
|
||||
|
||||
// ListDeviceTypes 查询未删除设备的去重设备类型。
|
||||
func (s *DeviceStore) ListDeviceTypes(ctx context.Context) ([]string, error) {
|
||||
types := make([]string, 0)
|
||||
trimmedType := "TRIM(device_type)"
|
||||
err := s.db.WithContext(ctx).
|
||||
Model(&model.Device{}).
|
||||
Where("NULLIF("+trimmedType+", '') IS NOT NULL").
|
||||
Select(trimmedType).
|
||||
Distinct().
|
||||
Order(trimmedType+" ASC").
|
||||
Pluck(trimmedType, &types).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return types, nil
|
||||
}
|
||||
|
||||
func (s *DeviceStore) applyDeviceFilters(ctx context.Context, query *gorm.DB, filters map[string]any) *gorm.DB {
|
||||
if virtualNo, ok := filters["virtual_no"].(string); ok && virtualNo != "" {
|
||||
query = query.Where("virtual_no LIKE ?", "%"+virtualNo+"%")
|
||||
|
||||
Reference in New Issue
Block a user