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:
1 parent
793d2ac064
commit
782a38f82f
33 files changed
+2473
-119
No files matched your search
@@ -3,8 +3,10 @@ package realtime
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -390,7 +392,7 @@ func (h *Hub) handleHello(ctx context.Context, c *client, p helloPayload) {
|
||||
if id == "" {
|
||||
id = p.DisplayKey
|
||||
}
|
||||
h.registerDisplay(c, id, p.Page)
|
||||
h.registerDisplay(c, id, p.Page, p.Screen)
|
||||
h.join(c, RoomDisplay)
|
||||
}
|
||||
|
||||
@@ -528,7 +530,7 @@ func (h *Hub) SendCommandTo(room string, cmd DisplayCommand) {
|
||||
return
|
||||
}
|
||||
if cmd.Action == CmdGoto && (room == "" || room == RoomDisplay) {
|
||||
h.setInstancePage(pageFromPayload(cmd.Payload))
|
||||
h.setInstancePage(pageFromPayload(cmd.Payload), nil)
|
||||
}
|
||||
|
||||
h.sendMu.Lock()
|
||||
@@ -544,6 +546,62 @@ func (h *Hub) SendCommandTo(room string, cmd DisplayCommand) {
|
||||
}
|
||||
}
|
||||
|
||||
// SendCommandToInstances 按实例定向下发 display:command,返回命中的实例数。
|
||||
//
|
||||
// targets 是要控制的 instanceID(GET /api/display/instances 里的 id);为空时退化成广播,
|
||||
// 公告这类全屏指令靠的就是广播,这条语义不能改。已离线的实例不计入命中,
|
||||
// 调用方据此告诉现场「那块屏没收到」。非法 action 返回错误而不是静默丢弃,
|
||||
// 定向指令需要一个明确的失败信号。
|
||||
func (h *Hub) SendCommandToInstances(targets []string, cmd DisplayCommand) (int, error) {
|
||||
if !ValidDisplayAction(cmd.Action) {
|
||||
return 0, fmt.Errorf("未知的大屏指令 %q", cmd.Action)
|
||||
}
|
||||
if len(targets) == 0 {
|
||||
h.SendCommand(cmd)
|
||||
return h.onlineDisplayCount(), nil
|
||||
}
|
||||
|
||||
wanted := make(map[string]bool, len(targets))
|
||||
for _, id := range targets {
|
||||
if id = strings.TrimSpace(id); id != "" {
|
||||
wanted[id] = true
|
||||
}
|
||||
}
|
||||
|
||||
h.sendMu.Lock()
|
||||
matched := make(map[string]bool, len(wanted))
|
||||
for _, c := range h.roomClients(RoomDisplay) {
|
||||
c.mu.Lock()
|
||||
greeted, id := c.greeted, c.instanceID
|
||||
c.mu.Unlock()
|
||||
if !greeted || !wanted[id] {
|
||||
continue
|
||||
}
|
||||
c.sendEvent(EventDisplayCommand, cmd)
|
||||
matched[id] = true
|
||||
}
|
||||
h.sendMu.Unlock()
|
||||
|
||||
if cmd.Action == CmdGoto {
|
||||
h.setInstancePage(pageFromPayload(cmd.Payload), targets)
|
||||
}
|
||||
return len(matched), nil
|
||||
}
|
||||
|
||||
// onlineDisplayCount 统计已握手且在线的实例数,用于告知调用方广播命中了几块屏。
|
||||
func (h *Hub) onlineDisplayCount() int {
|
||||
seen := make(map[string]bool)
|
||||
for _, c := range h.roomClients(RoomDisplay) {
|
||||
c.mu.Lock()
|
||||
greeted, id := c.greeted, c.instanceID
|
||||
c.mu.Unlock()
|
||||
if greeted && id != "" {
|
||||
seen[id] = true
|
||||
}
|
||||
}
|
||||
return len(seen)
|
||||
}
|
||||
|
||||
// checkSlow 用 ack 版本差识别慢客户端;超阈值直接断开,由客户端重连后补齐。
|
||||
func (h *Hub) checkSlow(c *client, version int64) {
|
||||
lag := h.slowLagValue()
|
||||
|
||||
Reference in new issue
Block a user