feat: AGV点位锁与缓存迁移 + 工位终端去离线队列 + WMS出入库增强
【MES】 - AGV点位/线路点位/AGV任务/工单 ent schema 重构(全量重生成 ent 代码) - 新增派车锁 agv_point_lock.go:目标点位占用即拒车,JBT21 库房接驳台卸货后保持锁定待库管手动解锁 - 新增进程内 TTL 缓存 cache.go,由 Redis 看板缓存迁移至内存(singleflight 防击穿,去除外部依赖) - AGV 三段链安全机制、车辆状态/接驳台左右互换、补料损耗闭环完善 - 来料检/工序卡/工单/质检/日排产/AGV 前端与帮助文档更新 - 新增 migrations/、sql/ 目录 【WMS】 - 出库、Excel 导出、物料、路由处理增强 - 配置与 DB 初始化调整;基础数据/成品入库/入库前端调整 【工位终端】 - 移除离线同步队列(syncer 包、sync.go、SyncQueueDialog.vue),改为实时直连上报 MES(断网即失败报错),以本人身份操作 - 本地 SQLite 仅保留操作日志 + 内置账号 + 登录态;保留空闲自动登出 【文档】 - 删除 AGV海康litev1.5.md;案例.md 更新
This commit is contained in:
@@ -10,8 +10,8 @@ import (
|
||||
"bj_power_mes/internal/svc"
|
||||
)
|
||||
|
||||
// OccupyPointHandler POST /line/occupy(点位人工记账:IN 上料占位 / OUT 下料释放)
|
||||
// 供工位终端在无 PLC 联调时、或上料位(IN)/末端下料检测位(11/12) 人工操作时维护点位台账(唯一事实源)。
|
||||
// OccupyPointHandler POST /line/occupy(点位人工记账:IN 占位 / OUT 释放)
|
||||
// 供工位终端在无 PLC 联调时、或末端下料检测位(11/12) 人工操作时维护点位台账(唯一事实源)。
|
||||
func OccupyPointHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
@@ -47,7 +47,7 @@ func OccupyPointHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// ListPointsHandler GET /line/points(产线点位台账:上料位/工位/缓存位/接驳台/末端 当前工件)
|
||||
// ListPointsHandler GET /line/points(产线点位台账:主线位置/工位/末端 当前工件)
|
||||
func ListPointsHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
_ = logic.New(svcCtx).InitLinePoints(r.Context())
|
||||
|
||||
@@ -16,6 +16,7 @@ var pathPermMap = map[string]string{
|
||||
"POST:/api/v1/product-types/*": "produce.product:edit",
|
||||
"DELETE:/api/v1/product-types/*": "produce.product:delete",
|
||||
"POST:/api/v1/product-types/import": "produce.product:add",
|
||||
"POST:/api/v1/product-types/import/preview": "produce.product:add",
|
||||
"GET:/api/v1/product-types/template": "produce.product:edit",
|
||||
"POST:/api/v1/work-orders": "produce.workorder:add",
|
||||
"PUT:/api/v1/work-orders": "produce.workorder:edit",
|
||||
|
||||
@@ -298,7 +298,6 @@ func ProcessCardListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
"workOrderNo": wo.WorkOrderNo,
|
||||
"productCode": wo.ProductCode,
|
||||
"productName": wo.ProductName,
|
||||
"productSerial": wo.ProductSerial,
|
||||
"status": wo.Status,
|
||||
"planQty": wo.Quantity,
|
||||
"finishedNum": wo.FinishedNum,
|
||||
|
||||
@@ -26,12 +26,12 @@ func SubmitAgvHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
if operator == "" {
|
||||
operator = "dispatcher"
|
||||
}
|
||||
created, failed, err := logic.New(svcCtx).SubmitAgv(r.Context(), req, operator)
|
||||
created, failed, chains, err := logic.New(svcCtx).SubmitAgv(r.Context(), req, operator)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3301, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"created": created, "failed": failed})
|
||||
httpx.Ok(w, map[string]any{"created": created, "failed": failed, "chains": chains})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,40 +186,6 @@ func UpdateAgvPointHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// DispatchAgvInternalHandler POST /api/internal/agv/dispatch
|
||||
// WMS 仓库完成备料后调用(X-API-TOKEN):MES 据叫料单触发海康 RCS 派车。
|
||||
func DispatchAgvInternalHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
RequestNo string `json:"requestNo"`
|
||||
Operator string `json:"operator"`
|
||||
OutboundNo string `json:"outboundNo"`
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil || req.RequestNo == "" {
|
||||
httpx.BadRequest(w, "缺少叫料单号")
|
||||
return
|
||||
}
|
||||
op := req.Operator
|
||||
if op == "" {
|
||||
op = "warehouse"
|
||||
}
|
||||
mr, err := logic.New(svcCtx).LoadCallForDispatch(r.Context(), req.RequestNo)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3305, err.Error())
|
||||
return
|
||||
}
|
||||
if !mr.NeedAgv || mr.TargetDock == "" {
|
||||
httpx.OkMessage(w, "该叫料单无需 AGV 派车", nil)
|
||||
return
|
||||
}
|
||||
if derr := logic.New(svcCtx).DispatchAgvForCall(r.Context(), mr, op); derr != nil {
|
||||
httpx.Fail(w, 3306, "AGV 派车失败: "+derr.Error())
|
||||
return
|
||||
}
|
||||
httpx.OkMessage(w, "AGV 已派车", nil)
|
||||
}
|
||||
}
|
||||
|
||||
// AgvCallbackHandler POST /api/spi/agv/agvCallbackService/agvCallback 海康 RCS-Lite SPI 任务状态回调(文档 2.2.1)。
|
||||
// 回调体含 taskCode(当前任务单号) 与 method(start/outbin/end/cancel),据此驱动任务状态。
|
||||
// 注意:RCS 回调不带我方鉴权头,生产环境必须以防火墙/IP 白名单隔离该端点(待与 RCS 方确认鉴权方式)。
|
||||
@@ -282,6 +248,123 @@ func SetAgvVehicleStateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// AgvChainNextHandler POST /agv/chain/next 手动链「下一个节点」:body {chainNo, source?, target}
|
||||
// 当前段必须已到位;用链锁定车下发下一段(全程同一台车);RCS 未分车时拒绝并提示先刷新。
|
||||
func AgvChainNextHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
ChainNo string `json:"chainNo"`
|
||||
Source string `json:"source"`
|
||||
Target string `json:"target"`
|
||||
ConfirmForcePick string `json:"confirmForcePick"` // "1"=人工已确认强提风险点位
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil || req.ChainNo == "" {
|
||||
httpx.BadRequest(w, "缺少任务链号(chainNo)")
|
||||
return
|
||||
}
|
||||
operator := r.Header.Get("X-Username")
|
||||
if operator == "" {
|
||||
operator = "dispatcher"
|
||||
}
|
||||
taskNo, err := logic.New(svcCtx).AgvChainNextNode(r.Context(), req.ChainNo, req.Source, req.Target, operator, req.ConfirmForcePick)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3313, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"taskNo": taskNo})
|
||||
}
|
||||
}
|
||||
|
||||
// AgvChainEndHandler POST /agv/chain/end 手动链「结束任务」:body {chainNo}
|
||||
// 校验 AGV 上无托盘(载货台账+RCS 车载货架双校验),通过后本段结束并空车自动回充。
|
||||
func AgvChainEndHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
ChainNo string `json:"chainNo"`
|
||||
Force bool `json:"force"` // 人工确认无托盘强制结束(仅 RCS 查询失败时放行,后端留痕)
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &req); err != nil || req.ChainNo == "" {
|
||||
httpx.BadRequest(w, "缺少任务链号(chainNo)")
|
||||
return
|
||||
}
|
||||
operator := r.Header.Get("X-Username")
|
||||
if operator == "" {
|
||||
operator = "dispatcher"
|
||||
}
|
||||
if err := logic.New(svcCtx).AgvChainEndTask(r.Context(), req.ChainNo, operator, req.Force); err != nil {
|
||||
httpx.Fail(w, 3314, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.OkMessage(w, "任务已结束,AGV 空车自动回充", nil)
|
||||
}
|
||||
}
|
||||
|
||||
// AgvChainListHandler GET /agv/chain/list 手动链列表(任务进行中面板:链号/锁定车/节点/进行中)。
|
||||
func AgvChainListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
list, err := logic.New(svcCtx).AgvChainList(r.Context())
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3315, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, map[string]any{"list": list})
|
||||
}
|
||||
}
|
||||
|
||||
// AgvPointLockHandler POST /agv/points/:id/lock —— 点位锁定管理(派车锁 2026-11-06 拍板):
|
||||
// body {locked bool, reason string, clearForcePick bool}
|
||||
// locked=true → 人工锁定(reason 必填,locked_by=manual,仅人工解锁);
|
||||
// locked=false → 人工解锁(含 JBT21 手动解锁、系统锁人工释放);
|
||||
// clearForcePick=true → 清除强提风险标记(人工确认现场安全后)。
|
||||
// 全部操作 event_log 留痕。
|
||||
func AgvPointLockHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
id := pathID(r)
|
||||
if id <= 0 {
|
||||
httpx.BadRequest(w, "非法的点位 ID")
|
||||
return
|
||||
}
|
||||
var body struct {
|
||||
Locked bool `json:"locked"` // true=人工锁定
|
||||
Unlock bool `json:"unlock"` // true=人工解锁(含 JBT21/系统锁)
|
||||
Reason string `json:"reason"` // 锁定原因(锁定时必填)
|
||||
ClearForcePick bool `json:"clearForcePick"` // true=清除强提风险标记
|
||||
}
|
||||
if err := httpx.ParseJSON(r, &body); err != nil {
|
||||
httpx.BadRequest(w, "请求体解析失败")
|
||||
return
|
||||
}
|
||||
if !body.Locked && !body.Unlock && !body.ClearForcePick {
|
||||
httpx.BadRequest(w, "无可执行操作(locked/unlock/clearForcePick 任选其一)")
|
||||
return
|
||||
}
|
||||
operator := r.Header.Get("X-Username")
|
||||
if operator == "" {
|
||||
operator = "admin"
|
||||
}
|
||||
lg := logic.New(svcCtx)
|
||||
if body.ClearForcePick {
|
||||
if err := lg.ClearAgvPointForcePick(r.Context(), id, operator); err != nil {
|
||||
httpx.Fail(w, 3316, err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
if body.Locked {
|
||||
if err := lg.SetAgvPointLockManual(r.Context(), id, true, body.Reason, operator); err != nil {
|
||||
httpx.Fail(w, 3316, err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
if body.Unlock {
|
||||
if err := lg.SetAgvPointLockManual(r.Context(), id, false, "", operator); err != nil {
|
||||
httpx.Fail(w, 3316, err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
httpx.OkMessage(w, "已保存", nil)
|
||||
}
|
||||
}
|
||||
|
||||
// atoiSafe 安全解析分页参数(非法/缺省回退 def)。
|
||||
func atoiSafe(s string, def int) int {
|
||||
if s == "" {
|
||||
|
||||
@@ -20,10 +20,11 @@ import (
|
||||
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"`
|
||||
TaskNo string `json:"taskNo"`
|
||||
BizNo string `json:"bizNo"` // 可选:WMS 装车确认只知叫料单号
|
||||
Action string `json:"action"`
|
||||
NextDock string `json:"nextDock"`
|
||||
ConfirmForcePick string `json:"confirmForcePick"` // "1"=人工已确认强提风险点位
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
httpx.Fail(w, 400, "参数错误: "+err.Error())
|
||||
@@ -45,7 +46,7 @@ func ConfirmAgvHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
var err error
|
||||
switch req.Action {
|
||||
case "load_go":
|
||||
err = lg.ConfirmLoadAndGo(r.Context(), req.TaskNo, req.NextDock, op)
|
||||
err = lg.ConfirmLoadAndGo(r.Context(), req.TaskNo, req.NextDock, op, req.ConfirmForcePick)
|
||||
case "unload_release":
|
||||
err = lg.ConfirmUnloadRelease(r.Context(), req.TaskNo, op)
|
||||
case "finish_return":
|
||||
@@ -67,8 +68,9 @@ func ConfirmAgvHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
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"`
|
||||
Source string `json:"source"`
|
||||
Target string `json:"target"`
|
||||
ConfirmForcePick string `json:"confirmForcePick"` // "1"=人工已确认强提风险点位
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
||||
httpx.Fail(w, 400, "参数错误: "+err.Error())
|
||||
@@ -78,7 +80,7 @@ func FreeDispatchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
if op == "" {
|
||||
op = "system"
|
||||
}
|
||||
taskNo, err := logic.New(svcCtx).FreeDispatch(r.Context(), req.Source, req.Target, op)
|
||||
taskNo, err := logic.New(svcCtx).FreeDispatch(r.Context(), req.Source, req.Target, op, req.ConfirmForcePick)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 500, err.Error())
|
||||
return
|
||||
|
||||
@@ -38,6 +38,34 @@ func ImportProductTypesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// ImportProductTypesPreviewHandler POST /product-types/import/preview 物料档案导入预检
|
||||
// 只读:解析+逐行校验,不写任何数据。返回 {total 总行数, success 将成功行数, failed 失败行数, errors 逐行原因}。
|
||||
func ImportProductTypesPreviewHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if err := r.ParseMultipartForm(32 << 20); err != nil {
|
||||
httpx.BadRequest(w, "表单解析失败,请使用 multipart/form-data 上传文件")
|
||||
return
|
||||
}
|
||||
file, _, err := r.FormFile("file")
|
||||
if err != nil {
|
||||
httpx.BadRequest(w, "未找到上传文件(字段名 file)")
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
data, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3016, "读取文件失败:"+err.Error())
|
||||
return
|
||||
}
|
||||
res, err := logic.New(svcCtx).PreviewProductTypesImport(r.Context(), data)
|
||||
if err != nil {
|
||||
httpx.Fail(w, 3016, err.Error())
|
||||
return
|
||||
}
|
||||
httpx.Ok(w, res)
|
||||
}
|
||||
}
|
||||
|
||||
// DownloadProductTypeTemplateHandler GET /product-types/template 物料档案 Excel 导入模板下载
|
||||
func DownloadProductTypeTemplateHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
@@ -23,6 +23,8 @@ import (
|
||||
// 工艺路线卡(产品级定义层卡片,2026-10-09 客户裁定恢复)
|
||||
//
|
||||
// 定位:回答「这个产品应该怎么做」——产品工艺的路线 + 每道工艺的步骤配置 + 物料清单 + 检验卡项。
|
||||
// 业务口径(2026-11-06 拍板):工艺路线显示工位号——路线卡表格含「绑定工位」列、
|
||||
// 产品工艺页工序行展示「工位N,N」;注意工单详情抽屉按 2026-10-19 裁定不显示工位列(工位号仅作排序)。
|
||||
// 与「生产流程卡」(工单实绩层)分离:本卡只读定义、不复制不落表;工单页不嵌入本卡,
|
||||
// 工单想看定义层时跳转到「产品工艺」页查看/打印(客户裁定)。
|
||||
// 端点:GET /api/v1/product-processes/card?id=N 默认可打印 HTML;?format=json 返回结构化数据。
|
||||
@@ -144,7 +146,10 @@ func buildProductProcessCard(ctx context.Context, svcCtx *svc.ServiceContext, id
|
||||
one := c.Name
|
||||
switch c.Logic {
|
||||
case "BETWEEN":
|
||||
one += fmt.Sprintf(" %g~%g", c.Min, c.Max)
|
||||
// 修复(2026-11-06):Min/Max 为 *float64,%g 直接传指针会打印地址;判空后取值,空则不展示区间
|
||||
if c.Min != nil && c.Max != nil {
|
||||
one += fmt.Sprintf(" %g~%g", *c.Min, *c.Max)
|
||||
}
|
||||
case "GT":
|
||||
one += fmt.Sprintf(" >%g", c.Target)
|
||||
case "LT":
|
||||
|
||||
@@ -300,10 +300,6 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodGet, Path: "/api/internal/agv/mode", Handler: internal(production.AgvModeHandler(serverCtx)),
|
||||
})
|
||||
// 叫料完成备料后由 MES 自动派车(CompleteCall 内部已触发);此端点为手动补派/重试专用
|
||||
server.AddRoute(rest.Route{
|
||||
Method: http.MethodPost, Path: "/api/internal/agv/dispatch", Handler: internal(production.DispatchAgvInternalHandler(serverCtx)),
|
||||
})
|
||||
|
||||
// ---------- JWT 业务 API ----------
|
||||
jwtRoutes := []rest.Route{
|
||||
@@ -311,6 +307,7 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
{Method: http.MethodGet, Path: "/product-types/page", Handler: production.ListProductTypesPageHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/product-types/export", Handler: production.ExportProductTypesHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/product-types/import", Handler: production.ImportProductTypesHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/product-types/import/preview", Handler: production.ImportProductTypesPreviewHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/product-types/template", Handler: production.DownloadProductTypeTemplateHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/product-types", Handler: production.CreateProductTypeHandler(serverCtx)},
|
||||
{Method: http.MethodPut, Path: "/product-types", Handler: production.UpdateProductTypeHandler(serverCtx)},
|
||||
@@ -414,10 +411,16 @@ func RegisterProductionRoutes(server *rest.Server, serverCtx *svc.ServiceContext
|
||||
{Method: http.MethodPost, Path: "/agv/refresh", Handler: production.RefreshAgvTasksHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/agv/cancel", Handler: production.CancelAgvTaskHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/agv/retry", Handler: production.RetryAgvTaskHandler(serverCtx)},
|
||||
// 手动多段链(2026-11-06 拍板):逐节点人工推进,全程锁同一台车
|
||||
{Method: http.MethodPost, Path: "/agv/chain/next", Handler: production.AgvChainNextHandler(serverCtx)},
|
||||
{Method: http.MethodPost, Path: "/agv/chain/end", Handler: production.AgvChainEndHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/agv/chain/list", Handler: production.AgvChainListHandler(serverCtx)},
|
||||
{Method: http.MethodGet, Path: "/agv/mode", Handler: production.AgvModeHandler(serverCtx)},
|
||||
// AGV 点位管理(独立点位表:硬件映射编码/接驳台绑定不可改,仅名称/启用可改)
|
||||
{Method: http.MethodGet, Path: "/agv/points", Handler: production.ListAgvPointsHandler(serverCtx)},
|
||||
{Method: http.MethodPut, Path: "/agv/points/:id", Handler: production.UpdateAgvPointHandler(serverCtx)},
|
||||
// 点位锁定管理(派车锁 2026-11-06 拍板):人工锁定/解锁 + 清强提标记
|
||||
{Method: http.MethodPost, Path: "/agv/points/:id/lock", Handler: production.AgvPointLockHandler(serverCtx)},
|
||||
// 车辆状态只读展示(海康 3.1.7,2026-11-03 拍板:纯只读,不干预调度)
|
||||
{Method: http.MethodGet, Path: "/agv/vehicles", Handler: production.ListAgvVehiclesHandler(serverCtx)},
|
||||
// AGV 载货状态台账(2026-11-04 防撞校验补做):取货/卸货确认自动维护 + 人工维护留痕;
|
||||
|
||||
Reference in New Issue
Block a user