group.go 1012 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 GroupService struct {
  8. }
  9. // InfoById 根据用户id取用户信息
  10. func (us *GroupService) InfoById(id uint) *model.Group {
  11. u := &model.Group{}
  12. global.DB.Where("id = ?", id).First(u)
  13. return u
  14. }
  15. func (us *GroupService) List(page, pageSize uint, where func(tx *gorm.DB)) (res *model.GroupList) {
  16. res = &model.GroupList{}
  17. res.Page = int64(page)
  18. res.PageSize = int64(pageSize)
  19. tx := global.DB.Model(&model.Group{})
  20. if where != nil {
  21. where(tx)
  22. }
  23. tx.Count(&res.Total)
  24. tx.Scopes(Paginate(page, pageSize))
  25. tx.Find(&res.Groups)
  26. return
  27. }
  28. // Create 创建
  29. func (us *GroupService) Create(u *model.Group) error {
  30. res := global.DB.Create(u).Error
  31. return res
  32. }
  33. func (us *GroupService) Delete(u *model.Group) error {
  34. return global.DB.Delete(u).Error
  35. }
  36. // Update 更新
  37. func (us *GroupService) Update(u *model.Group) error {
  38. return global.DB.Model(u).Updates(u).Error
  39. }