feat: 重构 AGV 对接与在制品查询,新增 PLC 手动监控功能
This commit is contained in:
@@ -78,7 +78,8 @@ type OnlineReq struct {
|
||||
Sn string `json:"sn"`
|
||||
OrderNo string `json:"orderNo"`
|
||||
WorkOrderId int `json:"workOrderId"`
|
||||
StationNo int `json:"stationNo"` // 建档落点工位(二.4/二.11);0/空=沿用旧虚拟位模型(终端 0/13 重构未完成时兼容)
|
||||
StationNo int `json:"stationNo"` // 建档落点工位(必填;业务定稿·一.3/一.4/一.11)
|
||||
PointNo string `json:"pointNo"` // 工件当前位置(产线点位台账编号:IN/C1/1-R1/工位号等);空=未选,不落账
|
||||
}
|
||||
|
||||
// OnlineWorkpiece 工件进线登记(返回提示文案,供响应透出)。
|
||||
@@ -102,6 +103,10 @@ type OnlineReq struct {
|
||||
// PLC↔MES 对账(#8 T5 建档提交):建档成功后做单工位对账,命中则返回 mismatch(提示不拦),
|
||||
// 供工位终端弹四选对话框(新件建档/绑定已知件/报异常/忽略)。
|
||||
func (s *Service) OnlineWorkpiece(ctx context.Context, req OnlineReq, operator string) (string, *PlcMesMismatch, error) {
|
||||
// 工件当前位置预检(建档前 fail-fast,点位不存在/被占用直接拒绝,不产生半量副作用)
|
||||
if err := s.CheckPointFree(ctx, req.PointNo, req.Sn); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
// 重上线识别先于分流:重上线不涉及发号/SN 校验
|
||||
if req.Sn != "" {
|
||||
exist, err := s.ctx.EntClient.Workpiece.Query().Where(workpiece.Sn(req.Sn)).First(ctx)
|
||||
@@ -177,8 +182,12 @@ func (s *Service) OnlineWorkpiece(ctx context.Context, req OnlineReq, operator s
|
||||
// 二.2 物理位置:建档落点写入 at_station;三.2 状态流水 NEW→ONLINE
|
||||
s.writeLifecycle(ctx, req.Sn, req.OrderNo, "NEW", "ONLINE", req.StationNo, 0, operator, "workstation", "上线建档")
|
||||
s.ctx.EventLog.Write(ctx, "workpiece.online", req.OrderNo, operator, "workpiece", req.Sn,
|
||||
"工件进线登记", map[string]any{"snMode": snMode, "stationNo": req.StationNo,
|
||||
"工件进线登记", map[string]any{"snMode": snMode, "stationNo": req.StationNo, "pointNo": req.PointNo,
|
||||
"snSource": map[int]string{1: "SCANNED", 2: "AUTO"}[snMode]})
|
||||
// 工件当前位置落账(点位台账:建档即占位;PointNo 空=未选,跳过)
|
||||
if err := s.occupyStartPoint(ctx, req.PointNo, req.Sn, req.OrderNo, operator); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
s.notifyDashboard()
|
||||
// PLC↔MES 对账(#8 T5 建档提交):提示不拦,仅透出 mismatch 供终端弹窗
|
||||
mm, _ := s.detectAndRecord(ctx, req.StationNo, "terminal", req.OrderNo, operator)
|
||||
@@ -193,7 +202,7 @@ func (s *Service) OnlineWorkpiece(ctx context.Context, req OnlineReq, operator s
|
||||
//
|
||||
// ③ 下一站工位当天停单时提示"工位N已停止接单"(复用 GetStationPaused 既有停单判定,不阻断登记)。
|
||||
// onlineNewWorkpiece 预生成 SN 首次上线建档(NEW→ONLINE)。
|
||||
// 二.4 资格校验:新件必须落点在工序1工位(工艺组合中工位号最小者);落点未传(终端 0/13 重构未完成)时放行但不校验。
|
||||
// 二.4 资格校验:新件必须落点在工序1工位(工艺组合中工位号最小者),落点必填。
|
||||
// 不涉及 WMS 出库(从未入半成品库);写物理位置 at_station=落点,记生命周期 NEW→ONLINE。
|
||||
func (s *Service) onlineNewWorkpiece(ctx context.Context, wp *ent.Workpiece, req OnlineReq, operator string) (string, *PlcMesMismatch, error) {
|
||||
wo := s.workpieceWorkOrder(ctx, wp)
|
||||
@@ -207,13 +216,13 @@ func (s *Service) onlineNewWorkpiece(ctx context.Context, wp *ent.Workpiece, req
|
||||
first = it.StationNo
|
||||
}
|
||||
}
|
||||
if req.StationNo > 0 && req.StationNo != first {
|
||||
if req.StationNo <= 0 {
|
||||
return "", nil, errors.New("建档落点工位必填")
|
||||
}
|
||||
if req.StationNo != first {
|
||||
return "", nil, fmt.Errorf("新件建档必须落在工序1工位(工位%d),当前落点工位%d不符合资格", first, req.StationNo)
|
||||
}
|
||||
station := req.StationNo
|
||||
if station == 0 {
|
||||
station = first // 终端未传落点时按工序1兜底,避免 at_station 失真
|
||||
}
|
||||
if _, e := s.ctx.EntClient.Workpiece.UpdateOneID(wp.ID).
|
||||
SetStatus("ONLINE").SetOnlineAt(time.Now()).SetAtStationNo(station).Save(ctx); e != nil {
|
||||
return "", nil, e
|
||||
@@ -221,7 +230,11 @@ func (s *Service) onlineNewWorkpiece(ctx context.Context, wp *ent.Workpiece, req
|
||||
// 二.2 物理位置 + 三.2 状态流水 NEW→ONLINE
|
||||
s.writeLifecycle(ctx, wp.Sn, wp.OrderNo, "NEW", "ONLINE", station, 0, operator, "workstation", "上线建档")
|
||||
s.ctx.EventLog.Write(ctx, "workpiece.online", wp.OrderNo, operator, "workpiece", wp.Sn,
|
||||
"预生成SN上线建档", map[string]any{"stationNo": station})
|
||||
"预生成SN上线建档", map[string]any{"stationNo": station, "pointNo": req.PointNo})
|
||||
// 工件当前位置落账(点位台账:建档即占位)
|
||||
if err := s.occupyStartPoint(ctx, req.PointNo, wp.Sn, wp.OrderNo, operator); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
s.notifyDashboard()
|
||||
// PLC↔MES 对账(#8 T5 建档提交):提示不拦,仅透出 mismatch 供终端弹窗
|
||||
mm, _ := s.detectAndRecord(ctx, station, "terminal", wp.OrderNo, operator)
|
||||
@@ -233,7 +246,7 @@ func (s *Service) onlineNewWorkpiece(ctx context.Context, wp *ent.Workpiece, req
|
||||
// ② 再调 SemiFlow(OUTBOUND) 让 WMS 半成品出库,失败则报错不继续(文案含 WMS 原文)——
|
||||
// 顺序保证:校验全部通过后才产生出库这一副作用,避免"已出库却登记失败"的悬挂状态;
|
||||
// ③ 下一站工位当天停单时提示"工位N已停止接单"(复用 GetStationPaused 既有停单判定,不阻断登记)。
|
||||
// 出库一次解锁一次(一.5):置回 ONLINE 并写物理位置 at_station=下一站;记生命周期 SEMI_OUT。
|
||||
// 出库一次解锁一次(业务定稿·一.5):置回 ONLINE 并写物理位置 at_station=下一站;记生命周期 SEMI_OUT。
|
||||
func (s *Service) reonlineWorkpiece(ctx context.Context, wp *ent.Workpiece, req OnlineReq, operator string) (string, *PlcMesMismatch, error) {
|
||||
items, _ := RouteStationsFromWO(ctx, s.ctx.EntClient, s.workpieceWorkOrder(ctx, wp))
|
||||
if len(items) == 0 {
|
||||
@@ -248,7 +261,7 @@ func (s *Service) reonlineWorkpiece(ctx context.Context, wp *ent.Workpiece, req
|
||||
if next == 0 {
|
||||
return "", nil, fmt.Errorf("工件已报工至工位%d,工艺组合中无下一站", wp.CurrentStationNo)
|
||||
}
|
||||
// 二.4 资格校验:半成品(SEMI_STORED)重上线落点须为后续工序工位(=下一站);未传落点时按下一站兜底
|
||||
// 二.4 资格校验:半成品(SEMI_STORED)重上线落点须为后续工序工位(=下一站);落点未传时按下一站执行
|
||||
if req.StationNo > 0 && req.StationNo != next {
|
||||
return "", nil, fmt.Errorf("半成品重上线须落在后续工序工位(工位%d),当前落点工位%d不符合资格", next, req.StationNo)
|
||||
}
|
||||
@@ -267,13 +280,26 @@ func (s *Service) reonlineWorkpiece(ctx context.Context, wp *ent.Workpiece, req
|
||||
msg += "(注意:工位" + itoa(next) + "已停止接单)"
|
||||
}
|
||||
s.ctx.EventLog.Write(ctx, "workpiece.reonline", wp.OrderNo, operator, "workpiece", wp.Sn,
|
||||
"工件重上线(暂存退库后出库继续)", map[string]any{"nextStationNo": next, "nextFlowId": nextFlow})
|
||||
"工件重上线(暂存退库后出库继续)", map[string]any{"nextStationNo": next, "nextFlowId": nextFlow, "pointNo": req.PointNo})
|
||||
// 工件当前位置落账(点位台账:重上线即占位)
|
||||
if err := s.occupyStartPoint(ctx, req.PointNo, wp.Sn, wp.OrderNo, operator); err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
s.notifyDashboard()
|
||||
// PLC↔MES 对账(#8 T5 建档提交):提示不拦,仅透出 mismatch 供终端弹窗
|
||||
mm, _ := s.detectAndRecord(ctx, next, "terminal", wp.OrderNo, operator)
|
||||
return msg, mm, nil
|
||||
}
|
||||
|
||||
// occupyStartPoint 建档落账:把工件当前位置(产线点位台账)记为占用。
|
||||
// pointNo 空=终端未选位置(旧模型兼容),跳过不报错;调用前须已过 CheckPointFree 预检。
|
||||
func (s *Service) occupyStartPoint(ctx context.Context, pointNo, sn, orderNo, operator string) error {
|
||||
if strings.TrimSpace(pointNo) == "" {
|
||||
return nil
|
||||
}
|
||||
return s.OccupyPoint(ctx, pointNo, sn, orderNo, operator, "IN")
|
||||
}
|
||||
|
||||
// writeLifecycle 写工件生命周期状态流水(三.2 / P2 定稿:所有 status 变更点同事务写)。
|
||||
// action 值域:NEW/ONLINE/REPORT/SEMI_IN/SEMI_OUT/DONE/SCRAPPED;from/to 为变更前后状态。
|
||||
// 入库次数统一 count(action='SEMI_IN'),不再依赖 semiflow(CountSemiStored 已删)。
|
||||
@@ -715,10 +741,15 @@ type DoneReq struct {
|
||||
Sn string `json:"sn"`
|
||||
BatchItems []string `json:"batchItems"` // 序列号=否:批次号
|
||||
SerialItems []string `json:"serialItems"` // 序列号=是:SN
|
||||
PointNo string `json:"pointNo"` // 下料落点(产线点位台账编号:END-U 上排/END-D 下排);空=未选,不落账
|
||||
}
|
||||
|
||||
// DoneWorkpiece 完工:先兜底校验全部工序装配物料齐套(工艺流程强校验),再登记成品并生成关联追溯
|
||||
func (s *Service) DoneWorkpiece(ctx context.Context, req DoneReq, operator string) error {
|
||||
// 下料落点预检(完工前 fail-fast:落点不存在/被占用直接拒绝,避免完工后无法落账)
|
||||
if err := s.CheckPointFree(ctx, req.PointNo, req.Sn); err != nil {
|
||||
return err
|
||||
}
|
||||
wp, err := s.ctx.EntClient.Workpiece.Query().Where(workpiece.Sn(req.Sn)).First(ctx)
|
||||
if err != nil {
|
||||
return errors.New("工件不存在")
|
||||
@@ -762,6 +793,10 @@ func (s *Service) DoneWorkpiece(ctx context.Context, req DoneReq, operator strin
|
||||
}
|
||||
// 三.2 状态流水:DONE→DONE;SEMI_STORED→补 INBOUND 缺口(SEMI_IN)
|
||||
s.writeLifecycle(ctx, req.Sn, wp.OrderNo, wp.Status, status, 0, 0, operator, "workstation", "下线完工")
|
||||
// 下料落点落账(点位台账:完工/半成品入库均登记末端下料检测位占用)
|
||||
if err := s.occupyStartPoint(ctx, req.PointNo, req.Sn, wp.OrderNo, operator); err != nil {
|
||||
return err
|
||||
}
|
||||
if status == "DONE" {
|
||||
existID, _ := s.ctx.EntClient.AssociationTrace.Query().
|
||||
Where(associationtrace.FinishedSn(req.Sn)).FirstID(ctx)
|
||||
@@ -782,9 +817,9 @@ func (s *Service) DoneWorkpiece(ctx context.Context, req DoneReq, operator strin
|
||||
}
|
||||
s.bumpWorkOrderProgress(ctx, wp.OrderNo, req.Sn)
|
||||
s.bumpDailyPlanCompleted(ctx, wp.OrderNo, now)
|
||||
s.ctx.EventLog.Write(ctx, "workpiece.done", wp.OrderNo, operator, "workpiece", req.Sn, "完工+关联追溯", map[string]any{"batchItems": req.BatchItems, "serialItems": req.SerialItems})
|
||||
s.ctx.EventLog.Write(ctx, "workpiece.done", wp.OrderNo, operator, "workpiece", req.Sn, "完工+关联追溯", map[string]any{"batchItems": req.BatchItems, "serialItems": req.SerialItems, "pointNo": req.PointNo})
|
||||
} else {
|
||||
s.ctx.EventLog.Write(ctx, "workpiece.semi_stored", wp.OrderNo, operator, "workpiece", req.Sn, "下线完工(半成品入库)", map[string]any{"routeCount": routeCount, "reported": reported})
|
||||
s.ctx.EventLog.Write(ctx, "workpiece.semi_stored", wp.OrderNo, operator, "workpiece", req.Sn, "下线完工(半成品入库)", map[string]any{"routeCount": routeCount, "reported": reported, "pointNo": req.PointNo})
|
||||
}
|
||||
s.notifyDashboard()
|
||||
return nil
|
||||
@@ -955,8 +990,8 @@ type InProcessItem struct {
|
||||
OrderNo string `json:"orderNo"`
|
||||
ProductCode string `json:"productCode"`
|
||||
ProductName string `json:"productName"`
|
||||
CurrentStation int `json:"currentStation"` // 0=上线位, 13=下线位, 其余为物理工位
|
||||
CurrentStationName string `json:"currentStationName"` // 工位显示名(上线位/下线位/装配X)
|
||||
CurrentStation int `json:"currentStation"` // 0=待流转(未分配工位), 13=末端待取件, 其余为物理工位
|
||||
CurrentStationName string `json:"currentStationName"` // 工位显示名(待流转/末端待取件/装配X)
|
||||
Status string `json:"status"`
|
||||
OnlineAt string `json:"onlineAt"`
|
||||
DwellSec int64 `json:"dwellSec"` // 停留时长(秒),自进线起算
|
||||
@@ -965,10 +1000,14 @@ type InProcessItem struct {
|
||||
}
|
||||
|
||||
// WorkpiecesInProcess 列出停在各工位、尚未完工的在制品(ONLINE/PROCESSING)。
|
||||
// stationNo<=0 返回全部;stationNo>0 仅返回当前停在该工位的工件。
|
||||
// 位置口径(原虚拟位 0/13 魔法值已废除,业务定稿·一.10):
|
||||
// - stationNo>0 :仅返回停在该工位的工件(currentStationNo 匹配)
|
||||
// - scope=pending :待流转(ONLINE 未报工、未分配工位)
|
||||
// - scope=end-pending :末端待取件(PROCESSING 且已报工至工艺路线末端工位)
|
||||
// - 以上皆空 :返回全部
|
||||
// orderNo 非空时按工单号模糊过滤(客户第12条「记录查看加一项看工单号查询」)。
|
||||
// 已进线未完工的工件跨天继续,日排产仅排「未开工数量」,不会重复排产。
|
||||
func (s *Service) WorkpiecesInProcess(ctx context.Context, stationNo int, orderNo string) ([]InProcessItem, error) {
|
||||
func (s *Service) WorkpiecesInProcess(ctx context.Context, stationNo int, orderNo, scope string) ([]InProcessItem, error) {
|
||||
q := s.ctx.EntClient.Workpiece.Query().
|
||||
Where(workpiece.Or(
|
||||
workpiece.Status("ONLINE"),
|
||||
@@ -1007,17 +1046,20 @@ func (s *Service) WorkpiecesInProcess(ctx context.Context, stationNo int, orderN
|
||||
maxStation = c
|
||||
}
|
||||
}
|
||||
// 推算当前物理工位:ONLINE 在未分配工位;PROCESSING 且已到末端 → 对应下线位
|
||||
cur := 0
|
||||
if wp.Status == "PROCESSING" {
|
||||
cp := wp.CurrentStationNo
|
||||
if cp <= 0 {
|
||||
cp = maxStation
|
||||
// 显示口径按 status 派生(原 0/13 魔法值已废除,业务定稿·一.10):
|
||||
// 待流转 = ONLINE 未报工(未分配工位)
|
||||
// 末端待取件 = PROCESSING 且已报工至工艺路线末端工位
|
||||
// 其余 = 真实工位显示名
|
||||
cur := wp.CurrentStationNo
|
||||
atEnd := wp.Status == "PROCESSING" && maxStation > 0 && cur >= maxStation
|
||||
switch scope {
|
||||
case "pending":
|
||||
if wp.Status != "ONLINE" || cur > 0 {
|
||||
continue
|
||||
}
|
||||
if cp >= maxStation && wp.Status == "PROCESSING" {
|
||||
cur = 13
|
||||
} else {
|
||||
cur = cp
|
||||
case "end-pending":
|
||||
if !atEnd {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if stationNo > 0 && cur != stationNo {
|
||||
@@ -1045,11 +1087,14 @@ func (s *Service) WorkpiecesInProcess(ctx context.Context, stationNo int, orderN
|
||||
code, name = wo.ProductCode, wo.ProductName
|
||||
}
|
||||
}
|
||||
stName := stationDisplayName("", cur)
|
||||
if cur == 0 {
|
||||
stName = "上线位(虚拟)"
|
||||
} else if cur == 13 {
|
||||
stName = "下线位(虚拟)"
|
||||
stName := ""
|
||||
switch {
|
||||
case wp.Status == "ONLINE" && cur <= 0:
|
||||
stName = "待流转"
|
||||
case atEnd:
|
||||
stName = "末端待取件"
|
||||
default:
|
||||
stName = stationDisplayName("", cur)
|
||||
}
|
||||
out = append(out, InProcessItem{
|
||||
Sn: wp.Sn,
|
||||
|
||||
Reference in New Issue
Block a user