task.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package dao
  2. import (
  3. "context"
  4. "database/sql"
  5. "go-common/app/admin/main/push/model"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _addTaskSQL = "insert into push_tasks (job,type,app_id,business_id,title,summary,link_type,link_value,sound,vibration,push_time,expire_time,status,`group`,image_url,extra) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
  10. _taskInfoSQL = "select id,job,type,app_id,business_id,platform,title,summary,link_type,link_value,build,sound,vibration,pass_through,mid_file,progress,push_time,expire_time,status,`group`,image_url from push_tasks where id=?"
  11. )
  12. // TaskInfo .
  13. func (d *Dao) TaskInfo(ctx context.Context, id int64) (t *model.Task, err error) {
  14. t = &model.Task{}
  15. if err = d.db.QueryRow(ctx, _taskInfoSQL, id).Scan(&t.ID, &t.Job, &t.Type, &t.AppID, &t.BusinessID, &t.Platform, &t.Title, &t.Summary, &t.LinkType, &t.LinkValue, &t.Build,
  16. &t.Sound, &t.Vibration, &t.PassThrough, &t.MidFile, &t.Progress, &t.PushTime, &t.ExpireTime, &t.Status, &t.Group, &t.ImageURL); err != nil {
  17. if err == sql.ErrNoRows {
  18. t = nil
  19. err = nil
  20. return
  21. }
  22. log.Error("d.TaskInfo(%s) error(%v)", id, err)
  23. return
  24. }
  25. t.PushTimeUnix = t.PushTime.Unix()
  26. t.ExpireTimeUnix = t.ExpireTime.Unix()
  27. return
  28. }
  29. // AddTask add data platform task
  30. func (d *Dao) AddTask(ctx context.Context, t *model.Task) (id int64, err error) {
  31. var res sql.Result
  32. if res, err = d.db.Exec(ctx, _addTaskSQL, t.Job, t.Type, t.AppID, t.BusinessID, t.Title, t.Summary, t.LinkType, t.LinkValue, t.Sound, t.Vibration, t.PushTime, t.ExpireTime, t.Status, t.Group, t.ImageURL, t.Extra); err != nil {
  33. log.Error("d.AddTask(%+v) error(%v)", t, err)
  34. return
  35. }
  36. id, err = res.LastInsertId()
  37. return
  38. }