diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index c325639f9..4b574cc11 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -311,6 +311,18 @@ module Mobile present :data,news,with:Mobile::Entities::News present :status,0 end + + desc '课程历次作业总成绩列表' + params do + requires :token,type:String + requires :course_id,type:Integer,desc:'课程id' + optional :page,type:Integer,desc:'页码' + end + get ':course_id/students_score_list' do + cs = CoursesService.new + news = cs.students_score_list params,current_user + present :data,news,with:Mobile::Entities::User + end end end end diff --git a/app/api/mobile/entities/course_dynamic.rb b/app/api/mobile/entities/course_dynamic.rb index 221870cd4..46ab5b272 100644 --- a/app/api/mobile/entities/course_dynamic.rb +++ b/app/api/mobile/entities/course_dynamic.rb @@ -97,6 +97,16 @@ module Mobile obj end + expose :better_students,using:Mobile::Entities::User do |f,opt| + obj = nil + f[:dynamics].each do |d| + if d[:type] == 6 + obj = d[:better_students] + end + end + obj + end + end end end \ No newline at end of file diff --git a/app/api/mobile/entities/user.rb b/app/api/mobile/entities/user.rb index aee687dc9..2b3483625 100644 --- a/app/api/mobile/entities/user.rb +++ b/app/api/mobile/entities/user.rb @@ -22,6 +22,8 @@ module Mobile get_user_location u unless u.user_extensions.nil? when :brief_introduction u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.brief_introduction + when :student_num + u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.student_id end end end @@ -47,6 +49,10 @@ module Mobile user_expose :location #签名 user_expose :brief_introduction + #总成绩 + user_expose :score + #学号 + user_expose :student_num end end diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index fbdaee7cf..339d9a92d 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -666,7 +666,13 @@ class CoursesService latest_course_dynamics = [] dynamics_count = 0 # 课程学霸 学生总分数排名靠前的5个人 - + homework_count = course.homework_commons.count + unless homework_count == 0 + sql = "select users.*,sum(IFNULL(0,student_works.final_score))/#{homework_count} score from student_works left outer join users on student_works.user_id = users.id" << + " where homework_common_id in ( select id from homework_commons where homework_commons.course_id = #{course.id}) GROUP BY student_works.user_id ORDER BY score limit 0,5" + latest_course_dynamics <<{:type=> 6,:time=>Time.now.to_s,:count=> 5,:better_students=> User.find_by_sql(sql)} + dynamics_count += 1 + end # 课程通知 latest_news = course.news.page(1).per(2).order("created_on desc") unless latest_news.first.nil? @@ -707,5 +713,14 @@ class CoursesService result end + # 获取课程历次作业的学生总成绩 + def students_score_list params,current_user + homework_count = Course.find(params[:course_id]).homework_commons.count + page = (params[:page] || 1) - 1 + sql = "select users.*,sum(IFNULL(0,student_works.final_score))/#{homework_count} score from student_works left outer join users on student_works.user_id = users.id" << + " where homework_common_id in ( select id from homework_commons where homework_commons.course_id = #{params[:course_id]}) GROUP BY student_works.user_id ORDER BY score limit #{page*10},10" + User.find_by_sql(sql) + end + end