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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user