sys_session.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package system
  2. import (
  3. "eta_gn/eta_api/global"
  4. "time"
  5. )
  6. type SysSession struct {
  7. Id int `gorm:"primaryKey"`
  8. SysUserId int
  9. UserName string
  10. AccessToken string
  11. IsRemember int `description:"是否属于受信设备"`
  12. ExpiredTime time.Time
  13. CreatedTime time.Time
  14. LastUpdatedTime time.Time
  15. }
  16. // AddSysSession 新增用户登录session信息
  17. func AddSysSession(item *SysSession) (err error) {
  18. o := global.DEFAULT_DmSQL
  19. err = o.Create(item).Error
  20. return
  21. }
  22. // GetSysSessionByToken 根据token获取session
  23. func GetSysSessionByToken(token string) (item *SysSession, err error) {
  24. sql := `SELECT * FROM sys_session WHERE access_token=? AND expired_time> NOW() ORDER BY expired_time DESC LIMIT 1 `
  25. err = global.DEFAULT_DmSQL.Raw(sql, token).First(&item).Error
  26. return
  27. }
  28. // ExpiredSysSessionByAdminId 过期掉用户token
  29. func ExpiredSysSessionByAdminId(adminId int) (err error) {
  30. sql := `update sys_session set expired_time = NOW() WHERE sys_user_id=? `
  31. err = global.DEFAULT_DmSQL.Exec(sql, adminId).Error
  32. return
  33. }
  34. // UnBindAdminRecordByUserId 根据系统用户id解除绑定用户关系
  35. func UnBindAdminRecordByUserId(userId int) (err error) {
  36. msql := ` UPDATE admin_record SET user_id = 0 WHERE user_id = ? `
  37. err = global.DEFAULT_DmSQL.Exec(msql, userId).Error
  38. return
  39. }