课程动态api改变

查看学生作业总平均分列表
This commit is contained in:
lizanle 2015-07-01 16:56:03 +08:00
parent 248a3c191a
commit 664770c63f
4 changed files with 44 additions and 1 deletions

View File

@ -311,6 +311,18 @@ module Mobile
present :data,news,with:Mobile::Entities::News present :data,news,with:Mobile::Entities::News
present :status,0 present :status,0
end 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 end
end end

View File

@ -97,6 +97,16 @@ module Mobile
obj obj
end 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 end
end end

View File

@ -22,6 +22,8 @@ module Mobile
get_user_location u unless u.user_extensions.nil? get_user_location u unless u.user_extensions.nil?
when :brief_introduction when :brief_introduction
u.nil? || u.user_extensions.nil? ? "" : u.user_extensions.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 end
end end
@ -47,6 +49,10 @@ module Mobile
user_expose :location user_expose :location
#签名 #签名
user_expose :brief_introduction user_expose :brief_introduction
#总成绩
user_expose :score
#学号
user_expose :student_num
end end
end end

View File

@ -666,7 +666,13 @@ class CoursesService
latest_course_dynamics = [] latest_course_dynamics = []
dynamics_count = 0 dynamics_count = 0
# 课程学霸 学生总分数排名靠前的5个人 # 课程学霸 学生总分数排名靠前的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") latest_news = course.news.page(1).per(2).order("created_on desc")
unless latest_news.first.nil? unless latest_news.first.nil?
@ -707,5 +713,14 @@ class CoursesService
result result
end 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 end