task_info.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package upcrm
  2. import (
  3. "go-common/app/job/main/up/model/upcrmmodel"
  4. "go-common/library/log"
  5. xtime "go-common/library/time"
  6. "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. }