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
123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. LogId string `xorm:"INDEX NOT NULL"`
  9. ConfigId int64 `xorm:"NOT NULL"`
  10. TaskCode string `xorm:"NOT NULL"`
  11. UserId int64 `xorm:"INDEX NOT NULL"`
  12. ActionId int64
  13. CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
  14. }
  15. type PeriodResult struct {
  16. StartTime time.Time
  17. EndTime time.Time
  18. LeftTime time.Duration
  19. }
  20. func getTaskAccomplishLog(tl *TaskAccomplishLog) (*TaskAccomplishLog, error) {
  21. has, err := x.Get(tl)
  22. if err != nil {
  23. return nil, err
  24. } else if !has {
  25. return nil, ErrRecordNotExist{}
  26. }
  27. return tl, nil
  28. }
  29. func CountTaskAccomplishLogInTaskPeriod(configId int64, userId int64, period *PeriodResult) (int64, error) {
  30. if period == nil {
  31. return x.Where("config_id = ? and user_id = ?", configId, userId).Count(&TaskAccomplishLog{})
  32. } else {
  33. return x.Where("config_id = ? and user_id = ? and created_unix >= ? and created_unix < ? ", configId, userId, period.StartTime.Unix(), period.EndTime.Unix()).Count(&TaskAccomplishLog{})
  34. }
  35. }
  36. func InsertTaskAccomplishLog(tl *TaskAccomplishLog) (int64, error) {
  37. return x.Insert(tl)
  38. }