From 21b1931824ff8060a9858be23d4c7fda3c8c6f5a Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 5 Sep 2019 14:07:36 +0800 Subject: [PATCH 1/8] merge --- lib/tasks/public_course_sync.rake | 13 +++++--- lib/tasks/public_message.rake | 55 ++++++------------------------- 2 files changed, 18 insertions(+), 50 deletions(-) diff --git a/lib/tasks/public_course_sync.rake b/lib/tasks/public_course_sync.rake index 928cd9113..a22a9f1f8 100644 --- a/lib/tasks/public_course_sync.rake +++ b/lib/tasks/public_course_sync.rake @@ -1,5 +1,5 @@ #coding=utf-8 -# 执行示例 bundle exec rake public_course:student args=149,2903 +# 执行示例 RAILS_ENV=production bundle exec rake public_classes:student args=3,3056,'2019-03-01','2019-03-31',10,1 # args 第一个参数是subject_id,第二个参数是课程course_id # 第一期时间:2018-12-16 至2019-03-31 # 第二期时间:2019-04-07 至2019-07-28 @@ -22,10 +22,13 @@ namespace :public_classes do task :student => :environment do puts "subject_id is #{subject_id}" puts "course_id is #{course_id}" + puts "start time is #{start_time}" + puts "end time is #{end_time}" + puts "limt is #{limit}" - user_ids = Myshixun.find_by_sql("select distinct(user_id) from myshixuns where created_at between #{start_time} and #{end_time} and shixun_id in (select shixun_id from stage_shixuns + user_ids = Myshixun.find_by_sql("select distinct(user_id) from myshixuns where created_at between '#{start_time}' and '#{end_time}' and shixun_id in (select shixun_id from stage_shixuns where stage_id in (select id from stages where subject_id=#{subject_id})) limit #{limit}").map(&:user_id) - puts user_ids + puts "user_ids count is #{user_ids.count}" if user_ids.present? user_ids.each do |user_id| puts user_id @@ -39,8 +42,8 @@ namespace :public_classes do end task :test_user => :environment do - users = User.where(is_test: true) - users.limit(limit).find_each do |user| + users = User.where(is_test: true).limit(limit) + users.find_each do |user| puts user.id CourseMember.create!(course_id: course_id, user_id: user.id, role: 4) end diff --git a/lib/tasks/public_message.rake b/lib/tasks/public_message.rake index 9b2f89224..00299cabc 100644 --- a/lib/tasks/public_message.rake +++ b/lib/tasks/public_message.rake @@ -1,30 +1,22 @@ # bundle exec rake sync:public_message args=149,2903 namespace :sync do - task :public_message => :environment do + if ENV['args'] 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 + start_time = ENV['args'].split(",")[4] # 表示课程模块 + end_time = ENV['args'].split(",")[5] # 表示课程模块 + limit = ENV['args'].split(",")[6] # 限制导入的数量 + 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 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(",")[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 discusses = Discuss.where("parent_id is null and dis_id=?", shixun_id) @@ -119,18 +94,8 @@ namespace :sync do end end - task :board_count => :environment do - Course.find_each do |course| - puts course.id - - 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 + task :delete_boards => :environment do + course = Course.find(course_id) + course.boards.destroy end end From 9d4194e7e437c4f40acd517e60d0b04387d269e2 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 5 Sep 2019 15:20:04 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E8=AE=A8=E8=AE=BA=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=8A=A0=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/public_message.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/public_message.rake b/lib/tasks/public_message.rake index 00299cabc..e51917a2e 100644 --- a/lib/tasks/public_message.rake +++ b/lib/tasks/public_message.rake @@ -1,4 +1,4 @@ -# bundle exec rake sync:public_message args=149,2903 +# RAILS_ENV=production bundle exec rake sync:sigle_message args=3,-1,8848,48337,'2017-07-23','2017-10-31',1000 namespace :sync do if ENV['args'] subject_id = ENV['args'].split(",")[0] # 对应课程的id @@ -33,7 +33,7 @@ namespace :sync do else 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("parent_id is null").where(dis_id: shixun_ids) + discusses = Discuss.where("parent_id is null and created_at between '#{start_time}' and '#{end_time}'").where(dis_id: shixun_ids) end discusses.each do |discuss| From 87ad4c1342dc6cebdb492d3a28593bf2275738e5 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 5 Sep 2019 22:53:19 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/user_login.rake | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lib/tasks/user_login.rake diff --git a/lib/tasks/user_login.rake b/lib/tasks/user_login.rake new file mode 100644 index 000000000..06315cc12 --- /dev/null +++ b/lib/tasks/user_login.rake @@ -0,0 +1,20 @@ +namespace :user do + task :update_login => :environment do + begin + user_count = ENV['args'].split(",")[0].to_i # 更新的用户数 + status = ENV['args'].split(",")[1] # 测试用户类型 + base_login = ENV['args'].split(",")[2] # 基本的用户参数 + + users = User.where(:is_test => status).limit(user_count) + users.each_with_index do |user, i| + puts i + + no = sprintf("%04d", i) + login = "#{base_login}#{no}" + user.update_attribute(:login, login) + end + rescue Exception => e + Rails.logger.error(e.message) + end + end +end \ No newline at end of file From abc7c0c928ea6f80a9fd022e0cd5b54ca2c92da0 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 5 Sep 2019 22:55:59 +0800 Subject: [PATCH 4/8] nick name and lastname --- lib/tasks/user_login.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/user_login.rake b/lib/tasks/user_login.rake index 06315cc12..dcd82297a 100644 --- a/lib/tasks/user_login.rake +++ b/lib/tasks/user_login.rake @@ -11,7 +11,7 @@ namespace :user do no = sprintf("%04d", i) login = "#{base_login}#{no}" - user.update_attribute(:login, login) + user.update_attributes(:login => login, :lastname => login, :nickname => login) end rescue Exception => e Rails.logger.error(e.message) From ada380b02cc5b8db25246f91e35e6d112c116abc Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 5 Sep 2019 23:02:28 +0800 Subject: [PATCH 5/8] yonghu --- lib/tasks/user_login.rake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/tasks/user_login.rake b/lib/tasks/user_login.rake index dcd82297a..59e861b98 100644 --- a/lib/tasks/user_login.rake +++ b/lib/tasks/user_login.rake @@ -11,7 +11,12 @@ namespace :user do no = sprintf("%04d", i) login = "#{base_login}#{no}" - user.update_attributes(:login => login, :lastname => login, :nickname => login) + puts no + puts login + user.login = login + user.lastname = login + user.nickname = login + user.save end rescue Exception => e Rails.logger.error(e.message) From 354f4cf49a7163d5912a41696ac7545c995f860a Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 6 Sep 2019 00:06:24 +0800 Subject: [PATCH 6/8] sql exec --- lib/tasks/user_login.rake | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/tasks/user_login.rake b/lib/tasks/user_login.rake index 59e861b98..31dfbb2b4 100644 --- a/lib/tasks/user_login.rake +++ b/lib/tasks/user_login.rake @@ -13,10 +13,13 @@ namespace :user do login = "#{base_login}#{no}" puts no puts login - user.login = login - user.lastname = login - user.nickname = login - user.save + + sql1 = "update users set login='#{login}' where id=#{user.id}" + sql2 = "update users set lastname='#{login}' where id=#{user.id}" + sql3 = "update users set nickname='#{login}' where id=#{user.id}" + ActiveRecord::Base.connection.execute(sql1) + ActiveRecord::Base.connection.execute(sql2) + ActiveRecord::Base.connection.execute(sql3) end rescue Exception => e Rails.logger.error(e.message) From b08fcf1cda71ce35ce234d796a7a2770289499f6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 6 Sep 2019 09:05:08 +0800 Subject: [PATCH 7/8] =?UTF-8?q?rake=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 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/excellent_course_exercise.rake b/lib/tasks/excellent_course_exercise.rake index 4309eec26..e05a813f4 100644 --- a/lib/tasks/excellent_course_exercise.rake +++ b/lib/tasks/excellent_course_exercise.rake @@ -14,7 +14,7 @@ namespace :excellent_course_exercise do course = Course.find_by(id: course_id) course.exercises.each_with_index do |exercise, index| - if exercise.exercise_users.where(commit_status: 1).count == 0 + # if exercise.exercise_users.where(commit_status: 1).count == 0 # 第一个试卷的参与人数和通过人数都是传的数据,后续的随机 if index == 0 members = course.students.order("id asc").limit(participant_count) @@ -26,7 +26,7 @@ namespace :excellent_course_exercise do members = course.students.order("id asc").limit(new_participant_count) update_exercise_user(exercise, members, new_pass_count) end - end + # end end end From e9ec302cfd05050259e412ce29bac1eac7229728 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 6 Sep 2019 10:35:42 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E7=9A=84=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=E4=B8=8D=E5=8A=A0=E7=AE=A1=E7=90=86=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/home_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 37cfed3fb..665eaa294 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -29,7 +29,7 @@ class HomeController < ApplicationController @subjects = Subject.where(homepage_show: 1).includes(:shixuns, :repertoire).limit(8) @tea_users = User.where(homepage_teacher: 1).includes(:user_extension).limit(10).order("experience desc") - @stu_users = User.includes(:user_extension).where(user_extensions: {identity: 1}).limit(10).order("experience desc") + @stu_users = User.where(is_test: 0).includes(:user_extension).where(user_extensions: {identity: 1}).limit(10).order("experience desc") end def search