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

Иерархия групп работает
Полностью завязано на пользователя и серверы
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

@@ -100,9 +100,11 @@ func (r *pgRepository) GetActiveServer(userID uuid.UUID) (*account.RMSServer, er
return &server, nil
}
// GetAllServers возвращает ВСЕ серверы пользователя, чтобы можно было переключаться
func (r *pgRepository) GetAllServers(userID uuid.UUID) ([]account.RMSServer, error) {
var servers []account.RMSServer
err := r.db.Where("user_id = ? AND is_active = ?", userID, true).Find(&servers).Error
// Убрали фильтр AND is_active = true, теперь возвращает весь список
err := r.db.Where("user_id = ?", userID).Find(&servers).Error
return servers, err
}

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
}

View File

@@ -60,6 +60,14 @@ func (r *pgRepository) CreateItems(items []drafts.DraftInvoiceItem) error {
return r.db.CreateInBatches(items, 100).Error
}
func (r *pgRepository) CreateItem(item *drafts.DraftInvoiceItem) error {
return r.db.Create(item).Error
}
func (r *pgRepository) DeleteItem(itemID uuid.UUID) error {
return r.db.Delete(&drafts.DraftInvoiceItem{}, itemID).Error
}
func (r *pgRepository) UpdateItem(itemID uuid.UUID, productID *uuid.UUID, containerID *uuid.UUID, qty, price decimal.Decimal) error {
sum := qty.Mul(price)
isMatched := productID != nil