@ -41,8 +41,14 @@ class CompetitionTeamsController < ApplicationController
# 课堂
student_count_subquery = CourseMember . where ( 'course_id = courses.id AND role = 5' ) . select ( 'count(*)' ) . to_sql
subquery = StudentWork . where ( 'homework_common_id = hcs.id' )
. select ( 'count(compelete_status !=0 ) as finish, count(*) as total' )
. having ( 'finish > (total / 2)' ) . to_sql
course_ids = Course . where ( 'courses.created_at > ?' , Time . parse ( '2018-06-01' ) )
. where ( 'courses.created_at <= ?' , @competition . end_time )
. where ( " ( #{ student_count_subquery } ) >= 10 " )
. where ( " exists(select 1 from homework_commons hcs where hcs.course_id = courses.id and hcs.homework_type = 4 and exists( #{ subquery } )) " )
. joins ( 'join course_members on course_members.course_id = courses.id and course_members.role in (1,2,3)' )
. where ( course_members : { user_id : @team_user_ids } ) . pluck ( :id )
courses = Course . where ( id : course_ids ) . joins ( :shixun_homework_commons ) . where ( 'homework_commons.publish_time < now()' )
@ -359,7 +365,7 @@ class CompetitionTeamsController < ApplicationController
end
def get_valid_course_count ( ids )
percentage_sql = StudentWork . where ( 'homework_common_id = homework_commons.id ')
percentage_sql = StudentWork . where ( 'homework_common_id = homework_commons.id and homework_commons.publish_time is not null and homework_commons.publish_time < NOW() ')
. select ( 'count(compelete_status !=0 ) as finish, count(*) as total' )
. having ( 'finish > (total / 2)' ) . to_sql