dev_aliyun
p31729568 5 years ago
parent ba11884a60
commit 57588e33f0

@ -43,12 +43,12 @@ class CompetitionTeamsController < ApplicationController
# 课堂 # 课堂
student_count_subquery = CourseMember.where('course_id = courses.id AND role = 5').select('count(*)').to_sql student_count_subquery = CourseMember.where('course_id = courses.id AND role = 5').select('count(*)').to_sql
subquery = StudentWork.where('homework_common_id = hcs.id') subquery = StudentWork.where('homework_common_id = hcs.id')
.select('count(compelete_status !=0 ) as finish, count(*) as total') .select('sum(compelete_status !=0 ) as finish, count(*) as total')
.having('finish > (total / 2)').to_sql .having('finish > (total / 2)').to_sql
course_ids = Course.where('courses.created_at > ?', Time.parse('2018-06-01')) course_ids = Course.where('courses.created_at > ?', Time.parse('2018-06-01'))
.where('courses.created_at <= ?', @competition.end_time) .where('courses.created_at <= ?', @competition.end_time)
.where("(#{student_count_subquery}) >= 10") .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}))") .where("exists(select 1 from homework_commons hcs where hcs.course_id = courses.id and hcs.publish_time is not null and hcs.publish_time < NOW() 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)') .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) .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()') courses = Course.where(id: course_ids).joins(:shixun_homework_commons).where('homework_commons.publish_time < now()')
@ -366,8 +366,8 @@ class CompetitionTeamsController < ApplicationController
def get_valid_course_count(ids) def get_valid_course_count(ids)
percentage_sql = StudentWork.where('homework_common_id = homework_commons.id and homework_commons.publish_time is not null and homework_commons.publish_time < NOW()') 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') .select('sum(compelete_status !=0 ) as finish, count(*) as total')
.having('finish > (total / 2)').to_sql .having('total != 0 && finish > (total / 2)').to_sql
Course.joins(shixun_homework_commons: :homework_commons_shixuns) Course.joins(shixun_homework_commons: :homework_commons_shixuns)
.where('shixun_id in (?)', ids) .where('shixun_id in (?)', ids)
@ -376,8 +376,8 @@ class CompetitionTeamsController < ApplicationController
end end
def get_valid_shixun_count(ids) def get_valid_shixun_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') .select('sum(compelete_status !=0 ) as finish, count(*) as total')
.having('finish > (total / 2)').to_sql .having('finish > (total / 2)').to_sql
Shixun.joins(homework_commons_shixuns: :homework_common) Shixun.joins(homework_commons_shixuns: :homework_common)
.where(homework_commons: { homework_type: 3 }) .where(homework_commons: { homework_type: 3 })

Loading…
Cancel
Save