37 lines
858 B
Go
37 lines
858 B
Go
package handler
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"net/http"
|
||
|
|
"strconv"
|
||
|
|
|
||
|
|
"bj_power_workstation/internal/svc"
|
||
|
|
)
|
||
|
|
|
||
|
|
// tighteningListHandler GET /api/tightening/list?sn=&only_pending=true&limit=100
|
||
|
|
// 查询本地 torque_results(最新优先)。
|
||
|
|
func tighteningListHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
||
|
|
q := r.URL.Query()
|
||
|
|
sn := q.Get("sn")
|
||
|
|
|
||
|
|
onlyPending := false
|
||
|
|
if v, err := strconv.ParseBool(q.Get("only_pending")); err == nil {
|
||
|
|
onlyPending = v
|
||
|
|
}
|
||
|
|
|
||
|
|
limit := atoi(q.Get("limit"), 100)
|
||
|
|
if limit <= 0 || limit > 500 {
|
||
|
|
limit = 500
|
||
|
|
}
|
||
|
|
|
||
|
|
list, err := ctx.Store.ListTorqueResults(sn, onlyPending, limit)
|
||
|
|
if err != nil {
|
||
|
|
fail(w, http.StatusInternalServerError, "查询拧紧结果失败:"+err.Error())
|
||
|
|
return
|
||
|
|
}
|
||
|
|
ok(w, map[string]any{
|
||
|
|
"total": len(list),
|
||
|
|
"list": list,
|
||
|
|
})
|
||
|
|
}
|
||
|
|
}
|