Files
backend_v2/internal/pkg/season/season.go
toom1996 10d8a96e8c update
2026-09-07 00:04:01 +08:00

72 lines
1.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Package season 走秀季节 / 年份 → season_code 的推导与解析辅助。
//
// season_code 是对外与排序共用的紧凑编码:SS26 / FW25 / RES26 / PF25,
// 规则:前缀由 collection_type(rtw/menswear→SS/FW;resort→RES;pre_fall→PF)
// 或 season(spring→SS / fall→FW)决定,后缀为两位年份。
// 历史代码 vogue.go 漏填 season_code 是已知 bug,这里集中推导逻辑,worker 与回填脚本复用。
package season
import (
"strconv"
)
// CollectionType / Season 取值白名单。
const (
ColRTW = "rtw"
ColMenswear = "menswear"
ColCouture = "couture"
ColResort = "resort"
ColPreFall = "pre_fall"
SeasonSpring = "spring"
SeasonFall = "fall"
)
// Derive 由年份 + 系列/季节推导 season_code(如 2026 + spring → "SS26")。
//
// 优先级:collection_type 先在(resort→RES、pre_fall→PF);否则用 season
// (spring→SS、fall→FW);二者皆空或无法识别时回落 "SS"。
// year 为 0 时返回空串(未知年份无法编码)。
func Derive(year uint16, collectionType, season string) string {
if year == 0 {
return ""
}
prefix := prefixOf(collectionType, season)
return prefix + twoDigit(year)
}
func prefixOf(collectionType, season string) string {
switch collectionType {
case ColResort:
return "RES"
case ColPreFall:
return "PF"
case ColCouture:
// 高定沿用秋冬编码(FW),与排序优先级一致
return "FW"
case ColMenswear:
return "FW"
case ColRTW:
return "SS"
}
switch season {
case SeasonFall:
return "FW"
case SeasonSpring:
return "SS"
}
return "SS"
}
// twoDigit 取年份后两位(2026 → "26")。
func twoDigit(year uint16) string {
if year >= 2000 {
year -= 2000
}
s := strconv.Itoa(int(year))
if len(s) > 2 {
s = s[len(s)-2:]
}
return s
}