feat: 大屏控制可看局域网设备并逐台切页 + 两种新导出(单页成绩 / 单位积分总明细)

## 大屏控制(用户:管理面板只能看到本机显示器,看不到局域网设备;也不能给某块屏单独切页)
- 服务端:`POST /api/display/command` 新增可选 `targets []string` —— 空 = 广播(公告语义不变),
  非空 = 只发给点名的实例并返回命中数;命中 0 个返回 404 +「目标大屏已离线,请刷新在线列表」
  (不落审计、公告也不落库)。`DisplaySender` 签名随之扩展,新增
  `Hub.SendCommandToInstances`(与按房间的 SendCommand 并存)。
- 服务端:WS `hello` 新增可选 `screen`,`realtime.Instance` 新增 `Screen`(不带 omitempty,
  局域网浏览器恒为空串),这样管理端能把「本机显示器」与「在线实例」精确对上。
- 管理端「大屏控制」:写死的「在线看板」占位换成真实列表(5 秒轮询、页面隐藏停表),
  列出实例 id / 在线离线 / 落后 / 屏号或「局域网浏览器」/ 当前页 / 来源 / 心跳;
  每行可单独切页;本机显示器卡片补「当前页」与逐屏切页;离线时控件置灰并说明原因。
  页面下拉改为共用大屏那份页名清单(管理端两处标签随之变为「个人积分奖牌榜」「分项成绩」)。

## 导出(用户:保留多页工作簿的同时,再要一种全平铺单页;积分榜明细也要能导出)
- 新增 `GET /api/export/all-flat.xlsx` → `赛事成绩总表(单页).xlsx`:一个工作簿一张表,
  列 = 大项/小项/组别/名次/号码/单位/运动员-队/成绩/积分/状态/备注;前三列取
  `EventSheet` 的结构化字段(不解析标题),后 8 列就是 `eventColumns` 本身(append 拼出,
  两处不可能漂移)。**既有「全部」(all.xlsx,多 sheet)一字未动。**
- 新增 `GET /api/export/teams.xlsx` → `单位积分总明细.xlsx`:一张带「单位」列的总表 +
  每个有明细行的单位一张分表;**无明细行的单位不出分表**(空表没信息量,且会把假删除的
  隐藏单位名字重新印进导出件);已隐藏但有流水的单位照常出表(它在榜单上)。
- 积分榜页:页头「导出总明细」、单位明细面板「导出该单位明细」;导出页新增「全部(单页)」。

测试:服务端 12 包全绿 / 347 个测试函数;前端 vue-tsc 通过、184 例全过;Console 18 文件。
docs/ 与 devdocs/ 同步(含新增 Q65–Q70 与两轮进度记录)。
This commit is contained in:
AskaEth committed 2026-09-11 00:44:03 +08:00
1 parent 793d2ac064
commit 782a38f82f
33 files changed
+2473 -119

No files matched your search

