task_info.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package upcrm
  2. import (
  3. "time"
  4. "go-common/app/admin/main/up/model/upcrmmodel"
  5. "go-common/library/log"
  6. xtime "go-common/library/time"
  7. )
  8. //StartTask start task
  9. func (d *Dao) StartTask(taskType int, now time.Time) (affectedRow int64, err error) {
  10. var task = &upcrmmodel.TaskInfo{}
  11. task.TaskType = int8(taskType)
  12. task.GenerateDate = now.Format(upcrmmodel.TimeFmtDate)
  13. task.StartTime = xtime.Time(now.Unix())
  14. task.TaskState = upcrmmodel.TaskStateStart
  15. var db = d.crmdb.Model(task).Save(task)
  16. err = db.Error
  17. if err != nil {
  18. log.Error("error start task info, err=%+v", err)
  19. return
  20. }
  21. affectedRow = db.RowsAffected
  22. return
  23. }
  24. //FinishTask finish task
  25. func (d *Dao) FinishTask(taskType int, now time.Time, state int) (affectedRow int64, err error) {
  26. var task = &upcrmmodel.TaskInfo{}
  27. task.TaskType = int8(taskType)
  28. task.GenerateDate = now.Format(upcrmmodel.TimeFmtDate)
  29. task.EndTime = xtime.Time(now.Unix())
  30. task.TaskState = int16(state)
  31. var db = d.crmdb.Model(task).Where("generate_date=? and task_type=?", task.GenerateDate, taskType).Update(task)
  32. err = db.Error
  33. if err != nil {
  34. log.Error("error end task info, err=%+v", err)
  35. return
  36. }
  37. affectedRow = db.RowsAffected
  38. return
  39. }