|
|
@ -65,14 +65,56 @@ namespace :public_course do
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 更新某个课程的某类时间
|
|
|
|
# 更新某个课程的某类时间
|
|
|
|
# 执行示例 bundle exec rake public_course:student tiems=149,2903
|
|
|
|
# 执行示例 bundle exec rake public_course:student args=2903,1
|
|
|
|
task :time => :environment do
|
|
|
|
task :time => :environment do
|
|
|
|
course_id = ENV['args'].split(",")[0] # 对应课堂的id
|
|
|
|
# course_id = ENV['args'].split(",")[0] # 对应课堂的id
|
|
|
|
satus = ENV['args'].split(",")[1]
|
|
|
|
# type = ENV['args'].split(",")[1]
|
|
|
|
|
|
|
|
|
|
|
|
course = Course.find(course_id)
|
|
|
|
course = Course.find(course_id)
|
|
|
|
|
|
|
|
|
|
|
|
hour = (6..24).to_a.sample(1).first
|
|
|
|
case type.to_i
|
|
|
|
|
|
|
|
when 1
|
|
|
|
|
|
|
|
# 讨论区
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
when 2
|
|
|
|
|
|
|
|
# 作业
|
|
|
|
|
|
|
|
course.homework_commons.each do |homework|
|
|
|
|
|
|
|
|
created_at = random_time(start_time, end_time)
|
|
|
|
|
|
|
|
publish_time = random_larger_time created_at, start_time, end_time
|
|
|
|
|
|
|
|
end_time = random_larger_time publish_time, start_time, end_time
|
|
|
|
|
|
|
|
updated_at = end_time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
homework.update_columns(publish_time: publish_time, end_time: end_time, created_at: created_at, updated_at: updated_at)
|
|
|
|
|
|
|
|
homework.homework_detail_manual.update_columns(comment_status: 6, created_at: created_at, updated_at: updated_at)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
when 3
|
|
|
|
|
|
|
|
# 试卷
|
|
|
|
|
|
|
|
course.exercises.each do |exercise|
|
|
|
|
|
|
|
|
created_at = random_time start_time, end_time
|
|
|
|
|
|
|
|
publish_time = random_larger_time created_at, start_time, end_time
|
|
|
|
|
|
|
|
end_time = random_larger_time publish_time, start_time, end_time
|
|
|
|
|
|
|
|
updated_at = end_time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exercise.update_columns(publish_time: publish_time, end_time: end_time, created_at: created_at, updated_at: updated_at, exercise_status: 3)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
when 4
|
|
|
|
|
|
|
|
# 资源
|
|
|
|
|
|
|
|
course.attachments.each do |atta|
|
|
|
|
|
|
|
|
created_on = random_time start_time, end_time
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
atta.update_columns(is_publish: 1, created_on: created_on)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def min_swith(time)
|
|
|
|
|
|
|
|
puts time
|
|
|
|
|
|
|
|
return time < 9 ? "0#{time}" : time
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def random_time(start_time, end_time)
|
|
|
|
|
|
|
|
hour = (6..23).to_a.sample(1).first
|
|
|
|
min = rand(60)
|
|
|
|
min = rand(60)
|
|
|
|
sec = rand(60)
|
|
|
|
sec = rand(60)
|
|
|
|
|
|
|
|
|
|
|
@ -83,17 +125,15 @@ namespace :public_course do
|
|
|
|
time = "#{date} #{min_swith(hour)}:#{min_swith(min)}:#{min_swith(sec)}"
|
|
|
|
time = "#{date} #{min_swith(hour)}:#{min_swith(min)}:#{min_swith(sec)}"
|
|
|
|
|
|
|
|
|
|
|
|
puts time
|
|
|
|
puts time
|
|
|
|
case type
|
|
|
|
time
|
|
|
|
when 1
|
|
|
|
|
|
|
|
# 讨论区
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def min_swith(time)
|
|
|
|
def random_larger_time(time, start_time, end_time)
|
|
|
|
puts time
|
|
|
|
large_time = random_time(start_time, end_time)
|
|
|
|
return time < 9 ? "0#{time}" : time
|
|
|
|
while large_time <= time
|
|
|
|
|
|
|
|
large_time = random_time(start_time, end_time)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
large_time
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|