electricity_bill_calc_service/model/will_diluted_fee.go

36 lines
1.0 KiB
Go

package model
import (
"context"
"time"
"github.com/shopspring/decimal"
"github.com/uptrace/bun"
)
type WillDilutedFee struct {
bun.BaseModel `bun:"table:will_diluted_fee,alias:w"`
CreatedAndModified `bun:"extend"`
Id string `bun:",pk,notnull" json:"diluteId"`
ReportId string `bun:",notnull" json:"reportId"`
SourceId *string `json:"sourceId"`
Name string `bun:",notnull" json:"name"`
Fee decimal.Decimal `bun:",notnull" json:"fee"`
Memo *string `bun:"type:text" json:"memo"`
Origin *MaintenanceFee `bun:"rel:belongs-to,join:source_id=id"`
}
var _ bun.BeforeAppendModelHook = (*WillDilutedFee)(nil)
func (d *WillDilutedFee) BeforeAppendModel(ctx context.Context, query bun.Query) error {
oprTime := time.Now()
switch query.(type) {
case *bun.InsertQuery:
d.CreatedAt = oprTime
d.LastModifiedAt = &oprTime
case *bun.UpdateQuery:
d.LastModifiedAt = &oprTime
}
return nil
}