Files
Scoreboard/server/internal/httpapi/dto.go
T
AskaEth 631c8dd8e1 feat: 8 条功能 + 身份口径改为号码布为准(含批量退赛/移出、基础数据导入导出、登录有效期)
用户给出的 8 条功能 + 一条口径变更,全部带真机/真浏览器验证:

① 录入页姓名后直接显示号码布(原「号码」列保留)
② 录入页批次进度条:`第 2 批 已录 5/8 · 3 条有错`,录完变绿;已录判据复用
   entryGuards.judgeEntryRow(与发布防呆同源,不会出现"进度条说录完、发布说缺 8 条")
⑦ 小项列表双击 → 跳到该小项的组别(编辑/删除按钮不误触)
③ 赛事开关 `standings.live_on_publish`(默认开=保持原行为):关闭后分批发布只上屏成绩,
   名次/流水/榜单一起等该组录完再结算 —— 代理实读代码后纠正了我的前提:
   奖牌榜读的是 results.rank(buildRanked)而非流水汇总,只延迟流水会出现
   「有金牌但 0 分」。另提供 POST /api/results/settle 人工兜底 + GET /api/results/settlement 未结算清单
④ 组别「就地更新」PUT /api/events/{id}/categories/{categoryId}:有报名数据时也能改名/改年龄/
   改性别/改权重(旧路径是整表替换,一改就被 409 拦下);改名不动报名/成绩/流水(真机逐字节比对);
   权重真的变了才触发该组重算(容差 1e-9)
④辅 运动员列表多选+全选,POST /api/athletes/batch 一次请求完成整批停用/彻底删除(逐条回报,
   dryRun 预览走同一段 SQL 但不提交、不写审计)——这才是绕开限流的正解
新增 报名项批量:POST /api/entries/batch(scratch/restore/remove)。退赛只动 registered、
   跳过 dq/dns 并说明原因;移出是物理删除,必须显式清 score_ledger(该表 entry_id 是
   ON DELETE SET NULL,不显式删会留下"人没了分还在"的孤儿流水,验证基线 orphan=0);
   退赛同时清 results.rank(否则出现"0 分还挂着金牌")
⑤ GET /api/export/entries.xlsx 报名名单导出(13 列含批次,状态中文与录入页逐字一致)
⑥ 基础数据包:GET /api/export/basedata.xlsx + POST /api/export/basedata/import
   (四张表、表头只有一份定义、表头行自动定位、列缺席≠写空、按编码 upsert、绝不删除、
   行级中文错误带真实 Excel 行号、枚举走既有校验、新增单位一定是启用)
⑧ 登录有效期面板可配:系统设置新页签,1–720 小时,默认 12h → 24h;滑动续期 +
   Cookie 同步刷新(只服务端续期是假的,浏览器侧的 Max-Age 到点仍会丢 Cookie)
身份口径:号码布为唯一标识、证件号退出匹配(号码布不同=同名的两个人,新建并单独报告);
   同一份表重复证件号不再报错;两个不同的人共用证件号仍报行级错误(唯一索引保留)

其它对齐:分项成绩表草稿行不再消失(成绩列「分数未录入」、名次/积分 `—`,没成绩的行同占位);
大屏实时赛况单栏铺满(留白 370→78px)、字号上限 56→96px、≥7 行自动拆左右两块;
删除报名项/退赛/权重等改动都会重算并推榜单。

测试:服务端 13 包(连跑两遍)、前端 335 例、vue-tsc + build、Console 18 文件 —— 全绿。
文档:README、docs/ 四份(含 debug/使用说明 副本)、devdocs 05/08/04/13。
版本号 dev_0.1.5 → dev_0.1.6。
2026-09-11 17:14:02 +08:00

345 lines
11 KiB
Go

