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

35 lines
964 B
Go
Raw Normal View History

2026-08-27 19:50:57 +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 返回待同步条数统计。
func syncStatsHandler(ctx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
pendingTorque, err1 := ctx.Store.PendingTorqueCount()
pendingQueue, err2 := ctx.Store.PendingQueueCount()
if err1 != nil || err2 != nil {
fail(w, http.StatusInternalServerError, "查询待同步统计失败")
return
}
ok(w, map[string]any{
"pendingTorque": pendingTorque,
"pendingQueue": pendingQueue,
})
}
}