2026-08-28 15:06:01 +08:00
|
|
|
package schema
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"entgo.io/ent"
|
2026-10-08 13:09:53 +08:00
|
|
|
"entgo.io/ent/dialect/entsql"
|
|
|
|
|
"entgo.io/ent/schema"
|
2026-08-28 15:06:01 +08:00
|
|
|
"entgo.io/ent/schema/field"
|
|
|
|
|
"entgo.io/ent/schema/index"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// InventoryLock 库存锁定(工单锁库存,防超卖)
|
|
|
|
|
type InventoryLock struct {
|
|
|
|
|
ent.Schema
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-08 13:09:53 +08:00
|
|
|
func (InventoryLock) Annotations() []schema.Annotation {
|
|
|
|
|
return []schema.Annotation{entsql.Table("inventory_locks"), entsql.WithComments(true), schema.Comment("InventoryLock 库存锁定(工单锁库存,防超卖)")}
|
|
|
|
|
}
|
2026-08-28 15:06:01 +08:00
|
|
|
func (InventoryLock) Fields() []ent.Field {
|
|
|
|
|
return []ent.Field{
|
|
|
|
|
// 锁定对象:批次或 SN
|
|
|
|
|
field.String("target_type").Comment("BATCH/SN"),
|
|
|
|
|
field.String("target_id").Comment("批次号或 SN"),
|
|
|
|
|
field.String("material_code").Comment("物料编码"),
|
|
|
|
|
field.Int("locked_qty").Default(1).Comment("锁定数量"),
|
|
|
|
|
field.String("order_no").Comment("关联工单号"),
|
|
|
|
|
field.String("status").Default("ACTIVE").Comment("ACTIVE/RELEASED/CONSUMED"),
|
|
|
|
|
field.Int64("expired_at").Optional().Comment("过期时间戳"),
|
|
|
|
|
field.String("remark").Optional().Comment("备注"),
|
|
|
|
|
field.Int64("created_at").DefaultFunc(nowUnix),
|
|
|
|
|
field.Int64("updated_at").DefaultFunc(nowUnix),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (InventoryLock) Indexes() []ent.Index {
|
|
|
|
|
return []ent.Index{
|
|
|
|
|
index.Fields("order_no"),
|
|
|
|
|
index.Fields("status"),
|
|
|
|
|
index.Fields("target_id"),
|
|
|
|
|
}
|
|
|
|
|
}
|