- 用户表扩展:MES/WMS user 实体新增字段,新增 active_token 迁移 SQL(2026-11-11) - 会话机制:MES 新增 session_guard,重构 token/auth/jwt/perm 与路由;WMS/工作站同步令牌续签与鉴权 - 看板(board):调整 MES 看板产线/生产/侧栏/仓库组件及样式;WMS 看板展示页同步调整 - 工位终端后端:完善报警流、绑定、PLC 对账、拧紧、proxy、上报、站点告警/操作等 handler,补充 mes client/store - 工位终端前端:登录/主界面/各操作面板调整,新增滚动分页与多语言 yaml 文案,刷新构建产物 - MES 业务:新增流程链 logic,调整待审核/产能支撑/产品工艺/设置页、PLC 监控与帮助文档,刷新构建产物 - 更新问题记录文档
83 lines
2.8 KiB
Go
83 lines
2.8 KiB
Go
package handler
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"net/http"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"bj_power_workstation/internal/svc"
|
|
)
|
|
|
|
// bindPanelHandler 代理 MES GET /api/internal/workpiece/bind-panel?sn=&flowId=。
|
|
// 工位终端扫码工件后按工位绑定工艺(flowId)拉取应装/已装物料清单(装机绑定引导),响应原样透传。
|
|
func bindPanelHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
sn := strings.TrimSpace(r.URL.Query().Get("sn"))
|
|
flowId := strings.TrimSpace(r.URL.Query().Get("flowId"))
|
|
if sn == "" || flowId == "" {
|
|
fail(w, http.StatusBadRequest, "缺少 sn / flowId 参数")
|
|
return
|
|
}
|
|
body, _, err := ctx.Mes.Get("/api/internal/workpiece/bind-panel",
|
|
url.Values{"sn": {sn}, "flowId": {flowId}})
|
|
if err != nil {
|
|
fail(w, http.StatusBadGateway, "MES 服务不可达:"+errString(err))
|
|
return
|
|
}
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(http.StatusOK)
|
|
_, _ = w.Write(body)
|
|
}
|
|
}
|
|
|
|
// bindRecordHandler POST /api/bind/record —— 工位扫/录一个物料(SN/批次)→ MES 装机绑定。
|
|
// 透传原 body,MES 负责校验(料是否属于本工艺装配 / 电气件SN防重 / 幂等)。
|
|
// 请求体按定稿契约:{sn, flowId, stationNo, items:[{materialCode, bindValue}]}。
|
|
func bindRecordHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
payload, err := io.ReadAll(r.Body)
|
|
if err != nil {
|
|
fail(w, http.StatusBadRequest, "请求体读取失败")
|
|
return
|
|
}
|
|
var probe struct {
|
|
Sn string `json:"sn"`
|
|
FlowId int `json:"flowId"`
|
|
}
|
|
_ = json.Unmarshal(payload, &probe)
|
|
if probe.Sn == "" || probe.FlowId <= 0 {
|
|
fail(w, http.StatusBadRequest, "sn / flowId 必填")
|
|
return
|
|
}
|
|
body, _, err := ctx.Mes.Post("/api/internal/workpiece/binds", json.RawMessage(payload), bearerOf(r))
|
|
if err != nil {
|
|
fail(w, http.StatusBadGateway, "MES 服务不可达:"+errString(err))
|
|
return
|
|
}
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(http.StatusOK)
|
|
_, _ = w.Write(body)
|
|
}
|
|
}
|
|
|
|
// bindRemoveHandler POST /api/bind/remove —— 撤销误绑(未报工前)
|
|
func bindRemoveHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
payload, err := io.ReadAll(r.Body)
|
|
if err != nil {
|
|
fail(w, http.StatusBadRequest, "请求体读取失败")
|
|
return
|
|
}
|
|
body, _, err := ctx.Mes.Post("/api/internal/workpiece/binds/remove", json.RawMessage(payload), bearerOf(r))
|
|
if err != nil {
|
|
fail(w, http.StatusBadGateway, "MES 服务不可达:"+errString(err))
|
|
return
|
|
}
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
w.WriteHeader(http.StatusOK)
|
|
_, _ = w.Write(body)
|
|
}
|
|
}
|