34 lines
963 B
Go
34 lines
963 B
Go
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,
|
|
})
|
|
}
|
|
} |