feat: 解耦管理类型与SN管理方式,新增sn_mode字段实现全链路SN管理标准化
本次重构将原manage_mode字段拆分为独立的分类维度(manage_mode)和SN管理维度(sn_mode),实现全链路(MES/WMS/工位终端)的SN管理行为统一依据: 1. 新增sn_mode字段,定义1=序列号件、2=批次件、0=未选择,替代原manage_mode的SN判断逻辑 2. 移除冗余的manage_mode字段在多个实体中的使用,统一使用sn_mode决定业务行为 3. 新增工位接驳台配置,服务端固定接驳台,前端不可修改,确保AGV送达准确性 4. 优化检验记录导出,新增装配物料绑定明细,满足客户追溯需求 5. 修正前端提示文本,统一使用序列号件/批次件表述,与后端逻辑对齐
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"math"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"bj_power_mes/ent"
|
||||
"bj_power_mes/ent/flowmaterial"
|
||||
@@ -68,7 +69,7 @@ func (s *Service) BindWorkpiece(ctx context.Context, sn, orderNo string, flowId
|
||||
// BindItemReq 单条装机绑定请求(报工时随 steps 一并提交)
|
||||
type BindItemReq struct {
|
||||
MaterialCode string `json:"materialCode"`
|
||||
BindValue string `json:"bindValue"` // 结构件=批次号;电气件=SN
|
||||
BindValue string `json:"bindValue"` // 批次件=批次号;序列号件=SN
|
||||
}
|
||||
|
||||
// bindTarget 某工艺要求装配的物料定义(源自工艺物料清单 flow_material)
|
||||
@@ -77,7 +78,7 @@ type bindTarget struct {
|
||||
MaterialName string
|
||||
Spec string
|
||||
Unit string
|
||||
ManageMode string // 1 批次(结构件) / 2 SN(电气件)
|
||||
SnMode int // 是否逐件SN管理:1 序列号件(录SN) / 2 批次件
|
||||
UnitQty float64
|
||||
}
|
||||
|
||||
@@ -108,7 +109,7 @@ func (s *Service) stationBindTargets(ctx context.Context, client *ent.Client, fl
|
||||
for _, it := range items {
|
||||
out = append(out, bindTarget{
|
||||
MaterialCode: it.MaterialCode, MaterialName: it.MaterialName, Spec: it.Spec,
|
||||
Unit: it.Unit, ManageMode: it.ManageMode, UnitQty: it.UnitQty,
|
||||
Unit: it.Unit, SnMode: it.SnMode, UnitQty: it.UnitQty,
|
||||
})
|
||||
}
|
||||
return out, nil
|
||||
@@ -140,7 +141,7 @@ func (s *Service) applyBinds(ctx context.Context, client *ent.Client, sn, orderN
|
||||
fmMap[targets[i].MaterialCode] = &ent.FlowMaterial{
|
||||
MaterialCode: targets[i].MaterialCode, MaterialName: targets[i].MaterialName,
|
||||
Spec: targets[i].Spec, Unit: targets[i].Unit,
|
||||
ManageMode: targets[i].ManageMode, UnitQty: targets[i].UnitQty,
|
||||
SnMode: targets[i].SnMode, UnitQty: targets[i].UnitQty,
|
||||
}
|
||||
}
|
||||
bound := 0
|
||||
@@ -154,9 +155,9 @@ func (s *Service) applyBinds(ctx context.Context, client *ent.Client, sn, orderN
|
||||
if !ok {
|
||||
return bound, fmt.Errorf("物料 %s 未配置在工艺「%s」的物料清单,不能绑定", mc, s.flowNameById(ctx, flowId))
|
||||
}
|
||||
manageMode := fm.ManageMode
|
||||
if manageMode == "" {
|
||||
manageMode = "1"
|
||||
snMode := fm.SnMode
|
||||
if snMode != 1 {
|
||||
snMode = 2
|
||||
}
|
||||
// 同工件同料同值幂等
|
||||
exists, _ := client.WorkpieceBind.Query().
|
||||
@@ -164,23 +165,23 @@ func (s *Service) applyBinds(ctx context.Context, client *ent.Client, sn, orderN
|
||||
if exists {
|
||||
continue
|
||||
}
|
||||
// 电气件 SN 全局防重
|
||||
if manageMode == "2" {
|
||||
// 序列号件 SN 全局防重
|
||||
if snMode == 1 {
|
||||
other, _ := client.WorkpieceBind.Query().
|
||||
Where(workpiecebind.BindValue(bv), workpiecebind.BindType("SN"), workpiecebind.SnNEQ(sn)).First(ctx)
|
||||
if other != nil {
|
||||
return bound, fmt.Errorf("电气件SN %s 已绑定到工件 %s(工艺「%s」),不能重复装机",
|
||||
return bound, fmt.Errorf("序列号件SN %s 已绑定到工件 %s(工艺「%s」),不能重复装机",
|
||||
bv, other.Sn, s.flowNameById(ctx, other.FlowId))
|
||||
}
|
||||
}
|
||||
bindType := "BATCH"
|
||||
if manageMode == "2" {
|
||||
if snMode == 1 {
|
||||
bindType = "SN"
|
||||
}
|
||||
if err := client.WorkpieceBind.Create().
|
||||
SetSn(sn).SetOrderNo(orderNo).SetFlowId(flowId).
|
||||
SetStationNo(stationNo).SetMaterialCode(mc).SetMaterialName(fm.MaterialName).
|
||||
SetSpec(fm.Spec).SetUnit(fm.Unit).SetManageMode(manageMode).
|
||||
SetSpec(fm.Spec).SetUnit(fm.Unit).SetSnMode(snMode).
|
||||
SetBindValue(bv).SetBindType(bindType).SetOperator(operator).
|
||||
Exec(ctx); err != nil {
|
||||
return bound, err
|
||||
@@ -222,11 +223,11 @@ func (s *Service) validateStationBinds(ctx context.Context, client *ent.Client,
|
||||
if need < 1 {
|
||||
need = 1
|
||||
}
|
||||
if t.ManageMode == "2" { // 电气件 SN:需绑满单台用量
|
||||
if t.SnMode == 1 { // 序列号件 SN:需绑满单台用量
|
||||
if boundCount < need {
|
||||
missing = append(missing, fmt.Sprintf("%s(%s):需绑定%d颗SN,已绑%d颗", t.MaterialCode, t.MaterialName, need, boundCount))
|
||||
}
|
||||
} else { // 结构件批次:至少绑定1个批次号
|
||||
} else { // 批次件:至少绑定1个批次号
|
||||
if boundCount < 1 {
|
||||
missing = append(missing, fmt.Sprintf("%s(%s):未绑定批次号", t.MaterialCode, t.MaterialName))
|
||||
}
|
||||
@@ -266,6 +267,53 @@ func (s *Service) validateAllFlows(ctx context.Context, client *ent.Client, sn s
|
||||
return strings.Join(missing, ";"), nil
|
||||
}
|
||||
|
||||
// InspectionBindItem 检验记录/检验单附带的装配物料绑定明细条目
|
||||
// (客户需求:每个工位对精密器件扫码录入,记录在检验单上)
|
||||
type InspectionBindItem struct {
|
||||
Sn string `json:"sn"`
|
||||
FlowName string `json:"flowName"` // 装配工艺名
|
||||
StationNo string `json:"stationNo"` // 绑定工位
|
||||
MaterialCode string `json:"materialCode"`
|
||||
MaterialName string `json:"materialName"`
|
||||
Spec string `json:"spec"`
|
||||
BindValue string `json:"bindValue"` // 序列号件=SN / 批次件=批次号
|
||||
BindMode string `json:"bindMode"` // 序列号件 / 批次件
|
||||
Operator string `json:"operator"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
}
|
||||
|
||||
// inspectionBindItems 按 SN 查跨工艺全部装配绑定明细(供检验记录详情/检验单附明细区;无绑定返回空不报错)
|
||||
func (s *Service) inspectionBindItems(ctx context.Context, sn string) []InspectionBindItem {
|
||||
if sn == "" {
|
||||
return nil
|
||||
}
|
||||
binds, err := s.ctx.EntClient.WorkpieceBind.Query().
|
||||
Where(workpiecebind.Sn(sn)).
|
||||
Order(ent.Asc(workpiecebind.FieldFlowId), ent.Asc(workpiecebind.FieldID)).
|
||||
All(ctx)
|
||||
if err != nil || len(binds) == 0 {
|
||||
return nil
|
||||
}
|
||||
out := make([]InspectionBindItem, 0, len(binds))
|
||||
for _, b := range binds {
|
||||
mode := "批次件"
|
||||
if b.SnMode == 1 {
|
||||
mode = "序列号件"
|
||||
}
|
||||
out = append(out, InspectionBindItem{
|
||||
Sn: b.Sn, FlowName: s.flowNameById(ctx, b.FlowId), StationNo: b.StationNo,
|
||||
MaterialCode: b.MaterialCode, MaterialName: b.MaterialName, Spec: b.Spec,
|
||||
BindValue: b.BindValue, BindMode: mode, Operator: b.Operator, CreatedAt: b.CreatedAt,
|
||||
})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// InspectionBinds 检验记录详情:按 SN 返回装配物料绑定明细(跨工艺,标注工艺/工位)
|
||||
func (s *Service) InspectionBinds(ctx context.Context, sn string) []InspectionBindItem {
|
||||
return s.inspectionBindItems(ctx, sn)
|
||||
}
|
||||
|
||||
// ListWorkpieceBinds 查询工件的装机绑定明细
|
||||
func (s *Service) ListWorkpieceBinds(ctx context.Context, sn string) ([]*ent.WorkpieceBind, error) {
|
||||
q := s.ctx.EntClient.WorkpieceBind.Query()
|
||||
@@ -289,9 +337,9 @@ type BindNode struct {
|
||||
MaterialName string `json:"materialName"`
|
||||
Spec string `json:"spec"`
|
||||
Unit string `json:"unit"`
|
||||
ManageMode string `json:"manageMode"` // 1 批次(结构件) / 2 SN(电气件)
|
||||
Qty float64 `json:"qty"` // 折算到单台成品的用量
|
||||
Level int `json:"level"` // 0=顶层装配物料,1+=下级
|
||||
SnMode int `json:"snMode"` // 1 序列号件 / 2 批次件
|
||||
Qty float64 `json:"qty"` // 折算到单台成品的用量
|
||||
Level int `json:"level"` // 0=顶层装配物料,1+=下级
|
||||
Children []BindNode `json:"children,omitempty"`
|
||||
}
|
||||
|
||||
@@ -314,7 +362,7 @@ func (s *Service) BuildBindTrace(ctx context.Context, sn string) (*BindTraceVO,
|
||||
for _, it := range s.WorkOrderUnitUsage(ctx, wo) {
|
||||
tree = append(tree, BindNode{
|
||||
MaterialCode: it.MaterialCode, MaterialName: it.MaterialName,
|
||||
Spec: it.Spec, Unit: it.Unit, ManageMode: it.ManageMode,
|
||||
Spec: it.Spec, Unit: it.Unit, SnMode: it.SnMode,
|
||||
Qty: it.UnitQty, Level: 0,
|
||||
})
|
||||
}
|
||||
@@ -327,7 +375,7 @@ type BindRequiredItem struct {
|
||||
MaterialName string `json:"materialName"`
|
||||
Spec string `json:"spec"`
|
||||
Unit string `json:"unit"`
|
||||
ManageMode string `json:"manageMode"`
|
||||
SnMode int `json:"snMode"` // 1 序列号件(录SN) / 2 批次件
|
||||
UnitQty float64 `json:"unitQty"`
|
||||
Need int `json:"need"` // 需绑数量
|
||||
Bound []string `json:"bound"` // 已绑定的批次号/SN 列表
|
||||
@@ -390,10 +438,10 @@ func (s *Service) StationBindPanelData(ctx context.Context, sn string, flowId in
|
||||
sort.Strings(bound)
|
||||
item := BindRequiredItem{
|
||||
MaterialCode: t.MaterialCode, MaterialName: t.MaterialName, Spec: t.Spec, Unit: t.Unit,
|
||||
ManageMode: t.ManageMode, UnitQty: t.UnitQty, Need: need, Bound: bound,
|
||||
SnMode: t.SnMode, UnitQty: t.UnitQty, Need: need, Bound: bound,
|
||||
BoundCount: len(bound),
|
||||
}
|
||||
if t.ManageMode == "2" {
|
||||
if t.SnMode == 1 {
|
||||
item.Complete = len(bound) >= need
|
||||
} else {
|
||||
item.Complete = len(bound) >= 1
|
||||
|
||||
Reference in New Issue
Block a user