You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.7 KiB
73 lines
2.7 KiB
# bundle exec rake sync:public_message args=149,2903
|
|
namespace :sync do
|
|
task :public_message => :environment do
|
|
subject_id = ENV['args'].split(",")[0] # 对应课程的id
|
|
board_id = ENV['args'].split(",")[1]
|
|
message_id = ENV['args'].split(",")[2]
|
|
status = ENV['args'].split(",")[3] # 表示相应的期数
|
|
|
|
if status.to_i == 1
|
|
start_time = '2018-12-16'
|
|
end_time = '2019-04-01'
|
|
elsif status.to_i == 2
|
|
start_time = '2019-04-07'
|
|
end_time = '2019-07-28'
|
|
else
|
|
# 这种情况是取所有的
|
|
start_time = '2015-01-01'
|
|
end_time = '2022-07-28'
|
|
end
|
|
|
|
shixun_ids = Shixun.find_by_sql("select shixun_id from stage_shixuns where stage_id in (select id from stages where
|
|
subject_id=#{subject_id}) ").map(&:shixun_id)
|
|
|
|
|
|
discusses = Discuss.where(dis_id: shixun_ids).where("created_at >? and created_at <?", start_time, end_time)
|
|
if discusses.present?
|
|
discusses.find_each do |discuss|
|
|
puts discuss.user_id
|
|
puts board_id
|
|
puts message_id
|
|
new_message = Message.create!(board_id: board_id.to_i, author_id: discuss.user_id, parent_id: message_id, root_id: message_id)
|
|
MessageDetail.create!(message_id: new_message.id, content: discuss.try(:content))
|
|
end
|
|
end
|
|
end
|
|
|
|
task :sigle_message => :environment do
|
|
shixun_id = ENV['args'].split(",")[0] # 对应课程的id
|
|
board_id = ENV['args'].split(",")[1]
|
|
message_id = ENV['args'].split(",")[2]
|
|
status = ENV['args'].split(",")[3] # 表示相应的期数
|
|
|
|
if status.to_i == 1
|
|
start_time = '2018-12-16'
|
|
end_time = '2019-04-01'
|
|
elsif status.to_i == 2
|
|
start_time = '2019-04-07'
|
|
end_time = '2019-07-28'
|
|
else
|
|
# 这种情况是取所有的
|
|
start_time = '2015-01-01'
|
|
end_time = '2022-07-28'
|
|
end
|
|
|
|
discusses = Discuss.where(dis_id: shixun_id).where("parent_id is null and created_at >? and created_at <?", start_time, end_time)
|
|
discusses.each do |discuss|
|
|
puts discusse.id
|
|
# 找到所有的子回复
|
|
replies = Discuss.where(parent_id: discusse.id)
|
|
|
|
# 如果有子回复,除了创建父回复外,还需要同步子回复
|
|
new_message = Message.create!(board_id: board_id.to_i, author_id: discuss.user_id, parent_id: message_id, root_id: message_id)
|
|
MessageDetail.create!(message_id: new_message.id, content: discuss.try(:content))
|
|
if replies.present?
|
|
replies.each do |reply|
|
|
reply_message = Message.create!(board_id: board_id.to_i, author_id: reply.user_id, parent_id: new_message.id, root_id: message_id)
|
|
MessageDetail.create!(message_id: reply_message.id, content: reply.try(:content))
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|