diff --git a/link_homework/internal/logic/homework/homework.go b/link_homework/internal/logic/homework/homework.go index c4bdf17..e5470b2 100644 --- a/link_homework/internal/logic/homework/homework.go +++ b/link_homework/internal/logic/homework/homework.go @@ -71,9 +71,18 @@ func UpdateHomework(ctx context.Context, homeworkList []*entity.ActivityInteract } } - // 对 homeworkList 按 Status 升序排序 + // 对 homeworkList 进行排序 sort.Slice(homeworkList, func(i, j int) bool { - return homeworkList[i].Status < homeworkList[j].Status + if homeworkList[i].Status != homeworkList[j].Status { + return homeworkList[i].Status < homeworkList[j].Status + } + if homeworkList[i].Status == 0 { + return homeworkList[i].StartDate.Before(homeworkList[j].StartDate) + } + if homeworkList[i].Status == 1 { + return homeworkList[i].EndDate.Before(homeworkList[j].EndDate) + } + return false }) return homeworkList