task.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package dao
  2. import (
  3. "context"
  4. "github.com/pkg/errors"
  5. "database/sql"
  6. "go-common/app/interface/main/laser/model"
  7. xsql "go-common/library/database/sql"
  8. "go-common/library/log"
  9. )
  10. const (
  11. _queryTaskInfoSql = "SELECT mid, log_date, source_type, platform FROM task WHERE state = 0 AND is_deleted = 0 AND mid = ?"
  12. _updateStateSql = "UPDATE task SET state = ? WHERE is_deleted = 0 AND id = ? "
  13. _queryTaskIDSql = "SELECT id FROM task WHERE is_deleted = 0 AND state = 0 and mid = ? "
  14. _selectByPrimaryID = "SELECT id, admin_id, mid, log_date, contact_email, source_type, platform,state, is_deleted, mtime, ctime FROM task WHERE id = ? AND is_deleted = 0"
  15. )
  16. func (d *Dao) QueryUndoneTaskInfo(c context.Context, mid int64) (t *model.TaskInfo, err error) {
  17. t = &model.TaskInfo{}
  18. row := d.db.QueryRow(c, _queryTaskInfoSql, mid)
  19. if err = row.Scan(&t.MID, &t.LogDate, &t.SourceType, &t.Platform); err != nil {
  20. if err == sql.ErrNoRows {
  21. t = nil
  22. err = nil
  23. } else {
  24. err = errors.WithStack(err)
  25. log.Error("row.Scan() error(%v)", err)
  26. }
  27. }
  28. return
  29. }
  30. func (d *Dao) TxUpdateTaskState(c context.Context, tx *xsql.Tx, state int, taskID int64) (rows int64, err error) {
  31. res, err := tx.Exec(_updateStateSql, state, taskID)
  32. if err != nil {
  33. err = errors.WithStack(err)
  34. return
  35. }
  36. rows, err = res.RowsAffected()
  37. return
  38. }
  39. func (d *Dao) QueryTaskID(c context.Context, mid int64) (taskID int64, err error) {
  40. row := d.db.QueryRow(c, _queryTaskIDSql, mid)
  41. if err = row.Scan(&taskID); err != nil {
  42. if err == sql.ErrNoRows {
  43. err = nil
  44. } else {
  45. err = errors.WithStack(err)
  46. log.Error("row.Scan() error(%v)", err)
  47. }
  48. }
  49. return
  50. }
  51. func (d *Dao) DetailTask(c context.Context, taskID int64) (t *model.Task, err error) {
  52. t = &model.Task{}
  53. row := d.db.QueryRow(c, _selectByPrimaryID, taskID)
  54. if err = row.Scan(&t.ID, &t.AdminID, &t.MID, &t.LogDate, &t.ContactEmail, &t.SourceType, &t.Platform, &t.State, &t.IsDeleted, &t.CTime, &t.MTime); err != nil {
  55. err = errors.WithStack(err)
  56. log.Error("rows.Scan error(%v)", err)
  57. return
  58. }
  59. return
  60. }