From 795d4ecf71f25ffa990f94285f29d36f0cd234ab Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 11 Jul 2019 10:49:03 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=92=8C=E4=BD=9C=E5=93=81=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/graduation_tasks_controller.rb | 6 ++++-- app/helpers/graduation_tasks_helper.rb | 2 +- app/models/graduation_work.rb | 2 +- app/views/graduation_tasks/index.json.jbuilder | 8 ++++---- app/views/graduation_tasks/tasks_list.json.jbuilder | 5 +++-- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index c3b73ad20..910299fd0 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -37,7 +37,7 @@ class GraduationTasksController < ApplicationController @all_count = @course.graduation_tasks.size @published_count = @course.graduation_tasks.where("publish_time <= '#{Time.now}'").size @task_count = @tasks.size - @tasks = @tasks.reorder("#{default_order}").page(page).per(15).includes(:graduation_works, course: [course_members: :teacher_course_groups]) + @tasks = @tasks.reorder("#{default_order}").page(page).per(15).includes(:graduation_works) end # 任务问答 @@ -72,7 +72,7 @@ class GraduationTasksController < ApplicationController @work_list = @task.graduation_works.where(user_id: user_ids).includes(user: [:user_extension]) @all_work_count = @work_list.count - @teachers = @course.teachers.where.not(user_id: current_user.id) + @teachers = @course.teachers.where.not(user_id: current_user.id).includes(:user) # 教师评阅搜索 0: 未评, 1 已评 unless params[:teacher_comment].blank? graduation_work_ids = GraduationWorkScore.where(graduation_work_id: @work_list.map(&:id)).pluck(:graduation_work_id) @@ -123,6 +123,8 @@ class GraduationTasksController < ApplicationController @work_count = @work_list.count @work_excel = @work_list @work_list = @work_list.page(page).per(limit) + @students = @course.students + @assign_power = @user_course_identity < Course::STUDENT && @task.cross_comment && @task.comment_status == 2 if params[:format] == "xlsx" complete_works = @work_excel.where("work_status > 0").size diff --git a/app/helpers/graduation_tasks_helper.rb b/app/helpers/graduation_tasks_helper.rb index b9039544d..2bc059a55 100644 --- a/app/helpers/graduation_tasks_helper.rb +++ b/app/helpers/graduation_tasks_helper.rb @@ -67,7 +67,7 @@ module GraduationTasksHelper # 作品数统计:type: 1 已提交 0 未提交 def grduationwork_count task, type works = task.graduation_works - type == 1 ? works.where("work_status !=?", 0).size : works.where("work_status =?", 0).size + type == 1 ? works.select{|work| work.work_status != 0}.size : works.select{|work| work.work_status == 0}.size end # 普通/分组 作业作品状态数组 diff --git a/app/models/graduation_work.rb b/app/models/graduation_work.rb index 093e409a9..235bfcac6 100644 --- a/app/models/graduation_work.rb +++ b/app/models/graduation_work.rb @@ -68,7 +68,7 @@ class GraduationWork < ApplicationRecord # 作品是否能够分配指导老师 def assign_power?(course_identity) - course_identity < Course::STUDENT && self.graduation_task.cross_comment.present? && self.graduation_task.comment_status == 2 + course_identity < Course::STUDENT && graduation_task.cross_comment && graduation_task.comment_status == 2 end # 老师评阅分 diff --git a/app/views/graduation_tasks/index.json.jbuilder b/app/views/graduation_tasks/index.json.jbuilder index 7fcececd9..a6540555d 100644 --- a/app/views/graduation_tasks/index.json.jbuilder +++ b/app/views/graduation_tasks/index.json.jbuilder @@ -1,10 +1,6 @@ json.course_identity @identity json.course_public @course.is_public == 1 json.is_end @course.is_end -json.all_count @all_count -json.published_count @published_count -json.unpublished_count @all_count - @published_count -json.task_count @task_count json.tasks @tasks.each do |task| # task_private = @identity > Course::STUDENT && !task.is_public @@ -29,3 +25,7 @@ json.tasks @tasks.each do |task| end end +json.all_count @all_count +json.published_count @published_count +json.unpublished_count @all_count - @published_count +json.task_count @task_count diff --git a/app/views/graduation_tasks/tasks_list.json.jbuilder b/app/views/graduation_tasks/tasks_list.json.jbuilder index 7588b6b6e..ac5aa050e 100644 --- a/app/views/graduation_tasks/tasks_list.json.jbuilder +++ b/app/views/graduation_tasks/tasks_list.json.jbuilder @@ -34,6 +34,7 @@ if @task.published? || @user_course_identity < Course::STUDENT json.work_count @work_count json.all_work_count @all_work_count end + # 学生数据 json.work_lists do json.array! @work_list do |work| @@ -41,7 +42,7 @@ if @task.published? || @user_course_identity < Course::STUDENT json.user_id work.user.id json.name work.user.real_name json.student_id work.user.student_id - json.class_grouping_name work.class_grouping_name + json.class_grouping_name @students.select{|student| student.user_id == work.user_id}.first.try(:course_group_name) json.ultimate_score work.ultimate_score if @task.have_grouping? json.grouping_name work.grouping_name @@ -58,7 +59,7 @@ if @task.published? || @user_course_identity < Course::STUDENT end json.late_penalty work.late_penalty if @task.allow_late json.final_score work_final_score work, @current_user, @user_course_identity - json.assign work.assign_power?(@user_course_identity) + json.assign @assign_power json.view_work @view_work || @current_user.id == work.user_id end end From ef5da1ea0ee164dd20559583be61b2982e5f8971 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 11 Jul 2019 11:07:36 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E4=BD=9C=E5=93=81?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/graduation_tasks_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 910299fd0..cadac75be 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -112,7 +112,7 @@ class GraduationTasksController < ApplicationController # 排序 rorder = params[:order].blank? ? "updated_at" : params[:order] b_order = params[:b_order].blank? ? "desc" : params[:b_order] - if rorder == "created_at" || rorder == "work_score" + if rorder == "updated_at" || rorder == "work_score" @work_list = @work_list.order("graduation_works.#{rorder} #{b_order}") elsif rorder == "student_id" @work_list = @work_list.joins(user: :user_extension).order("user_extensions.#{rorder} #{b_order}") From 32ecb2ed6dd47cbfe1a1404326d157b7c6f3f6fc Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 11 Jul 2019 11:19:48 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/graduation_tasks_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index cadac75be..9b62f7dbd 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -110,9 +110,9 @@ class GraduationTasksController < ApplicationController end # 排序 - rorder = params[:order].blank? ? "updated_at" : params[:order] + rorder = params[:order].blank? ? "update_time" : params[:order] b_order = params[:b_order].blank? ? "desc" : params[:b_order] - if rorder == "updated_at" || rorder == "work_score" + if rorder == "update_time" || rorder == "work_score" @work_list = @work_list.order("graduation_works.#{rorder} #{b_order}") elsif rorder == "student_id" @work_list = @work_list.joins(user: :user_extension).order("user_extensions.#{rorder} #{b_order}") From f8ba7399df12316a009789b2e735f51e1f6f7fb0 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 11 Jul 2019 11:23:54 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=AE=9E=E8=B7=B5=E7=A4=BE=E5=8C=BA?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E7=9A=84'=E6=9C=80=E7=83=AD'tab=E7=9A=84?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/subjects_controller.rb | 22 ++++++++++++---------- app/models/subject.rb | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index bb7059af6..34f9c2f5a 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -22,17 +22,17 @@ class SubjectsController < ApplicationController # 最热排序 if reorder == "myshixun_count" if select - @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, - subjects.shixuns_count, COUNT(myshixuns.id) AS myshixun_member_count FROM myshixuns, stage_shixuns, subjects - WHERE myshixuns.shixun_id = stage_shixuns.shixun_id AND stage_shixuns.subject_id = subjects.id - AND `subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%' - AND `subjects`.`repertoire_id` = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count DESC") + @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, + subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns + on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where + subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%' + AND `subjects`.`repertoire_id` = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count DESC") else - @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, - subjects.shixuns_count, COUNT(myshixuns.id) AS myshixun_member_count FROM myshixuns, stage_shixuns, subjects - WHERE myshixuns.shixun_id = stage_shixuns.shixun_id AND stage_shixuns.subject_id = subjects.id - AND `subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%' - GROUP BY subjects.id ORDER BY myshixun_member_count DESC") + @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, + subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns + on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where + `subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%' + GROUP BY subjects.id ORDER BY myshixun_member_count DESC") end else # 我的路径 @@ -68,6 +68,8 @@ class SubjectsController < ApplicationController @subjects = @subjects.page(page).per(limit).includes(:shixuns) else @subjects = @subjects[offset, limit] + subject_ids = @subjects.pluck(:id) + @subjects = Subject.where(id: subject_ids).order("field(id,#{subject_ids.join(',')})").includes(:shixuns) end end diff --git a/app/models/subject.rb b/app/models/subject.rb index ced610377..66ac41c40 100644 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -31,7 +31,7 @@ class Subject < ApplicationRecord # 挑战过路径的成员数 def member_count - shixuns.sum(:myshixuns_count) + shixuns.pluck(:myshixuns_count).sum end def all_score From 4032174a104544866ecbadb757bccd8b25cec70a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 11 Jul 2019 11:26:23 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/subjects_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 34f9c2f5a..20b28121f 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -65,11 +65,11 @@ class SubjectsController < ApplicationController @total_count = @subjects.size if reorder != "myshixun_count" - @subjects = @subjects.page(page).per(limit).includes(:shixuns) + @subjects = @subjects.page(page).per(limit).includes(:shixuns, :repertoire) else @subjects = @subjects[offset, limit] subject_ids = @subjects.pluck(:id) - @subjects = Subject.where(id: subject_ids).order("field(id,#{subject_ids.join(',')})").includes(:shixuns) + @subjects = Subject.where(id: subject_ids).order("field(id,#{subject_ids.join(',')})").includes(:shixuns, :repertoire) end end