时间调整

dev_hjm
cxt 6 years ago
parent c9e8ea9e7f
commit 0bef9700a1

@ -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
course_id = ENV['args'].split(",")[0] # 对应课堂的id
satus = ENV['args'].split(",")[1]
# course_id = ENV['args'].split(",")[0] # 对应课堂的id
# type = ENV['args'].split(",")[1]
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)
sec = rand(60)
@ -83,17 +125,15 @@ namespace :public_course do
time = "#{date} #{min_swith(hour)}:#{min_swith(min)}:#{min_swith(sec)}"
puts time
case type
when 1
# 讨论区
time
end
def random_larger_time(time, start_time, end_time)
large_time = random_time(start_time, end_time)
while large_time <= time
large_time = random_time(start_time, end_time)
end
def min_swith(time)
puts time
return time < 9 ? "0#{time}" : time
large_time
end
end

@ -20,7 +20,6 @@ namespace :public_course do
puts user_id
unless CourseMember.exists?(course_id: course_id, user_id: user_id)
CourseMember.create!(course_id: course_id, user_id: user_id, role: 4)
CourseAddStudentCreateWorksJob.perform_later(course_id, [user_id])
end
end
end

Loading…
Cancel
Save