Files
bj_power/bj_power_mes/ent/mixproductiontemplate_update.go
T
SunYF 1e92b2a596 feat: 核心业务实体扩充(混产模板/产品BOM/试制记录)、WMS 库存检验增强与前端通用能力
- MES 新增实体:混产模板、产品BOM、产品工艺物料、试制记录(schema + ent 生成码 + logic/handler/前端页)
- WMS 实体增强:检验记录、库存、半成品重构;新增序列号库存与短缺代报
- AGV 与产能:AGV 手动点位与链路、物料守卫、短缺预测、原因字典
- 前端通用能力:新增下一步引导组件 NextStepBar,统一帮助文档/布局/请求拦截与操作列
- 工位终端:界面与各 handler 调整(api/store/绑定/PLC/拧紧/上报等)
- 配置与文档:更新 mes-api.yaml、WMS README 及案例/产线API/问题记录/项目说明/流程说明
2026-11-15 12:17:39 +08:00

374 lines
12 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"bj_power_mes/ent/mixproductiontemplate"
"bj_power_mes/ent/predicate"
"context"
"errors"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// MixProductionTemplateUpdate is the builder for updating MixProductionTemplate entities.
type MixProductionTemplateUpdate struct {
config
hooks []Hook
mutation *MixProductionTemplateMutation
modifiers []func(*sql.UpdateBuilder)
}
// Where appends a list predicates to the MixProductionTemplateUpdate builder.
func (_u *MixProductionTemplateUpdate) Where(ps ...predicate.MixProductionTemplate) *MixProductionTemplateUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetName sets the "name" field.
func (_u *MixProductionTemplateUpdate) SetName(v string) *MixProductionTemplateUpdate {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *MixProductionTemplateUpdate) SetNillableName(v *string) *MixProductionTemplateUpdate {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetProductCodes sets the "productCodes" field.
func (_u *MixProductionTemplateUpdate) SetProductCodes(v string) *MixProductionTemplateUpdate {
_u.mutation.SetProductCodes(v)
return _u
}
// SetNillableProductCodes sets the "productCodes" field if the given value is not nil.
func (_u *MixProductionTemplateUpdate) SetNillableProductCodes(v *string) *MixProductionTemplateUpdate {
if v != nil {
_u.SetProductCodes(*v)
}
return _u
}
// SetRemark sets the "remark" field.
func (_u *MixProductionTemplateUpdate) SetRemark(v string) *MixProductionTemplateUpdate {
_u.mutation.SetRemark(v)
return _u
}
// SetNillableRemark sets the "remark" field if the given value is not nil.
func (_u *MixProductionTemplateUpdate) SetNillableRemark(v *string) *MixProductionTemplateUpdate {
if v != nil {
_u.SetRemark(*v)
}
return _u
}
// SetStatus sets the "status" field.
func (_u *MixProductionTemplateUpdate) SetStatus(v string) *MixProductionTemplateUpdate {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *MixProductionTemplateUpdate) SetNillableStatus(v *string) *MixProductionTemplateUpdate {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// Mutation returns the MixProductionTemplateMutation object of the builder.
func (_u *MixProductionTemplateUpdate) Mutation() *MixProductionTemplateMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *MixProductionTemplateUpdate) 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 *MixProductionTemplateUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *MixProductionTemplateUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *MixProductionTemplateUpdate) 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 *MixProductionTemplateUpdate) check() error {
if v, ok := _u.mutation.Name(); ok {
if err := mixproductiontemplate.NameValidator(v); err != nil {
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "MixProductionTemplate.name": %w`, err)}
}
}
if v, ok := _u.mutation.Remark(); ok {
if err := mixproductiontemplate.RemarkValidator(v); err != nil {
return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "MixProductionTemplate.remark": %w`, err)}
}
}
if v, ok := _u.mutation.Status(); ok {
if err := mixproductiontemplate.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "MixProductionTemplate.status": %w`, err)}
}
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *MixProductionTemplateUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *MixProductionTemplateUpdate {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *MixProductionTemplateUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(mixproductiontemplate.Table, mixproductiontemplate.Columns, sqlgraph.NewFieldSpec(mixproductiontemplate.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.Name(); ok {
_spec.SetField(mixproductiontemplate.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.ProductCodes(); ok {
_spec.SetField(mixproductiontemplate.FieldProductCodes, field.TypeString, value)
}
if value, ok := _u.mutation.Remark(); ok {
_spec.SetField(mixproductiontemplate.FieldRemark, field.TypeString, value)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(mixproductiontemplate.FieldStatus, 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{mixproductiontemplate.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// MixProductionTemplateUpdateOne is the builder for updating a single MixProductionTemplate entity.
type MixProductionTemplateUpdateOne struct {
config
fields []string
hooks []Hook
mutation *MixProductionTemplateMutation
modifiers []func(*sql.UpdateBuilder)
}
// SetName sets the "name" field.
func (_u *MixProductionTemplateUpdateOne) SetName(v string) *MixProductionTemplateUpdateOne {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *MixProductionTemplateUpdateOne) SetNillableName(v *string) *MixProductionTemplateUpdateOne {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetProductCodes sets the "productCodes" field.
func (_u *MixProductionTemplateUpdateOne) SetProductCodes(v string) *MixProductionTemplateUpdateOne {
_u.mutation.SetProductCodes(v)
return _u
}
// SetNillableProductCodes sets the "productCodes" field if the given value is not nil.
func (_u *MixProductionTemplateUpdateOne) SetNillableProductCodes(v *string) *MixProductionTemplateUpdateOne {
if v != nil {
_u.SetProductCodes(*v)
}
return _u
}
// SetRemark sets the "remark" field.
func (_u *MixProductionTemplateUpdateOne) SetRemark(v string) *MixProductionTemplateUpdateOne {
_u.mutation.SetRemark(v)
return _u
}
// SetNillableRemark sets the "remark" field if the given value is not nil.
func (_u *MixProductionTemplateUpdateOne) SetNillableRemark(v *string) *MixProductionTemplateUpdateOne {
if v != nil {
_u.SetRemark(*v)
}
return _u
}
// SetStatus sets the "status" field.
func (_u *MixProductionTemplateUpdateOne) SetStatus(v string) *MixProductionTemplateUpdateOne {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *MixProductionTemplateUpdateOne) SetNillableStatus(v *string) *MixProductionTemplateUpdateOne {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// Mutation returns the MixProductionTemplateMutation object of the builder.
func (_u *MixProductionTemplateUpdateOne) Mutation() *MixProductionTemplateMutation {
return _u.mutation
}
// Where appends a list predicates to the MixProductionTemplateUpdate builder.
func (_u *MixProductionTemplateUpdateOne) Where(ps ...predicate.MixProductionTemplate) *MixProductionTemplateUpdateOne {
_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 *MixProductionTemplateUpdateOne) Select(field string, fields ...string) *MixProductionTemplateUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated MixProductionTemplate entity.
func (_u *MixProductionTemplateUpdateOne) Save(ctx context.Context) (*MixProductionTemplate, error) {
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *MixProductionTemplateUpdateOne) SaveX(ctx context.Context) *MixProductionTemplate {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *MixProductionTemplateUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *MixProductionTemplateUpdateOne) 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 *MixProductionTemplateUpdateOne) check() error {
if v, ok := _u.mutation.Name(); ok {
if err := mixproductiontemplate.NameValidator(v); err != nil {
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "MixProductionTemplate.name": %w`, err)}
}
}
if v, ok := _u.mutation.Remark(); ok {
if err := mixproductiontemplate.RemarkValidator(v); err != nil {
return &ValidationError{Name: "remark", err: fmt.Errorf(`ent: validator failed for field "MixProductionTemplate.remark": %w`, err)}
}
}
if v, ok := _u.mutation.Status(); ok {
if err := mixproductiontemplate.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "MixProductionTemplate.status": %w`, err)}
}
}
return nil
}
// Modify adds a statement modifier for attaching custom logic to the UPDATE statement.
func (_u *MixProductionTemplateUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *MixProductionTemplateUpdateOne {
_u.modifiers = append(_u.modifiers, modifiers...)
return _u
}
func (_u *MixProductionTemplateUpdateOne) sqlSave(ctx context.Context) (_node *MixProductionTemplate, err error) {
if err := _u.check(); err != nil {
return _node, err
}
_spec := sqlgraph.NewUpdateSpec(mixproductiontemplate.Table, mixproductiontemplate.Columns, sqlgraph.NewFieldSpec(mixproductiontemplate.FieldID, field.TypeInt))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "MixProductionTemplate.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, mixproductiontemplate.FieldID)
for _, f := range fields {
if !mixproductiontemplate.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != mixproductiontemplate.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.Name(); ok {
_spec.SetField(mixproductiontemplate.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.ProductCodes(); ok {
_spec.SetField(mixproductiontemplate.FieldProductCodes, field.TypeString, value)
}
if value, ok := _u.mutation.Remark(); ok {
_spec.SetField(mixproductiontemplate.FieldRemark, field.TypeString, value)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(mixproductiontemplate.FieldStatus, field.TypeString, value)
}
_spec.AddModifiers(_u.modifiers...)
_node = &MixProductionTemplate{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{mixproductiontemplate.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}