diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb
index d2c9f88d2..1ca907080 100644
--- a/app/controllers/courses_controller.rb
+++ b/app/controllers/courses_controller.rb
@@ -307,8 +307,8 @@ class CoursesController < ApplicationController
def destroy
if @course.is_delete == 0
@course.delete!
- Tiding.create!(user_id: @course.tea_id, trigger_user_id: 0, container_id: @course.id,
- container_type: 'Course', tiding_type: 'Delete', extra: @course.name)
+ Tiding.create!(user_id: current_user.id, trigger_user_id: current_user.id, container_id: @course.id,
+ container_type: 'DeleteCourse', tiding_type: 'System', belong_container: @course, extra: @course.name)
normal_status(0, "成功")
else
normal_status(-1, "课堂已删除,无需重复操作")
@@ -572,6 +572,10 @@ class CoursesController < ApplicationController
tip_exception("删除失败") if course_member.CREATOR? or course_member.STUDENT?
course_student = CourseMember.find_by(user_id: course_member.user_id, course_id: @course.id, role: %i[STUDENT])
+ # Tiding.create!(user_id: course_member.user_id, trigger_user_id: current_user.id, container_id: @course.id,
+ # container_type: 'DeleteCourseMember', tiding_type: 'System', belong_container: @course, extra: @course.name)
+ CourseDeleteStudentNotifyJob.perform_later(@course.id, [course_member.user_id], current_user.id)
+
course_member.destroy!
course_student.update_attributes(is_active: 1) if course_student.present? && !course_student.is_active
normal_status(0, "删除成功")
@@ -802,6 +806,7 @@ class CoursesController < ApplicationController
end
end
CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, student_ids) if student_ids.present?
+ CourseDeleteStudentNotifyJob.perform_later(@course.id, student_ids, current_user.id) if student_ids.present?
normal_status(0, "操作成功")
rescue => e
uid_logger(e.message)
diff --git a/app/decorators/tiding_decorator.rb b/app/decorators/tiding_decorator.rb
index b4f851e5f..b1284d3d4 100644
--- a/app/decorators/tiding_decorator.rb
+++ b/app/decorators/tiding_decorator.rb
@@ -134,6 +134,15 @@ module TidingDecorator
end
end
+ def delete_course_content
+ I18n.t(locale_format) % container.name
+ end
+
+ def delete_course_member_content
+ name = Course.find_by(id: container_id)&.name
+ I18n.t(locale_format) % [trigger_user&.show_real_name, name]
+ end
+
def shixun_content
I18n.t(locale_format) % container.name
end
diff --git a/app/jobs/course_delete_student_notify_job.rb b/app/jobs/course_delete_student_notify_job.rb
new file mode 100644
index 000000000..898fc97c9
--- /dev/null
+++ b/app/jobs/course_delete_student_notify_job.rb
@@ -0,0 +1,22 @@
+# 删除课堂用户
+class CourseDeleteStudentNotifyJob < ApplicationJob
+ queue_as :notify
+
+ def perform(course_id, student_ids, trigger_user_id)
+ course = Course.find_by(id: course_id)
+ return if course.blank?
+
+ attrs = %i[user_id trigger_user_id container_id container_type belong_container_id
+ belong_container_type tiding_type created_at updated_at]
+
+ same_attrs = {
+ trigger_user_id: trigger_user_id, container_id: course.id, container_type: 'DeleteCourseMember',
+ belong_container_id: course.id, belong_container_type: 'Course', tiding_type: 'System'
+ }
+ Tiding.bulk_insert(*attrs) do |worker|
+ student_ids.each do |user_id|
+ worker.add same_attrs.merge(user_id: user_id)
+ end
+ end
+ end
+end
diff --git a/config/locales/tidings/zh-CN.yml b/config/locales/tidings/zh-CN.yml
index 557f3f79b..8e5224ddf 100644
--- a/config/locales/tidings/zh-CN.yml
+++ b/config/locales/tidings/zh-CN.yml
@@ -58,8 +58,8 @@
"2_end": "你提交的试用授权申请,审核未通过
原因:%{reason}"
Apply_end: "提交了试用授权申请"
Course_end: "你创建了课堂:%s"
- Course:
- Delete_end: "你删除了课堂:%s"
+ DeleteCourse_end: "你删除了课堂:%s"
+ DeleteCourseMember_end: "%s 将你从课堂中删除了:%s"
Shixun_end: "你创建了实训:%s"
Subject_end: "你创建了实践课程:%s"
ArchiveCourse_end: "你的课堂已经归档:%s"
diff --git a/spec/jobs/course_delete_student_notify_job_spec.rb b/spec/jobs/course_delete_student_notify_job_spec.rb
new file mode 100644
index 000000000..75cff4162
--- /dev/null
+++ b/spec/jobs/course_delete_student_notify_job_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe CourseDeleteStudentNotifyJob, type: :job do
+ pending "add some examples to (or delete) #{__FILE__}"
+end