Files
bj_power/bj_power_mes/internal/mom/adapter.go
T

25 lines
637 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package mom
import (
"context"
"fmt"
"bj_power_mes/ent"
"bj_power_mes/ent/producttype"
)
// MatchProductType 通过 product_type.name 匹配 MOM 的 ProdModelV_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
}