+159
View File
@@ -749,3 +749,162 @@ func TestGuardLoopRecoversPanic(t *testing.T) {
t.Fatalf("panic 后关闭码应为 %d,得到 %d", websocket.StatusInternalError, c.closeCode)
}
}
// ---------- 按实例定向下发 ----------
// instancePage 取注册表里某个实例的当前页;实例不存在返回空串。
func instancePage(insts []Instance, id string) string {
for _, st := range insts {
if st.ID == id {
return st.Page
}
}
return ""
}
// 定向下发只发给被点名的在线实例;注册表里的「当前页」也只更新那一块屏。
func TestSendCommandTargetsSingleInstance(t *testing.T) {
env := newTestEnv(t)
a := env.dial(t, &helloPayload{Role: RoleDisplay, InstanceID: "screen-a", Page: "standings", Screen: "1"})
b := env.dial(t, &helloPayload{Role: RoleDisplay, InstanceID: "screen-b", Page: "standings", Screen: "2"})
a.recvEvent(EventSnapshot)
b.recvEvent(EventSnapshot)
cmd, err := NewDisplayCommand(CmdGoto, map[string]string{"page": "medals"})
if err != nil {
t.Fatalf("构造 goto: %v", err)
}
matched, err := env.hub.SendCommandToInstances([]string{"screen-a"}, cmd)
if err != nil {
t.Fatalf("定向下发: %v", err)
}
if matched != 1 {
t.Fatalf("命中实例数应为 1,得到 %d", matched)
}
if got := decode[DisplayCommand](t, a.recvEvent(EventDisplayCommand)); got.Action != CmdGoto {
t.Fatalf("被点名的实例应收到 goto,得到 %s", got.Action)
}
// 没被点名的实例一条都不能收到(心跳之外的静默是这条断言的全部意义)。
if ev, _, ok := b.recvWithin(200 * time.Millisecond); ok {
t.Fatalf("未被点名的实例不该收到消息,得到 %s", ev)
}
insts := env.hub.Instances()
if got := instancePage(insts, "screen-a"); got != "medals" {
t.Fatalf("被点名实例的当前页应更新为 medals,得到 %q", got)
}
if got := instancePage(insts, "screen-b"); got != "standings" {
t.Fatalf("未被点名实例的当前页不该变,得到 %q", got)
}
}
// targets 为空保持广播语义:所有在线实例都收到。
func TestSendCommandEmptyTargetsBroadcasts(t *testing.T) {
env := newTestEnv(t)
a := env.dial(t, &helloPayload{Role: RoleDisplay, InstanceID: "screen-a"})
b := env.dial(t, &helloPayload{Role: RoleDisplay, InstanceID: "screen-b"})
a.recvEvent(EventSnapshot)
b.recvEvent(EventSnapshot)
cmd, err := NewDisplayCommand(CmdLock, map[string]any{})
if err != nil {
t.Fatalf("构造 lock: %v", err)
}
matched, err := env.hub.SendCommandToInstances(nil, cmd)
if err != nil {
t.Fatalf("广播: %v", err)
}
if matched != 2 {
t.Fatalf("广播应命中 2 个在线实例,得到 %d", matched)
}
for _, c := range []*wsClient{a, b} {
if got := decode[DisplayCommand](t, c.recvEvent(EventDisplayCommand)); got.Action != CmdLock {
t.Fatalf("广播时每个实例都应收到 lock,得到 %s", got.Action)
}
}
}
// 目标全都不在线(已断开或 id 不存在):命中 0,且没有任何连接收到指令。
func TestSendCommandTargetsOfflineInstances(t *testing.T) {
env := newTestEnv(t)
a := env.dial(t, &helloPayload{Role: RoleDisplay, InstanceID: "screen-a"})
a.recvEvent(EventSnapshot)
a.close()
waitFor(t, "实例离线", func() bool {
insts := env.hub.Instances()
return len(insts) == 1 && !insts[0].Online
})
cmd, err := NewDisplayCommand(CmdReload, map[string]any{})
if err != nil {
t.Fatalf("构造 reload: %v", err)
}
matched, err := env.hub.SendCommandToInstances([]string{"screen-a", "never-seen"}, cmd)
if err != nil {
t.Fatalf("定向下发: %v", err)
}
if matched != 0 {
t.Fatalf("离线/不存在的实例不该计入命中,得到 %d", matched)
}
}
// 目标里混了在线与离线:在线的收到,命中数只算在线的。
func TestSendCommandTargetsMixedOnlineOffline(t *testing.T) {
env := newTestEnv(t)
a := env.dial(t, &helloPayload{Role: RoleDisplay, InstanceID: "screen-a"})
b := env.dial(t, &helloPayload{Role: RoleDisplay, InstanceID: "screen-b"})
a.recvEvent(EventSnapshot)
b.recvEvent(EventSnapshot)
b.close()
waitFor(t, "screen-b 离线", func() bool {
for _, st := range env.hub.Instances() {
if st.ID == "screen-b" {
return !st.Online
}
}
return false
})
cmd, err := NewDisplayCommand(CmdGoto, map[string]string{"page": "results"})
if err != nil {
t.Fatalf("构造 goto: %v", err)
}
matched, err := env.hub.SendCommandToInstances([]string{"screen-a", "screen-b"}, cmd)
if err != nil {
t.Fatalf("定向下发: %v", err)
}
if matched != 1 {
t.Fatalf("只应在线的 screen-a 计入命中,得到 %d", matched)
}
if got := decode[DisplayCommand](t, a.recvEvent(EventDisplayCommand)); got.Action != CmdGoto {
t.Fatalf("在线的实例应收到 goto,得到 %s", got.Action)
}
}
// 非法 action 走定向通道要报错,不能静默丢掉。
func TestSendCommandTargetsRejectsUnknownAction(t *testing.T) {
env := newTestEnv(t)
if _, err := env.hub.SendCommandToInstances([]string{"screen-a"}, DisplayCommand{Action: "nope"}); err == nil {
t.Fatal("非法 action 应报错")
}
}
// 屏号上报:Console 窗口带 screen,局域网浏览器不带(空串),两者都要能查出来。
func TestDisplayInstancesReportScreen(t *testing.T) {
env := newTestEnv(t)
console := env.dial(t, &helloPayload{Role: RoleDisplay, InstanceID: "console-1", Page: "standings", Screen: "2"})
lan := env.dial(t, &helloPayload{Role: RoleDisplay, InstanceID: "lan-1", Page: "medals"})
console.recvEvent(EventSnapshot)
lan.recvEvent(EventSnapshot)
byID := make(map[string]Instance)
for _, st := range env.hub.Instances() {
byID[st.ID] = st
}
if got := byID["console-1"].Screen; got != "2" {
t.Fatalf("Console 窗口的屏号应为 2,得到 %q", got)
}
if got := byID["lan-1"].Screen; got != "" {
t.Fatalf("局域网浏览器不带屏号,应为空串,得到 %q", got)
}
}