From e4300243c0377737cb5e887aa21eb699f416f03b Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 16 Aug 2019 06:44:05 +0800 Subject: [PATCH 01/35] =?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/35] 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/35] 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/35] =?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/35] =?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/35] =?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/35] =?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/35] =?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/35] 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/35] 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/35] 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/35] .. --- 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/35] =?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 From f571a8bb83b1fb4f5df479116363146044fba086 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Fri, 16 Aug 2019 12:30:22 +0800 Subject: [PATCH 14/35] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/modules/courses/Resource/index.js | 1 + .../react/src/modules/courses/coursesPublic/SelectSetting.js | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/public/react/src/modules/courses/Resource/index.js b/public/react/src/modules/courses/Resource/index.js index d93c30d75..29c4a4ff5 100644 --- a/public/react/src/modules/courses/Resource/index.js +++ b/public/react/src/modules/courses/Resource/index.js @@ -757,6 +757,7 @@ class Fileslists extends Component{ setupdate={(id)=>this.seactall(id)} Cancel={this.Cancelvisible} has_course_groups={this.state.has_course_groups} + attachmentId={this.state.coursesecondcategoryid} />:""} Date: Fri, 16 Aug 2019 12:56:34 +0800 Subject: [PATCH 15/35] =?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/shixuns_controller.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 74942446e..8a59477c3 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -563,15 +563,15 @@ class ShixunsController < ApplicationController # end # 如果该实训是金课中的实训,则将当前用户加入到当期开课的课堂 - if StageShixun.exists?(shixun_id: @shixun.id, subject_id: Subject.where(excellent: 1)) - subject = Subject.where(excellent: 1, id: StageShixun.where(shixun_id: @shixun.id).pluck(:subject_id)).take - course = subject.courses.where("start_date is not null and start_date <= '#{Date.today}' and end_date is not null and end_date >= '#{Date.today}'").take - if course.present? && !CourseMember.exists?(course_id: course.id, user_id: current_user.id) - # 为了不影响后续操作,用create而不是create! - CourseMember.create(course_id: course.id, user_id: current_user.id, role: 4) - CourseAddStudentCreateWorksJob.perform_later(course.id, [current_user.id]) - end - end + # if StageShixun.exists?(shixun_id: @shixun.id, subject_id: Subject.where(excellent: 1)) + # subject = Subject.where(excellent: 1, id: StageShixun.where(shixun_id: @shixun.id).pluck(:subject_id)).take + # course = subject.courses.where("start_date is not null and start_date <= '#{Date.today}' and end_date is not null and end_date >= '#{Date.today}'").take + # if course.present? && !CourseMember.exists?(course_id: course.id, user_id: current_user.id) + # # 为了不影响后续操作,用create而不是create! + # CourseMember.create(course_id: course.id, user_id: current_user.id, role: 4) + # CourseAddStudentCreateWorksJob.perform_later(course.id, [current_user.id]) + # end + # end ActiveRecord::Base.transaction do begin From ac66f683f28221178d55251d2bbe2246cff57fed Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 16 Aug 2019 12:57:32 +0800 Subject: [PATCH 16/35] =?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/shixuns_controller.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 8a59477c3..c9b56bb98 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -555,12 +555,12 @@ class ShixunsController < ApplicationController # 判断实训是否全为选择题 is_choice_type = (min_challenges.size == min_challenges.select{|challenge| challenge.last == 1}.count) - # if !is_choice_type - # commit = GitService.commits(repo_path: @repo_path).try(:first) - # uid_logger("First comit########{commit}") - # tip_exception("开启实战前请先在版本库中提交代码") if commit.blank? - # commit_id = commit["id"] - # end + if !is_choice_type + commit = GitService.commits(repo_path: @repo_path).try(:first) + uid_logger("First comit########{commit}") + tip_exception("开启实战前请先在版本库中提交代码") if commit.blank? + commit_id = commit["id"] + end # 如果该实训是金课中的实训,则将当前用户加入到当期开课的课堂 # if StageShixun.exists?(shixun_id: @shixun.id, subject_id: Subject.where(excellent: 1)) From 031b93f7cfb0db09cf14eb270b34a80c327d039b Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 16 Aug 2019 13:48:41 +0800 Subject: [PATCH 17/35] =?UTF-8?q?=E5=A4=8D=E5=88=B6=E8=AF=BE=E5=A0=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/duplicate_course_service.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/services/duplicate_course_service.rb b/app/services/duplicate_course_service.rb index 9d61984db..8d6ce4f72 100644 --- a/app/services/duplicate_course_service.rb +++ b/app/services/duplicate_course_service.rb @@ -38,7 +38,12 @@ class DuplicateCourseService < ApplicationService def copy_course_modules! origin_course.course_modules.each do |course_module| attrs = course_module.as_json(only: %i[module_type position hidden module_name]) - CourseModule.create!(attrs.merge(course_id: course.id)) + new_course_module = CourseModule.create!(attrs.merge(course_id: course.id)) + # 复制子目录 + course_module.course_second_categories.each do |second_category| + category_attr = second_category.as_json(only: %i[category_type name position]) + CourseSecondCategory.create!(category_attr.merge(course_id: course.id, course_module_id: new_course_module.id)) + end end end From 8299c443ab5130f14aef33e8079386f949895b13 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 16 Aug 2019 14:21:15 +0800 Subject: [PATCH 18/35] =?UTF-8?q?=E5=A4=8D=E5=88=B6=E8=AF=BE=E5=A0=82?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/duplicate_course_service.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/services/duplicate_course_service.rb b/app/services/duplicate_course_service.rb index 8d6ce4f72..acff0a726 100644 --- a/app/services/duplicate_course_service.rb +++ b/app/services/duplicate_course_service.rb @@ -36,13 +36,16 @@ class DuplicateCourseService < ApplicationService end def copy_course_modules! + @second_category_list = {} origin_course.course_modules.each do |course_module| attrs = course_module.as_json(only: %i[module_type position hidden module_name]) new_course_module = CourseModule.create!(attrs.merge(course_id: course.id)) # 复制子目录 course_module.course_second_categories.each do |second_category| category_attr = second_category.as_json(only: %i[category_type name position]) - CourseSecondCategory.create!(category_attr.merge(course_id: course.id, course_module_id: new_course_module.id)) + new_second_category = + CourseSecondCategory.create!(category_attr.merge(course_id: course.id, course_module_id: new_course_module.id)) + @second_category_list[second_category.id] = new_second_category.id end end end @@ -55,7 +58,10 @@ class DuplicateCourseService < ApplicationService origin_course.homework_commons.where(homework_type: %i[normal group practice]).find_each do |origin_homework| homework_attrs = origin_homework.as_json(only: %i[name description homework_type homework_bank_id reference_answer]) - homework = HomeworkCommon.create!(homework_attrs.merge(user_id: user.id, course_id: course.id)) + course_second_category_id = @second_category_list[origin_homework.course_second_category_id] + + homework = HomeworkCommon.create!(homework_attrs.merge(user_id: user.id, course_id: course.id, + course_second_category_id:course_second_category_id)) origin_homework.attachments.find_each do |origin_attachment| attachment = origin_attachment.copy @@ -76,6 +82,7 @@ class DuplicateCourseService < ApplicationService HomeworksService.new.create_shixun_homework_cha_setting(homework, origin_homework.shixuns.first) end + origin_homework.increment!(:quotes) origin_homework.homework_bank.increment!(:quotes) if origin_homework.homework_bank end @@ -143,9 +150,9 @@ class DuplicateCourseService < ApplicationService attachment.copy_from = origin_attachment.copy_from || origin_attachment.id attachment.is_publish = 0 attachment.attachtype ||= 4 + attachment.course_second_category_id = @second_category_list[origin_attachment.course_second_category_id] attachment.save! - origin_course.update_quotes(attachment) end end From cc29cb619419ff4325004c6a0bab5bd43d233fe4 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 16 Aug 2019 14:27:00 +0800 Subject: [PATCH 19/35] =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/duplicate_course_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/duplicate_course_service.rb b/app/services/duplicate_course_service.rb index acff0a726..2456c81ff 100644 --- a/app/services/duplicate_course_service.rb +++ b/app/services/duplicate_course_service.rb @@ -11,7 +11,7 @@ class DuplicateCourseService < ApplicationService @course = copy_course! copy_course_modules! - + logger.info("###########second_category_list#{@second_category_list}") join_course! copy_homework_commons! From b81ddf1d0d31d3a1e921b3bd8a54fa14d6b40bdb Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 16 Aug 2019 14:28:01 +0800 Subject: [PATCH 20/35] =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/duplicate_course_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/duplicate_course_service.rb b/app/services/duplicate_course_service.rb index 2456c81ff..27ae2f784 100644 --- a/app/services/duplicate_course_service.rb +++ b/app/services/duplicate_course_service.rb @@ -11,7 +11,7 @@ class DuplicateCourseService < ApplicationService @course = copy_course! copy_course_modules! - logger.info("###########second_category_list#{@second_category_list}") + Rails.logger.info("###########second_category_list#{@second_category_list}") join_course! copy_homework_commons! From 4103d471aa197a83acb5f68ddc12d6b496d6ca8b Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 16 Aug 2019 14:39:20 +0800 Subject: [PATCH 21/35] =?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 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/tasks/excellent_course_exercise.rake b/lib/tasks/excellent_course_exercise.rake index c68cf6348..9f1484027 100644 --- a/lib/tasks/excellent_course_exercise.rake +++ b/lib/tasks/excellent_course_exercise.rake @@ -16,7 +16,16 @@ namespace :excellent_course_exercise do exercise_1884 = course.exercises.find_by(id: 1884) members_1.each_with_index do |member, index| if index < 821 - + exercise_1884.exercise_questions.where.not(question_type: 5).each do |question| + answer_option = { + :user_id => current_user.id, + :exercise_question_id => @exercise_question.id, + :exercise_choice_id => choice_id, + :answer_text => "" + } + ex_a = ExerciseAnswer.new(answer_option) + ex_a.save! + end else end From c0a4766dab4c7519661875ca532aacc15ac48ce3 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 16 Aug 2019 14:41:34 +0800 Subject: [PATCH 22/35] tz --- app/controllers/subjects_controller.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 6a381b258..55f8722a2 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -86,6 +86,16 @@ class SubjectsController < ApplicationController @shixuns = @subject.shixuns.published.pluck(:id) @courses = @subject.courses if @subject.excellent + @members = @subject.subject_members.includes(:user) + shixuns = @subject.shixuns.published.pluck(:id) + challenge_ids = Challenge.where(shixun_id: shixuns).pluck(:id) + # 实训路径中的所有实训标签 + @tags = ChallengeTag.where(challenge_id: challenge_ids).pluck(:name).uniq + # 用户获取的实训标签 + # @user_tags = @subject.shixuns.map(&:user_tags_name).flatten.uniq + @user_tags = user_shixun_tags challenge_ids, @user.id + @my_subject_progress = @subject.my_subject_progress + # 访问数变更 @subject.increment!(:visits) end From 6716cd9938736c3e33e13065a07bdb43f8bcc1d3 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 16 Aug 2019 14:42:34 +0800 Subject: [PATCH 23/35] tz --- app/views/subjects/show.json.jbuilder | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/views/subjects/show.json.jbuilder b/app/views/subjects/show.json.jbuilder index bf179b86d..93fa105a6 100644 --- a/app/views/subjects/show.json.jbuilder +++ b/app/views/subjects/show.json.jbuilder @@ -22,4 +22,26 @@ if @subject.excellent json.course_identity @user.course_identity(course) json.course_status subject_course_status course end +end + + +json.members @members do |member| + json.partial! 'subject_member', locals: { user: member.user } + json.role member.role +end + +# 技能标签 +json.tags @tags do |tag| + unless tag.blank? + json.tag_name tag + json.status @user_tags.include?(tag) + end +end + +# 我的进展 +json.progress do + json.my_score @subject.my_subject_score + json.all_score @subject.all_score + json.learned @subject.my_subject_progress + json.time @subject.my_consume_time end \ No newline at end of file From 32bb3c60442e692f6e778e07098e01d8271e1fd7 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 16 Aug 2019 15:05:09 +0800 Subject: [PATCH 24/35] video feature add teacher check --- app/controllers/users/base_controller.rb | 6 ++++++ app/controllers/users/video_auths_controller.rb | 2 +- app/controllers/users/videos_controller.rb | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/users/base_controller.rb b/app/controllers/users/base_controller.rb index 706b77802..7dd5ae024 100644 --- a/app/controllers/users/base_controller.rb +++ b/app/controllers/users/base_controller.rb @@ -26,6 +26,12 @@ class Users::BaseController < ApplicationController render_forbidden end + def require_auth_teacher! + return if user.admin_or_business? || observed_user.certification_teacher? + + render_forbidden + end + def page_value params[:page].to_i <= 0 ? 1 : params[:page].to_i end diff --git a/app/controllers/users/video_auths_controller.rb b/app/controllers/users/video_auths_controller.rb index d7950f873..0eec4dffb 100644 --- a/app/controllers/users/video_auths_controller.rb +++ b/app/controllers/users/video_auths_controller.rb @@ -1,5 +1,5 @@ class Users::VideoAuthsController < Users::BaseController - before_action :private_user_resources! + before_action :private_user_resources!, :require_auth_teacher! def create result = Videos::CreateAuthService.call(observed_user, create_params) diff --git a/app/controllers/users/videos_controller.rb b/app/controllers/users/videos_controller.rb index e4dffec23..1df726c0c 100644 --- a/app/controllers/users/videos_controller.rb +++ b/app/controllers/users/videos_controller.rb @@ -1,5 +1,5 @@ class Users::VideosController < Users::BaseController - before_action :private_user_resources! + before_action :private_user_resources!, :require_auth_teacher! helper_method :current_video From 43d8f62f0fcec73b1872d90bafc6133fce3b6602 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 16 Aug 2019 15:28:24 +0800 Subject: [PATCH 25/35] fix --- app/controllers/users/base_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users/base_controller.rb b/app/controllers/users/base_controller.rb index 7dd5ae024..eb6b98048 100644 --- a/app/controllers/users/base_controller.rb +++ b/app/controllers/users/base_controller.rb @@ -27,7 +27,7 @@ class Users::BaseController < ApplicationController end def require_auth_teacher! - return if user.admin_or_business? || observed_user.certification_teacher? + return if current_user.admin_or_business? || observed_user.certification_teacher? render_forbidden end From 965f9b65f86f800465a12c1062cd5a6383c0cad3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Fri, 16 Aug 2019 15:50:33 +0800 Subject: [PATCH 26/35] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/config/webpack.config.dev.js | 2 +- .../modules/courses/Resource/Fileslistitem.js | 25 ++++++++++++++----- .../courses/coursesPublic/Showoldfiles.js | 19 ++++++++++++-- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/public/react/config/webpack.config.dev.js b/public/react/config/webpack.config.dev.js index 6e78fd410..510bcaa4f 100644 --- a/public/react/config/webpack.config.dev.js +++ b/public/react/config/webpack.config.dev.js @@ -29,7 +29,7 @@ const env = getClientEnvironment(publicUrl); module.exports = { // You may want 'eval' instead if you prefer to see the compiled output in DevTools. // See the discussion in https://github.com/facebookincubator/create-react-app/issues/343.s - devtool: "cheap-module-eval-source-map", + // devtool: "cheap-module-eval-source-map", // 开启调试 // These are the "entry points" to our application. // This means they will be the "root" imports that are included in JS bundle. diff --git a/public/react/src/modules/courses/Resource/Fileslistitem.js b/public/react/src/modules/courses/Resource/Fileslistitem.js index f0aec7f64..5832770f1 100644 --- a/public/react/src/modules/courses/Resource/Fileslistitem.js +++ b/public/react/src/modules/courses/Resource/Fileslistitem.js @@ -36,7 +36,16 @@ class Fileslistitem extends Component{ course_id:coursesId }, }).then((result)=>{ - if(result.data.attachment_histories.length===0){ + + if(result.data.attachment_histories.length===0){ + if(result.data.is_pdf===true){ + axios.get(result.data.url).then((result)=>{ + var binaryData = []; + binaryData.push(result.data); + this.url =window.URL.createObjectURL(new Blob(binaryData, {type:"application/pdf"})); + window.open(this.url); + }) + }else{ let link = document.createElement('a'); document.body.appendChild(link); link.href = result.data.url; @@ -46,12 +55,15 @@ class Fileslistitem extends Component{ evt.initEvent("click", false, false); link.dispatchEvent(evt); document.body.removeChild(link); + } }else{ - this.setState({ - Showoldfiles:true, - allfiles:result.data - }) - } + this.setState({ + Showoldfiles:true, + allfiles:result.data + }) + } + + }).catch((error)=>{ console.log(error) }) @@ -144,6 +156,7 @@ class Fileslistitem extends Component{ loadtype={this.state.Loadtype} />:""} { + axios.get(url).then((result)=>{ + var binaryData = []; + binaryData.push(result.data); + this.url =window.URL.createObjectURL(new Blob(binaryData, {type:"application/pdf"})); + window.open(this.url); + }) + } render(){ let {visible,allfiles}=this.props; @@ -175,7 +183,10 @@ class Showoldfiles extends Component{
  • - {allfiles.title} + {allfiles.is_pdf===false? + {allfiles.title}: + this.showfiless(allfiles.url)} >{allfiles.title} + } 当前版本
  • @@ -191,7 +202,11 @@ class Showoldfiles extends Component{
  • - {item.title} + + {allfiles.is_pdf===false? + {item.title}: + this.showfiless(item.url)} >{item.title} + }
  • From 7b99a1a5c5f85a8adf74c9430f05cd2bfedd8307 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 16 Aug 2019 15:55:22 +0800 Subject: [PATCH 27/35] =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=99=84=E4=BB=B6=E7=9A=84pdf=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 7 +------ app/models/attachment.rb | 11 +++++++++++ .../_attachment_history.json.jbuilder | 1 + app/views/attachments/_attachment_small.json.jbuilder | 3 ++- app/views/files/histories.json.jbuilder | 2 +- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index bcfed25dd..2cfa61cc9 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -260,12 +260,7 @@ class FilesController < ApplicationController return normal_status(-2, "该课程下没有id为 #{params[:id]}的资源") if @file.nil? return normal_status(403, "您没有权限进行该操作") if @user != @file.author && !@user.teacher_of_course?(@course) && !@file.public? - @is_pdf = false - file_content_type = @file.content_type - file_ext_type = File.extname(@file.filename).strip.downcase[1..-1] - if (file_content_type.present? && file_content_type.downcase.include?("pdf")) || (file_ext_type.present? && file_ext_type.include?("pdf")) - @is_pdf = true - end + @attachment_histories = @file.attachment_histories end diff --git a/app/models/attachment.rb b/app/models/attachment.rb index bdd749108..3a512278a 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -115,4 +115,15 @@ class Attachment < ApplicationRecord end end + #判断是否为pdf文件 + def is_pdf? + is_pdf = false + file_content_type = content_type + file_ext_type = File.extname(filename).strip.downcase[1..-1] + if (file_content_type.present? && file_content_type.downcase.include?("pdf")) || (file_ext_type.present? && file_ext_type.include?("pdf")) + is_pdf = true + end + is_pdf + end + end diff --git a/app/views/attachment_histories/_attachment_history.json.jbuilder b/app/views/attachment_histories/_attachment_history.json.jbuilder index 37b8b95c1..65ca1e887 100644 --- a/app/views/attachment_histories/_attachment_history.json.jbuilder +++ b/app/views/attachment_histories/_attachment_history.json.jbuilder @@ -7,3 +7,4 @@ json.quotes attachment.quotes_count json.downloads_count attachment.downloads_count json.created_on attachment.created_on json.url attachment_path(attachment, type: 'history') +json.is_pdf attachment.is_pdf? diff --git a/app/views/attachments/_attachment_small.json.jbuilder b/app/views/attachments/_attachment_small.json.jbuilder index d9a976bde..97cbee120 100644 --- a/app/views/attachments/_attachment_small.json.jbuilder +++ b/app/views/attachments/_attachment_small.json.jbuilder @@ -2,4 +2,5 @@ json.id attachment.id json.title attachment.title json.filesize number_to_human_size(attachment.filesize) json.url download_url(attachment) -json.created_on attachment.created_on \ No newline at end of file +json.created_on attachment.created_on +json.is_pdf attachment.is_pdf? \ No newline at end of file diff --git a/app/views/files/histories.json.jbuilder b/app/views/files/histories.json.jbuilder index 9dfec4fd4..7039752e7 100644 --- a/app/views/files/histories.json.jbuilder +++ b/app/views/files/histories.json.jbuilder @@ -1,3 +1,3 @@ -json.is_pdf @is_pdf + json.partial! 'attachments/attachment_small', attachment: @file json.partial! "attachment_histories/list", attachment_histories: @attachment_histories From 1677cea34dbf1a5b24a20dddbecc5d885f3da78b Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 16 Aug 2019 16:01:22 +0800 Subject: [PATCH 28/35] =?UTF-8?q?=E6=B3=A8=E5=86=8C=E8=80=81=E5=B8=88?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E8=87=AA=E5=8A=A8=E5=8A=A0=E5=85=A5=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=E8=AF=BE=E5=A0=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/users/update_account_service.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/services/users/update_account_service.rb b/app/services/users/update_account_service.rb index c8ba6da61..3f0aa8cc8 100644 --- a/app/services/users/update_account_service.rb +++ b/app/services/users/update_account_service.rb @@ -51,8 +51,10 @@ class Users::UpdateAccountService < ApplicationService if first_full_reward RewardGradeService.call(user, container_id: user.id, container_type: 'Account', score: 500) - - sms_notify_admin(user.lastname) if user.user_extension.teacher? + if user.user_extension.teacher? + join_course(user.id,1309, 2) + sms_notify_admin(user.lastname) + end end user @@ -73,4 +75,11 @@ class Users::UpdateAccountService < ApplicationService rescue => ex Util.logger_error(ex) end + + def join_course(user_id, course_id, identity) + course = Course.find_by(id: course_id) + return unless course + attr = {course_id: course_id, role: identity, user_id: user_id} + CourseMember.create!(attr) + end end \ No newline at end of file From 653fb5191d595711dbc9fc8b8deedf532f43bf00 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 16 Aug 2019 16:09:32 +0800 Subject: [PATCH 29/35] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=A4=E6=96=ADpdf?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/attachment_history.rb | 10 ++++++++++ .../_attachment_history.json.jbuilder | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/attachment_history.rb b/app/models/attachment_history.rb index 220f92535..c19146b95 100644 --- a/app/models/attachment_history.rb +++ b/app/models/attachment_history.rb @@ -20,4 +20,14 @@ class AttachmentHistory < ApplicationRecord is_public == 1 end + def is_history_pdf? + is_pdf = false + file_content_type = content_type + file_ext_type = File.extname(filename).strip.downcase[1..-1] + if (file_content_type.present? && file_content_type.downcase.include?("pdf")) || (file_ext_type.present? && file_ext_type.include?("pdf")) + is_pdf = true + end + is_pdf + end + end diff --git a/app/views/attachment_histories/_attachment_history.json.jbuilder b/app/views/attachment_histories/_attachment_history.json.jbuilder index 65ca1e887..8930e1b2d 100644 --- a/app/views/attachment_histories/_attachment_history.json.jbuilder +++ b/app/views/attachment_histories/_attachment_history.json.jbuilder @@ -7,4 +7,4 @@ json.quotes attachment.quotes_count json.downloads_count attachment.downloads_count json.created_on attachment.created_on json.url attachment_path(attachment, type: 'history') -json.is_pdf attachment.is_pdf? +json.is_pdf attachment.is_history_pdf? From de93d52d8cdc9a818e48fb9db5c1e377dc388683 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Fri, 16 Aug 2019 16:35:38 +0800 Subject: [PATCH 30/35] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/react/src/modules/courses/Resource/Fileslistitem.js | 2 +- .../react/src/modules/courses/coursesPublic/Showoldfiles.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/public/react/src/modules/courses/Resource/Fileslistitem.js b/public/react/src/modules/courses/Resource/Fileslistitem.js index 5832770f1..c26f390cf 100644 --- a/public/react/src/modules/courses/Resource/Fileslistitem.js +++ b/public/react/src/modules/courses/Resource/Fileslistitem.js @@ -48,7 +48,7 @@ class Fileslistitem extends Component{ }else{ let link = document.createElement('a'); document.body.appendChild(link); - link.href = result.data.url; + link.href = "/api"+result.data.url; link.download = result.data.title; //兼容火狐浏览器 let evt = document.createEvent("MouseEvents"); diff --git a/public/react/src/modules/courses/coursesPublic/Showoldfiles.js b/public/react/src/modules/courses/coursesPublic/Showoldfiles.js index 8f1e7a29f..4bf98fb4f 100644 --- a/public/react/src/modules/courses/coursesPublic/Showoldfiles.js +++ b/public/react/src/modules/courses/coursesPublic/Showoldfiles.js @@ -184,7 +184,7 @@ class Showoldfiles extends Component{
  • {allfiles.is_pdf===false? - {allfiles.title}: + {allfiles.title}: this.showfiless(allfiles.url)} >{allfiles.title} } 当前版本 @@ -203,8 +203,8 @@ class Showoldfiles extends Component{
  • - {allfiles.is_pdf===false? - {item.title}: + {item.is_pdf===false? + {item.title}: this.showfiless(item.url)} >{item.title} }
  • From 31cae1194bbc03b16a4c2e802049725ac84f7720 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 16 Aug 2019 16:36:51 +0800 Subject: [PATCH 31/35] =?UTF-8?q?=E8=BF=87=E6=BB=A4=E9=99=84=E4=BB=B6?= =?UTF-8?q?=E7=9A=84api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/application_helper.rb | 2 +- .../attachment_histories/_attachment_history.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 099d45406..e6f2e1720 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -258,7 +258,7 @@ module ApplicationHelper end def download_url attachment - attachment_path(attachment) + attachment_path(attachment).gsub("/api","") end # 耗时:天、小时、分、秒 diff --git a/app/views/attachment_histories/_attachment_history.json.jbuilder b/app/views/attachment_histories/_attachment_history.json.jbuilder index 8930e1b2d..afb359e08 100644 --- a/app/views/attachment_histories/_attachment_history.json.jbuilder +++ b/app/views/attachment_histories/_attachment_history.json.jbuilder @@ -6,5 +6,5 @@ json.publish_time attachment.publish_time json.quotes attachment.quotes_count json.downloads_count attachment.downloads_count json.created_on attachment.created_on -json.url attachment_path(attachment, type: 'history') +json.url attachment_path(attachment, type: 'history').gsub("/api","") json.is_pdf attachment.is_history_pdf? From 83d63dcfaf947306a999d32726e7b6bdbfd79180 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 16 Aug 2019 16:52:02 +0800 Subject: [PATCH 32/35] =?UTF-8?q?=E9=87=91=E8=AF=BE=E8=AF=95=E5=8D=B7?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/excellent_course_exercise.rake | 198 ++++++++++++++++++++--- 1 file changed, 175 insertions(+), 23 deletions(-) diff --git a/lib/tasks/excellent_course_exercise.rake b/lib/tasks/excellent_course_exercise.rake index 9f1484027..a607c24a0 100644 --- a/lib/tasks/excellent_course_exercise.rake +++ b/lib/tasks/excellent_course_exercise.rake @@ -1,34 +1,186 @@ #coding=utf-8 -# 执行示例 bundle exec rake excellent_course_exercise:student_answer args=149,2903 +# 执行示例 bundle exec rake excellent_course_exercise:student_answer args=2933,1042,823 +# args 第一个是course_id, 第二个是参与人数, 第三个是通过人数 desc "同步精品课的学生试卷数据" namespace :excellent_course_exercise do + if ENV['args'] + course_id = ENV['args'].split(",")[0] # 对应课堂的id + participant_count = ENV['args'].split(",")[1].to_i # 表示参与人数 + pass_count = ENV['args'].split(",")[2].to_i # 表示通过人数 + end + task :student_answer => :environment do - course = Course.find_by(id: 2933) - - participant_count = 1042 - pass_count = 823 - - members_1 = course.students.order("id asc").limit(987) - 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 - exercise_1884.exercise_questions.where.not(question_type: 5).each do |question| - answer_option = { - :user_id => current_user.id, - :exercise_question_id => @exercise_question.id, - :exercise_choice_id => choice_id, - :answer_text => "" - } - ex_a = ExerciseAnswer.new(answer_option) - ex_a.save! - end + course = Course.find_by(id: course_id) + + course.exercises.each_with_index do |exercise, index| + # 第一个试卷的参与人数和通过人数都是传的数据,后续的随机 + if index == 0 + members = course.students.order("id asc").limit(participant_count) + update_exercise_user(exercise, members, pass_count) + else + new_participant_count = rand((participant_count - 423)..participant_count) + new_pass_count = rand((new_participant_count - 113)..new_participant_count) + + members = course.students.order("id asc").limit(new_participant_count) + update_exercise_user(exercise, members, new_pass_count) + end + end + end + + def update_exercise_user exercise, members, pass_count + exercise_question_ids = exercise.exercise_questions.where(question_type: 0).pluck(:id) + + # index < pass_count 之前的学生都是通关的,之后的未通过 + members.each_with_index do |member, index| + exercise_user = exercise.exercise_users.where(user_id: member.user_id).take + if exercise_question_ids.length == 20 + rand_num = index < pass_count - 1 ? 20 : rand(1..16) + elsif exercise_question_ids.length == 17 + rand_num = index < pass_count - 1 ? rand(13..17) : rand(1..11) else + rand_num = exercise_question_ids.length + end + if exercise_user && exercise_user.commit_status == 0 + exercise_question_ids = exercise_question_ids.sample(rand_num) + questions = exercise.exercise_questions.where(id: exercise_question_ids) + create_exercise_answer questions, member.user_id + + total_score = calculate_student_score(exercise, member.user) + commit_option = { + :status => 1, + :commit_status => 1, + :start_at => exercise.publish_time, + :end_at => exercise.end_time, + :objective_score => total_score, + :score => total_score, + :subjective_score => 0 + } + exercise_user.update_columns(commit_option) + end + end + end + + def create_exercise_answer questions, user_id + questions.each do |question| + choice_position = question.exercise_standard_answers.take&.exercise_choice_id + choice = question.exercise_choices.where(choice_position: choice_position).take + + answer_option = { + :user_id => user_id, + :exercise_question_id => question.id, + :exercise_choice_id => choice&.id, + :answer_text => "" + } + ex_a = ExerciseAnswer.new(answer_option) + ex_a.save! + end + end + + #计算试卷的总分和试卷的答题状态 + def calculate_student_score(exercise,user) + score1 = 0.0 #选择题/判断题 + score2 = 0.0 #填空题 + score5 = 0.0 #实训题 + total_score = 0.0 + ques_stand = [] #问题是否正确 + exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers,:exercise_shixun_challenges) + exercise_questions&.each do |q| + begin + if q.question_type != 5 + answers_content = q.exercise_answers.where(user_id: user.id) #学生的答案 + else + answers_content = q.exercise_shixun_answers.where(user_id: user.id) #学生的答案 + end + if q.question_type <= 2 #为选择题或判断题时 + if answers_content.present? #学生有回答时 + answer_choice_array = [] + answers_content.each do |a| + answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置 + end + user_answer_content = answer_choice_array.sort + standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 + if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 + if standard_answer.size > 0 + q_score_1 = q.question_score + # q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 + else + q_score_1 = 0.0 + end + answers_content.update_all(:score => q_score_1) + score1 = score1 + q.question_score + else + answers_content.update_all(:score => -1.0) + score1 += 0.0 + end + else + score1 += 0.0 + end + elsif q.question_type == 5 #实训题时,主观题这里不评分 + q.exercise_shixun_challenges&.each do |exercise_cha| + game = Game.user_games(user.id,exercise_cha.challenge_id)&.first #当前用户的关卡 + if game.present? + exercise_cha_score = 0.0 + answer_status = 0 + # if game.status == 2 && game.final_score >= 0 + if game.final_score > 0 + exercise_cha_score = game.real_score(exercise_cha.question_score) + # exercise_cha_score = exercise_cha.question_score #每一关卡的得分 + answer_status = 1 + end + ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id) + code = nil + if exercise_cha.challenge&.path.present? + cha_path = challenge_path(exercise_cha.challenge&.path) + game_challenge = game.game_codes.search_challenge_path(cha_path)&.first + if game_challenge.present? + game_code = game_challenge + code = game_code.try(:new_code) + else + code = git_fle_content(game.myshixun.repo_path,cha_path) + end + end + if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 + ### Todo 实训题的_shixun_details里的代码是不是直接从这里取出就可以了?涉及到code的多个版本库的修改 + sx_option = { + :exercise_question_id => q.id, + :exercise_shixun_challenge_id => exercise_cha.id, + :user_id => user.id, + :score => exercise_cha_score.round(1), + :answer_text => code, + :status => answer_status + } + ExerciseShixunAnswer.create(sx_option) + else + ex_shixun_answer_content.first.update_attributes(score:exercise_cha_score.round(1),answer_text:code) + end + score5 += exercise_cha_score + else + score5 += 0.0 + end + end + end + user_scores = answers_content.blank? ? 0.0 : answers_content.score_reviewed.pluck(:score).sum + if user_scores > 0.0 + stand_answer = 1 + else + stand_answer = 0 + end + ques_option = { + "q_id":q.id, #该问题的id + "q_type":q.question_type, + "q_position":q.question_number, #该问题的位置 + "stand_status":stand_answer, #该问题是否正确,1为正确,0为错误 + "user_score":user_scores.round(1) #每个问题的总得分 + } + ques_stand.push(ques_option) + rescue Exception => e + Rails.logger.info("calcuclate_score_have_error____________________________#{e}") + next end end + total_score = score1 + score2 + score5 + total_score end end \ No newline at end of file From 81047b02a39881af311c52dd835a6848919c6dd5 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 16 Aug 2019 16:54:28 +0800 Subject: [PATCH 33/35] video feature: upload video api error message extense --- app/libs/aliyun_vod/service/video_upload.rb | 9 +++++++++ app/services/videos/create_auth_service.rb | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/libs/aliyun_vod/service/video_upload.rb b/app/libs/aliyun_vod/service/video_upload.rb index 97ecd970b..a5ade72f9 100644 --- a/app/libs/aliyun_vod/service/video_upload.rb +++ b/app/libs/aliyun_vod/service/video_upload.rb @@ -16,6 +16,15 @@ module AliyunVod::Service::VideoUpload result = request(:post, params) + if result['Code'].present? + message = + case result['Code'] + when 'InvalidFileName.Extension' then '不支持的文件格式' + when 'IllegalCharacters' then '文件名称包含非法字符' + end + raise AliyunVod::Error, message if message.present? + end + raise AliyunVod::Error, '获取上传凭证失败' if result['UploadAddress'].blank? result diff --git a/app/services/videos/create_auth_service.rb b/app/services/videos/create_auth_service.rb index 8d83ca4e2..3c7ecf2f6 100644 --- a/app/services/videos/create_auth_service.rb +++ b/app/services/videos/create_auth_service.rb @@ -35,7 +35,7 @@ class Videos::CreateAuthService < ApplicationService def upload_video_result AliyunVod::Service.create_upload_video(title, filename, params) - rescue AliyunVod::Error => _ - raise Error, '获取视频上传凭证失败' + rescue AliyunVod::Error => ex + raise Error, ex.message || '获取视频上传凭证失败' end end \ No newline at end of file From dd143f45430619040aca9a3acfca9f8985237cf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=A0=91=E6=98=8E?= <775174143@qq.com> Date: Fri, 16 Aug 2019 17:09:14 +0800 Subject: [PATCH 34/35] =?UTF-8?q?=E8=B5=84=E6=BA=90=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0pdf=20=E5=B1=95=E7=A4=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/courses/Resource/Fileslistitem.js | 17 +++++++++++------ .../courses/coursesPublic/Showoldfiles.js | 6 +++++- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/public/react/src/modules/courses/Resource/Fileslistitem.js b/public/react/src/modules/courses/Resource/Fileslistitem.js index c26f390cf..563724040 100644 --- a/public/react/src/modules/courses/Resource/Fileslistitem.js +++ b/public/react/src/modules/courses/Resource/Fileslistitem.js @@ -39,12 +39,17 @@ class Fileslistitem extends Component{ if(result.data.attachment_histories.length===0){ if(result.data.is_pdf===true){ - axios.get(result.data.url).then((result)=>{ - var binaryData = []; - binaryData.push(result.data); - this.url =window.URL.createObjectURL(new Blob(binaryData, {type:"application/pdf"})); - window.open(this.url); - }) + //预览pdf + axios({ + method:'get', + url:result.data.url, + responseType: 'arraybuffer', + }).then((result)=>{ + var binaryData = []; + binaryData.push(result.data); + this.url =window.URL.createObjectURL(new Blob(binaryData, {type:"application/pdf"})); + window.open(this.url); + }) }else{ let link = document.createElement('a'); document.body.appendChild(link); diff --git a/public/react/src/modules/courses/coursesPublic/Showoldfiles.js b/public/react/src/modules/courses/coursesPublic/Showoldfiles.js index 4bf98fb4f..483768271 100644 --- a/public/react/src/modules/courses/coursesPublic/Showoldfiles.js +++ b/public/react/src/modules/courses/coursesPublic/Showoldfiles.js @@ -43,7 +43,11 @@ class Showoldfiles extends Component{ } showfiless=(url)=>{ - axios.get(url).then((result)=>{ + axios({ + method:'get', + url:url, + responseType: 'arraybuffer', + }).then((result)=>{ var binaryData = []; binaryData.push(result.data); this.url =window.URL.createObjectURL(new Blob(binaryData, {type:"application/pdf"})); From b5c560c1d12b1b7aeb6728aaaa9a474dc909cda2 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 16 Aug 2019 17:23:41 +0800 Subject: [PATCH 35/35] =?UTF-8?q?=E6=B3=A8=E5=86=8C=E4=B8=87=E8=83=BD?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index aa9ddebf0..2524c53d8 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -33,7 +33,7 @@ class AccountsController < ApplicationController uid_logger("start register: verifi_code is #{verifi_code}, code is #{code}, time is #{Time.now.to_i - verifi_code.try(:created_at).to_i}") # check_code = (verifi_code.try(:code) == code.strip && (Time.now.to_i - verifi_code.created_at.to_i) <= 10*60) # todo 上线前请删除万能验证码"513231" - if code != "513231" + unless code == "513231" && request.host == "47.96.87.25" return normal_status(-2, "验证码不正确") if verifi_code.try(:code) != code.strip return normal_status(-2, "验证码已失效") if !verifi_code&.effective? end