Commit 21aed002 authored by 贾浩@五瓣科技's avatar 贾浩@五瓣科技

add submitTimestamp

parent 7bcec231
......@@ -136,28 +136,28 @@ func (d *Dao) IsTaskDone(tid int, userId string) (ok bool, err error) {
return count > 0, err
}
func (d *Dao) GetTaskResult(tid int, userId string) (status string, err error) {
func (d *Dao) GetTaskResult(tid int, userId string) (status string, createdAt time.Time, err error) {
isDailyTask, err := d.IsDailyTask(tid)
if err != nil {
return "", err
return "", time.Time{}, err
}
temp := &dbModel.TaskHistory{}
tx := d.db.Session(&gorm.Session{Logger: logger.Default.LogMode(logger.Silent)})
if !isDailyTask {
err = tx.Model(&dbModel.TaskHistory{}).Where("task_id = ? and user_id = ?", tid, userId).First(temp).Error
if err == gorm.ErrRecordNotFound {
return constant.TaskHistoryStatusTodo, nil
return constant.TaskHistoryStatusTodo, time.Time{}, nil
}
return temp.Status, err
return temp.Status, temp.CreatedAt, err
}
err = tx.Model(&dbModel.TaskHistory{}).
Where("task_id = ? and user_id = ? and created_at >= ?", tid, userId, time.Now().UTC().Truncate(24*time.Hour)).
First(temp).Error
if err == gorm.ErrRecordNotFound {
return constant.TaskHistoryStatusTodo, nil
return constant.TaskHistoryStatusTodo, time.Time{}, nil
}
return temp.Status, err
return temp.Status, temp.CreatedAt, err
}
func (d *Dao) CreateTaskHistory(taskId int, userId string, isDailyTask bool, initStatus string) (exist bool, err error) {
......
......@@ -60,6 +60,7 @@ type Task struct {
TelegramActiveThreshold int `json:"telegramActiveThreshold"` // 仅电报活跃可用
Enable bool `json:"enable"`
Msg string `json:"msg"`
SubmitTimestamp int `json:"submitTimestamp"`
}
type CreateTaskRequest struct {
......
......@@ -79,7 +79,7 @@ func checkTask(c *gin.Context) {
return
}
status, err := srv.GetTaskResult(taskId, userId)
status, _, err := srv.GetTaskResult(taskId, userId)
if err != nil {
c.JSON(200, withError(constant.InternalError))
return
......@@ -117,7 +117,7 @@ func submitTask(c *gin.Context) {
return
}
status, err := srv.GetTaskResult(taskId, userId)
status, _, err := srv.GetTaskResult(taskId, userId)
if err != nil {
c.JSON(200, withError(constant.InternalError))
return
......
......@@ -74,7 +74,7 @@ func (s *Service) GetGroup(gid int, userId string, admin bool) (resp *apiModel.G
Enable: task.Enable,
}
status, err := s.GetTaskResult(_task.TaskId.(int), userId)
status, createdAt, err := s.GetTaskResult(_task.TaskId.(int), userId)
if err != nil {
log.WithError(err).Error("group check task")
return nil, err
......@@ -83,6 +83,7 @@ func (s *Service) GetGroup(gid int, userId string, admin bool) (resp *apiModel.G
if status == constant.TaskHistoryStatusRetry {
_task.Msg = "The task is not completed, please try again."
}
_task.SubmitTimestamp = int(createdAt.Unix())
resp.Tasks = append(resp.Tasks, _task)
}
return
......
......@@ -149,8 +149,8 @@ func (s *Service) GetTaskDetail(taskId int) (task *dbModel.Task, err error) {
return
}
func (s *Service) GetTaskResult(taskId int, userId string) (status string, err error) {
status, err = s.d.GetTaskResult(taskId, userId)
func (s *Service) GetTaskResult(taskId int, userId string) (status string, createdAt time.Time, err error) {
status, createdAt, err = s.d.GetTaskResult(taskId, userId)
if err != nil {
log.WithError(err).Error("get task result error")
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment