From c61cb1190f683a237058ce3babdcfbc26adf3460 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 17:32:04 +0800 Subject: [PATCH 1/5] fixbug --- app/controllers/homework_commons_controller.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 2fcf421f4..018218799 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -106,11 +106,9 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.all_works @all_member_count = student_works.size - logger.info("##########__________@homework.publish_time______________#############{@homework.publish_time}") if @homework.publish_time.blank? || (@homework.publish_time > Time.now) @student_works = [] - if params[:format] == "xlsx" || params[:format] == "zip" - logger.info("##########__________params[:format]______________#############{params[:format]}") + if (params[:format] == "xlsx") || (params[:format] == "zip") normal_status(-1,"作业未发布") end else @@ -198,7 +196,7 @@ class HomeworkCommonsController < ApplicationController end if params[:format] == "xlsx" - complete_works = @work_excel.where("work_status > 0").size + complete_works = @work_excel.exist? ? @work_excel.where("work_status > 0").size : 0 if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") elsif complete_works == 0 @@ -218,8 +216,13 @@ class HomeworkCommonsController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") else - zip_works = @work_excel.where("work_status > 0") - status = checkfileSize(zip_works) + if @work_excel.exist? + zip_works = @work_excel&.where("work_status > 0") + status = checkfileSize(zip_works) + else + status = -1 + end + if status == 0 respond_to do |format| format.zip{ From 1a96c3841df7faadd0c0cfb6076c8cbf67b94939 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 3 Jul 2019 17:33:59 +0800 Subject: [PATCH 2/5] =?UTF-8?q?job=E4=BB=BB=E5=8A=A1=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/exercise_publish_notify_job.rb | 1 + app/jobs/graduation_task_publish_notify_job.rb | 4 +++- app/jobs/submit_graduation_work_notify_job.rb | 5 +++-- app/jobs/submit_student_work_notify_job.rb | 5 +++-- app/models/course_member.rb | 8 ++++---- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/jobs/exercise_publish_notify_job.rb b/app/jobs/exercise_publish_notify_job.rb index 563f6ceb0..f68a68c00 100644 --- a/app/jobs/exercise_publish_notify_job.rb +++ b/app/jobs/exercise_publish_notify_job.rb @@ -6,6 +6,7 @@ class ExercisePublishNotifyJob < ApplicationJob exercise = Exercise.find_by(id: exercise_id) return if exercise.blank? user = exercise.user + course = exercise.course if group_ids.present? students = course.students.where(course_group_id: group_ids) diff --git a/app/jobs/graduation_task_publish_notify_job.rb b/app/jobs/graduation_task_publish_notify_job.rb index 92346ab27..16f5893ae 100644 --- a/app/jobs/graduation_task_publish_notify_job.rb +++ b/app/jobs/graduation_task_publish_notify_job.rb @@ -5,6 +5,8 @@ class GraduationTaskPublishNotifyJob < ApplicationJob def perform(graduation_task_id) task = GraduationTask.find_by(id: graduation_task_id) return if task.blank? + course = task.course + return if course.blank? attrs = %i[ user_id trigger_user_id container_id container_type parent_container_id parent_container_type @@ -18,7 +20,7 @@ class GraduationTaskPublishNotifyJob < ApplicationJob viewed: 0, tiding_type: 'GraduationTask' } Tiding.bulk_insert(*attrs) do |worker| - task.course.course_members.pluck(:user_id).uniq.find_each do |user_id| + course.course_members.pluck(:user_id).uniq.find_each do |user_id| worker.add same_attrs.merge(user_id: user_id) end end diff --git a/app/jobs/submit_graduation_work_notify_job.rb b/app/jobs/submit_graduation_work_notify_job.rb index 17cfc21d2..d4bb21cc4 100644 --- a/app/jobs/submit_graduation_work_notify_job.rb +++ b/app/jobs/submit_graduation_work_notify_job.rb @@ -19,11 +19,12 @@ class SubmitGraduationWorkNotifyJob < ApplicationJob next unless User.exists?(id: user_id) work = task.graduation_works.find_by(user_id: user_id) - next if work.blank? + member = course.students.find_by(user_id: user_id) + next if work.blank? || member.blank? attrs = same_attrs.merge(trigger_user_id: user_id, container_id: work.id) - course.course_member(user_id).member_teachers.find_each do |teacher| + member.member_teachers.find_each do |teacher| worker.add attrs.merge(user_id: teacher.user_id) end end diff --git a/app/jobs/submit_student_work_notify_job.rb b/app/jobs/submit_student_work_notify_job.rb index acb7873ac..c4dff264c 100644 --- a/app/jobs/submit_student_work_notify_job.rb +++ b/app/jobs/submit_student_work_notify_job.rb @@ -19,11 +19,12 @@ class SubmitStudentWorkNotifyJob < ApplicationJob next unless User.exists?(id: user_id) work = homework.student_works.find_by(user_id: user_id) - next if work.blank? + member = course.students.find_by(user_id: user_id) + next if work.blank? || member.blank? attrs = same_attrs.merge(trigger_user_id: user_id, container_id: work.id) - course.course_member(user_id).member_teachers.find_each do |teacher| + member.member_teachers.find_each do |teacher| worker.add attrs.merge(user_id: teacher.user_id) end end diff --git a/app/models/course_member.rb b/app/models/course_member.rb index d9995d463..7db681e67 100644 --- a/app/models/course_member.rb +++ b/app/models/course_member.rb @@ -146,11 +146,11 @@ class CourseMember < ApplicationRecord def member_teachers teacher_groups = course.teacher_course_groups if teacher_groups.count > 0 - member_ids = teacher_groups.where(course_group_id: self.try(:course_group_id)).pluck(:course_member_id) + member_ids = teacher_groups.where(course_group_id: self.try(:course_group_id)).pluck(:course_member_id).compact - none_group_teachers = teacher_groups.pluck(:course_member_id).size > 0 ? teacher_groups.pluck(:course_member_id).join(',') : -1 - teachers = course.teachers.where("members.id not in (#{none_group_teachers}) or - members.id in (#{member_ids.size > 0 ? member_ids.join(',') : -1})") + none_group_teachers = teacher_groups.pluck(:course_member_id).size > 0 ? teacher_groups.pluck(:course_member_id).compact.join(',') : -1 + teachers = course.teachers.where("course_members.id not in (#{none_group_teachers}) or + course_members.id in (#{member_ids.size > 0 ? member_ids.join(',') : -1})") else teachers = course.teachers end From 69ed83fae1a2473223189a4972a90e7e81c8afd2 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 17:34:02 +0800 Subject: [PATCH 3/5] fix bug --- app/controllers/homework_commons_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 018218799..66dd7c864 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -196,7 +196,7 @@ class HomeworkCommonsController < ApplicationController end if params[:format] == "xlsx" - complete_works = @work_excel.exist? ? @work_excel.where("work_status > 0").size : 0 + complete_works = @work_excel.present? ? @work_excel.where("work_status > 0").size : 0 if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") elsif complete_works == 0 @@ -216,7 +216,7 @@ class HomeworkCommonsController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") else - if @work_excel.exist? + if @work_excel.present? zip_works = @work_excel&.where("work_status > 0") status = checkfileSize(zip_works) else From 441dcf54e77bfe632dcd501863857d37cc8b5d87 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 17:39:12 +0800 Subject: [PATCH 4/5] fix bug --- app/controllers/homework_commons_controller.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 66dd7c864..229db7278 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -106,9 +106,15 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.all_works @all_member_count = student_works.size - if @homework.publish_time.blank? || (@homework.publish_time > Time.now) + logger.info("@@@@@@@_____________@homework.publish_time______________##{@homework.publish_time}") + logger.info("@@@@@@@_____________@homework.publish_time > Time.now______________##{@homework.publish_time > Time.now}") + + if @homework.publish_time.nil? || (@homework.publish_time > Time.now) + logger.info("@@@@@@@_____________1111111111_____________#11111111111") @student_works = [] if (params[:format] == "xlsx") || (params[:format] == "zip") + logger.info("@@@@@@@_____________22222222_____________#2222222221") + normal_status(-1,"作业未发布") end else From 0e68cc0e4ccbc1c4ca24726f478859e2c3453058 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 17:49:37 +0800 Subject: [PATCH 5/5] fix bug --- app/controllers/homework_commons_controller.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 229db7278..d49dac853 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -106,15 +106,10 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.all_works @all_member_count = student_works.size - logger.info("@@@@@@@_____________@homework.publish_time______________##{@homework.publish_time}") - logger.info("@@@@@@@_____________@homework.publish_time > Time.now______________##{@homework.publish_time > Time.now}") if @homework.publish_time.nil? || (@homework.publish_time > Time.now) - logger.info("@@@@@@@_____________1111111111_____________#11111111111") @student_works = [] if (params[:format] == "xlsx") || (params[:format] == "zip") - logger.info("@@@@@@@_____________22222222_____________#2222222221") - normal_status(-1,"作业未发布") end else