From 1b1cce615d79f2d6774d99701ba0cbdfb5c54689 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Wed, 8 Jul 2015 17:36:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E5=A4=8D=E9=80=9A=E7=9F=A5api=20?= =?UTF-8?q?=E6=B4=BB=E8=B7=83=E6=8E=92=E5=90=8Dapi=20=E5=85=B6=E4=BB=96api?= =?UTF-8?q?=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/comments.rb | 14 ++++++++++++++ app/api/mobile/apis/courses.rb | 3 ++- app/api/mobile/entities/news.rb | 2 ++ app/services/comment_service.rb | 5 ++++- app/services/courses_service.rb | 18 ++++++++++++++---- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/app/api/mobile/apis/comments.rb b/app/api/mobile/apis/comments.rb index 86132a93a..7fa676161 100644 --- a/app/api/mobile/apis/comments.rb +++ b/app/api/mobile/apis/comments.rb @@ -113,6 +113,20 @@ module Mobile present :status, 0 end + desc '通知评论列表' + params do + requires :token, type: String + requires :notice_id,type:Integer,desc:'通知id' + optional :page,type:Integer,desc:'页码' + end + get ':notice_id/notice_comments' do + cs = CommentService.new + comments = cs.notice_comments params,current_user + present :data, comments, with: Mobile::Entities::Comment + present :status, 0 + end + + end end end diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index 509d31d86..39d2ebe9d 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -312,11 +312,12 @@ module Mobile present :status,0 end - desc '课程历次作业总成绩列表' + desc '总成绩 or 活跃度列表' params do requires :token,type:String requires :course_id,type:Integer,desc:'课程id' optional :page,type:Integer,desc:'页码' + optional :type,type:Integer,desc:'0是活跃度,1是成绩' end get ':course_id/students_score_list' do cs = CoursesService.new diff --git a/app/api/mobile/entities/news.rb b/app/api/mobile/entities/news.rb index 5ed3958ba..36893d16f 100644 --- a/app/api/mobile/entities/news.rb +++ b/app/api/mobile/entities/news.rb @@ -56,6 +56,8 @@ module Mobile expose :comments, using: Mobile::Entities::Comment do |f, opt| if f.is_a?(Hash) && f.key?(:comments) f[:comments] + elsif f.is_a?(::News) && f.respond_to?(:comments) + f.send(:comments) end end diff --git a/app/services/comment_service.rb b/app/services/comment_service.rb index 2464297da..62955905b 100644 --- a/app/services/comment_service.rb +++ b/app/services/comment_service.rb @@ -112,6 +112,9 @@ class CommentService end end - + # 获取课程里的某个通知的所有回复 + def notice_comments params,current_user + News.find(params[:notice_id]).comments.page(params[:page] || 1).per(10) + end end \ No newline at end of file diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index 94dcaf6fc..00a8ffd8b 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -719,11 +719,21 @@ class CoursesService # 获取课程历次作业的学生总成绩 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) + if params[:type] == 1 + homework_count = Course.find(params[:course_id]).homework_commons.count + + 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) + else + sql1 = " select users.*,count(author_id)*2 active_count from messages " << + " LEFT JOIN users on messages.author_id = users.id " << + " where messages.board_id in (select id from boards where boards.course_id = #{params[:course_id]} ) " << + " GROUP BY messages.author_id ORDER BY count(author_id) desc " << + " limit #{page*10},10" + User.find_by_sql(sql1) + end end # 获取某次作业的所有作业列表