From c353398d65d110894f723fecc3bf74ed10c89626 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Mon, 4 May 2015 17:36:48 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/courses.rb | 12 +++++++ app/api/mobile/entities/course.rb | 1 + app/services/courses_service.rb | 54 ++++++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 1 deletion(-) 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/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 From 8929644ab15890c18f24dffd45b8a9b155e95000 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Mon, 4 May 2015 17:38:38 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=AD=A6=E7=94=9Fmodel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/entities/member.rb | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 app/api/mobile/entities/member.rb 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 From 71004e2f7832acd901d916873ff10e420dd0b3ab Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Tue, 5 May 2015 10:58:37 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=98=BE=E7=A4=BA=E5=A4=AA=E6=85=A2=EF=BC=8C?= =?UTF-8?q?=E9=9C=80=E8=A6=81=E5=AF=B9=E8=A1=A8=E5=8A=A0=E7=B4=A2=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20150505023015_add_index_to_homeworkattach_bid_id.rb | 5 +++++ ...0150505023127_add_index_to_studentforcourse_student_id.rb | 5 +++++ ...20150505023452_add_index_to_studentforcourse_course_id.rb | 5 +++++ ...0150505025003_add_index_to_homeworkforcourse_course_id.rb | 5 +++++ .../20150505025537_add_index_to_homeworkforcourse_bid_id.rb | 5 +++++ 5 files changed, 25 insertions(+) create mode 100644 db/migrate/20150505023015_add_index_to_homeworkattach_bid_id.rb create mode 100644 db/migrate/20150505023127_add_index_to_studentforcourse_student_id.rb create mode 100644 db/migrate/20150505023452_add_index_to_studentforcourse_course_id.rb create mode 100644 db/migrate/20150505025003_add_index_to_homeworkforcourse_course_id.rb create mode 100644 db/migrate/20150505025537_add_index_to_homeworkforcourse_bid_id.rb diff --git a/db/migrate/20150505023015_add_index_to_homeworkattach_bid_id.rb b/db/migrate/20150505023015_add_index_to_homeworkattach_bid_id.rb new file mode 100644 index 000000000..ce4d4499c --- /dev/null +++ b/db/migrate/20150505023015_add_index_to_homeworkattach_bid_id.rb @@ -0,0 +1,5 @@ +class AddIndexToHomeworkattachBidId < ActiveRecord::Migration + def change + add_index(:homework_attaches,:bid_id) + end +end diff --git a/db/migrate/20150505023127_add_index_to_studentforcourse_student_id.rb b/db/migrate/20150505023127_add_index_to_studentforcourse_student_id.rb new file mode 100644 index 000000000..d24e2f31e --- /dev/null +++ b/db/migrate/20150505023127_add_index_to_studentforcourse_student_id.rb @@ -0,0 +1,5 @@ +class AddIndexToStudentforcourseStudentId < ActiveRecord::Migration + def change + add_index(:students_for_courses,:student_id) + end +end diff --git a/db/migrate/20150505023452_add_index_to_studentforcourse_course_id.rb b/db/migrate/20150505023452_add_index_to_studentforcourse_course_id.rb new file mode 100644 index 000000000..99c0a640a --- /dev/null +++ b/db/migrate/20150505023452_add_index_to_studentforcourse_course_id.rb @@ -0,0 +1,5 @@ +class AddIndexToStudentforcourseCourseId < ActiveRecord::Migration + def change + add_index(:students_for_courses,:course_id) + end +end diff --git a/db/migrate/20150505025003_add_index_to_homeworkforcourse_course_id.rb b/db/migrate/20150505025003_add_index_to_homeworkforcourse_course_id.rb new file mode 100644 index 000000000..cd60a00af --- /dev/null +++ b/db/migrate/20150505025003_add_index_to_homeworkforcourse_course_id.rb @@ -0,0 +1,5 @@ +class AddIndexToHomeworkattachCourseId < ActiveRecord::Migration + def change + add_index(:homework_for_courses,:course_id) + end +end diff --git a/db/migrate/20150505025537_add_index_to_homeworkforcourse_bid_id.rb b/db/migrate/20150505025537_add_index_to_homeworkforcourse_bid_id.rb new file mode 100644 index 000000000..7504e8421 --- /dev/null +++ b/db/migrate/20150505025537_add_index_to_homeworkforcourse_bid_id.rb @@ -0,0 +1,5 @@ +class AddIndexToHomeworkforcourseBidId < ActiveRecord::Migration + def change + add_index(:homework_for_courses,:bid_id) + end +end From 6b7a17de8c72a0d9b4110e43aa2e6dbdbf53c09c Mon Sep 17 00:00:00 2001 From: huang Date: Tue, 5 May 2015 14:11:01 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=BA=93Git=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/show.html.erb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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

李海提供