From c1ad4c0585bf34fa89c5974ab3c14b1156a85994 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 3 Jul 2019 14:57:20 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E6=88=AA=E6=AD=A2?= =?UTF-8?q?=E6=97=B6=E8=AE=A1=E7=AE=97=E6=95=88=E7=8E=87=E5=88=86=E7=9A=84?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 2 +- app/jobs/homework_end_update_score_job.rb | 32 +++++++++++++++++++ lib/tasks/homework_publishtime.rake | 6 ++-- .../homework_end_update_score_job_spec.rb | 5 +++ 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 app/jobs/homework_end_update_score_job.rb create mode 100644 spec/jobs/homework_end_update_score_job_spec.rb diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 2d52b6aa0..9bbc374a1 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -1117,7 +1117,7 @@ class HomeworkCommonsController < ApplicationController =end # 更新所有学生的效率分(重新取homework确保是更新后的) - HomeworksService.new.update_student_eff_score HomeworkCommon.find_by(id: homework.id) if !homework.allow_late && homework.end_time <= time + HomeworkEndUpdateScoreJob.perform_later(homework.id) if !homework.allow_late && homework.end_time <= time end end homework.save! diff --git a/app/jobs/homework_end_update_score_job.rb b/app/jobs/homework_end_update_score_job.rb new file mode 100644 index 000000000..ea6d3e5e3 --- /dev/null +++ b/app/jobs/homework_end_update_score_job.rb @@ -0,0 +1,32 @@ +class HomeworkEndUpdateScoreJob < ApplicationJob + # 不允许补交的作业截止后,或者补交截止后需要重新计算一次作业成绩 + queue_as :score + + def perform(*args) + homework = HomeworkCommon.find_by(id: homework_id) + return if homework.blank? + course = homework.course + return if course.blank? + + if homework.unified_setting + student_works = homework.student_works + user_ids = course.students.pluck(:user_id) + else + user_ids = course.students.where(course_group_id: homework.published_settings.pluck(:course_group_id)).pluck(:user_id) + student_works = homework.student_works.where(user_id: user_ids) + end + + myshixuns = Myshixun.where(shixun_id: params[:shixun_id], user_id: user_ids). + includes(:games).where(games: {challenge_id: homework.homework_challenge_settings.pluck(:challenge_id)}) + challenge_settings = homework.homework_challenge_settings + myshixuns.find_each(batch_size: 100) do |myshixun| + work = student_works.select{|work| work.user_id == myshixun.user_id}.first + if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at) + games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id)) + HomeworksService.new.update_myshixun_work_score work, myshixun, games, homework, challenge_settings + end + end + HomeworksService.new.update_student_eff_score homework + homework.update_attribute('calculation_time', Time.now) + end +end diff --git a/lib/tasks/homework_publishtime.rake b/lib/tasks/homework_publishtime.rake index 4127a9339..918e70a70 100644 --- a/lib/tasks/homework_publishtime.rake +++ b/lib/tasks/homework_publishtime.rake @@ -84,7 +84,8 @@ namespace :homework_publishtime do student_works.joins(:myshixun).where("myshixuns.status != 1").update_all(late_penalty: homework.late_penalty) if student_works.present? else - HomeworksService.new.update_student_eff_score homework + HomeworkEndUpdateScoreJob.perform_later(homework.id) + # HomeworksService.new.update_student_eff_score homework end =begin @@ -206,7 +207,8 @@ namespace :homework_publishtime do homework_commons = HomeworkCommon.joins(:homework_detail_manual).where("homework_type = 4 and allow_late = 1 and late_time <= ? and late_time > ? and homework_detail_manuals.comment_status != 6", Time.now, Time.now - 900) homework_commons.each do |homework| - HomeworksService.new.update_student_eff_score homework + # HomeworksService.new.update_student_eff_score homework + HomeworkEndUpdateScoreJob.perform_later(homework.id) =begin homework_detail_manual = homework.homework_detail_manual diff --git a/spec/jobs/homework_end_update_score_job_spec.rb b/spec/jobs/homework_end_update_score_job_spec.rb new file mode 100644 index 000000000..492b35d43 --- /dev/null +++ b/spec/jobs/homework_end_update_score_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe HomeworkEndUpdateScoreJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end From d38053e0f45f01db3941df89f1f3ca77aadde143 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 15:23:18 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E5=B7=B2=E5=8F=91=E5=B8=83=E7=9A=84?= =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=BC=96=E8=BE=91=E5=90=8E=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E5=88=86=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_questions_controller.rb | 11 ++++++----- app/controllers/graduation_tasks_controller.rb | 4 ++-- app/controllers/homework_commons_controller.rb | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index b231d6af7..77cc108b3 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -350,8 +350,9 @@ class ExerciseQuestionsController < ApplicationController @exercise_question.shixun_name = shixun_name end - #当标准答案修改时,如有已提交的学生,需重新计算分数 - if st_count > 0 + #当试卷已发布时(试卷的总状态),当标准答案修改时,如有已提交的学生,需重新计算分数. + + 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| @@ -587,15 +588,15 @@ class ExerciseQuestionsController < ApplicationController if @exercise_question.present? @exercise = @exercise_question.exercise if @exercise.blank? - tip_exception(404) + tip_exception(404,"试卷不存在") else @course = @exercise.course if @course.blank? - tip_exception(404) + tip_exception(404,"课堂不存在") end end else - tip_exception(404) + tip_exception(404,"试卷问题不存在") end end diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index a89a81798..545b10e11 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -129,7 +129,7 @@ class GraduationTasksController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") elsif complete_works == 0 - normal_status(-1,"暂无用户提交!") + normal_status(-1,"暂无用户提交") else respond_to do |format| format.xlsx{ @@ -164,7 +164,7 @@ class GraduationTasksController < ApplicationController @work_count = @work_list.count @all_work_count = @work_list.count if params[:format] == "xlsx" || params[:format] == "zip" - normal_status(-1,"作业未发布") + normal_status(-1,"毕设任务未发布") end end end diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index fe2adba45..e595c703e 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -106,7 +106,7 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.all_works @all_member_count = student_works.size - if @homework.publish_time.nil? || @homework.publish_time > Time.now + if @homework.publish_time.blank? || (@homework.publish_time > Time.now) @student_works = [] if params[:format] == "xlsx" || params[:format] == "zip" normal_status(-1,"作业未发布") From b286e432ffb4655196558811a46458d59be274ad Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 3 Jul 2019 15:43:17 +0800 Subject: [PATCH 3/7] =?UTF-8?q?sidekiq=E6=9C=AC=E5=9C=B0=E7=9B=91=E6=8E=A7?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 1 + Gemfile.lock | 7 +++++++ config/routes.rb | 3 +++ 3 files changed, 11 insertions(+) diff --git a/Gemfile b/Gemfile index b8b174a6f..0473e221e 100644 --- a/Gemfile +++ b/Gemfile @@ -84,6 +84,7 @@ gem 'rails-i18n', '~> 5.1' # job gem 'sidekiq' +gem 'sinatra' # batch insert gem 'bulk_insert' diff --git a/Gemfile.lock b/Gemfile.lock index 86f524bc2..728bbc672 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -142,6 +142,7 @@ GEM multi_json (1.13.1) multi_xml (0.6.0) multipart-post (2.0.0) + mustermann (1.0.3) mysql2 (0.5.2) nio4r (2.3.1) nokogiri (1.8.4) @@ -265,6 +266,11 @@ GEM simple_xlsx_reader (1.0.4) nokogiri rubyzip + sinatra (2.0.5) + mustermann (~> 1.0) + rack (~> 2.0) + rack-protection (= 2.0.5) + tilt (~> 2.0) spreadsheet (1.2.3) ruby-ole (>= 1.0) spring (2.0.2) @@ -341,6 +347,7 @@ DEPENDENCIES selenium-webdriver sidekiq simple_xlsx_reader + sinatra spreadsheet spring spring-watcher-listen (~> 2.0.0) diff --git a/config/routes.rb b/config/routes.rb index a27dde1f3..01e301c3c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,8 @@ Rails.application.routes.draw do + require 'sidekiq/web' + mount Sidekiq::Web => '/sidekiq' + resources :edu_settings scope '/api' do get 'home/index' From 841bd09f236c9be5807774c7f4d328bd6cf6aaa3 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 3 Jul 2019 15:55:50 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E7=9A=84=E8=AE=BF=E9=97=AE=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 2 +- app/controllers/subjects_controller.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 9c3847b3c..e558e657c 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -18,7 +18,7 @@ class MyshixunsController < ApplicationController # REDO等删除是否可以做成异步 # 前段需要按照操作过程提示 def reset_my_game - unless (current_user.admin? || current_user.id == @myshixun.user_id) + unless current_user.admin? tip_exception("403", "") end diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index c73fec500..bb7059af6 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -81,6 +81,9 @@ class SubjectsController < ApplicationController @tags = ChallengeTag.where(challenge_id: challenge_ids).pluck(:name).uniq # 用户获取的实训标签 @user_tags = @subject.shixuns.map(&:user_tags_name).flatten.uniq + + # 访问数变更 + @subject.increment!(:visits) end def create From 748f4dc5779690ee82d46f055111e065fc597c0b Mon Sep 17 00:00:00 2001 From: p31729568 Date: Wed, 3 Jul 2019 16:04:52 +0800 Subject: [PATCH 5/7] fix users subject repeat bug --- app/services/users/subject_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/users/subject_service.rb b/app/services/users/subject_service.rb index 7e3eaaa81..745b7cce2 100644 --- a/app/services/users/subject_service.rb +++ b/app/services/users/subject_service.rb @@ -14,7 +14,7 @@ class Users::SubjectService subjects = category_scope_subjects subjects = user_policy_filter(subjects) - custom_sort(subjects, :updated_at, params[:sort_direction]) + custom_sort(subjects.distinct, :updated_at, params[:sort_direction]) end private From b21966c3572d62849d5bd7e179ecb54fb087a81a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 16:05:45 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=A4=9A=E7=A9=BA?= =?UTF-8?q?=E9=A2=98=E7=9A=84=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exercise_questions_controller.rb | 5 ---- ...611_add_old_exercise_tiankong_choice_id.rb | 23 +++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20190703072611_add_old_exercise_tiankong_choice_id.rb diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 77cc108b3..deb9b3157 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -223,7 +223,6 @@ class ExerciseQuestionsController < ApplicationController end end #试卷未发布时,当标准答案存在时,可修改标准答案内容,可增删标准答案,否则只能修改标准答案,不能增删标准答案 - st_count = 0 @exercise_answers_array = @exercise_question.exercise_standard_answers #问卷的全部标准答案 if standard_answer.present? if @exercise_question.question_type <= 2 #选择题/判断题,标准答案为一个或多个 @@ -232,7 +231,6 @@ class ExerciseQuestionsController < ApplicationController old_left_standard_choices = exercise_standard_choices - common_standard_choices # 以前的差集共同的,剩余的表示需要删掉 new_left_standard_choices = standard_answer - common_standard_choices # 传入的标准答案差集共同的,剩余的表示需要新建 if old_left_standard_choices.count > 0 - st_count += 1 @exercise_answers_array.standard_by_ids(old_left_standard_choices).destroy_all end if new_left_standard_choices.count > 0 #新建标准答案 @@ -258,7 +256,6 @@ class ExerciseQuestionsController < ApplicationController #删除多余的选项 if old_ex_answer_choice_ids.count > new_ex_answer_choice_ids.count #有减少的填空 - st_count += 1 delete_ex_answer_choice_ids = old_ex_answer_choice_ids - new_ex_answer_choice_ids old_ex_answer.standard_by_ids(delete_ex_answer_choice_ids).destroy_all end @@ -284,7 +281,6 @@ class ExerciseQuestionsController < ApplicationController ex_answer_pre[n-1].update(standard_option) end if new_add_choice.count > 0 #表示有新增的 - st_count += 1 new_add_choice.each do |i| standard_option = { :exercise_question_id => @exercise_question.id, @@ -306,7 +302,6 @@ class ExerciseQuestionsController < ApplicationController ex_answer_pre[index].update(standard_option) end if new_delete_choice.count > 0 #表示填空题的答案有删减的 - st_count += 1 new_delete_choice.each do |d| ex_answer_pre[d-1].destroy end diff --git a/db/migrate/20190703072611_add_old_exercise_tiankong_choice_id.rb b/db/migrate/20190703072611_add_old_exercise_tiankong_choice_id.rb new file mode 100644 index 000000000..9ad1429e2 --- /dev/null +++ b/db/migrate/20190703072611_add_old_exercise_tiankong_choice_id.rb @@ -0,0 +1,23 @@ +class AddOldExerciseTiankongChoiceId < ActiveRecord::Migration[5.2] + + def up + #类型为3 的问题答案及标准答案更新exercise_choice_id 为1,即表示第一空 + exercise_question_ids = ExerciseQuestion.where("question_type = 3").pluck(:id) + ExerciseAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: nil).update_all(exercise_choice_id:1) + ExerciseStandardAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: nil).update_all(exercise_choice_id:1) + + exercise_bank_question_ids = ExerciseBankQuestion.where("question_type =3").pluck(:id) + ExerciseBankStandardAnswer.where(exercise_bank_question_id: exercise_bank_question_ids).update_all(exercise_bank_choice_id:1) + end + + def down + #类型为3 的问题答案及标准答案更新exercise_choice_id 为1,即表示第一空 + exercise_question_ids = ExerciseQuestion.where("question_type = 3").pluck(:id) + ExerciseAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: 1).update_all(exercise_choice_id:nil) + ExerciseStandardAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: 1).update_all(exercise_choice_id:nil) + + exercise_bank_question_ids = ExerciseBankQuestion.where("question_type =3").pluck(:id) + ExerciseBankStandardAnswer.where(exercise_bank_question_id: exercise_bank_question_ids).update_all(exercise_bank_choice_id:nil) + end + +end From 0d254b0da4c2701e3efc0a8b5184e4e8e0b6434a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 3 Jul 2019 16:16:24 +0800 Subject: [PATCH 7/7] score fix --- 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 4cd9209f3..57ae1023b 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -250,7 +250,7 @@ class HomeworkCommonsController < ApplicationController challenge_settings = @homework.homework_challenge_settings myshixuns.find_each(batch_size: 100) do |myshixun| work = student_works.select{|work| work.user_id == myshixun.user_id}.first - if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at) + if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.games.pluck(:updated_at).max) games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id)) HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings end @@ -271,7 +271,7 @@ class HomeworkCommonsController < ApplicationController myshixun = Myshixun.find_by(shixun_id: params[:shixun_id], user_id: current_user.id) ActiveRecord::Base.transaction do begin - if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at) + if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.games.pluck(:updated_at).max) challenge_settings = @homework.homework_challenge_settings games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id)) HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings