feat: 分批发布 + 实时赛况页 + 显式批次层 + 成绩框实时提示 + 窄屏适配 + 版本号单一真相
## 分批发布(现场:100 米跑道只有 8 条,不能等所有人跑完才发) - 空成绩从"错误"降级为"提示",不再阻塞发布;真会算错(写法无法识别、秒位 ≥ 60、 手动名次缺名次)仍挡住。发布确认框说明"只发已填的 M 人,其余保持未发布"。 - 服务端核实:publishResults/computeEventScore 本就不会因缺成绩报错 (collectCandidates 直接跳过没有 results 的报名项),根因在前端防呆。 ## 实时赛况(新大屏页 + 定向接口) - 新增 `GET /api/display/live`(guest 可读):返回「当前项目」判定 + 该项目**全量**已发布成绩 (不受快照 latestResults 的 20 行截断)。回退链:manual 指定 > 排期命中 > 最近发布。 设置键 display.live_events / display.live_source。 - 大屏新页 `live`「实时赛况」:1 个项目单栏、2 个自动左右分栏;失败保留上一次画面 (下一场开始前持续显示上一场);30s 轮询(判定依赖当前时间)+ 快照变更触发。 - 管理端「大屏控制」新增「实时赛况」卡;该卡走 PUT /api/settings(admin-only), 故对非管理员整组置灰 + 提示条(不新增角色)。 ## 显式批次层(组别之下) - 迁移 0019 `entries.heat`;批次仅是录入/展示分组,**不参与算分**(有"分批与不分批结果 完全一致"的断言守住)。批量设置接口 + 导入 CSV 可选列 heat + 录入页批次下拉 + 一键均分(按 N 人切片,已有批次号接着往后排)。 ## 成绩输入框实时悬浮提示 - 聚焦格旁的浮动气泡:pointer-events:none、不占布局不改行高、贴底自动上翻; 合法显示解析结果(1:06 → = 66 秒)、可疑/不合法显示原因并带那一格原文; 与发布防呆共用同一套纯函数(entryGuards.ts),口径不会分叉。 ## 窄屏 / 手机端布局 - 真浏览器(Playwright + chromium)在 1440/1024/768/390 四宽度逐页审计 + 溢出探针, 四轮迭代修复;桌面端 1440 前后像素差异 < 0.25%(无回归);修掉如「修改密码」输入框 塌成 22px 这类真问题。 ## 版本号单一真相 - 新增仓库根 `VERSION`:构建时注入二进制(-X main.version)并同步 console/package.json 的版本(产物名跟随)。源码里不再有人工维护的版本号(兜底值改为 `dev`,故意不写数字)。 测试:服务端 13 包全绿;前端 vue-tsc 通过、249 例全过;Console 18 文件。 docs/ 与 devdocs/ 同步(FAQ 到 Q80、新增 devdocs/16 自定义大屏模板设计文档)。
This commit is contained in:
1 parent
e5e0944d26
commit
08a5740fb2
64 files changed
+4968
-270
No files matched your search
@@ -0,0 +1,268 @@
|
||||
package httpapi_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// importHeaderHeat 是带批次列的 12 列表头(与 ImportSection 模板一致)。
|
||||
const importHeaderHeat = "event_code,category,team_code,athlete_name,id_card,gender,age,bib,seed,heat,status,member_names"
|
||||
|
||||
// 批量设置批次:成功写库、GET 下发、再传 null 清除;重复提交幂等。
|
||||
func TestSetEntriesHeatSetsAndClears(t *testing.T) {
|
||||
env, ids, client := recorderWithSeed(t)
|
||||
|
||||
status, env2 := env.do(client, http.MethodPut, "/api/entries/heat", map[string]any{
|
||||
"entryIds": []int64{ids.entryA, ids.entryB},
|
||||
"heat": 2,
|
||||
}, true)
|
||||
if status != http.StatusOK || !env2.OK {
|
||||
t.Fatalf("设置批次应 200,得到 %d %+v", status, env2.Error)
|
||||
}
|
||||
result := decodeData[map[string]any](t, env2)
|
||||
if result["updated"] != float64(2) || result["heat"] != float64(2) {
|
||||
t.Fatalf("批量设置结果不对: %+v", result)
|
||||
}
|
||||
|
||||
var heat int
|
||||
if err := env.ev.QueryRow(`SELECT heat FROM entries WHERE id = ?`, ids.entryA).Scan(&heat); err != nil {
|
||||
t.Fatalf("读 entries.heat: %v", err)
|
||||
}
|
||||
if heat != 2 {
|
||||
t.Fatalf("entryA 的批次应为 2,得到 %d", heat)
|
||||
}
|
||||
|
||||
// 下发路径也要带上 heat:录入页靠 GET /api/events/{id}/entries 拿批次。
|
||||
status, env2 = env.do(client, http.MethodGet, fmt.Sprintf("/api/events/%d/entries", ids.event), nil, false)
|
||||
if status != http.StatusOK || !env2.OK {
|
||||
t.Fatalf("读报名列表应 200,得到 %d %+v", status, env2.Error)
|
||||
}
|
||||
items := decodeData[[]map[string]any](t, env2)
|
||||
if len(items) != 2 {
|
||||
t.Fatalf("报名列表应有 2 条,得到 %d", len(items))
|
||||
}
|
||||
for _, item := range items {
|
||||
if item["heat"] != float64(2) {
|
||||
t.Fatalf("报名列表应下发 heat=2,得到 %+v", item["heat"])
|
||||
}
|
||||
}
|
||||
|
||||
// 幂等:同一批再设一次批次号,结果一致。
|
||||
status, env2 = env.do(client, http.MethodPut, "/api/entries/heat", map[string]any{
|
||||
"entryIds": []int64{ids.entryA, ids.entryB},
|
||||
"heat": 2,
|
||||
}, true)
|
||||
if status != http.StatusOK || !env2.OK {
|
||||
t.Fatalf("重复设置同一批次应 200,得到 %d %+v", status, env2.Error)
|
||||
}
|
||||
if again := decodeData[map[string]any](t, env2); again["updated"] != float64(2) {
|
||||
t.Fatalf("重复设置应同样更新 2 条,得到 %+v", again)
|
||||
}
|
||||
|
||||
// 传 null 清除为「未分批」。
|
||||
status, env2 = env.do(client, http.MethodPut, "/api/entries/heat", map[string]any{
|
||||
"entryIds": []int64{ids.entryA, ids.entryB},
|
||||
"heat": nil,
|
||||
}, true)
|
||||
if status != http.StatusOK || !env2.OK {
|
||||
t.Fatalf("清除批次应 200,得到 %d %+v", status, env2.Error)
|
||||
}
|
||||
if cleared := decodeData[map[string]any](t, env2); cleared["heat"] != nil {
|
||||
t.Fatalf("清除后 heat 应为 null,得到 %+v", cleared["heat"])
|
||||
}
|
||||
var nullHeat any
|
||||
if err := env.ev.QueryRow(`SELECT heat FROM entries WHERE id = ?`, ids.entryA).Scan(&nullHeat); err != nil {
|
||||
t.Fatalf("读 entries.heat: %v", err)
|
||||
}
|
||||
if nullHeat != nil {
|
||||
t.Fatalf("清除后 entries.heat 应为 NULL,得到 %v", nullHeat)
|
||||
}
|
||||
}
|
||||
|
||||
// 跨小项批量设置一定是选错行:必须拒绝,且一条都不能改。
|
||||
func TestSetEntriesHeatRejectsCrossEvent(t *testing.T) {
|
||||
env, ids, client := recorderWithSeed(t)
|
||||
|
||||
otherEvent := env.insert(t,
|
||||
`INSERT INTO events (sport_id, code, name, event_type, result_mode, result_type, compare, scored, multiplier, status)
|
||||
VALUES (?, 'M200', '200米跑', 'individual', 'auto', 'time', 'asc', 1, 1, 'ongoing')`, ids.sport)
|
||||
otherCategory := env.insert(t,
|
||||
`INSERT INTO event_categories (event_id, name, multiplier, sort_order) VALUES (?, '男子', 1, 0)`, otherEvent)
|
||||
otherEntry := env.insert(t,
|
||||
`INSERT INTO entries (event_id, category_id, team_id, athlete_id, status) VALUES (?, ?, ?, ?, 'registered')`,
|
||||
otherEvent, otherCategory, ids.teamB, ids.athB)
|
||||
|
||||
status, env2 := env.do(client, http.MethodPut, "/api/entries/heat", map[string]any{
|
||||
"entryIds": []int64{ids.entryA, otherEntry},
|
||||
"heat": 1,
|
||||
}, true)
|
||||
if status != http.StatusBadRequest {
|
||||
t.Fatalf("跨小项设置批次应 400,得到 %d %+v", status, env2.Error)
|
||||
}
|
||||
assertNoHeat(t, env, ids.entryA)
|
||||
assertNoHeat(t, env, otherEntry)
|
||||
}
|
||||
|
||||
// entryIds 为空 / 全部非法、以及 heat 越界都必须被拒。
|
||||
func TestSetEntriesHeatValidatesInput(t *testing.T) {
|
||||
env, ids, client := recorderWithSeed(t)
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
body map[string]any
|
||||
}{
|
||||
{"entryIds 为空", map[string]any{"entryIds": []int64{}, "heat": 1}},
|
||||
{"entryIds 缺失", map[string]any{"heat": 1}},
|
||||
{"entryIds 全是非法 id", map[string]any{"entryIds": []int64{0, -3}, "heat": 1}},
|
||||
{"heat 为 0", map[string]any{"entryIds": []int64{ids.entryA}, "heat": 0}},
|
||||
{"heat 为负", map[string]any{"entryIds": []int64{ids.entryA}, "heat": -1}},
|
||||
{"heat 超上限", map[string]any{"entryIds": []int64{ids.entryA}, "heat": 100000}},
|
||||
{"报名项不存在", map[string]any{"entryIds": []int64{ids.entryA, 999999}, "heat": 1}},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
status, env2 := env.do(client, http.MethodPut, "/api/entries/heat", tc.body, true)
|
||||
if status != http.StatusBadRequest {
|
||||
t.Errorf("%s 应 400,得到 %d %+v", tc.name, status, env2.Error)
|
||||
continue
|
||||
}
|
||||
if env2.Error == nil || env2.Error.Code != "VALIDATION_FAILED" {
|
||||
t.Errorf("%s 应返回 VALIDATION_FAILED,得到 %+v", tc.name, env2.Error)
|
||||
}
|
||||
}
|
||||
assertNoHeat(t, env, ids.entryA)
|
||||
}
|
||||
|
||||
// 权限:guest 未登录 401;recorder 放行;批次写操作进审计。
|
||||
func TestSetEntriesHeatPermissionAndAudit(t *testing.T) {
|
||||
env, ids, _ := recorderWithSeed(t)
|
||||
|
||||
guest, _ := env.client()
|
||||
status, env2 := env.do(guest, http.MethodPut, "/api/entries/heat", map[string]any{
|
||||
"entryIds": []int64{ids.entryA}, "heat": 1,
|
||||
}, false)
|
||||
if status != http.StatusUnauthorized || env2.Error == nil || env2.Error.Code != "AUTH_REQUIRED" {
|
||||
t.Fatalf("guest 设置批次应 401 AUTH_REQUIRED,得到 %d %+v", status, env2.Error)
|
||||
}
|
||||
assertNoHeat(t, env, ids.entryA)
|
||||
|
||||
recorder, _ := env.client()
|
||||
env.login(recorder, "recorder", "recorder-pass")
|
||||
status, env2 = env.do(recorder, http.MethodPut, "/api/entries/heat", map[string]any{
|
||||
"entryIds": []int64{ids.entryA}, "heat": 3,
|
||||
}, true)
|
||||
if status != http.StatusOK || !env2.OK {
|
||||
t.Fatalf("recorder 设置批次应 200,得到 %d %+v", status, env2.Error)
|
||||
}
|
||||
|
||||
var (
|
||||
action, after string
|
||||
)
|
||||
if err := env.ev.QueryRow(
|
||||
`SELECT action, after_json FROM audit_logs WHERE action = 'entry.heat' ORDER BY id DESC LIMIT 1`).
|
||||
Scan(&action, &after); err != nil {
|
||||
t.Fatalf("查批次审计: %v", err)
|
||||
}
|
||||
if !strings.Contains(after, `"heat":3`) {
|
||||
t.Fatalf("审计里应记下批次号 3,得到 %s", after)
|
||||
}
|
||||
}
|
||||
|
||||
func assertNoHeat(t *testing.T, env *testEnv, entryID int64) {
|
||||
t.Helper()
|
||||
var heat any
|
||||
if err := env.ev.QueryRow(`SELECT heat FROM entries WHERE id = ?`, entryID).Scan(&heat); err != nil {
|
||||
t.Fatalf("读 entries.heat: %v", err)
|
||||
}
|
||||
if heat != nil {
|
||||
t.Fatalf("entry %d 的批次应保持未分批,得到 %v", entryID, heat)
|
||||
}
|
||||
}
|
||||
|
||||
// 导入带 heat 列:正常值入库、留空 = 未分批、非法值走行级拦截且其余行照常导入。
|
||||
func TestImportEntriesWithHeatColumn(t *testing.T) {
|
||||
env, _, client := recorderWithSeed(t)
|
||||
|
||||
body := importHeaderHeat + "\n" +
|
||||
"M100,男子,A,张三,110101199001011234,男,,,,1,registered,\n" +
|
||||
"M100,男子,A,李强,110101199001011235,男,,,,2,registered,\n" +
|
||||
"M100,男子,B,王芳,110101199001011236,女,,,,3,registered,\n" +
|
||||
"M100,男子,A,赵六,110101199001011237,男,,,,abc,registered,\n" +
|
||||
"M100,男子,B,孙七,110101199001011238,男,,,,0,registered,\n"
|
||||
status, env2 := env.postImport(t, client, "/api/entries/import", body, "")
|
||||
if status != http.StatusOK || !env2.OK {
|
||||
t.Fatalf("导入应 200,得到 %d %+v", status, env2.Error)
|
||||
}
|
||||
result := decodeData[map[string]any](t, env2)
|
||||
if result["created"] != float64(3) || result["skipped"] != float64(2) {
|
||||
t.Fatalf("应新建 3 条、跳过 2 条,得到 %+v", result)
|
||||
}
|
||||
errs, _ := result["errors"].([]any)
|
||||
if len(errs) != 2 {
|
||||
t.Fatalf("应有 2 条行级错误,得到 %+v", errs)
|
||||
}
|
||||
for _, raw := range errs {
|
||||
text, _ := raw.(string)
|
||||
if !strings.Contains(text, "heat") {
|
||||
t.Errorf("行级错误应说明 heat 非法,得到 %q", text)
|
||||
}
|
||||
}
|
||||
|
||||
// 正常值入库;heat 非法的两行被拦,不影响同一份表里的其余行。
|
||||
for idCard, want := range map[string]int64{
|
||||
"110101199001011234": 1,
|
||||
"110101199001011235": 2,
|
||||
"110101199001011236": 3,
|
||||
} {
|
||||
var heat int64
|
||||
if err := env.ev.QueryRow(
|
||||
`SELECT e.heat FROM entries e JOIN athletes a ON a.id = e.athlete_id WHERE a.id_card = ?`, idCard).
|
||||
Scan(&heat); err != nil {
|
||||
t.Fatalf("读 %s 的报名批次: %v", idCard, err)
|
||||
}
|
||||
if heat != want {
|
||||
t.Errorf("%s 的批次应为 %d,得到 %d", idCard, want, heat)
|
||||
}
|
||||
}
|
||||
// 非法值的两行没有落库。
|
||||
assertCount(t, env, `SELECT COUNT(*) FROM athletes WHERE id_card IN ('110101199001011237','110101199001011238')`, 0)
|
||||
// 表头没有 heat 列时(老模板)照常导入,批次为未分批。
|
||||
status, env2 = env.postImport(t, client, "/api/entries/import", importHeader+
|
||||
"\nM100,男子,A,周八,110101199001011239,男,,,,registered,\n", "")
|
||||
if status != http.StatusOK || !env2.OK {
|
||||
t.Fatalf("无 heat 列的老模板应照常导入,得到 %d %+v", status, env2.Error)
|
||||
}
|
||||
var heat any
|
||||
if err := env.ev.QueryRow(
|
||||
`SELECT e.heat FROM entries e JOIN athletes a ON a.id = e.athlete_id WHERE a.id_card = '110101199001011239'`).
|
||||
Scan(&heat); err != nil {
|
||||
t.Fatalf("读老模板导入的报名批次: %v", err)
|
||||
}
|
||||
if heat != nil {
|
||||
t.Fatalf("无 heat 列时应为未分批,得到 %v", heat)
|
||||
}
|
||||
}
|
||||
|
||||
// 导入留空 = 未分批:显式带 heat 列但留空,写入 NULL。
|
||||
func TestImportEntriesHeatBlankMeansUnbatched(t *testing.T) {
|
||||
env, _, client := recorderWithSeed(t)
|
||||
|
||||
body := importHeaderHeat + "\nM100,男子,A,张三,110101199001011234,男,,,,,registered,\n"
|
||||
status, env2 := env.postImport(t, client, "/api/entries/import", body, "")
|
||||
if status != http.StatusOK || !env2.OK {
|
||||
t.Fatalf("导入应 200,得到 %d %+v", status, env2.Error)
|
||||
}
|
||||
if result := decodeData[map[string]any](t, env2); result["created"] != float64(1) {
|
||||
t.Fatalf("应新建 1 条,得到 %+v", result)
|
||||
}
|
||||
var heat any
|
||||
if err := env.ev.QueryRow(
|
||||
`SELECT e.heat FROM entries e JOIN athletes a ON a.id = e.athlete_id WHERE a.id_card = '110101199001011234'`).
|
||||
Scan(&heat); err != nil {
|
||||
t.Fatalf("读报名批次: %v", err)
|
||||
}
|
||||
if heat != nil {
|
||||
t.Fatalf("留空应为未分批(NULL),得到 %v", heat)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user