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。
This commit is contained in:
1 parent
8dd599bd97
commit
631c8dd8e1
80 files changed
+12468
-519
No files matched your search
@@ -15,6 +15,7 @@ import (
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/xuri/excelize/v2"
|
||||
@@ -59,7 +60,12 @@ func (s *server) login(w http.ResponseWriter, r *http.Request) (any, error) {
|
||||
Action: "auth.login", EntityType: "user", EntityID: u.ID, ActorID: u.ID,
|
||||
After: map[string]any{"username": u.Username},
|
||||
})
|
||||
return userDTO(u), nil
|
||||
out := userDTO(u)
|
||||
// 刚建好的会话到期时间 = 此刻 + 当前有效期(与 createSession 同一请求内,误差在毫秒级);
|
||||
// 下发它,界面登录后就能立刻显示「当前会话将于 … 过期」,不用等下一次 /auth/me。
|
||||
expiresAt := time.Now().UTC().Add(s.auth.SessionTTL()).Format(time.RFC3339)
|
||||
out.SessionExpiresAt = &expiresAt
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (s *server) logout(w http.ResponseWriter, r *http.Request) (any, error) {
|
||||
@@ -75,7 +81,31 @@ func (s *server) logout(w http.ResponseWriter, r *http.Request) (any, error) {
|
||||
|
||||
func (s *server) me(w http.ResponseWriter, r *http.Request) (any, error) {
|
||||
u := middleware.User(r.Context())
|
||||
return userDTO(u), nil
|
||||
out := userDTO(u)
|
||||
if u.Role == auth.RoleGuest {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// 顺带把会话 Cookie 的期限同步到最新的到期时间:
|
||||
// 滑动续期只改服务端 expires_at,Cookie 的 Max-Age 不跟着走的话,
|
||||
// 浏览器会在「登录时刻 + 有效期」处丢掉 Cookie,人还是被登出。
|
||||
// /auth/me 是管理端启动与定时心跳都会走的接口,放在这里就够。
|
||||
c, err := r.Cookie(auth.CookieSession)
|
||||
if err != nil || c.Value == "" {
|
||||
return out, nil
|
||||
}
|
||||
_, sess, err := s.auth.Lookup(r.Context(), c.Value)
|
||||
if err != nil || sess == nil {
|
||||
return out, nil
|
||||
}
|
||||
expiresAt := sess.ExpiresAt.UTC().Format(time.RFC3339)
|
||||
out.SessionExpiresAt = &expiresAt
|
||||
csrf := ""
|
||||
if c, err := r.Cookie(auth.CookieCSRF); err == nil {
|
||||
csrf = c.Value
|
||||
}
|
||||
s.auth.RefreshSessionCookies(w, c.Value, csrf, sess.ExpiresAt)
|
||||
return out, nil
|
||||
}
|
||||
|
||||
type changePasswordInput struct {
|
||||
@@ -356,9 +386,19 @@ func (s *server) getEventHandler(w http.ResponseWriter, r *http.Request) (any, e
|
||||
|
||||
func (s *server) createEventHandler(w http.ResponseWriter, r *http.Request) (any, error) {
|
||||
var in eventDTO
|
||||
if err := decodeJSON(r, &in); err != nil {
|
||||
keys, err := decodeJSONPresence(r, &in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 与建单位 / 大项同口径:缺省 = 建表默认值(migrations/event/0004_sports_events.sql 里
|
||||
// scored 与 record_eligible 都 DEFAULT 1)。Go 的 bool 零值是 false,漏传会被静默建成
|
||||
// 「只排名不计分、不能破纪录」的小项 —— 这与导入侧按建表默认值建档的口径也不一致。
|
||||
if !keys.has("scored") {
|
||||
in.Scored = true
|
||||
}
|
||||
if !keys.has("recordEligible") {
|
||||
in.RecordEligible = true
|
||||
}
|
||||
created, err := s.createEvent(r.Context(), in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -373,13 +413,22 @@ func (s *server) updateEventHandler(w http.ResponseWriter, r *http.Request) (any
|
||||
return nil, err
|
||||
}
|
||||
var in eventDTO
|
||||
if err := decodeJSON(r, &in); err != nil {
|
||||
keys, err := decodeJSONPresence(r, &in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
before, err := s.getEvent(r.Context(), id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// 更新仍是全量覆盖语义,但漏传这两个开关不等于「关掉它」:沿用库里的现值,
|
||||
// 与 active 在单位 / 大项上的处理一致。
|
||||
if !keys.has("scored") {
|
||||
in.Scored = before.Scored
|
||||
}
|
||||
if !keys.has("recordEligible") {
|
||||
in.RecordEligible = before.RecordEligible
|
||||
}
|
||||
updated, err := s.updateEvent(r.Context(), id, in)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -611,9 +660,12 @@ type entryImportResult struct {
|
||||
Skipped int `json:"skipped"`
|
||||
Errors []string `json:"errors"`
|
||||
Conflicts []importConflict `json:"conflicts"`
|
||||
// SameNameNewPersons 是「号码布不同 → 按同名的另一个人新建档案」的清单。
|
||||
// 只作报告:不弹窗、不阻塞导入,但必须让用户看得见。
|
||||
SameNameNewPersons []sameNameNewPerson `json:"sameNameNewPersons"`
|
||||
}
|
||||
|
||||
// importConflict 是「证件号或号码布已存在、但人员字段与库中不一致」的一行。
|
||||
// importConflict 是「命中了库里已有人员、但人员字段与库中不一致」的一行。
|
||||
// 该行本轮不落库,等用户逐条决策后走 /api/entries/import/resolve。
|
||||
type importConflict struct {
|
||||
Row int `json:"row"`
|
||||
@@ -886,9 +938,9 @@ func (s *server) importEntries(ctx context.Context, rows [][]string) (entryImpor
|
||||
}
|
||||
|
||||
// importEntriesWith 是导入主体。decisions 为 nil 表示纯导入:冲突只收集不落库;
|
||||
// 非 nil 时按决策处理证件号/号码布命中的冲突,未出现在 decisions 里的冲突继续收集。
|
||||
// 非 nil 时按决策处理命中人员的冲突,未出现在 decisions 里的冲突继续收集。
|
||||
func (s *server) importEntriesWith(ctx context.Context, rows [][]string, decisions map[string]string) (entryImportResult, error) {
|
||||
result := entryImportResult{Errors: []string{}, Conflicts: []importConflict{}}
|
||||
result := entryImportResult{Errors: []string{}, Conflicts: []importConflict{}, SameNameNewPersons: []sameNameNewPerson{}}
|
||||
if len(rows) < 2 {
|
||||
return result, badRequest("报名表为空", nil)
|
||||
}
|
||||
@@ -904,8 +956,8 @@ func (s *server) importEntriesWith(ctx context.Context, rows [][]string, decisio
|
||||
}
|
||||
}
|
||||
|
||||
// 同一文件里证件号、号码布都只能出现一次,否则无法判断是不是同一个人。
|
||||
seenIDCards := make(map[string]bool)
|
||||
// 号码布是人员唯一标识,同一份表里重复出现仍无法判断是不是同一个人,照旧按行报错;
|
||||
// 证件号只是可选档案信息,重复不再拦截(同一份表内、跨行、跨表都不因它拦截)。
|
||||
seenBibs := make(map[string]bool)
|
||||
for n, row := range rows[1:] {
|
||||
line := n + 2
|
||||
@@ -982,7 +1034,7 @@ func (s *server) importEntriesWith(ctx context.Context, rows [][]string, decisio
|
||||
if athleteName != "" {
|
||||
idCard := cell("id_card")
|
||||
bib := cell("bib")
|
||||
// 证件号与号码布二选一即可,都没有就无法区分同名的两个人。
|
||||
// 有姓名就必须给证件号或号码布之一:两者都空时无法确认是哪一个人。
|
||||
if idCard == "" && bib == "" {
|
||||
result.Skipped++
|
||||
result.Errors = append(result.Errors, s.interceptRow(line, "填写了 athlete_name 就必须填 id_card 或 bib"))
|
||||
@@ -994,14 +1046,6 @@ func (s *server) importEntriesWith(ctx context.Context, rows [][]string, decisio
|
||||
result.Errors = append(result.Errors, s.interceptRow(line, "age 需要是 0-120 的整数"))
|
||||
continue
|
||||
}
|
||||
if idCard != "" {
|
||||
if seenIDCards[idCard] {
|
||||
result.Skipped++
|
||||
result.Errors = append(result.Errors, s.interceptRow(line, "证件号 %s 在报名表内重复出现", idCard))
|
||||
continue
|
||||
}
|
||||
seenIDCards[idCard] = true
|
||||
}
|
||||
if bib != "" {
|
||||
if seenBibs[bib] {
|
||||
result.Skipped++
|
||||
@@ -1023,13 +1067,16 @@ func (s *server) importEntriesWith(ctx context.Context, rows [][]string, decisio
|
||||
}, decisions)
|
||||
if err != nil {
|
||||
result.Skipped++
|
||||
result.Errors = append(result.Errors, s.interceptRow(line, "%s", err.Error()))
|
||||
result.Errors = append(result.Errors, s.interceptRow(line, "%s", importRowMessage(err)))
|
||||
continue
|
||||
}
|
||||
if matched.Conflict != nil {
|
||||
result.Conflicts = append(result.Conflicts, *matched.Conflict)
|
||||
continue
|
||||
}
|
||||
if matched.SameNameNewPerson != nil {
|
||||
result.SameNameNewPersons = append(result.SameNameNewPersons, *matched.SameNameNewPerson)
|
||||
}
|
||||
athleteID = &matched.AthleteID
|
||||
// keep-existing 时报名跟随库里已有的单位,避免报名与人员的单位不一致。
|
||||
teamID = matched.TeamID
|
||||
|
||||
Reference in new issue
Block a user