作业消息的发布
This commit is contained in:
parent
97e9fb5444
commit
fd7300bcaf
|
@ -33,7 +33,7 @@ class HomeworkCommon < ActiveRecord::Base
|
|||
:description => :description,
|
||||
:author => :author,
|
||||
:url => Proc.new {|o| {:controller => 'student_work', :action => 'index', :homework => o.id}}
|
||||
after_create :act_as_activity, :act_as_course_message
|
||||
after_create :act_as_activity, :act_as_course_message, :delay_homework_send
|
||||
after_update :update_activity
|
||||
after_save :act_as_course_activity
|
||||
after_destroy :delete_kindeditor_assets
|
||||
|
@ -135,11 +135,57 @@ class HomeworkCommon < ActiveRecord::Base
|
|||
# end
|
||||
# # end
|
||||
# end
|
||||
self.delay.send_homework_wechat_message_delay
|
||||
self.delay.homework_wechat_message
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def homework_wechat_message
|
||||
self.course.members.each do |m|
|
||||
rolesids = []
|
||||
m.roles.each do |role|
|
||||
rolesids << role.id
|
||||
end
|
||||
if rolesids.include?(10)
|
||||
count = ShieldWechatMessage.where("container_type='User' and container_id=#{m.user_id} and shield_type='Course' and shield_id=#{self.course_id}").count
|
||||
if count == 0
|
||||
ws = WechatService.new
|
||||
name = self.course.syllabus.nil? ? self.course.name : self.course.syllabus.title+" • "+self.course.name
|
||||
ws.homework_message_notice(m.user_id, "homework", self.id, "#{m.user.show_name},#{l(:label_new_homework_template)}", name, "新作业:"+ self.name.html_safe, "作业内容请点击“详情”查看。")
|
||||
end
|
||||
end
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
def delay_homework_send
|
||||
if self.course
|
||||
|
||||
vs = []
|
||||
self.course.members.each do | m|
|
||||
if m.user_id != self.user_id
|
||||
vs << {course_message_type:'HomeworkCommon',course_message_id:self.id, :user_id => m.user_id,
|
||||
:course_id => self.course_id, :viewed => false}
|
||||
|
||||
#delayed_job卡住的原因是一次执行的条数太多,导致超时。
|
||||
#现在把每次只执行不超过30条,就不会超了。
|
||||
if vs.size >= 30
|
||||
self.delay.contain_homework_message(vs)
|
||||
vs.clear
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
unless vs.empty?
|
||||
self.delay.contain_homework_message(vs)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def contain_homework_message(vs)
|
||||
CourseMessage.create(vs)
|
||||
end
|
||||
|
||||
#作业微信通知delay
|
||||
def send_homework_wechat_message_delay
|
||||
self.course.members.each do |m|
|
||||
|
|
Loading…
Reference in New Issue