diff --git a/link_homework/internal/logic/homework/homework.go b/link_homework/internal/logic/homework/homework.go index eb600dc..6f3594e 100644 --- a/link_homework/internal/logic/homework/homework.go +++ b/link_homework/internal/logic/homework/homework.go @@ -78,9 +78,8 @@ func UpdateHomework(ctx context.Context, homeworkList []*entity.ActivityInteract v.Status = 1 } if v.Status != 0 { - rCount, _ := dao.ActivityInteractiveRecord.Ctx(ctx).Where("group_id", v.Id).Count() - tCount, _ := dao.ActivityInteractiveForm.Ctx(ctx).Where("group_id", v.Id).Count() - v.Count = rCount / tCount + result, _ := dao.ActivityInteractiveRecord.Ctx(ctx).Where("group_id", v.Id).Group("form_id").Limit(1).Value("COUNT(*)") + v.Count = result.Int() } } } @@ -91,9 +90,10 @@ func UpdateHomework(ctx context.Context, homeworkList []*entity.ActivityInteract func InitHomework(ctx context.Context, homeworkList []*entity.ActivityInteractiveGroup) []*entity.ActivityInteractiveGroup { for _, v := range homeworkList { if v.Status == 2 { - rCount, _ := dao.ActivityInteractiveRecord.Ctx(ctx).Where("group_id", v.Id).Count() - tCount, _ := dao.ActivityInteractiveForm.Ctx(ctx).Where("group_id", v.Id).Count() - v.Count = rCount / tCount + if v.Status != 0 { + result, _ := dao.ActivityInteractiveRecord.Ctx(ctx).Where("group_id", v.Id).Group("form_id").Limit(1).Value("COUNT(*)") + v.Count = result.Int() + } } }