audit.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package service
  2. import (
  3. "Gwen/global"
  4. "Gwen/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. // InfoById
  41. func (as *AuditService) InfoById(id uint) (res *model.AuditConn) {
  42. res = &model.AuditConn{}
  43. global.DB.Where("id = ?", id).First(res)
  44. return
  45. }