Files
bj_power/bj_power_wms/ent/alert_create.go
T
SunYF 6b98b21dd4 重构排产/叫料配送/时钟/终端事件驱动,清理 SHIPPED 废弃状态
时钟与 JWT:验签按「谁签发谁的时间为准」,向签发方取 /api/server-time,
对端地址由既有 BaseURL 自动推导;不再要求现场人工 w32tm 对时。

排产 C 方案:工单状态不再回写排产,排产只表示启用开关;启用排产是唯一
开工开关,未启用不允许建档上件;完工/取消后工单进度从工单派生、叫料池
按工单状态重算;逐日手改后合计为准;日期筛选默认空=全部日期。

叫料配送 B 方案:新增 DELIVERED 待签收态,货真到工位才从 PREPARED 转
DELIVERED、工人签收再转 DONE;PREPARED 在途不可签收/退库;叫料队列一屏
显示 PENDING+PREPARED、支持批量完成备料;配送链改按工位凑车,一张配送单
=一个托盘=一个工位,只在配送单页新建,未派车可删可改;新建弹窗直列有货
工位;派车硬门禁要求接驳台传感器检测到托盘;删除改为事务内复核状态、
带 PENDING 条件删单头,防止并发派车时误删。

装配记账:新增已装量 installedQty 与追溯绑定 traceBind,落实「总账=分账
之和」;追溯件绑定/撤销回补、非序列号件报工按单台用量自动扣已装;报工前
按工位×物料核对累计已签收 ≥ 已消耗,不够拦下。

工件与工位终端:建档/重上线增加上料位可达性校验与 PLC 送件、半截补齐防
重复扣库;终端去轮询改事件驱动(报警/工件到位/点位/停单即时推送),铃铛
只挂消息类预警、与待办角标分家;刷新保留拧紧录入;跨服务连线失败不再
误报成数据库故障;新增 BJ_POWER_DEV=1 单进程调试模式(不起守护/托盘)。

告警:新增处置字段 resolved_at/resolved_by,红点=待处置数,确认关闭才消。

清理:删除 migrate 中 SHIPPED→DELIVERED 兼容补丁;场景1测试断言改为
现行 PREPARED / DELIVERED;同步更新案例.md、现场对时操作卡.md 与 ent 生成代码。
2026-11-26 17:18:58 +08:00

