2026-11-03 18:29:31 +08:00
|
|
|
|
package handler
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"encoding/json"
|
|
|
|
|
|
"net/http"
|
|
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
|
|
|
|
"bj_power_wms/internal/mesclient"
|
|
|
|
|
|
"bj_power_wms/internal/svc"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// ============ AGV 三段链 / 托盘工作台(2026-11-03 三层安全机制) ============
|
|
|
|
|
|
// 库管在 WMS 侧的 AGV 交互入口:装货确认(叫料队列行内)与托盘回收派车(托盘工作台)。
|
|
|
|
|
|
// 所有确认动作都在 MES「到位待令(ARRIVED)」闸门后执行;空车段由 MES 业务自动触发免弹窗。
|
|
|
|
|
|
|
|
|
|
|
|
// ConfirmCallLoadHandler POST /call/confirm-load {requestNo}
|
|
|
|
|
|
// 库管在叫料队列对「到位待令」的空车段点「确认装车并送货」→ MES 生成重载运输段发往工位接驳台。
|
|
|
|
|
|
func ConfirmCallLoadHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
|
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
var req struct {
|
|
|
|
|
|
RequestNo string `json:"requestNo"`
|
|
|
|
|
|
Operator string `json:"operator"`
|
|
|
|
|
|
}
|
|
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
|
|
|
|
fail(w, http.StatusBadRequest, "参数错误: "+err.Error())
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
if req.RequestNo == "" {
|
|
|
|
|
|
fail(w, http.StatusBadRequest, "requestNo 必填")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
op := r.Header.Get("X-Username")
|
|
|
|
|
|
if op == "" {
|
|
|
|
|
|
op = req.Operator
|
|
|
|
|
|
}
|
|
|
|
|
|
if err := ctx.Mes.AgvConfirm(r.Context(), req.RequestNo, "load_go", "", op); err != nil {
|
|
|
|
|
|
fail(w, http.StatusBadGateway, err.Error())
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
ok(w, map[string]any{"ok": true})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 19:06:03 +08:00
|
|
|
|
// DispatchCallHandler POST /call/dispatch {requestNo}
|
|
|
|
|
|
// 库管人工派车(2026-11-03 定论:废除备料完成自动派车)——叫料队列点「送货」,AGV 才出发去装货点。
|
|
|
|
|
|
func DispatchCallHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
|
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
var req struct {
|
|
|
|
|
|
RequestNo string `json:"requestNo"`
|
|
|
|
|
|
Operator string `json:"operator"`
|
|
|
|
|
|
}
|
|
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
|
|
|
|
fail(w, http.StatusBadRequest, "参数错误: "+err.Error())
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
if req.RequestNo == "" {
|
|
|
|
|
|
fail(w, http.StatusBadRequest, "requestNo 必填")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
op := r.Header.Get("X-Username")
|
|
|
|
|
|
if op == "" {
|
|
|
|
|
|
op = req.Operator
|
|
|
|
|
|
}
|
|
|
|
|
|
if err := ctx.Mes.AgvDispatch(r.Context(), req.RequestNo, op); err != nil {
|
|
|
|
|
|
fail(w, http.StatusBadGateway, err.Error())
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
ok(w, map[string]any{"ok": true})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-03 18:29:31 +08:00
|
|
|
|
// PalletDocksHandler GET /pallet/docks —— 接驳台台账列表(托盘工作台:谁有托盘/空托盘待回收)。
|
|
|
|
|
|
func PalletDocksHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
|
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
docks, err := ctx.Mes.ListDocks(r.Context())
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
fail(w, http.StatusBadGateway, "MES 不可达: "+err.Error())
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
ok(w, map[string]any{"list": dockViews(docks)})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// StationDocksProxyHandler GET /pallet/station-docks?stationNo= —— 某工位两个接驳台(代退料选左/右)。
|
|
|
|
|
|
func StationDocksProxyHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
|
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
stationNo, _ := strconv.Atoi(r.URL.Query().Get("stationNo"))
|
|
|
|
|
|
if stationNo <= 0 {
|
|
|
|
|
|
fail(w, http.StatusBadRequest, "stationNo 必填")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
docks, err := ctx.Mes.ListDocks(r.Context())
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
fail(w, http.StatusBadGateway, "MES 不可达: "+err.Error())
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
out := []map[string]any{}
|
|
|
|
|
|
for _, d := range dockViews(docks) {
|
|
|
|
|
|
if d["stationNo"] == stationNo {
|
|
|
|
|
|
out = append(out, map[string]any{"code": d["dockCode"], "label": d["label"]})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
ok(w, map[string]any{"docks": out})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// dockViews 统一接驳台视图(含操作员左右中文)。
|
|
|
|
|
|
func dockViews(docks []mesclient.DockRow) []map[string]any {
|
|
|
|
|
|
out := make([]map[string]any, 0, len(docks))
|
|
|
|
|
|
for _, d := range docks {
|
|
|
|
|
|
side := "右"
|
|
|
|
|
|
if d.Side == "left" {
|
|
|
|
|
|
side = "左"
|
|
|
|
|
|
}
|
|
|
|
|
|
out = append(out, map[string]any{
|
|
|
|
|
|
"dockCode": d.DockCode, "name": d.Name, "dockType": d.DockType,
|
|
|
|
|
|
"stationNo": d.StationNo, "side": d.Side, "sideCn": side,
|
|
|
|
|
|
"label": "工位" + strconv.Itoa(d.StationNo) + " " + side + "(" + d.DockCode + ")",
|
|
|
|
|
|
"hasPallet": d.HasPallet, "palletRef": d.PalletRef, "status": d.Status,
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
return out
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-04 19:06:03 +08:00
|
|
|
|
// Jbt21FreeHandler GET /pallet/jbt21-free
|
|
|
|
|
|
// 库房接驳台 JBT21 空位查询(转发 MES):无空位时托盘回收「派 AGV」按钮禁用并提示(2026-11-04 定稿 Q5)。
|
|
|
|
|
|
func Jbt21FreeHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
|
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
free, reason, err := ctx.Mes.Jbt21Free(r.Context())
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
fail(w, http.StatusBadGateway, "MES 不可达: "+err.Error())
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
ok(w, map[string]any{"free": free, "reason": reason})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-11-03 18:29:31 +08:00
|
|
|
|
// PalletDispatchHandler POST /pallet/dispatch {dockCode, operator}
|
|
|
|
|
|
// 库管派 AGV 回收指定工位接驳台的托盘(空车段免弹窗,到位待令后确认装车)。
|
|
|
|
|
|
func PalletDispatchHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
|
|
|
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
|
var req struct {
|
|
|
|
|
|
DockCode string `json:"dockCode"`
|
|
|
|
|
|
Operator string `json:"operator"`
|
|
|
|
|
|
}
|
|
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
|
|
|
|
fail(w, http.StatusBadRequest, "参数错误: "+err.Error())
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
if req.DockCode == "" {
|
|
|
|
|
|
fail(w, http.StatusBadRequest, "dockCode 必填")
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
op := r.Header.Get("X-Username")
|
|
|
|
|
|
if op == "" {
|
|
|
|
|
|
op = req.Operator
|
|
|
|
|
|
}
|
|
|
|
|
|
if err := ctx.Mes.PalletDispatch(r.Context(), req.DockCode, op); err != nil {
|
|
|
|
|
|
fail(w, http.StatusBadGateway, err.Error())
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
ok(w, map[string]any{"ok": true})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|