refactor: 重构工艺工序相关命名与数据模型
1. 全局替换"工序"为"工艺"统一术语,包括页面文案、枚举、注释
2. 重构工单与工件工艺数据模型:
- 新增工艺组合表flow_material作为备料/齐套唯一源头
- 新增工位状态表station_state支持自主停单/恢复接单
- 移除station_process派工表,改用工单工艺组合作为路线唯一源头
- 替换processCode为flowId作为工艺关联标识
- 重构工件当前进度字段为currentStationNo
3. 删除冗余的静态备份资源文件
4. 调整物料选择组件默认启用仅显示激活物料
5. 优化工单创建/编辑逻辑,新增工艺组合校验与保存
This commit is contained in:
@@ -10,18 +10,18 @@ import (
|
||||
"bj_power_workstation/internal/svc"
|
||||
)
|
||||
|
||||
// bindPanelHandler 代理 MES GET /api/internal/workpiece/bind-panel?sn=&processCode=。
|
||||
// 工位终端扫码工件后拉取本工序应装/已装物料清单(装机绑定引导),响应原样透传。
|
||||
// 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"))
|
||||
processCode := strings.TrimSpace(r.URL.Query().Get("processCode"))
|
||||
if sn == "" || processCode == "" {
|
||||
fail(w, http.StatusBadRequest, "缺少 sn / processCode 参数")
|
||||
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}, "processCode": {processCode}})
|
||||
url.Values{"sn": {sn}, "flowId": {flowId}})
|
||||
if err != nil {
|
||||
fail(w, http.StatusBadGateway, "MES 服务不可达:"+errString(err))
|
||||
return
|
||||
@@ -33,7 +33,8 @@ func bindPanelHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
|
||||
// bindRecordHandler POST /api/bind/record —— 工位扫/录一个物料(SN/批次)→ MES 装机绑定。
|
||||
// 透传原 body,MES 负责校验(料是否属于本产品本工序 / 电气件SN防重 / 幂等)。
|
||||
// 透传原 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)
|
||||
@@ -42,12 +43,12 @@ func bindRecordHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
var probe struct {
|
||||
Sn string `json:"sn"`
|
||||
ProcessCode int `json:"processCode"`
|
||||
Sn string `json:"sn"`
|
||||
FlowId int `json:"flowId"`
|
||||
}
|
||||
_ = json.Unmarshal(payload, &probe)
|
||||
if probe.Sn == "" || probe.ProcessCode <= 0 {
|
||||
fail(w, http.StatusBadRequest, "sn / processCode 必填")
|
||||
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))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -80,6 +81,49 @@ func stationsHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 工位停单/恢复接单(透传 MES 内部 API) ----------
|
||||
|
||||
// stationPauseHandler POST /api/station/pause —— 工人停止接单/恢复接单。
|
||||
// 请求体按定稿契约:{stationNo:number, paused:bool, reason:string};
|
||||
// operator 由本服务补当前登录人(MES 记录操作人,body 多余字段 MES 忽略),响应原样透传。
|
||||
func stationPauseHandler(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 {
|
||||
StationNo int `json:"stationNo"`
|
||||
Paused bool `json:"paused"`
|
||||
}
|
||||
_ = json.Unmarshal(payload, &probe)
|
||||
if probe.StationNo <= 0 {
|
||||
fail(w, http.StatusBadRequest, "缺少 stationNo 参数")
|
||||
return
|
||||
}
|
||||
var req map[string]any
|
||||
_ = json.Unmarshal(payload, &req)
|
||||
injectOperator(req, r)
|
||||
body, _ := json.Marshal(req)
|
||||
resp, _, perr := ctx.Mes.Post("/api/internal/station/pause", json.RawMessage(body))
|
||||
mesJSON(w, resp, perr)
|
||||
}
|
||||
}
|
||||
|
||||
// stationStateHandler GET /api/station/state?date=yyyy-MM-dd —— 当天各工位停单状态。
|
||||
// MES 响应 [{stationNo,paused,reason,operator}],原样透传;date 缺省由 MES 取当天。
|
||||
func stationStateHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var params url.Values
|
||||
if d := strings.TrimSpace(r.URL.Query().Get("date")); d != "" {
|
||||
params = url.Values{"date": {d}}
|
||||
}
|
||||
body, _, err := ctx.Mes.Get("/api/internal/station/state", params)
|
||||
mesJSON(w, body, err)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- 工艺 PDF 直通代理(含本地预缓存) ----------
|
||||
//
|
||||
// 前端 iframe/window.open 无法携带 Authorization,故提供免 JWT 前缀 /pdfopen/<name>,
|
||||
@@ -202,4 +246,4 @@ func streamBytes(body []byte, w http.ResponseWriter, name, contentType string) {
|
||||
w.Header().Set("X-PDF-Cache", "miss")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write(body)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,19 +34,19 @@ func mesRespCode(respBody []byte) string {
|
||||
}
|
||||
|
||||
// processDoneHandler POST /api/report/process-done
|
||||
// {sn, orderNo, processCode, stationNo, steps:[{stepId,name,value,text}], binds:[{materialCode,bindValue}], operator}
|
||||
// {sn, orderNo, flowId, stationNo, steps:[{stepId,name,value,text}], binds:[{materialCode,bindValue}], operator}
|
||||
// 流程:先冲刷一轮积压 → 实时报 MES /api/internal/station/report;
|
||||
// MES 不可达则写入 report_queue(kind=process_done) 并返回 data.queued=true(离线缓存稍后自动重传);
|
||||
// MES 业务拒绝(HTTP200+code!=0,如装配物料未绑齐/电气件SN重复)直接失败回前端,绝不入离线队。
|
||||
// binds 为本次工序的装机绑定(结构件批次/电气件SN),MES 端落库 + 齐套强校验;离线重传时原样携带。
|
||||
// binds 为本次工艺的装机绑定(结构件批次/电气件SN),MES 端落库 + 齐套强校验;离线重传时原样携带。
|
||||
func processDoneHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
Sn string `json:"sn"`
|
||||
OrderNo string `json:"orderNo"`
|
||||
ProcessCode int `json:"processCode"`
|
||||
StationNo int `json:"stationNo"`
|
||||
Steps []struct {
|
||||
Sn string `json:"sn"`
|
||||
OrderNo string `json:"orderNo"`
|
||||
FlowId int `json:"flowId"`
|
||||
StationNo int `json:"stationNo"`
|
||||
Steps []struct {
|
||||
StepId int `json:"stepId"`
|
||||
Name string `json:"name"`
|
||||
Value float64 `json:"value"`
|
||||
@@ -67,8 +67,8 @@ func processDoneHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
fail(w, http.StatusBadRequest, "参数错误")
|
||||
return
|
||||
}
|
||||
if req.Sn == "" || req.ProcessCode <= 0 || req.StationNo <= 0 {
|
||||
fail(w, http.StatusBadRequest, "sn/processCode/stationNo 必填")
|
||||
if req.Sn == "" || req.FlowId <= 0 || req.StationNo <= 0 {
|
||||
fail(w, http.StatusBadRequest, "sn/flowId/stationNo 必填")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -76,12 +76,12 @@ func processDoneHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
ctx.Syncer.RunOnce(r.Context())
|
||||
|
||||
body := map[string]any{
|
||||
"sn": req.Sn,
|
||||
"orderNo": req.OrderNo,
|
||||
"processCode": req.ProcessCode,
|
||||
"stationNo": req.StationNo,
|
||||
"steps": req.Steps,
|
||||
"operator": req.Operator,
|
||||
"sn": req.Sn,
|
||||
"orderNo": req.OrderNo,
|
||||
"flowId": req.FlowId,
|
||||
"stationNo": req.StationNo,
|
||||
"steps": req.Steps,
|
||||
"operator": req.Operator,
|
||||
}
|
||||
if len(req.Binds) > 0 {
|
||||
body["binds"] = req.Binds
|
||||
@@ -95,7 +95,7 @@ func processDoneHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
payloadBytes, _ := json.Marshal(body)
|
||||
|
||||
ctx.Store.AddEventLog(req.OrderNo, req.Operator, "process_done",
|
||||
"工序完成上报 sn="+req.Sn+" stationNo="+itoa(req.StationNo)+" processCode="+itoa(req.ProcessCode)+" binds="+itoa(len(req.Binds)))
|
||||
"工艺完成上报 sn="+req.Sn+" stationNo="+itoa(req.StationNo)+" flowId="+itoa(req.FlowId)+" binds="+itoa(len(req.Binds)))
|
||||
|
||||
respBody, _, err := ctx.Mes.Post("/api/internal/station/report", json.RawMessage(payloadBytes))
|
||||
if err != nil {
|
||||
@@ -119,16 +119,16 @@ func processDoneHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
|
||||
// tempStoreHandler POST /api/report/temp-store
|
||||
// {sn, orderNo, stationNo, processCode, operator} → 调 MES /api/internal/station/checkin(半成品入库)。
|
||||
// {sn, orderNo, stationNo, flowId, operator} → 调 MES /api/internal/station/checkin(半成品入库)。
|
||||
// 不可达时以同样 payload 写入 report_queue(kind=temp_store)。
|
||||
func tempStoreHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
Sn string `json:"sn"`
|
||||
OrderNo string `json:"orderNo"`
|
||||
StationNo int `json:"stationNo"`
|
||||
ProcessCode int `json:"processCode"`
|
||||
Operator string `json:"operator"`
|
||||
Sn string `json:"sn"`
|
||||
OrderNo string `json:"orderNo"`
|
||||
StationNo int `json:"stationNo"`
|
||||
FlowId int `json:"flowId"`
|
||||
Operator string `json:"operator"`
|
||||
}
|
||||
if err := parseJSON(r, &req); err != nil {
|
||||
fail(w, http.StatusBadRequest, "参数错误")
|
||||
@@ -143,11 +143,11 @@ func tempStoreHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
ctx.Syncer.RunOnce(r.Context())
|
||||
|
||||
body := map[string]any{
|
||||
"sn": req.Sn,
|
||||
"orderNo": req.OrderNo,
|
||||
"stationNo": req.StationNo,
|
||||
"processCode": req.ProcessCode,
|
||||
"operator": req.Operator,
|
||||
"sn": req.Sn,
|
||||
"orderNo": req.OrderNo,
|
||||
"stationNo": req.StationNo,
|
||||
"flowId": req.FlowId,
|
||||
"operator": req.Operator,
|
||||
}
|
||||
payloadBytes, _ := json.Marshal(body)
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@ func RegisterHandlers(server *rest.Server, ctx *svc.ServiceContext) {
|
||||
{Method: http.MethodPost, Path: "/api/bind/remove", Handler: bindRemoveHandler(ctx)},
|
||||
{Method: http.MethodGet, Path: "/api/workload", Handler: workloadHandler(ctx)},
|
||||
{Method: http.MethodGet, Path: "/api/stations", Handler: stationsHandler(ctx)},
|
||||
{Method: http.MethodPost, Path: "/api/station/pause", Handler: stationPauseHandler(ctx)},
|
||||
{Method: http.MethodGet, Path: "/api/station/state", Handler: stationStateHandler(ctx)},
|
||||
{Method: http.MethodGet, Path: "/api/pdf", Handler: pdfQueryHandler(ctx)},
|
||||
{Method: http.MethodGet, Path: "/pdfopen/:name", Handler: pdfOpenHandler(ctx)},
|
||||
{Method: http.MethodGet, Path: "/api/tightening/list", Handler: tighteningListHandler(ctx)},
|
||||
|
||||
Reference in New Issue
Block a user