1. 全局替换"工序"为"工艺"统一术语,包括页面文案、枚举、注释
2. 重构工单与工件工艺数据模型:
- 新增工艺组合表flow_material作为备料/齐套唯一源头
- 新增工位状态表station_state支持自主停单/恢复接单
- 移除station_process派工表,改用工单工艺组合作为路线唯一源头
- 替换processCode为flowId作为工艺关联标识
- 重构工件当前进度字段为currentStationNo
3. 删除冗余的静态备份资源文件
4. 调整物料选择组件默认启用仅显示激活物料
5. 优化工单创建/编辑逻辑,新增工艺组合校验与保存
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))
|
|
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))
|
|
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)
|
|
}
|
|
}
|