feat: 新增产品工艺管理与工序审核功能
- 新增产品工艺(product_process)及明细(product_process_item)数据模型 - 新增工序审核开关(need_audit)与审核角色(audit_role)字段 - 新增待审核签字页面与路由 - 优化 WMS/MES 接口交互,增加业务错误处理与友好提示 - 补充库存过滤逻辑,避免返回已出库 SN 数据 - 调整默认查询时间范围为近一个月,优化用户体验
This commit is contained in:
@@ -0,0 +1,370 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"bj_power_mes/ent/productprocess"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ProductProcessCreate is the builder for creating a ProductProcess entity.
|
||||
type ProductProcessCreate struct {
|
||||
config
|
||||
mutation *ProductProcessMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetProductCode sets the "productCode" field.
|
||||
func (_c *ProductProcessCreate) SetProductCode(v string) *ProductProcessCreate {
|
||||
_c.mutation.SetProductCode(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetProductName sets the "productName" field.
|
||||
func (_c *ProductProcessCreate) SetProductName(v string) *ProductProcessCreate {
|
||||
_c.mutation.SetProductName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableProductName sets the "productName" field if the given value is not nil.
|
||||
func (_c *ProductProcessCreate) SetNillableProductName(v *string) *ProductProcessCreate {
|
||||
if v != nil {
|
||||
_c.SetProductName(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_c *ProductProcessCreate) SetName(v string) *ProductProcessCreate {
|
||||
_c.mutation.SetName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetIsDefault sets the "isDefault" field.
|
||||
func (_c *ProductProcessCreate) SetIsDefault(v bool) *ProductProcessCreate {
|
||||
_c.mutation.SetIsDefault(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableIsDefault sets the "isDefault" field if the given value is not nil.
|
||||
func (_c *ProductProcessCreate) SetNillableIsDefault(v *bool) *ProductProcessCreate {
|
||||
if v != nil {
|
||||
_c.SetIsDefault(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (_c *ProductProcessCreate) SetStatus(v string) *ProductProcessCreate {
|
||||
_c.mutation.SetStatus(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (_c *ProductProcessCreate) SetNillableStatus(v *string) *ProductProcessCreate {
|
||||
if v != nil {
|
||||
_c.SetStatus(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetRemark sets the "remark" field.
|
||||
func (_c *ProductProcessCreate) SetRemark(v string) *ProductProcessCreate {
|
||||
_c.mutation.SetRemark(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableRemark sets the "remark" field if the given value is not nil.
|
||||
func (_c *ProductProcessCreate) SetNillableRemark(v *string) *ProductProcessCreate {
|
||||
if v != nil {
|
||||
_c.SetRemark(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "createdAt" field.
|
||||
func (_c *ProductProcessCreate) SetCreatedAt(v time.Time) *ProductProcessCreate {
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "createdAt" field if the given value is not nil.
|
||||
func (_c *ProductProcessCreate) SetNillableCreatedAt(v *time.Time) *ProductProcessCreate {
|
||||
if v != nil {
|
||||
_c.SetCreatedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetID sets the "id" field.
|
||||
func (_c *ProductProcessCreate) SetID(v int) *ProductProcessCreate {
|
||||
_c.mutation.SetID(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// Mutation returns the ProductProcessMutation object of the builder.
|
||||
func (_c *ProductProcessCreate) Mutation() *ProductProcessMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the ProductProcess in the database.
|
||||
func (_c *ProductProcessCreate) Save(ctx context.Context) (*ProductProcess, error) {
|
||||
_c.defaults()
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *ProductProcessCreate) SaveX(ctx context.Context) *ProductProcess {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *ProductProcessCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *ProductProcessCreate) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_c *ProductProcessCreate) defaults() {
|
||||
if _, ok := _c.mutation.ProductName(); !ok {
|
||||
v := productprocess.DefaultProductName
|
||||
_c.mutation.SetProductName(v)
|
||||
}
|
||||
if _, ok := _c.mutation.IsDefault(); !ok {
|
||||
v := productprocess.DefaultIsDefault
|
||||
_c.mutation.SetIsDefault(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Status(); !ok {
|
||||
v := productprocess.DefaultStatus
|
||||
_c.mutation.SetStatus(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Remark(); !ok {
|
||||
v := productprocess.DefaultRemark
|
||||
_c.mutation.SetRemark(v)
|
||||
}
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
v := productprocess.DefaultCreatedAt()
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *ProductProcessCreate) check() error {
|
||||
if _, ok := _c.mutation.ProductCode(); !ok {
|
||||
return &ValidationError{Name: "productCode", err: errors.New(`ent: missing required field "ProductProcess.productCode"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.ProductCode(); ok {
|
||||
if err := productprocess.ProductCodeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "productCode", err: fmt.Errorf(`ent: validator failed for field "ProductProcess.productCode": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.ProductName(); !ok {
|
||||
return &ValidationError{Name: "productName", err: errors.New(`ent: missing required field "ProductProcess.productName"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.ProductName(); ok {
|
||||
if err := productprocess.ProductNameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "productName", err: fmt.Errorf(`ent: validator failed for field "ProductProcess.productName": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "ProductProcess.name"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.Name(); ok {
|
||||
if err := productprocess.NameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ProductProcess.name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.IsDefault(); !ok {
|
||||
return &ValidationError{Name: "isDefault", err: errors.New(`ent: missing required field "ProductProcess.isDefault"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Status(); !ok {
|
||||
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "ProductProcess.status"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.Status(); ok {
|
||||
if err := productprocess.StatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "ProductProcess.status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.Remark(); !ok {
|
||||
return &ValidationError{Name: "remark", err: errors.New(`ent: missing required field "ProductProcess.remark"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.Remark(); ok {
|
||||
if err := productprocess.RemarkValidator(v); err != nil {
|
||||
return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "ProductProcess.remark": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "createdAt", err: errors.New(`ent: missing required field "ProductProcess.createdAt"`)}
|
||||
}
|
||||
if v, ok := _c.mutation.ID(); ok {
|
||||
if err := productprocess.IDValidator(v); err != nil {
|
||||
return &ValidationError{Name: "id", err: fmt.Errorf(`ent: validator failed for field "ProductProcess.id": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *ProductProcessCreate) sqlSave(ctx context.Context) (*ProductProcess, error) {
|
||||
if err := _c.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := _c.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, _c.driver, _spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if _spec.ID.Value != _node.ID {
|
||||
id := _spec.ID.Value.(int64)
|
||||
_node.ID = int(id)
|
||||
}
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (_c *ProductProcessCreate) createSpec() (*ProductProcess, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &ProductProcess{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(productprocess.Table, sqlgraph.NewFieldSpec(productprocess.FieldID, field.TypeInt))
|
||||
)
|
||||
if id, ok := _c.mutation.ID(); ok {
|
||||
_node.ID = id
|
||||
_spec.ID.Value = id
|
||||
}
|
||||
if value, ok := _c.mutation.ProductCode(); ok {
|
||||
_spec.SetField(productprocess.FieldProductCode, field.TypeString, value)
|
||||
_node.ProductCode = value
|
||||
}
|
||||
if value, ok := _c.mutation.ProductName(); ok {
|
||||
_spec.SetField(productprocess.FieldProductName, field.TypeString, value)
|
||||
_node.ProductName = value
|
||||
}
|
||||
if value, ok := _c.mutation.Name(); ok {
|
||||
_spec.SetField(productprocess.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := _c.mutation.IsDefault(); ok {
|
||||
_spec.SetField(productprocess.FieldIsDefault, field.TypeBool, value)
|
||||
_node.IsDefault = value
|
||||
}
|
||||
if value, ok := _c.mutation.Status(); ok {
|
||||
_spec.SetField(productprocess.FieldStatus, field.TypeString, value)
|
||||
_node.Status = value
|
||||
}
|
||||
if value, ok := _c.mutation.Remark(); ok {
|
||||
_spec.SetField(productprocess.FieldRemark, field.TypeString, value)
|
||||
_node.Remark = value
|
||||
}
|
||||
if value, ok := _c.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(productprocess.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// ProductProcessCreateBulk is the builder for creating many ProductProcess entities in bulk.
|
||||
type ProductProcessCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*ProductProcessCreate
|
||||
}
|
||||
|
||||
// Save creates the ProductProcess entities in the database.
|
||||
func (_c *ProductProcessCreateBulk) Save(ctx context.Context) ([]*ProductProcess, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*ProductProcess, len(_c.builders))
|
||||
mutators := make([]Mutator, len(_c.builders))
|
||||
for i := range _c.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := _c.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*ProductProcessMutation)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("unexpected mutation type %T", m)
|
||||
}
|
||||
if err := builder.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
builder.mutation = mutation
|
||||
var err error
|
||||
nodes[i], specs[i] = builder.createSpec()
|
||||
if i < len(mutators)-1 {
|
||||
_, err = mutators[i+1].Mutate(root, _c.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, _c.driver, spec); err != nil {
|
||||
if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mutation.id = &nodes[i].ID
|
||||
if specs[i].ID.Value != nil && nodes[i].ID == 0 {
|
||||
id := specs[i].ID.Value.(int64)
|
||||
nodes[i].ID = int(id)
|
||||
}
|
||||
mutation.done = true
|
||||
return nodes[i], nil
|
||||
})
|
||||
for i := len(builder.hooks) - 1; i >= 0; i-- {
|
||||
mut = builder.hooks[i](mut)
|
||||
}
|
||||
mutators[i] = mut
|
||||
}(i, ctx)
|
||||
}
|
||||
if len(mutators) > 0 {
|
||||
if _, err := mutators[0].Mutate(ctx, _c.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_c *ProductProcessCreateBulk) SaveX(ctx context.Context) []*ProductProcess {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *ProductProcessCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *ProductProcessCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user