feat: 新增产品工艺管理与工序审核功能
- 新增产品工艺(product_process)及明细(product_process_item)数据模型 - 新增工序审核开关(need_audit)与审核角色(audit_role)字段 - 新增待审核签字页面与路由 - 优化 WMS/MES 接口交互,增加业务错误处理与友好提示 - 补充库存过滤逻辑,避免返回已出库 SN 数据 - 调整默认查询时间范围为近一个月,优化用户体验
This commit is contained in:
@@ -0,0 +1,461 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"bj_power_mes/ent/predicate"
|
||||
"bj_power_mes/ent/productprocess"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ProductProcessUpdate is the builder for updating ProductProcess entities.
|
||||
type ProductProcessUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *ProductProcessMutation
|
||||
modifiers []func(*sql.UpdateBuilder)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ProductProcessUpdate builder.
|
||||
func (_u *ProductProcessUpdate) Where(ps ...predicate.ProductProcess) *ProductProcessUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetProductCode sets the "productCode" field.
|
||||
func (_u *ProductProcessUpdate) SetProductCode(v string) *ProductProcessUpdate {
|
||||
_u.mutation.SetProductCode(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableProductCode sets the "productCode" field if the given value is not nil.
|
||||
func (_u *ProductProcessUpdate) SetNillableProductCode(v *string) *ProductProcessUpdate {
|
||||
if v != nil {
|
||||
_u.SetProductCode(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetProductName sets the "productName" field.
|
||||
func (_u *ProductProcessUpdate) SetProductName(v string) *ProductProcessUpdate {
|
||||
_u.mutation.SetProductName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableProductName sets the "productName" field if the given value is not nil.
|
||||
func (_u *ProductProcessUpdate) SetNillableProductName(v *string) *ProductProcessUpdate {
|
||||
if v != nil {
|
||||
_u.SetProductName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_u *ProductProcessUpdate) SetName(v string) *ProductProcessUpdate {
|
||||
_u.mutation.SetName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_u *ProductProcessUpdate) SetNillableName(v *string) *ProductProcessUpdate {
|
||||
if v != nil {
|
||||
_u.SetName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetIsDefault sets the "isDefault" field.
|
||||
func (_u *ProductProcessUpdate) SetIsDefault(v bool) *ProductProcessUpdate {
|
||||
_u.mutation.SetIsDefault(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableIsDefault sets the "isDefault" field if the given value is not nil.
|
||||
func (_u *ProductProcessUpdate) SetNillableIsDefault(v *bool) *ProductProcessUpdate {
|
||||
if v != nil {
|
||||
_u.SetIsDefault(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (_u *ProductProcessUpdate) SetStatus(v string) *ProductProcessUpdate {
|
||||
_u.mutation.SetStatus(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (_u *ProductProcessUpdate) SetNillableStatus(v *string) *ProductProcessUpdate {
|
||||
if v != nil {
|
||||
_u.SetStatus(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetRemark sets the "remark" field.
|
||||
func (_u *ProductProcessUpdate) SetRemark(v string) *ProductProcessUpdate {
|
||||
_u.mutation.SetRemark(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableRemark sets the "remark" field if the given value is not nil.
|
||||
func (_u *ProductProcessUpdate) SetNillableRemark(v *string) *ProductProcessUpdate {
|
||||
if v != nil {
|
||||
_u.SetRemark(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the ProductProcessMutation object of the builder.
|
||||
func (_u *ProductProcessUpdate) Mutation() *ProductProcessMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *ProductProcessUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *ProductProcessUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *ProductProcessUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *ProductProcessUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *ProductProcessUpdate) check() error {
|
||||
if v, ok := _u.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 v, ok := _u.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 v, ok := _u.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 v, ok := _u.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 v, ok := _u.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)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
||||
func (_u *ProductProcessUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *ProductProcessUpdate {
|
||||
_u.modifiers = append(_u.modifiers, modifiers...)
|
||||
return _u
|
||||
}
|
||||
|
||||
func (_u *ProductProcessUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(productprocess.Table, productprocess.Columns, sqlgraph.NewFieldSpec(productprocess.FieldID, field.TypeInt))
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.ProductCode(); ok {
|
||||
_spec.SetField(productprocess.FieldProductCode, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.ProductName(); ok {
|
||||
_spec.SetField(productprocess.FieldProductName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Name(); ok {
|
||||
_spec.SetField(productprocess.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.IsDefault(); ok {
|
||||
_spec.SetField(productprocess.FieldIsDefault, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Status(); ok {
|
||||
_spec.SetField(productprocess.FieldStatus, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Remark(); ok {
|
||||
_spec.SetField(productprocess.FieldRemark, field.TypeString, value)
|
||||
}
|
||||
_spec.AddModifiers(_u.modifiers...)
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{productprocess.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// ProductProcessUpdateOne is the builder for updating a single ProductProcess entity.
|
||||
type ProductProcessUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *ProductProcessMutation
|
||||
modifiers []func(*sql.UpdateBuilder)
|
||||
}
|
||||
|
||||
// SetProductCode sets the "productCode" field.
|
||||
func (_u *ProductProcessUpdateOne) SetProductCode(v string) *ProductProcessUpdateOne {
|
||||
_u.mutation.SetProductCode(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableProductCode sets the "productCode" field if the given value is not nil.
|
||||
func (_u *ProductProcessUpdateOne) SetNillableProductCode(v *string) *ProductProcessUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetProductCode(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetProductName sets the "productName" field.
|
||||
func (_u *ProductProcessUpdateOne) SetProductName(v string) *ProductProcessUpdateOne {
|
||||
_u.mutation.SetProductName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableProductName sets the "productName" field if the given value is not nil.
|
||||
func (_u *ProductProcessUpdateOne) SetNillableProductName(v *string) *ProductProcessUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetProductName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_u *ProductProcessUpdateOne) SetName(v string) *ProductProcessUpdateOne {
|
||||
_u.mutation.SetName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_u *ProductProcessUpdateOne) SetNillableName(v *string) *ProductProcessUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetIsDefault sets the "isDefault" field.
|
||||
func (_u *ProductProcessUpdateOne) SetIsDefault(v bool) *ProductProcessUpdateOne {
|
||||
_u.mutation.SetIsDefault(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableIsDefault sets the "isDefault" field if the given value is not nil.
|
||||
func (_u *ProductProcessUpdateOne) SetNillableIsDefault(v *bool) *ProductProcessUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetIsDefault(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (_u *ProductProcessUpdateOne) SetStatus(v string) *ProductProcessUpdateOne {
|
||||
_u.mutation.SetStatus(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (_u *ProductProcessUpdateOne) SetNillableStatus(v *string) *ProductProcessUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetStatus(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetRemark sets the "remark" field.
|
||||
func (_u *ProductProcessUpdateOne) SetRemark(v string) *ProductProcessUpdateOne {
|
||||
_u.mutation.SetRemark(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableRemark sets the "remark" field if the given value is not nil.
|
||||
func (_u *ProductProcessUpdateOne) SetNillableRemark(v *string) *ProductProcessUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetRemark(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the ProductProcessMutation object of the builder.
|
||||
func (_u *ProductProcessUpdateOne) Mutation() *ProductProcessMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ProductProcessUpdate builder.
|
||||
func (_u *ProductProcessUpdateOne) Where(ps ...predicate.ProductProcess) *ProductProcessUpdateOne {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (_u *ProductProcessUpdateOne) Select(field string, fields ...string) *ProductProcessUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated ProductProcess entity.
|
||||
func (_u *ProductProcessUpdateOne) Save(ctx context.Context) (*ProductProcess, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *ProductProcessUpdateOne) SaveX(ctx context.Context) *ProductProcess {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *ProductProcessUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *ProductProcessUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *ProductProcessUpdateOne) check() error {
|
||||
if v, ok := _u.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 v, ok := _u.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 v, ok := _u.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 v, ok := _u.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 v, ok := _u.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)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
|
||||
func (_u *ProductProcessUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *ProductProcessUpdateOne {
|
||||
_u.modifiers = append(_u.modifiers, modifiers...)
|
||||
return _u
|
||||
}
|
||||
|
||||
func (_u *ProductProcessUpdateOne) sqlSave(ctx context.Context) (_node *ProductProcess, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(productprocess.Table, productprocess.Columns, sqlgraph.NewFieldSpec(productprocess.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ProductProcess.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := _u.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, productprocess.FieldID)
|
||||
for _, f := range fields {
|
||||
if !productprocess.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != productprocess.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := _u.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := _u.mutation.ProductCode(); ok {
|
||||
_spec.SetField(productprocess.FieldProductCode, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.ProductName(); ok {
|
||||
_spec.SetField(productprocess.FieldProductName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Name(); ok {
|
||||
_spec.SetField(productprocess.FieldName, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.IsDefault(); ok {
|
||||
_spec.SetField(productprocess.FieldIsDefault, field.TypeBool, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Status(); ok {
|
||||
_spec.SetField(productprocess.FieldStatus, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.Remark(); ok {
|
||||
_spec.SetField(productprocess.FieldRemark, field.TypeString, value)
|
||||
}
|
||||
_spec.AddModifiers(_u.modifiers...)
|
||||
_node = &ProductProcess{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{productprocess.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
Reference in New Issue
Block a user