25 lines
637 B
Go
25 lines
637 B
Go
package mom
|
||
|
||
import (
|
||
"context"
|
||
"fmt"
|
||
|
||
"bj_power_mes/ent"
|
||
"bj_power_mes/ent/producttype"
|
||
)
|
||
|
||
// MatchProductType 通过 product_type.name 匹配 MOM 的 ProdModel(V_WO_PROD.PROD_MODEL)。
|
||
// 返回 nil 表示未找到匹配的产品类型。
|
||
func MatchProductType(ctx context.Context, client *ent.Client, prodModel string) (*ent.ProductType, error) {
|
||
pt, err := client.ProductType.Query().
|
||
Where(producttype.NameEQ(prodModel), producttype.IsActive(true)).
|
||
First(ctx)
|
||
if err != nil {
|
||
if ent.IsNotFound(err) {
|
||
return nil, nil
|
||
}
|
||
return nil, fmt.Errorf("match product type %s: %w", prodModel, err)
|
||
}
|
||
return pt, nil
|
||
}
|