task_log.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package service
  2. import (
  3. "fmt"
  4. "strings"
  5. "context"
  6. "go-common/app/admin/main/laser/model"
  7. )
  8. // QueryTaskLog is query the finished task
  9. func (s *Service) QueryTaskLog(ctx context.Context, mid int64, taskID int64, platform int, taskState int, sortBy string, pageNo int, pageSize int) (logs []*model.TaskLog, count int64, err error) {
  10. var wherePairs []string
  11. if mid > 0 {
  12. wherePairs = append(wherePairs, fmt.Sprintf("mid = %d", mid))
  13. }
  14. if taskID > 0 {
  15. wherePairs = append(wherePairs, fmt.Sprintf("task_id = %d", taskID))
  16. }
  17. if platform > 0 {
  18. wherePairs = append(wherePairs, fmt.Sprintf("platform = %d", platform))
  19. }
  20. if taskState > 0 {
  21. wherePairs = append(wherePairs, fmt.Sprintf("task_state = %d", taskState))
  22. }
  23. var queryStmt string
  24. if len(wherePairs) > 0 {
  25. queryStmt = "WHERE " + strings.Join(wherePairs, " AND ")
  26. }
  27. sort := buildSortStmt(sortBy)
  28. var limit, offset int
  29. if pageNo >= 0 && pageSize > 0 {
  30. offset = (pageNo - 1) * pageSize
  31. limit = pageSize
  32. } else {
  33. offset = 0
  34. limit = 20
  35. }
  36. logs, count, err = s.dao.QueryTaskLog(ctx, queryStmt, sort, offset, limit)
  37. return
  38. }