dev_aliyun
p31729568 5 years ago
parent 57588e33f0
commit 6822506bdf

@ -44,7 +44,7 @@ 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('sum(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 and 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")
@ -367,7 +367,7 @@ 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('sum(compelete_status !=0 ) as finish, count(*) as total') .select('sum(compelete_status !=0 ) as finish, count(*) as total')
.having('total != 0 && finish > (total / 2)').to_sql .having('total != 0 and 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)
@ -378,7 +378,7 @@ class CompetitionTeamsController < ApplicationController
def get_valid_shixun_count(ids) def get_valid_shixun_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('sum(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 and 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 })
.where('course_id in (?)', ids) .where('course_id in (?)', ids)

Loading…
Cancel
Save