You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

task_accomplish_log.go 1.2 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package models
  2. import (
  3. "code.gitea.io/gitea/modules/timeutil"
  4. "time"
  5. )
  6. type TaskAccomplishLog struct {
  7. ID int64 `xorm:"pk autoincr"`
  8. ConfigId int64 `xorm:"NOT NULL"`
  9. TaskCode string `xorm:"NOT NULL"`
  10. UserId int64 `xorm:"INDEX NOT NULL"`
  11. ActionId int64
  12. CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
  13. }
  14. type PeriodResult struct {
  15. StartTime time.Time
  16. EndTime time.Time
  17. LeftTime time.Duration
  18. }
  19. func getTaskAccomplishLog(tl *TaskAccomplishLog) (*TaskAccomplishLog, error) {
  20. has, err := x.Get(tl)
  21. if err != nil {
  22. return nil, err
  23. } else if !has {
  24. return nil, ErrRecordNotExist{}
  25. }
  26. return tl, nil
  27. }
  28. func CountTaskAccomplishLogInTaskPeriod(taskCode string, userId int64, period *PeriodResult) (int64, error) {
  29. if period == nil {
  30. return x.Where("task_code = ? and user_id = ?", taskCode, userId).Count(&TaskAccomplishLog{})
  31. } else {
  32. return x.Where("task_code = ? and user_id = ? and created_unix >= ? and created_unix < ? ", taskCode, userId, period.StartTime.Unix(), period.EndTime.Unix()).Count(&TaskAccomplishLog{})
  33. }
  34. }
  35. func InsertTaskAccomplishLog(tl *TaskAccomplishLog) (int64, error) {
  36. return x.Insert(tl)
  37. }