refactor(mes): 移除工位接驳台绑定逻辑,改为独立dock主数据
- 移除station表的hasDock、dockCode字段及相关代码 - 新增dock表注释及关联逻辑,支持一个工位绑定多个接驳台 - 更新工位相关的seed、logic、schema及前端代码,适配新的接驳台管理方式 - 新增SQL注释固化脚本,完善MES表注释
This commit is contained in:
@@ -263,8 +263,6 @@ type StationVO struct {
|
||||
StationType string `json:"stationType"`
|
||||
Status string `json:"status"`
|
||||
IsBuiltin bool `json:"isBuiltin"`
|
||||
HasDock bool `json:"hasDock"`
|
||||
DockCode string `json:"dockCode"`
|
||||
VisibleTabs []string `json:"visibleTabs"`
|
||||
}
|
||||
|
||||
@@ -280,7 +278,7 @@ func (s *Service) ListStations(ctx context.Context) ([]*StationVO, error) {
|
||||
}
|
||||
out := make([]*StationVO, 0, len(stas))
|
||||
for _, st := range stas {
|
||||
vo := &StationVO{Id: st.ID, StationNo: st.StationNo, Name: st.Name, FlowId: st.FlowId, StationType: st.StationType, Status: st.Status, IsBuiltin: st.IsBuiltin, HasDock: st.HasDock, DockCode: st.DockCode, VisibleTabs: st.VisibleTabs}
|
||||
vo := &StationVO{Id: st.ID, StationNo: st.StationNo, Name: st.Name, FlowId: st.FlowId, StationType: st.StationType, Status: st.Status, IsBuiltin: st.IsBuiltin, VisibleTabs: st.VisibleTabs}
|
||||
if f, ok := flowMap[st.FlowId]; ok {
|
||||
vo.FlowName = f.Name
|
||||
}
|
||||
@@ -296,8 +294,7 @@ func (s *Service) ListStations(ctx context.Context) ([]*StationVO, error) {
|
||||
// 工位数量以数据库为准,前端下拉随 station 表自动增减;虚拟工位(0/13/14...)不连 PLC、仅记录。
|
||||
// 内置工位(种子/初始化数据,is_builtin=true)需连 PLC 并必须按工位号顺序流转,
|
||||
// 不允许手动更改工位类型;页面新增的工位一律为非内置,可改类型、可删除。
|
||||
// 「是否有接驳台」对应实体位置,由内置数据给定,不接收页面入参。
|
||||
// 接驳台↔工位 1:1 绑定为系统预置只读主数据,由种子初始化,页面不可更改、也不接收页面入参。
|
||||
// 接驳台为独立主数据(MES dock 表),一个工位可绑定多个接驳台,关系以 dock.station_no 为准,页面不维护。
|
||||
func (s *Service) SaveStation(ctx context.Context, req StationReq, operator string) error {
|
||||
if req.StationNo < 0 {
|
||||
return errors.New("工位号非法(需 ≥ 0)")
|
||||
@@ -321,8 +318,7 @@ func (s *Service) SaveStation(ctx context.Context, req StationReq, operator stri
|
||||
cr := s.ctx.EntClient.Station.Create().
|
||||
SetStationNo(req.StationNo).SetName(req.Name).SetStationType(stype).SetStatus("ENABLED").
|
||||
// 页面「新增工位」创建的是非内置工位(可改类型、可删除);内置工位只能由种子/初始化数据产生。
|
||||
// 是否有接驳台对应实体位置,由内置数据给定,页面新增时一律为 false 且不可手改。
|
||||
SetIsBuiltin(false).SetHasDock(false)
|
||||
SetIsBuiltin(false)
|
||||
if len(req.VisibleTabs) > 0 {
|
||||
cr.SetVisibleTabs(req.VisibleTabs)
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ type ProductTypeReq struct {
|
||||
ManageMode int `json:"manageMode"` // 类型 1结构件/2电气件/3其他(必选)
|
||||
SnMode int `json:"snMode"` // 是否逐件SN管理 1序列号件/2批次件(必选,0=未选择不可保存)
|
||||
IsActive bool `json:"isActive"`
|
||||
Description string `json:"description"` // 说明(与 WMS 物料档案同口径,可空)
|
||||
}
|
||||
|
||||
// validateTypeAndSnMode 建档必选校验:类型 1/2/3、序列号件 1/2(0=未选择直接拒绝)。
|
||||
@@ -117,6 +118,7 @@ func (s *Service) CreateProductType(ctx context.Context, req ProductTypeReq) err
|
||||
SetName(req.Name).
|
||||
SetSpec(req.Spec).
|
||||
SetUnit(req.Unit).
|
||||
SetDescription(req.Description).
|
||||
SetItemType(3).
|
||||
SetManageMode(req.ManageMode).
|
||||
SetSnMode(req.SnMode).
|
||||
@@ -156,6 +158,7 @@ func (s *Service) UpdateProductType(ctx context.Context, req ProductTypeReq) err
|
||||
SetName(req.Name).
|
||||
SetSpec(req.Spec).
|
||||
SetUnit(req.Unit).
|
||||
SetDescription(req.Description).
|
||||
SetManageMode(req.ManageMode).
|
||||
SetSnMode(req.SnMode).
|
||||
SetIsActive(req.IsActive).
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/ent/alert"
|
||||
dockent "bj_power_mes/ent/dock"
|
||||
"bj_power_mes/ent/materialqtyreport"
|
||||
"bj_power_mes/ent/station"
|
||||
)
|
||||
|
||||
// ============ 数量不符(工位上报 → 处理闭环) ============
|
||||
@@ -172,11 +172,11 @@ func (s *Service) HandleQtyReport(ctx context.Context, id int, handleType, note,
|
||||
if rep.DiffQty <= 0 {
|
||||
return nil, errors.New("本单为「多发」,不能走补发;请选择退库或调整")
|
||||
}
|
||||
// 目标接驳台:取该工位绑定的接驳台(无则空,由 WMS 侧按默认处理)
|
||||
// 目标接驳台:取该工位关联的接驳台(一个工位可绑多个接驳台,取第一个;无则空,由 WMS 侧按默认处理)
|
||||
dock := ""
|
||||
if st, e := s.ctx.EntClient.Station.Query().
|
||||
Where(station.StationNo(rep.StationNo)).Only(ctx); e == nil {
|
||||
dock = st.DockCode
|
||||
if dk, e := s.ctx.EntClient.Dock.Query().
|
||||
Where(dockent.StationNo(rep.StationNo)).First(ctx); e == nil {
|
||||
dock = dk.DockCode
|
||||
}
|
||||
reqNo := fmt.Sprintf("MR%d", time.Now().UnixNano())
|
||||
create := s.ctx.EntClient.MaterialRequest.Create().
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"bj_power_mes/ent/dock"
|
||||
"bj_power_mes/ent/permission"
|
||||
"bj_power_mes/ent/role"
|
||||
"bj_power_mes/ent/station"
|
||||
@@ -203,8 +202,6 @@ func (s *Service) Seed(ctx context.Context) error {
|
||||
seedStations(ctx, s)
|
||||
// 5. 接驳台主数据(真源在 MES,2026-09-21 自 WMS 迁入);系统预置只读
|
||||
seedDocks(ctx, s)
|
||||
// 6. 接驳台↔工位默认绑定(系统预置只读主数据;一工位可绑多接驳台,station.dock_code 仅存默认接驳台兜底)
|
||||
bindStationDocks(ctx, s)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -246,7 +243,7 @@ func seedStations(ctx context.Context, s *Service) {
|
||||
if _, err := s.ctx.EntClient.Station.Query().Where(station.StationNo(i)).First(ctx); err != nil {
|
||||
_, _ = s.ctx.EntClient.Station.Create().
|
||||
SetStationNo(i).SetName("装配工位" + strconv.Itoa(i)).SetStatus("ENABLED").
|
||||
SetIsBuiltin(true).SetHasDock(i <= 10).Save(ctx)
|
||||
SetIsBuiltin(true).Save(ctx)
|
||||
}
|
||||
}
|
||||
// 0 号(上线位) / 13 号(下线位) 虚拟工位:OFFLINE 类型,用 PAD 操作,不连 PLC、
|
||||
@@ -261,35 +258,11 @@ func seedStations(ctx context.Context, s *Service) {
|
||||
if _, err := s.ctx.EntClient.Station.Query().Where(station.StationNo(v.no)).First(ctx); err != nil {
|
||||
_, _ = s.ctx.EntClient.Station.Create().
|
||||
SetStationNo(v.no).SetName(v.name).SetStationType("OFFLINE").
|
||||
SetIsBuiltin(true).SetHasDock(false).SetStatus("ENABLED").Save(ctx)
|
||||
SetIsBuiltin(true).SetStatus("ENABLED").Save(ctx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// bindStationDocks 接驳台↔工位默认绑定:按产线布局(2026-10-06),工位1~10 各配 R1/R2 两个接驳台,
|
||||
// 一个工位可对应多个接驳台,对应关系以 dock 表内置数据(用户内置/种子数据)为准,页面展示也按 dock 表聚合。
|
||||
// station.dock_code 仅作为「默认接驳台」兜底字段:仅在该工位尚未绑定时按 dock.station_no 回填一次,
|
||||
// 不覆盖既有值(避免一工位多接驳台时来回翻转);库房/虚拟接驳台(station_no=0)及无接驳台工位不参与。
|
||||
func bindStationDocks(ctx context.Context, s *Service) {
|
||||
docks, err := s.ctx.EntClient.Dock.Query().
|
||||
Where(dock.StationNoGT(0), dock.DockTypeEQ("line")).
|
||||
All(ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, d := range docks {
|
||||
st, err := s.ctx.EntClient.Station.Query().
|
||||
Where(station.StationNo(d.StationNo)).First(ctx)
|
||||
if err != nil || st == nil {
|
||||
continue
|
||||
}
|
||||
if st.DockCode != "" || !st.HasDock || !st.IsBuiltin {
|
||||
continue
|
||||
}
|
||||
_, _ = s.ctx.EntClient.Station.UpdateOneID(st.ID).SetDockCode(d.DockCode).Save(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
// mergeCodes 合并两份权限码列表(去重、保序)
|
||||
func mergeCodes(a, b []string) []string {
|
||||
seen := map[string]bool{}
|
||||
|
||||
Reference in New Issue
Block a user