diff --git a/bj_power_mes/ent/agvpoint.go b/bj_power_mes/ent/agvpoint.go new file mode 100644 index 0000000..7e2fde5 --- /dev/null +++ b/bj_power_mes/ent/agvpoint.go @@ -0,0 +1,166 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/agvpoint" + "fmt" + "strings" + "time" + + "entgo.io/ent" + "entgo.io/ent/dialect/sql" +) + +// AgvPoint AGV 点位(硬件级别真源):点位编码与接驳台一一对应,软件仅可启用/停用与改显示名。 +type AgvPoint struct { + config `json:"-"` + // ID of the ent. + ID int `json:"id,omitempty"` + // AGV 点位编码(硬件映射=送往 RCS 的目标坐标,软件不可改) + PositionCode string `json:"position_code,omitempty"` + // 点位显示名称(可编辑) + Name string `json:"name,omitempty"` + // 是否接驳台点位(true=绑定接驳台,false=纯待命/充电点位) + IsDock bool `json:"is_dock,omitempty"` + // 绑定的接驳台 ID(is_dock=true 时硬件内置强绑定) + DockID *int `json:"dock_id,omitempty"` + // 是否启用(可编辑) + Enabled bool `json:"enabled,omitempty"` + // CreatedAt holds the value of the "created_at" field. + CreatedAt time.Time `json:"created_at,omitempty"` + selectValues sql.SelectValues +} + +// scanValues returns the types for scanning values from sql.Rows. +func (*AgvPoint) scanValues(columns []string) ([]any, error) { + values := make([]any, len(columns)) + for i := range columns { + switch columns[i] { + case agvpoint.FieldIsDock, agvpoint.FieldEnabled: + values[i] = new(sql.NullBool) + case agvpoint.FieldID, agvpoint.FieldDockID: + values[i] = new(sql.NullInt64) + case agvpoint.FieldPositionCode, agvpoint.FieldName: + values[i] = new(sql.NullString) + case agvpoint.FieldCreatedAt: + values[i] = new(sql.NullTime) + default: + values[i] = new(sql.UnknownType) + } + } + return values, nil +} + +// assignValues assigns the values that were returned from sql.Rows (after scanning) +// to the AgvPoint fields. +func (_m *AgvPoint) assignValues(columns []string, values []any) error { + if m, n := len(values), len(columns); m < n { + return fmt.Errorf("mismatch number of scan values: %d != %d", m, n) + } + for i := range columns { + switch columns[i] { + case agvpoint.FieldID: + value, ok := values[i].(*sql.NullInt64) + if !ok { + return fmt.Errorf("unexpected type %T for field id", value) + } + _m.ID = int(value.Int64) + case agvpoint.FieldPositionCode: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field position_code", values[i]) + } else if value.Valid { + _m.PositionCode = value.String + } + case agvpoint.FieldName: + if value, ok := values[i].(*sql.NullString); !ok { + return fmt.Errorf("unexpected type %T for field name", values[i]) + } else if value.Valid { + _m.Name = value.String + } + case agvpoint.FieldIsDock: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field is_dock", values[i]) + } else if value.Valid { + _m.IsDock = value.Bool + } + case agvpoint.FieldDockID: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field dock_id", values[i]) + } else if value.Valid { + _m.DockID = new(int) + *_m.DockID = int(value.Int64) + } + case agvpoint.FieldEnabled: + if value, ok := values[i].(*sql.NullBool); !ok { + return fmt.Errorf("unexpected type %T for field enabled", values[i]) + } else if value.Valid { + _m.Enabled = value.Bool + } + case agvpoint.FieldCreatedAt: + if value, ok := values[i].(*sql.NullTime); !ok { + return fmt.Errorf("unexpected type %T for field created_at", values[i]) + } else if value.Valid { + _m.CreatedAt = value.Time + } + default: + _m.selectValues.Set(columns[i], values[i]) + } + } + return nil +} + +// Value returns the ent.Value that was dynamically selected and assigned to the AgvPoint. +// This includes values selected through modifiers, order, etc. +func (_m *AgvPoint) Value(name string) (ent.Value, error) { + return _m.selectValues.Get(name) +} + +// Update returns a builder for updating this AgvPoint. +// Note that you need to call AgvPoint.Unwrap() before calling this method if this AgvPoint +// was returned from a transaction, and the transaction was committed or rolled back. +func (_m *AgvPoint) Update() *AgvPointUpdateOne { + return NewAgvPointClient(_m.config).UpdateOne(_m) +} + +// Unwrap unwraps the AgvPoint entity that was returned from a transaction after it was closed, +// so that all future queries will be executed through the driver which created the transaction. +func (_m *AgvPoint) Unwrap() *AgvPoint { + _tx, ok := _m.config.driver.(*txDriver) + if !ok { + panic("ent: AgvPoint is not a transactional entity") + } + _m.config.driver = _tx.drv + return _m +} + +// String implements the fmt.Stringer. +func (_m *AgvPoint) String() string { + var builder strings.Builder + builder.WriteString("AgvPoint(") + builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID)) + builder.WriteString("position_code=") + builder.WriteString(_m.PositionCode) + builder.WriteString(", ") + builder.WriteString("name=") + builder.WriteString(_m.Name) + builder.WriteString(", ") + builder.WriteString("is_dock=") + builder.WriteString(fmt.Sprintf("%v", _m.IsDock)) + builder.WriteString(", ") + if v := _m.DockID; v != nil { + builder.WriteString("dock_id=") + builder.WriteString(fmt.Sprintf("%v", *v)) + } + builder.WriteString(", ") + builder.WriteString("enabled=") + builder.WriteString(fmt.Sprintf("%v", _m.Enabled)) + builder.WriteString(", ") + builder.WriteString("created_at=") + builder.WriteString(_m.CreatedAt.Format(time.ANSIC)) + builder.WriteByte(')') + return builder.String() +} + +// AgvPoints is a parsable slice of AgvPoint. +type AgvPoints []*AgvPoint diff --git a/bj_power_mes/ent/agvpoint/agvpoint.go b/bj_power_mes/ent/agvpoint/agvpoint.go new file mode 100644 index 0000000..0e53dd5 --- /dev/null +++ b/bj_power_mes/ent/agvpoint/agvpoint.go @@ -0,0 +1,104 @@ +// Code generated by ent, DO NOT EDIT. + +package agvpoint + +import ( + "time" + + "entgo.io/ent/dialect/sql" +) + +const ( + // Label holds the string label denoting the agvpoint type in the database. + Label = "agv_point" + // FieldID holds the string denoting the id field in the database. + FieldID = "id" + // FieldPositionCode holds the string denoting the position_code field in the database. + FieldPositionCode = "position_code" + // FieldName holds the string denoting the name field in the database. + FieldName = "name" + // FieldIsDock holds the string denoting the is_dock field in the database. + FieldIsDock = "is_dock" + // FieldDockID holds the string denoting the dock_id field in the database. + FieldDockID = "dock_id" + // FieldEnabled holds the string denoting the enabled field in the database. + FieldEnabled = "enabled" + // FieldCreatedAt holds the string denoting the created_at field in the database. + FieldCreatedAt = "created_at" + // Table holds the table name of the agvpoint in the database. + Table = "agv_point" +) + +// Columns holds all SQL columns for agvpoint fields. +var Columns = []string{ + FieldID, + FieldPositionCode, + FieldName, + FieldIsDock, + FieldDockID, + FieldEnabled, + FieldCreatedAt, +} + +// ValidColumn reports if the column name is valid (part of the table columns). +func ValidColumn(column string) bool { + for i := range Columns { + if column == Columns[i] { + return true + } + } + return false +} + +var ( + // PositionCodeValidator is a validator for the "position_code" field. It is called by the builders before save. + PositionCodeValidator func(string) error + // DefaultName holds the default value on creation for the "name" field. + DefaultName string + // NameValidator is a validator for the "name" field. It is called by the builders before save. + NameValidator func(string) error + // DefaultIsDock holds the default value on creation for the "is_dock" field. + DefaultIsDock bool + // DefaultEnabled holds the default value on creation for the "enabled" field. + DefaultEnabled bool + // DefaultCreatedAt holds the default value on creation for the "created_at" field. + DefaultCreatedAt func() time.Time +) + +// OrderOption defines the ordering options for the AgvPoint queries. +type OrderOption func(*sql.Selector) + +// ByID orders the results by the id field. +func ByID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldID, opts...).ToFunc() +} + +// ByPositionCode orders the results by the position_code field. +func ByPositionCode(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldPositionCode, opts...).ToFunc() +} + +// ByName orders the results by the name field. +func ByName(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldName, opts...).ToFunc() +} + +// ByIsDock orders the results by the is_dock field. +func ByIsDock(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldIsDock, opts...).ToFunc() +} + +// ByDockID orders the results by the dock_id field. +func ByDockID(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldDockID, opts...).ToFunc() +} + +// ByEnabled orders the results by the enabled field. +func ByEnabled(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldEnabled, opts...).ToFunc() +} + +// ByCreatedAt orders the results by the created_at field. +func ByCreatedAt(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldCreatedAt, opts...).ToFunc() +} diff --git a/bj_power_mes/ent/agvpoint/where.go b/bj_power_mes/ent/agvpoint/where.go new file mode 100644 index 0000000..bdd2069 --- /dev/null +++ b/bj_power_mes/ent/agvpoint/where.go @@ -0,0 +1,340 @@ +// Code generated by ent, DO NOT EDIT. + +package agvpoint + +import ( + "bj_power_mes/ent/predicate" + "time" + + "entgo.io/ent/dialect/sql" +) + +// ID filters vertices based on their ID field. +func ID(id int) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldEQ(FieldID, id)) +} + +// IDEQ applies the EQ predicate on the ID field. +func IDEQ(id int) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldEQ(FieldID, id)) +} + +// IDNEQ applies the NEQ predicate on the ID field. +func IDNEQ(id int) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldNEQ(FieldID, id)) +} + +// IDIn applies the In predicate on the ID field. +func IDIn(ids ...int) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldIn(FieldID, ids...)) +} + +// IDNotIn applies the NotIn predicate on the ID field. +func IDNotIn(ids ...int) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldNotIn(FieldID, ids...)) +} + +// IDGT applies the GT predicate on the ID field. +func IDGT(id int) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldGT(FieldID, id)) +} + +// IDGTE applies the GTE predicate on the ID field. +func IDGTE(id int) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldGTE(FieldID, id)) +} + +// IDLT applies the LT predicate on the ID field. +func IDLT(id int) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldLT(FieldID, id)) +} + +// IDLTE applies the LTE predicate on the ID field. +func IDLTE(id int) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldLTE(FieldID, id)) +} + +// PositionCode applies equality check predicate on the "position_code" field. It's identical to PositionCodeEQ. +func PositionCode(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldEQ(FieldPositionCode, v)) +} + +// Name applies equality check predicate on the "name" field. It's identical to NameEQ. +func Name(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldEQ(FieldName, v)) +} + +// IsDock applies equality check predicate on the "is_dock" field. It's identical to IsDockEQ. +func IsDock(v bool) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldEQ(FieldIsDock, v)) +} + +// DockID applies equality check predicate on the "dock_id" field. It's identical to DockIDEQ. +func DockID(v int) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldEQ(FieldDockID, v)) +} + +// Enabled applies equality check predicate on the "enabled" field. It's identical to EnabledEQ. +func Enabled(v bool) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldEQ(FieldEnabled, v)) +} + +// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ. +func CreatedAt(v time.Time) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldEQ(FieldCreatedAt, v)) +} + +// PositionCodeEQ applies the EQ predicate on the "position_code" field. +func PositionCodeEQ(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldEQ(FieldPositionCode, v)) +} + +// PositionCodeNEQ applies the NEQ predicate on the "position_code" field. +func PositionCodeNEQ(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldNEQ(FieldPositionCode, v)) +} + +// PositionCodeIn applies the In predicate on the "position_code" field. +func PositionCodeIn(vs ...string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldIn(FieldPositionCode, vs...)) +} + +// PositionCodeNotIn applies the NotIn predicate on the "position_code" field. +func PositionCodeNotIn(vs ...string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldNotIn(FieldPositionCode, vs...)) +} + +// PositionCodeGT applies the GT predicate on the "position_code" field. +func PositionCodeGT(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldGT(FieldPositionCode, v)) +} + +// PositionCodeGTE applies the GTE predicate on the "position_code" field. +func PositionCodeGTE(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldGTE(FieldPositionCode, v)) +} + +// PositionCodeLT applies the LT predicate on the "position_code" field. +func PositionCodeLT(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldLT(FieldPositionCode, v)) +} + +// PositionCodeLTE applies the LTE predicate on the "position_code" field. +func PositionCodeLTE(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldLTE(FieldPositionCode, v)) +} + +// PositionCodeContains applies the Contains predicate on the "position_code" field. +func PositionCodeContains(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldContains(FieldPositionCode, v)) +} + +// PositionCodeHasPrefix applies the HasPrefix predicate on the "position_code" field. +func PositionCodeHasPrefix(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldHasPrefix(FieldPositionCode, v)) +} + +// PositionCodeHasSuffix applies the HasSuffix predicate on the "position_code" field. +func PositionCodeHasSuffix(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldHasSuffix(FieldPositionCode, v)) +} + +// PositionCodeEqualFold applies the EqualFold predicate on the "position_code" field. +func PositionCodeEqualFold(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldEqualFold(FieldPositionCode, v)) +} + +// PositionCodeContainsFold applies the ContainsFold predicate on the "position_code" field. +func PositionCodeContainsFold(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldContainsFold(FieldPositionCode, v)) +} + +// NameEQ applies the EQ predicate on the "name" field. +func NameEQ(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldEQ(FieldName, v)) +} + +// NameNEQ applies the NEQ predicate on the "name" field. +func NameNEQ(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldNEQ(FieldName, v)) +} + +// NameIn applies the In predicate on the "name" field. +func NameIn(vs ...string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldIn(FieldName, vs...)) +} + +// NameNotIn applies the NotIn predicate on the "name" field. +func NameNotIn(vs ...string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldNotIn(FieldName, vs...)) +} + +// NameGT applies the GT predicate on the "name" field. +func NameGT(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldGT(FieldName, v)) +} + +// NameGTE applies the GTE predicate on the "name" field. +func NameGTE(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldGTE(FieldName, v)) +} + +// NameLT applies the LT predicate on the "name" field. +func NameLT(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldLT(FieldName, v)) +} + +// NameLTE applies the LTE predicate on the "name" field. +func NameLTE(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldLTE(FieldName, v)) +} + +// NameContains applies the Contains predicate on the "name" field. +func NameContains(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldContains(FieldName, v)) +} + +// NameHasPrefix applies the HasPrefix predicate on the "name" field. +func NameHasPrefix(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldHasPrefix(FieldName, v)) +} + +// NameHasSuffix applies the HasSuffix predicate on the "name" field. +func NameHasSuffix(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldHasSuffix(FieldName, v)) +} + +// NameEqualFold applies the EqualFold predicate on the "name" field. +func NameEqualFold(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldEqualFold(FieldName, v)) +} + +// NameContainsFold applies the ContainsFold predicate on the "name" field. +func NameContainsFold(v string) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldContainsFold(FieldName, v)) +} + +// IsDockEQ applies the EQ predicate on the "is_dock" field. +func IsDockEQ(v bool) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldEQ(FieldIsDock, v)) +} + +// IsDockNEQ applies the NEQ predicate on the "is_dock" field. +func IsDockNEQ(v bool) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldNEQ(FieldIsDock, v)) +} + +// DockIDEQ applies the EQ predicate on the "dock_id" field. +func DockIDEQ(v int) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldEQ(FieldDockID, v)) +} + +// DockIDNEQ applies the NEQ predicate on the "dock_id" field. +func DockIDNEQ(v int) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldNEQ(FieldDockID, v)) +} + +// DockIDIn applies the In predicate on the "dock_id" field. +func DockIDIn(vs ...int) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldIn(FieldDockID, vs...)) +} + +// DockIDNotIn applies the NotIn predicate on the "dock_id" field. +func DockIDNotIn(vs ...int) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldNotIn(FieldDockID, vs...)) +} + +// DockIDGT applies the GT predicate on the "dock_id" field. +func DockIDGT(v int) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldGT(FieldDockID, v)) +} + +// DockIDGTE applies the GTE predicate on the "dock_id" field. +func DockIDGTE(v int) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldGTE(FieldDockID, v)) +} + +// DockIDLT applies the LT predicate on the "dock_id" field. +func DockIDLT(v int) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldLT(FieldDockID, v)) +} + +// DockIDLTE applies the LTE predicate on the "dock_id" field. +func DockIDLTE(v int) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldLTE(FieldDockID, v)) +} + +// DockIDIsNil applies the IsNil predicate on the "dock_id" field. +func DockIDIsNil() predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldIsNull(FieldDockID)) +} + +// DockIDNotNil applies the NotNil predicate on the "dock_id" field. +func DockIDNotNil() predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldNotNull(FieldDockID)) +} + +// EnabledEQ applies the EQ predicate on the "enabled" field. +func EnabledEQ(v bool) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldEQ(FieldEnabled, v)) +} + +// EnabledNEQ applies the NEQ predicate on the "enabled" field. +func EnabledNEQ(v bool) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldNEQ(FieldEnabled, v)) +} + +// CreatedAtEQ applies the EQ predicate on the "created_at" field. +func CreatedAtEQ(v time.Time) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldEQ(FieldCreatedAt, v)) +} + +// CreatedAtNEQ applies the NEQ predicate on the "created_at" field. +func CreatedAtNEQ(v time.Time) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldNEQ(FieldCreatedAt, v)) +} + +// CreatedAtIn applies the In predicate on the "created_at" field. +func CreatedAtIn(vs ...time.Time) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldIn(FieldCreatedAt, vs...)) +} + +// CreatedAtNotIn applies the NotIn predicate on the "created_at" field. +func CreatedAtNotIn(vs ...time.Time) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldNotIn(FieldCreatedAt, vs...)) +} + +// CreatedAtGT applies the GT predicate on the "created_at" field. +func CreatedAtGT(v time.Time) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldGT(FieldCreatedAt, v)) +} + +// CreatedAtGTE applies the GTE predicate on the "created_at" field. +func CreatedAtGTE(v time.Time) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldGTE(FieldCreatedAt, v)) +} + +// CreatedAtLT applies the LT predicate on the "created_at" field. +func CreatedAtLT(v time.Time) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldLT(FieldCreatedAt, v)) +} + +// CreatedAtLTE applies the LTE predicate on the "created_at" field. +func CreatedAtLTE(v time.Time) predicate.AgvPoint { + return predicate.AgvPoint(sql.FieldLTE(FieldCreatedAt, v)) +} + +// And groups predicates with the AND operator between them. +func And(predicates ...predicate.AgvPoint) predicate.AgvPoint { + return predicate.AgvPoint(sql.AndPredicates(predicates...)) +} + +// Or groups predicates with the OR operator between them. +func Or(predicates ...predicate.AgvPoint) predicate.AgvPoint { + return predicate.AgvPoint(sql.OrPredicates(predicates...)) +} + +// Not applies the not operator on the given predicate. +func Not(p predicate.AgvPoint) predicate.AgvPoint { + return predicate.AgvPoint(sql.NotPredicates(p)) +} diff --git a/bj_power_mes/ent/agvpoint_create.go b/bj_power_mes/ent/agvpoint_create.go new file mode 100644 index 0000000..a09c9cf --- /dev/null +++ b/bj_power_mes/ent/agvpoint_create.go @@ -0,0 +1,318 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/agvpoint" + "context" + "errors" + "fmt" + "time" + + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// AgvPointCreate is the builder for creating a AgvPoint entity. +type AgvPointCreate struct { + config + mutation *AgvPointMutation + hooks []Hook +} + +// SetPositionCode sets the "position_code" field. +func (_c *AgvPointCreate) SetPositionCode(v string) *AgvPointCreate { + _c.mutation.SetPositionCode(v) + return _c +} + +// SetName sets the "name" field. +func (_c *AgvPointCreate) SetName(v string) *AgvPointCreate { + _c.mutation.SetName(v) + return _c +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_c *AgvPointCreate) SetNillableName(v *string) *AgvPointCreate { + if v != nil { + _c.SetName(*v) + } + return _c +} + +// SetIsDock sets the "is_dock" field. +func (_c *AgvPointCreate) SetIsDock(v bool) *AgvPointCreate { + _c.mutation.SetIsDock(v) + return _c +} + +// SetNillableIsDock sets the "is_dock" field if the given value is not nil. +func (_c *AgvPointCreate) SetNillableIsDock(v *bool) *AgvPointCreate { + if v != nil { + _c.SetIsDock(*v) + } + return _c +} + +// SetDockID sets the "dock_id" field. +func (_c *AgvPointCreate) SetDockID(v int) *AgvPointCreate { + _c.mutation.SetDockID(v) + return _c +} + +// SetNillableDockID sets the "dock_id" field if the given value is not nil. +func (_c *AgvPointCreate) SetNillableDockID(v *int) *AgvPointCreate { + if v != nil { + _c.SetDockID(*v) + } + return _c +} + +// SetEnabled sets the "enabled" field. +func (_c *AgvPointCreate) SetEnabled(v bool) *AgvPointCreate { + _c.mutation.SetEnabled(v) + return _c +} + +// SetNillableEnabled sets the "enabled" field if the given value is not nil. +func (_c *AgvPointCreate) SetNillableEnabled(v *bool) *AgvPointCreate { + if v != nil { + _c.SetEnabled(*v) + } + return _c +} + +// SetCreatedAt sets the "created_at" field. +func (_c *AgvPointCreate) SetCreatedAt(v time.Time) *AgvPointCreate { + _c.mutation.SetCreatedAt(v) + return _c +} + +// SetNillableCreatedAt sets the "created_at" field if the given value is not nil. +func (_c *AgvPointCreate) SetNillableCreatedAt(v *time.Time) *AgvPointCreate { + if v != nil { + _c.SetCreatedAt(*v) + } + return _c +} + +// Mutation returns the AgvPointMutation object of the builder. +func (_c *AgvPointCreate) Mutation() *AgvPointMutation { + return _c.mutation +} + +// Save creates the AgvPoint in the database. +func (_c *AgvPointCreate) Save(ctx context.Context) (*AgvPoint, error) { + _c.defaults() + return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks) +} + +// SaveX calls Save and panics if Save returns an error. +func (_c *AgvPointCreate) SaveX(ctx context.Context) *AgvPoint { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *AgvPointCreate) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *AgvPointCreate) 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 *AgvPointCreate) defaults() { + if _, ok := _c.mutation.Name(); !ok { + v := agvpoint.DefaultName + _c.mutation.SetName(v) + } + if _, ok := _c.mutation.IsDock(); !ok { + v := agvpoint.DefaultIsDock + _c.mutation.SetIsDock(v) + } + if _, ok := _c.mutation.Enabled(); !ok { + v := agvpoint.DefaultEnabled + _c.mutation.SetEnabled(v) + } + if _, ok := _c.mutation.CreatedAt(); !ok { + v := agvpoint.DefaultCreatedAt() + _c.mutation.SetCreatedAt(v) + } +} + +// check runs all checks and user-defined validators on the builder. +func (_c *AgvPointCreate) check() error { + if _, ok := _c.mutation.PositionCode(); !ok { + return &ValidationError{Name: "position_code", err: errors.New(`ent: missing required field "AgvPoint.position_code"`)} + } + if v, ok := _c.mutation.PositionCode(); ok { + if err := agvpoint.PositionCodeValidator(v); err != nil { + return &ValidationError{Name: "position_code", err: fmt.Errorf(`ent: validator failed for field "AgvPoint.position_code": %w`, err)} + } + } + if _, ok := _c.mutation.Name(); !ok { + return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "AgvPoint.name"`)} + } + if v, ok := _c.mutation.Name(); ok { + if err := agvpoint.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "AgvPoint.name": %w`, err)} + } + } + if _, ok := _c.mutation.IsDock(); !ok { + return &ValidationError{Name: "is_dock", err: errors.New(`ent: missing required field "AgvPoint.is_dock"`)} + } + if _, ok := _c.mutation.Enabled(); !ok { + return &ValidationError{Name: "enabled", err: errors.New(`ent: missing required field "AgvPoint.enabled"`)} + } + if _, ok := _c.mutation.CreatedAt(); !ok { + return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "AgvPoint.created_at"`)} + } + return nil +} + +func (_c *AgvPointCreate) sqlSave(ctx context.Context) (*AgvPoint, 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 + } + id := _spec.ID.Value.(int64) + _node.ID = int(id) + _c.mutation.id = &_node.ID + _c.mutation.done = true + return _node, nil +} + +func (_c *AgvPointCreate) createSpec() (*AgvPoint, *sqlgraph.CreateSpec) { + var ( + _node = &AgvPoint{config: _c.config} + _spec = sqlgraph.NewCreateSpec(agvpoint.Table, sqlgraph.NewFieldSpec(agvpoint.FieldID, field.TypeInt)) + ) + if value, ok := _c.mutation.PositionCode(); ok { + _spec.SetField(agvpoint.FieldPositionCode, field.TypeString, value) + _node.PositionCode = value + } + if value, ok := _c.mutation.Name(); ok { + _spec.SetField(agvpoint.FieldName, field.TypeString, value) + _node.Name = value + } + if value, ok := _c.mutation.IsDock(); ok { + _spec.SetField(agvpoint.FieldIsDock, field.TypeBool, value) + _node.IsDock = value + } + if value, ok := _c.mutation.DockID(); ok { + _spec.SetField(agvpoint.FieldDockID, field.TypeInt, value) + _node.DockID = &value + } + if value, ok := _c.mutation.Enabled(); ok { + _spec.SetField(agvpoint.FieldEnabled, field.TypeBool, value) + _node.Enabled = value + } + if value, ok := _c.mutation.CreatedAt(); ok { + _spec.SetField(agvpoint.FieldCreatedAt, field.TypeTime, value) + _node.CreatedAt = value + } + return _node, _spec +} + +// AgvPointCreateBulk is the builder for creating many AgvPoint entities in bulk. +type AgvPointCreateBulk struct { + config + err error + builders []*AgvPointCreate +} + +// Save creates the AgvPoint entities in the database. +func (_c *AgvPointCreateBulk) Save(ctx context.Context) ([]*AgvPoint, error) { + if _c.err != nil { + return nil, _c.err + } + specs := make([]*sqlgraph.CreateSpec, len(_c.builders)) + nodes := make([]*AgvPoint, 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.(*AgvPointMutation) + 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 { + 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 *AgvPointCreateBulk) SaveX(ctx context.Context) []*AgvPoint { + v, err := _c.Save(ctx) + if err != nil { + panic(err) + } + return v +} + +// Exec executes the query. +func (_c *AgvPointCreateBulk) Exec(ctx context.Context) error { + _, err := _c.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_c *AgvPointCreateBulk) ExecX(ctx context.Context) { + if err := _c.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/bj_power_mes/ent/agvpoint_delete.go b/bj_power_mes/ent/agvpoint_delete.go new file mode 100644 index 0000000..e273072 --- /dev/null +++ b/bj_power_mes/ent/agvpoint_delete.go @@ -0,0 +1,88 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/agvpoint" + "bj_power_mes/ent/predicate" + "context" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// AgvPointDelete is the builder for deleting a AgvPoint entity. +type AgvPointDelete struct { + config + hooks []Hook + mutation *AgvPointMutation +} + +// Where appends a list predicates to the AgvPointDelete builder. +func (_d *AgvPointDelete) Where(ps ...predicate.AgvPoint) *AgvPointDelete { + _d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query and returns how many vertices were deleted. +func (_d *AgvPointDelete) Exec(ctx context.Context) (int, error) { + return withHooks(ctx, _d.sqlExec, _d.mutation, _d.hooks) +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *AgvPointDelete) ExecX(ctx context.Context) int { + n, err := _d.Exec(ctx) + if err != nil { + panic(err) + } + return n +} + +func (_d *AgvPointDelete) sqlExec(ctx context.Context) (int, error) { + _spec := sqlgraph.NewDeleteSpec(agvpoint.Table, sqlgraph.NewFieldSpec(agvpoint.FieldID, field.TypeInt)) + if ps := _d.mutation.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + affected, err := sqlgraph.DeleteNodes(ctx, _d.driver, _spec) + if err != nil && sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + _d.mutation.done = true + return affected, err +} + +// AgvPointDeleteOne is the builder for deleting a single AgvPoint entity. +type AgvPointDeleteOne struct { + _d *AgvPointDelete +} + +// Where appends a list predicates to the AgvPointDelete builder. +func (_d *AgvPointDeleteOne) Where(ps ...predicate.AgvPoint) *AgvPointDeleteOne { + _d._d.mutation.Where(ps...) + return _d +} + +// Exec executes the deletion query. +func (_d *AgvPointDeleteOne) Exec(ctx context.Context) error { + n, err := _d._d.Exec(ctx) + switch { + case err != nil: + return err + case n == 0: + return &NotFoundError{agvpoint.Label} + default: + return nil + } +} + +// ExecX is like Exec, but panics if an error occurs. +func (_d *AgvPointDeleteOne) ExecX(ctx context.Context) { + if err := _d.Exec(ctx); err != nil { + panic(err) + } +} diff --git a/bj_power_mes/ent/agvpoint_query.go b/bj_power_mes/ent/agvpoint_query.go new file mode 100644 index 0000000..0e2714c --- /dev/null +++ b/bj_power_mes/ent/agvpoint_query.go @@ -0,0 +1,577 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/agvpoint" + "bj_power_mes/ent/predicate" + "context" + "fmt" + "math" + + "entgo.io/ent" + "entgo.io/ent/dialect" + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// AgvPointQuery is the builder for querying AgvPoint entities. +type AgvPointQuery struct { + config + ctx *QueryContext + order []agvpoint.OrderOption + inters []Interceptor + predicates []predicate.AgvPoint + modifiers []func(*sql.Selector) + // intermediate query (i.e. traversal path). + sql *sql.Selector + path func(context.Context) (*sql.Selector, error) +} + +// Where adds a new predicate for the AgvPointQuery builder. +func (_q *AgvPointQuery) Where(ps ...predicate.AgvPoint) *AgvPointQuery { + _q.predicates = append(_q.predicates, ps...) + return _q +} + +// Limit the number of records to be returned by this query. +func (_q *AgvPointQuery) Limit(limit int) *AgvPointQuery { + _q.ctx.Limit = &limit + return _q +} + +// Offset to start from. +func (_q *AgvPointQuery) Offset(offset int) *AgvPointQuery { + _q.ctx.Offset = &offset + return _q +} + +// Unique configures the query builder to filter duplicate records on query. +// By default, unique is set to true, and can be disabled using this method. +func (_q *AgvPointQuery) Unique(unique bool) *AgvPointQuery { + _q.ctx.Unique = &unique + return _q +} + +// Order specifies how the records should be ordered. +func (_q *AgvPointQuery) Order(o ...agvpoint.OrderOption) *AgvPointQuery { + _q.order = append(_q.order, o...) + return _q +} + +// First returns the first AgvPoint entity from the query. +// Returns a *NotFoundError when no AgvPoint was found. +func (_q *AgvPointQuery) First(ctx context.Context) (*AgvPoint, error) { + nodes, err := _q.Limit(1).All(setContextOp(ctx, _q.ctx, ent.OpQueryFirst)) + if err != nil { + return nil, err + } + if len(nodes) == 0 { + return nil, &NotFoundError{agvpoint.Label} + } + return nodes[0], nil +} + +// FirstX is like First, but panics if an error occurs. +func (_q *AgvPointQuery) FirstX(ctx context.Context) *AgvPoint { + node, err := _q.First(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return node +} + +// FirstID returns the first AgvPoint ID from the query. +// Returns a *NotFoundError when no AgvPoint ID was found. +func (_q *AgvPointQuery) FirstID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = _q.Limit(1).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryFirstID)); err != nil { + return + } + if len(ids) == 0 { + err = &NotFoundError{agvpoint.Label} + return + } + return ids[0], nil +} + +// FirstIDX is like FirstID, but panics if an error occurs. +func (_q *AgvPointQuery) FirstIDX(ctx context.Context) int { + id, err := _q.FirstID(ctx) + if err != nil && !IsNotFound(err) { + panic(err) + } + return id +} + +// Only returns a single AgvPoint entity found by the query, ensuring it only returns one. +// Returns a *NotSingularError when more than one AgvPoint entity is found. +// Returns a *NotFoundError when no AgvPoint entities are found. +func (_q *AgvPointQuery) Only(ctx context.Context) (*AgvPoint, error) { + nodes, err := _q.Limit(2).All(setContextOp(ctx, _q.ctx, ent.OpQueryOnly)) + if err != nil { + return nil, err + } + switch len(nodes) { + case 1: + return nodes[0], nil + case 0: + return nil, &NotFoundError{agvpoint.Label} + default: + return nil, &NotSingularError{agvpoint.Label} + } +} + +// OnlyX is like Only, but panics if an error occurs. +func (_q *AgvPointQuery) OnlyX(ctx context.Context) *AgvPoint { + node, err := _q.Only(ctx) + if err != nil { + panic(err) + } + return node +} + +// OnlyID is like Only, but returns the only AgvPoint ID in the query. +// Returns a *NotSingularError when more than one AgvPoint ID is found. +// Returns a *NotFoundError when no entities are found. +func (_q *AgvPointQuery) OnlyID(ctx context.Context) (id int, err error) { + var ids []int + if ids, err = _q.Limit(2).IDs(setContextOp(ctx, _q.ctx, ent.OpQueryOnlyID)); err != nil { + return + } + switch len(ids) { + case 1: + id = ids[0] + case 0: + err = &NotFoundError{agvpoint.Label} + default: + err = &NotSingularError{agvpoint.Label} + } + return +} + +// OnlyIDX is like OnlyID, but panics if an error occurs. +func (_q *AgvPointQuery) OnlyIDX(ctx context.Context) int { + id, err := _q.OnlyID(ctx) + if err != nil { + panic(err) + } + return id +} + +// All executes the query and returns a list of AgvPoints. +func (_q *AgvPointQuery) All(ctx context.Context) ([]*AgvPoint, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryAll) + if err := _q.prepareQuery(ctx); err != nil { + return nil, err + } + qr := querierAll[[]*AgvPoint, *AgvPointQuery]() + return withInterceptors[[]*AgvPoint](ctx, _q, qr, _q.inters) +} + +// AllX is like All, but panics if an error occurs. +func (_q *AgvPointQuery) AllX(ctx context.Context) []*AgvPoint { + nodes, err := _q.All(ctx) + if err != nil { + panic(err) + } + return nodes +} + +// IDs executes the query and returns a list of AgvPoint IDs. +func (_q *AgvPointQuery) IDs(ctx context.Context) (ids []int, err error) { + if _q.ctx.Unique == nil && _q.path != nil { + _q.Unique(true) + } + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryIDs) + if err = _q.Select(agvpoint.FieldID).Scan(ctx, &ids); err != nil { + return nil, err + } + return ids, nil +} + +// IDsX is like IDs, but panics if an error occurs. +func (_q *AgvPointQuery) IDsX(ctx context.Context) []int { + ids, err := _q.IDs(ctx) + if err != nil { + panic(err) + } + return ids +} + +// Count returns the count of the given query. +func (_q *AgvPointQuery) Count(ctx context.Context) (int, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryCount) + if err := _q.prepareQuery(ctx); err != nil { + return 0, err + } + return withInterceptors[int](ctx, _q, querierCount[*AgvPointQuery](), _q.inters) +} + +// CountX is like Count, but panics if an error occurs. +func (_q *AgvPointQuery) CountX(ctx context.Context) int { + count, err := _q.Count(ctx) + if err != nil { + panic(err) + } + return count +} + +// Exist returns true if the query has elements in the graph. +func (_q *AgvPointQuery) Exist(ctx context.Context) (bool, error) { + ctx = setContextOp(ctx, _q.ctx, ent.OpQueryExist) + switch _, err := _q.FirstID(ctx); { + case IsNotFound(err): + return false, nil + case err != nil: + return false, fmt.Errorf("ent: check existence: %w", err) + default: + return true, nil + } +} + +// ExistX is like Exist, but panics if an error occurs. +func (_q *AgvPointQuery) ExistX(ctx context.Context) bool { + exist, err := _q.Exist(ctx) + if err != nil { + panic(err) + } + return exist +} + +// Clone returns a duplicate of the AgvPointQuery builder, including all associated steps. It can be +// used to prepare common query builders and use them differently after the clone is made. +func (_q *AgvPointQuery) Clone() *AgvPointQuery { + if _q == nil { + return nil + } + return &AgvPointQuery{ + config: _q.config, + ctx: _q.ctx.Clone(), + order: append([]agvpoint.OrderOption{}, _q.order...), + inters: append([]Interceptor{}, _q.inters...), + predicates: append([]predicate.AgvPoint{}, _q.predicates...), + // clone intermediate query. + sql: _q.sql.Clone(), + path: _q.path, + modifiers: append([]func(*sql.Selector){}, _q.modifiers...), + } +} + +// GroupBy is used to group vertices by one or more fields/columns. +// It is often used with aggregate functions, like: count, max, mean, min, sum. +// +// Example: +// +// var v []struct { +// PositionCode string `json:"position_code,omitempty"` +// Count int `json:"count,omitempty"` +// } +// +// client.AgvPoint.Query(). +// GroupBy(agvpoint.FieldPositionCode). +// Aggregate(ent.Count()). +// Scan(ctx, &v) +func (_q *AgvPointQuery) GroupBy(field string, fields ...string) *AgvPointGroupBy { + _q.ctx.Fields = append([]string{field}, fields...) + grbuild := &AgvPointGroupBy{build: _q} + grbuild.flds = &_q.ctx.Fields + grbuild.label = agvpoint.Label + grbuild.scan = grbuild.Scan + return grbuild +} + +// Select allows the selection one or more fields/columns for the given query, +// instead of selecting all fields in the entity. +// +// Example: +// +// var v []struct { +// PositionCode string `json:"position_code,omitempty"` +// } +// +// client.AgvPoint.Query(). +// Select(agvpoint.FieldPositionCode). +// Scan(ctx, &v) +func (_q *AgvPointQuery) Select(fields ...string) *AgvPointSelect { + _q.ctx.Fields = append(_q.ctx.Fields, fields...) + sbuild := &AgvPointSelect{AgvPointQuery: _q} + sbuild.label = agvpoint.Label + sbuild.flds, sbuild.scan = &_q.ctx.Fields, sbuild.Scan + return sbuild +} + +// Aggregate returns a AgvPointSelect configured with the given aggregations. +func (_q *AgvPointQuery) Aggregate(fns ...AggregateFunc) *AgvPointSelect { + return _q.Select().Aggregate(fns...) +} + +func (_q *AgvPointQuery) prepareQuery(ctx context.Context) error { + for _, inter := range _q.inters { + if inter == nil { + return fmt.Errorf("ent: uninitialized interceptor (forgotten import ent/runtime?)") + } + if trv, ok := inter.(Traverser); ok { + if err := trv.Traverse(ctx, _q); err != nil { + return err + } + } + } + for _, f := range _q.ctx.Fields { + if !agvpoint.ValidColumn(f) { + return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + } + if _q.path != nil { + prev, err := _q.path(ctx) + if err != nil { + return err + } + _q.sql = prev + } + return nil +} + +func (_q *AgvPointQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*AgvPoint, error) { + var ( + nodes = []*AgvPoint{} + _spec = _q.querySpec() + ) + _spec.ScanValues = func(columns []string) ([]any, error) { + return (*AgvPoint).scanValues(nil, columns) + } + _spec.Assign = func(columns []string, values []any) error { + node := &AgvPoint{config: _q.config} + nodes = append(nodes, node) + return node.assignValues(columns, values) + } + if len(_q.modifiers) > 0 { + _spec.Modifiers = _q.modifiers + } + for i := range hooks { + hooks[i](ctx, _spec) + } + if err := sqlgraph.QueryNodes(ctx, _q.driver, _spec); err != nil { + return nil, err + } + if len(nodes) == 0 { + return nodes, nil + } + return nodes, nil +} + +func (_q *AgvPointQuery) sqlCount(ctx context.Context) (int, error) { + _spec := _q.querySpec() + if len(_q.modifiers) > 0 { + _spec.Modifiers = _q.modifiers + } + _spec.Node.Columns = _q.ctx.Fields + if len(_q.ctx.Fields) > 0 { + _spec.Unique = _q.ctx.Unique != nil && *_q.ctx.Unique + } + return sqlgraph.CountNodes(ctx, _q.driver, _spec) +} + +func (_q *AgvPointQuery) querySpec() *sqlgraph.QuerySpec { + _spec := sqlgraph.NewQuerySpec(agvpoint.Table, agvpoint.Columns, sqlgraph.NewFieldSpec(agvpoint.FieldID, field.TypeInt)) + _spec.From = _q.sql + if unique := _q.ctx.Unique; unique != nil { + _spec.Unique = *unique + } else if _q.path != nil { + _spec.Unique = true + } + if fields := _q.ctx.Fields; len(fields) > 0 { + _spec.Node.Columns = make([]string, 0, len(fields)) + _spec.Node.Columns = append(_spec.Node.Columns, agvpoint.FieldID) + for i := range fields { + if fields[i] != agvpoint.FieldID { + _spec.Node.Columns = append(_spec.Node.Columns, fields[i]) + } + } + } + if ps := _q.predicates; len(ps) > 0 { + _spec.Predicate = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + if limit := _q.ctx.Limit; limit != nil { + _spec.Limit = *limit + } + if offset := _q.ctx.Offset; offset != nil { + _spec.Offset = *offset + } + if ps := _q.order; len(ps) > 0 { + _spec.Order = func(selector *sql.Selector) { + for i := range ps { + ps[i](selector) + } + } + } + return _spec +} + +func (_q *AgvPointQuery) sqlQuery(ctx context.Context) *sql.Selector { + builder := sql.Dialect(_q.driver.Dialect()) + t1 := builder.Table(agvpoint.Table) + columns := _q.ctx.Fields + if len(columns) == 0 { + columns = agvpoint.Columns + } + selector := builder.Select(t1.Columns(columns...)...).From(t1) + if _q.sql != nil { + selector = _q.sql + selector.Select(selector.Columns(columns...)...) + } + if _q.ctx.Unique != nil && *_q.ctx.Unique { + selector.Distinct() + } + for _, m := range _q.modifiers { + m(selector) + } + for _, p := range _q.predicates { + p(selector) + } + for _, p := range _q.order { + p(selector) + } + if offset := _q.ctx.Offset; offset != nil { + // limit is mandatory for offset clause. We start + // with default value, and override it below if needed. + selector.Offset(*offset).Limit(math.MaxInt32) + } + if limit := _q.ctx.Limit; limit != nil { + selector.Limit(*limit) + } + return selector +} + +// ForUpdate locks the selected rows against concurrent updates, and prevent them from being +// updated, deleted or "selected ... for update" by other sessions, until the transaction is +// either committed or rolled-back. +func (_q *AgvPointQuery) ForUpdate(opts ...sql.LockOption) *AgvPointQuery { + if _q.driver.Dialect() == dialect.Postgres { + _q.Unique(false) + } + _q.modifiers = append(_q.modifiers, func(s *sql.Selector) { + s.ForUpdate(opts...) + }) + return _q +} + +// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock +// on any rows that are read. Other sessions can read the rows, but cannot modify them +// until your transaction commits. +func (_q *AgvPointQuery) ForShare(opts ...sql.LockOption) *AgvPointQuery { + if _q.driver.Dialect() == dialect.Postgres { + _q.Unique(false) + } + _q.modifiers = append(_q.modifiers, func(s *sql.Selector) { + s.ForShare(opts...) + }) + return _q +} + +// Modify adds a query modifier for attaching custom logic to queries. +func (_q *AgvPointQuery) Modify(modifiers ...func(s *sql.Selector)) *AgvPointSelect { + _q.modifiers = append(_q.modifiers, modifiers...) + return _q.Select() +} + +// AgvPointGroupBy is the group-by builder for AgvPoint entities. +type AgvPointGroupBy struct { + selector + build *AgvPointQuery +} + +// Aggregate adds the given aggregation functions to the group-by query. +func (_g *AgvPointGroupBy) Aggregate(fns ...AggregateFunc) *AgvPointGroupBy { + _g.fns = append(_g.fns, fns...) + return _g +} + +// Scan applies the selector query and scans the result into the given value. +func (_g *AgvPointGroupBy) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _g.build.ctx, ent.OpQueryGroupBy) + if err := _g.build.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*AgvPointQuery, *AgvPointGroupBy](ctx, _g.build, _g, _g.build.inters, v) +} + +func (_g *AgvPointGroupBy) sqlScan(ctx context.Context, root *AgvPointQuery, v any) error { + selector := root.sqlQuery(ctx).Select() + aggregation := make([]string, 0, len(_g.fns)) + for _, fn := range _g.fns { + aggregation = append(aggregation, fn(selector)) + } + if len(selector.SelectedColumns()) == 0 { + columns := make([]string, 0, len(*_g.flds)+len(_g.fns)) + for _, f := range *_g.flds { + columns = append(columns, selector.C(f)) + } + columns = append(columns, aggregation...) + selector.Select(columns...) + } + selector.GroupBy(selector.Columns(*_g.flds...)...) + if err := selector.Err(); err != nil { + return err + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _g.build.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// AgvPointSelect is the builder for selecting fields of AgvPoint entities. +type AgvPointSelect struct { + *AgvPointQuery + selector +} + +// Aggregate adds the given aggregation functions to the selector query. +func (_s *AgvPointSelect) Aggregate(fns ...AggregateFunc) *AgvPointSelect { + _s.fns = append(_s.fns, fns...) + return _s +} + +// Scan applies the selector query and scans the result into the given value. +func (_s *AgvPointSelect) Scan(ctx context.Context, v any) error { + ctx = setContextOp(ctx, _s.ctx, ent.OpQuerySelect) + if err := _s.prepareQuery(ctx); err != nil { + return err + } + return scanWithInterceptors[*AgvPointQuery, *AgvPointSelect](ctx, _s.AgvPointQuery, _s, _s.inters, v) +} + +func (_s *AgvPointSelect) sqlScan(ctx context.Context, root *AgvPointQuery, v any) error { + selector := root.sqlQuery(ctx) + aggregation := make([]string, 0, len(_s.fns)) + for _, fn := range _s.fns { + aggregation = append(aggregation, fn(selector)) + } + switch n := len(*_s.selector.flds); { + case n == 0 && len(aggregation) > 0: + selector.Select(aggregation...) + case n != 0 && len(aggregation) > 0: + selector.AppendSelect(aggregation...) + } + rows := &sql.Rows{} + query, args := selector.Query() + if err := _s.driver.Query(ctx, query, args, rows); err != nil { + return err + } + defer rows.Close() + return sql.ScanSlice(rows, v) +} + +// Modify adds a query modifier for attaching custom logic to queries. +func (_s *AgvPointSelect) Modify(modifiers ...func(s *sql.Selector)) *AgvPointSelect { + _s.modifiers = append(_s.modifiers, modifiers...) + return _s +} diff --git a/bj_power_mes/ent/agvpoint_update.go b/bj_power_mes/ent/agvpoint_update.go new file mode 100644 index 0000000..572fe8d --- /dev/null +++ b/bj_power_mes/ent/agvpoint_update.go @@ -0,0 +1,435 @@ +// Code generated by ent, DO NOT EDIT. + +package ent + +import ( + "bj_power_mes/ent/agvpoint" + "bj_power_mes/ent/predicate" + "context" + "errors" + "fmt" + + "entgo.io/ent/dialect/sql" + "entgo.io/ent/dialect/sql/sqlgraph" + "entgo.io/ent/schema/field" +) + +// AgvPointUpdate is the builder for updating AgvPoint entities. +type AgvPointUpdate struct { + config + hooks []Hook + mutation *AgvPointMutation + modifiers []func(*sql.UpdateBuilder) +} + +// Where appends a list predicates to the AgvPointUpdate builder. +func (_u *AgvPointUpdate) Where(ps ...predicate.AgvPoint) *AgvPointUpdate { + _u.mutation.Where(ps...) + return _u +} + +// SetPositionCode sets the "position_code" field. +func (_u *AgvPointUpdate) SetPositionCode(v string) *AgvPointUpdate { + _u.mutation.SetPositionCode(v) + return _u +} + +// SetNillablePositionCode sets the "position_code" field if the given value is not nil. +func (_u *AgvPointUpdate) SetNillablePositionCode(v *string) *AgvPointUpdate { + if v != nil { + _u.SetPositionCode(*v) + } + return _u +} + +// SetName sets the "name" field. +func (_u *AgvPointUpdate) SetName(v string) *AgvPointUpdate { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *AgvPointUpdate) SetNillableName(v *string) *AgvPointUpdate { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetIsDock sets the "is_dock" field. +func (_u *AgvPointUpdate) SetIsDock(v bool) *AgvPointUpdate { + _u.mutation.SetIsDock(v) + return _u +} + +// SetNillableIsDock sets the "is_dock" field if the given value is not nil. +func (_u *AgvPointUpdate) SetNillableIsDock(v *bool) *AgvPointUpdate { + if v != nil { + _u.SetIsDock(*v) + } + return _u +} + +// SetDockID sets the "dock_id" field. +func (_u *AgvPointUpdate) SetDockID(v int) *AgvPointUpdate { + _u.mutation.ResetDockID() + _u.mutation.SetDockID(v) + return _u +} + +// SetNillableDockID sets the "dock_id" field if the given value is not nil. +func (_u *AgvPointUpdate) SetNillableDockID(v *int) *AgvPointUpdate { + if v != nil { + _u.SetDockID(*v) + } + return _u +} + +// AddDockID adds value to the "dock_id" field. +func (_u *AgvPointUpdate) AddDockID(v int) *AgvPointUpdate { + _u.mutation.AddDockID(v) + return _u +} + +// ClearDockID clears the value of the "dock_id" field. +func (_u *AgvPointUpdate) ClearDockID() *AgvPointUpdate { + _u.mutation.ClearDockID() + return _u +} + +// SetEnabled sets the "enabled" field. +func (_u *AgvPointUpdate) SetEnabled(v bool) *AgvPointUpdate { + _u.mutation.SetEnabled(v) + return _u +} + +// SetNillableEnabled sets the "enabled" field if the given value is not nil. +func (_u *AgvPointUpdate) SetNillableEnabled(v *bool) *AgvPointUpdate { + if v != nil { + _u.SetEnabled(*v) + } + return _u +} + +// Mutation returns the AgvPointMutation object of the builder. +func (_u *AgvPointUpdate) Mutation() *AgvPointMutation { + return _u.mutation +} + +// Save executes the query and returns the number of nodes affected by the update operation. +func (_u *AgvPointUpdate) 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 *AgvPointUpdate) SaveX(ctx context.Context) int { + affected, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return affected +} + +// Exec executes the query. +func (_u *AgvPointUpdate) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *AgvPointUpdate) 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 *AgvPointUpdate) check() error { + if v, ok := _u.mutation.PositionCode(); ok { + if err := agvpoint.PositionCodeValidator(v); err != nil { + return &ValidationError{Name: "position_code", err: fmt.Errorf(`ent: validator failed for field "AgvPoint.position_code": %w`, err)} + } + } + if v, ok := _u.mutation.Name(); ok { + if err := agvpoint.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "AgvPoint.name": %w`, err)} + } + } + return nil +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (_u *AgvPointUpdate) Modify(modifiers ...func(u *sql.UpdateBuilder)) *AgvPointUpdate { + _u.modifiers = append(_u.modifiers, modifiers...) + return _u +} + +func (_u *AgvPointUpdate) sqlSave(ctx context.Context) (_node int, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(agvpoint.Table, agvpoint.Columns, sqlgraph.NewFieldSpec(agvpoint.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.PositionCode(); ok { + _spec.SetField(agvpoint.FieldPositionCode, field.TypeString, value) + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(agvpoint.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.IsDock(); ok { + _spec.SetField(agvpoint.FieldIsDock, field.TypeBool, value) + } + if value, ok := _u.mutation.DockID(); ok { + _spec.SetField(agvpoint.FieldDockID, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedDockID(); ok { + _spec.AddField(agvpoint.FieldDockID, field.TypeInt, value) + } + if _u.mutation.DockIDCleared() { + _spec.ClearField(agvpoint.FieldDockID, field.TypeInt) + } + if value, ok := _u.mutation.Enabled(); ok { + _spec.SetField(agvpoint.FieldEnabled, field.TypeBool, value) + } + _spec.AddModifiers(_u.modifiers...) + if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil { + if _, ok := err.(*sqlgraph.NotFoundError); ok { + err = &NotFoundError{agvpoint.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return 0, err + } + _u.mutation.done = true + return _node, nil +} + +// AgvPointUpdateOne is the builder for updating a single AgvPoint entity. +type AgvPointUpdateOne struct { + config + fields []string + hooks []Hook + mutation *AgvPointMutation + modifiers []func(*sql.UpdateBuilder) +} + +// SetPositionCode sets the "position_code" field. +func (_u *AgvPointUpdateOne) SetPositionCode(v string) *AgvPointUpdateOne { + _u.mutation.SetPositionCode(v) + return _u +} + +// SetNillablePositionCode sets the "position_code" field if the given value is not nil. +func (_u *AgvPointUpdateOne) SetNillablePositionCode(v *string) *AgvPointUpdateOne { + if v != nil { + _u.SetPositionCode(*v) + } + return _u +} + +// SetName sets the "name" field. +func (_u *AgvPointUpdateOne) SetName(v string) *AgvPointUpdateOne { + _u.mutation.SetName(v) + return _u +} + +// SetNillableName sets the "name" field if the given value is not nil. +func (_u *AgvPointUpdateOne) SetNillableName(v *string) *AgvPointUpdateOne { + if v != nil { + _u.SetName(*v) + } + return _u +} + +// SetIsDock sets the "is_dock" field. +func (_u *AgvPointUpdateOne) SetIsDock(v bool) *AgvPointUpdateOne { + _u.mutation.SetIsDock(v) + return _u +} + +// SetNillableIsDock sets the "is_dock" field if the given value is not nil. +func (_u *AgvPointUpdateOne) SetNillableIsDock(v *bool) *AgvPointUpdateOne { + if v != nil { + _u.SetIsDock(*v) + } + return _u +} + +// SetDockID sets the "dock_id" field. +func (_u *AgvPointUpdateOne) SetDockID(v int) *AgvPointUpdateOne { + _u.mutation.ResetDockID() + _u.mutation.SetDockID(v) + return _u +} + +// SetNillableDockID sets the "dock_id" field if the given value is not nil. +func (_u *AgvPointUpdateOne) SetNillableDockID(v *int) *AgvPointUpdateOne { + if v != nil { + _u.SetDockID(*v) + } + return _u +} + +// AddDockID adds value to the "dock_id" field. +func (_u *AgvPointUpdateOne) AddDockID(v int) *AgvPointUpdateOne { + _u.mutation.AddDockID(v) + return _u +} + +// ClearDockID clears the value of the "dock_id" field. +func (_u *AgvPointUpdateOne) ClearDockID() *AgvPointUpdateOne { + _u.mutation.ClearDockID() + return _u +} + +// SetEnabled sets the "enabled" field. +func (_u *AgvPointUpdateOne) SetEnabled(v bool) *AgvPointUpdateOne { + _u.mutation.SetEnabled(v) + return _u +} + +// SetNillableEnabled sets the "enabled" field if the given value is not nil. +func (_u *AgvPointUpdateOne) SetNillableEnabled(v *bool) *AgvPointUpdateOne { + if v != nil { + _u.SetEnabled(*v) + } + return _u +} + +// Mutation returns the AgvPointMutation object of the builder. +func (_u *AgvPointUpdateOne) Mutation() *AgvPointMutation { + return _u.mutation +} + +// Where appends a list predicates to the AgvPointUpdate builder. +func (_u *AgvPointUpdateOne) Where(ps ...predicate.AgvPoint) *AgvPointUpdateOne { + _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 *AgvPointUpdateOne) Select(field string, fields ...string) *AgvPointUpdateOne { + _u.fields = append([]string{field}, fields...) + return _u +} + +// Save executes the query and returns the updated AgvPoint entity. +func (_u *AgvPointUpdateOne) Save(ctx context.Context) (*AgvPoint, error) { + return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks) +} + +// SaveX is like Save, but panics if an error occurs. +func (_u *AgvPointUpdateOne) SaveX(ctx context.Context) *AgvPoint { + node, err := _u.Save(ctx) + if err != nil { + panic(err) + } + return node +} + +// Exec executes the query on the entity. +func (_u *AgvPointUpdateOne) Exec(ctx context.Context) error { + _, err := _u.Save(ctx) + return err +} + +// ExecX is like Exec, but panics if an error occurs. +func (_u *AgvPointUpdateOne) 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 *AgvPointUpdateOne) check() error { + if v, ok := _u.mutation.PositionCode(); ok { + if err := agvpoint.PositionCodeValidator(v); err != nil { + return &ValidationError{Name: "position_code", err: fmt.Errorf(`ent: validator failed for field "AgvPoint.position_code": %w`, err)} + } + } + if v, ok := _u.mutation.Name(); ok { + if err := agvpoint.NameValidator(v); err != nil { + return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "AgvPoint.name": %w`, err)} + } + } + return nil +} + +// Modify adds a statement modifier for attaching custom logic to the UPDATE statement. +func (_u *AgvPointUpdateOne) Modify(modifiers ...func(u *sql.UpdateBuilder)) *AgvPointUpdateOne { + _u.modifiers = append(_u.modifiers, modifiers...) + return _u +} + +func (_u *AgvPointUpdateOne) sqlSave(ctx context.Context) (_node *AgvPoint, err error) { + if err := _u.check(); err != nil { + return _node, err + } + _spec := sqlgraph.NewUpdateSpec(agvpoint.Table, agvpoint.Columns, sqlgraph.NewFieldSpec(agvpoint.FieldID, field.TypeInt)) + id, ok := _u.mutation.ID() + if !ok { + return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "AgvPoint.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, agvpoint.FieldID) + for _, f := range fields { + if !agvpoint.ValidColumn(f) { + return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)} + } + if f != agvpoint.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.PositionCode(); ok { + _spec.SetField(agvpoint.FieldPositionCode, field.TypeString, value) + } + if value, ok := _u.mutation.Name(); ok { + _spec.SetField(agvpoint.FieldName, field.TypeString, value) + } + if value, ok := _u.mutation.IsDock(); ok { + _spec.SetField(agvpoint.FieldIsDock, field.TypeBool, value) + } + if value, ok := _u.mutation.DockID(); ok { + _spec.SetField(agvpoint.FieldDockID, field.TypeInt, value) + } + if value, ok := _u.mutation.AddedDockID(); ok { + _spec.AddField(agvpoint.FieldDockID, field.TypeInt, value) + } + if _u.mutation.DockIDCleared() { + _spec.ClearField(agvpoint.FieldDockID, field.TypeInt) + } + if value, ok := _u.mutation.Enabled(); ok { + _spec.SetField(agvpoint.FieldEnabled, field.TypeBool, value) + } + _spec.AddModifiers(_u.modifiers...) + _node = &AgvPoint{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{agvpoint.Label} + } else if sqlgraph.IsConstraintError(err) { + err = &ConstraintError{msg: err.Error(), wrap: err} + } + return nil, err + } + _u.mutation.done = true + return _node, nil +} diff --git a/bj_power_mes/ent/client.go b/bj_power_mes/ent/client.go index 3a071cd..3d29f92 100644 --- a/bj_power_mes/ent/client.go +++ b/bj_power_mes/ent/client.go @@ -11,6 +11,7 @@ import ( "bj_power_mes/ent/migrate" + "bj_power_mes/ent/agvpoint" "bj_power_mes/ent/agvtask" "bj_power_mes/ent/alert" "bj_power_mes/ent/alertrule" @@ -53,6 +54,8 @@ import ( "entgo.io/ent" "entgo.io/ent/dialect" "entgo.io/ent/dialect/sql" + + stdsql "database/sql" ) // Client is the client that holds all ent builders. @@ -60,6 +63,8 @@ type Client struct { config // Schema is the client for creating, migrating and dropping schema. Schema *migrate.Schema + // AgvPoint is the client for interacting with the AgvPoint builders. + AgvPoint *AgvPointClient // AgvTask is the client for interacting with the AgvTask builders. AgvTask *AgvTaskClient // Alert is the client for interacting with the Alert builders. @@ -147,6 +152,7 @@ func NewClient(opts ...Option) *Client { func (c *Client) init() { c.Schema = migrate.NewSchema(c.driver) + c.AgvPoint = NewAgvPointClient(c.config) c.AgvTask = NewAgvTaskClient(c.config) c.Alert = NewAlertClient(c.config) c.AlertRule = NewAlertRuleClient(c.config) @@ -277,6 +283,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { return &Tx{ ctx: ctx, config: cfg, + AgvPoint: NewAgvPointClient(cfg), AgvTask: NewAgvTaskClient(cfg), Alert: NewAlertClient(cfg), AlertRule: NewAlertRuleClient(cfg), @@ -334,6 +341,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) return &Tx{ ctx: ctx, config: cfg, + AgvPoint: NewAgvPointClient(cfg), AgvTask: NewAgvTaskClient(cfg), Alert: NewAlertClient(cfg), AlertRule: NewAlertRuleClient(cfg), @@ -378,7 +386,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) // Debug returns a new debug-client. It's used to get verbose logging on specific operations. // // client.Debug(). -// AgvTask. +// AgvPoint. // Query(). // Count(ctx) func (c *Client) Debug() *Client { @@ -401,7 +409,7 @@ func (c *Client) Close() error { // In order to add hooks to a specific client, call: `client.Node.Use(...)`. func (c *Client) Use(hooks ...Hook) { for _, n := range []interface{ Use(...Hook) }{ - c.AgvTask, c.Alert, c.AlertRule, c.AssociationTrace, c.Attachment, + c.AgvPoint, c.AgvTask, c.Alert, c.AlertRule, c.AssociationTrace, c.Attachment, c.BackupRecord, c.CallPool, c.DailyPlan, c.Dock, c.EventLog, c.FlowMaterial, c.InspectionRecord, c.LinePoint, c.Material, c.MaterialQtyReport, c.MaterialRequest, c.Permission, c.PlcSendLog, c.ProcessFlow, c.ProcessStep, @@ -418,7 +426,7 @@ func (c *Client) Use(hooks ...Hook) { // In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`. func (c *Client) Intercept(interceptors ...Interceptor) { for _, n := range []interface{ Intercept(...Interceptor) }{ - c.AgvTask, c.Alert, c.AlertRule, c.AssociationTrace, c.Attachment, + c.AgvPoint, c.AgvTask, c.Alert, c.AlertRule, c.AssociationTrace, c.Attachment, c.BackupRecord, c.CallPool, c.DailyPlan, c.Dock, c.EventLog, c.FlowMaterial, c.InspectionRecord, c.LinePoint, c.Material, c.MaterialQtyReport, c.MaterialRequest, c.Permission, c.PlcSendLog, c.ProcessFlow, c.ProcessStep, @@ -434,6 +442,8 @@ func (c *Client) Intercept(interceptors ...Interceptor) { // Mutate implements the ent.Mutator interface. func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { switch m := m.(type) { + case *AgvPointMutation: + return c.AgvPoint.mutate(ctx, m) case *AgvTaskMutation: return c.AgvTask.mutate(ctx, m) case *AlertMutation: @@ -515,6 +525,139 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { } } +// AgvPointClient is a client for the AgvPoint schema. +type AgvPointClient struct { + config +} + +// NewAgvPointClient returns a client for the AgvPoint from the given config. +func NewAgvPointClient(c config) *AgvPointClient { + return &AgvPointClient{config: c} +} + +// Use adds a list of mutation hooks to the hooks stack. +// A call to `Use(f, g, h)` equals to `agvpoint.Hooks(f(g(h())))`. +func (c *AgvPointClient) Use(hooks ...Hook) { + c.hooks.AgvPoint = append(c.hooks.AgvPoint, hooks...) +} + +// Intercept adds a list of query interceptors to the interceptors stack. +// A call to `Intercept(f, g, h)` equals to `agvpoint.Intercept(f(g(h())))`. +func (c *AgvPointClient) Intercept(interceptors ...Interceptor) { + c.inters.AgvPoint = append(c.inters.AgvPoint, interceptors...) +} + +// Create returns a builder for creating a AgvPoint entity. +func (c *AgvPointClient) Create() *AgvPointCreate { + mutation := newAgvPointMutation(c.config, OpCreate) + return &AgvPointCreate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// CreateBulk returns a builder for creating a bulk of AgvPoint entities. +func (c *AgvPointClient) CreateBulk(builders ...*AgvPointCreate) *AgvPointCreateBulk { + return &AgvPointCreateBulk{config: c.config, builders: builders} +} + +// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates +// a builder and applies setFunc on it. +func (c *AgvPointClient) MapCreateBulk(slice any, setFunc func(*AgvPointCreate, int)) *AgvPointCreateBulk { + rv := reflect.ValueOf(slice) + if rv.Kind() != reflect.Slice { + return &AgvPointCreateBulk{err: fmt.Errorf("calling to AgvPointClient.MapCreateBulk with wrong type %T, need slice", slice)} + } + builders := make([]*AgvPointCreate, rv.Len()) + for i := 0; i < rv.Len(); i++ { + builders[i] = c.Create() + setFunc(builders[i], i) + } + return &AgvPointCreateBulk{config: c.config, builders: builders} +} + +// Update returns an update builder for AgvPoint. +func (c *AgvPointClient) Update() *AgvPointUpdate { + mutation := newAgvPointMutation(c.config, OpUpdate) + return &AgvPointUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOne returns an update builder for the given entity. +func (c *AgvPointClient) UpdateOne(_m *AgvPoint) *AgvPointUpdateOne { + mutation := newAgvPointMutation(c.config, OpUpdateOne, withAgvPoint(_m)) + return &AgvPointUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// UpdateOneID returns an update builder for the given id. +func (c *AgvPointClient) UpdateOneID(id int) *AgvPointUpdateOne { + mutation := newAgvPointMutation(c.config, OpUpdateOne, withAgvPointID(id)) + return &AgvPointUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// Delete returns a delete builder for AgvPoint. +func (c *AgvPointClient) Delete() *AgvPointDelete { + mutation := newAgvPointMutation(c.config, OpDelete) + return &AgvPointDelete{config: c.config, hooks: c.Hooks(), mutation: mutation} +} + +// DeleteOne returns a builder for deleting the given entity. +func (c *AgvPointClient) DeleteOne(_m *AgvPoint) *AgvPointDeleteOne { + return c.DeleteOneID(_m.ID) +} + +// DeleteOneID returns a builder for deleting the given entity by its id. +func (c *AgvPointClient) DeleteOneID(id int) *AgvPointDeleteOne { + builder := c.Delete().Where(agvpoint.ID(id)) + builder.mutation.id = &id + builder.mutation.op = OpDeleteOne + return &AgvPointDeleteOne{builder} +} + +// Query returns a query builder for AgvPoint. +func (c *AgvPointClient) Query() *AgvPointQuery { + return &AgvPointQuery{ + config: c.config, + ctx: &QueryContext{Type: TypeAgvPoint}, + inters: c.Interceptors(), + } +} + +// Get returns a AgvPoint entity by its id. +func (c *AgvPointClient) Get(ctx context.Context, id int) (*AgvPoint, error) { + return c.Query().Where(agvpoint.ID(id)).Only(ctx) +} + +// GetX is like Get, but panics if an error occurs. +func (c *AgvPointClient) GetX(ctx context.Context, id int) *AgvPoint { + obj, err := c.Get(ctx, id) + if err != nil { + panic(err) + } + return obj +} + +// Hooks returns the client hooks. +func (c *AgvPointClient) Hooks() []Hook { + return c.hooks.AgvPoint +} + +// Interceptors returns the client interceptors. +func (c *AgvPointClient) Interceptors() []Interceptor { + return c.inters.AgvPoint +} + +func (c *AgvPointClient) mutate(ctx context.Context, m *AgvPointMutation) (Value, error) { + switch m.Op() { + case OpCreate: + return (&AgvPointCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdate: + return (&AgvPointUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpUpdateOne: + return (&AgvPointUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx) + case OpDelete, OpDeleteOne: + return (&AgvPointDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx) + default: + return nil, fmt.Errorf("ent: unknown AgvPoint mutation op: %q", m.Op()) + } +} + // AgvTaskClient is a client for the AgvTask schema. type AgvTaskClient struct { config @@ -5572,21 +5715,45 @@ func (c *WorkpieceProcessClient) mutate(ctx context.Context, m *WorkpieceProcess // hooks and interceptors per client, for fast access. type ( hooks struct { - AgvTask, Alert, AlertRule, AssociationTrace, Attachment, BackupRecord, CallPool, - DailyPlan, Dock, EventLog, FlowMaterial, InspectionRecord, LinePoint, Material, - MaterialQtyReport, MaterialRequest, Permission, PlcSendLog, ProcessFlow, - ProcessStep, ProductProcess, ProductProcessItem, Role, SemiFlow, Station, - StationState, StepCriterion, StepData, StepSignRecord, SysConfig, TorqueRecord, - User, UserStation, WorkOrder, Workpiece, WorkpieceBind, WorkpieceLifecycleLog, - WorkpieceProcess []ent.Hook + AgvPoint, AgvTask, Alert, AlertRule, AssociationTrace, Attachment, BackupRecord, + CallPool, DailyPlan, Dock, EventLog, FlowMaterial, InspectionRecord, LinePoint, + Material, MaterialQtyReport, MaterialRequest, Permission, PlcSendLog, + ProcessFlow, ProcessStep, ProductProcess, ProductProcessItem, Role, SemiFlow, + Station, StationState, StepCriterion, StepData, StepSignRecord, SysConfig, + TorqueRecord, User, UserStation, WorkOrder, Workpiece, WorkpieceBind, + WorkpieceLifecycleLog, WorkpieceProcess []ent.Hook } inters struct { - AgvTask, Alert, AlertRule, AssociationTrace, Attachment, BackupRecord, CallPool, - DailyPlan, Dock, EventLog, FlowMaterial, InspectionRecord, LinePoint, Material, - MaterialQtyReport, MaterialRequest, Permission, PlcSendLog, ProcessFlow, - ProcessStep, ProductProcess, ProductProcessItem, Role, SemiFlow, Station, - StationState, StepCriterion, StepData, StepSignRecord, SysConfig, TorqueRecord, - User, UserStation, WorkOrder, Workpiece, WorkpieceBind, WorkpieceLifecycleLog, - WorkpieceProcess []ent.Interceptor + AgvPoint, AgvTask, Alert, AlertRule, AssociationTrace, Attachment, BackupRecord, + CallPool, DailyPlan, Dock, EventLog, FlowMaterial, InspectionRecord, LinePoint, + Material, MaterialQtyReport, MaterialRequest, Permission, PlcSendLog, + ProcessFlow, ProcessStep, ProductProcess, ProductProcessItem, Role, SemiFlow, + Station, StationState, StepCriterion, StepData, StepSignRecord, SysConfig, + TorqueRecord, User, UserStation, WorkOrder, Workpiece, WorkpieceBind, + WorkpieceLifecycleLog, WorkpieceProcess []ent.Interceptor } ) + +// ExecContext allows calling the underlying ExecContext method of the driver if it is supported by it. +// See, database/sql#DB.ExecContext for more information. +func (c *config) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error) { + ex, ok := c.driver.(interface { + ExecContext(context.Context, string, ...any) (stdsql.Result, error) + }) + if !ok { + return nil, fmt.Errorf("Driver.ExecContext is not supported") + } + return ex.ExecContext(ctx, query, args...) +} + +// QueryContext allows calling the underlying QueryContext method of the driver if it is supported by it. +// See, database/sql#DB.QueryContext for more information. +func (c *config) QueryContext(ctx context.Context, query string, args ...any) (*stdsql.Rows, error) { + q, ok := c.driver.(interface { + QueryContext(context.Context, string, ...any) (*stdsql.Rows, error) + }) + if !ok { + return nil, fmt.Errorf("Driver.QueryContext is not supported") + } + return q.QueryContext(ctx, query, args...) +} diff --git a/bj_power_mes/ent/ent.go b/bj_power_mes/ent/ent.go index 0478fe0..35d3de0 100644 --- a/bj_power_mes/ent/ent.go +++ b/bj_power_mes/ent/ent.go @@ -3,6 +3,7 @@ package ent import ( + "bj_power_mes/ent/agvpoint" "bj_power_mes/ent/agvtask" "bj_power_mes/ent/alert" "bj_power_mes/ent/alertrule" @@ -110,6 +111,7 @@ var ( func checkColumn(t, c string) error { initCheck.Do(func() { columnCheck = sql.NewColumnCheck(map[string]func(string) bool{ + agvpoint.Table: agvpoint.ValidColumn, agvtask.Table: agvtask.ValidColumn, alert.Table: alert.ValidColumn, alertrule.Table: alertrule.ValidColumn, diff --git a/bj_power_mes/ent/hook/hook.go b/bj_power_mes/ent/hook/hook.go index 21506de..9b64f11 100644 --- a/bj_power_mes/ent/hook/hook.go +++ b/bj_power_mes/ent/hook/hook.go @@ -8,6 +8,18 @@ import ( "fmt" ) +// The AgvPointFunc type is an adapter to allow the use of ordinary +// function as AgvPoint mutator. +type AgvPointFunc func(context.Context, *ent.AgvPointMutation) (ent.Value, error) + +// Mutate calls f(ctx, m). +func (f AgvPointFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) { + if mv, ok := m.(*ent.AgvPointMutation); ok { + return f(ctx, mv) + } + return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.AgvPointMutation", m) +} + // The AgvTaskFunc type is an adapter to allow the use of ordinary // function as AgvTask mutator. type AgvTaskFunc func(context.Context, *ent.AgvTaskMutation) (ent.Value, error) diff --git a/bj_power_mes/ent/migrate/schema.go b/bj_power_mes/ent/migrate/schema.go index ac017ac..5eee771 100644 --- a/bj_power_mes/ent/migrate/schema.go +++ b/bj_power_mes/ent/migrate/schema.go @@ -9,6 +9,40 @@ import ( ) var ( + // AgvPointColumns holds the columns for the "agv_point" table. + AgvPointColumns = []*schema.Column{ + {Name: "id", Type: field.TypeInt, Increment: true}, + {Name: "position_code", Type: field.TypeString, Unique: true, Size: 32, Comment: "AGV 点位编码(硬件映射=送往 RCS 的目标坐标,软件不可改)"}, + {Name: "name", Type: field.TypeString, Size: 64, Comment: "点位显示名称(可编辑)", Default: ""}, + {Name: "is_dock", Type: field.TypeBool, Comment: "是否接驳台点位(true=绑定接驳台,false=纯待命/充电点位)", Default: false}, + {Name: "dock_id", Type: field.TypeInt, Nullable: true, Comment: "绑定的接驳台 ID(is_dock=true 时硬件内置强绑定)"}, + {Name: "enabled", Type: field.TypeBool, Comment: "是否启用(可编辑)", Default: true}, + {Name: "created_at", Type: field.TypeTime}, + } + // AgvPointTable holds the schema information for the "agv_point" table. + AgvPointTable = &schema.Table{ + Name: "agv_point", + Comment: "AgvPoint AGV 点位(硬件级别真源):点位编码与接驳台一一对应,软件仅可启用/停用与改显示名。", + Columns: AgvPointColumns, + PrimaryKey: []*schema.Column{AgvPointColumns[0]}, + Indexes: []*schema.Index{ + { + Name: "agvpoint_position_code", + Unique: true, + Columns: []*schema.Column{AgvPointColumns[1]}, + }, + { + Name: "agvpoint_is_dock", + Unique: false, + Columns: []*schema.Column{AgvPointColumns[3]}, + }, + { + Name: "agvpoint_enabled", + Unique: false, + Columns: []*schema.Column{AgvPointColumns[5]}, + }, + }, + } // AgvTasksColumns holds the columns for the "agv_tasks" table. AgvTasksColumns = []*schema.Column{ {Name: "id", Type: field.TypeInt, Increment: true}, @@ -1396,6 +1430,7 @@ var ( } // Tables holds all the tables in the schema. Tables = []*schema.Table{ + AgvPointTable, AgvTasksTable, AlertTable, AlertRuleTable, @@ -1438,6 +1473,9 @@ var ( ) func init() { + AgvPointTable.Annotation = &entsql.Annotation{ + Table: "agv_point", + } AgvTasksTable.Annotation = &entsql.Annotation{ Table: "agv_tasks", } diff --git a/bj_power_mes/ent/mutation.go b/bj_power_mes/ent/mutation.go index c18e344..1e1920d 100644 --- a/bj_power_mes/ent/mutation.go +++ b/bj_power_mes/ent/mutation.go @@ -3,6 +3,7 @@ package ent import ( + "bj_power_mes/ent/agvpoint" "bj_power_mes/ent/agvtask" "bj_power_mes/ent/alert" "bj_power_mes/ent/alertrule" @@ -61,6 +62,7 @@ const ( OpUpdateOne = ent.OpUpdateOne // Node types. + TypeAgvPoint = "AgvPoint" TypeAgvTask = "AgvTask" TypeAlert = "Alert" TypeAlertRule = "AlertRule" @@ -101,6 +103,661 @@ const ( TypeWorkpieceProcess = "WorkpieceProcess" ) +// AgvPointMutation represents an operation that mutates the AgvPoint nodes in the graph. +type AgvPointMutation struct { + config + op Op + typ string + id *int + position_code *string + name *string + is_dock *bool + dock_id *int + adddock_id *int + enabled *bool + created_at *time.Time + clearedFields map[string]struct{} + done bool + oldValue func(context.Context) (*AgvPoint, error) + predicates []predicate.AgvPoint +} + +var _ ent.Mutation = (*AgvPointMutation)(nil) + +// agvpointOption allows management of the mutation configuration using functional options. +type agvpointOption func(*AgvPointMutation) + +// newAgvPointMutation creates new mutation for the AgvPoint entity. +func newAgvPointMutation(c config, op Op, opts ...agvpointOption) *AgvPointMutation { + m := &AgvPointMutation{ + config: c, + op: op, + typ: TypeAgvPoint, + clearedFields: make(map[string]struct{}), + } + for _, opt := range opts { + opt(m) + } + return m +} + +// withAgvPointID sets the ID field of the mutation. +func withAgvPointID(id int) agvpointOption { + return func(m *AgvPointMutation) { + var ( + err error + once sync.Once + value *AgvPoint + ) + m.oldValue = func(ctx context.Context) (*AgvPoint, error) { + once.Do(func() { + if m.done { + err = errors.New("querying old values post mutation is not allowed") + } else { + value, err = m.Client().AgvPoint.Get(ctx, id) + } + }) + return value, err + } + m.id = &id + } +} + +// withAgvPoint sets the old AgvPoint of the mutation. +func withAgvPoint(node *AgvPoint) agvpointOption { + return func(m *AgvPointMutation) { + m.oldValue = func(context.Context) (*AgvPoint, error) { + return node, nil + } + m.id = &node.ID + } +} + +// Client returns a new `ent.Client` from the mutation. If the mutation was +// executed in a transaction (ent.Tx), a transactional client is returned. +func (m AgvPointMutation) Client() *Client { + client := &Client{config: m.config} + client.init() + return client +} + +// Tx returns an `ent.Tx` for mutations that were executed in transactions; +// it returns an error otherwise. +func (m AgvPointMutation) Tx() (*Tx, error) { + if _, ok := m.driver.(*txDriver); !ok { + return nil, errors.New("ent: mutation is not running in a transaction") + } + tx := &Tx{config: m.config} + tx.init() + return tx, nil +} + +// ID returns the ID value in the mutation. Note that the ID is only available +// if it was provided to the builder or after it was returned from the database. +func (m *AgvPointMutation) ID() (id int, exists bool) { + if m.id == nil { + return + } + return *m.id, true +} + +// IDs queries the database and returns the entity ids that match the mutation's predicate. +// That means, if the mutation is applied within a transaction with an isolation level such +// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated +// or updated by the mutation. +func (m *AgvPointMutation) IDs(ctx context.Context) ([]int, error) { + switch { + case m.op.Is(OpUpdateOne | OpDeleteOne): + id, exists := m.ID() + if exists { + return []int{id}, nil + } + fallthrough + case m.op.Is(OpUpdate | OpDelete): + return m.Client().AgvPoint.Query().Where(m.predicates...).IDs(ctx) + default: + return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op) + } +} + +// SetPositionCode sets the "position_code" field. +func (m *AgvPointMutation) SetPositionCode(s string) { + m.position_code = &s +} + +// PositionCode returns the value of the "position_code" field in the mutation. +func (m *AgvPointMutation) PositionCode() (r string, exists bool) { + v := m.position_code + if v == nil { + return + } + return *v, true +} + +// OldPositionCode returns the old "position_code" field's value of the AgvPoint entity. +// If the AgvPoint object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AgvPointMutation) OldPositionCode(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldPositionCode is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldPositionCode requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldPositionCode: %w", err) + } + return oldValue.PositionCode, nil +} + +// ResetPositionCode resets all changes to the "position_code" field. +func (m *AgvPointMutation) ResetPositionCode() { + m.position_code = nil +} + +// SetName sets the "name" field. +func (m *AgvPointMutation) SetName(s string) { + m.name = &s +} + +// Name returns the value of the "name" field in the mutation. +func (m *AgvPointMutation) Name() (r string, exists bool) { + v := m.name + if v == nil { + return + } + return *v, true +} + +// OldName returns the old "name" field's value of the AgvPoint entity. +// If the AgvPoint object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AgvPointMutation) OldName(ctx context.Context) (v string, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldName is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldName requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldName: %w", err) + } + return oldValue.Name, nil +} + +// ResetName resets all changes to the "name" field. +func (m *AgvPointMutation) ResetName() { + m.name = nil +} + +// SetIsDock sets the "is_dock" field. +func (m *AgvPointMutation) SetIsDock(b bool) { + m.is_dock = &b +} + +// IsDock returns the value of the "is_dock" field in the mutation. +func (m *AgvPointMutation) IsDock() (r bool, exists bool) { + v := m.is_dock + if v == nil { + return + } + return *v, true +} + +// OldIsDock returns the old "is_dock" field's value of the AgvPoint entity. +// If the AgvPoint object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AgvPointMutation) OldIsDock(ctx context.Context) (v bool, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldIsDock is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldIsDock requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldIsDock: %w", err) + } + return oldValue.IsDock, nil +} + +// ResetIsDock resets all changes to the "is_dock" field. +func (m *AgvPointMutation) ResetIsDock() { + m.is_dock = nil +} + +// SetDockID sets the "dock_id" field. +func (m *AgvPointMutation) SetDockID(i int) { + m.dock_id = &i + m.adddock_id = nil +} + +// DockID returns the value of the "dock_id" field in the mutation. +func (m *AgvPointMutation) DockID() (r int, exists bool) { + v := m.dock_id + if v == nil { + return + } + return *v, true +} + +// OldDockID returns the old "dock_id" field's value of the AgvPoint entity. +// If the AgvPoint object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AgvPointMutation) OldDockID(ctx context.Context) (v *int, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldDockID is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldDockID requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldDockID: %w", err) + } + return oldValue.DockID, nil +} + +// AddDockID adds i to the "dock_id" field. +func (m *AgvPointMutation) AddDockID(i int) { + if m.adddock_id != nil { + *m.adddock_id += i + } else { + m.adddock_id = &i + } +} + +// AddedDockID returns the value that was added to the "dock_id" field in this mutation. +func (m *AgvPointMutation) AddedDockID() (r int, exists bool) { + v := m.adddock_id + if v == nil { + return + } + return *v, true +} + +// ClearDockID clears the value of the "dock_id" field. +func (m *AgvPointMutation) ClearDockID() { + m.dock_id = nil + m.adddock_id = nil + m.clearedFields[agvpoint.FieldDockID] = struct{}{} +} + +// DockIDCleared returns if the "dock_id" field was cleared in this mutation. +func (m *AgvPointMutation) DockIDCleared() bool { + _, ok := m.clearedFields[agvpoint.FieldDockID] + return ok +} + +// ResetDockID resets all changes to the "dock_id" field. +func (m *AgvPointMutation) ResetDockID() { + m.dock_id = nil + m.adddock_id = nil + delete(m.clearedFields, agvpoint.FieldDockID) +} + +// SetEnabled sets the "enabled" field. +func (m *AgvPointMutation) SetEnabled(b bool) { + m.enabled = &b +} + +// Enabled returns the value of the "enabled" field in the mutation. +func (m *AgvPointMutation) Enabled() (r bool, exists bool) { + v := m.enabled + if v == nil { + return + } + return *v, true +} + +// OldEnabled returns the old "enabled" field's value of the AgvPoint entity. +// If the AgvPoint object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AgvPointMutation) OldEnabled(ctx context.Context) (v bool, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldEnabled is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldEnabled requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldEnabled: %w", err) + } + return oldValue.Enabled, nil +} + +// ResetEnabled resets all changes to the "enabled" field. +func (m *AgvPointMutation) ResetEnabled() { + m.enabled = nil +} + +// SetCreatedAt sets the "created_at" field. +func (m *AgvPointMutation) SetCreatedAt(t time.Time) { + m.created_at = &t +} + +// CreatedAt returns the value of the "created_at" field in the mutation. +func (m *AgvPointMutation) CreatedAt() (r time.Time, exists bool) { + v := m.created_at + if v == nil { + return + } + return *v, true +} + +// OldCreatedAt returns the old "created_at" field's value of the AgvPoint entity. +// If the AgvPoint object wasn't provided to the builder, the object is fetched from the database. +// An error is returned if the mutation operation is not UpdateOne, or the database query fails. +func (m *AgvPointMutation) OldCreatedAt(ctx context.Context) (v time.Time, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldCreatedAt is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldCreatedAt requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldCreatedAt: %w", err) + } + return oldValue.CreatedAt, nil +} + +// ResetCreatedAt resets all changes to the "created_at" field. +func (m *AgvPointMutation) ResetCreatedAt() { + m.created_at = nil +} + +// Where appends a list predicates to the AgvPointMutation builder. +func (m *AgvPointMutation) Where(ps ...predicate.AgvPoint) { + m.predicates = append(m.predicates, ps...) +} + +// WhereP appends storage-level predicates to the AgvPointMutation builder. Using this method, +// users can use type-assertion to append predicates that do not depend on any generated package. +func (m *AgvPointMutation) WhereP(ps ...func(*sql.Selector)) { + p := make([]predicate.AgvPoint, len(ps)) + for i := range ps { + p[i] = ps[i] + } + m.Where(p...) +} + +// Op returns the operation name. +func (m *AgvPointMutation) Op() Op { + return m.op +} + +// SetOp allows setting the mutation operation. +func (m *AgvPointMutation) SetOp(op Op) { + m.op = op +} + +// Type returns the node type of this mutation (AgvPoint). +func (m *AgvPointMutation) Type() string { + return m.typ +} + +// Fields returns all fields that were changed during this mutation. Note that in +// order to get all numeric fields that were incremented/decremented, call +// AddedFields(). +func (m *AgvPointMutation) Fields() []string { + fields := make([]string, 0, 6) + if m.position_code != nil { + fields = append(fields, agvpoint.FieldPositionCode) + } + if m.name != nil { + fields = append(fields, agvpoint.FieldName) + } + if m.is_dock != nil { + fields = append(fields, agvpoint.FieldIsDock) + } + if m.dock_id != nil { + fields = append(fields, agvpoint.FieldDockID) + } + if m.enabled != nil { + fields = append(fields, agvpoint.FieldEnabled) + } + if m.created_at != nil { + fields = append(fields, agvpoint.FieldCreatedAt) + } + return fields +} + +// Field returns the value of a field with the given name. The second boolean +// return value indicates that this field was not set, or was not defined in the +// schema. +func (m *AgvPointMutation) Field(name string) (ent.Value, bool) { + switch name { + case agvpoint.FieldPositionCode: + return m.PositionCode() + case agvpoint.FieldName: + return m.Name() + case agvpoint.FieldIsDock: + return m.IsDock() + case agvpoint.FieldDockID: + return m.DockID() + case agvpoint.FieldEnabled: + return m.Enabled() + case agvpoint.FieldCreatedAt: + return m.CreatedAt() + } + return nil, false +} + +// OldField returns the old value of the field from the database. An error is +// returned if the mutation operation is not UpdateOne, or the query to the +// database failed. +func (m *AgvPointMutation) OldField(ctx context.Context, name string) (ent.Value, error) { + switch name { + case agvpoint.FieldPositionCode: + return m.OldPositionCode(ctx) + case agvpoint.FieldName: + return m.OldName(ctx) + case agvpoint.FieldIsDock: + return m.OldIsDock(ctx) + case agvpoint.FieldDockID: + return m.OldDockID(ctx) + case agvpoint.FieldEnabled: + return m.OldEnabled(ctx) + case agvpoint.FieldCreatedAt: + return m.OldCreatedAt(ctx) + } + return nil, fmt.Errorf("unknown AgvPoint field %s", name) +} + +// SetField sets the value of a field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *AgvPointMutation) SetField(name string, value ent.Value) error { + switch name { + case agvpoint.FieldPositionCode: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetPositionCode(v) + return nil + case agvpoint.FieldName: + v, ok := value.(string) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetName(v) + return nil + case agvpoint.FieldIsDock: + v, ok := value.(bool) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetIsDock(v) + return nil + case agvpoint.FieldDockID: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetDockID(v) + return nil + case agvpoint.FieldEnabled: + v, ok := value.(bool) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetEnabled(v) + return nil + case agvpoint.FieldCreatedAt: + v, ok := value.(time.Time) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetCreatedAt(v) + return nil + } + return fmt.Errorf("unknown AgvPoint field %s", name) +} + +// AddedFields returns all numeric fields that were incremented/decremented during +// this mutation. +func (m *AgvPointMutation) AddedFields() []string { + var fields []string + if m.adddock_id != nil { + fields = append(fields, agvpoint.FieldDockID) + } + return fields +} + +// AddedField returns the numeric value that was incremented/decremented on a field +// with the given name. The second boolean return value indicates that this field +// was not set, or was not defined in the schema. +func (m *AgvPointMutation) AddedField(name string) (ent.Value, bool) { + switch name { + case agvpoint.FieldDockID: + return m.AddedDockID() + } + return nil, false +} + +// AddField adds the value to the field with the given name. It returns an error if +// the field is not defined in the schema, or if the type mismatched the field +// type. +func (m *AgvPointMutation) AddField(name string, value ent.Value) error { + switch name { + case agvpoint.FieldDockID: + v, ok := value.(int) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddDockID(v) + return nil + } + return fmt.Errorf("unknown AgvPoint numeric field %s", name) +} + +// ClearedFields returns all nullable fields that were cleared during this +// mutation. +func (m *AgvPointMutation) ClearedFields() []string { + var fields []string + if m.FieldCleared(agvpoint.FieldDockID) { + fields = append(fields, agvpoint.FieldDockID) + } + return fields +} + +// FieldCleared returns a boolean indicating if a field with the given name was +// cleared in this mutation. +func (m *AgvPointMutation) FieldCleared(name string) bool { + _, ok := m.clearedFields[name] + return ok +} + +// ClearField clears the value of the field with the given name. It returns an +// error if the field is not defined in the schema. +func (m *AgvPointMutation) ClearField(name string) error { + switch name { + case agvpoint.FieldDockID: + m.ClearDockID() + return nil + } + return fmt.Errorf("unknown AgvPoint nullable field %s", name) +} + +// ResetField resets all changes in the mutation for the field with the given name. +// It returns an error if the field is not defined in the schema. +func (m *AgvPointMutation) ResetField(name string) error { + switch name { + case agvpoint.FieldPositionCode: + m.ResetPositionCode() + return nil + case agvpoint.FieldName: + m.ResetName() + return nil + case agvpoint.FieldIsDock: + m.ResetIsDock() + return nil + case agvpoint.FieldDockID: + m.ResetDockID() + return nil + case agvpoint.FieldEnabled: + m.ResetEnabled() + return nil + case agvpoint.FieldCreatedAt: + m.ResetCreatedAt() + return nil + } + return fmt.Errorf("unknown AgvPoint field %s", name) +} + +// AddedEdges returns all edge names that were set/added in this mutation. +func (m *AgvPointMutation) AddedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// AddedIDs returns all IDs (to other nodes) that were added for the given edge +// name in this mutation. +func (m *AgvPointMutation) AddedIDs(name string) []ent.Value { + return nil +} + +// RemovedEdges returns all edge names that were removed in this mutation. +func (m *AgvPointMutation) RemovedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with +// the given name in this mutation. +func (m *AgvPointMutation) RemovedIDs(name string) []ent.Value { + return nil +} + +// ClearedEdges returns all edge names that were cleared in this mutation. +func (m *AgvPointMutation) ClearedEdges() []string { + edges := make([]string, 0, 0) + return edges +} + +// EdgeCleared returns a boolean which indicates if the edge with the given name +// was cleared in this mutation. +func (m *AgvPointMutation) EdgeCleared(name string) bool { + return false +} + +// ClearEdge clears the value of the edge with the given name. It returns an error +// if that edge is not defined in the schema. +func (m *AgvPointMutation) ClearEdge(name string) error { + return fmt.Errorf("unknown AgvPoint unique edge %s", name) +} + +// ResetEdge resets all changes to the edge with the given name in this mutation. +// It returns an error if the edge is not defined in the schema. +func (m *AgvPointMutation) ResetEdge(name string) error { + return fmt.Errorf("unknown AgvPoint edge %s", name) +} + // AgvTaskMutation represents an operation that mutates the AgvTask nodes in the graph. type AgvTaskMutation struct { config diff --git a/bj_power_mes/ent/predicate/predicate.go b/bj_power_mes/ent/predicate/predicate.go index 4aafdeb..8847376 100644 --- a/bj_power_mes/ent/predicate/predicate.go +++ b/bj_power_mes/ent/predicate/predicate.go @@ -6,6 +6,9 @@ import ( "entgo.io/ent/dialect/sql" ) +// AgvPoint is the predicate function for agvpoint builders. +type AgvPoint func(*sql.Selector) + // AgvTask is the predicate function for agvtask builders. type AgvTask func(*sql.Selector) diff --git a/bj_power_mes/ent/runtime.go b/bj_power_mes/ent/runtime.go index 7c47ee0..7046242 100644 --- a/bj_power_mes/ent/runtime.go +++ b/bj_power_mes/ent/runtime.go @@ -3,6 +3,7 @@ package ent import ( + "bj_power_mes/ent/agvpoint" "bj_power_mes/ent/agvtask" "bj_power_mes/ent/alert" "bj_power_mes/ent/alertrule" @@ -49,6 +50,30 @@ import ( // (default values, validators, hooks and policies) and stitches it // to their package variables. func init() { + agvpointFields := schema.AgvPoint{}.Fields() + _ = agvpointFields + // agvpointDescPositionCode is the schema descriptor for position_code field. + agvpointDescPositionCode := agvpointFields[0].Descriptor() + // agvpoint.PositionCodeValidator is a validator for the "position_code" field. It is called by the builders before save. + agvpoint.PositionCodeValidator = agvpointDescPositionCode.Validators[0].(func(string) error) + // agvpointDescName is the schema descriptor for name field. + agvpointDescName := agvpointFields[1].Descriptor() + // agvpoint.DefaultName holds the default value on creation for the name field. + agvpoint.DefaultName = agvpointDescName.Default.(string) + // agvpoint.NameValidator is a validator for the "name" field. It is called by the builders before save. + agvpoint.NameValidator = agvpointDescName.Validators[0].(func(string) error) + // agvpointDescIsDock is the schema descriptor for is_dock field. + agvpointDescIsDock := agvpointFields[2].Descriptor() + // agvpoint.DefaultIsDock holds the default value on creation for the is_dock field. + agvpoint.DefaultIsDock = agvpointDescIsDock.Default.(bool) + // agvpointDescEnabled is the schema descriptor for enabled field. + agvpointDescEnabled := agvpointFields[4].Descriptor() + // agvpoint.DefaultEnabled holds the default value on creation for the enabled field. + agvpoint.DefaultEnabled = agvpointDescEnabled.Default.(bool) + // agvpointDescCreatedAt is the schema descriptor for created_at field. + agvpointDescCreatedAt := agvpointFields[5].Descriptor() + // agvpoint.DefaultCreatedAt holds the default value on creation for the created_at field. + agvpoint.DefaultCreatedAt = agvpointDescCreatedAt.Default.(func() time.Time) agvtaskFields := schema.AgvTask{}.Fields() _ = agvtaskFields // agvtaskDescTaskNo is the schema descriptor for task_no field. diff --git a/bj_power_mes/ent/tx.go b/bj_power_mes/ent/tx.go index 5f78b99..48ac19a 100644 --- a/bj_power_mes/ent/tx.go +++ b/bj_power_mes/ent/tx.go @@ -4,6 +4,8 @@ package ent import ( "context" + stdsql "database/sql" + "fmt" "sync" "entgo.io/ent/dialect" @@ -12,6 +14,8 @@ import ( // Tx is a transactional client that is created by calling Client.Tx(). type Tx struct { config + // AgvPoint is the client for interacting with the AgvPoint builders. + AgvPoint *AgvPointClient // AgvTask is the client for interacting with the AgvTask builders. AgvTask *AgvTaskClient // Alert is the client for interacting with the Alert builders. @@ -219,6 +223,7 @@ func (tx *Tx) Client() *Client { } func (tx *Tx) init() { + tx.AgvPoint = NewAgvPointClient(tx.config) tx.AgvTask = NewAgvTaskClient(tx.config) tx.Alert = NewAlertClient(tx.config) tx.AlertRule = NewAlertRuleClient(tx.config) @@ -266,7 +271,7 @@ func (tx *Tx) init() { // of them in order to commit or rollback the transaction. // // If a closed transaction is embedded in one of the generated entities, and the entity -// applies a query, for example: AgvTask.QueryXXX(), the query will be executed +// applies a query, for example: AgvPoint.QueryXXX(), the query will be executed // through the driver which created this transaction. // // Note that txDriver is not goroutine safe. @@ -319,3 +324,27 @@ func (tx *txDriver) Query(ctx context.Context, query string, args, v any) error } var _ dialect.Driver = (*txDriver)(nil) + +// ExecContext allows calling the underlying ExecContext method of the transaction if it is supported by it. +// See, database/sql#Tx.ExecContext for more information. +func (tx *txDriver) ExecContext(ctx context.Context, query string, args ...any) (stdsql.Result, error) { + ex, ok := tx.tx.(interface { + ExecContext(context.Context, string, ...any) (stdsql.Result, error) + }) + if !ok { + return nil, fmt.Errorf("Tx.ExecContext is not supported") + } + return ex.ExecContext(ctx, query, args...) +} + +// QueryContext allows calling the underlying QueryContext method of the transaction if it is supported by it. +// See, database/sql#Tx.QueryContext for more information. +func (tx *txDriver) QueryContext(ctx context.Context, query string, args ...any) (*stdsql.Rows, error) { + q, ok := tx.tx.(interface { + QueryContext(context.Context, string, ...any) (*stdsql.Rows, error) + }) + if !ok { + return nil, fmt.Errorf("Tx.QueryContext is not supported") + } + return q.QueryContext(ctx, query, args...) +} diff --git a/bj_power_mes/frontend/src/help.js b/bj_power_mes/frontend/src/help.js index 1cb1356..c2a29ce 100644 --- a/bj_power_mes/frontend/src/help.js +++ b/bj_power_mes/frontend/src/help.js @@ -141,14 +141,17 @@ export const helpQtyReport = { } export const helpPlc = { - title: '工位组合下发(下发录入 / 下发记录)', + title: '工位下发(下发录入 / 下发记录)', overview: - '这个菜单做什么用:把某工单/工件的「工位组合」写入产线设备(如 PLC 控制器),产线传送带据此只停靠勾选的工位,其余工位不加工。\n\n页面分两个页签:「下发录入」(默认打开)、「下发记录」(点击才加载,可按产品工号/状态筛选)。\n\n操作流程:选产品工号 → 下拉选出该工单已上线未完工的工件 SN(也可扫码/手输) → 系统按工件实际进度自动带出「当前工位」(只读) → 工位组合由工单「工艺组合」按工位号升序自动派生 → 下发。\n\n为什么单独一个菜单:产线偶尔需要人工干预——比如本该走 3 号工位却做成了半成品,可到「工单管理」编辑工单的工艺组合(只勾剩余工位)后重上线,完成闭环。\n\n核心约束:系统遵循「上一条未收到完成信号,不下发下一条」,确保产线不串序。\n\n数据链路:工单(含工艺组合) → 本页下发到产线设备 → 产线设备驱动传送带/工位 → 收到完成信号再下发下一条。', + '这个菜单做什么用:一台电表箱从工位 A 做完要去工位 B,靠什么"告诉"产线?就靠本页——把该工件要经过的「工位组合」(工位顺序清单)写入产线控制器(PLC),产线传送带据此只把工件送到组合内的工位,其余工位不停靠、不加工。\n\n页面分两个页签:「下发录入」(默认打开)、「下发记录」(点击才加载,可按产品工号/状态筛选)。\n\n日常操作流程:选产品工号 → 下拉选出该工单已上线未完工的工件 SN(也可扫码/手输)→ 系统按工件实际进度自动带出「当前工位」(只读)→ 工位组合由工单「工艺组合」按工位号升序自动派生 → 点「下发工位码」。做完一步、完成信号回来,再下发下一条——现场无需人记住顺序。\n\n发错了怎么办(两条收口路,都在「下发记录」页签):\n· 撤回:选错工件/工位,点「撤回」填原因,该条作废,可立即重发正确的。\n· 人工完成:工件实际已经流转到位、但 PLC 完成信号没回来(信号丢失/产线未接入),点「人工完成」现场收口,放行下一条。\n\n核心约束:系统遵循「上一条未收到完成信号,不下发下一条」,确保产线不串序;有在途未收口的下发时,看板会持续报警提醒收口。\n\n数据链路:工单(含工艺组合) → 本页下发到产线设备 → 产线设备驱动传送带/工位 → 收到完成信号(或人工完成)再下发下一条;每一步均留痕「操作日志」。', fields: [ { name: '产品工号', source: '下拉选择/输入。来自工单。', purpose: '当前生产的工单,选中后带出该工单可下发的工件 SN', fill: '选择或输入产品工号' }, { name: '工件SN', source: '下拉选择(该工单已上线未完工的 SN,可搜索),也可扫码枪扫入手输。', purpose: '当前流经的工件唯一序列号', fill: '优先下拉选已上线 SN;扫码手输时须是已上线的工件才能带出当前工位' }, { name: '当前工位', source: '自动带出(只读)。按所选工件的实际生产进度识别。', purpose: '从哪一站开始继续下发', fill: '无需填写;未带出说明工件未上线或 SN 有误' }, - { name: '工位组合', source: '由工单「工艺组合」按工位号升序自动派生,无需手选。', purpose: '该工件要经过的工位,产线设备控制停靠', fill: '如需调整路线,到「工单管理」编辑工单的工艺组合' } + { name: '工位组合', source: '由工单「工艺组合」按工位号升序自动派生,无需手选。', purpose: '该工件要经过的工位,产线设备控制停靠', fill: '如需调整路线,到「工单管理」编辑工单的工艺组合' }, + { name: '状态', source: '下发记录页签:已下发(在途)/已完成/已撤回。', purpose: '区分指令是否已收口', fill: '「已下发」长期挂着=产线有指令未收口,需撤回或人工完成' }, + { name: '撤回', source: '下发记录行内按钮,仅「已下发」可撤,原因必填。', purpose: '误下发(选错工件/工位)的纠错入口', fill: '点「撤回」→ 填原因 → 确认;撤回后可立即重新下发正确工位码' }, + { name: '人工完成', source: '下发记录行内按钮,仅「已下发」可用。', purpose: 'PLC 完成信号丢失/产线未接入时,现场确认工件已到位后人工收口,放行下一条', fill: '仅限现场确认实际已到位时使用,二次确认后状态置「已完成」' } ] } @@ -600,9 +603,9 @@ export const helpProducible = { } export const helpPlcMonitor = { - title: 'PLC 手动监控', + title: 'PLC管理', overview: - '本页用于人工查看产线 PLC 点位状态、查看并清零卡住的在途指令、以及手动下发路径指令。\n\n页面从上到下分六块:\n· 顶部:刷新按钮 + 最后刷新时间(打开页面自动读一次,不轮询;需最新状态点「刷新」)。\n· 工位托盘位(只读)、主线缓存位(只读)、接驳台托盘位(只读):三块均为只读,展示各点位「●有件 / ○空」(PLC 实时读取,中文名如 工位1、缓存位5、接驳台1)。无任何按钮、无输入框;传感器位由 PLC 覆盖,无需也不可人工改动。\n· 在途指令:仅列出 PLC 中仍记录为「在途」(MW 非 0)的路径指令,显示为「源 → 目标」。若该指令已实际卡住、PLC 未自动清零,可点「强制清零」——二次确认并勾选「已确认现场安全且指令已实际卡住」后写 MW=0。正常自动线不应出现长期在途。\n· 手动下发:选「源」(工位1~12 / 缓存位1~15)→ 目标下拉按源类型动态过滤 → 系统自动预览「源 → 目标」→ 点「下发」二次确认后写入 PLC。\n\n互斥保护:手动下发前系统检查是否存在在途指令(尚未收到完成信号)——若有则拒绝并提示,以免打断自动线。\n\n所有手动下发动作记入操作日志(event_log,类型 plc_manual_write);所有强制清零动作记入操作日志(event_log,类型 plc_in_transit_clear),均可在「操作日志」页按类型筛选追溯。', + '这个菜单做什么用:产线设备(PLC)的"仪表盘+方向盘"。产线工人不用懂 PLC,本页把设备状态翻译成人话,并在设备不干活时给人工干预的入口。\n\n页面从上到下分六块:\n· 顶部:刷新按钮 + 最后刷新时间(打开页面自动读一次,不轮询;需最新状态点「刷新」)。\n· 工位托盘位(只读)、主线缓存位(只读)、接驳台托盘位(只读):三块均为只读,展示各点位「●有件 / ○空」(PLC 实时读取,中文名如 工位1、缓存位5、接驳台1)。无任何按钮、无输入框;传感器位由 PLC 覆盖,无需也不可人工改动。\n· 在途指令:仅列出 PLC 中仍记录为「在途」(MW 非 0)的路径指令,显示为「源 → 目标」。若该指令已实际卡住、PLC 未自动清零,可点「强制清零」——二次确认并勾选「已确认现场安全且指令已实际卡住」后写 MW=0。正常自动线不应出现长期在途。\n· 手动下发:选「源」(工位1~12 / 缓存位1~15)→ 目标下拉按源类型动态过滤 → 系统自动预览「源 → 目标」→ 点「下发」二次确认后写入 PLC。\n\n与「工位下发」的分工:工位下发=按工单路线正常驱动产线(业务动作);本页=设备排障工具(PLC 卡住/漂移时的人工干预),只在异常时用。手动下发受互斥保护——存在在途指令(工位下发尚未收到完成信号)时拒绝,以免打断自动线;可先到「工位下发」页撤回或人工完成后再来。\n\n所有手动下发动作记入操作日志(event_log,类型 plc_manual_write);所有强制清零动作记入操作日志(event_log,类型 plc_in_transit_clear),均可在「操作日志」页按类型筛选追溯。', fields: [ { name: '源', source: '下拉选择。工位1~12 或 缓存位1~15。', purpose: '路径起点', fill: '选择后目标下拉按源类型动态过滤' }, { name: '目标', source: '下拉选择(按源类型动态过滤,仅显示 §4.4 合法组合)。', purpose: '路径终点', fill: '选源后才有可选目标' }, diff --git a/bj_power_mes/frontend/src/layouts/MainLayout.vue b/bj_power_mes/frontend/src/layouts/MainLayout.vue index a81935d..f5ca286 100644 --- a/bj_power_mes/frontend/src/layouts/MainLayout.vue +++ b/bj_power_mes/frontend/src/layouts/MainLayout.vue @@ -126,6 +126,14 @@ const menus = computed(() => { // 侧栏菜单按业务域分组(参考 WMS MainLayout):组无权限码,子项各自带 code 过滤, // 组内子项全被过滤则整组隐藏。SUPER_ADMIN / '*' 全放行。 const menuGroups = [ + { + title: '基础配置', icon: Box, children: [ + { code: 'produce.processflow', name: '工艺', path: '/process-flow', icon: Operation }, + { code: 'produce.station', name: '工位管理', path: '/station', icon: Link }, + { code: 'produce.product', name: '物料档案', path: '/product-type', icon: Box }, + { code: 'produce.line.manage', name: '产线管理', path: '/line-management', icon: Operation } + ] + }, { title: '生产管理', icon: Document, children: [ { code: 'produce.workorder', name: '工单管理', path: '/work-order', icon: Document }, @@ -133,31 +141,24 @@ const menuGroups = [ { code: 'produce.producible', name: '排产支撑', path: '/producible-support', icon: DataLine }, { code: 'produce.material', name: '备料单', path: '/material-request', icon: ShoppingCart }, { code: 'produce.qty', name: '数量不符处理', path: '/qty-report', icon: Warning }, + { code: 'produce.quality', name: '质量检验', path: '/quality', icon: CircleCheck }, { code: 'produce.performance', name: '绩效报表', path: '/performance', icon: DataLine }, - { code: 'produce.quality', name: '质量检验', path: '/quality', icon: CircleCheck } + { code: 'produce.plc', name: '工位下发', path: '/plc-send', icon: Monitor }, + { code: 'produce.plc.monitor', name: 'PLC管理', path: '/plc-monitor', icon: Monitor } ] }, { title: '现场作业', icon: Monitor, children: [ - { code: 'produce.plc', name: '工位组合下发', path: '/plc-send', icon: Monitor }, - { code: 'produce.plc.monitor', name: 'PLC 手动监控', path: '/plc-monitor', icon: Monitor }, - { code: 'produce.line.manage', name: '产线管理', path: '/line-management', icon: Operation }, - { code: 'produce.agv', name: 'AGV配送', path: '/agv', icon: Van }, { code: 'produce.wip', name: '在制品', path: '/wip', icon: Clock }, { code: 'produce.trace', name: '工件追溯', path: '/trace', icon: Search }, { code: 'produce.virtualstation', name: '虚拟工位作业', path: '/virtual-station', icon: Goods }, { code: 'produce.processcard', name: '生产流程卡', path: '/process-card', icon: Tickets }, { code: 'produce.audit', name: '待审核签字', path: '/audit-pending', icon: CircleCheck }, - { code: 'sys.inspect', name: '巡检终端', path: '/inspect', icon: CircleCheck } - ] - }, - { - title: '基础配置', icon: Box, children: [ - { code: 'produce.processflow', name: '工艺', path: '/process-flow', icon: Operation }, - { code: 'produce.station', name: '工位管理', path: '/station', icon: Link }, - { code: 'produce.product', name: '物料档案', path: '/product-type', icon: Box } + { code: 'sys.inspect', name: '巡检终端', path: '/inspect', icon: CircleCheck }, + { code: 'produce.agv', name: 'AGV配送', path: '/agv', icon: Van } ] }, + { title: '系统管理', icon: Key, children: [ { code: 'sys.account', name: '账号管理', path: '/account', icon: User }, diff --git a/bj_power_mes/frontend/src/pages/Agv.vue b/bj_power_mes/frontend/src/pages/Agv.vue index 43b440a..ab5be99 100644 --- a/bj_power_mes/frontend/src/pages/Agv.vue +++ b/bj_power_mes/frontend/src/pages/Agv.vue @@ -31,14 +31,40 @@ async function loadDocks() { loadingDocks.value = false } -// 手动派车可选的接驳台(来自接驳台主数据,仅启用项) -const dockOptions = computed(() => - docks.value.filter((d) => d.status === 'ENABLED').map((d) => d.dockCode) -) // 显示层统一(2026-10-17 裁定):库房接驳台一律显示「库房接驳台」,不显示 DOCK21/JBT21 编号 // (DOCK21 仅作后端映射/提交值;PLC 侧对应点位于监控页同样只显示「库房接驳台」) const dockLabel = (code) => (String(code || '') === 'DOCK21' ? '库房接驳台' : code || '—') +/* ===================== AGV 点位(独立点位表,硬件真源) ===================== */ +const agvPoints = ref([]) +const loadingPoints = ref(false) +async function loadAgvPoints() { + loadingPoints.value = true + try { + const data = await request.get('/agv/points') + agvPoints.value = Array.isArray(data) ? data : [] + } catch { agvPoints.value = [] } + loadingPoints.value = false +} +// 启用点位下拉(派车源/目标可选) +const pointOptions = computed(() => agvPoints.value.filter((p) => p.enabled).map((p) => p.positionCode)) +const pointMap = computed(() => { + const m = {} + agvPoints.value.forEach((p) => { m[p.positionCode] = p }) + return m +}) +const pointLabel = (code) => (pointMap.value[String(code)]?.name) || String(code || '—') +const savingPoint = ref(0) +async function savePoint(p) { + savingPoint.value = p.id + try { + await request.put(`/agv/points/${p.id}`, { name: p.name, enabled: p.enabled }) + ElMessage.success('已保存') + await loadAgvPoints() + } catch { /* 拦截器已提示 */ } + savingPoint.value = 0 +} + /* ===================== AGV 任务列表 ===================== */ const tasks = ref([]) const taskTotal = ref(0) @@ -96,23 +122,49 @@ function batchSetDock(v) { ElMessage.success(`已批量设为 ${v}`) } -// 按 targetDock 分组统计(下发确认弹窗展示;编号经 dockLabel 转中文显示) +// 按 targetDock(点位编码) 分组统计(下发确认弹窗展示;编码经 pointLabel 转显示名) const groupPreview = computed(() => { const g = {} for (const r of selected.value) { const d = r.targetDock || '未指定' g[d] = (g[d] || 0) + 1 } - return Object.entries(g).map(([dock, n]) => ({ dock: dock === '未指定' ? dock : dockLabel(dock), n })) + return Object.entries(g).map(([dock, n]) => ({ dock: dock === '未指定' ? dock : pointLabel(dock), n })) }) async function submitAgv() { const rows = selected.value.filter((r) => r.targetDock) - if (!rows.length) return ElMessage.warning('请至少选择一行且指定目标接驳台') + if (!rows.length) return ElMessage.warning('请至少选择一行且指定目标点位') + // 防撞强校验①:目标接驳台点位当前有托盘 → 拒派(避免小车与目标点已有托盘碰撞) + const busy = rows.filter((r) => { + const p = pointMap.value[r.targetDock] + return p && p.isDock && p.hasPallet + }) + if (busy.length) { + const names = [...new Set(busy.map((r) => pointLabel(r.targetDock)))].join('、') + return ElMessage.error(`目标接驳台有托盘,存在碰撞风险,禁止派车:${names}`) + } + // 防撞强校验②:已停用点位 → 直接拒派(与后端同口径,管理员停用即 AGV 不去,不提供确认放行) + const disabled = rows.filter((r) => { const p = pointMap.value[r.targetDock]; return p && !p.enabled }) + if (disabled.length) { + const names = [...new Set(disabled.map((r) => pointLabel(r.targetDock)))].join('、') + return ElMessage.error(`目标点位已停用,禁止派车(请先在「产线管理」恢复启用):${names}`) + } + // 防撞强校验③:纯点位(无接驳台/无传感器)→ 强制二次确认 + const pure = rows.filter((r) => { const p = pointMap.value[r.targetDock]; return p && !p.isDock }) + if (pure.length) { + const names = [...new Set(pure.map((r) => pointLabel(r.targetDock)))].join('、') + try { + await ElMessageBox.confirm( + `以下目标点位:${names}。该点位无传感器,请确保现场安全。仍要派车吗?`, + '防撞二次确认', { type: 'warning', confirmButtonText: '仍要派车', cancelButtonText: '取消' } + ) + } catch { return } + } const lines = groupPreview.value.map((g) => `· ${g.dock}:${g.n} 行`).join('\n') try { await ElMessageBox.confirm( - `确认对 ${rows.length} 行叫料单手动派车?\n\n按目标接驳台分组:\n${lines}\n\n源点:${dockLabel(sourceDock.value)}\n操作人:${operator.value}\n\n注:仓库完成备料时系统已自动派车,本操作用于补派或对失败任务重试。`, + `确认对 ${rows.length} 行叫料单手动派车?\n\n按目标点位分组:\n${lines}\n\n源点:${pointLabel(sourceDock.value)}\n操作人:${operator.value}\n\n注:仓库完成备料时系统已自动派车,本操作用于补派或对失败任务重试。`, '手动派车确认', { type: 'warning', confirmButtonText: '确认派车', cancelButtonText: '取消' } ) @@ -156,10 +208,14 @@ const agvMode = reactive({ mock: false, tip: '' }) function canCancel(status) { return status === 'PENDING' || status === '1' || status === '2' } +// 重试口径与后端 RetryAgvTask 对齐:FAILED(RCS 下发失败)与 PENDING(未成功下发到 RCS)均可重试 +function canRetry(status) { + return status === 'FAILED' || status === 'PENDING' +} async function cancelTask(row) { const { value: reason } = await ElMessageBox.prompt( - `确认取消 AGV 任务 ${row.taskNo}(${dockLabel(row.sourceDock)} → ${dockLabel(row.targetDock)})?`, + `确认取消 AGV 任务 ${row.taskNo}(${pointLabel(row.sourceDock)} → ${pointLabel(row.targetDock)})?`, '取消 AGV 任务', { type: 'warning', confirmButtonText: '确认取消', cancelButtonText: '返回', inputPlaceholder: '取消原因(选填)', inputValue: '' } ).catch(() => ({ value: null })) @@ -171,6 +227,20 @@ async function cancelTask(row) { } catch { /* 拦截器已提示 */ } } +async function retryTask(row) { + try { + await ElMessageBox.confirm( + `确认重试 AGV 任务 ${row.taskNo}(${pointLabel(row.sourceDock)} → ${pointLabel(row.targetDock)})?将重新向 RCS 下发。`, + '重试 AGV 任务', { type: 'warning', confirmButtonText: '确认重试', cancelButtonText: '返回' } + ) + } catch { return } + try { + await request.post('/agv/retry', { taskNo: row.taskNo }, withOperator()) + ElMessage.success('已重试派车') + loadTasks(); loadAgvPoints() + } catch { /* 拦截器已提示 */ } +} + async function loadMode() { try { const m = await request.get('/agv/mode') @@ -179,13 +249,14 @@ async function loadMode() { } catch { /* 忽略 */ } } -onMounted(() => { loadDocks(); loadTasks(); loadMode() }) +onMounted(() => { loadDocks(); loadTasks(); loadMode(); loadAgvPoints() }) // 切 tab 重新加载对应数据(2026-10-19:lazy 页签切回不 reload,状态/叫料单会停留在旧数据) function onTabChange(name) { if (name === 'docks') loadDocks() else if (name === 'tasks') loadTasks() else if (name === 'dispatch') loadMrs() + else if (name === 'points') loadAgvPoints() } @@ -232,10 +303,10 @@ function onTabChange(name) { - + - + + + + +
+ 刷新 + 硬件映射点位编码与接驳台绑定不可改(置灰);仅「显示名」与「启用」可编辑 +
+ + + + + + + + + + + + + + + + + + + + + + + +
@@ -344,4 +454,6 @@ function onTabChange(name) { .dock-status { font-size: 13px; font-weight: 600; color: #67c23a; } .dock-card.busy .dock-status { color: #e6a23c; } .dock-ref { font-size: 12px; color: #e6a23c; margin-top: 2px; } +.mono { font-family: Consolas, Monaco, monospace; } +.disabled-text { color: #909399; } diff --git a/bj_power_mes/frontend/src/pages/PlcSend.vue b/bj_power_mes/frontend/src/pages/PlcSend.vue index 0285e2d..e059f0f 100644 --- a/bj_power_mes/frontend/src/pages/PlcSend.vue +++ b/bj_power_mes/frontend/src/pages/PlcSend.vue @@ -1,7 +1,7 @@ @@ -80,6 +107,7 @@ import { helpPlc } from '../help' // 多 Tab 范式:下发录入在前默认打开,下发记录在后点击才加载。 // 当前工位语义(2026-09-08):选择工件 SN 后由工件实际进度自动带出(只读); // 工位组合由工单「工艺组合」按工位号升序自动派生,不再手选。 +// 2026-11-03 断头路补全:下发记录支持「撤回」(误下发收回)与「人工完成」(PLC 信号丢失现场收口)。 const tab = ref('send') const send = reactive({ orderNo: '', sn: '', stationNo: 0 }) const query = reactive({ orderNo: '', status: '' }) @@ -89,8 +117,14 @@ const orderSns = ref([]) const currentStation = ref(0) const woSearching = ref(false) const snSearching = ref(false) +const withdrawVisible = ref(false) +const withdrawRow = ref(null) +const withdrawReason = ref('') -const plcStatusText = (s) => (s === 'DONE' ? '已完成' : '已下发') +const plcStatusText = (s) => ({ + SENT: '已下发', DONE: '已完成', CANCELLED: '已撤回', TIMEOUT: '已超时', REPLY_NG: '回复异常' +}[s] || s) +const statusTagType = (s) => (s === 'DONE' ? 'success' : s === 'CANCELLED' ? 'info' : 'warning') // 工单下拉远程搜索(keyword+limit=50,防数据炸弹) async function searchWorkOrders(kw) { @@ -148,6 +182,26 @@ async function doSend() { async function loadLogs() { logs.value = (await request.get('/plc/send-logs', { params: query })) || [] } +function openWithdraw(row) { + withdrawRow.value = row + withdrawReason.value = '' + withdrawVisible.value = true +} +async function doWithdraw() { + try { + await request.post('/plc/send-withdraw', { id: withdrawRow.value.id, reason: withdrawReason.value.trim() }) + ElMessage.success('已撤回,可重新下发') + withdrawVisible.value = false + loadLogs() + } catch (e) { /* 拦截器已提示 */ } +} +async function doManualDone(row) { + try { + await request.post('/plc/send-manual-done', { id: row.id }) + ElMessage.success('已人工完成,可下发下一条') + loadLogs() + } catch (e) { /* 拦截器已提示 */ } +} function onTab(name) { // 每次切回日志页都重新拉取(2026-10-19:原逻辑仅首次为空时加载,新下发记录切回不刷新) if (name === 'logs') loadLogs() diff --git a/bj_power_mes/frontend/src/pages/ProductType.vue b/bj_power_mes/frontend/src/pages/ProductType.vue index 1ea26a0..6e31170 100644 --- a/bj_power_mes/frontend/src/pages/ProductType.vue +++ b/bj_power_mes/frontend/src/pages/ProductType.vue @@ -68,7 +68,7 @@ 正常
- + - +