时钟与 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 生成代码。
648 lines
18 KiB
Go
648 lines
18 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"bj_power_wms/ent/alert"
|
|
"bj_power_wms/ent/predicate"
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
"entgo.io/ent/schema/field"
|
|
)
|
|
|
|
// AlertUpdate is the builder for updating Alert entities.
|
|
type AlertUpdate struct {
|
|
config
|
|
hooks []Hook
|
|
mutation *AlertMutation
|
|
}
|
|
|
|
// Where appends a list predicates to the AlertUpdate builder.
|
|
func (_u *AlertUpdate) Where(ps ...predicate.Alert) *AlertUpdate {
|
|
_u.mutation.Where(ps...)
|
|
return _u
|
|
}
|
|
|
|
// SetRuleCode sets the "rule_code" field.
|
|
func (_u *AlertUpdate) SetRuleCode(v string) *AlertUpdate {
|
|
_u.mutation.SetRuleCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableRuleCode sets the "rule_code" field if the given value is not nil.
|
|
func (_u *AlertUpdate) SetNillableRuleCode(v *string) *AlertUpdate {
|
|
if v != nil {
|
|
_u.SetRuleCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetLevel sets the "level" field.
|
|
func (_u *AlertUpdate) SetLevel(v string) *AlertUpdate {
|
|
_u.mutation.SetLevel(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableLevel sets the "level" field if the given value is not nil.
|
|
func (_u *AlertUpdate) SetNillableLevel(v *string) *AlertUpdate {
|
|
if v != nil {
|
|
_u.SetLevel(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTitle sets the "title" field.
|
|
func (_u *AlertUpdate) SetTitle(v string) *AlertUpdate {
|
|
_u.mutation.SetTitle(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTitle sets the "title" field if the given value is not nil.
|
|
func (_u *AlertUpdate) SetNillableTitle(v *string) *AlertUpdate {
|
|
if v != nil {
|
|
_u.SetTitle(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetContent sets the "content" field.
|
|
func (_u *AlertUpdate) SetContent(v string) *AlertUpdate {
|
|
_u.mutation.SetContent(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableContent sets the "content" field if the given value is not nil.
|
|
func (_u *AlertUpdate) SetNillableContent(v *string) *AlertUpdate {
|
|
if v != nil {
|
|
_u.SetContent(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTarget sets the "target" field.
|
|
func (_u *AlertUpdate) SetTarget(v string) *AlertUpdate {
|
|
_u.mutation.SetTarget(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTarget sets the "target" field if the given value is not nil.
|
|
func (_u *AlertUpdate) SetNillableTarget(v *string) *AlertUpdate {
|
|
if v != nil {
|
|
_u.SetTarget(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearTarget clears the value of the "target" field.
|
|
func (_u *AlertUpdate) ClearTarget() *AlertUpdate {
|
|
_u.mutation.ClearTarget()
|
|
return _u
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_u *AlertUpdate) SetStatus(v string) *AlertUpdate {
|
|
_u.mutation.SetStatus(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (_u *AlertUpdate) SetNillableStatus(v *string) *AlertUpdate {
|
|
if v != nil {
|
|
_u.SetStatus(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetResolvedAt sets the "resolved_at" field.
|
|
func (_u *AlertUpdate) SetResolvedAt(v int64) *AlertUpdate {
|
|
_u.mutation.ResetResolvedAt()
|
|
_u.mutation.SetResolvedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableResolvedAt sets the "resolved_at" field if the given value is not nil.
|
|
func (_u *AlertUpdate) SetNillableResolvedAt(v *int64) *AlertUpdate {
|
|
if v != nil {
|
|
_u.SetResolvedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddResolvedAt adds value to the "resolved_at" field.
|
|
func (_u *AlertUpdate) AddResolvedAt(v int64) *AlertUpdate {
|
|
_u.mutation.AddResolvedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearResolvedAt clears the value of the "resolved_at" field.
|
|
func (_u *AlertUpdate) ClearResolvedAt() *AlertUpdate {
|
|
_u.mutation.ClearResolvedAt()
|
|
return _u
|
|
}
|
|
|
|
// SetResolvedBy sets the "resolved_by" field.
|
|
func (_u *AlertUpdate) SetResolvedBy(v string) *AlertUpdate {
|
|
_u.mutation.SetResolvedBy(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableResolvedBy sets the "resolved_by" field if the given value is not nil.
|
|
func (_u *AlertUpdate) SetNillableResolvedBy(v *string) *AlertUpdate {
|
|
if v != nil {
|
|
_u.SetResolvedBy(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *AlertUpdate) SetCreatedAt(v int64) *AlertUpdate {
|
|
_u.mutation.ResetCreatedAt()
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *AlertUpdate) SetNillableCreatedAt(v *int64) *AlertUpdate {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddCreatedAt adds value to the "created_at" field.
|
|
func (_u *AlertUpdate) AddCreatedAt(v int64) *AlertUpdate {
|
|
_u.mutation.AddCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *AlertUpdate) SetUpdatedAt(v int64) *AlertUpdate {
|
|
_u.mutation.ResetUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_u *AlertUpdate) SetNillableUpdatedAt(v *int64) *AlertUpdate {
|
|
if v != nil {
|
|
_u.SetUpdatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddUpdatedAt adds value to the "updated_at" field.
|
|
func (_u *AlertUpdate) AddUpdatedAt(v int64) *AlertUpdate {
|
|
_u.mutation.AddUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the AlertMutation object of the builder.
|
|
func (_u *AlertUpdate) Mutation() *AlertMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Save executes the query and returns the number of nodes affected by the update operation.
|
|
func (_u *AlertUpdate) 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 *AlertUpdate) SaveX(ctx context.Context) int {
|
|
affected, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return affected
|
|
}
|
|
|
|
// Exec executes the query.
|
|
func (_u *AlertUpdate) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *AlertUpdate) 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 *AlertUpdate) check() error {
|
|
if v, ok := _u.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 v, ok := _u.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)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *AlertUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(alert.Table, alert.Columns, sqlgraph.NewFieldSpec(alert.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.RuleCode(); ok {
|
|
_spec.SetField(alert.FieldRuleCode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Level(); ok {
|
|
_spec.SetField(alert.FieldLevel, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Title(); ok {
|
|
_spec.SetField(alert.FieldTitle, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Content(); ok {
|
|
_spec.SetField(alert.FieldContent, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Target(); ok {
|
|
_spec.SetField(alert.FieldTarget, field.TypeString, value)
|
|
}
|
|
if _u.mutation.TargetCleared() {
|
|
_spec.ClearField(alert.FieldTarget, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Status(); ok {
|
|
_spec.SetField(alert.FieldStatus, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.ResolvedAt(); ok {
|
|
_spec.SetField(alert.FieldResolvedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedResolvedAt(); ok {
|
|
_spec.AddField(alert.FieldResolvedAt, field.TypeInt64, value)
|
|
}
|
|
if _u.mutation.ResolvedAtCleared() {
|
|
_spec.ClearField(alert.FieldResolvedAt, field.TypeInt64)
|
|
}
|
|
if value, ok := _u.mutation.ResolvedBy(); ok {
|
|
_spec.SetField(alert.FieldResolvedBy, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(alert.FieldCreatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedCreatedAt(); ok {
|
|
_spec.AddField(alert.FieldCreatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(alert.FieldUpdatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedUpdatedAt(); ok {
|
|
_spec.AddField(alert.FieldUpdatedAt, field.TypeInt64, value)
|
|
}
|
|
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
|
|
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
|
err = &NotFoundError{alert.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return 0, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|
|
|
|
// AlertUpdateOne is the builder for updating a single Alert entity.
|
|
type AlertUpdateOne struct {
|
|
config
|
|
fields []string
|
|
hooks []Hook
|
|
mutation *AlertMutation
|
|
}
|
|
|
|
// SetRuleCode sets the "rule_code" field.
|
|
func (_u *AlertUpdateOne) SetRuleCode(v string) *AlertUpdateOne {
|
|
_u.mutation.SetRuleCode(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableRuleCode sets the "rule_code" field if the given value is not nil.
|
|
func (_u *AlertUpdateOne) SetNillableRuleCode(v *string) *AlertUpdateOne {
|
|
if v != nil {
|
|
_u.SetRuleCode(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetLevel sets the "level" field.
|
|
func (_u *AlertUpdateOne) SetLevel(v string) *AlertUpdateOne {
|
|
_u.mutation.SetLevel(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableLevel sets the "level" field if the given value is not nil.
|
|
func (_u *AlertUpdateOne) SetNillableLevel(v *string) *AlertUpdateOne {
|
|
if v != nil {
|
|
_u.SetLevel(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTitle sets the "title" field.
|
|
func (_u *AlertUpdateOne) SetTitle(v string) *AlertUpdateOne {
|
|
_u.mutation.SetTitle(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTitle sets the "title" field if the given value is not nil.
|
|
func (_u *AlertUpdateOne) SetNillableTitle(v *string) *AlertUpdateOne {
|
|
if v != nil {
|
|
_u.SetTitle(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetContent sets the "content" field.
|
|
func (_u *AlertUpdateOne) SetContent(v string) *AlertUpdateOne {
|
|
_u.mutation.SetContent(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableContent sets the "content" field if the given value is not nil.
|
|
func (_u *AlertUpdateOne) SetNillableContent(v *string) *AlertUpdateOne {
|
|
if v != nil {
|
|
_u.SetContent(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetTarget sets the "target" field.
|
|
func (_u *AlertUpdateOne) SetTarget(v string) *AlertUpdateOne {
|
|
_u.mutation.SetTarget(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableTarget sets the "target" field if the given value is not nil.
|
|
func (_u *AlertUpdateOne) SetNillableTarget(v *string) *AlertUpdateOne {
|
|
if v != nil {
|
|
_u.SetTarget(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// ClearTarget clears the value of the "target" field.
|
|
func (_u *AlertUpdateOne) ClearTarget() *AlertUpdateOne {
|
|
_u.mutation.ClearTarget()
|
|
return _u
|
|
}
|
|
|
|
// SetStatus sets the "status" field.
|
|
func (_u *AlertUpdateOne) SetStatus(v string) *AlertUpdateOne {
|
|
_u.mutation.SetStatus(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableStatus sets the "status" field if the given value is not nil.
|
|
func (_u *AlertUpdateOne) SetNillableStatus(v *string) *AlertUpdateOne {
|
|
if v != nil {
|
|
_u.SetStatus(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetResolvedAt sets the "resolved_at" field.
|
|
func (_u *AlertUpdateOne) SetResolvedAt(v int64) *AlertUpdateOne {
|
|
_u.mutation.ResetResolvedAt()
|
|
_u.mutation.SetResolvedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableResolvedAt sets the "resolved_at" field if the given value is not nil.
|
|
func (_u *AlertUpdateOne) SetNillableResolvedAt(v *int64) *AlertUpdateOne {
|
|
if v != nil {
|
|
_u.SetResolvedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddResolvedAt adds value to the "resolved_at" field.
|
|
func (_u *AlertUpdateOne) AddResolvedAt(v int64) *AlertUpdateOne {
|
|
_u.mutation.AddResolvedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// ClearResolvedAt clears the value of the "resolved_at" field.
|
|
func (_u *AlertUpdateOne) ClearResolvedAt() *AlertUpdateOne {
|
|
_u.mutation.ClearResolvedAt()
|
|
return _u
|
|
}
|
|
|
|
// SetResolvedBy sets the "resolved_by" field.
|
|
func (_u *AlertUpdateOne) SetResolvedBy(v string) *AlertUpdateOne {
|
|
_u.mutation.SetResolvedBy(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableResolvedBy sets the "resolved_by" field if the given value is not nil.
|
|
func (_u *AlertUpdateOne) SetNillableResolvedBy(v *string) *AlertUpdateOne {
|
|
if v != nil {
|
|
_u.SetResolvedBy(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// SetCreatedAt sets the "created_at" field.
|
|
func (_u *AlertUpdateOne) SetCreatedAt(v int64) *AlertUpdateOne {
|
|
_u.mutation.ResetCreatedAt()
|
|
_u.mutation.SetCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
|
func (_u *AlertUpdateOne) SetNillableCreatedAt(v *int64) *AlertUpdateOne {
|
|
if v != nil {
|
|
_u.SetCreatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddCreatedAt adds value to the "created_at" field.
|
|
func (_u *AlertUpdateOne) AddCreatedAt(v int64) *AlertUpdateOne {
|
|
_u.mutation.AddCreatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetUpdatedAt sets the "updated_at" field.
|
|
func (_u *AlertUpdateOne) SetUpdatedAt(v int64) *AlertUpdateOne {
|
|
_u.mutation.ResetUpdatedAt()
|
|
_u.mutation.SetUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
|
func (_u *AlertUpdateOne) SetNillableUpdatedAt(v *int64) *AlertUpdateOne {
|
|
if v != nil {
|
|
_u.SetUpdatedAt(*v)
|
|
}
|
|
return _u
|
|
}
|
|
|
|
// AddUpdatedAt adds value to the "updated_at" field.
|
|
func (_u *AlertUpdateOne) AddUpdatedAt(v int64) *AlertUpdateOne {
|
|
_u.mutation.AddUpdatedAt(v)
|
|
return _u
|
|
}
|
|
|
|
// Mutation returns the AlertMutation object of the builder.
|
|
func (_u *AlertUpdateOne) Mutation() *AlertMutation {
|
|
return _u.mutation
|
|
}
|
|
|
|
// Where appends a list predicates to the AlertUpdate builder.
|
|
func (_u *AlertUpdateOne) Where(ps ...predicate.Alert) *AlertUpdateOne {
|
|
_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 *AlertUpdateOne) Select(field string, fields ...string) *AlertUpdateOne {
|
|
_u.fields = append([]string{field}, fields...)
|
|
return _u
|
|
}
|
|
|
|
// Save executes the query and returns the updated Alert entity.
|
|
func (_u *AlertUpdateOne) Save(ctx context.Context) (*Alert, error) {
|
|
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
|
|
}
|
|
|
|
// SaveX is like Save, but panics if an error occurs.
|
|
func (_u *AlertUpdateOne) SaveX(ctx context.Context) *Alert {
|
|
node, err := _u.Save(ctx)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return node
|
|
}
|
|
|
|
// Exec executes the query on the entity.
|
|
func (_u *AlertUpdateOne) Exec(ctx context.Context) error {
|
|
_, err := _u.Save(ctx)
|
|
return err
|
|
}
|
|
|
|
// ExecX is like Exec, but panics if an error occurs.
|
|
func (_u *AlertUpdateOne) 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 *AlertUpdateOne) check() error {
|
|
if v, ok := _u.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 v, ok := _u.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)}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (_u *AlertUpdateOne) sqlSave(ctx context.Context) (_node *Alert, err error) {
|
|
if err := _u.check(); err != nil {
|
|
return _node, err
|
|
}
|
|
_spec := sqlgraph.NewUpdateSpec(alert.Table, alert.Columns, sqlgraph.NewFieldSpec(alert.FieldID, field.TypeInt))
|
|
id, ok := _u.mutation.ID()
|
|
if !ok {
|
|
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Alert.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, alert.FieldID)
|
|
for _, f := range fields {
|
|
if !alert.ValidColumn(f) {
|
|
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
|
}
|
|
if f != alert.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.RuleCode(); ok {
|
|
_spec.SetField(alert.FieldRuleCode, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Level(); ok {
|
|
_spec.SetField(alert.FieldLevel, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Title(); ok {
|
|
_spec.SetField(alert.FieldTitle, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Content(); ok {
|
|
_spec.SetField(alert.FieldContent, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.Target(); ok {
|
|
_spec.SetField(alert.FieldTarget, field.TypeString, value)
|
|
}
|
|
if _u.mutation.TargetCleared() {
|
|
_spec.ClearField(alert.FieldTarget, field.TypeString)
|
|
}
|
|
if value, ok := _u.mutation.Status(); ok {
|
|
_spec.SetField(alert.FieldStatus, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.ResolvedAt(); ok {
|
|
_spec.SetField(alert.FieldResolvedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedResolvedAt(); ok {
|
|
_spec.AddField(alert.FieldResolvedAt, field.TypeInt64, value)
|
|
}
|
|
if _u.mutation.ResolvedAtCleared() {
|
|
_spec.ClearField(alert.FieldResolvedAt, field.TypeInt64)
|
|
}
|
|
if value, ok := _u.mutation.ResolvedBy(); ok {
|
|
_spec.SetField(alert.FieldResolvedBy, field.TypeString, value)
|
|
}
|
|
if value, ok := _u.mutation.CreatedAt(); ok {
|
|
_spec.SetField(alert.FieldCreatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedCreatedAt(); ok {
|
|
_spec.AddField(alert.FieldCreatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.UpdatedAt(); ok {
|
|
_spec.SetField(alert.FieldUpdatedAt, field.TypeInt64, value)
|
|
}
|
|
if value, ok := _u.mutation.AddedUpdatedAt(); ok {
|
|
_spec.AddField(alert.FieldUpdatedAt, field.TypeInt64, value)
|
|
}
|
|
_node = &Alert{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{alert.Label}
|
|
} else if sqlgraph.IsConstraintError(err) {
|
|
err = &ConstraintError{msg: err.Error(), wrap: err}
|
|
}
|
|
return nil, err
|
|
}
|
|
_u.mutation.done = true
|
|
return _node, nil
|
|
}
|