forked from Gitlink/forgeplus
竞赛通知任务调度
This commit is contained in:
parent
4e2c46260c
commit
5ed7b3e4ad
|
@ -10,9 +10,9 @@ class NoticesController < ApplicationController
|
|||
elsif params["source"] == "CompetitionResult"
|
||||
competition_id = params[:competition_id]
|
||||
SendTemplateMessageJob.perform_later('CompetitionResult', user_id, competition_id)
|
||||
elsif params["source"] == "CompetitionView"
|
||||
elsif params["source"] == "CompetitionReview"
|
||||
competition_id = params[:competition_id]
|
||||
SendTemplateMessageJob.perform_later('CompetitionView', user_id, competition_id)
|
||||
SendTemplateMessageJob.perform_later('CompetitionReview', user_id, competition_id)
|
||||
else
|
||||
tip_exception("#{params["source"]}未配置")
|
||||
end
|
||||
|
|
|
@ -332,7 +332,23 @@ class SendTemplateMessageJob < ApplicationJob
|
|||
project = Project.find_by_sql("select *,title as name from competitions where id=#{competition_id}")
|
||||
return unless user.present? && project.present?
|
||||
receivers = User.where(id: user_id)
|
||||
receivers_string, content, notification_url = MessageTemplate::TeamLeft.get_message_content(receivers, nil, nil)
|
||||
receivers_string, content, notification_url = MessageTemplate::CompetitionBegin.get_message_content(receivers, project.first)
|
||||
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {user_id: user_id, competition_name: project.first&.name, identifier: project.first&.identifier})
|
||||
when 'CompetitionReview'
|
||||
user_id, competition_id = args[0], args[1]
|
||||
user = User.find_by_id(user_id)
|
||||
project = Project.find_by_sql("select *,title as name from competitions where id=#{competition_id}")
|
||||
return unless user.present? && project.present?
|
||||
receivers = User.where(id: user_id)
|
||||
receivers_string, content, notification_url = MessageTemplate::CompetitionReview.get_message_content(receivers, project.first)
|
||||
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {user_id: user_id, competition_name: project.first&.name, identifier: project.first&.identifier})
|
||||
when 'CompetitionResult'
|
||||
user_id, competition_id = args[0], args[1]
|
||||
user = User.find_by_id(user_id)
|
||||
project = Project.find_by_sql("select *,title as name from competitions where id=#{competition_id}")
|
||||
return unless user.present? && project.present?
|
||||
receivers = User.where(id: user_id)
|
||||
receivers_string, content, notification_url = MessageTemplate::CompetitionResult.get_message_content(receivers, project.first)
|
||||
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {user_id: user_id, competition_name: project.first&.name, identifier: project.first&.identifier})
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
# 点击通知跳转页面
|
||||
# 点击此通知将跳转到代码审查大赛详情页:
|
||||
# http://117.50.100.12:8080/competitions/lgw7st/home
|
||||
class MessageTemplate::CompetitionView < MessageTemplate
|
||||
class MessageTemplate::CompetitionReview < MessageTemplate
|
||||
|
||||
# MessageTemplate::FollowedTip.get_message_content(User.where(login: 'yystopf'), User.last)
|
||||
def self.get_message_content(receivers, competition)
|
|
@ -0,0 +1,38 @@
|
|||
# 竞赛通知
|
||||
|
||||
namespace :competition_notice do
|
||||
|
||||
desc "竞赛通知-进入提交作品状态"
|
||||
task submit_work_begin: :environment do
|
||||
competitions = Project.find_by_sql("select * from competitions where status=1 and DATE_FORMAT(enroll_end_time,'%Y-%m-%d %h:00:00') ='#{(Time.now - 1.day).strftime('%Y-%m-%d %H:00:00')}' ")
|
||||
competitions.each do |c|
|
||||
competition_teams = Project.find_by_sql("select * from competition_teams where competition_id=#{c.id} ")
|
||||
competition_teams.each do |team|
|
||||
SendTemplateMessageJob.perform_later('CompetitionBegin', team.user_id, c.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc "竞赛通知-截止提交作品时间前3小时"
|
||||
task submit_work_end: :environment do
|
||||
competitions = Project.find_by_sql("select * from competitions where status=1 and DATE_FORMAT(end_time,'%Y-%m-%d %h:00:00') ='#{(Time.now + 3.hours).strftime('%Y-%m-%d %H:00:00')}' ")
|
||||
competitions.each do |c|
|
||||
competition_teams = Project.find_by_sql("select * from competition_teams where competition_id=#{c.id} ")
|
||||
competition_teams.each do |team|
|
||||
SendTemplateMessageJob.perform_later('CompetitionReview', team.user_id, c.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
desc "竞赛通知-报名的竞赛进入成绩公示阶段"
|
||||
task submit_work_result: :environment do
|
||||
competitions = Project.find_by_sql("select * from competitions where status=1 and DATE_FORMAT(review_time,'%Y-%m-%d %h:00:00') ='#{(Time.now - 1.day).strftime('%Y-%m-%d %H:00:00')}' ")
|
||||
competitions.each do |c|
|
||||
competition_teams = Project.find_by_sql("select * from competition_teams where competition_id=#{c.id} ")
|
||||
competition_teams.each do |team|
|
||||
SendTemplateMessageJob.perform_later('CompetitionResult', team.user_id, c.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue