#2096 course、forge的邮件通知系统,改为可以每日一报、一事一报、不报
This commit is contained in:
parent
f139427f03
commit
c1ed8bd36d
|
@ -114,15 +114,17 @@ class Mailer < ActionMailer::Base
|
|||
@forums = Forum.find_by_sql("select DISTINCT * from forums where creator_id = #{user.id} and (created_at between '#{date_from}' and '#{date_to}') order by created_at desc")
|
||||
@memos = Memo.find_by_sql("select DISTINCT m.* from memos m, forums f where (m.author_id = #{user.id} or (m.forum_id = f.id and f.creator_id = #{user.id}))
|
||||
and (m.created_at between '#{date_from}' and '#{date_to}') order by m.created_at desc")
|
||||
if days == 1
|
||||
subject = "[ #{user.show_name} : #{l(:label_day_mail)}]"
|
||||
@subject = " #{user.show_name} : #{date_to - 1.days} #{l(:label_day_mail)}"
|
||||
else
|
||||
subject = "[ #{user.show_name} : #{l(:label_week_mail)}]"
|
||||
@subject = "#{user.show_name} : #{l(:label_week_mail)}"
|
||||
end
|
||||
mail :to => user.mail,:subject => subject
|
||||
|
||||
subject = "[ #{user.show_name} : #{l(:label_day_mail)}]"
|
||||
@subject = " #{user.show_name} : #{date_to - 1.days} #{l(:label_day_mail)}"
|
||||
|
||||
has_content = [@issues,@homeworks,@course_messages,@project_messages,@course_news,@project_news,
|
||||
@course_journal_messages,@user_journal_messages,@forums,@memos,@attachments,@bids].any? {|o|
|
||||
!o.empty?
|
||||
}
|
||||
binding.pry
|
||||
#有内容才发,没有不发
|
||||
mail :to => user.mail,:subject => subject if has_content
|
||||
end
|
||||
|
||||
# 公共讨论区发帖、回帖添加邮件发送信息
|
||||
|
|
|
@ -64,9 +64,10 @@ class User < Principal
|
|||
},
|
||||
}
|
||||
|
||||
#每日一报、一事一报、不报
|
||||
MAIL_NOTIFICATION_OPTIONS = [
|
||||
['all', :label_user_mail_option_all],
|
||||
['week', :label_user_mail_option_week],
|
||||
#['week', :label_user_mail_option_week],
|
||||
['day', :label_user_mail_option_day],
|
||||
['none', :label_user_mail_option_none]
|
||||
]
|
||||
|
|
|
@ -1,27 +1,12 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'rubygems'
|
||||
require 'rufus-scheduler'
|
||||
|
||||
#users = User.where("mail_notification = 'week' or mail_notification = 'day'")
|
||||
#coding=utf-8
|
||||
|
||||
scheduler = Rufus::Scheduler.new
|
||||
scheduler.cron('0 0 * * 1') do
|
||||
users = User.where("mail_notification = 'week'")
|
||||
users.each do |user|
|
||||
#Rails.logger.info "send mail to #{user.show_name}(#{user.mail}) at #{Time.now}"
|
||||
Thread.start do
|
||||
Mailer.send_for_user_activities(user, Date.today, 7).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
scheduler.cron('0 0 * * *') do
|
||||
users = User.where("mail_notification = 'day'")
|
||||
users.each do |user|
|
||||
#Rails.logger.info "send mail to #{user.show_name}(#{user.mail}) at #{Time.now}"
|
||||
Thread.start do
|
||||
Mailer.send_for_user_activities(user, Date.today, 1).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#每天18:00发送当天的邮件汇总
|
||||
scheduler.cron('0 18 * * *') do
|
||||
users = User.where(mail_notification: 'day')
|
||||
users.each do |user|
|
||||
mailer = Mailer.send_for_user_activities(user, Date.today, 1)
|
||||
mailer.deliver if mailer
|
||||
end
|
||||
end
|
||||
|
|
|
@ -80,7 +80,7 @@ zh:
|
|||
field_enterprise_name: 组织
|
||||
|
||||
label_week_mail: 一周动态
|
||||
label_day_mail: 一日动态
|
||||
label_day_mail: 今日动态
|
||||
#added by huang
|
||||
field_tea_name: 教师
|
||||
field_couurse_time: 学时
|
||||
|
@ -2031,5 +2031,5 @@ zh:
|
|||
label_name_not_null: 名称不能为空
|
||||
modal_valid_unpassing: 该分班已经存在
|
||||
|
||||
|
||||
mail_footer: 点击修改邮件发送设置
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
class ChnageMailNotificationWeekToDay < ActiveRecord::Migration
|
||||
def up
|
||||
User.where(mail_notification: 'week').update_all(mail_notification: 'day')
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
2886
db/schema.rb
2886
db/schema.rb
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue