课堂message同步问题

dev_aliyun_beta
jingquan huang 5 years ago
parent 0e4c054fd2
commit 08c7dff09a

@ -42,8 +42,8 @@ namespace :public_classes do
end end
task :test_user => :environment do task :test_user => :environment do
users = User.where(is_test: true) users = User.where(is_test: true).limit(limit)
users.limit(limit).find_each do |user| users.find_each do |user|
puts user.id puts user.id
CourseMember.create!(course_id: course_id, user_id: user.id, role: 4) CourseMember.create!(course_id: course_id, user_id: user.id, role: 4)
end end

@ -1,30 +1,22 @@
# bundle exec rake sync:public_message args=149,2903 # bundle exec rake sync:public_message args=149,2903
namespace :sync do namespace :sync do
task :public_message => :environment do if ENV['args']
subject_id = ENV['args'].split(",")[0] # 对应课程的id subject_id = ENV['args'].split(",")[0] # 对应课程的id
shixun_id = ENV['args'].split(",")[1] # 对应课程的id shixun_id = ENV['args'].split(",")[1] # 对应课程的id
board_id = ENV['args'].split(",")[2] board_id = ENV['args'].split(",")[2]
message_id = ENV['args'].split(",")[3] message_id = ENV['args'].split(",")[3]
status = ENV['args'].split(",")[4] # 表示相应的期数 start_time = ENV['args'].split(",")[4] # 表示课程模块
end_time = ENV['args'].split(",")[5] # 表示课程模块
if status.to_i == 1 limit = ENV['args'].split(",")[6] # 限制导入的数量
start_time = '2018-12-16' end
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
task :public_message => :environment do
shixun_ids = Shixun.find_by_sql("select shixun_id from stage_shixuns where stage_id in (select id from stages where 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) subject_id=#{subject_id}) ").map(&:shixun_id)
discusses = Discuss.where(dis_id: shixun_ids).where("created_at >? and created_at <?", start_time, end_time) discusses = Discuss.where(dis_id: shixun_ids).where("created_at >? and created_at <?", start_time, end_time)
if discusses.present? if discusses.present?
discusses.find_each do |discuss| discusses.limit(limit).find_each do |discuss|
puts discuss.user_id puts discuss.user_id
puts board_id puts board_id
puts message_id puts message_id
@ -35,23 +27,6 @@ namespace :sync do
end end
task :sigle_message => :environment do task :sigle_message => :environment do
subject_id = ENV['args'].split(",")[0] # 对应课程的id
shixun_id = ENV['args'].split(",")[1] # 对应课程的id
board_id = ENV['args'].split(",")[2]
message_id = ENV['args'].split(",")[3]
status = ENV['args'].split(",")[4] # 表示相应的期数
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
if subject_id.to_i == -1 if subject_id.to_i == -1
discusses = Discuss.where("parent_id is null and dis_id=?", shixun_id) discusses = Discuss.where("parent_id is null and dis_id=?", shixun_id)
@ -119,18 +94,8 @@ namespace :sync do
end end
end end
task :board_count => :environment do task :delete_boards => :environment do
Course.find_each do |course| course = Course.find(course_id)
puts course.id course.boards.destroy
begin
messages_count = Message.find_by_sql("select count(*) as count from messages where board_id in (select id from boards where course_id=#{course.id})").first.try(:count)
Board.update_column(messages_count: messages_count)
rescue
end
end
end end
end end

Loading…
Cancel
Save