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,10 +10,17 @@ import (
|
||||
"bj_power_mes/ent/linepoint"
|
||||
)
|
||||
|
||||
// ============ 产线点位台账(产线布局说明·修正版) ============
|
||||
// 布局:上料位 IN(工位1/2间主线,人工投料)→ [1,2] → C1,C2 → [3,4] → C3,C4 → [5,6] → C5,C6 → [7,8] → C7,C8 → [9,10] → 上排末端11 / 下排末端12(下料检测位)
|
||||
// 接驳台:工位1~10 各 2 个(L=左侧、R=右侧,与 AGV 编号无关),属 AGV 点位,PLC 只读在位信号
|
||||
// 上料位:工位1/2 之间的主传送带,人工投料,带传感器,PLC 上报在位信号
|
||||
// ============ 产线点位台账(产线布局说明·主线位置编址版,2026-11-05 权威文档) ============
|
||||
// 主线位置统一编址 C1~C15(左→右),**没有独立缓存位**——缓存是主线位置的属性:
|
||||
// 停靠位(STOP,不缓存,工件到达即顶升进工位):C1(正对G1/G2)、C4(G3/G4)、C7(G5/G6)、
|
||||
// C10(G7/G8)、C13(G9/G10)、C15(G11/G12 进料位·下料检测);
|
||||
// 缓存位(CACHE,可缓存):C2/C3、C5/C6、C8/C9、C11/C12、C14。
|
||||
// 工件流向:C1 → 1/2 → 3/4 → 5/6 → 7/8 → 9/10 → 末端 11/12(下料检测)。
|
||||
// 业务口径(2026-11-06 拍板):缓存位(CACHE)能停工件,但与虚拟工位(负数号)无代码关联——
|
||||
// 两者只是编号空间不同,缓存位不参与工单工艺组合/工位资格校验。
|
||||
// 上料 = 人工把托盘放到主线任意位置(C1~C15)或任意工位(建档时选当前位置)。
|
||||
// 接驳台(工位 GxL/GxR 20 个 + 库房 JBT21)是 AGV 点位(dock 表),不是主线位置、不进本台账。
|
||||
// C1~C15 采用 upsert:存量旧定义(C1~C8 全 CACHE)自动对齐文档编址,并补建 C9~C15。
|
||||
|
||||
type pointDef struct {
|
||||
pointType string
|
||||
@@ -21,32 +28,63 @@ type pointDef struct {
|
||||
label string
|
||||
seq int
|
||||
stationNo int
|
||||
cacheable bool
|
||||
}
|
||||
|
||||
// InitLinePoints 初始化点位台账(幂等:只补缺失,不覆盖已占用点位)
|
||||
// lineCDefs 主线位置 C1~C15 权威定义(产线布局说明·编址表逐条对应)。
|
||||
var lineCDefs = []pointDef{
|
||||
{"STOP", "C1", "停靠位C1(工位1/2出料,正对G1/G2)", 45, 0, false},
|
||||
{"CACHE", "C2", "缓存位C2(工位1/2与3/4之间)", 50, 0, true},
|
||||
{"CACHE", "C3", "缓存位C3(工位1/2与3/4之间)", 55, 0, true},
|
||||
{"STOP", "C4", "停靠位C4(工位3/4出料,正对G3/G4)", 75, 0, false},
|
||||
{"CACHE", "C5", "缓存位C5(工位3/4与5/6之间)", 80, 0, true},
|
||||
{"CACHE", "C6", "缓存位C6(工位3/4与5/6之间)", 85, 0, true},
|
||||
{"STOP", "C7", "停靠位C7(工位5/6出料,正对G5/G6)", 105, 0, false},
|
||||
{"CACHE", "C8", "缓存位C8(工位5/6与7/8之间)", 110, 0, true},
|
||||
{"CACHE", "C9", "缓存位C9(工位5/6与7/8之间)", 115, 0, true},
|
||||
{"STOP", "C10", "停靠位C10(工位7/8出料,正对G7/G8)", 135, 0, false},
|
||||
{"CACHE", "C11", "缓存位C11(工位7/8与9/10之间)", 140, 0, true},
|
||||
{"CACHE", "C12", "缓存位C12(工位7/8与9/10之间)", 145, 0, true},
|
||||
{"STOP", "C13", "停靠位C13(工位9/10出料,正对G9/G10)", 165, 0, false},
|
||||
{"CACHE", "C14", "缓存位C14(工位9/10与11/12之间)", 170, 0, true},
|
||||
{"STOP", "C15", "进料位C15(工位11/12下料检测)", 175, 0, false},
|
||||
}
|
||||
|
||||
// InitLinePoints 初始化点位台账:
|
||||
// - C1~C15 按权威编址表 upsert(更新类型/名称/可缓存属性与主线顺序,不动占用字段);
|
||||
// - 工位/末端点位幂等只补缺失,不覆盖已占用点位。
|
||||
// 废弃的 FEED"上料位"数据清理走独立迁移 SQL(migrations/20261105_purge_feed_line_point.sql,
|
||||
// 部署时手工执行——用户裁定:禁止服务启动时更新任何数据库数据结构)。
|
||||
func (s *Service) InitLinePoints(ctx context.Context) error {
|
||||
// 主线位置 C1~C15:按文档编址 upsert(存量 C1~C8 旧"缓存位"定义自动对齐;C9~C15 补建)
|
||||
for _, d := range lineCDefs {
|
||||
exist, _ := s.ctx.EntClient.LinePoint.Query().
|
||||
Where(linepoint.PointNo(d.pointNo)).First(ctx)
|
||||
if exist != nil {
|
||||
_, _ = s.ctx.EntClient.LinePoint.UpdateOneID(exist.ID).
|
||||
SetPointType(d.pointType).SetLabel(d.label).
|
||||
SetSeq(d.seq).SetCacheable(d.cacheable).Save(ctx)
|
||||
continue
|
||||
}
|
||||
_, _ = s.ctx.EntClient.LinePoint.Create().
|
||||
SetPointType(d.pointType).SetPointNo(d.pointNo).SetLabel(d.label).
|
||||
SetSeq(d.seq).SetStationNo(d.stationNo).SetCacheable(d.cacheable).Save(ctx)
|
||||
}
|
||||
|
||||
defs := []pointDef{}
|
||||
seq := 10
|
||||
add := func(pt, no, label string, stationNo int) {
|
||||
seq += 10
|
||||
defs = append(defs, pointDef{pt, no, label, seq, stationNo})
|
||||
defs = append(defs, pointDef{pt, no, label, seq, stationNo, false})
|
||||
}
|
||||
add("FEED", "IN", "上料位(工位1/2间主线)", 0)
|
||||
for i := 1; i <= 10; i += 2 {
|
||||
add("STATION", fmt.Sprint(i), fmt.Sprintf("工位%d", i), i)
|
||||
add("STATION", fmt.Sprint(i+1), fmt.Sprintf("工位%d", i+1), i+1)
|
||||
if i <= 7 {
|
||||
add("CACHE", fmt.Sprintf("C%d", i), fmt.Sprintf("缓存位C%d", i), 0)
|
||||
add("CACHE", fmt.Sprintf("C%d", i+1), fmt.Sprintf("缓存位C%d", i+1), 0)
|
||||
}
|
||||
}
|
||||
add("END", "END-U", "上排末端下料检测位(工位11)", 11)
|
||||
add("END", "END-D", "下排末端下料检测位(工位12)", 12)
|
||||
for st := 1; st <= 10; st++ {
|
||||
for agv := 1; agv <= 2; agv++ {
|
||||
add("DOCK", fmt.Sprintf("%d-R%d", st, agv), fmt.Sprintf("工位%d %d号AGV接驳台", st, agv), st)
|
||||
}
|
||||
}
|
||||
// 注意:接驳台(GxL/GxR/JBT21)是 AGV 点位(dock 表维护),不再进点位台账;
|
||||
// 历史库遗留的 DOCK 类型行不删除、不参与主线落点(前端建档落点下拉已排除)。
|
||||
for _, d := range defs {
|
||||
exist, _ := s.ctx.EntClient.LinePoint.Query().
|
||||
Where(linepoint.PointType(d.pointType), linepoint.PointNo(d.pointNo)).First(ctx)
|
||||
@@ -55,7 +93,7 @@ func (s *Service) InitLinePoints(ctx context.Context) error {
|
||||
}
|
||||
_, _ = s.ctx.EntClient.LinePoint.Create().
|
||||
SetPointType(d.pointType).SetPointNo(d.pointNo).SetLabel(d.label).
|
||||
SetSeq(d.seq).SetStationNo(d.stationNo).Save(ctx)
|
||||
SetSeq(d.seq).SetStationNo(d.stationNo).SetCacheable(d.cacheable).Save(ctx)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -71,7 +109,7 @@ func (s *Service) ListPoints(ctx context.Context) ([]map[string]any, error) {
|
||||
out = append(out, map[string]any{
|
||||
"id": p.ID, "pointType": p.PointType, "pointNo": p.PointNo, "label": p.Label,
|
||||
"seq": p.Seq, "stationNo": p.StationNo, "currentSn": p.CurrentSn,
|
||||
"orderNo": p.OrderNo, "occupied": p.Occupied, "updatedAt": p.UpdatedAt,
|
||||
"orderNo": p.OrderNo, "occupied": p.Occupied, "cacheable": p.Cacheable, "updatedAt": p.UpdatedAt,
|
||||
})
|
||||
}
|
||||
return out, nil
|
||||
@@ -79,6 +117,8 @@ func (s *Service) ListPoints(ctx context.Context) ([]map[string]any, error) {
|
||||
|
||||
// CheckPointFree 点位可占用预检(建档/完工落账前调用,避免半量副作用):
|
||||
// 点位必须存在且未被其它工件占用(同一工件幂等放行);pointNo 为空=未选点位,直接放行。
|
||||
// 2026-11-05 产线布局说明(主线位置编址版):接驳台(DOCK=AGV 点位)不作工件落点,
|
||||
// 历史遗留行(如 1-R1)在类型层拒绝,不依赖前端下拉;FEED"上料位"已废弃删除。
|
||||
func (s *Service) CheckPointFree(ctx context.Context, pointNo, sn string) error {
|
||||
pointNo = strings.TrimSpace(pointNo)
|
||||
if pointNo == "" {
|
||||
@@ -88,6 +128,9 @@ func (s *Service) CheckPointFree(ctx context.Context, pointNo, sn string) error
|
||||
if err != nil {
|
||||
return errors.New("工件位置不存在:" + pointNo)
|
||||
}
|
||||
if pt.PointType == "DOCK" {
|
||||
return errors.New("接驳台是 AGV 点位,不能作为工件位置:" + pointNo + "(请选主线位置 C1~C15 或工位号)")
|
||||
}
|
||||
if pt.Occupied && pt.CurrentSn != strings.TrimSpace(sn) {
|
||||
return errors.New("工件位置 " + pointNo + " 已被工件 " + pt.CurrentSn + " 占用,请改选空闲点位")
|
||||
}
|
||||
@@ -97,7 +140,7 @@ func (s *Service) CheckPointFree(ctx context.Context, pointNo, sn string) error
|
||||
// OccupyPoint 点位人工记账(唯一事实源维护入口)。
|
||||
// action=IN :上料/占位,把工件 SN 记到该点位(点位被其它工件占用时报错;同一工件幂等放行)。
|
||||
// action=OUT :下料/释放,清空该点位(传入 sn 时校验点位当前就是该工件)。
|
||||
// 用途:产线首件上线、上料位(IN)投料、末端下料检测位(11/12)下料、未联调 PLC 时的人工记账。
|
||||
// 用途:产线首件上线、末端下料检测位(11/12)下料、未联调 PLC 时的人工记账。
|
||||
func (s *Service) OccupyPoint(ctx context.Context, pointNo, sn, orderNo, operator, action string) error {
|
||||
pointNo = strings.TrimSpace(pointNo)
|
||||
sn = strings.TrimSpace(sn)
|
||||
|
||||
Reference in New Issue
Block a user