feat: 退料闭环定稿(损耗台账/备料清单/退料AGV自动派车/剩余量参考)+ 工位托盘守卫
- MES 新增损耗台账 loss_ledger,差异确认损耗接口 ConfirmReceiveLoss(按工单归集) - 备料清单 preparation:MES 按 日计划×工单×工位×物料 实时计算,WMS 只读展示 PreparationList - 退料闭环:N5 工位托盘守卫(未完成禁止退料)、退料 AGV 自动派车(JBT21 空位判定 + 托盘回收链路)、退料参考剩余量接口(应剩余=实备-已耗-已退-已损) - 新增 AGV 车辆状态表 agv_vehicle_state 及查询 - 整合接驳台/叫料池/库存锁既有闭环,清理 sql 目录注释生成脚本与 catalog,更新文档
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package production
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -113,6 +114,27 @@ func AgvModeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// DispatchCallInternalHandler POST /api/internal/agv/dispatch-call body {requestNo, operator}
|
||||
// 库管人工派车(2026-11-03 定论:废除备料完成自动派车)——WMS 叫料队列点「送货」→ 下发空车去程段。
|
||||
func DispatchCallInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
RequestNo string `json:"requestNo"`
|
||||
Operator string `json:"operator"`
|
||||
}
|
||||
_ = json.NewDecoder(r.Body).Decode(&req)
|
||||
if req.RequestNo == "" {
|
||||
httpx.Fail(w, 3309, "requestNo 必填")
|
||||
return
|
||||
}
|
||||
if err := logic.New(svcCtx).DispatchCallAgv(r.Context(), req.RequestNo, req.Operator); err != nil {
|
||||
httpx.Fail(w, 3309, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"ok": true})
|
||||
}
|
||||
}
|
||||
|
||||
// ListAgvPointsHandler GET /agv/points?enabledOnly=1 列出 AGV 点位(启停用管理 / 派车下拉)。
|
||||
func ListAgvPointsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -204,14 +226,15 @@ func DispatchAgvInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
func AgvCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var body struct {
|
||||
TaskCode string `json:"taskCode"`
|
||||
Method string `json:"method"`
|
||||
TaskCode string `json:"taskCode"`
|
||||
Method string `json:"method"`
|
||||
RobotCode string `json:"robotCode"` // 文档 2.2.1 必填 AGV 编号,用于绑定任务与载货台账
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &body); err != nil {
|
||||
httpx.BadRequest(w, "回调报文解析失败")
|
||||
return
|
||||
}
|
||||
if err := logic.New(svcCtx).ApplyAgvCallback(r.Context(), body.TaskCode, body.Method); err != nil {
|
||||
if err := logic.New(svcCtx).ApplyAgvCallback(r.Context(), body.TaskCode, body.Method, body.RobotCode); err != nil {
|
||||
httpx.Fail(w, 3307, err.Error())
|
||||
return
|
||||
}
|
||||
@@ -219,6 +242,46 @@ func AgvCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// ListAgvVehicleStatesHandler GET /agv/vehicle-states —— AGV 载货台账列表(按车维护,防撞校验消费方)。
|
||||
func ListAgvVehicleStatesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
list, err := logic.New(svcCtx).ListAgvVehicleStates(r.Context())
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3311, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"list": list})
|
||||
}
|
||||
}
|
||||
|
||||
// SetAgvVehicleStateHandler POST /agv/vehicle-states/set —— 人工维护载货状态(有托盘/空车),留痕操作人与时间。
|
||||
func SetAgvVehicleStateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
AgvCode string `json:"agvCode"`
|
||||
HasPallet bool `json:"hasPallet"`
|
||||
Remark string `json:"remark"`
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil || req.AgvCode == "" {
|
||||
httpx.BadRequest(w, "缺少车辆编号(agvCode)")
|
||||
return
|
||||
}
|
||||
operator := r.Header.Get("X-Username")
|
||||
if operator == "" {
|
||||
operator = "manual"
|
||||
}
|
||||
if err := logic.New(svcCtx).SetAgvVehicleStateManual(r.Context(), req.AgvCode, req.HasPallet, operator, req.Remark); err != nil {
|
||||
httpx.Fail(w, 3312, err.Error())
|
||||
return
|
||||
}
|
||||
state := "空车"
|
||||
if req.HasPallet {
|
||||
state = "有托盘"
|
||||
}
|
||||
httpx.OkMessage(w, "载货状态已更新为「"+state+"」", nil)
|
||||
}
|
||||
}
|
||||
|
||||
// atoiSafe 安全解析分页参数(非法/缺省回退 def)。
|
||||
func atoiSafe(s string, def int) int {
|
||||
if s == "" {
|
||||
|
||||
@@ -165,12 +165,15 @@ func RejectCallHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
|
||||
// ConfirmReturnHandler POST /api/internal/call/return-confirm 仓库确认收回(退库闭环终点):
|
||||
// RETURNING → RETURNED,池子已发额度回补。
|
||||
// RETURNING → RETURNED,按实收量回补池子已发额度;实收<应退的差异落「待核」,不自动进损耗台账(R18 2026-11-03)。
|
||||
func ConfirmReturnHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
RequestNo string `json:"requestNo"`
|
||||
Operator string `json:"operator"`
|
||||
RequestNo string `json:"requestNo"`
|
||||
Operator string `json:"operator"`
|
||||
ReceiveQty float64 `json:"receiveQty"` // 库管实收量(0=整单全收)
|
||||
ReceiveDiff float64 `json:"receiveDiff"` // 收货差异=应退-实收
|
||||
ReceiveNote string `json:"receiveNote"` // 差异备注
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil || req.RequestNo == "" {
|
||||
httpx.BadRequest(w, "缺少叫料单号")
|
||||
@@ -180,7 +183,7 @@ func ConfirmReturnHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
if op == "" {
|
||||
op = "warehouse"
|
||||
}
|
||||
if err := logic.New(svcCtx).ConfirmReturn(r.Context(), req.RequestNo, op); err != nil {
|
||||
if err := logic.New(svcCtx).ConfirmReturn(r.Context(), req.RequestNo, op, req.ReceiveQty, req.ReceiveDiff, req.ReceiveNote); err != nil {
|
||||
httpx.Fail(w, 3208, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package production
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"bj_power_mes/common/httpx"
|
||||
"bj_power_mes/internal/logic"
|
||||
"bj_power_mes/internal/svc"
|
||||
)
|
||||
|
||||
// ConfirmReceiveLossHandler POST /api/v1/material-requests/confirm-loss
|
||||
// T2(2026-11-04 拍板):收货差异「确认损耗」——人工点击才写损耗台账并挂工单,不自动转。
|
||||
// body {"requestNo":"...", "reason":"..."};权限码 produce.qty:handle(数量不符处理同链路)。
|
||||
func ConfirmReceiveLossHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
RequestNo string `json:"requestNo"`
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
httpx.Fail(w, 3406, "参数错误: "+err.Error())
|
||||
return
|
||||
}
|
||||
op := strings.TrimSpace(operator(r, ""))
|
||||
if err := logic.New(svcCtx).ConfirmReceiveLoss(r.Context(), req.RequestNo, strings.TrimSpace(req.Reason), op); err != nil {
|
||||
httpx.Fail(w, 3407, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"requestNo": req.RequestNo, "lossQty": "written", "status": "PENDING"})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package production
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"bj_power_mes/common/httpx"
|
||||
"bj_power_mes/internal/logic"
|
||||
"bj_power_mes/internal/svc"
|
||||
)
|
||||
|
||||
// ---------- P1 备料清单(2026-11-04 用户拍板) ----------
|
||||
|
||||
// PreparationListInternalHandler GET /api/internal/preparation-list
|
||||
// 备料清单:今天及以后 × 未完成/已启用/执行中 日排产 → 日期×工单×工位×物料×数量。
|
||||
// 只读实时算(工艺改动后刷新即联动),不触发出库/领料,不管库存。供 WMS 备料清单页调用。
|
||||
func PreparationListInternalHandler(serverCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
list, err := logic.New(serverCtx).ComputePreparationList(r.Context())
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3404, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, list)
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- E4 托盘余料明细(2026-11-04 拍板) ----------
|
||||
|
||||
// PalletResidualInternalHandler GET /api/internal/pallet/residual?dock=XXX
|
||||
// 指定接驳台托盘余料明细:最近一次 AGV 送达该接驳台的运输段 materials_json(只读)。
|
||||
// 供 WMS 托盘工作台「代发起退料」弹窗自动带出余料,库管核对后提交。
|
||||
func PalletResidualInternalHandler(serverCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
dock := r.URL.Query().Get("dock")
|
||||
rows, err := logic.New(serverCtx).PalletResidual(r.Context(), dock)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3405, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, rows)
|
||||
}
|
||||
}
|
||||
@@ -267,6 +267,8 @@ func InProcessInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
|
||||
// OnlineWorkpieceInternalHandler 工件进线建档(工位终端上线面板提交)。
|
||||
// POST OnlineReq{sn,orderNo,workOrderId,processSeq};operator 从 query 兜底(内部接口无 JWT)。
|
||||
// E2(2026-11-03 拍板):建档标记位置+工单——工位号优先取工位登录态注入的 X-Station-No
|
||||
// (终端链路 body 不带 stationNo,历史落 0 导致建档工位缺失、预生成 SN 被首道工位校验拒绝)。
|
||||
func OnlineWorkpieceInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req logic.OnlineReq
|
||||
@@ -274,6 +276,7 @@ func OnlineWorkpieceInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
req.StationNo = StationNo(r, req.StationNo)
|
||||
LogImpersonation(svcCtx, r, r.URL.Query().Get("operator"), "/api/internal/workpiece/online")
|
||||
if msg, mm, err := logic.New(svcCtx).OnlineWorkpiece(r.Context(), req, StationOp(r, r.URL.Query().Get("operator"))); err != nil {
|
||||
httpx.Fail(w, 2007, err.Error())
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
package production
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"bj_power_mes/common/httpx"
|
||||
"bj_power_mes/internal/logic"
|
||||
"bj_power_mes/internal/svc"
|
||||
)
|
||||
|
||||
// ============ 退料 AGV / 损耗 / 余量参考值 internal 接口(2026-11-04 口径定稿) ============
|
||||
|
||||
// Jbt21FreeInternalHandler GET /api/internal/agv/jbt21-free
|
||||
// 库房接驳台 JBT21 空位查询(WMS 托盘工作台按钮禁用判定 / 自动派车循环复用)。
|
||||
// 口径:JBT21 无空位不派车——传感器有托盘或有在途任务即视为占用。
|
||||
func Jbt21FreeInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
free, reason := logic.New(svcCtx).Jbt21Free(r.Context())
|
||||
httpx.Ok(w, map[string]any{"free": free, "reason": reason})
|
||||
}
|
||||
}
|
||||
|
||||
// CancelAgvByDockInternalHandler POST /api/internal/agv/cancel-by-dock {dockCode, reason}
|
||||
// 按接驳台取消未终态 PALLET 回收任务(退料单取消联动:作废未完成 AGV 任务,留痕)。
|
||||
// 已装车运输中(TRANSPORT 段执行中)的段不在此列——按 D2 口径由调用方先判定可取消窗口。
|
||||
func CancelAgvByDockInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
DockCode string `json:"dockCode"`
|
||||
Reason string `json:"reason"`
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil || req.DockCode == "" {
|
||||
httpx.BadRequest(w, "dockCode 必填")
|
||||
return
|
||||
}
|
||||
n, inTransit, err := logic.New(svcCtx).CancelPalletTasksByDock(r.Context(), req.DockCode, req.Reason)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3306, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"cancelled": n, "hasInTransit": inTransit})
|
||||
}
|
||||
}
|
||||
|
||||
// LossConfirmInternalHandler POST /api/internal/loss/confirm
|
||||
// WMS 确认收货时实收<应退就地填损耗原因 → 落 MES loss_ledgers(损耗确认移 WMS,MES 只读展示)。
|
||||
func LossConfirmInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
ReturnNo string `json:"returnNo"`
|
||||
OrderNo string `json:"orderNo"`
|
||||
StationNo int `json:"stationNo"`
|
||||
MaterialCode string `json:"materialCode"`
|
||||
MaterialName string `json:"materialName"`
|
||||
TheoryQty float64 `json:"theoryQty"`
|
||||
ActualQty float64 `json:"actualQty"`
|
||||
LossQty float64 `json:"lossQty"`
|
||||
Reason string `json:"reason"`
|
||||
Operator string `json:"operator"`
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
op := r.Header.Get("X-Username")
|
||||
if op == "" {
|
||||
op = req.Operator
|
||||
}
|
||||
if err := logic.New(svcCtx).ConfirmLossFromWMS(r.Context(), req.ReturnNo, req.OrderNo, req.StationNo,
|
||||
req.MaterialCode, req.MaterialName, req.TheoryQty, req.ActualQty, req.LossQty, req.Reason, op); err != nil {
|
||||
httpx.Fail(w, 3408, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.OkMessage(w, "损耗已落账", nil)
|
||||
}
|
||||
}
|
||||
|
||||
// ReturnReferenceHandler GET /api/v1/return-reference?stationNo= (JWT,MES 前端转产向导/下班退料展示)
|
||||
func ReturnReferenceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
stationNo, _ := strconv.Atoi(r.URL.Query().Get("stationNo"))
|
||||
rows, err := logic.New(svcCtx).ReturnReference(r.Context(), stationNo)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3409, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"rows": rows})
|
||||
}
|
||||
}
|
||||
|
||||
// ReturnReferenceInternalHandler GET /api/internal/return-reference?stationNo=
|
||||
// 余量参考值(应剩余量−已退余量−已损耗):转产向导/下班退料/巡检退料/WMS 代退料共用数据源。
|
||||
func ReturnReferenceInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
stationNo, _ := strconv.Atoi(r.URL.Query().Get("stationNo"))
|
||||
rows, err := logic.New(svcCtx).ReturnReference(r.Context(), stationNo)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3409, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"rows": rows})
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package production
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -150,6 +151,11 @@ func OffDutyInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
op = r.Header.Get("X-Username")
|
||||
}
|
||||
if err := logic.New(svcCtx).OffDuty(r.Context(), req.StationNo, op, req.HasLeftover, req.Items); err != nil {
|
||||
// 拍板2(2026-11-04):PLC 离线需人工强行确认 → 业务码 2409,前端弹风险提示二次确认
|
||||
if errors.Is(err, logic.ErrReturnForceConfirm) {
|
||||
httpx.Fail(w, 2409, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Fail(w, 500, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
package production
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
"bj_power_mes/common/httpx"
|
||||
"bj_power_mes/internal/logic"
|
||||
"bj_power_mes/internal/svc"
|
||||
)
|
||||
|
||||
// ============ 工位托盘位传感器 / 退料前置守卫(N5 2026-11-04 拍板) ============
|
||||
//
|
||||
// N5 口径:工位传感器表示无托盘(工件已完工离开工位)才允许退料;有托盘(工件在工位、
|
||||
// 未完工、消耗未定)时所有退料入口一律拒绝,提示「工件未完工,不允许退料」。
|
||||
// 本文件三个内部端点:读传感器 / mock 联调置位 / WMS 代退料前置校验。
|
||||
|
||||
// StationPalletInternalHandler GET /api/internal/station/pallet?stationNo=
|
||||
// 读工位托盘位传感器(G{stationNo} 位)。hasPallet=true = 工件在工位未完工。
|
||||
func StationPalletInternalHandler(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.BadRequest(w, "缺少 stationNo")
|
||||
return
|
||||
}
|
||||
if svcCtx.PLC == nil || svcCtx.PLC.Get() == nil {
|
||||
httpx.Fail(w, 3202, "PLC 未接入")
|
||||
return
|
||||
}
|
||||
has, err := svcCtx.PLC.QueryStationPallet(r.Context(), stationNo)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3202, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"stationNo": stationNo, "hasPallet": has})
|
||||
}
|
||||
}
|
||||
|
||||
// SetStationPalletInternalHandler POST /api/internal/station/pallet/set {stationNo, hasPallet}
|
||||
// mock 联调用:手动置位某工位托盘位是否有件(仅 mock 模式生效,真实 PLC 忽略)。
|
||||
func SetStationPalletInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
StationNo int `json:"stationNo"`
|
||||
HasPallet bool `json:"hasPallet"`
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil || req.StationNo <= 0 {
|
||||
httpx.BadRequest(w, "请求体缺失或 stationNo 非法")
|
||||
return
|
||||
}
|
||||
svcCtx.PLC.SetMockStationPallet(req.StationNo, req.HasPallet)
|
||||
if !svcCtx.PLC.IsMock() {
|
||||
httpx.OkMessage(w, "真实 PLC 模式忽略手动置位", nil)
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, nil)
|
||||
}
|
||||
}
|
||||
|
||||
// StationReturnGuardInternalHandler GET /api/internal/station/return-guard?stationNo=
|
||||
// WMS 代退料前置校验(N5 + 拍板2):三态——
|
||||
// allowed=true 正常放行(传感器无托盘);
|
||||
// allowed=false, needForce=true PLC 离线:前端弹风险提示,人工确认后带 forceConfirm 重提;
|
||||
// allowed=false, needForce=false 硬拒(传感器有托盘/工位号非法),reason 为拒绝文案。
|
||||
func StationReturnGuardInternalHandler(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.BadRequest(w, "缺少 stationNo")
|
||||
return
|
||||
}
|
||||
needForce, err := logic.New(svcCtx).CheckReturnStationClear(r.Context(), stationNo)
|
||||
if err != nil {
|
||||
httpx.Ok(w, map[string]any{"stationNo": stationNo, "allowed": false, "needForce": false, "reason": err.Error()})
|
||||
return
|
||||
}
|
||||
if needForce {
|
||||
httpx.Ok(w, map[string]any{"stationNo": stationNo, "allowed": false, "needForce": true, "reason": logic.ErrReturnForceConfirm.Error()})
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"stationNo": stationNo, "allowed": true, "needForce": false, "reason": ""})
|
||||
}
|
||||
}
|
||||
|
||||
// PlcMockOfflineInternalHandler POST /api/internal/plc/mock-offline {offline}
|
||||
// mock 联调用:模拟 PLC 离线(工位托盘位读失败),验证拍板2「PLC 离线提示+人工强行确认」链路。
|
||||
// 仅 mock 模式生效;真实 PLC 模式忽略(读真实传感器,离线与否由现场决定)。
|
||||
func PlcMockOfflineInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
Offline bool `json:"offline"`
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
svcCtx.PLC.SetMockOffline(req.Offline)
|
||||
if !svcCtx.PLC.IsMock() {
|
||||
httpx.OkMessage(w, "真实 PLC 模式忽略离线模拟", nil)
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"offline": req.Offline})
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package production
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
@@ -51,6 +52,11 @@ func CreateTransferReturnsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
op = "system"
|
||||
}
|
||||
if err := logic.New(svcCtx).CreateTransferReturns(r.Context(), req.StationNo, op, req.Items); err != nil {
|
||||
// 拍板2(2026-11-04):PLC 离线需人工强行确认 → 业务码 2409,前端弹风险提示二次确认
|
||||
if errors.Is(err, logic.ErrReturnForceConfirm) {
|
||||
httpx.Fail(w, 2409, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Fail(w, 500, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user