From fea8a31f747c2a7b44962638ff9b71db6d52121f Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Wed, 11 Sep 2019 11:06:42 +0800 Subject: [PATCH 1/5] test --- public/react/src/AppConfig.js | 1 + 1 file changed, 1 insertion(+) diff --git a/public/react/src/AppConfig.js b/public/react/src/AppConfig.js index 939d2cdaa..9653eb690 100644 --- a/public/react/src/AppConfig.js +++ b/public/react/src/AppConfig.js @@ -45,6 +45,7 @@ export function initAxiosInterceptors(props) { proxy="http://47.96.87.25:48080" // wy proxy="https://pre-newweb.educoder.net" + proxy="https://test-newweb.educoder.net" // wy // proxy="http://192.168.2.63:3001" From a7ec58e1b2368e026b8be3ab0c7a066a85f3c1b8 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 11 Sep 2019 11:07:41 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=BC=82=E6=AD=A5=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E7=9A=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 48 ++++---- .../homework_commons_controller.rb | 104 ++++++++---------- app/controllers/subjects_controller.rb | 28 +++-- ...90911020749_migrate_shixun_student_work.rb | 18 +++ 4 files changed, 96 insertions(+), 102 deletions(-) create mode 100644 db/migrate/20190911020749_migrate_shixun_student_work.rb diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index bec53f993..a180130f4 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -812,43 +812,37 @@ class CoursesController < ApplicationController # 搜索添加学生 def add_students_by_search + student_ids = [] ActiveRecord::Base.transaction do - begin - user_ids = params[:user_ids] - course_group_id = params[:course_group_id].to_i - if course_group_id != 0 - course_group = CourseGroup.find(course_group_id) - course_group_id = course_group.id - end + user_ids = params[:user_ids] + course_group_id = params[:course_group_id].to_i + if course_group_id != 0 + course_group = CourseGroup.find(course_group_id) + course_group_id = course_group.id + end - student_ids = [] - user_ids.each do |user_id| - existing_course_member = @course.course_members.find_by(user_id: user_id.to_i) - new_student = CourseMember.new(user_id: user_id.to_i, course_id: @course.id, course_group_id: course_group_id, role: 4) + user_ids.each do |user_id| + existing_course_member = @course.course_members.find_by(user_id: user_id.to_i) + new_student = CourseMember.new(user_id: user_id.to_i, course_id: @course.id, course_group_id: course_group_id, role: 4) - if existing_course_member.present? - if existing_course_member.STUDENT? - existing_course_member.update_attributes(course_group_id: course_group_id) - else - new_student.is_active = 0 if existing_course_member.is_active - new_student.save! - student_ids << user_id - end + if existing_course_member.present? + if existing_course_member.STUDENT? + existing_course_member.update_attributes(course_group_id: course_group_id) else + new_student.is_active = 0 if existing_course_member.is_active new_student.save! student_ids << user_id end + else + new_student.save! + student_ids << user_id end - - CourseAddStudentCreateWorksJob.perform_later(@course.id, student_ids) if student_ids.present? - TeacherInviteJoinCourseNotifyJob.perform_later(current_user.id, @course.id, 10, student_ids) if student_ids.present? - normal_status(0, "添加成功") - rescue => e - uid_logger(e.message) - tip_exception("添加失败") - raise ActiveRecord::Rollback end end + + CourseAddStudentCreateWorksJob.perform_later(@course.id, student_ids) if student_ids.present? + TeacherInviteJoinCourseNotifyJob.perform_later(current_user.id, @course.id, 10, student_ids) if student_ids.present? + normal_status(0, "添加成功") end # 获取历史课堂,即用户管理的所有课堂以及课堂下的分班(去除当前课堂) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index c0da42aa8..3b395bab2 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -927,18 +927,10 @@ class HomeworkCommonsController < ApplicationController unless params[:category_id].blank? @category = @course.course_second_categories.find_by(id: params[:category_id], category_type: "shixun_homework") end - ActiveRecord::Base.transaction do - begin - shixuns.each do |shixun| - homework = HomeworksService.new.create_homework shixun, @course, @category, current_user - @homework_ids << homework.id - CreateStudentWorkJob.perform_later(homework.id) - end - rescue Exception => e - uid_logger(e.message) - tip_exception("创建失败") - raise ActiveRecord::Rollback - end + shixuns.each do |shixun| + homework = HomeworksService.new.create_homework shixun, @course, @category, current_user + @homework_ids << homework.id + CreateStudentWorkJob.perform_later(homework.id) end end @@ -1019,29 +1011,21 @@ class HomeworkCommonsController < ApplicationController none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id) course_module = @course.course_modules.find_by(module_type: "shixun_homework") - ActiveRecord::Base.transaction do - begin - subjects.each do |subject| + subjects.each do |subject| - subject.stages.each do |stage| + subject.stages.each do |stage| - # 为实训作业创建与stage同名的子目录 - category = CourseSecondCategory.find_by(name: stage.name, course_id: @course.id, category_type: "shixun_homework") || - CourseSecondCategory.create!(name: stage.name, course_id: @course.id, category_type: "shixun_homework", - course_module_id: course_module.id, position: course_module.course_second_categories.count + 1) + # 为实训作业创建与stage同名的子目录 + category = CourseSecondCategory.find_by(name: stage.name, course_id: @course.id, category_type: "shixun_homework") || + CourseSecondCategory.create!(name: stage.name, course_id: @course.id, category_type: "shixun_homework", + course_module_id: course_module.id, position: course_module.course_second_categories.count + 1) - # 去掉不对当前用户的单位公开的实训,已发布的实训 - stage.shixuns.where.not(shixuns: {id: none_shixun_ids}).unhidden.each do |shixun| - homework = HomeworksService.new.create_homework shixun, @course, category, current_user - @homework_ids << homework.id - CreateStudentWorkJob.perform_later(homework.id) - end - end + # 去掉不对当前用户的单位公开的实训,已发布的实训 + stage.shixuns.where.not(shixuns: {id: none_shixun_ids}).unhidden.each do |shixun| + homework = HomeworksService.new.create_homework shixun, @course, category, current_user + @homework_ids << homework.id + CreateStudentWorkJob.perform_later(homework.id) end - rescue Exception => e - uid_logger(e.message) - tip_exception("创建失败") - raise ActiveRecord::Rollback end end end @@ -1070,7 +1054,7 @@ class HomeworkCommonsController < ApplicationController charge_group_ids = @course.charge_group_ids(current_user) publish_groups = charge_group_ids & params[:group_ids] if params[:group_ids] - ActiveRecord::Base.transaction do + # ActiveRecord::Base.transaction do begin homeworks.each do |homework| # 作业未发布时 @@ -1141,7 +1125,7 @@ class HomeworkCommonsController < ApplicationController tip_exception("发布失败") raise ActiveRecord::Rollback end - end + # end end def end_groups @@ -1170,9 +1154,9 @@ class HomeworkCommonsController < ApplicationController charge_group_ids = @course.charge_group_ids(current_user) end_groups = charge_group_ids & params[:group_ids] if params[:group_ids] - ActiveRecord::Base.transaction do - begin - homeworks.each do |homework| + begin + homeworks.each do |homework| + ActiveRecord::Base.transaction do homework_detail_manual = homework.homework_detail_manual # 分组设置 @@ -1187,7 +1171,7 @@ class HomeworkCommonsController < ApplicationController none_end_settings.update_all(end_time: time) student_works = homework.student_works.where(user_id: course_students.where(course_group_id: none_end_settings. - pluck(:course_group_id)).pluck(:user_id)).has_committed if homework.homework_type == "practice" + pluck(:course_group_id)).pluck(:user_id)).has_committed if homework.homework_type == "practice" homework.end_time = homework.max_group_end_time if homework.end_time > time && homework_detail_manual.try(:comment_status) > 1 @@ -1210,40 +1194,40 @@ class HomeworkCommonsController < ApplicationController student_works.joins(:myshixun).where("myshixuns.status != 1").update_all(late_penalty: homework.late_penalty) if homework.allow_late =begin - student_works.where("work_status != 0").includes(:myshixun).each do |student_work| - unless student_work.myshixun.is_complete? - student_work.update_attributes(work_status: 2, late_penalty: homework.late_penalty) - student_work.late_penalty = homework.late_penalty - end - HomeworksService.new.set_shixun_final_score student_work, student_work.myshixun, homework_detail_manual.answer_open_evaluation, - homework_challenge_settings + student_works.where("work_status != 0").includes(:myshixun).each do |student_work| + unless student_work.myshixun.is_complete? + student_work.update_attributes(work_status: 2, late_penalty: homework.late_penalty) + student_work.late_penalty = homework.late_penalty end + HomeworksService.new.set_shixun_final_score student_work, student_work.myshixun, homework_detail_manual.answer_open_evaluation, + homework_challenge_settings + end - student_works.where("work_status = 0").each do |student_work| - myshixun = Myshixun.where(shixun_id: shixun.id, user_id: student_work.user_id).first - if myshixun.present? - student_work.update_attributes(work_status: (myshixun.is_complete? ? 1 : 2), - late_penalty: myshixun.is_complete? ? 0 : homework.late_penalty, - commit_time: myshixun.created_at, myshixun_id: myshixun.id) - student_work.late_penalty = myshixun.is_complete? ? 0 : homework.late_penalty - HomeworksService.new.set_shixun_final_score student_work, myshixun, homework_detail_manual.answer_open_evaluation, - homework_challenge_settings - end + student_works.where("work_status = 0").each do |student_work| + myshixun = Myshixun.where(shixun_id: shixun.id, user_id: student_work.user_id).first + if myshixun.present? + student_work.update_attributes(work_status: (myshixun.is_complete? ? 1 : 2), + late_penalty: myshixun.is_complete? ? 0 : homework.late_penalty, + commit_time: myshixun.created_at, myshixun_id: myshixun.id) + student_work.late_penalty = myshixun.is_complete? ? 0 : homework.late_penalty + HomeworksService.new.set_shixun_final_score student_work, myshixun, homework_detail_manual.answer_open_evaluation, + homework_challenge_settings end + end =end # 更新所有学生的效率分(重新取homework确保是更新后的) - HomeworkEndUpdateScoreJob.perform_later(homework.id) if !homework.allow_late && homework.end_time <= time end end homework.save! end - normal_status(0, "更新成功") - rescue Exception => e - uid_logger(e.message) - tip_exception("操作失败") - raise ActiveRecord::Rollback + HomeworkEndUpdateScoreJob.perform_later(homework.id) if !homework.allow_late && homework.end_time <= time end + normal_status(0, "更新成功") + rescue Exception => e + uid_logger(e.message) + tip_exception("操作失败") + raise ActiveRecord::Rollback end end diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 952301053..ccd07c811 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -203,26 +203,24 @@ class SubjectsController < ApplicationController stages = @subject.stages.where(id: @subject.stage_shixuns.where(shixun_id: params[:shixun_ids]).pluck(:stage_id)) course_module = @course.course_modules.where(module_type: "shixun_homework").first + homework_ids = [] ActiveRecord::Base.transaction do - begin - # 将实训课程下的所有已发布实训按顺序发送到课堂,同时创建与章节同名的实训作业目录 - stages.each do |stage| - category = CourseSecondCategory.where(name: stage.name, course_id: @course.id, category_type: "shixun_homework").first || - CourseSecondCategory.create!(name: stage.name, course_id: @course.id, category_type: "shixun_homework", - course_module_id: course_module.id, position: course_module.course_second_categories.count + 1) - - stage.shixuns.where(id: params[:shixun_ids], status: 2).each do |shixun| - homework = HomeworksService.new.create_homework shixun, @course, category, current_user - CreateStudentWorkJob.perform_later(homework.id) - end + # 将实训课程下的所有已发布实训按顺序发送到课堂,同时创建与章节同名的实训作业目录 + stages.each do |stage| + category = CourseSecondCategory.where(name: stage.name, course_id: @course.id, category_type: "shixun_homework").first || + CourseSecondCategory.create!(name: stage.name, course_id: @course.id, category_type: "shixun_homework", + course_module_id: course_module.id, position: course_module.course_second_categories.count + 1) + + stage.shixuns.where(id: params[:shixun_ids], status: 2).each do |shixun| + homework = HomeworksService.new.create_homework shixun, @course, category, current_user + homework_ids << homework.id end - rescue Exception => e - uid_logger(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback end end + homework_ids.each do |homework_id| + CreateStudentWorkJob.perform_later(homework_id) + end end def publish diff --git a/db/migrate/20190911020749_migrate_shixun_student_work.rb b/db/migrate/20190911020749_migrate_shixun_student_work.rb new file mode 100644 index 000000000..54474c544 --- /dev/null +++ b/db/migrate/20190911020749_migrate_shixun_student_work.rb @@ -0,0 +1,18 @@ +class MigrateShixunStudentWork < ActiveRecord::Migration[5.2] + def change + homework_commons = HomeworkCommon.where(homework_type: 4).where("created_at > '2019-07-01 00:00:00'") + attrs = %i[homework_common_id user_id created_at updated_at] + StudentWork.bulk_insert(*attrs) do |worker| + homework_commons.each do |homework| + course = homework.course + if course && homework.student_works.count != course.students.count + course.students.each do |student| + next if StudentWork.where(homework_common_id: homework.id, user_id: student.user_id).any? + same_attrs = {user_id: student.user_id} + worker.add same_attrs.merge(homework_common_id: homework.id) + end + end + end + end + end +end From e1cda8ee615d68de7298c83aefea2348de9765d6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 11 Sep 2019 11:08:05 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=BC=82=E6=AD=A5=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E7=9A=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/graduation_tasks_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index fe7511e29..a159cff59 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -326,7 +326,7 @@ class GraduationTasksController < ApplicationController tip_exception("截止时间不能晚于课堂结束时间(#{@course.end_date.end_of_day.strftime("%Y-%m-%d %H:%M")})") if @course.end_date.present? && params[:end_time] > @course.end_date.end_of_day - ActiveRecord::Base.transaction do + # ActiveRecord::Base.transaction do begin tasks = @course.graduation_tasks.where(id: params[:task_ids], status: 0). where("publish_time is null or publish_time > '#{Time.now}'") @@ -350,7 +350,7 @@ class GraduationTasksController < ApplicationController tip_exception(e.message) raise ActiveRecord::Rollback end - end + # end end def end_task From 45db8554e4208b9457a52ee5fc21ff6caadbeadb Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 11 Sep 2019 11:10:44 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E5=AD=A6=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/course.rb | 2 +- app/views/courses/online_learning.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/course.rb b/app/models/course.rb index ce7cde161..ba818449e 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -357,7 +357,7 @@ class Course < ApplicationRecord def my_subject_progress my_challenge_count = Game.joins(:challenge).where(user_id: User.current.id, status: 2, challenges: {shixun_id: shixuns.published_closed}). pluck(:challenge_id).uniq.size - course_challeng_count = course.shixuns.pluck(:challenges_count).sum + course_challeng_count = shixuns.pluck(:challenges_count).sum count = course_challeng_count == 0 ? 0 : ((my_challenge_count.to_f / course_challeng_count).round(2) * 100).to_i end diff --git a/app/views/courses/online_learning.json.jbuilder b/app/views/courses/online_learning.json.jbuilder index 9c87743ee..057ec61cf 100644 --- a/app/views/courses/online_learning.json.jbuilder +++ b/app/views/courses/online_learning.json.jbuilder @@ -8,4 +8,4 @@ json.start_learning @start_learning json.learned @start_learning ? @course.my_subject_progress : 0 -json.last_shixun @start_learning ? last_subject_shixun(@user.id, @subject) : "" \ No newline at end of file +json.last_shixun @start_learning ? last_subject_shixun(@user.id, @course) : "" \ No newline at end of file From 51e4d7bb36b549ed1b85a5425b5d793d9590edb8 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 11 Sep 2019 11:26:57 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E5=AD=98=E5=9C=A8=E8=80=81=E5=B8=88=E5=92=8C?= =?UTF-8?q?=E5=8A=A9=E6=95=99=E8=BA=AB=E4=BB=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index a180130f4..0dc8829da 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -426,7 +426,7 @@ class CoursesController < ApplicationController active_student_exist = CourseMember.where(user_id: user[:user_id], role: 4, course_id: @course.id, is_active: 1).any? is_active = active_student_exist ? 0 : 1 user_id = User.find(user[:user_id]).id - existing_teacher = CourseMember.find_by(course_id: @course.id, user_id: user_id, role: role) + existing_teacher = CourseMember.find_by(course_id: @course.id, user_id: user_id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR]) if existing_teacher.blank? teacher_ids << user_id member = CourseMember.create(course_id: @course.id, graduation_group_id: @graduation_group_id, user_id: user_id, role: role, is_active: is_active)