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

fix typo

parent 21aed002
...@@ -136,7 +136,7 @@ func (d *Dao) IsTaskDone(tid int, userId string) (ok bool, err error) { ...@@ -136,7 +136,7 @@ func (d *Dao) IsTaskDone(tid int, userId string) (ok bool, err error) {
return count > 0, err return count > 0, err
} }
func (d *Dao) GetTaskResult(tid int, userId string) (status string, createdAt time.Time, err error) { func (d *Dao) GetTaskResult(tid int, userId string) (status string, submittedAt time.Time, err error) {
isDailyTask, err := d.IsDailyTask(tid) isDailyTask, err := d.IsDailyTask(tid)
if err != nil { if err != nil {
return "", time.Time{}, err return "", time.Time{}, err
...@@ -148,7 +148,7 @@ func (d *Dao) GetTaskResult(tid int, userId string) (status string, createdAt ti ...@@ -148,7 +148,7 @@ func (d *Dao) GetTaskResult(tid int, userId string) (status string, createdAt ti
if err == gorm.ErrRecordNotFound { if err == gorm.ErrRecordNotFound {
return constant.TaskHistoryStatusTodo, time.Time{}, nil return constant.TaskHistoryStatusTodo, time.Time{}, nil
} }
return temp.Status, temp.CreatedAt, err return temp.Status, temp.SubmittedAt, err
} }
err = tx.Model(&dbModel.TaskHistory{}). err = tx.Model(&dbModel.TaskHistory{}).
...@@ -157,7 +157,7 @@ func (d *Dao) GetTaskResult(tid int, userId string) (status string, createdAt ti ...@@ -157,7 +157,7 @@ func (d *Dao) GetTaskResult(tid int, userId string) (status string, createdAt ti
if err == gorm.ErrRecordNotFound { if err == gorm.ErrRecordNotFound {
return constant.TaskHistoryStatusTodo, time.Time{}, nil return constant.TaskHistoryStatusTodo, time.Time{}, nil
} }
return temp.Status, temp.CreatedAt, err return temp.Status, temp.SubmittedAt, err
} }
func (d *Dao) CreateTaskHistory(taskId int, userId string, isDailyTask bool, initStatus string) (exist bool, err error) { func (d *Dao) CreateTaskHistory(taskId int, userId string, isDailyTask bool, initStatus string) (exist bool, err error) {
...@@ -176,10 +176,11 @@ func (d *Dao) CreateTaskHistory(taskId int, userId string, isDailyTask bool, ini ...@@ -176,10 +176,11 @@ func (d *Dao) CreateTaskHistory(taskId int, userId string, isDailyTask bool, ini
"FOR UPDATE").Where("task_id = ? and user_id = ?", taskId, userId).Take(&temp).Error "FOR UPDATE").Where("task_id = ? and user_id = ?", taskId, userId).Take(&temp).Error
if err == gorm.ErrRecordNotFound { if err == gorm.ErrRecordNotFound {
err = tx.Create(&dbModel.TaskHistory{ err = tx.Create(&dbModel.TaskHistory{
Id: util.GenFlakeID(), Id: util.GenFlakeID(),
TaskId: taskId, TaskId: taskId,
UserId: userId, UserId: userId,
Status: initStatus, Status: initStatus,
SubmittedAt: time.Now(),
}).Error }).Error
if err != nil { if err != nil {
return false, err return false, err
...@@ -190,7 +191,7 @@ func (d *Dao) CreateTaskHistory(taskId int, userId string, isDailyTask bool, ini ...@@ -190,7 +191,7 @@ func (d *Dao) CreateTaskHistory(taskId int, userId string, isDailyTask bool, ini
return true, tx.Model(&dbModel.TaskHistory{}). return true, tx.Model(&dbModel.TaskHistory{}).
Where("task_id = ? and user_id = ?", taskId, userId). Where("task_id = ? and user_id = ?", taskId, userId).
Limit(1). Limit(1).
Updates(map[string]interface{}{"updated_at": time.Now(), "status": initStatus}).Error Updates(map[string]interface{}{"updated_at": time.Now(), "submitted_at": time.Now(), "status": initStatus}).Error
} }
return err == nil, err return err == nil, err
...@@ -199,10 +200,11 @@ func (d *Dao) CreateTaskHistory(taskId int, userId string, isDailyTask bool, ini ...@@ -199,10 +200,11 @@ func (d *Dao) CreateTaskHistory(taskId int, userId string, isDailyTask bool, ini
err = tx.Set("gorm:query_option", "FOR UPDATE").Where("task_id = ? and user_id = ? and created_at >= ?", taskId, userId, time.Now().UTC().Truncate(24*time.Hour)).Take(&temp).Error err = tx.Set("gorm:query_option", "FOR UPDATE").Where("task_id = ? and user_id = ? and created_at >= ?", taskId, userId, time.Now().UTC().Truncate(24*time.Hour)).Take(&temp).Error
if err == gorm.ErrRecordNotFound { if err == gorm.ErrRecordNotFound {
err = tx.Create(&dbModel.TaskHistory{ err = tx.Create(&dbModel.TaskHistory{
Id: util.GenFlakeID(), Id: util.GenFlakeID(),
TaskId: taskId, TaskId: taskId,
UserId: userId, UserId: userId,
Status: initStatus, Status: initStatus,
SubmittedAt: time.Now(),
}).Error }).Error
if err != nil { if err != nil {
return false, err return false, err
...@@ -213,7 +215,7 @@ func (d *Dao) CreateTaskHistory(taskId int, userId string, isDailyTask bool, ini ...@@ -213,7 +215,7 @@ func (d *Dao) CreateTaskHistory(taskId int, userId string, isDailyTask bool, ini
return true, tx.Model(&dbModel.TaskHistory{}). return true, tx.Model(&dbModel.TaskHistory{}).
Where("task_id = ? and user_id = ? and created_at >= ?", taskId, userId, time.Now().UTC().Truncate(24*time.Hour)). Where("task_id = ? and user_id = ? and created_at >= ?", taskId, userId, time.Now().UTC().Truncate(24*time.Hour)).
Limit(1). Limit(1).
Updates(map[string]interface{}{"updated_at": time.Now(), "status": initStatus}). Updates(map[string]interface{}{"updated_at": time.Now(), "submitted_at": time.Now(), "status": initStatus}).
Error Error
} }
return err == nil, err return err == nil, err
......
...@@ -98,6 +98,7 @@ type TaskHistory struct { ...@@ -98,6 +98,7 @@ type TaskHistory struct {
UserId string `gorm:"type:uuid;index;not null;comment:用户id"` UserId string `gorm:"type:uuid;index;not null;comment:用户id"`
RewardTxHash string `gorm:"type:text;not null;index;comment:发放奖励的txHash"` RewardTxHash string `gorm:"type:text;not null;index;comment:发放奖励的txHash"`
Status string `gorm:"type:text;not null;comment:任务状态"` Status string `gorm:"type:text;not null;comment:任务状态"`
SubmittedAt time.Time `gorm:"comment:提交时间"`
CreatedAt time.Time `gorm:"index"` CreatedAt time.Time `gorm:"index"`
UpdatedAt time.Time `gorm:"index"` UpdatedAt time.Time `gorm:"index"`
gorm.Model gorm.Model
......
...@@ -74,7 +74,7 @@ func (s *Service) GetGroup(gid int, userId string, admin bool) (resp *apiModel.G ...@@ -74,7 +74,7 @@ func (s *Service) GetGroup(gid int, userId string, admin bool) (resp *apiModel.G
Enable: task.Enable, Enable: task.Enable,
} }
status, createdAt, err := s.GetTaskResult(_task.TaskId.(int), userId) status, submittedAt, err := s.GetTaskResult(_task.TaskId.(int), userId)
if err != nil { if err != nil {
log.WithError(err).Error("group check task") log.WithError(err).Error("group check task")
return nil, err return nil, err
...@@ -83,7 +83,7 @@ func (s *Service) GetGroup(gid int, userId string, admin bool) (resp *apiModel.G ...@@ -83,7 +83,7 @@ func (s *Service) GetGroup(gid int, userId string, admin bool) (resp *apiModel.G
if status == constant.TaskHistoryStatusRetry { if status == constant.TaskHistoryStatusRetry {
_task.Msg = "The task is not completed, please try again." _task.Msg = "The task is not completed, please try again."
} }
_task.SubmitTimestamp = int(createdAt.Unix()) _task.SubmitTimestamp = int(submittedAt.Unix())
resp.Tasks = append(resp.Tasks, _task) resp.Tasks = append(resp.Tasks, _task)
} }
return return
......
...@@ -149,8 +149,8 @@ func (s *Service) GetTaskDetail(taskId int) (task *dbModel.Task, err error) { ...@@ -149,8 +149,8 @@ func (s *Service) GetTaskDetail(taskId int) (task *dbModel.Task, err error) {
return return
} }
func (s *Service) GetTaskResult(taskId int, userId string) (status string, createdAt time.Time, err error) { func (s *Service) GetTaskResult(taskId int, userId string) (status string, submittedAt time.Time, err error) {
status, createdAt, err = s.d.GetTaskResult(taskId, userId) status, submittedAt, err = s.d.GetTaskResult(taskId, userId)
if err != nil { if err != nil {
log.WithError(err).Error("get task result error") 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