feat: AGV三段链安全机制、补料/损耗/下班闭环、接驳台左右互换

AGV 调度:
- 任务重构为 GO_LOAD/TRANSPORT/EMPTY_RETURN/FREE 三段链,到位即停(ARRIVED)需人工确认装卸
- 自由调度单点步进,每段强制弹"请确保路径畅通无杂物";托盘回收独立工作台
- 接驳台 PLC 传感器检测到托盘即自动卸货放行,传感器故障由人工按钮兜底(无轮询)
- 车辆状态只读展示(海康3.1.7 queryAgvStatus),调度仍由 RCS 负责

物料闭环:
- 补料管理(SHORTAGE):工位申请 + 主管审批调增叫料池额度,与借料/差异补发三轨并行
- 损耗台账(loss_ledger):退料实际 < 理论必填原因、后审核,工单不记损耗
- 退料强制指定左/右接驳台,WMS 库管可代工位退料

下班闭环:
- 工位终端自检接驳台剩余物料后下班;库管收货 + 托盘拉走后事件驱动自动结班
- 退出登录未下班仅作安全提示(不强制拦截、不新增责任审批)

接驳台左右按操作员朝向建模(dock.side 字段),废除"奇左偶右"隐式约定;
看板标签 / seed / 迁移补丁 / 布局文档统一为中文左/右。

