diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index bb28fff54..9eeba6adc 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -656,7 +656,17 @@ class ExerciseQuestionsController < ApplicationController :exercise_answer_id => ex_answer_comment_id } @exercise_comments = ExerciseAnswerComment.new(comment_option) - @exercise_comments.save + @exercise_comments.save! + + # 给被评阅人发送消息,同一个教师评阅无需重复发消息 + + unless Tiding.where(user_id: @user_id, trigger_user_id: current_user.id, parent_container_id: @exercise.id, parent_container_type: "ExerciseScore").exists? + Tiding.create!(user_id: @user_id, trigger_user_id: current_user.id, container_id: @exercise.id, + container_type: "Exercise", parent_container_id: @exercise.id, + parent_container_type: "ExerciseScore", belong_container_id: @course.id, + belong_container_type: 'Course', tiding_type: "Exercise") + end + end rescue Exception => e uid_logger_error(e.message) diff --git a/app/controllers/graduation_works_controller.rb b/app/controllers/graduation_works_controller.rb index 204e0e5d4..3d516b4b1 100644 --- a/app/controllers/graduation_works_controller.rb +++ b/app/controllers/graduation_works_controller.rb @@ -371,6 +371,11 @@ class GraduationWorksController < ApplicationController new_score.save! @work.update_attributes(ultimate_score: 1, work_score: params[:score].to_f) + Tiding.create!(user_id: @work.user_id, trigger_user_id: current_user.id, container_id: new_score.id, + container_type: "AdjustScore", parent_container_id: @task.id, + parent_container_type: "GraduationTask", belong_container_id: @course.id, + belong_container_type: 'Course', tiding_type: "GraduationTask") + normal_status("调分成功") rescue Exception => e uid_logger(e.message) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 2612510c5..a4e08b90a 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -224,7 +224,7 @@ class StudentWorksController < ApplicationController raise ActiveRecord::Rollback end - SubmitStudentWorkNotifyJob.perform_later(@homework.id, student_ids) if student_ids.present? + ResubmitStudentWorkNotifyJob.perform_later(@homework.id, student_ids) if student_ids.present? end end @@ -333,6 +333,11 @@ class StudentWorksController < ApplicationController @work.update_attributes(update_time: Time.now) + # 补交附件时给评阅过作品的教师、助教发消息 + unless @work.student_works_scores.where.not(score: nil).where(reviewer_role: [1, 2]).pluck(user_id).uniq.blank? + ResubmitStudentWorkNotifyJob.perform_later(@homework.id, [current_user.id]) + end + normal_status(0, "提交成功") rescue Exception => e uid_logger(e.message) @@ -551,6 +556,11 @@ class StudentWorksController < ApplicationController @work.work_score = params[:score].to_f @work.save! + Tiding.create!(user_id: @work.user_id, trigger_user_id: current_user.id, container_id: new_score.id, + container_type: "AdjustScore", parent_container_id: @homework.id, + parent_container_type: "HomeworkCommon", belong_container_id: @course.id, + belong_container_type: 'Course', tiding_type: "HomeworkCommon") + normal_status(0,"调分成功") rescue Exception => e uid_logger(e.message) diff --git a/app/decorators/tiding_decorator.rb b/app/decorators/tiding_decorator.rb index b1284d3d4..9dc439377 100644 --- a/app/decorators/tiding_decorator.rb +++ b/app/decorators/tiding_decorator.rb @@ -340,13 +340,21 @@ module TidingDecorator end def student_work_content - I18n.t(locale_format(extra.nil?)) % container&.homework_common.try(:name) + I18n.t(locale_format) % container&.homework_common.try(:name) + end + + def resubmit_student_work_content + I18n.t(locale_format) % container&.homework_common.try(:name) end def student_works_score_content I18n.t(locale_format(extra)) % container&.student_work&.homework_common.try(:name) end + def adjust_score_content + I18n.t(locale_format) % parent_container.try(:name) + end + def challenge_work_score_content I18n.t(locale_format) % container&.comment end diff --git a/app/jobs/resubmit_student_work_notify_job.rb b/app/jobs/resubmit_student_work_notify_job.rb new file mode 100644 index 000000000..1a67aa3ad --- /dev/null +++ b/app/jobs/resubmit_student_work_notify_job.rb @@ -0,0 +1,33 @@ +class ResubmitStudentWorkNotifyJob < ApplicationJob + queue_as :notify + + def perform(homework_id, student_ids) + homework = HomeworkCommon.find_by(id: homework_id) + return if homework.blank? || student_ids.blank? + course = homework.course + + attrs = %i[user_id trigger_user_id container_id container_type parent_container_id parent_container_type + belong_container_id belong_container_type tiding_type viewed created_at updated_at] + + same_attrs = { + container_type: 'ResubmitStudentWork', parent_container_id: homework.id, parent_container_type: 'HomeworkCommon', + belong_container_id: course.id, belong_container_type: 'Course', tiding_type: 'HomeworkCommon', viewed: 0 + } + Tiding.bulk_insert(*attrs) do |worker| + student_ids.each do |user_id| + next unless User.exists?(id: user_id) + + work = homework.student_works.find_by(user_id: user_id) + next if work.blank? + score_user_ids = work.student_works_scores.where.not(score: nil).where(reviewer_role: [1, 2]).pluck(user_id).uniq + next if score_user_ids.blank? + + attrs = same_attrs.merge(trigger_user_id: user_id, container_id: work.id) + + score_user_ids.each do |user_id| + worker.add attrs.merge(user_id: user_id) + end + end + end + end +end diff --git a/config/locales/tidings/zh-CN.yml b/config/locales/tidings/zh-CN.yml index 8e5224ddf..f484efdc1 100644 --- a/config/locales/tidings/zh-CN.yml +++ b/config/locales/tidings/zh-CN.yml @@ -185,13 +185,13 @@ NearlyEnd_end: "作业的提交截止时间快到啦:%{name}" AppealNearlyEnd_end: "作品的匿评申诉时间快到啦:%{name}" EvaluationNearlyEnd_end: "作业的匿评截止时间快到啦:%{name}" - StudentWork: - true_end: "提交了作品:%s" - false_end: "重新提交了作品,建议您重新评阅:%s" + StudentWork_end: "提交了作品:%s" + ResubmitStudentWork_end: "重新提交了作品,建议您重新评阅作品:%s" StudentWorksScore: 1_end: "评阅了你的作品:%s" 2_end: "评阅了你的作品:%s" 3_end: "有人匿评了你的作品:%s" + AdjustScore_end: "调整了你的作品得分:%s" ChallengeWorkScore_end: "调整了你的作品分数:%s" StudentWorksScoresAppeal: UserAppealResult: diff --git a/spec/jobs/resubmit_student_work_notify_job_spec.rb b/spec/jobs/resubmit_student_work_notify_job_spec.rb new file mode 100644 index 000000000..53b354b22 --- /dev/null +++ b/spec/jobs/resubmit_student_work_notify_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ResubmitStudentWorkNotifyJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end