diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index c3333c912..0d32926e4 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -83,7 +83,6 @@ class AccountsController < ApplicationController email = params[:login] verifi_code = VerificationCode.where(email: email, code: code, code_type: 3).last user = User.find_by_mail(email) #这里有问题,应该是为email,而不是mail 6.13-hs - end check_code = (verifi_code.try(:code) == code.strip && (Time.now.to_i - verifi_code.created_at.to_i) <= 10*60) unless check_code diff --git a/app/controllers/discusses_controller.rb b/app/controllers/discusses_controller.rb index 6e9c1427e..1d3b524f4 100644 --- a/app/controllers/discusses_controller.rb +++ b/app/controllers/discusses_controller.rb @@ -7,9 +7,18 @@ class DiscussesController < ApplicationController page = params[:page].to_i offset = page * LIMIT # 总数,分页使用 - @disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count - @discusses = Discuss.limit(LIMIT).where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil). - includes(:user, :praise_tread).offset(offset) + if current_user.admin? + @disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count + @discusses = Discuss.limit(LIMIT).where(:dis_id => @container.id, :dis_type => @container.class.to_s, + :root_id => nil).includes(:user, :praise_tread).offset(offset) + else + disscusses = Discuss.where("dis_id = :dis_id and dis_type = :dis_type and root_id is null and + (hidden = :hidden or user_id = :user_id)", + {dis_id: @container.id, dis_type: @container.class.to_s, hidden: false, user_id: current_user.id}) + @disscuss_count = disscusses.count + @discusses = disscusses.limit(LIMIT).includes(:user, :praise_tread).offset(offset) + end + @current_user = current_user end @@ -23,8 +32,10 @@ class DiscussesController < ApplicationController def create begin - @discuss = Discuss.create!(:dis_id => params[:container_id], :dis_type => params[:container_type], :content => params[:content].gsub(" \;", "").strip, - :user_id => current_user.id, :praise_count => 0, :position => params[:position], :challenge_id => params[:challenge_id]) + @discuss = Discuss.create!(:dis_id => params[:container_id], :dis_type => params[:container_type], + :content => params[:content].gsub(" \;", "").strip, :user_id => current_user.id, + :praise_count => 0, :position => params[:position], :challenge_id => params[:challenge_id], + :hidden => !current_user.admin?) # 管理员回复的能够显示 rescue Exception => e uid_logger_error("create discuss failed : #{e.message}") raise Educoder::TipException.new("评论异常") diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 44b694239..e1e8e226b 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1334,7 +1334,7 @@ class ExercisesController < ApplicationController #导出空白试卷 def export_exercise - @exercise_questions = @exercise.exercise_questions.order("question_number ASC") + @exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") filename = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.current.strftime('%Y%m%d%H%M%S')}.pdf" stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css" render pdf: 'exercise_export/blank_exercise', filename: filename, stylesheets: stylesheets diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index 521aaffc6..c611069a8 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -193,8 +193,8 @@ class GraduationTopicsController < ApplicationController def student_select_topic user_unaccept_topics = @course.student_graduation_topics.where(user_id: current_user.id, status: [0, 1]) if user_unaccept_topics.size == 0 - member_id = @course.course_members.find_by_user_id(current_user.id) - StudentGraduationTopic.create(course_id: @course.id, user_id: current_user.id, course_member_id: member_id, + member = @course.course_members.find_by_user_id(current_user.id) + StudentGraduationTopic.create(course_id: @course.id, user_id: current_user.id, course_member_id: member.try(:id), graduation_topic_id: @graduation_topic.id) @graduation_topic.update_attribute(:status, 1) normal_status("选题成功") diff --git a/app/controllers/graduation_works_controller.rb b/app/controllers/graduation_works_controller.rb index 9117112d3..09b9146e8 100644 --- a/app/controllers/graduation_works_controller.rb +++ b/app/controllers/graduation_works_controller.rb @@ -432,11 +432,11 @@ class GraduationWorksController < ApplicationController # 交叉评阅分配老师 def assign_teacher tip_exception(-1, "user_id不能为空") if params[:user_id].nil? - @work_assign_teacher = @work.graduation_work_comment_assignations.first + @work_assign_teacher = @work.graduation_work_comment_assignations.find_by(user_id: params[:user_id]) - if @work_assign_teacher + if @work_assign_teacher.present? # graduation_group_id: 已经是答辩组的需要 将答辩组清空 - @work_assign_teacher.update_attributes(user_id: params[:user_id], graduation_group_id: 0) + @work_assign_teacher.update_attributes(graduation_group_id: 0) else @work.graduation_work_comment_assignations << GraduationWorkCommentAssignation.new(graduation_task_id: @task.id, user_id: params[:user_id], diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 4abada488..83bfd29fc 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -121,23 +121,26 @@ class HomeworkCommonsController < ApplicationController @work = @homework.user_work(current_user.id) # 学生已提交作品且补交(提交)已截止、作品公开、非匿评阶段 - if @work.work_status > 0 && @homework.work_public && + if @work&.work_status.to_i > 0 && @homework.work_public && ((!@homework.anonymous_comment && @homework.end_or_late) || @homework_detail_manual.comment_status > 4) - @student_works = student_works.where("user_id != #{@work.id}") + @student_works = student_works.where("user_id != #{@work.user_id}") # 匿评、申诉阶段只能看到分配给自己的匿评作品 - elsif @work.work_status > 0 && @homework.anonymous_comment && @homework_detail_manual.comment_status > 2 + elsif @work&.work_status.to_i > 0 && @homework.anonymous_comment && @homework_detail_manual.comment_status > 2 @is_evaluation = true @student_works = student_works.joins(:student_works_evaluation_distributions).where( "student_works_evaluation_distributions.user_id = #{@current_user.id}") else @student_works = [] end + @score_open = @homework.score_open && @work&.work_status.to_i > 0 elsif @user_course_identity < Course::STUDENT @student_works = @homework.teacher_works(@member) @all_member_count = @student_works.size + @score_open = true elsif @user_course_identity > Course::STUDENT && @homework.work_public @student_works = student_works + @score_open = false else @student_works = [] end diff --git a/app/jobs/graduation_task_cross_comment_job.rb b/app/jobs/graduation_task_cross_comment_job.rb new file mode 100644 index 000000000..64973a3e9 --- /dev/null +++ b/app/jobs/graduation_task_cross_comment_job.rb @@ -0,0 +1,39 @@ +# 毕设任务的交叉评阅分配 +class GraduationTaskCrossCommentJob < ApplicationJob + queue_as :evaluation_comment + + def perform(graduation_task_id) + task = GraduationTask.find_by(id: graduation_task_id) + return if task.blank? + + course = task.course + task.graduation_task_group_assignations.each do |assignation| + graduation_group = assignation.graduation_group + assign_group = assignation.assign_group + if graduation_group.present? && assign_group.present? + course_group_ids = course.teacher_course_groups.where(course_member_id: graduation_group.course_members.pluck(:id)).pluck(:course_group_id) + graduation_works = task.graduation_works.where(user_id: course.course_members.where(:course_group_id => course_group_ids).map(&:user_id), + work_status: [1, 2]) + if assign_group.course_members.count <= task.comment_num + graduation_works.each do |work| + assign_group.course_members.each do |member| + work.graduation_work_comment_assignations << GraduationWorkCommentAssignation.new( + graduation_group_id: assign_group.id, user_id: member.user_id, graduation_task_id: task.id) + end + end + else + member_user_ids = assign_group.course_members.pluck(:user_id) + count = 0 + graduation_works.each do |work| + for i in 1 .. task.comment_num + assign_user_id = member_user_ids[count % member_user_ids.size] + work.graduation_work_comment_assignations << GraduationWorkCommentAssignation.new( + graduation_group_id: assign_group.id, user_id: assign_user_id, graduation_task_id: task.id) + count += 1 + end + end + end + end + end + end +end diff --git a/app/jobs/graduation_task_publish_notify_job.rb b/app/jobs/graduation_task_publish_notify_job.rb index 3489aa711..92346ab27 100644 --- a/app/jobs/graduation_task_publish_notify_job.rb +++ b/app/jobs/graduation_task_publish_notify_job.rb @@ -18,8 +18,8 @@ class GraduationTaskPublishNotifyJob < ApplicationJob viewed: 0, tiding_type: 'GraduationTask' } Tiding.bulk_insert(*attrs) do |worker| - task.course.students.find_each do |student| - worker.add same_attrs.merge(user_id: student.user_id) + task.course.course_members.pluck(:user_id).uniq.find_each do |user_id| + worker.add same_attrs.merge(user_id: user_id) end end end diff --git a/app/jobs/homework_absence_penalty_calculation_job.rb b/app/jobs/homework_absence_penalty_calculation_job.rb new file mode 100644 index 000000000..87f78f311 --- /dev/null +++ b/app/jobs/homework_absence_penalty_calculation_job.rb @@ -0,0 +1,33 @@ +class HomeworkAbsencePenaltyCalculationJob < ApplicationJob + queue_as :score + + def perform(homework_common_id) + homework_common = HomeworkCommon.find_by(id: homework_common_id) + return if homework_common.blank? + + #计算缺评扣分 参与匿评 + work_ids = homework_common.student_works.has_committed.pluck(:id) + homework_detail_manual = homework_common.homework_detail_manual + + homework_common.student_works.where("work_status != 0").each do |student_work| + absence_penalty_count = student_work.user.student_works_evaluation_distributions.where(student_work_id: work_ids).count - + student_work.user.student_works_scores.where(student_work_id: work_ids, reviewer_role: 3).group_by(:student_work_id).count + + student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * homework_detail_manual.absence_penalty : 0 + student_work.save + end + + # 未参与匿评 + if homework_detail_manual.no_anon_penalty == 0 + all_dis_eva = StudentWorksEvaluationDistribution.where(student_work_id: work_ids) + has_sw_count = all_dis_eva.select("distinct user_id").count + anon_count = all_dis_eva.count / has_sw_count + homework_common.student_works.where("work_status != 0").each do |student_work| + if student_work.user.student_works_evaluation_distributions.where(student_work_id: work_ids).count == 0 + student_work.absence_penalty = homework_detail_manual.absence_penalty * anon_count + student_work.save + end + end + end + end +end diff --git a/app/jobs/homework_anonymous_appeal_start_notify_job.rb b/app/jobs/homework_anonymous_appeal_start_notify_job.rb new file mode 100644 index 000000000..1c3098690 --- /dev/null +++ b/app/jobs/homework_anonymous_appeal_start_notify_job.rb @@ -0,0 +1,28 @@ +# 匿评申诉开启时给分配了匿评的学生发消息 +class HomeworkAnonymousAppealStartNotifyJob < ApplicationJob + queue_as :notify + + def perform(homework_common_id) + homework = HomeworkCommon.find_by(id: homework_common_id) + return if homework.blank? + eva_distribution = StudentWorksEvaluationDistribution.where(student_work_id: homework.student_works.pluck(:id)) + + attrs = %i[ + user_id trigger_user_id container_id container_type parent_container_id parent_container_type + belong_container_id belong_container_type viewed tiding_type created_at updated_at + ] + + same_attrs = { + trigger_user_id: homework.user_id, container_id: homework.id, container_type: 'HomeworkCommon', + parent_container_id: homework.id, parent_container_type: 'AnonymousAppeal', + belong_container_id: homework.course_id, belong_container_type: 'Course', + viewed: 0, tiding_type: 'HomeworkCommon' + } + Tiding.bulk_insert(*attrs) do |worker| + + eva_distribution.pluck(:user_id).uniq.each do |user_id| + worker.add same_attrs.merge(user_id: user_id) + end + end + end +end diff --git a/app/jobs/homework_common_push_notify_job.rb b/app/jobs/homework_common_push_notify_job.rb index 961face58..47956a14c 100644 --- a/app/jobs/homework_common_push_notify_job.rb +++ b/app/jobs/homework_common_push_notify_job.rb @@ -24,7 +24,7 @@ class HomeworkCommonPushNotifyJob < ApplicationJob same_attrs = { trigger_user_id: homework.user_id, container_id: homework.id, container_type: 'HomeworkCommon', parent_container_id: homework.id, parent_container_type: 'HomeworkPublish', - belong_container_id: task.course_id, belong_container_type: 'Course', + belong_container_id: homework.course_id, belong_container_type: 'Course', viewed: 0, tiding_type: 'HomeworkCommon' } Tiding.bulk_insert(*attrs) do |worker| diff --git a/app/jobs/homework_evaluation_comment_assgin_job.rb b/app/jobs/homework_evaluation_comment_assgin_job.rb new file mode 100644 index 000000000..2579ea18b --- /dev/null +++ b/app/jobs/homework_evaluation_comment_assgin_job.rb @@ -0,0 +1,48 @@ +class HomeworkEvaluationCommentAssginJob < ApplicationJob + queue_as :evaluation_comment + + def get_assigned_homeworks(student_works, n, index) + student_works += student_works + student_works[index + 1..index + n] + end + + def perform(homework_common_id) + homework_common = HomeworkCommon.find_by(id: homework_common_id) + return if homework_common.blank? + homework_detail_manual = homework_common.homework_detail_manual + + if homework_common.homework_type == "group" + student_works = homework_common.student_works.where("work_status != 0").group(:group_id) + student_work_projects = homework_common.student_works.where("work_status != 0").shuffle + student_work_projects.each do |pro_work| + n = homework_detail_manual.evaluation_num + n = (n < student_works.size && n != -1) ? n : student_works.size - 1 + work_index = -1 + student_works.each_with_index do |stu_work, stu_index| + if stu_work.group_id.to_i == pro_work.group_id.to_i + work_index = stu_index + end + end + assigned_homeworks = get_assigned_homeworks(student_works, n, work_index) + assigned_homeworks.each do |h| + student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: pro_work.user_id, student_work_id: h.id) + student_works_evaluation_distributions.save + end + end + + else + student_works = homework_common.student_works.has_committed + student_works = student_works.shuffle + student_works.each_with_index do |work, index| + user = work.user + n = homework_detail_manual.evaluation_num + n = (n < student_works.size && n != -1) ? n : student_works.size - 1 + assigned_homeworks = get_assigned_homeworks(student_works, n, index) + assigned_homeworks.each do |h| + student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: user.id, student_work_id: h.id) + student_works_evaluation_distributions.save + end + end + end + end +end diff --git a/app/jobs/homework_evaluation_start_notify_job.rb b/app/jobs/homework_evaluation_start_notify_job.rb new file mode 100644 index 000000000..709c37b32 --- /dev/null +++ b/app/jobs/homework_evaluation_start_notify_job.rb @@ -0,0 +1,30 @@ +class HomeworkEvaluationStartNotifyJob < ApplicationJob + queue_as :notify + + def perform(homework_common_id, content) + homework = HomeworkCommon.find_by(id: homework_common_id) + return if homework.blank? + course = homework.course + members = content.blank? ? course.course_members : course.teachers + tiding_type = content.blank? ? "HomeworkCommon" : "System" + + attrs = %i[ + user_id trigger_user_id container_id container_type parent_container_id parent_container_type + belong_container_id belong_container_type viewed tiding_type extra created_at updated_at + ] + + same_attrs = { + trigger_user_id: homework.user_id, container_id: homework.id, container_type: 'HomeworkCommon', + parent_container_id: homework.id, parent_container_type: 'AnonymousComment', + belong_container_id: homework.course_id, belong_container_type: 'Course', + viewed: 0, tiding_type: tiding_type, extra: content + } + Tiding.bulk_insert(*attrs) do |worker| + member_ids = members.pluck(:user_id).uniq + + member_ids.each do |user_id| + worker.add same_attrs.merge(user_id: user_id) + end + end + end +end diff --git a/app/jobs/homework_publish_update_work_status_job.rb b/app/jobs/homework_publish_update_work_status_job.rb index 0060ab270..fe03a3ac5 100644 --- a/app/jobs/homework_publish_update_work_status_job.rb +++ b/app/jobs/homework_publish_update_work_status_job.rb @@ -1,6 +1,6 @@ class HomeworkPublishUpdateWorkStatusJob < ApplicationJob # 作业发布时更新学生(发布前已开启过实训)的作业状态和成绩 - queue_as :default + queue_as :score def perform(group_ids, homework_id) # Do something later diff --git a/app/models/discuss.rb b/app/models/discuss.rb index 602813e66..8d8dc0163 100644 --- a/app/models/discuss.rb +++ b/app/models/discuss.rb @@ -36,7 +36,13 @@ class Discuss < ApplicationRecord def contents(shixun, user) return content unless hidden? - shixun.has_manager?(user) ? content : '违规评论已被屏蔽!' + shixun.has_manager?(user) ? content : '' + end + + def child_discuss(user) + user.admin? ? + Discuss.where(parent_id: self.id).includes(:user).reorder(created_at: :asc) : + Discuss.where(parent_id: self.id, :hidden => false).includes(:user).reorder(created_at: :asc) end private diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index d55973ed8..c0882ec6f 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -169,12 +169,8 @@ class HomeworkCommon < ApplicationRecord #删除时更新题库中的引用数 def update_homework_bank_quotes - old_banks = self.homework_bank - unless old_banks.blank? - old_banks.each do |bank| - bank.update_attributes(quotes: (bank.quotes - 1) > 0 ? (bank.quotes - 1) : 0, homework_common_id: nil) - end - end + old_bank = self.homework_bank + old_bank.update_attributes(quotes: (old_bank.quotes - 1) > 0 ? (old_bank.quotes - 1) : 0, homework_common_id: nil) end # 查重是否有新结果 diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index d74e66d31..28857dff9 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -81,9 +81,8 @@ class ExerciseUserPdfService @exercise_ques_shixun_count = exercise_ques_shixun.all.count @exercise_ques_shixun_scores = exercise_ques_shixun.pluck(:question_score).sum - challenge_ids = @exercise_questions.joins(:exercise_shixun_challenges).pluck("exercise_shixun_challenges.challenge_id") - + @exercise_questions = @exercise_questions.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers) get_each_student_exercise(exercise.id,@exercise_questions,@ex_user_user.id) - @games = @exercise_user.user.games.ch_games(challenge_ids) + end end \ No newline at end of file diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 59be4f1bd..9190e9251 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -156,7 +156,7 @@ p{ position: absolute; display: inline-block; bottom: 6px; - /*left: 1px;*/ + left: 1px; } .line-line { @@ -231,7 +231,7 @@ p{ position: absolute; display: inline-block; bottom: 9px; - left: 1px; + left: 2px; } .circle-right:after{ color:#fff; diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 193a25301..c81f45d68 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -112,6 +112,7 @@
实训详情
- <% @games.each_with_index do |game, index| %> + <% games&.each_with_index do |game, index| %>第<%= index+1 %>关<%= game.challenge.subject %> diff --git a/app/views/discusses/_discuss.json.jbuilder b/app/views/discusses/_discuss.json.jbuilder index 1fcf150bc..da1ca5a6c 100644 --- a/app/views/discusses/_discuss.json.jbuilder +++ b/app/views/discusses/_discuss.json.jbuilder @@ -2,7 +2,7 @@ json.author do json.partial! 'users/user', user: discuss.user end json.id discuss.id -json.content discuss.contents(container, current_user) +json.content discuss.contents json.time time_from_now(discuss.created_at) json.position discuss.position json.shixun_id discuss.dis_id diff --git a/app/views/discusses/index.json.jbuilder b/app/views/discusses/index.json.jbuilder index 3d0ee9fc9..1b7a95eb3 100644 --- a/app/views/discusses/index.json.jbuilder +++ b/app/views/discusses/index.json.jbuilder @@ -2,8 +2,7 @@ json.disscuss_count @disscuss_count json.all @current_user.admin? json.comments @discusses do |discuss| json.partial! 'discusses/discuss', locals: { discuss: discuss, container: @container, current_user: @current_user } - child_discuss = Discuss.children(discuss.id) - json.children child_discuss do |c_d| + json.children discuss.child_discuss(current_user) do |c_d| json.partial! 'discusses/discuss', locals: { discuss: c_d, container: @container, current_user: @current_user } end end diff --git a/app/views/homework_commons/works_list.json.jbuilder b/app/views/homework_commons/works_list.json.jbuilder index 716b12190..60441909b 100644 --- a/app/views/homework_commons/works_list.json.jbuilder +++ b/app/views/homework_commons/works_list.json.jbuilder @@ -33,19 +33,19 @@ elsif @user_course_identity == Course::STUDENT json.late_penalty @work.late_penalty if @homework.allow_late json.cost_time @work.myshixun.try(:total_cost_time) - json.work_score work_score_format(@work.work_score, true, @homework.score_open) - json.final_score work_score_format(@work.final_score, true, @homework.score_open) - json.efficiency work_score_format(@work.efficiency, true, @homework.score_open) - json.eff_score work_score_format(@work.eff_score, true, @homework.score_open) + json.work_score work_score_format(@work.work_score, true, @score_open) + json.final_score work_score_format(@work.final_score, true, @score_open) + json.efficiency work_score_format(@work.efficiency, true, @score_open) + json.eff_score work_score_format(@work.eff_score, true, @score_open) json.complete_count @work.myshixun.try(:passed_count) else json.(@work, :id, :work_status, :update_time, :ultimate_score) - json.work_score work_score_format(@work.work_score, true, @homework.score_open) - json.final_score work_score_format(@work.final_score, true, @homework.score_open) - json.teacher_score work_score_format(@work.teacher_score, true, @homework.score_open) - json.student_score work_score_format(@work.student_score, true, @homework.score_open) - json.teaching_asistant_score work_score_format(@work.teaching_asistant_score, true, @homework.score_open) + json.work_score work_score_format(@work.work_score, true, @score_open) + json.final_score work_score_format(@work.final_score, true, @score_open) + json.teacher_score work_score_format(@work.teacher_score, true, @score_open) + json.student_score work_score_format(@work.student_score, true, @score_open) + json.teaching_asistant_score work_score_format(@work.teaching_asistant_score, true, @score_open) json.ta_comment_count @work.ta_comment_count @@ -84,10 +84,10 @@ if @homework.homework_type == "practice" json.(work, :id, :work_status, :update_time, :ultimate_score) json.late_penalty work.late_penalty if @homework.allow_late - json.work_score work_score_format(work.work_score, @current_user == work.user, @homework.score_open) - json.final_score work_score_format(work.final_score, @current_user == work.user, @homework.score_open) - json.efficiency work_score_format(work.efficiency, @current_user == work.user, @homework.score_open) - json.eff_score work_score_format(work.eff_score, @current_user == work.user, @homework.score_open) + json.work_score work_score_format(work.work_score, @current_user == work.user, @score_open) + json.final_score work_score_format(work.final_score, @current_user == work.user, @score_open) + json.efficiency work_score_format(work.efficiency, @current_user == work.user, @score_open) + json.eff_score work_score_format(work.eff_score, @current_user == work.user, @score_open) json.cost_time work.myshixun.try(:total_cost_time) json.complete_count work.myshixun.try(:passed_count) @@ -117,11 +117,11 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal" :teaching_asistant_score, :ultimate_score) json.late_penalty work.late_penalty if @homework.allow_late - json.work_score work_score_format(work.work_score, @current_user == work.user, @homework.score_open) - json.final_score work_score_format(work.final_score, @current_user == work.user, @homework.score_open) - json.teacher_score work_score_format(work.teacher_score, @current_user == work.user, @homework.score_open) - json.student_score work_score_format(work.student_score, @current_user == work.user, @homework.score_open) - json.teaching_asistant_score work_score_format(work.teaching_asistant_score, @current_user == work.user, @homework.score_open) + json.work_score work_score_format(work.work_score, @current_user == work.user, @score_open) + json.final_score work_score_format(work.final_score, @current_user == work.user, @score_open) + json.teacher_score work_score_format(work.teacher_score, @current_user == work.user, @score_open) + json.student_score work_score_format(work.student_score, @current_user == work.user, @score_open) + json.teaching_asistant_score work_score_format(work.teaching_asistant_score, @current_user == work.user, @score_open) # 助教评分次数 json.ta_comment_count work.ta_comment_count diff --git a/config/sidekiq.yml b/config/sidekiq.yml index a2b3fc0be..5bd9dad23 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -3,4 +3,6 @@ :logfile: log/sidekiq.log :queues: - [default, 3] + - [score, 4] + - [evaluation_comment, 5] - [notify, 100] \ No newline at end of file diff --git a/lib/tasks/graduation_task.rake b/lib/tasks/graduation_task.rake index aad84491f..0d4dff237 100644 --- a/lib/tasks/graduation_task.rake +++ b/lib/tasks/graduation_task.rake @@ -5,27 +5,9 @@ namespace :graduation_task do tasks = GraduationTask.where("publish_time is not null and publish_time <= '#{Time.now}' and status = 0") tasks.each do |task| task.update_attributes(status: 1) - course = task.course - members = course.course_members - if !course.nil? && !members.empty? - tid_str = "" - members.find_each do |member| - tid_str += "," if tid_str != "" - tid_str += "(#{member.user_id}, #{task.user_id}, #{task.id}, 'GraduationTask', #{task.id}, 'TaskPublish', - #{course.id}, 'Course', 0, 'GraduationTask', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', - '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - if tid_str != "" - tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, - parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, - updated_at) values" + tid_str - ActiveRecord::Base.connection.execute tid_sql - end - end + GraduationTaskPublishNotifyJob.perform_later(task.id) - if task.course_acts.size == 0 - task.course_acts << CourseActivity.new(user_id: task.user_id, course_id: task.course_id) - end + task.course_acts << CourseActivity.new(user_id: task.user_id, course_id: task.course_id) if task.course_acts.exists? end end @@ -62,37 +44,11 @@ namespace :graduation_task do tasks = GraduationTask.where("cross_comment = 1 and comment_time is not null and comment_time <= '#{Time.now}' and status = 2") tasks.each do |task| if task.comment_status == 4 - course = task.course - task.graduation_task_group_assignations.each do |assignation| - graduation_group = assignation.graduation_group - assign_group = assignation.assign_group - if graduation_group.present? && assign_group.present? - course_group_ids = course.teacher_course_groups.where(course_member_id: graduation_group.course_members.pluck(:id)).pluck(:course_group_id) - graduation_works = task.graduation_works.where(user_id: course.course_members.where(:course_group_id => course_group_ids).map(&:user_id), - work_status: [1, 2]) - if assign_group.course_members.count <= task.comment_num - graduation_works.each do |work| - assign_group.course_members.each do |member| - work.graduation_work_comment_assignations << GraduationWorkCommentAssignation.new( - graduation_group_id: assign_group.id, user_id: member.user_id, graduation_task_id: task.id) - end - end - else - member_user_ids = assign_group.course_members.pluck(:user_id) - count = 0 - graduation_works.each do |work| - for i in 1 .. task.comment_num - assign_user_id = member_user_ids[count % member_user_ids.size] - work.graduation_work_comment_assignations << GraduationWorkCommentAssignation.new( - graduation_group_id: assign_group.id, user_id: assign_user_id, graduation_task_id: task.id) - count += 1 - end - end - end - end - end + GraduationTaskCrossCommentJob.perform_later(task.id) end task.update_attributes(status: 3) + + # 给老师发消息 tid_str = "" task.course.teachers.find_each do |member| tid_str += "," if tid_str != "" diff --git a/lib/tasks/homework_evaluation.rake b/lib/tasks/homework_evaluation.rake index cb7b51fae..d1fad8f14 100644 --- a/lib/tasks/homework_evaluation.rake +++ b/lib/tasks/homework_evaluation.rake @@ -23,59 +23,11 @@ namespace :homework_evaluation do else student_works = homework_common.student_works.has_committed end - if student_works.present? && student_works.length >= 2 - if homework_common.homework_type == "group" - student_work_projects = homework_common.student_works.where("work_status != 0").shuffle - student_work_projects.each_with_index do |pro_work, pro_index| - n = homework_detail_manual.evaluation_num - n = (n < student_works.size && n != -1) ? n : student_works.size - 1 - work_index = -1 - student_works.each_with_index do |stu_work, stu_index| - if stu_work.group_id.to_i == pro_work.group_id.to_i - work_index = stu_index - end - end - assigned_homeworks = get_assigned_homeworks(student_works, n, work_index) - assigned_homeworks.each do |h| - student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: pro_work.user_id, student_work_id: h.id) - student_works_evaluation_distributions.save - end - #更新CourseHomeworkStatistics中该学生的待匿评数 - # course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(homework_common.course_id, pro_work.user_id) - # course_statistics.update_attribute('un_evaluation_work_num', course_statistics.un_evaluation_work_num + n) if course_statistics - end - else - student_works = student_works.shuffle - student_works.each_with_index do |work, index| - user = work.user - n = homework_detail_manual.evaluation_num - n = (n < student_works.size && n != -1) ? n : student_works.size - 1 - assigned_homeworks = get_assigned_homeworks(student_works, n, index) - assigned_homeworks.each do |h| - student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: user.id, student_work_id: h.id) - student_works_evaluation_distributions.save - end + if student_works.size >= 2 + HomeworkEvaluationCommentAssginJob.perform_later(homework_common.id) - #更新CourseHomeworkStatistics中该学生的待匿评数 - # course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(homework_common.course_id, user.id) - # course_statistics.update_attribute('un_evaluation_work_num', course_statistics.un_evaluation_work_num + n) if course_statistics - end - end homework_detail_manual.update_column('comment_status', 3) - # 匿评开启消息邮件通知,# 所有人 - str = "" - homework_common.course.course_members.pluck(:user_id).uniq.each do |user_id| - str += "," if str != "" - str += "('#{user_id}', '#{homework_common.user_id}', '#{homework_common.id}','HomeworkCommon','#{homework_common.id}', - 'AnonymousComment',#{homework_common.course_id},'Course',0,'HomeworkCommon', - '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - if str != "" - sql = "insert into tidings (user_id,trigger_user_id,container_id, container_type, parent_container_id, - parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + str - ActiveRecord::Base.connection.execute sql - end else #作业数小于2,启动失败, 只给老师和助教发 extra = "作品数量低于两个,无法开启匿评" @@ -83,20 +35,8 @@ namespace :homework_evaluation do else extra = "存在尚未截止的分班,无法开启匿评" end + HomeworkEvaluationStartNotifyJob.perform_later(homework_common.id, extra) if extra.present? - str = '' - homework_common.course.teachers.each do |mem| - str += "," if str != "" - str += "('#{mem.user.id}', '#{homework_common.user_id}', '#{homework_common.id}','HomeworkCommon','#{homework_common.id}', - 'AnonymousCommentFail',#{homework_common.course_id},'Course',0,'System','#{extra}', - '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - if str != "" - sql = "insert into tidings (user_id,trigger_user_id,container_id, container_type,parent_container_id, - parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, extra, created_at, - updated_at) values" + str - ActiveRecord::Base.connection.execute sql - end homework_detail_manual.update_attributes(:evaluation_start => nil, :evaluation_end => nil, :absence_penalty => 0, :evaluation_num => 0, :appeal_time => nil, :appeal_penalty => 0) homework_common.update_attributes(:anonymous_comment => 0, :anonymous_appeal => 0) @@ -114,63 +54,15 @@ namespace :homework_evaluation do homework_detail_manuals.each do |homework_detail_manual| homework_common = homework_detail_manual.homework_common if homework_common.anonymous_comment #开启匿评状态才可关闭匿评 - #计算缺评扣分 参与匿评 - work_ids = "(" + homework_common.student_works.has_committed.map(&:id).join(",") + ")" - - homework_common.student_works.where("work_status != 0").each do |student_work| - absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - - student_work.user.student_works_scores.where("student_work_id IN #{work_ids} and reviewer_role = 3").count - - student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * homework_detail_manual.absence_penalty : 0 - student_work.save - - #更新CourseHomeworkStatistics中该学生的待匿评数和缺评数 - # absence_penalty_count = absence_penalty_count > 0 ? absence_penalty_count : 0 - # course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(homework_common.course_id, student_work.user_id) - # course_statistics.update_attribute('un_evaluation_work_num', (course_statistics.un_evaluation_work_num - absence_penalty_count) < 0 ? 0 : - # (course_statistics.un_evaluation_work_num - absence_penalty_count)) if course_statistics - # course_statistics.update_attribute('absence_evaluation_work_num', course_statistics.absence_evaluation_work_num + absence_penalty_count) if course_statistics - end - - # 未参与匿评 - if homework_common.homework_detail_manual.no_anon_penalty == 0 - all_dis_eva = StudentWorksEvaluationDistribution.where("student_work_id IN #{work_ids}") - has_sw_count = all_dis_eva.select("distinct user_id").count - anon_count = all_dis_eva.count / has_sw_count - homework_common.student_works.where("work_status != 0").each do |student_work| - if student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count == 0 - student_work.absence_penalty = homework_detail_manual.absence_penalty * anon_count - student_work.save - end - end - end - if homework_common.anonymous_appeal homework_detail_manual.update_column('comment_status', 4) - # 申诉开启 - eva_distribution = StudentWorksEvaluationDistribution.where(:student_work_id => homework_common.student_works.pluck(:id)) - str = "" - eva_distribution.pluck(:user_id).uniq.each do |user_id| - str += "," if str != "" - str += "(#{user_id}, #{homework_common.user_id}, #{homework_common.id}, 'HomeworkCommon', #{homework_common.id}, - 'AnonymousAppeal', #{homework_common.course_id}, 'Course', 0, 'HomeworkCommon', - '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - if str != "" - sql = "insert into tidings (user_id,trigger_user_id,container_id, container_type, parent_container_id, - parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + str - ActiveRecord::Base.connection.execute sql - end + # 申诉开启发送消息 + HomeworkAnonymousAppealStartNotifyJob.perform_later(homework_common.id) else homework_detail_manual.update_column('comment_status', 5) end - # 匿评关闭消息通知 给所有人发 - # course = homework_common.course - # course.members.each do |m| - # homework_common.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 3) - # end - # 邮件通知 - # Mailer.send_mail_anonymous_comment_close(homework_common).deliver + + HomeworkAbsencePenaltyCalculationJob.perform_later(homework_common.id) end end end diff --git a/lib/tasks/homework_publishtime.rake b/lib/tasks/homework_publishtime.rake index 0e45b0224..4c27f0317 100644 --- a/lib/tasks/homework_publishtime.rake +++ b/lib/tasks/homework_publishtime.rake @@ -21,37 +21,31 @@ namespace :homework_publishtime do homework_commons.each do |homework| homework_detail_manual = homework.homework_detail_manual homework_detail_manual.update_column('comment_status', 1) - course = homework.course - students = course.students - if !course.nil? && !students.empty? + # 统一设置的作业在这发消息,非统一设置的只给有全部分班权限的老师发 + if homework.unified_setting + HomeworkPublishUpdateWorkStatusJob.perform_later(nil, homework.id) + HomeworkCommonPushNotifyJob.perform_later(homework.id, nil) + else + course = homework.course + teachers = course.teachers.where.not(id: course.teacher_course_groups.select(:course_member_id)) + tid_str = "" - course.teachers.find_each do |member| + teachers.find_each do |member| tid_str += "," if tid_str != "" tid_str += "(#{member.user_id}, #{homework.user_id}, #{homework.id}, 'HomeworkCommon', #{homework.id}, 'HomeworkPublish', #{course.id}, 'Course', 0, 'HomeworkCommon', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" end - if homework.unified_setting - students.each do |student| - tid_str += "," if tid_str != "" - tid_str += "(#{student.user_id}, #{homework.user_id}, #{homework.id}, 'HomeworkCommon', #{homework.id}, - 'HomeworkPublish', #{course.id}, 'Course', 0, 'HomeworkCommon', - '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - HomeworkPublishUpdateWorkStatusJob.perform_now(nil, homework.id) - end if tid_str != "" tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str ActiveRecord::Base.connection.execute tid_sql end - end - - if homework.course_acts.size == 0 - homework.course_acts << CourseActivity.new(:user_id => homework.user_id,:course_id => homework.course_id) end + + homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id) if homework.course_acts.exists? end # 分组设置发布时间的作业 @@ -59,27 +53,8 @@ namespace :homework_publishtime do homework_group_settings.each do |homework_group| homework = homework_group.homework_common if homework.present? - course = homework.course - homework_detail_manual = homework.homework_detail_manual - homework_detail_manual.update_column('comment_status', 1) if homework_detail_manual.comment_status == 0 - - tid_str = "" - members = course.students.where(:course_group_id => homework_group.course_group_id) - members.find_each do |member| - tid_str += "," if tid_str != "" - tid_str += "(#{member.user_id}, #{homework.user_id}, #{homework.id}, 'HomeworkCommon', #{homework.id}, 'HomeworkPublish', - #{course.id}, 'Course', 0, 'HomeworkCommon', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', - '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - if tid_str != "" - tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, - parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, - updated_at) values" + tid_str - ActiveRecord::Base.connection.execute tid_sql - end - HomeworkPublishUpdateWorkStatusJob.perform_now([homework_group.id], homework.id) - + HomeworkCommonPushNotifyJob.perform_later(homework.id, [homework_group.id]) end end Rails.logger.info("log--------------------------------homework_publish end") @@ -98,11 +73,10 @@ namespace :homework_publishtime do student_works = homework.student_works.where("work_status != 0") # none_student_works = homework.student_works.where("work_status = 0") else - setting = homework.homework_group_settings.where(:end_time => homework.end_time) + setting = homework.homework_group_settings.where(end_time: homework.end_time) unless setting.blank? - users = homework.course.students.where(:course_group_id => setting.map(&:course_group_id)) - user_ids = users.blank? ? "(-1)" : "(" + users.map(&:user_id).join(",") + ")" - student_works = homework.student_works.where("work_status != 0 and user_id in #{user_ids}") + users = homework.course.students.where(course_group_id: setting.pluck(:course_group_id)) + student_works = homework.student_works.where("work_status != 0").where(user_id: users.pluck(:user_id)) # none_student_works = homework.student_works.where("work_status = 0 and user_id in #{user_ids}") end end @@ -172,8 +146,7 @@ namespace :homework_publishtime do # homework_challenge_settings = homework.homework_challenge_settings users = homework.course.students.where(:course_group_id => homework_setting.course_group_id) - user_ids = users.blank? ? "(-1)" : "(" + users.map(&:user_id).join(",") + ")" - student_works = homework.student_works.where("work_status != 0 and user_id in #{user_ids}") + student_works = homework.student_works.where("work_status != 0").where(user_id: users.pluck(:user_id)) 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 # 分班设置的不需要另外算效率分 diff --git a/spec/jobs/graduation_task_cross_comment_job_spec.rb b/spec/jobs/graduation_task_cross_comment_job_spec.rb new file mode 100644 index 000000000..d517d939b --- /dev/null +++ b/spec/jobs/graduation_task_cross_comment_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe GraduationTaskCrossCommentJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/jobs/graduation_task_publish_notify_job_spec.rb b/spec/jobs/graduation_task_publish_notify_job_spec.rb new file mode 100644 index 000000000..39f6046af --- /dev/null +++ b/spec/jobs/graduation_task_publish_notify_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe GraduationTaskPublishNotifyJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/jobs/homework_absence_penalty_calculation_job_spec.rb b/spec/jobs/homework_absence_penalty_calculation_job_spec.rb new file mode 100644 index 000000000..b347086ce --- /dev/null +++ b/spec/jobs/homework_absence_penalty_calculation_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe HomeworkAbsencePenaltyCalculationJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/jobs/homework_anonymous_appeal_start_notify_job_spec.rb b/spec/jobs/homework_anonymous_appeal_start_notify_job_spec.rb new file mode 100644 index 000000000..bd5db1e69 --- /dev/null +++ b/spec/jobs/homework_anonymous_appeal_start_notify_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe HomeworkAnonymousAppealStartNotifyJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/jobs/homework_evaluation_comment_assgin_job_spec.rb b/spec/jobs/homework_evaluation_comment_assgin_job_spec.rb new file mode 100644 index 000000000..7a31a825f --- /dev/null +++ b/spec/jobs/homework_evaluation_comment_assgin_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe HomeworkEvaluationCommentAssginJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/jobs/homework_evaluation_start_notify_job_spec.rb b/spec/jobs/homework_evaluation_start_notify_job_spec.rb new file mode 100644 index 000000000..b347ea1f5 --- /dev/null +++ b/spec/jobs/homework_evaluation_start_notify_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe HomeworkEvaluationStartNotifyJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end