feat: 核心业务实体扩充(混产模板/产品BOM/试制记录)、WMS 库存检验增强与前端通用能力

- MES 新增实体:混产模板、产品BOM、产品工艺物料、试制记录(schema + ent 生成码 + logic/handler/前端页)
- WMS 实体增强:检验记录、库存、半成品重构;新增序列号库存与短缺代报
- AGV 与产能:AGV 手动点位与链路、物料守卫、短缺预测、原因字典
- 前端通用能力:新增下一步引导组件 NextStepBar,统一帮助文档/布局/请求拦截与操作列
- 工位终端:界面与各 handler 调整(api/store/绑定/PLC/拧紧/上报等)
- 配置与文档:更新 mes-api.yaml、WMS README 及案例/产线API/问题记录/项目说明/流程说明
This commit is contained in:
SunYF
2026-11-15 12:17:39 +08:00
parent 7e8066ab66
commit 1e92b2a596
221 changed files with 26421 additions and 2230 deletions
+73 -24
View File
@@ -195,19 +195,27 @@ type StationTemplateSkipRow struct {
}
// TemplatePrecheckRow 单个工位的套用预检结果(只读,不写库)
// 2026-11-13 拍板:必须带真实产品维度与工序维度——「当前工位绑定的工序」+
// 「该模板支持的成品」,不允许前端只显示横杠。
type TemplatePrecheckRow struct {
StationNo int `json:"stationNo"`
FlowId int `json:"flowId"`
Blocked bool `json:"blocked"`
Reasons []string `json:"reasons"`
StationNo int `json:"stationNo"`
FlowId int `json:"flowId"`
FlowName string `json:"flowName"` // 模板要给该工位绑定的基础工序名
CurrentFlowId int `json:"currentFlowId"` // 该工位当前绑定的基础工序 ID
CurrentFlowName string `json:"currentFlowName"` // 该工位当前绑定的基础工序名
Products []string `json:"products"` // 当前混产模板支持的成品
Blocked bool `json:"blocked"`
Reasons []string `json:"reasons"`
}
// TemplatePrecheckResult 套用前的冲突清单:前端先展示、用户确认后再提交真正的套用。
type TemplatePrecheckResult struct {
Name string `json:"name"`
ProductCode string `json:"productCode"`
Matched []string `json:"matched"`
Rows []TemplatePrecheckRow `json:"rows"`
Name string `json:"name"`
ProductCode string `json:"productCode"`
TemplateName string `json:"templateName"` // 当前产线在用的混产模板
Products []string `json:"products"` // 该模板支持的成品
Matched []string `json:"matched"`
Rows []TemplatePrecheckRow `json:"rows"`
}
// findStationTemplate 按名称取模板,供套用与预检共用。
@@ -249,21 +257,57 @@ func (s *Service) PrecheckStationTemplate(ctx context.Context, name, targetProdu
if err := checkTemplateProduct(tpl, targetProductCode); err != nil {
return nil, err
}
// 产品维度:当前在用混产模板圈定的成品(用户要求预检里能看到「该模板支持的成品」)
activeName, products, aErr := s.ActiveMixProducts(ctx)
if aErr != nil {
return nil, aErr
}
res := &TemplatePrecheckResult{
Name: tpl.Name,
ProductCode: tpl.ProductCode,
Matched: append([]string{}, tpl.ProcessNames...),
Rows: []TemplatePrecheckRow{},
Name: tpl.Name,
ProductCode: tpl.ProductCode,
TemplateName: activeName,
Products: products,
Matched: append([]string{}, tpl.ProcessNames...),
Rows: []TemplatePrecheckRow{},
}
if res.Matched == nil {
res.Matched = []string{}
}
if res.Products == nil {
res.Products = []string{}
}
for _, item := range tpl.Stations {
row := TemplatePrecheckRow{StationNo: item.StationNo, FlowId: item.FlowId, Reasons: []string{}}
row := TemplatePrecheckRow{
StationNo: item.StationNo, FlowId: item.FlowId, Reasons: []string{},
Products: products,
}
// 模板要绑定的基础工序名
if item.FlowId > 0 {
flow, fErr := s.ctx.EntClient.ProcessFlow.Get(ctx, item.FlowId)
if fErr != nil {
row.Reasons = append(row.Reasons, "所选工艺流程不存在")
} else {
row.FlowName = flow.Name
if flow.Status != "ACTIVE" {
row.Reasons = append(row.Reasons, "所选工艺流程已停用")
}
}
}
st, e := s.ctx.EntClient.Station.Query().Where(station.StationNo(item.StationNo)).First(ctx)
if e != nil {
row.Reasons = append(row.Reasons, "工位不存在,不会套用")
} else {
// 当前工位绑定的基础工序(能力声明:工位×工序,不是工位×成品)
row.CurrentFlowId = st.FlowId
if st.FlowId > 0 {
if cur, cErr := s.ctx.EntClient.ProcessFlow.Get(ctx, st.FlowId); cErr == nil {
row.CurrentFlowName = cur.Name
} else {
row.CurrentFlowName = "已绑定工序不存在"
}
} else {
row.CurrentFlowName = "未绑定"
}
if item.FlowId != st.FlowId {
if busy, bErr := s.stationHasActiveWorkOrder(ctx, item.StationNo); bErr == nil && busy {
row.Reasons = append(row.Reasons, "有正在进行的工单引用此工位,禁止改绑定")
@@ -279,14 +323,6 @@ func (s *Service) PrecheckStationTemplate(ctx context.Context, name, targetProdu
}
}
}
if item.FlowId > 0 {
flow, fErr := s.ctx.EntClient.ProcessFlow.Get(ctx, item.FlowId)
if fErr != nil {
row.Reasons = append(row.Reasons, "所选工艺流程不存在")
} else if flow.Status != "ACTIVE" {
row.Reasons = append(row.Reasons, "所选工艺流程已停用")
}
}
row.Blocked = len(row.Reasons) > 0
res.Rows = append(res.Rows, row)
}
@@ -307,6 +343,12 @@ type ApplyStationTemplateResult struct {
// 2026-11-10:加产品范围校验——模板带 productCode 时,必须与目标产品工艺一致才允许套用,
// 避免「给 A 产品配的产线」被误套到 B 产品上。老模板(无 productCode)与不传目标产品时兼容放行。
func (s *Service) ApplyStationTemplate(ctx context.Context, name, targetProductCode, operator string) (*ApplyStationTemplateResult, error) {
return s.ApplyStationTemplateWithConfirm(ctx, name, targetProductCode, operator, nil)
}
// ApplyStationTemplateWithConfirm 带「清线确认单」逐项确认的应用入口。
// confirmed 为用户逐项打勾/人工确认放行的 key(见 CheckLineClearance),放行结果写 event_log 留痕。
func (s *Service) ApplyStationTemplateWithConfirm(ctx context.Context, name, targetProductCode, operator string, confirmed []string) (*ApplyStationTemplateResult, error) {
tpl, err := s.findStationTemplate(ctx, name)
if err != nil {
return nil, err
@@ -314,6 +356,11 @@ func (s *Service) ApplyStationTemplate(ctx context.Context, name, targetProductC
if err := checkTemplateProduct(tpl, targetProductCode); err != nil {
return nil, err
}
// 2026-11-13 拍板:同模板内多成品混产切换靠扫码防错,不强制停机清线;
// 引入模板外的新产品必须先过清线门禁(在制品 / 余料 / 托盘 / PLC 未完成任务 / AGV 在途 五项)。
if err := s.GuardLineClearanceWithConfirm(ctx, targetProductCode, confirmed, operator); err != nil {
return nil, err
}
res := &ApplyStationTemplateResult{
Applied: []int{},
Skipped: []StationTemplateSkipRow{},
@@ -333,10 +380,12 @@ func (s *Service) ApplyStationTemplate(ctx context.Context, name, targetProductC
continue
}
flowId := item.FlowId
// 清线门禁已在 ApplyStationTemplate 入口统一执行,逐工位保存时跳过,避免重复检查
if e := s.SaveStation(ctx, StationReq{
StationNo: item.StationNo,
Name: st.Name,
FlowId: &flowId,
StationNo: item.StationNo,
Name: st.Name,
FlowId: &flowId,
SkipClearanceCheck: true,
}, operator); e != nil {
res.Skipped = append(res.Skipped, StationTemplateSkipRow{
StationNo: item.StationNo, Reason: e.Error(),