- domain/rules: 计分与排名解耦、破纪录按组别、tieBreak 生效、调整分不丢、移除 aggregate 假能力 - realtime: 新建 internal/dto,快照三项契约对齐,/ws 只认会话身份 - httpapi: 流水幂等、standings 整表载荷、广播接线、强制改密、XFF 防伪造、records 写入、审计、赛事包内容、发布前备份、result.points、实例列表 - web: FormData 上传、YAML 解析、快照归一化、大屏解析层、bootstrap 降级、访客判定、主题切换 - console: 优雅关闭握手、中文化、免验证改管理员账号、选屏与日志轮转修复 - docs: 用户文档三份 + README - 主代理: 破纪录加分接线(levels 未加载导致恒 0)
120 lines
3.9 KiB
Go
120 lines
3.9 KiB
Go
package rules
|
||
|
||
import "git.yeij.top/AskaEth/Scoreboard/server/internal/domain"
|
||
|
||
// 本文件是规则包类型与 domain 类型之间的唯一转换入口;
|
||
// 转换只搬字段、不填默认值(默认值统一由 Canonical 负责),避免两处口径打架。
|
||
|
||
// ToDomain 把模板转成 domain.ScoringProfile;id 由调用方(仓储层)决定。
|
||
func (p Profile) ToDomain(id int64) domain.ScoringProfile {
|
||
tie := p.TieMode
|
||
if tie == "" {
|
||
tie = domain.TieSkip
|
||
}
|
||
bonus := p.RecordBonusMode
|
||
if bonus == "" {
|
||
bonus = domain.RecordBonusMax
|
||
}
|
||
rules := make([]domain.ScoringRule, 0, len(p.Rules))
|
||
for _, r := range p.Rules {
|
||
rules = append(rules, domain.ScoringRule{Rank: r.Rank, Points: r.Points})
|
||
}
|
||
return domain.ScoringProfile{
|
||
ID: id,
|
||
Code: p.Code,
|
||
Name: p.Name,
|
||
AwardRanks: p.AwardRanks,
|
||
LastPlaceZero: p.LastPlaceZero,
|
||
TieMode: tie,
|
||
RecordBonusMode: bonus,
|
||
Rules: rules,
|
||
}
|
||
}
|
||
|
||
// ProfileFromDomain 把 domain 模板转回规则包类型。
|
||
func ProfileFromDomain(p domain.ScoringProfile) Profile {
|
||
rules := make([]Rule, 0, len(p.Rules))
|
||
for _, r := range p.Rules {
|
||
rules = append(rules, Rule{Rank: r.Rank, Points: r.Points})
|
||
}
|
||
return Profile{
|
||
Code: p.Code,
|
||
Name: p.Name,
|
||
AwardRanks: p.AwardRanks,
|
||
LastPlaceZero: p.LastPlaceZero,
|
||
TieMode: p.TieMode,
|
||
RecordBonusMode: p.RecordBonusMode,
|
||
Rules: rules,
|
||
}
|
||
}
|
||
|
||
// ToDomain 把通道转成 domain.ScoreChannel;profileID 由调用方按模板编码查出。
|
||
func (c Channel) ToDomain(eventID, profileID int64, sortOrder int) domain.ScoreChannel {
|
||
return domain.ScoreChannel{
|
||
EventID: eventID,
|
||
Scope: c.Scope,
|
||
Basis: c.Basis,
|
||
ProfileID: profileID,
|
||
SortOrder: sortOrder,
|
||
}
|
||
}
|
||
|
||
// ChannelFromDomain 把 domain 通道转回规则包类型;profileCode 由调用方按模板 ID 查出。
|
||
func ChannelFromDomain(c domain.ScoreChannel, profileCode string) Channel {
|
||
return Channel{
|
||
Scope: c.Scope,
|
||
Basis: c.Basis,
|
||
Profile: profileCode,
|
||
}
|
||
}
|
||
|
||
// ProfileIndex 按模板编码建索引,便于通道引用解析。
|
||
func (p *RulePack) ProfileIndex() map[string]Profile {
|
||
out := make(map[string]Profile, len(p.Profiles))
|
||
for _, prof := range p.Profiles {
|
||
out[prof.Code] = prof
|
||
}
|
||
return out
|
||
}
|
||
|
||
// ToStandingsInput 把榜单口径映射成 domain 聚合输入。
|
||
func (s Standings) ToStandingsInput() domain.StandingsInput {
|
||
return domain.StandingsInput{
|
||
TieBreak: append([]string(nil), s.TieBreak...),
|
||
IndividualToTeamWeight: s.IndividualToTeamWeight,
|
||
ExcludeTeamEventMedals: !s.MedalCountsTeamEventsEnabled(),
|
||
}
|
||
}
|
||
|
||
// ToDomain 把破纪录配置转成 domain.RecordBonusConfig。
|
||
func (r RecordBonus) ToDomain() domain.RecordBonusConfig {
|
||
mode := r.Mode
|
||
if mode == "" {
|
||
mode = domain.RecordBonusMax
|
||
}
|
||
levels := make([]domain.RecordLevel, 0, len(r.Levels))
|
||
for _, lv := range r.Levels {
|
||
levels = append(levels, domain.RecordLevel{Code: lv.Code, Name: lv.Name, Points: lv.Points})
|
||
}
|
||
return domain.RecordBonusConfig{Enabled: r.Enabled, Mode: mode, Levels: levels}
|
||
}
|
||
|
||
// RecordBonusFromDomain 把 domain 破纪录配置转回规则包类型。
|
||
func RecordBonusFromDomain(c domain.RecordBonusConfig) RecordBonus {
|
||
levels := make([]RecordLevel, 0, len(c.Levels))
|
||
for _, lv := range c.Levels {
|
||
levels = append(levels, RecordLevel{Code: lv.Code, Name: lv.Name, Points: lv.Points})
|
||
}
|
||
return RecordBonus{Enabled: c.Enabled, Mode: c.Mode, Levels: levels}
|
||
}
|
||
|
||
// ToDomain 把人工调整开关转成 domain.ManualAdjustmentConfig。
|
||
func (m ManualAdjustment) ToDomain() domain.ManualAdjustmentConfig {
|
||
return domain.ManualAdjustmentConfig{Enabled: m.Enabled, ReasonRequired: m.ReasonRequired}
|
||
}
|
||
|
||
// ManualAdjustmentFromDomain 把 domain 人工调整开关转回规则包类型。
|
||
func ManualAdjustmentFromDomain(c domain.ManualAdjustmentConfig) ManualAdjustment {
|
||
return ManualAdjustment{Enabled: c.Enabled, ReasonRequired: c.ReasonRequired}
|
||
}
|