update
This commit is contained in:
71
internal/pkg/season/season.go
Normal file
71
internal/pkg/season/season.go
Normal file
@ -0,0 +1,71 @@
|
||||
// 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
|
||||
}
|
||||
28
internal/pkg/season/season_test.go
Normal file
28
internal/pkg/season/season_test.go
Normal file
@ -0,0 +1,28 @@
|
||||
package season
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestDerive(t *testing.T) {
|
||||
cases := []struct {
|
||||
year uint16
|
||||
col string
|
||||
season string
|
||||
want string
|
||||
}{
|
||||
{2026, ColRTW, SeasonSpring, "SS26"},
|
||||
{2025, "", SeasonFall, "FW25"},
|
||||
{2026, ColResort, "", "RES26"},
|
||||
{2026, ColPreFall, "", "PF26"},
|
||||
{2025, ColMenswear, "", "FW25"},
|
||||
{2025, ColCouture, "", "FW25"},
|
||||
{2026, "", "", "SS26"}, // 二者皆空回落 SS
|
||||
{0, ColRTW, SeasonSpring, ""}, // 未知年份无法编码
|
||||
{2099, ColRTW, SeasonSpring, "SS99"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
got := Derive(c.year, c.col, c.season)
|
||||
if got != c.want {
|
||||
t.Fatalf("Derive(%d,%q,%q)=%q want %q", c.year, c.col, c.season, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user