package httpapi
// 本文件是 REST 的 JSON 契约(camelCase,与 web/src/shared/types.ts 一一对应)。
// 数据库列是 snake_case,转换集中放在 repo.go 的扫描函数里。
type teamDTO struct {
ID int64 `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
ShortName *string `json:"shortName"`
LogoPath *string `json:"logoPath"`
Color *string `json:"color"`
SortOrder int `json:"sortOrder"`
Active bool `json:"active"`
// DeletedAt 非空表示「彻底删除」(对界面不可见),行仍在库里;停用是另一回事(active = false)。
DeletedAt *string `json:"deletedAt"`
}
type athleteDTO struct {
ID int64 `json:"id"`
Name string `json:"name"`
Gender *string `json:"gender"`
TeamID int64 `json:"teamId"`
EmployeeNo *string `json:"employeeNo"`
IDCard *string `json:"idCard"`
Bib *string `json:"bib"`
Age *int `json:"age"`
Active bool `json:"active"`
}
type sportDTO struct {
ID int64 `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
ShortName *string `json:"shortName"`
DefaultProfileID *int64 `json:"defaultProfileId"`
SortOrder int `json:"sortOrder"`
Active bool `json:"active"`
}
type categoryDTO struct {
ID int64 `json:"id"`
EventID int64 `json:"eventId"`
Name string `json:"name"`
Multiplier float64 `json:"multiplier"`
Gender *string `json:"gender"`
AgeMin *int `json:"ageMin"`
AgeMax *int `json:"ageMax"`
SortOrder int `json:"sortOrder"`
}
type channelDTO struct {
ID int64 `json:"id"`
EventID int64 `json:"eventId"`
Scope string `json:"scope"`
Basis string `json:"basis"`
ProfileID int64 `json:"profileId"`
SortOrder int `json:"sortOrder"`
// CountToTeam 决定该通道产出的流水是否计入单位总分;请求体里缺省(null)按 true 处理,
// 「个人+团体」项目的个人通道传 false。响应里始终是具体值。
CountToTeam *bool `json:"countToTeam"`
}
type eventDTO struct {
ID int64 `json:"id"`
SportID int64 `json:"sportId"`
Code string `json:"code"`
Name string `json:"name"`
EventType string `json:"eventType"`
ResultMode string `json:"resultMode"`
ResultType string `json:"resultType"`
Compare string `json:"compare"`
RecordEligible bool `json:"recordEligible"`
Scored bool `json:"scored"`
Multiplier float64 `json:"multiplier"`
Status string `json:"status"`
ScheduledAt *string `json:"scheduledAt"`
Venue *string `json:"venue"`
SortOrder int `json:"sortOrder"`
Remark *string `json:"remark"`
AvgMode string `json:"avgMode"`
Categories []categoryDTO `json:"categories,omitempty"`
Channels []channelDTO `json:"channels,omitempty"`
}
type profileRuleDTO struct {
Rank int `json:"rank"`
Points float64 `json:"points"`
}
type profileDTO struct {
ID int64 `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
TieMode string `json:"tieMode"`
RecordBonusMode string `json:"recordBonusMode"`
AwardRanks int `json:"awardRanks"`
LastPlaceZero bool `json:"lastPlaceZero"`
Rules []profileRuleDTO `json:"rules"`
}
type entryDTO struct {
ID int64 `json:"id"`
EventID int64 `json:"eventId"`
CategoryID int64 `json:"categoryId"`
TeamID int64 `json:"teamId"`
AthleteID *int64 `json:"athleteId"`
MemberNames []string `json:"memberNames"`
Bib *string `json:"bib"`
Seed *string `json:"seed"`
// Heat 是录入 / 展示用的批次号,null 表示「未分批」;批次不参与算分。
Heat *int64 `json:"heat"`
Status string `json:"status"`
Remark *string `json:"remark"`
AthleteName *string `json:"athleteName,omitempty"`
TeamCode string `json:"teamCode,omitempty"`
TeamName string `json:"teamName,omitempty"`
ShortName *string `json:"shortName,omitempty"`
CategoryName string `json:"categoryName,omitempty"`
}
type entryWithResultDTO struct {
entryDTO
Result *resultDTO `json:"result"`
}
// entryHeatResultDTO 是批量设置批次的结果:本批条目当前统一的批次号(null = 未分批)。
type entryHeatResultDTO struct {
Updated int `json:"updated"`
Heat *int64 `json:"heat"`
EntryIDs []int64 `json:"entryIds"`
}
type resultDTO struct {
ID int64 `json:"id"`
EventID int64 `json:"eventId"`
EntryID int64 `json:"entryId"`
Rank *int `json:"rank"`
ResultText string `json:"resultText"`
ResultValue *float64 `json:"resultValue"`
Unit string `json:"unit"`
IsTie bool `json:"isTie"`
PointsOverride *float64 `json:"pointsOverride"`
Status string `json:"status"`
State string `json:"state"`
RecordedBy *int64 `json:"recordedBy"`
RecordedAt *string `json:"recordedAt"`
VerifiedBy *int64 `json:"verifiedBy"`
VerifiedAt *string `json:"verifiedAt"`
Note *string `json:"note"`
Points *float64 `json:"points,omitempty"`
}
type athleteStandingDTO struct {
Rank int `json:"rank"`
AthleteID int64 `json:"athleteId"`
AthleteName string `json:"athleteName"`
Gender *string `json:"gender"`
TeamID int64 `json:"teamId"`
TeamCode string `json:"teamCode"`
TeamName string `json:"teamName"`
ShortName *string `json:"shortName"`
LogoPath *string `json:"logoPath"`
TotalPoints float64 `json:"totalPoints"`
Gold int `json:"gold"`
Silver int `json:"silver"`
Bronze int `json:"bronze"`
}
type breakdownItemDTO struct {
LedgerID int64 `json:"ledgerId"`
SourceType string `json:"sourceType"`
EventID *int64 `json:"eventId"`
EventCode *string `json:"eventCode"`
EventName *string `json:"eventName"`
CategoryName *string `json:"categoryName"`
AthleteID *int64 `json:"athleteId"`
AthleteName *string `json:"athleteName"`
Rank *int `json:"rank"`
ResultText *string `json:"resultText"`
Points float64 `json:"points"`
CreatedAt string `json:"createdAt"`
}
type teamBreakdownDTO struct {
TeamID int64 `json:"teamId"`
TeamCode string `json:"teamCode"`
TeamName string `json:"teamName"`
TotalPoints float64 `json:"totalPoints"`
Items []breakdownItemDTO `json:"items"`
}
type adjustmentDTO struct {
ID int64 `json:"id"`
TeamID int64 `json:"teamId"`
Delta float64 `json:"delta"`
Category string `json:"category"`
Reason string `json:"reason"`
EventID *int64 `json:"eventId"`
Voided bool `json:"voided"`
CreatedBy *int64 `json:"createdBy"`
CreatedAt string `json:"createdAt"`
}
type recordEntryDTO struct {
ID int64 `json:"id"`
EventID int64 `json:"eventId"`
Level string `json:"level"`
ResultValue float64 `json:"resultValue"`
ResultText string `json:"resultText"`
HolderName *string `json:"holderName"`
HolderTeamID *int64 `json:"holderTeamId"`
AchievedAt *string `json:"achievedAt"`
IsCurrent bool `json:"isCurrent"`
Source string `json:"source"`
}
type recordBreakDTO struct {
ID int64 `json:"id"`
EventID int64 `json:"eventId"`
EntryID int64 `json:"entryId"`
Level string `json:"level"`
ResultValue float64 `json:"resultValue"`
ResultText string `json:"resultText"`
BonusPoints float64 `json:"bonusPoints"`
State string `json:"state"`
ApprovedBy *int64 `json:"approvedBy"`
ApprovedAt *string `json:"approvedAt"`
}
type auditLogDTO struct {
ID int64 `json:"id"`
UserID *int64 `json:"userId"`
Action string `json:"action"`
EntityType string `json:"entityType"`
EntityID *int64 `json:"entityId"`
BeforeJSON *string `json:"beforeJson"`
AfterJSON *string `json:"afterJson"`
IP *string `json:"ip"`
RequestID *string `json:"requestId"`
CreatedAt string `json:"createdAt"`
}
type currentUserDTO struct {
ID int64 `json:"id"`
Username string `json:"username"`
DisplayName string `json:"displayName"`
Role string `json:"role"`
LastLoginAt *string `json:"lastLoginAt"`
MustChangePassword bool `json:"mustChangePassword"`
// SessionExpiresAt 是当前会话的到期时间(RFC3339 UTC),供界面显示
// 「当前会话将于 … 过期」;未登录时为 null。
SessionExpiresAt *string `json:"sessionExpiresAt"`
}
type backupResultDTO struct {
Path string `json:"path"`
CreatedAt string `json:"createdAt"`
}
// GET/PUT /api/settings 的线上结构见 internal/dto.EventSettings(与 snapshot.settings 共用)。
// ---------- 用户管理 ----------
type userListItemDTO struct {
ID int64 `json:"id"`
Username string `json:"username"`
DisplayName string `json:"displayName"`
Role string `json:"role"`
Active bool `json:"active"`
MustChangePassword bool `json:"mustChangePassword"`
LastLoginAt *string `json:"lastLoginAt"`
}
// resetPasswordResultDTO 里的 password 是唯一一次明文,落库只存哈希。
type resetPasswordResultDTO struct {
ID int64 `json:"id"`
Username string `json:"username"`
Password string `json:"password"`
Generated bool `json:"generated"`
MustChangePassword bool `json:"mustChangePassword"`
}
// ---------- 变更历史 ----------
type revisionPageDTO struct {
Items []revisionListItemDTO `json:"items"`
Total int `json:"total"`
Limit int `json:"limit"`
Offset int `json:"offset"`
}
type revisionListItemDTO struct {
ID int64 `json:"id"`
ParentID *int64 `json:"parentId"`
EventID int64 `json:"eventId"`
EventName string `json:"eventName"`
Action string `json:"action"`
ActorID *int64 `json:"actorId"`
ActorName string `json:"actorName"`
Message *string `json:"message"`
CreatedAt string `json:"createdAt"`
ChangedCount int `json:"changedCount"`
}
type revisionDetailDTO struct {
revisionListItemDTO
Snapshot []resultDTO `json:"snapshot"`
Diff revisionDiffDTO `json:"diff"`
}
type revisionDiffDTO struct {
Results []revisionResultChangeDTO `json:"results"`
Teams []revisionTeamDeltaDTO `json:"teams"`
}
type revisionResultChangeDTO struct {
ResultID int64 `json:"resultId"`
EntryID int64 `json:"entryId"`
TeamID *int64 `json:"teamId"`
Change string `json:"change"`
Fields []string `json:"fields,omitempty"`
Before *resultDTO `json:"before"`
After *resultDTO `json:"after"`
}
type revisionTeamDeltaDTO struct {
TeamID int64 `json:"teamId"`
TeamCode string `json:"teamCode"`
TeamName string `json:"teamName"`
PointsBefore float64 `json:"pointsBefore"`
PointsAfter float64 `json:"pointsAfter"`
PointsDelta float64 `json:"pointsDelta"`
ChangedResults int `json:"changedResults"`
}
// ---------- domain → DTO ----------
func nilIfEmpty(s string) *string {
if s == "" {
return nil
}
return &s
}