From 9ee6fee20ad7640d8721431e6e65c5f77046264c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 16:58:42 +0800 Subject: [PATCH 1/9] fix bug --- .../exercise_questions_controller.rb | 40 ++++++------------- app/helpers/exercises_helper.rb | 9 +++++ 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index b852e9437..e33e5e2dc 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -347,36 +347,20 @@ class ExerciseQuestionsController < ApplicationController #当试卷已发布时(试卷的总状态),当标准答案修改时,如有已提交的学生,需重新计算分数. - # if @exercise.exercise_status == 2 - # ex_users_committed = @exercise.exercise_users.exercise_user_committed - # if ex_users_committed.size > 0 - # ex_users_committed.each do |ex_user| - # user = ex_user.user - # objective_score = calculate_student_score(@exercise,user)[:total_score] - # subjective_score = ex_user.subjective_score - # total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - # total_score = objective_score + total_score_subjective_score - # ex_user.update_attributes(objective_score:objective_score,score:total_score) - # end - # end - # end - ex_users_committed = @exercise.exercise_users.exercise_user_committed - if ex_users_committed.size > 0 - ex_users_committed.each do |ex_user| - user = ex_user.user - objective_score = calculate_student_score(@exercise,user)[:total_score] - subjective_score = ex_user.subjective_score - total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - total_score = objective_score + total_score_subjective_score - ex_user.update_attributes(objective_score:objective_score,score:total_score) + if @exercise.exercise_status == 2 + ex_users_committed = @exercise.exercise_users.exercise_user_committed + if ex_users_committed.size > 0 + ex_users_committed.each do |ex_user| + user = ex_user.user + objective_score = calculate_student_score(@exercise,user)[:total_score] + subjective_score = ex_user.subjective_score + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = objective_score + total_score_subjective_score + ex_user.update_attributes(objective_score:objective_score,score:total_score) + end end end - - if @exercise_question.save - normal_status(0,"试卷更新成功!") - else - normal_status(-1,"试卷更新失败!") - end + normal_status(0,"试卷更新成功!") rescue Exception => e uid_logger_error(e.message) tip_exception("页面调用失败!") diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 437965ca6..55ade6e7c 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -382,6 +382,9 @@ module ExercisesHelper end answers_content.update_all(:score => q_score_1) score1 = score1 + q.question_score + else + answers_content.update_all(:score => -1.0) + score1 += 0.0 end else score1 += 0.0 @@ -403,6 +406,9 @@ module ExercisesHelper if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数 u.update_column('score',q_score_2) score2 = score2 + q_score_2 + else + u.update_column('score',-1.0) + score2 += 0.0 end end else @@ -413,6 +419,9 @@ module ExercisesHelper u.update_column("score",q_score_2) score2 = score2 + q_score_2 st_answer_text.delete(u_answer_text) + else + u.update_column('score',-1.0) + score2 += 0.0 end end end From 2c472f44a9a6e8245fd0d7899a2b70d5f056c7b3 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 17:10:03 +0800 Subject: [PATCH 2/9] fix bug --- app/controllers/homework_commons_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 4474d47c8..2fcf421f4 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -106,9 +106,11 @@ 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]}") normal_status(-1,"作业未发布") end else From 41f01f49614a1885ffe373e7eaeb7033fb4a3a58 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 3 Jul 2019 17:21:21 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 1 + db/migrate/20190703090511_add_index_for_shixun_services.rb | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 db/migrate/20190703090511_add_index_for_shixun_services.rb diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 5a1773a10..2c4f2a7d1 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -180,6 +180,7 @@ class ShixunsController < ApplicationController end # 同步配置 + logger.info("########-shixun_service_configs_count: #{@shixun.shixun_service_configs.pluck(:id, :shixun_id)}") @shixun.shixun_service_configs.each do |config| ShixunServiceConfig.create!(:shixun_id => @new_shixun.id, :cpu_limit => config.cpu_limit, diff --git a/db/migrate/20190703090511_add_index_for_shixun_services.rb b/db/migrate/20190703090511_add_index_for_shixun_services.rb new file mode 100644 index 000000000..3e6dd3703 --- /dev/null +++ b/db/migrate/20190703090511_add_index_for_shixun_services.rb @@ -0,0 +1,5 @@ +class AddIndexForShixunServices < ActiveRecord::Migration[5.2] + def change + add_index :shixun_service_configs, [:shixun_id, :mirror_repository_id], unique: true, name: "shixun_id_mirror_id_unique" + end +end From c61cb1190f683a237058ce3babdcfbc26adf3460 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 17:32:04 +0800 Subject: [PATCH 4/9] 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 5/9] =?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 6/9] 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 7/9] 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 8/9] 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 From ab9b9b2fa0fe8a1b10a911c914bff24aa0744b58 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 3 Jul 2019 17:52:16 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190703090511_add_index_for_shixun_services.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/db/migrate/20190703090511_add_index_for_shixun_services.rb b/db/migrate/20190703090511_add_index_for_shixun_services.rb index 3e6dd3703..693add3e3 100644 --- a/db/migrate/20190703090511_add_index_for_shixun_services.rb +++ b/db/migrate/20190703090511_add_index_for_shixun_services.rb @@ -1,5 +1,9 @@ class AddIndexForShixunServices < ActiveRecord::Migration[5.2] def change + sql = %Q(delete from shixun_service_configs where (shixun_id, mirror_repository_id) in + (select * from (select shixun_id, mirror_repository_id from shixun_service_configs group by shixun_id, mirror_repository_id having count(*) > 1) a) + and id not in (select * from (select min(id) from shixun_service_configs group by shixun_id, mirror_repository_id having count(*) > 1 order by id) b)) + ActiveRecord::Base.connection.execute sql add_index :shixun_service_configs, [:shixun_id, :mirror_repository_id], unique: true, name: "shixun_id_mirror_id_unique" end end