1118 lines
30 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"bj_power_wms/ent/alert"
"context"
"errors"
"fmt"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
)
// AlertCreate is the builder for creating a Alert entity.
type AlertCreate struct {
config
mutation *AlertMutation
hooks []Hook
conflict []sql.ConflictOption
}
// SetRuleCode sets the "rule_code" field.
func (_c *AlertCreate) SetRuleCode(v string) *AlertCreate {
_c.mutation.SetRuleCode(v)
return _c
}
// SetLevel sets the "level" field.
func (_c *AlertCreate) SetLevel(v string) *AlertCreate {
_c.mutation.SetLevel(v)
return _c
}
// SetNillableLevel sets the "level" field if the given value is not nil.
func (_c *AlertCreate) SetNillableLevel(v *string) *AlertCreate {
if v != nil {
_c.SetLevel(*v)
}
return _c
}
// SetTitle sets the "title" field.
func (_c *AlertCreate) SetTitle(v string) *AlertCreate {
_c.mutation.SetTitle(v)
return _c
}
// SetContent sets the "content" field.
func (_c *AlertCreate) SetContent(v string) *AlertCreate {
_c.mutation.SetContent(v)
return _c
}
// SetTarget sets the "target" field.
func (_c *AlertCreate) SetTarget(v string) *AlertCreate {
_c.mutation.SetTarget(v)
return _c
}
// SetNillableTarget sets the "target" field if the given value is not nil.
func (_c *AlertCreate) SetNillableTarget(v *string) *AlertCreate {
if v != nil {
_c.SetTarget(*v)
}
return _c
}
// SetStatus sets the "status" field.
func (_c *AlertCreate) SetStatus(v string) *AlertCreate {
_c.mutation.SetStatus(v)
return _c
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_c *AlertCreate) SetNillableStatus(v *string) *AlertCreate {
if v != nil {
_c.SetStatus(*v)
}
return _c
}
// SetResolvedAt sets the "resolved_at" field.
func (_c *AlertCreate) SetResolvedAt(v int64) *AlertCreate {
_c.mutation.SetResolvedAt(v)
return _c
}
// SetNillableResolvedAt sets the "resolved_at" field if the given value is not nil.
func (_c *AlertCreate) SetNillableResolvedAt(v *int64) *AlertCreate {
if v != nil {
_c.SetResolvedAt(*v)
}
return _c
}
// SetResolvedBy sets the "resolved_by" field.
func (_c *AlertCreate) SetResolvedBy(v string) *AlertCreate {
_c.mutation.SetResolvedBy(v)
return _c
}
// SetNillableResolvedBy sets the "resolved_by" field if the given value is not nil.
func (_c *AlertCreate) SetNillableResolvedBy(v *string) *AlertCreate {
if v != nil {
_c.SetResolvedBy(*v)
}
return _c
}
// SetCreatedAt sets the "created_at" field.
func (_c *AlertCreate) SetCreatedAt(v int64) *AlertCreate {
_c.mutation.SetCreatedAt(v)
return _c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_c *AlertCreate) SetNillableCreatedAt(v *int64) *AlertCreate {
if v != nil {
_c.SetCreatedAt(*v)
}
return _c
}
// SetUpdatedAt sets the "updated_at" field.
func (_c *AlertCreate) SetUpdatedAt(v int64) *AlertCreate {
_c.mutation.SetUpdatedAt(v)
return _c
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func (_c *AlertCreate) SetNillableUpdatedAt(v *int64) *AlertCreate {
if v != nil {
_c.SetUpdatedAt(*v)
}
return _c
}
// Mutation returns the AlertMutation object of the builder.
func (_c *AlertCreate) Mutation() *AlertMutation {
return _c.mutation
}
// Save creates the Alert in the database.
func (_c *AlertCreate) Save(ctx context.Context) (*Alert, error) {
_c.defaults()
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
}
// SaveX calls Save and panics if Save returns an error.
func (_c *AlertCreate) SaveX(ctx context.Context) *Alert {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *AlertCreate) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *AlertCreate) 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 *AlertCreate) defaults() {
if _, ok := _c.mutation.Level(); !ok {
v := alert.DefaultLevel
_c.mutation.SetLevel(v)
}
if _, ok := _c.mutation.Status(); !ok {
v := alert.DefaultStatus
_c.mutation.SetStatus(v)
}
if _, ok := _c.mutation.ResolvedBy(); !ok {
v := alert.DefaultResolvedBy
_c.mutation.SetResolvedBy(v)
}
if _, ok := _c.mutation.CreatedAt(); !ok {
v := alert.DefaultCreatedAt()
_c.mutation.SetCreatedAt(v)
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
v := alert.DefaultUpdatedAt()
_c.mutation.SetUpdatedAt(v)
}
}
// check runs all checks and user-defined validators on the builder.
func (_c *AlertCreate) check() error {
if _, ok := _c.mutation.RuleCode(); !ok {
return &ValidationError{Name: "rule_code", err: errors.New(`ent: missing required field "Alert.rule_code"`)}
}
if _, ok := _c.mutation.Level(); !ok {
return &ValidationError{Name: "level", err: errors.New(`ent: missing required field "Alert.level"`)}
}
if v, ok := _c.mutation.Level(); ok {
if err := alert.LevelValidator(v); err != nil {
return &ValidationError{Name: "level", err: fmt.Errorf(`ent: validator failed for field "Alert.level": %w`, err)}
}
}
if _, ok := _c.mutation.Title(); !ok {
return &ValidationError{Name: "title", err: errors.New(`ent: missing required field "Alert.title"`)}
}
if _, ok := _c.mutation.Content(); !ok {
return &ValidationError{Name: "content", err: errors.New(`ent: missing required field "Alert.content"`)}
}
if _, ok := _c.mutation.Status(); !ok {
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "Alert.status"`)}
}
if v, ok := _c.mutation.Status(); ok {
if err := alert.StatusValidator(v); err != nil {
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "Alert.status": %w`, err)}
}
}
if _, ok := _c.mutation.ResolvedBy(); !ok {
return &ValidationError{Name: "resolved_by", err: errors.New(`ent: missing required field "Alert.resolved_by"`)}
}
if _, ok := _c.mutation.CreatedAt(); !ok {
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "Alert.created_at"`)}
}
if _, ok := _c.mutation.UpdatedAt(); !ok {
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "Alert.updated_at"`)}
}
return nil
}
func (_c *AlertCreate) sqlSave(ctx context.Context) (*Alert, 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 *AlertCreate) createSpec() (*Alert, *sqlgraph.CreateSpec) {
var (
_node = &Alert{config: _c.config}
_spec = sqlgraph.NewCreateSpec(alert.Table, sqlgraph.NewFieldSpec(alert.FieldID, field.TypeInt))
)
_spec.OnConflict = _c.conflict
if value, ok := _c.mutation.RuleCode(); ok {
_spec.SetField(alert.FieldRuleCode, field.TypeString, value)
_node.RuleCode = value
}
if value, ok := _c.mutation.Level(); ok {
_spec.SetField(alert.FieldLevel, field.TypeString, value)
_node.Level = value
}
if value, ok := _c.mutation.Title(); ok {
_spec.SetField(alert.FieldTitle, field.TypeString, value)
_node.Title = value
}
if value, ok := _c.mutation.Content(); ok {
_spec.SetField(alert.FieldContent, field.TypeString, value)
_node.Content = value
}
if value, ok := _c.mutation.Target(); ok {
_spec.SetField(alert.FieldTarget, field.TypeString, value)
_node.Target = value
}
if value, ok := _c.mutation.Status(); ok {
_spec.SetField(alert.FieldStatus, field.TypeString, value)
_node.Status = value
}
if value, ok := _c.mutation.ResolvedAt(); ok {
_spec.SetField(alert.FieldResolvedAt, field.TypeInt64, value)
_node.ResolvedAt = value
}
if value, ok := _c.mutation.ResolvedBy(); ok {
_spec.SetField(alert.FieldResolvedBy, field.TypeString, value)
_node.ResolvedBy = value
}
if value, ok := _c.mutation.CreatedAt(); ok {
_spec.SetField(alert.FieldCreatedAt, field.TypeInt64, value)
_node.CreatedAt = value
}
if value, ok := _c.mutation.UpdatedAt(); ok {
_spec.SetField(alert.FieldUpdatedAt, field.TypeInt64, value)
_node.UpdatedAt = value
}
return _node, _spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.Alert.Create().
// SetRuleCode(v).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.AlertUpsert) {
// SetRuleCode(v+v).
// }).
// Exec(ctx)
func (_c *AlertCreate) OnConflict(opts ...sql.ConflictOption) *AlertUpsertOne {
_c.conflict = opts
return &AlertUpsertOne{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.Alert.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *AlertCreate) OnConflictColumns(columns ...string) *AlertUpsertOne {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &AlertUpsertOne{
create: _c,
}
}
type (
// AlertUpsertOne is the builder for "upsert"-ing
// one Alert node.
AlertUpsertOne struct {
create *AlertCreate
}
// AlertUpsert is the "OnConflict" setter.
AlertUpsert struct {
*sql.UpdateSet
}
)
// SetRuleCode sets the "rule_code" field.
func (u *AlertUpsert) SetRuleCode(v string) *AlertUpsert {
u.Set(alert.FieldRuleCode, v)
return u
}
// UpdateRuleCode sets the "rule_code" field to the value that was provided on create.
func (u *AlertUpsert) UpdateRuleCode() *AlertUpsert {
u.SetExcluded(alert.FieldRuleCode)
return u
}
// SetLevel sets the "level" field.
func (u *AlertUpsert) SetLevel(v string) *AlertUpsert {
u.Set(alert.FieldLevel, v)
return u
}
// UpdateLevel sets the "level" field to the value that was provided on create.
func (u *AlertUpsert) UpdateLevel() *AlertUpsert {
u.SetExcluded(alert.FieldLevel)
return u
}
// SetTitle sets the "title" field.
func (u *AlertUpsert) SetTitle(v string) *AlertUpsert {
u.Set(alert.FieldTitle, v)
return u
}
// UpdateTitle sets the "title" field to the value that was provided on create.
func (u *AlertUpsert) UpdateTitle() *AlertUpsert {
u.SetExcluded(alert.FieldTitle)
return u
}
// SetContent sets the "content" field.
func (u *AlertUpsert) SetContent(v string) *AlertUpsert {
u.Set(alert.FieldContent, v)
return u
}
// UpdateContent sets the "content" field to the value that was provided on create.
func (u *AlertUpsert) UpdateContent() *AlertUpsert {
u.SetExcluded(alert.FieldContent)
return u
}
// SetTarget sets the "target" field.
func (u *AlertUpsert) SetTarget(v string) *AlertUpsert {
u.Set(alert.FieldTarget, v)
return u
}
// UpdateTarget sets the "target" field to the value that was provided on create.
func (u *AlertUpsert) UpdateTarget() *AlertUpsert {
u.SetExcluded(alert.FieldTarget)
return u
}
// ClearTarget clears the value of the "target" field.
func (u *AlertUpsert) ClearTarget() *AlertUpsert {
u.SetNull(alert.FieldTarget)
return u
}
// SetStatus sets the "status" field.
func (u *AlertUpsert) SetStatus(v string) *AlertUpsert {
u.Set(alert.FieldStatus, v)
return u
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *AlertUpsert) UpdateStatus() *AlertUpsert {
u.SetExcluded(alert.FieldStatus)
return u
}
// SetResolvedAt sets the "resolved_at" field.
func (u *AlertUpsert) SetResolvedAt(v int64) *AlertUpsert {
u.Set(alert.FieldResolvedAt, v)
return u
}
// UpdateResolvedAt sets the "resolved_at" field to the value that was provided on create.
func (u *AlertUpsert) UpdateResolvedAt() *AlertUpsert {
u.SetExcluded(alert.FieldResolvedAt)
return u
}
// AddResolvedAt adds v to the "resolved_at" field.
func (u *AlertUpsert) AddResolvedAt(v int64) *AlertUpsert {
u.Add(alert.FieldResolvedAt, v)
return u
}
// ClearResolvedAt clears the value of the "resolved_at" field.
func (u *AlertUpsert) ClearResolvedAt() *AlertUpsert {
u.SetNull(alert.FieldResolvedAt)
return u
}
// SetResolvedBy sets the "resolved_by" field.
func (u *AlertUpsert) SetResolvedBy(v string) *AlertUpsert {
u.Set(alert.FieldResolvedBy, v)
return u
}
// UpdateResolvedBy sets the "resolved_by" field to the value that was provided on create.
func (u *AlertUpsert) UpdateResolvedBy() *AlertUpsert {
u.SetExcluded(alert.FieldResolvedBy)
return u
}
// SetCreatedAt sets the "created_at" field.
func (u *AlertUpsert) SetCreatedAt(v int64) *AlertUpsert {
u.Set(alert.FieldCreatedAt, v)
return u
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *AlertUpsert) UpdateCreatedAt() *AlertUpsert {
u.SetExcluded(alert.FieldCreatedAt)
return u
}
// AddCreatedAt adds v to the "created_at" field.
func (u *AlertUpsert) AddCreatedAt(v int64) *AlertUpsert {
u.Add(alert.FieldCreatedAt, v)
return u
}
// SetUpdatedAt sets the "updated_at" field.
func (u *AlertUpsert) SetUpdatedAt(v int64) *AlertUpsert {
u.Set(alert.FieldUpdatedAt, v)
return u
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *AlertUpsert) UpdateUpdatedAt() *AlertUpsert {
u.SetExcluded(alert.FieldUpdatedAt)
return u
}
// AddUpdatedAt adds v to the "updated_at" field.
func (u *AlertUpsert) AddUpdatedAt(v int64) *AlertUpsert {
u.Add(alert.FieldUpdatedAt, v)
return u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
// client.Alert.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *AlertUpsertOne) UpdateNewValues() *AlertUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.Alert.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *AlertUpsertOne) Ignore() *AlertUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
return u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *AlertUpsertOne) DoNothing() *AlertUpsertOne {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the AlertCreate.OnConflict
// documentation for more info.
func (u *AlertUpsertOne) Update(set func(*AlertUpsert)) *AlertUpsertOne {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&AlertUpsert{UpdateSet: update})
}))
return u
}
// SetRuleCode sets the "rule_code" field.
func (u *AlertUpsertOne) SetRuleCode(v string) *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.SetRuleCode(v)
})
}
// UpdateRuleCode sets the "rule_code" field to the value that was provided on create.
func (u *AlertUpsertOne) UpdateRuleCode() *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.UpdateRuleCode()
})
}
// SetLevel sets the "level" field.
func (u *AlertUpsertOne) SetLevel(v string) *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.SetLevel(v)
})
}
// UpdateLevel sets the "level" field to the value that was provided on create.
func (u *AlertUpsertOne) UpdateLevel() *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.UpdateLevel()
})
}
// SetTitle sets the "title" field.
func (u *AlertUpsertOne) SetTitle(v string) *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.SetTitle(v)
})
}
// UpdateTitle sets the "title" field to the value that was provided on create.
func (u *AlertUpsertOne) UpdateTitle() *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.UpdateTitle()
})
}
// SetContent sets the "content" field.
func (u *AlertUpsertOne) SetContent(v string) *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.SetContent(v)
})
}
// UpdateContent sets the "content" field to the value that was provided on create.
func (u *AlertUpsertOne) UpdateContent() *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.UpdateContent()
})
}
// SetTarget sets the "target" field.
func (u *AlertUpsertOne) SetTarget(v string) *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.SetTarget(v)
})
}
// UpdateTarget sets the "target" field to the value that was provided on create.
func (u *AlertUpsertOne) UpdateTarget() *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.UpdateTarget()
})
}
// ClearTarget clears the value of the "target" field.
func (u *AlertUpsertOne) ClearTarget() *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.ClearTarget()
})
}
// SetStatus sets the "status" field.
func (u *AlertUpsertOne) SetStatus(v string) *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.SetStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *AlertUpsertOne) UpdateStatus() *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.UpdateStatus()
})
}
// SetResolvedAt sets the "resolved_at" field.
func (u *AlertUpsertOne) SetResolvedAt(v int64) *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.SetResolvedAt(v)
})
}
// AddResolvedAt adds v to the "resolved_at" field.
func (u *AlertUpsertOne) AddResolvedAt(v int64) *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.AddResolvedAt(v)
})
}
// UpdateResolvedAt sets the "resolved_at" field to the value that was provided on create.
func (u *AlertUpsertOne) UpdateResolvedAt() *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.UpdateResolvedAt()
})
}
// ClearResolvedAt clears the value of the "resolved_at" field.
func (u *AlertUpsertOne) ClearResolvedAt() *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.ClearResolvedAt()
})
}
// SetResolvedBy sets the "resolved_by" field.
func (u *AlertUpsertOne) SetResolvedBy(v string) *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.SetResolvedBy(v)
})
}
// UpdateResolvedBy sets the "resolved_by" field to the value that was provided on create.
func (u *AlertUpsertOne) UpdateResolvedBy() *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.UpdateResolvedBy()
})
}
// SetCreatedAt sets the "created_at" field.
func (u *AlertUpsertOne) SetCreatedAt(v int64) *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.SetCreatedAt(v)
})
}
// AddCreatedAt adds v to the "created_at" field.
func (u *AlertUpsertOne) AddCreatedAt(v int64) *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.AddCreatedAt(v)
})
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *AlertUpsertOne) UpdateCreatedAt() *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.UpdateCreatedAt()
})
}
// SetUpdatedAt sets the "updated_at" field.
func (u *AlertUpsertOne) SetUpdatedAt(v int64) *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.SetUpdatedAt(v)
})
}
// AddUpdatedAt adds v to the "updated_at" field.
func (u *AlertUpsertOne) AddUpdatedAt(v int64) *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.AddUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *AlertUpsertOne) UpdateUpdatedAt() *AlertUpsertOne {
return u.Update(func(s *AlertUpsert) {
s.UpdateUpdatedAt()
})
}
// Exec executes the query.
func (u *AlertUpsertOne) Exec(ctx context.Context) error {
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for AlertCreate.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *AlertUpsertOne) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}
// Exec executes the UPSERT query and returns the inserted/updated ID.
func (u *AlertUpsertOne) ID(ctx context.Context) (id int, err error) {
node, err := u.create.Save(ctx)
if err != nil {
return id, err
}
return node.ID, nil
}
// IDX is like ID, but panics if an error occurs.
func (u *AlertUpsertOne) IDX(ctx context.Context) int {
id, err := u.ID(ctx)
if err != nil {
panic(err)
}
return id
}
// AlertCreateBulk is the builder for creating many Alert entities in bulk.
type AlertCreateBulk struct {
config
err error
builders []*AlertCreate
conflict []sql.ConflictOption
}
// Save creates the Alert entities in the database.
func (_c *AlertCreateBulk) Save(ctx context.Context) ([]*Alert, error) {
if _c.err != nil {
return nil, _c.err
}
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
nodes := make([]*Alert, 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.(*AlertMutation)
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}
spec.OnConflict = _c.conflict
// 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 *AlertCreateBulk) SaveX(ctx context.Context) []*Alert {
v, err := _c.Save(ctx)
if err != nil {
panic(err)
}
return v
}
// Exec executes the query.
func (_c *AlertCreateBulk) Exec(ctx context.Context) error {
_, err := _c.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_c *AlertCreateBulk) ExecX(ctx context.Context) {
if err := _c.Exec(ctx); err != nil {
panic(err)
}
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.Alert.CreateBulk(builders...).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.AlertUpsert) {
// SetRuleCode(v+v).
// }).
// Exec(ctx)
func (_c *AlertCreateBulk) OnConflict(opts ...sql.ConflictOption) *AlertUpsertBulk {
_c.conflict = opts
return &AlertUpsertBulk{
create: _c,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.Alert.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func (_c *AlertCreateBulk) OnConflictColumns(columns ...string) *AlertUpsertBulk {
_c.conflict = append(_c.conflict, sql.ConflictColumns(columns...))
return &AlertUpsertBulk{
create: _c,
}
}
// AlertUpsertBulk is the builder for "upsert"-ing
// a bulk of Alert nodes.
type AlertUpsertBulk struct {
create *AlertCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.Alert.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func (u *AlertUpsertBulk) UpdateNewValues() *AlertUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWithNewValues())
return u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.Alert.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func (u *AlertUpsertBulk) Ignore() *AlertUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWithIgnore())
return u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func (u *AlertUpsertBulk) DoNothing() *AlertUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.DoNothing())
return u
}
// Update allows overriding fields `UPDATE` values. See the AlertCreateBulk.OnConflict
// documentation for more info.
func (u *AlertUpsertBulk) Update(set func(*AlertUpsert)) *AlertUpsertBulk {
u.create.conflict = append(u.create.conflict, sql.ResolveWith(func(update *sql.UpdateSet) {
set(&AlertUpsert{UpdateSet: update})
}))
return u
}
// SetRuleCode sets the "rule_code" field.
func (u *AlertUpsertBulk) SetRuleCode(v string) *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.SetRuleCode(v)
})
}
// UpdateRuleCode sets the "rule_code" field to the value that was provided on create.
func (u *AlertUpsertBulk) UpdateRuleCode() *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.UpdateRuleCode()
})
}
// SetLevel sets the "level" field.
func (u *AlertUpsertBulk) SetLevel(v string) *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.SetLevel(v)
})
}
// UpdateLevel sets the "level" field to the value that was provided on create.
func (u *AlertUpsertBulk) UpdateLevel() *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.UpdateLevel()
})
}
// SetTitle sets the "title" field.
func (u *AlertUpsertBulk) SetTitle(v string) *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.SetTitle(v)
})
}
// UpdateTitle sets the "title" field to the value that was provided on create.
func (u *AlertUpsertBulk) UpdateTitle() *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.UpdateTitle()
})
}
// SetContent sets the "content" field.
func (u *AlertUpsertBulk) SetContent(v string) *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.SetContent(v)
})
}
// UpdateContent sets the "content" field to the value that was provided on create.
func (u *AlertUpsertBulk) UpdateContent() *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.UpdateContent()
})
}
// SetTarget sets the "target" field.
func (u *AlertUpsertBulk) SetTarget(v string) *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.SetTarget(v)
})
}
// UpdateTarget sets the "target" field to the value that was provided on create.
func (u *AlertUpsertBulk) UpdateTarget() *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.UpdateTarget()
})
}
// ClearTarget clears the value of the "target" field.
func (u *AlertUpsertBulk) ClearTarget() *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.ClearTarget()
})
}
// SetStatus sets the "status" field.
func (u *AlertUpsertBulk) SetStatus(v string) *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.SetStatus(v)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func (u *AlertUpsertBulk) UpdateStatus() *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.UpdateStatus()
})
}
// SetResolvedAt sets the "resolved_at" field.
func (u *AlertUpsertBulk) SetResolvedAt(v int64) *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.SetResolvedAt(v)
})
}
// AddResolvedAt adds v to the "resolved_at" field.
func (u *AlertUpsertBulk) AddResolvedAt(v int64) *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.AddResolvedAt(v)
})
}
// UpdateResolvedAt sets the "resolved_at" field to the value that was provided on create.
func (u *AlertUpsertBulk) UpdateResolvedAt() *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.UpdateResolvedAt()
})
}
// ClearResolvedAt clears the value of the "resolved_at" field.
func (u *AlertUpsertBulk) ClearResolvedAt() *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.ClearResolvedAt()
})
}
// SetResolvedBy sets the "resolved_by" field.
func (u *AlertUpsertBulk) SetResolvedBy(v string) *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.SetResolvedBy(v)
})
}
// UpdateResolvedBy sets the "resolved_by" field to the value that was provided on create.
func (u *AlertUpsertBulk) UpdateResolvedBy() *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.UpdateResolvedBy()
})
}
// SetCreatedAt sets the "created_at" field.
func (u *AlertUpsertBulk) SetCreatedAt(v int64) *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.SetCreatedAt(v)
})
}
// AddCreatedAt adds v to the "created_at" field.
func (u *AlertUpsertBulk) AddCreatedAt(v int64) *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.AddCreatedAt(v)
})
}
// UpdateCreatedAt sets the "created_at" field to the value that was provided on create.
func (u *AlertUpsertBulk) UpdateCreatedAt() *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.UpdateCreatedAt()
})
}
// SetUpdatedAt sets the "updated_at" field.
func (u *AlertUpsertBulk) SetUpdatedAt(v int64) *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.SetUpdatedAt(v)
})
}
// AddUpdatedAt adds v to the "updated_at" field.
func (u *AlertUpsertBulk) AddUpdatedAt(v int64) *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.AddUpdatedAt(v)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func (u *AlertUpsertBulk) UpdateUpdatedAt() *AlertUpsertBulk {
return u.Update(func(s *AlertUpsert) {
s.UpdateUpdatedAt()
})
}
// Exec executes the query.
func (u *AlertUpsertBulk) Exec(ctx context.Context) error {
if u.create.err != nil {
return u.create.err
}
for i, b := range u.create.builders {
if len(b.conflict) != 0 {
return fmt.Errorf("ent: OnConflict was set for builder %d. Set it on the AlertCreateBulk instead", i)
}
}
if len(u.create.conflict) == 0 {
return errors.New("ent: missing options for AlertCreateBulk.OnConflict")
}
return u.create.Exec(ctx)
}
// ExecX is like Exec, but panics if an error occurs.
func (u *AlertUpsertBulk) ExecX(ctx context.Context) {
if err := u.create.Exec(ctx); err != nil {
panic(err)
}
}