Настройки работают

Иерархия групп работает
Полностью завязано на пользователя и серверы
This commit is contained in:
2025-12-18 07:21:31 +03:00
parent 542beafe0e
commit 4e4571b3db
23 changed files with 1572 additions and 385 deletions

View File

@@ -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
}