ResolveLotCategoriesStrict переименован в ResolveLotCategories и лишён
строгости: лоты, отсутствующие в прайслисте или с пустой lot_category,
просто пропускаются — партномер из них не собирается. Ранее любой
«незнакомый» лот возвращал ошибку и блокировал сохранение конфига.
Удалены ErrMissingCategoryForLot, MissingCategoryForLotError и
fallback через local_components (противоречил cc72052).
resolvePricelistID: если прайслист отсутствует локально после синка —
fallback на последний активный вместо ошибки.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
85 lines
2.0 KiB
Go
85 lines
2.0 KiB
Go
package article
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"git.mchus.pro/mchus/quoteforge/internal/localdb"
|
|
)
|
|
|
|
type Group string
|
|
|
|
const (
|
|
GroupCPU Group = "CPU"
|
|
GroupMEM Group = "MEM"
|
|
GroupGPU Group = "GPU"
|
|
GroupDISK Group = "DISK"
|
|
GroupNET Group = "NET"
|
|
GroupPSU Group = "PSU"
|
|
)
|
|
|
|
// GroupForLotCategory maps pricelist lot_category codes into article groups.
|
|
// Unknown/unrelated categories return ok=false.
|
|
func GroupForLotCategory(cat string) (group Group, ok bool) {
|
|
c := strings.ToUpper(strings.TrimSpace(cat))
|
|
switch c {
|
|
case "CPU":
|
|
return GroupCPU, true
|
|
case "MEM":
|
|
return GroupMEM, true
|
|
case "GPU":
|
|
return GroupGPU, true
|
|
case "M2", "SSD", "HDD", "EDSFF", "HHHL":
|
|
return GroupDISK, true
|
|
case "NIC", "HCA", "DPU":
|
|
return GroupNET, true
|
|
case "HBA":
|
|
return GroupNET, true
|
|
case "PSU", "PS":
|
|
return GroupPSU, true
|
|
default:
|
|
return "", false
|
|
}
|
|
}
|
|
|
|
// ResolveLotCategories returns lot_category for each lotName found in local_pricelist_items
|
|
// for the given server pricelist. Lots not found in the pricelist are omitted from the result —
|
|
// callers must treat a missing key as "no category" and skip that lot.
|
|
func ResolveLotCategories(local *localdb.LocalDB, serverPricelistID uint, lotNames []string) (map[string]string, error) {
|
|
if local == nil {
|
|
return nil, fmt.Errorf("local db is nil")
|
|
}
|
|
cats, err := local.GetLocalLotCategoriesByServerPricelistID(serverPricelistID, lotNames)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
for lot, cat := range cats {
|
|
cats[lot] = strings.TrimSpace(cat)
|
|
}
|
|
return cats, nil
|
|
}
|
|
|
|
// NormalizeServerModel produces a stable article segment for the server model.
|
|
func NormalizeServerModel(model string) string {
|
|
trimmed := strings.TrimSpace(model)
|
|
if trimmed == "" {
|
|
return ""
|
|
}
|
|
upper := strings.ToUpper(trimmed)
|
|
var b strings.Builder
|
|
for _, r := range upper {
|
|
if r >= 'A' && r <= 'Z' {
|
|
b.WriteRune(r)
|
|
continue
|
|
}
|
|
if r >= '0' && r <= '9' {
|
|
b.WriteRune(r)
|
|
continue
|
|
}
|
|
if r == '.' {
|
|
b.WriteRune(r)
|
|
}
|
|
}
|
|
return b.String()
|
|
}
|