package model import ( "context" "time" "github.com/shopspring/decimal" "github.com/uptrace/bun" ) type Meter04KV struct { bun.BaseModel `bun:"table:meter_04kv,alias:mt"` CreatedAndModified `bun:"extend"` Code string `bun:",pk,notnull" json:"code" excel:"code"` ParkId string `bun:",pk,notnull" json:"parkId"` Address *string `json:"address" excel:"address"` CustomerName *string `json:"customerName" excel:"name"` ContactName *string `json:"contactName" excel:"contact"` ContactPhone *string `json:"contactPhone" excel:"phone"` Ratio decimal.Decimal `bun:",notnull,default:1" json:"ratio" excel:"ratio"` Seq int64 `bun:"type:bigint,notnull" json:"seq" excel:"seq"` IsPublicMeter bool `bun:"public_meter,notnull" json:"isPublicMeter" excel:"public"` WillDilute bool `bun:"dilute,notnull" json:"willDilute" excel:"dilute"` Enabled bool `bun:",notnull" json:"enabled"` ParkDetail *Park `bun:"rel:belongs-to,join:park_id=id" json:"-"` } var _ bun.BeforeAppendModelHook = (*Meter04KV)(nil) func (m *Meter04KV) BeforeAppendModel(ctx context.Context, query bun.Query) error { oprTime := time.Now() switch query.(type) { case *bun.InsertQuery: m.CreatedAt = oprTime m.LastModifiedAt = &oprTime case *bun.UpdateQuery: m.LastModifiedAt = &oprTime } return nil }