Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
28 lines
789 B
Go
28 lines
789 B
Go
package adminhandler
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/baicai2026-baicai/goods/api/internal/adminstore"
|
|
)
|
|
|
|
func (h *Handler) ImportBypos(w http.ResponseWriter, r *http.Request) {
|
|
var records []adminstore.ByposRecord
|
|
dec := json.NewDecoder(http.MaxBytesReader(w, r.Body, 50<<20))
|
|
if err := dec.Decode(&records); err != nil {
|
|
writeError(w, http.StatusBadRequest, "bad_request", "请求体应为 JSON 数组")
|
|
return
|
|
}
|
|
if len(records) == 0 {
|
|
writeError(w, http.StatusBadRequest, "empty", "\u6ca1\u6709\u53ef\u5bfc\u5165\u7684\u8bb0\u5f55")
|
|
return
|
|
}
|
|
result, err := h.store.ImportByposRecords(r.Context(), records)
|
|
if err != nil {
|
|
writeError(w, http.StatusInternalServerError, "import_error", err.Error())
|
|
return
|
|
}
|
|
writeJSON(w, http.StatusOK, result)
|
|
}
|