spark-server/internal/module/user/model/user_login_log.go

51 lines
1.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package model
import (
"context"
"time"
"spark-server/internal/module/user/entity"
)
// UserLoginLog maps table user_login_logs: one row per successful login.
type UserLoginLog struct {
ID int64 `gorm:"column:id;primaryKey;autoIncrement;comment:行 id,表内自增"`
UserID int64 `gorm:"column:user_id;comment:登录用户"`
DeviceID uint64 `gorm:"column:device_id;comment:devices.device_id"`
AppID uint8 `gorm:"column:app_id;comment:当次登录 app_id"`
DeviceType string `gorm:"column:device_type;comment:设备类型"`
DeviceName string `gorm:"column:device_name;comment:设备展示名"`
AppVersion string `gorm:"column:app_version;comment:客户端版本"`
Language string `gorm:"column:language;comment:登录语言"`
IP string `gorm:"column:ip;comment:PROXY RealIP"`
CreatedAt time.Time `gorm:"column:created_at;comment:本次登录时间"`
}
func (UserLoginLog) TableName() string { return "user_login_logs" }
func (m *Repo) InsertLoginLog(ctx context.Context, log *entity.LoginLog) error {
if log == nil {
return nil
}
db, err := m.session(ctx)
if err != nil {
return err
}
row := UserLoginLog{
UserID: log.UserID,
DeviceID: log.DeviceID,
AppID: log.AppID,
DeviceType: log.DeviceType,
DeviceName: log.DeviceName,
AppVersion: log.AppVersion,
Language: log.Language,
IP: log.IP,
CreatedAt: log.CreatedAt,
}
if err := db.Create(&row).Error; err != nil {
return mapDBErr(err)
}
log.ID = row.ID
return nil
}