33 lines
1.1 KiB
Go
33 lines
1.1 KiB
Go
package logic
|
|||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"fmt"
|
||
|
|
"strings"
|
||
|
|
|
||
|
|
"bj_power_mes/ent/material"
|
||
|
|
)
|
||
|
|
|
||
|
|
// AssertMaterialOnly 物料单据硬守卫(2026-11-13 拍板:成品与物料业务彻底隔离)。
|
||
|
|
// 叫料 / 补料 / 退料 / 转产退料等单据只服务物料(item_type=1);成品(3)不参与,
|
||
|
|
// 在制品也不是独立物种(它是成品的状态属性),同样不得进入物料单据。
|
||
|
|
// 档案不存在时交由各接口原有的「物料编码不存在」校验处理,不在这里重复报错。
|
||
|
|
func (s *Service) AssertMaterialOnly(ctx context.Context, codes []string) error {
|
||
|
|
seen := map[string]bool{}
|
||
|
|
for _, raw := range codes {
|
||
|
|
code := strings.TrimSpace(raw)
|
||
|
|
if code == "" || seen[code] {
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
seen[code] = true
|
||
|
|
m, err := s.ctx.EntClient.Material.Query().Where(material.CodeEQ(code)).Only(ctx)
|
||
|
|
if err != nil || m == nil {
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
if m.ItemType != 1 {
|
||
|
|
return fmt.Errorf("仅物料可发起叫料/补料/退料;%s 属于成品,成品与物料业务隔离,不参与物料单据", code)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|