123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package system
- import (
- "eta_gn/eta_api/global"
- "time"
- )
- type SysSession struct {
- Id int `gorm:"primaryKey"`
- SysUserId int
- UserName string
- AccessToken string
- IsRemember int `description:"是否属于受信设备"`
- ExpiredTime time.Time
- CreatedTime time.Time
- LastUpdatedTime time.Time
- }
- // AddSysSession 新增用户登录session信息
- func AddSysSession(item *SysSession) (err error) {
- o := global.DEFAULT_DmSQL
- err = o.Create(item).Error
- return
- }
- // GetSysSessionByToken 根据token获取session
- func GetSysSessionByToken(token string) (item *SysSession, err error) {
- sql := `SELECT * FROM sys_session WHERE access_token=? AND expired_time> NOW() ORDER BY expired_time DESC LIMIT 1 `
- err = global.DEFAULT_DmSQL.Raw(sql, token).First(&item).Error
- return
- }
- // ExpiredSysSessionByAdminId 过期掉用户token
- func ExpiredSysSessionByAdminId(adminId int) (err error) {
- sql := `update sys_session set expired_time = NOW() WHERE sys_user_id=? `
- err = global.DEFAULT_DmSQL.Exec(sql, adminId).Error
- return
- }
- // UnBindAdminRecordByUserId 根据系统用户id解除绑定用户关系
- func UnBindAdminRecordByUserId(userId int) (err error) {
- msql := ` UPDATE admin_record SET user_id = 0 WHERE user_id = ? `
- err = global.DEFAULT_DmSQL.Exec(msql, userId).Error
- return
- }
|