12345678910111213141516171819202122232425262728293031323334 |
- package user
- import (
- "eta/eta_mini_ht_api/models"
- "gorm.io/gorm"
- "time"
- )
- type LogType string
- const (
- Login LogType = "login"
- Logout LogType = "logout"
- )
- type UserEventFlow struct {
- ID int `gorm:"primaryKey;autoIncrement"`
- UserID int `gorm:"not null"`
- EventType LogType `gorm:"type:enum('login','logout');not null"`
- EventTime time.Time `gorm:"default:null"`
- CreateTime time.Time `gorm:"default:null"`
- }
- // BeforeCreate 钩子用于在创建记录前设置 CreateTime
- func (uef *UserEventFlow) BeforeCreate(tx *gorm.DB) (err error) {
- uef.CreateTime = time.Now()
- uef.EventTime = time.Now()
- return
- }
- func InsertEventFlow(flow UserEventFlow) error {
- db := models.Main()
- return db.Model(&UserEventFlow{}).Create(&flow).Error
- }
|