Files
xk-hy-forward-go/internal/forward/testweb/prescription_handlers.go
2026-07-21 16:35:46 +08:00

57 lines
1.6 KiB
Go

package testweb
import (
"net/http"
"strconv"
"strings"
)
// handlePrescriptionPage 处方业务记录 HTML 页。
func (s *server) handlePrescriptionPage(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/t/prescription" && r.URL.Path != "/t/prescription/" {
http.NotFound(w, r)
return
}
b, err := webFS.ReadFile("web/prescription.html")
if err != nil {
http.Error(w, "page not found", http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
_, _ = w.Write(b)
}
// handlePrescriptionRecords 返回 prescription-audit.jsonl 列表。
func (s *server) handlePrescriptionRecords(w http.ResponseWriter, r *http.Request) {
bizType := strings.TrimSpace(r.URL.Query().Get("bizType"))
limit := 100
if v := r.URL.Query().Get("limit"); v != "" {
if n, err := strconv.Atoi(v); err == nil && n > 0 {
limit = n
}
}
list, err := ListPrescriptionRecords(s.deps.APILogRoot, bizType, limit)
if err != nil {
writeErr(w, err.Error(), http.StatusInternalServerError)
return
}
if list == nil {
list = []PrescriptionRecord{}
}
writeJSON(w, map[string]any{"items": list, "bizType": bizType, "limit": limit})
}
// handlePrescriptionRebuild 全量重建处方业务索引。
func (s *server) handlePrescriptionRebuild(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost && r.Method != http.MethodGet {
writeErr(w, "GET or POST only", http.StatusMethodNotAllowed)
return
}
n, err := RebuildPrescriptionIndex(s.deps.APILogRoot)
if err != nil {
writeErr(w, err.Error(), http.StatusInternalServerError)
return
}
writeJSON(w, map[string]any{"ok": true, "count": n})
}