mysql_event_log.go 999 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package dao
  2. import "go-common/app/admin/ep/tapd/model"
  3. // AddEventLog Add Event Log.
  4. func (d *Dao) AddEventLog(eventLog *model.EventLog) error {
  5. return d.db.Create(eventLog).Error
  6. }
  7. // UpdateEventLog Update Event Log.
  8. func (d *Dao) UpdateEventLog(eventLog *model.EventLog) error {
  9. return d.db.Model(&model.EventLog{}).Where("id=?", eventLog.ID).Update(eventLog).Error
  10. }
  11. //FindEventLogs Find Event Logs.
  12. func (d *Dao) FindEventLogs(req *model.QueryEventLogReq) (total int64, eventLogs []*model.EventLog, err error) {
  13. gDB := d.db.Model(&model.EventLog{})
  14. if req.WorkspaceID > 0 {
  15. gDB = gDB.Where("workspace_id=?", req.WorkspaceID)
  16. }
  17. if req.EventID > 0 {
  18. gDB = gDB.Where("event_id=?", req.EventID)
  19. }
  20. if string(req.Event) != "" {
  21. gDB = gDB.Where("event like ?", string(req.Event)+_wildcards)
  22. }
  23. if err = gDB.Count(&total).Error; err != nil {
  24. return
  25. }
  26. err = gDB.Order("ctime desc").Offset((req.PageNum - 1) * req.PageSize).Limit(req.PageSize).Find(&eventLogs).Error
  27. return
  28. }