spark-server/internal/module/user/model/user_login_log.go
zhr ae9a71034d feat: implement Spark IM V3 modular monolith
Add HTTP /v1 MVC, TCP send path, groups with server-side member-avatar collage, object-storage upload, and friends/favorites around the architecture-v3 layout.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-17 19:52:11 +08:00

49 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:客户端设备 id"`
DeviceType string `gorm:"column:device_type;comment:设备类型:ios/android/harmony/windows/macos/web"`
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,
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
}