shareRecord.go 1.2 KB

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