作者 linmadan

重构任务排序

... ... @@ -68,8 +68,14 @@ type Task struct {
SolvePictureUrls []string `json:"solvePictureUrls"`
// 创建时间
CreateTime time.Time `json:"createTime"`
// 发布时间
// 发布任务时间
ReleaseTime time.Time `json:"releaseTime"`
// 领取任务时间
ReceiveTime time.Time `json:"receiveTime"`
// 完成任务操作时间
CompleteTime time.Time `json:"completeTime"`
// 验收方验收时间
AcceptanceTime time.Time `json:"acceptanceTime"`
//当前状态
CurrentStatus TaskStatus `json:"-"`
}
... ...
... ... @@ -131,7 +131,7 @@ func (dao *TaskDao) CalculatePersonTask(uid int64) (*domain.PersonTaskStatistics
Count(); err != nil {
return nil, err
} else {
personTaskStatistics.UnderwayAsReceiver = int64(count)
personTaskStatistics.UnderwayAsSponsor = int64(count)
}
if count, err := tx.Model(taskModel).
Where(`task.sponsor @> '{"uid":?}'`, uid).
... ...
... ... @@ -50,6 +50,13 @@ type Task struct {
// 创建时间
CreateTime time.Time
ReceiverUid int64
// 发布任务时间
ReleaseTime time.Time
// 领取任务时间
ReceiveTime time.Time
// 完成任务操作时间
CompleteTime time.Time
// 验收方验收时间
AcceptanceTime time.Time
RemoveTime time.Time `pg:",soft_delete"`
}
... ...
... ... @@ -183,8 +183,16 @@ func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int
} else {
query = query.Limit(20)
}
if sortByReleaseTime, ok := queryOptions["sortByReleaseTime"]; ok && (sortByReleaseTime == "ASC" || sortByReleaseTime == "DESC") {
if sortByCreateTime, ok := queryOptions["sortByCreateTime"]; ok && (sortByCreateTime == "ASC" || sortByCreateTime == "DESC") {
query = query.Order(fmt.Sprintf("task.create_time %s", sortByCreateTime.(string)))
} else if sortByReleaseTime, ok := queryOptions["sortByReleaseTime"]; ok && (sortByReleaseTime == "ASC" || sortByReleaseTime == "DESC") {
query = query.Order(fmt.Sprintf("task.release_time %s", sortByReleaseTime.(string)))
} else if sortByReceiveTime, ok := queryOptions["sortByReceiveTime"]; ok && (sortByReceiveTime == "ASC" || sortByReceiveTime == "DESC") {
query = query.Order(fmt.Sprintf("task.release_time %s", sortByReleaseTime.(string)))
} else if sortByCompleteTime, ok := queryOptions["sortByCompleteTime"]; ok && (sortByCompleteTime == "ASC" || sortByCompleteTime == "DESC") {
query = query.Order(fmt.Sprintf("task.complete_time %s", sortByCompleteTime.(string)))
} else if sortByAcceptanceTime, ok := queryOptions["sortByAcceptanceTime"]; ok && (sortByAcceptanceTime == "ASC" || sortByAcceptanceTime == "DESC") {
query = query.Order(fmt.Sprintf("task.acceptance_time %s", sortByAcceptanceTime.(string)))
} else {
query = query.Order("task.id DESC")
}
... ... @@ -276,6 +284,10 @@ func (repository *TaskRepository) transformPgModelToDomainModel(taskModel *model
TaskPictureUrls: taskModel.TaskPictureUrls,
IsRewardTake: taskModel.IsRewardTake,
CreateTime: taskModel.CreateTime,
ReleaseTime: taskModel.ReleaseTime,
ReceiveTime: taskModel.ReceiveTime,
CompleteTime: taskModel.CompleteTime,
AcceptanceTime: taskModel.AcceptanceTime,
RobInfo: robInfo,
BidInfo: bidInfo,
Participators: taskModel.Participators,
... ...
... ... @@ -48,7 +48,7 @@ var _ = Describe("获取个人任务统计", func() {
"INSERT INTO tasks (id, company_id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, participators, task_percentage, solve_report, solve_picture_urls, create_time, release_time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
4, 101, "竞标任务1", 2, &domain.EmployeeInfo{
Uid: 2499036607974745099,
}, 1, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), false, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
}, 3, "null", pg.Array([]string{"口感", "便利", "品牌"}), "面", 1000.00, "验收标准1", "任务描述1", pg.Array([]string{}), false, "null", "null", "", pg.Array([]string{}), time.Now(), time.Now().Add(dayAfter))
Expect(err3).NotTo(HaveOccurred())
_, err4 := pG.DB.QueryOne(
pg.Scan(),
... ...