feat(mes): 添加定时同步可生产数量到WMS及BOM项相关标准字段
- 在main.go中添加定时任务每10分钟同步可生产数量到WMS系统 - 为BomItem实体添加relatedStandard字段及相关CRUD方法 - 为InspectionRecord实体添加reportNo、materialCode、materialName等字段 - 更新ent schema确保新字段的验证和默认值设置 - 添加必要的数据库迁移和字段映射逻辑
This commit is contained in:
@@ -0,0 +1,475 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"bj_power_wms/ent/predicate"
|
||||
"bj_power_wms/ent/produciblesnapshot"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// ProducibleSnapshotUpdate is the builder for updating ProducibleSnapshot entities.
|
||||
type ProducibleSnapshotUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *ProducibleSnapshotMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ProducibleSnapshotUpdate builder.
|
||||
func (_u *ProducibleSnapshotUpdate) Where(ps ...predicate.ProducibleSnapshot) *ProducibleSnapshotUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetProductCode sets the "product_code" field.
|
||||
func (_u *ProducibleSnapshotUpdate) SetProductCode(v string) *ProducibleSnapshotUpdate {
|
||||
_u.mutation.SetProductCode(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableProductCode sets the "product_code" field if the given value is not nil.
|
||||
func (_u *ProducibleSnapshotUpdate) SetNillableProductCode(v *string) *ProducibleSnapshotUpdate {
|
||||
if v != nil {
|
||||
_u.SetProductCode(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetProductName sets the "product_name" field.
|
||||
func (_u *ProducibleSnapshotUpdate) SetProductName(v string) *ProducibleSnapshotUpdate {
|
||||
_u.mutation.SetProductName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableProductName sets the "product_name" field if the given value is not nil.
|
||||
func (_u *ProducibleSnapshotUpdate) SetNillableProductName(v *string) *ProducibleSnapshotUpdate {
|
||||
if v != nil {
|
||||
_u.SetProductName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearProductName clears the value of the "product_name" field.
|
||||
func (_u *ProducibleSnapshotUpdate) ClearProductName() *ProducibleSnapshotUpdate {
|
||||
_u.mutation.ClearProductName()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetProducibleQty sets the "producible_qty" field.
|
||||
func (_u *ProducibleSnapshotUpdate) SetProducibleQty(v int) *ProducibleSnapshotUpdate {
|
||||
_u.mutation.ResetProducibleQty()
|
||||
_u.mutation.SetProducibleQty(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableProducibleQty sets the "producible_qty" field if the given value is not nil.
|
||||
func (_u *ProducibleSnapshotUpdate) SetNillableProducibleQty(v *int) *ProducibleSnapshotUpdate {
|
||||
if v != nil {
|
||||
_u.SetProducibleQty(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddProducibleQty adds value to the "producible_qty" field.
|
||||
func (_u *ProducibleSnapshotUpdate) AddProducibleQty(v int) *ProducibleSnapshotUpdate {
|
||||
_u.mutation.AddProducibleQty(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetShortText sets the "short_text" field.
|
||||
func (_u *ProducibleSnapshotUpdate) SetShortText(v string) *ProducibleSnapshotUpdate {
|
||||
_u.mutation.SetShortText(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableShortText sets the "short_text" field if the given value is not nil.
|
||||
func (_u *ProducibleSnapshotUpdate) SetNillableShortText(v *string) *ProducibleSnapshotUpdate {
|
||||
if v != nil {
|
||||
_u.SetShortText(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearShortText clears the value of the "short_text" field.
|
||||
func (_u *ProducibleSnapshotUpdate) ClearShortText() *ProducibleSnapshotUpdate {
|
||||
_u.mutation.ClearShortText()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetComputedAt sets the "computed_at" field.
|
||||
func (_u *ProducibleSnapshotUpdate) SetComputedAt(v int64) *ProducibleSnapshotUpdate {
|
||||
_u.mutation.ResetComputedAt()
|
||||
_u.mutation.SetComputedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableComputedAt sets the "computed_at" field if the given value is not nil.
|
||||
func (_u *ProducibleSnapshotUpdate) SetNillableComputedAt(v *int64) *ProducibleSnapshotUpdate {
|
||||
if v != nil {
|
||||
_u.SetComputedAt(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddComputedAt adds value to the "computed_at" field.
|
||||
func (_u *ProducibleSnapshotUpdate) AddComputedAt(v int64) *ProducibleSnapshotUpdate {
|
||||
_u.mutation.AddComputedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetSyncedAt sets the "synced_at" field.
|
||||
func (_u *ProducibleSnapshotUpdate) SetSyncedAt(v int64) *ProducibleSnapshotUpdate {
|
||||
_u.mutation.ResetSyncedAt()
|
||||
_u.mutation.SetSyncedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableSyncedAt sets the "synced_at" field if the given value is not nil.
|
||||
func (_u *ProducibleSnapshotUpdate) SetNillableSyncedAt(v *int64) *ProducibleSnapshotUpdate {
|
||||
if v != nil {
|
||||
_u.SetSyncedAt(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddSyncedAt adds value to the "synced_at" field.
|
||||
func (_u *ProducibleSnapshotUpdate) AddSyncedAt(v int64) *ProducibleSnapshotUpdate {
|
||||
_u.mutation.AddSyncedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the ProducibleSnapshotMutation object of the builder.
|
||||
func (_u *ProducibleSnapshotUpdate) Mutation() *ProducibleSnapshotMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *ProducibleSnapshotUpdate) 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 *ProducibleSnapshotUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *ProducibleSnapshotUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *ProducibleSnapshotUpdate) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *ProducibleSnapshotUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(produciblesnapshot.Table, produciblesnapshot.Columns, sqlgraph.NewFieldSpec(produciblesnapshot.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(produciblesnapshot.FieldProductCode, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.ProductName(); ok {
|
||||
_spec.SetField(produciblesnapshot.FieldProductName, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.ProductNameCleared() {
|
||||
_spec.ClearField(produciblesnapshot.FieldProductName, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.ProducibleQty(); ok {
|
||||
_spec.SetField(produciblesnapshot.FieldProducibleQty, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedProducibleQty(); ok {
|
||||
_spec.AddField(produciblesnapshot.FieldProducibleQty, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.ShortText(); ok {
|
||||
_spec.SetField(produciblesnapshot.FieldShortText, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.ShortTextCleared() {
|
||||
_spec.ClearField(produciblesnapshot.FieldShortText, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.ComputedAt(); ok {
|
||||
_spec.SetField(produciblesnapshot.FieldComputedAt, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedComputedAt(); ok {
|
||||
_spec.AddField(produciblesnapshot.FieldComputedAt, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.SyncedAt(); ok {
|
||||
_spec.SetField(produciblesnapshot.FieldSyncedAt, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedSyncedAt(); ok {
|
||||
_spec.AddField(produciblesnapshot.FieldSyncedAt, field.TypeInt64, value)
|
||||
}
|
||||
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{produciblesnapshot.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
_u.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// ProducibleSnapshotUpdateOne is the builder for updating a single ProducibleSnapshot entity.
|
||||
type ProducibleSnapshotUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *ProducibleSnapshotMutation
|
||||
}
|
||||
|
||||
// SetProductCode sets the "product_code" field.
|
||||
func (_u *ProducibleSnapshotUpdateOne) SetProductCode(v string) *ProducibleSnapshotUpdateOne {
|
||||
_u.mutation.SetProductCode(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableProductCode sets the "product_code" field if the given value is not nil.
|
||||
func (_u *ProducibleSnapshotUpdateOne) SetNillableProductCode(v *string) *ProducibleSnapshotUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetProductCode(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetProductName sets the "product_name" field.
|
||||
func (_u *ProducibleSnapshotUpdateOne) SetProductName(v string) *ProducibleSnapshotUpdateOne {
|
||||
_u.mutation.SetProductName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableProductName sets the "product_name" field if the given value is not nil.
|
||||
func (_u *ProducibleSnapshotUpdateOne) SetNillableProductName(v *string) *ProducibleSnapshotUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetProductName(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearProductName clears the value of the "product_name" field.
|
||||
func (_u *ProducibleSnapshotUpdateOne) ClearProductName() *ProducibleSnapshotUpdateOne {
|
||||
_u.mutation.ClearProductName()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetProducibleQty sets the "producible_qty" field.
|
||||
func (_u *ProducibleSnapshotUpdateOne) SetProducibleQty(v int) *ProducibleSnapshotUpdateOne {
|
||||
_u.mutation.ResetProducibleQty()
|
||||
_u.mutation.SetProducibleQty(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableProducibleQty sets the "producible_qty" field if the given value is not nil.
|
||||
func (_u *ProducibleSnapshotUpdateOne) SetNillableProducibleQty(v *int) *ProducibleSnapshotUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetProducibleQty(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddProducibleQty adds value to the "producible_qty" field.
|
||||
func (_u *ProducibleSnapshotUpdateOne) AddProducibleQty(v int) *ProducibleSnapshotUpdateOne {
|
||||
_u.mutation.AddProducibleQty(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetShortText sets the "short_text" field.
|
||||
func (_u *ProducibleSnapshotUpdateOne) SetShortText(v string) *ProducibleSnapshotUpdateOne {
|
||||
_u.mutation.SetShortText(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableShortText sets the "short_text" field if the given value is not nil.
|
||||
func (_u *ProducibleSnapshotUpdateOne) SetNillableShortText(v *string) *ProducibleSnapshotUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetShortText(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearShortText clears the value of the "short_text" field.
|
||||
func (_u *ProducibleSnapshotUpdateOne) ClearShortText() *ProducibleSnapshotUpdateOne {
|
||||
_u.mutation.ClearShortText()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetComputedAt sets the "computed_at" field.
|
||||
func (_u *ProducibleSnapshotUpdateOne) SetComputedAt(v int64) *ProducibleSnapshotUpdateOne {
|
||||
_u.mutation.ResetComputedAt()
|
||||
_u.mutation.SetComputedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableComputedAt sets the "computed_at" field if the given value is not nil.
|
||||
func (_u *ProducibleSnapshotUpdateOne) SetNillableComputedAt(v *int64) *ProducibleSnapshotUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetComputedAt(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddComputedAt adds value to the "computed_at" field.
|
||||
func (_u *ProducibleSnapshotUpdateOne) AddComputedAt(v int64) *ProducibleSnapshotUpdateOne {
|
||||
_u.mutation.AddComputedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetSyncedAt sets the "synced_at" field.
|
||||
func (_u *ProducibleSnapshotUpdateOne) SetSyncedAt(v int64) *ProducibleSnapshotUpdateOne {
|
||||
_u.mutation.ResetSyncedAt()
|
||||
_u.mutation.SetSyncedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableSyncedAt sets the "synced_at" field if the given value is not nil.
|
||||
func (_u *ProducibleSnapshotUpdateOne) SetNillableSyncedAt(v *int64) *ProducibleSnapshotUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetSyncedAt(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddSyncedAt adds value to the "synced_at" field.
|
||||
func (_u *ProducibleSnapshotUpdateOne) AddSyncedAt(v int64) *ProducibleSnapshotUpdateOne {
|
||||
_u.mutation.AddSyncedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Mutation returns the ProducibleSnapshotMutation object of the builder.
|
||||
func (_u *ProducibleSnapshotUpdateOne) Mutation() *ProducibleSnapshotMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ProducibleSnapshotUpdate builder.
|
||||
func (_u *ProducibleSnapshotUpdateOne) Where(ps ...predicate.ProducibleSnapshot) *ProducibleSnapshotUpdateOne {
|
||||
_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 *ProducibleSnapshotUpdateOne) Select(field string, fields ...string) *ProducibleSnapshotUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated ProducibleSnapshot entity.
|
||||
func (_u *ProducibleSnapshotUpdateOne) Save(ctx context.Context) (*ProducibleSnapshot, error) {
|
||||
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *ProducibleSnapshotUpdateOne) SaveX(ctx context.Context) *ProducibleSnapshot {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *ProducibleSnapshotUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *ProducibleSnapshotUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := _u.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (_u *ProducibleSnapshotUpdateOne) sqlSave(ctx context.Context) (_node *ProducibleSnapshot, err error) {
|
||||
_spec := sqlgraph.NewUpdateSpec(produciblesnapshot.Table, produciblesnapshot.Columns, sqlgraph.NewFieldSpec(produciblesnapshot.FieldID, field.TypeInt))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ProducibleSnapshot.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, produciblesnapshot.FieldID)
|
||||
for _, f := range fields {
|
||||
if !produciblesnapshot.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != produciblesnapshot.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(produciblesnapshot.FieldProductCode, field.TypeString, value)
|
||||
}
|
||||
if value, ok := _u.mutation.ProductName(); ok {
|
||||
_spec.SetField(produciblesnapshot.FieldProductName, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.ProductNameCleared() {
|
||||
_spec.ClearField(produciblesnapshot.FieldProductName, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.ProducibleQty(); ok {
|
||||
_spec.SetField(produciblesnapshot.FieldProducibleQty, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedProducibleQty(); ok {
|
||||
_spec.AddField(produciblesnapshot.FieldProducibleQty, field.TypeInt, value)
|
||||
}
|
||||
if value, ok := _u.mutation.ShortText(); ok {
|
||||
_spec.SetField(produciblesnapshot.FieldShortText, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.ShortTextCleared() {
|
||||
_spec.ClearField(produciblesnapshot.FieldShortText, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.ComputedAt(); ok {
|
||||
_spec.SetField(produciblesnapshot.FieldComputedAt, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedComputedAt(); ok {
|
||||
_spec.AddField(produciblesnapshot.FieldComputedAt, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.SyncedAt(); ok {
|
||||
_spec.SetField(produciblesnapshot.FieldSyncedAt, field.TypeInt64, value)
|
||||
}
|
||||
if value, ok := _u.mutation.AddedSyncedAt(); ok {
|
||||
_spec.AddField(produciblesnapshot.FieldSyncedAt, field.TypeInt64, value)
|
||||
}
|
||||
_node = &ProducibleSnapshot{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{produciblesnapshot.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