From e4300243c0377737cb5e887aa21eb699f416f03b Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 16 Aug 2019 06:44:05 +0800 Subject: [PATCH 01/13] =?UTF-8?q?=E5=85=AC=E5=BC=80=E8=AF=BE=E8=AE=A8?= =?UTF-8?q?=E8=AE=BA=E5=8C=BA=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/public_message.rake | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 lib/tasks/public_message.rake diff --git a/lib/tasks/public_message.rake b/lib/tasks/public_message.rake new file mode 100644 index 000000000..a675d98fe --- /dev/null +++ b/lib/tasks/public_message.rake @@ -0,0 +1,41 @@ +# 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 Date: Fri, 16 Aug 2019 06:52:55 +0800 Subject: [PATCH 02/13] message detail --- lib/tasks/public_message.rake | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lib/tasks/public_message.rake b/lib/tasks/public_message.rake index a675d98fe..837a72a0b 100644 --- a/lib/tasks/public_message.rake +++ b/lib/tasks/public_message.rake @@ -2,9 +2,8 @@ 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] # 表示相应的期数 + message_id = ENV['args'].split(",")[1] + status = ENV['args'].split(",")[2] # 表示相应的期数 if status.to_i == 1 start_time = '2018-12-16' @@ -23,17 +22,11 @@ namespace :sync do discusses = Discuss.where(dis_id: shixun_ids).where("created_at >? and created_at Date: Fri, 16 Aug 2019 07:45:28 +0800 Subject: [PATCH 03/13] message --- lib/tasks/public_message.rake | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/tasks/public_message.rake b/lib/tasks/public_message.rake index 837a72a0b..a804f9c2d 100644 --- a/lib/tasks/public_message.rake +++ b/lib/tasks/public_message.rake @@ -2,8 +2,9 @@ namespace :sync do task :public_message => :environment do subject_id = ENV['args'].split(",")[0] # 对应课程的id - message_id = ENV['args'].split(",")[1] - status = ENV['args'].split(",")[2] # 表示相应的期数 + 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' @@ -26,7 +27,8 @@ namespace :sync do discusses.find_each do |discuss| puts discuss.user_id puts discuss.content - MessageDetail.create!(message_id: message_id, content: discuss.try(:content)) + new_message = Message.create!(board: board_id, author: discuss.user_id) + MessageDetail.create!(message_id: new_message.id, content: discuss.try(:content)) end end From c9e8ea9e7f45e4a45f227eede5074c659e6cd9f3 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 16 Aug 2019 10:12:33 +0800 Subject: [PATCH 04/13] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/excellent_course_exercise.rake | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 From 0bef9700a1fa56efe4c206e755caaf4bea6c99ad Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 16 Aug 2019 11:07:22 +0800 Subject: [PATCH 05/13] =?UTF-8?q?=E6=97=B6=E9=97=B4=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/public_course.rake | 66 ++++++++++++++++++++++++++++------- lib/tasks/publick_course.rake | 1 - 2 files changed, 53 insertions(+), 14 deletions(-) diff --git a/lib/tasks/public_course.rake b/lib/tasks/public_course.rake index 9c5065982..7ed492968 100644 --- a/lib/tasks/public_course.rake +++ b/lib/tasks/public_course.rake @@ -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 - # 讨论区 - - 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/publick_course.rake b/lib/tasks/publick_course.rake index 2c12a859b..7e6f53a91 100644 --- a/lib/tasks/publick_course.rake +++ b/lib/tasks/publick_course.rake @@ -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 From 6451e82e532b8e2c2581d04c50d9db41f483e114 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 16 Aug 2019 11:18:17 +0800 Subject: [PATCH 06/13] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index bcfed25dd..e0ad6c5e5 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -221,8 +221,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 From 33cc18117f38981ce9913e7aa110abbd9dbd88a1 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 16 Aug 2019 11:18:53 +0800 Subject: [PATCH 07/13] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/public_course.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/public_course.rake b/lib/tasks/public_course.rake index 7ed492968..d2777e613 100644 --- a/lib/tasks/public_course.rake +++ b/lib/tasks/public_course.rake @@ -102,7 +102,7 @@ namespace :public_course do course.attachments.each do |atta| created_on = random_time start_time, end_time - atta.update_columns(is_publish: 1, created_on: created_on) + atta.update_columns(is_publish: 1, created_on: created_on, publish_time: created_on) end end From b377047dfd9fddc5056db752de55ea4f59c42308 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 16 Aug 2019 11:29:46 +0800 Subject: [PATCH 08/13] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index e0ad6c5e5..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] || [] From f63ea194e15be4259a2e98f51adfff9e951cf924 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 16 Aug 2019 07:46:56 +0800 Subject: [PATCH 09/13] rake .. --- lib/tasks/publick_course.rake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/tasks/publick_course.rake b/lib/tasks/publick_course.rake index 7e6f53a91..1e663067b 100644 --- a/lib/tasks/publick_course.rake +++ b/lib/tasks/publick_course.rake @@ -6,11 +6,13 @@ desc "同步精品课数据" namespace :public_course do task :student => :environment do - + if ENV['args'] subject_id = ENV['args'].split(",").first course_id = ENV['args'].split(",").last puts "subject_id is #{subject_id}" puts "course_id is #{course_id}" + end + 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) From 51fb3db2e3404b274f89e14bd95addeb79febcd9 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 16 Aug 2019 07:48:34 +0800 Subject: [PATCH 10/13] sync public --- lib/tasks/public_course.rake | 11 +++++++---- lib/tasks/publick_course.rake | 29 ----------------------------- 2 files changed, 7 insertions(+), 33 deletions(-) delete mode 100644 lib/tasks/publick_course.rake diff --git a/lib/tasks/public_course.rake b/lib/tasks/public_course.rake index d2777e613..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' diff --git a/lib/tasks/publick_course.rake b/lib/tasks/publick_course.rake deleted file mode 100644 index 1e663067b..000000000 --- a/lib/tasks/publick_course.rake +++ /dev/null @@ -1,29 +0,0 @@ -#coding=utf-8 -# 执行示例 bundle exec rake public_course:student args=149,2903 -# args 第一个参数是subject_id,第二个参数是课程course_id - -desc "同步精品课数据" -namespace :public_course do - task :student => :environment do - - if ENV['args'] - subject_id = ENV['args'].split(",").first - course_id = ENV['args'].split(",").last - puts "subject_id is #{subject_id}" - puts "course_id is #{course_id}" - end - - - 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) - end - end - end - end -end \ No newline at end of file From 4f9d645ec57ced7cc6abdd31fe055e27779d0690 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 16 Aug 2019 07:54:13 +0800 Subject: [PATCH 11/13] sync message --- lib/tasks/public_message.rake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/tasks/public_message.rake b/lib/tasks/public_message.rake index a804f9c2d..046f79909 100644 --- a/lib/tasks/public_message.rake +++ b/lib/tasks/public_message.rake @@ -26,8 +26,9 @@ namespace :sync do if discusses.present? discusses.find_each do |discuss| puts discuss.user_id - puts discuss.content - new_message = Message.create!(board: board_id, author: discuss.user_id) + puts board_id + puts message_id + new_message = Message.create!(board: board_id.to_i, author: discuss.user_id) MessageDetail.create!(message_id: new_message.id, content: discuss.try(:content)) end end From 475dea03581c0eab60894ef951ac80d6766b331d Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 16 Aug 2019 07:55:50 +0800 Subject: [PATCH 12/13] .. --- lib/tasks/public_message.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/public_message.rake b/lib/tasks/public_message.rake index 046f79909..d06c4a272 100644 --- a/lib/tasks/public_message.rake +++ b/lib/tasks/public_message.rake @@ -28,7 +28,7 @@ namespace :sync do puts discuss.user_id puts board_id puts message_id - new_message = Message.create!(board: board_id.to_i, author: discuss.user_id) + new_message = Message.create!(board_id: board_id.to_i, author: discuss.user_id) MessageDetail.create!(message_id: new_message.id, content: discuss.try(:content)) end end From d1f7143bd45148b4eadf0c9ddd52105637a0557e Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 16 Aug 2019 12:23:06 +0800 Subject: [PATCH 13/13] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/public_message.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/public_message.rake b/lib/tasks/public_message.rake index d06c4a272..ca54fbd7b 100644 --- a/lib/tasks/public_message.rake +++ b/lib/tasks/public_message.rake @@ -28,7 +28,7 @@ namespace :sync do puts discuss.user_id puts board_id puts message_id - new_message = Message.create!(board_id: board_id.to_i, author: discuss.user_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