loginLog.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package service
  2. import (
  3. "github.com/lejianwen/rustdesk-api/v2/model"
  4. "gorm.io/gorm"
  5. )
  6. type LoginLogService struct {
  7. }
  8. // InfoById 根据用户id取用户信息
  9. func (us *LoginLogService) InfoById(id uint) *model.LoginLog {
  10. u := &model.LoginLog{}
  11. DB.Where("id = ?", id).First(u)
  12. return u
  13. }
  14. func (us *LoginLogService) List(page, pageSize uint, where func(tx *gorm.DB)) (res *model.LoginLogList) {
  15. res = &model.LoginLogList{}
  16. res.Page = int64(page)
  17. res.PageSize = int64(pageSize)
  18. tx := DB.Model(&model.LoginLog{})
  19. if where != nil {
  20. where(tx)
  21. }
  22. tx.Count(&res.Total)
  23. tx.Scopes(Paginate(page, pageSize))
  24. tx.Find(&res.LoginLogs)
  25. return
  26. }
  27. // Create 创建
  28. func (us *LoginLogService) Create(u *model.LoginLog) error {
  29. res := DB.Create(u).Error
  30. return res
  31. }
  32. func (us *LoginLogService) Delete(u *model.LoginLog) error {
  33. return DB.Delete(u).Error
  34. }
  35. // Update 更新
  36. func (us *LoginLogService) Update(u *model.LoginLog) error {
  37. return DB.Model(u).Updates(u).Error
  38. }
  39. func (us *LoginLogService) BatchDelete(ids []uint) error {
  40. return DB.Where("id in (?)", ids).Delete(&model.LoginLog{}).Error
  41. }
  42. func (us *LoginLogService) SoftDelete(l *model.LoginLog) error {
  43. l.IsDeleted = model.IsDeletedYes
  44. return us.Update(l)
  45. }
  46. func (us *LoginLogService) BatchSoftDelete(uid uint, ids []uint) error {
  47. return DB.Model(&model.LoginLog{}).Where("user_id = ? and id in (?)", uid, ids).Update("is_deleted", model.IsDeletedYes).Error
  48. }