mirror of
https://github.com/serty2005/rmser.git
synced 2026-02-05 03:12:34 -06:00
Настройки работают
Иерархия групп работает Полностью завязано на пользователя и серверы
This commit is contained in:
@@ -86,14 +86,25 @@ func (r *pgRepository) GetAll() ([]catalog.Product, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (r *pgRepository) GetActiveGoods(serverID uuid.UUID) ([]catalog.Product, error) {
|
||||
func (r *pgRepository) GetActiveGoods(serverID uuid.UUID, rootGroupID *uuid.UUID) ([]catalog.Product, error) {
|
||||
var products []catalog.Product
|
||||
err := r.db.
|
||||
Preload("MainUnit").
|
||||
Preload("Containers").
|
||||
Where("rms_server_id = ? AND is_deleted = ? AND type IN ?", serverID, false, []string{"GOODS"}).
|
||||
Order("name ASC").
|
||||
Find(&products).Error
|
||||
db := r.db.Preload("MainUnit").Preload("Containers").
|
||||
Where("rms_server_id = ? AND is_deleted = ? AND type IN ?", serverID, false, []string{"GOODS"})
|
||||
|
||||
if rootGroupID != nil && *rootGroupID != uuid.Nil {
|
||||
// Используем Recursive CTE для поиска всех дочерних элементов папки
|
||||
subQuery := r.db.Raw(`
|
||||
WITH RECURSIVE subnodes AS (
|
||||
SELECT id FROM products WHERE id = ?
|
||||
UNION ALL
|
||||
SELECT p.id FROM products p INNER JOIN subnodes s ON p.parent_id = s.id
|
||||
)
|
||||
SELECT id FROM subnodes
|
||||
`, rootGroupID)
|
||||
db = db.Where("id IN (?)", subQuery)
|
||||
}
|
||||
|
||||
err := db.Order("name ASC").Find(&products).Error
|
||||
return products, err
|
||||
}
|
||||
|
||||
@@ -103,19 +114,27 @@ func (r *pgRepository) GetActiveStores(serverID uuid.UUID) ([]catalog.Store, err
|
||||
return stores, err
|
||||
}
|
||||
|
||||
func (r *pgRepository) Search(serverID uuid.UUID, query string) ([]catalog.Product, error) {
|
||||
func (r *pgRepository) Search(serverID uuid.UUID, query string, rootGroupID *uuid.UUID) ([]catalog.Product, error) {
|
||||
var products []catalog.Product
|
||||
q := "%" + query + "%"
|
||||
|
||||
err := r.db.
|
||||
Preload("MainUnit").
|
||||
Preload("Containers").
|
||||
db := r.db.Preload("MainUnit").Preload("Containers").
|
||||
Where("rms_server_id = ? AND is_deleted = ? AND type = ?", serverID, false, "GOODS").
|
||||
Where("name ILIKE ? OR code ILIKE ? OR num ILIKE ?", q, q, q).
|
||||
Order("name ASC").
|
||||
Limit(20).
|
||||
Find(&products).Error
|
||||
Where("(name ILIKE ? OR code ILIKE ? OR num ILIKE ?)", q, q, q)
|
||||
|
||||
if rootGroupID != nil && *rootGroupID != uuid.Nil {
|
||||
subQuery := r.db.Raw(`
|
||||
WITH RECURSIVE subnodes AS (
|
||||
SELECT id FROM products WHERE id = ?
|
||||
UNION ALL
|
||||
SELECT p.id FROM products p INNER JOIN subnodes s ON p.parent_id = s.id
|
||||
)
|
||||
SELECT id FROM subnodes
|
||||
`, rootGroupID)
|
||||
db = db.Where("id IN (?)", subQuery)
|
||||
}
|
||||
|
||||
err := db.Order("name ASC").Limit(20).Find(&products).Error
|
||||
return products, err
|
||||
}
|
||||
|
||||
@@ -176,3 +195,12 @@ func (r *pgRepository) CountStores(serverID uuid.UUID) (int64, error) {
|
||||
Count(&count).Error
|
||||
return count, err
|
||||
}
|
||||
|
||||
func (r *pgRepository) GetGroups(serverID uuid.UUID) ([]catalog.Product, error) {
|
||||
var groups []catalog.Product
|
||||
// iiko присылает группы с типом "GROUP"
|
||||
err := r.db.Where("rms_server_id = ? AND type = ? AND is_deleted = ?", serverID, "GROUP", false).
|
||||
Order("name ASC").
|
||||
Find(&groups).Error
|
||||
return groups, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user