report.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package gorm
  2. import (
  3. "context"
  4. "database/sql"
  5. "go-common/app/admin/main/aegis/model"
  6. "go-common/library/log"
  7. )
  8. //ReportTaskMetas 任务数据统计
  9. func (d *Dao) ReportTaskMetas(c context.Context, bt string, et string, bizid, flowid int64, uids []int64, mnames map[int64]string, tp int8) (metas []*model.ReportMeta, missuid []int64, err error) {
  10. db := d.orm.Table("task_report").Select("mtime,uid,type,content").Where("business_id=? AND type=?", bizid, tp)
  11. if flowid != 0 {
  12. db.Where("flow_id=?", flowid)
  13. }
  14. db = db.Where("mtime>=? AND mtime<?", bt, et)
  15. if len(uids) > 0 {
  16. db = db.Where("uid IN (?)", uids)
  17. }
  18. var rows *sql.Rows
  19. if rows, err = db.Order("mtime asc").Rows(); err != nil {
  20. log.Error("ReportTaskFlow error(%v)", err)
  21. return
  22. }
  23. defer rows.Close()
  24. for rows.Next() {
  25. meta := &model.ReportMeta{}
  26. if err = rows.Scan(&meta.Mtime, &meta.UID, &meta.Type, &meta.Content); err != nil {
  27. return
  28. }
  29. if uname, ok := mnames[meta.UID]; ok {
  30. meta.Uname = uname
  31. } else {
  32. missuid = append(missuid, meta.UID)
  33. }
  34. metas = append(metas, meta)
  35. }
  36. return
  37. }
  38. //TaskReports 任务报表记录
  39. func (d *Dao) TaskReports(c context.Context, biz int64, flowID int64, tp []int8, statdateFrom string, statdateTo string) (res []*model.TaskReport, err error) {
  40. res = []*model.TaskReport{}
  41. db := d.orm
  42. if statdateFrom != "" {
  43. db = db.Where("stat_date>=?", statdateFrom)
  44. }
  45. if statdateTo != "" {
  46. db = db.Where("stat_date <=?", statdateTo)
  47. }
  48. db = db.Where("business_id=?", biz)
  49. if flowID > 0 {
  50. db = db.Where("flow_id=?", flowID)
  51. }
  52. if len(tp) >= 0 {
  53. db = db.Where("type in (?)", tp)
  54. }
  55. db = db.Order("stat_date desc, business_id desc, flow_id desc")
  56. if err = db.Find(&res).Error; err != nil {
  57. log.Error("TaskReports error(%v)", err)
  58. }
  59. return
  60. }