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 返回「当前登录人」尚未成功上报的本地数据(失败列表), // 供前端在「同一人重新登录」时仅展示失败信息(不自动打开页面)。他人数据不被返回、不可见。 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{}}) return } queue, _ := ctx.Store.PendingQueueItemsForOperator(ss.UserID, 200) torque, _ := ctx.Store.PendingTorqueResultsForOperator(ss.UserID, 200) ok(w, map[string]any{ "pendingQueue": len(queue), "pendingTorque": len(torque), "pendingTotal": len(queue) + len(torque), "queue": queue, "torque": torque, }) } }