Files
bj_power/bj_power_workstation/internal/handler/sync.go
T

39 lines
1.3 KiB
Go
Raw Normal View History

2026-08-28 15:06:01 +08:00
package handler
import (
"net/http"
"bj_power_workstation/internal/svc"
)
// syncFlushHandler POST /api/sync/flush 手动立即执行一轮同步,返回本次成功条数。
func syncFlushHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
count := ctx.Syncer.RunOnce(r.Context())
ok(w, map[string]any{
"count": count,
"message": "本轮同步完成",
})
}
}
// syncStatsHandler GET /api/sync/stats 返回「当前登录人」尚未成功上报的本地数据(失败列表),
// 供前端在「同一人重新登录」时仅展示失败信息(不自动打开页面)。他人数据不被返回、不可见。
2026-08-28 15:06:01 +08:00
func syncStatsHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
ss, err := ctx.Store.GetStationSession()
if err != nil || ss == nil {
ok(w, map[string]any{"pendingTorque": 0, "pendingQueue": 0, "pendingTotal": 0, "queue": []any{}, "torque": []any{}})
2026-08-28 15:06:01 +08:00
return
}
queue, _ := ctx.Store.PendingQueueItemsForOperator(ss.UserID, 200)
torque, _ := ctx.Store.PendingTorqueResultsForOperator(ss.UserID, 200)
2026-08-28 15:06:01 +08:00
ok(w, map[string]any{
"pendingQueue": len(queue),
"pendingTorque": len(torque),
"pendingTotal": len(queue) + len(torque),
"queue": queue,
"torque": torque,
2026-08-28 15:06:01 +08:00
})
}
}