Добавлены сортировка по категориям, секции PCI и автосохранение

Основные изменения:

1. CSV экспорт и веб-интерфейс:
   - Компоненты теперь сортируются по иерархии категорий (display_order)
   - Категории отображаются в правильном порядке: BB, CPU, MEM, GPU и т.д.
   - Компоненты без категории отображаются в конце

2. Раздел PCI в конфигураторе:
   - Разделен на секции: GPU/DPU, NIC/HCA, HBA
   - Улучшена навигация и выбор компонентов

3. Сохранение "своей цены":
   - Добавлено поле custom_price в модель Configuration
   - Создана миграция 002_add_custom_price.sql
   - "Своя цена" сохраняется при сохранении конфигурации
   - При загрузке конфигурации восстанавливается сохраненная цена

4. Автосохранение:
   - Конфигурация автоматически сохраняется через 1 секунду после изменений
   - Debounce предотвращает избыточные запросы
   - Автосохранение работает для всех изменений (компоненты, количество, цена)

5. Дополнительно:
   - Добавлен cmd/importer для импорта метаданных из таблицы lot
   - Создан скрипт apply_migration.sh для применения миграций
   - Оптимизирована работа с категориями в ExportService

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Mikhail Chusavitin
2026-01-30 17:48:44 +03:00
parent db37040399
commit d32b1c5d0c
16 changed files with 971 additions and 168 deletions

View File

@@ -1,7 +1,6 @@
package services
import (
"encoding/json"
"errors"
"github.com/google/uuid"
@@ -33,23 +32,25 @@ func NewConfigurationService(
}
type CreateConfigRequest struct {
Name string `json:"name"`
Items models.ConfigItems `json:"items"`
Notes string `json:"notes"`
IsTemplate bool `json:"is_template"`
Name string `json:"name"`
Items models.ConfigItems `json:"items"`
CustomPrice *float64 `json:"custom_price"`
Notes string `json:"notes"`
IsTemplate bool `json:"is_template"`
}
func (s *ConfigurationService) Create(userID uint, req *CreateConfigRequest) (*models.Configuration, error) {
total := req.Items.Total()
config := &models.Configuration{
UUID: uuid.New().String(),
UserID: userID,
Name: req.Name,
Items: req.Items,
TotalPrice: &total,
Notes: req.Notes,
IsTemplate: req.IsTemplate,
UUID: uuid.New().String(),
UserID: userID,
Name: req.Name,
Items: req.Items,
TotalPrice: &total,
CustomPrice: req.CustomPrice,
Notes: req.Notes,
IsTemplate: req.IsTemplate,
}
if err := s.configRepo.Create(config); err != nil {
@@ -91,6 +92,7 @@ func (s *ConfigurationService) Update(uuid string, userID uint, req *CreateConfi
config.Name = req.Name
config.Items = req.Items
config.TotalPrice = &total
config.CustomPrice = req.CustomPrice
config.Notes = req.Notes
config.IsTemplate = req.IsTemplate
@@ -133,6 +135,33 @@ func (s *ConfigurationService) Rename(uuid string, userID uint, newName string)
return config, nil
}
func (s *ConfigurationService) Clone(configUUID string, userID uint, newName string) (*models.Configuration, error) {
original, err := s.GetByUUID(configUUID, userID)
if err != nil {
return nil, err
}
// Create copy with new UUID and name
total := original.Items.Total()
clone := &models.Configuration{
UUID: uuid.New().String(),
UserID: userID,
Name: newName,
Items: original.Items,
TotalPrice: &total,
CustomPrice: original.CustomPrice,
Notes: original.Notes,
IsTemplate: false, // Clone is never a template
}
if err := s.configRepo.Create(clone); err != nil {
return nil, err
}
return clone, nil
}
func (s *ConfigurationService) ListByUser(userID uint, page, perPage int) ([]models.Configuration, int64, error) {
if page < 1 {
page = 1
@@ -157,39 +186,39 @@ func (s *ConfigurationService) ListTemplates(page, perPage int) ([]models.Config
return s.configRepo.ListTemplates(offset, perPage)
}
// Export configuration as JSON
type ConfigExport struct {
Name string `json:"name"`
Notes string `json:"notes"`
Items models.ConfigItems `json:"items"`
}
func (s *ConfigurationService) ExportJSON(uuid string, userID uint) ([]byte, error) {
config, err := s.GetByUUID(uuid, userID)
if err != nil {
return nil, err
}
export := ConfigExport{
Name: config.Name,
Notes: config.Notes,
Items: config.Items,
}
return json.MarshalIndent(export, "", " ")
}
func (s *ConfigurationService) ImportJSON(userID uint, data []byte) (*models.Configuration, error) {
var export ConfigExport
if err := json.Unmarshal(data, &export); err != nil {
return nil, err
}
req := &CreateConfigRequest{
Name: export.Name,
Notes: export.Notes,
Items: export.Items,
}
return s.Create(userID, req)
}
// // Export configuration as JSON
// type ConfigExport struct {
// Name string `json:"name"`
// Notes string `json:"notes"`
// Items models.ConfigItems `json:"items"`
// }
//
// func (s *ConfigurationService) ExportJSON(uuid string, userID uint) ([]byte, error) {
// config, err := s.GetByUUID(uuid, userID)
// if err != nil {
// return nil, err
// }
//
// export := ConfigExport{
// Name: config.Name,
// Notes: config.Notes,
// Items: config.Items,
// }
//
// return json.MarshalIndent(export, "", " ")
// }
//
// func (s *ConfigurationService) ImportJSON(userID uint, data []byte) (*models.Configuration, error) {
// var export ConfigExport
// if err := json.Unmarshal(data, &export); err != nil {
// return nil, err
// }
//
// req := &CreateConfigRequest{
// Name: export.Name,
// Notes: export.Notes,
// Items: export.Items,
// }
//
// return s.Create(userID, req)
// }