feat&refactor: 2026-09-22 半成品业务模型重构与功能完善

- 重构半成品流转逻辑:进度权威源改为 workpiece.currentStationNo,新增 completedText 快照字段,废除 doneProcessCodes
- 清理物料品类中半成品类型,存量数据幂等清理,调整物料管理方式文案为批次/序列号
- 新增日排产状态专用更新接口,修复工单工艺校验逻辑
- 新增物料档案代理接口、深路径文件下载接口
- 优化前端界面文案与工位选择逻辑,补充追溯页半成品流转展示
- 调整WMS端物料品类校验与入库接口契约
- 新增/更新数据库表结构与实体类代码
This commit is contained in:
SunYF
2026-09-22 14:42:52 +08:00
parent 09cfc6ca1c
commit d3eda6b588
49 changed files with 1155 additions and 1122 deletions
+116 -116
View File
@@ -1,271 +1,271 @@
// Code generated by ent, DO NOT EDIT.
// Code generated by ent, DO NOT EDIT.
package hook
import (
"bj_power_wms"
"bj_power_wms/ent"
"context"
"fmt"
)
// The AgvTaskFunc type is an adapter to allow the use of ordinary
// function as AgvTask mutator.
type AgvTaskFunc func(context.Context, *bj_power_wms.AgvTaskMutation) (bj_power_wms.Value, error)
type AgvTaskFunc func(context.Context, *ent.AgvTaskMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f AgvTaskFunc) Mutate(ctx context.Context, m bj_power_wms.Mutation) (bj_power_wms.Value, error) {
if mv, ok := m.(*bj_power_wms.AgvTaskMutation); ok {
func (f AgvTaskFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.AgvTaskMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *bj_power_wms.AgvTaskMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AgvTaskMutation", m)
}
// The AttachmentFunc type is an adapter to allow the use of ordinary
// function as Attachment mutator.
type AttachmentFunc func(context.Context, *bj_power_wms.AttachmentMutation) (bj_power_wms.Value, error)
type AttachmentFunc func(context.Context, *ent.AttachmentMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f AttachmentFunc) Mutate(ctx context.Context, m bj_power_wms.Mutation) (bj_power_wms.Value, error) {
if mv, ok := m.(*bj_power_wms.AttachmentMutation); ok {
func (f AttachmentFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.AttachmentMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *bj_power_wms.AttachmentMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AttachmentMutation", m)
}
// The EventLogFunc type is an adapter to allow the use of ordinary
// function as EventLog mutator.
type EventLogFunc func(context.Context, *bj_power_wms.EventLogMutation) (bj_power_wms.Value, error)
type EventLogFunc func(context.Context, *ent.EventLogMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f EventLogFunc) Mutate(ctx context.Context, m bj_power_wms.Mutation) (bj_power_wms.Value, error) {
if mv, ok := m.(*bj_power_wms.EventLogMutation); ok {
func (f EventLogFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.EventLogMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *bj_power_wms.EventLogMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.EventLogMutation", m)
}
// The InboundDetailFunc type is an adapter to allow the use of ordinary
// function as InboundDetail mutator.
type InboundDetailFunc func(context.Context, *bj_power_wms.InboundDetailMutation) (bj_power_wms.Value, error)
type InboundDetailFunc func(context.Context, *ent.InboundDetailMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f InboundDetailFunc) Mutate(ctx context.Context, m bj_power_wms.Mutation) (bj_power_wms.Value, error) {
if mv, ok := m.(*bj_power_wms.InboundDetailMutation); ok {
func (f InboundDetailFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.InboundDetailMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *bj_power_wms.InboundDetailMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.InboundDetailMutation", m)
}
// The InboundOrderFunc type is an adapter to allow the use of ordinary
// function as InboundOrder mutator.
type InboundOrderFunc func(context.Context, *bj_power_wms.InboundOrderMutation) (bj_power_wms.Value, error)
type InboundOrderFunc func(context.Context, *ent.InboundOrderMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f InboundOrderFunc) Mutate(ctx context.Context, m bj_power_wms.Mutation) (bj_power_wms.Value, error) {
if mv, ok := m.(*bj_power_wms.InboundOrderMutation); ok {
func (f InboundOrderFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.InboundOrderMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *bj_power_wms.InboundOrderMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.InboundOrderMutation", m)
}
// The InspectionRecordFunc type is an adapter to allow the use of ordinary
// function as InspectionRecord mutator.
type InspectionRecordFunc func(context.Context, *bj_power_wms.InspectionRecordMutation) (bj_power_wms.Value, error)
type InspectionRecordFunc func(context.Context, *ent.InspectionRecordMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f InspectionRecordFunc) Mutate(ctx context.Context, m bj_power_wms.Mutation) (bj_power_wms.Value, error) {
if mv, ok := m.(*bj_power_wms.InspectionRecordMutation); ok {
func (f InspectionRecordFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.InspectionRecordMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *bj_power_wms.InspectionRecordMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.InspectionRecordMutation", m)
}
// The InventoryFunc type is an adapter to allow the use of ordinary
// function as Inventory mutator.
type InventoryFunc func(context.Context, *bj_power_wms.InventoryMutation) (bj_power_wms.Value, error)
type InventoryFunc func(context.Context, *ent.InventoryMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f InventoryFunc) Mutate(ctx context.Context, m bj_power_wms.Mutation) (bj_power_wms.Value, error) {
if mv, ok := m.(*bj_power_wms.InventoryMutation); ok {
func (f InventoryFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.InventoryMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *bj_power_wms.InventoryMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.InventoryMutation", m)
}
// The InventoryLockFunc type is an adapter to allow the use of ordinary
// function as InventoryLock mutator.
type InventoryLockFunc func(context.Context, *bj_power_wms.InventoryLockMutation) (bj_power_wms.Value, error)
type InventoryLockFunc func(context.Context, *ent.InventoryLockMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f InventoryLockFunc) Mutate(ctx context.Context, m bj_power_wms.Mutation) (bj_power_wms.Value, error) {
if mv, ok := m.(*bj_power_wms.InventoryLockMutation); ok {
func (f InventoryLockFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.InventoryLockMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *bj_power_wms.InventoryLockMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.InventoryLockMutation", m)
}
// The MaterialFunc type is an adapter to allow the use of ordinary
// function as Material mutator.
type MaterialFunc func(context.Context, *bj_power_wms.MaterialMutation) (bj_power_wms.Value, error)
type MaterialFunc func(context.Context, *ent.MaterialMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f MaterialFunc) Mutate(ctx context.Context, m bj_power_wms.Mutation) (bj_power_wms.Value, error) {
if mv, ok := m.(*bj_power_wms.MaterialMutation); ok {
func (f MaterialFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.MaterialMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *bj_power_wms.MaterialMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MaterialMutation", m)
}
// The MaterialDemandFunc type is an adapter to allow the use of ordinary
// function as MaterialDemand mutator.
type MaterialDemandFunc func(context.Context, *bj_power_wms.MaterialDemandMutation) (bj_power_wms.Value, error)
type MaterialDemandFunc func(context.Context, *ent.MaterialDemandMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f MaterialDemandFunc) Mutate(ctx context.Context, m bj_power_wms.Mutation) (bj_power_wms.Value, error) {
if mv, ok := m.(*bj_power_wms.MaterialDemandMutation); ok {
func (f MaterialDemandFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.MaterialDemandMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *bj_power_wms.MaterialDemandMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.MaterialDemandMutation", m)
}
// The OrderMaterialLedgerFunc type is an adapter to allow the use of ordinary
// function as OrderMaterialLedger mutator.
type OrderMaterialLedgerFunc func(context.Context, *bj_power_wms.OrderMaterialLedgerMutation) (bj_power_wms.Value, error)
type OrderMaterialLedgerFunc func(context.Context, *ent.OrderMaterialLedgerMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f OrderMaterialLedgerFunc) Mutate(ctx context.Context, m bj_power_wms.Mutation) (bj_power_wms.Value, error) {
if mv, ok := m.(*bj_power_wms.OrderMaterialLedgerMutation); ok {
func (f OrderMaterialLedgerFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.OrderMaterialLedgerMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *bj_power_wms.OrderMaterialLedgerMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.OrderMaterialLedgerMutation", m)
}
// The OutboundDetailFunc type is an adapter to allow the use of ordinary
// function as OutboundDetail mutator.
type OutboundDetailFunc func(context.Context, *bj_power_wms.OutboundDetailMutation) (bj_power_wms.Value, error)
type OutboundDetailFunc func(context.Context, *ent.OutboundDetailMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f OutboundDetailFunc) Mutate(ctx context.Context, m bj_power_wms.Mutation) (bj_power_wms.Value, error) {
if mv, ok := m.(*bj_power_wms.OutboundDetailMutation); ok {
func (f OutboundDetailFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.OutboundDetailMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *bj_power_wms.OutboundDetailMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.OutboundDetailMutation", m)
}
// The OutboundOrderFunc type is an adapter to allow the use of ordinary
// function as OutboundOrder mutator.
type OutboundOrderFunc func(context.Context, *bj_power_wms.OutboundOrderMutation) (bj_power_wms.Value, error)
type OutboundOrderFunc func(context.Context, *ent.OutboundOrderMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f OutboundOrderFunc) Mutate(ctx context.Context, m bj_power_wms.Mutation) (bj_power_wms.Value, error) {
if mv, ok := m.(*bj_power_wms.OutboundOrderMutation); ok {
func (f OutboundOrderFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.OutboundOrderMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *bj_power_wms.OutboundOrderMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.OutboundOrderMutation", m)
}
// The PermissionFunc type is an adapter to allow the use of ordinary
// function as Permission mutator.
type PermissionFunc func(context.Context, *bj_power_wms.PermissionMutation) (bj_power_wms.Value, error)
type PermissionFunc func(context.Context, *ent.PermissionMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f PermissionFunc) Mutate(ctx context.Context, m bj_power_wms.Mutation) (bj_power_wms.Value, error) {
if mv, ok := m.(*bj_power_wms.PermissionMutation); ok {
func (f PermissionFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.PermissionMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *bj_power_wms.PermissionMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.PermissionMutation", m)
}
// The ReturnOrderFunc type is an adapter to allow the use of ordinary
// function as ReturnOrder mutator.
type ReturnOrderFunc func(context.Context, *bj_power_wms.ReturnOrderMutation) (bj_power_wms.Value, error)
type ReturnOrderFunc func(context.Context, *ent.ReturnOrderMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f ReturnOrderFunc) Mutate(ctx context.Context, m bj_power_wms.Mutation) (bj_power_wms.Value, error) {
if mv, ok := m.(*bj_power_wms.ReturnOrderMutation); ok {
func (f ReturnOrderFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.ReturnOrderMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *bj_power_wms.ReturnOrderMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ReturnOrderMutation", m)
}
// The RoleFunc type is an adapter to allow the use of ordinary
// function as Role mutator.
type RoleFunc func(context.Context, *bj_power_wms.RoleMutation) (bj_power_wms.Value, error)
type RoleFunc func(context.Context, *ent.RoleMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f RoleFunc) Mutate(ctx context.Context, m bj_power_wms.Mutation) (bj_power_wms.Value, error) {
if mv, ok := m.(*bj_power_wms.RoleMutation); ok {
func (f RoleFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.RoleMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *bj_power_wms.RoleMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.RoleMutation", m)
}
// The SemiFinishedFunc type is an adapter to allow the use of ordinary
// function as SemiFinished mutator.
type SemiFinishedFunc func(context.Context, *bj_power_wms.SemiFinishedMutation) (bj_power_wms.Value, error)
type SemiFinishedFunc func(context.Context, *ent.SemiFinishedMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f SemiFinishedFunc) Mutate(ctx context.Context, m bj_power_wms.Mutation) (bj_power_wms.Value, error) {
if mv, ok := m.(*bj_power_wms.SemiFinishedMutation); ok {
func (f SemiFinishedFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.SemiFinishedMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *bj_power_wms.SemiFinishedMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.SemiFinishedMutation", m)
}
// The StocktakeItemFunc type is an adapter to allow the use of ordinary
// function as StocktakeItem mutator.
type StocktakeItemFunc func(context.Context, *bj_power_wms.StocktakeItemMutation) (bj_power_wms.Value, error)
type StocktakeItemFunc func(context.Context, *ent.StocktakeItemMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f StocktakeItemFunc) Mutate(ctx context.Context, m bj_power_wms.Mutation) (bj_power_wms.Value, error) {
if mv, ok := m.(*bj_power_wms.StocktakeItemMutation); ok {
func (f StocktakeItemFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.StocktakeItemMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *bj_power_wms.StocktakeItemMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.StocktakeItemMutation", m)
}
// The StocktakeOrderFunc type is an adapter to allow the use of ordinary
// function as StocktakeOrder mutator.
type StocktakeOrderFunc func(context.Context, *bj_power_wms.StocktakeOrderMutation) (bj_power_wms.Value, error)
type StocktakeOrderFunc func(context.Context, *ent.StocktakeOrderMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f StocktakeOrderFunc) Mutate(ctx context.Context, m bj_power_wms.Mutation) (bj_power_wms.Value, error) {
if mv, ok := m.(*bj_power_wms.StocktakeOrderMutation); ok {
func (f StocktakeOrderFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.StocktakeOrderMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *bj_power_wms.StocktakeOrderMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.StocktakeOrderMutation", m)
}
// The UserFunc type is an adapter to allow the use of ordinary
// function as User mutator.
type UserFunc func(context.Context, *bj_power_wms.UserMutation) (bj_power_wms.Value, error)
type UserFunc func(context.Context, *ent.UserMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f UserFunc) Mutate(ctx context.Context, m bj_power_wms.Mutation) (bj_power_wms.Value, error) {
if mv, ok := m.(*bj_power_wms.UserMutation); ok {
func (f UserFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.UserMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *bj_power_wms.UserMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.UserMutation", m)
}
// The ZoneFunc type is an adapter to allow the use of ordinary
// function as Zone mutator.
type ZoneFunc func(context.Context, *bj_power_wms.ZoneMutation) (bj_power_wms.Value, error)
type ZoneFunc func(context.Context, *ent.ZoneMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f ZoneFunc) Mutate(ctx context.Context, m bj_power_wms.Mutation) (bj_power_wms.Value, error) {
if mv, ok := m.(*bj_power_wms.ZoneMutation); ok {
func (f ZoneFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.ZoneMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *bj_power_wms.ZoneMutation", m)
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ZoneMutation", m)
}
// Condition is a hook condition function.
type Condition func(context.Context, bj_power_wms.Mutation) bool
type Condition func(context.Context, ent.Mutation) bool
// And groups conditions with the AND operator.
func And(first, second Condition, rest ...Condition) Condition {
return func(ctx context.Context, m bj_power_wms.Mutation) bool {
return func(ctx context.Context, m ent.Mutation) bool {
if !first(ctx, m) || !second(ctx, m) {
return false
}
@@ -280,7 +280,7 @@ func And(first, second Condition, rest ...Condition) Condition {
// Or groups conditions with the OR operator.
func Or(first, second Condition, rest ...Condition) Condition {
return func(ctx context.Context, m bj_power_wms.Mutation) bool {
return func(ctx context.Context, m ent.Mutation) bool {
if first(ctx, m) || second(ctx, m) {
return true
}
@@ -295,21 +295,21 @@ func Or(first, second Condition, rest ...Condition) Condition {
// Not negates a given condition.
func Not(cond Condition) Condition {
return func(ctx context.Context, m bj_power_wms.Mutation) bool {
return func(ctx context.Context, m ent.Mutation) bool {
return !cond(ctx, m)
}
}
// HasOp is a condition testing mutation operation.
func HasOp(op bj_power_wms.Op) Condition {
return func(_ context.Context, m bj_power_wms.Mutation) bool {
func HasOp(op ent.Op) Condition {
return func(_ context.Context, m ent.Mutation) bool {
return m.Op().Is(op)
}
}
// HasAddedFields is a condition validating `.AddedField` on fields.
func HasAddedFields(field string, fields ...string) Condition {
return func(_ context.Context, m bj_power_wms.Mutation) bool {
return func(_ context.Context, m ent.Mutation) bool {
if _, exists := m.AddedField(field); !exists {
return false
}
@@ -324,7 +324,7 @@ func HasAddedFields(field string, fields ...string) Condition {
// HasClearedFields is a condition validating `.FieldCleared` on fields.
func HasClearedFields(field string, fields ...string) Condition {
return func(_ context.Context, m bj_power_wms.Mutation) bool {
return func(_ context.Context, m ent.Mutation) bool {
if exists := m.FieldCleared(field); !exists {
return false
}
@@ -339,7 +339,7 @@ func HasClearedFields(field string, fields ...string) Condition {
// HasFields is a condition validating `.Field` on fields.
func HasFields(field string, fields ...string) Condition {
return func(_ context.Context, m bj_power_wms.Mutation) bool {
return func(_ context.Context, m ent.Mutation) bool {
if _, exists := m.Field(field); !exists {
return false
}
@@ -355,9 +355,9 @@ func HasFields(field string, fields ...string) Condition {
// If executes the given hook under condition.
//
// hook.If(ComputeAverage, And(HasFields(...), HasAddedFields(...)))
func If(hk bj_power_wms.Hook, cond Condition) bj_power_wms.Hook {
return func(next bj_power_wms.Mutator) bj_power_wms.Mutator {
return bj_power_wms.MutateFunc(func(ctx context.Context, m bj_power_wms.Mutation) (bj_power_wms.Value, error) {
func If(hk ent.Hook, cond Condition) ent.Hook {
return func(next ent.Mutator) ent.Mutator {
return ent.MutateFunc(func(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if cond(ctx, m) {
return hk(next).Mutate(ctx, m)
}
@@ -368,22 +368,22 @@ func If(hk bj_power_wms.Hook, cond Condition) bj_power_wms.Hook {
// On executes the given hook only for the given operation.
//
// hook.On(Log, bj_power_wms.Delete|bj_power_wms.Create)
func On(hk bj_power_wms.Hook, op bj_power_wms.Op) bj_power_wms.Hook {
// hook.On(Log, ent.Delete|ent.Create)
func On(hk ent.Hook, op ent.Op) ent.Hook {
return If(hk, HasOp(op))
}
// Unless skips the given hook only for the given operation.
//
// hook.Unless(Log, bj_power_wms.Update|bj_power_wms.UpdateOne)
func Unless(hk bj_power_wms.Hook, op bj_power_wms.Op) bj_power_wms.Hook {
// hook.Unless(Log, ent.Update|ent.UpdateOne)
func Unless(hk ent.Hook, op ent.Op) ent.Hook {
return If(hk, Not(HasOp(op)))
}
// FixedError is a hook returning a fixed error.
func FixedError(err error) bj_power_wms.Hook {
return func(bj_power_wms.Mutator) bj_power_wms.Mutator {
return bj_power_wms.MutateFunc(func(context.Context, bj_power_wms.Mutation) (bj_power_wms.Value, error) {
func FixedError(err error) ent.Hook {
return func(ent.Mutator) ent.Mutator {
return ent.MutateFunc(func(context.Context, ent.Mutation) (ent.Value, error) {
return nil, err
})
}
@@ -391,12 +391,12 @@ func FixedError(err error) bj_power_wms.Hook {
// Reject returns a hook that rejects all operations that match op.
//
// func (T) Hooks() []bj_power_wms.Hook {
// return []bj_power_wms.Hook{
// Reject(bj_power_wms.Delete|bj_power_wms.Update),
// func (T) Hooks() []ent.Hook {
// return []ent.Hook{
// Reject(ent.Delete|ent.Update),
// }
// }
func Reject(op bj_power_wms.Op) bj_power_wms.Hook {
func Reject(op ent.Op) ent.Hook {
hk := FixedError(fmt.Errorf("%s operation is not allowed", op))
return On(hk, op)
}
@@ -404,17 +404,17 @@ func Reject(op bj_power_wms.Op) bj_power_wms.Hook {
// Chain acts as a list of hooks and is effectively immutable.
// Once created, it will always hold the same set of hooks in the same order.
type Chain struct {
hooks []bj_power_wms.Hook
hooks []ent.Hook
}
// NewChain creates a new chain of hooks.
func NewChain(hooks ...bj_power_wms.Hook) Chain {
return Chain{append([]bj_power_wms.Hook(nil), hooks...)}
func NewChain(hooks ...ent.Hook) Chain {
return Chain{append([]ent.Hook(nil), hooks...)}
}
// Hook chains the list of hooks and returns the final hook.
func (c Chain) Hook() bj_power_wms.Hook {
return func(mutator bj_power_wms.Mutator) bj_power_wms.Mutator {
func (c Chain) Hook() ent.Hook {
return func(mutator ent.Mutator) ent.Mutator {
for i := len(c.hooks) - 1; i >= 0; i-- {
mutator = c.hooks[i](mutator)
}
@@ -424,8 +424,8 @@ func (c Chain) Hook() bj_power_wms.Hook {
// Append extends a chain, adding the specified hook
// as the last ones in the mutation flow.
func (c Chain) Append(hooks ...bj_power_wms.Hook) Chain {
newHooks := make([]bj_power_wms.Hook, 0, len(c.hooks)+len(hooks))
func (c Chain) Append(hooks ...ent.Hook) Chain {
newHooks := make([]ent.Hook, 0, len(c.hooks)+len(hooks))
newHooks = append(newHooks, c.hooks...)
newHooks = append(newHooks, hooks...)
return Chain{newHooks}