diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb index ce02f4249..f7b03947c 100644 --- a/app/api/mobile/apis/courses.rb +++ b/app/api/mobile/apis/courses.rb @@ -240,6 +240,18 @@ module Mobile present :status, 0 end + desc '课程学生' + params do + requires :token,type:String + requires :course_id,type:Integer,desc: '课程id' + end + get ":course_id/members" do + cs = CoursesService.new + count = cs.course_members params + present :data, count, with: Mobile::Entities::Member + present :status, 0 + end + end end end diff --git a/app/api/mobile/entities/course.rb b/app/api/mobile/entities/course.rb index 520f73384..50812b349 100644 --- a/app/api/mobile/entities/course.rb +++ b/app/api/mobile/entities/course.rb @@ -46,6 +46,7 @@ module Mobile course_expose :term course_expose :time course_expose :updated_at + course_expose :course_student_num expose :teacher, using: Mobile::Entities::User do |c, opt| if c.is_a? ::Course c.teacher diff --git a/app/api/mobile/entities/member.rb b/app/api/mobile/entities/member.rb new file mode 100644 index 000000000..837ec788a --- /dev/null +++ b/app/api/mobile/entities/member.rb @@ -0,0 +1,33 @@ +module Mobile + module Entities + class Member < Grape::Entity + include ApplicationHelper + include ApiHelper + def self.member_expose(f) + expose f do |u,opt| + if u.is_a?(Hash) && u.key?(f) + u[f] + elsif u.is_a?(::Member) + if u.respond_to?(f) + u.send(f) + else + case f + when :student_id + u.user.user_extensions.student_id + end + end + end + + end + end + + expose :user, using: Mobile::Entities::User do |c, opt| + if c.is_a?(::Member) + c.user + end + end + member_expose :student_id + member_expose :score + end + end +end \ No newline at end of file diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb index b992665d3..42bf8fe3f 100644 --- a/app/services/courses_service.rb +++ b/app/services/courses_service.rb @@ -169,7 +169,7 @@ class CoursesService unless (course.is_public == 1 || current_user.member_of_course?(course) || current_user.admin?) raise '403' end - {:course => course,:work_unit => work_unit, :img_url => url_to_avatar(course),:current_user_is_member => current_user.member_of_course?(course),:current_user_is_teacher => is_course_teacher(current_user,course)} + {:course => course,:work_unit => work_unit, :img_url => url_to_avatar(course),:current_user_is_member => current_user.member_of_course?(course),:current_user_is_teacher => is_course_teacher(current_user,course),:course_student_num => course ? course.student.count.to_s : 0} end #创建课程 @@ -439,6 +439,11 @@ class CoursesService result end + # 课程学生列表 + def course_members params + @all_members = student_homework_score(0,params[:course_id], 10,"desc") + end + private def show_homework_info course,bid,current_user,is_course_teacher author_real_name = bid.author.lastname + bid.author.firstname @@ -476,5 +481,52 @@ class CoursesService end + def student_homework_score(groupid,course_id, nums, score_sort_by) + #teachers = find_course_teachers(@course) + #start_from = start_from * nums + sql_select = "" + if groupid == 0 + if nums == 0 + sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches + WHERE members.course_id = #{course_id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{course_id}) AND members.user_id = homework_attaches.user_id + AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id}) GROUP BY members.user_id + UNION all + SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{course_id} AND + students_for_courses.course_id = #{course_id} and members.user_id = students_for_courses.student_id AND + members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id} ) + ) + GROUP BY members.user_id ORDER BY score #{score_sort_by}" + else + sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches + WHERE members.course_id = #{course_id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{course_id}) AND members.user_id = homework_attaches.user_id + AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id}) GROUP BY members.user_id + UNION all + SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{course_id} AND + students_for_courses.course_id = #{course_id} and members.user_id = students_for_courses.student_id AND + members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id} ) + ) + GROUP BY members.user_id ORDER BY score #{score_sort_by} " #limit #{start_from}, #{nums}" + + end + else + sql_select = "SELECT members.*, SUM(homework_attaches.score) as score FROM members, homework_attaches + WHERE members.course_id = #{course_id} AND members.user_id in (SELECT students_for_courses.student_id FROM students_for_courses WHERE course_id = #{course_id}) AND members.user_id = homework_attaches.user_id + and members.course_group_id = #{groupid} AND homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id}) + GROUP BY members.user_id + UNION all + SELECT members.*, 0 as score FROM members,homework_attaches,students_for_courses WHERE members.course_id = #{course_id} + and members.course_group_id = #{groupid} AND + students_for_courses.course_id = #{course_id} and members.user_id = students_for_courses.student_id AND + members.user_id NOT IN (SELECT homework_attaches.user_id FROM homework_attaches WHERE homework_attaches.bid_id in (SELECT bid_id FROM homework_for_courses WHERE course_id = #{course_id} ) + ) + GROUP BY members.user_id ORDER BY score #{score_sort_by}" + end + sql = ActiveRecord::Base.connection() + homework_scores = Member.find_by_sql(sql_select) + sql.close() + + homework_scores + end + end \ No newline at end of file diff --git a/app/views/repositories/show.html.erb b/app/views/repositories/show.html.erb index 077bccdad..9d545d89a 100644 --- a/app/views/repositories/show.html.erb +++ b/app/views/repositories/show.html.erb @@ -34,9 +34,9 @@
项目代码请设置好正确的编码方式(utf-8),否则中文会出现乱码
- -建立版本库文件夹,打开命令行执行如下:
+项目代码请设置好正确的编码方式(utf-8),否则中文会出现乱码。
+通过cmd命令提示符进入代码对应文件夹的根目录,假设当前用户的登录名为user,版本库名称为demo,需要操作的版本库分支为branch。 + 如果是首次提交代码,执行如下命令:
git init
@@ -46,19 +46,19 @@git commit -m "first commit"
git remote add origin - http://xianbo_trustie2@repository.trustie.net/xianbo/trustie2.git + http://user_demo@repository.trustie.net/user/demo.git
git config http.postBuffer 524288000 #设置本地post缓存为500MB
-git push -u origin master:master
+git push -u origin branch:branch
已经有本地库,还没有配置远程地址,打开命令行执行如下:
git remote add origin http://xianbo_trustie2@repository.trustie.net/xianbo/trustie2.git
+git remote add origin http://user_demo@repository.trustie.net/user/demo.git
git add .
@@ -66,14 +66,14 @@git config http.postBuffer 524288000 #设置本地post缓存为500MB
-git push -u origin master:master
+git push -u origin branch:branch
已有远程地址,创建一个远程分支,并切换到该分支,打开命令行执行如下:
git clone http://xianbo_trustie2@repository.trustie.net/xianbo/trustie2.git
+git clone http://user_demo@repository.trustie.net/user/demo.git
git push
@@ -87,7 +87,7 @@git remote add trustie - http://xianbo_trustie2@repository.trustie.net/xianbo/trustie2.git + http://user_demo@repository.trustie.net/user/demo.git
git add .
@@ -96,7 +96,7 @@git config http.postBuffer 524288000 #设置本地post缓存为500MB
-git push -u trustie master:master
+git push -u trustie branch:branch
李海提供