task_log.go 904 B

1234567891011121314151617181920212223242526272829303132
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/admin/main/laser/model"
  6. )
  7. const (
  8. _countTaskLogSQL = "SELECT count(*) FROM task_log %s"
  9. _queryTaskLogSQL = "SELECT * FROM task_log %s ORDER BY %s LIMIT %d, %d"
  10. )
  11. // QueryTaskLog is query finished task.
  12. func (d *Dao) QueryTaskLog(ctx context.Context, queryStmt string, sort string, offset int, limit int) (taskLogs []*model.TaskLog, count int64, err error) {
  13. row := d.laserDB.QueryRow(ctx, fmt.Sprintf(_countTaskLogSQL, queryStmt))
  14. if err = row.Scan(&count); err != nil {
  15. return
  16. }
  17. rows, err := d.laserDB.Query(ctx, fmt.Sprintf(_queryTaskLogSQL, queryStmt, sort, offset, limit))
  18. if err != nil {
  19. return
  20. }
  21. for rows.Next() {
  22. t := &model.TaskLog{}
  23. if err = rows.Scan(&t.ID, &t.TaskID, &t.MID, &t.Build, &t.Platform, &t.TaskState, &t.Reason, &t.CTime, &t.MTime); err != nil {
  24. return
  25. }
  26. taskLogs = append(taskLogs, t)
  27. }
  28. return
  29. }