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 三层安全机制) ============
|
2026-11-26 17:18:58 +08:00
|
|
|
|
// 库管在 WMS 侧的 AGV 交互入口:托盘回收派车(托盘工作台)。
|
|
|
|
|
|
// 所有确认动作都在 MES「到位待令(ARRIVED)」闸门后执行;配送派车统一走配送单(2026-11-26 定稿)。
|
2026-11-04 19:06:03 +08:00
|
|
|
|
|
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 {
|
2026-11-26 17:18:58 +08:00
|
|
|
|
fail(w, http.StatusBadGateway, "MES 服务不可达,数据未读取("+err.Error()+");请检查服务后刷新重试")
|
2026-11-03 18:29:31 +08:00
|
|
|
|
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 {
|
2026-11-26 17:18:58 +08:00
|
|
|
|
fail(w, http.StatusBadGateway, "MES 服务不可达,数据未读取("+err.Error()+");请检查服务后刷新重试")
|
2026-11-03 18:29:31 +08:00
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
out := []map[string]any{}
|
|
|
|
|
|
for _, d := range dockViews(docks) {
|
|
|
|
|
|
if d["stationNo"] == stationNo {
|
2026-11-26 17:18:58 +08:00
|
|
|
|
// 2026-11-26:派车弹窗接驳台卡片需要状态(空位/有托盘/传感器离线),直接平铺点击选择。
|
|
|
|
|
|
out = append(out, map[string]any{
|
|
|
|
|
|
"code": d["dockCode"], "label": d["label"], "name": d["name"],
|
|
|
|
|
|
"sideCn": d["sideCn"], "status": d["status"],
|
|
|
|
|
|
"hasPallet": d["hasPallet"], "sensorHasPallet": d["sensorHasPallet"], "sensorOk": d["sensorOk"],
|
|
|
|
|
|
})
|
2026-11-03 18:29:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
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,
|
2026-11-19 08:31:05 +08:00
|
|
|
|
"sensorHasPallet": d.SensorHasPallet, "sensorOk": d.SensorOk,
|
2026-11-03 18:29:31 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
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 {
|
2026-11-26 17:18:58 +08:00
|
|
|
|
fail(w, http.StatusBadGateway, "MES 服务不可达,数据未读取("+err.Error()+");请检查服务后刷新重试")
|
2026-11-04 19:06:03 +08:00
|
|
|
|
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})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|