From c7036f25525a0fd8e16ee139157a34c3ffa3c1e1 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 2 Aug 2019 21:26:49 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 5 +++- app/controllers/polls_controller.rb | 1 + app/jobs/commit_exercsie_notify_job_job.rb | 26 +++++++++++++++++++ app/jobs/commit_poll_notify_job_job.rb | 26 +++++++++++++++++++ app/models/student_graduation_topic.rb | 5 ++++ config/locales/tidings/zh-CN.yml | 10 +++---- .../commit_exercsie_notify_job_job_spec.rb | 5 ++++ spec/jobs/commit_poll_notify_job_job_spec.rb | 5 ++++ 8 files changed, 77 insertions(+), 6 deletions(-) create mode 100644 app/jobs/commit_exercsie_notify_job_job.rb create mode 100644 app/jobs/commit_poll_notify_job_job.rb create mode 100644 spec/jobs/commit_exercsie_notify_job_job_spec.rb create mode 100644 spec/jobs/commit_poll_notify_job_job_spec.rb diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 6f121db5f..e92c3b266 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -703,12 +703,14 @@ class ExercisesController < ApplicationController end if ex_status == 1 #如果试卷存在已发布的,或者是已截止的,那么则直接跳过 g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数,那么试卷的统一设置需修改 + tiding_group_ids = g_course if g_course user_course_groups = @course.charge_group_ids(current_user) if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则试卷不用分组,且试卷设定为统一设置,否则则分组设置 exercise.exercise_group_settings.destroy_all ex_unified = true e_time = ex_end_time + tiding_group_ids = [] else ex_unified = false g_course.each do |i| @@ -748,7 +750,7 @@ class ExercisesController < ApplicationController if exercise.course_acts.size == 0 exercise.course_acts << CourseActivity.new(:user_id => exercise.user_id,:course_id => exercise.course_id) end - ExercisePublishNotifyJob.perform_later(exercise.id, g_course) + ExercisePublishNotifyJob.perform_later(exercise.id, tiding_group_ids) end end end @@ -1084,6 +1086,7 @@ class ExercisesController < ApplicationController :subjective_score => subjective_score } @answer_committed_user.update_attributes(commit_option) + CommitExercsieNotifyJobJob.perform_later(@exercise.id, current_user.id) normal_status(0,"试卷提交成功!") end rescue Exception => e diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 7d978d722..ba3030424 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -919,6 +919,7 @@ class PollsController < ApplicationController :end_at => Time.now } poll_user_current.update_attributes(poll_user_params) + CommitPollNotifyJobJob.perform_later(@poll.id, current_user.id) normal_status(0, "问卷提交成功!") end ## 需添加发送消息的接口,稍后添加 diff --git a/app/jobs/commit_exercsie_notify_job_job.rb b/app/jobs/commit_exercsie_notify_job_job.rb new file mode 100644 index 000000000..1be0bb2bc --- /dev/null +++ b/app/jobs/commit_exercsie_notify_job_job.rb @@ -0,0 +1,26 @@ +class CommitExercsieNotifyJobJob < ApplicationJob + queue_as :notify + + def perform(exercise_id, user_id) + exercise = Exercise.find_by(id: exercise_id) + user = User.find_by(id: user_id) + return if [exercise, user].any?(&:blank?) + course = exercise.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 status created_at updated_at] + + same_attrs = { + trigger_user_id: user.id, + container_id: exercise.id, container_type: 'Exercise', + parent_container_id: exercise.id, parent_container_type: 'CommitExercise', + belong_container_id: course.id, belong_container_type: 'Course', + tiding_type: 'Exercise', viewed: 0, status: 0 + } + Tiding.bulk_insert(*attrs) do |worker| + course.course_member(user).member_teachers.each do |teacher| + worker.add same_attrs.merge(user_id: teacher.user_id) + end + end + end +end diff --git a/app/jobs/commit_poll_notify_job_job.rb b/app/jobs/commit_poll_notify_job_job.rb new file mode 100644 index 000000000..6953fa9e9 --- /dev/null +++ b/app/jobs/commit_poll_notify_job_job.rb @@ -0,0 +1,26 @@ +class CommitPollNotifyJobJob < ApplicationJob + queue_as :notify + + def perform(poll_id, user_id) + poll = Poll.find_by(id: poll_id) + user = User.find_by(id: user_id) + return if [poll, user].any?(&:blank?) + course = poll.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 status created_at updated_at] + + same_attrs = { + trigger_user_id: user.id, + container_id: poll.id, container_type: 'Poll', + parent_container_id: poll.id, parent_container_type: 'CommitPoll', + belong_container_id: course.id, belong_container_type: 'Course', + tiding_type: 'Poll', viewed: 0, status: 0 + } + Tiding.bulk_insert(*attrs) do |worker| + course.course_member(user).member_teachers.each do |teacher| + worker.add same_attrs.merge(user_id: teacher.user_id) + end + end + end +end diff --git a/app/models/student_graduation_topic.rb b/app/models/student_graduation_topic.rb index ea1774695..50f150f92 100644 --- a/app/models/student_graduation_topic.rb +++ b/app/models/student_graduation_topic.rb @@ -17,7 +17,12 @@ class StudentGraduationTopic < ApplicationRecord scope :is_refused, -> {where(status: 2)} scope :is_accepted, -> {where(status: 1)} scope :is_accepting, -> {where(status: 0)} + after_create :send_tiding + def send_tiding + self.tidings << Tiding.new(:user_id => self.graduation_topic.tea_id, :trigger_user_id => self.user_id, :parent_container_id => self.graduation_topic_id, :parent_container_type => "GraduationTopic", + :belong_container_id => self.graduation_topic.course_id, :belong_container_type => "Course", :viewed => 0, :status => 0, :tiding_type => "GraduationTopic") + end # 学生名称 def name diff --git a/config/locales/tidings/zh-CN.yml b/config/locales/tidings/zh-CN.yml index 456f15887..d6b44b26c 100644 --- a/config/locales/tidings/zh-CN.yml +++ b/config/locales/tidings/zh-CN.yml @@ -164,7 +164,7 @@ NearlyEnd_end: "试卷的截止时间快到啦:%s" CommitExercise_end: "提交了试卷答题:%s" ExerciseScore_end: "评阅了你的试卷:%s" - StudentGraduationTopic_end: "选择了毕设选题:%s" + StudentGraduationTopic_end: "申请选择毕设选题:%s" DealStudentTopicSelect: 1_end: "你提交的选题申请:%s,审核已通过" 2_end: "你提交的选题申请:%s,审核未通过" @@ -195,11 +195,11 @@ ChallengeWorkScore_end: "调整了你的作品分数:%s" StudentWorksScoresAppeal: UserAppealResult: - 1_end: "同意了你提交的匿评申诉申请:%s" - 2_end: "拒绝了你提交的匿评申诉:%s" + 1_end: "你提交的匿评申诉申请:%s,审核已通过" + 2_end: "你提交的匿评申诉:%s,审核未通过" AppealResult: - 1_end: "同意了他人对你的匿评申诉申请:%s" - 2_end: "拒绝了他人对你的匿评申诉:%s" + 1_end: "别人对你的匿评发起的申诉申请:%s,审核已通过" + 2_end: "别人对你的匿评发起的申诉申请:%s,审核未通过" StudentWork: Apply_end: "发起了匿评申诉申请:%s" HomeworkCommon_end: "有人对你的匿评发起了申诉:%s" diff --git a/spec/jobs/commit_exercsie_notify_job_job_spec.rb b/spec/jobs/commit_exercsie_notify_job_job_spec.rb new file mode 100644 index 000000000..17894c9ad --- /dev/null +++ b/spec/jobs/commit_exercsie_notify_job_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CommitExercsieNotifyJobJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/jobs/commit_poll_notify_job_job_spec.rb b/spec/jobs/commit_poll_notify_job_job_spec.rb new file mode 100644 index 000000000..da292f7fb --- /dev/null +++ b/spec/jobs/commit_poll_notify_job_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CommitPollNotifyJobJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end From de9a841c6fd5162c8c66ef6da8e5c5081e420fbf Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 2 Aug 2019 21:31:07 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journals_for_message.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index d5697d87f..4300ae9cc 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -11,6 +11,7 @@ class JournalsForMessage < ApplicationRecord scope :parent_comment, -> { where(m_parent_id: nil)} scope :search_by_jour_type, lambda{|type,ids| where(jour_type:type,jour_id: ids)} + has_many :tidings, as: :container, dependent: :destroy # "jour_type", # 留言所属类型 # "jour_id", # 留言所属类型的id