feat: 大屏多订单改为同屏并列展示,物料申请新增跨工位借料来源并移除工单完成日期
This commit is contained in:
@@ -155,6 +155,10 @@ func (s *Service) SaveFlow(ctx context.Context, req FlowReq, operator string) er
|
||||
// 保存时所选工位一律改绑到本流程(覆盖旧绑定),不再报"已被启用流程绑定"冲突。
|
||||
var flowID int
|
||||
if req.Id > 0 {
|
||||
// 条目12 守卫(2026-11-02):被执行中/已暂停工单引用的工艺禁止改内容(含启停)
|
||||
if err := s.guardFlowEditable(ctx, req.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
upd := s.ctx.EntClient.ProcessFlow.UpdateOneID(req.Id).
|
||||
SetName(req.Name).SetStatus(status).SetRemark(req.Remark)
|
||||
if req.PdfFile != "" {
|
||||
@@ -233,6 +237,10 @@ func (s *Service) syncStationFlow(ctx context.Context, stationNo, flowID int) er
|
||||
}
|
||||
|
||||
func (s *Service) DeleteFlow(ctx context.Context, id int, operator string) error {
|
||||
// 条目12 守卫(2026-11-02):被执行中/已暂停工单引用的工艺禁止删除
|
||||
if err := s.guardFlowEditable(ctx, id); err != nil {
|
||||
return err
|
||||
}
|
||||
// 删除前先解除所有工位绑定,再清步骤与流程本身
|
||||
_, _ = s.ctx.EntClient.Station.Update().
|
||||
Where(station.FlowId(id)).
|
||||
@@ -327,11 +335,30 @@ func (s *Service) ListStations(ctx context.Context) ([]*StationVO, error) {
|
||||
// 内置工位(种子/初始化数据,is_builtin=true)需连 PLC 并必须按工位号顺序流转,
|
||||
// 不允许手动更改工位类型;页面新增的工位一律为非内置,可改类型、可删除。
|
||||
// 接驳台为独立主数据(MES dock 表),一个工位可绑定多个接驳台,关系以 dock.station_no 为准,页面不维护。
|
||||
// stationHasActiveWorkOrder 工位是否正被"进行中"工单的生产路线引用(flow_combination 含该 stationNo)。
|
||||
// 进行中 = IN_PROGRESS(执行中) / PAUSED(已暂停) / RELEASED(残量已下发待开工):这些状态下路线已固定,禁止改绑定。
|
||||
func (s *Service) stationHasActiveWorkOrder(ctx context.Context, stationNo int) (bool, error) {
|
||||
active := []string{"IN_PROGRESS", "PAUSED", "RELEASED"}
|
||||
orders, err := s.ctx.EntClient.WorkOrder.Query().Where(workorder.StatusIn(active...)).All(ctx)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
for _, o := range orders {
|
||||
for _, item := range o.FlowCombination {
|
||||
if item["stationNo"] == stationNo {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// 校验为收集式(报错一次收全 + 每条带怎么办,2026-10-20):类型/流程/托盘/在途指令全部列出、一次性返回。
|
||||
func (s *Service) SaveStation(ctx context.Context, req StationReq, operator string) error {
|
||||
if req.StationNo < 0 {
|
||||
return errors.New("工位号非法(需 ≥ 0)")
|
||||
}
|
||||
// 工位号规则(2026-11-02 产线布局业务调整):
|
||||
// 1~12 内置物理工位(硬件锁定,不可新增/占用);负数(-1、-2…)= 产线前段虚拟工位(排在工位1之前);
|
||||
// ≥13 扩展工位;0 保留(历史虚拟位已废弃,不再用于新建)。
|
||||
// 工位号 ≤ 0 仅允许线下位(虚拟工位,不连 PLC、仅记录)。
|
||||
if req.StationNo == 0 && req.Name == "" {
|
||||
return errors.New("工位号非法")
|
||||
}
|
||||
@@ -342,13 +369,21 @@ func (s *Service) SaveStation(ctx context.Context, req StationReq, operator stri
|
||||
// 禁止通过本接口新增或占用,避免与内置物理工位冲突、或绕过前端改物理工位号。
|
||||
// 物理工位号只能由种子/初始化数据产生;页面新增请使用虚拟工位(0)或扩展工位号(≥13)。
|
||||
if req.StationNo >= 1 && req.StationNo <= 12 {
|
||||
return errors.New("工位号 1~12 为内置物理产线工位(硬件锁定),不可通过本接口新增或占用;新增工位请使用虚拟工位(0)或扩展工位号(≥13)")
|
||||
return errors.New("工位号 1~12 为内置物理产线工位(硬件锁定),不可通过本接口新增或占用;产线前段虚拟工位请用负数号(-1、-2…),12 之后扩展用 ≥13")
|
||||
}
|
||||
ve := verr.New()
|
||||
if req.Name == "" {
|
||||
ve.Add("name", "请填写工位名称", "在「工位名称」输入框填写名称后保存")
|
||||
}
|
||||
// 工位类型:尊重请求(修复:此前新增一律落 LINE,前端建"线下位"实际存成线上位,
|
||||
// 导致看板虚拟工位列表为空——2026-11-02 条目14根因)
|
||||
stype := "LINE"
|
||||
if req.StationType != nil && *req.StationType == "OFFLINE" {
|
||||
stype = "OFFLINE"
|
||||
}
|
||||
if req.StationNo <= 0 && stype != "OFFLINE" {
|
||||
ve.Add("stationNo", "工位号 ≤ 0 仅允许线下位(虚拟工位)", "类型选「线下位」后再保存")
|
||||
}
|
||||
if req.FlowId != nil && *req.FlowId > 0 {
|
||||
flow, fErr := s.ctx.EntClient.ProcessFlow.Get(ctx, *req.FlowId)
|
||||
if fErr != nil {
|
||||
@@ -391,6 +426,14 @@ plcOffline := false
|
||||
bindFlow := 0
|
||||
if req.FlowId != nil {
|
||||
bindFlow = *req.FlowId
|
||||
// 进行中工单守卫(2026-11-02 工位管理需求):工位正被进行中工单的生产路线引用时,禁止修改/解除绑定工艺。
|
||||
// 仅当绑定关系真的发生变化(含解绑/换绑)时才拦截;重复保存原绑定不误伤。
|
||||
if *req.FlowId != st.FlowId {
|
||||
if busy, bErr := s.stationHasActiveWorkOrder(ctx, st.StationNo); bErr == nil && busy {
|
||||
ve.Add("flowId", fmt.Sprintf("工位%d 存在正在进行的工单(生产路线包含此工位),禁止修改绑定工艺", st.StationNo),
|
||||
"请先将该工位的进行中工单完工或取消,再修改绑定工艺")
|
||||
}
|
||||
}
|
||||
if n, _ := s.ctx.EntClient.PlcSendLog.Query().
|
||||
Where(plcsendlog.Status("SENT"), plcsendlog.StationNo(st.StationNo)).Count(ctx); n > 0 {
|
||||
ve.AddAction("flowId", fmt.Sprintf("工位%d 有正在执行的指令,不能修改配置", st.StationNo),
|
||||
@@ -425,6 +468,16 @@ if err := ve.OrNil(); err != nil {
|
||||
return err
|
||||
}
|
||||
upd := s.ctx.EntClient.Station.UpdateOneID(st.ID).SetName(req.Name)
|
||||
// 类型调整:仅非内置工位允许 LINE↔OFFLINE(2026-11-02:修复存量虚拟工位被存成 LINE 后
|
||||
// 看板"暂无虚拟工位"无法自愈的问题);内置工位类型锁定不变。
|
||||
if req.StationType != nil && !st.IsBuiltin {
|
||||
if nt := *req.StationType; (nt == "LINE" || nt == "OFFLINE") && nt != st.StationType {
|
||||
upd.SetStationType(nt)
|
||||
s.ctx.EventLog.Write(ctx, "station.type_change", "", operator, "station", "",
|
||||
fmt.Sprintf("工位%d 类型变更:%s → %s", st.StationNo, st.StationType, nt),
|
||||
map[string]any{"stationNo": st.StationNo, "before": st.StationType, "after": nt})
|
||||
}
|
||||
}
|
||||
if req.FlowId != nil {
|
||||
upd.SetFlowId(bindFlow) // 0=解绑
|
||||
}
|
||||
@@ -916,6 +969,11 @@ func (s *Service) SaveFlowMaterials(ctx context.Context, flowId int, items []Flo
|
||||
if _, err := s.ctx.EntClient.ProcessFlow.Get(ctx, flowId); err != nil {
|
||||
return errors.New("工艺不存在")
|
||||
}
|
||||
// 条目12 守卫(2026-11-02):被执行中/已暂停工单引用的工艺,物料清单禁止整表覆盖
|
||||
//(叫料池/单台用料均实时读本清单,改了会改变在产工单的备料口径)
|
||||
if err := s.guardFlowEditable(ctx, flowId); err != nil {
|
||||
return err
|
||||
}
|
||||
// WMS 物料存在性校验(缺失拒绝;不可达降级放行)
|
||||
codes := make([]string, 0, len(items))
|
||||
seen := map[string]bool{}
|
||||
|
||||
Reference in New Issue
Block a user