From f6766ce6b8bcb4409ec6ef721facf4e2433f944c Mon Sep 17 00:00:00 2001 From: Mikhail Chusavitin Date: Mon, 29 Jun 2026 11:56:59 +0300 Subject: [PATCH] =?UTF-8?q?refactor:=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D0=BC=D1=91=D1=80=D1=82=D0=B2=D1=8B=D0=B9=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=B4=20qt=5Flot=5Fmetadata?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Таблица qt_lot_metadata не использовалась в рантайме — ни один репозиторий/сервис/хендлер к ней не обращался. - удалён models/metadata.go (LotMetadata, Specs, PriceMethod, PriceFreshness) - удалена LocalToComponent() из localdb/converters.go - убран &LotMetadata{} из AutoMigrate - убраны мёртвые поля PriceFreshness/PopularityScore/Specs из ComponentView Co-Authored-By: Claude Sonnet 4.6 --- internal/localdb/converters.go | 11 ---- internal/models/metadata.go | 92 ---------------------------------- internal/models/models.go | 1 - internal/services/component.go | 17 ++----- 4 files changed, 5 insertions(+), 116 deletions(-) delete mode 100644 internal/models/metadata.go diff --git a/internal/localdb/converters.go b/internal/localdb/converters.go index 92ba8ca..5f0106f 100644 --- a/internal/localdb/converters.go +++ b/internal/localdb/converters.go @@ -330,14 +330,3 @@ func LocalToPricelistItem(local *LocalPricelistItem, serverPricelistID uint) *mo } } -// LocalToComponent converts LocalComponent to models.LotMetadata -func LocalToComponent(local *LocalComponent) *models.LotMetadata { - return &models.LotMetadata{ - LotName: local.LotName, - Model: local.Model, - Lot: &models.Lot{ - LotName: local.LotName, - LotDescription: local.LotDescription, - }, - } -} diff --git a/internal/models/metadata.go b/internal/models/metadata.go deleted file mode 100644 index 3e448ff..0000000 --- a/internal/models/metadata.go +++ /dev/null @@ -1,92 +0,0 @@ -package models - -import ( - "database/sql/driver" - "encoding/json" - "errors" - "time" -) - -type PriceMethod string - -const ( - PriceMethodManual PriceMethod = "manual" - PriceMethodMedian PriceMethod = "median" - PriceMethodAverage PriceMethod = "average" - PriceMethodWeightedMedian PriceMethod = "weighted_median" -) - -type Specs map[string]interface{} - -func (s Specs) Value() (driver.Value, error) { - return json.Marshal(s) -} - -func (s *Specs) Scan(value interface{}) error { - if value == nil { - *s = make(Specs) - return nil - } - bytes, ok := value.([]byte) - if !ok { - return errors.New("type assertion to []byte failed") - } - return json.Unmarshal(bytes, s) -} - -type LotMetadata struct { - LotName string `gorm:"column:lot_name;primaryKey;size:255" json:"lot_name"` - CategoryID *uint `gorm:"column:category_id" json:"category_id"` - Model string `gorm:"size:100" json:"model"` - Specs Specs `gorm:"type:json" json:"specs"` - CurrentPrice *float64 `gorm:"type:decimal(12,2)" json:"current_price"` - PriceMethod PriceMethod `gorm:"type:enum('manual','median','average','weighted_median');default:'median'" json:"price_method"` - PricePeriodDays int `gorm:"default:90" json:"price_period_days"` - PriceCoefficient float64 `gorm:"type:decimal(5,2);default:0" json:"price_coefficient"` - ManualPrice *float64 `gorm:"type:decimal(12,2)" json:"manual_price"` - PriceUpdatedAt *time.Time `json:"price_updated_at"` - RequestCount int `gorm:"default:0" json:"request_count"` - LastRequestDate *time.Time `gorm:"type:date" json:"last_request_date"` - PopularityScore float64 `gorm:"type:decimal(10,4);default:0" json:"popularity_score"` - MetaPrices string `gorm:"size:1000" json:"meta_prices"` - MetaMethod string `gorm:"size:20" json:"meta_method"` - MetaPeriodDays int `gorm:"default:90" json:"meta_period_days"` - IsHidden bool `gorm:"default:false" json:"is_hidden"` - - // Relations - Lot *Lot `gorm:"foreignKey:LotName;references:LotName" json:"lot,omitempty"` - Category *Category `gorm:"foreignKey:CategoryID" json:"category,omitempty"` -} - -func (LotMetadata) TableName() string { - return "qt_lot_metadata" -} - -type PriceFreshness string - -const ( - FreshnessFresh PriceFreshness = "fresh" - FreshnessNormal PriceFreshness = "normal" - FreshnessStale PriceFreshness = "stale" - FreshnessCritical PriceFreshness = "critical" -) - -func (m *LotMetadata) GetPriceFreshness(greenDays, yellowDays, redDays, minQuotes int) PriceFreshness { - if m.CurrentPrice == nil || *m.CurrentPrice == 0 { - return FreshnessCritical - } - if m.PriceUpdatedAt == nil { - return FreshnessCritical - } - - daysSince := int(time.Since(*m.PriceUpdatedAt).Hours() / 24) - - if daysSince < greenDays && m.RequestCount >= minQuotes { - return FreshnessFresh - } else if daysSince < yellowDays { - return FreshnessNormal - } else if daysSince < redDays { - return FreshnessStale - } - return FreshnessCritical -} diff --git a/internal/models/models.go b/internal/models/models.go index 7e696ba..e2a2a9b 100644 --- a/internal/models/models.go +++ b/internal/models/models.go @@ -11,7 +11,6 @@ import ( func AllModels() []interface{} { return []interface{}{ &Category{}, - &LotMetadata{}, &Project{}, &Configuration{}, &Pricelist{}, diff --git a/internal/services/component.go b/internal/services/component.go index b4fd02f..f31c0f0 100644 --- a/internal/services/component.go +++ b/internal/services/component.go @@ -1,9 +1,5 @@ package services -import ( - "git.mchus.pro/mchus/quoteforge/internal/models" -) - type ComponentListResult struct { Items []ComponentView `json:"items"` TotalCount int64 `json:"total_count"` @@ -13,12 +9,9 @@ type ComponentListResult struct { } type ComponentView struct { - LotName string `json:"lot_name"` - Description string `json:"description"` - Category string `json:"category"` - CategoryName string `json:"category_name"` - Model string `json:"model"` - PriceFreshness models.PriceFreshness `json:"price_freshness"` - PopularityScore float64 `json:"popularity_score"` - Specs models.Specs `json:"specs,omitempty"` + LotName string `json:"lot_name"` + Description string `json:"description"` + Category string `json:"category"` + CategoryName string `json:"category_name"` + Model string `json:"model"` }