diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index bcfed25dd..2bdd88566 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -210,6 +210,7 @@ class FilesController < ApplicationController is_unified_setting = params[:is_unified_setting] publish_time = params[:publish_time] + publish_time = format_time(Time.parse(publish_time)) unless publish_time.blank? is_public = params[:is_public] course_group_publish_times = params[:course_group_publish_times] || [] @@ -221,8 +222,10 @@ class FilesController < ApplicationController @new_attachment_history = @old_attachment.become_history @new_attachment_history.save! + old_course_second_category_id = @old_attachment.course_second_category_id @old_attachment.copy_attributes_from_new_attachment(@new_attachment) @old_attachment.is_public = is_public == true ? 1 : 0 if is_public + @old_attachment.course_second_category_id = old_course_second_category_id @old_attachment.save! @new_attachment.delete end diff --git a/lib/tasks/excellent_course_exercise.rake b/lib/tasks/excellent_course_exercise.rake index 3546e48c3..c68cf6348 100644 --- a/lib/tasks/excellent_course_exercise.rake +++ b/lib/tasks/excellent_course_exercise.rake @@ -5,7 +5,6 @@ namespace :excellent_course_exercise do task :student_answer => :environment do course = Course.find_by(id: 2933) - exercises = course.exercises participant_count = 1042 pass_count = 823 @@ -14,6 +13,13 @@ namespace :excellent_course_exercise do members_2 = course.students.order("id asc").limit(1042) members_1 = course.students.order("id asc").limit(322) + exercise_1884 = course.exercises.find_by(id: 1884) + members_1.each_with_index do |member, index| + if index < 821 + else + + end + end end end \ No newline at end of file diff --git a/lib/tasks/public_course.rake b/lib/tasks/public_course.rake index 9c5065982..13ef7b2e7 100644 --- a/lib/tasks/public_course.rake +++ b/lib/tasks/public_course.rake @@ -9,10 +9,13 @@ desc "同步精品课数据" namespace :public_course do - subject_id = ENV['args'].split(",")[0] # 对应课程的id - course_id = ENV['args'].split(",")[1] # 对应课堂的id - status = ENV['args'].split(",")[2] # 表示相应的期数 - type = ENV['args'].split(",")[3] # 表示课程模块 + if ENV['args'] + subject_id = ENV['args'].split(",")[0] # 对应课程的id + course_id = ENV['args'].split(",")[1] # 对应课堂的id + status = ENV['args'].split(",")[2] # 表示相应的期数 + type = ENV['args'].split(",")[3] # 表示课程模块 + end + if status.to_i == 1 start_time = '2018-12-16' @@ -65,14 +68,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, publish_time: 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 +128,15 @@ namespace :public_course do time = "#{date} #{min_swith(hour)}:#{min_swith(min)}:#{min_swith(sec)}" puts time - case type - when 1 - # 讨论区 - - end - + time end - def min_swith(time) - puts time - return time < 9 ? "0#{time}" : time + 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 + large_time end end diff --git a/lib/tasks/public_message.rake b/lib/tasks/public_message.rake new file mode 100644 index 000000000..ca54fbd7b --- /dev/null +++ b/lib/tasks/public_message.rake @@ -0,0 +1,37 @@ +# 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 :environment do - - - subject_id = ENV['args'].split(",").first - course_id = ENV['args'].split(",").last - puts "subject_id is #{subject_id}" - puts "course_id is #{course_id}" - - user_ids = Myshixun.find_by_sql("select distinct(user_id) from myshixuns where shixun_id in (select shixun_id from stage_shixuns - where stage_id in (select id from stages where subject_id=#{subject_id}))").map(&:user_id) - puts user_ids - if user_ids.present? - user_ids.each do |user_id| - 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 - end -end \ No newline at end of file