From 00fec133676a78f596f47cf6b7bc856a0987dfb2 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Thu, 30 Oct 2014 17:42:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=85=88=E6=8C=89=E6=80=BB?= =?UTF-8?q?=E8=AF=84=E5=BE=97=E5=88=86=E7=84=B6=E5=90=8E=E6=8C=89=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_attach_controller.rb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/controllers/homework_attach_controller.rb b/app/controllers/homework_attach_controller.rb index 9bbe7bcca..364742aea 100644 --- a/app/controllers/homework_attach_controller.rb +++ b/app/controllers/homework_attach_controller.rb @@ -27,10 +27,12 @@ class HomeworkAttachController < ApplicationController #获取已评作业列表 def get_batch_homeworks teachers = find_course_teachers @course + teacher_proportion = get_teacher_proportion @bid all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT * FROM (SELECT homework_attaches.*, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id IN #{teachers} and stars IS NOT NULL) AS t_score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id NOT IN #{teachers}) AS s_score - FROM homework_attaches WHERE bid_id = #{@bid.id} ORDER BY s_score DESC,created_at ASC) AS table1 + FROM homework_attaches WHERE bid_id = #{@bid.id} + ORDER BY (CASE WHEN t_score IS NULL THEN 0 ELSE t_score * #{teacher_proportion} END + CASE WHEN s_score IS NULL THEN 0 ELSE s_score * #{1 - teacher_proportion} END) DESC,created_at ASC) AS table1 WHERE table1.t_score IS NOT NULL") @homework_list = paginateHelper all_homework_list,10 respond_to do |format| @@ -41,11 +43,12 @@ class HomeworkAttachController < ApplicationController #获取所有作业列表 def get_homeworks teachers = find_course_teachers @course + teacher_proportion = get_teacher_proportion @bid all_homework_list = HomeworkAttach.eager_load(:attachments,:user,:rate_averages).find_by_sql("SELECT homework_attaches.*, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id in #{teachers}) AS t_score, (SELECT AVG(stars) FROM seems_rateable_rates WHERE rateable_type = 'HomeworkAttach' AND rateable_id = homework_attaches.id AND rater_id not in #{teachers}) AS s_score FROM homework_attaches WHERE bid_id = #{@bid.id} - ORDER BY s_score DESC,created_at ASC") + ORDER BY (CASE WHEN t_score IS NULL THEN 0 ELSE t_score * #{teacher_proportion} END + CASE WHEN s_score IS NULL THEN 0 ELSE s_score * #{1 - teacher_proportion} END) DESC,created_at ASC") @homework_list = paginateHelper all_homework_list,10 respond_to do |format| format.js @@ -393,5 +396,15 @@ class HomeworkAttachController < ApplicationController end teachers end + + #获取作业教师评分所占比例 + def get_teacher_proportion bid + if bid.proportion + teacher_proportion = bid.proportion * 1.0 / 100 + else + teacher_proportion = 1.0 + end + teacher_proportion + end end