产线布局说明:C1 前线头 AGV 点、C15 后线尾 AGV 点、外部 O1/O2/O3 散点,
清理修订痕迹为最终态描述。
This commit is contained in:
SunYF
2026-11-03 18:29:31 +08:00
parent 2ccf9bb9ca
commit 42bcf395d2
123 changed files with 19472 additions and 247 deletions
@@ -126,6 +126,19 @@ func ListAgvPointsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
}
// ListAgvVehiclesHandler GET /agv/vehicles —— 只读获取车辆状态(海康 3.1.7 queryAgvStatus):
// 车辆闲忙/充电/电量/位置,纯只读展示,调度完全交给 RCS;本系统不干预(2026-11-03 拍板)。
func ListAgvVehiclesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vs, err := logic.New(svcCtx).ListAgvVehicles(r.Context())
if err != nil {
httpx.Ok(w, map[string]any{"list": []any{}, "unavailable": true, "reason": err.Error()})
return
}
httpx.Ok(w, map[string]any{"list": vs, "unavailable": false})
}
}
// UpdateAgvPointHandler PUT /agv/points/:id body {name, enabled}
// 仅允许改显示名与启用状态;硬件映射 position_code / dock_id 不可改。
func UpdateAgvPointHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
@@ -0,0 +1,141 @@
package production
import (
"encoding/json"
"net/http"
"bj_power_mes/common/httpx"
"bj_power_mes/internal/logic"
"bj_power_mes/internal/svc"
)
// ============ AGV 三段链确认与自由调度(2026-11-03 三层安全机制) ============
// 第一层 业务自动触发(免弹窗):空车去程/回充由系统自动下发(CompleteCall/卸货放行内触发);
// 第二层 装卸强制确认(到位待令):本文件 confirm 端点——「确认装车并送货/卸货完成并放行/结束回充」;
// 第三层 人工自由调度(FREE):free-dispatch 端点——前端每次点击「开始搬运」必须弹「请确保路径畅通无杂物」。
// ConfirmAgvHandler POST /api/v1/agv/confirm {taskNo, action, nextDock}
// action: load_go=确认装车并送货(需 nextDock,CALL 链可空默认叫料单目标台)/
// unload_release=卸货完成并放行 / finish_return=结束回充电位(自由调度)
func ConfirmAgvHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
TaskNo string `json:"taskNo"`
BizNo string `json:"bizNo"` // 可选:WMS 装车确认只知叫料单号
Action string `json:"action"`
NextDock string `json:"nextDock"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
httpx.Fail(w, 400, "参数错误: "+err.Error())
return
}
op := r.Header.Get("X-Username")
if op == "" {
op = "system"
}
lg := logic.New(svcCtx)
if req.TaskNo == "" && req.BizNo != "" {
tn, terr := lg.FindArrivedTaskNo(r.Context(), req.BizNo, "GO_LOAD")
if terr != nil {
httpx.Fail(w, 500, terr.Error())
return
}
req.TaskNo = tn
}
var err error
switch req.Action {
case "load_go":
err = lg.ConfirmLoadAndGo(r.Context(), req.TaskNo, req.NextDock, op)
case "unload_release":
err = lg.ConfirmUnloadRelease(r.Context(), req.TaskNo, op)
case "finish_return":
err = lg.FinishFreeReturn(r.Context(), req.TaskNo, op)
default:
httpx.Fail(w, 400, "未知动作: "+req.Action)
return
}
if err != nil {
httpx.Fail(w, 500, err.Error())
return
}
httpx.Ok(w, map[string]any{"ok": true})
}
}
// FreeDispatchHandler POST /api/v1/agv/free-dispatch {source?, target}
// 人工自由调度单点段(前端已弹「请确保路径畅通无杂物」确认后才调用)。
func FreeDispatchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
Source string `json:"source"`
Target string `json:"target"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
httpx.Fail(w, 400, "参数错误: "+err.Error())
return
}
op := r.Header.Get("X-Username")
if op == "" {
op = "system"
}
taskNo, err := logic.New(svcCtx).FreeDispatch(r.Context(), req.Source, req.Target, op)
if err != nil {
httpx.Fail(w, 500, err.Error())
return
}
httpx.Ok(w, map[string]any{"taskNo": taskNo})
}
}
// ConfirmAgvInternalHandler POST /api/internal/agv/confirm —— WMS(库管装货确认)内部网关调用。
func ConfirmAgvInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return ConfirmAgvHandler(svcCtx)
}
// PalletDispatchInternalHandler POST /api/internal/agv/pallet-dispatch {dockCode}
// 托盘回收(WMS 托盘工作台):空车前往工位接驳台拉托盘,业务自动触发免弹窗,到位待令。
func PalletDispatchInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
DockCode string `json:"dockCode"`
Operator string `json:"operator"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
httpx.Fail(w, 400, "参数错误: "+err.Error())
return
}
if req.DockCode == "" {
httpx.Fail(w, 400, "dockCode 必填")
return
}
if err := logic.New(svcCtx).DispatchPalletRecovery(r.Context(), req.DockCode, req.Operator); err != nil {
httpx.Fail(w, 500, err.Error())
return
}
httpx.Ok(w, map[string]any{"ok": true})
}
}
// DockListInternalHandler GET /api/internal/dock/list —— 全量接驳台台账(WMS 托盘工作台列表)。
func DockListInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
docks, err := svcCtx.EntClient.Dock.Query().All(r.Context())
if err != nil {
httpx.Fail(w, 500, err.Error())
return
}
out := make([]map[string]any, 0, len(docks))
for _, d := range docks {
side := "右"
if d.Side == "left" {
side = "左"
}
out = append(out, map[string]any{
"dockCode": d.DockCode, "name": d.Name, "dockType": d.DockType,
"stationNo": d.StationNo, "side": d.Side, "sideCn": side,
"hasPallet": d.HasPallet, "palletRef": d.PalletRef, "status": d.Status,
})
}
httpx.Ok(w, map[string]any{"list": out})
}
}
@@ -29,6 +29,7 @@ type dockRow struct {
Name string `json:"name"`
DockType string `json:"dockType"`
StationNo int `json:"stationNo"`
Side string `json:"side"` // left/right(按操作员朝向,2026-11-03)
Status string `json:"status"`
HasPallet bool `json:"hasPallet"`
PalletRef string `json:"palletRef"`
@@ -42,6 +43,7 @@ func dockRowOf(d *ent.Dock) dockRow {
Name: d.Name,
DockType: d.DockType,
StationNo: d.StationNo,
Side: d.Side,
Status: d.Status,
HasPallet: d.HasPallet,
PalletRef: d.PalletRef,
@@ -0,0 +1,175 @@
package production
import (
"encoding/json"
"net/http"
"strconv"
"bj_power_mes/common/httpx"
"bj_power_mes/internal/logic"
"bj_power_mes/internal/svc"
)
// ============ 补料(SHORTAGE)/ 损耗台账 / 工位班次(2026-11-03 拍板) ============
// ShortageListHandler GET /api/v1/shortages?status=&page=&pageSize=
func ShortageListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
page, _ := strconv.Atoi(q.Get("page"))
size, _ := strconv.Atoi(q.Get("pageSize"))
data, err := logic.New(svcCtx).ListShortages(r.Context(), q.Get("status"), page, size)
if err != nil {
httpx.Fail(w, 500, err.Error())
return
}
httpx.Ok(w, data)
}
}
// ShortageCreateHandler POST /api/v1/shortages 工人提交补料申请(原因必填)。
func ShortageCreateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
StationNo int `json:"stationNo"`
MaterialCode string `json:"materialCode"`
MaterialName string `json:"materialName"`
Unit string `json:"unit"`
Qty int `json:"qty"`
Reason string `json:"reason"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
httpx.Fail(w, 400, "参数错误: "+err.Error())
return
}
op := r.Header.Get("X-Username")
if op == "" {
op = "system"
}
row, err := logic.New(svcCtx).CreateShortage(r.Context(), req.StationNo, req.MaterialCode,
req.MaterialName, req.Unit, req.Qty, req.Reason, op)
if err != nil {
httpx.Fail(w, 500, err.Error())
return
}
httpx.Ok(w, row)
}
}
// ShortageReviewHandler POST /api/v1/shortages/review 主管审批 {id, approve, comment}。
func ShortageReviewHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
ID int `json:"id"`
Approve bool `json:"approve"`
Comment string `json:"comment"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
httpx.Fail(w, 400, "参数错误: "+err.Error())
return
}
op := r.Header.Get("X-Username")
if op == "" {
op = "system"
}
if err := logic.New(svcCtx).ReviewShortage(r.Context(), req.ID, req.Approve, req.Comment, op); err != nil {
httpx.Fail(w, 500, err.Error())
return
}
httpx.Ok(w, map[string]any{"ok": true})
}
}
// LossListHandler GET /api/v1/losses?status=&page=&pageSize= 损耗台账。
func LossListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
page, _ := strconv.Atoi(q.Get("page"))
size, _ := strconv.Atoi(q.Get("pageSize"))
data, err := logic.New(svcCtx).ListLosses(r.Context(), q.Get("status"), page, size)
if err != nil {
httpx.Fail(w, 500, err.Error())
return
}
httpx.Ok(w, data)
}
}
// LossCommentHandler POST /api/v1/losses/comment 主管批注 {id, comment}(后审核)。
func LossCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
ID int `json:"id"`
Comment string `json:"comment"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
httpx.Fail(w, 400, "参数错误: "+err.Error())
return
}
op := r.Header.Get("X-Username")
if op == "" {
op = "system"
}
if err := logic.New(svcCtx).CommentLoss(r.Context(), req.ID, req.Comment, op); err != nil {
httpx.Fail(w, 500, err.Error())
return
}
httpx.Ok(w, map[string]any{"ok": true})
}
}
// ShiftGetInternalHandler GET /api/internal/station/shift?stationNo= 当前班次(工位终端退出提示)。
func ShiftGetInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
stationNo, _ := strconv.Atoi(r.URL.Query().Get("stationNo"))
shift, err := logic.New(svcCtx).GetShift(r.Context(), stationNo)
if err != nil {
httpx.Ok(w, map[string]any{"shift": nil})
return
}
httpx.Ok(w, map[string]any{"shift": shift})
}
}
// OffDutyInternalHandler POST /api/internal/station/off-duty(StationSessionAuth)
// 工人下班/结束作业:{hasLeftover, items[]}——确认无剩余直接下班;有剩余走退料流程后离场。
func OffDutyInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
StationNo int `json:"stationNo"`
Operator string `json:"operator"`
HasLeftover bool `json:"hasLeftover"`
Items []logic.TransferReturnInput `json:"items"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
httpx.Fail(w, 400, "参数错误: "+err.Error())
return
}
op := req.Operator
if op == "" {
op = r.Header.Get("X-Username")
}
if err := logic.New(svcCtx).OffDuty(r.Context(), req.StationNo, op, req.HasLeftover, req.Items); err != nil {
httpx.Fail(w, 500, err.Error())
return
}
httpx.Ok(w, map[string]any{"ok": true})
}
}
// StationDocksHandler GET /api/v1/station-docks?stationNo= 工位接驳台选项(左/右,退料选择用)。
func StationDocksHandler(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, 400, "stationNo 必填")
return
}
docks, err := logic.New(svcCtx).ListStationDocks(r.Context(), stationNo)
if err != nil {
httpx.Fail(w, 500, err.Error())
return
}
httpx.Ok(w, map[string]any{"docks": docks})
}
}
@@ -0,0 +1,59 @@
package production
import (
"encoding/json"
"net/http"
"strconv"
"bj_power_mes/common/httpx"
"bj_power_mes/internal/logic"
"bj_power_mes/internal/svc"
)
// ============ 转产按工单精确退料(TransferReturn 向导,2026-11-03 第三轮重构) ============
// 背景:工位故障,旧工位料须「按工单归集」退库(而非按工位无差别退)——系统列出该工位涉及的所有工单
// 及每工单理论应剩料量,用户改实际剩余、勾选后按工单生成多张退库单(每张绑工单号),库管按工单分别确认。
// ListTransferOrdersHandler GET /api/v1/transfer/orders?stationNo= 列出故障工位涉及的所有工单及理论应剩料量
func ListTransferOrdersHandler(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, 400, "stationNo 必填")
return
}
items, err := logic.New(svcCtx).ListStationTransferOrders(r.Context(), stationNo)
if err != nil {
httpx.Fail(w, 500, err.Error())
return
}
docks, _ := logic.New(svcCtx).ListStationDocks(r.Context(), stationNo)
httpx.Ok(w, map[string]any{"items": items, "docks": docks})
}
}
// transferReturnsReq POST /api/v1/transfer/returns 请求体
type transferReturnsReq struct {
StationNo int `json:"stationNo"`
Items []logic.TransferReturnInput `json:"items"`
}
// CreateTransferReturnsHandler POST /api/v1/transfer/returns 按工单精确生成退库单
func CreateTransferReturnsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req transferReturnsReq
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
httpx.Fail(w, 400, "参数错误: "+err.Error())
return
}
op := r.Header.Get("X-Username")
if op == "" {
op = "system"
}
if err := logic.New(svcCtx).CreateTransferReturns(r.Context(), req.StationNo, op, req.Items); err != nil {
httpx.Fail(w, 500, err.Error())
return
}
httpx.Ok(w, map[string]any{"ok": true})
}
}
@@ -47,6 +47,45 @@ func DoneWorkpieceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
}
// ScrapWorkpieceHandler 工件报废/人工取走(MES 后台入口,2026-11-03 补全):原因必填、留痕。
func ScrapWorkpieceHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
Sn string `json:"sn"`
Reason string `json:"reason"`
}
if err := httpx.ParseJSON(r, &req); err != nil {
httpx.BadRequest(w, "请求体解析失败")
return
}
if err := logic.New(svcCtx).ScrapWorkpiece(r.Context(), req.Sn, req.Reason, operator(r, ""), "admin"); err != nil {
httpx.Fail(w, 3304, err.Error())
return
}
httpx.OkMessage(w, "已登记报废/取走,工件状态置「已报废」,全程留痕", nil)
}
}
// ScrapWorkpieceInternalHandler 工件报废/人工取走(工位终端代理入口,X-API-TOKEN + 工位会话)。
func ScrapWorkpieceInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
Sn string `json:"sn"`
Reason string `json:"reason"`
}
if err := httpx.ParseJSON(r, &req); err != nil {
httpx.BadRequest(w, "请求体解析失败")
return
}
LogImpersonation(svcCtx, r, r.URL.Query().Get("operator"), "/api/internal/workpiece/scrap")
if err := logic.New(svcCtx).ScrapWorkpiece(r.Context(), req.Sn, req.Reason, StationOp(r, r.URL.Query().Get("operator")), "workstation"); err != nil {
httpx.Fail(w, 3305, err.Error())
return
}
httpx.OkMessage(w, "已登记报废/取走,工件状态置「已报废」,全程留痕", nil)
}
}
func ListWorkpiecesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
@@ -115,6 +115,31 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/workpiece/done", Handler: internal(production.StationSessionAuth(serverCtx)(production.DoneWorkpieceInternalHandler(serverCtx))),
})
// 工件报废/人工取走(工位终端代理,2026-11-03 补全):原因必填、留痕。
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/workpiece/scrap", Handler: internal(production.StationSessionAuth(serverCtx)(production.ScrapWorkpieceInternalHandler(serverCtx))),
})
// 公开配置快照(2026-11-03 拍板):受信内部端读取拧紧手填开关/缓存策略/AGV 超时等
server.AddRoute(rest.Route{
Method: http.MethodGet, Path: "/api/internal/public-config", Handler: internal(PublicConfigHandler(serverCtx)),
})
// AGV 三段链内部端点(WMS 库管装货确认 / 托盘工作台派车回收 / 接驳台台账列表)
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/agv/confirm", Handler: internal(production.ConfirmAgvInternalHandler(serverCtx)),
})
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/agv/pallet-dispatch", Handler: internal(production.PalletDispatchInternalHandler(serverCtx)),
})
server.AddRoute(rest.Route{
Method: http.MethodGet, Path: "/api/internal/dock/list", Handler: internal(production.DockListInternalHandler(serverCtx)),
})
// 工位班次(下班闭环):终端查询当前班次 + 下班/结束作业(自检接驳台剩余物料)
server.AddRoute(rest.Route{
Method: http.MethodGet, Path: "/api/internal/station/shift", Handler: internal(production.ShiftGetInternalHandler(serverCtx)),
})
server.AddRoute(rest.Route{
Method: http.MethodPost, Path: "/api/internal/station/off-duty", Handler: internal(production.StationSessionAuth(serverCtx)(production.OffDutyInternalHandler(serverCtx))),
})
server.AddRoute(rest.Route{
Method: http.MethodGet, Path: "/api/internal/order-usage", Handler: internal(production.OrderUsageInternalHandler(serverCtx)),
})
@@ -240,6 +265,21 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
{Method: http.MethodPost, Path: "/work-orders/force-complete", Handler: production.ForceCompleteHandler(serverCtx)},
{Method: http.MethodGet, Path: "/work-orders/:id", Handler: production.GetWorkOrderHandler(serverCtx)},
{Method: http.MethodDelete, Path: "/work-orders/:id", Handler: production.DeleteWorkOrderHandler(serverCtx)},
// 转产按工单精确退料(TransferReturn 向导):列出故障工位涉及工单+理论应剩 / 按工单生成退库单
{Method: http.MethodGet, Path: "/transfer/orders", Handler: production.ListTransferOrdersHandler(serverCtx)},
{Method: http.MethodPost, Path: "/transfer/returns", Handler: production.CreateTransferReturnsHandler(serverCtx)},
// AGV 三段链确认(到位待令)与自由调度(2026-11-03 三层安全机制)
{Method: http.MethodPost, Path: "/agv/confirm", Handler: production.ConfirmAgvHandler(serverCtx)},
{Method: http.MethodPost, Path: "/agv/free-dispatch", Handler: production.FreeDispatchHandler(serverCtx)},
// 工位接驳台选项(退料选左/右)
{Method: http.MethodGet, Path: "/station-docks", Handler: production.StationDocksHandler(serverCtx)},
// 补料申请与审批(SHORTAGE,独立于借料)
{Method: http.MethodGet, Path: "/shortages", Handler: production.ShortageListHandler(serverCtx)},
{Method: http.MethodPost, Path: "/shortages", Handler: production.ShortageCreateHandler(serverCtx)},
{Method: http.MethodPost, Path: "/shortages/review", Handler: production.ShortageReviewHandler(serverCtx)},
// 损耗台账与主管批注(后审核)
{Method: http.MethodGet, Path: "/losses", Handler: production.LossListHandler(serverCtx)},
{Method: http.MethodPost, Path: "/losses/comment", Handler: production.LossCommentHandler(serverCtx)},
// 排产预览/确认(M9:预览逐日可调、Σ==应排总数才能确认)
{Method: http.MethodPost, Path: "/work-orders/auto-schedule/preview", Handler: production.AutoSchedulePreviewHandler(serverCtx)},
{Method: http.MethodPost, Path: "/work-orders/auto-schedule/apply", Handler: production.AutoScheduleApplyHandler(serverCtx)},
@@ -310,6 +350,8 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
// AGV 点位管理(独立点位表:硬件映射编码/接驳台绑定不可改,仅名称/启用可改)
{Method: http.MethodGet, Path: "/agv/points", Handler: production.ListAgvPointsHandler(serverCtx)},
{Method: http.MethodPut, Path: "/agv/points/:id", Handler: production.UpdateAgvPointHandler(serverCtx)},
// 车辆状态只读展示(海康 3.1.7,2026-11-03 拍板:纯只读,不干预调度)
{Method: http.MethodGet, Path: "/agv/vehicles", Handler: production.ListAgvVehiclesHandler(serverCtx)},
{Method: http.MethodPost, Path: "/torque/report", Handler: production.TorqueReportHandler(serverCtx)},
{Method: http.MethodGet, Path: "/torque/records", Handler: production.TorqueRecordsHandler(serverCtx)},
@@ -328,6 +370,9 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
{Method: http.MethodPost, Path: "/workpiece/online", Handler: production.OnlineWorkpieceHandler(serverCtx)},
{Method: http.MethodPost, Path: "/workpiece/done", Handler: production.DoneWorkpieceHandler(serverCtx)},
// 工件报废/人工取走(2026-11-03 断头路补全):SCRAPPED 唯一写入者,原因必填、留痕;
// 与「暂存退库(半成品回库)」语义互斥——报废=永久退出,退库=合法暂停可重上线。
{Method: http.MethodPost, Path: "/workpiece/scrap", Handler: production.ScrapWorkpieceHandler(serverCtx)},
{Method: http.MethodGet, Path: "/workpieces", Handler: production.ListWorkpiecesHandler(serverCtx)},
{Method: http.MethodGet, Path: "/workpieces/in-process", Handler: production.InProcessHandler(serverCtx)},
{Method: http.MethodGet, Path: "/trace", Handler: production.TraceHandler(serverCtx)},
+18
View File
@@ -52,6 +52,24 @@ func WmsTestHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
}
// PublicConfigHandler GET /api/internal/public-config 受信内部端(工位终端)读取的公开配置快照:
// 拧紧手填开关 / 多工单缓存策略 / AGV 卸货超时等,供终端按配置显隐或约束交互(2026-11-03 拍板)。
// 仅需内部 X-API-TOKEN,不绑定工位会话。
func PublicConfigHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
vo, err := logic.New(svcCtx).GetSettings(r.Context())
if err != nil {
httpx.Fail(w, 2504, "读取配置失败")
return
}
httpx.Ok(w, map[string]any{
"torqueManualInput": vo.TorqueManualInput,
"multiOrderCachePolicy": vo.MultiOrderCachePolicy,
"agvUnloadTimeoutMinutes": vo.AgvUnloadTimeoutMinutes,
})
}
}
// StartEventLogRetention 事件日志保留期清理:每小时检查一次(保留天数在「基础设置」页
// 配置 eventlog.retention.days,0=不清理),删除超过保留期的操作日志。
func StartEventLogRetention(ctx *svc.ServiceContext) {
+5
View File
@@ -59,6 +59,11 @@ func StationLoginInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
svcCtx.EventLog.Write(r.Context(), "auth.station_login", "", req.Username, "auth", req.Username,
"工位终端登录(工位"+strconv.Itoa(req.StationNo)+")",
map[string]any{"ip": clientIP(r), "stationNo": req.StationNo})
// 登录建班(下班闭环,2026-11-03):无进行中班次则创建 ON_DUTY(失败不阻断登录)
if serr := logic.New(svcCtx).EnsureShiftOnLogin(r.Context(), req.StationNo, req.Username); serr != nil {
svcCtx.EventLog.Write(r.Context(), "shift.start.fail", "", req.Username, "station_shift",
"station:"+strconv.Itoa(req.StationNo), "登录建班失败: "+serr.Error(), nil)
}
httpx.Ok(w, data)
}
}
+2 -1
View File
@@ -71,6 +71,7 @@ func StationReturnMaterialInternalHandler(svcCtx *svc.ServiceContext) http.Handl
Spec string `json:"spec"`
Qty int `json:"qty"`
Unit string `json:"unit"`
ReturnDock string `json:"returnDock"`
Reason string `json:"reason"`
Operator string `json:"operator"`
}
@@ -80,7 +81,7 @@ 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); err != nil {
req.MaterialCode, req.MaterialName, req.Spec, req.Reason, production.StationOp(r, req.Operator), req.Unit, req.Qty, req.ReturnDock); err != nil {
httpx.Fail(w, 2403, err.Error())
return
}