audit.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 AuditService struct {
  8. }
  9. func (as *AuditService) AuditConnList(page, pageSize uint, where func(tx *gorm.DB)) (res *model.AuditConnList) {
  10. res = &model.AuditConnList{}
  11. res.Page = int64(page)
  12. res.PageSize = int64(pageSize)
  13. tx := global.DB.Model(&model.AuditConn{})
  14. if where != nil {
  15. where(tx)
  16. }
  17. tx.Count(&res.Total)
  18. tx.Scopes(Paginate(page, pageSize))
  19. tx.Find(&res.AuditConns)
  20. return
  21. }
  22. // Create 创建
  23. func (as *AuditService) CreateAuditConn(u *model.AuditConn) error {
  24. res := global.DB.Create(u).Error
  25. return res
  26. }
  27. func (as *AuditService) DeleteAuditConn(u *model.AuditConn) error {
  28. return global.DB.Delete(u).Error
  29. }
  30. // Update 更新
  31. func (as *AuditService) UpdateAuditConn(u *model.AuditConn) error {
  32. return global.DB.Model(u).Updates(u).Error
  33. }
  34. // InfoByPeerIdAndConnId
  35. func (as *AuditService) InfoByPeerIdAndConnId(peerId string, connId int64) (res *model.AuditConn) {
  36. res = &model.AuditConn{}
  37. global.DB.Where("peer_id = ? and conn_id = ?", peerId, connId).First(res)
  38. return
  39. }
  40. // ConnInfoById
  41. func (as *AuditService) ConnInfoById(id uint) (res *model.AuditConn) {
  42. res = &model.AuditConn{}
  43. global.DB.Where("id = ?", id).First(res)
  44. return
  45. }
  46. // FileInfoById
  47. func (as *AuditService) FileInfoById(id uint) (res *model.AuditFile) {
  48. res = &model.AuditFile{}
  49. global.DB.Where("id = ?", id).First(res)
  50. return
  51. }
  52. func (as *AuditService) AuditFileList(page, pageSize uint, where func(tx *gorm.DB)) (res *model.AuditFileList) {
  53. res = &model.AuditFileList{}
  54. res.Page = int64(page)
  55. res.PageSize = int64(pageSize)
  56. tx := global.DB.Model(&model.AuditFile{})
  57. if where != nil {
  58. where(tx)
  59. }
  60. tx.Count(&res.Total)
  61. tx.Scopes(Paginate(page, pageSize))
  62. tx.Find(&res.AuditFiles)
  63. return
  64. }
  65. // CreateAuditFile
  66. func (as *AuditService) CreateAuditFile(u *model.AuditFile) error {
  67. res := global.DB.Create(u).Error
  68. return res
  69. }
  70. func (as *AuditService) DeleteAuditFile(u *model.AuditFile) error {
  71. return global.DB.Delete(u).Error
  72. }
  73. // Update 更新
  74. func (as *AuditService) UpdateAuditFile(u *model.AuditFile) error {
  75. return global.DB.Model(u).Updates(u).Error
  76. }
  77. func (as *AuditService) BatchDeleteAuditConn(ids []uint) error {
  78. return global.DB.Where("id in (?)", ids).Delete(&model.AuditConn{}).Error
  79. }
  80. func (as *AuditService) BatchDeleteAuditFile(ids []uint) error {
  81. return global.DB.Where("id in (?)", ids).Delete(&model.AuditFile{}).Error
  82. }