feat: 退料闭环定稿(损耗台账/备料清单/退料AGV自动派车/剩余量参考)+ 工位托盘守卫
- MES 新增损耗台账 loss_ledger,差异确认损耗接口 ConfirmReceiveLoss(按工单归集) - 备料清单 preparation:MES 按 日计划×工单×工位×物料 实时计算,WMS 只读展示 PreparationList - 退料闭环:N5 工位托盘守卫(未完成禁止退料)、退料 AGV 自动派车(JBT21 空位判定 + 托盘回收链路)、退料参考剩余量接口(应剩余=实备-已耗-已退-已损) - 新增 AGV 车辆状态表 agv_vehicle_state 及查询 - 整合接驳台/叫料池/库存锁既有闭环,清理 sql 目录注释生成脚本与 catalog,更新文档
This commit is contained in:
@@ -2,9 +2,11 @@ package handler
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -63,17 +65,20 @@ func StationQtyReportInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFun
|
||||
func StationReturnMaterialInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
OrderNo string `json:"orderNo"`
|
||||
StationNo int `json:"stationNo"`
|
||||
Sn string `json:"sn"`
|
||||
MaterialCode string `json:"materialCode"`
|
||||
MaterialName string `json:"materialName"`
|
||||
Spec string `json:"spec"`
|
||||
Qty int `json:"qty"`
|
||||
Unit string `json:"unit"`
|
||||
ReturnDock string `json:"returnDock"`
|
||||
Reason string `json:"reason"`
|
||||
Operator string `json:"operator"`
|
||||
OrderNo string `json:"orderNo"`
|
||||
StationNo int `json:"stationNo"`
|
||||
Sn string `json:"sn"`
|
||||
MaterialCode string `json:"materialCode"`
|
||||
MaterialName string `json:"materialName"`
|
||||
Spec string `json:"spec"`
|
||||
Qty int `json:"qty"`
|
||||
Unit string `json:"unit"`
|
||||
ReturnDock string `json:"returnDock"`
|
||||
Reason string `json:"reason"`
|
||||
LossReason string `json:"lossReason"` // 2026-11-04 拍板:工位退料损耗原因(巡检退料一律必填,前端校验)
|
||||
TransportMode string `json:"transportMode"` // 2026-11-04 拍板:运输方式 agv/manual(必填;agv=传感器检测到托盘且库房有空位自动派车)
|
||||
ForceConfirm bool `json:"forceConfirm"` // 拍板2 2026-11-04:PLC 离线时前端弹风险提示后人工强行确认
|
||||
Operator string `json:"operator"`
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
@@ -81,7 +86,12 @@ func StationReturnMaterialInternalHandler(svcCtx *svc.ServiceContext) http.Handl
|
||||
}
|
||||
production.LogImpersonation(svcCtx, r, req.Operator, "/api/internal/station/return-material")
|
||||
if err := logic.New(svcCtx).StationReturnMaterial(r.Context(), req.OrderNo, req.StationNo, req.Sn,
|
||||
req.MaterialCode, req.MaterialName, req.Spec, req.Reason, production.StationOp(r, req.Operator), req.Unit, req.Qty, req.ReturnDock); err != nil {
|
||||
req.MaterialCode, req.MaterialName, req.Spec, req.Reason, production.StationOp(r, req.Operator), req.Unit, req.Qty, req.ReturnDock, req.LossReason, req.TransportMode, req.ForceConfirm); err != nil {
|
||||
// 拍板2(2026-11-04):PLC 离线需人工强行确认 → 业务码 2409,前端弹风险提示二次确认
|
||||
if errors.Is(err, logic.ErrReturnForceConfirm) {
|
||||
httpx.Fail(w, 2409, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Fail(w, 2403, err.Error())
|
||||
return
|
||||
}
|
||||
@@ -89,6 +99,67 @@ func StationReturnMaterialInternalHandler(svcCtx *svc.ServiceContext) http.Handl
|
||||
}
|
||||
}
|
||||
|
||||
// StationReturnListInternalHandler GET /api/internal/station/return-list?stationNo=
|
||||
// 工位终端「我的退料单」列表(PENDING 可取消 / 全部可查),WMS 数据经 MES 转发。
|
||||
func StationReturnListInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
stationNo, _ := strconv.Atoi(r.URL.Query().Get("stationNo"))
|
||||
if stationNo <= 0 {
|
||||
httpx.Fail(w, 2407, "stationNo 必填")
|
||||
return
|
||||
}
|
||||
list, err := logic.New(svcCtx).ListStationReturnOrders(r.Context(), stationNo)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 2407, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"list": list})
|
||||
}
|
||||
}
|
||||
|
||||
// StationReturnCancelInternalHandler POST /api/internal/station/return-cancel {returnNo, reason}
|
||||
// 工位取消自己发起的 PENDING 退料单(库房也可取消,见 WMS 退库单页取消入口)。
|
||||
// 已收货(RECEIVED)不可取消;取消后作废未完成 AGV 任务、不产生库存变动。
|
||||
func StationReturnCancelInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
StationNo int `json:"stationNo"`
|
||||
ReturnNo string `json:"returnNo"`
|
||||
Reason string `json:"reason"`
|
||||
Operator string `json:"operator"`
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil || req.ReturnNo == "" {
|
||||
httpx.BadRequest(w, "returnNo 必填")
|
||||
return
|
||||
}
|
||||
production.LogImpersonation(svcCtx, r, req.Operator, "/api/internal/station/return-cancel")
|
||||
if err := logic.New(svcCtx).CancelStationReturn(r.Context(), req.ReturnNo, req.StationNo,
|
||||
production.StationOp(r, req.Operator), req.Reason); err != nil {
|
||||
httpx.Fail(w, 2408, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.OkMessage(w, "退料单已取消", nil)
|
||||
}
|
||||
}
|
||||
|
||||
// StationReturnReferenceInternalHandler GET /api/internal/station/return-reference?stationNo=
|
||||
// 工位终端余量参考值(剩余余量=应剩余量−已退余量−已损耗;仅展示不阻断提交)。
|
||||
func StationReturnReferenceInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
stationNo, _ := strconv.Atoi(r.URL.Query().Get("stationNo"))
|
||||
if stationNo <= 0 {
|
||||
httpx.Fail(w, 2409, "stationNo 必填")
|
||||
return
|
||||
}
|
||||
rows, err := logic.New(svcCtx).ReturnReference(r.Context(), stationNo)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 2409, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"rows": rows})
|
||||
}
|
||||
}
|
||||
|
||||
// StationInspectionInternalHandler POST /api/internal/station/inspection
|
||||
// 工位终端提交巡检记录(签到/点检/过程巡检/完工确认/异常),复用与 PAD 巡检终端相同的落库逻辑。
|
||||
// 工位终端无按钮级权限概念,仅按 category 合法性校验(CreateInspection 内部已做)。
|
||||
|
||||
Reference in New Issue
Block a user