From 1de21d7705d1e3c8801fefe88b1cb43dc0f8fe71 Mon Sep 17 00:00:00 2001 From: it512 Date: Wed, 25 Dec 2024 15:22:00 +0800 Subject: [PATCH] last use ts --- card/orm/ent/card.go | 13 ++++- card/orm/ent/card/card.go | 10 ++++ card/orm/ent/card/where.go | 45 +++++++++++++++++ card/orm/ent/card_create.go | 85 ++++++++++++++++++++++++++++++++ card/orm/ent/card_update.go | 54 +++++++++++++++++++++ card/orm/ent/entql.go | 6 +++ card/orm/ent/migrate/schema.go | 3 +- card/orm/ent/mutation.go | 89 +++++++++++++++++++++++++++++++++- card/orm/ent/runtime.go | 10 ++-- 9 files changed, 309 insertions(+), 6 deletions(-) diff --git a/card/orm/ent/card.go b/card/orm/ent/card.go index 69c5dd9..dc2c41a 100644 --- a/card/orm/ent/card.go +++ b/card/orm/ent/card.go @@ -37,6 +37,8 @@ type Card struct { MemberCode string `json:"member_code,omitempty"` // BindTime holds the value of the "bind_time" field. BindTime *time.Time `json:"bind_time,omitempty"` + // LastUseTs holds the value of the "last_use_ts" field. + LastUseTs int64 `json:"last_use_ts,omitempty"` // LastCleanBalance holds the value of the "last_clean_balance" field. LastCleanBalance int64 `json:"last_clean_balance,omitempty"` // LastCleanTs holds the value of the "last_clean_ts" field. @@ -51,7 +53,7 @@ func (*Card) scanValues(columns []string) ([]any, error) { values := make([]any, len(columns)) for i := range columns { switch columns[i] { - case card.FieldID, card.FieldType, card.FieldAmount, card.FieldLastCleanBalance, card.FieldLastCleanTs, card.FieldStatus: + case card.FieldID, card.FieldType, card.FieldAmount, card.FieldLastUseTs, card.FieldLastCleanBalance, card.FieldLastCleanTs, card.FieldStatus: values[i] = new(sql.NullInt64) case card.FieldCode, card.FieldCardBin, card.FieldPic1, card.FieldPic2, card.FieldMemberCode: values[i] = new(sql.NullString) @@ -139,6 +141,12 @@ func (c *Card) assignValues(columns []string, values []any) error { c.BindTime = new(time.Time) *c.BindTime = value.Time } + case card.FieldLastUseTs: + if value, ok := values[i].(*sql.NullInt64); !ok { + return fmt.Errorf("unexpected type %T for field last_use_ts", values[i]) + } else if value.Valid { + c.LastUseTs = value.Int64 + } case card.FieldLastCleanBalance: if value, ok := values[i].(*sql.NullInt64); !ok { return fmt.Errorf("unexpected type %T for field last_clean_balance", values[i]) @@ -225,6 +233,9 @@ func (c *Card) String() string { builder.WriteString(v.Format(time.ANSIC)) } builder.WriteString(", ") + builder.WriteString("last_use_ts=") + builder.WriteString(fmt.Sprintf("%v", c.LastUseTs)) + builder.WriteString(", ") builder.WriteString("last_clean_balance=") builder.WriteString(fmt.Sprintf("%v", c.LastCleanBalance)) builder.WriteString(", ") diff --git a/card/orm/ent/card/card.go b/card/orm/ent/card/card.go index 4af33fa..547e30a 100644 --- a/card/orm/ent/card/card.go +++ b/card/orm/ent/card/card.go @@ -33,6 +33,8 @@ const ( FieldMemberCode = "member_code" // FieldBindTime holds the string denoting the bind_time field in the database. FieldBindTime = "bind_time" + // FieldLastUseTs holds the string denoting the last_use_ts field in the database. + FieldLastUseTs = "last_use_ts" // FieldLastCleanBalance holds the string denoting the last_clean_balance field in the database. FieldLastCleanBalance = "last_clean_balance" // FieldLastCleanTs holds the string denoting the last_clean_ts field in the database. @@ -56,6 +58,7 @@ var Columns = []string{ FieldAmount, FieldMemberCode, FieldBindTime, + FieldLastUseTs, FieldLastCleanBalance, FieldLastCleanTs, FieldStatus, @@ -94,6 +97,8 @@ var ( DefaultAmount int64 // MemberCodeValidator is a validator for the "member_code" field. It is called by the builders before save. MemberCodeValidator func(string) error + // DefaultLastUseTs holds the default value on creation for the "last_use_ts" field. + DefaultLastUseTs int64 // DefaultLastCleanBalance holds the default value on creation for the "last_clean_balance" field. DefaultLastCleanBalance int64 // DefaultLastCleanTs holds the default value on creation for the "last_clean_ts" field. @@ -160,6 +165,11 @@ func ByBindTime(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldBindTime, opts...).ToFunc() } +// ByLastUseTs orders the results by the last_use_ts field. +func ByLastUseTs(opts ...sql.OrderTermOption) OrderOption { + return sql.OrderByField(FieldLastUseTs, opts...).ToFunc() +} + // ByLastCleanBalance orders the results by the last_clean_balance field. func ByLastCleanBalance(opts ...sql.OrderTermOption) OrderOption { return sql.OrderByField(FieldLastCleanBalance, opts...).ToFunc() diff --git a/card/orm/ent/card/where.go b/card/orm/ent/card/where.go index 5ef1fff..63272fd 100644 --- a/card/orm/ent/card/where.go +++ b/card/orm/ent/card/where.go @@ -104,6 +104,11 @@ func BindTime(v time.Time) predicate.Card { return predicate.Card(sql.FieldEQ(FieldBindTime, v)) } +// LastUseTs applies equality check predicate on the "last_use_ts" field. It's identical to LastUseTsEQ. +func LastUseTs(v int64) predicate.Card { + return predicate.Card(sql.FieldEQ(FieldLastUseTs, v)) +} + // LastCleanBalance applies equality check predicate on the "last_clean_balance" field. It's identical to LastCleanBalanceEQ. func LastCleanBalance(v int64) predicate.Card { return predicate.Card(sql.FieldEQ(FieldLastCleanBalance, v)) @@ -664,6 +669,46 @@ func BindTimeNotNil() predicate.Card { return predicate.Card(sql.FieldNotNull(FieldBindTime)) } +// LastUseTsEQ applies the EQ predicate on the "last_use_ts" field. +func LastUseTsEQ(v int64) predicate.Card { + return predicate.Card(sql.FieldEQ(FieldLastUseTs, v)) +} + +// LastUseTsNEQ applies the NEQ predicate on the "last_use_ts" field. +func LastUseTsNEQ(v int64) predicate.Card { + return predicate.Card(sql.FieldNEQ(FieldLastUseTs, v)) +} + +// LastUseTsIn applies the In predicate on the "last_use_ts" field. +func LastUseTsIn(vs ...int64) predicate.Card { + return predicate.Card(sql.FieldIn(FieldLastUseTs, vs...)) +} + +// LastUseTsNotIn applies the NotIn predicate on the "last_use_ts" field. +func LastUseTsNotIn(vs ...int64) predicate.Card { + return predicate.Card(sql.FieldNotIn(FieldLastUseTs, vs...)) +} + +// LastUseTsGT applies the GT predicate on the "last_use_ts" field. +func LastUseTsGT(v int64) predicate.Card { + return predicate.Card(sql.FieldGT(FieldLastUseTs, v)) +} + +// LastUseTsGTE applies the GTE predicate on the "last_use_ts" field. +func LastUseTsGTE(v int64) predicate.Card { + return predicate.Card(sql.FieldGTE(FieldLastUseTs, v)) +} + +// LastUseTsLT applies the LT predicate on the "last_use_ts" field. +func LastUseTsLT(v int64) predicate.Card { + return predicate.Card(sql.FieldLT(FieldLastUseTs, v)) +} + +// LastUseTsLTE applies the LTE predicate on the "last_use_ts" field. +func LastUseTsLTE(v int64) predicate.Card { + return predicate.Card(sql.FieldLTE(FieldLastUseTs, v)) +} + // LastCleanBalanceEQ applies the EQ predicate on the "last_clean_balance" field. func LastCleanBalanceEQ(v int64) predicate.Card { return predicate.Card(sql.FieldEQ(FieldLastCleanBalance, v)) diff --git a/card/orm/ent/card_create.go b/card/orm/ent/card_create.go index 7efcad1..f398e52 100644 --- a/card/orm/ent/card_create.go +++ b/card/orm/ent/card_create.go @@ -138,6 +138,20 @@ func (cc *CardCreate) SetNillableBindTime(t *time.Time) *CardCreate { return cc } +// SetLastUseTs sets the "last_use_ts" field. +func (cc *CardCreate) SetLastUseTs(i int64) *CardCreate { + cc.mutation.SetLastUseTs(i) + return cc +} + +// SetNillableLastUseTs sets the "last_use_ts" field if the given value is not nil. +func (cc *CardCreate) SetNillableLastUseTs(i *int64) *CardCreate { + if i != nil { + cc.SetLastUseTs(*i) + } + return cc +} + // SetLastCleanBalance sets the "last_clean_balance" field. func (cc *CardCreate) SetLastCleanBalance(i int64) *CardCreate { cc.mutation.SetLastCleanBalance(i) @@ -235,6 +249,10 @@ func (cc *CardCreate) defaults() { v := card.DefaultAmount cc.mutation.SetAmount(v) } + if _, ok := cc.mutation.LastUseTs(); !ok { + v := card.DefaultLastUseTs + cc.mutation.SetLastUseTs(v) + } if _, ok := cc.mutation.LastCleanBalance(); !ok { v := card.DefaultLastCleanBalance cc.mutation.SetLastCleanBalance(v) @@ -300,6 +318,9 @@ func (cc *CardCreate) check() error { return &ValidationError{Name: "member_code", err: fmt.Errorf(`ent: validator failed for field "Card.member_code": %w`, err)} } } + if _, ok := cc.mutation.LastUseTs(); !ok { + return &ValidationError{Name: "last_use_ts", err: errors.New(`ent: missing required field "Card.last_use_ts"`)} + } if _, ok := cc.mutation.LastCleanBalance(); !ok { return &ValidationError{Name: "last_clean_balance", err: errors.New(`ent: missing required field "Card.last_clean_balance"`)} } @@ -376,6 +397,10 @@ func (cc *CardCreate) createSpec() (*Card, *sqlgraph.CreateSpec) { _spec.SetField(card.FieldBindTime, field.TypeTime, value) _node.BindTime = &value } + if value, ok := cc.mutation.LastUseTs(); ok { + _spec.SetField(card.FieldLastUseTs, field.TypeInt64, value) + _node.LastUseTs = value + } if value, ok := cc.mutation.LastCleanBalance(); ok { _spec.SetField(card.FieldLastCleanBalance, field.TypeInt64, value) _node.LastCleanBalance = value @@ -506,6 +531,24 @@ func (u *CardUpsert) ClearBindTime() *CardUpsert { return u } +// SetLastUseTs sets the "last_use_ts" field. +func (u *CardUpsert) SetLastUseTs(v int64) *CardUpsert { + u.Set(card.FieldLastUseTs, v) + return u +} + +// UpdateLastUseTs sets the "last_use_ts" field to the value that was provided on create. +func (u *CardUpsert) UpdateLastUseTs() *CardUpsert { + u.SetExcluded(card.FieldLastUseTs) + return u +} + +// AddLastUseTs adds v to the "last_use_ts" field. +func (u *CardUpsert) AddLastUseTs(v int64) *CardUpsert { + u.Add(card.FieldLastUseTs, v) + return u +} + // SetStatus sets the "status" field. func (u *CardUpsert) SetStatus(v int) *CardUpsert { u.Set(card.FieldStatus, v) @@ -667,6 +710,27 @@ func (u *CardUpsertOne) ClearBindTime() *CardUpsertOne { }) } +// SetLastUseTs sets the "last_use_ts" field. +func (u *CardUpsertOne) SetLastUseTs(v int64) *CardUpsertOne { + return u.Update(func(s *CardUpsert) { + s.SetLastUseTs(v) + }) +} + +// AddLastUseTs adds v to the "last_use_ts" field. +func (u *CardUpsertOne) AddLastUseTs(v int64) *CardUpsertOne { + return u.Update(func(s *CardUpsert) { + s.AddLastUseTs(v) + }) +} + +// UpdateLastUseTs sets the "last_use_ts" field to the value that was provided on create. +func (u *CardUpsertOne) UpdateLastUseTs() *CardUpsertOne { + return u.Update(func(s *CardUpsert) { + s.UpdateLastUseTs() + }) +} + // SetStatus sets the "status" field. func (u *CardUpsertOne) SetStatus(v int) *CardUpsertOne { return u.Update(func(s *CardUpsert) { @@ -997,6 +1061,27 @@ func (u *CardUpsertBulk) ClearBindTime() *CardUpsertBulk { }) } +// SetLastUseTs sets the "last_use_ts" field. +func (u *CardUpsertBulk) SetLastUseTs(v int64) *CardUpsertBulk { + return u.Update(func(s *CardUpsert) { + s.SetLastUseTs(v) + }) +} + +// AddLastUseTs adds v to the "last_use_ts" field. +func (u *CardUpsertBulk) AddLastUseTs(v int64) *CardUpsertBulk { + return u.Update(func(s *CardUpsert) { + s.AddLastUseTs(v) + }) +} + +// UpdateLastUseTs sets the "last_use_ts" field to the value that was provided on create. +func (u *CardUpsertBulk) UpdateLastUseTs() *CardUpsertBulk { + return u.Update(func(s *CardUpsert) { + s.UpdateLastUseTs() + }) +} + // SetStatus sets the "status" field. func (u *CardUpsertBulk) SetStatus(v int) *CardUpsertBulk { return u.Update(func(s *CardUpsert) { diff --git a/card/orm/ent/card_update.go b/card/orm/ent/card_update.go index 3f5374f..f11f2c6 100644 --- a/card/orm/ent/card_update.go +++ b/card/orm/ent/card_update.go @@ -95,6 +95,27 @@ func (cu *CardUpdate) ClearBindTime() *CardUpdate { return cu } +// SetLastUseTs sets the "last_use_ts" field. +func (cu *CardUpdate) SetLastUseTs(i int64) *CardUpdate { + cu.mutation.ResetLastUseTs() + cu.mutation.SetLastUseTs(i) + return cu +} + +// SetNillableLastUseTs sets the "last_use_ts" field if the given value is not nil. +func (cu *CardUpdate) SetNillableLastUseTs(i *int64) *CardUpdate { + if i != nil { + cu.SetLastUseTs(*i) + } + return cu +} + +// AddLastUseTs adds i to the "last_use_ts" field. +func (cu *CardUpdate) AddLastUseTs(i int64) *CardUpdate { + cu.mutation.AddLastUseTs(i) + return cu +} + // SetStatus sets the "status" field. func (cu *CardUpdate) SetStatus(i int) *CardUpdate { cu.mutation.ResetStatus() @@ -200,6 +221,12 @@ func (cu *CardUpdate) sqlSave(ctx context.Context) (n int, err error) { if cu.mutation.BindTimeCleared() { _spec.ClearField(card.FieldBindTime, field.TypeTime) } + if value, ok := cu.mutation.LastUseTs(); ok { + _spec.SetField(card.FieldLastUseTs, field.TypeInt64, value) + } + if value, ok := cu.mutation.AddedLastUseTs(); ok { + _spec.AddField(card.FieldLastUseTs, field.TypeInt64, value) + } if value, ok := cu.mutation.Status(); ok { _spec.SetField(card.FieldStatus, field.TypeInt, value) } @@ -293,6 +320,27 @@ func (cuo *CardUpdateOne) ClearBindTime() *CardUpdateOne { return cuo } +// SetLastUseTs sets the "last_use_ts" field. +func (cuo *CardUpdateOne) SetLastUseTs(i int64) *CardUpdateOne { + cuo.mutation.ResetLastUseTs() + cuo.mutation.SetLastUseTs(i) + return cuo +} + +// SetNillableLastUseTs sets the "last_use_ts" field if the given value is not nil. +func (cuo *CardUpdateOne) SetNillableLastUseTs(i *int64) *CardUpdateOne { + if i != nil { + cuo.SetLastUseTs(*i) + } + return cuo +} + +// AddLastUseTs adds i to the "last_use_ts" field. +func (cuo *CardUpdateOne) AddLastUseTs(i int64) *CardUpdateOne { + cuo.mutation.AddLastUseTs(i) + return cuo +} + // SetStatus sets the "status" field. func (cuo *CardUpdateOne) SetStatus(i int) *CardUpdateOne { cuo.mutation.ResetStatus() @@ -428,6 +476,12 @@ func (cuo *CardUpdateOne) sqlSave(ctx context.Context) (_node *Card, err error) if cuo.mutation.BindTimeCleared() { _spec.ClearField(card.FieldBindTime, field.TypeTime) } + if value, ok := cuo.mutation.LastUseTs(); ok { + _spec.SetField(card.FieldLastUseTs, field.TypeInt64, value) + } + if value, ok := cuo.mutation.AddedLastUseTs(); ok { + _spec.AddField(card.FieldLastUseTs, field.TypeInt64, value) + } if value, ok := cuo.mutation.Status(); ok { _spec.SetField(card.FieldStatus, field.TypeInt, value) } diff --git a/card/orm/ent/entql.go b/card/orm/ent/entql.go index c82c601..aacdd4a 100644 --- a/card/orm/ent/entql.go +++ b/card/orm/ent/entql.go @@ -35,6 +35,7 @@ var schemaGraph = func() *sqlgraph.Schema { card.FieldAmount: {Type: field.TypeInt64, Column: card.FieldAmount}, card.FieldMemberCode: {Type: field.TypeString, Column: card.FieldMemberCode}, card.FieldBindTime: {Type: field.TypeTime, Column: card.FieldBindTime}, + card.FieldLastUseTs: {Type: field.TypeInt64, Column: card.FieldLastUseTs}, card.FieldLastCleanBalance: {Type: field.TypeInt64, Column: card.FieldLastCleanBalance}, card.FieldLastCleanTs: {Type: field.TypeInt16, Column: card.FieldLastCleanTs}, card.FieldStatus: {Type: field.TypeInt, Column: card.FieldStatus}, @@ -139,6 +140,11 @@ func (f *CardFilter) WhereBindTime(p entql.TimeP) { f.Where(p.Field(card.FieldBindTime)) } +// WhereLastUseTs applies the entql int64 predicate on the last_use_ts field. +func (f *CardFilter) WhereLastUseTs(p entql.Int64P) { + f.Where(p.Field(card.FieldLastUseTs)) +} + // WhereLastCleanBalance applies the entql int64 predicate on the last_clean_balance field. func (f *CardFilter) WhereLastCleanBalance(p entql.Int64P) { f.Where(p.Field(card.FieldLastCleanBalance)) diff --git a/card/orm/ent/migrate/schema.go b/card/orm/ent/migrate/schema.go index 8fb59c7..0a259db 100644 --- a/card/orm/ent/migrate/schema.go +++ b/card/orm/ent/migrate/schema.go @@ -22,6 +22,7 @@ var ( {Name: "amount", Type: field.TypeInt64, Default: 0}, {Name: "member_code", Type: field.TypeString, Nullable: true, Size: 36, SchemaType: map[string]string{"mysql": "char(36)", "postgres": "char(36)", "sqlite3": "char(36)"}}, {Name: "bind_time", Type: field.TypeTime, Nullable: true}, + {Name: "last_use_ts", Type: field.TypeInt64, Default: 0}, {Name: "last_clean_balance", Type: field.TypeInt64, Default: 0}, {Name: "last_clean_ts", Type: field.TypeInt16, Default: 0}, {Name: "status", Type: field.TypeInt, Default: 0}, @@ -50,7 +51,7 @@ var ( { Name: "card_status", Unique: false, - Columns: []*schema.Column{TCardColumns[13]}, + Columns: []*schema.Column{TCardColumns[14]}, }, }, } diff --git a/card/orm/ent/mutation.go b/card/orm/ent/mutation.go index 777d366..f73a591 100644 --- a/card/orm/ent/mutation.go +++ b/card/orm/ent/mutation.go @@ -45,6 +45,8 @@ type CardMutation struct { addamount *int64 member_code *string bind_time *time.Time + last_use_ts *int64 + addlast_use_ts *int64 last_clean_balance *int64 addlast_clean_balance *int64 last_clean_ts *int16 @@ -581,6 +583,62 @@ func (m *CardMutation) ResetBindTime() { delete(m.clearedFields, card.FieldBindTime) } +// SetLastUseTs sets the "last_use_ts" field. +func (m *CardMutation) SetLastUseTs(i int64) { + m.last_use_ts = &i + m.addlast_use_ts = nil +} + +// LastUseTs returns the value of the "last_use_ts" field in the mutation. +func (m *CardMutation) LastUseTs() (r int64, exists bool) { + v := m.last_use_ts + if v == nil { + return + } + return *v, true +} + +// OldLastUseTs returns the old "last_use_ts" field's value of the Card entity. +// If the Card 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 *CardMutation) OldLastUseTs(ctx context.Context) (v int64, err error) { + if !m.op.Is(OpUpdateOne) { + return v, errors.New("OldLastUseTs is only allowed on UpdateOne operations") + } + if m.id == nil || m.oldValue == nil { + return v, errors.New("OldLastUseTs requires an ID field in the mutation") + } + oldValue, err := m.oldValue(ctx) + if err != nil { + return v, fmt.Errorf("querying old value for OldLastUseTs: %w", err) + } + return oldValue.LastUseTs, nil +} + +// AddLastUseTs adds i to the "last_use_ts" field. +func (m *CardMutation) AddLastUseTs(i int64) { + if m.addlast_use_ts != nil { + *m.addlast_use_ts += i + } else { + m.addlast_use_ts = &i + } +} + +// AddedLastUseTs returns the value that was added to the "last_use_ts" field in this mutation. +func (m *CardMutation) AddedLastUseTs() (r int64, exists bool) { + v := m.addlast_use_ts + if v == nil { + return + } + return *v, true +} + +// ResetLastUseTs resets all changes to the "last_use_ts" field. +func (m *CardMutation) ResetLastUseTs() { + m.last_use_ts = nil + m.addlast_use_ts = nil +} + // SetLastCleanBalance sets the "last_clean_balance" field. func (m *CardMutation) SetLastCleanBalance(i int64) { m.last_clean_balance = &i @@ -783,7 +841,7 @@ func (m *CardMutation) Type() string { // order to get all numeric fields that were incremented/decremented, call // AddedFields(). func (m *CardMutation) Fields() []string { - fields := make([]string, 0, 13) + fields := make([]string, 0, 14) if m.create_time != nil { fields = append(fields, card.FieldCreateTime) } @@ -814,6 +872,9 @@ func (m *CardMutation) Fields() []string { if m.bind_time != nil { fields = append(fields, card.FieldBindTime) } + if m.last_use_ts != nil { + fields = append(fields, card.FieldLastUseTs) + } if m.last_clean_balance != nil { fields = append(fields, card.FieldLastCleanBalance) } @@ -851,6 +912,8 @@ func (m *CardMutation) Field(name string) (ent.Value, bool) { return m.MemberCode() case card.FieldBindTime: return m.BindTime() + case card.FieldLastUseTs: + return m.LastUseTs() case card.FieldLastCleanBalance: return m.LastCleanBalance() case card.FieldLastCleanTs: @@ -886,6 +949,8 @@ func (m *CardMutation) OldField(ctx context.Context, name string) (ent.Value, er return m.OldMemberCode(ctx) case card.FieldBindTime: return m.OldBindTime(ctx) + case card.FieldLastUseTs: + return m.OldLastUseTs(ctx) case card.FieldLastCleanBalance: return m.OldLastCleanBalance(ctx) case card.FieldLastCleanTs: @@ -971,6 +1036,13 @@ func (m *CardMutation) SetField(name string, value ent.Value) error { } m.SetBindTime(v) return nil + case card.FieldLastUseTs: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.SetLastUseTs(v) + return nil case card.FieldLastCleanBalance: v, ok := value.(int64) if !ok { @@ -1006,6 +1078,9 @@ func (m *CardMutation) AddedFields() []string { if m.addamount != nil { fields = append(fields, card.FieldAmount) } + if m.addlast_use_ts != nil { + fields = append(fields, card.FieldLastUseTs) + } if m.addlast_clean_balance != nil { fields = append(fields, card.FieldLastCleanBalance) } @@ -1027,6 +1102,8 @@ func (m *CardMutation) AddedField(name string) (ent.Value, bool) { return m.AddedType() case card.FieldAmount: return m.AddedAmount() + case card.FieldLastUseTs: + return m.AddedLastUseTs() case card.FieldLastCleanBalance: return m.AddedLastCleanBalance() case card.FieldLastCleanTs: @@ -1056,6 +1133,13 @@ func (m *CardMutation) AddField(name string, value ent.Value) error { } m.AddAmount(v) return nil + case card.FieldLastUseTs: + v, ok := value.(int64) + if !ok { + return fmt.Errorf("unexpected type %T for field %s", value, name) + } + m.AddLastUseTs(v) + return nil case card.FieldLastCleanBalance: v, ok := value.(int64) if !ok { @@ -1149,6 +1233,9 @@ func (m *CardMutation) ResetField(name string) error { case card.FieldBindTime: m.ResetBindTime() return nil + case card.FieldLastUseTs: + m.ResetLastUseTs() + return nil case card.FieldLastCleanBalance: m.ResetLastCleanBalance() return nil diff --git a/card/orm/ent/runtime.go b/card/orm/ent/runtime.go index b978c2e..22db812 100644 --- a/card/orm/ent/runtime.go +++ b/card/orm/ent/runtime.go @@ -86,16 +86,20 @@ func init() { cardDescMemberCode := cardFields[6].Descriptor() // card.MemberCodeValidator is a validator for the "member_code" field. It is called by the builders before save. card.MemberCodeValidator = cardDescMemberCode.Validators[0].(func(string) error) + // cardDescLastUseTs is the schema descriptor for last_use_ts field. + cardDescLastUseTs := cardFields[8].Descriptor() + // card.DefaultLastUseTs holds the default value on creation for the last_use_ts field. + card.DefaultLastUseTs = cardDescLastUseTs.Default.(int64) // cardDescLastCleanBalance is the schema descriptor for last_clean_balance field. - cardDescLastCleanBalance := cardFields[8].Descriptor() + cardDescLastCleanBalance := cardFields[9].Descriptor() // card.DefaultLastCleanBalance holds the default value on creation for the last_clean_balance field. card.DefaultLastCleanBalance = cardDescLastCleanBalance.Default.(int64) // cardDescLastCleanTs is the schema descriptor for last_clean_ts field. - cardDescLastCleanTs := cardFields[9].Descriptor() + cardDescLastCleanTs := cardFields[10].Descriptor() // card.DefaultLastCleanTs holds the default value on creation for the last_clean_ts field. card.DefaultLastCleanTs = cardDescLastCleanTs.Default.(int16) // cardDescStatus is the schema descriptor for status field. - cardDescStatus := cardFields[10].Descriptor() + cardDescStatus := cardFields[11].Descriptor() // card.DefaultStatus holds the default value on creation for the status field. card.DefaultStatus = cardDescStatus.Default.(int) }