From 0c29de67551e0f0faf81958f292e30ef5b54eeb4 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 20 Jun 2019 16:33:16 +0800 Subject: [PATCH 0001/1015] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E4=BD=9C=E5=93=81?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=9A=84=E5=AD=A6=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/graduation_tasks/tasks_list.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/graduation_tasks/tasks_list.json.jbuilder b/app/views/graduation_tasks/tasks_list.json.jbuilder index 5f1b8eb40..c36526ceb 100644 --- a/app/views/graduation_tasks/tasks_list.json.jbuilder +++ b/app/views/graduation_tasks/tasks_list.json.jbuilder @@ -33,7 +33,7 @@ if @task.published? || @user_course_identity < Course::STUDENT json.id work.id json.user_id work.user.id json.name work.user.full_name - json.student_id work.user.school_id + json.student_id work.user.student_id json.class_grouping_name work.class_grouping_name if @task.have_grouping? json.grouping_name work.grouping_name From b4089eec1cce887b6b453531f0cc78b192944930 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 20 Jun 2019 17:01:54 +0800 Subject: [PATCH 0002/1015] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E9=A2=98=E5=BA=93?= =?UTF-8?q?=E9=80=89=E7=94=A8=E7=9A=84=E6=97=B6=E5=80=99=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=9D=A5=E6=BA=90=E7=9A=84id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/question_banks_controller.rb | 7 +++++-- app/models/graduation_task.rb | 2 ++ app/models/graduation_topic.rb | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index f814822e8..299224527 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -240,8 +240,9 @@ class QuestionBanksController < ApplicationController ActiveRecord::Base.transaction do new_task = GraduationTask.new new_task.attributes = task.attributes.dup.except("id", "course_id", "user_id", "quotes", "graduation_task_id", - "course_list_id") + "course_list_id", "gtask_bank_id") new_task.course_id = course.id + new_task.gtask_bank_id = task.id new_task.user_id = current_user.id if new_task.save! new_task.create_work_list @@ -264,8 +265,10 @@ class QuestionBanksController < ApplicationController def quote_gtopic_bank topic, course ActiveRecord::Base.transaction do new_topic = GraduationTopic.new - new_topic.attributes = topic.attributes.dup.except("id", "course_id", "user_id", "graduation_topic_id", "course_list_id") + new_topic.attributes = topic.attributes.dup.except("id", "course_id", "user_id", "graduation_topic_id", + "course_list_id", "gtopic_bank_id") new_topic.course_id = course.id + new_topic.gtopic_bank_id = topic.id new_topic.user_id = current_user.id new_topic.save diff --git a/app/models/graduation_task.rb b/app/models/graduation_task.rb index 308c51be4..8d89da693 100644 --- a/app/models/graduation_task.rb +++ b/app/models/graduation_task.rb @@ -19,6 +19,8 @@ class GraduationTask < ApplicationRecord has_many :graduation_works, -> { where("is_delete != 1") } has_many :graduation_work_scores + belongs_to :gtask_bank, optional: true + validates :name, length: { maximum: 60 } validates :description, length: { maximum: 5000 } diff --git a/app/models/graduation_topic.rb b/app/models/graduation_topic.rb index 3aed72d9c..5a2a630e5 100644 --- a/app/models/graduation_topic.rb +++ b/app/models/graduation_topic.rb @@ -10,7 +10,7 @@ class GraduationTopic < ApplicationRecord has_many :journals_for_messages, :as => :jour, :dependent => :destroy # 题库 - + belongs_to :gtopic_bank, optional: true scope :search_by_name, ->(name) { where("graduation_topics.name LIKE ?", "%#{name}%")} scope :search_by_status, ->(status) {where(status: status)} From ba08f9adb137c39858166dd75ac16dbbb19c2984 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 20 Jun 2019 17:22:14 +0800 Subject: [PATCH 0003/1015] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E4=BD=9C=E5=93=81=E5=88=97=E8=A1=A8=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 2 +- app/models/graduation_work.rb | 2 +- app/views/graduation_tasks/tasks_list.json.jbuilder | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index df23b6b25..66682e30f 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -27,7 +27,7 @@ class CoursesController < ApplicationController before_action :teacher_allowed, only: [:update, :destroy, :settings, :search_teacher_candidate, :transfer_to_course_group, :delete_from_course, :search_users, :add_students_by_search, :get_historical_courses, :add_teacher_popup, :add_teacher] - before_action :admin_allowed, only: [:set_invite_code_halt, :set_public_or_private, + before_action :admin_allowed, only: [:set_invite_code_halt, :set_public_or_private, :join_graduation_group, :set_course_group, :change_course_admin, :change_course_teacher, :delete_course_teacher, :teacher_application_review, :create_group_by_importing_file] before_action :teacher_or_admin_allowed, only: [:graduation_group_list, :create_graduation_group, :join_graduation_group, diff --git a/app/models/graduation_work.rb b/app/models/graduation_work.rb index 11255ce4e..a99a18b2a 100644 --- a/app/models/graduation_work.rb +++ b/app/models/graduation_work.rb @@ -53,7 +53,7 @@ class GraduationWork < ApplicationRecord # 分班名 def class_grouping_name - CourseMember.find_by(user_id: self.user_id, course_id: self.course_id).try(:course_group).try(:name) || '未分班' + CourseMember.find_by(user_id: self.user_id, course_id: self.course_id, role: 4).try(:course_group).try(:name) || '未分班' end # 分组名 diff --git a/app/views/graduation_tasks/tasks_list.json.jbuilder b/app/views/graduation_tasks/tasks_list.json.jbuilder index c36526ceb..fe7ffddc4 100644 --- a/app/views/graduation_tasks/tasks_list.json.jbuilder +++ b/app/views/graduation_tasks/tasks_list.json.jbuilder @@ -32,7 +32,7 @@ if @task.published? || @user_course_identity < Course::STUDENT json.array! @work_list do |work| json.id work.id json.user_id work.user.id - json.name work.user.full_name + json.name work.user.real_name json.student_id work.user.student_id json.class_grouping_name work.class_grouping_name if @task.have_grouping? From c32532cc8298f379c881e9b2efb8cc52bcf236a2 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 20 Jun 2019 17:35:18 +0800 Subject: [PATCH 0004/1015] fix message move issue --- app/controllers/messages_controller.rb | 10 ++-------- app/models/message.rb | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 8e340da73..98f453424 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -170,15 +170,9 @@ class MessagesController < ApplicationController def bulk_move # 课堂的目录之间移动,有子栏目的才显示此项 - return normal_status(403) unless current_user.teacher_of_course?(@board.course) + return normal_status(403) unless current_user.teacher_of_course?(@board.course) - begin - Message.bulk_move_to_other_board(params[:ids], params[:to_board_id], current_user.id) - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end + Message.bulk_move_to_other_board(params[:ids], params[:to_board_id]) end def bulk_public diff --git a/app/models/message.rb b/app/models/message.rb index ae804e991..26946f6d0 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -47,10 +47,25 @@ class Message < ApplicationRecord end end - def self.bulk_move_to_other_board(message_ids, to_board_id, author_id) - message_ids.each do |id| - message = Message.find id - message.update_attributes(board_id: to_board_id, author_id: author_id) if message.parent_id.nil? # TODO 暂时只支持跟节点移动 + def self.bulk_move_to_other_board(message_ids, to_board_id) + to_board = Board.find(to_board_id) + + messages = Message.where(id: message_ids, parent_id: nil).select(:id, :board_id).to_a + return if messages.blank? + + from_board = Board.find(messages.first.board_id) + + root_ids = messages.map(&:id) + children = Message.where(parent_id: root_ids).select(:id).to_a + children_ids = children.map(&:id) + second_children = Message.where(parent_id: children_ids).select(:id).to_a + + ids = root_ids.concat(children_ids).concat(second_children.map(&:id)).uniq + + ActiveRecord::Base.transaction do + Message.where(id: ids, board_id: from_board.id).update_all(board_id: to_board.id) + to_board.increment!(:messages_count, ids.size) + from_board.increment!(:messages_count, - ids.size) end end From a6c1a7e155a5083bda570917f9c5d5f50e5c8038 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 20 Jun 2019 17:37:08 +0800 Subject: [PATCH 0005/1015] fix bug --- app/controllers/exercises_controller.rb | 33 ++++++++++++++----------- app/controllers/polls_controller.rb | 32 ++++++++++++------------ app/models/poll.rb | 2 -- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index a18292047..762c12797 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -431,7 +431,9 @@ class ExercisesController < ApplicationController ActiveRecord::Base.transaction do begin error_count = 0 # 判断循环里是否有已发布/已截止的,且时间更改了的分班。 - course_group_ids = @course.teacher_course_group_ids(current_user.id) #当前老师的班级id数组 + # course_group_ids = @course.teacher_course_group_ids(current_user.id) #当前老师的班级id数组 + course_group_ids = @course.charge_group_ids(current_user) #当前老师的班级id数组 + exercise_status = @exercise.get_exercise_status(current_user.id) if exercise_status == 1 && (course_group_ids - [0]).count > 0 # 试卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按试卷默认的来处理 @@ -695,13 +697,15 @@ class ExercisesController < ApplicationController if ex_status == 1 #如果试卷存在已发布的,或者是已截止的,那么则直接跳过 g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数,那么试卷的统一设置需修改 if g_course - course_groups = @course.teacher_course_groups.get_user_groups(current_user.id) + # course_groups = @course.teacher_course_groups.get_user_groups(current_user.id) + # + # if course_groups.blank? + # user_course_groups = @course.course_groups.present? ? @course.course_groups.pluck(:id) : [] + # else + # user_course_groups = course_groups.pluck(:course_group_id).reject(&:blank?).uniq + # end + user_course_groups = @course.charge_group_ids(current_user) - if course_groups.blank? - user_course_groups = @course.course_groups.present? ? @course.course_groups.pluck(:id) : [] - else - user_course_groups = course_groups.pluck(:course_group_id).reject(&:blank?).uniq - end if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则试卷不用分组,且试卷设定为统一设置,否则则分组设置 exercise.exercise_group_settings.destroy_all @@ -1505,13 +1509,14 @@ class ExercisesController < ApplicationController def get_user_permission_course(exercise_ids,status) exercise_status = status.to_i #传入的试卷发布状态 unpublish_group = [] - g_course_ids = @course.teacher_course_groups.get_user_groups(current_user.id).pluck(:course_group_id).reject(&:blank?).uniq #当前用户有权限的分班 - #用户的班级,理论上用户的班级要大于等于试卷设置的班级 - if g_course_ids.blank? || g_course_ids.include?(0) - user_groups_id = @course.course_groups.pluck(:id) - else - user_groups_id = g_course_ids - end + # g_course_ids = @course.teacher_course_groups.get_user_groups(current_user.id).pluck(:course_group_id).reject(&:blank?).uniq #当前用户有权限的分班 + # #用户的班级,理论上用户的班级要大于等于试卷设置的班级 + # if g_course_ids.blank? || g_course_ids.include?(0) + # user_groups_id = @course.course_groups.pluck(:id) + # else + # user_groups_id = g_course_ids + # end + user_groups_id = @course.charge_group_ids(current_user) exercises_all = Exercise.where(id:exercise_ids) exercises_all.each do |exercise| if exercise.present? diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 751b725e6..38fa973b5 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -43,7 +43,7 @@ class PollsController < ApplicationController # polls的不同用户群体的显示 if @user_course_identity < Course::STUDENT # @is_teacher_or 1为老师/管理员/助教 @is_teacher_or = 1 - @teacher_groups_ids = @course.teacher_course_groups.get_user_groups(current_user.id).pluck(:course_group_id).reject(&:blank?) + @teacher_groups_ids = @course.charge_group_ids(current_user) @polls = @polls_all #老师能看到全部的问卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同) elsif @user_course_identity == Course::STUDENT # 2为课堂成员,能看到统一设置的和自己班级的 @is_teacher_or = 2 @@ -254,12 +254,12 @@ class PollsController < ApplicationController if pl_status == 1 #如果问卷存在已发布的,或者是已截止的,那么则直接跳过 g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数,那么poll的统一设置需修改 if g_course - course_groups = @course.teacher_course_groups.get_user_groups(current_user.id) - if course_groups.blank? - user_course_groups = @course.course_groups.present? ? @course.course_groups.pluck(:id) : [] - else - user_course_groups = course_groups.pluck(:course_group_id) - end + user_course_groups = @course.charge_group_ids(current_user) + # if course_groups.blank? + # user_course_groups = @course.course_groups.present? ? @course.course_groups.pluck(:id) : [] + # else + # user_course_groups = course_groups.pluck(:course_group_id) + # end if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则问卷不用分组,且问卷设定为统一设置,否则则分组设置 poll.poll_group_settings.destroy_all poll_unified = true @@ -673,7 +673,7 @@ class PollsController < ApplicationController @user_published_setting = @poll.poll_group_settings.find_in_poll_group("course_group_id",@being_setting_course_ids) poll_ids = [@poll.id] @poll_publish_count = get_user_permission_course(poll_ids,2).count - ## 需添加发送消息的接口,稍后添加 + rescue Exception => e uid_logger_error(e.message) tip_exception("页面调用失败!") @@ -688,7 +688,7 @@ class PollsController < ApplicationController begin error_count = 0 # 判断循环里是否有已发布/已截止的,且时间更改了的分班。 - course_group_ids = @course.teacher_course_group_ids(current_user.id) #当前老师的班级id数组 + course_group_ids = @course.charge_group_ids(current_user) #当前老师的班级id数组 poll_status = @poll.get_poll_status(current_user.id) if poll_status == 1 && (course_group_ids - [0]).count > 0 # 问卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按poll默认的来处理 @@ -951,7 +951,6 @@ class PollsController < ApplicationController def poll_lists ActiveRecord::Base.transaction do begin - logger.info("########___________@course.teacher_course_groups)________________####################{@course.teacher_course_groups.where(user_id:current_user.id).pluck(:course_group_id)}") poll_ids = [@poll.id] @poll_list_status = @poll.get_poll_status(current_user.id) @poll_publish_count = get_user_permission_course(poll_ids,2).count @@ -1213,12 +1212,13 @@ class PollsController < ApplicationController def get_user_permission_course(poll_ids,status) #获取用户权限范围内的已发布/未发布 poll_status = status.to_i unpublish_group = [] - g_course_ids = @course.teacher_course_groups.get_user_groups(current_user.id).pluck(:course_group_id).reject(&:blank?).uniq - if g_course_ids.blank? || g_course_ids.include?(0) #当前用户的分班权限为空,即具体全部的分班权限 - user_groups_id = @course.course_groups.pluck(:id) - else - user_groups_id = g_course_ids - end + # g_course_ids = @course.teacher_course_groups.get_user_groups(current_user.id).pluck(:course_group_id).reject(&:blank?).uniq + # if g_course_ids.blank? || g_course_ids.include?(0) #当前用户的分班权限为空,即具体全部的分班权限 + # user_groups_id = @course.course_groups.pluck(:id) + # else + # user_groups_id = g_course_ids + # end + user_groups_id = @course.charge_group_ids(current_user) all_polls = Poll.where(id:poll_ids) all_polls.each do |poll| if poll.present? diff --git a/app/models/poll.rb b/app/models/poll.rb index 7ebcceafd..fd9093fcc 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -54,7 +54,6 @@ class Poll < ApplicationRecord def all_poll_users(user_id) poll_users = self.poll_users group_ids = poll_published_ids(user_id) - logger.info("##########_________group_ids______#########################{group_ids}") if group_ids.present? poll_users = poll_users.where(user_id: course.students.where(course_group_id: group_ids).pluck(:user_id)) end @@ -64,7 +63,6 @@ class Poll < ApplicationRecord #当前用户已发布的班级id和试卷分组已发布的班级id的交集 def poll_published_ids(user_id) current_user_groups = course.teacher_course_group_ids(user_id) - logger.info("##########_________current_user_groups______#########################{current_user_groups}") if unified_setting if course.none_group_count > 0 #有未分班的,则发布到未发布 un_group_ids = [0] From 7ffd21858a9c136294f5099a54e0bd9f560170c4 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 20 Jun 2019 18:41:23 +0800 Subject: [PATCH 0006/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index df23b6b25..4a34d9039 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -50,9 +50,11 @@ class CoursesController < ApplicationController order_str = @order != "course_members_count" && @order != "created_at" ? "updated_at" : @order if @order == "all" - # @course = Course.where(is_delete: 0, is_hidden: 0).find_by_sql("select c.name, c.id, s.name, u.last_name from - # courses c, users u, user_extensions ue, schools s where c.is_delete=0 and c.tea_id=u.id and - # u.id=ue.user_id and ue.school_id=s.id limit 10;") + # @course = Course.where(is_delete: 0, is_hidden: 0).select("select c.name, c.id, s.name, u.login, ifnull(concat(u.lastname,u.firstname), + # u.login), s.name from courses c, users u, user_extensions ue, schools s where c.is_delete=0 and + # c.tea_id=u.id and u.id=ue.user_id and ue.school_id=s.id") + + # @courses = Course.where(is_delete: 0, is_hidden: 0).includes([teacher: :user_extension], :school) @courses = Course.where(is_delete: 0, is_hidden: 0).select("courses.id, courses.tea_id, courses.name, courses.exercises_count, courses.polls_count, courses.is_public, courses.is_end, courses.visits, courses.course_members_count,courses.homework_commons_count,(SELECT MAX(created_at) From 82edc4c9a9d18a5939fa1f4ffbc0900f504ff076 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 20 Jun 2019 18:45:01 +0800 Subject: [PATCH 0007/1015] configuration --- config/application.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/application.rb b/config/application.rb index 8f1d3aebf..baa0011f2 100644 --- a/config/application.rb +++ b/config/application.rb @@ -17,7 +17,7 @@ module Educoderplus # the framework and any gems in your application. # # - config.educoder = config_for(:configuration) + # config.educoder = config_for(:configuration) config.active_record.default_timezone = :local config.time_zone = 'Beijing' From 4519abbce477d934b88aa795eaad657c61ef50e6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 20 Jun 2019 18:50:36 +0800 Subject: [PATCH 0008/1015] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E4=BD=9C=E5=93=81=E5=88=97=E8=A1=A8=E5=8F=8C=E9=87=8D=E8=BA=AB?= =?UTF-8?q?=E4=BB=BD=E7=9A=84=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/graduation_tasks_controller.rb | 4 ++-- app/models/course.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index d95716c9b..435dbd4ed 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -66,7 +66,7 @@ class GraduationTasksController < ApplicationController @course.teacher_group_user_ids(current_user.id) else course_group_id = @course.course_member(current_user.id).course_group_id - @course.course_members.where(course_group_id: course_group_id).pluck(:user_id) + @course.students.where(course_group_id: course_group_id).pluck(:user_id) end @work_list = @task.graduation_works.where(user_id: user_ids).includes(user: [:user_extension]) @@ -89,7 +89,7 @@ class GraduationTasksController < ApplicationController # 分班情况 unless params[:course_group].blank? - group_user_ids = @course.course_members.where(course_group_id: params[:course_group]).pluck(:user_id) + group_user_ids = @course.students.where(course_group_id: params[:course_group]).pluck(:user_id) # 有分组只可能是老师身份查看列表 @work_list = @work_list.where(user_id: group_user_ids) end diff --git a/app/models/course.rb b/app/models/course.rb index dd2248d7c..30460b49a 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -139,9 +139,9 @@ class Course < ApplicationRecord def teacher_group_user_ids user_id teachers = teacher_course_groups.where(user_id: user_id) if teachers.exists? - course_members.where(course_group_id: teachers.pluck(:course_group_id)).pluck(:user_id) + students.where(course_group_id: teachers.pluck(:course_group_id)).pluck(:user_id) else - course_members.where(role: 4).pluck(:user_id) + students.pluck(:user_id) end end From 26e6ecba6dc09350e78263d5d3769147421cd5a9 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 20 Jun 2019 18:53:56 +0800 Subject: [PATCH 0009/1015] fix bug --- app/controllers/exercises_controller.rb | 17 +++++++++-------- app/controllers/polls_controller.rb | 2 +- app/models/course.rb | 2 +- app/models/exercise.rb | 2 +- app/models/poll.rb | 2 +- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 762c12797..2239f570d 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -436,7 +436,7 @@ class ExercisesController < ApplicationController exercise_status = @exercise.get_exercise_status(current_user.id) - if exercise_status == 1 && (course_group_ids - [0]).count > 0 # 试卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按试卷默认的来处理 + if exercise_status == 1 && course_group_ids.size > 0 # 试卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按试卷默认的来处理 unified_setting = params[:unified_setting] else unified_setting = @exercise.unified_setting @@ -450,7 +450,7 @@ class ExercisesController < ApplicationController answer_open = params[:answer_open] ? true : false #答案是否公开 # 统一设置或者分班为0,则更新试卷,并删除试卷分组 - if unified_setting || (course_group_ids.count == 0) + if unified_setting || (course_group_ids.size == 0) params_publish_time = params[:publish_time].blank? ? nil : params[:publish_time].to_time params_end_time = nil if params[:end_time].blank? @@ -798,12 +798,13 @@ class ExercisesController < ApplicationController if exercise_status == 2 #跳过已截止的或未发布的 g_course = params[:group_ids] if g_course.present? - user_course_groups= @course.teacher_course_groups.get_user_groups(current_user.id) - if user_course_groups.present? - teacher_course_group_ids = user_course_groups.pluck(:course_group_id) - else - teacher_course_group_ids = @course.course_groups.pluck(:id) - end + # user_course_groups= @course.teacher_course_groups.get_user_groups(current_user.id) + # if user_course_groups.present? + # teacher_course_group_ids = user_course_groups.pluck(:course_group_id) + # else + # teacher_course_group_ids = @course.course_groups.pluck(:id) + # end + teacher_course_group_ids = @course.charge_group_ids(current_user) if g_course.map(&:to_i).sort == teacher_course_group_ids.sort #开始为统一设置 exercise.exercise_group_settings.destroy_all new_ex_status = set_exercise_status(exercise.publish_time,Time.now) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 38fa973b5..ae93357cc 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -691,7 +691,7 @@ class PollsController < ApplicationController course_group_ids = @course.charge_group_ids(current_user) #当前老师的班级id数组 poll_status = @poll.get_poll_status(current_user.id) - if poll_status == 1 && (course_group_ids - [0]).count > 0 # 问卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按poll默认的来处理 + if poll_status == 1 && course_group_ids.size > 0 # 问卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按poll默认的来处理 unified_setting = params[:unified_setting] else unified_setting = @poll.unified_setting diff --git a/app/models/course.rb b/app/models/course.rb index dd2248d7c..dec8c1b50 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -121,7 +121,7 @@ class Course < ApplicationRecord end #当前老师的班级id - def teacher_course_group_ids(user_id) + def teacher_course_ids(user_id) course_teacher_member = teacher_course_groups.get_user_groups(user_id) #获取当前老师的分班 if course_teacher_member.blank? if none_group_count > 0 #有未分班的,则发布到未发布分班 diff --git a/app/models/exercise.rb b/app/models/exercise.rb index e2623c692..b3feec12c 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -66,7 +66,7 @@ class Exercise < ApplicationRecord #当前用户已发布的班级id和试卷分组已发布的班级id的交集 def common_published_ids(user_id) - current_user_groups = course.teacher_course_group_ids(user_id) + current_user_groups = course.teacher_course_ids(user_id) if unified_setting if course.none_group_count > 0 #有未分班的,则发布到未发布分班 un_group_ids = [0] diff --git a/app/models/poll.rb b/app/models/poll.rb index fd9093fcc..b498eda4e 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -62,7 +62,7 @@ class Poll < ApplicationRecord #当前用户已发布的班级id和试卷分组已发布的班级id的交集 def poll_published_ids(user_id) - current_user_groups = course.teacher_course_group_ids(user_id) + current_user_groups = course.teacher_course_ids(user_id) if unified_setting if course.none_group_count > 0 #有未分班的,则发布到未发布 un_group_ids = [0] From 45a0f6cf2c3d42793b01d2bf99467d687c2ac777 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 20 Jun 2019 19:04:05 +0800 Subject: [PATCH 0010/1015] modify school list apu --- app/controllers/schools_controller.rb | 10 +++++++--- app/views/schools/school_list.json.jbuilder | 1 - .../modules/Courses/coursesPublic/form/SchoolSelect.js | 4 ++-- public/react/src/modules/Courses/new/CoursesNew.js | 2 +- 4 files changed, 10 insertions(+), 7 deletions(-) delete mode 100644 app/views/schools/school_list.json.jbuilder diff --git a/app/controllers/schools_controller.rb b/app/controllers/schools_controller.rb index 1551091aa..11932be42 100644 --- a/app/controllers/schools_controller.rb +++ b/app/controllers/schools_controller.rb @@ -1,8 +1,12 @@ class SchoolsController < ApplicationController + def school_list + schools = School.all + search = params[:search].to_s.strip + if search.present? + schools = schools.where('name Like ?', "%#{search}%") + end - def school_list - q = params[:search] ? params[:search].strip : "" - @schools = School.where("name like ?", "%#{q}%").pluck(:name) + render_ok(school_names: schools.pluck(:name)) end end diff --git a/app/views/schools/school_list.json.jbuilder b/app/views/schools/school_list.json.jbuilder deleted file mode 100644 index 1e2c89897..000000000 --- a/app/views/schools/school_list.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.shools_name @schools \ No newline at end of file diff --git a/public/react/src/modules/Courses/coursesPublic/form/SchoolSelect.js b/public/react/src/modules/Courses/coursesPublic/form/SchoolSelect.js index db62c50b6..e1a9062e3 100644 --- a/public/react/src/modules/Courses/coursesPublic/form/SchoolSelect.js +++ b/public/react/src/modules/Courses/coursesPublic/form/SchoolSelect.js @@ -34,9 +34,9 @@ class SchoolSelect extends Component{ } }) .then((response) => { - if (response.data.shools_name) { + if (response.data.school_names) { if (currentValue === value) { - callback(response.data.shools_name); + callback(response.data.school_names); } } }) diff --git a/public/react/src/modules/Courses/new/CoursesNew.js b/public/react/src/modules/Courses/new/CoursesNew.js index d8fb83974..6c0158f21 100644 --- a/public/react/src/modules/Courses/new/CoursesNew.js +++ b/public/react/src/modules/Courses/new/CoursesNew.js @@ -314,7 +314,7 @@ class CoursesNew extends Component { } }).then((result)=>{ this.setState({ - searchlistscholl:result.data.shools_name, + searchlistscholl:result.data.school_names, scholl:value }) this.props.form.setFieldsValue({ From a1aa51353c3ce9c9f0d76c1743226805767b2093 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 20 Jun 2019 19:44:06 +0800 Subject: [PATCH 0011/1015] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E6=9D=83=E9=99=90?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E3=80=81=E4=BD=9C=E4=B8=9A=E5=92=8C=E6=AF=95?= =?UTF-8?q?=E8=AE=BE=E7=9A=84=E7=A7=81=E6=9C=89=E5=8F=82=E6=95=B0=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 6 +++--- app/views/courses/top_banner.json.jbuilder | 4 ++-- app/views/graduation_tasks/index.json.jbuilder | 4 ++-- app/views/graduation_topics/_topics.json.jbuilder | 4 ++-- app/views/homework_commons/index.json.jbuilder | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 65f8f5ff9..2c37285fa 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -274,7 +274,7 @@ class CoursesController < ApplicationController end end - @is_admin = current_user.creator_of_course? @course + @is_admin = @user_course_identity < Course::PROFESSOR @applications= CourseMessage.unhandled_join_course_requests_by_course(@course) @@ -897,8 +897,8 @@ class CoursesController < ApplicationController def top_banner @user = current_user - @is_teacher = @user.teacher_of_course?(@course) - @is_student = @course.course_members.where(user_id: @user.id, role: 4, is_active: 1).present? + @is_teacher = @user_course_identity < Course::STUDENT + @is_student = @user_course_identity == Course::STUDENT @course.increment!(:visits) end diff --git a/app/views/courses/top_banner.json.jbuilder b/app/views/courses/top_banner.json.jbuilder index ddf860709..c0a1ff956 100644 --- a/app/views/courses/top_banner.json.jbuilder +++ b/app/views/courses/top_banner.json.jbuilder @@ -11,7 +11,7 @@ json.course_end @course.is_end json.deadline course_end_date @course.end_date json.educoder_teacher @user.is_teacher? #json.is_student @is_student -json.is_admin @user.creator_of_course?(@course) +json.is_admin @user_course_identity < Course::PROFESSOR json.is_public @course.is_public == 1 json.code_halt @course.invite_code_halt == 1 json.invite_code @course.invite_code_halt == 0 ? @course.generate_invite_code : "" @@ -20,7 +20,7 @@ json.switch_to_teacher switch_teacher_role(@is_student, @course, @user) json.switch_to_assistant switch_assistant_role(@is_student, @course, @user) #json.join_course !@user.member_of_course?(@course) #json.copy_course !@user.member_of_course?(@course) && @user.is_teacher? -json.course_identity @user.course_identity(@course) +json.course_identity @user_course_identity if @course.is_end == 0 json.days_remaining (@course.end_date.to_date - Time.now.to_date).to_i end diff --git a/app/views/graduation_tasks/index.json.jbuilder b/app/views/graduation_tasks/index.json.jbuilder index 157bde672..80780b209 100644 --- a/app/views/graduation_tasks/index.json.jbuilder +++ b/app/views/graduation_tasks/index.json.jbuilder @@ -7,10 +7,10 @@ json.unpublished_count @all_count - @published_count json.task_count @task_count json.tasks @tasks.each do |task| - task_private = @identity > Course::STUDENT && !task.is_public + # task_private = @identity > Course::STUDENT && !task.is_public json.task_id task.id json.name task.name - json.private_icon task_private + json.private_icon !task.is_public json.task_status task.status #6.12 -hs json.status task_curr_status(task, @course)[:status] json.status_time task_curr_status(task, @course)[:time] diff --git a/app/views/graduation_topics/_topics.json.jbuilder b/app/views/graduation_topics/_topics.json.jbuilder index 7a37b666b..271531f85 100644 --- a/app/views/graduation_topics/_topics.json.jbuilder +++ b/app/views/graduation_topics/_topics.json.jbuilder @@ -1,6 +1,6 @@ json.array! topics do |topic| - task_private = course_identity > Course::STUDENT && !topic.is_public - json.private_icon task_private + # task_private = course_identity > Course::STUDENT && !topic.is_public + json.private_icon !topic.is_public json.(topic, :id, :name, :status) json.author topic.teacher.full_name json.user_topic_status topic.user_status(current_user) diff --git a/app/views/homework_commons/index.json.jbuilder b/app/views/homework_commons/index.json.jbuilder index 18e601871..c9074cc2b 100644 --- a/app/views/homework_commons/index.json.jbuilder +++ b/app/views/homework_commons/index.json.jbuilder @@ -12,10 +12,10 @@ json.category_id @category.try(:id) json.category_name @category.try(:name) json.homeworks @homework_commons.each do |homework| - homework_private = (@user_course_identity > Course::STUDENT) && !homework.is_public + # homework_private = (@user_course_identity > Course::STUDENT) && !homework.is_public json.homework_id homework.id json.name homework.name - json.private_icon homework_private + json.private_icon !homework.is_public json.status homework_curr_status(homework, @user_course_identity, @course, @member, @member&.teacher_course_groups)[:status] json.status_time homework_curr_status(homework, @user_course_identity, @course, @member, @member&.teacher_course_groups)[:time] json.time_status homework_curr_status(homework, @user_course_identity, @course, @member, @member&.teacher_course_groups)[:time_status] From 61f491bdde789056d5cab606300a4b8467126e67 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 20 Jun 2019 19:46:35 +0800 Subject: [PATCH 0012/1015] fix bug --- app/controllers/exercise_answers_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/exercise_answers_controller.rb b/app/controllers/exercise_answers_controller.rb index 68ba83276..c709980f9 100644 --- a/app/controllers/exercise_answers_controller.rb +++ b/app/controllers/exercise_answers_controller.rb @@ -8,7 +8,7 @@ class ExerciseAnswersController < ApplicationController q_type = @exercise_question.question_type #试卷的类型 choice_id = params[:exercise_choice_id].present? ? params[:exercise_choice_id] : "" answer_text = params[:answer_text].present? ? params[:answer_text] : "" #为字符串 - if q_type < 4 && choice_id.blank? + if q_type < 4 && (q_type != 1) && choice_id.blank? normal_status(-1,"请选择序号") else ea = @exercise_question.exercise_answers.search_answer_users("user_id",current_user.id) #试卷的当前用户的答案 From 010d2f4049ada3e9abeee1f20427c31503a348aa Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 20 Jun 2019 19:52:12 +0800 Subject: [PATCH 0013/1015] =?UTF-8?q?=E9=80=89=E9=A2=98=E6=8B=92=E7=BB=9D?= =?UTF-8?q?=E5=90=8E=E9=80=89=E9=A2=98=E7=8A=B6=E6=80=81=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/graduation_topic.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/graduation_topic.rb b/app/models/graduation_topic.rb index 5a2a630e5..294bfa785 100644 --- a/app/models/graduation_topic.rb +++ b/app/models/graduation_topic.rb @@ -50,10 +50,10 @@ class GraduationTopic < ApplicationRecord def student_graduation_topic_status sgt = self.student_graduation_topics status = - if sgt.is_accepting.count == 0 - 2 - elsif sgt.is_refused.count == self.student_graduation_topics.size + if sgt.where(status: [0, 1]).count.zero? 0 + elsif sgt.is_accepting.count.zero? + 2 else 1 end From 5b3752275c33aa6ae3227dc12440c98caf904b45 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 20 Jun 2019 20:17:26 +0800 Subject: [PATCH 0014/1015] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 11 ++++++----- app/models/course.rb | 2 +- app/views/courses/index.json.jbuilder | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 65f8f5ff9..e012f34ca 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -54,12 +54,12 @@ class CoursesController < ApplicationController # u.login), s.name from courses c, users u, user_extensions ue, schools s where c.is_delete=0 and # c.tea_id=u.id and u.id=ue.user_id and ue.school_id=s.id") - # @courses = Course.where(is_delete: 0, is_hidden: 0).includes([teacher: :user_extension], :school) + @courses = Course.where(is_delete: 0, is_hidden: 0).includes(:course_modules, :course_members, teacher: [user_extension: :school]) - @courses = Course.where(is_delete: 0, is_hidden: 0).select("courses.id, courses.tea_id, courses.name, courses.exercises_count, courses.polls_count, - courses.is_public, courses.is_end, courses.visits, courses.course_members_count,courses.homework_commons_count,(SELECT MAX(created_at) - FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a") - .order("courses.id = 1309 desc, a desc") + # @courses = Course.where(is_delete: 0, is_hidden: 0).select("courses.id, courses.tea_id, courses.name, courses.exercises_count, courses.polls_count, + # courses.is_public, courses.is_end, courses.visits, courses.course_members_count,courses.homework_commons_count,(SELECT MAX(created_at) + # FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a") + # .order("courses.id = 1309 desc, a desc") elsif @order == "mine" @courses = Course.joins(:course_members) .where("is_delete = 0 AND is_hidden = 0 AND course_members.user_id = ?", @user.id) @@ -103,6 +103,7 @@ class CoursesController < ApplicationController # GET /courses/1 # GET /courses/1.json def show + # render :json => {first_category_url: module_url(course.course_modules.where.not(module_type: "activity").where(hidden: 0).first, course)} end # GET /courses/new diff --git a/app/models/course.rb b/app/models/course.rb index dd2248d7c..1ea9e782e 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -7,7 +7,7 @@ class Course < ApplicationRecord has_many :course_infos, dependent: :destroy # 课堂左侧导航栏的模块 - has_many :course_modules, dependent: :destroy + has_many :course_modules, -> {where hidden: 0}, dependent: :destroy has_many :board_course_modules, -> { board_module }, class_name: "CourseModule" has_many :attachment_course_modules, -> { attachment_module }, class_name: "CourseModule" has_many :common_course_modules, -> { common_homework_module }, class_name: "CourseModule" diff --git a/app/views/courses/index.json.jbuilder b/app/views/courses/index.json.jbuilder index ec9ebfc3f..23e8715af 100644 --- a/app/views/courses/index.json.jbuilder +++ b/app/views/courses/index.json.jbuilder @@ -10,9 +10,9 @@ json.courses do json.tasks_count get_tasks_count course json.visits course.visits json.is_public course.is_public - json.is_accessible @user.present? ? @user.member_of_course?(course) || @user.creator_of_course?(course) : course.is_public == 1 + json.is_accessible course.is_public? ? true : (course.tea_id == @user.id || @user.course_identity(course) < 5) json.is_end course.is_end - json.first_category_url module_url(course.course_modules.where.not(module_type: "activity").where(hidden: 0).order(position: :desc).first, course) + json.first_category_url module_url(course.course_modules.first, course) end end json.courses_count @courses_count From 22409b564ffe4c6294f01995cfea81ce3ae8c718 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 20 Jun 2019 20:19:07 +0800 Subject: [PATCH 0015/1015] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190309085449_migrate_course_members.rb | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/db/migrate/20190309085449_migrate_course_members.rb b/db/migrate/20190309085449_migrate_course_members.rb index ef8741bfb..8e828610e 100644 --- a/db/migrate/20190309085449_migrate_course_members.rb +++ b/db/migrate/20190309085449_migrate_course_members.rb @@ -1,27 +1,27 @@ class MigrateCourseMembers < ActiveRecord::Migration[5.2] def change - add_column :course_groups, :position, :integer, default: 0 - - Course.find_each do |course| - position = 1 - course.course_groups.reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").find_each do |group| - group.update_attribute(:position, position) - position += 1 - end - end - - - add_column :course_groups, :course_members_count, :integer, default: 0 - - CourseGroup.find_each do |g| - CourseGroup.reset_counters g.id, :course_members - end + # add_column :course_groups, :position, :integer, default: 0 + # + # Course.find_each do |course| + # position = 1 + # course.course_groups.reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").find_each do |group| + # group.update_attribute(:position, position) + # position += 1 + # end + # end + # + # + # add_column :course_groups, :course_members_count, :integer, default: 0 + # + # CourseGroup.find_each do |g| + # CourseGroup.reset_counters g.id, :course_members + # end ActiveRecord::Base.transaction do begin Member.where("course_id != -1").find_each do |member| if member.course && member.user - puts(member.course_id) + puts(member.id) member.member_roles.each do |role| course_member_role = role.role_id == 3 ? 1 : (role.role_id == 9 ? 2 : (role.role_id == 7 ? 3 : 4)) member_group_id = role.role_id == 10 ? member.course_group_id : 0 From 363f5c67b97a0522874e86350ca1240345caeba2 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 20 Jun 2019 20:23:42 +0800 Subject: [PATCH 0016/1015] fix bug --- .../exercise_answers_controller.rb | 23 +++++++++++++++++++ app/helpers/exercises_helper.rb | 8 +++++-- app/helpers/polls_helper.rb | 14 +++++++---- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/app/controllers/exercise_answers_controller.rb b/app/controllers/exercise_answers_controller.rb index c709980f9..81f117daf 100644 --- a/app/controllers/exercise_answers_controller.rb +++ b/app/controllers/exercise_answers_controller.rb @@ -1,6 +1,8 @@ class ExerciseAnswersController < ApplicationController before_action :require_login before_action :get_exercise_question + before_action :commit_exercise_time + include ExercisesHelper def create #每一次答案的点击,请求一次,实训题不在这里回答 ActiveRecord::Base.transaction do @@ -31,6 +33,7 @@ class ExerciseAnswersController < ApplicationController end elsif q_type == 1 #多选题的 choice_ids = params[:exercise_choice_id].present? ? params[:exercise_choice_id] : [] + ea_ids = ea.pluck(:exercise_choice_id) common_answer_ids = choice_ids & ea_ids #已经存在的试卷选项id new_ids = choice_ids - common_answer_ids # 新增的id @@ -113,4 +116,24 @@ class ExerciseAnswersController < ApplicationController end end + def commit_exercise_time + @exercise_user_current = @exercise.exercise_users.exercise_commit_users(current_user.id).first #查找当前用户是否有过答题 + if @exercise.exercise_status == 3 || (@exercise.time > 0 && ((@exercise_user_current&.start_at + (@exercise.time.to_i + 1).minutes) < Time.now)) + #当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制 + objective_score = calculate_student_score(@exercise,current_user)[:total_score] + subjective_score = @exercise_user_current&.subjective_score < 0.0 ? 0.0 : @exercise_user_current&.subjective_score + total_score = objective_score + subjective_score + commit_option = { + :status => 1, + :commit_status => 1, + :end_at => Time.now, + :objective_score => objective_score, + :score => total_score, + :subjective_score => subjective_score + } + @exercise_user_current.update_attributes(commit_option) + normal_status(-1,"考试时间已到,已交卷成功!") + end + end + end diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 4f4c015eb..95ec0ac24 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -478,8 +478,12 @@ module ExercisesHelper ex_user_end_at = ex_user.end_at course_member = course.students.course_find_by_ids("user_id",ex_user.user.id) current_user_group_id = course_member.first.course_group_id if course_member.present? - course_group = course.course_groups.by_group_ids(current_user_group_id) - current_user_group_name = course_group.first.name if course_group.present? + if current_user_group_id == 0 + current_user_group_name = "未分班" + else + course_group = course.course_groups.by_group_ids(current_user_group_id) + current_user_group_name = course_group.first.name if course_group.present? + end teacher_review = ex_user.subjective_score < 0.0 ? false : true if ex_user_exercise_status != 3 || commit_status != 1 #试卷未截止或用户未提交 # if (user_status != 0 && ex_user_exercise_status != 3)|| commit_status == 0 #不为教师,且试卷未截止;当前用户未提交 不显示分数 diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index 5b4702174..56bbb9b77 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -110,14 +110,20 @@ module PollsHelper poll_user_name = user.nickname end course_member = course_members.find_by(user_id:user.id) - current_user_group_id = course_members.present? ? course_member.course_group_id : nil - course_group = course.course_groups.find_by_id(current_user_group_id) + course_group_id = course_members.present? ? course_member.course_group_id : nil + if course_group_id == 0 + course_group_name = "未分班" + else + course_group = course.course_groups.find_by_id(course_group_id) + course_group_id = course_group&.id + course_group_name = course_group&.name + end { "user_name":poll_user_name, "user_id": user.id, "student_id":user_student_id, - "group_name":course_group.try(:name), - "group_id":course_group.try(:id), + "group_name":course_group_name, + "group_id":course_group_id, "login":user.login } end From a6ec81eac4ac8eef7f61763169304eb93fba5d03 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 20 Jun 2019 20:24:24 +0800 Subject: [PATCH 0017/1015] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190309085449_migrate_course_members.rb | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/db/migrate/20190309085449_migrate_course_members.rb b/db/migrate/20190309085449_migrate_course_members.rb index 8e828610e..1d28eb5d1 100644 --- a/db/migrate/20190309085449_migrate_course_members.rb +++ b/db/migrate/20190309085449_migrate_course_members.rb @@ -1,21 +1,21 @@ class MigrateCourseMembers < ActiveRecord::Migration[5.2] def change - # add_column :course_groups, :position, :integer, default: 0 - # - # Course.find_each do |course| - # position = 1 - # course.course_groups.reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").find_each do |group| - # group.update_attribute(:position, position) - # position += 1 - # end - # end - # - # - # add_column :course_groups, :course_members_count, :integer, default: 0 - # - # CourseGroup.find_each do |g| - # CourseGroup.reset_counters g.id, :course_members - # end + add_column :course_groups, :position, :integer, default: 0 + + Course.find_each do |course| + position = 1 + course.course_groups.reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").find_each do |group| + group.update_attribute(:position, position) + position += 1 + end + end + + + add_column :course_groups, :course_members_count, :integer, default: 0 + + CourseGroup.find_each do |g| + CourseGroup.reset_counters g.id, :course_members + end ActiveRecord::Base.transaction do begin From f3a6f3bbf7326cdaf4e3f9eaff562ebabb4f35ea Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Jun 2019 08:33:13 +0800 Subject: [PATCH 0018/1015] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E9=80=89=E9=A2=98?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=B0=E9=A2=98=E5=BA=93=E6=8A=A5404?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 2 -- app/controllers/graduation_topics_controller.rb | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 7aca31dbc..2b988e89c 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -2,8 +2,6 @@ class CoursesController < ApplicationController include MessagesHelper include ExportHelper - rescue_from ::ActionView::MissingTemplate, with: :missing_template - rescue_from ActiveRecord::RecordNotFound, with: :object_not_found # model validation error rescue_from ActiveRecord::RecordInvalid do |ex| render_error(ex.record.errors.full_messages.join(',')) diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index 6bc3a4c2a..bcc947642 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -3,7 +3,7 @@ class GraduationTopicsController < ApplicationController before_action :find_course before_action :teacher_allowed, only: [:new, :create, :update, :edit, :destroys, :set_public, :refuse_student_topic, :accept_student_topic, :export] - before_action :find_graduation_topic, except: [:index, :create, :new, :set_public, :destroys, :export] + before_action :find_graduation_topic, except: [:index, :create, :new, :set_public, :destroys, :export, :add_to_bank] before_action :find_course_teachers, only: [:new, :edit] before_action :user_course_identity, only: [:index, :show, :show_detail, :show_comment] From 3dbc4814378bcf4388b8ecd834bbde8778acc645 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 08:53:17 +0800 Subject: [PATCH 0019/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190426010412_add_is_invalid_to_student_works_scores.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20190426010412_add_is_invalid_to_student_works_scores.rb b/db/migrate/20190426010412_add_is_invalid_to_student_works_scores.rb index 2d782f924..7b893db6d 100644 --- a/db/migrate/20190426010412_add_is_invalid_to_student_works_scores.rb +++ b/db/migrate/20190426010412_add_is_invalid_to_student_works_scores.rb @@ -1,6 +1,6 @@ class AddIsInvalidToStudentWorksScores < ActiveRecord::Migration[5.2] def change - add_column :student_works_scores, :is_invalid, :boolean, default: false + # add_column :student_works_scores, :is_invalid, :boolean, default: false StudentWorksScore.where("score is not null").order("id desc").find_each do |score| unless score.is_invalid From be653f8a9430c0a0dd93b7e2ddc3497bfcb4853c Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 08:57:50 +0800 Subject: [PATCH 0020/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190426010412_add_is_invalid_to_student_works_scores.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20190426010412_add_is_invalid_to_student_works_scores.rb b/db/migrate/20190426010412_add_is_invalid_to_student_works_scores.rb index 7b893db6d..2d782f924 100644 --- a/db/migrate/20190426010412_add_is_invalid_to_student_works_scores.rb +++ b/db/migrate/20190426010412_add_is_invalid_to_student_works_scores.rb @@ -1,6 +1,6 @@ class AddIsInvalidToStudentWorksScores < ActiveRecord::Migration[5.2] def change - # add_column :student_works_scores, :is_invalid, :boolean, default: false + add_column :student_works_scores, :is_invalid, :boolean, default: false StudentWorksScore.where("score is not null").order("id desc").find_each do |score| unless score.is_invalid From db2b3a4058f0949644e94a67d5bdf9f333de3eb4 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Jun 2019 09:03:44 +0800 Subject: [PATCH 0021/1015] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E9=80=89=E9=A2=98?= =?UTF-8?q?=E5=88=86=E7=8F=AD=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/graduation_topics_controller.rb | 10 ---------- app/views/graduation_topics/show.json.jbuilder | 8 +------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index bcc947642..36f51ce6e 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -45,16 +45,6 @@ class GraduationTopicsController < ApplicationController end ## 分页参数 @current_user = current_user - course_group_ids = @course.course_members.where(user_id: current_user.id, role: [1,2,3]).pluck(:course_group_id).uniq - #6.11 -hs - if course_group_ids.present? - if course_group_ids.include?(0) - course_group_ids = @course.course_groups.pluck(:id) - end - end - - @group_list = CourseGroup.where(id: course_group_ids) - page = params[:page] || 1 limit = params[:limit] || 50 @users_count = @student_graduation_topics.try(:count).to_i diff --git a/app/views/graduation_topics/show.json.jbuilder b/app/views/graduation_topics/show.json.jbuilder index 440dc776e..a75ac5240 100644 --- a/app/views/graduation_topics/show.json.jbuilder +++ b/app/views/graduation_topics/show.json.jbuilder @@ -7,13 +7,7 @@ json.edit_url edit_course_graduation_topic_path(@course, graduation_topic_id: @g json.users_count @users_count json.course_identity @current_user.course_identity(@course) json.user_selected_topic @graduation_topic.user_status(current_user.id) - -json.group_list do - json.array! @group_list do |group| - json.course_group_id group.id - json.group_name group.name - end -end +json.group_list @course.teacher_group(current_user.id) # 列表数据 json.users_list do From ee2838bd9d101a9220031363a70a694dbb83ec61 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 09:10:33 +0800 Subject: [PATCH 0022/1015] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E5=88=86=E7=BB=84?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E8=B0=83=E6=95=B4=E6=9C=80=E5=A4=A7=E5=88=86?= =?UTF-8?q?=E7=BB=84=E4=BA=BA=E6=95=B0=E7=9A=84=E9=BB=98=E8=AE=A4=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190505093440_init_use_index.rb | 6 +++--- db/migrate/20190621010002_change_default_to_max_num.rb | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20190621010002_change_default_to_max_num.rb diff --git a/db/migrate/20190505093440_init_use_index.rb b/db/migrate/20190505093440_init_use_index.rb index d885c3a9d..b7c3101dd 100644 --- a/db/migrate/20190505093440_init_use_index.rb +++ b/db/migrate/20190505093440_init_use_index.rb @@ -2,8 +2,8 @@ class InitUseIndex < ActiveRecord::Migration[5.2] def change remove_index :users, name: :index_users_on_login if index_exists?(:users, :login, name: :index_users_on_login) remove_index :users, name: :index_users_on_mail if index_exists?(:users, :mail, name: :index_users_on_mail) - add_index :users, :login, unique: true - add_index :users, :mail, unique: true - add_index :users, :phone, unique: true + # add_index :users, :login, unique: true + # add_index :users, :mail, unique: true + # add_index :users, :phone, unique: true end end diff --git a/db/migrate/20190621010002_change_default_to_max_num.rb b/db/migrate/20190621010002_change_default_to_max_num.rb new file mode 100644 index 000000000..435756cd8 --- /dev/null +++ b/db/migrate/20190621010002_change_default_to_max_num.rb @@ -0,0 +1,5 @@ +class ChangeDefaultToMaxNum < ActiveRecord::Migration[5.2] + def change + change_column :graduation_tasks, :max_num, :integer, default: 5 + end +end From 82cc18596c9f9488fe60d4befefe8f5dc450c8ee Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Jun 2019 09:17:43 +0800 Subject: [PATCH 0023/1015] =?UTF-8?q?=E9=80=89=E9=A2=98=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E7=94=A8=E6=88=B7=E6=98=AF=E5=90=A6=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E4=BA=86=E5=85=B6=E4=BB=96=E9=80=89=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/graduation_topics_controller.rb | 4 ++++ app/views/graduation_topics/show.json.jbuilder | 1 + 2 files changed, 5 insertions(+) diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index 36f51ce6e..366b6d9ca 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -45,6 +45,10 @@ class GraduationTopicsController < ApplicationController end ## 分页参数 @current_user = current_user + user_graduation_topics = @course.student_graduation_topics.where(user_id: current_user.id, + status: [0, 1], + graduation_topic_id: @graduation_topic.pluck(:id)) + @user_selected = user_graduation_topics.size > 0 page = params[:page] || 1 limit = params[:limit] || 50 @users_count = @student_graduation_topics.try(:count).to_i diff --git a/app/views/graduation_topics/show.json.jbuilder b/app/views/graduation_topics/show.json.jbuilder index a75ac5240..87fcc87aa 100644 --- a/app/views/graduation_topics/show.json.jbuilder +++ b/app/views/graduation_topics/show.json.jbuilder @@ -8,6 +8,7 @@ json.users_count @users_count json.course_identity @current_user.course_identity(@course) json.user_selected_topic @graduation_topic.user_status(current_user.id) json.group_list @course.teacher_group(current_user.id) +json.user_selected @user_selected # 列表数据 json.users_list do From 3cc0e9b7ba7c414bd3e7441704fda7f625aab3b1 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 21 Jun 2019 09:17:52 +0800 Subject: [PATCH 0024/1015] fix bug --- .../exercises/exercise_lists.json.jbuilder | 2 +- app/views/polls/poll_lists.json.jbuilder | 1 + lib/tasks/exercise_publish.rake | 155 +++++++++++------- 3 files changed, 99 insertions(+), 59 deletions(-) diff --git a/app/views/exercises/exercise_lists.json.jbuilder b/app/views/exercises/exercise_lists.json.jbuilder index b51e781c7..5e7c83b35 100644 --- a/app/views/exercises/exercise_lists.json.jbuilder +++ b/app/views/exercises/exercise_lists.json.jbuilder @@ -15,6 +15,7 @@ json.exercise_types do json.exercise_id @exercise.id json.subjective @subjective_type #是否包含主观题,1为包括,0为不包括 json.exercise_end_time ((@ex_user_end_time.nil? || @ex_user_end_time < Time.now) ? "--" : how_much_time(@ex_user_end_time)) + json.groups_count @exercise_course_groups.size end if @exercise_current_user_status == 0 #当为老师的时候 @@ -29,7 +30,6 @@ if @exercise_current_user_status == 0 #当为老师的时候 else json.course_groups [] end - end if @current_user_ex_answers.present? diff --git a/app/views/polls/poll_lists.json.jbuilder b/app/views/polls/poll_lists.json.jbuilder index fef129599..8278ac3e0 100644 --- a/app/views/polls/poll_lists.json.jbuilder +++ b/app/views/polls/poll_lists.json.jbuilder @@ -16,6 +16,7 @@ json.poll_types do json.user_permission @poll_current_user_status #当前用户存在且为课堂教师/管理员/超级管理员时为0 ,其他否则为1 json.poll_id @poll.id json.poll_end_time @poll.end_time + json.groups_count @poll_course_groups.size end if @poll_current_user_status == 0 diff --git a/lib/tasks/exercise_publish.rake b/lib/tasks/exercise_publish.rake index 8a13154cc..7d80dc2e9 100644 --- a/lib/tasks/exercise_publish.rake +++ b/lib/tasks/exercise_publish.rake @@ -25,83 +25,118 @@ namespace :exercise_publish do end end - # def calculate_student_score(exercise, user) - # score = 0 - # score1 = 0 - # score2 = 0 - # score3 = 0 - # score4 = 0 - # exercise_qustions = exercise.exercise_questions - # exercise_qustions.each do |question| - # if question.question_type != 5 - # answer = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}") - # if question.question_type == 3 - # standard_answer =[] - # question.exercise_standard_answers.each do |answer| - # standard_answer << answer.answer_text.strip.downcase + #计算试卷的总分和试卷的答题状态 + # def calculate_student_score(exercise,user) + # score1 = 0.0 #选择题/判断题 + # score2 = 0.0 #填空题 + # score5 = 0.0 #实训题 + # ques_stand = [] #问题是否正确 + # exercise_questions = exercise.exercise_questions + # exercise_questions.each do |q| + # if q.question_type != 5 + # answers_content = q.exercise_answers.search_answer_users("user_id",user.id) #学生的答案 + # else + # answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user.id) #学生的答案 + # end + # if q.question_type <= 2 #为选择题或判断题时 + # 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.count > 0 + # multi_each_score = (q.question_score / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 + # else + # multi_each_score = 0.0 # end + # answers_content.update_all(:score => multi_each_score) + # score1 = score1 + q.question_score + # end + # elsif q.question_type == 3 #填空题 + # null_standard_answer = q.exercise_standard_answers + # standard_answer_array = null_standard_answer.select(:exercise_choice_id,:answer_text) + # standard_answer_ids = standard_answer_array.pluck(:exercise_choice_id).reject(&:blank?).uniq #标准答案的exercise_choice_id数组 + # standard_answer_count = standard_answer_ids.count + # if standard_answer_count > 0 #存在标准答案时才有分数 + # each_standard_score = (q.question_score.to_f / standard_answer_count).round(1) #每一空的得分 # else - # standard_answer = question.exercise_standard_answers.first + # each_standard_score = 0.0 # end - # - # unless answer.empty? - # # 问答题有多个答案 - # if question.question_type == 3 && !standard_answer.empty? - # if standard_answer.include?(answer.first.answer_text.strip.downcase) - # score1 = score1+ question.question_score unless question.question_score.nil? - # end - # elsif question.question_type == 1 && !standard_answer.nil? - # if answer.first.exercise_choice.choice_position == standard_answer.exercise_choice_id - # score2 = score2 + question.question_score unless question.question_score.nil? + # if q.is_ordered + # answers_content.each do |u| + # i_standard_answer = standard_answer_array.where(exercise_choice_id:u.exercise_choice_id).pluck(:answer_text).reject(&:blank?).map!(&:downcase) #该选项的全部标准答案 + # if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数 + # u.update_attribute("score",each_standard_score) + # score2 = score2 + each_standard_score # end - # elsif question.question_type == 2 && !standard_answer.nil? - # arr = get_mulscore(question, user) - # if arr.to_i == standard_answer.exercise_choice_id - # score3 = score3 + question.question_score unless question.question_score.nil? + # end + # else + # st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map!(&:downcase) + # answers_content.each do |u| + # u_answer_text = u.answer_text.downcase + # if st_answer_text.include?(u_answer_text) #只要标准答案包含用户的答案,就有分数。同时,下一次循环时,就会删除该标准答案。防止用户的相同答案获分 + # u.update_attribute("score",each_standard_score) + # score2 = score2 + each_standard_score + # st_answer_text.delete(u_answer_text) # end # end # end - # else - # question.exercise_shixun_challenges.each do |exercise_cha| - # game = Game.where(:user_id => user.id, :challenge_id => exercise_cha.challenge_id).first + # 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 # answer_status = 0 - # cha_path = exercise_cha.challenge.path.present? ? exercise_cha.challenge.path.split(";") : [] - # challeng_path = cha_path.reject(&:blank?)[0].try(:strip) + # cha_path = challenge_path exercise_cha.challenge.path # if game.status == 2 && game.final_score >= 0 - # exercise_cha_score = exercise_cha.question_score + # exercise_cha_score = game.real_score exercise_cha.question_score #每一关卡的得分 # answer_status = 1 # end - # if exercise_cha.exercise_shixun_answers.where(:user_id => user.id).empty? - # if GameCode.where(:game_id => game.try(:id), :path => challeng_path).first.present? - # game_code = GameCode.where(:game_id => game.try(:id), :path => challeng_path).first + # if exercise_cha.exercise_shixun_answers.search_shixun_answers("user_id",user.id).blank? #把关卡的答案存入试卷的实训里 + # 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 - # begin - # g = Gitlab.client - # Rails.logger.info "commit_exercise_path---- #{challeng_path}" - # if game.present? - # code = g.files(game.myshixun.gpid, challeng_path, "master").try(:content) - # else - # code = g.files(question.shixun.gpid, challeng_path, "master").try(:content) - # end - # code = tran_base64_decode64(code) - # rescue Exception => e - # @error_messages = e.message - # Rails.logger.info "commit_exercise---- #{@error_messages}" - # end + # code = git_fle_content(exercise_cha.shixun.repo_path,cha_path) # end - # ExerciseShixunAnswer.create(:exercise_question_id => question.id, :exercise_shixun_challenge_id => exercise_cha.id, :user_id => user.id, - # :score => exercise_cha_score, :answer_text => code, :status => answer_status) - # + # sx_option = { + # :exercise_question_id => q.id, + # :exercise_shixun_challenge_id => exercise_cha.id, + # :user_id => user.id, + # :score => exercise_cha_score, + # :answer_text => code, + # :status => answer_status + # } + # ex_shixun_answer = ExerciseShixunAnswer.new(sx_option) + # ex_shixun_answer.save! # end - # score4 += exercise_cha_score + # score5 += exercise_cha_score # end # end # end + # user_scores = answers_content.score_reviewed.pluck(:score).sum + # if user_scores > 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 #每个问题的总得分 + # } + # ques_stand.push(ques_option) # end - # score = score1 + score2 + score3 + score4 + # total_score = score1 + score2 + score5 + # { + # "total_score":total_score, + # "stand_status":ques_stand + # } # end task :publish => :environment do @@ -169,6 +204,9 @@ namespace :exercise_publish do end task :end => :environment do + # include ExercisesHelper + # include ApplicationController + exercises = Exercise.where("end_time <=? and exercise_status = 2",Time.now) exercises.each do |exercise| course = exercise.course @@ -180,7 +218,7 @@ namespace :exercise_publish do s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) - if exercise_user.user.exercise_answer.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? + if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? exercise_user.update_attributes(:subjective_score => 0) end end @@ -201,11 +239,12 @@ namespace :exercise_publish do s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) - if exercise_user.user.exercise_answer.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? + if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? exercise_user.update_attributes(:subjective_score => 0) end end end end + logger.info("") end end From 79328e29207b6f6437f089b188d852febd79f16d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Jun 2019 09:20:33 +0800 Subject: [PATCH 0025/1015] =?UTF-8?q?=E9=80=89=E9=A2=98=E6=8A=A5500?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/graduation_topics_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index 366b6d9ca..56a0d5a3f 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -47,7 +47,7 @@ class GraduationTopicsController < ApplicationController @current_user = current_user user_graduation_topics = @course.student_graduation_topics.where(user_id: current_user.id, status: [0, 1], - graduation_topic_id: @graduation_topic.pluck(:id)) + graduation_topic_id: @graduation_topic.id) @user_selected = user_graduation_topics.size > 0 page = params[:page] || 1 limit = params[:limit] || 50 From 281417e6b27471a7bfa6e6e613da84385f21180b Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Jun 2019 09:29:46 +0800 Subject: [PATCH 0026/1015] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E9=80=89=E9=A2=98?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E4=B8=AD=E5=AD=A6=E7=94=9F=E9=80=89=E9=A2=98?= =?UTF-8?q?=E4=B8=8D=E5=AF=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/graduation_topics_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index 56a0d5a3f..cd1726d1c 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -46,8 +46,7 @@ class GraduationTopicsController < ApplicationController ## 分页参数 @current_user = current_user user_graduation_topics = @course.student_graduation_topics.where(user_id: current_user.id, - status: [0, 1], - graduation_topic_id: @graduation_topic.id) + status: [0, 1]) @user_selected = user_graduation_topics.size > 0 page = params[:page] || 1 limit = params[:limit] || 50 From 2aaa0fe652000239969dedf3ccf684fe82917658 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Jun 2019 09:31:10 +0800 Subject: [PATCH 0027/1015] =?UTF-8?q?=E6=98=AF=E5=90=A6=E9=80=89=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/graduation_topics_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index cd1726d1c..a6903dbc7 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -24,8 +24,7 @@ class GraduationTopicsController < ApplicationController end # 当前用户是否已经选过题 - # @user_selected = StudentGraduationTopic.where(graduation_topic_id: @graduation_topic, user_id: current_user.id).count > 0 - user_graduation_topics = @course.student_graduation_topics.where(user_id: current_user.id, status: [0, 1], graduation_topic_id: @graduation_topic.pluck(:id)) #6.12 -hs + user_graduation_topics = @course.student_graduation_topics.where(user_id: current_user.id, status: [0, 1]) #6.12 -hs @user_selected = user_graduation_topics.size > 0 ## 分页参数 page = params[:page] || 1 From 559eb0da65cf52ad753c693a86a869400afffa7f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Jun 2019 09:33:32 +0800 Subject: [PATCH 0028/1015] =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E4=B8=BB=E9=A1=B5=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index dc68f47c6..17281087b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -61,7 +61,7 @@ class UsersController < ApplicationController # 新消息数 @new_message = @user.tidings.where("created_at > '#{@user.click_time}'").count > 0 || @user.private_messages.where("created_at > '#{@user.click_time}'").count > 0 - @user_url = "#{@old_domain}/users/#{@user.login}" + @user_url = "/users/#{@user.login}" @career = Career.where(status: true).order("created_at asc").pluck(:id, :name) ec_user = EcSchoolUser.where(:user_id => current_user.id).first @auth = ec_user ? "#{@old_domain}/ecs/department?school_id=#{ec_user.school_id}" : nil From c19744e25fd6a604a123850d835b08379ed5159a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Jun 2019 09:42:19 +0800 Subject: [PATCH 0029/1015] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/courses/index.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/courses/index.json.jbuilder b/app/views/courses/index.json.jbuilder index 23e8715af..58a75e317 100644 --- a/app/views/courses/index.json.jbuilder +++ b/app/views/courses/index.json.jbuilder @@ -10,7 +10,7 @@ json.courses do json.tasks_count get_tasks_count course json.visits course.visits json.is_public course.is_public - json.is_accessible course.is_public? ? true : (course.tea_id == @user.id || @user.course_identity(course) < 5) + json.is_accessible course.is_public? || course.tea_id == @user.id || @user.course_identity(course) < Course::NORMAL json.is_end course.is_end json.first_category_url module_url(course.course_modules.first, course) end From db58702645069aa7dcefa4fb32f330854aca96f1 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Jun 2019 09:42:44 +0800 Subject: [PATCH 0030/1015] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E8=AE=BF=E9=97=AE?= =?UTF-8?q?=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/courses/index.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/courses/index.json.jbuilder b/app/views/courses/index.json.jbuilder index 58a75e317..94da87af5 100644 --- a/app/views/courses/index.json.jbuilder +++ b/app/views/courses/index.json.jbuilder @@ -10,7 +10,7 @@ json.courses do json.tasks_count get_tasks_count course json.visits course.visits json.is_public course.is_public - json.is_accessible course.is_public? || course.tea_id == @user.id || @user.course_identity(course) < Course::NORMAL + json.is_accessible course.is_public? || @user.course_identity(course) < Course::NORMAL json.is_end course.is_end json.first_category_url module_url(course.course_modules.first, course) end From 63dba0f703041c5b4bf3bd44b3eeb2d349863774 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 09:44:43 +0800 Subject: [PATCH 0031/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190517080313_add_test_set_average_for_challenges.rb | 2 +- .../20190517083326_change_test_set_averger_for_challenges.rb | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) delete mode 100644 db/migrate/20190517083326_change_test_set_averger_for_challenges.rb diff --git a/db/migrate/20190517080313_add_test_set_average_for_challenges.rb b/db/migrate/20190517080313_add_test_set_average_for_challenges.rb index 59fabec9d..cac1d80bc 100644 --- a/db/migrate/20190517080313_add_test_set_average_for_challenges.rb +++ b/db/migrate/20190517080313_add_test_set_average_for_challenges.rb @@ -1,5 +1,5 @@ class AddTestSetAverageForChallenges < ActiveRecord::Migration[5.2] def change - add_column :challenges, :test_set_average, :boolean, :default => false + add_column :challenges, :test_set_average, :boolean, :default => true end end diff --git a/db/migrate/20190517083326_change_test_set_averger_for_challenges.rb b/db/migrate/20190517083326_change_test_set_averger_for_challenges.rb deleted file mode 100644 index bf474245f..000000000 --- a/db/migrate/20190517083326_change_test_set_averger_for_challenges.rb +++ /dev/null @@ -1,5 +0,0 @@ -class ChangeTestSetAvergerForChallenges < ActiveRecord::Migration[5.2] - def change - change_column :challenges, :test_set_average, :boolean, :default => true - end -end From 544152cdf60aee6287003304fefcaa19a9958d69 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Jun 2019 09:57:38 +0800 Subject: [PATCH 0032/1015] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 2b988e89c..ec34126ac 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -77,11 +77,17 @@ class CoursesController < ApplicationController # 根据搜索关键字进一步筛选 if params[:search].present? # REDO:Extension - user_ids = User.includes(user_extension: :school).where("schools.name like ?", "%#{params[:search]}%").pluck(:id) - course_ids = CourseMember.includes(:user, :course).where("course_members.course_id in (?) and course_members.role in (1,2,3) - and CONCAT(users.lastname, users.firstname) like ?", @courses.map(&:id), "%#{params[:search]}%") - .pluck(:course_id) - @courses = @courses.where("name like ?", "%#{params[:search]}%").or(@courses.where(tea_id: user_ids)).or(@courses.where(id: course_ids)) + #user_ids = User.includes(user_extension: :school).where("schools.name like ?", "%#{params[:search]}%").pluck(:id) + #course_ids = CourseMember.includes(:user, :course).where("course_members.course_id in (?) and course_members.role in (1,2,3) + # and CONCAT(users.lastname, users.firstname) like ?", @courses.map(&:id), "%#{params[:search]}%") + # .pluck(:course_id) + #@courses = @courses.where("name like ?", "%#{params[:search]}%").or(@courses.where(tea_id: user_ids)).or(@courses.where(id: course_ids)) + # 6:21 daiao + sql = %Q{ + (course_members.role in (1,2,3) and CONCAT(users.lastname, users.firstname) like :keyword) or courses.name like :keyword + or schools.name like :keyword + } + @courses.includes(course_members: [user: [user_extension: :school]]).where(sql, keyword: "%#{params[:search]}%") end @courses_count = @courses.size From 62bd057317c28271e1688c4af5f17fd3c1e2d94c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 21 Jun 2019 09:59:21 +0800 Subject: [PATCH 0033/1015] fix bug --- app/controllers/exercises_controller.rb | 1 + app/controllers/poll_votes_controller.rb | 11 ++++++++++- app/controllers/polls_controller.rb | 2 ++ app/views/exercises/exercise_lists.json.jbuilder | 2 +- app/views/polls/poll_lists.json.jbuilder | 2 +- lib/tasks/exercise_publish.rake | 2 +- 6 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 2239f570d..e2d6110bd 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1140,6 +1140,7 @@ class ExercisesController < ApplicationController exercise_ids = [@exercise.id] @exercise_status = @exercise.get_exercise_status(current_user.id) @course_all_members = @course.students + @c_group_counts = @course.course_groups_count question_types = @exercise.exercise_questions.pluck(:question_type) @exercise_publish_count = get_user_permission_course(exercise_ids,2).count #判断是否有已发布的分班 @exercise_unpublish_count = get_user_permission_course(exercise_ids,1).count #判断是否有未发布的分班 diff --git a/app/controllers/poll_votes_controller.rb b/app/controllers/poll_votes_controller.rb index eef953d5e..d8a4ce852 100644 --- a/app/controllers/poll_votes_controller.rb +++ b/app/controllers/poll_votes_controller.rb @@ -30,16 +30,25 @@ class PollVotesController < ApplicationController #begin if question_type == 1 if user_votes.present? #用户曾经回答过的,答案选择不一样,否则新建 + logger.info("########___________user_votes.present1111____________________#######") current_user_answer = user_votes.first - if current_user_answer.poll_answer_id != question_answer_id #如果说更换了答案,则以前的答案删除,并新建记录 + if current_user_answer&.poll_answer_id != question_answer_id #如果说更换了答案,则以前的答案删除,并新建记录 + logger.info("########___________user_votes.present22222____________________#######") + current_user_answer.destroy PollVote.create(vote_answer_params) else + logger.info("########___________user_votes.present33333____________________#######") + if question_answer_text.present? + logger.info("########___________user_votes.present4444444____________________#######") + current_user_answer.update_attribute("vote_text", question_answer_text) end end else + logger.info("########___________user_votes.present555555____________________#######") + PollVote.create(vote_answer_params) end elsif question_type == 2 #多选题的话,答案应该是1个以上 diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index ae93357cc..675e3283c 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -956,6 +956,8 @@ class PollsController < ApplicationController @poll_publish_count = get_user_permission_course(poll_ids,2).count @poll_unpublish_count = get_user_permission_course(poll_ids,1).count @course_all_members = @course.students + @poll_group_counts = @course.course_groups_count + if @user_course_identity < Course::STUDENT #当前为老师,而且老师只能查看自己班级的/课堂的问卷 @poll_current_user_status = 0 @poll_users_list = @poll.all_poll_users(current_user.id).distinct #该老师分班的全部学生 diff --git a/app/views/exercises/exercise_lists.json.jbuilder b/app/views/exercises/exercise_lists.json.jbuilder index 5e7c83b35..26723c894 100644 --- a/app/views/exercises/exercise_lists.json.jbuilder +++ b/app/views/exercises/exercise_lists.json.jbuilder @@ -15,7 +15,7 @@ json.exercise_types do json.exercise_id @exercise.id json.subjective @subjective_type #是否包含主观题,1为包括,0为不包括 json.exercise_end_time ((@ex_user_end_time.nil? || @ex_user_end_time < Time.now) ? "--" : how_much_time(@ex_user_end_time)) - json.groups_count @exercise_course_groups.size + json.groups_count @c_group_counts end if @exercise_current_user_status == 0 #当为老师的时候 diff --git a/app/views/polls/poll_lists.json.jbuilder b/app/views/polls/poll_lists.json.jbuilder index 8278ac3e0..f134967c9 100644 --- a/app/views/polls/poll_lists.json.jbuilder +++ b/app/views/polls/poll_lists.json.jbuilder @@ -16,7 +16,7 @@ json.poll_types do json.user_permission @poll_current_user_status #当前用户存在且为课堂教师/管理员/超级管理员时为0 ,其他否则为1 json.poll_id @poll.id json.poll_end_time @poll.end_time - json.groups_count @poll_course_groups.size + json.groups_count @poll_group_counts end if @poll_current_user_status == 0 diff --git a/lib/tasks/exercise_publish.rake b/lib/tasks/exercise_publish.rake index 7d80dc2e9..bc9330b66 100644 --- a/lib/tasks/exercise_publish.rake +++ b/lib/tasks/exercise_publish.rake @@ -245,6 +245,6 @@ namespace :exercise_publish do end end end - logger.info("") + Rails.logger.info("log--------------------------------exercise_end completed") end end From 85df7ce8fc243b357d44c3d0a40bade6011bdde9 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Jun 2019 10:01:53 +0800 Subject: [PATCH 0034/1015] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E4=BC=98=E5=8C=96?= 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 ec34126ac..31e886d36 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -87,7 +87,7 @@ class CoursesController < ApplicationController (course_members.role in (1,2,3) and CONCAT(users.lastname, users.firstname) like :keyword) or courses.name like :keyword or schools.name like :keyword } - @courses.includes(course_members: [user: [user_extension: :school]]).where(sql, keyword: "%#{params[:search]}%") + @courses = @courses.includes(course_members: [user: [user_extension: :school]]).where("#{sql}", keyword: "%#{params[:search]}%") end @courses_count = @courses.size From 843f6becc989dd139b2c3ce0f0fe1005506b674e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 21 Jun 2019 10:04:55 +0800 Subject: [PATCH 0035/1015] fix bug --- app/controllers/poll_votes_controller.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/app/controllers/poll_votes_controller.rb b/app/controllers/poll_votes_controller.rb index d8a4ce852..81126b044 100644 --- a/app/controllers/poll_votes_controller.rb +++ b/app/controllers/poll_votes_controller.rb @@ -30,26 +30,21 @@ class PollVotesController < ApplicationController #begin if question_type == 1 if user_votes.present? #用户曾经回答过的,答案选择不一样,否则新建 - logger.info("########___________user_votes.present1111____________________#######") current_user_answer = user_votes.first if current_user_answer&.poll_answer_id != question_answer_id #如果说更换了答案,则以前的答案删除,并新建记录 - logger.info("########___________user_votes.present22222____________________#######") - current_user_answer.destroy - PollVote.create(vote_answer_params) + user_votes = PollVote.new(vote_answer_params) + user_votes.save! else - logger.info("########___________user_votes.present33333____________________#######") if question_answer_text.present? - logger.info("########___________user_votes.present4444444____________________#######") current_user_answer.update_attribute("vote_text", question_answer_text) end end else - logger.info("########___________user_votes.present555555____________________#######") - - PollVote.create(vote_answer_params) + user_votes = PollVote.new(vote_answer_params) + user_votes.save! end elsif question_type == 2 #多选题的话,答案应该是1个以上 question_answer_ids = params[:poll_answer_id] ? params[:poll_answer_id] : [] #该答案的id @@ -107,6 +102,7 @@ class PollVotesController < ApplicationController @current_question_necessary = @poll_question.is_necessary #问答记录存在,且有值,才会有返回值。 @current_question_status = 0 + if user_votes.present? vote_answer_id = user_votes.pluck(:poll_answer_id).reject(&:blank?).size vote_text_count = user_votes.pluck(:vote_text).reject(&:blank?).size From 5c40a97fef33325a671ece1f1c99259341b721d8 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Jun 2019 10:05:06 +0800 Subject: [PATCH 0036/1015] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=8A=A5500?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 31e886d36..c442e5a6c 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -84,10 +84,10 @@ class CoursesController < ApplicationController #@courses = @courses.where("name like ?", "%#{params[:search]}%").or(@courses.where(tea_id: user_ids)).or(@courses.where(id: course_ids)) # 6:21 daiao sql = %Q{ - (course_members.role in (1,2,3) and CONCAT(users.lastname, users.firstname) like :keyword) or courses.name like :keyword + (course_members.role in(1,2,3) and CONCAT(users.lastname, users.firstname) like :keyword) or courses.name like :keyword or schools.name like :keyword } - @courses = @courses.includes(course_members: [user: [user_extension: :school]]).where("#{sql}", keyword: "%#{params[:search]}%") + @courses = @courses.joins(course_members: [user: [user_extension: :school]]).where("#{sql}", keyword: "%#{params[:search]}%") end @courses_count = @courses.size From 2f5d7ca4512ae71b19ee24edc2b6ca64676e3e8d Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 21 Jun 2019 10:07:45 +0800 Subject: [PATCH 0037/1015] fix bug --- app/controllers/poll_votes_controller.rb | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/controllers/poll_votes_controller.rb b/app/controllers/poll_votes_controller.rb index 81126b044..a2f805a97 100644 --- a/app/controllers/poll_votes_controller.rb +++ b/app/controllers/poll_votes_controller.rb @@ -33,8 +33,7 @@ class PollVotesController < ApplicationController current_user_answer = user_votes.first if current_user_answer&.poll_answer_id != question_answer_id #如果说更换了答案,则以前的答案删除,并新建记录 current_user_answer.destroy - user_votes = PollVote.new(vote_answer_params) - user_votes.save! + PollVote.create(vote_answer_params) else if question_answer_text.present? @@ -43,8 +42,7 @@ class PollVotesController < ApplicationController end end else - user_votes = PollVote.new(vote_answer_params) - user_votes.save! + PollVote.create(vote_answer_params) end elsif question_type == 2 #多选题的话,答案应该是1个以上 question_answer_ids = params[:poll_answer_id] ? params[:poll_answer_id] : [] #该答案的id @@ -102,10 +100,10 @@ class PollVotesController < ApplicationController @current_question_necessary = @poll_question.is_necessary #问答记录存在,且有值,才会有返回值。 @current_question_status = 0 - - if user_votes.present? - vote_answer_id = user_votes.pluck(:poll_answer_id).reject(&:blank?).size - vote_text_count = user_votes.pluck(:vote_text).reject(&:blank?).size + new_user_votes = question_votes.where(user_id: current_user.id) + if new_user_votes.present? + vote_answer_id = new_user_votes.pluck(:poll_answer_id).reject(&:blank?).size + vote_text_count = new_user_votes.pluck(:vote_text).reject(&:blank?).size if vote_text_count > 0 || vote_answer_id > 0 @current_question_status = 1 end From a42ce8c0246a8c76c0eb68e85e5acfd89ca02e5e Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 21 Jun 2019 10:16:18 +0800 Subject: [PATCH 0038/1015] add search bank slim api --- app/controllers/courses_controller.rb | 14 ++++++++++++++ app/models/course.rb | 2 ++ config/routes.rb | 1 + 3 files changed, 17 insertions(+) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index c442e5a6c..5097536d5 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -994,6 +994,20 @@ class CoursesController < ApplicationController end end + def search_slim + courses = current_user.manage_courses.not_deleted.processing + + keyword = params[:keyword].to_s.strip + if keyword.present? + courses = courses.where('name LIKE ?', "%#{keyword}%") + end + + count = courses.count + courses = paginate(courses) + + render_ok(count: count, courses: courses.select(:id, :name).as_json) + end + private # Use callbacks to share common setup or constraints between actions. diff --git a/app/models/course.rb b/app/models/course.rb index c0c7f1f23..61e48d350 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -61,6 +61,8 @@ class Course < ApplicationRecord scope :hidden, ->(is_hidden = true) { where(is_hidden: is_hidden) } scope :ended, ->(is_end = true) { where(is_end: is_end) } + scope :processing, -> { where(is_end: false) } + scope :not_deleted, -> { where(is_delete: false) } scope :deleted, ->(is_delete = 1) { where(is_delete: is_delete) } scope :by_user, ->(user) { joins(:course_members).where('course_members.user_id = ?', user.id).order(updated_at: :desc) } scope :by_keywords, lambda { |keywords| diff --git a/config/routes.rb b/config/routes.rb index e7fac7331..ecd54c8c0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -303,6 +303,7 @@ Rails.application.routes.draw do post 'search_course_list' get 'board_list' get 'mine' + get 'search_slim' end resources :polls, only:[:index,:new,:create] do From 8ab306550aafc3385ee357b8292e1a091ff48364 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 10:31:41 +0800 Subject: [PATCH 0039/1015] =?UTF-8?q?=E4=BB=8E=E9=A2=98=E5=BA=93=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E6=AF=95=E8=AE=BE=E4=BB=BB=E5=8A=A1=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E6=97=B6=E9=97=B4=E5=BA=94=E4=B8=BA=E5=BD=93?= =?UTF-8?q?=E5=89=8D=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/question_banks_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index 299224527..bf55db9dd 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -240,7 +240,7 @@ class QuestionBanksController < ApplicationController ActiveRecord::Base.transaction do new_task = GraduationTask.new new_task.attributes = task.attributes.dup.except("id", "course_id", "user_id", "quotes", "graduation_task_id", - "course_list_id", "gtask_bank_id") + "course_list_id", "gtask_bank_id", "created_at", "updated_at") new_task.course_id = course.id new_task.gtask_bank_id = task.id new_task.user_id = current_user.id @@ -266,7 +266,7 @@ class QuestionBanksController < ApplicationController ActiveRecord::Base.transaction do new_topic = GraduationTopic.new new_topic.attributes = topic.attributes.dup.except("id", "course_id", "user_id", "graduation_topic_id", - "course_list_id", "gtopic_bank_id") + "course_list_id", "gtopic_bank_id", "created_at", "updated_at") new_topic.course_id = course.id new_topic.gtopic_bank_id = topic.id new_topic.user_id = current_user.id From c7287122af88b31aa07ffd2eb797b2f4c3a076cd Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 10:37:53 +0800 Subject: [PATCH 0040/1015] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/courses/index.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/courses/index.json.jbuilder b/app/views/courses/index.json.jbuilder index 94da87af5..1993851e8 100644 --- a/app/views/courses/index.json.jbuilder +++ b/app/views/courses/index.json.jbuilder @@ -10,7 +10,7 @@ json.courses do json.tasks_count get_tasks_count course json.visits course.visits json.is_public course.is_public - json.is_accessible course.is_public? || @user.course_identity(course) < Course::NORMAL + json.is_accessible course.is_public == 1 || @user.course_identity(course) < Course::NORMAL json.is_end course.is_end json.first_category_url module_url(course.course_modules.first, course) end From e86cb487a3eab919edf7ed2b42bc5e796d10678e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Jun 2019 10:50:16 +0800 Subject: [PATCH 0041/1015] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E9=87=8D=E5=A4=8D?= 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 5097536d5..753999e54 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -87,7 +87,7 @@ class CoursesController < ApplicationController (course_members.role in(1,2,3) and CONCAT(users.lastname, users.firstname) like :keyword) or courses.name like :keyword or schools.name like :keyword } - @courses = @courses.joins(course_members: [user: [user_extension: :school]]).where("#{sql}", keyword: "%#{params[:search]}%") + @courses = @courses.left_joins(course_members: [user: [user_extension: :school]]).where("#{sql}", keyword: "%#{params[:search]}%") end @courses_count = @courses.size From e442c30823aaf821238b642e686c37cdd1c70723 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Jun 2019 10:52:23 +0800 Subject: [PATCH 0042/1015] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E6=9C=89=E9=97=AE=E9=A2=98?= 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 753999e54..cd1e9a0ea 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -87,7 +87,7 @@ class CoursesController < ApplicationController (course_members.role in(1,2,3) and CONCAT(users.lastname, users.firstname) like :keyword) or courses.name like :keyword or schools.name like :keyword } - @courses = @courses.left_joins(course_members: [user: [user_extension: :school]]).where("#{sql}", keyword: "%#{params[:search]}%") + @courses = @courses.left_outer_joins(course_members: [user: [user_extension: :school]]).where("#{sql}", keyword: "%#{params[:search]}%") end @courses_count = @courses.size From bea98cb44a6b35bc14a6e08fbc74a8deb24ac785 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 21 Jun 2019 10:58:44 +0800 Subject: [PATCH 0043/1015] add course board message count rake --- app/models/message.rb | 7 +++---- lib/tasks/course_board_message_count.rake | 24 +++++++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 lib/tasks/course_board_message_count.rake diff --git a/app/models/message.rb b/app/models/message.rb index 26946f6d0..d3d507a72 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -56,11 +56,10 @@ class Message < ApplicationRecord from_board = Board.find(messages.first.board_id) root_ids = messages.map(&:id) - children = Message.where(parent_id: root_ids).select(:id).to_a - children_ids = children.map(&:id) - second_children = Message.where(parent_id: children_ids).select(:id).to_a + children_ids = Message.where(parent_id: root_ids).pluck(:id) + second_children_ids = Message.where(parent_id: children_ids).pluck(:id) - ids = root_ids.concat(children_ids).concat(second_children.map(&:id)).uniq + ids = root_ids.concat(children_ids).concat(second_children_ids).uniq ActiveRecord::Base.transaction do Message.where(id: ids, board_id: from_board.id).update_all(board_id: to_board.id) diff --git a/lib/tasks/course_board_message_count.rake b/lib/tasks/course_board_message_count.rake new file mode 100644 index 000000000..d1ac5524d --- /dev/null +++ b/lib/tasks/course_board_message_count.rake @@ -0,0 +1,24 @@ +namespace :course_board do + desc 'transfer children message to root message board' + task children_message_transfer: :environment do + Board.find_each do |board| + logger("Current transfer board id: #{board.id} ~") + + root_subquery = board.messages.where(parent_id: nil).reorder(nil).pluck(:id) + next if root_subquery.blank? + children_subquery = Message.where(parent_id: root_subquery).reorder(nil).pluck(:id) + next if children_subquery.blank? + second_children_subquery = Message.where(parent_id: children_subquery).reorder(nil).pluck(:id) + + ids = children_subquery.concat(second_children_subquery).uniq + Message.where(id: ids).update_all(board_id: board.id) + + Board.reset_counters(board.id, :messages) + logger("transfer success ~") + end + end + + def logger(msg) + puts msg + end +end \ No newline at end of file From f53b5af75b5953103ed6426d8a6be70adb15fa3b Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 10:59:47 +0800 Subject: [PATCH 0044/1015] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E9=A6=96=E9=A1=B5t?= =?UTF-8?q?iaozn?= 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 5097536d5..252664139 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -87,7 +87,7 @@ class CoursesController < ApplicationController (course_members.role in(1,2,3) and CONCAT(users.lastname, users.firstname) like :keyword) or courses.name like :keyword or schools.name like :keyword } - @courses = @courses.joins(course_members: [user: [user_extension: :school]]).where("#{sql}", keyword: "%#{params[:search]}%") + @courses = @courses.joins(course_members: [user: [user_extension: :school]]).where("#{sql}", keyword: "%#{params[:search]}%").distinct end @courses_count = @courses.size From 819b2347c48447b71c4212081ae07804a0cb95f1 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 11:14:41 +0800 Subject: [PATCH 0045/1015] =?UTF-8?q?=E4=BA=A4=E5=8F=89=E8=AF=84=E9=98=85?= =?UTF-8?q?=E6=9C=AA=E5=BC=80=E5=90=AF=E5=89=8D=E4=B8=8D=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/graduation_tasks/tasks_list.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/graduation_tasks/tasks_list.json.jbuilder b/app/views/graduation_tasks/tasks_list.json.jbuilder index fe7ffddc4..cda1eb6d4 100644 --- a/app/views/graduation_tasks/tasks_list.json.jbuilder +++ b/app/views/graduation_tasks/tasks_list.json.jbuilder @@ -9,7 +9,7 @@ if @task.published? || @user_course_identity < Course::STUDENT json.teacher_comment teacher_comment @task, @current_user.id json.task_status task_status @task, @current_user.id json.course_group_info course_group_info @course, @current_user.id - json.cross_comment cross_comment @task, @current_user + json.cross_comment cross_comment @task, @current_user if @task.status >= 3 end # 课堂下所有老师 TODO: 考虑以后在点击分配时,再获取老师列表 json.teacher_list do From 4a6909b59f32a697624a4d8997aa757339a9f5a4 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 11:19:21 +0800 Subject: [PATCH 0046/1015] =?UTF-8?q?D=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/graduation_tasks_helper.rb | 2 +- app/views/graduation_tasks/tasks_list.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/graduation_tasks_helper.rb b/app/helpers/graduation_tasks_helper.rb index 5253b0d56..a5f05d623 100644 --- a/app/helpers/graduation_tasks_helper.rb +++ b/app/helpers/graduation_tasks_helper.rb @@ -14,7 +14,7 @@ module GraduationTasksHelper # 交叉评阅 def cross_comment task, user_id - if task.cross_comment + if task.cross_comment && task.status >= 3 [{id: 1, name: "只看我的交叉评阅", count: task.graduation_work_comment_assignations.myself(user_id).count}] else [] diff --git a/app/views/graduation_tasks/tasks_list.json.jbuilder b/app/views/graduation_tasks/tasks_list.json.jbuilder index cda1eb6d4..fe7ffddc4 100644 --- a/app/views/graduation_tasks/tasks_list.json.jbuilder +++ b/app/views/graduation_tasks/tasks_list.json.jbuilder @@ -9,7 +9,7 @@ if @task.published? || @user_course_identity < Course::STUDENT json.teacher_comment teacher_comment @task, @current_user.id json.task_status task_status @task, @current_user.id json.course_group_info course_group_info @course, @current_user.id - json.cross_comment cross_comment @task, @current_user if @task.status >= 3 + json.cross_comment cross_comment @task, @current_user end # 课堂下所有老师 TODO: 考虑以后在点击分配时,再获取老师列表 json.teacher_list do From 4fd4b579af190ce80d5700e8fe6ef6ed74284454 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 21 Jun 2019 11:20:32 +0800 Subject: [PATCH 0047/1015] fix rake --- lib/tasks/course_board_message_count.rake | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/tasks/course_board_message_count.rake b/lib/tasks/course_board_message_count.rake index d1ac5524d..35e439403 100644 --- a/lib/tasks/course_board_message_count.rake +++ b/lib/tasks/course_board_message_count.rake @@ -5,13 +5,15 @@ namespace :course_board do logger("Current transfer board id: #{board.id} ~") root_subquery = board.messages.where(parent_id: nil).reorder(nil).pluck(:id) - next if root_subquery.blank? - children_subquery = Message.where(parent_id: root_subquery).reorder(nil).pluck(:id) - next if children_subquery.blank? - second_children_subquery = Message.where(parent_id: children_subquery).reorder(nil).pluck(:id) + if root_subquery.present? + children_subquery = Message.where(parent_id: root_subquery).reorder(nil).pluck(:id) + if children_subquery.present? + second_children_subquery = Message.where(parent_id: children_subquery).reorder(nil).pluck(:id) - ids = children_subquery.concat(second_children_subquery).uniq - Message.where(id: ids).update_all(board_id: board.id) + ids = children_subquery.concat(second_children_subquery).uniq + Message.where(id: ids).update_all(board_id: board.id) + end + end Board.reset_counters(board.id, :messages) logger("transfer success ~") From 1253844369cb8438b1b2a0af7ff314bad5a0f2ed Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 21 Jun 2019 13:54:07 +0800 Subject: [PATCH 0048/1015] modify --- app/controllers/courses_controller.rb | 2 +- app/models/course.rb | 2 +- app/services/users/course_service.rb | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 252664139..cb3b5c929 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -937,7 +937,7 @@ class CoursesController < ApplicationController @page = params[:page] || 1 @page_size = params[:page_size] || 15 - @courses = Course.by_user(current_user).hidden(false).ended(false).deleted(0).by_keywords(params[:search]).distinct + @courses = Course.by_user(current_user).hidden(false).processing.not_deleted.by_keywords(params[:search]).distinct # @total_count = @courses.count # offset = 0 diff --git a/app/models/course.rb b/app/models/course.rb index 61e48d350..e4ade6e9f 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -62,7 +62,7 @@ class Course < ApplicationRecord scope :hidden, ->(is_hidden = true) { where(is_hidden: is_hidden) } scope :ended, ->(is_end = true) { where(is_end: is_end) } scope :processing, -> { where(is_end: false) } - scope :not_deleted, -> { where(is_delete: false) } + scope :not_deleted, -> { where(is_delete: 0) } scope :deleted, ->(is_delete = 1) { where(is_delete: is_delete) } scope :by_user, ->(user) { joins(:course_members).where('course_members.user_id = ?', user.id).order(updated_at: :desc) } scope :by_keywords, lambda { |keywords| diff --git a/app/services/users/course_service.rb b/app/services/users/course_service.rb index 6271db17b..9eb34917e 100644 --- a/app/services/users/course_service.rb +++ b/app/services/users/course_service.rb @@ -11,7 +11,7 @@ class Users::CourseService end def call - courses = category_scope_courses.deleted(false) + courses = category_scope_courses.not_deleted courses = status_filter(courses) @@ -38,9 +38,9 @@ class Users::CourseService case params[:status] when 'processing' then - relations.ended(false) + relations.processing when 'end' then - relations.ended(true) + relations.ended else relations end From 88c1d7c48ac4795bb4992ea6819c7057ed55f509 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 21 Jun 2019 13:54:21 +0800 Subject: [PATCH 0049/1015] fix bug --- app/controllers/application_controller.rb | 61 +-- app/controllers/concerns/git_helper.rb | 52 +++ app/controllers/concerns/logger_helper.rb | 16 + app/tasks/exercise_publish_task.rb | 111 +++++ lib/tasks/exercise_publish.rake | 518 +++++++++++----------- 5 files changed, 449 insertions(+), 309 deletions(-) create mode 100644 app/controllers/concerns/git_helper.rb create mode 100644 app/controllers/concerns/logger_helper.rb create mode 100644 app/tasks/exercise_publish_task.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cffe2df15..9482dc2dd 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,6 +5,8 @@ class ApplicationController < ActionController::Base include RenderExpand include RenderHelper include ControllerRescueHandler + include GitHelper + include LoggerHelper protect_from_forgery prepend: true, unless: -> { request.format.json? } @@ -202,55 +204,6 @@ class ApplicationController < ActionController::Base # end end - # 版本库目录空间 - def repo_namespace(user_login, shixun_identifier) - "#{user_login}/#{shixun_identifier}.git" - end - - # 版本库文件内容,带转码 - def git_fle_content(repo_path, path) - begin - content = GitService.file_content(repo_path: repo_path, path: path)["content"] - logger.info("@@@@@@@@@@@@@@@@@@#{content}") - - decode_content = nil - if content.present? - content = Base64.decode64(content) - cd = CharDet.detect(content) - logger.info "encoding: #{cd['encoding']} confidence: #{cd['confidence']}" - - decode_content = - if cd["encoding"] == 'GB18030' && cd['confidence'] > 0.8 - content.encode('UTF-8', 'GBK', {:invalid => :replace, :undef => :replace, :replace => ' '}) - else - content.force_encoding('UTF-8') - end - end - - decode_content - rescue Exception => e - uid_logger_error(e.message) - raise Educoder::TipException.new("文档内容获取异常") - end - end - - # 更新文件代码 - # content: 文件内容;message:提交描述 - def update_file_content(content, repo_path, path, mail, username, message) - GitService.update_file(repo_path: repo_path, file_path: path, message: message, - content: content, author_name: username, author_email: mail) - end - - # 版本库Fork功能 - def project_fork(container, original_rep_path, username) - raise Educoder::TipException.new("fork源路径为空,fork失败!") if original_rep_path.blank? - # 将要生成的仓库名字 - new_repo_name = "#{username}/#{container.try(:identifier)}#{ Time.now.strftime("%Y%m%d%H%M%S")}" - uid_logger("start fork container: repo_name is #{new_repo_name}") - GitService.fork_repository(repo_path: original_rep_path, fork_repository_path: (new_repo_name + ".git")) - container.update_attributes!(:repo_name => new_repo_name) - end - def start_user_session(user) session[:user_id] = user.id session[:ctime] = Time.now.utc.to_i @@ -330,16 +283,6 @@ class ApplicationController < ActionController::Base end end - # 以用户id开始的日志定义 - def uid_logger(message) - Rails.logger.info("##:#{current_user.try(:id)} --#{message}") - end - - # 以用户id开始的日志定义 - def uid_logger_error(message) - Rails.logger.error("##:#{current_user.try(:id)} --#{message}") - end - ## 输出错误信息 def error_status(message = nil) @status = -1 diff --git a/app/controllers/concerns/git_helper.rb b/app/controllers/concerns/git_helper.rb new file mode 100644 index 000000000..0d8c91a55 --- /dev/null +++ b/app/controllers/concerns/git_helper.rb @@ -0,0 +1,52 @@ +module GitHelper + extend ActiveSupport::Concern + + # 版本库目录空间 + def repo_namespace(user_login, shixun_identifier) + "#{user_login}/#{shixun_identifier}.git" + end + + # 版本库文件内容,带转码 + def git_fle_content(repo_path, path) + begin + content = GitService.file_content(repo_path: repo_path, path: path)["content"] + logger.info("@@@@@@@@@@@@@@@@@@#{content}") + + decode_content = nil + if content.present? + content = Base64.decode64(content) + cd = CharDet.detect(content) + logger.info "encoding: #{cd['encoding']} confidence: #{cd['confidence']}" + + decode_content = + if cd["encoding"] == 'GB18030' && cd['confidence'] > 0.8 + content.encode('UTF-8', 'GBK', {:invalid => :replace, :undef => :replace, :replace => ' '}) + else + content.force_encoding('UTF-8') + end + end + + decode_content + rescue Exception => e + uid_logger_error(e.message) + raise Educoder::TipException.new("文档内容获取异常") + end + end + + # 更新文件代码 + # content: 文件内容;message:提交描述 + def update_file_content(content, repo_path, path, mail, username, message) + GitService.update_file(repo_path: repo_path, file_path: path, message: message, + content: content, author_name: username, author_email: mail) + end + + # 版本库Fork功能 + def project_fork(container, original_rep_path, username) + raise Educoder::TipException.new("fork源路径为空,fork失败!") if original_rep_path.blank? + # 将要生成的仓库名字 + new_repo_name = "#{username}/#{container.try(:identifier)}#{ Time.now.strftime("%Y%m%d%H%M%S")}" + uid_logger("start fork container: repo_name is #{new_repo_name}") + GitService.fork_repository(repo_path: original_rep_path, fork_repository_path: (new_repo_name + ".git")) + container.update_attributes!(:repo_name => new_repo_name) + end +end \ No newline at end of file diff --git a/app/controllers/concerns/logger_helper.rb b/app/controllers/concerns/logger_helper.rb new file mode 100644 index 000000000..44d0448ce --- /dev/null +++ b/app/controllers/concerns/logger_helper.rb @@ -0,0 +1,16 @@ +module LoggerHelper + extend ActiveSupport::Concern + + extend LoggerHelper + + + # 以用户id开始的日志定义 + def uid_logger(message) + Rails.logger.info("##:#{current_user.try(:id)} --#{message}") + end + + # 以用户id开始的日志定义 + def uid_logger_error(message) + Rails.logger.error("##:#{current_user.try(:id)} --#{message}") + end +end \ No newline at end of file diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb new file mode 100644 index 000000000..d0a52646b --- /dev/null +++ b/app/tasks/exercise_publish_task.rb @@ -0,0 +1,111 @@ +class ExercisePublishTask + include ExercisesHelper + include GitHelper + + def publish + Rails.logger.info("log--------------------------------exercise_publish start") + puts "--------------------------------exercise_publish start" + exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) + exercises.each do |exercise| + exercise.update_column('exercise_status', 2) + course = exercise.course + tid_str = "" + course.teachers.find_each do |member| + tid_str += "," if tid_str != "" + tid_str += "(#{member.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" + end + if exercise.unified_setting + course.student.find_each do |student| + tid_str += "," if tid_str != "" + tid_str += "(#{student.student_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" + end + end + if tid_str != "" + tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str + ActiveRecord::Base.connection.execute tid_sql + end + + if exercise.exercise_users.count == 0 + str = "" + course.students.find_each do |student| + str += "," if str != "" + str += "(#{student.user_id}, #{exercise.id}, 0, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" + end + + if str != "" + sql = "insert into exercise_users (user_id, exercise_id, commit_status, created_at, updated_at) values" + str + ActiveRecord::Base.connection.execute sql + end + end + + if exercise.course_acts.size == 0 + exercise.course_acts << CourseActivity.new(:user_id => exercise.user_id,:course_id => exercise.course_id) + end + end + + # 分组设置发布时间的测验 + exercise_group_settings = ExerciseGroupSetting.where("publish_time < ? and publish_time > ?", Time.now + 1800, Time.now - 1800) + exercise_group_settings.each do |exercise_group| + exercise = exercise_group.exercise + if exercise.present? + course = exercise.course + exercise.update_attributes(:exercise_status => 2) if exercise.exercise_status == 1 + tid_str = "" + members = course.students.where(:course_group_id => exercise_group.course_group_id) + members.find_each do |member| + tid_str += "," if tid_str != "" + tid_str += "(#{member.user_id},#{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" + end + if tid_str != "" + tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str + ActiveRecord::Base.connection.execute tid_sql + end + end + end + Rails.logger.info("log--------------------------------exercise_publish end") + puts "--------------------------------exercise_publish end" + end + + def end + exercises = Exercise.where("end_time <=? and exercise_status = 2",Time.now) + exercises.each do |exercise| + course = exercise.course + exercise.update_column('exercise_status', 3) + + exercise.exercise_users.each do |exercise_user| + if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? + exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true) + + s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] + exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) + if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? + exercise_user.update_attributes(:subjective_score => 0) + end + end + end + end + + all_exercises = Exercise.where("end_time > ? and exercise_status = 2",Time.now) + exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")" + ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}").each do |exercise_setting| + exercise = exercise_setting.exercise + + users = exercise.course.students.where(:course_group_id => exercise_setting.course_group_id) + exercise_users = exercise.exercise_users.where(:user_id => users.map(&:user_id)) + + exercise_users.each do |exercise_user| + if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? + exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true) + + s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] + exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) + if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? + exercise_user.update_attributes(:subjective_score => 0) + end + end + end + end + Rails.logger.info("log--------------------------------exercise_end completed") + end + +end \ No newline at end of file diff --git a/lib/tasks/exercise_publish.rake b/lib/tasks/exercise_publish.rake index bc9330b66..a26de1499 100644 --- a/lib/tasks/exercise_publish.rake +++ b/lib/tasks/exercise_publish.rake @@ -1,250 +1,268 @@ -#coding=utf-8 - -namespace :exercise_publish do - desc "publish exercise and end exercise" - def get_mulscore(question, user) - ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) - arr = [] - ecs.each do |ec| - arr << ec.exercise_choice.choice_position - end - #arr = arr.sort - str = arr.sort.join("") - return str - end - - def tran_base64_decode64 str - if str.blank? - str - else - s_size = str.size % 4 - if s_size != 0 - str += "=" * (4 - s_size) - end - Base64.decode64(str.tr("-_", "+/")).force_encoding("utf-8") - end - end - - #计算试卷的总分和试卷的答题状态 - # def calculate_student_score(exercise,user) - # score1 = 0.0 #选择题/判断题 - # score2 = 0.0 #填空题 - # score5 = 0.0 #实训题 - # ques_stand = [] #问题是否正确 - # exercise_questions = exercise.exercise_questions - # exercise_questions.each do |q| - # if q.question_type != 5 - # answers_content = q.exercise_answers.search_answer_users("user_id",user.id) #学生的答案 - # else - # answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user.id) #学生的答案 - # end - # if q.question_type <= 2 #为选择题或判断题时 - # 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.count > 0 - # multi_each_score = (q.question_score / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 - # else - # multi_each_score = 0.0 - # end - # answers_content.update_all(:score => multi_each_score) - # score1 = score1 + q.question_score - # end - # elsif q.question_type == 3 #填空题 - # null_standard_answer = q.exercise_standard_answers - # standard_answer_array = null_standard_answer.select(:exercise_choice_id,:answer_text) - # standard_answer_ids = standard_answer_array.pluck(:exercise_choice_id).reject(&:blank?).uniq #标准答案的exercise_choice_id数组 - # standard_answer_count = standard_answer_ids.count - # if standard_answer_count > 0 #存在标准答案时才有分数 - # each_standard_score = (q.question_score.to_f / standard_answer_count).round(1) #每一空的得分 - # else - # each_standard_score = 0.0 - # end - # if q.is_ordered - # answers_content.each do |u| - # i_standard_answer = standard_answer_array.where(exercise_choice_id:u.exercise_choice_id).pluck(:answer_text).reject(&:blank?).map!(&:downcase) #该选项的全部标准答案 - # if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数 - # u.update_attribute("score",each_standard_score) - # score2 = score2 + each_standard_score - # end - # end - # else - # st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map!(&:downcase) - # answers_content.each do |u| - # u_answer_text = u.answer_text.downcase - # if st_answer_text.include?(u_answer_text) #只要标准答案包含用户的答案,就有分数。同时,下一次循环时,就会删除该标准答案。防止用户的相同答案获分 - # u.update_attribute("score",each_standard_score) - # score2 = score2 + each_standard_score - # st_answer_text.delete(u_answer_text) - # end - # end - # 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 - # answer_status = 0 - # cha_path = challenge_path exercise_cha.challenge.path - # if game.status == 2 && game.final_score >= 0 - # exercise_cha_score = game.real_score exercise_cha.question_score #每一关卡的得分 - # answer_status = 1 - # end - # if exercise_cha.exercise_shixun_answers.search_shixun_answers("user_id",user.id).blank? #把关卡的答案存入试卷的实训里 - # 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(exercise_cha.shixun.repo_path,cha_path) - # end - # sx_option = { - # :exercise_question_id => q.id, - # :exercise_shixun_challenge_id => exercise_cha.id, - # :user_id => user.id, - # :score => exercise_cha_score, - # :answer_text => code, - # :status => answer_status - # } - # ex_shixun_answer = ExerciseShixunAnswer.new(sx_option) - # ex_shixun_answer.save! - # end - # score5 += exercise_cha_score - # end - # end - # end - # user_scores = answers_content.score_reviewed.pluck(:score).sum - # if user_scores > 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 #每个问题的总得分 - # } - # ques_stand.push(ques_option) - # end - # total_score = score1 + score2 + score5 - # { - # "total_score":total_score, - # "stand_status":ques_stand - # } - # end - - task :publish => :environment do - Rails.logger.info("log--------------------------------exercise_publish start") - puts "--------------------------------exercise_publish start" - exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) - exercises.each do |exercise| - exercise.update_column('exercise_status', 2) - course = exercise.course - tid_str = "" - course.teachers.find_each do |member| - tid_str += "," if tid_str != "" - tid_str += "(#{member.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - if exercise.unified_setting - course.student.find_each do |student| - tid_str += "," if tid_str != "" - tid_str += "(#{student.student_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - end - if tid_str != "" - tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str - ActiveRecord::Base.connection.execute tid_sql - end - - if exercise.exercise_users.count == 0 - str = "" - course.student.find_each do |student| - str += "," if str != "" - str += "(#{student.user_id}, #{exercise.id}, 0, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - - if str != "" - sql = "insert into exercise_users (user_id, exercise_id, commit_status, created_at, updated_at) values" + str - ActiveRecord::Base.connection.execute sql - end - end - - if exercise.course_acts.size == 0 - exercise.course_acts << CourseActivity.new(:user_id => exercise.user_id,:course_id => exercise.course_id) - end - end - - # 分组设置发布时间的测验 - exercise_group_settings = ExerciseGroupSetting.where("publish_time < ? and publish_time > ?", Time.now + 1800, Time.now - 1800) - exercise_group_settings.each do |exercise_group| - exercise = exercise_group.exercise - if exercise.present? - course = exercise.course - exercise.update_attributes(:exercise_status => 2) if exercise.exercise_status == 1 - tid_str = "" - members = course.students.where(:course_group_id => exercise_group.course_group_id) - members.find_each do |member| - tid_str += "," if tid_str != "" - tid_str += "(#{member.user_id},#{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - if tid_str != "" - tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str - ActiveRecord::Base.connection.execute tid_sql - end - end - end - Rails.logger.info("log--------------------------------exercise_publish end") - puts "--------------------------------exercise_publish end" - end - - task :end => :environment do - # include ExercisesHelper - # include ApplicationController - - exercises = Exercise.where("end_time <=? and exercise_status = 2",Time.now) - exercises.each do |exercise| - course = exercise.course - exercise.update_column('exercise_status', 3) - - exercise.exercise_users.each do |exercise_user| - if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? - exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true) - - s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] - exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) - if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? - exercise_user.update_attributes(:subjective_score => 0) - end - end - end - end - - all_exercises = Exercise.where("end_time > ? and exercise_status = 2",Time.now) - exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")" - ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}").each do |exercise_setting| - exercise = exercise_setting.exercise - - users = exercise.course.students.where(:course_group_id => exercise_setting.course_group_id) - exercise_users = exercise.exercise_users.where(:user_id => users.map(&:user_id)) - - exercise_users.each do |exercise_user| - if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? - exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true) - - s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] - exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) - if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? - exercise_user.update_attributes(:subjective_score => 0) - end - end - end - end - Rails.logger.info("log--------------------------------exercise_end completed") - end -end +# #coding=utf-8 +# +# namespace :exercise_publish do +# desc "publish exercise and end exercise" +# def get_mulscore(question, user) +# ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id) +# arr = [] +# ecs.each do |ec| +# arr << ec.exercise_choice.choice_position +# end +# #arr = arr.sort +# str = arr.sort.join("") +# return str +# end +# +# def tran_base64_decode64 str +# if str.blank? +# str +# else +# s_size = str.size % 4 +# if s_size != 0 +# str += "=" * (4 - s_size) +# end +# Base64.decode64(str.tr("-_", "+/")).force_encoding("utf-8") +# end +# end +# +# #计算试卷的总分和试卷的答题状态 +# def calculate_student_score(exercise,user) +# score1 = 0.0 #选择题/判断题 +# score2 = 0.0 #填空题 +# score5 = 0.0 #实训题 +# ques_stand = [] #问题是否正确 +# exercise_questions = exercise.exercise_questions +# exercise_questions.each do |q| +# if q.question_type != 5 +# answers_content = q.exercise_answers.search_answer_users("user_id",user.id) #学生的答案 +# else +# answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user.id) #学生的答案 +# end +# if q.question_type <= 2 #为选择题或判断题时 +# 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.count > 0 +# multi_each_score = (q.question_score / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 +# else +# multi_each_score = 0.0 +# end +# answers_content.update_all(:score => multi_each_score) +# score1 = score1 + q.question_score +# end +# elsif q.question_type == 3 #填空题 +# null_standard_answer = q.exercise_standard_answers +# standard_answer_array = null_standard_answer.select(:exercise_choice_id,:answer_text) +# standard_answer_ids = standard_answer_array.pluck(:exercise_choice_id).reject(&:blank?).uniq #标准答案的exercise_choice_id数组 +# standard_answer_count = standard_answer_ids.count +# if standard_answer_count > 0 #存在标准答案时才有分数 +# each_standard_score = (q.question_score.to_f / standard_answer_count).round(1) #每一空的得分 +# else +# each_standard_score = 0.0 +# end +# if q.is_ordered +# answers_content.each do |u| +# i_standard_answer = standard_answer_array.where(exercise_choice_id:u.exercise_choice_id).pluck(:answer_text).reject(&:blank?).map!(&:downcase) #该选项的全部标准答案 +# if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数 +# u.update_attribute("score",each_standard_score) +# score2 = score2 + each_standard_score +# end +# end +# else +# st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map!(&:downcase) +# answers_content.each do |u| +# u_answer_text = u.answer_text.downcase +# if st_answer_text.include?(u_answer_text) #只要标准答案包含用户的答案,就有分数。同时,下一次循环时,就会删除该标准答案。防止用户的相同答案获分 +# u.update_attribute("score",each_standard_score) +# score2 = score2 + each_standard_score +# st_answer_text.delete(u_answer_text) +# end +# end +# 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 +# answer_status = 0 +# cha_path = exercise_cha.challenge.path.present? ? exercise_cha.challenge.path.split(";").reject(&:blank?) : [] +# if game.status == 2 && game.final_score >= 0 +# exercise_cha_score = game.real_score exercise_cha.question_score #每一关卡的得分 +# answer_status = 1 +# end +# if exercise_cha.exercise_shixun_answers.search_shixun_answers("user_id",user.id).blank? #把关卡的答案存入试卷的实训里 +# 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 +# begin +# content = GitService.file_content(repo_path: exercise_cha.shixun.repo_path, path: cha_path)["content"] +# decode_content = nil +# if content.present? +# content = Base64.decode64(content) +# cd = CharDet.detect(content) +# decode_content = +# if cd["encoding"] == 'GB18030' && cd['confidence'] > 0.8 +# content.encode('UTF-8', 'GBK', {:invalid => :replace, :undef => :replace, :replace => ' '}) +# else +# content.force_encoding('UTF-8') +# end +# end +# decode_content +# rescue Exception => e +# uid_logger_error(e.message) +# raise Educoder::TipException.new("文档内容获取异常") +# end +# code = git_fle_content(exercise_cha.shixun.repo_path,cha_path) +# end +# sx_option = { +# :exercise_question_id => q.id, +# :exercise_shixun_challenge_id => exercise_cha.id, +# :user_id => user.id, +# :score => exercise_cha_score, +# :answer_text => code, +# :status => answer_status +# } +# ex_shixun_answer = ExerciseShixunAnswer.new(sx_option) +# ex_shixun_answer.save! +# end +# score5 += exercise_cha_score +# end +# end +# end +# user_scores = answers_content.score_reviewed.pluck(:score).sum +# if user_scores > 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 #每个问题的总得分 +# } +# ques_stand.push(ques_option) +# end +# total_score = score1 + score2 + score5 +# { +# "total_score":total_score, +# "stand_status":ques_stand +# } +# end +# +# task :publish => :environment do +# Rails.logger.info("log--------------------------------exercise_publish start") +# puts "--------------------------------exercise_publish start" +# exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) +# exercises.each do |exercise| +# exercise.update_column('exercise_status', 2) +# course = exercise.course +# tid_str = "" +# course.teachers.find_each do |member| +# tid_str += "," if tid_str != "" +# tid_str += "(#{member.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" +# end +# if exercise.unified_setting +# course.student.find_each do |student| +# tid_str += "," if tid_str != "" +# tid_str += "(#{student.student_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" +# end +# end +# if tid_str != "" +# tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str +# ActiveRecord::Base.connection.execute tid_sql +# end +# +# if exercise.exercise_users.count == 0 +# str = "" +# course.student.find_each do |student| +# str += "," if str != "" +# str += "(#{student.user_id}, #{exercise.id}, 0, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" +# end +# +# if str != "" +# sql = "insert into exercise_users (user_id, exercise_id, commit_status, created_at, updated_at) values" + str +# ActiveRecord::Base.connection.execute sql +# end +# end +# +# if exercise.course_acts.size == 0 +# exercise.course_acts << CourseActivity.new(:user_id => exercise.user_id,:course_id => exercise.course_id) +# end +# end +# +# # 分组设置发布时间的测验 +# exercise_group_settings = ExerciseGroupSetting.where("publish_time < ? and publish_time > ?", Time.now + 1800, Time.now - 1800) +# exercise_group_settings.each do |exercise_group| +# exercise = exercise_group.exercise +# if exercise.present? +# course = exercise.course +# exercise.update_attributes(:exercise_status => 2) if exercise.exercise_status == 1 +# tid_str = "" +# members = course.students.where(:course_group_id => exercise_group.course_group_id) +# members.find_each do |member| +# tid_str += "," if tid_str != "" +# tid_str += "(#{member.user_id},#{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" +# end +# if tid_str != "" +# tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str +# ActiveRecord::Base.connection.execute tid_sql +# end +# end +# end +# Rails.logger.info("log--------------------------------exercise_publish end") +# puts "--------------------------------exercise_publish end" +# end +# +# task :end => :environment do +# # include ExercisesHelper +# # include ApplicationController +# +# exercises = Exercise.where("end_time <=? and exercise_status = 2",Time.now) +# exercises.each do |exercise| +# course = exercise.course +# exercise.update_column('exercise_status', 3) +# +# exercise.exercise_users.each do |exercise_user| +# if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? +# exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true) +# +# s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] +# exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) +# if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? +# exercise_user.update_attributes(:subjective_score => 0) +# end +# end +# end +# end +# +# all_exercises = Exercise.where("end_time > ? and exercise_status = 2",Time.now) +# exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")" +# ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}").each do |exercise_setting| +# exercise = exercise_setting.exercise +# +# users = exercise.course.students.where(:course_group_id => exercise_setting.course_group_id) +# exercise_users = exercise.exercise_users.where(:user_id => users.map(&:user_id)) +# +# exercise_users.each do |exercise_user| +# if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? +# exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true) +# +# s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] +# exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) +# if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? +# exercise_user.update_attributes(:subjective_score => 0) +# end +# end +# end +# end +# Rails.logger.info("log--------------------------------exercise_end completed") +# end +# end From 6adf1254505df7cb989ed2f98050cbfdfab2dc15 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 21 Jun 2019 14:04:05 +0800 Subject: [PATCH 0050/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E4=B8=80=E4=BA=9B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 2 ++ app/controllers/shixuns_controller.rb | 2 +- app/models/user.rb | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cffe2df15..23b3f02f8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -258,6 +258,8 @@ class ApplicationController < ActionController::Base end def user_setup + # reacct静态资源加载不需要走这一步 + return if params[:controller] == "main" # Find the current user User.current = find_current_user uid_logger("user_step: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous")) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 00ae559b1..32a314c54 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -1,5 +1,5 @@ class ShixunsController < ApplicationController - before_action :require_login, except: [:download_file, :index] + before_action :require_login, except: [:download_file, :index, :menus] # before_action :check_auth, except: [:download_file, :index] before_action :find_shixun, except: [:index, :new, :create, :menus, :get_recommend_shixuns, :propaedeutics, diff --git a/app/models/user.rb b/app/models/user.rb index 60765b852..ece69dc02 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -388,10 +388,10 @@ class User < ApplicationRecord # 用户是否有权限查看实训 def shixun_permission(shixun) # 性能优化:先处理不需要权限的实训(已发布并且没有单位权限限制的实训) - return true if manager_of_shixun?(shixun) # 实训管理员 return false if shixun.status != 2 || shixun.hidden # 隐藏或者未发布的实训:false return true if shixun.use_scope == 0 # 对所有学校公开 - return true if shixun.use_scope == 1 && shixun.shixun_schools.exists?(school_id: school_id) # 对部分高校公开 + return true if shixun.use_scope == 1 && (manager_of_shixun?(shixun) || shixun.shixun_schools.exists?(school_id: school_id)) # 对部分高校公开 + # return true if manager_of_shixun?(shixun) # 实训管理员 return false end From 75fae4b3cc3c597851f0ce94fee2d7b8193ab323 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Jun 2019 14:13:09 +0800 Subject: [PATCH 0051/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=AF=84=E5=88=86?= =?UTF-8?q?=E4=B8=8D=E6=98=BE=E7=A4=BA=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/views/shixuns/_top.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shixuns/_top.json.jbuilder b/app/views/shixuns/_top.json.jbuilder index 7c006cccf..bd23365e5 100644 --- a/app/views/shixuns/_top.json.jbuilder +++ b/app/views/shixuns/_top.json.jbuilder @@ -13,7 +13,7 @@ json.name shixun.name json.stu_num shixun.myshixuns_count json.experience shixun.all_score json.diffcult diff_to_s(shixun.trainee) -json.score_info shixun.averge_star +json.score_info shixun.shixun_preference_info # 用于是否显示导航栏中的'背景知识' json.propaedeutics shixun.propaedeutics.present? ? true : false From aab6a3f00d8859b80934150f2c518990937441b5 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Jun 2019 14:19:18 +0800 Subject: [PATCH 0052/1015] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shixuns/_top.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shixuns/_top.json.jbuilder b/app/views/shixuns/_top.json.jbuilder index bd23365e5..f741e9021 100644 --- a/app/views/shixuns/_top.json.jbuilder +++ b/app/views/shixuns/_top.json.jbuilder @@ -13,7 +13,7 @@ json.name shixun.name json.stu_num shixun.myshixuns_count json.experience shixun.all_score json.diffcult diff_to_s(shixun.trainee) -json.score_info shixun.shixun_preference_info +json.score_info shixun.shixun_preference_info # todo: 这块可以改成只显示实训的平均分,不用每次都去取每种星的分数了。 # 用于是否显示导航栏中的'背景知识' json.propaedeutics shixun.propaedeutics.present? ? true : false From b1b9d7103bfc26a2adb420c1934c18063aa65bc9 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 14:32:57 +0800 Subject: [PATCH 0053/1015] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E4=BC=98=E5=8C=96=E3=80=81=E8=AF=BE=E5=A0=82=E7=9A=84?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E9=9A=90=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 6 +++--- app/models/homework_common.rb | 3 ++- db/migrate/20190621062948_migrate_course_module_activity.rb | 5 +++++ 3 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20190621062948_migrate_course_module_activity.rb diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index d3ece9feb..c0d72e1ee 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -90,13 +90,13 @@ class HomeworkCommonsController < ApplicationController if @homework_type == 4 if @user_course_identity == Course::STUDENT - @homework_commons = @homework_commons.includes(:homework_detail_manual, :homework_group_settings, :shixuns, + @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns, student_works: [myshixun: [:games]]) else - @homework_commons = @homework_commons.includes(:homework_detail_manual, :homework_group_settings, :shixuns, :student_works) + @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns, :student_works) end else - @homework_commons = @homework_commons.includes(:homework_detail_manual, :homework_group_settings, :homework_detail_group, + @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :homework_detail_group, :student_works) end end diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 74d85e2ae..d67b6e0fd 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -2,6 +2,7 @@ class HomeworkCommon < ApplicationRecord # homework_type 1:普通作业 2:编程作业(弃用) 3:分组作业 4:实训作业 enum homework_type: { normal: 1, program: 2, group: 3, practice: 4 }, _suffix: true has_many :homework_group_settings, dependent: :destroy + has_many :published_settings, -> { group_published }, class_name: "HomeworkGroupSetting" has_many :student_works, -> { where("is_delete != 1") } has_one :homework_detail_manual, dependent: :destroy @@ -78,7 +79,7 @@ class HomeworkCommon < ApplicationRecord def all_works student_works = self.unified_setting ? self.student_works : self.student_works.where(user_id: self.course.students.where( - course_group_id: self.homework_group_settings.group_published.pluck(:course_group_id)). + course_group_id: self.published_settings.pluck(:course_group_id)). pluck(:user_id)) end diff --git a/db/migrate/20190621062948_migrate_course_module_activity.rb b/db/migrate/20190621062948_migrate_course_module_activity.rb new file mode 100644 index 000000000..1fa1ea112 --- /dev/null +++ b/db/migrate/20190621062948_migrate_course_module_activity.rb @@ -0,0 +1,5 @@ +class MigrateCourseModuleActivity < ActiveRecord::Migration[5.2] + def change + CourseModule.where(module_type: 'activity').update_all(hidden: 1) + end +end \ No newline at end of file From a67bb19f496231ecc66413e9864a80bbec96062e Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 14:43:58 +0800 Subject: [PATCH 0054/1015] =?UTF-8?q?=E7=94=A8=E6=88=B7url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/courses/teachers.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/courses/teachers.json.jbuilder b/app/views/courses/teachers.json.jbuilder index 25df05097..1be1ce16c 100644 --- a/app/views/courses/teachers.json.jbuilder +++ b/app/views/courses/teachers.json.jbuilder @@ -2,7 +2,7 @@ json.teacher_list do json.array! @teacher_list do |teacher| json.course_member_id teacher.id json.name teacher.user.real_name - json.name_link user_path(teacher.user.login) + json.name_link user_path(teacher.user) json.login teacher.user.login json.user_id teacher.user.id json.role teacher.role == "CREATOR" ? "管理员" : teacher.role == "PROFESSOR" ? "教师" : "助教" From 6e1b595b0a017e50b08b1ae7943836ec5ab3303f Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 21 Jun 2019 14:52:44 +0800 Subject: [PATCH 0055/1015] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E6=8E=92=E5=BA=8F?= 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 cb3b5c929..ef52632e7 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -52,7 +52,7 @@ class CoursesController < ApplicationController # u.login), s.name from courses c, users u, user_extensions ue, schools s where c.is_delete=0 and # c.tea_id=u.id and u.id=ue.user_id and ue.school_id=s.id") - @courses = Course.where(is_delete: 0, is_hidden: 0).includes(:course_modules, :course_members, teacher: [user_extension: :school]) + @courses = Course.where(is_delete: 0, is_hidden: 0).includes(:course_modules, :course_members, teacher: [user_extension: :school]).order("courses.id = 1309 desc, courses.created_at desc") # @courses = Course.where(is_delete: 0, is_hidden: 0).select("courses.id, courses.tea_id, courses.name, courses.exercises_count, courses.polls_count, # courses.is_public, courses.is_end, courses.visits, courses.course_members_count,courses.homework_commons_count,(SELECT MAX(created_at) From f8f3aefd0d4163fe14b6f8ce893bd286318e5517 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Jun 2019 15:09:39 +0800 Subject: [PATCH 0056/1015] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 7 +++++-- app/views/shixuns/_top.json.jbuilder | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index ef52632e7..3d0926994 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -52,7 +52,9 @@ class CoursesController < ApplicationController # u.login), s.name from courses c, users u, user_extensions ue, schools s where c.is_delete=0 and # c.tea_id=u.id and u.id=ue.user_id and ue.school_id=s.id") - @courses = Course.where(is_delete: 0, is_hidden: 0).includes(:course_modules, :course_members, teacher: [user_extension: :school]).order("courses.id = 1309 desc, courses.created_at desc") + @courses = Course.where(is_delete: 0, is_hidden: 0) + .includes(:course_modules, :course_members, teacher: [user_extension: :school]) + .order("courses.id = 1309 desc, courses.created_at desc") # @courses = Course.where(is_delete: 0, is_hidden: 0).select("courses.id, courses.tea_id, courses.name, courses.exercises_count, courses.polls_count, # courses.is_public, courses.is_end, courses.visits, courses.course_members_count,courses.homework_commons_count,(SELECT MAX(created_at) @@ -87,7 +89,8 @@ class CoursesController < ApplicationController (course_members.role in(1,2,3) and CONCAT(users.lastname, users.firstname) like :keyword) or courses.name like :keyword or schools.name like :keyword } - @courses = @courses.joins(course_members: [user: [user_extension: :school]]).where("#{sql}", keyword: "%#{params[:search]}%").distinct + @courses = @courses.joins(course_members: [user: [user_extension: :school]]) + .where("#{sql}", keyword: "%#{params[:search]}%").distinct end @courses_count = @courses.size diff --git a/app/views/shixuns/_top.json.jbuilder b/app/views/shixuns/_top.json.jbuilder index f741e9021..ef15e2515 100644 --- a/app/views/shixuns/_top.json.jbuilder +++ b/app/views/shixuns/_top.json.jbuilder @@ -15,5 +15,4 @@ json.experience shixun.all_score json.diffcult diff_to_s(shixun.trainee) json.score_info shixun.shixun_preference_info # todo: 这块可以改成只显示实训的平均分,不用每次都去取每种星的分数了。 # 用于是否显示导航栏中的'背景知识' -json.propaedeutics shixun.propaedeutics.present? ? true : false - +json.propaedeutics shixun.propaedeutics.present? From dade4b8c27d31880b0235f338977f1a4c1008b5d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 15:29:13 +0800 Subject: [PATCH 0057/1015] =?UTF-8?q?=E5=88=86=E7=BB=84=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BD=9C=E5=93=81=E6=B7=BB=E5=8A=A0=E6=88=90?= =?UTF-8?q?=E5=91=98=E6=97=B6=E8=BF=87=E6=BB=A4=E6=8E=89=E6=9C=AA=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E7=9A=84=E5=88=86=E7=8F=AD=E5=AD=A6=E7=94=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 46e87e632..4d98ea02b 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -41,14 +41,16 @@ class StudentWorksController < ApplicationController # 搜索课堂学生 def search_member_list + # 统一设置的作业取所有学生,否则取已发布的分班学生 + students = @homework.unified_setting? ? @course.students : @course.students.where(course_group_id: @homework.published_settings.pluck(:course_group_id)) unless params[:search].blank? - @members = @course.students.joins(:user).where("user_id != #{current_user.id} and + @members = students.joins(:user).where("user_id != #{current_user.id} and concat(users.lastname, users.firstname) like ?", "%#{params[:search]}%") else # 没有搜索条件时搜索课堂所有未提交的学生 user_ids = @homework.student_works.where("work_status = 0").pluck(:user_id) - [current_user.id] - @members = @course.students.where(user_id: user_ids) + @members = students.where(user_id: user_ids) end page = params[:page] ? params[:page].to_i : 1 From ed891522fffd7c1236c0cbd4a514d13465016c87 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 21 Jun 2019 15:40:54 +0800 Subject: [PATCH 0058/1015] logger --- README.md | 5 +++++ app/controllers/application_controller.rb | 1 + config/environments/production.rb | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1aa92e1f5..8dcb6d131 100644 --- a/README.md +++ b/README.md @@ -62,3 +62,8 @@ testeduplus2.educoder.net/games/* # 文件上传:ActiveStorage # 新能:bootsnap + +# 注意事项: +# 第一次部署需要执行一些rake任务 +# 配置redis地址 +# 配置gitlab/intializers/gitlab_config.yml \ No newline at end of file diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a3a278e0d..98dd577a1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -244,6 +244,7 @@ class ApplicationController < ActionController::Base # Returns the current user or nil if no user is logged in # and starts a session if needed def find_current_user + uid_logger("user setup start: session[:user_id] is #{session[:user_id]}") if session[:user_id] # existing session (User.active.find(session[:user_id]) rescue nil) diff --git a/config/environments/production.rb b/config/environments/production.rb index 38938b7e3..e6c21345b 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -96,7 +96,7 @@ Rails.application.configure do config.active_record.belongs_to_required_by_default = false # config.cache_store = :file_store, "#{Rails.root }/files/cache_store/" - config.cache_store = :redis_store, 'redis://10.9.72.102:6379/0/cache', { expires_in: 90.minutes } + config.cache_store = :redis_store, 'redis://`10.9.72.102:637`9/0/cache', { expires_in: 90.minutes } config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { From 2de80c4a641e1c0976a07fc04aeaa1c626b2b9e6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 15:43:31 +0800 Subject: [PATCH 0059/1015] =?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/student_works_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 4d98ea02b..15b59e863 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -44,8 +44,8 @@ class StudentWorksController < ApplicationController # 统一设置的作业取所有学生,否则取已发布的分班学生 students = @homework.unified_setting? ? @course.students : @course.students.where(course_group_id: @homework.published_settings.pluck(:course_group_id)) unless params[:search].blank? - @members = students.joins(:user).where("user_id != #{current_user.id} and - concat(users.lastname, users.firstname) like ?", "%#{params[:search]}%") + @members = students.joins(user: :user_extensions).where("user_id != #{current_user.id} and (concat(users.lastname, users.firstname) + like ? or user_extensions.student_id like ?)", "%#{params[:search]}%", "%#{params[:search]}%") else # 没有搜索条件时搜索课堂所有未提交的学生 From eb7655d0517a03ea55554b5ee552512feaad2bef Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 21 Jun 2019 15:46:28 +0800 Subject: [PATCH 0060/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/tasks/exercise_publish_task.rb | 68 ++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 17 deletions(-) diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb index d0a52646b..7f3ee63ee 100644 --- a/app/tasks/exercise_publish_task.rb +++ b/app/tasks/exercise_publish_task.rb @@ -67,41 +67,75 @@ class ExercisePublishTask end def end - exercises = Exercise.where("end_time <=? and exercise_status = 2",Time.now) + exercises = Exercise.where("end_time <= ? and exercise_status = ?",Time.now,2) exercises.each do |exercise| course = exercise.course - exercise.update_column('exercise_status', 3) - + ex_type = exercise.exercise_questions.pluck(:question_type).uniq + exercise.update_attribute('exercise_status', 3) exercise.exercise_users.each do |exercise_user| if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? - exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true) - + # exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true) s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] - exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) - if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? - exercise_user.update_attributes(:subjective_score => 0) + if ex_type.include?(4) #是否包含主观题 + subjective_score = exercise_user.subjective_score + else + subjective_score = -1.0 end + # subjective_score = exercise_user.subjective_score + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = s_score + total_score_subjective_score + commit_option = { + :status => 1, + :commit_status => 1, + :end_at => Time.now, + :objective_score => s_score, + :score => total_score, + :subjective_score => subjective_score + } + exercise_user.update_attributes(commit_option) + # if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? + # exercise_user.update_attributes(:subjective_score => 0) + # end end end end - all_exercises = Exercise.where("end_time > ? and exercise_status = 2",Time.now) + all_exercises = Exercise.where("end_time > ? and exercise_status = ?",Time.now,2) exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")" - ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}").each do |exercise_setting| + ex_group_settings = ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}") + ex_group_settings.each do |exercise_setting| exercise = exercise_setting.exercise - + ex_types = exercise.exercise_questions.pluck(:question_type).uniq users = exercise.course.students.where(:course_group_id => exercise_setting.course_group_id) exercise_users = exercise.exercise_users.where(:user_id => users.map(&:user_id)) exercise_users.each do |exercise_user| if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? - exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true) - - s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] - exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) - if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? - exercise_user.update_attributes(:subjective_score => 0) + if ex_types.include?(4) #是否包含主观题 + subjective_score = exercise_user.subjective_score + else + subjective_score = -1.0 end + s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] + # subjective_score = exercise_user.subjective_score + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = s_score + total_score_subjective_score + commit_option = { + :status => 1, + :commit_status => 1, + :end_at => Time.now, + :objective_score => s_score, + :score => total_score, + :subjective_score => subjective_score + } + exercise_user.update_attributes(commit_option) + # exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true) + + # s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] + # exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) + # if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? + # exercise_user.update_attributes(:subjective_score => 0.0) + # end end end end From 32e2872bbd73431f7bf1805e195367329b316784 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 21 Jun 2019 15:48:55 +0800 Subject: [PATCH 0061/1015] modify users controller code --- app/controllers/users_controller.rb | 27 ++++++++++----------- app/views/users/reply_message.json.jbuilder | 1 - 2 files changed, 13 insertions(+), 15 deletions(-) delete mode 100644 app/views/users/reply_message.json.jbuilder diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 17281087b..d01973175 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -9,10 +9,6 @@ class UsersController < ApplicationController @user = User.find params[:id] @user.update!(user_params) render_ok - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback end # 贴吧获取用户信接口 @@ -69,21 +65,24 @@ class UsersController < ApplicationController # 用户回复功能 def reply_message - @message = JournalsForMessage.new(reply_message_params) - @message.user_id = current_user.id - @message.save! - #normal_status("回复成功") + message = JournalsForMessage.new(reply_message_params) + message.user_id = current_user.id + message.save! + + render_ok(id: message.id) end # 搜索用户具有管理员角色的项目 def search_user_projects - condition = '%%' - condition = "%#{params[:search].strip}%".gsub(" ","") if !params[:search].blank? + projects = Project.where.not(status: 9) + + projects = projects.joins(members: :member_roles).where(member_roles: { role_id: 3 }) + projects = projects.where(members: { user_id: current_user.id }) + + search = params[:search].to_s.strip + projects = projects.where('projects.name LIKE ?', "%#{search}%") if search.present? - project_ids = Project.find_by_sql("SELECT p.id FROM projects p, members m, member_roles mr WHERE m.project_id = p.id - AND m.id=mr.member_id AND mr.role_id = 3 AND m.user_id=#{current_user.id} AND p.status != 9 and - p.name like '#{condition}'") - @projects = Project.where(id: project_ids.pluck(:id)) + @projects = projects.select(:id, :name) end # 个人主页信息 diff --git a/app/views/users/reply_message.json.jbuilder b/app/views/users/reply_message.json.jbuilder deleted file mode 100644 index 26052baa8..000000000 --- a/app/views/users/reply_message.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.id @message.id \ No newline at end of file From 62d2e5c6f58db77efae96d0501ba6347b6bbaad4 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 21 Jun 2019 15:49:39 +0800 Subject: [PATCH 0062/1015] redis yml --- .gitignore | 1 + config/redis.yml | 12 ------------ 2 files changed, 1 insertion(+), 12 deletions(-) delete mode 100644 config/redis.yml diff --git a/.gitignore b/.gitignore index ecc3e003a..b2e36f7ee 100644 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,7 @@ /public/images/avatars /config/secrets.yml +/config/redis.yml /files/archiveZip/* /files/cache_store/* public/upload.html diff --git a/config/redis.yml b/config/redis.yml deleted file mode 100644 index 71e61cfd9..000000000 --- a/config/redis.yml +++ /dev/null @@ -1,12 +0,0 @@ -defaults: &defaults - url: <%= ENV["REDIS_URL"] || "redis://localhost:6379/0" %> - -development: - <<: *defaults - -test: - <<: *defaults - -production: - <<: *defaults - url: redis://10.9.72.102:6379/0/job \ No newline at end of file From 8ed6eee7d8362442f5e4f05629825b953170c7ff Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 21 Jun 2019 15:51:53 +0800 Subject: [PATCH 0063/1015] .. --- config/environments/production.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index e6c21345b..38938b7e3 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -96,7 +96,7 @@ Rails.application.configure do config.active_record.belongs_to_required_by_default = false # config.cache_store = :file_store, "#{Rails.root }/files/cache_store/" - config.cache_store = :redis_store, 'redis://`10.9.72.102:637`9/0/cache', { expires_in: 90.minutes } + config.cache_store = :redis_store, 'redis://10.9.72.102:6379/0/cache', { expires_in: 90.minutes } config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { From cd41197a46d22795a5f4201bbb544b5a21d6f9e2 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 21 Jun 2019 15:57:18 +0800 Subject: [PATCH 0064/1015] redis init --- config/environments/production.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index 38938b7e3..c3950f345 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -96,7 +96,7 @@ Rails.application.configure do config.active_record.belongs_to_required_by_default = false # config.cache_store = :file_store, "#{Rails.root }/files/cache_store/" - config.cache_store = :redis_store, 'redis://10.9.72.102:6379/0/cache', { expires_in: 90.minutes } + config.cache_store = :redis_store, 'redis://r-bp122bd1b710f274.redis.rds.aliyuncs.com:6379/0/cache', { expires_in: 90.minutes } config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { From ac7c1e8ac6af2c49464c3cf6916096542ac8694d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 15:58:45 +0800 Subject: [PATCH 0065/1015] =?UTF-8?q?D=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 15b59e863..9eec32521 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -44,7 +44,7 @@ class StudentWorksController < ApplicationController # 统一设置的作业取所有学生,否则取已发布的分班学生 students = @homework.unified_setting? ? @course.students : @course.students.where(course_group_id: @homework.published_settings.pluck(:course_group_id)) unless params[:search].blank? - @members = students.joins(user: :user_extensions).where("user_id != #{current_user.id} and (concat(users.lastname, users.firstname) + @members = students.joins(user: :user_extension).where("user_id != #{current_user.id} and (concat(users.lastname, users.firstname) like ? or user_extensions.student_id like ?)", "%#{params[:search]}%", "%#{params[:search]}%") else From 6a887e21e3b1507ee5eee75fa72fad5ca2075e57 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 16:01:19 +0800 Subject: [PATCH 0066/1015] =?UTF-8?q?D=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 9eec32521..aa0a0f171 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -44,7 +44,7 @@ class StudentWorksController < ApplicationController # 统一设置的作业取所有学生,否则取已发布的分班学生 students = @homework.unified_setting? ? @course.students : @course.students.where(course_group_id: @homework.published_settings.pluck(:course_group_id)) unless params[:search].blank? - @members = students.joins(user: :user_extension).where("user_id != #{current_user.id} and (concat(users.lastname, users.firstname) + @members = students.joins(user: :user_extension).where("course_members.user_id != #{current_user.id} and (concat(users.lastname, users.firstname) like ? or user_extensions.student_id like ?)", "%#{params[:search]}%", "%#{params[:search]}%") else From 32a9916fc46359565cf0ecdae5a6c311f62e0fc8 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 16:11:00 +0800 Subject: [PATCH 0067/1015] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_homework_public_navigation.json.jbuilder | 5 +++-- app/views/homework_commons/index.json.jbuilder | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/views/homework_commons/_homework_public_navigation.json.jbuilder b/app/views/homework_commons/_homework_public_navigation.json.jbuilder index 09dd076c0..2c803bee8 100644 --- a/app/views/homework_commons/_homework_public_navigation.json.jbuilder +++ b/app/views/homework_commons/_homework_public_navigation.json.jbuilder @@ -3,8 +3,9 @@ json.course_name course.name json.is_end course.is_end json.category homework.category_info member = course.course_members.find_by(user_id: user.id, is_active: 1) -json.homework_status homework_curr_status(homework, user.course_identity(course), course, member, member&.teacher_course_groups)[:status] -json.time_status homework_curr_status(homework, user.course_identity(course), course, member, member&.teacher_course_groups)[:time_status] +curr_status = homework_curr_status(homework, user.course_identity(course), course, member, member&.teacher_course_groups) +json.homework_status curr_status[:status] +json.time_status curr_status[:time_status] json.homework_name homework.name json.homework_id homework.id json.homework_type homework.homework_type diff --git a/app/views/homework_commons/index.json.jbuilder b/app/views/homework_commons/index.json.jbuilder index c9074cc2b..262d4d92d 100644 --- a/app/views/homework_commons/index.json.jbuilder +++ b/app/views/homework_commons/index.json.jbuilder @@ -13,15 +13,16 @@ json.category_name @category.try(:name) json.homeworks @homework_commons.each do |homework| # homework_private = (@user_course_identity > Course::STUDENT) && !homework.is_public + curr_status = homework_curr_status(homework, @user_course_identity, @course, @member, @member&.teacher_course_groups) json.homework_id homework.id json.name homework.name json.private_icon !homework.is_public - json.status homework_curr_status(homework, @user_course_identity, @course, @member, @member&.teacher_course_groups)[:status] - json.status_time homework_curr_status(homework, @user_course_identity, @course, @member, @member&.teacher_course_groups)[:time] - json.time_status homework_curr_status(homework, @user_course_identity, @course, @member, @member&.teacher_course_groups)[:time_status] + json.status curr_status[:status] + json.status_time curr_status[:time] + json.time_status curr_status[:time_status] json.allow_late homework.allow_late - unless homework_curr_status(homework, @user_course_identity, @course, @member, @member&.teacher_course_groups)[:status].include?("未发布") + unless curr_status[:status].include?("未发布") json.commit_count studentwork_count homework, 1, @user.id json.uncommit_count studentwork_count homework, 0, @user.id end From 2b87d06598862af98a31f27c3a87c9f3fb745433 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 16:19:29 +0800 Subject: [PATCH 0068/1015] =?UTF-8?q?=E4=BA=A4=E5=8F=89=E8=AF=84=E9=98=85?= =?UTF-8?q?=E4=BA=BA=E5=8E=BB=E6=8E=89=E5=BD=93=E5=89=8D=E8=80=81=E5=B8=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/graduation_tasks_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 435dbd4ed..3a6762663 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -71,7 +71,7 @@ class GraduationTasksController < ApplicationController @work_list = @task.graduation_works.where(user_id: user_ids).includes(user: [:user_extension]) @all_work_count = @work_list.count - @teachers = @course.teachers + @teachers = @course.teachers.where.not(user_id: current_user.id) # 教师评阅搜索 0: 未评, 1 已评 unless params[:teacher_comment].blank? graduation_work_ids = GraduationWorkScore.where(graduation_work_id: @work_list.map(&:id)).pluck(:graduation_work_id) From 6264af326309883b63207e1447994db662940022 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 16:32:03 +0800 Subject: [PATCH 0069/1015] =?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/homework_commons_controller.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index c0d72e1ee..4c01a7dc0 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -89,12 +89,7 @@ class HomeworkCommonsController < ApplicationController @homework_commons = @homework_commons.page(page).per(15) if @homework_type == 4 - if @user_course_identity == Course::STUDENT - @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns, - student_works: [myshixun: [:games]]) - else - @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns, :student_works) - end + @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns, :student_works) else @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :homework_detail_group, :student_works) From 464956935709ebf0ded574d49059bd1b2358bfc0 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 21 Jun 2019 16:40:21 +0800 Subject: [PATCH 0070/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 4c01a7dc0..bb37283ca 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -89,10 +89,9 @@ class HomeworkCommonsController < ApplicationController @homework_commons = @homework_commons.page(page).per(15) if @homework_type == 4 - @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns, :student_works) + @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns) else - @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :homework_detail_group, - :student_works) + @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :homework_detail_group) end end From 2880e8ac25a3bd5383f40df22044acbe00857605 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 21 Jun 2019 17:04:40 +0800 Subject: [PATCH 0071/1015] =?UTF-8?q?gitlab=E8=BF=81=E7=A7=BB=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/gitlab.rake | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/tasks/gitlab.rake b/lib/tasks/gitlab.rake index 396f197d3..0d872991b 100644 --- a/lib/tasks/gitlab.rake +++ b/lib/tasks/gitlab.rake @@ -10,7 +10,7 @@ namespace :sync do puts repo_name myshixun.update_column(:repo_name, repo_name) rescue Exception => e - Rails.logger.error("e.message") + Rails.logger.error("#{e.message}") end end end @@ -26,7 +26,27 @@ namespace :sync do puts repo_name shixun.update_column(:repo_name, repo_name) rescue Exception => e - Rails.logger.error("e.message") + Rails.logger.error("#{e.message}") + end + end + end + + + task :check => :environment do + g = Gitlab.client + shixuns = Shixun.where("repo_name is null and fork_from is not null") + shixuns.find_each do |shixun| + begin + puts shixun.identifier + original_shixun = Shixun.find(fork_from) + + gshixun = g.fork(original_shixun.gpid, shixun.owner.try(:gid)) + + repo_name = g.project(gshixun.id).path_with_namespace + puts repo_name + shixun.update_attributes(:repo_name => repo_name, :gpid => gshixun.id) + rescue Exception => e + Rails.logger.error("#{e.message}") end end end From 48eab5234f8bb3cf0001b9548166df51994587e8 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 17:04:53 +0800 Subject: [PATCH 0072/1015] =?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/graduation_tasks_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 3a6762663..a1f1d01c4 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -98,7 +98,7 @@ class GraduationTasksController < ApplicationController unless params[:cross_comment].blank? graduation_work_id = @task.graduation_work_comment_assignations.where(:user_id =>current_user.id) .pluck(:graduation_work_id).uniq if @task.graduation_work_comment_assignations - @work_list = @work_list.where(id: graduation_work_id) + @work_list = @task.graduation_works.where(id: graduation_work_id) end # 输入姓名和学号搜索 From 4e65aaa214c647efbe92945fcd2ae92dde4e292b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 21 Jun 2019 17:09:44 +0800 Subject: [PATCH 0073/1015] fix bug --- app/controllers/exercises_controller.rb | 16 +++++++++++----- app/helpers/exercises_helper.rb | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index e2d6110bd..e4204d9d1 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1023,7 +1023,7 @@ class ExercisesController < ApplicationController if @t_user_exercise_status == 3 get_each_student_exercise(@exercise.id,@exercise_questions,@exercise_current_user_id) end - get_user_answer_status(@exercise_questions,@exercise_current_user_id) + get_user_answer_status(@exercise_questions,@exercise_current_user_id,@exercise,@t_user_exercise_status) rescue Exception => e uid_logger_error(e.message) @@ -1117,7 +1117,7 @@ class ExercisesController < ApplicationController @student_status = 0 else @student_status = 1 - get_user_answer_status(@exercise_questions,@exercise_current_user_id) + get_user_answer_status(@exercise_questions,@exercise_current_user_id,@exercise,get_exercise_status) end end end @@ -1685,11 +1685,17 @@ class ExercisesController < ApplicationController end end - def get_user_answer_status(exercise_questions,user_id) + def get_user_answer_status(exercise_questions,user_id,exercise,exercise_user_status) @question_status = [] @exercise_all_questions = [] + ex_question_random = exercise.question_random question_answered = 0 exercise_questions.each_with_index do |q,index| + if ex_question_random && exercise_user_status != 3 + ques_number = index + 1 + else + ques_number = q.question_number + end if q.question_type != 5 ques_vote = q.exercise_answers.search_exercise_answer("user_id",user_id) else @@ -1725,12 +1731,12 @@ class ExercisesController < ApplicationController end question_status = { :ques_id => q.id, - :ques_number => index+1, #仅问题的显示位置变化,但是问题的question_number 不会变化,与之相关的choice/standard_answer/answer不会变化 + :ques_number => ques_number, #仅问题的显示位置变化,但是问题的question_number 不会变化,与之相关的choice/standard_answer/answer不会变化 :ques_status => ques_status, } question_options = { :question => q, - :ques_number => index+1, + :ques_number => ques_number, } @question_status = @question_status.push(question_status).sort_by {|k| k[:ques_number]} @exercise_all_questions = @exercise_all_questions.push(question_options).sort_by {|k| k[:ques_number]} diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 95ec0ac24..53b2fa4c1 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -323,6 +323,7 @@ module ExercisesHelper else show_unreview_count = nil end + logger.info("##########__________exercise_end_time__________###############{exercise_end_time}") if exercise_status == 2 && exercise_end_time.present? ex_left_time = how_much_time(exercise_end_time) From 1543ed0379e170d130b310d47c1511c6e13ec8e2 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 21 Jun 2019 17:13:52 +0800 Subject: [PATCH 0074/1015] git ignore --- .gitignore | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index b2e36f7ee..309e960d7 100644 --- a/.gitignore +++ b/.gitignore @@ -44,8 +44,7 @@ /config/secrets.yml /config/redis.yml -/files/archiveZip/* -/files/cache_store/* + public/upload.html /config/configuration.yml /config/initializers/gitlab_config.rb @@ -55,3 +54,9 @@ vendor/bundle/ .ruby-version .ruby-gemset +/files +/public/images/avatars +/public/files +/workspace +/log + From fb6d114fde7fb9ca30201f2502be462aaef3f65c Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 21 Jun 2019 17:21:25 +0800 Subject: [PATCH 0075/1015] add descendants_count to solve index sort by hot --- app/controllers/messages_controller.rb | 49 ++++++++----------- app/models/message.rb | 17 +++---- app/views/messages/index.json.jbuilder | 5 ++ ...83604_add_descendants_count_to_messages.rb | 5 ++ lib/tasks/course_board_message_count.rake | 17 +++++++ 5 files changed, 53 insertions(+), 40 deletions(-) create mode 100644 db/migrate/20190621083604_add_descendants_count_to_messages.rb diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 98f453424..5569ec165 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -17,17 +17,25 @@ class MessagesController < ApplicationController @page = params[:page] || 1 @page_size = params[:page_size] || 15 - sort = params[:sort] || 0 + sort = params[:sort].to_i == 1 ? 'asc' : 'desc' sort_type = params[:sort_type] || 'time' - sort = sort.to_i - sort_type = sort_type.strip - @messages = @board.messages.root_nodes.by_keywords(params[:search]).includes(:praise_treads, :author, :children) - @messages = @messages.ordered(sort: sort, sort_type: sort_type) - @messages = sort_by_all_replies(sort, sort_type, @messages) + messages = @board.messages.root_nodes.by_keywords(params[:search]) - @messages = sort_by_sticky(@messages) - @messages = Kaminari.paginate_array(@messages).page(@page).per(@page_size) + messages = messages.order('(sticky = 1) DESC') # 置顶 + + messages = + case sort_type + when 'time' then messages.reorder("created_on #{sort}") + when 'hot' then messages.reorder("descendants_count #{sort}") + else messages.reorder("created_on #{sort}") + end + + messages = messages.includes(:author) + @messages = Kaminari.paginate_array(messages).page(@page).per(@page_size) + + ids = @messages.map(&:id) + @praises_count_map = Message.where(root_id: ids).group(:root_id).sum(:praises_count) end def reply_list @@ -43,33 +51,16 @@ class MessagesController < ApplicationController def reply return normal_status(2, "回复内容不能为空") if params[:content].blank? - begin - @reply = Message.create!(board: @message.board, - author: current_user, - parent: @message, - message_detail_attributes: { + @reply = Message.create!(board: @message.board, root: @message.root, author: current_user, parent: @message, + message_detail_attributes: { content: params[:content] - } - ) - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end + }) end def sticky_top return normal_status(403, "您没有权限进行该操作") unless current_user.teacher_of_course?(@message.board.course) - ActiveRecord::Base.transaction do - begin - @message.update_attributes(:sticky => @message.sticky == 1 ? 0 : 1) - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end - end + @message.update_attributes(:sticky => @message.sticky == 1 ? 0 : 1) end def bulk_delete diff --git a/app/models/message.rb b/app/models/message.rb index d3d507a72..c3b3bca40 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -4,6 +4,8 @@ class Message < ApplicationRecord belongs_to :board, counter_cache: true belongs_to :author, class_name: "User", foreign_key: 'author_id' belongs_to :parent, class_name: "Message", foreign_key: "parent_id", counter_cache: :replies_count, optional: true + belongs_to :root, class_name: 'Message', foreign_key: :root_id, counter_cache: :descendants_count, optional: true + has_one :message_detail, dependent: :destroy accepts_nested_attributes_for :message_detail, update_only: true @@ -12,6 +14,7 @@ class Message < ApplicationRecord has_many :tidings, as: :container, dependent: :destroy has_many :attachments, as: :container, dependent: :destroy has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy # 课程动态 + has_many :descendants, class_name: 'Message', foreign_key: :root_id, dependent: :destroy scope :root_nodes, -> { where("parent_id IS NULL") } #判断该信息是帖子还是回复。null为发布的帖子 scope :reply_nodes, -> { where("parent_id IS NOT NULL") } @@ -70,24 +73,16 @@ class Message < ApplicationRecord # 包含二级回复的总点赞数 def total_praises_count - praises_count + children.includes(:children).reduce(0) { |count, filed| - sub_sum_count = filed.children.reduce(0) { |sub_count, sub_filed| sub_count += sub_filed.praises_count } - count += filed.praises_count - sub_sum_count += count - } + descendants.sum(:praises_count) end # 包含二级回复数的总回复数 def total_replies_count - replies_count + children.includes(:children).reduce(0) { |count, child| - sub_sum_count = child.children.reduce(0) { |sub_count, sub_child| sub_count += sub_child.replies_count } - count += child.replies_count - sub_sum_count += count - } + descendants_count end def has_replies - children.present? + children.exists? end # diff --git a/app/views/messages/index.json.jbuilder b/app/views/messages/index.json.jbuilder index 026e193a6..60d35e769 100644 --- a/app/views/messages/index.json.jbuilder +++ b/app/views/messages/index.json.jbuilder @@ -6,6 +6,11 @@ json.data do json.total_count @messages.total_count json.messages do json.array! @messages do |message| + json.extract! message, :id, :parent_id, :subject, :created_on, :total_replies_count, + :praises_count, :visits, :sticky, :is_hidden, :is_public + + json.total_praises_count @praises_count_map.fetch(message.id, 0) + json.partial! "messages/message", message: message json.author do json.partial! "users/user_simple", user: message.author diff --git a/db/migrate/20190621083604_add_descendants_count_to_messages.rb b/db/migrate/20190621083604_add_descendants_count_to_messages.rb new file mode 100644 index 000000000..02b721583 --- /dev/null +++ b/db/migrate/20190621083604_add_descendants_count_to_messages.rb @@ -0,0 +1,5 @@ +class AddDescendantsCountToMessages < ActiveRecord::Migration[5.2] + def change + add_column :messages, :descendants_count, :integer, default: 0 + end +end diff --git a/lib/tasks/course_board_message_count.rake b/lib/tasks/course_board_message_count.rake index 35e439403..49f33c615 100644 --- a/lib/tasks/course_board_message_count.rake +++ b/lib/tasks/course_board_message_count.rake @@ -20,6 +20,23 @@ namespace :course_board do end end + desc 'transfer root id && statistic descendants count' + task messages_descendants_count_transfer: :environment do + Message.root_nodes.find_each do |root| + logger("Current transfer root id: #{root.id} ~") + children_ids = root.children.pluck(:id) + next if children_ids.blank? + + second_children_ids = Message.where(parent_id: children_ids).pluck(:id) + + ids = children_ids.concat(second_children_ids).uniq + Message.where(id: ids).update_all(root_id: root.id) + + Message.reset_counters(root.id, :descendants) + logger("transfer success ~") + end + end + def logger(msg) puts msg end From 6c6d64ad42f9e5d02b2bbf4b117f63e46c30fcf4 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 21 Jun 2019 17:22:31 +0800 Subject: [PATCH 0076/1015] test --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 32a314c54..499bd0aa4 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -1,5 +1,5 @@ class ShixunsController < ApplicationController - before_action :require_login, except: [:download_file, :index, :menus] + # before_action :require_login, except: [:download_file, :index, :menus] # before_action :check_auth, except: [:download_file, :index] before_action :find_shixun, except: [:index, :new, :create, :menus, :get_recommend_shixuns, :propaedeutics, From 1629fbf2223ee54683a42be066d988afc8830aba Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 17:25:00 +0800 Subject: [PATCH 0077/1015] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E4=BD=9C=E5=93=81?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons/works_list.json.jbuilder | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/app/views/homework_commons/works_list.json.jbuilder b/app/views/homework_commons/works_list.json.jbuilder index 1d3110604..a1618d8ff 100644 --- a/app/views/homework_commons/works_list.json.jbuilder +++ b/app/views/homework_commons/works_list.json.jbuilder @@ -29,8 +29,9 @@ elsif @user_course_identity == Course::STUDENT json.left_time left_time @homework, @current_user.id if @homework.homework_type == "practice" - json.(@work, :id, :work_status, :update_time, :late_penalty, :ultimate_score) + json.(@work, :id, :work_status, :update_time, :ultimate_score) + json.late_penalty @work.late_penalty if @homework.allow_late json.cost_time @work.myshixun.try(:total_cost_time) json.work_score work_score_format(@work.work_score, true, @homework.score_open) json.final_score work_score_format(@work.final_score, true, @homework.score_open) @@ -38,7 +39,7 @@ elsif @user_course_identity == Course::STUDENT json.eff_score work_score_format(@work.eff_score, true, @homework.score_open) json.complete_count @work.myshixun.try(:passed_count) else - json.(@work, :id, :work_status, :update_time, :late_penalty, :absence_penalty, :appeal_penalty, :ultimate_score) + json.(@work, :id, :work_status, :update_time, :ultimate_score) json.work_score work_score_format(@work.work_score, true, @homework.score_open) json.final_score work_score_format(@work.final_score, true, @homework.score_open) @@ -48,13 +49,17 @@ elsif @user_course_identity == Course::STUDENT json.ta_comment_count @work.ta_comment_count + json.late_penalty @work.late_penalty if @homework.allow_late + if @homework.anonymous_comment json.student_comment_count @work.student_comment_num + json.absence_penalty @work.absence_penalty end if @homework.anonymous_appeal json.appeal_all_count @work.appeal_all_count json.appeal_deal_count @work.appeal_deal_count + json.appeal_penalty @work.appeal_penalty end if @homework.homework_type == "group" @@ -76,8 +81,9 @@ if @homework.homework_type == "practice" json.work_efficiency @homework.work_efficiency json.student_works @student_works.each do |work| - json.(work, :id, :work_status, :update_time, :late_penalty, :ultimate_score) + json.(work, :id, :work_status, :update_time, :ultimate_score) + json.late_penalty work.late_penalty if @homework.allow_late json.work_score work_score_format(work.work_score, @current_user == work.user, @homework.score_open) json.final_score work_score_format(work.final_score, @current_user == work.user, @homework.score_open) json.efficiency work_score_format(work.efficiency, @current_user == work.user, @homework.score_open) @@ -103,8 +109,9 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal" # json.student_comment_count anon_comments(@current_user, work.id).count else json.(work, :id, :work_status, :update_time, :work_score, :final_score, :teacher_score, :student_score, - :teaching_asistant_score, :late_penalty, :absence_penalty, :appeal_penalty, :ultimate_score) + :teaching_asistant_score, :ultimate_score) + json.late_penalty work.late_penalty if @homework.allow_late json.work_score work_score_format(work.work_score, @current_user == work.user, @homework.score_open) json.final_score work_score_format(work.final_score, @current_user == work.user, @homework.score_open) json.teacher_score work_score_format(work.teacher_score, @current_user == work.user, @homework.score_open) @@ -117,6 +124,7 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal" # 作品匿评条数 if @homework.anonymous_comment json.student_comment_count @homework_detail_manual.comment_status > 2 ? work.student_comment_num : 0 + json.absence_penalty work.absence_penalty end json.student_id work.user.try(:student_id) @@ -133,6 +141,7 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal" if @homework.anonymous_appeal json.appeal_all_count work.appeal_all_count json.appeal_deal_count work.appeal_deal_count + json.appeal_penalty work.appeal_penalty end json.user_login @is_evaluation ? "--" : work.user.try(:login) From 2a9e521d5465277f87d84f6b2047c1e3bb942c5a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 21 Jun 2019 17:31:15 +0800 Subject: [PATCH 0078/1015] =?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/views/graduation_tasks/tasks_list.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/graduation_tasks/tasks_list.json.jbuilder b/app/views/graduation_tasks/tasks_list.json.jbuilder index fe7ffddc4..5868be4fb 100644 --- a/app/views/graduation_tasks/tasks_list.json.jbuilder +++ b/app/views/graduation_tasks/tasks_list.json.jbuilder @@ -1,6 +1,7 @@ json.partial! "public_navigation", locals: {graduation: @task, course: @course} json.user_course_identity @user_course_identity json.course_group_count @course.course_groups_count +json.cross_comment @task.cross_comment # 课程发布才有数据 if @task.published? || @user_course_identity < Course::STUDENT # 老师身份才有的分类信息 From e269f32591c3b3907b20751b68c39d5d027247d6 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 21 Jun 2019 17:33:04 +0800 Subject: [PATCH 0079/1015] fix --- app/controllers/messages_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 5569ec165..3dac97899 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -22,13 +22,13 @@ class MessagesController < ApplicationController messages = @board.messages.root_nodes.by_keywords(params[:search]) - messages = messages.order('(sticky = 1) DESC') # 置顶 + messages = messages.reorder('(sticky = 1) DESC') # 置顶 messages = case sort_type - when 'time' then messages.reorder("created_on #{sort}") - when 'hot' then messages.reorder("descendants_count #{sort}") - else messages.reorder("created_on #{sort}") + when 'time' then messages.order("created_on #{sort}") + when 'hot' then messages.order("descendants_count #{sort}") + else messages.order("created_on #{sort}") end messages = messages.includes(:author) From 04bb267f6ff6dc6feaba163a028e15982428c5bc Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 21 Jun 2019 18:53:04 +0800 Subject: [PATCH 0080/1015] =?UTF-8?q?=E5=A4=84=E7=90=86=E6=97=A0=E6=95=88?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...rb => 20190621105144_sync_ivalid_users.rb} | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) rename db/migrate/{20190505092009_delete_ivalid_data.rb => 20190621105144_sync_ivalid_users.rb} (60%) diff --git a/db/migrate/20190505092009_delete_ivalid_data.rb b/db/migrate/20190621105144_sync_ivalid_users.rb similarity index 60% rename from db/migrate/20190505092009_delete_ivalid_data.rb rename to db/migrate/20190621105144_sync_ivalid_users.rb index 98f13d9e4..3520ca84d 100644 --- a/db/migrate/20190505092009_delete_ivalid_data.rb +++ b/db/migrate/20190621105144_sync_ivalid_users.rb @@ -1,34 +1,34 @@ -class DeleteIvalidData < ActiveRecord::Migration[5.2] - def change - users = User.find_by_sql("select count(*) as user_count, login from users group by login having user_count>1") - users.each do |user| - valid_users = User.where(login: user.login) - valid_users.each do |valid_user| - unless valid_user.lastname.present? - valid_user.delete - end - end - end - - mail_users = User.find_by_sql("select count(*) as user_count, mail from users where mail is not null group by mail having user_count>1") - mail_users.each do |mail_user| - valid_mail_users = User.where(mail: mail_user.mail) - valid_mail_users.each do |valid_mail_user| - unless valid_mail_user.lastname.present? - valid_mail_user.delete - end - end - end - - - phone_users = User.find_by_sql("select count(*) as user_count, phone from users where phone is not null group by phone having user_count>1") - phone_users.each do |phone_user| - valid_phone_users = User.where(phone: phone_user.phone) - valid_phone_users.each do |valid_phone_user| - unless valid_phone_user.lastname.present? - valid_phone_user.delete - end - end - end - end -end +class SyncIvalidUsers < ActiveRecord::Migration[5.2] + def change + users = User.where.not(id: 2).find_by_sql("select count(*) as user_count, login from users group by login having user_count>1") + users.each do |user| + valid_users = User.where(login: user.login) + valid_users.each do |valid_user| + unless valid_user.lastname.present? + valid_user.delete + end + end + end + + mail_users = User.where.not(id: 2).find_by_sql("select count(*) as user_count, mail from users where mail is not null group by mail having user_count>1") + mail_users.each do |mail_user| + valid_mail_users = User.where(mail: mail_user.mail) + valid_mail_users.each do |valid_mail_user| + unless valid_mail_user.lastname.present? + valid_mail_user.delete + end + end + end + + + phone_users = User.where.not(id: 2).find_by_sql("select count(*) as user_count, phone from users where phone is not null group by phone having user_count>1") + phone_users.each do |phone_user| + valid_phone_users = User.where(phone: phone_user.phone) + valid_phone_users.each do |valid_phone_user| + unless valid_phone_user.lastname.present? + valid_phone_user.delete + end + end + end + end +end From 471edd3607fff9aab1176a21b501f46a39741038 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 21 Jun 2019 19:17:58 +0800 Subject: [PATCH 0081/1015] fix bug --- app/helpers/application_helper.rb | 2 +- app/helpers/exercises_helper.rb | 1 - app/tasks/exercise_publish_task.rb | 32 +++++++++++------------------- lib/tasks/poll_publish.rake | 7 ++++--- 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index ac50e78d3..42bc16343 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -109,7 +109,7 @@ module ApplicationHelper # 计算到结束还有多长时间 **天**小时**分 def how_much_time(time) - if time.nil? + if time.nil? || time < Time.now #6.21 -hs 增加小于time.now '' else result = ((time - Time.now.to_i).to_i / (24*60*60)).to_s + " 天 " diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 53b2fa4c1..95ec0ac24 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -323,7 +323,6 @@ module ExercisesHelper else show_unreview_count = nil end - logger.info("##########__________exercise_end_time__________###############{exercise_end_time}") if exercise_status == 2 && exercise_end_time.present? ex_left_time = how_much_time(exercise_end_time) diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb index 7f3ee63ee..9d62e4d2e 100644 --- a/app/tasks/exercise_publish_task.rb +++ b/app/tasks/exercise_publish_task.rb @@ -5,7 +5,7 @@ class ExercisePublishTask def publish Rails.logger.info("log--------------------------------exercise_publish start") puts "--------------------------------exercise_publish start" - exercises = Exercise.where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) + exercises = Exercise.includes(:exercise_users).where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) exercises.each do |exercise| exercise.update_column('exercise_status', 2) course = exercise.course @@ -67,21 +67,21 @@ class ExercisePublishTask end def end - exercises = Exercise.where("end_time <= ? and exercise_status = ?",Time.now,2) + Rails.logger.info("log--------------------------------exercise_end start") + puts "--------------------------------exercise_end start" + # 1。统一设置的试卷 + exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND unified_setting = true AND end_time <= ?",Time.now) exercises.each do |exercise| - course = exercise.course ex_type = exercise.exercise_questions.pluck(:question_type).uniq - exercise.update_attribute('exercise_status', 3) + exercise.update_column('exercise_status', 3) exercise.exercise_users.each do |exercise_user| if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? - # exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true) s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] if ex_type.include?(4) #是否包含主观题 subjective_score = exercise_user.subjective_score else subjective_score = -1.0 end - # subjective_score = exercise_user.subjective_score total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score total_score = s_score + total_score_subjective_score commit_option = { @@ -93,21 +93,20 @@ class ExercisePublishTask :subjective_score => subjective_score } exercise_user.update_attributes(commit_option) - # if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? - # exercise_user.update_attributes(:subjective_score => 0) - # end end end end - all_exercises = Exercise.where("end_time > ? and exercise_status = ?",Time.now,2) + # 2.非统一的试卷 + all_exercises = Exercise.includes(:exercise_group_settings,:exercise_users,:exercise_questions).where("unified_setting = false AND exercise_status = 2 AND end_time > ?",Time.now) exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")" ex_group_settings = ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}") ex_group_settings.each do |exercise_setting| exercise = exercise_setting.exercise + exercise.update_column('exercise_status', 3) ex_types = exercise.exercise_questions.pluck(:question_type).uniq users = exercise.course.students.where(:course_group_id => exercise_setting.course_group_id) - exercise_users = exercise.exercise_users.where(:user_id => users.map(&:user_id)) + exercise_users = exercise.exercise_users.where(:user_id => users.pluck(:user_id)) exercise_users.each do |exercise_user| if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? @@ -117,7 +116,6 @@ class ExercisePublishTask subjective_score = -1.0 end s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] - # subjective_score = exercise_user.subjective_score total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score total_score = s_score + total_score_subjective_score commit_option = { @@ -129,17 +127,11 @@ class ExercisePublishTask :subjective_score => subjective_score } exercise_user.update_attributes(commit_option) - # exercise_user.update_attributes(:commit_status => 1, :end_at => Time.now, :status => true) - - # s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] - # exercise_user.update_attributes(:objective_score => s_score, :score => (s_score + (exercise_user.subjective_score && exercise_user.subjective_score > 0 ? exercise_user.subjective_score : 0))) - # if exercise_user.user.exercise_answers.where(:exercise_question_id => exercise.exercise_questions.where(:question_type => 4).map(&:id)).empty? - # exercise_user.update_attributes(:subjective_score => 0.0) - # end end end end - Rails.logger.info("log--------------------------------exercise_end completed") + Rails.logger.info("log--------------------------------exercise_end end") + puts "--------------------------------exercise_end end" end end \ No newline at end of file diff --git a/lib/tasks/poll_publish.rake b/lib/tasks/poll_publish.rake index c33ad3afb..d10db7a5d 100644 --- a/lib/tasks/poll_publish.rake +++ b/lib/tasks/poll_publish.rake @@ -6,7 +6,7 @@ namespace :poll_publish do task :publish => :environment do puts "--------------------------------poll_publish start" # 统一设置发布时间的问卷 - polls = Poll.where("publish_time is not null and polls_status = 1 and publish_time <=?",Time.now) + polls = Poll.includes(:poll_users).where("publish_time is not null and polls_status = 1 and publish_time <=?",Time.now) polls.each do |poll| poll.update_attributes(:polls_status => 2) course = poll.course @@ -71,7 +71,7 @@ namespace :poll_publish do task :nearly_end => :environment do puts "--------------------------------poll_nearly_end start" # 统一设置发布时间的问卷 - polls = Poll.where("polls_status = 2 and unified_setting = 1 and end_time <=? and end_time > ?", Time.now + 86400, Time.now + 84600) + polls = Poll.includes(:poll_users).where("polls_status = 2 and unified_setting = 1 and end_time <=? and end_time > ?", Time.now + 86400, Time.now + 84600) polls.each do |poll| if poll.tidings.where(:parent_container_type => "NearlyEnd").count == 0 course = poll.course @@ -111,7 +111,7 @@ namespace :poll_publish do end task :end => :environment do - polls = Poll.where("polls_status = 2 and unified_setting = 1 and end_time <=?",Time.now) + polls = Poll.includes(:poll_users).where("polls_status = 2 and unified_setting = 1 and end_time <=?",Time.now) polls.each do |poll| poll.update_attributes(:polls_status => 3) poll.poll_users.each do |poll_user| @@ -123,6 +123,7 @@ namespace :poll_publish do PollGroupSetting.where("end_time < ? and end_time > ?", Time.now + 1800, Time.now - 1800).each do |poll_setting| poll = poll_setting.poll + poll.update_column('polls_status',3) users = poll.course.course_members.where(:course_group_id => poll_setting.course_group_id) poll_users = poll.poll_users.where(:user_id => users.map(&:user_id)) From 0babcc3195e67dab8516fb3c846252289d7097fe Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 21 Jun 2019 19:57:50 +0800 Subject: [PATCH 0082/1015] =?UTF-8?q?exercise=E5=AE=9A=E6=97=B6=E6=88=AA?= =?UTF-8?q?=E6=AD=A2=E7=9A=84=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 2 +- app/tasks/exercise_publish_task.rb | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 95ec0ac24..1b201d875 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -352,7 +352,7 @@ module ExercisesHelper score2 = 0.0 #填空题 score5 = 0.0 #实训题 ques_stand = [] #问题是否正确 - exercise_questions = exercise.exercise_questions + exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers) exercise_questions.each do |q| if q.question_type != 5 answers_content = q.exercise_answers.search_answer_users("user_id",user.id) #学生的答案 diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb index 9d62e4d2e..6f18dc403 100644 --- a/app/tasks/exercise_publish_task.rb +++ b/app/tasks/exercise_publish_task.rb @@ -70,12 +70,12 @@ class ExercisePublishTask Rails.logger.info("log--------------------------------exercise_end start") puts "--------------------------------exercise_end start" # 1。统一设置的试卷 - exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND unified_setting = true AND end_time <= ?",Time.now) + exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND unified_setting = true AND end_time <= ?",Time.now + 900) exercises.each do |exercise| ex_type = exercise.exercise_questions.pluck(:question_type).uniq exercise.update_column('exercise_status', 3) exercise.exercise_users.each do |exercise_user| - if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? + if exercise_user.commit_status == 0 && exercise_user.start_at.present? s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] if ex_type.include?(4) #是否包含主观题 subjective_score = exercise_user.subjective_score @@ -84,6 +84,8 @@ class ExercisePublishTask end total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score total_score = s_score + total_score_subjective_score + Rails.logger.info("log-------------total_score-------------------total_scoretotal_scoretotal_scoretotal_score#{total_score}") + commit_option = { :status => 1, :commit_status => 1, @@ -98,12 +100,15 @@ class ExercisePublishTask end # 2.非统一的试卷 - all_exercises = Exercise.includes(:exercise_group_settings,:exercise_users,:exercise_questions).where("unified_setting = false AND exercise_status = 2 AND end_time > ?",Time.now) + all_exercises = Exercise.includes(:exercise_group_settings,:exercise_users,:exercise_questions).where("unified_setting = false AND exercise_status = 2 AND end_time > ?",Time.now + 900) exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")" ex_group_settings = ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}") ex_group_settings.each do |exercise_setting| exercise = exercise_setting.exercise - exercise.update_column('exercise_status', 3) + if exercise&.end_time <= Time.now + exercise.update_column('exercise_status', 3) + end + ex_types = exercise.exercise_questions.pluck(:question_type).uniq users = exercise.course.students.where(:course_group_id => exercise_setting.course_group_id) exercise_users = exercise.exercise_users.where(:user_id => users.pluck(:user_id)) From d0942590513334483e89139c51333c6496afe0bd Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 21 Jun 2019 20:51:37 +0800 Subject: [PATCH 0083/1015] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=95=E5=8D=B7?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E5=88=86=E6=95=B0=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 6 - app/controllers/concerns/git_helper.rb | 6 + app/helpers/exercises_helper.rb | 145 ++++++++++++---------- 3 files changed, 86 insertions(+), 71 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 98dd577a1..d1aac6f3a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -349,12 +349,6 @@ class ApplicationController < ActionController::Base end end - #实训题的关卡url初始化 - def challenge_path(path) - cha_path = path.present? ? path.split(";") : [] - cha_path.reject(&:blank?)[0].try(:strip) - end - # 适用与已经用url_safe编码后,回调字符串形式 def tran_base64_decode64(str) s_size = str.size % 4 diff --git a/app/controllers/concerns/git_helper.rb b/app/controllers/concerns/git_helper.rb index 0d8c91a55..f6724a654 100644 --- a/app/controllers/concerns/git_helper.rb +++ b/app/controllers/concerns/git_helper.rb @@ -49,4 +49,10 @@ module GitHelper GitService.fork_repository(repo_path: original_rep_path, fork_repository_path: (new_repo_name + ".git")) container.update_attributes!(:repo_name => new_repo_name) end + + #实训题的关卡url初始化 + def challenge_path(path) + cha_path = path.present? ? path.split(";") : [] + cha_path.reject(&:blank?)[0].try(:strip) + end end \ No newline at end of file diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 1b201d875..67eb373ef 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -352,7 +352,7 @@ module ExercisesHelper score2 = 0.0 #填空题 score5 = 0.0 #实训题 ques_stand = [] #问题是否正确 - exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers) + exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers,:exercise_shixun_challenges) exercise_questions.each do |q| if q.question_type != 5 answers_content = q.exercise_answers.search_answer_users("user_id",user.id) #学生的答案 @@ -360,84 +360,99 @@ module ExercisesHelper answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user.id) #学生的答案 end if q.question_type <= 2 #为选择题或判断题时 - 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.count > 0 - multi_each_score = (q.question_score / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 - else - multi_each_score = 0.0 + if answers_content.present? #学生有回答时 + answer_choice_array = [] + answers_content.each do |a| + answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置 end - answers_content.update_all(:score => multi_each_score) - score1 = score1 + q.question_score - end - elsif q.question_type == 3 #填空题 - null_standard_answer = q.exercise_standard_answers - standard_answer_array = null_standard_answer.select(:exercise_choice_id,:answer_text) - standard_answer_ids = standard_answer_array.pluck(:exercise_choice_id).reject(&:blank?).uniq #标准答案的exercise_choice_id数组 - standard_answer_count = standard_answer_ids.count - if standard_answer_count > 0 #存在标准答案时才有分数 - each_standard_score = (q.question_score.to_f / standard_answer_count).round(1) #每一空的得分 - else - each_standard_score = 0.0 - end - if q.is_ordered - answers_content.each do |u| - i_standard_answer = standard_answer_array.where(exercise_choice_id:u.exercise_choice_id).pluck(:answer_text).reject(&:blank?).map!(&:downcase) #该选项的全部标准答案 - if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数 - u.update_attribute("score",each_standard_score) - score2 = score2 + each_standard_score + 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.count > 0 + q_score_1 = (q.question_score / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 + else + q_score_1 = 0.0 end + answers_content.update_all(:score => q_score_1) + score1 = score1 + q.question_score end else - st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map!(&:downcase) - answers_content.each do |u| - u_answer_text = u.answer_text.downcase - if st_answer_text.include?(u_answer_text) #只要标准答案包含用户的答案,就有分数。同时,下一次循环时,就会删除该标准答案。防止用户的相同答案获分 - u.update_attribute("score",each_standard_score) - score2 = score2 + each_standard_score - st_answer_text.delete(u_answer_text) + score1 += 0.0 + end + elsif q.question_type == 3 #填空题 + if answers_content.present? + null_standard_answer = q.exercise_standard_answers + standard_answer_array = null_standard_answer.select(:exercise_choice_id,:answer_text) + standard_answer_ids = standard_answer_array.pluck(:exercise_choice_id).reject(&:blank?).uniq #标准答案的exercise_choice_id数组 + standard_answer_count = standard_answer_ids.count + if standard_answer_count > 0 #存在标准答案时才有分数 + q_score_2 = (q.question_score.to_f / standard_answer_count) #每一空的得分 + else + q_score_2 = 0.0 + end + if q.is_ordered + answers_content.each do |u| + i_standard_answer = standard_answer_array.where(exercise_choice_id:u.exercise_choice_id).pluck(:answer_text).reject(&:blank?).map!(&:downcase) #该选项的全部标准答案 + if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数 + u.update_column('score',q_score_2) + score2 = score2 + q_score_2 + end + end + else + st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map!(&:downcase) + answers_content.each do |u| + u_answer_text = u.answer_text.downcase + if st_answer_text.include?(u_answer_text) #只要标准答案包含用户的答案,就有分数。同时,下一次循环时,就会删除该标准答案。防止用户的相同答案获分 + u.update_column("score",q_score_2) + score2 = score2 + q_score_2 + st_answer_text.delete(u_answer_text) + end end end + else + score2 += 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 - answer_status = 0 - cha_path = challenge_path exercise_cha.challenge.path - if game.status == 2 && game.final_score >= 0 - exercise_cha_score = game.real_score exercise_cha.question_score #每一关卡的得分 - answer_status = 1 - end - if exercise_cha.exercise_shixun_answers.search_shixun_answers("user_id",user.id).blank? #把关卡的答案存入试卷的实训里 - 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) + if answers_content.present? + 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 + cha_path = challenge_path exercise_cha.challenge.path + if game.status == 2 && game.final_score >= 0 + 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) + if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 + 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(exercise_cha.shixun.repo_path,cha_path) + end + sx_option = { + :exercise_question_id => q.id, + :exercise_shixun_challenge_id => exercise_cha.id, + :user_id => user.id, + :score => exercise_cha_score, + :answer_text => code, + :status => answer_status + } + ExerciseShixunAnswer.create(sx_option) else - code = git_fle_content(exercise_cha.shixun.repo_path,cha_path) + ex_shixun_answer_content.first.update_column('score',exercise_cha_score) end - sx_option = { - :exercise_question_id => q.id, - :exercise_shixun_challenge_id => exercise_cha.id, - :user_id => user.id, - :score => exercise_cha_score, - :answer_text => code, - :status => answer_status - } - ExerciseShixunAnswer.create(sx_option) + score5 += exercise_cha_score end - score5 += exercise_cha_score end + else + score5 += 0.0 end end - user_scores = answers_content.score_reviewed.pluck(:score).sum + user_scores = answers_content.present? ? answers_content.score_reviewed.pluck(:score).sum : 0.0 if user_scores > 0 stand_answer = 1 else From 287f7ff17b15d7c3bb0972d495e33435490c333f Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 09:07:50 +0800 Subject: [PATCH 0084/1015] test 403 --- app/controllers/shixuns_controller.rb | 1 + app/controllers/users_controller.rb | 2 ++ app/views/shixuns/show_right.json.jbuilder | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 499bd0aa4..e47064e24 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -118,6 +118,7 @@ class ShixunsController < ApplicationController #@fans_count = owner.followers.count #@followed_count = owner.followed_users.count @user_own_shixuns = owner.shixuns.published.count + uid_logger_error("777777777777777777") end # 排行榜 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d01973175..d65675aac 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -15,6 +15,7 @@ class UsersController < ApplicationController def get_user_info begin @user = current_user + uid_logger_error("############{@user.id}") # TODO 等消息上线再打开注释 #@tidding_count = unviewed_tiddings(current_user) if current_user.present? @course = @@ -37,6 +38,7 @@ class UsersController < ApplicationController end @course_identity = current_user.course_identity(@course) if @course rescue Exception => e + uid_logger_error(e.message) missing_template end diff --git a/app/views/shixuns/show_right.json.jbuilder b/app/views/shixuns/show_right.json.jbuilder index 8f4679a37..e3414df55 100644 --- a/app/views/shixuns/show_right.json.jbuilder +++ b/app/views/shixuns/show_right.json.jbuilder @@ -1,4 +1,4 @@ -json.partial! 'shixuns/right', locals: { shixun: @shixun } +# json.partial! 'shixuns/right', locals: { shixun: @shixun } #json.follow follow?(@shixun.owner, User.current) #json.fans_count @fans_count From 7135094316a7113c1d5f6dd79e1e6028fbdaff85 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 22 Jun 2019 09:12:23 +0800 Subject: [PATCH 0085/1015] fix reply message api --- app/controllers/messages_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 3dac97899..60a1c171c 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -51,7 +51,8 @@ class MessagesController < ApplicationController def reply return normal_status(2, "回复内容不能为空") if params[:content].blank? - @reply = Message.create!(board: @message.board, root: @message.root, author: current_user, parent: @message, + @reply = Message.create!(board: @message.board, root_id: @message.root_id || @message.id, + author: current_user, parent: @message, message_detail_attributes: { content: params[:content] }) From ba91ae106fd018ff23fe8f5d9749ab3fa175fee0 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 09:17:17 +0800 Subject: [PATCH 0086/1015] 403 problem --- app/controllers/application_controller.rb | 2 +- app/controllers/shixuns_controller.rb | 1 - app/controllers/users_controller.rb | 7 ++++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 98dd577a1..d9b6f5b6b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -215,7 +215,7 @@ class ApplicationController < ActionController::Base return if params[:controller] == "main" # Find the current user User.current = find_current_user - uid_logger("user_step: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous")) + uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous")) if !User.current.logged? && Rails.env.development? User.current = User.find 12 diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index e47064e24..499bd0aa4 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -118,7 +118,6 @@ class ShixunsController < ApplicationController #@fans_count = owner.followers.count #@followed_count = owner.followed_users.count @user_own_shixuns = owner.shixuns.published.count - uid_logger_error("777777777777777777") end # 排行榜 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d65675aac..90e2d3a62 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -14,8 +14,8 @@ class UsersController < ApplicationController # 贴吧获取用户信接口 def get_user_info begin - @user = current_user - uid_logger_error("############{@user.id}") + @user = User.find(12) + # @user = current_user # TODO 等消息上线再打开注释 #@tidding_count = unviewed_tiddings(current_user) if current_user.present? @course = @@ -55,7 +55,8 @@ class UsersController < ApplicationController # Redo: 消息总数缓存 def get_navigation_info @old_domain = edu_setting('old_edu_host') - @user = current_user + # @user = current_user + @user = User.find(12) # 新消息数 @new_message = @user.tidings.where("created_at > '#{@user.click_time}'").count > 0 || @user.private_messages.where("created_at > '#{@user.click_time}'").count > 0 From 15e27382094e4be0addf684baadbd03084fca8b2 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 09:25:01 +0800 Subject: [PATCH 0087/1015] start --- app/controllers/users_controller.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 90e2d3a62..9c9d7411c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -14,8 +14,7 @@ class UsersController < ApplicationController # 贴吧获取用户信接口 def get_user_info begin - @user = User.find(12) - # @user = current_user + @user = current_user # TODO 等消息上线再打开注释 #@tidding_count = unviewed_tiddings(current_user) if current_user.present? @course = @@ -55,8 +54,7 @@ class UsersController < ApplicationController # Redo: 消息总数缓存 def get_navigation_info @old_domain = edu_setting('old_edu_host') - # @user = current_user - @user = User.find(12) + @user = current_user # 新消息数 @new_message = @user.tidings.where("created_at > '#{@user.click_time}'").count > 0 || @user.private_messages.where("created_at > '#{@user.click_time}'").count > 0 From 2420ce6a1ba0491b23a25a8e9fd9efe95e8ae52b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 09:29:57 +0800 Subject: [PATCH 0088/1015] fix bug --- app/tasks/exercise_publish_task.rb | 2 -- app/views/exercise_questions/_exercise_questions.json.jbuilder | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb index 6f18dc403..282968755 100644 --- a/app/tasks/exercise_publish_task.rb +++ b/app/tasks/exercise_publish_task.rb @@ -84,8 +84,6 @@ class ExercisePublishTask end total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score total_score = s_score + total_score_subjective_score - Rails.logger.info("log-------------total_score-------------------total_scoretotal_scoretotal_scoretotal_score#{total_score}") - commit_option = { :status => 1, :commit_status => 1, diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index 10dc46abf..b5a01ed06 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -1,5 +1,6 @@ json.question_id question.id -json.question_number question.question_number +# json.question_number question.question_number +json.q_position question.question_number json.question_title question.question_title json.question_type question.question_type json.question_score question.question_score.round(1).to_s From 7ddd0c4f5d45bf07be04a03e306b12033a88b2c3 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 22 Jun 2019 09:42:39 +0800 Subject: [PATCH 0089/1015] fix user shixuns list filter bug and n+1 bug --- app/controllers/users/shixuns_controller.rb | 4 ++++ app/decorators/shixun_decorator.rb | 4 ---- app/models/shixun.rb | 4 ++++ app/services/users/shixun_service.rb | 2 +- app/views/users/shixuns/shared/_shixun.json.jbuilder | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/controllers/users/shixuns_controller.rb b/app/controllers/users/shixuns_controller.rb index c4c0d4c07..7b840a0a1 100644 --- a/app/controllers/users/shixuns_controller.rb +++ b/app/controllers/users/shixuns_controller.rb @@ -4,6 +4,10 @@ class Users::ShixunsController < Users::BaseController @count = shixuns.count @shixuns = paginate(shixuns.includes(:first_tag_repertoire), special: true) + + ids = @shixuns.map(&:id) + @finished_challenges_count_map = Game.joins(:myshixun).where(user_id: observed_user.id, status: 2) + .where(myshixuns: { shixun_id: ids }).group('myshixuns.shixun_id').count end private diff --git a/app/decorators/shixun_decorator.rb b/app/decorators/shixun_decorator.rb index 50e2e27eb..4b7a0714a 100644 --- a/app/decorators/shixun_decorator.rb +++ b/app/decorators/shixun_decorator.rb @@ -1,8 +1,4 @@ module ShixunDecorator - def finished_challenges_count(user) - Game.joins(:myshixun).where(user_id: user.id, status: 2, myshixuns: { shixun_id: id }).count - end - def human_status I18n.t("shixun.status.#{status}") end diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 9ccefca92..556a4400f 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -233,4 +233,8 @@ class Shixun < ApplicationRecord shixun_members.where(role: [1, 2]).exists?(user_id: user.id) end + + def finished_challenges_count(user) + Game.joins(:myshixun).where(user_id: user.id, status: 2, myshixuns: { shixun_id: id }).count + end end diff --git a/app/services/users/shixun_service.rb b/app/services/users/shixun_service.rb index b5e5586f1..4730a5777 100644 --- a/app/services/users/shixun_service.rb +++ b/app/services/users/shixun_service.rb @@ -58,7 +58,7 @@ class Users::ShixunService when 'passed' then 1 when 'processing' then 0 end - relations.where(myshixuns: { status: status }) if status + relations = relations.where(myshixuns: { status: status }) if status relations end diff --git a/app/views/users/shixuns/shared/_shixun.json.jbuilder b/app/views/users/shixuns/shared/_shixun.json.jbuilder index 13cc3a9ee..8427ead58 100644 --- a/app/views/users/shixuns/shared/_shixun.json.jbuilder +++ b/app/views/users/shixuns/shared/_shixun.json.jbuilder @@ -6,4 +6,4 @@ json.name shixun.name json.status shixun.status json.human_status shixun.human_status json.challenges_count shixun.challenges_count -json.finished_challenges_count shixun.finished_challenges_count(user) \ No newline at end of file +json.finished_challenges_count @finished_challenges_count_map&.fetch(shixun.id, 0) || shixun.finished_challenges_count(user) \ No newline at end of file From ab6c1bd682d153ff779b2a1fff97e38176d1c24f Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 22 Jun 2019 09:45:42 +0800 Subject: [PATCH 0090/1015] fix user projects filter bug --- app/services/users/subject_service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/users/subject_service.rb b/app/services/users/subject_service.rb index e0d8377c2..7e3eaaa81 100644 --- a/app/services/users/subject_service.rb +++ b/app/services/users/subject_service.rb @@ -65,7 +65,7 @@ class Users::SubjectService when 'finished' then subjects.having('finished = 1').map(&:id) end - relations.where(id: subject_ids) if subject_ids.present? + relations = relations.where(id: subject_ids) if subject_ids.present? relations end @@ -75,7 +75,7 @@ class Users::SubjectService when 'applying' then 1 when 'published' then 2 end - relations.where(status: status) if status + relations = relations.where(status: status) if status relations end From 130a39ed5b2eac847ed6116ca8e49932d3ac4f5f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 09:46:14 +0800 Subject: [PATCH 0091/1015] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/course.rb | 7 ++++--- app/models/homework_common.rb | 11 ++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/models/course.rb b/app/models/course.rb index e4ade6e9f..a2f5add51 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -165,7 +165,7 @@ class Course < ApplicationRecord all_course_module_types.each do |type| hidden_value = course_module_types.include?(type) ? 0 : 1 - course_module = get_course_module_by_type(type, self.id) + course_module = course_modules.where(module_type: type).first course_module.update_attribute(:hidden, hidden_value) if course_module.present? end end @@ -174,8 +174,9 @@ class Course < ApplicationRecord %w[activity shixun_homework common_homework group_homework graduation exercise poll attachment board course_group] end - def get_course_module_by_type(type, course_id) - CourseModule.where(course_id: course_id, module_type: type).first + def get_course_module_by_type(type) + #CourseModule.where(course_id: course_id, module_type: type).first + self.course_modules.where(module_type: type).first end # 创建课程讨论区 diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index d67b6e0fd..c3bfd2dd9 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -170,7 +170,7 @@ class HomeworkCommon < ApplicationRecord #删除时更新题库中的引用数 def update_homework_bank_quotes - old_banks = HomeworkBank.where(homework_common_id: self.id) + old_banks = self.homework_bank unless old_banks.blank? old_banks.each do |bank| bank.update_attributes(quotes: (bank.quotes - 1) > 0 ? (bank.quotes - 1) : 0, homework_common_id: nil) @@ -243,10 +243,15 @@ class HomeworkCommon < ApplicationRecord end def min_group_publish_time - HomeworkGroupSetting.where("homework_common_id = #{self.id} and publish_time is not null").pluck(:publish_time).min + #HomeworkGroupSetting.where("homework_common_id = #{self.id} and publish_time is not null").pluck(:publish_time).min + # 可以使用includes + self.homework_group_settings.where("publish_time is not null").pluck(:publish_time).min end def max_group_end_time - HomeworkGroupSetting.where("homework_common_id = #{self.id} and end_time is not null").pluck(:end_time).max + #HomeworkGroupSetting.where("homework_common_id = #{self.id} and end_time is not null").pluck(:end_time).max + # 可以使用includes + self.homework_group_settings.where("end_time is not null").pluck(:end_time).max + end end From e318ee25b5707c9c66f57aa9242b115bbd0a56c6 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 09:53:35 +0800 Subject: [PATCH 0092/1015] fix bug --- .../exercise_questions/_exercise_questions.json.jbuilder | 2 +- app/views/exercises/start_answer.json.jbuilder | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index b5a01ed06..7a05c2e11 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -1,6 +1,6 @@ json.question_id question.id # json.question_number question.question_number -json.q_position question.question_number +json.q_position ques_position.present? ? ques_position : question.question_number json.question_title question.question_title json.question_type question.question_type json.question_score question.question_score.round(1).to_s diff --git a/app/views/exercises/start_answer.json.jbuilder b/app/views/exercises/start_answer.json.jbuilder index fb9916696..4cc461d56 100644 --- a/app/views/exercises/start_answer.json.jbuilder +++ b/app/views/exercises/start_answer.json.jbuilder @@ -36,9 +36,9 @@ json.partial! "exercises/exercise_scores" json.exercise_questions do json.array! @exercise_all_questions do |q| question = q[:question] - ques_position = q[:ques_number] #问题的序号,当问题为随机时,重新更新后的问题序号 + # ques_position = q[:ques_number] #问题的序号,当问题为随机时,重新更新后的问题序号 question_info = get_exercise_question_info(question,@exercise,@exercise_user_current,@ex_answerer.id) - json.q_position ques_position + # json.q_position q[:ques_number] #问题的序号,当问题为随机时,重新更新后的问题序号 if @t_user_exercise_status == 3 this_answer_status = "0.0" user_score = "0.0" @@ -58,6 +58,7 @@ json.exercise_questions do user_answer: question_info[:answered_content], choices:question.exercise_choices, exercise_type:3, - shixun_type:question_info[:shixun_type] + shixun_type:question_info[:shixun_type], + ques_position: q[:ques_number] end end \ No newline at end of file From 2ec730e4fd1772250b1ea8f06b9cbc39b10b6e32 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 10:01:13 +0800 Subject: [PATCH 0093/1015] fix bug --- app/views/exercise_questions/edit.json.jbuilder | 3 ++- app/views/exercise_questions/show.json.jbuilder | 3 ++- app/views/exercises/_user_exercise_info.json.jbuilder | 3 ++- app/views/exercises/blank_exercise.json.jbuilder | 3 ++- app/views/exercises/edit.json.jbuilder | 3 ++- app/views/exercises/show.json.jbuilder | 3 ++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/views/exercise_questions/edit.json.jbuilder b/app/views/exercise_questions/edit.json.jbuilder index 32567d813..35db720c7 100644 --- a/app/views/exercise_questions/edit.json.jbuilder +++ b/app/views/exercise_questions/edit.json.jbuilder @@ -5,4 +5,5 @@ json.partial! "exercise_questions/exercise_questions", choices:@exercise_choices, shixun_challenges: @exercise_question_shixun, exercise_type:1, - user_answer:[] \ No newline at end of file + user_answer:[], + ques_position:nil \ No newline at end of file diff --git a/app/views/exercise_questions/show.json.jbuilder b/app/views/exercise_questions/show.json.jbuilder index e8662a611..c27fe21a5 100644 --- a/app/views/exercise_questions/show.json.jbuilder +++ b/app/views/exercise_questions/show.json.jbuilder @@ -5,4 +5,5 @@ json.partial! "exercise_questions/exercise_questions", choices:@exercise_choices, shixun_challenges: @exercise_question_shixun, exercise_type:1, - user_answer:[] + user_answer:[], + ques_position:nil diff --git a/app/views/exercises/_user_exercise_info.json.jbuilder b/app/views/exercises/_user_exercise_info.json.jbuilder index a3b7b208c..5b5d0c725 100644 --- a/app/views/exercises/_user_exercise_info.json.jbuilder +++ b/app/views/exercises/_user_exercise_info.json.jbuilder @@ -62,7 +62,8 @@ json.exercise_questions do shixun_challenges: q.exercise_shixun_challenges, exercise_type: ex_type, user_answer: user_ques_answers[:answered_content], - shixun_type: user_ques_answers[:shixun_type] + shixun_type: user_ques_answers[:shixun_type], + ques_position:nil if user_ques_comments.count > 0 json.question_comments do json.partial! "exercises/exercise_comments", question_comment:user_ques_answers[:question_comment].first diff --git a/app/views/exercises/blank_exercise.json.jbuilder b/app/views/exercises/blank_exercise.json.jbuilder index 631f0dcb3..16b5449fb 100644 --- a/app/views/exercises/blank_exercise.json.jbuilder +++ b/app/views/exercises/blank_exercise.json.jbuilder @@ -11,7 +11,8 @@ json.exercise_questions do choices:q.exercise_choices, shixun_challenges: q.exercise_shixun_challenges, exercise_type:2, - user_answer:[] + user_answer:[], + ques_position:nil end end diff --git a/app/views/exercises/edit.json.jbuilder b/app/views/exercises/edit.json.jbuilder index 61ec71db5..71a6fcf07 100644 --- a/app/views/exercises/edit.json.jbuilder +++ b/app/views/exercises/edit.json.jbuilder @@ -15,7 +15,8 @@ json.exercise_questions do shixun_challenges: q.exercise_shixun_challenges, exercise_type:1, user_answer:[], - shixun_type:0 + shixun_type:0, + ques_position:nil end end diff --git a/app/views/exercises/show.json.jbuilder b/app/views/exercises/show.json.jbuilder index 8f6517c2c..d92eebeab 100644 --- a/app/views/exercises/show.json.jbuilder +++ b/app/views/exercises/show.json.jbuilder @@ -18,7 +18,8 @@ json.exercise_questions do shixun_challenges: q.exercise_shixun_challenges, exercise_type:1, user_answer:[], - shixun_type:0 + shixun_type:0, + ques_position:nil end end From 5d3c49f1972f643f3fa106395fbe221a32e9c7d9 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 22 Jun 2019 10:19:56 +0800 Subject: [PATCH 0094/1015] fix user homepage info api --- app/decorators/user_decorator.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/decorators/user_decorator.rb b/app/decorators/user_decorator.rb index 0ee9a4b43..a0f9f7fdd 100644 --- a/app/decorators/user_decorator.rb +++ b/app/decorators/user_decorator.rb @@ -39,19 +39,19 @@ module UserDecorator apply = ApplyAction.order(created_at: :desc).find_by(user_id: id, container_type: 'TrialAuthorization') - apply && !apply.status.zero? + apply.present? && !apply.status.zero? end # 是否已经签到 def attendance_signed? attendance = Attendance.find_by(user_id: id) - attendance && Util.days_between(Time.zone.now, attendance.created_at).zero? + attendance.present? && Util.days_between(Time.zone.now, attendance.created_at).zero? end # 明日签到金币 def tomorrow_attendance_gold - Attendance.find_by(user_id: id)&.next_gold + Attendance.find_by(user_id: id)&.next_gold || 50 end # ----------- 账号管理 ------------- From 2c7f9f9f77106ca40da3ac59f84d17a3a307c287 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 22 Jun 2019 10:21:21 +0800 Subject: [PATCH 0095/1015] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E8=BA=AB=E4=BB=BD?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=E6=AF=95=E8=AE=BE=E4=BD=9C=E5=93=81=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=A2=9E=E5=8A=A0=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/graduation_tasks_helper.rb | 16 ++++++++++++++++ app/models/graduation_task.rb | 2 ++ app/views/graduation_tasks/index.json.jbuilder | 7 ++++--- .../graduation_tasks/tasks_list.json.jbuilder | 10 ++++++++-- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/app/helpers/graduation_tasks_helper.rb b/app/helpers/graduation_tasks_helper.rb index a5f05d623..b9039544d 100644 --- a/app/helpers/graduation_tasks_helper.rb +++ b/app/helpers/graduation_tasks_helper.rb @@ -131,4 +131,20 @@ module GraduationTasksHelper end end end + + # 阶段剩余时间 + def task_left_time task + if task.publish_time && task.publish_time < Time.now + if task.end_time > Time.now + status = "剩余提交时间" + time = "#{how_much_time(task.end_time)}" + else + if task.allow_late && task.late_time && task.late_time >= Time.now + status = "剩余补交时间" + time = "#{how_much_time(task.late_time)}" + end + end + end + {status: status, time: time} + end end diff --git a/app/models/graduation_task.rb b/app/models/graduation_task.rb index 8d89da693..d85f9782d 100644 --- a/app/models/graduation_task.rb +++ b/app/models/graduation_task.rb @@ -168,6 +168,8 @@ class GraduationTask < ApplicationRecord end end + + # 是否具有分组 def have_grouping? self.task_type == 2 diff --git a/app/views/graduation_tasks/index.json.jbuilder b/app/views/graduation_tasks/index.json.jbuilder index 80780b209..7fcececd9 100644 --- a/app/views/graduation_tasks/index.json.jbuilder +++ b/app/views/graduation_tasks/index.json.jbuilder @@ -12,10 +12,11 @@ json.tasks @tasks.each do |task| json.name task.name json.private_icon !task.is_public json.task_status task.status #6.12 -hs - json.status task_curr_status(task, @course)[:status] - json.status_time task_curr_status(task, @course)[:time] + task_curr_status = task_curr_status(task, @course) + json.status task_curr_status[:status] + json.status_time task_curr_status[:time] - unless task_curr_status(task, @course)[:status].include?("未发布") + unless task_curr_status[:status].include?("未发布") json.commit_count grduationwork_count task, 1 json.uncommit_count grduationwork_count task, 0 end diff --git a/app/views/graduation_tasks/tasks_list.json.jbuilder b/app/views/graduation_tasks/tasks_list.json.jbuilder index 5868be4fb..a0cffc41b 100644 --- a/app/views/graduation_tasks/tasks_list.json.jbuilder +++ b/app/views/graduation_tasks/tasks_list.json.jbuilder @@ -26,8 +26,14 @@ if @task.published? || @user_course_identity < Course::STUDENT # 是否具有分组 json.have_grouping @task.have_grouping? - json.work_count @work_count - json.all_work_count @all_work_count + if @user_course_identity == Course::STUDENT + json.commit_count grduationwork_count @task, 1 + json.uncommit_count grduationwork_count @task, 0 + json.left_time task_left_time @task + else + json.work_count @work_count + json.all_work_count @all_work_count + end # 学生数据 json.work_lists do json.array! @work_list do |work| From c216cfd44b785c1506a040eb045e44762766a8ba Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 10:35:43 +0800 Subject: [PATCH 0096/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E5=88=9B=E5=BB=BA=E5=88=99=E5=92=8C=E6=8E=A8?= =?UTF-8?q?=E8=8D=90=E5=AE=9E=E8=AE=AD=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shixuns/show_right.json.jbuilder | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/shixuns/show_right.json.jbuilder b/app/views/shixuns/show_right.json.jbuilder index e3414df55..fe3c5d0f5 100644 --- a/app/views/shixuns/show_right.json.jbuilder +++ b/app/views/shixuns/show_right.json.jbuilder @@ -1,6 +1,6 @@ -# json.partial! 'shixuns/right', locals: { shixun: @shixun } +json.partial! 'shixuns/right', locals: { shixun: @shixun } -#json.follow follow?(@shixun.owner, User.current) -#json.fans_count @fans_count -#json.followed_count @followed_count +json.follow follow?(@shixun.owner, User.current) +json.fans_count @fans_count +json.followed_count @followed_count json.user_shixuns_count @user_own_shixuns From b4fa106873267fd5d74e578396226e5165b9ae3d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 22 Jun 2019 10:36:45 +0800 Subject: [PATCH 0097/1015] =?UTF-8?q?=E7=AB=8B=E5=8D=B3=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E6=97=B6=E6=88=AA=E6=AD=A2=E6=97=B6=E9=97=B4=E6=9C=AA=E5=8F=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index bb37283ca..ee6cc80e0 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -907,10 +907,9 @@ class HomeworkCommonsController < ApplicationController # 创建作业分班设置:homework_group_setting create_homework_group_settings(homework) - # 选中的分班设置的发布时间改为当前时间,截止时间不为空的保持原状,为空的改为一个月后 - homework.homework_group_settings.where(course_group_id: publish_groups).update_all(publish_time: Time.now) - homework.homework_group_settings.where(course_group_id: publish_groups, end_time: nil). - update_all(end_time: params[:end_time]) + # 选中的分班设置的发布时间改为当前时间,截止时间改为传的截止时间参数 + homework.homework_group_settings.where(course_group_id: publish_groups).update_all(publish_time: Time.now, + end_time: params[:end_time]) # 发消息 tiding_group_ids = publish_groups end @@ -938,8 +937,7 @@ class HomeworkCommonsController < ApplicationController create_homework_group_settings(homework) none_publish_settings = homework.homework_group_settings.where(course_group_id: publish_groups).none_published - none_publish_settings.update_all(publish_time: Time.now) - none_publish_settings.where(end_time: nil).update_all(end_time: params[:end_time]) + none_publish_settings.update_all(publish_time: Time.now, end_time: params[:end_time]) if homework.max_group_end_time homework.end_time = homework.max_group_end_time end From 09d8e6e5da4b0b2a0ce60370a807743773ae8e4f Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 22 Jun 2019 10:42:40 +0800 Subject: [PATCH 0098/1015] =?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/homework_commons_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index ee6cc80e0..ec3f0ab9a 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -90,8 +90,10 @@ class HomeworkCommonsController < ApplicationController if @homework_type == 4 @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns) + elsif @homework_type == 3 + @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :homework_detail_group) else - @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :homework_detail_group) + @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings) end end From 34dc1032d83ed071d695dc27903efb10b2132207 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 22 Jun 2019 10:45:54 +0800 Subject: [PATCH 0099/1015] add cache to edusetting get --- app/controllers/application_controller.rb | 4 ++-- app/helpers/application_helper.rb | 2 +- app/libs/base64_image_converter.rb | 2 +- app/models/edu_setting.rb | 22 +++++++++++++++++++++- app/services/git_service.rb | 2 +- app/services/review_service.rb | 2 +- lib/educoder/sms.rb | 2 +- 7 files changed, 28 insertions(+), 8 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d1aac6f3a..89b3ed5d8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -19,8 +19,8 @@ class ApplicationController < ActionController::Base # 全局配置参数 # 返回name对应的value - def edu_setting name - EduSetting.find_by_name(name).try(:value) + def edu_setting(name) + EduSetting.get(name) end def user_course_identity diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 42bc16343..b4e3baf51 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -11,7 +11,7 @@ module ApplicationHelper # 全局参数配置 def edu_setting name - EduSetting.find_by_name(name).try(:value) + EduSetting.get(name) end def graduation_navigation graduation diff --git a/app/libs/base64_image_converter.rb b/app/libs/base64_image_converter.rb index 2a8155283..2dc9aa41e 100644 --- a/app/libs/base64_image_converter.rb +++ b/app/libs/base64_image_converter.rb @@ -35,7 +35,7 @@ class Base64ImageConverter end def size_limit - EduSetting.find_by_name('upload_avatar_max_size')&.value + EduSetting.get('upload_avatar_max_size') end class Image diff --git a/app/models/edu_setting.rb b/app/models/edu_setting.rb index db6d545f0..e6e4d900e 100644 --- a/app/models/edu_setting.rb +++ b/app/models/edu_setting.rb @@ -1,5 +1,25 @@ class EduSetting < ApplicationRecord + after_commit :expire_cache + + def cache_key + self.class.cache_key(name) + end + def self.get(key) - find_by_name(key.to_s)&.value + Rails.cache.fetch(cache_key(key), expires_in: 1.days) do + find_by_name(key.to_s)&.value + end + end + + def self.cache_key(name) + raise ArgumentError if name.blank? + + "educoder/edu-settings/#{name.to_s}" + end + + private + + def expire_cache + Rails.cache.clear(cache_key) end end diff --git a/app/services/git_service.rb b/app/services/git_service.rb index 4b6bf17ef..3298185bf 100644 --- a/app/services/git_service.rb +++ b/app/services/git_service.rb @@ -15,7 +15,7 @@ class GitService private def root_url - new_git_address = EduSetting.find_by_name('git_address_domain').try(:value) + new_git_address = EduSetting.get('git_address_domain') raise 'error: new_git_address not configuration' unless new_git_address.present? new_git_address end diff --git a/app/services/review_service.rb b/app/services/review_service.rb index 7602aa51b..df004fd19 100644 --- a/app/services/review_service.rb +++ b/app/services/review_service.rb @@ -4,7 +4,7 @@ require 'net/http' require 'uri' class ReviewService - @review_server_url = EduSetting.find_by_name('review_server_url').try(:value) + @review_server_url = EduSetting.get('review_server_url') def self.logger diff --git a/lib/educoder/sms.rb b/lib/educoder/sms.rb index 9d54a6df5..e79678ad3 100644 --- a/lib/educoder/sms.rb +++ b/lib/educoder/sms.rb @@ -27,7 +27,7 @@ module Educoder def self.sendYunpian(mobile, code, send_type, name, user_name, result) #修改为您的apikey.可在官网(http://www.yunpian.com)登录后用户中心首页看到 - apikey = EduSetting.find_by_name('sms_apikey').try(:value) + apikey = EduSetting.get('sms_apikey') #指定模板发送接口HTTP地址 send_tpl_sms_uri = URI.parse('https://sms.yunpian.com/v2/sms/single_send.json') From db081f1f3b6bf09b9ad5110b28acd8c3c444aeac Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 10:47:40 +0800 Subject: [PATCH 0100/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=9D=83=E9=99=90?= =?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/controllers/shixuns_controller.rb | 3 +-- app/models/user.rb | 17 +++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 499bd0aa4..165b570fc 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -1,6 +1,6 @@ class ShixunsController < ApplicationController # before_action :require_login, except: [:download_file, :index, :menus] - # before_action :check_auth, except: [:download_file, :index] + before_action :check_auth, except: [:download_file, :index] before_action :find_shixun, except: [:index, :new, :create, :menus, :get_recommend_shixuns, :propaedeutics, :departments, :apply_shixun_mirror, :get_mirror_script, :download_file] @@ -710,7 +710,6 @@ private def find_shixun @shixun = Shixun.find_by_identifier(params[:identifier]) - shixun = Shixun.where(identifier: params[:identifier]).first if @shixun.blank? normal_status(404, "...") return diff --git a/app/models/user.rb b/app/models/user.rb index ece69dc02..a877b2b90 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -386,13 +386,18 @@ class User < ApplicationRecord end # 用户是否有权限查看实训 + # 1、实训删除只有管理员能看到 + # 2、实训隐藏了只有管理员、实训合作者能看到 + # 3、如果有限制学校范围,则学校的用户、管理员、实训合作者能看到 def shixun_permission(shixun) - # 性能优化:先处理不需要权限的实训(已发布并且没有单位权限限制的实训) - return false if shixun.status != 2 || shixun.hidden # 隐藏或者未发布的实训:false - return true if shixun.use_scope == 0 # 对所有学校公开 - return true if shixun.use_scope == 1 && (manager_of_shixun?(shixun) || shixun.shixun_schools.exists?(school_id: school_id)) # 对部分高校公开 - # return true if manager_of_shixun?(shixun) # 实训管理员 - return false + case status + when -1 # 软删除只有管理员能访问 + admin? + when 0, 1, 3 # 申请发布或者已关闭的实训,只有实训管理员可以访问 + manager_of_shixun?(shixun) + when 2 + shixun.use_scope == 0 || (manager_of_shixun?(shixun) || shixun.shixun_schools.exists?(school_id: school_id)) + end end # 用户在平台名称的显示方式 From 3f837dbda5c742c104c5e9330852948ed7197ff5 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 22 Jun 2019 10:48:01 +0800 Subject: [PATCH 0101/1015] modify edusetting cache key method Avoid duplication --- app/models/edu_setting.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/models/edu_setting.rb b/app/models/edu_setting.rb index e6e4d900e..4b39dea81 100644 --- a/app/models/edu_setting.rb +++ b/app/models/edu_setting.rb @@ -1,17 +1,17 @@ class EduSetting < ApplicationRecord - after_commit :expire_cache + after_commit :expire_value_cache - def cache_key - self.class.cache_key(name) + def value_cache_key + self.class.value_cache_key(name) end def self.get(key) - Rails.cache.fetch(cache_key(key), expires_in: 1.days) do + Rails.cache.fetch(value_cache_key(key), expires_in: 1.days) do find_by_name(key.to_s)&.value end end - def self.cache_key(name) + def self.value_cache_key(name) raise ArgumentError if name.blank? "educoder/edu-settings/#{name.to_s}" @@ -19,7 +19,7 @@ class EduSetting < ApplicationRecord private - def expire_cache - Rails.cache.clear(cache_key) + def expire_value_cache + Rails.cache.clear(value_cache_key) end end From 5bf0be607a6d373008bf1cce416b5a91e807b077 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 10:52:08 +0800 Subject: [PATCH 0102/1015] git request --- app/controllers/gits_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/gits_controller.rb b/app/controllers/gits_controller.rb index 778963f6e..4351bf602 100644 --- a/app/controllers/gits_controller.rb +++ b/app/controllers/gits_controller.rb @@ -4,6 +4,7 @@ class GitsController < ApplicationController def auth # HTTP_AUTHORIZATION: "Basic 这里base64编码的的密码(user:passwd)" logger.info("11111112222223333#{request.env["HTTP_AUTHORIZATION"]}") + logger.info("11111112222223333: request is #{request}") #logger.info("#########-----request_env: #{request.env}") # {"service"=>"git-receive-pack", "controller"=>"gits", "action"=>"auth", # "url"=>"forge01/cermyt39.git/info/refs"} From 460a89fe6e086e0fdb5bc80c7cc6db472b6ffc20 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 22 Jun 2019 10:55:12 +0800 Subject: [PATCH 0103/1015] user brief introduction allow blank --- app/controllers/users_controller.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index d01973175..408e73fa5 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -90,10 +90,6 @@ class UsersController < ApplicationController def brief_introduction content = params[:content].to_s.strip - if content.blank? - render_error('内容不能为空') - return - end current_user.user_extension.update!(brief_introduction: content) From 98a541e5a8883e004f9cc4cb5c2ff347a3746b68 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 10:55:26 +0800 Subject: [PATCH 0104/1015] fix bug --- lib/tasks/poll_publish.rake | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/tasks/poll_publish.rake b/lib/tasks/poll_publish.rake index d10db7a5d..48c289050 100644 --- a/lib/tasks/poll_publish.rake +++ b/lib/tasks/poll_publish.rake @@ -111,28 +111,48 @@ namespace :poll_publish do end task :end => :environment do - polls = Poll.includes(:poll_users).where("polls_status = 2 and unified_setting = 1 and end_time <=?",Time.now) + + #1.统一设置的截止 + polls = Poll.includes(:poll_users).where("polls_status = 2 AND unified_setting = true AND end_time <=?",Time.now + 900) polls.each do |poll| - poll.update_attributes(:polls_status => 3) + poll.update_column('polls_status', 3) poll.poll_users.each do |poll_user| - if poll_user.commit_status == 0 && !poll_user.start_at.nil? + if poll_user.commit_status == 0 && poll_user.start_at.present? poll_user.update_attributes(:commit_status => 1, :end_at => Time.now) end end end - PollGroupSetting.where("end_time < ? and end_time > ?", Time.now + 1800, Time.now - 1800).each do |poll_setting| + #2.分班设置的截止 + polls = Poll.includes(:poll_users).where("polls_status = 2 AND unified_setting = false AND end_time > ?",Time.now + 900) + poll_ids = polls.blank? ? "(-1)" : "(" + polls.map(&:id).join(",") + ")" + polls_group_settings = PollGroupSetting.where("end_time <= '#{Time.now}' and poll_id in #{poll_ids}") + polls_group_settings.each do |poll_setting| poll = poll_setting.poll - poll.update_column('polls_status',3) - + if poll&.end_time <= Time.now + poll.update_column('polls_status', 3) + end users = poll.course.course_members.where(:course_group_id => poll_setting.course_group_id) poll_users = poll.poll_users.where(:user_id => users.map(&:user_id)) - poll_users.each do |poll_user| if poll_user.commit_status == 0 && !poll_user.start_at.nil? poll_user.update_attributes(:commit_status => 1, :end_at => Time.now) end end end + + # PollGroupSetting.where("end_time < ? and end_time > ?", Time.now + 1800, Time.now - 1800).each do |poll_setting| + # poll = poll_setting.poll + # poll.update_column('polls_status',3) + # + # users = poll.course.course_members.where(:course_group_id => poll_setting.course_group_id) + # poll_users = poll.poll_users.where(:user_id => users.map(&:user_id)) + # + # poll_users.each do |poll_user| + # if poll_user.commit_status == 0 && !poll_user.start_at.nil? + # poll_user.update_attributes(:commit_status => 1, :end_at => Time.now) + # end + # end + # end end end From d9001276227bc6ec184b5bb11eca9896b1ce6b93 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 10:59:18 +0800 Subject: [PATCH 0105/1015] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E7=9A=84=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 165b570fc..6dfa94252 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -715,7 +715,7 @@ private return end - if !current_user.shixun_permission(@shixun) || (@shixun.status == -1 && !current_user.admin?) + if !current_user.shixun_permission(@shixun) tip_exception(403, "..") end end From 709fbcda0437a6c6086a579034f5bf5d63634d97 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 11:03:35 +0800 Subject: [PATCH 0106/1015] http auth --- app/controllers/gits_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/gits_controller.rb b/app/controllers/gits_controller.rb index 4351bf602..92451d655 100644 --- a/app/controllers/gits_controller.rb +++ b/app/controllers/gits_controller.rb @@ -4,7 +4,7 @@ class GitsController < ApplicationController def auth # HTTP_AUTHORIZATION: "Basic 这里base64编码的的密码(user:passwd)" logger.info("11111112222223333#{request.env["HTTP_AUTHORIZATION"]}") - logger.info("11111112222223333: request is #{request}") + logger.info("11111112222223333: request is #{request.env}") #logger.info("#########-----request_env: #{request.env}") # {"service"=>"git-receive-pack", "controller"=>"gits", "action"=>"auth", # "url"=>"forge01/cermyt39.git/info/refs"} From eee76b604ee2a7a1a85351ce6527ef7f7910e943 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 11:10:28 +0800 Subject: [PATCH 0107/1015] git passsword --- app/controllers/gits_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/gits_controller.rb b/app/controllers/gits_controller.rb index 92451d655..e5d33acab 100644 --- a/app/controllers/gits_controller.rb +++ b/app/controllers/gits_controller.rb @@ -3,7 +3,7 @@ class GitsController < ApplicationController #供git-workhorse反向调用认证 def auth # HTTP_AUTHORIZATION: "Basic 这里base64编码的的密码(user:passwd)" - logger.info("11111112222223333#{request.env["HTTP_AUTHORIZATION"]}") + logger.info("11111112222223333 HTTP_AUTHORIZATION: #{request.env["HTTP_AUTHORIZATION"]}") logger.info("11111112222223333: request is #{request.env}") #logger.info("#########-----request_env: #{request.env}") # {"service"=>"git-receive-pack", "controller"=>"gits", "action"=>"auth", @@ -20,7 +20,9 @@ class GitsController < ApplicationController uid_logger("git start auth: input_username is #{input_username}") # Git 超级权限用户 + logger.info("666666666: a: #{input_username}, b: #{gituser}, c #{input_password} , d #{gitpassword}}") if input_username == gituser && input_password == gitpassword + result = true else # 用户是否对对象拥有权限 From 283ee9e5398c8bbb9bd3ad94027af6893bfa8a45 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 11:13:38 +0800 Subject: [PATCH 0108/1015] git usrname strip --- app/controllers/gits_controller.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/controllers/gits_controller.rb b/app/controllers/gits_controller.rb index e5d33acab..4064f0f99 100644 --- a/app/controllers/gits_controller.rb +++ b/app/controllers/gits_controller.rb @@ -20,9 +20,7 @@ class GitsController < ApplicationController uid_logger("git start auth: input_username is #{input_username}") # Git 超级权限用户 - logger.info("666666666: a: #{input_username}, b: #{gituser}, c #{input_password} , d #{gitpassword}}") - if input_username == gituser && input_password == gitpassword - + if input_username.strip == gituser.strip && input_password.strip == gitpassword.strip result = true else # 用户是否对对象拥有权限 From b004cb2e9960b2407dcd1d4ab99ff40ad56de1a7 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 11:14:57 +0800 Subject: [PATCH 0109/1015] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index a877b2b90..0177d71a2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -396,7 +396,7 @@ class User < ApplicationRecord when 0, 1, 3 # 申请发布或者已关闭的实训,只有实训管理员可以访问 manager_of_shixun?(shixun) when 2 - shixun.use_scope == 0 || (manager_of_shixun?(shixun) || shixun.shixun_schools.exists?(school_id: school_id)) + shixun.use_scope == 0 || manager_of_shixun?(shixun) || shixun.shixun_schools.exists?(school_id: school_id) end end From 41f92346dbc9d22bb286bc20d960dacc90d0c429 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 11:33:10 +0800 Subject: [PATCH 0110/1015] =?UTF-8?q?=E5=AF=BC=E8=88=AA=E6=A0=8F=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E5=AD=A6=E9=99=A2url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/get_navigation_info.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/users/get_navigation_info.json.jbuilder b/app/views/users/get_navigation_info.json.jbuilder index 57a303cb6..6b04a121c 100644 --- a/app/views/users/get_navigation_info.json.jbuilder +++ b/app/views/users/get_navigation_info.json.jbuilder @@ -30,6 +30,7 @@ json.top do json.my_project_url "#{@user_url}?type=a_project" json.account_manager_url "#{@old_domain}/my/account" json.logout_url logout_accounts_path + json.college_identifier @user.college_identifier # 旧版的域名 json.old_url @old_domain end From 6f7598bde102ae255bdf76d3aa196ffaf9d5dd33 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 12:08:22 +0800 Subject: [PATCH 0111/1015] fix bug --- .../exercise_answers_controller.rb | 32 ++++--------------- app/controllers/poll_votes_controller.rb | 30 +++++++++-------- 2 files changed, 24 insertions(+), 38 deletions(-) diff --git a/app/controllers/exercise_answers_controller.rb b/app/controllers/exercise_answers_controller.rb index 81f117daf..fec26d674 100644 --- a/app/controllers/exercise_answers_controller.rb +++ b/app/controllers/exercise_answers_controller.rb @@ -1,7 +1,6 @@ class ExerciseAnswersController < ApplicationController before_action :require_login before_action :get_exercise_question - before_action :commit_exercise_time include ExercisesHelper def create #每一次答案的点击,请求一次,实训题不在这里回答 @@ -95,9 +94,11 @@ class ExerciseAnswersController < ApplicationController def get_exercise_question @exercise_question = ExerciseQuestion.find_by_id(params[:exercise_question_id]) - @exercise = @exercise_question.exercise + @exercise = @exercise_question.exercise.includes(:exercise_users) @course = @exercise.course - @exercise_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first #当前用户 + @exercise_user = @exercise.exercise_users.find_by(user_id: current_user.id) #当前用户 + @exercise_user_status = @exercise.get_exercise_status(current_user.id) + if @exercise_question.blank? normal_status(-1,"试卷问题不存在!") @@ -105,34 +106,15 @@ class ExerciseAnswersController < ApplicationController normal_status(-1,"试卷不存在!") elsif @course.blank? normal_status(-1,"该课堂不存在!") - elsif (@exercise_user.present? && @exercise_user.commit_status == 1) || (@exercise.end_time.present? && @exercise.end_time < Time.now) #已提交答案的/时间已结束的试卷不允许再修改 + elsif (@exercise_user.present? && @exercise_user&.commit_status == 1) || @exercise_user_status == 3 #已提交答案的/时间已结束的试卷不允许再修改 normal_status(-1,"已提交/已结束的试卷不允许修改!") elsif @exercise.time > 0 - user_start_at = @exercise.exercise_users.exercise_commit_users(current_user.id).first.start_at - exercise_time = @exercise.time.to_i + user_start_at = @exercise_user&.start_at + exercise_time = @exercise.time.to_i + 1 # if (user_start_at + exercise_time.minutes) < Time.now normal_status(-1,"限时试卷已结束!") end - end - end - def commit_exercise_time - @exercise_user_current = @exercise.exercise_users.exercise_commit_users(current_user.id).first #查找当前用户是否有过答题 - if @exercise.exercise_status == 3 || (@exercise.time > 0 && ((@exercise_user_current&.start_at + (@exercise.time.to_i + 1).minutes) < Time.now)) - #当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制 - objective_score = calculate_student_score(@exercise,current_user)[:total_score] - subjective_score = @exercise_user_current&.subjective_score < 0.0 ? 0.0 : @exercise_user_current&.subjective_score - total_score = objective_score + subjective_score - commit_option = { - :status => 1, - :commit_status => 1, - :end_at => Time.now, - :objective_score => objective_score, - :score => total_score, - :subjective_score => subjective_score - } - @exercise_user_current.update_attributes(commit_option) - normal_status(-1,"考试时间已到,已交卷成功!") end end diff --git a/app/controllers/poll_votes_controller.rb b/app/controllers/poll_votes_controller.rb index a2f805a97..789d5748e 100644 --- a/app/controllers/poll_votes_controller.rb +++ b/app/controllers/poll_votes_controller.rb @@ -2,8 +2,7 @@ class PollVotesController < ApplicationController #在开始回答和提交问卷的时候,已经做了判断用户的身份权限 before_action :require_login before_action :get_poll_question - before_action :check_answer_in_question,only: [:create] - before_action :check_multi_answers + before_action :check_answer_in_question def create #每一次答案的点击,请求一次 @@ -124,7 +123,7 @@ class PollVotesController < ApplicationController if @poll_question.blank? normal_status(-1,"问卷试题不存在!") else - @poll = @poll_question.poll + @poll = @poll_question.poll.includes(:poll_users) @course = @poll.course if @poll.blank? normal_status(-1,"问卷不存在!") @@ -132,20 +131,22 @@ class PollVotesController < ApplicationController normal_status(-1,"课堂不存在!") end end - end def check_answer_in_question - poll_answer_ids = @poll_question.poll_answers.pluck(:id) - if @poll_question.question_type == 1 #单选题/多选题 - unless (params[:poll_answer_id].present? && poll_answer_ids.include?(params[:poll_answer_id].to_i)) || (params[:poll_answer_id].blank? && params[:vote_text].present?) - normal_status(-1, "答案ID错误!") - end - end - end + # poll_answer_ids = @poll_question.poll_answers.pluck(:id) + # if @poll_question.question_type == 1 #单选题/多选题 + # unless (params[:poll_answer_id].present? && poll_answer_ids.include?(params[:poll_answer_id].to_i)) || (params[:poll_answer_id].blank? && params[:vote_text].present?) + # normal_status(-1, "答案ID错误!") + # end + # end + poll_user_status = @poll.get_poll_status(current_user.id) + poll_user = @poll.poll_users.find_by(user_id: current_user.id) #当前用户 - def check_multi_answers - if @poll_question.question_type == 2 + question_type = @poll_question&.question_type + if [1,2].include?(question_type) && params[:poll_answer_id].blank? + normal_status(-1,"答案ID错误!") + elsif question_type == 2 user_vote_count = params[:poll_answer_id].size if @poll_question.max_choices.present? question_max_choices = @poll_question.max_choices @@ -155,6 +156,9 @@ class PollVotesController < ApplicationController if question_max_choices > 0 && user_vote_count > question_max_choices normal_status(-1,"多选题答案超过最大限制!") end + elsif (poll_user.present? && poll_user&.commit_status) || poll_user_status == 3 + normal_status(-1,"已提交/已结束的问卷不允许修改!") end end + end From 2243e890774b2a7bf26f0aba24e13f08ad02069a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 13:46:56 +0800 Subject: [PATCH 0112/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190328134047_sync_shixuninfo.rb | 8 -------- db/migrate/20190328152957_remove_column_for_shixun.rb | 5 ----- ...060799_modify_script_and_description_for_shixuninfo.rb | 1 + 3 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 db/migrate/20190328134047_sync_shixuninfo.rb delete mode 100644 db/migrate/20190328152957_remove_column_for_shixun.rb diff --git a/db/migrate/20190328134047_sync_shixuninfo.rb b/db/migrate/20190328134047_sync_shixuninfo.rb deleted file mode 100644 index bb374dc29..000000000 --- a/db/migrate/20190328134047_sync_shixuninfo.rb +++ /dev/null @@ -1,8 +0,0 @@ -class SyncShixuninfo < ActiveRecord::Migration[5.2] - def change - Shixun.find_each do |shixun| - ShixunInfo.create!(propaedeutics: shixun.propaedeutics, description: shixun.description, - evaluate_script: shixun.evaluate_script, shixun_id: shixun.id) - end - end -end diff --git a/db/migrate/20190328152957_remove_column_for_shixun.rb b/db/migrate/20190328152957_remove_column_for_shixun.rb deleted file mode 100644 index 70131a4b2..000000000 --- a/db/migrate/20190328152957_remove_column_for_shixun.rb +++ /dev/null @@ -1,5 +0,0 @@ -class RemoveColumnForShixun < ActiveRecord::Migration[5.2] - def change - remove_columns :shixuns, :description, :propaedeutics, :evaluate_script - end -end diff --git a/db/migrate/20190605060799_modify_script_and_description_for_shixuninfo.rb b/db/migrate/20190605060799_modify_script_and_description_for_shixuninfo.rb index 4b3318d56..151d3c03e 100644 --- a/db/migrate/20190605060799_modify_script_and_description_for_shixuninfo.rb +++ b/db/migrate/20190605060799_modify_script_and_description_for_shixuninfo.rb @@ -11,5 +11,6 @@ class ModifyScriptAndDescriptionForShixuninfo < ActiveRecord::Migration[5.2] evaluate_script: shixun[:evaluate_script], shixun_id: shixun.id) end end + remove_columns :shixuns, :description, :propaedeutics, :evaluate_script end end From faac0e76aa708de34d60f0b03b8f4ca913aa896c Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 13:56:06 +0800 Subject: [PATCH 0113/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...2055449_modify_shixun_info_for_shixuns.rb} | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) rename db/migrate/{20190605060799_modify_script_and_description_for_shixuninfo.rb => 20190622055449_modify_shixun_info_for_shixuns.rb} (77%) diff --git a/db/migrate/20190605060799_modify_script_and_description_for_shixuninfo.rb b/db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb similarity index 77% rename from db/migrate/20190605060799_modify_script_and_description_for_shixuninfo.rb rename to db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb index 151d3c03e..30ea96d65 100644 --- a/db/migrate/20190605060799_modify_script_and_description_for_shixuninfo.rb +++ b/db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb @@ -1,16 +1,18 @@ -class ModifyScriptAndDescriptionForShixuninfo < ActiveRecord::Migration[5.2] - def change - Shixun.find_each do |shixun| - if shixun.shixun_info - shixun.shixun_info.update_attributes(propaedeutics: shixun[:propaedeutics], - description: shixun[:description], - evaluate_script: shixun[:evaluate_script], - shixun_id: shixun[:id]) - else - ShixunInfo.create!(propaedeutics: shixun[:propaedeutics], description: shixun[:description], - evaluate_script: shixun[:evaluate_script], shixun_id: shixun.id) - end - end - remove_columns :shixuns, :description, :propaedeutics, :evaluate_script - end -end +class ModifyShixunInfoForShixuns < ActiveRecord::Migration[5.2] + def change + Shixun.find_each do |shixun| + if shixun.shixun_info + shixun.shixun_info.update_attributes(propaedeutics: shixun[:propaedeutics], + description: shixun[:description], + evaluate_script: shixun[:evaluate_script], + shixun_id: shixun[:id]) + else + ShixunInfo.create!(propaedeutics: shixun[:propaedeutics], description: shixun[:description], + evaluate_script: shixun[:evaluate_script], shixun_id: shixun.id) + end + end + if shixun.description.present? + remove_columns :shixuns, :description, :propaedeutics, :evaluate_script + end + end +end From 05cafcff8c49f8e236b2763a8ff63fbdf3018ece Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 13:57:58 +0800 Subject: [PATCH 0114/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb b/db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb index 30ea96d65..5b3ceada6 100644 --- a/db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb +++ b/db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb @@ -11,7 +11,7 @@ class ModifyShixunInfoForShixuns < ActiveRecord::Migration[5.2] evaluate_script: shixun[:evaluate_script], shixun_id: shixun.id) end end - if shixun.description.present? + if Shixun.first.description.present? remove_columns :shixuns, :description, :propaedeutics, :evaluate_script end end From db62c1d6c371c41a7206ce90a939be5a212b597a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 14:00:57 +0800 Subject: [PATCH 0115/1015] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E7=9A=84=E9=95=BF=E7=B1=BB=E5=9E=8B=E7=9A=84=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190622055449_modify_shixun_info_for_shixuns.rb | 3 --- .../20190622060005_remove_shixun_long_text_for_shixuns.rb | 7 +++++++ 2 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20190622060005_remove_shixun_long_text_for_shixuns.rb diff --git a/db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb b/db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb index 5b3ceada6..1a3aa147b 100644 --- a/db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb +++ b/db/migrate/20190622055449_modify_shixun_info_for_shixuns.rb @@ -11,8 +11,5 @@ class ModifyShixunInfoForShixuns < ActiveRecord::Migration[5.2] evaluate_script: shixun[:evaluate_script], shixun_id: shixun.id) end end - if Shixun.first.description.present? - remove_columns :shixuns, :description, :propaedeutics, :evaluate_script - end end end diff --git a/db/migrate/20190622060005_remove_shixun_long_text_for_shixuns.rb b/db/migrate/20190622060005_remove_shixun_long_text_for_shixuns.rb new file mode 100644 index 000000000..bcc8a2bce --- /dev/null +++ b/db/migrate/20190622060005_remove_shixun_long_text_for_shixuns.rb @@ -0,0 +1,7 @@ +class RemoveShixunLongTextForShixuns < ActiveRecord::Migration[5.2] + def change + if Shixun.first.description.present? + remove_columns :shixuns, :description, :propaedeutics, :evaluate_script + end + end +end From a76088fe30a77e1883f634348c9979080838dc39 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 14:04:45 +0800 Subject: [PATCH 0116/1015] fix bug --- app/controllers/exercise_questions_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 9e3259e6e..a0b88a97e 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -480,7 +480,7 @@ class ExerciseQuestionsController < ApplicationController ex_answers = @exercise_question.exercise_answers.search_answer_users("user_id",@user_id) #当前用户答案的得分 if @exercise_question.question_type == 3 #当为填空题,更新问题的总分, ex_answer_old = ex_answers.score_reviewed.pluck(:score).sum #每一关的得分总和 - each_right_score = (@c_score / ex_answers.count.to_f).round(1) #调分后,平均每关的分数 + each_right_score = (@c_score / ex_answers.count.to_f) #调分后,平均每关的分数 new_obj_score = ex_obj_score - ex_answer_old + @c_score total_scores = new_obj_score + ex_subj_score ex_scores = { @@ -615,7 +615,7 @@ class ExerciseQuestionsController < ApplicationController normal_status(-1,"题目不允许为空!") if (params[:question_title].blank? && params[:question_type].to_i !=5 ) #除了实训题,其余题目必需有题干 normal_status(-1,"问题类型不允许为空!" ) if params[:question_type].blank? normal_status(-1,"分值不允许为空!" ) if params[:question_score].blank? && params[:question_scores].blank? #分值的数组或参数必需存在一个 - if params[:question_score].present? && params[:question_score].to_f.round(1) <= 0.0 #问题类型存在,则分值不能为空,且必需大于0 + if params[:question_score].present? && params[:question_score].to_f <= 0.0 #问题类型存在,则分值不能为空,且必需大于0 normal_status(-1,"分值必需大于0!") elsif (params[:question_score].present? && params[:question_score].to_f.round(1) > 100.0) || (params[:question_scores].present? && (params[:question_scores].map{|a| a.to_f.round(1)}.max > 100.0)) normal_status(-1,"分值不能超过100分!") @@ -677,7 +677,7 @@ class ExerciseQuestionsController < ApplicationController end def check_adjust_score - @c_score = params[:score].to_f.round(1) #调分后的分数 + @c_score = params[:score].to_f #调分后的分数 @user_id = params[:user_id] @exercise_current_user = @exercise.exercise_users.exercise_commit_users(@user_id).first #当前试卷用户的答案内容 if @exercise_current_user.blank? From 899c7fb673408e839febe7b9720af7bee9c2a8d9 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 14:08:45 +0800 Subject: [PATCH 0117/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190622060005_remove_shixun_long_text_for_shixuns.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20190622060005_remove_shixun_long_text_for_shixuns.rb b/db/migrate/20190622060005_remove_shixun_long_text_for_shixuns.rb index bcc8a2bce..4557c610f 100644 --- a/db/migrate/20190622060005_remove_shixun_long_text_for_shixuns.rb +++ b/db/migrate/20190622060005_remove_shixun_long_text_for_shixuns.rb @@ -1,6 +1,6 @@ class RemoveShixunLongTextForShixuns < ActiveRecord::Migration[5.2] def change - if Shixun.first.description.present? + if Shixun.first.has_attribute?(:description) remove_columns :shixuns, :description, :propaedeutics, :evaluate_script end end From 19617532734469ddd05feb48e1b152c8a350a818 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 14:37:01 +0800 Subject: [PATCH 0118/1015] fix bug --- app/helpers/export_helper.rb | 2 +- .../exercise_export/blank_exercise.html.erb | 10 +++++----- .../exercise_export/exercise_export.css | 3 +++ .../exercise_export/exercise_user.html.erb | 16 ++++++++-------- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index a5e3c5d9d..918995bef 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -245,7 +245,7 @@ module ExportHelper else user_course = "--" end - user_obj_score = e_user.objective_score < 0.0 ? 0.0 : e_user.subjective_score.round(1).to_s + user_obj_score = e_user.objective_score < 0.0 ? 0.0 : e_user.objective_score.round(1).to_s user_suj_score = e_user.subjective_score < 0.0 ? 0.0 : e_user.subjective_score.round(1).to_s user_score = e_user.score.present? ? e_user.score.round(1).to_s : 0.0 if e_user.commit_status.present? && e_user.commit_status == 1 diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 61bde0d27..123e114b1 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -13,13 +13,13 @@

- <%= @exercise.try(:exercise_description).nil? ? "" : @exercise.try(:exercise_description).html_safe %> + <%= @exercise.try(:exercise_description).nil? ? "" : @exercise.try(:exercise_description)&.html_safe %>

-
+
<% if @exercise_single_ques_count > 0 %> 单选题<%= @exercise_single_ques_count %>题, 共<%= @exercise_single_ques_scores %> @@ -63,12 +63,12 @@
<% if q.question_type == 5 %> - <%= q.shixun_name.present? ? q.shixun_name.html_safe : "" %> + <%= q.shixun_name.present? ? q.shixun_name&.html_safe : "" %>
- <%= q.question_title.present? ? q.question_title.html_safe : "" %> + <%= q.question_title.present? ? q.question_title&.html_safe : "" %>
<% else %> - <%= q.question_title.present? ? q.question_title.html_safe : "" %> + <%= q.question_title.present? ? q.question_title&.html_safe : "" %> <% end %>
diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 91f25e45e..4747e9eed 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -303,6 +303,9 @@ textarea{ background-color:#eee; line-height:2; } +.max-100{ + max-width:100%; +} diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 713f09ee4..67aaf493a 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -13,13 +13,13 @@

- <%= @exercise.try(:exercise_description).nil? ? "" : @exercise.try(:exercise_description).html_safe %> + <%= @exercise.try(:exercise_description).nil? ? "" : @exercise.try(:exercise_description)&.html_safe %>

-
+
<% if @exercise_single_ques_count > 0 %> 单选题<%= @exercise_single_ques_count %>题, 共<%= @exercise_single_ques_scores %> @@ -162,14 +162,14 @@
<% if q_type == 5 %> - <%= q.shixun_name.html_safe %> + <%= q.shixun_name&.html_safe %>
- <%= q.question_title.html_safe %> + <%= q.question_title&.html_safe %>
<% elsif q_type == 4 %> - <%= q.question_title.html_safe %> + <%= q.question_title&.html_safe %> <% else %> - <%= q.question_title.html_safe %> + <%= q.question_title&.html_safe %> <% end %>
@@ -218,13 +218,13 @@ <% end %>

答案(填空<%= index+1 %>): - <%= check_answer.html_safe %> + <%= check_answer&.html_safe %>

<% end %> <% elsif q_type == 4 %> <% check_answer = (user_answer.present? ? user_answer.first.answer_text : '--') %>

- <%= check_answer.html_safe %> + <%= check_answer&.html_safe %>

<% else %>
From 9642805db14358b21777ead1bf681fd0e84c9565 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 14:45:25 +0800 Subject: [PATCH 0119/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=8A=A5=E5=91=8A?= =?UTF-8?q?=E8=B6=85=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index aa0a0f171..9c71b82e2 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -429,7 +429,7 @@ class StudentWorksController < ApplicationController def shixun_work_report @user = @work.user @shixun = @homework.shixuns.take - @games = @work.myshixun.games.includes(:challenge, :game_codes,:outputs) if @work.myshixun + @games = @work.myshixun.games.includes(:challenge) if @work.myshixun # 用户最大评测次数 @user_evaluate_count = @games.inject(0){|sum, g| sum + g.outputs.pluck(:query_index).first.to_i } if @games From f630266141e4d7e51b6ba93e400fadd8518257d9 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 14:48:47 +0800 Subject: [PATCH 0120/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=8A=A5=E5=91=8A?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 9c71b82e2..213ea40c0 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -432,7 +432,7 @@ class StudentWorksController < ApplicationController @games = @work.myshixun.games.includes(:challenge) if @work.myshixun # 用户最大评测次数 - @user_evaluate_count = @games.inject(0){|sum, g| sum + g.outputs.pluck(:query_index).first.to_i } if @games + @user_evaluate_count = @games.sum(:evaluate_count) if @games # 图形效率图的数据 @echart_data = student_efficiency(@homework, @work) end @@ -440,10 +440,10 @@ class StudentWorksController < ApplicationController def export_shixun_work_report @user = @work.user @shixun = @homework.shixuns.take - @games = @work.myshixun.games.includes(:challenge, :game_codes,:outputs) if @work.myshixun + @games = @work.myshixun.games.includes(:challenge, :game_codes) if @work.myshixun # 用户最大评测次数 - @user_evaluate_count = @games.inject(0){|sum, g| sum + g.outputs.pluck(:query_index).first.to_i } if @games + @user_evaluate_count = @games.sum(:evaluate_count) if @games # 图形效率图的数据 @echart_data = student_efficiency(@homework, @work) @myself_eff = @echart_data[:efficiency_list].find { |item| item.last == @user.id } From 152fcd9bc454d850ccd31e1dea392f9a5abd652c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 14:49:57 +0800 Subject: [PATCH 0121/1015] fix bug --- app/controllers/homework_commons_controller.rb | 13 +++++++++---- .../exercise_export/blank_exercise.html.erb | 2 +- app/templates/exercise_export/exercise_export.css | 4 ++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index ec3f0ab9a..5e8f7b67e 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -200,10 +200,15 @@ class HomeworkCommonsController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") else - student_work_to_xlsx(@work_excel,@homework) - exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: - {table_columns: @work_head_cells,task_users: @work_cells_column} + if @work_excel.size > 0 + student_work_to_xlsx(@work_excel,@homework) + exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') + render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: + {table_columns: @work_head_cells,task_users: @work_cells_column} + else + normal_status(-1,"暂无提交的学生!") + end + end } format.zip{ diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 123e114b1..53466929d 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -18,7 +18,7 @@
-
+
<% if @exercise_single_ques_count > 0 %> 单选题<%= @exercise_single_ques_count %>题, diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 4747e9eed..454bb1c26 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -306,6 +306,10 @@ textarea{ .max-100{ max-width:100%; } +.width100{ + width:100%; + word-break:normal; +} From c0df2b017f72371bbefc2027168682b2da16b609 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 22 Jun 2019 14:52:10 +0800 Subject: [PATCH 0122/1015] =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190621105144_sync_ivalid_users.rb | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/db/migrate/20190621105144_sync_ivalid_users.rb b/db/migrate/20190621105144_sync_ivalid_users.rb index 3520ca84d..f2875977f 100644 --- a/db/migrate/20190621105144_sync_ivalid_users.rb +++ b/db/migrate/20190621105144_sync_ivalid_users.rb @@ -1,34 +1,34 @@ class SyncIvalidUsers < ActiveRecord::Migration[5.2] - def change - users = User.where.not(id: 2).find_by_sql("select count(*) as user_count, login from users group by login having user_count>1") - users.each do |user| - valid_users = User.where(login: user.login) - valid_users.each do |valid_user| - unless valid_user.lastname.present? - valid_user.delete - end - end - end - - mail_users = User.where.not(id: 2).find_by_sql("select count(*) as user_count, mail from users where mail is not null group by mail having user_count>1") - mail_users.each do |mail_user| - valid_mail_users = User.where(mail: mail_user.mail) - valid_mail_users.each do |valid_mail_user| - unless valid_mail_user.lastname.present? - valid_mail_user.delete - end - end - end - - - phone_users = User.where.not(id: 2).find_by_sql("select count(*) as user_count, phone from users where phone is not null group by phone having user_count>1") - phone_users.each do |phone_user| - valid_phone_users = User.where(phone: phone_user.phone) - valid_phone_users.each do |valid_phone_user| - unless valid_phone_user.lastname.present? - valid_phone_user.delete - end - end - end - end + # def change + # users = User.where.not(id: 2).find_by_sql("select count(*) as user_count, login from users group by login having user_count>1") + # users.each do |user| + # valid_users = User.where(login: user.login) + # valid_users.each do |valid_user| + # unless valid_user.lastname.present? + # valid_user.delete + # end + # end + # end + # + # mail_users = User.where.not(id: 2).find_by_sql("select count(*) as user_count, mail from users where mail is not null group by mail having user_count>1") + # mail_users.each do |mail_user| + # valid_mail_users = User.where(mail: mail_user.mail) + # valid_mail_users.each do |valid_mail_user| + # unless valid_mail_user.lastname.present? + # valid_mail_user.delete + # end + # end + # end + # + # + # phone_users = User.where.not(id: 2).find_by_sql("select count(*) as user_count, phone from users where phone is not null group by phone having user_count>1") + # phone_users.each do |phone_user| + # valid_phone_users = User.where(phone: phone_user.phone) + # valid_phone_users.each do |valid_phone_user| + # unless valid_phone_user.lastname.present? + # valid_phone_user.delete + # end + # end + # end + # end end From 218020fdcadca69d8b2b238d39bd8b758c679f9d Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 14:52:52 +0800 Subject: [PATCH 0123/1015] fix bug --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 5e8f7b67e..a9843a5cc 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -200,7 +200,7 @@ class HomeworkCommonsController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") else - if @work_excel.size > 0 + if @work_excel.present? student_work_to_xlsx(@work_excel,@homework) exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: From 980cb9e730545abc7827f442a19f4f1e4441e850 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 14:54:05 +0800 Subject: [PATCH 0124/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=8A=A5=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 213ea40c0..9e3a1930c 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -429,7 +429,7 @@ class StudentWorksController < ApplicationController def shixun_work_report @user = @work.user @shixun = @homework.shixuns.take - @games = @work.myshixun.games.includes(:challenge) if @work.myshixun + @games = @work.myshixun.games.includes(:challenge, :game_codes, :outputs) if @work.myshixun # 用户最大评测次数 @user_evaluate_count = @games.sum(:evaluate_count) if @games @@ -440,7 +440,7 @@ class StudentWorksController < ApplicationController def export_shixun_work_report @user = @work.user @shixun = @homework.shixuns.take - @games = @work.myshixun.games.includes(:challenge, :game_codes) if @work.myshixun + @games = @work.myshixun.games.includes(:challenge, :game_codes, :outputs) if @work.myshixun # 用户最大评测次数 @user_evaluate_count = @games.sum(:evaluate_count) if @games From 2bbd5dcc2456a81a64aa7ca8aa547ed019f0d89f Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 14:59:45 +0800 Subject: [PATCH 0125/1015] .. --- db/migrate/20190622065825_add_profile_completed_to_uses.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 db/migrate/20190622065825_add_profile_completed_to_uses.rb diff --git a/db/migrate/20190622065825_add_profile_completed_to_uses.rb b/db/migrate/20190622065825_add_profile_completed_to_uses.rb new file mode 100644 index 000000000..ef2cc2bf2 --- /dev/null +++ b/db/migrate/20190622065825_add_profile_completed_to_uses.rb @@ -0,0 +1,5 @@ +class AddProfileCompletedToUses < ActiveRecord::Migration[5.2] + def change + add_column :users, :profile_completed, :boolean, default: false + end +end From 1f3ab3645d46e3c8d200caae088b1db1d3979aa2 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 15:00:17 +0800 Subject: [PATCH 0126/1015] reset --- db/migrate/20190622065825_add_profile_completed_to_uses.rb | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 db/migrate/20190622065825_add_profile_completed_to_uses.rb diff --git a/db/migrate/20190622065825_add_profile_completed_to_uses.rb b/db/migrate/20190622065825_add_profile_completed_to_uses.rb deleted file mode 100644 index ef2cc2bf2..000000000 --- a/db/migrate/20190622065825_add_profile_completed_to_uses.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddProfileCompletedToUses < ActiveRecord::Migration[5.2] - def change - add_column :users, :profile_completed, :boolean, default: false - end -end From 3b68ce2474a778cbc4458f1f25f6ee85245adc55 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 15:07:06 +0800 Subject: [PATCH 0127/1015] fix bug --- config/initializers/pdfkit.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/config/initializers/pdfkit.rb b/config/initializers/pdfkit.rb index 168fc0c1e..bb562f473 100644 --- a/config/initializers/pdfkit.rb +++ b/config/initializers/pdfkit.rb @@ -6,8 +6,9 @@ PDFKit.configure do |config| dpi: 300, debug_javascript: true, javascript_delay: 500, - stop_slow_scripts:false, - no_stop_slow_scripts: true + quiet: false + # stop_slow_scripts:false, + # no_stop_slow_scripts: true } end From 620539b9247b47847171910730e4c88c7f60d8f7 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 22 Jun 2019 15:18:24 +0800 Subject: [PATCH 0128/1015] =?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/homework_commons_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index ec3f0ab9a..e4ed35b4b 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -173,8 +173,8 @@ class HomeworkCommonsController < ApplicationController end # 排序 - rorder = params[:order] || "update_time" - b_order = params[:b_order] || "desc" + rorder = params[:order].blank? ? "update_time" : params[:order] + b_order = params[:b_order].blank? ? "desc" : params[:b_order] if rorder == "update_time" || rorder == "work_score" @student_works = @student_works.order("student_works.#{rorder} #{b_order}") elsif rorder == "student_id" From c4c93fb0e1445960e972cb78615c5897f561e15e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 15:20:33 +0800 Subject: [PATCH 0129/1015] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shixuns/_shixun.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shixuns/_shixun.json.jbuilder b/app/views/shixuns/_shixun.json.jbuilder index 6913c4745..ebc0c520d 100644 --- a/app/views/shixuns/_shixun.json.jbuilder +++ b/app/views/shixuns/_shixun.json.jbuilder @@ -13,7 +13,7 @@ json.array! shixuns do |shixun| json.identifier shixun.identifier json.name shixun.name json.status shixun.status - json.power (User.current.shixun_permission(shixun)) # 现在首页只显示已发布的实训 + json.power (current_user.shixun_permission(shixun)) # 现在首页只显示已发布的实训 # REDO: 局部缓存 json.tag_name shixun.tag_repertoires.first.try(:name) json.myshixuns_count shixun.myshixuns_count From 32479e4d3a8f4ffeff1dda8e7e22243a8fd54db9 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 22 Jun 2019 15:22:57 +0800 Subject: [PATCH 0130/1015] =?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/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 a1f1d01c4..2e72c57d3 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -109,8 +109,8 @@ class GraduationTasksController < ApplicationController end # 排序 - rorder = params[:order] || "updated_at" - b_order = params[:b_order] || "desc" + rorder = params[:order].blank? ? "updated_at" : params[:order] + b_order = params[:b_order].blank? ? "desc" : params[:b_order] if rorder == "created_at" || rorder == "work_score" @work_list = @work_list.order("graduation_works.#{rorder} #{b_order}") elsif rorder == "student_id" From cf5e40b97f2d35c46ced9d3fec2a09667379a589 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 15:29:11 +0800 Subject: [PATCH 0131/1015] fix but --- app/templates/exercise_export/blank_exercise.html.erb | 4 ++-- config/initializers/pdfkit.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 53466929d..9028139cb 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -19,7 +19,7 @@
-
+
<% if @exercise_single_ques_count > 0 %> 单选题<%= @exercise_single_ques_count %>题, 共<%= @exercise_single_ques_scores %> @@ -45,7 +45,7 @@ 共<%= @exercise_ques_shixun_scores %>分 <% end %>
-
合计<%= @exercise_ques_count %>题, +
合计<%= @exercise_ques_count %>题, 共<%= @exercise_ques_scores %>
diff --git a/config/initializers/pdfkit.rb b/config/initializers/pdfkit.rb index bb562f473..36ff30963 100644 --- a/config/initializers/pdfkit.rb +++ b/config/initializers/pdfkit.rb @@ -6,9 +6,9 @@ PDFKit.configure do |config| dpi: 300, debug_javascript: true, javascript_delay: 500, - quiet: false - # stop_slow_scripts:false, - # no_stop_slow_scripts: true + # quiet: false + stop_slow_scripts:false, + no_stop_slow_scripts: true } end From 112281a3a10a9143fa16bf25a56e195244f931db Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 15:33:40 +0800 Subject: [PATCH 0132/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=9D=83=E9=99=90?= =?UTF-8?q?=E7=9A=84=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 0177d71a2..0d5517c50 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -390,13 +390,17 @@ class User < ApplicationRecord # 2、实训隐藏了只有管理员、实训合作者能看到 # 3、如果有限制学校范围,则学校的用户、管理员、实训合作者能看到 def shixun_permission(shixun) - case status + case shixun.status when -1 # 软删除只有管理员能访问 admin? when 0, 1, 3 # 申请发布或者已关闭的实训,只有实训管理员可以访问 manager_of_shixun?(shixun) when 2 - shixun.use_scope == 0 || manager_of_shixun?(shixun) || shixun.shixun_schools.exists?(school_id: school_id) + if shixun.hidden + manager_of_shixun?(shixun) + else + shixun.use_scope == 0 || manager_of_shixun?(shixun) || shixun.shixun_schools.exists?(school_id: school_id) + end end end From 8f3584733e062c98da1074ac910a4bbc9b7bb976 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 15:49:11 +0800 Subject: [PATCH 0133/1015] =?UTF-8?q?=E9=98=BF=E9=87=8C=E4=BA=91=E7=89=88?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shixuns/_top.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shixuns/_top.json.jbuilder b/app/views/shixuns/_top.json.jbuilder index ef15e2515..ebb77ec74 100644 --- a/app/views/shixuns/_top.json.jbuilder +++ b/app/views/shixuns/_top.json.jbuilder @@ -1,4 +1,4 @@ -json.status shixun.status +json.shixun_status shixun.status # REDO:前端需要通过status来判断发布 json.task_operation task_operation_url(current_myshixun, shixun) From 4e0f9b4842c4c7273563958341e1df5db3bea7b4 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 16:00:38 +0800 Subject: [PATCH 0134/1015] fix bug --- .../exercise_export/blank_exercise.html.erb | 18 +- .../exercise_export/exercise_export.css | 9 +- .../exercise_export/exercise_user.html.erb | 17 +- public/123.html | 366 ++++++++++++++++++ 4 files changed, 392 insertions(+), 18 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 9028139cb..2745f8cbe 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -18,8 +18,8 @@
-
-
+
+

<% if @exercise_single_ques_count > 0 %> 单选题<%= @exercise_single_ques_count %>题, 共<%= @exercise_single_ques_scores %> @@ -44,10 +44,16 @@ 实训题<%= @exercise_ques_shixun_count %>题, 共<%= @exercise_ques_shixun_scores %> <% end %> -

-
合计<%= @exercise_ques_count %>题, - 共<%= @exercise_ques_scores %>分 -
+ + <% if @exercise_ques_count > 0 %> + + 共<%= @exercise_ques_scores %>分 + + + 合计<%= @exercise_ques_count %>题 + + <% end %> +

diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 454bb1c26..884a49af0 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -303,12 +303,9 @@ textarea{ background-color:#eee; line-height:2; } -.max-100{ - max-width:100%; -} -.width100{ - width:100%; - word-break:normal; +.clearfix{ + clear:both; + zoom:1; } diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 67aaf493a..088ff1fd4 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -19,7 +19,7 @@
-
+

<% if @exercise_single_ques_count > 0 %> 单选题<%= @exercise_single_ques_count %>题, 共<%= @exercise_single_ques_scores %> @@ -44,11 +44,16 @@ 实训题<%= @exercise_ques_shixun_count %>题, 共<%= @exercise_ques_shixun_scores %> <% end %> -

-
- 合计<%= @exercise_ques_count %>题, - 共<%= @exercise_ques_scores %>分 -
+ + <% if @exercise_ques_count > 0 %> + + 共<%= @exercise_ques_scores %>分 + + + 合计<%= @exercise_ques_count %>题 + + <% end %> +

diff --git a/public/123.html b/public/123.html index e69de29bb..8986880e5 100644 --- a/public/123.html +++ b/public/123.html @@ -0,0 +1,366 @@ + + + + + + + + + +
+
+

+ + 单选题5题,共10分 + + + 单选题5题,共10分 + + + 单选题5题,共10分 + + + 单选题5题,共10分 + + + 共10分 + + + 合计20题 + + + +

+ + + + + + + +
+
+ + + \ No newline at end of file From 8e3af838907ee42d74bd0809ca99f2f75a3ae43d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 16:06:47 +0800 Subject: [PATCH 0135/1015] =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/environments/production.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index c3950f345..be2bdf3d7 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -96,7 +96,8 @@ Rails.application.configure do config.active_record.belongs_to_required_by_default = false # config.cache_store = :file_store, "#{Rails.root }/files/cache_store/" - config.cache_store = :redis_store, 'redis://r-bp122bd1b710f274.redis.rds.aliyuncs.com:6379/0/cache', { expires_in: 90.minutes } + #config.cache_store = :redis_store, 'redis://r-bp122bd1b710f274.redis.rds.aliyuncs.com:6379/0/cache', { expires_in: 90.minutes } + config.cache_store = :redis_store, 'redis://10.9.72.102:6379/0/cache', { expires_in: 90.minutes } config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { From 73d9a633e9d13ac2f2f782e19ee3b8f740beb7de Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 16:17:44 +0800 Subject: [PATCH 0136/1015] fix bug --- app/controllers/zips_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 89f473499..f0ab50001 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -46,7 +46,7 @@ class ZipsController < ApplicationController else @course = @exercise.course - default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed + default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed.limit 2 default_ex_users_size = default_ex_users.size @ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。 #可以分班选择 From 2fa4e118feade84bf0a5a397db170f3ed2dc3431 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 16:33:17 +0800 Subject: [PATCH 0137/1015] =?UTF-8?q?git=20=E6=8F=90=E4=BA=A4=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E6=B2=A1=E5=AE=9A=E4=BD=8D=E5=88=B0=E5=85=B7=E4=BD=93?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E7=9A=84=E6=97=B6=E5=80=99=E5=A4=84=E7=90=86?= =?UTF-8?q?=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shixuns/_commit.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/shixuns/_commit.json.jbuilder b/app/views/shixuns/_commit.json.jbuilder index cd934baea..b752affb6 100644 --- a/app/views/shixuns/_commit.json.jbuilder +++ b/app/views/shixuns/_commit.json.jbuilder @@ -14,6 +14,7 @@ json.commits commits do |commit| json.author do json.id nil json.login nil + json.image_url "avatars/User/b" json.name commit["author_name"] json.email commit["author_email"] end From 5f0f16e1d8400aefe3f986c5407d7c5729ea0466 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 16:43:04 +0800 Subject: [PATCH 0138/1015] fix b ug --- config/initializers/pdfkit.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/initializers/pdfkit.rb b/config/initializers/pdfkit.rb index 36ff30963..556076f4b 100644 --- a/config/initializers/pdfkit.rb +++ b/config/initializers/pdfkit.rb @@ -1,5 +1,6 @@ PDFKit.configure do |config| - config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || 'wkhtmltopdf' + # config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || 'wkhtmltopdf' + config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || '/usr/bin/wkhtmltopdf' config.default_options = { page_size: 'A4', print_media_type: true, From e10a29306d7c78ef0c94d5e766ad1ae95219cb47 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 22 Jun 2019 16:44:57 +0800 Subject: [PATCH 0139/1015] =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=88=86=E7=8F=AD?= =?UTF-8?q?=E7=9A=84=E8=AF=BE=E5=A0=82=E4=B8=8D=E6=98=BE=E7=A4=BA=E6=9C=AA?= =?UTF-8?q?=E5=88=86=E7=8F=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/courses_helper.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 8c88f02d0..a56eb27a6 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -246,15 +246,17 @@ module CoursesHelper def left_group_info course group_info = [] - course.course_groups.each do |course_group| - group_info << {category_id: course_group.id, category_name: course_group.name, position: course_group.position, - category_count: course_group.course_members_count, category_type: false, - second_category_url: "/courses/#{@course.id}/course_groups/#{course_group.id}"} + if course.course_groups_count > 0 + course.course_groups.each do |course_group| + group_info << {category_id: course_group.id, category_name: course_group.name, position: course_group.position, + category_count: course_group.course_members_count, category_type: false, + second_category_url: "/courses/#{@course.id}/course_groups/#{course_group.id}"} + end + none_group_count = course.students.where(course_group_id: 0).size + group_info << {category_id: 0, category_name: "未分班", position: course.course_groups.pluck(:position).max.to_i + 1, + category_count: none_group_count, category_type: false, + second_category_url: "/courses/#{@course.id}/course_groups/0"} end - none_group_count = course.students.where(course_group_id: 0).size - group_info << {category_id: 0, category_name: "未分班", position: course.course_groups.pluck(:position).max.to_i + 1, - category_count: none_group_count, category_type: false, - second_category_url: "/courses/#{@course.id}/course_groups/0"} end end From f4503cc467a43b2e1074bb060d613808466fb161 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 22 Jun 2019 16:47:53 +0800 Subject: [PATCH 0140/1015] =?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/helpers/courses_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index a56eb27a6..226a45570 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -257,6 +257,7 @@ module CoursesHelper category_count: none_group_count, category_type: false, second_category_url: "/courses/#{@course.id}/course_groups/0"} end + group_info end end From 08861416f2f1c7fdad04bf4e00be6781d321d874 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 16:52:28 +0800 Subject: [PATCH 0141/1015] =?UTF-8?q?TPI=E5=A4=B4=E5=83=8F=E7=82=B9?= =?UTF-8?q?=E5=87=BB=E8=B7=B3=E8=BD=AC=E6=9C=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/_user.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/_user.json.jbuilder b/app/views/users/_user.json.jbuilder index 1d26506f3..8c5f58265 100644 --- a/app/views/users/_user.json.jbuilder +++ b/app/views/users/_user.json.jbuilder @@ -4,5 +4,5 @@ json.name user.full_name json.grade user.grade # json.email user.mail # 邮箱原则上不暴露的,如果实在需要的话只能对某些具体的接口公开 json.image_url url_to_avatar(user) -json.user_url user_path(user) +json.user_url "/users/#{user.login}" json.school user.school_name \ No newline at end of file From db67ed37fadf7751851e41e54193fe974e8ed45c Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 16:54:55 +0800 Subject: [PATCH 0142/1015] =?UTF-8?q?=E5=88=A0=E9=99=A4tpi=E7=9A=84user=5F?= =?UTF-8?q?url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/_user.json.jbuilder | 1 - 1 file changed, 1 deletion(-) diff --git a/app/views/users/_user.json.jbuilder b/app/views/users/_user.json.jbuilder index 8c5f58265..afec979a1 100644 --- a/app/views/users/_user.json.jbuilder +++ b/app/views/users/_user.json.jbuilder @@ -4,5 +4,4 @@ json.name user.full_name json.grade user.grade # json.email user.mail # 邮箱原则上不暴露的,如果实在需要的话只能对某些具体的接口公开 json.image_url url_to_avatar(user) -json.user_url "/users/#{user.login}" json.school user.school_name \ No newline at end of file From 66c2f52f4896491dee0e3985a005bc995003ab3f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 16:56:47 +0800 Subject: [PATCH 0143/1015] =?UTF-8?q?user.jbuider=E8=BF=98=E6=98=AF?= =?UTF-8?q?=E9=9C=80=E8=A6=81user=5Furl=E4=BA=86=EF=BC=8C=E5=A4=AA?= =?UTF-8?q?=E5=A4=9A=E6=8E=A5=E5=8F=A3=E8=B0=83=E7=94=A8=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E6=94=B9=E7=9A=84=E5=A4=AA=E9=BA=BB=E7=83=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/_user.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/users/_user.json.jbuilder b/app/views/users/_user.json.jbuilder index afec979a1..8c5f58265 100644 --- a/app/views/users/_user.json.jbuilder +++ b/app/views/users/_user.json.jbuilder @@ -4,4 +4,5 @@ json.name user.full_name json.grade user.grade # json.email user.mail # 邮箱原则上不暴露的,如果实在需要的话只能对某些具体的接口公开 json.image_url url_to_avatar(user) +json.user_url "/users/#{user.login}" json.school user.school_name \ No newline at end of file From 8fce13d83aaacb289543344faf6b2167881c5d18 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 16:58:01 +0800 Subject: [PATCH 0144/1015] fix bug --- app/controllers/zips_controller.rb | 7 ++++--- config/initializers/pdfkit.rb | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index f0ab50001..41407f876 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -20,6 +20,7 @@ class ZipsController < ApplicationController exercises = ExportExercisesService.new(@exercise,@ex_users) file_name = filename_for_content_disposition(exercises.filename) + logger.info("##################_______________________file_name_____________________############{file_name}") send_file exercises.ex_zip, filename: file_name, type: 'application/zip' rescue Exception => e normal_status(-1, e.message) @@ -39,14 +40,14 @@ class ZipsController < ApplicationController def get_exercise ActiveRecord::Base.transaction do begin - @exercise = Exercise.find_by(id:params[:exercise_id]) + @exercise = Exercise.find_by(id:params[:exercise_id]).includes(:exercise_users) group_id = params[:exercise_group_id] if @exercise.blank? normal_status(-1,"试卷不存在") else - @course = @exercise.course + @course = @exercise.course.includes(:course_members) - default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed.limit 2 + default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed default_ex_users_size = default_ex_users.size @ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。 #可以分班选择 diff --git a/config/initializers/pdfkit.rb b/config/initializers/pdfkit.rb index 556076f4b..0cd80c9c7 100644 --- a/config/initializers/pdfkit.rb +++ b/config/initializers/pdfkit.rb @@ -1,7 +1,8 @@ PDFKit.configure do |config| - # config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || 'wkhtmltopdf' - config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || '/usr/bin/wkhtmltopdf' + config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || 'wkhtmltopdf' + # config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || '/usr/bin/wkhtmltopdf' config.default_options = { + encoding: "UTF-8", page_size: 'A4', print_media_type: true, dpi: 300, From d335f9315e20b51910032d3ae160d8a41dc71907 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 16:59:32 +0800 Subject: [PATCH 0145/1015] =?UTF-8?q?tpi=E6=8E=A5=E5=8F=A3=E5=8E=BB?= =?UTF-8?q?=E9=99=A4user=5Furl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/_user.json.jbuilder | 1 - 1 file changed, 1 deletion(-) diff --git a/app/views/users/_user.json.jbuilder b/app/views/users/_user.json.jbuilder index 8c5f58265..afec979a1 100644 --- a/app/views/users/_user.json.jbuilder +++ b/app/views/users/_user.json.jbuilder @@ -4,5 +4,4 @@ json.name user.full_name json.grade user.grade # json.email user.mail # 邮箱原则上不暴露的,如果实在需要的话只能对某些具体的接口公开 json.image_url url_to_avatar(user) -json.user_url "/users/#{user.login}" json.school user.school_name \ No newline at end of file From b0bee8bc75e2df5d4eff20ff0553c3d11fa55760 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 16:59:51 +0800 Subject: [PATCH 0146/1015] fix bug --- app/controllers/zips_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 41407f876..35373730c 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -40,12 +40,12 @@ class ZipsController < ApplicationController def get_exercise ActiveRecord::Base.transaction do begin - @exercise = Exercise.find_by(id:params[:exercise_id]).includes(:exercise_users) + @exercise = Exercise.includes(:exercise_users).find_by(id:params[:exercise_id]) group_id = params[:exercise_group_id] if @exercise.blank? normal_status(-1,"试卷不存在") else - @course = @exercise.course.includes(:course_members) + @course = @exercise.course default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed default_ex_users_size = default_ex_users.size From aa8c02a9a7c836579362abb72f2ef1c2eb5dc768 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 22 Jun 2019 17:02:04 +0800 Subject: [PATCH 0147/1015] =?UTF-8?q?=E6=95=99=E5=B8=88=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E6=9D=83=E9=99=90=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 7 +++++++ app/controllers/course_groups_controller.rb | 2 +- app/controllers/courses_controller.rb | 8 ++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1915281bf..36659ff4a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -126,6 +126,13 @@ class ApplicationController < ActionController::Base end end + # 课堂教师、课堂管理员、超级管理员的权限(不包含助教) + def teacher_or_admin_allowed + unless current_user.course_identity(@course) < Course::ASSISTANT_PROFESSOR + normal_status(403, "") + end + end + def require_admin normal_status(403, "") unless User.current.admin? end diff --git a/app/controllers/course_groups_controller.rb b/app/controllers/course_groups_controller.rb index 8b6737e0f..bee3fa09d 100644 --- a/app/controllers/course_groups_controller.rb +++ b/app/controllers/course_groups_controller.rb @@ -2,7 +2,7 @@ class CourseGroupsController < ApplicationController before_action :require_login before_action :set_group, except: [:create] before_action :find_course, only: [:create] - before_action :teacher_allowed + before_action :teacher_or_admin_allowed def create tip_exception("分班名称不能为空") if params[:name].blank? diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 3d0926994..b76673945 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -25,11 +25,11 @@ class CoursesController < ApplicationController before_action :teacher_allowed, only: [:update, :destroy, :settings, :search_teacher_candidate, :transfer_to_course_group, :delete_from_course, :search_users, :add_students_by_search, :get_historical_courses, :add_teacher_popup, :add_teacher] - before_action :admin_allowed, only: [:set_invite_code_halt, :set_public_or_private, :join_graduation_group, - :set_course_group, :change_course_admin, :change_course_teacher, - :delete_course_teacher, :teacher_application_review, :create_group_by_importing_file] + before_action :admin_allowed, only: [:set_invite_code_halt, :set_public_or_private, :change_course_admin, + :set_course_group, :delete_course_teacher, :teacher_application_review, + :create_group_by_importing_file] before_action :teacher_or_admin_allowed, only: [:graduation_group_list, :create_graduation_group, :join_graduation_group, - :export_member_scores_excel, :course_group_list] + :change_course_teacher, :export_member_scores_excel, :course_group_list] before_action :validate_course_name, only: [:create, :update] before_action :find_board, only: :board_list before_action :validate_page_size, only: :mine From fb279178ae8fe6c4ae27a71d688a0639f39e4279 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 17:06:26 +0800 Subject: [PATCH 0148/1015] fix bug --- app/controllers/zips_controller.rb | 5 +++-- app/services/exercise_user_pdf_service.rb | 5 +++++ app/services/export_exercises_service.rb | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 35373730c..3e3445e77 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -20,8 +20,9 @@ class ZipsController < ApplicationController exercises = ExportExercisesService.new(@exercise,@ex_users) file_name = filename_for_content_disposition(exercises.filename) - logger.info("##################_______________________file_name_____________________############{file_name}") send_file exercises.ex_zip, filename: file_name, type: 'application/zip' + logger.info("##################_______________________file_name___________1100101010010__________###########") + rescue Exception => e normal_status(-1, e.message) end @@ -40,7 +41,7 @@ class ZipsController < ApplicationController def get_exercise ActiveRecord::Base.transaction do begin - @exercise = Exercise.includes(:exercise_users).find_by(id:params[:exercise_id]) + @exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id]) group_id = params[:exercise_group_id] if @exercise.blank? normal_status(-1,"试卷不存在") diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 5f92aee9c..52f54163e 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -41,9 +41,14 @@ class ExerciseUserPdfService # aa = File.open(Rails.root.join("public/123.html"),"w+") # aa.syswrite(kit.source) #正式需删掉------- + logger.info("##################_______________________file_name___________5555555555__________###########") file = Tempfile.new(filename) + logger.info("##################_______________________file_name___________66666666__________###########") + kit.to_pdf(file.path) + logger.info("##################_______________________file_name___________7777777777__________###########") + file end diff --git a/app/services/export_exercises_service.rb b/app/services/export_exercises_service.rb index 12b5501f9..4b7b10b9b 100644 --- a/app/services/export_exercises_service.rb +++ b/app/services/export_exercises_service.rb @@ -14,15 +14,29 @@ class ExportExercisesService end def ex_zip + logger.info("##################_______________________file_name___________11111__________###########") + zip_file = Tempfile.new(filename) + logger.info("##################_______________________file_name___________2222222__________###########") + pdfs = [] Zip::File.open(zip_file.path, Zip::File::CREATE) do |zip| + logger.info("##################_______________________file_name___________3333333__________###########") + ex_users.each do |ex_user| export = ExerciseUserPdfService.new(exercise, ex_user) + logger.info("##################_______________________file_name___________444444__________###########") + pdf = export.ex_pdf + logger.info("##################_______________________file_name___________888888888__________###########") + pdfs << pdf + logger.info("##################_______________________file_name___________999999999__________###########") + begin zip.add(export.filename, pdf.path) + logger.info("##################_______________________file_name___________10000000000000__________###########") + rescue => ex Rails.logger.error(ex.message) zip.get_output_stream('FILE_NOTICE.txt'){|os| os.write("文件重复:#{export.filename}") } From 28ae66071901ab1b3ecdff6c971afd34f613d9c7 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 17:07:08 +0800 Subject: [PATCH 0149/1015] =?UTF-8?q?=E8=AE=A4=E8=AF=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 27 ++++++++++++----------- app/controllers/shixuns_controller.rb | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1915281bf..1fffc0cb7 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -176,19 +176,20 @@ class ApplicationController < ActionController::Base # 系统全局认证 # def check_auth - old_edu_host = edu_setting('old_edu_host') - ue = current_user.user_extension - - if current_user.lastname.blank? || ue.school_id.blank? || ue.identity.blank? || current_user.mail.blank? - info_url = old_edu_host + '/account/user_info' - render :json => { status: 402, url: info_url } - elsif current_user.certification != 1 - day_cer = UserDayCertification.where(user_id: current_user.id).last - unless (Time.now.to_i - day_cer.try(:created_at).to_i) < 86400 - account_url = old_edu_host + "/my/account" - render :json => { status: 402, url: account_url } - end - end + # old_edu_host = edu_setting('old_edu_host') + # ue = current_user.user_extension + # + # if current_user.lastname.blank? || ue.school_id.blank? || ue.identity.blank? || current_user.mail.blank? + # info_url = old_edu_host + '/account/user_info' + # render :json => { status: 402, url: info_url } + # elsif current_user.certification != 1 + # day_cer = UserDayCertification.where(user_id: current_user.id).last + # unless (Time.now.to_i - day_cer.try(:created_at).to_i) < 86400 + # account_url = old_edu_host + "/my/account" + # render :json => { status: 402, url: account_url } + # end + # end + true end # 身份资料的认证: diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 6dfa94252..5cc470d61 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -1,5 +1,5 @@ class ShixunsController < ApplicationController - # before_action :require_login, except: [:download_file, :index, :menus] + before_action :require_login, except: [:download_file, :index, :menus] before_action :check_auth, except: [:download_file, :index] before_action :find_shixun, except: [:index, :new, :create, :menus, :get_recommend_shixuns, :propaedeutics, From 05d0bb7c1af6d27fee5e7b99ca90c438880d234b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 17:09:21 +0800 Subject: [PATCH 0150/1015] fix bug --- app/controllers/zips_controller.rb | 2 +- app/services/exercise_user_pdf_service.rb | 6 +++--- app/services/export_exercises_service.rb | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 3e3445e77..b04ee3cb1 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -21,7 +21,7 @@ class ZipsController < ApplicationController file_name = filename_for_content_disposition(exercises.filename) send_file exercises.ex_zip, filename: file_name, type: 'application/zip' - logger.info("##################_______________________file_name___________1100101010010__________###########") + Rails.logger.info("##################_______________________file_name___________1100101010010__________###########") rescue Exception => e normal_status(-1, e.message) diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 52f54163e..1f2f84414 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -41,13 +41,13 @@ class ExerciseUserPdfService # aa = File.open(Rails.root.join("public/123.html"),"w+") # aa.syswrite(kit.source) #正式需删掉------- - logger.info("##################_______________________file_name___________5555555555__________###########") + Rails.logger.info("##################_______________________file_name___________5555555555__________###########") file = Tempfile.new(filename) - logger.info("##################_______________________file_name___________66666666__________###########") + Rails.logger.info("##################_______________________file_name___________66666666__________###########") kit.to_pdf(file.path) - logger.info("##################_______________________file_name___________7777777777__________###########") + Rails.logger.info("##################_______________________file_name___________7777777777__________###########") file end diff --git a/app/services/export_exercises_service.rb b/app/services/export_exercises_service.rb index 4b7b10b9b..c450f6247 100644 --- a/app/services/export_exercises_service.rb +++ b/app/services/export_exercises_service.rb @@ -14,28 +14,28 @@ class ExportExercisesService end def ex_zip - logger.info("##################_______________________file_name___________11111__________###########") + Rails.logger.info("##################_______________________file_name___________11111__________###########") zip_file = Tempfile.new(filename) - logger.info("##################_______________________file_name___________2222222__________###########") + Rails.logger.info("##################_______________________file_name___________2222222__________###########") pdfs = [] Zip::File.open(zip_file.path, Zip::File::CREATE) do |zip| - logger.info("##################_______________________file_name___________3333333__________###########") + Rails.logger.info("##################_______________________file_name___________3333333__________###########") ex_users.each do |ex_user| export = ExerciseUserPdfService.new(exercise, ex_user) - logger.info("##################_______________________file_name___________444444__________###########") + Rails.logger.info("##################_______________________file_name___________444444__________###########") pdf = export.ex_pdf - logger.info("##################_______________________file_name___________888888888__________###########") + Rails.logger.info("##################_______________________file_name___________888888888__________###########") pdfs << pdf - logger.info("##################_______________________file_name___________999999999__________###########") + Rails.logger.info("##################_______________________file_name___________999999999__________###########") begin zip.add(export.filename, pdf.path) - logger.info("##################_______________________file_name___________10000000000000__________###########") + Rails.logger.info("##################_______________________file_name___________10000000000000__________###########") rescue => ex Rails.logger.error(ex.message) From 92bd6ea4b5c31924e801806038b4c4737e0d9ccb Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 17:16:53 +0800 Subject: [PATCH 0151/1015] =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 0d5517c50..8e25efe70 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -260,7 +260,7 @@ class User < ApplicationRecord # 实训管理员:实训合作者、admin def manager_of_shixun?(shixun) - shixun.shixun_members.exists?(role: [1,2], user_id: id) || admin? + shixun.shixun_members.exists?(role: [1,2], user_id: id) || admin? || business? end # 实训管理员 From 262c3bf78a0529dd0722ce89232ae9b7f975a763 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 17:17:11 +0800 Subject: [PATCH 0152/1015] fixbug --- app/controllers/zips_controller.rb | 1 - config/initializers/pdfkit.rb | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index b04ee3cb1..a8750fc3d 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -21,7 +21,6 @@ class ZipsController < ApplicationController file_name = filename_for_content_disposition(exercises.filename) send_file exercises.ex_zip, filename: file_name, type: 'application/zip' - Rails.logger.info("##################_______________________file_name___________1100101010010__________###########") rescue Exception => e normal_status(-1, e.message) diff --git a/config/initializers/pdfkit.rb b/config/initializers/pdfkit.rb index 0cd80c9c7..8bd9e5e38 100644 --- a/config/initializers/pdfkit.rb +++ b/config/initializers/pdfkit.rb @@ -1,6 +1,6 @@ PDFKit.configure do |config| - config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || 'wkhtmltopdf' - # config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || '/usr/bin/wkhtmltopdf' + # config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || 'wkhtmltopdf' + config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || '/usr/bin/wkhtmltopdf' config.default_options = { encoding: "UTF-8", page_size: 'A4', From 7055401525b818a1b457eea15a960e6eedfde93e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 17:20:46 +0800 Subject: [PATCH 0153/1015] fix but --- app/services/exercise_user_pdf_service.rb | 6 - app/services/export_exercises_service.rb | 14 - .../exercise_export/exercise_user.html.erb | 354 +----------------- 3 files changed, 1 insertion(+), 373 deletions(-) diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 1f2f84414..d74e66d31 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -41,14 +41,8 @@ class ExerciseUserPdfService # aa = File.open(Rails.root.join("public/123.html"),"w+") # aa.syswrite(kit.source) #正式需删掉------- - Rails.logger.info("##################_______________________file_name___________5555555555__________###########") - file = Tempfile.new(filename) - Rails.logger.info("##################_______________________file_name___________66666666__________###########") - kit.to_pdf(file.path) - Rails.logger.info("##################_______________________file_name___________7777777777__________###########") - file end diff --git a/app/services/export_exercises_service.rb b/app/services/export_exercises_service.rb index c450f6247..12b5501f9 100644 --- a/app/services/export_exercises_service.rb +++ b/app/services/export_exercises_service.rb @@ -14,29 +14,15 @@ class ExportExercisesService end def ex_zip - Rails.logger.info("##################_______________________file_name___________11111__________###########") - zip_file = Tempfile.new(filename) - Rails.logger.info("##################_______________________file_name___________2222222__________###########") - pdfs = [] Zip::File.open(zip_file.path, Zip::File::CREATE) do |zip| - Rails.logger.info("##################_______________________file_name___________3333333__________###########") - ex_users.each do |ex_user| export = ExerciseUserPdfService.new(exercise, ex_user) - Rails.logger.info("##################_______________________file_name___________444444__________###########") - pdf = export.ex_pdf - Rails.logger.info("##################_______________________file_name___________888888888__________###########") - pdfs << pdf - Rails.logger.info("##################_______________________file_name___________999999999__________###########") - begin zip.add(export.filename, pdf.path) - Rails.logger.info("##################_______________________file_name___________10000000000000__________###########") - rescue => ex Rails.logger.error(ex.message) zip.get_output_stream('FILE_NOTICE.txt'){|os| os.write("文件重复:#{export.filename}") } diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 088ff1fd4..d769ca0f0 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -1,353 +1 @@ - - - - - - - -
-
-
-
-

<%= @exercise.try(:exercise_name) %>

-
-
-

- <%= @exercise.try(:exercise_description).nil? ? "" : @exercise.try(:exercise_description)&.html_safe %> -

-
-
-
-
-

- <% if @exercise_single_ques_count > 0 %> - 单选题<%= @exercise_single_ques_count %>题, - 共<%= @exercise_single_ques_scores %> - <% end %> - <% if @exercise_double_ques_count > 0 %> - 多选题<%= @exercise_double_ques_count %>题, - 共<%= @exercise_double_ques_scores %> - <% end %> - <% if @exercise_ques_judge_count > 0 %> - 判断题<%= @exercise_ques_judge_count %>题, - 共<%= @exercise_ques_judge_scores %> - <% end %> - <% if @exercise_ques_null_count > 0 %> - 填空题<%= @exercise_ques_null_count %>题, - 共<%= @exercise_ques_null_scores %> - <% end %> - <% if @exercise_ques_main_count > 0 %> - 主观题<%= @exercise_ques_main_count %>题, - 共<%= @exercise_ques_main_scores %> - <% end %> - <% if @exercise_ques_shixun_count > 0 %> - 实训题<%= @exercise_ques_shixun_count %>题, - 共<%= @exercise_ques_shixun_scores %> - <% end %> - - <% if @exercise_ques_count > 0 %> - - 共<%= @exercise_ques_scores %>分 - - - 合计<%= @exercise_ques_count %>题 - - <% end %> -

-
-
-
- <% if @ex_obj_array.size > 0 %> -
-

- 客观题 - 正确 - 错误 - 部分得分 - 总分:<%= @exercise_user.score %>分 -

-
-
- <% @ex_obj_array.each do |s| %> - <% if s[:stand_status] == 1 %> -
- <%= s[:q_position] %> -
- <% elsif s[:stand_status] == 0 %> -
- <%= s[:q_position] %> -
- <% else %> -
- <%= s[:q_position] %> -
- <% end %> - <% end %> -
- <% end %> - <% if @ex_sub_array.size > 0 %> -
-

- 主观题 - 已评 - 未评 - 开始答题时间:<%= @exercise_user.start_at.present? ? @exercise_user.start_at.strftime("%Y-%m-%d %H:%M") : "--" %> -

-
-
- <% @ex_sub_array.each do |s| %> - <% if s[:stand_status] == 0 %> -
- <%= s[:q_position] %> -
- <% else %> -
- <%= s[:q_position] %> -
- <% end %> - <% end %> -
- <% end %> -
-
- <% @exercise_questions.each do |q| %> - <% q_type = q.question_type %> - <% user_answer = (q_type == 5 ? q.exercise_shixun_answers.where(user_id: @ex_user_user.id) : q.exercise_answers.where(user_id: @ex_user_user.id)) %> - <% this_ques_status = @ex_obj_array.detect{|f| f[:q_id] == q.id} %> - <% main_ques_status = @ex_sub_array.detect{|f| f[:q_id] == q.id} %> - <% ques_comment = q.exercise_answer_comments.where("exercise_answer_id",user_answer.first&.id) %> -
-
-
-
- <%= q.question_number %>、  - - <%= q.question_type_name %> - - (<%= q&.question_score %>分) - <% if q_type == 5 %> - - <% if this_ques_status.present? && this_ques_status[:stand_status] == 1 %> - - <%= this_ques_status[:user_score] %>分 - <% elsif this_ques_status.present? && this_ques_status[:stand_status] == 2 %> - - <%= this_ques_status[:user_score] %>分 - <% else %> - - 0.0分 - <% end %> - - <% elsif q_type == 4 %> - - <% if main_ques_status.present? && main_ques_status[:stand_status] == 1 %> - - <%= main_ques_status[:user_score] %>分 - <% elsif main_ques_status.present? && main_ques_status[:stand_status] == 2 %> - - <%= main_ques_status[:user_score] %>分 - <% else %> - 未批 - <% end %> - - <% else %> - - <% if this_ques_status.present? && this_ques_status[:stand_status] == 1 %> - - <%= this_ques_status[:user_score] %>分 - <% elsif this_ques_status.present? && this_ques_status[:stand_status] == 2 %> - - <%= this_ques_status[:user_score] %>分 - <% else %> - - 0.0分 - <% end %> - - <% end %> -
-
- <% if q_type == 5 %> - <%= q.shixun_name&.html_safe %> -
- <%= q.question_title&.html_safe %> -
- <% elsif q_type == 4 %> - <%= q.question_title&.html_safe %> - <% else %> - <%= q.question_title&.html_safe %> - <% end %> -
-
-
- <% if q_type == 0 %> - <% q.exercise_choices.each_with_index do |s,index| %> - <% check_answer = (user_answer.present? && (s.id == user_answer.first.exercise_choice_id)) ? "choose-answer" : '' %> -

- - <%= convert_to_char((index+1).to_s)%><%= s.choice_text%> -

- <% end %> - <% elsif q_type == 1 %> - <% q.exercise_choices.each_with_index do |s,index| %> - <% check_answer = (user_answer.present? && (user_answer.pluck(:exercise_choice_id).include?(s.id))) ? true : false %> -

- <% if check_answer %> - - <% else %> - - <% end %> - <%= convert_to_char((index+1).to_s)%><%= s.choice_text%> -

- <% end %> - <% elsif q_type == 2 %> -

- <% q.exercise_choices.each do |s| %> - <% if user_answer.present? && (s.id == user_answer.first.exercise_choice_id) %> - <% check_answer = 'choose-answer' %> - <% else %> - <% check_answer = '' %> - <% end %> - - - <%= s.choice_text %> - - <% end %> -

- <% elsif q_type == 3 %> - <% st_counts = q.exercise_standard_answers.pluck(:exercise_choice_id).uniq %> - <% st_counts.each_with_index do |s,index| %> - <% if user_answer.present? && user_answer.where(exercise_choice_id:s).present? %> - <% check_answer = user_answer.where(exercise_choice_id:s).first.answer_text %> - <% else %> - <% check_answer = "--" %> - <% end %> -

- 答案(填空<%= index+1 %>): - <%= check_answer&.html_safe %> -

- <% end %> - <% elsif q_type == 4 %> - <% check_answer = (user_answer.present? ? user_answer.first.answer_text : '--') %> -

- <%= check_answer&.html_safe %> -

- <% else %> -
-

- 阶段成绩 -

- - - - - - - - - - - - <% if @games.size > 0 %> - <% @games.each_with_index do |game, index| %> - <% user_score = q.exercise_shixun_answers.where(exercise_shixun_challenge_id:game.challenge.id,user_id: @ex_user_user.id) %> - <% game_score = q.exercise_shixun_challenges.where(challenge_id:game.challenge.id) %> - - - - - - - - - - <% end %> - <% else %> - <% q.exercise_shixun_challenges.each_with_index do |game, index| %> - <% game_score = q.exercise_shixun_challenges.where(challenge_id:game.challenge.id) %> - - - - - - - - - - <% end %> - <% end %> - -
关卡任务名称评测次数完成时间耗时经验值得分/满分
<%= index + 1 %> - <%= game.challenge.subject %> - <%= game.evaluate_count %><%= game.end_time.present? ? game.end_time.strftime("%Y-%m-%d %H:%M") : "--" %><%= ApplicationController.helpers.time_consuming game %><%= game.final_score %> / <%= game.challenge.all_score %><%= user_score.present? ? user_score.first.score : 0.0 %> / <%= game_score.present? ? game_score.first.question_score : 0.0 %>
<%= index + 1 %> - <%= game.challenge.subject %> - 0----0.0 / <%= game.challenge.all_score %>0.0 / <%= game_score.present? ? game_score.first.question_score : 0.0 %>
-
-
-

- 实训详情 -

- <% @games.each_with_index do |game, index| %> -
-

- 第<%= index+1 %>关<%= game.challenge.subject %> -

-
- <% if game.outputs.present? %> - - - - - - - <% outputs = game.outputs.group("query_index") %> - <% outputs.reverse.try(:each) do |output| %> - - - - - <% end %> - -
评测次数评测信息
<%= "第#{output.query_index}次" %><%= output_detail(game, output) %>
- <% end %> - <% if game.try(:lastest_code).present? && game.challenge.st == 0 %> - <% con_rows = content_line(game.lastest_code) %> -
-

- - 最近通过的代码 - <%= game.challenge.path %> - -

-
- -
-
- <% end %> -
-
- <% end %> -
- <% end %> -
-
-
- <% if ques_comment.present? && ques_comment.first.comment.present? %> - <% ques_user = ques_comment.first.user %> -
-
-
- -
-
-

<%= ques_user.real_name %><%= ques_comment.first.updated_at.strftime('%Y-%m-%d %H:%M') %>

-

<%= ques_comment.first.comment %>

-
-
-
- <% end %> - <% end %> -
-
-
- - +11111111111111 \ No newline at end of file From df76135f8d44c67682bb732193cacb06319f3167 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 17:27:59 +0800 Subject: [PATCH 0154/1015] fix bug --- app/services/exercise_user_pdf_service.rb | 1 + .../exercise_export/exercise_user.html.erb | 354 +++++++++++++++++- 2 files changed, 354 insertions(+), 1 deletion(-) diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index d74e66d31..6dbb11c83 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -42,6 +42,7 @@ class ExerciseUserPdfService # aa.syswrite(kit.source) #正式需删掉------- file = Tempfile.new(filename) + logger.info("###########__________________file.path_______________########################{file.path}") kit.to_pdf(file.path) file end diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index d769ca0f0..70c023d26 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -1 +1,353 @@ -11111111111111 \ No newline at end of file + + + + + + + +
+
+
+
+

<%= @exercise.try(:exercise_name) %>

+
+
+

+ <%= @exercise.try(:exercise_description).nil? ? "" : @exercise.try(:exercise_description)&.html_safe %> +

+
+
+
+
+

+ <% if @exercise_single_ques_count > 0 %> + 单选题<%= @exercise_single_ques_count %>题, + 共<%= @exercise_single_ques_scores %> + <% end %> + <% if @exercise_double_ques_count > 0 %> + 多选题<%= @exercise_double_ques_count %>题, + 共<%= @exercise_double_ques_scores %> + <% end %> + <% if @exercise_ques_judge_count > 0 %> + 判断题<%= @exercise_ques_judge_count %>题, + 共<%= @exercise_ques_judge_scores %> + <% end %> + <% if @exercise_ques_null_count > 0 %> + 填空题<%= @exercise_ques_null_count %>题, + 共<%= @exercise_ques_null_scores %> + <% end %> + <% if @exercise_ques_main_count > 0 %> + 主观题<%= @exercise_ques_main_count %>题, + 共<%= @exercise_ques_main_scores %> + <% end %> + <% if @exercise_ques_shixun_count > 0 %> + 实训题<%= @exercise_ques_shixun_count %>题, + 共<%= @exercise_ques_shixun_scores %> + <% end %> + + <% if @exercise_ques_count > 0 %> + + 共<%= @exercise_ques_scores %>分 + + + 合计<%= @exercise_ques_count %>题 + + <% end %> +

+
+
+
+ <% if @ex_obj_array.size > 0 %> +
+

+ 客观题 + 正确 + 错误 + 部分得分 + 总分:<%= @exercise_user&.score %>分 +

+
+
+ <% @ex_obj_array.each do |s| %> + <% if s[:stand_status] == 1 %> +
+ <%= s[:q_position] %> +
+ <% elsif s[:stand_status] == 0 %> +
+ <%= s[:q_position] %> +
+ <% else %> +
+ <%= s[:q_position] %> +
+ <% end %> + <% end %> +
+ <% end %> + <% if @ex_sub_array.size > 0 %> +
+

+ 主观题 + 已评 + 未评 + 开始答题时间:<%= @exercise_user.start_at.present? ? @exercise_user.start_at.strftime("%Y-%m-%d %H:%M") : "--" %> +

+
+
+ <% @ex_sub_array.each do |s| %> + <% if s[:stand_status] == 0 %> +
+ <%= s[:q_position] %> +
+ <% else %> +
+ <%= s[:q_position] %> +
+ <% end %> + <% end %> +
+ <% end %> +
+
+ <% @exercise_questions.each do |q| %> + <% q_type = q.question_type %> + <% user_answer = (q_type == 5 ? q.exercise_shixun_answers.where(user_id: @ex_user_user.id) : q.exercise_answers.where(user_id: @ex_user_user.id)) %> + <% this_ques_status = @ex_obj_array.detect{|f| f[:q_id] == q.id} %> + <% main_ques_status = @ex_sub_array.detect{|f| f[:q_id] == q.id} %> + <% ques_comment = q.exercise_answer_comments.where("exercise_answer_id",user_answer.first&.id) %> +
+
+
+
+ <%= q.question_number %>、  + + <%= q.question_type_name %> + + (<%= q&.question_score %>分) + <% if q_type == 5 %> + + <% if this_ques_status.present? && this_ques_status[:stand_status] == 1 %> + + <%= this_ques_status[:user_score] %>分 + <% elsif this_ques_status.present? && this_ques_status[:stand_status] == 2 %> + + <%= this_ques_status[:user_score] %>分 + <% else %> + + 0.0分 + <% end %> + + <% elsif q_type == 4 %> + + <% if main_ques_status.present? && main_ques_status[:stand_status] == 1 %> + + <%= main_ques_status[:user_score] %>分 + <% elsif main_ques_status.present? && main_ques_status[:stand_status] == 2 %> + + <%= main_ques_status[:user_score] %>分 + <% else %> + 未批 + <% end %> + + <% else %> + + <% if this_ques_status.present? && this_ques_status[:stand_status] == 1 %> + + <%= this_ques_status[:user_score] %>分 + <% elsif this_ques_status.present? && this_ques_status[:stand_status] == 2 %> + + <%= this_ques_status[:user_score] %>分 + <% else %> + + 0.0分 + <% end %> + + <% end %> +
+
+ <% if q_type == 5 %> + <%= q.shixun_name&.html_safe %> +
+ <%= q.question_title&.html_safe %> +
+ <% elsif q_type == 4 %> + <%= q.question_title&.html_safe %> + <% else %> + <%= q.question_title&.html_safe %> + <% end %> +
+
+
+ <% if q_type == 0 %> + <% q.exercise_choices.each_with_index do |s,index| %> + <% check_answer = (user_answer.present? && (s.id == user_answer.first.exercise_choice_id)) ? "choose-answer" : '' %> +

+ + <%= convert_to_char((index+1).to_s)%><%= s.choice_text%> +

+ <% end %> + <% elsif q_type == 1 %> + <% q.exercise_choices.each_with_index do |s,index| %> + <% check_answer = (user_answer.present? && (user_answer.pluck(:exercise_choice_id).include?(s.id))) ? true : false %> +

+ <% if check_answer %> + + <% else %> + + <% end %> + <%= convert_to_char((index+1).to_s)%><%= s.choice_text%> +

+ <% end %> + <% elsif q_type == 2 %> +

+ <% q.exercise_choices.each do |s| %> + <% if user_answer.present? && (s.id == user_answer.first.exercise_choice_id) %> + <% check_answer = 'choose-answer' %> + <% else %> + <% check_answer = '' %> + <% end %> + + + <%= s.choice_text %> + + <% end %> +

+ <% elsif q_type == 3 %> + <% st_counts = q.exercise_standard_answers.pluck(:exercise_choice_id).uniq %> + <% st_counts.each_with_index do |s,index| %> + <% if user_answer.present? && user_answer.where(exercise_choice_id:s).present? %> + <% check_answer = user_answer.where(exercise_choice_id:s).first.answer_text %> + <% else %> + <% check_answer = "--" %> + <% end %> +

+ 答案(填空<%= index+1 %>): + <%= check_answer&.html_safe %> +

+ <% end %> + <% elsif q_type == 4 %> + <% check_answer = (user_answer.present? ? user_answer.first.answer_text : '--') %> +

+ <%= check_answer&.html_safe %> +

+ <% else %> +
+

+ 阶段成绩 +

+ + + + + + + + + + + + <% if @games.size > 0 %> + <% @games.each_with_index do |game, index| %> + <% user_score = q.exercise_shixun_answers.where(exercise_shixun_challenge_id:game.challenge.id,user_id: @ex_user_user.id) %> + <% game_score = q.exercise_shixun_challenges.where(challenge_id:game.challenge.id) %> + + + + + + + + + + <% end %> + <% else %> + <% q.exercise_shixun_challenges.each_with_index do |game, index| %> + <% game_score = q.exercise_shixun_challenges.where(challenge_id:game.challenge.id) %> + + + + + + + + + + <% end %> + <% end %> + +
关卡任务名称评测次数完成时间耗时经验值得分/满分
<%= index + 1 %> + <%= game.challenge.subject %> + <%= game.evaluate_count %><%= game.end_time.present? ? game.end_time.strftime("%Y-%m-%d %H:%M") : "--" %><%= ApplicationController.helpers.time_consuming game %><%= game.final_score %> / <%= game.challenge.all_score %><%= user_score.present? ? user_score.first.score : 0.0 %> / <%= game_score.present? ? game_score.first.question_score : 0.0 %>
<%= index + 1 %> + <%= game.challenge.subject %> + 0----0.0 / <%= game.challenge.all_score %>0.0 / <%= game_score.present? ? game_score.first.question_score : 0.0 %>
+
+
+

+ 实训详情 +

+ <% @games.each_with_index do |game, index| %> +
+

+ 第<%= index+1 %>关<%= game.challenge.subject %> +

+
+ <% if game.outputs.present? %> + + + + + + + <% outputs = game.outputs.group("query_index") %> + <% outputs.reverse.try(:each) do |output| %> + + + + + <% end %> + +
评测次数评测信息
<%= "第#{output.query_index}次" %><%= output_detail(game, output) %>
+ <% end %> + <% if game.try(:lastest_code).present? && game.challenge.st == 0 %> + <% con_rows = content_line(game.lastest_code) %> +
+

+ + 最近通过的代码 + <%= game.challenge.path %> + +

+
+ +
+
+ <% end %> +
+
+ <% end %> +
+ <% end %> +
+
+
+ <% if ques_comment.present? && ques_comment.first.comment.present? %> + <% ques_user = ques_comment.first.user %> +
+
+
+ +
+
+

<%= ques_user.real_name %><%= ques_comment.first.updated_at.strftime('%Y-%m-%d %H:%M') %>

+

<%= ques_comment.first.comment %>

+
+
+
+ <% end %> + <% end %> +
+
+
+ + From fc92232cdea1d4a8e6415355c525d6c14d7378b8 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 22 Jun 2019 17:50:11 +0800 Subject: [PATCH 0155/1015] =?UTF-8?q?vnc=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 16 ++++++++++++++++ app/views/games/show.json.jbuilder | 3 +++ 2 files changed, 19 insertions(+) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 4aa0b13b8..79167150e 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -62,6 +62,22 @@ class GamesController < ApplicationController praise_count: praise_count, user_praise: user_praise, time_limit: time_limit, tomcat_url: edu_setting('cloud_tomcat_php'), is_teacher: is_teacher, myshixun_manager: myshixun_manager} + if @shixun.vnc + begin + shixun_tomcat = edu_setting('shixun_tomcat') + service_host = edu_setting('vnc_url') + uri = "#{shixun_tomcat}/bridge/vnc/getvnc" + params = {tpiID: @myshixun.id, :containers => "#{Base64.urlsafe_encode64(container_limit(@shixun.mirror_repositories))}"} + res = uri_post uri, params + if res && res['code'].to_i != 0 + raise("实训云平台繁忙(繁忙等级:99)") + end + @url = "http://#{service_host}:#{res['port']}}/vnc_lite.html?password=headless" + Rails.logger.info("66666666sssssss#{url}") + rescue Exception => e + Rails.logger.error(e.message) + end + end # 区分选择题和编程题,st:0编程题; if @st == 0 diff --git a/app/views/games/show.json.jbuilder b/app/views/games/show.json.jbuilder index acbc8c2ef..607a57a15 100644 --- a/app/views/games/show.json.jbuilder +++ b/app/views/games/show.json.jbuilder @@ -1,6 +1,9 @@ json.(@base_date, :st, :discusses_count, :game_count, :record_onsume_time, :prev_game, :next_game, :praise_count, :user_praise, :time_limit, :tomcat_url, :is_teacher, :myshixun_manager, :game, :challenge, :shixun, :myshixun) +if @shixun.vnc + json.vnc_url @vnc_url +end json.user do json.partial! 'users/user', user: @user json.identity @identity From fe133afc0993918973a5b0a822616d297027ba65 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 18:00:04 +0800 Subject: [PATCH 0156/1015] fix but --- app/services/exercise_user_pdf_service.rb | 1 - .../exercise_export/exercise_export.css | 6 +- public/123.html | 366 ------------------ 3 files changed, 4 insertions(+), 369 deletions(-) diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 6dbb11c83..d74e66d31 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -42,7 +42,6 @@ class ExerciseUserPdfService # aa.syswrite(kit.source) #正式需删掉------- file = Tempfile.new(filename) - logger.info("###########__________________file.path_______________########################{file.path}") kit.to_pdf(file.path) file end diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 884a49af0..302097208 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -1,5 +1,7 @@ body{ - font-size:14px;} + font-size:14px; + font-family: "微软雅黑","宋体"; +} p{ margin:0; } @@ -229,7 +231,7 @@ p{ position: absolute; display: inline-block; bottom: 9px; - left: 3px; + left: 1px; } .circle-right:after{ color:#fff; diff --git a/public/123.html b/public/123.html index 8986880e5..e69de29bb 100644 --- a/public/123.html +++ b/public/123.html @@ -1,366 +0,0 @@ - - - - - - - - - -
-
-

- - 单选题5题,共10分 - - - 单选题5题,共10分 - - - 单选题5题,共10分 - - - 单选题5题,共10分 - - - 共10分 - - - 合计20题 - - - -

- - - - - - - -
-
- - - \ No newline at end of file From d45e8da5b9503553a40d8f5a15154346f0a7c40e Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 22 Jun 2019 18:08:02 +0800 Subject: [PATCH 0157/1015] fix --- app/decorators/user_decorator.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/decorators/user_decorator.rb b/app/decorators/user_decorator.rb index a0f9f7fdd..463d9a6e3 100644 --- a/app/decorators/user_decorator.rb +++ b/app/decorators/user_decorator.rb @@ -14,12 +14,14 @@ module UserDecorator # 关注数 def follow_count - User.watched_by(id).count + Watcher.where(user_id: id, watchable_type: %w(Principal User)).count + # User.watched_by(id).count end # 粉丝数 def fan_count - watchers.count + Watcher.where(watchable_type: %w(Principal User), watchable_id: id).count + # watchers.count end # 是否绑定邮箱 From 7b92517d3df36485e2fdfcbecfc679356e76a8ac Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 18:09:04 +0800 Subject: [PATCH 0158/1015] =?UTF-8?q?=E8=AF=84=E6=B5=8B=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 042945b6e..91cff3c19 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -1,7 +1,7 @@ class MyshixunsController < ApplicationController before_action :require_login, :except => [:training_task_status, :code_runinng_message] - before_action :find_myshixun, :except => [:training_task_status] - before_action :find_repo_name, :except => [:training_task_status] + before_action :find_myshixun, :except => [:training_task_status, :code_runinng_message] + before_action :find_repo_name, :except => [:training_task_status, :code_runinng_message] skip_before_action :verify_authenticity_token, :only => [:html_content] ## TPI关卡列表 From 73de92d405a5c3055a0c47b979e8848f5a752699 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 18:13:49 +0800 Subject: [PATCH 0159/1015] production ignore --- .gitignore | 1 + Gemfile | 4 ++-- .../environments/{development.rb => development.rb.example} | 0 3 files changed, 3 insertions(+), 2 deletions(-) rename config/environments/{development.rb => development.rb.example} (100%) diff --git a/.gitignore b/.gitignore index 309e960d7..4f52644ff 100644 --- a/.gitignore +++ b/.gitignore @@ -47,6 +47,7 @@ public/upload.html /config/configuration.yml +/config/environments/production.rb /config/initializers/gitlab_config.rb /db/schema.rb .vscode/ diff --git a/Gemfile b/Gemfile index dfc9d41fd..f7c7e487a 100644 --- a/Gemfile +++ b/Gemfile @@ -45,12 +45,12 @@ gem 'rqrcode_png' gem 'acts-as-taggable-on', '~> 6.0' -group :development, :test do +group :'development.rb.example', :test do gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] gem 'rspec-rails', '~> 3.8' end -group :development do +group :'development.rb.example' do gem 'awesome_print' gem 'web-console', '>= 3.3.0' gem 'listen', '>= 3.0.5', '< 3.2' diff --git a/config/environments/development.rb b/config/environments/development.rb.example similarity index 100% rename from config/environments/development.rb rename to config/environments/development.rb.example From 8ac11cace5a7f2a157b35e1249f7c781e7065d3e Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 18:15:36 +0800 Subject: [PATCH 0160/1015] .. --- config/environments/development.rb | 76 ++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 config/environments/development.rb diff --git a/config/environments/development.rb b/config/environments/development.rb new file mode 100644 index 000000000..0b31f5828 --- /dev/null +++ b/config/environments/development.rb @@ -0,0 +1,76 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + # Run rails dev:cache to toggle caching. + + config.cache_store = :file_store, "#{Rails.root }/files/cache_store/" + + # if Rails.root.join('tmp', 'caching-dev.txt').exist? + # config.action_controller.perform_caching = true + # + # config.cache_store = :memory_store + # config.public_file_server.headers = { + # 'Cache-Control' => "public, max-age=#{2.days.to_i}" + # } + # else + # config.action_controller.perform_caching = false + # + # config.cache_store = :null_store + # end + + # Store uploaded files on the local file system (see config/storage.yml for options) + config.active_storage.service = :local + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + config.action_mailer.perform_caching = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true + + # Suppress logger output for asset requests. + config.assets.quiet = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + config.file_watcher = ActiveSupport::EventedFileUpdateChecker + + config.action_controller.perform_caching = true + + config.action_mailer.delivery_method = :smtp + config.action_mailer.smtp_settings = { + address: 'smtp.exmail.qq.com', + port: 25, + domain: 'smtp.qq.com', + user_name: 'educoder@trustie.org', + password: 'mAZc9EWbe2Kawaqo2', + authentication: 'login', + enable_starttls_auto: true } +end From 5ad7840fb4f6ee1b47cb23eede31b488168c96b7 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 18:17:24 +0800 Subject: [PATCH 0161/1015] development ignore --- config/environments/{production.rb => production.rb.example} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename config/environments/{production.rb => production.rb.example} (100%) diff --git a/config/environments/production.rb b/config/environments/production.rb.example similarity index 100% rename from config/environments/production.rb rename to config/environments/production.rb.example From 254b35935674e46b5ead21914e3cbc0009cb7a53 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 18:25:49 +0800 Subject: [PATCH 0162/1015] fix bug --- app/controllers/exercise_answers_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/exercise_answers_controller.rb b/app/controllers/exercise_answers_controller.rb index fec26d674..df6550c0d 100644 --- a/app/controllers/exercise_answers_controller.rb +++ b/app/controllers/exercise_answers_controller.rb @@ -94,7 +94,7 @@ class ExerciseAnswersController < ApplicationController def get_exercise_question @exercise_question = ExerciseQuestion.find_by_id(params[:exercise_question_id]) - @exercise = @exercise_question.exercise.includes(:exercise_users) + @exercise = @exercise_question.exercise @course = @exercise.course @exercise_user = @exercise.exercise_users.find_by(user_id: current_user.id) #当前用户 @exercise_user_status = @exercise.get_exercise_status(current_user.id) From b4557b17ac1280c744a4dcbd03db09c48a9577a4 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 22 Jun 2019 18:30:25 +0800 Subject: [PATCH 0163/1015] fix but --- app/templates/exercise_export/exercise_export.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 302097208..f5022527e 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -241,7 +241,7 @@ p{ position: absolute; display: inline-block; bottom: 9px; - left: 0; + left: 1px; } table{ width:100%; From 26d0e0a917878ce7f4400d71d6a5746035b36591 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 19:48:06 +0800 Subject: [PATCH 0164/1015] =?UTF-8?q?reset=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 5cc470d61..b11444716 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -492,7 +492,7 @@ class ShixunsController < ApplicationController if current_myshixun # 如果TPM和TPI的管卡数不相等或者关卡顺序错了,说明实训被极大的改动,需要重置 - if current_myshixun.games.count != @shixun.challenges_count || current_myshixun.games.map(&:challenge_id).sort != Challenge.where(shixun_id: @shixun.id).pluck(:id).sort + if current_myshixun.games.count != @shixun.challenges_count # 这里页面弹框要收到 当前用户myshixun的identifier. tip_show_exception("/myshixuns/#{current_myshixun.try(:identifier)}/reset_my_game") end From 8fc26a69f36f856cc0ee4511228de40b50de75bf Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 22 Jun 2019 19:50:04 +0800 Subject: [PATCH 0165/1015] log --- app/controllers/shixuns_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index b11444716..8359b14f9 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -492,7 +492,8 @@ class ShixunsController < ApplicationController if current_myshixun # 如果TPM和TPI的管卡数不相等或者关卡顺序错了,说明实训被极大的改动,需要重置 - if current_myshixun.games.count != @shixun.challenges_count + uid_logger_error("7777777777777777#{current_myshixun.games.count}, #{@shixun.challenges_count}") + if current_myshixun.games.count != @shixun.challenges_count || current_myshixun.games.map(&:challenge_id).sort != Challenge.where(shixun_id: @shixun.id).pluck(:id).sort # 这里页面弹框要收到 当前用户myshixun的identifier. tip_show_exception("/myshixuns/#{current_myshixun.try(:identifier)}/reset_my_game") end From eab4740743ba2df098a00a8f840458382137814c Mon Sep 17 00:00:00 2001 From: p31729568 Date: Mon, 24 Jun 2019 09:38:38 +0800 Subject: [PATCH 0166/1015] trial apply api require logged --- app/controllers/concerns/render_helper.rb | 4 ++++ app/controllers/trial_applies_controller.rb | 7 +++++++ config/locales/en.yml | 3 ++- config/locales/zh-CN.yml | 3 ++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/controllers/concerns/render_helper.rb b/app/controllers/concerns/render_helper.rb index 94ac351cd..5ea73e666 100644 --- a/app/controllers/concerns/render_helper.rb +++ b/app/controllers/concerns/render_helper.rb @@ -16,4 +16,8 @@ module RenderHelper render json: { status: 403, message: message } # render status: 403, json: { errors: errors } end + + def render_unauthorized(message = I18n.t('error.unauthorized')) + render json: { status: 401, message: message } + end end \ No newline at end of file diff --git a/app/controllers/trial_applies_controller.rb b/app/controllers/trial_applies_controller.rb index f8454e557..acfde75da 100644 --- a/app/controllers/trial_applies_controller.rb +++ b/app/controllers/trial_applies_controller.rb @@ -1,4 +1,5 @@ class TrialAppliesController < ApplicationController + before_action :require_user_login def create Users::ApplyTrailService.call(current_user, create_params) @@ -12,4 +13,10 @@ class TrialAppliesController < ApplicationController def create_params params.permit(:phone, :code, :reason).merge(remote_ip: request.remote_ip) end + + def require_user_login + return if User.current.logged? + + render_unauthorized + end end diff --git a/config/locales/en.yml b/config/locales/en.yml index bb1bb3934..257c83750 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1,4 +1,5 @@ en: error: record_not_found: Record not found - forbidden: Forbidden \ No newline at end of file + forbidden: Forbidden + unauthorized: Unauthorized \ No newline at end of file diff --git a/config/locales/zh-CN.yml b/config/locales/zh-CN.yml index 99d5ac843..71cdb02e9 100644 --- a/config/locales/zh-CN.yml +++ b/config/locales/zh-CN.yml @@ -1,4 +1,5 @@ 'zh-CN': error: record_not_found: 您访问的页面不存在或已被删除 - forbidden: 您没有权限进行该操作 \ No newline at end of file + forbidden: 您没有权限进行该操作 + unauthorized: 未登录 \ No newline at end of file From 494d425088256b6314252604f14dc06633807be5 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 09:58:53 +0800 Subject: [PATCH 0167/1015] fix bug --- app/helpers/exercises_helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 67eb373ef..478b38204 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -326,9 +326,9 @@ module ExercisesHelper if exercise_status == 2 && exercise_end_time.present? ex_left_time = how_much_time(exercise_end_time) - elsif exercise_status == 3 && course.end_date.present? - ex_left_time = how_much_time(course.end_date.to_time) - else + # elsif exercise_status == 3 && course.end_date.present? + # ex_left_time = how_much_time(course.end_date.to_time) + else #已截止后不显示时间 ex_left_time = nil end From 7833d10caee5845da43cb3e7c859aeec10294d0d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 24 Jun 2019 10:01:15 +0800 Subject: [PATCH 0168/1015] =?UTF-8?q?=E6=AF=95=E4=B8=9A=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E7=9A=84=E5=8B=BE=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 2 +- app/models/course.rb | 2 +- app/models/course_module.rb | 1 + app/views/courses/index.json.jbuilder | 2 +- app/views/users/courses/shared/_course.json.jbuilder | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index b76673945..01ce1f6e8 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -913,7 +913,7 @@ class CoursesController < ApplicationController def left_banner @user = current_user @is_teacher = @user.teacher_of_course?(@course) - @course_modules = @course.course_modules.where.not(module_type: "activity").where(hidden: 0) + @course_modules = @course.course_modules.where(hidden: 0) @hidden_modules = @course.course_modules.where(hidden: 1) @second_category_type = ["shixun_homework", "graduation", "attachment", "board", "course_group"] end diff --git a/app/models/course.rb b/app/models/course.rb index a2f5add51..7729a2650 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -7,7 +7,7 @@ class Course < ApplicationRecord has_many :course_infos, dependent: :destroy # 课堂左侧导航栏的模块 - has_many :course_modules, -> {where hidden: 0}, dependent: :destroy + has_many :course_modules, dependent: :destroy has_many :board_course_modules, -> { board_module }, class_name: "CourseModule" has_many :attachment_course_modules, -> { attachment_module }, class_name: "CourseModule" has_many :common_course_modules, -> { common_homework_module }, class_name: "CourseModule" diff --git a/app/models/course_module.rb b/app/models/course_module.rb index 7b96a044f..641c70425 100644 --- a/app/models/course_module.rb +++ b/app/models/course_module.rb @@ -7,6 +7,7 @@ class CourseModule < ApplicationRecord validates :module_name, length: { maximum: 20 } + scope :not_hidden, -> { where(hidden: 0) } scope :graduation_module, -> { where(module_type: "graduation") } scope :graduation_module_not_hidden, -> { graduation_module.where(hidden: 0) } scope :board_module, -> { where(module_type: 'board') } diff --git a/app/views/courses/index.json.jbuilder b/app/views/courses/index.json.jbuilder index 1993851e8..5a128a0b7 100644 --- a/app/views/courses/index.json.jbuilder +++ b/app/views/courses/index.json.jbuilder @@ -12,7 +12,7 @@ json.courses do json.is_public course.is_public json.is_accessible course.is_public == 1 || @user.course_identity(course) < Course::NORMAL json.is_end course.is_end - json.first_category_url module_url(course.course_modules.first, course) + json.first_category_url module_url(course.course_modules.not_hidden.first, course) end end json.courses_count @courses_count diff --git a/app/views/users/courses/shared/_course.json.jbuilder b/app/views/users/courses/shared/_course.json.jbuilder index e5823212e..629f47264 100644 --- a/app/views/users/courses/shared/_course.json.jbuilder +++ b/app/views/users/courses/shared/_course.json.jbuilder @@ -4,7 +4,7 @@ json.members_count course.members_count json.homework_commons_count course.homework_commons_count json.attachments_count course.attachments.count -json.first_category_url module_url(course.course_modules.where.not(module_type: "activity").where(hidden: 0).order(position: :desc).first, course) +json.first_category_url module_url(course.course_modules.where(hidden: 0).order(position: :desc).first, course) json.is_public course.is_public json.can_visited observed_logged_user? || course.can_visited? From d0683cd83cf04e1427c250bf2ed5662c154d1c4e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 24 Jun 2019 10:11:49 +0800 Subject: [PATCH 0169/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=8A=A5=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/student_works_helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/student_works_helper.rb b/app/helpers/student_works_helper.rb index 93a1a3f9a..682bfbf81 100644 --- a/app/helpers/student_works_helper.rb +++ b/app/helpers/student_works_helper.rb @@ -41,7 +41,7 @@ module StudentWorksHelper def student_efficiency(homework_common, work) myshixun_ids = homework_common.student_works.pluck(:myshixun_id) - myshixuns = Myshixun.where(id: myshixun_ids).includes(games: [:outputs]) + myshixuns = Myshixun.where(id: myshixun_ids).includes(:games) #student_works_user_id = homework_common.student_works.pluck(:user_id).uniq #shixun = homework_common.shixuns.first #logger.info("#########shixun_id: ###{shixun.id}") @@ -54,13 +54,13 @@ module StudentWorksHelper objects = myshixuns.map do |myshixun| # 评测次数 - evaluate_count = myshixun.games.inject(0) {|sum, g| sum + g.outputs.pluck(:query_index).first.to_i} + evaluate_count = myshixun.games.sum(:evaluate_count) # 获取最大评测次数 max_evaluate_count = (evaluate_count > max_evaluate_count ? evaluate_count : max_evaluate_count) # 通关耗时 pass_consume_time = (myshixun.games.where(status: 2).pluck(:cost_time).sum / 60.0) # 总耗时 - all_time = (myshixun.games.pluck(:cost_time).sum / 60.0) + all_time = (myshixun.games.sum(:cost_time) / 60.0) # 通关得分 user_total_score = myshixun.total_score.to_i # 耗时,保留2位小数, From 85363ea89f3e5d1e00be00214284914aeeb4a89f Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 24 Jun 2019 10:26:26 +0800 Subject: [PATCH 0170/1015] =?UTF-8?q?=E7=94=B3=E8=AF=89=E6=88=90=E5=8A=9F?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E8=AF=A5=E8=AF=84=E5=88=86=E5=BA=94=E5=A4=B1?= =?UTF-8?q?=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 9e3a1930c..f4a072a4b 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -582,6 +582,9 @@ class StudentWorksController < ApplicationController score_appeal.tidings.update_all(status: 1) if params[:status].to_i == 3 + # 申诉成功后该评分失效 + score.update_attributes(is_invalid: 1) + # 申诉成功后 扣匿评学生的违规匿评扣分 sw = @homework.student_works.find_by(user_id: score.user_id) sw.update_attribute("appeal_penalty", @homework.homework_detail_manual.appeal_penalty + sw.appeal_penalty) if sw.present? From 31cdcff85384ab0b2c172f63762fecfec0f7b998 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 24 Jun 2019 10:33:25 +0800 Subject: [PATCH 0171/1015] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 72 +++++++++++++++++-------- 1 file changed, 50 insertions(+), 22 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index e4204d9d1..e1a5ce826 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -53,8 +53,11 @@ class ExercisesController < ApplicationController @exercises = member_show_exercises.present? ? member_show_exercises.unified_setting : [] else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷 # 已发布 当前用户班级分组的 试卷id - exercise_settings_ids = @course.exercise_group_settings.exercise_group_published.where(course_group_id: member_group_id).pluck(:exercise_id).uniq - @exercises = member_show_exercises.present? ? member_show_exercises.unified_setting.or(member_show_exercises.where(id: exercise_settings_ids)) : [] + exercise_settings_ids = @course.exercise_group_settings.exercise_group_published + .where(course_group_id: member_group_id).pluck(:exercise_id).uniq + @exercises = member_show_exercises.present? ? + member_show_exercises.unified_setting.or(member_show_exercises.where(id: exercise_settings_ids)) + : [] end else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁 @is_teacher_or = 0 @@ -65,13 +68,20 @@ class ExercisesController < ApplicationController choose_type = params[:type].to_i member_group_id = @current_student.first.try(:course_group_id).to_i if @is_teacher_or == 2 && member_group_id > 0 - exercise_groups_sets = @course.exercise_group_settings.where(course_group_id: member_group_id).exercise_group_published + exercise_groups_sets = @course.exercise_group_settings.where(course_group_id: member_group_id) + .exercise_group_published exercise_settings_ids = exercise_groups_sets.pluck(:exercise_id) exercise_ended_ids = exercise_groups_sets.exercise_group_ended.pluck(:exercise_id).uniq if choose_type == 2 - @exercises = @exercises_all.present? ? @exercises_all.exercise_by_status(2).unified_setting.or(@exercises_all.where(id: (exercise_settings_ids - exercise_ended_ids).uniq)) : [] + @exercises = @exercises_all.present? ? + @exercises_all.exercise_by_status(2).unified_setting + .or(@exercises_all.where(id: (exercise_settings_ids - exercise_ended_ids).uniq)) + : [] elsif choose_type == 3 - @exercises = @exercises_all.present? ? @exercises_all.exercise_by_status(3).unified_setting.or(@exercises_all.where(id: exercise_ended_ids)) : [] + @exercises = @exercises_all.present? ? + @exercises_all.exercise_by_status(3).unified_setting + .or(@exercises_all.where(id: exercise_ended_ids)) + : [] end else @exercises = @exercises.exercise_by_status(choose_type) @@ -412,7 +422,8 @@ class ExercisesController < ApplicationController @user_permission = 2 @user_course_groups = @course.teacher_group(current_user.id) #当前老师的分班 @being_setting_course_ids = @exercise.common_published_ids(current_user.id) #当前用户已发布的班级的id - @user_published_setting = @exercise.exercise_group_settings.find_in_exercise_group("course_group_id",@being_setting_course_ids) #当前用户已发布班级的试卷设置 + @user_published_setting = @exercise.exercise_group_settings + .find_in_exercise_group("course_group_id",@being_setting_course_ids) #当前用户已发布班级的试卷设置 exercise_ids = [@exercise.id] @exercise_publish_count = get_user_permission_course(exercise_ids,2).count #判断当前用户是否有试卷已发布的分班,用于显示立即截止/撤销发布 @exercise_unpublish_count = get_user_permission_course(exercise_ids,1).count #判断当前用户是否有试卷未发布的分班,用户显示立即发布 @@ -451,7 +462,7 @@ class ExercisesController < ApplicationController # 统一设置或者分班为0,则更新试卷,并删除试卷分组 if unified_setting || (course_group_ids.size == 0) - params_publish_time = params[:publish_time].blank? ? nil : params[:publish_time].to_time + params_publish_time = params[:publish_time].blank? ? nil : params[:publish_time].to_time params_end_time = nil if params[:end_time].blank? if params_publish_time.present? @@ -507,10 +518,12 @@ class ExercisesController < ApplicationController end # exercise_end_time = t[:end_time].present? ? t[:end_time].to_time : nil exercise_group = exercise_groups.find_in_exercise_group("course_group_id",course_id) #判断该分班是否存在 - if exercise_group.present? && exercise_group.first.end_time <= Time.now && (exercise_end_time != exercise_group.first.end_time || exercise_publish_time != exercise_group.first.publish_time) #已截止且时间改变的,则提示错误 + if exercise_group.present? && exercise_group.first.end_time <= Time.now && + (exercise_end_time != exercise_group.first.end_time || exercise_publish_time != exercise_group.first.publish_time) #已截止且时间改变的,则提示错误 error_count += 1 end - if exercise_group.present? && exercise_group.first.publish_time < Time.now && exercise_publish_time != exercise_group.first.publish_time + if exercise_group.present? && exercise_group.first.publish_time < + Time.now && exercise_publish_time != exercise_group.first.publish_time error_count += 1 end if error_count == 0 @@ -692,7 +705,8 @@ class ExercisesController < ApplicationController if exercise.unified_setting ex_status = exercise.exercise_status #则为试卷的状态 else - ex_status = exercise.exercise_group_settings.find_in_exercise_group("course_group_id",params[:group_ids]).exercise_group_not_published.present? ? 1 : 0 + ex_status = exercise.exercise_group_settings.find_in_exercise_group("course_group_id",params[:group_ids]) + .exercise_group_not_published.present? ? 1 : 0 end if ex_status == 1 #如果试卷存在已发布的,或者是已截止的,那么则直接跳过 g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数,那么试卷的统一设置需修改 @@ -891,11 +905,13 @@ class ExercisesController < ApplicationController if exercise_user.present? if exercise_user.commit_status == 1 && @exercise.get_exercise_status(current_user.id) == 2 #用户已提交且试卷提交中 if @exercise.time == -1 || ((Time.now.to_i - exercise_user.start_at.to_i) < @exercise.time.to_i * 60) - exercise_user.update_attributes(:score => nil, :end_at => nil, :status => nil, :commit_status => 0, :objective_score => 0.0, :subjective_score => -1.0) + exercise_user.update_attributes(:score => nil, :end_at => nil, :status => nil, :commit_status => 0, + :objective_score => 0.0, :subjective_score => -1.0) exercise_user.user.exercise_shixun_answers.search_shixun_answers("exercise_question_id",ex_question_ids).destroy_all exercise_answers = exercise_user.user.exercise_answers.search_answer_users("exercise_question_id",ex_question_ids) exercise_answers.update_all(:score => -1.0) - all_answer_comment = ExerciseAnswerComment.search_answer_comments("exercise_question_id",ex_question_ids).search_answer_comments("exercise_answer_id",exercise_answers.pluck(:id)) + all_answer_comment = ExerciseAnswerComment.search_answer_comments("exercise_question_id",ex_question_ids) + .search_answer_comments("exercise_answer_id",exercise_answers.pluck(:id)) all_answer_comment.destroy_all normal_status(0,"撤销回答成功") else @@ -923,11 +939,13 @@ class ExercisesController < ApplicationController if params[:realname].present? search_name = params[:realname] #搜索用户的nickname,如果存在则返回,否则继续查询用户的真实姓名或学生号 - @exercise_users = @exercise_users.includes(:user).where("LOWER(concat(users.lastname, users.firstname)) like ?","%#{search_name}%") + @exercise_users = @exercise_users.includes(:user).where("LOWER(concat(users.lastname, users.firstname)) like ?", + "%#{search_name}%") end if params[:student_id].present? search_st_id = params[:student_id].to_i - @exercise_users = @exercise_users.includes(user: [:user_extension]).where('user_extensions.student_id like ?',"%#{search_st_id}%") + @exercise_users = @exercise_users.includes(user: [:user_extension]) + .where('user_extensions.student_id like ?',"%#{search_st_id}%") end sort = params[:sort] ? params[:sort] : "asc" @exercise_users = @exercise_users.order("score #{sort}") @@ -962,8 +980,10 @@ class ExercisesController < ApplicationController redo_exercise_users = @exercise_users.exercise_commit_users(user_ids) redo_exercise_users.update_all(redo_option) exercise_question_ids = @exercise.exercise_questions.pluck(:id).uniq - ExerciseAnswer.search_answer_users("user_id",user_ids).search_answer_users("exercise_question_id",exercise_question_ids).destroy_all - ExerciseShixunAnswer.search_shixun_answers("user_id",user_ids).search_shixun_answers("exercise_question_id",exercise_question_ids).destroy_all + ExerciseAnswer.search_answer_users("user_id",user_ids) + .search_answer_users("exercise_question_id",exercise_question_ids).destroy_all + ExerciseShixunAnswer.search_shixun_answers("user_id",user_ids) + .search_shixun_answers("exercise_question_id",exercise_question_ids).destroy_all normal_status(0,"已成功打回重做!") else @@ -1005,13 +1025,17 @@ class ExercisesController < ApplicationController @t_user_exercise_status = @exercise.get_exercise_status(current_user.id) - if @user_course_identity < Course::STUDENT || (@t_user_exercise_status == 3) || (@exercise_user_current.present? && @exercise_user_current.commit_status == 1) + if @user_course_identity < Course::STUDENT || (@t_user_exercise_status == 3) || + (@exercise_user_current.present? && @exercise_user_current.commit_status == 1) @user_exercise_status = 1 #当前用户为老师/试卷已截止/试卷已提交不可编辑 else @user_exercise_status = 0 #可编辑 end - @exercise_questions = @exercise.exercise_questions.includes(:exercise_shixun_challenges,:exercise_shixun_answers,:exercise_answers,:exercise_standard_answers) + @exercise_questions = @exercise.exercise_questions.includes(:exercise_shixun_challenges, + :exercise_shixun_answers, + :exercise_answers, + :exercise_standard_answers) if @exercise.question_random @exercise_questions = @exercise_questions.order("RAND()") @@ -1266,7 +1290,8 @@ class ExercisesController < ApplicationController tip_exception(403,"无权限操作") else get_export_users(@exercise,@course,@export_ex_users) - exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @exercise.exercise_name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') + exercise_export_name = + "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} end } @@ -1426,7 +1451,8 @@ class ExercisesController < ApplicationController def validates_exercise_params normal_status(-1, "试卷标题不能为空!") if params[:exercise_name].blank? normal_status(-1, "试卷标题不能超过60个字符") if (params[:exercise_name].length > 60) - normal_status(-1, "试卷须知不能超过100个字符") if (params[:exercise_description].present? && params[:exercise_description].length > 100) + normal_status(-1, "试卷须知不能超过100个字符") if (params[:exercise_description].present? && + params[:exercise_description].length > 100) end #判断设置的时间是否合理 @@ -1619,7 +1645,8 @@ class ExercisesController < ApplicationController @exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id).first #查找当前用户是否有过答题 if @user_course_identity == Course::STUDENT if @exercise_user_current.present? - if @exercise.time > 0 && @exercise_user_current.start_at.present? && (@exercise_user_current.commit_status == 0) && ((@exercise_user_current.start_at + (@exercise.time.to_i + 1).minutes) < Time.now) + if @exercise.time > 0 && @exercise_user_current.start_at.present? && (@exercise_user_current.commit_status == 0) && + ((@exercise_user_current.start_at + (@exercise.time.to_i + 1).minutes) < Time.now) #当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制 objective_score = calculate_student_score(@exercise,current_user)[:total_score] subjective_score = @exercise_user_current.subjective_score < 0.0 ? 0.0 : @exercise_user_current.subjective_score @@ -1669,7 +1696,8 @@ class ExercisesController < ApplicationController def check_exercise_public if @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生,试卷公开统计,且已截止,且已提交 ex_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first - unless @exercise.get_exercise_status(current_user.id) == 3 && ex_user.present? && ex_user.commit_status == 1 && @exercise.show_statistic + unless @exercise.get_exercise_status(current_user.id) == 3 && ex_user.present? && ex_user.commit_status == 1 && + @exercise.show_statistic normal_status(-1,"学生暂不能查看") end end From 4ac9838d361a2da460ed35f7ad03f20d55c6818d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 24 Jun 2019 10:50:51 +0800 Subject: [PATCH 0172/1015] =?UTF-8?q?=E5=B7=A6=E4=BE=A7=E5=AF=BC=E8=88=AA?= =?UTF-8?q?=E6=A0=8F=E5=8E=BB=E6=8E=89=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 01ce1f6e8..8de98f0cb 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -912,7 +912,7 @@ class CoursesController < ApplicationController def left_banner @user = current_user - @is_teacher = @user.teacher_of_course?(@course) + @is_teacher = @user_course_identity < Course::ASSISTANT_PROFESSOR @course_modules = @course.course_modules.where(hidden: 0) @hidden_modules = @course.course_modules.where(hidden: 1) @second_category_type = ["shixun_homework", "graduation", "attachment", "board", "course_group"] From 12c862c0e9f39fd064f70c20f22006ea25a02730 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 24 Jun 2019 11:11:32 +0800 Subject: [PATCH 0173/1015] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index f7c7e487a..b668b906d 100644 --- a/Gemfile +++ b/Gemfile @@ -45,12 +45,14 @@ gem 'rqrcode_png' gem 'acts-as-taggable-on', '~> 6.0' -group :'development.rb.example', :test do +group :development, :test do +#group :'development.rb.example', :test do gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] gem 'rspec-rails', '~> 3.8' end -group :'development.rb.example' do +group :development, :test do +#group :'development.rb.example' do gem 'awesome_print' gem 'web-console', '>= 3.3.0' gem 'listen', '>= 3.0.5', '< 3.2' From 3796fa40e70f7197f30e51018577d1cad6bc4f84 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 24 Jun 2019 11:12:51 +0800 Subject: [PATCH 0174/1015] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index b668b906d..31af87f14 100644 --- a/Gemfile +++ b/Gemfile @@ -51,7 +51,7 @@ group :development, :test do gem 'rspec-rails', '~> 3.8' end -group :development, :test do +group :development do #group :'development.rb.example' do gem 'awesome_print' gem 'web-console', '>= 3.3.0' From 00aed4fb2273f828b8dd6c08e74fbe317e606fd6 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 14:13:27 +0800 Subject: [PATCH 0175/1015] fix bug --- app/models/exercise.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index b3feec12c..22e2c885b 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -119,6 +119,7 @@ class Exercise < ApplicationRecord else status = exercise_status end + Rails.logger.info("#################__________status___________####################{status}") status end From b58c54d6a37c551c33f6e25b05de8dab6edd55d0 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Mon, 24 Jun 2019 14:18:25 +0800 Subject: [PATCH 0176/1015] fix i18n issue --- config/locales/shixuns/en.yml | 8 ++++---- config/locales/shixuns/zh-CN.yml | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/config/locales/shixuns/en.yml b/config/locales/shixuns/en.yml index 0f1a9f695..10de1eaef 100644 --- a/config/locales/shixuns/en.yml +++ b/config/locales/shixuns/en.yml @@ -1,7 +1,7 @@ 'en': shixun: status: - 0: editing - 1: applying - 2: published - 3: closed + '0': editing + '1': applying + '2': published + '3': closed diff --git a/config/locales/shixuns/zh-CN.yml b/config/locales/shixuns/zh-CN.yml index c5ba574d8..d7ad5f7e2 100644 --- a/config/locales/shixuns/zh-CN.yml +++ b/config/locales/shixuns/zh-CN.yml @@ -1,7 +1,7 @@ 'zh-CN': shixun: status: - 0: 编辑中 - 1: 审核中 - 2: 已发布 - 3: 已关闭 + '0': 编辑中 + '1': 审核中 + '2': 已发布 + '3': 已关闭 From bdc43fb9ce99905d97fb01eaeb50dca66cf6eb0d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 24 Jun 2019 14:29:19 +0800 Subject: [PATCH 0177/1015] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E8=AF=BE=E5=A0=82=E7=9A=84=E5=AD=A6=E7=94=9Fapi=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 6 ++++-- .../courses/get_historical_course_students.json.jbuilder | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 8de98f0cb..1bf81e87b 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -737,11 +737,13 @@ class CoursesController < ApplicationController end end - # 获取历史课堂,即用户管理的所有课堂以及课堂下的分班 + # 获取历史课堂,即用户管理的所有课堂以及课堂下的分班(去除当前课堂) def get_historical_courses user_id = current_user.id - @courses = Course.includes(:course_groups).where(tea_id: user_id, is_delete: 0) + @courses = Course.where.not(id: @course.id).joins(:course_members). + where(is_delete: 0, course_members: {user_id: current_user.id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR]}).includes(:course_groups) + # @courses = Course.includes(:course_groups).where(id: current_user.course_members, is_delete: 0) end # 根据历史课堂的课堂id和分班id获取所有学生 diff --git a/app/views/courses/get_historical_course_students.json.jbuilder b/app/views/courses/get_historical_course_students.json.jbuilder index a2d3a3f57..8dc4e22ce 100644 --- a/app/views/courses/get_historical_course_students.json.jbuilder +++ b/app/views/courses/get_historical_course_students.json.jbuilder @@ -1,6 +1,6 @@ json.students do json.array! @students do |student| - json.course_member_id student.id + json.user_id student.user_id json.name student.user.real_name json.student_id student.user.user_extension.try(:student_id) json.school_name student.user.user_extension.school.try(:name) From fd00b5981325aaa526ee6ca8a34c44829c535446 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Mon, 24 Jun 2019 14:33:55 +0800 Subject: [PATCH 0178/1015] =?UTF-8?q?=E6=97=A5=E5=BF=97=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/gits_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/gits_controller.rb b/app/controllers/gits_controller.rb index 4064f0f99..60a551e7b 100644 --- a/app/controllers/gits_controller.rb +++ b/app/controllers/gits_controller.rb @@ -4,7 +4,6 @@ class GitsController < ApplicationController def auth # HTTP_AUTHORIZATION: "Basic 这里base64编码的的密码(user:passwd)" logger.info("11111112222223333 HTTP_AUTHORIZATION: #{request.env["HTTP_AUTHORIZATION"]}") - logger.info("11111112222223333: request is #{request.env}") #logger.info("#########-----request_env: #{request.env}") # {"service"=>"git-receive-pack", "controller"=>"gits", "action"=>"auth", # "url"=>"forge01/cermyt39.git/info/refs"} From 9034e1a53409bfd447baf2ad17aeb0ed8cd668da Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 14:43:07 +0800 Subject: [PATCH 0179/1015] fix bug --- app/models/exercise.rb | 104 ++++++++++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 37 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 22e2c885b..fb2608632 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -98,59 +98,89 @@ class Exercise < ApplicationRecord #判断是否为分班,如果分班,试卷的截止时间为当前分班时间,否则为试卷的截止时间 def get_exercise_status(user_id) user_group = course.course_members.find_by(user_id: user_id) - if user_group.present? - if user_group.role == "STUDENT" #为学生 - is_teacher = false - else - is_teacher = true - end - ex_time = get_exercise_times(user_id,is_teacher) + if user_group.present? && user_group.role == "STUDENT" #当为学生的时候,需根据分班来判断试卷状态 + ex_time = get_exercise_times(user_id,false) - pb_time = ex_time[:publish_time] - ed_time = ex_time[:end_time] + pb_time = ex_time[:publish_time] + ed_time = ex_time[:end_time] - if pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now - status = 2 - elsif ed_time.present? && ed_time <= Time.now - status = 3 - else - status = 1 - end + if pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now + status = 2 + elsif ed_time.present? && ed_time <= Time.now + status = 3 + else + status = 1 + end else - status = exercise_status + status = exercise_status #当为老师的时候,则为试卷的总状态 end - Rails.logger.info("#################__________status___________####################{status}") + # if user_group.present? + # if user_group.role == "STUDENT" #为学生 + # is_teacher = false + # else + # is_teacher = true + # end + # ex_time = get_exercise_times(user_id,is_teacher) + # + # pb_time = ex_time[:publish_time] + # ed_time = ex_time[:end_time] + # + # if pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now + # status = 2 + # elsif ed_time.present? && ed_time <= Time.now + # status = 3 + # else + # status = 1 + # end + # else + # status = exercise_status + # end status end #获取试卷的发布时间和截止时间。teacher 为boolean,当为true时,表示的是当前为老师 def get_exercise_times(user_id,teacher) - if unified_setting + if unified_setting || teacher #当试卷为统一设置或当前为老师的时候 pb_time = publish_time en_time = end_time + + if end_time <= Time.now && exercise_status != 3 + update_column("exercise_status",3) + end else ex_group_setting = exercise_group_settings - if teacher #当前为老师,为设置组的最大值和最小值 - user_group = course.teacher_course_groups.get_user_groups(user_id) - user_group_ids = user_group.present? ? user_group.pluck(:course_group_id) : course.course_groups.pluck(:id) - user_ex_group_settings = ex_group_setting.find_in_exercise_group("course_group_id",user_group_ids) - pb_time_min = user_ex_group_settings.publish_time_no_null.map(&:publish_time) - en_time_max = user_ex_group_settings.end_time_no_null.map(&:end_time) - pb_time = pb_time_min.size > 0 ? pb_time_min.min : nil - en_time = en_time_max.size > 0 ? en_time_max.max : nil + # if teacher #当前为老师,为设置组的最大值和最小值 + # user_group = course.teacher_course_groups.get_user_groups(user_id) + # user_group_ids = user_group.present? ? user_group.pluck(:course_group_id) : course.course_groups.pluck(:id) + # user_ex_group_settings = ex_group_setting.find_in_exercise_group("course_group_id",user_group_ids) + # pb_time_min = user_ex_group_settings.publish_time_no_null.map(&:publish_time) + # en_time_max = user_ex_group_settings.end_time_no_null.map(&:end_time) + # pb_time = pb_time_min.size > 0 ? pb_time_min.min : nil + # en_time = en_time_max.size > 0 ? en_time_max.max : nil + # else + # user_group = course.students.course_find_by_ids("user_id",user_id) + # if user_group.present? + # user_group_id = user_group.first.course_group_id + # user_ex_group_setting = ex_group_setting.find_in_exercise_group("course_group_id",user_group_id) + # pb_time = user_ex_group_setting.present? ? user_ex_group_setting.first.publish_time : nil + # en_time = user_ex_group_setting.present? ? user_ex_group_setting.first.end_time : nil + # else + # pb_time = nil + # en_time = nil + # end + # end + user_group = course.students.course_find_by_ids("user_id",user_id) + if user_group.present? + user_group_id = user_group.first.course_group_id + user_ex_group_setting = ex_group_setting.find_in_exercise_group("course_group_id",user_group_id) + pb_time = user_ex_group_setting.present? ? user_ex_group_setting.first.publish_time : nil + en_time = user_ex_group_setting.present? ? user_ex_group_setting.first.end_time : nil else - user_group = course.students.course_find_by_ids("user_id",user_id) - if user_group.present? - user_group_id = user_group.first.course_group_id - user_ex_group_setting = ex_group_setting.find_in_exercise_group("course_group_id",user_group_id) - pb_time = user_ex_group_setting.present? ? user_ex_group_setting.first.publish_time : nil - en_time = user_ex_group_setting.present? ? user_ex_group_setting.first.end_time : nil - else - pb_time = nil - en_time = nil - end + pb_time = nil + en_time = nil end end + { "publish_time":pb_time, "end_time":en_time From d8621fc366df1fb7141373d7bcda556ce9055185 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 24 Jun 2019 14:58:06 +0800 Subject: [PATCH 0180/1015] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 3 +-- .../courses/get_historical_course_students.json.jbuilder | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 1bf81e87b..253bafa48 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -739,8 +739,6 @@ class CoursesController < ApplicationController # 获取历史课堂,即用户管理的所有课堂以及课堂下的分班(去除当前课堂) def get_historical_courses - user_id = current_user.id - @courses = Course.where.not(id: @course.id).joins(:course_members). where(is_delete: 0, course_members: {user_id: current_user.id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR]}).includes(:course_groups) # @courses = Course.includes(:course_groups).where(id: current_user.course_members, is_delete: 0) @@ -756,6 +754,7 @@ class CoursesController < ApplicationController @students = @students.where(course_group_id: course_group_id) end + @students = @students.includes(user: [user_extension: :school]) @students_count = @students.size end diff --git a/app/views/courses/get_historical_course_students.json.jbuilder b/app/views/courses/get_historical_course_students.json.jbuilder index 8dc4e22ce..be58ff06a 100644 --- a/app/views/courses/get_historical_course_students.json.jbuilder +++ b/app/views/courses/get_historical_course_students.json.jbuilder @@ -2,8 +2,8 @@ json.students do json.array! @students do |student| json.user_id student.user_id json.name student.user.real_name - json.student_id student.user.user_extension.try(:student_id) - json.school_name student.user.user_extension.school.try(:name) + json.student_id student.user.student_id + json.school_name student.user.school_name end end json.students_count @students_count \ No newline at end of file From ff3e34510e95c875dc71d75b6f159479cdafef0f Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 15:19:38 +0800 Subject: [PATCH 0181/1015] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=9A=84=E7=8A=B6=E6=80=81=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exercise_answers_controller.rb | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/app/controllers/exercise_answers_controller.rb b/app/controllers/exercise_answers_controller.rb index df6550c0d..7298f2fe7 100644 --- a/app/controllers/exercise_answers_controller.rb +++ b/app/controllers/exercise_answers_controller.rb @@ -94,28 +94,39 @@ class ExerciseAnswersController < ApplicationController def get_exercise_question @exercise_question = ExerciseQuestion.find_by_id(params[:exercise_question_id]) - @exercise = @exercise_question.exercise - @course = @exercise.course - @exercise_user = @exercise.exercise_users.find_by(user_id: current_user.id) #当前用户 + @exercise = @exercise_question&.exercise + @course = @exercise&.course + @exercise_user = @exercise&.exercise_users.find_by(user_id: current_user.id) #当前用户 @exercise_user_status = @exercise.get_exercise_status(current_user.id) - if @exercise_question.blank? normal_status(-1,"试卷问题不存在!") elsif @exercise.blank? normal_status(-1,"试卷不存在!") elsif @course.blank? normal_status(-1,"该课堂不存在!") - elsif (@exercise_user.present? && @exercise_user&.commit_status == 1) || @exercise_user_status == 3 #已提交答案的/时间已结束的试卷不允许再修改 + elsif @exercise_user.blank? + normal_status(-1,"试卷用户不存在!") + elsif @exercise_user_status == 3 || @exercise_user.commit_status == 1 normal_status(-1,"已提交/已结束的试卷不允许修改!") - elsif @exercise.time > 0 - user_start_at = @exercise_user&.start_at - exercise_time = @exercise.time.to_i + 1 # - if (user_start_at + exercise_time.minutes) < Time.now - normal_status(-1,"限时试卷已结束!") + else + if @exercise.time > 0 && @exercise_user.start_at.present? && ((@exercise_user.start_at + (@exercise.time.to_i + 1).minutes) < Time.now) + objective_score = calculate_student_score(@exercise,current_user)[:total_score] + subjective_score = @exercise_user.subjective_score < 0.0 ? 0.0 : @exercise_user.subjective_score + total_score = objective_score + subjective_score + commit_option = { + :status => 1, + :commit_status => 1, + :end_at => Time.now, + :objective_score => objective_score, + :score => total_score, + :subjective_score => subjective_score + } + @exercise_user.update_attributes(commit_option) + normal_status(-1,"试卷提交时间已截止!") end - end + end end From 76d29f9559071fac481ccdcc5db4d4d1482db54a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 24 Jun 2019 15:38:36 +0800 Subject: [PATCH 0182/1015] =?UTF-8?q?=E8=AF=84=E6=B5=8B=E6=B2=A1=E8=BF=87?= =?UTF-8?q?=E5=85=B3=E5=88=86=E6=95=B0=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 91cff3c19..035b43955 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -182,7 +182,13 @@ class MyshixunsController < ApplicationController test_set_percentage = test_set_score / 100.to_f # 测试集得分比 score = (challenge.score * test_set_percentage * answer_deduction_percentage).to_i # 如果分数比上次多,则更新成绩 - game.update_attributes!(:status => 0, :final_score => score) if game.final_score < score + game_update = + if game.final_score < score + {final_score: score, status: 0} + else + {status: 0} + end + game.update_attributes!(game_update) end end test_cases_time = format("%.3f", (Time.now.to_f - t1.to_f)).to_f From 13f1d15b337a184143eae10ee7bdd8769d8f5491 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 16:01:46 +0800 Subject: [PATCH 0183/1015] fix but --- app/models/exercise.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index fb2608632..3b3b93f09 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -144,7 +144,7 @@ class Exercise < ApplicationRecord pb_time = publish_time en_time = end_time - if end_time <= Time.now && exercise_status != 3 + if en_time.present? && (en_time <= Time.now) && (exercise_status != 3) update_column("exercise_status",3) end else From a5e63a512485e18145f13d07edb05ae384af557a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 16:07:43 +0800 Subject: [PATCH 0184/1015] fix but --- app/models/exercise.rb | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 3b3b93f09..0c8b97ca7 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -114,27 +114,6 @@ class Exercise < ApplicationRecord else status = exercise_status #当为老师的时候,则为试卷的总状态 end - # if user_group.present? - # if user_group.role == "STUDENT" #为学生 - # is_teacher = false - # else - # is_teacher = true - # end - # ex_time = get_exercise_times(user_id,is_teacher) - # - # pb_time = ex_time[:publish_time] - # ed_time = ex_time[:end_time] - # - # if pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now - # status = 2 - # elsif ed_time.present? && ed_time <= Time.now - # status = 3 - # else - # status = 1 - # end - # else - # status = exercise_status - # end status end @@ -149,26 +128,6 @@ class Exercise < ApplicationRecord end else ex_group_setting = exercise_group_settings - # if teacher #当前为老师,为设置组的最大值和最小值 - # user_group = course.teacher_course_groups.get_user_groups(user_id) - # user_group_ids = user_group.present? ? user_group.pluck(:course_group_id) : course.course_groups.pluck(:id) - # user_ex_group_settings = ex_group_setting.find_in_exercise_group("course_group_id",user_group_ids) - # pb_time_min = user_ex_group_settings.publish_time_no_null.map(&:publish_time) - # en_time_max = user_ex_group_settings.end_time_no_null.map(&:end_time) - # pb_time = pb_time_min.size > 0 ? pb_time_min.min : nil - # en_time = en_time_max.size > 0 ? en_time_max.max : nil - # else - # user_group = course.students.course_find_by_ids("user_id",user_id) - # if user_group.present? - # user_group_id = user_group.first.course_group_id - # user_ex_group_setting = ex_group_setting.find_in_exercise_group("course_group_id",user_group_id) - # pb_time = user_ex_group_setting.present? ? user_ex_group_setting.first.publish_time : nil - # en_time = user_ex_group_setting.present? ? user_ex_group_setting.first.end_time : nil - # else - # pb_time = nil - # en_time = nil - # end - # end user_group = course.students.course_find_by_ids("user_id",user_id) if user_group.present? user_group_id = user_group.first.course_group_id From 9c1ab345193dea5f0248866986d15426b282564b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 16:19:07 +0800 Subject: [PATCH 0185/1015] fix bug --- app/controllers/exercise_answers_controller.rb | 4 ++-- app/controllers/exercises_controller.rb | 6 ------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/app/controllers/exercise_answers_controller.rb b/app/controllers/exercise_answers_controller.rb index 7298f2fe7..cad482390 100644 --- a/app/controllers/exercise_answers_controller.rb +++ b/app/controllers/exercise_answers_controller.rb @@ -107,10 +107,10 @@ class ExerciseAnswersController < ApplicationController normal_status(-1,"该课堂不存在!") elsif @exercise_user.blank? normal_status(-1,"试卷用户不存在!") - elsif @exercise_user_status == 3 || @exercise_user.commit_status == 1 + elsif @exercise_user.commit_status == 1 normal_status(-1,"已提交/已结束的试卷不允许修改!") else - if @exercise.time > 0 && @exercise_user.start_at.present? && ((@exercise_user.start_at + (@exercise.time.to_i + 1).minutes) < Time.now) + if (@exercise_user_status == 3 && @exercise_user.commit_status == 0) || (@exercise.time > 0 && @exercise_user.start_at.present? && ((@exercise_user.start_at + (@exercise.time.to_i + 1).minutes) < Time.now)) objective_score = calculate_student_score(@exercise,current_user)[:total_score] subjective_score = @exercise_user.subjective_score < 0.0 ? 0.0 : @exercise_user.subjective_score total_score = objective_score + subjective_score diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index e1a5ce826..555da8e54 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1632,12 +1632,6 @@ class ExercisesController < ApplicationController normal_status(404,"答题用户不存在") elsif @exercise.get_exercise_status(current_user.id) != 2 || @answer_committed_user.commit_status == 1 # normal_status(-1,"提交错误,试卷已截止/用户已提交!") - # elsif @exercise.time > 0 - # user_start_at = @answer_committed_user.start_at - # exercise_time = @exercise.time.to_i - # if (user_start_at + exercise_time.minutes) < Time.now - # normal_status(-1,"限时试卷已结束,已自动提交!") - # end end end From 3d8c3ed9383547c14fac4ea5609325b0fbc69d3e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 24 Jun 2019 16:23:35 +0800 Subject: [PATCH 0186/1015] =?UTF-8?q?=E8=83=8C=E6=99=AF=E7=9F=A5=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 8359b14f9..a809e8d2b 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -409,7 +409,7 @@ class ShixunsController < ApplicationController end def propaedeutics - @content = Shixun.where(identifier: params[:identifier]).pluck(:propaedeutics) + @content = Shixun.find_by_identifier!(params[:identifier]).propaedeutics end # 更新背景知识 From 7d8af1c407f6af1c1f79ef059b86504fcb1010d3 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 24 Jun 2019 16:26:07 +0800 Subject: [PATCH 0187/1015] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=83=8C=E6=99=AF?= =?UTF-8?q?=E7=9F=A5=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index a809e8d2b..e7a1a8411 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -414,7 +414,7 @@ class ShixunsController < ApplicationController # 更新背景知识 def update_propaedeutics - @shixun.update_column(:propaedeutics, params[:content]) + @shixun.shixun_info.update_column(:propaedeutics, params[:content]) end # 获取推荐实训接口 2个热门实训 + 2个最新实训 From 799ec98df11c84f620559d800e9df32901dcdf2c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 16:46:03 +0800 Subject: [PATCH 0188/1015] fix but --- app/helpers/exercises_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 478b38204..3ffe177e7 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -56,8 +56,8 @@ module ExercisesHelper } @ex_sub_array.push(sub_score) end - @ex_obj_array.sort_by {|k| k[:q_position]} - @ex_sub_array.sort_by {|k| k[:q_position]} + @ex_obj_array = @ex_obj_array.sort_by {|k| k[:q_position]} + @ex_sub_array = @ex_sub_array.sort_by {|k| k[:q_position]} end #试卷的统计结果页面计算各题的 From a9749fd88615da6778014b2a487e3023448a31f3 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Mon, 24 Jun 2019 16:53:54 +0800 Subject: [PATCH 0189/1015] remove relationships && move user decorator methods to model --- app/controllers/shixuns_controller.rb | 4 +- app/decorators/user_decorator.rb | 56 --------------- app/libs/util.rb | 5 ++ app/models/relationship.rb | 2 + app/models/user.rb | 72 ++++++++++++++----- app/views/shixuns/collaborators.json.jbuilder | 2 +- 6 files changed, 63 insertions(+), 78 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 8359b14f9..c18e72efa 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -115,8 +115,8 @@ class ShixunsController < ApplicationController def show_right owner = @shixun.owner - #@fans_count = owner.followers.count - #@followed_count = owner.followed_users.count + #@fans_count = owner.fan_count + #@followed_count = owner.follow_count @user_own_shixuns = owner.shixuns.published.count end diff --git a/app/decorators/user_decorator.rb b/app/decorators/user_decorator.rb index 463d9a6e3..e00dead39 100644 --- a/app/decorators/user_decorator.rb +++ b/app/decorators/user_decorator.rb @@ -12,50 +12,6 @@ module UserDecorator logged_user? ? real_name : full_name end - # 关注数 - def follow_count - Watcher.where(user_id: id, watchable_type: %w(Principal User)).count - # User.watched_by(id).count - end - - # 粉丝数 - def fan_count - Watcher.where(watchable_type: %w(Principal User), watchable_id: id).count - # watchers.count - end - - # 是否绑定邮箱 - def email_binded? - mail.present? - end - - # 学院的url标识 - def college_identifier - - Department.find_by_id(department_members.pluck(:department_id).first)&.identifier - end - - # 是否能申请试用 - def can_apply_trial? - return false if certification == 1 - - apply = ApplyAction.order(created_at: :desc).find_by(user_id: id, container_type: 'TrialAuthorization') - - apply.present? && !apply.status.zero? - end - - # 是否已经签到 - def attendance_signed? - attendance = Attendance.find_by(user_id: id) - - attendance.present? && Util.days_between(Time.zone.now, attendance.created_at).zero? - end - - # 明日签到金币 - def tomorrow_attendance_gold - Attendance.find_by(user_id: id)&.next_gold || 50 - end - # ----------- 账号管理 ------------- def authentication_status if authentication? @@ -76,16 +32,4 @@ module UserDecorator 'uncertified' end end - - def base_info_completed? - user_columns = %i[nickname lastname] - user_extension_columns = %i[gender location location_city identity school_id department] - - user_columns.all? { |column| public_send(column).present? } && - user_extension_columns.all? { |column| user_extension.send(column).present? } - end - - def all_certified? - authentication? && professional_certification? - end end \ No newline at end of file diff --git a/app/libs/util.rb b/app/libs/util.rb index f6c8855b9..3485bebd7 100644 --- a/app/libs/util.rb +++ b/app/libs/util.rb @@ -28,4 +28,9 @@ module Util end end end + + def logger_error(exception) + Rails.logger.error(exception.message) + exception.backtrace.each { |message| Rails.logger.error(message) } + end end \ No newline at end of file diff --git a/app/models/relationship.rb b/app/models/relationship.rb index d5c754745..d71987867 100644 --- a/app/models/relationship.rb +++ b/app/models/relationship.rb @@ -1,6 +1,8 @@ +# TODO: 已废弃 class Relationship < ApplicationRecord belongs_to :follower, class_name: "User" belongs_to :followed, class_name: "User" + validates :follower_id, presence: true validates :followed_id, presence: true end diff --git a/app/models/user.rb b/app/models/user.rb index 8e25efe70..1b3349467 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -47,14 +47,6 @@ class User < ApplicationRecord has_many :graduation_works, dependent: :destroy - # 关注 - has_many :relationships, foreign_key: "follower_id", dependent: :destroy - has_many :followed_users, through: :relationships, source: :followed - # 粉丝 - has_many :reverse_relationships, foreign_key: "followed_id", - class_name: "Relationship", - dependent: :destroy - has_many :followers, through: :reverse_relationships, source: :follower has_many :students_for_courses, foreign_key: :student_id, dependent: :destroy has_one :onclick_time, :dependent => :destroy @@ -161,19 +153,16 @@ class User < ApplicationRecord self.user_extension.try(:student_id) end - # 关注总数 - def following?(other_user) - relationships.find_by(followed_id: other_user) - end - - # 关注 - def follow!(other_user) - relationships.create!(followed_id: other_user) + # 关注数 + def follow_count + Watcher.where(user_id: id, watchable_type: %w(Principal User)).count + # User.watched_by(id).count end - # 取消关注 - def unfollow!(other_user) - relationships.find_by(followed_id: other_user.id).destroy + # 粉丝数 + def fan_count + Watcher.where(watchable_type: %w(Principal User), watchable_id: id).count + # watchers.count end # 判断当前用户是否为老师 @@ -545,6 +534,51 @@ class User < ApplicationRecord Educoder::Utils.random_hex(16) end + # 基本资料是否完善 + def base_info_completed? + user_columns = %i[nickname lastname] + user_extension_columns = %i[gender location location_city identity school_id department] + + user_columns.all? { |column| public_send(column).present? } && + user_extension_columns.all? { |column| user_extension.send(column).present? } + end + + # 全部已认证 + def all_certified? + authentication? && professional_certification? + end + + # 是否绑定邮箱 + def email_binded? + mail.present? + end + + # 学院的url标识 + def college_identifier + Department.find_by_id(department_members.pluck(:department_id).first)&.identifier + end + + # 是否能申请试用 + def can_apply_trial? + return false if certification == 1 + + apply = ApplyAction.order(created_at: :desc).find_by(user_id: id, container_type: 'TrialAuthorization') + + apply.present? && !apply.status.zero? + end + + # 是否已经签到 + def attendance_signed? + attendance = Attendance.find_by(user_id: id) + + attendance.present? && Util.days_between(Time.zone.now, attendance.created_at).zero? + end + + # 明日签到金币 + def tomorrow_attendance_gold + Attendance.find_by(user_id: id)&.next_gold || 60 # 基础50,连续签到+10 + end + protected def validate_password_length # 管理员的初始密码是5位 diff --git a/app/views/shixuns/collaborators.json.jbuilder b/app/views/shixuns/collaborators.json.jbuilder index bd880c93e..0101f1e59 100644 --- a/app/views/shixuns/collaborators.json.jbuilder +++ b/app/views/shixuns/collaborators.json.jbuilder @@ -10,7 +10,7 @@ json.array! @members do |member| json.user do json.partial! 'users/user', locals: { user: member.user } json.user_shixuns_count member.user.shixuns.published.count - #json.fans_count member.user.followers.count + #json.fans_count member.user.fan_count json.brief_introduction member.user.user_extension.brief_introduction json.identity member.user.identity json.school_name member.user.school_name From 28c48c996eb3dc94f4e0388d7cd3fec38c7756fb Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 24 Jun 2019 16:57:32 +0800 Subject: [PATCH 0190/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E7=9A=84=E5=85=B3=E5=8D=A1=E8=AE=BE=E7=BD=AE=E5=8A=A0=E5=94=AF?= =?UTF-8?q?=E4=B8=80=E7=B4=A2=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 2 +- app/services/homeworks_service.rb | 2 +- ...20_add_uniq_index_to_homework_challenge_settings.rb | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20190624085120_add_uniq_index_to_homework_challenge_settings.rb diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 6217b08c3..6e2e1df40 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -530,7 +530,7 @@ class HomeworkCommonsController < ApplicationController if setting && setting.score != score score_change = true setting.update_attributes(score: score) - else + elsif setting.blank? score_change = true HomeworkChallengeSetting.create!(homework_common_id: @homework.id, challenge_id: challenge[:challenge_id], shixun_id: @homework.homework_commons_shixun.try(:shixun_id), score: score) diff --git a/app/services/homeworks_service.rb b/app/services/homeworks_service.rb index 536d62c66..2affec0ba 100644 --- a/app/services/homeworks_service.rb +++ b/app/services/homeworks_service.rb @@ -165,7 +165,7 @@ class HomeworksService homework = work.homework_common #logger.info("#############member_course_group_id: #{member.try(:course_group_id)}") setting_time = homework.homework_group_setting work.user_id - if setting_time.end_time.present? && (setting_time.end_time > Time.now || (homework.allow_late && !homework.course.is_end)) + if setting_time.end_time.present? && (setting_time.end_time > Time.now || (homework.allow_late && homework.late_time && homework.late_time > Time.now)) #logger.info("#############setting_time: #{setting_time.end_time}") user_total_score = 0 diff --git a/db/migrate/20190624085120_add_uniq_index_to_homework_challenge_settings.rb b/db/migrate/20190624085120_add_uniq_index_to_homework_challenge_settings.rb new file mode 100644 index 000000000..49a385ad9 --- /dev/null +++ b/db/migrate/20190624085120_add_uniq_index_to_homework_challenge_settings.rb @@ -0,0 +1,10 @@ +class AddUniqIndexToHomeworkChallengeSettings < ActiveRecord::Migration[5.2] + def change + remove_index :homework_challenge_settings, [:homework_common_id, :challenge_id] if index_exists?(:homework_challenge_settings, [:homework_common_id, :challenge_id]) + sql = %Q(delete from homework_challenge_settings where (homework_common_id, challenge_id) in + (select * from (select homework_common_id, challenge_id from homework_challenge_settings group by homework_common_id, challenge_id having count(*) > 1) a) + and id not in (select * from (select max(id) from homework_challenge_settings group by homework_common_id, challenge_id having count(*) > 1 order by id) b)) + ActiveRecord::Base.connection.execute sql + add_index :homework_challenge_settings, [:homework_common_id, :challenge_id], unique: true, name: "index_on_homework_common_id_challenge_id" + end +end From 13af28f9ba12fedd6b7d7dadf14913344d6c3d6d Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 17:15:58 +0800 Subject: [PATCH 0191/1015] fix but --- app/controllers/exercises_controller.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 555da8e54..bab1170de 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1016,10 +1016,15 @@ class ExercisesController < ApplicationController @exercise_user_current.update_attribute("start_at",Time.now) end end - if @exercise.time > 0 + ex_time = @exercise.time + if ex_time > 0 + time_mill = ex_time * 60 #转为秒 + exercise_end_time = @exercise.end_time.present? ? @exercise.end_time.to_i : 0 exercise_user_start = @exercise_user_current.present? ? @exercise_user_current.start_at.to_i : 0 - exercise_user_left_time = Time.now.to_i - exercise_user_start - time_mill = @exercise.time * 60 #转为毫秒 + if (exercise_user_start + time_mill) > exercise_end_time + time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时 + end + exercise_user_left_time = Time.now.to_i - exercise_user_start #用户已回答的时间 @user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间 end From a0a109401f32b51900b5d678145f7f5467bacfc5 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 24 Jun 2019 17:29:01 +0800 Subject: [PATCH 0192/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index d603904c4..f2a964c8d 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -206,7 +206,7 @@ class ChallengesController < ApplicationController end # 关卡评测执行文件如果被修改,需要修改脚本内容 script = modify_shixun_script @shixun, @shixun.evaluate_script - @shixun.update_column(:evaluate_script, script) + @shixun.shixun_info.update_column(:evaluate_script, script) # TODO: # if path != params[:challenge][:path] # shixun_modify_status_without_publish(@shixun, 1) From 354b3a907bb8ef7495a696ec093b82d5850e3368 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 17:35:53 +0800 Subject: [PATCH 0193/1015] fix bug --- app/helpers/exercise_questions_helper.rb | 2 +- app/views/exercises/_shixun_details.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/exercise_questions_helper.rb b/app/helpers/exercise_questions_helper.rb index 28f3fddb0..69dee034f 100644 --- a/app/helpers/exercise_questions_helper.rb +++ b/app/helpers/exercise_questions_helper.rb @@ -32,7 +32,7 @@ module ExerciseQuestionsHelper def shixun_game_scores(challenge,ex_answerer,shixun_type,question_id) game_score = challenge.question_score - game_answers = challenge.exercise_shixun_answers.search_shixun_answers("user_id",ex_answerer.id).search_shixun_answers("exercise_question_id",question_id) + game_answers = challenge.exercise_shixun_answers.where(user_id:ex_answerer.id,exercise_question_id:question_id) if shixun_type == 2 && game_answers.present? #试卷已截止,用户才可以查看答案 s_score = game_answers.first.score else diff --git a/app/views/exercises/_shixun_details.json.jbuilder b/app/views/exercises/_shixun_details.json.jbuilder index 033ac3dc1..c788b8c1c 100644 --- a/app/views/exercises/_shixun_details.json.jbuilder +++ b/app/views/exercises/_shixun_details.json.jbuilder @@ -7,7 +7,7 @@ json.stage_list do json.evaluate_count game.evaluate_count json.finished_time finished_time game.end_time json.time_consuming time_consuming game - json.myself_experience game.final_score #经验值 + json.myself_experience game.final_score < 0 ? 0 : game.final_score #经验值 json.experience game.challenge.all_score #经验值 json.user_score user_score.round(1).to_s #用户获得的分数 json.game_score game_score.round(1).to_s #该关卡的总分数 From 84c714310c0229ba29e58e63df938f72f0adb79a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 18:17:21 +0800 Subject: [PATCH 0194/1015] fix but --- app/controllers/exercises_controller.rb | 32 ++++++++++++------- app/helpers/exercises_helper.rb | 17 +++++++++- .../exercises/common_header.json.jbuilder | 4 ++- app/views/exercises/index.json.jbuilder | 6 +++- 4 files changed, 45 insertions(+), 14 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index bab1170de..c3e8c4e5d 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -48,6 +48,7 @@ class ExercisesController < ApplicationController @exercises = @exercises_all #老师能看到全部的试卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同) elsif @user_course_identity == Course::STUDENT # 2为课堂成员,能看到统一设置的和自己班级的 @is_teacher_or = 2 + # get_exercise_left_time(@exercise,current_user) member_group_id = @current_student.first.try(:course_group_id).to_i # 成员的分班id,默认为0 if member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的) @exercises = member_show_exercises.present? ? member_show_exercises.unified_setting : [] @@ -204,10 +205,12 @@ class ExercisesController < ApplicationController @is_teacher_or = 0 @user_exercise_answer = @exercise.check_user_answer_status(current_user) @user_commit_counts = 0 + get_exercise_left_time(@exercise,current_user) else @is_teacher_or = 1 @user_exercise_answer = 3 #教师页面 @user_commit_counts = @exercise.exercise_users.where(commit_status:1).count #已提交的用户数 + @user_left_time = nil end @ex_status = @exercise.get_exercise_status(current_user.id) @@ -222,6 +225,8 @@ class ExercisesController < ApplicationController @exercise_publish_count = 1 #试卷未发布,且课堂没有分班的时候 end end + + rescue Exception => e uid_logger_error(e.message) tip_exception("没有权限") @@ -1016,17 +1021,20 @@ class ExercisesController < ApplicationController @exercise_user_current.update_attribute("start_at",Time.now) end end - ex_time = @exercise.time - if ex_time > 0 - time_mill = ex_time * 60 #转为秒 - exercise_end_time = @exercise.end_time.present? ? @exercise.end_time.to_i : 0 - exercise_user_start = @exercise_user_current.present? ? @exercise_user_current.start_at.to_i : 0 - if (exercise_user_start + time_mill) > exercise_end_time - time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时 - end - exercise_user_left_time = Time.now.to_i - exercise_user_start #用户已回答的时间 - @user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间 - end + + get_exercise_left_time(@exercise,@exercise_user_current) + + # ex_time = @exercise.time + # if ex_time > 0 + # time_mill = ex_time * 60 #转为秒 + # exercise_end_time = @exercise.end_time.present? ? @exercise.end_time.to_i : 0 + # exercise_user_start = @exercise_user_current.present? ? @exercise_user_current.start_at.to_i : 0 + # if (exercise_user_start + time_mill) > exercise_end_time + # time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时 + # end + # exercise_user_left_time = Time.now.to_i - exercise_user_start #用户已回答的时间 + # @user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间 + # end @t_user_exercise_status = @exercise.get_exercise_status(current_user.id) @@ -1788,4 +1796,6 @@ class ExercisesController < ApplicationController end end + + end diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 3ffe177e7..b734d9685 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -419,13 +419,13 @@ module ExercisesHelper if game.present? exercise_cha_score = 0.0 answer_status = 0 - cha_path = challenge_path exercise_cha.challenge.path if game.status == 2 && game.final_score >= 0 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) if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 + 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 @@ -681,6 +681,21 @@ module ExercisesHelper result end + def get_exercise_left_time(exercise,exercise_user) + ex_time = exercise.time + if ex_time > 0 + time_mill = ex_time * 60 #转为秒 + exercise_end_time = exercise.end_time.present? ? exercise.end_time.to_i : 0 + exercise_user_start = exercise_user.present? ? exercise_user.start_at.to_i : 0 + if (exercise_user_start + time_mill) > exercise_end_time + time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时 + end + exercise_user_left_time = Time.now.to_i - exercise_user_start #用户已回答的时间 + @user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间 + end + @user_left_time + end + #实训题学生代码的行数 def content_line(content) content.split(/\r?\n/).length diff --git a/app/views/exercises/common_header.json.jbuilder b/app/views/exercises/common_header.json.jbuilder index 68fa45a67..5d33aca66 100644 --- a/app/views/exercises/common_header.json.jbuilder +++ b/app/views/exercises/common_header.json.jbuilder @@ -1,5 +1,7 @@ json.course_is_end @course.is_end # true表示已结束,false表示未结束 -json.extract! @exercise, :id,:exercise_name,:exercise_description,:show_statistic,:time +json.extract! @exercise, :id,:exercise_name,:exercise_description,:show_statistic +json.time @user_left_time + json.exercise_status @ex_status json.user_permission do diff --git a/app/views/exercises/index.json.jbuilder b/app/views/exercises/index.json.jbuilder index 661a8886d..d7d51c343 100644 --- a/app/views/exercises/index.json.jbuilder +++ b/app/views/exercises/index.json.jbuilder @@ -21,7 +21,11 @@ if @exercises_count > 0 json.exercises do json.array! @exercises do |exercise| ex_index = exercise_index_show(exercise,@course,@is_teacher_or,@current_user_) - json.extract! exercise, :id, :exercise_name,:is_public,:created_at,:time + json.extract! exercise, :id, :exercise_name,:is_public,:created_at + if @is_teacher_or == 2 + json.time get_exercise_left_time(exercise,@current_user_) + end + json.exercise_status ex_index[:ex_status] json.lock_status ex_index[:lock_icon] json.publish_time ex_index[:publish_time] # 试卷的发布时间 From 01be5588be227918c6f8b74c70d9a2c9886d40bc Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 18:31:14 +0800 Subject: [PATCH 0195/1015] fix bug --- app/controllers/exercises_controller.rb | 8 ++++---- app/helpers/exercises_helper.rb | 8 +++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index c3e8c4e5d..3e4dea5e3 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -201,16 +201,16 @@ class ExercisesController < ApplicationController def common_header ActiveRecord::Base.transaction do begin + @user_left_time = nil if @user_course_identity > Course::ASSISTANT_PROFESSOR @is_teacher_or = 0 @user_exercise_answer = @exercise.check_user_answer_status(current_user) @user_commit_counts = 0 - get_exercise_left_time(@exercise,current_user) + @user_left_time = get_exercise_left_time(@exercise,current_user) else @is_teacher_or = 1 @user_exercise_answer = 3 #教师页面 @user_commit_counts = @exercise.exercise_users.where(commit_status:1).count #已提交的用户数 - @user_left_time = nil end @ex_status = @exercise.get_exercise_status(current_user.id) @@ -1022,8 +1022,6 @@ class ExercisesController < ApplicationController end end - get_exercise_left_time(@exercise,@exercise_user_current) - # ex_time = @exercise.time # if ex_time > 0 # time_mill = ex_time * 60 #转为秒 @@ -1038,10 +1036,12 @@ class ExercisesController < ApplicationController @t_user_exercise_status = @exercise.get_exercise_status(current_user.id) + @user_left_time = nil if @user_course_identity < Course::STUDENT || (@t_user_exercise_status == 3) || (@exercise_user_current.present? && @exercise_user_current.commit_status == 1) @user_exercise_status = 1 #当前用户为老师/试卷已截止/试卷已提交不可编辑 else + @user_left_time = get_exercise_left_time(@exercise,current_user) @user_exercise_status = 0 #可编辑 end diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index b734d9685..3f3229136 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -681,9 +681,11 @@ module ExercisesHelper result end - def get_exercise_left_time(exercise,exercise_user) + def get_exercise_left_time(exercise,user) ex_time = exercise.time + user_left_time = nil if ex_time > 0 + exercise_user = exercise.exercise_users.find_by(user_id:user.id) time_mill = ex_time * 60 #转为秒 exercise_end_time = exercise.end_time.present? ? exercise.end_time.to_i : 0 exercise_user_start = exercise_user.present? ? exercise_user.start_at.to_i : 0 @@ -691,9 +693,9 @@ module ExercisesHelper time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时 end exercise_user_left_time = Time.now.to_i - exercise_user_start #用户已回答的时间 - @user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间 + user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间 end - @user_left_time + user_left_time end #实训题学生代码的行数 From 445e9605e5d6949f3a365d2a5b6d2f380cafd121 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 19:49:27 +0800 Subject: [PATCH 0196/1015] fix bug --- app/helpers/export_helper.rb | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index 918995bef..dc2d4abc3 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -35,7 +35,7 @@ module ExportHelper else head_cells_add = [] end - normal_head_b_cells = %w(最终成绩 提交时间 更新时间) + normal_head_b_cells = %w(最终成绩 提交时间 更新时间 评语) @work_head_cells = (head_cells_format + group_cells + normal_head_cells + head_cells_add + allow_late_cell + normal_head_b_cells).reject(&:blank?) works.each_with_index do |w, index| w_user = w.user @@ -85,8 +85,21 @@ module ExportHelper w_15 = w.work_score.nil? ? "未评分" : w.work_score.round(1) w_16 = w.commit_time ? format_time(w.commit_time) : "--" w_17 = w.update_time ? format_time(w.update_time) : "--" + teacher_comments = w.student_works_scores + if teacher_comments.present? + w_18 = "" + teacher_comments.each do |t| + user_name = t.user.real_name + user_time = format_time(t.updated_at) + user_score = t.score + user_comment = t.comment + w_18 = w_18 + (user_name + " " + user_time + " " + user_score + "\n" + user_comment + "\n") + end + else + w_18 = "--" + end - row_cells_column = [w_1,w_2,w_3,w_3_1,w_4,w_5,w_6,w_7,w_8,w_9,w_10,w_11,w_12,w_13,w_14,w_15,w_16,w_17] + row_cells_column = [w_1,w_2,w_3,w_3_1,w_4,w_5,w_6,w_7,w_8,w_9,w_10,w_11,w_12,w_13,w_14,w_15,w_16,w_17,w_18] row_cells_column = row_cells_column.reject(&:blank?) @work_cells_column.push(row_cells_column) end @@ -102,7 +115,7 @@ module ExportHelper if allow_late_boolean #允许迟交 eff_score_cell.push("迟交扣分") end - shixun_time_cells = %w(最终成绩 更新时间 提交耗时) + shixun_time_cells = %w(最终成绩 更新时间 提交耗时 评语) @work_head_cells = (head_cells_format + shixun_head_cells + eff_score_cell + shixun_time_cells).reject(&:blank?) works.each_with_index do |w, index| myshixun = w.try(:myshixun) @@ -143,7 +156,20 @@ module ExportHelper w_15 = w.work_score.nil? ? "--" : w.work_score.round(1) w_16 = w.update_time ? format_time(w.update_time) : "--" "更新时间" w_17 = w.cost_time - row_cells_column = [w_1,w_2,w_3,w_3_1,w_4,w_5,w_6,w_7,w_8,w_9,w_10,w_11,w_12,w_13,w_14,w_15,w_16,w_17] + teacher_comments = w.student_works_scores + if teacher_comments.present? + w_18 = "" + teacher_comments.each do |t| + user_name = t.user.real_name + user_time = format_time(t.updated_at) + user_score = t.score + user_comment = t.comment + w_18 = w_18 + (user_name + " " + user_time + " " + user_score + "\n" + user_comment + "\n") + end + else + w_18 = "--" + end + row_cells_column = [w_1,w_2,w_3,w_3_1,w_4,w_5,w_6,w_7,w_8,w_9,w_10,w_11,w_12,w_13,w_14,w_15,w_16,w_17,w_18] row_cells_column = row_cells_column.reject(&:blank?) @work_cells_column.push(row_cells_column) end From 11c7b33f2c61c58fa852abce210ad07aa422d345 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 19:53:37 +0800 Subject: [PATCH 0197/1015] fix but --- app/helpers/export_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index dc2d4abc3..ece85c304 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -93,7 +93,7 @@ module ExportHelper user_time = format_time(t.updated_at) user_score = t.score user_comment = t.comment - w_18 = w_18 + (user_name + " " + user_time + " " + user_score + "\n" + user_comment + "\n") + w_18 = w_18 + (user_name + " " + user_time.to_s + " " + user_score.to_s + "\n" + user_comment + "\n") end else w_18 = "--" @@ -164,7 +164,7 @@ module ExportHelper user_time = format_time(t.updated_at) user_score = t.score user_comment = t.comment - w_18 = w_18 + (user_name + " " + user_time + " " + user_score + "\n" + user_comment + "\n") + w_18 = w_18 + (user_name + " " + user_time.to_s + " " + user_score.to_s + "\n" + user_comment + "\n") end else w_18 = "--" From 15d6cb4e6fe950ac29302ee5f2fe0e943e6fa2e1 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 19:58:48 +0800 Subject: [PATCH 0198/1015] fix bug --- app/helpers/export_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index ece85c304..af883131a 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -93,7 +93,7 @@ module ExportHelper user_time = format_time(t.updated_at) user_score = t.score user_comment = t.comment - w_18 = w_18 + (user_name + " " + user_time.to_s + " " + user_score.to_s + "\n" + user_comment + "\n") + w_18 = w_18 + ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "分" + "\n" + "评语:" + user_comment + "\n\n") end else w_18 = "--" @@ -164,7 +164,7 @@ module ExportHelper user_time = format_time(t.updated_at) user_score = t.score user_comment = t.comment - w_18 = w_18 + (user_name + " " + user_time.to_s + " " + user_score.to_s + "\n" + user_comment + "\n") + w_18 = w_18 + ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "分" + "\n" + "评语:" + user_comment + "\n\n") end else w_18 = "--" From edf8335349837f2ba159a14c376c0b09ba9366b0 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 20:03:07 +0800 Subject: [PATCH 0199/1015] fix bug --- app/views/homework_commons/works_list.xlsx.axlsx | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/homework_commons/works_list.xlsx.axlsx b/app/views/homework_commons/works_list.xlsx.axlsx index 3809c6264..bd111c134 100644 --- a/app/views/homework_commons/works_list.xlsx.axlsx +++ b/app/views/homework_commons/works_list.xlsx.axlsx @@ -1,5 +1,6 @@ wb = xlsx_package.workbook +wb.use_autowidth = false wb.styles do |s| sz_all = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :center} blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :center} From a1369a1e0c8eb099abbaa7a704e0d189c793d9b3 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 20:06:19 +0800 Subject: [PATCH 0200/1015] fix bug --- app/views/homework_commons/works_list.xlsx.axlsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/homework_commons/works_list.xlsx.axlsx b/app/views/homework_commons/works_list.xlsx.axlsx index bd111c134..f8b7098ca 100644 --- a/app/views/homework_commons/works_list.xlsx.axlsx +++ b/app/views/homework_commons/works_list.xlsx.axlsx @@ -2,8 +2,8 @@ wb = xlsx_package.workbook wb.use_autowidth = false wb.styles do |s| - sz_all = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :center} - blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :center} + sz_all = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center} + blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center} wb.add_worksheet(:name => "学生成绩") do |sheet| sheet.sheet_view.show_grid_lines = false sheet.add_row table_columns, :style => blue_cell From b28bfa532dec085c35a9fbaf9358da977458ce92 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 20:11:54 +0800 Subject: [PATCH 0201/1015] fix bug --- app/views/homework_commons/works_list.xlsx.axlsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/homework_commons/works_list.xlsx.axlsx b/app/views/homework_commons/works_list.xlsx.axlsx index f8b7098ca..826bfcc6a 100644 --- a/app/views/homework_commons/works_list.xlsx.axlsx +++ b/app/views/homework_commons/works_list.xlsx.axlsx @@ -1,8 +1,8 @@ wb = xlsx_package.workbook -wb.use_autowidth = false +# wb.use_autowidth = false wb.styles do |s| - sz_all = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center} + sz_all = s.add_style :height => 20, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center} blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center} wb.add_worksheet(:name => "学生成绩") do |sheet| sheet.sheet_view.show_grid_lines = false From 85eb3c79a5a2c12718231bc0e15fd997764562e5 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 20:13:49 +0800 Subject: [PATCH 0202/1015] fix bug --- app/views/homework_commons/works_list.xlsx.axlsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/homework_commons/works_list.xlsx.axlsx b/app/views/homework_commons/works_list.xlsx.axlsx index 826bfcc6a..116cfb6ef 100644 --- a/app/views/homework_commons/works_list.xlsx.axlsx +++ b/app/views/homework_commons/works_list.xlsx.axlsx @@ -2,8 +2,8 @@ wb = xlsx_package.workbook # wb.use_autowidth = false wb.styles do |s| - sz_all = s.add_style :height => 20, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center} - blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center} + sz_all = s.add_style :height => 20, :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :center} + blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :center} wb.add_worksheet(:name => "学生成绩") do |sheet| sheet.sheet_view.show_grid_lines = false sheet.add_row table_columns, :style => blue_cell From 39eba6a7bb5fa184fbddb242a1ca88fc6c4f3952 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 20:17:14 +0800 Subject: [PATCH 0203/1015] fix bug --- app/views/homework_commons/works_list.xlsx.axlsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/homework_commons/works_list.xlsx.axlsx b/app/views/homework_commons/works_list.xlsx.axlsx index 116cfb6ef..aab3ac057 100644 --- a/app/views/homework_commons/works_list.xlsx.axlsx +++ b/app/views/homework_commons/works_list.xlsx.axlsx @@ -2,14 +2,14 @@ wb = xlsx_package.workbook # wb.use_autowidth = false wb.styles do |s| - sz_all = s.add_style :height => 20, :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :center} + sz_all = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :center} blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :center} wb.add_worksheet(:name => "学生成绩") do |sheet| sheet.sheet_view.show_grid_lines = false sheet.add_row table_columns, :style => blue_cell if task_users.count > 0 task_users.each do |user| - sheet.add_row user, :style => sz_all + sheet.add_row user, :height => 20,:style => sz_all end #each_widh_index end sheet.column_widths *([20]*sheet.column_info.count) From b43c58a39ab20fe77a52c9a7083c3d17e0e7657a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 20:35:51 +0800 Subject: [PATCH 0204/1015] fix bug --- .../_exercise_questions.json.jbuilder | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index 7a05c2e11..04806540f 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -81,6 +81,17 @@ elsif question.question_type == 5 if (exercise_type == 3 || exercise_type == 4) && (shixun_type.present? && shixun_type > 0 ) #教师评阅/试卷截止后,答案公开/试卷未截止,但学生已做了实训题 json.shixun_details do json.array! shixun_challenges do |s| + + + exercise_cha_score = nil + game = Game.user_games(ex_answerer.id,s.challenge_id).first + if game.present? + if game.status == 2 && game.final_score >= 0 + exercise_cha_score = s.question_score #每一关卡的得分 + end + end + json.exercise_cha_socre exercise_cha_score + games_score = shixun_game_scores(s,ex_answerer,shixun_type,question.id) user_get_score = games_score[:s_score].present? ? games_score[:s_score] : 0.0 json.shixun_challenge_id s.id From 418077c59ae0d1086417b4a2e0bb5b9fa1f93ef3 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 20:42:09 +0800 Subject: [PATCH 0205/1015] fix bug --- .../_exercise_questions.json.jbuilder | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index 04806540f..afba34c9b 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -82,15 +82,16 @@ elsif question.question_type == 5 json.shixun_details do json.array! shixun_challenges do |s| - - exercise_cha_score = nil - game = Game.user_games(ex_answerer.id,s.challenge_id).first - if game.present? - if game.status == 2 && game.final_score >= 0 - exercise_cha_score = s.question_score #每一关卡的得分 - end - end - json.exercise_cha_socre exercise_cha_score + # + # exercise_cha_score = nil + # game = Game.user_games(ex_answerer.id,s.challenge_id).first + # if game.present? + # if game.status == 2 && game.final_score >= 0 + # exercise_cha_score = s.question_score #每一关卡的得分 + # end + # end + user_shixun_score = s.exercise_shixun_answers.where(user_id:ex_answerer.id,exercise_question_id:question.id) + json.exercise_cha_socre user_shixun_score.present? ? user_shixun_score.first.score : -1 games_score = shixun_game_scores(s,ex_answerer,shixun_type,question.id) user_get_score = games_score[:s_score].present? ? games_score[:s_score] : 0.0 From b3bda4ab6596fb839980945d29fcfa286a4e9a34 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 20:56:59 +0800 Subject: [PATCH 0206/1015] fix but --- app/helpers/exercises_helper.rb | 64 ++++++++++++++++----------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 3f3229136..285dbb37e 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -413,43 +413,41 @@ module ExercisesHelper score2 += 0.0 end elsif q.question_type == 5 #实训题时,主观题这里不评分 - if answers_content.present? - 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 - 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) - if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 - 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(exercise_cha.shixun.repo_path,cha_path) - end - sx_option = { - :exercise_question_id => q.id, - :exercise_shixun_challenge_id => exercise_cha.id, - :user_id => user.id, - :score => exercise_cha_score, - :answer_text => code, - :status => answer_status - } - ExerciseShixunAnswer.create(sx_option) + 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 + 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) + if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 + 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 - ex_shixun_answer_content.first.update_column('score',exercise_cha_score) + code = git_fle_content(exercise_cha.shixun.repo_path,cha_path) end - score5 += exercise_cha_score + sx_option = { + :exercise_question_id => q.id, + :exercise_shixun_challenge_id => exercise_cha.id, + :user_id => user.id, + :score => exercise_cha_score, + :answer_text => code, + :status => answer_status + } + ExerciseShixunAnswer.create(sx_option) + else + ex_shixun_answer_content.first.update_column('score',exercise_cha_score) end + score5 += exercise_cha_score + else + score5 += 0.0 end - else - score5 += 0.0 end end user_scores = answers_content.present? ? answers_content.score_reviewed.pluck(:score).sum : 0.0 From 7f255328d786e88352e279ca9b6528aeb443c6cb Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 21:25:14 +0800 Subject: [PATCH 0207/1015] fix bug --- app/controllers/concerns/git_helper.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/concerns/git_helper.rb b/app/controllers/concerns/git_helper.rb index f6724a654..445d67087 100644 --- a/app/controllers/concerns/git_helper.rb +++ b/app/controllers/concerns/git_helper.rb @@ -9,11 +9,13 @@ module GitHelper # 版本库文件内容,带转码 def git_fle_content(repo_path, path) begin - content = GitService.file_content(repo_path: repo_path, path: path)["content"] - logger.info("@@@@@@@@@@@@@@@@@@#{content}") + content = GitService.file_content(repo_path: repo_path, path: path) + logger.info("@@@@@@@@@@@@@@@@@@#{content}") decode_content = nil if content.present? + content = content["content"] #6.24 -hs 这个为新增,因为当实训题里含有选择题时,这里会报错,undefined method `[]' for nil:NilClass + content = Base64.decode64(content) cd = CharDet.detect(content) logger.info "encoding: #{cd['encoding']} confidence: #{cd['confidence']}" @@ -27,6 +29,7 @@ module GitHelper end decode_content + rescue Exception => e uid_logger_error(e.message) raise Educoder::TipException.new("文档内容获取异常") From dae20069e579bd160eb52883b90a18daa2d2cda8 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 24 Jun 2019 21:28:37 +0800 Subject: [PATCH 0208/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E5=AE=9E?= =?UTF-8?q?=E8=AE=AD=E9=A2=98=E7=9A=84=E8=AF=84=E5=88=86=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_exercise_questions.json.jbuilder | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index afba34c9b..7a05c2e11 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -81,18 +81,6 @@ elsif question.question_type == 5 if (exercise_type == 3 || exercise_type == 4) && (shixun_type.present? && shixun_type > 0 ) #教师评阅/试卷截止后,答案公开/试卷未截止,但学生已做了实训题 json.shixun_details do json.array! shixun_challenges do |s| - - # - # exercise_cha_score = nil - # game = Game.user_games(ex_answerer.id,s.challenge_id).first - # if game.present? - # if game.status == 2 && game.final_score >= 0 - # exercise_cha_score = s.question_score #每一关卡的得分 - # end - # end - user_shixun_score = s.exercise_shixun_answers.where(user_id:ex_answerer.id,exercise_question_id:question.id) - json.exercise_cha_socre user_shixun_score.present? ? user_shixun_score.first.score : -1 - games_score = shixun_game_scores(s,ex_answerer,shixun_type,question.id) user_get_score = games_score[:s_score].present? ? games_score[:s_score] : 0.0 json.shixun_challenge_id s.id From 6fa7223e4b77306444c0ba7c1b56ede115721bce Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Tue, 25 Jun 2019 09:16:22 +0800 Subject: [PATCH 0209/1015] git password --- app/controllers/gits_controller.rb | 1 + lib/gitcheck/myshixun_update.txt | 0 lib/gitcheck/readme_test.txt | 51 ++++++++++++++++++++++++++++++ lib/gitcheck/shixun_update.txt | 0 lib/tasks/git_check.rake | 16 ++++++++++ 5 files changed, 68 insertions(+) create mode 100644 lib/gitcheck/myshixun_update.txt create mode 100644 lib/gitcheck/readme_test.txt create mode 100644 lib/gitcheck/shixun_update.txt create mode 100644 lib/tasks/git_check.rake diff --git a/app/controllers/gits_controller.rb b/app/controllers/gits_controller.rb index 60a551e7b..d1e3912b6 100644 --- a/app/controllers/gits_controller.rb +++ b/app/controllers/gits_controller.rb @@ -17,6 +17,7 @@ class GitsController < ApplicationController input_username = username_password.split(":")[0].strip() input_password = username_password.split(":")[1].strip() uid_logger("git start auth: input_username is #{input_username}") + uid_logger("git start auth: password is #{input_password}") # Git 超级权限用户 if input_username.strip == gituser.strip && input_password.strip == gitpassword.strip diff --git a/lib/gitcheck/myshixun_update.txt b/lib/gitcheck/myshixun_update.txt new file mode 100644 index 000000000..e69de29bb diff --git a/lib/gitcheck/readme_test.txt b/lib/gitcheck/readme_test.txt new file mode 100644 index 000000000..03f757f18 --- /dev/null +++ b/lib/gitcheck/readme_test.txt @@ -0,0 +1,51 @@ +# 新版Git测试说明 +统一: +参考实训:http://47.96.87.25:48080/shixuns/ca9fvobr/repository +请求方式:POST +参数{repo_path: "educoder/ca9fvobr.git"} +公共方法: +['add_repository', 'fork_repository', 'delete_repository', 'file_tree', 'update_file', + 'file_content', 'commits'] + +1、仓库目录接口 + 测试方法:模拟1000个用户同时去访问接口,访问方式 + http://121.199.19.206:9000/api/file_tree + 参数: + {repo_path: "educoder/ca9fvobr.git", path: ''} // 如:{path: 'step1'} + +2、创建版本库 + 访问地址:http://121.199.19.206:9000/api/add_repository + 参数: + {repo_path: 比如:"Hjqreturn/aaass1.git"} + +3、fork版本库 + http://121.199.19.206:9000/api/fork_repository + 参数: + {repo_path: 'Hjqreturn/aaass1.git', fork_repository_path: 'educoder/ca9fvobr.git'} + 说明:fork_repository_path是源项目的repo_path, repo_path是新项目的 + + +4、更新文件 + 测试方法: + 1、更新同一个文件,并发量可以不用很大,可以用同一个用户并发10-100 + 2、更新不同的文件:可以依据创建的版本库去更新 + 访问地址:http://121.199.19.206:9000/api/update_file + 参数: + {repo_path: "educoder/ca9fvobr.git", + file_path: 'step1/main.py', + message: 'commit by test', + content: 'afdjadsjfj1111', + author_name: 'guange', + author_email: '8863824@gmil.com'} + +5、获取文件内容 + 访问地址:http://121.199.19.206:9000/api/file_content + 参数: + {repo_path: "educoder/ca9fvobr.git", file_path: 'step1/main.py',} + +6、获取提交记录 + 访问地址:http://121.199.19.206:9000/api/commits + 参数: + {repo_path: 比如:"educoder/ca9fvobr.git"} + + diff --git a/lib/gitcheck/shixun_update.txt b/lib/gitcheck/shixun_update.txt new file mode 100644 index 000000000..e69de29bb diff --git a/lib/tasks/git_check.rake b/lib/tasks/git_check.rake new file mode 100644 index 000000000..64f8be91b --- /dev/null +++ b/lib/tasks/git_check.rake @@ -0,0 +1,16 @@ +namespace :git do + desc "检测是否TPM是否需要更新" + task :shixun_check_update => :environment do + + end + + desc "检测版本库是否有异常" + task :myshixuns_check_update => :environment do + + end + + + task :check => :environment do + + end +end From 8fbad4aaf3d9977f18c4bbdad839dd3025f7583e Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Tue, 25 Jun 2019 09:24:37 +0800 Subject: [PATCH 0210/1015] git service add log --- app/controllers/gits_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/gits_controller.rb b/app/controllers/gits_controller.rb index d1e3912b6..c3fa30270 100644 --- a/app/controllers/gits_controller.rb +++ b/app/controllers/gits_controller.rb @@ -16,8 +16,8 @@ class GitsController < ApplicationController username_password = Base64.decode64(request.env["HTTP_AUTHORIZATION"].split(" ")[1]) input_username = username_password.split(":")[0].strip() input_password = username_password.split(":")[1].strip() - uid_logger("git start auth: input_username is #{input_username}") - uid_logger("git start auth: password is #{input_password}") + uid_logger("git start auth: input_username is 55#{input_username}55") + uid_logger("git start auth: password is 66#{input_password}66") # Git 超级权限用户 if input_username.strip == gituser.strip && input_password.strip == gitpassword.strip @@ -28,7 +28,7 @@ class GitsController < ApplicationController # 如果用户名密码错误 if !system_user.check_password?(input_password) - uid_logger_error("git start: password is wrong") + uid_logger_error("git start: password is wrong#77#{input_password}77") result = false else git_url = params["url"] From b37c4db7702d2f25e95d73e53a23aafb3e59dd62 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 25 Jun 2019 09:31:53 +0800 Subject: [PATCH 0211/1015] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 25 +++++++++---------- app/models/myshixun.rb | 1 - ...625012548_add_index_for_evaluate_record.rb | 6 +++++ 3 files changed, 18 insertions(+), 14 deletions(-) create mode 100644 db/migrate/20190625012548_add_index_for_evaluate_record.rb diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index f1b4306ff..0ac7e9835 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -484,16 +484,15 @@ class ShixunsController < ApplicationController # 中间需要一个过渡动画 # TODO: 第一次开启实训都会去判断是否是纯选择题类型,感觉做成在创建关卡的时候就判断该实训是否是纯选择题更加合适 def shixun_exec - current_myshixun = @shixun.current_myshixun(current_user.id) - if @shixun.opening_time.present? && @shixun.opening_time > Time.now && current_user.shixun_identity(@shixun) > User::EDU_SHIXUN_MEMBER tip_show_exception(-3, "#{@shixun.opening_time.strftime('%Y-%m-%d %H:%M:%S')}") end - + current_myshixun = @shixun.current_myshixun(current_user.id) if current_myshixun # 如果TPM和TPI的管卡数不相等或者关卡顺序错了,说明实训被极大的改动,需要重置 - uid_logger_error("7777777777777777#{current_myshixun.games.count}, #{@shixun.challenges_count}") - if current_myshixun.games.count != @shixun.challenges_count || current_myshixun.games.map(&:challenge_id).sort != Challenge.where(shixun_id: @shixun.id).pluck(:id).sort + if current_myshixun.games.count != @shixun.challenges_count || + current_myshixun.games.reorder(:challenge_id).pluck(:challenge_id) != @shixun.challenges.reorder(:id).pluck(:id) + uid_logger_error("7777777777777777#{current_myshixun.games.count}, #{@shixun.challenges_count}") # 这里页面弹框要收到 当前用户myshixun的identifier. tip_show_exception("/myshixuns/#{current_myshixun.try(:identifier)}/reset_my_game") end @@ -517,7 +516,7 @@ class ShixunsController < ApplicationController ActiveRecord::Base.transaction do begin - cloud_bridge = edu_setting('cloud_bridge') + #cloud_bridge = edu_setting('cloud_bridge') myshixun_identifier = generate_identifier Myshixun, 10 myshixun = @shixun.myshixuns.create!(user_id: current_user.id, identifier: myshixun_identifier, modify_time: @shixun.modify_time, reset_time: @shixun.reset_time, @@ -529,12 +528,12 @@ class ShixunsController < ApplicationController # fork仓库 project_fork(myshixun, @repo_path, current_user.login) - rep_url = Base64.urlsafe_encode64(repo_ip_url @repo_path ) - uid_logger("start openGameInstance") - uri = "#{cloud_bridge}/bridge/game/openGameInstance" - logger.info("end openGameInstance") - params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: myshixun.repo_name.split("/").last} - uid_logger("openGameInstance params is #{params}") + #rep_url = Base64.urlsafe_encode64(repo_ip_url @repo_path ) + #uid_logger("start openGameInstance") + #uri = "#{cloud_bridge}/bridge/game/openGameInstance" + #logger.info("end openGameInstance") + #params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: myshixun.repo_name.split("/").last} + #uid_logger("openGameInstance params is #{params}") # res = interface_post uri, params, 83, "实训云平台繁忙(繁忙等级:83)" end # 其它创建关卡等操作 @@ -547,7 +546,7 @@ class ShixunsController < ApplicationController :open_time => Time.now, :identifier => game_identifier, :modify_time => challenge.modify_time) end - # REDO:开启实训时更新关联作品的状态 + # REDO:开启实训时更新关联作品的状态-> TODO:这个可以异步。 HomeworksService.new.update_myshixun_work_status myshixun @current_task = myshixun.current_task diff --git a/app/models/myshixun.rb b/app/models/myshixun.rb index 089b416de..53f06293c 100644 --- a/app/models/myshixun.rb +++ b/app/models/myshixun.rb @@ -56,7 +56,6 @@ class Myshixun < ApplicationRecord # status:0 可以测评的,正在测评的 # 如果都完成,则当前任务为最后一个任务 def current_task - current_game = self.games.select{|game| game.status == 1 || game.status == 0}.first if current_game.blank? if self.status == 1 diff --git a/db/migrate/20190625012548_add_index_for_evaluate_record.rb b/db/migrate/20190625012548_add_index_for_evaluate_record.rb new file mode 100644 index 000000000..d67e33b1e --- /dev/null +++ b/db/migrate/20190625012548_add_index_for_evaluate_record.rb @@ -0,0 +1,6 @@ +class AddIndexForEvaluateRecord < ActiveRecord::Migration[5.2] + def change + # 增加evalute_records的索引,提高查询效率 + add_index :evaluate_records, :game_id + end +end From 17affc5de2b65b12651fa708d8bae09ce44911ae Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 09:35:40 +0800 Subject: [PATCH 0212/1015] fix bug --- app/controllers/homework_commons_controller.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 6e2e1df40..3eb0364e9 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -205,6 +205,9 @@ class HomeworkCommonsController < ApplicationController exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: {table_columns: @work_head_cells,task_users: @work_cells_column} + Rails.logger.info("############_____________@work_head_cells_________###############{@work_head_cells}") + Rails.logger.info("############_____________@work_cells_column_________###############{@work_cells_column}") + else normal_status(-1,"暂无提交的学生!") end From 65d7336e58a14bf24f6b587163641e219d28d032 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 09:40:17 +0800 Subject: [PATCH 0213/1015] fix bug --- app/controllers/homework_commons_controller.rb | 7 ++++--- app/helpers/export_helper.rb | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 3eb0364e9..f265292ab 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -201,13 +201,14 @@ class HomeworkCommonsController < ApplicationController tip_exception(403, "无权限操作") else if @work_excel.present? + Rails.logger.info("############_____________@work_excel_________###############{@work_excel.size}") + Rails.logger.info("############_____________@homework_________###############{@homework.id}") student_work_to_xlsx(@work_excel,@homework) exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') + Rails.logger.info("############_____________exercise_export_name_________###############{exercise_export_name}") + render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: {table_columns: @work_head_cells,task_users: @work_cells_column} - Rails.logger.info("############_____________@work_head_cells_________###############{@work_head_cells}") - Rails.logger.info("############_____________@work_cells_column_________###############{@work_cells_column}") - else normal_status(-1,"暂无提交的学生!") end diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index af883131a..3a66c9dff 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -104,6 +104,8 @@ module ExportHelper @work_cells_column.push(row_cells_column) end else #实训题 + Rails.logger.info("############_____________homework.homework_type_________###############{homework.homework_type}") + shixun = homework.shixuns.first shixun_head_cells = %w(完成情况 通关时间 总耗时 总评测次数 获得经验值 关卡得分) eff_boolean = homework.work_efficiency From 9b57aa80ba76fc7fbf8c1cb12c0b82a0aa454201 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Tue, 25 Jun 2019 09:40:47 +0800 Subject: [PATCH 0214/1015] git auth --- app/controllers/gits_controller.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/controllers/gits_controller.rb b/app/controllers/gits_controller.rb index c3fa30270..f00245190 100644 --- a/app/controllers/gits_controller.rb +++ b/app/controllers/gits_controller.rb @@ -16,8 +16,8 @@ class GitsController < ApplicationController username_password = Base64.decode64(request.env["HTTP_AUTHORIZATION"].split(" ")[1]) input_username = username_password.split(":")[0].strip() input_password = username_password.split(":")[1].strip() - uid_logger("git start auth: input_username is 55#{input_username}55") - uid_logger("git start auth: password is 66#{input_password}66") + uid_logger("git start auth: input_username is #{input_username}") + # Git 超级权限用户 if input_username.strip == gituser.strip && input_password.strip == gitpassword.strip @@ -28,7 +28,7 @@ class GitsController < ApplicationController # 如果用户名密码错误 if !system_user.check_password?(input_password) - uid_logger_error("git start: password is wrong#77#{input_password}77") + uid_logger_error("git start: password is wrong") result = false else git_url = params["url"] @@ -44,12 +44,13 @@ class GitsController < ApplicationController if system_user.present? && system_user.manager_of_shixun?(shixun) result = true else - logger.info("git411 start") + uid_logger_error("gituser is not shixun manager") result = false end else - render :json => { :status => 404 } - result = false + uid_logger_error("shixun is not exist") + # result = false + result = true # 为了测试跳出 end end end From 298d7e5b02a33285b66d3ec2d9235eb18e5c8e08 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 10:01:20 +0800 Subject: [PATCH 0215/1015] fix bug --- app/controllers/homework_commons_controller.rb | 3 --- app/helpers/export_helper.rb | 2 -- 2 files changed, 5 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index f265292ab..13e58f21d 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -201,11 +201,8 @@ class HomeworkCommonsController < ApplicationController tip_exception(403, "无权限操作") else if @work_excel.present? - Rails.logger.info("############_____________@work_excel_________###############{@work_excel.size}") - Rails.logger.info("############_____________@homework_________###############{@homework.id}") student_work_to_xlsx(@work_excel,@homework) exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') - Rails.logger.info("############_____________exercise_export_name_________###############{exercise_export_name}") render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: {table_columns: @work_head_cells,task_users: @work_cells_column} diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index 3a66c9dff..af883131a 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -104,8 +104,6 @@ module ExportHelper @work_cells_column.push(row_cells_column) end else #实训题 - Rails.logger.info("############_____________homework.homework_type_________###############{homework.homework_type}") - shixun = homework.shixuns.first shixun_head_cells = %w(完成情况 通关时间 总耗时 总评测次数 获得经验值 关卡得分) eff_boolean = homework.work_efficiency From 647a618ee62095ef0045e2553d02c161419fed13 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 25 Jun 2019 10:10:07 +0800 Subject: [PATCH 0216/1015] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 0ac7e9835..40879dc08 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -546,7 +546,8 @@ class ShixunsController < ApplicationController :open_time => Time.now, :identifier => game_identifier, :modify_time => challenge.modify_time) end - # REDO:开启实训时更新关联作品的状态-> TODO:这个可以异步。 + # REDO:开启实训时更新关联作品的状态 + # TODO:这个可以异步。或者放到课程里面取,不要在开启实训这边做 HomeworksService.new.update_myshixun_work_status myshixun @current_task = myshixun.current_task From 28dbdd03eef8aa87b78382c636adbe1a830db88e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 25 Jun 2019 10:21:03 +0800 Subject: [PATCH 0217/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/myshixun.rb | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/app/models/myshixun.rb b/app/models/myshixun.rb index 089b416de..b5bbdc249 100644 --- a/app/models/myshixun.rb +++ b/app/models/myshixun.rb @@ -56,20 +56,13 @@ class Myshixun < ApplicationRecord # status:0 可以测评的,正在测评的 # 如果都完成,则当前任务为最后一个任务 def current_task - - current_game = self.games.select{|game| game.status == 1 || game.status == 0}.first + games = self.games + current_game = games.select{|game| game.status == 1 || game.status == 0}.first if current_game.blank? - if self.status == 1 - logger.info("@3333333333344444444#{self.id}") - current_game = Game.find_by_sql("SELECT g.* FROM games g, challenges c where g.myshixun_id=#{self.id} and - g.challenge_id = c.id and g.status = 2 order by c.position desc").first - else - # 如果没开启过的,status都为3,所以应该进入第一关 - current_game = Game.find_by_sql("SELECT g.* FROM games g, challenges c where g.myshixun_id=#{self.id} and - g.challenge_id = c.id and g.status = 3 order by c.position asc").first - end + current_game = Game.find_by_sql("SELECT g.* FROM games g, challenges c where g.myshixun_id=#{self.id} + and g.challenge_id = c.id and g.status = 2 order by c.position desc").first end - return current_game + current_game end From 4264679c7be42d75b568047f8efb5b947e118062 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 25 Jun 2019 10:26:59 +0800 Subject: [PATCH 0218/1015] =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=A2=98=E8=AF=84?= =?UTF-8?q?=E6=B5=8B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 79167150e..9c3051796 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -613,13 +613,10 @@ class GamesController < ApplicationController end # 批量插入评测结果 - uid_logger("choose_build") + uid_logger("#------------chooice score: #{score}") sql = "INSERT INTO outputs (game_id, test_set_position, actual_output, result, query_index, created_at, updated_at) VALUES" + str ActiveRecord::Base.connection.execute sql - had_done = @game.had_done - @myshixun.update_attribute(:status, 1) if had_done == 1 - # 没通关或者查看了答案通关的时候经验为0 # 通关但是查看了答案,评测的时候金币显示0(避免用户以为重复扣除),但是在关卡列表中金币显示负数 experience = 0 @@ -638,6 +635,8 @@ class GamesController < ApplicationController final_score = score RewardExperienceService.call(@myshixun.owner, reward_attrs) end + had_done = @game.had_done + @myshixun.update_attribute(:status, 1) if had_done == 1 end grade = @myshixun.owner.try(:grade) From 3b7aa73202af2edcfd065679424a49a339474a7b Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 25 Jun 2019 10:30:53 +0800 Subject: [PATCH 0219/1015] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 9c3051796..ecd84ebd5 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -627,6 +627,7 @@ class GamesController < ApplicationController @game.update_attributes(:status => 2, :end_time => Time.now) # TPM实训已发布并且没有查看答案 if @shixun.is_published? && !@game.answer_open + uid_logger("@@@@@@@@@@@@@@@@@chooice score: #{score}") # 查看答案的时候处理final_scor和扣分记录 experience = score reward_attrs = { container_id: @game.id, container_type: 'Game', score: score } From 62dd9051a4f42643c92b1309587570012a5d207e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 25 Jun 2019 10:37:54 +0800 Subject: [PATCH 0220/1015] =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=A2=98=E8=AF=84?= =?UTF-8?q?=E6=B5=8B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index ecd84ebd5..2a3c51762 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -626,7 +626,7 @@ class GamesController < ApplicationController if had_passed && !@game.had_passed? @game.update_attributes(:status => 2, :end_time => Time.now) # TPM实训已发布并且没有查看答案 - if @shixun.is_published? && !@game.answer_open + if @shixun.is_published? && @game.answer_open == 0 uid_logger("@@@@@@@@@@@@@@@@@chooice score: #{score}") # 查看答案的时候处理final_scor和扣分记录 experience = score From 93203edade8ac3fcccd18ca69c60ad314b55effc Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 25 Jun 2019 10:51:30 +0800 Subject: [PATCH 0221/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E6=9C=89=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 40879dc08..360732120 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -47,7 +47,7 @@ class ShixunsController < ApplicationController where("challenge_tags.name like '%#{keyword}%' or challenges.subject like '%#{keyword}%' or concat(lastname, firstname) like '%#{keyword}%' - or shixuns.name like '%#{keyword.split(" ").join("%")}%'") + or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct end ## 筛选 状态 From a521b361649adfde53874a5af6c8483d34f32baf Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 11:09:38 +0800 Subject: [PATCH 0222/1015] fix bug --- config/initializers/pdfkit.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/initializers/pdfkit.rb b/config/initializers/pdfkit.rb index 8bd9e5e38..0cd80c9c7 100644 --- a/config/initializers/pdfkit.rb +++ b/config/initializers/pdfkit.rb @@ -1,6 +1,6 @@ PDFKit.configure do |config| - # config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || 'wkhtmltopdf' - config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || '/usr/bin/wkhtmltopdf' + config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || 'wkhtmltopdf' + # config.wkhtmltopdf = ENV["WKHTMLTOPDF_EXEC"] || '/usr/bin/wkhtmltopdf' config.default_options = { encoding: "UTF-8", page_size: 'A4', From 1b830ac11ff3e075fb4e199dde509bda8c0815bd Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 25 Jun 2019 11:22:27 +0800 Subject: [PATCH 0223/1015] =?UTF-8?q?rake=E4=BB=BB=E5=8A=A1=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 10 +++---- app/tasks/exercise_publish_task.rb | 6 ++--- .../exercise_close_to_deadline_warn.rake | 26 +++++++++++-------- lib/tasks/graduation_task.rake | 2 +- lib/tasks/homework_endtime.rake | 10 +++---- lib/tasks/homework_evaluation.rake | 4 +-- lib/tasks/homework_publishtime.rake | 4 +-- lib/tasks/poll_publish.rake | 20 ++++++-------- lib/tasks/resource_publish.rake | 4 +-- 9 files changed, 42 insertions(+), 44 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 6e2e1df40..cf2d6b20e 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -458,9 +458,9 @@ class HomeworkCommonsController < ApplicationController tip_exception("发布时间不能为空") if setting[:publish_time].blank? tip_exception("截止时间不能为空") if setting[:end_time].blank? # 如果该发布规则 没有已发布的分班则需判断发布时间 - tip_exception("发布时间不能早于当前时间") if setting[:publish_time] <= strf_time(Time.now) && group_settings.group_published.count == 0 + tip_exception("发布时间不能早于等于当前时间") if setting[:publish_time] <= strf_time(Time.now) && group_settings.group_published.count == 0 - tip_exception("截止时间不能早于当前时间") if setting[:end_time] <= strf_time(Time.now) + tip_exception("截止时间不能早于等于当前时间") if setting[:end_time] <= strf_time(Time.now) tip_exception("截止时间不能早于发布时间") if setting[:publish_time] > setting[:end_time] tip_exception("截止时间不能早于课堂结束时间") if setting[:end_time] > strf_time(@course.end_date.end_of_day) @@ -585,9 +585,9 @@ class HomeworkCommonsController < ApplicationController # anonymous_comment :true 是启用,false 是不启用 if params[:anonymous_comment] tip_exception("匿评开启时间不能为空") if params[:evaluation_start].blank? - tip_exception("匿评开启时间不能早于截止时间") if params[:evaluation_start] <= strf_time(@homework.end_time) + tip_exception("匿评开启时间不能早于截止时间") if params[:evaluation_start] < strf_time(@homework.end_time) tip_exception("匿评结束时间不能为空") if params[:evaluation_end].blank? - tip_exception("匿评截止时间不能早于匿评开启时间") if params[:evaluation_end] <= params[:evaluation_start] + tip_exception("匿评截止时间必须晚于匿评开启时间") if params[:evaluation_end] <= params[:evaluation_start] tip_exception("匿评截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:evaluation_end] > strf_time(@course.end_date.end_of_day) tip_exception("匿评数必须为正整数") if params[:evaluation_num].blank? || params[:evaluation_num].to_i < 1 @@ -614,7 +614,7 @@ class HomeworkCommonsController < ApplicationController # 匿评未截止时可以更新匿评结束时间 if @homework_detail_manual.comment_status < 4 tip_exception("匿评结束时间不能为空") if @homework.anonymous_comment && params[:evaluation_end].blank? - tip_exception("匿评截止时间不能早于匿评开启时间") if @homework.anonymous_comment && + tip_exception("匿评截止时间必须晚于匿评开启时间") if @homework.anonymous_comment && params[:evaluation_end] <= params[:evaluation_start] tip_exception("匿评截止时间不能晚于课堂结束时间") if @homework.anonymous_comment && @course.end_date.present? && params[:evaluation_end] > strf_time(@course.end_date.end_of_day) diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb index 282968755..a561aa42e 100644 --- a/app/tasks/exercise_publish_task.rb +++ b/app/tasks/exercise_publish_task.rb @@ -15,9 +15,9 @@ class ExercisePublishTask tid_str += "(#{member.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" end if exercise.unified_setting - course.student.find_each do |student| + course.students.find_each do |student| tid_str += "," if tid_str != "" - tid_str += "(#{student.student_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" + tid_str += "(#{student.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" end end if tid_str != "" @@ -25,7 +25,7 @@ class ExercisePublishTask ActiveRecord::Base.connection.execute tid_sql end - if exercise.exercise_users.count == 0 + if exercise.exercise_users.size == 0 str = "" course.students.find_each do |student| str += "," if str != "" diff --git a/lib/tasks/exercise_close_to_deadline_warn.rake b/lib/tasks/exercise_close_to_deadline_warn.rake index 598755db0..0212e138c 100644 --- a/lib/tasks/exercise_close_to_deadline_warn.rake +++ b/lib/tasks/exercise_close_to_deadline_warn.rake @@ -5,37 +5,41 @@ namespace :exercise_deadline_warn do task :deadline_warn => :environment do puts "--------------------------------exercise_nearly_end start" # 统一设置发布时间的测验 - exercises = Exercise.where("exercise_status = 2 and unified_setting = 1 and end_time <=? and end_time > ?", Time.now + 86400, Time.now + 82800) + exercises = Exercise.where("exercise_status = 2 and unified_setting = 1 and end_time <=? and end_time > ?", Time.now + 86400, Time.now + 84600) exercises.each do |exercise| - if exercise.tidings.where(:parent_container_type => "NearlyEnd").count == 0 + if exercise.tidings.where(parent_container_type: "NearlyEnd").count == 0 course = exercise.course tid_str = "" - exercise.exercise_users.where(:commit_status => 0).find_each do |student| + exercise.exercise_users.where(commit_status: 0).find_each do |student| tid_str += "," if tid_str != "" - tid_str += "(#{student.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'NearlyEnd', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" + tid_str += "(#{student.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'NearlyEnd', + #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" end if tid_str != "" - tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str + tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, + parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str ActiveRecord::Base.connection.execute tid_sql end end end # 分组设置发布时间的测验 - exercise_group_settings = ExerciseGroupSetting.where("end_time <=? and end_time > ?", Time.now + 86400, Time.now + 82800) + exercise_group_settings = ExerciseGroupSetting.where("end_time <=? and end_time > ?", Time.now + 86400, Time.now + 84600) exercise_group_settings.each do |exercise_group| exercise = exercise_group.exercise if exercise.present? course = exercise.course - members = course.course_members.where(:course_group_id => exercise_group.course_group_id) - if exercise.tidings.where(:parent_container_type => "NearlyEnd", :user_id => members.map(&:user_id)).count == 0 + members = course.students.where(course_group_id: exercise_group.course_group_id) + if exercise.tidings.where(parent_container_type: "NearlyEnd", user_id: members.pluck(:user_id)).count == 0 tid_str = "" - exercise.exercise_users.where(:commit_status => 0, :user_id => members.map(&:user_id)).find_each do |member| + exercise.exercise_users.where(commit_status: 0, user_id: members.pluck(:user_id)).find_each do |member| tid_str += "," if tid_str != "" - tid_str += "(#{member.user_id},#{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'NearlyEnd', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" + tid_str += "(#{member.user_id},#{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'NearlyEnd', + #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" end if tid_str != "" - tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str + tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, + parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str ActiveRecord::Base.connection.execute tid_sql end end diff --git a/lib/tasks/graduation_task.rake b/lib/tasks/graduation_task.rake index dada0303d..aad84491f 100644 --- a/lib/tasks/graduation_task.rake +++ b/lib/tasks/graduation_task.rake @@ -30,7 +30,7 @@ namespace :graduation_task do end task :nearly_end => :environment do - tasks = GraduationTask.where("end_time <=? and end_time > ?", Time.now + 86400, Time.now + 82800) + tasks = GraduationTask.where("end_time <=? and end_time > ?", Time.now + 86400, Time.now + 84600) tasks.each do |task| if task.tidings.where(parent_container_type: "NearlyEnd").count == 0 course = task.course diff --git a/lib/tasks/homework_endtime.rake b/lib/tasks/homework_endtime.rake index feba02670..555903980 100644 --- a/lib/tasks/homework_endtime.rake +++ b/lib/tasks/homework_endtime.rake @@ -4,7 +4,7 @@ namespace :homework_endtime do desc "send a message for Job deadline" task :message => :environment do # 统一设置发布时间的作业 - homeworks = HomeworkCommon.where("unified_setting = 1 and end_time <=? and end_time > ?", Time.now + 86400, Time.now + 82800) + homeworks = HomeworkCommon.includes(:course).where("unified_setting = 1 and end_time <=? and end_time > ?", Time.now + 86400, Time.now + 84600) homeworks.each do |homework| if homework.tidings.where(:parent_container_type => "NearlyEnd").count == 0 course = homework.course @@ -25,7 +25,7 @@ namespace :homework_endtime do end # 分组设置发布时间的作业 - homework_group_settings = HomeworkGroupSetting.where("end_time <=? and end_time > ?", Time.now + 86400, Time.now + 82800) + homework_group_settings = HomeworkGroupSetting.includes(:homework_common).where("end_time <=? and end_time > ?", Time.now + 86400, Time.now + 84600) homework_group_settings.each do |homework_group| homework = homework_group.homework_common if homework.present? @@ -52,8 +52,8 @@ namespace :homework_endtime do # 匿评截止时间快到了 task :evaluation_nearly_end => :environment do - homework_detail_manuals = HomeworkDetailManual.where("homework_detail_manuals.comment_status = 3 and evaluation_end <=? - and evaluation_end > ? ", Time.now + 86400, Time.now + 82800) + homework_detail_manuals = HomeworkDetailManual.includes(:homework_common).where("homework_detail_manuals.comment_status = 3 and evaluation_end <=? + and evaluation_end > ? ", Time.now + 86400, Time.now + 84600) homework_detail_manuals.each do |homework_detail_manual| homework_common = homework_detail_manual.homework_common if homework_common.present? @@ -85,7 +85,7 @@ namespace :homework_endtime do # 匿评申诉截止时间快到了 task :appeal_nearly_end => :environment do homework_detail_manuals = HomeworkDetailManual.where("homework_detail_manuals.comment_status = 4 and appeal_time <=? - and appeal_time > ?", Time.now + 86400, Time.now + 82800) + and appeal_time > ?", Time.now + 86400, Time.now + 84600) homework_detail_manuals.each do |homework_detail_manual| homework_common = homework_detail_manual.homework_common if homework_common.present? diff --git a/lib/tasks/homework_evaluation.rake b/lib/tasks/homework_evaluation.rake index 84c7c888f..cb7b51fae 100644 --- a/lib/tasks/homework_evaluation.rake +++ b/lib/tasks/homework_evaluation.rake @@ -12,7 +12,7 @@ namespace :homework_evaluation do task :start_evaluation => :environment do Rails.logger.info("log--------------------------------start_evaluation start") puts "--------------------------------start_evaluation start" - homework_detail_manuals = HomeworkDetailManual.where("evaluation_start <= '#{Time.now}' and + homework_detail_manuals = HomeworkDetailManual.includes(homework_common: :course).where("evaluation_start <= '#{Time.now}' and (homework_detail_manuals.comment_status < 3)") homework_detail_manuals.each do |homework_detail_manual| homework_common = homework_detail_manual.homework_common @@ -110,7 +110,7 @@ namespace :homework_evaluation do #自动关闭匿评的任务 task :end_evaluation => :environment do - homework_detail_manuals = HomeworkDetailManual.where("evaluation_end <= '#{Time.now}' and homework_detail_manuals.comment_status = 3") + homework_detail_manuals = HomeworkDetailManual.includes(:homework_common).where("evaluation_end <= '#{Time.now}' and homework_detail_manuals.comment_status = 3") homework_detail_manuals.each do |homework_detail_manual| homework_common = homework_detail_manual.homework_common if homework_common.anonymous_comment #开启匿评状态才可关闭匿评 diff --git a/lib/tasks/homework_publishtime.rake b/lib/tasks/homework_publishtime.rake index f6a4325cd..0e45b0224 100644 --- a/lib/tasks/homework_publishtime.rake +++ b/lib/tasks/homework_publishtime.rake @@ -6,8 +6,8 @@ namespace :homework_publishtime do # 作业的分班设置时间 def homework_group_setting homework, group_id setting = nil - if homework.homework_group_settings.where(:course_group_id => group_id).first - setting = homework.homework_group_settings.where(:course_group_id => group_id).first + if homework.homework_group_settings.where(course_group_id: group_id).first + setting = homework.homework_group_settings.where(course_group_id: group_id).first else setting = homework end diff --git a/lib/tasks/poll_publish.rake b/lib/tasks/poll_publish.rake index 48c289050..6ced88908 100644 --- a/lib/tasks/poll_publish.rake +++ b/lib/tasks/poll_publish.rake @@ -116,11 +116,7 @@ namespace :poll_publish do polls = Poll.includes(:poll_users).where("polls_status = 2 AND unified_setting = true AND end_time <=?",Time.now + 900) polls.each do |poll| poll.update_column('polls_status', 3) - poll.poll_users.each do |poll_user| - if poll_user.commit_status == 0 && poll_user.start_at.present? - poll_user.update_attributes(:commit_status => 1, :end_at => Time.now) - end - end + poll.poll_users.where("commit_status = 0 and start_at is not null").update_all(commit_status: 1, end_at: Time.now) end #2.分班设置的截止 @@ -132,13 +128,13 @@ namespace :poll_publish do if poll&.end_time <= Time.now poll.update_column('polls_status', 3) end - users = poll.course.course_members.where(:course_group_id => poll_setting.course_group_id) - poll_users = poll.poll_users.where(:user_id => users.map(&:user_id)) - poll_users.each do |poll_user| - if poll_user.commit_status == 0 && !poll_user.start_at.nil? - poll_user.update_attributes(:commit_status => 1, :end_at => Time.now) - end - end + users = poll.course.course_members.where(course_group_id: poll_setting.course_group_id) + poll.poll_users.where(user_id: users.pluck(:user_id)).where("commit_status = 0 and start_at is not null").update_all(commit_status: 1, end_at: Time.now) + # poll_users.each do |poll_user| + # if poll_user.commit_status == 0 && !poll_user.start_at.nil? + # poll_user.update_attributes(:commit_status => 1, :end_at => Time.now) + # end + # end end # PollGroupSetting.where("end_time < ? and end_time > ?", Time.now + 1800, Time.now - 1800).each do |poll_setting| diff --git a/lib/tasks/resource_publish.rake b/lib/tasks/resource_publish.rake index 7872a6ce4..f90718cfb 100644 --- a/lib/tasks/resource_publish.rake +++ b/lib/tasks/resource_publish.rake @@ -5,9 +5,7 @@ namespace :resource_publish do task :publish => :environment do Rails.logger.info("log--------------------------------resource_publish start") attachments = Attachment.where("publish_time < '#{Time.now}' and is_publish = 0") - attachments.each do |attachment| - attachment.update_attributes(:is_publish => 1) - end + attachments.update_all(is_publish: 1) Rails.logger.info("log--------------------------------resource_publish end") end end \ No newline at end of file From dcec641b5b7f62410836152e2582db1acca66415 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 11:33:02 +0800 Subject: [PATCH 0224/1015] fix bug --- app/helpers/exercises_helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 285dbb37e..9526acaf1 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -424,13 +424,13 @@ module ExercisesHelper end ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id) if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 - cha_path = challenge_path exercise_cha.challenge.path - game_challenge = game.game_codes.search_challenge_path(cha_path).first + 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(exercise_cha.shixun.repo_path,cha_path) + code = git_fle_content(exercise_cha.shixun&.repo_path,cha_path) end sx_option = { :exercise_question_id => q.id, From fa5685a877586ed8b0d62120c5048e2412dadb7c Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 25 Jun 2019 14:08:28 +0800 Subject: [PATCH 0225/1015] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E4=BD=9C=E5=93=81=E5=88=97=E8=A1=A8=E6=B7=BB=E5=8A=A0=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/graduation_works_helper.rb | 3 +-- app/models/graduation_work.rb | 7 +++++-- app/views/graduation_tasks/tasks_list.json.jbuilder | 7 ++++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/helpers/graduation_works_helper.rb b/app/helpers/graduation_works_helper.rb index 177720d24..577efa797 100644 --- a/app/helpers/graduation_works_helper.rb +++ b/app/helpers/graduation_works_helper.rb @@ -15,7 +15,6 @@ module GraduationWorksHelper end end # work_score 最终成绩; late_penalty 迟交扣分; final_score 最终评分 - {username: work.user.full_name, login: work.user.login, work_score: work_score, final_score: work.final_score, - late_penalty:work.late_penalty } + {username: work.user.full_name, login: work.user.login, work_score: work_score, final_score: work.final_score} end end diff --git a/app/models/graduation_work.rb b/app/models/graduation_work.rb index a99a18b2a..49cab19ee 100644 --- a/app/models/graduation_work.rb +++ b/app/models/graduation_work.rb @@ -100,8 +100,7 @@ class GraduationWork < ApplicationRecord "未批阅" else if self.check_score_power?(current_user, course_identity) - "#{format("%.1f", self.cross_score.round(1))}(#{self.graduation_work_scores - .where(reviewer_role: 2).group_by(&:user_id).count})" + "#{format("%.1f", self.cross_score.round(1))}" else "**" end @@ -109,6 +108,10 @@ class GraduationWork < ApplicationRecord end end + def cross_comment_num + graduation_work_scores.where(reviewer_role: 2).group_by(&:user_id).count + end + def scored? graduation_work_scores.where.not(reviewer_role: 3).exists? end diff --git a/app/views/graduation_tasks/tasks_list.json.jbuilder b/app/views/graduation_tasks/tasks_list.json.jbuilder index a0cffc41b..62c95901f 100644 --- a/app/views/graduation_tasks/tasks_list.json.jbuilder +++ b/app/views/graduation_tasks/tasks_list.json.jbuilder @@ -42,6 +42,7 @@ if @task.published? || @user_course_identity < Course::STUDENT json.name work.user.real_name json.student_id work.user.student_id json.class_grouping_name work.class_grouping_name + json.ultimate_score work.ultimate_score if @task.have_grouping? json.grouping_name work.grouping_name if @task.base_on_project @@ -51,7 +52,11 @@ if @task.published? || @user_course_identity < Course::STUDENT json.status work.work_status json.update_time format_time work.update_time json.teacher_comment_score work.teacher_comment_score(@current_user, @user_course_identity) - json.cross_comment_score work.cross_comment_score(@current_user, @user_course_identity) + if @task.cross_comment + json.cross_comment_score work.cross_comment_score(@current_user, @user_course_identity) + json.cross_comment_num work.cross_comment_num + end + json.late_penalty work.late_penalty if @task.allow_late json.final_score work_final_score work, @current_user, @user_course_identity json.assign work.assign_power?(@user_course_identity) end From 97ffdc47dfa2949ba2f4ca008a469f6d8ff1d0a2 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 25 Jun 2019 14:13:28 +0800 Subject: [PATCH 0226/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E9=80=89=E7=94=A8?= =?UTF-8?q?=E9=A2=98=E5=BA=93=E6=B2=A1=E4=BF=9D=E5=AD=98=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/question_banks_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index bf55db9dd..0a999e1f3 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -178,6 +178,7 @@ class QuestionBanksController < ApplicationController :question_type => q.question_type || 1, :question_number => q.question_number, :question_score => q.question_score, + :shixun_name => q.shixun_name, :shixun_id => q.shixun_id } exercise_question = new_exercise.exercise_questions.new option @@ -190,7 +191,8 @@ class QuestionBanksController < ApplicationController # 复制标准答案(填空题和问答题) 多空填空题的话,应该是原标准答案的exercise_choice_id,即为题空的位置。 q.exercise_bank_standard_answers.try(:each) do |answer| - exercise_question.exercise_standard_answers.new({exercise_choice_id: answer.exercise_bank_choice_id, answer_text: answer.answer_text}) + exercise_question.exercise_standard_answers.new({exercise_choice_id: answer.exercise_bank_choice_id, + answer_text: answer.answer_text}) end else # 复制实训题 From 203ccd383cbba4f9c3658852a399f6ab049f1ceb Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 14:26:44 +0800 Subject: [PATCH 0227/1015] fix bug --- .../exercise_questions_controller.rb | 2 +- app/controllers/question_banks_controller.rb | 51 +++++++++++++------ app/helpers/exercises_helper.rb | 2 +- app/tasks/exercise_publish_task.rb | 4 +- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index a0b88a97e..96951ac48 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -127,7 +127,7 @@ class ExerciseQuestionsController < ApplicationController shixun_scores = params[:question_scores] #试卷有多个的分值有多个分数表,所以为分数的数组 shixun_name = params[:shixun_name] || shixun.name question_score = 0 - shixun.challenges.each_with_index do |challenge,index| + shixun.challenges.try(:each_with_index) do |challenge,index| shixun_option = { :challenge_id => challenge.id, :shixun_id => shixun.id, diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index bf55db9dd..cfb4d7763 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -181,31 +181,50 @@ class QuestionBanksController < ApplicationController :shixun_id => q.shixun_id } exercise_question = new_exercise.exercise_questions.new option - # question_type:5实训题;其他是非实训题 - if q.question_type != 5 - # 复制选择题题目选项 - q.exercise_bank_choices.try(:each_with_index) do |choice, index| - exercise_question.exercise_choices.new({choice_position: index+1, choice_text: choice.choice_text}) - end + if exercise_question.save + if q.question_type != 5 + # 复制选择题题目选项 + q.exercise_bank_choices.try(:each_with_index) do |choice, index| + exercise_question.exercise_choices.create({choice_position: index+1, choice_text: choice.choice_text}) + end - # 复制标准答案(填空题和问答题) 多空填空题的话,应该是原标准答案的exercise_choice_id,即为题空的位置。 - q.exercise_bank_standard_answers.try(:each) do |answer| - exercise_question.exercise_standard_answers.new({exercise_choice_id: answer.exercise_bank_choice_id, answer_text: answer.answer_text}) - end - else - # 复制实训题 - q.exercise_bank_shixun_challenges.try(:each_with_index) do |sc, index| - exercise_question.exercise_shixun_challenges.new({position: index+1, challenge_id: sc.challenge_id, - shixun_id: sc.shixun_id, question_score: sc.question_score}) + # 复制标准答案(填空题和问答题) 多空填空题的话,应该是原标准答案的exercise_choice_id,即为题空的位置。 + q.exercise_bank_standard_answers.try(:each) do |answer| + exercise_question.exercise_standard_answers.create({exercise_choice_id: answer.exercise_bank_choice_id, answer_text: answer.answer_text}) + end + else + # 复制实训题 + q.exercise_bank_shixun_challenges.try(:each_with_index) do |sc, index| + exercise_question.exercise_shixun_challenges.create({position: index+1, challenge_id: sc.challenge_id, + shixun_id: sc.shixun_id, question_score: sc.question_score}) + end end end + # question_type:5实训题;其他是非实训题 + # if q.question_type != 5 + # # 复制选择题题目选项 + # q.exercise_bank_choices.try(:each_with_index) do |choice, index| + # exercise_question.exercise_choices.new({choice_position: index+1, choice_text: choice.choice_text}) + # end + # + # # 复制标准答案(填空题和问答题) 多空填空题的话,应该是原标准答案的exercise_choice_id,即为题空的位置。 + # q.exercise_bank_standard_answers.try(:each) do |answer| + # exercise_question.exercise_standard_answers.new({exercise_choice_id: answer.exercise_bank_choice_id, answer_text: answer.answer_text}) + # end + # else + # # 复制实训题 + # q.exercise_bank_shixun_challenges.try(:each_with_index) do |sc, index| + # exercise_question.exercise_shixun_challenges.new({position: index+1, challenge_id: sc.challenge_id, + # shixun_id: sc.shixun_id, question_score: sc.question_score}) + # end + # end end # 添加学生 # if new_exercise.save # new_exercise.create_exercise_list # exercise.update_column(:quotes, exercise.quotes+1) # end - new_exercise if new_exercise.save! + # new_exercise if new_exercise.save! end end diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 9526acaf1..4530167ba 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -451,7 +451,7 @@ module ExercisesHelper end end user_scores = answers_content.present? ? answers_content.score_reviewed.pluck(:score).sum : 0.0 - if user_scores > 0 + if user_scores > 0.0 stand_answer = 1 else stand_answer = 0 diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb index 282968755..932fe00fb 100644 --- a/app/tasks/exercise_publish_task.rb +++ b/app/tasks/exercise_publish_task.rb @@ -70,7 +70,7 @@ class ExercisePublishTask Rails.logger.info("log--------------------------------exercise_end start") puts "--------------------------------exercise_end start" # 1。统一设置的试卷 - exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND unified_setting = true AND end_time <= ?",Time.now + 900) + exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND unified_setting = true AND end_time <= ?",Time.now) exercises.each do |exercise| ex_type = exercise.exercise_questions.pluck(:question_type).uniq exercise.update_column('exercise_status', 3) @@ -98,7 +98,7 @@ class ExercisePublishTask end # 2.非统一的试卷 - all_exercises = Exercise.includes(:exercise_group_settings,:exercise_users,:exercise_questions).where("unified_setting = false AND exercise_status = 2 AND end_time > ?",Time.now + 900) + all_exercises = Exercise.includes(:exercise_group_settings,:exercise_users,:exercise_questions).where("unified_setting = false AND exercise_status = 2 AND end_time > ?",Time.now) exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")" ex_group_settings = ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}") ex_group_settings.each do |exercise_setting| From f3885408a570cd1f9e5e0d6691a1272a38ebc9b7 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 14:28:15 +0800 Subject: [PATCH 0228/1015] fix bug --- app/controllers/question_banks_controller.rb | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index b304c8d41..0fcdaf941 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -188,8 +188,6 @@ class QuestionBanksController < ApplicationController q.exercise_bank_choices.try(:each_with_index) do |choice, index| exercise_question.exercise_choices.create({choice_position: index+1, choice_text: choice.choice_text}) end - -<<<<<<< HEAD # 复制标准答案(填空题和问答题) 多空填空题的话,应该是原标准答案的exercise_choice_id,即为题空的位置。 q.exercise_bank_standard_answers.try(:each) do |answer| exercise_question.exercise_standard_answers.create({exercise_choice_id: answer.exercise_bank_choice_id, answer_text: answer.answer_text}) @@ -200,18 +198,6 @@ class QuestionBanksController < ApplicationController exercise_question.exercise_shixun_challenges.create({position: index+1, challenge_id: sc.challenge_id, shixun_id: sc.shixun_id, question_score: sc.question_score}) end -======= - # 复制标准答案(填空题和问答题) 多空填空题的话,应该是原标准答案的exercise_choice_id,即为题空的位置。 - q.exercise_bank_standard_answers.try(:each) do |answer| - exercise_question.exercise_standard_answers.new({exercise_choice_id: answer.exercise_bank_choice_id, - answer_text: answer.answer_text}) - end - else - # 复制实训题 - q.exercise_bank_shixun_challenges.try(:each_with_index) do |sc, index| - exercise_question.exercise_shixun_challenges.new({position: index+1, challenge_id: sc.challenge_id, - shixun_id: sc.shixun_id, question_score: sc.question_score}) ->>>>>>> 97ffdc47dfa2949ba2f4ca008a469f6d8ff1d0a2 end end # question_type:5实训题;其他是非实训题 From 96a613a9c9c411597181b5be6d95b555f980c65c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 14:28:57 +0800 Subject: [PATCH 0229/1015] fix bug --- app/controllers/question_banks_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index 0fcdaf941..0184fa81a 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -200,7 +200,7 @@ class QuestionBanksController < ApplicationController end end end - # question_type:5实训题;其他是非实训题 + # question_type:5实训题;其他是非实训题git # if q.question_type != 5 # # 复制选择题题目选项 # q.exercise_bank_choices.try(:each_with_index) do |choice, index| From 1fe4a8c986d78422b3fecb37074705d79d8555be Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 14:35:00 +0800 Subject: [PATCH 0230/1015] fix bug --- app/controllers/question_banks_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index 0184fa81a..0f9ed4d31 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -224,7 +224,7 @@ class QuestionBanksController < ApplicationController # new_exercise.create_exercise_list # exercise.update_column(:quotes, exercise.quotes+1) # end - # new_exercise if new_exercise.save! + new_exercise if new_exercise.save! end end From 287d7b0a311256a867aa6eab66ca45117b8998db Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 25 Jun 2019 14:46:15 +0800 Subject: [PATCH 0231/1015] =?UTF-8?q?vnc=E8=B0=83=E8=AF=95=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 2a3c51762..bd9f2e184 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -68,6 +68,7 @@ class GamesController < ApplicationController service_host = edu_setting('vnc_url') uri = "#{shixun_tomcat}/bridge/vnc/getvnc" params = {tpiID: @myshixun.id, :containers => "#{Base64.urlsafe_encode64(container_limit(@shixun.mirror_repositories))}"} + logger.info("#######_------uri:#{uri}, params: #{params}") res = uri_post uri, params if res && res['code'].to_i != 0 raise("实训云平台繁忙(繁忙等级:99)") From c74b34ce585be8b9093a70d4d8e30c42455ce89d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 25 Jun 2019 14:48:34 +0800 Subject: [PATCH 0232/1015] =?UTF-8?q?vnc=E5=9C=B0=E5=9D=80=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index bd9f2e184..9b69ca058 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -64,7 +64,7 @@ class GamesController < ApplicationController myshixun_manager: myshixun_manager} if @shixun.vnc begin - shixun_tomcat = edu_setting('shixun_tomcat') + shixun_tomcat = edu_setting('cloud_bridge') service_host = edu_setting('vnc_url') uri = "#{shixun_tomcat}/bridge/vnc/getvnc" params = {tpiID: @myshixun.id, :containers => "#{Base64.urlsafe_encode64(container_limit(@shixun.mirror_repositories))}"} From d8901891f6a2b93891d0a81921e5e8b61a0f9d41 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 25 Jun 2019 14:53:23 +0800 Subject: [PATCH 0233/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=ADvnc=E6=8A=A5?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 9b69ca058..67fdbfb9e 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -68,13 +68,11 @@ class GamesController < ApplicationController service_host = edu_setting('vnc_url') uri = "#{shixun_tomcat}/bridge/vnc/getvnc" params = {tpiID: @myshixun.id, :containers => "#{Base64.urlsafe_encode64(container_limit(@shixun.mirror_repositories))}"} - logger.info("#######_------uri:#{uri}, params: #{params}") res = uri_post uri, params if res && res['code'].to_i != 0 raise("实训云平台繁忙(繁忙等级:99)") end @url = "http://#{service_host}:#{res['port']}}/vnc_lite.html?password=headless" - Rails.logger.info("66666666sssssss#{url}") rescue Exception => e Rails.logger.error(e.message) end From 18dce71695f2396fc272d69f8fda55d60150a319 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 25 Jun 2019 14:53:39 +0800 Subject: [PATCH 0234/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E7=9A=84=E6=8C=89=E7=AD=94=E6=A1=88=E7=BA=A7=E5=88=AB=E6=89=A3?= =?UTF-8?q?=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/homeworks_service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/homeworks_service.rb b/app/services/homeworks_service.rb index 2affec0ba..2d6f50b5c 100644 --- a/app/services/homeworks_service.rb +++ b/app/services/homeworks_service.rb @@ -81,7 +81,7 @@ class HomeworksService pass_consume_time += (game.cost_time / 60.0).to_f user_total_score += game.final_score.to_i < 0 ? 0 : game.challenge.score.to_i adjust_score = student_work.challenge_work_scores.where(challenge_id: setting.challenge_id).last - final_score += adjust_score.present? ? adjust_score.score : (answer_open_evaluation ? setting.score : (game.final_score >= 0 ? setting.score : 0)) + final_score += adjust_score.present? ? adjust_score.score : (answer_open_evaluation ? setting.score : (game.final_score > 0 ? game.real_score(setting.score) : 0)) max_endtime = max_endtime == "" ? game.end_time : (game.end_time > max_endtime ? game.end_time : max_endtime) else compelete = false @@ -177,7 +177,7 @@ class HomeworksService pass_consume_time += (game.cost_time / 60.0).to_f user_total_score += game.final_score.to_i < 0 ? 0 : game.challenge.score.to_i adjust_score = work.challenge_work_scores.where(:challenge_id => setting.challenge_id).last - final_score += adjust_score.present? ? adjust_score.score : (homework.homework_detail_manual.answer_open_evaluation ? setting.score : (game.final_score >= 0 ? setting.score : 0)) + final_score += adjust_score.present? ? adjust_score.score : (homework.homework_detail_manual.answer_open_evaluation ? setting.score : (game.final_score > 0 ? game.real_score(setting.score) : 0)) end end if work.work_status == 0 From 0cc4f8262c80be46fda832924e5cda476b0ba148 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 14:56:43 +0800 Subject: [PATCH 0235/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E5=8A=A0?= =?UTF-8?q?=E5=85=A5=E9=A2=98=E5=BA=93=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 2 +- app/controllers/question_banks_controller.rb | 50 +++++++------------- 2 files changed, 17 insertions(+), 35 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 3e4dea5e3..2175108fc 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -321,7 +321,7 @@ class ExercisesController < ApplicationController begin check_ids = Exercise.where(id: params[:check_ids]) check_ids.each do |exercise| - current_ex_bank = current_user.exercise_banks.find_by_container(exercise.id,"Exercise").first + current_ex_bank = current_user.exercise_banks.find_by_container(exercise.id,"Exercise")&.first if current_ex_bank.present? #当前用户的选择试卷是否已加入习题库,存在则更新习题库和问题库,否则新建习题库和问题库 ex_params = { :name => exercise.exercise_name, diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index 0f9ed4d31..740e3a993 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -182,42 +182,24 @@ class QuestionBanksController < ApplicationController :shixun_id => q.shixun_id } exercise_question = new_exercise.exercise_questions.new option - if exercise_question.save - if q.question_type != 5 - # 复制选择题题目选项 - q.exercise_bank_choices.try(:each_with_index) do |choice, index| - exercise_question.exercise_choices.create({choice_position: index+1, choice_text: choice.choice_text}) - end - # 复制标准答案(填空题和问答题) 多空填空题的话,应该是原标准答案的exercise_choice_id,即为题空的位置。 - q.exercise_bank_standard_answers.try(:each) do |answer| - exercise_question.exercise_standard_answers.create({exercise_choice_id: answer.exercise_bank_choice_id, answer_text: answer.answer_text}) - end - else - # 复制实训题 - q.exercise_bank_shixun_challenges.try(:each_with_index) do |sc, index| - exercise_question.exercise_shixun_challenges.create({position: index+1, challenge_id: sc.challenge_id, - shixun_id: sc.shixun_id, question_score: sc.question_score}) - end + # question_type:5实训题;其他是非实训题 + if q.question_type != 5 + # 复制选择题题目选项 + q.exercise_bank_choices.try(:each_with_index) do |choice, index| + exercise_question.exercise_choices.new({choice_position: index+1, choice_text: choice.choice_text}) + end + + # 复制标准答案(填空题和问答题) 多空填空题的话,应该是原标准答案的exercise_choice_id,即为题空的位置。 + q.exercise_bank_standard_answers.try(:each) do |answer| + exercise_question.exercise_standard_answers.new({exercise_choice_id: answer.exercise_bank_choice_id, answer_text: answer.answer_text}) + end + else + # 复制实训题 + q.exercise_bank_shixun_challenges.try(:each_with_index) do |sc, index| + exercise_question.exercise_shixun_challenges.new({position: index+1, challenge_id: sc.challenge_id, + shixun_id: sc.shixun_id, question_score: sc.question_score}) end end - # question_type:5实训题;其他是非实训题git - # if q.question_type != 5 - # # 复制选择题题目选项 - # q.exercise_bank_choices.try(:each_with_index) do |choice, index| - # exercise_question.exercise_choices.new({choice_position: index+1, choice_text: choice.choice_text}) - # end - # - # # 复制标准答案(填空题和问答题) 多空填空题的话,应该是原标准答案的exercise_choice_id,即为题空的位置。 - # q.exercise_bank_standard_answers.try(:each) do |answer| - # exercise_question.exercise_standard_answers.new({exercise_choice_id: answer.exercise_bank_choice_id, answer_text: answer.answer_text}) - # end - # else - # # 复制实训题 - # q.exercise_bank_shixun_challenges.try(:each_with_index) do |sc, index| - # exercise_question.exercise_shixun_challenges.new({position: index+1, challenge_id: sc.challenge_id, - # shixun_id: sc.shixun_id, question_score: sc.question_score}) - # end - # end end # 添加学生 # if new_exercise.save From 4e472736000ad44732e5da350e960de02b55f9ad Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 25 Jun 2019 14:58:44 +0800 Subject: [PATCH 0236/1015] =?UTF-8?q?vnc=E7=9A=84url?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 67fdbfb9e..93b27e8b2 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -72,7 +72,7 @@ class GamesController < ApplicationController if res && res['code'].to_i != 0 raise("实训云平台繁忙(繁忙等级:99)") end - @url = "http://#{service_host}:#{res['port']}}/vnc_lite.html?password=headless" + @vnc_url = "http://#{service_host}:#{res['port']}}/vnc_lite.html?password=headless" rescue Exception => e Rails.logger.error(e.message) end From 7622c9b4b61a7f2f6dec6ea662e841e76f4bedaf Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 25 Jun 2019 14:59:39 +0800 Subject: [PATCH 0237/1015] =?UTF-8?q?vnc=E7=9A=84url=E5=A4=9A=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 93b27e8b2..5fe230d32 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -72,7 +72,7 @@ class GamesController < ApplicationController if res && res['code'].to_i != 0 raise("实训云平台繁忙(繁忙等级:99)") end - @vnc_url = "http://#{service_host}:#{res['port']}}/vnc_lite.html?password=headless" + @vnc_url = "http://#{service_host}:#{res['port']}/vnc_lite.html?password=headless" rescue Exception => e Rails.logger.error(e.message) end From a588202c5d48dd8fb75aa2aefac713b4f5f8c2b9 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 25 Jun 2019 15:35:38 +0800 Subject: [PATCH 0238/1015] =?UTF-8?q?=E8=AF=84=E6=B5=8B=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/game.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/game.rb b/app/models/game.rb index c08884afb..ba6664d5c 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -115,9 +115,9 @@ class Game < ApplicationRecord end # 评测次数 - def evaluate_count - self.outputs.pluck(:query_index).first - end + #def evaluate_count + # self.outputs.pluck(:query_index).first + #end # 用户关卡得分 def get_user_final_score From 1e8550a825a7f416161c390e3080407194224722 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 25 Jun 2019 15:41:45 +0800 Subject: [PATCH 0239/1015] =?UTF-8?q?=E6=89=93=E5=8D=B0=E8=AF=84=E6=B5=8B?= =?UTF-8?q?=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index f4a072a4b..e2d26e89f 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -432,6 +432,7 @@ class StudentWorksController < ApplicationController @games = @work.myshixun.games.includes(:challenge, :game_codes, :outputs) if @work.myshixun # 用户最大评测次数 + logger.info("-----------#{@games.map(&:evaluate_count)}") @user_evaluate_count = @games.sum(:evaluate_count) if @games # 图形效率图的数据 @echart_data = student_efficiency(@homework, @work) From d656a879b31b06e6ab65ea5c7d1a70f50dce1643 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 25 Jun 2019 15:43:28 +0800 Subject: [PATCH 0240/1015] =?UTF-8?q?=E6=89=93=E5=8D=B0sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index e2d26e89f..7d22f4b71 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -433,6 +433,8 @@ class StudentWorksController < ApplicationController # 用户最大评测次数 logger.info("-----------#{@games.map(&:evaluate_count)}") + logger.info("-------sum_evaluate_count----#{@games.sum(:evaluate_count)}") + logger.info("-----------#{@games.sum(:evaluate_count).to_sql}") @user_evaluate_count = @games.sum(:evaluate_count) if @games # 图形效率图的数据 @echart_data = student_efficiency(@homework, @work) From e2dce33955956ff4d081717e11f04cc1279fb7dd Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 25 Jun 2019 15:45:24 +0800 Subject: [PATCH 0241/1015] =?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/controllers/student_works_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 7d22f4b71..0002a49ea 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -434,7 +434,7 @@ class StudentWorksController < ApplicationController # 用户最大评测次数 logger.info("-----------#{@games.map(&:evaluate_count)}") logger.info("-------sum_evaluate_count----#{@games.sum(:evaluate_count)}") - logger.info("-----------#{@games.sum(:evaluate_count).to_sql}") + logger.info("-------sum_evaluate_count----#{@games.sum("games.evaluate_count")}") @user_evaluate_count = @games.sum(:evaluate_count) if @games # 图形效率图的数据 @echart_data = student_efficiency(@homework, @work) From 40979e7b2cbe6c391c0e33c5c3495b7d194918cf Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 25 Jun 2019 15:52:48 +0800 Subject: [PATCH 0242/1015] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E6=8A=A5=E5=91=8A=E8=AF=84=E6=B5=8B=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 0002a49ea..7e23443d2 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -429,13 +429,17 @@ class StudentWorksController < ApplicationController def shixun_work_report @user = @work.user @shixun = @homework.shixuns.take - @games = @work.myshixun.games.includes(:challenge, :game_codes, :outputs) if @work.myshixun + # 提示: 这里如果includes outputs表的话: sum(:evaluate_count)会出现错误 + @games = @work.myshixun.games if @work.myshixun # 用户最大评测次数 - logger.info("-----------#{@games.map(&:evaluate_count)}") - logger.info("-------sum_evaluate_count----#{@games.sum(:evaluate_count)}") - logger.info("-------sum_evaluate_count----#{@games.sum("games.evaluate_count")}") - @user_evaluate_count = @games.sum(:evaluate_count) if @games + if @games + @user_evaluate_count = @games.sum(:evaluate_count) + @games = @games.includes(:challenge, :game_codes, :outputs) + else + @user_evaluate_count = 0 + end + # 图形效率图的数据 @echart_data = student_efficiency(@homework, @work) end From 9b5955cda185b6f8e0f86a43f196818ad1737ea7 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 16:02:09 +0800 Subject: [PATCH 0243/1015] fix bug --- app/helpers/exercises_helper.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 4530167ba..2a052fffe 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -682,16 +682,26 @@ module ExercisesHelper def get_exercise_left_time(exercise,user) ex_time = exercise.time user_left_time = nil + time_now_i = Time.now.to_i if ex_time > 0 exercise_user = exercise.exercise_users.find_by(user_id:user.id) time_mill = ex_time * 60 #转为秒 exercise_end_time = exercise.end_time.present? ? exercise.end_time.to_i : 0 exercise_user_start = exercise_user.present? ? exercise_user.start_at.to_i : 0 - if (exercise_user_start + time_mill) > exercise_end_time - time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时 + #用户未开始答题时,即exercise_user_start为0 + if exercise_user_start == 0 + if (exercise_end_time - time_now_i) > time_mill + user_left_time = time_mill + else + user_left_time = (exercise_end_time < time_now_i) ? nil : (exercise_end_time - time_now_i) + end + else + if (exercise_user_start + time_mill) > exercise_end_time + time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时 + end + exercise_user_left_time = time_now_i - exercise_user_start #用户已回答的时间 + user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间 end - exercise_user_left_time = Time.now.to_i - exercise_user_start #用户已回答的时间 - user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间 end user_left_time end From 525b848cca2984172b46c5cf4effc603fd68bd37 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 16:21:38 +0800 Subject: [PATCH 0244/1015] fix bug --- app/tasks/exercise_publish_task.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb index 387a834f1..4c8ee39e8 100644 --- a/app/tasks/exercise_publish_task.rb +++ b/app/tasks/exercise_publish_task.rb @@ -44,7 +44,7 @@ class ExercisePublishTask end # 分组设置发布时间的测验 - exercise_group_settings = ExerciseGroupSetting.where("publish_time < ? and publish_time > ?", Time.now + 1800, Time.now - 1800) + exercise_group_settings = ExerciseGroupSetting.where("publish_time < ? and publish_time > ?", Time.now + 900, Time.now - 900) exercise_group_settings.each do |exercise_group| exercise = exercise_group.exercise if exercise.present? @@ -70,12 +70,12 @@ class ExercisePublishTask Rails.logger.info("log--------------------------------exercise_end start") puts "--------------------------------exercise_end start" # 1。统一设置的试卷 - exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND unified_setting = true AND end_time <= ?",Time.now) + exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND unified_setting = true AND end_time <= ?",Time.now + 900) exercises.each do |exercise| ex_type = exercise.exercise_questions.pluck(:question_type).uniq exercise.update_column('exercise_status', 3) exercise.exercise_users.each do |exercise_user| - if exercise_user.commit_status == 0 && exercise_user.start_at.present? + if exercise_user&.commit_status == 0 && exercise_user&.start_at.present? s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] if ex_type.include?(4) #是否包含主观题 subjective_score = exercise_user.subjective_score @@ -98,7 +98,7 @@ class ExercisePublishTask end # 2.非统一的试卷 - all_exercises = Exercise.includes(:exercise_group_settings,:exercise_users,:exercise_questions).where("unified_setting = false AND exercise_status = 2 AND end_time > ?",Time.now) + all_exercises = Exercise.includes(:exercise_group_settings,:exercise_users,:exercise_questions).where("unified_setting = false AND exercise_status = 2 AND end_time > ?",Time.now + 900) exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")" ex_group_settings = ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}") ex_group_settings.each do |exercise_setting| From 1d6500ca7af8e7e7e7a58804e6b3f81967beb9e4 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 16:50:54 +0800 Subject: [PATCH 0245/1015] fix bug --- app/templates/exercise_export/exercise_user.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 70c023d26..3a651f89d 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -249,8 +249,8 @@ <% if @games.size > 0 %> <% @games.each_with_index do |game, index| %> - <% user_score = q.exercise_shixun_answers.where(exercise_shixun_challenge_id:game.challenge.id,user_id: @ex_user_user.id) %> <% game_score = q.exercise_shixun_challenges.where(challenge_id:game.challenge.id) %> + <% user_score = q.exercise_shixun_answers.where(exercise_shixun_challenge_id: game_score&.id,user_id: @ex_user_user.id) %> <%= index + 1 %> From 62cf506e2b33ed06d51033374a8a5a5e62dc711c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 16:55:30 +0800 Subject: [PATCH 0246/1015] fix bug --- app/templates/exercise_export/exercise_export.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index f5022527e..59be4f1bd 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -241,7 +241,7 @@ p{ position: absolute; display: inline-block; bottom: 9px; - left: 1px; + left: 2px; } table{ width:100%; From f40f8ae0422b6678b002999bbdd25c838f77ba52 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 16:58:20 +0800 Subject: [PATCH 0247/1015] fix bug --- app/templates/exercise_export/exercise_user.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 3a651f89d..193a25301 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -250,7 +250,7 @@ <% if @games.size > 0 %> <% @games.each_with_index do |game, index| %> <% game_score = q.exercise_shixun_challenges.where(challenge_id:game.challenge.id) %> - <% user_score = q.exercise_shixun_answers.where(exercise_shixun_challenge_id: game_score&.id,user_id: @ex_user_user.id) %> + <% user_score = q.exercise_shixun_answers.where(exercise_shixun_challenge_id: game_score&.first&.id,user_id: @ex_user_user.id) %> <%= index + 1 %> From 25ef08118c76f5758cad7162561ddad3f71a5722 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 17:45:57 +0800 Subject: [PATCH 0248/1015] fixbug --- app/helpers/exercises_helper.rb | 12 ++++++------ app/helpers/export_helper.rb | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 2a052fffe..856f808d7 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -355,9 +355,9 @@ module ExercisesHelper exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers,:exercise_shixun_challenges) exercise_questions.each do |q| if q.question_type != 5 - answers_content = q.exercise_answers.search_answer_users("user_id",user.id) #学生的答案 + answers_content = q.exercise_answers.where(user_id: user.id) #学生的答案 else - answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user.id) #学生的答案 + answers_content = q.exercise_shixun_answers.where(user_id: user.id) #学生的答案 end if q.question_type <= 2 #为选择题或判断题时 if answers_content.present? #学生有回答时 @@ -369,11 +369,11 @@ module ExercisesHelper standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 if standard_answer.count > 0 - q_score_1 = (q.question_score / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 + multi_each_score = (q.question_score / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 else - q_score_1 = 0.0 + multi_each_score = 0.0 end - answers_content.update_all(:score => q_score_1) + answers_content.update_all(:score => multi_each_score) score1 = score1 + q.question_score end else @@ -424,7 +424,7 @@ module ExercisesHelper end ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id) if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 - cha_path = challenge_path exercise_cha.challenge&.path + 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 diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index af883131a..22c10bdb3 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -89,11 +89,12 @@ module ExportHelper if teacher_comments.present? w_18 = "" teacher_comments.each do |t| - user_name = t.user.real_name + user_name = t.user&.real_name user_time = format_time(t.updated_at) - user_score = t.score - user_comment = t.comment - w_18 = w_18 + ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "分" + "\n" + "评语:" + user_comment + "\n\n") + user_score = t&.score + user_comment = t&.comment + comment_title = "教师:#{user_name}\n时间:#{user_time.to_s}\n分数:#{user_score.to_s}分\n评语:#{user_comment}\n\n" + w_18 = w_18 + comment_title end else w_18 = "--" @@ -160,11 +161,13 @@ module ExportHelper if teacher_comments.present? w_18 = "" teacher_comments.each do |t| - user_name = t.user.real_name + user_name = t.user&.real_name user_time = format_time(t.updated_at) - user_score = t.score - user_comment = t.comment - w_18 = w_18 + ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "分" + "\n" + "评语:" + user_comment + "\n\n") + user_score = t&.score + user_comment = t&.comment + comment_title = "教师:#{user_name}\n时间:#{user_time.to_s}\n分数:#{user_score.to_s}分\n评语:#{user_comment}\n\n" + # ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "分" + "\n" + "评语:" + user_comment + "\n\n") + w_18 = w_18 + comment_title end else w_18 = "--" From 555b1f8dc0dc08c68a5773a8edcb13bd18f1f541 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 25 Jun 2019 17:46:57 +0800 Subject: [PATCH 0249/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E7=9A=84=E6=9C=80=E5=A4=A7=E6=95=88=E7=8E=87=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/homeworks_service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/homeworks_service.rb b/app/services/homeworks_service.rb index 2d6f50b5c..1e155dde0 100644 --- a/app/services/homeworks_service.rb +++ b/app/services/homeworks_service.rb @@ -111,7 +111,7 @@ class HomeworksService if homework.work_efficiency if homework.max_efficiency < student_work.efficiency # homework.max_efficiency = student_work.efficiency - homework.update_column("max_efficiency", homework.max_efficiency) + homework.update_column("max_efficiency", student_work.efficiency) end # eff_score = homework.max_efficiency == 0 ? 0 : student_work.efficiency / homework.max_efficiency * homework.eff_score # student_work.eff_score = format("%.2f", eff_score) @@ -200,7 +200,7 @@ class HomeworksService # 如果作业的最大效率值有变更则更新所有作品的效率分 if homework.work_efficiency && homework.max_efficiency < work.efficiency - homework.update_column("max_efficiency", homework.max_efficiency) + homework.update_column("max_efficiency", work.efficiency) end end From cc1d09bee79e53efd7beb55e48a87f1e6b410cd3 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 25 Jun 2019 18:03:19 +0800 Subject: [PATCH 0250/1015] =?UTF-8?q?=E6=9F=A5=E7=9C=8B=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E5=BC=B9=E6=A1=86=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7=E8=8E=B7?= =?UTF-8?q?=E5=BE=97=E7=9A=84=E6=80=BB=E7=BB=8F=E9=AA=8C=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/student_works/shixun_work.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/student_works/shixun_work.json.jbuilder b/app/views/student_works/shixun_work.json.jbuilder index 3b6b598cb..74c33420e 100644 --- a/app/views/student_works/shixun_work.json.jbuilder +++ b/app/views/student_works/shixun_work.json.jbuilder @@ -15,6 +15,7 @@ json.efficiency number_with_precision @work.efficiency, precision: 2 json.max_efficiency number_with_precision @homework.max_efficiency, precision: 2 json.passed_time @myshixun.passed_time json.total_spend_time @myshixun.total_spend_time +json.user_score @myshixun.total_score # 关卡完成情况 index = 1 From 9ca32a6d1a1a8bfb28c929ca13ff061baff4dca2 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 25 Jun 2019 18:10:13 +0800 Subject: [PATCH 0251/1015] =?UTF-8?q?=E5=9B=BE=E7=89=87url=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/application_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b4e3baf51..32c4438a6 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -128,7 +128,7 @@ module ApplicationHelper if source.class.to_s == 'User' File.join(relative_path, ["#{source.class}", "#{source.id}"]) else - File.join("/images/avatars", ["#{source.class}", "#{source.id}"]) + File.join("images/avatars", ["#{source.class}", "#{source.id}"]) end elsif source.class.to_s == 'User' str = source.user_extension.try(:gender).to_i == 0 ? "b" : "g" @@ -146,7 +146,7 @@ module ApplicationHelper def shixun_url_to_avatar(shixun) if File.exist?(disk_filename(shixun.class, shixun.id)) - File.join("/images/#{relative_path}", "#{shixun.class}", "#{shixun.id}") + File.join("images/#{relative_path}", "#{shixun.class}", "#{shixun.id}") else File.join("educoder", "index", "shixun", "shixun#{rand(23)}.jpg") end From 0be306704cda33b3ab90eb208d6d974fb9451987 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 18:16:03 +0800 Subject: [PATCH 0252/1015] fix bug --- app/helpers/exercises_helper.rb | 12 ++++++------ app/views/exercises/index.json.jbuilder | 3 ++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 856f808d7..604258c32 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -369,11 +369,11 @@ module ExercisesHelper standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 if standard_answer.count > 0 - multi_each_score = (q.question_score / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 + q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 else - multi_each_score = 0.0 + q_score_1 = 0.0 end - answers_content.update_all(:score => multi_each_score) + answers_content.update_all(:score => q_score_1) score1 = score1 + q.question_score end else @@ -461,13 +461,13 @@ module ExercisesHelper "q_type":q.question_type, "q_position":q.question_number, #该问题的位置 "stand_status":stand_answer, #该问题是否正确,1为正确,0为错误 - "user_score":user_scores #每个问题的总得分 + "user_score":user_scores.round(1) #每个问题的总得分 } ques_stand.push(ques_option) end total_score = score1 + score2 + score5 { - "total_score":total_score, + "total_score":total_score.round(1), "stand_status":ques_stand } end @@ -687,7 +687,7 @@ module ExercisesHelper exercise_user = exercise.exercise_users.find_by(user_id:user.id) time_mill = ex_time * 60 #转为秒 exercise_end_time = exercise.end_time.present? ? exercise.end_time.to_i : 0 - exercise_user_start = exercise_user.present? ? exercise_user.start_at.to_i : 0 + exercise_user_start = exercise_user&.start_at.present? ? exercise_user.start_at.to_i : 0 #用户未开始答题时,即exercise_user_start为0 if exercise_user_start == 0 if (exercise_end_time - time_now_i) > time_mill diff --git a/app/views/exercises/index.json.jbuilder b/app/views/exercises/index.json.jbuilder index d7d51c343..4694ecdf0 100644 --- a/app/views/exercises/index.json.jbuilder +++ b/app/views/exercises/index.json.jbuilder @@ -23,7 +23,8 @@ if @exercises_count > 0 ex_index = exercise_index_show(exercise,@course,@is_teacher_or,@current_user_) json.extract! exercise, :id, :exercise_name,:is_public,:created_at if @is_teacher_or == 2 - json.time get_exercise_left_time(exercise,@current_user_) + second_left = get_exercise_left_time(exercise,@current_user_) + json.time second_left.present? ? (second_left / 60) : nil end json.exercise_status ex_index[:ex_status] From d3e0ecc33afe5bba8f21e085e962cff3256355f3 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 25 Jun 2019 18:17:25 +0800 Subject: [PATCH 0253/1015] fix bug --- app/helpers/export_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index 22c10bdb3..b6720c66c 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -92,7 +92,7 @@ module ExportHelper user_name = t.user&.real_name user_time = format_time(t.updated_at) user_score = t&.score - user_comment = t&.comment + user_comment = t.comment.present? ? t.comment : "--" comment_title = "教师:#{user_name}\n时间:#{user_time.to_s}\n分数:#{user_score.to_s}分\n评语:#{user_comment}\n\n" w_18 = w_18 + comment_title end @@ -164,7 +164,7 @@ module ExportHelper user_name = t.user&.real_name user_time = format_time(t.updated_at) user_score = t&.score - user_comment = t&.comment + user_comment = t.comment.present? ? t.comment : "--" comment_title = "教师:#{user_name}\n时间:#{user_time.to_s}\n分数:#{user_score.to_s}分\n评语:#{user_comment}\n\n" # ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "分" + "\n" + "评语:" + user_comment + "\n\n") w_18 = w_18 + comment_title From f6faab935392c4a07d9f83771ebee3b90cfc5407 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 25 Jun 2019 18:21:50 +0800 Subject: [PATCH 0254/1015] =?UTF-8?q?=E7=BC=93=E5=AD=98=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/edu_setting.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/edu_setting.rb b/app/models/edu_setting.rb index 4b39dea81..aadb6540c 100644 --- a/app/models/edu_setting.rb +++ b/app/models/edu_setting.rb @@ -20,6 +20,6 @@ class EduSetting < ApplicationRecord private def expire_value_cache - Rails.cache.clear(value_cache_key) + Rails.cache.write(value_cache_key, nil) end end From 07e3cf3c862abbb3384b50d3baa3461ec1e7d9ba Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 25 Jun 2019 18:29:03 +0800 Subject: [PATCH 0255/1015] modify code style --- app/controllers/attachments_controller.rb | 64 +++++++++++------------ app/controllers/boards_controller.rb | 43 +++++++-------- 2 files changed, 49 insertions(+), 58 deletions(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 0a89bb3f9..bf5c11856 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -25,51 +25,49 @@ class AttachmentsController < ApplicationController # 2. 上传到云 upload_file = params["file"] || params["#{params[:file_param_name]}"] # 这里的file_param_name是为了方便其他插件名称 uid_logger("#########################file_params####{params["#{params[:file_param_name]}"]}") - if upload_file - folder = edu_setting('attachment_folder') - raise "存储目录未定义" unless folder.present? + raise "未上传文件" unless upload_file - month_folder = current_month_folder - save_path = File.join(folder, month_folder) + folder = edu_setting('attachment_folder') + raise "存储目录未定义" unless folder.present? - ext = file_ext(upload_file.original_filename) + month_folder = current_month_folder + save_path = File.join(folder, month_folder) - local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext) + ext = file_ext(upload_file.original_filename) - content_type = upload_file.content_type.presence || 'application/octet-stream' + local_path, digest = file_save_to_local(save_path, upload_file.tempfile, ext) - remote_path = file_save_to_ucloud(local_path[folder.size, local_path.size], local_path, content_type) + content_type = upload_file.content_type.presence || 'application/octet-stream' - logger.info "local_path: #{local_path}" - logger.info "remote_path: #{remote_path}" + remote_path = file_save_to_ucloud(local_path[folder.size, local_path.size], local_path, content_type) + logger.info "local_path: #{local_path}" + logger.info "remote_path: #{remote_path}" - disk_filename = local_path[save_path.size + 1, local_path.size] - #存数据库 - # - @attachment = Attachment.where(disk_filename: disk_filename, - author_id: current_user.id, - cloud_url: remote_path).first - unless @attachment.present? - @attachment = Attachment.new - @attachment.filename = upload_file.original_filename - @attachment.disk_filename = local_path[save_path.size + 1, local_path.size] - @attachment.filesize = upload_file.tempfile.size - @attachment.content_type = content_type - @attachment.digest = digest - @attachment.author_id = current_user.id - @attachment.disk_directory = month_folder - @attachment.cloud_url = remote_path - @attachment.save! - else - logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}" - end + disk_filename = local_path[save_path.size + 1, local_path.size] + #存数据库 + # + @attachment = Attachment.where(disk_filename: disk_filename, + author_id: current_user.id, + cloud_url: remote_path).first - render_json + if @attachment.blank? + @attachment = Attachment.new + @attachment.filename = upload_file.original_filename + @attachment.disk_filename = local_path[save_path.size + 1, local_path.size] + @attachment.filesize = upload_file.tempfile.size + @attachment.content_type = content_type + @attachment.digest = digest + @attachment.author_id = current_user.id + @attachment.disk_directory = month_folder + @attachment.cloud_url = remote_path + @attachment.save! else - raise "未上传文件" + logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}" end + + render_json end def destroy diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index 51c8397b1..2e82c36d7 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -9,46 +9,39 @@ class BoardsController < ApplicationController end def show - - end - - def new end def create ActiveRecord::Base.transaction do - begin - board = @course.course_board - new_board = Board.new(board_params) - new_board.course_id = @course.id - new_board.project_id = -1 - new_board.parent_id = board.try(:id) - new_board.position = board.children.count + 1 - new_board.save! - normal_status(0, "添加成功") - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback - end + board = @course.course_board + new_board = Board.new(board_params) + new_board.course_id = @course.id + new_board.project_id = -1 + new_board.parent_id = board.try(:id) + new_board.position = board.children.count + 1 + new_board.save! end + + normal_status(0, "添加成功") end # 子目录的拖动 def move_category tip_exception("移动失败") if params[:position].blank? - unless params[:position].to_i == @board.position - course_board = @course.course_board + return normal_status(-1, "位置没有变化") if params[:position].to_i == @board.position + + course_board = @course.course_board + ActiveRecord::Base.transaction do if params[:position].to_i < @board.position - course_board.children.where("position < #{@board.position} and position >= ?", params[:position]).update_all("position = position + 1") + course_board.children.where("position < ? and position >= ?", @board.position, params[:position]) + .update_all("position = position + 1") else - course_board.children.where("position > #{@board.position} and position <= ?", params[:position]).update_all("position = position - 1") + course_board.children.where("position > ? and position <= ?", @board.position, params[:position]) + .update_all("position = position - 1") end @board.update_attributes(position: params[:position]) - normal_status(0, "移动成功") - else - normal_status(-1, "位置没有变化") end + normal_status(0, "移动成功") end def destroy From 264ffe91439482092b9a19dccc8823f7d825c9cd Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 25 Jun 2019 18:40:02 +0800 Subject: [PATCH 0256/1015] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=93=E5=AD=98?= =?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/models/edu_setting.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/edu_setting.rb b/app/models/edu_setting.rb index aadb6540c..835aaec76 100644 --- a/app/models/edu_setting.rb +++ b/app/models/edu_setting.rb @@ -20,6 +20,6 @@ class EduSetting < ApplicationRecord private def expire_value_cache - Rails.cache.write(value_cache_key, nil) + Rails.cache.write(value_cache_key, value) end end From 81e25bd77cd32bc41564940a461255b4391e74d8 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 26 Jun 2019 09:06:53 +0800 Subject: [PATCH 0257/1015] =?UTF-8?q?=E5=BC=80=E5=8F=91=E7=A4=BE=E5=8C=BA?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shixuns/index.json.jbuilder | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/views/shixuns/index.json.jbuilder b/app/views/shixuns/index.json.jbuilder index 41da7120f..8e5d49a34 100644 --- a/app/views/shixuns/index.json.jbuilder +++ b/app/views/shixuns/index.json.jbuilder @@ -1,7 +1,8 @@ -if @fuzzy_searchs - json.keyword @fuzzy_searchs - json.total_count @fuzzy_searchs.blank? ? nil : @total_count -end +# if @fuzzy_searchs +# json.keyword @fuzzy_searchs +# json.total_count @fuzzy_searchs.blank? ? nil : @total_count +# end +json.total_count @total_count json.pagination @total_count > 16 ? true : false json.search_tags @search_tags json.shixuns do From d21c46339bb23595d32b04de9da259e762a56491 Mon Sep 17 00:00:00 2001 From: jasder Date: Wed, 26 Jun 2019 09:58:59 +0800 Subject: [PATCH 0258/1015] ADD competition some eelated featrue --- app/controllers/messages_controller.rb | 8 +++++++- app/models/message.rb | 2 +- app/views/messages/reply_list.json.jbuilder | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 60a1c171c..33f4e5bfb 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -43,9 +43,15 @@ class MessagesController < ApplicationController @page_size = params[:page_size] || 10 @current_user = current_user || nil - @messages = @message.children.preload_messages + @messages = @message.children.preload_messages.includes(:message_detail, :praise_treads) @messages = @messages.ordered(sort: 1) unless @message.parent_id.nil? + @user_course_identity = current_user.course_identity(@message.board.course) + case @user_course_identity + when 5 || 6 || 7 + @messages = @messages.visible + end + @messages = @messages.page(@page).per(@page_size) end diff --git a/app/models/message.rb b/app/models/message.rb index c3b3bca40..6b41cdd95 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -18,7 +18,7 @@ class Message < ApplicationRecord scope :root_nodes, -> { where("parent_id IS NULL") } #判断该信息是帖子还是回复。null为发布的帖子 scope :reply_nodes, -> { where("parent_id IS NOT NULL") } - scope :visible, -> { where(is_hidden: false)} + scope :visible, -> { where(is_hidden: false) } scope :by_user, ->(user) { visible if user.nil? || !user.admin? } scope :preload_messages, -> { includes(:author, :message_detail) } scope :short, -> { select(:id, :subject, :created_on, :replies_count, :visits, :sticky, :praises_count) } diff --git a/app/views/messages/reply_list.json.jbuilder b/app/views/messages/reply_list.json.jbuilder index 2b7ef7178..b5c1ce256 100644 --- a/app/views/messages/reply_list.json.jbuilder +++ b/app/views/messages/reply_list.json.jbuilder @@ -1,6 +1,6 @@ json.partial! "commons/success" json.data do - json.user_course_identity @current_user.course_identity(@message.board.course) + json.user_course_identity @user_course_identity json.id @message.id json.total_count @messages.total_count json.total_replies_count @message.total_replies_count From 06db1820d619dafb495f741340e760caf2e2ef76 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 26 Jun 2019 10:14:12 +0800 Subject: [PATCH 0259/1015] =?UTF-8?q?=E6=9C=AA=E5=88=86=E7=8F=AD=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=9C=A8=E5=AD=90=E5=88=86=E7=8F=AD=E5=89=8D=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/courses_helper.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 226a45570..93b8bfc50 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -247,15 +247,15 @@ module CoursesHelper def left_group_info course group_info = [] if course.course_groups_count > 0 + none_group_count = course.students.where(course_group_id: 0).size + group_info << {category_id: 0, category_name: "未分班", position: course.course_groups.pluck(:position).max.to_i + 1, + category_count: none_group_count, category_type: false, + second_category_url: "/courses/#{@course.id}/course_groups/0"} course.course_groups.each do |course_group| group_info << {category_id: course_group.id, category_name: course_group.name, position: course_group.position, category_count: course_group.course_members_count, category_type: false, second_category_url: "/courses/#{@course.id}/course_groups/#{course_group.id}"} end - none_group_count = course.students.where(course_group_id: 0).size - group_info << {category_id: 0, category_name: "未分班", position: course.course_groups.pluck(:position).max.to_i + 1, - category_count: none_group_count, category_type: false, - second_category_url: "/courses/#{@course.id}/course_groups/0"} end group_info end From 7af7ad8e372bd879de948bde7144eb27d256bab0 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 10:18:54 +0800 Subject: [PATCH 0260/1015] fix calculate_scores --- app/controllers/exercises_controller.rb | 58 +++---- app/helpers/exercises_helper.rb | 198 ++++++++++++------------ app/tasks/exercise_publish_task.rb | 95 +++++++----- 3 files changed, 184 insertions(+), 167 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 2175108fc..4f72a1d46 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -12,10 +12,10 @@ class ExercisesController < ApplicationController before_action :get_exercise_question_counts,only: [:show,:edit,:start_answer,:review_exercise,:blank_exercise,:export_exercise] before_action :validate_publish_time,only: [:commit_setting] #提交设置时,需判断时间是否符合 before_action :check_course_public,only: [:set_public] - before_action :check_user_on_answer,only: [:show,:start_answer,:commit_exercise,:exercise_lists] #判断当前用户在试卷的权限/老师是否属于分班的权限 + before_action :check_user_on_answer,only: [:show,:start_answer,:exercise_lists] #判断当前用户在试卷的权限/老师是否属于分班的权限 before_action :only_student_in,only: [:start_answer] before_action :check_user_id_start_answer,only: [:start_answer,:review_exercise] - before_action :commit_user_exercise,only: [:start_answer,:exercise_lists,:review_exercise] #判断试卷时间到用户是否提交 + # before_action :commit_user_exercise,only: [:start_answer,:exercise_lists,:review_exercise] #已有定时的任务 before_action :check_exercise_time,only: [:commit_exercise] #提交试卷时,判断时间是否超过 before_action :check_exercise_status,only: [:redo_modal,:redo_exercise] before_action :check_exercise_is_end, only: [:review_exercise] @@ -1640,38 +1640,38 @@ class ExercisesController < ApplicationController end def check_exercise_time - @answer_committed_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first + @answer_committed_user = @exercise.exercise_users.exercise_commit_users(current_user.id)&.first if @answer_committed_user.blank? normal_status(404,"答题用户不存在") - elsif @exercise.get_exercise_status(current_user.id) != 2 || @answer_committed_user.commit_status == 1 # - normal_status(-1,"提交错误,试卷已截止/用户已提交!") + # elsif @exercise.get_exercise_status(current_user.id) == 2 && @answer_committed_user.commit_status == 1 #当试卷截止时,会自动提交 + # normal_status(-1,"提交错误,试卷用户已提交!") end end - def commit_user_exercise - @exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id).first #查找当前用户是否有过答题 - if @user_course_identity == Course::STUDENT - if @exercise_user_current.present? - if @exercise.time > 0 && @exercise_user_current.start_at.present? && (@exercise_user_current.commit_status == 0) && - ((@exercise_user_current.start_at + (@exercise.time.to_i + 1).minutes) < Time.now) - #当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制 - objective_score = calculate_student_score(@exercise,current_user)[:total_score] - subjective_score = @exercise_user_current.subjective_score < 0.0 ? 0.0 : @exercise_user_current.subjective_score - total_score = objective_score + subjective_score - commit_option = { - :status => 1, - :commit_status => 1, - :end_at => Time.now, - :objective_score => objective_score, - :score => total_score, - :subjective_score => subjective_score - } - @exercise_user_current.update_attributes(commit_option) - normal_status(0,"已交卷成功!") - end - end - end - end + # def commit_user_exercise + # @exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id)&.first #查找当前用户是否有过答题 + # if @user_course_identity == Course::STUDENT + # if @exercise_user_current.present? + # if @exercise.time > 0 && @exercise_user_current.start_at.present? && (@exercise_user_current.commit_status == 0) && + # ((@exercise_user_current.start_at + (@exercise.time.to_i + 1).minutes) < Time.now) + # #当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制 + # objective_score = calculate_student_score(@exercise,current_user)[:total_score] + # subjective_score = @exercise_user_current.subjective_score < 0.0 ? 0.0 : @exercise_user_current.subjective_score + # total_score = objective_score + subjective_score + # commit_option = { + # :status => 1, + # :commit_status => 1, + # :end_at => Time.now, + # :objective_score => objective_score, + # :score => total_score, + # :subjective_score => subjective_score + # } + # @exercise_user_current.update_attributes(commit_option) + # normal_status(0,"已交卷成功!") + # end + # end + # end + # end #打回重做时的初步判断 def check_exercise_status diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 604258c32..9ea7578f2 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -353,117 +353,123 @@ module ExercisesHelper score5 = 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| - 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.count > 0 - 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 - end + exercise_questions&.each do |q| + begin + if q.question_type != 5 + answers_content = q.exercise_answers.where(user_id: user.id) #学生的答案 else - score1 += 0.0 + answers_content = q.exercise_shixun_answers.where(user_id: user.id) #学生的答案 end - elsif q.question_type == 3 #填空题 - if answers_content.present? - null_standard_answer = q.exercise_standard_answers - standard_answer_array = null_standard_answer.select(:exercise_choice_id,:answer_text) - standard_answer_ids = standard_answer_array.pluck(:exercise_choice_id).reject(&:blank?).uniq #标准答案的exercise_choice_id数组 - standard_answer_count = standard_answer_ids.count - if standard_answer_count > 0 #存在标准答案时才有分数 - q_score_2 = (q.question_score.to_f / standard_answer_count) #每一空的得分 - else - q_score_2 = 0.0 - end - if q.is_ordered - answers_content.each do |u| - i_standard_answer = standard_answer_array.where(exercise_choice_id:u.exercise_choice_id).pluck(:answer_text).reject(&:blank?).map!(&:downcase) #该选项的全部标准答案 - if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数 - u.update_column('score',q_score_2) - score2 = score2 + q_score_2 + 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.count > 0 + 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 end else - st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map!(&:downcase) - answers_content.each do |u| - u_answer_text = u.answer_text.downcase - if st_answer_text.include?(u_answer_text) #只要标准答案包含用户的答案,就有分数。同时,下一次循环时,就会删除该标准答案。防止用户的相同答案获分 - u.update_column("score",q_score_2) - score2 = score2 + q_score_2 - st_answer_text.delete(u_answer_text) + score1 += 0.0 + end + elsif q.question_type == 3 #填空题 + if answers_content.present? + null_standard_answer = q.exercise_standard_answers + standard_answer_array = null_standard_answer.select(:exercise_choice_id,:answer_text) + standard_answer_ids = standard_answer_array.pluck(:exercise_choice_id).reject(&:blank?).uniq #标准答案的exercise_choice_id数组 + standard_answer_count = standard_answer_ids.count + if standard_answer_count > 0 #存在标准答案时才有分数 + q_score_2 = (q.question_score.to_f / standard_answer_count) #每一空的得分 + else + q_score_2 = 0.0 + end + if q.is_ordered + answers_content.each do |u| + i_standard_answer = standard_answer_array.where(exercise_choice_id:u.exercise_choice_id).pluck(:answer_text).reject(&:blank?).map!(&:downcase) #该选项的全部标准答案 + if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数 + u.update_column('score',q_score_2) + score2 = score2 + q_score_2 + end + end + else + st_answer_text = standard_answer_array.pluck(:answer_text).reject(&:blank?).map!(&:downcase) + answers_content.each do |u| + u_answer_text = u.answer_text.downcase + if st_answer_text.include?(u_answer_text) #只要标准答案包含用户的答案,就有分数。同时,下一次循环时,就会删除该标准答案。防止用户的相同答案获分 + u.update_column("score",q_score_2) + score2 = score2 + q_score_2 + st_answer_text.delete(u_answer_text) + end end end + else + score2 += 0.0 end - else - score2 += 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 - 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) - if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 - 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) + 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 + 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) + if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 + 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(exercise_cha.shixun&.repo_path,cha_path) + end + sx_option = { + :exercise_question_id => q.id, + :exercise_shixun_challenge_id => exercise_cha.id, + :user_id => user.id, + :score => exercise_cha_score, + :answer_text => code, + :status => answer_status + } + ExerciseShixunAnswer.create(sx_option) else - code = git_fle_content(exercise_cha.shixun&.repo_path,cha_path) + ex_shixun_answer_content.first.update_column('score',exercise_cha_score) end - sx_option = { - :exercise_question_id => q.id, - :exercise_shixun_challenge_id => exercise_cha.id, - :user_id => user.id, - :score => exercise_cha_score, - :answer_text => code, - :status => answer_status - } - ExerciseShixunAnswer.create(sx_option) + score5 += exercise_cha_score else - ex_shixun_answer_content.first.update_column('score',exercise_cha_score) + score5 += 0.0 end - score5 += exercise_cha_score - else - score5 += 0.0 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 - user_scores = answers_content.present? ? answers_content.score_reviewed.pluck(:score).sum : 0.0 - 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) + end total_score = score1 + score2 + score5 { diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb index 4c8ee39e8..3df5f84ae 100644 --- a/app/tasks/exercise_publish_task.rb +++ b/app/tasks/exercise_publish_task.rb @@ -6,7 +6,7 @@ class ExercisePublishTask Rails.logger.info("log--------------------------------exercise_publish start") puts "--------------------------------exercise_publish start" exercises = Exercise.includes(:exercise_users).where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) - exercises.each do |exercise| + exercises&.each do |exercise| exercise.update_column('exercise_status', 2) course = exercise.course tid_str = "" @@ -45,7 +45,7 @@ class ExercisePublishTask # 分组设置发布时间的测验 exercise_group_settings = ExerciseGroupSetting.where("publish_time < ? and publish_time > ?", Time.now + 900, Time.now - 900) - exercise_group_settings.each do |exercise_group| + exercise_group_settings&.each do |exercise_group| exercise = exercise_group.exercise if exercise.present? course = exercise.course @@ -71,29 +71,35 @@ class ExercisePublishTask puts "--------------------------------exercise_end start" # 1。统一设置的试卷 exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND unified_setting = true AND end_time <= ?",Time.now + 900) - exercises.each do |exercise| + exercises&.each do |exercise| ex_type = exercise.exercise_questions.pluck(:question_type).uniq exercise.update_column('exercise_status', 3) - exercise.exercise_users.each do |exercise_user| - if exercise_user&.commit_status == 0 && exercise_user&.start_at.present? - s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] - if ex_type.include?(4) #是否包含主观题 - subjective_score = exercise_user.subjective_score - else - subjective_score = -1.0 + exercise.exercise_users&.each do |exercise_user| + begin + if (exercise_user&.commit_status == 0) && (exercise_user&.start_at.present?) + s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] + if ex_type.include?(4) #是否包含主观题 + subjective_score = exercise_user.subjective_score + else + subjective_score = -1.0 + end + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = s_score + total_score_subjective_score + commit_option = { + :status => 1, + :commit_status => 1, + :end_at => Time.now, + :objective_score => s_score, + :score => total_score, + :subjective_score => subjective_score + } + exercise_user.update_attributes(commit_option) end - total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - total_score = s_score + total_score_subjective_score - commit_option = { - :status => 1, - :commit_status => 1, - :end_at => Time.now, - :objective_score => s_score, - :score => total_score, - :subjective_score => subjective_score - } - exercise_user.update_attributes(commit_option) + rescue Exception => e + Rails.logger.info("rescue errors ___________________________#{e}") + next end + end end @@ -101,36 +107,41 @@ class ExercisePublishTask all_exercises = Exercise.includes(:exercise_group_settings,:exercise_users,:exercise_questions).where("unified_setting = false AND exercise_status = 2 AND end_time > ?",Time.now + 900) exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")" ex_group_settings = ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}") - ex_group_settings.each do |exercise_setting| + ex_group_settings&.each do |exercise_setting| exercise = exercise_setting.exercise - if exercise&.end_time <= Time.now + if exercise.end_time <= Time.now exercise.update_column('exercise_status', 3) end ex_types = exercise.exercise_questions.pluck(:question_type).uniq users = exercise.course.students.where(:course_group_id => exercise_setting.course_group_id) exercise_users = exercise.exercise_users.where(:user_id => users.pluck(:user_id)) - - exercise_users.each do |exercise_user| - if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? - if ex_types.include?(4) #是否包含主观题 - subjective_score = exercise_user.subjective_score - else - subjective_score = -1.0 + exercise_users&.each do |exercise_user| + begin + if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? + if ex_types.include?(4) #是否包含主观题 + subjective_score = exercise_user.subjective_score + else + subjective_score = -1.0 + end + s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = s_score + total_score_subjective_score + commit_option = { + :status => 1, + :commit_status => 1, + :end_at => Time.now, + :objective_score => s_score, + :score => total_score, + :subjective_score => subjective_score + } + exercise_user.update_attributes(commit_option) end - s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] - total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - total_score = s_score + total_score_subjective_score - commit_option = { - :status => 1, - :commit_status => 1, - :end_at => Time.now, - :objective_score => s_score, - :score => total_score, - :subjective_score => subjective_score - } - exercise_user.update_attributes(commit_option) + rescue Exception => e + Rails.logger.info("unified_setting_false_rescue errors ___________________________#{e}") + next end + end end Rails.logger.info("log--------------------------------exercise_end end") From d8e7d8203c9533fa5dd57122bd44da0859813001 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 10:32:15 +0800 Subject: [PATCH 0261/1015] fix bug --- app/controllers/exercises_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 4f72a1d46..f10bc81ff 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1006,6 +1006,7 @@ class ExercisesController < ApplicationController def start_answer ActiveRecord::Base.transaction do begin + @exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id)&.first if @exercise_user_current.blank? if @user_course_identity > Course::ASSISTANT_PROFESSOR #当为老师的时候,不创建exercise_user表,理论上老师是不能进入答题的 exercise_user_params = { From 5689b2924349f9be0b42c00ff66462a8f2796b10 Mon Sep 17 00:00:00 2001 From: jasder Date: Wed, 26 Jun 2019 10:46:20 +0800 Subject: [PATCH 0262/1015] FIX --- app/controllers/messages_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 33f4e5bfb..bad54b88e 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -48,7 +48,7 @@ class MessagesController < ApplicationController @user_course_identity = current_user.course_identity(@message.board.course) case @user_course_identity - when 5 || 6 || 7 + when 5, 6, 7 @messages = @messages.visible end From 870952ecda289510032e0b837f79d53b1edea760 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 26 Jun 2019 11:20:30 +0800 Subject: [PATCH 0263/1015] =?UTF-8?q?=E4=BD=9C=E5=93=81=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 4 ++-- app/helpers/homework_commons_helper.rb | 12 +++++----- app/models/homework_common.rb | 24 +++++++++---------- .../homework_commons/index.json.jbuilder | 4 ++-- .../homework_commons/works_list.json.jbuilder | 6 ++--- 5 files changed, 25 insertions(+), 25 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 58e68dfce..e58484941 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -89,7 +89,7 @@ class HomeworkCommonsController < ApplicationController @homework_commons = @homework_commons.page(page).per(15) if @homework_type == 4 - @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns) + @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns, :student_works) elsif @homework_type == 3 @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :homework_detail_group) else @@ -134,7 +134,7 @@ class HomeworkCommonsController < ApplicationController @student_works = [] end elsif @user_course_identity < Course::STUDENT - @student_works = @homework.teacher_works(@current_user.id) + @student_works = @homework.teacher_works(@member) @all_member_count = @student_works.count elsif @user_course_identity > Course::STUDENT && @homework.work_public @student_works = student_works diff --git a/app/helpers/homework_commons_helper.rb b/app/helpers/homework_commons_helper.rb index 0d166729c..2d3827fac 100644 --- a/app/helpers/homework_commons_helper.rb +++ b/app/helpers/homework_commons_helper.rb @@ -174,8 +174,8 @@ module HomeworkCommonsHelper end # 作品数统计:type: 1 已提交 0 未提交 - def studentwork_count homework_common, type, user_id - student_works = homework_common.teacher_works(user_id) + def studentwork_count homework_common, type, member + student_works = homework_common.teacher_works(member) type == 1 ? student_works.select{|work| work.work_status != 0}.size : student_works.select{|work| work.work_status = 0}.size end @@ -223,10 +223,10 @@ module HomeworkCommonsHelper end # 作品状态 - def homework_status homework, user_id - [{id: 0, name: "未提交", count: homework.unfinished_count(user_id)}, - {id: 1, name: "按时提交", count: homework.finished_count(user_id)}, - {id: 2, name: "延时提交", count: homework.delay_finished_count(user_id)}] + def homework_status homework, member + [{id: 0, name: "未提交", count: homework.unfinished_count(member)}, + {id: 1, name: "按时提交", count: homework.finished_count(member)}, + {id: 2, name: "延时提交", count: homework.delay_finished_count(member)}] end # 作品分数的显示 diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index c3bfd2dd9..6a117eff1 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -78,20 +78,20 @@ class HomeworkCommon < ApplicationRecord # 根据是否统一发布获取作业的作品列表 def all_works student_works = self.unified_setting ? self.student_works : - self.student_works.where(user_id: self.course.students.where( - course_group_id: self.published_settings.pluck(:course_group_id)). - pluck(:user_id)) + self.student_works.joins("join course_members cm on student_works.user_id=cm.user_id"). + where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)}) end # 分班权限的老师可见的作品列表 - def teacher_works user_id - member = course.course_member(user_id) + def teacher_works member + # member = course.course_member(user_id) teacher_course_groups = member.try(:teacher_course_groups) all_student_works = self.all_works # 有分班权限的统计管理的分班且已发布的学生情况 if member.present? && teacher_course_groups.size > 0 group_ids = teacher_course_groups.pluck(:course_group_id) - all_student_works = all_student_works.where(user_id: course.students.where(course_group_id: group_ids).pluck(:user_id)) + all_student_works = all_student_works.joins("join course_members cm on student_works.user_id=cm.user_id"). + where(course_members: {course_group_id: group_ids}) end all_student_works end @@ -216,17 +216,17 @@ class HomeworkCommon < ApplicationRecord end # 作品未提交数 - def unfinished_count user_id - self.teacher_works(user_id).unfinished.count + def unfinished_count member + self.teacher_works(member).unfinished.count end # 任务按时提交数 - def finished_count user_id - self.teacher_works(user_id).finished.count + def finished_count member + self.teacher_works(member).finished.count end - def delay_finished_count user_id - self.teacher_works(user_id).delay_finished.count + def delay_finished_count member + self.teacher_works(member).delay_finished.count end # 分组作业的最大分组id diff --git a/app/views/homework_commons/index.json.jbuilder b/app/views/homework_commons/index.json.jbuilder index 262d4d92d..d718550c1 100644 --- a/app/views/homework_commons/index.json.jbuilder +++ b/app/views/homework_commons/index.json.jbuilder @@ -23,8 +23,8 @@ json.homeworks @homework_commons.each do |homework| json.allow_late homework.allow_late unless curr_status[:status].include?("未发布") - json.commit_count studentwork_count homework, 1, @user.id - json.uncommit_count studentwork_count homework, 0, @user.id + json.commit_count studentwork_count homework, 1, @member + json.uncommit_count studentwork_count homework, 0, @member end if @user_course_identity < Course::STUDENT diff --git a/app/views/homework_commons/works_list.json.jbuilder b/app/views/homework_commons/works_list.json.jbuilder index a1618d8ff..0c1ed0c5b 100644 --- a/app/views/homework_commons/works_list.json.jbuilder +++ b/app/views/homework_commons/works_list.json.jbuilder @@ -20,12 +20,12 @@ if @user_course_identity < Course::STUDENT if @homework.homework_type != "practice" json.teacher_comment teacher_comment @homework, @current_user.id end - json.task_status homework_status @homework, @current_user.id + json.task_status homework_status @homework, @member json.course_group_info course_group_info @course, @current_user.id elsif @user_course_identity == Course::STUDENT - json.commit_count studentwork_count @homework, 1, @current_user.id - json.uncommit_count studentwork_count @homework, 0, @current_user.id + json.commit_count studentwork_count @homework, 1, @member + json.uncommit_count studentwork_count @homework, 0, @member json.left_time left_time @homework, @current_user.id if @homework.homework_type == "practice" From 88f9dbc68e531113dbb190aa2233ea9027285cb6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 26 Jun 2019 11:23:10 +0800 Subject: [PATCH 0264/1015] =?UTF-8?q?=E4=BD=9C=E5=93=81=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index e58484941..3aacd71fa 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -89,7 +89,7 @@ class HomeworkCommonsController < ApplicationController @homework_commons = @homework_commons.page(page).per(15) if @homework_type == 4 - @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns, :student_works) + @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns) elsif @homework_type == 3 @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :homework_detail_group) else From 383723612df1075ac165c82b34d2481a434557a7 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 26 Jun 2019 11:28:51 +0800 Subject: [PATCH 0265/1015] =?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/models/homework_common.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 6a117eff1..9cc2c9a69 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -78,7 +78,7 @@ class HomeworkCommon < ApplicationRecord # 根据是否统一发布获取作业的作品列表 def all_works student_works = self.unified_setting ? self.student_works : - self.student_works.joins("join course_members cm on student_works.user_id=cm.user_id"). + self.student_works.joins("join course_members on student_works.user_id=course_members.user_id"). where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)}) end @@ -90,7 +90,7 @@ class HomeworkCommon < ApplicationRecord # 有分班权限的统计管理的分班且已发布的学生情况 if member.present? && teacher_course_groups.size > 0 group_ids = teacher_course_groups.pluck(:course_group_id) - all_student_works = all_student_works.joins("join course_members cm on student_works.user_id=cm.user_id"). + all_student_works = all_student_works.joins("join course_members course_members on student_works.user_id=course_members.user_id"). where(course_members: {course_group_id: group_ids}) end all_student_works From e22ec14690dbaa202cf44c8f9ab1a32b1413918d Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 12:26:07 +0800 Subject: [PATCH 0266/1015] fix bug --- app/controllers/poll_votes_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/poll_votes_controller.rb b/app/controllers/poll_votes_controller.rb index 789d5748e..644cc8949 100644 --- a/app/controllers/poll_votes_controller.rb +++ b/app/controllers/poll_votes_controller.rb @@ -123,7 +123,7 @@ class PollVotesController < ApplicationController if @poll_question.blank? normal_status(-1,"问卷试题不存在!") else - @poll = @poll_question.poll.includes(:poll_users) + @poll = @poll_question.poll @course = @poll.course if @poll.blank? normal_status(-1,"问卷不存在!") From 650df60bedfe4291b563a4cf12a7cb3173353978 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 12:28:53 +0800 Subject: [PATCH 0267/1015] fix bug --- app/controllers/poll_votes_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/poll_votes_controller.rb b/app/controllers/poll_votes_controller.rb index 644cc8949..813e35bba 100644 --- a/app/controllers/poll_votes_controller.rb +++ b/app/controllers/poll_votes_controller.rb @@ -156,7 +156,7 @@ class PollVotesController < ApplicationController if question_max_choices > 0 && user_vote_count > question_max_choices normal_status(-1,"多选题答案超过最大限制!") end - elsif (poll_user.present? && poll_user&.commit_status) || poll_user_status == 3 + elsif (poll_user.present? && poll_user.commit_status == 1) || poll_user_status == 3 normal_status(-1,"已提交/已结束的问卷不允许修改!") end end From 102226efdf58584d941bc96665ce8309b4ccc234 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 12:32:00 +0800 Subject: [PATCH 0268/1015] fix bug --- app/controllers/poll_votes_controller.rb | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/app/controllers/poll_votes_controller.rb b/app/controllers/poll_votes_controller.rb index 813e35bba..f1da3a1b2 100644 --- a/app/controllers/poll_votes_controller.rb +++ b/app/controllers/poll_votes_controller.rb @@ -134,17 +134,11 @@ class PollVotesController < ApplicationController end def check_answer_in_question - # poll_answer_ids = @poll_question.poll_answers.pluck(:id) - # if @poll_question.question_type == 1 #单选题/多选题 - # unless (params[:poll_answer_id].present? && poll_answer_ids.include?(params[:poll_answer_id].to_i)) || (params[:poll_answer_id].blank? && params[:vote_text].present?) - # normal_status(-1, "答案ID错误!") - # end - # end poll_user_status = @poll.get_poll_status(current_user.id) poll_user = @poll.poll_users.find_by(user_id: current_user.id) #当前用户 question_type = @poll_question&.question_type - if [1,2].include?(question_type) && params[:poll_answer_id].blank? + if (question_type == 1) && params[:poll_answer_id].blank? normal_status(-1,"答案ID错误!") elsif question_type == 2 user_vote_count = params[:poll_answer_id].size @@ -153,7 +147,7 @@ class PollVotesController < ApplicationController else question_max_choices = 0 end - if question_max_choices > 0 && user_vote_count > question_max_choices + if question_max_choices > 0 && (user_vote_count > question_max_choices) normal_status(-1,"多选题答案超过最大限制!") end elsif (poll_user.present? && poll_user.commit_status == 1) || poll_user_status == 3 From e808b0bb3d366192829fd4519104cfc1e5fa5186 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 26 Jun 2019 13:59:37 +0800 Subject: [PATCH 0269/1015] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E5=88=97=E8=A1=A8?= =?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/helpers/homework_commons_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/homework_commons_helper.rb b/app/helpers/homework_commons_helper.rb index 2d3827fac..261fc85e9 100644 --- a/app/helpers/homework_commons_helper.rb +++ b/app/helpers/homework_commons_helper.rb @@ -176,7 +176,7 @@ module HomeworkCommonsHelper # 作品数统计:type: 1 已提交 0 未提交 def studentwork_count homework_common, type, member student_works = homework_common.teacher_works(member) - type == 1 ? student_works.select{|work| work.work_status != 0}.size : student_works.select{|work| work.work_status = 0}.size + type == 1 ? student_works.where("work_status != 0").size : student_works.where(work_status: 0).size end # 上次查重的时间 From b6300cfc846fa030b2823dc6e2a93e69c01b1a67 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 14:31:37 +0800 Subject: [PATCH 0270/1015] fix bug --- app/controllers/poll_questions_controller.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/poll_questions_controller.rb b/app/controllers/poll_questions_controller.rb index 69aef41c0..59af29758 100644 --- a/app/controllers/poll_questions_controller.rb +++ b/app/controllers/poll_questions_controller.rb @@ -197,22 +197,22 @@ class PollQuestionsController < ApplicationController begin opr = params[:opr] current_q_p = @poll_question.question_number.to_i #问题的当前位置 - last_q_p = @poll.poll_questions.last_poll(current_q_p) #当前问题的前一个问题 - next_q_p = @poll.poll_questions.next_poll(current_q_p) # 当前问题的后一个问题 if @poll.polls_status.to_i == 1 if opr.present? if opr.to_s == "up" + last_q_p = @poll.poll_questions.last_poll(current_q_p) #当前问题的前一个问题 if last_q_p.present? - @poll_question.update_attribute(:question_number, (current_q_p - 1)) - last_q_p.update_attribute(:question_number, (@poll_question.question_number.to_i + 1)) # 重新获取当前问题的位置 + @poll_question.update_attribute("question_number", (current_q_p - 1)) + last_q_p.update_attribute("question_number", current_q_p) # 重新获取当前问题的位置 normal_status(0, "问题上移成功!") else normal_status(-1, "移动失败,已经是第一个问题了!") end elsif opr.to_s == "down" + next_q_p = @poll.poll_questions.next_poll(current_q_p) #当前问题的后一个问题 if next_q_p.present? - @poll_question.update_attribute(:question_number, (current_q_p + 1)) - next_q_p.update_attribute(:question_number, (@poll_question.question_number.to_i - 1)) + @poll_question.update_attribute("question_number", (current_q_p + 1)) + next_q_p.update_attribute("question_number", current_q_p) normal_status(0, "问题下移成功!") else normal_status(-1, "移动失败,已经是最后一个问题了!") From d0249457473611d77d6a01de9a6b5224248286e0 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 14:41:33 +0800 Subject: [PATCH 0271/1015] fix bug --- app/controllers/poll_questions_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/poll_questions_controller.rb b/app/controllers/poll_questions_controller.rb index 59af29758..dfff147c4 100644 --- a/app/controllers/poll_questions_controller.rb +++ b/app/controllers/poll_questions_controller.rb @@ -202,8 +202,8 @@ class PollQuestionsController < ApplicationController if opr.to_s == "up" last_q_p = @poll.poll_questions.last_poll(current_q_p) #当前问题的前一个问题 if last_q_p.present? - @poll_question.update_attribute("question_number", (current_q_p - 1)) last_q_p.update_attribute("question_number", current_q_p) # 重新获取当前问题的位置 + @poll_question.update_attribute("question_number", (current_q_p - 1)) normal_status(0, "问题上移成功!") else normal_status(-1, "移动失败,已经是第一个问题了!") @@ -211,8 +211,8 @@ class PollQuestionsController < ApplicationController elsif opr.to_s == "down" next_q_p = @poll.poll_questions.next_poll(current_q_p) #当前问题的后一个问题 if next_q_p.present? - @poll_question.update_attribute("question_number", (current_q_p + 1)) next_q_p.update_attribute("question_number", current_q_p) + @poll_question.update_attribute("question_number", (current_q_p + 1)) normal_status(0, "问题下移成功!") else normal_status(-1, "移动失败,已经是最后一个问题了!") From d10567926b923bed180ffd519ed40b79a74d4d9f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 26 Jun 2019 14:55:47 +0800 Subject: [PATCH 0272/1015] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E9=80=89=E9=A2=98?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E9=A2=98=E5=BA=93=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/graduation_topics_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index a6903dbc7..ce4488ffd 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -223,7 +223,7 @@ class GraduationTopicsController < ApplicationController # 已加入的更新,未加入的新建 if topic_bank.present? - topic_bank.update_attributes(name: topic, description: topic.description, + topic_bank.update_attributes(name: topic.name, description: topic.description, topic_source: topic.topic_source, topic_property_first: topic.topic_property_first, topic_property_second: topic.topic_property_second, @@ -234,7 +234,7 @@ class GraduationTopicsController < ApplicationController course_list_id: @course.course_list_id) topic_bank.attachments.destroy_all else - topic_bank = GtopicBank.new(name: topic, description: topic.description, + topic_bank = GtopicBank.new(name: topic.name, description: topic.description, topic_source: topic.topic_source, topic_property_first: topic.topic_property_first, topic_property_second: topic.topic_property_second, From 6e88b1adbb584e583f2668423f481abfcfdedaf9 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 14:58:24 +0800 Subject: [PATCH 0273/1015] fix but --- app/controllers/poll_questions_controller.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/poll_questions_controller.rb b/app/controllers/poll_questions_controller.rb index dfff147c4..74c73968c 100644 --- a/app/controllers/poll_questions_controller.rb +++ b/app/controllers/poll_questions_controller.rb @@ -200,19 +200,21 @@ class PollQuestionsController < ApplicationController if @poll.polls_status.to_i == 1 if opr.present? if opr.to_s == "up" - last_q_p = @poll.poll_questions.last_poll(current_q_p) #当前问题的前一个问题 + last_q_p = @poll.poll_questions.find_by(question_number: (current_q_p-1)) #当前问题的前一个问题 if last_q_p.present? - last_q_p.update_attribute("question_number", current_q_p) # 重新获取当前问题的位置 @poll_question.update_attribute("question_number", (current_q_p - 1)) + last_q_p.update_attribute("question_number", current_q_p) # 重新获取当前问题的位置 + normal_status(0, "问题上移成功!") else normal_status(-1, "移动失败,已经是第一个问题了!") end elsif opr.to_s == "down" - next_q_p = @poll.poll_questions.next_poll(current_q_p) #当前问题的后一个问题 + next_q_p = @poll.poll_questions.find_by(question_number: (current_q_p+1)) #当前问题的后一个问题 if next_q_p.present? - next_q_p.update_attribute("question_number", current_q_p) @poll_question.update_attribute("question_number", (current_q_p + 1)) + next_q_p.update_attribute("question_number", current_q_p) + normal_status(0, "问题下移成功!") else normal_status(-1, "移动失败,已经是最后一个问题了!") From d9608410f69e0726f31e330f3f2e9af6777557ad Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 15:04:09 +0800 Subject: [PATCH 0274/1015] fix bug --- app/controllers/exercise_questions_controller.rb | 10 ++++------ app/controllers/poll_questions_controller.rb | 1 - app/models/exercise_question.rb | 4 ++-- app/models/poll_question.rb | 2 -- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 96951ac48..490791918 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -384,24 +384,22 @@ class ExerciseQuestionsController < ApplicationController begin opr = params[:opr] current_q_p = @exercise_question.question_number.to_i #问题的当前位置 - # last_q_p = @exercise.exercise_questions.find_by_custom("question_number",(current_q_p - 1)).first # 当前问题的前一个问题 - # next_q_p = @exercise.exercise_questions.find_by_custom("question_number",(current_q_p + 1)).first # 当前问题的后一个问题 - last_q_p = @exercise.exercise_questions.last_exercise(current_q_p) # 当前问题的前一个问题 - next_q_p = @exercise.exercise_questions.next_exercise(current_q_p) # 当前问题的后一个问题 if @exercise.exercise_status.to_i == 1 if opr.present? if opr.to_s == "up" + last_q_p = @exercise.exercise_questions.find_by(question_number: (current_q_p - 1)) # 当前问题的前一个问题 if last_q_p.present? @exercise_question.update_attribute('question_number', (current_q_p - 1)) - last_q_p.update_attribute('question_number', (@exercise_question.question_number.to_i + 1)) # 重新获取当前问题的位置 + last_q_p.update_attribute('question_number', current_q_p) # 重新获取当前问题的位置 normal_status(0, "问题上移成功!") else normal_status(-1, "移动失败,已经是第一个问题了!") end elsif opr.to_s == "down" + next_q_p = @exercise.exercise_questions.find_by(question_number: (current_q_p + 1)) # 当前问题的前一个问题 if next_q_p.present? @exercise_question.update_attribute('question_number', (current_q_p + 1)) - next_q_p.update_attribute('question_number', (@exercise_question.question_number.to_i - 1)) + next_q_p.update_attribute('question_number', current_q_p) normal_status(0, "问题下移成功!") else normal_status(-1, "移动失败,已经是最后一个问题了!") diff --git a/app/controllers/poll_questions_controller.rb b/app/controllers/poll_questions_controller.rb index 74c73968c..47cd236a9 100644 --- a/app/controllers/poll_questions_controller.rb +++ b/app/controllers/poll_questions_controller.rb @@ -204,7 +204,6 @@ class PollQuestionsController < ApplicationController if last_q_p.present? @poll_question.update_attribute("question_number", (current_q_p - 1)) last_q_p.update_attribute("question_number", current_q_p) # 重新获取当前问题的位置 - normal_status(0, "问题上移成功!") else normal_status(-1, "移动失败,已经是第一个问题了!") diff --git a/app/models/exercise_question.rb b/app/models/exercise_question.rb index ae58a7592..5f456e21f 100644 --- a/app/models/exercise_question.rb +++ b/app/models/exercise_question.rb @@ -15,8 +15,8 @@ class ExerciseQuestion < ApplicationRecord scope :find_by_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题 - scope :next_exercise, lambda {|k| where("question_number > ?",k).first} - scope :last_exercise, lambda {|k| where("question_number < ?",k).last} + # scope :next_exercise, lambda {|k| where("question_number > ?",k).first} + # scope :last_exercise, lambda {|k| where("question_number < ?",k).last} def question_type_name case self.question_type diff --git a/app/models/poll_question.rb b/app/models/poll_question.rb index 958b69acd..1fc8e0c16 100644 --- a/app/models/poll_question.rb +++ b/app/models/poll_question.rb @@ -8,8 +8,6 @@ class PollQuestion < ApplicationRecord scope :ques_count, lambda {|k| where("question_type = ?",k)} scope :ques_necessary, -> {where("is_necessary = ?",1)} scope :insert_question, lambda {|k| where("question_number > ?",k)} - scope :next_poll, lambda {|k| where("question_number > ?",k).first} - scope :last_poll, lambda {|k| where("question_number < ?",k).last} def question_type_name case self.question_type From c872f8bce375d5242e86e3e333ef126807d30eab Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 26 Jun 2019 15:36:00 +0800 Subject: [PATCH 0275/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=BD=9C=E5=93=81?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E3=80=81=E5=AE=9E=E8=AE=AD=E6=8A=A5=E5=91=8A?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=9A=84=E6=80=A7=E8=83=BD=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 11 ++++++----- app/helpers/courses_helper.rb | 2 +- app/helpers/student_works_helper.rb | 6 +++--- app/models/challenge.rb | 2 +- app/models/homework_common.rb | 2 +- app/models/myshixun.rb | 8 ++++---- .../_homework_public_navigation.json.jbuilder | 2 +- app/views/homework_commons/index.json.jbuilder | 9 +++++---- app/views/homework_commons/works_list.json.jbuilder | 1 - 9 files changed, 22 insertions(+), 21 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 3aacd71fa..4abada488 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -104,7 +104,7 @@ class HomeworkCommonsController < ApplicationController @shixun = @homework.shixuns.take if @homework.homework_type == "practice" student_works = @homework.all_works - @all_member_count = student_works.count + @all_member_count = student_works.size if @homework.publish_time.nil? || @homework.publish_time > Time.now @student_works = [] respond_to do |format| @@ -135,14 +135,14 @@ class HomeworkCommonsController < ApplicationController end elsif @user_course_identity < Course::STUDENT @student_works = @homework.teacher_works(@member) - @all_member_count = @student_works.count + @all_member_count = @student_works.size elsif @user_course_identity > Course::STUDENT && @homework.work_public @student_works = student_works else @student_works = [] end - unless @student_works.size == 0 + unless @student_works.blank? # 教师评阅搜索 0: 未评, 1 已评 unless params[:teacher_comment].blank? student_work_ids = StudentWorksScore.where(student_work_id: @student_works.map(&:id)).pluck(:student_work_id) @@ -187,12 +187,13 @@ class HomeworkCommonsController < ApplicationController # 分页参数 page = params[:page] || 1 limit = params[:limit] || 20 - @student_works = @student_works.page(page).per(limit).includes(:student_works_scores) + @student_works = @student_works.page(page).per(limit) if @homework.homework_type == "practice" - @student_works = @student_works.includes(user: :user_extension, myshixun: :games) + @student_works = @student_works.includes(:student_works_scores, user: :user_extension, myshixun: :games) else @student_works = @student_works.includes(:student_works_scores, :project, user: :user_extension) end + # @members = @course.students.where(user_id: @student_works.pluck(:user_id)).includes(:course_group) end respond_to do |format| format.json diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index 93b8bfc50..fa51de6b7 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -232,7 +232,7 @@ module CoursesHelper course.course_groups.includes(:course_members) end group_info = [] - if course_groups.count > 0 + if !course_groups.blank? course_groups.each do |group| group_info << {course_group_id: group.id, group_group_name: group.name, count: group.course_members_count} end diff --git a/app/helpers/student_works_helper.rb b/app/helpers/student_works_helper.rb index 682bfbf81..17cdd41a7 100644 --- a/app/helpers/student_works_helper.rb +++ b/app/helpers/student_works_helper.rb @@ -54,13 +54,13 @@ module StudentWorksHelper objects = myshixuns.map do |myshixun| # 评测次数 - evaluate_count = myshixun.games.sum(:evaluate_count) + evaluate_count = myshixun.games.pluck(:evaluate_count).sum # 获取最大评测次数 max_evaluate_count = (evaluate_count > max_evaluate_count ? evaluate_count : max_evaluate_count) # 通关耗时 - pass_consume_time = (myshixun.games.where(status: 2).pluck(:cost_time).sum / 60.0) + pass_consume_time = (myshixun.total_cost_time / 60.0) # 总耗时 - all_time = (myshixun.games.sum(:cost_time) / 60.0) + all_time = (myshixun.games.pluck(:cost_time).sum / 60.0) # 通关得分 user_total_score = myshixun.total_score.to_i # 耗时,保留2位小数, diff --git a/app/models/challenge.rb b/app/models/challenge.rb index a5d9874ce..5495dd7a3 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -38,7 +38,7 @@ class Challenge < ApplicationRecord ## 选择题总分 def choose_score - self.challenge_chooses.sum(:score) + self.challenge_chooses.pluck(:score).sum end # 关卡总分 diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 9cc2c9a69..9ed80e746 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -70,7 +70,7 @@ class HomeworkCommon < ApplicationRecord if self.course_second_category.present? {category_id: self.course_second_category.try(:id), category_name: self.course_second_category.try(:name)} else - {category_id: course.shixun_course_modules.first.try(:id), category_name: course.shixun_course_modules.first.try(:module_name)} + {category_id: course.shixun_course_modules.take.try(:id), category_name: course.shixun_course_modules.take.try(:module_name)} end end end diff --git a/app/models/myshixun.rb b/app/models/myshixun.rb index b5bbdc249..e4573f3dd 100644 --- a/app/models/myshixun.rb +++ b/app/models/myshixun.rb @@ -74,12 +74,12 @@ class Myshixun < ApplicationRecord # 个人实训得分 def total_score - self.games.where("status = 2 and final_score > 0").sum(:final_score).to_i + self.games.select{|game| game.status = 2 && game.final_score > 0}.pluck(:final_score).sum.to_i end # 个人通关数 def passed_count - self.games.where(status: 2).count + self.games.select{|game| game.status = 2}.size end # 通关时间 @@ -89,12 +89,12 @@ class Myshixun < ApplicationRecord # 耗时 def total_spend_time - game_spend_time self.games.where(status: 2).sum(:cost_time).to_i + game_spend_time total_cost_time end # 通关总耗时 def total_cost_time - self.games.where(status: 2).sum(:cost_time).to_i + self.games.select{|game| game.status = 2}.map(&:cost_time).sum.to_i end end diff --git a/app/views/homework_commons/_homework_public_navigation.json.jbuilder b/app/views/homework_commons/_homework_public_navigation.json.jbuilder index 2c803bee8..2c548074c 100644 --- a/app/views/homework_commons/_homework_public_navigation.json.jbuilder +++ b/app/views/homework_commons/_homework_public_navigation.json.jbuilder @@ -10,5 +10,5 @@ json.homework_name homework.name json.homework_id homework.id json.homework_type homework.homework_type if homework.homework_type == "practice" - json.shixun_identifier homework.shixuns.first.try(:identifier) + json.shixun_identifier homework.shixuns.take.try(:identifier) end diff --git a/app/views/homework_commons/index.json.jbuilder b/app/views/homework_commons/index.json.jbuilder index d718550c1..5b9717c2f 100644 --- a/app/views/homework_commons/index.json.jbuilder +++ b/app/views/homework_commons/index.json.jbuilder @@ -2,10 +2,6 @@ json.course_identity @user_course_identity json.homework_type @homework_type json.course_public @course.is_public == 1 json.is_end @course.is_end -json.all_count @all_count -json.published_count @published_count -json.unpublished_count @all_count - @published_count -json.task_count @task_count json.main_category_id @main_category.try(:id) json.main_category_name @main_category.try(:module_name) json.category_id @category.try(:id) @@ -46,3 +42,8 @@ json.homeworks @homework_commons.each do |homework| end end +json.all_count @all_count +json.published_count @published_count +json.unpublished_count @all_count - @published_count +json.task_count @task_count + diff --git a/app/views/homework_commons/works_list.json.jbuilder b/app/views/homework_commons/works_list.json.jbuilder index 0c1ed0c5b..42d4abf48 100644 --- a/app/views/homework_commons/works_list.json.jbuilder +++ b/app/views/homework_commons/works_list.json.jbuilder @@ -101,7 +101,6 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal" json.anonymous_appeal @homework.anonymous_appeal json.student_works @student_works.each do |work| - if @is_evaluation json.(work, :id, :work_status, :update_time) From 79d99f10cad0db729d16dd2c37014f11ba72ec51 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 15:36:43 +0800 Subject: [PATCH 0276/1015] fix bug --- app/views/polls/commit_result.xlsx.axlsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/views/polls/commit_result.xlsx.axlsx b/app/views/polls/commit_result.xlsx.axlsx index ce1817f76..be27d73c5 100644 --- a/app/views/polls/commit_result.xlsx.axlsx +++ b/app/views/polls/commit_result.xlsx.axlsx @@ -1,6 +1,6 @@ wb = xlsx_package.workbook -wb.use_autowidth = false +# wb.use_autowidth = false wb.styles do |s| sz_all = s.add_style :sz => 10,:border => { :style => :thin, :color =>"000000"},:alignment => {:horizontal => :left} blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :left} @@ -9,8 +9,6 @@ wb.styles do |s| sheet.sheet_view.show_grid_lines = false poll_users_info = %w(序号) poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?} - - poll_ques_ids = poll_questions.pluck(:id).sort #问题的全部id poll_un_anony = @poll.un_anonymous if poll_un_anony #是否匿名,默认为false user_info = %w(登陆名 真实姓名 邮箱 学号) From b86b7ac3528b56868a510a94054c4b9c75498d65 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 26 Jun 2019 15:53:06 +0800 Subject: [PATCH 0277/1015] =?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/student_works_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 7e23443d2..31c198fd8 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -434,7 +434,7 @@ class StudentWorksController < ApplicationController # 用户最大评测次数 if @games - @user_evaluate_count = @games.sum(:evaluate_count) + @user_evaluate_count = @games.pluck(:evaluate_count).sum @games = @games.includes(:challenge, :game_codes, :outputs) else @user_evaluate_count = 0 @@ -450,7 +450,7 @@ class StudentWorksController < ApplicationController @games = @work.myshixun.games.includes(:challenge, :game_codes, :outputs) if @work.myshixun # 用户最大评测次数 - @user_evaluate_count = @games.sum(:evaluate_count) if @games + @user_evaluate_count = @games.pluck(:evaluate_count).sum if @games # 图形效率图的数据 @echart_data = student_efficiency(@homework, @work) @myself_eff = @echart_data[:efficiency_list].find { |item| item.last == @user.id } From a8fb8c32f3688efe360d748d3af6769aef7971c0 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 16:43:06 +0800 Subject: [PATCH 0278/1015] fix bug --- app/views/polls/commit_result.xlsx.axlsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/views/polls/commit_result.xlsx.axlsx b/app/views/polls/commit_result.xlsx.axlsx index be27d73c5..f949af10a 100644 --- a/app/views/polls/commit_result.xlsx.axlsx +++ b/app/views/polls/commit_result.xlsx.axlsx @@ -30,19 +30,19 @@ wb.styles do |s| sheet_answer_row.push(answer_users_count) sheet_answer_percent.push(answer_percent.to_s) end - sheet.add_row sheet_row, :style => blue_cell - sheet.add_row sheet_answer_row, :style => sz_all - sheet.add_row sheet_answer_percent, :style => sz_all - sheet.add_row sheet_answer_useful, :style => sz_all + sheet.add_row sheet_row, :height =>20,:style => blue_cell + sheet.add_row sheet_answer_row, :height =>20, :style => sz_all + sheet.add_row sheet_answer_percent, :height =>20, :style => sz_all + sheet.add_row sheet_answer_useful, :height =>20, :style => sz_all #合并单元格,但无法填充style # sheet.merge_cells (Axlsx::cell_r(1,sheet.rows.last.row_index) + ':' + Axlsx::cell_r(sheet_row.count-1,sheet.rows.last.row_index)) # sheet.rows[sheet.rows.last.row_index].style = sz_all sheet.add_row [] else #主观题答案 main_show_row = ["第#{q.question_number}题",q.question_title] - sheet.add_row main_show_row, :style => blue_cell + sheet.add_row main_show_row,:height =>20, :style => blue_cell q.poll_votes.each do |v| #主观题的答案 - sheet.add_row ["",v.vote_text.present? ? v.vote_text : "--"], :style => sz_all + sheet.add_row ["",v.vote_text.present? ? v.vote_text : "--"],:height =>20, :style => sz_all end sheet.add_row [], :style => sz_all end @@ -86,7 +86,7 @@ wb.styles do |s| user_cell += [user_login,user_name, u_user.mail, user_student_id] end all_user_cell = user_cell + user_answer_array - sheet.add_row all_user_cell, :style => sz_all + sheet.add_row all_user_cell, :height =>20,:style => sz_all end sheet.column_widths *([25]*sheet.column_info.count) sheet.column_info.first.width = 10 From 7b51084c374cc83188ee4de02cfa9f496f72df22 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 16:49:00 +0800 Subject: [PATCH 0279/1015] fix bug --- app/views/polls/commit_result.xlsx.axlsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/polls/commit_result.xlsx.axlsx b/app/views/polls/commit_result.xlsx.axlsx index f949af10a..9c91b63a0 100644 --- a/app/views/polls/commit_result.xlsx.axlsx +++ b/app/views/polls/commit_result.xlsx.axlsx @@ -2,8 +2,8 @@ wb = xlsx_package.workbook # wb.use_autowidth = false wb.styles do |s| - sz_all = s.add_style :sz => 10,:border => { :style => :thin, :color =>"000000"},:alignment => {:horizontal => :left} - blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :left} + sz_all = s.add_style :sz => 10,:border => { :style => :thin, :color =>"000000"},:alignment => {wrap_text: true,:horizontal => :left} + blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :left} wb.add_worksheet(:name => "统计结果") do |sheet| sheet.sheet_view.show_grid_lines = false From 6b66be9e60b26ff522dd79307060f40bc2649ffd Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 16:52:05 +0800 Subject: [PATCH 0280/1015] fix bug --- app/views/polls/commit_result.xlsx.axlsx | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/views/polls/commit_result.xlsx.axlsx b/app/views/polls/commit_result.xlsx.axlsx index 9c91b63a0..3ea0571cb 100644 --- a/app/views/polls/commit_result.xlsx.axlsx +++ b/app/views/polls/commit_result.xlsx.axlsx @@ -30,25 +30,25 @@ wb.styles do |s| sheet_answer_row.push(answer_users_count) sheet_answer_percent.push(answer_percent.to_s) end - sheet.add_row sheet_row, :height =>20,:style => blue_cell - sheet.add_row sheet_answer_row, :height =>20, :style => sz_all - sheet.add_row sheet_answer_percent, :height =>20, :style => sz_all - sheet.add_row sheet_answer_useful, :height =>20, :style => sz_all + sheet.add_row sheet_row, :height =>15,:style => blue_cell + sheet.add_row sheet_answer_row, :height =>15, :style => sz_all + sheet.add_row sheet_answer_percent, :height =>15, :style => sz_all + sheet.add_row sheet_answer_useful, :height =>15, :style => sz_all #合并单元格,但无法填充style # sheet.merge_cells (Axlsx::cell_r(1,sheet.rows.last.row_index) + ':' + Axlsx::cell_r(sheet_row.count-1,sheet.rows.last.row_index)) # sheet.rows[sheet.rows.last.row_index].style = sz_all sheet.add_row [] else #主观题答案 main_show_row = ["第#{q.question_number}题",q.question_title] - sheet.add_row main_show_row,:height =>20, :style => blue_cell + sheet.add_row main_show_row,:height =>15, :style => blue_cell q.poll_votes.each do |v| #主观题的答案 - sheet.add_row ["",v.vote_text.present? ? v.vote_text : "--"],:height =>20, :style => sz_all + sheet.add_row ["",v.vote_text.present? ? v.vote_text : "--"],:height =>15, :style => sz_all end sheet.add_row [], :style => sz_all end end #each_with_index - sheet.add_row poll_users_info, :style => blue_cell + sheet.add_row poll_users_info, :height =>15, :style => blue_cell @poll.poll_users.each_with_index do |u,index| u_user = u.user user_answer_array = [] @@ -86,7 +86,7 @@ wb.styles do |s| user_cell += [user_login,user_name, u_user.mail, user_student_id] end all_user_cell = user_cell + user_answer_array - sheet.add_row all_user_cell, :height =>20,:style => sz_all + sheet.add_row all_user_cell, :height =>15,:style => sz_all end sheet.column_widths *([25]*sheet.column_info.count) sheet.column_info.first.width = 10 From aa8b8accc11ffcab96a4c92979da0984e8ab07c2 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 26 Jun 2019 17:08:12 +0800 Subject: [PATCH 0281/1015] =?UTF-8?q?=E5=8C=BF=E8=AF=84=E4=BD=9C=E5=93=81?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/student_work.rb | 10 ++++++++++ .../homework_commons/works_list.json.jbuilder | 18 ++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 0e674dd4c..8acc2e098 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -59,6 +59,16 @@ class StudentWork < ApplicationRecord group_by(&:user_id).count : 0 end + # 当前用户该作品的匿评申诉总条数 + def my_appeal_all_count user_id + student_works_scores.where("reviewer_role = 3 and appeal_status != 0 and user_id = #{user_id}").size + end + + # 当前用户该作品的匿评申诉总条数 + def my_appeal_deal_count user_id + student_works_scores.where("reviewer_role = 3 and appeal_status = 1 and user_id = #{user_id}").size + end + # 分组名 def work_group_name self.group_id == 0 ? "--" : "分组#{self.group_id}" diff --git a/app/views/homework_commons/works_list.json.jbuilder b/app/views/homework_commons/works_list.json.jbuilder index 42d4abf48..716b12190 100644 --- a/app/views/homework_commons/works_list.json.jbuilder +++ b/app/views/homework_commons/works_list.json.jbuilder @@ -106,6 +106,12 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal" json.student_score work_score_format(anon_comments(@current_user, work.id).last.try(:score), false, true) # json.student_comment_count anon_comments(@current_user, work.id).count + + # 申诉条数 + if @homework.anonymous_appeal + json.appeal_all_count work.my_appeal_all_count @current_user.id + json.appeal_deal_count work.my_appeal_deal_count @current_user.id + end else json.(work, :id, :work_status, :update_time, :work_score, :final_score, :teacher_score, :student_score, :teaching_asistant_score, :ultimate_score) @@ -134,13 +140,13 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal" end json.work_group work.work_group_name end - end - # 申诉条数 - if @homework.anonymous_appeal - json.appeal_all_count work.appeal_all_count - json.appeal_deal_count work.appeal_deal_count - json.appeal_penalty work.appeal_penalty + # 申诉条数 + if @homework.anonymous_appeal + json.appeal_all_count work.appeal_all_count + json.appeal_deal_count work.appeal_deal_count + json.appeal_penalty work.appeal_penalty + end end json.user_login @is_evaluation ? "--" : work.user.try(:login) From 665791f4720cf24050ccc4bef4159652856ca266 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 26 Jun 2019 17:12:20 +0800 Subject: [PATCH 0282/1015] =?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/models/myshixun.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/myshixun.rb b/app/models/myshixun.rb index e4573f3dd..a1aca3253 100644 --- a/app/models/myshixun.rb +++ b/app/models/myshixun.rb @@ -74,12 +74,12 @@ class Myshixun < ApplicationRecord # 个人实训得分 def total_score - self.games.select{|game| game.status = 2 && game.final_score > 0}.pluck(:final_score).sum.to_i + self.games.select{|game| game.status == 2 && game.final_score > 0}.pluck(:final_score).sum.to_i end # 个人通关数 def passed_count - self.games.select{|game| game.status = 2}.size + self.games.select{|game| game.status == 2}.size end # 通关时间 @@ -94,7 +94,7 @@ class Myshixun < ApplicationRecord # 通关总耗时 def total_cost_time - self.games.select{|game| game.status = 2}.map(&:cost_time).sum.to_i + self.games.select{|game| game.status == 2}.map(&:cost_time).sum.to_i end end From d44ada37510e85bb0b00cc857e85f4d17ed71358 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 17:24:38 +0800 Subject: [PATCH 0283/1015] check poll_user create --- app/controllers/polls_controller.rb | 3 ++- app/views/polls/poll_lists.json.jbuilder | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 675e3283c..be3316df6 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -951,6 +951,7 @@ class PollsController < ApplicationController def poll_lists ActiveRecord::Base.transaction do begin + @poll_new_users = @poll.poll_users.find_by(user_id:current_user.id) poll_ids = [@poll.id] @poll_list_status = @poll.get_poll_status(current_user.id) @poll_publish_count = get_user_permission_course(poll_ids,2).count @@ -1184,7 +1185,7 @@ class PollsController < ApplicationController def check_poll_commit_result poll_status = @poll.get_poll_status(current_user.id) commit_poll_user = @poll.poll_users.find_by_group_ids(current_user.id).commit_by_status(1) #当前用户已提交问卷的 - unless @user_course_identity < Course::STUDENT || (@poll.show_result && poll_status == 3 && commit_poll_user.present?) + unless (@user_course_identity < Course::STUDENT) || (@poll.show_result && poll_status == 3 && commit_poll_user.present?) normal_status(-1,"没有权限!") #当前为老师/问卷公开统计,且问卷已截止,且用户有过回答的 end end diff --git a/app/views/polls/poll_lists.json.jbuilder b/app/views/polls/poll_lists.json.jbuilder index f134967c9..b83e767a1 100644 --- a/app/views/polls/poll_lists.json.jbuilder +++ b/app/views/polls/poll_lists.json.jbuilder @@ -1,7 +1,7 @@ json.course do json.partial! "polls/course_name",locals:{course:@course} end - +json.current_poll_user @poll_new_users.present? ? @poll_new_users.id : "---" json.poll_types do if @poll_current_user_status == 0 json.published_count @poll_publish_count From 939a536d3a916de320fd53141ea38526e547f000 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 18:29:45 +0800 Subject: [PATCH 0284/1015] fix bug --- app/controllers/exercises_controller.rb | 2 +- app/controllers/polls_controller.rb | 3 +-- app/views/polls/poll_lists.json.jbuilder | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index f10bc81ff..5fa5296d5 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -402,7 +402,7 @@ class ExercisesController < ApplicationController :position => c.position, :challenge_id => c.challenge_id, :shixun_id => q.shixun_id, - :question_score => q.question_score + :question_score => c.question_score } shixun_challenge_bank = exercise_bank_question.exercise_bank_shixun_challenges.new challenge_option shixun_challenge_bank.save diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index be3316df6..119226c87 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -951,7 +951,6 @@ class PollsController < ApplicationController def poll_lists ActiveRecord::Base.transaction do begin - @poll_new_users = @poll.poll_users.find_by(user_id:current_user.id) poll_ids = [@poll.id] @poll_list_status = @poll.get_poll_status(current_user.id) @poll_publish_count = get_user_permission_course(poll_ids,2).count @@ -1185,7 +1184,7 @@ class PollsController < ApplicationController def check_poll_commit_result poll_status = @poll.get_poll_status(current_user.id) commit_poll_user = @poll.poll_users.find_by_group_ids(current_user.id).commit_by_status(1) #当前用户已提交问卷的 - unless (@user_course_identity < Course::STUDENT) || (@poll.show_result && poll_status == 3 && commit_poll_user.present?) + unless (@user_course_identity < Course::STUDENT) || ((@poll.show_result == 1) && (poll_status == 3) && commit_poll_user.present?) normal_status(-1,"没有权限!") #当前为老师/问卷公开统计,且问卷已截止,且用户有过回答的 end end diff --git a/app/views/polls/poll_lists.json.jbuilder b/app/views/polls/poll_lists.json.jbuilder index b83e767a1..1ebccffeb 100644 --- a/app/views/polls/poll_lists.json.jbuilder +++ b/app/views/polls/poll_lists.json.jbuilder @@ -1,7 +1,6 @@ json.course do json.partial! "polls/course_name",locals:{course:@course} end -json.current_poll_user @poll_new_users.present? ? @poll_new_users.id : "---" json.poll_types do if @poll_current_user_status == 0 json.published_count @poll_publish_count From 3587b33a81a7640f15a40d89ef8fce98199541d5 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 26 Jun 2019 18:52:11 +0800 Subject: [PATCH 0285/1015] fixbug --- app/helpers/exercises_helper.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 9ea7578f2..e0db9c2bf 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -13,7 +13,8 @@ module ExercisesHelper ques_score = q.exercise_answers.search_answer_users("user_id",user_id).score_reviewed.pluck(:score).sum end - if ques_score == q.question_score #满分作答为正确 + if ques_score >= q.question_score #满分作答为正确 + ques_score = q.question_score stand_answer = 1 elsif ques_score > 0.0 #部分作答 stand_answer = 2 @@ -35,7 +36,8 @@ module ExercisesHelper exercise_sub_status.each do |s| sub_answer = s.exercise_answers.search_answer_users("user_id",user_id) #主观题只有一个回答 if sub_answer.present? && sub_answer.first.score >= 0.0 - if s.question_score == sub_answer.first.score + + if s.question_score <= sub_answer.first.score stand_status = 1 else stand_status = 2 From 595e4bcf6441ffcb004ba593052acc346c89511b Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 27 Jun 2019 09:02:20 +0800 Subject: [PATCH 0286/1015] modify shixun exec method --- app/controllers/shixuns_controller.rb | 20 +++++++++++--------- app/jobs/update_myshixun_work_status_job.rb | 10 ++++++++++ 2 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 app/jobs/update_myshixun_work_status_job.rb diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 360732120..3b14eea84 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -539,16 +539,21 @@ class ShixunsController < ApplicationController # 其它创建关卡等操作 challenges = @shixun.challenges # 之所以增加user_id是为了方便统计查询性能 - challenges.each_with_index do |challenge, index| - status = (index == 0 ? 0 : 3) - game_identifier = generate_identifier(Game, 12) - Game.create!(:challenge_id => challenge.id, :myshixun_id => myshixun.id, :status => status, :user_id => myshixun.user_id, - :open_time => Time.now, :identifier => game_identifier, :modify_time => challenge.modify_time) + game_attrs = %i[challenge_id myshixun_id status user_id open_time identifier modify_time created_at updated_at] + Game.bulk_insert(*game_attrs) do |worker| + base_attr = { myshixun_id: myshixun.id, user_id: myshixun.user_id } + challenges.each_with_index do |challenge, index| + status = (index == 0 ? 0 : 3) + game_identifier = generate_identifier(Game, 12) + worker.add(base_attr.merge(challenge_id: challenge.id, status: status, open_time: Time.now, + identifier: game_identifier, modify_time: challenge.modify_time)) + end end # REDO:开启实训时更新关联作品的状态 # TODO:这个可以异步。或者放到课程里面取,不要在开启实训这边做 - HomeworksService.new.update_myshixun_work_status myshixun + # HomeworksService.new.update_myshixun_work_status myshixun + UpdateMyshixunWorkStatusJob.perform_later(myshixun.id) @current_task = myshixun.current_task uid_logger("## shixun exec: myshixun id is #{myshixun.id}") @@ -559,9 +564,6 @@ class ShixunsController < ApplicationController end end end - - - end # gameID 及实训ID # status: 0 , 1 申请过, 2,实训关卡路径未填, 3 实训标签未填, 4 实训未创建关卡 diff --git a/app/jobs/update_myshixun_work_status_job.rb b/app/jobs/update_myshixun_work_status_job.rb new file mode 100644 index 000000000..27a53408f --- /dev/null +++ b/app/jobs/update_myshixun_work_status_job.rb @@ -0,0 +1,10 @@ +class UpdateMyshixunWorkStatusJob < ApplicationJob + queue_as :default + + def perform(myshixun_id) + myshixun = Myshixun.find_by(id: myshixun_id) + return if myshixun.blank? + + HomeworksService.new.update_myshixun_work_status myshixun + end +end From 82f63e712ffe89a2f909362d704af0c916f536d4 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 27 Jun 2019 09:02:41 +0800 Subject: [PATCH 0287/1015] fix bug --- app/models/poll.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/poll.rb b/app/models/poll.rb index b498eda4e..ce5da17dd 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -145,7 +145,8 @@ class Poll < ApplicationRecord end if poll_answer_user.present? && poll_answer_user.start_at.blank? && user_poll_status == 3 - user_status = 4 + # user_status = 4 + user_status = 5 #问卷用户存在,且未开始答题,且问卷已截止时,返回未提交标示 end user_status From 17527970fc1f1fb37fe0672fb343f9ff03f322fc Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 27 Jun 2019 09:16:22 +0800 Subject: [PATCH 0288/1015] =?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/models/homework_common.rb | 5 ++--- app/models/student_work.rb | 16 ++++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 9ed80e746..d55973ed8 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -78,8 +78,7 @@ class HomeworkCommon < ApplicationRecord # 根据是否统一发布获取作业的作品列表 def all_works student_works = self.unified_setting ? self.student_works : - self.student_works.joins("join course_members on student_works.user_id=course_members.user_id"). - where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)}) + self.student_works.joins("join course_members on student_works.user_id=course_members.user_id").where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)}) end # 分班权限的老师可见的作品列表 @@ -90,7 +89,7 @@ class HomeworkCommon < ApplicationRecord # 有分班权限的统计管理的分班且已发布的学生情况 if member.present? && teacher_course_groups.size > 0 group_ids = teacher_course_groups.pluck(:course_group_id) - all_student_works = all_student_works.joins("join course_members course_members on student_works.user_id=course_members.user_id"). + all_student_works = all_student_works.joins("join course_members on student_works.user_id=course_members.user_id"). where(course_members: {course_group_id: group_ids}) end all_student_works diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 8acc2e098..a2379f1a8 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -39,34 +39,34 @@ class StudentWork < ApplicationRecord # 助教评分次数 def ta_comment_count - self.student_works_scores.where(reviewer_role: 2).group_by(&:user_id).count + self.student_works_scores.select{|score| score.reviewer_role == 2}.group_by(&:user_id).count end # 匿评次数 def student_comment_num - homework_common.homework_detail_manual.comment_status > 2 ? self.student_works_scores.where(reviewer_role: 3).group_by(&:user_id).count : 0 + homework_common.homework_detail_manual.comment_status > 2 ? self.student_works_scores.select{|score| score.reviewer_role == 3}.group_by(&:user_id).count : 0 end # 匿评申诉总条数 def appeal_all_count - homework_common.homework_detail_manual.comment_status >= 3 ? self.student_works_scores.where("reviewer_role = 3 and appeal_status != 0"). - group_by(&:user_id).count : 0 + homework_common.homework_detail_manual.comment_status >= 3 ? self.student_works_scores. + select{|score| score.reviewer_role == 3 && score.appeal_status != 0}.group_by(&:user_id).count : 0 end # 匿评申诉待处理条数 def appeal_deal_count - homework_common.homework_detail_manual.comment_status >= 3 ? self.student_works_scores.where("reviewer_role = 3 and appeal_status = 1"). - group_by(&:user_id).count : 0 + homework_common.homework_detail_manual.comment_status >= 3 ? self.student_works_scores. + select{|score| score.reviewer_role == 3 && score.appeal_status == 1}.group_by(&:user_id).count : 0 end # 当前用户该作品的匿评申诉总条数 def my_appeal_all_count user_id - student_works_scores.where("reviewer_role = 3 and appeal_status != 0 and user_id = #{user_id}").size + student_works_scores.select{|score| score.reviewer_role == 3 && score.appeal_status != 0 && score.user_id = user_id}.size end # 当前用户该作品的匿评申诉总条数 def my_appeal_deal_count user_id - student_works_scores.where("reviewer_role = 3 and appeal_status = 1 and user_id = #{user_id}").size + student_works_scores.select{|score| score.reviewer_role == 3 && score.appeal_status == 1 && score.user_id = user_id}.size end # 分组名 From bc3291d00bef43ef32645de2f85ffcdf2cad59e7 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 27 Jun 2019 09:23:04 +0800 Subject: [PATCH 0289/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/graduation_topics_controller.rb | 4 ++-- app/controllers/question_banks_controller.rb | 2 +- db/migrate/20190627012117_modify_quotes_for_gtopic_banks.rb | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20190627012117_modify_quotes_for_gtopic_banks.rb diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index ce4488ffd..7a61613da 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -173,7 +173,7 @@ class GraduationTopicsController < ApplicationController member = @course.course_members.where(:user_id => @graduation_topic.tea_id).first tip_exception("分班名称不能为空") if params[:course_group_name].blank? course_group = CourseGroup.create(:name => params[:course_group_name], :course_id => @course.id) - teacher_group = TeacherCourseGroup.create(:course_id => @course.id, :member_id => member.try(:id), + teacher_group = TeacherCourseGroup.create(:course_id => @course.id, :course_member_id => member.try(:id), :user_id => @graduation_topic.tea_id, :course_group_id => course_group.try(:id)) end @@ -195,7 +195,7 @@ class GraduationTopicsController < ApplicationController user_unaccept_topics = @course.student_graduation_topics.where(user_id: current_user.id, status: [0, 1]) if user_unaccept_topics.size == 0 member_id = @course.course_members.find_by_user_id(current_user.id) - StudentGraduationTopic.create(course_id: @course.id, user_id: current_user.id, member_id: member_id, + StudentGraduationTopic.create(course_id: @course.id, user_id: current_user.id, course_member_id: member_id, graduation_topic_id: @graduation_topic.id) @graduation_topic.update_attribute(:status, 1) normal_status("选题成功") diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index 740e3a993..4df392257 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -266,7 +266,7 @@ class QuestionBanksController < ApplicationController def quote_gtopic_bank topic, course ActiveRecord::Base.transaction do new_topic = GraduationTopic.new - new_topic.attributes = topic.attributes.dup.except("id", "course_id", "user_id", "graduation_topic_id", + new_topic.attributes = topic.attributes.dup.except("id", "course_id", "user_id", "graduation_topic_id", "quotes", "course_list_id", "gtopic_bank_id", "created_at", "updated_at") new_topic.course_id = course.id new_topic.gtopic_bank_id = topic.id diff --git a/db/migrate/20190627012117_modify_quotes_for_gtopic_banks.rb b/db/migrate/20190627012117_modify_quotes_for_gtopic_banks.rb new file mode 100644 index 000000000..4c475fd8f --- /dev/null +++ b/db/migrate/20190627012117_modify_quotes_for_gtopic_banks.rb @@ -0,0 +1,5 @@ +class ModifyQuotesForGtopicBanks < ActiveRecord::Migration[5.2] + def change + change_column :gtopic_banks, :quotes, :integer, :default => 0 + end +end From 0b1049e319f1eb78c3f2b1b741c82f234e45a8d7 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 27 Jun 2019 09:26:42 +0800 Subject: [PATCH 0290/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...banks.rb => 20190627012118_modify_quotes_for_gtopic_banks.rb} | 1 + 1 file changed, 1 insertion(+) rename db/migrate/{20190627012117_modify_quotes_for_gtopic_banks.rb => 20190627012118_modify_quotes_for_gtopic_banks.rb} (70%) diff --git a/db/migrate/20190627012117_modify_quotes_for_gtopic_banks.rb b/db/migrate/20190627012118_modify_quotes_for_gtopic_banks.rb similarity index 70% rename from db/migrate/20190627012117_modify_quotes_for_gtopic_banks.rb rename to db/migrate/20190627012118_modify_quotes_for_gtopic_banks.rb index 4c475fd8f..a47157414 100644 --- a/db/migrate/20190627012117_modify_quotes_for_gtopic_banks.rb +++ b/db/migrate/20190627012118_modify_quotes_for_gtopic_banks.rb @@ -1,5 +1,6 @@ class ModifyQuotesForGtopicBanks < ActiveRecord::Migration[5.2] def change + GtopicBank.where("quotes is null").update_all(:quotes => 0) change_column :gtopic_banks, :quotes, :integer, :default => 0 end end From 26919424e09a72f7c24fd377494eb7759f1838bc Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 27 Jun 2019 09:33:53 +0800 Subject: [PATCH 0291/1015] fix bug --- app/controllers/exercises_controller.rb | 12 ++++++------ app/helpers/polls_helper.rb | 4 ++-- app/models/poll.rb | 12 ++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 5fa5296d5..44b694239 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -32,13 +32,13 @@ class ExercisesController < ApplicationController @exercises_all = @course.exercises member_show_exercises = @exercises_all.is_exercise_published #已发布的或已截止的试卷 @current_user_ = current_user - @exercises_count = @exercises_all.count # 全部页面,需返回 - @exercises_unpublish_counts = @exercises_all.exercise_by_status(1).count #未发布的试卷数 - @exercises_published_counts = @exercises_all.exercise_by_status([2,3]).count # 已发布的试卷数,包含已截止的 - @exercises_ended_counts = @exercises_all.exercise_by_status(3).count #已截止的试卷数 + @exercises_count = @exercises_all.size # 全部页面,需返回 + @exercises_unpublish_counts = @exercises_all.exercise_by_status(1).size #未发布的试卷数 + @exercises_published_counts = @exercises_all.exercise_by_status([2,3]).size # 已发布的试卷数,包含已截止的 + @exercises_ended_counts = @exercises_all.exercise_by_status(3).size #已截止的试卷数 # 课堂的学生人数 @course_all_members = @course.students #当前课堂的全部学生 - @course_all_members_count = @course_all_members.count #当前课堂的学生数 + @course_all_members_count = @course_all_members.size #当前课堂的学生数 @current_student = @course_all_members.course_find_by_ids("user_id",current_user.id) #当前用户是否为课堂的学生 # exercises的不同用户群体的显示 @@ -64,7 +64,7 @@ class ExercisesController < ApplicationController @is_teacher_or = 0 @exercises = member_show_exercises.present? ? member_show_exercises.unified_setting : [] end - if @exercises.count > 0 + if @exercises.size > 0 if params[:type].present? choose_type = params[:type].to_i member_group_id = @current_student.first.try(:course_group_id).to_i diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index 56bbb9b77..b5ba79dcc 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -3,8 +3,8 @@ module PollsHelper #获取试卷的已答/未答人数 def get_poll_answers(poll_users) @commit_poll_users = poll_users.commit_by_status(1) #当前老师的全部学生中已提交的 - @poll_answers = @commit_poll_users.present? ? @commit_poll_users.count : 0 #表示已经提交了的用户 - course_all_members_count = poll_users.present? ? poll_users.count : 0 + @poll_answers = @commit_poll_users.present? ? @commit_poll_users.size : 0 #表示已经提交了的用户 + course_all_members_count = poll_users.present? ? poll_users.size : 0 @poll_unanswers = (course_all_members_count - @poll_answers) end diff --git a/app/models/poll.rb b/app/models/poll.rb index ce5da17dd..1cead3291 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -137,17 +137,17 @@ class Poll < ApplicationRecord #判断当前用户的答题状态 def check_user_votes_status(user) poll_answer_user = poll_users.find_by(user_id: user.id) - user_poll_status = get_poll_status(user.id) + # user_poll_status = get_poll_status(user.id) user_status = 2 if poll_answer_user.present? && (poll_answer_user.start_at.present? || poll_answer_user.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 user_status = poll_answer_user.commit_status end - - if poll_answer_user.present? && poll_answer_user.start_at.blank? && user_poll_status == 3 - # user_status = 4 - user_status = 5 #问卷用户存在,且未开始答题,且问卷已截止时,返回未提交标示 - end + # + # if poll_answer_user.present? && poll_answer_user.start_at.blank? && user_poll_status == 3 + # # user_status = 4 + # user_status = 2 #问卷用户存在,且未开始答题,且问卷已截止时,返回未提交标示 + # end user_status end From 0e32e63b7b836c3792b1f340af584327d39c9314 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 27 Jun 2019 09:34:33 +0800 Subject: [PATCH 0292/1015] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E9=80=89=E9=A2=98?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/graduation_topics_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index 7a61613da..521aaffc6 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -24,8 +24,7 @@ class GraduationTopicsController < ApplicationController end # 当前用户是否已经选过题 - user_graduation_topics = @course.student_graduation_topics.where(user_id: current_user.id, status: [0, 1]) #6.12 -hs - @user_selected = user_graduation_topics.size > 0 + @user_selected = @course.student_graduation_topics.where(user_id: current_user.id, status: [0, 1]).count > 0 #6.12 -hs ## 分页参数 page = params[:page] || 1 limit = params[:limit] || 15 From da719e500fa9a6330674911bcce6eb6ff6ceb694 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 27 Jun 2019 09:59:56 +0800 Subject: [PATCH 0293/1015] =?UTF-8?q?=E8=80=81=E5=B8=88=E6=89=BE=E4=B8=8D?= =?UTF-8?q?=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/question_banks_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index 4df392257..22650f2d3 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -271,6 +271,7 @@ class QuestionBanksController < ApplicationController new_topic.course_id = course.id new_topic.gtopic_bank_id = topic.id new_topic.user_id = current_user.id + new_topic.tea_id = current_user.id new_topic.save topic.attachments.each.try(:each) do |attachment| From a58bd2552a405d20c1e08e4bca06f1af2107a7b7 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 27 Jun 2019 11:26:27 +0800 Subject: [PATCH 0294/1015] =?UTF-8?q?=E6=89=A3=E5=88=86=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 5fe230d32..32175ec2f 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -270,7 +270,8 @@ class GamesController < ApplicationController if @game.status == 2 @game.update_attributes!(:answer_open => @answer.level) else - @game.update_attributes!(:answer_open => @answer.level, :answer_deduction => deduct_score) + answer_deduction = challenge.challenge_answers.where("level <= #{@answer.level}").sum(:score) + @game.update_attributes!(:answer_open => @answer.level, :answer_deduction => answer_deduction) end rescue Exception => e From b7023c4c8e10c1cc4cad5b7a2d1ca541eb1b7aa6 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 27 Jun 2019 11:27:47 +0800 Subject: [PATCH 0295/1015] new git check --- lib/gitcheck/myshixun_update_error.txt | 0 lib/gitcheck/readme_test.txt | 4 +- lib/gitcheck/shixun_update.txt | 563 +++++++++++++++++++++++++ lib/gitcheck/shixun_update_error.txt | 72 ++++ lib/tasks/git_check.rake | 43 +- 5 files changed, 677 insertions(+), 5 deletions(-) create mode 100644 lib/gitcheck/myshixun_update_error.txt create mode 100644 lib/gitcheck/shixun_update_error.txt diff --git a/lib/gitcheck/myshixun_update_error.txt b/lib/gitcheck/myshixun_update_error.txt new file mode 100644 index 000000000..e69de29bb diff --git a/lib/gitcheck/readme_test.txt b/lib/gitcheck/readme_test.txt index 03f757f18..317af632c 100644 --- a/lib/gitcheck/readme_test.txt +++ b/lib/gitcheck/readme_test.txt @@ -22,7 +22,7 @@ http://121.199.19.206:9000/api/fork_repository 参数: {repo_path: 'Hjqreturn/aaass1.git', fork_repository_path: 'educoder/ca9fvobr.git'} - 说明:fork_repository_path是源项目的repo_path, repo_path是新项目的 + 说明:fork_repository_path是新项目的repo_path, repo_path是源项目的 4、更新文件 @@ -41,7 +41,7 @@ 5、获取文件内容 访问地址:http://121.199.19.206:9000/api/file_content 参数: - {repo_path: "educoder/ca9fvobr.git", file_path: 'step1/main.py',} + {repo_path: "educoder/ca9fvobr.git", path: 'step1/main.py',} 6、获取提交记录 访问地址:http://121.199.19.206:9000/api/commits diff --git a/lib/gitcheck/shixun_update.txt b/lib/gitcheck/shixun_update.txt index e69de29bb..ff5e54236 100644 --- a/lib/gitcheck/shixun_update.txt +++ b/lib/gitcheck/shixun_update.txt @@ -0,0 +1,563 @@ +http://testbdgit2.educoder.net/educoder/mqex9s82.git +http://testbdgit2.educoder.net/educoder/nf9ja46l.git +http://testbdgit2.educoder.net/educoder/qmeb65oa.git +http://testbdgit2.educoder.net/educoder/748fkcya.git +http://testbdgit2.educoder.net/educoder/o7pr4f6v.git +http://testbdgit2.educoder.net/educoder/tjxnyuv6.git +http://testbdgit2.educoder.net/educoder/fp6cmstz.git +http://testbdgit2.educoder.net/educoder/eh5oxkm9.git +http://testbdgit2.educoder.net/educoder/uznmbg54.git +http://testbdgit2.educoder.net/educoder/i8utopmc.git +http://testbdgit2.educoder.net/educoder/f9ly35vz.git +http://testbdgit2.educoder.net/educoder/vnw2fg5r.git +http://testbdgit2.educoder.net/educoder/pcfhzue5.git +http://testbdgit2.educoder.net/educoder/zlg2nmcf.git +http://testbdgit2.educoder.net/educoder/klp26sqc.git +http://testbdgit2.educoder.net/educoder/y68uqmoe.git +http://testbdgit2.educoder.net/educoder/7zg5mi2r.git +http://testbdgit2.educoder.net/educoder/8g93nfvc.git +http://testbdgit2.educoder.net/educoder/mnj3srpe.git +http://testbdgit2.educoder.net/educoder/lrwsyhzc.git +http://testbdgit2.educoder.net/educoder/a2ct98o7.git +http://testbdgit2.educoder.net/educoder/hawxspqm.git +http://testbdgit2.educoder.net/educoder/pobfl4g8.git +http://testbdgit2.educoder.net/educoder/zg7e9o2y.git +http://testbdgit2.educoder.net/educoder/fsu7tkaw.git +http://testbdgit2.educoder.net/educoder/cmklt4f8.git +http://testbdgit2.educoder.net/educoder/2gt3yuen.git +http://testbdgit2.educoder.net/educoder/v3bksozu.git +http://testbdgit2.educoder.net/educoder/ku6lva8t.git +http://testbdgit2.educoder.net/educoder/g8w3nj6r.git +http://testbdgit2.educoder.net/educoder/pxlsuotc.git +http://testbdgit2.educoder.net/educoder/opv8xkjw.git +http://testbdgit2.educoder.net/educoder/stewl573.git +http://testbdgit2.educoder.net/educoder/nuj9lbwv.git +http://testbdgit2.educoder.net/educoder/r4vlju5x.git +http://testbdgit2.educoder.net/educoder/85fat9w3.git +http://testbdgit2.educoder.net/educoder/guzqi4nm.git +http://testbdgit2.educoder.net/educoder/obtfwj3e.git +http://testbdgit2.educoder.net/educoder/3ozvy5f8.git +http://testbdgit2.educoder.net/educoder/8bu9zmjy.git +http://testbdgit2.educoder.net/educoder/n489y7qt.git +http://testbdgit2.educoder.net/educoder/f3pwvrtk.git +http://testbdgit2.educoder.net/educoder/b6ljcet3.git +http://testbdgit2.educoder.net/educoder/uie9snqp.git +http://testbdgit2.educoder.net/educoder/xti6ueyf.git +http://testbdgit2.educoder.net/educoder/gwkc395l.git +http://testbdgit2.educoder.net/educoder/6a2qy98p.git +http://testbdgit2.educoder.net/educoder/2qffg3pu.git +http://testbdgit2.educoder.net/educoder/nfypjxhl.git +http://testbdgit2.educoder.net/educoder/9p4neovc.git +http://testbdgit2.educoder.net/educoder/k4wg9b32.git +http://testbdgit2.educoder.net/educoder/pw53ln4m.git +http://testbdgit2.educoder.net/educoder/cylj7vgb.git +http://testbdgit2.educoder.net/educoder/ftfzbw72.git +http://testbdgit2.educoder.net/educoder/qt78x4a5.git +http://testbdgit2.educoder.net/educoder/qsza57pj.git +http://testbdgit2.educoder.net/educoder/afvk9r35.git +http://testbdgit2.educoder.net/educoder/68rqajhy.git +http://testbdgit2.educoder.net/educoder/q4ixftoz.git +http://testbdgit2.educoder.net/educoder/pbmkl5vt.git +http://testbdgit2.educoder.net/educoder/ral8fjw9.git +http://testbdgit2.educoder.net/educoder/89zfsjbp.git +http://testbdgit2.educoder.net/educoder/no9uv3g2.git +http://testbdgit2.educoder.net/educoder/cztux23y.git +http://testbdgit2.educoder.net/educoder/4bflgcs8.git +http://testbdgit2.educoder.net/educoder/6w2xmtls.git +http://testbdgit2.educoder.net/educoder/o4xa93mc.git +http://testbdgit2.educoder.net/educoder/uctzevfx.git +http://testbdgit2.educoder.net/educoder/wokspmut.git +http://testbdgit2.educoder.net/educoder/ba56rk8v.git +http://testbdgit2.educoder.net/educoder/6w49utr2.git +http://testbdgit2.educoder.net/educoder/qnubm248.git +http://testbdgit2.educoder.net/educoder/itzexlbn.git +http://testbdgit2.educoder.net/educoder/e6o9pmz4.git +http://testbdgit2.educoder.net/educoder/qr9fhylp.git +http://testbdgit2.educoder.net/educoder/q2nya3cj.git +http://testbdgit2.educoder.net/educoder/58drwg63.git +http://testbdgit2.educoder.net/educoder/oiwsvgpf.git +http://testbdgit2.educoder.net/educoder/4uyn5ebp.git +http://testbdgit2.educoder.net/educoder/pebvjtk9.git +http://testbdgit2.educoder.net/educoder/uywljq4v.git +http://testbdgit2.educoder.net/educoder/zawfjtnm.git +http://testbdgit2.educoder.net/educoder/z5w3gbhk.git +http://testbdgit2.educoder.net/educoder/cz7yw3en.git +http://testbdgit2.educoder.net/educoder/p87sflg2.git +http://testbdgit2.educoder.net/educoder/w3vcokrg.git +http://testbdgit2.educoder.net/educoder/uc64f2qs.git +http://testbdgit2.educoder.net/educoder/vtnag4op.git +http://testbdgit2.educoder.net/educoder/mbgfitn6.git +http://testbdgit2.educoder.net/educoder/nwj4ua2k.git +http://testbdgit2.educoder.net/educoder/y8kfhtu6.git +http://testbdgit2.educoder.net/educoder/tmivlph2.git +http://testbdgit2.educoder.net/educoder/ziyft572.git +http://testbdgit2.educoder.net/educoder/k8u4nrj6.git +http://testbdgit2.educoder.net/educoder/wgfyrzhe.git +http://testbdgit2.educoder.net/educoder/a4ts237c.git +http://testbdgit2.educoder.net/educoder/cvw63y9e.git +http://testbdgit2.educoder.net/educoder/bxltfpa5.git +http://testbdgit2.educoder.net/educoder/x2anczf5.git +http://testbdgit2.educoder.net/educoder/m57iyhan.git +http://testbdgit2.educoder.net/educoder/iqrakwl2.git +http://testbdgit2.educoder.net/educoder/fagcx7yl.git +http://testbdgit2.educoder.net/educoder/oxlpy9uq.git +http://testbdgit2.educoder.net/educoder/6spm2y7k.git +http://testbdgit2.educoder.net/educoder/6fxzts5b.git +http://testbdgit2.educoder.net/eduforge/fhc7p56a.git +http://testbdgit2.educoder.net/eduforge/3aexl5my.git +http://testbdgit2.educoder.net/educoder/9mz7qn5t.git +http://testbdgit2.educoder.net/educoder/b9r8pon3.git +http://testbdgit2.educoder.net/educoder/ciz68os9.git +http://testbdgit2.educoder.net/educoder/2e4fuw87.git +http://testbdgit2.educoder.net/educoder/hwm9s64y.git +http://testbdgit2.educoder.net/educoder/owsik483.git +http://testbdgit2.educoder.net/educoder/pbt9cyfo.git +http://testbdgit2.educoder.net/educoder/8u4fvn9w.git +http://testbdgit2.educoder.net/educoder/5bpkg3e6.git +http://testbdgit2.educoder.net/educoder/ohkunqe2.git +http://testbdgit2.educoder.net/educoder/u3j28qe6.git +http://testbdgit2.educoder.net/educoder/yjo3t72c.git +http://testbdgit2.educoder.net/educoder/oy7prsxe.git +http://testbdgit2.educoder.net/educoder/q3ljmkn2.git +http://testbdgit2.educoder.net/educoder/gk6lhtrf.git +http://testbdgit2.educoder.net/eduforge/v6pa2kiz.git +http://testbdgit2.educoder.net/educoder/qpuobn24.git +http://testbdgit2.educoder.net/educoder/mkxfysza.git +http://testbdgit2.educoder.net/eduforge/hpr7ojgc.git +http://testbdgit2.educoder.net/educoder/2aef9wni.git +http://testbdgit2.educoder.net/eduforge/8texrqwj.git +http://testbdgit2.educoder.net/educoder/wle7zmxu.git +http://testbdgit2.educoder.net/eduforge/j7cx68b9.git +http://testbdgit2.educoder.net/educoder/ywrcjki2.git +http://testbdgit2.educoder.net/educoder/sauvl9px.git +http://testbdgit2.educoder.net/educoder/3pl6j2me.git +http://testbdgit2.educoder.net/eduforge/o53rjgsh.git +http://testbdgit2.educoder.net/educoder/g8znf6cy.git +http://testbdgit2.educoder.net/educoder/itk4hy6l.git +http://testbdgit2.educoder.net/eduforge/igbc4rtw.git +http://testbdgit2.educoder.net/educoder/mnkfuyvx.git +http://testbdgit2.educoder.net/educoder/oatsh64e.git +http://testbdgit2.educoder.net/educoder/2mgsyrnu.git +http://testbdgit2.educoder.net/educoder/69ulmat5.git +http://testbdgit2.educoder.net/eduforge/9z3k5i4f.git +http://testbdgit2.educoder.net/educoder/7bysthvr.git +http://testbdgit2.educoder.net/eduforge/z3wh7uex.git +http://testbdgit2.educoder.net/educoder/9o5h2rsf.git +http://testbdgit2.educoder.net/educoder/uf3gl2vq.git +http://testbdgit2.educoder.net/eduforge/jef9xvzb.git +http://testbdgit2.educoder.net/educoder/g94qce7p.git +http://testbdgit2.educoder.net/educoder/2a54vk8x.git +http://testbdgit2.educoder.net/educoder/sx5eukfq.git +http://testbdgit2.educoder.net/educoder/ivzjw793.git +http://testbdgit2.educoder.net/eduforge/aekgf6pz.git +http://testbdgit2.educoder.net/educoder/tzqbu6c4.git +http://testbdgit2.educoder.net/educoder/ovz3e6a7.git +http://testbdgit2.educoder.net/educoder/ujavffi2.git +http://testbdgit2.educoder.net/educoder/8jsxcfm5.git +http://testbdgit2.educoder.net/educoder/qgpycjvn.git +http://testbdgit2.educoder.net/educoder/rhasift3.git +http://testbdgit2.educoder.net/educoder/nfpla5jg.git +http://testbdgit2.educoder.net/educoder/bjo2x4c9.git +http://testbdgit2.educoder.net/educoder/3jawxy9g.git +http://testbdgit2.educoder.net/eduforge/h6gs8t7q.git +http://testbdgit2.educoder.net/educoder/ntexhzrl.git +http://testbdgit2.educoder.net/educoder/jft327sa.git +http://testbdgit2.educoder.net/educoder/7bvs54gw.git +http://testbdgit2.educoder.net/educoder/grunzcs3.git +http://testbdgit2.educoder.net/educoder/q4fowkfa.git +http://testbdgit2.educoder.net/educoder/fkmtrpsn.git +http://testbdgit2.educoder.net/educoder/2iubzxfh.git +http://testbdgit2.educoder.net/educoder/gbhwvrki.git +http://testbdgit2.educoder.net/educoder/kpxfs4b5.git +http://testbdgit2.educoder.net/educoder/h5f6wi7x.git +http://testbdgit2.educoder.net/educoder/c3lr2xjz.git +http://testbdgit2.educoder.net/educoder/q8bcyxz3.git +http://testbdgit2.educoder.net/educoder/qha5emif.git +http://testbdgit2.educoder.net/educoder/5jr4gzs7.git +http://testbdgit2.educoder.net/educoder/9ksg4up7.git +http://testbdgit2.educoder.net/educoder/4rcxvftu.git +http://testbdgit2.educoder.net/educoder/hvaf5txj.git +http://testbdgit2.educoder.net/educoder/b4vqe8uz.git +http://testbdgit2.educoder.net/educoder/pg6c2i5y.git +http://testbdgit2.educoder.net/educoder/fbtlw8ro.git +http://testbdgit2.educoder.net/educoder/86f92lri.git +http://testbdgit2.educoder.net/educoder/zvaup9yo.git +http://testbdgit2.educoder.net/educoder/exm3ffap.git +http://testbdgit2.educoder.net/educoder/owg63ezu.git +http://testbdgit2.educoder.net/educoder/c36opqaj.git +http://testbdgit2.educoder.net/educoder/xuyrc6qs.git +http://testbdgit2.educoder.net/educoder/xc9tj82p.git +http://testbdgit2.educoder.net/educoder/nmougtya.git +http://testbdgit2.educoder.net/educoder/8arufxzl.git +http://testbdgit2.educoder.net/educoder/m7nrf6zf.git +http://testbdgit2.educoder.net/educoder/zffu9j6v.git +http://testbdgit2.educoder.net/educoder/epmtoh6b.git +http://testbdgit2.educoder.net/educoder/ejab7vxn.git +http://testbdgit2.educoder.net/educoder/83lyhsen.git +http://testbdgit2.educoder.net/educoder/m4e6x573.git +http://testbdgit2.educoder.net/educoder/unfihtsv.git +http://testbdgit2.educoder.net/educoder/74ftapwb.git +http://testbdgit2.educoder.net/educoder/iu47m9qx.git +http://testbdgit2.educoder.net/educoder/8bh6mfu3.git +http://testbdgit2.educoder.net/educoder/sb26oath.git +http://testbdgit2.educoder.net/educoder/igvm3fsb.git +http://testbdgit2.educoder.net/educoder/gancv2yo.git +http://testbdgit2.educoder.net/educoder/kyp65jwu.git +http://testbdgit2.educoder.net/educoder/6ru2nbpj.git +http://testbdgit2.educoder.net/educoder/rfpwhsu5.git +http://testbdgit2.educoder.net/educoder/orem2wgc.git +http://testbdgit2.educoder.net/educoder/yuhmfliq.git +http://testbdgit2.educoder.net/educoder/m4c7jo6y.git +http://testbdgit2.educoder.net/educoder/5l6oufzc.git +http://testbdgit2.educoder.net/educoder/my7vcffx.git +http://testbdgit2.educoder.net/educoder/uvka63xs.git +http://testbdgit2.educoder.net/educoder/c9thq3li.git +http://testbdgit2.educoder.net/educoder/o45rn2sl.git +http://testbdgit2.educoder.net/educoder/sae3fyjc.git +http://testbdgit2.educoder.net/educoder/56orxtg3.git +http://testbdgit2.educoder.net/educoder/cqpzx47f.git +http://testbdgit2.educoder.net/educoder/2in3vcf7.git +http://testbdgit2.educoder.net/educoder/6isfgtun.git +http://testbdgit2.educoder.net/educoder/46woubzq.git +http://testbdgit2.educoder.net/educoder/6xwmi29f.git +http://testbdgit2.educoder.net/educoder/hk968fua.git +http://testbdgit2.educoder.net/educoder/ogb6ixjz.git +http://testbdgit2.educoder.net/educoder/va7cru64.git +http://testbdgit2.educoder.net/educoder/vqnk5tjo.git +http://testbdgit2.educoder.net/educoder/oqfsci8u.git +http://testbdgit2.educoder.net/educoder/qcosi4f8.git +http://testbdgit2.educoder.net/educoder/bsnk7wit.git +http://testbdgit2.educoder.net/educoder/ksvmtwql.git +http://testbdgit2.educoder.net/educoder/eigqpfua.git +http://testbdgit2.educoder.net/educoder/hqmwxztb.git +http://testbdgit2.educoder.net/educoder/jlgt9wfk.git +http://testbdgit2.educoder.net/educoder/hcuzqkgv.git +http://testbdgit2.educoder.net/educoder/hzw89pof.git +http://testbdgit2.educoder.net/educoder/xnft4fsm.git +http://testbdgit2.educoder.net/educoder/guj4ml8q.git +http://testbdgit2.educoder.net/educoder/l56jkwfn.git +http://testbdgit2.educoder.net/educoder/4jqry5gl.git +http://testbdgit2.educoder.net/educoder/65kiwb72.git +http://testbdgit2.educoder.net/educoder/xb39mzfr.git +http://testbdgit2.educoder.net/educoder/hyb5m38x.git +http://testbdgit2.educoder.net/educoder/p4f2jtkq.git +http://testbdgit2.educoder.net/educoder/4n3stcol.git +http://testbdgit2.educoder.net/educoder/6kjqar5e.git +http://testbdgit2.educoder.net/educoder/qhc2prk4.git +http://testbdgit2.educoder.net/educoder/ltw8b29i.git +http://testbdgit2.educoder.net/educoder/g5y8zcvl.git +http://testbdgit2.educoder.net/educoder/5et7zpra.git +http://testbdgit2.educoder.net/educoder/au97mpbr.git +http://testbdgit2.educoder.net/educoder/oxmt2zvc.git +http://testbdgit2.educoder.net/educoder/26chou4y.git +http://testbdgit2.educoder.net/educoder/lfmus7o2.git +http://testbdgit2.educoder.net/educoder/efbp7luz.git +http://testbdgit2.educoder.net/educoder/7lr8agws.git +http://testbdgit2.educoder.net/educoder/ak8tbjuv.git +http://testbdgit2.educoder.net/educoder/qu8a93ew.git +http://testbdgit2.educoder.net/educoder/zlgfiowe.git +http://testbdgit2.educoder.net/educoder/qmt4nfai.git +http://testbdgit2.educoder.net/educoder/u2s4v9ba.git +http://testbdgit2.educoder.net/educoder/2icxsunf.git +http://testbdgit2.educoder.net/educoder/fzmqjp6g.git +http://testbdgit2.educoder.net/educoder/7ir3vmzw.git +http://testbdgit2.educoder.net/educoder/xkfzg96o.git +http://testbdgit2.educoder.net/educoder/xvfl5sjz.git +http://testbdgit2.educoder.net/educoder/qnwuy7h3.git +http://testbdgit2.educoder.net/educoder/bhnspvmg.git +http://testbdgit2.educoder.net/educoder/ns7vh6ro.git +http://testbdgit2.educoder.net/eduforge/un3xoal7.git +http://testbdgit2.educoder.net/educoder/29am7wv4.git +http://testbdgit2.educoder.net/educoder/qlfn5hiu.git +http://testbdgit2.educoder.net/educoder/e4pvkhtj.git +http://testbdgit2.educoder.net/educoder/hfesmtuz.git +http://testbdgit2.educoder.net/educoder/6kjhil3m.git +http://testbdgit2.educoder.net/educoder/2igrh8c4.git +http://testbdgit2.educoder.net/educoder/e7yt3kmw.git +http://testbdgit2.educoder.net/educoder/a8zybrkt.git +http://testbdgit2.educoder.net/educoder/v2uzrasj.git +http://testbdgit2.educoder.net/educoder/rb83htif.git +http://testbdgit2.educoder.net/eduforge/jc3p2wto.git +http://testbdgit2.educoder.net/educoder/jtnlfgw2.git +http://testbdgit2.educoder.net/educoder/fa96xrti.git +http://testbdgit2.educoder.net/educoder/r6bjga3u.git +http://testbdgit2.educoder.net/educoder/fpmwzxqn.git +http://testbdgit2.educoder.net/educoder/rbpsw8ct.git +http://testbdgit2.educoder.net/educoder/4zuxembp.git +http://testbdgit2.educoder.net/educoder/3gxwrzaf.git +http://testbdgit2.educoder.net/educoder/wz6j5lpn.git +http://testbdgit2.educoder.net/educoder/izu9tf3j.git +http://testbdgit2.educoder.net/educoder/vhux4pa7.git +http://testbdgit2.educoder.net/educoder/s9wvroqn.git +http://testbdgit2.educoder.net/educoder/ruofj2xl.git +http://testbdgit2.educoder.net/educoder/qj4mlxoi.git +http://testbdgit2.educoder.net/educoder/34gzbolc.git +http://testbdgit2.educoder.net/educoder/at86wfsn.git +http://testbdgit2.educoder.net/educoder/j7fnwsrh.git +http://testbdgit2.educoder.net/educoder/zgsuk364.git +http://testbdgit2.educoder.net/educoder/nf3gv54x.git +http://testbdgit2.educoder.net/educoder/fnbuq957.git +http://testbdgit2.educoder.net/educoder/z4fp9o3e.git +http://testbdgit2.educoder.net/educoder/c3qh4p6f.git +http://testbdgit2.educoder.net/educoder/fszntcbw.git +http://testbdgit2.educoder.net/educoder/af968lnf.git +http://testbdgit2.educoder.net/educoder/kpc36fhn.git +http://testbdgit2.educoder.net/educoder/6c4wp5bu.git +http://testbdgit2.educoder.net/educoder/hzmikncs.git +http://testbdgit2.educoder.net/educoder/6ogr4bhj.git +http://testbdgit2.educoder.net/educoder/fu59rezf.git +http://testbdgit2.educoder.net/educoder/zef9gswv.git +http://testbdgit2.educoder.net/educoder/p9z4fxv8.git +http://testbdgit2.educoder.net/eduforge/hcxeuyfl.git +http://testbdgit2.educoder.net/educoder/4u2ebx89.git +http://testbdgit2.educoder.net/educoder/cikojzsb.git +http://testbdgit2.educoder.net/educoder/2rzomtx5.git +http://testbdgit2.educoder.net/educoder/wfvbhr2s.git +http://testbdgit2.educoder.net/educoder/q8mxg4zv.git +http://testbdgit2.educoder.net/educoder/q8fezi37.git +http://testbdgit2.educoder.net/educoder/nb7ha8te.git +http://testbdgit2.educoder.net/educoder/qxgfbyn9.git +http://testbdgit2.educoder.net/educoder/k8so9wa2.git +http://testbdgit2.educoder.net/educoder/zwc9ja5y.git +http://testbdgit2.educoder.net/educoder/89lwscfy.git +http://testbdgit2.educoder.net/educoder/ga26fy4f.git +http://testbdgit2.educoder.net/educoder/rgy4769i.git +http://testbdgit2.educoder.net/educoder/q3rnovik.git +http://testbdgit2.educoder.net/educoder/r5xsukn4.git +http://testbdgit2.educoder.net/educoder/yu6za47j.git +http://testbdgit2.educoder.net/educoder/fqvr56nm.git +http://testbdgit2.educoder.net/educoder/tq26m73o.git +http://testbdgit2.educoder.net/educoder/k2rmpuf6.git +http://testbdgit2.educoder.net/educoder/fzg87ip6.git +http://testbdgit2.educoder.net/educoder/qk3l64zi.git +http://testbdgit2.educoder.net/educoder/bcjpk93f.git +http://testbdgit2.educoder.net/educoder/rnjak48l.git +http://testbdgit2.educoder.net/educoder/hyzkq5vr.git +http://testbdgit2.educoder.net/educoder/tqnvbisr.git +http://testbdgit2.educoder.net/educoder/nfszy26f.git +http://testbdgit2.educoder.net/educoder/rfnhkvgo.git +http://testbdgit2.educoder.net/educoder/6omf2gbl.git +http://testbdgit2.educoder.net/educoder/x4qhb5k7.git +http://testbdgit2.educoder.net/educoder/jyz63ge5.git +http://testbdgit2.educoder.net/educoder/hfqwilp3.git +http://testbdgit2.educoder.net/educoder/aq9c4fy5.git +http://testbdgit2.educoder.net/educoder/tzshnbl8.git +http://testbdgit2.educoder.net/educoder/zm8qffrj.git +http://testbdgit2.educoder.net/educoder/szctor3e.git +http://testbdgit2.educoder.net/educoder/amcyzpvk.git +http://testbdgit2.educoder.net/educoder/fpy467o9.git +http://testbdgit2.educoder.net/educoder/w5nytxec.git +http://testbdgit2.educoder.net/educoder/icreqzu4.git +http://testbdgit2.educoder.net/educoder/2jf76xr5.git +http://testbdgit2.educoder.net/educoder/yl4a2qf5.git +http://testbdgit2.educoder.net/educoder/jgmcieqk.git +http://testbdgit2.educoder.net/educoder/hjtxy657.git +http://testbdgit2.educoder.net/educoder/47w6uyeh.git +http://testbdgit2.educoder.net/educoder/pr4vg7j5.git +http://testbdgit2.educoder.net/educoder/m6xn7z93.git +http://testbdgit2.educoder.net/educoder/f23fge9h.git +http://testbdgit2.educoder.net/educoder/cfo7lqhs.git +http://testbdgit2.educoder.net/educoder/4gnkqf3y.git +http://testbdgit2.educoder.net/educoder/k89bgonj.git +http://testbdgit2.educoder.net/educoder/k98qr7iw.git +http://testbdgit2.educoder.net/educoder/jel85v62.git +http://testbdgit2.educoder.net/educoder/zt2aqnb6.git +http://testbdgit2.educoder.net/educoder/7icqubfj.git +http://testbdgit2.educoder.net/educoder/2x59s3by.git +http://testbdgit2.educoder.net/educoder/mrvwxekj.git +http://testbdgit2.educoder.net/educoder/k5cruoyp.git +http://testbdgit2.educoder.net/educoder/rc6hw58u.git +http://testbdgit2.educoder.net/educoder/ygzf7v3k.git +http://testbdgit2.educoder.net/educoder/8ty6fgln.git +http://testbdgit2.educoder.net/educoder/wp5mbjg8.git +http://testbdgit2.educoder.net/educoder/oniuafxz.git +http://testbdgit2.educoder.net/educoder/aviljpmn.git +http://testbdgit2.educoder.net/educoder/iufg8573.git +http://testbdgit2.educoder.net/educoder/gc8xl2v9.git +http://testbdgit2.educoder.net/educoder/2wgmhvuk.git +http://testbdgit2.educoder.net/educoder/clx7ha6j.git +http://testbdgit2.educoder.net/educoder/bz9wxpvr.git +http://testbdgit2.educoder.net/educoder/uw95cg28.git +http://testbdgit2.educoder.net/educoder/4frpc7ix.git +http://testbdgit2.educoder.net/educoder/nas3v78t.git +http://testbdgit2.educoder.net/educoder/cbrys8f3.git +http://testbdgit2.educoder.net/educoder/ofj29enq.git +http://testbdgit2.educoder.net/educoder/btvk2w5h.git +http://testbdgit2.educoder.net/educoder/cztbjan5.git +http://testbdgit2.educoder.net/educoder/7atfm9vu.git +http://testbdgit2.educoder.net/educoder/cpxs3kfu.git +http://testbdgit2.educoder.net/educoder/5pfalzkh.git +http://testbdgit2.educoder.net/educoder/yf6covh2.git +http://testbdgit2.educoder.net/educoder/ocevha8x.git +http://testbdgit2.educoder.net/educoder/qtxkogfi.git +http://testbdgit2.educoder.net/educoder/pa8fh4m2.git +http://testbdgit2.educoder.net/educoder/n3ps8i4m.git +http://testbdgit2.educoder.net/educoder/5x9alvmc.git +http://testbdgit2.educoder.net/educoder/yl732ofk.git +http://testbdgit2.educoder.net/educoder/hvlgfjb7.git +http://testbdgit2.educoder.net/educoder/i9sfum58.git +http://testbdgit2.educoder.net/educoder/my9jcvio.git +http://testbdgit2.educoder.net/educoder/2myqxbce.git +http://testbdgit2.educoder.net/educoder/p4x9qmka.git +http://testbdgit2.educoder.net/educoder/aslcogwk.git +http://testbdgit2.educoder.net/educoder/eryg8fot.git +http://testbdgit2.educoder.net/educoder/ust5hgjm.git +http://testbdgit2.educoder.net/educoder/ypve8gbo.git +http://testbdgit2.educoder.net/educoder/ir768pfq.git +http://testbdgit2.educoder.net/educoder/ki98yelu.git +http://testbdgit2.educoder.net/educoder/i4nzvb7x.git +http://testbdgit2.educoder.net/educoder/58l7vb9f.git +http://testbdgit2.educoder.net/educoder/l859pqs3.git +http://testbdgit2.educoder.net/educoder/6rvpzn7x.git +http://testbdgit2.educoder.net/educoder/c5msxfe8.git +http://testbdgit2.educoder.net/educoder/cwa6igze.git +http://testbdgit2.educoder.net/educoder/vbnqglcw.git +http://testbdgit2.educoder.net/educoder/8bysvmcf.git +http://testbdgit2.educoder.net/educoder/u3ceh2xw.git +http://testbdgit2.educoder.net/educoder/heqtnza3.git +http://testbdgit2.educoder.net/educoder/uzoltjva.git +http://testbdgit2.educoder.net/educoder/mefykafs.git +http://testbdgit2.educoder.net/educoder/6jvypwgq.git +http://testbdgit2.educoder.net/educoder/h5wisac9.git +http://testbdgit2.educoder.net/educoder/52ufjw9m.git +http://testbdgit2.educoder.net/educoder/v2uxoifl.git +http://testbdgit2.educoder.net/educoder/an2ofy6k.git +http://testbdgit2.educoder.net/educoder/kao2rlf5.git +http://testbdgit2.educoder.net/educoder/uihap3wr.git +http://testbdgit2.educoder.net/educoder/wliam3nq.git +http://testbdgit2.educoder.net/educoder/7cpo6hel.git +http://testbdgit2.educoder.net/educoder/bmtlph7e.git +http://testbdgit2.educoder.net/educoder/b8n9twpf.git +http://testbdgit2.educoder.net/educoder/3cur5wz6.git +http://testbdgit2.educoder.net/educoder/h6ga29wv.git +http://testbdgit2.educoder.net/educoder/67kv4zmg.git +http://testbdgit2.educoder.net/educoder/buf6h8jf.git +http://testbdgit2.educoder.net/educoder/gce9ojqv.git +http://testbdgit2.educoder.net/educoder/jm2l6rwf.git +http://testbdgit2.educoder.net/educoder/4lwfjfrt.git +http://testbdgit2.educoder.net/educoder/5qsw32oj.git +http://testbdgit2.educoder.net/educoder/9yw36vxq.git +http://testbdgit2.educoder.net/educoder/93fivo6k.git +http://testbdgit2.educoder.net/educoder/nwy3x4t2.git +http://testbdgit2.educoder.net/educoder/ku9o2fcf.git +http://testbdgit2.educoder.net/educoder/s68uqlic.git +http://testbdgit2.educoder.net/educoder/4bajyohg.git +http://testbdgit2.educoder.net/educoder/qtfpscz8.git +http://testbdgit2.educoder.net/educoder/j5u7y6wn.git +http://testbdgit2.educoder.net/educoder/btku8vcx.git +http://testbdgit2.educoder.net/educoder/a9n8w2eu.git +http://testbdgit2.educoder.net/educoder/vze7ny25.git +http://testbdgit2.educoder.net/educoder/yz5aofe2.git +http://testbdgit2.educoder.net/educoder/r9nibvz4.git +http://testbdgit2.educoder.net/educoder/6cvxk3q8.git +http://testbdgit2.educoder.net/educoder/rmtuvk6z.git +http://testbdgit2.educoder.net/educoder/sbitr936.git +http://testbdgit2.educoder.net/educoder/sb6j4raf.git +http://testbdgit2.educoder.net/educoder/a7gfvh5s.git +http://testbdgit2.educoder.net/educoder/zsj6ao3c.git +http://testbdgit2.educoder.net/educoder/8x2epwk6.git +http://testbdgit2.educoder.net/educoder/cbnfxeiw.git +http://testbdgit2.educoder.net/educoder/ul47bqcn.git +http://testbdgit2.educoder.net/educoder/ltsnfy4x.git +http://testbdgit2.educoder.net/educoder/t53nvo8e.git +http://testbdgit2.educoder.net/educoder/yojwp2mb.git +http://testbdgit2.educoder.net/educoder/67nayvtg.git +http://testbdgit2.educoder.net/educoder/42fq3yx7.git +http://testbdgit2.educoder.net/educoder/f39hiscw.git +http://testbdgit2.educoder.net/educoder/jey9avks.git +http://testbdgit2.educoder.net/educoder/ascbpy86.git +http://testbdgit2.educoder.net/educoder/vagzfryl.git +http://testbdgit2.educoder.net/educoder/c6k5i82o.git +http://testbdgit2.educoder.net/educoder/utr8bp9a.git +http://testbdgit2.educoder.net/educoder/ul65ap4o.git +http://testbdgit2.educoder.net/educoder/bmulap4n.git +http://testbdgit2.educoder.net/educoder/nxj2sfvr.git +http://testbdgit2.educoder.net/educoder/vq5t9hea.git +http://testbdgit2.educoder.net/educoder/7g5l6kzr.git +http://testbdgit2.educoder.net/educoder/2y8t594n.git +http://testbdgit2.educoder.net/educoder/mlnpqx9r.git +http://testbdgit2.educoder.net/educoder/apgxmqs7.git +http://testbdgit2.educoder.net/educoder/vur567ha.git +http://testbdgit2.educoder.net/educoder/qwctfpjl.git +http://testbdgit2.educoder.net/educoder/5w6gh9m8.git +http://testbdgit2.educoder.net/educoder/fzhe4mpv.git +http://testbdgit2.educoder.net/educoder/vmygstfb.git +http://testbdgit2.educoder.net/educoder/uryh3e4i.git +http://testbdgit2.educoder.net/educoder/nbixuzkf.git +http://testbdgit2.educoder.net/educoder/zpkyj7bs.git +http://testbdgit2.educoder.net/educoder/79tpk5oy.git +http://testbdgit2.educoder.net/educoder/s93x58at.git +http://testbdgit2.educoder.net/educoder/6ymec92a.git +http://testbdgit2.educoder.net/educoder/7vqgbsfc.git +http://testbdgit2.educoder.net/educoder/fr5fom8n.git +http://testbdgit2.educoder.net/educoder/7uzyskn9.git +http://testbdgit2.educoder.net/educoder/g4fvywf6.git +http://testbdgit2.educoder.net/educoder/wa98h2ly.git +http://testbdgit2.educoder.net/educoder/u6i2o3qz.git +http://testbdgit2.educoder.net/educoder/enxbyiok.git +http://testbdgit2.educoder.net/educoder/2fuweqf8.git +http://testbdgit2.educoder.net/educoder/48flws5g.git +http://testbdgit2.educoder.net/educoder/yugrij4n.git +http://testbdgit2.educoder.net/educoder/gtbkvm58.git +http://testbdgit2.educoder.net/educoder/nes73wfv.git +http://testbdgit2.educoder.net/educoder/oztyjl4h.git +http://testbdgit2.educoder.net/educoder/f398leqr.git +http://testbdgit2.educoder.net/educoder/i3xutoze.git +http://testbdgit2.educoder.net/educoder/mfv6zrj7.git +http://testbdgit2.educoder.net/educoder/6ujfeqbh.git +http://testbdgit2.educoder.net/educoder/8x93tfqn.git +http://testbdgit2.educoder.net/educoder/fxv9bpcw.git +http://testbdgit2.educoder.net/eduforge/64xb9k2q.git +http://testbdgit2.educoder.net/educoder/5e4vcr7t.git +http://testbdgit2.educoder.net/educoder/qwaffs2p.git +http://testbdgit2.educoder.net/educoder/ose7482b.git +http://testbdgit2.educoder.net/educoder/wt2xfzny.git +http://testbdgit2.educoder.net/educoder/cuqnpzjv.git +http://testbdgit2.educoder.net/educoder/n3a8q9b2.git +http://testbdgit2.educoder.net/educoder/f9o4hpix.git +http://testbdgit2.educoder.net/educoder/bm9qr7ue.git +http://testbdgit2.educoder.net/educoder/nhlygi7p.git +http://testbdgit2.educoder.net/educoder/mf2vfngu.git +http://testbdgit2.educoder.net/educoder/x6tsevzy.git +http://testbdgit2.educoder.net/educoder/rjfbm74o.git +http://testbdgit2.educoder.net/educoder/ztbukf7e.git +http://testbdgit2.educoder.net/educoder/pf8yze9h.git +http://testbdgit2.educoder.net/educoder/nrug2mfz.git +http://testbdgit2.educoder.net/educoder/jswmzaxr.git +http://testbdgit2.educoder.net/educoder/wpxjzo3c.git +http://testbdgit2.educoder.net/educoder/zaohblre.git +http://testbdgit2.educoder.net/educoder/psx2h9kf.git +http://testbdgit2.educoder.net/educoder/ayju6fie.git +http://testbdgit2.educoder.net/educoder/5kp9guol.git +http://testbdgit2.educoder.net/educoder/c4ztkfb2.git +http://testbdgit2.educoder.net/educoder/kboupjtl.git +http://testbdgit2.educoder.net/educoder/bcvhs9u7.git +http://testbdgit2.educoder.net/educoder/26vljnb3.git +http://testbdgit2.educoder.net/educoder/zesqa3wi.git +http://testbdgit2.educoder.net/educoder/43phxgsf.git +http://testbdgit2.educoder.net/educoder/fbx6awcm.git +http://testbdgit2.educoder.net/educoder/i2s7jof5.git +http://testbdgit2.educoder.net/educoder/n2w4jrax.git +http://testbdgit2.educoder.net/educoder/4pou5tey.git +http://testbdgit2.educoder.net/eduforge/e9qr7cxi.git +http://testbdgit2.educoder.net/educoder/y6bg739q.git +http://testbdgit2.educoder.net/educoder/h32r58s7.git +http://testbdgit2.educoder.net/eduforge/hpr7ojgc-1.git +http://testbdgit2.educoder.net/educoder/c3j4hufp.git +http://testbdgit2.educoder.net/eduforge/o72clmi4.git +http://testbdgit2.educoder.net/educoder/qfz8o2r6.git +http://testbdgit2.educoder.net/educoder/rw3i8vf2.git +http://testbdgit2.educoder.net/educoder/shpwf3xf.git +http://testbdgit2.educoder.net/eduforge/vnw2fg5r.git +http://testbdgit2.educoder.net/innov/f2izon59.git +http://testbdgit2.educoder.net/innov/qlkpiusm.git +http://testbdgit2.educoder.net/innov/edu1547017399.git +http://testbdgit2.educoder.net/forge01/cermyt39.git +http://testbdgit2.educoder.net/innov/em3z8yn6.git +http://testbdgit2.educoder.net/innov/c8ynf526.git +http://testbdgit2.educoder.net/Hjqreturn/sx36oveq.git +http://testbdgit2.educoder.net/innov/t7sxkfab20190115135957.git +http://testbdgit2.educoder.net/innov/etlb3pn620190115140004.git +http://testbdgit2.educoder.net/innov/5jbomfrg20190115140011.git +http://testbdgit2.educoder.net/innov/6ecmbf7g20190115140015.git +http://testbdgit2.educoder.net/innov/f7jn8kex20190115140330.git diff --git a/lib/gitcheck/shixun_update_error.txt b/lib/gitcheck/shixun_update_error.txt new file mode 100644 index 000000000..ef9663c46 --- /dev/null +++ b/lib/gitcheck/shixun_update_error.txt @@ -0,0 +1,72 @@ +mbtclufr +9op3hs4j +96ctv7yr +rtmzxfke +ofqxthrf +czu9w4gj +9fpzj6et +pwhc865b +maozpx4l +y5wh2ofx +b5rzhpf3 +bs243nrl +47fn2yfb +kwotfxey +w5468sbp +fyekprio +q6ze5fih +b5hjq9zm +ky8pbqux +53phc7nq +b9j2yuix +9t3uphwk +iokm8ah2 +qlsy6xb4 +345bqhfi +v728fqia +4euftvf2 +f23sef5m +nhqis8m9 +qp72tb5x +gt3anszw +tng6heyf +nb9keawo +elgnbkp9 +4neslomg +lh35s6ma +xmc4rpay +qrpaxi6b +9fla2zry +efuibzrm +fzp3iu4w +pligsyn8 +glbksr29 +kfm7ghyc +p6hk3svf +p539gjhm +am5o73er +4x3qwrbe +fqosyl8g +of5z3fci +tb7hw62n +ie6zxg7r +4q2bmy9h +fpm3u5yb +nikx3ojt +vt82s9bq +ma59fefo +lxa39tfq +4gnockxf +nxwg84ey +fmie8nzb +w5nsr24v +4hn3efwc +h9ljfbq7 +nuv54t8b +2te9fmfq +vihnsayz +qhlyn82s +vw74kmfr +vcta36bz +henz425l +g529v38z diff --git a/lib/tasks/git_check.rake b/lib/tasks/git_check.rake index 64f8be91b..a5e95eedc 100644 --- a/lib/tasks/git_check.rake +++ b/lib/tasks/git_check.rake @@ -1,15 +1,52 @@ +# 需要做的几件事: +# 1、检测两边(TPM\TPI)同步后有更新的仓库 +# + namespace :git do desc "检测是否TPM是否需要更新" task :shixun_check_update => :environment do - + g = Gitlab.client + file_txt = File.new("lib/gitcheck/shixun_update.txt", "r+") + file_error_txt = File.new("lib/gitcheck/shixun_update_error.txt", "r+") + host = EduSetting.find_by_name("git_address_domain").try(:value) + Shixun.find_each do |shixun| + begin + gitlab_commit = g.commits(shixun.gpid, :ref_name => 'master').first.try(:id) + repo_name = shixun.repo_name + git_commit = GitService.commits(repo_path: "#{repo_name}.git").first["id"] + git_url = host + "/" + repo_name + ".git\n" + if git_commit != gitlab_commit + file_txt.syswrite(git_url) + end + rescue + file_error_txt.syswrite("#{shixun.identifier}\n") + end + end end - desc "检测版本库是否有异常" + desc "检测版本库是否有更新" task :myshixuns_check_update => :environment do - + g = Gitlab.client + file_txt = File.new("lib/gitcheck/myshixun_update.txt", "r+") + file_error_txt = File.new("lib/gitcheck/myshixun_update_error.txt", "r+") + host = EduSetting.find_by_name("git_address_domain").try(:value) + Myshixun.find_each do |myshixun| + begin + gitlab_commit = g.commits(myshixun.gpid, :ref_name => 'master').first.try(:id) + repo_name = myshixun.repo_name + git_commit = GitService.commits(repo_path: "#{repo_name}.git").first["id"] + git_url = host + "/" + repo_name + ".git\n" + if git_commit != gitlab_commit + file_txt.syswrite(git_url) + end + rescue + file_error_txt.syswrite("#{myshixun.identifier}\n") + end + end end + # 检测TPI没有迁移过来的 task :check => :environment do end From bab042a7a5e80ec2f1739b13e68fd09f5ca61743 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 27 Jun 2019 11:35:10 +0800 Subject: [PATCH 0296/1015] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=9B=86=E8=A7=A3?= =?UTF-8?q?=E9=94=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 1 + config/routes.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 32175ec2f..4e7afa516 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -270,6 +270,7 @@ class GamesController < ApplicationController if @game.status == 2 @game.update_attributes!(:answer_open => @answer.level) else + # 扣除总分计算 answer_deduction = challenge.challenge_answers.where("level <= #{@answer.level}").sum(:score) @game.update_attributes!(:answer_open => @answer.level, :answer_deduction => answer_deduction) end diff --git a/config/routes.rb b/config/routes.rb index ecd54c8c0..f81d90267 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -117,6 +117,7 @@ Rails.application.routes.draw do get :close_webssh get :get_answer_info get :unlock_answer + get :check_test_sets end collection do From f755a2dca8aacaba6d1b5f74d502c9f3d7776a93 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 27 Jun 2019 14:07:24 +0800 Subject: [PATCH 0297/1015] fix export exercise pdf --- app/controllers/accounts_controller.rb | 1 - app/services/exercise_user_pdf_service.rb | 6 +++--- app/templates/exercise_export/exercise_export.css | 2 +- app/templates/exercise_export/exercise_user.html.erb | 7 ++++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index c3333c912..0d32926e4 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -83,7 +83,6 @@ class AccountsController < ApplicationController email = params[:login] verifi_code = VerificationCode.where(email: email, code: code, code_type: 3).last user = User.find_by_mail(email) #这里有问题,应该是为email,而不是mail 6.13-hs - end check_code = (verifi_code.try(:code) == code.strip && (Time.now.to_i - verifi_code.created_at.to_i) <= 10*60) unless check_code diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index d74e66d31..663d8b042 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -47,7 +47,7 @@ class ExerciseUserPdfService end def load_data - @exercise_questions = exercise.exercise_questions + @exercise_questions = exercise.exercise_questions.joins(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments) @exercise_ques_count = @exercise_questions.count # 全部的题目数 @exercise_ques_scores = @exercise_questions.pluck(:question_score).sum @@ -81,9 +81,9 @@ class ExerciseUserPdfService @exercise_ques_shixun_count = exercise_ques_shixun.all.count @exercise_ques_shixun_scores = exercise_ques_shixun.pluck(:question_score).sum - challenge_ids = @exercise_questions.joins(:exercise_shixun_challenges).pluck("exercise_shixun_challenges.challenge_id") + challenge_ids = @exercise_questions.pluck("exercise_shixun_challenges.challenge_id") get_each_student_exercise(exercise.id,@exercise_questions,@ex_user_user.id) - @games = @exercise_user.user.games.ch_games(challenge_ids) + # @games = @exercise_user.user.games.ch_games(challenge_ids) end end \ No newline at end of file diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 59be4f1bd..e04f77035 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -231,7 +231,7 @@ p{ position: absolute; display: inline-block; bottom: 9px; - left: 1px; + left: 2px; } .circle-right:after{ color:#fff; diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 193a25301..c81f45d68 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -112,6 +112,7 @@
<% @exercise_questions.each do |q| %> <% q_type = q.question_type %> + <% games =( q_type == 5 ? @ex_user_user.games.ch_games(q.exercise_shixun_challenges.pluck(:challenge_id)) : nil) %> <% user_answer = (q_type == 5 ? q.exercise_shixun_answers.where(user_id: @ex_user_user.id) : q.exercise_answers.where(user_id: @ex_user_user.id)) %> <% this_ques_status = @ex_obj_array.detect{|f| f[:q_id] == q.id} %> <% main_ques_status = @ex_sub_array.detect{|f| f[:q_id] == q.id} %> @@ -247,8 +248,8 @@ 得分/满分 - <% if @games.size > 0 %> - <% @games.each_with_index do |game, index| %> + <% if games.present? %> + <% games&.each_with_index do |game, index| %> <% game_score = q.exercise_shixun_challenges.where(challenge_id:game.challenge.id) %> <% user_score = q.exercise_shixun_answers.where(exercise_shixun_challenge_id: game_score&.first&.id,user_id: @ex_user_user.id) %> @@ -286,7 +287,7 @@

实训详情

- <% @games.each_with_index do |game, index| %> + <% games&.each_with_index do |game, index| %>

第<%= index+1 %>关<%= game.challenge.subject %> From 3eadedc9ad3ec611e67016d761870fe42f312f78 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 27 Jun 2019 14:11:38 +0800 Subject: [PATCH 0298/1015] fix bug --- app/services/exercise_user_pdf_service.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 663d8b042..d76e792c4 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -47,7 +47,7 @@ class ExerciseUserPdfService end def load_data - @exercise_questions = exercise.exercise_questions.joins(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments) + @exercise_questions = exercise.exercise_questions @exercise_ques_count = @exercise_questions.count # 全部的题目数 @exercise_ques_scores = @exercise_questions.pluck(:question_score).sum @@ -80,8 +80,9 @@ class ExerciseUserPdfService exercise_ques_shixun = @exercise_questions.find_by_custom("question_type",5) @exercise_ques_shixun_count = exercise_ques_shixun.all.count @exercise_ques_shixun_scores = exercise_ques_shixun.pluck(:question_score).sum + @exercise_questions = @exercise_questions.joins(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers) - challenge_ids = @exercise_questions.pluck("exercise_shixun_challenges.challenge_id") + # challenge_ids = @exercise_questions.pluck("exercise_shixun_challenges.challenge_id") get_each_student_exercise(exercise.id,@exercise_questions,@ex_user_user.id) # @games = @exercise_user.user.games.ch_games(challenge_ids) From d89a9138d15975ecafc33c0b6adf234c934e8a03 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 27 Jun 2019 14:13:27 +0800 Subject: [PATCH 0299/1015] fix bug --- app/services/exercise_user_pdf_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index d76e792c4..ae90f60bf 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -80,7 +80,7 @@ class ExerciseUserPdfService exercise_ques_shixun = @exercise_questions.find_by_custom("question_type",5) @exercise_ques_shixun_count = exercise_ques_shixun.all.count @exercise_ques_shixun_scores = exercise_ques_shixun.pluck(:question_score).sum - @exercise_questions = @exercise_questions.joins(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers) + # @exercise_questions = @exercise_questions.joins(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers) # challenge_ids = @exercise_questions.pluck("exercise_shixun_challenges.challenge_id") From ca172d57e796a813a65d581fcebe1fcd47fb09e1 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 27 Jun 2019 14:19:15 +0800 Subject: [PATCH 0300/1015] fix exprot exercise bugs 2 --- app/services/exercise_user_pdf_service.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index ae90f60bf..422c3ad5f 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -47,7 +47,7 @@ class ExerciseUserPdfService end def load_data - @exercise_questions = exercise.exercise_questions + @exercise_questions = exercise.exercise_questions.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers) @exercise_ques_count = @exercise_questions.count # 全部的题目数 @exercise_ques_scores = @exercise_questions.pluck(:question_score).sum @@ -80,11 +80,7 @@ class ExerciseUserPdfService exercise_ques_shixun = @exercise_questions.find_by_custom("question_type",5) @exercise_ques_shixun_count = exercise_ques_shixun.all.count @exercise_ques_shixun_scores = exercise_ques_shixun.pluck(:question_score).sum - # @exercise_questions = @exercise_questions.joins(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers) - - # challenge_ids = @exercise_questions.pluck("exercise_shixun_challenges.challenge_id") get_each_student_exercise(exercise.id,@exercise_questions,@ex_user_user.id) - # @games = @exercise_user.user.games.ch_games(challenge_ids) end end \ No newline at end of file From 6e36cc24ab8b803028f99cad4d90ce6198b8c859 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 27 Jun 2019 14:22:04 +0800 Subject: [PATCH 0301/1015] fix bug --- app/services/exercise_user_pdf_service.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 422c3ad5f..28857dff9 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -47,7 +47,7 @@ class ExerciseUserPdfService end def load_data - @exercise_questions = exercise.exercise_questions.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers) + @exercise_questions = exercise.exercise_questions @exercise_ques_count = @exercise_questions.count # 全部的题目数 @exercise_ques_scores = @exercise_questions.pluck(:question_score).sum @@ -81,6 +81,8 @@ class ExerciseUserPdfService @exercise_ques_shixun_count = exercise_ques_shixun.all.count @exercise_ques_shixun_scores = exercise_ques_shixun.pluck(:question_score).sum + @exercise_questions = @exercise_questions.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers) get_each_student_exercise(exercise.id,@exercise_questions,@ex_user_user.id) + end end \ No newline at end of file From 28c641510c13cd7a6477df4c8176ac6dbec0292d Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 27 Jun 2019 14:32:05 +0800 Subject: [PATCH 0302/1015] fix bug --- app/controllers/exercises_controller.rb | 2 +- app/templates/exercise_export/exercise_export.css | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 44b694239..e1e8e226b 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1334,7 +1334,7 @@ class ExercisesController < ApplicationController #导出空白试卷 def export_exercise - @exercise_questions = @exercise.exercise_questions.order("question_number ASC") + @exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") filename = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.current.strftime('%Y%m%d%H%M%S')}.pdf" stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css" render pdf: 'exercise_export/blank_exercise', filename: filename, stylesheets: stylesheets diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index e04f77035..9190e9251 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -156,7 +156,7 @@ p{ position: absolute; display: inline-block; bottom: 6px; - /*left: 1px;*/ + left: 1px; } .line-line { From aab9b3e56d9c098e648923486dff33ce53efd1b4 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 27 Jun 2019 14:40:15 +0800 Subject: [PATCH 0303/1015] =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E7=9A=84=E5=BC=82=E6=AD=A5=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...omework_absence_penalty_calculation_job.rb | 33 +++++ ...ework_anonymous_appeal_start_notify_job.rb | 27 ++++ app/jobs/homework_common_push_notify_job.rb | 2 +- .../homework_evaluation_comment_assgin_job.rb | 48 +++++++ .../homework_evaluation_start_notify_job.rb | 30 +++++ ...homework_publish_update_work_status_job.rb | 2 +- config/sidekiq.yml | 2 + lib/tasks/homework_evaluation.rake | 122 +----------------- lib/tasks/homework_publishtime.rake | 56 +++----- ...rk_absence_penalty_calculation_job_spec.rb | 5 + ..._anonymous_appeal_start_notify_job_spec.rb | 5 + ...work_evaluation_comment_assgin_job_spec.rb | 5 + ...mework_evaluation_start_notify_job_spec.rb | 5 + 13 files changed, 184 insertions(+), 158 deletions(-) create mode 100644 app/jobs/homework_absence_penalty_calculation_job.rb create mode 100644 app/jobs/homework_anonymous_appeal_start_notify_job.rb create mode 100644 app/jobs/homework_evaluation_comment_assgin_job.rb create mode 100644 app/jobs/homework_evaluation_start_notify_job.rb create mode 100644 spec/jobs/homework_absence_penalty_calculation_job_spec.rb create mode 100644 spec/jobs/homework_anonymous_appeal_start_notify_job_spec.rb create mode 100644 spec/jobs/homework_evaluation_comment_assgin_job_spec.rb create mode 100644 spec/jobs/homework_evaluation_start_notify_job_spec.rb diff --git a/app/jobs/homework_absence_penalty_calculation_job.rb b/app/jobs/homework_absence_penalty_calculation_job.rb new file mode 100644 index 000000000..87f78f311 --- /dev/null +++ b/app/jobs/homework_absence_penalty_calculation_job.rb @@ -0,0 +1,33 @@ +class HomeworkAbsencePenaltyCalculationJob < ApplicationJob + queue_as :score + + def perform(homework_common_id) + homework_common = HomeworkCommon.find_by(id: homework_common_id) + return if homework_common.blank? + + #计算缺评扣分 参与匿评 + work_ids = homework_common.student_works.has_committed.pluck(:id) + homework_detail_manual = homework_common.homework_detail_manual + + homework_common.student_works.where("work_status != 0").each do |student_work| + absence_penalty_count = student_work.user.student_works_evaluation_distributions.where(student_work_id: work_ids).count - + student_work.user.student_works_scores.where(student_work_id: work_ids, reviewer_role: 3).group_by(:student_work_id).count + + student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * homework_detail_manual.absence_penalty : 0 + student_work.save + end + + # 未参与匿评 + if homework_detail_manual.no_anon_penalty == 0 + all_dis_eva = StudentWorksEvaluationDistribution.where(student_work_id: work_ids) + has_sw_count = all_dis_eva.select("distinct user_id").count + anon_count = all_dis_eva.count / has_sw_count + homework_common.student_works.where("work_status != 0").each do |student_work| + if student_work.user.student_works_evaluation_distributions.where(student_work_id: work_ids).count == 0 + student_work.absence_penalty = homework_detail_manual.absence_penalty * anon_count + student_work.save + end + end + end + end +end diff --git a/app/jobs/homework_anonymous_appeal_start_notify_job.rb b/app/jobs/homework_anonymous_appeal_start_notify_job.rb new file mode 100644 index 000000000..97c369846 --- /dev/null +++ b/app/jobs/homework_anonymous_appeal_start_notify_job.rb @@ -0,0 +1,27 @@ +class HomeworkAnonymousAppealStartNotifyJob < ApplicationJob + queue_as :notify + + def perform(homework_common_id) + homework = HomeworkCommon.find_by(id: homework_common_id) + return if homework.blank? + eva_distribution = StudentWorksEvaluationDistribution.where(student_work_id: homework.student_works.pluck(:id)) + + attrs = %i[ + user_id trigger_user_id container_id container_type parent_container_id parent_container_type + belong_container_id belong_container_type viewed tiding_type created_at updated_at + ] + + same_attrs = { + trigger_user_id: homework.user_id, container_id: homework.id, container_type: 'HomeworkCommon', + parent_container_id: homework.id, parent_container_type: 'AnonymousAppeal', + belong_container_id: homework.course_id, belong_container_type: 'Course', + viewed: 0, tiding_type: 'HomeworkCommon' + } + Tiding.bulk_insert(*attrs) do |worker| + + eva_distribution.pluck(:user_id).uniq.each do |user_id| + worker.add same_attrs.merge(user_id: user_id) + end + end + end +end diff --git a/app/jobs/homework_common_push_notify_job.rb b/app/jobs/homework_common_push_notify_job.rb index 961face58..47956a14c 100644 --- a/app/jobs/homework_common_push_notify_job.rb +++ b/app/jobs/homework_common_push_notify_job.rb @@ -24,7 +24,7 @@ class HomeworkCommonPushNotifyJob < ApplicationJob same_attrs = { trigger_user_id: homework.user_id, container_id: homework.id, container_type: 'HomeworkCommon', parent_container_id: homework.id, parent_container_type: 'HomeworkPublish', - belong_container_id: task.course_id, belong_container_type: 'Course', + belong_container_id: homework.course_id, belong_container_type: 'Course', viewed: 0, tiding_type: 'HomeworkCommon' } Tiding.bulk_insert(*attrs) do |worker| diff --git a/app/jobs/homework_evaluation_comment_assgin_job.rb b/app/jobs/homework_evaluation_comment_assgin_job.rb new file mode 100644 index 000000000..2579ea18b --- /dev/null +++ b/app/jobs/homework_evaluation_comment_assgin_job.rb @@ -0,0 +1,48 @@ +class HomeworkEvaluationCommentAssginJob < ApplicationJob + queue_as :evaluation_comment + + def get_assigned_homeworks(student_works, n, index) + student_works += student_works + student_works[index + 1..index + n] + end + + def perform(homework_common_id) + homework_common = HomeworkCommon.find_by(id: homework_common_id) + return if homework_common.blank? + homework_detail_manual = homework_common.homework_detail_manual + + if homework_common.homework_type == "group" + student_works = homework_common.student_works.where("work_status != 0").group(:group_id) + student_work_projects = homework_common.student_works.where("work_status != 0").shuffle + student_work_projects.each do |pro_work| + n = homework_detail_manual.evaluation_num + n = (n < student_works.size && n != -1) ? n : student_works.size - 1 + work_index = -1 + student_works.each_with_index do |stu_work, stu_index| + if stu_work.group_id.to_i == pro_work.group_id.to_i + work_index = stu_index + end + end + assigned_homeworks = get_assigned_homeworks(student_works, n, work_index) + assigned_homeworks.each do |h| + student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: pro_work.user_id, student_work_id: h.id) + student_works_evaluation_distributions.save + end + end + + else + student_works = homework_common.student_works.has_committed + student_works = student_works.shuffle + student_works.each_with_index do |work, index| + user = work.user + n = homework_detail_manual.evaluation_num + n = (n < student_works.size && n != -1) ? n : student_works.size - 1 + assigned_homeworks = get_assigned_homeworks(student_works, n, index) + assigned_homeworks.each do |h| + student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: user.id, student_work_id: h.id) + student_works_evaluation_distributions.save + end + end + end + end +end diff --git a/app/jobs/homework_evaluation_start_notify_job.rb b/app/jobs/homework_evaluation_start_notify_job.rb new file mode 100644 index 000000000..709c37b32 --- /dev/null +++ b/app/jobs/homework_evaluation_start_notify_job.rb @@ -0,0 +1,30 @@ +class HomeworkEvaluationStartNotifyJob < ApplicationJob + queue_as :notify + + def perform(homework_common_id, content) + homework = HomeworkCommon.find_by(id: homework_common_id) + return if homework.blank? + course = homework.course + members = content.blank? ? course.course_members : course.teachers + tiding_type = content.blank? ? "HomeworkCommon" : "System" + + attrs = %i[ + user_id trigger_user_id container_id container_type parent_container_id parent_container_type + belong_container_id belong_container_type viewed tiding_type extra created_at updated_at + ] + + same_attrs = { + trigger_user_id: homework.user_id, container_id: homework.id, container_type: 'HomeworkCommon', + parent_container_id: homework.id, parent_container_type: 'AnonymousComment', + belong_container_id: homework.course_id, belong_container_type: 'Course', + viewed: 0, tiding_type: tiding_type, extra: content + } + Tiding.bulk_insert(*attrs) do |worker| + member_ids = members.pluck(:user_id).uniq + + member_ids.each do |user_id| + worker.add same_attrs.merge(user_id: user_id) + end + end + end +end diff --git a/app/jobs/homework_publish_update_work_status_job.rb b/app/jobs/homework_publish_update_work_status_job.rb index 0060ab270..fe03a3ac5 100644 --- a/app/jobs/homework_publish_update_work_status_job.rb +++ b/app/jobs/homework_publish_update_work_status_job.rb @@ -1,6 +1,6 @@ class HomeworkPublishUpdateWorkStatusJob < ApplicationJob # 作业发布时更新学生(发布前已开启过实训)的作业状态和成绩 - queue_as :default + queue_as :score def perform(group_ids, homework_id) # Do something later diff --git a/config/sidekiq.yml b/config/sidekiq.yml index a2b3fc0be..5bd9dad23 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -3,4 +3,6 @@ :logfile: log/sidekiq.log :queues: - [default, 3] + - [score, 4] + - [evaluation_comment, 5] - [notify, 100] \ No newline at end of file diff --git a/lib/tasks/homework_evaluation.rake b/lib/tasks/homework_evaluation.rake index cb7b51fae..d1fad8f14 100644 --- a/lib/tasks/homework_evaluation.rake +++ b/lib/tasks/homework_evaluation.rake @@ -23,59 +23,11 @@ namespace :homework_evaluation do else student_works = homework_common.student_works.has_committed end - if student_works.present? && student_works.length >= 2 - if homework_common.homework_type == "group" - student_work_projects = homework_common.student_works.where("work_status != 0").shuffle - student_work_projects.each_with_index do |pro_work, pro_index| - n = homework_detail_manual.evaluation_num - n = (n < student_works.size && n != -1) ? n : student_works.size - 1 - work_index = -1 - student_works.each_with_index do |stu_work, stu_index| - if stu_work.group_id.to_i == pro_work.group_id.to_i - work_index = stu_index - end - end - assigned_homeworks = get_assigned_homeworks(student_works, n, work_index) - assigned_homeworks.each do |h| - student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: pro_work.user_id, student_work_id: h.id) - student_works_evaluation_distributions.save - end - #更新CourseHomeworkStatistics中该学生的待匿评数 - # course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(homework_common.course_id, pro_work.user_id) - # course_statistics.update_attribute('un_evaluation_work_num', course_statistics.un_evaluation_work_num + n) if course_statistics - end - else - student_works = student_works.shuffle - student_works.each_with_index do |work, index| - user = work.user - n = homework_detail_manual.evaluation_num - n = (n < student_works.size && n != -1) ? n : student_works.size - 1 - assigned_homeworks = get_assigned_homeworks(student_works, n, index) - assigned_homeworks.each do |h| - student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: user.id, student_work_id: h.id) - student_works_evaluation_distributions.save - end + if student_works.size >= 2 + HomeworkEvaluationCommentAssginJob.perform_later(homework_common.id) - #更新CourseHomeworkStatistics中该学生的待匿评数 - # course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(homework_common.course_id, user.id) - # course_statistics.update_attribute('un_evaluation_work_num', course_statistics.un_evaluation_work_num + n) if course_statistics - end - end homework_detail_manual.update_column('comment_status', 3) - # 匿评开启消息邮件通知,# 所有人 - str = "" - homework_common.course.course_members.pluck(:user_id).uniq.each do |user_id| - str += "," if str != "" - str += "('#{user_id}', '#{homework_common.user_id}', '#{homework_common.id}','HomeworkCommon','#{homework_common.id}', - 'AnonymousComment',#{homework_common.course_id},'Course',0,'HomeworkCommon', - '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - if str != "" - sql = "insert into tidings (user_id,trigger_user_id,container_id, container_type, parent_container_id, - parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + str - ActiveRecord::Base.connection.execute sql - end else #作业数小于2,启动失败, 只给老师和助教发 extra = "作品数量低于两个,无法开启匿评" @@ -83,20 +35,8 @@ namespace :homework_evaluation do else extra = "存在尚未截止的分班,无法开启匿评" end + HomeworkEvaluationStartNotifyJob.perform_later(homework_common.id, extra) if extra.present? - str = '' - homework_common.course.teachers.each do |mem| - str += "," if str != "" - str += "('#{mem.user.id}', '#{homework_common.user_id}', '#{homework_common.id}','HomeworkCommon','#{homework_common.id}', - 'AnonymousCommentFail',#{homework_common.course_id},'Course',0,'System','#{extra}', - '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - if str != "" - sql = "insert into tidings (user_id,trigger_user_id,container_id, container_type,parent_container_id, - parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, extra, created_at, - updated_at) values" + str - ActiveRecord::Base.connection.execute sql - end homework_detail_manual.update_attributes(:evaluation_start => nil, :evaluation_end => nil, :absence_penalty => 0, :evaluation_num => 0, :appeal_time => nil, :appeal_penalty => 0) homework_common.update_attributes(:anonymous_comment => 0, :anonymous_appeal => 0) @@ -114,63 +54,15 @@ namespace :homework_evaluation do homework_detail_manuals.each do |homework_detail_manual| homework_common = homework_detail_manual.homework_common if homework_common.anonymous_comment #开启匿评状态才可关闭匿评 - #计算缺评扣分 参与匿评 - work_ids = "(" + homework_common.student_works.has_committed.map(&:id).join(",") + ")" - - homework_common.student_works.where("work_status != 0").each do |student_work| - absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - - student_work.user.student_works_scores.where("student_work_id IN #{work_ids} and reviewer_role = 3").count - - student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * homework_detail_manual.absence_penalty : 0 - student_work.save - - #更新CourseHomeworkStatistics中该学生的待匿评数和缺评数 - # absence_penalty_count = absence_penalty_count > 0 ? absence_penalty_count : 0 - # course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(homework_common.course_id, student_work.user_id) - # course_statistics.update_attribute('un_evaluation_work_num', (course_statistics.un_evaluation_work_num - absence_penalty_count) < 0 ? 0 : - # (course_statistics.un_evaluation_work_num - absence_penalty_count)) if course_statistics - # course_statistics.update_attribute('absence_evaluation_work_num', course_statistics.absence_evaluation_work_num + absence_penalty_count) if course_statistics - end - - # 未参与匿评 - if homework_common.homework_detail_manual.no_anon_penalty == 0 - all_dis_eva = StudentWorksEvaluationDistribution.where("student_work_id IN #{work_ids}") - has_sw_count = all_dis_eva.select("distinct user_id").count - anon_count = all_dis_eva.count / has_sw_count - homework_common.student_works.where("work_status != 0").each do |student_work| - if student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count == 0 - student_work.absence_penalty = homework_detail_manual.absence_penalty * anon_count - student_work.save - end - end - end - if homework_common.anonymous_appeal homework_detail_manual.update_column('comment_status', 4) - # 申诉开启 - eva_distribution = StudentWorksEvaluationDistribution.where(:student_work_id => homework_common.student_works.pluck(:id)) - str = "" - eva_distribution.pluck(:user_id).uniq.each do |user_id| - str += "," if str != "" - str += "(#{user_id}, #{homework_common.user_id}, #{homework_common.id}, 'HomeworkCommon', #{homework_common.id}, - 'AnonymousAppeal', #{homework_common.course_id}, 'Course', 0, 'HomeworkCommon', - '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - if str != "" - sql = "insert into tidings (user_id,trigger_user_id,container_id, container_type, parent_container_id, - parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + str - ActiveRecord::Base.connection.execute sql - end + # 申诉开启发送消息 + HomeworkAnonymousAppealStartNotifyJob.perform_later(homework_common.id) else homework_detail_manual.update_column('comment_status', 5) end - # 匿评关闭消息通知 给所有人发 - # course = homework_common.course - # course.members.each do |m| - # homework_common.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 3) - # end - # 邮件通知 - # Mailer.send_mail_anonymous_comment_close(homework_common).deliver + + HomeworkAbsencePenaltyCalculationJob.perform_later(homework_common.id) end end end diff --git a/lib/tasks/homework_publishtime.rake b/lib/tasks/homework_publishtime.rake index 0e45b0224..cbfd4413a 100644 --- a/lib/tasks/homework_publishtime.rake +++ b/lib/tasks/homework_publishtime.rake @@ -21,34 +21,29 @@ namespace :homework_publishtime do homework_commons.each do |homework| homework_detail_manual = homework.homework_detail_manual homework_detail_manual.update_column('comment_status', 1) - course = homework.course - students = course.students - if !course.nil? && !students.empty? + # 统一设置的作业在这发消息,非统一设置的只给有全部分班权限的老师发 + if homework.unified_setting + HomeworkPublishUpdateWorkStatusJob.perform_later(nil, homework.id) + HomeworkCommonPushNotifyJob.perform_later(homework.id, nil) + else + course = homework.course + teachers = course.teachers.where.not(id: course.teacher_course_groups.select(:course_member_id)) + tid_str = "" - course.teachers.find_each do |member| + teachers.find_each do |member| tid_str += "," if tid_str != "" tid_str += "(#{member.user_id}, #{homework.user_id}, #{homework.id}, 'HomeworkCommon', #{homework.id}, 'HomeworkPublish', #{course.id}, 'Course', 0, 'HomeworkCommon', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" end - if homework.unified_setting - students.each do |student| - tid_str += "," if tid_str != "" - tid_str += "(#{student.user_id}, #{homework.user_id}, #{homework.id}, 'HomeworkCommon', #{homework.id}, - 'HomeworkPublish', #{course.id}, 'Course', 0, 'HomeworkCommon', - '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - HomeworkPublishUpdateWorkStatusJob.perform_now(nil, homework.id) - end if tid_str != "" tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str ActiveRecord::Base.connection.execute tid_sql end - end - + end if homework.course_acts.size == 0 homework.course_acts << CourseActivity.new(:user_id => homework.user_id,:course_id => homework.course_id) end @@ -59,27 +54,8 @@ namespace :homework_publishtime do homework_group_settings.each do |homework_group| homework = homework_group.homework_common if homework.present? - course = homework.course - homework_detail_manual = homework.homework_detail_manual - homework_detail_manual.update_column('comment_status', 1) if homework_detail_manual.comment_status == 0 - - tid_str = "" - members = course.students.where(:course_group_id => homework_group.course_group_id) - members.find_each do |member| - tid_str += "," if tid_str != "" - tid_str += "(#{member.user_id}, #{homework.user_id}, #{homework.id}, 'HomeworkCommon', #{homework.id}, 'HomeworkPublish', - #{course.id}, 'Course', 0, 'HomeworkCommon', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', - '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - if tid_str != "" - tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, - parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, - updated_at) values" + tid_str - ActiveRecord::Base.connection.execute tid_sql - end - HomeworkPublishUpdateWorkStatusJob.perform_now([homework_group.id], homework.id) - + HomeworkCommonPushNotifyJob.perform_later(homework.id, [homework_group.id]) end end Rails.logger.info("log--------------------------------homework_publish end") @@ -98,11 +74,10 @@ namespace :homework_publishtime do student_works = homework.student_works.where("work_status != 0") # none_student_works = homework.student_works.where("work_status = 0") else - setting = homework.homework_group_settings.where(:end_time => homework.end_time) + setting = homework.homework_group_settings.where(end_time: homework.end_time) unless setting.blank? - users = homework.course.students.where(:course_group_id => setting.map(&:course_group_id)) - user_ids = users.blank? ? "(-1)" : "(" + users.map(&:user_id).join(",") + ")" - student_works = homework.student_works.where("work_status != 0 and user_id in #{user_ids}") + users = homework.course.students.where(course_group_id: setting.pluck(:course_group_id)) + student_works = homework.student_works.where("work_status != 0").where(user_id: users.pluck(:user_id)) # none_student_works = homework.student_works.where("work_status = 0 and user_id in #{user_ids}") end end @@ -172,8 +147,7 @@ namespace :homework_publishtime do # homework_challenge_settings = homework.homework_challenge_settings users = homework.course.students.where(:course_group_id => homework_setting.course_group_id) - user_ids = users.blank? ? "(-1)" : "(" + users.map(&:user_id).join(",") + ")" - student_works = homework.student_works.where("work_status != 0 and user_id in #{user_ids}") + student_works = homework.student_works.where("work_status != 0").where(user_id: users.pluck(:user_id)) student_works.joins(:myshixun).where("myshixuns.status != 1").update_all(late_penalty: homework.late_penalty) if student_works.present? else # HomeworksService.new.update_student_eff_score homework # 分班设置的不需要另外算效率分 diff --git a/spec/jobs/homework_absence_penalty_calculation_job_spec.rb b/spec/jobs/homework_absence_penalty_calculation_job_spec.rb new file mode 100644 index 000000000..b347086ce --- /dev/null +++ b/spec/jobs/homework_absence_penalty_calculation_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe HomeworkAbsencePenaltyCalculationJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/jobs/homework_anonymous_appeal_start_notify_job_spec.rb b/spec/jobs/homework_anonymous_appeal_start_notify_job_spec.rb new file mode 100644 index 000000000..bd5db1e69 --- /dev/null +++ b/spec/jobs/homework_anonymous_appeal_start_notify_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe HomeworkAnonymousAppealStartNotifyJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/jobs/homework_evaluation_comment_assgin_job_spec.rb b/spec/jobs/homework_evaluation_comment_assgin_job_spec.rb new file mode 100644 index 000000000..7a31a825f --- /dev/null +++ b/spec/jobs/homework_evaluation_comment_assgin_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe HomeworkEvaluationCommentAssginJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/jobs/homework_evaluation_start_notify_job_spec.rb b/spec/jobs/homework_evaluation_start_notify_job_spec.rb new file mode 100644 index 000000000..b347ea1f5 --- /dev/null +++ b/spec/jobs/homework_evaluation_start_notify_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe HomeworkEvaluationStartNotifyJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end From 118cf21fdecd9106aaa3280c83ceb870f697fc1c Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 27 Jun 2019 14:41:36 +0800 Subject: [PATCH 0304/1015] =?UTF-8?q?=E9=80=89=E9=A2=98=E6=B2=A1=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E7=8F=AD=E7=BA=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/graduation_topics_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index 521aaffc6..c611069a8 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -193,8 +193,8 @@ class GraduationTopicsController < ApplicationController def student_select_topic user_unaccept_topics = @course.student_graduation_topics.where(user_id: current_user.id, status: [0, 1]) if user_unaccept_topics.size == 0 - member_id = @course.course_members.find_by_user_id(current_user.id) - StudentGraduationTopic.create(course_id: @course.id, user_id: current_user.id, course_member_id: member_id, + member = @course.course_members.find_by_user_id(current_user.id) + StudentGraduationTopic.create(course_id: @course.id, user_id: current_user.id, course_member_id: member.try(:id), graduation_topic_id: @graduation_topic.id) @graduation_topic.update_attribute(:status, 1) normal_status("选题成功") From b6216e29972241f3a5d9adaa748328b0abfe271f Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 27 Jun 2019 14:46:07 +0800 Subject: [PATCH 0305/1015] =?UTF-8?q?=E4=BD=9C=E5=93=81=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E5=88=86=E6=95=B0=E6=9F=A5=E7=9C=8B=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 7 ++-- .../homework_commons/works_list.json.jbuilder | 36 +++++++++---------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 4abada488..59f745fb0 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -121,23 +121,26 @@ class HomeworkCommonsController < ApplicationController @work = @homework.user_work(current_user.id) # 学生已提交作品且补交(提交)已截止、作品公开、非匿评阶段 - if @work.work_status > 0 && @homework.work_public && + if @work&.work_status.to_i > 0 && @homework.work_public && ((!@homework.anonymous_comment && @homework.end_or_late) || @homework_detail_manual.comment_status > 4) @student_works = student_works.where("user_id != #{@work.id}") # 匿评、申诉阶段只能看到分配给自己的匿评作品 - elsif @work.work_status > 0 && @homework.anonymous_comment && @homework_detail_manual.comment_status > 2 + elsif @work&.work_status.to_i > 0 && @homework.anonymous_comment && @homework_detail_manual.comment_status > 2 @is_evaluation = true @student_works = student_works.joins(:student_works_evaluation_distributions).where( "student_works_evaluation_distributions.user_id = #{@current_user.id}") else @student_works = [] end + @score_open = @homework.score_open && @work&.work_status.to_i > 0 elsif @user_course_identity < Course::STUDENT @student_works = @homework.teacher_works(@member) @all_member_count = @student_works.size + @score_open = true elsif @user_course_identity > Course::STUDENT && @homework.work_public @student_works = student_works + @score_open = false else @student_works = [] end diff --git a/app/views/homework_commons/works_list.json.jbuilder b/app/views/homework_commons/works_list.json.jbuilder index 716b12190..60441909b 100644 --- a/app/views/homework_commons/works_list.json.jbuilder +++ b/app/views/homework_commons/works_list.json.jbuilder @@ -33,19 +33,19 @@ elsif @user_course_identity == Course::STUDENT json.late_penalty @work.late_penalty if @homework.allow_late json.cost_time @work.myshixun.try(:total_cost_time) - json.work_score work_score_format(@work.work_score, true, @homework.score_open) - json.final_score work_score_format(@work.final_score, true, @homework.score_open) - json.efficiency work_score_format(@work.efficiency, true, @homework.score_open) - json.eff_score work_score_format(@work.eff_score, true, @homework.score_open) + json.work_score work_score_format(@work.work_score, true, @score_open) + json.final_score work_score_format(@work.final_score, true, @score_open) + json.efficiency work_score_format(@work.efficiency, true, @score_open) + json.eff_score work_score_format(@work.eff_score, true, @score_open) json.complete_count @work.myshixun.try(:passed_count) else json.(@work, :id, :work_status, :update_time, :ultimate_score) - json.work_score work_score_format(@work.work_score, true, @homework.score_open) - json.final_score work_score_format(@work.final_score, true, @homework.score_open) - json.teacher_score work_score_format(@work.teacher_score, true, @homework.score_open) - json.student_score work_score_format(@work.student_score, true, @homework.score_open) - json.teaching_asistant_score work_score_format(@work.teaching_asistant_score, true, @homework.score_open) + json.work_score work_score_format(@work.work_score, true, @score_open) + json.final_score work_score_format(@work.final_score, true, @score_open) + json.teacher_score work_score_format(@work.teacher_score, true, @score_open) + json.student_score work_score_format(@work.student_score, true, @score_open) + json.teaching_asistant_score work_score_format(@work.teaching_asistant_score, true, @score_open) json.ta_comment_count @work.ta_comment_count @@ -84,10 +84,10 @@ if @homework.homework_type == "practice" json.(work, :id, :work_status, :update_time, :ultimate_score) json.late_penalty work.late_penalty if @homework.allow_late - json.work_score work_score_format(work.work_score, @current_user == work.user, @homework.score_open) - json.final_score work_score_format(work.final_score, @current_user == work.user, @homework.score_open) - json.efficiency work_score_format(work.efficiency, @current_user == work.user, @homework.score_open) - json.eff_score work_score_format(work.eff_score, @current_user == work.user, @homework.score_open) + json.work_score work_score_format(work.work_score, @current_user == work.user, @score_open) + json.final_score work_score_format(work.final_score, @current_user == work.user, @score_open) + json.efficiency work_score_format(work.efficiency, @current_user == work.user, @score_open) + json.eff_score work_score_format(work.eff_score, @current_user == work.user, @score_open) json.cost_time work.myshixun.try(:total_cost_time) json.complete_count work.myshixun.try(:passed_count) @@ -117,11 +117,11 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal" :teaching_asistant_score, :ultimate_score) json.late_penalty work.late_penalty if @homework.allow_late - json.work_score work_score_format(work.work_score, @current_user == work.user, @homework.score_open) - json.final_score work_score_format(work.final_score, @current_user == work.user, @homework.score_open) - json.teacher_score work_score_format(work.teacher_score, @current_user == work.user, @homework.score_open) - json.student_score work_score_format(work.student_score, @current_user == work.user, @homework.score_open) - json.teaching_asistant_score work_score_format(work.teaching_asistant_score, @current_user == work.user, @homework.score_open) + json.work_score work_score_format(work.work_score, @current_user == work.user, @score_open) + json.final_score work_score_format(work.final_score, @current_user == work.user, @score_open) + json.teacher_score work_score_format(work.teacher_score, @current_user == work.user, @score_open) + json.student_score work_score_format(work.student_score, @current_user == work.user, @score_open) + json.teaching_asistant_score work_score_format(work.teaching_asistant_score, @current_user == work.user, @score_open) # 助教评分次数 json.ta_comment_count work.ta_comment_count From c68bbfc937aa668e0f9ec524f4bdfceaa2eab422 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 27 Jun 2019 14:49:48 +0800 Subject: [PATCH 0306/1015] =?UTF-8?q?=E4=BD=9C=E5=93=81=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 59f745fb0..83bfd29fc 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -123,7 +123,7 @@ class HomeworkCommonsController < ApplicationController # 学生已提交作品且补交(提交)已截止、作品公开、非匿评阶段 if @work&.work_status.to_i > 0 && @homework.work_public && ((!@homework.anonymous_comment && @homework.end_or_late) || @homework_detail_manual.comment_status > 4) - @student_works = student_works.where("user_id != #{@work.id}") + @student_works = student_works.where("user_id != #{@work.user_id}") # 匿评、申诉阶段只能看到分配给自己的匿评作品 elsif @work&.work_status.to_i > 0 && @homework.anonymous_comment && @homework_detail_manual.comment_status > 2 From 94daf8d429922fae5c761eaf86e1b431e556497e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 27 Jun 2019 14:56:28 +0800 Subject: [PATCH 0307/1015] =?UTF-8?q?=E8=AF=84=E8=AE=BA=E9=9A=90=E8=97=8F?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=88=B0=E6=96=B0=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/discusses_controller.rb | 15 ++++++++++++--- app/models/discuss.rb | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/controllers/discusses_controller.rb b/app/controllers/discusses_controller.rb index 6e9c1427e..abedca8ba 100644 --- a/app/controllers/discusses_controller.rb +++ b/app/controllers/discusses_controller.rb @@ -7,9 +7,18 @@ class DiscussesController < ApplicationController page = params[:page].to_i offset = page * LIMIT # 总数,分页使用 - @disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count - @discusses = Discuss.limit(LIMIT).where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil). - includes(:user, :praise_tread).offset(offset) + if current_user.admin? + @disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count + @discusses = Discuss.limit(LIMIT).where(:dis_id => dis_id, :dis_type => dis_type, + :root_id => nil).includes(:user, :praise_tread).offset(offset) + else + disscusses = Discuss.where("dis_id = :dis_id and dis_type = :dis_type and root_id is null and + (hidden = :hidden or user_id = :user_id)", + {dis_id: dis_id, dis_type: dis_type, hidden: false, user_id: current_user.id}) + @disscuss_count = disscusses.count + @discusses = disscusses.limit(LIMIT).includes(:user, :praise_tread).offset(offset) + end + @current_user = current_user end diff --git a/app/models/discuss.rb b/app/models/discuss.rb index 602813e66..c1b08718c 100644 --- a/app/models/discuss.rb +++ b/app/models/discuss.rb @@ -36,7 +36,7 @@ class Discuss < ApplicationRecord def contents(shixun, user) return content unless hidden? - shixun.has_manager?(user) ? content : '违规评论已被屏蔽!' + shixun.has_manager?(user) ? content : '' end private From cea5187439158c5452463cc840e93d3e17505fad Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 27 Jun 2019 14:59:19 +0800 Subject: [PATCH 0308/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E6=94=B9=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/discusses_controller.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/controllers/discusses_controller.rb b/app/controllers/discusses_controller.rb index abedca8ba..93cf90780 100644 --- a/app/controllers/discusses_controller.rb +++ b/app/controllers/discusses_controller.rb @@ -32,8 +32,10 @@ class DiscussesController < ApplicationController def create begin - @discuss = Discuss.create!(:dis_id => params[:container_id], :dis_type => params[:container_type], :content => params[:content].gsub(" \;", "").strip, - :user_id => current_user.id, :praise_count => 0, :position => params[:position], :challenge_id => params[:challenge_id]) + @discuss = Discuss.create!(:dis_id => params[:container_id], :dis_type => params[:container_type], + :content => params[:content].gsub(" \;", "").strip, :user_id => current_user.id, + :praise_count => 0, :position => params[:position], :challenge_id => params[:challenge_id], + :hidden => current_user.admin?) rescue Exception => e uid_logger_error("create discuss failed : #{e.message}") raise Educoder::TipException.new("评论异常") From 48b1d7ca159f58de7e24fe5afd511bd0b1654439 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 27 Jun 2019 14:59:56 +0800 Subject: [PATCH 0309/1015] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/homework_common.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index d55973ed8..c0882ec6f 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -169,12 +169,8 @@ class HomeworkCommon < ApplicationRecord #删除时更新题库中的引用数 def update_homework_bank_quotes - old_banks = self.homework_bank - unless old_banks.blank? - old_banks.each do |bank| - bank.update_attributes(quotes: (bank.quotes - 1) > 0 ? (bank.quotes - 1) : 0, homework_common_id: nil) - end - end + old_bank = self.homework_bank + old_bank.update_attributes(quotes: (old_bank.quotes - 1) > 0 ? (old_bank.quotes - 1) : 0, homework_common_id: nil) end # 查重是否有新结果 From f61490ab738d9499e50890524537f99a2ae6ab7b Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 27 Jun 2019 15:03:34 +0800 Subject: [PATCH 0310/1015] =?UTF-8?q?=E8=AF=84=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/discusses_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/discusses_controller.rb b/app/controllers/discusses_controller.rb index 93cf90780..1d3b524f4 100644 --- a/app/controllers/discusses_controller.rb +++ b/app/controllers/discusses_controller.rb @@ -9,12 +9,12 @@ class DiscussesController < ApplicationController # 总数,分页使用 if current_user.admin? @disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count - @discusses = Discuss.limit(LIMIT).where(:dis_id => dis_id, :dis_type => dis_type, + @discusses = Discuss.limit(LIMIT).where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).includes(:user, :praise_tread).offset(offset) else disscusses = Discuss.where("dis_id = :dis_id and dis_type = :dis_type and root_id is null and (hidden = :hidden or user_id = :user_id)", - {dis_id: dis_id, dis_type: dis_type, hidden: false, user_id: current_user.id}) + {dis_id: @container.id, dis_type: @container.class.to_s, hidden: false, user_id: current_user.id}) @disscuss_count = disscusses.count @discusses = disscusses.limit(LIMIT).includes(:user, :praise_tread).offset(offset) end @@ -35,7 +35,7 @@ class DiscussesController < ApplicationController @discuss = Discuss.create!(:dis_id => params[:container_id], :dis_type => params[:container_type], :content => params[:content].gsub(" \;", "").strip, :user_id => current_user.id, :praise_count => 0, :position => params[:position], :challenge_id => params[:challenge_id], - :hidden => current_user.admin?) + :hidden => !current_user.admin?) # 管理员回复的能够显示 rescue Exception => e uid_logger_error("create discuss failed : #{e.message}") raise Educoder::TipException.new("评论异常") From 39b87564feb04ee5f7f9d6e2f78f5814043d8ce0 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 27 Jun 2019 15:41:14 +0800 Subject: [PATCH 0311/1015] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../graduation_works_controller.rb | 6 +-- app/jobs/graduation_task_cross_comment_job.rb | 39 ++++++++++++++ .../graduation_task_publish_notify_job.rb | 4 +- ...ework_anonymous_appeal_start_notify_job.rb | 1 + lib/tasks/graduation_task.rake | 54 ++----------------- lib/tasks/homework_publishtime.rake | 5 +- .../graduation_task_cross_comment_job_spec.rb | 5 ++ ...graduation_task_publish_notify_job_spec.rb | 5 ++ 8 files changed, 62 insertions(+), 57 deletions(-) create mode 100644 app/jobs/graduation_task_cross_comment_job.rb create mode 100644 spec/jobs/graduation_task_cross_comment_job_spec.rb create mode 100644 spec/jobs/graduation_task_publish_notify_job_spec.rb diff --git a/app/controllers/graduation_works_controller.rb b/app/controllers/graduation_works_controller.rb index 9117112d3..09b9146e8 100644 --- a/app/controllers/graduation_works_controller.rb +++ b/app/controllers/graduation_works_controller.rb @@ -432,11 +432,11 @@ class GraduationWorksController < ApplicationController # 交叉评阅分配老师 def assign_teacher tip_exception(-1, "user_id不能为空") if params[:user_id].nil? - @work_assign_teacher = @work.graduation_work_comment_assignations.first + @work_assign_teacher = @work.graduation_work_comment_assignations.find_by(user_id: params[:user_id]) - if @work_assign_teacher + if @work_assign_teacher.present? # graduation_group_id: 已经是答辩组的需要 将答辩组清空 - @work_assign_teacher.update_attributes(user_id: params[:user_id], graduation_group_id: 0) + @work_assign_teacher.update_attributes(graduation_group_id: 0) else @work.graduation_work_comment_assignations << GraduationWorkCommentAssignation.new(graduation_task_id: @task.id, user_id: params[:user_id], diff --git a/app/jobs/graduation_task_cross_comment_job.rb b/app/jobs/graduation_task_cross_comment_job.rb new file mode 100644 index 000000000..64973a3e9 --- /dev/null +++ b/app/jobs/graduation_task_cross_comment_job.rb @@ -0,0 +1,39 @@ +# 毕设任务的交叉评阅分配 +class GraduationTaskCrossCommentJob < ApplicationJob + queue_as :evaluation_comment + + def perform(graduation_task_id) + task = GraduationTask.find_by(id: graduation_task_id) + return if task.blank? + + course = task.course + task.graduation_task_group_assignations.each do |assignation| + graduation_group = assignation.graduation_group + assign_group = assignation.assign_group + if graduation_group.present? && assign_group.present? + course_group_ids = course.teacher_course_groups.where(course_member_id: graduation_group.course_members.pluck(:id)).pluck(:course_group_id) + graduation_works = task.graduation_works.where(user_id: course.course_members.where(:course_group_id => course_group_ids).map(&:user_id), + work_status: [1, 2]) + if assign_group.course_members.count <= task.comment_num + graduation_works.each do |work| + assign_group.course_members.each do |member| + work.graduation_work_comment_assignations << GraduationWorkCommentAssignation.new( + graduation_group_id: assign_group.id, user_id: member.user_id, graduation_task_id: task.id) + end + end + else + member_user_ids = assign_group.course_members.pluck(:user_id) + count = 0 + graduation_works.each do |work| + for i in 1 .. task.comment_num + assign_user_id = member_user_ids[count % member_user_ids.size] + work.graduation_work_comment_assignations << GraduationWorkCommentAssignation.new( + graduation_group_id: assign_group.id, user_id: assign_user_id, graduation_task_id: task.id) + count += 1 + end + end + end + end + end + end +end diff --git a/app/jobs/graduation_task_publish_notify_job.rb b/app/jobs/graduation_task_publish_notify_job.rb index 3489aa711..92346ab27 100644 --- a/app/jobs/graduation_task_publish_notify_job.rb +++ b/app/jobs/graduation_task_publish_notify_job.rb @@ -18,8 +18,8 @@ class GraduationTaskPublishNotifyJob < ApplicationJob viewed: 0, tiding_type: 'GraduationTask' } Tiding.bulk_insert(*attrs) do |worker| - task.course.students.find_each do |student| - worker.add same_attrs.merge(user_id: student.user_id) + task.course.course_members.pluck(:user_id).uniq.find_each do |user_id| + worker.add same_attrs.merge(user_id: user_id) end end end diff --git a/app/jobs/homework_anonymous_appeal_start_notify_job.rb b/app/jobs/homework_anonymous_appeal_start_notify_job.rb index 97c369846..1c3098690 100644 --- a/app/jobs/homework_anonymous_appeal_start_notify_job.rb +++ b/app/jobs/homework_anonymous_appeal_start_notify_job.rb @@ -1,3 +1,4 @@ +# 匿评申诉开启时给分配了匿评的学生发消息 class HomeworkAnonymousAppealStartNotifyJob < ApplicationJob queue_as :notify diff --git a/lib/tasks/graduation_task.rake b/lib/tasks/graduation_task.rake index aad84491f..0d4dff237 100644 --- a/lib/tasks/graduation_task.rake +++ b/lib/tasks/graduation_task.rake @@ -5,27 +5,9 @@ namespace :graduation_task do tasks = GraduationTask.where("publish_time is not null and publish_time <= '#{Time.now}' and status = 0") tasks.each do |task| task.update_attributes(status: 1) - course = task.course - members = course.course_members - if !course.nil? && !members.empty? - tid_str = "" - members.find_each do |member| - tid_str += "," if tid_str != "" - tid_str += "(#{member.user_id}, #{task.user_id}, #{task.id}, 'GraduationTask', #{task.id}, 'TaskPublish', - #{course.id}, 'Course', 0, 'GraduationTask', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', - '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - if tid_str != "" - tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, - parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, - updated_at) values" + tid_str - ActiveRecord::Base.connection.execute tid_sql - end - end + GraduationTaskPublishNotifyJob.perform_later(task.id) - if task.course_acts.size == 0 - task.course_acts << CourseActivity.new(user_id: task.user_id, course_id: task.course_id) - end + task.course_acts << CourseActivity.new(user_id: task.user_id, course_id: task.course_id) if task.course_acts.exists? end end @@ -62,37 +44,11 @@ namespace :graduation_task do tasks = GraduationTask.where("cross_comment = 1 and comment_time is not null and comment_time <= '#{Time.now}' and status = 2") tasks.each do |task| if task.comment_status == 4 - course = task.course - task.graduation_task_group_assignations.each do |assignation| - graduation_group = assignation.graduation_group - assign_group = assignation.assign_group - if graduation_group.present? && assign_group.present? - course_group_ids = course.teacher_course_groups.where(course_member_id: graduation_group.course_members.pluck(:id)).pluck(:course_group_id) - graduation_works = task.graduation_works.where(user_id: course.course_members.where(:course_group_id => course_group_ids).map(&:user_id), - work_status: [1, 2]) - if assign_group.course_members.count <= task.comment_num - graduation_works.each do |work| - assign_group.course_members.each do |member| - work.graduation_work_comment_assignations << GraduationWorkCommentAssignation.new( - graduation_group_id: assign_group.id, user_id: member.user_id, graduation_task_id: task.id) - end - end - else - member_user_ids = assign_group.course_members.pluck(:user_id) - count = 0 - graduation_works.each do |work| - for i in 1 .. task.comment_num - assign_user_id = member_user_ids[count % member_user_ids.size] - work.graduation_work_comment_assignations << GraduationWorkCommentAssignation.new( - graduation_group_id: assign_group.id, user_id: assign_user_id, graduation_task_id: task.id) - count += 1 - end - end - end - end - end + GraduationTaskCrossCommentJob.perform_later(task.id) end task.update_attributes(status: 3) + + # 给老师发消息 tid_str = "" task.course.teachers.find_each do |member| tid_str += "," if tid_str != "" diff --git a/lib/tasks/homework_publishtime.rake b/lib/tasks/homework_publishtime.rake index cbfd4413a..4c27f0317 100644 --- a/lib/tasks/homework_publishtime.rake +++ b/lib/tasks/homework_publishtime.rake @@ -44,9 +44,8 @@ namespace :homework_publishtime do ActiveRecord::Base.connection.execute tid_sql end end - if homework.course_acts.size == 0 - homework.course_acts << CourseActivity.new(:user_id => homework.user_id,:course_id => homework.course_id) - end + + homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id) if homework.course_acts.exists? end # 分组设置发布时间的作业 diff --git a/spec/jobs/graduation_task_cross_comment_job_spec.rb b/spec/jobs/graduation_task_cross_comment_job_spec.rb new file mode 100644 index 000000000..d517d939b --- /dev/null +++ b/spec/jobs/graduation_task_cross_comment_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe GraduationTaskCrossCommentJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/jobs/graduation_task_publish_notify_job_spec.rb b/spec/jobs/graduation_task_publish_notify_job_spec.rb new file mode 100644 index 000000000..39f6046af --- /dev/null +++ b/spec/jobs/graduation_task_publish_notify_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe GraduationTaskPublishNotifyJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end From 67b6b735cd23a697ee0ff0aec7cecbcd77272aed Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 27 Jun 2019 15:58:34 +0800 Subject: [PATCH 0312/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E5=9B=9E=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/discuss.rb | 6 ++++++ app/views/discusses/_discuss.json.jbuilder | 2 +- app/views/discusses/index.json.jbuilder | 3 +-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/models/discuss.rb b/app/models/discuss.rb index c1b08718c..8d8dc0163 100644 --- a/app/models/discuss.rb +++ b/app/models/discuss.rb @@ -39,6 +39,12 @@ class Discuss < ApplicationRecord shixun.has_manager?(user) ? content : '' end + def child_discuss(user) + user.admin? ? + Discuss.where(parent_id: self.id).includes(:user).reorder(created_at: :asc) : + Discuss.where(parent_id: self.id, :hidden => false).includes(:user).reorder(created_at: :asc) + end + private def send_tiding diff --git a/app/views/discusses/_discuss.json.jbuilder b/app/views/discusses/_discuss.json.jbuilder index 1fcf150bc..da1ca5a6c 100644 --- a/app/views/discusses/_discuss.json.jbuilder +++ b/app/views/discusses/_discuss.json.jbuilder @@ -2,7 +2,7 @@ json.author do json.partial! 'users/user', user: discuss.user end json.id discuss.id -json.content discuss.contents(container, current_user) +json.content discuss.contents json.time time_from_now(discuss.created_at) json.position discuss.position json.shixun_id discuss.dis_id diff --git a/app/views/discusses/index.json.jbuilder b/app/views/discusses/index.json.jbuilder index 3d0ee9fc9..1b7a95eb3 100644 --- a/app/views/discusses/index.json.jbuilder +++ b/app/views/discusses/index.json.jbuilder @@ -2,8 +2,7 @@ json.disscuss_count @disscuss_count json.all @current_user.admin? json.comments @discusses do |discuss| json.partial! 'discusses/discuss', locals: { discuss: discuss, container: @container, current_user: @current_user } - child_discuss = Discuss.children(discuss.id) - json.children child_discuss do |c_d| + json.children discuss.child_discuss(current_user) do |c_d| json.partial! 'discusses/discuss', locals: { discuss: c_d, container: @container, current_user: @current_user } end end From 3286d175a2ccbe037df7a3f4305aa6af9ac99d74 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 27 Jun 2019 16:28:50 +0800 Subject: [PATCH 0313/1015] =?UTF-8?q?=E5=BC=80=E5=90=AF=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E7=9A=84=E4=B8=80=E4=BA=9B=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 29 +++++++++++++++------------ app/models/myshixun.rb | 8 +++----- app/services/git_service.rb | 5 +++++ 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 3b14eea84..a319dc58a 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -488,17 +488,19 @@ class ShixunsController < ApplicationController tip_show_exception(-3, "#{@shixun.opening_time.strftime('%Y-%m-%d %H:%M:%S')}") end current_myshixun = @shixun.current_myshixun(current_user.id) + + min_challenges = @shixun.challenges.pluck(:id , :st) + if current_myshixun + games = current_myshixun.games # 如果TPM和TPI的管卡数不相等或者关卡顺序错了,说明实训被极大的改动,需要重置 - if current_myshixun.games.count != @shixun.challenges_count || - current_myshixun.games.reorder(:challenge_id).pluck(:challenge_id) != @shixun.challenges.reorder(:id).pluck(:id) - uid_logger_error("7777777777777777#{current_myshixun.games.count}, #{@shixun.challenges_count}") + if games.size != min_challenges.size || games.map(&:challenge_id) != min_challenges.map{|challenge| challenge.first} # 这里页面弹框要收到 当前用户myshixun的identifier. tip_show_exception("/myshixuns/#{current_myshixun.try(:identifier)}/reset_my_game") end # 如果存在实训,则直接进入实训 - @current_task = current_myshixun.current_task + @current_task = current_myshixun.current_task(games) else # 如果未创建关卡一定不能开启实训,否则TPI没法找到当前的关卡 if @shixun.challenges_count == 0 @@ -506,10 +508,10 @@ class ShixunsController < ApplicationController end # 判断实训是否全为选择题 - is_choice_type = @shixun.is_choice_type? + 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) - Rails.logger.info("First comit########{commit}") + uid_logger("First comit########{commit}") tip_exception("开启实战前请先在版本库中提交代码") if commit.blank? commit_id = commit["id"] end @@ -528,13 +530,13 @@ class ShixunsController < ApplicationController # fork仓库 project_fork(myshixun, @repo_path, current_user.login) - #rep_url = Base64.urlsafe_encode64(repo_ip_url @repo_path ) - #uid_logger("start openGameInstance") - #uri = "#{cloud_bridge}/bridge/game/openGameInstance" - #logger.info("end openGameInstance") - #params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: myshixun.repo_name.split("/").last} - #uid_logger("openGameInstance params is #{params}") - # res = interface_post uri, params, 83, "实训云平台繁忙(繁忙等级:83)" + rep_url = Base64.urlsafe_encode64(repo_ip_url @repo_path ) + uid_logger("start openGameInstance") + uri = "#{cloud_bridge}/bridge/game/openGameInstance" + logger.info("end openGameInstance") + params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: myshixun.repo_name.split("/").last} + uid_logger("openGameInstance params is #{params}") + interface_post uri, params, 83, "实训云平台繁忙(繁忙等级:83)" end # 其它创建关卡等操作 challenges = @shixun.challenges @@ -565,6 +567,7 @@ class ShixunsController < ApplicationController end end end + # gameID 及实训ID # status: 0 , 1 申请过, 2,实训关卡路径未填, 3 实训标签未填, 4 实训未创建关卡 def publish diff --git a/app/models/myshixun.rb b/app/models/myshixun.rb index a1aca3253..d8f294a39 100644 --- a/app/models/myshixun.rb +++ b/app/models/myshixun.rb @@ -53,14 +53,12 @@ class Myshixun < ApplicationRecord end # 当前任务:一个实训中只可能一个未完成任务(status 0或1只会存在一条记录) - # status:0 可以测评的,正在测评的 + # status:0 可以测评的; 1 正在测评的; 2评测通过的; 3未开启的 # 如果都完成,则当前任务为最后一个任务 - def current_task - games = self.games + def current_task games current_game = games.select{|game| game.status == 1 || game.status == 0}.first if current_game.blank? - current_game = Game.find_by_sql("SELECT g.* FROM games g, challenges c where g.myshixun_id=#{self.id} - and g.challenge_id = c.id and g.status = 2 order by c.position desc").first + current_game = games.last end current_game end diff --git a/app/services/git_service.rb b/app/services/git_service.rb index 3298185bf..076f62920 100644 --- a/app/services/git_service.rb +++ b/app/services/git_service.rb @@ -33,7 +33,12 @@ class GitService res = https.request(req) body = res.body logger.info("--uri_exec: .....res is #{body}") + content = JSON.parse(body) + if content["code"] != 0 + raise("版本库异常") + logger.error("repository error: #{content['msg']}") + end #raise content["msg"] if content["code"] != 0 content["data"] From 86e8ab96973ba71dbd4792773e13e5324465e8f8 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 27 Jun 2019 16:33:22 +0800 Subject: [PATCH 0314/1015] =?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/polls_controller.rb | 7 ++-- app/helpers/student_works_helper.rb | 2 +- app/jobs/poll_publish_notify_job.rb | 16 +++++++-- lib/tasks/graduation_task.rake | 2 +- lib/tasks/homework_publishtime.rake | 4 +-- lib/tasks/poll_publish.rake | 52 +++++++---------------------- 6 files changed, 31 insertions(+), 52 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 119226c87..6fbba1c3d 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -263,7 +263,6 @@ class PollsController < ApplicationController if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则问卷不用分组,且问卷设定为统一设置,否则则分组设置 poll.poll_group_settings.destroy_all poll_unified = true - notify_student_ids = @course.students.pluck(:user_id) else poll_unified = false g_course.each do |i| @@ -282,13 +281,11 @@ class PollsController < ApplicationController new_poll_group.save end end - - notify_student_ids = @course.students.where(course_group_id: params[:group_ids]).pluck(:user_id) + group_ids = params[:group_ids] end else poll.poll_group_settings.destroy_all poll_unified = true - notify_student_ids = @course.students.pluck(:user_id) end if poll.end_time.blank? e_time = ex_end_time @@ -309,7 +306,7 @@ class PollsController < ApplicationController if poll.course_acts.size == 0 poll.course_acts << CourseActivity.new(:user_id => poll.user_id,:course_id => poll.course_id) end - PollPublishNotifyJob.perform_later(poll.id, notify_student_ids) + PollPublishNotifyJob.perform_later(poll.id, group_ids) end end normal_status(0, "问卷发布成功!") diff --git a/app/helpers/student_works_helper.rb b/app/helpers/student_works_helper.rb index 17cdd41a7..a7103b4bf 100644 --- a/app/helpers/student_works_helper.rb +++ b/app/helpers/student_works_helper.rb @@ -145,7 +145,7 @@ module StudentWorksHelper else user_name = message_user.real_name user_login = message_user.login - image_url = url_to_avatar(score.user) + image_url = url_to_avatar(message_user) end {user_name: user_name, user_login: user_login, user_image_url: image_url} end diff --git a/app/jobs/poll_publish_notify_job.rb b/app/jobs/poll_publish_notify_job.rb index bc31957e0..d7ed1ae02 100644 --- a/app/jobs/poll_publish_notify_job.rb +++ b/app/jobs/poll_publish_notify_job.rb @@ -2,10 +2,20 @@ class PollPublishNotifyJob < ApplicationJob queue_as :notify - def perform(poll_id, receiver_ids) + def perform(poll_id, group_ids) poll = Poll.find_by(id: poll_id) return if poll.blank? user = poll.user + course = poll.course + + if group_ids.present? + students = course.students.where(course_group_id: group_ids) + subquery = course.teacher_course_groups.where(course_group_id: group_ids).select(:course_member_id) + teachers = course.teachers.where(id: subquery) + else + students = course.students + teachers = course.teachers + end attrs = %i[ user_id trigger_user_id container_id container_type parent_container_id parent_container_type @@ -19,14 +29,14 @@ class PollPublishNotifyJob < ApplicationJob viewed: 0, tiding_type: 'Poll' } Tiding.bulk_insert(*attrs) do |worker| - teacher_ids = poll.course.teachers.pluck(:user_id) + teacher_ids = teachers.pluck(:user_id) unless poll.tidings.exists?(parent_container_type: 'PollPublish', user_id: teacher_ids) poll.course.teachers.find_each do |teacher| worker.add same_attrs.merge(user_id: teacher.user_id) end end - receiver_ids.each do |user_id| + students.pluck(:user_id).each do |user_id| worker.add same_attrs.merge(user_id: user_id) end end diff --git a/lib/tasks/graduation_task.rake b/lib/tasks/graduation_task.rake index 0d4dff237..58f7764d0 100644 --- a/lib/tasks/graduation_task.rake +++ b/lib/tasks/graduation_task.rake @@ -7,7 +7,7 @@ namespace :graduation_task do task.update_attributes(status: 1) GraduationTaskPublishNotifyJob.perform_later(task.id) - task.course_acts << CourseActivity.new(user_id: task.user_id, course_id: task.course_id) if task.course_acts.exists? + task.course_acts << CourseActivity.new(user_id: task.user_id, course_id: task.course_id) if !task.course_acts.exists? end end diff --git a/lib/tasks/homework_publishtime.rake b/lib/tasks/homework_publishtime.rake index 4c27f0317..7ee2a4a07 100644 --- a/lib/tasks/homework_publishtime.rake +++ b/lib/tasks/homework_publishtime.rake @@ -45,7 +45,7 @@ namespace :homework_publishtime do end end - homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id) if homework.course_acts.exists? + homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id) if !homework.course_acts.exists? end # 分组设置发布时间的作业 @@ -54,7 +54,7 @@ namespace :homework_publishtime do homework = homework_group.homework_common if homework.present? HomeworkPublishUpdateWorkStatusJob.perform_now([homework_group.id], homework.id) - HomeworkCommonPushNotifyJob.perform_later(homework.id, [homework_group.id]) + HomeworkCommonPushNotifyJob.perform_later(homework.id, [homework_group.course_group_id]) end end Rails.logger.info("log--------------------------------homework_publish end") diff --git a/lib/tasks/poll_publish.rake b/lib/tasks/poll_publish.rake index 6ced88908..8cec43565 100644 --- a/lib/tasks/poll_publish.rake +++ b/lib/tasks/poll_publish.rake @@ -9,39 +9,22 @@ namespace :poll_publish do polls = Poll.includes(:poll_users).where("publish_time is not null and polls_status = 1 and publish_time <=?",Time.now) polls.each do |poll| poll.update_attributes(:polls_status => 2) - course = poll.course - tid_str = "" - course.teachers.find_each do |member| - tid_str += "," if tid_str != "" - tid_str += "(#{member.user_id}, #{poll.user_id}, #{poll.id}, 'Poll', #{poll.id}, 'PollPublish', #{course.id}, 'Course', 0, 'Poll', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end if poll.unified_setting - course.students.find_each do |student| + PollPublishNotifyJob.perform_later(poll.id, nil) + else + course = poll.course + teachers = course.teachers.where.not(id: course.teacher_course_groups.select(:course_member_id)) + tid_str = "" + teachers.find_each do |member| tid_str += "," if tid_str != "" - tid_str += "(#{student.user_id}, #{poll.user_id}, #{poll.id}, 'Poll', #{poll.id}, 'PollPublish', #{course.id}, 'Course', 0, 'Poll', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - end - if tid_str != "" - tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str - ActiveRecord::Base.connection.execute tid_sql - end - - if poll.poll_users.count == 0 - str = "" - course.students.find_each do |student| - str += "," if str != "" - str += "(#{student.user_id},#{poll.id}, 0, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" + tid_str += "(#{member.user_id}, #{poll.user_id}, #{poll.id}, 'Poll', #{poll.id}, 'PollPublish', #{course.id}, 'Course', 0, 'Poll', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" end - - if str != "" - sql = "insert into poll_users (user_id, poll_id, commit_status, created_at, updated_at) values" + str - ActiveRecord::Base.connection.execute sql + if tid_str != "" + tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str + ActiveRecord::Base.connection.execute tid_sql end end - - if poll.course_acts.size == 0 - poll.course_acts << CourseActivity.new(:user_id => poll.user_id,:course_id => poll.course_id) - end + poll.course_acts << CourseActivity.new(user_id: poll.user_id, course_id: poll.course_id) if !poll.course_acts.exists? end # 分组设置发布时间的问卷 @@ -49,19 +32,8 @@ namespace :poll_publish do poll_group_settings.each do |poll_group| poll = poll_group.poll if poll.present? - course = poll.course poll.update_attributes(:polls_status => 2) if poll.polls_status == 1 - - tid_str = "" - members = course.course_members.where(:course_group_id => poll_group.course_group_id) - members.find_each do |member| - tid_str += "," if tid_str != "" - tid_str += "(#{member.user_id},#{poll.user_id}, #{poll.id}, 'Poll', #{poll.id}, 'PollPublish', #{course.id}, 'Course', 0, 'Poll', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - if tid_str != "" - tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str - ActiveRecord::Base.connection.execute tid_sql - end + PollPublishNotifyJob.perform_later(poll.id, [poll_group.course_group_id]) end end From fd3f85aa93123c7e02a4cc3c8824a6c0eb24d4f2 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 27 Jun 2019 16:50:35 +0800 Subject: [PATCH 0315/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/discuss.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/models/discuss.rb b/app/models/discuss.rb index 8d8dc0163..93f0d62cd 100644 --- a/app/models/discuss.rb +++ b/app/models/discuss.rb @@ -33,11 +33,11 @@ class Discuss < ApplicationRecord "/tasks/#{game&.identifier}" end - def contents(shixun, user) - return content unless hidden? - - shixun.has_manager?(user) ? content : '' - end + # def contents(shixun, user) + # return content unless hidden? + # + # shixun.has_manager?(user) ? content : '' + # end def child_discuss(user) user.admin? ? From 4e7098a3397586c464c2bc52468ff51c8d35f25e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 27 Jun 2019 16:50:44 +0800 Subject: [PATCH 0316/1015] fix bug --- app/controllers/exercises_controller.rb | 2 +- app/services/exercise_user_pdf_service.rb | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index e1e8e226b..720f8f593 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1512,7 +1512,7 @@ class ExercisesController < ApplicationController end def get_exercise_question_counts #获取试卷的问题数及总分数 - exercise_questions = @exercise.exercise_questions.all + exercise_questions = @exercise.exercise_questions.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers) @exercise_ques_count = exercise_questions.count # 全部的题目数 @exercise_ques_scores = exercise_questions.pluck(:question_score).sum diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 28857dff9..8ee1d0cd4 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -47,7 +47,7 @@ class ExerciseUserPdfService end def load_data - @exercise_questions = exercise.exercise_questions + @exercise_questions = exercise.exercise_questions.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers) @exercise_ques_count = @exercise_questions.count # 全部的题目数 @exercise_ques_scores = @exercise_questions.pluck(:question_score).sum @@ -81,7 +81,6 @@ class ExerciseUserPdfService @exercise_ques_shixun_count = exercise_ques_shixun.all.count @exercise_ques_shixun_scores = exercise_ques_shixun.pluck(:question_score).sum - @exercise_questions = @exercise_questions.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers) get_each_student_exercise(exercise.id,@exercise_questions,@ex_user_user.id) end From b65f8bc0a532a391094f5f0ddbfc39f0b0085009 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 27 Jun 2019 16:51:59 +0800 Subject: [PATCH 0317/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/discusses/_discuss.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/discusses/_discuss.json.jbuilder b/app/views/discusses/_discuss.json.jbuilder index da1ca5a6c..e7e6e425f 100644 --- a/app/views/discusses/_discuss.json.jbuilder +++ b/app/views/discusses/_discuss.json.jbuilder @@ -2,7 +2,7 @@ json.author do json.partial! 'users/user', user: discuss.user end json.id discuss.id -json.content discuss.contents +json.content discuss.content json.time time_from_now(discuss.created_at) json.position discuss.position json.shixun_id discuss.dis_id From a43f0b64e935980ba7b1833e3f045653563da0c6 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 27 Jun 2019 16:53:44 +0800 Subject: [PATCH 0318/1015] fix bug --- app/controllers/exercises_controller.rb | 19 +++++++++++-------- app/services/exercise_user_pdf_service.rb | 17 +++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 720f8f593..9a46aa09b 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1512,39 +1512,42 @@ class ExercisesController < ApplicationController end def get_exercise_question_counts #获取试卷的问题数及总分数 - exercise_questions = @exercise.exercise_questions.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers) - @exercise_ques_count = exercise_questions.count # 全部的题目数 + exercise_questions = @exercise.exercise_questions + @exercise_ques_count = exercise_questions.size # 全部的题目数 @exercise_ques_scores = exercise_questions.pluck(:question_score).sum #单选题的数量及分数 exercise_single_ques = exercise_questions.find_by_custom("question_type",0) - @exercise_single_ques_count = exercise_single_ques.all.count + @exercise_single_ques_count = exercise_single_ques.size @exercise_single_ques_scores = exercise_single_ques.pluck(:question_score).sum #多选题的数量及分数 exercise_double_ques = exercise_questions.find_by_custom("question_type",1) - @exercise_double_ques_count = exercise_double_ques.all.count + @exercise_double_ques_count = exercise_double_ques.size @exercise_double_ques_scores = exercise_double_ques.pluck(:question_score).sum # 判断题数量及分数 exercise_ques_judge = exercise_questions.find_by_custom("question_type",2) - @exercise_ques_judge_count = exercise_ques_judge.all.count + @exercise_ques_judge_count = exercise_ques_judge.size @exercise_ques_judge_scores = exercise_ques_judge.pluck(:question_score).sum #填空题数量及分数 exercise_ques_null = exercise_questions.find_by_custom("question_type",3) - @exercise_ques_null_count = exercise_ques_null.all.count + @exercise_ques_null_count = exercise_ques_null.size @exercise_ques_null_scores = exercise_ques_null.pluck(:question_score).sum #简答题数量及分数 exercise_ques_main = exercise_questions.find_by_custom("question_type",4) - @exercise_ques_main_count = exercise_ques_main.all.count + @exercise_ques_main_count = exercise_ques_main.size @exercise_ques_main_scores = exercise_ques_main.pluck(:question_score).sum #实训题数量及分数 exercise_ques_shixun = exercise_questions.find_by_custom("question_type",5) - @exercise_ques_shixun_count = exercise_ques_shixun.all.count + @exercise_ques_shixun_count = exercise_ques_shixun.size @exercise_ques_shixun_scores = exercise_ques_shixun.pluck(:question_score).sum + + @exercise_questions = @exercise_questions.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers) + end #获取用户有权限的分班 diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 8ee1d0cd4..63fbb5a1d 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -47,40 +47,41 @@ class ExerciseUserPdfService end def load_data - @exercise_questions = exercise.exercise_questions.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers) - @exercise_ques_count = @exercise_questions.count # 全部的题目数 + @exercise_questions = exercise.exercise_questions + @exercise_ques_count = @exercise_questions.size # 全部的题目数 @exercise_ques_scores = @exercise_questions.pluck(:question_score).sum #单选题的数量及分数 exercise_single_ques = @exercise_questions.find_by_custom("question_type",0) - @exercise_single_ques_count = exercise_single_ques.all.count + @exercise_single_ques_count = exercise_single_ques.size @exercise_single_ques_scores = exercise_single_ques.pluck(:question_score).sum #多选题的数量及分数 exercise_double_ques = @exercise_questions.find_by_custom("question_type",1) - @exercise_double_ques_count = exercise_double_ques.all.count + @exercise_double_ques_count = exercise_double_ques.size @exercise_double_ques_scores = exercise_double_ques.pluck(:question_score).sum # 判断题数量及分数 exercise_ques_judge = @exercise_questions.find_by_custom("question_type",2) - @exercise_ques_judge_count = exercise_ques_judge.all.count + @exercise_ques_judge_count = exercise_ques_judge.size @exercise_ques_judge_scores = exercise_ques_judge.pluck(:question_score).sum #填空题数量及分数 exercise_ques_null = @exercise_questions.find_by_custom("question_type",3) - @exercise_ques_null_count = exercise_ques_null.all.count + @exercise_ques_null_count = exercise_ques_null.size @exercise_ques_null_scores = exercise_ques_null.pluck(:question_score).sum #简答题数量及分数 exercise_ques_main = @exercise_questions.find_by_custom("question_type",4) - @exercise_ques_main_count = exercise_ques_main.all.count + @exercise_ques_main_count = exercise_ques_main.size @exercise_ques_main_scores = exercise_ques_main.pluck(:question_score).sum #实训题数量及分数 exercise_ques_shixun = @exercise_questions.find_by_custom("question_type",5) - @exercise_ques_shixun_count = exercise_ques_shixun.all.count + @exercise_ques_shixun_count = exercise_ques_shixun.size @exercise_ques_shixun_scores = exercise_ques_shixun.pluck(:question_score).sum + @exercise_questions = @exercise_questions.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers) get_each_student_exercise(exercise.id,@exercise_questions,@ex_user_user.id) end From 28b39b94f4cae61a7bf9deb8e932434e25d484ed Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 27 Jun 2019 16:58:12 +0800 Subject: [PATCH 0319/1015] fix bug --- app/controllers/exercises_controller.rb | 2 +- app/services/exercise_user_pdf_service.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 9a46aa09b..4b96afc85 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1546,7 +1546,7 @@ class ExercisesController < ApplicationController @exercise_ques_shixun_count = exercise_ques_shixun.size @exercise_ques_shixun_scores = exercise_ques_shixun.pluck(:question_score).sum - @exercise_questions = @exercise_questions.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers) + @exercise_questions = @exercise_questions&.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers) end diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 63fbb5a1d..22804092e 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -81,7 +81,7 @@ class ExerciseUserPdfService @exercise_ques_shixun_count = exercise_ques_shixun.size @exercise_ques_shixun_scores = exercise_ques_shixun.pluck(:question_score).sum - @exercise_questions = @exercise_questions.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers) + @exercise_questions = @exercise_questions&.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_answers,:exercise_shixun_answers,:exercise_answer_comments,:exercise_standard_answers) get_each_student_exercise(exercise.id,@exercise_questions,@ex_user_user.id) end From 7c1635f157fbb73172de7b5e91e9580df4993db9 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 27 Jun 2019 17:02:47 +0800 Subject: [PATCH 0320/1015] 1 --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 83bfd29fc..2f63f3ab9 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -1233,7 +1233,7 @@ class HomeworkCommonsController < ApplicationController # 代码查重届结果 def code_review_results # 如果有未获取结果的查重操作 则先读取结果 - get_new_code_reviews_result @homework + #get_new_code_reviews_result @homework @current_user = current_user # 列表数据 From a04bdef1eb3655de4c45677172210039e4fd95bd Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 27 Jun 2019 17:05:59 +0800 Subject: [PATCH 0321/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E4=BB=BB=E5=8A=A1=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 6 +-- app/jobs/exercise_publish_notify_job.rb | 19 ++++++--- app/jobs/poll_publish_notify_job.rb | 4 +- app/tasks/exercise_publish_task.rb | 51 +++++++------------------ 4 files changed, 31 insertions(+), 49 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index e1e8e226b..2103a8614 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -729,7 +729,6 @@ class ExercisesController < ApplicationController if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则试卷不用分组,且试卷设定为统一设置,否则则分组设置 exercise.exercise_group_settings.destroy_all ex_unified = true - notify_receiver_ids = @course.students.pluck(:user_id) else ex_unified = false g_course.each do |i| @@ -749,12 +748,11 @@ class ExercisesController < ApplicationController end end - notify_receiver_ids = @course.students.where(course_group_id: params[:group_ids]).pluck(:user_id) + group_ids = params[:group_ids] end else exercise.exercise_group_settings.destroy_all ex_unified = true - notify_receiver_ids = @course.students.pluck(:user_id) end if exercise.end_time.blank? e_time = ex_end_time @@ -775,7 +773,7 @@ class ExercisesController < ApplicationController if exercise.course_acts.size == 0 exercise.course_acts << CourseActivity.new(:user_id => exercise.user_id,:course_id => exercise.course_id) end - ExercisePublishNotifyJob.perform_later(exercise.id, notify_receiver_ids) + ExercisePublishNotifyJob.perform_later(exercise.id, group_ids) end end end diff --git a/app/jobs/exercise_publish_notify_job.rb b/app/jobs/exercise_publish_notify_job.rb index c66fa5660..563f6ceb0 100644 --- a/app/jobs/exercise_publish_notify_job.rb +++ b/app/jobs/exercise_publish_notify_job.rb @@ -2,11 +2,20 @@ class ExercisePublishNotifyJob < ApplicationJob queue_as :notify - def perform(exercise_id, receiver_ids) + def perform(exercise_id, group_ids) exercise = Exercise.find_by(id: exercise_id) return if exercise.blank? user = exercise.user + if group_ids.present? + students = course.students.where(course_group_id: group_ids) + subquery = course.teacher_course_groups.where(course_group_id: group_ids).select(:course_member_id) + teachers = course.teachers.where(id: subquery) + else + students = course.students + teachers = course.teachers + end + attrs = %i[ user_id trigger_user_id container_id container_type parent_container_id parent_container_type belong_container_id belong_container_type viewed tiding_type created_at updated_at @@ -19,14 +28,14 @@ class ExercisePublishNotifyJob < ApplicationJob viewed: 0, tiding_type: 'Exercise' } Tiding.bulk_insert(*attrs) do |worker| - teacher_ids = exercise.course.teachers.pluck(:user_id) + teacher_ids = teachers.pluck(:user_id) unless exercise.tidings.exists?(parent_container_type: 'ExercisePublish', user_id: teacher_ids) - exercise.course.teachers.find_each do |teacher| - worker.add same_attrs.merge(user_id: teacher.user_id) + teacher_ids.find_each do |user_id| + worker.add same_attrs.merge(user_id: user_id) end end - receiver_ids.each do |user_id| + students.pluck(:user_id).each do |user_id| worker.add same_attrs.merge(user_id: user_id) end end diff --git a/app/jobs/poll_publish_notify_job.rb b/app/jobs/poll_publish_notify_job.rb index d7ed1ae02..89fb45ea5 100644 --- a/app/jobs/poll_publish_notify_job.rb +++ b/app/jobs/poll_publish_notify_job.rb @@ -31,8 +31,8 @@ class PollPublishNotifyJob < ApplicationJob Tiding.bulk_insert(*attrs) do |worker| teacher_ids = teachers.pluck(:user_id) unless poll.tidings.exists?(parent_container_type: 'PollPublish', user_id: teacher_ids) - poll.course.teachers.find_each do |teacher| - worker.add same_attrs.merge(user_id: teacher.user_id) + teacher_ids.find_each do |user_id| + worker.add same_attrs.merge(user_id: user_id) end end diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb index 3df5f84ae..220512664 100644 --- a/app/tasks/exercise_publish_task.rb +++ b/app/tasks/exercise_publish_task.rb @@ -8,39 +8,24 @@ class ExercisePublishTask exercises = Exercise.includes(:exercise_users).where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now) exercises&.each do |exercise| exercise.update_column('exercise_status', 2) - course = exercise.course - tid_str = "" - course.teachers.find_each do |member| - tid_str += "," if tid_str != "" - tid_str += "(#{member.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end + if exercise.unified_setting - course.students.find_each do |student| + ExercisePublishNotifyJob.perform_later(exercise.id, nil) + else + course = exercise.course + teachers = course.teachers.where.not(id: course.teacher_course_groups.select(:course_member_id)) + tid_str = "" + teachers.find_each do |member| tid_str += "," if tid_str != "" - tid_str += "(#{student.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" + tid_str += "(#{member.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" end - end - if tid_str != "" - tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str - ActiveRecord::Base.connection.execute tid_sql - end - - if exercise.exercise_users.size == 0 - str = "" - course.students.find_each do |student| - str += "," if str != "" - str += "(#{student.user_id}, #{exercise.id}, 0, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - - if str != "" - sql = "insert into exercise_users (user_id, exercise_id, commit_status, created_at, updated_at) values" + str - ActiveRecord::Base.connection.execute sql + if tid_str != "" + tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str + ActiveRecord::Base.connection.execute tid_sql end end - if exercise.course_acts.size == 0 - exercise.course_acts << CourseActivity.new(:user_id => exercise.user_id,:course_id => exercise.course_id) - end + exercise.course_acts << CourseActivity.new(user_id: exercise.user_id, course_id: exercise.course_id) if !exercise.course_acts.exists? end # 分组设置发布时间的测验 @@ -48,18 +33,8 @@ class ExercisePublishTask exercise_group_settings&.each do |exercise_group| exercise = exercise_group.exercise if exercise.present? - course = exercise.course exercise.update_attributes(:exercise_status => 2) if exercise.exercise_status == 1 - tid_str = "" - members = course.students.where(:course_group_id => exercise_group.course_group_id) - members.find_each do |member| - tid_str += "," if tid_str != "" - tid_str += "(#{member.user_id},#{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - if tid_str != "" - tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id, parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at, updated_at) values" + tid_str - ActiveRecord::Base.connection.execute tid_sql - end + ExercisePublishNotifyJob.perform_later(exercise.id, [exercise_group.course_group_id]) end end Rails.logger.info("log--------------------------------exercise_publish end") From 442ff88d39c7097baca78a7a476f2cc64a9237aa Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 27 Jun 2019 17:06:27 +0800 Subject: [PATCH 0322/1015] =?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/helpers/homework_commons_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/homework_commons_helper.rb b/app/helpers/homework_commons_helper.rb index 261fc85e9..c77ae5937 100644 --- a/app/helpers/homework_commons_helper.rb +++ b/app/helpers/homework_commons_helper.rb @@ -65,7 +65,7 @@ module HomeworkCommonsHelper # 作业统一设置、游客身份、超级管理员、分班权限不限的老师身份 if homework_common.unified_setting || identity > Course::STUDENT || identity == Course::ADMIN || - (identity < Course::STUDENT && teacher_course_groups.size == 0) + (identity < Course::STUDENT && teacher_course_groups.blank?) case ho_detail_manual.comment_status when 0 status << "未发布" From 3c92d07cf343a09b4a84d9f8fc470d1171601f79 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 27 Jun 2019 17:21:12 +0800 Subject: [PATCH 0323/1015] fix bug --- .../exercise_questions_controller.rb | 36 +++++++++++-------- app/controllers/poll_questions_controller.rb | 20 ++++++----- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 490791918..8c4eb0a89 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -424,14 +424,18 @@ class ExerciseQuestionsController < ApplicationController begin choice_d_id = params[:choice_no].to_i # 选项的当前位置 question_choices = @exercise_question.exercise_choices - delete_answer = question_choices.find_choice_custom("choice_position",choice_d_id).first - left_choice = question_choices.left_choice_choose("choice_position",choice_d_id) - if left_choice.present? - left_choice.each do |p| - p.choice_position -= 1 - p.save - end - end + delete_answer = question_choices.find_by(choice_position: choice_d_id) + left_choices = question_choices.where("choice_position > ? ",choice_d_id) + left_choices.update_all("choice_position = choice_position - 1") if left_choices + # delete_answer = question_choices.find_choice_custom("choice_position",choice_d_id).first + # + # left_choice = question_choices.left_choice_choose("choice_position",choice_d_id) + # if left_choice.present? + # left_choice.each do |p| + # p.choice_position -= 1 + # p.save + # end + # end if delete_answer.destroy normal_status(0, "答案删除成功!") else @@ -450,13 +454,15 @@ class ExerciseQuestionsController < ApplicationController begin question_d_id = @exercise_question.question_number.to_i #问题的当前位置 exercise_questions = @exercise.exercise_questions - left_question = exercise_questions.left_question_choose("question_number",question_d_id) - if left_question.present? - left_question.each do |q| - q.question_number -= 1 - q.save - end - end + left_questions = exercise_questions.where("question_number > ?", question_d_id) + left_questions.update_all("question_number = question_number - 1") if left_questions + # left_question = exercise_questions.left_question_choose("question_number",question_d_id) + # if left_question.present? + # left_question.each do |q| + # q.question_number -= 1 + # q.save + # end + # end if @exercise_question.destroy normal_status(0, "问题删除成功!") else diff --git a/app/controllers/poll_questions_controller.rb b/app/controllers/poll_questions_controller.rb index 47cd236a9..c7407c129 100644 --- a/app/controllers/poll_questions_controller.rb +++ b/app/controllers/poll_questions_controller.rb @@ -156,14 +156,18 @@ class PollQuestionsController < ApplicationController begin answer_d_id = params[:answer_no].to_i # 答案的当前位置 poll_answers = @poll_question.poll_answers - delete_answer = poll_answers.find_answer_by_custom("answer_position",answer_d_id).first - left_answer = poll_answers.left_answer_choose("answer_position",answer_d_id) - if left_answer.present? - left_answer.each do |p| - p.answer_position -= 1 - p.save - end - end + delete_answer = poll_answers.find_by(answer_position: answer_d_id) + left_answers = poll_answers.where("answer_position > ?",answer_d_id) + left_answers.update_all("answer_position = answer_position - 1") if left_answers + + # delete_answer = poll_answers.find_answer_by_custom("answer_position",answer_d_id).first + # left_answer = poll_answers.left_answer_choose("answer_position",answer_d_id) + # if left_answer.present? + # left_answer.each do |p| + # p.answer_position -= 1 + # p.save + # end + # end if delete_answer.destroy normal_status(0, "答案删除成功!") else From 1f224b681296eaeb517373f76d22eb4305d9520a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 27 Jun 2019 17:32:44 +0800 Subject: [PATCH 0324/1015] =?UTF-8?q?=E8=A7=A3=E9=94=81=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 19 ++++++++++++++----- .../homework_commons_controller.rb | 2 +- app/views/games/check_test_sets.json.jbuilder | 3 +-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 4e7afa516..00760209e 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -344,11 +344,20 @@ class GamesController < ApplicationController @game.update_attribute(:test_sets_view, true) # 扣分记录 Grade.create(:user_id => current_user.id, :container_id => @game.id, :score => -@minus_grade, :container_type => "testSet") - @status = 0 - @message = "解锁成功!" + max_query_index = game.query_index.to_i + # 区分评测过未评测过,未评测过按需求取数据 + if max_query_index > 0 + qurey_test_sets = TestSet.find_by_sql("SELECT o.code, o.actual_output, o.out_put, o.result, o.compile_success, o.test_set_position, o.query_index,t.is_public,t.input, t.output, g.id as game_id, c.id as challenge_id FROM outputs o,games g ,challenges c,test_sets t where + g.id=#{game.id} and o.query_index=#{max_query_index} and g.id = o.game_id and c.id= g.challenge_id and t.challenge_id = c.id and t.position =o.test_set_position order by o.query_index + ") + else + qurey_test_sets = TestSet.find_by_sql("SELECT t.is_public,t.input, t.output,t.position FROM games g ,challenges c,test_sets t where + g.id=#{game.id} and c.id= g.challenge_id and t.challenge_id = c.id + ") + end + testset_detail max_query_index, challenge else - @status = -1 - @message = "本操作需要扣除#{ @minus_grade }金币,您的金币不够了" + tip_exception(-1, "本操作需要扣除#{ @minus_grade }金币,您的金币不够了") end end @@ -813,7 +822,7 @@ class GamesController < ApplicationController # 评测测试机封装 def testset_detail max_query_index, challenge # 是否允许查看隐藏的测试集,以前的power - @allowed_hidden_testset = @identity < User::EDU_GAME_MANAGER + @allowed_hidden_testset = @identity < User::EDU_GAME_MANAGER || @game.test_sets_view #解锁的用户 if max_query_index > 0 uid_logger("max_query_index is #{max_query_index} game id is #{@game.id}, challenge_id is #{challenge.id}") diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 2f63f3ab9..83bfd29fc 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -1233,7 +1233,7 @@ class HomeworkCommonsController < ApplicationController # 代码查重届结果 def code_review_results # 如果有未获取结果的查重操作 则先读取结果 - #get_new_code_reviews_result @homework + get_new_code_reviews_result @homework @current_user = current_user # 列表数据 diff --git a/app/views/games/check_test_sets.json.jbuilder b/app/views/games/check_test_sets.json.jbuilder index 017a75aea..ae44b54e9 100644 --- a/app/views/games/check_test_sets.json.jbuilder +++ b/app/views/games/check_test_sets.json.jbuilder @@ -1,2 +1 @@ -json.status @status -json.message @message \ No newline at end of file +json.partial! 'games/testset_list' \ No newline at end of file From 0800574303ca924e4592362f530ca651869fac13 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 27 Jun 2019 17:42:10 +0800 Subject: [PATCH 0325/1015] =?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/graduation_tasks_controller.rb | 5 ++++- app/models/graduation_work.rb | 2 +- app/views/graduation_tasks/tasks_list.json.jbuilder | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 2e72c57d3..93d3cba3d 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -59,7 +59,8 @@ class GraduationTasksController < ApplicationController # 任务发布的情况下: 是老师身份或者任务已截止的情况下公开任务了作品设置的学生也能查看其他人的作品 if @task.published? && (@user_course_identity < Course::STUDENT || (@user_course_identity == Course::STUDENT && @work.present? && @work.take.work_status > 0 && - @task.status > 1 && @task.open_work)) + ((!@task.allow_late && @task.status > 1) || (@task.allow_late && @task.late_time && @task.late_time < Time.now)) && + (@task.open_work || @task.open_score))) # 如有有分班则看分班内的学生,否则看所有学生的作品 user_ids = if @user_course_identity < Course::STUDENT @@ -117,6 +118,7 @@ class GraduationTasksController < ApplicationController @work_list = @work_list.joins(user: :user_extension).order("user_extensions.#{rorder} #{b_order}") end + @view_work = @task.open_work || @user_course_identity < Course::STUDENT @work_count = @work_list.count @work_excel = @work_list @@ -150,6 +152,7 @@ class GraduationTasksController < ApplicationController end else @work_list = @work + @view_work = false @work_count = @work_list.count @all_work_count = @work_list.count respond_to do |format| diff --git a/app/models/graduation_work.rb b/app/models/graduation_work.rb index 49cab19ee..e9be0a43e 100644 --- a/app/models/graduation_work.rb +++ b/app/models/graduation_work.rb @@ -63,7 +63,7 @@ class GraduationWork < ApplicationRecord #用户是否有查看分数的权限 def check_score_power? current_user, course_identity - self.work_score.present? || course_identity < Course::STUDENT || self.user_id = current_user.id + self.work_score.present? && (course_identity < Course::STUDENT || self.user_id = current_user.id || graduation_task.open_score) end # 作品是否能够分配指导老师 diff --git a/app/views/graduation_tasks/tasks_list.json.jbuilder b/app/views/graduation_tasks/tasks_list.json.jbuilder index 62c95901f..7588b6b6e 100644 --- a/app/views/graduation_tasks/tasks_list.json.jbuilder +++ b/app/views/graduation_tasks/tasks_list.json.jbuilder @@ -59,6 +59,7 @@ if @task.published? || @user_course_identity < Course::STUDENT json.late_penalty work.late_penalty if @task.allow_late json.final_score work_final_score work, @current_user, @user_course_identity json.assign work.assign_power?(@user_course_identity) + json.view_work @view_work || @current_user.id == work.user_id end end end \ No newline at end of file From 2a559db5806d151f37f7329f7cb61741bfea2d1d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 27 Jun 2019 17:57:35 +0800 Subject: [PATCH 0326/1015] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E4=BD=9C=E5=93=81?= =?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/graduation_works_controller.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/controllers/graduation_works_controller.rb b/app/controllers/graduation_works_controller.rb index 09b9146e8..7cf1a3393 100644 --- a/app/controllers/graduation_works_controller.rb +++ b/app/controllers/graduation_works_controller.rb @@ -13,6 +13,7 @@ class GraduationWorksController < ApplicationController before_action :published_task, only: [:new, :create, :edit, :update, :search_member_list, :relate_project, :cancel_relate_project, :revise_attachment] before_action :edit_duration, only: [:edit, :update] + before_action :open_work, only: [:show, :supply_attachments, :comment_list] def new if @task.task_type == 2 && @task.base_on_project @@ -489,6 +490,11 @@ class GraduationWorksController < ApplicationController tip_exception("已过了修改时间") if @task.end_time && @task.end_time < Time.now end + # 作品是否公开 + def open_work + tip_exception(403,"没有操作权限") unless (@user_course_identity < Course::STUDENT || current_user == @work.user || @task.open_work) + end + def update_check work tip_exception("作品描述不能为空") if params[:description].blank? if @task.task_type == 2 From 2c48a24f485a98a329b7b69138841f3dbf2bbf90 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 27 Jun 2019 18:12:04 +0800 Subject: [PATCH 0327/1015] 1 --- app/controllers/games_controller.rb | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 00760209e..ac0b6baa8 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -344,17 +344,7 @@ class GamesController < ApplicationController @game.update_attribute(:test_sets_view, true) # 扣分记录 Grade.create(:user_id => current_user.id, :container_id => @game.id, :score => -@minus_grade, :container_type => "testSet") - max_query_index = game.query_index.to_i - # 区分评测过未评测过,未评测过按需求取数据 - if max_query_index > 0 - qurey_test_sets = TestSet.find_by_sql("SELECT o.code, o.actual_output, o.out_put, o.result, o.compile_success, o.test_set_position, o.query_index,t.is_public,t.input, t.output, g.id as game_id, c.id as challenge_id FROM outputs o,games g ,challenges c,test_sets t where - g.id=#{game.id} and o.query_index=#{max_query_index} and g.id = o.game_id and c.id= g.challenge_id and t.challenge_id = c.id and t.position =o.test_set_position order by o.query_index - ") - else - qurey_test_sets = TestSet.find_by_sql("SELECT t.is_public,t.input, t.output,t.position FROM games g ,challenges c,test_sets t where - g.id=#{game.id} and c.id= g.challenge_id and t.challenge_id = c.id - ") - end + max_query_index = @game.query_index.to_i testset_detail max_query_index, challenge else tip_exception(-1, "本操作需要扣除#{ @minus_grade }金币,您的金币不够了") From 248ff8a43464dcc0da7dad304144994456f9a918 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 27 Jun 2019 18:14:52 +0800 Subject: [PATCH 0328/1015] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/games/check_test_sets.json.jbuilder | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/views/games/check_test_sets.json.jbuilder b/app/views/games/check_test_sets.json.jbuilder index ae44b54e9..ba1ed64a6 100644 --- a/app/views/games/check_test_sets.json.jbuilder +++ b/app/views/games/check_test_sets.json.jbuilder @@ -1 +1,10 @@ -json.partial! 'games/testset_list' \ No newline at end of file +json.test_sets @qurey_test_sets do |test_set| + json.is_public test_set.is_public + json.result test_set.try(:result) + if test_set.is_public || @allowed_hidden_testset + json.input test_set.input + json.output test_set.output + json.actual_output evaluate_actual_output(test_set) + end + json.compile_success test_set.try(:compile_success) +end \ No newline at end of file From 5bc7ef8da5b9985cf9281dec5b821456c1683ee4 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 27 Jun 2019 18:15:06 +0800 Subject: [PATCH 0329/1015] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E7=9A=84=E6=9D=83?= =?UTF-8?q?=E9=99=90=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 2 +- app/controllers/student_works_controller.rb | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 83bfd29fc..b89fd6b67 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -121,7 +121,7 @@ class HomeworkCommonsController < ApplicationController @work = @homework.user_work(current_user.id) # 学生已提交作品且补交(提交)已截止、作品公开、非匿评阶段 - if @work&.work_status.to_i > 0 && @homework.work_public && + if @work&.work_status.to_i > 0 && (@homework.work_public || @homework.score_open) && ((!@homework.anonymous_comment && @homework.end_or_late) || @homework_detail_manual.comment_status > 4) @student_works = student_works.where("user_id != #{@work.user_id}") diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 31c198fd8..ab026cf05 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -25,7 +25,7 @@ class StudentWorksController < ApplicationController before_action :require_score_id, only: [:destroy_score, :add_score_reply, :appeal_anonymous_score, :deal_appeal_score, :cancel_appeal] - before_action :is_evaluation, only: [:show, :supply_attachments] + before_action :is_evaluation, :open_work, only: [:show, :supply_attachments] def new uid_logger("#######new current_user : 1111") @@ -704,6 +704,11 @@ class StudentWorksController < ApplicationController [3, 4].include?(@homework.homework_detail_manual.comment_status) end + # 作品是否公开 + def open_work + tip_exception(403,"没有操作权限") unless (@user_course_identity < Course::STUDENT || current_user == @work.user || @homework.work_public || @is_evaluation) + end + def allow_add_score # 老师始终有评阅权限,匿评阶段内,学生对分配给该学生的作品有评阅权限 tip_exception(403, "没有权限") unless allow_score(@homework, @user_course_identity, current_user.id, @work) From 4f88d88bed4ff9a6195b4ca501eb0cbf9edec3e1 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 27 Jun 2019 18:22:56 +0800 Subject: [PATCH 0330/1015] =?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/models/student_work.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/student_work.rb b/app/models/student_work.rb index a2379f1a8..d5b746ebd 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -61,12 +61,12 @@ class StudentWork < ApplicationRecord # 当前用户该作品的匿评申诉总条数 def my_appeal_all_count user_id - student_works_scores.select{|score| score.reviewer_role == 3 && score.appeal_status != 0 && score.user_id = user_id}.size + student_works_scores.select{|score| score.reviewer_role == 3 && score.appeal_status != 0 && score.user_id == user_id}.size end # 当前用户该作品的匿评申诉总条数 def my_appeal_deal_count user_id - student_works_scores.select{|score| score.reviewer_role == 3 && score.appeal_status == 1 && score.user_id = user_id}.size + student_works_scores.select{|score| score.reviewer_role == 3 && score.appeal_status == 1 && score.user_id == user_id}.size end # 分组名 From 4d1ff1f0e8521b04587775ecfa91065de47b31fb Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 27 Jun 2019 18:32:21 +0800 Subject: [PATCH 0331/1015] fix bug --- app/controllers/exercise_questions_controller.rb | 16 ---------------- app/controllers/poll_questions_controller.rb | 8 -------- 2 files changed, 24 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 8c4eb0a89..dd0247f70 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -427,15 +427,6 @@ class ExerciseQuestionsController < ApplicationController delete_answer = question_choices.find_by(choice_position: choice_d_id) left_choices = question_choices.where("choice_position > ? ",choice_d_id) left_choices.update_all("choice_position = choice_position - 1") if left_choices - # delete_answer = question_choices.find_choice_custom("choice_position",choice_d_id).first - # - # left_choice = question_choices.left_choice_choose("choice_position",choice_d_id) - # if left_choice.present? - # left_choice.each do |p| - # p.choice_position -= 1 - # p.save - # end - # end if delete_answer.destroy normal_status(0, "答案删除成功!") else @@ -456,13 +447,6 @@ class ExerciseQuestionsController < ApplicationController exercise_questions = @exercise.exercise_questions left_questions = exercise_questions.where("question_number > ?", question_d_id) left_questions.update_all("question_number = question_number - 1") if left_questions - # left_question = exercise_questions.left_question_choose("question_number",question_d_id) - # if left_question.present? - # left_question.each do |q| - # q.question_number -= 1 - # q.save - # end - # end if @exercise_question.destroy normal_status(0, "问题删除成功!") else diff --git a/app/controllers/poll_questions_controller.rb b/app/controllers/poll_questions_controller.rb index c7407c129..84e21c4e8 100644 --- a/app/controllers/poll_questions_controller.rb +++ b/app/controllers/poll_questions_controller.rb @@ -160,14 +160,6 @@ class PollQuestionsController < ApplicationController left_answers = poll_answers.where("answer_position > ?",answer_d_id) left_answers.update_all("answer_position = answer_position - 1") if left_answers - # delete_answer = poll_answers.find_answer_by_custom("answer_position",answer_d_id).first - # left_answer = poll_answers.left_answer_choose("answer_position",answer_d_id) - # if left_answer.present? - # left_answer.each do |p| - # p.answer_position -= 1 - # p.save - # end - # end if delete_answer.destroy normal_status(0, "答案删除成功!") else From 0946b44fadf3db54e62b5f3458ebe5c3b0b3cca6 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 28 Jun 2019 08:42:50 +0800 Subject: [PATCH 0332/1015] =?UTF-8?q?=E5=BC=80=E5=90=AF=E6=8C=91=E6=88=98?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E5=85=B3=E5=8D=A1=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index a319dc58a..d9588cb5b 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -557,7 +557,7 @@ class ShixunsController < ApplicationController # HomeworksService.new.update_myshixun_work_status myshixun UpdateMyshixunWorkStatusJob.perform_later(myshixun.id) - @current_task = myshixun.current_task + @current_task = myshixun.current_task(myshixun.games) uid_logger("## shixun exec: myshixun id is #{myshixun.id}") rescue Exception => e uid_logger_error(e.message) From 6f97f3e6c94891c72bb8e813f410f9427c114478 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 09:01:05 +0800 Subject: [PATCH 0333/1015] =?UTF-8?q?=E5=85=B3=E5=8D=A1=E7=9A=84=E6=9D=83?= =?UTF-8?q?=E9=99=90=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index f2a964c8d..e315ab596 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -5,8 +5,8 @@ class ChallengesController < ApplicationController before_action :find_challenge, only: [:edit, :show, :update, :create_choose_question, :index_down, :index_up, :edit_choose_question, :show_choose_question, :destroy_challenge_choose, :update_choose_question, :destroy, :crud_answer, :answer] - # before_action :allowed, except: [:index, :show, :edit_choose_question, :edit] - + # 权限控制 + before_action :allowed, except: [:index] include ShixunsHelper include ChallengesHelper @@ -296,8 +296,7 @@ class ChallengesController < ApplicationController end def allowed - # 实训为发布前,除实训的管理者外,其他人都不人都不允许访问 - if !current_user.manager_of_shixun?(@shixun) && (@shixun.status < 1 || @shixun.hidden == 1) + unless current_user.manager_of_shixun?(@shixun) raise Educoder::TipException.new(403, "..") end end From 0773f7fc48004fb9a7e604dfedf5d662bffeb17a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 28 Jun 2019 09:36:56 +0800 Subject: [PATCH 0334/1015] =?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/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 253bafa48..93eba89d8 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -11,7 +11,7 @@ class CoursesController < ApplicationController render_error(ex.model.errors.full_messages.join(',')) end - before_action :require_login, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups] + before_action :require_login, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups, :left_banner, :top_banner] before_action :set_course, :user_course_identity, only: [:show, :update, :destroy, :settings, :set_invite_code_halt, :set_public_or_private, :search_teacher_candidate, :teachers, :top_banner, :left_banner, :add_teacher_popup, :add_teacher, From 6e18d221112013a4d783dea3828ce224d3be623d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 09:42:59 +0800 Subject: [PATCH 0335/1015] =?UTF-8?q?=E6=89=93=E5=BC=80=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index d9588cb5b..290b4387d 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -518,7 +518,7 @@ class ShixunsController < ApplicationController ActiveRecord::Base.transaction do begin - #cloud_bridge = edu_setting('cloud_bridge') + cloud_bridge = edu_setting('cloud_bridge') myshixun_identifier = generate_identifier Myshixun, 10 myshixun = @shixun.myshixuns.create!(user_id: current_user.id, identifier: myshixun_identifier, modify_time: @shixun.modify_time, reset_time: @shixun.reset_time, From 11c7e95a4606c25f27f6a1ba081534a5cdeff73b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 09:44:00 +0800 Subject: [PATCH 0336/1015] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AF=95=E5=8D=B7?= =?UTF-8?q?=E7=9A=84=E5=88=A0=E9=99=A4=E6=85=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/exercise_question.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/exercise_question.rb b/app/models/exercise_question.rb index 5f456e21f..607ad1a29 100644 --- a/app/models/exercise_question.rb +++ b/app/models/exercise_question.rb @@ -5,11 +5,11 @@ class ExerciseQuestion < ApplicationRecord belongs_to :shixun, optional: true has_many :exercise_choices, :dependent => :destroy - has_many :exercise_answers, :dependent => :destroy + has_many :exercise_answers has_many :exercise_shixun_challenges,:dependent => :destroy - has_many :exercise_shixun_answers, :dependent => :destroy - has_many :exercise_answer_comments, :dependent => :destroy - has_many :exercise_standard_answers, :dependent => :destroy + has_many :exercise_shixun_answers + has_many :exercise_answer_comments + has_many :exercise_standard_answers scope :insert_question_ex, lambda {|k| where("question_number > ?",k)} scope :find_by_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 From fc2685a9d8433f36a1f2775ba5c4ed8acd607053 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 10:07:55 +0800 Subject: [PATCH 0337/1015] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=88=E4=BD=9C?= =?UTF-8?q?=E8=80=85=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 290b4387d..743594749 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -624,8 +624,11 @@ class ShixunsController < ApplicationController def add_collaborators raise("搜索内容不能为空") unless params[:search] member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")" - condition = "%#{params[:search].strip}%".gsub(" ","") - @users = User.where("id not in #{member_ids} and status = 1 and LOWER(concat(lastname, firstname, login, mail, nickname)) LIKE '#{condition}'") + user_name = "%#{params[:user_name].strip}%" + school_name = "%#{params[:school_name].strip}%" + @users = User.joins(user_extension: :school).where("users.id not in #{member_ids} AND users.status = 1 AND + LOWER(users.lastname) LIKE '#{user_name}' AND LOWER(schools.name) LIKE + '#{school_name}' ") end def shixun_members_added From e1c40cd30d9288e6a0b3e5cb03f44c5c8f0f9d3d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 10:11:27 +0800 Subject: [PATCH 0338/1015] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=88=E4=BD=9C?= =?UTF-8?q?=E8=80=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 743594749..ecbcbf872 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -626,9 +626,13 @@ class ShixunsController < ApplicationController member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")" user_name = "%#{params[:user_name].strip}%" school_name = "%#{params[:school_name].strip}%" - @users = User.joins(user_extension: :school).where("users.id not in #{member_ids} AND users.status = 1 AND + if user_name.present? || school_name.present? + @users = User.joins(user_extension: :school).where("users.id not in #{member_ids} AND users.status = 1 AND LOWER(users.lastname) LIKE '#{user_name}' AND LOWER(schools.name) LIKE - '#{school_name}' ") + '#{school_name}'") + else + @users = User.none + end end def shixun_members_added From 72c304faa5707b76035221cf2812e21fd88664ec Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 10:22:03 +0800 Subject: [PATCH 0339/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E9=80=89?= =?UTF-8?q?=E9=A1=B9=E9=9A=8F=E6=9C=BA=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exercise_questions/_exercise_questions.json.jbuilder | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index 7a05c2e11..9445862ba 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -6,10 +6,11 @@ json.question_type question.question_type json.question_score question.question_score.round(1).to_s if question.question_type <= 2 #当为选择题或判断题时,只显示选项的位置 standard_answers_array = question.get_standard_answer_ids - exercise_choices = choices.order("choice_position ASC") ex_choice_random_boolean = (exercise_type.present? && exercise_type == 3 && (question.exercise.choice_random)) ? true : false #问题的选项随机打乱 if ex_choice_random_boolean - exercise_choices = exercise_choices.order("RAND()") + exercise_choices = choices.order("RAND()") + else + exercise_choices = choices.order("choice_position ASC") end json.question_choices do json.array! exercise_choices.each_with_index.to_a do |a,index| From 21c0d774e4d9e717b747dceb2de164bd6aa37210 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 10:26:11 +0800 Subject: [PATCH 0340/1015] =?UTF-8?q?=E5=8F=91=E9=80=81=E8=87=B3=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E8=AF=BE=E7=A8=8B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index ecbcbf872..f8c2fce68 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -674,14 +674,14 @@ class ShixunsController < ApplicationController limit = params[:limit] || 20 if params[:search] search = "%#{params[:search].to_s.strip.downcase}%" - course_ids = Course.find_by_sql("SELECT c.id FROM courses c, members m, member_roles mr - WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) + course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m + WHERE m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0 AND c.name like '#{search}' ").map(&:id) else - course_ids = Course.find_by_sql("SELECT c.id, c.name FROM courses c, members m, member_roles mr - WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) + course_ids = Course.find_by_sql("SELECT c.id, c.name FROM courses c, course_members m + WHERE m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0").map(&:id) end From fa9448967bc96d6b679ae28c5a6718dd2fc789b2 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 10:32:56 +0800 Subject: [PATCH 0341/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E5=8F=91=E9=80=81?= =?UTF-8?q?=E8=87=B3=E8=AF=BE=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index f8c2fce68..e3a658d7c 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -693,7 +693,7 @@ class ShixunsController < ApplicationController # 将实训发送到课程 def send_to_course @course = Course.find(params[:course_id]) - homework = HomeworksService.new.create_homework shixun, @course, nil, current_user + homework = HomeworksService.new.create_homework @shixun, @course, nil, current_user end # 二维码扫描下载 From d4bdc7e8e2145f730875937b70917d89082c9d25 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 10:34:50 +0800 Subject: [PATCH 0342/1015] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=8F=91=E9=80=81?= =?UTF-8?q?=E8=87=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shixuns/send_to_course.json.jbuilder | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/views/shixuns/send_to_course.json.jbuilder b/app/views/shixuns/send_to_course.json.jbuilder index dd087d3e2..b2e30f985 100644 --- a/app/views/shixuns/send_to_course.json.jbuilder +++ b/app/views/shixuns/send_to_course.json.jbuilder @@ -1,4 +1,3 @@ json.status 1 json.message "发送成功" -json.url course_homework_commons_path(@course.id, type: 4) -# json.url "#{Rails::configuration.educoder['old_edu_host']}/homework_common?course=#{@course.id}&homework_type=4" \ No newline at end of file +json.course_id @course.id \ No newline at end of file From 863dad51b1ab2d80da23070c020c20da2df13d53 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 10:37:41 +0800 Subject: [PATCH 0343/1015] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=95=E5=8D=B7?= =?UTF-8?q?=E7=AD=94=E9=A2=98=E5=88=97=E8=A1=A8=E7=9A=84=E5=AD=A6=E7=94=9F?= =?UTF-8?q?=E5=92=8C=E8=80=81=E5=B8=88=E8=A7=86=E8=A7=92=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 7e7e1070d..fd2877cc8 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -508,15 +508,14 @@ module ExercisesHelper current_user_group_name = course_group.first.name if course_group.present? end teacher_review = ex_user.subjective_score < 0.0 ? false : true - if ex_user_exercise_status != 3 || commit_status != 1 #试卷未截止或用户未提交 - # if (user_status != 0 && ex_user_exercise_status != 3)|| commit_status == 0 #不为教师,且试卷未截止;当前用户未提交 不显示分数 - ex_object_score = nil - ex_subject_score = nil - score = nil - else + if (user_status == 0 && commit_status == 1) || (user_status == 1 && ex_user_exercise_status == 3 && commit_status == 1) #老师都可以看,学生,需在试卷已提交,且已截止的情况下看 ex_object_score = ex_user.objective_score < 0.0 ? 0.0 : ex_user.objective_score.round(1).to_s ex_subject_score = ex_user.subjective_score < 0.0 ? nil : ex_user.subjective_score.round(1).to_s score = ex_user.score.present? ? ex_user.score.round(1).to_s : 0.0.to_s + else + ex_object_score = nil + ex_subject_score = nil + score = nil end { From 4122ccf438accbacf156baf67012c98f2041e37a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 10:48:23 +0800 Subject: [PATCH 0344/1015] fix bug --- app/helpers/exercises_helper.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index fd2877cc8..8db7e8bfa 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -638,6 +638,9 @@ module ExercisesHelper if student_status == 2 #当前为老师,或为学生且已提交 user_score = exercise_answers.score_reviewed.pluck(:score).sum end + if user_score > q.question_score + user_score = q.question_score + end if ques_type <= 2 answered_content = exercise_answers.pluck(:exercise_choice_id) elsif ques_type == 3 From 76028ceca5e290dd7a620176189d6c673bd1a7cb Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 10:59:31 +0800 Subject: [PATCH 0345/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E5=8F=91=E9=80=81=E8=87=B3=E5=8A=9F=E8=83=BD=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/subjects_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 4b954584b..c73fec500 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -164,8 +164,8 @@ class SubjectsController < ApplicationController end def choose_course - course_ids = Course.find_by_sql("SELECT c.id FROM courses c, members m, member_roles mr - WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9) + course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m + WHERE m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0").map(&:id) @courses = Course.where(id: course_ids) @none_shixun_ids = ShixunSchool.where("school_id != #{current_user.user_extension.try(:school_id)}").pluck(:shixun_id) From 6f900946d79d9cf912431b02fcc66d4eeaf89680 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 11:08:15 +0800 Subject: [PATCH 0346/1015] =?UTF-8?q?=E6=90=9C=E7=B4=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index e3a658d7c..5f7c13964 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -622,7 +622,6 @@ class ShixunsController < ApplicationController end def add_collaborators - raise("搜索内容不能为空") unless params[:search] member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")" user_name = "%#{params[:user_name].strip}%" school_name = "%#{params[:school_name].strip}%" From 2a010194578c773162e856a6812ea74adb83b667 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 12:23:10 +0800 Subject: [PATCH 0347/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/exercise.rb | 13 ++++++++++--- app/models/exercise_answer.rb | 8 +++++++- app/models/exercise_choice.rb | 11 +++++++++-- app/models/exercise_question.rb | 10 ++++++++-- app/models/exercise_shixun_answer.rb | 7 ++++++- 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 0c8b97ca7..af84a5c49 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -3,9 +3,9 @@ class Exercise < ApplicationRecord belongs_to :exercise_bank, optional: true belongs_to :user - has_many :exercise_users,:dependent => :destroy - has_many :exercise_questions,:dependent => :destroy - has_many :exercise_group_settings,:dependent => :destroy + has_many :exercise_users + has_many :exercise_questions + has_many :exercise_group_settings has_many :tidings, as: :container has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :destroy @@ -19,6 +19,13 @@ class Exercise < ApplicationRecord validates :exercise_name, length: { maximum: 60, too_long: "60 characters is the maximum allowed" } after_create :create_exercise_list + after_destroy :destroy_other_relations + + def destroy_other_relations + exercise_users.destroy_all + exercise_questions.destroy_all + exercise_group_settings.destroy_all + end def create_exercise_list str = "" diff --git a/app/models/exercise_answer.rb b/app/models/exercise_answer.rb index 465fa036b..96fbe17bb 100644 --- a/app/models/exercise_answer.rb +++ b/app/models/exercise_answer.rb @@ -3,7 +3,7 @@ class ExerciseAnswer < ApplicationRecord belongs_to :user belongs_to :exercise_question belongs_to :exercise_choice, optional: true - has_many :exercise_answer_comments, :dependent => :destroy + has_many :exercise_answer_comments scope :search_exercise_answer, lambda { |name,key| where("#{name} = ?",key)} scope :search_answer_users, lambda {|name,ids| where("#{name}":ids)} @@ -11,4 +11,10 @@ class ExerciseAnswer < ApplicationRecord scope :exercise_answer_is_right, -> {where("score > ?",0.0)} #判断答案是否正确,根据分数总和大于0 scope :score_reviewed, lambda {where("score >= ?",0.0)} #是否评分,用于判断主观题的 + after_destroy :destroy_answers_relations + + def destroy_answers_relations + exercise_answer_comments.destroy_all + end + end \ No newline at end of file diff --git a/app/models/exercise_choice.rb b/app/models/exercise_choice.rb index 525251ce6..f4f5c5a16 100644 --- a/app/models/exercise_choice.rb +++ b/app/models/exercise_choice.rb @@ -1,9 +1,16 @@ class ExerciseChoice < ApplicationRecord belongs_to :exercise_question - has_many :exercise_answers, :dependent => :destroy - has_many :exercise_standard_answers, :dependent => :destroy + has_many :exercise_answers + has_many :exercise_standard_answers scope :find_choice_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :left_choice_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 + + after_destroy :destroy_choices_relations + + def destroy_choices_relations + exercise_answers.destroy_all + exercise_standard_answers.destroy_all + end end \ No newline at end of file diff --git a/app/models/exercise_question.rb b/app/models/exercise_question.rb index 607ad1a29..c236b657c 100644 --- a/app/models/exercise_question.rb +++ b/app/models/exercise_question.rb @@ -4,9 +4,9 @@ class ExerciseQuestion < ApplicationRecord belongs_to :exercise belongs_to :shixun, optional: true - has_many :exercise_choices, :dependent => :destroy + has_many :exercise_choices has_many :exercise_answers - has_many :exercise_shixun_challenges,:dependent => :destroy + has_many :exercise_shixun_challenges has_many :exercise_shixun_answers has_many :exercise_answer_comments has_many :exercise_standard_answers @@ -17,6 +17,12 @@ class ExerciseQuestion < ApplicationRecord scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题 # scope :next_exercise, lambda {|k| where("question_number > ?",k).first} # scope :last_exercise, lambda {|k| where("question_number < ?",k).last} + after_destroy :destroy_questions_relations + + def destroy_questions_relations + exercise_choices.destroy_all + exercise_shixun_challenges.destroy_all + end def question_type_name case self.question_type diff --git a/app/models/exercise_shixun_answer.rb b/app/models/exercise_shixun_answer.rb index 8548e497d..72a6999d6 100644 --- a/app/models/exercise_shixun_answer.rb +++ b/app/models/exercise_shixun_answer.rb @@ -2,7 +2,7 @@ class ExerciseShixunAnswer < ApplicationRecord belongs_to :exercise_question belongs_to :user belongs_to :exercise_shixun_challenge - has_many :exercise_answer_comments, :dependent => :destroy + has_many :exercise_answer_comments # status 0: 未通过, 1:通过 # attr_accessible :answer_text, :score, :status scope :search_shixun_answers, lambda {|name,ids| where("#{name}":ids)} @@ -10,4 +10,9 @@ class ExerciseShixunAnswer < ApplicationRecord scope :shixun_no_full_scores, lambda { |score| where("score > 0.0 AND score < ?",score)} scope :score_reviewed, lambda {where("score is not NULL AND score >= ?",0.0)} #是否评分 + after_destroy :destroy_shixun_relations + + def destroy_shixun_relations + exercise_answer_comments.destroy_all + end end From 7a007dbd44315ea14fe384b50dedb1f6212f6404 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 12:38:32 +0800 Subject: [PATCH 0348/1015] fix bug --- app/models/exercise.rb | 15 ++++----------- app/models/exercise_answer.rb | 8 +------- app/models/exercise_choice.rb | 10 ++-------- app/models/exercise_question.rb | 11 ++--------- app/models/exercise_shixun_answer.rb | 7 +------ 5 files changed, 10 insertions(+), 41 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index af84a5c49..60409e51d 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -3,11 +3,11 @@ class Exercise < ApplicationRecord belongs_to :exercise_bank, optional: true belongs_to :user - has_many :exercise_users - has_many :exercise_questions - has_many :exercise_group_settings + has_many :exercise_users, :dependent => :delete_all + has_many :exercise_questions, :dependent => :delete_all + has_many :exercise_group_settings, :dependent => :delete_all has_many :tidings, as: :container - has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :destroy + has_many :course_acts, class_name: 'CourseActivity', as: :course_act, :dependent => :delete_all scope :is_exercise_published, -> { where("exercise_status > ? ",1)} scope :unified_setting, -> { where("unified_setting = ?",true) } @@ -19,13 +19,6 @@ class Exercise < ApplicationRecord validates :exercise_name, length: { maximum: 60, too_long: "60 characters is the maximum allowed" } after_create :create_exercise_list - after_destroy :destroy_other_relations - - def destroy_other_relations - exercise_users.destroy_all - exercise_questions.destroy_all - exercise_group_settings.destroy_all - end def create_exercise_list str = "" diff --git a/app/models/exercise_answer.rb b/app/models/exercise_answer.rb index 96fbe17bb..11558f937 100644 --- a/app/models/exercise_answer.rb +++ b/app/models/exercise_answer.rb @@ -3,7 +3,7 @@ class ExerciseAnswer < ApplicationRecord belongs_to :user belongs_to :exercise_question belongs_to :exercise_choice, optional: true - has_many :exercise_answer_comments + has_many :exercise_answer_comments, :dependent => :delete_all scope :search_exercise_answer, lambda { |name,key| where("#{name} = ?",key)} scope :search_answer_users, lambda {|name,ids| where("#{name}":ids)} @@ -11,10 +11,4 @@ class ExerciseAnswer < ApplicationRecord scope :exercise_answer_is_right, -> {where("score > ?",0.0)} #判断答案是否正确,根据分数总和大于0 scope :score_reviewed, lambda {where("score >= ?",0.0)} #是否评分,用于判断主观题的 - after_destroy :destroy_answers_relations - - def destroy_answers_relations - exercise_answer_comments.destroy_all - end - end \ No newline at end of file diff --git a/app/models/exercise_choice.rb b/app/models/exercise_choice.rb index f4f5c5a16..72dc30c9d 100644 --- a/app/models/exercise_choice.rb +++ b/app/models/exercise_choice.rb @@ -1,16 +1,10 @@ class ExerciseChoice < ApplicationRecord belongs_to :exercise_question - has_many :exercise_answers - has_many :exercise_standard_answers + has_many :exercise_answers, :dependent => :delete_all + has_many :exercise_standard_answers, :dependent => :delete_all scope :find_choice_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :left_choice_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 - after_destroy :destroy_choices_relations - - def destroy_choices_relations - exercise_answers.destroy_all - exercise_standard_answers.destroy_all - end end \ No newline at end of file diff --git a/app/models/exercise_question.rb b/app/models/exercise_question.rb index c236b657c..2c9b281c3 100644 --- a/app/models/exercise_question.rb +++ b/app/models/exercise_question.rb @@ -4,9 +4,9 @@ class ExerciseQuestion < ApplicationRecord belongs_to :exercise belongs_to :shixun, optional: true - has_many :exercise_choices + has_many :exercise_choices, :dependent => :delete_all has_many :exercise_answers - has_many :exercise_shixun_challenges + has_many :exercise_shixun_challenges, :dependent => :delete_all has_many :exercise_shixun_answers has_many :exercise_answer_comments has_many :exercise_standard_answers @@ -15,14 +15,7 @@ class ExerciseQuestion < ApplicationRecord scope :find_by_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题 scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题 - # scope :next_exercise, lambda {|k| where("question_number > ?",k).first} - # scope :last_exercise, lambda {|k| where("question_number < ?",k).last} - after_destroy :destroy_questions_relations - def destroy_questions_relations - exercise_choices.destroy_all - exercise_shixun_challenges.destroy_all - end def question_type_name case self.question_type diff --git a/app/models/exercise_shixun_answer.rb b/app/models/exercise_shixun_answer.rb index 72a6999d6..a9550c024 100644 --- a/app/models/exercise_shixun_answer.rb +++ b/app/models/exercise_shixun_answer.rb @@ -2,7 +2,7 @@ class ExerciseShixunAnswer < ApplicationRecord belongs_to :exercise_question belongs_to :user belongs_to :exercise_shixun_challenge - has_many :exercise_answer_comments + has_many :exercise_answer_comments, :dependent => :delete_all # status 0: 未通过, 1:通过 # attr_accessible :answer_text, :score, :status scope :search_shixun_answers, lambda {|name,ids| where("#{name}":ids)} @@ -10,9 +10,4 @@ class ExerciseShixunAnswer < ApplicationRecord scope :shixun_no_full_scores, lambda { |score| where("score > 0.0 AND score < ?",score)} scope :score_reviewed, lambda {where("score is not NULL AND score >= ?",0.0)} #是否评分 - after_destroy :destroy_shixun_relations - - def destroy_shixun_relations - exercise_answer_comments.destroy_all - end end From e233d90197bc70ef7775c364f3bdb13e2c6673a1 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 12:48:41 +0800 Subject: [PATCH 0349/1015] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=95=E5=8D=B7?= =?UTF-8?q?=E5=92=8C=E9=97=AE=E5=8D=B7=E5=88=A0=E9=99=A4=E5=85=B3=E8=81=94?= =?UTF-8?q?=E4=B8=BAdelete=5Fall?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/poll.rb | 10 +++++----- app/models/poll_answer.rb | 2 +- app/models/poll_question.rb | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/poll.rb b/app/models/poll.rb index 1cead3291..f72239ba7 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -4,13 +4,13 @@ class Poll < ApplicationRecord belongs_to :exercise_bank, optional: true # belongs_to :exercise_bank - has_many :poll_questions,dependent: :destroy - has_many :poll_users, :dependent => :destroy + has_many :poll_questions,dependent: :delete_all + has_many :poll_users, :dependent => :delete_all has_many :users, :through => :poll_users #该文件被哪些用户提交答案过 - has_many :poll_group_settings, :dependent => :destroy - has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :destroy + has_many :poll_group_settings, :dependent => :delete_all + has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :delete_all - has_many :tidings, as: :container, dependent: :destroy + has_many :tidings, as: :container, dependent: :delete_all scope :publish_or_not, -> { where("polls_status > ? ",1)} scope :only_public, -> {where("is_public = ?",true)} diff --git a/app/models/poll_answer.rb b/app/models/poll_answer.rb index 423198bbf..8e2421328 100644 --- a/app/models/poll_answer.rb +++ b/app/models/poll_answer.rb @@ -3,7 +3,7 @@ class PollAnswer < ApplicationRecord # include Redmine::SafeAttributes belongs_to :poll_question - has_many :poll_votes, :dependent => :destroy + has_many :poll_votes, :dependent => :delete_all scope :find_answer_by_custom, lambda {|k,v| where("#{k}":v)} #根据传入的参数查找问题 scope :left_answer_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题 diff --git a/app/models/poll_question.rb b/app/models/poll_question.rb index 1fc8e0c16..a0854aa48 100644 --- a/app/models/poll_question.rb +++ b/app/models/poll_question.rb @@ -1,9 +1,9 @@ class PollQuestion < ApplicationRecord belongs_to :poll - has_many :poll_answers, :dependent => :destroy + has_many :poll_answers, :dependent => :delete_all attr_accessor :question_answers, :question_other_anser - has_many :poll_votes, :dependent => :destroy + has_many :poll_votes scope :ques_count, lambda {|k| where("question_type = ?",k)} scope :ques_necessary, -> {where("is_necessary = ?",1)} From d183334d919a1b5e6188041d7271c59b240e7e47 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 28 Jun 2019 13:57:09 +0800 Subject: [PATCH 0350/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 7 +++-- app/models/challenge.rb | 40 +++++++++++++++--------- app/views/challenges/index.json.jbuilder | 2 +- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index f2a964c8d..bce0ae3c2 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -149,7 +149,11 @@ class ChallengesController < ApplicationController def index uid_logger("identifier: #{params}") # 通过调试发现 这里includes(:games)性能会慢10倍 - @challenges = @shixun.challenges.fields_for_list + # @challenges = @shixun.challenges.fields_for_list + @challenges = Challenge.fields_for_list.includes(:games).where("challenges.shixun_id" => @shixun.id) + + # @challenges = Challenge.includes(:games).where("games.user_id" => 12).where(shixun_id: @shixun.id) + @editable = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0 @user = current_user end @@ -247,7 +251,6 @@ class ChallengesController < ApplicationController # 关卡位置被修改,需要修改脚本 script = modify_shixun_script @shixun, @shixun.evaluate_script @shixun.update_column(:evaluate_script, script) - end def index_up diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 5495dd7a3..f25ce330a 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -51,9 +51,8 @@ class Challenge < ApplicationRecord end # 开启挑战 - def open_game(user_id) - game = self.games.select([:status, :identifier]).where(user_id: user_id).first - shixun = self.shixun + def open_game user_id, challenge_id, shixun + game = games.select{|game| game.challenge_id = challenge_id && game.user_id == user_id}.first if game.present? shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : "" else @@ -61,18 +60,31 @@ class Challenge < ApplicationRecord end end + # # 开启挑战 + # def open_game(user_id, shixun) + # + # + # game = self.games.select([:status, :identifier]).where(user_id: user_id).first + # game = self.games.select{|game| game.user_id == user_id} + # if game.present? + # shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : "" + # else + # "/api/shixuns/#{shixun.identifier}/shixun_exec" + # end + # end + ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成 def user_tpi_status user_id # todo: 以前没加索引导致相同关卡,同一用户有多个games - game = self.games.where(user_id: user_id).last - status = - if game.blank? - self.position == 1 ? 1 : 0 - elsif game.status == 2 - 2 - else - 1 - end + game = games.select{|game| game.user_id == user_id }.last + + if game.blank? + self.position == 1 ? 1 : 0 + elsif game.status == 2 + 2 + else + 1 + end end ## 选择题答案 @@ -85,12 +97,12 @@ class Challenge < ApplicationRecord # 关卡用户通关数 def user_passed_count - games.where(status: 2).count + games.select{|game| game.status == 2}.size end # 关卡用户正在挑战的人数 def playing_count - games.where(status: [0, 1]).count + games.select{|game| game.status == 0 || game.status == 1}.size end def last_challenge diff --git a/app/views/challenges/index.json.jbuilder b/app/views/challenges/index.json.jbuilder index 0b90b5ca5..dc122b8c4 100644 --- a/app/views/challenges/index.json.jbuilder +++ b/app/views/challenges/index.json.jbuilder @@ -17,7 +17,7 @@ if @challenges.present? json.passed_count challenge.user_passed_count json.playing_count challenge.playing_count json.name_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) - json.open_game challenge.open_game(@user.id) + json.open_game challenge.open_game(@user.id, challenge.id, @shixun) if @editable json.edit_url edit_shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) json.delete_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) From aa4dfd6190599fdfdbd21d50b37e1e3a6839eb97 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 14:10:09 +0800 Subject: [PATCH 0351/1015] fix bug --- app/helpers/exercises_helper.rb | 10 +++++----- app/views/exercises/start_answer.json.jbuilder | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 8db7e8bfa..cec6dd0ff 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -46,7 +46,7 @@ module ExercisesHelper sub_answer_score = sub_answer.first.score else stand_status = 0 - sub_answer_score = 0.0 + sub_answer_score = nil end sub_score = { @@ -54,7 +54,7 @@ module ExercisesHelper "q_type":s.question_type, "q_position":s.question_number, "stand_status":stand_status, - "user_score":sub_answer_score.round(1).to_s + "user_score":sub_answer_score.present? ? sub_answer_score.round(1).to_s : nil } @ex_sub_array.push(sub_score) end @@ -627,7 +627,7 @@ module ExercisesHelper #学生的分数状态及回答的内容 def user_question_answers(q,ex_answerer_id,student_status,is_teacher_or,ex_status,ques_type,ex_type) answered_content = [] - user_score = 0.0 + user_score = nil shixun_type = 0 question_comment = [] if q.question_type == 5 @@ -638,7 +638,7 @@ module ExercisesHelper if student_status == 2 #当前为老师,或为学生且已提交 user_score = exercise_answers.score_reviewed.pluck(:score).sum end - if user_score > q.question_score + if user_score.present? && (user_score > q.question_score) user_score = q.question_score end if ques_type <= 2 @@ -667,7 +667,7 @@ module ExercisesHelper question_comment = q.exercise_answer_comments.search_answer_comments("exercise_answer_id",q_answer_id) end { - "user_score": user_score.round(1), + "user_score": user_score.present? ? user_score.round(1) : nil, "answered_content":answered_content, "shixun_type":shixun_type, "question_comment":question_comment diff --git a/app/views/exercises/start_answer.json.jbuilder b/app/views/exercises/start_answer.json.jbuilder index 4cc461d56..42d611712 100644 --- a/app/views/exercises/start_answer.json.jbuilder +++ b/app/views/exercises/start_answer.json.jbuilder @@ -40,8 +40,8 @@ json.exercise_questions do question_info = get_exercise_question_info(question,@exercise,@exercise_user_current,@ex_answerer.id) # json.q_position q[:ques_number] #问题的序号,当问题为随机时,重新更新后的问题序号 if @t_user_exercise_status == 3 - this_answer_status = "0.0" - user_score = "0.0" + this_answer_status = 0 + user_score = nil if all_question_status.size > 0 this_ques_status = all_question_status.detect {|f| f[:q_id] == question.id} this_answer_status = this_ques_status[:stand_status] From d1f721b249d86400226c2f91a89390407e01cc62 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 28 Jun 2019 14:12:04 +0800 Subject: [PATCH 0352/1015] left out join --- app/controllers/challenges_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 3782468d4..5503dfe63 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -150,7 +150,7 @@ class ChallengesController < ApplicationController uid_logger("identifier: #{params}") # 通过调试发现 这里includes(:games)性能会慢10倍 # @challenges = @shixun.challenges.fields_for_list - @challenges = Challenge.fields_for_list.includes(:games).where("challenges.shixun_id" => @shixun.id) + @challenges = Challenge.fields_for_list.left_outer_joins(:games).where("challenges.shixun_id" => @shixun.id) # @challenges = Challenge.includes(:games).where("games.user_id" => 12).where(shixun_id: @shixun.id) From c8bfb0b4c1a92f572b601eb68ee2c10001a954e8 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 28 Jun 2019 14:14:23 +0800 Subject: [PATCH 0353/1015] .. --- app/controllers/challenges_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 5503dfe63..b821929d6 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -150,7 +150,7 @@ class ChallengesController < ApplicationController uid_logger("identifier: #{params}") # 通过调试发现 这里includes(:games)性能会慢10倍 # @challenges = @shixun.challenges.fields_for_list - @challenges = Challenge.fields_for_list.left_outer_joins(:games).where("challenges.shixun_id" => @shixun.id) + @challenges = Challenge.fields_for_list.where(shixun_id: @shixun.id) # @challenges = Challenge.includes(:games).where("games.user_id" => 12).where(shixun_id: @shixun.id) From 20fe2ba75c6ef5213f70fdfbd6f3805f721a4b20 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 28 Jun 2019 14:15:39 +0800 Subject: [PATCH 0354/1015] =?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/homework_evaluation.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/homework_evaluation.rake b/lib/tasks/homework_evaluation.rake index d1fad8f14..35d075398 100644 --- a/lib/tasks/homework_evaluation.rake +++ b/lib/tasks/homework_evaluation.rake @@ -24,7 +24,7 @@ namespace :homework_evaluation do student_works = homework_common.student_works.has_committed end - if student_works.size >= 2 + if student_works.count >= 2 HomeworkEvaluationCommentAssginJob.perform_later(homework_common.id) homework_detail_manual.update_column('comment_status', 3) From 732fcaa466a379c39abde30e1195dbdb604c9006 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 28 Jun 2019 14:20:48 +0800 Subject: [PATCH 0355/1015] =?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/homework_evaluation.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/homework_evaluation.rake b/lib/tasks/homework_evaluation.rake index 35d075398..56c46179c 100644 --- a/lib/tasks/homework_evaluation.rake +++ b/lib/tasks/homework_evaluation.rake @@ -24,7 +24,7 @@ namespace :homework_evaluation do student_works = homework_common.student_works.has_committed end - if student_works.count >= 2 + if student_works.present? && student_works.length >= 2 HomeworkEvaluationCommentAssginJob.perform_later(homework_common.id) homework_detail_manual.update_column('comment_status', 3) From b51c899cb558e79d13721b0e1771a1b1267d2922 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 28 Jun 2019 14:22:30 +0800 Subject: [PATCH 0356/1015] =?UTF-8?q?challenge=20index=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/challenge.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/challenge.rb b/app/models/challenge.rb index f25ce330a..9bfb89b4b 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -97,12 +97,12 @@ class Challenge < ApplicationRecord # 关卡用户通关数 def user_passed_count - games.select{|game| game.status == 2}.size + games.where(status: 2).count end # 关卡用户正在挑战的人数 def playing_count - games.select{|game| game.status == 0 || game.status == 1}.size + games.where(status: [0, 1]).count end def last_challenge From bc61bbbe05ef0101ae4a7bea8c5bbc1633b18d7e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 14:26:39 +0800 Subject: [PATCH 0357/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E7=9A=84=E5=85=B3?= =?UTF-8?q?=E5=8D=A1=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 7 +++++++ app/controllers/challenges_controller.rb | 11 ++++++++--- app/controllers/shixuns_controller.rb | 9 +++------ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4a9220939..afe2129a9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -23,6 +23,13 @@ class ApplicationController < ActionController::Base EduSetting.get(name) end + # 实训的访问权限 + def shixun_access_allowed + if !current_user.shixun_permission(@shixun) + tip_exception(403, "..") + end + end + def user_course_identity @user_course_identity = current_user.course_identity(@course) if @user_course_identity > Course::STUDENT && @course.is_public == 0 diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index b821929d6..8550c20ce 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -5,8 +5,10 @@ class ChallengesController < ApplicationController before_action :find_challenge, only: [:edit, :show, :update, :create_choose_question, :index_down, :index_up, :edit_choose_question, :show_choose_question, :destroy_challenge_choose, :update_choose_question, :destroy, :crud_answer, :answer] - # 权限控制 - before_action :allowed, except: [:index] + # 关卡更新和操作的权限控制 + before_action :update_allowed, except: [:index] + # 关卡访问的权限控制 + before_action :shixun_access_allowed include ShixunsHelper include ChallengesHelper @@ -279,6 +281,9 @@ class ChallengesController < ApplicationController def find_shixun @shixun = Shixun.find_by_identifier(params[:shixun_identifier]) + if !current_user.shixun_permission(@shixun) + tip_exception(403, "..") + end end # 通用接口 @@ -298,7 +303,7 @@ class ChallengesController < ApplicationController :standard_answer, :score, :difficult) end - def allowed + def update_allowed unless current_user.manager_of_shixun?(@shixun) raise Educoder::TipException.new(403, "..") end diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 5f7c13964..0cf4fc77e 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -2,8 +2,9 @@ class ShixunsController < ApplicationController before_action :require_login, except: [:download_file, :index, :menus] before_action :check_auth, except: [:download_file, :index] - before_action :find_shixun, except: [:index, :new, :create, :menus, :get_recommend_shixuns, :propaedeutics, - :departments, :apply_shixun_mirror, :get_mirror_script, :download_file] + before_action :find_shixun, :shixun_access_allowed, except: [:index, :new, :create, :menus, :get_recommend_shixuns, + :propaedeutics, :departments, :apply_shixun_mirror, + :get_mirror_script, :download_file] before_action :find_repo_name, only: [:repository, :commits, :file_content, :update_file, :shixun_exec, :copy] before_action :allowed, only: [:update, :close, :update_propaedeutics, :settings, :publish, @@ -726,10 +727,6 @@ private normal_status(404, "...") return end - - if !current_user.shixun_permission(@shixun) - tip_exception(403, "..") - end end def find_repo_name From 79eb49c7506e85cb73e4b253c370cfb158dc6ed0 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 14:26:46 +0800 Subject: [PATCH 0358/1015] fix bug --- app/views/exercises/_user_exercise_info.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/exercises/_user_exercise_info.json.jbuilder b/app/views/exercises/_user_exercise_info.json.jbuilder index 5b5d0c725..cc10f5bb7 100644 --- a/app/views/exercises/_user_exercise_info.json.jbuilder +++ b/app/views/exercises/_user_exercise_info.json.jbuilder @@ -54,7 +54,7 @@ json.exercise_questions do this_ques_status = all_question_status.detect {|f| f[:q_id] == q.id} json.answer_status this_ques_status[:stand_status] end - json.user_score user_ques_answers[:user_score].to_s + json.user_score user_ques_answers[:user_score].present? ? user_ques_answers[:user_score].to_s : nil json.partial! "exercise_questions/exercise_questions", question: q, ex_answerer: ex_answerer, From cc3687df2f895705fc6d19c027ec3f4b0d294aa8 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 28 Jun 2019 14:28:17 +0800 Subject: [PATCH 0359/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E5=BC=80=E5=90=AF?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/challenge.rb | 4 ++-- app/views/challenges/index.json.jbuilder | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 9bfb89b4b..434812234 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -51,8 +51,8 @@ class Challenge < ApplicationRecord end # 开启挑战 - def open_game user_id, challenge_id, shixun - game = games.select{|game| game.challenge_id = challenge_id && game.user_id == user_id}.first + def open_game user_id, shixun + game = self.games.select([:status, :identifier]).where(user_id: user_id).first if game.present? shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : "" else diff --git a/app/views/challenges/index.json.jbuilder b/app/views/challenges/index.json.jbuilder index dc122b8c4..6b92be411 100644 --- a/app/views/challenges/index.json.jbuilder +++ b/app/views/challenges/index.json.jbuilder @@ -17,7 +17,7 @@ if @challenges.present? json.passed_count challenge.user_passed_count json.playing_count challenge.playing_count json.name_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) - json.open_game challenge.open_game(@user.id, challenge.id, @shixun) + json.open_game challenge.open_game(@user.id, @shixun) if @editable json.edit_url edit_shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) json.delete_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) From c7c39f46311e31782798411b3a10a1319ce64587 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 28 Jun 2019 14:31:50 +0800 Subject: [PATCH 0360/1015] =?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/jobs/homework_evaluation_comment_assgin_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/homework_evaluation_comment_assgin_job.rb b/app/jobs/homework_evaluation_comment_assgin_job.rb index 2579ea18b..5921386f2 100644 --- a/app/jobs/homework_evaluation_comment_assgin_job.rb +++ b/app/jobs/homework_evaluation_comment_assgin_job.rb @@ -16,7 +16,7 @@ class HomeworkEvaluationCommentAssginJob < ApplicationJob student_work_projects = homework_common.student_works.where("work_status != 0").shuffle student_work_projects.each do |pro_work| n = homework_detail_manual.evaluation_num - n = (n < student_works.size && n != -1) ? n : student_works.size - 1 + n = (n < student_works.length && n != -1) ? n : student_works.length - 1 work_index = -1 student_works.each_with_index do |stu_work, stu_index| if stu_work.group_id.to_i == pro_work.group_id.to_i From 58259feb483d04a03a979f467ce6c3ee81b1068e Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 28 Jun 2019 14:36:18 +0800 Subject: [PATCH 0361/1015] =?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/models/homework_common.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index c0882ec6f..6512c3f1d 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -170,7 +170,7 @@ class HomeworkCommon < ApplicationRecord #删除时更新题库中的引用数 def update_homework_bank_quotes old_bank = self.homework_bank - old_bank.update_attributes(quotes: (old_bank.quotes - 1) > 0 ? (old_bank.quotes - 1) : 0, homework_common_id: nil) + old_bank.update_attributes(quotes: (old_bank.quotes - 1) > 0 ? (old_bank.quotes - 1) : 0, homework_common_id: nil) if old_bank.present? end # 查重是否有新结果 From 68637a2464764546f8f3136a45c3f799fecd5723 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 14:48:08 +0800 Subject: [PATCH 0362/1015] fix bug --- app/helpers/exercises_helper.rb | 8 +++++--- app/views/exercises/_user_exercise_info.json.jbuilder | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index cec6dd0ff..3595b5866 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -630,14 +630,16 @@ module ExercisesHelper user_score = nil shixun_type = 0 question_comment = [] - if q.question_type == 5 + if ques_type == 5 exercise_answers = q.exercise_shixun_answers.search_shixun_answers("user_id",ex_answerer_id) else exercise_answers = q.exercise_answers.search_exercise_answer("user_id",ex_answerer_id) #试卷用户的回答 end if student_status == 2 #当前为老师,或为学生且已提交 - user_score = exercise_answers.score_reviewed.pluck(:score).sum + user_score_pre = exercise_answers.score_reviewed.pluck(:score).sum + user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : nil end + if user_score.present? && (user_score > q.question_score) user_score = q.question_score end @@ -667,7 +669,7 @@ module ExercisesHelper question_comment = q.exercise_answer_comments.search_answer_comments("exercise_answer_id",q_answer_id) end { - "user_score": user_score.present? ? user_score.round(1) : nil, + "user_score": (user_score.present? ? user_score.round(1).to_s : nil), "answered_content":answered_content, "shixun_type":shixun_type, "question_comment":question_comment diff --git a/app/views/exercises/_user_exercise_info.json.jbuilder b/app/views/exercises/_user_exercise_info.json.jbuilder index cc10f5bb7..1ff929897 100644 --- a/app/views/exercises/_user_exercise_info.json.jbuilder +++ b/app/views/exercises/_user_exercise_info.json.jbuilder @@ -47,14 +47,13 @@ end json.exercise_questions do json.array! exercise_questions do |q| - user_ques_answers = user_question_answers(q,ex_answerer.id,student_status,is_teacher_or,exercise_status,q.question_type,ex_type) user_ques_comments = user_ques_answers[:question_comment] if all_question_status.size > 0 this_ques_status = all_question_status.detect {|f| f[:q_id] == q.id} json.answer_status this_ques_status[:stand_status] end - json.user_score user_ques_answers[:user_score].present? ? user_ques_answers[:user_score].to_s : nil + json.user_score user_ques_answers[:user_score] json.partial! "exercise_questions/exercise_questions", question: q, ex_answerer: ex_answerer, From 584d9bd53ab208c2e6afae0451b789e6b7da70c2 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 28 Jun 2019 14:49:00 +0800 Subject: [PATCH 0363/1015] =?UTF-8?q?=E5=85=B3=E5=8D=A1=E9=80=9A=E5=85=B3?= =?UTF-8?q?=E6=83=85=E5=86=B5=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 4 +--- app/models/challenge.rb | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 8550c20ce..565545713 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -151,10 +151,8 @@ class ChallengesController < ApplicationController def index uid_logger("identifier: #{params}") # 通过调试发现 这里includes(:games)性能会慢10倍 - # @challenges = @shixun.challenges.fields_for_list - @challenges = Challenge.fields_for_list.where(shixun_id: @shixun.id) - # @challenges = Challenge.includes(:games).where("games.user_id" => 12).where(shixun_id: @shixun.id) + @challenges = @shixun.challenges.fields_for_list.includes(:games).where("games.user_id" => current_user.id) @editable = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0 @user = current_user diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 434812234..07a49196d 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -52,7 +52,7 @@ class Challenge < ApplicationRecord # 开启挑战 def open_game user_id, shixun - game = self.games.select([:status, :identifier]).where(user_id: user_id).first + game = self.games.first if game.present? shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : "" else @@ -76,7 +76,7 @@ class Challenge < ApplicationRecord ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成 def user_tpi_status user_id # todo: 以前没加索引导致相同关卡,同一用户有多个games - game = games.select{|game| game.user_id == user_id }.last + game = games.last if game.blank? self.position == 1 ? 1 : 0 From 0576924ab636945a1047e6ecfc2f0d8bd393495b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 14:49:42 +0800 Subject: [PATCH 0364/1015] fix bug --- app/helpers/exercises_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 3595b5866..a2a80c311 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -636,7 +636,7 @@ module ExercisesHelper exercise_answers = q.exercise_answers.search_exercise_answer("user_id",ex_answerer_id) #试卷用户的回答 end if student_status == 2 #当前为老师,或为学生且已提交 - user_score_pre = exercise_answers.score_reviewed.pluck(:score).sum + user_score_pre = exercise_answers.score_reviewed user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : nil end From 54196a44c5d36fb22b40023a1b6e04f47ebfaa62 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 15:07:36 +0800 Subject: [PATCH 0365/1015] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=88=E4=BD=9C?= =?UTF-8?q?=E8=80=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 2 +- app/controllers/shixuns_controller.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 565545713..2ba76c60a 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -8,7 +8,7 @@ class ChallengesController < ApplicationController # 关卡更新和操作的权限控制 before_action :update_allowed, except: [:index] # 关卡访问的权限控制 - before_action :shixun_access_allowed + before_action :shixun_access_allowed, only: [:index] include ShixunsHelper include ChallengesHelper diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 0cf4fc77e..52e05e57d 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -624,12 +624,12 @@ class ShixunsController < ApplicationController def add_collaborators member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")" - user_name = "%#{params[:user_name].strip}%" - school_name = "%#{params[:school_name].strip}%" + user_name = "%#{params[:user_name].to_s.strip}%" + school_name = "%#{params[:school_name].to_s.strip}%" if user_name.present? || school_name.present? @users = User.joins(user_extension: :school).where("users.id not in #{member_ids} AND users.status = 1 AND LOWER(users.lastname) LIKE '#{user_name}' AND LOWER(schools.name) LIKE - '#{school_name}'") + '#{school_name}'").limit(20) else @users = User.none end From 4efa98153fe89cf82c46cde024a0d83585c01490 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 15:09:40 +0800 Subject: [PATCH 0366/1015] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=88=E4=BD=9C?= =?UTF-8?q?=E8=80=85=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 52e05e57d..234983932 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -627,9 +627,11 @@ class ShixunsController < ApplicationController user_name = "%#{params[:user_name].to_s.strip}%" school_name = "%#{params[:school_name].to_s.strip}%" if user_name.present? || school_name.present? + page = params[:page] || 1 + limit = params[:limit] || 20 @users = User.joins(user_extension: :school).where("users.id not in #{member_ids} AND users.status = 1 AND LOWER(users.lastname) LIKE '#{user_name}' AND LOWER(schools.name) LIKE - '#{school_name}'").limit(20) + '#{school_name}'").page(page).per(limit) else @users = User.none end From cd87ea9b5a95c085e8cbdea5b72fefd6d4aa7f66 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 15:11:45 +0800 Subject: [PATCH 0367/1015] =?UTF-8?q?=E5=8E=BB=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 234983932..df6de775a 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -631,7 +631,7 @@ class ShixunsController < ApplicationController limit = params[:limit] || 20 @users = User.joins(user_extension: :school).where("users.id not in #{member_ids} AND users.status = 1 AND LOWER(users.lastname) LIKE '#{user_name}' AND LOWER(schools.name) LIKE - '#{school_name}'").page(page).per(limit) + '#{school_name}'").distinct.page(page).per(limit) else @users = User.none end From 250888abc58fcf60f0c66fe9f7097d13523ee419 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 15:15:58 +0800 Subject: [PATCH 0368/1015] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=88=E4=BD=9C?= =?UTF-8?q?=E8=80=85=E7=BF=BB=E9=A1=B5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 27 ++++++++++--------- .../shixuns/add_collaborators.json.jbuilder | 5 ++-- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index df6de775a..32a2c6ef9 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -623,19 +623,22 @@ class ShixunsController < ApplicationController end def add_collaborators - member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")" - user_name = "%#{params[:user_name].to_s.strip}%" - school_name = "%#{params[:school_name].to_s.strip}%" - if user_name.present? || school_name.present? - page = params[:page] || 1 - limit = params[:limit] || 20 - @users = User.joins(user_extension: :school).where("users.id not in #{member_ids} AND users.status = 1 AND + member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")" + user_name = "%#{params[:user_name].to_s.strip}%" + school_name = "%#{params[:school_name].to_s.strip}%" + if user_name.present? || school_name.present? + @users = User.joins(user_extension: :school).where("users.id not in #{member_ids} AND users.status = 1 AND LOWER(users.lastname) LIKE '#{user_name}' AND LOWER(schools.name) LIKE - '#{school_name}'").distinct.page(page).per(limit) - else - @users = User.none - end - end + '#{school_name}'") + else + @users = User.none + end + page = params[:page] || 1 + limit = params[:limit] || 20 + @users_count = @users.count + @users = @users.page(page).per(limit) + + end def shixun_members_added raise("user_ids 不能为空!") if params[:user_ids].blank? diff --git a/app/views/shixuns/add_collaborators.json.jbuilder b/app/views/shixuns/add_collaborators.json.jbuilder index ab4716681..e77fd41a0 100644 --- a/app/views/shixuns/add_collaborators.json.jbuilder +++ b/app/views/shixuns/add_collaborators.json.jbuilder @@ -2,6 +2,7 @@ json.array! @users do |user| json.user_id user.id json.identify user.identity - json.nickname user.nickname + json.nickname user.real_name json.school_name user.school_name -end \ No newline at end of file +end +json.user_count @users_count \ No newline at end of file From 796f9a97f0a07c834a63c525a195906cbd090fb2 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 15:18:28 +0800 Subject: [PATCH 0369/1015] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=88=E4=BD=9C?= =?UTF-8?q?=E8=80=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shixuns/add_collaborators.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shixuns/add_collaborators.json.jbuilder b/app/views/shixuns/add_collaborators.json.jbuilder index e77fd41a0..3fc341b69 100644 --- a/app/views/shixuns/add_collaborators.json.jbuilder +++ b/app/views/shixuns/add_collaborators.json.jbuilder @@ -1,8 +1,8 @@ #json.partial! "users/users_list", users: @users +json.user_count @users_count json.array! @users do |user| json.user_id user.id json.identify user.identity json.nickname user.real_name json.school_name user.school_name end -json.user_count @users_count \ No newline at end of file From c145345c4dca841462a136175369a429030ecf86 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 15:22:01 +0800 Subject: [PATCH 0370/1015] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=88=E4=BD=9C?= =?UTF-8?q?=E8=80=85=E7=9C=9F=E5=AE=9E=E5=A7=93=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shixuns/add_collaborators.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shixuns/add_collaborators.json.jbuilder b/app/views/shixuns/add_collaborators.json.jbuilder index 3fc341b69..1264caafa 100644 --- a/app/views/shixuns/add_collaborators.json.jbuilder +++ b/app/views/shixuns/add_collaborators.json.jbuilder @@ -3,6 +3,6 @@ json.user_count @users_count json.array! @users do |user| json.user_id user.id json.identify user.identity - json.nickname user.real_name + json.nickname user.lastname json.school_name user.school_name end From 7487bc1c0c3b951ab94d2dfb806f92ab91b4d790 Mon Sep 17 00:00:00 2001 From: jasder Date: Fri, 28 Jun 2019 15:22:03 +0800 Subject: [PATCH 0371/1015] =?UTF-8?q?ADD=20=E9=80=89=E7=94=A8=E7=9A=84?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E9=87=8C=E7=AB=8B=E9=A9=AC=E5=8F=91=E5=B8=83?= 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 0e00dcc66..7e150c44c 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -180,6 +180,8 @@ class FilesController < ApplicationController attach_copied_obj.created_on = Time.now attach_copied_obj.author = current_user attach_copied_obj.is_public = 0 + attach_copied_obj.is_publish = 1 + attach_copied_obj.publish_time = Time.now attach_copied_obj.course_second_category_id = course_second_category_id attach_copied_obj.copy_from = ori.copy_from.nil? ? ori.id : ori.copy_from if attach_copied_obj.attachtype == nil From 7e02210ab8807634dbac5d08816e1291a50f7503 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 15:26:11 +0800 Subject: [PATCH 0372/1015] =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shixuns/add_collaborators.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shixuns/add_collaborators.json.jbuilder b/app/views/shixuns/add_collaborators.json.jbuilder index 1264caafa..7bac0c24c 100644 --- a/app/views/shixuns/add_collaborators.json.jbuilder +++ b/app/views/shixuns/add_collaborators.json.jbuilder @@ -1,5 +1,5 @@ #json.partial! "users/users_list", users: @users -json.user_count @users_count +#json.users_count @users_count json.array! @users do |user| json.user_id user.id json.identify user.identity From 9bc8453ba3b14c11cc2956d7658d6e08efa7e68b Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 15:32:25 +0800 Subject: [PATCH 0373/1015] =?UTF-8?q?=E5=88=86=E9=A1=B5=E6=8A=A5500?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- app/views/shixuns/add_collaborators.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 32a2c6ef9..89a0d524f 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -635,7 +635,7 @@ class ShixunsController < ApplicationController end page = params[:page] || 1 limit = params[:limit] || 20 - @users_count = @users.count + @total_count = @users.count @users = @users.page(page).per(limit) end diff --git a/app/views/shixuns/add_collaborators.json.jbuilder b/app/views/shixuns/add_collaborators.json.jbuilder index 7bac0c24c..963389933 100644 --- a/app/views/shixuns/add_collaborators.json.jbuilder +++ b/app/views/shixuns/add_collaborators.json.jbuilder @@ -1,5 +1,5 @@ #json.partial! "users/users_list", users: @users -#json.users_count @users_count +json.total_count @total_count json.array! @users do |user| json.user_id user.id json.identify user.identity From d8dab33c211df583815601263e3d581e2a2d220f Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 28 Jun 2019 15:34:24 +0800 Subject: [PATCH 0374/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E7=AD=94?= =?UTF-8?q?=E9=A2=98=E5=88=97=E8=A1=A8=E6=98=AF=E5=90=A6=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E5=AE=A2=E8=A7=82=E9=A2=98=E5=92=8C=E4=B8=BB=E8=A7=82=E9=A2=98?= =?UTF-8?q?=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 01a2d540a..421c5177a 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1177,15 +1177,16 @@ class ExercisesController < ApplicationController @exercise_status = @exercise.get_exercise_status(current_user.id) @course_all_members = @course.students @c_group_counts = @course.course_groups_count - question_types = @exercise.exercise_questions.pluck(:question_type) + question_types = @exercise.exercise_questions.pluck(:question_type).uniq @exercise_publish_count = get_user_permission_course(exercise_ids,2).count #判断是否有已发布的分班 @exercise_unpublish_count = get_user_permission_course(exercise_ids,1).count #判断是否有未发布的分班 - if question_types.include?(4) #是否包含主观题 + if (question_types.size > 1) && question_types.include?(4) #是否包含主观题,或者是否大于1 @subjective_type = 1 else @subjective_type = 0 end + if @user_course_identity < Course::STUDENT #当前为老师,而且老师只能查看自己班级的/课堂的试卷 @exercise_current_user_status = 0 if @exercise_status == 1 From ce07bf7e3497bc5aa8348705d6b5968a92760bbc Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 15:37:45 +0800 Subject: [PATCH 0375/1015] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=90=88=E4=BD=9C?= =?UTF-8?q?=E8=80=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shixuns/add_collaborators.json.jbuilder | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/views/shixuns/add_collaborators.json.jbuilder b/app/views/shixuns/add_collaborators.json.jbuilder index 963389933..79b325fcd 100644 --- a/app/views/shixuns/add_collaborators.json.jbuilder +++ b/app/views/shixuns/add_collaborators.json.jbuilder @@ -1,8 +1,11 @@ #json.partial! "users/users_list", users: @users json.total_count @total_count -json.array! @users do |user| - json.user_id user.id - json.identify user.identity - json.nickname user.lastname - json.school_name user.school_name +json.users do + json.array! @users do |user| + json.user_id user.id + json.identify user.identity + json.nickname user.lastname + json.school_name user.school_name + end + end From bf5489ca5b692087eededfc4b9794234d4eba1b3 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 28 Jun 2019 15:38:16 +0800 Subject: [PATCH 0376/1015] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=88=86=E7=8F=AD?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 93eba89d8..e0844ab4c 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -799,6 +799,8 @@ class CoursesController < ApplicationController uid_logger_error(e.message) normal_status(-1, "无法完成导入,原因:文件内容无法读取") end + else + normal_status(-1, "只支持xls文件的导入") end end end From c211548a13326945c5795b74ee1ad64e41c29383 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 15:38:22 +0800 Subject: [PATCH 0377/1015] =?UTF-8?q?=E5=90=88=E4=BD=9C=E8=80=85=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- app/views/shixuns/add_collaborators.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 89a0d524f..73029706f 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -635,7 +635,7 @@ class ShixunsController < ApplicationController end page = params[:page] || 1 limit = params[:limit] || 20 - @total_count = @users.count + @user_count = @users.count @users = @users.page(page).per(limit) end diff --git a/app/views/shixuns/add_collaborators.json.jbuilder b/app/views/shixuns/add_collaborators.json.jbuilder index 79b325fcd..d73a5b9bc 100644 --- a/app/views/shixuns/add_collaborators.json.jbuilder +++ b/app/views/shixuns/add_collaborators.json.jbuilder @@ -1,5 +1,5 @@ #json.partial! "users/users_list", users: @users -json.total_count @total_count +json.user_count @user_count json.users do json.array! @users do |user| json.user_id user.id From 4fefe12d16da4987ea91037813207ba5d73321d1 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 28 Jun 2019 16:29:13 +0800 Subject: [PATCH 0378/1015] =?UTF-8?q?=E6=9D=83=E9=99=90=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 5 ++--- app/views/shixuns/add_collaborators.json.jbuilder | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index ac0b6baa8..9e645c35a 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -51,9 +51,8 @@ class GamesController < ApplicationController # 统计评测时间 record_onsume_time = EvaluateRecord.where(game_id: @game.id).first.try(:consume_time) - # power判断用户是否有权限查看隐藏测试集(TPM管理员;平台认证的老师;花费金币查看者) - # myshixun_manager - myshixun_manager = current_user.manager_of_shixun?(@shixun) || (current_user.is_teacher? && current_user.pro_certification?) + # myshixun_manager判断用户是否有权限查看隐藏测试集(TPM管理员;平台认证的老师;花费金币查看者) + myshixun_manager = @identity < USER::EDU_GAME_MANAGER # 选择题和编程题公共部分 @base_date = {st: @st, discusses_count: discusses_count, game_count: game_count, myshixun: @myshixun, diff --git a/app/views/shixuns/add_collaborators.json.jbuilder b/app/views/shixuns/add_collaborators.json.jbuilder index d73a5b9bc..d20f0b318 100644 --- a/app/views/shixuns/add_collaborators.json.jbuilder +++ b/app/views/shixuns/add_collaborators.json.jbuilder @@ -4,7 +4,7 @@ json.users do json.array! @users do |user| json.user_id user.id json.identify user.identity - json.nickname user.lastname + json.nickname user.real_name json.school_name user.school_name end From 2a50253d39d3691fa49105346e7d9448c9ee3645 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 28 Jun 2019 16:52:26 +0800 Subject: [PATCH 0379/1015] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 92 ++++++++++++++++++- app/models/homework_common.rb | 10 +- 2 files changed, 98 insertions(+), 4 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index b89fd6b67..bd18f102a 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -235,6 +235,96 @@ class HomeworkCommonsController < ApplicationController end end + def update_score + student_works = @homework.student_works + myshixuns = Myshixun.where(shixun_id: @homework.homework_commons_shixun&.shixun_id, user_id: @course.students.pluck(:user_id)) + myshixuns = Myshixun.where(shixun_id: @homework.homework_commons_shixun&.shixun_id). + joins("join course_members on myshixuns.user_id=course_members.user_id").where(course_members: {course_id: @course.id, role: 4}).includes(:games) + myshixuns.find_each(batch_size: 100) do |myshixun| + work = student_works.select{|work| work.user_id == myshixun.user_id}.first + setting_time = @homework.homework_group_setting work.user_id + + if setting_time.end_time.present? && (setting_time.end_time > Time.now || (@homework.allow_late && @homework.late_time && @homework.late_time > Time.now)) + #logger.info("#############setting_time: #{setting_time.end_time}") + + user_total_score = 0 + pass_consume_time = 0 + final_score = 0 + homework.homework_challenge_settings.each do |setting| + game = myshixun.games.where(:challenge_id => setting.challenge_id, :status => 2).first + unless game.nil? + pass_consume_time += (game.cost_time / 60.0).to_f + user_total_score += game.final_score.to_i < 0 ? 0 : game.challenge.score.to_i + adjust_score = work.challenge_work_scores.where(:challenge_id => setting.challenge_id).last + final_score += adjust_score.present? ? adjust_score.score : (homework.homework_detail_manual.answer_open_evaluation ? setting.score : (game.final_score > 0 ? game.real_score(setting.score) : 0)) + end + end + if work.work_status == 0 + is_complete = myshixun.is_complete? && (myshixun.done_time < setting_time.end_time) + work.work_status = setting_time.end_time > Time.now ? 1 : (is_complete ? 1 : 2) + work.late_penalty = setting_time.end_time > Time.now ? 0 : (is_complete ? 0 : homework.late_penalty) + work.commit_time = myshixun.created_at > setting_time.publish_time ? setting_time.publish_time : myshixun.created_at + work.myshixun_id = myshixun.id + end + + games = myshixun.games.where(:challenge_id => homework.homework_challenge_settings.map(&:challenge_id)) + myshixun_endtime = games.select{|game| game.status == 2}.size == games.size ? games.map(&:end_time).max : nil + if myshixun_endtime.present? + min_efficiency_changed = min_efficiency_changed.present? ? min_efficiency_changed : false + work.compelete_status = 1 + work.cost_time = myshixun_endtime.to_i - setting_time.publish_time.to_i + + efficiency = (pass_consume_time == 0 ? 0 : Math.log((user_total_score / pass_consume_time.to_f) + 1.0)) + work.efficiency = format("%.2f", efficiency) + + # 如果作业的最大效率值有变更则更新所有作品的效率分 + if homework.work_efficiency && homework.max_efficiency < work.efficiency + homework.update_column("max_efficiency", work.efficiency) + end + end + + work.update_time = Time.now + + work.final_score = final_score + score = work.final_score + work.eff_score - work.late_penalty + work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) unless work.ultimate_score + #logger.info("#############work_score: #{score}") + work.save! + end + end + @homework.student_works.each do || + + end + end + + def update_student_score + work = @homework.students_works.find_by(user_id: current_user.id) + myshixun = Myshixun.find_by(shixun_id: params[:shixun_id], user_id: current_user.id) + if work && myshixun + # 判断作品是否关联过myshixun + if work.myshixun_id.nil? + work.myshixun_id = myshixun.id + work.update_time = myshixun.updated_at + setting_time = @homework.homework_group_setting myshixun.user_id + games = myshixun.games.where(:challenge_id => @homework.homework_challenge_settings.pluck(:challenge_id)) + myshixun_endtime = games.select{|game| game.status == 2}.size == games.size ? games.map(&:end_time).max : nil + compelete_status = 0 + if myshixun_endtime.present? && myshixun_endtime < setting_time.end_time + if myshixun_endtime < setting_time.publish_time + compelete_status = 2 + else + compelete_status = 1 + end + end + if setting_time.end_time > Time.now + work.update_attributes(:work_status => 1, :late_penalty => 0, :commit_time => myshixun.updated_at, :update_time => myshixun.updated_at, :myshixun_id => myshixun.id, :compelete_status => compelete_status) + else + work.update_attributes(:work_status => ((myshixun.is_complete? && (myshixun.done_time < setting_time.end_time)) ? 1 : 2), :late_penalty => (myshixun.is_complete? && (myshixun.done_time < setting_time.end_time) ? 0 : homework.late_penalty), :commit_time => myshixun.updated_at, :update_time => myshixun.updated_at, :myshixun_id => myshixun.id, :compelete_status => compelete_status) + end + end + end + end + def alter_name tip_exception("作业名称不能为空") if params[:name].blank? @homework.update_attributes(name: params[:name].strip) @@ -620,7 +710,7 @@ class HomeworkCommonsController < ApplicationController if @homework_detail_manual.comment_status < 4 tip_exception("匿评结束时间不能为空") if @homework.anonymous_comment && params[:evaluation_end].blank? tip_exception("匿评截止时间必须晚于匿评开启时间") if @homework.anonymous_comment && - params[:evaluation_end] <= params[:evaluation_start] + params[:evaluation_end] <= strf_time(@homework_detail_manual.evaluation_start) tip_exception("匿评截止时间不能晚于课堂结束时间") if @homework.anonymous_comment && @course.end_date.present? && params[:evaluation_end] > strf_time(@course.end_date.end_of_day) diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 6512c3f1d..8f24820e7 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -231,9 +231,13 @@ class HomeworkCommon < ApplicationRecord # 作业的分班设置时间 def homework_group_setting user_id - member = course.course_member(user_id) - group_setting = self.homework_group_settings.find_by_course_group_id(member.try(:course_group_id)) - homework_setting = group_setting.present? ? group_setting : self + if unified_setting + homework_setting = self + else + member = course.course_member(user_id) + group_setting = self.homework_group_settings.find_by_course_group_id(member.try(:course_group_id)) + homework_setting = group_setting.present? ? group_setting : self + end homework_setting end From 5d9c142b3524fa727e885cc3348b8651b4fd205f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 29 Jun 2019 08:49:31 +0800 Subject: [PATCH 0380/1015] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9F=A5=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index b89fd6b67..1ebb1cf93 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -1233,7 +1233,7 @@ class HomeworkCommonsController < ApplicationController # 代码查重届结果 def code_review_results # 如果有未获取结果的查重操作 则先读取结果 - get_new_code_reviews_result @homework + #get_new_code_reviews_result @homework @current_user = current_user # 列表数据 From 41da5389dee3d1c5c19d86de98b8178889f3242a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 29 Jun 2019 09:07:41 +0800 Subject: [PATCH 0381/1015] =?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/graduation_tasks_controller.rb | 2 +- app/controllers/homework_commons_controller.rb | 11 +++++++---- app/controllers/student_works_controller.rb | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 93d3cba3d..454f23c81 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -122,7 +122,7 @@ class GraduationTasksController < ApplicationController @work_count = @work_list.count @work_excel = @work_list - @work_list = @work_list.page(page).limit(limit) + @work_list = @work_list.page(page).per(limit) respond_to do |format| format.json format.xlsx{ diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index bd18f102a..c3bd777ae 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -316,10 +316,13 @@ class HomeworkCommonsController < ApplicationController compelete_status = 1 end end - if setting_time.end_time > Time.now - work.update_attributes(:work_status => 1, :late_penalty => 0, :commit_time => myshixun.updated_at, :update_time => myshixun.updated_at, :myshixun_id => myshixun.id, :compelete_status => compelete_status) - else - work.update_attributes(:work_status => ((myshixun.is_complete? && (myshixun.done_time < setting_time.end_time)) ? 1 : 2), :late_penalty => (myshixun.is_complete? && (myshixun.done_time < setting_time.end_time) ? 0 : homework.late_penalty), :commit_time => myshixun.updated_at, :update_time => myshixun.updated_at, :myshixun_id => myshixun.id, :compelete_status => compelete_status) + games.each do |game| + unless game.nil? + pass_consume_time += (game.cost_time / 60.0).to_f + user_total_score += game.final_score.to_i < 0 ? 0 : game.challenge.score.to_i + adjust_score = work.challenge_work_scores.where(:challenge_id => setting.challenge_id).last + final_score += adjust_score.present? ? adjust_score.score : (homework.homework_detail_manual.answer_open_evaluation ? setting.score : (game.final_score > 0 ? game.real_score(setting.score) : 0)) + end end end end diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index ab026cf05..5d14a43ea 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -43,7 +43,7 @@ class StudentWorksController < ApplicationController def search_member_list # 统一设置的作业取所有学生,否则取已发布的分班学生 students = @homework.unified_setting? ? @course.students : @course.students.where(course_group_id: @homework.published_settings.pluck(:course_group_id)) - unless params[:search].blank? + if !params[:search].blank? @members = students.joins(user: :user_extension).where("course_members.user_id != #{current_user.id} and (concat(users.lastname, users.firstname) like ? or user_extensions.student_id like ?)", "%#{params[:search]}%", "%#{params[:search]}%") else From 48bf9693d87b9f21a819bc210cb752a010c40376 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 09:19:35 +0800 Subject: [PATCH 0382/1015] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E9=A2=98=E6=9C=AA=E9=80=9A=E5=85=B3=E6=98=BE=E7=A4=BA=E5=85=B3?= =?UTF-8?q?=E5=8D=A1=E5=86=85=E5=AE=B9=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_questions_controller.rb | 2 +- .../exercise_questions/_exercise_questions.json.jbuilder | 2 +- app/views/exercises/_shixun_details.json.jbuilder | 9 ++++++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index dd0247f70..79d671605 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -640,7 +640,7 @@ class ExerciseQuestionsController < ApplicationController if @exercise.exercise_status != 1 question_score = @exercise_question.question_score #原来的分数 update_question_score = params[:question_score].to_f.round(1) #传入的分数 - choices_count = @exercise_question.exercise_choices.count #原来的选项个数 + choices_count = @exercise_question.exercise_choices.size #原来的选项个数 exercise_choice_ids = @exercise_question.exercise_standard_answers.pluck(:exercise_choice_id).uniq standard_answers_text = @exercise_question.exercise_standard_answers.pluck(:answer_text).uniq update_choices_count = params[:question_choices].present? ? params[:question_choices].count : choices_count #传入的选项个数 diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index 9445862ba..4e05ffb7a 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -86,7 +86,7 @@ elsif question.question_type == 5 user_get_score = games_score[:s_score].present? ? games_score[:s_score] : 0.0 json.shixun_challenge_id s.id if games_score[:games].count > 0 - json.partial! "exercises/shixun_details",games: games_score[:games], user_score: user_get_score,game_score: games_score[:game_score] + json.partial! "exercises/shixun_details",games: games_score[:games], user_score: user_get_score,game_score: games_score[:game_score],shixun_challenge:s else json.partial! "exercises/shixun_undo",games: [s], user_score: user_get_score ,game_score: s.question_score end diff --git a/app/views/exercises/_shixun_details.json.jbuilder b/app/views/exercises/_shixun_details.json.jbuilder index c788b8c1c..a28bf4145 100644 --- a/app/views/exercises/_shixun_details.json.jbuilder +++ b/app/views/exercises/_shixun_details.json.jbuilder @@ -26,6 +26,13 @@ json.shixun_detail do json.position output.query_index json.output_detail output_detail game, output end - json.passed_code game.try(:lastest_code) + + if game.try(:lastest_code).blank? + cha_path = challenge_path(shixun_challenge.challenge&.path) + latest_code = git_fle_content(shixun_challenge.shixun&.repo_path,cha_path) + else + latest_code = game.try(:lastest_code) + end + json.passed_code latest_code end end \ No newline at end of file From f2fed6a237d740b3f1c3825bdb6dfe4013a4464b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 09:32:59 +0800 Subject: [PATCH 0383/1015] fix bug --- app/controllers/concerns/git_helper.rb | 5 ----- app/helpers/application_helper.rb | 6 ++++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/concerns/git_helper.rb b/app/controllers/concerns/git_helper.rb index 445d67087..f40e18e1c 100644 --- a/app/controllers/concerns/git_helper.rb +++ b/app/controllers/concerns/git_helper.rb @@ -53,9 +53,4 @@ module GitHelper container.update_attributes!(:repo_name => new_repo_name) end - #实训题的关卡url初始化 - def challenge_path(path) - cha_path = path.present? ? path.split(";") : [] - cha_path.reject(&:blank?)[0].try(:strip) - end end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 32c4438a6..0cdfeba06 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -332,6 +332,12 @@ module ApplicationHelper raw arr.join('') end + + #实训题的关卡url初始化 + def challenge_path(path) + cha_path = path.present? ? path.split(";") : [] + cha_path.reject(&:blank?)[0].try(:strip) + end end From 71ea32797d5193d8c891575dbc443fd5b5b27c65 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 09:39:05 +0800 Subject: [PATCH 0384/1015] fix bug --- app/controllers/concerns/git_helper.rb | 5 +++++ app/helpers/application_helper.rb | 6 +----- app/helpers/exercises_helper.rb | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/controllers/concerns/git_helper.rb b/app/controllers/concerns/git_helper.rb index f40e18e1c..445d67087 100644 --- a/app/controllers/concerns/git_helper.rb +++ b/app/controllers/concerns/git_helper.rb @@ -53,4 +53,9 @@ module GitHelper container.update_attributes!(:repo_name => new_repo_name) end + #实训题的关卡url初始化 + def challenge_path(path) + cha_path = path.present? ? path.split(";") : [] + cha_path.reject(&:blank?)[0].try(:strip) + end end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0cdfeba06..d8ea8cd60 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,6 +1,7 @@ # 所有的方法请按首字母的顺序依次列出 module ApplicationHelper include Educoder::I18n + include GitHelper ONE_MINUTE = 60 * 1000 ONE_HOUR = 60 * ONE_MINUTE @@ -333,11 +334,6 @@ module ApplicationHelper raw arr.join('') end - #实训题的关卡url初始化 - def challenge_path(path) - cha_path = path.present? ? path.split(";") : [] - cha_path.reject(&:blank?)[0].try(:strip) - end end diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index a2a80c311..45666d296 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -1,5 +1,6 @@ module ExercisesHelper + # include GitHelper #获取每个学生对每个题的答案状态 def get_each_student_exercise(exercise_id,exercise_questions,user_id) From 226afa2d96beb9aea284303b1589220b9f377955 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 09:42:54 +0800 Subject: [PATCH 0385/1015] fix bug --- app/views/exercises/_shixun_details.json.jbuilder | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/views/exercises/_shixun_details.json.jbuilder b/app/views/exercises/_shixun_details.json.jbuilder index a28bf4145..de847ebed 100644 --- a/app/views/exercises/_shixun_details.json.jbuilder +++ b/app/views/exercises/_shixun_details.json.jbuilder @@ -27,12 +27,17 @@ json.shixun_detail do json.output_detail output_detail game, output end - if game.try(:lastest_code).blank? - cha_path = challenge_path(shixun_challenge.challenge&.path) - latest_code = git_fle_content(shixun_challenge.shixun&.repo_path,cha_path) + if game.evaluate_count > 0 + if game.try(:lastest_code).blank? + cha_path = challenge_path(shixun_challenge.challenge&.path) + latest_code = git_fle_content(shixun_challenge.shixun&.repo_path,cha_path) + else + latest_code = game.try(:lastest_code) + end else - latest_code = game.try(:lastest_code) + latest_code = nil end + json.passed_code latest_code end end \ No newline at end of file From a8b0f950c71eacef61154a822821c96978db7194 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 09:52:17 +0800 Subject: [PATCH 0386/1015] fix bug --- app/views/exercises/_shixun_details.json.jbuilder | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/app/views/exercises/_shixun_details.json.jbuilder b/app/views/exercises/_shixun_details.json.jbuilder index de847ebed..ac3884336 100644 --- a/app/views/exercises/_shixun_details.json.jbuilder +++ b/app/views/exercises/_shixun_details.json.jbuilder @@ -27,15 +27,11 @@ json.shixun_detail do json.output_detail output_detail game, output end - if game.evaluate_count > 0 - if game.try(:lastest_code).blank? - cha_path = challenge_path(shixun_challenge.challenge&.path) - latest_code = git_fle_content(shixun_challenge.shixun&.repo_path,cha_path) - else - latest_code = game.try(:lastest_code) - end + if game.try(:lastest_code).blank? + cha_path = challenge_path(shixun_challenge.challenge&.path) + latest_code = git_fle_content(shixun_challenge.shixun&.repo_path,cha_path) else - latest_code = nil + latest_code = game.try(:lastest_code) end json.passed_code latest_code From 4b71fc157677ad9ca15eeb9f856cd4dc30370c3f Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 09:59:06 +0800 Subject: [PATCH 0387/1015] fix bug --- app/controllers/concerns/git_helper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/concerns/git_helper.rb b/app/controllers/concerns/git_helper.rb index 445d67087..8e7288df2 100644 --- a/app/controllers/concerns/git_helper.rb +++ b/app/controllers/concerns/git_helper.rb @@ -31,7 +31,8 @@ module GitHelper decode_content rescue Exception => e - uid_logger_error(e.message) + Rails.logger.error(e.message) + # uid_logger_error(e.message) raise Educoder::TipException.new("文档内容获取异常") end end From 5c74d71c947720f37b94e7e2dec7d6f630daf021 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 10:14:46 +0800 Subject: [PATCH 0388/1015] fix bug --- app/helpers/exercises_helper.rb | 2 +- app/views/exercises/_shixun_details.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 45666d296..5f8683fd0 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -436,7 +436,7 @@ module ExercisesHelper game_code = game_challenge code = game_code.try(:new_code) else - code = git_fle_content(exercise_cha.shixun&.repo_path,cha_path) + code = git_fle_content(game.myshixun.repo_path,cha_path) end sx_option = { :exercise_question_id => q.id, diff --git a/app/views/exercises/_shixun_details.json.jbuilder b/app/views/exercises/_shixun_details.json.jbuilder index ac3884336..96e5c6281 100644 --- a/app/views/exercises/_shixun_details.json.jbuilder +++ b/app/views/exercises/_shixun_details.json.jbuilder @@ -29,7 +29,7 @@ json.shixun_detail do if game.try(:lastest_code).blank? cha_path = challenge_path(shixun_challenge.challenge&.path) - latest_code = git_fle_content(shixun_challenge.shixun&.repo_path,cha_path) + latest_code = git_fle_content(game&.myshixun.repo_path,cha_path) else latest_code = game.try(:lastest_code) end From a78759f8af49cc8c20d2d2b523256fe7875b7e6e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 29 Jun 2019 10:19:10 +0800 Subject: [PATCH 0389/1015] =?UTF-8?q?=E5=BC=80=E5=90=AF=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E6=8A=A5500?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 9e645c35a..8c364308f 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -52,7 +52,7 @@ class GamesController < ApplicationController record_onsume_time = EvaluateRecord.where(game_id: @game.id).first.try(:consume_time) # myshixun_manager判断用户是否有权限查看隐藏测试集(TPM管理员;平台认证的老师;花费金币查看者) - myshixun_manager = @identity < USER::EDU_GAME_MANAGER + myshixun_manager = @identity < User::EDU_GAME_MANAGER # 选择题和编程题公共部分 @base_date = {st: @st, discusses_count: discusses_count, game_count: game_count, myshixun: @myshixun, From 8cfb86d76c9857493bc5f926408fe80ad49cd91d Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 10:28:30 +0800 Subject: [PATCH 0390/1015] fix bug --- app/views/exercises/_shixun_details.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/exercises/_shixun_details.json.jbuilder b/app/views/exercises/_shixun_details.json.jbuilder index 96e5c6281..85bf532e1 100644 --- a/app/views/exercises/_shixun_details.json.jbuilder +++ b/app/views/exercises/_shixun_details.json.jbuilder @@ -29,7 +29,7 @@ json.shixun_detail do if game.try(:lastest_code).blank? cha_path = challenge_path(shixun_challenge.challenge&.path) - latest_code = git_fle_content(game&.myshixun.repo_path,cha_path) + latest_code = git_fle_content(game.myshixun.repo_path,cha_path) else latest_code = game.try(:lastest_code) end From 067c516561d1fc70ae7152cf2893d0d16673fec8 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 29 Jun 2019 10:43:50 +0800 Subject: [PATCH 0391/1015] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=BA=93=E6=89=93?= =?UTF-8?q?=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/controllers/concerns/git_helper.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/concerns/git_helper.rb b/app/controllers/concerns/git_helper.rb index 8e7288df2..78eae769c 100644 --- a/app/controllers/concerns/git_helper.rb +++ b/app/controllers/concerns/git_helper.rb @@ -9,6 +9,8 @@ module GitHelper # 版本库文件内容,带转码 def git_fle_content(repo_path, path) begin + logger.info("##########repo_path: #{repo_path}") + logger.info("##########path: #{path}") content = GitService.file_content(repo_path: repo_path, path: path) logger.info("@@@@@@@@@@@@@@@@@@#{content}") From 76d16698a1d83e3ac5753d6f8c3c56b3fd0bb72c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 10:49:05 +0800 Subject: [PATCH 0392/1015] fix bug --- app/helpers/exercises_helper.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 5f8683fd0..6ec6cd601 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -430,7 +430,10 @@ module ExercisesHelper end ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id) if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 + logger.info("############_________exercise_cha.challenge&.path___________###############{exercise_cha.challenge&.path}") cha_path = challenge_path(exercise_cha.challenge&.path) + logger.info("############_________cha_path___________###############{cha_path}") + game_challenge = game.game_codes.search_challenge_path(cha_path)&.first if game_challenge.present? game_code = game_challenge From 831b1937f98eeb529283db11bae76f7cc8dff4c7 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 29 Jun 2019 10:57:24 +0800 Subject: [PATCH 0393/1015] =?UTF-8?q?challenge=E6=98=BE=E7=A4=BA=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 4 ++-- app/controllers/shixuns_controller.rb | 5 ----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 2ba76c60a..afe0e14b6 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -151,8 +151,8 @@ class ChallengesController < ApplicationController def index uid_logger("identifier: #{params}") # 通过调试发现 这里includes(:games)性能会慢10倍 - - @challenges = @shixun.challenges.fields_for_list.includes(:games).where("games.user_id" => current_user.id) + current_myshixun = @shixun.current_myshixun(current_user.id) + @challenges = @shixun.challenges.includes(:games).where("games.user_id" => (current_myshixun ? current_user.id : nil)) @editable = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0 @user = current_user diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 73029706f..b3069bc5d 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -553,11 +553,6 @@ class ShixunsController < ApplicationController end end - # REDO:开启实训时更新关联作品的状态 - # TODO:这个可以异步。或者放到课程里面取,不要在开启实训这边做 - # HomeworksService.new.update_myshixun_work_status myshixun - UpdateMyshixunWorkStatusJob.perform_later(myshixun.id) - @current_task = myshixun.current_task(myshixun.games) uid_logger("## shixun exec: myshixun id is #{myshixun.id}") rescue Exception => e From 538efef33aa40d3483da58d57bd933c569e1a48d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 29 Jun 2019 11:18:59 +0800 Subject: [PATCH 0394/1015] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9F=A5=E9=87=8D?= =?UTF-8?q?=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 2a1dfb14a..c3bd777ae 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -1326,7 +1326,7 @@ class HomeworkCommonsController < ApplicationController # 代码查重届结果 def code_review_results # 如果有未获取结果的查重操作 则先读取结果 - #get_new_code_reviews_result @homework + get_new_code_reviews_result @homework @current_user = current_user # 列表数据 From 9d7d609bb5ebfa4d573dc6be55582653f445a0d3 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 11:28:36 +0800 Subject: [PATCH 0395/1015] fix bug --- app/helpers/exercises_helper.rb | 11 ++++++----- .../_exercise_questions.json.jbuilder | 6 +++++- app/views/exercises/_shixun_details.json.jbuilder | 13 ++++++++----- .../exercises/_user_exercise_info.json.jbuilder | 2 +- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 6ec6cd601..68f6574ee 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -429,11 +429,9 @@ module ExercisesHelper answer_status = 1 end ex_shixun_answer_content = answers_content&.where(exercise_shixun_challenge_id: exercise_cha.id) - if ex_shixun_answer_content.blank? #把关卡的答案存入试卷的实训里 - logger.info("############_________exercise_cha.challenge&.path___________###############{exercise_cha.challenge&.path}") + code = nil + if exercise_cha.challenge&.path.present? cha_path = challenge_path(exercise_cha.challenge&.path) - logger.info("############_________cha_path___________###############{cha_path}") - game_challenge = game.game_codes.search_challenge_path(cha_path)&.first if game_challenge.present? game_code = game_challenge @@ -441,6 +439,9 @@ module ExercisesHelper 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, @@ -451,7 +452,7 @@ module ExercisesHelper } ExerciseShixunAnswer.create(sx_option) else - ex_shixun_answer_content.first.update_column('score',exercise_cha_score) + ex_shixun_answer_content.first.update_attributes(score:exercise_cha_score.round(1),answer_text:code) end score5 += exercise_cha_score else diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index 4e05ffb7a..4cdd97f3c 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -1,6 +1,10 @@ json.question_id question.id # json.question_number question.question_number -json.q_position ques_position.present? ? ques_position : question.question_number +q_positon = question.question_number +if ques_position.present? + q_positon = ques_position +end +json.q_position q_positon json.question_title question.question_title json.question_type question.question_type json.question_score question.question_score.round(1).to_s diff --git a/app/views/exercises/_shixun_details.json.jbuilder b/app/views/exercises/_shixun_details.json.jbuilder index 85bf532e1..4a73a9bbb 100644 --- a/app/views/exercises/_shixun_details.json.jbuilder +++ b/app/views/exercises/_shixun_details.json.jbuilder @@ -27,11 +27,14 @@ json.shixun_detail do json.output_detail output_detail game, output end - if game.try(:lastest_code).blank? - cha_path = challenge_path(shixun_challenge.challenge&.path) - latest_code = git_fle_content(game.myshixun.repo_path,cha_path) - else - latest_code = game.try(:lastest_code) + latest_code = nil + if shixun_challenge.challenge&.path.present? + if game.try(:lastest_code).blank? + cha_path = challenge_path(shixun_challenge.challenge&.path) + latest_code = git_fle_content(game.myshixun.repo_path,cha_path) + else + latest_code = game.try(:lastest_code) + end end json.passed_code latest_code diff --git a/app/views/exercises/_user_exercise_info.json.jbuilder b/app/views/exercises/_user_exercise_info.json.jbuilder index 1ff929897..cba07fb3f 100644 --- a/app/views/exercises/_user_exercise_info.json.jbuilder +++ b/app/views/exercises/_user_exercise_info.json.jbuilder @@ -62,7 +62,7 @@ json.exercise_questions do exercise_type: ex_type, user_answer: user_ques_answers[:answered_content], shixun_type: user_ques_answers[:shixun_type], - ques_position:nil + ques_position: nil if user_ques_comments.count > 0 json.question_comments do json.partial! "exercises/exercise_comments", question_comment:user_ques_answers[:question_comment].first From 16dba624008e84859976f2223f4b094faea942a9 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 11:31:54 +0800 Subject: [PATCH 0396/1015] fix bug --- app/views/exercise_questions/_exercise_questions.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index 4cdd97f3c..ce8d0f1f2 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -4,7 +4,7 @@ q_positon = question.question_number if ques_position.present? q_positon = ques_position end -json.q_position q_positon +json.q_position question.question_number json.question_title question.question_title json.question_type question.question_type json.question_score question.question_score.round(1).to_s From 0ec0e612fa4d568db685c4c5b4df884ddff5d6dd Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 11:41:10 +0800 Subject: [PATCH 0397/1015] fix bug --- app/views/exercise_questions/_exercise_questions.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index ce8d0f1f2..4cdd97f3c 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -4,7 +4,7 @@ q_positon = question.question_number if ques_position.present? q_positon = ques_position end -json.q_position question.question_number +json.q_position q_positon json.question_title question.question_title json.question_type question.question_type json.question_score question.question_score.round(1).to_s From da2c9c97c263743af8c3a6238ff63f9cede3a36b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 12:29:14 +0800 Subject: [PATCH 0398/1015] fix bug --- app/helpers/exercises_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 68f6574ee..72fbc9486 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -642,7 +642,7 @@ module ExercisesHelper end if student_status == 2 #当前为老师,或为学生且已提交 user_score_pre = exercise_answers.score_reviewed - user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : nil + user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : "0.0" end if user_score.present? && (user_score > q.question_score) From 8dd42b59a7237468f4c0c72487032e9293f82b2c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 12:30:32 +0800 Subject: [PATCH 0399/1015] fix bug --- app/helpers/exercises_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 72fbc9486..04890954b 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -642,7 +642,7 @@ module ExercisesHelper end if student_status == 2 #当前为老师,或为学生且已提交 user_score_pre = exercise_answers.score_reviewed - user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : "0.0" + user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : 0.0 end if user_score.present? && (user_score > q.question_score) From 079d757021b4678302f9e34832117f6222baf709 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 29 Jun 2019 14:17:43 +0800 Subject: [PATCH 0400/1015] =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 035b43955..8629083dd 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -260,12 +260,12 @@ class MyshixunsController < ApplicationController unless @hide_code # 远程版本库文件内容 last_content = GitService.file_content(repo_path: @repo_path, path: path)["content"] - - content = if @myshixun.mirror_name.select{|a| a.include?("MachineLearning") || a.include?("Python")}.present? && params[:content].present? - params[:content].gsub(/\t/, ' ') - else - params[:content] - end + content = params[:content] + # content = if @myshixun.mirror_name.select{|a| a.include?("MachineLearning") || a.include?("Python")}.present? && params[:content].present? + # params[:content].gsub(/\t/, ' ') + # else + # params[:content] + # end if content != last_content @content_modified = 1 From 0d5361b59cd9c45c10c585610ba1df83ef22a0dd Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 29 Jun 2019 14:38:12 +0800 Subject: [PATCH 0401/1015] shixun file update --- app/controllers/myshixuns_controller.rb | 85 ++++++++++--------- app/views/myshixuns/update_file.json.jbuilder | 1 + 2 files changed, 44 insertions(+), 42 deletions(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 035b43955..24c5066e5 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -243,55 +243,56 @@ class MyshixunsController < ApplicationController # -----Repository # TODO: 之类需要一个resubmit参数,但是是关于games. def update_file - @hide_code = Shixun.where(id: @myshixun.shixun_id).pluck(:hide_code).first - tip_exception("技术平台为空!") if @myshixun.mirror_name.blank? - path = params[:path].strip unless params[:path].blank? - game_id = params[:game_id] - game = Game.find(game_id) - @content_modified = 0 - # params[:evaluate] 实训评测时更新必须给的参数,需要依据该参数做性能统计,其它类型的更新可以跳过 - # 自动保存的时候evaluate为0;点评测的时候为1 - if params[:evaluate] == 1 - record = EvaluateRecord.create!(:user_id => current_user.id, :shixun_id => @myshixun.shixun_id, :game_id => game_id) - uid_logger("-- game is #{game_id}, record id is #{record.id}, time is **** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") - student_work_time = format("%.3f", (Time.now.to_f - record.created_at.to_f)).to_f - record.update_attributes!(:student_work => student_work_time) - end - unless @hide_code - # 远程版本库文件内容 - last_content = GitService.file_content(repo_path: @repo_path, path: path)["content"] + begin + @hide_code = Shixun.where(id: @myshixun.shixun_id).pluck(:hide_code).first + tip_exception("技术平台为空!") if @myshixun.mirror_name.blank? + path = params[:path].strip unless params[:path].blank? + game_id = params[:game_id] + game = Game.find(game_id) + @content_modified = 0 + + # params[:evaluate] 实训评测时更新必须给的参数,需要依据该参数做性能统计,其它类型的更新可以跳过 + # 自动保存的时候evaluate为0;点评测的时候为1 + if params[:evaluate] == 1 + @sec_key = generate_identifier(EvaluateRecord, 12) + record = EvaluateRecord.create!(:user_id => current_user.id, :shixun_id => @myshixun.shixun_id, :game_id => game_id, + :identifier => @sec_key) + uid_logger("-- game build: file update #{@sec_key}, record id is #{record.id}, time is **** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") + end + unless @hide_code + # 远程版本库文件内容 + last_content = GitService.file_content(repo_path: @repo_path, path: path)["content"] - content = if @myshixun.mirror_name.select{|a| a.include?("MachineLearning") || a.include?("Python")}.present? && params[:content].present? - params[:content].gsub(/\t/, ' ') - else - params[:content] - end - if content != last_content - @content_modified = 1 + content = params[:content] - author_name = current_user.full_name - author_email = current_user.mail - message = params[:evaluate] == 0 ? "auto commit" : "task commit" - @content = GitService.update_file(repo_path: @repo_path, - file_path: path, - message: message, - content: content, - author_name: author_name, - author_email: author_email) + if content != last_content + @content_modified = 1 - uid_logger("-- file update #{@content}") + author_name = current_user.full_name + author_email = current_user.mail + message = params[:evaluate] == 0 ? "System automatically submitted" : "User submitted" + @content = GitService.update_file(repo_path: @repo_path, + file_path: path, + message: message, + content: content, + author_name: author_name, + author_email: author_email) + end end - end - if game.status == 2 - @resubmit = Time.now.to_i - end + if game.status == 2 + @resubmit = Time.now.to_i + end - # 评测时间记录 - if record.present? - consume_time = format("%.3f", (Time.now.to_f - record.created_at.to_f)).to_f - record.update_attributes!(:file_update => consume_time) + # 评测时间记录 + if record.present? + consume_time = format("%.3f", (Time.now.to_f - record.created_at.to_f)).to_f + record.update_attributes!(:file_update => consume_time) + end + rescue Exception => e + uid_logger_error(e.message) + tip_exception("文件内容更新异常,请稍后重试") end end diff --git a/app/views/myshixuns/update_file.json.jbuilder b/app/views/myshixuns/update_file.json.jbuilder index c647927c4..ce8426715 100644 --- a/app/views/myshixuns/update_file.json.jbuilder +++ b/app/views/myshixuns/update_file.json.jbuilder @@ -1,3 +1,4 @@ json.content @content json.resubmit "#{@resubmit}" +json.sec_key "#{@sec_key}" json.content_modified @hide_code ? false : @content_modified From 84b6110c56e58c409628273315ad252bb82b9172 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 14:44:18 +0800 Subject: [PATCH 0402/1015] fix bug --- .../exercise_questions_controller.rb | 2 +- app/helpers/exercises_helper.rb | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 79d671605..b231d6af7 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -616,7 +616,7 @@ class ExerciseQuestionsController < ApplicationController elsif params[:question_type].to_i == 2 && (params[:standard_answers].count > 1 || params[:question_choices].blank? || params[:question_choices].include?("")) #判断题的标准答案不能大于1个,选项不能为空 normal_status(-1,"判断题选项不能为空/标准答案不能大于1个!") elsif params[:question_type].to_i <= 1 && (params[:question_choices].blank? || params[:question_choices].include?("") || params[:question_choices].count < 2) #选择题选项不能为空,且不能小于2 - normal_status(-1,"选择题选项内容不能为空,且不能少于3个!") + normal_status(-1,"选择题选项内容不能为空,且不能少于2个!") elsif params[:question_type].to_i == 3 && (params[:standard_answers].blank? || params[:standard_answers].count > 5 ) #填空题选项最多为5个,且如果为1个的话,不允许修改is_ordered normal_status(-1,"填空题标准答案不能为空/不能超过5个!") elsif params[:question_type].to_i == 4 && params[:standard_answers].count > 2 #简单题参考答案最多为1个 diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 04890954b..1442e1da3 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -167,10 +167,13 @@ module ExercisesHelper ex_score = ex&.question_score full_scores = effictive_users.search_exercise_answer("score",ex_score).count #满分人数 no_full_scores = effictive_users.exercise_no_full_scores(ex_score).count #部分分数人数 - all_zero_scores = effictive_users.search_exercise_answer("score",0.0).count #包含为0分的,及未评阅的 - review_scores = ex.exercise_answer_comments.count #主观题的评阅数量 - un_review_scores = effictive_users_count - review_scores #未评阅数 - zero_scores = all_zero_scores - un_review_scores #已评阅,且答案未0分的人数 + zero_scores = effictive_users.search_exercise_answer("score",0.0).count #包含为0分的,及未评阅的 + # review_scores = ex.exercise_answer_comments.count #主观题的评阅数量 + un_review_scores = effictive_users_count - full_scores - no_full_scores - zero_scores #未评阅数 + if un_review_scores < 0 + un_review_scores = 0 + end + # zero_scores = all_zero_scores - un_review_scores #已评阅,且答案未0分的人数 main_scores_array = [full_scores,no_full_scores,zero_scores,un_review_scores] main_scores_array.each_with_index do |s,index| if index == 0 @@ -642,7 +645,11 @@ module ExercisesHelper end if student_status == 2 #当前为老师,或为学生且已提交 user_score_pre = exercise_answers.score_reviewed - user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : 0.0 + if ques_type == 4 && user_score_pre.blank? #主观题时,且没有大于0的分数时,为空 + user_score = nil + else + user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : 0.0 + end end if user_score.present? && (user_score > q.question_score) From ab098a3e24d305b9069ee2c7419d0d3331b7f28a Mon Sep 17 00:00:00 2001 From: jasder Date: Sat, 29 Jun 2019 15:04:25 +0800 Subject: [PATCH 0403/1015] =?UTF-8?q?FIX=20=E8=B5=84=E6=BA=90=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E9=A1=B6=E9=83=A8=E6=95=B0=E9=87=8F=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E6=9B=B4=E6=94=B9=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/files_controller.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 7e150c44c..c303c7e78 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -17,25 +17,27 @@ class FilesController < ApplicationController sort_type = params[:sort_type] || 'created_on' # created_on:时间排序, downloads:下载次数排序; quotes: 引用次数排序 course_second_category_id = params[:course_second_category_id] || 0 # 0: 为主目录, 其他为次目录id @user = current_user || nil - @attachments = @course.attachments.by_keywords(params[:search]) + @attachments = @course.attachments.by_course_second_category_id(course_second_category_id) .includes(attachment_group_settings: :course_group, author: [:user_extension, :course_members]) - .by_course_second_category_id(course_second_category_id) .ordered(sort: sort.to_i, sort_type: sort_type.strip) get_category(@course, course_second_category_id) - case @user.course_identity(@course) - when 5 - # 课程学生 - @attachments = @attachments.published - when 6 || 7 - # 非课堂成员 - @attachments = @attachments.publiced.published - end + @attachments = + case @user.course_identity(@course) + when 5 + @attachments.published + when 6, 7 + @attachments.publiced.published + else + @attachments + end @total_count = @attachments.size @public_count = @attachments.publiced.size @private_count = @total_count - @public_count + @attachments = @attachments.by_keywords(params[:search]) + @attachments = @attachments.page(@page).per(@page_size) end From d8ecd6e7728977f463a0975eaaef51640c5e7c9e Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 29 Jun 2019 15:09:44 +0800 Subject: [PATCH 0404/1015] =?UTF-8?q?tpi=20=E7=89=88=E6=9C=AC=E5=BA=93?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=9B=B4=E6=96=B0=E5=92=8C=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E7=9A=84=E4=B8=80=E4=BA=9B=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/concerns/git_common.rb | 1 - app/controllers/concerns/git_helper.rb | 6 ++---- app/controllers/games_controller.rb | 1 + 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/controllers/concerns/git_common.rb b/app/controllers/concerns/git_common.rb index 2f977245c..452204419 100644 --- a/app/controllers/concerns/git_common.rb +++ b/app/controllers/concerns/git_common.rb @@ -28,7 +28,6 @@ module GitCommon end def file_content - logger.info("#################{@repo_path}, #{@path}") @content = git_fle_content @repo_path, @path end diff --git a/app/controllers/concerns/git_helper.rb b/app/controllers/concerns/git_helper.rb index 78eae769c..8d769a244 100644 --- a/app/controllers/concerns/git_helper.rb +++ b/app/controllers/concerns/git_helper.rb @@ -9,11 +9,10 @@ module GitHelper # 版本库文件内容,带转码 def git_fle_content(repo_path, path) begin - logger.info("##########repo_path: #{repo_path}") - logger.info("##########path: #{path}") + logger.info("git file content: repo_path is #{repo_path}, path is #{path}") content = GitService.file_content(repo_path: repo_path, path: path) - logger.info("@@@@@@@@@@@@@@@@@@#{content}") + logger.info("git file content: content is #{content}") decode_content = nil if content.present? content = content["content"] #6.24 -hs 这个为新增,因为当实训题里含有选择题时,这里会报错,undefined method `[]' for nil:NilClass @@ -34,7 +33,6 @@ module GitHelper rescue Exception => e Rails.logger.error(e.message) - # uid_logger_error(e.message) raise Educoder::TipException.new("文档内容获取异常") end end diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 8c364308f..2a2439226 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -461,6 +461,7 @@ class GamesController < ApplicationController git_fle_content(@myshixun.shixun.repo_path, path) rescue Exception => e uid_logger_error("#{e.message}") + # 如果已发布的TPM实训也不能获取到内容,那么肯定是版本库异常了 if @myshixun.shixun.try(:status) < 2 tip_exception("代码获取异常,请检查实训模板的评测设置是否正确") else From cd3147dc970a41c91ef569fffe241a8da8dc69bc Mon Sep 17 00:00:00 2001 From: jasder Date: Sat, 29 Jun 2019 15:17:03 +0800 Subject: [PATCH 0405/1015] FIX bug --- app/controllers/files_controller.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index c303c7e78..c8fd042ea 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -16,12 +16,17 @@ class FilesController < ApplicationController sort = params[:sort] || 0 # 0: 降序;1: 升序 sort_type = params[:sort_type] || 'created_on' # created_on:时间排序, downloads:下载次数排序; quotes: 引用次数排序 course_second_category_id = params[:course_second_category_id] || 0 # 0: 为主目录, 其他为次目录id - @user = current_user || nil + @user = current_user @attachments = @course.attachments.by_course_second_category_id(course_second_category_id) .includes(attachment_group_settings: :course_group, author: [:user_extension, :course_members]) .ordered(sort: sort.to_i, sort_type: sort_type.strip) + get_category(@course, course_second_category_id) + @total_count = @attachments.size + @public_count = @attachments.publiced.size + @private_count = @total_count - @public_count + @attachments = @attachments.by_keywords(params[:search]) @attachments = case @user.course_identity(@course) when 5 @@ -32,12 +37,6 @@ class FilesController < ApplicationController @attachments end - @total_count = @attachments.size - @public_count = @attachments.publiced.size - @private_count = @total_count - @public_count - - @attachments = @attachments.by_keywords(params[:search]) - @attachments = @attachments.page(@page).per(@page_size) end From 069571bec2ad5de05dca27ac29a7a8c539007582 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 29 Jun 2019 15:17:46 +0800 Subject: [PATCH 0406/1015] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index afe0e14b6..41ba59be8 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -160,8 +160,8 @@ class ChallengesController < ApplicationController def show @tab = params[:tab].nil? ? 1 : params[:tab].to_i - challenge_num = Challenge.where(shixun_id: @shixun).count - @power = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0 + challenge_num = @shixun.challenges_count + @power = @shixun.status == 0 # 之前验证走过了是不是管理员,因此这里只用判断是否发布 @position = @challenge.position if @position < challenge_num @next_challenge = Challenge.where(:shixun_id => @shixun, :position => @position + 1).first From 6cf53047c35635351ec2f495cc3262b1858d044e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 29 Jun 2019 15:25:24 +0800 Subject: [PATCH 0407/1015] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 41ba59be8..d56c3ecbd 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -138,7 +138,7 @@ class ChallengesController < ApplicationController # tab 0,nil 过关任务, 1 评测设置, 2 参考答案 def edit @tab = params[:tab].to_i - @power = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0 + @power = @shixun.status == 0 challenge_num = Challenge.where(:shixun_id => @shixun).count @position = @challenge.position @chooses = @challenge.challenge_chooses @@ -279,9 +279,6 @@ class ChallengesController < ApplicationController def find_shixun @shixun = Shixun.find_by_identifier(params[:shixun_identifier]) - if !current_user.shixun_permission(@shixun) - tip_exception(403, "..") - end end # 通用接口 From 3c1710eefc7218f1ad82d4c2e3f75c4b8eb15a06 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 15:36:03 +0800 Subject: [PATCH 0408/1015] fix bug --- app/controllers/exercises_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 421c5177a..2fcd7275b 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1418,7 +1418,7 @@ class ExercisesController < ApplicationController :best_counts => best_counts, } - @exercise_questions = @exercise.exercise_questions + @exercise_questions = @exercise.exercise_questions&.includes(:exercise_choices,:exercise_answers,:exercise_standard_answers,:exercise_shixun_challenges,:exercise_shixun_answers) @paging_type = "percent" # 按题型排序 From 133eaf42cb390f68070119668b92e3719d9fe20f Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 15:53:04 +0800 Subject: [PATCH 0409/1015] =?UTF-8?q?=E9=97=AE=E5=8D=B7/=E8=AF=95=E5=8D=B7?= =?UTF-8?q?=E7=9A=84=E5=88=97=E8=A1=A8=E9=A1=B5=EF=BC=8C=E9=A2=84=E8=A7=88?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=8F=8A=E7=BB=9F=E8=AE=A1=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 4 ++-- app/controllers/polls_controller.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 2fcd7275b..8b65d7c70 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -101,7 +101,7 @@ class ExercisesController < ApplicationController @page = params[:page] || 1 @limit = params[:limit] || 15 @exercises = @exercises.page(@page).per(@limit) - @exercises = @exercises.includes(:exercise_users,:exercise_questions,:exercise_group_settings) + @exercises = @exercises&.includes(:exercise_users,:exercise_questions,:exercise_group_settings) else @exercises = [] end @@ -188,7 +188,7 @@ class ExercisesController < ApplicationController else @is_teacher_or = 0 #为学生 end - @exercise_questions = @exercise.exercise_questions.order("question_number ASC") + @exercise_questions = @exercise.exercise_questions&.includes(:exercise_choices,:exercise_shixun_challenges,:exercise_standard_answers).order("question_number ASC") rescue Exception => e uid_logger_error(e.message) tip_exception("试卷创建失败!") diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 6fbba1c3d..cd9679972 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -90,7 +90,7 @@ class PollsController < ApplicationController @limit = params[:limit] || 15 @polls = @polls.page(@page).per(@limit) - @polls = @polls.includes(:poll_users,:poll_questions,:poll_group_settings) + @polls = @polls&.includes(:poll_users,:poll_questions,:poll_group_settings) else @polls = [] @@ -183,7 +183,7 @@ class PollsController < ApplicationController else @is_teacher_or = 0 end - @poll_questions = @poll.poll_questions.order("question_number ASC") + @poll_questions = @poll.poll_questions&.includes(:poll_answers).order("question_number ASC") rescue Exception => e uid_logger_error(e.message) tip_exception("没有权限") @@ -1148,7 +1148,7 @@ class PollsController < ApplicationController end def get_questions_count - @poll_questions = @poll.poll_questions.order("question_number ASC") + @poll_questions = @poll.poll_questions&.includes(:poll_answers,:poll_votes).order("question_number ASC") @poll_questions_count = @poll_questions.count # 全部的题目数 @poll_question_singles = @poll_questions.ques_count(1).all.count # 单选题 @poll_question_doubles = @poll_questions.ques_count(2).all.count # 多选题 From 783e2e1727cd0e29dc529c9eaf78df33dfe3602d Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 16:23:37 +0800 Subject: [PATCH 0410/1015] fix bug --- app/helpers/polls_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index b5ba79dcc..d9b6ccee7 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -110,7 +110,7 @@ module PollsHelper poll_user_name = user.nickname end course_member = course_members.find_by(user_id:user.id) - course_group_id = course_members.present? ? course_member.course_group_id : nil + course_group_id = course_member.present? ? course_member.course_group_id : nil if course_group_id == 0 course_group_name = "未分班" else From ad9e7a58f70e584f7254f5049643e546779969e4 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 29 Jun 2019 17:21:38 +0800 Subject: [PATCH 0411/1015] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 2a2439226..76e15f9e2 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -426,12 +426,12 @@ class GamesController < ApplicationController game_code = GameCode.where(:game_id => @game.try(:id), :path => path).first if game_code.present? content = game_code.try(:new_code) - @content = if @myshixun.mirror_name.select{|a| a.include?("MachineLearning") || a.include?("Python")}.present? && content.present? - content.gsub(/\t/, ' ') - else - content - end - update_file_content(@content, @myshixun.repo_path, path, current_user.mail, current_user.full_name, "game passed reset") + # @content = if @myshixun.mirror_name.select{|a| a.include?("MachineLearning") || a.include?("Python")}.present? && content.present? + # content.gsub(/\t/, ' ') + # else + # content + # end + update_file_content(content, @myshixun.repo_path, path, current_user.mail, current_user.full_name, "game passed reset") else tip_exception("代码重置失败,代码为空") end From 07e7f0d206b7058438b06bb6f94c80a41c483961 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 17:23:40 +0800 Subject: [PATCH 0412/1015] fix bug --- app/controllers/zips_controller.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index a8750fc3d..710846f64 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -52,15 +52,16 @@ class ZipsController < ApplicationController @ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。 #可以分班选择 if group_id.present? - exercise_students = @course.students.course_find_by_ids("course_group_id",group_id) # 试卷所分班的全部人数 - user_ids = exercise_students.pluck(:user_id).reject(&:blank?) - @ex_users = @ex_users.exercise_commit_users(user_ids) + exercise_students = @course.students.where(course_group_id: group_id) # 试卷所分班的全部人数 + user_ids = exercise_students.pluck(:user_id).reject(&:blank?).uniq + logger.info("+++++++##################_________________user_ids_____________#########{user_ids}") + @ex_users = @ex_users.where(user_id: user_ids) end # @ex_users = @ex_users.first(200) if default_ex_users_size == 0 normal_status(-1,"导出失败,暂时没有已提交的学生") - elsif default_ex_users_size > 200 - normal_status(-1,"导出数量超过200,请分班导出或联系网站管理员导出") + elsif default_ex_users_size > 100 + normal_status(-1,"导出数量超过100,请分班导出或联系网站管理员导出") end end rescue Exception => e From c6e1fd3f8d0cb2ffd2078582e1eb00a19f1af684 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 17:26:36 +0800 Subject: [PATCH 0413/1015] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AF=95=E5=8D=B7?= =?UTF-8?q?=E7=9A=84=E7=AD=94=E9=A2=98=E8=AF=95=E5=8D=B7=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/zips_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 710846f64..4de85ec64 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -48,16 +48,16 @@ class ZipsController < ApplicationController @course = @exercise.course default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed - default_ex_users_size = default_ex_users.size @ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。 #可以分班选择 if group_id.present? exercise_students = @course.students.where(course_group_id: group_id) # 试卷所分班的全部人数 user_ids = exercise_students.pluck(:user_id).reject(&:blank?).uniq - logger.info("+++++++##################_________________user_ids_____________#########{user_ids}") @ex_users = @ex_users.where(user_id: user_ids) end - # @ex_users = @ex_users.first(200) + + default_ex_users_size = @ex_users.size + if default_ex_users_size == 0 normal_status(-1,"导出失败,暂时没有已提交的学生") elsif default_ex_users_size > 100 From 15668d41986e7851c9d29ac2719ad4cb986995aa Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 17:49:18 +0800 Subject: [PATCH 0414/1015] fix bug --- app/templates/exercise_export/exercise_user.html.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index c81f45d68..0c1c1bbab 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -9,6 +9,7 @@

+
<%= request.url %>

<%= @exercise.try(:exercise_name) %>

From 9ce0af33704eb849e2f5006f7aef686e7d3f973a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 18:06:25 +0800 Subject: [PATCH 0415/1015] fix bug --- app/controllers/zips_controller.rb | 4 +++- app/services/exercise_user_pdf_service.rb | 3 ++- app/services/export_exercises_service.rb | 5 +++-- app/templates/exercise_export/exercise_user.html.erb | 11 ++++++----- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 4de85ec64..c1ff95abd 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -17,7 +17,7 @@ class ZipsController < ApplicationController end def export_exercises - exercises = ExportExercisesService.new(@exercise,@ex_users) + exercises = ExportExercisesService.new(@exercise,@ex_users,@request_url) file_name = filename_for_content_disposition(exercises.filename) send_file exercises.ex_zip, filename: file_name, type: 'application/zip' @@ -41,6 +41,8 @@ class ZipsController < ApplicationController ActiveRecord::Base.transaction do begin @exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id]) + @request_url = request.base_url + logger.info("######################____________@request_url____________##########################{@request_url}") group_id = params[:exercise_group_id] if @exercise.blank? normal_status(-1,"试卷不存在") diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 22804092e..913d0cfbc 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -5,9 +5,10 @@ class ExerciseUserPdfService attr_reader :exercise, :ex_user - def initialize(exercise, ex_user) + def initialize(exercise, ex_user,request_url) @exercise = exercise @ex_user = ex_user + @request_url = request_url @ex_user_user = @ex_user.user @course = @exercise.course end diff --git a/app/services/export_exercises_service.rb b/app/services/export_exercises_service.rb index 12b5501f9..48bfc9519 100644 --- a/app/services/export_exercises_service.rb +++ b/app/services/export_exercises_service.rb @@ -3,9 +3,10 @@ class ExportExercisesService include StudentWorksHelper attr_reader :exercise, :ex_users - def initialize(exercise, ex_users) + def initialize(exercise, ex_users,request_url) @exercise = exercise @ex_users = ex_users + @request_url = request_url end def filename @@ -18,7 +19,7 @@ class ExportExercisesService pdfs = [] Zip::File.open(zip_file.path, Zip::File::CREATE) do |zip| ex_users.each do |ex_user| - export = ExerciseUserPdfService.new(exercise, ex_user) + export = ExerciseUserPdfService.new(exercise, ex_user,@request_url) pdf = export.ex_pdf pdfs << pdf begin diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 0c1c1bbab..269237520 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -168,15 +168,16 @@ <% end %>
+ <% q_title = q.question_title&.gsub("src='","src='/#{@request_url}") %> + <% if q_type == 5 %> - <%= q.shixun_name&.html_safe %> + <% q_name = q.shixun_name&.gsub("src='","src='/#{@request_url}") %> + <%= q_name&.html_safe %>
- <%= q.question_title&.html_safe %> + <%= q_title&.html_safe %>
- <% elsif q_type == 4 %> - <%= q.question_title&.html_safe %> <% else %> - <%= q.question_title&.html_safe %> + <%= q_title&.html_safe %> <% end %>
From 7dd8189f17368b01d1e9647512364692a5b6259a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 18:08:03 +0800 Subject: [PATCH 0416/1015] fix bug --- app/templates/exercise_export/exercise_user.html.erb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 269237520..df9c4c6ab 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -9,7 +9,6 @@
-
<%= request.url %>

<%= @exercise.try(:exercise_name) %>

From 51dc8ae124d3e5eca4921d5f0134782de39bb94e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 19:31:45 +0800 Subject: [PATCH 0417/1015] =?UTF-8?q?=E5=AF=BC=E5=87=BApdf=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=A0=87=E9=A2=98=E5=9B=BE=E7=89=87=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 1 + app/controllers/zips_controller.rb | 5 ++--- app/services/exercise_user_pdf_service.rb | 4 ++-- app/templates/exercise_export/blank_exercise.html.erb | 8 +++++--- app/templates/exercise_export/exercise_user.html.erb | 5 ++--- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 8b65d7c70..2377f411b 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1334,6 +1334,7 @@ class ExercisesController < ApplicationController #导出空白试卷 def export_exercise @exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") + @request_url = request.base_url filename = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.current.strftime('%Y%m%d%H%M%S')}.pdf" stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css" render pdf: 'exercise_export/blank_exercise', filename: filename, stylesheets: stylesheets diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index c1ff95abd..b23a3e033 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -42,7 +42,6 @@ class ZipsController < ApplicationController begin @exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id]) @request_url = request.base_url - logger.info("######################____________@request_url____________##########################{@request_url}") group_id = params[:exercise_group_id] if @exercise.blank? normal_status(-1,"试卷不存在") @@ -50,12 +49,12 @@ class ZipsController < ApplicationController @course = @exercise.course default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed - @ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。 + @ex_users = default_ex_users.limit 1 #仅导出已提交的,截止后则是全部为提交的。 #可以分班选择 if group_id.present? exercise_students = @course.students.where(course_group_id: group_id) # 试卷所分班的全部人数 user_ids = exercise_students.pluck(:user_id).reject(&:blank?).uniq - @ex_users = @ex_users.where(user_id: user_ids) + @ex_users = @ex_users.where(user_id: user_ids).limit 1 end default_ex_users_size = @ex_users.size diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 913d0cfbc..9b96cd70c 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -38,10 +38,10 @@ class ExerciseUserPdfService kit = PDFKit.new(html) base_css = %w(app/templates/exercise_export/exercise_export.css) base_css.each { |css| kit.stylesheets << Rails.root.join(css) } - #-----正式需删掉 + # #-----正式需删掉 # aa = File.open(Rails.root.join("public/123.html"),"w+") # aa.syswrite(kit.source) - #正式需删掉------- + # #正式需删掉------- file = Tempfile.new(filename) kit.to_pdf(file.path) file diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 2745f8cbe..95a92358f 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -68,13 +68,15 @@ (<%= q&.question_score %>分)
+ <% q_title = q.question_title&.include?("src=\"") ? q.question_title&.gsub("src=\"","src=\"#{@request_url}") : q.question_title %> <% if q.question_type == 5 %> - <%= q.shixun_name.present? ? q.shixun_name&.html_safe : "" %> + <% q_name = q.shixun_name&.include?("src=\"") ? q.shixun_name&.gsub("src=\"","src=\"#{@request_url}") : q.shixun_name %> + <%= q_name&.html_safe %>
- <%= q.question_title.present? ? q.question_title&.html_safe : "" %> + <%= q_title&.html_safe %>
<% else %> - <%= q.question_title.present? ? q.question_title&.html_safe : "" %> + <%= q_title&.html_safe %> <% end %>
diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index df9c4c6ab..42758af77 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -167,10 +167,9 @@ <% end %>
- <% q_title = q.question_title&.gsub("src='","src='/#{@request_url}") %> - + <% q_title = q.question_title&.include?("src=\"") ? q.question_title&.gsub("src=\"","src=\"#{@request_url}") : q.question_title %> <% if q_type == 5 %> - <% q_name = q.shixun_name&.gsub("src='","src='/#{@request_url}") %> + <% q_name = q.shixun_name&.include?("src=\"") ? q.shixun_name&.gsub("src=\"","src=\"#{@request_url}") : q.shixun_name %> <%= q_name&.html_safe %>
<%= q_title&.html_safe %> From fba4bf318488bcd1df5eeea72e55048062625e91 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 29 Jun 2019 19:33:33 +0800 Subject: [PATCH 0418/1015] fix bug --- app/controllers/zips_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index b23a3e033..77a41d065 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -49,12 +49,12 @@ class ZipsController < ApplicationController @course = @exercise.course default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed - @ex_users = default_ex_users.limit 1 #仅导出已提交的,截止后则是全部为提交的。 + @ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。 #可以分班选择 if group_id.present? exercise_students = @course.students.where(course_group_id: group_id) # 试卷所分班的全部人数 user_ids = exercise_students.pluck(:user_id).reject(&:blank?).uniq - @ex_users = @ex_users.where(user_id: user_ids).limit 1 + @ex_users = @ex_users.where(user_id: user_ids) end default_ex_users_size = @ex_users.size From e3dbe6c5734fe337a48fe6df350b5704bbf38e98 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 09:11:08 +0800 Subject: [PATCH 0419/1015] fix bug --- app/templates/exercise_export/blank_exercise.html.erb | 10 +++++----- app/templates/exercise_export/exercise_user.html.erb | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 95a92358f..74cea75f1 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -68,15 +68,15 @@ (<%= q&.question_score %>分)
- <% q_title = q.question_title&.include?("src=\"") ? q.question_title&.gsub("src=\"","src=\"#{@request_url}") : q.question_title %> + <% q_title = q.question_title&.html_safe %> <% if q.question_type == 5 %> - <% q_name = q.shixun_name&.include?("src=\"") ? q.shixun_name&.gsub("src=\"","src=\"#{@request_url}") : q.shixun_name %> - <%= q_name&.html_safe %> + <% q_name = q.shixun_name&.html_safe %> + <%= q_name&.include?("src=\"") ? q_name&.gsub("src=\"","src=\"#{@request_url}") : q_name %>
- <%= q_title&.html_safe %> + <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %>
<% else %> - <%= q_title&.html_safe %> + <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %> <% end %>
diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 42758af77..5770c5921 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -167,15 +167,15 @@ <% end %>
- <% q_title = q.question_title&.include?("src=\"") ? q.question_title&.gsub("src=\"","src=\"#{@request_url}") : q.question_title %> + <% q_title = q.question_title&.html_safe %> <% if q_type == 5 %> - <% q_name = q.shixun_name&.include?("src=\"") ? q.shixun_name&.gsub("src=\"","src=\"#{@request_url}") : q.shixun_name %> - <%= q_name&.html_safe %> + <% q_name = q.shixun_name&.html_safe %> + <%= q_name&.include?("src=\"") ? q_name&.gsub("src=\"","src=\"#{@request_url}") : q_name %>
- <%= q_title&.html_safe %> + <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %>
<% else %> - <%= q_title&.html_safe %> + <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %> <% end %>
From 04bbbc7319175eb83c609454d226d54dd7358535 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Mon, 1 Jul 2019 09:49:48 +0800 Subject: [PATCH 0420/1015] =?UTF-8?q?challenges=20=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index afe0e14b6..bad438fdf 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -150,9 +150,8 @@ class ChallengesController < ApplicationController def index uid_logger("identifier: #{params}") - # 通过调试发现 这里includes(:games)性能会慢10倍 - current_myshixun = @shixun.current_myshixun(current_user.id) - @challenges = @shixun.challenges.includes(:games).where("games.user_id" => (current_myshixun ? current_user.id : nil)) + + @challenges = Challenge.fields_for_list.where(shixun_id: @shixun.id) @editable = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0 @user = current_user From b29d4063a87c1fcbc09c7c46bfcc8c2639b3cdcd Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 09:53:58 +0800 Subject: [PATCH 0421/1015] fix bug --- .../exercise_export/blank_exercise.html.erb | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 74cea75f1..995d04995 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -57,7 +57,7 @@
- <% @exercise_questions.each do |q| %> + <% @exercise_questions.each_with_index do |q,index| %>
@@ -68,15 +68,27 @@ (<%= q&.question_score %>分)
- <% q_title = q.question_title&.html_safe %> + <% q_title = q.question_title&.include?("src=\"") ? q.question_title&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q.question_title&.html_safe %> <% if q.question_type == 5 %> - <% q_name = q.shixun_name&.html_safe %> - <%= q_name&.include?("src=\"") ? q_name&.gsub("src=\"","src=\"#{@request_url}") : q_name %> + <% q_name = q.shixun_name&.include?("src=\"") ? q.shixun_name&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q.shixun_name&.html_safe %> + <%= q_name %>
- <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %> + <%= q_title %>
+ <% else %> - <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %> + <%= q_title %> + <% end %>
@@ -134,4 +146,6 @@
+<%= ApplicationController.helpers.pdf_load_sources(*%w(react/public/js/jquery-1.8.3.min.js react/public/js/editormd/marked.min.js))%> + \ No newline at end of file From 93d18fac5dbba3bd15d925dcc958c42b681b06dd Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:12:26 +0800 Subject: [PATCH 0422/1015] fix bug --- Gemfile | 2 ++ Gemfile.lock | 2 ++ app/helpers/application_helper.rb | 12 +++++++++++ .../exercise_export/blank_exercise.html.erb | 21 +++++-------------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Gemfile b/Gemfile index 31af87f14..b8b174a6f 100644 --- a/Gemfile +++ b/Gemfile @@ -39,6 +39,8 @@ gem 'pdfkit' gem 'wkhtmltopdf-binary' #gem 'iconv' +# markdown 转html +gem 'redcarpet', '~> 3.4' gem 'rqrcode', '~> 0.10.1' gem 'rqrcode_png' diff --git a/Gemfile.lock b/Gemfile.lock index 83bd79628..86f524bc2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -193,6 +193,7 @@ GEM rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) rchardet (1.8.0) + redcarpet (3.4.0) redis (4.1.0) redis-actionpack (5.0.2) actionpack (>= 4.0, < 6) @@ -328,6 +329,7 @@ DEPENDENCIES rails (~> 5.2.0) rails-i18n (~> 5.1) rchardet (~> 1.8) + redcarpet (~> 3.4) redis-rails roo-xls rqrcode (~> 0.10.1) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index d8ea8cd60..8d92362cc 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -334,6 +334,18 @@ module ApplicationHelper raw arr.join('') end + def to_markdown(text) + nil if text.blank? + html_render_options = { + fenced_code_blocks: true, + tables: true, + autolink: true + } + + markdown = Redcarpet::Markdown.new(html_render_options) + raw markdown.render(h(text)).html_safe + end + end diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 995d04995..bdb86d9d9 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -57,7 +57,7 @@
- <% @exercise_questions.each_with_index do |q,index| %> + <% @exercise_questions.each do |q| %>
@@ -68,27 +68,17 @@ (<%= q&.question_score %>分)
- <% q_title = q.question_title&.include?("src=\"") ? q.question_title&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q.question_title&.html_safe %> + <% q_markdown = to_markdown(q.question_title) %> + <% q_title = q_markdown&.include?("src=\"") ? q_markdown&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q_markdown %> <% if q.question_type == 5 %> - <% q_name = q.shixun_name&.include?("src=\"") ? q.shixun_name&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q.shixun_name&.html_safe %> + <% q_markdown_name = to_markdown(q.shixun_name) %> + <% q_name = q_markdown_name&.include?("src=\"") ? q_markdown_name&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q_markdown_name %> <%= q_name %>
<%= q_title %>
- <% else %> <%= q_title %> - <% end %>
@@ -146,6 +136,5 @@
-<%= ApplicationController.helpers.pdf_load_sources(*%w(react/public/js/jquery-1.8.3.min.js react/public/js/editormd/marked.min.js))%> \ No newline at end of file From 4f21bcb3bb479f43b08ba755dbcd3e5e947a2255 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:17:09 +0800 Subject: [PATCH 0423/1015] fix bug --- app/helpers/application_helper.rb | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8d92362cc..34848fd51 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -335,15 +335,19 @@ module ApplicationHelper end def to_markdown(text) - nil if text.blank? - html_render_options = { - fenced_code_blocks: true, - tables: true, - autolink: true + return nil if text.blank? + options = { + :autolink => true, + :no_intra_emphasis => true, + :fenced_code_blocks => true, + :lax_html_blocks => true, + :strikethrough => true, + :superscript => true, + :tables => true } - markdown = Redcarpet::Markdown.new(html_render_options) - raw markdown.render(h(text)).html_safe + markdown = Redcarpet::Markdown.new(options) + markdown.render(h(text)).html_safe end end From 5bfd514211a3ab67621230684ef04c3990373bb4 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:22:03 +0800 Subject: [PATCH 0424/1015] fix bug --- app/helpers/application_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 34848fd51..acb1089ec 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -346,7 +346,7 @@ module ApplicationHelper :tables => true } - markdown = Redcarpet::Markdown.new(options) + markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) markdown.render(h(text)).html_safe end From a6ea8d139a1c9861701d28bfbfa498f76e46d3f9 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:23:02 +0800 Subject: [PATCH 0425/1015] fix bug --- app/helpers/application_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index acb1089ec..055731168 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -347,7 +347,7 @@ module ApplicationHelper } markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) - markdown.render(h(text)).html_safe + markdown.render(text).html_safe end end From 1044209d4f995b3c6bee369b183986d53e9f1160 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 1 Jul 2019 10:25:14 +0800 Subject: [PATCH 0426/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 18 ++++++++++++++++++ app/controllers/challenges_controller.rb | 4 ++-- app/controllers/games_controller.rb | 6 +++--- app/controllers/myshixuns_controller.rb | 2 +- app/controllers/shixuns_controller.rb | 16 ++++++++++++++++ app/models/challenge.rb | 2 +- app/models/shixun.rb | 2 ++ app/models/shixun_service_config.rb | 4 ++++ app/views/challenges/edit.json.jbuilder | 2 +- spec/models/shixun_service_config_spec.rb | 5 +++++ 10 files changed, 53 insertions(+), 8 deletions(-) create mode 100644 app/models/shixun_service_config.rb create mode 100644 spec/models/shixun_service_config_spec.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index afe2129a9..cbd2962b6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -427,6 +427,24 @@ class ApplicationController < ActionController::Base container.to_json end + # 实训中间层pod配置 + def shixun_container_limit shixun + container = [] + shixun.shixun_service_configs.each do |config| + mirror = config.mirror_repository + if mirror.name.present? + container << {:image => mirror.name, + :cpuLimit => config.cpu_limit, + :cpuRequest => config.lower_cpu_limit, + :memoryLimit => "#{config.memory_limit}M", + :memoryRequest => "#{config.request_limit}M", + :resourceLimit => "#{config.resource_limit}K", + :type => mirror.try(:main_type) == "1" ? "main" : "sub"} + end + end + container.to_json + end + # 毕设任务列表的赛选 def course_work(task, **option) logger.info("#############{option}") diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index d56c3ecbd..856afeb01 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -154,7 +154,7 @@ class ChallengesController < ApplicationController current_myshixun = @shixun.current_myshixun(current_user.id) @challenges = @shixun.challenges.includes(:games).where("games.user_id" => (current_myshixun ? current_user.id : nil)) - @editable = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0 + @editable = @shixun.status == 0 # before_action:有判断权限,如果没发布,则肯定是管理人员 @user = current_user end @@ -290,7 +290,7 @@ class ChallengesController < ApplicationController def challenge_params params.require(:challenge).permit(:subject, :task_pass, :difficulty, :score, :st, :modify_time, :test_set_average, :path, :exec_path, :show_type, :original_picture_path, :test_set_score, - :expect_picture_path, :picture_path, :web_route, :answer) + :expect_picture_path, :picture_path, :web_route, :answer, :exec_time) end def chooce_params diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 76e15f9e2..7e7b6e082 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -33,7 +33,7 @@ class GamesController < ApplicationController is_teacher = @user.is_teacher? # 实训超时设置 - time_limit = @shixun.exec_time + time_limit = game_challenge.exec_time # 上一关、下一关 prev_game = @game.prev_of_current_game(@shixun.id, @game.myshixun_id, game_challenge.position) @@ -66,7 +66,7 @@ class GamesController < ApplicationController shixun_tomcat = edu_setting('cloud_bridge') service_host = edu_setting('vnc_url') uri = "#{shixun_tomcat}/bridge/vnc/getvnc" - params = {tpiID: @myshixun.id, :containers => "#{Base64.urlsafe_encode64(container_limit(@shixun.mirror_repositories))}"} + params = {tpiID: @myshixun.id, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(@shixun))}"} res = uri_post uri, params if res && res['code'].to_i != 0 raise("实训云平台繁忙(繁忙等级:99)") @@ -547,7 +547,7 @@ class GamesController < ApplicationController br_params = {:tpiID => "#{@myshixun.id}", :tpiGitURL => "#{gitUrl}", :buildID => "#{@game.id}", :instanceChallenge => "#{step}", :testCases => "#{testCases}", :resubmit => "#{resubmit}", :times => params[:first].to_i, :podType => @shixun.webssh, :content_modified => content_modified, - :containers => "#{Base64.urlsafe_encode64(container_limit(@shixun.mirror_repositories))}", + :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(@shixun))}", :persistenceName => @shixun.identifier, :tpmScript => "#{tpmScript}", :timeLimit => "#{@shixun.exec_time}", :isPublished => (@shixun.status < 2 ? 0 : 1) } diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index a4a3b7222..909533301 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -217,7 +217,7 @@ class MyshixunsController < ApplicationController shixun_tomcat = edu_setting('tomcat_webssh') uri = "#{shixun_tomcat}/bridge/webssh/getConnectInfo" params = {tpiID:@myshixun.id, podType:@myshixun.shixun.try(:webssh), - containers:(Base64.urlsafe_encode64(container_limit @myshixun.shixun.mirror_repositories))} + containers:(Base64.urlsafe_encode64(shixun_container_limit @myshixun.shixun))} res = uri_post uri, params if res && res['code'].to_i != 0 tip_exception("实训云平台繁忙(繁忙等级:92)") diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index b3069bc5d..f079aed1e 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -315,9 +315,13 @@ class ShixunsController < ApplicationController # 镜像-实训关联表 ShixunMirrorRepository.create!(:shixun_id => @shixun.id, :mirror_repository_id => main_type.to_i) if main_type.present? + # 实训主镜像服务配置 + ShixunServiceConfig.create!(:shixun_id => @shixun.id, :mirror_repository_id => main_type.to_i) if sub_type.present? sub_type.each do |mirror| ShixunMirrorRepository.create!(:shixun_id => @shixun.id, :mirror_repository_id => mirror) + # 实训子镜像服务配置 + ShixunServiceConfig.create!(:shixun_id => @shixun.id, :mirror_repository_id => mirror) end end @@ -395,6 +399,18 @@ class ShixunsController < ApplicationController use_scope = 0 end @shixun.update_attributes!(:use_scope => use_scope) + # 超级管理员和运营人员才能保存 中间层服务器pod信息的配置 + if current_user.admin? || current_user.business? + @shixun.shixun_service_configs.destroy_all + params[:mirror_id].each_with_index do |mirror_id, index| + ShixunServiceConfig.create!(:shixun_id => @shixun.id, + :cpu_limit => params[:cpu_limit][index], + :lower_cpu_limit => params[:lower_cpu_limit][index], + :memory_limit => params[:memory_limit][index], + :request_limit => params[:request_limit][index], + :mirror_repository_id => mirror_id) + end + end rescue Exception => e uid_logger_error(e.message) tip_exception("实训保存失败") diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 07a49196d..18b177e1c 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -20,7 +20,7 @@ class Challenge < ApplicationRecord # acts_as_attachable scope :base_attrs, -> { select([:id, :subject, :position, :shixun_id, :st, :score, :path, :task_pass, :modify_time, - :web_route, :answer]) } + :web_route, :answer, :exec_time]) } scope :choose_type, -> { where(st: 1) } scope :practice_type, -> { where(st: 0) } diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 556a4400f..18d5c5fae 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -30,6 +30,8 @@ class Shixun < ApplicationRecord has_one :shixun_info, dependent: :destroy belongs_to :user + # 实训服务配置 + has_many :shixun_service_configs, :dependent => :destroy scope :search_by_name, ->(keyword) { where("name like ? or description like ? ", diff --git a/app/models/shixun_service_config.rb b/app/models/shixun_service_config.rb new file mode 100644 index 000000000..6d106fc07 --- /dev/null +++ b/app/models/shixun_service_config.rb @@ -0,0 +1,4 @@ +class ShixunServiceConfig < ApplicationRecord + belongs_to :shixun + belongs_to :mirror_repository +end diff --git a/app/views/challenges/edit.json.jbuilder b/app/views/challenges/edit.json.jbuilder index 64848a4e6..2774b5a05 100644 --- a/app/views/challenges/edit.json.jbuilder +++ b/app/views/challenges/edit.json.jbuilder @@ -7,7 +7,7 @@ json.chooses do end if @tab == 0 # 本关任务tab的编辑模式 - json.(@challenge, :id, :subject, :task_pass, :difficulty, :score) + json.(@challenge, :id, :subject, :task_pass, :difficulty, :score, :exec_time) json.tags @challenge.challenge_tags.map(&:name) elsif @tab == 1 # 评测设置的编辑模式 diff --git a/spec/models/shixun_service_config_spec.rb b/spec/models/shixun_service_config_spec.rb new file mode 100644 index 000000000..d79cd19f7 --- /dev/null +++ b/spec/models/shixun_service_config_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe ShixunServiceConfig, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 3533f2e7b6204fc033dacd9c3106648e52b9200e Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 1 Jul 2019 10:30:19 +0800 Subject: [PATCH 0427/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E7=9A=84=E8=AE=A1=E7=AE=97=E6=88=90=E7=BB=A9=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 119 ++++++------------ app/services/homeworks_service.rb | 63 ++++++++++ .../_homework_public_navigation.json.jbuilder | 1 + .../homework_commons/works_list.json.jbuilder | 7 +- config/routes.rb | 2 + ...013243_add_calculation_time_to_homework.rb | 6 + 6 files changed, 115 insertions(+), 83 deletions(-) create mode 100644 db/migrate/20190701013243_add_calculation_time_to_homework.rb diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 2a1dfb14a..8ce99cb79 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -186,6 +186,7 @@ class HomeworkCommonsController < ApplicationController @work_count = @student_works.size @work_excel = @student_works + @students = @course.students # 分页参数 page = params[:page] || 1 @@ -236,94 +237,51 @@ class HomeworkCommonsController < ApplicationController end def update_score - student_works = @homework.student_works - myshixuns = Myshixun.where(shixun_id: @homework.homework_commons_shixun&.shixun_id, user_id: @course.students.pluck(:user_id)) - myshixuns = Myshixun.where(shixun_id: @homework.homework_commons_shixun&.shixun_id). - joins("join course_members on myshixuns.user_id=course_members.user_id").where(course_members: {course_id: @course.id, role: 4}).includes(:games) - myshixuns.find_each(batch_size: 100) do |myshixun| - work = student_works.select{|work| work.user_id == myshixun.user_id}.first - setting_time = @homework.homework_group_setting work.user_id - - if setting_time.end_time.present? && (setting_time.end_time > Time.now || (@homework.allow_late && @homework.late_time && @homework.late_time > Time.now)) - #logger.info("#############setting_time: #{setting_time.end_time}") - - user_total_score = 0 - pass_consume_time = 0 - final_score = 0 - homework.homework_challenge_settings.each do |setting| - game = myshixun.games.where(:challenge_id => setting.challenge_id, :status => 2).first - unless game.nil? - pass_consume_time += (game.cost_time / 60.0).to_f - user_total_score += game.final_score.to_i < 0 ? 0 : game.challenge.score.to_i - adjust_score = work.challenge_work_scores.where(:challenge_id => setting.challenge_id).last - final_score += adjust_score.present? ? adjust_score.score : (homework.homework_detail_manual.answer_open_evaluation ? setting.score : (game.final_score > 0 ? game.real_score(setting.score) : 0)) - end - end - if work.work_status == 0 - is_complete = myshixun.is_complete? && (myshixun.done_time < setting_time.end_time) - work.work_status = setting_time.end_time > Time.now ? 1 : (is_complete ? 1 : 2) - work.late_penalty = setting_time.end_time > Time.now ? 0 : (is_complete ? 0 : homework.late_penalty) - work.commit_time = myshixun.created_at > setting_time.publish_time ? setting_time.publish_time : myshixun.created_at - work.myshixun_id = myshixun.id - end - - games = myshixun.games.where(:challenge_id => homework.homework_challenge_settings.map(&:challenge_id)) - myshixun_endtime = games.select{|game| game.status == 2}.size == games.size ? games.map(&:end_time).max : nil - if myshixun_endtime.present? - min_efficiency_changed = min_efficiency_changed.present? ? min_efficiency_changed : false - work.compelete_status = 1 - work.cost_time = myshixun_endtime.to_i - setting_time.publish_time.to_i - - efficiency = (pass_consume_time == 0 ? 0 : Math.log((user_total_score / pass_consume_time.to_f) + 1.0)) - work.efficiency = format("%.2f", efficiency) + begin + if @homework.unified_setting + student_works = @homework.student_works + user_ids = @course.students.pluck(:user_id) + else + user_ids = @course.students.where(course_group_id: @homework.published_settings.pluck(:course_group_id)).pluck(:user_id) + student_works = @homework.student_works.where(user_id: user_ids) + end - # 如果作业的最大效率值有变更则更新所有作品的效率分 - if homework.work_efficiency && homework.max_efficiency < work.efficiency - homework.update_column("max_efficiency", work.efficiency) - end + myshixuns = Myshixun.where(shixun_id: params[:shixun_id], user_id: user_ids). + includes(:games).where(games: {challenge_id: @homework.homework_challenge_settings.pluck(:challenge_id)}) + challenge_settings = @homework.homework_challenge_settings + myshixuns.find_each(batch_size: 100) do |myshixun| + work = student_works.select{|work| work.user_id == myshixun.user_id}.first + if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at) + games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id)) + HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings end - - work.update_time = Time.now - - work.final_score = final_score - score = work.final_score + work.eff_score - work.late_penalty - work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) unless work.ultimate_score - #logger.info("#############work_score: #{score}") - work.save! end - end - @homework.student_works.each do || - + @homework.update_attribute('calculation_time', Time.now) + normal_status("更新成功") + rescue Exception => e + uid_logger(e.message) + tip_exception(e.message) + raise ActiveRecord::Rollback end end def update_student_score - work = @homework.students_works.find_by(user_id: current_user.id) + work = @homework.student_works.find_by(user_id: current_user.id) myshixun = Myshixun.find_by(shixun_id: params[:shixun_id], user_id: current_user.id) - if work && myshixun - # 判断作品是否关联过myshixun - if work.myshixun_id.nil? - work.myshixun_id = myshixun.id - work.update_time = myshixun.updated_at - setting_time = @homework.homework_group_setting myshixun.user_id - games = myshixun.games.where(:challenge_id => @homework.homework_challenge_settings.pluck(:challenge_id)) - myshixun_endtime = games.select{|game| game.status == 2}.size == games.size ? games.map(&:end_time).max : nil - compelete_status = 0 - if myshixun_endtime.present? && myshixun_endtime < setting_time.end_time - if myshixun_endtime < setting_time.publish_time - compelete_status = 2 - else - compelete_status = 1 - end - end - games.each do |game| - unless game.nil? - pass_consume_time += (game.cost_time / 60.0).to_f - user_total_score += game.final_score.to_i < 0 ? 0 : game.challenge.score.to_i - adjust_score = work.challenge_work_scores.where(:challenge_id => setting.challenge_id).last - final_score += adjust_score.present? ? adjust_score.score : (homework.homework_detail_manual.answer_open_evaluation ? setting.score : (game.final_score > 0 ? game.real_score(setting.score) : 0)) - end + ActiveRecord::Base.transaction do + begin + if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at) + challenge_settings = @homework.homework_challenge_settings + games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id)) + HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings + normal_status("更新成功") + else + normal_status("已是最新成绩") end + rescue Exception => e + uid_logger(e.message) + tip_exception(e.message) + raise ActiveRecord::Rollback end end end @@ -1036,7 +994,7 @@ class HomeworkCommonsController < ApplicationController if homework.course_acts.size == 0 homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id) end - + # 发消息 HomeworkCommonPushNotifyJob.perform_later(homework.id, tiding_group_ids) else create_homework_group_settings(homework) @@ -1057,6 +1015,7 @@ class HomeworkCommonsController < ApplicationController homework.save! + # 更新学生状态及成绩 HomeworkPublishUpdateWorkStatusJob.perform_later(tiding_group_ids, homework.id) end normal_status(0, "发布成功") diff --git a/app/services/homeworks_service.rb b/app/services/homeworks_service.rb index 1e155dde0..48db76295 100644 --- a/app/services/homeworks_service.rb +++ b/app/services/homeworks_service.rb @@ -272,4 +272,67 @@ class HomeworksService end end end + + # 计算实训作品成绩 + def update_myshixun_work_score work, myshixun, games, homework, challenge_settings + user_total_score = 0 + pass_consume_time = 0 + final_score = 0 + setting_time = homework.homework_group_setting myshixun.user_id + homework_end_or_late_time = homework.allow_late ? homework.late_time : setting_time.end_time + games.each do |game| + # 在截止时间前通关的关卡才考虑得分 + if game.status == 2 && game.end_time <= homework_end_or_late_time + challenge_setting = challenge_settings.select{|setting| setting.challenge_id == game.challenge_id}.first + pass_consume_time += (game.cost_time / 60.0).to_f + user_total_score += game.final_score.to_i < 0 ? 0 : game.challenge.score.to_i + adjust_score = work.challenge_work_scores.where(:challenge_id => game.challenge_id).last + final_score += if adjust_score.present? + adjust_score.score + elsif homework.homework_detail_manual.answer_open_evaluation + challenge_setting.score + elsif game.final_score > 0 + game.real_score(challenge_setting.score) + else + 0 + end + end + end + + myshixun_endtime = games.select{|game| game.status == 2}.size == games.size ? games.map(&:end_time).max : nil + if myshixun_endtime.present? + work.cost_time = myshixun_endtime.to_i - setting_time.publish_time.to_i + + efficiency = (pass_consume_time == 0 ? 0 : Math.log((user_total_score / pass_consume_time.to_f) + 1.0)) + work.efficiency = format("%.2f", efficiency) + + if myshixun_endtime <= homework_end_or_late_time + work.compelete_status = myshixun_endtime < setting_time.publish_time ? 2 : 1 + + # 如果作业的最大效率值有变更则更新所有作品的效率分 + homework.update_column("max_efficiency", work.efficiency) if homework.work_efficiency && homework.max_efficiency < work.efficiency + end + end + + if work.work_status == 0 + is_complete = myshixun_endtime && (myshixun_endtime < setting_time.end_time) + if is_complete || (!homework.allow_late && myshixun.created_at < setting_time.end_time) + work.work_status = 1 + elsif homework.allow_late && myshixun.created_at < homework.late_time + work.work_status = 2 + end + work.late_penalty = work.work_status == 2 ? homework.late_penalty : 0 + work.commit_time = myshixun.created_at > setting_time.publish_time ? setting_time.publish_time : myshixun.created_at + work.myshixun_id = myshixun.id + end + + work.update_time = myshixun.updated_at + + work.final_score = final_score + score = work.final_score + work.eff_score - work.late_penalty + work.work_score = format("%.2f",(score < 0 ? 0 : score).to_f) unless work.ultimate_score + #logger.info("#############work_score: #{score}") + work.calculation_time = Time.now + work.save! + end end \ No newline at end of file diff --git a/app/views/homework_commons/_homework_public_navigation.json.jbuilder b/app/views/homework_commons/_homework_public_navigation.json.jbuilder index 2c548074c..243c6aecd 100644 --- a/app/views/homework_commons/_homework_public_navigation.json.jbuilder +++ b/app/views/homework_commons/_homework_public_navigation.json.jbuilder @@ -11,4 +11,5 @@ json.homework_id homework.id json.homework_type homework.homework_type if homework.homework_type == "practice" json.shixun_identifier homework.shixuns.take.try(:identifier) + json.shixun_id homework.shixuns.take.try(:id) end diff --git a/app/views/homework_commons/works_list.json.jbuilder b/app/views/homework_commons/works_list.json.jbuilder index 60441909b..f740959d0 100644 --- a/app/views/homework_commons/works_list.json.jbuilder +++ b/app/views/homework_commons/works_list.json.jbuilder @@ -13,6 +13,7 @@ json.ta_mode @homework_detail_manual.ta_mode json.is_evaluation @is_evaluation ? @is_evaluation : false json.work_public @homework.work_public +json.calculation_time @homework.calculation_time if @homework.homework_type == "practice" if @user_course_identity < Course::STUDENT @@ -30,7 +31,7 @@ elsif @user_course_identity == Course::STUDENT if @homework.homework_type == "practice" json.(@work, :id, :work_status, :update_time, :ultimate_score) - + json.calculation_time @work.calculation_time json.late_penalty @work.late_penalty if @homework.allow_late json.cost_time @work.myshixun.try(:total_cost_time) json.work_score work_score_format(@work.work_score, true, @score_open) @@ -94,7 +95,7 @@ if @homework.homework_type == "practice" json.user_login work.user.try(:login) json.user_name work.user.try(:real_name) json.student_id work.user.try(:student_id) - json.group_name @course.course_student(work.user_id).try(:course_group_name) + json.group_name @students.select{|student| student.user_id == work.user_id}.first.try(:course_group_name) end elsif @homework.homework_type == "group" || @homework.homework_type == "normal" json.anonymous_comment @homework.anonymous_comment @@ -133,7 +134,7 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal" end json.student_id work.user.try(:student_id) - json.group_name @course.course_student(work.user_id).try(:course_group_name) + json.group_name @students.select{|student| student.user_id == work.user_id}.first.try(:course_group_name) if @homework.homework_type == "group" if @homework.homework_detail_group.base_on_project json.project_info project_info work, @current_user, @user_course_identity diff --git a/config/routes.rb b/config/routes.rb index f81d90267..0f47cda76 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -338,6 +338,8 @@ Rails.application.routes.draw do get :publish_groups get :end_groups post :alter_name + get :update_score + get :update_student_score end collection do diff --git a/db/migrate/20190701013243_add_calculation_time_to_homework.rb b/db/migrate/20190701013243_add_calculation_time_to_homework.rb new file mode 100644 index 000000000..4a622ee92 --- /dev/null +++ b/db/migrate/20190701013243_add_calculation_time_to_homework.rb @@ -0,0 +1,6 @@ +class AddCalculationTimeToHomework < ActiveRecord::Migration[5.2] + def change + add_column :homework_commons, :calculation_time, :datetime + add_column :student_works, :calculation_time, :datetime + end +end From 9c7523a8527679f1711f63ebb4de3d9b4da29e4c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:31:00 +0800 Subject: [PATCH 0428/1015] fix bug --- app/helpers/application_helper.rb | 3 +-- app/templates/exercise_export/blank_exercise.html.erb | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 055731168..f77e9a313 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -345,9 +345,8 @@ module ApplicationHelper :superscript => true, :tables => true } - markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) - markdown.render(text).html_safe + markdown.render(text) end end diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index bdb86d9d9..63b7fb8bc 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -75,10 +75,10 @@ <% q_name = q_markdown_name&.include?("src=\"") ? q_markdown_name&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q_markdown_name %> <%= q_name %>
- <%= q_title %> + <%= q_markdown %>
<% else %> - <%= q_title %> + <%= q_markdown %> <% end %>
From 5db1bbd18a8fcd73d28c414a044fc77533582ca2 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:33:57 +0800 Subject: [PATCH 0429/1015] fix bug --- app/helpers/application_helper.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f77e9a313..cb2f487cb 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -335,6 +335,7 @@ module ApplicationHelper end def to_markdown(text) + Rails.logger.info("#########################text______________tedxt_________________###{text}") return nil if text.blank? options = { :autolink => true, @@ -346,7 +347,10 @@ module ApplicationHelper :tables => true } markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) - markdown.render(text) + ss = markdown.render(text) + Rails.logger.info("#########################text______________markdown.render(text)________________###{ss}") + ss + end end From 53b0f2efcd8b6810278ffe8d5ccb1558b3a299ec Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 1 Jul 2019 10:37:05 +0800 Subject: [PATCH 0430/1015] =?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/views/homework_commons/works_list.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/homework_commons/works_list.json.jbuilder b/app/views/homework_commons/works_list.json.jbuilder index f740959d0..a7dc292b8 100644 --- a/app/views/homework_commons/works_list.json.jbuilder +++ b/app/views/homework_commons/works_list.json.jbuilder @@ -13,10 +13,10 @@ json.ta_mode @homework_detail_manual.ta_mode json.is_evaluation @is_evaluation ? @is_evaluation : false json.work_public @homework.work_public -json.calculation_time @homework.calculation_time if @homework.homework_type == "practice" if @user_course_identity < Course::STUDENT + json.calculation_time @homework.calculation_time if @homework.homework_type == "practice" # 教师身份的评阅、提交状态、分班过滤 if @homework.homework_type != "practice" json.teacher_comment teacher_comment @homework, @current_user.id From 6110df20bd10d12b72ad2c125c6377b12cb0f810 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:38:47 +0800 Subject: [PATCH 0431/1015] fix bug --- app/helpers/application_helper.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cb2f487cb..df024264e 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -336,6 +336,8 @@ module ApplicationHelper def to_markdown(text) Rails.logger.info("#########################text______________tedxt_________________###{text}") + Rails.logger.info("#########################text______________request_base_url________________###{request.base_url}") + return nil if text.blank? options = { :autolink => true, @@ -347,10 +349,10 @@ module ApplicationHelper :tables => true } markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) - ss = markdown.render(text) - Rails.logger.info("#########################text______________markdown.render(text)________________###{ss}") - ss - + m_t = markdown.render(text) + q_title = m_t &.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : m_t + Rails.logger.info("#########################text______________markdown.render(text)________________###{q_title }") + q_title end end From b320715e6e9ff22b45cf5e742337b309a2f02ea7 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:45:45 +0800 Subject: [PATCH 0432/1015] fix bug --- app/helpers/application_helper.rb | 9 ++++----- .../exercise_export/blank_exercise.html.erb | 14 ++++++-------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index df024264e..67e899820 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -335,8 +335,7 @@ module ApplicationHelper end def to_markdown(text) - Rails.logger.info("#########################text______________tedxt_________________###{text}") - Rails.logger.info("#########################text______________request_base_url________________###{request.base_url}") + request_url = request.base_url return nil if text.blank? options = { @@ -350,9 +349,9 @@ module ApplicationHelper } markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) m_t = markdown.render(text) - q_title = m_t &.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : m_t - Rails.logger.info("#########################text______________markdown.render(text)________________###{q_title }") - q_title + ss = m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{request_url}")&.html_safe : m_t + Rails.logger.info("############_____________ss________________##################{ss}") + ss end end diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 63b7fb8bc..d562224da 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -69,16 +69,14 @@
<% q_markdown = to_markdown(q.question_title) %> - <% q_title = q_markdown&.include?("src=\"") ? q_markdown&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q_markdown %> <% if q.question_type == 5 %> <% q_markdown_name = to_markdown(q.shixun_name) %> - <% q_name = q_markdown_name&.include?("src=\"") ? q_markdown_name&.gsub("src=\"","src=\"#{@request_url}")&.html_safe : q_markdown_name %> - <%= q_name %> + <%= q_markdown_name %>
- <%= q_markdown %> + <%= q_markdown %>
<% else %> - <%= q_markdown %> + <%= q_markdown %> <% end %>
@@ -86,14 +84,14 @@ <% q.exercise_choices.each_with_index do |s,index| %>

- <%= convert_to_char((index+1).to_s)%><%= s.choice_text%> + <%= convert_to_char((index+1).to_s)%><%= to_markdown(s.choice_text) %>

<% end %> <% elsif q.question_type == 1 %> <% q.exercise_choices.each_with_index do |s,index| %>

- <%= convert_to_char((index+1).to_s)%><%= s.choice_text%> + <%= convert_to_char((index+1).to_s)%><%= to_markdown(s.choice_text) %>

<% end %> <% elsif q.question_type == 2 %> @@ -101,7 +99,7 @@ <% q.exercise_choices.each_with_index do |s,index| %> - <%= s.choice_text %> + <%= to_markdown(s.choice_text) %> <% end %>

From fec939b098c167812f7b7f7bd55c11e13cf92115 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 10:58:26 +0800 Subject: [PATCH 0433/1015] fix bug --- app/helpers/application_helper.rb | 2 +- app/templates/exercise_export/blank_exercise.html.erb | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 67e899820..fd5a8b233 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -349,7 +349,7 @@ module ApplicationHelper } markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) m_t = markdown.render(text) - ss = m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{request_url}")&.html_safe : m_t + ss = m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{request_url}") : m_t Rails.logger.info("############_____________ss________________##################{ss}") ss end diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index d562224da..b43dc1923 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -68,6 +68,7 @@ (<%= q&.question_score %>分)
+ 电脑的电路图 <% q_markdown = to_markdown(q.question_title) %> <% if q.question_type == 5 %> <% q_markdown_name = to_markdown(q.shixun_name) %> @@ -84,14 +85,14 @@ <% q.exercise_choices.each_with_index do |s,index| %>

- <%= convert_to_char((index+1).to_s)%><%= to_markdown(s.choice_text) %> + <%= convert_to_char((index+1).to_s)%><%= to_markdown(s.choice_text) %>

<% end %> <% elsif q.question_type == 1 %> <% q.exercise_choices.each_with_index do |s,index| %>

- <%= convert_to_char((index+1).to_s)%><%= to_markdown(s.choice_text) %> + <%= convert_to_char((index+1).to_s)%><%= to_markdown(s.choice_text) %>

<% end %> <% elsif q.question_type == 2 %> @@ -99,7 +100,7 @@ <% q.exercise_choices.each_with_index do |s,index| %> - <%= to_markdown(s.choice_text) %> + <%= to_markdown(s.choice_text) %> <% end %>

From decedbe354ac222e9a90a9e3884cc3e6971b19ad Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 11:28:42 +0800 Subject: [PATCH 0434/1015] fix bug --- app/templates/exercise_export/blank_exercise.html.erb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index b43dc1923..9ee1d40f7 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -69,6 +69,7 @@
电脑的电路图 + udasker_picture <% q_markdown = to_markdown(q.question_title) %> <% if q.question_type == 5 %> <% q_markdown_name = to_markdown(q.shixun_name) %> @@ -85,14 +86,16 @@ <% q.exercise_choices.each_with_index do |s,index| %>

- <%= convert_to_char((index+1).to_s)%><%= to_markdown(s.choice_text) %> + <%= convert_to_char((index+1).to_s)%> + <%= to_markdown(s.choice_text) %>

<% end %> <% elsif q.question_type == 1 %> <% q.exercise_choices.each_with_index do |s,index| %>

- <%= convert_to_char((index+1).to_s)%><%= to_markdown(s.choice_text) %> + <%= convert_to_char((index+1).to_s)%> + <%= to_markdown(s.choice_text) %>

<% end %> <% elsif q.question_type == 2 %> From 4d2943973fc156ee5c51352e72b3b2222e3c2252 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 1 Jul 2019 11:31:17 +0800 Subject: [PATCH 0435/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E5=99=A8=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 27 +++++++++++------------- app/models/shixun.rb | 2 ++ app/views/shixuns/settings.json.jbuilder | 8 +++++++ 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index f079aed1e..5631d03a7 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -367,11 +367,6 @@ class ShixunsController < ApplicationController end def update - h = {test_set_permission: params[:test_set_permission], code_hidden: params[:code_hidden], - task_pass: params[:task_pass], hide_code: params[:hide_code], forbid_copy: params[:forbid_copy]} - - s_params = shixun_params.merge(h) - ActiveRecord::Base.transaction do begin @shixun.shixun_mirror_repositories.destroy_all @@ -384,8 +379,8 @@ class ShixunsController < ApplicationController end end - @shixun.update_attributes(s_params) - @shixun.shixun_info.update_attributes(description: params[:description], evaluate_script: params[:evaluate_script]) + @shixun.update_attributes(shixun_params) + @shixun.shixun_info.update_attributes(shixun_info_params) @shixun.shixun_schools.delete_all if params[:scope_partment].present? && params[:user_scope].to_i == 1 arr = [] @@ -402,13 +397,8 @@ class ShixunsController < ApplicationController # 超级管理员和运营人员才能保存 中间层服务器pod信息的配置 if current_user.admin? || current_user.business? @shixun.shixun_service_configs.destroy_all - params[:mirror_id].each_with_index do |mirror_id, index| - ShixunServiceConfig.create!(:shixun_id => @shixun.id, - :cpu_limit => params[:cpu_limit][index], - :lower_cpu_limit => params[:lower_cpu_limit][index], - :memory_limit => params[:memory_limit][index], - :request_limit => params[:request_limit][index], - :mirror_repository_id => mirror_id) + params[:shixun_service_configs].each do |config| + @shixun.shixun_service_configs.create!(config) end end rescue Exception => e @@ -446,6 +436,7 @@ class ShixunsController < ApplicationController @choice_small_type = @shixun.small_mirror_id @main_type = shixun_main_type @small_type = shixun_small_type + @configs = @shixun.shixun_service_configs #@mirror_script = MirrorScript.select([:id, :script_type]).find(@shixun.mirror_script_id).attributes if @shixun.mirror_script_id && @shixun.mirror_script_id != 0 # @shixun_main_mirror = @shixun.show_shixun_mirror # @script_type = @shixun.script_tag.try(:script_type) || "无" @@ -734,7 +725,13 @@ private def shixun_params raise("实训名称不能为空") if params[:name].blank? params.require(:shixun).permit(:name, :trainee, :webssh, :can_copy, :use_scope, :vnc, :test_set_permission, - :task_pass, :repo_name, :multi_webssh, :opening_time, :mirror_script_id) + :task_pass, :repo_name, :multi_webssh, :opening_time, :mirror_script_id, :code_hidden, + :hide_code, :forbid_copy) + end + def shixun_info_params + raise("实训描述不能为空") if params[:description].blank? + raise("评测脚本不能为空") if params[:evaluate_script].blank? + params.require(:shixun_info).permit(:description, :evaluate_script) end def find_shixun diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 18d5c5fae..c4345f90a 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -1,5 +1,7 @@ class Shixun < ApplicationRecord # status: 0:编辑 1:申请发布 2:正式发布 3:关闭 -1:软删除 + # hide_code: 隐藏代码窗口 + # code_hidden: 隐藏代码目录 has_many :challenges, dependent: :destroy has_many :myshixuns, :dependent => :destroy has_many :shixun_members, dependent: :destroy diff --git a/app/views/shixuns/settings.json.jbuilder b/app/views/shixuns/settings.json.jbuilder index e97331388..ed7d93039 100644 --- a/app/views/shixuns/settings.json.jbuilder +++ b/app/views/shixuns/settings.json.jbuilder @@ -29,6 +29,14 @@ json.shixun do json.scope_partment @shixun.schools.map(&:name) # 公开范围 json.opening_time @shixun.opening_time json.forbid_copy @shixun.forbid_copy + + # 实训服务配置 + json.shixun_service_configs do + json.array! @configs do |config| + json.name config.mirror_repository&.name + json.(config, :cpu_limit, :lower_cpu_limit, :memory_limit, :request_limit, :mirror_repository_id) + end + end end From 029aac355491a4ee5a44823ea0cc55875719dab4 Mon Sep 17 00:00:00 2001 From: jasder Date: Mon, 1 Jul 2019 11:35:27 +0800 Subject: [PATCH 0436/1015] FIX delete message permission --- app/controllers/messages_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index bad54b88e..f684b27f3 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -128,7 +128,7 @@ class MessagesController < ApplicationController def destroy begin - return normal_status(403, "您没有权限进行该操作") unless @message.author == current_user || current_user.teacher_of_course?(@message.board.course) + return normal_status(403, "您没有权限进行该操作") if current_user.course_identity(@message.board.course) >= 5 || @message.author != current_user @message.destroy! rescue Exception => e uid_logger_error(e.message) From 4a257c29603b67ab17d2d59f66b6ba2ce580e172 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 12:24:00 +0800 Subject: [PATCH 0437/1015] fix bug --- .../exercise_export/blank_exercise.html.erb | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 9ee1d40f7..f281a55a0 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -83,30 +83,28 @@
<% if q.question_type == 0 %> - <% q.exercise_choices.each_with_index do |s,index| %> -

- - <%= convert_to_char((index+1).to_s)%> - <%= to_markdown(s.choice_text) %> -

+ <% q.exercise_choices.each do |s| %> +
+ + <%= to_markdown(s.choice_text) %> +
<% end %> <% elsif q.question_type == 1 %> - <% q.exercise_choices.each_with_index do |s,index| %> -

- - <%= convert_to_char((index+1).to_s)%> - <%= to_markdown(s.choice_text) %> -

+ <% q.exercise_choices.each do |s| %> +
+ + <%= to_markdown(s.choice_text) %> +
<% end %> <% elsif q.question_type == 2 %> -

- <% q.exercise_choices.each_with_index do |s,index| %> - - - <%= to_markdown(s.choice_text) %> +

+ <% q.exercise_choices.each do |s| %> + + + <%= to_markdown(s.choice_text) %> <% end %> -

+
<% elsif q.question_type == 3 %> <% st_counts = q.exercise_standard_answers.pluck(:exercise_choice_id).uniq %> <% st_counts.each_with_index do |s,index| %> From 8f3be9a7f6e42c8e3678df80eb6b0f660b748d4c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 12:37:13 +0800 Subject: [PATCH 0438/1015] fix bug --- .../exercise_export/blank_exercise.html.erb | 16 ++++++---------- .../exercise_export/exercise_export.css | 6 ++++++ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index f281a55a0..b253d86b9 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -68,17 +68,13 @@ (<%= q&.question_score %>分)
- 电脑的电路图 - udasker_picture - <% q_markdown = to_markdown(q.question_title) %> <% if q.question_type == 5 %> - <% q_markdown_name = to_markdown(q.shixun_name) %> - <%= q_markdown_name %> + <%= to_markdown(q.shixun_name) %>
- <%= q_markdown %> + <%= to_markdown(q.question_title) %>
<% else %> - <%= q_markdown %> + <%= to_markdown(q.question_title) %> <% end %>
@@ -86,14 +82,14 @@ <% q.exercise_choices.each do |s| %>
- <%= to_markdown(s.choice_text) %> + <%= to_markdown(s.choice_text) %>
<% end %> <% elsif q.question_type == 1 %> <% q.exercise_choices.each do |s| %>
- <%= to_markdown(s.choice_text) %> + <%= to_markdown(s.choice_text) %>
<% end %> <% elsif q.question_type == 2 %> @@ -101,7 +97,7 @@ <% q.exercise_choices.each do |s| %> - <%= to_markdown(s.choice_text) %> + <%= to_markdown(s.choice_text) %> <% end %>
diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 9190e9251..bbe523972 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -309,6 +309,12 @@ textarea{ clear:both; zoom:1; } +.line-20{ + line-height: 20px; +} +.line-20 P{ + margin-bottom:0; +} From 0922155a1cdd9a603bd59b193506b2537c165896 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 12:50:01 +0800 Subject: [PATCH 0439/1015] fix bug --- app/helpers/application_helper.rb | 4 +--- .../exercise_export/blank_exercise.html.erb | 15 +++++++-------- app/templates/exercise_export/exercise_export.css | 4 +++- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fd5a8b233..c49e5e775 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -349,9 +349,7 @@ module ApplicationHelper } markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) m_t = markdown.render(text) - ss = m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{request_url}") : m_t - Rails.logger.info("############_____________ss________________##################{ss}") - ss + m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{request_url}") : m_t end end diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index b253d86b9..5727d0f62 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -44,7 +44,6 @@ 实训题<%= @exercise_ques_shixun_count %>题, 共<%= @exercise_ques_shixun_scores %> <% end %> - <% if @exercise_ques_count > 0 %> <%= @exercise_ques_scores %>分 @@ -59,7 +58,7 @@
<% @exercise_questions.each do |q| %>
-
+
<%= q.question_number %>、 @@ -80,15 +79,15 @@
<% if q.question_type == 0 %> <% q.exercise_choices.each do |s| %> -
- +
+ <%= to_markdown(s.choice_text) %>
<% end %> <% elsif q.question_type == 1 %> <% q.exercise_choices.each do |s| %> -
- +
+ <%= to_markdown(s.choice_text) %>
<% end %> @@ -96,8 +95,8 @@
<% q.exercise_choices.each do |s| %> - - <%= to_markdown(s.choice_text) %> + + <%= s.choice_text %> <% end %>
diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index bbe523972..140db58ef 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -315,6 +315,8 @@ textarea{ .line-20 P{ margin-bottom:0; } - +.v-middle{ + vertical-align: middle; +} From b69d705ed77f4f81f78b32d323a03f05d5ca5aef Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 12:52:42 +0800 Subject: [PATCH 0440/1015] Fix bug --- app/templates/exercise_export/blank_exercise.html.erb | 8 ++++---- app/templates/exercise_export/exercise_export.css | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 5727d0f62..aed7acdcd 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -80,15 +80,15 @@ <% if q.question_type == 0 %> <% q.exercise_choices.each do |s| %>
- - <%= to_markdown(s.choice_text) %> + + <%= to_markdown(s.choice_text) %>
<% end %> <% elsif q.question_type == 1 %> <% q.exercise_choices.each do |s| %>
- - <%= to_markdown(s.choice_text) %> + + <%= to_markdown(s.choice_text) %>
<% end %> <% elsif q.question_type == 2 %> diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 140db58ef..3efda43bb 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -309,8 +309,8 @@ textarea{ clear:both; zoom:1; } -.line-20{ - line-height: 20px; +.line-24{ + line-height: 24px; } .line-20 P{ margin-bottom:0; From e365005af14682e96f3bc080ac32ab1c733f1438 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 12:55:04 +0800 Subject: [PATCH 0441/1015] fix bug --- app/templates/exercise_export/blank_exercise.html.erb | 4 ++-- app/templates/exercise_export/exercise_export.css | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index aed7acdcd..99b8e6683 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -79,14 +79,14 @@
<% if q.question_type == 0 %> <% q.exercise_choices.each do |s| %> -
+
<%= to_markdown(s.choice_text) %>
<% end %> <% elsif q.question_type == 1 %> <% q.exercise_choices.each do |s| %> -
+
<%= to_markdown(s.choice_text) %>
diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 3efda43bb..53dc5b3c8 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -312,11 +312,9 @@ textarea{ .line-24{ line-height: 24px; } -.line-20 P{ +.line-24 p{ margin-bottom:0; } -.v-middle{ - vertical-align: middle; -} + From 81950469b4c33cdd8e139a8ac26a4717c7c87f6b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 13:15:13 +0800 Subject: [PATCH 0442/1015] fix bug --- .../exercise_export/blank_exercise.html.erb | 8 ++-- .../exercise_export/exercise_export.css | 10 +++++ .../exercise_export/exercise_user.html.erb | 40 +++++++++---------- 3 files changed, 33 insertions(+), 25 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 99b8e6683..7e7c14977 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -80,15 +80,15 @@ <% if q.question_type == 0 %> <% q.exercise_choices.each do |s| %>
- - <%= to_markdown(s.choice_text) %> + + <%= to_markdown(s.choice_text) %>
<% end %> <% elsif q.question_type == 1 %> <% q.exercise_choices.each do |s| %>
- - <%= to_markdown(s.choice_text) %> + + <%= to_markdown(s.choice_text) %>
<% end %> <% elsif q.question_type == 2 %> diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 53dc5b3c8..a72b26782 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -44,6 +44,9 @@ p{ .mbt10{ margin: 10px 0; } +.mt5{ + margin-top:5px; +} .pull-right{ float:right; } @@ -82,9 +85,15 @@ p{ .ml20{ margin-left:20px; } +.ml10{ + margin-left:10px; +} .mr3{ margin-right:3px; } +.mr8{ + margin-right:8px; +} .mr15{ margin-right:15px; } @@ -318,3 +327,4 @@ textarea{ + diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 5770c5921..1679692b3 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -167,41 +167,39 @@ <% end %>
- <% q_title = q.question_title&.html_safe %> - <% if q_type == 5 %> - <% q_name = q.shixun_name&.html_safe %> - <%= q_name&.include?("src=\"") ? q_name&.gsub("src=\"","src=\"#{@request_url}") : q_name %> + <% if q.question_type == 5 %> + <%= to_markdown(q.shixun_name) %>
- <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %> + <%= to_markdown(q.question_title) %>
<% else %> - <%= q_title&.include?("src=\"") ? q_title&.gsub("src=\"","src=\"#{@request_url}") : q_title %> + <%= to_markdown(q.question_title) %> <% end %>
<% if q_type == 0 %> - <% q.exercise_choices.each_with_index do |s,index| %> + <% q.exercise_choices.each do |s| %> <% check_answer = (user_answer.present? && (s.id == user_answer.first.exercise_choice_id)) ? "choose-answer" : '' %> -

- - <%= convert_to_char((index+1).to_s)%><%= s.choice_text%> -

+
+ + <%= to_markdown(s.choice_text) %> +
<% end %> <% elsif q_type == 1 %> - <% q.exercise_choices.each_with_index do |s,index| %> + <% q.exercise_choices.each do |s| %> <% check_answer = (user_answer.present? && (user_answer.pluck(:exercise_choice_id).include?(s.id))) ? true : false %> -

+

<% if check_answer %> - + <% else %> - + <% end %> - <%= convert_to_char((index+1).to_s)%><%= s.choice_text%> -

+ <%= to_markdown(s.choice_text) %> +
<% end %> <% elsif q_type == 2 %> -

+

<% q.exercise_choices.each do |s| %> <% if user_answer.present? && (s.id == user_answer.first.exercise_choice_id) %> <% check_answer = 'choose-answer' %> @@ -213,7 +211,7 @@ <%= s.choice_text %> <% end %> -

+
<% elsif q_type == 3 %> <% st_counts = q.exercise_standard_answers.pluck(:exercise_choice_id).uniq %> <% st_counts.each_with_index do |s,index| %> @@ -224,13 +222,13 @@ <% end %>

答案(填空<%= index+1 %>): - <%= check_answer&.html_safe %> + <%= to_markdown(check_answer) %>

<% end %> <% elsif q_type == 4 %> <% check_answer = (user_answer.present? ? user_answer.first.answer_text : '--') %>

- <%= check_answer&.html_safe %> + <%= to_markdown(check_answer) %>

<% else %>
From 065669bc2b2a0c7dcdadbdfa450a61b0d559df7d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 1 Jul 2019 13:38:18 +0800 Subject: [PATCH 0443/1015] =?UTF-8?q?fork=E5=AE=9E=E8=AE=AD=E5=B8=A6?= =?UTF-8?q?=E7=9D=80=E9=85=8D=E7=BD=AE=E4=BF=A1=E6=81=AF"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 5631d03a7..f7172021c 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -179,6 +179,16 @@ class ShixunsController < ApplicationController ShixunTagRepertoire.create!(:tag_repertoire_id => str.tag_repertoire_id, :shixun_id => @new_shixun.id) end + # 同步配置 + @shixun.shixun_service_configs.each do |config| + ShixunServiceConfig.create!(:shixun_id => @new_shixun.id, + :cpu_limit => config.cpu_limit, + :lower_cpu_limit => config.lower_cpu_limit, + :memory_limit => config.memory_limit, + :request_limit => config.request_limit, + :mirror_repository_id => config.mirror_repository_id) + end + # fork版本库 logger.info("###########fork_repo_path: ######{@repo_path}") project_fork(@new_shixun, @repo_path, current_user.login) From db4d45d00e4f5c31842dc9b94fa6e6ec3de4cef9 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 1 Jul 2019 13:56:36 +0800 Subject: [PATCH 0444/1015] =?UTF-8?q?=E5=85=B3=E5=8D=A1=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E5=8F=82=E6=95=B0=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/challenges/show.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/challenges/show.json.jbuilder b/app/views/challenges/show.json.jbuilder index 332879eac..cffe77ebb 100644 --- a/app/views/challenges/show.json.jbuilder +++ b/app/views/challenges/show.json.jbuilder @@ -1,6 +1,6 @@ # 导航栏公共数据 json.partial! "challenges/top_common_data", shixun_identifier: @shixun.identifier -json.(@challenge, :id, :subject, :task_pass, :difficulty, :score) +json.(@challenge, :id, :subject, :task_pass, :difficulty, :score, :exec_time) json.tags @challenge.challenge_tags.map(&:name) From c3087d7b4e95003a7b1139362f810653884fe90a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 13:59:33 +0800 Subject: [PATCH 0445/1015] fix bug --- app/helpers/application_helper.rb | 1 + .../exercise_export/blank_exercise.html.erb | 12 ++++++------ app/templates/exercise_export/exercise_export.css | 8 +++----- .../exercise_export/exercise_user.html.erb | 14 +++++++------- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index c49e5e775..e6bc84f20 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -350,6 +350,7 @@ module ApplicationHelper markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) m_t = markdown.render(text) m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{request_url}") : m_t + Rails.logger.info("###########__________request_url_________###################{request_url}") end end diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 7e7c14977..1dde00e56 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -79,16 +79,16 @@
<% if q.question_type == 0 %> <% q.exercise_choices.each do |s| %> -
- - <%= to_markdown(s.choice_text) %> +
+ + <%= to_markdown(s.choice_text) %>
<% end %> <% elsif q.question_type == 1 %> <% q.exercise_choices.each do |s| %> -
- - <%= to_markdown(s.choice_text) %> +
+ + <%= to_markdown(s.choice_text) %>
<% end %> <% elsif q.question_type == 2 %> diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index a72b26782..f0eeb0f4c 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -257,7 +257,7 @@ table{ text-align:center; } -table, tr, td, th, tbody, thead, tfoot,textarea{ +table, tr, td, th, tbody, thead, tfoot,textarea,.main-choice{ page-break-inside: avoid; } table th{ @@ -318,10 +318,8 @@ textarea{ clear:both; zoom:1; } -.line-24{ - line-height: 24px; -} -.line-24 p{ + +.choice-text p{ margin-bottom:0; } diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 1679692b3..3e92c5864 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -181,21 +181,21 @@ <% if q_type == 0 %> <% q.exercise_choices.each do |s| %> <% check_answer = (user_answer.present? && (s.id == user_answer.first.exercise_choice_id)) ? "choose-answer" : '' %> -
- - <%= to_markdown(s.choice_text) %> +
+ + <%= to_markdown(s.choice_text) %>
<% end %> <% elsif q_type == 1 %> <% q.exercise_choices.each do |s| %> <% check_answer = (user_answer.present? && (user_answer.pluck(:exercise_choice_id).include?(s.id))) ? true : false %> -
+
<% if check_answer %> - + <% else %> - + <% end %> - <%= to_markdown(s.choice_text) %> + <%= to_markdown(s.choice_text) %>
<% end %> <% elsif q_type == 2 %> From 733e7827234ddf4055f9932d20f3db6115597dc4 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 14:03:03 +0800 Subject: [PATCH 0446/1015] fix bug --- app/controllers/zips_controller.rb | 3 +-- app/helpers/application_helper.rb | 1 + app/services/exercise_user_pdf_service.rb | 3 +-- app/services/export_exercises_service.rb | 5 ++--- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 77a41d065..4de85ec64 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -17,7 +17,7 @@ class ZipsController < ApplicationController end def export_exercises - exercises = ExportExercisesService.new(@exercise,@ex_users,@request_url) + exercises = ExportExercisesService.new(@exercise,@ex_users) file_name = filename_for_content_disposition(exercises.filename) send_file exercises.ex_zip, filename: file_name, type: 'application/zip' @@ -41,7 +41,6 @@ class ZipsController < ApplicationController ActiveRecord::Base.transaction do begin @exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id]) - @request_url = request.base_url group_id = params[:exercise_group_id] if @exercise.blank? normal_status(-1,"试卷不存在") diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e6bc84f20..f0cac79b9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -334,6 +334,7 @@ module ApplicationHelper raw arr.join('') end + # 导出pdf时,转化markdown为html def to_markdown(text) request_url = request.base_url diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 9b96cd70c..be048c4c2 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -5,10 +5,9 @@ class ExerciseUserPdfService attr_reader :exercise, :ex_user - def initialize(exercise, ex_user,request_url) + def initialize(exercise, ex_user) @exercise = exercise @ex_user = ex_user - @request_url = request_url @ex_user_user = @ex_user.user @course = @exercise.course end diff --git a/app/services/export_exercises_service.rb b/app/services/export_exercises_service.rb index 48bfc9519..12b5501f9 100644 --- a/app/services/export_exercises_service.rb +++ b/app/services/export_exercises_service.rb @@ -3,10 +3,9 @@ class ExportExercisesService include StudentWorksHelper attr_reader :exercise, :ex_users - def initialize(exercise, ex_users,request_url) + def initialize(exercise, ex_users) @exercise = exercise @ex_users = ex_users - @request_url = request_url end def filename @@ -19,7 +18,7 @@ class ExportExercisesService pdfs = [] Zip::File.open(zip_file.path, Zip::File::CREATE) do |zip| ex_users.each do |ex_user| - export = ExerciseUserPdfService.new(exercise, ex_user,@request_url) + export = ExerciseUserPdfService.new(exercise, ex_user) pdf = export.ex_pdf pdfs << pdf begin From b8592a99433ac4af3eeb508d1d456fd3b53c623e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 14:10:48 +0800 Subject: [PATCH 0447/1015] fix bug --- app/controllers/exercises_controller.rb | 1 - app/helpers/application_helper.rb | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 2377f411b..8b65d7c70 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1334,7 +1334,6 @@ class ExercisesController < ApplicationController #导出空白试卷 def export_exercise @exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") - @request_url = request.base_url filename = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.current.strftime('%Y%m%d%H%M%S')}.pdf" stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css" render pdf: 'exercise_export/blank_exercise', filename: filename, stylesheets: stylesheets diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f0cac79b9..65b6c0634 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -336,9 +336,9 @@ module ApplicationHelper # 导出pdf时,转化markdown为html def to_markdown(text) + return nil if text.blank? request_url = request.base_url - return nil if text.blank? options = { :autolink => true, :no_intra_emphasis => true, @@ -350,7 +350,7 @@ module ApplicationHelper } markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) m_t = markdown.render(text) - m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{request_url}") : m_t + m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{request.base_url}") : m_t Rails.logger.info("###########__________request_url_________###################{request_url}") end From dade42727badc705a19a0e37f3f0a80a53389b86 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 1 Jul 2019 14:19:39 +0800 Subject: [PATCH 0448/1015] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E7=9A=84=E5=85=B3=E5=8D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shixuns/settings.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shixuns/settings.json.jbuilder b/app/views/shixuns/settings.json.jbuilder index ed7d93039..e81498058 100644 --- a/app/views/shixuns/settings.json.jbuilder +++ b/app/views/shixuns/settings.json.jbuilder @@ -22,7 +22,7 @@ json.shixun do json.hide_code @shixun.hide_code # 隐藏代码窗口 json.code_hidden @shixun.code_hidden # 代码目录隐藏 json.vnc @shixun.vnc - json.exec_time @shixun.exec_time + #json.exec_time @shixun.exec_time json.webssh @shixun.webssh json.multi_webssh @shixun.multi_webssh json.use_scope @shixun.use_scope From c543779cb1aaac41615d0093b5907e14c4f6d6ae Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 14:20:48 +0800 Subject: [PATCH 0449/1015] fix bug --- app/helpers/application_helper.rb | 4 ++-- app/templates/exercise_export/exercise_user.html.erb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 65b6c0634..6ddbdce0c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -337,7 +337,7 @@ module ApplicationHelper # 导出pdf时,转化markdown为html def to_markdown(text) return nil if text.blank? - request_url = request.base_url + request_url = "http://47.96.87.25:48080" options = { :autolink => true, @@ -350,7 +350,7 @@ module ApplicationHelper } markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) m_t = markdown.render(text) - m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{request.base_url}") : m_t + m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{request_url}") : m_t Rails.logger.info("###########__________request_url_________###################{request_url}") end diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 3e92c5864..f523246a0 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -121,7 +121,7 @@
- <%= q.question_number %>、  + <%= q.question_number %>、 <%= request.base_url %> <%= q.question_type_name %> From 90fadb2869971dd7fc8a6b11cc3cd8b52024f92b Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 1 Jul 2019 14:22:56 +0800 Subject: [PATCH 0450/1015] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=88=86=E7=8F=AD?= 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 e0844ab4c..cef2a1785 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -776,7 +776,7 @@ class CoursesController < ApplicationController name = attachment.disk_filename if name.split(".").last == "xls" begin - attachment_folder = Rails.configuration.educoder['attachment_folder'] + attachment_folder = edu_setting('attachment_folder') full_path = "#{attachment_folder}/#{path}/#{name}" xls = Roo::Spreadsheet.open(full_path, extension: :xls) worksheet = xls.sheet(0) From 0387dbaf9142376a5397438d7c4526d6c1baddd0 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 14:23:59 +0800 Subject: [PATCH 0451/1015] fix bug --- app/templates/exercise_export/exercise_user.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index f523246a0..3e92c5864 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -121,7 +121,7 @@
- <%= q.question_number %>、 <%= request.base_url %> + <%= q.question_number %>、  <%= q.question_type_name %> From cc20b5459fc3574baa79218b9ddb126a6093edae Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 14:36:21 +0800 Subject: [PATCH 0452/1015] fix bug --- app/controllers/exercises_controller.rb | 1 + app/controllers/zips_controller.rb | 3 ++- app/helpers/application_helper.rb | 7 ++----- app/services/exercise_user_pdf_service.rb | 3 ++- app/services/export_exercises_service.rb | 5 +++-- .../exercise_export/blank_exercise.html.erb | 10 +++++----- app/templates/exercise_export/exercise_user.html.erb | 12 ++++++------ 7 files changed, 21 insertions(+), 20 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 8b65d7c70..3c364b979 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1333,6 +1333,7 @@ class ExercisesController < ApplicationController #导出空白试卷 def export_exercise + @request_url = request.base_url @exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") filename = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.current.strftime('%Y%m%d%H%M%S')}.pdf" stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css" diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 4de85ec64..c20546701 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -17,7 +17,8 @@ class ZipsController < ApplicationController end def export_exercises - exercises = ExportExercisesService.new(@exercise,@ex_users) + @request_url = request.base_url + exercises = ExportExercisesService.new(@exercise,@ex_users,@request_url) file_name = filename_for_content_disposition(exercises.filename) send_file exercises.ex_zip, filename: file_name, type: 'application/zip' diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6ddbdce0c..fd72b5651 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -335,10 +335,8 @@ module ApplicationHelper end # 导出pdf时,转化markdown为html - def to_markdown(text) + def to_markdown(text,origin_url) return nil if text.blank? - request_url = "http://47.96.87.25:48080" - options = { :autolink => true, :no_intra_emphasis => true, @@ -350,8 +348,7 @@ module ApplicationHelper } markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,options) m_t = markdown.render(text) - m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{request_url}") : m_t - Rails.logger.info("###########__________request_url_________###################{request_url}") + m_t&.include?("src=\"") ? m_t&.gsub("src=\"","src=\"#{origin_url}") : m_t end end diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index be048c4c2..9b96cd70c 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -5,9 +5,10 @@ class ExerciseUserPdfService attr_reader :exercise, :ex_user - def initialize(exercise, ex_user) + def initialize(exercise, ex_user,request_url) @exercise = exercise @ex_user = ex_user + @request_url = request_url @ex_user_user = @ex_user.user @course = @exercise.course end diff --git a/app/services/export_exercises_service.rb b/app/services/export_exercises_service.rb index 12b5501f9..0d2d8f3ce 100644 --- a/app/services/export_exercises_service.rb +++ b/app/services/export_exercises_service.rb @@ -3,9 +3,10 @@ class ExportExercisesService include StudentWorksHelper attr_reader :exercise, :ex_users - def initialize(exercise, ex_users) + def initialize(exercise, ex_users,request_url) @exercise = exercise @ex_users = ex_users + @request_url = request_url end def filename @@ -18,7 +19,7 @@ class ExportExercisesService pdfs = [] Zip::File.open(zip_file.path, Zip::File::CREATE) do |zip| ex_users.each do |ex_user| - export = ExerciseUserPdfService.new(exercise, ex_user) + export = ExerciseUserPdfService.new(exercise, ex_user,request_url) pdf = export.ex_pdf pdfs << pdf begin diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 1dde00e56..153ba1514 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -68,12 +68,12 @@
<% if q.question_type == 5 %> - <%= to_markdown(q.shixun_name) %> + <%= to_markdown(q.shixun_name,@request_url) %>
- <%= to_markdown(q.question_title) %> + <%= to_markdown(q.question_title,@request_url) %>
<% else %> - <%= to_markdown(q.question_title) %> + <%= to_markdown(q.question_title,@request_url) %> <% end %>
@@ -81,14 +81,14 @@ <% q.exercise_choices.each do |s| %>
- <%= to_markdown(s.choice_text) %> + <%= to_markdown(s.choice_text,@request_url) %>
<% end %> <% elsif q.question_type == 1 %> <% q.exercise_choices.each do |s| %>
- <%= to_markdown(s.choice_text) %> + <%= to_markdown(s.choice_text,@request_url) %>
<% end %> <% elsif q.question_type == 2 %> diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 3e92c5864..bb3723373 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -168,12 +168,12 @@
<% if q.question_type == 5 %> - <%= to_markdown(q.shixun_name) %> + <%= to_markdown(q.shixun_name,@request_url) %>
- <%= to_markdown(q.question_title) %> + <%= to_markdown(q.question_title,@request_url) %>
<% else %> - <%= to_markdown(q.question_title) %> + <%= to_markdown(q.question_title,@request_url) %> <% end %>
@@ -183,7 +183,7 @@ <% check_answer = (user_answer.present? && (s.id == user_answer.first.exercise_choice_id)) ? "choose-answer" : '' %>
- <%= to_markdown(s.choice_text) %> + <%= to_markdown(s.choice_text,@request_url) %>
<% end %> <% elsif q_type == 1 %> @@ -195,7 +195,7 @@ <% else %> <% end %> - <%= to_markdown(s.choice_text) %> + <%= to_markdown(s.choice_text,@request_url) %>
<% end %> <% elsif q_type == 2 %> @@ -335,7 +335,7 @@
- +

<%= ques_user.real_name %><%= ques_comment.first.updated_at.strftime('%Y-%m-%d %H:%M') %>

From 1e5db588192fe5b130c99589e3ae78719c83fce4 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 14:38:24 +0800 Subject: [PATCH 0453/1015] fix bug --- app/services/exercise_user_pdf_service.rb | 2 +- app/services/export_exercises_service.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 9b96cd70c..44ee1e769 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -3,7 +3,7 @@ class ExerciseUserPdfService include ApplicationHelper include StudentWorksHelper - attr_reader :exercise, :ex_user + attr_reader :exercise, :ex_user, :request_url def initialize(exercise, ex_user,request_url) @exercise = exercise diff --git a/app/services/export_exercises_service.rb b/app/services/export_exercises_service.rb index 0d2d8f3ce..f83323d7e 100644 --- a/app/services/export_exercises_service.rb +++ b/app/services/export_exercises_service.rb @@ -1,9 +1,9 @@ class ExportExercisesService include ExercisesHelper include StudentWorksHelper - attr_reader :exercise, :ex_users + attr_reader :exercise, :ex_users, :request_url - def initialize(exercise, ex_users,request_url) + def initialize(exercise, ex_users, request_url) @exercise = exercise @ex_users = ex_users @request_url = request_url @@ -19,7 +19,7 @@ class ExportExercisesService pdfs = [] Zip::File.open(zip_file.path, Zip::File::CREATE) do |zip| ex_users.each do |ex_user| - export = ExerciseUserPdfService.new(exercise, ex_user,request_url) + export = ExerciseUserPdfService.new(exercise, ex_user,@request_url) pdf = export.ex_pdf pdfs << pdf begin From e5cd38ed9007b5fe2338ef3da7cfa9ecaa100486 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 1 Jul 2019 14:39:46 +0800 Subject: [PATCH 0454/1015] =?UTF-8?q?=E8=AE=A1=E7=AE=97=E6=88=90=E7=BB=A9?= =?UTF-8?q?=E7=9A=84=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index f242f3438..545fbce85 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -12,7 +12,7 @@ class HomeworkCommonsController < ApplicationController :code_review_detail, :show_comment, :settings, :works_list, :update_settings, :reference_answer, :publish_groups, :end_groups, :alter_name, :update_explanation] before_action :user_course_identity - before_action :homework_publish, only: [:show, :works_list, :code_review_results, :show_comment, :settings, :reference_answer] + before_action :homework_publish, only: [:show, :works_list, :code_review_results, :show_comment, :settings, :reference_answer, :update_student_score] before_action :teacher_allowed, only: [:new, :edit, :create, :update, :shixuns, :subjects, :create_shixun_homework, :publish_homework, :end_homework, :set_public, :choose_category, :move_to_category, :choose_category, :create_subject_homework, :multi_destroy, :group_list, :homework_code_repeat, @@ -237,6 +237,7 @@ class HomeworkCommonsController < ApplicationController end def update_score + tip_exception("作业还未发布,暂不能计算成绩") if @homework.publish_time.nil? || @homework.publish_time > Time.now begin if @homework.unified_setting student_works = @homework.student_works From 99d94df66117f9939ed3141e9e98d7ba9d653595 Mon Sep 17 00:00:00 2001 From: jasder Date: Mon, 1 Jul 2019 14:44:49 +0800 Subject: [PATCH 0455/1015] =?UTF-8?q?FIX=20=E2=80=98=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E2=80=99=E5=85=AC=E5=85=B1api=E6=9B=B4=E6=94=B9=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/commons_controller.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/controllers/commons_controller.rb b/app/controllers/commons_controller.rb index ca68c65d3..105cbefbe 100644 --- a/app/controllers/commons_controller.rb +++ b/app/controllers/commons_controller.rb @@ -42,7 +42,18 @@ class CommonsController < ApplicationController end def validate_power - tip_exception(403, "无操作权限") unless current_user.admin? + code = + case params[:object_type].strip + when 'message' + if current_user.course_identity(@object.board.course) >= 5 || @object.author != current_user + 403 + else + 200 + end + else + current_user.admin? ? 200 : 403 + end + return normal_status(403, "你没有权限操作!") if code == 403 end def action(flag) From bfd6b60f66ed0fd2a7751d85e34fd057678c9861 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 1 Jul 2019 14:45:47 +0800 Subject: [PATCH 0456/1015] =?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/homework_commons_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 545fbce85..3562be4f3 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -10,7 +10,8 @@ class HomeworkCommonsController < ApplicationController :create_subject_homework, :multi_destroy, :add_to_homework_bank] before_action :find_homework, only: [:edit, :show, :update, :group_list, :homework_code_repeat, :code_review_results, :code_review_detail, :show_comment, :settings, :works_list, :update_settings, - :reference_answer, :publish_groups, :end_groups, :alter_name, :update_explanation] + :reference_answer, :publish_groups, :end_groups, :alter_name, :update_explanation, + :update_score, :update_student_score] before_action :user_course_identity before_action :homework_publish, only: [:show, :works_list, :code_review_results, :show_comment, :settings, :reference_answer, :update_student_score] before_action :teacher_allowed, only: [:new, :edit, :create, :update, :shixuns, :subjects, :create_shixun_homework, From 2d2ab5e8bb24bd564e9e8ba552e9ba94e55dd9aa Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 14:46:34 +0800 Subject: [PATCH 0457/1015] fix bug --- app/templates/exercise_export/exercise_user.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index bb3723373..41f8d5726 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -222,13 +222,13 @@ <% end %>

答案(填空<%= index+1 %>): - <%= to_markdown(check_answer) %> + <%= to_markdown(check_answer,@request_url) %>

<% end %> <% elsif q_type == 4 %> <% check_answer = (user_answer.present? ? user_answer.first.answer_text : '--') %>

- <%= to_markdown(check_answer) %> + <%= to_markdown(check_answer,@request_url) %>

<% else %>
From cf714a85ea0b317b7059805f9fe7d1d865bd926a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 1 Jul 2019 14:48:47 +0800 Subject: [PATCH 0458/1015] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index f7172021c..0eaeae7de 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -739,8 +739,8 @@ private :hide_code, :forbid_copy) end def shixun_info_params - raise("实训描述不能为空") if params[:description].blank? - raise("评测脚本不能为空") if params[:evaluate_script].blank? + raise("实训描述不能为空") if params[:shixun_info][:description].blank? + raise("评测脚本不能为空") if params[:shixun_info][:evaluate_script].blank? params.require(:shixun_info).permit(:description, :evaluate_script) end From 783f73796007f6e1f39aeeae9b6fbcaadbb4ebd7 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 1 Jul 2019 14:49:19 +0800 Subject: [PATCH 0459/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 0eaeae7de..0d913a0a1 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -733,7 +733,7 @@ class ShixunsController < ApplicationController private def shixun_params - raise("实训名称不能为空") if params[:name].blank? + raise("实训名称不能为空") if params[:shixun][:name].blank? params.require(:shixun).permit(:name, :trainee, :webssh, :can_copy, :use_scope, :vnc, :test_set_permission, :task_pass, :repo_name, :multi_webssh, :opening_time, :mirror_script_id, :code_hidden, :hide_code, :forbid_copy) From 191c2a25fa9f989694eb1cfb495f533cfc73f987 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 15:03:50 +0800 Subject: [PATCH 0460/1015] fix bug --- app/templates/exercise_export/exercise_export.css | 3 +++ app/templates/exercise_export/exercise_user.html.erb | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index f0eeb0f4c..ef76479c5 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -109,6 +109,9 @@ p{ white-space: normal; min-height:12px; } +.null-answer p{ + display: inline-block; +} .choose-radio{ display: inline-block; width: 12px; diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 41f8d5726..8731df439 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -181,7 +181,7 @@ <% if q_type == 0 %> <% q.exercise_choices.each do |s| %> <% check_answer = (user_answer.present? && (s.id == user_answer.first.exercise_choice_id)) ? "choose-answer" : '' %> -
+
<%= to_markdown(s.choice_text,@request_url) %>
@@ -189,9 +189,9 @@ <% elsif q_type == 1 %> <% q.exercise_choices.each do |s| %> <% check_answer = (user_answer.present? && (user_answer.pluck(:exercise_choice_id).include?(s.id))) ? true : false %> -
+
<% if check_answer %> - + <% else %> <% end %> From 275bc3bd0d39aab0f6ff7a0de19fef148a6eebed Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 1 Jul 2019 15:08:11 +0800 Subject: [PATCH 0461/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E5=85=B3=E5=8D=A1?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/challenge.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 18b177e1c..e7a382a51 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -52,7 +52,7 @@ class Challenge < ApplicationRecord # 开启挑战 def open_game user_id, shixun - game = self.games.first + game = self.games.where(user_id: user_id).first if game.present? shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : "" else From fcbd308d05c1406263450a3c9b7c5dd4b07d3cfb Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 15:09:31 +0800 Subject: [PATCH 0462/1015] fix bug --- app/templates/exercise_export/exercise_export.css | 3 +++ .../exercise_export/exercise_user.html.erb | 14 ++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index ef76479c5..2745382f7 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -41,6 +41,9 @@ p{ .mt8{ margin-top:8px; } +.mt10{ + margin-top:10px; +} .mbt10{ margin: 10px 0; } diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 8731df439..1e3d88a44 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -182,7 +182,7 @@ <% q.exercise_choices.each do |s| %> <% check_answer = (user_answer.present? && (s.id == user_answer.first.exercise_choice_id)) ? "choose-answer" : '' %>
- + <%= to_markdown(s.choice_text,@request_url) %>
<% end %> @@ -191,9 +191,9 @@ <% check_answer = (user_answer.present? && (user_answer.pluck(:exercise_choice_id).include?(s.id))) ? true : false %>
<% if check_answer %> - + <% else %> - + <% end %> <%= to_markdown(s.choice_text,@request_url) %>
@@ -227,9 +227,11 @@ <% end %> <% elsif q_type == 4 %> <% check_answer = (user_answer.present? ? user_answer.first.answer_text : '--') %> -

- <%= to_markdown(check_answer,@request_url) %> -

+
+
+ <%= to_markdown(check_answer,@request_url) %> +
+
<% else %>

From a820dd0a67da819a28441f2ffd451d3b654fecbe Mon Sep 17 00:00:00 2001 From: jasder Date: Mon, 1 Jul 2019 15:10:24 +0800 Subject: [PATCH 0463/1015] FIX bug --- app/controllers/commons_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/commons_controller.rb b/app/controllers/commons_controller.rb index 105cbefbe..1f6dce053 100644 --- a/app/controllers/commons_controller.rb +++ b/app/controllers/commons_controller.rb @@ -45,7 +45,7 @@ class CommonsController < ApplicationController code = case params[:object_type].strip when 'message' - if current_user.course_identity(@object.board.course) >= 5 || @object.author != current_user + if current_user.course_identity(@object.board.course) >= 5 && @object.author != current_user 403 else 200 @@ -53,7 +53,7 @@ class CommonsController < ApplicationController else current_user.admin? ? 200 : 403 end - return normal_status(403, "你没有权限操作!") if code == 403 + return normal_status(code, "你没有权限操作!") if code == 403 end def action(flag) From 08a4a0d89ba71bf0ebbf045fd7bf695466470036 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 15:22:59 +0800 Subject: [PATCH 0464/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E5=AF=BC=E5=87=BAhtml=E5=92=8Ccss=E7=9A=84=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/zips_controller.rb | 4 ++-- app/templates/exercise_export/exercise_user.html.erb | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index c20546701..51761d023 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -49,12 +49,12 @@ class ZipsController < ApplicationController @course = @exercise.course default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed - @ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。 + @ex_users = default_ex_users.limit 2 #仅导出已提交的,截止后则是全部为提交的。 #可以分班选择 if group_id.present? exercise_students = @course.students.where(course_group_id: group_id) # 试卷所分班的全部人数 user_ids = exercise_students.pluck(:user_id).reject(&:blank?).uniq - @ex_users = @ex_users.where(user_id: user_ids) + @ex_users = @ex_users.where(user_id: user_ids).limit 2 end default_ex_users_size = @ex_users.size diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 1e3d88a44..62d2132ce 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -220,10 +220,10 @@ <% else %> <% check_answer = "--" %> <% end %> -

- 答案(填空<%= index+1 %>): - <%= to_markdown(check_answer,@request_url) %> -

+
+
答案(填空<%= index+1 %>):
+
<%= to_markdown(check_answer,@request_url) %>
+
<% end %> <% elsif q_type == 4 %> <% check_answer = (user_answer.present? ? user_answer.first.answer_text : '--') %> From f613331443ec493aec0dd9e5b96b6af67e08e4e8 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 15:38:12 +0800 Subject: [PATCH 0465/1015] fix bug --- app/templates/exercise_export/exercise_export.css | 3 +++ .../exercise_export/exercise_user.html.erb | 13 ++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 2745382f7..0c4bf54e5 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -328,6 +328,9 @@ textarea{ .choice-text p{ margin-bottom:0; } +.mt-2{ + margin-top:-2px; +} diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 62d2132ce..7e40047b0 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -21,8 +21,8 @@

<% if @exercise_single_ques_count > 0 %> - 单选题<%= @exercise_single_ques_count %>题, - 共<%= @exercise_single_ques_scores %> + 单选题<%= @exercise_single_ques_count %>题, + 共<%= @exercise_single_ques_scores %> <% end %> <% if @exercise_double_ques_count > 0 %> 多选题<%= @exercise_double_ques_count %>题, @@ -44,7 +44,6 @@ 实训题<%= @exercise_ques_shixun_count %>题, 共<%= @exercise_ques_shixun_scores %> <% end %> - <% if @exercise_ques_count > 0 %> <%= @exercise_ques_scores %>分 @@ -183,7 +182,7 @@ <% check_answer = (user_answer.present? && (s.id == user_answer.first.exercise_choice_id)) ? "choose-answer" : '' %>

- <%= to_markdown(s.choice_text,@request_url) %> + <%= to_markdown(s.choice_text,@request_url) %>
<% end %> <% elsif q_type == 1 %> @@ -195,7 +194,7 @@ <% else %> <% end %> - <%= to_markdown(s.choice_text,@request_url) %> + <%= to_markdown(s.choice_text,@request_url) %>
<% end %> <% elsif q_type == 2 %> @@ -221,13 +220,13 @@ <% check_answer = "--" %> <% end %>
-
答案(填空<%= index+1 %>):
+
答案(填空<%= index+1 %>):
<%= to_markdown(check_answer,@request_url) %>
<% end %> <% elsif q_type == 4 %> <% check_answer = (user_answer.present? ? user_answer.first.answer_text : '--') %> -
+
<%= to_markdown(check_answer,@request_url) %>
From b679e1f0bfe60ad22605960eda6f00431af459fc Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 15:48:57 +0800 Subject: [PATCH 0466/1015] fix bug --- app/templates/exercise_export/blank_exercise.html.erb | 2 +- app/templates/exercise_export/exercise_export.css | 5 +++++ app/templates/exercise_export/exercise_user.html.erb | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 153ba1514..759a2d2b0 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -94,7 +94,7 @@ <% elsif q.question_type == 2 %>
<% q.exercise_choices.each do |s| %> - + <%= s.choice_text %> diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 0c4bf54e5..d2a4fe0de 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -331,6 +331,11 @@ textarea{ .mt-2{ margin-top:-2px; } +.ex-scores{ + min-height: 100%; + height: auto !important; + position: relative; +} diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 7e40047b0..d79379596 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -220,8 +220,8 @@ <% check_answer = "--" %> <% end %>
-
答案(填空<%= index+1 %>):
-
<%= to_markdown(check_answer,@request_url) %>
+ 答案(填空<%= index+1 %>): + <%= to_markdown(check_answer,@request_url) %>
<% end %> <% elsif q_type == 4 %> From 90a6f4d7378dd04f8e9839d8c7343ee42ba2ab5b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 15:59:19 +0800 Subject: [PATCH 0467/1015] fix bug --- .../exercise_export/exercise_user.html.erb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index d79379596..e43af2fb9 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -21,8 +21,8 @@

<% if @exercise_single_ques_count > 0 %> - 单选题<%= @exercise_single_ques_count %>题, - 共<%= @exercise_single_ques_scores %> + 单选题<%= @exercise_single_ques_count %>题, + 共<%= @exercise_single_ques_scores %> <% end %> <% if @exercise_double_ques_count > 0 %> 多选题<%= @exercise_double_ques_count %>题, @@ -55,6 +55,7 @@

+
<% if @ex_obj_array.size > 0 %>
@@ -176,15 +177,17 @@ <% end %>
+
<% if q_type == 0 %> <% q.exercise_choices.each do |s| %> <% check_answer = (user_answer.present? && (s.id == user_answer.first.exercise_choice_id)) ? "choose-answer" : '' %> -
+
<%= to_markdown(s.choice_text,@request_url) %>
<% end %> +
<% elsif q_type == 1 %> <% q.exercise_choices.each do |s| %> <% check_answer = (user_answer.present? && (user_answer.pluck(:exercise_choice_id).include?(s.id))) ? true : false %> @@ -197,6 +200,7 @@ <%= to_markdown(s.choice_text,@request_url) %>
<% end %> +
<% elsif q_type == 2 %>
<% q.exercise_choices.each do |s| %> @@ -211,6 +215,7 @@ <% end %>
+
<% elsif q_type == 3 %> <% st_counts = q.exercise_standard_answers.pluck(:exercise_choice_id).uniq %> <% st_counts.each_with_index do |s,index| %> @@ -223,14 +228,16 @@ 答案(填空<%= index+1 %>): <%= to_markdown(check_answer,@request_url) %>
+
<% end %> <% elsif q_type == 4 %> <% check_answer = (user_answer.present? ? user_answer.first.answer_text : '--') %> -
+
<%= to_markdown(check_answer,@request_url) %>
+
<% else %>

@@ -327,6 +334,7 @@

<% end %>
+
<% end %>
From 5e87e88f560ab315caf514975c36ce06cea7be8d Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 16:17:31 +0800 Subject: [PATCH 0468/1015] fix bug --- app/controllers/zips_controller.rb | 4 ++-- app/services/exercise_user_pdf_service.rb | 2 +- app/templates/exercise_export/exercise_export.css | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 51761d023..c20546701 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -49,12 +49,12 @@ class ZipsController < ApplicationController @course = @exercise.course default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed - @ex_users = default_ex_users.limit 2 #仅导出已提交的,截止后则是全部为提交的。 + @ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。 #可以分班选择 if group_id.present? exercise_students = @course.students.where(course_group_id: group_id) # 试卷所分班的全部人数 user_ids = exercise_students.pluck(:user_id).reject(&:blank?).uniq - @ex_users = @ex_users.where(user_id: user_ids).limit 2 + @ex_users = @ex_users.where(user_id: user_ids) end default_ex_users_size = @ex_users.size diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index 44ee1e769..ee055ac66 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -41,7 +41,7 @@ class ExerciseUserPdfService # #-----正式需删掉 # aa = File.open(Rails.root.join("public/123.html"),"w+") # aa.syswrite(kit.source) - # #正式需删掉------- + # #正式需删掉-------s file = Tempfile.new(filename) kit.to_pdf(file.path) file diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index d2a4fe0de..bc06800a9 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -39,7 +39,7 @@ p{ margin-bottom: 10px; } .mt8{ - margin-top:8px; + margin-top:7px; } .mt10{ margin-top:10px; From bf2f8743aa0ac8ffcaa3a69f3695d4196c2cc20b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 16:27:32 +0800 Subject: [PATCH 0469/1015] fix bug --- app/templates/exercise_export/exercise_export.css | 3 +-- app/templates/exercise_export/exercise_user.html.erb | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index bc06800a9..97b070dc3 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -333,8 +333,7 @@ textarea{ } .ex-scores{ min-height: 100%; - height: auto !important; - position: relative; + height: auto ; } diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index e43af2fb9..2d41f93fa 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -37,12 +37,12 @@ 共<%= @exercise_ques_null_scores %>分 <% end %> <% if @exercise_ques_main_count > 0 %> - 主观题<%= @exercise_ques_main_count %>题, - 共<%= @exercise_ques_main_scores %> + 主观题<%= @exercise_ques_main_count %>题, + 共<%= @exercise_ques_main_scores %> <% end %> <% if @exercise_ques_shixun_count > 0 %> - 实训题<%= @exercise_ques_shixun_count %>题, - 共<%= @exercise_ques_shixun_scores %> + 实训题<%= @exercise_ques_shixun_count %>题, + 共<%= @exercise_ques_shixun_scores %> <% end %> <% if @exercise_ques_count > 0 %> From f4602d1d5cbfa59d3a97ffc720a2e3d2a8f6dae0 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 16:38:58 +0800 Subject: [PATCH 0470/1015] fixu bug --- app/templates/exercise_export/exercise_export.css | 1 - app/templates/exercise_export/exercise_user.html.erb | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 97b070dc3..1cfa57c80 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -332,7 +332,6 @@ textarea{ margin-top:-2px; } .ex-scores{ - min-height: 100%; height: auto ; } diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 2d41f93fa..bb50f7edf 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -182,7 +182,7 @@ <% if q_type == 0 %> <% q.exercise_choices.each do |s| %> <% check_answer = (user_answer.present? && (s.id == user_answer.first.exercise_choice_id)) ? "choose-answer" : '' %> -
+
<%= to_markdown(s.choice_text,@request_url) %>
From 0aa403ff757e39fdf3eaffb0c7f9f691a3ccff6b Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 1 Jul 2019 17:18:25 +0800 Subject: [PATCH 0471/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E7=AE=97=E5=88=86=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 20 ++++++++++--------- app/controllers/myshixuns_controller.rb | 2 +- app/models/homework_common.rb | 5 +++++ app/services/homeworks_service.rb | 2 +- lib/tasks/homework_publishtime.rake | 4 ++-- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 3562be4f3..aaffc34a6 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -238,7 +238,7 @@ class HomeworkCommonsController < ApplicationController end def update_score - tip_exception("作业还未发布,暂不能计算成绩") if @homework.publish_time.nil? || @homework.publish_time > Time.now + tip_exception("作业还未发布,暂不能计算成绩") if @homework.end_or_late_none_group begin if @homework.unified_setting student_works = @homework.student_works @@ -258,6 +258,8 @@ class HomeworkCommonsController < ApplicationController HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings end end + HomeworksService.new.update_student_eff_score @homework if (@homework.allow_late && @homework.late_time < Time.now) || + (!@homework.allow_late && @homework.end_time < Time.now) @homework.update_attribute('calculation_time', Time.now) normal_status("更新成功") rescue Exception => e @@ -606,14 +608,14 @@ class HomeworkCommonsController < ApplicationController @homework.score_open = params[:score_open] @homework.save! - if score_change - @homework.student_works.has_committed.each do |student_work| - HomeworksService.new.set_shixun_final_score student_work - end - end + # if score_change + # @homework.student_works.has_committed.each do |student_work| + # HomeworksService.new.set_shixun_final_score student_work + # end + # end # 更新所有学生的效率分(作业允许补交且补交已截止 或者 作业不允许补交且提交已截止) - if (score_change || update_eff_score) && @homework.end_or_late + if update_eff_score && @homework.end_or_late_none_group HomeworksService.new.update_student_eff_score HomeworkCommon.find_by(id: @homework.id) end @@ -1017,8 +1019,8 @@ class HomeworkCommonsController < ApplicationController homework.save! - # 更新学生状态及成绩 - HomeworkPublishUpdateWorkStatusJob.perform_later(tiding_group_ids, homework.id) + # 更新学生状态及成绩(手动点击计算) + # HomeworkPublishUpdateWorkStatusJob.perform_later(tiding_group_ids, homework.id) end normal_status(0, "发布成功") rescue Exception => e diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 909533301..9c3847b3c 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -167,7 +167,7 @@ class MyshixunsController < ApplicationController end # 更新实训关联的作品分数 TODO: 更新作品分数 - HomeworksService.new.update_myshixun_work_score myshixun + # HomeworksService.new.update_myshixun_work_score myshixun end # 如果过关了,下一关的状态是3(为开启),则需要把状态改成1(已开启) # next_game = game.next_game diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 8f24820e7..3e0bec5fe 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -118,6 +118,11 @@ class HomeworkCommon < ApplicationRecord status end + # 作业是否补交截止或者不允许补交且提交截止(不考虑分班) + def end_or_late_none_group + course.is_end || (allow_late && late_time < Time.now) || (!allow_late && end_time < Time.now) + end + # 作业是否可以查重 def code_review self.homework_type == 'practice' && self.publish_time.present? && self.publish_time < Time.now && self.homework_group_reviews.count == 0 diff --git a/app/services/homeworks_service.rb b/app/services/homeworks_service.rb index 48db76295..306a48d3c 100644 --- a/app/services/homeworks_service.rb +++ b/app/services/homeworks_service.rb @@ -156,7 +156,7 @@ class HomeworksService end # 用户评测时更新实训作业成绩 - def update_myshixun_work_score myshixun + def update_myshixun_work_score_old myshixun ActiveRecord::Base.transaction do student_works = myshixun.student_works.where(user_id: myshixun.user_id) #logger.info("#############student_works_count: #{student_works.count}") diff --git a/lib/tasks/homework_publishtime.rake b/lib/tasks/homework_publishtime.rake index 7ee2a4a07..4127a9339 100644 --- a/lib/tasks/homework_publishtime.rake +++ b/lib/tasks/homework_publishtime.rake @@ -23,7 +23,7 @@ namespace :homework_publishtime do homework_detail_manual.update_column('comment_status', 1) # 统一设置的作业在这发消息,非统一设置的只给有全部分班权限的老师发 if homework.unified_setting - HomeworkPublishUpdateWorkStatusJob.perform_later(nil, homework.id) + # HomeworkPublishUpdateWorkStatusJob.perform_later(nil, homework.id) HomeworkCommonPushNotifyJob.perform_later(homework.id, nil) else course = homework.course @@ -53,7 +53,7 @@ namespace :homework_publishtime do homework_group_settings.each do |homework_group| homework = homework_group.homework_common if homework.present? - HomeworkPublishUpdateWorkStatusJob.perform_now([homework_group.id], homework.id) + # HomeworkPublishUpdateWorkStatusJob.perform_now([homework_group.id], homework.id) HomeworkCommonPushNotifyJob.perform_later(homework.id, [homework_group.course_group_id]) end end From 148ac868e772afe6b1058388f0e5ad9802dbcc22 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 17:18:58 +0800 Subject: [PATCH 0472/1015] fix bug --- app/services/exercise_user_pdf_service.rb | 1 + .../exercise_export/exercise_export.css | 1 + .../exercise_export/exercise_user.html.erb | 23 +++++++++++-------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index ee055ac66..f0f7c1ac1 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -2,6 +2,7 @@ class ExerciseUserPdfService include ExercisesHelper include ApplicationHelper include StudentWorksHelper + include GitHelper attr_reader :exercise, :ex_user, :request_url diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 1cfa57c80..c2b054666 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -333,6 +333,7 @@ textarea{ } .ex-scores{ height: auto ; + word-break: break-all; } diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index bb50f7edf..ea782e23b 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -316,20 +316,23 @@ <% end %> - <% if game.try(:lastest_code).present? && game.challenge.st == 0 %> - <% con_rows = content_line(game.lastest_code) %> -
-

+ <% if game.try(:lastest_code).blank? %> + <% cha_path = challenge_path(game.challenge&.path) %> + <% latest_code = git_fle_content(game.myshixun.repo_path,cha_path) %> + <% else %> + <% latest_code = game.try(:lastest_code) %> + <% end %> +

+

最近通过的代码 - <%= game.challenge.path %> + <%= game.challenge&.path %> -

-
- -
+

+
+
- <% end %> +
<% end %> From 4e435cca0f7c96f03222a252bb935b729b0d6131 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 17:21:42 +0800 Subject: [PATCH 0473/1015] fix bug --- app/controllers/concerns/git_helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/concerns/git_helper.rb b/app/controllers/concerns/git_helper.rb index 8d769a244..65ebd4074 100644 --- a/app/controllers/concerns/git_helper.rb +++ b/app/controllers/concerns/git_helper.rb @@ -9,17 +9,17 @@ module GitHelper # 版本库文件内容,带转码 def git_fle_content(repo_path, path) begin - logger.info("git file content: repo_path is #{repo_path}, path is #{path}") + Rails.logger.info("git file content: repo_path is #{repo_path}, path is #{path}") content = GitService.file_content(repo_path: repo_path, path: path) - logger.info("git file content: content is #{content}") + Rails.logger.info("git file content: content is #{content}") decode_content = nil if content.present? content = content["content"] #6.24 -hs 这个为新增,因为当实训题里含有选择题时,这里会报错,undefined method `[]' for nil:NilClass content = Base64.decode64(content) cd = CharDet.detect(content) - logger.info "encoding: #{cd['encoding']} confidence: #{cd['confidence']}" + Rails.logger.info "encoding: #{cd['encoding']} confidence: #{cd['confidence']}" decode_content = if cd["encoding"] == 'GB18030' && cd['confidence'] > 0.8 From ee04d36e978b1afba99a21464385001e40a13a6c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 17:23:59 +0800 Subject: [PATCH 0474/1015] fix bug --- app/templates/exercise_export/exercise_export.css | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index c2b054666..b7f4892c1 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -315,10 +315,12 @@ table td{ /*}*/ textarea{ width:100%; + height:100%; resize:none; border:none; background-color:#eee; line-height:2; + } .clearfix{ clear:both; @@ -339,3 +341,4 @@ textarea{ + From 8a88b57a321d21ce050d40c3898f18ded89c0af7 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 17:27:10 +0800 Subject: [PATCH 0475/1015] fix bug --- app/helpers/exercises_helper.rb | 2 +- app/templates/exercise_export/exercise_export.css | 1 - app/templates/exercise_export/exercise_user.html.erb | 3 ++- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 1442e1da3..437965ca6 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -734,6 +734,6 @@ module ExercisesHelper #实训题学生代码的行数 def content_line(content) - content.split(/\r?\n/).length + content.split(/\r?\n/).length + 1 end end diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index b7f4892c1..407a39b1f 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -315,7 +315,6 @@ table td{ /*}*/ textarea{ width:100%; - height:100%; resize:none; border:none; background-color:#eee; diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index ea782e23b..52a083eab 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -322,6 +322,7 @@ <% else %> <% latest_code = game.try(:lastest_code) %> <% end %> + <% con_rows = content_line(latest_code) %>

@@ -330,7 +331,7 @@

- +
From fa692a25353d18b5737218f67a334c9e00bd1de2 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 17:37:22 +0800 Subject: [PATCH 0476/1015] fix bug --- app/templates/exercise_export/exercise_user.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 52a083eab..fa5060a1e 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -17,8 +17,8 @@

-
-
+
+

<% if @exercise_single_ques_count > 0 %> 单选题<%= @exercise_single_ques_count %>题, From 4904e536a262eebd6713e1ca5a3b3a5dba676272 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 17:38:32 +0800 Subject: [PATCH 0477/1015] fix bug --- app/templates/exercise_export/exercise_export.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 407a39b1f..09d8f0268 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -333,7 +333,7 @@ textarea{ margin-top:-2px; } .ex-scores{ - height: auto ; + height: 100% ; word-break: break-all; } From feca48a4574c4b21acb7307bdeaddc7d1bbd9f63 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 17:40:56 +0800 Subject: [PATCH 0478/1015] fix bug --- app/templates/exercise_export/exercise_export.css | 4 +++- app/templates/exercise_export/exercise_user.html.erb | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 09d8f0268..828987bb7 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -333,7 +333,8 @@ textarea{ margin-top:-2px; } .ex-scores{ - height: 100% ; + width:100%; + display:inline-block; word-break: break-all; } @@ -341,3 +342,4 @@ textarea{ + diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index fa5060a1e..52a083eab 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -17,8 +17,8 @@

-
-
+
+

<% if @exercise_single_ques_count > 0 %> 单选题<%= @exercise_single_ques_count %>题, From 68ad44129febc0310a9ae316c92142d6f267c456 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 17:42:34 +0800 Subject: [PATCH 0479/1015] fix bug --- app/templates/exercise_export/exercise_export.css | 3 +++ app/templates/exercise_export/exercise_user.html.erb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 828987bb7..8e950f7ed 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -332,6 +332,9 @@ textarea{ .mt-2{ margin-top:-2px; } +.width100{ + width:100%; +} .ex-scores{ width:100%; display:inline-block; diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 52a083eab..7e3a5a64f 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -17,7 +17,7 @@

-
+

<% if @exercise_single_ques_count > 0 %> From 479df01b7a28c0c1d999b2d71112a5ef0d30fd06 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 1 Jul 2019 17:44:17 +0800 Subject: [PATCH 0480/1015] fix bug --- app/templates/exercise_export/exercise_export.css | 8 ++++---- app/templates/exercise_export/exercise_user.html.erb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 8e950f7ed..66bd565b1 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -332,11 +332,11 @@ textarea{ .mt-2{ margin-top:-2px; } -.width100{ - width:100%; -} +/*.width100{*/ + /*width:100%;*/ +/*}*/ .ex-scores{ - width:100%; + /*width:100%;*/ display:inline-block; word-break: break-all; } diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 7e3a5a64f..52a083eab 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -17,7 +17,7 @@

-
+

<% if @exercise_single_ques_count > 0 %> From 65c7dafb8208a7b1f4a8211702eb4a4b0d168ff5 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 08:41:22 +0800 Subject: [PATCH 0481/1015] fix bug --- .../exercise_export/blank_exercise.html.erb | 28 +++++++++------ .../exercise_export/exercise_user.html.erb | 34 +++++++++++-------- 2 files changed, 36 insertions(+), 26 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 759a2d2b0..45a086e6e 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -20,41 +20,47 @@

- <% if @exercise_single_ques_count > 0 %> + + <% if @exercise_single_ques_count > 0 %> 单选题<%= @exercise_single_ques_count %>题, 共<%= @exercise_single_ques_scores %> <% end %> - <% if @exercise_double_ques_count > 0 %> + <% if @exercise_double_ques_count > 0 %> 多选题<%= @exercise_double_ques_count %>题, 共<%= @exercise_double_ques_scores %> <% end %> - <% if @exercise_ques_judge_count > 0 %> + <% if @exercise_ques_judge_count > 0 %> 判断题<%= @exercise_ques_judge_count %>题, 共<%= @exercise_ques_judge_scores %> <% end %> - <% if @exercise_ques_null_count > 0 %> + <% if @exercise_ques_null_count > 0 %> 填空题<%= @exercise_ques_null_count %>题, 共<%= @exercise_ques_null_scores %> <% end %> - <% if @exercise_ques_main_count > 0 %> + <% if @exercise_ques_main_count > 0 %> 主观题<%= @exercise_ques_main_count %>题, 共<%= @exercise_ques_main_scores %> <% end %> - <% if @exercise_ques_shixun_count > 0 %> + <% if @exercise_ques_shixun_count > 0 %> 实训题<%= @exercise_ques_shixun_count %>题, 共<%= @exercise_ques_shixun_scores %> <% end %> - <% if @exercise_ques_count > 0 %> - - 共<%= @exercise_ques_scores %>分 - - + + + + <% if @exercise_ques_count > 0 %> + 合计<%= @exercise_ques_count %> + + 共<%= @exercise_ques_scores %>分 + <% end %> +

+
<% @exercise_questions.each do |q| %>
diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 52a083eab..ba47d6b02 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -20,38 +20,42 @@

- <% if @exercise_single_ques_count > 0 %> + + <% if @exercise_single_ques_count > 0 %> 单选题<%= @exercise_single_ques_count %>题, 共<%= @exercise_single_ques_scores %> <% end %> - <% if @exercise_double_ques_count > 0 %> + <% if @exercise_double_ques_count > 0 %> 多选题<%= @exercise_double_ques_count %>题, 共<%= @exercise_double_ques_scores %> <% end %> - <% if @exercise_ques_judge_count > 0 %> + <% if @exercise_ques_judge_count > 0 %> 判断题<%= @exercise_ques_judge_count %>题, 共<%= @exercise_ques_judge_scores %> <% end %> - <% if @exercise_ques_null_count > 0 %> + <% if @exercise_ques_null_count > 0 %> 填空题<%= @exercise_ques_null_count %>题, 共<%= @exercise_ques_null_scores %> <% end %> - <% if @exercise_ques_main_count > 0 %> - 主观题<%= @exercise_ques_main_count %>题, - 共<%= @exercise_ques_main_scores %> + <% if @exercise_ques_main_count > 0 %> + 主观题<%= @exercise_ques_main_count %>题, + 共<%= @exercise_ques_main_scores %> <% end %> - <% if @exercise_ques_shixun_count > 0 %> - 实训题<%= @exercise_ques_shixun_count %>题, - 共<%= @exercise_ques_shixun_scores %> + <% if @exercise_ques_shixun_count > 0 %> + 实训题<%= @exercise_ques_shixun_count %>题, + 共<%= @exercise_ques_shixun_scores %> <% end %> - <% if @exercise_ques_count > 0 %> - - 共<%= @exercise_ques_scores %>分 - - + + + <% if @exercise_ques_count > 0 %> + 合计<%= @exercise_ques_count %> + + 共<%= @exercise_ques_scores %>分 + <% end %> +

From 4267b8d32cf5eea0876e83fa833fedeb266813ca Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 08:46:36 +0800 Subject: [PATCH 0482/1015] fix bug --- app/templates/exercise_export/exercise_export.css | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 66bd565b1..cdb4adc32 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -2,6 +2,9 @@ body{ font-size:14px; font-family: "微软雅黑","宋体"; } +.container{ + width:1200px; +} p{ margin:0; } From b6cd30946ae494b6ecbbe7411c0c91698296acab Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 08:49:48 +0800 Subject: [PATCH 0483/1015] fix bug --- app/templates/exercise_export/blank_exercise.html.erb | 2 +- app/templates/exercise_export/exercise_export.css | 10 ++++------ app/templates/exercise_export/exercise_user.html.erb | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 45a086e6e..37900d983 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -19,7 +19,7 @@
-

+

<% if @exercise_single_ques_count > 0 %> 单选题<%= @exercise_single_ques_count %>题, diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index cdb4adc32..6e2ecd8b3 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -2,9 +2,7 @@ body{ font-size:14px; font-family: "微软雅黑","宋体"; } -.container{ - width:1200px; -} + p{ margin:0; } @@ -335,9 +333,9 @@ textarea{ .mt-2{ margin-top:-2px; } -/*.width100{*/ - /*width:100%;*/ -/*}*/ +.width100{ + width:100%; +} .ex-scores{ /*width:100%;*/ display:inline-block; diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index ba47d6b02..9b2fef1e0 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -19,7 +19,7 @@

-

+

<% if @exercise_single_ques_count > 0 %> 单选题<%= @exercise_single_ques_count %>题, From 402562144dbb0978aa60452443af9c7656138c35 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 08:53:17 +0800 Subject: [PATCH 0484/1015] fix bug --- app/templates/exercise_export/exercise_export.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 6e2ecd8b3..e34eefedc 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -338,7 +338,7 @@ textarea{ } .ex-scores{ /*width:100%;*/ - display:inline-block; + /*display:inline-block;*/ word-break: break-all; } From 7be1a7901cfd806612e59758181c1f5a6d6b3170 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 08:56:16 +0800 Subject: [PATCH 0485/1015] fix bug --- app/templates/exercise_export/exercise_export.css | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index e34eefedc..2e5f77a11 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -337,8 +337,8 @@ textarea{ width:100%; } .ex-scores{ - /*width:100%;*/ - /*display:inline-block;*/ + width:100%; + display:inline-block; word-break: break-all; } From 684084cc6387dc56e2b9195bd7dbd8c69cf8572a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 09:02:43 +0800 Subject: [PATCH 0486/1015] fix bug --- app/controllers/exercises_controller.rb | 2 +- app/templates/exercise_export/blank_exercise.html.erb | 2 +- app/templates/exercise_export/exercise_user.html.erb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 3c364b979..aee99fbab 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1335,7 +1335,7 @@ class ExercisesController < ApplicationController def export_exercise @request_url = request.base_url @exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") - filename = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.current.strftime('%Y%m%d%H%M%S')}.pdf" + filename = "#{@exercise.user.real_name}_#{@exercise.exercise_name}_#{Time.current.strftime('%Y%m%d%H%M%S')}.pdf" stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css" render pdf: 'exercise_export/blank_exercise', filename: filename, stylesheets: stylesheets end diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 37900d983..48bb1567f 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -19,7 +19,7 @@

-

+

<% if @exercise_single_ques_count > 0 %> 单选题<%= @exercise_single_ques_count %>题, diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 9b2fef1e0..42d25dd1b 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -19,7 +19,7 @@

-

+

<% if @exercise_single_ques_count > 0 %> 单选题<%= @exercise_single_ques_count %>题, From 5d3cb93b35f6b1319423f7d017d178d9d721bb96 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 09:10:22 +0800 Subject: [PATCH 0487/1015] fi xbug --- app/templates/exercise_export/exercise_user.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 42d25dd1b..934ca6586 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -17,7 +17,7 @@

-
+

From e178f32db50613624c0fbaba460ccd6245133b03 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 09:32:22 +0800 Subject: [PATCH 0488/1015] fix bug --- app/controllers/exercises_controller.rb | 2 +- app/controllers/zips_controller.rb | 4 ++-- app/services/exercise_user_pdf_service.rb | 4 ++-- app/services/export_exercises_service.rb | 2 +- .../exercise_export/blank_exercise.html.erb | 19 ++++++++----------- .../exercise_export/exercise_export.css | 4 ++-- .../exercise_export/exercise_user.html.erb | 16 +++++++--------- 7 files changed, 23 insertions(+), 28 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index aee99fbab..ff4dc6be9 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1335,7 +1335,7 @@ class ExercisesController < ApplicationController def export_exercise @request_url = request.base_url @exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") - filename = "#{@exercise.user.real_name}_#{@exercise.exercise_name}_#{Time.current.strftime('%Y%m%d%H%M%S')}.pdf" + filename = "#{@exercise.user.real_name}_#{@exercise.exercise_name}_#{Time.current.strftime('%Y%m%d_%H%M')}.pdf" stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css" render pdf: 'exercise_export/blank_exercise', filename: filename, stylesheets: stylesheets end diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index c20546701..51761d023 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -49,12 +49,12 @@ class ZipsController < ApplicationController @course = @exercise.course default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed - @ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。 + @ex_users = default_ex_users.limit 2 #仅导出已提交的,截止后则是全部为提交的。 #可以分班选择 if group_id.present? exercise_students = @course.students.where(course_group_id: group_id) # 试卷所分班的全部人数 user_ids = exercise_students.pluck(:user_id).reject(&:blank?).uniq - @ex_users = @ex_users.where(user_id: user_ids) + @ex_users = @ex_users.where(user_id: user_ids).limit 2 end default_ex_users_size = @ex_users.size diff --git a/app/services/exercise_user_pdf_service.rb b/app/services/exercise_user_pdf_service.rb index f0f7c1ac1..73711192f 100644 --- a/app/services/exercise_user_pdf_service.rb +++ b/app/services/exercise_user_pdf_service.rb @@ -15,8 +15,8 @@ class ExerciseUserPdfService end def filename - user_course = @course.course_members.find_by(user_id:@ex_user_user.id).course_group_name - exercise_user_name = user_course + "_" + exercise.exercise_name + "_" + @ex_user_user.real_name + user_course = @course.course_members.find_by(user_id:@ex_user_user.id)&.course_group_name + exercise_user_name = "#{@ex_user_user.real_name}_#{user_course.present? ? user_course : "未分班"}_#{exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M')}" "#{exercise_user_name.strip}.pdf" end diff --git a/app/services/export_exercises_service.rb b/app/services/export_exercises_service.rb index f83323d7e..3aac67713 100644 --- a/app/services/export_exercises_service.rb +++ b/app/services/export_exercises_service.rb @@ -10,7 +10,7 @@ class ExportExercisesService end def filename - exercise_export_name = exercise.user.real_name + "_" + exercise.exercise_name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') + exercise_export_name = "#{exercise.user.real_name}_#{exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M')}" "#{exercise_export_name.strip}.zip" end diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 48bb1567f..bb7b28f22 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -17,37 +17,34 @@

-
+
-

- - <% if @exercise_single_ques_count > 0 %> +

+ <% if @exercise_single_ques_count > 0 %> 单选题<%= @exercise_single_ques_count %>题, 共<%= @exercise_single_ques_scores %> <% end %> - <% if @exercise_double_ques_count > 0 %> + <% if @exercise_double_ques_count > 0 %> 多选题<%= @exercise_double_ques_count %>题, 共<%= @exercise_double_ques_scores %> <% end %> - <% if @exercise_ques_judge_count > 0 %> + <% if @exercise_ques_judge_count > 0 %> 判断题<%= @exercise_ques_judge_count %>题, 共<%= @exercise_ques_judge_scores %> <% end %> - <% if @exercise_ques_null_count > 0 %> + <% if @exercise_ques_null_count > 0 %> 填空题<%= @exercise_ques_null_count %>题, 共<%= @exercise_ques_null_scores %> <% end %> - <% if @exercise_ques_main_count > 0 %> + <% if @exercise_ques_main_count > 0 %> 主观题<%= @exercise_ques_main_count %>题, 共<%= @exercise_ques_main_scores %> <% end %> - <% if @exercise_ques_shixun_count > 0 %> + <% if @exercise_ques_shixun_count > 0 %> 实训题<%= @exercise_ques_shixun_count %>题, 共<%= @exercise_ques_shixun_scores %> <% end %> - - <% if @exercise_ques_count > 0 %> 合计<%= @exercise_ques_count %>题 diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index 2e5f77a11..e34eefedc 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -337,8 +337,8 @@ textarea{ width:100%; } .ex-scores{ - width:100%; - display:inline-block; + /*width:100%;*/ + /*display:inline-block;*/ word-break: break-all; } diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 934ca6586..847820d57 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -19,33 +19,31 @@

-

- - <% if @exercise_single_ques_count > 0 %> +

+ <% if @exercise_single_ques_count > 0 %> 单选题<%= @exercise_single_ques_count %>题, 共<%= @exercise_single_ques_scores %> <% end %> - <% if @exercise_double_ques_count > 0 %> + <% if @exercise_double_ques_count > 0 %> 多选题<%= @exercise_double_ques_count %>题, 共<%= @exercise_double_ques_scores %> <% end %> - <% if @exercise_ques_judge_count > 0 %> + <% if @exercise_ques_judge_count > 0 %> 判断题<%= @exercise_ques_judge_count %>题, 共<%= @exercise_ques_judge_scores %> <% end %> - <% if @exercise_ques_null_count > 0 %> + <% if @exercise_ques_null_count > 0 %> 填空题<%= @exercise_ques_null_count %>题, 共<%= @exercise_ques_null_scores %> <% end %> - <% if @exercise_ques_main_count > 0 %> + <% if @exercise_ques_main_count > 0 %> 主观题<%= @exercise_ques_main_count %>题, 共<%= @exercise_ques_main_scores %> <% end %> - <% if @exercise_ques_shixun_count > 0 %> + <% if @exercise_ques_shixun_count > 0 %> 实训题<%= @exercise_ques_shixun_count %>题, 共<%= @exercise_ques_shixun_scores %> <% end %> - <% if @exercise_ques_count > 0 %> From ce2344eecd1ebc4bc703ded6434655e8ec31970a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 09:44:14 +0800 Subject: [PATCH 0489/1015] fix bug --- app/controllers/zips_controller.rb | 4 ++-- app/templates/exercise_export/blank_exercise.html.erb | 2 +- app/templates/exercise_export/exercise_export.css | 1 + app/templates/exercise_export/exercise_user.html.erb | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 51761d023..c20546701 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -49,12 +49,12 @@ class ZipsController < ApplicationController @course = @exercise.course default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed - @ex_users = default_ex_users.limit 2 #仅导出已提交的,截止后则是全部为提交的。 + @ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。 #可以分班选择 if group_id.present? exercise_students = @course.students.where(course_group_id: group_id) # 试卷所分班的全部人数 user_ids = exercise_students.pluck(:user_id).reject(&:blank?).uniq - @ex_users = @ex_users.where(user_id: user_ids).limit 2 + @ex_users = @ex_users.where(user_id: user_ids) end default_ex_users_size = @ex_users.size diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index bb7b28f22..5e763d1cc 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -19,7 +19,7 @@

-

+

<% if @exercise_single_ques_count > 0 %> 单选题<%= @exercise_single_ques_count %>题, 共<%= @exercise_single_ques_scores %> diff --git a/app/templates/exercise_export/exercise_export.css b/app/templates/exercise_export/exercise_export.css index e34eefedc..119d92a05 100644 --- a/app/templates/exercise_export/exercise_export.css +++ b/app/templates/exercise_export/exercise_export.css @@ -340,6 +340,7 @@ textarea{ /*width:100%;*/ /*display:inline-block;*/ word-break: break-all; + line-height:2; } diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 847820d57..1c91baec2 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -19,7 +19,7 @@

-

+

<% if @exercise_single_ques_count > 0 %> 单选题<%= @exercise_single_ques_count %>题, 共<%= @exercise_single_ques_scores %> From 95255749bd4f98eb2c3ddcd55e5df52b67546052 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 2 Jul 2019 11:23:49 +0800 Subject: [PATCH 0490/1015] =?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/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index aaffc34a6..af1dffe71 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -272,7 +272,7 @@ class HomeworkCommonsController < ApplicationController def update_student_score work = @homework.student_works.find_by(user_id: current_user.id) myshixun = Myshixun.find_by(shixun_id: params[:shixun_id], user_id: current_user.id) - ActiveRecord::Base.transaction do + ActiveRecord::Base.transaction do begin if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at) challenge_settings = @homework.homework_challenge_settings From c3885ec64c6f9982452c8b1ca0deba763135a889 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 2 Jul 2019 11:43:02 +0800 Subject: [PATCH 0491/1015] =?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/controllers/shixuns_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 0d913a0a1..767129026 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -280,7 +280,6 @@ class ShixunsController < ApplicationController @small_type = shixun_small_type end - # 注意这里传参都应该使用params[:shixun]['name']这种格式 def create # 评测脚本的一些操作 main_type, sub_type = params[:main_type], params[:small_type] @@ -388,7 +387,8 @@ class ShixunsController < ApplicationController ShixunMirrorRepository.create(:shixun_id => @shixun.id, :mirror_repository_id => mirror) end end - + logger.info("#######shixun_params: ##{shixun_params}") + logger.info("#######shixun_info_params: ##{shixun_info_params}") @shixun.update_attributes(shixun_params) @shixun.shixun_info.update_attributes(shixun_info_params) @shixun.shixun_schools.delete_all @@ -735,7 +735,7 @@ private def shixun_params raise("实训名称不能为空") if params[:shixun][:name].blank? params.require(:shixun).permit(:name, :trainee, :webssh, :can_copy, :use_scope, :vnc, :test_set_permission, - :task_pass, :repo_name, :multi_webssh, :opening_time, :mirror_script_id, :code_hidden, + :task_pass, :multi_webssh, :opening_time, :mirror_script_id, :code_hidden, :hide_code, :forbid_copy) end def shixun_info_params From 61747f8e840675f796de679fcf99b48cef8807a7 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 12:25:44 +0800 Subject: [PATCH 0492/1015] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=95=E5=8D=B7?= =?UTF-8?q?=E5=92=8C=E9=97=AE=E5=8D=B7=E7=AD=94=E9=A2=98=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E6=90=9C=E7=B4=A2=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 10 ++-------- app/controllers/polls_controller.rb | 10 +++------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index ff4dc6be9..2761523a6 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1278,14 +1278,8 @@ class ExercisesController < ApplicationController #搜索 if params[:search].present? - search_content = params[:search] - #搜索用户的nickname,如果存在则返回,否则继续查询用户的真实姓名或学生号 - nick_name_search = @exercise_users_list.where(user_id: User.where('CONCAT(users.lastname, users.firstname) like ?',"%#{search_content}%")) - if nick_name_search.present? - @exercise_users_list = nick_name_search - else - @exercise_users_list = @exercise_users_list.joins(user: [:user_extension]).where('user_extensions.student_id like ? OR user_extensions.student_realname like ?',"%#{search_content}%","%#{search_content}%") - end + + @exercise_users_list = @exercise_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%") end @export_ex_users = @exercise_users_list diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index cd9679972..90ca1778e 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -1026,13 +1026,9 @@ class PollsController < ApplicationController #搜索 if search_content.present? - #搜索用户的nickname,如果存在则返回,否则继续查询用户的真实姓名或学生号 - nick_name_search = @poll_users_list.where(user_id: User.where('CONCAT(users.lastname, users.firstname) like ?',"%#{search_content}%")) - if nick_name_search.present? - @poll_users_list = nick_name_search - else - @poll_users_list = @poll_users_list.joins(user: [:user_extension]).where('user_extensions.student_id like ? OR user_extensions.student_realname like ?',"%#{search_content}%","%#{search_content}%") - end + + @poll_users_list = @poll_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{search_content}%", "%#{search_content}%") + end @poll_users_size = @poll_users_list.count From 50c7e9815e7d71ab46e641c07ad94b72968c0c9c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 13:43:19 +0800 Subject: [PATCH 0493/1015] fix bug --- app/controllers/polls_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 90ca1778e..24aa54309 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -953,12 +953,14 @@ class PollsController < ApplicationController @poll_publish_count = get_user_permission_course(poll_ids,2).count @poll_unpublish_count = get_user_permission_course(poll_ids,1).count @course_all_members = @course.students + logger.info("#######F___________poll_user_ids________________####{@poll.poll_users.pluck(:id)}") @poll_group_counts = @course.course_groups_count if @user_course_identity < Course::STUDENT #当前为老师,而且老师只能查看自己班级的/课堂的问卷 @poll_current_user_status = 0 - @poll_users_list = @poll.all_poll_users(current_user.id).distinct #该老师分班的全部学生 + @poll_users_list = @poll.all_poll_users(current_user.id) #该老师分班的全部学生 get_poll_answers(@poll_users_list) + logger.info("#######F__________@poll_users_list________________####{@poll_users_list.pluck(:id)}") if @poll_list_status == 1 @poll_course_groups =[] @@ -1026,9 +1028,7 @@ class PollsController < ApplicationController #搜索 if search_content.present? - @poll_users_list = @poll_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{search_content}%", "%#{search_content}%") - end @poll_users_size = @poll_users_list.count From b1e13758d3d1c127b4153460b1ec04e70d1ebcd1 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 2 Jul 2019 13:53:00 +0800 Subject: [PATCH 0494/1015] add school and department api for option --- app/controllers/departments_controller.rb | 11 +++++++++++ app/controllers/schools_controller.rb | 4 ++++ app/models/department.rb | 22 +++++++++++++++++++++ app/models/school.rb | 24 +++++++++++++++++++++++ config/routes.rb | 6 +++++- 5 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 app/controllers/departments_controller.rb diff --git a/app/controllers/departments_controller.rb b/app/controllers/departments_controller.rb new file mode 100644 index 000000000..f0fa8fe2c --- /dev/null +++ b/app/controllers/departments_controller.rb @@ -0,0 +1,11 @@ +class DepartmentsController < ApplicationController + def for_option + render_ok(departments: Department.cached_names_data(current_school)) + end + + private + + def current_school + @_current_school ||= School.find(params[:id]) + end +end \ No newline at end of file diff --git a/app/controllers/schools_controller.rb b/app/controllers/schools_controller.rb index 11932be42..ea94f4c69 100644 --- a/app/controllers/schools_controller.rb +++ b/app/controllers/schools_controller.rb @@ -9,4 +9,8 @@ class SchoolsController < ApplicationController render_ok(school_names: schools.pluck(:name)) end + + def for_option + render_ok(schools: School.cached_names_data) + end end diff --git a/app/models/department.rb b/app/models/department.rb index 15a8a7c1b..bf5c3a90e 100644 --- a/app/models/department.rb +++ b/app/models/department.rb @@ -2,4 +2,26 @@ class Department < ApplicationRecord belongs_to :school has_many :department_members, dependent: :destroy + + after_create_commit :reset_data_cache + after_update_commit :reset_data_cache + + def self.cached_names_data(school) + Rails.cache.fetch(names_data_cache_key(school.id), expires_in: 7.days) do + school.departments.select(:id, :name).as_json + end + end + + private + + def reset_data_cache + # 清除部门名称缓存 + if new_record? || name_previously_changed? + Rails.cache.delete(self.class.names_data_cache_key(school_id)) + end + end + + def self.names_data_cache_key(school_id) + "schools/#{school_id}/department_names_data" + end end diff --git a/app/models/school.rb b/app/models/school.rb index af04ed0c7..983a93735 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -1,4 +1,6 @@ class School < ApplicationRecord + has_many :departments, dependent: :destroy + has_many :shixun_schools, :dependent => :destroy has_many :shixuns, :through => :shixun_schools @@ -8,6 +10,9 @@ class School < ApplicationRecord has_many :ec_major_schools, :dependent => :destroy has_many :ec_majors, :through => :ec_major_schools + after_create_commit :reset_data_cache + after_update_commit :reset_data_cache + # 学校管理员 def manager?(user) ec_school_users.exists?(user_id: user.id) @@ -28,4 +33,23 @@ class School < ApplicationRecord def manage_permission?(user) manager?(user) || major_manager?(user) || course_manager?(user) end + + def self.cached_names_data + Rails.cache.fetch(names_data_cache_key, expires_in: 7.days) do + School.select(:id, :name).as_json + end + end + + private + + def reset_data_cache + # 清除学校名称缓存 + if new_record? || name_previously_changed? + Rails.cache.delete(self.class.names_data_cache_key) + end + end + + def self.names_data_cache_key + 'schools/names_data' + end end diff --git a/config/routes.rb b/config/routes.rb index 0f47cda76..a27dde1f3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -576,9 +576,13 @@ Rails.application.routes.draw do resources :schools do member do + resources :departments, only: [] do + get :for_option, on: :collection + end end collection do - get "school_list" + get :school_list + get :for_option end scope module: :ecs do From 1cbd20b57add58f719a7cefbf7f07af8320378d1 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 13:58:43 +0800 Subject: [PATCH 0495/1015] fix bug --- app/controllers/polls_controller.rb | 2 ++ app/models/poll.rb | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 24aa54309..e1ea02016 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -961,6 +961,8 @@ class PollsController < ApplicationController @poll_users_list = @poll.all_poll_users(current_user.id) #该老师分班的全部学生 get_poll_answers(@poll_users_list) logger.info("#######F__________@poll_users_list________________####{@poll_users_list.pluck(:id)}") + logger.info("#######F__________@users_ids________________####{PollUser.where(id:@poll_users_list.pluck(:id)).pluck(:user_id)}") + if @poll_list_status == 1 @poll_course_groups =[] diff --git a/app/models/poll.rb b/app/models/poll.rb index f72239ba7..7e71505ba 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -52,12 +52,12 @@ class Poll < ApplicationRecord # 统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生 def all_poll_users(user_id) - poll_users = self.poll_users + poll_all_users = poll_users group_ids = poll_published_ids(user_id) if group_ids.present? - poll_users = poll_users.where(user_id: course.students.where(course_group_id: group_ids).pluck(:user_id)) + poll_all_users = poll_all_users.where(user_id: course.students.where(course_group_id: group_ids).pluck(:user_id).uniq) end - poll_users + poll_all_users end #当前用户已发布的班级id和试卷分组已发布的班级id的交集 From 3d6ab9da88fe236d4aff0d344789e15b4c65efec Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 14:02:58 +0800 Subject: [PATCH 0496/1015] fix bug --- app/controllers/polls_controller.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index e1ea02016..810bf55c1 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -1029,15 +1029,20 @@ class PollsController < ApplicationController end #搜索 - if search_content.present? - @poll_users_list = @poll_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{search_content}%", "%#{search_content}%") - end + # if search_content.present? + # @poll_users_list = @poll_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{search_content}%", "%#{search_content}%") + # end + + logger.info("#######F_______@poll_users_list_last___@users_ids________________####{@poll_users_list.pluck(:id)}") + @poll_users_size = @poll_users_list.count # 分页 @page = params[:page] || 1 @limit = params[:limit] || 20 @poll_users_list = @poll_users_list.page(@page).per(@limit) + logger.info("#######F_______@poll_users_list_after_page___@users_ids________________####{@poll_users_list.pluck(:id)}") + else @poll_users_list = [] @poll_users_size = 0 From 8269367f4737ef49753bfebcb81e4680718cacc6 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 14:21:16 +0800 Subject: [PATCH 0497/1015] fix bug --- app/controllers/polls_controller.rb | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 810bf55c1..7ac288d7d 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -1029,20 +1029,19 @@ class PollsController < ApplicationController end #搜索 - # if search_content.present? - # @poll_users_list = @poll_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{search_content}%", "%#{search_content}%") - # end + if search_content.present? + @poll_users_list = @poll_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{search_content}%", "%#{search_content}%") + end logger.info("#######F_______@poll_users_list_last___@users_ids________________####{@poll_users_list.pluck(:id)}") @poll_users_size = @poll_users_list.count # 分页 - @page = params[:page] || 1 - @limit = params[:limit] || 20 - @poll_users_list = @poll_users_list.page(@page).per(@limit) + page = params[:page] || 1 + limit = params[:limit] || 20 + @poll_users_list = @poll_users_list.page(page).per(limit) logger.info("#######F_______@poll_users_list_after_page___@users_ids________________####{@poll_users_list.pluck(:id)}") - else @poll_users_list = [] @poll_users_size = 0 From 910c0b13b3fe2e0fae05258c94426b4229a91671 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 2 Jul 2019 14:23:20 +0800 Subject: [PATCH 0498/1015] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 767129026..65d671856 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -387,8 +387,6 @@ class ShixunsController < ApplicationController ShixunMirrorRepository.create(:shixun_id => @shixun.id, :mirror_repository_id => mirror) end end - logger.info("#######shixun_params: ##{shixun_params}") - logger.info("#######shixun_info_params: ##{shixun_info_params}") @shixun.update_attributes(shixun_params) @shixun.shixun_info.update_attributes(shixun_info_params) @shixun.shixun_schools.delete_all @@ -407,6 +405,8 @@ class ShixunsController < ApplicationController # 超级管理员和运营人员才能保存 中间层服务器pod信息的配置 if current_user.admin? || current_user.business? @shixun.shixun_service_configs.destroy_all + ActionController::Parameters.permit_all_parameters = true + logger.info("##--;;;;---#{params[:shixun_service_configs]}") params[:shixun_service_configs].each do |config| @shixun.shixun_service_configs.create!(config) end @@ -738,6 +738,7 @@ private :task_pass, :multi_webssh, :opening_time, :mirror_script_id, :code_hidden, :hide_code, :forbid_copy) end + def shixun_info_params raise("实训描述不能为空") if params[:shixun_info][:description].blank? raise("评测脚本不能为空") if params[:shixun_info][:evaluate_script].blank? From 857f2dcb3e169d27fcf804e919b0f3ac66d2ee55 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 14:43:56 +0800 Subject: [PATCH 0499/1015] fix bug --- app/controllers/exercises_controller.rb | 2 +- app/controllers/polls_controller.rb | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 2761523a6..a793c673c 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1238,7 +1238,7 @@ class ExercisesController < ApplicationController @teacher_unreview_count = 0 #筛选/分类,排序 order = params[:order] - if @exercise_users_list.present? && @exercise_users_list.count > 0 + if @exercise_users_list.present? && @exercise_users_list.size > 0 teacher_reviews = @exercise_users_list.exercise_review teacher_unreviews = @exercise_users_list.exercise_unreview @teacher_review_count = teacher_reviews.count #已评阅 diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 7ac288d7d..6a8edee71 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -953,17 +953,12 @@ class PollsController < ApplicationController @poll_publish_count = get_user_permission_course(poll_ids,2).count @poll_unpublish_count = get_user_permission_course(poll_ids,1).count @course_all_members = @course.students - logger.info("#######F___________poll_user_ids________________####{@poll.poll_users.pluck(:id)}") @poll_group_counts = @course.course_groups_count if @user_course_identity < Course::STUDENT #当前为老师,而且老师只能查看自己班级的/课堂的问卷 @poll_current_user_status = 0 @poll_users_list = @poll.all_poll_users(current_user.id) #该老师分班的全部学生 get_poll_answers(@poll_users_list) - logger.info("#######F__________@poll_users_list________________####{@poll_users_list.pluck(:id)}") - logger.info("#######F__________@users_ids________________####{PollUser.where(id:@poll_users_list.pluck(:id)).pluck(:user_id)}") - - if @poll_list_status == 1 @poll_course_groups =[] else @@ -1033,15 +1028,15 @@ class PollsController < ApplicationController @poll_users_list = @poll_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{search_content}%", "%#{search_content}%") end - logger.info("#######F_______@poll_users_list_last___@users_ids________________####{@poll_users_list.pluck(:id)}") - + logger.info("#######F_______@poll_users_list_last___@users_ids________________####{@poll_users_list.pluck(:user_id)}") @poll_users_size = @poll_users_list.count + # 分页 page = params[:page] || 1 limit = params[:limit] || 20 @poll_users_list = @poll_users_list.page(page).per(limit) - logger.info("#######F_______@poll_users_list_after_page___@users_ids________________####{@poll_users_list.pluck(:id)}") + logger.info("#######F_______@poll_users_list_after_page___@users_ids________________####{@poll_users_list.pluck(:user_id)}") else @poll_users_list = [] @poll_users_size = 0 From 23333a8186e50f1ab51d0fc17fd8de027f5cdd80 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 2 Jul 2019 14:55:59 +0800 Subject: [PATCH 0500/1015] =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/polls_controller.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 6a8edee71..d928d1df5 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -1005,12 +1005,6 @@ class PollsController < ApplicationController if @poll_users_list.present? && @poll_users_list.count > 0 - if order == "student_id" - @poll_users_list = @poll_users_list.joins(user: [:user_extension]).order("user_extensions.student_id DESC") - else - @poll_users_list = @poll_users_list.order("end_at DESC") - end - #答题状态的选择 if choose_type.present? @poll_users_list = @poll_users_list.commit_by_status(choose_type) @@ -1027,8 +1021,12 @@ class PollsController < ApplicationController if search_content.present? @poll_users_list = @poll_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{search_content}%", "%#{search_content}%") end - - logger.info("#######F_______@poll_users_list_last___@users_ids________________####{@poll_users_list.pluck(:user_id)}") + if order == "student_id" + @poll_users_list = @poll_users_list.joins(user: :user_extension).order("user_extensions.student_id DESC") + else + @poll_users_list = @poll_users_list.order("end_at DESC") + end + logger.info("#######user_id: ####{@poll_users_list.pluck(:user_id).sort}") @poll_users_size = @poll_users_list.count @@ -1036,7 +1034,7 @@ class PollsController < ApplicationController page = params[:page] || 1 limit = params[:limit] || 20 @poll_users_list = @poll_users_list.page(page).per(limit) - logger.info("#######F_______@poll_users_list_after_page___@users_ids________________####{@poll_users_list.pluck(:user_id)}") + logger.info("#####page_user: #{@poll_users_list.pluck(:user_id).sort}") else @poll_users_list = [] @poll_users_size = 0 From 91d875c36b9bbab0a02b12cbd900b297f2cb861d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 2 Jul 2019 15:01:20 +0800 Subject: [PATCH 0501/1015] =?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/controllers/polls_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index d928d1df5..50784ee74 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -1024,9 +1024,9 @@ class PollsController < ApplicationController if order == "student_id" @poll_users_list = @poll_users_list.joins(user: :user_extension).order("user_extensions.student_id DESC") else - @poll_users_list = @poll_users_list.order("end_at DESC") + @poll_users_list = @poll_users_list.joins(user: :user_extension).order("end_at DESC") end - logger.info("#######user_id: ####{@poll_users_list.pluck(:user_id).sort}") + logger.info("#######user_id: ####{@poll_users_list.pluck(:id, :user_id)}") @poll_users_size = @poll_users_list.count @@ -1034,7 +1034,7 @@ class PollsController < ApplicationController page = params[:page] || 1 limit = params[:limit] || 20 @poll_users_list = @poll_users_list.page(page).per(limit) - logger.info("#####page_user: #{@poll_users_list.pluck(:user_id).sort}") + logger.info("#####page_user: #{@poll_users_list.pluck(:id, :user_id)}") else @poll_users_list = [] @poll_users_size = 0 From 2b2257b181dc5dd2ce7e92547565f91da74b1112 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 15:16:24 +0800 Subject: [PATCH 0502/1015] fix bug --- app/controllers/homework_commons_controller.rb | 3 ++- app/controllers/polls_controller.rb | 11 ++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index af1dffe71..2478633a1 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -186,7 +186,7 @@ class HomeworkCommonsController < ApplicationController end @work_count = @student_works.size - @work_excel = @student_works + @work_excel = @student_works.includes(:student_works_scores) @students = @course.students # 分页参数 @@ -207,6 +207,7 @@ class HomeworkCommonsController < ApplicationController tip_exception(403, "无权限操作") else if @work_excel.present? + @homework = @homework.includes() student_work_to_xlsx(@work_excel,@homework) exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 6a8edee71..81e6cedaa 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -1005,11 +1005,6 @@ class PollsController < ApplicationController if @poll_users_list.present? && @poll_users_list.count > 0 - if order == "student_id" - @poll_users_list = @poll_users_list.joins(user: [:user_extension]).order("user_extensions.student_id DESC") - else - @poll_users_list = @poll_users_list.order("end_at DESC") - end #答题状态的选择 if choose_type.present? @@ -1028,6 +1023,12 @@ class PollsController < ApplicationController @poll_users_list = @poll_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{search_content}%", "%#{search_content}%") end + if order == "student_id" + @poll_users_list = @poll_users_list.joins(user: :user_extension).order("user_extensions.student_id DESC") + else + @poll_users_list = @poll_users_list.order("end_at DESC") + end + logger.info("#######F_______@poll_users_list_last___@users_ids________________####{@poll_users_list.pluck(:user_id)}") @poll_users_size = @poll_users_list.count From 925ff7fd09d2319b8d71032e2879e852c218467a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 15:21:10 +0800 Subject: [PATCH 0503/1015] fix bug --- app/controllers/polls_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index a7e039944..84af9b584 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -1025,7 +1025,7 @@ class PollsController < ApplicationController if order == "student_id" @poll_users_list = @poll_users_list.joins(user: :user_extension).order("user_extensions.student_id DESC") else - @poll_users_list = @poll_users_list.order("end_at DESC") + @poll_users_list = @poll_users_list.joins(user: :user_extension).order("end_at DESC") end logger.info("#######F_______@poll_users_list_last___@users_ids________________####{@poll_users_list.pluck(:user_id)}") From bf8e88c39396931b0c2cc9cfc012403ecde67ea6 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 2 Jul 2019 15:28:57 +0800 Subject: [PATCH 0504/1015] =?UTF-8?q?=E5=8F=82=E6=95=B0=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 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 65d671856..3a4592b2f 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -405,11 +405,7 @@ class ShixunsController < ApplicationController # 超级管理员和运营人员才能保存 中间层服务器pod信息的配置 if current_user.admin? || current_user.business? @shixun.shixun_service_configs.destroy_all - ActionController::Parameters.permit_all_parameters = true - logger.info("##--;;;;---#{params[:shixun_service_configs]}") - params[:shixun_service_configs].each do |config| - @shixun.shixun_service_configs.create!(config) - end + @shixun.shixun_service_configs.create!(service_config_params[:shixun_service_configs]) end rescue Exception => e uid_logger_error(e.message) @@ -745,6 +741,11 @@ private params.require(:shixun_info).permit(:description, :evaluate_script) end + + def service_config_params + params.permit(shixun_service_configs: [:cpu_limit, :lower_cpu_limit, :memory_limit, :request_limit, :mirror_repository_id]) + end + def find_shixun @shixun = Shixun.find_by_identifier(params[:identifier]) if @shixun.blank? From c22ec7dff21c85adf3d6f11fcbbeb35213f5b851 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 2 Jul 2019 16:10:38 +0800 Subject: [PATCH 0505/1015] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E7=AD=9B=E9=80=89?= =?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/models/repertoire.rb | 4 ++-- app/models/sub_repertoire.rb | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/repertoire.rb b/app/models/repertoire.rb index 400cef494..5c6ffebff 100644 --- a/app/models/repertoire.rb +++ b/app/models/repertoire.rb @@ -1,6 +1,6 @@ class Repertoire < ApplicationRecord - - has_many :sub_repertoires + default_scope :order => 'updated_at desc' + has_many :sub_repertoires, :dependent => :destroy, :order => "sub_repertoires.updated_at desc" has_many :tag_repertoires, through: :sub_repertoires end diff --git a/app/models/sub_repertoire.rb b/app/models/sub_repertoire.rb index d94db66c7..aa99494b1 100644 --- a/app/models/sub_repertoire.rb +++ b/app/models/sub_repertoire.rb @@ -1,3 +1,5 @@ class SubRepertoire < ApplicationRecord - has_many :tag_repertoires + belongs_to :repertoire + has_many :tag_repertoires, :dependent => :destroy, :order => "tag_repertoires.updated_at desc" + end From a53c20e02892d01ae72ffd514024ce879ed9a7f3 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 16:13:35 +0800 Subject: [PATCH 0506/1015] fix bug --- app/controllers/exercises_controller.rb | 31 +++++++++++-------- .../homework_commons_controller.rb | 4 +-- app/controllers/polls_controller.rb | 30 ++++++++++++------ app/helpers/export_helper.rb | 4 +-- app/views/polls/commit_result.xlsx.axlsx | 8 ++--- 5 files changed, 46 insertions(+), 31 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index a793c673c..18b8fbb2f 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1173,6 +1173,7 @@ class ExercisesController < ApplicationController ActiveRecord::Base.transaction do begin @current_user_id = current_user.id + @exercise = @exercise.includes(:exercise_questions) exercise_ids = [@exercise.id] @exercise_status = @exercise.get_exercise_status(current_user.id) @course_all_members = @course.students @@ -1254,14 +1255,6 @@ class ExercisesController < ApplicationController end end - if order == "student_id" - @exercise_users_list = @exercise_users_list.joins(user: [:user_extension]).order("user_extensions.student_id DESC") - elsif order == "score" - @exercise_users_list = @exercise_users_list.order("#{order} DESC") - else - @exercise_users_list = @exercise_users_list.order("end_at DESC, start_at DESC") - end - #答题状态的选择 if params[:commit_status].present? choose_type = params[:commit_status] @@ -1282,9 +1275,17 @@ class ExercisesController < ApplicationController @exercise_users_list = @exercise_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%") end + if order == "student_id" + @exercise_users_list = @exercise_users_list.joins(user: :user_extension).order("user_extensions.student_id DESC") + elsif order == "score" + @exercise_users_list = @exercise_users_list.joins(user: :user_extension).order("#{order} DESC") + else + @exercise_users_list = @exercise_users_list.order("end_at DESC, start_at DESC") + end + @export_ex_users = @exercise_users_list - @exercise_users_size = @exercise_users_list.count + @exercise_users_size = @exercise_users_list.size # 分页 @page = params[:page] || 1 @@ -1296,10 +1297,14 @@ class ExercisesController < ApplicationController if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") else - get_export_users(@exercise,@course,@export_ex_users) - exercise_export_name = - "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} + if @exercise_users_size.size > 0 + normal_status(-1,"暂无用户提交") + else + get_export_users(@exercise,@course,@export_ex_users) + exercise_export_name = + "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} + end end } end diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 2478633a1..dc4d6b117 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -186,7 +186,7 @@ class HomeworkCommonsController < ApplicationController end @work_count = @student_works.size - @work_excel = @student_works.includes(:student_works_scores) + @work_excel = @student_works.includes(:student_works_scores, user: :user_extension, myshixun: :games) @students = @course.students # 分页参数 @@ -207,7 +207,7 @@ class HomeworkCommonsController < ApplicationController tip_exception(403, "无权限操作") else if @work_excel.present? - @homework = @homework.includes() + @homework = @homework.includes(:shixuns,:homework_detail_manual) student_work_to_xlsx(@work_excel,@homework) exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 84af9b584..151a2a098 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -18,7 +18,7 @@ class PollsController < ApplicationController before_action :check_user_id_start_answer,only: [:start_answer] before_action :check_poll_question_complete,only: [:commit_poll] #问卷提交前来判断问题是否完成 before_action :check_poll_commit_result,only: [:commit_result] - before_action :get_all_polls_commit, only: [:commit_result] #该问卷全部的用户 + # before_action :get_all_polls_commit, only: [:commit_result] #该问卷全部的用户 before_action :get_left_banner_id, only:[:common_header,:start_answer,:new,:edit,:index] include PollsHelper @@ -920,19 +920,32 @@ class PollsController < ApplicationController def commit_result ActiveRecord::Base.transaction do begin + # @poll_questions = @poll.poll_questions.order("question_number ASC") + # 全部页面,需返回 + # @poll_questions_count = @poll_questions.size # 分页 + @poll = @poll.includes(:poll_users,user: :user_extension,) + @poll_users = @poll.poll_users + @poll_commit_ids = @poll_users.commit_by_status(1).pluck(:user_id) #问卷提交用户的id @page = params[:page] || 1 @limit = params[:limit] || 10 @poll_export_questions = @poll_questions.order("question_number ASC") + @poll_questions = @poll_questions.page(@page).per(@limit) respond_to do |format| format.json format.xlsx{ if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") + elsif @poll_export_questions.size == 0 || (@poll_users.where("commit_status = ?",1).size == 0) + normal_status(-1,"暂时没有提交的用户") else - polls_export_name = current_user.real_name + "_" + @course.name + "_" + @poll.polls_name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') - render xlsx: "#{polls_export_name.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: {poll_questions:@poll_export_questions} + polls_export_name = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + render xlsx: "#{polls_export_name.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: { + poll_questions:@poll_export_questions, + poll:@poll, + poll_users: @poll_users, + poll_commit_ids:@poll_commit_ids} end } end @@ -1028,15 +1041,12 @@ class PollsController < ApplicationController @poll_users_list = @poll_users_list.joins(user: :user_extension).order("end_at DESC") end - logger.info("#######F_______@poll_users_list_last___@users_ids________________####{@poll_users_list.pluck(:user_id)}") - @poll_users_size = @poll_users_list.count # 分页 page = params[:page] || 1 limit = params[:limit] || 20 @poll_users_list = @poll_users_list.page(page).per(limit) - logger.info("#####page_user: #{@poll_users_list.pluck(:id, :user_id)}") else @poll_users_list = [] @poll_users_size = 0 @@ -1146,10 +1156,10 @@ class PollsController < ApplicationController def get_questions_count @poll_questions = @poll.poll_questions&.includes(:poll_answers,:poll_votes).order("question_number ASC") - @poll_questions_count = @poll_questions.count # 全部的题目数 - @poll_question_singles = @poll_questions.ques_count(1).all.count # 单选题 - @poll_question_doubles = @poll_questions.ques_count(2).all.count # 多选题 - @poll_question_mains = @poll_questions.ques_count(3).all.count #主观题 + @poll_questions_count = @poll_questions.size # 全部的题目数 + @poll_question_singles = @poll_questions.ques_count(1).all.size # 单选题 + @poll_question_doubles = @poll_questions.ques_count(2).all.size # 多选题 + @poll_question_mains = @poll_questions.ques_count(3).all.size #主观题 end def check_poll_question_complete #commit_poll 的权限 diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index b6720c66c..211b31660 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -262,14 +262,14 @@ module ExportHelper end export_ex_users.each_with_index do |e_user,index| user_info = e_user.user - user_course_id = user_info.course_members.course_find_by_ids("course_id",course.id).first + user_course_id = user_info.course_members.course_find_by_ids("course_id",course.id)&.first if user_course_id.present? get_course_group_id = user_course_id.course_group_id if get_course_group_id.present? && get_course_group_id != 0 user_course_info = CourseGroup.by_group_ids(get_course_group_id) user_course = user_course_info.first.name else - user_course = "--" + user_course = "未分班" end else user_course = "--" diff --git a/app/views/polls/commit_result.xlsx.axlsx b/app/views/polls/commit_result.xlsx.axlsx index 3ea0571cb..6ce00388c 100644 --- a/app/views/polls/commit_result.xlsx.axlsx +++ b/app/views/polls/commit_result.xlsx.axlsx @@ -9,7 +9,7 @@ wb.styles do |s| sheet.sheet_view.show_grid_lines = false poll_users_info = %w(序号) poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?} - poll_un_anony = @poll.un_anonymous + poll_un_anony = poll.un_anonymous if poll_un_anony #是否匿名,默认为false user_info = %w(登陆名 真实姓名 邮箱 学号) else @@ -18,13 +18,13 @@ wb.styles do |s| poll_users_info = poll_users_info + user_info + poll_ques_titles poll_questions.each do |q| if q.question_type != 3 #问题不为主观题 - question_vote_user = q.poll_votes.find_current_vote("user_id",@poll_commit_ids).count #该问题的有效填写量 + question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids).count #该问题的有效填写量 sheet_row = ["第#{q.question_number}题"] #选择题答案选项的数组 sheet_answer_row = ["小计"] #选择题回答的答案人数,数组 sheet_answer_percent = ["比例"] sheet_answer_useful = ["有效填写人次",question_vote_user] q.poll_answers.each do |a| #问卷的答案选项 - answer_users_count = a.poll_votes.find_current_vote("user_id",@poll_commit_ids).count + answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids).count answer_percent = number_to_percentage((answer_users_count.to_f / question_vote_user.to_f)*100,precision:1) sheet_row.push(a.answer_text) sheet_answer_row.push(answer_users_count) @@ -49,7 +49,7 @@ wb.styles do |s| end #each_with_index sheet.add_row poll_users_info, :height =>15, :style => blue_cell - @poll.poll_users.each_with_index do |u,index| + poll_users.each_with_index do |u,index| u_user = u.user user_answer_array = [] poll_questions.each do |q| From ad092d91e1b1ad5feb9d7256f0b988b07958775b Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 2 Jul 2019 16:14:17 +0800 Subject: [PATCH 0507/1015] =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/repertoire.rb | 2 +- app/models/sub_repertoire.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/repertoire.rb b/app/models/repertoire.rb index 5c6ffebff..995d52d0b 100644 --- a/app/models/repertoire.rb +++ b/app/models/repertoire.rb @@ -1,6 +1,6 @@ class Repertoire < ApplicationRecord default_scope :order => 'updated_at desc' - has_many :sub_repertoires, :dependent => :destroy, :order => "sub_repertoires.updated_at desc" + has_many :sub_repertoires, ->{order("sub_repertoires.updated_at desc")}, :dependent => :destroy has_many :tag_repertoires, through: :sub_repertoires end diff --git a/app/models/sub_repertoire.rb b/app/models/sub_repertoire.rb index aa99494b1..9f7079cfc 100644 --- a/app/models/sub_repertoire.rb +++ b/app/models/sub_repertoire.rb @@ -1,5 +1,5 @@ class SubRepertoire < ApplicationRecord belongs_to :repertoire - has_many :tag_repertoires, :dependent => :destroy, :order => "tag_repertoires.updated_at desc" + has_many :tag_repertoires, ->{order("tag_repertoires.updated_at desc")} ,:dependent => :destroy end From 2ab15ddf5c4eaa2c3e0c8c3ccb29080b563d51eb Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 2 Jul 2019 16:16:16 +0800 Subject: [PATCH 0508/1015] =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/repertoire.rb | 2 +- app/models/sub_repertoire.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/repertoire.rb b/app/models/repertoire.rb index 995d52d0b..5c37eb3b6 100644 --- a/app/models/repertoire.rb +++ b/app/models/repertoire.rb @@ -1,6 +1,6 @@ class Repertoire < ApplicationRecord default_scope :order => 'updated_at desc' - has_many :sub_repertoires, ->{order("sub_repertoires.updated_at desc")}, :dependent => :destroy + has_many :sub_repertoires, ->{order(updated_at: :desc)}, :dependent => :destroy has_many :tag_repertoires, through: :sub_repertoires end diff --git a/app/models/sub_repertoire.rb b/app/models/sub_repertoire.rb index 9f7079cfc..d6a6c1b3d 100644 --- a/app/models/sub_repertoire.rb +++ b/app/models/sub_repertoire.rb @@ -1,5 +1,5 @@ class SubRepertoire < ApplicationRecord belongs_to :repertoire - has_many :tag_repertoires, ->{order("tag_repertoires.updated_at desc")} ,:dependent => :destroy + has_many :tag_repertoires, ->{order(updated_at: :desc)} ,:dependent => :destroy end From 91661cbee857109803c17d6a917a64c1f10d1f35 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 2 Jul 2019 16:18:08 +0800 Subject: [PATCH 0509/1015] =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/repertoire.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/models/repertoire.rb b/app/models/repertoire.rb index 5c37eb3b6..d76a022c5 100644 --- a/app/models/repertoire.rb +++ b/app/models/repertoire.rb @@ -1,5 +1,4 @@ class Repertoire < ApplicationRecord - default_scope :order => 'updated_at desc' has_many :sub_repertoires, ->{order(updated_at: :desc)}, :dependent => :destroy has_many :tag_repertoires, through: :sub_repertoires From 03797ce1fa82333ab085c58d0a0327425c6c973a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 16:51:27 +0800 Subject: [PATCH 0510/1015] ifx bug --- app/controllers/exercises_controller.rb | 4 ++-- app/controllers/polls_controller.rb | 2 +- app/controllers/zips_controller.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 18b8fbb2f..b3cf1f0be 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1173,7 +1173,7 @@ class ExercisesController < ApplicationController ActiveRecord::Base.transaction do begin @current_user_id = current_user.id - @exercise = @exercise.includes(:exercise_questions) + @exercise = @exercise exercise_ids = [@exercise.id] @exercise_status = @exercise.get_exercise_status(current_user.id) @course_all_members = @course.students @@ -1297,7 +1297,7 @@ class ExercisesController < ApplicationController if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") else - if @exercise_users_size.size > 0 + if @exercise_users_size == 0 normal_status(-1,"暂无用户提交") else get_export_users(@exercise,@course,@export_ex_users) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 151a2a098..eb03345e7 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -924,7 +924,7 @@ class PollsController < ApplicationController # 全部页面,需返回 # @poll_questions_count = @poll_questions.size # 分页 - @poll = @poll.includes(:poll_users,user: :user_extension,) + # @poll = @poll.includes(:poll_users,user: :user_extension) @poll_users = @poll.poll_users @poll_commit_ids = @poll_users.commit_by_status(1).pluck(:user_id) #问卷提交用户的id @page = params[:page] || 1 diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index c20546701..a70d4c332 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -62,7 +62,7 @@ class ZipsController < ApplicationController if default_ex_users_size == 0 normal_status(-1,"导出失败,暂时没有已提交的学生") elsif default_ex_users_size > 100 - normal_status(-1,"导出数量超过100,请分班导出或联系网站管理员导出") + normal_status(-2,"100") end end rescue Exception => e From df714555fcf1aead83378154a8d66031fef3cd6c Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 2 Jul 2019 17:07:23 +0800 Subject: [PATCH 0511/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E5=85=B3=E5=8D=A1?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=E7=9A=84model=E5=85=B3=E7=B3=BB=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/challenge_tag.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/challenge_tag.rb b/app/models/challenge_tag.rb index 6f176cc67..83b743adc 100644 --- a/app/models/challenge_tag.rb +++ b/app/models/challenge_tag.rb @@ -1,5 +1,5 @@ class ChallengeTag < ApplicationRecord belongs_to :challenge, counter_cache: true - belongs_to :challenge_choose + belongs_to :challenge_choose, optional: true end From 178a448f54d0bacd20f7cff301bcea605231985d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 2 Jul 2019 17:08:38 +0800 Subject: [PATCH 0512/1015] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E6=88=90=E7=BB=A9=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 72 +++++++++---------- .../graduation_tasks_controller.rb | 2 +- .../homework_commons_controller.rb | 2 +- app/helpers/export_helper.rb | 22 ++---- app/models/exercise.rb | 3 +- app/models/graduation_task.rb | 3 +- app/models/graduation_work.rb | 2 +- app/models/homework_common.rb | 3 +- app/models/poll.rb | 2 +- 9 files changed, 48 insertions(+), 63 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index cef2a1785..bae37d92a 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -969,22 +969,17 @@ class CoursesController < ApplicationController @all_members = @course.students end if name.present? - nick_name_search = @all_members.joins(:user).where("nickname like ?","%#{name}%") - if nick_name_search.present? - @all_members = nick_name_search - else - @all_members = @all_members.joins(user: [:user_extension]).where('user_extensions.student_id like ? OR user_extensions.student_realname like ?',"%#{name}%","%#{name}%") - end + @all_members = @all_members.joins(user: [:user_extension]).where('concat(users.lastname, users.firstname) like ? or user_extensions.student_id like ?',"%#{name}%","%#{name}%") end - @c_homeworks = @course.homework_commons.homework_published.order("publish_time asc, created_at asc") - @c_exercises = @course.exercises.is_exercise_published.order("publish_time asc, created_at asc") - @c_polls = @course.polls.publish_or_not.order("publish_time asc, created_at asc") - @c_tasks = @course.graduation_tasks.task_published.order("publish_time asc, created_at asc") + @c_homeworks = @course.homework_commons.homework_published.order("homework_commons.publish_time asc, homework_commons.created_at asc") + @c_exercises = @course.exercises.is_exercise_published.order("exercises.publish_time asc, exercises.created_at asc") + @c_polls = @course.polls.publish_or_not.order("polls.publish_time asc, polls.created_at asc") + @c_tasks = @course.graduation_tasks.task_published.order("graduation_tasks.publish_time asc, graduation_tasks.created_at asc") if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") else - member_to_xlsx(@course,@all_members,@c_homeworks,@c_exercises,@c_tasks,@c_polls) + member_to_xlsx(@course, @all_members, @c_homeworks, @c_exercises, @c_tasks, @c_polls) filename = current_user.real_name + "_" + @course.name + "_全部成绩" + Time.now.strftime('%Y%m%d_%H%M%S') render xlsx: "#{filename.strip.first(30)}",template: "courses/export_member_scores_excel.xlsx.axlsx", locals: {course_info:@course_info, activity_level:@user_activity_level, @@ -1058,14 +1053,14 @@ class CoursesController < ApplicationController def member_to_xlsx(course,all_members,homeworks,exercises,tasks,polls) #课堂的作业信息 - shixun_homeworks = homeworks.search_homework_type(4) #全部实训作业 + shixun_homeworks = homeworks.search_homework_type(4).includes(:score_student_works) #全部实训作业 shixun_titles = shixun_homeworks.pluck(:name) + ["总得分"] - common_homeworks = homeworks.search_homework_type(1) #全部普通作业 + common_homeworks = homeworks.search_homework_type(1).includes(:score_student_works) #全部普通作业 common_titles = common_homeworks.pluck(:name)+ ["总得分"] - group_homeworks = homeworks.search_homework_type(3) #全部分组作业 + group_homeworks = homeworks.search_homework_type(3).includes(:score_student_works) #全部分组作业 group_titles = group_homeworks.pluck(:name)+ ["总得分"] - task_titles = tasks.pluck(:name)+ ["总得分"] - exercise_titles = exercises.pluck(:exercise_name)+ ["总得分"] + task_titles = tasks.includes(:score_graduation_works).pluck(:name) + ["总得分"] + exercise_titles = exercises.includes(:score_exercise_users).pluck(:exercise_name) + ["总得分"] total_user_score_array = [] #学生总成绩集合 #课堂信息 @@ -1114,7 +1109,7 @@ class CoursesController < ApplicationController course_user_level = [] course_activity_title = "课堂活跃度统计" user_cell_head = %w(排名 真实姓名 登录名 邮箱 学号 分班 作业完成数(*10) 试卷完成数(*10) 问卷完成数(*7) 资源发布数(*5) 帖子发布数(*2) 帖子回复数(*1) 作业回复数(*1) 活跃度) - all_members.each do |u| + all_members.includes(user: :user_extension).each do |u| #用户的基本信息 user = u.user user_login = user.login @@ -1174,12 +1169,11 @@ class CoursesController < ApplicationController #实训作业 if shixun_homeworks.count > 0 shixun_homeworks.each do |s| - user_student_work = s.student_works.homework_by_user(user.id) #当前用户的对该作业的回答 - if user_student_work.blank? + user_student_work = s.score_student_works.find_by_user_id(user.id) #当前用户的对该作业的回答 + if user_student_work.nil? h_score = 0.0 #该作业的得分为0 else - user_stu_work = user_student_work.first - h_score = user_stu_work.work_score.nil? ? 0.0 : user_stu_work.work_score #用户对该作业的分数 + h_score = user_student_work.work_score.nil? ? 0.0 : user_student_work.work_score #用户对该作业的分数 end shixun_score_array.push(h_score) end @@ -1191,12 +1185,11 @@ class CoursesController < ApplicationController #普通作业 if common_homeworks.count > 0 common_homeworks.each do |c| - user_student_work_1 = c.student_works.homework_by_user(user.id) #当前用户的对该作业的回答 - if user_student_work_1.blank? + user_student_work_1 = c.score_student_works.find_by_user_id(user.id) #当前用户的对该作业的回答 + if user_student_work_1.nil? h_score_1 = 0.0 #该作业的得分为0 else - user_stu_work_1 = user_student_work_1.first - h_score_1 = user_stu_work_1.work_score.nil? ? 0.0 : user_stu_work_1.work_score #用户对该作业的分数 + h_score_1 = user_student_work_1.work_score.nil? ? 0.0 : user_student_work_1.work_score #用户对该作业的分数 end common_score_array.push(h_score_1) end @@ -1208,12 +1201,11 @@ class CoursesController < ApplicationController #分组作业 if group_homeworks.count > 0 group_homeworks.each do |g| - user_student_work_3 = g.student_works.homework_by_user(user.id) #当前用户的对该作业的回答 - if user_student_work_3.blank? + user_student_work_3 = g.score_student_works.find_by_user_id(user.id) #当前用户的对该作业的回答 + if user_student_work_3.nil? h_score_3 = 0.0 #该作业的得分为0 else - user_stu_work_3 = user_student_work_3.first - h_score_3 = user_stu_work_3.work_score.nil? ? 0.0 : user_stu_work_3.work_score #用户对该作业的分数 + h_score_3 = user_student_work_3.work_score.nil? ? 0.0 : user_student_work_3.work_score #用户对该作业的分数 end group_score_array.push(h_score_3) end @@ -1225,11 +1217,11 @@ class CoursesController < ApplicationController #毕设作业 if tasks.count > 0 tasks.each do |task| - graduation_works = task.graduation_works.find_by_task_user(user.id) - if graduation_works.empty? + graduation_work = task.score_graduation_works.find_by_user_id(user.id) + if graduation_work.nil? t_score = 0.0 else - t_score = graduation_works.first.work_score.nil? ? 0.0 : graduation_works.first.work_score + t_score = graduation_work.work_score.nil? ? 0.0 : graduation_work.work_score end task_score_array.push(t_score) end @@ -1241,11 +1233,11 @@ class CoursesController < ApplicationController #试卷 if exercises.count > 0 exercises.each do |ex| - exercise_works = ex.exercise_users.exercise_commit_users(user.id) - if exercise_works.empty? + exercise_work = ex.score_exercise_users.find_by_user_id(user.id) + if exercise_work.nil? e_score = 0.0 else - e_score = exercise_works.first.score.nil? ? 0.0 : exercise_works.first.score + e_score = exercise_work.score.nil? ? 0.0 : exercise_work.score end exercise_score_array.push(e_score) end @@ -1285,7 +1277,7 @@ class CoursesController < ApplicationController #实训作业 if count_1 > 0 shixun_homeworks.each_with_index do |s,index| - all_student_works = s.student_works.has_committed.order("work_score desc") #该实训题的全部用户回答 + all_student_works = s.score_student_works #该实训题的全部用户回答 title_no = index.to_i + 1 student_work_to_xlsx(all_student_works,s) shixun_work_display_name = (title_no.to_s + "." + s.name).strip.first(30) @@ -1297,7 +1289,7 @@ class CoursesController < ApplicationController #普通作业 if count_2 > 0 common_homeworks.each_with_index do |c,index| - all_student_works = c.student_works.has_committed.order("work_score desc") #当前用户的对该作业的回答 + all_student_works = c.score_student_works #当前用户的对该作业的回答 title_no = count_1 + index.to_i + 1 student_work_to_xlsx(all_student_works,c) @@ -1311,7 +1303,7 @@ class CoursesController < ApplicationController #分组作业 if count_3 > 0 group_homeworks.each_with_index do |c,index| - all_student_works = c.student_works.has_committed.order("work_score desc") #当前用户的对该作业的回答 + all_student_works = c.score_student_works #当前用户的对该作业的回答 title_no = count_1 + count_2 + index.to_i + 1 student_work_to_xlsx(all_student_works,c) work_name = (title_no.to_s + "." + c.name).strip.first(30) @@ -1323,7 +1315,7 @@ class CoursesController < ApplicationController #毕设任务 if count_4 > 0 tasks.each_with_index do |c,index| - all_student_works = c.graduation_works.has_committed.order("work_score desc") #当前用户的对该作业的回答 + all_student_works = c.score_graduation_works #当前用户的对该作业的回答 title_no = count_1 + count_2 + count_3 + index.to_i + 1 graduation_work_to_xlsx(all_student_works,c,current_user) work_name = (title_no.to_s + "." + c.name).strip.first(30) @@ -1336,7 +1328,7 @@ class CoursesController < ApplicationController #试卷的导出 if count_5 > 0 exercises.each_with_index do |c,index| - all_student_works = c.exercise_users.exercise_user_committed #当前用户的对该作业的回答 + all_student_works = c.score_exercise_users #当前用户的对该作业的回答 title_no = count_1 + count_2 + count_3 + count_4 + index.to_i + 1 get_export_users(c,course,all_student_works) work_name = (title_no.to_s + "." + c.exercise_name).strip.first(30) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 454f23c81..41ddb7659 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -145,7 +145,7 @@ class GraduationTasksController < ApplicationController file = decode64(zipfile[0][:base64file]) send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' else - tip_exception(status == -1 ? "文件大小超过500M,请通过微信或者QQ联系管理员辅助您打包下载" : "无附件可下载") + tip_exception(status == -2 ? "500" : "无附件可下载") end end } diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index af1dffe71..ca8d6364d 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -229,7 +229,7 @@ class HomeworkCommonsController < ApplicationController file = decode64(zipfile[0][:base64file]) send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' else - tip_exception(status == -1 ? "文件大小超过500M,请通过微信或者QQ联系管理员辅助您打包下载" : "无附件可下载") + tip_exception(status == -2 ? "500M" : "无附件可下载") end end } diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index b6720c66c..31fadc265 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -37,7 +37,7 @@ module ExportHelper end normal_head_b_cells = %w(最终成绩 提交时间 更新时间 评语) @work_head_cells = (head_cells_format + group_cells + normal_head_cells + head_cells_add + allow_late_cell + normal_head_b_cells).reject(&:blank?) - works.each_with_index do |w, index| + works.includes(student_works_scores: :user).each_with_index do |w, index| w_user = w.user w_1 = (index + 1) w_2 = w_user.login @@ -118,7 +118,7 @@ module ExportHelper end shixun_time_cells = %w(最终成绩 更新时间 提交耗时 评语) @work_head_cells = (head_cells_format + shixun_head_cells + eff_score_cell + shixun_time_cells).reject(&:blank?) - works.each_with_index do |w, index| + works.includes(:myshixun).each_with_index do |w, index| myshixun = w.try(:myshixun) w_user = w.user w_1 = (index + 1) @@ -262,18 +262,8 @@ module ExportHelper end export_ex_users.each_with_index do |e_user,index| user_info = e_user.user - user_course_id = user_info.course_members.course_find_by_ids("course_id",course.id).first - if user_course_id.present? - get_course_group_id = user_course_id.course_group_id - if get_course_group_id.present? && get_course_group_id != 0 - user_course_info = CourseGroup.by_group_ids(get_course_group_id) - user_course = user_course_info.first.name - else - user_course = "--" - end - else - user_course = "--" - end + member = course.students.find_by_user_id(e_user.user_id) + user_course = member.try(:course_group_name) user_obj_score = e_user.objective_score < 0.0 ? 0.0 : e_user.objective_score.round(1).to_s user_suj_score = e_user.subjective_score < 0.0 ? 0.0 : e_user.subjective_score.round(1).to_s user_score = e_user.score.present? ? e_user.score.round(1).to_s : 0.0 @@ -375,11 +365,11 @@ module ExportHelper end if file_size > MAX_DOWN_SIZE - status = -1 + status = -2 elsif file_count > 0 status = 0 else - status = -2 + status = -1 end status end diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 60409e51d..ed003286b 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -3,7 +3,8 @@ class Exercise < ApplicationRecord belongs_to :exercise_bank, optional: true belongs_to :user - has_many :exercise_users, :dependent => :delete_all + has_many :exercise_users, -> { where("is_delete = 0") }, :dependent => :delete_all + has_many :score_exercise_users, -> { where("is_delete = 0 and commit_status != 0").order("score desc") }, class_name: "ExerciseUser" has_many :exercise_questions, :dependent => :delete_all has_many :exercise_group_settings, :dependent => :delete_all has_many :tidings, as: :container diff --git a/app/models/graduation_task.rb b/app/models/graduation_task.rb index d85f9782d..030978817 100644 --- a/app/models/graduation_task.rb +++ b/app/models/graduation_task.rb @@ -16,7 +16,8 @@ class GraduationTask < ApplicationRecord has_many :graduation_task_group_assignations, dependent: :destroy has_many :graduation_work_comment_assignations, dependent: :destroy - has_many :graduation_works, -> { where("is_delete != 1") } + has_many :graduation_works, -> { where("is_delete = 0") } + has_many :score_graduation_works, -> { where("is_delete = 0 and work_status != 0").order("work_score desc") }, class_name: "GraduationWork" has_many :graduation_work_scores belongs_to :gtask_bank, optional: true diff --git a/app/models/graduation_work.rb b/app/models/graduation_work.rb index e9be0a43e..093e409a9 100644 --- a/app/models/graduation_work.rb +++ b/app/models/graduation_work.rb @@ -53,7 +53,7 @@ class GraduationWork < ApplicationRecord # 分班名 def class_grouping_name - CourseMember.find_by(user_id: self.user_id, course_id: self.course_id, role: 4).try(:course_group).try(:name) || '未分班' + CourseMember.find_by(course_id: self.course_id, user_id: self.user_id, role: 4).try(:course_group).try(:name) || '未分班' end # 分组名 diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 3e0bec5fe..193d9aa6c 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -3,7 +3,8 @@ class HomeworkCommon < ApplicationRecord enum homework_type: { normal: 1, program: 2, group: 3, practice: 4 }, _suffix: true has_many :homework_group_settings, dependent: :destroy has_many :published_settings, -> { group_published }, class_name: "HomeworkGroupSetting" - has_many :student_works, -> { where("is_delete != 1") } + has_many :student_works, -> { where("is_delete = 0") } + has_many :score_student_works, -> { where("is_delete = 0 and work_status != 0").order("work_score desc") }, class_name: "StudentWork" has_one :homework_detail_manual, dependent: :destroy # 分组作业的设置 diff --git a/app/models/poll.rb b/app/models/poll.rb index f72239ba7..1920dd939 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -5,7 +5,7 @@ class Poll < ApplicationRecord # belongs_to :exercise_bank has_many :poll_questions,dependent: :delete_all - has_many :poll_users, :dependent => :delete_all + has_many :poll_users, -> { where("is_delete != 1") }, :dependent => :delete_all has_many :users, :through => :poll_users #该文件被哪些用户提交答案过 has_many :poll_group_settings, :dependent => :delete_all has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :delete_all From 8f2be183f6885306961d41ff118198f6286458c6 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 17:11:46 +0800 Subject: [PATCH 0513/1015] fix bug --- app/controllers/exercises_controller.rb | 15 +++++++++------ app/controllers/polls_controller.rb | 13 +++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index b3cf1f0be..1d81ed4c2 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1173,7 +1173,7 @@ class ExercisesController < ApplicationController ActiveRecord::Base.transaction do begin @current_user_id = current_user.id - @exercise = @exercise + @exercise = @exercise.joins(:exercise_questions,:exercise_users) exercise_ids = [@exercise.id] @exercise_status = @exercise.get_exercise_status(current_user.id) @course_all_members = @course.students @@ -1271,16 +1271,17 @@ class ExercisesController < ApplicationController #搜索 if params[:search].present? - @exercise_users_list = @exercise_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%") end + exercise_user_joins = @exercise_users_list.joins(user: :user_extension) + if order == "student_id" - @exercise_users_list = @exercise_users_list.joins(user: :user_extension).order("user_extensions.student_id DESC") + @exercise_users_list = exercise_user_joins.order("user_extensions.student_id DESC") elsif order == "score" - @exercise_users_list = @exercise_users_list.joins(user: :user_extension).order("#{order} DESC") + @exercise_users_list = exercise_user_joins.order("#{order} DESC") else - @exercise_users_list = @exercise_users_list.order("end_at DESC, start_at DESC") + @exercise_users_list = exercise_user_joins.order("end_at DESC, start_at DESC") end @export_ex_users = @exercise_users_list @@ -1297,9 +1298,11 @@ class ExercisesController < ApplicationController if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") else - if @exercise_users_size == 0 + if @export_ex_users.exercise_user_committed.size == 0 normal_status(-1,"暂无用户提交") else + @exercise = @exercise.includes(:exercise_questions) + @export_ex_users = @export_ex_users.joins(user: :user_extension) get_export_users(@exercise,@course,@export_ex_users) exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index eb03345e7..44cdc6512 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -920,11 +920,6 @@ class PollsController < ApplicationController def commit_result ActiveRecord::Base.transaction do begin - # @poll_questions = @poll.poll_questions.order("question_number ASC") - # 全部页面,需返回 - # @poll_questions_count = @poll_questions.size - # 分页 - # @poll = @poll.includes(:poll_users,user: :user_extension) @poll_users = @poll.poll_users @poll_commit_ids = @poll_users.commit_by_status(1).pluck(:user_id) #问卷提交用户的id @page = params[:page] || 1 @@ -937,7 +932,7 @@ class PollsController < ApplicationController format.xlsx{ if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") - elsif @poll_export_questions.size == 0 || (@poll_users.where("commit_status = ?",1).size == 0) + elsif (@poll.polls_status == 1) || (@poll_export_questions.size == 0) || (@poll_commit_ids.size == 0) normal_status(-1,"暂时没有提交的用户") else polls_export_name = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" @@ -1035,10 +1030,12 @@ class PollsController < ApplicationController @poll_users_list = @poll_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{search_content}%", "%#{search_content}%") end + poll_users_joins = @poll_users_list.joins(user: :user_extension) + if order == "student_id" - @poll_users_list = @poll_users_list.joins(user: :user_extension).order("user_extensions.student_id DESC") + @poll_users_list = poll_users_joins.order("user_extensions.student_id DESC") else - @poll_users_list = @poll_users_list.joins(user: :user_extension).order("end_at DESC") + @poll_users_list = poll_users_joins.order("end_at DESC") end @poll_users_size = @poll_users_list.count From 35b91d96d896e57ee9d07e598fbefc8e1cdbf5f7 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 17:15:44 +0800 Subject: [PATCH 0514/1015] fix bug --- app/controllers/exercises_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 1d81ed4c2..d19de52c4 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1173,7 +1173,6 @@ class ExercisesController < ApplicationController ActiveRecord::Base.transaction do begin @current_user_id = current_user.id - @exercise = @exercise.joins(:exercise_questions,:exercise_users) exercise_ids = [@exercise.id] @exercise_status = @exercise.get_exercise_status(current_user.id) @course_all_members = @course.students @@ -1302,7 +1301,7 @@ class ExercisesController < ApplicationController normal_status(-1,"暂无用户提交") else @exercise = @exercise.includes(:exercise_questions) - @export_ex_users = @export_ex_users.joins(user: :user_extension) + @export_ex_users = @export_ex_users.includes(user: :user_extension) get_export_users(@exercise,@course,@export_ex_users) exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" From 7a9a78d918390aa84854347ecca19ec296fd70dc Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 2 Jul 2019 17:34:21 +0800 Subject: [PATCH 0515/1015] =?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/courses_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index bae37d92a..2d379b555 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1169,7 +1169,7 @@ class CoursesController < ApplicationController #实训作业 if shixun_homeworks.count > 0 shixun_homeworks.each do |s| - user_student_work = s.score_student_works.find_by_user_id(user.id) #当前用户的对该作业的回答 + user_student_work = s.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答 if user_student_work.nil? h_score = 0.0 #该作业的得分为0 else @@ -1185,7 +1185,7 @@ class CoursesController < ApplicationController #普通作业 if common_homeworks.count > 0 common_homeworks.each do |c| - user_student_work_1 = c.score_student_works.find_by_user_id(user.id) #当前用户的对该作业的回答 + user_student_work_1 = c.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答 if user_student_work_1.nil? h_score_1 = 0.0 #该作业的得分为0 else @@ -1201,7 +1201,7 @@ class CoursesController < ApplicationController #分组作业 if group_homeworks.count > 0 group_homeworks.each do |g| - user_student_work_3 = g.score_student_works.find_by_user_id(user.id) #当前用户的对该作业的回答 + user_student_work_3 = g.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答 if user_student_work_3.nil? h_score_3 = 0.0 #该作业的得分为0 else @@ -1217,7 +1217,7 @@ class CoursesController < ApplicationController #毕设作业 if tasks.count > 0 tasks.each do |task| - graduation_work = task.score_graduation_works.find_by_user_id(user.id) + graduation_work = task.score_graduation_works.select{|work| work.user_id == user.id}.first if graduation_work.nil? t_score = 0.0 else @@ -1233,7 +1233,7 @@ class CoursesController < ApplicationController #试卷 if exercises.count > 0 exercises.each do |ex| - exercise_work = ex.score_exercise_users.find_by_user_id(user.id) + exercise_work = ex.score_exercise_users.select{|work| work.user_id == user.id}.first if exercise_work.nil? e_score = 0.0 else From 254a643b4f8ab7eb2145726813c01bfdb4fbcd7b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 2 Jul 2019 18:10:08 +0800 Subject: [PATCH 0516/1015] fix bug --- app/controllers/exercises_controller.rb | 2 -- .../graduation_tasks_controller.rb | 10 ++++-- .../homework_commons_controller.rb | 3 +- app/controllers/zips_controller.rb | 19 +++++++--- .../batch_export_shixun_report_service.rb | 36 ++++++++++--------- 5 files changed, 43 insertions(+), 27 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index d19de52c4..79bed2d25 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1300,8 +1300,6 @@ class ExercisesController < ApplicationController if @export_ex_users.exercise_user_committed.size == 0 normal_status(-1,"暂无用户提交") else - @exercise = @exercise.includes(:exercise_questions) - @export_ex_users = @export_ex_users.includes(user: :user_extension) get_export_users(@exercise,@course,@export_ex_users) exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 41ddb7659..1931c26a0 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -129,9 +129,13 @@ class GraduationTasksController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") else - graduation_work_to_xlsx(@work_excel,@task,current_user) - exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @task.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_tasks/tasks_list.xlsx.axlsx",locals: {table_columns:@head_cells_column, task_users:@task_cells_column} + if @work_count > 1 + graduation_work_to_xlsx(@work_excel,@task,current_user) + exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@task.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_tasks/tasks_list.xlsx.axlsx",locals: {table_columns:@head_cells_column, task_users:@task_cells_column} + else + normal_status(-1,"暂无提交的学生!") + end end } format.zip{ diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index b3953c7dd..89e301f93 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -206,8 +206,7 @@ class HomeworkCommonsController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") else - if @work_excel.present? - @homework = @homework.includes(:shixuns,:homework_detail_manual) + if @work_count > 1 student_work_to_xlsx(@work_excel,@homework) exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index a70d4c332..e88f4d552 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -6,9 +6,11 @@ class ZipsController < ApplicationController before_action :require_admin_or_teacher def shixun_report - student_work_ids = Array.wrap(params[:student_work_ids]) + # student_work_ids = Array.wrap(params[:student_work_ids]) + + # service = BatchExportShixunReportService.new(@homework, @student_work_ids) + service = BatchExportShixunReportService.new(@homework, @all_student_works) - service = BatchExportShixunReportService.new(@homework, student_work_ids) filename = filename_for_content_disposition(service.filename) send_file service.zip, filename: filename, type: 'application/zip' @@ -57,9 +59,9 @@ class ZipsController < ApplicationController @ex_users = @ex_users.where(user_id: user_ids) end - default_ex_users_size = @ex_users.size + default_ex_users_size = @ex_users&.size - if default_ex_users_size == 0 + if default_ex_users_size.blank? || default_ex_users_size == 0 normal_status(-1,"导出失败,暂时没有已提交的学生") elsif default_ex_users_size > 100 normal_status(-2,"100") @@ -75,5 +77,14 @@ class ZipsController < ApplicationController def load_homework @homework = HomeworkCommon.find(params[:homework_common_id]) @course = @homework.course + ##7。2 -hs新增 + @member = @course.course_member(current_user.id) + @all_student_works = @homework.teacher_works(@member) + student_work_sizes = @all_student_works&.size + if student_work_sizes.blank? || student_work_sizes == 0 + normal_status(-1,"导出失败,暂时没有已提交的学生") + elsif student_work_sizes > 100 + normal_status(-2,"100") + end end end diff --git a/app/services/batch_export_shixun_report_service.rb b/app/services/batch_export_shixun_report_service.rb index 6ea38b23f..ebb273a87 100644 --- a/app/services/batch_export_shixun_report_service.rb +++ b/app/services/batch_export_shixun_report_service.rb @@ -3,11 +3,15 @@ class BatchExportShixunReportService MAX_BATCH_LIMIT = 20 - attr_reader :homework, :student_work_ids + # attr_reader :homework, :student_work_ids + attr_reader :homework, :all_student_works - def initialize(homework, student_work_ids) + + def initialize(homework, all_student_works) @homework = homework - @student_work_ids = student_work_ids + # @student_work_ids = student_work_ids + @all_student_works = all_student_works + end def filename @@ -15,8 +19,8 @@ class BatchExportShixunReportService end def zip - validate! - student_works = homework.student_works.where(id: student_work_ids).includes(:myshixun, user: :user_extension) + # validate! + student_works = all_student_works.includes(:myshixun, user: :user_extension) if student_works.count.zero? raise Error, '请选择要导出的学生实训报告' @@ -41,15 +45,15 @@ class BatchExportShixunReportService end end - private - - def validate! - if student_work_ids.size.zero? - raise Error, '请选择学生实训作业' - end - - if student_work_ids.size > MAX_BATCH_LIMIT - raise Error, '导出实训报告太多,请分批导出' - end - end + # private + # + # def validate! + # if student_work_ids.size.zero? + # raise Error, '请选择学生实训作业' + # end + # + # if student_work_ids.size > MAX_BATCH_LIMIT + # raise Error, '导出实训报告太多,请分批导出' + # end + # end end From 74e613e8045c063c235220e936b9a239c160ee2a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 09:21:08 +0800 Subject: [PATCH 0517/1015] =?UTF-8?q?pdf=E6=89=B9=E9=87=8F=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E5=A2=9E=E5=8A=A0=E7=AD=9B=E9=80=89=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/zips_controller.rb | 43 +++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index e88f4d552..984bef6d2 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -49,9 +49,26 @@ class ZipsController < ApplicationController normal_status(-1,"试卷不存在") else @course = @exercise.course - default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed @ex_users = default_ex_users #仅导出已提交的,截止后则是全部为提交的。 + + #是否评阅 + if params[:review].present? + review_type = params[:review].first.to_i #已评,则数据为1,未评,则数据为0,前端传过来的为数组 + if review_type == 1 + @ex_users = @ex_users.where("subjective_score >= ?",0.0) + else + @ex_users = @ex_users.where("subjective_score < ?",0.0) + end + end + + #答题状态的选择 + if params[:commit_status].present? && (params[:commit_status].to_i == 1) + @exercise_users_list = @exercise_users_list.where(commit_status:params[:commit_status]) + elsif params[:commit_status].present? && (params[:commit_status].to_i == 0) + normal_status(-1,"仅支持导出已提交的学生!") + end + #可以分班选择 if group_id.present? exercise_students = @course.students.where(course_group_id: group_id) # 试卷所分班的全部人数 @@ -59,6 +76,11 @@ class ZipsController < ApplicationController @ex_users = @ex_users.where(user_id: user_ids) end + #搜索 + if params[:search].present? + @ex_users = @ex_users.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%") + end + default_ex_users_size = @ex_users&.size if default_ex_users_size.blank? || default_ex_users_size == 0 @@ -80,6 +102,25 @@ class ZipsController < ApplicationController ##7。2 -hs新增 @member = @course.course_member(current_user.id) @all_student_works = @homework.teacher_works(@member) + work_status = params[:work_status] + group_id = params[:course_group] + + if work_status.present? && !work_status.include?(0) + @all_student_works = @all_student_works.where(work_status:work_status) + elsif work_status.present? && work_status.include?(0) + normal_status(-1,"仅支持导出已提交的学生!") + end + + if group_id.present? + group_user_ids = @course.students.where(course_group_id: params[:course_group]).pluck(:user_id) + @all_student_works = @all_student_works.where(user_id: group_user_ids) + end + + unless params[:search].blank? + @all_student_works = @all_student_works.joins(user: :user_extension).where("concat(lastname, firstname) like ? + or student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%") + end + student_work_sizes = @all_student_works&.size if student_work_sizes.blank? || student_work_sizes == 0 normal_status(-1,"导出失败,暂时没有已提交的学生") From dfe784a051c14398029a9aaae96ecfbd51471cae Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 09:38:22 +0800 Subject: [PATCH 0518/1015] fix bug --- app/controllers/exercises_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 79bed2d25..d8278faff 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1297,7 +1297,7 @@ class ExercisesController < ApplicationController if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") else - if @export_ex_users.exercise_user_committed.size == 0 + if (@exercise_users_size == 0) ||( @export_ex_users&.exercise_user_committed.size == 0) normal_status(-1,"暂无用户提交") else get_export_users(@exercise,@course,@export_ex_users) From 8768f4cb237abde1eda6f9e9221d8049f8e8e2ab Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 09:43:04 +0800 Subject: [PATCH 0519/1015] fix bug --- app/controllers/exercises_controller.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index d8278faff..72e075d31 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1291,13 +1291,15 @@ class ExercisesController < ApplicationController @page = params[:page] || 1 @limit = params[:limit] || 20 @exercise_users_list = @exercise_users_list.page(@page).per(@limit) + logger.info("#######___________@exercise_users_size_________##################{@exercise_users_size}") + logger.info("#######__________@export_ex_users&.exercise_user_committed.size_________##################{@export_ex_users&.exercise_user_committed.size}") respond_to do |format| format.json format.xlsx{ if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") else - if (@exercise_users_size == 0) ||( @export_ex_users&.exercise_user_committed.size == 0) + if (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) normal_status(-1,"暂无用户提交") else get_export_users(@exercise,@course,@export_ex_users) @@ -1316,9 +1318,6 @@ class ExercisesController < ApplicationController format.xlsx{ normal_status(-1,"暂无用户提交") } - format.zip{ - normal_status(-1,"暂无用户提交") - } end end From 09a2eca61846b1ef58154a3352a08d2d756557fb Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 3 Jul 2019 09:58:59 +0800 Subject: [PATCH 0520/1015] =?UTF-8?q?fork=E5=AE=9E=E8=AE=AD=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E5=A4=8D=E5=88=B6=E5=8F=82=E8=80=83=E7=AD=94=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 3a4592b2f..b91ce9580 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -203,6 +203,13 @@ class ShixunsController < ApplicationController new_challenge.user_id = User.current.id new_challenge.shixun_id = @new_shixun.id new_challenge.save! + # 同步参考答案 + challenge.challenge_answers.each do |answer| + new_answer = Challenge.new + new_answer = answer.attributes.dup.except("id","challenge_id") + new_answer.challenge_id = new_challenge.id + new_answer.save! + end if challenge.st == 0 # 评测题 # 同步测试集 if challenge.test_sets.present? From 14dc08892ce247719bbc6e3a200b93690b9f0740 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 10:14:16 +0800 Subject: [PATCH 0521/1015] =?UTF-8?q?=E9=AA=8C=E8=AF=81=20format.xlsx?= =?UTF-8?q?=E4=B8=8B=E7=9A=84render=20json=E6=98=AF=E5=90=A6=E6=9C=89?= =?UTF-8?q?=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 45 +++++++++++++++++-------- 1 file changed, 31 insertions(+), 14 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 72e075d31..a1db41d79 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1291,23 +1291,40 @@ class ExercisesController < ApplicationController @page = params[:page] || 1 @limit = params[:limit] || 20 @exercise_users_list = @exercise_users_list.page(@page).per(@limit) - logger.info("#######___________@exercise_users_size_________##################{@exercise_users_size}") - logger.info("#######__________@export_ex_users&.exercise_user_committed.size_________##################{@export_ex_users&.exercise_user_committed.size}") respond_to do |format| format.json + if @user_course_identity > Course::ASSISTANT_PROFESSOR + tip_exception(403,"无权限操作") + elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) + logger.info("#######___________@exercise_users_size_________##################{@exercise_users_size}") + logger.info("#######__________@export_ex_users&.exercise_user_committed.size_________##################{@export_ex_users&.exercise_user_committed.size}") + + + normal_status(-1,"暂无用户提交") + else + format.xlsx{ + get_export_users(@exercise,@course,@export_ex_users) + exercise_export_name = + "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} + } + end format.xlsx{ - if @user_course_identity > Course::ASSISTANT_PROFESSOR - tip_exception(403,"无权限操作") - else - if (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) - normal_status(-1,"暂无用户提交") - else - get_export_users(@exercise,@course,@export_ex_users) - exercise_export_name = - "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} - end - end + # if @user_course_identity > Course::ASSISTANT_PROFESSOR + # tip_exception(403,"无权限操作") + # else + # if (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) + # logger.info("#######__________@export_ex_users&.exercise_user_committed.size_________##################{@export_ex_users&.exercise_user_committed.size}") + # logger.info("#######___________@exercise_users_size_________##################{@exercise_users_size}") + # + # normal_status(-1,"暂无用户提交") + # else + # get_export_users(@exercise,@course,@export_ex_users) + # exercise_export_name = + # "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + # render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} + # end + # end } end else From d7649d04421ab02105d40d987072a75a2d46f254 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 10:16:18 +0800 Subject: [PATCH 0522/1015] fix bug --- app/controllers/exercises_controller.rb | 46 ++++++++----------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index a1db41d79..038d9a87c 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1293,38 +1293,22 @@ class ExercisesController < ApplicationController @exercise_users_list = @exercise_users_list.page(@page).per(@limit) respond_to do |format| format.json - if @user_course_identity > Course::ASSISTANT_PROFESSOR - tip_exception(403,"无权限操作") - elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) - logger.info("#######___________@exercise_users_size_________##################{@exercise_users_size}") - logger.info("#######__________@export_ex_users&.exercise_user_committed.size_________##################{@export_ex_users&.exercise_user_committed.size}") - - - normal_status(-1,"暂无用户提交") - else - format.xlsx{ - get_export_users(@exercise,@course,@export_ex_users) - exercise_export_name = - "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} - } - end format.xlsx{ - # if @user_course_identity > Course::ASSISTANT_PROFESSOR - # tip_exception(403,"无权限操作") - # else - # if (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) - # logger.info("#######__________@export_ex_users&.exercise_user_committed.size_________##################{@export_ex_users&.exercise_user_committed.size}") - # logger.info("#######___________@exercise_users_size_________##################{@exercise_users_size}") - # - # normal_status(-1,"暂无用户提交") - # else - # get_export_users(@exercise,@course,@export_ex_users) - # exercise_export_name = - # "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - # render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} - # end - # end + if @user_course_identity > Course::ASSISTANT_PROFESSOR + tip_exception(403,"无权限操作") + else + if (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) + logger.info("#######__________@export_ex_users&.exercise_user_committed.size_________##################{@export_ex_users&.exercise_user_committed.size}") + logger.info("#######___________@exercise_users_size_________##################{@exercise_users_size}") + + normal_status(-1,"暂无用户提交") + else + get_export_users(@exercise,@course,@export_ex_users) + exercise_export_name = + "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} + end + end } end else From 9fc9bf97e56bbbaf6d2fc4bda6e089c90c4fae44 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 10:23:43 +0800 Subject: [PATCH 0523/1015] fix bug --- app/controllers/exercises_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 038d9a87c..a10e5ad1b 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1291,6 +1291,7 @@ class ExercisesController < ApplicationController @page = params[:page] || 1 @limit = params[:limit] || 20 @exercise_users_list = @exercise_users_list.page(@page).per(@limit) + tip_exception(403,"无权限操作") respond_to do |format| format.json format.xlsx{ From 39f75a0dc75de9401453b8da6ab3b332ba8d92a4 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 10:30:46 +0800 Subject: [PATCH 0524/1015] fix bug --- app/controllers/exercises_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index a10e5ad1b..090386361 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1291,7 +1291,7 @@ class ExercisesController < ApplicationController @page = params[:page] || 1 @limit = params[:limit] || 20 @exercise_users_list = @exercise_users_list.page(@page).per(@limit) - tip_exception(403,"无权限操作") + logger.info("###########______________format.xlsx_______#######{format.xlsx}") respond_to do |format| format.json format.xlsx{ From ca4c84d6c2f6f6b425bf0e59f2cd2eb33133f5c9 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 10:35:09 +0800 Subject: [PATCH 0525/1015] fix bug --- app/controllers/exercises_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 090386361..a050e7eaa 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1291,7 +1291,10 @@ class ExercisesController < ApplicationController @page = params[:page] || 1 @limit = params[:limit] || 20 @exercise_users_list = @exercise_users_list.page(@page).per(@limit) - logger.info("###########______________format.xlsx_______#######{format.xlsx}") + if params[:format] == "xlsx" + logger.info("###########______________format.xlsx______111111111_#######") + + end respond_to do |format| format.json format.xlsx{ From 92006341b66a9a21e878982206b30a0108238eea Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 10:48:12 +0800 Subject: [PATCH 0526/1015] fix bug --- app/controllers/exercises_controller.rb | 56 ++++++++++++------------- app/controllers/polls_controller.rb | 42 ++++++++++++------- 2 files changed, 54 insertions(+), 44 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index a050e7eaa..2fcf45cda 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1291,39 +1291,37 @@ class ExercisesController < ApplicationController @page = params[:page] || 1 @limit = params[:limit] || 20 @exercise_users_list = @exercise_users_list.page(@page).per(@limit) - if params[:format] == "xlsx" - logger.info("###########______________format.xlsx______111111111_#######") - - end - respond_to do |format| - format.json - format.xlsx{ - if @user_course_identity > Course::ASSISTANT_PROFESSOR - tip_exception(403,"无权限操作") - else - if (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) - logger.info("#######__________@export_ex_users&.exercise_user_committed.size_________##################{@export_ex_users&.exercise_user_committed.size}") - logger.info("#######___________@exercise_users_size_________##################{@exercise_users_size}") - - normal_status(-1,"暂无用户提交") - else - get_export_users(@exercise,@course,@export_ex_users) - exercise_export_name = - "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} - end - end - } - end else @exercise_users_list = [] + @export_ex_users = @exercise_users_list @exercise_users_size = 0 - respond_to do |format| - format.json - format.xlsx{ - normal_status(-1,"暂无用户提交") - } + end + + if params[:format] == "xlsx" + if @user_course_identity > Course::ASSISTANT_PROFESSOR + tip_exception(403,"无权限操作") + elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) + normal_status(-1,"暂无用户提交") + else + respond_to do |format| + format.xlsx{ + get_export_users(@exercise,@course,@export_ex_users) + exercise_export_name = + "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} + } + end end + # else + # respond_to do |format| + # format.json + # format.xlsx{ + # get_export_users(@exercise,@course,@export_ex_users) + # exercise_export_name = + # "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + # render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} + # } + # end end rescue Exception => e diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 44cdc6512..7075ac0ef 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -927,23 +927,35 @@ class PollsController < ApplicationController @poll_export_questions = @poll_questions.order("question_number ASC") @poll_questions = @poll_questions.page(@page).per(@limit) - respond_to do |format| - format.json - format.xlsx{ - if @user_course_identity > Course::ASSISTANT_PROFESSOR - tip_exception(403,"无权限操作") - elsif (@poll.polls_status == 1) || (@poll_export_questions.size == 0) || (@poll_commit_ids.size == 0) - normal_status(-1,"暂时没有提交的用户") - else - polls_export_name = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - render xlsx: "#{polls_export_name.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: { - poll_questions:@poll_export_questions, - poll:@poll, - poll_users: @poll_users, - poll_commit_ids:@poll_commit_ids} + if params[:format] == "xlsx" + if @user_course_identity > Course::ASSISTANT_PROFESSOR + tip_exception(403,"无权限操作") + elsif (@poll.polls_status == 1) || (@poll_export_questions.size == 0) || (@poll_commit_ids.size == 0) + normal_status(-1,"暂无用户提交") + else + respond_to do |format| + format.xlsx{ + polls_export_name = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + render xlsx: "#{polls_export_name.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: { + poll_questions:@poll_export_questions, + poll:@poll, + poll_users: @poll_users, + poll_commit_ids:@poll_commit_ids} + } end - } + end end + # respond_to do |format| + # format.json + # format.xlsx{ + # polls_export_name = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + # render xlsx: "#{polls_export_name.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: { + # poll_questions:@poll_export_questions, + # poll:@poll, + # poll_users: @poll_users, + # poll_commit_ids:@poll_commit_ids} + # } + # end rescue Exception => e uid_logger_error(e.message) tip_exception("页面调用失败!") From e6f5a2b13a314ab4ec6625cd7ea19f545a0b38b8 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 10:58:24 +0800 Subject: [PATCH 0527/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84xlsx?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA=E7=9A=84=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 2fcf45cda..c5cf7390f 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1298,9 +1298,16 @@ class ExercisesController < ApplicationController end if params[:format] == "xlsx" + logger.info("#######___________params_xlsx____________##########") + logger.info("#######___________@exercise_users_size____________##########{@exercise_users_size}") + logger.info("#######___________@export_ex_users&.exercise_user_committed.size____________##########{@export_ex_users&.exercise_user_committed.size}") + + if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) + logger.info("#######___________@exercise_users_size == 0____________##########") + normal_status(-1,"暂无用户提交") else respond_to do |format| @@ -1312,18 +1319,7 @@ class ExercisesController < ApplicationController } end end - # else - # respond_to do |format| - # format.json - # format.xlsx{ - # get_export_users(@exercise,@course,@export_ex_users) - # exercise_export_name = - # "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - # render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} - # } - # end end - rescue Exception => e uid_logger_error(e.message) tip_exception("页面调用失败!") From 1b4103a54b1377da8dbd17d661b33681fff65f07 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 3 Jul 2019 11:00:29 +0800 Subject: [PATCH 0528/1015] =?UTF-8?q?copy=E5=8F=82=E8=80=83=E7=AD=94?= =?UTF-8?q?=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index b91ce9580..265398833 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -205,7 +205,7 @@ class ShixunsController < ApplicationController new_challenge.save! # 同步参考答案 challenge.challenge_answers.each do |answer| - new_answer = Challenge.new + new_answer = ChallengeAnswer.new new_answer = answer.attributes.dup.except("id","challenge_id") new_answer.challenge_id = new_challenge.id new_answer.save! From 04dc476b8854cd3f03178017f030e4c099c37296 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 3 Jul 2019 11:02:45 +0800 Subject: [PATCH 0529/1015] =?UTF-8?q?copy=E5=8F=82=E8=80=83=E7=AD=94?= =?UTF-8?q?=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 265398833..fdd55e6cf 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -206,7 +206,7 @@ class ShixunsController < ApplicationController # 同步参考答案 challenge.challenge_answers.each do |answer| new_answer = ChallengeAnswer.new - new_answer = answer.attributes.dup.except("id","challenge_id") + new_answer = new_answer.attributes.dup.except("id","challenge_id") new_answer.challenge_id = new_challenge.id new_answer.save! end From af4922ea72ac791332f2fea62e96bc243b25049c Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 3 Jul 2019 11:05:31 +0800 Subject: [PATCH 0530/1015] 1 --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index fdd55e6cf..265398833 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -206,7 +206,7 @@ class ShixunsController < ApplicationController # 同步参考答案 challenge.challenge_answers.each do |answer| new_answer = ChallengeAnswer.new - new_answer = new_answer.attributes.dup.except("id","challenge_id") + new_answer = answer.attributes.dup.except("id","challenge_id") new_answer.challenge_id = new_challenge.id new_answer.save! end From 35c3cc1e2937ac9d86e6653601676f8ecbac82b2 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 3 Jul 2019 11:07:29 +0800 Subject: [PATCH 0531/1015] =?UTF-8?q?copy=E5=AE=9E=E8=AE=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 265398833..5a1773a10 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -206,7 +206,7 @@ class ShixunsController < ApplicationController # 同步参考答案 challenge.challenge_answers.each do |answer| new_answer = ChallengeAnswer.new - new_answer = answer.attributes.dup.except("id","challenge_id") + new_answer.attributes = answer.attributes.dup.except("id","challenge_id") new_answer.challenge_id = new_challenge.id new_answer.save! end From 275030bb6a3221f7eaa91bb14231d1928713438a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 11:07:31 +0800 Subject: [PATCH 0532/1015] fix bug --- app/controllers/exercises_controller.rb | 27 ++++++++++--------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index c5cf7390f..dd19c36d1 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1298,28 +1298,23 @@ class ExercisesController < ApplicationController end if params[:format] == "xlsx" - logger.info("#######___________params_xlsx____________##########") - logger.info("#######___________@exercise_users_size____________##########{@exercise_users_size}") - logger.info("#######___________@export_ex_users&.exercise_user_committed.size____________##########{@export_ex_users&.exercise_user_committed.size}") - - if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) - logger.info("#######___________@exercise_users_size == 0____________##########") - normal_status(-1,"暂无用户提交") - else - respond_to do |format| - format.xlsx{ - get_export_users(@exercise,@course,@export_ex_users) - exercise_export_name = - "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} - } - end + end end + + respond_to do |format| + format.json + format.xlsx{ + get_export_users(@exercise,@course,@export_ex_users) + exercise_export_name = + "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} + } + end rescue Exception => e uid_logger_error(e.message) tip_exception("页面调用失败!") From cece1eee5f0b48a1964c4f1049c773d87a08037e Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 3 Jul 2019 11:08:36 +0800 Subject: [PATCH 0533/1015] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E6=88=90=E7=BB=A9?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 222 +++++++++++++++----------- app/helpers/export_helper.rb | 21 +-- app/models/myshixun.rb | 2 +- 3 files changed, 143 insertions(+), 102 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 2d379b555..26e70f471 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -959,18 +959,20 @@ class CoursesController < ApplicationController def export_member_scores_excel ActiveRecord::Base.transaction do begin - name = params[:name] ? "#{params[:name].strip}" : "" #用户名或学生学号id搜索 + search = params[:search] ? "#{params[:search].strip}" : "" #用户名或学生学号id搜索 group_id = params[:group_id] #分班的班级id - if group_id && group_id != "0" && group_id != "-1" - @all_members = @course.students.course_find_by_ids("course_group_id",group_id) - elsif group_id && group_id == "0" # 未分班 - @all_members = @course.course_members.ungroup_students - else - @all_members = @course.students - end - if name.present? - @all_members = @all_members.joins(user: [:user_extension]).where('concat(users.lastname, users.firstname) like ? or user_extensions.student_id like ?',"%#{name}%","%#{name}%") - end + # if group_id && group_id != "0" && group_id != "-1" + # @all_members = @course.students.course_find_by_ids("course_group_id",group_id) + # elsif group_id && group_id == "0" # 未分班 + # @all_members = @course.course_members.ungroup_students + # else + # @all_members = @course.students + # end + # if name.present? + # @all_members = @all_members.joins(user: [:user_extension]).where('concat(users.lastname, users.firstname) like ? or user_extensions.student_id like ?',"%#{name}%","%#{name}%") + # end + + @all_members = student_act_score group_id, search @c_homeworks = @course.homework_commons.homework_published.order("homework_commons.publish_time asc, homework_commons.created_at asc") @c_exercises = @course.exercises.is_exercise_published.order("exercises.publish_time asc, exercises.created_at asc") @@ -981,7 +983,7 @@ class CoursesController < ApplicationController else member_to_xlsx(@course, @all_members, @c_homeworks, @c_exercises, @c_tasks, @c_polls) filename = current_user.real_name + "_" + @course.name + "_全部成绩" + Time.now.strftime('%Y%m%d_%H%M%S') - render xlsx: "#{filename.strip.first(30)}",template: "courses/export_member_scores_excel.xlsx.axlsx", + render xlsx: "#{format_sheet_name filename.strip.first(30)}",template: "courses/export_member_scores_excel.xlsx.axlsx", locals: {course_info:@course_info, activity_level:@user_activity_level, course_scores:@course_user_scores,shixun_works:@shixun_work_arrays, common_works:@common_work_arrays,group_works:@group_work_arrays,task_works:@task_work_arrays, @@ -1051,16 +1053,68 @@ class CoursesController < ApplicationController end end - def member_to_xlsx(course,all_members,homeworks,exercises,tasks,polls) + def student_act_score group_id, search + sql_select = %Q{SELECT cm.*,( + SELECT SUM(student_works.work_score) + FROM student_works,homework_commons + WHERE student_works.homework_common_id = homework_commons.id + AND homework_commons.course_id = #{@course.id} + AND student_works.user_id = cm.user_id + ) AS score, + (SELECT SUM(gw.work_score) FROM graduation_works gw,graduation_tasks gt WHERE gw.graduation_task_id = gt.id + AND gt.course_id = #{@course.id} AND gw.user_id = cm.user_id) AS graduation_score, + (SELECT SUM(exercise_users.score) FROM exercise_users,exercises WHERE exercise_users.exercise_id = exercises.id + AND exercises.course_id = #{@course.id} AND exercise_users.user_id = cm.user_id) AS ex_score, + (SELECT max(student_id) FROM user_extensions WHERE user_extensions.user_id = cm.user_id) AS student_id, + (SELECT max(message_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS message_num, + (SELECT max(message_reply_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS message_reply_num, + (SELECT max(resource_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS resource_num, + (SELECT max(homework_journal_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS homework_journal_num, + (SELECT COUNT(gw.id) FROM graduation_works AS gw, graduation_tasks AS gt WHERE gw.graduation_task_id = gt.id AND gt.course_id = #{@course.id} AND gw.work_status != 0 AND gw.user_id = cm.user_id) AS graduation_num, + (SELECT COUNT(ss.id) FROM student_works AS ss ,homework_commons AS hc WHERE ss.homework_common_id = hc.id AND hc.course_id = #{@course.id} AND ss.work_status != 0 AND ss.user_id = cm.user_id) AS homework_num, + (SELECT COUNT(eu.id) FROM exercise_users AS eu,exercises WHERE eu.exercise_id = exercises.id AND exercises.course_id = #{@course.id} AND eu.commit_status = 1 AND eu.user_id = cm.user_id) AS exercise_num, + (SELECT COUNT(pu.id) FROM poll_users AS pu, polls WHERE pu.poll_id = polls.id AND polls.course_id = #{@course.id} AND pu.commit_status = 1 AND pu.user_id = cm.user_id) AS poll_num + FROM course_members cm} + if search.present? && group_id.present? + sql_select += %Q{ join users on cm.user_id = users.id + joins user_extensions ue on ue.user_id = users.id + WHERE cm.role = 4 and cm.course_id = #{@course.id} and cm.course_group_id = #{group_id} and + (concat(users.lastname, users.firstname) like '%#{search}%' or ue.student_id like '%#{search}%') ORDER BY score desc} + + elsif search.present? + ql_select += %Q{ join users on cm.user_id = users.id + joins user_extensions ue on ue.user_id = users.id + WHERE cm.role = 4 and + (concat(users.lastname, users.firstname) like '%#{search}%' or ue.student_id like '%#{search}%') ORDER BY score desc} + elsif group_id.present? + sql_select += %Q{ WHERE cm.role = 4 and cm.course_id = #{@course.id} and cm.course_group_id = #{group_id} ORDER BY score desc} + else + sql_select += %Q{ WHERE cm.role = 4 and cm.course_id = #{@course.id} ORDER BY score desc} + end + act_scores = CourseMember.find_by_sql(sql_select) + act_scores + end + + def member_to_xlsx(course,all_members,homeworks,exercises,tasks) #课堂的作业信息 - shixun_homeworks = homeworks.search_homework_type(4).includes(:score_student_works) #全部实训作业 + shixun_homeworks = homeworks.search_homework_type(4) #全部实训作业 shixun_titles = shixun_homeworks.pluck(:name) + ["总得分"] - common_homeworks = homeworks.search_homework_type(1).includes(:score_student_works) #全部普通作业 + shixun_homeworks = shixun_homeworks.includes(:score_student_works) + + common_homeworks = homeworks.search_homework_type(1) #全部普通作业 common_titles = common_homeworks.pluck(:name)+ ["总得分"] + common_homeworks = common_homeworks.includes(:score_student_works) + group_homeworks = homeworks.search_homework_type(3).includes(:score_student_works) #全部分组作业 group_titles = group_homeworks.pluck(:name)+ ["总得分"] - task_titles = tasks.includes(:score_graduation_works).pluck(:name) + ["总得分"] - exercise_titles = exercises.includes(:score_exercise_users).pluck(:exercise_name) + ["总得分"] + group_homeworks = group_homeworks.includes(:score_student_works) + + task_titles = tasks.pluck(:name) + ["总得分"] + tasks = tasks.includes(:score_graduation_works) + + exercise_titles = exercises.pluck(:exercise_name) + ["总得分"] + exercises = exercises.includes(:score_exercise_users) + total_user_score_array = [] #学生总成绩集合 #课堂信息 @@ -1075,7 +1129,7 @@ class CoursesController < ApplicationController course_teacher_member = course.course_members.course_user_role(%i[CREATOR]) course_teacher = course_teacher_member.present? ? course_teacher_member.first.user.real_name : "--" course_class_counts = course.course_groups_count - course_students_count = course.students.count + course_students_count = course.students.size course_1 = ["课堂编号",course_id] course_2 = ["课程名称",course_list_name] course_3 = ["课堂名称",course_name] @@ -1100,16 +1154,11 @@ class CoursesController < ApplicationController @course_info += [course_info_title,course_main_info,course_group_info] #课堂活跃度 - course_homework_ids = homeworks.pluck(:id) #该课堂的全部作业id - course_graduate_task_ids = tasks.pluck(:id) #该课堂的全部毕业任务id - course_exercise_ids = exercises.pluck(:id) #课堂的全部试卷数 - course_poll_ids = polls.pluck(:id) #课堂的全部问卷数 - course_board_ids = course.boards.pluck(:id) #课堂的全部讨论区 @user_activity_level = [] course_user_level = [] course_activity_title = "课堂活跃度统计" user_cell_head = %w(排名 真实姓名 登录名 邮箱 学号 分班 作业完成数(*10) 试卷完成数(*10) 问卷完成数(*7) 资源发布数(*5) 帖子发布数(*2) 帖子回复数(*1) 作业回复数(*1) 活跃度) - all_members.includes(user: :user_extension).each do |u| + all_members.each do |u| #用户的基本信息 user = u.user user_login = user.login @@ -1121,15 +1170,14 @@ class CoursesController < ApplicationController user_work_scores = [] #课堂活跃度统计 - user_homeworks_num = user.student_works.find_by_homework(course_homework_ids).has_committed.count #完成的作业数 - user_graduate_num = user.graduation_works.find_by_task(course_graduate_task_ids).has_committed.count #毕业任务完成数 - user_exercise_num = user.exercise_users.search_by_exercise(course_exercise_ids).commit_exercise_by_status(1).count #根据试卷的id来查找 - user_poll_num = user.poll_users.search_by_poll(course_poll_ids).commit_by_status(1).count #已完成问卷 - user_file_num = user.attachments.search_by_container(course.id).count - user_messages = user.messages - user_messages_num = user_messages.root_nodes.find_by_boards(course_board_ids).count #帖子发布数 - user_reply_num = user_messages.reply_nodes.find_by_boards(course_board_ids).count #帖子回复数 - user_work_reply_num = user.journals_for_messages.search_by_jour_type("HomeworkCommon",course_homework_ids).count #作业回复数的数量 + user_homeworks_num = u.homework_num.to_i #完成的作业数 + user_graduate_num = u.graduation_num.to_i #毕业任务完成数 + user_exercise_num = u.exercise_num.to_i #根据试卷的id来查找 + user_poll_num = u.poll_num.to_i #已完成问卷 + user_file_num = u.resource_num.to_i + user_messages_num = u.message_num.to_i #帖子发布数 + user_reply_num = u.message_reply_num.to_i #帖子回复数 + user_work_reply_num = u.homework_journal_num.to_i #作业回复数的数量 c_works_num = (user_homeworks_num + user_graduate_num)*10 c_exercise_num = user_exercise_num*10 c_poll_num = user_poll_num*7 @@ -1167,7 +1215,7 @@ class CoursesController < ApplicationController exercise_score_array = [] #实训作业 - if shixun_homeworks.count > 0 + if shixun_homeworks.size > 0 shixun_homeworks.each do |s| user_student_work = s.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答 if user_student_work.nil? @@ -1183,7 +1231,7 @@ class CoursesController < ApplicationController user_work_scores += user_info_array + shixun_score_array #单个用户的实训作业得分信息 #普通作业 - if common_homeworks.count > 0 + if common_homeworks.size > 0 common_homeworks.each do |c| user_student_work_1 = c.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答 if user_student_work_1.nil? @@ -1199,7 +1247,7 @@ class CoursesController < ApplicationController user_work_scores += common_score_array #单个用户的普通作业得分信息 #分组作业 - if group_homeworks.count > 0 + if group_homeworks.size > 0 group_homeworks.each do |g| user_student_work_3 = g.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答 if user_student_work_3.nil? @@ -1215,7 +1263,7 @@ class CoursesController < ApplicationController user_work_scores += group_score_array #单个用户的分组作业得分信息 #毕设作业 - if tasks.count > 0 + if tasks.size > 0 tasks.each do |task| graduation_work = task.score_graduation_works.select{|work| work.user_id == user.id}.first if graduation_work.nil? @@ -1231,7 +1279,7 @@ class CoursesController < ApplicationController user_work_scores += task_score_array #单个用户的分组作业得分信息 #试卷 - if exercises.count > 0 + if exercises.size > 0 exercises.each do |ex| exercise_work = ex.score_exercise_users.select{|work| work.user_id == user.id}.first if exercise_work.nil? @@ -1269,73 +1317,63 @@ class CoursesController < ApplicationController @common_work_arrays = [] @task_work_arrays = [] @exercise_work_arrays = [] - count_1 = shixun_homeworks.count - count_2 = common_homeworks.count - count_3 = group_homeworks.count - count_4 = tasks.count - count_5 = exercises.count + count_1 = shixun_homeworks.size + count_2 = common_homeworks.size + count_3 = group_homeworks.size + count_4 = tasks.size + count_5 = exercises.size #实训作业 - if count_1 > 0 - shixun_homeworks.each_with_index do |s,index| - all_student_works = s.score_student_works #该实训题的全部用户回答 - title_no = index.to_i + 1 - student_work_to_xlsx(all_student_works,s) - shixun_work_display_name = (title_no.to_s + "." + s.name).strip.first(30) - shixun_work_content = [shixun_work_display_name,@work_head_cells,@work_cells_column] - @shixun_work_arrays.push(shixun_work_content) - end + shixun_homeworks.each_with_index do |s,index| + all_student_works = s.score_student_works #该实训题的全部用户回答 + title_no = index.to_i + 1 + student_work_to_xlsx(all_student_works,s) + shixun_work_display_name = format_sheet_name (title_no.to_s + "." + s.name).strip.first(30) + shixun_work_content = [shixun_work_display_name,@work_head_cells,@work_cells_column] + @shixun_work_arrays.push(shixun_work_content) end #普通作业 - if count_2 > 0 - common_homeworks.each_with_index do |c,index| - all_student_works = c.score_student_works #当前用户的对该作业的回答 - title_no = count_1 + index.to_i + 1 - student_work_to_xlsx(all_student_works,c) - - work_name = (title_no.to_s + "." + c.name).strip.first(30) - work_content = [work_name,@work_head_cells,@work_cells_column] - @common_work_arrays.push(work_content) - title_no - end + common_homeworks.each_with_index do |c,index| + all_student_works = c.score_student_works #当前用户的对该作业的回答 + title_no = count_1 + index.to_i + 1 + student_work_to_xlsx(all_student_works,c) + + work_name = format_sheet_name (title_no.to_s + "." + c.name).strip.first(30) + work_content = [work_name,@work_head_cells,@work_cells_column] + @common_work_arrays.push(work_content) + title_no end #分组作业 - if count_3 > 0 - group_homeworks.each_with_index do |c,index| - all_student_works = c.score_student_works #当前用户的对该作业的回答 - title_no = count_1 + count_2 + index.to_i + 1 - student_work_to_xlsx(all_student_works,c) - work_name = (title_no.to_s + "." + c.name).strip.first(30) - work_content = [work_name,@work_head_cells,@work_cells_column] - @group_work_arrays.push(work_content) - end + group_homeworks.each_with_index do |c,index| + all_student_works = c.score_student_works #当前用户的对该作业的回答 + title_no = count_1 + count_2 + index.to_i + 1 + student_work_to_xlsx(all_student_works,c) + work_name = format_sheet_name (title_no.to_s + "." + c.name).strip.first(30) + work_content = [work_name,@work_head_cells,@work_cells_column] + @group_work_arrays.push(work_content) end #毕设任务 - if count_4 > 0 - tasks.each_with_index do |c,index| - all_student_works = c.score_graduation_works #当前用户的对该作业的回答 - title_no = count_1 + count_2 + count_3 + index.to_i + 1 - graduation_work_to_xlsx(all_student_works,c,current_user) - work_name = (title_no.to_s + "." + c.name).strip.first(30) - # work_content = [work_name,@work_head_cells,@work_cells_column] - work_content = [work_name,@head_cells_column,@task_cells_column] - @task_work_arrays.push(work_content) - end + tasks.each_with_index do |c,index| + all_student_works = c.score_graduation_works #当前用户的对该作业的回答 + title_no = count_1 + count_2 + count_3 + index.to_i + 1 + graduation_work_to_xlsx(all_student_works,c,current_user) + work_name = format_sheet_name (title_no.to_s + "." + c.name).strip.first(30) + # work_content = [work_name,@work_head_cells,@work_cells_column] + work_content = [work_name,@head_cells_column,@task_cells_column] + @task_work_arrays.push(work_content) end #试卷的导出 - if count_5 > 0 - exercises.each_with_index do |c,index| - all_student_works = c.score_exercise_users #当前用户的对该作业的回答 - title_no = count_1 + count_2 + count_3 + count_4 + index.to_i + 1 - get_export_users(c,course,all_student_works) - work_name = (title_no.to_s + "." + c.exercise_name).strip.first(30) - # work_content = [work_name,@work_head_cells,@work_cells_column] - work_content = [work_name,@table_columns,@user_columns] - @exercise_work_arrays.push(work_content) - end + exercises.each_with_index do |c,index| + all_student_works = c.score_exercise_users #当前用户的对该作业的回答 + title_no = count_1 + count_2 + count_3 + count_4 + index.to_i + 1 + get_export_users(c,course,all_student_works) + work_name = format_sheet_name (title_no.to_s + "." + c.exercise_name).strip.first(30) + # work_content = [work_name,@work_head_cells,@work_cells_column] + work_content = [work_name,@table_columns,@user_columns] + @exercise_work_arrays.push(work_content) end end end diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index 31fadc265..edb2b7e74 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -37,14 +37,14 @@ module ExportHelper end normal_head_b_cells = %w(最终成绩 提交时间 更新时间 评语) @work_head_cells = (head_cells_format + group_cells + normal_head_cells + head_cells_add + allow_late_cell + normal_head_b_cells).reject(&:blank?) - works.includes(student_works_scores: :user).each_with_index do |w, index| + works.includes(user: :user_extension, student_works_scores: :user).each_with_index do |w, index| w_user = w.user w_1 = (index + 1) w_2 = w_user.login w_3 = w_user.real_name w_3_1 = w_user.mail w_4 = w_user.student_id.present? ? w_user.student_id : "--" - course_name = course.course_member(w.user_id).try(:course_group_name) + course_name = course.students.find_by(user_id: w.user_id).try(:course_group_name) w_5 = course_name.present? ? course_name : "--" #0: 未提交, 1 按时提交, 2 延迟提交 if w.work_status == 0 @@ -118,7 +118,7 @@ module ExportHelper end shixun_time_cells = %w(最终成绩 更新时间 提交耗时 评语) @work_head_cells = (head_cells_format + shixun_head_cells + eff_score_cell + shixun_time_cells).reject(&:blank?) - works.includes(:myshixun).each_with_index do |w, index| + works.includes(:student_works_scores, user: :user_extension, myshixun: :games).each_with_index do |w, index| myshixun = w.try(:myshixun) w_user = w.user w_1 = (index + 1) @@ -126,7 +126,7 @@ module ExportHelper w_3 = w_user.real_name w_3_1 = w_user.mail w_4 = w_user.student_id.present? ? w_user.student_id : "--" - course_name = course.course_member(w.user_id).try(:course_group_name) + course_name = course.students.find_by(user_id: w.user_id).try(:course_group_name) w_5 = course_name.present? ? course_name : "--" #0: 未提交, 1 按时提交, 2 延迟提交 if w.work_status == 0 @@ -138,7 +138,7 @@ module ExportHelper else w_6 = "--" end - w_7 = w.work_status == 0 ? '--' : myshixun.try(:passed_count).to_s+"/"+shixun.challenges.count.to_s + w_7 = w.work_status == 0 ? '--' : myshixun.try(:passed_count).to_s+"/"+shixun.challenges_count.to_s w_8 = myshixun ? myshixun.try(:passed_time) == "--" ? "--" : format_time(myshixun.try(:passed_time)) : "--" # 通关时间 w_9 = myshixun ? (myshixun.try(:passed_count) > 0 ? myshixun.total_spend_time : '--') : "--" #总耗时 w_10 = myshixun ? myshixun.output_times : 0 #评测次数 @@ -204,7 +204,7 @@ module ExportHelper @head_cells_column = head_cells_format @task_cells_column = [] - items.each_with_index do |work,index| + items.includes(user: :user_extension).each_with_index do |work,index| w_1 = (index+1) w_user = work.user w_2 = w_user.login @@ -260,7 +260,7 @@ module ExportHelper else @table_columns = @table_columns + %w(最终成绩 开始答题时间 提交时间) end - export_ex_users.each_with_index do |e_user,index| + export_ex_users.includes(user: :user_extension).each_with_index do |e_user,index| user_info = e_user.user member = course.students.find_by_user_id(e_user.user_id) user_course = member.try(:course_group_name) @@ -295,7 +295,7 @@ module ExportHelper @topic_body_cells = [] if students.count > 0 - students.each_with_index do |student, index| + students.includes(user: :user_extension).each_with_index do |student, index| user = student.user student_topic = course.student_graduation_topics.user_topics_accept(user.id).first if student_topic.present? @@ -308,7 +308,7 @@ module ExportHelper w_2 = user.login w_3 = user.real_name w_3_1 = user.mail - w_4 = user.user_extension.student_id + w_4 = user.student_id w_5 = student.course_group_name w_6 = topic.present? ? topic.name : "--" w_7 = topic.present? ? topic.teacher.full_name : "--" @@ -504,4 +504,7 @@ module ExportHelper attach.filename end + def format_sheet_name name + name = name.gsub(":", "-") + end end diff --git a/app/models/myshixun.rb b/app/models/myshixun.rb index d8f294a39..31cc53200 100644 --- a/app/models/myshixun.rb +++ b/app/models/myshixun.rb @@ -18,7 +18,7 @@ class Myshixun < ApplicationRecord end def output_times - games.sum(:evaluate_count) + games.pluck(:evaluate_count).sum.to_i end def repo_path From ad7f287faccca9b38b35e7e2a2375b99feed5686 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 3 Jul 2019 11:10:14 +0800 Subject: [PATCH 0534/1015] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E6=88=90=E7=BB=A9?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 26e70f471..4e4d0284a 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -976,12 +976,12 @@ class CoursesController < ApplicationController @c_homeworks = @course.homework_commons.homework_published.order("homework_commons.publish_time asc, homework_commons.created_at asc") @c_exercises = @course.exercises.is_exercise_published.order("exercises.publish_time asc, exercises.created_at asc") - @c_polls = @course.polls.publish_or_not.order("polls.publish_time asc, polls.created_at asc") + # @c_polls = @course.polls.publish_or_not.order("polls.publish_time asc, polls.created_at asc") @c_tasks = @course.graduation_tasks.task_published.order("graduation_tasks.publish_time asc, graduation_tasks.created_at asc") if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") else - member_to_xlsx(@course, @all_members, @c_homeworks, @c_exercises, @c_tasks, @c_polls) + member_to_xlsx(@course, @all_members, @c_homeworks, @c_exercises, @c_tasks) filename = current_user.real_name + "_" + @course.name + "_全部成绩" + Time.now.strftime('%Y%m%d_%H%M%S') render xlsx: "#{format_sheet_name filename.strip.first(30)}",template: "courses/export_member_scores_excel.xlsx.axlsx", locals: {course_info:@course_info, activity_level:@user_activity_level, From a5c784c42383e97ad01e9217e29a86fffa3527e1 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Wed, 3 Jul 2019 11:13:31 +0800 Subject: [PATCH 0535/1015] fix account update --- app/forms/users/update_account_form.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/forms/users/update_account_form.rb b/app/forms/users/update_account_form.rb index 68e7fb7bf..d82459fcf 100644 --- a/app/forms/users/update_account_form.rb +++ b/app/forms/users/update_account_form.rb @@ -10,9 +10,9 @@ class Users::UpdateAccountForm validates :gender, presence: true, numericality: { only_integer: true }, inclusion: { in: [0, 1] } validates :location, presence: true validates :location_city, presence: true - validates :identity, presence: true, numericality: { only_integer: true }, inclusion: { in: [0, 1, 2] } - validates :technical_title, presence: true, unless: -> { identity == 1 } - validates :student_id, presence: true, if: -> { identity == 1 } + validates :identity, presence: true, inclusion: { in: %w[teacher student professional ] } + validates :technical_title, presence: true, unless: -> { identity.to_s == 'student' } + validates :student_id, presence: true, if: -> { identity.to_s == 'student' } validates :school_id, presence: true validate :check_school_exist From dd49b9e9adca84254a5fc552acb5a0920354fa8a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 11:26:16 +0800 Subject: [PATCH 0536/1015] =?UTF-8?q?=20xlsx=E5=AF=BC=E5=87=BA=E7=9A=84?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 2 + app/controllers/exercises_controller.rb | 22 ++-- .../graduation_tasks_controller.rb | 104 ++++++++++++------ .../homework_commons_controller.rb | 86 ++++++++++----- app/controllers/polls_controller.rb | 11 -- 5 files changed, 137 insertions(+), 88 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 2d379b555..6d1964840 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -978,6 +978,8 @@ class CoursesController < ApplicationController @c_tasks = @course.graduation_tasks.task_published.order("graduation_tasks.publish_time asc, graduation_tasks.created_at asc") if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") + elsif @all_members.size == 0 + normal_status(-1,"课堂暂时没有学生") else member_to_xlsx(@course, @all_members, @c_homeworks, @c_exercises, @c_tasks, @c_polls) filename = current_user.real_name + "_" + @course.name + "_全部成绩" + Time.now.strftime('%Y%m%d_%H%M%S') diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index dd19c36d1..07113792d 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1300,21 +1300,19 @@ class ExercisesController < ApplicationController if params[:format] == "xlsx" if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") - elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) + elsif (@exercise_status == 1) || (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) normal_status(-1,"暂无用户提交") - + else + respond_to do |format| + format.xlsx{ + get_export_users(@exercise,@course,@export_ex_users) + exercise_export_name = + "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} + } + end end end - - respond_to do |format| - format.json - format.xlsx{ - get_export_users(@exercise,@course,@export_ex_users) - exercise_export_name = - "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} - } - end rescue Exception => e uid_logger_error(e.message) tip_exception("页面调用失败!") diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 1931c26a0..23344e7fc 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -123,51 +123,83 @@ class GraduationTasksController < ApplicationController @work_count = @work_list.count @work_excel = @work_list @work_list = @work_list.page(page).per(limit) - respond_to do |format| - format.json - format.xlsx{ - if @user_course_identity >= Course::STUDENT - tip_exception(403, "无权限操作") - else - if @work_count > 1 - graduation_work_to_xlsx(@work_excel,@task,current_user) - exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@task.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_tasks/tasks_list.xlsx.axlsx",locals: {table_columns:@head_cells_column, task_users:@task_cells_column} - else - normal_status(-1,"暂无提交的学生!") - end - end - } - format.zip{ - if @user_course_identity >= Course::STUDENT - tip_exception(403, "无权限操作") + + if params[:format] == "xlsx" + if @user_course_identity >= Course::STUDENT + tip_exception(403, "无权限操作") + elsif @work_count == 0 + normal_status(-1,"暂无提交的学生!") + else + student_work_to_xlsx(@work_excel,@homework) + exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') + + render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: + {table_columns: @work_head_cells,task_users: @work_cells_column} + end + elsif params[:format] == "zip" + if @user_course_identity >= Course::STUDENT + tip_exception(403, "无权限操作") + else + zip_works = @work_excel.where("work_status > 0") + status = checkfileSize(zip_works) + if status == 0 + zipfile = zip_homework_common @homework, zip_works + file = decode64(zipfile[0][:base64file]) + send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' else - zip_works = @work_excel.where("work_status > 0") - status = checkfileSize(zip_works) - if status == 0 - zipfile = zip_homework_common @task, zip_works - file = decode64(zipfile[0][:base64file]) - send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' - else - tip_exception(status == -2 ? "500" : "无附件可下载") - end + tip_exception(status == -2 ? "500M" : "无附件可下载") end - } + end end + # + # respond_to do |format| + # format.json + # format.xlsx{ + # if @user_course_identity >= Course::STUDENT + # tip_exception(403, "无权限操作") + # else + # if @work_count > 1 + # graduation_work_to_xlsx(@work_excel,@task,current_user) + # exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@task.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + # render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_tasks/tasks_list.xlsx.axlsx",locals: {table_columns:@head_cells_column, task_users:@task_cells_column} + # else + # normal_status(-1,"暂无提交的学生!") + # end + # end + # } + # format.zip{ + # if @user_course_identity >= Course::STUDENT + # tip_exception(403, "无权限操作") + # else + # zip_works = @work_excel.where("work_status > 0") + # status = checkfileSize(zip_works) + # if status == 0 + # zipfile = zip_homework_common @task, zip_works + # file = decode64(zipfile[0][:base64file]) + # send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' + # else + # tip_exception(status == -2 ? "500" : "无附件可下载") + # end + # end + # } + # end else @work_list = @work @view_work = false @work_count = @work_list.count @all_work_count = @work_list.count - respond_to do |format| - format.json - format.xlsx{ - normal_status(-1,"作业未发布") - } - format.zip{ - normal_status(-1,"作业未发布") - } + if params[:format] == "xlsx" || params[:format] == "zip" + normal_status(-1,"作业未发布") end + # respond_to do |format| + # format.json + # format.xlsx{ + # normal_status(-1,"作业未发布") + # } + # format.zip{ + # normal_status(-1,"作业未发布") + # } + # end end end diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 89e301f93..5de65210f 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -200,40 +200,68 @@ class HomeworkCommonsController < ApplicationController end # @members = @course.students.where(user_id: @student_works.pluck(:user_id)).includes(:course_group) end - respond_to do |format| - format.json - format.xlsx{ - if @user_course_identity >= Course::STUDENT - tip_exception(403, "无权限操作") - else - if @work_count > 1 - student_work_to_xlsx(@work_excel,@homework) - exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: - {table_columns: @work_head_cells,task_users: @work_cells_column} - else - normal_status(-1,"暂无提交的学生!") - end + if params[:format] == "xlsx" + if @user_course_identity >= Course::STUDENT + tip_exception(403, "无权限操作") + elsif @work_count == 0 + normal_status(-1,"暂无提交的学生!") + else + student_work_to_xlsx(@work_excel,@homework) + exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') - end - } - format.zip{ - if @user_course_identity >= Course::STUDENT - tip_exception(403, "无权限操作") + render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: + {table_columns: @work_head_cells,task_users: @work_cells_column} + end + elsif params[:format] == "zip" + if @user_course_identity >= Course::STUDENT + tip_exception(403, "无权限操作") + else + zip_works = @work_excel.where("work_status > 0") + status = checkfileSize(zip_works) + if status == 0 + zipfile = zip_homework_common @homework, zip_works + file = decode64(zipfile[0][:base64file]) + send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' else - zip_works = @work_excel.where("work_status > 0") - status = checkfileSize(zip_works) - if status == 0 - zipfile = zip_homework_common @homework, zip_works - file = decode64(zipfile[0][:base64file]) - send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' - else - tip_exception(status == -2 ? "500M" : "无附件可下载") - end + tip_exception(status == -2 ? "500M" : "无附件可下载") end - } + end end + # respond_to do |format| + # format.json + # format.xlsx{ + # if @user_course_identity >= Course::STUDENT + # tip_exception(403, "无权限操作") + # else + # if @work_count > 1 + # student_work_to_xlsx(@work_excel,@homework) + # exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') + # + # render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: + # {table_columns: @work_head_cells,task_users: @work_cells_column} + # else + # normal_status(-1,"暂无提交的学生!") + # end + # + # end + # } + # format.zip{ + # if @user_course_identity >= Course::STUDENT + # tip_exception(403, "无权限操作") + # else + # zip_works = @work_excel.where("work_status > 0") + # status = checkfileSize(zip_works) + # if status == 0 + # zipfile = zip_homework_common @homework, zip_works + # file = decode64(zipfile[0][:base64file]) + # send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' + # else + # tip_exception(status == -2 ? "500M" : "无附件可下载") + # end + # end + # } + # end end end diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 7075ac0ef..244cdf57f 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -945,17 +945,6 @@ class PollsController < ApplicationController end end end - # respond_to do |format| - # format.json - # format.xlsx{ - # polls_export_name = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - # render xlsx: "#{polls_export_name.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: { - # poll_questions:@poll_export_questions, - # poll:@poll, - # poll_users: @poll_users, - # poll_commit_ids:@poll_commit_ids} - # } - # end rescue Exception => e uid_logger_error(e.message) tip_exception("页面调用失败!") From d80b7d924523c715ba0a3341a29d49096fa5dc46 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 3 Jul 2019 11:26:19 +0800 Subject: [PATCH 0537/1015] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E6=88=90=E7=BB=A9?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 4e4d0284a..5d8c1408f 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -991,7 +991,7 @@ class CoursesController < ApplicationController end rescue Exception => e uid_logger_error(e.message) - tip_exception("没有权限") + tip_exception(e.message) raise ActiveRecord::Rollback end end @@ -1061,15 +1061,11 @@ class CoursesController < ApplicationController AND homework_commons.course_id = #{@course.id} AND student_works.user_id = cm.user_id ) AS score, - (SELECT SUM(gw.work_score) FROM graduation_works gw,graduation_tasks gt WHERE gw.graduation_task_id = gt.id - AND gt.course_id = #{@course.id} AND gw.user_id = cm.user_id) AS graduation_score, - (SELECT SUM(exercise_users.score) FROM exercise_users,exercises WHERE exercise_users.exercise_id = exercises.id - AND exercises.course_id = #{@course.id} AND exercise_users.user_id = cm.user_id) AS ex_score, (SELECT max(student_id) FROM user_extensions WHERE user_extensions.user_id = cm.user_id) AS student_id, - (SELECT max(message_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS message_num, - (SELECT max(message_reply_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS message_reply_num, - (SELECT max(resource_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS resource_num, - (SELECT max(homework_journal_num) FROM course_contributor_scores AS ccs WHERE ccs.course_id = #{@course.id} AND ccs.user_id = cm.user_id) AS homework_journal_num, + (SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{@course.id} AND messages.author_id = cm.user_id and messages.parent_id is null) AS message_num, + (SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{@course.id} AND messages.author_id = cm.user_id and messages.parent_id is not null) AS message_reply_num, + (SELECT count(attachments.id) FROM attachments WHERE container_id = #{@course.id} and container_type = "Course" AND attachments.author_id = cm.user_id) AS resource_num, + (SELECT count(jfm.id) FROM journals_for_messages AS jfm, homework_commons hs WHERE jfm.jour_id = hs.id AND jfm.user_id = cm.user_id and jfm.jour_type = "HomeworkCommon" and hs.course_id = #{@course.id}) AS homework_journal_num, (SELECT COUNT(gw.id) FROM graduation_works AS gw, graduation_tasks AS gt WHERE gw.graduation_task_id = gt.id AND gt.course_id = #{@course.id} AND gw.work_status != 0 AND gw.user_id = cm.user_id) AS graduation_num, (SELECT COUNT(ss.id) FROM student_works AS ss ,homework_commons AS hc WHERE ss.homework_common_id = hc.id AND hc.course_id = #{@course.id} AND ss.work_status != 0 AND ss.user_id = cm.user_id) AS homework_num, (SELECT COUNT(eu.id) FROM exercise_users AS eu,exercises WHERE eu.exercise_id = exercises.id AND exercises.course_id = #{@course.id} AND eu.commit_status = 1 AND eu.user_id = cm.user_id) AS exercise_num, From 0a48259433bda039d08363c559f7f2eb5b46298e Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 3 Jul 2019 11:27:11 +0800 Subject: [PATCH 0538/1015] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E6=88=90=E7=BB=A9?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= 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 5d8c1408f..5c03dffee 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1160,7 +1160,7 @@ class CoursesController < ApplicationController user_login = user.login user_name = user.real_name user_mail = user.mail - user_stu_id = user.student_id.present? ? (user.student_id.to_s + "\t") : "--" + user_stu_id = u.student_id.present? ? (u.student_id.to_s + "\t") : "--" user_course_group = u.course_group_name user_info_array = [user_login,user_name,user_mail,user_stu_id,user_course_group] #用户的信息集合 user_work_scores = [] From 515b6aef09aa4433140305143ebb0700e7787266 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 12:15:30 +0800 Subject: [PATCH 0539/1015] fix bug --- app/controllers/homework_commons_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 5de65210f..6cffa866d 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -202,6 +202,7 @@ class HomeworkCommonsController < ApplicationController end if params[:format] == "xlsx" + logger.info("#########______@work_count_________#######{@work_count}") if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") elsif @work_count == 0 From 9e720b3d00ac61573eb97ab3987fbd7bcb3e639b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 12:24:09 +0800 Subject: [PATCH 0540/1015] fix bug --- .../graduation_tasks_controller.rb | 9 ++++---- .../graduation_topics_controller.rb | 2 +- .../homework_commons_controller.rb | 23 +++++++++++++------ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 23344e7fc..a518ac954 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -130,11 +130,10 @@ class GraduationTasksController < ApplicationController elsif @work_count == 0 normal_status(-1,"暂无提交的学生!") else - student_work_to_xlsx(@work_excel,@homework) - exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: - {table_columns: @work_head_cells,task_users: @work_cells_column} + graduation_work_to_xlsx(@work_excel,@task,current_user) + exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@task.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_tasks/tasks_list.xlsx.axlsx",locals: {table_columns:@head_cells_column, task_users:@task_cells_column} end elsif params[:format] == "zip" if @user_course_identity >= Course::STUDENT @@ -143,7 +142,7 @@ class GraduationTasksController < ApplicationController zip_works = @work_excel.where("work_status > 0") status = checkfileSize(zip_works) if status == 0 - zipfile = zip_homework_common @homework, zip_works + zipfile = zip_homework_common @task, zip_works file = decode64(zipfile[0][:base64file]) send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' else diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index c611069a8..2c9132520 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -269,7 +269,7 @@ class GraduationTopicsController < ApplicationController course = @course students = course.students.joins(user: :user_extension).order("user_extensions.student_id") graduation_topic_to_xlsx(students,course) - exercise_export_name = current_user.real_name + "_" + course.name + "_毕设选题" + "_" + Time.now.strftime('%Y%m%d_%H%M%S') + exercise_export_name = "#{current_user.real_name}_#{course.name}_毕设选题_#{Time.now.strftime('%Y%m%d_%H%M%S')}" render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_topics/export.xlsx.axlsx",locals: {table_columns:@topic_head_cells,topic_users:@topic_body_cells} end diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 6cffa866d..50ec4f7db 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -208,11 +208,16 @@ class HomeworkCommonsController < ApplicationController elsif @work_count == 0 normal_status(-1,"暂无提交的学生!") else - student_work_to_xlsx(@work_excel,@homework) - exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') + respond_to do |format| + format.xlsx{ + student_work_to_xlsx(@work_excel,@homework) + exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') + + render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: + {table_columns: @work_head_cells,task_users: @work_cells_column} + } + end - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: - {table_columns: @work_head_cells,task_users: @work_cells_column} end elsif params[:format] == "zip" if @user_course_identity >= Course::STUDENT @@ -221,9 +226,13 @@ class HomeworkCommonsController < ApplicationController zip_works = @work_excel.where("work_status > 0") status = checkfileSize(zip_works) if status == 0 - zipfile = zip_homework_common @homework, zip_works - file = decode64(zipfile[0][:base64file]) - send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' + respond_to do |format| + format.zip{ + zipfile = zip_homework_common @homework, zip_works + file = decode64(zipfile[0][:base64file]) + send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' + } + end else tip_exception(status == -2 ? "500M" : "无附件可下载") end From 44e4496928a1a8ae9a7fcc4c363070d8f60428fb Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 12:56:43 +0800 Subject: [PATCH 0541/1015] =?UTF-8?q?xlsx=E5=AF=BC=E5=87=BA=E7=9A=84?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E5=88=A4=E6=96=AD=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../graduation_tasks_controller.rb | 65 +++++-------------- .../graduation_topics_controller.rb | 15 +++-- .../homework_commons_controller.rb | 49 ++------------ app/helpers/export_helper.rb | 11 +++- 4 files changed, 40 insertions(+), 100 deletions(-) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index a518ac954..aebd8b092 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -125,15 +125,19 @@ class GraduationTasksController < ApplicationController @work_list = @work_list.page(page).per(limit) if params[:format] == "xlsx" + complete_works = @work_excel.where("work_status > 0").size if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") - elsif @work_count == 0 + elsif complete_works == 0 normal_status(-1,"暂无提交的学生!") else - - graduation_work_to_xlsx(@work_excel,@task,current_user) - exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@task.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_tasks/tasks_list.xlsx.axlsx",locals: {table_columns:@head_cells_column, task_users:@task_cells_column} + respond_to do |format| + format.xlsx{ + graduation_work_to_xlsx(@work_excel,@task,current_user) + exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@task.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_tasks/tasks_list.xlsx.axlsx",locals: {table_columns:@head_cells_column, task_users:@task_cells_column} + } + end end elsif params[:format] == "zip" if @user_course_identity >= Course::STUDENT @@ -142,46 +146,18 @@ class GraduationTasksController < ApplicationController zip_works = @work_excel.where("work_status > 0") status = checkfileSize(zip_works) if status == 0 - zipfile = zip_homework_common @task, zip_works - file = decode64(zipfile[0][:base64file]) - send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' + respond_to do |format| + format.zip{ + zipfile = zip_homework_common @task, zip_works + file = decode64(zipfile[0][:base64file]) + send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' + } + end else tip_exception(status == -2 ? "500M" : "无附件可下载") end end end - # - # respond_to do |format| - # format.json - # format.xlsx{ - # if @user_course_identity >= Course::STUDENT - # tip_exception(403, "无权限操作") - # else - # if @work_count > 1 - # graduation_work_to_xlsx(@work_excel,@task,current_user) - # exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@task.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - # render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_tasks/tasks_list.xlsx.axlsx",locals: {table_columns:@head_cells_column, task_users:@task_cells_column} - # else - # normal_status(-1,"暂无提交的学生!") - # end - # end - # } - # format.zip{ - # if @user_course_identity >= Course::STUDENT - # tip_exception(403, "无权限操作") - # else - # zip_works = @work_excel.where("work_status > 0") - # status = checkfileSize(zip_works) - # if status == 0 - # zipfile = zip_homework_common @task, zip_works - # file = decode64(zipfile[0][:base64file]) - # send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' - # else - # tip_exception(status == -2 ? "500" : "无附件可下载") - # end - # end - # } - # end else @work_list = @work @view_work = false @@ -190,15 +166,6 @@ class GraduationTasksController < ApplicationController if params[:format] == "xlsx" || params[:format] == "zip" normal_status(-1,"作业未发布") end - # respond_to do |format| - # format.json - # format.xlsx{ - # normal_status(-1,"作业未发布") - # } - # format.zip{ - # normal_status(-1,"作业未发布") - # } - # end end end diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index 2c9132520..b20b767a4 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -266,11 +266,16 @@ class GraduationTopicsController < ApplicationController # 导出功能 def export - course = @course - students = course.students.joins(user: :user_extension).order("user_extensions.student_id") - graduation_topic_to_xlsx(students,course) - exercise_export_name = "#{current_user.real_name}_#{course.name}_毕设选题_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_topics/export.xlsx.axlsx",locals: {table_columns:@topic_head_cells,topic_users:@topic_body_cells} + begin + course = @course + students = course.students.joins(user: :user_extension).order("user_extensions.student_id") + graduation_topic_to_xlsx(students,course) + exercise_export_name = "#{current_user.real_name}_#{course.name}_毕设选题_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_topics/export.xlsx.axlsx",locals: {table_columns:@topic_head_cells,topic_users:@topic_body_cells} + rescue Exception => e + uid_logger(e.message) + missing_template + end end private diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 50ec4f7db..2d52b6aa0 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -108,14 +108,8 @@ class HomeworkCommonsController < ApplicationController @all_member_count = student_works.size if @homework.publish_time.nil? || @homework.publish_time > Time.now @student_works = [] - respond_to do |format| - format.json - format.xlsx{ - normal_status(-1,"作业未发布") - } - format.zip{ - normal_status(-1,"作业未发布") - } + if params[:format] == "xlsx" || params[:format] == "zip" + normal_status(-1,"作业未发布") end else if @user_course_identity == Course::STUDENT @@ -202,10 +196,10 @@ class HomeworkCommonsController < ApplicationController end if params[:format] == "xlsx" - logger.info("#########______@work_count_________#######{@work_count}") + complete_works = @work_excel.where("work_status > 0").size if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") - elsif @work_count == 0 + elsif complete_works == 0 normal_status(-1,"暂无提交的学生!") else respond_to do |format| @@ -217,7 +211,6 @@ class HomeworkCommonsController < ApplicationController {table_columns: @work_head_cells,task_users: @work_cells_column} } end - end elsif params[:format] == "zip" if @user_course_identity >= Course::STUDENT @@ -238,40 +231,6 @@ class HomeworkCommonsController < ApplicationController end end end - # respond_to do |format| - # format.json - # format.xlsx{ - # if @user_course_identity >= Course::STUDENT - # tip_exception(403, "无权限操作") - # else - # if @work_count > 1 - # student_work_to_xlsx(@work_excel,@homework) - # exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') - # - # render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: - # {table_columns: @work_head_cells,task_users: @work_cells_column} - # else - # normal_status(-1,"暂无提交的学生!") - # end - # - # end - # } - # format.zip{ - # if @user_course_identity >= Course::STUDENT - # tip_exception(403, "无权限操作") - # else - # zip_works = @work_excel.where("work_status > 0") - # status = checkfileSize(zip_works) - # if status == 0 - # zipfile = zip_homework_common @homework, zip_works - # file = decode64(zipfile[0][:base64file]) - # send_file "#{OUTPUT_FOLDER}/#{file}", filename: filename_for_content_disposition(file), type: 'application/zip' - # else - # tip_exception(status == -2 ? "500M" : "无附件可下载") - # end - # end - # } - # end end end diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index edb2b7e74..a23cb8a65 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -217,7 +217,16 @@ module ExportHelper else w_6 = nil end - w_7 = work.work_status + w_status = work.work_status.to_i + if w_status == 0 + w_7 = "未提交" + elsif w_status == 1 + w_7 = "按时提交" + elsif w_status == 2 + w_7 = "延时提交" + else + w_7 = "--" + end if task_project_boolean #关联项目 w_project = project_info work, current_user, @user_course_identity #因为课堂引用了export_helper w_8 = w_project[:name] From af2f6ae95e4581c1aeebfc76055911fb1c23ea28 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 13:46:52 +0800 Subject: [PATCH 0542/1015] fix bug --- app/controllers/zips_controller.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 984bef6d2..3b9fa7c02 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -101,14 +101,12 @@ class ZipsController < ApplicationController @course = @homework.course ##7。2 -hs新增 @member = @course.course_member(current_user.id) - @all_student_works = @homework.teacher_works(@member) + @all_student_works = @homework.teacher_works(@member).where("work_status > 0") work_status = params[:work_status] group_id = params[:course_group] - if work_status.present? && !work_status.include?(0) + if work_status.present? @all_student_works = @all_student_works.where(work_status:work_status) - elsif work_status.present? && work_status.include?(0) - normal_status(-1,"仅支持导出已提交的学生!") end if group_id.present? From d3927146dcb2b2a227971d00a306ee903d6759df Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 3 Jul 2019 14:20:35 +0800 Subject: [PATCH 0543/1015] =?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/courses_controller.rb | 30 +++++++++++++++++---------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 5c03dffee..fbc1c04cf 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1062,14 +1062,22 @@ class CoursesController < ApplicationController AND student_works.user_id = cm.user_id ) AS score, (SELECT max(student_id) FROM user_extensions WHERE user_extensions.user_id = cm.user_id) AS student_id, - (SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{@course.id} AND messages.author_id = cm.user_id and messages.parent_id is null) AS message_num, - (SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{@course.id} AND messages.author_id = cm.user_id and messages.parent_id is not null) AS message_reply_num, - (SELECT count(attachments.id) FROM attachments WHERE container_id = #{@course.id} and container_type = "Course" AND attachments.author_id = cm.user_id) AS resource_num, - (SELECT count(jfm.id) FROM journals_for_messages AS jfm, homework_commons hs WHERE jfm.jour_id = hs.id AND jfm.user_id = cm.user_id and jfm.jour_type = "HomeworkCommon" and hs.course_id = #{@course.id}) AS homework_journal_num, - (SELECT COUNT(gw.id) FROM graduation_works AS gw, graduation_tasks AS gt WHERE gw.graduation_task_id = gt.id AND gt.course_id = #{@course.id} AND gw.work_status != 0 AND gw.user_id = cm.user_id) AS graduation_num, - (SELECT COUNT(ss.id) FROM student_works AS ss ,homework_commons AS hc WHERE ss.homework_common_id = hc.id AND hc.course_id = #{@course.id} AND ss.work_status != 0 AND ss.user_id = cm.user_id) AS homework_num, - (SELECT COUNT(eu.id) FROM exercise_users AS eu,exercises WHERE eu.exercise_id = exercises.id AND exercises.course_id = #{@course.id} AND eu.commit_status = 1 AND eu.user_id = cm.user_id) AS exercise_num, - (SELECT COUNT(pu.id) FROM poll_users AS pu, polls WHERE pu.poll_id = polls.id AND polls.course_id = #{@course.id} AND pu.commit_status = 1 AND pu.user_id = cm.user_id) AS poll_num + (SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{@course.id} + AND messages.author_id = cm.user_id and messages.parent_id is null) AS message_num, + (SELECT count(messages.id) FROM messages join boards on messages.board_id = boards.id WHERE boards.course_id = #{@course.id} + AND messages.author_id = cm.user_id and messages.parent_id is not null) AS message_reply_num, + (SELECT count(attachments.id) FROM attachments WHERE container_id = #{@course.id} and container_type = "Course" + AND attachments.author_id = cm.user_id) AS resource_num, + (SELECT count(jfm.id) FROM journals_for_messages AS jfm, homework_commons hs WHERE jfm.jour_id = hs.id AND + jfm.user_id = cm.user_id and jfm.jour_type = "HomeworkCommon" and hs.course_id = #{@course.id}) AS homework_journal_num, + (SELECT COUNT(gw.id) FROM graduation_works AS gw, graduation_tasks AS gt WHERE gw.graduation_task_id = gt.id AND + gt.course_id = #{@course.id} AND gw.work_status != 0 AND gw.user_id = cm.user_id) AS graduation_num, + (SELECT COUNT(ss.id) FROM student_works AS ss ,homework_commons AS hc WHERE ss.homework_common_id = hc.id AND + hc.course_id = #{@course.id} AND ss.work_status != 0 AND ss.user_id = cm.user_id) AS homework_num, + (SELECT COUNT(eu.id) FROM exercise_users AS eu,exercises WHERE eu.exercise_id = exercises.id AND exercises.course_id = #{@course.id} + AND eu.commit_status = 1 AND eu.user_id = cm.user_id) AS exercise_num, + (SELECT COUNT(pu.id) FROM poll_users AS pu, polls WHERE pu.poll_id = polls.id AND polls.course_id = #{@course.id} + AND pu.commit_status = 1 AND pu.user_id = cm.user_id) AS poll_num FROM course_members cm} if search.present? && group_id.present? sql_select += %Q{ join users on cm.user_id = users.id @@ -1078,7 +1086,7 @@ class CoursesController < ApplicationController (concat(users.lastname, users.firstname) like '%#{search}%' or ue.student_id like '%#{search}%') ORDER BY score desc} elsif search.present? - ql_select += %Q{ join users on cm.user_id = users.id + sql_select += %Q{ join users on cm.user_id = users.id joins user_extensions ue on ue.user_id = users.id WHERE cm.role = 4 and (concat(users.lastname, users.firstname) like '%#{search}%' or ue.student_id like '%#{search}%') ORDER BY score desc} @@ -1101,7 +1109,7 @@ class CoursesController < ApplicationController common_titles = common_homeworks.pluck(:name)+ ["总得分"] common_homeworks = common_homeworks.includes(:score_student_works) - group_homeworks = homeworks.search_homework_type(3).includes(:score_student_works) #全部分组作业 + group_homeworks = homeworks.search_homework_type(3) #全部分组作业 group_titles = group_homeworks.pluck(:name)+ ["总得分"] group_homeworks = group_homeworks.includes(:score_student_works) @@ -1179,7 +1187,7 @@ class CoursesController < ApplicationController c_poll_num = user_poll_num*7 c_file_num = user_file_num*5 c_message_num = user_messages_num*2 - c_reply_num = user_reply_num*2 + c_reply_num = user_reply_num user_activity_levels = c_works_num + c_exercise_num + c_poll_num + c_file_num + c_message_num + c_reply_num + user_work_reply_num user_ac_level = { u_1: user_name, From 19ef46f0778775dd80ea25812209b4b8c056f20d Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 14:21:53 +0800 Subject: [PATCH 0544/1015] fix bug --- app/controllers/graduation_tasks_controller.rb | 2 +- app/controllers/homework_commons_controller.rb | 2 +- app/controllers/zips_controller.rb | 11 ++++++++--- app/services/export_shixun_report_service.rb | 3 ++- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index aebd8b092..a89a81798 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -129,7 +129,7 @@ class GraduationTasksController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") elsif complete_works == 0 - normal_status(-1,"暂无提交的学生!") + normal_status(-1,"暂无用户提交!") else respond_to do |format| format.xlsx{ diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 2d52b6aa0..fe2adba45 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -200,7 +200,7 @@ class HomeworkCommonsController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") elsif complete_works == 0 - normal_status(-1,"暂无提交的学生!") + normal_status(-1,"暂无用户提交!") else respond_to do |format| format.xlsx{ diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 3b9fa7c02..8553cbb44 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -44,9 +44,12 @@ class ZipsController < ApplicationController ActiveRecord::Base.transaction do begin @exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id]) + @exercise_status = @exercise.get_exercise_status(current_user.id) group_id = params[:exercise_group_id] if @exercise.blank? normal_status(-1,"试卷不存在") + elsif @exercise_status == 1 + normal_status(-1,"试卷未发布") else @course = @exercise.course default_ex_users = @exercise.all_exercise_users(current_user.id).exercise_user_committed @@ -66,7 +69,7 @@ class ZipsController < ApplicationController if params[:commit_status].present? && (params[:commit_status].to_i == 1) @exercise_users_list = @exercise_users_list.where(commit_status:params[:commit_status]) elsif params[:commit_status].present? && (params[:commit_status].to_i == 0) - normal_status(-1,"仅支持导出已提交的学生!") + normal_status(-1,"暂无用户提交!") end #可以分班选择 @@ -84,7 +87,7 @@ class ZipsController < ApplicationController default_ex_users_size = @ex_users&.size if default_ex_users_size.blank? || default_ex_users_size == 0 - normal_status(-1,"导出失败,暂时没有已提交的学生") + normal_status(-1,"暂无用户提交") elsif default_ex_users_size > 100 normal_status(-2,"100") end @@ -98,6 +101,8 @@ class ZipsController < ApplicationController def load_homework @homework = HomeworkCommon.find(params[:homework_common_id]) + + @course = @homework.course ##7。2 -hs新增 @member = @course.course_member(current_user.id) @@ -121,7 +126,7 @@ class ZipsController < ApplicationController student_work_sizes = @all_student_works&.size if student_work_sizes.blank? || student_work_sizes == 0 - normal_status(-1,"导出失败,暂时没有已提交的学生") + normal_status(-1,"暂无用户提交") elsif student_work_sizes > 100 normal_status(-2,"100") end diff --git a/app/services/export_shixun_report_service.rb b/app/services/export_shixun_report_service.rb index 8358d422e..4c8dab6aa 100644 --- a/app/services/export_shixun_report_service.rb +++ b/app/services/export_shixun_report_service.rb @@ -45,7 +45,8 @@ class ExportShixunReportService @games = @work.myshixun.games.includes(:challenge, :game_codes,:outputs) if @work.myshixun # 用户最大评测次数 - @user_evaluate_count = @games.inject(0){|sum, g| sum + g.outputs.pluck(:query_index).first } if @games + @user_evaluate_count = @games.pluck(:evaluate_count).sum if @games + # @user_evaluate_count = @games.inject(0){|sum, g| sum + g.outputs.pluck(:query_index)&.first } if @games # 图形效率图的数据 @echart_data = student_efficiency(homework, @work) @myself_eff = @echart_data[:efficiency_list].find { |item| item.last == @user.id } From 77b6b52cff13adb2dea41c5e6a16e2ae32cf6a5c Mon Sep 17 00:00:00 2001 From: jasder Date: Wed, 3 Jul 2019 14:53:03 +0800 Subject: [PATCH 0545/1015] files pemission --- app/controllers/files_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index c8fd042ea..2af178e47 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -200,7 +200,7 @@ class FilesController < ApplicationController # 资源设置 def update - return normal_status(403, "您没有权限进行该操作") unless current_user.teacher_or_admin?(@course) || @file.author == current_user + return normal_status(403, "您没有权限进行该操作") if current_user.course_identity(@course) >= 5 && @file.author != current_user is_unified_setting = params[:is_unified_setting] publish_time = params[:publish_time] From c1ad4c0585bf34fa89c5974ab3c14b1156a85994 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 3 Jul 2019 14:57:20 +0800 Subject: [PATCH 0546/1015] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E6=88=AA=E6=AD=A2?= =?UTF-8?q?=E6=97=B6=E8=AE=A1=E7=AE=97=E6=95=88=E7=8E=87=E5=88=86=E7=9A=84?= =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 2 +- app/jobs/homework_end_update_score_job.rb | 32 +++++++++++++++++++ lib/tasks/homework_publishtime.rake | 6 ++-- .../homework_end_update_score_job_spec.rb | 5 +++ 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 app/jobs/homework_end_update_score_job.rb create mode 100644 spec/jobs/homework_end_update_score_job_spec.rb diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 2d52b6aa0..9bbc374a1 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -1117,7 +1117,7 @@ class HomeworkCommonsController < ApplicationController =end # 更新所有学生的效率分(重新取homework确保是更新后的) - HomeworksService.new.update_student_eff_score HomeworkCommon.find_by(id: homework.id) if !homework.allow_late && homework.end_time <= time + HomeworkEndUpdateScoreJob.perform_later(homework.id) if !homework.allow_late && homework.end_time <= time end end homework.save! diff --git a/app/jobs/homework_end_update_score_job.rb b/app/jobs/homework_end_update_score_job.rb new file mode 100644 index 000000000..ea6d3e5e3 --- /dev/null +++ b/app/jobs/homework_end_update_score_job.rb @@ -0,0 +1,32 @@ +class HomeworkEndUpdateScoreJob < ApplicationJob + # 不允许补交的作业截止后,或者补交截止后需要重新计算一次作业成绩 + queue_as :score + + def perform(*args) + homework = HomeworkCommon.find_by(id: homework_id) + return if homework.blank? + course = homework.course + return if course.blank? + + if homework.unified_setting + student_works = homework.student_works + user_ids = course.students.pluck(:user_id) + else + user_ids = course.students.where(course_group_id: homework.published_settings.pluck(:course_group_id)).pluck(:user_id) + student_works = homework.student_works.where(user_id: user_ids) + end + + myshixuns = Myshixun.where(shixun_id: params[:shixun_id], user_id: user_ids). + includes(:games).where(games: {challenge_id: homework.homework_challenge_settings.pluck(:challenge_id)}) + challenge_settings = homework.homework_challenge_settings + myshixuns.find_each(batch_size: 100) do |myshixun| + work = student_works.select{|work| work.user_id == myshixun.user_id}.first + if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at) + games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id)) + HomeworksService.new.update_myshixun_work_score work, myshixun, games, homework, challenge_settings + end + end + HomeworksService.new.update_student_eff_score homework + homework.update_attribute('calculation_time', Time.now) + end +end diff --git a/lib/tasks/homework_publishtime.rake b/lib/tasks/homework_publishtime.rake index 4127a9339..918e70a70 100644 --- a/lib/tasks/homework_publishtime.rake +++ b/lib/tasks/homework_publishtime.rake @@ -84,7 +84,8 @@ namespace :homework_publishtime do student_works.joins(:myshixun).where("myshixuns.status != 1").update_all(late_penalty: homework.late_penalty) if student_works.present? else - HomeworksService.new.update_student_eff_score homework + HomeworkEndUpdateScoreJob.perform_later(homework.id) + # HomeworksService.new.update_student_eff_score homework end =begin @@ -206,7 +207,8 @@ namespace :homework_publishtime do homework_commons = HomeworkCommon.joins(:homework_detail_manual).where("homework_type = 4 and allow_late = 1 and late_time <= ? and late_time > ? and homework_detail_manuals.comment_status != 6", Time.now, Time.now - 900) homework_commons.each do |homework| - HomeworksService.new.update_student_eff_score homework + # HomeworksService.new.update_student_eff_score homework + HomeworkEndUpdateScoreJob.perform_later(homework.id) =begin homework_detail_manual = homework.homework_detail_manual diff --git a/spec/jobs/homework_end_update_score_job_spec.rb b/spec/jobs/homework_end_update_score_job_spec.rb new file mode 100644 index 000000000..492b35d43 --- /dev/null +++ b/spec/jobs/homework_end_update_score_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe HomeworkEndUpdateScoreJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end From 7264d1f0f3615884aba975803c7f6d58bfe3b159 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Wed, 3 Jul 2019 15:13:57 +0800 Subject: [PATCH 0547/1015] add apply add school && apply add department --- .../add_department_applies_controller.rb | 15 +++++++ .../add_school_applies_controller.rb | 16 +++++++ app/forms/add_school_apply_form.rb | 10 +++++ app/models/applied_message.rb | 5 +++ app/models/apply_add_department.rb | 15 +++++++ app/models/apply_add_school.rb | 14 ++++++ .../create_add_department_apply_service.rb | 43 +++++++++++++++++++ .../create_add_school_apply_service.rb | 37 ++++++++++++++++ .../forms/add_school_apply_form.zh-CN.yml | 8 ++++ config/routes.rb | 2 + 10 files changed, 165 insertions(+) create mode 100644 app/controllers/add_department_applies_controller.rb create mode 100644 app/controllers/add_school_applies_controller.rb create mode 100644 app/forms/add_school_apply_form.rb create mode 100644 app/models/applied_message.rb create mode 100644 app/models/apply_add_department.rb create mode 100644 app/models/apply_add_school.rb create mode 100644 app/services/create_add_department_apply_service.rb create mode 100644 app/services/create_add_school_apply_service.rb create mode 100644 config/locales/forms/add_school_apply_form.zh-CN.yml diff --git a/app/controllers/add_department_applies_controller.rb b/app/controllers/add_department_applies_controller.rb new file mode 100644 index 000000000..ed8067c84 --- /dev/null +++ b/app/controllers/add_department_applies_controller.rb @@ -0,0 +1,15 @@ +class AddDepartmentAppliesController < ApplicationController + before_action :require_login + + def create + CreateAddDepartmentApplyService.call(current_user, create_params) + render_ok + rescue CreateAddDepartmentApplyService::Error => ex + render_error(ex.message) + end + + private + def create_params + params.permit(:name, :school_id, :remarks) + end +end \ No newline at end of file diff --git a/app/controllers/add_school_applies_controller.rb b/app/controllers/add_school_applies_controller.rb new file mode 100644 index 000000000..9f2376b9e --- /dev/null +++ b/app/controllers/add_school_applies_controller.rb @@ -0,0 +1,16 @@ +class AddSchoolAppliesController < ApplicationController + before_action :require_login + + def create + CreateAddSchoolApplyService.call(current_user, create_params) + render_ok + rescue CreateAddSchoolApplyService::Error => ex + render_error(ex.message) + end + + private + + def create_params + params.permit(:name, :province, :city, :address, :remarks) + end +end \ No newline at end of file diff --git a/app/forms/add_school_apply_form.rb b/app/forms/add_school_apply_form.rb new file mode 100644 index 000000000..c0b767f06 --- /dev/null +++ b/app/forms/add_school_apply_form.rb @@ -0,0 +1,10 @@ +class AddSchoolApplyForm + include ActiveModel::Model + + attr_accessor :name, :province, :city, :address, :remarks + + validates :name, presence: true + validates :province, presence: true + validates :city, presence: true + validates :address, presence: true +end \ No newline at end of file diff --git a/app/models/applied_message.rb b/app/models/applied_message.rb new file mode 100644 index 000000000..ed02a5445 --- /dev/null +++ b/app/models/applied_message.rb @@ -0,0 +1,5 @@ +class AppliedMessage < ApplicationRecord + belongs_to :user + belongs_to :applied, polymorphic: true + +end \ No newline at end of file diff --git a/app/models/apply_add_department.rb b/app/models/apply_add_department.rb new file mode 100644 index 000000000..3deeaa97e --- /dev/null +++ b/app/models/apply_add_department.rb @@ -0,0 +1,15 @@ +class ApplyAddDepartment < ApplicationRecord + belongs_to :user + belongs_to :school + belongs_to :department + + has_many :applied_messages, as: :applied + has_many :tidings, as: :container, dependent: :destroy + + after_create :send_notify + + private + def send_notify + tidings.create!(user_id: 1, trigger_user_id: user_id, belong_container: school, tiding_type: 'Apply', status: 0) + end +end \ No newline at end of file diff --git a/app/models/apply_add_school.rb b/app/models/apply_add_school.rb new file mode 100644 index 000000000..bae65d24f --- /dev/null +++ b/app/models/apply_add_school.rb @@ -0,0 +1,14 @@ +class ApplyAddSchool < ApplicationRecord + belongs_to :school + + has_many :applied_messages, as: :applied + has_many :tidings, as: :container, dependent: :destroy + + after_create :send_notify + + private + + def send_notify + tidings.create!(user_id: 1, status: 0, trigger_user_id: user_id, belong_container: school, tiding_type: 'Apply') + end +end \ No newline at end of file diff --git a/app/services/create_add_department_apply_service.rb b/app/services/create_add_department_apply_service.rb new file mode 100644 index 000000000..f1d6cf852 --- /dev/null +++ b/app/services/create_add_department_apply_service.rb @@ -0,0 +1,43 @@ +class CreateAddDepartmentApplyService < ApplicationService + Error = Class.new(StandardError) + + attr_reader :user, :params + + def initialize(user, params) + @user = user + @params = params + end + + def call + name = params[:name].to_s.strip + raise Error, '名称不能为空' if name.blank? + + school = School.find_by(id: params[:school_id]) + raise Error, '学校/单位不存在' if school.blank? + + department = Department.new + department.name = name + department.school = school + + ActiveRecord::Base.transaction do + department.save! + + attrs = { + user_id: user.id, department: department, school: school, + name: department.name, remarks: params[:remarks], status: 0, + } + apply = ApplyAddDepartment.create!(attrs) + + unless user.professional_certification? + user.user_extension.update!(department_id: department.id) + end + + # 向管理员发送通知 + message = AppliedMessage.new(user_id: 1, status: 0, applied_user_id: user.id, viewed: 0, + applied_id: apply.id, applied_type: 'ApplyAddDepartment', name: department.name) + message.save(validate: false) + end + + school + end +end diff --git a/app/services/create_add_school_apply_service.rb b/app/services/create_add_school_apply_service.rb new file mode 100644 index 000000000..96619c681 --- /dev/null +++ b/app/services/create_add_school_apply_service.rb @@ -0,0 +1,37 @@ +class CreateAddSchoolApplyService < ApplicationService + Error = Class.new(StandardError) + + attr_reader :user, :params + + def initialize(user, params) + @user = user + @params = params + end + + def call + AddSchoolApplyForm.new(params).validate! + + name = params[:name].to_s.strip + raise Error, '学校/单位已经存在' if name.present? && School.exists?(name: name) + + school = School.new + school.name = name + school.province = params[:province].to_s.strip + school.city = params[:city].to_s.strip + school.address = params[:address].to_s.strip + + ActiveRecord::Base.transaction do + school.save! + + school_attrs = school.as_json(only: %i[name province city address]) + ApplyAddSchool.create!(school_attrs.merge(school: school, user_id: user.id, remarks: params[:remarks])) + + # 向管理员发送通知 + message = AppliedMessage.new(user_id: 1, status: 0, applied_user_id: user.id, viewed: 0, + applied_id: school.id, applied_type: 'ApplyAddSchools', name: school.name) + message.save(validate: false) + end + + school + end +end diff --git a/config/locales/forms/add_school_apply_form.zh-CN.yml b/config/locales/forms/add_school_apply_form.zh-CN.yml new file mode 100644 index 000000000..749578164 --- /dev/null +++ b/config/locales/forms/add_school_apply_form.zh-CN.yml @@ -0,0 +1,8 @@ +'zh-CN': + activemodel: + attributes: + add_school_apply_form: + name: 名称 + province: 省份 + city: 城市 + address: 详细地址 diff --git a/config/routes.rb b/config/routes.rb index a27dde1f3..610b7f550 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -592,6 +592,8 @@ Rails.application.routes.draw do resources :ec_major_schools, only: [:index, :create, :destroy] end end + resources :add_school_applies, only: [:create] + resources :add_department_applies, only: [:create] # 为避免url过长以及层级过深,路由定义和controller继承都做了处理 scope module: :ecs do From d38053e0f45f01db3941df89f1f3ca77aadde143 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 15:23:18 +0800 Subject: [PATCH 0548/1015] =?UTF-8?q?=E5=B7=B2=E5=8F=91=E5=B8=83=E7=9A=84?= =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=BC=96=E8=BE=91=E5=90=8E=E9=87=8D=E6=96=B0?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E5=88=86=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercise_questions_controller.rb | 11 ++++++----- app/controllers/graduation_tasks_controller.rb | 4 ++-- app/controllers/homework_commons_controller.rb | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index b231d6af7..77cc108b3 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -350,8 +350,9 @@ class ExerciseQuestionsController < ApplicationController @exercise_question.shixun_name = shixun_name end - #当标准答案修改时,如有已提交的学生,需重新计算分数 - if st_count > 0 + #当试卷已发布时(试卷的总状态),当标准答案修改时,如有已提交的学生,需重新计算分数. + + if @exercise.exercise_status == 2 ex_users_committed = @exercise.exercise_users.exercise_user_committed if ex_users_committed.size > 0 ex_users_committed.each do |ex_user| @@ -587,15 +588,15 @@ class ExerciseQuestionsController < ApplicationController if @exercise_question.present? @exercise = @exercise_question.exercise if @exercise.blank? - tip_exception(404) + tip_exception(404,"试卷不存在") else @course = @exercise.course if @course.blank? - tip_exception(404) + tip_exception(404,"课堂不存在") end end else - tip_exception(404) + tip_exception(404,"试卷问题不存在") end end diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index a89a81798..545b10e11 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -129,7 +129,7 @@ class GraduationTasksController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") elsif complete_works == 0 - normal_status(-1,"暂无用户提交!") + normal_status(-1,"暂无用户提交") else respond_to do |format| format.xlsx{ @@ -164,7 +164,7 @@ class GraduationTasksController < ApplicationController @work_count = @work_list.count @all_work_count = @work_list.count if params[:format] == "xlsx" || params[:format] == "zip" - normal_status(-1,"作业未发布") + normal_status(-1,"毕设任务未发布") end end end diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index fe2adba45..e595c703e 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -106,7 +106,7 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.all_works @all_member_count = student_works.size - if @homework.publish_time.nil? || @homework.publish_time > Time.now + if @homework.publish_time.blank? || (@homework.publish_time > Time.now) @student_works = [] if params[:format] == "xlsx" || params[:format] == "zip" normal_status(-1,"作业未发布") From b286e432ffb4655196558811a46458d59be274ad Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 3 Jul 2019 15:43:17 +0800 Subject: [PATCH 0549/1015] =?UTF-8?q?sidekiq=E6=9C=AC=E5=9C=B0=E7=9B=91?= =?UTF-8?q?=E6=8E=A7=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 1 + Gemfile.lock | 7 +++++++ config/routes.rb | 3 +++ 3 files changed, 11 insertions(+) diff --git a/Gemfile b/Gemfile index b8b174a6f..0473e221e 100644 --- a/Gemfile +++ b/Gemfile @@ -84,6 +84,7 @@ gem 'rails-i18n', '~> 5.1' # job gem 'sidekiq' +gem 'sinatra' # batch insert gem 'bulk_insert' diff --git a/Gemfile.lock b/Gemfile.lock index 86f524bc2..728bbc672 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -142,6 +142,7 @@ GEM multi_json (1.13.1) multi_xml (0.6.0) multipart-post (2.0.0) + mustermann (1.0.3) mysql2 (0.5.2) nio4r (2.3.1) nokogiri (1.8.4) @@ -265,6 +266,11 @@ GEM simple_xlsx_reader (1.0.4) nokogiri rubyzip + sinatra (2.0.5) + mustermann (~> 1.0) + rack (~> 2.0) + rack-protection (= 2.0.5) + tilt (~> 2.0) spreadsheet (1.2.3) ruby-ole (>= 1.0) spring (2.0.2) @@ -341,6 +347,7 @@ DEPENDENCIES selenium-webdriver sidekiq simple_xlsx_reader + sinatra spreadsheet spring spring-watcher-listen (~> 2.0.0) diff --git a/config/routes.rb b/config/routes.rb index a27dde1f3..01e301c3c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,8 @@ Rails.application.routes.draw do + require 'sidekiq/web' + mount Sidekiq::Web => '/sidekiq' + resources :edu_settings scope '/api' do get 'home/index' From 841bd09f236c9be5807774c7f4d328bd6cf6aaa3 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 3 Jul 2019 15:55:50 +0800 Subject: [PATCH 0550/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E7=9A=84=E8=AE=BF=E9=97=AE=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 2 +- app/controllers/subjects_controller.rb | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 9c3847b3c..e558e657c 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -18,7 +18,7 @@ class MyshixunsController < ApplicationController # REDO等删除是否可以做成异步 # 前段需要按照操作过程提示 def reset_my_game - unless (current_user.admin? || current_user.id == @myshixun.user_id) + unless current_user.admin? tip_exception("403", "") end diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index c73fec500..bb7059af6 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -81,6 +81,9 @@ class SubjectsController < ApplicationController @tags = ChallengeTag.where(challenge_id: challenge_ids).pluck(:name).uniq # 用户获取的实训标签 @user_tags = @subject.shixuns.map(&:user_tags_name).flatten.uniq + + # 访问数变更 + @subject.increment!(:visits) end def create From 748f4dc5779690ee82d46f055111e065fc597c0b Mon Sep 17 00:00:00 2001 From: p31729568 Date: Wed, 3 Jul 2019 16:04:52 +0800 Subject: [PATCH 0551/1015] fix users subject repeat bug --- app/services/users/subject_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/users/subject_service.rb b/app/services/users/subject_service.rb index 7e3eaaa81..745b7cce2 100644 --- a/app/services/users/subject_service.rb +++ b/app/services/users/subject_service.rb @@ -14,7 +14,7 @@ class Users::SubjectService subjects = category_scope_subjects subjects = user_policy_filter(subjects) - custom_sort(subjects, :updated_at, params[:sort_direction]) + custom_sort(subjects.distinct, :updated_at, params[:sort_direction]) end private From b21966c3572d62849d5bd7e179ecb54fb087a81a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 16:05:45 +0800 Subject: [PATCH 0552/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=A4=9A=E7=A9=BA?= =?UTF-8?q?=E9=A2=98=E7=9A=84=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exercise_questions_controller.rb | 5 ---- ...611_add_old_exercise_tiankong_choice_id.rb | 23 +++++++++++++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20190703072611_add_old_exercise_tiankong_choice_id.rb diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 77cc108b3..deb9b3157 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -223,7 +223,6 @@ class ExerciseQuestionsController < ApplicationController end end #试卷未发布时,当标准答案存在时,可修改标准答案内容,可增删标准答案,否则只能修改标准答案,不能增删标准答案 - st_count = 0 @exercise_answers_array = @exercise_question.exercise_standard_answers #问卷的全部标准答案 if standard_answer.present? if @exercise_question.question_type <= 2 #选择题/判断题,标准答案为一个或多个 @@ -232,7 +231,6 @@ class ExerciseQuestionsController < ApplicationController old_left_standard_choices = exercise_standard_choices - common_standard_choices # 以前的差集共同的,剩余的表示需要删掉 new_left_standard_choices = standard_answer - common_standard_choices # 传入的标准答案差集共同的,剩余的表示需要新建 if old_left_standard_choices.count > 0 - st_count += 1 @exercise_answers_array.standard_by_ids(old_left_standard_choices).destroy_all end if new_left_standard_choices.count > 0 #新建标准答案 @@ -258,7 +256,6 @@ class ExerciseQuestionsController < ApplicationController #删除多余的选项 if old_ex_answer_choice_ids.count > new_ex_answer_choice_ids.count #有减少的填空 - st_count += 1 delete_ex_answer_choice_ids = old_ex_answer_choice_ids - new_ex_answer_choice_ids old_ex_answer.standard_by_ids(delete_ex_answer_choice_ids).destroy_all end @@ -284,7 +281,6 @@ class ExerciseQuestionsController < ApplicationController ex_answer_pre[n-1].update(standard_option) end if new_add_choice.count > 0 #表示有新增的 - st_count += 1 new_add_choice.each do |i| standard_option = { :exercise_question_id => @exercise_question.id, @@ -306,7 +302,6 @@ class ExerciseQuestionsController < ApplicationController ex_answer_pre[index].update(standard_option) end if new_delete_choice.count > 0 #表示填空题的答案有删减的 - st_count += 1 new_delete_choice.each do |d| ex_answer_pre[d-1].destroy end diff --git a/db/migrate/20190703072611_add_old_exercise_tiankong_choice_id.rb b/db/migrate/20190703072611_add_old_exercise_tiankong_choice_id.rb new file mode 100644 index 000000000..9ad1429e2 --- /dev/null +++ b/db/migrate/20190703072611_add_old_exercise_tiankong_choice_id.rb @@ -0,0 +1,23 @@ +class AddOldExerciseTiankongChoiceId < ActiveRecord::Migration[5.2] + + def up + #类型为3 的问题答案及标准答案更新exercise_choice_id 为1,即表示第一空 + exercise_question_ids = ExerciseQuestion.where("question_type = 3").pluck(:id) + ExerciseAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: nil).update_all(exercise_choice_id:1) + ExerciseStandardAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: nil).update_all(exercise_choice_id:1) + + exercise_bank_question_ids = ExerciseBankQuestion.where("question_type =3").pluck(:id) + ExerciseBankStandardAnswer.where(exercise_bank_question_id: exercise_bank_question_ids).update_all(exercise_bank_choice_id:1) + end + + def down + #类型为3 的问题答案及标准答案更新exercise_choice_id 为1,即表示第一空 + exercise_question_ids = ExerciseQuestion.where("question_type = 3").pluck(:id) + ExerciseAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: 1).update_all(exercise_choice_id:nil) + ExerciseStandardAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: 1).update_all(exercise_choice_id:nil) + + exercise_bank_question_ids = ExerciseBankQuestion.where("question_type =3").pluck(:id) + ExerciseBankStandardAnswer.where(exercise_bank_question_id: exercise_bank_question_ids).update_all(exercise_bank_choice_id:nil) + end + +end From 0d254b0da4c2701e3efc0a8b5184e4e8e0b6434a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 3 Jul 2019 16:16:24 +0800 Subject: [PATCH 0553/1015] score fix --- app/controllers/homework_commons_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 4cd9209f3..57ae1023b 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -250,7 +250,7 @@ class HomeworkCommonsController < ApplicationController challenge_settings = @homework.homework_challenge_settings myshixuns.find_each(batch_size: 100) do |myshixun| work = student_works.select{|work| work.user_id == myshixun.user_id}.first - if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at) + if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.games.pluck(:updated_at).max) games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id)) HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings end @@ -271,7 +271,7 @@ class HomeworkCommonsController < ApplicationController myshixun = Myshixun.find_by(shixun_id: params[:shixun_id], user_id: current_user.id) ActiveRecord::Base.transaction do begin - if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at) + if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.games.pluck(:updated_at).max) challenge_settings = @homework.homework_challenge_settings games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id)) HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings From 0fb454cca58cdbce989441cc7bef237d0623036a Mon Sep 17 00:00:00 2001 From: jasder Date: Wed, 3 Jul 2019 16:18:45 +0800 Subject: [PATCH 0554/1015] ADD files bulk publish --- app/controllers/files_controller.rb | 8 +++++++- config/routes.rb | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 2af178e47..05a9ab841 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -3,7 +3,7 @@ class FilesController < ApplicationController before_action :require_login, except: %i[index] before_action :find_course, except: %i[public_with_course_and_project mine_with_course_and_project] - before_action :find_ids, only: %i[bulk_delete bulk_send bulk_move bulk_public] + before_action :find_ids, only: %i[bulk_delete bulk_send bulk_move bulk_public bulk_publish] before_action :file_validate_sort_type, only: :index before_action :validate_send_message_to_course_params, only: :bulk_send before_action :set_pagination, only: %i[index public_with_course_and_project mine_with_course_and_project] @@ -40,6 +40,12 @@ class FilesController < ApplicationController @attachments = @attachments.page(@page).per(@page_size) end + def bulk_publish + return normal_status(403, "您没有权限进行操作") if current_user.course_identity(@course) >= 5 + @course.attachments.by_ids(@attachment_ids).unpublish.update_all(is_publish: 1, publish_time: Time.now) + render_ok + end + def bulk_delete ActiveRecord::Base.transaction do begin diff --git a/config/routes.rb b/config/routes.rb index a27dde1f3..f47b704b1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -253,6 +253,7 @@ Rails.application.routes.draw do get :mine_with_course_and_project post :import post :upload + put :bulk_publish end member do get :histories From bed09475eda5361252cd32c0a4acceb2318a024a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 16:35:06 +0800 Subject: [PATCH 0555/1015] fix bug --- .../exercise_questions_controller.rb | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index deb9b3157..b852e9437 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -347,17 +347,28 @@ class ExerciseQuestionsController < ApplicationController #当试卷已发布时(试卷的总状态),当标准答案修改时,如有已提交的学生,需重新计算分数. - if @exercise.exercise_status == 2 - ex_users_committed = @exercise.exercise_users.exercise_user_committed - if ex_users_committed.size > 0 - ex_users_committed.each do |ex_user| - user = ex_user.user - objective_score = calculate_student_score(@exercise,user)[:total_score] - subjective_score = ex_user.subjective_score - total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - total_score = objective_score + total_score_subjective_score - ex_user.update_attributes(objective_score:objective_score,score:total_score) - end + # if @exercise.exercise_status == 2 + # ex_users_committed = @exercise.exercise_users.exercise_user_committed + # if ex_users_committed.size > 0 + # ex_users_committed.each do |ex_user| + # user = ex_user.user + # objective_score = calculate_student_score(@exercise,user)[:total_score] + # subjective_score = ex_user.subjective_score + # total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + # total_score = objective_score + total_score_subjective_score + # ex_user.update_attributes(objective_score:objective_score,score:total_score) + # end + # end + # end + ex_users_committed = @exercise.exercise_users.exercise_user_committed + if ex_users_committed.size > 0 + ex_users_committed.each do |ex_user| + user = ex_user.user + objective_score = calculate_student_score(@exercise,user)[:total_score] + subjective_score = ex_user.subjective_score + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = objective_score + total_score_subjective_score + ex_user.update_attributes(objective_score:objective_score,score:total_score) end end From 50ea41ac7ff492eaba5f6d638b37a5f2007b8827 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 3 Jul 2019 16:40:57 +0800 Subject: [PATCH 0556/1015] git email test --- app/controllers/myshixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 9c3847b3c..89d76c16c 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -275,7 +275,7 @@ class MyshixunsController < ApplicationController message: message, content: content, author_name: author_name, - author_email: author_email) + author_email: "53246666@qq.com") end end From 75aa92026fa3d563134ca3c695039ddcccfb7aaf Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 3 Jul 2019 16:55:08 +0800 Subject: [PATCH 0557/1015] add author email for git --- app/controllers/myshixuns_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 87823ce21..3dfb739d0 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -15,7 +15,6 @@ class MyshixunsController < ApplicationController # For Admin # 强制重置实训 - # REDO等删除是否可以做成异步 # 前段需要按照操作过程提示 def reset_my_game unless current_user.admin? @@ -275,7 +274,7 @@ class MyshixunsController < ApplicationController message: message, content: content, author_name: author_name, - author_email: "53246666@qq.com") + author_email: author_email) end end From 9ee6fee20ad7640d8721431e6e65c5f77046264c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 16:58:42 +0800 Subject: [PATCH 0558/1015] fix bug --- .../exercise_questions_controller.rb | 40 ++++++------------- app/helpers/exercises_helper.rb | 9 +++++ 2 files changed, 21 insertions(+), 28 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index b852e9437..e33e5e2dc 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -347,36 +347,20 @@ class ExerciseQuestionsController < ApplicationController #当试卷已发布时(试卷的总状态),当标准答案修改时,如有已提交的学生,需重新计算分数. - # if @exercise.exercise_status == 2 - # ex_users_committed = @exercise.exercise_users.exercise_user_committed - # if ex_users_committed.size > 0 - # ex_users_committed.each do |ex_user| - # user = ex_user.user - # objective_score = calculate_student_score(@exercise,user)[:total_score] - # subjective_score = ex_user.subjective_score - # total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - # total_score = objective_score + total_score_subjective_score - # ex_user.update_attributes(objective_score:objective_score,score:total_score) - # end - # end - # end - ex_users_committed = @exercise.exercise_users.exercise_user_committed - if ex_users_committed.size > 0 - ex_users_committed.each do |ex_user| - user = ex_user.user - objective_score = calculate_student_score(@exercise,user)[:total_score] - subjective_score = ex_user.subjective_score - total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - total_score = objective_score + total_score_subjective_score - ex_user.update_attributes(objective_score:objective_score,score:total_score) + if @exercise.exercise_status == 2 + ex_users_committed = @exercise.exercise_users.exercise_user_committed + if ex_users_committed.size > 0 + ex_users_committed.each do |ex_user| + user = ex_user.user + objective_score = calculate_student_score(@exercise,user)[:total_score] + subjective_score = ex_user.subjective_score + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = objective_score + total_score_subjective_score + ex_user.update_attributes(objective_score:objective_score,score:total_score) + end end end - - if @exercise_question.save - normal_status(0,"试卷更新成功!") - else - normal_status(-1,"试卷更新失败!") - end + normal_status(0,"试卷更新成功!") rescue Exception => e uid_logger_error(e.message) tip_exception("页面调用失败!") diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 437965ca6..55ade6e7c 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -382,6 +382,9 @@ module ExercisesHelper 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 @@ -403,6 +406,9 @@ module ExercisesHelper if i_standard_answer.include?(u.answer_text.downcase) #该空的标准答案包含用户的答案才有分数 u.update_column('score',q_score_2) score2 = score2 + q_score_2 + else + u.update_column('score',-1.0) + score2 += 0.0 end end else @@ -413,6 +419,9 @@ module ExercisesHelper u.update_column("score",q_score_2) score2 = score2 + q_score_2 st_answer_text.delete(u_answer_text) + else + u.update_column('score',-1.0) + score2 += 0.0 end end end From 2c472f44a9a6e8245fd0d7899a2b70d5f056c7b3 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 17:10:03 +0800 Subject: [PATCH 0559/1015] fix bug --- app/controllers/homework_commons_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 4474d47c8..2fcf421f4 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -106,9 +106,11 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.all_works @all_member_count = student_works.size + logger.info("##########__________@homework.publish_time______________#############{@homework.publish_time}") if @homework.publish_time.blank? || (@homework.publish_time > Time.now) @student_works = [] if params[:format] == "xlsx" || params[:format] == "zip" + logger.info("##########__________params[:format]______________#############{params[:format]}") normal_status(-1,"作业未发布") end else From 41f01f49614a1885ffe373e7eaeb7033fb4a3a58 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 3 Jul 2019 17:21:21 +0800 Subject: [PATCH 0560/1015] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 1 + db/migrate/20190703090511_add_index_for_shixun_services.rb | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 db/migrate/20190703090511_add_index_for_shixun_services.rb diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 5a1773a10..2c4f2a7d1 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -180,6 +180,7 @@ class ShixunsController < ApplicationController end # 同步配置 + logger.info("########-shixun_service_configs_count: #{@shixun.shixun_service_configs.pluck(:id, :shixun_id)}") @shixun.shixun_service_configs.each do |config| ShixunServiceConfig.create!(:shixun_id => @new_shixun.id, :cpu_limit => config.cpu_limit, diff --git a/db/migrate/20190703090511_add_index_for_shixun_services.rb b/db/migrate/20190703090511_add_index_for_shixun_services.rb new file mode 100644 index 000000000..3e6dd3703 --- /dev/null +++ b/db/migrate/20190703090511_add_index_for_shixun_services.rb @@ -0,0 +1,5 @@ +class AddIndexForShixunServices < ActiveRecord::Migration[5.2] + def change + add_index :shixun_service_configs, [:shixun_id, :mirror_repository_id], unique: true, name: "shixun_id_mirror_id_unique" + end +end From c61cb1190f683a237058ce3babdcfbc26adf3460 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 17:32:04 +0800 Subject: [PATCH 0561/1015] fixbug --- app/controllers/homework_commons_controller.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 2fcf421f4..018218799 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -106,11 +106,9 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.all_works @all_member_count = student_works.size - logger.info("##########__________@homework.publish_time______________#############{@homework.publish_time}") if @homework.publish_time.blank? || (@homework.publish_time > Time.now) @student_works = [] - if params[:format] == "xlsx" || params[:format] == "zip" - logger.info("##########__________params[:format]______________#############{params[:format]}") + if (params[:format] == "xlsx") || (params[:format] == "zip") normal_status(-1,"作业未发布") end else @@ -198,7 +196,7 @@ class HomeworkCommonsController < ApplicationController end if params[:format] == "xlsx" - complete_works = @work_excel.where("work_status > 0").size + complete_works = @work_excel.exist? ? @work_excel.where("work_status > 0").size : 0 if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") elsif complete_works == 0 @@ -218,8 +216,13 @@ class HomeworkCommonsController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") else - zip_works = @work_excel.where("work_status > 0") - status = checkfileSize(zip_works) + if @work_excel.exist? + zip_works = @work_excel&.where("work_status > 0") + status = checkfileSize(zip_works) + else + status = -1 + end + if status == 0 respond_to do |format| format.zip{ From 1a96c3841df7faadd0c0cfb6076c8cbf67b94939 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 3 Jul 2019 17:33:59 +0800 Subject: [PATCH 0562/1015] =?UTF-8?q?job=E4=BB=BB=E5=8A=A1=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/exercise_publish_notify_job.rb | 1 + app/jobs/graduation_task_publish_notify_job.rb | 4 +++- app/jobs/submit_graduation_work_notify_job.rb | 5 +++-- app/jobs/submit_student_work_notify_job.rb | 5 +++-- app/models/course_member.rb | 8 ++++---- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/jobs/exercise_publish_notify_job.rb b/app/jobs/exercise_publish_notify_job.rb index 563f6ceb0..f68a68c00 100644 --- a/app/jobs/exercise_publish_notify_job.rb +++ b/app/jobs/exercise_publish_notify_job.rb @@ -6,6 +6,7 @@ class ExercisePublishNotifyJob < ApplicationJob exercise = Exercise.find_by(id: exercise_id) return if exercise.blank? user = exercise.user + course = exercise.course if group_ids.present? students = course.students.where(course_group_id: group_ids) diff --git a/app/jobs/graduation_task_publish_notify_job.rb b/app/jobs/graduation_task_publish_notify_job.rb index 92346ab27..16f5893ae 100644 --- a/app/jobs/graduation_task_publish_notify_job.rb +++ b/app/jobs/graduation_task_publish_notify_job.rb @@ -5,6 +5,8 @@ class GraduationTaskPublishNotifyJob < ApplicationJob def perform(graduation_task_id) task = GraduationTask.find_by(id: graduation_task_id) return if task.blank? + course = task.course + return if course.blank? attrs = %i[ user_id trigger_user_id container_id container_type parent_container_id parent_container_type @@ -18,7 +20,7 @@ class GraduationTaskPublishNotifyJob < ApplicationJob viewed: 0, tiding_type: 'GraduationTask' } Tiding.bulk_insert(*attrs) do |worker| - task.course.course_members.pluck(:user_id).uniq.find_each do |user_id| + course.course_members.pluck(:user_id).uniq.find_each do |user_id| worker.add same_attrs.merge(user_id: user_id) end end diff --git a/app/jobs/submit_graduation_work_notify_job.rb b/app/jobs/submit_graduation_work_notify_job.rb index 17cfc21d2..d4bb21cc4 100644 --- a/app/jobs/submit_graduation_work_notify_job.rb +++ b/app/jobs/submit_graduation_work_notify_job.rb @@ -19,11 +19,12 @@ class SubmitGraduationWorkNotifyJob < ApplicationJob next unless User.exists?(id: user_id) work = task.graduation_works.find_by(user_id: user_id) - next if work.blank? + member = course.students.find_by(user_id: user_id) + next if work.blank? || member.blank? attrs = same_attrs.merge(trigger_user_id: user_id, container_id: work.id) - course.course_member(user_id).member_teachers.find_each do |teacher| + member.member_teachers.find_each do |teacher| worker.add attrs.merge(user_id: teacher.user_id) end end diff --git a/app/jobs/submit_student_work_notify_job.rb b/app/jobs/submit_student_work_notify_job.rb index acb7873ac..c4dff264c 100644 --- a/app/jobs/submit_student_work_notify_job.rb +++ b/app/jobs/submit_student_work_notify_job.rb @@ -19,11 +19,12 @@ class SubmitStudentWorkNotifyJob < ApplicationJob next unless User.exists?(id: user_id) work = homework.student_works.find_by(user_id: user_id) - next if work.blank? + member = course.students.find_by(user_id: user_id) + next if work.blank? || member.blank? attrs = same_attrs.merge(trigger_user_id: user_id, container_id: work.id) - course.course_member(user_id).member_teachers.find_each do |teacher| + member.member_teachers.find_each do |teacher| worker.add attrs.merge(user_id: teacher.user_id) end end diff --git a/app/models/course_member.rb b/app/models/course_member.rb index d9995d463..7db681e67 100644 --- a/app/models/course_member.rb +++ b/app/models/course_member.rb @@ -146,11 +146,11 @@ class CourseMember < ApplicationRecord def member_teachers teacher_groups = course.teacher_course_groups if teacher_groups.count > 0 - member_ids = teacher_groups.where(course_group_id: self.try(:course_group_id)).pluck(:course_member_id) + member_ids = teacher_groups.where(course_group_id: self.try(:course_group_id)).pluck(:course_member_id).compact - none_group_teachers = teacher_groups.pluck(:course_member_id).size > 0 ? teacher_groups.pluck(:course_member_id).join(',') : -1 - teachers = course.teachers.where("members.id not in (#{none_group_teachers}) or - members.id in (#{member_ids.size > 0 ? member_ids.join(',') : -1})") + none_group_teachers = teacher_groups.pluck(:course_member_id).size > 0 ? teacher_groups.pluck(:course_member_id).compact.join(',') : -1 + teachers = course.teachers.where("course_members.id not in (#{none_group_teachers}) or + course_members.id in (#{member_ids.size > 0 ? member_ids.join(',') : -1})") else teachers = course.teachers end From 69ed83fae1a2473223189a4972a90e7e81c8afd2 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 17:34:02 +0800 Subject: [PATCH 0563/1015] fix bug --- app/controllers/homework_commons_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 018218799..66dd7c864 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -196,7 +196,7 @@ class HomeworkCommonsController < ApplicationController end if params[:format] == "xlsx" - complete_works = @work_excel.exist? ? @work_excel.where("work_status > 0").size : 0 + complete_works = @work_excel.present? ? @work_excel.where("work_status > 0").size : 0 if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") elsif complete_works == 0 @@ -216,7 +216,7 @@ class HomeworkCommonsController < ApplicationController if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") else - if @work_excel.exist? + if @work_excel.present? zip_works = @work_excel&.where("work_status > 0") status = checkfileSize(zip_works) else From 441dcf54e77bfe632dcd501863857d37cc8b5d87 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 17:39:12 +0800 Subject: [PATCH 0564/1015] fix bug --- app/controllers/homework_commons_controller.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 66dd7c864..229db7278 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -106,9 +106,15 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.all_works @all_member_count = student_works.size - if @homework.publish_time.blank? || (@homework.publish_time > Time.now) + logger.info("@@@@@@@_____________@homework.publish_time______________##{@homework.publish_time}") + logger.info("@@@@@@@_____________@homework.publish_time > Time.now______________##{@homework.publish_time > Time.now}") + + if @homework.publish_time.nil? || (@homework.publish_time > Time.now) + logger.info("@@@@@@@_____________1111111111_____________#11111111111") @student_works = [] if (params[:format] == "xlsx") || (params[:format] == "zip") + logger.info("@@@@@@@_____________22222222_____________#2222222221") + normal_status(-1,"作业未发布") end else From 0e68cc0e4ccbc1c4ca24726f478859e2c3453058 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 17:49:37 +0800 Subject: [PATCH 0565/1015] fix bug --- app/controllers/homework_commons_controller.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 229db7278..d49dac853 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -106,15 +106,10 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.all_works @all_member_count = student_works.size - logger.info("@@@@@@@_____________@homework.publish_time______________##{@homework.publish_time}") - logger.info("@@@@@@@_____________@homework.publish_time > Time.now______________##{@homework.publish_time > Time.now}") if @homework.publish_time.nil? || (@homework.publish_time > Time.now) - logger.info("@@@@@@@_____________1111111111_____________#11111111111") @student_works = [] if (params[:format] == "xlsx") || (params[:format] == "zip") - logger.info("@@@@@@@_____________22222222_____________#2222222221") - normal_status(-1,"作业未发布") end else From ab9b9b2fa0fe8a1b10a911c914bff24aa0744b58 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 3 Jul 2019 17:52:16 +0800 Subject: [PATCH 0566/1015] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190703090511_add_index_for_shixun_services.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/db/migrate/20190703090511_add_index_for_shixun_services.rb b/db/migrate/20190703090511_add_index_for_shixun_services.rb index 3e6dd3703..693add3e3 100644 --- a/db/migrate/20190703090511_add_index_for_shixun_services.rb +++ b/db/migrate/20190703090511_add_index_for_shixun_services.rb @@ -1,5 +1,9 @@ class AddIndexForShixunServices < ActiveRecord::Migration[5.2] def change + sql = %Q(delete from shixun_service_configs where (shixun_id, mirror_repository_id) in + (select * from (select shixun_id, mirror_repository_id from shixun_service_configs group by shixun_id, mirror_repository_id having count(*) > 1) a) + and id not in (select * from (select min(id) from shixun_service_configs group by shixun_id, mirror_repository_id having count(*) > 1 order by id) b)) + ActiveRecord::Base.connection.execute sql add_index :shixun_service_configs, [:shixun_id, :mirror_repository_id], unique: true, name: "shixun_id_mirror_id_unique" end end From ce381b24d660a481fc16054d2f7d454234cea248 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 3 Jul 2019 18:05:18 +0800 Subject: [PATCH 0567/1015] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=90=8D/n?= =?UTF-8?q?=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/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 1b3349467..d28a42eb6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -407,7 +407,7 @@ class User < ApplicationRecord name = lastname + firstname name.blank? ? (nickname.blank? ? login : nickname) : name - name.gsub(/\s+/, '').strip #6.11 -hs + name.gsub(/\s+/, '').gsub(/\n/, '').strip #6.11 -hs end # 用户是否选题毕设课题 From 99d2c9478c2745262de93f99f9553f7982962ee9 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 18:06:25 +0800 Subject: [PATCH 0568/1015] fixbug --- app/controllers/homework_commons_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index d49dac853..0ab3a6381 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -107,6 +107,8 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.all_works @all_member_count = student_works.size + logger.info("###########______@homework.publish_time_________#{@homework.publish_time}") + if @homework.publish_time.nil? || (@homework.publish_time > Time.now) @student_works = [] if (params[:format] == "xlsx") || (params[:format] == "zip") From fa4e184a032b8fa4fcb3f68d8919451bc3c2ab63 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 18:11:08 +0800 Subject: [PATCH 0569/1015] fix bug --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 0ab3a6381..9780b4eec 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -109,7 +109,7 @@ class HomeworkCommonsController < ApplicationController logger.info("###########______@homework.publish_time_________#{@homework.publish_time}") - if @homework.publish_time.nil? || (@homework.publish_time > Time.now) + if @homework.publish_time.present? || (@homework.publish_time > Time.now) @student_works = [] if (params[:format] == "xlsx") || (params[:format] == "zip") normal_status(-1,"作业未发布") From d957d57b4b01de4d0574dc7063098633e88c2168 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 3 Jul 2019 18:11:11 +0800 Subject: [PATCH 0570/1015] add log --- app/models/user.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index d28a42eb6..ca8913526 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -406,8 +406,10 @@ class User < ApplicationRecord return '游客' unless logged? name = lastname + firstname - name.blank? ? (nickname.blank? ? login : nickname) : name - name.gsub(/\s+/, '').gsub(/\n/, '').strip #6.11 -hs + username = name.blank? ? (nickname.blank? ? login : nickname) : name + Rail.logger.info("3333333332222222#{username}") + username.gsub(/\s+/, '').gsub(/\n/, '').strip #6.11 -hs + end # 用户是否选题毕设课题 From 938190ef9bb549e17eb20f7fde933437493c65ad Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 18:13:18 +0800 Subject: [PATCH 0571/1015] fix bug --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 9780b4eec..9b77f8dc7 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -109,7 +109,7 @@ class HomeworkCommonsController < ApplicationController logger.info("###########______@homework.publish_time_________#{@homework.publish_time}") - if @homework.publish_time.present? || (@homework.publish_time > Time.now) + if @homework.publish_time.blank? || (@homework.publish_time > Time.now) @student_works = [] if (params[:format] == "xlsx") || (params[:format] == "zip") normal_status(-1,"作业未发布") From 6516908a5867fb84ed768135a723cca976f78e7c Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 3 Jul 2019 18:15:36 +0800 Subject: [PATCH 0572/1015] real name --- app/models/user.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index ca8913526..20b60dfcb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -404,12 +404,9 @@ class User < ApplicationRecord # 用户的真实姓名(不考虑用户是否隐藏了真实姓名,课堂模块都用真实姓名) def real_name return '游客' unless logged? - name = lastname + firstname - username = name.blank? ? (nickname.blank? ? login : nickname) : name - Rail.logger.info("3333333332222222#{username}") - username.gsub(/\s+/, '').gsub(/\n/, '').strip #6.11 -hs - + name.blank? ? (nickname.blank? ? login : nickname) : name + gsub(/\s+/, '').strip #6.11 -hs end # 用户是否选题毕设课题 From e071aeb556a0dd1bb643ea23ebc25db667e6c1b9 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 3 Jul 2019 18:17:44 +0800 Subject: [PATCH 0573/1015] .. --- app/controllers/myshixuns_controller.rb | 1 + app/models/user.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 3dfb739d0..fd75b7062 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -269,6 +269,7 @@ class MyshixunsController < ApplicationController author_name = current_user.full_name author_email = current_user.mail message = params[:evaluate] == 0 ? "System automatically submitted" : "User submitted" + uid_logger("") @content = GitService.update_file(repo_path: @repo_path, file_path: path, message: message, diff --git a/app/models/user.rb b/app/models/user.rb index 20b60dfcb..e775af5f8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -406,7 +406,7 @@ class User < ApplicationRecord return '游客' unless logged? name = lastname + firstname name.blank? ? (nickname.blank? ? login : nickname) : name - gsub(/\s+/, '').strip #6.11 -hs + name.gsub(/\s+/, '').strip #6.11 -hs end # 用户是否选题毕设课题 From ae1046632083dc4601738a210c525f1524ff95f3 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 3 Jul 2019 18:19:15 +0800 Subject: [PATCH 0574/1015] =?UTF-8?q?=E6=B7=BB=E5=8A=A0git=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index fd75b7062..2131eed9a 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -269,7 +269,8 @@ class MyshixunsController < ApplicationController author_name = current_user.full_name author_email = current_user.mail message = params[:evaluate] == 0 ? "System automatically submitted" : "User submitted" - uid_logger("") + uid_logger("112233#{author_name}") + uid_logger("112233#{author_email}") @content = GitService.update_file(repo_path: @repo_path, file_path: path, message: message, From d2f1a7a06b690ad30996ae74b7254c8234a20da9 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 18:22:00 +0800 Subject: [PATCH 0575/1015] fix bug --- app/controllers/homework_commons_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 9b77f8dc7..5842d2522 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -108,8 +108,10 @@ class HomeworkCommonsController < ApplicationController @all_member_count = student_works.size logger.info("###########______@homework.publish_time_________#{@homework.publish_time}") + logger.info("-----------------------------------------------------") if @homework.publish_time.blank? || (@homework.publish_time > Time.now) + logger.info("+++++++++++++++++#{@homework.publish_time}") @student_works = [] if (params[:format] == "xlsx") || (params[:format] == "zip") normal_status(-1,"作业未发布") From 3fecc15aa7fc8c76cf3c708dc9bcb8a06d6dba65 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 3 Jul 2019 18:24:10 +0800 Subject: [PATCH 0576/1015] fix bug --- app/controllers/homework_commons_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 5842d2522..b25782026 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -114,6 +114,8 @@ class HomeworkCommonsController < ApplicationController logger.info("+++++++++++++++++#{@homework.publish_time}") @student_works = [] if (params[:format] == "xlsx") || (params[:format] == "zip") + logger.info("++++++params[:format]params[:format]params[:format]params[:format]+++++++++++#{params[:format]}") + normal_status(-1,"作业未发布") end else From cab3b87de3d311687998f9202c1a6899164dc1d8 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 3 Jul 2019 18:27:33 +0800 Subject: [PATCH 0577/1015] =?UTF-8?q?git=20=E6=9B=B4=E6=96=B0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8D=E6=88=90=E5=8A=9F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 2131eed9a..3abc71fd0 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -266,7 +266,7 @@ class MyshixunsController < ApplicationController if content != last_content @content_modified = 1 - author_name = current_user.full_name + author_name = current_user.real_name author_email = current_user.mail message = params[:evaluate] == 0 ? "System automatically submitted" : "User submitted" uid_logger("112233#{author_name}") From 233965ddca435fb4d350ca135038ac67925f4080 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 08:58:01 +0800 Subject: [PATCH 0578/1015] =?UTF-8?q?=E5=BC=80=E5=90=AF=E5=AE=9E=E8=AE=AD?= =?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 | 8 +++++++- app/views/challenges/index.json.jbuilder | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 2c4f2a7d1..4afba7a7b 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -522,7 +522,13 @@ class ShixunsController < ApplicationController end # 如果存在实训,则直接进入实训 - @current_task = current_myshixun.current_task(games) + # 如果实训允许跳关,传参params[:challenge_id]跳入具体的关卡 + @current_task = + if params[:challenge_id] && @shixun.task_pass + current_myshixun.games.where(challenge_id: params[:challenge_id]).take + else + current_myshixun.current_task(games) + end else # 如果未创建关卡一定不能开启实训,否则TPI没法找到当前的关卡 if @shixun.challenges_count == 0 diff --git a/app/views/challenges/index.json.jbuilder b/app/views/challenges/index.json.jbuilder index 6b92be411..37ce94305 100644 --- a/app/views/challenges/index.json.jbuilder +++ b/app/views/challenges/index.json.jbuilder @@ -17,7 +17,7 @@ if @challenges.present? json.passed_count challenge.user_passed_count json.playing_count challenge.playing_count json.name_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) - json.open_game challenge.open_game(@user.id, @shixun) + #json.open_game challenge.open_game(@user.id, @shixun) if @editable json.edit_url edit_shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) json.delete_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) From 5cdc8bb687ff3d7ad25b04b71e2a51138c4c8ae2 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 4 Jul 2019 09:00:28 +0800 Subject: [PATCH 0579/1015] =?UTF-8?q?xlsx=E5=AF=BC=E5=87=BA=E7=9A=84?= =?UTF-8?q?=E9=83=A8=E5=88=86=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 6 ------ app/views/polls/commit_result.xlsx.axlsx | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index b25782026..519c05c62 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -107,15 +107,9 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.all_works @all_member_count = student_works.size - logger.info("###########______@homework.publish_time_________#{@homework.publish_time}") - logger.info("-----------------------------------------------------") - if @homework.publish_time.blank? || (@homework.publish_time > Time.now) - logger.info("+++++++++++++++++#{@homework.publish_time}") @student_works = [] if (params[:format] == "xlsx") || (params[:format] == "zip") - logger.info("++++++params[:format]params[:format]params[:format]params[:format]+++++++++++#{params[:format]}") - normal_status(-1,"作业未发布") end else diff --git a/app/views/polls/commit_result.xlsx.axlsx b/app/views/polls/commit_result.xlsx.axlsx index 6ce00388c..aa7943d2a 100644 --- a/app/views/polls/commit_result.xlsx.axlsx +++ b/app/views/polls/commit_result.xlsx.axlsx @@ -49,7 +49,7 @@ wb.styles do |s| end #each_with_index sheet.add_row poll_users_info, :height =>15, :style => blue_cell - poll_users.each_with_index do |u,index| + poll_users.includes(user: :user_extension).each_with_index do |u,index| u_user = u.user user_answer_array = [] poll_questions.each do |q| From 2d6ed002d542530741e8bc206287dbc5e7dc1b06 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 4 Jul 2019 09:21:47 +0800 Subject: [PATCH 0580/1015] =?UTF-8?q?=E8=B0=83=E6=95=B4job?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/exercise_publish_notify_job.rb | 2 +- app/jobs/homework_end_update_score_job.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/jobs/exercise_publish_notify_job.rb b/app/jobs/exercise_publish_notify_job.rb index f68a68c00..9c43b1978 100644 --- a/app/jobs/exercise_publish_notify_job.rb +++ b/app/jobs/exercise_publish_notify_job.rb @@ -31,7 +31,7 @@ class ExercisePublishNotifyJob < ApplicationJob Tiding.bulk_insert(*attrs) do |worker| teacher_ids = teachers.pluck(:user_id) unless exercise.tidings.exists?(parent_container_type: 'ExercisePublish', user_id: teacher_ids) - teacher_ids.find_each do |user_id| + teacher_ids.each do |user_id| worker.add same_attrs.merge(user_id: user_id) end end diff --git a/app/jobs/homework_end_update_score_job.rb b/app/jobs/homework_end_update_score_job.rb index ea6d3e5e3..e141fd758 100644 --- a/app/jobs/homework_end_update_score_job.rb +++ b/app/jobs/homework_end_update_score_job.rb @@ -2,7 +2,7 @@ class HomeworkEndUpdateScoreJob < ApplicationJob # 不允许补交的作业截止后,或者补交截止后需要重新计算一次作业成绩 queue_as :score - def perform(*args) + def perform(homework_id) homework = HomeworkCommon.find_by(id: homework_id) return if homework.blank? course = homework.course From 21c8e0eae856a916ec18c11eab516b27fc95e101 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 09:22:01 +0800 Subject: [PATCH 0581/1015] =?UTF-8?q?=E5=BC=80=E5=90=AF=E5=85=B3=E5=8D=A1?= =?UTF-8?q?=E6=9C=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 4afba7a7b..1c6476a34 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -525,7 +525,7 @@ class ShixunsController < ApplicationController # 如果实训允许跳关,传参params[:challenge_id]跳入具体的关卡 @current_task = if params[:challenge_id] && @shixun.task_pass - current_myshixun.games.where(challenge_id: params[:challenge_id]).take + games.where(challenge_id: params[:challenge_id]).take else current_myshixun.current_task(games) end From 2b745db4b4340f52c601cfe35ed41ac9b0cd1bf3 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 4 Jul 2019 09:26:02 +0800 Subject: [PATCH 0582/1015] =?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/jobs/homework_end_update_score_job.rb | 3 ++- app/jobs/poll_publish_notify_job.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/jobs/homework_end_update_score_job.rb b/app/jobs/homework_end_update_score_job.rb index e141fd758..649a5c37a 100644 --- a/app/jobs/homework_end_update_score_job.rb +++ b/app/jobs/homework_end_update_score_job.rb @@ -16,7 +16,8 @@ class HomeworkEndUpdateScoreJob < ApplicationJob student_works = homework.student_works.where(user_id: user_ids) end - myshixuns = Myshixun.where(shixun_id: params[:shixun_id], user_id: user_ids). + shixun_id = homework.homework_commons_shixun.try(:shixun_id) + myshixuns = Myshixun.where(shixun_id: shixun_id, user_id: user_ids). includes(:games).where(games: {challenge_id: homework.homework_challenge_settings.pluck(:challenge_id)}) challenge_settings = homework.homework_challenge_settings myshixuns.find_each(batch_size: 100) do |myshixun| diff --git a/app/jobs/poll_publish_notify_job.rb b/app/jobs/poll_publish_notify_job.rb index 89fb45ea5..52660abd1 100644 --- a/app/jobs/poll_publish_notify_job.rb +++ b/app/jobs/poll_publish_notify_job.rb @@ -31,7 +31,7 @@ class PollPublishNotifyJob < ApplicationJob Tiding.bulk_insert(*attrs) do |worker| teacher_ids = teachers.pluck(:user_id) unless poll.tidings.exists?(parent_container_type: 'PollPublish', user_id: teacher_ids) - teacher_ids.find_each do |user_id| + teacher_ids.each do |user_id| worker.add same_attrs.merge(user_id: user_id) end end From 9fb26f8ff5627a9096272fa8f91ea19266d11e3a Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 4 Jul 2019 09:50:10 +0800 Subject: [PATCH 0583/1015] poll export test --- app/controllers/polls_controller.rb | 2 +- app/helpers/polls_helper.rb | 13 +++++++++++++ app/views/polls/commit_result.xlsx.axlsx | 11 +++++++---- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 244cdf57f..0dfa4b1b8 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -920,7 +920,7 @@ class PollsController < ApplicationController def commit_result ActiveRecord::Base.transaction do begin - @poll_users = @poll.poll_users + @poll_users = @poll.all_poll_users(current_user.id) @poll_commit_ids = @poll_users.commit_by_status(1).pluck(:user_id) #问卷提交用户的id @page = params[:page] || 1 @limit = params[:limit] || 10 diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index d9b6ccee7..1892f3fa2 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -127,4 +127,17 @@ module PollsHelper "login":user.login } end + + def poll_commit_result(poll,poll_questions,poll_users,poll_commit_ids) + poll_users_info = %w(序号) + poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?} + poll_un_anony = poll.un_anonymous + if poll_un_anony #是否匿名,默认为false + user_info = %w(登陆名 真实姓名 邮箱 学号) + else + user_info = [] + end + poll_users_info = poll_users_info + user_info + poll_ques_titles + + end end diff --git a/app/views/polls/commit_result.xlsx.axlsx b/app/views/polls/commit_result.xlsx.axlsx index aa7943d2a..71585dae9 100644 --- a/app/views/polls/commit_result.xlsx.axlsx +++ b/app/views/polls/commit_result.xlsx.axlsx @@ -8,7 +8,10 @@ wb.styles do |s| wb.add_worksheet(:name => "统计结果") do |sheet| sheet.sheet_view.show_grid_lines = false poll_users_info = %w(序号) + Rails.logger.info("#############_______________poll_questions.pluck(:question_title)_______####################{poll_questions.pluck(:question_title)}") + poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?} + Rails.logger.info("#############_______________poll_ques_titles_______####################{poll_ques_titles}") poll_un_anony = poll.un_anonymous if poll_un_anony #是否匿名,默认为false user_info = %w(登陆名 真实姓名 邮箱 学号) @@ -18,13 +21,13 @@ wb.styles do |s| poll_users_info = poll_users_info + user_info + poll_ques_titles poll_questions.each do |q| if q.question_type != 3 #问题不为主观题 - question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids).count #该问题的有效填写量 + question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids).size #该问题的有效填写量 sheet_row = ["第#{q.question_number}题"] #选择题答案选项的数组 sheet_answer_row = ["小计"] #选择题回答的答案人数,数组 sheet_answer_percent = ["比例"] sheet_answer_useful = ["有效填写人次",question_vote_user] q.poll_answers.each do |a| #问卷的答案选项 - answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids).count + answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids).size answer_percent = number_to_percentage((answer_users_count.to_f / question_vote_user.to_f)*100,precision:1) sheet_row.push(a.answer_text) sheet_answer_row.push(answer_users_count) @@ -41,8 +44,8 @@ wb.styles do |s| else #主观题答案 main_show_row = ["第#{q.question_number}题",q.question_title] sheet.add_row main_show_row,:height =>15, :style => blue_cell - q.poll_votes.each do |v| #主观题的答案 - sheet.add_row ["",v.vote_text.present? ? v.vote_text : "--"],:height =>15, :style => sz_all + q.poll_votes.each_with_index do |v,index| #主观题的答案 + sheet.add_row [(index+1),v.vote_text.present? ? v.vote_text : "--"],:height =>15, :style => sz_all end sheet.add_row [], :style => sz_all end From b84954dbd21c02b8b7c21c2a6fa1e905061800fb Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 4 Jul 2019 10:06:51 +0800 Subject: [PATCH 0584/1015] =?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/views/homework_commons/_student_btn_check.json.jbuilder | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/homework_commons/_student_btn_check.json.jbuilder b/app/views/homework_commons/_student_btn_check.json.jbuilder index efa89203d..7b34622fa 100644 --- a/app/views/homework_commons/_student_btn_check.json.jbuilder +++ b/app/views/homework_commons/_student_btn_check.json.jbuilder @@ -1,6 +1,8 @@ if identity == Course::STUDENT if homework.homework_type == "practice" - json.task_operation task_operation_url(work.try(:myshixun), homework.shixuns.take) + shixun = homework.shixuns.take + myshixun = work.try(:myshixun) ? work.myshixun : shixun.myshixuns.find_by(user_id: work.user_id) + json.task_operation task_operation_url(myshixun, shixun) json.view_report work.work_status > 0 json.commit_des commit_des_status(work, homework) else From 6932dc7127a7c946e1e0e044b4247bd2adce1d13 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 10:12:31 +0800 Subject: [PATCH 0585/1015] =?UTF-8?q?=20=E5=85=81=E8=AE=B8=E8=B7=B3?= =?UTF-8?q?=E5=85=B3=E7=9A=84=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 9 +++++++-- app/models/challenge.rb | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 1c6476a34..0a7a4fece 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -524,8 +524,13 @@ class ShixunsController < ApplicationController # 如果存在实训,则直接进入实训 # 如果实训允许跳关,传参params[:challenge_id]跳入具体的关卡 @current_task = - if params[:challenge_id] && @shixun.task_pass - games.where(challenge_id: params[:challenge_id]).take + if params[:challenge_id] + game = games.where(challenge_id: params[:challenge_id]).take + if game.status == 3 && !@shixun.task_pass + tip_show_exception(-4, "关卡还未开启") + else + game + end else current_myshixun.current_task(games) end diff --git a/app/models/challenge.rb b/app/models/challenge.rb index e7a382a51..ac031c31c 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -76,8 +76,9 @@ class Challenge < ApplicationRecord ## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成 def user_tpi_status user_id # todo: 以前没加索引导致相同关卡,同一用户有多个games - game = games.last - + # 允许跳关则直接开启 + return 1 if shixun.task_pass + game = games.where(user_id: user_id).take if game.blank? self.position == 1 ? 1 : 0 elsif game.status == 2 From 0cd20c6b62728728678b0c77a1c49704bd7be1b2 Mon Sep 17 00:00:00 2001 From: jasder Date: Thu, 4 Jul 2019 10:13:53 +0800 Subject: [PATCH 0586/1015] FIX update files publish count --- app/controllers/files_controller.rb | 4 ++-- app/views/files/index.json.jbuilder | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index 05a9ab841..b75020643 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -23,8 +23,8 @@ class FilesController < ApplicationController get_category(@course, course_second_category_id) @total_count = @attachments.size - @public_count = @attachments.publiced.size - @private_count = @total_count - @public_count + @publish_count = @attachments.published.size + @unpublish_count = @total_count - @publish_count @attachments = @attachments.by_keywords(params[:search]) @attachments = diff --git a/app/views/files/index.json.jbuilder b/app/views/files/index.json.jbuilder index 03b4d4892..81fa406dd 100644 --- a/app/views/files/index.json.jbuilder +++ b/app/views/files/index.json.jbuilder @@ -3,8 +3,8 @@ json.data do json.id @category_id json.name @category_name json.total_count @total_count - json.public_count @public_count - json.private_count @private_count + json.publish_count @publish_count + json.unpublish_count @unpublish_count json.course_is_public @course.is_public? json.files do json.array! @attachments do |attachment| From e868f9eba134b6fcfe1eff73d2a8d0ac84db7c8b Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 10:24:18 +0800 Subject: [PATCH 0587/1015] =?UTF-8?q?=E5=85=81=E8=AE=B8=E8=B7=B3=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 0a7a4fece..b3b3023a8 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -526,10 +526,10 @@ class ShixunsController < ApplicationController @current_task = if params[:challenge_id] game = games.where(challenge_id: params[:challenge_id]).take - if game.status == 3 && !@shixun.task_pass - tip_show_exception(-4, "关卡还未开启") - else + if @shixun.task_pass || game.status != 3 game + else + current_myshixun.current_task(games) end else current_myshixun.current_task(games) From 394efe9bf58504b5defb2c6b964fc025dd325cb9 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 10:31:07 +0800 Subject: [PATCH 0588/1015] =?UTF-8?q?=E6=8C=91=E6=88=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 3abc71fd0..f0e64bc67 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -17,7 +17,7 @@ class MyshixunsController < ApplicationController # 强制重置实训 # 前段需要按照操作过程提示 def reset_my_game - unless current_user.admin? + unless (current_user.admin? || current_user.id == @myshixun.user_id) tip_exception("403", "") end From 82a3a5aecd1fea4edc19cef9bcd6df2d1844b53c Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 4 Jul 2019 10:59:40 +0800 Subject: [PATCH 0589/1015] =?UTF-8?q?job=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/graduation_task_publish_notify_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/graduation_task_publish_notify_job.rb b/app/jobs/graduation_task_publish_notify_job.rb index 16f5893ae..84049fe90 100644 --- a/app/jobs/graduation_task_publish_notify_job.rb +++ b/app/jobs/graduation_task_publish_notify_job.rb @@ -20,7 +20,7 @@ class GraduationTaskPublishNotifyJob < ApplicationJob viewed: 0, tiding_type: 'GraduationTask' } Tiding.bulk_insert(*attrs) do |worker| - course.course_members.pluck(:user_id).uniq.find_each do |user_id| + course.course_members.pluck(:user_id).uniq.each do |user_id| worker.add same_attrs.merge(user_id: user_id) end end From 1679cfc6b5030663a0340adf2981ce026da9031c Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 11:12:41 +0800 Subject: [PATCH 0590/1015] =?UTF-8?q?=E6=92=A4=E9=94=80=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index b3b3023a8..ae75a9a0a 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -742,8 +742,8 @@ class ShixunsController < ApplicationController if apply && apply.status == 0 apply.update_attribute(:status, 3) apply.tidings.destroy_all - @shixun.update_column('status', 0) end + @shixun.update_column('status', 0) end private From 82c0318861cbcc40efda9b6abb0c797101a63b87 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 11:14:29 +0800 Subject: [PATCH 0591/1015] =?UTF-8?q?=E6=92=A4=E9=94=80=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index ae75a9a0a..b8a5ec53c 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -743,7 +743,7 @@ class ShixunsController < ApplicationController apply.update_attribute(:status, 3) apply.tidings.destroy_all end - @shixun.update_column('status', 0) + @shixun.update_column(:status, 0) end private From 977a966706f1c32c0db263f0a632cecc03d85f70 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 11:38:18 +0800 Subject: [PATCH 0592/1015] =?UTF-8?q?=E5=BC=80=E5=90=AF=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E6=9C=89=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 +- app/models/challenge.rb | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 7e7b6e082..56c1d9347 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -454,7 +454,7 @@ class GamesController < ApplicationController begin @content = git_fle_content(@myshixun.repo_path, path) || "" rescue - if params[:retry].present? + if params[:retry].to_i == 1 begin begin # 检测TPM对应的路径代码是否正常 diff --git a/app/models/challenge.rb b/app/models/challenge.rb index ac031c31c..6dd93dcc0 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -77,14 +77,17 @@ class Challenge < ApplicationRecord def user_tpi_status user_id # todo: 以前没加索引导致相同关卡,同一用户有多个games # 允许跳关则直接开启 - return 1 if shixun.task_pass game = games.where(user_id: user_id).take if game.blank? self.position == 1 ? 1 : 0 elsif game.status == 2 2 else - 1 + if shixun.task_pass + 1 + else + 0 + end end end From 5321c98037f184bda9672f71b161d054f54f7c04 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 4 Jul 2019 11:38:34 +0800 Subject: [PATCH 0593/1015] poll export youhua --- app/controllers/polls_controller.rb | 123 +++++++++++++-- app/helpers/polls_helper.rb | 12 -- app/views/polls/commit_result.xlsx.axlsx | 191 ++++++++++++++--------- 3 files changed, 228 insertions(+), 98 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 0dfa4b1b8..1a6981d9f 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -924,7 +924,8 @@ class PollsController < ApplicationController @poll_commit_ids = @poll_users.commit_by_status(1).pluck(:user_id) #问卷提交用户的id @page = params[:page] || 1 @limit = params[:limit] || 10 - @poll_export_questions = @poll_questions.order("question_number ASC") + @poll_export_questions = @poll_questions + logger.info("################____________________#{@poll_questions.pluck(:id)}") @poll_questions = @poll_questions.page(@page).per(@limit) if params[:format] == "xlsx" @@ -936,11 +937,14 @@ class PollsController < ApplicationController respond_to do |format| format.xlsx{ polls_export_name = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - render xlsx: "#{polls_export_name.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: { - poll_questions:@poll_export_questions, - poll:@poll, - poll_users: @poll_users, - poll_commit_ids:@poll_commit_ids} + polls_user_commit = poll_commit_result(@poll,@poll_export_questions,@poll_users,@poll_commit_ids) + render xlsx: "#{polls_export_name.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: {polls_user_commit:polls_user_commit} + + # render xlsx: "#{polls_export_name.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: { + # poll_questions:@poll_export_questions, + # poll:@poll, + # poll_users: @poll_users, + # poll_commit_ids:@poll_commit_ids} } end end @@ -1153,11 +1157,12 @@ class PollsController < ApplicationController end def get_questions_count - @poll_questions = @poll.poll_questions&.includes(:poll_answers,:poll_votes).order("question_number ASC") + @poll_questions = @poll.poll_questions.order("question_number ASC") @poll_questions_count = @poll_questions.size # 全部的题目数 - @poll_question_singles = @poll_questions.ques_count(1).all.size # 单选题 - @poll_question_doubles = @poll_questions.ques_count(2).all.size # 多选题 - @poll_question_mains = @poll_questions.ques_count(3).all.size #主观题 + @poll_question_singles = @poll_questions.ques_count(1).size # 单选题 + @poll_question_doubles = @poll_questions.ques_count(2).size # 多选题 + @poll_question_mains = @poll_questions.ques_count(3).size #主观题 + @poll_questions = @poll_questions&.includes(:poll_answers,:poll_votes).distinct end def check_poll_question_complete #commit_poll 的权限 @@ -1301,4 +1306,102 @@ class PollsController < ApplicationController end end + #问卷的统计结果的导出 + def poll_commit_result(poll,poll_questions,poll_users,poll_commit_ids) + obj_commit = [] + sub_commit = [] + user_commit = [] + poll_users_info = %w(序号) + poll_ques_titles = poll_questions.pluck(:question_title).map {|k| k.strip if k.present?} + poll_un_anony = poll.un_anonymous + if poll_un_anony #是否匿名,默认为false + user_info = %w(登陆名 真实姓名 邮箱 学号) + else + user_info = [] + end + poll_users_info = poll_users_info + user_info + poll_ques_titles + poll_questions.each do |q| + if q.question_type != 3 #问题不为主观题 + question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids).size #该问题的有效填写量 + sheet_row = ["第#{q.question_number}题"] #选择题答案选项的数组 + sheet_answer_row = ["小计"] #选择题回答的答案人数,数组 + sheet_answer_percent = ["比例"] + sheet_answer_useful = ["有效填写人次",question_vote_user] + q.poll_answers.each do |a| #问卷的答案选项 + answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids).size + answer_percent = (question_vote_user == 0) ? "0.0%" : "#{((answer_users_count / question_vote_user.to_f)*100).round(1).to_s}%" + sheet_row.push(a.answer_text) + sheet_answer_row.push(answer_users_count) + sheet_answer_percent.push(answer_percent) + end + sheet_obj_commit = { + sheet_row:sheet_row, + sheet_answer_row:sheet_answer_row, + sheet_answer_percent:sheet_answer_percent, + sheet_answer_useful:sheet_answer_useful + } + obj_commit.push(sheet_obj_commit) + else #主观题答案 + user_votes= [] + main_show_row = ["第#{q.question_number}题", q.question_title] + q.poll_votes.each_with_index do |v,index| #主观题的答案 + q_poll_vote = [(index+1),v.vote_text.present? ? v.vote_text : "--"] + user_votes.push(q_poll_vote) + end + sheet_sub_commit = { + sub_title: main_show_row, + sub_user_votes:user_votes + } + sub_commit.push(sheet_sub_commit) + end + end #each_with_index + + poll_users.includes(user: :user_extension).each_with_index do |u,index| + u_user = u.user + user_answer_array = [] + poll_questions.each do |q| + user_poll_votes = u_user.poll_votes.find_current_vote("poll_question_id",q.id) + if user_poll_votes.present? + user_poll_answer_ids = user_poll_votes.pluck(:poll_answer_id).reject(&:blank?) + user_poll_vote_texts = user_poll_votes.pluck(:vote_text).reject(&:blank?) + if user_poll_answer_ids.count > 0 + answer_content = q.poll_answers.find_answer_by_custom("id",user_poll_answer_ids) + if user_poll_answer_ids.count >1 + u_answer = answer_content.pluck(:answer_text).join(";") + else + u_answer = answer_content.first.answer_text + end + elsif user_poll_vote_texts.count > 0 + if user_poll_vote_texts.count > 1 + u_answer = user_poll_vote_texts.join(";") + else + u_answer = user_poll_vote_texts.first + end + else + u_answer = "--" + end + else + u_answer = "--" + end + user_answer_array.push(u_answer) + end + user_cell = [index+1] + if poll_un_anony + user_login = u_user.login + user_name = u_user.real_name.present? ? u_user.real_name : "--" + user_student_id = u_user.student_id.present? ? u_user.student_id : "--" + user_cell += [user_login,user_name, u_user.mail, user_student_id] + end + all_user_cell = user_cell + user_answer_array + user_commit.push(all_user_cell) + end + + { + obj_commit:obj_commit, + poll_users_info:poll_users_info, + sub_commit:sub_commit, + user_commit:user_commit + } + end + end diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index 1892f3fa2..693149e8f 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -128,16 +128,4 @@ module PollsHelper } end - def poll_commit_result(poll,poll_questions,poll_users,poll_commit_ids) - poll_users_info = %w(序号) - poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?} - poll_un_anony = poll.un_anonymous - if poll_un_anony #是否匿名,默认为false - user_info = %w(登陆名 真实姓名 邮箱 学号) - else - user_info = [] - end - poll_users_info = poll_users_info + user_info + poll_ques_titles - - end end diff --git a/app/views/polls/commit_result.xlsx.axlsx b/app/views/polls/commit_result.xlsx.axlsx index 71585dae9..975668bfe 100644 --- a/app/views/polls/commit_result.xlsx.axlsx +++ b/app/views/polls/commit_result.xlsx.axlsx @@ -7,91 +7,130 @@ wb.styles do |s| wb.add_worksheet(:name => "统计结果") do |sheet| sheet.sheet_view.show_grid_lines = false - poll_users_info = %w(序号) - Rails.logger.info("#############_______________poll_questions.pluck(:question_title)_______####################{poll_questions.pluck(:question_title)}") + obj_commit = polls_user_commit[:obj_commit] + sub_commit = polls_user_commit[:sub_commit] + poll_user_info = polls_user_commit[:poll_users_info] + user_commit = polls_user_commit[:user_commit] - poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?} - Rails.logger.info("#############_______________poll_ques_titles_______####################{poll_ques_titles}") - poll_un_anony = poll.un_anonymous - if poll_un_anony #是否匿名,默认为false - user_info = %w(登陆名 真实姓名 邮箱 学号) - else - user_info = [] - end - poll_users_info = poll_users_info + user_info + poll_ques_titles - poll_questions.each do |q| - if q.question_type != 3 #问题不为主观题 - question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids).size #该问题的有效填写量 - sheet_row = ["第#{q.question_number}题"] #选择题答案选项的数组 - sheet_answer_row = ["小计"] #选择题回答的答案人数,数组 - sheet_answer_percent = ["比例"] - sheet_answer_useful = ["有效填写人次",question_vote_user] - q.poll_answers.each do |a| #问卷的答案选项 - answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids).size - answer_percent = number_to_percentage((answer_users_count.to_f / question_vote_user.to_f)*100,precision:1) - sheet_row.push(a.answer_text) - sheet_answer_row.push(answer_users_count) - sheet_answer_percent.push(answer_percent.to_s) - end - sheet.add_row sheet_row, :height =>15,:style => blue_cell - sheet.add_row sheet_answer_row, :height =>15, :style => sz_all - sheet.add_row sheet_answer_percent, :height =>15, :style => sz_all - sheet.add_row sheet_answer_useful, :height =>15, :style => sz_all - #合并单元格,但无法填充style - # sheet.merge_cells (Axlsx::cell_r(1,sheet.rows.last.row_index) + ':' + Axlsx::cell_r(sheet_row.count-1,sheet.rows.last.row_index)) - # sheet.rows[sheet.rows.last.row_index].style = sz_all + #客观题的导出 + if obj_commit.size > 0 + obj_commit.each do |obj| + sheet.add_row obj[:sheet_row], :height =>15,:style => blue_cell + sheet.add_row obj[:sheet_answer_row], :height =>15, :style => sz_all + sheet.add_row obj[:sheet_answer_percent], :height =>15, :style => sz_all + sheet.add_row obj[:sheet_answer_useful], :height =>15, :style => sz_all sheet.add_row [] - else #主观题答案 - main_show_row = ["第#{q.question_number}题",q.question_title] - sheet.add_row main_show_row,:height =>15, :style => blue_cell - q.poll_votes.each_with_index do |v,index| #主观题的答案 - sheet.add_row [(index+1),v.vote_text.present? ? v.vote_text : "--"],:height =>15, :style => sz_all - end - sheet.add_row [], :style => sz_all end - end #each_with_index + end - sheet.add_row poll_users_info, :height =>15, :style => blue_cell - poll_users.includes(user: :user_extension).each_with_index do |u,index| - u_user = u.user - user_answer_array = [] - poll_questions.each do |q| - user_poll_votes = u_user.poll_votes.find_current_vote("poll_question_id",q.id) - if user_poll_votes.present? - user_poll_answer_ids = user_poll_votes.pluck(:poll_answer_id).reject(&:blank?) - user_poll_vote_texts = user_poll_votes.pluck(:vote_text).reject(&:blank?) - if user_poll_answer_ids.count > 0 - answer_content = q.poll_answers.find_answer_by_custom("id",user_poll_answer_ids) - if user_poll_answer_ids.count >1 - u_answer = answer_content.pluck(:answer_text).join(";") - else - u_answer = answer_content.first.answer_text - end - elsif user_poll_vote_texts.count > 0 - if user_poll_vote_texts.count > 1 - u_answer = user_poll_vote_texts.join(";") - else - u_answer = user_poll_vote_texts.first - end - else - u_answer = "--" - end - else - u_answer = "--" + #主观题的导出 + if sub_commit.size > 0 + sub_commit.each do |sub| + main_sub_title = sub[:sub_tile] + main_sub_content = sub[:sub_user_votes] + sheet.add_row main_sub_title,:height =>15, :style => blue_cell + main_sub_content.each do |con| + sheet.add_row con,:height =>15, :style => sz_all end - user_answer_array.push(u_answer) + sheet.add_row [] end - user_cell = [index+1] - if poll_un_anony - user_login = u_user.login - user_name = u_user.real_name.present? ? u_user.real_name : "--" - user_student_id = u_user.student_id.present? ? u_user.student_id : "--" - user_cell += [user_login,user_name, u_user.mail, user_student_id] + end + + sheet.add_row poll_user_info, :height =>15, :style => blue_cell + + if user_commit.size > 0 + user_commit.each do |com| + sheet.add_row com, :height =>15,:style => sz_all end - all_user_cell = user_cell + user_answer_array - sheet.add_row all_user_cell, :height =>15,:style => sz_all end sheet.column_widths *([25]*sheet.column_info.count) sheet.column_info.first.width = 10 + + #答题用户的导出 + + # sheet.sheet_view.show_grid_lines = false + # poll_users_info = %w(序号) + # poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?} + # poll_un_anony = poll.un_anonymous + # if poll_un_anony #是否匿名,默认为false + # user_info = %w(登陆名 真实姓名 邮箱 学号) + # else + # user_info = [] + # end + # poll_users_info = poll_users_info + user_info + poll_ques_titles + # poll_questions.each do |q| + # if q.question_type != 3 #问题不为主观题 + # question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids).size #该问题的有效填写量 + # sheet_row = ["第#{q.question_number}题"] #选择题答案选项的数组 + # sheet_answer_row = ["小计"] #选择题回答的答案人数,数组 + # sheet_answer_percent = ["比例"] + # sheet_answer_useful = ["有效填写人次",question_vote_user] + # q.poll_answers.each do |a| #问卷的答案选项 + # answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids).size + # answer_percent = number_to_percentage((answer_users_count.to_f / question_vote_user.to_f)*100,precision:1) + # sheet_row.push(a.answer_text) + # sheet_answer_row.push(answer_users_count) + # sheet_answer_percent.push(answer_percent.to_s) + # end + # sheet.add_row sheet_row, :height =>15,:style => blue_cell + # sheet.add_row sheet_answer_row, :height =>15, :style => sz_all + # sheet.add_row sheet_answer_percent, :height =>15, :style => sz_all + # sheet.add_row sheet_answer_useful, :height =>15, :style => sz_all + # #合并单元格,但无法填充style + # # sheet.merge_cells (Axlsx::cell_r(1,sheet.rows.last.row_index) + ':' + Axlsx::cell_r(sheet_row.count-1,sheet.rows.last.row_index)) + # # sheet.rows[sheet.rows.last.row_index].style = sz_all + # sheet.add_row [] + # else #主观题答案 + # main_show_row = ["第#{q.question_number}题",q.question_title] + # sheet.add_row main_show_row,:height =>15, :style => blue_cell + # q.poll_votes.each_with_index do |v,index| #主观题的答案 + # sheet.add_row [(index+1),v.vote_text.present? ? v.vote_text : "--"],:height =>15, :style => sz_all + # end + # sheet.add_row [], :style => sz_all + # end + # end #each_with_index + # + # sheet.add_row poll_users_info, :height =>15, :style => blue_cell + # poll_users.includes(user: :user_extension).each_with_index do |u,index| + # u_user = u.user + # user_answer_array = [] + # poll_questions.each do |q| + # user_poll_votes = u_user.poll_votes.find_current_vote("poll_question_id",q.id) + # if user_poll_votes.present? + # user_poll_answer_ids = user_poll_votes.pluck(:poll_answer_id).reject(&:blank?) + # user_poll_vote_texts = user_poll_votes.pluck(:vote_text).reject(&:blank?) + # if user_poll_answer_ids.count > 0 + # answer_content = q.poll_answers.find_answer_by_custom("id",user_poll_answer_ids) + # if user_poll_answer_ids.count >1 + # u_answer = answer_content.pluck(:answer_text).join(";") + # else + # u_answer = answer_content.first.answer_text + # end + # elsif user_poll_vote_texts.count > 0 + # if user_poll_vote_texts.count > 1 + # u_answer = user_poll_vote_texts.join(";") + # else + # u_answer = user_poll_vote_texts.first + # end + # else + # u_answer = "--" + # end + # else + # u_answer = "--" + # end + # user_answer_array.push(u_answer) + # end + # user_cell = [index+1] + # if poll_un_anony + # user_login = u_user.login + # user_name = u_user.real_name.present? ? u_user.real_name : "--" + # user_student_id = u_user.student_id.present? ? u_user.student_id : "--" + # user_cell += [user_login,user_name, u_user.mail, user_student_id] + # end + # all_user_cell = user_cell + user_answer_array + # sheet.add_row all_user_cell, :height =>15,:style => sz_all + # end + # sheet.column_widths *([25]*sheet.column_info.count) + # sheet.column_info.first.width = 10 end #add_worksheet end \ No newline at end of file From 427a437e99e68fe5b76061d7ac9a9ee4a62d881e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 4 Jul 2019 12:14:09 +0800 Subject: [PATCH 0594/1015] fix bug --- app/controllers/polls_controller.rb | 7 ------- app/views/polls/commit_result.xlsx.axlsx | 14 +++++++------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 1a6981d9f..e6ada3098 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -925,7 +925,6 @@ class PollsController < ApplicationController @page = params[:page] || 1 @limit = params[:limit] || 10 @poll_export_questions = @poll_questions - logger.info("################____________________#{@poll_questions.pluck(:id)}") @poll_questions = @poll_questions.page(@page).per(@limit) if params[:format] == "xlsx" @@ -939,12 +938,6 @@ class PollsController < ApplicationController polls_export_name = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" polls_user_commit = poll_commit_result(@poll,@poll_export_questions,@poll_users,@poll_commit_ids) render xlsx: "#{polls_export_name.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: {polls_user_commit:polls_user_commit} - - # render xlsx: "#{polls_export_name.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: { - # poll_questions:@poll_export_questions, - # poll:@poll, - # poll_users: @poll_users, - # poll_commit_ids:@poll_commit_ids} } end end diff --git a/app/views/polls/commit_result.xlsx.axlsx b/app/views/polls/commit_result.xlsx.axlsx index 975668bfe..016c6e34c 100644 --- a/app/views/polls/commit_result.xlsx.axlsx +++ b/app/views/polls/commit_result.xlsx.axlsx @@ -7,13 +7,13 @@ wb.styles do |s| wb.add_worksheet(:name => "统计结果") do |sheet| sheet.sheet_view.show_grid_lines = false - obj_commit = polls_user_commit[:obj_commit] - sub_commit = polls_user_commit[:sub_commit] - poll_user_info = polls_user_commit[:poll_users_info] - user_commit = polls_user_commit[:user_commit] + obj_commit = polls_user_commit[:obj_commit] || [] + sub_commit = polls_user_commit[:sub_commit] || [] + poll_user_info = polls_user_commit[:poll_users_info] || [] + user_commit = polls_user_commit[:user_commit] || [] #客观题的导出 - if obj_commit.size > 0 + if obj_commit&.size > 0 obj_commit.each do |obj| sheet.add_row obj[:sheet_row], :height =>15,:style => blue_cell sheet.add_row obj[:sheet_answer_row], :height =>15, :style => sz_all @@ -24,7 +24,7 @@ wb.styles do |s| end #主观题的导出 - if sub_commit.size > 0 + if sub_commit&.size > 0 sub_commit.each do |sub| main_sub_title = sub[:sub_tile] main_sub_content = sub[:sub_user_votes] @@ -38,7 +38,7 @@ wb.styles do |s| sheet.add_row poll_user_info, :height =>15, :style => blue_cell - if user_commit.size > 0 + if user_commit&.size > 0 user_commit.each do |com| sheet.add_row com, :height =>15,:style => sz_all end From bebbbe099d678e3486cc9084103b6355576a7139 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 13:45:22 +0800 Subject: [PATCH 0595/1015] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9F=A5=E9=87=8D?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/homework_commons/group_list.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/homework_commons/group_list.json.jbuilder b/app/views/homework_commons/group_list.json.jbuilder index 1be1cdab6..dcc04e761 100644 --- a/app/views/homework_commons/group_list.json.jbuilder +++ b/app/views/homework_commons/group_list.json.jbuilder @@ -7,7 +7,7 @@ json.group_list do end end # 未分班展示情况放在最后 -if @course_groups.count > 0 && @course_groups.count < @limit.to_i +if @course_groups.count < @limit.to_i json.ungroup_list do json.id 0 json.name "未分班" From 17eaebc75a5d34dc759f346a8376b3712768037f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 13:55:56 +0800 Subject: [PATCH 0596/1015] =?UTF-8?q?=E5=8D=A1=E5=85=B6=E5=AE=9E=E8=AE=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/challenge.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 6dd93dcc0..a4fd71830 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -79,14 +79,14 @@ class Challenge < ApplicationRecord # 允许跳关则直接开启 game = games.where(user_id: user_id).take if game.blank? - self.position == 1 ? 1 : 0 - elsif game.status == 2 - 2 + position == 1 ? 1 : 0 else - if shixun.task_pass - 1 + if game.status == 3 + shixun.task_pass ? 1 : 0 + elsif game.status == 2 + 2 else - 0 + 1 end end end From 77ebf88fde7db138e3a709f2ae6e72f3448f6a42 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 14:01:24 +0800 Subject: [PATCH 0597/1015] =?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/models/challenge.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/challenge.rb b/app/models/challenge.rb index a4fd71830..cc0f68efb 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -78,6 +78,8 @@ class Challenge < ApplicationRecord # todo: 以前没加索引导致相同关卡,同一用户有多个games # 允许跳关则直接开启 game = games.where(user_id: user_id).take + logger.info("########---game_status: #{game.status}") + logger.info("########---challenge_id: #{id}") if game.blank? position == 1 ? 1 : 0 else From aa76382c5e67bada312767e6cc3155df4f17308f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 14:05:13 +0800 Subject: [PATCH 0598/1015] =?UTF-8?q?=E5=85=81=E8=AE=B8=E8=B7=B3=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/myshixun.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/myshixun.rb b/app/models/myshixun.rb index 31cc53200..a4f05f2ce 100644 --- a/app/models/myshixun.rb +++ b/app/models/myshixun.rb @@ -56,7 +56,7 @@ class Myshixun < ApplicationRecord # status:0 可以测评的; 1 正在测评的; 2评测通过的; 3未开启的 # 如果都完成,则当前任务为最后一个任务 def current_task games - current_game = games.select{|game| game.status == 1 || game.status == 0}.first + current_game = games.select{|game| game.status == 1 || game.status == 0}.last if current_game.blank? current_game = games.last end From af00e24ce460afba3204514c672d55ec94d1f6c5 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 4 Jul 2019 14:07:59 +0800 Subject: [PATCH 0599/1015] =?UTF-8?q?=E4=BD=9C=E5=93=81=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/homework_commons/works_list.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/homework_commons/works_list.json.jbuilder b/app/views/homework_commons/works_list.json.jbuilder index a7dc292b8..458db9621 100644 --- a/app/views/homework_commons/works_list.json.jbuilder +++ b/app/views/homework_commons/works_list.json.jbuilder @@ -13,6 +13,7 @@ json.ta_mode @homework_detail_manual.ta_mode json.is_evaluation @is_evaluation ? @is_evaluation : false json.work_public @homework.work_public +json.allow_late @homework.allow_late if @user_course_identity < Course::STUDENT From 65f82eda89b7b9a61a645a090f6d1bea9b9d5e7a Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 4 Jul 2019 14:29:26 +0800 Subject: [PATCH 0600/1015] use apply realname auth && apply professional auth api --- .../users/auth_attachments_controller.rb | 39 ++++++++++++ .../authentication_applies_controller.rb | 16 +++++ .../professional_auth_applies_controller.rb | 16 +++++ app/forms/users/apply_authentication_form.rb | 8 +++ .../users/apply_professional_auth_form.rb | 10 +++ app/helpers/application_helper.rb | 12 ++++ app/models/user_extension.rb | 2 +- .../users/apply_authentication_service.rb | 52 ++++++++++++++++ .../users/apply_professional_auth_service.rb | 62 +++++++++++++++++++ .../forms/apply_authentication_form.zh-CN.yml | 7 +++ .../apply_professional_auth_form.zh-CN.yml | 9 +++ config/routes.rb | 3 + lib/educoder/sms.rb | 2 +- 13 files changed, 236 insertions(+), 2 deletions(-) create mode 100644 app/controllers/users/auth_attachments_controller.rb create mode 100644 app/controllers/users/authentication_applies_controller.rb create mode 100644 app/controllers/users/professional_auth_applies_controller.rb create mode 100644 app/forms/users/apply_authentication_form.rb create mode 100644 app/forms/users/apply_professional_auth_form.rb create mode 100644 app/services/users/apply_authentication_service.rb create mode 100644 app/services/users/apply_professional_auth_service.rb create mode 100644 config/locales/forms/apply_authentication_form.zh-CN.yml create mode 100644 config/locales/forms/apply_professional_auth_form.zh-CN.yml diff --git a/app/controllers/users/auth_attachments_controller.rb b/app/controllers/users/auth_attachments_controller.rb new file mode 100644 index 000000000..86c3e70ef --- /dev/null +++ b/app/controllers/users/auth_attachments_controller.rb @@ -0,0 +1,39 @@ +class Users::AuthAttachmentsController < Users::BaseAccountController + before_action :private_user_resources! + before_action :convert_image!, only: [:update] + + def update + image_temp_path = auth_image_path + 'temp' # 上传文件保存至临时文件,提交申请时再移到正常目录 + + File.delete(image_temp_path) if File.exist?(image_temp_path) # 删除之前的临时文件 + + Util.write_file(@image, image_temp_path) + + render_ok + rescue StandardError => ex + logger_error(ex) + render_error('上传失败') + end + + private + + def convert_image! + max_size = EduSetting.get('upload_avatar_max_size') || 10 * 1024 * 1024 # 10M + if params[:image].class == ActionDispatch::Http::UploadedFile + @image = params[:image] + render_error('请上传文件') if @image.size.zero? + render_error('文件大小超过限制') if @image.size > max_size + else + image = params[:image].to_s.strip + return render_error('请上传正确的图片') if image.blank? + @image = Util.convert_base64_image(image, max_size: max_size) + end + rescue Base64ImageConverter::Error => ex + render_error(ex.message) + end + + def auth_image_path + url_method = params[:type] == 'professional' ? :disk_professional_auth_filename : :disk_real_name_auth_filename + ApplicationController.helpers.send(url_method, observed_user.id) + end +end \ No newline at end of file diff --git a/app/controllers/users/authentication_applies_controller.rb b/app/controllers/users/authentication_applies_controller.rb new file mode 100644 index 000000000..d406b33d3 --- /dev/null +++ b/app/controllers/users/authentication_applies_controller.rb @@ -0,0 +1,16 @@ +class Users::AuthenticationAppliesController < Users::BaseAccountController + before_action :private_user_resources! + + def create + Users::ApplyAuthenticationService.call(observed_user, create_params) + render_ok + rescue Users::ApplyAuthenticationService::Error => ex + render_error(ex.message) + end + + private + + def create_params + params.permit(:name, :id_number, :upload_image) + end +end \ No newline at end of file diff --git a/app/controllers/users/professional_auth_applies_controller.rb b/app/controllers/users/professional_auth_applies_controller.rb new file mode 100644 index 000000000..b2603f642 --- /dev/null +++ b/app/controllers/users/professional_auth_applies_controller.rb @@ -0,0 +1,16 @@ +class Users::ProfessionalAuthAppliesController < Users::BaseAccountController + before_action :private_user_resources! + + def create + Users::ApplyProfessionalAuthService.call(observed_user, create_params) + render_ok + rescue Users::ApplyProfessionalAuthService::Error => ex + render_error(ex.message) + end + + private + + def create_params + params.permit(:school_id, :department_id, :identity, :extra, :upload_image) + end +end \ No newline at end of file diff --git a/app/forms/users/apply_authentication_form.rb b/app/forms/users/apply_authentication_form.rb new file mode 100644 index 000000000..986ba6223 --- /dev/null +++ b/app/forms/users/apply_authentication_form.rb @@ -0,0 +1,8 @@ +class Users::ApplyAuthenticationForm + include ActiveModel::Model + + attr_accessor :name, :id_number, :upload_image + + validates :name, presence: true + validates :id_number, presence: true +end \ No newline at end of file diff --git a/app/forms/users/apply_professional_auth_form.rb b/app/forms/users/apply_professional_auth_form.rb new file mode 100644 index 000000000..c5de9700c --- /dev/null +++ b/app/forms/users/apply_professional_auth_form.rb @@ -0,0 +1,10 @@ +class Users::ApplyProfessionalAuthForm + include ActiveModel::Model + + attr_accessor :school_id, :department_id, :identity, :extra, :upload_image + + validates :school_id, presence: true, numericality: { only_integer: true, greater_than: 0 } + validates :department_id, numericality: { only_integer: true, greater_than: 0 }, allow_blank: true + validates :identity, presence: true, inclusion: { in: %w(student teacher professional) } + validates :extra, presence: true +end \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index fd72b5651..cdd647ebd 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -145,6 +145,18 @@ module ApplicationHelper File.join(storage_path, "#{source_type}", "#{source_id}") end + def disk_auth_filename(source_type, source_id, type) + File.join(storage_path, "#{source_type}", "#{source_id}#{type}") + end + + def disk_real_name_auth_filename(source_id) + disk_auth_filename('UserAuthentication', source_id, 'ID') + end + + def disk_professional_auth_filename(source_id) + disk_auth_filename('UserAuthentication', source_id, 'PRO') + end + def shixun_url_to_avatar(shixun) if File.exist?(disk_filename(shixun.class, shixun.id)) File.join("images/#{relative_path}", "#{shixun.class}", "#{shixun.id}") diff --git a/app/models/user_extension.rb b/app/models/user_extension.rb index 3d8457ce3..49fca7c71 100644 --- a/app/models/user_extension.rb +++ b/app/models/user_extension.rb @@ -4,7 +4,7 @@ class UserExtension < ApplicationRecord belongs_to :user belongs_to :school - belongs_to :department + belongs_to :department, optional: true def identity_text I18n.t("user.identity.#{identity}") diff --git a/app/services/users/apply_authentication_service.rb b/app/services/users/apply_authentication_service.rb new file mode 100644 index 000000000..f31bb335c --- /dev/null +++ b/app/services/users/apply_authentication_service.rb @@ -0,0 +1,52 @@ +class Users::ApplyAuthenticationService < ApplicationService + Error = Class.new(StandardError) + + attr_reader :user, :params + + def initialize(user, params) + @user = user + @params = params + end + + def call + Users::ApplyAuthenticationForm.new(params).validate! + raise Error, '您已经申请过实名认证了' if ApplyUserAuthentication.real_name_auth.processing.exists?(user_id: user.id) + + user.lastname = params[:name].to_s.strip + user.firstname = '' + user.ID_number = params[:id_number].to_s.strip.presence + + ActiveRecord::Base.transaction do + user.authentication = false + user.save! + + user.apply_user_authentication.create!(auth_type: 1, status: 0) + + move_image_file! unless params[:upload_image].to_s == 'false' + + sms_notify_admin + end + + user + end + + private + + def move_image_file! + image_url = ApplicationController.helpers.disk_real_name_auth_filename(user.id) + temp_image_url = image_url + 'temp' + + FileUtils.mv(temp_image_url, image_url, force: true) if File.exist?(temp_image_url) + rescue RuntimeError => ex + Util.logger_error(ex) + raise Error, '申请失败' + ensure + File.delete(temp_image_url) if File.exist?(temp_image_url) + end + + def sms_notify_admin + Educoder::Sms.notify_admin(send_type: 'apply_auth') + rescue => ex + Util.logger_error(ex) + end +end \ No newline at end of file diff --git a/app/services/users/apply_professional_auth_service.rb b/app/services/users/apply_professional_auth_service.rb new file mode 100644 index 000000000..2d8279317 --- /dev/null +++ b/app/services/users/apply_professional_auth_service.rb @@ -0,0 +1,62 @@ +class Users::ApplyProfessionalAuthService < ApplicationService + Error = Class.new(StandardError) + + attr_reader :user, :params + + def initialize(user, params) + @user = user + @params = params + end + + def call + Users::ApplyProfessionalAuthForm.new(params).validate! + raise Error, '您已经申请过职业认证了' if ApplyUserAuthentication.professional_auth.processing.exists?(user_id: user.id) + + user.professional_certification = false + + extension = user.user_extension + extension.school_id = params[:school_id] + extension.department_id = params[:department_id] + extension.identity = params[:identity] + + extra = params[:extra].to_s.strip.presence + if extension.identity.to_s == 'student' + extension.technical_title = nil + extension.student_id = extra + else + extension.technical_title = extra + extension.student_id = nil + end + + ActiveRecord::Base.transaction do + user.save! + extension.save! + + user.apply_user_authentication.create!(auth_type: 2, status: 0) + + move_image_file! unless params[:upload_image].to_s == 'false' + + sms_notify_admin + end + end + + private + + def move_image_file! + image_url = ApplicationController.helpers.disk_professional_auth_filename(user.id) + temp_image_url = image_url + 'temp' + + FileUtils.mv(temp_image_url, image_url, force: true) if File.exist?(temp_image_url) + rescue RuntimeError => ex + Util.logger_error(ex) + raise Error, '申请失败' + ensure + File.delete(temp_image_url) if File.exist?(temp_image_url) + end + + def sms_notify_admin + Educoder::Sms.notify_admin(send_type: 'apply_pro_certification') + rescue => ex + Util.logger_error(ex) + end +end \ No newline at end of file diff --git a/config/locales/forms/apply_authentication_form.zh-CN.yml b/config/locales/forms/apply_authentication_form.zh-CN.yml new file mode 100644 index 000000000..cfc2e5b39 --- /dev/null +++ b/config/locales/forms/apply_authentication_form.zh-CN.yml @@ -0,0 +1,7 @@ +'zh-CN': + activemodel: + attributes: + users/apply_authentication_form: + name: 姓名 + id_number: 身份证号 + diff --git a/config/locales/forms/apply_professional_auth_form.zh-CN.yml b/config/locales/forms/apply_professional_auth_form.zh-CN.yml new file mode 100644 index 000000000..bbba03238 --- /dev/null +++ b/config/locales/forms/apply_professional_auth_form.zh-CN.yml @@ -0,0 +1,9 @@ +'zh-CN': + activemodel: + attributes: + users/apply_professional_auth_form: + school_id: 学校/单位 + department_id: 学院/部门 + identity: 职业 + extra: 职称/学号 + diff --git a/config/routes.rb b/config/routes.rb index 1a81f1175..e09808f6c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -74,6 +74,9 @@ Rails.application.routes.draw do resource :email_bind, only: [:create] resource :password, only: [:update] resource :avatar, only: [:update] + resource :auth_attachment, only: [:update] + resource :authentication_apply, only: [:create] + resource :professional_auth_apply, only: [:create] end end end diff --git a/lib/educoder/sms.rb b/lib/educoder/sms.rb index e79678ad3..237b270d5 100644 --- a/lib/educoder/sms.rb +++ b/lib/educoder/sms.rb @@ -21,7 +21,7 @@ module Educoder def self.notify_admin(opt) opt[:name] = '管理员' - opt[:mobile] = ENV['NOTIDY_ADMIN_PHONE'] || '17680641960' + opt[:mobile] = ENV['NOTIFY_ADMIN_PHONE'] || EduSetting.get('notify_admin_phone') || '17680641960' send(opt) end From b5ab3785d93d368e90941ac717d994e0a6aa34f8 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 4 Jul 2019 14:34:33 +0800 Subject: [PATCH 0601/1015] poll export youhua --- app/controllers/polls_controller.rb | 33 +++---- app/views/polls/commit_result.xlsx.axlsx | 117 ++--------------------- 2 files changed, 24 insertions(+), 126 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index e6ada3098..ee2b061ba 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -146,7 +146,7 @@ class PollsController < ApplicationController def edit ActiveRecord::Base.transaction do begin - @poll_questions = @poll.poll_questions.order("question_number ASC") + rescue Exception => e uid_logger_error(e.message) tip_exception("页面请求失败!") @@ -183,7 +183,7 @@ class PollsController < ApplicationController else @is_teacher_or = 0 end - @poll_questions = @poll.poll_questions&.includes(:poll_answers).order("question_number ASC") + rescue Exception => e uid_logger_error(e.message) tip_exception("没有权限") @@ -868,7 +868,6 @@ class PollsController < ApplicationController @user_poll_status = 0 #可编辑 end - # @answer_user = User.find_by(id:@poll_current_user_id) @answer_status = [] question_answered = 0 @@ -925,7 +924,6 @@ class PollsController < ApplicationController @page = params[:page] || 1 @limit = params[:limit] || 10 @poll_export_questions = @poll_questions - @poll_questions = @poll_questions.page(@page).per(@limit) if params[:format] == "xlsx" if @user_course_identity > Course::ASSISTANT_PROFESSOR @@ -1151,7 +1149,7 @@ class PollsController < ApplicationController def get_questions_count @poll_questions = @poll.poll_questions.order("question_number ASC") - @poll_questions_count = @poll_questions.size # 全部的题目数 + @poll_questions_count = @poll_questions&.size # 全部的题目数 @poll_question_singles = @poll_questions.ques_count(1).size # 单选题 @poll_question_doubles = @poll_questions.ques_count(2).size # 多选题 @poll_question_mains = @poll_questions.ques_count(3).size #主观题 @@ -1301,7 +1299,6 @@ class PollsController < ApplicationController #问卷的统计结果的导出 def poll_commit_result(poll,poll_questions,poll_users,poll_commit_ids) - obj_commit = [] sub_commit = [] user_commit = [] poll_users_info = %w(序号) @@ -1315,30 +1312,28 @@ class PollsController < ApplicationController poll_users_info = poll_users_info + user_info + poll_ques_titles poll_questions.each do |q| if q.question_type != 3 #问题不为主观题 - question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids).size #该问题的有效填写量 + question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids)&.size #该问题的有效填写量 sheet_row = ["第#{q.question_number}题"] #选择题答案选项的数组 sheet_answer_row = ["小计"] #选择题回答的答案人数,数组 sheet_answer_percent = ["比例"] - sheet_answer_useful = ["有效填写人次",question_vote_user] + sheet_answer_useful = ["本题有效填写人次",question_vote_user] q.poll_answers.each do |a| #问卷的答案选项 - answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids).size + answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids)&.size answer_percent = (question_vote_user == 0) ? "0.0%" : "#{((answer_users_count / question_vote_user.to_f)*100).round(1).to_s}%" sheet_row.push(a.answer_text) sheet_answer_row.push(answer_users_count) sheet_answer_percent.push(answer_percent) end - sheet_obj_commit = { - sheet_row:sheet_row, - sheet_answer_row:sheet_answer_row, - sheet_answer_percent:sheet_answer_percent, - sheet_answer_useful:sheet_answer_useful + sheet_sub_commit = { + sub_title: sheet_row, + sub_user_votes:[sheet_answer_row,sheet_answer_percent,sheet_answer_useful] } - obj_commit.push(sheet_obj_commit) + sub_commit.push(sheet_sub_commit) else #主观题答案 user_votes= [] - main_show_row = ["第#{q.question_number}题", q.question_title] + main_show_row = ["第#{q.question_number}题", q.question_title ] q.poll_votes.each_with_index do |v,index| #主观题的答案 - q_poll_vote = [(index+1),v.vote_text.present? ? v.vote_text : "--"] + q_poll_vote = [(index+1), v.vote_text.present? ? v.vote_text : "--"] user_votes.push(q_poll_vote) end sheet_sub_commit = { @@ -1347,9 +1342,10 @@ class PollsController < ApplicationController } sub_commit.push(sheet_sub_commit) end + end #each_with_index - poll_users.includes(user: :user_extension).each_with_index do |u,index| + poll_users.includes(user: [:user_extension,:poll_votes]).each_with_index do |u,index| u_user = u.user user_answer_array = [] poll_questions.each do |q| @@ -1390,7 +1386,6 @@ class PollsController < ApplicationController end { - obj_commit:obj_commit, poll_users_info:poll_users_info, sub_commit:sub_commit, user_commit:user_commit diff --git a/app/views/polls/commit_result.xlsx.axlsx b/app/views/polls/commit_result.xlsx.axlsx index 016c6e34c..4391e0e8f 100644 --- a/app/views/polls/commit_result.xlsx.axlsx +++ b/app/views/polls/commit_result.xlsx.axlsx @@ -7,30 +7,19 @@ wb.styles do |s| wb.add_worksheet(:name => "统计结果") do |sheet| sheet.sheet_view.show_grid_lines = false - obj_commit = polls_user_commit[:obj_commit] || [] - sub_commit = polls_user_commit[:sub_commit] || [] - poll_user_info = polls_user_commit[:poll_users_info] || [] - user_commit = polls_user_commit[:user_commit] || [] + sub_commit = polls_user_commit[:sub_commit] + poll_user_info = polls_user_commit[:poll_users_info] + user_commit = polls_user_commit[:user_commit] - #客观题的导出 - if obj_commit&.size > 0 - obj_commit.each do |obj| - sheet.add_row obj[:sheet_row], :height =>15,:style => blue_cell - sheet.add_row obj[:sheet_answer_row], :height =>15, :style => sz_all - sheet.add_row obj[:sheet_answer_percent], :height =>15, :style => sz_all - sheet.add_row obj[:sheet_answer_useful], :height =>15, :style => sz_all - sheet.add_row [] - end - end - - #主观题的导出 if sub_commit&.size > 0 sub_commit.each do |sub| - main_sub_title = sub[:sub_tile] + main_sub_title = sub[:sub_title] main_sub_content = sub[:sub_user_votes] sheet.add_row main_sub_title,:height =>15, :style => blue_cell - main_sub_content.each do |con| - sheet.add_row con,:height =>15, :style => sz_all + if main_sub_content.present? + main_sub_content.each do |con| + sheet.add_row con,:height =>15, :style => sz_all + end end sheet.add_row [] end @@ -44,93 +33,7 @@ wb.styles do |s| end end sheet.column_widths *([25]*sheet.column_info.count) - sheet.column_info.first.width = 10 - - #答题用户的导出 + sheet.column_info.first.width = 15 - # sheet.sheet_view.show_grid_lines = false - # poll_users_info = %w(序号) - # poll_ques_titles = poll_questions.pluck(:question_title).map {|k| strip_export_title(k) if k.present?} - # poll_un_anony = poll.un_anonymous - # if poll_un_anony #是否匿名,默认为false - # user_info = %w(登陆名 真实姓名 邮箱 学号) - # else - # user_info = [] - # end - # poll_users_info = poll_users_info + user_info + poll_ques_titles - # poll_questions.each do |q| - # if q.question_type != 3 #问题不为主观题 - # question_vote_user = q.poll_votes.find_current_vote("user_id",poll_commit_ids).size #该问题的有效填写量 - # sheet_row = ["第#{q.question_number}题"] #选择题答案选项的数组 - # sheet_answer_row = ["小计"] #选择题回答的答案人数,数组 - # sheet_answer_percent = ["比例"] - # sheet_answer_useful = ["有效填写人次",question_vote_user] - # q.poll_answers.each do |a| #问卷的答案选项 - # answer_users_count = a.poll_votes.find_current_vote("user_id",poll_commit_ids).size - # answer_percent = number_to_percentage((answer_users_count.to_f / question_vote_user.to_f)*100,precision:1) - # sheet_row.push(a.answer_text) - # sheet_answer_row.push(answer_users_count) - # sheet_answer_percent.push(answer_percent.to_s) - # end - # sheet.add_row sheet_row, :height =>15,:style => blue_cell - # sheet.add_row sheet_answer_row, :height =>15, :style => sz_all - # sheet.add_row sheet_answer_percent, :height =>15, :style => sz_all - # sheet.add_row sheet_answer_useful, :height =>15, :style => sz_all - # #合并单元格,但无法填充style - # # sheet.merge_cells (Axlsx::cell_r(1,sheet.rows.last.row_index) + ':' + Axlsx::cell_r(sheet_row.count-1,sheet.rows.last.row_index)) - # # sheet.rows[sheet.rows.last.row_index].style = sz_all - # sheet.add_row [] - # else #主观题答案 - # main_show_row = ["第#{q.question_number}题",q.question_title] - # sheet.add_row main_show_row,:height =>15, :style => blue_cell - # q.poll_votes.each_with_index do |v,index| #主观题的答案 - # sheet.add_row [(index+1),v.vote_text.present? ? v.vote_text : "--"],:height =>15, :style => sz_all - # end - # sheet.add_row [], :style => sz_all - # end - # end #each_with_index - # - # sheet.add_row poll_users_info, :height =>15, :style => blue_cell - # poll_users.includes(user: :user_extension).each_with_index do |u,index| - # u_user = u.user - # user_answer_array = [] - # poll_questions.each do |q| - # user_poll_votes = u_user.poll_votes.find_current_vote("poll_question_id",q.id) - # if user_poll_votes.present? - # user_poll_answer_ids = user_poll_votes.pluck(:poll_answer_id).reject(&:blank?) - # user_poll_vote_texts = user_poll_votes.pluck(:vote_text).reject(&:blank?) - # if user_poll_answer_ids.count > 0 - # answer_content = q.poll_answers.find_answer_by_custom("id",user_poll_answer_ids) - # if user_poll_answer_ids.count >1 - # u_answer = answer_content.pluck(:answer_text).join(";") - # else - # u_answer = answer_content.first.answer_text - # end - # elsif user_poll_vote_texts.count > 0 - # if user_poll_vote_texts.count > 1 - # u_answer = user_poll_vote_texts.join(";") - # else - # u_answer = user_poll_vote_texts.first - # end - # else - # u_answer = "--" - # end - # else - # u_answer = "--" - # end - # user_answer_array.push(u_answer) - # end - # user_cell = [index+1] - # if poll_un_anony - # user_login = u_user.login - # user_name = u_user.real_name.present? ? u_user.real_name : "--" - # user_student_id = u_user.student_id.present? ? u_user.student_id : "--" - # user_cell += [user_login,user_name, u_user.mail, user_student_id] - # end - # all_user_cell = user_cell + user_answer_array - # sheet.add_row all_user_cell, :height =>15,:style => sz_all - # end - # sheet.column_widths *([25]*sheet.column_info.count) - # sheet.column_info.first.width = 10 end #add_worksheet -end \ No newline at end of file +end From 37d932b5463b73a1d0a0f6c879cc34575b9e781a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 14:38:25 +0800 Subject: [PATCH 0602/1015] =?UTF-8?q?=E6=9C=AA=E5=88=86=E7=8F=AD=E6=9C=89?= =?UTF-8?q?=E6=95=88=E4=BD=9C=E5=93=81=E4=B8=BA0=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5=E4=B8=8B=E3=80=82=E4=B8=8D=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/homework_commons/group_list.json.jbuilder | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/app/views/homework_commons/group_list.json.jbuilder b/app/views/homework_commons/group_list.json.jbuilder index dcc04e761..5e6c63556 100644 --- a/app/views/homework_commons/group_list.json.jbuilder +++ b/app/views/homework_commons/group_list.json.jbuilder @@ -8,10 +8,13 @@ json.group_list do end # 未分班展示情况放在最后 if @course_groups.count < @limit.to_i - json.ungroup_list do - json.id 0 - json.name "未分班" - json.work_count homework_ungroup_works_count @homework, @ungroup_user_ids - json.last_review_time ungroup_last_review_time @homework + ungroup_work_count = homework_ungroup_works_count(@homework, @ungroup_user_ids) + if ungroup_work_count > 0 + json.ungroup_list do + json.id 0 + json.name "未分班" + json.work_count ungroup_work_count + json.last_review_time ungroup_last_review_time @homework + end end end \ No newline at end of file From cbb2cf6d1d8b5f04dd9cc6d39ec730f416bd6539 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 15:00:01 +0800 Subject: [PATCH 0603/1015] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/challenge.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/models/challenge.rb b/app/models/challenge.rb index cc0f68efb..a4fd71830 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -78,8 +78,6 @@ class Challenge < ApplicationRecord # todo: 以前没加索引导致相同关卡,同一用户有多个games # 允许跳关则直接开启 game = games.where(user_id: user_id).take - logger.info("########---game_status: #{game.status}") - logger.info("########---challenge_id: #{id}") if game.blank? position == 1 ? 1 : 0 else From c5e283b1bd6ec664871c71fd38ce53f6467be314 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 4 Jul 2019 15:05:52 +0800 Subject: [PATCH 0604/1015] fix bug --- app/views/graduation_topics/export.xlsx.axlsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/graduation_topics/export.xlsx.axlsx b/app/views/graduation_topics/export.xlsx.axlsx index f1d7e8e74..ff5b58b11 100644 --- a/app/views/graduation_topics/export.xlsx.axlsx +++ b/app/views/graduation_topics/export.xlsx.axlsx @@ -15,7 +15,7 @@ wb.styles do |s| sheet.sheet_view.show_grid_lines = false sheet_title = table_columns sheet_title_c = sheet_title.count - sheet.add_row sheet_title, :style => bg_cell + sheet.add_row sheet_title, :style => bg_cell,:height => 15 sheet["J1:L1"].each { |c| c.style = bg_db } sheet["M1:O1"].each { |c| c.style = bg_cc } sheet["P1:Q1"].each { |c| c.style = bg_d2 } From e07d595aabf76c4a24c68e651beb899227830fe5 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 4 Jul 2019 15:09:55 +0800 Subject: [PATCH 0605/1015] =?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/services/export_shixun_report_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/export_shixun_report_service.rb b/app/services/export_shixun_report_service.rb index 4c8dab6aa..f9da3d6f2 100644 --- a/app/services/export_shixun_report_service.rb +++ b/app/services/export_shixun_report_service.rb @@ -10,7 +10,7 @@ class ExportShixunReportService end def filename - @_filename ||= "#{homework.name}-#{work.user.user_extension&.student_id}-#{work.user.real_name}.pdf".gsub(' ', '-').gsub('/', '_') + @_filename ||= "#{homework.name}-#{work.user&.student_id}-#{work.user.real_name}.pdf".gsub(' ', '-').gsub('/', '_') end def prepare_binding From d5049dfc74eb0edadeacbc617f82bb3ab04e8bbc Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 4 Jul 2019 15:11:10 +0800 Subject: [PATCH 0606/1015] fix bug --- app/views/graduation_topics/export.xlsx.axlsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/graduation_topics/export.xlsx.axlsx b/app/views/graduation_topics/export.xlsx.axlsx index ff5b58b11..77e9bec5a 100644 --- a/app/views/graduation_topics/export.xlsx.axlsx +++ b/app/views/graduation_topics/export.xlsx.axlsx @@ -1,5 +1,5 @@ wb = xlsx_package.workbook -wb.use_autowidth = false +# wb.use_autowidth = false wb.use_shared_strings = true wb.styles do |s| @@ -9,13 +9,13 @@ wb.styles do |s| bg_cc = s.add_style :bg_color=> "CCC1DA",:border => { :style => :thick, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } bg_ff = s.add_style :bg_color=> "FFC000",:border => { :style => :thick, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } bg_bb = s.add_style :bg_color=> "9BBB59",:border => { :style => :thick, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } - bg_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } + bg_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } wb.add_worksheet(:name => "毕设选题情况汇总") do |sheet| sheet.sheet_view.show_grid_lines = false sheet_title = table_columns sheet_title_c = sheet_title.count - sheet.add_row sheet_title, :style => bg_cell,:height => 15 + sheet.add_row sheet_title,:height => 30, :style => bg_cell sheet["J1:L1"].each { |c| c.style = bg_db } sheet["M1:O1"].each { |c| c.style = bg_cc } sheet["P1:Q1"].each { |c| c.style = bg_d2 } @@ -23,10 +23,10 @@ wb.styles do |s| sheet["U1:W1"].each { |c| c.style = bg_bb } if topic_users.count > 0 topic_users.each do |user| - sheet.add_row user, :style => sz_all + sheet.add_row user,:height => 18, :style => sz_all end #each_widh_index else - sheet.add_row ["--"]*sheet_title_c + sheet.add_row ["--"]*sheet_title_c,:height => 18 end sheet.column_widths *([15]*sheet.column_info.count) From d27bb78d32b989017468852b3b685c492869693b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 4 Jul 2019 15:14:00 +0800 Subject: [PATCH 0607/1015] fix bug --- app/views/graduation_topics/export.xlsx.axlsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/graduation_topics/export.xlsx.axlsx b/app/views/graduation_topics/export.xlsx.axlsx index 77e9bec5a..2da608f6a 100644 --- a/app/views/graduation_topics/export.xlsx.axlsx +++ b/app/views/graduation_topics/export.xlsx.axlsx @@ -15,7 +15,7 @@ wb.styles do |s| sheet.sheet_view.show_grid_lines = false sheet_title = table_columns sheet_title_c = sheet_title.count - sheet.add_row sheet_title,:height => 30, :style => bg_cell + sheet.add_row sheet_title,:height => 32, :style => bg_cell sheet["J1:L1"].each { |c| c.style = bg_db } sheet["M1:O1"].each { |c| c.style = bg_cc } sheet["P1:Q1"].each { |c| c.style = bg_d2 } From b990d6b74ea956dbb59efdf4d52ca8d0ca7b1fd0 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 16:14:03 +0800 Subject: [PATCH 0608/1015] =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=A2=98=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E5=8F=82=E8=80=83=E7=AD=94=E6=A1=88=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 13 +++++++-- app/views/games/get_answer_info.json.jbuilder | 28 +++++++++++++------ 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 56c1d9347..b490352bb 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -225,8 +225,17 @@ class GamesController < ApplicationController # GET: /tasks/:identifier/get_answer_info # 0 直接查看答案, 1 查看答案弹框, 2 答案详情弹框 def get_answer_info - challenge = @game.challenge - @challenge_answers = challenge.challenge_answers + @challenge = @game.challenge + @challenge_answers = if @challenge.st == 0 + @challenge.challenge_answers + else + result = [] + @challenge.challenge_chooses.each do |choose| + result << {:position => choose.position, :answer => (choose.answer.blank? ? choose.standard_answer : choose.answer)} + end + end + + # 平台已认证的老师需要控制 @power = (@identity < User::EDU_GAME_MANAGER) if !@power diff --git a/app/views/games/get_answer_info.json.jbuilder b/app/views/games/get_answer_info.json.jbuilder index 7620a991a..4cfebd856 100644 --- a/app/views/games/get_answer_info.json.jbuilder +++ b/app/views/games/get_answer_info.json.jbuilder @@ -1,15 +1,25 @@ index = 0 json.status 3 -json.message do - json.array! @challenge_answers do |answer| - index += 1 - json.answer_id answer.id - json.answer_name answer.name - json.answer_score answer.score - # 高层级不给答案 - if @power || @game.answer_open >= index - json.answer_contents answer.contents +if @challenge.st == 0 + json.message do + json.array! @challenge_answers do |answer| + index += 1 + json.answer_id answer.id + json.answer_name answer.name + json.answer_score answer.score + # 高层级不给答案 + if @power || @game.answer_open >= index + json.answer_contents answer.contents + end + end + end +else + json.message do + json.array! @challenge_answers do |answer| + json.position answer[:postion] + json.answer_contents answer[:answer] end end end + From 716b5af39fd8be91981344492f328d18390c488f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 16:14:56 +0800 Subject: [PATCH 0609/1015] =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=A2=98=E7=AD=94?= =?UTF-8?q?=E6=A1=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 17 +++++++++-------- app/views/games/get_answer_info.json.jbuilder | 1 + 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index b490352bb..0142ef2ba 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -226,14 +226,15 @@ class GamesController < ApplicationController # 0 直接查看答案, 1 查看答案弹框, 2 答案详情弹框 def get_answer_info @challenge = @game.challenge - @challenge_answers = if @challenge.st == 0 - @challenge.challenge_answers - else - result = [] - @challenge.challenge_chooses.each do |choose| - result << {:position => choose.position, :answer => (choose.answer.blank? ? choose.standard_answer : choose.answer)} - end - end + if @challenge.st == 0 + @challenge_answers = @challenge.challenge_answers + else + result = [] + @challenge.challenge_chooses.each do |choose| + result << {:position => choose.position, :answer => (choose.answer.blank? ? choose.standard_answer : choose.answer)} + end + @challenge_answers = result + end # 平台已认证的老师需要控制 diff --git a/app/views/games/get_answer_info.json.jbuilder b/app/views/games/get_answer_info.json.jbuilder index 4cfebd856..57b180816 100644 --- a/app/views/games/get_answer_info.json.jbuilder +++ b/app/views/games/get_answer_info.json.jbuilder @@ -1,5 +1,6 @@ index = 0 json.status 3 +# st: 0 实践题 1 选择题 if @challenge.st == 0 json.message do json.array! @challenge_answers do |answer| From b6ccd6562cc18fb81e3405541ebfb7c375d9fcf3 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 16:27:04 +0800 Subject: [PATCH 0610/1015] =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=A2=98=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E5=AE=9E=E8=AE=AD=E7=AD=94=E6=A1=88=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 38 +++++++++---------- app/views/games/get_answer_info.json.jbuilder | 28 +++++--------- app/views/games/unlock_answer.json.jbuilder | 6 ++- 3 files changed, 33 insertions(+), 39 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 0142ef2ba..eea4e4dc0 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -225,18 +225,8 @@ class GamesController < ApplicationController # GET: /tasks/:identifier/get_answer_info # 0 直接查看答案, 1 查看答案弹框, 2 答案详情弹框 def get_answer_info - @challenge = @game.challenge - if @challenge.st == 0 - @challenge_answers = @challenge.challenge_answers - else - result = [] - @challenge.challenge_chooses.each do |choose| - result << {:position => choose.position, :answer => (choose.answer.blank? ? choose.standard_answer : choose.answer)} - end - @challenge_answers = result - end - - + challenge = @game.challenge + @challenge_answers = challenge.challenge_answers # 平台已认证的老师需要控制 @power = (@identity < User::EDU_GAME_MANAGER) if !@power @@ -259,14 +249,22 @@ class GamesController < ApplicationController # 解锁答案 # GET: /tasks/:identifier/get_answer_info?answer_id=? def unlock_answer - @answer = ChallengeAnswer.find(params[:answer_id]) - challenge = @answer.challenge - # 解锁需要本层级的答案是否需要扣分 - points = challenge.challenge_answers.where(level: @game.answer_open+1..@answer.level).sum(:score) - deduct_score = ((points / 100.0) * challenge.score).to_i - uid_logger("############金币数目: #{current_user.grade}") - unless current_user.grade.to_i - deduct_score > 0 - tip_exception("您没有足够的金币") + @challenge = @game.challenge + if @challenge.st == 0 + @answer = ChallengeAnswer.find(params[:answer_id]) + challenge = @answer.challenge + # 解锁需要本层级的答案是否需要扣分 + points = challenge.challenge_answers.where(level: @game.answer_open+1..@answer.level).sum(:score) + deduct_score = ((points / 100.0) * challenge.score).to_i + uid_logger("############金币数目: #{current_user.grade}") + unless current_user.grade.to_i - deduct_score > 0 + tip_exception("您没有足够的金币") + end + else + @answer = [] + @challenge.challenge_chooses.each do |choose| + @answer << {:position => choose.position, :answer => (choose.answer.blank? ? choose.standard_answer : choose.answer)} + end end ActiveRecord::Base.transaction do diff --git a/app/views/games/get_answer_info.json.jbuilder b/app/views/games/get_answer_info.json.jbuilder index 57b180816..0f150d500 100644 --- a/app/views/games/get_answer_info.json.jbuilder +++ b/app/views/games/get_answer_info.json.jbuilder @@ -1,26 +1,18 @@ index = 0 json.status 3 # st: 0 实践题 1 选择题 -if @challenge.st == 0 - json.message do - json.array! @challenge_answers do |answer| - index += 1 - json.answer_id answer.id - json.answer_name answer.name - json.answer_score answer.score - # 高层级不给答案 - if @power || @game.answer_open >= index - json.answer_contents answer.contents - end - end - end -else - json.message do - json.array! @challenge_answers do |answer| - json.position answer[:postion] - json.answer_contents answer[:answer] +json.message do + json.array! @challenge_answers do |answer| + index += 1 + json.answer_id answer.id + json.answer_name answer.name + json.answer_score answer.score + # 高层级不给答案 + if @power || @game.answer_open >= index + json.answer_contents answer.contents end end end + diff --git a/app/views/games/unlock_answer.json.jbuilder b/app/views/games/unlock_answer.json.jbuilder index 71018c7be..9776fde46 100644 --- a/app/views/games/unlock_answer.json.jbuilder +++ b/app/views/games/unlock_answer.json.jbuilder @@ -1 +1,5 @@ -json.contents @answer.contents \ No newline at end of file +if @challenge.st == 0 + json.contents @answer.contents +else + json.contents @answer +end From 1730552269ea552aef42f67acd45496bc7f93338 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 4 Jul 2019 17:21:32 +0800 Subject: [PATCH 0611/1015] fix bug --- app/controllers/polls_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index ee2b061ba..57bbc9769 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -1302,7 +1302,7 @@ class PollsController < ApplicationController sub_commit = [] user_commit = [] poll_users_info = %w(序号) - poll_ques_titles = poll_questions.pluck(:question_title).map {|k| k.strip if k.present?} + poll_ques_titles = poll_questions.pluck(:question_title).map {|k| ActionController::Base.helpers.strip_tags(k) if k.present?} poll_un_anony = poll.un_anonymous if poll_un_anony #是否匿名,默认为false user_info = %w(登陆名 真实姓名 邮箱 学号) From eb5cf9f75957910e232397c97f2f2ec6dcdbd45f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 4 Jul 2019 17:38:04 +0800 Subject: [PATCH 0612/1015] =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=A2=98=E7=AD=94?= =?UTF-8?q?=E6=A1=88=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 75 +++++++++++++------ .../games/get_choose_answer.json.jbuilder | 6 ++ app/views/games/unlock_answer.json.jbuilder | 6 +- .../games/unlock_choose_answer.json.jbuilder | 6 ++ config/routes.rb | 2 + 5 files changed, 68 insertions(+), 27 deletions(-) create mode 100644 app/views/games/get_choose_answer.json.jbuilder create mode 100644 app/views/games/unlock_choose_answer.json.jbuilder diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index eea4e4dc0..ea09b9003 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -221,12 +221,12 @@ class GamesController < ApplicationController @result = challenge.st == 0 ? challenge.try(:answer) : challenge.choose_answer end - # 获取答案 + # 获取实践题答案 # GET: /tasks/:identifier/get_answer_info # 0 直接查看答案, 1 查看答案弹框, 2 答案详情弹框 def get_answer_info - challenge = @game.challenge - @challenge_answers = challenge.challenge_answers + @challenge = @game.challenge + @challenge_answers = @challenge.challenge_answers # 平台已认证的老师需要控制 @power = (@identity < User::EDU_GAME_MANAGER) if !@power @@ -243,43 +243,49 @@ class GamesController < ApplicationController end end end + end + # 获取选择题答案 + def get_choose_answer + @challenge = @game.challenge + tip_exception("本接口只能获取选择题答案") if @challenge.st != 1 + @power = (@identity < User::EDU_GAME_MANAGER) + # 如果没权限,也没看过答案,则需要解锁 + if @game.answer_open == 0 && !@power + tip_exception(1, @challenge.choose_score) + else + @challenge_chooses = @challenge.challenge_chooses + end end - # 解锁答案 + # 解锁实践题答案 # GET: /tasks/:identifier/get_answer_info?answer_id=? def unlock_answer @challenge = @game.challenge - if @challenge.st == 0 - @answer = ChallengeAnswer.find(params[:answer_id]) - challenge = @answer.challenge - # 解锁需要本层级的答案是否需要扣分 - points = challenge.challenge_answers.where(level: @game.answer_open+1..@answer.level).sum(:score) - deduct_score = ((points / 100.0) * challenge.score).to_i - uid_logger("############金币数目: #{current_user.grade}") - unless current_user.grade.to_i - deduct_score > 0 - tip_exception("您没有足够的金币") - end - else - @answer = [] - @challenge.challenge_chooses.each do |choose| - @answer << {:position => choose.position, :answer => (choose.answer.blank? ? choose.standard_answer : choose.answer)} - end + @answer = ChallengeAnswer.find(params[:answer_id]) + challenge = @answer.challenge + # 解锁需要本层级的答案是否需要扣分 + points = challenge.challenge_answers.where(level: @game.answer_open + 1..@answer.level).sum(:score) + deduct_score = ((points / 100.0) * challenge.score).to_i + uid_logger("############金币数目: #{current_user.grade}") + unless current_user.grade.to_i - deduct_score > 0 + tip_exception("您没有足够的金币") end ActiveRecord::Base.transaction do begin # 积分消耗情况记录 score = challenge.st.zero? ? -deduct_score : -challenge.choose_score.to_i - RewardGradeService.call(current_user, container_id: @answer.id, container_type: 'Answer', score: score) + RewardGradeService.call(current_user, container_id: @game.id, container_type: 'Answer', score: score) # 通关查看答案 不扣 得分 + answer_open = @challenge.st == 1 ? 1 : @answer.level if @game.status == 2 - @game.update_attributes!(:answer_open => @answer.level) + @game.update_attributes!(:answer_open =>answer_open) else # 扣除总分计算 answer_deduction = challenge.challenge_answers.where("level <= #{@answer.level}").sum(:score) - @game.update_attributes!(:answer_open => @answer.level, :answer_deduction => answer_deduction) + @game.update_attributes!(:answer_open => answer_open, :answer_deduction => answer_deduction) end rescue Exception => e @@ -287,7 +293,32 @@ class GamesController < ApplicationController raise ActiveRecord::Rollback end end + end + # 解锁选择题答案 + def unlock_choose_answer + @challenge = @game.challenge + score = @challenge.choose_score + unless current_user.grade.to_i - score > 0 + tip_exception("您没有足够的金币") + end + ActiveRecord::Base.transaction do + begin + # 积分消耗情况记录 + RewardGradeService.call(current_user, container_id: @game.id, container_type: 'Answer', score: -score) + # 通关查看答案 不扣 得分 + if @game.status == 2 + @game.update_attributes!(:answer_open => 1) + else + # 扣除总分计算 + @game.update_attributes!(:answer_open => 1, :answer_deduction => 100) + end + @challenge_answers = @challenge.challenge_chooses + rescue Exception => e + uid_logger_error("#######金币扣除异常: #{e.message}") + raise ActiveRecord::Rollback + end + end end # 查看答案需要扣取金币 diff --git a/app/views/games/get_choose_answer.json.jbuilder b/app/views/games/get_choose_answer.json.jbuilder new file mode 100644 index 000000000..15586de13 --- /dev/null +++ b/app/views/games/get_choose_answer.json.jbuilder @@ -0,0 +1,6 @@ +json.choose_answers do + json.array! @challenge_chooses do |choose| + json.position choose.position + json.answer choose.answer.blank? ? choose.standard_answer : choose.answer + end +end diff --git a/app/views/games/unlock_answer.json.jbuilder b/app/views/games/unlock_answer.json.jbuilder index 9776fde46..322536c2b 100644 --- a/app/views/games/unlock_answer.json.jbuilder +++ b/app/views/games/unlock_answer.json.jbuilder @@ -1,5 +1 @@ -if @challenge.st == 0 - json.contents @answer.contents -else - json.contents @answer -end +json.contents @answer.contents diff --git a/app/views/games/unlock_choose_answer.json.jbuilder b/app/views/games/unlock_choose_answer.json.jbuilder new file mode 100644 index 000000000..15586de13 --- /dev/null +++ b/app/views/games/unlock_choose_answer.json.jbuilder @@ -0,0 +1,6 @@ +json.choose_answers do + json.array! @challenge_chooses do |choose| + json.position choose.position + json.answer choose.answer.blank? ? choose.standard_answer : choose.answer + end +end diff --git a/config/routes.rb b/config/routes.rb index e09808f6c..cf5bad608 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -124,6 +124,8 @@ Rails.application.routes.draw do get :get_answer_info get :unlock_answer get :check_test_sets + get :unlock_choose_answer + get :get_choose_answer end collection do From e09625df9458409ac00e32f384788305c9feca2a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 4 Jul 2019 17:43:31 +0800 Subject: [PATCH 0613/1015] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E8=AF=BE=E5=A0=82?= =?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/courses_controller.rb | 2 +- .../course_add_student_create_works_job.rb | 30 +++++++++++++++++++ .../course_delete_student_delete_works_job.rb | 7 +++++ app/models/course_member.rb | 6 ++-- config/sidekiq.yml | 1 + ...ourse_add_student_create_works_job_spec.rb | 5 ++++ ...se_delete_student_delete_works_job_spec.rb | 5 ++++ 7 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 app/jobs/course_add_student_create_works_job.rb create mode 100644 app/jobs/course_delete_student_delete_works_job.rb create mode 100644 spec/jobs/course_add_student_create_works_job_spec.rb create mode 100644 spec/jobs/course_delete_student_delete_works_job_spec.rb diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index d1ab595e5..d6a86ff50 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -711,7 +711,7 @@ class CoursesController < ApplicationController student_ids = [] user_ids.each do |user_id| - existing_course_member = CourseMember.find_by(user_id: user_id.to_i, course_id: @course.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? diff --git a/app/jobs/course_add_student_create_works_job.rb b/app/jobs/course_add_student_create_works_job.rb new file mode 100644 index 000000000..41c3065a1 --- /dev/null +++ b/app/jobs/course_add_student_create_works_job.rb @@ -0,0 +1,30 @@ +# 学生加入课堂时创建相关任务作品 +class CourseAddStudentCreateWorksJob < ApplicationJob + queue_as :course_member + + def perform(course_id, student_ids) + course = Course.find_by(id: course_id) + return if course.blank? + + # 如果之前存在相关作品,则更新is_delete字段 + student_works = StudentWork.joins(:homework_common).where(user_id: student_ids, homework_commons: {course_id: course.id}) + student_works.update_all(is_delete: 0) + + exercise_users = ExerciseUser.joins(:exercise).where(user_id: student_ids, exercises: {course_id: course.id}) + exercise_users.update_all(is_delete: 0) + + poll_users = PollUser.joins(:poll).where(user_id: student_ids, polls: {course_id: course.id}) + poll_users.update_all(is_delete: 0) + + graduation_works = course.graduation_works.where(user_id: student_ids) + graduation_works.update_all(is_delete: 0) + + attrs = %i[homework_common_id user_id created_at updated_at] + + StudentWork.bulk_insert(*attrs) do |worker| + student_ids.each do |teacher| + worker.add same_attrs.merge(user_id: teacher.user_id) + end + end + end +end diff --git a/app/jobs/course_delete_student_delete_works_job.rb b/app/jobs/course_delete_student_delete_works_job.rb new file mode 100644 index 000000000..2eb3fb60e --- /dev/null +++ b/app/jobs/course_delete_student_delete_works_job.rb @@ -0,0 +1,7 @@ +class CourseDeleteStudentDeleteWorksJob < ApplicationJob + queue_as :course_member + + def perform(*args) + # Do something later + end +end diff --git a/app/models/course_member.rb b/app/models/course_member.rb index 7db681e67..87d4ffe88 100644 --- a/app/models/course_member.rb +++ b/app/models/course_member.rb @@ -52,13 +52,13 @@ class CourseMember < ApplicationRecord def recover_works course = self.course - student_works = StudentWork.where(user_id: self.user_id, homework_common_id: course.homework_commons) + student_works = StudentWork.joins(:homework_common).where(user_id: self.user_id, homework_commons: {course_id: course.id}) student_works.update_all(is_delete: 0) - exercise_users = ExerciseUser.where(user_id: self.user_id, exercise_id: course.exercises) + exercise_users = ExerciseUser.joins(:exercise).where(user_id: self.user_id, exercises: {course_id: course.id}) exercise_users.update_all(is_delete: 0) - poll_users = PollUser.where(user_id: self.user_id, poll_id: course.polls) + poll_users = PollUser.joins(:poll).where(user_id: self.user_id, polls: {course_id: course.id}) poll_users.update_all(is_delete: 0) graduation_works = course.graduation_works.where(user_id: self.user_id) diff --git a/config/sidekiq.yml b/config/sidekiq.yml index 5bd9dad23..93e89b4dc 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -5,4 +5,5 @@ - [default, 3] - [score, 4] - [evaluation_comment, 5] + - [course_member, 6] - [notify, 100] \ No newline at end of file diff --git a/spec/jobs/course_add_student_create_works_job_spec.rb b/spec/jobs/course_add_student_create_works_job_spec.rb new file mode 100644 index 000000000..5466f830c --- /dev/null +++ b/spec/jobs/course_add_student_create_works_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CourseAddStudentCreateWorksJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/jobs/course_delete_student_delete_works_job_spec.rb b/spec/jobs/course_delete_student_delete_works_job_spec.rb new file mode 100644 index 000000000..71ad3b1dc --- /dev/null +++ b/spec/jobs/course_delete_student_delete_works_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CourseDeleteStudentDeleteWorksJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end From 234cdbeab907804f42b9a358fd356a30c1f6779d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 09:28:37 +0800 Subject: [PATCH 0614/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E7=82=B9=E8=B5=9E?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0190705011739_add_praises_count_for_challenges.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 db/migrate/20190705011739_add_praises_count_for_challenges.rb diff --git a/db/migrate/20190705011739_add_praises_count_for_challenges.rb b/db/migrate/20190705011739_add_praises_count_for_challenges.rb new file mode 100644 index 000000000..6455f1f10 --- /dev/null +++ b/db/migrate/20190705011739_add_praises_count_for_challenges.rb @@ -0,0 +1,12 @@ +class AddPraisesCountForChallenges < ActiveRecord::Migration[5.2] + def change + add_column :challenges, :praises_count, :integer, :default => 0 + + challenges = Challenge.where(nil) + challenges.each do |c| + praises_count = c.praise_tread.where(praise_or_tread: 1).count + c.update_column(:praises_count, praises_count) + end + + end +end From fbcf9b77f53245d163aec43c78076422308d443f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 09:32:29 +0800 Subject: [PATCH 0615/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190705011739_add_praises_count_for_challenges.rb | 9 +-------- ...20190705013203_modify_praises_count_for_challenges.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20190705013203_modify_praises_count_for_challenges.rb diff --git a/db/migrate/20190705011739_add_praises_count_for_challenges.rb b/db/migrate/20190705011739_add_praises_count_for_challenges.rb index 6455f1f10..2bf246277 100644 --- a/db/migrate/20190705011739_add_praises_count_for_challenges.rb +++ b/db/migrate/20190705011739_add_praises_count_for_challenges.rb @@ -1,12 +1,5 @@ class AddPraisesCountForChallenges < ActiveRecord::Migration[5.2] def change - add_column :challenges, :praises_count, :integer, :default => 0 - - challenges = Challenge.where(nil) - challenges.each do |c| - praises_count = c.praise_tread.where(praise_or_tread: 1).count - c.update_column(:praises_count, praises_count) - end - + #add_column :challenges, :praises_count, :integer, :default => 0 end end diff --git a/db/migrate/20190705013203_modify_praises_count_for_challenges.rb b/db/migrate/20190705013203_modify_praises_count_for_challenges.rb new file mode 100644 index 000000000..d2441d948 --- /dev/null +++ b/db/migrate/20190705013203_modify_praises_count_for_challenges.rb @@ -0,0 +1,9 @@ +class ModifyPraisesCountForChallenges < ActiveRecord::Migration[5.2] + def change + challenges = Challenge.where(nil) + challenges.each do |c| + praises_count = c.praise_tread.where(praise_or_tread: 1).count + c.update_column(:praises_count, praises_count) + end + end +end From 6f1d84eecc41ef8cf4c6529d0f60c9e4009c39b1 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 09:34:32 +0800 Subject: [PATCH 0616/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190705011739_add_praises_count_for_challenges.rb | 2 +- .../20190705013203_modify_praises_count_for_challenges.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/db/migrate/20190705011739_add_praises_count_for_challenges.rb b/db/migrate/20190705011739_add_praises_count_for_challenges.rb index 2bf246277..6ae1d8420 100644 --- a/db/migrate/20190705011739_add_praises_count_for_challenges.rb +++ b/db/migrate/20190705011739_add_praises_count_for_challenges.rb @@ -1,5 +1,5 @@ class AddPraisesCountForChallenges < ActiveRecord::Migration[5.2] def change - #add_column :challenges, :praises_count, :integer, :default => 0 + add_column :challenges, :praises_count, :integer, :default => 0 end end diff --git a/db/migrate/20190705013203_modify_praises_count_for_challenges.rb b/db/migrate/20190705013203_modify_praises_count_for_challenges.rb index d2441d948..35711027a 100644 --- a/db/migrate/20190705013203_modify_praises_count_for_challenges.rb +++ b/db/migrate/20190705013203_modify_praises_count_for_challenges.rb @@ -1,7 +1,7 @@ class ModifyPraisesCountForChallenges < ActiveRecord::Migration[5.2] def change - challenges = Challenge.where(nil) - challenges.each do |c| + challenges = Challenge.where(nil).unscope + challenges.find_each do |c| praises_count = c.praise_tread.where(praise_or_tread: 1).count c.update_column(:praises_count, praises_count) end From f0b6c04e5fa9c2a958fc1e2ec7a970c36f66fdb4 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 09:36:27 +0800 Subject: [PATCH 0617/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E7=82=B9=E8=B5=9E?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...rb => 20190705013204_modify_praises_count_for_challenges.rb} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename db/migrate/{20190705013203_modify_praises_count_for_challenges.rb => 20190705013204_modify_praises_count_for_challenges.rb} (84%) diff --git a/db/migrate/20190705013203_modify_praises_count_for_challenges.rb b/db/migrate/20190705013204_modify_praises_count_for_challenges.rb similarity index 84% rename from db/migrate/20190705013203_modify_praises_count_for_challenges.rb rename to db/migrate/20190705013204_modify_praises_count_for_challenges.rb index 35711027a..4cf975f3d 100644 --- a/db/migrate/20190705013203_modify_praises_count_for_challenges.rb +++ b/db/migrate/20190705013204_modify_praises_count_for_challenges.rb @@ -1,6 +1,6 @@ class ModifyPraisesCountForChallenges < ActiveRecord::Migration[5.2] def change - challenges = Challenge.where(nil).unscope + challenges = Challenge.where(nil).unscoped challenges.find_each do |c| praises_count = c.praise_tread.where(praise_or_tread: 1).count c.update_column(:praises_count, praises_count) From 3d7284525f64849b7f8364c0fbf0f5165cfe4987 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 09:53:23 +0800 Subject: [PATCH 0618/1015] =?UTF-8?q?=E7=82=B9=E8=B5=9E=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index ea09b9003..e54d5c34f 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -40,10 +40,8 @@ class GamesController < ApplicationController next_game = @game.next_of_current_game(@shixun.id, @game.myshixun_id, game_challenge.position) # 关卡点赞数, praise_or_tread = 1则表示赞过 - praise_count = PraiseTread.where(praise_tread_object_id: game_challenge.id, praise_tread_object_type: "Challenge", - praise_or_tread: 1).count - user_praise = PraiseTread.where(praise_tread_object_id: game_challenge.id, praise_tread_object_type: "Challenge", - user_id: current_user.id, praise_or_tread: 1).present? ? true : false + praise_count = game_challenge.praises_count + user_praise = game_challenge.praise_tread.exists?(user_id:current_user.id, praise_or_tread: 1) # 实训的最大评测次数,这个值是为了优化查询,每次只取最新的最新一次评测的结果集 max_query_index = @game.query_index.to_i From db69b3737c93c98ca962672e12e42a6029c54dea Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 09:55:30 +0800 Subject: [PATCH 0619/1015] =?UTF-8?q?TPI=E7=82=B9=E8=B5=9E=E8=BF=81?= =?UTF-8?q?=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/challenge.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/challenge.rb b/app/models/challenge.rb index a4fd71830..e4524a69a 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -20,7 +20,7 @@ class Challenge < ApplicationRecord # acts_as_attachable scope :base_attrs, -> { select([:id, :subject, :position, :shixun_id, :st, :score, :path, :task_pass, :modify_time, - :web_route, :answer, :exec_time]) } + :web_route, :answer, :exec_time, :praises_count]) } scope :choose_type, -> { where(st: 1) } scope :practice_type, -> { where(st: 0) } From 7d81be96a5b6f00b06f58228a409fed174109dfe Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 09:57:38 +0800 Subject: [PATCH 0620/1015] =?UTF-8?q?zip=E5=AF=BC=E5=87=BA=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 4 +- app/controllers/zips_controller.rb | 61 ++++++++++--------- .../batch_export_shixun_report_service.rb | 14 +---- 3 files changed, 36 insertions(+), 43 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 07113792d..e6f9876bc 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1300,7 +1300,9 @@ class ExercisesController < ApplicationController if params[:format] == "xlsx" if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") - elsif (@exercise_status == 1) || (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) + elsif @exercise_status == 1 + normal_status(-1,"试卷未发布") + elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) normal_status(-1,"暂无用户提交") else respond_to do |format| diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 8553cbb44..4089e5231 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -6,12 +6,9 @@ class ZipsController < ApplicationController before_action :require_admin_or_teacher def shixun_report - # student_work_ids = Array.wrap(params[:student_work_ids]) - # service = BatchExportShixunReportService.new(@homework, @student_work_ids) service = BatchExportShixunReportService.new(@homework, @all_student_works) - filename = filename_for_content_disposition(service.filename) send_file service.zip, filename: filename, type: 'application/zip' rescue BatchExportShixunReportService::Error => ex @@ -23,8 +20,8 @@ class ZipsController < ApplicationController exercises = ExportExercisesService.new(@exercise,@ex_users,@request_url) file_name = filename_for_content_disposition(exercises.filename) - send_file exercises.ex_zip, filename: file_name, type: 'application/zip' + send_file exercises.ex_zip, filename: file_name, type: 'application/zip' rescue Exception => e normal_status(-1, e.message) end @@ -44,7 +41,7 @@ class ZipsController < ApplicationController ActiveRecord::Base.transaction do begin @exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id]) - @exercise_status = @exercise.get_exercise_status(current_user.id) + @exercise_status = @exercise.present? ? @exercise.get_exercise_status(current_user.id) : 1 group_id = params[:exercise_group_id] if @exercise.blank? normal_status(-1,"试卷不存在") @@ -101,34 +98,40 @@ class ZipsController < ApplicationController def load_homework @homework = HomeworkCommon.find(params[:homework_common_id]) + @homework_status = @homework.present? ? @homework.homework_detail_manual.comment_status : 0 + if @homework.blank? + normal_status(-1,"该作业不存在") + elsif @homework_status == 0 + normal_status(-1,"该作业未发布") + else + @course = @homework.course + ##7。2 -hs新增 + @member = @course.course_member(current_user.id) + + @all_student_works = @homework.teacher_works(@member).where("work_status > 0") + work_status = params[:work_status] + group_id = params[:course_group] + + if work_status.present? + @all_student_works = @all_student_works.where(work_status:work_status) + end + if group_id.present? + group_user_ids = @course.students.where(course_group_id: params[:course_group]).pluck(:user_id) + @all_student_works = @all_student_works.where(user_id: group_user_ids) + end - @course = @homework.course - ##7。2 -hs新增 - @member = @course.course_member(current_user.id) - @all_student_works = @homework.teacher_works(@member).where("work_status > 0") - work_status = params[:work_status] - group_id = params[:course_group] - - if work_status.present? - @all_student_works = @all_student_works.where(work_status:work_status) - end - - if group_id.present? - group_user_ids = @course.students.where(course_group_id: params[:course_group]).pluck(:user_id) - @all_student_works = @all_student_works.where(user_id: group_user_ids) - end - - unless params[:search].blank? - @all_student_works = @all_student_works.joins(user: :user_extension).where("concat(lastname, firstname) like ? + unless params[:search].blank? + @all_student_works = @all_student_works.joins(user: :user_extension).where("concat(lastname, firstname) like ? or student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%") - end + end - student_work_sizes = @all_student_works&.size - if student_work_sizes.blank? || student_work_sizes == 0 - normal_status(-1,"暂无用户提交") - elsif student_work_sizes > 100 - normal_status(-2,"100") + student_work_sizes = @all_student_works&.size + if student_work_sizes.blank? || student_work_sizes == 0 + normal_status(-1,"暂无用户提交") + elsif student_work_sizes > 100 + normal_status(-2,"100") + end end end end diff --git a/app/services/batch_export_shixun_report_service.rb b/app/services/batch_export_shixun_report_service.rb index ebb273a87..90c8fb2af 100644 --- a/app/services/batch_export_shixun_report_service.rb +++ b/app/services/batch_export_shixun_report_service.rb @@ -3,7 +3,6 @@ class BatchExportShixunReportService MAX_BATCH_LIMIT = 20 - # attr_reader :homework, :student_work_ids attr_reader :homework, :all_student_works @@ -15,7 +14,7 @@ class BatchExportShixunReportService end def filename - @_filename ||= "#{Time.now.strftime('%Y%m%d%H%M%S')}-#{homework.name}.zip" + @_filename ||= "#{homework.name}-#{Time.now.strftime('%Y%m%d%H%M%S')}.zip" end def zip @@ -45,15 +44,4 @@ class BatchExportShixunReportService end end - # private - # - # def validate! - # if student_work_ids.size.zero? - # raise Error, '请选择学生实训作业' - # end - # - # if student_work_ids.size > MAX_BATCH_LIMIT - # raise Error, '导出实训报告太多,请分批导出' - # end - # end end From 155e9a0a37b635a7d99e8d616ecae257d90a611a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 10:40:16 +0800 Subject: [PATCH 0621/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E7=82=B9=E8=B5=9E?= =?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/controllers/discusses_controller.rb | 4 ++-- app/models/challenge.rb | 2 +- app/models/discuss.rb | 2 +- app/services/shixuns_service.rb | 10 +++++----- app/views/discusses/_discuss.json.jbuilder | 4 ++-- ...190705013204_modify_praises_count_for_challenges.rb | 2 +- .../20190705022502_add_praises_count_for_discuess.rb | 5 +++++ ...20190705022737_modify_praises_count_for_discuess.rb | 9 +++++++++ 8 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 db/migrate/20190705022502_add_praises_count_for_discuess.rb create mode 100644 db/migrate/20190705022737_modify_praises_count_for_discuess.rb diff --git a/app/controllers/discusses_controller.rb b/app/controllers/discusses_controller.rb index 1d3b524f4..db3047e74 100644 --- a/app/controllers/discusses_controller.rb +++ b/app/controllers/discusses_controller.rb @@ -10,13 +10,13 @@ class DiscussesController < ApplicationController if current_user.admin? @disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count @discusses = Discuss.limit(LIMIT).where(:dis_id => @container.id, :dis_type => @container.class.to_s, - :root_id => nil).includes(:user, :praise_tread).offset(offset) + :root_id => nil).includes(:user, :praise_treads).offset(offset) else disscusses = Discuss.where("dis_id = :dis_id and dis_type = :dis_type and root_id is null and (hidden = :hidden or user_id = :user_id)", {dis_id: @container.id, dis_type: @container.class.to_s, hidden: false, user_id: current_user.id}) @disscuss_count = disscusses.count - @discusses = disscusses.limit(LIMIT).includes(:user, :praise_tread).offset(offset) + @discusses = disscusses.limit(LIMIT).includes(:user, :praise_treads).offset(offset) end @current_user = current_user diff --git a/app/models/challenge.rb b/app/models/challenge.rb index e4524a69a..7afb919a0 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -10,7 +10,7 @@ class Challenge < ApplicationRecord has_many :games, :dependent => :destroy has_many :challenge_chooses, :dependent => :destroy has_many :homework_challenge_settings, :dependent => :destroy - has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_many :praise_treads, as: :praise_tread_object, dependent: :destroy has_one :praise_tread_cache, as: :object, dependent: :destroy has_many :tidings # 参考答案 diff --git a/app/models/discuss.rb b/app/models/discuss.rb index 93f0d62cd..737a89ec1 100644 --- a/app/models/discuss.rb +++ b/app/models/discuss.rb @@ -5,7 +5,7 @@ class Discuss < ApplicationRecord belongs_to :parent, class_name: 'Discuss', foreign_key: :parent_id, optional: true has_many :children, -> { reorder(created_at: :asc) }, class_name: 'Discuss', foreign_key: :parent_id - has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_many :praise_treads, as: :praise_tread_object, dependent: :destroy has_many :tidings, as: :container, dependent: :destroy has_one :praise_tread_cache, as: :object, dependent: :destroy diff --git a/app/services/shixuns_service.rb b/app/services/shixuns_service.rb index 83d61b352..4efefd4c2 100644 --- a/app/services/shixuns_service.rb +++ b/app/services/shixuns_service.rb @@ -47,7 +47,7 @@ class ShixunsService if current_user.admin? disscuss_count = Discuss.where(dis_id: dis_id, dis_type: dis_type, root_id: nil).count discusses = Discuss.where(dis_id: dis_id, dis_type: dis_type, root_id: nil) - .includes(:user, :praise_tread).limit(LIMIT).offset(offset) + .includes(:user, :praise_treads).limit(LIMIT).offset(offset) else disscusses = Discuss.where( 'dis_id = :dis_id and dis_type = :dis_type and root_id is null and (hidden = :hidden or user_id = :user_id)', @@ -55,7 +55,7 @@ class ShixunsService ) disscuss_count = disscusses.count - discusses = disscusses.includes(:user, :praise_tread).limit(LIMIT).offset(offset) + discusses = disscusses.includes(:user, :praise_treads).limit(LIMIT).offset(offset) end base_data discusses, dis, current_user @@ -81,7 +81,7 @@ class ShixunsService offset = page * LIMIT find_status = true if position end - discusses = Discuss.limit(LIMIT).where(:dis_id => dis_id, :dis_type => dis_type, :root_id => nil).includes(:user, :praise_tread).offset(offset) + discusses = Discuss.limit(LIMIT).where(:dis_id => dis_id, :dis_type => dis_type, :root_id => nil).includes(:user, :praise_treads).offset(offset) base_data discusses, dis, current_user Myshixun.find(params[:myshixun_id]).update_attribute(:onclick_time, Time.now) @@ -109,8 +109,8 @@ class ShixunsService if discusses.present? discusses.each do |d| # 总点赞数 - praise_count = d.praise_tread.where(:praise_or_tread => 1).count - user_praise= d.praise_tread.select{|pt| pt.user_id == current_user.id}.length > 0 ? true : false + praise_count = d.praises_count + user_praise= d.praise_treads.select{|pt| pt.user_id == current_user.id}.length > 0 ? true : false manager = current_user.manager_of_shixun?(dis, current_user) game_url = if manager diff --git a/app/views/discusses/_discuss.json.jbuilder b/app/views/discusses/_discuss.json.jbuilder index e7e6e425f..992466559 100644 --- a/app/views/discusses/_discuss.json.jbuilder +++ b/app/views/discusses/_discuss.json.jbuilder @@ -14,8 +14,8 @@ json.game_url discuss.game_url(container, current_user) if discuss.parent_id json.can_delete discuss.can_deleted?(current_user) else - json.praise_count discuss.praise_tread.where(praise_or_tread: 1).count - json.user_praise discuss.praise_tread.select{|pt| pt.user_id == current_user.id}.length > 0 ? true : false + json.praise_count discuss.praises_count + json.user_praise discuss.praise_treads.select{|pt| pt.user_id == current_user.id}.length > 0 end diff --git a/db/migrate/20190705013204_modify_praises_count_for_challenges.rb b/db/migrate/20190705013204_modify_praises_count_for_challenges.rb index 4cf975f3d..59aa6ca53 100644 --- a/db/migrate/20190705013204_modify_praises_count_for_challenges.rb +++ b/db/migrate/20190705013204_modify_praises_count_for_challenges.rb @@ -2,7 +2,7 @@ class ModifyPraisesCountForChallenges < ActiveRecord::Migration[5.2] def change challenges = Challenge.where(nil).unscoped challenges.find_each do |c| - praises_count = c.praise_tread.where(praise_or_tread: 1).count + praises_count = c.praise_treads.where(praise_or_tread: 1).count c.update_column(:praises_count, praises_count) end end diff --git a/db/migrate/20190705022502_add_praises_count_for_discuess.rb b/db/migrate/20190705022502_add_praises_count_for_discuess.rb new file mode 100644 index 000000000..47fd5ec1a --- /dev/null +++ b/db/migrate/20190705022502_add_praises_count_for_discuess.rb @@ -0,0 +1,5 @@ +class AddPraisesCountForDiscuess < ActiveRecord::Migration[5.2] + def change + add_column :discusses, :praises_count, :integer, :default => 0 + end +end diff --git a/db/migrate/20190705022737_modify_praises_count_for_discuess.rb b/db/migrate/20190705022737_modify_praises_count_for_discuess.rb new file mode 100644 index 000000000..4d5b6ca97 --- /dev/null +++ b/db/migrate/20190705022737_modify_praises_count_for_discuess.rb @@ -0,0 +1,9 @@ +class ModifyPraisesCountForDiscuess < ActiveRecord::Migration[5.2] + def change + discusses = Discuss.includes(:praise_treads).unscoped + discusses.find_each do |d| + praises_count = d.praise_treads.liker.count + d.update_column(:praises_count, praises_count) + end + end +end From 5666a3564e5199b2ac84a2110eb6c11cdcc0390d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 10:41:38 +0800 Subject: [PATCH 0622/1015] =?UTF-8?q?=E7=82=B9=E8=B5=9E=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index e54d5c34f..c36be012f 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -41,7 +41,7 @@ class GamesController < ApplicationController # 关卡点赞数, praise_or_tread = 1则表示赞过 praise_count = game_challenge.praises_count - user_praise = game_challenge.praise_tread.exists?(user_id:current_user.id, praise_or_tread: 1) + user_praise = game_challenge.praise_treads.exists?(user_id:current_user.id, praise_or_tread: 1) # 实训的最大评测次数,这个值是为了优化查询,每次只取最新的最新一次评测的结果集 max_query_index = @game.query_index.to_i From 20657ff933180557e7d20eb746c6a45bda9e4662 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 10:47:15 +0800 Subject: [PATCH 0623/1015] fix bug --- app/services/batch_export_shixun_report_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/batch_export_shixun_report_service.rb b/app/services/batch_export_shixun_report_service.rb index 90c8fb2af..2c294395d 100644 --- a/app/services/batch_export_shixun_report_service.rb +++ b/app/services/batch_export_shixun_report_service.rb @@ -36,7 +36,7 @@ class BatchExportShixunReportService rescue => ex Rails.logger.error(ex.message) - zip.get_output_stream('FILE_NOTICE.txt'){|os| os.write('文件重复') } + zip.get_output_stream('FILE_NOTICE.txt'){|os| os.write("文件重复:#{export.filename}") } next end end From 6628269df16274745bd24d3680bca631ceb0d4a7 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 5 Jul 2019 10:52:47 +0800 Subject: [PATCH 0624/1015] =?UTF-8?q?=E4=BD=9C=E5=93=81=E9=99=84=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E5=AF=BC=E5=87=BA=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/export_helper.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index a23cb8a65..839686f5b 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -487,6 +487,8 @@ module ExportHelper zipfile_name = "#{output_path}/#{rename_zipfile}" + # 同名文件重命名时用 + index = 1 Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name)) Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile| files_paths.each do |filename| @@ -496,7 +498,11 @@ module ExportHelper begin zipfile.add(rename_file, filename) rescue Exception => e - zipfile.get_output_stream('FILE_NOTICE.txt'){|os| os.write "该作品中有重复命名文件,请通过文件名学号和姓名信息进入该作业详细界面手动下载"} + rename_file = rename_same_file(rename_file, index) + index += 1 + zipfile.add(rename_file, filename) + + # zipfile.get_output_stream('FILE_NOTICE.txt'){|os| os.write "该作品中有重复命名文件,请通过文件名学号和姓名信息进入该作业详细界面手动下载"} next end end @@ -516,4 +522,11 @@ module ExportHelper def format_sheet_name name name = name.gsub(":", "-") end + + def rename_same_file(name, index) + basename = File.basename(name, ".*") + new_basename = basename + "_" + index.to_s + extname = File.extname(name) + new_basename + extname + end end From 1ab39388137209d5941c953d01bdd69a6799beaf Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 5 Jul 2019 10:54:07 +0800 Subject: [PATCH 0625/1015] =?UTF-8?q?=E8=AE=A1=E7=AE=97=E7=BC=BA=E8=AF=84?= =?UTF-8?q?=E6=88=90=E7=BB=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/homework_absence_penalty_calculation_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/homework_absence_penalty_calculation_job.rb b/app/jobs/homework_absence_penalty_calculation_job.rb index 87f78f311..6e80f2330 100644 --- a/app/jobs/homework_absence_penalty_calculation_job.rb +++ b/app/jobs/homework_absence_penalty_calculation_job.rb @@ -11,7 +11,7 @@ class HomeworkAbsencePenaltyCalculationJob < ApplicationJob homework_common.student_works.where("work_status != 0").each do |student_work| absence_penalty_count = student_work.user.student_works_evaluation_distributions.where(student_work_id: work_ids).count - - student_work.user.student_works_scores.where(student_work_id: work_ids, reviewer_role: 3).group_by(:student_work_id).count + student_work.user.student_works_scores.where(student_work_id: work_ids, reviewer_role: 3).group_by(&:student_work_id).count student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * homework_detail_manual.absence_penalty : 0 student_work.save From 4b49571ab58b3b6651626d71f7dc505bc62c36e0 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 11:31:45 +0800 Subject: [PATCH 0626/1015] fix bug --- app/controllers/exercises_controller.rb | 40 ++----------------------- app/controllers/polls_controller.rb | 2 -- 2 files changed, 3 insertions(+), 39 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index e6f9876bc..49dd7edb9 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -477,10 +477,8 @@ class ExercisesController < ApplicationController params_end_time = params[:end_time].to_time end - if exercise_status == 2 && @exercise.publish_time != params_publish_time - normal_status(-1,"已发布,不允许修改发布时间") - elsif exercise_status == 3 && (@exercise.end_time != params_end_time || @exercise.publish_time != params_publish_time) - normal_status(-1,"已截止,不允许修改时间") + if (exercise_status != 1) && (@exercise.publish_time != params_publish_time) + normal_status(-1,"已发布/已截止,不允许修改发布时间") elsif params_publish_time.present? && params_end_time.present? && params_end_time < params_publish_time normal_status(-1,"截止时间不能小于发布时间") else @@ -523,12 +521,7 @@ class ExercisesController < ApplicationController end # exercise_end_time = t[:end_time].present? ? t[:end_time].to_time : nil exercise_group = exercise_groups.find_in_exercise_group("course_group_id",course_id) #判断该分班是否存在 - if exercise_group.present? && exercise_group.first.end_time <= Time.now && - (exercise_end_time != exercise_group.first.end_time || exercise_publish_time != exercise_group.first.publish_time) #已截止且时间改变的,则提示错误 - error_count += 1 - end - if exercise_group.present? && exercise_group.first.publish_time < - Time.now && exercise_publish_time != exercise_group.first.publish_time + if exercise_group.present? && (exercise_group.first.publish_time < Time.now) && (exercise_publish_time != exercise_group.first.publish_time) error_count += 1 end if error_count == 0 @@ -1639,36 +1632,9 @@ class ExercisesController < ApplicationController @answer_committed_user = @exercise.exercise_users.exercise_commit_users(current_user.id)&.first if @answer_committed_user.blank? normal_status(404,"答题用户不存在") - # elsif @exercise.get_exercise_status(current_user.id) == 2 && @answer_committed_user.commit_status == 1 #当试卷截止时,会自动提交 - # normal_status(-1,"提交错误,试卷用户已提交!") end end - # def commit_user_exercise - # @exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id)&.first #查找当前用户是否有过答题 - # if @user_course_identity == Course::STUDENT - # if @exercise_user_current.present? - # if @exercise.time > 0 && @exercise_user_current.start_at.present? && (@exercise_user_current.commit_status == 0) && - # ((@exercise_user_current.start_at + (@exercise.time.to_i + 1).minutes) < Time.now) - # #当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制 - # objective_score = calculate_student_score(@exercise,current_user)[:total_score] - # subjective_score = @exercise_user_current.subjective_score < 0.0 ? 0.0 : @exercise_user_current.subjective_score - # total_score = objective_score + subjective_score - # commit_option = { - # :status => 1, - # :commit_status => 1, - # :end_at => Time.now, - # :objective_score => objective_score, - # :score => total_score, - # :subjective_score => subjective_score - # } - # @exercise_user_current.update_attributes(commit_option) - # normal_status(0,"已交卷成功!") - # end - # end - # end - # end - #打回重做时的初步判断 def check_exercise_status @exercise_users = @exercise.all_exercise_users(current_user.id).commit_exercise_by_status(1) #当前教师所在分班的全部已提交的学生数 diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 57bbc9769..64827b375 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -1282,8 +1282,6 @@ class PollsController < ApplicationController else normal_status(-1,"请选择分班!") end - # elsif (@poll.poll_status != 1) && (params[:publish_time].to_time != @poll.publish_time) && (@user_course_identity > Course::CREATOR) - # normal_status(-1,"已发布/已截止的不能修发布时间!") #课堂管理员和超级管理员才有权限 end end From 8d2a90a94702ab4b4cc27442b2baafbacf9f68b9 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 5 Jul 2019 14:13:54 +0800 Subject: [PATCH 0627/1015] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E8=AF=BE=E5=A0=82=E5=92=8C=E9=80=80=E5=87=BA=E8=AF=BE=E5=A0=82?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E6=95=B0=E6=8D=AE=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 | 13 +++++- .../course_add_student_create_works_job.rb | 41 ++++++++++++++++++- .../course_delete_student_delete_works_job.rb | 16 +++++++- app/models/course_member.rb | 4 +- 4 files changed, 66 insertions(+), 8 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index d6a86ff50..d7b039e02 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -548,6 +548,7 @@ class CoursesController < ApplicationController course_teacher = CourseMember.find_by(user_id: current_user.id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR], course_id: @course.id) course_student.destroy! course_teacher.update_attributes(is_active: 1) if course_teacher.present? && !course_teacher.is_active + CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [current_user.id]) normal_status(0, "退出成功") end @@ -684,11 +685,16 @@ class CoursesController < ApplicationController ActiveRecord::Base.transaction do begin students = params[:students] + student_ids = [] students.each do |student| - course_member = CourseMember.find_by!(id: student[:course_member_id].to_i, course_id: @course.id) - course_member.destroy! + course_member = CourseMember.find_by(id: student[:course_member_id].to_i, course_id: @course.id) + if course_member.present? + student_ids << course_member.user_id + course_member.destroy! + end end + CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, student_ids) if student_ids.present? normal_status(0, "操作成功") rescue => e uid_logger(e.message) @@ -720,6 +726,7 @@ class CoursesController < ApplicationController else new_student.is_active = 0 if existing_course_member.is_active new_student.save! + student_ids << user_id end else new_student.save! @@ -727,6 +734,7 @@ class CoursesController < ApplicationController 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, "添加成功") rescue => e @@ -868,6 +876,7 @@ class CoursesController < ApplicationController new_student.course_group_id = course_group.id if course_group.present? new_student.save! + CourseAddStudentCreateWorksJob.perform_later(course.id, [current_user.id]) StudentJoinCourseNotifyJob.perform_later(current_user.id, course.id) end end diff --git a/app/jobs/course_add_student_create_works_job.rb b/app/jobs/course_add_student_create_works_job.rb index 41c3065a1..1631b5b77 100644 --- a/app/jobs/course_add_student_create_works_job.rb +++ b/app/jobs/course_add_student_create_works_job.rb @@ -22,8 +22,45 @@ class CourseAddStudentCreateWorksJob < ApplicationJob attrs = %i[homework_common_id user_id created_at updated_at] StudentWork.bulk_insert(*attrs) do |worker| - student_ids.each do |teacher| - worker.add same_attrs.merge(user_id: teacher.user_id) + student_ids.each do |user_id| + same_attrs = {user_id: user_id} + course.homework_commons.where(homework_type: %i[normal group practice]).each do |homework| + next if homework.student_works.where(user_id: user_id).any? + worker.add same_attrs.merge(homework_common_id: homework.id) + end + end + end + + attrs = %i[exercise_id user_id created_at updated_at] + ExerciseUser.bulk_insert(*attrs) do |worker| + student_ids.each do |user_id| + same_attrs = {user_id: user_id} + course.exercises.each do |exercise| + next if exercise.exercise_users.where(user_id: user_id).any? + worker.add same_attrs.merge(exercise_id: exercise.id) + end + end + end + + attrs = %i[poll_id user_id created_at updated_at] + PollUser.bulk_insert(*attrs) do |worker| + student_ids.each do |user_id| + same_attrs = {user_id: user_id} + course.polls.each do |poll| + next if poll.poll_users.where(user_id: user_id).any? + worker.add same_attrs.merge(poll_id: poll.id) + end + end + end + + attrs = %i[graduation_task_id user_id course_id created_at updated_at] + GraduationWork.bulk_insert(*attrs) do |worker| + student_ids.each do |user_id| + same_attrs = {user_id: user_id, course_id: course.id} + course.graduation_tasks.each do |task| + next if task.graduation_works.where(user_id: user_id).any? + worker.add same_attrs.merge(graduation_task_id: task.id) + end end end end diff --git a/app/jobs/course_delete_student_delete_works_job.rb b/app/jobs/course_delete_student_delete_works_job.rb index 2eb3fb60e..9bdb93b87 100644 --- a/app/jobs/course_delete_student_delete_works_job.rb +++ b/app/jobs/course_delete_student_delete_works_job.rb @@ -1,7 +1,19 @@ class CourseDeleteStudentDeleteWorksJob < ApplicationJob queue_as :course_member - def perform(*args) - # Do something later + def perform(course_id, student_ids) + course = Course.find_by(id: course_id) + return if course.blank? + course = self.course + student_works = StudentWork.joins(:homework_common).where(user_id: student_ids, homework_commons: {course_id: course.id}) + student_works.update_all(is_delete: 1) + + exercise_users = ExerciseUser.joins(:exercise).where(user_id: student_ids, exercises: {course_id: course.id}) + exercise_users.update_all(is_delete: 1) + + poll_users = PollUser.joins(:poll).where(user_id: student_ids, polls: {course_id: course.id}) + poll_users.update_all(is_delete: 1) + + course.graduation_works.where(user_id: student_ids).update_all(is_delete: 1) end end diff --git a/app/models/course_member.rb b/app/models/course_member.rb index 87d4ffe88..52c13dbbf 100644 --- a/app/models/course_member.rb +++ b/app/models/course_member.rb @@ -20,8 +20,8 @@ class CourseMember < ApplicationRecord # 未分班 scope :ungroup_students, -> { where(course_group_id: 0, role: 4) } - after_destroy :delete_works - after_create :work_operation + # after_destroy :delete_works + # after_create :work_operation def delete_works if self.role == "STUDENT" course = self.course From 8828a04432d1e934e06b3ed785a14793516134fd Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 5 Jul 2019 14:17:50 +0800 Subject: [PATCH 0628/1015] =?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/jobs/course_delete_student_delete_works_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/course_delete_student_delete_works_job.rb b/app/jobs/course_delete_student_delete_works_job.rb index 9bdb93b87..c12762fbe 100644 --- a/app/jobs/course_delete_student_delete_works_job.rb +++ b/app/jobs/course_delete_student_delete_works_job.rb @@ -4,7 +4,7 @@ class CourseDeleteStudentDeleteWorksJob < ApplicationJob def perform(course_id, student_ids) course = Course.find_by(id: course_id) return if course.blank? - course = self.course + student_works = StudentWork.joins(:homework_common).where(user_id: student_ids, homework_commons: {course_id: course.id}) student_works.update_all(is_delete: 1) From b70179d967f1ea40c98f91d7482289cc7545c662 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 5 Jul 2019 14:36:20 +0800 Subject: [PATCH 0629/1015] =?UTF-8?q?=E6=95=B4=E7=BB=84=E5=90=8C=E8=AF=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 5d14a43ea..ef12e5650 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -730,19 +730,19 @@ class StudentWorksController < ApplicationController student_works.each do |st_work| st_score = StudentWorksScore.new(user_id: new_score.user_id, score: new_score.score, reviewer_role: new_score.reviewer_role, comment: new_score.comment) - st_work.student_works_scores << st_score - score = StudentWorksScore.where(user_id: new_score.user_id, student_work_id: st_work.id).last + score = StudentWorksScore.where(user_id: new_score.user_id, student_work_id: st_work.id, reviewer_role: new_score.reviewer_role).last # 该用户的历史评阅无效 score.update_column('is_invalid', true) if score.present? && score.score.present? + st_work.student_works_scores << st_score if new_score.reviewer_role == 1 - st_work.teacher_score = new_score.score + st_work.teacher_score = new_score.score if new_score.score.present? elsif new_score.reviewer_role == 2 if homework.homework_detail_manual.ta_mode == 1 - st_work.teaching_asistant_score = new_score.ta_score st_work.id + st_work.teaching_asistant_score = new_score.ta_score st_work.id if new_score.score.present? else - st_work.teaching_asistant_score = new_score.score + st_work.teaching_asistant_score = new_score.score if new_score.score.present? end else st_work.student_score = student_work.student_score From cedb27368ec4314152ff267bd9c042fe357f3413 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 14:40:34 +0800 Subject: [PATCH 0630/1015] fix bug --- app/controllers/zips_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 4089e5231..78151a78a 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -21,7 +21,10 @@ class ZipsController < ApplicationController file_name = filename_for_content_disposition(exercises.filename) - send_file exercises.ex_zip, filename: file_name, type: 'application/zip' + Rails.logger.info("################___________file_name________________###########{file_name}") + Rails.logger.info("################___________exercises.filename________________###########{exercises.filename}") + + send_file exercises.ex_zip, filename: file_name.encode(Encoding.default_external, 'gb2312'), type: 'application/zip' rescue Exception => e normal_status(-1, e.message) end From 83043baf61bbf95c7cc10d01f1c322f56b066ad8 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 14:43:10 +0800 Subject: [PATCH 0631/1015] fix bug --- app/controllers/zips_controller.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 78151a78a..67c8c74f7 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -10,7 +10,9 @@ class ZipsController < ApplicationController service = BatchExportShixunReportService.new(@homework, @all_student_works) filename = filename_for_content_disposition(service.filename) - send_file service.zip, filename: filename, type: 'application/zip' + Rails.logger.info("################___________file_name________________###########{filename}") + Rails.logger.info("################___________service.filename________________###########{service.filename}") + send_file service.zip, filename: filename.encode(Encoding.default_external, 'gb2312'), type: 'application/zip' rescue BatchExportShixunReportService::Error => ex normal_status(-1, ex.message) end @@ -21,10 +23,7 @@ class ZipsController < ApplicationController file_name = filename_for_content_disposition(exercises.filename) - Rails.logger.info("################___________file_name________________###########{file_name}") - Rails.logger.info("################___________exercises.filename________________###########{exercises.filename}") - - send_file exercises.ex_zip, filename: file_name.encode(Encoding.default_external, 'gb2312'), type: 'application/zip' + send_file exercises.ex_zip, filename: file_name, type: 'application/zip' rescue Exception => e normal_status(-1, e.message) end From 495c8d653e40abcf6f4c5f4b575da973f7c271a6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 5 Jul 2019 14:48:32 +0800 Subject: [PATCH 0632/1015] =?UTF-8?q?=E5=8A=A9=E6=95=99=E8=AF=84=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index ef12e5650..c85474a10 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -334,7 +334,6 @@ class StudentWorksController < ApplicationController ActiveRecord::Base.transaction do begin # 没传score则取上次评分成绩 - score = StudentWorksScore.where(user_id: current_user.id, student_work_id: @work.id).last new_score = StudentWorksScore.new new_score.score = params[:score].blank? ? score.try(:score) : params[:score].to_f new_score.comment = params[:comment] if params[:comment] && params[:comment].strip != "" @@ -348,7 +347,9 @@ class StudentWorksController < ApplicationController @work.update_attributes(group_id: @homework.max_group_id) if @homework.homework_type == "group" end - new_score.reviewer_role = @user_course_identity == Course::STUDENT ? 3 : @user_course_identity == Course::ASSISTANT_PROFESSOR ? 2 : 1 + reviewer_role = @user_course_identity == Course::STUDENT ? 3 : @user_course_identity == Course::ASSISTANT_PROFESSOR ? 2 : 1 + new_score.reviewer_role = reviewer_role + score = StudentWorksScore.where(user_id: current_user.id, student_work_id: @work.id, reviewer_role: reviewer_role).last if new_score.save! Attachment.associate_container(params[:attachment_ids], new_score.id, new_score.class) @@ -740,7 +741,7 @@ class StudentWorksController < ApplicationController st_work.teacher_score = new_score.score if new_score.score.present? elsif new_score.reviewer_role == 2 if homework.homework_detail_manual.ta_mode == 1 - st_work.teaching_asistant_score = new_score.ta_score st_work.id if new_score.score.present? + st_work.teaching_asistant_score = new_score.ta_score st_work.id else st_work.teaching_asistant_score = new_score.score if new_score.score.present? end From f6ae3f329328c1c99104af77506dc22c6b3efbe6 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 15:04:21 +0800 Subject: [PATCH 0633/1015] fixbug --- app/controllers/homework_commons_controller.rb | 2 +- app/controllers/zips_controller.rb | 5 ++--- app/helpers/export_helper.rb | 15 +++++++++++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 519c05c62..d09609bdc 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -208,7 +208,7 @@ class HomeworkCommonsController < ApplicationController student_work_to_xlsx(@work_excel,@homework) exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: + render xlsx: "#{exercise_export_name.encode('UTF-8', 'gb2312', {:invalid => :replace, :undef => :replace, :replace => ' '}).strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: {table_columns: @work_head_cells,task_users: @work_cells_column} } end diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 67c8c74f7..2b70b9b27 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -10,9 +10,8 @@ class ZipsController < ApplicationController service = BatchExportShixunReportService.new(@homework, @all_student_works) filename = filename_for_content_disposition(service.filename) - Rails.logger.info("################___________file_name________________###########{filename}") - Rails.logger.info("################___________service.filename________________###########{service.filename}") - send_file service.zip, filename: filename.encode(Encoding.default_external, 'gb2312'), type: 'application/zip' + + send_file service.zip, filename: filename, type: 'application/zip' rescue BatchExportShixunReportService::Error => ex normal_status(-1, ex.message) end diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index 839686f5b..7f64a99cd 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -40,10 +40,17 @@ module ExportHelper works.includes(user: :user_extension, student_works_scores: :user).each_with_index do |w, index| w_user = w.user w_1 = (index + 1) - w_2 = w_user.login - w_3 = w_user.real_name - w_3_1 = w_user.mail - w_4 = w_user.student_id.present? ? w_user.student_id : "--" + if w_user.present? + w_2 = w_user&.login + w_3 = w_user&.real_name + w_3_1 = w_user&.mail + w_4 = w_user.student_id.present? ? w_user.student_id : "--" + else + w_2 = "--" + w_3 = "--" + w_3_1 = "--" + w_4 = "--" + end course_name = course.students.find_by(user_id: w.user_id).try(:course_group_name) w_5 = course_name.present? ? course_name : "--" #0: 未提交, 1 按时提交, 2 延迟提交 From bcc66261c61f00e9c89a8412a1dbcc2764bcc711 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 15:09:03 +0800 Subject: [PATCH 0634/1015] fix bug --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index d09609bdc..d47ce609c 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -208,7 +208,7 @@ class HomeworkCommonsController < ApplicationController student_work_to_xlsx(@work_excel,@homework) exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') - render xlsx: "#{exercise_export_name.encode('UTF-8', 'gb2312', {:invalid => :replace, :undef => :replace, :replace => ' '}).strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: + render xlsx: "#{exercise_export_name.encode("GBK", :invalid => :replace, :undef => :replace, :replace => " ").strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: {table_columns: @work_head_cells,task_users: @work_cells_column} } end From 76646a3fbcd723f1aa58c5157afa8ee357e14b09 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 15:12:00 +0800 Subject: [PATCH 0635/1015] =?UTF-8?q?xlsx=E4=B8=8B=E8=BD=BD=E4=B9=B1?= =?UTF-8?q?=E7=A0=81=E8=A7=A3=E5=86=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index d47ce609c..794ccb228 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -208,9 +208,11 @@ class HomeworkCommonsController < ApplicationController student_work_to_xlsx(@work_excel,@homework) exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') - render xlsx: "#{exercise_export_name.encode("GBK", :invalid => :replace, :undef => :replace, :replace => " ").strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: + render xlsx: "#{exercise_export_name.encode(Encoding.default_external,"UTF-8", :invalid => :replace, :undef => :replace, :replace => " ").strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: {table_columns: @work_head_cells,task_users: @work_cells_column} } + + # .encode(Encoding.default_external, 'gb2312') end end elsif params[:format] == "zip" From 61f36ea2379deeabac7792e922872502e58d4a1f Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 5 Jul 2019 15:17:01 +0800 Subject: [PATCH 0636/1015] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E7=BC=BA=E8=AF=84?= =?UTF-8?q?=E6=89=A3=E5=88=86=E7=9A=84=E8=AE=A1=E7=AE=97=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/homework_evaluation.rake | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/tasks/homework_evaluation.rake b/lib/tasks/homework_evaluation.rake index 56c46179c..757b07877 100644 --- a/lib/tasks/homework_evaluation.rake +++ b/lib/tasks/homework_evaluation.rake @@ -60,9 +60,9 @@ namespace :homework_evaluation do HomeworkAnonymousAppealStartNotifyJob.perform_later(homework_common.id) else homework_detail_manual.update_column('comment_status', 5) + # 没有申诉阶段则直接计算缺评扣分 否则申诉结束时才计算 + HomeworkAbsencePenaltyCalculationJob.perform_later(homework_common.id) end - - HomeworkAbsencePenaltyCalculationJob.perform_later(homework_common.id) end end end @@ -71,5 +71,8 @@ namespace :homework_evaluation do task :end_appeal => :environment do homework_detail_manuals = HomeworkDetailManual.where("appeal_time <= '#{Time.now}' and homework_detail_manuals.comment_status = 4") homework_detail_manuals.update_all(:comment_status => 5) + homework_detail_manuals.each do |homework_detail_manual| + HomeworkAbsencePenaltyCalculationJob.perform_later(homework_detail_manual.homework_common_id) + end end end From 425a32680adbd8e7caa04804045ef0927adc8fa3 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 5 Jul 2019 15:35:37 +0800 Subject: [PATCH 0637/1015] =?UTF-8?q?=E6=95=99=E5=B8=88=E5=88=97=E8=A1=A8?= =?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/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 d7b039e02..0679e5619 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -284,7 +284,7 @@ class CoursesController < ApplicationController @is_admin = @user_course_identity < Course::PROFESSOR - @applications= CourseMessage.unhandled_join_course_requests_by_course(@course) + @applications = @is_admin ? CourseMessage.unhandled_join_course_requests_by_course(@course) : CourseMessage.none page = params[:page] || 1 limit = params[:limit] || 20 From df246f245c329c9a6a786455534a5adcb6bbcff5 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 15:36:24 +0800 Subject: [PATCH 0638/1015] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9F=A5=E9=87=8D?= =?UTF-8?q?=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 13 ++++++++++--- .../code_review_detail.json.jbuilder | 18 ------------------ .../get_challenge_detail.json.jbuilder | 17 +++++++++++++++++ config/routes.rb | 1 + 4 files changed, 28 insertions(+), 21 deletions(-) create mode 100644 app/views/homework_commons/get_challenge_detail.json.jbuilder diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 519c05c62..06326fe72 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -11,14 +11,14 @@ class HomeworkCommonsController < ApplicationController before_action :find_homework, only: [:edit, :show, :update, :group_list, :homework_code_repeat, :code_review_results, :code_review_detail, :show_comment, :settings, :works_list, :update_settings, :reference_answer, :publish_groups, :end_groups, :alter_name, :update_explanation, - :update_score, :update_student_score] + :update_score, :update_student_score, :get_challenge_detail] before_action :user_course_identity before_action :homework_publish, only: [:show, :works_list, :code_review_results, :show_comment, :settings, :reference_answer, :update_student_score] before_action :teacher_allowed, only: [:new, :edit, :create, :update, :shixuns, :subjects, :create_shixun_homework, :publish_homework, :end_homework, :set_public, :choose_category, :move_to_category, :choose_category, :create_subject_homework, :multi_destroy, :group_list, :homework_code_repeat, :code_review_results, :code_review_detail, :update_explanation, :update_settings, - :add_to_homework_bank, :publish_groups, :end_groups] + :add_to_homework_bank, :publish_groups, :end_groups, :get_challenge_detail] before_action :require_id_params, only: [:set_public, :multi_destroy, :publish_homework, :end_homework, :move_to_category, :add_to_homework_bank] before_action :course_manager, only: [:alter_name] @@ -1342,7 +1342,14 @@ class HomeworkCommonsController < ApplicationController end - # 代码查重详情 + # 代码查重关卡详情 + def get_challenge_detail + @student_work = @homework.student_works.find_by(user_id: params[:user_id]) + @user = @student_work.user + tip_exception("当前用户无作品可以显示") if @student_work.nil? + end + + # 代码查重代码的详情 def code_review_detail @student_work = @homework.student_works.find_by(user_id: params[:user_id]) @user = @student_work.user diff --git a/app/views/homework_commons/code_review_detail.json.jbuilder b/app/views/homework_commons/code_review_detail.json.jbuilder index 4ebabf20a..916e77c0f 100644 --- a/app/views/homework_commons/code_review_detail.json.jbuilder +++ b/app/views/homework_commons/code_review_detail.json.jbuilder @@ -1,21 +1,3 @@ -json.course_id @course.id -json.course_name @course.name -json.homework_common_id @homework.id -json.homework_common_name @homework.name -json.work_name @student_work.name -json.username @user.full_name -json.user_id @user.id -json.user_login @user.login - -json.work_score @student_work.work_score -if @student_work.ultimate_score - json.adjust_score @student_work.work_score < 0 ? 0 : number_with_precision(@student_work.work_score, precision: 1) -else - json.final_score @student_work.final_score - json.late_penalty @student_work.late_penalty - json.score @student_work.work_score < 0 ? 0 : number_with_precision(@student_work.work_score, precision: 1) -end - json.challenge_list do json.array! @challenges do |challenge| json.id challenge[:id] diff --git a/app/views/homework_commons/get_challenge_detail.json.jbuilder b/app/views/homework_commons/get_challenge_detail.json.jbuilder new file mode 100644 index 000000000..d3d6c2c1e --- /dev/null +++ b/app/views/homework_commons/get_challenge_detail.json.jbuilder @@ -0,0 +1,17 @@ +json.course_id @course.id +json.course_name @course.name +json.homework_common_id @homework.id +json.homework_common_name @homework.name +json.work_name @student_work.name +json.username @user.full_name +json.user_id @user.id +json.user_login @user.login + +json.work_score @student_work.work_score +if @student_work.ultimate_score + json.adjust_score @student_work.work_score < 0 ? 0 : number_with_precision(@student_work.work_score, precision: 1) +else + json.final_score @student_work.final_score + json.late_penalty @student_work.late_penalty + json.score @student_work.work_score < 0 ? 0 : number_with_precision(@student_work.work_score, precision: 1) +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index cf5bad608..395ce0ef9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -337,6 +337,7 @@ Rails.application.routes.draw do post :homework_code_repeat get :code_review_results get :code_review_detail + get :get_challenge_detail post :update_explanation get :show_comment get :settings From 118d27c649cbc0642247d3b1638c4c5a27ec2cff Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 15:45:15 +0800 Subject: [PATCH 0639/1015] fix bug --- app/controllers/homework_commons_controller.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 794ccb228..1318f3b04 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -204,15 +204,17 @@ class HomeworkCommonsController < ApplicationController normal_status(-1,"暂无用户提交!") else respond_to do |format| + format.json{normal_status(0,"000000")} format.xlsx{ student_work_to_xlsx(@work_excel,@homework) exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') - - render xlsx: "#{exercise_export_name.encode(Encoding.default_external,"UTF-8", :invalid => :replace, :undef => :replace, :replace => " ").strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: + response.headers['Content-Disposition'] = "attachment; filename=\"#{exercise_export_name.strip.first(30)}\"" + render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: {table_columns: @work_head_cells,task_users: @work_cells_column} } + # send_data data, :type => 'text/csv', :disposition => 'attachment; filename=my_file_name.csv' - # .encode(Encoding.default_external, 'gb2312') + # .encode(Encoding.default_external, 'gb2312') end end elsif params[:format] == "zip" From 82b0f0f0f5cc1683955c32741ba25d82137ab542 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 15:53:26 +0800 Subject: [PATCH 0640/1015] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9F=A5=E9=87=8D?= =?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/controllers/homework_commons_controller.rb | 11 ++--------- .../code_review_detail.json.jbuilder | 18 ++++++++++++++++++ .../get_challenge_detail.json.jbuilder | 17 ----------------- config/routes.rb | 1 - 4 files changed, 20 insertions(+), 27 deletions(-) delete mode 100644 app/views/homework_commons/get_challenge_detail.json.jbuilder diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 025218424..f0703d1f0 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -11,14 +11,14 @@ class HomeworkCommonsController < ApplicationController before_action :find_homework, only: [:edit, :show, :update, :group_list, :homework_code_repeat, :code_review_results, :code_review_detail, :show_comment, :settings, :works_list, :update_settings, :reference_answer, :publish_groups, :end_groups, :alter_name, :update_explanation, - :update_score, :update_student_score, :get_challenge_detail] + :update_score, :update_student_score] before_action :user_course_identity before_action :homework_publish, only: [:show, :works_list, :code_review_results, :show_comment, :settings, :reference_answer, :update_student_score] before_action :teacher_allowed, only: [:new, :edit, :create, :update, :shixuns, :subjects, :create_shixun_homework, :publish_homework, :end_homework, :set_public, :choose_category, :move_to_category, :choose_category, :create_subject_homework, :multi_destroy, :group_list, :homework_code_repeat, :code_review_results, :code_review_detail, :update_explanation, :update_settings, - :add_to_homework_bank, :publish_groups, :end_groups, :get_challenge_detail] + :add_to_homework_bank, :publish_groups, :end_groups] before_action :require_id_params, only: [:set_public, :multi_destroy, :publish_homework, :end_homework, :move_to_category, :add_to_homework_bank] before_action :course_manager, only: [:alter_name] @@ -1346,13 +1346,6 @@ class HomeworkCommonsController < ApplicationController end - # 代码查重关卡详情 - def get_challenge_detail - @student_work = @homework.student_works.find_by(user_id: params[:user_id]) - @user = @student_work.user - tip_exception("当前用户无作品可以显示") if @student_work.nil? - end - # 代码查重代码的详情 def code_review_detail @student_work = @homework.student_works.find_by(user_id: params[:user_id]) diff --git a/app/views/homework_commons/code_review_detail.json.jbuilder b/app/views/homework_commons/code_review_detail.json.jbuilder index 916e77c0f..4ebabf20a 100644 --- a/app/views/homework_commons/code_review_detail.json.jbuilder +++ b/app/views/homework_commons/code_review_detail.json.jbuilder @@ -1,3 +1,21 @@ +json.course_id @course.id +json.course_name @course.name +json.homework_common_id @homework.id +json.homework_common_name @homework.name +json.work_name @student_work.name +json.username @user.full_name +json.user_id @user.id +json.user_login @user.login + +json.work_score @student_work.work_score +if @student_work.ultimate_score + json.adjust_score @student_work.work_score < 0 ? 0 : number_with_precision(@student_work.work_score, precision: 1) +else + json.final_score @student_work.final_score + json.late_penalty @student_work.late_penalty + json.score @student_work.work_score < 0 ? 0 : number_with_precision(@student_work.work_score, precision: 1) +end + json.challenge_list do json.array! @challenges do |challenge| json.id challenge[:id] diff --git a/app/views/homework_commons/get_challenge_detail.json.jbuilder b/app/views/homework_commons/get_challenge_detail.json.jbuilder deleted file mode 100644 index d3d6c2c1e..000000000 --- a/app/views/homework_commons/get_challenge_detail.json.jbuilder +++ /dev/null @@ -1,17 +0,0 @@ -json.course_id @course.id -json.course_name @course.name -json.homework_common_id @homework.id -json.homework_common_name @homework.name -json.work_name @student_work.name -json.username @user.full_name -json.user_id @user.id -json.user_login @user.login - -json.work_score @student_work.work_score -if @student_work.ultimate_score - json.adjust_score @student_work.work_score < 0 ? 0 : number_with_precision(@student_work.work_score, precision: 1) -else - json.final_score @student_work.final_score - json.late_penalty @student_work.late_penalty - json.score @student_work.work_score < 0 ? 0 : number_with_precision(@student_work.work_score, precision: 1) -end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 395ce0ef9..cf5bad608 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -337,7 +337,6 @@ Rails.application.routes.draw do post :homework_code_repeat get :code_review_results get :code_review_detail - get :get_challenge_detail post :update_explanation get :show_comment get :settings From 1a2067698c97622947cc7e5741fb138cbe84a0c1 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 16:06:19 +0800 Subject: [PATCH 0641/1015] fixbug --- app/controllers/homework_commons_controller.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 1318f3b04..cfa54e721 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -204,17 +204,14 @@ class HomeworkCommonsController < ApplicationController normal_status(-1,"暂无用户提交!") else respond_to do |format| - format.json{normal_status(0,"000000")} format.xlsx{ student_work_to_xlsx(@work_excel,@homework) exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') - response.headers['Content-Disposition'] = "attachment; filename=\"#{exercise_export_name.strip.first(30)}\"" + response.set_header("Content-Disposition","attachment; filename=#{exercise_export_name.strip.first(30)}};filename*=utf-8''#{exercise_export_name.strip.first(30)}}") + # response.setHeader['Content-Disposition'] = "attachment; filename=\"#{exercise_export_name.strip.first(30)}\"" render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: {table_columns: @work_head_cells,task_users: @work_cells_column} } - # send_data data, :type => 'text/csv', :disposition => 'attachment; filename=my_file_name.csv' - - # .encode(Encoding.default_external, 'gb2312') end end elsif params[:format] == "zip" From 457b4fdf0f1f3b836c66b7c067dfc39013993fa5 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 5 Jul 2019 16:28:58 +0800 Subject: [PATCH 0642/1015] =?UTF-8?q?=E5=8C=BF=E8=AF=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index c85474a10..ed642a557 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -382,7 +382,7 @@ class StudentWorksController < ApplicationController when 3 #学生评分 学生评分显示平均分 # 匿评分 @work.student_score = new_score.stu_score(@work.id) - if @homework.homework_type == "group" && params[:same_score] && new_score.score.present? + if @homework.homework_type == "group" && new_score.score.present? add_score_to_member @work, @homework, new_score end From 0a7715cbc5b5ba001ded6ebae35aa0c1351654c6 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 16:44:52 +0800 Subject: [PATCH 0643/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E9=94=81?= =?UTF-8?q?=E6=A0=87=E5=BF=97=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 55ade6e7c..6e3ef835e 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -260,6 +260,7 @@ module ExercisesHelper def exercise_index_show(exercise,course,is_teacher_or,user) # exercise_all_users = exercise.exercise_users + # lock_icon 0不出现锁,1和2均出现锁。但是1仅表示私有,可点击,2表示私有,且不点击 ex_show_text = [] if course.is_end #课堂停止后,试卷显示为已结束 @@ -280,6 +281,7 @@ module ExercisesHelper else ex_show_text end + if is_teacher_or == 1 exercise_users_list = exercise.all_exercise_users(user.id) #当前老师所在班级的全部学生 unreview_count = exercise_users_list.exercise_unreview.size @@ -288,7 +290,7 @@ module ExercisesHelper exercise_publish_time = ex_pb_time[:publish_time] exercise_end_time = ex_pb_time[:end_time] current_status = 3 - lock_icon = 1 #不显示锁图标 + lock_icon = 1 if exercise_status == 1 ex_show_text.push("未发布") elsif exercise_status == 3 @@ -302,7 +304,7 @@ module ExercisesHelper exercise_publish_time = ex_pb_time[:publish_time] exercise_end_time = ex_pb_time[:end_time] current_status = exercise.check_user_answer_status(user) - lock_icon = 1 #不显示锁图标 + lock_icon = 1 if current_status == 4 ex_show_text.push("未提交") end @@ -314,16 +316,20 @@ module ExercisesHelper unreview_count = nil if exercise.is_public current_status = exercise.check_user_answer_status(user) - lock_icon = 1 #非课堂成员,但是试卷为公开的,不加锁 + lock_icon = 0 #不出现锁 if current_status == 4 ex_show_text.push("未提交") end else current_status = 4 - lock_icon = 0 #显示锁图标 + lock_icon = 2 end end + if (course.is_public == 1) && exercise.is_public + lock_icon = 0 + end + if exercise_status > 1 show_unreview_count = unreview_count else @@ -332,8 +338,6 @@ module ExercisesHelper if exercise_status == 2 && exercise_end_time.present? ex_left_time = how_much_time(exercise_end_time) - # elsif exercise_status == 3 && course.end_date.present? - # ex_left_time = how_much_time(course.end_date.to_time) else #已截止后不显示时间 ex_left_time = nil end From ddd24d9acaa50c43d904cbde28db9da4683e8a55 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 17:43:05 +0800 Subject: [PATCH 0644/1015] fix bug --- app/controllers/exercises_controller.rb | 13 +++++----- .../homework_commons_controller.rb | 3 ++- app/helpers/exercises_helper.rb | 24 +++++++++---------- app/models/exercise.rb | 10 ++++---- 4 files changed, 24 insertions(+), 26 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 49dd7edb9..c017d4dc1 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -44,25 +44,24 @@ class ExercisesController < ApplicationController # exercises的不同用户群体的显示 if @user_course_identity < Course::STUDENT # @is_teacher_or 1为老师/管理员/助教 @is_teacher_or = 1 - # @teacher_groups_ids = @course.teacher_course_groups.get_user_groups(current_user.id).pluck(:course_group_id).reject(&:blank?) - @exercises = @exercises_all #老师能看到全部的试卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同) + @exercises = @exercises_all #老师能看到全部的试卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同) elsif @user_course_identity == Course::STUDENT # 2为课堂成员,能看到统一设置的和自己班级的 @is_teacher_or = 2 # get_exercise_left_time(@exercise,current_user) member_group_id = @current_student.first.try(:course_group_id).to_i # 成员的分班id,默认为0 if member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的) - @exercises = member_show_exercises.present? ? member_show_exercises.unified_setting : [] + @exercises = member_show_exercises.exists? ? member_show_exercises.unified_setting : [] else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷 # 已发布 当前用户班级分组的 试卷id exercise_settings_ids = @course.exercise_group_settings.exercise_group_published .where(course_group_id: member_group_id).pluck(:exercise_id).uniq - @exercises = member_show_exercises.present? ? + @exercises = member_show_exercises.exists? ? member_show_exercises.unified_setting.or(member_show_exercises.where(id: exercise_settings_ids)) : [] end else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁 @is_teacher_or = 0 - @exercises = member_show_exercises.present? ? member_show_exercises.unified_setting : [] + @exercises = member_show_exercises.exists? ? member_show_exercises.unified_setting : [] end if @exercises.size > 0 if params[:type].present? @@ -74,12 +73,12 @@ class ExercisesController < ApplicationController exercise_settings_ids = exercise_groups_sets.pluck(:exercise_id) exercise_ended_ids = exercise_groups_sets.exercise_group_ended.pluck(:exercise_id).uniq if choose_type == 2 - @exercises = @exercises_all.present? ? + @exercises = @exercises_all.exists? ? @exercises_all.exercise_by_status(2).unified_setting .or(@exercises_all.where(id: (exercise_settings_ids - exercise_ended_ids).uniq)) : [] elsif choose_type == 3 - @exercises = @exercises_all.present? ? + @exercises = @exercises_all.exists? ? @exercises_all.exercise_by_status(3).unified_setting .or(@exercises_all.where(id: exercise_ended_ids)) : [] diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index bd7a36e98..a04d2b1a8 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -208,8 +208,9 @@ class HomeworkCommonsController < ApplicationController student_work_to_xlsx(@work_excel,@homework) exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') response.set_header("Content-Disposition","attachment; filename=#{exercise_export_name.strip.first(30)}};filename*=utf-8''#{exercise_export_name.strip.first(30)}}") + file_name = Base64.urlsafe_encode64(exercise_export_name.strip.first(30)) # response.setHeader['Content-Disposition'] = "attachment; filename=\"#{exercise_export_name.strip.first(30)}\"" - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: + render xlsx: "#{file_name}",template: "homework_commons/works_list.xlsx.axlsx",locals: {table_columns: @work_head_cells,task_users: @work_cells_column} } end diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 6e3ef835e..96507d002 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -251,16 +251,14 @@ module ExercisesHelper #获取试卷的已答/未答人数 def get_exercise_answers(ex_users) - @commit_ex_users = ex_users.commit_exercise_by_status(1) #当前老师的全部学生中已提交的 - - @exercise_answers = @commit_ex_users.present? ? @commit_ex_users.size : 0 #表示已经提交了的用户 - course_all_members_count = ex_users.present? ? ex_users.size : 0 + @exercise_answers = ex_users.commit_exercise_by_status(1).size #表示已经提交了的用户 + course_all_members_count = ex_users.exists? ? ex_users.size : 0 @exercise_unanswers = (course_all_members_count - @exercise_answers) end def exercise_index_show(exercise,course,is_teacher_or,user) # exercise_all_users = exercise.exercise_users - # lock_icon 0不出现锁,1和2均出现锁。但是1仅表示私有,可点击,2表示私有,且不点击 + # lock_icon 0出现锁,1不出现锁 ex_show_text = [] if course.is_end #课堂停止后,试卷显示为已结束 @@ -290,7 +288,7 @@ module ExercisesHelper exercise_publish_time = ex_pb_time[:publish_time] exercise_end_time = ex_pb_time[:end_time] current_status = 3 - lock_icon = 1 + lock_icon = 0 if exercise_status == 1 ex_show_text.push("未发布") elsif exercise_status == 3 @@ -304,7 +302,7 @@ module ExercisesHelper exercise_publish_time = ex_pb_time[:publish_time] exercise_end_time = ex_pb_time[:end_time] current_status = exercise.check_user_answer_status(user) - lock_icon = 1 + lock_icon = 0 if current_status == 4 ex_show_text.push("未提交") end @@ -316,18 +314,18 @@ module ExercisesHelper unreview_count = nil if exercise.is_public current_status = exercise.check_user_answer_status(user) - lock_icon = 0 #不出现锁 + lock_icon = 1 #不出现锁 if current_status == 4 ex_show_text.push("未提交") end else current_status = 4 - lock_icon = 2 + lock_icon = 0 end end if (course.is_public == 1) && exercise.is_public - lock_icon = 0 + lock_icon = 1 end if exercise_status > 1 @@ -336,7 +334,7 @@ module ExercisesHelper show_unreview_count = nil end - if exercise_status == 2 && exercise_end_time.present? + if exercise_status == 2 && exercise_end_time.exists? ex_left_time = how_much_time(exercise_end_time) else #已截止后不显示时间 ex_left_time = nil @@ -725,8 +723,8 @@ module ExercisesHelper if ex_time > 0 exercise_user = exercise.exercise_users.find_by(user_id:user.id) time_mill = ex_time * 60 #转为秒 - exercise_end_time = exercise.end_time.present? ? exercise.end_time.to_i : 0 - exercise_user_start = exercise_user&.start_at.present? ? exercise_user.start_at.to_i : 0 + exercise_end_time = exercise.end_time.exists? ? exercise.end_time.to_i : 0 + exercise_user_start = exercise_user&.start_at.exists? ? exercise_user.start_at.to_i : 0 #用户未开始答题时,即exercise_user_start为0 if exercise_user_start == 0 if (exercise_end_time - time_now_i) > time_mill diff --git a/app/models/exercise.rb b/app/models/exercise.rb index ed003286b..d6e9269cc 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -130,11 +130,11 @@ class Exercise < ApplicationRecord else ex_group_setting = exercise_group_settings user_group = course.students.course_find_by_ids("user_id",user_id) - if user_group.present? + if user_group.exists? user_group_id = user_group.first.course_group_id user_ex_group_setting = ex_group_setting.find_in_exercise_group("course_group_id",user_group_id) - pb_time = user_ex_group_setting.present? ? user_ex_group_setting.first.publish_time : nil - en_time = user_ex_group_setting.present? ? user_ex_group_setting.first.end_time : nil + pb_time = user_ex_group_setting.exists? ? user_ex_group_setting.first.publish_time : nil + en_time = user_ex_group_setting.exists? ? user_ex_group_setting.first.end_time : nil else pb_time = nil en_time = nil @@ -152,10 +152,10 @@ class Exercise < ApplicationRecord ex_answer_user = exercise_users.find_by(user_id: user.id) user_ex_status = get_exercise_status(user.id) user_status = 2 - if ex_answer_user.present? && (ex_answer_user.start_at.present? || ex_answer_user.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 + if ex_answer_user.exists? && (ex_answer_user.start_at.exists? || ex_answer_user.end_at.exists?) #学生有过答题的,或者立即截止,但学生未做试卷的 user_status = ex_answer_user.commit_status end - if ex_answer_user.present? && ex_answer_user.start_at.blank? && user_ex_status == 3 + if ex_answer_user.exists? && ex_answer_user.start_at.blank? && user_ex_status == 3 user_status = 4 end From 16f53062ee3ccba69d0ba82699a9c6a7cc522ae6 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 18:00:35 +0800 Subject: [PATCH 0645/1015] fixbug --- app/controllers/exercises_controller.rb | 13 ++++--- .../homework_commons_controller.rb | 4 +- app/views/exercises/index.json.jbuilder | 37 ++++++++++--------- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index c017d4dc1..7426a40d5 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -32,13 +32,9 @@ class ExercisesController < ApplicationController @exercises_all = @course.exercises member_show_exercises = @exercises_all.is_exercise_published #已发布的或已截止的试卷 @current_user_ = current_user - @exercises_count = @exercises_all.size # 全部页面,需返回 - @exercises_unpublish_counts = @exercises_all.exercise_by_status(1).size #未发布的试卷数 - @exercises_published_counts = @exercises_all.exercise_by_status([2,3]).size # 已发布的试卷数,包含已截止的 - @exercises_ended_counts = @exercises_all.exercise_by_status(3).size #已截止的试卷数 + # 课堂的学生人数 @course_all_members = @course.students #当前课堂的全部学生 - @course_all_members_count = @course_all_members.size #当前课堂的学生数 @current_student = @course_all_members.course_find_by_ids("user_id",current_user.id) #当前用户是否为课堂的学生 # exercises的不同用户群体的显示 @@ -63,6 +59,7 @@ class ExercisesController < ApplicationController @is_teacher_or = 0 @exercises = member_show_exercises.exists? ? member_show_exercises.unified_setting : [] end + if @exercises.size > 0 if params[:type].present? choose_type = params[:type].to_i @@ -105,6 +102,12 @@ class ExercisesController < ApplicationController @exercises = [] end + @course_all_members_count = @course_all_members.size #当前课堂的学生数 + @exercises_count = @exercises_all.size # 全部页面,需返回 + @exercises_unpublish_counts = @exercises_all.exercise_by_status(1).size #未发布的试卷数 + @exercises_published_counts = @exercises_all.exercise_by_status([2,3]).size # 已发布的试卷数,包含已截止的 + @exercises_ended_counts = @exercises_all.exercise_by_status(3).size #已截止的试卷数 + rescue Exception => e uid_logger_error(e.message) tip_exception(e.message) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index a04d2b1a8..355a8d8e3 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -207,8 +207,8 @@ class HomeworkCommonsController < ApplicationController format.xlsx{ student_work_to_xlsx(@work_excel,@homework) exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') - response.set_header("Content-Disposition","attachment; filename=#{exercise_export_name.strip.first(30)}};filename*=utf-8''#{exercise_export_name.strip.first(30)}}") - file_name = Base64.urlsafe_encode64(exercise_export_name.strip.first(30)) + # response.set_header("Content-Disposition","attachment; filename=#{exercise_export_name.strip.first(30)}};filename*=utf-8''#{exercise_export_name.strip.first(30)}}") + file_name = Base64.encode64(exercise_export_name.strip.first(30)) # response.setHeader['Content-Disposition'] = "attachment; filename=\"#{exercise_export_name.strip.first(30)}\"" render xlsx: "#{file_name}",template: "homework_commons/works_list.xlsx.axlsx",locals: {table_columns: @work_head_cells,task_users: @work_cells_column} diff --git a/app/views/exercises/index.json.jbuilder b/app/views/exercises/index.json.jbuilder index 4694ecdf0..4c143da4b 100644 --- a/app/views/exercises/index.json.jbuilder +++ b/app/views/exercises/index.json.jbuilder @@ -1,22 +1,4 @@ -json.exercises_counts do - json.exercises_total_counts @exercises_count #全部试卷数 - json.exercises_all_counts @exercises_select_count #选择后的全部试卷数 - json.exercises_unpublish_counts @exercises_unpublish_counts #未发布试卷数 - json.exercises_published_counts @exercises_published_counts #已发布试卷数 - json.exercises_ended_counts @exercises_ended_counts #已截止试卷数 - json.left_banner_id @left_banner_id - json.left_banner_name @left_banner_name -end - -json.course_types do - json.course_status @course.is_end ? 1 : 0 #课堂的当前是否结束,如结束,则为1,否则为0 - json.course_end_time @course.end_date #课堂的截止时间 - json.course_is_public @course.is_public #判断课堂是否为公开,只有公开课才有设为公开的按钮 - json.user_permission @is_teacher_or # 当前用户存在且为课堂教师/管理员/超级管理员时为1 ,课堂成员为2,否则为0 -end - - if @exercises_count > 0 json.exercises do json.array! @exercises do |exercise| @@ -43,3 +25,22 @@ else json.exercises [] end +json.course_types do + json.course_status @course.is_end ? 1 : 0 #课堂的当前是否结束,如结束,则为1,否则为0 + json.course_end_time @course.end_date #课堂的截止时间 + json.course_is_public @course.is_public #判断课堂是否为公开,只有公开课才有设为公开的按钮 + json.user_permission @is_teacher_or # 当前用户存在且为课堂教师/管理员/超级管理员时为1 ,课堂成员为2,否则为0 +end + +json.exercises_counts do + json.exercises_total_counts @exercises_count #全部试卷数 + json.exercises_all_counts @exercises_select_count #选择后的全部试卷数 + json.exercises_unpublish_counts @exercises_unpublish_counts #未发布试卷数 + json.exercises_published_counts @exercises_published_counts #已发布试卷数 + json.exercises_ended_counts @exercises_ended_counts #已截止试卷数 + json.left_banner_id @left_banner_id + json.left_banner_name @left_banner_name +end + + + From 9b8887fa0f217efb16b980d75606445c78c20b10 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 18:09:44 +0800 Subject: [PATCH 0646/1015] fixbug --- app/helpers/exercises_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 96507d002..fe29497d0 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -334,7 +334,7 @@ module ExercisesHelper show_unreview_count = nil end - if exercise_status == 2 && exercise_end_time.exists? + if exercise_status == 2 && exercise_end_time.present? ex_left_time = how_much_time(exercise_end_time) else #已截止后不显示时间 ex_left_time = nil From f6a6a5e98da0a15cfcd718bcff6d4c981d69f6f6 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 18:21:22 +0800 Subject: [PATCH 0647/1015] fixbug --- app/controllers/exercises_controller.rb | 3 +-- app/models/exercise.rb | 12 ++---------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 7426a40d5..9087aeee6 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -105,8 +105,7 @@ class ExercisesController < ApplicationController @course_all_members_count = @course_all_members.size #当前课堂的学生数 @exercises_count = @exercises_all.size # 全部页面,需返回 @exercises_unpublish_counts = @exercises_all.exercise_by_status(1).size #未发布的试卷数 - @exercises_published_counts = @exercises_all.exercise_by_status([2,3]).size # 已发布的试卷数,包含已截止的 - @exercises_ended_counts = @exercises_all.exercise_by_status(3).size #已截止的试卷数 + @exercises_published_counts = @exercises_count - @exercises_unpublish_counts # 已发布的试卷数,包含已截止的 rescue Exception => e uid_logger_error(e.message) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index d6e9269cc..42b737c26 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -69,11 +69,7 @@ class Exercise < ApplicationRecord def common_published_ids(user_id) current_user_groups = course.teacher_course_ids(user_id) if unified_setting - if course.none_group_count > 0 #有未分班的,则发布到未发布分班 - un_group_ids = [0] - else - un_group_ids = [] - end + un_group_ids = (course.none_group_count > 0) ? [0] : [] published_group_ids = (current_user_groups + un_group_ids).uniq #统一设置时,为当前用户的分班id及未分班 else ex_group_setting = exercise_group_settings.pluck("course_group_id").uniq @@ -89,11 +85,7 @@ class Exercise < ApplicationRecord ex_group_settings = exercise_group_settings.pluck(:course_group_id) member = course.course_members.course_find_by_ids("user_id",user_id) member_group_id = member.pluck(:course_group_id).uniq - if (member_group_id & ex_group_settings).size > 0 || user_identity < Course::STUDENT - true - else - false - end + ((member_group_id & ex_group_settings).size > 0 || user_identity < Course::STUDENT) ? true : false end #判断是否为分班,如果分班,试卷的截止时间为当前分班时间,否则为试卷的截止时间 From ade4ffb7076f521c8b6653a6dd2b1f8d82c22e1b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 20:52:31 +0800 Subject: [PATCH 0648/1015] fixbug --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 355a8d8e3..b12980094 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -208,7 +208,7 @@ class HomeworkCommonsController < ApplicationController student_work_to_xlsx(@work_excel,@homework) exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') # response.set_header("Content-Disposition","attachment; filename=#{exercise_export_name.strip.first(30)}};filename*=utf-8''#{exercise_export_name.strip.first(30)}}") - file_name = Base64.encode64(exercise_export_name.strip.first(30)) + file_name = Base64.urlsafe_encode64(exercise_export_name.strip.first(30)) # response.setHeader['Content-Disposition'] = "attachment; filename=\"#{exercise_export_name.strip.first(30)}\"" render xlsx: "#{file_name}",template: "homework_commons/works_list.xlsx.axlsx",locals: {table_columns: @work_head_cells,task_users: @work_cells_column} From fe77865779b79b87b42843aa3484209325b71a3f Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 6 Jul 2019 09:01:15 +0800 Subject: [PATCH 0649/1015] =?UTF-8?q?=E8=AF=84=E6=B5=8B=E5=8A=A0=E5=85=A5s?= =?UTF-8?q?ec=5Fkey?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 3 ++- app/controllers/gits_controller.rb | 9 +++++++-- app/controllers/myshixuns_controller.rb | 8 +++----- db/migrate/20190705085829_add_sec_key_to_outputs.rb | 5 +++++ 4 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20190705085829_add_sec_key_to_outputs.rb diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 7e7b6e082..41af7ae68 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -501,6 +501,7 @@ class GamesController < ApplicationController # 编程题评测 def game_build + sec_key = params[:sec_key] game_challenge = Challenge.select([:id, :position, :picture_path]).find(@game.challenge_id) # 更新评测次数 @@ -548,7 +549,7 @@ class GamesController < ApplicationController :instanceChallenge => "#{step}", :testCases => "#{testCases}", :resubmit => "#{resubmit}", :times => params[:first].to_i, :podType => @shixun.webssh, :content_modified => content_modified, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(@shixun))}", - :persistenceName => @shixun.identifier, :tpmScript => "#{tpmScript}", + :persistenceName => @shixun.identifier, :tpmScript => "#{tpmScript}", :sec_key => sec_key, :timeLimit => "#{@shixun.exec_time}", :isPublished => (@shixun.status < 2 ? 0 : 1) } # 评测有文件输出的需要特殊传字段 path:表示文件存储的位置 diff --git a/app/controllers/gits_controller.rb b/app/controllers/gits_controller.rb index f00245190..1965f61ba 100644 --- a/app/controllers/gits_controller.rb +++ b/app/controllers/gits_controller.rb @@ -1,10 +1,15 @@ class GitsController < ApplicationController - #供git-workhorse反向调用认证 + # 说明: + # 以下Git认证只针对新版git,Gitlab的Git认证不走该控制器 + # 思路: + # 1、用户通过Git客户端推送代码的时候,这个时候Git客户端肯定会强制用户输入邮箱的 + # 2、通过web端版本库界面更新代码(如果用户邮箱不存在,则用系统备用邮箱) + # 供 git-workhorse反向调用认证 def auth # HTTP_AUTHORIZATION: "Basic 这里base64编码的的密码(user:passwd)" logger.info("11111112222223333 HTTP_AUTHORIZATION: #{request.env["HTTP_AUTHORIZATION"]}") - #logger.info("#########-----request_env: #{request.env}") + # logger.info("#########-----request_env: #{request.env}") # {"service"=>"git-receive-pack", "controller"=>"gits", "action"=>"auth", # "url"=>"forge01/cermyt39.git/info/refs"} # diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 3abc71fd0..499612167 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -85,9 +85,6 @@ class MyshixunsController < ApplicationController # "createPod":"1.610","evaluateAllTime":2820,"evaluateStart":"2017-11-24 11:04:35","execute":"0.294"}' # params[:pics] = "a.png,b.png,c.png" def training_task_status - logger.info("123################{params[:jsonTestDetails]}") - logger.info("456################{params[:timeCost]}") - logger.info("666###############{params}") ActiveRecord::Base.transaction do begin @@ -98,13 +95,14 @@ class MyshixunsController < ApplicationController return_back_time = format("%.3f", ( t1.to_f - brige_end_time.to_f)).to_f status = jsonTestDetails['status'] game_id = jsonTestDetails['buildID'] + sec_key = jsonTestDetails['sec_key'] logger.info("training_task_status start#1**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") resubmit = jsonTestDetails['resubmit'] outPut = tran_base64_decode64(jsonTestDetails['outPut']) jenkins_testsets = jsonTestDetails['msg'] compile_success = jsonTestDetails['compileSuccess'] # message = Base64.decode64(params[:msg]) unless params[:msg].blank? - logger.info(outPut) + game = Game.find(game_id) myshixun = game.myshixun challenge = game.challenge @@ -125,7 +123,7 @@ class MyshixunsController < ApplicationController logger.info "actual_output:################################################# #{actual_output}" Output.create!(:code => status, :game_id => game_id, :out_put => outPut, :test_set_position => j_test_set['caseId'], :actual_output => actual_output, :result => j_test_set['passed'].to_i, :query_index => max_query_index, - :compile_success => compile_success.to_i) + :compile_success => compile_success.to_i, :sec_key => sec_key) # 如果设置了按测试集给分,则需要统计测试集的分值 if challenge.test_set_score && j_test_set['passed'].to_i == 1 test_set_score += challenge.test_sets.where(:position => j_test_set['caseId']).pluck(:score).first diff --git a/db/migrate/20190705085829_add_sec_key_to_outputs.rb b/db/migrate/20190705085829_add_sec_key_to_outputs.rb new file mode 100644 index 000000000..428fbaced --- /dev/null +++ b/db/migrate/20190705085829_add_sec_key_to_outputs.rb @@ -0,0 +1,5 @@ +class AddSecKeyToOutputs < ActiveRecord::Migration[5.2] + def change + add_column :outputs, :sec_key, :string + end +end From e6999da273e6b1850297ec1504d6bc16b6aed3e2 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 6 Jul 2019 09:19:47 +0800 Subject: [PATCH 0650/1015] user interest api --- app/controllers/users/interests_controller.rb | 25 +++++++++++++++++++ app/models/repertoire.rb | 1 + app/models/user.rb | 4 +++ app/models/user_interest.rb | 4 +++ config/routes.rb | 1 + .../20190706010307_create_user_interests.rb | 8 ++++++ 6 files changed, 43 insertions(+) create mode 100644 app/controllers/users/interests_controller.rb create mode 100644 app/models/user_interest.rb create mode 100644 db/migrate/20190706010307_create_user_interests.rb diff --git a/app/controllers/users/interests_controller.rb b/app/controllers/users/interests_controller.rb new file mode 100644 index 000000000..ca5f63af9 --- /dev/null +++ b/app/controllers/users/interests_controller.rb @@ -0,0 +1,25 @@ +class Users::InterestsController < Users::BaseController + before_action :require_login + before_action :private_user_resources! + + def create + identity = params[:identity].to_s.strip + + extension = observed_user.user_extension || observed_user.build_user_extension + return render_error('请选择职业') unless %w(teacher student professional).include?(identity) + + ActiveRecord::Base.transaction do + extension.update_column(:identity, identity) + + # 兴趣 + observed_user.user_interests.delete_all + UserInterest.bulk_insert(:user_id, :repertoire_id) do |worker| + (Repertoire.pluck(:id) & Array.wrap(params[:interest_ids]).map(&:to_i)).each do |repertoire_id| + worker.add(user_id: observed_user.id, repertoire_id: repertoire_id) + end + end + end + + render_ok + end +end \ No newline at end of file diff --git a/app/models/repertoire.rb b/app/models/repertoire.rb index d76a022c5..72e1ebfff 100644 --- a/app/models/repertoire.rb +++ b/app/models/repertoire.rb @@ -2,4 +2,5 @@ class Repertoire < ApplicationRecord has_many :sub_repertoires, ->{order(updated_at: :desc)}, :dependent => :destroy has_many :tag_repertoires, through: :sub_repertoires + has_many :user_interests, dependent: :delete_all end diff --git a/app/models/user.rb b/app/models/user.rb index e775af5f8..7e04ff423 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -115,6 +115,10 @@ class User < ApplicationRecord has_many :attendances + # 兴趣 + has_many :user_interests, dependent: :delete_all + has_many :interests, through: :user_interests, source: :repertoire + # Groups and active users scope :active, lambda { where(status: STATUS_ACTIVE) } diff --git a/app/models/user_interest.rb b/app/models/user_interest.rb new file mode 100644 index 000000000..bdb6e77d4 --- /dev/null +++ b/app/models/user_interest.rb @@ -0,0 +1,4 @@ +class UserInterest < ApplicationRecord + belongs_to :user + belongs_to :repertoire +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index cf5bad608..f0123d95b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -47,6 +47,7 @@ Rails.application.routes.draw do resource :experience_records, only: [:show] resource :grade_records, only: [:show] resource :watch, only: [:create, :destroy] + resource :interest, only: [:create] end diff --git a/db/migrate/20190706010307_create_user_interests.rb b/db/migrate/20190706010307_create_user_interests.rb new file mode 100644 index 000000000..d64a1c228 --- /dev/null +++ b/db/migrate/20190706010307_create_user_interests.rb @@ -0,0 +1,8 @@ +class CreateUserInterests < ActiveRecord::Migration[5.2] + def change + create_table :user_interests do |t| + t.references :user + t.references :repertoire + end + end +end From 7b8555c51b7d319b34f5974b1762018720a9a1ba Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 6 Jul 2019 09:36:33 +0800 Subject: [PATCH 0651/1015] =?UTF-8?q?=E9=AA=8C=E8=AF=81=E9=82=AE=E7=AE=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 0d32926e4..e5d9ba5c4 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -151,6 +151,8 @@ class AccountsController < ApplicationController send_type = verify_type(login_type, type) verification_code = code.sample(6).join + logger.info("########get_verification_code: login_type: #{login_type}, send_type:#{send_type}, ") + # 记录验证码 check_verification_code(verification_code, send_type, value) sucess_status From a13dc35905dddfebf99bb83220c3d36a89fc8832 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 6 Jul 2019 10:05:45 +0800 Subject: [PATCH 0652/1015] =?UTF-8?q?=E5=BC=82=E6=AD=A5=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/course_add_student_create_works_job.rb | 2 +- app/jobs/course_delete_student_delete_works_job.rb | 2 +- app/jobs/graduation_task_cross_comment_job.rb | 2 +- app/jobs/homework_absence_penalty_calculation_job.rb | 2 +- app/jobs/homework_end_update_score_job.rb | 2 +- app/jobs/homework_evaluation_comment_assgin_job.rb | 2 +- app/jobs/homework_publish_update_work_status_job.rb | 2 +- config/sidekiq.yml | 3 --- 8 files changed, 7 insertions(+), 10 deletions(-) diff --git a/app/jobs/course_add_student_create_works_job.rb b/app/jobs/course_add_student_create_works_job.rb index 1631b5b77..d8bd6363c 100644 --- a/app/jobs/course_add_student_create_works_job.rb +++ b/app/jobs/course_add_student_create_works_job.rb @@ -1,6 +1,6 @@ # 学生加入课堂时创建相关任务作品 class CourseAddStudentCreateWorksJob < ApplicationJob - queue_as :course_member + queue_as :default def perform(course_id, student_ids) course = Course.find_by(id: course_id) diff --git a/app/jobs/course_delete_student_delete_works_job.rb b/app/jobs/course_delete_student_delete_works_job.rb index c12762fbe..a84608b2c 100644 --- a/app/jobs/course_delete_student_delete_works_job.rb +++ b/app/jobs/course_delete_student_delete_works_job.rb @@ -1,5 +1,5 @@ class CourseDeleteStudentDeleteWorksJob < ApplicationJob - queue_as :course_member + queue_as :default def perform(course_id, student_ids) course = Course.find_by(id: course_id) diff --git a/app/jobs/graduation_task_cross_comment_job.rb b/app/jobs/graduation_task_cross_comment_job.rb index 64973a3e9..cf2cb613e 100644 --- a/app/jobs/graduation_task_cross_comment_job.rb +++ b/app/jobs/graduation_task_cross_comment_job.rb @@ -1,6 +1,6 @@ # 毕设任务的交叉评阅分配 class GraduationTaskCrossCommentJob < ApplicationJob - queue_as :evaluation_comment + queue_as :default def perform(graduation_task_id) task = GraduationTask.find_by(id: graduation_task_id) diff --git a/app/jobs/homework_absence_penalty_calculation_job.rb b/app/jobs/homework_absence_penalty_calculation_job.rb index 6e80f2330..02836d9ec 100644 --- a/app/jobs/homework_absence_penalty_calculation_job.rb +++ b/app/jobs/homework_absence_penalty_calculation_job.rb @@ -1,5 +1,5 @@ class HomeworkAbsencePenaltyCalculationJob < ApplicationJob - queue_as :score + queue_as :default def perform(homework_common_id) homework_common = HomeworkCommon.find_by(id: homework_common_id) diff --git a/app/jobs/homework_end_update_score_job.rb b/app/jobs/homework_end_update_score_job.rb index 649a5c37a..4ba4502fc 100644 --- a/app/jobs/homework_end_update_score_job.rb +++ b/app/jobs/homework_end_update_score_job.rb @@ -1,6 +1,6 @@ class HomeworkEndUpdateScoreJob < ApplicationJob # 不允许补交的作业截止后,或者补交截止后需要重新计算一次作业成绩 - queue_as :score + queue_as :default def perform(homework_id) homework = HomeworkCommon.find_by(id: homework_id) diff --git a/app/jobs/homework_evaluation_comment_assgin_job.rb b/app/jobs/homework_evaluation_comment_assgin_job.rb index 5921386f2..25a7f0a24 100644 --- a/app/jobs/homework_evaluation_comment_assgin_job.rb +++ b/app/jobs/homework_evaluation_comment_assgin_job.rb @@ -1,5 +1,5 @@ class HomeworkEvaluationCommentAssginJob < ApplicationJob - queue_as :evaluation_comment + queue_as :default def get_assigned_homeworks(student_works, n, index) student_works += student_works diff --git a/app/jobs/homework_publish_update_work_status_job.rb b/app/jobs/homework_publish_update_work_status_job.rb index fe03a3ac5..0060ab270 100644 --- a/app/jobs/homework_publish_update_work_status_job.rb +++ b/app/jobs/homework_publish_update_work_status_job.rb @@ -1,6 +1,6 @@ class HomeworkPublishUpdateWorkStatusJob < ApplicationJob # 作业发布时更新学生(发布前已开启过实训)的作业状态和成绩 - queue_as :score + queue_as :default def perform(group_ids, homework_id) # Do something later diff --git a/config/sidekiq.yml b/config/sidekiq.yml index 93e89b4dc..a2b3fc0be 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -3,7 +3,4 @@ :logfile: log/sidekiq.log :queues: - [default, 3] - - [score, 4] - - [evaluation_comment, 5] - - [course_member, 6] - [notify, 100] \ No newline at end of file From 3f3f7ed8544d67014f6323d12c412061cd216ead Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 6 Jul 2019 10:06:09 +0800 Subject: [PATCH 0653/1015] fix interest --- app/controllers/users/interests_controller.rb | 8 ++++---- config/routes.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/users/interests_controller.rb b/app/controllers/users/interests_controller.rb index ca5f63af9..93836fd63 100644 --- a/app/controllers/users/interests_controller.rb +++ b/app/controllers/users/interests_controller.rb @@ -1,21 +1,21 @@ class Users::InterestsController < Users::BaseController + skip_before_action :check_observed_user_exists! before_action :require_login - before_action :private_user_resources! def create identity = params[:identity].to_s.strip - extension = observed_user.user_extension || observed_user.build_user_extension + extension = current_user.user_extension || current_user.build_user_extension return render_error('请选择职业') unless %w(teacher student professional).include?(identity) ActiveRecord::Base.transaction do extension.update_column(:identity, identity) # 兴趣 - observed_user.user_interests.delete_all + current_user.user_interests.delete_all UserInterest.bulk_insert(:user_id, :repertoire_id) do |worker| (Repertoire.pluck(:id) & Array.wrap(params[:interest_ids]).map(&:to_i)).each do |repertoire_id| - worker.add(user_id: observed_user.id, repertoire_id: repertoire_id) + worker.add(user_id: current_user.id, repertoire_id: repertoire_id) end end end diff --git a/config/routes.rb b/config/routes.rb index f0123d95b..74eaa7bed 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -47,7 +47,6 @@ Rails.application.routes.draw do resource :experience_records, only: [:show] resource :grade_records, only: [:show] resource :watch, only: [:create, :destroy] - resource :interest, only: [:create] end @@ -78,6 +77,7 @@ Rails.application.routes.draw do resource :auth_attachment, only: [:update] resource :authentication_apply, only: [:create] resource :professional_auth_apply, only: [:create] + resource :interest, only: [:create] end end end From 508d24af2c8f350f2c99fe0376f7d9415071cc22 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 6 Jul 2019 10:10:24 +0800 Subject: [PATCH 0654/1015] fix trial apply --- app/controllers/concerns/controller_rescue_handler.rb | 3 +++ app/controllers/ecs/base_controller.rb | 9 --------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/app/controllers/concerns/controller_rescue_handler.rb b/app/controllers/concerns/controller_rescue_handler.rb index e9563d1e5..31934db03 100644 --- a/app/controllers/concerns/controller_rescue_handler.rb +++ b/app/controllers/concerns/controller_rescue_handler.rb @@ -12,5 +12,8 @@ module ControllerRescueHandler rescue_from ActiveModel::ValidationError do |ex| render_error(ex.model.errors.full_messages.join(',')) end + rescue_from ActiveRecord::RecordInvalid do |ex| + render_error(ex.record.errors.full_messages.join(',')) + end end end \ No newline at end of file diff --git a/app/controllers/ecs/base_controller.rb b/app/controllers/ecs/base_controller.rb index ad11682c3..9fb99c420 100644 --- a/app/controllers/ecs/base_controller.rb +++ b/app/controllers/ecs/base_controller.rb @@ -1,14 +1,5 @@ class Ecs::BaseController < ApplicationController - # model validation error - rescue_from ActiveRecord::RecordInvalid do |ex| - render_error(ex.record.errors.full_messages.join(',')) - end - # form validation error - rescue_from ActiveModel::ValidationError do |ex| - render_error(ex.model.errors.full_messages.join(',')) - end - before_action :require_login before_action :check_user_permission! From 24a0c43d1627cf5cf31ac616784332331f3ca7bf Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 6 Jul 2019 10:19:57 +0800 Subject: [PATCH 0655/1015] repertoires name list --- app/controllers/repertoires_controller.rb | 5 +++++ app/models/repertoire.rb | 19 +++++++++++++++++++ config/routes.rb | 2 ++ 3 files changed, 26 insertions(+) create mode 100644 app/controllers/repertoires_controller.rb diff --git a/app/controllers/repertoires_controller.rb b/app/controllers/repertoires_controller.rb new file mode 100644 index 000000000..0ac78a15b --- /dev/null +++ b/app/controllers/repertoires_controller.rb @@ -0,0 +1,5 @@ +class RepertoiresController < ApplicationController + def index + render_ok(repertoires: Repertoire.cache_data) + end +end \ No newline at end of file diff --git a/app/models/repertoire.rb b/app/models/repertoire.rb index 72e1ebfff..140416658 100644 --- a/app/models/repertoire.rb +++ b/app/models/repertoire.rb @@ -3,4 +3,23 @@ class Repertoire < ApplicationRecord has_many :tag_repertoires, through: :sub_repertoires has_many :user_interests, dependent: :delete_all + + after_create_commit :reset_cache_data + after_update_commit :reset_cache_data + + def self.cache_data + Rails.cache.fetch(data_cache_key, expires_in: 1.days) do + Repertoire.select(:id, :name).order(:created_at).as_json + end + end + + def self.data_cache_key + 'repertoire/cache_data' + end + + private + + def reset_cache_data + Rails.cache.delete(self.class.data_cache_key) + end end diff --git a/config/routes.rb b/config/routes.rb index 74eaa7bed..d3d04edfb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -661,6 +661,8 @@ Rails.application.routes.draw do get :export_exercises end end + + resources :repertoires, only: [:index] end #git 认证回调 From fe990abc607c24e1e0b12d4bcb000f4550e971e4 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 6 Jul 2019 10:21:18 +0800 Subject: [PATCH 0656/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=8F=8A=E5=AF=BC=E5=87=BA=E7=9A=84=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 3 +- app/controllers/exercises_controller.rb | 84 ++++++++++++------- .../graduation_tasks_controller.rb | 5 +- .../graduation_topics_controller.rb | 5 +- .../homework_commons_controller.rb | 4 +- app/controllers/polls_controller.rb | 6 +- app/controllers/zips_controller.rb | 8 +- app/helpers/polls_helper.rb | 7 +- app/models/exercise.rb | 4 +- .../batch_export_shixun_report_service.rb | 2 +- app/services/export_exercises_service.rb | 2 +- 11 files changed, 78 insertions(+), 52 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 0679e5619..cb2b8d201 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -993,7 +993,8 @@ class CoursesController < ApplicationController normal_status(-1,"课堂暂时没有学生") else member_to_xlsx(@course, @all_members, @c_homeworks, @c_exercises, @c_tasks) - filename = current_user.real_name + "_" + @course.name + "_全部成绩" + Time.now.strftime('%Y%m%d_%H%M%S') + filename_ = "#{current_user.real_name}_#{@course.name}_全部成绩" + filename = Base64.urlsafe_encode64(filename_) render xlsx: "#{format_sheet_name filename.strip.first(30)}",template: "courses/export_member_scores_excel.xlsx.axlsx", locals: {course_info:@course_info, activity_level:@user_activity_level, course_scores:@course_user_scores,shixun_works:@shixun_work_arrays, diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 9087aeee6..6d0adef27 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -23,7 +23,6 @@ class ExercisesController < ApplicationController before_action :commit_shixun_present,only: [:commit_shixun] include ExportHelper include ExercisesHelper - # require 'pdfkit' def index ActiveRecord::Base.transaction do @@ -43,46 +42,65 @@ class ExercisesController < ApplicationController @exercises = @exercises_all #老师能看到全部的试卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同) elsif @user_course_identity == Course::STUDENT # 2为课堂成员,能看到统一设置的和自己班级的 @is_teacher_or = 2 - # get_exercise_left_time(@exercise,current_user) - member_group_id = @current_student.first.try(:course_group_id).to_i # 成员的分班id,默认为0 - if member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的) + @member_group_id = @current_student.first.try(:course_group_id).to_i # 成员的分班id,默认为0 + if @member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的) @exercises = member_show_exercises.exists? ? member_show_exercises.unified_setting : [] else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷 # 已发布 当前用户班级分组的 试卷id - exercise_settings_ids = @course.exercise_group_settings.exercise_group_published - .where(course_group_id: member_group_id).pluck(:exercise_id).uniq - @exercises = member_show_exercises.exists? ? - member_show_exercises.unified_setting.or(member_show_exercises.where(id: exercise_settings_ids)) - : [] + not_exercise_ids = @course.exercise_group_settings.exercise_group_not_published.where("course_group_id = #{@member_group_id}").pluck(:exercise_id) + @exercises = member_show_exercises.where.not(id: not_exercise_ids) + # exercise_settings_ids = @course.exercise_group_settings.exercise_group_published + # .where(course_group_id: member_group_id).pluck(:exercise_id).uniq + # @exercises = member_show_exercises.exists? ? + # member_show_exercises.unified_setting.or(member_show_exercises.where(id: exercise_settings_ids)) + # : [] end else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁 @is_teacher_or = 0 - @exercises = member_show_exercises.exists? ? member_show_exercises.unified_setting : [] + @exercises = member_show_exercises.unified_setting end if @exercises.size > 0 if params[:type].present? choose_type = params[:type].to_i - member_group_id = @current_student.first.try(:course_group_id).to_i - if @is_teacher_or == 2 && member_group_id > 0 - exercise_groups_sets = @course.exercise_group_settings.where(course_group_id: member_group_id) - .exercise_group_published - exercise_settings_ids = exercise_groups_sets.pluck(:exercise_id) - exercise_ended_ids = exercise_groups_sets.exercise_group_ended.pluck(:exercise_id).uniq - if choose_type == 2 - @exercises = @exercises_all.exists? ? - @exercises_all.exercise_by_status(2).unified_setting - .or(@exercises_all.where(id: (exercise_settings_ids - exercise_ended_ids).uniq)) - : [] - elsif choose_type == 3 - @exercises = @exercises_all.exists? ? - @exercises_all.exercise_by_status(3).unified_setting - .or(@exercises_all.where(id: exercise_ended_ids)) - : [] - end - else - @exercises = @exercises.exercise_by_status(choose_type) + ex_setting_ids = [] + case choose_type + when 1 + ex_setting_ids = @course.exercise_group_settings.exercise_group_not_published.pluck(:exercise_id) + + # @exercises = @exercises.where("exercise_status = #{choose_type}").or(@exercises.where(id:ex_setting_ids)) + when 2 + ex_setting_ids = @course.exercise_group_settings.where("publish_time is not null and publish_time <= ? and end_time > ?",Time.now,Time.now).pluck(:exercise_id) + # @exercises = @exercises.where("exercise_status = #{choose_type}").or(@exercises.where(id:ex_published_groups)) + when 3 + ex_setting_ids = @course.exercise_group_settings.exercise_group_ended.pluck(:exercise_id) + # @exercises = @exercises.where("exercise_status = #{choose_type}").or(@exercises.where(id:ex_ended_groups)) end + @exercises = @exercises.unified_setting.where("exercise_status = #{choose_type}").or(@exercises.where(id:ex_setting_ids)).distinct + + + + + # member_group_id = @current_student.first.try(:course_group_id).to_i + # if @is_teacher_or == 2 && member_group_id > 0 + # exercise_groups_sets = @course.exercise_group_settings.where(course_group_id: member_group_id) + # .exercise_group_published + # exercise_settings_ids = exercise_groups_sets.pluck(:exercise_id) + # exercise_ended_ids = exercise_groups_sets.exercise_group_ended.pluck(:exercise_id).uniq + # if choose_type == 2 + # @exercises = @exercises_all.exists? ? + # @exercises_all.exercise_by_status(2).unified_setting + # .or(@exercises_all.where(id: (exercise_settings_ids - exercise_ended_ids).uniq)) + # : [] + # elsif choose_type == 3 + # @exercises = @exercises_all.exists? ? + # @exercises_all.exercise_by_status(3).unified_setting + # .or(@exercises_all.where(id: exercise_ended_ids)) + # : [] + # end + # else + # @exercises = @exercises.exercise_by_status(choose_type) + # end end if params[:search].present? @@ -1302,9 +1320,11 @@ class ExercisesController < ApplicationController respond_to do |format| format.xlsx{ get_export_users(@exercise,@course,@export_ex_users) - exercise_export_name = - "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} + exercise_export_name_ = + "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}" + exercise_export_name = Base64.urlsafe_encode64(exercise_export_name_.strip.first(30)) + + render xlsx: "#{exercise_export_name}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} } end end diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 545b10e11..41d8bd68d 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -134,8 +134,9 @@ class GraduationTasksController < ApplicationController respond_to do |format| format.xlsx{ graduation_work_to_xlsx(@work_excel,@task,current_user) - exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@task.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_tasks/tasks_list.xlsx.axlsx",locals: {table_columns:@head_cells_column, task_users:@task_cells_column} + task_export_name_ = "#{current_user.real_name}_#{@course.name}_#{@task.name}" + task_export_name = Base64.urlsafe_encode64(task_export_name_.strip.first(30)) + render xlsx: "#{task_export_name}",template: "graduation_tasks/tasks_list.xlsx.axlsx",locals: {table_columns:@head_cells_column, task_users:@task_cells_column} } end end diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index b20b767a4..75f7ddc6f 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -270,8 +270,9 @@ class GraduationTopicsController < ApplicationController course = @course students = course.students.joins(user: :user_extension).order("user_extensions.student_id") graduation_topic_to_xlsx(students,course) - exercise_export_name = "#{current_user.real_name}_#{course.name}_毕设选题_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - render xlsx: "#{exercise_export_name.strip.first(30)}",template: "graduation_topics/export.xlsx.axlsx",locals: {table_columns:@topic_head_cells,topic_users:@topic_body_cells} + topic_export_name_ = "#{current_user.real_name}_#{course.name}_毕设选题_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + topic_export_name = Base64.urlsafe_encode64(topic_export_name_.strip.first(30)) + render xlsx: "#{topic_export_name}",template: "graduation_topics/export.xlsx.axlsx",locals: {table_columns:@topic_head_cells,topic_users:@topic_body_cells} rescue Exception => e uid_logger(e.message) missing_template diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index b12980094..cdbfac5bc 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -206,10 +206,8 @@ class HomeworkCommonsController < ApplicationController respond_to do |format| format.xlsx{ student_work_to_xlsx(@work_excel,@homework) - exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S') - # response.set_header("Content-Disposition","attachment; filename=#{exercise_export_name.strip.first(30)}};filename*=utf-8''#{exercise_export_name.strip.first(30)}}") + exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@homework.name}" file_name = Base64.urlsafe_encode64(exercise_export_name.strip.first(30)) - # response.setHeader['Content-Disposition'] = "attachment; filename=\"#{exercise_export_name.strip.first(30)}\"" render xlsx: "#{file_name}",template: "homework_commons/works_list.xlsx.axlsx",locals: {table_columns: @work_head_cells,task_users: @work_cells_column} } diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 64827b375..d94299454 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -933,9 +933,11 @@ class PollsController < ApplicationController else respond_to do |format| format.xlsx{ - polls_export_name = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + polls_export_name_ = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}" + polls_export_name = Base64.urlsafe_encode64(polls_export_name_.strip.first(30)) + polls_user_commit = poll_commit_result(@poll,@poll_export_questions,@poll_users,@poll_commit_ids) - render xlsx: "#{polls_export_name.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: {polls_user_commit:polls_user_commit} + render xlsx: "#{polls_export_name}",template: "polls/commit_result.xlsx.axlsx",locals: {polls_user_commit:polls_user_commit} } end end diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 2b70b9b27..2d21237f5 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -9,8 +9,8 @@ class ZipsController < ApplicationController service = BatchExportShixunReportService.new(@homework, @all_student_works) - filename = filename_for_content_disposition(service.filename) - + filename_ = filename_for_content_disposition(service.filename) + filename = Base64.urlsafe_encode64(filename_) send_file service.zip, filename: filename, type: 'application/zip' rescue BatchExportShixunReportService::Error => ex normal_status(-1, ex.message) @@ -20,8 +20,8 @@ class ZipsController < ApplicationController @request_url = request.base_url exercises = ExportExercisesService.new(@exercise,@ex_users,@request_url) - file_name = filename_for_content_disposition(exercises.filename) - + file_name_ = filename_for_content_disposition(exercises.filename) + file_name = Base64.urlsafe_encode64(file_name_) send_file exercises.ex_zip, filename: file_name, type: 'application/zip' rescue Exception => e normal_status(-1, e.message) diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index 693149e8f..aee95eef7 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -65,7 +65,7 @@ module PollsHelper poll_publish_time = ex_pb_time[:publish_time] poll_end_time = ex_pb_time[:end_time] current_status = 3 - lock_icon = 1 #不显示锁图标 + lock_icon = 0 #不显示锁图标 elsif is_teacher_or == 2 poll_users_list = poll.get_poll_exercise_users get_poll_answers(poll_users_list) # 未答和已答的 @@ -74,7 +74,7 @@ module PollsHelper poll_publish_time = ex_pb_time[:publish_time] poll_end_time = ex_pb_time[:end_time] current_status = poll.check_user_votes_status(user) - lock_icon = 1 #不显示锁图标 + lock_icon = 0 #不显示锁图标 else poll_users_list = poll.get_poll_exercise_users get_poll_answers(poll_users_list) # 未答和已答的 @@ -87,6 +87,9 @@ module PollsHelper lock_icon = 0 #显示锁图标 end end + if (course.is_public == 1) && poll.is_public + lock_icon = 1 + end { "publish_time":poll_publish_time, "end_time":poll_end_time, diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 42b737c26..bc5424b6e 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -144,10 +144,10 @@ class Exercise < ApplicationRecord ex_answer_user = exercise_users.find_by(user_id: user.id) user_ex_status = get_exercise_status(user.id) user_status = 2 - if ex_answer_user.exists? && (ex_answer_user.start_at.exists? || ex_answer_user.end_at.exists?) #学生有过答题的,或者立即截止,但学生未做试卷的 + if ex_answer_user.present? && (ex_answer_user.start_at.present? || ex_answer_user.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 user_status = ex_answer_user.commit_status end - if ex_answer_user.exists? && ex_answer_user.start_at.blank? && user_ex_status == 3 + if ex_answer_user.present? && ex_answer_user.start_at.blank? && user_ex_status == 3 user_status = 4 end diff --git a/app/services/batch_export_shixun_report_service.rb b/app/services/batch_export_shixun_report_service.rb index 2c294395d..01d94ffe5 100644 --- a/app/services/batch_export_shixun_report_service.rb +++ b/app/services/batch_export_shixun_report_service.rb @@ -14,7 +14,7 @@ class BatchExportShixunReportService end def filename - @_filename ||= "#{homework.name}-#{Time.now.strftime('%Y%m%d%H%M%S')}.zip" + @_filename ||= "#{homework.name}" end def zip diff --git a/app/services/export_exercises_service.rb b/app/services/export_exercises_service.rb index 3aac67713..1b284e598 100644 --- a/app/services/export_exercises_service.rb +++ b/app/services/export_exercises_service.rb @@ -10,7 +10,7 @@ class ExportExercisesService end def filename - exercise_export_name = "#{exercise.user.real_name}_#{exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M')}" + exercise_export_name = "#{exercise.user.real_name}_#{exercise.exercise_name}" "#{exercise_export_name.strip}.zip" end From b7b5821f939cee7c72717ac01c1f11d60f789dd5 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 6 Jul 2019 10:23:52 +0800 Subject: [PATCH 0657/1015] fixbug --- app/helpers/exercises_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index fe29497d0..8174d1eea 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -723,8 +723,8 @@ module ExercisesHelper if ex_time > 0 exercise_user = exercise.exercise_users.find_by(user_id:user.id) time_mill = ex_time * 60 #转为秒 - exercise_end_time = exercise.end_time.exists? ? exercise.end_time.to_i : 0 - exercise_user_start = exercise_user&.start_at.exists? ? exercise_user.start_at.to_i : 0 + exercise_end_time = exercise.end_time.present? ? exercise.end_time.to_i : 0 + exercise_user_start = exercise_user&.start_at.present? ? exercise_user.start_at.to_i : 0 #用户未开始答题时,即exercise_user_start为0 if exercise_user_start == 0 if (exercise_end_time - time_now_i) > time_mill From bd218764e991eacad83ef2b255e3bac0564e29bf Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 6 Jul 2019 10:54:02 +0800 Subject: [PATCH 0658/1015] fixvbug --- app/controllers/exercises_controller.rb | 31 +++++++++++++------------ 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 6d0adef27..79668dad3 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -64,22 +64,23 @@ class ExercisesController < ApplicationController if params[:type].present? choose_type = params[:type].to_i ex_setting_ids = [] - case choose_type - when 1 - ex_setting_ids = @course.exercise_group_settings.exercise_group_not_published.pluck(:exercise_id) - - # @exercises = @exercises.where("exercise_status = #{choose_type}").or(@exercises.where(id:ex_setting_ids)) - when 2 - ex_setting_ids = @course.exercise_group_settings.where("publish_time is not null and publish_time <= ? and end_time > ?",Time.now,Time.now).pluck(:exercise_id) - # @exercises = @exercises.where("exercise_status = #{choose_type}").or(@exercises.where(id:ex_published_groups)) - when 3 - ex_setting_ids = @course.exercise_group_settings.exercise_group_ended.pluck(:exercise_id) - # @exercises = @exercises.where("exercise_status = #{choose_type}").or(@exercises.where(id:ex_ended_groups)) + if @is_teacher_or != 2 + @exercises = @exercises.where("exercise_status = #{choose_type}") + else + case choose_type + when 1 + ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}").exercise_group_not_published.pluck(:exercise_id) + when 2 + ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}") + .where("publish_time is not null and publish_time <= ? and end_time > ?",Time.now,Time.now).pluck(:exercise_id) + when 3 + ex_setting_ids = @course.exercise_group_settings.where("course_group_id = #{@member_group_id}").exercise_group_ended.pluck(:exercise_id) + end + unified_setting_ids = @exercises.unified_setting.where("exercise_status = #{choose_type}").pluck(:id) + ex_ids = (ex_setting_ids + unified_setting_ids).uniq + @exercises = @exercises.where(id: ex_ids) + # @exercises = @exercises.unified_setting.where("exercise_status = #{choose_type}").or(@exercises.where(id:ex_setting_ids)).distinct end - @exercises = @exercises.unified_setting.where("exercise_status = #{choose_type}").or(@exercises.where(id:ex_setting_ids)).distinct - - - # member_group_id = @current_student.first.try(:course_group_id).to_i # if @is_teacher_or == 2 && member_group_id > 0 From c5baf84e8562729ee4b45f865fa52b5e5343f413 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 6 Jul 2019 12:40:16 +0800 Subject: [PATCH 0659/1015] fixbug --- app/controllers/exercises_controller.rb | 25 ++------------------- app/controllers/student_works_controller.rb | 4 ++-- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 79668dad3..30cc51dc2 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -79,29 +79,7 @@ class ExercisesController < ApplicationController unified_setting_ids = @exercises.unified_setting.where("exercise_status = #{choose_type}").pluck(:id) ex_ids = (ex_setting_ids + unified_setting_ids).uniq @exercises = @exercises.where(id: ex_ids) - # @exercises = @exercises.unified_setting.where("exercise_status = #{choose_type}").or(@exercises.where(id:ex_setting_ids)).distinct end - - # member_group_id = @current_student.first.try(:course_group_id).to_i - # if @is_teacher_or == 2 && member_group_id > 0 - # exercise_groups_sets = @course.exercise_group_settings.where(course_group_id: member_group_id) - # .exercise_group_published - # exercise_settings_ids = exercise_groups_sets.pluck(:exercise_id) - # exercise_ended_ids = exercise_groups_sets.exercise_group_ended.pluck(:exercise_id).uniq - # if choose_type == 2 - # @exercises = @exercises_all.exists? ? - # @exercises_all.exercise_by_status(2).unified_setting - # .or(@exercises_all.where(id: (exercise_settings_ids - exercise_ended_ids).uniq)) - # : [] - # elsif choose_type == 3 - # @exercises = @exercises_all.exists? ? - # @exercises_all.exercise_by_status(3).unified_setting - # .or(@exercises_all.where(id: exercise_ended_ids)) - # : [] - # end - # else - # @exercises = @exercises.exercise_by_status(choose_type) - # end end if params[:search].present? @@ -1342,7 +1320,8 @@ class ExercisesController < ApplicationController def export_exercise @request_url = request.base_url @exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") - filename = "#{@exercise.user.real_name}_#{@exercise.exercise_name}_#{Time.current.strftime('%Y%m%d_%H%M')}.pdf" + filename_ = "#{@exercise.user.real_name}_#{@exercise.exercise_name}" + filename = Base64.urlsafe_encode64(filename_.strip.first(30)) stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css" render pdf: 'exercise_export/blank_exercise', filename: filename, stylesheets: stylesheets end diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index ed642a557..7c7201d32 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -456,9 +456,9 @@ class StudentWorksController < ApplicationController @echart_data = student_efficiency(@homework, @work) @myself_eff = @echart_data[:efficiency_list].find { |item| item.last == @user.id } @myself_consume = @echart_data[:consume_list].find { |item| item.last == @user.id } - # filename = "实训报告_#{@shixun.name}_#{@use.real_name}_#{Time.current.strftime('%Y%m%d%H%M%S')}.pdf" #下载报错 unknown nil name,下面为修改的-hs-0606 - filename = "实训报告_#{@shixun&.name}_#{@use&.real_name}_#{Time.current.strftime('%Y%m%d%H%M%S')}.pdf" + filename_ = "实训报告_#{@shixun&.name}_#{@use&.real_name}" + filename = Base64.urlsafe_encode64(filename_.strip.first(30)) stylesheets = %w(shixun_work/shixun_work.css shared/codemirror.css) render pdf: 'shixun_work/shixun_work', filename: filename, stylesheets: stylesheets end From 67a1850adc268a8c0aae38c40aa90ef2ac127709 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 6 Jul 2019 13:52:10 +0800 Subject: [PATCH 0660/1015] =?UTF-8?q?=E6=89=93=E5=8D=B0=E6=97=A5=E5=BF=97?= =?UTF-8?q?=EF=BC=8C=E6=9F=A5=E7=9C=8B=E9=82=AE=E4=BB=B6=E5=8F=91=E9=80=81?= =?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/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index cbd2962b6..e6c0116fc 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -72,7 +72,7 @@ class ApplicationController < ActionController::Base UserMailer.register_email(value, code).deliver_now # Mailer.run.email_register(code, value) rescue Exception => e - uid_logger_error(e.message) + logger_error(e) tip_exception("邮件发送失败,请稍后重试") end end From 772d477039169d28f35e3872f621e8577ba74b7a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 6 Jul 2019 15:05:51 +0800 Subject: [PATCH 0661/1015] =?UTF-8?q?=E8=AF=84=E6=B5=8B=E8=B6=85=E6=97=B6?= =?UTF-8?q?=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/games_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index d6a000ffa..10938664c 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -587,7 +587,7 @@ class GamesController < ApplicationController :times => params[:first].to_i, :podType => @shixun.webssh, :content_modified => content_modified, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(@shixun))}", :persistenceName => @shixun.identifier, :tpmScript => "#{tpmScript}", :sec_key => sec_key, - :timeLimit => "#{@shixun.exec_time}", :isPublished => (@shixun.status < 2 ? 0 : 1) } + :timeLimit => "#{game_challenge.exec_time}", :isPublished => (@shixun.status < 2 ? 0 : 1) } # 评测有文件输出的需要特殊传字段 path:表示文件存储的位置 br_params['file'] = Base64.urlsafe_encode64({path: "#{game_challenge.picture_path}"}.to_json) if game_challenge.picture_path.present? From 5f7b68bb698bedeff964359c4633cb2e58e8a01e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 6 Jul 2019 15:14:48 +0800 Subject: [PATCH 0662/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=AF=84=E6=B5=8B?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 10938664c..5f93bc36b 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -539,7 +539,7 @@ class GamesController < ApplicationController # 编程题评测 def game_build sec_key = params[:sec_key] - game_challenge = Challenge.select([:id, :position, :picture_path]).find(@game.challenge_id) + game_challenge = Challenge.select([:id, :position, :picture_path, :exec_time]).find(@game.challenge_id) # 更新评测次数 @game.update_column(:evaluate_count, (@game.evaluate_count.to_i + 1)) From caa53f10969b57a5aa91e659443f33714d3893ce Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 6 Jul 2019 15:48:36 +0800 Subject: [PATCH 0663/1015] fix interest 404 --- config/routes.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index d3d04edfb..ee8b6a187 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -69,6 +69,8 @@ Rails.application.routes.draw do resources :tidings, only: [:index] scope module: :users do + resource :interest, only: [:create] + resources :accounts, only: [:show, :update] do resource :phone_bind, only: [:create] resource :email_bind, only: [:create] @@ -77,7 +79,6 @@ Rails.application.routes.draw do resource :auth_attachment, only: [:update] resource :authentication_apply, only: [:create] resource :professional_auth_apply, only: [:create] - resource :interest, only: [:create] end end end From 9d308bb75143170675060f3428e47821375e46b2 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 6 Jul 2019 15:49:47 +0800 Subject: [PATCH 0664/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=92=8C=E9=97=AE?= =?UTF-8?q?=E5=8D=B7=E7=9A=84=E5=88=97=E8=A1=A8=E9=A1=B5=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exercise_answers_controller.rb | 2 +- app/controllers/exercises_controller.rb | 31 ++++---- app/controllers/poll_votes_controller.rb | 2 +- app/controllers/polls_controller.rb | 75 +++++++++---------- app/controllers/zips_controller.rb | 2 +- app/helpers/exercises_helper.rb | 6 +- app/helpers/polls_helper.rb | 7 +- app/models/course.rb | 2 +- app/models/exercise.rb | 33 ++++---- app/models/poll.rb | 59 +++++---------- app/views/exercises/index.json.jbuilder | 3 +- app/views/polls/index.json.jbuilder | 28 +++---- 12 files changed, 106 insertions(+), 144 deletions(-) diff --git a/app/controllers/exercise_answers_controller.rb b/app/controllers/exercise_answers_controller.rb index cad482390..aa3966d25 100644 --- a/app/controllers/exercise_answers_controller.rb +++ b/app/controllers/exercise_answers_controller.rb @@ -97,7 +97,7 @@ class ExerciseAnswersController < ApplicationController @exercise = @exercise_question&.exercise @course = @exercise&.course @exercise_user = @exercise&.exercise_users.find_by(user_id: current_user.id) #当前用户 - @exercise_user_status = @exercise.get_exercise_status(current_user.id) + @exercise_user_status = @exercise.get_exercise_status(current_user) if @exercise_question.blank? normal_status(-1,"试卷问题不存在!") diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 30cc51dc2..ea424a411 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -49,11 +49,6 @@ class ExercisesController < ApplicationController # 已发布 当前用户班级分组的 试卷id not_exercise_ids = @course.exercise_group_settings.exercise_group_not_published.where("course_group_id = #{@member_group_id}").pluck(:exercise_id) @exercises = member_show_exercises.where.not(id: not_exercise_ids) - # exercise_settings_ids = @course.exercise_group_settings.exercise_group_published - # .where(course_group_id: member_group_id).pluck(:exercise_id).uniq - # @exercises = member_show_exercises.exists? ? - # member_show_exercises.unified_setting.or(member_show_exercises.where(id: exercise_settings_ids)) - # : [] end else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁 @is_teacher_or = 0 @@ -210,7 +205,7 @@ class ExercisesController < ApplicationController @user_exercise_answer = 3 #教师页面 @user_commit_counts = @exercise.exercise_users.where(commit_status:1).count #已提交的用户数 end - @ex_status = @exercise.get_exercise_status(current_user.id) + @ex_status = @exercise.get_exercise_status(current_user) exercise_id_array = [@exercise.id] @exercise_publish_count = get_user_permission_course(exercise_id_array,2).count #是否存在已发布的 @@ -448,7 +443,7 @@ class ExercisesController < ApplicationController # course_group_ids = @course.teacher_course_group_ids(current_user.id) #当前老师的班级id数组 course_group_ids = @course.charge_group_ids(current_user) #当前老师的班级id数组 - exercise_status = @exercise.get_exercise_status(current_user.id) + exercise_status = @exercise.get_exercise_status(current_user) if exercise_status == 1 && course_group_ids.size > 0 # 试卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按试卷默认的来处理 unified_setting = params[:unified_setting] @@ -802,7 +797,7 @@ class ExercisesController < ApplicationController check_ids = Exercise.where(id:params[:check_ids]) course_students = @course.students #课堂的全部学生数 check_ids.each do |exercise| - exercise_status= exercise.get_exercise_status(current_user.id) + exercise_status= exercise.get_exercise_status(current_user) if exercise_status == 2 #跳过已截止的或未发布的 g_course = params[:group_ids] if g_course.present? @@ -897,7 +892,7 @@ class ExercisesController < ApplicationController ex_question_ids = @exercise.exercise_questions.pluck(:id) exercise_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first if exercise_user.present? - if exercise_user.commit_status == 1 && @exercise.get_exercise_status(current_user.id) == 2 #用户已提交且试卷提交中 + if exercise_user.commit_status == 1 && @exercise.get_exercise_status(current_user) == 2 #用户已提交且试卷提交中 if @exercise.time == -1 || ((Time.now.to_i - exercise_user.start_at.to_i) < @exercise.time.to_i * 60) exercise_user.update_attributes(:score => nil, :end_at => nil, :status => nil, :commit_status => 0, :objective_score => 0.0, :subjective_score => -1.0) @@ -1024,7 +1019,7 @@ class ExercisesController < ApplicationController # @user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间 # end - @t_user_exercise_status = @exercise.get_exercise_status(current_user.id) + @t_user_exercise_status = @exercise.get_exercise_status(current_user) @user_left_time = nil if @user_course_identity < Course::STUDENT || (@t_user_exercise_status == 3) || @@ -1137,7 +1132,7 @@ class ExercisesController < ApplicationController # @exercise_answerer = User.find_by(id:@exercise_current_user_id) #试卷回答者 @exercise_questions = @exercise.exercise_questions.order("question_number ASC") @question_status = [] - get_exercise_status = @exercise.get_exercise_status(current_user.id) + get_exercise_status = @exercise.get_exercise_status(current_user) if @ex_user.present? && @is_teacher_or == 0 if get_exercise_status == 2 #当前用户已提交,且试卷未截止 if @ex_user.commit_status == 0 #学生未提交,且当前为学生 @@ -1165,7 +1160,7 @@ class ExercisesController < ApplicationController begin @current_user_id = current_user.id exercise_ids = [@exercise.id] - @exercise_status = @exercise.get_exercise_status(current_user.id) + @exercise_status = @exercise.get_exercise_status(current_user) @course_all_members = @course.students @c_group_counts = @course.course_groups_count question_types = @exercise.exercise_questions.pluck(:question_type).uniq @@ -1370,7 +1365,7 @@ class ExercisesController < ApplicationController @exercise_commit_users = @exercise_all_users.commit_exercise_by_status(1) #试卷的已提交用户 @exercise_commit_user_ids = @exercise_commit_users.pluck(:user_id).uniq #已提交试卷的全部用户id @exercise_commit_user_counts = @exercise_commit_users.count #试卷的已提交用户人数 - @exercise_status = @exercise.get_exercise_status(current_user.id) + @exercise_status = @exercise.get_exercise_status(current_user) #提交率 if @course_all_members_count == 0 @@ -1552,7 +1547,7 @@ class ExercisesController < ApplicationController exercises_all.each do |exercise| if exercise.present? if exercise.unified_setting #统一设置只有两种情况,全部发布,全部截止 - exercise_user_status = exercise.get_exercise_status(current_user.id) #当前用户的能看到的试卷 + exercise_user_status = exercise.get_exercise_status(current_user) #当前用户的能看到的试卷 if exercise_user_status == exercise_status || exercise_status == 3 #未发布的情况 unpublish_group = unpublish_group + user_groups_id else @@ -1622,7 +1617,7 @@ class ExercisesController < ApplicationController ## 判断开始答题页面的用户权限 def check_user_on_answer - if @user_course_identity == Course::STUDENT && @exercise.get_exercise_status(current_user.id) == 1 #试卷未发布,且当前用户不为老师/管理员 + if @user_course_identity == Course::STUDENT && @exercise.get_exercise_status(current_user) == 1 #试卷未发布,且当前用户不为老师/管理员 normal_status(-1, "未发布试卷!") elsif @user_course_identity > Course::STUDENT && (!@exercise.is_public || (@exercise.is_public && !@exercise.unified_setting)) ##不为课堂成员,且试卷不为公开的,或试卷公开,但不是统一设置的 normal_status(-1, "试卷暂未公开!") @@ -1639,7 +1634,7 @@ class ExercisesController < ApplicationController #打回重做时的初步判断 def check_exercise_status @exercise_users = @exercise.all_exercise_users(current_user.id).commit_exercise_by_status(1) #当前教师所在分班的全部已提交的学生数 - if @exercise.get_exercise_status(current_user.id) != 2 + if @exercise.get_exercise_status(current_user) != 2 normal_status(-1,"非提交中的试卷不允许打回重做!") elsif @exercise_users.count < 1 normal_status(-1,"暂无人提交试卷!") @@ -1649,7 +1644,7 @@ class ExercisesController < ApplicationController #查看试题页面,当为学生时,除非试卷已截止,或已提交才可以查看 def check_exercise_is_end - ex_status = @exercise.get_exercise_status(current_user.id) + ex_status = @exercise.get_exercise_status(current_user) @ex_user = @exercise.exercise_users.find_by(user_id:@exercise_current_user_id) #该试卷的回答者 if @user_course_identity > Course::ASSISTANT_PROFESSOR if ex_status == 1 @@ -1666,7 +1661,7 @@ class ExercisesController < ApplicationController def check_exercise_public if @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生,试卷公开统计,且已截止,且已提交 ex_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first - unless @exercise.get_exercise_status(current_user.id) == 3 && ex_user.present? && ex_user.commit_status == 1 && + unless @exercise.get_exercise_status(current_user) == 3 && ex_user.present? && ex_user.commit_status == 1 && @exercise.show_statistic normal_status(-1,"学生暂不能查看") end diff --git a/app/controllers/poll_votes_controller.rb b/app/controllers/poll_votes_controller.rb index f1da3a1b2..c11248054 100644 --- a/app/controllers/poll_votes_controller.rb +++ b/app/controllers/poll_votes_controller.rb @@ -134,7 +134,7 @@ class PollVotesController < ApplicationController end def check_answer_in_question - poll_user_status = @poll.get_poll_status(current_user.id) + poll_user_status = @poll.get_poll_status(current_user) poll_user = @poll.poll_users.find_by(user_id: current_user.id) #当前用户 question_type = @poll_question&.question_type diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index d94299454..fa8d7dd8c 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -31,50 +31,48 @@ class PollsController < ApplicationController @current_user_ = current_user @course_status = @course.is_end ? 0 : 1 # 课堂是否结束 @course_is_public = @course.is_public - @polls_count = @polls_all.count # 全部页面,需返回 - @polls_unpublish_counts = @polls_all.poll_by_status(1).count #未发布的问卷数 - @polls_published_counts = @polls_all.poll_by_status([2, 3]).count # 已发布的问卷数 # 课堂的学生人数 @course_all_members = @course.students #当前课堂的全部学生 - @course_all_members_count = @course_all_members.count #当前课堂的学生数 @current_student = @course_all_members.find_by(user_id: current_user.id) #当前用户是否为课堂的学生 - # polls的不同用户群体的显示 if @user_course_identity < Course::STUDENT # @is_teacher_or 1为老师/管理员/助教 @is_teacher_or = 1 - @teacher_groups_ids = @course.charge_group_ids(current_user) @polls = @polls_all #老师能看到全部的问卷,不管是已发布的/未发布的/已截止的/统一设置的/私有设置的(看到内容不同) elsif @user_course_identity == Course::STUDENT # 2为课堂成员,能看到统一设置的和自己班级的 @is_teacher_or = 2 - member_group_id = @current_student.try(:course_group_id).to_i # 成员的分班id,默认为0 - if member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的) + @member_group_id = @current_student.try(:course_group_id).to_i # 成员的分班id,默认为0 + if @member_group_id == 0 #表示是课堂的未分班成员,只能查看统一设置的试卷(已发布的/已截止的) @polls = member_show_polls.size > 0 ? member_show_polls.public_or_unset : [] else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷 # 已发布 当前用户班级分组的 试卷id - poll_settings_ids = @course.poll_group_settings.where(course_group_id: member_group_id).poll_group_published.pluck(:poll_id).uniq # 选择成员的班级id等于课堂问卷设置的班级id - @polls = member_show_polls.present? ? member_show_polls.public_or_unset.or(member_show_polls.where(id: poll_settings_ids)) : [] + not_poll_ids = @course.poll_group_settings.poll_group_not_published.where("course_group_id = #{@member_group_id}").pluck(:poll_id) + @polls = member_show_polls.where.not(id: not_poll_ids) end else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁 @is_teacher_or = 0 - @polls = member_show_polls.size > 0 ? member_show_polls.public_or_unset : [] + @polls = member_show_polls.public_or_unset end + if @polls.count > 0 if params[:type].present? choose_type = params[:type] - member_group_id = @current_student.try(:course_group_id).to_i # 成员的分班id,默认为0 - if @is_teacher_or == 2 && member_group_id > 0 - poll_groups_sets = @course.poll_group_settings.where(course_group_id: member_group_id).poll_group_published - poll_settings_ids = poll_groups_sets.pluck(:poll_id) - poll_ended_ids = poll_groups_sets.poll_group_ended.pluck(:poll_id).uniq - # poll_settings_ids = @course.poll_group_settings.where(course_group_id: member_group_id).poll_group_ended.pluck(:poll_id).uniq - if choose_type.to_i == 2 - @polls = @polls_all.present? ? @polls_all.poll_by_status(2).public_or_unset.or(@polls_all.where(id:(poll_settings_ids - poll_ended_ids).uniq)).distinct : [] - elsif choose_type.to_i == 3 - @polls = @polls_all.present? ? @polls_all.poll_by_status(3).public_or_unset.or(@polls_all.where(id: poll_ended_ids)).distinct : [] - end + poll_setting_ids = [] + if @is_teacher_or != 2 + @polls = @polls.where("polls_status = #{choose_type}") else - @polls = @polls.poll_by_status(choose_type) + case choose_type + when 1 + poll_setting_ids = @course.poll_group_settings.where("course_group_id = #{@member_group_id}").poll_group_not_published.pluck(:poll_id) + when 2 + poll_setting_ids = @course.poll_group_settings.where("course_group_id = #{@member_group_id}") + .where("publish_time is not null and publish_time <= ? and end_time > ?",Time.now,Time.now).pluck(:poll_id) + when 3 + poll_setting_ids = @course.poll_group_settings.where("course_group_id = #{@member_group_id}").poll_group_ended.pluck(:poll_id) + end + unified_setting_ids = @polls.public_or_unset.where("polls_status = #{choose_type}").pluck(:id) + ex_ids = (poll_setting_ids + unified_setting_ids).uniq + @polls = @polls.where(id: ex_ids) end end @@ -91,10 +89,15 @@ class PollsController < ApplicationController @polls = @polls.page(@page).per(@limit) @polls = @polls&.includes(:poll_users,:poll_questions,:poll_group_settings) - else @polls = [] end + + @polls_count = @polls_all.size # 全部页面,需返回 + @polls_unpublish_counts = @polls_all.poll_by_status(1).size #未发布的问卷数 + @polls_published_counts = @polls_count - @polls_unpublish_counts # 已发布的问卷数 + @course_all_members_count = @course_all_members.size #当前课堂的学生数 + rescue Exception => e uid_logger_error(e.message) tip_exception(e.message) @@ -202,7 +205,7 @@ class PollsController < ApplicationController @is_teacher_or = 1 @user_poll_answer = 3 #教师页面 end - poll_status = @poll.get_poll_status(current_user.id) + poll_status = @poll.get_poll_status(current_user) poll_id_array = [@poll.id] @poll_publish_count = get_user_permission_course(poll_id_array,2).count #是否存在已发布的 @poll_unpublish_count = get_user_permission_course(poll_id_array,1).count #是否存在未发布的 @@ -344,7 +347,7 @@ class PollsController < ApplicationController begin check_ids = Poll.where(id: params[:check_ids]) check_ids.each do |poll| - poll_status = poll.get_poll_status(current_user.id) + poll_status = poll.get_poll_status(current_user) if poll_status == 2 #跳过已截止的或未发布的 g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数,那么poll的统一设置需修改,poll_group_settings if g_course @@ -687,7 +690,7 @@ class PollsController < ApplicationController course_group_ids = @course.charge_group_ids(current_user) #当前老师的班级id数组 - poll_status = @poll.get_poll_status(current_user.id) + poll_status = @poll.get_poll_status(current_user) if poll_status == 1 && course_group_ids.size > 0 # 问卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按poll默认的来处理 unified_setting = params[:unified_setting] else @@ -847,7 +850,7 @@ class PollsController < ApplicationController ActiveRecord::Base.transaction do begin poll_user_current = @poll.poll_users.find_by_group_ids(@poll_current_user_id).first #查找当前用户是否有过答题 - @poll_status = @poll.get_poll_status(current_user.id) + @poll_status = @poll.get_poll_status(current_user) if poll_user_current.blank? if @user_course_identity > Course::ASSISTANT_PROFESSOR #当为老师的时候,不创建poll_user表,理论上老师是不能进入答题的 poll_user_params = { @@ -955,7 +958,7 @@ class PollsController < ApplicationController ActiveRecord::Base.transaction do begin poll_ids = [@poll.id] - @poll_list_status = @poll.get_poll_status(current_user.id) + @poll_list_status = @poll.get_poll_status(current_user) @poll_publish_count = get_user_permission_course(poll_ids,2).count @poll_unpublish_count = get_user_permission_course(poll_ids,1).count @course_all_members = @course.students @@ -1103,7 +1106,7 @@ class PollsController < ApplicationController ## 判断开始答题页面的用户权限 def check_user_on_answer - poll_status = @poll.get_poll_status(current_user.id) + poll_status = @poll.get_poll_status(current_user) if @user_course_identity == Course::STUDENT && poll_status == 1 #问卷未发布,且当前用户不为老师/管理员 normal_status(-1, "未发布问卷!") elsif @user_course_identity > Course::STUDENT && (!@poll.is_public || (@poll.is_public && !@poll.unified_setting)) ##不为课堂成员,且问卷不为公开的,或问卷公开,但是不是统一设置的 @@ -1160,7 +1163,7 @@ class PollsController < ApplicationController def check_poll_question_complete #commit_poll 的权限 poll_user_current = @poll.poll_users.find_by_group_ids(current_user.id).first - poll_status = @poll.get_poll_status(current_user.id) + poll_status = @poll.get_poll_status(current_user) if @user_course_identity < Course::STUDENT || (poll_status == 3) || (poll_user_current.present? && poll_user_current.commit_status == 1) normal_status(-1,"用户没有权限!") #老师/管理员在提交时没有权限 else @@ -1182,7 +1185,7 @@ class PollsController < ApplicationController end def check_poll_commit_result - poll_status = @poll.get_poll_status(current_user.id) + poll_status = @poll.get_poll_status(current_user) commit_poll_user = @poll.poll_users.find_by_group_ids(current_user.id).commit_by_status(1) #当前用户已提交问卷的 unless (@user_course_identity < Course::STUDENT) || ((@poll.show_result == 1) && (poll_status == 3) && commit_poll_user.present?) normal_status(-1,"没有权限!") #当前为老师/问卷公开统计,且问卷已截止,且用户有过回答的 @@ -1214,18 +1217,12 @@ class PollsController < ApplicationController def get_user_permission_course(poll_ids,status) #获取用户权限范围内的已发布/未发布 poll_status = status.to_i unpublish_group = [] - # g_course_ids = @course.teacher_course_groups.get_user_groups(current_user.id).pluck(:course_group_id).reject(&:blank?).uniq - # if g_course_ids.blank? || g_course_ids.include?(0) #当前用户的分班权限为空,即具体全部的分班权限 - # user_groups_id = @course.course_groups.pluck(:id) - # else - # user_groups_id = g_course_ids - # end user_groups_id = @course.charge_group_ids(current_user) all_polls = Poll.where(id:poll_ids) all_polls.each do |poll| if poll.present? if poll.unified_setting - poll_user_status = poll.get_poll_status(current_user.id) #当前用户的能看到的试卷 + poll_user_status = poll.get_poll_status(current_user) #当前用户的能看到的试卷 if poll_user_status == poll_status || poll_status == 3 #未发布的情况 unpublish_group = unpublish_group + user_groups_id else diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 2d21237f5..e8a2874dd 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -42,7 +42,7 @@ class ZipsController < ApplicationController ActiveRecord::Base.transaction do begin @exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id]) - @exercise_status = @exercise.present? ? @exercise.get_exercise_status(current_user.id) : 1 + @exercise_status = @exercise.present? ? @exercise.get_exercise_status(current_user) : 1 group_id = params[:exercise_group_id] if @exercise.blank? normal_status(-1,"试卷不存在") diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 8174d1eea..ca2f6d47c 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -252,7 +252,7 @@ module ExercisesHelper #获取试卷的已答/未答人数 def get_exercise_answers(ex_users) @exercise_answers = ex_users.commit_exercise_by_status(1).size #表示已经提交了的用户 - course_all_members_count = ex_users.exists? ? ex_users.size : 0 + course_all_members_count = ex_users.size @exercise_unanswers = (course_all_members_count - @exercise_answers) end @@ -266,7 +266,7 @@ module ExercisesHelper elsif is_teacher_or == 1 #当前为老师的时候,显示的是老师身份的对应试卷的状态,因为该试卷,可能对应老师的多个分班 exercise_status = exercise.exercise_status else - exercise_status = exercise.get_exercise_status(user.id) #当前用户查看的试卷的发布状态 + exercise_status = exercise.get_exercise_status(user) #当前用户查看的试卷的发布状态 end case exercise_status @@ -509,7 +509,7 @@ module ExercisesHelper ex_user_user = ex_user.user exercise_user_name = ex_user_user.real_name exercise_user_id = ex_user_user.id - ex_user_exercise_status = exercise.get_exercise_status(exercise_user_id) + ex_user_exercise_status = exercise.get_exercise_status(ex_user_user) ex_user_student_id = ex_user_user.student_id if ex_user.start_at.present? && ex_user.commit_status == 0 #用户已回答,但未提交 commit_status = 2 #继续答题 diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index aee95eef7..54a9fe1f0 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -2,9 +2,8 @@ module PollsHelper #获取试卷的已答/未答人数 def get_poll_answers(poll_users) - @commit_poll_users = poll_users.commit_by_status(1) #当前老师的全部学生中已提交的 - @poll_answers = @commit_poll_users.present? ? @commit_poll_users.size : 0 #表示已经提交了的用户 - course_all_members_count = poll_users.present? ? poll_users.size : 0 + @poll_answers = poll_users.commit_by_status(1).size #表示已经提交了的用户 + course_all_members_count = poll_users.size @poll_unanswers = (course_all_members_count - @poll_answers) end @@ -55,7 +54,7 @@ module PollsHelper #当前为老师(非课堂成员、统一设置)的时候,显示的是老师身份的对应试卷的状态,因为该试卷,可能对应老师的多个分班 poll_status = poll.polls_status else - poll_status = poll.get_poll_status(user.id) #当前用户查看的试卷的发布状态 + poll_status = poll.get_poll_status(user) #当前用户查看的试卷的发布状态 end if is_teacher_or == 1 diff --git a/app/models/course.rb b/app/models/course.rb index 7729a2650..f61ff1e2a 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -124,7 +124,7 @@ class Course < ApplicationRecord #当前老师的班级id def teacher_course_ids(user_id) - course_teacher_member = teacher_course_groups.get_user_groups(user_id) #获取当前老师的分班 + course_teacher_member = teacher_course_groups.get_user_groups(user_id).select(:course_group_id) #获取当前老师的分班 if course_teacher_member.blank? if none_group_count > 0 #有未分班的,则发布到未发布分班 un_group_ids = [0] diff --git a/app/models/exercise.rb b/app/models/exercise.rb index bc5424b6e..150988a49 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -57,10 +57,10 @@ class Exercise < ApplicationRecord #统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生 def all_exercise_users(user_id) - ex_users = self.exercise_users + ex_users = exercise_users group_ids = common_published_ids(user_id) if group_ids.present? - ex_users = ex_users.where(user_id: course.students.where(course_group_id: group_ids).pluck(:user_id)) + ex_users = ex_users.where(user_id: course.students.where(course_group_id: group_ids).select(:user_id).pluck(:user_id)) end ex_users end @@ -72,7 +72,7 @@ class Exercise < ApplicationRecord un_group_ids = (course.none_group_count > 0) ? [0] : [] published_group_ids = (current_user_groups + un_group_ids).uniq #统一设置时,为当前用户的分班id及未分班 else - ex_group_setting = exercise_group_settings.pluck("course_group_id").uniq + ex_group_setting = exercise_group_settings.select(:course_group_id).pluck("course_group_id").uniq common_all_ids = ex_group_setting & current_user_groups #当前用户有权限的已发布的分班id #非统一设置时,为当前用户有权限的且已发布分班的id published_group_ids = common_all_ids.uniq end @@ -89,11 +89,9 @@ class Exercise < ApplicationRecord end #判断是否为分班,如果分班,试卷的截止时间为当前分班时间,否则为试卷的截止时间 - def get_exercise_status(user_id) - user_group = course.course_members.find_by(user_id: user_id) - if user_group.present? && user_group.role == "STUDENT" #当为学生的时候,需根据分班来判断试卷状态 + def get_exercise_status(user) + if user.student_of_course?(course) #当为学生的时候,需根据分班来判断试卷状态 ex_time = get_exercise_times(user_id,false) - pb_time = ex_time[:publish_time] ed_time = ex_time[:end_time] @@ -115,18 +113,17 @@ class Exercise < ApplicationRecord if unified_setting || teacher #当试卷为统一设置或当前为老师的时候 pb_time = publish_time en_time = end_time - - if en_time.present? && (en_time <= Time.now) && (exercise_status != 3) + if (exercise_status != 3) && en_time.present? && (en_time <= Time.now) update_column("exercise_status",3) end else ex_group_setting = exercise_group_settings - user_group = course.students.course_find_by_ids("user_id",user_id) + user_group = course.students.where(user_id:user_id).select(:course_group_id) if user_group.exists? - user_group_id = user_group.first.course_group_id - user_ex_group_setting = ex_group_setting.find_in_exercise_group("course_group_id",user_group_id) - pb_time = user_ex_group_setting.exists? ? user_ex_group_setting.first.publish_time : nil - en_time = user_ex_group_setting.exists? ? user_ex_group_setting.first.end_time : nil + user_group_id = user_group.first&.course_group_id + user_ex_group_setting = ex_group_setting.where(course_group_id:user_group_id).select(:publish_time,:end_time) + pb_time = user_ex_group_setting.first&.publish_time + en_time = user_ex_group_setting.first&.end_time else pb_time = nil en_time = nil @@ -141,13 +138,13 @@ class Exercise < ApplicationRecord #判断当前用户的答题状态 def check_user_answer_status(user) - ex_answer_user = exercise_users.find_by(user_id: user.id) - user_ex_status = get_exercise_status(user.id) + ex_answer_user = exercise_users.where(user_id: user.id).select(:start_at,:end_at,:commit_status) + user_ex_status = get_exercise_status(user) user_status = 2 - if ex_answer_user.present? && (ex_answer_user.start_at.present? || ex_answer_user.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 + if ex_answer_user.exists? && (ex_answer_user.first&.start_at.present? || ex_answer_user.first&.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 user_status = ex_answer_user.commit_status end - if ex_answer_user.present? && ex_answer_user.start_at.blank? && user_ex_status == 3 + if ex_answer_user.exists? && ex_answer_user.first&.start_at.blank? && user_ex_status == 3 user_status = 4 end diff --git a/app/models/poll.rb b/app/models/poll.rb index 0434068cd..ed3c143fa 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -45,8 +45,7 @@ class Poll < ApplicationRecord poll_users else ex_group_setting_ids = poll_group_settings.poll_group_published.pluck(:course_group_id) - course_user_ids = course.students.where(course_group_id:ex_group_setting_ids).pluck(:user_id) - poll_users.where(user_id:course_user_ids) + poll_users.where(user_id: course.students.where(course_group_id:ex_group_setting_ids).pluck(:user_id).uniq) end end @@ -55,7 +54,7 @@ class Poll < ApplicationRecord poll_all_users = poll_users group_ids = poll_published_ids(user_id) if group_ids.present? - poll_all_users = poll_all_users.where(user_id: course.students.where(course_group_id: group_ids).pluck(:user_id).uniq) + poll_all_users = poll_all_users.where(user_id: course.students.where(course_group_id: group_ids).select(:user_id).pluck(:user_id).uniq) end poll_all_users end @@ -71,20 +70,14 @@ class Poll < ApplicationRecord end (current_user_groups + un_group_ids).uniq #统一设置时,为当前用户的分班id else - ex_group_setting = poll_group_settings.pluck("course_group_id").uniq + ex_group_setting = poll_group_settings.select(:course_group_id).pluck("course_group_id").uniq ex_group_setting & current_user_groups #当前用户有权限的已发布的分班id #非统一设置时,为当前用户有权限的且已发布分班的id end end - def get_poll_status(user_id) - user_group = course.course_members.find_by(user_id: user_id, is_active: 1) - if user_group.present? - if user_group.role == "STUDENT" #为学生 - is_teacher = false - else - is_teacher = true - end - ex_time = get_poll_times(user_id,is_teacher) + def get_poll_status(user) + if user.student_of_course?(course) + ex_time = get_poll_times(user_id,false) pb_time = ex_time[:publish_time] ed_time = ex_time[:end_time] if pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now @@ -102,30 +95,20 @@ class Poll < ApplicationRecord #获取问卷的发布时间和截止时间。teacher 为boolean,当为true时,表示的是当前为老师 def get_poll_times(user_id,teacher) - if unified_setting + if unified_setting || teacher pb_time = publish_time en_time = end_time else poll_group_setting = poll_group_settings - if teacher #当前为老师,为设置组的最大值和最小值 - user_group = course.teacher_course_groups.get_user_groups(user_id) - user_group_ids = user_group.present? ? user_group.pluck(:course_group_id) : course.course_groups.pluck(:id) - user_poll_group_settings = poll_group_setting.find_in_poll_group("course_group_id",user_group_ids) - pb_time_min = user_poll_group_settings.publish_time_present.map(&:publish_time) - en_time_max = user_poll_group_settings.end_time_present.map(&:end_time) - pb_time = pb_time_min.size > 0 ? pb_time_min.min : nil - en_time = en_time_max.size > 0 ? en_time_max.max : nil + user_group = course.course_members.where(user_id: user_id).select(:course_group_id) + if user_group.exists? + user_group_id = user_group.first&.course_group_id + user_p_group_setting = poll_group_setting.where(course_group_id: user_group_id).select(:publish_time,:end_time) + pb_time = user_p_group_setting.first&.publish_time + en_time = user_p_group_setting.first&.end_time else - user_group = course.students.find_by(user_id: user_id) - if user_group.present? - user_group_id = user_group.course_group_id - user_p_group_setting = poll_group_setting.find_by(course_group_id: user_group_id) - pb_time = user_p_group_setting.present? ? user_p_group_setting.publish_time : nil - en_time = user_p_group_setting.present? ? user_p_group_setting.end_time : nil - else - pb_time = nil - en_time = nil - end + pb_time = nil + en_time = nil end end { @@ -136,19 +119,11 @@ class Poll < ApplicationRecord #判断当前用户的答题状态 def check_user_votes_status(user) - poll_answer_user = poll_users.find_by(user_id: user.id) - # user_poll_status = get_poll_status(user.id) + poll_answer_user = poll_users.where(user_id: user.id).select(:start_at,:end_at,:commit_status) user_status = 2 - - if poll_answer_user.present? && (poll_answer_user.start_at.present? || poll_answer_user.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 + if poll_answer_user.exists? && (poll_answer_user.first&.start_at.present? || poll_answer_user.first&.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 user_status = poll_answer_user.commit_status end - # - # if poll_answer_user.present? && poll_answer_user.start_at.blank? && user_poll_status == 3 - # # user_status = 4 - # user_status = 2 #问卷用户存在,且未开始答题,且问卷已截止时,返回未提交标示 - # end - user_status end diff --git a/app/views/exercises/index.json.jbuilder b/app/views/exercises/index.json.jbuilder index 4c143da4b..bccce4f2b 100644 --- a/app/views/exercises/index.json.jbuilder +++ b/app/views/exercises/index.json.jbuilder @@ -2,13 +2,12 @@ if @exercises_count > 0 json.exercises do json.array! @exercises do |exercise| - ex_index = exercise_index_show(exercise,@course,@is_teacher_or,@current_user_) json.extract! exercise, :id, :exercise_name,:is_public,:created_at if @is_teacher_or == 2 second_left = get_exercise_left_time(exercise,@current_user_) json.time second_left.present? ? (second_left / 60) : nil end - + ex_index = exercise_index_show(exercise,@course,@is_teacher_or,@current_user_) json.exercise_status ex_index[:ex_status] json.lock_status ex_index[:lock_icon] json.publish_time ex_index[:publish_time] # 试卷的发布时间 diff --git a/app/views/polls/index.json.jbuilder b/app/views/polls/index.json.jbuilder index b657da7a0..0face0966 100644 --- a/app/views/polls/index.json.jbuilder +++ b/app/views/polls/index.json.jbuilder @@ -1,18 +1,4 @@ - json.polls_counts do - json.polls_total_counts @polls_count #全部问卷数 - json.polls_all_counts @polls_select_count #选择后的问卷数 - json.polls_unpublish_counts @polls_unpublish_counts #未发布问卷数 - json.polls_published_counts @polls_published_counts #已发布问卷数 - # json.polls_ended_counts @polls_ended_counts #已截止问卷数 - json.left_banner_id @left_banner_id - json.left_banner_name @left_banner_name -end -json.course_types do - json.course_status @course_status # 课堂的当前是否结束,如结束,则为1,否则为0 - json.course_is_public @course_is_public #判断课堂是否为公开,只有公开课才有设为公开的按钮 - json.user_permission @is_teacher_or # 当前用户存在且为课堂教师/管理员/超级管理员时为1 ,课堂成员为2,否则为0 -end if @polls_count > 0 json.polls do @@ -32,3 +18,17 @@ else json.polls [] end +json.polls_counts do + json.polls_total_counts @polls_count #全部问卷数 + json.polls_all_counts @polls_select_count #选择后的问卷数 + json.polls_unpublish_counts @polls_unpublish_counts #未发布问卷数 + json.polls_published_counts @polls_published_counts #已发布问卷数 + json.left_banner_id @left_banner_id + json.left_banner_name @left_banner_name +end + +json.course_types do + json.course_status @course_status # 课堂的当前是否结束,如结束,则为1,否则为0 + json.course_is_public @course_is_public #判断课堂是否为公开,只有公开课才有设为公开的按钮 + json.user_permission @is_teacher_or # 当前用户存在且为课堂教师/管理员/超级管理员时为1 ,课堂成员为2,否则为0 +end From 878b1e6c21e8a62ae6f1021c4a2a9c1811991cbe Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 6 Jul 2019 15:54:40 +0800 Subject: [PATCH 0665/1015] add user attribteus chinese name --- config/locales/users/zh-CN.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/config/locales/users/zh-CN.yml b/config/locales/users/zh-CN.yml index 5c4ad76a7..48b8ca075 100644 --- a/config/locales/users/zh-CN.yml +++ b/config/locales/users/zh-CN.yml @@ -1,4 +1,11 @@ 'zh-CN': + activerecord: + models: + user: '用户' + attributes: + user: + phone: '手机号' + mail: '邮箱' user: identity: teacher: 教师 From 8b7ba5c765266cbe8f9243eafb35530eef200897 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 6 Jul 2019 16:53:03 +0800 Subject: [PATCH 0666/1015] =?UTF-8?q?=E8=B0=83=E5=88=86=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 2 +- app/services/homeworks_service.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 7c7201d32..309c8b379 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -335,6 +335,7 @@ class StudentWorksController < ApplicationController begin # 没传score则取上次评分成绩 new_score = StudentWorksScore.new + score = StudentWorksScore.where(user_id: current_user.id, student_work_id: @work.id, reviewer_role: reviewer_role).last new_score.score = params[:score].blank? ? score.try(:score) : params[:score].to_f new_score.comment = params[:comment] if params[:comment] && params[:comment].strip != "" new_score.user_id = current_user.id @@ -349,7 +350,6 @@ class StudentWorksController < ApplicationController reviewer_role = @user_course_identity == Course::STUDENT ? 3 : @user_course_identity == Course::ASSISTANT_PROFESSOR ? 2 : 1 new_score.reviewer_role = reviewer_role - score = StudentWorksScore.where(user_id: current_user.id, student_work_id: @work.id, reviewer_role: reviewer_role).last if new_score.save! Attachment.associate_container(params[:attachment_ids], new_score.id, new_score.class) diff --git a/app/services/homeworks_service.rb b/app/services/homeworks_service.rb index 306a48d3c..4d16b5456 100644 --- a/app/services/homeworks_service.rb +++ b/app/services/homeworks_service.rb @@ -316,7 +316,7 @@ class HomeworksService if work.work_status == 0 is_complete = myshixun_endtime && (myshixun_endtime < setting_time.end_time) - if is_complete || (!homework.allow_late && myshixun.created_at < setting_time.end_time) + if is_complete || (myshixun.created_at < setting_time.end_time && (!homework.allow_late || setting_time.end_time <= Time.now)) work.work_status = 1 elsif homework.allow_late && myshixun.created_at < homework.late_time work.work_status = 2 From a83b4f13272ddbc02de50088bb496c798aa658e3 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 6 Jul 2019 16:54:03 +0800 Subject: [PATCH 0667/1015] =?UTF-8?q?=E8=B0=83=E5=88=86=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 309c8b379..92d146c82 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -334,6 +334,7 @@ class StudentWorksController < ApplicationController ActiveRecord::Base.transaction do begin # 没传score则取上次评分成绩 + reviewer_role = @user_course_identity == Course::STUDENT ? 3 : @user_course_identity == Course::ASSISTANT_PROFESSOR ? 2 : 1 new_score = StudentWorksScore.new score = StudentWorksScore.where(user_id: current_user.id, student_work_id: @work.id, reviewer_role: reviewer_role).last new_score.score = params[:score].blank? ? score.try(:score) : params[:score].to_f @@ -348,7 +349,6 @@ class StudentWorksController < ApplicationController @work.update_attributes(group_id: @homework.max_group_id) if @homework.homework_type == "group" end - reviewer_role = @user_course_identity == Course::STUDENT ? 3 : @user_course_identity == Course::ASSISTANT_PROFESSOR ? 2 : 1 new_score.reviewer_role = reviewer_role if new_score.save! From 177dded9690bc4c350f6b91d4e197be69181e1cc Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 6 Jul 2019 17:02:33 +0800 Subject: [PATCH 0668/1015] =?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/views/homework_commons/index.json.jbuilder | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/views/homework_commons/index.json.jbuilder b/app/views/homework_commons/index.json.jbuilder index 5b9717c2f..60aa720f5 100644 --- a/app/views/homework_commons/index.json.jbuilder +++ b/app/views/homework_commons/index.json.jbuilder @@ -25,14 +25,16 @@ json.homeworks @homework_commons.each do |homework| if @user_course_identity < Course::STUDENT if homework.homework_type == "practice" - json.shixun_identifier homework.shixuns.first.try(:identifier) + json.shixun_identifier homework.shixuns.take.try(:identifier) end elsif @user_course_identity == Course::STUDENT if homework.homework_type == "practice" + shixun = homework.shixuns.take # json.challenge_count homework.shixuns.first.try(:challenges_count).to_i current_myshixun = homework.user_work(@user.id).try(:myshixun) + myshixun = current_myshixun ? current_myshixun : shixun.myshixuns.find_by(user_id: @user.id) # json.game_count current_myshixun ? current_myshixun.exec_count : 0 - json.task_operation task_operation_url(current_myshixun, homework.shixuns.first) + json.task_operation task_operation_url(current_myshixun, shixun) else work = homework.user_work(@user.id) json.work_id work.try(:id) From bf9796c8b59b5c06d976ada22670b32698f2a23c Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 6 Jul 2019 17:03:24 +0800 Subject: [PATCH 0669/1015] =?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/views/homework_commons/index.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/homework_commons/index.json.jbuilder b/app/views/homework_commons/index.json.jbuilder index 60aa720f5..9107c9634 100644 --- a/app/views/homework_commons/index.json.jbuilder +++ b/app/views/homework_commons/index.json.jbuilder @@ -34,7 +34,7 @@ json.homeworks @homework_commons.each do |homework| current_myshixun = homework.user_work(@user.id).try(:myshixun) myshixun = current_myshixun ? current_myshixun : shixun.myshixuns.find_by(user_id: @user.id) # json.game_count current_myshixun ? current_myshixun.exec_count : 0 - json.task_operation task_operation_url(current_myshixun, shixun) + json.task_operation task_operation_url(myshixun, shixun) else work = homework.user_work(@user.id) json.work_id work.try(:id) From 281a49a8b0175e6bdedebcc769fd7c96e7a0947c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 6 Jul 2019 17:16:29 +0800 Subject: [PATCH 0670/1015] fixbug --- app/helpers/exercises_helper.rb | 2 +- app/models/exercise.rb | 2 +- app/models/poll.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index ca2f6d47c..3bc342c06 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -511,7 +511,7 @@ module ExercisesHelper exercise_user_id = ex_user_user.id ex_user_exercise_status = exercise.get_exercise_status(ex_user_user) ex_user_student_id = ex_user_user.student_id - if ex_user.start_at.present? && ex_user.commit_status == 0 #用户已回答,但未提交 + if ex_user.start_at.present? && (ex_user.commit_status == 0) #用户已回答,但未提交 commit_status = 2 #继续答题 else commit_status = ex_user.commit_status diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 150988a49..606132c27 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -142,7 +142,7 @@ class Exercise < ApplicationRecord user_ex_status = get_exercise_status(user) user_status = 2 if ex_answer_user.exists? && (ex_answer_user.first&.start_at.present? || ex_answer_user.first&.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 - user_status = ex_answer_user.commit_status + user_status = ex_answer_user.first.commit_status end if ex_answer_user.exists? && ex_answer_user.first&.start_at.blank? && user_ex_status == 3 user_status = 4 diff --git a/app/models/poll.rb b/app/models/poll.rb index ed3c143fa..a055fd656 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -122,7 +122,7 @@ class Poll < ApplicationRecord poll_answer_user = poll_users.where(user_id: user.id).select(:start_at,:end_at,:commit_status) user_status = 2 if poll_answer_user.exists? && (poll_answer_user.first&.start_at.present? || poll_answer_user.first&.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 - user_status = poll_answer_user.commit_status + user_status = poll_answer_user.first.commit_status end user_status end From 5ccaeb4a272535e801869a8ed456db7758458562 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 6 Jul 2019 17:17:29 +0800 Subject: [PATCH 0671/1015] =?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/services/homeworks_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/homeworks_service.rb b/app/services/homeworks_service.rb index 4d16b5456..b835685a6 100644 --- a/app/services/homeworks_service.rb +++ b/app/services/homeworks_service.rb @@ -316,7 +316,7 @@ class HomeworksService if work.work_status == 0 is_complete = myshixun_endtime && (myshixun_endtime < setting_time.end_time) - if is_complete || (myshixun.created_at < setting_time.end_time && (!homework.allow_late || setting_time.end_time <= Time.now)) + if is_complete || (myshixun.created_at < setting_time.end_time && (!homework.allow_late || setting_time.end_time >= Time.now)) work.work_status = 1 elsif homework.allow_late && myshixun.created_at < homework.late_time work.work_status = 2 From 0ef3779b1703cce7ce3b4fd9c214dd9c2afa42fb Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 6 Jul 2019 17:53:21 +0800 Subject: [PATCH 0672/1015] fixbug --- app/controllers/exercises_controller.rb | 28 ++++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index ea424a411..9de91ca0e 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1291,16 +1291,24 @@ class ExercisesController < ApplicationController elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) normal_status(-1,"暂无用户提交") else - respond_to do |format| - format.xlsx{ - get_export_users(@exercise,@course,@export_ex_users) - exercise_export_name_ = - "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}" - exercise_export_name = Base64.urlsafe_encode64(exercise_export_name_.strip.first(30)) - - render xlsx: "#{exercise_export_name}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} - } - end + get_export_users(@exercise,@course,@export_ex_users) + exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}" + ex_xlsx = render_to_string handlers: [:axlsx], formats: [:xlsx], template: "exercises/exercise_lists.xlsx.axlsx", locals: {table_columns:@table_columns,exercise_users:@user_columns} + zip_file = Tempfile.new(["#{exercise_export_name}","xlsx"],"/home/tmp") + zip_file.write(ex_xlsx) + zip_file.close + # render json{:status => 0,"file_name":"#{exercise_export_name}"} + render :json => { status: 0, file_name: "#{exercise_export_name}",file_path: "#{zip_file.path}" } + # respond_to do |format| + # format.xlsx{ + # get_export_users(@exercise,@course,@export_ex_users) + # exercise_export_name_ = + # "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}" + # exercise_export_name = Base64.urlsafe_encode64(exercise_export_name_.strip.first(30)) + # + # render xlsx: "#{exercise_export_name}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} + # } + # end end end rescue Exception => e From 33cc969d880a4dd797136bb21b2ad37d501e5b77 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 6 Jul 2019 17:55:44 +0800 Subject: [PATCH 0673/1015] fixbug --- app/controllers/exercises_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 9de91ca0e..cc7756ca2 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1294,7 +1294,7 @@ class ExercisesController < ApplicationController get_export_users(@exercise,@course,@export_ex_users) exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}" ex_xlsx = render_to_string handlers: [:axlsx], formats: [:xlsx], template: "exercises/exercise_lists.xlsx.axlsx", locals: {table_columns:@table_columns,exercise_users:@user_columns} - zip_file = Tempfile.new(["#{exercise_export_name}","xlsx"],"/home/tmp") + zip_file = Tempfile.new(exercise_export_name,"/home/tmp") zip_file.write(ex_xlsx) zip_file.close # render json{:status => 0,"file_name":"#{exercise_export_name}"} From 148b73d4ff4379643de7eedc8e1c5153e4233afb Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Sat, 6 Jul 2019 18:20:10 +0800 Subject: [PATCH 0674/1015] fixbug --- app/controllers/courses_controller.rb | 3 +- app/controllers/exercises_controller.rb | 32 +++++++------------ .../graduation_tasks_controller.rb | 5 ++- .../graduation_topics_controller.rb | 3 +- .../homework_commons_controller.rb | 5 ++- app/controllers/polls_controller.rb | 6 ++-- app/controllers/zips_controller.rb | 8 ++--- .../batch_export_shixun_report_service.rb | 2 +- app/services/export_exercises_service.rb | 2 +- 9 files changed, 23 insertions(+), 43 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index cb2b8d201..fa1d06d77 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -994,8 +994,7 @@ class CoursesController < ApplicationController else member_to_xlsx(@course, @all_members, @c_homeworks, @c_exercises, @c_tasks) filename_ = "#{current_user.real_name}_#{@course.name}_全部成绩" - filename = Base64.urlsafe_encode64(filename_) - render xlsx: "#{format_sheet_name filename.strip.first(30)}",template: "courses/export_member_scores_excel.xlsx.axlsx", + render xlsx: "#{format_sheet_name filename_.strip.first(30)}",template: "courses/export_member_scores_excel.xlsx.axlsx", locals: {course_info:@course_info, activity_level:@user_activity_level, course_scores:@course_user_scores,shixun_works:@shixun_work_arrays, common_works:@common_work_arrays,group_works:@group_work_arrays,task_works:@task_work_arrays, diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index cc7756ca2..1a20e7406 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1291,24 +1291,15 @@ class ExercisesController < ApplicationController elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) normal_status(-1,"暂无用户提交") else - get_export_users(@exercise,@course,@export_ex_users) - exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}" - ex_xlsx = render_to_string handlers: [:axlsx], formats: [:xlsx], template: "exercises/exercise_lists.xlsx.axlsx", locals: {table_columns:@table_columns,exercise_users:@user_columns} - zip_file = Tempfile.new(exercise_export_name,"/home/tmp") - zip_file.write(ex_xlsx) - zip_file.close - # render json{:status => 0,"file_name":"#{exercise_export_name}"} - render :json => { status: 0, file_name: "#{exercise_export_name}",file_path: "#{zip_file.path}" } - # respond_to do |format| - # format.xlsx{ - # get_export_users(@exercise,@course,@export_ex_users) - # exercise_export_name_ = - # "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}" - # exercise_export_name = Base64.urlsafe_encode64(exercise_export_name_.strip.first(30)) - # - # render xlsx: "#{exercise_export_name}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} - # } - # end + respond_to do |format| + format.xlsx{ + get_export_users(@exercise,@course,@export_ex_users) + exercise_export_name_ = + "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + + render xlsx: "#{exercise_export_name_.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} + } + end end end rescue Exception => e @@ -1323,10 +1314,9 @@ class ExercisesController < ApplicationController def export_exercise @request_url = request.base_url @exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") - filename_ = "#{@exercise.user.real_name}_#{@exercise.exercise_name}" - filename = Base64.urlsafe_encode64(filename_.strip.first(30)) + filename_ = "#{@exercise.user.real_name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css" - render pdf: 'exercise_export/blank_exercise', filename: filename, stylesheets: stylesheets + render pdf: 'exercise_export/blank_exercise', filename: filename_.strip.first(30), stylesheets: stylesheets end #空白试卷预览页面,仅供测试使用,无其他任何用途 diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 41d8bd68d..c3b73ad20 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -134,9 +134,8 @@ class GraduationTasksController < ApplicationController respond_to do |format| format.xlsx{ graduation_work_to_xlsx(@work_excel,@task,current_user) - task_export_name_ = "#{current_user.real_name}_#{@course.name}_#{@task.name}" - task_export_name = Base64.urlsafe_encode64(task_export_name_.strip.first(30)) - render xlsx: "#{task_export_name}",template: "graduation_tasks/tasks_list.xlsx.axlsx",locals: {table_columns:@head_cells_column, task_users:@task_cells_column} + task_export_name_ = "#{current_user.real_name}_#{@course.name}_#{@task.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + render xlsx: "#{task_export_name_.strip.first(30)}",template: "graduation_tasks/tasks_list.xlsx.axlsx",locals: {table_columns:@head_cells_column, task_users:@task_cells_column} } end end diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index 75f7ddc6f..4ad07c77e 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -271,8 +271,7 @@ class GraduationTopicsController < ApplicationController students = course.students.joins(user: :user_extension).order("user_extensions.student_id") graduation_topic_to_xlsx(students,course) topic_export_name_ = "#{current_user.real_name}_#{course.name}_毕设选题_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - topic_export_name = Base64.urlsafe_encode64(topic_export_name_.strip.first(30)) - render xlsx: "#{topic_export_name}",template: "graduation_topics/export.xlsx.axlsx",locals: {table_columns:@topic_head_cells,topic_users:@topic_body_cells} + render xlsx: "#{topic_export_name_.strip.first(30)}",template: "graduation_topics/export.xlsx.axlsx",locals: {table_columns:@topic_head_cells,topic_users:@topic_body_cells} rescue Exception => e uid_logger(e.message) missing_template diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index cdbfac5bc..9a12634cf 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -206,9 +206,8 @@ class HomeworkCommonsController < ApplicationController respond_to do |format| format.xlsx{ student_work_to_xlsx(@work_excel,@homework) - exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@homework.name}" - file_name = Base64.urlsafe_encode64(exercise_export_name.strip.first(30)) - render xlsx: "#{file_name}",template: "homework_commons/works_list.xlsx.axlsx",locals: + exercise_export_name = "#{current_user.real_name}_#{@course.name}_#{@homework.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals: {table_columns: @work_head_cells,task_users: @work_cells_column} } end diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index fa8d7dd8c..47ad365f5 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -936,11 +936,9 @@ class PollsController < ApplicationController else respond_to do |format| format.xlsx{ - polls_export_name_ = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}" - polls_export_name = Base64.urlsafe_encode64(polls_export_name_.strip.first(30)) - + polls_export_name_ = "#{current_user.real_name}_#{@course.name}_#{@poll.polls_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" polls_user_commit = poll_commit_result(@poll,@poll_export_questions,@poll_users,@poll_commit_ids) - render xlsx: "#{polls_export_name}",template: "polls/commit_result.xlsx.axlsx",locals: {polls_user_commit:polls_user_commit} + render xlsx: "#{polls_export_name_.strip.first(30)}",template: "polls/commit_result.xlsx.axlsx",locals: {polls_user_commit:polls_user_commit} } end end diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index e8a2874dd..a4140fe34 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -6,12 +6,9 @@ class ZipsController < ApplicationController before_action :require_admin_or_teacher def shixun_report - service = BatchExportShixunReportService.new(@homework, @all_student_works) - filename_ = filename_for_content_disposition(service.filename) - filename = Base64.urlsafe_encode64(filename_) - send_file service.zip, filename: filename, type: 'application/zip' + send_file service.zip, filename: filename_, type: 'application/zip' rescue BatchExportShixunReportService::Error => ex normal_status(-1, ex.message) end @@ -21,8 +18,7 @@ class ZipsController < ApplicationController exercises = ExportExercisesService.new(@exercise,@ex_users,@request_url) file_name_ = filename_for_content_disposition(exercises.filename) - file_name = Base64.urlsafe_encode64(file_name_) - send_file exercises.ex_zip, filename: file_name, type: 'application/zip' + send_file exercises.ex_zip, filename: file_name_, type: 'application/zip' rescue Exception => e normal_status(-1, e.message) end diff --git a/app/services/batch_export_shixun_report_service.rb b/app/services/batch_export_shixun_report_service.rb index 01d94ffe5..d71235790 100644 --- a/app/services/batch_export_shixun_report_service.rb +++ b/app/services/batch_export_shixun_report_service.rb @@ -14,7 +14,7 @@ class BatchExportShixunReportService end def filename - @_filename ||= "#{homework.name}" + @_filename ||= "#{homework.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" end def zip diff --git a/app/services/export_exercises_service.rb b/app/services/export_exercises_service.rb index 1b284e598..ca2d347a6 100644 --- a/app/services/export_exercises_service.rb +++ b/app/services/export_exercises_service.rb @@ -10,7 +10,7 @@ class ExportExercisesService end def filename - exercise_export_name = "#{exercise.user.real_name}_#{exercise.exercise_name}" + exercise_export_name = "#{exercise.user.real_name}_#{exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" "#{exercise_export_name.strip}.zip" end From e946b06a9a840b5e65329f471660e1c1a376c099 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 8 Jul 2019 10:01:27 +0800 Subject: [PATCH 0675/1015] fixbug --- app/controllers/exercises_controller.rb | 19 ++++++------------- app/helpers/exercises_helper.rb | 1 - .../_user_exercise_info.json.jbuilder | 2 +- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 1a20e7406..93a243c2a 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -219,7 +219,6 @@ class ExercisesController < ApplicationController end end - rescue Exception => e uid_logger_error(e.message) tip_exception("没有权限") @@ -1206,8 +1205,6 @@ class ExercisesController < ApplicationController get_exercise_answers(@exercise_all_users) # 未答和已答的 @exercise_current_user_status = 2 #当前用户非课堂成员 @exercise_users_list = [] - # @exercise_unanswers = 0 - # @exercise_answers = 0 end end @@ -1296,7 +1293,6 @@ class ExercisesController < ApplicationController get_export_users(@exercise,@course,@export_ex_users) exercise_export_name_ = "#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" - render xlsx: "#{exercise_export_name_.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} } end @@ -1314,9 +1310,9 @@ class ExercisesController < ApplicationController def export_exercise @request_url = request.base_url @exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") - filename_ = "#{@exercise.user.real_name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}" + filename_ = "#{@exercise.user.real_name}_#{@course.name}__#{Time.now.strftime('%Y%m%d_%H%M%S')}" stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css" - render pdf: 'exercise_export/blank_exercise', filename: filename_.strip.first(30), stylesheets: stylesheets + render pdf: 'exercise_export/blank_exercise', filename: filename_, stylesheets: stylesheets end #空白试卷预览页面,仅供测试使用,无其他任何用途 @@ -1546,12 +1542,11 @@ class ExercisesController < ApplicationController if exercise.present? if exercise.unified_setting #统一设置只有两种情况,全部发布,全部截止 exercise_user_status = exercise.get_exercise_status(current_user) #当前用户的能看到的试卷 - if exercise_user_status == exercise_status || exercise_status == 3 #未发布的情况 + if (exercise_user_status == exercise_status) || exercise_status == 3 #未发布的情况 unpublish_group = unpublish_group + user_groups_id else unpublish_group = [] end - # unpublish_group = unpublish_group + user_groups_id else ex_all_group_settings = exercise.exercise_group_settings ex_group_settings = ex_all_group_settings.exercise_group_published.pluck(:course_group_id).uniq #问卷设置的班级 @@ -1579,13 +1574,13 @@ class ExercisesController < ApplicationController def set_exercise_status(publish_time,end_time) time_now_i = Time.now - if publish_time.present? && publish_time <= time_now_i && end_time > time_now_i + if publish_time.present? && (publish_time <= time_now_i) && (end_time > time_now_i) 2 elsif publish_time.nil? || (publish_time.present? && publish_time > time_now_i) 1 - elsif end_time.present? && end_time <= time_now_i + elsif end_time.present? && (end_time <= time_now_i) 3 - elsif end_time.present? && publish_time.present? && end_time < publish_time + elsif end_time.present? && publish_time.present? && (end_time < publish_time) normal_status(-1,"时间设置错误!") else 1 @@ -1752,6 +1747,4 @@ class ExercisesController < ApplicationController end end - - end diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 3bc342c06..796337c8e 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -257,7 +257,6 @@ module ExercisesHelper end def exercise_index_show(exercise,course,is_teacher_or,user) - # exercise_all_users = exercise.exercise_users # lock_icon 0出现锁,1不出现锁 ex_show_text = [] diff --git a/app/views/exercises/_user_exercise_info.json.jbuilder b/app/views/exercises/_user_exercise_info.json.jbuilder index cba07fb3f..9acb18326 100644 --- a/app/views/exercises/_user_exercise_info.json.jbuilder +++ b/app/views/exercises/_user_exercise_info.json.jbuilder @@ -36,7 +36,7 @@ elsif student_status == 1 json.question_status question_status end -exercise_status = exercise.get_exercise_status(ex_answerer.id) +exercise_status = exercise.get_exercise_status(ex_answerer) #当前为老师,或为学生,但在试卷截止后且答案选择公开的 if is_teacher_or == 1 || (exercise_status == 3 && exercise.answer_open) From 244f356fdef72cae7859b0385e3bd0e5cc17ccab Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 11:01:42 +0800 Subject: [PATCH 0676/1015] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E6=88=90=E7=BB=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 9a12634cf..97b9ecc44 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -250,7 +250,7 @@ class HomeworkCommonsController < ApplicationController student_works = @homework.student_works.where(user_id: user_ids) end - myshixuns = Myshixun.where(shixun_id: params[:shixun_id], user_id: user_ids). + myshixuns = Myshixun.where(shixun_id: @homework.homework_commons_shixun&.shixun_id, user_id: user_ids). includes(:games).where(games: {challenge_id: @homework.homework_challenge_settings.pluck(:challenge_id)}) challenge_settings = @homework.homework_challenge_settings myshixuns.find_each(batch_size: 100) do |myshixun| From 6f474391d323e11f939c28fdd6189dd1d34fca7c Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 8 Jul 2019 14:20:06 +0800 Subject: [PATCH 0677/1015] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 6 +++--- app/controllers/myshixuns_controller.rb | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 5f93bc36b..163ba1847 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -77,7 +77,7 @@ class GamesController < ApplicationController # 区分选择题和编程题,st:0编程题; if @st == 0 - has_answer = game_challenge.challenge_answers.size == 0 ? false : true + has_answer = game_challenge.challenge_answers.size != 0 game_challenge.answer = nil mirror_name = @shixun.mirror_name @@ -87,7 +87,7 @@ class GamesController < ApplicationController rescue uid_logger("实训平台繁忙,繁忙等级(81)") end - tpm_cases_modified = (game_challenge.modify_time != @game.modify_time ? true : false) # modify_time 决定TPM测试集是否有更新 + tpm_cases_modified = (game_challenge.modify_time != @game.modify_time) # modify_time 决定TPM测试集是否有更新 @task_result = {tpm_modified: tpm_modified, tpm_cases_modified: tpm_cases_modified, mirror_name: mirror_name, has_answer: has_answer} @@ -629,7 +629,7 @@ class GamesController < ApplicationController # user_answer虽然是传的数组,但是可能存在多选择提的情况. user_answer_tran = user_answer[index].size > 1 ? user_answer[index].split("").sort.join("") : user_answer[index] standard_answer_tran = choose.standard_answer.size > 1 ? choose.standard_answer.split("").sort.join("") : choose.standard_answer - correct = (user_answer_tran == standard_answer_tran) ? true : false + correct = (user_answer_tran == standard_answer_tran) if str.present? str += "," end diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index ffa2ccc3b..4a886dfc8 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -278,7 +278,6 @@ class MyshixunsController < ApplicationController end end - if game.status == 2 @resubmit = Time.now.to_i end From 15437ab72439eb709035c925f290139e275ab2d4 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 8 Jul 2019 14:31:02 +0800 Subject: [PATCH 0678/1015] =?UTF-8?q?run=5Fcode=5Fmessages=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E7=B4=A2=E5=BC=95=E6=8F=90=E9=AB=98=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190708062910_add_index_for_run_code_message.rb | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 db/migrate/20190708062910_add_index_for_run_code_message.rb diff --git a/db/migrate/20190708062910_add_index_for_run_code_message.rb b/db/migrate/20190708062910_add_index_for_run_code_message.rb new file mode 100644 index 000000000..4449d58a2 --- /dev/null +++ b/db/migrate/20190708062910_add_index_for_run_code_message.rb @@ -0,0 +1,5 @@ +class AddIndexForRunCodeMessage < ActiveRecord::Migration[5.2] + def change + add_index :run_code_messages, :game_id + end +end From 914c0e0ea17dc6e830f8613589b0130d65d44286 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 14:38:14 +0800 Subject: [PATCH 0679/1015] =?UTF-8?q?=E6=88=90=E7=BB=A9=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 6 +++--- app/controllers/myshixuns_controller.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 97b9ecc44..9048b0046 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -255,7 +255,7 @@ class HomeworkCommonsController < ApplicationController challenge_settings = @homework.homework_challenge_settings myshixuns.find_each(batch_size: 100) do |myshixun| work = student_works.select{|work| work.user_id == myshixun.user_id}.first - if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.games.pluck(:updated_at).max) + if work && myshixun games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id)) HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings end @@ -276,13 +276,13 @@ class HomeworkCommonsController < ApplicationController myshixun = Myshixun.find_by(shixun_id: params[:shixun_id], user_id: current_user.id) ActiveRecord::Base.transaction do begin - if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.games.pluck(:updated_at).max) + if work && myshixun challenge_settings = @homework.homework_challenge_settings games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id)) HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings normal_status("更新成功") else - normal_status("已是最新成绩") + normal_status("还开启挑战,暂不能更新成绩") end rescue Exception => e uid_logger(e.message) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index ffa2ccc3b..95fbf8200 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -33,7 +33,7 @@ class MyshixunsController < ApplicationController uid_logger_error("版本库删除异常,详情:#{e.message}") end - StudentWork.where(:myshixun_id => @myshixun.id).update_all(:myshixun_id => nil, :work_status => 0) + StudentWork.where(:myshixun_id => @myshixun.id).update_all(:myshixun_id => 0, :work_status => 0) rescue Exception => e uid_logger_error("myshixun reset failed #{e}") From 63c2dc69d2a9e512fda074617e91da82cad3016f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 8 Jul 2019 15:33:32 +0800 Subject: [PATCH 0680/1015] =?UTF-8?q?=E5=8F=82=E8=80=83=E7=AD=94=E6=A1=88?= =?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/controllers/games_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 163ba1847..e5106ff59 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -311,7 +311,7 @@ class GamesController < ApplicationController # 扣除总分计算 @game.update_attributes!(:answer_open => 1, :answer_deduction => 100) end - @challenge_answers = @challenge.challenge_chooses + @challenge_chooses = @challenge.challenge_chooses rescue Exception => e uid_logger_error("#######金币扣除异常: #{e.message}") raise ActiveRecord::Rollback From 09801538560b2a88b91736b5745f17cb160499e3 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 8 Jul 2019 15:42:01 +0800 Subject: [PATCH 0681/1015] =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=A2=98=E7=AD=94?= =?UTF-8?q?=E6=A1=88=E6=9F=A5=E7=9C=8B=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index e5106ff59..6ffc7f0ce 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -903,7 +903,7 @@ class GamesController < ApplicationController end # actual_output为空表示暂时没有评测答题,不允许查看 actual_output = output.try(:actual_output).try(:strip) - has_answer << choose.answer if choose.answer.present? + #has_answer << choose.answer if choose.answer.present? # 标准答案处理,错误的不让用户查看,用-1替代 standard_answer = (actual_output.blank? || !output.try(:result)) ? -1 : choose.standard_answer result = output.try(:result) @@ -914,7 +914,7 @@ class GamesController < ApplicationController @chooses << sin_choose test_sets << sin_test_set end - @has_answer = has_answer.present? + @has_answer = true # 选择题永远都有答案 @choose_test_cases = {:had_submmit => had_submmit, :challenge_chooses_count => challenge_chooses_count, :choose_correct_num => choose_correct_num, :test_sets => test_sets} end From f96e8e70e3315f9f9e03573ae4d3e2290c356e31 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 16:24:12 +0800 Subject: [PATCH 0682/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=AD=94=E9=A2=98?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=9A=84=E5=88=86=E7=8F=AD=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/course.rb | 4 ++-- app/models/homework_common.rb | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/models/course.rb b/app/models/course.rb index f61ff1e2a..d36d5d2c5 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -308,12 +308,12 @@ class Course < ApplicationRecord teacher_power_courses = [] if course_groups.present? common_ids.each do |i| - student_count = students.where(course_group_id:i).count if i == 0 + student_count = students.where(course_group_id:i).count teacher_power_courses << {course_name:"未分班",course_id:0,student_count:student_count} else course_group_name = course_groups.find_by(id:i) - teacher_power_courses << {course_name:course_group_name&.name,course_id:i,student_count:student_count} + teacher_power_courses << {course_name:course_group_name&.name,course_id:i,student_count:course_group_name&.course_members_count} end end end diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 193d9aa6c..70755e508 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -79,7 +79,8 @@ class HomeworkCommon < ApplicationRecord # 根据是否统一发布获取作业的作品列表 def all_works student_works = self.unified_setting ? self.student_works : - self.student_works.joins("join course_members on student_works.user_id=course_members.user_id").where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)}) + self.student_works.joins("join course_members on student_works.user_id=course_members.user_id"). + where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)}) end # 分班权限的老师可见的作品列表 From e3d21286f363134b41aa6f0b9345d1b61a7704b4 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 16:37:32 +0800 Subject: [PATCH 0683/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/exercise.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 606132c27..290032f24 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -60,7 +60,8 @@ class Exercise < ApplicationRecord ex_users = exercise_users group_ids = common_published_ids(user_id) if group_ids.present? - ex_users = ex_users.where(user_id: course.students.where(course_group_id: group_ids).select(:user_id).pluck(:user_id)) + ex_users = ex_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). + where(course_members: {course_group_id: group_ids}) end ex_users end @@ -69,8 +70,9 @@ class Exercise < ApplicationRecord def common_published_ids(user_id) current_user_groups = course.teacher_course_ids(user_id) if unified_setting - un_group_ids = (course.none_group_count > 0) ? [0] : [] - published_group_ids = (current_user_groups + un_group_ids).uniq #统一设置时,为当前用户的分班id及未分班 + # un_group_ids = (course.none_group_count > 0) ? [0] : [] + # published_group_ids = (current_user_groups + un_group_ids).uniq #统一设置时,为当前用户的分班id及未分班 + published_group_ids = current_user_groups else ex_group_setting = exercise_group_settings.select(:course_group_id).pluck("course_group_id").uniq common_all_ids = ex_group_setting & current_user_groups #当前用户有权限的已发布的分班id #非统一设置时,为当前用户有权限的且已发布分班的id From 17b8f21a2ad2d1202b1e3422a730ff5ca00982ae Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 17:19:41 +0800 Subject: [PATCH 0684/1015] =?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/exercises_controller.rb | 8 ++--- app/helpers/exercises_helper.rb | 23 +++++++++------ app/models/exercise.rb | 39 ++++++++++++++++++++----- app/models/homework_common.rb | 2 +- 4 files changed, 50 insertions(+), 22 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 93a243c2a..9a7838a96 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -89,7 +89,7 @@ class ExercisesController < ApplicationController @page = params[:page] || 1 @limit = params[:limit] || 15 @exercises = @exercises.page(@page).per(@limit) - @exercises = @exercises&.includes(:exercise_users,:exercise_questions,:exercise_group_settings) + @exercises = @exercises&.includes(:published_settings) else @exercises = [] end @@ -1183,12 +1183,12 @@ class ExercisesController < ApplicationController ex_common_ids = @exercise.common_published_ids(current_user.id) @exercise_course_groups = @course.get_ex_published_course(ex_common_ids) @exercise_users_list = @exercise.all_exercise_users(current_user.id) #当前老师所在班级的全部学生 - get_exercise_answers(@exercise_users_list) + get_exercise_answers(@exercise_users_list, @exercise_status) end elsif @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生或者有过答题的(提交/未提交) @ex_user_end_time = @exercise.get_exercise_end_time(current_user.id) #当前用户所看到的剩余时间 @exercise_all_users = @exercise.get_stu_exercise_users - get_exercise_answers(@exercise_all_users) # 未答和已答的 + get_exercise_answers(@exercise_users_list, @exercise_status) # 未答和已答的 exercise_current_user = @exercise_all_users.exercise_commit_users(current_user.id) #当前用户是否开始做试卷(提交/未提交/没做) if exercise_current_user.present? @exercise_current_user_status = 1 #当前用户的状态,为学生 @@ -1202,7 +1202,7 @@ class ExercisesController < ApplicationController end else @exercise_all_users = @exercise.get_stu_exercise_users - get_exercise_answers(@exercise_all_users) # 未答和已答的 + get_exercise_answers(@exercise_users_list, @exercise_status) # 未答和已答的 @exercise_current_user_status = 2 #当前用户非课堂成员 @exercise_users_list = [] end diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 796337c8e..655620db7 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -250,10 +250,15 @@ module ExercisesHelper end #获取试卷的已答/未答人数 - def get_exercise_answers(ex_users) - @exercise_answers = ex_users.commit_exercise_by_status(1).size #表示已经提交了的用户 - course_all_members_count = ex_users.size - @exercise_unanswers = (course_all_members_count - @exercise_answers) + def get_exercise_answers(ex_users, status) + if status == 1 + @exercise_answers = 0 + @exercise_unanswers = 0 + else + @exercise_answers = ex_users.commit_exercise_by_status(1).size #表示已经提交了的用户 + course_all_members_count = ex_users.size + @exercise_unanswers = (course_all_members_count - @exercise_answers) + end end def exercise_index_show(exercise,course,is_teacher_or,user) @@ -281,8 +286,8 @@ module ExercisesHelper if is_teacher_or == 1 exercise_users_list = exercise.all_exercise_users(user.id) #当前老师所在班级的全部学生 - unreview_count = exercise_users_list.exercise_unreview.size - get_exercise_answers(exercise_users_list) + unreview_count = exercise_status == 1 ? 0 : exercise_users_list.exercise_unreview.size + get_exercise_answers(exercise_users_list, exercise_status) ex_pb_time = exercise.get_exercise_times(user.id,true) exercise_publish_time = ex_pb_time[:publish_time] exercise_end_time = ex_pb_time[:end_time] @@ -295,8 +300,8 @@ module ExercisesHelper end elsif is_teacher_or == 2 exercise_users_list = exercise.get_stu_exercise_users - get_exercise_answers(exercise_users_list) # 未答和已答的 - unreview_count = exercise_users_list.exercise_unreview.size + get_exercise_answers(exercise_users_list, exercise_status) # 未答和已答的 + unreview_count = exercise_status == 1 ? 0 : exercise_users_list.exercise_unreview.size ex_pb_time = exercise.get_exercise_times(user.id,false) exercise_publish_time = ex_pb_time[:publish_time] exercise_end_time = ex_pb_time[:end_time] @@ -307,7 +312,7 @@ module ExercisesHelper end else exercise_users_list = exercise.get_stu_exercise_users - get_exercise_answers(exercise_users_list) # 未答和已答的 + get_exercise_answers(exercise_users_list, exercise_status) # 未答和已答的 exercise_publish_time = exercise.publish_time exercise_end_time = exercise.end_time unreview_count = nil diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 290032f24..8c1ad34d4 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -7,6 +7,8 @@ class Exercise < ApplicationRecord has_many :score_exercise_users, -> { where("is_delete = 0 and commit_status != 0").order("score desc") }, class_name: "ExerciseUser" has_many :exercise_questions, :dependent => :delete_all has_many :exercise_group_settings, :dependent => :delete_all + has_many :published_settings, -> { exercise_group_published }, class_name: "ExerciseGroupSetting" + has_many :tidings, as: :container has_many :course_acts, class_name: 'CourseActivity', as: :course_act, :dependent => :delete_all @@ -41,8 +43,8 @@ class Exercise < ApplicationRecord exercise_users else ex_group_setting_ids = exercise_group_settings.exercise_group_published.pluck(:course_group_id) - course_user_ids = course.students.where(course_group_id:ex_group_setting_ids).pluck(:user_id) - exercise_users.where(user_id:course_user_ids) + exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). + where(course_members: {course_group_id: ex_group_setting_ids}) end end @@ -55,17 +57,38 @@ class Exercise < ApplicationRecord end end - #统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生 - def all_exercise_users(user_id) - ex_users = exercise_users - group_ids = common_published_ids(user_id) - if group_ids.present? - ex_users = ex_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). + # 根据是否统一发布获取作业的作品列表 + def all_works + exercise_users = self.unified_setting ? self.exercise_users : + self.exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). + where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)}) + end + + # 分班权限的老师可见的作品列表 + def all_exercise_users user_id + # member = course.course_member(user_id) + teacher_course_groups = course.teacher_course_groups.where(user_id: user_id) + ex_users = self.all_works + # 有分班权限的统计管理的分班且已发布的学生情况 + if teacher_course_groups.exists? + group_ids = teacher_course_groups.pluck(:course_group_id) + ex_users = all_student_works.joins("join course_members on student_works.user_id=course_members.user_id"). where(course_members: {course_group_id: group_ids}) end ex_users end + # #统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生 + # def all_exercise_users(user_id) + # ex_users = exercise_users + # group_ids = common_published_ids(user_id) + # if group_ids.present? + # ex_users = ex_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). + # where(course_members: {course_group_id: group_ids}) + # end + # ex_users + # end + #当前用户已发布的班级id和试卷分组已发布的班级id的交集 def common_published_ids(user_id) current_user_groups = course.teacher_course_ids(user_id) diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 70755e508..80b92d175 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -89,7 +89,7 @@ class HomeworkCommon < ApplicationRecord teacher_course_groups = member.try(:teacher_course_groups) all_student_works = self.all_works # 有分班权限的统计管理的分班且已发布的学生情况 - if member.present? && teacher_course_groups.size > 0 + if member.present? && teacher_course_groups.exists? group_ids = teacher_course_groups.pluck(:course_group_id) all_student_works = all_student_works.joins("join course_members on student_works.user_id=course_members.user_id"). where(course_members: {course_group_id: group_ids}) From e4624252c8c66f5c3e70f65a461ba7126eb52a0b Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 17:21:30 +0800 Subject: [PATCH 0685/1015] =?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/models/exercise.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 8c1ad34d4..85419ff3d 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -72,7 +72,7 @@ class Exercise < ApplicationRecord # 有分班权限的统计管理的分班且已发布的学生情况 if teacher_course_groups.exists? group_ids = teacher_course_groups.pluck(:course_group_id) - ex_users = all_student_works.joins("join course_members on student_works.user_id=course_members.user_id"). + ex_users = ex_users.joins("join course_members on student_works.user_id=course_members.user_id"). where(course_members: {course_group_id: group_ids}) end ex_users From 4fe212c05d2895ad90e228c8204947b26a204d75 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 17:22:31 +0800 Subject: [PATCH 0686/1015] =?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/models/exercise.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 85419ff3d..e3a89a19a 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -72,7 +72,7 @@ class Exercise < ApplicationRecord # 有分班权限的统计管理的分班且已发布的学生情况 if teacher_course_groups.exists? group_ids = teacher_course_groups.pluck(:course_group_id) - ex_users = ex_users.joins("join course_members on student_works.user_id=course_members.user_id"). + ex_users = ex_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). where(course_members: {course_group_id: group_ids}) end ex_users From b241fb4dbe85f82517a3ce0abdd51ae1b0e4bdd4 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 8 Jul 2019 17:24:50 +0800 Subject: [PATCH 0687/1015] fixbug --- app/models/exercise.rb | 1 - app/models/poll.rb | 19 ++++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 606132c27..2a6a8f84b 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -79,7 +79,6 @@ class Exercise < ApplicationRecord published_group_ids end - #判断用户是否属于试卷分班的学生中 def check_user_in_course(user_id,user_identity) ex_group_settings = exercise_group_settings.pluck(:course_group_id) diff --git a/app/models/poll.rb b/app/models/poll.rb index a055fd656..69b717493 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -44,8 +44,8 @@ class Poll < ApplicationRecord if unified_setting #试卷统一设置 poll_users else - ex_group_setting_ids = poll_group_settings.poll_group_published.pluck(:course_group_id) - poll_users.where(user_id: course.students.where(course_group_id:ex_group_setting_ids).pluck(:user_id).uniq) + ex_group_setting_ids = poll_group_settings.poll_group_published.select(:course_group_id).pluck(:course_group_id) + poll_users.where(user_id: course.students.where(course_group_id:ex_group_setting_ids).select(:user_id).pluck(:user_id).uniq) end end @@ -63,15 +63,16 @@ class Poll < ApplicationRecord def poll_published_ids(user_id) current_user_groups = course.teacher_course_ids(user_id) if unified_setting - if course.none_group_count > 0 #有未分班的,则发布到未发布 - un_group_ids = [0] - else - un_group_ids = [] - end - (current_user_groups + un_group_ids).uniq #统一设置时,为当前用户的分班id + current_user_groups.uniq + # if course.none_group_count > 0 #有未分班的,则发布到未发布 + # un_group_ids = [0] + # else + # un_group_ids = [] + # end + # (current_user_groups + un_group_ids).uniq #统一设置时,为当前用户的分班id else ex_group_setting = poll_group_settings.select(:course_group_id).pluck("course_group_id").uniq - ex_group_setting & current_user_groups #当前用户有权限的已发布的分班id #非统一设置时,为当前用户有权限的且已发布分班的id + (ex_group_setting & current_user_groups).uniq #当前用户有权限的已发布的分班id #非统一设置时,为当前用户有权限的且已发布分班的id end end From 705363130d913e9c56ef7b411e9b4d3202931356 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 8 Jul 2019 17:26:24 +0800 Subject: [PATCH 0688/1015] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=BA=E9=99=B7'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/game.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/game.rb b/app/models/game.rb index ba6664d5c..eed425ea6 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -20,9 +20,9 @@ class Game < ApplicationRecord #全部关卡数 scope :ch_games, lambda { |challenge_id| where(challenge_id:challenge_id) } # 已通关的数量 - scope :finished_num, -> (challenge_id) { where(:challenge_id => challenge_id, :status => 1)} + scope :finished_num, -> (challenge_id) { where(:challenge_id => challenge_id, :status => 2)} # 正在通关的数量 - scope :doing_num, -> (challenge_id) { where(:challenge_id => challenge_id, :status => 0)} + scope :doing_num, -> (challenge_id) { where(:challenge_id => challenge_id, :status => [0,1])} #用户的全部关卡 scope :user_games, lambda { |user_id,challenge_id| where("user_id = ? AND challenge_id = ?",user_id,challenge_id) } From d9e274b2988caa26d39534595f0a0f1a4154a1e2 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 17:48:23 +0800 Subject: [PATCH 0689/1015] =?UTF-8?q?=E9=97=AE=E5=8D=B7=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/polls_controller.rb | 8 +++--- app/helpers/polls_helper.rb | 19 ++++++++----- app/models/exercise.rb | 10 +++---- app/models/poll.rb | 41 ++++++++++++++++++++++------- 4 files changed, 53 insertions(+), 25 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 47ad365f5..e2d0ce3cd 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -88,7 +88,7 @@ class PollsController < ApplicationController @limit = params[:limit] || 15 @polls = @polls.page(@page).per(@limit) - @polls = @polls&.includes(:poll_users,:poll_questions,:poll_group_settings) + @polls = @polls&.includes(:published_settings) else @polls = [] end @@ -965,7 +965,7 @@ class PollsController < ApplicationController if @user_course_identity < Course::STUDENT #当前为老师,而且老师只能查看自己班级的/课堂的问卷 @poll_current_user_status = 0 @poll_users_list = @poll.all_poll_users(current_user.id) #该老师分班的全部学生 - get_poll_answers(@poll_users_list) + get_poll_answers(@poll_users_list, @poll_list_status) if @poll_list_status == 1 @poll_course_groups =[] else @@ -977,7 +977,7 @@ class PollsController < ApplicationController end elsif @user_course_identity > Course::ASSISTANT_PROFESSOR @poll_all_users = @poll.get_poll_exercise_users - get_poll_answers(@poll_all_users) # 未答和已答的 + get_poll_answers(@poll_all_users, @poll_list_status) # 未答和已答的 @poll_course_groups = [] #当为学生的时候,不显示分班情况 @poll_current_user_status = 1 #当前用户的状态,为学生 poll_current_user = @poll_all_users.find_by_group_ids(current_user.id) #当前用户是否开始做问卷(提交/未提交/没做) @@ -988,7 +988,7 @@ class PollsController < ApplicationController end else @poll_all_users = @poll.get_poll_exercise_users - get_poll_answers(@poll_all_users) # 未答和已答的 + get_poll_answers(@poll_all_users, @poll_list_status) # 未答和已答的 @poll_current_user_status = 2 #当前用户非课堂成员 @poll_users_list = [] end diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index 54a9fe1f0..f6dc3fc89 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -1,10 +1,15 @@ module PollsHelper #获取试卷的已答/未答人数 - def get_poll_answers(poll_users) - @poll_answers = poll_users.commit_by_status(1).size #表示已经提交了的用户 - course_all_members_count = poll_users.size - @poll_unanswers = (course_all_members_count - @poll_answers) + def get_poll_answers(poll_users, status) + if status == 1 + @poll_answers = poll_users.commit_by_status(1).size #表示已经提交了的用户 + course_all_members_count = poll_users.size + @poll_unanswers = (course_all_members_count - @poll_answers) + else + @poll_answers = 0 + @poll_unanswers = 0 + end end def poll_votes_count(votes,user_ids) @@ -59,7 +64,7 @@ module PollsHelper if is_teacher_or == 1 poll_users_list = poll.all_poll_users(user.id) #当前老师所在班级的全部学生 - get_poll_answers(poll_users_list) + get_poll_answers(poll_users_list, poll_status) ex_pb_time = poll.get_poll_times(user.id,true) poll_publish_time = ex_pb_time[:publish_time] poll_end_time = ex_pb_time[:end_time] @@ -67,7 +72,7 @@ module PollsHelper lock_icon = 0 #不显示锁图标 elsif is_teacher_or == 2 poll_users_list = poll.get_poll_exercise_users - get_poll_answers(poll_users_list) # 未答和已答的 + get_poll_answers(poll_users_list, poll_status) # 未答和已答的 # get_poll_answers(poll_all_users) ex_pb_time = poll.get_poll_times(user.id,false) poll_publish_time = ex_pb_time[:publish_time] @@ -76,7 +81,7 @@ module PollsHelper lock_icon = 0 #不显示锁图标 else poll_users_list = poll.get_poll_exercise_users - get_poll_answers(poll_users_list) # 未答和已答的 + get_poll_answers(poll_users_list, poll_status) # 未答和已答的 poll_publish_time = poll.publish_time poll_end_time = poll.end_time current_status = 4 diff --git a/app/models/exercise.rb b/app/models/exercise.rb index e3a89a19a..cc7c99f1b 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -42,7 +42,7 @@ class Exercise < ApplicationRecord if unified_setting #试卷统一设置 exercise_users else - ex_group_setting_ids = exercise_group_settings.exercise_group_published.pluck(:course_group_id) + ex_group_setting_ids = published_settings.pluck(:course_group_id) exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). where(course_members: {course_group_id: ex_group_setting_ids}) end @@ -59,15 +59,15 @@ class Exercise < ApplicationRecord # 根据是否统一发布获取作业的作品列表 def all_works - exercise_users = self.unified_setting ? self.exercise_users : - self.exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). - where(course_members: {course_group_id: self.published_settings.pluck(:course_group_id)}) + exercise_users = unified_setting ? exercise_users : + exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). + where(course_members: {course_group_id: published_settings.pluck(:course_group_id)}) end # 分班权限的老师可见的作品列表 def all_exercise_users user_id # member = course.course_member(user_id) - teacher_course_groups = course.teacher_course_groups.where(user_id: user_id) + teacher_course_groups = course.teacher_course_groups.get_user_groups ex_users = self.all_works # 有分班权限的统计管理的分班且已发布的学生情况 if teacher_course_groups.exists? diff --git a/app/models/poll.rb b/app/models/poll.rb index a055fd656..3edc3c661 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -8,6 +8,7 @@ class Poll < ApplicationRecord has_many :poll_users, -> { where("is_delete != 1") }, :dependent => :delete_all has_many :users, :through => :poll_users #该文件被哪些用户提交答案过 has_many :poll_group_settings, :dependent => :delete_all + has_many :published_settings, -> { poll_group_published }, class_name: "PollGroupSetting" has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :delete_all has_many :tidings, as: :container, dependent: :delete_all @@ -44,21 +45,43 @@ class Poll < ApplicationRecord if unified_setting #试卷统一设置 poll_users else - ex_group_setting_ids = poll_group_settings.poll_group_published.pluck(:course_group_id) - poll_users.where(user_id: course.students.where(course_group_id:ex_group_setting_ids).pluck(:user_id).uniq) + ex_group_setting_ids = published_settings.pluck(:course_group_id) + poll_users.joins("join course_members on poll_users.user_id=course_members.user_id"). + where(course_members: {course_group_id: ex_group_setting_ids}) end end - # 统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生 - def all_poll_users(user_id) - poll_all_users = poll_users - group_ids = poll_published_ids(user_id) - if group_ids.present? - poll_all_users = poll_all_users.where(user_id: course.students.where(course_group_id: group_ids).select(:user_id).pluck(:user_id).uniq) + # 根据是否统一发布获取作业的作品列表 + def all_works + poll_users = unified_setting ? poll_users : + poll_users.joins("join course_members on poll_users.user_id=course_members.user_id"). + where(course_members: {course_group_id: published_settings.pluck(:course_group_id)}) + end + + # 分班权限的老师可见的作品列表 + def all_poll_users user_id + # member = course.course_member(user_id) + teacher_course_groups = course.teacher_course_groups.get_user_groups + poll_users = self.all_works + # 有分班权限的统计管理的分班且已发布的学生情况 + if teacher_course_groups.exists? + group_ids = teacher_course_groups.pluck(:course_group_id) + poll_users = poll_users.joins("join course_members on poll_users.user_id=course_members.user_id"). + where(course_members: {course_group_id: group_ids}) end - poll_all_users + poll_users end + # # 统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生 + # def all_poll_users(user_id) + # poll_all_users = poll_users + # group_ids = poll_published_ids(user_id) + # if group_ids.present? + # poll_all_users = poll_all_users.where(user_id: course.students.where(course_group_id: group_ids).select(:user_id).pluck(:user_id).uniq) + # end + # poll_all_users + # end + #当前用户已发布的班级id和试卷分组已发布的班级id的交集 def poll_published_ids(user_id) current_user_groups = course.teacher_course_ids(user_id) From fc37a72d11d70e87be4ae7d7eec97fd61b883bdb Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 17:49:43 +0800 Subject: [PATCH 0690/1015] =?UTF-8?q?=E9=97=AE=E5=8D=B7=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/exercise.rb | 2 +- app/models/poll.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index cc7c99f1b..0b4aca8eb 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -67,7 +67,7 @@ class Exercise < ApplicationRecord # 分班权限的老师可见的作品列表 def all_exercise_users user_id # member = course.course_member(user_id) - teacher_course_groups = course.teacher_course_groups.get_user_groups + teacher_course_groups = course.teacher_course_groups.get_user_groups(user_id) ex_users = self.all_works # 有分班权限的统计管理的分班且已发布的学生情况 if teacher_course_groups.exists? diff --git a/app/models/poll.rb b/app/models/poll.rb index 3edc3c661..d37ea8458 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -61,7 +61,7 @@ class Poll < ApplicationRecord # 分班权限的老师可见的作品列表 def all_poll_users user_id # member = course.course_member(user_id) - teacher_course_groups = course.teacher_course_groups.get_user_groups + teacher_course_groups = course.teacher_course_groups.get_user_groups(user_id) poll_users = self.all_works # 有分班权限的统计管理的分班且已发布的学生情况 if teacher_course_groups.exists? From a025e17daa685599f3f5982101bbdd0cb564753b Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 17:57:44 +0800 Subject: [PATCH 0691/1015] =?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/models/exercise.rb | 2 +- app/models/poll.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 0b4aca8eb..f9efabbd8 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -59,7 +59,7 @@ class Exercise < ApplicationRecord # 根据是否统一发布获取作业的作品列表 def all_works - exercise_users = unified_setting ? exercise_users : + ex_users = unified_setting ? exercise_users : exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). where(course_members: {course_group_id: published_settings.pluck(:course_group_id)}) end diff --git a/app/models/poll.rb b/app/models/poll.rb index d37ea8458..381a7f359 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -53,7 +53,7 @@ class Poll < ApplicationRecord # 根据是否统一发布获取作业的作品列表 def all_works - poll_users = unified_setting ? poll_users : + po_users = unified_setting ? poll_users : poll_users.joins("join course_members on poll_users.user_id=course_members.user_id"). where(course_members: {course_group_id: published_settings.pluck(:course_group_id)}) end From 74a5c849b0e4aeea3754c1df1585794d647c1deb Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 8 Jul 2019 18:00:16 +0800 Subject: [PATCH 0692/1015] =?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/helpers/polls_helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index f6dc3fc89..52e90f559 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -3,12 +3,12 @@ module PollsHelper #获取试卷的已答/未答人数 def get_poll_answers(poll_users, status) if status == 1 + @poll_answers = 0 + @poll_unanswers = 0 + else @poll_answers = poll_users.commit_by_status(1).size #表示已经提交了的用户 course_all_members_count = poll_users.size @poll_unanswers = (course_all_members_count - @poll_answers) - else - @poll_answers = 0 - @poll_unanswers = 0 end end From f6eadf1279fa963d2513fb343ffbcd7d3d14cda8 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 9 Jul 2019 10:29:05 +0800 Subject: [PATCH 0693/1015] =?UTF-8?q?=E6=95=99=E5=B8=88=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 50 +++++++++++++------ .../courses/apply_teachers.json.jbuilder | 13 +++++ app/views/courses/teachers.json.jbuilder | 13 +---- 3 files changed, 49 insertions(+), 27 deletions(-) create mode 100644 app/views/courses/apply_teachers.json.jbuilder diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index fa1d06d77..159650c38 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -13,7 +13,7 @@ class CoursesController < ApplicationController before_action :require_login, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups, :left_banner, :top_banner] before_action :set_course, :user_course_identity, only: [:show, :update, :destroy, :settings, :set_invite_code_halt, - :set_public_or_private, :search_teacher_candidate, :teachers, + :set_public_or_private, :search_teacher_candidate, :teachers, :apply_teachers, :top_banner, :left_banner, :add_teacher_popup, :add_teacher, :graduation_group_list, :create_graduation_group, :join_graduation_group, :course_group_list, :set_course_group, :change_course_admin, :change_course_teacher, @@ -26,10 +26,10 @@ class CoursesController < ApplicationController :transfer_to_course_group, :delete_from_course, :search_users, :add_students_by_search, :get_historical_courses, :add_teacher_popup, :add_teacher] before_action :admin_allowed, only: [:set_invite_code_halt, :set_public_or_private, :change_course_admin, - :set_course_group, :delete_course_teacher, :teacher_application_review, - :create_group_by_importing_file] + :set_course_group, :delete_course_teacher, :create_group_by_importing_file] before_action :teacher_or_admin_allowed, only: [:graduation_group_list, :create_graduation_group, :join_graduation_group, - :change_course_teacher, :export_member_scores_excel, :course_group_list] + :change_course_teacher, :export_member_scores_excel, :course_group_list, + :teacher_application_review, :apply_teachers] before_action :validate_course_name, only: [:create, :update] before_action :find_board, only: :board_list before_action :validate_page_size, only: :mine @@ -251,46 +251,52 @@ class CoursesController < ApplicationController if @course.try(:id) != 1309 || current_user.admin? || current_user.try(:id) == 15582 @teacher_list = @course.course_members.joins(:user).where("course_members.role in (1, 2, 3) - and LOWER(concat(users.lastname, users.firstname)) LIKE '%#{@search_str}%'") + and LOWER(concat(users.lastname, users.firstname)) LIKE ?", "%#{@search_str}%") else @teacher_list = @course.course_members.joins(:user).where("(course_members.role in (1, 3) or (course_members.user_id = #{current_user.id} and course_members.role = 2)) and LOWER(concat(users.lastname, users.firstname)) - LIKE '%#{@search_str}%'") + LIKE ?", "%#{@search_str}%") end @teacher_list_size = @teacher_list.size @has_graduation_design = @course.course_modules.graduation_module_not_hidden.any? + sort = params[:sort] || "desc" @order = params[:order].to_i if @order.present? case @order when 1 - @teacher_list = @teacher_list.includes(:user).order("CONVERT(CONCAT(users.lastname, users.firstname) USING gbk) COLLATE gbk_chinese_ci asc") + @teacher_list = @teacher_list.order("role #{sort}") when 2 - @teacher_list = @teacher_list.order("created_at") + @teacher_list = @teacher_list.includes(:user).order("CONVERT(CONCAT(users.lastname, users.firstname) USING gbk) COLLATE gbk_chinese_ci #{sort}") when 3 - @teacher_list = @teacher_list.includes(:course, :graduation_group).order("graduation_groups.name") + @teacher_list = @teacher_list.includes(:course, :graduation_group).order("graduation_groups.name #{sort}") else - @teacher_list = @teacher_list.order("created_at") + @teacher_list = @teacher_list.order("role #{sort}") end else - if @has_graduation_design - @teacher_list = @teacher_list.includes(:course, :graduation_group).order("graduation_groups.name") - else - @teacher_list = @teacher_list.order("created_at") - end + @teacher_list = @teacher_list.order("role #{sort}") end @is_admin = @user_course_identity < Course::PROFESSOR - @applications = @is_admin ? CourseMessage.unhandled_join_course_requests_by_course(@course) : CourseMessage.none + @applications_size = CourseMessage.unhandled_join_course_requests_by_course(@course).size page = params[:page] || 1 limit = params[:limit] || 20 @teacher_list = @teacher_list.page(page).per(limit) end + def apply_teachers + search_str = params[:search].present? ? params[:search].strip : "" + @applications = CourseMessage.unhandled_join_course_requests_by_course(@course).joins(:user). + where("LOWER(concat(users.lastname, users.firstname)) LIKE ?", "%#{search_str}%") + @teacher_list_size = @course.teachers.size + @applications_size = CourseMessage.unhandled_join_course_requests_by_course(@course).size + @is_admin = @user_course_identity < Course::PROFESSOR + end + # 打开添加教师或助教弹窗时访问的接口(需要返回该课堂所有答辩组和所有) def add_teacher_popup @graduation_groups = @course.graduation_groups @@ -577,6 +583,18 @@ class CoursesController < ApplicationController end new_teacher.save! + + # 课堂管理员才有分配权限,且课堂分班数大于0 + if @user_course_identity < Course::PROFESSOR && @course.course_groups_count > 0 && params[:group_id] && params[:group_id].size > 0 + # 分班全选则是不限,不需要做处理 + unless @course.course_groups.where(id: params[:group_id]).size == @course.course_groups_count + @course.course_groups.where(id: params[:group_id]).each do |group| + unless TeacherCourseGroup.where(course_id: @course.id, user_id: applier_user.id, course_group_id: group.id, course_member_id: new_teacher.id).exists? + TeacherCourseGroup.create(course_id: @course.id, user_id: applier_user.id, course_member_id: new_teacher.id, course_group_id: group.id) + end + end + end + end elsif approval == 2 course_message.reject! else diff --git a/app/views/courses/apply_teachers.json.jbuilder b/app/views/courses/apply_teachers.json.jbuilder new file mode 100644 index 000000000..aee0803b4 --- /dev/null +++ b/app/views/courses/apply_teachers.json.jbuilder @@ -0,0 +1,13 @@ +json.teacher_list_size @teacher_list_size +json.apply_size @applications_size +json.is_admin @is_admin +json.application_list do + json.array! @applications do |application| + json.application_id application.id + json.user_id application.course_message_id + json.name application.application_user.real_name + json.name_link user_path(application.application_user) + json.login application.application_user.login + json.role application.content.to_i == 3 || application.content.to_i == 7 ? "助教" : application.content.to_i == 2 || application.content.to_i == 9 ? "教师" : "" + end +end \ No newline at end of file diff --git a/app/views/courses/teachers.json.jbuilder b/app/views/courses/teachers.json.jbuilder index 1be1ce16c..6a8505964 100644 --- a/app/views/courses/teachers.json.jbuilder +++ b/app/views/courses/teachers.json.jbuilder @@ -17,14 +17,5 @@ json.teacher_list do end end json.teacher_list_size @teacher_list_size -json.application_list do - json.array! @applications do |application| - json.application_id application.id - json.user_id application.course_message_id - json.name application.application_user.real_name - json.name_link user_path(application.application_user) - json.login application.application_user.login - json.role application.content.to_i == 3 || application.content.to_i == 7 ? "助教" : application.content.to_i == 2 || application.content.to_i == 9 ? "教师" : "" - end -end -json.is_admin @is_admin +json.apply_size @applications_size +json.is_admin @is_admin \ No newline at end of file From e173cae3903bee6e537ab7d2d86e3dd7eb6aad38 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 9 Jul 2019 11:02:57 +0800 Subject: [PATCH 0694/1015] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9F=A5=E9=87=8D?= =?UTF-8?q?=E6=A3=80=E7=B4=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 2 +- app/helpers/exercises_helper.rb | 18 +++--------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 9048b0046..232250e4c 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -1321,7 +1321,7 @@ class HomeworkCommonsController < ApplicationController .where(:user_id => user_ids).joins(user: :user_extension) # 按学号和姓名搜索 if params[:search] - @users_reviews = @users_reviews.where("concat(lastname, firstname) like ? or student_id like ?", params[:search], params[:search]) + @users_reviews = @users_reviews.where("concat(lastname, firstname) like :keyword or student_id like :keyword", keyword: "%#{params[:search]}%") end # 抄袭作品数 @copy_reviews_count = @users_reviews.count diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 655620db7..0b64cb916 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -89,11 +89,7 @@ module ExercisesHelper if ex.question_type <= 2 #单选题 standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id) #标准答案的位置 ex.exercise_choices.each do |c| - if standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 - right_answer = true - else - right_answer = false - end + right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id) answer_users_count = answer_this_choice.count if effictive_users_count == 0 @@ -176,11 +172,7 @@ module ExercisesHelper # zero_scores = all_zero_scores - un_review_scores #已评阅,且答案未0分的人数 main_scores_array = [full_scores,no_full_scores,zero_scores,un_review_scores] main_scores_array.each_with_index do |s,index| - if index == 0 - right_answer = true - else - right_answer = false - end + right_answer = (index == 0) if effictive_users_count == 0 || s < 0 s = 0 score_percent = 0.0 @@ -207,11 +199,7 @@ module ExercisesHelper shixun_score_array = [full_scores,no_full_scores,all_zero_scores] shixun_chas = [] shixun_score_array.each_with_index do |s,index| - if index == 0 - right_answer = true - else - right_answer = false - end + right_answer = (index == 0) if effictive_users_count == 0 score_percent = 0.0 else From 69c8b92dd1dbb75a4ab93d5f8aae7c018f02415b Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 9 Jul 2019 11:36:45 +0800 Subject: [PATCH 0695/1015] =?UTF-8?q?=E9=80=89=E7=94=A8=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 76 ++++++++++++++----- 1 file changed, 55 insertions(+), 21 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index cdbfac5bc..a04e00865 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -822,38 +822,72 @@ class HomeworkCommonsController < ApplicationController # 选用实训 def shixuns - search = params[:search] - type = params[:type] - # 超级管理员用户显示所有未隐藏的实训、非管理员显示所有已发布的实训(对本单位公开且未隐藏未关闭) - if current_user.admin? - @shixuns = Shixun.unhidden - else - none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id) + @main_catrgory = @course.course_modules.where(module_type: "shixun_homework") + @homework_category = @main_catrgory.take.course_second_categories + + ## 我的实训 + @shixuns = + if params[:order_by] == 'mine' + current_user.my_shixuns + else + Shixun.unhidden + end + + ## 方向 + if params[:tag_level].present? && params[:tag_id].present? + @shixuns = @shixuns.filter_tag(params[:tag_level].to_i, params[:tag_id].to_i) + case params[:tag_level].to_i + when 1 #大类 + @search_tags = Repertoire.find(params[:tag_id].to_i).name + when 2 #子类 + @search_tags = SubRepertoire.find(params[:tag_id].to_i).name + when 3 #tag + tag = TagRepertoire.find(params[:tag_id].to_i) + @search_tags = "#{tag.sub_repertoire.name} / #{tag.name}" + end + end - @shixuns = Shixun.where.not(id: none_shixun_ids).unhidden + ## 搜索关键字创建者、实训名称、院校名称 + if params[:keyword].present? + keyword = params[:keyword].strip + @shixuns = @shixuns.joins(user: [user_extenison: :school]). + where("schools.name like '%#{keyword}%' + or concat(lastname, firstname) like '%#{keyword}%' + or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct end - # 实训的所有标签 - @tags = TagRepertoire.select([:id, :name]).joins(:shixuns).where(shixuns: {id: @shixuns}).distinct + ## 筛选 状态 + if params[:status].present? && params[:status].to_i != 0 + params[:status] = [0, 1] if params[:status].to_i == 1 + @shixuns = @shixuns.where(status: params[:status]) + end - if params[:search] && params[:search].strip != "" - @shixuns = @shixuns.joins(:user).where("shixuns.name like ? or concat(users.lastname, users.firstname) like ?", - "%#{search}%", "%#{search}%").distinct + ## 筛选 难度 + if params[:diff].present? && params[:diff].to_i != 0 + @shixuns = @shixuns.where(trainee: params[:diff]) end - unless type.blank? || type == "all" - @shixuns = @shixuns.joins(:shixun_tag_repertoires).where(shixun_tag_repertoires: {tag_repertoire_id: type}).distinct + ## 排序参数 + bsort = params[:sort] || 'desc' + case params[:order_by] || 'myshixuns_count' + when 'new' + @shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.created_at #{bsort}") + when 'hot' + @shixuns = @shixuns.order("shixuns.status = 2 desc, myshixuns_count #{bsort}") + when 'mine' + @shixuns = @shixuns.order("shixuns.created_at #{bsort}") + else + @shixuns = @shixuns.order("shixuns.status = 2 desc, myshixuns_count #{bsort}") end - @shixuns = @shixuns.select([:id, :name, :status, :myshixuns_count, :identifier]).reorder("shixuns.created_at desc") - @shixuns_count = @shixuns.size + + @total_count = @shixuns.count ## 分页参数 - page = params[:page] || 1 - @shixuns = @shixuns.page(page).per(10) + page = params[:page] || 1 + limit = params[:limit] || 15 - @main_catrgory = @course.course_modules.where(module_type: "shixun_homework") - @homework_category = @main_catrgory.take.course_second_categories + @shixuns = @shixuns.includes(:tag_repertoires, :challenges).page(page).per(limit) end def create_shixun_homework From 952221970b9663edddf1c65542fe945ca362587a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 9 Jul 2019 11:38:19 +0800 Subject: [PATCH 0696/1015] =?UTF-8?q?=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/routes.rb b/config/routes.rb index ee8b6a187..7e34363d1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -295,6 +295,7 @@ Rails.application.routes.draw do get 'course_group_list' get 'add_teacher_popup' get 'teachers' + get 'apply_teachers' get 'graduation_group_list' get 'top_banner' get 'left_banner' From ddc67bc14f08e21e53ac51310cb7cbcb0662179c Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 9 Jul 2019 14:03:38 +0800 Subject: [PATCH 0697/1015] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E4=BD=9C=E5=93=81?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=9A=84=E5=B7=B2=E8=AF=84=E6=95=B0=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/course.rb | 2 +- app/models/graduation_task.rb | 12 ++++++------ app/models/homework_common.rb | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/course.rb b/app/models/course.rb index d36d5d2c5..06090f236 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -258,7 +258,7 @@ class Course < ApplicationRecord # 是否具有分班权限,返回分班的id def group_course_power(user_id) - teacher_course_groups.where(user_id: user_id).pluck(:id) + teacher_course_groups.where(user_id: user_id).pluck(:course_group_id) end #课程动态公共表记录 diff --git a/app/models/graduation_task.rb b/app/models/graduation_task.rb index 030978817..e247f2b6e 100644 --- a/app/models/graduation_task.rb +++ b/app/models/graduation_task.rb @@ -100,15 +100,15 @@ class GraduationTask < ApplicationRecord SELECT count(distinct graduation_work_id) cnt FROM graduation_work_scores WHERE reviewer_role IN(1,2) AND graduation_work_id IN(SELECT id FROM graduation_works WHERE graduation_task_id = #{self.id} AND user_id IN(SELECT user_id FROM course_members WHERE role = 4 AND course_group_id - IN(SELECT course_group_id FROM teacher_course_groups WHERE id IN(#{course_group_ids.join(",")})) + IN(#{course_group_ids.join(",")}) ) ) } else %Q{ SELECT COUNT(distinct graduation_work_id) cnt FROM graduation_works gw - JOIN graduation_work_scores gwc ON gw.graduation_task_id = gwc.graduation_task_id - WHERE reviewer_role IN(1,2) AND gwc.graduation_task_id = #{self.id} + JOIN graduation_work_scores gwc ON gw.id = gwc.graduation_work_id + WHERE reviewer_role IN(1,2) AND gw.graduation_task_id = #{self.id} } end GraduationWorkScore.find_by_sql(sql).first.try(:cnt).to_i @@ -127,7 +127,7 @@ class GraduationTask < ApplicationRecord sql = %Q{ SELECT count(*) cnt FROM graduation_works gw WHERE work_status = 0 AND gw.graduation_task_id = #{self.id} AND gw.user_id IN( SELECT user_id FROM course_members WHERE role = 4 AND course_group_id - IN( SELECT course_group_id FROM teacher_course_groups WHERE id not IN(#{course_group_ids.join(",")}) ) + IN(#{course_group_ids.join(",")}) ) } GraduationWork.find_by_sql(sql).first.try(:cnt) @@ -144,7 +144,7 @@ class GraduationTask < ApplicationRecord sql = %Q{ SELECT count(*) cnt FROM graduation_works gw WHERE work_status = 1 AND gw.graduation_task_id = #{self.id} AND gw.user_id IN( SELECT user_id FROM course_members WHERE role = 4 AND course_group_id - IN( SELECT course_group_id FROM teacher_course_groups WHERE id IN(#{course_group_ids.join(",")}) ) + IN(#{course_group_ids.join(",")}) ) } GraduationWork.find_by_sql(sql).first.try(:cnt) @@ -160,7 +160,7 @@ class GraduationTask < ApplicationRecord sql = %Q{ SELECT count(*) cnt FROM graduation_works gw WHERE work_status = 2 AND gw.graduation_task_id = #{self.id} AND gw.user_id IN( SELECT user_id FROM course_members WHERE role = 4 AND course_group_id - IN( SELECT course_group_id FROM teacher_course_groups WHERE id IN(#{course_group_ids.join(",")}) ) + IN(#{course_group_ids.join(",")}) ) } GraduationWork.find_by_sql(sql).first.try(:cnt) diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 80b92d175..335b898fb 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -197,7 +197,7 @@ class HomeworkCommon < ApplicationRecord JOIN student_works_scores sws on sws.student_work_id = sw.id WHERE reviewer_role IN(1,2) AND sw.id IN (SELECT id FROM student_works WHERE homework_common_id = #{self.id} AND user_id IN (SELECT user_id FROM course_members WHERE role = 4 AND course_group_id - IN (SELECT course_group_id FROM teacher_course_groups WHERE id IN(#{course_group_ids.join(",")})) + IN (#{course_group_ids.join(",")}) ) ) } From 75ea0bd5cbabaa7c4e715ff008fadae4be306e82 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 9 Jul 2019 14:37:19 +0800 Subject: [PATCH 0698/1015] add sms type --- 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 e5d9ba5c4..d3808a06b 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -142,7 +142,7 @@ class AccountsController < ApplicationController # params[:login] 手机号或者邮箱号 # params[:type]为事件通知类型 1:用户注册注册 2:忘记密码 3: 绑定手机 4: 绑定邮箱 # 如果有新的继续后面加 # 发送验证码:send_type 1:注册手机验证码 2:找回密码手机验证码 3:找回密码邮箱验证码 4:绑定手机 5:绑定邮箱 - # 6:手机验证码登录 7:邮箱验证码登录 8:邮箱注册验证码 + # 6:手机验证码登录 7:邮箱验证码登录 8:邮箱注册验证码 9: 验收手机号有效 def get_verification_code code = %W(0 1 2 3 4 5 6 7 8 9) value = params[:login] From da58ff267c67cd5f87397fd81e247861d86c4bd4 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 9 Jul 2019 15:01:21 +0800 Subject: [PATCH 0699/1015] =?UTF-8?q?=E9=80=89=E7=94=A8=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3=E6=94=B9=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 19 +++++-------------- .../homework_commons/shixuns.json.jbuilder | 19 +++++++++++-------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 3afb32982..29d530ebb 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -827,7 +827,7 @@ class HomeworkCommonsController < ApplicationController ## 我的实训 @shixuns = if params[:order_by] == 'mine' - current_user.my_shixuns + current_user.my_shixuns.unhidden else Shixun.unhidden end @@ -855,12 +855,6 @@ class HomeworkCommonsController < ApplicationController or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct end - ## 筛选 状态 - if params[:status].present? && params[:status].to_i != 0 - params[:status] = [0, 1] if params[:status].to_i == 1 - @shixuns = @shixuns.where(status: params[:status]) - end - ## 筛选 难度 if params[:diff].present? && params[:diff].to_i != 0 @shixuns = @shixuns.where(trainee: params[:diff]) @@ -868,25 +862,22 @@ class HomeworkCommonsController < ApplicationController ## 排序参数 bsort = params[:sort] || 'desc' - case params[:order_by] || 'myshixuns_count' - when 'new' - @shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.created_at #{bsort}") + case params[:order_by] || 'hot' when 'hot' - @shixuns = @shixuns.order("shixuns.status = 2 desc, myshixuns_count #{bsort}") + @shixuns = @shixuns.order("myshixuns_count #{bsort}") when 'mine' @shixuns = @shixuns.order("shixuns.created_at #{bsort}") else - @shixuns = @shixuns.order("shixuns.status = 2 desc, myshixuns_count #{bsort}") + @shixuns = @shixuns.order("myshixuns_count #{bsort}") end - @total_count = @shixuns.count ## 分页参数 page = params[:page] || 1 limit = params[:limit] || 15 - @shixuns = @shixuns.includes(:tag_repertoires, :challenges).page(page).per(limit) + @shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(limit) end def create_shixun_homework diff --git a/app/views/homework_commons/shixuns.json.jbuilder b/app/views/homework_commons/shixuns.json.jbuilder index 129a0b6d3..8bfeea562 100644 --- a/app/views/homework_commons/shixuns.json.jbuilder +++ b/app/views/homework_commons/shixuns.json.jbuilder @@ -1,12 +1,15 @@ -json.tags @tags do |tag| - json.tag_id tag.id - json.tag_name tag.name +json.shixun_list @shixuns do |shixun| + json.shixun_identifier shixun.identifier + json.name shixun.name + json.creator shixun.user&.full_name + json.creator_login shixun.user&.login + json.school shixun.user&.school_name + json.myshixuns_count shixun.myshixuns_count + json.level level_to_s(shixun.trainee) + json.challenge_tags shixun.challenge_tags_name end -json.shixun_list do - json.partial! 'shixuns/choose_shixun', locals: {shixuns: @shixuns} -end - -json.shixuns_count @shixuns_count +json.shixuns_count @total_count +json.search_tags @search_tags json.partial! 'homework_commons/second_category', locals: {main_catrgory: @main_catrgory, homework_category: @homework_category} \ No newline at end of file From 0366af3a88f0176f2eafb8e460ad5999a912fa66 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 9 Jul 2019 15:07:57 +0800 Subject: [PATCH 0700/1015] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 159650c38..e6c4ae330 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -290,7 +290,8 @@ class CoursesController < ApplicationController def apply_teachers search_str = params[:search].present? ? params[:search].strip : "" - @applications = CourseMessage.unhandled_join_course_requests_by_course(@course).joins(:user). + @applications = CourseMessage.unhandled_join_course_requests_by_course(@course). + joins("join users on course_messages.course_message_id=users.id"). where("LOWER(concat(users.lastname, users.firstname)) LIKE ?", "%#{search_str}%") @teacher_list_size = @course.teachers.size @applications_size = CourseMessage.unhandled_join_course_requests_by_course(@course).size From 008690be20d7db7d74a146e38e88eba384c74d1e Mon Sep 17 00:00:00 2001 From: jasder Date: Tue, 9 Jul 2019 15:31:43 +0800 Subject: [PATCH 0701/1015] FIX bug --- app/views/boards/destroy.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/boards/destroy.json.jbuilder b/app/views/boards/destroy.json.jbuilder index a9d8fbdaf..0fd68dc8c 100644 --- a/app/views/boards/destroy.json.jbuilder +++ b/app/views/boards/destroy.json.jbuilder @@ -1,2 +1,2 @@ json.status 0 -json.right_url course_board_messages_path(@course, @course_board) \ No newline at end of file +json.right_url board_messages_path(@course_board) From 3f6049df398585e94fbf7dd64dc52bff3a56affd Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 9 Jul 2019 15:58:15 +0800 Subject: [PATCH 0702/1015] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E4=BD=9C=E5=93=81=E7=9A=84=E5=85=B3=E5=8D=A1=E5=88=86=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 35 ++++++++++++++----- app/models/challenge_work_score.rb | 8 +++++ .../adjust_review_score.json.jbuilder | 3 ++ .../shixun_work_report.json.jbuilder | 1 + 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 92d146c82..62d96c424 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -631,16 +631,35 @@ class StudentWorksController < ApplicationController # 查重作品调分 def adjust_review_score - if params[:score].nil? || params[:challenge_id].nil? || params[:code_rate].nil? || params[:copy_user_id].nil? + tip_exception("缺少type参数") if params[:type].blank? || ["review", "report"].include?(params[:type]) + if params[:type] == "review" && (params[:score].nil? || params[:challenge_id].nil? || params[:code_rate].nil? || params[:copy_user_id].nil?) tip_exception("参数错误,score和challenge_id和code_rate和copy_user_id不能为空") + elsif params[:type] == "report" && (params[:score].nil? || params[:challenge_id].nil?) + tip_exception("参数错误,score和challenge_id") + end + challenge_setting = @homework.homework_challenge_settings.find_by(challenge_id: params[:challenge_id]) + challenge = challenge_setting&.challenge + tip_exception("不能小于零") if params[:score] < 0 + tip_exception("不能大于关卡分值:#{challenge_setting.score}分") if challenge_setting.score < params[:score] + + ActiveRecord::Base.transaction do + begin + if params[:type] == "review" + copy_user = User.find params[:copy_user_id] + comment = "代码查重结果显示与#{copy_user.try(:show_real_name)}的代码相似度#{params[:code_rate]}%" + else + comment = "根据实训报告中最终提交的代码调整第#{challenge.position}关分数" + end + challenge_score = @work.challenge_work_scores.create(challenge_id: params[:challenge_id], user_id: current_user.id, score: params[:score], + comment: comment) + challenge_score.create_tiding current_user.id + HomeworksService.new.update_myshixun_work_score @work, @work&.myshixun, @work&.myshixun&.games, @homework, @homework.homework_challenge_settings + rescue Exception => e + uid_logger(e.message) + tip_exception(e.message) + raise ActiveRecord::Rollback + end end - copy_user = User.find params[:copy_user_id] - comment = "代码查重结果显示与#{copy_user.try(:show_real_name)}的代码相似度#{params[:code_rate]}%" - @work.challenge_work_scores.create(challenge_id: params[:challenge_id], user_id: current_user.id, score: params[:score], - comment: comment) - HomeworksService.new.set_shixun_final_score(@work) - @work_score = @homework.student_works.find_by(id: @work.id).try(:work_score) - end diff --git a/app/models/challenge_work_score.rb b/app/models/challenge_work_score.rb index 8316e228b..1e7c9f7fe 100644 --- a/app/models/challenge_work_score.rb +++ b/app/models/challenge_work_score.rb @@ -2,4 +2,12 @@ class ChallengeWorkScore < ApplicationRecord belongs_to :user belongs_to :student_work belongs_to :challenge + has_many :tidings, as: :container, dependent: :destroy + + def create_tiding trigger_user_id + tidings << Tiding.new(user_id: student_work.user_id, trigger_user_id: trigger_user_id, container_id: id, + container_type: "ChallengeWorkScore", parent_container_id: student_work_id, + parent_container_type: "StudentWork", belong_container_id: student_work&.homework_common&.course_id, + belong_container_type: "Course", viewed: 0, tiding_type: "HomeworkCommon") + end end diff --git a/app/views/student_works/adjust_review_score.json.jbuilder b/app/views/student_works/adjust_review_score.json.jbuilder index e69de29bb..399b52c13 100644 --- a/app/views/student_works/adjust_review_score.json.jbuilder +++ b/app/views/student_works/adjust_review_score.json.jbuilder @@ -0,0 +1,3 @@ +json.status 0 +json.message "调分成功" +json.work_score @work.work_score \ No newline at end of file diff --git a/app/views/student_works/shixun_work_report.json.jbuilder b/app/views/student_works/shixun_work_report.json.jbuilder index 1c6ed5899..f0aa8119e 100644 --- a/app/views/student_works/shixun_work_report.json.jbuilder +++ b/app/views/student_works/shixun_work_report.json.jbuilder @@ -24,6 +24,7 @@ if @shixun json.myself_experience game.final_score json.experience game.challenge.all_score json.complete_status game_status(game, @homework) + json.challenge_id game.challenge_id end end From 48cfc3f39dd56dabfcd080010cd23c95a92571d7 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 9 Jul 2019 17:18:06 +0800 Subject: [PATCH 0703/1015] =?UTF-8?q?=E9=80=89=E7=94=A8=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E7=9A=84=E5=BC=B9=E6=A1=86=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 29d530ebb..e662525f1 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -927,6 +927,64 @@ class HomeworkCommonsController < ApplicationController @subjects = @subjects.page(page).per(10) @subjects = @subjects.includes(:shixuns) + + @tags = Repertoire.where(nil).order("updated_at desc") + select = params[:select] # 路径导航类型 + reorder = params[:order] || "myshixun_count" + search = params[:search] + + ## 分页参数 + page = params[:page] || 1 + limit = params[:limit] || 15 + offset = (page.to_i-1) * limit + + # 最热排序 + if reorder == "myshixun_count" + if select + @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, + subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns + on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where + subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%' + AND `subjects`.`repertoire_id` = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count DESC") + else + @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, + subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns + on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where + `subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%' + GROUP BY subjects.id ORDER BY myshixun_member_count DESC") + end + else + # 我的路径 + if reorder == "mine" + mine_subject_id = StageShixun.find_by_sql("select DISTINCT(subject_id) from stage_shixuns where shixun_id in + (select distinct(shixun_id) from myshixuns where user_id=#{current_user.id})").map(&:subject_id) + manage_subject_id = SubjectMember.where(user_id: current_user.id).pluck(:subject_id) + total_subject_id = (mine_subject_id + manage_subject_id).uniq + @subjects = Subject.where(id: total_subject_id) + end + + # 类型 + if select + @subjects = @subjects.where(repertoire_id: select) + end + + if search.present? + @subjects = @subjects.where("name like ?", "%#{search}%") + end + + # 排序 + order_str = reorder == "publish_time" ? "status = 2 desc, publish_time asc" : "updated_at desc" + @subjects = @subjects.reorder(order_str) + end + + @total_count = @subjects.size + + if reorder != "myshixun_count" + @subjects = @subjects.page(page).per(limit).includes(:shixuns) + else + @subjects = @subjects[offset, limit] + + end end def create_subject_homework From 8bee375b67a224e583b9cfe56507ee1fea7684f8 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 9 Jul 2019 17:20:11 +0800 Subject: [PATCH 0704/1015] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E4=BD=9C=E5=93=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/graduation_works/edit.json.jbuilder | 2 ++ app/views/graduation_works/new.json.jbuilder | 2 ++ 2 files changed, 4 insertions(+) diff --git a/app/views/graduation_works/edit.json.jbuilder b/app/views/graduation_works/edit.json.jbuilder index 7fc3a9621..254579473 100644 --- a/app/views/graduation_works/edit.json.jbuilder +++ b/app/views/graduation_works/edit.json.jbuilder @@ -3,6 +3,8 @@ json.task_type @task.task_type json.work_id @work.id json.description @work.description json.user_name @task_user.real_name +json.max_num @task.max_num +json.min_num @task.min_num json.attachments @work.attachments do |atta| json.partial! "attachments/attachment_simple", locals: {attachment: atta, delete: @work.delete_atta(atta)} diff --git a/app/views/graduation_works/new.json.jbuilder b/app/views/graduation_works/new.json.jbuilder index 601ba02d3..26c046ab6 100644 --- a/app/views/graduation_works/new.json.jbuilder +++ b/app/views/graduation_works/new.json.jbuilder @@ -6,4 +6,6 @@ if @task.task_type == 2 json.user_id @user.id json.user_student_id @user.student_id json.group_name @course.course_member(@user.id).try(:course_group_name) + json.max_num @task.max_num + json.min_num @task.min_num end From 9b285f19c05329d3de367867f1f4a46971a042d1 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 9 Jul 2019 20:22:30 +0800 Subject: [PATCH 0705/1015] fixbug --- app/models/poll.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/models/poll.rb b/app/models/poll.rb index 1c88c4c5a..e6a363f1d 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -45,14 +45,9 @@ class Poll < ApplicationRecord if unified_setting #试卷统一设置 poll_users else -<<<<<<< HEAD - ex_group_setting_ids = poll_group_settings.poll_group_published.select(:course_group_id).pluck(:course_group_id) - poll_users.where(user_id: course.students.where(course_group_id:ex_group_setting_ids).select(:user_id).pluck(:user_id).uniq) -======= ex_group_setting_ids = published_settings.pluck(:course_group_id) poll_users.joins("join course_members on poll_users.user_id=course_members.user_id"). where(course_members: {course_group_id: ex_group_setting_ids}) ->>>>>>> 8bee375b67a224e583b9cfe56507ee1fea7684f8 end end From b023702f093b93a602b069676b6505c5c78f4e5c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 9 Jul 2019 20:47:32 +0800 Subject: [PATCH 0706/1015] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E7=9A=84=E8=AF=84=E8=AF=AD=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/export_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index 1732e1d10..898233ff4 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -257,7 +257,7 @@ module ExportHelper w_13 = work.work_score.nil? ? "未评分" : work.work_score.round(1) w_14 = work.commit_time.present? ? format_time(work.commit_time) : "--" w_15 = work.update_time.present? ? format_time(work.update_time) : "--" - teacher_comments = work.student_works_scores + teacher_comments = work.graduation_work_scores if teacher_comments.present? w_16 = "" teacher_comments.each do |t| From 0b529f7d39f332877c35d8871c19d5b058ee210f Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 9 Jul 2019 20:51:53 +0800 Subject: [PATCH 0707/1015] fixbug --- app/views/graduation_tasks/tasks_list.xlsx.axlsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/graduation_tasks/tasks_list.xlsx.axlsx b/app/views/graduation_tasks/tasks_list.xlsx.axlsx index 1f4f76292..8aa08122c 100644 --- a/app/views/graduation_tasks/tasks_list.xlsx.axlsx +++ b/app/views/graduation_tasks/tasks_list.xlsx.axlsx @@ -5,10 +5,12 @@ wb.styles do |s| blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {:horizontal => :center} wb.add_worksheet(:name =>"学生成绩") do |sheet| - sheet.add_row table_columns, :style => blue_cell + sheet.add_row table_columns,:height =>20, :style => blue_cell sheet.column_info.first.width = 12 task_users.each do |user| sheet.add_row user, :style => sz_all end #each_widh_index + sheet.column_widths *([25]*sheet.column_info.count) + sheet.column_info.first.width = 12 end #add_worksheet end \ No newline at end of file From fa86d4477e712fdb5106f983cb39a3bbb0ccc65e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 9 Jul 2019 20:58:28 +0800 Subject: [PATCH 0708/1015] =?UTF-8?q?=E4=BF=AE=E6=94=B9xlsx=E7=9A=84?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../export_member_scores_excel.xlsx.axlsx | 18 +++++++++--------- .../graduation_tasks/tasks_list.xlsx.axlsx | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/views/courses/export_member_scores_excel.xlsx.axlsx b/app/views/courses/export_member_scores_excel.xlsx.axlsx index da8c05f7a..4a70ea30a 100644 --- a/app/views/courses/export_member_scores_excel.xlsx.axlsx +++ b/app/views/courses/export_member_scores_excel.xlsx.axlsx @@ -14,7 +14,7 @@ wb.styles do |s| group_info_d = course_group_info[0] group_info_detail = course_group_info[1] course_main_info.each do |c| - sheet.add_row c, :style => sz_all #用户id + sheet.add_row c, :height => 20, :style => sz_all #用户id end sheet["A1:A7"].each { |c| c.style = row_cell } sheet.add_row [],:style => sz_all @@ -32,12 +32,12 @@ wb.styles do |s| sheet.sheet_view.show_grid_lines = false sheet_title = activity_level[1] sheet_content = activity_level[2] - sheet.add_row sheet_title, :style => blue_cell + sheet.add_row sheet_title, :height => 20,:style => blue_cell if sheet_content.count > 0 sheet_content.each_with_index do |c,index| c_1 = (index+1) c_2 = [c_1] + c.values - sheet.add_row c_2, :style => sz_all #用户id + sheet.add_row c_2, :height => 20, :style => sz_all #用户id end sheet.column_widths *([20]*sheet.column_info.count) sheet.column_info.first.width = 8 @@ -82,7 +82,7 @@ wb.styles do |s| sheet_content.each_with_index do |c,index| c_1 = (index+1) c_2 = [c_1] + c - sheet.add_row c_2, :style => sz_all #用户id + sheet.add_row c_2, :height => 20,:style => sz_all #用户id end end sheet.column_widths *([15]*sheet.column_info.count) @@ -100,7 +100,7 @@ wb.styles do |s| sheet.add_row head_title, :style => blue_cell if content_shixun.count > 0 content_shixun.each do |user| - sheet.add_row user, :style => sz_all + sheet.add_row user, :height => 20,:style => sz_all end #each_widh_index end sheet.column_widths *([20]*sheet.column_info.count) @@ -119,7 +119,7 @@ wb.styles do |s| sheet.add_row head_title, :style => blue_cell if content_.count > 0 content_.each do |user| - sheet.add_row user, :style => no_wrap_sz + sheet.add_row user, :height => 20,:style => no_wrap_sz end #each_widh_index end sheet.column_widths *([20]*sheet.column_info.count) @@ -138,7 +138,7 @@ wb.styles do |s| sheet.add_row head_title, :style => blue_cell if content_.count > 0 content_.each do |user| - sheet.add_row user, :style => sz_all + sheet.add_row user, :height => 20,:style => sz_all end #each_widh_index end sheet.column_widths *([20]*sheet.column_info.count) @@ -155,7 +155,7 @@ wb.styles do |s| content_ = task[2] sheet.add_row task[1], :style => blue_cell content_.each do |user| - sheet.add_row user, :style => sz_all + sheet.add_row user, :height => 20,:style => sz_all end #each_widh_index sheet.column_widths *([20]*sheet.column_info.count) sheet.column_info.first.width = 12 @@ -171,7 +171,7 @@ wb.styles do |s| content_ = ex[2] sheet.add_row ex[1], :style => blue_cell content_.each do |user| - sheet.add_row user, :style => sz_all #用户id + sheet.add_row user, :height => 20,:style => sz_all #用户id end #each_widh_index sheet.column_widths *([20]*sheet.column_info.count) sheet.column_info.first.width = 12 diff --git a/app/views/graduation_tasks/tasks_list.xlsx.axlsx b/app/views/graduation_tasks/tasks_list.xlsx.axlsx index 8aa08122c..e34290498 100644 --- a/app/views/graduation_tasks/tasks_list.xlsx.axlsx +++ b/app/views/graduation_tasks/tasks_list.xlsx.axlsx @@ -8,7 +8,7 @@ wb.styles do |s| sheet.add_row table_columns,:height =>20, :style => blue_cell sheet.column_info.first.width = 12 task_users.each do |user| - sheet.add_row user, :style => sz_all + sheet.add_row user, :height =>20, :style => sz_all end #each_widh_index sheet.column_widths *([25]*sheet.column_info.count) sheet.column_info.first.width = 12 From a102e6a22b830bbcaf1e40fe21a79dc0486776e0 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 9 Jul 2019 21:05:52 +0800 Subject: [PATCH 0709/1015] fixbug --- .../export_member_scores_excel.xlsx.axlsx | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/views/courses/export_member_scores_excel.xlsx.axlsx b/app/views/courses/export_member_scores_excel.xlsx.axlsx index 4a70ea30a..5b226a09c 100644 --- a/app/views/courses/export_member_scores_excel.xlsx.axlsx +++ b/app/views/courses/export_member_scores_excel.xlsx.axlsx @@ -4,7 +4,7 @@ wb.styles do |s| no_wrap_sz = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: false,:horizontal => :center,:vertical => :center } sz_all = s.add_style :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center } row_cell = s.add_style :bg_color=> "FAEBDC",:border => { :style => :thin, :color =>"000000" },alignment: {wrap_text: true,:horizontal => :center,:vertical => :center } - blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 20,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center} + blue_cell = s.add_style :bg_color => "FAEBDC", :sz => 10,:height => 25,:b => true, :border => { :style => :thin, :color =>"000000" },:alignment => {wrap_text: true,:horizontal => :center,:vertical => :center} #课堂信息摘要 wb.add_worksheet(name:course_info[0]) do |sheet| @@ -14,7 +14,7 @@ wb.styles do |s| group_info_d = course_group_info[0] group_info_detail = course_group_info[1] course_main_info.each do |c| - sheet.add_row c, :height => 20, :style => sz_all #用户id + sheet.add_row c, :style => sz_all #用户id end sheet["A1:A7"].each { |c| c.style = row_cell } sheet.add_row [],:style => sz_all @@ -32,12 +32,12 @@ wb.styles do |s| sheet.sheet_view.show_grid_lines = false sheet_title = activity_level[1] sheet_content = activity_level[2] - sheet.add_row sheet_title, :height => 20,:style => blue_cell + sheet.add_row sheet_title, :height => 25,:style => blue_cell if sheet_content.count > 0 sheet_content.each_with_index do |c,index| c_1 = (index+1) c_2 = [c_1] + c.values - sheet.add_row c_2, :height => 20, :style => sz_all #用户id + sheet.add_row c_2, :height => 25, :style => sz_all #用户id end sheet.column_widths *([20]*sheet.column_info.count) sheet.column_info.first.width = 8 @@ -82,7 +82,7 @@ wb.styles do |s| sheet_content.each_with_index do |c,index| c_1 = (index+1) c_2 = [c_1] + c - sheet.add_row c_2, :height => 20,:style => sz_all #用户id + sheet.add_row c_2, :height => 25,:style => sz_all #用户id end end sheet.column_widths *([15]*sheet.column_info.count) @@ -100,7 +100,7 @@ wb.styles do |s| sheet.add_row head_title, :style => blue_cell if content_shixun.count > 0 content_shixun.each do |user| - sheet.add_row user, :height => 20,:style => sz_all + sheet.add_row user, :height => 25,:style => sz_all end #each_widh_index end sheet.column_widths *([20]*sheet.column_info.count) @@ -119,7 +119,7 @@ wb.styles do |s| sheet.add_row head_title, :style => blue_cell if content_.count > 0 content_.each do |user| - sheet.add_row user, :height => 20,:style => no_wrap_sz + sheet.add_row user, :height => 25,:style => no_wrap_sz end #each_widh_index end sheet.column_widths *([20]*sheet.column_info.count) @@ -138,7 +138,7 @@ wb.styles do |s| sheet.add_row head_title, :style => blue_cell if content_.count > 0 content_.each do |user| - sheet.add_row user, :height => 20,:style => sz_all + sheet.add_row user, :height => 25,:style => sz_all end #each_widh_index end sheet.column_widths *([20]*sheet.column_info.count) @@ -155,7 +155,7 @@ wb.styles do |s| content_ = task[2] sheet.add_row task[1], :style => blue_cell content_.each do |user| - sheet.add_row user, :height => 20,:style => sz_all + sheet.add_row user, :height => 25,:style => sz_all end #each_widh_index sheet.column_widths *([20]*sheet.column_info.count) sheet.column_info.first.width = 12 @@ -171,7 +171,7 @@ wb.styles do |s| content_ = ex[2] sheet.add_row ex[1], :style => blue_cell content_.each do |user| - sheet.add_row user, :height => 20,:style => sz_all #用户id + sheet.add_row user, :height => 25,:style => sz_all #用户id end #each_widh_index sheet.column_widths *([20]*sheet.column_info.count) sheet.column_info.first.width = 12 From 274437554269290ec6872662fc887e0d9840de1d Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 9 Jul 2019 21:11:52 +0800 Subject: [PATCH 0710/1015] fixbug --- app/helpers/export_helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index 898233ff4..57fe9c17c 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -100,7 +100,7 @@ module ExportHelper user_time = format_time(t.updated_at) user_score = t&.score user_comment = t.comment.present? ? t.comment : "--" - comment_title = "教师:#{user_name}\n时间:#{user_time.to_s}\n分数:#{user_score.to_s}分\n评语:#{user_comment}\n\n" + comment_title = "#{user_name}: #{user_time.to_s} #{user_score.to_s}分\n#{user_comment}\n\n" w_18 = w_18 + comment_title end else @@ -172,7 +172,7 @@ module ExportHelper user_time = format_time(t.updated_at) user_score = t&.score user_comment = t.comment.present? ? t.comment : "--" - comment_title = "教师:#{user_name}\n时间:#{user_time.to_s}\n分数:#{user_score.to_s}分\n评语:#{user_comment}\n\n" + comment_title = "#{user_name}: #{user_time.to_s} #{user_score.to_s}分\n#{user_comment}\n\n" # ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "分" + "\n" + "评语:" + user_comment + "\n\n") w_18 = w_18 + comment_title end @@ -265,7 +265,7 @@ module ExportHelper user_time = format_time(t.updated_at) user_score = t&.score user_comment = t.comment.present? ? t.comment : "--" - comment_title = "教师:#{user_name}\n时间:#{user_time.to_s}\n分数:#{user_score.to_s}分\n评语:#{user_comment}\n\n" + comment_title = "#{user_name}: #{user_time.to_s} #{user_score.to_s}分\n#{user_comment}\n\n" # ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "分" + "\n" + "评语:" + user_comment + "\n\n") w_16 = w_16 + comment_title end From f286d837639b86f1378b76a7b5f38fd0a542c812 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 9 Jul 2019 21:16:08 +0800 Subject: [PATCH 0711/1015] fixbug --- app/helpers/export_helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index 57fe9c17c..76f51e498 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -100,7 +100,7 @@ module ExportHelper user_time = format_time(t.updated_at) user_score = t&.score user_comment = t.comment.present? ? t.comment : "--" - comment_title = "#{user_name}: #{user_time.to_s} #{user_score.to_s}分\n#{user_comment}\n\n" + comment_title = "#{user_name}: #{user_time.to_s} #{user_score.to_s}分\n#{user_comment}\n\n" w_18 = w_18 + comment_title end else @@ -172,7 +172,7 @@ module ExportHelper user_time = format_time(t.updated_at) user_score = t&.score user_comment = t.comment.present? ? t.comment : "--" - comment_title = "#{user_name}: #{user_time.to_s} #{user_score.to_s}分\n#{user_comment}\n\n" + comment_title = "#{user_name}: #{user_time.to_s} #{user_score.to_s}分\n#{user_comment}\n\n" # ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "分" + "\n" + "评语:" + user_comment + "\n\n") w_18 = w_18 + comment_title end @@ -265,7 +265,7 @@ module ExportHelper user_time = format_time(t.updated_at) user_score = t&.score user_comment = t.comment.present? ? t.comment : "--" - comment_title = "#{user_name}: #{user_time.to_s} #{user_score.to_s}分\n#{user_comment}\n\n" + comment_title = "#{user_name}: #{user_time.to_s} #{user_score.to_s}分\n#{user_comment}\n\n" # ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "分" + "\n" + "评语:" + user_comment + "\n\n") w_16 = w_16 + comment_title end From 4f3a696ea7896ca9de46ada4bf0b4b7786c48131 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 10 Jul 2019 09:48:26 +0800 Subject: [PATCH 0712/1015] =?UTF-8?q?=E6=89=93=E6=98=9F=E6=98=9F=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/shixun.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/models/shixun.rb b/app/models/shixun.rb index c4345f90a..4a4aea355 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -158,13 +158,12 @@ class Shixun < ApplicationRecord # 实训评分信息 # return [实训评分, 5星评分比例, 4星评分比例, 3星评分比例, 2星评分比例, 1星评分比例] def shixun_preference_info - game_star_info = Game.find_by_sql("select g.star from - (games g left join (myshixuns m join shixuns s on s.id = m.shixun_id) on m.id = g.myshixun_id) - where g.star != 0 and s.id = #{self.id}") + game_star_info = Game.joins(challenge: :shixun).where(shixuns: {id: id}).where.not(games: {star: 0}).pluck(:star) + star_info = [] if game_star_info.present? 5.downto(1) do |i| - star_info << ((game_star_info.select{|s| s.star == i}.count / game_star_info.count.to_f) * 100).round + star_info << ((game_star_info.select{|s| s == i}.count / game_star_info.count.to_f) * 100).round end sum = star_info.sum max = star_info.max @@ -175,7 +174,7 @@ class Shixun < ApplicationRecord star_info = star_info.map{|s| s == max ? s + 1 : s} end cnt = game_star_info.count - sum = game_star_info.sum(&:star) + sum = game_star_info.sum star_info.unshift((sum / cnt.to_f).round(1)) else star_info = [5.0, 100, 0, 0, 0, 0] From 0dbb4c6c540daae66c3019dd6ae40541e0d815e1 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 10 Jul 2019 10:09:30 +0800 Subject: [PATCH 0713/1015] =?UTF-8?q?=E9=80=89=E7=94=A8=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E7=9A=84=E5=BC=B9=E6=A1=86=E6=94=B9=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 49 ++++++------------- app/models/subject.rb | 5 ++ .../homework_commons/subjects.json.jbuilder | 6 ++- 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index e662525f1..7b61f8d4e 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -829,7 +829,13 @@ class HomeworkCommonsController < ApplicationController if params[:order_by] == 'mine' current_user.my_shixuns.unhidden else - Shixun.unhidden + if current_user.admin? + Shixun.unhidden + else + none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id) + + @shixuns = Shixun.where.not(id: none_shixun_ids).unhidden + end end ## 方向 @@ -903,34 +909,10 @@ class HomeworkCommonsController < ApplicationController # 选用实训课程 def subjects - search = params[:search] - type = params[:type] - # 显示所有未隐藏的、已发布的实训课程 - @subjects = Subject.select([:id, :name, :status, :repertoire_id]).visible.unhidden - - @tags = Repertoire.select([:id, :name]).where(id: @subjects.pluck(:repertoire_id).uniq).order("updated_at desc") - - if params[:search] && params[:search].strip != "" - @subjects = @subjects.joins(:user).where("subjects.name like ? or concat(users.lastname, users.firstname) like ?", - "%#{search}%", "%#{search}%") - end - - unless type.blank? || type == "all" - @subjects = @subjects.where(repertoire_id: type) - end - - @subjects = @subjects.reorder("subjects.created_at desc") - @subjects_count = @subjects.size - - ## 分页参数 - page = params[:page] || 1 - @subjects = @subjects.page(page).per(10) - - @subjects = @subjects.includes(:shixuns) - @tags = Repertoire.where(nil).order("updated_at desc") select = params[:select] # 路径导航类型 reorder = params[:order] || "myshixun_count" + sort = params[:sort] || "desc" search = params[:search] ## 分页参数 @@ -941,17 +923,17 @@ class HomeworkCommonsController < ApplicationController # 最热排序 if reorder == "myshixun_count" if select - @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, + @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%' - AND `subjects`.`repertoire_id` = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count DESC") + AND `subjects`.`repertoire_id` = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count #{sort}") else - @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, + @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where `subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%' - GROUP BY subjects.id ORDER BY myshixun_member_count DESC") + GROUP BY subjects.id ORDER BY myshixun_member_count #{sort}") end else # 我的路径 @@ -973,17 +955,18 @@ class HomeworkCommonsController < ApplicationController end # 排序 - order_str = reorder == "publish_time" ? "status = 2 desc, publish_time asc" : "updated_at desc" + order_str = "updated_at #{sort}" @subjects = @subjects.reorder(order_str) end @total_count = @subjects.size if reorder != "myshixun_count" - @subjects = @subjects.page(page).per(limit).includes(:shixuns) + @subjects = @subjects.page(page).per(limit).includes(:shixuns, user: [user_extension: :school]) else @subjects = @subjects[offset, limit] - + subject_ids = @subjects.pluck(:id) + @subjects = Subject.where(id: subject_ids).order("field(id,#{subject_ids.join(',')})").includes(:shixuns, user: [user_extension: :school]) end end diff --git a/app/models/subject.rb b/app/models/subject.rb index ced610377..115eecd49 100644 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -88,4 +88,9 @@ class Subject < ApplicationRecord def published? status == 2 end + + def shixun_tags + challenges = Challenge.where(shixun_id: shixuns.unhidden) + @tags = ChallengeTag.where(challenge_id: challenges).pluck(:name).uniq + end end \ No newline at end of file diff --git a/app/views/homework_commons/subjects.json.jbuilder b/app/views/homework_commons/subjects.json.jbuilder index ea63f2125..257fcc9d5 100644 --- a/app/views/homework_commons/subjects.json.jbuilder +++ b/app/views/homework_commons/subjects.json.jbuilder @@ -6,8 +6,12 @@ end json.subject_list @subjects do |subject| json.subject_id subject.id json.subject_name subject.name + json.challenge_tags subject.shixun_tags json.shixun_count subject.shixuns.unhidden.size json.myshixun_count subject.shixuns.pluck(:myshixuns_count).sum + json.creator subject.user&.full_name + json.creator_login subject.user&.login + json.school subject.user&.school_name end -json.subjects_count @subjects_count \ No newline at end of file +json.subjects_count @total_count \ No newline at end of file From e1864ea2f5fb92b75f35410afb2bb84deadbed25 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 10 Jul 2019 10:45:56 +0800 Subject: [PATCH 0714/1015] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/shixun.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 4a4aea355..cb305efaf 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -73,9 +73,8 @@ class Shixun < ApplicationRecord # 实训用户tag def user_tags_name(user = User.current) - challenge_ids = challenges.pluck(:id) - user_challenge_ids = user.games.where(challenge_id: challenge_ids, status: 2).pluck(:challenge_id) - ChallengeTag.where(challenge_id: user_challenge_ids).pluck(:name).uniq + Shixun.joins(challenges: [:challenge_tags, :games]).where(games: {status: 2, user_id: user.id}, shixuns: {id:id}) + .pluck("challenge_tags.name").uniq end # 实训关卡tag @@ -159,7 +158,6 @@ class Shixun < ApplicationRecord # return [实训评分, 5星评分比例, 4星评分比例, 3星评分比例, 2星评分比例, 1星评分比例] def shixun_preference_info game_star_info = Game.joins(challenge: :shixun).where(shixuns: {id: id}).where.not(games: {star: 0}).pluck(:star) - star_info = [] if game_star_info.present? 5.downto(1) do |i| From cade029fc14df0157e91ffc20c53f84d8fec29e6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 10 Jul 2019 11:06:28 +0800 Subject: [PATCH 0715/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=8A=A5=E5=91=8A?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=9A=84=E8=B0=83=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/homework_commons_helper.rb | 16 ++++++++++++++++ app/models/homework_common.rb | 4 ++++ .../shixun_work_report.json.jbuilder | 11 ++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/helpers/homework_commons_helper.rb b/app/helpers/homework_commons_helper.rb index c77ae5937..10e20ec0c 100644 --- a/app/helpers/homework_commons_helper.rb +++ b/app/helpers/homework_commons_helper.rb @@ -1,5 +1,21 @@ module HomeworkCommonsHelper + # 实训作品的单个关卡得分 + def work_challenge_score student_work, game, score, homework + result = 0 + adjust_score = student_work.challenge_work_scores.where(challenge_id: game.challenge_id).last + if adjust_score.present? + result = adjust_score.score + else + setting = homework.homework_group_setting student_work.user_id + if game.status == 2 && ((game.end_time && game.end_time < setting.end_time) || (homework.allow_late && game.end_time && game.end_time < homework.late_time)) + answer_open_evaluation = homework.homework_detail_manual.answer_open_evaluation + result = answer_open_evaluation ? score : (game.final_score > 0 ? game.real_score(score) : 0) + end + end + result + end + # 未发布时非老师角色不能访问,发布后非课堂成员不能访问未公开的作业,学生需要考虑分班设置的作业是否已发布 def homework_publish if (@user_course_identity >= Course::STUDENT && (@homework.publish_time.nil? || @homework.publish_time > Time.now)) || diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 335b898fb..ac64b92c1 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -260,4 +260,8 @@ class HomeworkCommon < ApplicationRecord self.homework_group_settings.where("end_time is not null").pluck(:end_time).max end + + def challenge_score challenge_id + homework_challenge_settings.find_by(challenge_id: challenge_id)&.score.to_f + end end diff --git a/app/views/student_works/shixun_work_report.json.jbuilder b/app/views/student_works/shixun_work_report.json.jbuilder index f0aa8119e..103ead73f 100644 --- a/app/views/student_works/shixun_work_report.json.jbuilder +++ b/app/views/student_works/shixun_work_report.json.jbuilder @@ -8,9 +8,15 @@ if @shixun json.myself_experience @work.myshixun.try(:total_score) json.total_experience @shixun.all_score json.work_score number_with_precision @work.work_score, precision: 1 - json.all_work_score 100 + json.all_work_score number_with_precision 100, precision: 1 json.time_consuming @work.myshixun_consume json.evaluate_count @user_evaluate_count.to_i + if @homework.work_efficiency + json.eff_score_full number_with_precision @homework.eff_score, precision: 1 + json.eff_score @work.eff_score + json.challenge_score_full number_with_precision (100 - @homework.eff_score), precision: 1 + json.challenge_score @work.final_score + end # 阶段成绩 json.stage_list do @@ -25,6 +31,9 @@ if @shixun json.experience game.challenge.all_score json.complete_status game_status(game, @homework) json.challenge_id game.challenge_id + challenge_score = @homework.challenge_score game.challenge_id + json.game_score_full challenge_score + json.game_score work_challenge_score @work, game, challenge_score, @homework end end From ddf679dd3671af9367eee4d31abe170a3b685241 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 10 Jul 2019 11:31:43 +0800 Subject: [PATCH 0716/1015] =?UTF-8?q?=E6=9F=A5=E9=87=8D=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E9=A1=B5=E7=9A=84=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 22 +++---------------- app/helpers/homework_commons_helper.rb | 16 -------------- app/models/student_work.rb | 15 +++++++++++++ .../code_review_detail.json.jbuilder | 7 ++++++ .../shixun_work_report.json.jbuilder | 6 ++--- 5 files changed, 28 insertions(+), 38 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 232250e4c..b7291b647 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -1354,7 +1354,7 @@ class HomeworkCommonsController < ApplicationController if results.status == 0 code_info = results.code_info homework_challenge_settings = @homework.homework_challenge_settings - @challenges = @shixun.challenges.where(id: homework_challenge_settings.pluck(:challenge_id), st: 0).includes(:games) + @challenges = @shixun.challenges.where(id: homework_challenge_settings.pluck(:challenge_id), st: 0) @challenges = @challenges.map do |challenge| code_rate = 0 @@ -1368,24 +1368,8 @@ class HomeworkCommonsController < ApplicationController game = challenge.games.find_by(user_id: @user.id) end_time = game.end_time # 用户关卡的得分 - all_score = homework_challenge_settings.find_by(challenge_id: challenge.id).try(:score) - final_score = - if @student_work.challenge_work_scores.where(challenge_id: challenge.id).last.present? - @student_work.challenge_work_scores.where(:challenge_id => game.challenge_id).last.score - else - if game.status == 2 && ((game.end_time && game.end_time < @homework.end_time) || - (@homework.allow_late && (@course.end_date.nil? || - (game.end_time && game.end_time < @course.end_date.end_of_day)))) - answer_open_evaluation = @homework.homework_detail_manual.answer_open_evaluation - # 设置了查看答案也获得满分的话就取总分。否则取关卡的百分比分支 - if answer_open_evaluation.present? - all_score - else - # 关卡的百分比 * 作业设置的分数 = 总得分 - ((game.final_score) / challenge.score) * all_score - end - end - end + all_score = homework_challenge_settings.find_by(challenge_id: challenge.id).try(:score).to_f + final_score = @student_work.work_challenge_score game, all_score # 抄袭用户 copy_user = User.find_by_id(game_codes[0].target_user_id) copy_end_time = copy_user.games.find_by(challenge_id: challenge.id).try(:end_time) if copy_user.present? diff --git a/app/helpers/homework_commons_helper.rb b/app/helpers/homework_commons_helper.rb index 10e20ec0c..c77ae5937 100644 --- a/app/helpers/homework_commons_helper.rb +++ b/app/helpers/homework_commons_helper.rb @@ -1,21 +1,5 @@ module HomeworkCommonsHelper - # 实训作品的单个关卡得分 - def work_challenge_score student_work, game, score, homework - result = 0 - adjust_score = student_work.challenge_work_scores.where(challenge_id: game.challenge_id).last - if adjust_score.present? - result = adjust_score.score - else - setting = homework.homework_group_setting student_work.user_id - if game.status == 2 && ((game.end_time && game.end_time < setting.end_time) || (homework.allow_late && game.end_time && game.end_time < homework.late_time)) - answer_open_evaluation = homework.homework_detail_manual.answer_open_evaluation - result = answer_open_evaluation ? score : (game.final_score > 0 ? game.real_score(score) : 0) - end - end - result - end - # 未发布时非老师角色不能访问,发布后非课堂成员不能访问未公开的作业,学生需要考虑分班设置的作业是否已发布 def homework_publish if (@user_course_identity >= Course::STUDENT && (@homework.publish_time.nil? || @homework.publish_time > Time.now)) || diff --git a/app/models/student_work.rb b/app/models/student_work.rb index d5b746ebd..0e41ce1ae 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -193,4 +193,19 @@ class StudentWork < ApplicationRecord def scored? student_works_scores.where.not(reviewer_role: 3).exists? end + + def work_challenge_score game, score + game_score = 0 + adjust_score = challenge_work_scores.where(challenge_id: game.challenge_id).last + if adjust_score.present? + game_score = adjust_score.score + else + setting = homework.homework_group_setting user_id + if game.status == 2 && ((game.end_time && game.end_time < setting.end_time) || (homework.allow_late && game.end_time && game.end_time < homework.late_time)) + answer_open_evaluation = homework.homework_detail_manual.answer_open_evaluation + game_score = answer_open_evaluation ? score : (game.final_score > 0 ? game.real_score(score) : 0) + end + end + game_score + end end diff --git a/app/views/homework_commons/code_review_detail.json.jbuilder b/app/views/homework_commons/code_review_detail.json.jbuilder index 4ebabf20a..f2cad7f3e 100644 --- a/app/views/homework_commons/code_review_detail.json.jbuilder +++ b/app/views/homework_commons/code_review_detail.json.jbuilder @@ -8,12 +8,19 @@ json.user_id @user.id json.user_login @user.login json.work_score @student_work.work_score + if @student_work.ultimate_score json.adjust_score @student_work.work_score < 0 ? 0 : number_with_precision(@student_work.work_score, precision: 1) else json.final_score @student_work.final_score json.late_penalty @student_work.late_penalty json.score @student_work.work_score < 0 ? 0 : number_with_precision(@student_work.work_score, precision: 1) + if @homework.work_efficiency + json.eff_score_full number_with_precision @homework.eff_score, precision: 1 + json.eff_score number_with_precision @work.eff_score, precision: 1 + json.challenge_score_full number_with_precision (100 - @homework.eff_score), precision: 1 + json.challenge_score number_with_precision @work.final_score, precision: 1 + end end json.challenge_list do diff --git a/app/views/student_works/shixun_work_report.json.jbuilder b/app/views/student_works/shixun_work_report.json.jbuilder index 103ead73f..05387125d 100644 --- a/app/views/student_works/shixun_work_report.json.jbuilder +++ b/app/views/student_works/shixun_work_report.json.jbuilder @@ -13,9 +13,9 @@ if @shixun json.evaluate_count @user_evaluate_count.to_i if @homework.work_efficiency json.eff_score_full number_with_precision @homework.eff_score, precision: 1 - json.eff_score @work.eff_score + json.eff_score number_with_precision @work.eff_score, precision: 1 json.challenge_score_full number_with_precision (100 - @homework.eff_score), precision: 1 - json.challenge_score @work.final_score + json.challenge_score number_with_precision @work.final_score, precision: 1 end # 阶段成绩 @@ -33,7 +33,7 @@ if @shixun json.challenge_id game.challenge_id challenge_score = @homework.challenge_score game.challenge_id json.game_score_full challenge_score - json.game_score work_challenge_score @work, game, challenge_score, @homework + json.game_score @work.work_challenge_score game, challenge_score end end From e9db5afd54fcd8e765c933a4aef454d9b32a0ea8 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 10 Jul 2019 11:33:21 +0800 Subject: [PATCH 0717/1015] =?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/models/student_work.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/student_work.rb b/app/models/student_work.rb index 0e41ce1ae..9151ca501 100644 --- a/app/models/student_work.rb +++ b/app/models/student_work.rb @@ -200,9 +200,9 @@ class StudentWork < ApplicationRecord if adjust_score.present? game_score = adjust_score.score else - setting = homework.homework_group_setting user_id - if game.status == 2 && ((game.end_time && game.end_time < setting.end_time) || (homework.allow_late && game.end_time && game.end_time < homework.late_time)) - answer_open_evaluation = homework.homework_detail_manual.answer_open_evaluation + setting = homework_common.homework_group_setting user_id + if game.status == 2 && ((game.end_time && game.end_time < setting.end_time) || (homework_common.allow_late && game.end_time && game.end_time < homework_common.late_time)) + answer_open_evaluation = homework_common.homework_detail_manual.answer_open_evaluation game_score = answer_open_evaluation ? score : (game.final_score > 0 ? game.real_score(score) : 0) end end From a1d11910fe2932f11cf4d17ae4b9886396495527 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 10 Jul 2019 13:52:11 +0800 Subject: [PATCH 0718/1015] =?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/views/homework_commons/code_review_detail.json.jbuilder | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/homework_commons/code_review_detail.json.jbuilder b/app/views/homework_commons/code_review_detail.json.jbuilder index f2cad7f3e..90d2c4a54 100644 --- a/app/views/homework_commons/code_review_detail.json.jbuilder +++ b/app/views/homework_commons/code_review_detail.json.jbuilder @@ -17,9 +17,9 @@ else json.score @student_work.work_score < 0 ? 0 : number_with_precision(@student_work.work_score, precision: 1) if @homework.work_efficiency json.eff_score_full number_with_precision @homework.eff_score, precision: 1 - json.eff_score number_with_precision @work.eff_score, precision: 1 + json.eff_score number_with_precision @student_work.eff_score, precision: 1 json.challenge_score_full number_with_precision (100 - @homework.eff_score), precision: 1 - json.challenge_score number_with_precision @work.final_score, precision: 1 + json.challenge_score number_with_precision @student_work.final_score, precision: 1 end end From bd099f2e1b4cce1edc309d107cc72b974e267c3e Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 10 Jul 2019 14:18:42 +0800 Subject: [PATCH 0719/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=8A=A5=E5=91=8A?= =?UTF-8?q?=E5=92=8C=E4=BB=A3=E7=A0=81=E6=9F=A5=E9=87=8D=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E9=A1=B5=E7=9A=84=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 2 +- app/views/homework_commons/code_review_detail.json.jbuilder | 2 ++ app/views/student_works/adjust_review_score.json.jbuilder | 3 ++- app/views/student_works/shixun_work_report.json.jbuilder | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 62d96c424..1c98db56c 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -631,7 +631,7 @@ class StudentWorksController < ApplicationController # 查重作品调分 def adjust_review_score - tip_exception("缺少type参数") if params[:type].blank? || ["review", "report"].include?(params[:type]) + tip_exception("缺少type参数") if params[:type].blank? || !["review", "report"].include?(params[:type]) if params[:type] == "review" && (params[:score].nil? || params[:challenge_id].nil? || params[:code_rate].nil? || params[:copy_user_id].nil?) tip_exception("参数错误,score和challenge_id和code_rate和copy_user_id不能为空") elsif params[:type] == "report" && (params[:score].nil? || params[:challenge_id].nil?) diff --git a/app/views/homework_commons/code_review_detail.json.jbuilder b/app/views/homework_commons/code_review_detail.json.jbuilder index 90d2c4a54..c33a906ec 100644 --- a/app/views/homework_commons/code_review_detail.json.jbuilder +++ b/app/views/homework_commons/code_review_detail.json.jbuilder @@ -2,6 +2,7 @@ json.course_id @course.id json.course_name @course.name json.homework_common_id @homework.id json.homework_common_name @homework.name +json.work_id @student_work.id json.work_name @student_work.name json.username @user.full_name json.user_id @user.id @@ -32,6 +33,7 @@ json.challenge_list do json.final_score challenge[:final_score] json.username challenge[:username] json.all_score challenge[:all_score] + json.copy_user_id challenge[:copy_user_id] json.copy_username challenge[:copy_username] json.copy_end_time challenge[:copy_end_time] json.code_rate challenge[:code_rate] diff --git a/app/views/student_works/adjust_review_score.json.jbuilder b/app/views/student_works/adjust_review_score.json.jbuilder index 399b52c13..928806bd6 100644 --- a/app/views/student_works/adjust_review_score.json.jbuilder +++ b/app/views/student_works/adjust_review_score.json.jbuilder @@ -1,3 +1,4 @@ json.status 0 json.message "调分成功" -json.work_score @work.work_score \ No newline at end of file +json.work_score number_with_precision @work.work_score, 1 +json.challenge_score number_with_precision @work.final_score, 1 \ No newline at end of file diff --git a/app/views/student_works/shixun_work_report.json.jbuilder b/app/views/student_works/shixun_work_report.json.jbuilder index 05387125d..e24092f05 100644 --- a/app/views/student_works/shixun_work_report.json.jbuilder +++ b/app/views/student_works/shixun_work_report.json.jbuilder @@ -1,6 +1,7 @@ json.homework_common_id @homework.id json.category @homework.category_info json.course_name @course.name +json.work_id @work.id if @shixun json.shixun_name @shixun.name # 总体评价 From a299eabdaf347fb6d71be65864864a0dd3912f9f Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 10 Jul 2019 14:55:57 +0800 Subject: [PATCH 0720/1015] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E6=9F=A5=E7=9C=8B?= =?UTF-8?q?=E4=BD=9C=E5=93=81=E5=88=97=E8=A1=A8=E6=97=B6=E6=B3=A8=E6=84=8F?= =?UTF-8?q?=E5=8C=BF=E8=AF=84=E6=88=AA=E6=AD=A2=E4=B8=8E=E8=A1=A5=E4=BA=A4?= =?UTF-8?q?=E6=88=AA=E6=AD=A2=E7=9A=84=E6=97=B6=E9=97=B4=E5=B7=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index b7291b647..767884d68 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -118,7 +118,7 @@ class HomeworkCommonsController < ApplicationController # 学生已提交作品且补交(提交)已截止、作品公开、非匿评阶段 if @work&.work_status.to_i > 0 && (@homework.work_public || @homework.score_open) && - ((!@homework.anonymous_comment && @homework.end_or_late) || @homework_detail_manual.comment_status > 4) + ((!@homework.anonymous_comment && @homework.end_or_late) || (@homework_detail_manual.comment_status > 4 && @homework.end_or_late)) @student_works = student_works.where("user_id != #{@work.user_id}") # 匿评、申诉阶段只能看到分配给自己的匿评作品 From 24799503e415a0c9c64bb4d9675fc087a46d775a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 10 Jul 2019 14:57:40 +0800 Subject: [PATCH 0721/1015] =?UTF-8?q?=E8=AF=84=E9=98=85=E9=98=B6=E6=AE=B5?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E7=9C=8B=E5=8C=BF=E8=AF=84=E4=BD=9C=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 767884d68..09d225496 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -122,7 +122,7 @@ class HomeworkCommonsController < ApplicationController @student_works = student_works.where("user_id != #{@work.user_id}") # 匿评、申诉阶段只能看到分配给自己的匿评作品 - elsif @work&.work_status.to_i > 0 && @homework.anonymous_comment && @homework_detail_manual.comment_status > 2 + elsif @work&.work_status.to_i > 0 && @homework.anonymous_comment && @homework_detail_manual.comment_status > 2 && @homework_detail_manual.comment_status <= 4 @is_evaluation = true @student_works = student_works.joins(:student_works_evaluation_distributions).where( "student_works_evaluation_distributions.user_id = #{@current_user.id}") From 1bfc279905387e0caf29cefe66472761d0ce8fc8 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 10 Jul 2019 15:36:52 +0800 Subject: [PATCH 0722/1015] =?UTF-8?q?=E8=AE=A1=E7=AE=97=E6=88=90=E7=BB=A9?= =?UTF-8?q?=E7=9A=84=E5=88=A4=E6=96=AD=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 09d225496..6f0f10f4d 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -240,7 +240,7 @@ class HomeworkCommonsController < ApplicationController end def update_score - tip_exception("作业还未发布,暂不能计算成绩") if @homework.end_or_late_none_group + tip_exception("作业还未发布,暂不能计算成绩") if @homework.publish_time.nil? || @homework.publish_time > Time.now begin if @homework.unified_setting student_works = @homework.student_works From e7cec7b8a34125769e8ada3ad35a7c6b2cc289f3 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 10 Jul 2019 15:51:30 +0800 Subject: [PATCH 0723/1015] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 9a7838a96..0b8e12094 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1188,7 +1188,7 @@ class ExercisesController < ApplicationController elsif @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生或者有过答题的(提交/未提交) @ex_user_end_time = @exercise.get_exercise_end_time(current_user.id) #当前用户所看到的剩余时间 @exercise_all_users = @exercise.get_stu_exercise_users - get_exercise_answers(@exercise_users_list, @exercise_status) # 未答和已答的 + get_exercise_answers(@exercise_all_users, @exercise_status) # 未答和已答的 exercise_current_user = @exercise_all_users.exercise_commit_users(current_user.id) #当前用户是否开始做试卷(提交/未提交/没做) if exercise_current_user.present? @exercise_current_user_status = 1 #当前用户的状态,为学生 @@ -1202,7 +1202,7 @@ class ExercisesController < ApplicationController end else @exercise_all_users = @exercise.get_stu_exercise_users - get_exercise_answers(@exercise_users_list, @exercise_status) # 未答和已答的 + get_exercise_answers(@exercise_all_users, @exercise_status) # 未答和已答的 @exercise_current_user_status = 2 #当前用户非课堂成员 @exercise_users_list = [] end From ef0953f86752a635e216eeef62ad5f2e80f163e7 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 10 Jul 2019 17:08:43 +0800 Subject: [PATCH 0724/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E8=AF=84=E9=98=85?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=9A=84=E5=88=86=E6=95=B0=E8=AF=84=E5=88=A4?= =?UTF-8?q?=E6=A0=87=E5=87=86=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 1 + app/helpers/exercises_helper.rb | 28 ++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 9a7838a96..68be45660 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1040,6 +1040,7 @@ class ExercisesController < ApplicationController @exercise_questions = @exercise_questions.order("question_number ASC") end # 判断问题是否已回答还是未回答 + @exercise_questions = @exercise_questions.includes(:exercise_stand_answers,:exercise_answers,:exercise_shixun_answers) if @t_user_exercise_status == 3 get_each_student_exercise(@exercise.id,@exercise_questions,@exercise_current_user_id) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 0b64cb916..25255de85 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -9,11 +9,32 @@ module ExercisesHelper @ex_obj_array = [] exercise_obj_status.each do |q| if q.question_type == 5 - ques_score = q.exercise_shixun_answers.search_shixun_answers("user_id",user_id).pluck(:score).sum + answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user_id) else - ques_score = q.exercise_answers.search_answer_users("user_id",user_id).score_reviewed.pluck(:score).sum + answers_content = q.exercise_answers.includes(:exercise_choices).search_answer_users("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 #答案一致,多选或单选才给分,答案不对不给分 + ques_score = q.question_score + else + ques_score = 0.0 + end + else + ques_score = 0.0 + end + else + ques_score = answers_content.select(:score).pluck(:score).sum + end + + if ques_score >= q.question_score #满分作答为正确 ques_score = q.question_score stand_answer = 1 @@ -370,7 +391,8 @@ module ExercisesHelper standard_answer = q.exercise_standard_answers.pluck(:exercise_choice_id).sort #该问题的标准答案,可能有多个 if user_answer_content == standard_answer #答案一致,多选或单选才给分,答案不对不给分 if standard_answer.count > 0 - q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 + 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 From 88a85bff7db9c71a0ace287606a1f9515102e25d Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 10 Jul 2019 17:12:17 +0800 Subject: [PATCH 0725/1015] fixbug --- app/helpers/exercises_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 25255de85..018bc2c39 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -11,7 +11,7 @@ module ExercisesHelper if q.question_type == 5 answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user_id) else - answers_content = q.exercise_answers.includes(:exercise_choices).search_answer_users("user_id",user_id) + answers_content = q.exercise_answers.search_answer_users("user_id",user_id) end if q.question_type <= 2 From e7da0d9be83609256420292bd2822a03e8ad20dd Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 10 Jul 2019 17:39:59 +0800 Subject: [PATCH 0726/1015] fixbug --- app/controllers/exercises_controller.rb | 2 +- app/helpers/exercises_helper.rb | 30 +++++++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 4be76fc59..6af48dbd1 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1130,7 +1130,7 @@ class ExercisesController < ApplicationController @is_teacher_or = @user_course_identity < Course::STUDENT ? 1 : 0 @student_status = 2 # @exercise_answerer = User.find_by(id:@exercise_current_user_id) #试卷回答者 - @exercise_questions = @exercise.exercise_questions.order("question_number ASC") + @exercise_questions = @exercise.exercise_questions.includes(:exercise_shixun_challenges,:exercise_standard_answers,:exercise_answers,:exercise_shixun_answers).order("question_number ASC") @question_status = [] get_exercise_status = @exercise.get_exercise_status(current_user) if @ex_user.present? && @is_teacher_or == 0 diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 018bc2c39..314a90403 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -34,7 +34,6 @@ module ExercisesHelper ques_score = answers_content.select(:score).pluck(:score).sum end - if ques_score >= q.question_score #满分作答为正确 ques_score = q.question_score stand_answer = 1 @@ -663,6 +662,7 @@ module ExercisesHelper user_score = nil shixun_type = 0 question_comment = [] + # user_score_pre = nil if ques_type == 5 exercise_answers = q.exercise_shixun_answers.search_shixun_answers("user_id",ex_answerer_id) else @@ -670,10 +670,26 @@ module ExercisesHelper end if student_status == 2 #当前为老师,或为学生且已提交 user_score_pre = exercise_answers.score_reviewed - if ques_type == 4 && user_score_pre.blank? #主观题时,且没有大于0的分数时,为空 - user_score = nil - else + if ques_type == 4 #主观题时,且没有大于0的分数时,为空 + user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : nil + elsif ques_type == 5 || ques_type == 3 user_score = user_score_pre.present? ? user_score_pre.pluck(:score).sum : 0.0 + else + if exercise_answers.present? #判断题和选择题时, + answer_choice_array = [] + exercise_answers.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 #答案一致,多选或单选才给分,答案不对不给分 + user_score = q.question_score + else + user_score = 0.0 + end + else + user_score = 0.0 + end end end @@ -681,9 +697,9 @@ module ExercisesHelper user_score = q.question_score end if ques_type <= 2 - answered_content = exercise_answers.pluck(:exercise_choice_id) + answered_content = exercise_answers&.pluck(:exercise_choice_id) elsif ques_type == 3 - exercise_answers.each do |a| + exercise_answers&.each do |a| u_answer = { "choice_id":a.exercise_choice_id, "answer_text": a.answer_text @@ -691,7 +707,7 @@ module ExercisesHelper answered_content.push(u_answer) end elsif ques_type == 4 - answered_content = exercise_answers.pluck(:answer_text) + answered_content = exercise_answers&.pluck(:answer_text) end if ques_type == 5 #存在实训题,及已经做了实训题的 if ex_status == 3 || is_teacher_or == 1 #如果试卷已截止,则可以看到分数,否则不能查看分数 From 092ececc96b12f491b1c9f5d1025a7bf2d63e8e5 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 11 Jul 2019 09:26:26 +0800 Subject: [PATCH 0727/1015] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=AF=95=E8=AE=BE?= =?UTF-8?q?=E9=80=89=E9=A2=98=E6=9D=83=E9=99=90=E4=B8=8D=E5=A4=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/commons_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/commons_controller.rb b/app/controllers/commons_controller.rb index 1f6dce053..fa5e14dc1 100644 --- a/app/controllers/commons_controller.rb +++ b/app/controllers/commons_controller.rb @@ -44,8 +44,8 @@ class CommonsController < ApplicationController def validate_power code = case params[:object_type].strip - when 'message' - if current_user.course_identity(@object.board.course) >= 5 && @object.author != current_user + when 'message', 'journals_for_message' + if current_user.course_identity(@object.board.course) >= Course::STUDENT && @object.author != current_user 403 else 200 From 036037df2246bff68671d2efb6400bdccad6f1d2 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 11 Jul 2019 09:31:49 +0800 Subject: [PATCH 0728/1015] =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=B8=96=E5=AD=90=E6=9D=83=E9=99=90=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/commons_controller.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/commons_controller.rb b/app/controllers/commons_controller.rb index fa5e14dc1..a23d4dba7 100644 --- a/app/controllers/commons_controller.rb +++ b/app/controllers/commons_controller.rb @@ -44,12 +44,18 @@ class CommonsController < ApplicationController def validate_power code = case params[:object_type].strip - when 'message', 'journals_for_message' + when 'message' if current_user.course_identity(@object.board.course) >= Course::STUDENT && @object.author != current_user 403 else 200 end + when 'journals_for_message' + if current_user.course_identity(@object.jour.course) >= Course::STUDENT && @object.user != current_user + 403 + else + 200 + end else current_user.admin? ? 200 : 403 end From 37737fe7866d8aa83624ca058536cbeb274b7370 Mon Sep 17 00:00:00 2001 From: jasder Date: Thu, 11 Jul 2019 09:48:24 +0800 Subject: [PATCH 0729/1015] =?UTF-8?q?FIX=20=E5=A4=84=E7=90=86=E7=82=B9?= =?UTF-8?q?=E8=B5=9E=E6=95=B0=E5=BC=82=E5=B8=B8=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/messages_controller.rb | 5 ++++- app/models/message.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index f684b27f3..0c61e2b69 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -87,7 +87,10 @@ class MessagesController < ApplicationController end def show - @message = Message.includes(:attachments, :message_detail, :children, :author => :user_extension, :board => [{course: :board_course_modules}]).find_by_id params[:id] + @message = Message.includes(:attachments, :message_detail, + :children, :author => :user_extension, + :board => [{course: :board_course_modules}]) + .find_by_id params[:id] return normal_status(-2, "ID为#{params[:id]}的帖子不存在") if @message.nil? @attachment_size = @message.attachments.size diff --git a/app/models/message.rb b/app/models/message.rb index 6b41cdd95..7588ddc2a 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -73,7 +73,7 @@ class Message < ApplicationRecord # 包含二级回复的总点赞数 def total_praises_count - descendants.sum(:praises_count) + praises_count + descendants.sum(:praises_count) end # 包含二级回复数的总回复数 From 79d1e96e36e8d25bcf996da5853989614834b479 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 11 Jul 2019 09:57:52 +0800 Subject: [PATCH 0730/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index b8a5ec53c..56fe8fc35 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -44,7 +44,7 @@ class ShixunsController < ApplicationController ## 搜索关键字 匹配关卡名, 用户名, 实训名 和 空格多搜索 if params[:keyword].present? keyword = params[:keyword].strip - @shixuns = @shixuns.joins(:users, challenges: :challenge_tags). + @shixuns = @shixuns.joins(:user, challenges: :challenge_tags). where("challenge_tags.name like '%#{keyword}%' or challenges.subject like '%#{keyword}%' or concat(lastname, firstname) like '%#{keyword}%' From 3a0e19b48bfdea0deddcdfd46ad85430ab579396 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 11 Jul 2019 10:18:50 +0800 Subject: [PATCH 0731/1015] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 56fe8fc35..20ff348a6 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -45,10 +45,11 @@ class ShixunsController < ApplicationController if params[:keyword].present? keyword = params[:keyword].strip @shixuns = @shixuns.joins(:user, challenges: :challenge_tags). - where("challenge_tags.name like '%#{keyword}%' - or challenges.subject like '%#{keyword}%' - or concat(lastname, firstname) like '%#{keyword}%' - or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct + where("challenge_tags.name like :keyword + or challenges.subject like :keyword + or concat(lastname, firstname) like :keyword + or shixuns.name like :name", + keyword: "%#{keyword}%", name: "%#{keyword.split(" ").join("%")}%").distinct end ## 筛选 状态 @@ -66,17 +67,17 @@ class ShixunsController < ApplicationController bsort = params[:sort] || 'desc' case params[:order_by] || 'publish_time' when 'new' - @shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.created_at #{bsort}") + @shixuns = @shixuns.reorder("shixuns.status = 2 desc, shixuns.created_at #{bsort}") when 'hot' - @shixuns = @shixuns.order("shixuns.status = 2 desc, myshixuns_count #{bsort}") + @shixuns = @shixuns.reorder("shixuns.status = 2 desc, shixuns.myshixuns_count #{bsort}") when 'mine' - @shixuns = @shixuns.order("shixuns.created_at #{bsort}") + @shixuns = @shixuns.reorder("shixuns.created_at #{bsort}") else - @shixuns = @shixuns.order("shixuns.status = 2 desc, publish_time #{bsort}") + @shixuns = @shixuns.reorder("shixuns.status = 2 desc, shixuns.publish_time #{bsort}") end - - @total_count = @shixuns.count + # 用id计数会快10MS左右。 + @total_count = @shixuns.count("shixuns.id") ## 分页参数 page = params[:page] || 1 From aaa0513ad5fa6fa6ee59d458a1087a6aea54ae08 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 11 Jul 2019 10:38:05 +0800 Subject: [PATCH 0732/1015] =?UTF-8?q?=E4=B8=BB=E9=A1=B5=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 20ff348a6..714351561 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -67,16 +67,16 @@ class ShixunsController < ApplicationController bsort = params[:sort] || 'desc' case params[:order_by] || 'publish_time' when 'new' - @shixuns = @shixuns.reorder("shixuns.status = 2 desc, shixuns.created_at #{bsort}") + @shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.created_at #{bsort}") when 'hot' - @shixuns = @shixuns.reorder("shixuns.status = 2 desc, shixuns.myshixuns_count #{bsort}") + @shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.myshixuns_count #{bsort}") when 'mine' - @shixuns = @shixuns.reorder("shixuns.created_at #{bsort}") + @shixuns = @shixuns.order("shixuns.created_at #{bsort}") else - @shixuns = @shixuns.reorder("shixuns.status = 2 desc, shixuns.publish_time #{bsort}") + @shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.publish_time #{bsort}") end - # 用id计数会快10MS左右。 + # 用id计数会快10+MS左右,随着数据的增加,性能会提升一些。 @total_count = @shixuns.count("shixuns.id") ## 分页参数 From c9d4714ef8fb0e42ff6fd41d17e1cadc96dd1cad Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 11 Jul 2019 10:45:30 +0800 Subject: [PATCH 0733/1015] =?UTF-8?q?=E6=88=91=E7=9A=84=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- app/models/shixun.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 714351561..c237da5e2 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -76,7 +76,7 @@ class ShixunsController < ApplicationController @shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.publish_time #{bsort}") end - # 用id计数会快10+MS左右,随着数据的增加,性能会提升一些。 + # 用id计数会快10+MS左右,对于搜索的内容随着数据的增加,性能会提升一些。 @total_count = @shixuns.count("shixuns.id") ## 分页参数 diff --git a/app/models/shixun.rb b/app/models/shixun.rb index cb305efaf..afad10397 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -52,7 +52,7 @@ class Shixun < ApplicationRecord end } - scope :visible, -> { where("status != -1") } + scope :visible, -> { where.not(status: -1) } scope :published, lambda{ where(status: 2) } scope :unhidden, lambda{ where(hidden: 0, status: 2) } scope :field_for_recommend, lambda{ select([:id, :name, :identifier, :myshixuns_count]) } From 795d4ecf71f25ffa990f94285f29d36f0cd234ab Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 11 Jul 2019 10:49:03 +0800 Subject: [PATCH 0734/1015] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=92=8C=E4=BD=9C=E5=93=81=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/graduation_tasks_controller.rb | 6 ++++-- app/helpers/graduation_tasks_helper.rb | 2 +- app/models/graduation_work.rb | 2 +- app/views/graduation_tasks/index.json.jbuilder | 8 ++++---- app/views/graduation_tasks/tasks_list.json.jbuilder | 5 +++-- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index c3b73ad20..910299fd0 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -37,7 +37,7 @@ class GraduationTasksController < ApplicationController @all_count = @course.graduation_tasks.size @published_count = @course.graduation_tasks.where("publish_time <= '#{Time.now}'").size @task_count = @tasks.size - @tasks = @tasks.reorder("#{default_order}").page(page).per(15).includes(:graduation_works, course: [course_members: :teacher_course_groups]) + @tasks = @tasks.reorder("#{default_order}").page(page).per(15).includes(:graduation_works) end # 任务问答 @@ -72,7 +72,7 @@ class GraduationTasksController < ApplicationController @work_list = @task.graduation_works.where(user_id: user_ids).includes(user: [:user_extension]) @all_work_count = @work_list.count - @teachers = @course.teachers.where.not(user_id: current_user.id) + @teachers = @course.teachers.where.not(user_id: current_user.id).includes(:user) # 教师评阅搜索 0: 未评, 1 已评 unless params[:teacher_comment].blank? graduation_work_ids = GraduationWorkScore.where(graduation_work_id: @work_list.map(&:id)).pluck(:graduation_work_id) @@ -123,6 +123,8 @@ class GraduationTasksController < ApplicationController @work_count = @work_list.count @work_excel = @work_list @work_list = @work_list.page(page).per(limit) + @students = @course.students + @assign_power = @user_course_identity < Course::STUDENT && @task.cross_comment && @task.comment_status == 2 if params[:format] == "xlsx" complete_works = @work_excel.where("work_status > 0").size diff --git a/app/helpers/graduation_tasks_helper.rb b/app/helpers/graduation_tasks_helper.rb index b9039544d..2bc059a55 100644 --- a/app/helpers/graduation_tasks_helper.rb +++ b/app/helpers/graduation_tasks_helper.rb @@ -67,7 +67,7 @@ module GraduationTasksHelper # 作品数统计:type: 1 已提交 0 未提交 def grduationwork_count task, type works = task.graduation_works - type == 1 ? works.where("work_status !=?", 0).size : works.where("work_status =?", 0).size + type == 1 ? works.select{|work| work.work_status != 0}.size : works.select{|work| work.work_status == 0}.size end # 普通/分组 作业作品状态数组 diff --git a/app/models/graduation_work.rb b/app/models/graduation_work.rb index 093e409a9..235bfcac6 100644 --- a/app/models/graduation_work.rb +++ b/app/models/graduation_work.rb @@ -68,7 +68,7 @@ class GraduationWork < ApplicationRecord # 作品是否能够分配指导老师 def assign_power?(course_identity) - course_identity < Course::STUDENT && self.graduation_task.cross_comment.present? && self.graduation_task.comment_status == 2 + course_identity < Course::STUDENT && graduation_task.cross_comment && graduation_task.comment_status == 2 end # 老师评阅分 diff --git a/app/views/graduation_tasks/index.json.jbuilder b/app/views/graduation_tasks/index.json.jbuilder index 7fcececd9..a6540555d 100644 --- a/app/views/graduation_tasks/index.json.jbuilder +++ b/app/views/graduation_tasks/index.json.jbuilder @@ -1,10 +1,6 @@ json.course_identity @identity json.course_public @course.is_public == 1 json.is_end @course.is_end -json.all_count @all_count -json.published_count @published_count -json.unpublished_count @all_count - @published_count -json.task_count @task_count json.tasks @tasks.each do |task| # task_private = @identity > Course::STUDENT && !task.is_public @@ -29,3 +25,7 @@ json.tasks @tasks.each do |task| end end +json.all_count @all_count +json.published_count @published_count +json.unpublished_count @all_count - @published_count +json.task_count @task_count diff --git a/app/views/graduation_tasks/tasks_list.json.jbuilder b/app/views/graduation_tasks/tasks_list.json.jbuilder index 7588b6b6e..ac5aa050e 100644 --- a/app/views/graduation_tasks/tasks_list.json.jbuilder +++ b/app/views/graduation_tasks/tasks_list.json.jbuilder @@ -34,6 +34,7 @@ if @task.published? || @user_course_identity < Course::STUDENT json.work_count @work_count json.all_work_count @all_work_count end + # 学生数据 json.work_lists do json.array! @work_list do |work| @@ -41,7 +42,7 @@ if @task.published? || @user_course_identity < Course::STUDENT json.user_id work.user.id json.name work.user.real_name json.student_id work.user.student_id - json.class_grouping_name work.class_grouping_name + json.class_grouping_name @students.select{|student| student.user_id == work.user_id}.first.try(:course_group_name) json.ultimate_score work.ultimate_score if @task.have_grouping? json.grouping_name work.grouping_name @@ -58,7 +59,7 @@ if @task.published? || @user_course_identity < Course::STUDENT end json.late_penalty work.late_penalty if @task.allow_late json.final_score work_final_score work, @current_user, @user_course_identity - json.assign work.assign_power?(@user_course_identity) + json.assign @assign_power json.view_work @view_work || @current_user.id == work.user_id end end From ef5da1ea0ee164dd20559583be61b2982e5f8971 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 11 Jul 2019 11:07:36 +0800 Subject: [PATCH 0735/1015] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E4=BD=9C=E5=93=81?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/graduation_tasks_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 910299fd0..cadac75be 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -112,7 +112,7 @@ class GraduationTasksController < ApplicationController # 排序 rorder = params[:order].blank? ? "updated_at" : params[:order] b_order = params[:b_order].blank? ? "desc" : params[:b_order] - if rorder == "created_at" || rorder == "work_score" + if rorder == "updated_at" || rorder == "work_score" @work_list = @work_list.order("graduation_works.#{rorder} #{b_order}") elsif rorder == "student_id" @work_list = @work_list.joins(user: :user_extension).order("user_extensions.#{rorder} #{b_order}") From 32ecb2ed6dd47cbfe1a1404326d157b7c6f3f6fc Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 11 Jul 2019 11:19:48 +0800 Subject: [PATCH 0736/1015] =?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/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 cadac75be..9b62f7dbd 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -110,9 +110,9 @@ class GraduationTasksController < ApplicationController end # 排序 - rorder = params[:order].blank? ? "updated_at" : params[:order] + rorder = params[:order].blank? ? "update_time" : params[:order] b_order = params[:b_order].blank? ? "desc" : params[:b_order] - if rorder == "updated_at" || rorder == "work_score" + if rorder == "update_time" || rorder == "work_score" @work_list = @work_list.order("graduation_works.#{rorder} #{b_order}") elsif rorder == "student_id" @work_list = @work_list.joins(user: :user_extension).order("user_extensions.#{rorder} #{b_order}") From f8ba7399df12316a009789b2e735f51e1f6f7fb0 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 11 Jul 2019 11:23:54 +0800 Subject: [PATCH 0737/1015] =?UTF-8?q?=E5=AE=9E=E8=B7=B5=E7=A4=BE=E5=8C=BA?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E7=9A=84'=E6=9C=80=E7=83=AD'tab=E7=9A=84?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/subjects_controller.rb | 22 ++++++++++++---------- app/models/subject.rb | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index bb7059af6..34f9c2f5a 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -22,17 +22,17 @@ class SubjectsController < ApplicationController # 最热排序 if reorder == "myshixun_count" if select - @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, - subjects.shixuns_count, COUNT(myshixuns.id) AS myshixun_member_count FROM myshixuns, stage_shixuns, subjects - WHERE myshixuns.shixun_id = stage_shixuns.shixun_id AND stage_shixuns.subject_id = subjects.id - AND `subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%' - AND `subjects`.`repertoire_id` = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count DESC") + @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, + subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns + on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where + subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%' + AND `subjects`.`repertoire_id` = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count DESC") else - @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, - subjects.shixuns_count, COUNT(myshixuns.id) AS myshixun_member_count FROM myshixuns, stage_shixuns, subjects - WHERE myshixuns.shixun_id = stage_shixuns.shixun_id AND stage_shixuns.subject_id = subjects.id - AND `subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%' - GROUP BY subjects.id ORDER BY myshixun_member_count DESC") + @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, + subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns + on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where + `subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%' + GROUP BY subjects.id ORDER BY myshixun_member_count DESC") end else # 我的路径 @@ -68,6 +68,8 @@ class SubjectsController < ApplicationController @subjects = @subjects.page(page).per(limit).includes(:shixuns) else @subjects = @subjects[offset, limit] + subject_ids = @subjects.pluck(:id) + @subjects = Subject.where(id: subject_ids).order("field(id,#{subject_ids.join(',')})").includes(:shixuns) end end diff --git a/app/models/subject.rb b/app/models/subject.rb index ced610377..66ac41c40 100644 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -31,7 +31,7 @@ class Subject < ApplicationRecord # 挑战过路径的成员数 def member_count - shixuns.sum(:myshixuns_count) + shixuns.pluck(:myshixuns_count).sum end def all_score From 4032174a104544866ecbadb757bccd8b25cec70a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 11 Jul 2019 11:26:23 +0800 Subject: [PATCH 0738/1015] =?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/subjects_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 34f9c2f5a..20b28121f 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -65,11 +65,11 @@ class SubjectsController < ApplicationController @total_count = @subjects.size if reorder != "myshixun_count" - @subjects = @subjects.page(page).per(limit).includes(:shixuns) + @subjects = @subjects.page(page).per(limit).includes(:shixuns, :repertoire) else @subjects = @subjects[offset, limit] subject_ids = @subjects.pluck(:id) - @subjects = Subject.where(id: subject_ids).order("field(id,#{subject_ids.join(',')})").includes(:shixuns) + @subjects = Subject.where(id: subject_ids).order("field(id,#{subject_ids.join(',')})").includes(:shixuns, :repertoire) end end From bd41f2904fdbe7198af52251c0995252b3821a4f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 11 Jul 2019 14:28:27 +0800 Subject: [PATCH 0739/1015] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E8=AF=84=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/discusses_controller.rb | 9 ++++++--- app/models/challenge.rb | 2 ++ app/models/discuss.rb | 1 + app/views/discusses/_discuss.json.jbuilder | 3 ++- ...0190711062033_modify_challenge_id_for_discusses.rb | 11 +++++++++++ 5 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20190711062033_modify_challenge_id_for_discusses.rb diff --git a/app/controllers/discusses_controller.rb b/app/controllers/discusses_controller.rb index db3047e74..f5de277b4 100644 --- a/app/controllers/discusses_controller.rb +++ b/app/controllers/discusses_controller.rb @@ -9,15 +9,18 @@ class DiscussesController < ApplicationController # 总数,分页使用 if current_user.admin? @disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count - @discusses = Discuss.limit(LIMIT).where(:dis_id => @container.id, :dis_type => @container.class.to_s, - :root_id => nil).includes(:user, :praise_treads).offset(offset) + disscusses = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, + :root_id => nil).joins(challenge: :games) + .where("discusses.user_id = games.user_id").select("discusses.*, games.identifier") else disscusses = Discuss.where("dis_id = :dis_id and dis_type = :dis_type and root_id is null and (hidden = :hidden or user_id = :user_id)", {dis_id: @container.id, dis_type: @container.class.to_s, hidden: false, user_id: current_user.id}) + .joins(challenge: :games).where("discusses.user_id = games.user_id").select("discusses.*, games.identifier") @disscuss_count = disscusses.count - @discusses = disscusses.limit(LIMIT).includes(:user, :praise_treads).offset(offset) end + @discusses = disscusses.limit(LIMIT).includes(:user, :praise_treads).offset(offset) + @manger = @container.has_manager?(current_user) @current_user = current_user end diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 7afb919a0..4d136a718 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -16,6 +16,8 @@ class Challenge < ApplicationRecord # 参考答案 has_many :challenge_answers, :dependent => :destroy has_many :exercise_bank_shixun_challenges, :dependent => :destroy + # 回复 + has_many :discusses, :dependent => :destroy # acts_as_attachable diff --git a/app/models/discuss.rb b/app/models/discuss.rb index 737a89ec1..00e3209c0 100644 --- a/app/models/discuss.rb +++ b/app/models/discuss.rb @@ -9,6 +9,7 @@ class Discuss < ApplicationRecord has_many :tidings, as: :container, dependent: :destroy has_one :praise_tread_cache, as: :object, dependent: :destroy + belongs_to :challenge after_create :send_tiding scope :children, -> (discuss_id){ where(parent_id: discuss_id).includes(:user).reorder(created_at: :asc) } diff --git a/app/views/discusses/_discuss.json.jbuilder b/app/views/discusses/_discuss.json.jbuilder index 992466559..ee9484131 100644 --- a/app/views/discusses/_discuss.json.jbuilder +++ b/app/views/discusses/_discuss.json.jbuilder @@ -9,7 +9,8 @@ json.shixun_id discuss.dis_id json.hidden discuss.hidden json.manage current_user.manager_of_shixun?(container) json.reward discuss.reward -json.game_url discuss.game_url(container, current_user) +#json.game_url discuss.game_url(container, current_user) +json.game_url "/tasks/#{discuss.identifier}" if @manger # 主贴和回复有一些不同点 if discuss.parent_id json.can_delete discuss.can_deleted?(current_user) diff --git a/db/migrate/20190711062033_modify_challenge_id_for_discusses.rb b/db/migrate/20190711062033_modify_challenge_id_for_discusses.rb new file mode 100644 index 000000000..86052375b --- /dev/null +++ b/db/migrate/20190711062033_modify_challenge_id_for_discusses.rb @@ -0,0 +1,11 @@ +class ModifyChallengeIdForDiscusses < ActiveRecord::Migration[5.2] + def change + discusses = Discuss.where(challenge_id: nil) + discusses.each do |dis| + challenge_id = Shixun.find(dis.dis_id).challenges.first.id + dis.update_column(:challenge_id, challenge_id) + end + add_index :discusses, :challenge_id + + end +end From 5af5fdc9138239fe31f39ca21bd12d5e3a603d62 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 11 Jul 2019 14:31:03 +0800 Subject: [PATCH 0740/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=AF=84=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/discusses_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/discusses_controller.rb b/app/controllers/discusses_controller.rb index f5de277b4..c09e9e285 100644 --- a/app/controllers/discusses_controller.rb +++ b/app/controllers/discusses_controller.rb @@ -17,7 +17,7 @@ class DiscussesController < ApplicationController (hidden = :hidden or user_id = :user_id)", {dis_id: @container.id, dis_type: @container.class.to_s, hidden: false, user_id: current_user.id}) .joins(challenge: :games).where("discusses.user_id = games.user_id").select("discusses.*, games.identifier") - @disscuss_count = disscusses.count + @disscuss_count = disscusses.count("discusses.id") end @discusses = disscusses.limit(LIMIT).includes(:user, :praise_treads).offset(offset) @manger = @container.has_manager?(current_user) From fc40905fdf7638380b7b2c3ef6fe3be770d67f65 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 11 Jul 2019 14:33:06 +0800 Subject: [PATCH 0741/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E6=8A=A5500?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/discusses_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/discusses_controller.rb b/app/controllers/discusses_controller.rb index c09e9e285..f100ac233 100644 --- a/app/controllers/discusses_controller.rb +++ b/app/controllers/discusses_controller.rb @@ -14,7 +14,7 @@ class DiscussesController < ApplicationController .where("discusses.user_id = games.user_id").select("discusses.*, games.identifier") else disscusses = Discuss.where("dis_id = :dis_id and dis_type = :dis_type and root_id is null and - (hidden = :hidden or user_id = :user_id)", + (discusses.hidden = :hidden or discusses.user_id = :user_id)", {dis_id: @container.id, dis_type: @container.class.to_s, hidden: false, user_id: current_user.id}) .joins(challenge: :games).where("discusses.user_id = games.user_id").select("discusses.*, games.identifier") @disscuss_count = disscusses.count("discusses.id") From 97e02718a79c3dd7b4e83b6c455cc78d978c5135 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 11 Jul 2019 15:02:57 +0800 Subject: [PATCH 0742/1015] =?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/subjects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 20b28121f..4fa818099 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -25,7 +25,7 @@ class SubjectsController < ApplicationController @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where - subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%' + 'subjects'.'hidden' = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%' AND `subjects`.`repertoire_id` = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count DESC") else @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, From c88ef3126f8f62954437a4e1ac7fb517847509eb Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 11 Jul 2019 15:09:22 +0800 Subject: [PATCH 0743/1015] =?UTF-8?q?git=20500=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/gits_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/gits_controller.rb b/app/controllers/gits_controller.rb index 1965f61ba..910864812 100644 --- a/app/controllers/gits_controller.rb +++ b/app/controllers/gits_controller.rb @@ -32,7 +32,7 @@ class GitsController < ApplicationController system_user = User.find_by_login(input_username) || User.find_by_mail(input_username) || User.find_by_phone(input_username) # 如果用户名密码错误 - if !system_user.check_password?(input_password) + if system_user && !system_user.check_password?(input_password) uid_logger_error("git start: password is wrong") result = false else From 541383ad0c1fef43b6dc05ad9ac992fb71627050 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 11 Jul 2019 15:33:54 +0800 Subject: [PATCH 0744/1015] =?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/subjects_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 4fa818099..522fffa63 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -25,8 +25,8 @@ class SubjectsController < ApplicationController @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where - 'subjects'.'hidden' = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%' - AND `subjects`.`repertoire_id` = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count DESC") + `subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%' + AND 'subjects'.'repertoire_id' = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count DESC") else @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns From a22805900d83776c6f651121077e6189ee771050 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 11 Jul 2019 15:36:42 +0800 Subject: [PATCH 0745/1015] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/discusses_controller.rb | 12 ++++++++---- app/views/discusses/_discuss.json.jbuilder | 2 +- app/views/discusses/index.json.jbuilder | 4 ++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/controllers/discusses_controller.rb b/app/controllers/discusses_controller.rb index f100ac233..c34b76a8a 100644 --- a/app/controllers/discusses_controller.rb +++ b/app/controllers/discusses_controller.rb @@ -10,17 +10,21 @@ class DiscussesController < ApplicationController if current_user.admin? @disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count disscusses = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, - :root_id => nil).joins(challenge: :games) - .where("discusses.user_id = games.user_id").select("discusses.*, games.identifier") + :root_id => nil) else disscusses = Discuss.where("dis_id = :dis_id and dis_type = :dis_type and root_id is null and (discusses.hidden = :hidden or discusses.user_id = :user_id)", {dis_id: @container.id, dis_type: @container.class.to_s, hidden: false, user_id: current_user.id}) - .joins(challenge: :games).where("discusses.user_id = games.user_id").select("discusses.*, games.identifier") @disscuss_count = disscusses.count("discusses.id") end - @discusses = disscusses.limit(LIMIT).includes(:user, :praise_treads).offset(offset) @manger = @container.has_manager?(current_user) + if @manger + @discusses = disscusses.limit(LIMIT).joins("left join games on discusses.challenge_id = games.challenge_id and discusses.user_id = games.user_id") + .select("discusses.*, games.identifier").includes(:user, :praise_treads).offset(offset) + logger.info("------#{@discusses.to_sql}") + else + @discusses = disscusses.limit(LIMIT).includes(:user, :praise_treads).offset(offset) + end @current_user = current_user end diff --git a/app/views/discusses/_discuss.json.jbuilder b/app/views/discusses/_discuss.json.jbuilder index ee9484131..7da0b7e1f 100644 --- a/app/views/discusses/_discuss.json.jbuilder +++ b/app/views/discusses/_discuss.json.jbuilder @@ -10,7 +10,7 @@ json.hidden discuss.hidden json.manage current_user.manager_of_shixun?(container) json.reward discuss.reward #json.game_url discuss.game_url(container, current_user) -json.game_url "/tasks/#{discuss.identifier}" if @manger +json.game_url "/tasks/#{discuss.identifier}" if @manger && !children # 主贴和回复有一些不同点 if discuss.parent_id json.can_delete discuss.can_deleted?(current_user) diff --git a/app/views/discusses/index.json.jbuilder b/app/views/discusses/index.json.jbuilder index 1b7a95eb3..7ddfb31fb 100644 --- a/app/views/discusses/index.json.jbuilder +++ b/app/views/discusses/index.json.jbuilder @@ -1,8 +1,8 @@ json.disscuss_count @disscuss_count json.all @current_user.admin? json.comments @discusses do |discuss| - json.partial! 'discusses/discuss', locals: { discuss: discuss, container: @container, current_user: @current_user } + json.partial! 'discusses/discuss', locals: { discuss: discuss, container: @container, current_user: @current_user, children: false} json.children discuss.child_discuss(current_user) do |c_d| - json.partial! 'discusses/discuss', locals: { discuss: c_d, container: @container, current_user: @current_user } + json.partial! 'discusses/discuss', locals: { discuss: c_d, container: @container, current_user: @current_user, children: true } end end From 1bfde5b562d615fa3fbe73638f4ef573ad270a93 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 11 Jul 2019 15:36:45 +0800 Subject: [PATCH 0746/1015] =?UTF-8?q?=E5=AE=9E=E8=B7=B5=E7=A4=BE=E5=8C=BA?= =?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/subjects_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 522fffa63..46f3b4850 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -25,13 +25,13 @@ class SubjectsController < ApplicationController @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where - `subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%' - AND 'subjects'.'repertoire_id' = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count DESC") + subjects.hidden = 0 AND subjects.status = 2 AND subjects.name like '%#{search}%' + AND subjects.repertoire_id = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count DESC") else @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where - `subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%' + subjects.hidden = 0 AND subjects.status = 2 AND subjects.name like '%#{search}%' GROUP BY subjects.id ORDER BY myshixun_member_count DESC") end else From c3ef1d85a495ee6eebc4544df5e949a7ff1c59ab Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 11 Jul 2019 15:39:43 +0800 Subject: [PATCH 0747/1015] 1 --- app/controllers/discusses_controller.rb | 5 ++--- app/views/discusses/_discuss.json.jbuilder | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/discusses_controller.rb b/app/controllers/discusses_controller.rb index c34b76a8a..c5cb6814d 100644 --- a/app/controllers/discusses_controller.rb +++ b/app/controllers/discusses_controller.rb @@ -20,10 +20,9 @@ class DiscussesController < ApplicationController @manger = @container.has_manager?(current_user) if @manger @discusses = disscusses.limit(LIMIT).joins("left join games on discusses.challenge_id = games.challenge_id and discusses.user_id = games.user_id") - .select("discusses.*, games.identifier").includes(:user, :praise_treads).offset(offset) - logger.info("------#{@discusses.to_sql}") + .select("discusses.*, games.identifier").includes(:praise_treads).offset(offset) else - @discusses = disscusses.limit(LIMIT).includes(:user, :praise_treads).offset(offset) + @discusses = disscusses.limit(LIMIT).includes(:praise_treads).offset(offset) end @current_user = current_user diff --git a/app/views/discusses/_discuss.json.jbuilder b/app/views/discusses/_discuss.json.jbuilder index 7da0b7e1f..3cd42439f 100644 --- a/app/views/discusses/_discuss.json.jbuilder +++ b/app/views/discusses/_discuss.json.jbuilder @@ -9,8 +9,8 @@ json.shixun_id discuss.dis_id json.hidden discuss.hidden json.manage current_user.manager_of_shixun?(container) json.reward discuss.reward -#json.game_url discuss.game_url(container, current_user) -json.game_url "/tasks/#{discuss.identifier}" if @manger && !children +json.game_url discuss.game_url(container, current_user) +#json.game_url "/tasks/#{discuss.identifier}" if @manger && !children # 主贴和回复有一些不同点 if discuss.parent_id json.can_delete discuss.can_deleted?(current_user) From 462929292732ec745aa12f14aaa590f366c028b3 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 11 Jul 2019 15:40:44 +0800 Subject: [PATCH 0748/1015] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/discusses/_discuss.json.jbuilder | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/discusses/_discuss.json.jbuilder b/app/views/discusses/_discuss.json.jbuilder index 3cd42439f..7da0b7e1f 100644 --- a/app/views/discusses/_discuss.json.jbuilder +++ b/app/views/discusses/_discuss.json.jbuilder @@ -9,8 +9,8 @@ json.shixun_id discuss.dis_id json.hidden discuss.hidden json.manage current_user.manager_of_shixun?(container) json.reward discuss.reward -json.game_url discuss.game_url(container, current_user) -#json.game_url "/tasks/#{discuss.identifier}" if @manger && !children +#json.game_url discuss.game_url(container, current_user) +json.game_url "/tasks/#{discuss.identifier}" if @manger && !children # 主贴和回复有一些不同点 if discuss.parent_id json.can_delete discuss.can_deleted?(current_user) From 10143e40c384a27e2074b6cb1a171b413f6da390 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 11 Jul 2019 15:42:23 +0800 Subject: [PATCH 0749/1015] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=AF=84=E8=AE=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/discusses/_discuss.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/discusses/_discuss.json.jbuilder b/app/views/discusses/_discuss.json.jbuilder index 7da0b7e1f..400798150 100644 --- a/app/views/discusses/_discuss.json.jbuilder +++ b/app/views/discusses/_discuss.json.jbuilder @@ -7,7 +7,7 @@ json.time time_from_now(discuss.created_at) json.position discuss.position json.shixun_id discuss.dis_id json.hidden discuss.hidden -json.manage current_user.manager_of_shixun?(container) +json.manage @manger json.reward discuss.reward #json.game_url discuss.game_url(container, current_user) json.game_url "/tasks/#{discuss.identifier}" if @manger && !children From c87f58bc73954c3a0c7cadfc1dc13b602bf02be2 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 11 Jul 2019 15:57:11 +0800 Subject: [PATCH 0750/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E5=9B=9E=E5=A4=8D'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/discusses_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/discusses_controller.rb b/app/controllers/discusses_controller.rb index c5cb6814d..3b987be51 100644 --- a/app/controllers/discusses_controller.rb +++ b/app/controllers/discusses_controller.rb @@ -20,9 +20,9 @@ class DiscussesController < ApplicationController @manger = @container.has_manager?(current_user) if @manger @discusses = disscusses.limit(LIMIT).joins("left join games on discusses.challenge_id = games.challenge_id and discusses.user_id = games.user_id") - .select("discusses.*, games.identifier").includes(:praise_treads).offset(offset) + .select("discusses.*, games.identifier").includes(:user, :praise_treads).offset(offset) else - @discusses = disscusses.limit(LIMIT).includes(:praise_treads).offset(offset) + @discusses = disscusses.limit(LIMIT).includes(:user, :praise_treads).offset(offset) end @current_user = current_user From 5c680a9a93825653495ee7931a9e27df4def9463 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 11 Jul 2019 16:05:30 +0800 Subject: [PATCH 0751/1015] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8E=92=E8=A1=8C?= =?UTF-8?q?=E6=A6=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index c237da5e2..e4d18316e 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -129,7 +129,7 @@ class ShixunsController < ApplicationController select m.user_id, u.login, u.lastname, m.updated_at, (select sum(cost_time) from games g where g.myshixun_id = m.id) as time, (select sum(final_score) from games g where g.myshixun_id = m.id) as score - from (myshixuns m join users u on m.user_id = u.id) where m.shixun_id = #{@shixun.id} and m.status = 1 + from (users u left join myshixuns m on m.user_id = u.id) where m.shixun_id = #{@shixun.id} and m.status = 1 order by score desc, time asc limit 10 " @myshixuns = Myshixun.find_by_sql(sql) From 35bbc0fe7bbd164a4bae643d165a397395bfb21c Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 11 Jul 2019 16:07:00 +0800 Subject: [PATCH 0752/1015] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E4=BD=9C=E5=93=81?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= 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 9b62f7dbd..fd6a1d859 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -55,6 +55,8 @@ class GraduationTasksController < ApplicationController page = params[:page] || 1 limit = params[:limit] || 20 @work = @task.graduation_works.where(user_id: current_user.id) + @students = @course.students + @assign_power = @user_course_identity < Course::STUDENT && @task.cross_comment && @task.comment_status == 2 #end_time @task.allow_late ? @task.late_time : @task.end_time # 任务发布的情况下: 是老师身份或者任务已截止的情况下公开任务了作品设置的学生也能查看其他人的作品 if @task.published? && (@user_course_identity < Course::STUDENT || @@ -123,8 +125,6 @@ class GraduationTasksController < ApplicationController @work_count = @work_list.count @work_excel = @work_list @work_list = @work_list.page(page).per(limit) - @students = @course.students - @assign_power = @user_course_identity < Course::STUDENT && @task.cross_comment && @task.comment_status == 2 if params[:format] == "xlsx" complete_works = @work_excel.where("work_status > 0").size From 05a7b9cdfce7471da3d8a931d188f5ccafbbf310 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 11 Jul 2019 16:21:30 +0800 Subject: [PATCH 0753/1015] =?UTF-8?q?=E9=82=AE=E7=AE=B1=E4=B8=8D=E6=9A=B4?= =?UTF-8?q?=E9=9C=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shixuns/_commit.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shixuns/_commit.json.jbuilder b/app/views/shixuns/_commit.json.jbuilder index b752affb6..f6587c261 100644 --- a/app/views/shixuns/_commit.json.jbuilder +++ b/app/views/shixuns/_commit.json.jbuilder @@ -16,7 +16,7 @@ json.commits commits do |commit| json.login nil json.image_url "avatars/User/b" json.name commit["author_name"] - json.email commit["author_email"] + # json.email commit["author_email"] end end end From 14aadb37b5a75e620d64760fc1640e312f55f6fd Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 11 Jul 2019 16:22:10 +0800 Subject: [PATCH 0754/1015] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/graduation_tasks/tasks_list.json.jbuilder | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/views/graduation_tasks/tasks_list.json.jbuilder b/app/views/graduation_tasks/tasks_list.json.jbuilder index ac5aa050e..8ee2f78af 100644 --- a/app/views/graduation_tasks/tasks_list.json.jbuilder +++ b/app/views/graduation_tasks/tasks_list.json.jbuilder @@ -26,6 +26,9 @@ if @task.published? || @user_course_identity < Course::STUDENT # 是否具有分组 json.have_grouping @task.have_grouping? + # 是否关联项目 + json.have_project @task.have_grouping? && @task.base_on_project + if @user_course_identity == Course::STUDENT json.commit_count grduationwork_count @task, 1 json.uncommit_count grduationwork_count @task, 0 From aa4dbf0f06ce1904adf0d9f25c35f3b4feddfa34 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 11 Jul 2019 16:31:18 +0800 Subject: [PATCH 0755/1015] account manange not check profile complete --- app/controllers/users/base_account_controller.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/controllers/users/base_account_controller.rb b/app/controllers/users/base_account_controller.rb index b693eaab5..29de52b26 100644 --- a/app/controllers/users/base_account_controller.rb +++ b/app/controllers/users/base_account_controller.rb @@ -4,4 +4,12 @@ class Users::BaseAccountController < Users::BaseController def observed_user @_observed_user ||= (User.find_by_id(params[:account_id]) || User.find_by_login(params[:account_id])) end + + private + + def require_login + return if User.current.logged? + + tip_exception(401, "..") + end end From a50cbc9e0bd4274208dbb0674c437ef913ef404d Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 11 Jul 2019 16:35:34 +0800 Subject: [PATCH 0756/1015] fix --- app/controllers/users/accounts_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users/accounts_controller.rb b/app/controllers/users/accounts_controller.rb index e88ff4564..dff5115e1 100644 --- a/app/controllers/users/accounts_controller.rb +++ b/app/controllers/users/accounts_controller.rb @@ -1,4 +1,4 @@ -class Users::AccountsController < Users::BaseController +class Users::AccountsController < Users::BaseAccountController before_action :private_user_resources! def show From 2f5f0cef16da9201934e34513dd9fd51310ea7ab Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 11 Jul 2019 16:36:10 +0800 Subject: [PATCH 0757/1015] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 6ffc7f0ce..929af8f47 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -710,10 +710,10 @@ class GamesController < ApplicationController resubmit_identifier = @game.resubmit_identifier # 如果没有超时并且正在评测中 # 判断评测中的状态有两种:1、如果之前没有通关的,只需判断status为1即可;如果通过关,则判断game的resubmit_identifier是否更新 - uid_logger("################game_status: #{@game.status}") - uid_logger("################params[:resubmit]: #{params[:resubmit]}") - uid_logger("################resubmit_identifier: #{resubmit_identifier}") - uid_logger("################time_out: #{params[:time_out]}") + # uid_logger("################game_status: #{@game.status}") + # uid_logger("################params[:resubmit]: #{params[:resubmit]}") + # uid_logger("################resubmit_identifier: #{resubmit_identifier}") + # uid_logger("################time_out: #{params[:time_out]}") if (params[:time_out] == "false") && ((params[:resubmit].blank? && @game.status == 1) || (params[:resubmit].present? && (params[:resubmit] != resubmit_identifier))) # 代码评测的信息 From e929ec427ed780a8ba7ea32839c45dd75b6e22f8 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 19 Jul 2019 01:03:44 +0800 Subject: [PATCH 0758/1015] =?UTF-8?q?job=E4=BB=BB=E5=8A=A1=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/course_member.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/course_member.rb b/app/models/course_member.rb index 52c13dbbf..65849e5de 100644 --- a/app/models/course_member.rb +++ b/app/models/course_member.rb @@ -148,7 +148,7 @@ class CourseMember < ApplicationRecord if teacher_groups.count > 0 member_ids = teacher_groups.where(course_group_id: self.try(:course_group_id)).pluck(:course_member_id).compact - none_group_teachers = teacher_groups.pluck(:course_member_id).size > 0 ? teacher_groups.pluck(:course_member_id).compact.join(',') : -1 + none_group_teachers = teacher_groups.pluck(:course_member_id).compact.size > 0 ? teacher_groups.pluck(:course_member_id).compact.join(',') : -1 teachers = course.teachers.where("course_members.id not in (#{none_group_teachers}) or course_members.id in (#{member_ids.size > 0 ? member_ids.join(',') : -1})") else From 2c143af77446adc8c24f28640db3776979f34afb Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 13 Jul 2019 10:30:22 +0800 Subject: [PATCH 0759/1015] =?UTF-8?q?sidekiq=E7=9B=91=E6=8E=A7=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E5=8A=A0=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/constraint/admin_constraint.rb | 7 +++++++ config/routes.rb | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 app/constraint/admin_constraint.rb diff --git a/app/constraint/admin_constraint.rb b/app/constraint/admin_constraint.rb new file mode 100644 index 000000000..3ddf9a11e --- /dev/null +++ b/app/constraint/admin_constraint.rb @@ -0,0 +1,7 @@ +class AdminConstraint + def matches?(request) + return false unless request.session[:user_id] + user = User.find request.session[:user_id] + user && user.admin? + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 7e34363d1..d9e10e4cc 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,8 @@ Rails.application.routes.draw do require 'sidekiq/web' - mount Sidekiq::Web => '/sidekiq' + require 'admin_constraint' + mount Sidekiq::Web => '/sidekiq', :constraints => AdminConstraint.new resources :edu_settings scope '/api' do From 9028cc193e49f647c1b22a9e9361933b5c62aabd Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 13 Jul 2019 11:07:01 +0800 Subject: [PATCH 0760/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E9=99=84=E4=BB=B6?= =?UTF-8?q?=E6=89=80=E6=9C=89Markdown=E5=9B=BE=E7=89=87=E7=9A=84=E7=9A=84u?= =?UTF-8?q?rl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...modify_md_attachment_url_for_md_cotents.rb | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 db/migrate/20190713022300_modify_md_attachment_url_for_md_cotents.rb diff --git a/db/migrate/20190713022300_modify_md_attachment_url_for_md_cotents.rb b/db/migrate/20190713022300_modify_md_attachment_url_for_md_cotents.rb new file mode 100644 index 000000000..188e017a5 --- /dev/null +++ b/db/migrate/20190713022300_modify_md_attachment_url_for_md_cotents.rb @@ -0,0 +1,30 @@ +class ModifyMdAttachmentUrlForMdCotents < ActiveRecord::Migration[5.2] + def change + # 更新MarkDown图片的URL + homework_commons = HomeworkCommon.all + homework_commons.find_each do |hc| + hc.update_column(:description, hc.description.gsub("![](/attachments/download", "![](/api/attachments")) if hc.description.present? + end + + challenges = Challenge.all.unscoped + challenges.find_each do |c| + c.update_column(:task_pass, c.task_pass.gsub("![](/attachments/download", "![](/api/attachments")) if c.task_pass.present? + end + + challenge_answers = ChallengeAnswer.all.unscoped + challenge_answers.find_each do |ca| + ca.update_column(:contents, ca.contents.gsub("![](/attachments/download", "![](/api/attachments")) if ca.contents.present? + end + + shixun_infos = ShixunInfo.all + shixun_infos.find_each do |si| + si.update_column(:propaedeutics, si.propaedeutics.gsub("![](/attachments/download", "![](/api/attachments")) if si.propaedeutics.present? + si.update_column(:description, si.description.gsub("![](/attachments/download", "![](/api/attachments")) if si.description.present? + end + + subjects = Subject.all + subjects.find_each do |s| + s.update_column(:description, s.description.gsub("![](/attachments/download", "![](/api/attachments")) if s.description.present? + end + end +end From be855c5920d5fab0bc9591f85871804e1c901872 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 13 Jul 2019 13:50:28 +0800 Subject: [PATCH 0761/1015] =?UTF-8?q?=E6=B3=A8=E5=86=8C=E5=90=8E=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index d3808a06b..d3d46b28d 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -52,6 +52,8 @@ class AccountsController < ApplicationController container_type: pre == 'p' ? 'Phone' : 'Mail', score: 500 ) + successful_authentication(@user) + session[:user_id] = @user.id end rescue Exception => e uid_logger_error(e.message) From af59295d6ca58b6b7d09a6734b47347578879337 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 13 Jul 2019 14:41:41 +0800 Subject: [PATCH 0762/1015] =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=AE=A4=E8=AF=81?= =?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/controllers/application_controller.rb | 55 ++++++----------------- 1 file changed, 14 insertions(+), 41 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e6c0116fc..c9c2d90e8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -147,20 +147,7 @@ class ApplicationController < ActionController::Base # 前端会捕捉401,弹登录弹框 # 未授权的捕捉407,弹试用申请弹框 def require_login - #6.13 -hs - if User.current.logged? - if !current_user.profile_completed? - info_url = "#{edu_setting('old_edu_host')}/account/user_info" - tip_exception(402, info_url) - # render :json => { status: 402, url: info_url } - elsif current_user.certification != 1 - day_cer = UserDayCertification.where(user_id: current_user.id).last - tip_exception(407, "系统未授权") unless (Time.now.to_i - day_cer.try(:created_at).to_i) < 86400 - end - else - tip_exception(401, "..") - end - + tip_exception(401, "..") unless User.current.logged? end # 异常提醒 @@ -190,33 +177,19 @@ class ApplicationController < ActionController::Base # 系统全局认证 # def check_auth - # old_edu_host = edu_setting('old_edu_host') - # ue = current_user.user_extension - # - # if current_user.lastname.blank? || ue.school_id.blank? || ue.identity.blank? || current_user.mail.blank? - # info_url = old_edu_host + '/account/user_info' - # render :json => { status: 402, url: info_url } - # elsif current_user.certification != 1 - # day_cer = UserDayCertification.where(user_id: current_user.id).last - # unless (Time.now.to_i - day_cer.try(:created_at).to_i) < 86400 - # account_url = old_edu_host + "/my/account" - # render :json => { status: 402, url: account_url } - # end - # end - true - end - - # 身份资料的认证: - # 如果试用过期则弹框提示认证,先跳入个人资料页面完善资料,资料完成后,弹框提醒用户试用申请 - def check_account - # # todo user_extension - # if User.current.logged? - # ue = current_user.user_extension - # if current_user.lastname.blank? || ue.school_id.blank? || ue.identity.blank? || current_user.mail.blank? - # info_url = "#{edu_setting('old_edu_host')}/account/user_info" - # render :json => { status: 402, url: info_url } - # end - # end + if User.current.logged? + if !current_user.profile_completed? + info_url = '/account/user_info' + tip_exception(402, info_url) + elsif current_user.certification != 1 + day_cer = UserDayCertification.where(user_id: current_user.id).last + unless (Time.now.to_i - day_cer.try(:created_at).to_i) < 86400 + tip_exception(407, "系统未授权") + end + end + else + tip_exception(401, "..") + end end def start_user_session(user) From 0061eff0f2a9511fd68322918cc77ce5b39bf63e Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 13 Jul 2019 14:53:18 +0800 Subject: [PATCH 0763/1015] =?UTF-8?q?=E6=9C=AA=E7=99=BB=E5=BD=95=E6=88=96?= =?UTF-8?q?=E8=80=85=E6=9C=AA=E6=B3=A8=E5=86=8C=E5=85=81=E8=AE=B8=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E5=AE=9E=E8=AE=AD=E9=A6=96=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index e4d18316e..3b3e0478a 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -1,6 +1,6 @@ class ShixunsController < ApplicationController before_action :require_login, except: [:download_file, :index, :menus] - before_action :check_auth, except: [:download_file, :index] + before_action :check_auth, except: [:download_file, :index, :menus] before_action :find_shixun, :shixun_access_allowed, except: [:index, :new, :create, :menus, :get_recommend_shixuns, :propaedeutics, :departments, :apply_shixun_mirror, From fbdd7b0a718aa0d808d4ae5849e8b62d7f6398b3 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 13 Jul 2019 14:59:23 +0800 Subject: [PATCH 0764/1015] =?UTF-8?q?=E5=8F=91=E9=80=81=E7=9F=AD=E4=BF=A1?= =?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 --- lib/educoder/sms.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/educoder/sms.rb b/lib/educoder/sms.rb index 237b270d5..5ba273aa8 100644 --- a/lib/educoder/sms.rb +++ b/lib/educoder/sms.rb @@ -28,6 +28,8 @@ module Educoder def self.sendYunpian(mobile, code, send_type, name, user_name, result) #修改为您的apikey.可在官网(http://www.yunpian.com)登录后用户中心首页看到 apikey = EduSetting.get('sms_apikey') + Rails.logger.info("#####apikey: #{apikey}") + Rails.logger.info("#####mobile: #{mobile}") #指定模板发送接口HTTP地址 send_tpl_sms_uri = URI.parse('https://sms.yunpian.com/v2/sms/single_send.json') @@ -70,6 +72,7 @@ module Educoder response = http.start { |http| http.request(request) } ActiveSupport::JSON.decode(response.body) rescue =>err + Rails.logger.error("#############sendYunpian_error: #{err.message}") return nil end end From cb0ce291a13ac614530bddc70f6403a8770e3f19 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 13 Jul 2019 15:15:31 +0800 Subject: [PATCH 0765/1015] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/educoder/sms.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/educoder/sms.rb b/lib/educoder/sms.rb index 5ba273aa8..cadce7465 100644 --- a/lib/educoder/sms.rb +++ b/lib/educoder/sms.rb @@ -28,8 +28,6 @@ module Educoder def self.sendYunpian(mobile, code, send_type, name, user_name, result) #修改为您的apikey.可在官网(http://www.yunpian.com)登录后用户中心首页看到 apikey = EduSetting.get('sms_apikey') - Rails.logger.info("#####apikey: #{apikey}") - Rails.logger.info("#####mobile: #{mobile}") #指定模板发送接口HTTP地址 send_tpl_sms_uri = URI.parse('https://sms.yunpian.com/v2/sms/single_send.json') From d6bf075d49af1b61b04cdb83b58763063e00674a Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 13 Jul 2019 15:28:17 +0800 Subject: [PATCH 0766/1015] =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=AE=A4=E8=AF=81u?= =?UTF-8?q?rl=E8=A7=84=E8=8C=83=E5=8F=8A=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c9c2d90e8..b8fe7d723 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -179,7 +179,7 @@ class ApplicationController < ActionController::Base def check_auth if User.current.logged? if !current_user.profile_completed? - info_url = '/account/user_info' + info_url = '/account/profile' tip_exception(402, info_url) elsif current_user.certification != 1 day_cer = UserDayCertification.where(user_id: current_user.id).last From 2dc1255abf32354d13180c6f85d5ddccb7294116 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 13 Jul 2019 15:40:18 +0800 Subject: [PATCH 0767/1015] =?UTF-8?q?=E6=B3=A8=E5=86=8C=E5=90=8E=E7=9A=84?= =?UTF-8?q?=E4=B8=80=E5=A4=A9=E8=AF=95=E7=94=A8=E7=94=B3=E8=AF=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 3 +++ app/controllers/application_controller.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index d3d46b28d..e2df181f0 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -109,6 +109,9 @@ class AccountsController < ApplicationController set_autologin_cookie(user) UserAction.create(:action_id => user.try(:id), :action_type => "Login", :user_id => user.try(:id)) + + # 注册完成后有一天的试用申请 + UserDayCertification.create(user_id: user.id, status: 1) end def set_autologin_cookie(user) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e6c0116fc..0a76fa624 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -154,7 +154,7 @@ class ApplicationController < ActionController::Base tip_exception(402, info_url) # render :json => { status: 402, url: info_url } elsif current_user.certification != 1 - day_cer = UserDayCertification.where(user_id: current_user.id).last + day_cer = UserDayCertification.find_by(user_id: current_user.id) tip_exception(407, "系统未授权") unless (Time.now.to_i - day_cer.try(:created_at).to_i) < 86400 end else From c48ed86bc76658ac91a1c889a988b8a045723bfc Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 13 Jul 2019 15:48:54 +0800 Subject: [PATCH 0768/1015] add . --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index b8fe7d723..48ea8eb59 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -210,7 +210,7 @@ class ApplicationController < ActionController::Base end if params[:debug] == 'teacher' #todo 为了测试,记得讲debug删除 - User.current = User.find 49610 + User.current = User.find_by_phone("153880833362") elsif params[:debug] == 'student' User.current = User.find 8686 elsif params[:debug] == 'admin' From 80fa5538663a7f24d9f8ef96bf6aa72835a80e45 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 13 Jul 2019 15:57:02 +0800 Subject: [PATCH 0769/1015] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 3bdd0d1b0..6a85984ca 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -211,7 +211,7 @@ class ApplicationController < ActionController::Base end if params[:debug] == 'teacher' #todo 为了测试,记得讲debug删除 - User.current = User.find_by_phone("153880833362") + User.current = User.find 81403 elsif params[:debug] == 'student' User.current = User.find 8686 elsif params[:debug] == 'admin' From 6bbb8e050e1e0f22456bfb98b8ea88b5ed06c40d Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 13 Jul 2019 16:10:01 +0800 Subject: [PATCH 0770/1015] =?UTF-8?q?..=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6a85984ca..5336e20c1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -210,13 +210,15 @@ class ApplicationController < ActionController::Base User.current = User.find 12 end - if params[:debug] == 'teacher' #todo 为了测试,记得讲debug删除 - User.current = User.find 81403 - elsif params[:debug] == 'student' - User.current = User.find 8686 - elsif params[:debug] == 'admin' - User.current = User.find 1 - end + User.current = User.find 81403 + + # if params[:debug] == 'teacher' #todo 为了测试,记得讲debug删除 + # User.current = User.find 81403 + # elsif params[:debug] == 'student' + # User.current = User.find 8686 + # elsif params[:debug] == 'admin' + # User.current = User.find 1 + # end end # Sets the logged in user From 85b2db7ac104114b11eb7fa13f4eee89e0348c6f Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 13 Jul 2019 16:26:52 +0800 Subject: [PATCH 0771/1015] =?UTF-8?q?=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 18 +++++++++--------- app/controllers/challenges_controller.rb | 1 + 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5336e20c1..f38541f12 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -210,15 +210,15 @@ class ApplicationController < ActionController::Base User.current = User.find 12 end - User.current = User.find 81403 - - # if params[:debug] == 'teacher' #todo 为了测试,记得讲debug删除 - # User.current = User.find 81403 - # elsif params[:debug] == 'student' - # User.current = User.find 8686 - # elsif params[:debug] == 'admin' - # User.current = User.find 1 - # end + # User.current = User.find 81403 + + if params[:debug] == 'teacher' #todo 为了测试,记得讲debug删除 + User.current = User.find 81403 + elsif params[:debug] == 'student' + User.current = User.find 8686 + elsif params[:debug] == 'admin' + User.current = User.find 1 + end end # Sets the logged in user diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 33963a192..36b0e66d3 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -1,5 +1,6 @@ class ChallengesController < ApplicationController before_action :require_login + before_action :check_auth before_action :find_shixun, only: [:new, :create, :index] skip_before_action :verify_authenticity_token, only: [:create, :update, :create_choose_question, :crud_answer] before_action :find_challenge, only: [:edit, :show, :update, :create_choose_question, :index_down, :index_up, From 689600314b1ba1db3802c6c0dcf2e493e39f87fb Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 15 Jul 2019 08:51:05 +0800 Subject: [PATCH 0772/1015] =?UTF-8?q?=E7=99=BB=E5=BD=95=E4=B8=8E=E8=AE=A4?= =?UTF-8?q?=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../add_department_applies_controller.rb | 2 +- .../add_school_applies_controller.rb | 2 +- app/controllers/application_controller.rb | 18 ++++++------------ app/controllers/attachments_controller.rb | 2 +- app/controllers/boards_controller.rb | 2 +- app/controllers/challenges_controller.rb | 2 +- app/controllers/commons_controller.rb | 2 +- app/controllers/course_groups_controller.rb | 2 +- app/controllers/course_modules_controller.rb | 2 +- .../course_second_categories_controller.rb | 2 +- app/controllers/courses_controller.rb | 2 +- app/controllers/ecs/base_controller.rb | 2 +- app/controllers/exercise_answers_controller.rb | 2 +- .../exercise_questions_controller.rb | 2 +- app/controllers/exercises_controller.rb | 2 +- app/controllers/files_controller.rb | 2 +- app/controllers/games_controller.rb | 2 +- app/controllers/graduation_tasks_controller.rb | 2 +- .../graduation_topics_controller.rb | 2 +- app/controllers/graduation_works_controller.rb | 2 +- app/controllers/homework_commons_controller.rb | 2 +- app/controllers/messages_controller.rb | 2 +- app/controllers/myshixuns_controller.rb | 2 +- app/controllers/poll_questions_controller.rb | 2 +- app/controllers/poll_votes_controller.rb | 2 +- app/controllers/polls_controller.rb | 2 +- app/controllers/praise_tread_controller.rb | 2 +- app/controllers/question_banks_controller.rb | 2 +- app/controllers/shixuns_controller.rb | 2 +- app/controllers/stages_controller.rb | 2 +- app/controllers/student_works_controller.rb | 2 +- app/controllers/subjects_controller.rb | 2 +- .../users/base_account_controller.rb | 2 +- app/controllers/users/interests_controller.rb | 2 +- app/controllers/users/watches_controller.rb | 2 +- app/controllers/zips_controller.rb | 2 +- 36 files changed, 41 insertions(+), 47 deletions(-) diff --git a/app/controllers/add_department_applies_controller.rb b/app/controllers/add_department_applies_controller.rb index ed8067c84..644ebd87e 100644 --- a/app/controllers/add_department_applies_controller.rb +++ b/app/controllers/add_department_applies_controller.rb @@ -1,5 +1,5 @@ class AddDepartmentAppliesController < ApplicationController - before_action :require_login + before_action :require_login, :check_auth def create CreateAddDepartmentApplyService.call(current_user, create_params) diff --git a/app/controllers/add_school_applies_controller.rb b/app/controllers/add_school_applies_controller.rb index 9f2376b9e..c868d79c9 100644 --- a/app/controllers/add_school_applies_controller.rb +++ b/app/controllers/add_school_applies_controller.rb @@ -1,5 +1,5 @@ class AddSchoolAppliesController < ApplicationController - before_action :require_login + before_action :require_login, :check_auth def create CreateAddSchoolApplyService.call(current_user, create_params) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 91ac1c282..e8cccaee3 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -178,18 +178,12 @@ class ApplicationController < ActionController::Base # 系统全局认证 # def check_auth - if User.current.logged? - if !current_user.profile_completed? - info_url = '/account/profile' - tip_exception(402, info_url) - elsif current_user.certification != 1 - day_cer = UserDayCertification.find_by(user_id: current_user.id) - unless (Time.now.to_i - day_cer.try(:created_at).to_i) < 86400 - tip_exception(407, "系统未授权") - end - end - else - tip_exception(401, "..") + if !current_user.profile_completed? + info_url = '/account/profile' + tip_exception(402, info_url) + elsif current_user.certification != 1 + day_cer = UserDayCertification.find_by(user_id: current_user.id) + tip_exception(407, "系统未授权") unless (Time.now.to_i - day_cer.try(:created_at).to_i) < 86400 end end diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index bf5c11856..c539b0a60 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -2,7 +2,7 @@ # # 文件上传 class AttachmentsController < ApplicationController - before_action :require_login + before_action :require_login, :check_auth before_action :find_file, only: %i[show destroy] include ErrorCommon diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index 2e82c36d7..0bcaaa2c0 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -1,5 +1,5 @@ class BoardsController < ApplicationController - before_action :require_login + before_action :require_login, :check_auth before_action :find_course, only: [:create] before_action :set_board, except: [:create] before_action :teacher_allowed diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 33963a192..697585e0c 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -1,5 +1,5 @@ class ChallengesController < ApplicationController - before_action :require_login + before_action :require_login, :check_auth before_action :find_shixun, only: [:new, :create, :index] skip_before_action :verify_authenticity_token, only: [:create, :update, :create_choose_question, :crud_answer] before_action :find_challenge, only: [:edit, :show, :update, :create_choose_question, :index_down, :index_up, diff --git a/app/controllers/commons_controller.rb b/app/controllers/commons_controller.rb index a23d4dba7..0c0fe79af 100644 --- a/app/controllers/commons_controller.rb +++ b/app/controllers/commons_controller.rb @@ -1,7 +1,7 @@ class CommonsController < ApplicationController OBJECT_TYPE = %W[message journals_for_message] - before_action :require_login + before_action :require_login, :check_auth before_action :validate_object_type before_action :find_object before_action :validate_power diff --git a/app/controllers/course_groups_controller.rb b/app/controllers/course_groups_controller.rb index bee3fa09d..0e16d1bac 100644 --- a/app/controllers/course_groups_controller.rb +++ b/app/controllers/course_groups_controller.rb @@ -1,5 +1,5 @@ class CourseGroupsController < ApplicationController - before_action :require_login + before_action :require_login, :check_auth before_action :set_group, except: [:create] before_action :find_course, only: [:create] before_action :teacher_or_admin_allowed diff --git a/app/controllers/course_modules_controller.rb b/app/controllers/course_modules_controller.rb index d8d4ea128..4e9f7b908 100644 --- a/app/controllers/course_modules_controller.rb +++ b/app/controllers/course_modules_controller.rb @@ -1,5 +1,5 @@ class CourseModulesController < ApplicationController - before_action :require_login + before_action :require_login, :check_auth before_action :set_module, except: [:unhidden_modules] before_action :find_course, only: [:unhidden_modules] before_action :teacher_allowed diff --git a/app/controllers/course_second_categories_controller.rb b/app/controllers/course_second_categories_controller.rb index d0f07f47f..ca544a584 100644 --- a/app/controllers/course_second_categories_controller.rb +++ b/app/controllers/course_second_categories_controller.rb @@ -1,5 +1,5 @@ class CourseSecondCategoriesController < ApplicationController - before_action :require_login + before_action :require_login, :check_auth before_action :set_category before_action :teacher_allowed diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index e6c4ae330..286935c17 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -11,7 +11,7 @@ class CoursesController < ApplicationController render_error(ex.model.errors.full_messages.join(',')) end - before_action :require_login, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups, :left_banner, :top_banner] + before_action :require_login, :check_auth, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups, :left_banner, :top_banner] before_action :set_course, :user_course_identity, only: [:show, :update, :destroy, :settings, :set_invite_code_halt, :set_public_or_private, :search_teacher_candidate, :teachers, :apply_teachers, :top_banner, :left_banner, :add_teacher_popup, :add_teacher, diff --git a/app/controllers/ecs/base_controller.rb b/app/controllers/ecs/base_controller.rb index 9fb99c420..2cded249a 100644 --- a/app/controllers/ecs/base_controller.rb +++ b/app/controllers/ecs/base_controller.rb @@ -1,6 +1,6 @@ class Ecs::BaseController < ApplicationController - before_action :require_login + before_action :require_login, :check_auth before_action :check_user_permission! helper_method :current_user, :current_school diff --git a/app/controllers/exercise_answers_controller.rb b/app/controllers/exercise_answers_controller.rb index aa3966d25..27e4aba11 100644 --- a/app/controllers/exercise_answers_controller.rb +++ b/app/controllers/exercise_answers_controller.rb @@ -1,5 +1,5 @@ class ExerciseAnswersController < ApplicationController - before_action :require_login + before_action :require_login, :check_auth before_action :get_exercise_question include ExercisesHelper diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index e33e5e2dc..3d488c7b0 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -1,5 +1,5 @@ class ExerciseQuestionsController < ApplicationController - before_action :require_login #用户需登陆 + before_action :require_login, :check_auth #用户需登陆 before_action :get_exercise,only:[:new,:create] #获取试卷 before_action :get_exercise_question,except: [:new,:create] #获取试卷的问题及试卷 before_action :is_course_teacher #是否为老师 diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 6af48dbd1..862166f00 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1,5 +1,5 @@ class ExercisesController < ApplicationController - before_action :require_login,except: [:index] + before_action :require_login, :check_auth, except: [:index] before_action :find_course,only: [:index,:new,:create,:my_exercises,:public_exercises,:set_public,:destroys, :join_exercise_banks,:publish_modal,:publish,:end_modal,:end_exercise] #需要有课堂id参数的 before_action :get_exercise,except: [:index,:new,:create,:my_exercises,:public_exercises,:set_public,:destroys, diff --git a/app/controllers/files_controller.rb b/app/controllers/files_controller.rb index b75020643..d090ae253 100644 --- a/app/controllers/files_controller.rb +++ b/app/controllers/files_controller.rb @@ -1,7 +1,7 @@ class FilesController < ApplicationController include MessagesHelper - before_action :require_login, except: %i[index] + before_action :require_login, :check_auth, except: %i[index] before_action :find_course, except: %i[public_with_course_and_project mine_with_course_and_project] before_action :find_ids, only: %i[bulk_delete bulk_send bulk_move bulk_public bulk_publish] before_action :file_validate_sort_type, only: :index diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 929af8f47..217f1839a 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -1,5 +1,5 @@ class GamesController < ApplicationController - before_action :require_login + before_action :require_login, :check_auth before_action :find_game before_action :find_shixun, only: [:show, :answer, :rep_content, :choose_build, :game_build, :game_status] diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index fd6a1d859..fc9c8df45 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -1,5 +1,5 @@ class GraduationTasksController < ApplicationController - before_action :require_login, except: [:index] + before_action :require_login, :check_auth, except: [:index] before_action :find_course, except: [:edit, :update, :settings, :update_settings, :tasks_list, :show, :show_comment] before_action :find_task, only: [:edit, :update, :settings, :update_settings, :tasks_list, :show, :show_comment] before_action :user_course_identity diff --git a/app/controllers/graduation_topics_controller.rb b/app/controllers/graduation_topics_controller.rb index 4ad07c77e..754b472c5 100644 --- a/app/controllers/graduation_topics_controller.rb +++ b/app/controllers/graduation_topics_controller.rb @@ -1,5 +1,5 @@ class GraduationTopicsController < ApplicationController - before_action :require_login, except: [:index] + before_action :require_login, :check_auth, except: [:index] before_action :find_course before_action :teacher_allowed, only: [:new, :create, :update, :edit, :destroys, :set_public, :refuse_student_topic, :accept_student_topic, :export] diff --git a/app/controllers/graduation_works_controller.rb b/app/controllers/graduation_works_controller.rb index 7cf1a3393..a4a59a3f5 100644 --- a/app/controllers/graduation_works_controller.rb +++ b/app/controllers/graduation_works_controller.rb @@ -1,5 +1,5 @@ class GraduationWorksController < ApplicationController - before_action :require_login + before_action :require_login, :check_auth before_action :find_task, only: [:new, :create, :search_member_list, :check_project, :relate_project, :cancel_relate_project] before_action :find_work, only: [:show, :edit, :update, :revise_attachment, :supply_attachments, :comment_list, diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 6f0f10f4d..bbae7ba75 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -3,7 +3,7 @@ class HomeworkCommonsController < ApplicationController include ApplicationHelper include ExportHelper - before_action :require_login, except: [:index, :choose_category] + before_action :require_login, :check_auth, except: [:index, :choose_category] before_action :find_course, only: [:index, :create, :new, :shixuns, :subjects, :create_shixun_homework, :publish_homework, :end_homework, :set_public, :choose_category, :move_to_category, :choose_category, diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 0c61e2b69..5bdc3e053 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -3,7 +3,7 @@ class MessagesController < ApplicationController SORT_TYPE = %w[time hot] - before_action :require_login, only: %i[create update sticky_top bulk_delete create destroy bulk_send bulk_move bulk_public] + before_action :require_login, :check_auth, only: %i[create update sticky_top bulk_delete create destroy bulk_send bulk_move bulk_public] before_action :find_board, only: [:create, :index, :bulk_delete, :bulk_move, :bulk_send, :bulk_public] before_action :find_message, only: [:update, :destroy, :sticky_top, :reply_list, :destroy, :reply] before_action :validate_delete_params, only: %i[bulk_delete bulk_public] diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index f4549d691..276fbef32 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -1,5 +1,5 @@ class MyshixunsController < ApplicationController - before_action :require_login, :except => [:training_task_status, :code_runinng_message] + before_action :require_login, :check_auth, :except => [:training_task_status, :code_runinng_message] before_action :find_myshixun, :except => [:training_task_status, :code_runinng_message] before_action :find_repo_name, :except => [:training_task_status, :code_runinng_message] skip_before_action :verify_authenticity_token, :only => [:html_content] diff --git a/app/controllers/poll_questions_controller.rb b/app/controllers/poll_questions_controller.rb index 84e21c4e8..6a0b9ea47 100644 --- a/app/controllers/poll_questions_controller.rb +++ b/app/controllers/poll_questions_controller.rb @@ -1,5 +1,5 @@ class PollQuestionsController < ApplicationController - before_action :require_login + before_action :require_login, :check_auth before_action :get_poll,only:[:new,:create] before_action :get_poll_question,except: [:new,:create] before_action :is_course_teacher diff --git a/app/controllers/poll_votes_controller.rb b/app/controllers/poll_votes_controller.rb index c11248054..b1191d8ea 100644 --- a/app/controllers/poll_votes_controller.rb +++ b/app/controllers/poll_votes_controller.rb @@ -1,6 +1,6 @@ class PollVotesController < ApplicationController #在开始回答和提交问卷的时候,已经做了判断用户的身份权限 - before_action :require_login + before_action :require_login, :check_auth before_action :get_poll_question before_action :check_answer_in_question diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index e2d0ce3cd..70995fbcf 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -1,6 +1,6 @@ class PollsController < ApplicationController # before_action :check_poll_status 问卷的发消息和定时任务没有做 - before_action :require_login,except: [:index] + before_action :require_login, :check_auth,except: [:index] before_action :find_course, except: [:show,:poll_setting,:commit_setting,:edit,:update,:start_answer,:commit_poll, :commit_result,:poll_lists,:cancel_publish,:cancel_publish_modal,:common_header] before_action :get_poll_and_course, only: [:show,:poll_setting,:commit_setting,:edit,:update,:start_answer, diff --git a/app/controllers/praise_tread_controller.rb b/app/controllers/praise_tread_controller.rb index bf814db77..459eb4bad 100644 --- a/app/controllers/praise_tread_controller.rb +++ b/app/controllers/praise_tread_controller.rb @@ -1,6 +1,6 @@ class PraiseTreadController < ApplicationController include MessagesHelper - before_action :require_login + before_action :require_login, :check_auth before_action :validate_params, only: [:like, :unlike] before_action :find_object diff --git a/app/controllers/question_banks_controller.rb b/app/controllers/question_banks_controller.rb index 22650f2d3..e30065d09 100644 --- a/app/controllers/question_banks_controller.rb +++ b/app/controllers/question_banks_controller.rb @@ -1,5 +1,5 @@ class QuestionBanksController < ApplicationController - before_action :require_login + before_action :require_login, :check_auth before_action :params_filter # 题库选用列表 diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 3b3e0478a..2d708bfa8 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -1,5 +1,5 @@ class ShixunsController < ApplicationController - before_action :require_login, except: [:download_file, :index, :menus] + before_action :require_login, :check_auth, except: [:download_file, :index, :menus] before_action :check_auth, except: [:download_file, :index, :menus] before_action :find_shixun, :shixun_access_allowed, except: [:index, :new, :create, :menus, :get_recommend_shixuns, diff --git a/app/controllers/stages_controller.rb b/app/controllers/stages_controller.rb index 3d0087981..c62832365 100644 --- a/app/controllers/stages_controller.rb +++ b/app/controllers/stages_controller.rb @@ -1,5 +1,5 @@ class StagesController < ApplicationController - before_action :require_login + before_action :require_login, :check_auth before_action :find_subject, only: [:create, :index] before_action :find_stage, only: [:update, :destroy, :edit, :up_position, :down_position] before_action :allowed, except: [:index] diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 1c98db56c..9b32358bd 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -2,7 +2,7 @@ class StudentWorksController < ApplicationController include HomeworkCommonsHelper include StudentWorksHelper - before_action :require_login + before_action :require_login, :check_auth before_action :find_homework, only: [:new, :create, :search_member_list, :check_project, :relate_project, :cancel_relate_project] before_action :find_work, only: [:shixun_work_report, :adjust_review_score, :shixun_work, :commit_des, :update_des, diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 46f3b4850..b3e317e4b 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -1,5 +1,5 @@ class SubjectsController < ApplicationController - before_action :require_login, except: [:index] + before_action :require_login, :check_auth, except: [:index] # before_action :check_auth, except: [:index] before_action :find_subject, except: [:index, :create, :append_to_stage] before_action :allowed, only: [:update, :edit, :destroy, :publish, :cancel_publish, :cancel_has_publish, diff --git a/app/controllers/users/base_account_controller.rb b/app/controllers/users/base_account_controller.rb index 29de52b26..5c474517d 100644 --- a/app/controllers/users/base_account_controller.rb +++ b/app/controllers/users/base_account_controller.rb @@ -1,5 +1,5 @@ class Users::BaseAccountController < Users::BaseController - before_action :require_login + before_action :require_login, :check_auth def observed_user @_observed_user ||= (User.find_by_id(params[:account_id]) || User.find_by_login(params[:account_id])) diff --git a/app/controllers/users/interests_controller.rb b/app/controllers/users/interests_controller.rb index 93836fd63..bac9c568d 100644 --- a/app/controllers/users/interests_controller.rb +++ b/app/controllers/users/interests_controller.rb @@ -1,6 +1,6 @@ class Users::InterestsController < Users::BaseController skip_before_action :check_observed_user_exists! - before_action :require_login + before_action :require_login, :check_auth def create identity = params[:identity].to_s.strip diff --git a/app/controllers/users/watches_controller.rb b/app/controllers/users/watches_controller.rb index 95a0b38cd..867106c52 100644 --- a/app/controllers/users/watches_controller.rb +++ b/app/controllers/users/watches_controller.rb @@ -1,5 +1,5 @@ class Users::WatchesController < Users::BaseController - before_action :require_login + before_action :require_login, :check_auth def create if observed_logged_user? diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index a4140fe34..10baf2454 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -1,5 +1,5 @@ class ZipsController < ApplicationController - before_action :require_login + before_action :require_login, :check_auth before_action :load_homework, only: [:shixun_report] before_action :get_exercise, only: [:export_exercises] From 394f4eb2fe9d8a621ae0289f95b18ad43d47f39d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 15 Jul 2019 09:01:42 +0800 Subject: [PATCH 0773/1015] merge --- app/controllers/challenges_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index ac06cdcc0..697585e0c 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -1,5 +1,4 @@ class ChallengesController < ApplicationController -<<<<<<< HEAD before_action :require_login, :check_auth before_action :find_shixun, only: [:new, :create, :index] skip_before_action :verify_authenticity_token, only: [:create, :update, :create_choose_question, :crud_answer] From 4000eafe94d75e2900098a01715638a7f9d75065 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 15 Jul 2019 11:29:47 +0800 Subject: [PATCH 0774/1015] =?UTF-8?q?=E5=9C=A8=E7=BA=BF=E8=AF=BE=E5=A0=82?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E7=9A=84=E4=BC=98=E5=8C=96=E3=80=81=E5=AD=A6?= =?UTF-8?q?=E7=94=9F=E5=88=97=E8=A1=A8=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 15 +++++++-------- app/models/user.rb | 7 ++++++- app/views/courses/index.json.jbuilder | 9 +++------ 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 286935c17..6b686e0e7 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -53,7 +53,6 @@ class CoursesController < ApplicationController # c.tea_id=u.id and u.id=ue.user_id and ue.school_id=s.id") @courses = Course.where(is_delete: 0, is_hidden: 0) - .includes(:course_modules, :course_members, teacher: [user_extension: :school]) .order("courses.id = 1309 desc, courses.created_at desc") # @courses = Course.where(is_delete: 0, is_hidden: 0).select("courses.id, courses.tea_id, courses.name, courses.exercises_count, courses.polls_count, @@ -66,13 +65,11 @@ class CoursesController < ApplicationController .order("courses.id = 1309 DESC, courses.#{order_str} DESC") elsif @order == "created_at" # REDO:Extension - @courses = Course.joins(teacher: :user_extension) - .where(is_delete: 0, is_hidden: 0, is_end: 0) + @courses = Course.where(is_delete: 0, is_hidden: 0, is_end: 0) .order("courses.id = 1309 DESC, courses.#{order_str} DESC") else # REDO:Extension - @courses = Course.joins(teacher: :user_extension) - .where(is_delete: 0, is_hidden: 0) + @courses = Course.where(is_delete: 0, is_hidden: 0) .order("courses.id = 1309 DESC, courses.#{order_str} DESC") end @@ -89,7 +86,7 @@ class CoursesController < ApplicationController (course_members.role in(1,2,3) and CONCAT(users.lastname, users.firstname) like :keyword) or courses.name like :keyword or schools.name like :keyword } - @courses = @courses.joins(course_members: [user: [user_extension: :school]]) + @courses = @courses.joins(:school, course_members: [user: :user_extension]) .where("#{sql}", keyword: "%#{params[:search]}%").distinct end @courses_count = @courses.size @@ -98,7 +95,8 @@ class CoursesController < ApplicationController page = params[:page] || 1 limit = params[:limit] || 16 - @courses= @courses.page(page).per(limit) + @courses = @courses.page(page).per(limit) + @courses = @courses.preload(:school, :course_members, teacher: :user_extension) end def visits_plus_one @@ -655,7 +653,8 @@ class CoursesController < ApplicationController page = params[:page] || 1 limit = params[:limit] || 20 - @students= Kaminari.paginate_array(@students).page(page).per(limit) + @students= @students.page(page).per(limit) + @students = @students.includes(:course_group, user: :user_extension) end # 获取当前课程所有分班 diff --git a/app/models/user.rb b/app/models/user.rb index 7e04ff423..523df045d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -318,7 +318,12 @@ class User < ApplicationRecord elsif business? Course::BUSINESS else - role = course.course_members.find_by(user_id: id, is_active: 1)&.role + role = + if course.course_members.loaded? + course.course_members.find{|member| member.user_id == id && member.is_active == 1}&.role + else + course.course_members.find_by(user_id: id, is_active: 1)&.role + end case role when nil then Course::NORMAL when 'CREATOR' then Course::CREATOR diff --git a/app/views/courses/index.json.jbuilder b/app/views/courses/index.json.jbuilder index 5a128a0b7..2b6866517 100644 --- a/app/views/courses/index.json.jbuilder +++ b/app/views/courses/index.json.jbuilder @@ -1,18 +1,15 @@ -json.courses do - json.array! @courses do |course| +json.courses @courses do |course| json.id course.id json.name course.name json.avatar_url url_to_avatar(course.teacher) json.creator course.teacher.real_name - json.school course.teacher.school_name - json.technical_title course.teacher.user_extension.technical_title + json.school course.school&.name + json.technical_title course.teacher.identity json.course_members_count course.course_members_count json.tasks_count get_tasks_count course json.visits course.visits json.is_public course.is_public json.is_accessible course.is_public == 1 || @user.course_identity(course) < Course::NORMAL json.is_end course.is_end - json.first_category_url module_url(course.course_modules.not_hidden.first, course) - end end json.courses_count @courses_count From 53e244a0a5aaa38bcf03aad0746aa82673329319 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 15 Jul 2019 13:47:12 +0800 Subject: [PATCH 0775/1015] =?UTF-8?q?Exercise=E9=87=8Cexercise=5Flists?= =?UTF-8?q?=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 76 ++++++++++--------------- app/helpers/exercises_helper.rb | 7 +-- app/models/exercise.rb | 24 ++++++-- 3 files changed, 52 insertions(+), 55 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 6af48dbd1..4c4481483 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1164,69 +1164,65 @@ class ExercisesController < ApplicationController @course_all_members = @course.students @c_group_counts = @course.course_groups_count question_types = @exercise.exercise_questions.pluck(:question_type).uniq - @exercise_publish_count = get_user_permission_course(exercise_ids,2).count #判断是否有已发布的分班 - @exercise_unpublish_count = get_user_permission_course(exercise_ids,1).count #判断是否有未发布的分班 + @exercise_publish_count = get_user_permission_course(exercise_ids,Exercise::PUBLISHED).count #判断是否有已发布的分班 + @exercise_unpublish_count = get_user_permission_course(exercise_ids,Exercise::UNPUBLISHED).count #判断是否有未发布的分班 - if (question_types.size > 1) && question_types.include?(4) #是否包含主观题,或者是否大于1 + if (question_types.size > 1) && question_types.include?(Exercise::SUBJECTIVE) #是否包含主观题,或者是否大于1 @subjective_type = 1 else @subjective_type = 0 end + #初始化值 + @exercise_users_list = [] #答题用户列表 + @exercise_course_groups = [] #当前用户有权限的班级 + @exercise_unanswers = 0 # 未答用户数 + @exercise_answers = 0 #已答用户数 + @exercise_users_count = 0 #全部用户数 + @teacher_review_count = 0 #已评数 + @teacher_unreview_count = 0 #未评数 + + #试卷的答题列表页的显示用户 if @user_course_identity < Course::STUDENT #当前为老师,而且老师只能查看自己班级的/课堂的试卷 @exercise_current_user_status = 0 - if @exercise_status == 1 - @exercise_users_list = [] - @exercise_course_groups = [] - @exercise_unanswers = 0 - @exercise_answers = 0 - else + unless @exercise_status == 1 ex_common_ids = @exercise.common_published_ids(current_user.id) @exercise_course_groups = @course.get_ex_published_course(ex_common_ids) @exercise_users_list = @exercise.all_exercise_users(current_user.id) #当前老师所在班级的全部学生 get_exercise_answers(@exercise_users_list, @exercise_status) end - elsif @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生或者有过答题的(提交/未提交) + else #当前为学生或者有过答题的 @ex_user_end_time = @exercise.get_exercise_end_time(current_user.id) #当前用户所看到的剩余时间 @exercise_all_users = @exercise.get_stu_exercise_users get_exercise_answers(@exercise_all_users, @exercise_status) # 未答和已答的 - exercise_current_user = @exercise_all_users.exercise_commit_users(current_user.id) #当前用户是否开始做试卷(提交/未提交/没做) - if exercise_current_user.present? - @exercise_current_user_status = 1 #当前用户的状态,为学生 - if @exercise.score_open && @exercise_status == 3 && exercise_current_user.present? #勾选了成绩公开且试卷已截止的 + exercise_current_user = @exercise_all_users.exercise_commit_users(current_user.id) + if exercise_current_user.exists? #表示为课堂学生或已回答的 + @exercise_current_user_status = 1 + if @exercise.score_open && @exercise_status == 3 #勾选了成绩公开且试卷已截止的 all_user_ids = @exercise_all_users.pluck(:user_id) all_user_ids.delete(current_user.id) #删除了当前用户的ID @exercise_users_list = @exercise_all_users.exercise_commit_users(all_user_ids).distinct @current_user_ex_answers = exercise_current_user #当前用户的回答 else - @exercise_users_list = exercise_current_user.present? ? exercise_current_user.distinct : [] + @exercise_users_list = exercise_current_user end - else - @exercise_all_users = @exercise.get_stu_exercise_users - get_exercise_answers(@exercise_all_users, @exercise_status) # 未答和已答的 + else #表示为未回答的,或未非课堂成员的 @exercise_current_user_status = 2 #当前用户非课堂成员 - @exercise_users_list = [] end end - if @exercise_users_list.present? && @exercise_users_list.count > 0 - @exercise_users_count = @exercise_users_list.count #当前显示的全部成员数量 - else - @exercise_users_count = 0 - end if @exercise_unanswers < 0 @exercise_unanswers = 0 end - @teacher_review_count = 0 - @teacher_unreview_count = 0 #筛选/分类,排序 order = params[:order] - if @exercise_users_list.present? && @exercise_users_list.size > 0 + if @exercise_users_list.exists? && @exercise_users_list.size > 0 + @exercise_users_count = @exercise_users_list.size #当前显示的全部成员数量 teacher_reviews = @exercise_users_list.exercise_review teacher_unreviews = @exercise_users_list.exercise_unreview - @teacher_review_count = teacher_reviews.count #已评阅 - @teacher_unreview_count = teacher_unreviews.count #未评阅 + @teacher_review_count = teacher_reviews.size #已评阅 + @teacher_unreview_count = teacher_unreviews.size #未评阅 #是否评阅 if params[:review].present? @@ -1284,7 +1280,7 @@ class ExercisesController < ApplicationController if params[:format] == "xlsx" if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") - elsif @exercise_status == 1 + elsif @exercise_status == Exercise::UNPUBLISHED normal_status(-1,"试卷未发布") elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) normal_status(-1,"暂无用户提交") @@ -1530,30 +1526,22 @@ class ExercisesController < ApplicationController def get_user_permission_course(exercise_ids,status) exercise_status = status.to_i #传入的试卷发布状态 unpublish_group = [] - # g_course_ids = @course.teacher_course_groups.get_user_groups(current_user.id).pluck(:course_group_id).reject(&:blank?).uniq #当前用户有权限的分班 - # #用户的班级,理论上用户的班级要大于等于试卷设置的班级 - # if g_course_ids.blank? || g_course_ids.include?(0) - # user_groups_id = @course.course_groups.pluck(:id) - # else - # user_groups_id = g_course_ids - # end + course_groups = [] user_groups_id = @course.charge_group_ids(current_user) - exercises_all = Exercise.where(id:exercise_ids) + exercises_all = Exercise.includes(:exercise_group_settings).where(id:exercise_ids) exercises_all.each do |exercise| if exercise.present? if exercise.unified_setting #统一设置只有两种情况,全部发布,全部截止 exercise_user_status = exercise.get_exercise_status(current_user) #当前用户的能看到的试卷 - if (exercise_user_status == exercise_status) || exercise_status == 3 #未发布的情况 + if (exercise_user_status == exercise_status) || exercise_status == Exercise::ENDED #未发布的情况 unpublish_group = unpublish_group + user_groups_id - else - unpublish_group = [] end else ex_all_group_settings = exercise.exercise_group_settings ex_group_settings = ex_all_group_settings.exercise_group_published.pluck(:course_group_id).uniq #问卷设置的班级 - if exercise_status == 1 + if exercise_status == Exercise::UNPUBLISHED unpublish_group = user_groups_id - ex_group_settings - elsif exercise_status == 3 + elsif exercise_status == Exercise::ENDED ex_ended_groups = ex_all_group_settings.exercise_group_ended.pluck(:course_group_id).uniq ex_and_user = user_groups_id & ex_group_settings #用户已设置的分班 unpublish_group = unpublish_group + ex_and_user - ex_ended_groups #已发布的全部班级减去截止的全部班级 @@ -1567,8 +1555,6 @@ class ExercisesController < ApplicationController unpublish_group = unpublish_group.uniq if unpublish_group.count > 0 course_groups = CourseGroup.by_group_ids(unpublish_group) - else - course_groups = [] end course_groups end diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 314a90403..ecc5de437 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -259,10 +259,9 @@ module ExercisesHelper #获取试卷的已答/未答人数 def get_exercise_answers(ex_users, status) - if status == 1 - @exercise_answers = 0 - @exercise_unanswers = 0 - else + @exercise_answers = 0 + @exercise_unanswers = 0 + unless status == Exercise::UNPUBLISHED @exercise_answers = ex_users.commit_exercise_by_status(1).size #表示已经提交了的用户 course_all_members_count = ex_users.size @exercise_unanswers = (course_all_members_count - @exercise_answers) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 3a4414ff9..10c7ab6d1 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -23,6 +23,21 @@ class Exercise < ApplicationRecord after_create :create_exercise_list + # 试卷的问题类型 + SINGLE = 0 #单选题 + MULTIPLE = 1 #多选题 + JUDGMENT = 2 #判断题 + COMPLETION = 3 # 填空题 + SUBJECTIVE = 4 # 主观题 + PRACTICAL = 5 #实训题 + + # 试卷的状态 + UNPUBLISHED = 1 #未发布 + PUBLISHED = 2 #已发布 + DEADLINE = 3 #已截止 + ENDED = 4 #课堂已结束 + + def create_exercise_list str = "" # TODO: 一次性为所有学生创建数据是否存在问题? @@ -93,8 +108,6 @@ class Exercise < ApplicationRecord def common_published_ids(user_id) current_user_groups = course.teacher_course_ids(user_id) if unified_setting - # un_group_ids = (course.none_group_count > 0) ? [0] : [] - # published_group_ids = (current_user_groups + un_group_ids).uniq #统一设置时,为当前用户的分班id及未分班 published_group_ids = current_user_groups else ex_group_setting = exercise_group_settings.select(:course_group_id).pluck("course_group_id").uniq @@ -118,13 +131,12 @@ class Exercise < ApplicationRecord ex_time = get_exercise_times(user_id,false) pb_time = ex_time[:publish_time] ed_time = ex_time[:end_time] - if pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now - status = 2 + status = Exercise::PUBLISHED elsif ed_time.present? && ed_time <= Time.now - status = 3 + status = Exercise::ENDED else - status = 1 + status = Exercise::UNPUBLISHED end else status = exercise_status #当为老师的时候,则为试卷的总状态 From f10cbf22507cfb24af98be433722bd6244e99769 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 15 Jul 2019 14:18:36 +0800 Subject: [PATCH 0776/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E8=B0=83?= =?UTF-8?q?=E5=88=86=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exercise_questions_controller.rb | 59 +++++++++---------- app/helpers/exercises_helper.rb | 2 +- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 3d488c7b0..ead874fc4 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -70,13 +70,13 @@ class ExerciseQuestionsController < ApplicationController } question_standard_answer = ExerciseStandardAnswer.new(standard_option) question_standard_answer.save - if standard_answer.count > 1 && ques_type == 0 #当标准答案数大于1,且不为多选时,修改为多选 - @exercise_question.update_attribute("question_type",1) - elsif standard_answer.count == 1 && ques_type == 1 - @exercise_question.update_attribute("question_type",0) + if standard_answer.count > 1 && ques_type == Exercise::SINGLE #当标准答案数大于1,且不为多选时,修改为多选 + @exercise_question.update_attribute("question_type",Exercise::MULTIPLE) + elsif standard_answer.count == 1 && ques_type == Exercise::MULTIPLE + @exercise_question.update_attribute("question_type",Exercise::SINGLE) end end - elsif ques_type == 2 #这个为判断题 + elsif ques_type == Exercise::JUDGMENT #这个为判断题 choices_array = params[:question_choices] #判断的选项,对/错等等 choices_count= choices_array.count (1..choices_count).each do |c| @@ -95,7 +95,7 @@ class ExerciseQuestionsController < ApplicationController } question_standard_answer = ExerciseStandardAnswer.new(standard_option) question_standard_answer.save - elsif ques_type == 3 #填空题,每空的参考答案有多个,那么以位置对应 + elsif ques_type == Exercise::COMPLETION #填空题,每空的参考答案有多个,那么以位置对应 standard_answer = params[:standard_answers] standard_answer.each do |a| null_choice_id = a[:choice_id] @@ -110,7 +110,7 @@ class ExerciseQuestionsController < ApplicationController question_standard_answer.save end end - elsif ques_type == 4 #简答题 + elsif ques_type == Exercise::SUBJECTIVE #简答题 if params[:standard_answers].present? && params[:standard_answers].reject(&:blank?).count > 0 standard_answer = params[:standard_answers] standard_answer.each do |a| @@ -122,7 +122,7 @@ class ExerciseQuestionsController < ApplicationController question_standard_answer.save end end - elsif ques_type == 5 #实训题 + elsif ques_type == Exercise::PRACTICAL #实训题 shixun = Shixun.find_by(id: params[:shixun_id]) shixun_scores = params[:question_scores] #试卷有多个的分值有多个分数表,所以为分数的数组 shixun_name = params[:shixun_name] || shixun.name @@ -225,7 +225,7 @@ class ExerciseQuestionsController < ApplicationController #试卷未发布时,当标准答案存在时,可修改标准答案内容,可增删标准答案,否则只能修改标准答案,不能增删标准答案 @exercise_answers_array = @exercise_question.exercise_standard_answers #问卷的全部标准答案 if standard_answer.present? - if @exercise_question.question_type <= 2 #选择题/判断题,标准答案为一个或多个 + if @exercise_question.question_type <= Exercise::JUDGMENT #选择题/判断题,标准答案为一个或多个 exercise_standard_choices = @exercise_answers_array.pluck(:exercise_choice_id) #问题以前的全部标准答案选项位置 common_standard_choices = standard_answer & exercise_standard_choices # 传入的标准答案的选项位置和以前的并集,即表示不用做更改的 old_left_standard_choices = exercise_standard_choices - common_standard_choices # 以前的差集共同的,剩余的表示需要删掉 @@ -244,12 +244,12 @@ class ExerciseQuestionsController < ApplicationController end end - if standard_answer.count > 1 && @exercise_question.question_type == 0 #当标准答案数大于1,且不为多选时,修改为多选 - @exercise_question.update_attribute("question_type",1) - elsif standard_answer.count == 1 && @exercise_question.question_type == 1 - @exercise_question.update_attribute("question_type",0) + if standard_answer.count > 1 && @exercise_question.question_type == Exercise::SINGLE #当标准答案数大于1,且不为多选时,修改为多选 + @exercise_question.update_attribute("question_type",Exercise::MULTIPLE) + elsif standard_answer.count == 1 && @exercise_question.question_type == Exercise::MULTIPLE + @exercise_question.update_attribute("question_type",Exercise::SINGLE) end - elsif @exercise_question.question_type == 3 #填空题 + elsif @exercise_question.question_type == Exercise::COMPLETION #填空题 old_ex_answer = @exercise_question.exercise_standard_answers #当前问题的全部标准答案 old_ex_answer_choice_ids = old_ex_answer.pluck(:exercise_choice_id).uniq #全部的答案数组序号 new_ex_answer_choice_ids = standard_answer.map {|a| a[:choice_id]}.uniq #新传入的答案数组序号 @@ -321,7 +321,7 @@ class ExerciseQuestionsController < ApplicationController end end end - if @exercise_question.question_type == 4 #主观题 + if @exercise_question.question_type == Exercise::SUBJECTIVE #主观题 main_standard_answer = standard_answer.present? ? standard_answer.first : nil if @exercise_answers_array.present? @exercise_answers_array.first.update_attribute("answer_text",main_standard_answer) @@ -333,7 +333,7 @@ class ExerciseQuestionsController < ApplicationController question_standard_answer = ExerciseStandardAnswer.new(standard_option) question_standard_answer.save end - elsif @exercise_question.question_type == 5 + elsif @exercise_question.question_type == Exercise::PRACTICAL question_score = 0 shixun_name = params[:shixun_name] || @exercise_question.shixun_name @exercise_question.exercise_shixun_challenges.each_with_index do |challenge, index| @@ -347,7 +347,7 @@ class ExerciseQuestionsController < ApplicationController #当试卷已发布时(试卷的总状态),当标准答案修改时,如有已提交的学生,需重新计算分数. - if @exercise.exercise_status == 2 + if @exercise.exercise_status == Exercise::PUBLISHED ex_users_committed = @exercise.exercise_users.exercise_user_committed if ex_users_committed.size > 0 ex_users_committed.each do |ex_user| @@ -375,7 +375,7 @@ class ExerciseQuestionsController < ApplicationController begin opr = params[:opr] current_q_p = @exercise_question.question_number.to_i #问题的当前位置 - if @exercise.exercise_status.to_i == 1 + if @exercise.exercise_status.to_i == Exercise::UNPUBLISHED if opr.present? if opr.to_s == "up" last_q_p = @exercise.exercise_questions.find_by(question_number: (current_q_p - 1)) # 当前问题的前一个问题 @@ -457,7 +457,7 @@ class ExerciseQuestionsController < ApplicationController ex_obj_score = @exercise_current_user.objective_score #全部客观题得分 ex_subj_score = @exercise_current_user.subjective_score < 0.0 ? 0.0 : @exercise_current_user.subjective_score #全部主观题得分 ex_answers = @exercise_question.exercise_answers.search_answer_users("user_id",@user_id) #当前用户答案的得分 - if @exercise_question.question_type == 3 #当为填空题,更新问题的总分, + if @exercise_question.question_type == Exercise::COMPLETION #当为填空题,更新问题的总分, ex_answer_old = ex_answers.score_reviewed.pluck(:score).sum #每一关的得分总和 each_right_score = (@c_score / ex_answers.count.to_f) #调分后,平均每关的分数 new_obj_score = ex_obj_score - ex_answer_old + @c_score @@ -468,8 +468,8 @@ class ExerciseQuestionsController < ApplicationController } @exercise_current_user.update_attributes(ex_scores) ex_answers.update_all(:score => each_right_score) #所有的正确选项需重新更新 - elsif @exercise_question.question_type == 4 #当为主观题时 - if ex_answers.present? + elsif @exercise_question.question_type == Exercise::SUBJECTIVE #当为主观题时 + if ex_answers.exists? ex_answers_old_score = ex_answers.first.score > 0.0 ? ex_answers.first.score : 0.0 #原分数小于0,取0 new_sub_score = ex_subj_score - ex_answers_old_score + @c_score #原全部主观题总分减去原该主观题得分再加调分后的分数,即为当前全部主观题得分 ex_answers.first.update_attribute("score",@c_score) @@ -481,7 +481,7 @@ class ExerciseQuestionsController < ApplicationController :answer_text => "" } ExerciseAnswer.create(answer_option) - new_sub_score = @c_score + new_sub_score = ex_subj_score + @c_score end total_scores = ex_obj_score + new_sub_score ex_scores = { @@ -490,8 +490,7 @@ class ExerciseQuestionsController < ApplicationController } @exercise_current_user.update_attributes(ex_scores) - elsif @exercise_question.question_type == 5 - # ex_answers = @exercise_question.exercise_shixun_answers.search_shixun_answers("user_id",@user_id).search_shixun_answers("exercise_shixun_challenge_id",@shixun_a_id) + elsif @exercise_question.question_type == Exercise::PRACTICAL ex_answers = @exercise_question.exercise_shixun_answers.where(user_id:@user_id,exercise_shixun_challenge_id:@shixun_a_id) if ex_answers.present? #当为实训题时 @@ -622,13 +621,13 @@ class ExerciseQuestionsController < ApplicationController end def check_exercise_status - normal_status(-1,"不能更改试卷问题!") if @exercise.exercise_status != 1 + normal_status(-1,"不能更改试卷问题!") if @exercise.exercise_status != Exercise::UNPUBLISHED end #更新时不能修改的内容 def cannot_change_column #已发布的/已截止的/评阅中的状态时,不能修改分数,不能增删问题和答案,不能修改标准答案,可以修改选项内容/题目内容,这里仅指单个问题 - if @exercise.exercise_status != 1 + if @exercise.exercise_status != Exercise::UNPUBLISHED question_score = @exercise_question.question_score #原来的分数 update_question_score = params[:question_score].to_f.round(1) #传入的分数 choices_count = @exercise_question.exercise_choices.size #原来的选项个数 @@ -641,12 +640,12 @@ class ExerciseQuestionsController < ApplicationController elsif update_choices_count != choices_count #选项个数有修改 normal_status(-1,"已发布/已截止,不允许增删答案!") elsif standard_answer.present? - if @exercise_question.question_type == 3 + if @exercise_question.question_type == Exercise::COMPLETION exercise_answers_text = standard_answer.map{|a| a[:answer_text]}.sum.uniq unless (standard_answer.count == exercise_choice_ids.count) && (standard_answers_text.count == exercise_answers_text.count) normal_status(-1,"已发布/已截止,不允许增删标准答案!") end - elsif @exercise_question.question_type == 4 + elsif @exercise_question.question_type == Exercise::SUBJECTIVE unless standard_answers_text.count == standard_answer.count normal_status(-1,"已发布/已截止,不允许增删标准答案!") end @@ -663,13 +662,13 @@ class ExerciseQuestionsController < ApplicationController normal_status(-1,"用户不存在!") elsif @c_score.blank? normal_status(-1,"分数不能为空!") - elsif @exercise_question.question_type <= 1 || @exercise_question.question_type == 2 + elsif @exercise_question.question_type <= Exercise::JUDGMENT normal_status(-1,"选择题/判断题不能调分!") elsif params[:comment].present? && params[:comment].length > 100 normal_status(-1,"评语不能超过100个字符!") else @shixun_a_id = params[:shixun_challenge_id] - if @exercise_question.question_type == 5 #当为实训题时,为关卡的分数 + if @exercise_question.question_type == Exercise::PRACTICAL #当为实训题时,为关卡的分数 @shixun_challenge = @exercise_question.exercise_shixun_challenges.cha_id_find(@shixun_a_id) if @shixun_challenge.present? @old_ques_score = @shixun_challenge.first.question_score diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index ecc5de437..71a520cef 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -4,7 +4,7 @@ module ExercisesHelper #获取每个学生对每个题的答案状态 def get_each_student_exercise(exercise_id,exercise_questions,user_id) - @exercise_user = ExerciseUser.current_exercise_user(user_id,exercise_id).first + @exercise_user = ExerciseUser.current_exercise_user(user_id,exercise_id)&.first exercise_obj_status = exercise_questions.find_objective_questions @ex_obj_array = [] exercise_obj_status.each do |q| From 0a286bf5b0476ed206052cd9822da7fde636f1e8 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Mon, 15 Jul 2019 14:41:15 +0800 Subject: [PATCH 0777/1015] ES search feature --- Gemfile | 2 + Gemfile.lock | 14 +++ .../homework_commons_controller.rb | 6 +- app/controllers/searchs_controller.rb | 10 ++ app/controllers/shixuns_controller.rb | 14 ++- app/libs/util.rb | 8 ++ app/models/challenge.rb | 1 - app/models/challenge_tag.rb | 2 + app/models/course.rb | 5 + app/models/memo.rb | 5 + app/models/searchable.rb | 3 + app/models/searchable/course.rb | 37 +++++++ app/models/searchable/dependents.rb | 2 + .../searchable/dependents/challenge_tag.rb | 16 ++++ app/models/searchable/dependents/stage.rb | 15 +++ app/models/searchable/dependents/user.rb | 22 +++++ app/models/searchable/memo.rb | 46 +++++++++ app/models/searchable/shixun.rb | 58 +++++++++++ app/models/searchable/subject.rb | 61 ++++++++++++ app/models/shixun.rb | 5 +- app/models/stage.rb | 3 + app/models/subject.rb | 3 + app/models/user.rb | 5 + app/models/user_extension.rb | 2 +- app/services/concerns/elasticsearch_able.rb | 41 ++++++++ app/services/search_service.rb | 39 ++++++++ app/services/search_shixun_service.rb | 96 +++++++++++++++++++ app/views/searchs/index.json.jbuilder | 10 ++ app/views/shixuns/_shixun.json.jbuilder | 2 +- config/routes.rb | 2 + 30 files changed, 523 insertions(+), 12 deletions(-) create mode 100644 app/controllers/searchs_controller.rb create mode 100644 app/models/searchable.rb create mode 100644 app/models/searchable/course.rb create mode 100644 app/models/searchable/dependents.rb create mode 100644 app/models/searchable/dependents/challenge_tag.rb create mode 100644 app/models/searchable/dependents/stage.rb create mode 100644 app/models/searchable/dependents/user.rb create mode 100644 app/models/searchable/memo.rb create mode 100644 app/models/searchable/shixun.rb create mode 100644 app/models/searchable/subject.rb create mode 100644 app/services/concerns/elasticsearch_able.rb create mode 100644 app/services/search_service.rb create mode 100644 app/services/search_shixun_service.rb create mode 100644 app/views/searchs/index.json.jbuilder diff --git a/Gemfile b/Gemfile index 0473e221e..4cabd09b9 100644 --- a/Gemfile +++ b/Gemfile @@ -89,3 +89,5 @@ gem 'sinatra' # batch insert gem 'bulk_insert' +# elasticsearch +gem 'searchkick' diff --git a/Gemfile.lock b/Gemfile.lock index 728bbc672..9fa84f471 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -90,6 +90,14 @@ GEM connection_pool (2.2.2) crass (1.0.4) diff-lcs (1.3) + elasticsearch (7.1.0) + elasticsearch-api (= 7.1.0) + elasticsearch-transport (= 7.1.0) + elasticsearch-api (7.1.0) + multi_json + elasticsearch-transport (7.1.0) + faraday + multi_json erubi (1.7.1) execjs (2.7.0) faraday (0.15.4) @@ -100,6 +108,7 @@ GEM grape-entity (0.7.1) activesupport (>= 4.0) multi_json (>= 1.3.2) + hashie (3.6.0) htmlentities (4.3.4) httparty (0.16.2) multi_xml (>= 0.5.2) @@ -255,6 +264,10 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + searchkick (3.1.3) + activemodel (>= 4.2) + elasticsearch (>= 5) + hashie selenium-webdriver (3.14.0) childprocess (~> 0.5) rubyzip (~> 1.2) @@ -344,6 +357,7 @@ DEPENDENCIES ruby-ole rubyzip sass-rails (~> 5.0) + searchkick selenium-webdriver sidekiq simple_xlsx_reader diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index bbae7ba75..969296539 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -410,10 +410,8 @@ class HomeworkCommonsController < ApplicationController homework_detail_group = @homework.homework_detail_group param_min = params[:min_num].to_i param_max = params[:max_num].to_i - homework_detail_group.min_num = @homework.has_commit_work ? (param_min > homework_detail_group.min_num ? homework_detail_group.min_num : - param_min) : param_min - homework_detail_group.max_num = @homework.has_commit_work ? (param_max < homework_detail_group.max_num ? homework_detail_group.max_num : - param_max) : param_max + homework_detail_group.min_num = @homework.has_commit_work ? [param_min, homework_detail_group.min_num].min : param_min + homework_detail_group.max_num = @homework.has_commit_work ? [param_max, homework_detail_group.max_num].max : param_max homework_detail_group.base_on_project = params[:base_on_project] unless @homework.has_relate_project homework_detail_group.save! end diff --git a/app/controllers/searchs_controller.rb b/app/controllers/searchs_controller.rb new file mode 100644 index 000000000..1ea1c5d05 --- /dev/null +++ b/app/controllers/searchs_controller.rb @@ -0,0 +1,10 @@ +class SearchsController < ApplicationController + def index + @results = SearchService.call(search_params) + end + + private + def search_params + params.permit(:keyword, :type, :page, :per_page) + end +end \ No newline at end of file diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 2d708bfa8..019b690b5 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -1,4 +1,7 @@ class ShixunsController < ApplicationController + include ShixunsHelper + include ApplicationHelper + before_action :require_login, :check_auth, except: [:download_file, :index, :menus] before_action :check_auth, except: [:download_file, :index, :menus] @@ -14,9 +17,6 @@ class ShixunsController < ApplicationController before_action :special_allowed, only: [:send_to_course, :search_user_courses] - include ShixunsHelper - include ApplicationHelper - ## 获取课程列表 def index ## 我的实训 @@ -59,7 +59,7 @@ class ShixunsController < ApplicationController end ## 筛选 难度 - if params[:diff].present? && params[:diff].to_i != 0 + if params[:diff].present? && params[:diff].to_i != 0 @shixuns = @shixuns.where(trainee: params[:diff]) end @@ -84,6 +84,12 @@ class ShixunsController < ApplicationController limit = params[:limit] || 16 @shixuns = @shixuns.includes(:tag_repertoires, :challenges).page(page).per(limit) + + @tag_name_map = TagRepertoire.joins(:shixun_tag_repertoires) + .where(shixun_tag_repertoires: { shixun_id: @shixuns.map(&:id) }) + .group('shixun_tag_repertoires.shixun_id') + .select('shixun_id, tag_repertoires.name') + .each_with_object({}) { |r, obj| obj[r.shixun_id] = r.name } end ## 获取顶部菜单 diff --git a/app/libs/util.rb b/app/libs/util.rb index 3485bebd7..7839b2304 100644 --- a/app/libs/util.rb +++ b/app/libs/util.rb @@ -33,4 +33,12 @@ module Util Rails.logger.error(exception.message) exception.backtrace.each { |message| Rails.logger.error(message) } end + + def map_or_pluck(relation, name) + relation.is_a?(Array) || relation.loaded? ? relation.map(&name.to_sym) : relation.pluck(name) + end + + def extract_content(str) + str.gsub(/<\/?.*?>/, '').gsub(/[\n\t\r]/, '').gsub(/ /, '') + end end \ No newline at end of file diff --git a/app/models/challenge.rb b/app/models/challenge.rb index 4d136a718..0bea54eb4 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -116,5 +116,4 @@ class Challenge < ApplicationRecord end # 关卡评测文件 - end diff --git a/app/models/challenge_tag.rb b/app/models/challenge_tag.rb index 83b743adc..b68e1792c 100644 --- a/app/models/challenge_tag.rb +++ b/app/models/challenge_tag.rb @@ -1,4 +1,6 @@ class ChallengeTag < ApplicationRecord + # TODO: ES feature + # include Searchable::Dependents::ChallengeTag belongs_to :challenge, counter_cache: true belongs_to :challenge_choose, optional: true diff --git a/app/models/course.rb b/app/models/course.rb index 06090f236..77ff6c46d 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -1,4 +1,7 @@ class Course < ApplicationRecord + # TODO: ES feature + # include Searchable::Course + has_many :boards, dependent: :destroy belongs_to :teacher, class_name: 'User', foreign_key: :tea_id # 定义一个方法teacher,该方法通过tea_id来调用User表 @@ -22,6 +25,8 @@ class Course < ApplicationRecord has_many :graduation_groups, dependent: :destroy has_many :course_members, dependent: :destroy + has_many :teacher_course_members, -> { teachers_and_admin }, class_name: 'CourseMember' + has_many :teacher_users, through: :teacher_course_members, source: :user has_many :course_messages, dependent: :destroy has_many :homework_commons, dependent: :destroy has_many :homework_group_settings diff --git a/app/models/memo.rb b/app/models/memo.rb index 524c37a96..3cb074a78 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -1,4 +1,6 @@ class Memo < ApplicationRecord + # TODO: ES feature + # include Searchable::Memo has_many :memo_tag_repertoires, :dependent => :destroy has_many :tag_repertoires, :through => :memo_tag_repertoires @@ -9,6 +11,9 @@ class Memo < ApplicationRecord belongs_to :author, class_name: 'User', foreign_key: 'author_id' belongs_to :parent, class_name: 'Memo', foreign_key: 'parent_id' + has_many :descendants, foreign_key: :root_id, class_name: 'Memo' + has_many :children, foreign_key: :parent_id, class_name: 'Memo' + scope :field_for_list, lambda{ select([:id, :subject, :author_id, :sticky, :updated_at, :language, :reward, :all_replies_count, :viewed_count, :forum_id]) } diff --git a/app/models/searchable.rb b/app/models/searchable.rb new file mode 100644 index 000000000..b8649a75c --- /dev/null +++ b/app/models/searchable.rb @@ -0,0 +1,3 @@ +module Searchable + MAXIMUM_LENGTH = 10922 # 最大字节数为32766 ,一个汉字3个字节 +end \ No newline at end of file diff --git a/app/models/searchable/course.rb b/app/models/searchable/course.rb new file mode 100644 index 000000000..93c69c9e8 --- /dev/null +++ b/app/models/searchable/course.rb @@ -0,0 +1,37 @@ +module Searchable::Course + extend ActiveSupport::Concern + + included do + searchkick language: 'chinese', callbacks: :async + + scope :search_import, -> { includes(:teacher_users, teacher: { user_extension: :school } ) } + end + + def searchable_title + name + end + + def search_data + { + name: name, + author_name: teacher&.real_name + } + end + + def to_searchable_json + { + id: id, + author_name: teacher.real_name, + author_school_name: teacher.school_name, + visits_count: visits, + members_count: members_count, + is_public: is_public == 1 + } + end + + module ClassMethods + def searchable_includes + { teacher: { user_extension: :school } } + end + end +end diff --git a/app/models/searchable/dependents.rb b/app/models/searchable/dependents.rb new file mode 100644 index 000000000..66751a475 --- /dev/null +++ b/app/models/searchable/dependents.rb @@ -0,0 +1,2 @@ +module Searchable::Dependents +end diff --git a/app/models/searchable/dependents/challenge_tag.rb b/app/models/searchable/dependents/challenge_tag.rb new file mode 100644 index 000000000..fdec79d1b --- /dev/null +++ b/app/models/searchable/dependents/challenge_tag.rb @@ -0,0 +1,16 @@ +module Searchable::Dependents::ChallengeTag + extend ActiveSupport::Concern + + included do + after_create_commit :check_searchable_dependents + after_update_commit :check_searchable_dependents + end + + private + + def check_searchable_dependents + if new_record? || name_previously_changed? + challenge.shixun.reindex(:searchable_challenge_data) + end + end +end \ No newline at end of file diff --git a/app/models/searchable/dependents/stage.rb b/app/models/searchable/dependents/stage.rb new file mode 100644 index 000000000..262ddd36f --- /dev/null +++ b/app/models/searchable/dependents/stage.rb @@ -0,0 +1,15 @@ +module Searchable::Dependents::Stage + extend ActiveSupport::Concern + + included do + after_update_commit :check_searchable_dependents + end + + private + + def check_searchable_dependents + if name_previously_changed? || description_previously_changed? + subject.reindex(:searchable_stages_data) + end + end +end \ No newline at end of file diff --git a/app/models/searchable/dependents/user.rb b/app/models/searchable/dependents/user.rb new file mode 100644 index 000000000..761704d06 --- /dev/null +++ b/app/models/searchable/dependents/user.rb @@ -0,0 +1,22 @@ +module Searchable::Dependents::User + extend ActiveSupport::Concern + + included do + after_update_commit :check_searchable_dependents + end + + private + + def check_searchable_dependents + if firstname_previously_changed? || lastname_previously_changed? || user_extension.school_id_previously_changed? + # reindex shixun + created_shixuns.each{ |shixun| shixun.reindex(:searchable_user_data) } + + # reindex course + manage_courses.each(&:reindex) + + # reindex subject + created_subjects.each { |subject| subject.reindex(:searchable_user_data) } + end + end +end \ No newline at end of file diff --git a/app/models/searchable/memo.rb b/app/models/searchable/memo.rb new file mode 100644 index 000000000..5aa9d5fe2 --- /dev/null +++ b/app/models/searchable/memo.rb @@ -0,0 +1,46 @@ +module Searchable::Memo + extend ActiveSupport::Concern + + included do + searchkick language: 'chinese', callbacks: :async + + scope :search_import, -> { includes(:descendants) } + end + + def searchable_title + subject + end + + def should_index? + hidden.zero? && root_id.blank? && parent_id.blank? + end + + def search_data + { + name: subject, + content: Util.extract_content(content)[0..Searchable::MAXIMUM_LENGTH], + }.merge!(searchable_descendants_data) + end + + def searchable_descendants_data + { + descendants_contents: Util.map_or_pluck(descendants, :content) + .map { |content| Util.extract_content(content)[0..Searchable::MAXIMUM_LENGTH] } + } + end + + def to_searchable_json + { + id: id, + author_name: author.full_name, + visits_count: viewed_count, + all_replies_count: all_replies_count + } + end + + module ClassMethods + def searchable_includes + [:author] + end + end +end diff --git a/app/models/searchable/shixun.rb b/app/models/searchable/shixun.rb new file mode 100644 index 000000000..1f39dcd76 --- /dev/null +++ b/app/models/searchable/shixun.rb @@ -0,0 +1,58 @@ +module Searchable::Shixun + extend ActiveSupport::Concern + + included do + searchkick language: 'chinese'#, callbacks: :async + + scope :search_import, -> { includes(:shixun_info, :challenges, :challenge_tags, :users, user: { user_extension: :school }) } + end + + def searchable_title + name + end + + def search_data + { + name: name, + description: Util.extract_content(description)[0..Searchable::MAXIMUM_LENGTH] + }.merge!(searchable_user_data) + .merge!(searchable_challenge_data) + end + + def searchable_user_data + { + author_name: user.real_name, + author_school_name: user.school_name, + } + end + + def searchable_challenge_data + challenge_names = Util.map_or_pluck(challenges, :subject) + .each_with_index.map { |subject, index| "第#{index + 1}关 #{subject}" } + + { + challenge_names: challenge_names, + challenge_tag_names: Util.map_or_pluck(challenge_tags, :name).uniq.join(' ') + } + end + + def should_index? + status == 2 # published + end + + def to_searchable_json + { + id: id, + author_name: user.real_name, + author_school_name: user.school_name, + visits_count: visits, + challenges_count: challenges_count + } + end + + module ClassMethods + def searchable_includes + { user: { user_extension: :school } } + end + end +end \ No newline at end of file diff --git a/app/models/searchable/subject.rb b/app/models/searchable/subject.rb new file mode 100644 index 000000000..feec41a3c --- /dev/null +++ b/app/models/searchable/subject.rb @@ -0,0 +1,61 @@ +module Searchable::Subject + extend ActiveSupport::Concern + + included do + searchkick language: 'chinese', callbacks: :async + + scope :search_import, -> { includes(:users, :stages, user: { user_extension: :school }) } + end + + def searchable_title + name + end + + def should_index? + !hidden? && status == 2 # published + end + + def search_data + { + name: name, + description: Util.extract_content(description)[0..Searchable::MAXIMUM_LENGTH] + }.merge!(searchable_user_data) + .merge!(searchable_stages_data) + end + + def searchable_user_data + { + author_name: user.real_name, + author_school_name: user.school_name, + } + end + + def searchable_stages_data + subject_stages = + stages.map do |stage| + { + name: stage.name, + description: Util.extract_content(stage.description)[0..Searchable::MAXIMUM_LENGTH] + } + end + + { subject_stages: subject_stages} + end + + def to_searchable_json + { + id: id, + author_name: user.real_name, + author_school_name: user.school_name, + visits_count: visits, + stage_count: stages_count, + stage_shixuns_count: stage_shixuns_count + } + end + + module ClassMethods + def searchable_includes + { user: { user_extension: :school } } + end + end +end diff --git a/app/models/shixun.rb b/app/models/shixun.rb index afad10397..0925f4fa0 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -1,8 +1,12 @@ class Shixun < ApplicationRecord + # TODO: ES feature + # include Searchable::Shixun + # status: 0:编辑 1:申请发布 2:正式发布 3:关闭 -1:软删除 # hide_code: 隐藏代码窗口 # code_hidden: 隐藏代码目录 has_many :challenges, dependent: :destroy + has_many :challenge_tags, through: :challenges has_many :myshixuns, :dependent => :destroy has_many :shixun_members, dependent: :destroy has_many :users, through: :shixun_members @@ -35,7 +39,6 @@ class Shixun < ApplicationRecord # 实训服务配置 has_many :shixun_service_configs, :dependent => :destroy - scope :search_by_name, ->(keyword) { where("name like ? or description like ? ", "%#{keyword}%", "%#{keyword}%") } diff --git a/app/models/stage.rb b/app/models/stage.rb index 7c80c4f9c..ee4e969dd 100644 --- a/app/models/stage.rb +++ b/app/models/stage.rb @@ -1,4 +1,7 @@ class Stage < ApplicationRecord + # TODO: ES feature + # include Searchable::Dependents::Stage + belongs_to :subject, counter_cache: true has_many :stage_shixuns, -> { order("stage_shixuns.position ASC") }, dependent: :destroy diff --git a/app/models/subject.rb b/app/models/subject.rb index 66ac41c40..d0b3e7aed 100644 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -2,6 +2,9 @@ # 可以在初始创建的时候 class Subject < ApplicationRecord + # TODO: ES feature + # include Searchable::Subject + #status :0 编辑中 1 审核中 2 发布 belongs_to :repertoire belongs_to :user diff --git a/app/models/user.rb b/app/models/user.rb index 7e04ff423..26f0fa544 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,8 @@ class User < ApplicationRecord include Watchable + # TODO: ES feature + # include Searchable::Dependents::User + # Account statuses STATUS_ANONYMOUS = 0 STATUS_ACTIVE = 1 @@ -28,6 +31,7 @@ class User < ApplicationRecord accepts_nested_attributes_for :user_extension, update_only: true has_many :memos, foreign_key: 'author_id' + has_many :created_shixuns, class_name: 'Shixun' has_many :shixun_members, :dependent => :destroy has_many :shixuns, :through => :shixun_members has_many :myshixuns, :dependent => :destroy @@ -55,6 +59,7 @@ class User < ApplicationRecord has_many :tidings, :dependent => :destroy has_many :games, :dependent => :destroy + has_many :created_subjects has_many :subjects, :through => :subject_members has_many :subject_members, :dependent => :destroy has_many :grades, :dependent => :destroy diff --git a/app/models/user_extension.rb b/app/models/user_extension.rb index 49fca7c71..458d31989 100644 --- a/app/models/user_extension.rb +++ b/app/models/user_extension.rb @@ -2,7 +2,7 @@ class UserExtension < ApplicationRecord # identity 0: 教师教授 1: 学生, 2: 专业人士, 3: 开发者 enum identity: { teacher: 0, student: 1, professional: 2, developer: 3 } - belongs_to :user + belongs_to :user, touch: true belongs_to :school belongs_to :department, optional: true diff --git a/app/services/concerns/elasticsearch_able.rb b/app/services/concerns/elasticsearch_able.rb new file mode 100644 index 000000000..e1c33ed4a --- /dev/null +++ b/app/services/concerns/elasticsearch_able.rb @@ -0,0 +1,41 @@ +module ElasticsearchAble + extend ActiveSupport::Concern + + private + + def default_options + { + debug: Rails.env.development?, + highlight: highlight_options, + body_options: body_options, + page: page, + per_page: per_page + } + end + + def keyword + params[:keyword].to_s.strip.presence || '*' + end + + def highlight_options + { + fragment_size: EduSetting.get('es_highlight_fragment_size') || 30, + tag: '' + } + end + + def body_options + { + min_score: EduSetting.get('es_min_score') || 10 + } + end + + def per_page + per_page = params[:per_page].to_s.strip.presence || params[:limit].to_s.strip.presence + per_page.to_i <= 0 ? 20 : per_page.to_i + end + + def page + params[:page].to_i <= 0 ? 1 : params[:page].to_i + end +end \ No newline at end of file diff --git a/app/services/search_service.rb b/app/services/search_service.rb new file mode 100644 index 000000000..7cd1857bd --- /dev/null +++ b/app/services/search_service.rb @@ -0,0 +1,39 @@ +class SearchService < ApplicationService + include ElasticsearchAble + + attr_reader :params + + def initialize(params) + @params = params + end + + def call + Searchkick.search(keyword, search_options) + end + + private + + def search_options + { + index_name: index_names, + model_includes: model_includes + }.merge(default_options) + end + + def index_names + @_index_names ||= + case params[:type].to_s.strip + when 'shixun' then [Shixun] + when 'course' then [Course] + when 'subject' then [Subject] + when 'memo' then [Memo] + else [Shixun, Course, Subject, Memo] + end + end + + def model_includes + index_names.each_with_object({}) do |klass, obj| + obj[klass] = klass.searchable_includes + end + end +end \ No newline at end of file diff --git a/app/services/search_shixun_service.rb b/app/services/search_shixun_service.rb new file mode 100644 index 000000000..2e77e82d8 --- /dev/null +++ b/app/services/search_shixun_service.rb @@ -0,0 +1,96 @@ +class SearchShixunService < ApplicationService + include ElasticsearchAble + + attr_reader :user, :params + + def initialize(user, params) + @user = user + @params = params + end + + def call + Shixun.search(keyword, + fields: search_fields, + where: where_clauses, + order: order_clauses, + includes: includes_clauses, + page: page, + per_page: per_page) + end + + private + + def tag_filter_shixun_ids + return [] if params[:tag_level].to_i == 0 || params[:tag_id].blank? + + case params[:tag_level].to_i + when 1 then + Repertoire.find(params[:tag_id]).tag_repertoires.joins(:shixun_tag_repertoires) + .pluck('shixun_tag_repertoires.shixun_id') + when 2 then + SubRepertoire.find(params[:tag_id]).tag_repertoires.joins(:shixun_tag_repertoires) + .pluck('shixun_tag_repertoires.shixun_id') + when 3 then + TagRepertoire.find(params[:tag_id]).shixun_tag_repertoires.pluck(:shixun_id) + else + [] + end + end + + def user_filter_shixun_ids + return [] if params[:order_by] != 'mine' + + user.shixun_members.pluck(:shixun_id) + user.myshixuns.pluck(:shixun_id) + end + + def keyword + params[:keyword].to_s.strip.presence || '*' + end + + def search_fields + %w(name^10 author_name challenge_names description challenge_tag_names) + end + + def where_clauses + hash = {} + + ids = user_filter_shixun_ids + tag_filter_shixun_ids + hash[:id] = ids if ids.present? + + if params[:order_by] == 'mine' + hash[:status] = { not: -1 } + else + hash.merge!(hidden: false, status: 2) + end + + unless params[:status].to_i.zero? + params[:status] = [0, 1] if params[:status].to_i == 1 + hash[:status] = params[:status] + end + + hash[:trainee] = params[:diff].to_i unless params[:diff].to_i.zero? + + hash + end + + def includes_clauses + [] + end + + def order_clauses + hash = { _score: :desc } + publish_order = { type: 'number', order: :desc, script: 'doc["status"].value=="2" ? 1 : 0' } + + sort = params[:sort].to_s.strip == 'asc' ? 'asc' : 'desc' + clauses = + case params[:order_by].presence + when 'new' then { _script: publish_order, created_at: sort } + when 'hot' then { _script: publish_order, myshixuns_count: sort } + when 'mine' then { created_at: sort } + else { _script: publish_order, publish_time: sort } + end + hash.merge!(clauses) + + hash + end +end \ No newline at end of file diff --git a/app/views/searchs/index.json.jbuilder b/app/views/searchs/index.json.jbuilder new file mode 100644 index 000000000..a36edb5bd --- /dev/null +++ b/app/views/searchs/index.json.jbuilder @@ -0,0 +1,10 @@ +json.count @results.total_count +json.results do + json.array! @results.with_highlights(multiple: true) do |obj, highlights| + json.merge! obj.to_searchable_json + json.type obj.class.name.downcase + + json.title highlights.delete(:name)&.join('...') || obj.searchable_title + json.description highlights.values[0,5].each { |arr| arr.is_a?(Array) ? arr.join('...') : arr }.join('
') + end +end \ No newline at end of file diff --git a/app/views/shixuns/_shixun.json.jbuilder b/app/views/shixuns/_shixun.json.jbuilder index ebc0c520d..f5ff0358b 100644 --- a/app/views/shixuns/_shixun.json.jbuilder +++ b/app/views/shixuns/_shixun.json.jbuilder @@ -15,7 +15,7 @@ json.array! shixuns do |shixun| json.status shixun.status json.power (current_user.shixun_permission(shixun)) # 现在首页只显示已发布的实训 # REDO: 局部缓存 - json.tag_name shixun.tag_repertoires.first.try(:name) + json.tag_name @tag_name_map&.fetch(shixun.id) || shixun.tag_repertoires.first.try(:name) json.myshixuns_count shixun.myshixuns_count json.stu_num shixun.myshixuns_count json.score_info shixun.averge_star diff --git a/config/routes.rb b/config/routes.rb index d9e10e4cc..676954600 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,6 +9,8 @@ Rails.application.routes.draw do get 'home/index' get 'home/search' + get 'search', to: 'searchs#index' + post 'praise_tread/like', to: 'praise_tread#like' delete 'praise_tread/unlike', to: 'praise_tread#unlike' From d29f9e830d8ed7160a7900c9c4ee374c6ca6822e Mon Sep 17 00:00:00 2001 From: p31729568 Date: Mon, 15 Jul 2019 14:43:03 +0800 Subject: [PATCH 0778/1015] remove searchkick gem --- Gemfile | 2 +- Gemfile.lock | 14 -------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/Gemfile b/Gemfile index 4cabd09b9..3450c06e8 100644 --- a/Gemfile +++ b/Gemfile @@ -90,4 +90,4 @@ gem 'sinatra' gem 'bulk_insert' # elasticsearch -gem 'searchkick' +# gem 'searchkick' diff --git a/Gemfile.lock b/Gemfile.lock index 9fa84f471..728bbc672 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -90,14 +90,6 @@ GEM connection_pool (2.2.2) crass (1.0.4) diff-lcs (1.3) - elasticsearch (7.1.0) - elasticsearch-api (= 7.1.0) - elasticsearch-transport (= 7.1.0) - elasticsearch-api (7.1.0) - multi_json - elasticsearch-transport (7.1.0) - faraday - multi_json erubi (1.7.1) execjs (2.7.0) faraday (0.15.4) @@ -108,7 +100,6 @@ GEM grape-entity (0.7.1) activesupport (>= 4.0) multi_json (>= 1.3.2) - hashie (3.6.0) htmlentities (4.3.4) httparty (0.16.2) multi_xml (>= 0.5.2) @@ -264,10 +255,6 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - searchkick (3.1.3) - activemodel (>= 4.2) - elasticsearch (>= 5) - hashie selenium-webdriver (3.14.0) childprocess (~> 0.5) rubyzip (~> 1.2) @@ -357,7 +344,6 @@ DEPENDENCIES ruby-ole rubyzip sass-rails (~> 5.0) - searchkick selenium-webdriver sidekiq simple_xlsx_reader From c3ef9c9bd8b79da93c64f9bb225d51b42ef121e9 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 15 Jul 2019 14:47:17 +0800 Subject: [PATCH 0779/1015] =?UTF-8?q?=E5=BC=80=E5=A7=8B=E5=9B=9E=E7=AD=94?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exercise_questions_controller.rb | 2 +- app/controllers/exercises_controller.rb | 45 +++++++------------ .../_user_exercise_info.json.jbuilder | 6 +-- .../exercises/review_exercise.json.jbuilder | 3 +- .../students_exercises.json.jbuilder | 18 -------- app/views/user_mailer/register_email.html.erb | 2 +- 6 files changed, 23 insertions(+), 53 deletions(-) delete mode 100644 app/views/exercises/students_exercises.json.jbuilder diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index ead874fc4..65fd77d98 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -47,7 +47,7 @@ class ExerciseQuestionsController < ApplicationController if @exercise_question.save #为选择题(包括单选和多选)的时候,创建问题选项 ques_type = @exercise_question.question_type - if ques_type <= 1 + if ques_type <= Exercise::MULTIPLE choices_array = params[:question_choices] choices_count= choices_array.count standard_answer = params[:standard_answers] #为数组格式,因为可能会有单选和多选,标准答案,已提前判断不能为空, diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 682c474bb..c02bdccec 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1005,19 +1005,6 @@ class ExercisesController < ApplicationController @exercise_user_current.update_attribute("start_at",Time.now) end end - - # ex_time = @exercise.time - # if ex_time > 0 - # time_mill = ex_time * 60 #转为秒 - # exercise_end_time = @exercise.end_time.present? ? @exercise.end_time.to_i : 0 - # exercise_user_start = @exercise_user_current.present? ? @exercise_user_current.start_at.to_i : 0 - # if (exercise_user_start + time_mill) > exercise_end_time - # time_mill = exercise_end_time - exercise_user_start #如果开始答题时间加试卷的限时长大于试卷的截止时间,则以试卷的截止时间到开始答题时间为试卷的限时 - # end - # exercise_user_left_time = Time.now.to_i - exercise_user_start #用户已回答的时间 - # @user_left_time = (time_mill < exercise_user_left_time) ? nil : (time_mill - exercise_user_left_time) #当前用户对试卷的回答剩余时间 - # end - @t_user_exercise_status = @exercise.get_exercise_status(current_user) @user_left_time = nil @@ -1029,10 +1016,7 @@ class ExercisesController < ApplicationController @user_exercise_status = 0 #可编辑 end - @exercise_questions = @exercise.exercise_questions.includes(:exercise_shixun_challenges, - :exercise_shixun_answers, - :exercise_answers, - :exercise_standard_answers) + @exercise_questions = @exercise.exercise_questions if @exercise.question_random @exercise_questions = @exercise_questions.order("RAND()") @@ -1040,7 +1024,10 @@ class ExercisesController < ApplicationController @exercise_questions = @exercise_questions.order("question_number ASC") end # 判断问题是否已回答还是未回答 - @exercise_questions = @exercise_questions.includes(:exercise_stand_answers,:exercise_answers,:exercise_shixun_answers) + @exercise_questions = @exercise_questions.includes(:exercise_shixun_challenges, + :exercise_shixun_answers, + :exercise_answers, + :exercise_standard_answers) if @t_user_exercise_status == 3 get_each_student_exercise(@exercise.id,@exercise_questions,@exercise_current_user_id) @@ -1127,14 +1114,14 @@ class ExercisesController < ApplicationController ActiveRecord::Base.transaction do begin # 1 老师权限,0 学生权限 - @is_teacher_or = @user_course_identity < Course::STUDENT ? 1 : 0 + @is_teacher_or = (@user_course_identity < Course::STUDENT) ? 1 : 0 @student_status = 2 - # @exercise_answerer = User.find_by(id:@exercise_current_user_id) #试卷回答者 @exercise_questions = @exercise.exercise_questions.includes(:exercise_shixun_challenges,:exercise_standard_answers,:exercise_answers,:exercise_shixun_answers).order("question_number ASC") @question_status = [] - get_exercise_status = @exercise.get_exercise_status(current_user) + get_exercise_status = @exercise.get_exercise_status(current_user) #当前用户的试卷状态 + @ex_answer_status = @exercise.get_exercise_status(@ex_user) #当前试卷用户的试卷状态 if @ex_user.present? && @is_teacher_or == 0 - if get_exercise_status == 2 #当前用户已提交,且试卷未截止 + if get_exercise_status == Exercise::PUBLISHED #当前用户已提交,且试卷未截止 if @ex_user.commit_status == 0 #学生未提交,且当前为学生 @student_status = 0 else @@ -1627,7 +1614,7 @@ class ExercisesController < ApplicationController ex_status = @exercise.get_exercise_status(current_user) @ex_user = @exercise.exercise_users.find_by(user_id:@exercise_current_user_id) #该试卷的回答者 if @user_course_identity > Course::ASSISTANT_PROFESSOR - if ex_status == 1 + if ex_status == Exercise::UNPUBLISHED normal_status(-1,"试卷未发布") elsif @ex_user.present? && @ex_user.commit_status == 0 normal_status(-1,"试卷未提交") @@ -1641,7 +1628,7 @@ class ExercisesController < ApplicationController def check_exercise_public if @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生,试卷公开统计,且已截止,且已提交 ex_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first - unless @exercise.get_exercise_status(current_user) == 3 && ex_user.present? && ex_user.commit_status == 1 && + unless @exercise.get_exercise_status(current_user) == Exercise::ENDED && ex_user.present? && ex_user.commit_status == 1 && @exercise.show_statistic normal_status(-1,"学生暂不能查看") end @@ -1664,19 +1651,19 @@ class ExercisesController < ApplicationController ex_question_random = exercise.question_random question_answered = 0 exercise_questions.each_with_index do |q,index| - if ex_question_random && exercise_user_status != 3 + if ex_question_random && exercise_user_status != Exercise::ENDED ques_number = index + 1 else ques_number = q.question_number end - if q.question_type != 5 + if q.question_type != Exercise::PRACTICAL ques_vote = q.exercise_answers.search_exercise_answer("user_id",user_id) else ques_vote = q.exercise_shixun_answers.search_shixun_answers("user_id",user_id) end ques_status = 0 if ques_vote.present? - if q.question_type == 5 + if q.question_type == Exercise::PRACTICAL if ques_vote.pluck(:exercise_shixun_challenge_id).sort == q.exercise_shixun_challenges.pluck(:id).sort #用户的总得分等于问题的分数 ques_status = 1 #全部回答了,才算已答 question_answered += 1 @@ -1684,12 +1671,12 @@ class ExercisesController < ApplicationController else #其他题目,需回答的有内容,才会为已答,否则如内容为空,视为未答 vote_answer_id = ques_vote.pluck(:exercise_choice_id).reject(&:blank?) vote_text_count = ques_vote.pluck(:answer_text).reject(&:blank?).size - if q.question_type <= 2 #选择题和判断题的时候,需要有选项,才算回答 + if q.question_type <= Exercise::JUDGMENT #选择题和判断题的时候,需要有选项,才算回答 if vote_answer_id.size > 0 ques_status = 1 question_answered += 1 end - elsif q.question_type == 3 #填空题的时候,需要有选项和内容,才算回答 + elsif q.question_type == Exercise::COMPLETION #填空题的时候,需要有选项和内容,才算回答 if vote_answer_id.uniq.sort == q.exercise_standard_answers.pluck(:exercise_choice_id).uniq.sort ques_status = 1 question_answered += 1 diff --git a/app/views/exercises/_user_exercise_info.json.jbuilder b/app/views/exercises/_user_exercise_info.json.jbuilder index 9acb18326..e690f4867 100644 --- a/app/views/exercises/_user_exercise_info.json.jbuilder +++ b/app/views/exercises/_user_exercise_info.json.jbuilder @@ -36,10 +36,10 @@ elsif student_status == 1 json.question_status question_status end -exercise_status = exercise.get_exercise_status(ex_answerer) +# exercise_status = exercise.get_exercise_status(ex_answerer) #当前为老师,或为学生,但在试卷截止后且答案选择公开的 -if is_teacher_or == 1 || (exercise_status == 3 && exercise.answer_open) +if is_teacher_or == 1 || (ex_answer_status == Exercise::ENDED && exercise.answer_open) ex_type = 4 else ex_type = 3 @@ -47,7 +47,7 @@ end json.exercise_questions do json.array! exercise_questions do |q| - user_ques_answers = user_question_answers(q,ex_answerer.id,student_status,is_teacher_or,exercise_status,q.question_type,ex_type) + user_ques_answers = user_question_answers(q,ex_answerer.id,student_status,is_teacher_or,ex_answer_status,q.question_type,ex_type) user_ques_comments = user_ques_answers[:question_comment] if all_question_status.size > 0 this_ques_status = all_question_status.detect {|f| f[:q_id] == q.id} diff --git a/app/views/exercises/review_exercise.json.jbuilder b/app/views/exercises/review_exercise.json.jbuilder index 5d2ac875d..638324256 100644 --- a/app/views/exercises/review_exercise.json.jbuilder +++ b/app/views/exercises/review_exercise.json.jbuilder @@ -8,5 +8,6 @@ json.partial! "exercises/user_exercise_info",locals:{exercise:@exercise, ex_sub_array:@ex_sub_array, exercise_questions:@exercise_questions, student_status:@student_status, - question_status:@question_status + question_status:@question_status, + ex_answer_status:@ex_answer_status } diff --git a/app/views/exercises/students_exercises.json.jbuilder b/app/views/exercises/students_exercises.json.jbuilder deleted file mode 100644 index 25c85be88..000000000 --- a/app/views/exercises/students_exercises.json.jbuilder +++ /dev/null @@ -1,18 +0,0 @@ -json.total_counts @total_exercise_counts - -json.total_user_exercises do - json.array! @all_exercise_stu_array do |a| - json.student_exercise do - json.partial! "exercises/user_exercise_info",locals:{exercise:@exercise, - is_teacher_or:a[:is_teacher], - ex_answerer:a[:ex_answerer], - exercise_user:a[:ex_user], - ex_obj_array:a[:ex_obj_array], - ex_sub_array:a[:ex_sub_array], - exercise_questions:@exercise_questions, - student_status:@student_status, - question_status:@question_status - } - end - end -end diff --git a/app/views/user_mailer/register_email.html.erb b/app/views/user_mailer/register_email.html.erb index 24ae606b7..6f88177c5 100644 --- a/app/views/user_mailer/register_email.html.erb +++ b/app/views/user_mailer/register_email.html.erb @@ -28,7 +28,7 @@

From c5ace72b7ad4e5981e7cef8bd2e152addfd6d7ce Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 15 Jul 2019 14:57:11 +0800 Subject: [PATCH 0780/1015] =?UTF-8?q?=E6=95=99=E5=B8=88=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E7=9A=84=E6=80=A7=E8=83=BD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 1 + app/views/courses/teachers.json.jbuilder | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 6b686e0e7..2ecb522a2 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -284,6 +284,7 @@ class CoursesController < ApplicationController page = params[:page] || 1 limit = params[:limit] || 20 @teacher_list = @teacher_list.page(page).per(limit) + @teacher_list = @teacher_list.preload(:graduation_group, :user, :teacher_course_groups) end def apply_teachers diff --git a/app/views/courses/teachers.json.jbuilder b/app/views/courses/teachers.json.jbuilder index 6a8505964..040ffb2aa 100644 --- a/app/views/courses/teachers.json.jbuilder +++ b/app/views/courses/teachers.json.jbuilder @@ -7,9 +7,11 @@ json.teacher_list do json.user_id teacher.user.id json.role teacher.role == "CREATOR" ? "管理员" : teacher.role == "PROFESSOR" ? "教师" : "助教" json.course_groups do - json.array! CourseGroup.where(id: TeacherCourseGroup.where(course_member_id: teacher.id, user_id: teacher.user.id, course_id: @course.id).pluck(:course_group_id)) do |course_group| - json.name course_group.name - json.id course_group.id + if @course.course_groups_count > 0 + json.array! @course.course_groups.select{|group| teacher.teacher_course_groups.pluck(:course_group_id).include?(group.id)} do |course_group| + json.name course_group.name + json.id course_group.id + end end end json.graduation_group teacher.graduation_group.try(:name) From 93d0a49ee9585c5c14153a695e126771089a7e41 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 15 Jul 2019 15:00:09 +0800 Subject: [PATCH 0781/1015] fix bug --- app/controllers/exercises_controller.rb | 2 +- app/helpers/exercises_helper.rb | 8 ++++---- app/models/exercise.rb | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index c02bdccec..f80327ad1 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1119,7 +1119,7 @@ class ExercisesController < ApplicationController @exercise_questions = @exercise.exercise_questions.includes(:exercise_shixun_challenges,:exercise_standard_answers,:exercise_answers,:exercise_shixun_answers).order("question_number ASC") @question_status = [] get_exercise_status = @exercise.get_exercise_status(current_user) #当前用户的试卷状态 - @ex_answer_status = @exercise.get_exercise_status(@ex_user) #当前试卷用户的试卷状态 + @ex_answer_status = @exercise.get_exercise_status(@ex_user&.user) #当前试卷用户的试卷状态 if @ex_user.present? && @is_teacher_or == 0 if get_exercise_status == Exercise::PUBLISHED #当前用户已提交,且试卷未截止 if @ex_user.commit_status == 0 #学生未提交,且当前为学生 diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 71a520cef..eb3802d94 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -8,13 +8,14 @@ module ExercisesHelper exercise_obj_status = exercise_questions.find_objective_questions @ex_obj_array = [] exercise_obj_status.each do |q| - if q.question_type == 5 + q_type = q.question_type + if q_type == Exercise::PRACTICAL answers_content = q.exercise_shixun_answers.search_shixun_answers("user_id",user_id) else answers_content = q.exercise_answers.search_answer_users("user_id",user_id) end - if q.question_type <= 2 + if q_type <= Exercise::JUDGMENT if answers_content.present? #学生有回答时 answer_choice_array = [] answers_content.each do |a| @@ -52,7 +53,7 @@ module ExercisesHelper } @ex_obj_array.push(ques_option) end - exercise_sub_status = exercise_questions.find_by_custom("question_type",4) #主观题 + exercise_sub_status = exercise_questions.find_by_custom("question_type",Exercise::SUBJECTIVE) #主观题 @ex_sub_array = [] #主观题的已答/未答 exercise_sub_status.each do |s| sub_answer = s.exercise_answers.search_answer_users("user_id",user_id) #主观题只有一个回答 @@ -63,7 +64,6 @@ module ExercisesHelper else stand_status = 2 end - # stand_status = 1 sub_answer_score = sub_answer.first.score else stand_status = 0 diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 10c7ab6d1..79701767f 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -127,6 +127,7 @@ class Exercise < ApplicationRecord #判断是否为分班,如果分班,试卷的截止时间为当前分班时间,否则为试卷的截止时间 def get_exercise_status(user) + return Exercise::UNPUBLISHED if user.nil? if user.student_of_course?(course) #当为学生的时候,需根据分班来判断试卷状态 ex_time = get_exercise_times(user_id,false) pb_time = ex_time[:publish_time] From 4a2d8c5bfec829d55748fe36661a9b93ae08e5b9 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 15 Jul 2019 15:02:10 +0800 Subject: [PATCH 0782/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E9=A6=96=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shixuns/_shixun.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shixuns/_shixun.json.jbuilder b/app/views/shixuns/_shixun.json.jbuilder index f5ff0358b..e6dbd3115 100644 --- a/app/views/shixuns/_shixun.json.jbuilder +++ b/app/views/shixuns/_shixun.json.jbuilder @@ -15,7 +15,7 @@ json.array! shixuns do |shixun| json.status shixun.status json.power (current_user.shixun_permission(shixun)) # 现在首页只显示已发布的实训 # REDO: 局部缓存 - json.tag_name @tag_name_map&.fetch(shixun.id) || shixun.tag_repertoires.first.try(:name) + json.tag_name @tag_name_map&.fetch(shixun.id, nil) || shixun.tag_repertoires.first.try(:name) json.myshixuns_count shixun.myshixuns_count json.stu_num shixun.myshixuns_count json.score_info shixun.averge_star From 6b92defd3f9272ffb97a9f32e69bec7d8ed3a8a3 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 15 Jul 2019 15:13:32 +0800 Subject: [PATCH 0783/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E7=BB=93=E6=9E=9C=E9=A1=B5=E9=9D=A2=E7=9A=84=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 9 ++++----- app/helpers/exercises_helper.rb | 10 +++++----- app/views/exercises/exercise_result.json.jbuilder | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index f80327ad1..6fa694fbf 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1323,13 +1323,12 @@ class ExercisesController < ApplicationController ActiveRecord::Base.transaction do begin exercise_ids = [@exercise.id] - @exercise_publish_count = get_user_permission_course(exercise_ids,2).count #判断是否有已发布的分班 - @exercise_unpublish_count = get_user_permission_course(exercise_ids,1).count #判断是否有未发布的分班 + @exercise_publish_count = get_user_permission_course(exercise_ids,Exercise::PUBLISHED).size #判断是否有已发布的分班 + @exercise_unpublish_count = get_user_permission_course(exercise_ids,Exercise::UNPUBLISHED).size #判断是否有未发布的分班 @course_all_members = @course.students #课堂的全部学生 @exercise_all_users = @exercise.exercise_users ex_common_ids = @exercise.common_published_ids(current_user.id) @exercise_course_groups = @course.get_ex_published_course(ex_common_ids) - # @exercise_course_groups = @exercise.get_ex_published_course(current_user.id) @exercise_users_list = @exercise.all_exercise_users(current_user.id) @course_all_members_count = @exercise_users_list.size @@ -1342,7 +1341,7 @@ class ExercisesController < ApplicationController end @exercise_commit_users = @exercise_all_users.commit_exercise_by_status(1) #试卷的已提交用户 @exercise_commit_user_ids = @exercise_commit_users.pluck(:user_id).uniq #已提交试卷的全部用户id - @exercise_commit_user_counts = @exercise_commit_users.count #试卷的已提交用户人数 + @exercise_commit_user_counts = @exercise_commit_users.size #试卷的已提交用户人数 @exercise_status = @exercise.get_exercise_status(current_user) #提交率 @@ -1394,7 +1393,7 @@ class ExercisesController < ApplicationController @question_result_hash = ques_result_all.sort_by{|s| s["#{@paging_type}"]} end - @exercise_questions_count = @exercise_questions.count + @exercise_questions_count = @exercise_questions.size @page = params[:page] || 1 @limit = params[:limit] || 10 @question_result_hash = Kaminari.paginate_array(@question_result_hash).page(@page).per(@limit) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index eb3802d94..3e73931e0 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -89,7 +89,7 @@ module ExercisesHelper questions.each do |ex| ex_total_score = user_ids.count * ex&.question_score #该试卷的已回答的总分 ex_answers = ex.exercise_answers - if ex.question_type != 5 + if ex.question_type != Exercise::PRACTICAL ques_title = ex.question_title ques_less_title = nil effictive_users = ex_answers.search_answer_users("user_id",user_ids) @@ -106,7 +106,7 @@ module ExercisesHelper percent = (ex_answered_scores / ex_total_score.to_f).round(3) * 100 #正确率 end question_answer_infos = [] - if ex.question_type <= 2 #单选题 + if ex.question_type <= Exercise::JUDGMENT #单选题 standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id) #标准答案的位置 ex.exercise_choices.each do |c| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 @@ -126,7 +126,7 @@ module ExercisesHelper } question_answer_infos.push(answer_option) end - elsif ex.question_type == 3 #填空题 + elsif ex.question_type == Exercise::COMPLETION #填空题 ex_ordered = ex.is_ordered null_standard_answer = ex.exercise_standard_answers null_stand_choice = null_standard_answer.pluck(:exercise_choice_id) @@ -179,7 +179,7 @@ module ExercisesHelper :right_answer => false } question_answer_infos.push(wrong_answer_position) - elsif ex.question_type == 4 #主观题 + elsif ex.question_type == Exercise::SUBJECTIVE #主观题 ex_score = ex&.question_score full_scores = effictive_users.search_exercise_answer("score",ex_score).count #满分人数 no_full_scores = effictive_users.exercise_no_full_scores(ex_score).count #部分分数人数 @@ -208,7 +208,7 @@ module ExercisesHelper } question_answer_infos.push(answer_option) end - elsif ex.question_type == 5 #实训题 + elsif ex.question_type == Exercise::PRACTICAL #实训题 ex.exercise_shixun_challenges.each do |c| cha_score = c&.question_score cha_shixun_answer = effictive_users.search_shixun_keys("exercise_shixun_challenge_id",c.id) diff --git a/app/views/exercises/exercise_result.json.jbuilder b/app/views/exercises/exercise_result.json.jbuilder index b0d1be9d2..2428e57c7 100644 --- a/app/views/exercises/exercise_result.json.jbuilder +++ b/app/views/exercises/exercise_result.json.jbuilder @@ -32,7 +32,7 @@ json.commit_results do json.ques_position q[:position] json.right_percent q[:percent] json.effictive_counts q[:ques_effictive_counts] - if q[:type] != 5 + if q[:type] != Exercise::PRACTICAL json.ques_details do json.array! q[:ques_details] do |d| json.choice_position d[:choice_position] From 603d6a4aec5eb8f2489f566b57ee294ba3d5973a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 15 Jul 2019 15:50:45 +0800 Subject: [PATCH 0784/1015] =?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/courses_controller.rb | 2 +- app/models/user.rb | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 2ecb522a2..1e18b8be6 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -96,7 +96,7 @@ class CoursesController < ApplicationController limit = params[:limit] || 16 @courses = @courses.page(page).per(limit) - @courses = @courses.preload(:school, :course_members, teacher: :user_extension) + @courses = @courses.preload(:school, teacher: :user_extension) end def visits_plus_one diff --git a/app/models/user.rb b/app/models/user.rb index f2ea635c4..26f0fa544 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -323,12 +323,7 @@ class User < ApplicationRecord elsif business? Course::BUSINESS else - role = - if course.course_members.loaded? - course.course_members.find{|member| member.user_id == id && member.is_active == 1}&.role - else - course.course_members.find_by(user_id: id, is_active: 1)&.role - end + role = course.course_members.find_by(user_id: id, is_active: 1)&.role case role when nil then Course::NORMAL when 'CREATOR' then Course::CREATOR From db6f5e2830cddd7ce01f37bb96dac70b13acbdea Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 15 Jul 2019 16:09:26 +0800 Subject: [PATCH 0785/1015] =?UTF-8?q?=E6=89=8B=E6=9C=BA=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=A0=81=E6=A8=A1=E7=89=88=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/educoder/sms.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/educoder/sms.rb b/lib/educoder/sms.rb index cadce7465..7fa1c0edb 100644 --- a/lib/educoder/sms.rb +++ b/lib/educoder/sms.rb @@ -36,7 +36,7 @@ module Educoder params['mobile'] = mobile params['text'] = "" if send_type.nil? - params['text'] = "【Edu实训】" + code + "(手机验证码)。如非本人操作,请忽略。" + params['text'] = "【Edu实训】" + code + "(手机验证码),有效期为10分钟。如非本人操作,请忽略。" elsif send_type == 'competition_start' params['text'] = "【Edu实训】亲爱的#{user_name},你参与的#{name}将于#{result}开始,请及时参赛" Rails.logger.info "#{params['text']}" From 04e46063b2dae1964645730587dad8071d30a9a3 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 15 Jul 2019 16:10:32 +0800 Subject: [PATCH 0786/1015] fixbug --- app/controllers/exercises_controller.rb | 8 ++++---- app/helpers/exercises_helper.rb | 6 +++++- app/models/exercise.rb | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 6fa694fbf..79b22d571 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1519,7 +1519,7 @@ class ExercisesController < ApplicationController if exercise.present? if exercise.unified_setting #统一设置只有两种情况,全部发布,全部截止 exercise_user_status = exercise.get_exercise_status(current_user) #当前用户的能看到的试卷 - if (exercise_user_status == exercise_status) || exercise_status == Exercise::ENDED #未发布的情况 + if (exercise_user_status == exercise_status) || exercise_status == Exercise::DEADLINE #未发布的情况 unpublish_group = unpublish_group + user_groups_id end else @@ -1527,7 +1527,7 @@ class ExercisesController < ApplicationController ex_group_settings = ex_all_group_settings.exercise_group_published.pluck(:course_group_id).uniq #问卷设置的班级 if exercise_status == Exercise::UNPUBLISHED unpublish_group = user_groups_id - ex_group_settings - elsif exercise_status == Exercise::ENDED + elsif exercise_status == Exercise::DEADLINE ex_ended_groups = ex_all_group_settings.exercise_group_ended.pluck(:course_group_id).uniq ex_and_user = user_groups_id & ex_group_settings #用户已设置的分班 unpublish_group = unpublish_group + ex_and_user - ex_ended_groups #已发布的全部班级减去截止的全部班级 @@ -1627,7 +1627,7 @@ class ExercisesController < ApplicationController def check_exercise_public if @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生,试卷公开统计,且已截止,且已提交 ex_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first - unless @exercise.get_exercise_status(current_user) == Exercise::ENDED && ex_user.present? && ex_user.commit_status == 1 && + unless @exercise.get_exercise_status(current_user) == Exercise::DEADLINE && ex_user.present? && ex_user.commit_status == 1 && @exercise.show_statistic normal_status(-1,"学生暂不能查看") end @@ -1650,7 +1650,7 @@ class ExercisesController < ApplicationController ex_question_random = exercise.question_random question_answered = 0 exercise_questions.each_with_index do |q,index| - if ex_question_random && exercise_user_status != Exercise::ENDED + if ex_question_random && exercise_user_status != Exercise::DEADLINE ques_number = index + 1 else ques_number = q.question_number diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 3e73931e0..92816d68b 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -89,6 +89,7 @@ module ExercisesHelper questions.each do |ex| ex_total_score = user_ids.count * ex&.question_score #该试卷的已回答的总分 ex_answers = ex.exercise_answers + if ex.question_type != Exercise::PRACTICAL ques_title = ex.question_title ques_less_title = nil @@ -98,13 +99,16 @@ module ExercisesHelper ques_less_title = ex.question_title effictive_users = ex.exercise_shixun_answers.search_shixun_answers("user_id",user_ids) end - effictive_users_count = effictive_users.count #有效回答数,可能有重复的用户id,这里仅统计是否回答这个问题的全部人数 + + effictive_users_count = effictive_users.size #有效回答数,可能有重复的用户id,这里仅统计是否回答这个问题的全部人数 ex_answered_scores = effictive_users.score_reviewed.pluck(:score).sum #该问题的全部得分 + if ex_total_score == 0.0 percent = 0.0 else percent = (ex_answered_scores / ex_total_score.to_f).round(3) * 100 #正确率 end + question_answer_infos = [] if ex.question_type <= Exercise::JUDGMENT #单选题 standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id) #标准答案的位置 diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 79701767f..e7d141ea9 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -135,7 +135,7 @@ class Exercise < ApplicationRecord if pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now status = Exercise::PUBLISHED elsif ed_time.present? && ed_time <= Time.now - status = Exercise::ENDED + status = Exercise::DEADLINE else status = Exercise::UNPUBLISHED end From 0e4bc4d4ce5ecdca0039de5101fd09a2b988008d Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Mon, 15 Jul 2019 16:15:56 +0800 Subject: [PATCH 0787/1015] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=B5=84=E6=96=99?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=9D=83=E9=99=90=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users/base_account_controller.rb | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/app/controllers/users/base_account_controller.rb b/app/controllers/users/base_account_controller.rb index 5c474517d..0d6bb24ec 100644 --- a/app/controllers/users/base_account_controller.rb +++ b/app/controllers/users/base_account_controller.rb @@ -1,15 +1,8 @@ class Users::BaseAccountController < Users::BaseController - before_action :require_login, :check_auth + before_action :require_login def observed_user @_observed_user ||= (User.find_by_id(params[:account_id]) || User.find_by_login(params[:account_id])) end - private - - def require_login - return if User.current.logged? - - tip_exception(401, "..") - end end From 5fa762085f47ae848c02358585edd7cf28aeb835 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 15 Jul 2019 16:18:01 +0800 Subject: [PATCH 0788/1015] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 1e18b8be6..c27a57c90 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -47,19 +47,19 @@ class CoursesController < ApplicationController @order = params[:order].present? ? params[:order] : "all" order_str = @order != "course_members_count" && @order != "created_at" ? "updated_at" : @order - if @order == "all" + # if @order == "all" # @course = Course.where(is_delete: 0, is_hidden: 0).select("select c.name, c.id, s.name, u.login, ifnull(concat(u.lastname,u.firstname), # u.login), s.name from courses c, users u, user_extensions ue, schools s where c.is_delete=0 and # c.tea_id=u.id and u.id=ue.user_id and ue.school_id=s.id") - @courses = Course.where(is_delete: 0, is_hidden: 0) - .order("courses.id = 1309 desc, courses.created_at desc") + # @courses = Course.where(is_delete: 0, is_hidden: 0) + # .order("courses.id = 1309 desc, courses.created_at desc") # @courses = Course.where(is_delete: 0, is_hidden: 0).select("courses.id, courses.tea_id, courses.name, courses.exercises_count, courses.polls_count, # courses.is_public, courses.is_end, courses.visits, courses.course_members_count,courses.homework_commons_count,(SELECT MAX(created_at) # FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a") # .order("courses.id = 1309 desc, a desc") - elsif @order == "mine" + if @order == "mine" @courses = Course.joins(:course_members) .where("is_delete = 0 AND is_hidden = 0 AND course_members.user_id = ?", @user.id) .order("courses.id = 1309 DESC, courses.#{order_str} DESC") @@ -86,7 +86,7 @@ class CoursesController < ApplicationController (course_members.role in(1,2,3) and CONCAT(users.lastname, users.firstname) like :keyword) or courses.name like :keyword or schools.name like :keyword } - @courses = @courses.joins(:school, course_members: [user: :user_extension]) + @courses = @courses.joins(:school, course_members: :user) .where("#{sql}", keyword: "%#{params[:search]}%").distinct end @courses_count = @courses.size From 560332ab0951dc7d7e48642bb4e95880173303fe Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 15 Jul 2019 16:46:40 +0800 Subject: [PATCH 0789/1015] fixbug --- app/helpers/exercises_helper.rb | 20 ++++++++++++++----- .../exercises/exercise_result.json.jbuilder | 1 + app/views/exercises/index.json.jbuilder | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 92816d68b..7d50d1a66 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -216,10 +216,19 @@ module ExercisesHelper ex.exercise_shixun_challenges.each do |c| cha_score = c&.question_score cha_shixun_answer = effictive_users.search_shixun_keys("exercise_shixun_challenge_id",c.id) - effictive_users_count = cha_shixun_answer.count #实训题的每个关卡的有效填写量 - full_scores = cha_shixun_answer.search_shixun_keys("score",cha_score).count #满分人数 - no_full_scores = cha_shixun_answer.shixun_no_full_scores(cha_score).count #部分分数人数c - all_zero_scores = cha_shixun_answer.search_shixun_keys("score",0.0).count #满分人数 + effictive_users_count = cha_shixun_answer.size #实训题的每个关卡的有效填写量 + full_scores = cha_shixun_answer.search_shixun_keys("score",cha_score).size #满分人数 + no_full_scores = cha_shixun_answer.shixun_no_full_scores(cha_score).size #部分分数人数c + all_zero_scores = cha_shixun_answer.search_shixun_keys("score",0.0).size #零分人数 + shiun_scores = user_ids.count * cha_score + shixun_answered_scores = cha_shixun_answer.score_reviewed.pluck(:score).sum #该问题的全部得分 + + if shixun_answered_scores == 0.0 + game_percent = 0.0 + else + game_percent = (shixun_answered_scores / shiun_scores.to_f).round(3) * 100 #正确率 + end + shixun_score_array = [full_scores,no_full_scores,all_zero_scores] shixun_chas = [] shixun_score_array.each_with_index do |s,index| @@ -242,7 +251,8 @@ module ExercisesHelper :cha_id => c.challenge_id, :cha_name => c.challenge.subject, :cha_position => c.position, - :cha_details => shixun_chas + :cha_details => shixun_chas, + :cha_percent => game_percent } question_answer_infos.push(shixun_new_chas) end diff --git a/app/views/exercises/exercise_result.json.jbuilder b/app/views/exercises/exercise_result.json.jbuilder index 2428e57c7..7f2d871fc 100644 --- a/app/views/exercises/exercise_result.json.jbuilder +++ b/app/views/exercises/exercise_result.json.jbuilder @@ -48,6 +48,7 @@ json.commit_results do json.challenge_id cha[:cha_id] json.challenge_name cha[:cha_name] json.challenge_position cha[:cha_position] + json.challenge_percent cha[:cha_percent] json.challenge_details do json.array! cha[:cha_details] do |ch| json.choice_position ch[:choice_position] diff --git a/app/views/exercises/index.json.jbuilder b/app/views/exercises/index.json.jbuilder index bccce4f2b..e5da76786 100644 --- a/app/views/exercises/index.json.jbuilder +++ b/app/views/exercises/index.json.jbuilder @@ -36,7 +36,7 @@ json.exercises_counts do json.exercises_all_counts @exercises_select_count #选择后的全部试卷数 json.exercises_unpublish_counts @exercises_unpublish_counts #未发布试卷数 json.exercises_published_counts @exercises_published_counts #已发布试卷数 - json.exercises_ended_counts @exercises_ended_counts #已截止试卷数 + # json.exercises_ended_counts @exercises_ended_counts #已截止试卷数 json.left_banner_id @left_banner_id json.left_banner_name @left_banner_name end From e655d36ed128ecf1fecf27dd2c1b9664af3003a1 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 15 Jul 2019 17:02:28 +0800 Subject: [PATCH 0790/1015] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=A4=B4=E5=83=8F?= =?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/users/avatars_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/users/avatars_controller.rb b/app/controllers/users/avatars_controller.rb index 6d161ba94..3b8c4be84 100644 --- a/app/controllers/users/avatars_controller.rb +++ b/app/controllers/users/avatars_controller.rb @@ -28,6 +28,6 @@ class Users::AvatarsController < Users::BaseAccountController end def avatar_url - ApplicationController.helpers.url_to_avatar(observed_user) + ApplicationController.helpers.url_to_avatar(observed_user).to_s + "?#{Time.now.to_i}" end end From 5a3ac8958c014c53c0c4f0183889884c44fefb93 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 15 Jul 2019 17:22:54 +0800 Subject: [PATCH 0791/1015] fixbug --- app/controllers/exercises_controller.rb | 2 +- app/helpers/exercises_helper.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 79b22d571..fe04e04f8 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1390,7 +1390,7 @@ class ExercisesController < ApplicationController if @paging_type == "percent" @question_result_hash = ques_result_all.sort_by{|s| s[:percent]} else - @question_result_hash = ques_result_all.sort_by{|s| s["#{@paging_type}"]} + @question_result_hash = ques_result_all.sort_by{|s| s[:"#{@paging_type}"]} end @exercise_questions_count = @exercise_questions.size diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 7d50d1a66..280f571a4 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -220,13 +220,13 @@ module ExercisesHelper full_scores = cha_shixun_answer.search_shixun_keys("score",cha_score).size #满分人数 no_full_scores = cha_shixun_answer.shixun_no_full_scores(cha_score).size #部分分数人数c all_zero_scores = cha_shixun_answer.search_shixun_keys("score",0.0).size #零分人数 - shiun_scores = user_ids.count * cha_score + shixun_scores = user_ids.count * cha_score shixun_answered_scores = cha_shixun_answer.score_reviewed.pluck(:score).sum #该问题的全部得分 if shixun_answered_scores == 0.0 - game_percent = 0.0 + game_percent = "0.0" else - game_percent = (shixun_answered_scores / shiun_scores.to_f).round(3) * 100 #正确率 + game_percent = (shixun_answered_scores / shixun_scores.to_f).round(3) * 100 #正确率 end shixun_score_array = [full_scores,no_full_scores,all_zero_scores] @@ -234,7 +234,7 @@ module ExercisesHelper shixun_score_array.each_with_index do |s,index| right_answer = (index == 0) if effictive_users_count == 0 - score_percent = 0.0 + score_percent = "0.0" else score_percent = (s.to_i / effictive_users_count.to_f ).round(3) end From a75483d8f29e8b8b9c559ce9f33615000b4e16d8 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 15 Jul 2019 17:27:18 +0800 Subject: [PATCH 0792/1015] fixbug --- app/helpers/exercises_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 280f571a4..be71aedab 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -234,7 +234,7 @@ module ExercisesHelper shixun_score_array.each_with_index do |s,index| right_answer = (index == 0) if effictive_users_count == 0 - score_percent = "0.0" + score_percent = 0.0 else score_percent = (s.to_i / effictive_users_count.to_f ).round(3) end From 8378e4db8ff3f3fe42bc95822c30c317dc486204 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 15 Jul 2019 17:32:30 +0800 Subject: [PATCH 0793/1015] =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E5=A4=B4=E5=83=8Fu?= =?UTF-8?q?rl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/_user.json.jbuilder | 2 +- db/migrate/20190715073825_add_test_for_challenges.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20190715073825_add_test_for_challenges.rb diff --git a/app/views/users/_user.json.jbuilder b/app/views/users/_user.json.jbuilder index afec979a1..66ea1530e 100644 --- a/app/views/users/_user.json.jbuilder +++ b/app/views/users/_user.json.jbuilder @@ -3,5 +3,5 @@ json.login user.login json.name user.full_name json.grade user.grade # json.email user.mail # 邮箱原则上不暴露的,如果实在需要的话只能对某些具体的接口公开 -json.image_url url_to_avatar(user) +json.image_url image_url(url_to_avatar(user)) json.school user.school_name \ No newline at end of file diff --git a/db/migrate/20190715073825_add_test_for_challenges.rb b/db/migrate/20190715073825_add_test_for_challenges.rb new file mode 100644 index 000000000..e7e9bbe80 --- /dev/null +++ b/db/migrate/20190715073825_add_test_for_challenges.rb @@ -0,0 +1,9 @@ +class AddTestForChallenges < ActiveRecord::Migration[5.2] + def change + challenge_answers = ChallengeAnswer.all + byebug + challenge_answers.find_each do |ca| + puts() + end + end +end From e3385daeba4c1532a78d08bb8c7e9b54d089e6a4 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 15 Jul 2019 17:32:54 +0800 Subject: [PATCH 0794/1015] 1 --- db/migrate/20190715073825_add_test_for_challenges.rb | 9 --------- 1 file changed, 9 deletions(-) delete mode 100644 db/migrate/20190715073825_add_test_for_challenges.rb diff --git a/db/migrate/20190715073825_add_test_for_challenges.rb b/db/migrate/20190715073825_add_test_for_challenges.rb deleted file mode 100644 index e7e9bbe80..000000000 --- a/db/migrate/20190715073825_add_test_for_challenges.rb +++ /dev/null @@ -1,9 +0,0 @@ -class AddTestForChallenges < ActiveRecord::Migration[5.2] - def change - challenge_answers = ChallengeAnswer.all - byebug - challenge_answers.find_each do |ca| - puts() - end - end -end From b7b69e2d0e929d1c6f371badbbc0b2e5b034b026 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 15 Jul 2019 17:35:10 +0800 Subject: [PATCH 0795/1015] =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/_user.json.jbuilder | 2 +- app/views/users/get_user_info.json.jbuilder | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/views/users/_user.json.jbuilder b/app/views/users/_user.json.jbuilder index 66ea1530e..afec979a1 100644 --- a/app/views/users/_user.json.jbuilder +++ b/app/views/users/_user.json.jbuilder @@ -3,5 +3,5 @@ json.login user.login json.name user.full_name json.grade user.grade # json.email user.mail # 邮箱原则上不暴露的,如果实在需要的话只能对某些具体的接口公开 -json.image_url image_url(url_to_avatar(user)) +json.image_url url_to_avatar(user) json.school user.school_name \ No newline at end of file diff --git a/app/views/users/get_user_info.json.jbuilder b/app/views/users/get_user_info.json.jbuilder index 779d58e95..fe8400ffd 100644 --- a/app/views/users/get_user_info.json.jbuilder +++ b/app/views/users/get_user_info.json.jbuilder @@ -1,7 +1,9 @@ json.username @user.full_name json.login @user.login json.user_id @user.id -json.image_url url_to_avatar(@user) +json.image_url image_url(url_to_avatar(@user)) +json.image_path image_path(url_to_avatar(@user)) +json.image_tag image_tag(url_to_avatar(@user)) json.admin @user.admin? json.is_teacher @user.user_extension&.teacher? json.tidding_count 0 From 70f3dfdaa3a9bf04f37e448621ad3a0274bfb0f0 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Mon, 15 Jul 2019 17:35:18 +0800 Subject: [PATCH 0796/1015] =?UTF-8?q?git=E6=96=87=E4=BB=B6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 019b690b5..0aa23d836 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -653,6 +653,7 @@ class ShixunsController < ApplicationController content = params[:content] author_name = current_user.full_name author_email = current_user.mail + Rails.logger.info("###222333####{content}") @content = update_file_content content, @repo_path, @path, author_email, author_name, "Edit by browser" end From a13a1c328c7aaff62fdec5c5e063d893eae0ed66 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 15 Jul 2019 17:40:14 +0800 Subject: [PATCH 0797/1015] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/get_user_info.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/get_user_info.json.jbuilder b/app/views/users/get_user_info.json.jbuilder index fe8400ffd..ba53d0c2a 100644 --- a/app/views/users/get_user_info.json.jbuilder +++ b/app/views/users/get_user_info.json.jbuilder @@ -1,7 +1,7 @@ json.username @user.full_name json.login @user.login json.user_id @user.id -json.image_url image_url(url_to_avatar(@user)) +json.image_url url_to_avatar(@user) json.image_path image_path(url_to_avatar(@user)) json.image_tag image_tag(url_to_avatar(@user)) json.admin @user.admin? From 1857679d41f1a5458eaea223e4233edef3e1e60b Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 15 Jul 2019 17:41:21 +0800 Subject: [PATCH 0798/1015] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E4=BB=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/get_user_info.json.jbuilder | 1 - 1 file changed, 1 deletion(-) diff --git a/app/views/users/get_user_info.json.jbuilder b/app/views/users/get_user_info.json.jbuilder index ba53d0c2a..2e1fad2e6 100644 --- a/app/views/users/get_user_info.json.jbuilder +++ b/app/views/users/get_user_info.json.jbuilder @@ -2,7 +2,6 @@ json.username @user.full_name json.login @user.login json.user_id @user.id json.image_url url_to_avatar(@user) -json.image_path image_path(url_to_avatar(@user)) json.image_tag image_tag(url_to_avatar(@user)) json.admin @user.admin? json.is_teacher @user.user_extension&.teacher? From d11f780bd8ed360b093138aca4cb14ff1c8853a0 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 15 Jul 2019 17:42:07 +0800 Subject: [PATCH 0799/1015] =?UTF-8?q?500=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/get_user_info.json.jbuilder | 1 - 1 file changed, 1 deletion(-) diff --git a/app/views/users/get_user_info.json.jbuilder b/app/views/users/get_user_info.json.jbuilder index 2e1fad2e6..779d58e95 100644 --- a/app/views/users/get_user_info.json.jbuilder +++ b/app/views/users/get_user_info.json.jbuilder @@ -2,7 +2,6 @@ json.username @user.full_name json.login @user.login json.user_id @user.id json.image_url url_to_avatar(@user) -json.image_tag image_tag(url_to_avatar(@user)) json.admin @user.admin? json.is_teacher @user.user_extension&.teacher? json.tidding_count 0 From 1802ac252bc21c5f9ef25b291abf97d780b216c7 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Mon, 15 Jul 2019 17:42:55 +0800 Subject: [PATCH 0800/1015] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 276fbef32..5163824c3 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -260,6 +260,8 @@ class MyshixunsController < ApplicationController # 远程版本库文件内容 last_content = GitService.file_content(repo_path: @repo_path, path: path)["content"] content = params[:content] + Rails.logger.info("###11222333####{content}") + Rails.logger.info("###222333####{last_content}") if content != last_content @content_modified = 1 From 7b476de0ef08cea2509b5c95fc79d364dc830162 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Mon, 15 Jul 2019 17:50:16 +0800 Subject: [PATCH 0801/1015] test --- app/controllers/myshixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 5163824c3..0df82118d 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -276,7 +276,7 @@ class MyshixunsController < ApplicationController message: message, content: content, author_name: author_name, - author_email: author_email) + author_email: "author_email@email.com") end end From f7db0a73809a340d9f700028a09029840beb15df Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Mon, 15 Jul 2019 18:07:39 +0800 Subject: [PATCH 0802/1015] =?UTF-8?q?git=20=E6=9B=B4=E6=96=B0=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E7=9A=84=E6=97=B6=E5=80=99=E5=A6=82=E6=9E=9C=E9=82=AE?= =?UTF-8?q?=E7=AE=B1=E4=B8=BA=E7=A9=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 4 ++-- app/helpers/application_helper.rb | 3 ++- app/models/user.rb | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 0df82118d..31395def2 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -267,7 +267,7 @@ class MyshixunsController < ApplicationController @content_modified = 1 author_name = current_user.real_name - author_email = current_user.mail + author_email = current_user.git_mail message = params[:evaluate] == 0 ? "System automatically submitted" : "User submitted" uid_logger("112233#{author_name}") uid_logger("112233#{author_email}") @@ -276,7 +276,7 @@ class MyshixunsController < ApplicationController message: message, content: content, author_name: author_name, - author_email: "author_email@email.com") + author_email: author_email) end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index cdd647ebd..993c132dc 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -30,8 +30,9 @@ module ApplicationHelper end # git用户 + # git用户命名规则:login+"@educoder.net" def git_username(email) - User.find_by_mail(email) + User.find_by_mail(email) || User.find_by_login(mail.split("@").first) end # 不同的类型扩展不同的目录 diff --git a/app/models/user.rb b/app/models/user.rb index 26f0fa544..89918551e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -156,6 +156,9 @@ class User < ApplicationRecord Token.where(:user_id => id, :action => 'session', :value => value).delete_all end + def git_mail + mail || "#{login}@educoder.net" + end # 学号 def student_id From 5522194d5f65c3047341f367afd07c4cb5a5ed1b Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Mon, 15 Jul 2019 18:11:12 +0800 Subject: [PATCH 0803/1015] .. --- app/helpers/application_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 993c132dc..4c3a449e9 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -32,7 +32,7 @@ module ApplicationHelper # git用户 # git用户命名规则:login+"@educoder.net" def git_username(email) - User.find_by_mail(email) || User.find_by_login(mail.split("@").first) + User.find_by_mail(email) || User.find_by_login(email.split("@").first) end # 不同的类型扩展不同的目录 From c257ad7456e259721efeb1aa7cec4939c83081b8 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Mon, 15 Jul 2019 18:15:22 +0800 Subject: [PATCH 0804/1015] =?UTF-8?q?=E7=BC=96=E8=BE=91tpi=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 0aa23d836..8f6dd23a4 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -652,8 +652,7 @@ class ShixunsController < ApplicationController def update_file content = params[:content] author_name = current_user.full_name - author_email = current_user.mail - Rails.logger.info("###222333####{content}") + author_email = current_user.git_mail @content = update_file_content content, @repo_path, @path, author_email, author_name, "Edit by browser" end From f1943707060914f781d5875cf903fc9a104225c4 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Mon, 15 Jul 2019 18:20:20 +0800 Subject: [PATCH 0805/1015] add log --- app/controllers/shixuns_controller.rb | 1 + app/models/user.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 8f6dd23a4..d6a142a22 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -653,6 +653,7 @@ class ShixunsController < ApplicationController content = params[:content] author_name = current_user.full_name author_email = current_user.git_mail + Rails.logger.info("111111#######{author_email}") @content = update_file_content content, @repo_path, @path, author_email, author_name, "Edit by browser" end diff --git a/app/models/user.rb b/app/models/user.rb index 89918551e..a41043ceb 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -157,6 +157,7 @@ class User < ApplicationRecord end def git_mail + Rails.logger.info("111111#######{mail} #222222222####{login}") mail || "#{login}@educoder.net" end From 194d7ee8d6a77d58d61190da77ad3112d4839bce Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Mon, 15 Jul 2019 18:26:24 +0800 Subject: [PATCH 0806/1015] git update file --- app/controllers/shixuns_controller.rb | 1 - app/models/user.rb | 1 - 2 files changed, 2 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index d6a142a22..8f6dd23a4 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -653,7 +653,6 @@ class ShixunsController < ApplicationController content = params[:content] author_name = current_user.full_name author_email = current_user.git_mail - Rails.logger.info("111111#######{author_email}") @content = update_file_content content, @repo_path, @path, author_email, author_name, "Edit by browser" end diff --git a/app/models/user.rb b/app/models/user.rb index a41043ceb..89918551e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -157,7 +157,6 @@ class User < ApplicationRecord end def git_mail - Rails.logger.info("111111#######{mail} #222222222####{login}") mail || "#{login}@educoder.net" end From 9787d70f9299b79ed18c9bdedd1a785abe7cae2e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 15 Jul 2019 18:33:05 +0800 Subject: [PATCH 0807/1015] fixbug --- app/helpers/exercises_helper.rb | 39 +++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index be71aedab..c9c213c47 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -86,10 +86,10 @@ module ExercisesHelper #试卷的统计结果页面计算各题的 def exercise_commit_result(questions,user_ids) question_infos = [] + percent = 0.0 questions.each do |ex| ex_total_score = user_ids.count * ex&.question_score #该试卷的已回答的总分 ex_answers = ex.exercise_answers - if ex.question_type != Exercise::PRACTICAL ques_title = ex.question_title ques_less_title = nil @@ -103,15 +103,23 @@ module ExercisesHelper effictive_users_count = effictive_users.size #有效回答数,可能有重复的用户id,这里仅统计是否回答这个问题的全部人数 ex_answered_scores = effictive_users.score_reviewed.pluck(:score).sum #该问题的全部得分 - if ex_total_score == 0.0 - percent = 0.0 - else - percent = (ex_answered_scores / ex_total_score.to_f).round(3) * 100 #正确率 + if ex.question_type > Exercise::COMPLETION #当为主观题和实训题时, + if ex_total_score != 0.0 + percent = (ex_answered_scores / ex_total_score.to_f).round(3) * 100 #正确率 + end end question_answer_infos = [] - if ex.question_type <= Exercise::JUDGMENT #单选题 - standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id) #标准答案的位置 + if ex.question_type <= Exercise::JUDGMENT #选择题和判断题 + standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置 + right_users_count = 0 #该问题的回答正确的人数 + user_ids.each do |user_id| + user_an_choice = effictive_users.where(user_id:user_id).pluck(:exercise_choice_id).sort + if user_an_choice == standard_answer + right_users_count += 1 + end + end + percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 ex.exercise_choices.each do |c| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id) @@ -125,7 +133,7 @@ module ExercisesHelper :choice_position => c.choice_position, :choice_text => c.choice_text, :choice_users_count => answer_users_count, - :choice_percent => answer_percent.round(1), + :choice_percent => answer_percent.round(1).to_s, :right_answer => right_answer } question_answer_infos.push(answer_option) @@ -161,13 +169,14 @@ module ExercisesHelper :choice_position => index+1, :choice_text => s_choice_text, :choice_users_count => user_count, - :choice_percent => answer_percent.round(1), + :choice_percent => answer_percent.round(1).to_s, :right_answer => true } question_answer_infos.push(answer_option) all_user_count += user_count standard_answer_count += 1 end + percent = effictive_users_count > 0 ? (all_user_count / effictive_users_count.to_f).round(3)*100 : 0.0 user_wrong_count = (effictive_users_count - all_user_count ) if effictive_users_count > 0 && user_wrong_count >= 0 @@ -179,7 +188,7 @@ module ExercisesHelper :choice_position => (standard_answer_count + 1), :choice_text => "wrong", :choice_users_count => user_wrong_count, - :choice_percent => wrong_percent.round(1), + :choice_percent => wrong_percent.round(1).to_s, :right_answer => false } question_answer_infos.push(wrong_answer_position) @@ -188,12 +197,10 @@ module ExercisesHelper full_scores = effictive_users.search_exercise_answer("score",ex_score).count #满分人数 no_full_scores = effictive_users.exercise_no_full_scores(ex_score).count #部分分数人数 zero_scores = effictive_users.search_exercise_answer("score",0.0).count #包含为0分的,及未评阅的 - # review_scores = ex.exercise_answer_comments.count #主观题的评阅数量 un_review_scores = effictive_users_count - full_scores - no_full_scores - zero_scores #未评阅数 if un_review_scores < 0 un_review_scores = 0 end - # zero_scores = all_zero_scores - un_review_scores #已评阅,且答案未0分的人数 main_scores_array = [full_scores,no_full_scores,zero_scores,un_review_scores] main_scores_array.each_with_index do |s,index| right_answer = (index == 0) @@ -207,7 +214,7 @@ module ExercisesHelper :choice_position => index+1, :choice_text => index+1, :choice_users_count => s, - :choice_percent => score_percent.round(1), + :choice_percent => score_percent.round(1).to_s, :right_answer => right_answer } question_answer_infos.push(answer_option) @@ -224,7 +231,7 @@ module ExercisesHelper shixun_answered_scores = cha_shixun_answer.score_reviewed.pluck(:score).sum #该问题的全部得分 if shixun_answered_scores == 0.0 - game_percent = "0.0" + game_percent = 0.0 else game_percent = (shixun_answered_scores / shixun_scores.to_f).round(3) * 100 #正确率 end @@ -242,7 +249,7 @@ module ExercisesHelper :choice_position => index+1, :choice_text => index+1, :choice_users_count => s, - :choice_percent => score_percent.round(1), + :choice_percent => score_percent.round(1).to_s, :right_answer => right_answer } shixun_chas.push(answer_option) @@ -252,7 +259,7 @@ module ExercisesHelper :cha_name => c.challenge.subject, :cha_position => c.position, :cha_details => shixun_chas, - :cha_percent => game_percent + :cha_percent => game_percent.round(1).to_s } question_answer_infos.push(shixun_new_chas) end From 1bdffb56cdf8947eb78ce4db9ddb42a0cd3e27d2 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 15 Jul 2019 18:43:12 +0800 Subject: [PATCH 0808/1015] fixbug --- app/helpers/exercises_helper.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index c9c213c47..a416dfcbe 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -113,9 +113,15 @@ module ExercisesHelper if ex.question_type <= Exercise::JUDGMENT #选择题和判断题 standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置 right_users_count = 0 #该问题的回答正确的人数 + + #计算每个问题的答案人数 user_ids.each do |user_id| - user_an_choice = effictive_users.where(user_id:user_id).pluck(:exercise_choice_id).sort - if user_an_choice == standard_answer + user_an_choice = ex_answers.where(user_id:user_id) + answer_choice_array = [] + user_an_choice.each do |a| + answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置 + end + if answer_choice_array == standard_answer right_users_count += 1 end end From d82a12d84b1bab94ae57096ce7461998f6129ab6 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 16 Jul 2019 09:14:49 +0800 Subject: [PATCH 0809/1015] =?UTF-8?q?=E6=B3=A8=E5=86=8C=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 e2df181f0..8b6469089 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -31,7 +31,7 @@ class AccountsController < ApplicationController phone = nil verifi_code = VerificationCode.where(email: email, code: code, code_type: 8).last end - uid_logger("start register: verifi_code is #{verifi_code}, code is #{code}, time is #{Time.now.to_i - verifi_code.created_at.to_i}") + 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) unless check_code tip_exception("验证码无效") From e23e7678e61c89a952fbb07d8fc28859d3f92dd7 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 09:17:25 +0800 Subject: [PATCH 0810/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E7=BB=93=E6=9E=9C=E9=A1=B5=E9=9D=A2=EF=BC=8C=E9=80=89?= =?UTF-8?q?=E6=8B=A9=E9=A2=98=E7=9A=84=E6=AD=A3=E7=A1=AE=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index a416dfcbe..6eb798d9a 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -116,12 +116,8 @@ module ExercisesHelper #计算每个问题的答案人数 user_ids.each do |user_id| - user_an_choice = ex_answers.where(user_id:user_id) - answer_choice_array = [] - user_an_choice.each do |a| - answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置 - end - if answer_choice_array == standard_answer + answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + if answer_choice_array.sort == standard_answer right_users_count += 1 end end @@ -129,7 +125,7 @@ module ExercisesHelper ex.exercise_choices.each do |c| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id) - answer_users_count = answer_this_choice.count + answer_users_count = answer_this_choice.size if effictive_users_count == 0 answer_percent = 0.0 else @@ -170,7 +166,6 @@ module ExercisesHelper else answer_percent = (user_count / effictive_users_count.to_f ).round(3) end - answer_option = { :choice_position => index+1, :choice_text => s_choice_text, @@ -200,9 +195,9 @@ module ExercisesHelper question_answer_infos.push(wrong_answer_position) elsif ex.question_type == Exercise::SUBJECTIVE #主观题 ex_score = ex&.question_score - full_scores = effictive_users.search_exercise_answer("score",ex_score).count #满分人数 - no_full_scores = effictive_users.exercise_no_full_scores(ex_score).count #部分分数人数 - zero_scores = effictive_users.search_exercise_answer("score",0.0).count #包含为0分的,及未评阅的 + full_scores = effictive_users.search_exercise_answer("score",ex_score).size #满分人数 + no_full_scores = effictive_users.exercise_no_full_scores(ex_score).size #部分分数人数 + zero_scores = effictive_users.search_exercise_answer("score",0.0).size #包含为0分的,及未评阅的 un_review_scores = effictive_users_count - full_scores - no_full_scores - zero_scores #未评阅数 if un_review_scores < 0 un_review_scores = 0 @@ -415,7 +410,7 @@ module ExercisesHelper 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.count > 0 + if standard_answer.size > 0 q_score_1 = q.question_score # q_score_1 = (q.question_score.to_f / standard_answer.count) #当多选答案正确时,每个answer的分数均摊。 else From 9a859c567547f5e183d1355fd41c2aea5b01c020 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 09:21:33 +0800 Subject: [PATCH 0811/1015] fixbug --- app/helpers/exercises_helper.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 6eb798d9a..1dd6c7452 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -115,13 +115,14 @@ module ExercisesHelper right_users_count = 0 #该问题的回答正确的人数 #计算每个问题的答案人数 - user_ids.each do |user_id| - answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq - if answer_choice_array.sort == standard_answer - right_users_count += 1 - end - end - percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 + # user_ids.each do |user_id| + # answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + # if answer_choice_array.sort == standard_answer + # right_users_count += 1 + # end + # end + # percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 + percent = 0.0 ex.exercise_choices.each do |c| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id) From a56da584d1fa4e1c2bb9c028bea67e9e592c9037 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 09:29:17 +0800 Subject: [PATCH 0812/1015] fixbug --- app/controllers/exercises_controller.rb | 6 +++--- app/helpers/exercises_helper.rb | 15 +++++++-------- app/models/exercise.rb | 5 ++--- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index fe04e04f8..09b237221 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -203,13 +203,13 @@ class ExercisesController < ApplicationController else @is_teacher_or = 1 @user_exercise_answer = 3 #教师页面 - @user_commit_counts = @exercise.exercise_users.where(commit_status:1).count #已提交的用户数 + @user_commit_counts = @exercise.exercise_users.where(commit_status:1).size #已提交的用户数 end @ex_status = @exercise.get_exercise_status(current_user) exercise_id_array = [@exercise.id] - @exercise_publish_count = get_user_permission_course(exercise_id_array,2).count #是否存在已发布的 - @exercise_unpublish_count = get_user_permission_course(exercise_id_array,1).count #是否存在未发布的 + @exercise_publish_count = get_user_permission_course(exercise_id_array,2).size #是否存在已发布的 + @exercise_unpublish_count = get_user_permission_course(exercise_id_array,1).size #是否存在未发布的 if (@exercise_publish_count == 0) && (@exercise_unpublish_count == 0) #即表示没有分班 if @ex_status == 1 diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 1dd6c7452..6eb798d9a 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -115,14 +115,13 @@ module ExercisesHelper right_users_count = 0 #该问题的回答正确的人数 #计算每个问题的答案人数 - # user_ids.each do |user_id| - # answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq - # if answer_choice_array.sort == standard_answer - # right_users_count += 1 - # end - # end - # percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 - percent = 0.0 + user_ids.each do |user_id| + answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + if answer_choice_array.sort == standard_answer + right_users_count += 1 + end + end + percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 ex.exercise_choices.each do |c| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index e7d141ea9..a46fded25 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -178,13 +178,12 @@ class Exercise < ApplicationRecord ex_answer_user = exercise_users.where(user_id: user.id).select(:start_at,:end_at,:commit_status) user_ex_status = get_exercise_status(user) user_status = 2 - if ex_answer_user.exists? && (ex_answer_user.first&.start_at.present? || ex_answer_user.first&.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 + if ex_answer_user.present? && (ex_answer_user.first&.start_at.present? || ex_answer_user.first&.end_at.present?) #学生有过答题的,或者立即截止,但学生未做试卷的 user_status = ex_answer_user.first.commit_status end - if ex_answer_user.exists? && ex_answer_user.first&.start_at.blank? && user_ex_status == 3 + if ex_answer_user.present? && ex_answer_user.first&.start_at.blank? && user_ex_status == 3 user_status = 4 end - user_status end From 4fbf6ad4e14e94e105c384a831b9d0bb20c0a4d5 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 16 Jul 2019 09:36:15 +0800 Subject: [PATCH 0813/1015] =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index e2df181f0..ae7335496 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -45,6 +45,8 @@ class AccountsController < ApplicationController @user.activate # 必须要用save操作,密码的保存是在users中 if @user.save! + # todo user_extension + UserExtension.create!(user_id: @user.id) # 注册完成,手机号或邮箱想可以奖励500金币 RewardGradeService.call( @user, From 81e52b9e18d9bcacda1a174feb29a08fa6aca7bb Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 16 Jul 2019 09:36:16 +0800 Subject: [PATCH 0814/1015] modify check mail and phone valid --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f9516b9e4..fbb1fef12 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -48,7 +48,7 @@ class ApplicationController < ActionController::Base # 考虑到安全参数问题,多一次查询,去掉Union user = User.where(phone: login).first || User.where(mail: login).first if type.to_i == 1 && !user.nil? - tip_exception("该手机号码或邮箱已被注册") + tip_exception(-2, "该手机号码或邮箱已被注册") elsif type.to_i == 2 && user.nil? tip_exception("该手机号码或邮箱未注册") end From 6998dd8286f3c0a2bb486e55c5519af7e2f66f3e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 09:36:35 +0800 Subject: [PATCH 0815/1015] fixbug --- app/controllers/exercises_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 09b237221..6eaa22f01 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1204,7 +1204,7 @@ class ExercisesController < ApplicationController #筛选/分类,排序 order = params[:order] - if @exercise_users_list.exists? && @exercise_users_list.size > 0 + if @exercise_users_list.present? && @exercise_users_list.size > 0 @exercise_users_count = @exercise_users_list.size #当前显示的全部成员数量 teacher_reviews = @exercise_users_list.exercise_review teacher_unreviews = @exercise_users_list.exercise_unreview From 8a78d0d3754a0e9a36c217af1c8192030d4aab2f Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 09:53:27 +0800 Subject: [PATCH 0816/1015] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 6eb798d9a..9ac02c82a 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -115,10 +115,12 @@ module ExercisesHelper right_users_count = 0 #该问题的回答正确的人数 #计算每个问题的答案人数 - user_ids.each do |user_id| - answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq - if answer_choice_array.sort == standard_answer - right_users_count += 1 + effictive_users.transaction do + user_ids.each do |user_id| + answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + if answer_choice_array.sort == standard_answer + right_users_count += 1 + end end end percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 From 6d535cd4bc057298e1b94b0d05dc9ebb258df5b7 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 16 Jul 2019 10:02:21 +0800 Subject: [PATCH 0817/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=90=88=E4=BD=9C=E8=80=85=E7=9A=84=E6=89=8B=E6=9C=BA=E6=90=9C?= =?UTF-8?q?=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 8f6dd23a4..599be4cde 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -662,8 +662,8 @@ class ShixunsController < ApplicationController school_name = "%#{params[:school_name].to_s.strip}%" if user_name.present? || school_name.present? @users = User.joins(user_extension: :school).where("users.id not in #{member_ids} AND users.status = 1 AND - LOWER(users.lastname) LIKE '#{user_name}' AND LOWER(schools.name) LIKE - '#{school_name}'") + (LOWER(users.lastname) LIKE ? or users.phone like ?) AND LOWER(schools.name) LIKE + ?", user_name, user_name, school_name) else @users = User.none end From 804fc5eea20fc717816b775f9cfa3c887ae230b7 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 10:19:55 +0800 Subject: [PATCH 0818/1015] fixbug --- app/controllers/exercises_controller.rb | 2 +- app/helpers/exercises_helper.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 6eaa22f01..39d793b5a 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1385,7 +1385,7 @@ class ExercisesController < ApplicationController @paging_type = params[:sort].to_s end - ques_result_all = exercise_commit_result(@exercise_questions,@exercise_commit_user_ids) + ques_result_all = exercise_commit_result(@exercise_questions,@exercise_commit_user_ids,@exercise_commit_users) if @paging_type == "percent" @question_result_hash = ques_result_all.sort_by{|s| s[:percent]} diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 9ac02c82a..24c296558 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -84,7 +84,7 @@ module ExercisesHelper end #试卷的统计结果页面计算各题的 - def exercise_commit_result(questions,user_ids) + def exercise_commit_result(questions,user_ids,commit_users) question_infos = [] percent = 0.0 questions.each do |ex| @@ -115,9 +115,9 @@ module ExercisesHelper right_users_count = 0 #该问题的回答正确的人数 #计算每个问题的答案人数 - effictive_users.transaction do - user_ids.each do |user_id| - answer_choice_array = effictive_users.where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + commit_users.transaction do + commit_users.each do |user| + answer_choice_array = effictive_users.select(:user_id).where(user_id:user.user_id)&.map {|s| s.exercise_choice.choice_position}.uniq if answer_choice_array.sort == standard_answer right_users_count += 1 end From 6af86402cbe654d395cb65e5f802557ec6c08772 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 10:22:18 +0800 Subject: [PATCH 0819/1015] fixbug --- app/helpers/exercises_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 24c296558..0cfcd5336 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -117,7 +117,7 @@ module ExercisesHelper #计算每个问题的答案人数 commit_users.transaction do commit_users.each do |user| - answer_choice_array = effictive_users.select(:user_id).where(user_id:user.user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user.user_id)&.map {|s| s.exercise_choice.choice_position}.uniq if answer_choice_array.sort == standard_answer right_users_count += 1 end From e480a8e2e54e1e2ebb13737d19a1e270c51ee802 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Tue, 16 Jul 2019 10:33:10 +0800 Subject: [PATCH 0820/1015] rep content is not exit --- app/controllers/games_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 217f1839a..e5cfaf2a6 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -490,7 +490,10 @@ class GamesController < ApplicationController uid_logger("--rep_content: path is #{path}") begin @content = git_fle_content(@myshixun.repo_path, path) || "" - rescue + rescue Exception => e + if e.status == -1 + tip_exception(-3, "#{e.message}") + end if params[:retry].to_i == 1 begin begin From 0e2ba6296779ef30ea024a3a939445457e426891 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 16 Jul 2019 10:36:22 +0800 Subject: [PATCH 0821/1015] =?UTF-8?q?=E6=B3=A8=E5=86=8C=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/user_extension.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user_extension.rb b/app/models/user_extension.rb index 458d31989..5a0dc8a37 100644 --- a/app/models/user_extension.rb +++ b/app/models/user_extension.rb @@ -3,7 +3,7 @@ class UserExtension < ApplicationRecord enum identity: { teacher: 0, student: 1, professional: 2, developer: 3 } belongs_to :user, touch: true - belongs_to :school + belongs_to :school, optional: true belongs_to :department, optional: true def identity_text From 6d6098452f2732e719a626024e1e33245eba01e8 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 10:37:39 +0800 Subject: [PATCH 0822/1015] fixbug --- app/controllers/exercises_controller.rb | 2 +- app/helpers/exercises_helper.rb | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 39d793b5a..6eaa22f01 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1385,7 +1385,7 @@ class ExercisesController < ApplicationController @paging_type = params[:sort].to_s end - ques_result_all = exercise_commit_result(@exercise_questions,@exercise_commit_user_ids,@exercise_commit_users) + ques_result_all = exercise_commit_result(@exercise_questions,@exercise_commit_user_ids) if @paging_type == "percent" @question_result_hash = ques_result_all.sort_by{|s| s[:percent]} diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 0cfcd5336..f5d341aae 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -84,12 +84,12 @@ module ExercisesHelper end #试卷的统计结果页面计算各题的 - def exercise_commit_result(questions,user_ids,commit_users) + def exercise_commit_result(questions,user_ids) question_infos = [] percent = 0.0 questions.each do |ex| ex_total_score = user_ids.count * ex&.question_score #该试卷的已回答的总分 - ex_answers = ex.exercise_answers + ex_answers = ex.exercise_answers.includes(:exercise_choice) if ex.question_type != Exercise::PRACTICAL ques_title = ex.question_title ques_less_title = nil @@ -115,12 +115,13 @@ module ExercisesHelper right_users_count = 0 #该问题的回答正确的人数 #计算每个问题的答案人数 - commit_users.transaction do - commit_users.each do |user| - answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user.user_id)&.map {|s| s.exercise_choice.choice_position}.uniq - if answer_choice_array.sort == standard_answer - right_users_count += 1 - end + # commit_users.transaction do + # + # end + user_ids.each do |user_id| + answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + if answer_choice_array.sort == standard_answer + right_users_count += 1 end end percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 From efa5e8b5bb79242a4e297227f07731ffe6c3e09c Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Tue, 16 Jul 2019 10:56:54 +0800 Subject: [PATCH 0823/1015] =?UTF-8?q?rep=20=E5=BC=82=E5=B8=B8=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=EF=BC=8C=E7=AB=8B=E5=8D=B3=E9=87=8D=E8=AF=95?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E5=90=8E=E5=8F=B0=E6=A3=80=E6=B5=8B=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 31 ++++++++++------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index e5cfaf2a6..c951340f8 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -477,7 +477,7 @@ class GamesController < ApplicationController # 获取版本库文件内容 # 注:如果本身path传错,内容肯定也为空;fork成功后,可能短时间内也获取不到版本库内容 # params[:status] 1: 目录树点击的请求 0:正常自动加载 - # 返回参数status : -3 需要重试,带retry参数;-1 给出提示 + # 返回参数status : -1 系统统一报错提示;-3 需要轮训重试,带retry参数;-4 立即重试 def rep_content challenge_path = @game.challenge.try(:path) if challenge_path.blank? @@ -491,24 +491,9 @@ class GamesController < ApplicationController begin @content = git_fle_content(@myshixun.repo_path, path) || "" rescue Exception => e - if e.status == -1 - tip_exception(-3, "#{e.message}") - end + # 思路: 异常首先应该考虑去恢复 if params[:retry].to_i == 1 begin - begin - # 检测TPM对应的路径代码是否正常 - git_fle_content(@myshixun.shixun.repo_path, path) - rescue Exception => e - uid_logger_error("#{e.message}") - # 如果已发布的TPM实训也不能获取到内容,那么肯定是版本库异常了 - if @myshixun.shixun.try(:status) < 2 - tip_exception("代码获取异常,请检查实训模板的评测设置是否正确") - else - tip_exception("代码获取异常,请联系系统管理员") - end - end - # 如果模板没有问题,则通过中间层检测实训仓库是否异常 # 监测版本库HEAD是否存在,不存在则取最新的HEAD gitUrl = repo_url @myshixun.repo_path @@ -531,11 +516,17 @@ class GamesController < ApplicationController end rescue Exception => e uid_logger_error(e.message) - # 报错继续retry - tip_exception(-3, "#{e.message}") + + if @myshixun.shixun.try(:status) < 2 + tip_exception("代码获取异常,请检查实训模板的评测设置是否正确") + else + # 报错继续retry + tip_exception(-3, "#{e.message}") + end end end - tip_exception(-3, "#{e.message}") + # 有异常了,立即重试 + tip_exception(-4, e.message) end end From a2779baf36794781c3606cb25abc919a8526d010 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 16 Jul 2019 11:02:10 +0800 Subject: [PATCH 0824/1015] =?UTF-8?q?=E9=80=89=E7=94=A8=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../homework_commons_controller.rb | 132 +++++++++++------- .../homework_commons/shixuns.json.jbuilder | 27 +++- 2 files changed, 103 insertions(+), 56 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 1f7433f8b..ccadba89c 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -822,66 +822,98 @@ class HomeworkCommonsController < ApplicationController @main_catrgory = @course.course_modules.where(module_type: "shixun_homework") @homework_category = @main_catrgory.take.course_second_categories - ## 我的实训 - @shixuns = - if params[:order_by] == 'mine' - current_user.my_shixuns.unhidden - else - if current_user.admin? - Shixun.unhidden - else - none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id) - - @shixuns = Shixun.where.not(id: none_shixun_ids).unhidden - end - end + search = params[:search] + type = params[:type] + # 超级管理员用户显示所有未隐藏的实训、非管理员显示所有已发布的实训(对本单位公开且未隐藏未关闭) + if current_user.admin? + @shixuns = Shixun.unhidden + else + none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id) - ## 方向 - if params[:tag_level].present? && params[:tag_id].present? - @shixuns = @shixuns.filter_tag(params[:tag_level].to_i, params[:tag_id].to_i) - case params[:tag_level].to_i - when 1 #大类 - @search_tags = Repertoire.find(params[:tag_id].to_i).name - when 2 #子类 - @search_tags = SubRepertoire.find(params[:tag_id].to_i).name - when 3 #tag - tag = TagRepertoire.find(params[:tag_id].to_i) - @search_tags = "#{tag.sub_repertoire.name} / #{tag.name}" - end + @shixuns = Shixun.where.not(id: none_shixun_ids).unhidden end - ## 搜索关键字创建者、实训名称、院校名称 - if params[:keyword].present? - keyword = params[:keyword].strip - @shixuns = @shixuns.joins(user: [user_extenison: :school]). - where("schools.name like '%#{keyword}%' - or concat(lastname, firstname) like '%#{keyword}%' - or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct - end + # 实训的所有标签 + @tags = TagRepertoire.select([:id, :name]).joins(:shixuns).where(shixuns: {id: @shixuns}).distinct - ## 筛选 难度 - if params[:diff].present? && params[:diff].to_i != 0 - @shixuns = @shixuns.where(trainee: params[:diff]) + if params[:search] && params[:search].strip != "" + @shixuns = @shixuns.joins(:user).where("shixuns.name like ? or concat(users.lastname, users.firstname) like ?", + "%#{search}%", "%#{search}%").distinct end - ## 排序参数 - bsort = params[:sort] || 'desc' - case params[:order_by] || 'hot' - when 'hot' - @shixuns = @shixuns.order("myshixuns_count #{bsort}") - when 'mine' - @shixuns = @shixuns.order("shixuns.created_at #{bsort}") - else - @shixuns = @shixuns.order("myshixuns_count #{bsort}") + unless type.blank? || type == "all" + @shixuns = @shixuns.joins(:shixun_tag_repertoires).where(shixun_tag_repertoires: {tag_repertoire_id: type}).distinct end - @total_count = @shixuns.count + @shixuns = @shixuns.select([:id, :name, :status, :myshixuns_count, :identifier, :user_id, :trainee]).reorder("shixuns.created_at desc") + @shixuns_count = @shixuns.size ## 分页参数 - page = params[:page] || 1 - limit = params[:limit] || 15 - - @shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(limit) + page = params[:page] || 1 + @shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(10) + + # 新版用下面的代码 + # ## 我的实训 + # @shixuns = + # if params[:order_by] == 'mine' + # current_user.my_shixuns.unhidden + # else + # if current_user.admin? + # Shixun.unhidden + # else + # none_shixun_ids = ShixunSchool.where("school_id != #{current_user.school_id}").pluck(:shixun_id) + # + # @shixuns = Shixun.where.not(id: none_shixun_ids).unhidden + # end + # end + # + # ## 方向 + # if params[:tag_level].present? && params[:tag_id].present? + # @shixuns = @shixuns.filter_tag(params[:tag_level].to_i, params[:tag_id].to_i) + # case params[:tag_level].to_i + # when 1 #大类 + # @search_tags = Repertoire.find(params[:tag_id].to_i).name + # when 2 #子类 + # @search_tags = SubRepertoire.find(params[:tag_id].to_i).name + # when 3 #tag + # tag = TagRepertoire.find(params[:tag_id].to_i) + # @search_tags = "#{tag.sub_repertoire.name} / #{tag.name}" + # end + # end + # + # ## 搜索关键字创建者、实训名称、院校名称 + # if params[:keyword].present? + # keyword = params[:keyword].strip + # @shixuns = @shixuns.joins(user: [user_extenison: :school]). + # where("schools.name like '%#{keyword}%' + # or concat(lastname, firstname) like '%#{keyword}%' + # or shixuns.name like '%#{keyword.split(" ").join("%")}%'").distinct + # end + # + # ## 筛选 难度 + # if params[:diff].present? && params[:diff].to_i != 0 + # @shixuns = @shixuns.where(trainee: params[:diff]) + # end + # + # ## 排序参数 + # bsort = params[:sort] || 'desc' + # case params[:order_by] || 'hot' + # when 'hot' + # @shixuns = @shixuns.order("myshixuns_count #{bsort}") + # when 'mine' + # @shixuns = @shixuns.order("shixuns.created_at #{bsort}") + # else + # @shixuns = @shixuns.order("myshixuns_count #{bsort}") + # end + # + # @total_count = @shixuns.count + # + # ## 分页参数 + # page = params[:page] || 1 + # limit = params[:limit] || 15 + # + # @shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(limit) + # end def create_shixun_homework diff --git a/app/views/homework_commons/shixuns.json.jbuilder b/app/views/homework_commons/shixuns.json.jbuilder index 8bfeea562..bd97f5e8d 100644 --- a/app/views/homework_commons/shixuns.json.jbuilder +++ b/app/views/homework_commons/shixuns.json.jbuilder @@ -1,12 +1,27 @@ +# json.shixun_list @shixuns do |shixun| +# json.shixun_identifier shixun.identifier +# json.name shixun.name +# json.creator shixun.user&.full_name +# json.creator_login shixun.user&.login +# json.school shixun.user&.school_name +# json.myshixuns_count shixun.myshixuns_count +# json.level level_to_s(shixun.trainee) +# json.challenge_tags shixun.challenge_tags_name +# end + json.shixun_list @shixuns do |shixun| - json.shixun_identifier shixun.identifier - json.name shixun.name - json.creator shixun.user&.full_name - json.creator_login shixun.user&.login - json.school shixun.user&.school_name + json.shixun_id shixun.id + json.identifier shixun.identifier + json.shixun_name shixun.name json.myshixuns_count shixun.myshixuns_count + json.school shixun.user&.school_name + json.creator shixun.user&.full_name json.level level_to_s(shixun.trainee) - json.challenge_tags shixun.challenge_tags_name +end + +json.tags @tags do |tag| + json.tag_id tag.id + json.tag_name tag.name end json.shixuns_count @total_count From b5ea3a60ca8536d65972cdea58025ed39778681c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 11:03:01 +0800 Subject: [PATCH 0825/1015] fixbug --- app/helpers/exercises_helper.rb | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index f5d341aae..8b0ad2ad5 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -113,17 +113,35 @@ module ExercisesHelper if ex.question_type <= Exercise::JUDGMENT #选择题和判断题 standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置 right_users_count = 0 #该问题的回答正确的人数 - - #计算每个问题的答案人数 - # commit_users.transaction do - # + # if ex.question_type == Exercise::MULTIPLE #多选题 + # user_ids.each do |user_id| + # answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + # if answer_choice_array.sort == standard_answer + # right_users_count += 1 + # end + # end + # else #单选题和判断题 + # user_ids.each do |user_id| + # answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice.choice_position + # if [answer_choice_array] == standard_answer + # right_users_count += 1 + # end + # end # end user_ids.each do |user_id| - answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq - if answer_choice_array.sort == standard_answer - right_users_count += 1 + if ex.question_type == Exercise::MULTIPLE + answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq + if answer_choice_array.sort == standard_answer + right_users_count += 1 + end + else + answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice.choice_position + if [answer_choice_array] == standard_answer + right_users_count += 1 + end end end + percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 ex.exercise_choices.each do |c| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 From 1aa5e6972eb4341e5f71400cf1659aef56a83fa4 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 11:06:20 +0800 Subject: [PATCH 0826/1015] fixbug --- app/helpers/exercises_helper.rb | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 8b0ad2ad5..7cd854d61 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -113,21 +113,6 @@ module ExercisesHelper if ex.question_type <= Exercise::JUDGMENT #选择题和判断题 standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置 right_users_count = 0 #该问题的回答正确的人数 - # if ex.question_type == Exercise::MULTIPLE #多选题 - # user_ids.each do |user_id| - # answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq - # if answer_choice_array.sort == standard_answer - # right_users_count += 1 - # end - # end - # else #单选题和判断题 - # user_ids.each do |user_id| - # answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice.choice_position - # if [answer_choice_array] == standard_answer - # right_users_count += 1 - # end - # end - # end user_ids.each do |user_id| if ex.question_type == Exercise::MULTIPLE answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq @@ -135,7 +120,7 @@ module ExercisesHelper right_users_count += 1 end else - answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice.choice_position + answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice&.choice_position if [answer_choice_array] == standard_answer right_users_count += 1 end From e132593ce7c06ad34b72a66ff2d119f98ef86992 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 11:11:16 +0800 Subject: [PATCH 0827/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=9A=84=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E7=BB=93=E6=9E=9C=E9=A1=B5=E9=9D=A2=EF=BC=8C=E5=A4=9A?= =?UTF-8?q?=E9=80=89=E9=A2=98=E7=9A=84=E6=AD=A3=E7=A1=AE=E7=8E=87=E7=9A=84?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 7cd854d61..dfb6e4237 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -113,13 +113,15 @@ module ExercisesHelper if ex.question_type <= Exercise::JUDGMENT #选择题和判断题 standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置 right_users_count = 0 #该问题的回答正确的人数 - user_ids.each do |user_id| - if ex.question_type == Exercise::MULTIPLE + if ex.question_type == Exercise::MULTIPLE #多选题 + user_ids.each do |user_id| answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq if answer_choice_array.sort == standard_answer right_users_count += 1 end - else + end + else #单选题和判断题 + user_ids.each do |user_id| answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice&.choice_position if [answer_choice_array] == standard_answer right_users_count += 1 From 4e8f18a30bd23fe70097b69b56587f2b888b8e7b Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 16 Jul 2019 13:43:03 +0800 Subject: [PATCH 0828/1015] enable elasticsearch && add elasticsearch config --- .gitignore | 1 + Gemfile | 2 +- Gemfile.lock | 14 ++++++++++++++ app/models/challenge_tag.rb | 3 +-- app/models/course.rb | 3 +-- app/models/memo.rb | 3 +-- app/models/searchable/memo.rb | 1 + app/models/searchable/shixun.rb | 2 +- app/models/searchable/subject.rb | 12 +++--------- app/models/shixun.rb | 3 +-- app/models/stage.rb | 3 +-- app/models/subject.rb | 3 +-- app/models/user.rb | 3 +-- config/elasticsearch.yml.example | 13 +++++++++++++ config/initializers/elasticsearch.rb | 2 ++ 15 files changed, 43 insertions(+), 25 deletions(-) create mode 100644 config/elasticsearch.yml.example create mode 100644 config/initializers/elasticsearch.rb diff --git a/.gitignore b/.gitignore index 4f52644ff..09b9eab36 100644 --- a/.gitignore +++ b/.gitignore @@ -44,6 +44,7 @@ /config/secrets.yml /config/redis.yml +/config/elasticsearch.yml public/upload.html /config/configuration.yml diff --git a/Gemfile b/Gemfile index 3450c06e8..4cabd09b9 100644 --- a/Gemfile +++ b/Gemfile @@ -90,4 +90,4 @@ gem 'sinatra' gem 'bulk_insert' # elasticsearch -# gem 'searchkick' +gem 'searchkick' diff --git a/Gemfile.lock b/Gemfile.lock index 728bbc672..94893687b 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -90,6 +90,14 @@ GEM connection_pool (2.2.2) crass (1.0.4) diff-lcs (1.3) + elasticsearch (7.2.0) + elasticsearch-api (= 7.2.0) + elasticsearch-transport (= 7.2.0) + elasticsearch-api (7.2.0) + multi_json + elasticsearch-transport (7.2.0) + faraday + multi_json erubi (1.7.1) execjs (2.7.0) faraday (0.15.4) @@ -100,6 +108,7 @@ GEM grape-entity (0.7.1) activesupport (>= 4.0) multi_json (>= 1.3.2) + hashie (3.6.0) htmlentities (4.3.4) httparty (0.16.2) multi_xml (>= 0.5.2) @@ -255,6 +264,10 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) + searchkick (3.1.3) + activemodel (>= 4.2) + elasticsearch (>= 5) + hashie selenium-webdriver (3.14.0) childprocess (~> 0.5) rubyzip (~> 1.2) @@ -344,6 +357,7 @@ DEPENDENCIES ruby-ole rubyzip sass-rails (~> 5.0) + searchkick selenium-webdriver sidekiq simple_xlsx_reader diff --git a/app/models/challenge_tag.rb b/app/models/challenge_tag.rb index b68e1792c..acea39770 100644 --- a/app/models/challenge_tag.rb +++ b/app/models/challenge_tag.rb @@ -1,6 +1,5 @@ class ChallengeTag < ApplicationRecord - # TODO: ES feature - # include Searchable::Dependents::ChallengeTag + include Searchable::Dependents::ChallengeTag belongs_to :challenge, counter_cache: true belongs_to :challenge_choose, optional: true diff --git a/app/models/course.rb b/app/models/course.rb index 77ff6c46d..b2835fc21 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -1,6 +1,5 @@ class Course < ApplicationRecord - # TODO: ES feature - # include Searchable::Course + include Searchable::Course has_many :boards, dependent: :destroy diff --git a/app/models/memo.rb b/app/models/memo.rb index 3cb074a78..610a7684d 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -1,6 +1,5 @@ class Memo < ApplicationRecord - # TODO: ES feature - # include Searchable::Memo + include Searchable::Memo has_many :memo_tag_repertoires, :dependent => :destroy has_many :tag_repertoires, :through => :memo_tag_repertoires diff --git a/app/models/searchable/memo.rb b/app/models/searchable/memo.rb index 5aa9d5fe2..648f4671b 100644 --- a/app/models/searchable/memo.rb +++ b/app/models/searchable/memo.rb @@ -26,6 +26,7 @@ module Searchable::Memo { descendants_contents: Util.map_or_pluck(descendants, :content) .map { |content| Util.extract_content(content)[0..Searchable::MAXIMUM_LENGTH] } + .join('
') } end diff --git a/app/models/searchable/shixun.rb b/app/models/searchable/shixun.rb index 1f39dcd76..e4108024c 100644 --- a/app/models/searchable/shixun.rb +++ b/app/models/searchable/shixun.rb @@ -31,7 +31,7 @@ module Searchable::Shixun .each_with_index.map { |subject, index| "第#{index + 1}关 #{subject}" } { - challenge_names: challenge_names, + challenge_names: challenge_names.join(' '), challenge_tag_names: Util.map_or_pluck(challenge_tags, :name).uniq.join(' ') } end diff --git a/app/models/searchable/subject.rb b/app/models/searchable/subject.rb index feec41a3c..94a5c1383 100644 --- a/app/models/searchable/subject.rb +++ b/app/models/searchable/subject.rb @@ -31,15 +31,9 @@ module Searchable::Subject end def searchable_stages_data - subject_stages = - stages.map do |stage| - { - name: stage.name, - description: Util.extract_content(stage.description)[0..Searchable::MAXIMUM_LENGTH] - } - end - - { subject_stages: subject_stages} + subject_stages = stages.map { |stage| "#{stage.name} #{Util.extract_content(stage.description)}"[0..Searchable::MAXIMUM_LENGTH] } + + { subject_stages: subject_stages.join('
') } end def to_searchable_json diff --git a/app/models/shixun.rb b/app/models/shixun.rb index 0925f4fa0..d274f0a6d 100644 --- a/app/models/shixun.rb +++ b/app/models/shixun.rb @@ -1,6 +1,5 @@ class Shixun < ApplicationRecord - # TODO: ES feature - # include Searchable::Shixun + include Searchable::Shixun # status: 0:编辑 1:申请发布 2:正式发布 3:关闭 -1:软删除 # hide_code: 隐藏代码窗口 diff --git a/app/models/stage.rb b/app/models/stage.rb index ee4e969dd..d255cddeb 100644 --- a/app/models/stage.rb +++ b/app/models/stage.rb @@ -1,6 +1,5 @@ class Stage < ApplicationRecord - # TODO: ES feature - # include Searchable::Dependents::Stage + include Searchable::Dependents::Stage belongs_to :subject, counter_cache: true diff --git a/app/models/subject.rb b/app/models/subject.rb index b9dd49f5a..064efb7a6 100644 --- a/app/models/subject.rb +++ b/app/models/subject.rb @@ -2,8 +2,7 @@ # 可以在初始创建的时候 class Subject < ApplicationRecord - # TODO: ES feature - # include Searchable::Subject + include Searchable::Subject #status :0 编辑中 1 审核中 2 发布 belongs_to :repertoire diff --git a/app/models/user.rb b/app/models/user.rb index 89918551e..fb1a47f2e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,7 +1,6 @@ class User < ApplicationRecord include Watchable - # TODO: ES feature - # include Searchable::Dependents::User + include Searchable::Dependents::User # Account statuses STATUS_ANONYMOUS = 0 diff --git a/config/elasticsearch.yml.example b/config/elasticsearch.yml.example new file mode 100644 index 000000000..cbecb85d7 --- /dev/null +++ b/config/elasticsearch.yml.example @@ -0,0 +1,13 @@ +defaults: &defaults + url: http://localhost:9200 + +development: + <<: *defaults + +test: + <<: *defaults + +production: + <<: *defaults + url: 'http://elastic:Elas+ucloud123@106.75.27.125:59200/' + # url: 'http://elastic:TEST_elastickibana321@es-cn-0pp174wsj000iubdx.public.elasticsearch.aliyuncs.com' diff --git a/config/initializers/elasticsearch.rb b/config/initializers/elasticsearch.rb new file mode 100644 index 000000000..5ab7d3e62 --- /dev/null +++ b/config/initializers/elasticsearch.rb @@ -0,0 +1,2 @@ +redis_config = Rails.application.config_for(:elasticsearch) +ENV['ELASTICSEARCH_URL'] = redis_config['url'] From 1821708642bbb25f9c82540dc2969a2e5209f20c Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 16 Jul 2019 13:43:46 +0800 Subject: [PATCH 0829/1015] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E6=8F=8F=E8=BF=B0=E5=9B=BE=E7=89=87=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...20190713022300_modify_md_attachment_url_for_md_cotents.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/db/migrate/20190713022300_modify_md_attachment_url_for_md_cotents.rb b/db/migrate/20190713022300_modify_md_attachment_url_for_md_cotents.rb index 188e017a5..3bc2d167c 100644 --- a/db/migrate/20190713022300_modify_md_attachment_url_for_md_cotents.rb +++ b/db/migrate/20190713022300_modify_md_attachment_url_for_md_cotents.rb @@ -26,5 +26,10 @@ class ModifyMdAttachmentUrlForMdCotents < ActiveRecord::Migration[5.2] subjects.find_each do |s| s.update_column(:description, s.description.gsub("![](/attachments/download", "![](/api/attachments")) if s.description.present? end + + plats = PlatformSample.where(samples_type: ['introduction', 'knowledge']) + plats.find_each do |p| + p.update_column(:contents, p.introduction.gsub("![](/attachments/download", "![](/api/attachments")) if p.introduction.present? + end end end From 895e76ead5005f47b75a1e524315dd355f0c61fa Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 16 Jul 2019 13:55:54 +0800 Subject: [PATCH 0830/1015] migrate change --- db/migrate/20190705085829_add_sec_key_to_outputs.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20190705085829_add_sec_key_to_outputs.rb b/db/migrate/20190705085829_add_sec_key_to_outputs.rb index 428fbaced..54d636757 100644 --- a/db/migrate/20190705085829_add_sec_key_to_outputs.rb +++ b/db/migrate/20190705085829_add_sec_key_to_outputs.rb @@ -1,5 +1,5 @@ class AddSecKeyToOutputs < ActiveRecord::Migration[5.2] def change - add_column :outputs, :sec_key, :string + # add_column :outputs, :sec_key, :string end end From e409eb4809760bc82a97ec99c41cf9cbcf957fd3 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 16 Jul 2019 13:57:08 +0800 Subject: [PATCH 0831/1015] fix --- db/migrate/20190705085829_add_sec_key_to_outputs.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20190705085829_add_sec_key_to_outputs.rb b/db/migrate/20190705085829_add_sec_key_to_outputs.rb index 54d636757..428fbaced 100644 --- a/db/migrate/20190705085829_add_sec_key_to_outputs.rb +++ b/db/migrate/20190705085829_add_sec_key_to_outputs.rb @@ -1,5 +1,5 @@ class AddSecKeyToOutputs < ActiveRecord::Migration[5.2] def change - # add_column :outputs, :sec_key, :string + add_column :outputs, :sec_key, :string end end From d9893fbdb279b1ac2a030ccd794a134227b8d227 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 16 Jul 2019 13:58:31 +0800 Subject: [PATCH 0832/1015] =?UTF-8?q?=E8=B0=83=E8=AF=95=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190713022300_modify_md_attachment_url_for_md_cotents.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20190713022300_modify_md_attachment_url_for_md_cotents.rb b/db/migrate/20190713022300_modify_md_attachment_url_for_md_cotents.rb index 3bc2d167c..99ea12309 100644 --- a/db/migrate/20190713022300_modify_md_attachment_url_for_md_cotents.rb +++ b/db/migrate/20190713022300_modify_md_attachment_url_for_md_cotents.rb @@ -29,7 +29,7 @@ class ModifyMdAttachmentUrlForMdCotents < ActiveRecord::Migration[5.2] plats = PlatformSample.where(samples_type: ['introduction', 'knowledge']) plats.find_each do |p| - p.update_column(:contents, p.introduction.gsub("![](/attachments/download", "![](/api/attachments")) if p.introduction.present? + p.update_column(:contents, p.contents.gsub("![](/attachments/download", "![](/api/attachments")) if p.introduction.present? end end end From 5e13fb19c7fa08bf5cd049514d59c0d39ff453fd Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 16 Jul 2019 14:01:01 +0800 Subject: [PATCH 0833/1015] =?UTF-8?q?=20=E8=BF=81=E7=A7=BB=E6=8A=A5?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190713022300_modify_md_attachment_url_for_md_cotents.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20190713022300_modify_md_attachment_url_for_md_cotents.rb b/db/migrate/20190713022300_modify_md_attachment_url_for_md_cotents.rb index 99ea12309..10b821fc5 100644 --- a/db/migrate/20190713022300_modify_md_attachment_url_for_md_cotents.rb +++ b/db/migrate/20190713022300_modify_md_attachment_url_for_md_cotents.rb @@ -29,7 +29,7 @@ class ModifyMdAttachmentUrlForMdCotents < ActiveRecord::Migration[5.2] plats = PlatformSample.where(samples_type: ['introduction', 'knowledge']) plats.find_each do |p| - p.update_column(:contents, p.contents.gsub("![](/attachments/download", "![](/api/attachments")) if p.introduction.present? + p.update_column(:contents, p.contents.gsub("![](/attachments/download", "![](/api/attachments")) if p.contents.present? end end end From db314d5ee9c337779f61f5e36c10c7f5cad52f50 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Tue, 16 Jul 2019 14:20:38 +0800 Subject: [PATCH 0834/1015] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E8=81=94=E5=8A=A8=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 599be4cde..a11f1c526 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -501,8 +501,8 @@ class ShixunsController < ApplicationController # TODO: 目前实训只做软删除. def destroy - # apply_records = ApplyAction.where(container_id: @shixun.id, container_type: "ApplyShixun") - # apply_records.delete_all if apply_records + apply_records = ApplyAction.where(container_id: @shixun.id, container_type: "ApplyShixun") + apply_records.delete_all if apply_records # HomeworkCommonShixuns.where(shixun_id: @shixun).delete_all # @shixun.destroy @shixun.update_column(:status, -1) From e5d6a7a4dd12ea36452c817aa016d5209d0464f3 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 16 Jul 2019 14:28:55 +0800 Subject: [PATCH 0835/1015] =?UTF-8?q?=E6=B3=A8=E5=86=8C=E8=B0=83=E6=95=B4?= 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 b429f3298..3020588e0 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -39,7 +39,7 @@ class AccountsController < ApplicationController code = generate_identifier User, 8 login = pre + code - @user = User.new(admin: false, login: login, mail: email, phone: phone) + @user = User.new(admin: false, login: login, mail: email, phone: phone, type: "User") @user.password = params[:password] # 现在因为是验证码,所以在注册的时候就可以激活 @user.activate From 5e83c0b8f4ccff2e8e63b383389305ad67565453 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 14:32:35 +0800 Subject: [PATCH 0836/1015] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 2 +- app/helpers/exercises_helper.rb | 33 +++++++++++++++---------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 6eaa22f01..c9aeba395 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1294,7 +1294,7 @@ class ExercisesController < ApplicationController def export_exercise @request_url = request.base_url @exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") - filename_ = "#{@exercise.user.real_name}_#{@course.name}__#{Time.now.strftime('%Y%m%d_%H%M%S')}" + filename_ = "#{@exercise.user.real_name}_#{@course.name}__#{Time.now.strftime('%Y%m%d_%H%M%S')}.pdf" stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css" render pdf: 'exercise_export/blank_exercise', filename: filename_, stylesheets: stylesheets end diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index dfb6e4237..b799fa40c 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -113,19 +113,26 @@ module ExercisesHelper if ex.question_type <= Exercise::JUDGMENT #选择题和判断题 standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置 right_users_count = 0 #该问题的回答正确的人数 - if ex.question_type == Exercise::MULTIPLE #多选题 - user_ids.each do |user_id| - answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).where(user_id:user_id)&.map {|s| s.exercise_choice.choice_position}.uniq - if answer_choice_array.sort == standard_answer - right_users_count += 1 - end - end - else #单选题和判断题 - user_ids.each do |user_id| - answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice&.choice_position - if [answer_choice_array] == standard_answer - right_users_count += 1 - end + # if ex.question_type == Exercise::MULTIPLE #多选题 + # user_ids.each do |user_id| + # answer_choice_array = ExerciseChoice.where(id:effictive_users.map{|e| e.exercise_choice_id if a.user_id == user_id}).pluck(:choice_position).uniq + # if answer_choice_array.sort == standard_answer + # right_users_count += 1 + # end + # end + # else #单选题和判断题 + # user_ids.each do |user_id| + # answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice&.choice_position + # if [answer_choice_array] == standard_answer + # right_users_count += 1 + # end + # end + # end + + user_ids.each do |user_id| + answer_choice_array = ExerciseChoice.where(id:effictive_users.map{|e| e.exercise_choice_id if a.user_id == user_id}).pluck(:choice_position).uniq + if answer_choice_array.sort == standard_answer + right_users_count += 1 end end From cf653740bacee97d228868632481a792a5585aa3 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 16 Jul 2019 14:36:07 +0800 Subject: [PATCH 0837/1015] fix --- app/controllers/accounts_controller.rb | 1 - app/controllers/attachments_controller.rb | 1 - app/controllers/concerns/controller_rescue_handler.rb | 4 ++++ app/controllers/concerns/error_common.rb | 10 ---------- app/models/searchable/shixun.rb | 4 ++-- 5 files changed, 6 insertions(+), 14 deletions(-) delete mode 100644 app/controllers/concerns/error_common.rb diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 3020588e0..7159c2bca 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -1,6 +1,5 @@ class AccountsController < ApplicationController - include ErrorCommon #skip_before_action :check_account, :only => [:logout] def index diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index c539b0a60..5132e203c 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -5,7 +5,6 @@ class AttachmentsController < ApplicationController before_action :require_login, :check_auth before_action :find_file, only: %i[show destroy] - include ErrorCommon include ApplicationHelper def show diff --git a/app/controllers/concerns/controller_rescue_handler.rb b/app/controllers/concerns/controller_rescue_handler.rb index 31934db03..71e2e9178 100644 --- a/app/controllers/concerns/controller_rescue_handler.rb +++ b/app/controllers/concerns/controller_rescue_handler.rb @@ -15,5 +15,9 @@ module ControllerRescueHandler rescue_from ActiveRecord::RecordInvalid do |ex| render_error(ex.record.errors.full_messages.join(',')) end + rescue_from Exception do |e| + logger.error e + render json: {status: -1, message: e.message} + end end end \ No newline at end of file diff --git a/app/controllers/concerns/error_common.rb b/app/controllers/concerns/error_common.rb deleted file mode 100644 index 5a5f41673..000000000 --- a/app/controllers/concerns/error_common.rb +++ /dev/null @@ -1,10 +0,0 @@ -module ErrorCommon - extend ActiveSupport::Concern - - included do - rescue_from Exception do |e| - logger.error e - render json: {status: -1, message: e.message} - end - end -end \ No newline at end of file diff --git a/app/models/searchable/shixun.rb b/app/models/searchable/shixun.rb index e4108024c..7abd76ec6 100644 --- a/app/models/searchable/shixun.rb +++ b/app/models/searchable/shixun.rb @@ -21,8 +21,8 @@ module Searchable::Shixun def searchable_user_data { - author_name: user.real_name, - author_school_name: user.school_name, + author_name: user&.real_name, + author_school_name: user&.school_name, } end From 2f70b763b3fadf0d6b41161c812bf218b802761f Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 16 Jul 2019 14:38:39 +0800 Subject: [PATCH 0838/1015] fix --- app/libs/util.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/libs/util.rb b/app/libs/util.rb index 7839b2304..6c7784606 100644 --- a/app/libs/util.rb +++ b/app/libs/util.rb @@ -39,6 +39,7 @@ module Util end def extract_content(str) + return '' if str.blank? str.gsub(/<\/?.*?>/, '').gsub(/[\n\t\r]/, '').gsub(/ /, '') end end \ No newline at end of file From 56f0a9bfb017d1684850fd8052156fe57434315e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 14:39:20 +0800 Subject: [PATCH 0839/1015] fixbug --- app/controllers/exercises_controller.rb | 2 +- app/helpers/exercises_helper.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index c9aeba395..6b2804716 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1294,7 +1294,7 @@ class ExercisesController < ApplicationController def export_exercise @request_url = request.base_url @exercise_questions = @exercise.exercise_questions.includes(:exercise_choices).order("question_number ASC") - filename_ = "#{@exercise.user.real_name}_#{@course.name}__#{Time.now.strftime('%Y%m%d_%H%M%S')}.pdf" + filename_ = "#{@exercise.user.real_name}_#{@course.name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}.pdf" stylesheets = "#{Rails.root}/app/templates/exercise_export/exercise_export.css" render pdf: 'exercise_export/blank_exercise', filename: filename_, stylesheets: stylesheets end diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index b799fa40c..61baac4be 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -130,7 +130,7 @@ module ExercisesHelper # end user_ids.each do |user_id| - answer_choice_array = ExerciseChoice.where(id:effictive_users.map{|e| e.exercise_choice_id if a.user_id == user_id}).pluck(:choice_position).uniq + answer_choice_array = ExerciseChoice.where(id:effictive_users.map{|e| e.exercise_choice_id if e.user_id == user_id}).pluck(:choice_position).uniq if answer_choice_array.sort == standard_answer right_users_count += 1 end From 518b05ddb9aa1383d72410ef45a10075be25cb64 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 16 Jul 2019 14:45:03 +0800 Subject: [PATCH 0840/1015] fix --- app/controllers/concerns/controller_rescue_handler.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/concerns/controller_rescue_handler.rb b/app/controllers/concerns/controller_rescue_handler.rb index 71e2e9178..bacd6a793 100644 --- a/app/controllers/concerns/controller_rescue_handler.rb +++ b/app/controllers/concerns/controller_rescue_handler.rb @@ -2,6 +2,10 @@ module ControllerRescueHandler extend ActiveSupport::Concern included do + rescue_from Exception do |e| + logger.error e + render json: {status: -1, message: e.message} + end # rescue_from ActionView::MissingTemplate, with: :object_not_found # rescue_from ActiveRecord::RecordNotFound, with: :object_not_found rescue_from Educoder::TipException, with: :tip_show @@ -15,9 +19,5 @@ module ControllerRescueHandler rescue_from ActiveRecord::RecordInvalid do |ex| render_error(ex.record.errors.full_messages.join(',')) end - rescue_from Exception do |e| - logger.error e - render json: {status: -1, message: e.message} - end end end \ No newline at end of file From 094a02163479010a0431b8ad1fe9449c44503543 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 16 Jul 2019 14:49:31 +0800 Subject: [PATCH 0841/1015] fix tiding url --- app/views/users/get_navigation_info.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/users/get_navigation_info.json.jbuilder b/app/views/users/get_navigation_info.json.jbuilder index 6b04a121c..586ddbd7c 100644 --- a/app/views/users/get_navigation_info.json.jbuilder +++ b/app/views/users/get_navigation_info.json.jbuilder @@ -10,7 +10,7 @@ json.top do json.new_project_url "#{@old_domain}/projects/new" json.join_course_url "#{@old_domain}/courses/join_course_multi_role" json.join_project_url "#{@old_domain}/applied_project/applied_project_info" - json.message_url "#{@user_url}/user_tidings" + json.message_url "#{@old_domain}#{@user_url}/user_tidings" json.new_message @new_message json.career_url do From 5fcd1693c8815fcc23701016210b6ab5f07e8c18 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 16 Jul 2019 15:02:24 +0800 Subject: [PATCH 0842/1015] modify --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index fbb1fef12..1dceb8ebe 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -43,7 +43,7 @@ class ApplicationController < ActionController::Base # params[:type] 1: 注册;2:忘记密码 def check_mail_and_phone_valid login, type unless login =~ /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/ || login =~ /^1\d{10}$/ - tip_exception("请输入正确的手机号或邮箱") + tip_exception(-2, "请输入正确的手机号或邮箱") end # 考虑到安全参数问题,多一次查询,去掉Union user = User.where(phone: login).first || User.where(mail: login).first From 85512465508c070d0a1579853988e8d24851d976 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 15:07:46 +0800 Subject: [PATCH 0843/1015] fixbug --- app/controllers/exercises_controller.rb | 28 ++++++++++--------------- app/controllers/polls_controller.rb | 20 ++++++++---------- app/helpers/exercises_helper.rb | 19 ++--------------- 3 files changed, 22 insertions(+), 45 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 6b2804716..0bc7658c5 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -689,7 +689,7 @@ class ExercisesController < ApplicationController ActiveRecord::Base.transaction do begin check_ids = Exercise.where(id: params[:check_ids]) - ex_end_time = params[:end_time] || Time.at(((1.month.since.to_i)/3600.0).ceil * 3600) + ex_end_time = params[:end_time].to_time check_ids.each do |exercise| if exercise.present? if exercise.unified_setting @@ -701,20 +701,13 @@ class ExercisesController < ApplicationController if ex_status == 1 #如果试卷存在已发布的,或者是已截止的,那么则直接跳过 g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数,那么试卷的统一设置需修改 if g_course - # course_groups = @course.teacher_course_groups.get_user_groups(current_user.id) - # - # if course_groups.blank? - # user_course_groups = @course.course_groups.present? ? @course.course_groups.pluck(:id) : [] - # else - # user_course_groups = course_groups.pluck(:course_group_id).reject(&:blank?).uniq - # end user_course_groups = @course.charge_group_ids(current_user) - - if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则试卷不用分组,且试卷设定为统一设置,否则则分组设置 exercise.exercise_group_settings.destroy_all ex_unified = true + e_time = ex_end_time else + e_time = exercise.exercise_group_settings.end_time_no_null.map(&:end_time).max ex_unified = false g_course.each do |i| exercise_group_setting = exercise.exercise_group_settings.find_in_exercise_group("course_group_id",i).first #根据课堂分班的id,寻找试卷所在的班级 @@ -732,20 +725,21 @@ class ExercisesController < ApplicationController new_exercise_group.save end end - group_ids = params[:group_ids] end else exercise.exercise_group_settings.destroy_all ex_unified = true - end - if exercise.end_time.blank? e_time = ex_end_time - elsif exercise.exercise_group_settings.end_time_no_null.count > 0 # 该试卷分组有结束时间为空的 - e_time = exercise.exercise_group_settings.end_time_no_null.map(&:end_time).max - else - e_time = exercise.end_time end + # if exercise.end_time.blank? + # e_time = ex_end_time + # elsif exercise.exercise_group_settings.end_time_no_null.count > 0 # 该试卷分组有结束时间为空的 + # e_time = exercise.exercise_group_settings.end_time_no_null.map(&:end_time).max + # else + # e_time = ex_end_time + # end + ex_status = set_exercise_status(Time.now,e_time) exercise_params = { :publish_time => Time.now, diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 70995fbcf..469c0bd4d 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -258,15 +258,12 @@ class PollsController < ApplicationController g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数,那么poll的统一设置需修改 if g_course user_course_groups = @course.charge_group_ids(current_user) - # if course_groups.blank? - # user_course_groups = @course.course_groups.present? ? @course.course_groups.pluck(:id) : [] - # else - # user_course_groups = course_groups.pluck(:course_group_id) - # end if g_course.map(&:to_i).sort == user_course_groups.sort # 如果是设置为全部班级,则问卷不用分组,且问卷设定为统一设置,否则则分组设置 poll.poll_group_settings.destroy_all poll_unified = true + e_time = ex_end_time else + e_time = poll.poll_group_settings.end_time_present.map(&:end_time).max poll_unified = false g_course.each do |i| poll_group_setting = poll.poll_group_settings.find_in_poll_group("course_group_id",i).first #根据课堂分班的id,寻找问卷所在的班级 @@ -289,14 +286,15 @@ class PollsController < ApplicationController else poll.poll_group_settings.destroy_all poll_unified = true - end - if poll.end_time.blank? e_time = ex_end_time - elsif poll.poll_group_settings.end_time_present.count > 0 # 该问卷分组有结束时间为空的 - e_time = poll.poll_group_settings.end_time_present.map(&:end_time).max - else - e_time = poll.end_time end + # if poll.end_time.blank? + # e_time = ex_end_time + # elsif poll.poll_group_settings.end_time_present.count > 0 # 该问卷分组有结束时间为空的 + # e_time = poll.poll_group_settings.end_time_present.map(&:end_time).max + # else + # e_time = poll.end_time + # end poll_status = set_poll_status(Time.now,e_time) poll_params = { diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 61baac4be..b10dc128b 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -87,7 +87,7 @@ module ExercisesHelper def exercise_commit_result(questions,user_ids) question_infos = [] percent = 0.0 - questions.each do |ex| + questions.includes(:exercise_choices).each do |ex| ex_total_score = user_ids.count * ex&.question_score #该试卷的已回答的总分 ex_answers = ex.exercise_answers.includes(:exercise_choice) if ex.question_type != Exercise::PRACTICAL @@ -113,24 +113,9 @@ module ExercisesHelper if ex.question_type <= Exercise::JUDGMENT #选择题和判断题 standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置 right_users_count = 0 #该问题的回答正确的人数 - # if ex.question_type == Exercise::MULTIPLE #多选题 - # user_ids.each do |user_id| - # answer_choice_array = ExerciseChoice.where(id:effictive_users.map{|e| e.exercise_choice_id if a.user_id == user_id}).pluck(:choice_position).uniq - # if answer_choice_array.sort == standard_answer - # right_users_count += 1 - # end - # end - # else #单选题和判断题 - # user_ids.each do |user_id| - # answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice&.choice_position - # if [answer_choice_array] == standard_answer - # right_users_count += 1 - # end - # end - # end user_ids.each do |user_id| - answer_choice_array = ExerciseChoice.where(id:effictive_users.map{|e| e.exercise_choice_id if e.user_id == user_id}).pluck(:choice_position).uniq + answer_choice_array = ex.exercise_choices.where(id:effictive_users.map{|e| e.exercise_choice_id if e.user_id == user_id}).pluck(:choice_position).uniq if answer_choice_array.sort == standard_answer right_users_count += 1 end From 97229718991fbb9258a57083fea301c25be6941e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 15:30:25 +0800 Subject: [PATCH 0844/1015] fixbug --- app/helpers/exercises_helper.rb | 10 ++++++---- app/models/game.rb | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index b10dc128b..32e5d1bfc 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -89,7 +89,7 @@ module ExercisesHelper percent = 0.0 questions.includes(:exercise_choices).each do |ex| ex_total_score = user_ids.count * ex&.question_score #该试卷的已回答的总分 - ex_answers = ex.exercise_answers.includes(:exercise_choice) + ex_answers = ex.exercise_answers if ex.question_type != Exercise::PRACTICAL ques_title = ex.question_title ques_less_title = nil @@ -111,18 +111,20 @@ module ExercisesHelper question_answer_infos = [] if ex.question_type <= Exercise::JUDGMENT #选择题和判断题 + ex_choices = ex.exercise_choices standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置 right_users_count = 0 #该问题的回答正确的人数 - user_ids.each do |user_id| - answer_choice_array = ex.exercise_choices.where(id:effictive_users.map{|e| e.exercise_choice_id if e.user_id == user_id}).pluck(:choice_position).uniq + ex_choice_ids = effictive_users.map{|e| e.exercise_choice_id if e.user_id == user_id}.reject(&:blank?).uniq + # answer_choice_array = ex_choices.where(id:ex_choice_ids).pluck(:choice_position) + answer_choice_array = ex_choices.map{|a| a.choice_position if ex_choice_ids.include?(a.id)}.reject(&:blank?).uniq if answer_choice_array.sort == standard_answer right_users_count += 1 end end percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 - ex.exercise_choices.each do |c| + ex_choices.each do |c| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id) answer_users_count = answer_this_choice.size diff --git a/app/models/game.rb b/app/models/game.rb index eed425ea6..002116748 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -31,7 +31,7 @@ class Game < ApplicationRecord # 根据得分比例来算实际得分(试卷、实训作业) def real_score score - final_score == challenge.score ? score : (final_score.to_f / challenge.score) * score + (final_score.to_f / challenge.all_score) * score end # 判断实训是否全部通关 From 4fd9279f79dad33a392778bc32242fd630c220bd Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 16 Jul 2019 15:40:49 +0800 Subject: [PATCH 0845/1015] user account info completed change --- app/models/user.rb | 9 --------- app/views/users/accounts/show.json.jbuilder | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index fb1a47f2e..49a3e9090 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -544,15 +544,6 @@ class User < ApplicationRecord Educoder::Utils.random_hex(16) end - # 基本资料是否完善 - def base_info_completed? - user_columns = %i[nickname lastname] - user_extension_columns = %i[gender location location_city identity school_id department] - - user_columns.all? { |column| public_send(column).present? } && - user_extension_columns.all? { |column| user_extension.send(column).present? } - end - # 全部已认证 def all_certified? authentication? && professional_certification? diff --git a/app/views/users/accounts/show.json.jbuilder b/app/views/users/accounts/show.json.jbuilder index fca883ea0..6b28bda55 100644 --- a/app/views/users/accounts/show.json.jbuilder +++ b/app/views/users/accounts/show.json.jbuilder @@ -21,5 +21,5 @@ json.school_name extension&.school&.name json.department_id extension&.department_id json.department_name extension&.department&.name -json.base_info_completed user.base_info_completed? +json.base_info_completed user.profile_completed? json.all_certified user.all_certified? From 8fd8da2e8ca329378573bbaf911148c95e078d3b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 16:00:56 +0800 Subject: [PATCH 0846/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0ABCD..?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 7 ------- .../exercise_questions/_exercise_questions.json.jbuilder | 3 +-- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 0bc7658c5..4319f2e4a 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -732,13 +732,6 @@ class ExercisesController < ApplicationController ex_unified = true e_time = ex_end_time end - # if exercise.end_time.blank? - # e_time = ex_end_time - # elsif exercise.exercise_group_settings.end_time_no_null.count > 0 # 该试卷分组有结束时间为空的 - # e_time = exercise.exercise_group_settings.end_time_no_null.map(&:end_time).max - # else - # e_time = ex_end_time - # end ex_status = set_exercise_status(Time.now,e_time) exercise_params = { diff --git a/app/views/exercise_questions/_exercise_questions.json.jbuilder b/app/views/exercise_questions/_exercise_questions.json.jbuilder index 4cdd97f3c..bfaf6b736 100644 --- a/app/views/exercise_questions/_exercise_questions.json.jbuilder +++ b/app/views/exercise_questions/_exercise_questions.json.jbuilder @@ -1,5 +1,4 @@ json.question_id question.id -# json.question_number question.question_number q_positon = question.question_number if ques_position.present? q_positon = ques_position @@ -22,7 +21,7 @@ if question.question_type <= 2 #当为选择题或判断题时,只显示选 user_answer_b = user_answer.include?(a.id) json.c_position (index+1) if ex_choice_random_boolean #当选项随机时,选项位置以此为准,否则不出现 json.choice_id a.id - json.choice_text a.choice_text + json.choice_text "#{(index+65).chr}.#{a.choice_text}" json.choice_position a.choice_position if exercise_type == 1 || exercise_type == 4 #1为教师编辑/预览 试卷或问题,2为空白试卷,即标准答案和用户答案都不显示,3为用户开始答题的显示,4为老师评阅试卷或学生在截止后查看试卷 json.standard_boolean standard_answer_b From 98ea54de41236d53b984df22d2162f86b4778433 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 16:15:13 +0800 Subject: [PATCH 0847/1015] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=9A=84=E9=80=89=E6=8B=A9=E5=BA=8F=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/exercises/exercise_result.json.jbuilder | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/views/exercises/exercise_result.json.jbuilder b/app/views/exercises/exercise_result.json.jbuilder index 7f2d871fc..38b03cccb 100644 --- a/app/views/exercises/exercise_result.json.jbuilder +++ b/app/views/exercises/exercise_result.json.jbuilder @@ -34,9 +34,16 @@ json.commit_results do json.effictive_counts q[:ques_effictive_counts] if q[:type] != Exercise::PRACTICAL json.ques_details do - json.array! q[:ques_details] do |d| + json.array! q[:ques_details].each_with_index.to_a do |d,index| + if q[:type] <= Exercise::MULTIPLE + ques_index = (index+65).chr + elsif q[:type] == Exercise::JUDGMENT + ques_index = (index+1).to_s + else + ques_index = "" + end json.choice_position d[:choice_position] - json.choice_text d[:choice_text] + json.choice_text "#{ques_index}.#{d[:choice_text]}" json.choice_users_count d[:choice_users_count] json.choice_percent d[:choice_percent] json.choice_right_boolean d[:right_answer] @@ -50,9 +57,9 @@ json.commit_results do json.challenge_position cha[:cha_position] json.challenge_percent cha[:cha_percent] json.challenge_details do - json.array! cha[:cha_details] do |ch| + json.array! cha[:cha_details].each_with_index.to_a do |ch,index| json.choice_position ch[:choice_position] - json.choice_text ch[:choice_text] + json.choice_text "#{(index+1).to_s}.#{ch[:choice_text]}" json.choice_users_count ch[:choice_users_count] json.choice_percent ch[:choice_percent] json.choice_right_boolean ch[:right_answer] From a2832d44a1a055cf2a9bea016715d854944c924f Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Tue, 16 Jul 2019 16:25:00 +0800 Subject: [PATCH 0848/1015] fixbug --- app/views/exercises/exercise_result.json.jbuilder | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/exercises/exercise_result.json.jbuilder b/app/views/exercises/exercise_result.json.jbuilder index 38b03cccb..2c4b3ded7 100644 --- a/app/views/exercises/exercise_result.json.jbuilder +++ b/app/views/exercises/exercise_result.json.jbuilder @@ -40,10 +40,10 @@ json.commit_results do elsif q[:type] == Exercise::JUDGMENT ques_index = (index+1).to_s else - ques_index = "" + ques_index = nil end json.choice_position d[:choice_position] - json.choice_text "#{ques_index}.#{d[:choice_text]}" + json.choice_text ques_index.present? ? "#{ques_index}.#{d[:choice_text]}" : d[:choice_text] json.choice_users_count d[:choice_users_count] json.choice_percent d[:choice_percent] json.choice_right_boolean d[:right_answer] @@ -57,9 +57,9 @@ json.commit_results do json.challenge_position cha[:cha_position] json.challenge_percent cha[:cha_percent] json.challenge_details do - json.array! cha[:cha_details].each_with_index.to_a do |ch,index| + json.array! cha[:cha_details] do |ch| json.choice_position ch[:choice_position] - json.choice_text "#{(index+1).to_s}.#{ch[:choice_text]}" + json.choice_text ch[:choice_text] json.choice_users_count ch[:choice_users_count] json.choice_percent ch[:choice_percent] json.choice_right_boolean ch[:right_answer] From 7df20dfa797e882010fc61c532432aefa1dcae34 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 16 Jul 2019 16:57:11 +0800 Subject: [PATCH 0849/1015] competition list, show, staff api --- app/controllers/application_controller.rb | 4 ++ .../competitions/base_controller.rb | 11 +++++ .../competition_staffs_controller.rb | 4 ++ .../competitions/competitions_controller.rb | 32 +++++++++++++++ app/controllers/concerns/paginate_helper.rb | 8 ++++ app/decorators/application_decorator.rb | 9 +++++ app/decorators/competition_decorator.rb | 6 +++ .../competition_stage_section_decorator.rb | 5 +++ app/models/competition.rb | 40 +++++++++++++++++++ app/models/competition_entry.rb | 4 ++ app/models/competition_module.rb | 7 ++++ app/models/competition_module_md_content.rb | 5 +++ app/models/competition_staff.rb | 3 ++ app/models/competition_stage.rb | 7 ++++ app/models/competition_stage_section.rb | 6 +++ app/models/competition_team.rb | 8 ++++ app/models/team_member.rb | 8 ++++ .../competition_staffs/show.json.jbuilder | 26 ++++++++++++ .../competitions/index.json.jbuilder | 29 ++++++++++++++ .../competitions/show.json.jbuilder | 36 +++++++++++++++++ config/routes.rb | 8 ++++ 21 files changed, 266 insertions(+) create mode 100644 app/controllers/competitions/base_controller.rb create mode 100644 app/controllers/competitions/competition_staffs_controller.rb create mode 100644 app/controllers/competitions/competitions_controller.rb create mode 100644 app/controllers/concerns/paginate_helper.rb create mode 100644 app/decorators/application_decorator.rb create mode 100644 app/decorators/competition_decorator.rb create mode 100644 app/decorators/competition_stage_section_decorator.rb create mode 100644 app/models/competition.rb create mode 100644 app/models/competition_entry.rb create mode 100644 app/models/competition_module.rb create mode 100644 app/models/competition_module_md_content.rb create mode 100644 app/models/competition_staff.rb create mode 100644 app/models/competition_stage.rb create mode 100644 app/models/competition_stage_section.rb create mode 100644 app/models/competition_team.rb create mode 100644 app/models/team_member.rb create mode 100644 app/views/competitions/competition_staffs/show.json.jbuilder create mode 100644 app/views/competitions/competitions/index.json.jbuilder create mode 100644 app/views/competitions/competitions/show.json.jbuilder diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1dceb8ebe..ee42ab8b5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -30,6 +30,10 @@ class ApplicationController < ActionController::Base end end + def admin_or_business? + User.current.admin? || User.current.business? + end + def user_course_identity @user_course_identity = current_user.course_identity(@course) if @user_course_identity > Course::STUDENT && @course.is_public == 0 diff --git a/app/controllers/competitions/base_controller.rb b/app/controllers/competitions/base_controller.rb new file mode 100644 index 000000000..127474ee7 --- /dev/null +++ b/app/controllers/competitions/base_controller.rb @@ -0,0 +1,11 @@ +class Competitions::BaseController < ApplicationController + include PaginateHelper + + before_action :require_login + + helper_method :current_competition + + def current_competition + @_current_competition ||= Competition.find_by!(identifier: params[:competition_id].presence || params[:id]) + end +end \ No newline at end of file diff --git a/app/controllers/competitions/competition_staffs_controller.rb b/app/controllers/competitions/competition_staffs_controller.rb new file mode 100644 index 000000000..39b91e57f --- /dev/null +++ b/app/controllers/competitions/competition_staffs_controller.rb @@ -0,0 +1,4 @@ +class Competitions::CompetitionStaffsController < Competitions::BaseController + def show + end +end diff --git a/app/controllers/competitions/competitions_controller.rb b/app/controllers/competitions/competitions_controller.rb new file mode 100644 index 000000000..f962682a1 --- /dev/null +++ b/app/controllers/competitions/competitions_controller.rb @@ -0,0 +1,32 @@ +class Competitions::CompetitionsController < Competitions::BaseController + skip_before_action :require_login + + def index + # 已上架 或者 即将上架 + competitions = Competition.where(status: true).or(Competition.where.not(published_at: nil)) + + competitions = + case params[:category] + when 'nearly_published' then competitions.where(status: false) + when 'progressing' then competitions.where('end_time > NOW()') + when 'ended' then competitions.where('end_time < NOW()') + else competitions + end + + @count = competitions.count + + competitions = competitions.order(published_at: :desc, online_time: :desc) + @competitions = paginate(competitions.includes(current_stage_section: :competition_stage)) + + ids = @competitions.map(&:id) + @member_count_map = TeamMember.where(competition_id: ids).group(:competition_id).count + @stage_count_map = CompetitionStage.where(competition_id: ids).group(:competition_id).count + end + + def show + unless current_competition.published? || admin_or_business? + render_forbidden + return + end + end +end \ No newline at end of file diff --git a/app/controllers/concerns/paginate_helper.rb b/app/controllers/concerns/paginate_helper.rb new file mode 100644 index 000000000..13148bf42 --- /dev/null +++ b/app/controllers/concerns/paginate_helper.rb @@ -0,0 +1,8 @@ +module PaginateHelper + def paginate(objs, **opts) + page = params[:page].to_i <= 0 ? 1 : params[:page].to_i + per_page = params[:per_page].to_i > 0 ? params[:per_page].to_i : 20 + + Kaminari.paginate_array(objs).page(page).per(per_page) + end +end \ No newline at end of file diff --git a/app/decorators/application_decorator.rb b/app/decorators/application_decorator.rb new file mode 100644 index 000000000..ccaf720e5 --- /dev/null +++ b/app/decorators/application_decorator.rb @@ -0,0 +1,9 @@ +module ApplicationDecorator + def display_time_method(*columns, format: '%Y-%m-%d %H:%M:%S') + columns.each do |column_name| + define_method "display_#{column_name}" do + public_send(column_name)&.strftime(format) + end + end + end +end \ No newline at end of file diff --git a/app/decorators/competition_decorator.rb b/app/decorators/competition_decorator.rb new file mode 100644 index 000000000..2be5b3ecb --- /dev/null +++ b/app/decorators/competition_decorator.rb @@ -0,0 +1,6 @@ +module CompetitionDecorator + extend ApplicationDecorator + + display_time_method :start_time, :end_time, :enroll_end_time + +end diff --git a/app/decorators/competition_stage_section_decorator.rb b/app/decorators/competition_stage_section_decorator.rb new file mode 100644 index 000000000..1196cb9ad --- /dev/null +++ b/app/decorators/competition_stage_section_decorator.rb @@ -0,0 +1,5 @@ +module CompetitionStageSectionDecorator + extend ApplicationDecorator + + display_time_method :start_time, :end_time +end \ No newline at end of file diff --git a/app/models/competition.rb b/app/models/competition.rb new file mode 100644 index 000000000..9a85bda58 --- /dev/null +++ b/app/models/competition.rb @@ -0,0 +1,40 @@ +class Competition < ApplicationRecord + + has_many :competition_modules, dependent: :destroy + has_many :competition_stages, dependent: :destroy + has_many :competition_stage_sections, dependent: :destroy + has_one :current_stage_section, -> { where('end_time > NOW()') }, class_name: 'CompetitionStageSection' + has_many :team_members, dependent: :destroy + has_many :competition_staffs, dependent: :destroy + has_one :teacher_staff, -> { where(category: :teacher) }, class_name: 'CompetitionStaff' + has_one :member_staff, -> { where.not(category: :teacher) }, class_name: 'CompetitionStaff' + + has_many :attachments, as: :container + + after_create :create_competition_modules + + # 是否上架 + def published? + status? + end + + # 报名是否结束 + def enroll_ended? + enroll_end_time.blank? || enroll_end_time < Time.now + end + + # 是否已经报名 + def enrolled?(user) + team_members.exists?(user_id: user.id) + end + + private + + def create_competition_modules + CompetitionModule.bulk_insert(*%i[competition_id name position]) do |worker| + %w(首页 报名 通知公告 排行榜 资料下载).each_with_index do |name, index| + worker.add(competition_id: id, name: name, position: index + 1) + end + end + end +end diff --git a/app/models/competition_entry.rb b/app/models/competition_entry.rb new file mode 100644 index 000000000..685faca24 --- /dev/null +++ b/app/models/competition_entry.rb @@ -0,0 +1,4 @@ +class CompetitionEntry < ApplicationRecord + belongs_to :competition_stage + belongs_to :competition_stage_section +end \ No newline at end of file diff --git a/app/models/competition_module.rb b/app/models/competition_module.rb new file mode 100644 index 000000000..be73bf3c1 --- /dev/null +++ b/app/models/competition_module.rb @@ -0,0 +1,7 @@ +class CompetitionModule < ApplicationRecord + default_scope { order('position ASC') } + + belongs_to :competition + + has_one :competition_module_md_content, dependent: :destroy +end diff --git a/app/models/competition_module_md_content.rb b/app/models/competition_module_md_content.rb new file mode 100644 index 000000000..cbf5a829a --- /dev/null +++ b/app/models/competition_module_md_content.rb @@ -0,0 +1,5 @@ +class CompetitionModuleMdContent < ApplicationRecord + belongs_to :competition_module + + has_many :attachments, as: :container, dependent: :destroy +end \ No newline at end of file diff --git a/app/models/competition_staff.rb b/app/models/competition_staff.rb new file mode 100644 index 000000000..2630a5d3d --- /dev/null +++ b/app/models/competition_staff.rb @@ -0,0 +1,3 @@ +class CompetitionStaff < ApplicationRecord + belongs_to :competition +end \ No newline at end of file diff --git a/app/models/competition_stage.rb b/app/models/competition_stage.rb new file mode 100644 index 000000000..60d4b1644 --- /dev/null +++ b/app/models/competition_stage.rb @@ -0,0 +1,7 @@ +class CompetitionStage < ApplicationRecord + belongs_to :competition + + has_many :competition_stage_sections, dependent: :destroy + has_many :competition_entries, dependent: :destroy + +end \ No newline at end of file diff --git a/app/models/competition_stage_section.rb b/app/models/competition_stage_section.rb new file mode 100644 index 000000000..027e7ec69 --- /dev/null +++ b/app/models/competition_stage_section.rb @@ -0,0 +1,6 @@ +class CompetitionStageSection < ApplicationRecord + belongs_to :competition + belongs_to :competition_stage + + has_many :competition_entries, dependent: :destroy +end \ No newline at end of file diff --git a/app/models/competition_team.rb b/app/models/competition_team.rb new file mode 100644 index 000000000..aa19db3b0 --- /dev/null +++ b/app/models/competition_team.rb @@ -0,0 +1,8 @@ +class CompetitionTeam < ApplicationRecord + belongs_to :user + belongs_to :competition + + has_many :team_members, dependent: :destroy + has_many :members, -> { without_teachers }, class_name: 'TeamMember' + has_many :teachers, -> { only_teachers }, class_name: 'TeamMember' +end \ No newline at end of file diff --git a/app/models/team_member.rb b/app/models/team_member.rb new file mode 100644 index 000000000..3909325e8 --- /dev/null +++ b/app/models/team_member.rb @@ -0,0 +1,8 @@ +class TeamMember < ApplicationRecord + belongs_to :user + belongs_to :competition + belongs_to :competition_team + + scope :only_teachers, -> { where(is_teacher: true) } + scope :without_teachers, -> { where(is_teacher: false) } +end \ No newline at end of file diff --git a/app/views/competitions/competition_staffs/show.json.jbuilder b/app/views/competitions/competition_staffs/show.json.jbuilder new file mode 100644 index 000000000..2cba22d2f --- /dev/null +++ b/app/views/competitions/competition_staffs/show.json.jbuilder @@ -0,0 +1,26 @@ +competition = current_competition + +json.enroll_ended competition.enroll_ended? +json.enrolled competition.enrolled?(current_user) + +# 教师报名设置 +if competition.teacher_staff.present? + json.teacher_staff do + json.minimum competition.teacher_staff.minimum + json.maximum competition.teacher_staff.maximum + json.mutiple_limited competition.teacher_staff.mutiple_limited + end +else + json.teacher_staff nil +end + +# 教师报名设置 +if competition.member_staff.present? + json.member_staff do + json.minimum competition.member_staff.minimum + json.maximum competition.member_staff.maximum + json.mutiple_limited competition.member_staff.mutiple_limited + end +else + json.member_staff nil +end diff --git a/app/views/competitions/competitions/index.json.jbuilder b/app/views/competitions/competitions/index.json.jbuilder new file mode 100644 index 000000000..f0d70f69e --- /dev/null +++ b/app/views/competitions/competitions/index.json.jbuilder @@ -0,0 +1,29 @@ +json.count @count +json.competitions do + json.array! @competitions.each do |competition| + json.extract! competition, :id, :identifier, :name, :sub_title + + json.visits_count competition.visits + member_count = @member_count_map&.fetch(competition.id, 0) || competition.team_members.count + json.member_count member_count.zero? ? 268 : member_count + + json.image url_to_avatar(competition) + json.published competition.published? + json.nearly_published competition.published_at.present? + json.single_stage (@stage_count_map&.fetch(competition.id, 0) || competition.competition_stages.count) == 1 + + json.start_time competition.display_start_time + json.end_time competition.display_end_time + json.enroll_end_time competition.display_enroll_end_time + + section = competition.current_stage_section + if section + json.current_stage do + + json.name = section.competition_stage.name + json.start_time section.display_start_time + json.end_time section.display_end_time + end + end + end +end \ No newline at end of file diff --git a/app/views/competitions/competitions/show.json.jbuilder b/app/views/competitions/competitions/show.json.jbuilder new file mode 100644 index 000000000..18216ee92 --- /dev/null +++ b/app/views/competitions/competitions/show.json.jbuilder @@ -0,0 +1,36 @@ +competition = current_competition +json.extract! competition, :id, :name, :sub_title, :identifier + +json.start_time competition.display_start_time +json.end_time competition.display_end_time +json.enroll_end_time competition.display_enroll_end_time + +json.images do + json.array! competition.attachments, partial: 'attachments/attachment_simple', as: :attachment +end + +json.competition_stages do + stages = competition.competition_stages.includes(competition_stage_sections: :competition_entries) + json.array! stages.each do |stage| + json.extract! stage, :id, :name + + json.sections do + json.array! stage.competition_stage_sections.each do |section| + json.extract! section, :id, :name + + decorator_section = ActiveDecorator::Decorator.instance.decorate(section) + json.start_time decorator_section.display_start_time + json.end_time decorator_section.display_end_time + + is_start = section.start_time > Time.now + json.entries do + json.array! section.competition_entries.each do |entry| + json.extract! entry, :id, :name + + json.url is_start ? entry.url : '' + end + end + end + end + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 676954600..90872faa8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -668,6 +668,14 @@ Rails.application.routes.draw do end resources :repertoires, only: [:index] + + scope module: :competitions do + resources :competitions, only: [:index, :show] do + resources :competition_modules, only: [:index, :show] + resource :competition_staff + resources :competition_teams, only: [:index, :show] + end + end end #git 认证回调 From 9cf393acb08588a671aa07fa16ffda4f4f3c2db1 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 16 Jul 2019 17:24:39 +0800 Subject: [PATCH 0850/1015] update user info api add professional logical && fix bug --- app/models/apply_user_authentication.rb | 1 + app/models/user.rb | 2 +- app/services/users/update_account_service.rb | 7 +++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/apply_user_authentication.rb b/app/models/apply_user_authentication.rb index 3907c3f16..c7fb5019e 100644 --- a/app/models/apply_user_authentication.rb +++ b/app/models/apply_user_authentication.rb @@ -6,4 +6,5 @@ class ApplyUserAuthentication < ApplicationRecord scope :real_name_auth, -> { where(auth_type: 1) } scope :professional_auth, -> { where(auth_type: 2) } scope :processing, -> { where(status: 0) } + scope :passed, -> { where(status: 1) } end diff --git a/app/models/user.rb b/app/models/user.rb index 49a3e9090..d089c49c3 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -58,7 +58,7 @@ class User < ApplicationRecord has_many :tidings, :dependent => :destroy has_many :games, :dependent => :destroy - has_many :created_subjects + has_many :created_subjects, foreign_key: :user_id, class_name: 'Subject' has_many :subjects, :through => :subject_members has_many :subject_members, :dependent => :destroy has_many :grades, :dependent => :destroy diff --git a/app/services/users/update_account_service.rb b/app/services/users/update_account_service.rb index 6a8588dee..d603cec8c 100644 --- a/app/services/users/update_account_service.rb +++ b/app/services/users/update_account_service.rb @@ -35,6 +35,13 @@ class Users::UpdateAccountService < ApplicationService extension.technical_title = params[:technical_title] end + # 职业、学校变动需要重新进行职业认证 + if extension.identity_changed? || extension.school_id_changed? + user.professional_certification = false + # 撤销之前的职业认证 + user.apply_user_authentication.professional_auth.passed.update_all(status: 3) + end + # 表示资料完整 user.profile_completed = true From 718320c8d4897113af0da956b4782d45a024eba3 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Tue, 16 Jul 2019 17:31:03 +0800 Subject: [PATCH 0851/1015] modify --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index ee42ab8b5..4bc3d5133 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -54,7 +54,7 @@ class ApplicationController < ActionController::Base if type.to_i == 1 && !user.nil? tip_exception(-2, "该手机号码或邮箱已被注册") elsif type.to_i == 2 && user.nil? - tip_exception("该手机号码或邮箱未注册") + tip_exception(-2, "该手机号码或邮箱未注册") end sucess_status end From 05e72f5f66fabd898b7d69db3942f3164184cdbd Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 17 Jul 2019 08:56:03 +0800 Subject: [PATCH 0852/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E9=A1=B5=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 6 ++++-- app/helpers/exercises_helper.rb | 18 ++++++++++-------- app/models/course.rb | 16 +++++++--------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 6eaa22f01..89e781425 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1329,8 +1329,6 @@ class ExercisesController < ApplicationController @exercise_all_users = @exercise.exercise_users ex_common_ids = @exercise.common_published_ids(current_user.id) @exercise_course_groups = @course.get_ex_published_course(ex_common_ids) - @exercise_users_list = @exercise.all_exercise_users(current_user.id) - @course_all_members_count = @exercise_users_list.size #班级的选择 if params[:exercise_group_id].present? @@ -1338,6 +1336,10 @@ class ExercisesController < ApplicationController exercise_students = @course_all_members.course_find_by_ids("course_group_id",group_id) # 试卷所分班的全部人数 user_ids = exercise_students.pluck(:user_id).reject(&:blank?) @exercise_all_users = @exercise.exercise_users.exercise_commit_users(user_ids) + @course_all_members_count = @exercise_all_users.size + else + @exercise_users_list = @exercise.all_exercise_users(current_user.id) + @course_all_members_count = @exercise_users_list.size end @exercise_commit_users = @exercise_all_users.commit_exercise_by_status(1) #试卷的已提交用户 @exercise_commit_user_ids = @exercise_commit_users.pluck(:user_id).uniq #已提交试卷的全部用户id diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index dfb6e4237..def163038 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -88,11 +88,11 @@ module ExercisesHelper question_infos = [] percent = 0.0 questions.each do |ex| - ex_total_score = user_ids.count * ex&.question_score #该试卷的已回答的总分 - ex_answers = ex.exercise_answers.includes(:exercise_choice) + ex_total_score = user_ids.size * ex&.question_score #该试卷的已回答的总分 if ex.question_type != Exercise::PRACTICAL ques_title = ex.question_title ques_less_title = nil + ex_answers = ex.exercise_answers effictive_users = ex_answers.search_answer_users("user_id",user_ids) else ques_title = ex.shixun.name @@ -121,12 +121,14 @@ module ExercisesHelper end end else #单选题和判断题 - user_ids.each do |user_id| - answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice&.choice_position - if [answer_choice_array] == standard_answer - right_users_count += 1 - end - end + standard_answer_choice_id = ex.exercise_choices.find_by(choice_position: standard_answer.first)&.id + right_users_count = effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.size + # user_ids.each do |user_id| + # answer_choice_array = effictive_users.select(:user_id,:exercise_choice_id).find_by(user_id:user_id)&.exercise_choice&.choice_position + # if [answer_choice_array] == standard_answer + # right_users_count += 1 + # end + # end end percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 diff --git a/app/models/course.rb b/app/models/course.rb index b2835fc21..26672afc2 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -310,15 +310,13 @@ class Course < ApplicationRecord #获取试卷/问卷已发布的班级id,名称和人数。当为统一设置时,显示全部,否则只显示当前已发布的班级信息 def get_ex_published_course(common_ids) teacher_power_courses = [] - if course_groups.present? - common_ids.each do |i| - if i == 0 - student_count = students.where(course_group_id:i).count - teacher_power_courses << {course_name:"未分班",course_id:0,student_count:student_count} - else - course_group_name = course_groups.find_by(id:i) - teacher_power_courses << {course_name:course_group_name&.name,course_id:i,student_count:course_group_name&.course_members_count} - end + publish_groups = course_groups.where(id: common_ids) + if common_ids.include?(0) + teacher_power_courses << {course_name:"未分班", course_id: 0, student_count: none_group_count} + end + if publish_groups.present? + publish_groups.each do |group| + teacher_power_courses << {course_name: group&.name,course_id: group&.id, student_count: group&.course_members_count} end end teacher_power_courses From 86726005bb609e93edae73604c39794290e2b86a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 17 Jul 2019 09:21:16 +0800 Subject: [PATCH 0853/1015] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 8 +++----- app/models/course.rb | 1 + app/views/courses/index.json.jbuilder | 1 + 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index c27a57c90..94c8a4ec1 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -62,15 +62,12 @@ class CoursesController < ApplicationController if @order == "mine" @courses = Course.joins(:course_members) .where("is_delete = 0 AND is_hidden = 0 AND course_members.user_id = ?", @user.id) - .order("courses.id = 1309 DESC, courses.#{order_str} DESC") elsif @order == "created_at" # REDO:Extension @courses = Course.where(is_delete: 0, is_hidden: 0, is_end: 0) - .order("courses.id = 1309 DESC, courses.#{order_str} DESC") else # REDO:Extension @courses = Course.where(is_delete: 0, is_hidden: 0) - .order("courses.id = 1309 DESC, courses.#{order_str} DESC") end # 根据搜索关键字进一步筛选 @@ -89,14 +86,15 @@ class CoursesController < ApplicationController @courses = @courses.joins(:school, course_members: :user) .where("#{sql}", keyword: "%#{params[:search]}%").distinct end - @courses_count = @courses.size + @courses_count = @courses.count("courses.id") + @courses = @courses.order("courses.id = 1309 DESC, courses.#{order_str} DESC") # 分页 page = params[:page] || 1 limit = params[:limit] || 16 @courses = @courses.page(page).per(limit) - @courses = @courses.preload(:school, teacher: :user_extension) + @courses = @courses.preload(:school, :none_hidden_course_modules, teacher: :user_extension) end def visits_plus_one diff --git a/app/models/course.rb b/app/models/course.rb index 26672afc2..3794a8b2b 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -10,6 +10,7 @@ class Course < ApplicationRecord has_many :course_infos, dependent: :destroy # 课堂左侧导航栏的模块 has_many :course_modules, dependent: :destroy + has_many :none_hidden_course_modules, -> { not_hidden }, class_name: "CourseModule" has_many :board_course_modules, -> { board_module }, class_name: "CourseModule" has_many :attachment_course_modules, -> { attachment_module }, class_name: "CourseModule" has_many :common_course_modules, -> { common_homework_module }, class_name: "CourseModule" diff --git a/app/views/courses/index.json.jbuilder b/app/views/courses/index.json.jbuilder index 2b6866517..32a7047b7 100644 --- a/app/views/courses/index.json.jbuilder +++ b/app/views/courses/index.json.jbuilder @@ -11,5 +11,6 @@ json.courses @courses do |course| json.is_public course.is_public json.is_accessible course.is_public == 1 || @user.course_identity(course) < Course::NORMAL json.is_end course.is_end + json.first_category_url module_url(course.none_hidden_course_modules.first, course) end json.courses_count @courses_count From b6a0b873acf521dcc1c246996ade5bb2e994cc9b Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 17 Jul 2019 09:27:36 +0800 Subject: [PATCH 0854/1015] fixubg --- app/controllers/homework_commons_controller.rb | 3 ++- app/controllers/polls_controller.rb | 7 ------- app/helpers/exercises_helper.rb | 1 - 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index ccadba89c..e3b72e62d 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -448,7 +448,7 @@ class HomeworkCommonsController < ApplicationController tip_exception("发布时间不能早于当前时间") if params[:publish_time] <= Time.now.strftime("%Y-%m-%d %H:%M:%S") tip_exception("截止时间不能早于当前时间") if params[:end_time] <= Time.now.strftime("%Y-%m-%d %H:%M:%S") tip_exception("截止时间不能早于发布时间") if params[:publish_time] > params[:end_time] - tip_exception("截止时间不能早于课堂结束时间") if @course.end_date.present? && params[:end_time] > @course.end_date.end_of_day + tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:end_time] > @course.end_date.end_of_day @homework.unified_setting = 1 @homework.homework_group_settings.destroy_all @@ -1086,6 +1086,7 @@ class HomeworkCommonsController < ApplicationController homework.publish_time = Time.now # 截止时间不为空的保持原状,为空的改为一个月后, 非统一设置的更新为最大分班截止时间 + if homework.end_time.nil? homework.end_time = params[:end_time] elsif homework.max_group_end_time diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 469c0bd4d..6262d9ef9 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -288,13 +288,6 @@ class PollsController < ApplicationController poll_unified = true e_time = ex_end_time end - # if poll.end_time.blank? - # e_time = ex_end_time - # elsif poll.poll_group_settings.end_time_present.count > 0 # 该问卷分组有结束时间为空的 - # e_time = poll.poll_group_settings.end_time_present.map(&:end_time).max - # else - # e_time = poll.end_time - # end poll_status = set_poll_status(Time.now,e_time) poll_params = { diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 32e5d1bfc..fc1e7874e 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -116,7 +116,6 @@ module ExercisesHelper right_users_count = 0 #该问题的回答正确的人数 user_ids.each do |user_id| ex_choice_ids = effictive_users.map{|e| e.exercise_choice_id if e.user_id == user_id}.reject(&:blank?).uniq - # answer_choice_array = ex_choices.where(id:ex_choice_ids).pluck(:choice_position) answer_choice_array = ex_choices.map{|a| a.choice_position if ex_choice_ids.include?(a.id)}.reject(&:blank?).uniq if answer_choice_array.sort == standard_answer right_users_count += 1 From 27d67477c6fb4771850d64584349b5686a5da524 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 17 Jul 2019 09:33:37 +0800 Subject: [PATCH 0855/1015] =?UTF-8?q?=E7=AB=8B=E5=8D=B3=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E7=9A=84=E6=88=AA=E6=AD=A2=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index ccadba89c..d1568a5e0 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -522,7 +522,7 @@ class HomeworkCommonsController < ApplicationController tip_exception("截止时间不能早于等于当前时间") if setting[:end_time] <= strf_time(Time.now) tip_exception("截止时间不能早于发布时间") if setting[:publish_time] > setting[:end_time] - tip_exception("截止时间不能早于课堂结束时间") if setting[:end_time] > strf_time(@course.end_date.end_of_day) + tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && setting[:end_time] > strf_time(@course.end_date.end_of_day) group_settings.none_published.update_all(publish_time: setting[:publish_time]) group_settings.none_end.update_all(end_time: setting[:end_time]) @@ -1048,7 +1048,8 @@ class HomeworkCommonsController < ApplicationController def publish_homework tip_exception("请至少选择一个分班") if params[:group_ids].blank? && @course.course_groups.size != 0 tip_exception("缺少截止时间参数") if params[:end_time].blank? - tip_exception("截止时间必须晚于当前时间") if params[:end_time] <= strf_time(Time.now) + tip_exception("截止时间不能早于当前时间") if params[:end_time] <= strf_time(Time.now) + tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day) homeworks = @course.homework_commons.where(id: params[:homework_ids]) homeworks = homeworks.includes(:homework_group_settings, :homework_detail_manual) @@ -1067,6 +1068,7 @@ class HomeworkCommonsController < ApplicationController if @course.course_groups.where(id: publish_groups).size == @course.course_groups.size homework.homework_group_settings.destroy_all homework.unified_setting = true + homework.end_time = params[:end_time] else homework.unified_setting = false # 创建作业分班设置:homework_group_setting @@ -1085,7 +1087,7 @@ class HomeworkCommonsController < ApplicationController homework.publish_time = Time.now - # 截止时间不为空的保持原状,为空的改为一个月后, 非统一设置的更新为最大分班截止时间 + # 截止时间的处理 if homework.end_time.nil? homework.end_time = params[:end_time] elsif homework.max_group_end_time From 81686af06ff89952ac213d52a322844acf8815a5 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 17 Jul 2019 09:40:01 +0800 Subject: [PATCH 0856/1015] =?UTF-8?q?=E6=8F=90=E7=A4=BA=E4=BF=A1=E6=81=AF?= =?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/homework_commons_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index d1568a5e0..83b107ba9 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -448,7 +448,7 @@ class HomeworkCommonsController < ApplicationController tip_exception("发布时间不能早于当前时间") if params[:publish_time] <= Time.now.strftime("%Y-%m-%d %H:%M:%S") tip_exception("截止时间不能早于当前时间") if params[:end_time] <= Time.now.strftime("%Y-%m-%d %H:%M:%S") tip_exception("截止时间不能早于发布时间") if params[:publish_time] > params[:end_time] - tip_exception("截止时间不能早于课堂结束时间") if @course.end_date.present? && params[:end_time] > @course.end_date.end_of_day + tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:end_time] > @course.end_date.end_of_day @homework.unified_setting = 1 @homework.homework_group_settings.destroy_all @@ -470,7 +470,7 @@ class HomeworkCommonsController < ApplicationController tip_exception("发布时间不能早于当前时间") if setting[:publish_time] <= strf_time(Time.now) tip_exception("截止时间不能早于当前时间") if setting[:end_time] <= strf_time(Time.now) tip_exception("截止时间不能早于发布时间") if setting[:publish_time] > setting[:end_time] - tip_exception("截止时间不能早于课堂结束时间") if @course.end_date.present? && setting[:end_time] > @course.end_date.end_of_day + tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && setting[:end_time] > @course.end_date.end_of_day publish_time = setting[:publish_time] == "" ? Time.now : setting[:publish_time] @@ -504,7 +504,7 @@ class HomeworkCommonsController < ApplicationController if @homework.end_time > Time.now && @homework.unified_setting tip_exception("截止时间不能为空") if params[:end_time].blank? tip_exception("截止时间不能早于当前时间") if params[:end_time] <= strf_time(Time.now) - tip_exception("截止时间不能早于课堂结束时间") if @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day) + tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day) @homework.end_time = params[:end_time] From 4a78c3cbc9e09b1381544aaea2365051dc685d06 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 17 Jul 2019 09:50:00 +0800 Subject: [PATCH 0857/1015] =?UTF-8?q?html=E6=95=88=E6=9E=9C=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E7=9A=84=E5=AE=9E=E8=AE=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/users_controller.rb | 7 +++++++ app/views/users/html_show.html.erb | 1 + 2 files changed, 8 insertions(+) create mode 100644 app/views/users/html_show.html.erb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 888e212e3..e9fe4ed94 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -51,6 +51,13 @@ class UsersController < ApplicationController :disposition => 'attachment' #inline can open in browser end + def html_show + @contents = File.read("#{params[:path]}") + respond_to do |format| + format.html {render :layout => false} + end + end + # Redo: 消息总数缓存 def get_navigation_info @old_domain = edu_setting('old_edu_host') diff --git a/app/views/users/html_show.html.erb b/app/views/users/html_show.html.erb new file mode 100644 index 000000000..0fb51d1b8 --- /dev/null +++ b/app/views/users/html_show.html.erb @@ -0,0 +1 @@ +<%= @contents.html_safe %> \ No newline at end of file From d5840e1f4f10a5c1cef8c84a9480965d628cface Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 17 Jul 2019 09:50:39 +0800 Subject: [PATCH 0858/1015] =?UTF-8?q?html=E6=95=88=E6=9E=9C=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E7=9A=84=E5=AE=9E=E8=AE=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/config/routes.rb b/config/routes.rb index 90872faa8..71cfb8c55 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -58,6 +58,7 @@ Rails.application.routes.draw do post :unfollow get :get_user_info get :attachment_show + get :html_show get :get_navigation_info post :reply_message get :search_user_projects From 8f2499613456391cba2a63ae2deb1bc57fb55d42 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 17 Jul 2019 10:31:59 +0800 Subject: [PATCH 0859/1015] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E6=A8=A1=E5=9D=97?= =?UTF-8?q?=E7=9A=84=E9=9A=90=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/boards_controller.rb | 4 ++-- app/controllers/course_modules_controller.rb | 3 ++- app/controllers/course_second_categories_controller.rb | 2 +- app/controllers/courses_controller.rb | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index 0bcaaa2c0..1081a82ce 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -2,10 +2,10 @@ class BoardsController < ApplicationController before_action :require_login, :check_auth before_action :find_course, only: [:create] before_action :set_board, except: [:create] - before_action :teacher_allowed + before_action :teacher_or_admin_allowed def index - @boards = @course.boards.includes(messages: [:last_reply, :author]); + @boards = @course.boards.includes(messages: [:last_reply, :author]) end def show diff --git a/app/controllers/course_modules_controller.rb b/app/controllers/course_modules_controller.rb index 4e9f7b908..6e8afd525 100644 --- a/app/controllers/course_modules_controller.rb +++ b/app/controllers/course_modules_controller.rb @@ -2,7 +2,7 @@ class CourseModulesController < ApplicationController before_action :require_login, :check_auth before_action :set_module, except: [:unhidden_modules] before_action :find_course, only: [:unhidden_modules] - before_action :teacher_allowed + before_action :teacher_or_admin_allowed # 模块置顶 def sticky_module @@ -16,6 +16,7 @@ class CourseModulesController < ApplicationController # 模块隐藏 def hidden_module + tip_exception("请至少保留一个课堂模块") if @course.none_hidden_course_modules.where.not(id: @course_module.id).size == 0 @course_module.update_attributes(hidden: 1) normal_status(0, "更新成功") end diff --git a/app/controllers/course_second_categories_controller.rb b/app/controllers/course_second_categories_controller.rb index ca544a584..af368a8dc 100644 --- a/app/controllers/course_second_categories_controller.rb +++ b/app/controllers/course_second_categories_controller.rb @@ -1,7 +1,7 @@ class CourseSecondCategoriesController < ApplicationController before_action :require_login, :check_auth before_action :set_category - before_action :teacher_allowed + before_action :teacher_or_admin_allowed # 目录重命名 def rename_category diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 94c8a4ec1..8ea5a7174 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1057,6 +1057,7 @@ class CoursesController < ApplicationController tip_exception("课堂名称应以课程名称开头命名") unless params[:course][:name].index(params[:course_list_name]) && params[:course][:name].index(params[:course_list_name]) == 0 tip_exception("课堂所属单位不能为空!") if params[:school].blank? + tip_exception("请至少添加一个课堂模块") if params[:course_module_types].blank? @school = School.find_by!(name: params[:school].strip) end From 00af9fe75dab32db6de4e747747db656a3b5394a Mon Sep 17 00:00:00 2001 From: jasder Date: Wed, 17 Jul 2019 10:44:48 +0800 Subject: [PATCH 0860/1015] =?UTF-8?q?FIX=20=E6=96=87=E4=BB=B6=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E5=9B=A0=E5=9F=9F=E5=90=8D=E9=85=8D=E7=BD=AE=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8C=E6=9A=82=E6=97=B6=E5=8F=AA=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 5132e203c..571374468 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -38,7 +38,8 @@ class AttachmentsController < ApplicationController content_type = upload_file.content_type.presence || 'application/octet-stream' - remote_path = file_save_to_ucloud(local_path[folder.size, local_path.size], local_path, content_type) + # remote_path = file_save_to_ucloud(local_path[folder.size, local_path.size], local_path, content_type) + remote_path = nil # TODO 暂时本地上传,待域名配置后方可上传至云端 logger.info "local_path: #{local_path}" logger.info "remote_path: #{remote_path}" From 6b01530ad2785f3483f266683a2d9663b866c079 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Wed, 17 Jul 2019 11:32:34 +0800 Subject: [PATCH 0861/1015] =?UTF-8?q?=E4=BB=93=E5=BA=93=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=AE=9A=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 3 ++- app/controllers/myshixuns_controller.rb | 8 ++++++-- app/models/evaluate_record.rb | 8 ++++++++ app/models/output.rb | 12 ++++++++++++ db/migrate/20190716062401_add_ts_time_to_outputs.rb | 5 +++++ ...20190716064225_add_max_mem_to_evaluate_records.rb | 5 +++++ 6 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20190716062401_add_ts_time_to_outputs.rb create mode 100644 db/migrate/20190716064225_add_max_mem_to_evaluate_records.rb diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index c951340f8..107839b31 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -503,6 +503,7 @@ class GamesController < ApplicationController # 监测版本库HEAD是否存在,不存在则取最新的HEAD uri = "#{shixun_tomcat}/bridge/game/check" res = uri_post uri, rep_params + uid_logger("repo_content to bridge: res is #{res}") # res值:0 表示正常;-1表示有错误;-2表示代码版本库没了 if status == 0 && res && (res['code'] == -2 || res['code'] == -1) # 删除不需要的仓库 @@ -512,7 +513,7 @@ class GamesController < ApplicationController uid_logger_error("#{e.message}") end # fork一个新的仓库 - project_fork(@myshixun, @shixun.repo_path, current_user.login) + # project_fork(@myshixun, @shixun.repo_path, current_user.login) end rescue Exception => e uid_logger_error(e.message) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 31395def2..60edb6dcb 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -96,6 +96,10 @@ class MyshixunsController < ApplicationController status = jsonTestDetails['status'] game_id = jsonTestDetails['buildID'] sec_key = jsonTestDetails['sec_key'] + + res_usage = jsonTestDetails['resUsage'] + ts_time = res_usage['test_set_time_1'] + logger.info("training_task_status start#1**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") resubmit = jsonTestDetails['resubmit'] outPut = tran_base64_decode64(jsonTestDetails['outPut']) @@ -191,8 +195,8 @@ class MyshixunsController < ApplicationController test_cases_time = format("%.3f", (Time.now.to_f - t1.to_f)).to_f if record.present? consume_time = format("%.3f", (Time.now - record.created_at)).to_f - record.update_attributes!(:consume_time => consume_time, :git_pull => timeCost['pull'] , - :create_pod => timeCost['createPod'], :pod_execute => timeCost['execute'], :test_cases => test_cases_time, + record.update_attributes!(:consume_time => consume_time, :git_pull => timeCost['pull'] , :create_pod => timeCost['createPod'], + :pod_execute => timeCost['execute'], :test_cases => test_cases_time, :ts_time => ts_time, :brige => timeCost['evaluateAllTime'], :return_back => return_back_time) end uid_logger("training_task_status start#4**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") diff --git a/app/models/evaluate_record.rb b/app/models/evaluate_record.rb index 451409493..392b12360 100644 --- a/app/models/evaluate_record.rb +++ b/app/models/evaluate_record.rb @@ -1,3 +1,11 @@ +# 字段说明: +# consume_time:总耗时,包括前端发出请求,到最后前端显示效果 +# git_pull:中间层pull代码耗时 +# create_pod:创建pod耗时 +# pod_execute:pod执行时间耗时,也就代码执行耗时,是各个测试集的总耗时 +# test_cases:outpus表中存储及处理测试集的时间耗时 +# brige:中间层总耗时 +# return_back:回调耗时,从中间层发送请求到educoder所耗时间 class EvaluateRecord < ApplicationRecord default_scope { order("evaluate_records.id desc") } belongs_to :game diff --git a/app/models/output.rb b/app/models/output.rb index b813f6070..7a4a22e7e 100644 --- a/app/models/output.rb +++ b/app/models/output.rb @@ -1,3 +1,15 @@ +# 字段说明: +# code:-1表示评测未通过,0表示评测成功,实质是status的值 +# mes: +# out_put: +# test_set_position: 测试集序号(排序) +# actual_output: +# result: +# is_public:测试集是否是公开 +# query_index:评测次数 +# compile_success: +# text_scor: +# sec_key:每次评测的唯一标识 class Output < ApplicationRecord belongs_to :game end diff --git a/db/migrate/20190716062401_add_ts_time_to_outputs.rb b/db/migrate/20190716062401_add_ts_time_to_outputs.rb new file mode 100644 index 000000000..8e0c55a78 --- /dev/null +++ b/db/migrate/20190716062401_add_ts_time_to_outputs.rb @@ -0,0 +1,5 @@ +class AddTsTimeToOutputs < ActiveRecord::Migration[5.2] + def change + add_column :outputs, :ts_time, :float + end +end diff --git a/db/migrate/20190716064225_add_max_mem_to_evaluate_records.rb b/db/migrate/20190716064225_add_max_mem_to_evaluate_records.rb new file mode 100644 index 000000000..4c9907d0a --- /dev/null +++ b/db/migrate/20190716064225_add_max_mem_to_evaluate_records.rb @@ -0,0 +1,5 @@ +class AddMaxMemToEvaluateRecords < ActiveRecord::Migration[5.2] + def change + add_column :evaluate_records, :max_mem, :float + end +end From 42791b4af9a4fbe235396ab708fe98b597ba0900 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 17 Jul 2019 14:14:29 +0800 Subject: [PATCH 0862/1015] fixbug --- app/controllers/exercises_controller.rb | 24 +++++++++++++----------- app/controllers/polls_controller.rb | 8 ++++---- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 4522c64f6..ede5ff8cf 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -689,7 +689,7 @@ class ExercisesController < ApplicationController ActiveRecord::Base.transaction do begin check_ids = Exercise.where(id: params[:check_ids]) - ex_end_time = params[:end_time].to_time + ex_end_time = params[:end_time].blank? ? Time.at(((1.month.since.to_i)/3600.0).ceil * 3600) : params[:end_time].to_time check_ids.each do |exercise| if exercise.present? if exercise.unified_setting @@ -707,7 +707,6 @@ class ExercisesController < ApplicationController ex_unified = true e_time = ex_end_time else - e_time = exercise.exercise_group_settings.end_time_no_null.map(&:end_time).max ex_unified = false g_course.each do |i| exercise_group_setting = exercise.exercise_group_settings.find_in_exercise_group("course_group_id",i).first #根据课堂分班的id,寻找试卷所在的班级 @@ -725,7 +724,8 @@ class ExercisesController < ApplicationController new_exercise_group.save end end - group_ids = params[:group_ids] + # group_ids = params[:group_ids] + e_time = exercise.exercise_group_settings.end_time_no_null.map(&:end_time).max end else exercise.exercise_group_settings.destroy_all @@ -745,7 +745,7 @@ class ExercisesController < ApplicationController if exercise.course_acts.size == 0 exercise.course_acts << CourseActivity.new(:user_id => exercise.user_id,:course_id => exercise.course_id) end - ExercisePublishNotifyJob.perform_later(exercise.id, group_ids) + ExercisePublishNotifyJob.perform_later(exercise.id, g_course) end end end @@ -976,8 +976,14 @@ class ExercisesController < ApplicationController def start_answer ActiveRecord::Base.transaction do begin - @exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id)&.first - if @exercise_user_current.blank? + ex_users_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id) + @exercise_user_current = ex_users_current&.first + logger.info("############______________ex_users_current________#######{ex_users_current}") + if ex_users_current.exists? + if @exercise_user_current.start_at.blank? + @exercise_user_current.update_attribute("start_at",Time.now) + end + else if @user_course_identity > Course::ASSISTANT_PROFESSOR #当为老师的时候,不创建exercise_user表,理论上老师是不能进入答题的 exercise_user_params = { :user_id => @exercise_current_user_id, @@ -987,16 +993,12 @@ class ExercisesController < ApplicationController exercise_user_current = ExerciseUser.new(exercise_user_params) exercise_user_current.save end - else - if @exercise_user_current.start_at.blank? - @exercise_user_current.update_attribute("start_at",Time.now) - end end @t_user_exercise_status = @exercise.get_exercise_status(current_user) @user_left_time = nil if @user_course_identity < Course::STUDENT || (@t_user_exercise_status == 3) || - (@exercise_user_current.present? && @exercise_user_current.commit_status == 1) + (ex_users_current.exists? && @exercise_user_current.commit_status == 1) @user_exercise_status = 1 #当前用户为老师/试卷已截止/试卷已提交不可编辑 else @user_left_time = get_exercise_left_time(@exercise,current_user) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 6262d9ef9..77e5505a5 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -247,7 +247,7 @@ class PollsController < ApplicationController ActiveRecord::Base.transaction do begin check_ids = Poll.where(id: params[:check_ids]) - ex_end_time = params[:end_time] || Time.at(((1.month.since.to_i)/3600.0).ceil * 3600) + ex_end_time = params[:end_time].blank? ? Time.at(((1.month.since.to_i)/3600.0).ceil * 3600) : params[:end_time].to_time check_ids.each do |poll| if poll.unified_setting pl_status = poll.polls_status #则为试卷的状态 @@ -263,7 +263,6 @@ class PollsController < ApplicationController poll_unified = true e_time = ex_end_time else - e_time = poll.poll_group_settings.end_time_present.map(&:end_time).max poll_unified = false g_course.each do |i| poll_group_setting = poll.poll_group_settings.find_in_poll_group("course_group_id",i).first #根据课堂分班的id,寻找问卷所在的班级 @@ -281,7 +280,8 @@ class PollsController < ApplicationController new_poll_group.save end end - group_ids = params[:group_ids] + e_time = poll.poll_group_settings.end_time_present.map(&:end_time).max + # group_ids = params[:group_ids] end else poll.poll_group_settings.destroy_all @@ -300,7 +300,7 @@ class PollsController < ApplicationController if poll.course_acts.size == 0 poll.course_acts << CourseActivity.new(:user_id => poll.user_id,:course_id => poll.course_id) end - PollPublishNotifyJob.perform_later(poll.id, group_ids) + PollPublishNotifyJob.perform_later(poll.id, g_course) end end normal_status(0, "问卷发布成功!") From 51c844f4a2a9bbe121067bae7913c5ac5d582019 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 17 Jul 2019 14:14:50 +0800 Subject: [PATCH 0863/1015] =?UTF-8?q?html=E7=B1=BB=E5=AE=9E=E8=AE=AD?= =?UTF-8?q?=E8=AF=84=E6=B5=8B=E6=8E=A5=E5=8F=A3=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/games/picture_display.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/games/picture_display.json.jbuilder b/app/views/games/picture_display.json.jbuilder index 0470a5c0b..541c478a9 100644 --- a/app/views/games/picture_display.json.jbuilder +++ b/app/views/games/picture_display.json.jbuilder @@ -19,7 +19,7 @@ if @type == "image" end elsif @type == "html" - json.iframe_src html_show_users_path(:path => "#{@user_path}/#{@user_picture[0]}") + json.iframe_src File.read("#{@user_path}/#{@user_picture[0]}")&.html_safe elsif @type == "txt" json.contents @contents.html_safe elsif @type =="qrcode" From f0d6c81424c35c91f7c4e42f76ccfdf6278aad38 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 17 Jul 2019 14:18:45 +0800 Subject: [PATCH 0864/1015] fixbug --- app/controllers/exercises_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index ede5ff8cf..4ac1db0d4 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -978,8 +978,10 @@ class ExercisesController < ApplicationController begin ex_users_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id) @exercise_user_current = ex_users_current&.first - logger.info("############______________ex_users_current________#######{ex_users_current}") + logger.info("############______________ex_users_current________#######{ex_users_current.pluck(:user_id,:exercise_id)}") if ex_users_current.exists? + logger.info("############______________ex_users_current_exists?________#########################") + if @exercise_user_current.start_at.blank? @exercise_user_current.update_attribute("start_at",Time.now) end From d9ce239fcff097b9c3b8003d846488222f93e27d Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 17 Jul 2019 14:43:46 +0800 Subject: [PATCH 0865/1015] fixbug --- .../exercise_answers_controller.rb | 12 ++-- .../exercise_questions_controller.rb | 2 +- app/controllers/exercises_controller.rb | 61 ++++++++----------- app/controllers/polls_controller.rb | 2 +- 4 files changed, 34 insertions(+), 43 deletions(-) diff --git a/app/controllers/exercise_answers_controller.rb b/app/controllers/exercise_answers_controller.rb index 27e4aba11..babdd50f7 100644 --- a/app/controllers/exercise_answers_controller.rb +++ b/app/controllers/exercise_answers_controller.rb @@ -9,11 +9,11 @@ class ExerciseAnswersController < ApplicationController q_type = @exercise_question.question_type #试卷的类型 choice_id = params[:exercise_choice_id].present? ? params[:exercise_choice_id] : "" answer_text = params[:answer_text].present? ? params[:answer_text] : "" #为字符串 - if q_type < 4 && (q_type != 1) && choice_id.blank? + if q_type < Exercise::SUBJECTIVE && (q_type != Exercise::MULTIPLE) && choice_id.blank? normal_status(-1,"请选择序号") else ea = @exercise_question.exercise_answers.search_answer_users("user_id",current_user.id) #试卷的当前用户的答案 - if q_type == 0 || q_type == 2 #选择题(单选)/判断题 + if q_type == Exercise::SINGLE || q_type == Exercise::JUDGMENT #选择题(单选)/判断题 ea_choice = ea.search_exercise_answer("exercise_choice_id",choice_id).first answer_option = { :user_id => current_user.id, @@ -30,7 +30,7 @@ class ExerciseAnswersController < ApplicationController ex_a = ExerciseAnswer.new(answer_option) ex_a.save! end - elsif q_type == 1 #多选题的 + elsif q_type == Exercise::MULTIPLE #多选题的 choice_ids = params[:exercise_choice_id].present? ? params[:exercise_choice_id] : [] ea_ids = ea.pluck(:exercise_choice_id) @@ -53,7 +53,7 @@ class ExerciseAnswersController < ApplicationController ea_answer = ea.search_answer_users("exercise_choice_id",old_ids) ea_answer.destroy_all end - elsif q_type == 3 #填空题 + elsif q_type == Exercise::COMPLETION #填空题 answer_option = { :user_id => current_user.id, :exercise_question_id => @exercise_question.id, @@ -67,7 +67,7 @@ class ExerciseAnswersController < ApplicationController ex_new = ExerciseAnswer.new(answer_option) ex_new.save! end - elsif q_type == 4 #简答题 + elsif q_type == Exercise::SUBJECTIVE #简答题 answer_option = { :user_id => current_user.id, :exercise_question_id => @exercise_question.id @@ -110,7 +110,7 @@ class ExerciseAnswersController < ApplicationController elsif @exercise_user.commit_status == 1 normal_status(-1,"已提交/已结束的试卷不允许修改!") else - if (@exercise_user_status == 3 && @exercise_user.commit_status == 0) || (@exercise.time > 0 && @exercise_user.start_at.present? && ((@exercise_user.start_at + (@exercise.time.to_i + 1).minutes) < Time.now)) + if (@exercise_user_status == Exercise::DEADLINE && @exercise_user.commit_status == 0) || (@exercise.time > 0 && @exercise_user.start_at.present? && ((@exercise_user.start_at + (@exercise.time.to_i + 1).minutes) < Time.now)) objective_score = calculate_student_score(@exercise,current_user)[:total_score] subjective_score = @exercise_user.subjective_score < 0.0 ? 0.0 : @exercise_user.subjective_score total_score = objective_score + subjective_score diff --git a/app/controllers/exercise_questions_controller.rb b/app/controllers/exercise_questions_controller.rb index 65fd77d98..3718e18d5 100644 --- a/app/controllers/exercise_questions_controller.rb +++ b/app/controllers/exercise_questions_controller.rb @@ -590,7 +590,7 @@ class ExerciseQuestionsController < ApplicationController end def validate_params - normal_status(-1,"题目不允许为空!") if (params[:question_title].blank? && params[:question_type].to_i !=5 ) #除了实训题,其余题目必需有题干 + normal_status(-1,"题目不允许为空!") if (params[:question_title].blank? && params[:question_type].to_i != Exercise::PRACTICAL ) #除了实训题,其余题目必需有题干 normal_status(-1,"问题类型不允许为空!" ) if params[:question_type].blank? normal_status(-1,"分值不允许为空!" ) if params[:question_score].blank? && params[:question_scores].blank? #分值的数组或参数必需存在一个 if params[:question_score].present? && params[:question_score].to_f <= 0.0 #问题类型存在,则分值不能为空,且必需大于0 diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 4ac1db0d4..995b1b75a 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -208,13 +208,13 @@ class ExercisesController < ApplicationController @ex_status = @exercise.get_exercise_status(current_user) exercise_id_array = [@exercise.id] - @exercise_publish_count = get_user_permission_course(exercise_id_array,2).size #是否存在已发布的 - @exercise_unpublish_count = get_user_permission_course(exercise_id_array,1).size #是否存在未发布的 + @exercise_publish_count = get_user_permission_course(exercise_id_array,Exercise::PUBLISHED).size #是否存在已发布的 + @exercise_unpublish_count = get_user_permission_course(exercise_id_array,Exercise::UNPUBLISHED).size #是否存在未发布的 if (@exercise_publish_count == 0) && (@exercise_unpublish_count == 0) #即表示没有分班 - if @ex_status == 1 + if @ex_status == Exercise::UNPUBLISHED @exercise_unpublish_count = 1 #试卷未发布,且课堂没有分班的时候 - elsif @ex_status == 2 + elsif @ex_status == Exercise::PUBLISHED @exercise_publish_count = 1 #试卷未发布,且课堂没有分班的时候 end end @@ -368,7 +368,7 @@ class ExercisesController < ApplicationController exercise_bank_question = current_ex_bank.exercise_bank_questions.new option exercise_bank_question.save ## 试卷选项的输入 - if q.question_type != 5 #不为实训题时,试卷选项加入试题答案库 + if q.question_type != Exercise::PRACTICAL #不为实训题时,试卷选项加入试题答案库 ex_choices = q.exercise_choices ex_standard = q.exercise_standard_answers ex_choices.each do |c| @@ -422,8 +422,8 @@ class ExercisesController < ApplicationController @user_published_setting = @exercise.exercise_group_settings .find_in_exercise_group("course_group_id",@being_setting_course_ids) #当前用户已发布班级的试卷设置 exercise_ids = [@exercise.id] - @exercise_publish_count = get_user_permission_course(exercise_ids,2).count #判断当前用户是否有试卷已发布的分班,用于显示立即截止/撤销发布 - @exercise_unpublish_count = get_user_permission_course(exercise_ids,1).count #判断当前用户是否有试卷未发布的分班,用户显示立即发布 + @exercise_publish_count = get_user_permission_course(exercise_ids,Exercise::PUBLISHED).count #判断当前用户是否有试卷已发布的分班,用于显示立即截止/撤销发布 + @exercise_unpublish_count = get_user_permission_course(exercise_ids,Exercise::UNPUBLISHED).count #判断当前用户是否有试卷未发布的分班,用户显示立即发布 @exercise_users_count = @exercise.exercise_users.commit_exercise_by_status(1).count #判断当前试卷是否有已提交的 # ## 需添加发送消息的接口,稍后添加 rescue Exception => e @@ -444,7 +444,7 @@ class ExercisesController < ApplicationController exercise_status = @exercise.get_exercise_status(current_user) - if exercise_status == 1 && course_group_ids.size > 0 # 试卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按试卷默认的来处理 + if exercise_status == Exercise::UNPUBLISHED && course_group_ids.size > 0 # 试卷未发布,且老师的分班大于1 ,才可以修改统一设置,否则按试卷默认的来处理 unified_setting = params[:unified_setting] else unified_setting = @exercise.unified_setting @@ -469,7 +469,7 @@ class ExercisesController < ApplicationController params_end_time = params[:end_time].to_time end - if (exercise_status != 1) && (@exercise.publish_time != params_publish_time) + if (exercise_status != Exercise::UNPUBLISHED) && (@exercise.publish_time != params_publish_time) normal_status(-1,"已发布/已截止,不允许修改发布时间") elsif params_publish_time.present? && params_end_time.present? && params_end_time < params_publish_time normal_status(-1,"截止时间不能小于发布时间") @@ -590,7 +590,7 @@ class ExercisesController < ApplicationController :end_time => e_time } @exercise.update_attributes(exercise_params) - if @exercise.exercise_status == 2 + if @exercise.exercise_status == Exercise::PUBLISHED if @exercise.course_acts.size == 0 @exercise.course_acts << CourseActivity.new(:user_id => @exercise.user_id,:course_id => @exercise.course_id) end @@ -784,15 +784,9 @@ class ExercisesController < ApplicationController course_students = @course.students #课堂的全部学生数 check_ids.each do |exercise| exercise_status= exercise.get_exercise_status(current_user) - if exercise_status == 2 #跳过已截止的或未发布的 + if exercise_status == Exercise::PUBLISHED #跳过已截止的或未发布的 g_course = params[:group_ids] if g_course.present? - # user_course_groups= @course.teacher_course_groups.get_user_groups(current_user.id) - # if user_course_groups.present? - # teacher_course_group_ids = user_course_groups.pluck(:course_group_id) - # else - # teacher_course_group_ids = @course.course_groups.pluck(:id) - # end teacher_course_group_ids = @course.charge_group_ids(current_user) if g_course.map(&:to_i).sort == teacher_course_group_ids.sort #开始为统一设置 exercise.exercise_group_settings.destroy_all @@ -878,7 +872,7 @@ class ExercisesController < ApplicationController ex_question_ids = @exercise.exercise_questions.pluck(:id) exercise_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first if exercise_user.present? - if exercise_user.commit_status == 1 && @exercise.get_exercise_status(current_user) == 2 #用户已提交且试卷提交中 + if exercise_user.commit_status == 1 && @exercise.get_exercise_status(current_user) == Exercise::PUBLISHED #用户已提交且试卷提交中 if @exercise.time == -1 || ((Time.now.to_i - exercise_user.start_at.to_i) < @exercise.time.to_i * 60) exercise_user.update_attributes(:score => nil, :end_at => nil, :status => nil, :commit_status => 0, :objective_score => 0.0, :subjective_score => -1.0) @@ -976,12 +970,9 @@ class ExercisesController < ApplicationController def start_answer ActiveRecord::Base.transaction do begin - ex_users_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id) + ex_users_current = ExerciseUser.where(user_id:@exercise_current_user_id,exercise_id:@exercise_id) #不能用@exercise.exercise_users,因为exercise_users删除时,只是状态改变,未删除 @exercise_user_current = ex_users_current&.first - logger.info("############______________ex_users_current________#######{ex_users_current.pluck(:user_id,:exercise_id)}") if ex_users_current.exists? - logger.info("############______________ex_users_current_exists?________#########################") - if @exercise_user_current.start_at.blank? @exercise_user_current.update_attribute("start_at",Time.now) end @@ -1020,7 +1011,7 @@ class ExercisesController < ApplicationController :exercise_answers, :exercise_standard_answers) - if @t_user_exercise_status == 3 + if @t_user_exercise_status == Exercise::DEADLINE get_each_student_exercise(@exercise.id,@exercise_questions,@exercise_current_user_id) end get_user_answer_status(@exercise_questions,@exercise_current_user_id,@exercise,@t_user_exercise_status) @@ -1051,9 +1042,9 @@ class ExercisesController < ApplicationController end end @exercise_questions.each do |q| - if q.question_type == 5 #当为实训题时 + if q.question_type == Exercise::PRACTICAL #当为实训题时 user_myshixun = q.shixun.myshixuns.search_myshixun_user(current_user.id) - if user_myshixun.blank? || user_myshixun.first.status != 1 #当前用户的实训是否做完 + if user_myshixun.blank? || user_myshixun.first.status != Exercise::UNPUBLISHED #当前用户的实训是否做完 @shixun_undo += 1 end else @@ -1163,7 +1154,7 @@ class ExercisesController < ApplicationController #试卷的答题列表页的显示用户 if @user_course_identity < Course::STUDENT #当前为老师,而且老师只能查看自己班级的/课堂的试卷 @exercise_current_user_status = 0 - unless @exercise_status == 1 + unless @exercise_status == Exercise::UNPUBLISHED ex_common_ids = @exercise.common_published_ids(current_user.id) @exercise_course_groups = @course.get_ex_published_course(ex_common_ids) @exercise_users_list = @exercise.all_exercise_users(current_user.id) #当前老师所在班级的全部学生 @@ -1176,7 +1167,7 @@ class ExercisesController < ApplicationController exercise_current_user = @exercise_all_users.exercise_commit_users(current_user.id) if exercise_current_user.exists? #表示为课堂学生或已回答的 @exercise_current_user_status = 1 - if @exercise.score_open && @exercise_status == 3 #勾选了成绩公开且试卷已截止的 + if @exercise.score_open && @exercise_status == Exercise::DEADLINE #勾选了成绩公开且试卷已截止的 all_user_ids = @exercise_all_users.pluck(:user_id) all_user_ids.delete(current_user.id) #删除了当前用户的ID @exercise_users_list = @exercise_all_users.exercise_commit_users(all_user_ids).distinct @@ -1468,32 +1459,32 @@ class ExercisesController < ApplicationController @exercise_ques_scores = exercise_questions.pluck(:question_score).sum #单选题的数量及分数 - exercise_single_ques = exercise_questions.find_by_custom("question_type",0) + exercise_single_ques = exercise_questions.find_by_custom("question_type",Exercise::SINGLE) @exercise_single_ques_count = exercise_single_ques.size @exercise_single_ques_scores = exercise_single_ques.pluck(:question_score).sum #多选题的数量及分数 - exercise_double_ques = exercise_questions.find_by_custom("question_type",1) + exercise_double_ques = exercise_questions.find_by_custom("question_type",Exercise::MULTIPLE) @exercise_double_ques_count = exercise_double_ques.size @exercise_double_ques_scores = exercise_double_ques.pluck(:question_score).sum # 判断题数量及分数 - exercise_ques_judge = exercise_questions.find_by_custom("question_type",2) + exercise_ques_judge = exercise_questions.find_by_custom("question_type",Exercise::JUDGMENT) @exercise_ques_judge_count = exercise_ques_judge.size @exercise_ques_judge_scores = exercise_ques_judge.pluck(:question_score).sum #填空题数量及分数 - exercise_ques_null = exercise_questions.find_by_custom("question_type",3) + exercise_ques_null = exercise_questions.find_by_custom("question_type",Exercise::COMPLETION) @exercise_ques_null_count = exercise_ques_null.size @exercise_ques_null_scores = exercise_ques_null.pluck(:question_score).sum #简答题数量及分数 - exercise_ques_main = exercise_questions.find_by_custom("question_type",4) + exercise_ques_main = exercise_questions.find_by_custom("question_type",Exercise::SUBJECTIVE) @exercise_ques_main_count = exercise_ques_main.size @exercise_ques_main_scores = exercise_ques_main.pluck(:question_score).sum #实训题数量及分数 - exercise_ques_shixun = exercise_questions.find_by_custom("question_type",5) + exercise_ques_shixun = exercise_questions.find_by_custom("question_type",Exercise::PRACTICAL) @exercise_ques_shixun_count = exercise_ques_shixun.size @exercise_ques_shixun_scores = exercise_ques_shixun.pluck(:question_score).sum @@ -1576,7 +1567,7 @@ class ExercisesController < ApplicationController ## 判断开始答题页面的用户权限 def check_user_on_answer - if @user_course_identity == Course::STUDENT && @exercise.get_exercise_status(current_user) == 1 #试卷未发布,且当前用户不为老师/管理员 + if @user_course_identity == Course::STUDENT && @exercise.get_exercise_status(current_user) == Exercise::UNPUBLISHED #试卷未发布,且当前用户不为老师/管理员 normal_status(-1, "未发布试卷!") elsif @user_course_identity > Course::STUDENT && (!@exercise.is_public || (@exercise.is_public && !@exercise.unified_setting)) ##不为课堂成员,且试卷不为公开的,或试卷公开,但不是统一设置的 normal_status(-1, "试卷暂未公开!") @@ -1593,7 +1584,7 @@ class ExercisesController < ApplicationController #打回重做时的初步判断 def check_exercise_status @exercise_users = @exercise.all_exercise_users(current_user.id).commit_exercise_by_status(1) #当前教师所在分班的全部已提交的学生数 - if @exercise.get_exercise_status(current_user) != 2 + if @exercise.get_exercise_status(current_user) != Exercise::PUBLISHED normal_status(-1,"非提交中的试卷不允许打回重做!") elsif @exercise_users.count < 1 normal_status(-1,"暂无人提交试卷!") diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 77e5505a5..3fc17c661 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -840,7 +840,7 @@ class PollsController < ApplicationController def start_answer ActiveRecord::Base.transaction do begin - poll_user_current = @poll.poll_users.find_by_group_ids(@poll_current_user_id).first #查找当前用户是否有过答题 + poll_user_current = PollUser.where(user_id:@poll_current_user_id,poll_id:@poll.id)&.first #查找当前用户是否有过答题 @poll_status = @poll.get_poll_status(current_user) if poll_user_current.blank? if @user_course_identity > Course::ASSISTANT_PROFESSOR #当为老师的时候,不创建poll_user表,理论上老师是不能进入答题的 From fd51e81a96322264d3133ee834c17eb249997124 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 17 Jul 2019 14:48:25 +0800 Subject: [PATCH 0866/1015] fixbug --- app/controllers/exercises_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 995b1b75a..2216574a9 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -970,7 +970,7 @@ class ExercisesController < ApplicationController def start_answer ActiveRecord::Base.transaction do begin - ex_users_current = ExerciseUser.where(user_id:@exercise_current_user_id,exercise_id:@exercise_id) #不能用@exercise.exercise_users,因为exercise_users删除时,只是状态改变,未删除 + ex_users_current = ExerciseUser.where(user_id:@exercise_current_user_id,exercise_id:@exercise.id) #不能用@exercise.exercise_users,因为exercise_users删除时,只是状态改变,未删除 @exercise_user_current = ex_users_current&.first if ex_users_current.exists? if @exercise_user_current.start_at.blank? From 03e5b0cf09f826abd9b67896d30d10ef7dde357e Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 17 Jul 2019 14:55:06 +0800 Subject: [PATCH 0867/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E7=9A=84=E9=80=89=E7=94=A8=E5=AE=9E=E8=AE=AD=E5=BC=B9=E6=A1=86?= =?UTF-8?q?=E3=80=81=E7=94=B3=E8=AF=B7=E5=8A=A0=E5=85=A5=E8=AF=BE=E5=A0=82?= =?UTF-8?q?=E6=97=B6=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6=E6=9C=89=E5=90=8C?= =?UTF-8?q?=E5=AD=A6=E5=8F=B7=E7=9A=84=E7=94=A8=E6=88=B7=E5=AD=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 7 +++++++ app/controllers/homework_commons_controller.rb | 6 +++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 8ea5a7174..7e2c68aab 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -879,6 +879,13 @@ class CoursesController < ApplicationController return normal_status(-1, "同一课堂不允许申请多个教师身份") end + # 验证是否存在同学号的学生 + u_extension = current_user.user_extension + if params[:student].present? && u_extension.student? + same_student_id_users = UserExtension.where.not(user_id: current_user.id).where(student_id: u_extension.student_id, identity: %i[student], school_id: u_extension.school_id).pluck(:user_id) + tip_exception("该课堂已存在同学号的学生,暂时无法加入,请联系老师") if course.students.where(user_id: same_student_id_users).size > 0 + end + # 创建学生身份 if params[:student].present? existing_student = CourseMember.find_by(course_id: course.id, role: %i[STUDENT], user_id: current_user.id) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 83b107ba9..3e12ac474 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -845,12 +845,12 @@ class HomeworkCommonsController < ApplicationController @shixuns = @shixuns.joins(:shixun_tag_repertoires).where(shixun_tag_repertoires: {tag_repertoire_id: type}).distinct end - @shixuns = @shixuns.select([:id, :name, :status, :myshixuns_count, :identifier, :user_id, :trainee]).reorder("shixuns.created_at desc") - @shixuns_count = @shixuns.size + @shixuns = @shixuns.select([:id, :name, :status, :myshixuns_count, :identifier, :user_id, :trainee]) + @total_count = @shixuns.size ## 分页参数 page = params[:page] || 1 - @shixuns = @shixuns.includes(:challenges, user: [user_extension: :school]).page(page).per(10) + @shixuns = @shixuns.reorder("shixuns.created_at desc").includes(:challenges, user: [user_extension: :school]).page(page).per(10) # 新版用下面的代码 # ## 我的实训 From da6af7680180ad59204226b5cfe5608e2f28555f Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 17 Jul 2019 14:55:13 +0800 Subject: [PATCH 0868/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E7=9A=84=E9=80=89=E7=94=A8=E5=AE=9E=E8=AE=AD=E5=BC=B9=E6=A1=86?= =?UTF-8?q?=E3=80=81=E7=94=B3=E8=AF=B7=E5=8A=A0=E5=85=A5=E8=AF=BE=E5=A0=82?= =?UTF-8?q?=E6=97=B6=E5=88=A4=E6=96=AD=E6=98=AF=E5=90=A6=E6=9C=89=E5=90=8C?= =?UTF-8?q?=E5=AD=A6=E5=8F=B7=E7=9A=84=E7=94=A8=E6=88=B7=E5=AD=98=E5=9C=A8?= 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 7e2c68aab..b661c06b4 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -883,7 +883,7 @@ class CoursesController < ApplicationController u_extension = current_user.user_extension if params[:student].present? && u_extension.student? same_student_id_users = UserExtension.where.not(user_id: current_user.id).where(student_id: u_extension.student_id, identity: %i[student], school_id: u_extension.school_id).pluck(:user_id) - tip_exception("该课堂已存在同学号的学生,暂时无法加入,请联系老师") if course.students.where(user_id: same_student_id_users).size > 0 + tip_exception("该课堂已存在同学号的学生,暂时无法加入,请联系老师") if course.students.exists?(user_id: same_student_id_users) end # 创建学生身份 From fd924a0f0bf72a840a2443dc9166d1137e3c7dac Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 17 Jul 2019 15:06:35 +0800 Subject: [PATCH 0869/1015] =?UTF-8?q?=E4=B8=87=E8=83=BD=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 7159c2bca..63a38670f 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -32,7 +32,8 @@ class AccountsController < ApplicationController end 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) - unless check_code + # todo 上线前请删除 + if !check_code && code != "513231" tip_exception("验证码无效") end From 00ba3c5c82f19ad71ca060f0e224b2de57baf747 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 17 Jul 2019 15:17:47 +0800 Subject: [PATCH 0870/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E4=BD=9C=E4=B8=9A?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 3e12ac474..74f1bb371 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -82,12 +82,10 @@ class HomeworkCommonsController < ApplicationController end @homework_commons = @homework_commons.joins(:homework_detail_manual).where(sql_str) end - @homework_commons = @homework_commons.order("IF(ISNULL(homework_commons.publish_time),0,1), homework_commons.publish_time DESC, - homework_commons.created_at DESC") - @task_count = @homework_commons.size - @homework_commons = @homework_commons.page(page).per(15) + @homework_commons = @homework_commons.order("IF(ISNULL(homework_commons.publish_time),0,1), homework_commons.publish_time DESC, + homework_commons.created_at DESC").page(page).per(15) if @homework_type == 4 @homework_commons = @homework_commons.includes(:homework_detail_manual, :published_settings, :shixuns) From 2c021417dcf0c06ad336e520805f0e14fdfddb53 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 17 Jul 2019 15:27:54 +0800 Subject: [PATCH 0871/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=80=97=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 60edb6dcb..a7c1e227c 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -98,7 +98,8 @@ class MyshixunsController < ApplicationController sec_key = jsonTestDetails['sec_key'] res_usage = jsonTestDetails['resUsage'] - ts_time = res_usage['test_set_time_1'] + # 关卡测试集的总耗时 + ts_time = 0 logger.info("training_task_status start#1**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") resubmit = jsonTestDetails['resubmit'] @@ -123,11 +124,13 @@ class MyshixunsController < ApplicationController jenkins_testsets.each_with_index do |j_test_set, i| logger.info("j_test_set: ############## #{j_test_set}") actual_output = tran_base64_decode64(j_test_set['output']) + ts_time += j_test_set['testSetTime'].to_i + # is_public = test_sets.where(:position => j_test_set['caseId']).first.try(:is_public) logger.info "actual_output:################################################# #{actual_output}" Output.create!(:code => status, :game_id => game_id, :out_put => outPut, :test_set_position => j_test_set['caseId'], :actual_output => actual_output, :result => j_test_set['passed'].to_i, :query_index => max_query_index, - :compile_success => compile_success.to_i, :sec_key => sec_key) + :compile_success => compile_success.to_i, :sec_key => sec_key, :ts_time => j_test_set['testSetTime']) # 如果设置了按测试集给分,则需要统计测试集的分值 if challenge.test_set_score && j_test_set['passed'].to_i == 1 test_set_score += challenge.test_sets.where(:position => j_test_set['caseId']).pluck(:score).first From 5f0ad4794ae6f95896befc1297c7d2587d4d36b1 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 17 Jul 2019 15:31:28 +0800 Subject: [PATCH 0872/1015] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E7=9A=84=E4=BD=9C?= =?UTF-8?q?=E5=93=81=E5=88=97=E8=A1=A8=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 74f1bb371..439da8add 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -139,7 +139,7 @@ class HomeworkCommonsController < ApplicationController @student_works = [] end - unless @student_works.blank? + if @student_works.size > 0 # 教师评阅搜索 0: 未评, 1 已评 unless params[:teacher_comment].blank? student_work_ids = StudentWorksScore.where(student_work_id: @student_works.map(&:id)).pluck(:student_work_id) @@ -169,6 +169,8 @@ class HomeworkCommonsController < ApplicationController or student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%") end + @work_count = @student_works.size + # 排序 rorder = params[:order].blank? ? "update_time" : params[:order] b_order = params[:b_order].blank? ? "desc" : params[:b_order] @@ -178,23 +180,22 @@ class HomeworkCommonsController < ApplicationController @student_works = @student_works.joins(user: :user_extension).order("user_extensions.#{rorder} #{b_order}") end - @work_count = @student_works.size - @work_excel = @student_works.includes(:student_works_scores, user: :user_extension, myshixun: :games) - @students = @course.students + @work_excel = @student_works # 分页参数 page = params[:page] || 1 limit = params[:limit] || 20 @student_works = @student_works.page(page).per(limit) + @students = @course.students.where(user_id: @student_works.pluck(:user_id)).preload(:course_group) if @homework.homework_type == "practice" @student_works = @student_works.includes(:student_works_scores, user: :user_extension, myshixun: :games) else @student_works = @student_works.includes(:student_works_scores, :project, user: :user_extension) end - # @members = @course.students.where(user_id: @student_works.pluck(:user_id)).includes(:course_group) end if params[:format] == "xlsx" + @work_excel = @work_excel.includes(:student_works_scores, user: :user_extension, myshixun: :games) complete_works = @work_excel.present? ? @work_excel.where("work_status > 0").size : 0 if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") From 8036c6eb85b3bdb3d9253c707d02c5edc622455f Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 17 Jul 2019 15:34:07 +0800 Subject: [PATCH 0873/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 55 +++++++++++++-------------------- 1 file changed, 21 insertions(+), 34 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 4a0c5509d..5ec9bcad4 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -88,8 +88,8 @@ module ExercisesHelper question_infos = [] percent = 0.0 questions.includes(:exercise_choices).each do |ex| - ex_total_score = user_ids.count * ex&.question_score #该试卷的已回答的总分 - ex_answers = ex.exercise_answers + ex_total_score = user_ids.count * ex&.question_score.to_f #该试卷的已回答的总分 + # ex_answers = ex.exercise_answers if ex.question_type != Exercise::PRACTICAL ques_title = ex.question_title ques_less_title = nil @@ -98,23 +98,23 @@ module ExercisesHelper else ques_title = ex.shixun.name ques_less_title = ex.question_title - effictive_users = ex.exercise_shixun_answers.search_shixun_answers("user_id",user_ids) + ex_answers = ex.exercise_shixun_answers + effictive_users = ex_answers.search_shixun_answers("user_id",user_ids) end effictive_users_count = effictive_users.size #有效回答数,可能有重复的用户id,这里仅统计是否回答这个问题的全部人数 ex_answered_scores = effictive_users.score_reviewed.pluck(:score).sum #该问题的全部得分 if ex.question_type > Exercise::COMPLETION #当为主观题和实训题时, - if ex_total_score != 0.0 - percent = (ex_answered_scores / ex_total_score.to_f).round(3) * 100 #正确率 - end + percent = (ex_total_score == 0.0 ? 0.0 : (ex_answered_scores / ex_total_score.to_f).round(3) * 100) #正确率 end question_answer_infos = [] if ex.question_type <= Exercise::JUDGMENT #选择题和判断题 ex_choices = ex.exercise_choices standard_answer = ex.exercise_standard_answers.pluck(:exercise_choice_id).sort #标准答案的位置 - right_users_count = 0 #该问题的回答正确的人数 + right_users_count = 0 + #该问题的正确率 if ex.question_type == Exercise::MULTIPLE #多选题 user_ids.each do |user_id| ex_choice_ids = effictive_users.map{|e| e.exercise_choice_id if e.user_id == user_id}.reject(&:blank?).uniq @@ -129,15 +129,14 @@ module ExercisesHelper end percent = effictive_users_count > 0 ? (right_users_count / effictive_users_count.to_f).round(3)*100 : 0.0 + + #每个选项的正确率 ex_choices.each do |c| right_answer = standard_answer.include?(c.choice_position) #选项的标准答案为选项的位置 - answer_this_choice = effictive_users.search_exercise_answer("exercise_choice_id",c.id) - answer_users_count = answer_this_choice.size - if effictive_users_count == 0 - answer_percent = 0.0 - else - answer_percent = (answer_users_count / effictive_users_count.to_f ).round(3) - end + answer_users_count = effictive_users.select{|answer| answer.exercise_choice_id == c.id}.size + + answer_percent = (effictive_users_count == 0 ? 0.0 : (answer_users_count / effictive_users_count.to_f ).round(3)) + answer_option = { :choice_position => c.choice_position, :choice_text => c.choice_text, @@ -150,7 +149,7 @@ module ExercisesHelper elsif ex.question_type == Exercise::COMPLETION #填空题 ex_ordered = ex.is_ordered null_standard_answer = ex.exercise_standard_answers - null_stand_choice = null_standard_answer.pluck(:exercise_choice_id) + null_stand_choice = null_standard_answer.pluck(:exercise_choice_id) #一个exercise_choice_id可能对应多个answer_text null_stand_text = null_standard_answer.pluck(:answer_text) standard_answer_count = 0 all_user_count = 0 @@ -159,20 +158,17 @@ module ExercisesHelper s_choice_text = null_stand_text[index] if ex_ordered #有序排列 user_ids.each do |u| - user_answers = ex_answers.search_answer_users("user_id",u).search_answer_users("exercise_choice_id",s) - user_answers_choice = user_answers.present? ? user_answers.first.answer_text : "" + user_answers = ex_answers.where(user_id:u,exercise_choice_id:s).select(:answer_text) + user_answers_choice = user_answers.exists? ? user_answers&.first&.answer_text.to_s : "" if s_choice_text == user_answers_choice user_count += 1 end end else - user_count = user_count + effictive_users.search_exercise_answer("answer_text",s_choice_text).count #回答了标准答案的用户 - end - if effictive_users_count == 0 - answer_percent = 0.0 - else - answer_percent = (user_count / effictive_users_count.to_f ).round(3) + user_count = user_count + effictive_users.select{|answer| answer.answer_text == s_choice_text }.size #回答了标准答案的用户 end + + answer_percent = ((effictive_users_count == 0) ? 0.0 : (user_count / effictive_users_count.to_f ).round(3)) answer_option = { :choice_position => index+1, :choice_text => s_choice_text, @@ -237,22 +233,13 @@ module ExercisesHelper all_zero_scores = cha_shixun_answer.search_shixun_keys("score",0.0).size #零分人数 shixun_scores = user_ids.count * cha_score shixun_answered_scores = cha_shixun_answer.score_reviewed.pluck(:score).sum #该问题的全部得分 - - if shixun_answered_scores == 0.0 - game_percent = 0.0 - else - game_percent = (shixun_answered_scores / shixun_scores.to_f).round(3) * 100 #正确率 - end + game_percent = (shixun_answered_scores == 0.0 ? 0.0 : (shixun_answered_scores / shixun_scores.to_f).round(3) * 100) #正确率 shixun_score_array = [full_scores,no_full_scores,all_zero_scores] shixun_chas = [] shixun_score_array.each_with_index do |s,index| right_answer = (index == 0) - if effictive_users_count == 0 - score_percent = 0.0 - else - score_percent = (s.to_i / effictive_users_count.to_f ).round(3) - end + score_percent = (effictive_users_count == 0 ? 0.0 : (s.to_i / effictive_users_count.to_f ).round(3)) answer_option = { :choice_position => index+1, :choice_text => index+1, From 874c2fea2c09c952a6194c93214ce5af81a148aa Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 17 Jul 2019 16:22:24 +0800 Subject: [PATCH 0874/1015] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E5=BA=93=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 1 + app/controllers/myshixuns_controller.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 107839b31..8dc0719f3 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -511,6 +511,7 @@ class GamesController < ApplicationController GitService.delete_repository(repo_path: @myshixun.repo_path) rescue Exception => e uid_logger_error("#{e.message}") + tip_exception(-3, "#{e.message}") end # fork一个新的仓库 # project_fork(@myshixun, @shixun.repo_path, current_user.login) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index a7c1e227c..811b9146a 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -97,6 +97,7 @@ class MyshixunsController < ApplicationController game_id = jsonTestDetails['buildID'] sec_key = jsonTestDetails['sec_key'] + # 资源消耗 res_usage = jsonTestDetails['resUsage'] # 关卡测试集的总耗时 ts_time = 0 From d991c52d103888d8aef1ea71ede2a65754f1e6b3 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 17 Jul 2019 16:39:41 +0800 Subject: [PATCH 0875/1015] =?UTF-8?q?=E7=BB=88=E7=AB=AF=E5=BE=AA=E7=8E=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 8dc0719f3..83678ca7f 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -511,7 +511,8 @@ class GamesController < ApplicationController GitService.delete_repository(repo_path: @myshixun.repo_path) rescue Exception => e uid_logger_error("#{e.message}") - tip_exception(-3, "#{e.message}") + # 终端循环 + tip_exception("#{e.message}") end # fork一个新的仓库 # project_fork(@myshixun, @shixun.repo_path, current_user.login) From b3dadf5a8459671b30ddd218cd813d5ef989f081 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 17 Jul 2019 16:50:27 +0800 Subject: [PATCH 0876/1015] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E7=9A=84=E6=88=90?= =?UTF-8?q?=E7=BB=A9=E5=AF=BC=E5=87=BA=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 38 +++++++++++++++++---------- app/models/course.rb | 2 +- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index b661c06b4..c46f9323a 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1180,15 +1180,27 @@ class CoursesController < ApplicationController course_main_info = [course_1,course_2,course_3,course_4,course_5,course_6,course_7] course_group_info_head = %w(序号 分班名称 邀请码 学生数量) course_group_info_body = [] - if course.course_groups.present? + none_group_counts = course.none_group_count + + #当有未分班时,应该也做个统计 + if none_group_counts > 0 + none_group_index = 2 + no_group_array = [1,"未分班",course.invite_code,none_group_counts] + course_group_info_body.push(no_group_array) + else + none_group_index = 1 + end + + if course.course_groups.exists? course.course_groups.each_with_index do |group, index| - group_index = (index+1) + group_index = (index+none_group_index) group_name = group.name group_code = group.invite_code group_count = group.course_members_count group_array = [group_index,group_name,group_code,group_count] course_group_info_body.push(group_array) end + end course_group_info = [course_group_info_head,course_group_info_body] @course_info += [course_info_title,course_main_info,course_group_info] @@ -1256,7 +1268,7 @@ class CoursesController < ApplicationController #实训作业 if shixun_homeworks.size > 0 - shixun_homeworks.each do |s| + shixun_homeworks&.includes(:score_student_works).each do |s| user_student_work = s.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答 if user_student_work.nil? h_score = 0.0 #该作业的得分为0 @@ -1272,7 +1284,7 @@ class CoursesController < ApplicationController #普通作业 if common_homeworks.size > 0 - common_homeworks.each do |c| + common_homeworks&.includes(:score_student_works).each do |c| user_student_work_1 = c.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答 if user_student_work_1.nil? h_score_1 = 0.0 #该作业的得分为0 @@ -1288,7 +1300,7 @@ class CoursesController < ApplicationController #分组作业 if group_homeworks.size > 0 - group_homeworks.each do |g| + group_homeworks&.includes(:score_student_works).each do |g| user_student_work_3 = g.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答 if user_student_work_3.nil? h_score_3 = 0.0 #该作业的得分为0 @@ -1304,7 +1316,7 @@ class CoursesController < ApplicationController #毕设作业 if tasks.size > 0 - tasks.each do |task| + tasks&.includes(:score_graduation_works).each do |task| graduation_work = task.score_graduation_works.select{|work| work.user_id == user.id}.first if graduation_work.nil? t_score = 0.0 @@ -1320,7 +1332,7 @@ class CoursesController < ApplicationController #试卷 if exercises.size > 0 - exercises.each do |ex| + exercises&.includes(:score_exercise_users).each do |ex| exercise_work = ex.score_exercise_users.select{|work| work.user_id == user.id}.first if exercise_work.nil? e_score = 0.0 @@ -1363,7 +1375,7 @@ class CoursesController < ApplicationController count_4 = tasks.size count_5 = exercises.size #实训作业 - shixun_homeworks.each_with_index do |s,index| + shixun_homeworks&.includes(:score_student_works).each_with_index do |s,index| all_student_works = s.score_student_works #该实训题的全部用户回答 title_no = index.to_i + 1 student_work_to_xlsx(all_student_works,s) @@ -1373,7 +1385,7 @@ class CoursesController < ApplicationController end #普通作业 - common_homeworks.each_with_index do |c,index| + common_homeworks&.includes(:score_student_works).each_with_index do |c,index| all_student_works = c.score_student_works #当前用户的对该作业的回答 title_no = count_1 + index.to_i + 1 student_work_to_xlsx(all_student_works,c) @@ -1385,7 +1397,7 @@ class CoursesController < ApplicationController end #分组作业 - group_homeworks.each_with_index do |c,index| + group_homeworks&.includes(:score_student_works).each_with_index do |c,index| all_student_works = c.score_student_works #当前用户的对该作业的回答 title_no = count_1 + count_2 + index.to_i + 1 student_work_to_xlsx(all_student_works,c) @@ -1395,23 +1407,21 @@ class CoursesController < ApplicationController end #毕设任务 - tasks.each_with_index do |c,index| + tasks&.includes(:score_graduation_works).each_with_index do |c,index| all_student_works = c.score_graduation_works #当前用户的对该作业的回答 title_no = count_1 + count_2 + count_3 + index.to_i + 1 graduation_work_to_xlsx(all_student_works,c,current_user) work_name = format_sheet_name (title_no.to_s + "." + c.name).strip.first(30) - # work_content = [work_name,@work_head_cells,@work_cells_column] work_content = [work_name,@head_cells_column,@task_cells_column] @task_work_arrays.push(work_content) end #试卷的导出 - exercises.each_with_index do |c,index| + exercises&.includes(:score_exercise_users).each_with_index do |c,index| all_student_works = c.score_exercise_users #当前用户的对该作业的回答 title_no = count_1 + count_2 + count_3 + count_4 + index.to_i + 1 get_export_users(c,course,all_student_works) work_name = format_sheet_name (title_no.to_s + "." + c.exercise_name).strip.first(30) - # work_content = [work_name,@work_head_cells,@work_cells_column] work_content = [work_name,@table_columns,@user_columns] @exercise_work_arrays.push(work_content) end diff --git a/app/models/course.rb b/app/models/course.rb index 3794a8b2b..1f38827ae 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -103,7 +103,7 @@ class Course < ApplicationRecord # 未分班的学生数 def none_group_count - course_members.where(role: 4, course_group_id: 0).count + course_members.where(role: 4, course_group_id: 0).size end def course_member(user_id) From 2eef513383649bfd7dbb053552ea1f9d67293f71 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 17 Jul 2019 16:50:58 +0800 Subject: [PATCH 0877/1015] =?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/controllers/games_controller.rb | 8 ++++---- app/controllers/myshixuns_controller.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 83678ca7f..977ddefa0 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -707,10 +707,10 @@ class GamesController < ApplicationController resubmit_identifier = @game.resubmit_identifier # 如果没有超时并且正在评测中 # 判断评测中的状态有两种:1、如果之前没有通关的,只需判断status为1即可;如果通过关,则判断game的resubmit_identifier是否更新 - # uid_logger("################game_status: #{@game.status}") - # uid_logger("################params[:resubmit]: #{params[:resubmit]}") - # uid_logger("################resubmit_identifier: #{resubmit_identifier}") - # uid_logger("################time_out: #{params[:time_out]}") + uid_logger("################game_status: #{@game.status}") + uid_logger("################params[:resubmit]: #{params[:resubmit]}") + uid_logger("################resubmit_identifier: #{resubmit_identifier}") + uid_logger("################time_out: #{params[:time_out]}") if (params[:time_out] == "false") && ((params[:resubmit].blank? && @game.status == 1) || (params[:resubmit].present? && (params[:resubmit] != resubmit_identifier))) # 代码评测的信息 diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 811b9146a..79429a30d 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -139,7 +139,6 @@ class MyshixunsController < ApplicationController end end uid_logger("#############status: #{status}") - uid_logger("#############resubmit: #{resubmit}") record = EvaluateRecord.where(:game_id => game_id).first logger.info("training_task_status start#3**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") answer_deduction_percentage = (100 - game.answer_deduction) / 100.to_f # 查看答案后剩余分数的百分比. @@ -147,6 +146,7 @@ class MyshixunsController < ApplicationController # status:0表示评测成功 if status == "0" if resubmit.present? + uid_logger("#############resubmit: #{resubmit}") game.update_attributes!(:retry_status => 2, :resubmit_identifier => resubmit) challenge.path.split(";").each do |path| game_passed_code(path.try(:strip), myshixun, game_id) From d21f863c17cbef3ebe320e90f070de508f9b87b0 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 17 Jul 2019 17:11:19 +0800 Subject: [PATCH 0878/1015] 1 --- app/controllers/myshixuns_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 79429a30d..dc6faee13 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -146,8 +146,9 @@ class MyshixunsController < ApplicationController # status:0表示评测成功 if status == "0" if resubmit.present? - uid_logger("#############resubmit: #{resubmit}") + uid_logger("#############resubmitdaiao: #{resubmit}") game.update_attributes!(:retry_status => 2, :resubmit_identifier => resubmit) + uid_logger("#############resubmit_identifier_resubmitdaiao: #{game.resubmit_identifier}") challenge.path.split(";").each do |path| game_passed_code(path.try(:strip), myshixun, game_id) end From 44774e9c5872c793e48468b83d6d8c2477dfea6a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 17 Jul 2019 17:14:21 +0800 Subject: [PATCH 0879/1015] =?UTF-8?q?=E8=AF=84=E6=B5=8B=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index dc6faee13..c36be6284 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -99,8 +99,6 @@ class MyshixunsController < ApplicationController # 资源消耗 res_usage = jsonTestDetails['resUsage'] - # 关卡测试集的总耗时 - ts_time = 0 logger.info("training_task_status start#1**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") resubmit = jsonTestDetails['resubmit'] @@ -148,7 +146,6 @@ class MyshixunsController < ApplicationController if resubmit.present? uid_logger("#############resubmitdaiao: #{resubmit}") game.update_attributes!(:retry_status => 2, :resubmit_identifier => resubmit) - uid_logger("#############resubmit_identifier_resubmitdaiao: #{game.resubmit_identifier}") challenge.path.split(";").each do |path| game_passed_code(path.try(:strip), myshixun, game_id) end @@ -201,7 +198,7 @@ class MyshixunsController < ApplicationController if record.present? consume_time = format("%.3f", (Time.now - record.created_at)).to_f record.update_attributes!(:consume_time => consume_time, :git_pull => timeCost['pull'] , :create_pod => timeCost['createPod'], - :pod_execute => timeCost['execute'], :test_cases => test_cases_time, :ts_time => ts_time, + :pod_execute => timeCost['execute'], :test_cases => test_cases_time, :brige => timeCost['evaluateAllTime'], :return_back => return_back_time) end uid_logger("training_task_status start#4**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") From 264e56d80506b104a1a115bd8183ef415bcfedf9 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 17 Jul 2019 17:15:16 +0800 Subject: [PATCH 0880/1015] fixbug --- app/controllers/courses_controller.rb | 4 ++-- app/helpers/export_helper.rb | 33 +++++++++++++++------------ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index c46f9323a..7ff94c16a 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1163,8 +1163,8 @@ class CoursesController < ApplicationController course_id = course.id course_name = course.name course_list_name = course.course_list.present? ? course.course_list.name : "--" - course_assistants = course.course_members.course_user_role(%i[PROFESSOR ASSISTANT_PROFESSOR]) - course_assistants_count = course_assistants&.count + course_assistants = course.teachers + course_assistants_count = course_assistants&.size course_assistants_name = course_assistants_count > 0 ? course_assistants.map{|m| m.user.real_name}.join('、') : "--" course_teacher_member = course.course_members.course_user_role(%i[CREATOR]) course_teacher = course_teacher_member.present? ? course_teacher_member.first.user.real_name : "--" diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index 76f51e498..b08cbb549 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -41,9 +41,9 @@ module ExportHelper w_user = w.user w_1 = (index + 1) if w_user.present? - w_2 = w_user&.login - w_3 = w_user&.real_name - w_3_1 = w_user&.mail + w_2 = w_user&.login.present? ? w_user&.login : "--" + w_3 = w_user&.real_name.present? ? w_user&.real_name : "--" + w_3_1 = w_user&.mail.present? ? w_user.mail : "--" w_4 = w_user.student_id.present? ? w_user.student_id : "--" else w_2 = "--" @@ -129,9 +129,9 @@ module ExportHelper myshixun = w.try(:myshixun) w_user = w.user w_1 = (index + 1) - w_2 = w_user.login - w_3 = w_user.real_name - w_3_1 = w_user.mail + w_2 = w_user&.login.present? ? w_user&.login : "--" + w_3 = w_user&.real_name.present? ? w_user&.real_name : "--" + w_3_1 = w_user&.mail.present? ? w_user.mail : "--" w_4 = w_user.student_id.present? ? w_user.student_id : "--" course_name = course.students.find_by(user_id: w.user_id).try(:course_group_name) w_5 = course_name.present? ? course_name : "--" @@ -214,9 +214,9 @@ module ExportHelper items.includes(user: :user_extension).each_with_index do |work,index| w_1 = (index+1) w_user = work.user - w_2 = w_user.login - w_3 = w_user.real_name - w_3_1 = w_user.mail + w_2 = w_user&.login.present? ? w_user&.login : "--" + w_3 = w_user&.real_name.present? ? w_user&.real_name : "--" + w_3_1 = w_user&.mail.present? ? w_user.mail : "--" w_4 = w_user.student_id.present? ? w_user.student_id : "--" w_5 = work.class_grouping_name if task_type_boolean #是否分组 @@ -305,8 +305,11 @@ module ExportHelper user_start_time = e_user.start_at.present? ? e_user.start_at.strftime('%Y-%m-%d %H:%M') : "--" user_end_time = e_user.end_at.present? ? e_user.end_at.strftime('%Y-%m-%d %H:%M') : "--" user_student_id = user_info.student_id.present? ? user_info.student_id : "--" + user_login = user_info&.login.present? ? user_info.login : "--" + user_real_name = user_info.real_name.present? ? user_info.real_name : "--" + user_mail = user_info&.mail.present? ? user_info.mail : "--" - user_option = [index+1,user_info.login,user_info.real_name, user_info.mail || '--', + user_option = [index+1,user_login,user_real_name, user_mail, user_student_id,user_course,user_commit_stu] if ques_type_boolean other_user_option = [user_obj_score,user_suj_score,user_score,user_start_time,user_end_time] @@ -335,11 +338,11 @@ module ExportHelper topic = nil end w_1 = (index+1) - w_2 = user.login - w_3 = user.real_name - w_3_1 = user.mail - w_4 = user.student_id - w_5 = student.course_group_name + w_2 = user&.login.present? ? user&.login : "--" + w_3 = user&.real_name.present? ? user&.real_name : "--" + w_3_1 = user&.mail.present? ? user.mail : "--" + w_4 = user.student_id.present? ? user.student_id : "--" + w_5 = student&.course_group_name.present? ? student.course_group_name : "--" w_6 = topic.present? ? topic.name : "--" w_7 = topic.present? ? topic.teacher.full_name : "--" w_8 = topic.present? ? topic.teacher.identity : "--" From b56ed404d8bb3a1633f151fb2500c8644dcc4f6d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 17 Jul 2019 17:16:28 +0800 Subject: [PATCH 0881/1015] =?UTF-8?q?=E8=AF=84=E6=B5=8B=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index c36be6284..ca527e47d 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -123,7 +123,7 @@ class MyshixunsController < ApplicationController jenkins_testsets.each_with_index do |j_test_set, i| logger.info("j_test_set: ############## #{j_test_set}") actual_output = tran_base64_decode64(j_test_set['output']) - ts_time += j_test_set['testSetTime'].to_i + #ts_time += j_test_set['testSetTime'].to_i # is_public = test_sets.where(:position => j_test_set['caseId']).first.try(:is_public) logger.info "actual_output:################################################# #{actual_output}" From 1675c21c2119ae56663099bd57e80dc29f7dfca2 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 17 Jul 2019 17:20:18 +0800 Subject: [PATCH 0882/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190716062401_add_ts_time_to_outputs.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20190716062401_add_ts_time_to_outputs.rb b/db/migrate/20190716062401_add_ts_time_to_outputs.rb index 8e0c55a78..7f09ea818 100644 --- a/db/migrate/20190716062401_add_ts_time_to_outputs.rb +++ b/db/migrate/20190716062401_add_ts_time_to_outputs.rb @@ -1,5 +1,5 @@ class AddTsTimeToOutputs < ActiveRecord::Migration[5.2] def change - add_column :outputs, :ts_time, :float + #add_column :outputs, :ts_time, :float end end From 5bfd875ffa5b886ba482a36a18ab58ca66aa3c64 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 17 Jul 2019 17:21:07 +0800 Subject: [PATCH 0883/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190716062401_add_ts_time_to_outputs.rb | 2 +- lib/educoder/tip_exception.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/migrate/20190716062401_add_ts_time_to_outputs.rb b/db/migrate/20190716062401_add_ts_time_to_outputs.rb index 7f09ea818..8e0c55a78 100644 --- a/db/migrate/20190716062401_add_ts_time_to_outputs.rb +++ b/db/migrate/20190716062401_add_ts_time_to_outputs.rb @@ -1,5 +1,5 @@ class AddTsTimeToOutputs < ActiveRecord::Migration[5.2] def change - #add_column :outputs, :ts_time, :float + add_column :outputs, :ts_time, :float end end diff --git a/lib/educoder/tip_exception.rb b/lib/educoder/tip_exception.rb index 09f0228ac..08fd53ed6 100644 --- a/lib/educoder/tip_exception.rb +++ b/lib/educoder/tip_exception.rb @@ -13,7 +13,7 @@ module Educoder @status = status @message = message - Rails.logger.info("############# #{@status}, #{@message}") + Rails.logger.error("############# #{@status}, #{@message}") end def tip_json From 1f6f1dadecca81f20bc3aac3555d11be73d3247c Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 17 Jul 2019 17:27:51 +0800 Subject: [PATCH 0884/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E9=A2=98=E7=9A=84?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E8=80=97=E6=97=B6=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/export_helper.rb | 3 +-- app/views/student_works/shixun_work.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/helpers/export_helper.rb b/app/helpers/export_helper.rb index b08cbb549..742deb85b 100644 --- a/app/helpers/export_helper.rb +++ b/app/helpers/export_helper.rb @@ -163,7 +163,7 @@ module ExportHelper end w_15 = w.work_score.nil? ? "--" : w.work_score.round(1) w_16 = w.update_time ? format_time(w.update_time) : "--" "更新时间" - w_17 = w.cost_time + w_17 = (game_spend_time w.cost_time) teacher_comments = w.student_works_scores if teacher_comments.present? w_18 = "" @@ -173,7 +173,6 @@ module ExportHelper user_score = t&.score user_comment = t.comment.present? ? t.comment : "--" comment_title = "#{user_name}: #{user_time.to_s} #{user_score.to_s}分\n#{user_comment}\n\n" - # ("教师:" + user_name + "\n" + "时间:" + user_time.to_s + "\n" + "分数:" + user_score.to_s + "分" + "\n" + "评语:" + user_comment + "\n\n") w_18 = w_18 + comment_title end else diff --git a/app/views/student_works/shixun_work.json.jbuilder b/app/views/student_works/shixun_work.json.jbuilder index 74c33420e..39e7eb1b3 100644 --- a/app/views/student_works/shixun_work.json.jbuilder +++ b/app/views/student_works/shixun_work.json.jbuilder @@ -22,7 +22,7 @@ index = 1 json.game_list @myshixun.games do |game| json.position index json.end_time game.end_time ? game.end_time : '--' - json.cost_time game.cost_time + json.cost_time (game_spend_time game.cost_time) json.score game.final_score json.complete_status game_status(game, @homework) index += 1 From c2e22e9b835a3616eaac1ce43f9677d614c7c716 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Wed, 17 Jul 2019 17:39:53 +0800 Subject: [PATCH 0885/1015] =?UTF-8?q?=E4=BD=9C=E5=93=81=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/homework_commons/works_list.json.jbuilder | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/homework_commons/works_list.json.jbuilder b/app/views/homework_commons/works_list.json.jbuilder index 458db9621..bbe71661a 100644 --- a/app/views/homework_commons/works_list.json.jbuilder +++ b/app/views/homework_commons/works_list.json.jbuilder @@ -34,7 +34,7 @@ elsif @user_course_identity == Course::STUDENT json.(@work, :id, :work_status, :update_time, :ultimate_score) json.calculation_time @work.calculation_time json.late_penalty @work.late_penalty if @homework.allow_late - json.cost_time @work.myshixun.try(:total_cost_time) + json.cost_time @work.myshixun.try(:total_spend_time) json.work_score work_score_format(@work.work_score, true, @score_open) json.final_score work_score_format(@work.final_score, true, @score_open) json.efficiency work_score_format(@work.efficiency, true, @score_open) @@ -91,7 +91,7 @@ if @homework.homework_type == "practice" json.efficiency work_score_format(work.efficiency, @current_user == work.user, @score_open) json.eff_score work_score_format(work.eff_score, @current_user == work.user, @score_open) - json.cost_time work.myshixun.try(:total_cost_time) + json.cost_time work.myshixun.try(:total_spend_time) json.complete_count work.myshixun.try(:passed_count) json.user_login work.user.try(:login) json.user_name work.user.try(:real_name) From 0d76d6bb3f8b474949c0bff3764a08d9339dac40 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 17 Jul 2019 17:44:47 +0800 Subject: [PATCH 0886/1015] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E7=9A=84=E6=88=90?= =?UTF-8?q?=E7=BB=A9=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 7ff94c16a..55352668f 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1210,7 +1210,7 @@ class CoursesController < ApplicationController course_user_level = [] course_activity_title = "课堂活跃度统计" user_cell_head = %w(排名 真实姓名 登录名 邮箱 学号 分班 作业完成数(*10) 试卷完成数(*10) 问卷完成数(*7) 资源发布数(*5) 帖子发布数(*2) 帖子回复数(*1) 作业回复数(*1) 活跃度) - all_members.each do |u| + all_members.includes(user: :user_extension).each do |u| #用户的基本信息 user = u.user user_login = user.login @@ -1268,7 +1268,7 @@ class CoursesController < ApplicationController #实训作业 if shixun_homeworks.size > 0 - shixun_homeworks&.includes(:score_student_works).each do |s| + shixun_homeworks&.includes(user: :user_extension, score_student_works: :user).each do |s| user_student_work = s.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答 if user_student_work.nil? h_score = 0.0 #该作业的得分为0 @@ -1284,7 +1284,7 @@ class CoursesController < ApplicationController #普通作业 if common_homeworks.size > 0 - common_homeworks&.includes(:score_student_works).each do |c| + common_homeworks&.includes(user: :user_extension, score_student_works: :user).each do |c| user_student_work_1 = c.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答 if user_student_work_1.nil? h_score_1 = 0.0 #该作业的得分为0 @@ -1300,7 +1300,7 @@ class CoursesController < ApplicationController #分组作业 if group_homeworks.size > 0 - group_homeworks&.includes(:score_student_works).each do |g| + group_homeworks&.includes(user: :user_extension, score_student_works: :user).each do |g| user_student_work_3 = g.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答 if user_student_work_3.nil? h_score_3 = 0.0 #该作业的得分为0 @@ -1316,7 +1316,7 @@ class CoursesController < ApplicationController #毕设作业 if tasks.size > 0 - tasks&.includes(:score_graduation_works).each do |task| + tasks&.includes(user: :user_extension, score_graduation_works: :user).each do |task| graduation_work = task.score_graduation_works.select{|work| work.user_id == user.id}.first if graduation_work.nil? t_score = 0.0 @@ -1332,7 +1332,7 @@ class CoursesController < ApplicationController #试卷 if exercises.size > 0 - exercises&.includes(:score_exercise_users).each do |ex| + exercises&.includes(user: :user_extension, score_exercise_users: :user).each do |ex| exercise_work = ex.score_exercise_users.select{|work| work.user_id == user.id}.first if exercise_work.nil? e_score = 0.0 @@ -1375,7 +1375,7 @@ class CoursesController < ApplicationController count_4 = tasks.size count_5 = exercises.size #实训作业 - shixun_homeworks&.includes(:score_student_works).each_with_index do |s,index| + shixun_homeworks&.includes(user: :user_extension, score_student_works: :user).each_with_index do |s,index| all_student_works = s.score_student_works #该实训题的全部用户回答 title_no = index.to_i + 1 student_work_to_xlsx(all_student_works,s) @@ -1385,7 +1385,7 @@ class CoursesController < ApplicationController end #普通作业 - common_homeworks&.includes(:score_student_works).each_with_index do |c,index| + common_homeworks&.includes(user: :user_extension, score_student_works: :user).each_with_index do |c,index| all_student_works = c.score_student_works #当前用户的对该作业的回答 title_no = count_1 + index.to_i + 1 student_work_to_xlsx(all_student_works,c) @@ -1397,7 +1397,7 @@ class CoursesController < ApplicationController end #分组作业 - group_homeworks&.includes(:score_student_works).each_with_index do |c,index| + group_homeworks&.includes(user: :user_extension, score_student_works: :user).each_with_index do |c,index| all_student_works = c.score_student_works #当前用户的对该作业的回答 title_no = count_1 + count_2 + index.to_i + 1 student_work_to_xlsx(all_student_works,c) @@ -1407,7 +1407,7 @@ class CoursesController < ApplicationController end #毕设任务 - tasks&.includes(:score_graduation_works).each_with_index do |c,index| + tasks&.includes(user: :user_extension, score_graduation_works: :user).each_with_index do |c,index| all_student_works = c.score_graduation_works #当前用户的对该作业的回答 title_no = count_1 + count_2 + count_3 + index.to_i + 1 graduation_work_to_xlsx(all_student_works,c,current_user) @@ -1417,7 +1417,7 @@ class CoursesController < ApplicationController end #试卷的导出 - exercises&.includes(:score_exercise_users).each_with_index do |c,index| + exercises&.includes(user: :user_extension, score_exercise_users: :user).each_with_index do |c,index| all_student_works = c.score_exercise_users #当前用户的对该作业的回答 title_no = count_1 + count_2 + count_3 + count_4 + index.to_i + 1 get_export_users(c,course,all_student_works) From 6db538a635d558c66fbb0450f7060d59019f9fb8 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 17 Jul 2019 17:48:50 +0800 Subject: [PATCH 0887/1015] fixbug --- app/controllers/courses_controller.rb | 32 +++++++++++++-------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 55352668f..db73cdcc6 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1139,21 +1139,21 @@ class CoursesController < ApplicationController #课堂的作业信息 shixun_homeworks = homeworks.search_homework_type(4) #全部实训作业 shixun_titles = shixun_homeworks.pluck(:name) + ["总得分"] - shixun_homeworks = shixun_homeworks.includes(:score_student_works) + shixun_homeworks = shixun_homeworks&.includes(user: :user_extension, score_student_works: :user) common_homeworks = homeworks.search_homework_type(1) #全部普通作业 common_titles = common_homeworks.pluck(:name)+ ["总得分"] - common_homeworks = common_homeworks.includes(:score_student_works) + common_homeworks = common_homeworks&.includes(user: :user_extension, score_student_works: :user) group_homeworks = homeworks.search_homework_type(3) #全部分组作业 group_titles = group_homeworks.pluck(:name)+ ["总得分"] - group_homeworks = group_homeworks.includes(:score_student_works) + group_homeworks = group_homeworks&.includes(user: :user_extension, score_student_works: :user) task_titles = tasks.pluck(:name) + ["总得分"] - tasks = tasks.includes(:score_graduation_works) + tasks = tasks&.includes(user: :user_extension, score_graduation_works: :user) exercise_titles = exercises.pluck(:exercise_name) + ["总得分"] - exercises = exercises.includes(:score_exercise_users) + exercises = exercises&.includes(user: :user_extension, score_exercise_users: :user) total_user_score_array = [] #学生总成绩集合 @@ -1210,7 +1210,7 @@ class CoursesController < ApplicationController course_user_level = [] course_activity_title = "课堂活跃度统计" user_cell_head = %w(排名 真实姓名 登录名 邮箱 学号 分班 作业完成数(*10) 试卷完成数(*10) 问卷完成数(*7) 资源发布数(*5) 帖子发布数(*2) 帖子回复数(*1) 作业回复数(*1) 活跃度) - all_members.includes(user: :user_extension).each do |u| + all_members.each do |u| #用户的基本信息 user = u.user user_login = user.login @@ -1268,7 +1268,7 @@ class CoursesController < ApplicationController #实训作业 if shixun_homeworks.size > 0 - shixun_homeworks&.includes(user: :user_extension, score_student_works: :user).each do |s| + shixun_homeworks.each do |s| user_student_work = s.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答 if user_student_work.nil? h_score = 0.0 #该作业的得分为0 @@ -1284,7 +1284,7 @@ class CoursesController < ApplicationController #普通作业 if common_homeworks.size > 0 - common_homeworks&.includes(user: :user_extension, score_student_works: :user).each do |c| + common_homeworks.each do |c| user_student_work_1 = c.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答 if user_student_work_1.nil? h_score_1 = 0.0 #该作业的得分为0 @@ -1300,7 +1300,7 @@ class CoursesController < ApplicationController #分组作业 if group_homeworks.size > 0 - group_homeworks&.includes(user: :user_extension, score_student_works: :user).each do |g| + group_homeworks.each do |g| user_student_work_3 = g.score_student_works.select{|work| work.user_id == user.id}.first #当前用户的对该作业的回答 if user_student_work_3.nil? h_score_3 = 0.0 #该作业的得分为0 @@ -1316,7 +1316,7 @@ class CoursesController < ApplicationController #毕设作业 if tasks.size > 0 - tasks&.includes(user: :user_extension, score_graduation_works: :user).each do |task| + tasks.each do |task| graduation_work = task.score_graduation_works.select{|work| work.user_id == user.id}.first if graduation_work.nil? t_score = 0.0 @@ -1332,7 +1332,7 @@ class CoursesController < ApplicationController #试卷 if exercises.size > 0 - exercises&.includes(user: :user_extension, score_exercise_users: :user).each do |ex| + exercises.each do |ex| exercise_work = ex.score_exercise_users.select{|work| work.user_id == user.id}.first if exercise_work.nil? e_score = 0.0 @@ -1375,7 +1375,7 @@ class CoursesController < ApplicationController count_4 = tasks.size count_5 = exercises.size #实训作业 - shixun_homeworks&.includes(user: :user_extension, score_student_works: :user).each_with_index do |s,index| + shixun_homeworks.each_with_index do |s,index| all_student_works = s.score_student_works #该实训题的全部用户回答 title_no = index.to_i + 1 student_work_to_xlsx(all_student_works,s) @@ -1385,7 +1385,7 @@ class CoursesController < ApplicationController end #普通作业 - common_homeworks&.includes(user: :user_extension, score_student_works: :user).each_with_index do |c,index| + common_homeworks.each_with_index do |c,index| all_student_works = c.score_student_works #当前用户的对该作业的回答 title_no = count_1 + index.to_i + 1 student_work_to_xlsx(all_student_works,c) @@ -1397,7 +1397,7 @@ class CoursesController < ApplicationController end #分组作业 - group_homeworks&.includes(user: :user_extension, score_student_works: :user).each_with_index do |c,index| + group_homeworks.each_with_index do |c,index| all_student_works = c.score_student_works #当前用户的对该作业的回答 title_no = count_1 + count_2 + index.to_i + 1 student_work_to_xlsx(all_student_works,c) @@ -1407,7 +1407,7 @@ class CoursesController < ApplicationController end #毕设任务 - tasks&.includes(user: :user_extension, score_graduation_works: :user).each_with_index do |c,index| + tasks.each_with_index do |c,index| all_student_works = c.score_graduation_works #当前用户的对该作业的回答 title_no = count_1 + count_2 + count_3 + index.to_i + 1 graduation_work_to_xlsx(all_student_works,c,current_user) @@ -1417,7 +1417,7 @@ class CoursesController < ApplicationController end #试卷的导出 - exercises&.includes(user: :user_extension, score_exercise_users: :user).each_with_index do |c,index| + exercises.each_with_index do |c,index| all_student_works = c.score_exercise_users #当前用户的对该作业的回答 title_no = count_1 + count_2 + count_3 + count_4 + index.to_i + 1 get_export_users(c,course,all_student_works) From e705548bf0e173de918f052fc3033ee0f07c99e6 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Wed, 17 Jul 2019 17:52:59 +0800 Subject: [PATCH 0888/1015] fixbug --- app/controllers/courses_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index db73cdcc6..e7ea119b8 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1139,15 +1139,15 @@ class CoursesController < ApplicationController #课堂的作业信息 shixun_homeworks = homeworks.search_homework_type(4) #全部实训作业 shixun_titles = shixun_homeworks.pluck(:name) + ["总得分"] - shixun_homeworks = shixun_homeworks&.includes(user: :user_extension, score_student_works: :user) + shixun_homeworks = shixun_homeworks&.includes(score_student_works: :user) common_homeworks = homeworks.search_homework_type(1) #全部普通作业 common_titles = common_homeworks.pluck(:name)+ ["总得分"] - common_homeworks = common_homeworks&.includes(user: :user_extension, score_student_works: :user) + common_homeworks = common_homeworks&.includes(score_student_works: :user) group_homeworks = homeworks.search_homework_type(3) #全部分组作业 group_titles = group_homeworks.pluck(:name)+ ["总得分"] - group_homeworks = group_homeworks&.includes(user: :user_extension, score_student_works: :user) + group_homeworks = group_homeworks&.includes(score_student_works: :user) task_titles = tasks.pluck(:name) + ["总得分"] tasks = tasks&.includes(user: :user_extension, score_graduation_works: :user) From da1ee20436bdcd15d9b06b7bc8c9ac88ea56183e Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 18 Jul 2019 08:32:27 +0800 Subject: [PATCH 0889/1015] fix interests api 402 bug --- app/controllers/users/interests_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/users/interests_controller.rb b/app/controllers/users/interests_controller.rb index bac9c568d..3f931612d 100644 --- a/app/controllers/users/interests_controller.rb +++ b/app/controllers/users/interests_controller.rb @@ -1,8 +1,9 @@ class Users::InterestsController < Users::BaseController skip_before_action :check_observed_user_exists! - before_action :require_login, :check_auth + before_action :require_login def create + return render_forbidden if current_user.user_extension&.identity.present? identity = params[:identity].to_s.strip extension = current_user.user_extension || current_user.build_user_extension From 9daed3b1ef89274e3a0fc344126eb6e36bb8e08a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 18 Jul 2019 09:45:28 +0800 Subject: [PATCH 0890/1015] =?UTF-8?q?=E6=AF=95=E8=AE=BE=E4=BD=9C=E5=93=81?= =?UTF-8?q?=E5=88=97=E8=A1=A8=EF=BC=9A=E5=AD=A6=E7=94=9F=E7=9A=84=E6=9F=A5?= =?UTF-8?q?=E7=9C=8B=E4=BD=9C=E5=93=81=E6=9D=83=E9=99=90=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/graduation_tasks/tasks_list.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/graduation_tasks/tasks_list.json.jbuilder b/app/views/graduation_tasks/tasks_list.json.jbuilder index 8ee2f78af..5a2d7e08a 100644 --- a/app/views/graduation_tasks/tasks_list.json.jbuilder +++ b/app/views/graduation_tasks/tasks_list.json.jbuilder @@ -63,7 +63,7 @@ if @task.published? || @user_course_identity < Course::STUDENT json.late_penalty work.late_penalty if @task.allow_late json.final_score work_final_score work, @current_user, @user_course_identity json.assign @assign_power - json.view_work @view_work || @current_user.id == work.user_id + json.view_work @view_work || (@current_user.id == work.user_id && work.work_status != 0) end end end \ No newline at end of file From 1e7f0afcb083515c58dc9087dc32cf87ecb751f6 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 18 Jul 2019 09:57:39 +0800 Subject: [PATCH 0891/1015] =?UTF-8?q?=E9=80=89=E6=8B=A9=E9=A2=98=E7=BB=8F?= =?UTF-8?q?=E9=AA=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/game.rb | 2 +- app/views/challenges/index.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/game.rb b/app/models/game.rb index 002116748..88d636998 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -69,7 +69,7 @@ class Game < ApplicationRecord else if self.status == 2 gold = (shixun_status <= 1) ? 0 : self.final_score.to_i - experience = (shixun_status <= 1 || self.final_score.to_i < 0) ? 0 : challenge.score.to_i + experience = (shixun_status <= 1 || self.final_score.to_i < 0) ? 0 : challenge.choose_score.to_i else # 选择题只有在全对的时候才会获取final score总分,错任何一个题final_score就为0 gold = challenge.choose_score diff --git a/app/views/challenges/index.json.jbuilder b/app/views/challenges/index.json.jbuilder index 37ce94305..a542b8119 100644 --- a/app/views/challenges/index.json.jbuilder +++ b/app/views/challenges/index.json.jbuilder @@ -13,7 +13,7 @@ if @challenges.present? json.position challenge.position json.st challenge.st json.name challenge.subject - json.score challenge.score + json.score challenge.all_score json.passed_count challenge.user_passed_count json.playing_count challenge.playing_count json.name_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier) From a1c51e02de47e00800f8ff80a222a191b9aa62d6 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 18 Jul 2019 10:02:08 +0800 Subject: [PATCH 0892/1015] =?UTF-8?q?=E5=B7=B2=E7=BB=8F=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E7=9A=84=E5=AE=9E=E8=AE=AD=EF=BC=8C=E6=97=A0=E6=B3=95=E6=92=A4?= =?UTF-8?q?=E9=94=80=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index a11f1c526..81fa5104c 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -745,6 +745,7 @@ class ShixunsController < ApplicationController # 撤销发布 def cancel_publish + tip_exception("实训已经发布,无法撤销") if @shixun.status == 2 apply = ApplyAction.where(:container_type => "ApplyShixun", :container_id => @shixun.id).order("created_at desc").first if apply && apply.status == 0 apply.update_attribute(:status, 3) From f339a617cd7cb7d30e538097c87ad06c5f6a3930 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 18 Jul 2019 10:32:45 +0800 Subject: [PATCH 0893/1015] =?UTF-8?q?=E7=94=B3=E8=AF=B7=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E5=89=8D=E7=8E=A9=E8=BF=87=E7=9A=84=E5=AE=9E=E8=AE=AD=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E9=87=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 3 +++ app/controllers/shixuns_controller.rb | 22 +++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index ca527e47d..79358f5c2 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -35,6 +35,9 @@ class MyshixunsController < ApplicationController StudentWork.where(:myshixun_id => @myshixun.id).update_all(:myshixun_id => 0, :work_status => 0) + # 实训在申请发布前,是否玩过实训,如果玩过需要更改记录,防止二次重置 + shixun_mod = ShixunModify.exists?(:shixun_id => @shixun.id, :myshixun_id => @myshixun.id, :status => 1) + shixun_mod.update_column(:status, 0) if shixun_mod rescue Exception => e uid_logger_error("myshixun reset failed #{e}") raise ActiveRecord::Rollback diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 81fa5104c..2f333b51a 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -513,7 +513,7 @@ class ShixunsController < ApplicationController # 中间需要一个过渡动画 # TODO: 第一次开启实训都会去判断是否是纯选择题类型,感觉做成在创建关卡的时候就判断该实训是否是纯选择题更加合适 def shixun_exec - if @shixun.opening_time.present? && @shixun.opening_time > Time.now && current_user.shixun_identity(@shixun) > User::EDU_SHIXUN_MEMBER + if is_shixun_opening? tip_show_exception(-3, "#{@shixun.opening_time.strftime('%Y-%m-%d %H:%M:%S')}") end current_myshixun = @shixun.current_myshixun(current_user.id) @@ -522,8 +522,8 @@ class ShixunsController < ApplicationController if current_myshixun games = current_myshixun.games - # 如果TPM和TPI的管卡数不相等或者关卡顺序错了,说明实训被极大的改动,需要重置 - if games.size != min_challenges.size || games.map(&:challenge_id) != min_challenges.map{|challenge| challenge.first} + # 如果TPM和TPI的管卡数不相等或者关卡顺序错了,说明实训被极大的改动,需要重置,实训发布前打过的实训都需要重置 + if is_shixun_reset?(games, min_challenges, current_myshixun) # 这里页面弹框要收到 当前用户myshixun的identifier. tip_show_exception("/myshixuns/#{current_myshixun.try(:identifier)}/reset_my_game") end @@ -803,4 +803,20 @@ private tip_exception(403, "..") end end + + # 实训是否需要开启 + def is_shixun_opening? + @shixun.opening_time.present? && + @shixun.opening_time > Time.now && + current_user.shixun_identity(@shixun) > User::EDU_SHIXUN_MEMBER + end + + # 实训是否需要重置 + def is_shixun_reset?(games, min_challenges, current_myshixun) + # 用户在申请发布之前,是否玩过实训 + modify_shixun = ShixunModify.exists?(:myshixun_id => current_myshixun.id, :shixun_id => @shixun.id, :status => 1) + games.size != min_challenges.size || + games.map(&:challenge_id) != min_challenges.map{|challenge| challenge.first} || + modify_shixun + end end From 4534e8fd0e2935c3bdb69eb543d0ae5133133fe8 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 18 Jul 2019 11:09:02 +0800 Subject: [PATCH 0894/1015] =?UTF-8?q?repo=5Fcontent=E7=9A=84=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 977ddefa0..4996a11ca 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -505,17 +505,18 @@ class GamesController < ApplicationController res = uri_post uri, rep_params uid_logger("repo_content to bridge: res is #{res}") # res值:0 表示正常;-1表示有错误;-2表示代码版本库没了 - if status == 0 && res && (res['code'] == -2 || res['code'] == -1) - # 删除不需要的仓库 - begin - GitService.delete_repository(repo_path: @myshixun.repo_path) - rescue Exception => e - uid_logger_error("#{e.message}") - # 终端循环 - tip_exception("#{e.message}") + # + if status == 0 && res + # 版本库报错,修复不了 + if res['code'] == -1 || res['code'] == -2 + begin + # GitService.delete_repository(repo_path: @myshixun.repo_path) if res['code'] == -1 + project_fork(@myshixun, @shixun.repo_path, current_user.login) + rescue Exception => e + uid_logger_error("#{e.message}") + tip_exception("#{e.message}") + end end - # fork一个新的仓库 - # project_fork(@myshixun, @shixun.repo_path, current_user.login) end rescue Exception => e uid_logger_error(e.message) From 896ca84c722dde96ae8b1bb33778216bdf6bb69e Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 18 Jul 2019 11:24:50 +0800 Subject: [PATCH 0895/1015] competition api --- app/controllers/application_controller.rb | 4 + .../competitions/base_controller.rb | 2 +- .../competition_modules_controller.rb | 28 ++++++ .../competition_teams_controller.rb | 49 ++++++++++ .../competitions/competitions_controller.rb | 6 ++ .../competitions/students_controller.rb | 22 +++++ .../competitions/teachers_controller.rb | 22 +++++ app/forms/competitions/save_team_form.rb | 98 +++++++++++++++++++ app/models/competition.rb | 25 +++++ app/models/competition_module_md_content.rb | 3 + app/models/competition_team.rb | 25 +++++ app/models/team_member.rb | 8 ++ .../competitions/join_team_service.rb | 35 +++++++ .../competitions/save_team_service.rb | 70 +++++++++++++ .../competition_modules/index.json.jbuilder | 7 ++ .../competition_modules/show.json.jbuilder | 8 ++ .../competition_teams/index.json.jbuilder | 23 +++++ .../competitions/students/index.json.jbuilder | 9 ++ .../competitions/teachers/index.json.jbuilder | 9 ++ config/locales/competitions/zh-CN.yml | 8 ++ config/locales/forms/save_team_form.zh-CN.yml | 25 +++++ config/routes.rb | 8 +- 22 files changed, 491 insertions(+), 3 deletions(-) create mode 100644 app/controllers/competitions/competition_modules_controller.rb create mode 100644 app/controllers/competitions/competition_teams_controller.rb create mode 100644 app/controllers/competitions/students_controller.rb create mode 100644 app/controllers/competitions/teachers_controller.rb create mode 100644 app/forms/competitions/save_team_form.rb create mode 100644 app/services/competitions/join_team_service.rb create mode 100644 app/services/competitions/save_team_service.rb create mode 100644 app/views/competitions/competition_modules/index.json.jbuilder create mode 100644 app/views/competitions/competition_modules/show.json.jbuilder create mode 100644 app/views/competitions/competition_teams/index.json.jbuilder create mode 100644 app/views/competitions/students/index.json.jbuilder create mode 100644 app/views/competitions/teachers/index.json.jbuilder create mode 100644 config/locales/competitions/zh-CN.yml create mode 100644 config/locales/forms/save_team_form.zh-CN.yml diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 4bc3d5133..875050642 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -148,6 +148,10 @@ class ApplicationController < ActionController::Base normal_status(403, "") unless User.current.admin? end + def require_business + normal_status(403, "") unless admin_or_business? + end + # 前端会捕捉401,弹登录弹框 # 未授权的捕捉407,弹试用申请弹框 def require_login diff --git a/app/controllers/competitions/base_controller.rb b/app/controllers/competitions/base_controller.rb index 127474ee7..b42a4ce8f 100644 --- a/app/controllers/competitions/base_controller.rb +++ b/app/controllers/competitions/base_controller.rb @@ -6,6 +6,6 @@ class Competitions::BaseController < ApplicationController helper_method :current_competition def current_competition - @_current_competition ||= Competition.find_by!(identifier: params[:competition_id].presence || params[:id]) + @_current_competition ||= Competition.find_by!(identifier: params[:competition_id]) end end \ No newline at end of file diff --git a/app/controllers/competitions/competition_modules_controller.rb b/app/controllers/competitions/competition_modules_controller.rb new file mode 100644 index 000000000..da9873c43 --- /dev/null +++ b/app/controllers/competitions/competition_modules_controller.rb @@ -0,0 +1,28 @@ +class Competitions::CompetitionModulesController < Competitions::BaseController + skip_before_action :require_login, only: [:index, :show] + + before_action :require_business, only: [:update] + + def index + @modules = current_competition.unhidden_competition_modules.order(position: :asc) + end + + def show + @module = current_module + end + + def update + md = current_module.competition_module_md_content || current_module.build_competition_module_md_content + md.name = params[:md_name] + md.content = params[:md_content] + md.save! + + render_ok + end + + private + + def current_module + @_current_module ||= current_competition.unhidden_competition_modules.find(params[:id]) + end +end diff --git a/app/controllers/competitions/competition_teams_controller.rb b/app/controllers/competitions/competition_teams_controller.rb new file mode 100644 index 000000000..34c80d24c --- /dev/null +++ b/app/controllers/competitions/competition_teams_controller.rb @@ -0,0 +1,49 @@ +class Competitions::CompetitionTeamsController < Competitions::BaseController + def index + admin_or_business? ? all_competition_teams : user_competition_teams + end + + def create + team = current_competition.competition_teams.new(user: current_user) + Competitions::SaveTeamService.call(team, save_params) + render_ok + end + + def update + team = current_competition.competition_teams.where(user: current_user).find(params[:id]) + Competitions::SaveTeamService.call(team, save_params) + render_ok + end + + def join + Competitions::JoinTeamService.call(current_competition, current_user, params) + render_ok + rescue Competitions::JoinTeamService::Error => ex + render_error(ex.message) + end + + private + + def all_competition_teams + teams = current_competition.competition_teams + + keyword = params[:keyword].to_s.strip + if keyword.present? + teams = teams.joins(users: { user_extension: :school }).where('schools.name LIKE ?', "%#{keyword}%") + end + + @count = teams.count + @teams = paginate(teams.includes(:user, users: :user_extension)) + end + + def user_competition_teams + teams = current_competition.competition_teams + teams = teams.joins(:team_members).where(team_members: { user_id: current_user.id }) + @teams = teams.includes(:user, users: :user_extension).to_a + @count = @teams.size + end + + def save_params + params.permit(:name, teacher_ids: [], member_ids: []) + end +end diff --git a/app/controllers/competitions/competitions_controller.rb b/app/controllers/competitions/competitions_controller.rb index f962682a1..34dac7350 100644 --- a/app/controllers/competitions/competitions_controller.rb +++ b/app/controllers/competitions/competitions_controller.rb @@ -29,4 +29,10 @@ class Competitions::CompetitionsController < Competitions::BaseController return end end + + private + + def current_competition + @_current_competition ||= Competition.find_by!(identifier: params[:id]) + end end \ No newline at end of file diff --git a/app/controllers/competitions/students_controller.rb b/app/controllers/competitions/students_controller.rb new file mode 100644 index 000000000..8fd235fd1 --- /dev/null +++ b/app/controllers/competitions/students_controller.rb @@ -0,0 +1,22 @@ +class Competitions::StudentsController < Competitions::BaseController + def index + keyword = params[:keyword].to_s.strip + if keyword.blank? + @students = [] + return + end + + students = User.joins(:user_extension).where(status: 1, user_extensions: { identity: 1 }) + students = students.where.not(id: params[:student_ids]) if params[:student_ids].present? + students = students.where('LOWER(CONCAT(lastname, firstname, login, nickname)) LIKE ?', "%#{keyword}%") + @students = students.includes(user_extension: :school).limit(20) + + # 队员多次报名限制 + if current_competition.member_multiple_limited? + ids = @students.map(&:id) + members = current_competition.team_members.where(user_id: ids) + members = members.where.not(competition_team_id: params[:team_id]) if params[:team_id].present? + @enrolled_map = members.group(:user_id).count + end + end +end diff --git a/app/controllers/competitions/teachers_controller.rb b/app/controllers/competitions/teachers_controller.rb new file mode 100644 index 000000000..76c7cfe6a --- /dev/null +++ b/app/controllers/competitions/teachers_controller.rb @@ -0,0 +1,22 @@ +class Competitions::TeachersController < Competitions::BaseController + def index + keyword = params[:keyword].to_s.strip + if keyword.blank? + @teachers = [] + return + end + + teachers = User.joins(:user_extension).where(status: 1, user_extensions: { identity: 0 }) + teachers = teachers.where.not(id: params[:teacher_ids]) if params[:teacher_ids].present? + teachers = teachers.where('LOWER(CONCAT(lastname, firstname, login, nickname)) LIKE ?', "%#{keyword}%") + @teachers = teachers.includes(user_extension: :school).limit(10) + + # 老师多次报名限制 + if current_competition.teacher_multiple_limited? + ids = @teachers.map(&:id) + members = current_competition.team_members.where(user_id: ids) + members = members.where.not(competition_team_id: params[:team_id]) if params[:team_id].present? + @enrolled_map = members.group(:user_id).count + end + end +end diff --git a/app/forms/competitions/save_team_form.rb b/app/forms/competitions/save_team_form.rb new file mode 100644 index 000000000..10685d260 --- /dev/null +++ b/app/forms/competitions/save_team_form.rb @@ -0,0 +1,98 @@ +class Competitions::SaveTeamForm + include ActiveModel::Model + + attr_accessor :competition, :team, :creator + attr_accessor :name, :teacher_ids, :member_ids + + validates :name, presence: true + + validate :check_creator_enrollable + def check_creator_enrollable + return unless check_creator_identity_enrollable + + check_creator_multiple_enrollable + end + + validate :check_teachers_enrollable + def check_teachers_enrollable + if competition.teacher_enroll_forbidden? && teacher_ids.present? + errors.add(:teacher_ids, :enroll_forbidden) + return + end + + self.teacher_ids = teacher_ids.map(&:to_i) + all_teachers = creator.is_teacher? ? teacher_ids + [creator.id] : teacher_ids + all_teachers.uniq! + + if all_teachers.size < competition.teacher_staff.minimum || all_teachers.size > competition.teacher_staff.maximum + errors.add(:teacher_ids, :invalid_count, minimum: competition.teacher_staff.minimum, maximum: competition.teacher_staff.maximum) + return + end + + # 老师可多次报名,不检查 + return unless competition.teacher_multiple_limited? + + # 存在已报名老师 + enrolled_teacher_members = competition.team_members.where(user_id: all_teachers) + .where.not(competition_team_id: team.id).includes(:user) + if enrolled_teacher_members.present? + errors.add(:teacher_ids, :enrolled, names: enrolled_teacher_members.map { |m| m.user.real_name }.join(',')) + return + end + end + + validate :check_members_enrollable + def check_members_enrollable + if competition.member_enroll_forbidden? && member_ids.present? + errors.add(:member_ids, :enroll_forbidden) + return + end + + self.member_ids = member_ids.map(&:to_i) + all_members = creator.is_teacher? ? member_ids : member_ids + [creator.id] + all_members.uniq! + + if all_members.size < competition.member_staff.minimum || all_members.size > competition.member_staff.maximum + errors.add(:member_ids, :invalid_count, minimum: competition.member_staff.minimum, maximum: competition.member_staff.maximum) + return + end + + # 成员可多次报名,不检查 + return unless competition.member_multiple_limited? + + # 存在已报名成员 + enrolled_members = competition.team_members.where(user_id: all_members) + .where.not(competition_team_id: team.id).includes(:user) + if enrolled_members.present? + errors.add(:member_ids, :enrolled, names: enrolled_members.map { |m| m.user.real_name }.join(',')) + return + end + end + + private + + # 竞赛是否限制了职业 + def check_creator_identity_enrollable + if user.is_teacher? && competition.teacher_enroll_forbidden? + errors.add(:creator, :teacher_enroll_forbidden) + return false + elsif !user.is_teacher? && competition.member_enroll_forbidden? + errors.add(:creator, :member_enroll_forbidden) + return false + end + + true + end + + # 创建者是否能多次报名 + def check_creator_multiple_enrollable + return unless competition.enrolled?(user) + + if (user.is_teacher? && competition.teacher_multiple_limited?) || (!user.is_teacher? && competition.member_multiple_limited?) + errors.add(:creator, :enrolled) + return false + end + + true + end +end \ No newline at end of file diff --git a/app/models/competition.rb b/app/models/competition.rb index 9a85bda58..f5d146ab4 100644 --- a/app/models/competition.rb +++ b/app/models/competition.rb @@ -1,10 +1,15 @@ class Competition < ApplicationRecord has_many :competition_modules, dependent: :destroy + has_many :unhidden_competition_modules, -> { where(hidden: false) }, class_name: 'CompetitionModule' + has_many :competition_stages, dependent: :destroy has_many :competition_stage_sections, dependent: :destroy has_one :current_stage_section, -> { where('end_time > NOW()') }, class_name: 'CompetitionStageSection' + + has_many :competition_teams, dependent: :destroy has_many :team_members, dependent: :destroy + has_many :competition_staffs, dependent: :destroy has_one :teacher_staff, -> { where(category: :teacher) }, class_name: 'CompetitionStaff' has_one :member_staff, -> { where.not(category: :teacher) }, class_name: 'CompetitionStaff' @@ -28,6 +33,26 @@ class Competition < ApplicationRecord team_members.exists?(user_id: user.id) end + # 是否禁止教师报名 + def teacher_enroll_forbidden? + teacher_staff.blank? || teacher_staff.maximum.zero? + end + + # 是否禁止学生报名 + def member_enroll_forbidden? + member_staff.blank? || member_staff.maximum.zero? + end + + # 老师是否能多次报名 + def teacher_multiple_limited? + teacher_staff.mutiple_limited? + end + + # 队员是否能多次报名 + def member_multiple_limited? + member_staff.mutiple_limited? + end + private def create_competition_modules diff --git a/app/models/competition_module_md_content.rb b/app/models/competition_module_md_content.rb index cbf5a829a..9dfcfca84 100644 --- a/app/models/competition_module_md_content.rb +++ b/app/models/competition_module_md_content.rb @@ -2,4 +2,7 @@ class CompetitionModuleMdContent < ApplicationRecord belongs_to :competition_module has_many :attachments, as: :container, dependent: :destroy + + validates :name, presence: true + validates :content, presence: true end \ No newline at end of file diff --git a/app/models/competition_team.rb b/app/models/competition_team.rb index aa19db3b0..625b29421 100644 --- a/app/models/competition_team.rb +++ b/app/models/competition_team.rb @@ -1,8 +1,33 @@ class CompetitionTeam < ApplicationRecord + + CODE_CHARS = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z).freeze + belongs_to :user belongs_to :competition has_many :team_members, dependent: :destroy + has_many :users, through: :team_members, source: :user has_many :members, -> { without_teachers }, class_name: 'TeamMember' has_many :teachers, -> { only_teachers }, class_name: 'TeamMember' + + def group_team_type? + team_type.zero? + end + + def personal_team_type? + team_type == 1 + end + + def en_team_type + group_team_type? ? 'group' : 'personal' + end + + def generate_invite_code + code = CODE_CHARS.sample(6).join + while self.class.exists?(invite_code: code) + code = CODE_CHARS.sample(6).join + end + self.code = code + code + end end \ No newline at end of file diff --git a/app/models/team_member.rb b/app/models/team_member.rb index 3909325e8..31890ea2e 100644 --- a/app/models/team_member.rb +++ b/app/models/team_member.rb @@ -5,4 +5,12 @@ class TeamMember < ApplicationRecord scope :only_teachers, -> { where(is_teacher: true) } scope :without_teachers, -> { where(is_teacher: false) } + + def creator? + role == 1 + end + + def en_role + is_teacher? ? 'teacher' : 'member' + end end \ No newline at end of file diff --git a/app/services/competitions/join_team_service.rb b/app/services/competitions/join_team_service.rb new file mode 100644 index 000000000..df889abe2 --- /dev/null +++ b/app/services/competitions/join_team_service.rb @@ -0,0 +1,35 @@ +class Competitions::JoinTeamService < ApplicationService + Error = Class.new(StandardError) + + attr_reader :competition, :user, :params + + def initialize(competition, user, params) + @competition = competition + @user = user + @params = params + end + + def call + invite_code = params[:invite_code].to_s.strip + raise Error, '战队邀请码不能为空' if invite_code.blank? + + is_teacher = user.is_teacher? + raise Error, '本竞赛的参赛者限定为:学生' if is_teacher && competition.teacher_enroll_forbidden? + raise Error, '本竞赛的参赛者限定为:教师' if !is_teacher && competition.member_enroll_forbidden? + + team = competition.competition_teams.find_by(invite_code: invite_code) + raise Error, '战队邀请码无效' if team.blank? + raise Error, '您已加入该战队' if team.team_members.exists?(user_id: user.id) + + enrolled = competition.team_members.exists?(user_id: user.id) + if enrolled && (is_teacher && competition.teacher_multiple_limited?) || (!is_teacher && competition.member_multiple_limited?) + raise Error, '您已加入其它战队' + end + + raise Error, '该战队教师人数已满' if is_teacher && team.teachers.count == competition.teacher_staff.maximum + raise Error, '该战队队员人数已满' if !is_teacher && team.members.count == competition.member_staff.maximum + + role = is_teacher ? 3 : 2 + team.team_members.create!(competition_id: competition.id, user_id: user, role: role, is_teacher: is_teacher) + end +end \ No newline at end of file diff --git a/app/services/competitions/save_team_service.rb b/app/services/competitions/save_team_service.rb new file mode 100644 index 000000000..c134e70d7 --- /dev/null +++ b/app/services/competitions/save_team_service.rb @@ -0,0 +1,70 @@ +class Competitions::SaveTeamService < ApplicationService + attr_reader :competition, :team, :creator, :params + + TEAM_MEMBER_ATTRIBUTES = %i[competition_id competition_team_id user_id role is_teacher created_at updated_at] + + def initialize(team, params) + @team = team + @competition = team.competition + @creator = team.user + @params = params + end + + def call + Competitions::SaveTeamForm.new(form_params).validate! + + new_record = team.new_record? + is_teacher = team.user.is_teacher? + ActiveRecord::Base.transaction do + team.generate_invite_code if new_record + team.name = params[:name].to_s.strip + team.save! + + # 创建者 + team.team_members.create!(user_id: creator.id, competition_id: competition.id, role: 1, is_teacher: is_teacher) if new_record + + update_teacher_team_members! + update_member_team_members! + end + end + + private + + def update_teacher_team_members! + teacher_ids = Array.wrap(params[:teacher_ids]).map(:to_i) + old_teacher_ids = team.team_members.where(role: 3).pluck(:user_id) + + destroy_teacher_ids = old_teacher_ids - teacher_ids + team.team_members.where(role: 3).where(user_id: destroy_teacher_ids).delete_all + + new_teacher_ids = teacher_ids - old_teacher_ids + TeamMember.bulk_insert(*TEAM_MEMBER_ATTRIBUTES) do |worker| + base_attr = { competition_id: competition.id, competition_team_id: team.id, role: 3, is_teacher: true } + new_teacher_ids.each do |teacher_id| + next if teacher_id == creator.id + worker.add(base_attr.merge(user_id: teacher_id)) + end + end + end + + def update_member_team_members! + member_ids = Array.wrap(params[:member_ids]).map(:to_i) + old_member_ids = team.team_members.where(role: 2).pluck(:user_id) + + destroy_member_ids = old_member_ids - member_ids + team.team_members.where(role: 2).where(user_id: destroy_member_ids).delete_all + + new_member_ids = member_ids - old_member_ids + TeamMember.bulk_insert(*TEAM_MEMBER_ATTRIBUTES) do |worker| + base_attr = { competition_id: competition.id, competition_team_id: team.id, role: 2, is_teacher: false } + new_member_ids.each do |member_id| + next if member_id == creator.id + worker.add(base_attr.merge(user_id: member_id)) + end + end + end + + def form_params + params.merge(competition: competition, team: team, creator: creator) + end +end \ No newline at end of file diff --git a/app/views/competitions/competition_modules/index.json.jbuilder b/app/views/competitions/competition_modules/index.json.jbuilder new file mode 100644 index 000000000..decfcb415 --- /dev/null +++ b/app/views/competitions/competition_modules/index.json.jbuilder @@ -0,0 +1,7 @@ + +json.modules do + json.array! @modules.each do |m| + json.extract! m, :id, :name, :position, :url + end +end +json.count @modules.size diff --git a/app/views/competitions/competition_modules/show.json.jbuilder b/app/views/competitions/competition_modules/show.json.jbuilder new file mode 100644 index 000000000..d47742cf0 --- /dev/null +++ b/app/views/competitions/competition_modules/show.json.jbuilder @@ -0,0 +1,8 @@ +json.extract! @module, :id, :name, :position, :url, :md_edit + +md = @module.competition_module_md_content +if md.present? + json.md_name md.name + json.md_content md.content + json.created_at md.created_at.strftime('%Y-%m-%d %H:%M:%S') +end \ No newline at end of file diff --git a/app/views/competitions/competition_teams/index.json.jbuilder b/app/views/competitions/competition_teams/index.json.jbuilder new file mode 100644 index 000000000..86bb86a1c --- /dev/null +++ b/app/views/competitions/competition_teams/index.json.jbuilder @@ -0,0 +1,23 @@ +json.count @count +json.competition_teams do + json.array! @teams.each do |team| + json.extract! team, :id, :name, :invite_code + json.team_type team.en_team_type + json.school_name team.user.school_name + + json.manage_permission current_user.id == team.user_id + + json.creator do + json.partial! 'users/user_simple', user: team.user + json.role team.team_members.find(&:creator?).en_role + end + + json.team_members do + json.array! team.team_members.each do |member| + json.partial! 'users/user_simple', user: member.user + json.user_id member.user_id + json.role member.en_role + end + end + end +end diff --git a/app/views/competitions/students/index.json.jbuilder b/app/views/competitions/students/index.json.jbuilder new file mode 100644 index 000000000..73ccd7d2d --- /dev/null +++ b/app/views/competitions/students/index.json.jbuilder @@ -0,0 +1,9 @@ +json.teachers do + json.array! @students.each do |student| + json.id student.id + json.name student.full_name + json.student_id student.student_id + json.school_name student.school_name + json.enrollable !current_competition.member_multiple_limited? || !@enrolled_map.key?(student.id) + end +end \ No newline at end of file diff --git a/app/views/competitions/teachers/index.json.jbuilder b/app/views/competitions/teachers/index.json.jbuilder new file mode 100644 index 000000000..4a8d2961d --- /dev/null +++ b/app/views/competitions/teachers/index.json.jbuilder @@ -0,0 +1,9 @@ +json.teachers do + json.array! @teachers.each do |teacher| + json.id teacher.id + json.name teacher.full_name + json.identity teacher.identity + json.school_name teacher.school_name + json.enrollable !current_competition.teacher_multiple_limited? || !@enrolled_map.key?(teacher.id) + end +end \ No newline at end of file diff --git a/config/locales/competitions/zh-CN.yml b/config/locales/competitions/zh-CN.yml new file mode 100644 index 000000000..9c3ff2f1e --- /dev/null +++ b/config/locales/competitions/zh-CN.yml @@ -0,0 +1,8 @@ +'zh-CN': + activerecord: + models: + competition_module_md_content: '' + attributes: + competition_module_md_content: + name: '标题' + content: '内容' diff --git a/config/locales/forms/save_team_form.zh-CN.yml b/config/locales/forms/save_team_form.zh-CN.yml new file mode 100644 index 000000000..106527687 --- /dev/null +++ b/config/locales/forms/save_team_form.zh-CN.yml @@ -0,0 +1,25 @@ +'zh-CN': + activemodel: + attributes: + competitions/save_team_form: + competition: '' + name: '战队名称' + creator: '' + teacher_ids: '' + member_ids: '' + errors: + models: + competitions/save_team_form: + attributes: + creator: + teacher_enroll_forbidden: "本竞赛的参赛者限定为:学生" + member_enroll_forbidden: "本竞赛的参赛者限定为:教师" + teacher_ids: + enroll_forbidden: "本竞赛的参赛者限定为:学生" + invalid_count: "教师数量应为%{minimum}~%{maximum}人" + enrolled: "教师 ${names} 已加入其它战队了" + member_ids: + enroll_forbidden: "本竞赛的参赛者限定为:教师" + invalid_count: "队员数量应为%{minimum}~%{maximum}人" + enrolled: "队员 ${names} 已加入其它战队了" + diff --git a/config/routes.rb b/config/routes.rb index 71cfb8c55..dc521266c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -672,9 +672,13 @@ Rails.application.routes.draw do scope module: :competitions do resources :competitions, only: [:index, :show] do - resources :competition_modules, only: [:index, :show] + resources :competition_modules, only: [:index, :show, :update] resource :competition_staff - resources :competition_teams, only: [:index, :show] + resources :competition_teams, only: [:index, :show] do + post :join, on: :collection + end + resources :teachers, only: [:index] + resources :students, only: [:index] end end end From 73f4cbda16618f09e93c53c6aa705cb4b77ecdc9 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 18 Jul 2019 11:29:48 +0800 Subject: [PATCH 0896/1015] fixbug --- app/controllers/courses_controller.rb | 1 - app/controllers/exercises_controller.rb | 1 - app/models/exercise.rb | 10 +++++----- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index e7ea119b8..a78aa028b 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -1373,7 +1373,6 @@ class CoursesController < ApplicationController count_2 = common_homeworks.size count_3 = group_homeworks.size count_4 = tasks.size - count_5 = exercises.size #实训作业 shixun_homeworks.each_with_index do |s,index| all_student_works = s.score_student_works #该实训题的全部用户回答 diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 2216574a9..f26e97849 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -511,7 +511,6 @@ class ExercisesController < ApplicationController else exercise_end_time = t[:end_time].to_time end - # exercise_end_time = t[:end_time].present? ? t[:end_time].to_time : nil exercise_group = exercise_groups.find_in_exercise_group("course_group_id",course_id) #判断该分班是否存在 if exercise_group.present? && (exercise_group.first.publish_time < Time.now) && (exercise_publish_time != exercise_group.first.publish_time) error_count += 1 diff --git a/app/models/exercise.rb b/app/models/exercise.rb index a46fded25..aba0a00bc 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -74,15 +74,15 @@ class Exercise < ApplicationRecord # 根据是否统一发布获取作业的作品列表 def all_works - ex_users = unified_setting ? exercise_users : + ex_users = self.unified_setting ? exercise_users : exercise_users.joins("join course_members on exercise_users.user_id=course_members.user_id"). where(course_members: {course_group_id: published_settings.pluck(:course_group_id)}) end # 分班权限的老师可见的作品列表 - def all_exercise_users user_id + def all_exercise_users(user_id) # member = course.course_member(user_id) - teacher_course_groups = course.teacher_course_groups.get_user_groups(user_id) + teacher_course_groups = course.teacher_course_groups.where(user_id:user_id) ex_users = self.all_works # 有分班权限的统计管理的分班且已发布的学生情况 if teacher_course_groups.exists? @@ -154,11 +154,11 @@ class Exercise < ApplicationRecord update_column("exercise_status",3) end else - ex_group_setting = exercise_group_settings + # ex_group_setting = exercise_group_settings user_group = course.students.where(user_id:user_id).select(:course_group_id) if user_group.exists? user_group_id = user_group.first&.course_group_id - user_ex_group_setting = ex_group_setting.where(course_group_id:user_group_id).select(:publish_time,:end_time) + user_ex_group_setting = exercise_group_settings.where(course_group_id:user_group_id).select(:publish_time,:end_time) pb_time = user_ex_group_setting.first&.publish_time en_time = user_ex_group_setting.first&.end_time else From 4043de1dd0e7e262164fdea32e9a8e582a7866ba Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 18 Jul 2019 13:45:15 +0800 Subject: [PATCH 0897/1015] =?UTF-8?q?=E9=87=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 2 +- app/controllers/shixuns_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 79358f5c2..c6fca1c99 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -36,7 +36,7 @@ class MyshixunsController < ApplicationController StudentWork.where(:myshixun_id => @myshixun.id).update_all(:myshixun_id => 0, :work_status => 0) # 实训在申请发布前,是否玩过实训,如果玩过需要更改记录,防止二次重置 - shixun_mod = ShixunModify.exists?(:shixun_id => @shixun.id, :myshixun_id => @myshixun.id, :status => 1) + shixun_mod = ShixunModify.where(:shixun_id => @shixun.id, :myshixun_id => @myshixun.id, :status => 1).take shixun_mod.update_column(:status, 0) if shixun_mod rescue Exception => e uid_logger_error("myshixun reset failed #{e}") diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 2f333b51a..f1e36a5c8 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -813,7 +813,7 @@ private # 实训是否需要重置 def is_shixun_reset?(games, min_challenges, current_myshixun) - # 用户在申请发布之前,是否玩过实训 + # 用户在申请发布之前,是否玩过实训 TODO: 重置的字段应该迁移到myshixuns表比较合适 modify_shixun = ShixunModify.exists?(:myshixun_id => current_myshixun.id, :shixun_id => @shixun.id, :status => 1) games.size != min_challenges.size || games.map(&:challenge_id) != min_challenges.map{|challenge| challenge.first} || From d9eb84eafc0015339743b8096ac249a9fec77e76 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 18 Jul 2019 14:38:00 +0800 Subject: [PATCH 0898/1015] =?UTF-8?q?=E7=BB=8F=E9=AA=8C=E5=80=BC=E4=B8=8D?= =?UTF-8?q?=E5=A4=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/game.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/game.rb b/app/models/game.rb index 88d636998..f1f2a09b4 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -61,7 +61,7 @@ class Game < ApplicationRecord if self.status == 2 # 通关了则取实际得分,没通关则取总分 gold = (shixun_status <= 1) ? 0 : self.final_score.to_i # 只要过关了,查看了答案经验值就是0;通关前查看了答案金final_score为负数 - experience = (shixun_status <= 1 || self.final_score.to_i < 0) ? 0 : challenge.score.to_i + experience = (shixun_status <= 1 || self.final_score.to_i < 0) ? 0 : challenge.final_score.to_i else gold = challenge.score.to_i experience = gold From 0536b357bc4d1a309ca38647f182477b416a7cd9 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 18 Jul 2019 14:48:02 +0800 Subject: [PATCH 0899/1015] competition: join team apig --- .../competition_teams_controller.rb | 25 +++++++++++++++-- app/models/competition.rb | 5 ++++ .../create_personal_team_service.rb | 27 +++++++++++++++++++ .../competitions/save_team_service.rb | 1 + config/routes.rb | 1 + 5 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 app/services/competitions/create_personal_team_service.rb diff --git a/app/controllers/competitions/competition_teams_controller.rb b/app/controllers/competitions/competition_teams_controller.rb index 34c80d24c..b4861c4d3 100644 --- a/app/controllers/competitions/competition_teams_controller.rb +++ b/app/controllers/competitions/competition_teams_controller.rb @@ -4,9 +4,16 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController end def create - team = current_competition.competition_teams.new(user: current_user) - Competitions::SaveTeamService.call(team, save_params) + if current_competition.personal? # 个人赛报名 + Competitions::CreatePersonalTeamService.call(current_competition, current_user) + else + team = current_competition.competition_teams.new(user: current_user) + Competitions::SaveTeamService.call(team, save_params) + end render_ok + + rescue Competitions::CreatePersonalTeamService::Error => ex + render_error(ex.message) end def update @@ -22,6 +29,20 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController render_error(ex.message) end + def leave + team = current_competition.competition_teams.find(params[:id]) + member = team.team_members.find_by(user_id: current_user.id) + return render_error('您不是该战队的成员') if member.blank? + + if member.user_id == team.user_id + team.destroy! # 队长退出,战队解散 + else + member.destroy! + end + + render_ok + end + private def all_competition_teams diff --git a/app/models/competition.rb b/app/models/competition.rb index f5d146ab4..024478ad6 100644 --- a/app/models/competition.rb +++ b/app/models/competition.rb @@ -23,6 +23,11 @@ class Competition < ApplicationRecord status? end + # 是否为个人赛 + def personal? + competition_staffs.maximum(:maximum) == 1 + end + # 报名是否结束 def enroll_ended? enroll_end_time.blank? || enroll_end_time < Time.now diff --git a/app/services/competitions/create_personal_team_service.rb b/app/services/competitions/create_personal_team_service.rb new file mode 100644 index 000000000..12b595cae --- /dev/null +++ b/app/services/competitions/create_personal_team_service.rb @@ -0,0 +1,27 @@ +class Competitions::CreatePersonalTeamService < ApplicationService + Error = Class.new(StandardError) + + attr_reader :competition, :user + + def initialize(competition, user) + @competition = competition + @user = user + end + + def call + raise Error, '个人赛才能报名' unless competition.personal? + + is_teacher = user.is_teacher? + raise Error, '本竞赛的参赛者限定为:学生' if is_teacher && competition.teacher_enroll_forbidden? + raise Error, '本竞赛的参赛者限定为:教师' if !is_teacher && competition.member_enroll_forbidden? + + enrolled = competition.competition_teams.exists?(user_id: user.id) + multiple_limited = (is_teacher && competition.teacher_multiple_limited?) || (!is_teacher && competition.member_multiple_limited?) + raise Error, '您已报名该竞赛' if enrolled && multiple_limited + + ActiveRecord::Base.transaction do + team = competition.competition_teams.create!(name: user.show_name, user_id: user.id) + team.team_members.create!(competition_id: competition, user_id: user.id, role: 1, is_teacher: is_teacher) + end + end +end \ No newline at end of file diff --git a/app/services/competitions/save_team_service.rb b/app/services/competitions/save_team_service.rb index c134e70d7..1021e6e6d 100644 --- a/app/services/competitions/save_team_service.rb +++ b/app/services/competitions/save_team_service.rb @@ -17,6 +17,7 @@ class Competitions::SaveTeamService < ApplicationService is_teacher = team.user.is_teacher? ActiveRecord::Base.transaction do team.generate_invite_code if new_record + team.team_type = 1 # 组队竞赛 team.name = params[:name].to_s.strip team.save! diff --git a/config/routes.rb b/config/routes.rb index dc521266c..a5742494d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -676,6 +676,7 @@ Rails.application.routes.draw do resource :competition_staff resources :competition_teams, only: [:index, :show] do post :join, on: :collection + post :leave, on: :member end resources :teachers, only: [:index] resources :students, only: [:index] From 074454743cf13d5514c9fc46ab7feb1234ea6e58 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 18 Jul 2019 14:54:43 +0800 Subject: [PATCH 0900/1015] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 10 ++++++---- app/controllers/myshixuns_controller.rb | 10 +++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 4996a11ca..9eed3cc69 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -712,6 +712,7 @@ class GamesController < ApplicationController uid_logger("################params[:resubmit]: #{params[:resubmit]}") uid_logger("################resubmit_identifier: #{resubmit_identifier}") uid_logger("################time_out: #{params[:time_out]}") + sec_key = params[:sec_key] if (params[:time_out] == "false") && ((params[:resubmit].blank? && @game.status == 1) || (params[:resubmit].present? && (params[:resubmit] != resubmit_identifier))) # 代码评测的信息 @@ -759,7 +760,7 @@ class GamesController < ApplicationController # 轮询结束,更新评测统计耗时 if game_status == 0 || game_status == 2 - e_record = EvaluateRecord.where(:game_id => @game.id).first + e_record = EvaluateRecord.where(:sec_key => sec_key).first if e_record front_js = format("%.3f", (Time.now.to_f - e_record.try(:updated_at).to_f)).to_f consume_time = format("%.3f", (Time.now - e_record.created_at)).to_f @@ -767,7 +768,7 @@ class GamesController < ApplicationController end end - uid_logger("game is is #{@game.id}, record id is #{e_record.try(:id)}, time is**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") + uid_logger("game is #{@game.id}, record id is #{e_record.try(:id)}, time is**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") # 记录前端总耗时 record_consume_time = EvaluateRecord.where(:game_id => @game.id).first.try(:consume_time) # 实训制作者当前拥有的金币 @@ -852,7 +853,7 @@ class GamesController < ApplicationController if max_query_index > 0 uid_logger("max_query_index is #{max_query_index} game id is #{@game.id}, challenge_id is #{challenge.id}") - @qurey_test_sets = TestSet.find_by_sql("SELECT o.code, o.actual_output, o.out_put, o.result, o.test_set_position, + @qurey_test_sets = TestSet.find_by_sql("SELECT o.code, o.actual_output, o.out_put, o.result, o.test_set_position, o.ts_time, o.query_index, t.is_public, t.input, t.output, o.compile_success FROM outputs o, games g, challenges c, test_sets t where g.id=#{@game.id} and c.id=#{challenge.id} and o.query_index=#{max_query_index} and g.id = o.game_id and c.id= g.challenge_id and t.challenge_id = c.id and @@ -866,8 +867,9 @@ class GamesController < ApplicationController end @last_compile_output = @qurey_test_sets.first['out_put'].gsub(/\n/, '
').gsub(/\t/, " \; \; \; \; \; \; \; \;") if @qurey_test_sets.first['out_put'].present? else + # 没有评测过,第一次进来后的呈现方式 @qurey_test_sets = TestSet.find_by_sql("SELECT t.is_public, t.input, t.output, t.position - FROM test_sets t where t.challenge_id = #{challenge.id}") + FROM test_sets t where t.challenge_id = #{challenge.id}") end end diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 79358f5c2..617ed29a3 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -46,6 +46,7 @@ class MyshixunsController < ApplicationController end # 代码运行中的信息接口 + # 这个方法是中间层主动调用的,点击评测后,中间层会发送参数过来,告诉目前Pod的启动情况,一次评测会调用两次请求 def code_runinng_message begin jsonTestDetails = JSON.parse(params[:jsonTestDetails]) @@ -100,12 +101,11 @@ class MyshixunsController < ApplicationController game_id = jsonTestDetails['buildID'] sec_key = jsonTestDetails['sec_key'] - # 资源消耗 - res_usage = jsonTestDetails['resUsage'] - logger.info("training_task_status start#1**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") resubmit = jsonTestDetails['resubmit'] outPut = tran_base64_decode64(jsonTestDetails['outPut']) + # 资源消耗 + max_mem = tran_base64_decode64(jsonTestDetails['resUsage']) if jsonTestDetails['resUsage'].present? jenkins_testsets = jsonTestDetails['msg'] compile_success = jsonTestDetails['compileSuccess'] # message = Base64.decode64(params[:msg]) unless params[:msg].blank? @@ -140,7 +140,7 @@ class MyshixunsController < ApplicationController end end uid_logger("#############status: #{status}") - record = EvaluateRecord.where(:game_id => game_id).first + record = EvaluateRecord.where(:sec_key => sec_key).first logger.info("training_task_status start#3**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") answer_deduction_percentage = (100 - game.answer_deduction) / 100.to_f # 查看答案后剩余分数的百分比. # answer_deduction是查看答案的扣分比例 @@ -201,7 +201,7 @@ class MyshixunsController < ApplicationController if record.present? consume_time = format("%.3f", (Time.now - record.created_at)).to_f record.update_attributes!(:consume_time => consume_time, :git_pull => timeCost['pull'] , :create_pod => timeCost['createPod'], - :pod_execute => timeCost['execute'], :test_cases => test_cases_time, + :pod_execute => timeCost['execute'], :test_cases => test_cases_time, :max_mem => max_mem, :brige => timeCost['evaluateAllTime'], :return_back => return_back_time) end uid_logger("training_task_status start#4**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") From 01dac41ff80ece78678d6b65d0f8adbdaa733711 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 18 Jul 2019 14:54:51 +0800 Subject: [PATCH 0901/1015] .. --- app/controllers/games_controller.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 9eed3cc69..b51dab344 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -741,14 +741,14 @@ class GamesController < ApplicationController end else # 重新评测 # 如果满足前面的条件,进入此处只可能是结果已返回并存入了数据库 - if params[:resubmit] == resubmit_identifier # 本次重新评测结果已经返回并存入数据库 + if params[:resubmit] == resubmit_identifier # 本次重新评测结果已经返回并存入数据库 game_status = (@game.retry_status == 2 ? 2 : 0) # retry_status是判断重新评测的通关情况。2表示通关 end end # 实训的最大评测次数,这个值是为了优化查询,每次只取最新的最新一次评测的结果集 max_query_index = @game.query_index - #max_query_index = @game.outputs.first.try(:query_index) + # max_query_index = @game.outputs.first.try(:query_index) # 区分评测过未评测过,未评测过按需求取数据 testset_detail max_query_index.to_i, game_challenge @@ -758,9 +758,10 @@ class GamesController < ApplicationController web_route = game_challenge.try(:web_route) mirror_name = @shixun.mirror_name + e_record = EvaluateRecord.where(:sec_key => sec_key).first # 轮询结束,更新评测统计耗时 if game_status == 0 || game_status == 2 - e_record = EvaluateRecord.where(:sec_key => sec_key).first + if e_record front_js = format("%.3f", (Time.now.to_f - e_record.try(:updated_at).to_f)).to_f consume_time = format("%.3f", (Time.now - e_record.created_at)).to_f @@ -770,7 +771,8 @@ class GamesController < ApplicationController uid_logger("game is #{@game.id}, record id is #{e_record.try(:id)}, time is**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") # 记录前端总耗时 - record_consume_time = EvaluateRecord.where(:game_id => @game.id).first.try(:consume_time) + record_consume_time = e_record.try(:pod_execute) + max_mem = e_record.try(:max_mem) # 实训制作者当前拥有的金币 grade = User.where(:id => @game.user_id).pluck(:grade).first @@ -781,7 +783,7 @@ class GamesController < ApplicationController @base_date = {grade: grade, gold: score, experience: experience, status: game_status, had_done: had_done, position: game_challenge.position, port: port, record_consume_time: record_consume_time, mirror_name: mirror_name, picture: picture, web_route: web_route, star: @game.star, - next_game: next_game, prev_game: prev_game} + next_game: next_game, prev_game: prev_game, max_mem: max_mem} end # 记录实训花费的时间 From c3d545bc57f5a7262521f14275aafbd7e38769aa Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 18 Jul 2019 15:04:19 +0800 Subject: [PATCH 0902/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7pdf=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E7=9A=84=E6=A0=B7=E5=BC=8F=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exercise_export/blank_exercise.html.erb | 12 ++++++------ app/templates/exercise_export/exercise_user.html.erb | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/templates/exercise_export/blank_exercise.html.erb b/app/templates/exercise_export/blank_exercise.html.erb index 5e763d1cc..4a2373f3f 100644 --- a/app/templates/exercise_export/blank_exercise.html.erb +++ b/app/templates/exercise_export/blank_exercise.html.erb @@ -81,25 +81,25 @@
<% if q.question_type == 0 %> - <% q.exercise_choices.each do |s| %> + <% q.exercise_choices.each_with_index do |s,index| %>
- <%= to_markdown(s.choice_text,@request_url) %> + <%= to_markdown("#{(index+65).chr}.#{s.choice_text}",@request_url) %>
<% end %> <% elsif q.question_type == 1 %> - <% q.exercise_choices.each do |s| %> + <% q.exercise_choices.each_with_index do |s,index| %>
- <%= to_markdown(s.choice_text,@request_url) %> + <%= to_markdown("#{(index+65).chr}.#{s.choice_text}",@request_url) %>
<% end %> <% elsif q.question_type == 2 %>
- <% q.exercise_choices.each do |s| %> + <% q.exercise_choices.each_with_index do |s,index| %> - <%= s.choice_text %> + <%= "#{(index+65).chr}.#{s.choice_text}" %> <% end %>
diff --git a/app/templates/exercise_export/exercise_user.html.erb b/app/templates/exercise_export/exercise_user.html.erb index 1c91baec2..8d4da5ca2 100644 --- a/app/templates/exercise_export/exercise_user.html.erb +++ b/app/templates/exercise_export/exercise_user.html.erb @@ -182,16 +182,16 @@
<% if q_type == 0 %> - <% q.exercise_choices.each do |s| %> + <% q.exercise_choices.each_with_index do |s,index| %> <% check_answer = (user_answer.present? && (s.id == user_answer.first.exercise_choice_id)) ? "choose-answer" : '' %>
- <%= to_markdown(s.choice_text,@request_url) %> + <%= to_markdown("#{(index+65).chr}.#{s.choice_text}",@request_url) %>
<% end %>
<% elsif q_type == 1 %> - <% q.exercise_choices.each do |s| %> + <% q.exercise_choices.each_with_index do |s,index| %> <% check_answer = (user_answer.present? && (user_answer.pluck(:exercise_choice_id).include?(s.id))) ? true : false %>
<% if check_answer %> @@ -199,13 +199,13 @@ <% else %> <% end %> - <%= to_markdown(s.choice_text,@request_url) %> + <%= to_markdown("#{(index+65).chr}.#{s.choice_text}",@request_url) %>
<% end %>
<% elsif q_type == 2 %>
- <% q.exercise_choices.each do |s| %> + <% q.exercise_choices.each_with_index do |s,index| %> <% if user_answer.present? && (s.id == user_answer.first.exercise_choice_id) %> <% check_answer = 'choose-answer' %> <% else %> @@ -213,7 +213,7 @@ <% end %> - <%= s.choice_text %> + <%= "#{(index+65).chr}.#{s.choice_text}" %> <% end %>
From 8d522fe57e85ebde0af70b49464bb6936dd823ac Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 18 Jul 2019 15:14:04 +0800 Subject: [PATCH 0903/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E7=9A=84=E5=AD=90=E5=9B=9E=E5=A4=8D=E4=B8=8D=E5=86=8D=E9=9A=90?= =?UTF-8?q?=E8=97=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/discuss.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/models/discuss.rb b/app/models/discuss.rb index 00e3209c0..2d9c00110 100644 --- a/app/models/discuss.rb +++ b/app/models/discuss.rb @@ -41,9 +41,7 @@ class Discuss < ApplicationRecord # end def child_discuss(user) - user.admin? ? - Discuss.where(parent_id: self.id).includes(:user).reorder(created_at: :asc) : - Discuss.where(parent_id: self.id, :hidden => false).includes(:user).reorder(created_at: :asc) + Discuss.where(parent_id: self.id).includes(:user).reorder(created_at: :asc) end private From e3f125a63cda4406228b5dc6f81af3cf10c4b015 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 18 Jul 2019 15:15:29 +0800 Subject: [PATCH 0904/1015] =?UTF-8?q?500=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 4 ++-- app/controllers/myshixuns_controller.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index b51dab344..3a49f4d80 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -47,7 +47,7 @@ class GamesController < ApplicationController max_query_index = @game.query_index.to_i # 统计评测时间 - record_onsume_time = EvaluateRecord.where(game_id: @game.id).first.try(:consume_time) + record_onsume_time = EvaluateRecord.where(game_id: @game.id).first.try(:pod_execute) # myshixun_manager判断用户是否有权限查看隐藏测试集(TPM管理员;平台认证的老师;花费金币查看者) myshixun_manager = @identity < User::EDU_GAME_MANAGER @@ -758,7 +758,7 @@ class GamesController < ApplicationController web_route = game_challenge.try(:web_route) mirror_name = @shixun.mirror_name - e_record = EvaluateRecord.where(:sec_key => sec_key).first + e_record = EvaluateRecord.where(:identifier => sec_key).first # 轮询结束,更新评测统计耗时 if game_status == 0 || game_status == 2 diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index fc59f6b7c..0a86f88da 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -140,7 +140,7 @@ class MyshixunsController < ApplicationController end end uid_logger("#############status: #{status}") - record = EvaluateRecord.where(:sec_key => sec_key).first + record = EvaluateRecord.where(:identifier => sec_key).first logger.info("training_task_status start#3**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") answer_deduction_percentage = (100 - game.answer_deduction) / 100.to_f # 查看答案后剩余分数的百分比. # answer_deduction是查看答案的扣分比例 From 8c841b95b66ff522ec77a760b63bb423a336e50b Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 18 Jul 2019 15:23:37 +0800 Subject: [PATCH 0905/1015] modify competition apig --- app/controllers/competitions/competition_teams_controller.rb | 4 ++-- app/models/searchable/dependents/challenge_tag.rb | 2 +- app/models/searchable/dependents/stage.rb | 2 +- app/models/searchable/dependents/user.rb | 4 ++-- app/views/competitions/competition_staffs/show.json.jbuilder | 1 + app/views/competitions/competition_teams/index.json.jbuilder | 3 +++ 6 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/controllers/competitions/competition_teams_controller.rb b/app/controllers/competitions/competition_teams_controller.rb index b4861c4d3..e03810b61 100644 --- a/app/controllers/competitions/competition_teams_controller.rb +++ b/app/controllers/competitions/competition_teams_controller.rb @@ -54,13 +54,13 @@ class Competitions::CompetitionTeamsController < Competitions::BaseController end @count = teams.count - @teams = paginate(teams.includes(:user, users: :user_extension)) + @teams = paginate(teams.includes(:user, users: { user_extension: :school })) end def user_competition_teams teams = current_competition.competition_teams teams = teams.joins(:team_members).where(team_members: { user_id: current_user.id }) - @teams = teams.includes(:user, users: :user_extension).to_a + @teams = teams.includes(:user, users: { user_extension: :school }).to_a @count = @teams.size end diff --git a/app/models/searchable/dependents/challenge_tag.rb b/app/models/searchable/dependents/challenge_tag.rb index fdec79d1b..51ef804dd 100644 --- a/app/models/searchable/dependents/challenge_tag.rb +++ b/app/models/searchable/dependents/challenge_tag.rb @@ -10,7 +10,7 @@ module Searchable::Dependents::ChallengeTag def check_searchable_dependents if new_record? || name_previously_changed? - challenge.shixun.reindex(:searchable_challenge_data) + challenge.shixun.reindex end end end \ No newline at end of file diff --git a/app/models/searchable/dependents/stage.rb b/app/models/searchable/dependents/stage.rb index 262ddd36f..d4207fec8 100644 --- a/app/models/searchable/dependents/stage.rb +++ b/app/models/searchable/dependents/stage.rb @@ -9,7 +9,7 @@ module Searchable::Dependents::Stage def check_searchable_dependents if name_previously_changed? || description_previously_changed? - subject.reindex(:searchable_stages_data) + subject.reindex end end end \ No newline at end of file diff --git a/app/models/searchable/dependents/user.rb b/app/models/searchable/dependents/user.rb index 761704d06..103131ed6 100644 --- a/app/models/searchable/dependents/user.rb +++ b/app/models/searchable/dependents/user.rb @@ -10,13 +10,13 @@ module Searchable::Dependents::User def check_searchable_dependents if firstname_previously_changed? || lastname_previously_changed? || user_extension.school_id_previously_changed? # reindex shixun - created_shixuns.each{ |shixun| shixun.reindex(:searchable_user_data) } + created_shixuns.each{ |shixun| shixun.reindex } # reindex course manage_courses.each(&:reindex) # reindex subject - created_subjects.each { |subject| subject.reindex(:searchable_user_data) } + created_subjects.each { |subject| subject.reindex } end end end \ No newline at end of file diff --git a/app/views/competitions/competition_staffs/show.json.jbuilder b/app/views/competitions/competition_staffs/show.json.jbuilder index 2cba22d2f..c490aaf5f 100644 --- a/app/views/competitions/competition_staffs/show.json.jbuilder +++ b/app/views/competitions/competition_staffs/show.json.jbuilder @@ -1,5 +1,6 @@ competition = current_competition +json.personal competition.personal? json.enroll_ended competition.enroll_ended? json.enrolled competition.enrolled?(current_user) diff --git a/app/views/competitions/competition_teams/index.json.jbuilder b/app/views/competitions/competition_teams/index.json.jbuilder index 86bb86a1c..b641b28e6 100644 --- a/app/views/competitions/competition_teams/index.json.jbuilder +++ b/app/views/competitions/competition_teams/index.json.jbuilder @@ -17,6 +17,9 @@ json.competition_teams do json.partial! 'users/user_simple', user: member.user json.user_id member.user_id json.role member.en_role + json.identity member.user.identity + json.school_name member.user.school_name + json.student_id member.user.student_id end end end From f6a5a0ebbca775e8f6d72ac8d4f65c7b9aea6b21 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 18 Jul 2019 15:27:07 +0800 Subject: [PATCH 0906/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=EF=BC=8C=E9=97=AE?= =?UTF-8?q?=E5=8D=B7=E7=9A=84=E7=8A=B6=E6=80=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/exercise.rb | 12 ++++++++---- app/models/poll.rb | 28 +++++++++++++++++----------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index aba0a00bc..8286a96e2 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -127,8 +127,10 @@ class Exercise < ApplicationRecord #判断是否为分班,如果分班,试卷的截止时间为当前分班时间,否则为试卷的截止时间 def get_exercise_status(user) - return Exercise::UNPUBLISHED if user.nil? - if user.student_of_course?(course) #当为学生的时候,需根据分班来判断试卷状态 + if course.end_time.present? && course.end_time <= Time.now + status = 4 + else + if user.present? && user.student_of_course?(course) #当为学生的时候,需根据分班来判断试卷状态 ex_time = get_exercise_times(user_id,false) pb_time = ex_time[:publish_time] ed_time = ex_time[:end_time] @@ -139,9 +141,11 @@ class Exercise < ApplicationRecord else status = Exercise::UNPUBLISHED end - else - status = exercise_status #当为老师的时候,则为试卷的总状态 + else + status = exercise_status #当为老师的时候,则为试卷的总状态 + end end + status end diff --git a/app/models/poll.rb b/app/models/poll.rb index e6a363f1d..5fda30609 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -100,19 +100,25 @@ class Poll < ApplicationRecord end def get_poll_status(user) - if user.student_of_course?(course) - ex_time = get_poll_times(user_id,false) - pb_time = ex_time[:publish_time] - ed_time = ex_time[:end_time] - if pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now - status = 2 - elsif ed_time.present? && ed_time <= Time.now - status = 3 + if course.end_time.present? && course.end_time <= Time.now + status = 4 + else + if user.present? && user.student_of_course?(course) + ex_time = get_poll_times(user_id,false) + pb_time = ex_time[:publish_time] + ed_time = ex_time[:end_time] + if course.end_time.present? && course.end_time <= Time.now + status = 4 + elsif pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now + status = 2 + elsif ed_time.present? && ed_time <= Time.now + status = 3 + else + status = 1 + end else - status = 1 + status = polls_status end - else - status = polls_status end status end From e8e02abbbb28aff0583078ddc7f47b83fe0e1dcb Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 18 Jul 2019 15:29:59 +0800 Subject: [PATCH 0907/1015] fixbug --- app/models/exercise.rb | 2 +- app/models/poll.rb | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 8286a96e2..61c5c8eab 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -127,7 +127,7 @@ class Exercise < ApplicationRecord #判断是否为分班,如果分班,试卷的截止时间为当前分班时间,否则为试卷的截止时间 def get_exercise_status(user) - if course.end_time.present? && course.end_time <= Time.now + if course.end_date.present? && course.end_date <= Time.now status = 4 else if user.present? && user.student_of_course?(course) #当为学生的时候,需根据分班来判断试卷状态 diff --git a/app/models/poll.rb b/app/models/poll.rb index 5fda30609..a9b4c2984 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -99,17 +99,15 @@ class Poll < ApplicationRecord end end - def get_poll_status(user) - if course.end_time.present? && course.end_time <= Time.now + def get_poll_status(user)s + if course.end_date.present? && course.end_date <= Time.now status = 4 else if user.present? && user.student_of_course?(course) ex_time = get_poll_times(user_id,false) pb_time = ex_time[:publish_time] ed_time = ex_time[:end_time] - if course.end_time.present? && course.end_time <= Time.now - status = 4 - elsif pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now + if pb_time.present? && ed_time.present? && pb_time <= Time.now && ed_time > Time.now status = 2 elsif ed_time.present? && ed_time <= Time.now status = 3 From a94728a6c434662767c15b474b3cd3363fc4f48e Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 18 Jul 2019 15:31:19 +0800 Subject: [PATCH 0908/1015] fixbug --- app/models/poll.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/poll.rb b/app/models/poll.rb index a9b4c2984..52b814bb3 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -99,7 +99,7 @@ class Poll < ApplicationRecord end end - def get_poll_status(user)s + def get_poll_status(user) if course.end_date.present? && course.end_date <= Time.now status = 4 else From 4303995003e44804998bb1fe1d05a6b8c1d8a225 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 18 Jul 2019 15:33:47 +0800 Subject: [PATCH 0909/1015] fixbug --- app/models/exercise.rb | 3 +-- app/models/poll.rb | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 61c5c8eab..825f7cd9f 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -127,7 +127,7 @@ class Exercise < ApplicationRecord #判断是否为分班,如果分班,试卷的截止时间为当前分班时间,否则为试卷的截止时间 def get_exercise_status(user) - if course.end_date.present? && course.end_date <= Time.now + if course.is_end status = 4 else if user.present? && user.student_of_course?(course) #当为学生的时候,需根据分班来判断试卷状态 @@ -145,7 +145,6 @@ class Exercise < ApplicationRecord status = exercise_status #当为老师的时候,则为试卷的总状态 end end - status end diff --git a/app/models/poll.rb b/app/models/poll.rb index 52b814bb3..7f0d2fd94 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -100,7 +100,7 @@ class Poll < ApplicationRecord end def get_poll_status(user) - if course.end_date.present? && course.end_date <= Time.now + if course.is_end status = 4 else if user.present? && user.student_of_course?(course) From de0aa8bcddf77952cc6e5b4d9c02569582e378fc Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 18 Jul 2019 15:38:00 +0800 Subject: [PATCH 0910/1015] fixbug --- app/controllers/polls_controller.rb | 6 +++--- app/views/polls/common_header.json.jbuilder | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 3fc17c661..9811cfa5a 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -205,15 +205,15 @@ class PollsController < ApplicationController @is_teacher_or = 1 @user_poll_answer = 3 #教师页面 end - poll_status = @poll.get_poll_status(current_user) + @poll_status = @poll.get_poll_status(current_user) poll_id_array = [@poll.id] @poll_publish_count = get_user_permission_course(poll_id_array,2).count #是否存在已发布的 @poll_unpublish_count = get_user_permission_course(poll_id_array,1).count #是否存在未发布的 if (@poll_publish_count == 0) && (@poll_unpublish_count == 0) #即表示没有分班 - if poll_status == 1 + if @poll_status == 1 @poll_unpublish_count = 1 #试卷未发布,且课堂没有分班的时候 - elsif poll_status == 2 + elsif @poll_status == 2 @poll_publish_count = 1 #试卷未发布,且课堂没有分班的时候 end end diff --git a/app/views/polls/common_header.json.jbuilder b/app/views/polls/common_header.json.jbuilder index 39c4ef811..b0a3d7374 100644 --- a/app/views/polls/common_header.json.jbuilder +++ b/app/views/polls/common_header.json.jbuilder @@ -1,5 +1,6 @@ json.course_is_end @course.is_end # true表示已结束,false表示未结束 -json.extract! @poll, :id,:polls_name,:polls_description,:polls_status,:show_result +json.extract! @poll, :id,:polls_name,:polls_description,:show_result +json.polls_status @poll_status json.user_permission do json.is_teacher_or @is_teacher_or From eb2290ffbcd54db402e6fb1a8b0fbb942dac638c Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 18 Jul 2019 15:41:48 +0800 Subject: [PATCH 0911/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E8=AF=84=E6=B5=8B?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=B7=BB=E5=8A=A0=E5=86=85=E5=AD=98=E5=92=8C?= =?UTF-8?q?=E8=AF=84=E6=B5=8B=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/games/_testset_list.json.jbuilder | 1 + app/views/games/game_status.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/games/_testset_list.json.jbuilder b/app/views/games/_testset_list.json.jbuilder index 2111e3467..31c780570 100644 --- a/app/views/games/_testset_list.json.jbuilder +++ b/app/views/games/_testset_list.json.jbuilder @@ -7,6 +7,7 @@ json.test_sets @qurey_test_sets do |test_set| json.actual_output evaluate_actual_output(test_set) end json.compile_success test_set.try(:compile_success) + json.max_mem test_set.ts_time end json.allowed_unlock @shixun.test_set_permission diff --git a/app/views/games/game_status.json.jbuilder b/app/views/games/game_status.json.jbuilder index 73de75598..aecbf9d42 100644 --- a/app/views/games/game_status.json.jbuilder +++ b/app/views/games/game_status.json.jbuilder @@ -1,4 +1,4 @@ json.(@base_date, :grade, :gold, :experience, :status, :had_done, :position, :port, :record_consume_time, :mirror_name, - :picture, :web_route, :star, :next_game, :prev_game) + :picture, :web_route, :star, :next_game, :prev_game, :max_mem) # # 测试集相关 json.partial! 'games/testset_list' \ No newline at end of file From 66bef13e5c3317fd0cb0ae71830e4394d5ad2978 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 18 Jul 2019 15:45:26 +0800 Subject: [PATCH 0912/1015] fixbug --- app/controllers/exercises_controller.rb | 4 ++++ app/controllers/polls_controller.rb | 3 +++ 2 files changed, 7 insertions(+) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index f26e97849..03c943f8d 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -667,6 +667,7 @@ class ExercisesController < ApplicationController #立即发布的弹窗内容 def publish_modal + ActiveRecord::Base.transaction do begin exercise_ids = params[:check_ids] @@ -685,6 +686,9 @@ class ExercisesController < ApplicationController #首页批量或单独 立即发布,应是跳出弹窗,设置开始时间和截止时间。 def publish + tip_exception("缺少截止时间参数") if params[:end_time].blank? + tip_exception("截止时间不能早于当前时间") if params[:end_time] <= strf_time(Time.now) + tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day) ActiveRecord::Base.transaction do begin check_ids = Exercise.where(id: params[:check_ids]) diff --git a/app/controllers/polls_controller.rb b/app/controllers/polls_controller.rb index 9811cfa5a..f5003a0c7 100644 --- a/app/controllers/polls_controller.rb +++ b/app/controllers/polls_controller.rb @@ -244,6 +244,9 @@ class PollsController < ApplicationController end #首页批量或单独 立即发布,应是跳出弹窗,设置开始时间和截止时间。 def publish + tip_exception("缺少截止时间参数") if params[:end_time].blank? + tip_exception("截止时间不能早于当前时间") if params[:end_time] <= strf_time(Time.now) + tip_exception("截止时间不能晚于课堂结束时间") if @course.end_date.present? && params[:end_time] > strf_time(@course.end_date.end_of_day) ActiveRecord::Base.transaction do begin check_ids = Poll.where(id: params[:check_ids]) From 44561b8a5196e6c93c1c0cbc3c442291fdd413cb Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 18 Jul 2019 16:01:42 +0800 Subject: [PATCH 0913/1015] =?UTF-8?q?=E8=AF=95=E7=94=A8=E7=9A=84=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=8F=AF=E4=BB=A5=E4=B8=8D=E7=94=A8=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E8=B5=84=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 875050642..6a7599f28 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -184,14 +184,13 @@ class ApplicationController < ActionController::Base end # 系统全局认证 - # def check_auth - if !current_user.profile_completed? - info_url = '/account/profile' - tip_exception(402, info_url) - elsif current_user.certification != 1 + if current_user.certification != 1 day_cer = UserDayCertification.find_by(user_id: current_user.id) tip_exception(407, "系统未授权") unless (Time.now.to_i - day_cer.try(:created_at).to_i) < 86400 + elsif !current_user.profile_completed? + info_url = '/account/profile' + tip_exception(402, info_url) end end From 02b0851e38de2b652ef2c850f117b27e229ad4aa Mon Sep 17 00:00:00 2001 From: p31729568 Date: Thu, 18 Jul 2019 16:05:24 +0800 Subject: [PATCH 0914/1015] competition module update api modify --- .../competitions/competition_modules_controller.rb | 12 +++++++++++- app/models/searchable/dependents/user.rb | 4 ++-- .../competition_modules/show.json.jbuilder | 3 +++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/controllers/competitions/competition_modules_controller.rb b/app/controllers/competitions/competition_modules_controller.rb index da9873c43..c4692af70 100644 --- a/app/controllers/competitions/competition_modules_controller.rb +++ b/app/controllers/competitions/competition_modules_controller.rb @@ -15,7 +15,17 @@ class Competitions::CompetitionModulesController < Competitions::BaseController md = current_module.competition_module_md_content || current_module.build_competition_module_md_content md.name = params[:md_name] md.content = params[:md_content] - md.save! + + ActiveRecord::Base.transaction do + md.save! + + attachment_ids = Array.wrap(params[:attachment_ids]).map(&:to_i) + old_attachment_ids = md.attachments.pluck(:id) + + destroy_ids = old_attachment_ids - attachment_ids + md.attachments.where(id: destroy_ids).delete_all + Attachment.where(id: attachment_ids - old_attachment_ids).update_all(container: md) + end render_ok end diff --git a/app/models/searchable/dependents/user.rb b/app/models/searchable/dependents/user.rb index 103131ed6..f6dcaa430 100644 --- a/app/models/searchable/dependents/user.rb +++ b/app/models/searchable/dependents/user.rb @@ -10,13 +10,13 @@ module Searchable::Dependents::User def check_searchable_dependents if firstname_previously_changed? || lastname_previously_changed? || user_extension.school_id_previously_changed? # reindex shixun - created_shixuns.each{ |shixun| shixun.reindex } + created_shixuns.each(&:reindex) # reindex course manage_courses.each(&:reindex) # reindex subject - created_subjects.each { |subject| subject.reindex } + created_subjects.each(&:reindex) end end end \ No newline at end of file diff --git a/app/views/competitions/competition_modules/show.json.jbuilder b/app/views/competitions/competition_modules/show.json.jbuilder index d47742cf0..69cdcc544 100644 --- a/app/views/competitions/competition_modules/show.json.jbuilder +++ b/app/views/competitions/competition_modules/show.json.jbuilder @@ -5,4 +5,7 @@ if md.present? json.md_name md.name json.md_content md.content json.created_at md.created_at.strftime('%Y-%m-%d %H:%M:%S') + json.attachments do + json.array! md.attachments, partial: 'attachments/attachment_simple', as: :attachment + end end \ No newline at end of file From 24e0eeb0ab3db61ddd46385c840c857bc3fe0183 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 18 Jul 2019 16:07:42 +0800 Subject: [PATCH 0915/1015] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 1 + config/elasticsearch.yml.example | 13 ------------- 2 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 config/elasticsearch.yml.example diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 0a86f88da..0cf220dcf 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -130,6 +130,7 @@ class MyshixunsController < ApplicationController # is_public = test_sets.where(:position => j_test_set['caseId']).first.try(:is_public) logger.info "actual_output:################################################# #{actual_output}" + ts_time = format("%.3f", j_test_set['testSetTime'].to_i).to_f Output.create!(:code => status, :game_id => game_id, :out_put => outPut, :test_set_position => j_test_set['caseId'], :actual_output => actual_output, :result => j_test_set['passed'].to_i, :query_index => max_query_index, :compile_success => compile_success.to_i, :sec_key => sec_key, :ts_time => j_test_set['testSetTime']) diff --git a/config/elasticsearch.yml.example b/config/elasticsearch.yml.example deleted file mode 100644 index cbecb85d7..000000000 --- a/config/elasticsearch.yml.example +++ /dev/null @@ -1,13 +0,0 @@ -defaults: &defaults - url: http://localhost:9200 - -development: - <<: *defaults - -test: - <<: *defaults - -production: - <<: *defaults - url: 'http://elastic:Elas+ucloud123@106.75.27.125:59200/' - # url: 'http://elastic:TEST_elastickibana321@es-cn-0pp174wsj000iubdx.public.elasticsearch.aliyuncs.com' From 66be66ef1ef2075c5604bd8895f6a362cfdd777f Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 18 Jul 2019 16:12:39 +0800 Subject: [PATCH 0916/1015] =?UTF-8?q?=E6=AF=8F=E4=B8=AA=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E9=9B=86=E7=9A=84=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/games/_testset_list.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/games/_testset_list.json.jbuilder b/app/views/games/_testset_list.json.jbuilder index 31c780570..579adc3e6 100644 --- a/app/views/games/_testset_list.json.jbuilder +++ b/app/views/games/_testset_list.json.jbuilder @@ -7,7 +7,7 @@ json.test_sets @qurey_test_sets do |test_set| json.actual_output evaluate_actual_output(test_set) end json.compile_success test_set.try(:compile_success) - json.max_mem test_set.ts_time + json.ts_time test_set.ts_time end json.allowed_unlock @shixun.test_set_permission From 332359368d267f838e74c69fe8c964db250bbec5 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 18 Jul 2019 16:15:55 +0800 Subject: [PATCH 0917/1015] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9F=A5=E9=87=8D?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/homework_commons/group_list.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/homework_commons/group_list.json.jbuilder b/app/views/homework_commons/group_list.json.jbuilder index 5e6c63556..0108e5534 100644 --- a/app/views/homework_commons/group_list.json.jbuilder +++ b/app/views/homework_commons/group_list.json.jbuilder @@ -7,7 +7,7 @@ json.group_list do end end # 未分班展示情况放在最后 -if @course_groups.count < @limit.to_i +if @course_groups.count > 0 && @course_groups.count < @limit.to_i ungroup_work_count = homework_ungroup_works_count(@homework, @ungroup_user_ids) if ungroup_work_count > 0 json.ungroup_list do From e5d3c86063d19bfc7361b71b5f927aeac26450ba Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 18 Jul 2019 16:35:48 +0800 Subject: [PATCH 0918/1015] =?UTF-8?q?=E7=BB=8F=E9=AA=8C=E5=80=BC=E6=8A=A5?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/game.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/game.rb b/app/models/game.rb index f1f2a09b4..ae056a702 100644 --- a/app/models/game.rb +++ b/app/models/game.rb @@ -61,7 +61,7 @@ class Game < ApplicationRecord if self.status == 2 # 通关了则取实际得分,没通关则取总分 gold = (shixun_status <= 1) ? 0 : self.final_score.to_i # 只要过关了,查看了答案经验值就是0;通关前查看了答案金final_score为负数 - experience = (shixun_status <= 1 || self.final_score.to_i < 0) ? 0 : challenge.final_score.to_i + experience = (shixun_status <= 1 || self.final_score.to_i < 0) ? 0 : self.final_score.to_i else gold = challenge.score.to_i experience = gold From c4d49d8097e7ce1a53e258b25ddab9f838e12f47 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 18 Jul 2019 16:35:57 +0800 Subject: [PATCH 0919/1015] =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 0cf220dcf..8eae3547a 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -105,7 +105,9 @@ class MyshixunsController < ApplicationController resubmit = jsonTestDetails['resubmit'] outPut = tran_base64_decode64(jsonTestDetails['outPut']) # 资源消耗 + uid_logger("##########!!!!!!#{jsonTestDetails['resUsage']}") max_mem = tran_base64_decode64(jsonTestDetails['resUsage']) if jsonTestDetails['resUsage'].present? + uid_logger("##########!!!!!!#{max_mem}") jenkins_testsets = jsonTestDetails['msg'] compile_success = jsonTestDetails['compileSuccess'] # message = Base64.decode64(params[:msg]) unless params[:msg].blank? From 3c5f0385a32bf5797e41a418d225cf2f842c3827 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 18 Jul 2019 16:51:20 +0800 Subject: [PATCH 0920/1015] 500 and log --- app/controllers/myshixuns_controller.rb | 1 + app/views/games/_testset_list.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 8eae3547a..cb31f2464 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -203,6 +203,7 @@ class MyshixunsController < ApplicationController test_cases_time = format("%.3f", (Time.now.to_f - t1.to_f)).to_f if record.present? consume_time = format("%.3f", (Time.now - record.created_at)).to_f + uid_logger("11122233334444#{max_mem}, #{sec_key}") record.update_attributes!(:consume_time => consume_time, :git_pull => timeCost['pull'] , :create_pod => timeCost['createPod'], :pod_execute => timeCost['execute'], :test_cases => test_cases_time, :max_mem => max_mem, :brige => timeCost['evaluateAllTime'], :return_back => return_back_time) diff --git a/app/views/games/_testset_list.json.jbuilder b/app/views/games/_testset_list.json.jbuilder index 579adc3e6..e5cc76625 100644 --- a/app/views/games/_testset_list.json.jbuilder +++ b/app/views/games/_testset_list.json.jbuilder @@ -7,7 +7,7 @@ json.test_sets @qurey_test_sets do |test_set| json.actual_output evaluate_actual_output(test_set) end json.compile_success test_set.try(:compile_success) - json.ts_time test_set.ts_time + json.ts_time test_set.try(:ts_time) end json.allowed_unlock @shixun.test_set_permission From 718f94ac32db0576bbb9b0f81a1cde8cb9692e49 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Thu, 18 Jul 2019 16:53:17 +0800 Subject: [PATCH 0921/1015] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BA=B5=E5=8C=85?= =?UTF-8?q?=E5=92=8C=E6=95=99=E5=AD=A6=E6=A1=88=E4=BE=8B=E5=AF=BC=E8=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/get_navigation_info.json.jbuilder | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/views/users/get_navigation_info.json.jbuilder b/app/views/users/get_navigation_info.json.jbuilder index 586ddbd7c..96f54d3d0 100644 --- a/app/views/users/get_navigation_info.json.jbuilder +++ b/app/views/users/get_navigation_info.json.jbuilder @@ -13,6 +13,9 @@ json.top do json.message_url "#{@old_domain}#{@user_url}/user_tidings" json.new_message @new_message + json.moop_cases_url "#{@old_domain}/moop_cases" + json.crowdsourcing_url "#{@old_domain}/crowdsourcing" + json.career_url do json.array! @career.to_a do |c| if c[1].present? From 4482276cbd2f067364a16d75423b91b260c1155d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 18 Jul 2019 17:08:42 +0800 Subject: [PATCH 0922/1015] =?UTF-8?q?=E8=AF=95=E5=8D=B7=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=9A=84=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/exercises_helper.rb | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 5ec9bcad4..6f30ba6c3 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -103,9 +103,9 @@ module ExercisesHelper end effictive_users_count = effictive_users.size #有效回答数,可能有重复的用户id,这里仅统计是否回答这个问题的全部人数 - ex_answered_scores = effictive_users.score_reviewed.pluck(:score).sum #该问题的全部得分 if ex.question_type > Exercise::COMPLETION #当为主观题和实训题时, + ex_answered_scores = effictive_users.score_reviewed.pluck(:score).sum #该问题的全部得分 percent = (ex_total_score == 0.0 ? 0.0 : (ex_answered_scores / ex_total_score.to_f).round(3) * 100) #正确率 end @@ -116,15 +116,21 @@ module ExercisesHelper right_users_count = 0 #该问题的正确率 if ex.question_type == Exercise::MULTIPLE #多选题 - user_ids.each do |user_id| - ex_choice_ids = effictive_users.map{|e| e.exercise_choice_id if e.user_id == user_id}.reject(&:blank?).uniq - answer_choice_array = ex_choices.map{|a| a.choice_position if ex_choice_ids.include?(a.id)}.reject(&:blank?).uniq - if answer_choice_array.sort == standard_answer - right_users_count += 1 - end + right_user_ids = user_ids + standard_answer.each do |choice_position| + standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == choice_position}.first.id + right_user_ids = right_user_ids & effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.pluck(:user_id) end + right_users_count = right_user_ids.size + # user_ids.each do |user_id| + # ex_choice_ids = effictive_users.map{|e| e.exercise_choice_id if e.user_id == user_id}.reject(&:blank?).uniq + # answer_choice_array = ex_choices.map{|a| a.choice_position if ex_choice_ids.include?(a.id)}.reject(&:blank?).uniq + # if answer_choice_array.sort == standard_answer + # right_users_count += 1 + # end + # end else #单选题和判断题 - standard_answer_choice_id = ex.exercise_choices.find_by(choice_position: standard_answer.first)&.id + standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == standard_answer.first}.first.id right_users_count = effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.size end @@ -157,13 +163,7 @@ module ExercisesHelper user_count = 0 s_choice_text = null_stand_text[index] if ex_ordered #有序排列 - user_ids.each do |u| - user_answers = ex_answers.where(user_id:u,exercise_choice_id:s).select(:answer_text) - user_answers_choice = user_answers.exists? ? user_answers&.first&.answer_text.to_s : "" - if s_choice_text == user_answers_choice - user_count += 1 - end - end + user_count = user_count + effictive_users.select{|answer| answer.exercise_choice_id == s && answer.answer_text == s_choice_text}.size else user_count = user_count + effictive_users.select{|answer| answer.answer_text == s_choice_text }.size #回答了标准答案的用户 end From efd83e4f81db45815cb373e967b2434a8512fe44 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 18 Jul 2019 17:12:19 +0800 Subject: [PATCH 0923/1015] =?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/helpers/exercises_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 6f30ba6c3..ace9e062e 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -118,7 +118,7 @@ module ExercisesHelper if ex.question_type == Exercise::MULTIPLE #多选题 right_user_ids = user_ids standard_answer.each do |choice_position| - standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == choice_position}.first.id + standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == choice_position}.first&.id right_user_ids = right_user_ids & effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.pluck(:user_id) end right_users_count = right_user_ids.size @@ -130,7 +130,7 @@ module ExercisesHelper # end # end else #单选题和判断题 - standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == standard_answer.first}.first.id + standard_answer_choice_id = ex_choices.select{|ec| ec.choice_position == standard_answer.first}.first&.id right_users_count = effictive_users.select{|answer| answer.exercise_choice_id == standard_answer_choice_id}.size end From e25427ff02958e333f99ddf057135c85c82f4a69 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 18 Jul 2019 17:20:13 +0800 Subject: [PATCH 0924/1015] =?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/models/user.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index d089c49c3..3ed327c0c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -416,7 +416,7 @@ class User < ApplicationRecord def real_name return '游客' unless logged? name = lastname + firstname - name.blank? ? (nickname.blank? ? login : nickname) : name + name = name.blank? ? (nickname.blank? ? login : nickname) : name name.gsub(/\s+/, '').strip #6.11 -hs end From 409c51bd911b6593c7b8c148ea73353b2207de8e Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 18 Jul 2019 17:29:29 +0800 Subject: [PATCH 0925/1015] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index cb31f2464..821c0df52 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -105,9 +105,11 @@ class MyshixunsController < ApplicationController resubmit = jsonTestDetails['resubmit'] outPut = tran_base64_decode64(jsonTestDetails['outPut']) # 资源消耗 - uid_logger("##########!!!!!!#{jsonTestDetails['resUsage']}") - max_mem = tran_base64_decode64(jsonTestDetails['resUsage']) if jsonTestDetails['resUsage'].present? - uid_logger("##########!!!!!!#{max_mem}") + if jsonTestDetails['resUsage'].present? + max_mem = tran_base64_decode64(jsonTestDetails['resUsage']).to_f + max_mem = format("%.3f", max_mem/1024/1024).to_f + end + jenkins_testsets = jsonTestDetails['msg'] compile_success = jsonTestDetails['compileSuccess'] # message = Base64.decode64(params[:msg]) unless params[:msg].blank? @@ -132,10 +134,11 @@ class MyshixunsController < ApplicationController # is_public = test_sets.where(:position => j_test_set['caseId']).first.try(:is_public) logger.info "actual_output:################################################# #{actual_output}" - ts_time = format("%.3f", j_test_set['testSetTime'].to_i).to_f + ts_time = format("%.2f", j_test_set['testSetTime'].to_f/1000000000).to_f + Output.create!(:code => status, :game_id => game_id, :out_put => outPut, :test_set_position => j_test_set['caseId'], :actual_output => actual_output, :result => j_test_set['passed'].to_i, :query_index => max_query_index, - :compile_success => compile_success.to_i, :sec_key => sec_key, :ts_time => j_test_set['testSetTime']) + :compile_success => compile_success.to_i, :sec_key => sec_key, :ts_time => ts_time) # 如果设置了按测试集给分,则需要统计测试集的分值 if challenge.test_set_score && j_test_set['passed'].to_i == 1 test_set_score += challenge.test_sets.where(:position => j_test_set['caseId']).pluck(:score).first @@ -203,7 +206,7 @@ class MyshixunsController < ApplicationController test_cases_time = format("%.3f", (Time.now.to_f - t1.to_f)).to_f if record.present? consume_time = format("%.3f", (Time.now - record.created_at)).to_f - uid_logger("11122233334444#{max_mem}, #{sec_key}") + record.update_attributes!(:consume_time => consume_time, :git_pull => timeCost['pull'] , :create_pod => timeCost['createPod'], :pod_execute => timeCost['execute'], :test_cases => test_cases_time, :max_mem => max_mem, :brige => timeCost['evaluateAllTime'], :return_back => return_back_time) From d48c86cbf48954c32020f09bc4e79e5ea2395c28 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 18 Jul 2019 17:38:38 +0800 Subject: [PATCH 0926/1015] log --- app/controllers/myshixuns_controller.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 821c0df52..7ced33156 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -107,9 +107,13 @@ class MyshixunsController < ApplicationController # 资源消耗 if jsonTestDetails['resUsage'].present? max_mem = tran_base64_decode64(jsonTestDetails['resUsage']).to_f + uid_logger("6661111111111111122222#{max_mem}") max_mem = format("%.3f", max_mem/1024/1024).to_f + uid_logger("444411111122222#{max_mem}") end + uid_logger("1111111111111122222#{max_mem}") + jenkins_testsets = jsonTestDetails['msg'] compile_success = jsonTestDetails['compileSuccess'] # message = Base64.decode64(params[:msg]) unless params[:msg].blank? From ae4e65296cde45f85683787ddb4e3901975857c6 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Thu, 18 Jul 2019 18:04:05 +0800 Subject: [PATCH 0927/1015] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=9B=86=E5=86=85?= =?UTF-8?q?=E5=AD=98=E4=BD=BF=E7=94=A8=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/myshixuns_controller.rb | 14 +++----------- db/migrate/20190718100242_add_ts_mem_to_outputs.rb | 5 +++++ 2 files changed, 8 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20190718100242_add_ts_mem_to_outputs.rb diff --git a/app/controllers/myshixuns_controller.rb b/app/controllers/myshixuns_controller.rb index 7ced33156..0a19f1c08 100644 --- a/app/controllers/myshixuns_controller.rb +++ b/app/controllers/myshixuns_controller.rb @@ -104,15 +104,6 @@ class MyshixunsController < ApplicationController logger.info("training_task_status start#1**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") resubmit = jsonTestDetails['resubmit'] outPut = tran_base64_decode64(jsonTestDetails['outPut']) - # 资源消耗 - if jsonTestDetails['resUsage'].present? - max_mem = tran_base64_decode64(jsonTestDetails['resUsage']).to_f - uid_logger("6661111111111111122222#{max_mem}") - max_mem = format("%.3f", max_mem/1024/1024).to_f - uid_logger("444411111122222#{max_mem}") - end - - uid_logger("1111111111111122222#{max_mem}") jenkins_testsets = jsonTestDetails['msg'] compile_success = jsonTestDetails['compileSuccess'] @@ -139,10 +130,11 @@ class MyshixunsController < ApplicationController # is_public = test_sets.where(:position => j_test_set['caseId']).first.try(:is_public) logger.info "actual_output:################################################# #{actual_output}" ts_time = format("%.2f", j_test_set['testSetTime'].to_f/1000000000).to_f + ts_mem = format("%.2f", j_test_set['testSetMem'].to_f/1024/1024).to_f Output.create!(:code => status, :game_id => game_id, :out_put => outPut, :test_set_position => j_test_set['caseId'], :actual_output => actual_output, :result => j_test_set['passed'].to_i, :query_index => max_query_index, - :compile_success => compile_success.to_i, :sec_key => sec_key, :ts_time => ts_time) + :compile_success => compile_success.to_i, :sec_key => sec_key, :ts_time => ts_time, :ts_mem => ts_mem) # 如果设置了按测试集给分,则需要统计测试集的分值 if challenge.test_set_score && j_test_set['passed'].to_i == 1 test_set_score += challenge.test_sets.where(:position => j_test_set['caseId']).pluck(:score).first @@ -212,7 +204,7 @@ class MyshixunsController < ApplicationController consume_time = format("%.3f", (Time.now - record.created_at)).to_f record.update_attributes!(:consume_time => consume_time, :git_pull => timeCost['pull'] , :create_pod => timeCost['createPod'], - :pod_execute => timeCost['execute'], :test_cases => test_cases_time, :max_mem => max_mem, + :pod_execute => timeCost['execute'], :test_cases => test_cases_time, :brige => timeCost['evaluateAllTime'], :return_back => return_back_time) end uid_logger("training_task_status start#4**#{game_id}**** #{Time.now.strftime("%Y-%m-%d %H:%M:%S.%L")}") diff --git a/db/migrate/20190718100242_add_ts_mem_to_outputs.rb b/db/migrate/20190718100242_add_ts_mem_to_outputs.rb new file mode 100644 index 000000000..70b593a35 --- /dev/null +++ b/db/migrate/20190718100242_add_ts_mem_to_outputs.rb @@ -0,0 +1,5 @@ +class AddTsMemToOutputs < ActiveRecord::Migration[5.2] + def change + add_column :outputs, :ts_mem, :float + end +end From fc4be36aa74bb24db19a5dfa003ee645b2e1b181 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 19 Jul 2019 08:53:45 +0800 Subject: [PATCH 0928/1015] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E9=9B=86=E5=86=85?= =?UTF-8?q?=E5=AD=98=E4=BD=BF=E7=94=A8=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 +- app/views/games/_testset_list.json.jbuilder | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 3a49f4d80..ecbf603b0 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -855,7 +855,7 @@ class GamesController < ApplicationController if max_query_index > 0 uid_logger("max_query_index is #{max_query_index} game id is #{@game.id}, challenge_id is #{challenge.id}") - @qurey_test_sets = TestSet.find_by_sql("SELECT o.code, o.actual_output, o.out_put, o.result, o.test_set_position, o.ts_time, + @qurey_test_sets = TestSet.find_by_sql("SELECT o.code, o.actual_output, o.out_put, o.result, o.test_set_position, o.ts_time, o.ts_mem, o.query_index, t.is_public, t.input, t.output, o.compile_success FROM outputs o, games g, challenges c, test_sets t where g.id=#{@game.id} and c.id=#{challenge.id} and o.query_index=#{max_query_index} and g.id = o.game_id and c.id= g.challenge_id and t.challenge_id = c.id and diff --git a/app/views/games/_testset_list.json.jbuilder b/app/views/games/_testset_list.json.jbuilder index e5cc76625..cef29997b 100644 --- a/app/views/games/_testset_list.json.jbuilder +++ b/app/views/games/_testset_list.json.jbuilder @@ -8,6 +8,7 @@ json.test_sets @qurey_test_sets do |test_set| end json.compile_success test_set.try(:compile_success) json.ts_time test_set.try(:ts_time) + json.ts_time test_set.try(:ts_mem) end json.allowed_unlock @shixun.test_set_permission From f12634869f5615d01df889df68ea6dc8e0c87461 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 19 Jul 2019 09:19:48 +0800 Subject: [PATCH 0929/1015] .. --- db/migrate/20190718100242_add_ts_mem_to_outputs.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20190718100242_add_ts_mem_to_outputs.rb b/db/migrate/20190718100242_add_ts_mem_to_outputs.rb index 70b593a35..8a603d7be 100644 --- a/db/migrate/20190718100242_add_ts_mem_to_outputs.rb +++ b/db/migrate/20190718100242_add_ts_mem_to_outputs.rb @@ -1,5 +1,5 @@ class AddTsMemToOutputs < ActiveRecord::Migration[5.2] def change - add_column :outputs, :ts_mem, :float + # add_column :outputs, :ts_mem, :float end end From 7369240c2b60d838e3000d268a19c4f794c5658a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 19 Jul 2019 09:25:32 +0800 Subject: [PATCH 0930/1015] =?UTF-8?q?get=5Fuser=5Finfo=E5=8A=A0=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0=E8=BA=AB=E4=BB=BD=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/users/get_user_info.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/users/get_user_info.json.jbuilder b/app/views/users/get_user_info.json.jbuilder index 779d58e95..fbb9778e2 100644 --- a/app/views/users/get_user_info.json.jbuilder +++ b/app/views/users/get_user_info.json.jbuilder @@ -4,6 +4,7 @@ json.user_id @user.id json.image_url url_to_avatar(@user) json.admin @user.admin? json.is_teacher @user.user_extension&.teacher? +json.user_identity @user.identity json.tidding_count 0 json.user_phone_binded @user.phone.present? if @course From 486ae178a326e7a57e3dbe67835e611500dac5d5 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 19 Jul 2019 10:07:24 +0800 Subject: [PATCH 0931/1015] =?UTF-8?q?=E9=80=89=E7=94=A8=E5=AE=9E=E8=B7=B5?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E7=9A=84=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/subjects_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index b3e317e4b..7857f2ec6 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -69,7 +69,8 @@ class SubjectsController < ApplicationController else @subjects = @subjects[offset, limit] subject_ids = @subjects.pluck(:id) - @subjects = Subject.where(id: subject_ids).order("field(id,#{subject_ids.join(',')})").includes(:shixuns, :repertoire) + order_ids = subject_ids.size > 0 ? subject_ids.join(',') : -1 + @subjects = Subject.where(id: subject_ids).order("field(id,#{order_ids})").includes(:shixuns, :repertoire) end end From db3366aaed9000fd723d7eda77e1ec246618d0c3 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 19 Jul 2019 10:15:10 +0800 Subject: [PATCH 0932/1015] =?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/homework_commons_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 439da8add..4c3393eaf 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -995,7 +995,8 @@ class HomeworkCommonsController < ApplicationController else @subjects = @subjects[offset, limit] subject_ids = @subjects.pluck(:id) - @subjects = Subject.where(id: subject_ids).order("field(id,#{subject_ids.join(',')})").includes(:shixuns, user: [user_extension: :school]) + order_ids = subject_ids.size > 0 ? subject_ids.join(',') : -1 + @subjects = Subject.where(id: subject_ids).order("field(id,#{order_ids})").includes(:shixuns, user: [user_extension: :school]) end end From bc10b0c43f06f1819fc1ec4893a82cc4ea5a18f3 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 19 Jul 2019 10:18:50 +0800 Subject: [PATCH 0933/1015] user must profile compeleted before apply auth --- app/services/users/apply_authentication_service.rb | 2 ++ app/services/users/apply_professional_auth_service.rb | 2 ++ app/views/searchs/index.json.jbuilder | 3 ++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/services/users/apply_authentication_service.rb b/app/services/users/apply_authentication_service.rb index f31bb335c..9e0901ef4 100644 --- a/app/services/users/apply_authentication_service.rb +++ b/app/services/users/apply_authentication_service.rb @@ -9,6 +9,8 @@ class Users::ApplyAuthenticationService < ApplicationService end def call + raise Error, '请先完善基本信息' unless user.profile_completed? + Users::ApplyAuthenticationForm.new(params).validate! raise Error, '您已经申请过实名认证了' if ApplyUserAuthentication.real_name_auth.processing.exists?(user_id: user.id) diff --git a/app/services/users/apply_professional_auth_service.rb b/app/services/users/apply_professional_auth_service.rb index 2d8279317..07afe18ae 100644 --- a/app/services/users/apply_professional_auth_service.rb +++ b/app/services/users/apply_professional_auth_service.rb @@ -9,6 +9,8 @@ class Users::ApplyProfessionalAuthService < ApplicationService end def call + raise Error, '请先完善基本信息' unless user.profile_completed? + Users::ApplyProfessionalAuthForm.new(params).validate! raise Error, '您已经申请过职业认证了' if ApplyUserAuthentication.professional_auth.processing.exists?(user_id: user.id) diff --git a/app/views/searchs/index.json.jbuilder b/app/views/searchs/index.json.jbuilder index a36edb5bd..5fa0c2744 100644 --- a/app/views/searchs/index.json.jbuilder +++ b/app/views/searchs/index.json.jbuilder @@ -5,6 +5,7 @@ json.results do json.type obj.class.name.downcase json.title highlights.delete(:name)&.join('...') || obj.searchable_title - json.description highlights.values[0,5].each { |arr| arr.is_a?(Array) ? arr.join('...') : arr }.join('
') + # json.description highlights.values[0,5].each { |arr| arr.is_a?(Array) ? arr.join('...') : arr }.join('
') + json.content highlights end end \ No newline at end of file From ea31d669d311dbc079fbfe597eab3e88467d7795 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 19 Jul 2019 10:28:11 +0800 Subject: [PATCH 0934/1015] =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E5=92=8C=E5=BF=98=E8=AE=B0=E5=AF=86=E7=A0=81=E7=9A=84=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E7=8A=B6=E6=80=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 15 +++++++-------- app/models/user.rb | 6 +++--- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 63a38670f..8df358cf7 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -31,10 +31,11 @@ class AccountsController < ApplicationController verifi_code = VerificationCode.where(email: email, code: code, code_type: 8).last end 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 上线前请删除 - if !check_code && code != "513231" - tip_exception("验证码无效") + # 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" + tip_exception(-2, "验证码不正确") if verifi_code.try(:code) != code.strip + tip_exception(-2, "验证码已失效") if (Time.now.to_i - verifi_code.created_at.to_i) <= 10*60 end code = generate_identifier User, 8 @@ -88,10 +89,8 @@ class AccountsController < ApplicationController verifi_code = VerificationCode.where(email: email, code: code, code_type: 3).last user = User.find_by_mail(email) #这里有问题,应该是为email,而不是mail 6.13-hs end - check_code = (verifi_code.try(:code) == code.strip && (Time.now.to_i - verifi_code.created_at.to_i) <= 10*60) - unless check_code - tip_exception("验证码无效") - end + tip_exception(-2, "验证码不正确") if verifi_code.try(:code) != code.strip + tip_exception(-2, "验证码已失效") if (Time.now.to_i - verifi_code.created_at.to_i) <= 10*60 user.password, user.password_confirmation = params[:new_password], params[:new_password_confirmation] if user.save! diff --git a/app/models/user.rb b/app/models/user.rb index 3ed327c0c..894a28910 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -509,10 +509,10 @@ class User < ApplicationRecord if user # user is already in local database - raise("账号已被注销,请联系管理员") if user.locked? - raise("密码错误") unless user.check_password?(password) + raise Educoder::TipException.new(-2, "违反平台使用规范,账号已被锁定") if user.locked? + raise Educoder::TipException.new(-2, "错误的账号或密码") unless user.check_password?(password) else - raise("账号未注册") + raise Educoder::TipException.new(-2, "错误的账号或密码") end user From 950b8e9acb54a5c9d5f2a355f5f0f65fc41c17c7 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 19 Jul 2019 10:41:27 +0800 Subject: [PATCH 0935/1015] =?UTF-8?q?=E6=B3=A8=E5=86=8C=E9=A1=B5=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=E8=B7=AF=E7=94=B1=E7=9A=84=E8=BF=94=E5=9B=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 1 + app/views/accounts/register.json.jbuilder | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 app/views/accounts/register.json.jbuilder diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 8df358cf7..6ac62f887 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -57,6 +57,7 @@ class AccountsController < ApplicationController ) successful_authentication(@user) session[:user_id] = @user.id + normal_status("注册成功") end rescue Exception => e uid_logger_error(e.message) diff --git a/app/views/accounts/register.json.jbuilder b/app/views/accounts/register.json.jbuilder deleted file mode 100644 index 9a3dba175..000000000 --- a/app/views/accounts/register.json.jbuilder +++ /dev/null @@ -1 +0,0 @@ -json.redirect_uri subjects_url \ No newline at end of file From 89fa1200b22d73ce22a457c1b8493d0494ec9b31 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 19 Jul 2019 14:45:19 +0800 Subject: [PATCH 0936/1015] =?UTF-8?q?=E6=B7=BB=E5=8A=A0mem=E5=AD=97?= =?UTF-8?q?=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190718100242_add_ts_mem_to_outputs.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20190718100242_add_ts_mem_to_outputs.rb b/db/migrate/20190718100242_add_ts_mem_to_outputs.rb index 8a603d7be..70b593a35 100644 --- a/db/migrate/20190718100242_add_ts_mem_to_outputs.rb +++ b/db/migrate/20190718100242_add_ts_mem_to_outputs.rb @@ -1,5 +1,5 @@ class AddTsMemToOutputs < ActiveRecord::Migration[5.2] def change - # add_column :outputs, :ts_mem, :float + add_column :outputs, :ts_mem, :float end end From d34817834cdfd584e3799449d246bbf4f992885b Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 19 Jul 2019 14:47:54 +0800 Subject: [PATCH 0937/1015] modify apply add school valid --- app/forms/add_school_apply_form.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/forms/add_school_apply_form.rb b/app/forms/add_school_apply_form.rb index c0b767f06..f98e8b05b 100644 --- a/app/forms/add_school_apply_form.rb +++ b/app/forms/add_school_apply_form.rb @@ -4,7 +4,7 @@ class AddSchoolApplyForm attr_accessor :name, :province, :city, :address, :remarks validates :name, presence: true - validates :province, presence: true - validates :city, presence: true - validates :address, presence: true + # validates :province, presence: true + # validates :city, presence: true + # validates :address, presence: true end \ No newline at end of file From eaacad16c014e9906cce7700eeaaa7ad40749422 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 19 Jul 2019 15:08:54 +0800 Subject: [PATCH 0938/1015] search api shixun add identifier column --- app/models/searchable/shixun.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/searchable/shixun.rb b/app/models/searchable/shixun.rb index 7abd76ec6..bc19967a2 100644 --- a/app/models/searchable/shixun.rb +++ b/app/models/searchable/shixun.rb @@ -43,6 +43,7 @@ module Searchable::Shixun def to_searchable_json { id: id, + identifier: identifier, author_name: user.real_name, author_school_name: user.school_name, visits_count: visits, @@ -55,4 +56,4 @@ module Searchable::Shixun { user: { user_extension: :school } } end end -end \ No newline at end of file +end From 45a3a17d8776eee76824662feffe0283b775bd65 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 19 Jul 2019 15:43:40 +0800 Subject: [PATCH 0939/1015] fix register verify code expire bug --- 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 6ac62f887..288cf2acc 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -35,7 +35,7 @@ class AccountsController < ApplicationController # todo 上线前请删除万能验证码"513231" if code != "513231" tip_exception(-2, "验证码不正确") if verifi_code.try(:code) != code.strip - tip_exception(-2, "验证码已失效") if (Time.now.to_i - verifi_code.created_at.to_i) <= 10*60 + tip_exception(-2, "验证码已失效") if (Time.now.to_i - verifi_code.created_at.to_i) > 10*60 end code = generate_identifier User, 8 From 635e0ad2e541154f8d768def7cbca6ed3f672e44 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 19 Jul 2019 15:49:38 +0800 Subject: [PATCH 0940/1015] mem --- app/views/games/_testset_list.json.jbuilder | 2 +- app/views/games/game_status.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/games/_testset_list.json.jbuilder b/app/views/games/_testset_list.json.jbuilder index cef29997b..86bf2de1b 100644 --- a/app/views/games/_testset_list.json.jbuilder +++ b/app/views/games/_testset_list.json.jbuilder @@ -8,7 +8,7 @@ json.test_sets @qurey_test_sets do |test_set| end json.compile_success test_set.try(:compile_success) json.ts_time test_set.try(:ts_time) - json.ts_time test_set.try(:ts_mem) + json.ts_mem test_set.try(:ts_mem) end json.allowed_unlock @shixun.test_set_permission diff --git a/app/views/games/game_status.json.jbuilder b/app/views/games/game_status.json.jbuilder index aecbf9d42..73de75598 100644 --- a/app/views/games/game_status.json.jbuilder +++ b/app/views/games/game_status.json.jbuilder @@ -1,4 +1,4 @@ json.(@base_date, :grade, :gold, :experience, :status, :had_done, :position, :port, :record_consume_time, :mirror_name, - :picture, :web_route, :star, :next_game, :prev_game, :max_mem) + :picture, :web_route, :star, :next_game, :prev_game) # # 测试集相关 json.partial! 'games/testset_list' \ No newline at end of file From 155152acb1f9442967ee198d43cf45ed4a8b0b76 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 19 Jul 2019 15:58:50 +0800 Subject: [PATCH 0941/1015] =?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/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 288cf2acc..d81195598 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -91,7 +91,7 @@ class AccountsController < ApplicationController user = User.find_by_mail(email) #这里有问题,应该是为email,而不是mail 6.13-hs end tip_exception(-2, "验证码不正确") if verifi_code.try(:code) != code.strip - tip_exception(-2, "验证码已失效") if (Time.now.to_i - verifi_code.created_at.to_i) <= 10*60 + tip_exception(-2, "验证码已失效") if (Time.now.to_i - verifi_code.created_at.to_i) > 10*60 user.password, user.password_confirmation = params[:new_password], params[:new_password_confirmation] if user.save! From 526a6d47028efc07a9ff01743d8a7f9fb9dd45d8 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 19 Jul 2019 16:54:36 +0800 Subject: [PATCH 0942/1015] change es highlight tag --- app/services/concerns/elasticsearch_able.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/concerns/elasticsearch_able.rb b/app/services/concerns/elasticsearch_able.rb index e1c33ed4a..c08aab029 100644 --- a/app/services/concerns/elasticsearch_able.rb +++ b/app/services/concerns/elasticsearch_able.rb @@ -20,7 +20,7 @@ module ElasticsearchAble def highlight_options { fragment_size: EduSetting.get('es_highlight_fragment_size') || 30, - tag: '' + tag: '' } end From da8d3dc29cf00a7077de9603e846051e4ffa1976 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 19 Jul 2019 17:43:02 +0800 Subject: [PATCH 0943/1015] =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E5=8A=A0=E5=85=A5=E5=BC=95=E6=B5=81=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 8 ++++++-- app/models/user_agent.rb | 6 ++++++ spec/models/user_agent_spec.rb | 5 +++++ 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 app/models/user_agent.rb create mode 100644 spec/models/user_agent_spec.rb diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 6ac62f887..feaee7eae 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -55,6 +55,10 @@ class AccountsController < ApplicationController container_type: pre == 'p' ? 'Phone' : 'Mail', score: 500 ) + # 注册时,记录是否是引流用户 + ip = request.remote_ip + ua = UserAgent.find_by_ip(ip) + ua.update_column(:agent_type, UserAgent::USER_REGISTER) if ua successful_authentication(@user) session[:user_id] = @user.id normal_status("注册成功") @@ -110,7 +114,7 @@ class AccountsController < ApplicationController # generate a key and set cookie if autologin set_autologin_cookie(user) - UserAction.create(:action_id => user.try(:id), :action_type => "Login", :user_id => user.try(:id)) + UserAction.create(:action_id => user.try(:id), :action_type => "Login", :user_id => user.try(:id), :ip => request.remote_ip) # 注册完成后有一天的试用申请 UserDayCertification.create(user_id: user.id, status: 1) @@ -133,7 +137,7 @@ class AccountsController < ApplicationController end def logout - UserAction.create(action_id: User.current.id, action_type: "Logout", user_id: User.current.id) + UserAction.create(action_id: User.current.id, action_type: "Logout", user_id: User.current.id, :ip => request.remote_ip) session[:user_id] = nil logout_user render :json => {status: 1, message: "退出成功!"} diff --git a/app/models/user_agent.rb b/app/models/user_agent.rb new file mode 100644 index 000000000..538369f1a --- /dev/null +++ b/app/models/user_agent.rb @@ -0,0 +1,6 @@ +class UserAgent < ApplicationRecord + has_many :user_actionss, :foreign_key => "ip", :primary_key => "ip" + USER_AD = 1 # 广告宣传的引流 + USER_REGISTER = 2 # 引流注册 + USER_COMPETITION = 3 # 引流参加竞赛 +end diff --git a/spec/models/user_agent_spec.rb b/spec/models/user_agent_spec.rb new file mode 100644 index 000000000..2bd0f7bbc --- /dev/null +++ b/spec/models/user_agent_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe UserAgent, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From ac5d8f627f0fbd36c1d5ee8814a245b7858381a6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 19 Jul 2019 18:02:55 +0800 Subject: [PATCH 0944/1015] =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 4 ++-- app/views/users/homepage_info.json.jbuilder | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index d81195598..5fa5357d9 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -35,7 +35,7 @@ class AccountsController < ApplicationController # todo 上线前请删除万能验证码"513231" if code != "513231" tip_exception(-2, "验证码不正确") if verifi_code.try(:code) != code.strip - tip_exception(-2, "验证码已失效") if (Time.now.to_i - verifi_code.created_at.to_i) > 10*60 + tip_exception(-2, "验证码已失效") if !verifi_code&.effective? end code = generate_identifier User, 8 @@ -91,7 +91,7 @@ class AccountsController < ApplicationController user = User.find_by_mail(email) #这里有问题,应该是为email,而不是mail 6.13-hs end tip_exception(-2, "验证码不正确") if verifi_code.try(:code) != code.strip - tip_exception(-2, "验证码已失效") if (Time.now.to_i - verifi_code.created_at.to_i) > 10*60 + tip_exception(-2, "验证码已失效") if !verifi_code&.effective? user.password, user.password_confirmation = params[:new_password], params[:new_password_confirmation] if user.save! diff --git a/app/views/users/homepage_info.json.jbuilder b/app/views/users/homepage_info.json.jbuilder index 3f985eab9..1621448f3 100644 --- a/app/views/users/homepage_info.json.jbuilder +++ b/app/views/users/homepage_info.json.jbuilder @@ -1,5 +1,5 @@ json.id @user.id -json.name @user.homepage_name +json.name @user.full_name json.avatar_url url_to_avatar(@user) json.is_logged_user @user.logged_user? json.experience @user.experience From 9e559fe023248736076829484c618a47262c6f6e Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 19 Jul 2019 18:04:21 +0800 Subject: [PATCH 0945/1015] =?UTF-8?q?=E5=88=A0=E9=99=A4gu=E5=AE=89?= =?UTF-8?q?=E7=90=AA=E5=95=8A=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 697585e0c..8a8763260 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -270,7 +270,7 @@ class ChallengesController < ApplicationController @challenge.destroy # 关卡位置被删除,需要修改脚本 script = modify_shixun_script @shixun, @shixun.evaluate_script - @shixun.update_column(:evaluate_script, script) + @shixun.shixun_info.update_column(:evaluate_script, script) end From a81caf66b86ceef130906e8c70d3a262f64a2bee Mon Sep 17 00:00:00 2001 From: p31729568 Date: Fri, 19 Jul 2019 18:12:32 +0800 Subject: [PATCH 0946/1015] modify search api --- app/models/searchable/shixun.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/searchable/shixun.rb b/app/models/searchable/shixun.rb index bc19967a2..a564be388 100644 --- a/app/models/searchable/shixun.rb +++ b/app/models/searchable/shixun.rb @@ -47,7 +47,8 @@ module Searchable::Shixun author_name: user.real_name, author_school_name: user.school_name, visits_count: visits, - challenges_count: challenges_count + challenges_count: challenges_count, + study_count: myshixuns_count } end From d19cf56e383ceefb6fbe86e9501a5d8ee93d61fa Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 19 Jul 2019 18:23:45 +0800 Subject: [PATCH 0947/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E7=9A=84=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190309085449_migrate_course_members.rb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/db/migrate/20190309085449_migrate_course_members.rb b/db/migrate/20190309085449_migrate_course_members.rb index 1d28eb5d1..d677e4bd4 100644 --- a/db/migrate/20190309085449_migrate_course_members.rb +++ b/db/migrate/20190309085449_migrate_course_members.rb @@ -19,15 +19,13 @@ class MigrateCourseMembers < ActiveRecord::Migration[5.2] ActiveRecord::Base.transaction do begin - Member.where("course_id != -1").find_each do |member| - if member.course && member.user - puts(member.id) - member.member_roles.each do |role| - course_member_role = role.role_id == 3 ? 1 : (role.role_id == 9 ? 2 : (role.role_id == 7 ? 3 : 4)) - member_group_id = role.role_id == 10 ? member.course_group_id : 0 - CourseMember.create!(course_id: member.course_id, user_id: member.user_id, course_group_id: member_group_id.to_i, - graduation_group_id: member.graduation_group_id.to_i, role: course_member_role, is_active: role.is_current) - end + Member.where("course_id != -1").includes(:member_roles).find_each(batch_size: 500) do |member| + puts(member.id) + member.member_roles.each do |role| + course_member_role = role.role_id == 3 ? 1 : (role.role_id == 9 ? 2 : (role.role_id == 7 ? 3 : 4)) + member_group_id = role.role_id == 10 ? member.course_group_id : 0 + CourseMember.create!(course_id: member.course_id, user_id: member.user_id, course_group_id: member_group_id, + graduation_group_id: member.graduation_group_id, role: course_member_role, is_active: role.is_current) end end rescue Exception => e From 9d678a73abc56718277217304caaacc54482b854 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 19 Jul 2019 18:30:41 +0800 Subject: [PATCH 0948/1015] =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E7=A7=BB=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/challenges_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/challenges_controller.rb b/app/controllers/challenges_controller.rb index 8a8763260..9b5f0b869 100644 --- a/app/controllers/challenges_controller.rb +++ b/app/controllers/challenges_controller.rb @@ -249,7 +249,7 @@ class ChallengesController < ApplicationController next_challenge.update_attribute(:position, next_challenge.position - 1) # 关卡位置被修改,需要修改脚本 script = modify_shixun_script @shixun, @shixun.evaluate_script - @shixun.update_column(:evaluate_script, script) + @shixun.shixun_info.update_column(:evaluate_script, script) end def index_up @@ -259,7 +259,7 @@ class ChallengesController < ApplicationController last_challenge.update_attribute(:position, last_challenge.position + 1) # 关卡位置被修改,需要修改脚本 script = modify_shixun_script @shixun, @shixun.evaluate_script - @shixun.update_column(:evaluate_script, script) + @shixun.shixun_info.update_column(:evaluate_script, script) end def destroy From 47a13454bc5b109252572c129ae006aeb8a67a90 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 19 Jul 2019 20:53:40 +0800 Subject: [PATCH 0949/1015] =?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/accounts_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 4491d0141..52d405955 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -34,8 +34,8 @@ class AccountsController < ApplicationController # 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" - tip_exception(-2, "验证码不正确") if verifi_code.try(:code) != code.strip - tip_exception(-2, "验证码已失效") if !verifi_code&.effective? + return normal_status(-2, "验证码不正确") if verifi_code.try(:code) != code.strip + return normal_status(-2, "验证码已失效") if !verifi_code&.effective? end code = generate_identifier User, 8 @@ -94,8 +94,8 @@ class AccountsController < ApplicationController verifi_code = VerificationCode.where(email: email, code: code, code_type: 3).last user = User.find_by_mail(email) #这里有问题,应该是为email,而不是mail 6.13-hs end - tip_exception(-2, "验证码不正确") if verifi_code.try(:code) != code.strip - tip_exception(-2, "验证码已失效") if !verifi_code&.effective? + return normal_status(-2, "验证码不正确") if verifi_code.try(:code) != code.strip + return normal_status(-2, "验证码已失效") if !verifi_code&.effective? user.password, user.password_confirmation = params[:new_password], params[:new_password_confirmation] if user.save! From c25d89db7578c2448a66f505adea9fd7a8477df6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 19 Jul 2019 21:02:02 +0800 Subject: [PATCH 0950/1015] =?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/accounts_controller.rb | 9 +++++++++ app/models/user.rb | 8 -------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 52d405955..71da15386 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -72,6 +72,15 @@ class AccountsController < ApplicationController # 用户登录 def login @user = User.try_to_login(params[:login], params[:password]) + + if @user + # user is already in local database + return normal_status(-2, "违反平台使用规范,账号已被锁定") if @user.locked? + return normal_status(-2, "错误的账号或密码") unless @user.check_password?(params[:password].to_s) + else + return normal_status(-2, "错误的账号或密码") + end + @user.update_column(:last_login_on, Time.now) successful_authentication(@user) diff --git a/app/models/user.rb b/app/models/user.rb index 894a28910..299ad1ff4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -507,14 +507,6 @@ class User < ApplicationRecord user = find_by_login(login) end - if user - # user is already in local database - raise Educoder::TipException.new(-2, "违反平台使用规范,账号已被锁定") if user.locked? - raise Educoder::TipException.new(-2, "错误的账号或密码") unless user.check_password?(password) - else - raise Educoder::TipException.new(-2, "错误的账号或密码") - end - user rescue => text raise text From 6c0bb47639d84467553c4dad3e83de7bd16cf16a Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 19 Jul 2019 23:01:20 +0800 Subject: [PATCH 0951/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E9=87=8D=E5=A4=8D?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190309085449_migrate_course_members.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20190309085449_migrate_course_members.rb b/db/migrate/20190309085449_migrate_course_members.rb index 1d28eb5d1..aeb633310 100644 --- a/db/migrate/20190309085449_migrate_course_members.rb +++ b/db/migrate/20190309085449_migrate_course_members.rb @@ -1,6 +1,6 @@ class MigrateCourseMembers < ActiveRecord::Migration[5.2] def change - add_column :course_groups, :position, :integer, default: 0 + # add_column :course_groups, :position, :integer, default: 0 Course.find_each do |course| position = 1 From 84dbbc42fe1d6131e9fe7101a5ff1089003b949d Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 19 Jul 2019 23:15:17 +0800 Subject: [PATCH 0952/1015] =?UTF-8?q?logger=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/course_board_message_count.rake | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/tasks/course_board_message_count.rake b/lib/tasks/course_board_message_count.rake index 49f33c615..bd85d7ede 100644 --- a/lib/tasks/course_board_message_count.rake +++ b/lib/tasks/course_board_message_count.rake @@ -2,7 +2,7 @@ namespace :course_board do desc 'transfer children message to root message board' task children_message_transfer: :environment do Board.find_each do |board| - logger("Current transfer board id: #{board.id} ~") + Rails.logger.info("Current transfer board id: #{board.id} ~") root_subquery = board.messages.where(parent_id: nil).reorder(nil).pluck(:id) if root_subquery.present? @@ -16,14 +16,14 @@ namespace :course_board do end Board.reset_counters(board.id, :messages) - logger("transfer success ~") + Rails.logger.info("transfer success ~") end end desc 'transfer root id && statistic descendants count' task messages_descendants_count_transfer: :environment do Message.root_nodes.find_each do |root| - logger("Current transfer root id: #{root.id} ~") + Rails.logger.info("Current transfer root id: #{root.id} ~") children_ids = root.children.pluck(:id) next if children_ids.blank? @@ -33,7 +33,7 @@ namespace :course_board do Message.where(id: ids).update_all(root_id: root.id) Message.reset_counters(root.id, :descendants) - logger("transfer success ~") + Rails.logger.info("transfer success ~") end end From eef2e988c26cd477b82e005a942d8902224efa9b Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 19 Jul 2019 23:16:52 +0800 Subject: [PATCH 0953/1015] .. --- lib/tasks/course_board_message_count.rake | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tasks/course_board_message_count.rake b/lib/tasks/course_board_message_count.rake index bd85d7ede..dadd7c3d0 100644 --- a/lib/tasks/course_board_message_count.rake +++ b/lib/tasks/course_board_message_count.rake @@ -37,7 +37,7 @@ namespace :course_board do end end - def logger(msg) - puts msg - end + # def logger(msg) + # puts msg + # end end \ No newline at end of file From a317f05f06884aa10765b2907b436f02be3fb87b Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 19 Jul 2019 23:36:12 +0800 Subject: [PATCH 0954/1015] =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=8E=A5=E5=8F=A3?= =?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/views/users/_user.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/users/_user.json.jbuilder b/app/views/users/_user.json.jbuilder index afec979a1..581072072 100644 --- a/app/views/users/_user.json.jbuilder +++ b/app/views/users/_user.json.jbuilder @@ -2,6 +2,7 @@ json.user_id user.id json.login user.login json.name user.full_name json.grade user.grade +json.identity user&.user_extension&.identity # json.email user.mail # 邮箱原则上不暴露的,如果实在需要的话只能对某些具体的接口公开 json.image_url url_to_avatar(user) json.school user.school_name \ No newline at end of file From 9cfb2c2a19cd545f53e2587d51db24f2cde38b16 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 19 Jul 2019 23:36:53 +0800 Subject: [PATCH 0955/1015] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=BA=93=E8=BF=81?= =?UTF-8?q?=E7=A7=BB=E5=A6=82=E6=9E=9C=E6=B2=A1=E8=BF=81=E7=A7=BB=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index ecbf603b0..5c432baa0 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -489,7 +489,13 @@ class GamesController < ApplicationController path = path.try(:strip) uid_logger("--rep_content: path is #{path}") begin - @content = git_fle_content(@myshixun.repo_path, path) || "" + if @myshixun.repo_name.nil? + g = Gitlab.client + repo_name = g.project(@myshixun.gpid).path_with_namespace + @myshixun.update_column(:repo_name, repo_name) + end + + @content = git_fle_content("#{repo_name}.git", path) || "" rescue Exception => e # 思路: 异常首先应该考虑去恢复 if params[:retry].to_i == 1 From 80f4c8f6ba7561c023b28aea4e71ec0ff6c64318 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Fri, 19 Jul 2019 23:41:18 +0800 Subject: [PATCH 0956/1015] repo content --- app/controllers/games_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 5c432baa0..ec69f3963 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -493,9 +493,11 @@ class GamesController < ApplicationController g = Gitlab.client repo_name = g.project(@myshixun.gpid).path_with_namespace @myshixun.update_column(:repo_name, repo_name) + @content = git_fle_content("#{repo_name}.git", path) || "" + else + @content = git_fle_content(@myshixun.repo_path, path) || "" end - @content = git_fle_content("#{repo_name}.git", path) || "" rescue Exception => e # 思路: 异常首先应该考虑去恢复 if params[:retry].to_i == 1 From 9741a0250304c731cbe553c07890eb5c6d98cb6b Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 00:17:46 +0800 Subject: [PATCH 0957/1015] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190426010412_add_is_invalid_to_student_works_scores.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20190426010412_add_is_invalid_to_student_works_scores.rb b/db/migrate/20190426010412_add_is_invalid_to_student_works_scores.rb index 2d782f924..7b893db6d 100644 --- a/db/migrate/20190426010412_add_is_invalid_to_student_works_scores.rb +++ b/db/migrate/20190426010412_add_is_invalid_to_student_works_scores.rb @@ -1,6 +1,6 @@ class AddIsInvalidToStudentWorksScores < ActiveRecord::Migration[5.2] def change - add_column :student_works_scores, :is_invalid, :boolean, default: false + # add_column :student_works_scores, :is_invalid, :boolean, default: false StudentWorksScore.where("score is not null").order("id desc").find_each do |score| unless score.is_invalid From ebf2b5c94a66390bbb71646683891ae7ab75605d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 00:39:03 +0800 Subject: [PATCH 0958/1015] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190517092730_add_description_to_edu_settings.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20190517092730_add_description_to_edu_settings.rb b/db/migrate/20190517092730_add_description_to_edu_settings.rb index ad273b805..65fb52e35 100644 --- a/db/migrate/20190517092730_add_description_to_edu_settings.rb +++ b/db/migrate/20190517092730_add_description_to_edu_settings.rb @@ -1,6 +1,6 @@ class AddDescriptionToEduSettings < ActiveRecord::Migration[5.2] def change - add_column :edu_settings, :description, :string + # add_column :edu_settings, :description, :string add_index :edu_settings, :name, unique: :true ['tomcat_webssh', 'webssh_username', 'webssh_password', 'git_address_ip', 'git_address_domain', 'git_username', From 8dbc4c65ce0b1525bd608e835fe2bbdecae5b20c Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 00:39:38 +0800 Subject: [PATCH 0959/1015] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190517092730_add_description_to_edu_settings.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20190517092730_add_description_to_edu_settings.rb b/db/migrate/20190517092730_add_description_to_edu_settings.rb index 65fb52e35..c8f54ca31 100644 --- a/db/migrate/20190517092730_add_description_to_edu_settings.rb +++ b/db/migrate/20190517092730_add_description_to_edu_settings.rb @@ -1,7 +1,7 @@ class AddDescriptionToEduSettings < ActiveRecord::Migration[5.2] def change # add_column :edu_settings, :description, :string - add_index :edu_settings, :name, unique: :true + # add_index :edu_settings, :name, unique: :true ['tomcat_webssh', 'webssh_username', 'webssh_password', 'git_address_ip', 'git_address_domain', 'git_username', 'git_password', 'public_key', 'private_key', 'public_bucket', 'public_bucket_host', 'public_cdn_host', 'cloud_bridge', From 70447eaa26de19e4002bbe2a502080a0c3cb40c3 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 00:41:04 +0800 Subject: [PATCH 0960/1015] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190613022158_add_exec_time_to_challenge.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20190613022158_add_exec_time_to_challenge.rb b/db/migrate/20190613022158_add_exec_time_to_challenge.rb index c1743674c..8998b3d82 100644 --- a/db/migrate/20190613022158_add_exec_time_to_challenge.rb +++ b/db/migrate/20190613022158_add_exec_time_to_challenge.rb @@ -1,6 +1,6 @@ class AddExecTimeToChallenge < ActiveRecord::Migration[5.2] def change - add_column :challenges, :exec_time, :integer + # add_column :challenges, :exec_time, :integer Shixun.find_each do |shixun| shixun.challenges.update_all(exec_time: shixun.exec_time) From 8097531dbb9ae6d03a5696ca3541aca53edb6a08 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 20 Jul 2019 01:29:16 +0800 Subject: [PATCH 0961/1015] =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190705085829_add_sec_key_to_outputs.rb | 2 ++ db/migrate/20190716062401_add_ts_time_to_outputs.rb | 5 ----- db/migrate/20190718100242_add_ts_mem_to_outputs.rb | 5 ----- 3 files changed, 2 insertions(+), 10 deletions(-) delete mode 100644 db/migrate/20190716062401_add_ts_time_to_outputs.rb delete mode 100644 db/migrate/20190718100242_add_ts_mem_to_outputs.rb diff --git a/db/migrate/20190705085829_add_sec_key_to_outputs.rb b/db/migrate/20190705085829_add_sec_key_to_outputs.rb index 428fbaced..df4d59be0 100644 --- a/db/migrate/20190705085829_add_sec_key_to_outputs.rb +++ b/db/migrate/20190705085829_add_sec_key_to_outputs.rb @@ -1,5 +1,7 @@ class AddSecKeyToOutputs < ActiveRecord::Migration[5.2] def change add_column :outputs, :sec_key, :string + add_column :outputs, :ts_mem, :float + add_column :outputs, :ts_time, :float end end diff --git a/db/migrate/20190716062401_add_ts_time_to_outputs.rb b/db/migrate/20190716062401_add_ts_time_to_outputs.rb deleted file mode 100644 index 8e0c55a78..000000000 --- a/db/migrate/20190716062401_add_ts_time_to_outputs.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddTsTimeToOutputs < ActiveRecord::Migration[5.2] - def change - add_column :outputs, :ts_time, :float - end -end diff --git a/db/migrate/20190718100242_add_ts_mem_to_outputs.rb b/db/migrate/20190718100242_add_ts_mem_to_outputs.rb deleted file mode 100644 index 70b593a35..000000000 --- a/db/migrate/20190718100242_add_ts_mem_to_outputs.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddTsMemToOutputs < ActiveRecord::Migration[5.2] - def change - add_column :outputs, :ts_mem, :float - end -end From 1e59e577bc1ebe8b15d283549c0cec28eeaddde7 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 20 Jul 2019 07:20:39 +0800 Subject: [PATCH 0962/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190705085829_add_sec_key_to_outputs.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20190705085829_add_sec_key_to_outputs.rb b/db/migrate/20190705085829_add_sec_key_to_outputs.rb index df4d59be0..792783047 100644 --- a/db/migrate/20190705085829_add_sec_key_to_outputs.rb +++ b/db/migrate/20190705085829_add_sec_key_to_outputs.rb @@ -1,6 +1,6 @@ class AddSecKeyToOutputs < ActiveRecord::Migration[5.2] def change - add_column :outputs, :sec_key, :string + #add_column :outputs, :sec_key, :string add_column :outputs, :ts_mem, :float add_column :outputs, :ts_time, :float end From 06661522d4638a12e029d37c5d09496fb25ba7ec Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 08:52:33 +0800 Subject: [PATCH 0963/1015] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190517092730_add_description_to_edu_settings.rb | 4 ++-- db/migrate/20190613022158_add_exec_time_to_challenge.rb | 2 +- db/migrate/20190705085829_add_sec_key_to_outputs.rb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/db/migrate/20190517092730_add_description_to_edu_settings.rb b/db/migrate/20190517092730_add_description_to_edu_settings.rb index c8f54ca31..ad273b805 100644 --- a/db/migrate/20190517092730_add_description_to_edu_settings.rb +++ b/db/migrate/20190517092730_add_description_to_edu_settings.rb @@ -1,7 +1,7 @@ class AddDescriptionToEduSettings < ActiveRecord::Migration[5.2] def change - # add_column :edu_settings, :description, :string - # add_index :edu_settings, :name, unique: :true + add_column :edu_settings, :description, :string + add_index :edu_settings, :name, unique: :true ['tomcat_webssh', 'webssh_username', 'webssh_password', 'git_address_ip', 'git_address_domain', 'git_username', 'git_password', 'public_key', 'private_key', 'public_bucket', 'public_bucket_host', 'public_cdn_host', 'cloud_bridge', diff --git a/db/migrate/20190613022158_add_exec_time_to_challenge.rb b/db/migrate/20190613022158_add_exec_time_to_challenge.rb index 8998b3d82..c1743674c 100644 --- a/db/migrate/20190613022158_add_exec_time_to_challenge.rb +++ b/db/migrate/20190613022158_add_exec_time_to_challenge.rb @@ -1,6 +1,6 @@ class AddExecTimeToChallenge < ActiveRecord::Migration[5.2] def change - # add_column :challenges, :exec_time, :integer + add_column :challenges, :exec_time, :integer Shixun.find_each do |shixun| shixun.challenges.update_all(exec_time: shixun.exec_time) diff --git a/db/migrate/20190705085829_add_sec_key_to_outputs.rb b/db/migrate/20190705085829_add_sec_key_to_outputs.rb index 792783047..1da2930ae 100644 --- a/db/migrate/20190705085829_add_sec_key_to_outputs.rb +++ b/db/migrate/20190705085829_add_sec_key_to_outputs.rb @@ -1,7 +1,7 @@ class AddSecKeyToOutputs < ActiveRecord::Migration[5.2] def change #add_column :outputs, :sec_key, :string - add_column :outputs, :ts_mem, :float - add_column :outputs, :ts_time, :float + # add_column :outputs, :ts_mem, :float + # add_column :outputs, :ts_time, :float end end From 910399013dca8d073d8657c3e106a86662f57fd0 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 20 Jul 2019 09:17:02 +0800 Subject: [PATCH 0964/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190716064225_add_max_mem_to_evaluate_records.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20190716064225_add_max_mem_to_evaluate_records.rb b/db/migrate/20190716064225_add_max_mem_to_evaluate_records.rb index 4c9907d0a..86425262d 100644 --- a/db/migrate/20190716064225_add_max_mem_to_evaluate_records.rb +++ b/db/migrate/20190716064225_add_max_mem_to_evaluate_records.rb @@ -1,5 +1,5 @@ class AddMaxMemToEvaluateRecords < ActiveRecord::Migration[5.2] def change - add_column :evaluate_records, :max_mem, :float + #add_column :evaluate_records, :max_mem, :float end end From 23ee7debfbe02ea1fb349a99bfe531e6163b67b2 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 20 Jul 2019 09:29:37 +0800 Subject: [PATCH 0965/1015] fix bind email --- app/models/searchable/shixun.rb | 2 +- app/services/users/bind_email_service.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/searchable/shixun.rb b/app/models/searchable/shixun.rb index a564be388..49e066eac 100644 --- a/app/models/searchable/shixun.rb +++ b/app/models/searchable/shixun.rb @@ -2,7 +2,7 @@ module Searchable::Shixun extend ActiveSupport::Concern included do - searchkick language: 'chinese'#, callbacks: :async + searchkick language: 'chinese', callbacks: :async scope :search_import, -> { includes(:shixun_info, :challenges, :challenge_tags, :users, user: { user_extension: :school }) } end diff --git a/app/services/users/bind_email_service.rb b/app/services/users/bind_email_service.rb index 02cf8b91a..1ad9ad6b4 100644 --- a/app/services/users/bind_email_service.rb +++ b/app/services/users/bind_email_service.rb @@ -13,7 +13,7 @@ class Users::BindEmailService < ApplicationService raise Error, '该邮箱已被绑定' if User.where.not(id: user.id).exists?(mail: params[:email]) - code = VerificationCode.where(mail: params[:email], code: params[:code], code_type: 4).last + code = VerificationCode.where(email: params[:email], code: params[:code], code_type: 4).last raise Error, '验证码无效' unless code&.effective? ActiveRecord::Base.transaction do From b31b3b939c2584f99f2c4433868a1fb13cbf128f Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 20 Jul 2019 10:29:20 +0800 Subject: [PATCH 0966/1015] rep_name --- app/controllers/shixuns_controller.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index f1e36a5c8..4b1d39245 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -528,6 +528,14 @@ class ShixunsController < ApplicationController tip_show_exception("/myshixuns/#{current_myshixun.try(:identifier)}/reset_my_game") end + + if current_myshixun.repo_name.nil? + g = Gitlab.client + repo_name = g.project(current_myshixun.gpid).try(:path_with_namespace) + current_myshixun.update_column(:repo_name, repo_name) + end + + # 如果存在实训,则直接进入实训 # 如果实训允许跳关,传参params[:challenge_id]跳入具体的关卡 @current_task = From c1a485f33a16d2e061fc55dd362db115cb2152b7 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 20 Jul 2019 10:36:24 +0800 Subject: [PATCH 0967/1015] fix es highlight --- app/services/concerns/elasticsearch_able.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/services/concerns/elasticsearch_able.rb b/app/services/concerns/elasticsearch_able.rb index c08aab029..c1640470c 100644 --- a/app/services/concerns/elasticsearch_able.rb +++ b/app/services/concerns/elasticsearch_able.rb @@ -20,7 +20,15 @@ module ElasticsearchAble def highlight_options { fragment_size: EduSetting.get('es_highlight_fragment_size') || 30, - tag: '' + tag: '', + fields: { + challenge_names: { type: 'plain' }, + challenge_tag_names: { type: 'plain' }, + description: { type: 'plain' }, + subject_stages: { type: 'plain' }, + content: { type: 'plain' }, + descendants_contents: { type: 'plain' }, + } } end From 27465a3549217defbf8273f617f868f39bb1e085 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 20 Jul 2019 10:36:39 +0800 Subject: [PATCH 0968/1015] fix es highlight --- app/services/concerns/elasticsearch_able.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/services/concerns/elasticsearch_able.rb b/app/services/concerns/elasticsearch_able.rb index c1640470c..59c2c890b 100644 --- a/app/services/concerns/elasticsearch_able.rb +++ b/app/services/concerns/elasticsearch_able.rb @@ -22,6 +22,8 @@ module ElasticsearchAble fragment_size: EduSetting.get('es_highlight_fragment_size') || 30, tag: '', fields: { + name: { type: 'plain' }, + subject: { type: 'plain' }, challenge_names: { type: 'plain' }, challenge_tag_names: { type: 'plain' }, description: { type: 'plain' }, From 0c91a327ccfc006f197781704d39142a24d37777 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 20 Jul 2019 10:53:55 +0800 Subject: [PATCH 0969/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190720025309_add_ts_mem_for_outputs.rb | 5 +++++ db/migrate/20190720025341_add_ts_time_for_outputs.rb | 5 +++++ 2 files changed, 10 insertions(+) create mode 100644 db/migrate/20190720025309_add_ts_mem_for_outputs.rb create mode 100644 db/migrate/20190720025341_add_ts_time_for_outputs.rb diff --git a/db/migrate/20190720025309_add_ts_mem_for_outputs.rb b/db/migrate/20190720025309_add_ts_mem_for_outputs.rb new file mode 100644 index 000000000..1cf3f3e6f --- /dev/null +++ b/db/migrate/20190720025309_add_ts_mem_for_outputs.rb @@ -0,0 +1,5 @@ +class AddTsMemForOutputs < ActiveRecord::Migration[5.2] + def change + add_column :outputs, :ts_mem, :float + end +end diff --git a/db/migrate/20190720025341_add_ts_time_for_outputs.rb b/db/migrate/20190720025341_add_ts_time_for_outputs.rb new file mode 100644 index 000000000..a5366fbd0 --- /dev/null +++ b/db/migrate/20190720025341_add_ts_time_for_outputs.rb @@ -0,0 +1,5 @@ +class AddTsTimeForOutputs < ActiveRecord::Migration[5.2] + def change + add_column :outputs, :ts_time, :float + end +end From 4d3dbcee4a6ce8605ea065f3f27165923f894b83 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 13:14:55 +0800 Subject: [PATCH 0970/1015] =?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/courses_controller.rb | 1 + app/controllers/shixuns_controller.rb | 1 + app/controllers/subjects_controller.rb | 6 ++++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index a78aa028b..b937d293d 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -60,6 +60,7 @@ class CoursesController < ApplicationController # FROM `course_activities` WHERE course_activities.course_id = courses.id) AS a") # .order("courses.id = 1309 desc, a desc") if @order == "mine" + tip_exception(401, "..") unless current_user.logged? @courses = Course.joins(:course_members) .where("is_delete = 0 AND is_hidden = 0 AND course_members.user_id = ?", @user.id) elsif @order == "created_at" diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index f1e36a5c8..35488ecc5 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -22,6 +22,7 @@ class ShixunsController < ApplicationController ## 我的实训 @shixuns = if params[:order_by] == 'mine' + tip_exception(401, "..") unless current_user.logged? current_user.my_shixuns else Shixun.unhidden diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 7857f2ec6..4d256f3dc 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -37,6 +37,8 @@ class SubjectsController < ApplicationController else # 我的路径 if reorder == "mine" + tip_exception(401, "..") unless current_user.logged? + mine_subject_id = StageShixun.find_by_sql("select DISTINCT(subject_id) from stage_shixuns where shixun_id in (select distinct(shixun_id) from myshixuns where user_id=#{current_user.id})").map(&:subject_id) manage_subject_id = SubjectMember.where(user_id: current_user.id).pluck(:subject_id) @@ -137,7 +139,7 @@ class SubjectsController < ApplicationController if current_user.admin? @shixuns = Shixun.select([:id, :name, :status, :myshixuns_count, :identifier]).where(hidden: 0) else - none_shixun_ids = ShixunSchool.where("school_id != #{current_user.user_extension.try(:school_id)}").pluck(:shixun_id) + none_shixun_ids = ShixunSchool.where("school_id != #{current_user.user_extension.try(:school_id).to_i}").pluck(:shixun_id) @shixuns = Shixun.select([:id, :name, :status, :myshixuns_count, :identifier]).where.not(id: none_shixun_ids).where(hidden: 0) end @@ -174,7 +176,7 @@ class SubjectsController < ApplicationController WHERE m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0").map(&:id) @courses = Course.where(id: course_ids) - @none_shixun_ids = ShixunSchool.where("school_id != #{current_user.user_extension.try(:school_id)}").pluck(:shixun_id) + @none_shixun_ids = ShixunSchool.where("school_id != #{current_user.user_extension.try(:school_id).to_i}").pluck(:shixun_id) end def send_to_course From 47286ba744e683e86646365cb2fab322c65e446e Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 20 Jul 2019 14:28:06 +0800 Subject: [PATCH 0971/1015] log --- app/controllers/shixuns_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 4b1d39245..5cf902e52 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -602,10 +602,10 @@ class ShixunsController < ApplicationController @current_task = myshixun.current_task(myshixun.games) uid_logger("## shixun exec: myshixun id is #{myshixun.id}") - rescue Exception => e - uid_logger_error(e.message) - tip_exception("实训云平台繁忙(繁忙等级:81)") - raise ActiveRecord::Rollback + # rescue Exception => e + # uid_logger_error(e.message) + # tip_exception("实训云平台繁忙(繁忙等级:81)") + # raise ActiveRecord::Rollback end end end From 4a86b86021d5ff2c323b06c8bf24797863b5d5fd Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 14:29:24 +0800 Subject: [PATCH 0972/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E8=AF=BE=E5=A0=82?= =?UTF-8?q?=E5=88=86=E7=8F=ADposition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190720062632_migrate_course_group_position.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 db/migrate/20190720062632_migrate_course_group_position.rb diff --git a/db/migrate/20190720062632_migrate_course_group_position.rb b/db/migrate/20190720062632_migrate_course_group_position.rb new file mode 100644 index 000000000..9b78c2e29 --- /dev/null +++ b/db/migrate/20190720062632_migrate_course_group_position.rb @@ -0,0 +1,11 @@ +class MigrateCourseGroupPosition < ActiveRecord::Migration[5.2] + def change + Course.find_each do |course| + position = 1 + course.course_groups.reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").find_each do |group| + group.update_attribute(:position, position) + position += 1 + end + end + end +end From f91b193f45b5c269bb0449b184f9261337d8c621 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 20 Jul 2019 14:34:34 +0800 Subject: [PATCH 0973/1015] log reset --- app/controllers/shixuns_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 9905d5f76..f5a2436c9 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -603,10 +603,10 @@ class ShixunsController < ApplicationController @current_task = myshixun.current_task(myshixun.games) uid_logger("## shixun exec: myshixun id is #{myshixun.id}") - # rescue Exception => e - # uid_logger_error(e.message) - # tip_exception("实训云平台繁忙(繁忙等级:81)") - # raise ActiveRecord::Rollback + rescue Exception => e + uid_logger_error(e.message) + tip_exception("实训云平台繁忙(繁忙等级:81)") + raise ActiveRecord::Rollback end end end From 0bf237a7ad3934757fa461bf275be24df7636e6d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 20 Jul 2019 14:39:44 +0800 Subject: [PATCH 0974/1015] =?UTF-8?q?vnc=E9=85=8D=E7=BD=AE=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index ec69f3963..10b690d0c 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -69,7 +69,10 @@ class GamesController < ApplicationController if res && res['code'].to_i != 0 raise("实训云平台繁忙(繁忙等级:99)") end - @vnc_url = "http://#{service_host}:#{res['port']}/vnc_lite.html?password=headless" + # 无域名版本 + #@vnc_url = "http://#{service_host}:#{res['port']}/vnc_lite.html?password=headless" + # 有域名版本 + @vnc_url = "http://#{res['port']}.#{service_host}/vnc_lite.html?password=headless" rescue Exception => e Rails.logger.error(e.message) end From 5e484022b384a668b04f9de9a0e314713c918626 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 14:41:11 +0800 Subject: [PATCH 0975/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190720062632_migrate_course_group_position.rb | 11 ----------- .../20190720063520_migrate_course_groups_position.rb | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) delete mode 100644 db/migrate/20190720062632_migrate_course_group_position.rb create mode 100644 db/migrate/20190720063520_migrate_course_groups_position.rb diff --git a/db/migrate/20190720062632_migrate_course_group_position.rb b/db/migrate/20190720062632_migrate_course_group_position.rb deleted file mode 100644 index 9b78c2e29..000000000 --- a/db/migrate/20190720062632_migrate_course_group_position.rb +++ /dev/null @@ -1,11 +0,0 @@ -class MigrateCourseGroupPosition < ActiveRecord::Migration[5.2] - def change - Course.find_each do |course| - position = 1 - course.course_groups.reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").find_each do |group| - group.update_attribute(:position, position) - position += 1 - end - end - end -end diff --git a/db/migrate/20190720063520_migrate_course_groups_position.rb b/db/migrate/20190720063520_migrate_course_groups_position.rb new file mode 100644 index 000000000..dbc38a9b5 --- /dev/null +++ b/db/migrate/20190720063520_migrate_course_groups_position.rb @@ -0,0 +1,11 @@ +class MigrateCourseGroupsPosition < ActiveRecord::Migration[5.2] + def change + Course.find_each do |course| + position = 1 + course.course_groups.unscoped.reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").each do |group| + group.update_attribute(:position, position) + position += 1 + end + end + end +end From 1771ab0870eb3c0a8dd6eab3dc5266cf82777343 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 20 Jul 2019 14:46:11 +0800 Subject: [PATCH 0976/1015] =?UTF-8?q?vnc=E6=94=B9=E6=88=90https?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 10b690d0c..b2f16d570 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -72,7 +72,7 @@ class GamesController < ApplicationController # 无域名版本 #@vnc_url = "http://#{service_host}:#{res['port']}/vnc_lite.html?password=headless" # 有域名版本 - @vnc_url = "http://#{res['port']}.#{service_host}/vnc_lite.html?password=headless" + @vnc_url = "https://#{res['port']}.#{service_host}/vnc_lite.html?password=headless" rescue Exception => e Rails.logger.error(e.message) end From aaf492e34af7d55affed7f290c46c5406fa4b3fd Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 15:18:31 +0800 Subject: [PATCH 0977/1015] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190309085449_migrate_course_members.rb | 2 +- .../20190720063520_migrate_course_groups_position.rb | 11 ----------- 2 files changed, 1 insertion(+), 12 deletions(-) delete mode 100644 db/migrate/20190720063520_migrate_course_groups_position.rb diff --git a/db/migrate/20190309085449_migrate_course_members.rb b/db/migrate/20190309085449_migrate_course_members.rb index 1e4e8c819..a6d049dd7 100644 --- a/db/migrate/20190309085449_migrate_course_members.rb +++ b/db/migrate/20190309085449_migrate_course_members.rb @@ -4,7 +4,7 @@ class MigrateCourseMembers < ActiveRecord::Migration[5.2] Course.find_each do |course| position = 1 - course.course_groups.reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").find_each do |group| + course.course_groups.reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").each do |group| group.update_attribute(:position, position) position += 1 end diff --git a/db/migrate/20190720063520_migrate_course_groups_position.rb b/db/migrate/20190720063520_migrate_course_groups_position.rb deleted file mode 100644 index dbc38a9b5..000000000 --- a/db/migrate/20190720063520_migrate_course_groups_position.rb +++ /dev/null @@ -1,11 +0,0 @@ -class MigrateCourseGroupsPosition < ActiveRecord::Migration[5.2] - def change - Course.find_each do |course| - position = 1 - course.course_groups.unscoped.reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").each do |group| - group.update_attribute(:position, position) - position += 1 - end - end - end -end From 42d6991e6f98cf432127d207849804e5dca922f5 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 20 Jul 2019 15:31:20 +0800 Subject: [PATCH 0978/1015] =?UTF-8?q?=E8=AF=84=E6=B5=8B=E4=B8=AD=E9=97=B4?= =?UTF-8?q?=E5=B1=82=E5=8F=82=E6=95=B0=E7=B1=BB=E5=9E=8B=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index b2f16d570..78b039e69 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -596,7 +596,7 @@ class GamesController < ApplicationController :times => params[:first].to_i, :podType => @shixun.webssh, :content_modified => content_modified, :containers => "#{Base64.urlsafe_encode64(shixun_container_limit(@shixun))}", :persistenceName => @shixun.identifier, :tpmScript => "#{tpmScript}", :sec_key => sec_key, - :timeLimit => "#{game_challenge.exec_time}", :isPublished => (@shixun.status < 2 ? 0 : 1) } + :timeLimit => game_challenge.exec_time, :isPublished => (@shixun.status < 2 ? 0 : 1) } # 评测有文件输出的需要特殊传字段 path:表示文件存储的位置 br_params['file'] = Base64.urlsafe_encode64({path: "#{game_challenge.picture_path}"}.to_json) if game_challenge.picture_path.present? From 60d5c4914aa9ff8c98899ea4e54f596320f7c4e6 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 20 Jul 2019 16:08:11 +0800 Subject: [PATCH 0979/1015] modify ES --- app/services/concerns/elasticsearch_able.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/services/concerns/elasticsearch_able.rb b/app/services/concerns/elasticsearch_able.rb index 59c2c890b..c1640470c 100644 --- a/app/services/concerns/elasticsearch_able.rb +++ b/app/services/concerns/elasticsearch_able.rb @@ -22,8 +22,6 @@ module ElasticsearchAble fragment_size: EduSetting.get('es_highlight_fragment_size') || 30, tag: '', fields: { - name: { type: 'plain' }, - subject: { type: 'plain' }, challenge_names: { type: 'plain' }, challenge_tag_names: { type: 'plain' }, description: { type: 'plain' }, From 7d50b915cb44c6a91a6aa612d613b8ed22278f4d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 16:56:45 +0800 Subject: [PATCH 0980/1015] =?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/graduation_tasks_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index fc9c8df45..6bf3d2f8a 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -78,10 +78,10 @@ class GraduationTasksController < ApplicationController # 教师评阅搜索 0: 未评, 1 已评 unless params[:teacher_comment].blank? graduation_work_ids = GraduationWorkScore.where(graduation_work_id: @work_list.map(&:id)).pluck(:graduation_work_id) - if params[:teacher_comment] == 0 - @work_list = @work_list.where.not(id: graduation_work_ids) - elsif params[:teacher_comment] == 1 - @work_list = @work_list.where(id: graduation_work_ids).where.not(work_status: 0) + if params[:teacher_comment].to_i == 0 + @work_list = @work_list.where("work_status != 0") + elsif params[:teacher_comment].to_i == 1 + @work_list = @work_list.where("work_status != 0").where(id: graduation_work_ids) end end From 3b66d5fc8e5fd4ce7149139e10ad4c6dd3b32f53 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 20 Jul 2019 17:10:43 +0800 Subject: [PATCH 0981/1015] add es queues --- config/sidekiq.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/sidekiq.yml b/config/sidekiq.yml index a2b3fc0be..1c7a4e2cd 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -3,4 +3,5 @@ :logfile: log/sidekiq.log :queues: - [default, 3] + - [searchkick, 10] - [notify, 100] \ No newline at end of file From 7c2644d5fa31b96bbfef59666999e63106108470 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 20 Jul 2019 17:57:16 +0800 Subject: [PATCH 0982/1015] log --- app/controllers/shixuns_controller.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index f5a2436c9..99f6ca405 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -521,6 +521,8 @@ class ShixunsController < ApplicationController min_challenges = @shixun.challenges.pluck(:id , :st) + Rails.logger.info("11111111112#{current_myshixun.try(:id)}") + if current_myshixun games = current_myshixun.games # 如果TPM和TPI的管卡数不相等或者关卡顺序错了,说明实训被极大的改动,需要重置,实训发布前打过的实训都需要重置 @@ -827,5 +829,9 @@ private games.size != min_challenges.size || games.map(&:challenge_id) != min_challenges.map{|challenge| challenge.first} || modify_shixun + + Rails.logger.info("11111111113#{modify_shixun.try(:id)}") + Rails.logger.info("11111111114#{games.map(&:challenge_id) != min_challenges.map{|challenge| challenge.first}}") + Rails.logger.info("11111111115#{games.size != min_challenges.size}") end end From 39e051a9ecf98800e08aaeed23adf00efde8743d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 18:00:06 +0800 Subject: [PATCH 0983/1015] =?UTF-8?q?=E9=87=8D=E7=BD=AE=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 71da15386..324e5bde3 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -110,9 +110,9 @@ class AccountsController < ApplicationController if user.save! sucess_status end - # rescue Exception => e - # uid_logger_error(e.message) - # tip_exception("密码重置失败,请稍后再试") + rescue Exception => e + uid_logger_error(e.message) + tip_exception("密码重置失败") end end From 07e65573c3b0b4f028d57e610dbd5bed6f99c39d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 20 Jul 2019 18:18:56 +0800 Subject: [PATCH 0984/1015] =?UTF-8?q?=E9=9A=90=E8=97=8F=E4=BB=A3=E7=A0=81?= =?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/views/myshixuns/update_file.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/myshixuns/update_file.json.jbuilder b/app/views/myshixuns/update_file.json.jbuilder index ce8426715..f15b07cf8 100644 --- a/app/views/myshixuns/update_file.json.jbuilder +++ b/app/views/myshixuns/update_file.json.jbuilder @@ -1,4 +1,4 @@ json.content @content json.resubmit "#{@resubmit}" json.sec_key "#{@sec_key}" -json.content_modified @hide_code ? false : @content_modified +json.content_modified @hide_code ? 0 : @content_modified From 13a86f7d796d30a809f22601eba38a0ca73cc8f0 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 20 Jul 2019 18:26:02 +0800 Subject: [PATCH 0985/1015] =?UTF-8?q?=E9=87=8D=E7=BD=AE=E8=AF=BB=E5=86=99?= =?UTF-8?q?=E5=88=86=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 99f6ca405..0731207e4 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -522,8 +522,10 @@ class ShixunsController < ApplicationController min_challenges = @shixun.challenges.pluck(:id , :st) Rails.logger.info("11111111112#{current_myshixun.try(:id)}") + Rails.logger.info("111111111102#{params[:reset]}") - if current_myshixun + # 因为读写分离有延迟,所以如果是重置来的请求可以先跳过,重置过来的params[:reset]为1 + if current_myshixun && params[:reset] != 1 games = current_myshixun.games # 如果TPM和TPI的管卡数不相等或者关卡顺序错了,说明实训被极大的改动,需要重置,实训发布前打过的实训都需要重置 if is_shixun_reset?(games, min_challenges, current_myshixun) @@ -829,9 +831,5 @@ private games.size != min_challenges.size || games.map(&:challenge_id) != min_challenges.map{|challenge| challenge.first} || modify_shixun - - Rails.logger.info("11111111113#{modify_shixun.try(:id)}") - Rails.logger.info("11111111114#{games.map(&:challenge_id) != min_challenges.map{|challenge| challenge.first}}") - Rails.logger.info("11111111115#{games.size != min_challenges.size}") end end From 016f4a687e7171126e15cf952fe1445634a36ec9 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 18:30:56 +0800 Subject: [PATCH 0986/1015] =?UTF-8?q?=E9=80=89=E7=94=A8=E5=AE=9E=E8=B7=B5?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 4c3393eaf..3cd4d59d0 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -939,7 +939,8 @@ class HomeworkCommonsController < ApplicationController # 选用实训课程 def subjects @tags = Repertoire.where(nil).order("updated_at desc") - select = params[:select] # 路径导航类型 + # select = params[:select] # 路径导航类型 + select = params[:type] # 路径导航类型 reorder = params[:order] || "myshixun_count" sort = params[:sort] || "desc" search = params[:search] From 6b18c817fbedc73abaf29afad51160038998bb62 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 20 Jul 2019 18:31:30 +0800 Subject: [PATCH 0987/1015] .. --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 0731207e4..572ab525b 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -522,7 +522,7 @@ class ShixunsController < ApplicationController min_challenges = @shixun.challenges.pluck(:id , :st) Rails.logger.info("11111111112#{current_myshixun.try(:id)}") - Rails.logger.info("111111111102#{params[:reset]}") + Rails.logger.info("111111111102#{params[:reset] != 1}") # 因为读写分离有延迟,所以如果是重置来的请求可以先跳过,重置过来的params[:reset]为1 if current_myshixun && params[:reset] != 1 From 1e98d26ed8834f9ecfd1903ae1bce06b8bb2a824 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 18:33:05 +0800 Subject: [PATCH 0988/1015] =?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/homework_commons_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 3cd4d59d0..bab9c285e 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -956,13 +956,13 @@ class HomeworkCommonsController < ApplicationController @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where - subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%' + 'subjects'.'hidden' = 0 AND 'subjects'.'status' = 2 AND 'subjects'.'name' like '%#{search}%' AND `subjects`.`repertoire_id` = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count #{sort}") else @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where - `subjects`.`hidden` = 0 AND `subjects`.`status` = 2 AND `subjects`.`name` like '%#{search}%' + 'subjects'.'hidden' = 0 AND 'subjects'.'status' = 2 AND 'subjects'.'name' like '%#{search}%' GROUP BY subjects.id ORDER BY myshixun_member_count #{sort}") end else From f0b9448dbb7f425c498f2bbef30cfa90f189fceb Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 20 Jul 2019 18:33:33 +0800 Subject: [PATCH 0989/1015] .. --- app/controllers/shixuns_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 572ab525b..14e6217d8 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -525,7 +525,7 @@ class ShixunsController < ApplicationController Rails.logger.info("111111111102#{params[:reset] != 1}") # 因为读写分离有延迟,所以如果是重置来的请求可以先跳过,重置过来的params[:reset]为1 - if current_myshixun && params[:reset] != 1 + if current_myshixun && params[:reset] != "1" games = current_myshixun.games # 如果TPM和TPI的管卡数不相等或者关卡顺序错了,说明实训被极大的改动,需要重置,实训发布前打过的实训都需要重置 if is_shixun_reset?(games, min_challenges, current_myshixun) From 68eb4024bc330b3d59cf3f27c707a2d26e88ca88 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 18:36:21 +0800 Subject: [PATCH 0990/1015] =?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/homework_commons_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index bab9c285e..86546d65c 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -956,13 +956,13 @@ class HomeworkCommonsController < ApplicationController @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where - 'subjects'.'hidden' = 0 AND 'subjects'.'status' = 2 AND 'subjects'.'name' like '%#{search}%' - AND `subjects`.`repertoire_id` = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count #{sort}") + subjects.hidden = 0 AND subjects.status = 2 AND subjects.name like '%#{search}%' + AND subjects.repertoire_id = #{select} GROUP BY subjects.id ORDER BY myshixun_member_count #{sort}") else @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where - 'subjects'.'hidden' = 0 AND 'subjects'.'status' = 2 AND 'subjects'.'name' like '%#{search}%' + subjects.hidden = 0 AND subjects.status = 2 AND subjects.name like '%#{search}%' GROUP BY subjects.id ORDER BY myshixun_member_count #{sort}") end else From 1edc9a98279d48b815ed76dbcfec93dab6afeeae Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 20 Jul 2019 18:39:29 +0800 Subject: [PATCH 0991/1015] =?UTF-8?q?=E9=87=8D=E7=BD=AE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/shixuns_controller.rb | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/app/controllers/shixuns_controller.rb b/app/controllers/shixuns_controller.rb index 14e6217d8..be4448a92 100644 --- a/app/controllers/shixuns_controller.rb +++ b/app/controllers/shixuns_controller.rb @@ -578,19 +578,7 @@ class ShixunsController < ApplicationController onclick_time: Time.now, commit_id: commit_id) uid_logger("myshixun_id is #{myshixun.id}") - # 如果实训是纯选择题,则不需要去fork仓库以及中间层的相关操作了 - unless is_choice_type - # fork仓库 - project_fork(myshixun, @repo_path, current_user.login) - rep_url = Base64.urlsafe_encode64(repo_ip_url @repo_path ) - uid_logger("start openGameInstance") - uri = "#{cloud_bridge}/bridge/game/openGameInstance" - logger.info("end openGameInstance") - params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: myshixun.repo_name.split("/").last} - uid_logger("openGameInstance params is #{params}") - interface_post uri, params, 83, "实训云平台繁忙(繁忙等级:83)" - end # 其它创建关卡等操作 challenges = @shixun.challenges # 之所以增加user_id是为了方便统计查询性能 @@ -605,6 +593,20 @@ class ShixunsController < ApplicationController end end + # 如果实训是纯选择题,则不需要去fork仓库以及中间层的相关操作了 + unless is_choice_type + # fork仓库 + project_fork(myshixun, @repo_path, current_user.login) + + rep_url = Base64.urlsafe_encode64(repo_ip_url @repo_path ) + uid_logger("start openGameInstance") + uri = "#{cloud_bridge}/bridge/game/openGameInstance" + logger.info("end openGameInstance") + params = {tpiID: "#{myshixun.id}", tpmGitURL:rep_url, tpiRepoName: myshixun.repo_name.split("/").last} + uid_logger("openGameInstance params is #{params}") + interface_post uri, params, 83, "实训云平台繁忙(繁忙等级:83)" + end + @current_task = myshixun.current_task(myshixun.games) uid_logger("## shixun exec: myshixun id is #{myshixun.id}") rescue Exception => e From 21778a01b017304d6f0577a406070b33804d13fd Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 18:42:03 +0800 Subject: [PATCH 0992/1015] =?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/application_controller.rb | 4 ++-- app/controllers/homework_commons_controller.rb | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6a7599f28..7b9d622b9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -68,7 +68,7 @@ class ApplicationController < ActionController::Base # 手机类型的发送 sigle_para = {phone: value} status = Educoder::Sms.send(mobile: value, code: code) - tip_exception(code_msg(status)) if status != 0 + tip_exception(-2, code_msg(status)) if status != 0 when 8, 3, 5 # 邮箱类型的发送 sigle_para = {email: value} @@ -77,7 +77,7 @@ class ApplicationController < ActionController::Base # Mailer.run.email_register(code, value) rescue Exception => e logger_error(e) - tip_exception("邮件发送失败,请稍后重试") + tip_exception(-2,"邮件发送失败,请稍后重试") end end ver_params = {code_type: send_type, code: code}.merge(sigle_para) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 86546d65c..1a162795a 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -995,9 +995,11 @@ class HomeworkCommonsController < ApplicationController @subjects = @subjects.page(page).per(limit).includes(:shixuns, user: [user_extension: :school]) else @subjects = @subjects[offset, limit] - subject_ids = @subjects.pluck(:id) - order_ids = subject_ids.size > 0 ? subject_ids.join(',') : -1 - @subjects = Subject.where(id: subject_ids).order("field(id,#{order_ids})").includes(:shixuns, user: [user_extension: :school]) + unless @subjects.blank? + subject_ids = @subjects.pluck(:id) + order_ids = subject_ids.size > 0 ? subject_ids.join(',') : -1 + @subjects = Subject.where(id: subject_ids).order("field(id,#{order_ids})").includes(:shixuns, user: [user_extension: :school]) + end end end From 877ee82230952d542dd5b021299978ec117761b9 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 19:19:59 +0800 Subject: [PATCH 0993/1015] =?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/homework_commons_controller.rb | 1 - app/controllers/zips_controller.rb | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 1a162795a..3cde340c6 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -195,7 +195,6 @@ class HomeworkCommonsController < ApplicationController end if params[:format] == "xlsx" - @work_excel = @work_excel.includes(:student_works_scores, user: :user_extension, myshixun: :games) complete_works = @work_excel.present? ? @work_excel.where("work_status > 0").size : 0 if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 10baf2454..f4822b96b 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -109,11 +109,11 @@ class ZipsController < ApplicationController work_status = params[:work_status] group_id = params[:course_group] - if work_status.present? + unless work_status.blank? @all_student_works = @all_student_works.where(work_status:work_status) end - if group_id.present? + unless group_id.blank? group_user_ids = @course.students.where(course_group_id: params[:course_group]).pluck(:user_id) @all_student_works = @all_student_works.where(user_id: group_user_ids) end From 54f7137886a0bbf5d0b683de4f4bb92ee907b081 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 20:02:43 +0800 Subject: [PATCH 0994/1015] =?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/application_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 7b9d622b9..5666884e9 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -185,7 +185,9 @@ class ApplicationController < ActionController::Base # 系统全局认证 def check_auth - if current_user.certification != 1 + if current_user.certification != 1 && current_user.apply_actions.exists?(container_type: 'TrialAuthorization', status: 0) + tip_exception(-1, "您的试用申请正在审核中,请耐心等待") + elsif current_user.certification != 1 day_cer = UserDayCertification.find_by(user_id: current_user.id) tip_exception(407, "系统未授权") unless (Time.now.to_i - day_cer.try(:created_at).to_i) < 86400 elsif !current_user.profile_completed? From e4a2a896e3c398a293e28e2a1ae19fa9a54469c6 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 20:11:22 +0800 Subject: [PATCH 0995/1015] =?UTF-8?q?=E5=AF=BC=E5=87=BA=E7=9A=84=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 3cde340c6..4685c9f69 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -170,6 +170,7 @@ class HomeworkCommonsController < ApplicationController end @work_count = @student_works.size + @work_excel = @student_works.where("work_status > 0") # 排序 rorder = params[:order].blank? ? "update_time" : params[:order] @@ -180,8 +181,6 @@ class HomeworkCommonsController < ApplicationController @student_works = @student_works.joins(user: :user_extension).order("user_extensions.#{rorder} #{b_order}") end - @work_excel = @student_works - # 分页参数 page = params[:page] || 1 limit = params[:limit] || 20 @@ -195,10 +194,9 @@ class HomeworkCommonsController < ApplicationController end if params[:format] == "xlsx" - complete_works = @work_excel.present? ? @work_excel.where("work_status > 0").size : 0 if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") - elsif complete_works == 0 + elsif @work_excel.size == 0 normal_status(-1,"暂无用户提交!") else respond_to do |format| From 8a70989f7f70e98446c482501a80deca85ce0d17 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 20 Jul 2019 20:23:23 +0800 Subject: [PATCH 0996/1015] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/messages/_message.json.jbuilder | 3 ++- db/migrate/20190720121537_add_is_md_for_messages.rb | 5 +++++ db/migrate/20190720122123_modify_is_md_for_messages.rb | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20190720121537_add_is_md_for_messages.rb create mode 100644 db/migrate/20190720122123_modify_is_md_for_messages.rb diff --git a/app/views/messages/_message.json.jbuilder b/app/views/messages/_message.json.jbuilder index bff2413cd..c3ab6c6e3 100644 --- a/app/views/messages/_message.json.jbuilder +++ b/app/views/messages/_message.json.jbuilder @@ -1 +1,2 @@ -json.extract! message, :id, :parent_id, :subject, :created_on, :total_replies_count, :total_praises_count, :praises_count, :visits, :sticky, :is_hidden, :is_public +json.extract! message, :id, :parent_id, :subject, :created_on, :total_replies_count, :total_praises_count, + :is_md, :praises_count, :visits, :sticky, :is_hidden, :is_public diff --git a/db/migrate/20190720121537_add_is_md_for_messages.rb b/db/migrate/20190720121537_add_is_md_for_messages.rb new file mode 100644 index 000000000..a801fb387 --- /dev/null +++ b/db/migrate/20190720121537_add_is_md_for_messages.rb @@ -0,0 +1,5 @@ +class AddIsMdForMessages < ActiveRecord::Migration[5.2] + def change + add_column :messages, :is_md, :boolean, :default => true + end +end diff --git a/db/migrate/20190720122123_modify_is_md_for_messages.rb b/db/migrate/20190720122123_modify_is_md_for_messages.rb new file mode 100644 index 000000000..4137fc8af --- /dev/null +++ b/db/migrate/20190720122123_modify_is_md_for_messages.rb @@ -0,0 +1,7 @@ +class ModifyIsMdForMessages < ActiveRecord::Migration[5.2] + def change + Message.find_each do |m| + m.update_column(:is_md, false) + end + end +end From 82f2bf1b0b655b1f4a88e6c21acbf0fc5692cd17 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 20 Jul 2019 20:30:55 +0800 Subject: [PATCH 0997/1015] =?UTF-8?q?=E6=9B=B4=E6=96=B0md=E7=9A=84?= =?UTF-8?q?=E8=A1=8C=E4=B8=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/messages_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 5bdc3e053..90da7d8e5 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -102,7 +102,9 @@ class MessagesController < ApplicationController return normal_status(403, "您没有权限进行该操作") if current_user != @message.author && !current_user.teacher_of_course?(@message.board.course) begin - @message.update_attributes(message_params) + h = {is_md: true} + m_params = message_params.merge(h) + @message.update_attributes(m_params) Attachment.associate_container(params[:attachment_ids], @message.id, @message.class.name) @message.update_content(params[:content]) rescue Exception => e From d2c112469f7099c1efb2c63c01c098fd2107c9ea Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 20 Jul 2019 20:31:55 +0800 Subject: [PATCH 0998/1015] =?UTF-8?q?=E7=99=BB=E5=BD=95=E8=A7=84=E8=8C=83?= =?UTF-8?q?=E6=A3=80=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6a7599f28..732ff781c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -46,7 +46,9 @@ class ApplicationController < ActionController::Base # 判断用户的邮箱或者手机是否可用 # params[:type] 1: 注册;2:忘记密码 def check_mail_and_phone_valid login, type - unless login =~ /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/ || login =~ /^1\d{10}$/ + unless login =~ /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/ || login =~ /^1\d{10}$/ || + login =~ /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])$/ +end tip_exception(-2, "请输入正确的手机号或邮箱") end # 考虑到安全参数问题,多一次查询,去掉Union From f9fd499bb0208b1db9d058fba82da49f6571b7e5 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 20:35:00 +0800 Subject: [PATCH 0999/1015] =?UTF-8?q?=E8=AF=95=E7=94=A8=E7=94=B3=E8=AF=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5666884e9..ac08fdf86 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -186,7 +186,7 @@ class ApplicationController < ActionController::Base # 系统全局认证 def check_auth if current_user.certification != 1 && current_user.apply_actions.exists?(container_type: 'TrialAuthorization', status: 0) - tip_exception(-1, "您的试用申请正在审核中,请耐心等待") + tip_exception(408, "您的试用申请正在审核中,请耐心等待") elsif current_user.certification != 1 day_cer = UserDayCertification.find_by(user_id: current_user.id) tip_exception(407, "系统未授权") unless (Time.now.to_i - day_cer.try(:created_at).to_i) < 86400 From b26a9fc03d709a46fa3283d42ef382d274cf5cf3 Mon Sep 17 00:00:00 2001 From: jingquan huang Date: Sat, 20 Jul 2019 20:38:53 +0800 Subject: [PATCH 1000/1015] =?UTF-8?q?=E7=99=BB=E5=BD=95=E7=9A=84=E6=97=B6?= =?UTF-8?q?=E5=80=99=E6=AD=A3=E5=88=99=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 0862892bb..b1c36c7bf 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -48,7 +48,6 @@ class ApplicationController < ActionController::Base def check_mail_and_phone_valid login, type unless login =~ /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/ || login =~ /^1\d{10}$/ || login =~ /^[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])$/ -end tip_exception(-2, "请输入正确的手机号或邮箱") end # 考虑到安全参数问题,多一次查询,去掉Union From 601c9eadf4a88ce83cea7d5692dc7aab08886374 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 20:49:23 +0800 Subject: [PATCH 1001/1015] =?UTF-8?q?=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index a5742494d..cabdcb18e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -80,7 +80,7 @@ Rails.application.routes.draw do resource :email_bind, only: [:create] resource :password, only: [:update] resource :avatar, only: [:update] - resource :auth_attachment, only: [:update] + resource :auth_attachment, only: [:create] resource :authentication_apply, only: [:create] resource :professional_auth_apply, only: [:create] end From 160a5372785c96fba715704e1add97c82d9b6c58 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 20 Jul 2019 21:02:13 +0800 Subject: [PATCH 1002/1015] fix --- app/controllers/users/auth_attachments_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/users/auth_attachments_controller.rb b/app/controllers/users/auth_attachments_controller.rb index 86c3e70ef..98eff078f 100644 --- a/app/controllers/users/auth_attachments_controller.rb +++ b/app/controllers/users/auth_attachments_controller.rb @@ -1,8 +1,8 @@ class Users::AuthAttachmentsController < Users::BaseAccountController before_action :private_user_resources! - before_action :convert_image!, only: [:update] + before_action :convert_image!, only: [:create] - def update + def create image_temp_path = auth_image_path + 'temp' # 上传文件保存至临时文件,提交申请时再移到正常目录 File.delete(image_temp_path) if File.exist?(image_temp_path) # 删除之前的临时文件 From fdb2380face9d956ea273f8b63efa9ef5361fc96 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 21:22:06 +0800 Subject: [PATCH 1003/1015] =?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/homework_commons_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 4685c9f69..8e4b888a1 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -196,7 +196,7 @@ class HomeworkCommonsController < ApplicationController if params[:format] == "xlsx" if @user_course_identity >= Course::STUDENT tip_exception(403, "无权限操作") - elsif @work_excel.size == 0 + elsif @work_excel.blank? || @work_excel.size == 0 normal_status(-1,"暂无用户提交!") else respond_to do |format| From 936f17d76dc634e508235be84fa31dd9f5a4cdfe Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 20 Jul 2019 21:26:17 +0800 Subject: [PATCH 1004/1015] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/application_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5666884e9..cf98f2973 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -221,6 +221,8 @@ class ApplicationController < ActionController::Base User.current = User.find 8686 elsif params[:debug] == 'admin' User.current = User.find 1 + elsif params[:debug] + User.current = User.find_by_login params[:debug] end end From 70b5cc84f506546071aa48f2abe21db633254c8c Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 21:33:43 +0800 Subject: [PATCH 1005/1015] =?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/models/user.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 299ad1ff4..73036c73e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -220,22 +220,22 @@ class User < ApplicationRecord # 课堂的老师(创建者、老师、助教) def teacher_of_course?(course) - course.course_members.exists?(user_id: id, role: [1,2,3], is_active: 1) || admin? + course.course_members.exists?(user_id: id, role: [1,2,3], is_active: 1) || admin? || business? end # 课堂的老师(创建者、老师、助教),不用考虑当前身份 def teacher_of_course_non_active?(course) - course.course_members.exists?(user_id: id, role: [1,2,3]) || admin? + course.course_members.exists?(user_id: id, role: [1,2,3]) || admin? || business? end # 是否是教师,课堂管理员或者超级管理员 def teacher_or_admin?(course) - course.course_members.exists?(user_id: id, role: [1,2], is_active: 1) || admin? + course.course_members.exists?(user_id: id, role: [1,2], is_active: 1) || admin? || business? end # 课堂的创建者(考虑到多重身份的用户) def creator_of_course?(course) - course.course_members.exists?(user_id: id, role: 1, is_active: 1) || admin? + course.course_members.exists?(user_id: id, role: 1, is_active: 1) || admin? || business? end # 课堂的学生 From 5ed17ac14aac6b667737061e585f2bcef02ba1f1 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Sat, 20 Jul 2019 21:47:44 +0800 Subject: [PATCH 1006/1015] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=8A=A5=E5=91=8A?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/student_works_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/student_works_controller.rb b/app/controllers/student_works_controller.rb index 9b32358bd..d12913852 100644 --- a/app/controllers/student_works_controller.rb +++ b/app/controllers/student_works_controller.rb @@ -431,7 +431,7 @@ class StudentWorksController < ApplicationController @user = @work.user @shixun = @homework.shixuns.take # 提示: 这里如果includes outputs表的话: sum(:evaluate_count)会出现错误 - @games = @work.myshixun.games if @work.myshixun + @games = @work.myshixun.games.joins(:challenge).reorder("challenges.position asc") if @work.myshixun # 用户最大评测次数 if @games From a7ab2dde23059e8d9c26386b5202adf69da3f608 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 23:17:20 +0800 Subject: [PATCH 1007/1015] =?UTF-8?q?=E9=99=84=E4=BB=B6=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/attachments_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/attachments_controller.rb b/app/controllers/attachments_controller.rb index 571374468..2efe1df09 100644 --- a/app/controllers/attachments_controller.rb +++ b/app/controllers/attachments_controller.rb @@ -14,7 +14,7 @@ class AttachmentsController < ApplicationController update_downloads(@file) redirect_to @file.cloud_url and return end - send_file absolute_path(local_path(@file)), type: @file.content_type + send_file absolute_path(local_path(@file)), type: @file.content_type.presence || 'application/octet-stream' update_downloads(@file) end From 533755fe155e3c64707b8477c4f4c5433ba770a1 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 23:39:45 +0800 Subject: [PATCH 1008/1015] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E4=B8=87=E8=83=BD?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/accounts_controller.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index 324e5bde3..47349e219 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -32,11 +32,8 @@ class AccountsController < ApplicationController end 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" - return normal_status(-2, "验证码不正确") if verifi_code.try(:code) != code.strip - return normal_status(-2, "验证码已失效") if !verifi_code&.effective? - end + return normal_status(-2, "验证码不正确") if verifi_code.try(:code) != code.strip + return normal_status(-2, "验证码已失效") if !verifi_code&.effective? code = generate_identifier User, 8 login = pre + code From c65475b199781b5a948cbfb200853d1c2047087d Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Sat, 20 Jul 2019 23:47:30 +0800 Subject: [PATCH 1009/1015] =?UTF-8?q?=E9=80=89=E7=94=A8=E5=AE=9E=E8=B7=B5?= =?UTF-8?q?=E8=AF=BE=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/homework_commons_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 8e4b888a1..052db3e4f 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -949,7 +949,7 @@ class HomeworkCommonsController < ApplicationController # 最热排序 if reorder == "myshixun_count" - if select + if select && select != "all" @subjects = Subject.find_by_sql("SELECT subjects.id, subjects.user_id, subjects.name, subjects.stages_count, subjects.repertoire_id, subjects.status, subjects.shixuns_count, sum(shixuns.myshixuns_count) AS myshixun_member_count FROM subjects join stage_shixuns on stage_shixuns.subject_id = subjects.id join shixuns on shixuns.id = stage_shixuns.shixun_id where @@ -973,7 +973,7 @@ class HomeworkCommonsController < ApplicationController end # 类型 - if select + if select && select != "all" @subjects = @subjects.where(repertoire_id: select) end From ce8f6273b7efa4afb152771791bbfd0a900b8637 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 22 Jul 2019 09:46:20 +0800 Subject: [PATCH 1010/1015] =?UTF-8?q?rep=5Fcontent=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 +- app/views/homework_commons/group_list.json.jbuilder | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 78b039e69..66fc4e0bd 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -541,7 +541,7 @@ class GamesController < ApplicationController end end # 有异常了,立即重试 - tip_exception(-4, e.message) + tip_exception(e.message) end end diff --git a/app/views/homework_commons/group_list.json.jbuilder b/app/views/homework_commons/group_list.json.jbuilder index 0108e5534..b5fead17e 100644 --- a/app/views/homework_commons/group_list.json.jbuilder +++ b/app/views/homework_commons/group_list.json.jbuilder @@ -7,7 +7,7 @@ json.group_list do end end # 未分班展示情况放在最后 -if @course_groups.count > 0 && @course_groups.count < @limit.to_i +if @course_groups.count != (@page -1)*@limit.to_i && @course_groups.count < @limit.to_i ungroup_work_count = homework_ungroup_works_count(@homework, @ungroup_user_ids) if ungroup_work_count > 0 json.ungroup_list do From 99d8592e4f3a88d58b0538e389fc7586f4cfc059 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 22 Jul 2019 09:46:50 +0800 Subject: [PATCH 1011/1015] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 66fc4e0bd..556423ba0 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -540,8 +540,8 @@ class GamesController < ApplicationController end end end - # 有异常了,立即重试 - tip_exception(e.message) + # 有异常,版本库获取不到代码,前端轮训 + tip_exception(0, e.message) end end From 13c0d273929c11f6b53336b5c52be3ef72a7707a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 22 Jul 2019 09:53:27 +0800 Subject: [PATCH 1012/1015] 1 --- app/controllers/games_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index 556423ba0..e6a592f51 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -540,7 +540,7 @@ class GamesController < ApplicationController end end end - # 有异常,版本库获取不到代码,前端轮训 + # 有异常,版本库获取不到代码,前端轮训30S后,调用retry == 1 tip_exception(0, e.message) end end From 0719eea4ec6fd65f3f7d14dcb792457887b94689 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 22 Jul 2019 09:59:29 +0800 Subject: [PATCH 1013/1015] =?UTF-8?q?homework=5Fcommon=20=E5=AF=BC?= =?UTF-8?q?=E5=87=BAzip=E7=9A=84=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/graduation_tasks_controller.rb | 2 +- app/controllers/homework_commons_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 6bf3d2f8a..8ee803609 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -156,7 +156,7 @@ class GraduationTasksController < ApplicationController } end else - tip_exception(status == -2 ? "500M" : "无附件可下载") + normal_status(status == -2 ? "500M" : "无附件可下载") end end end diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 052db3e4f..0d30056ac 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -228,7 +228,7 @@ class HomeworkCommonsController < ApplicationController } end else - tip_exception(status == -2 ? "500M" : "无附件可下载") + normal_status(status == -2 ? "500M" : "无附件可下载") end end end From 2719cf29f3219f3d835c57f68d4824f4ee082966 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Mon, 22 Jul 2019 10:10:15 +0800 Subject: [PATCH 1014/1015] =?UTF-8?q?issue=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 6 +++--- app/controllers/graduation_tasks_controller.rb | 2 +- app/controllers/homework_commons_controller.rb | 2 +- app/views/users/courses/shared/_course.json.jbuilder | 6 ++++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index b937d293d..1cee38816 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -62,13 +62,13 @@ class CoursesController < ApplicationController if @order == "mine" tip_exception(401, "..") unless current_user.logged? @courses = Course.joins(:course_members) - .where("is_delete = 0 AND is_hidden = 0 AND course_members.user_id = ?", @user.id) + .where("is_delete = 0 AND is_hidden = 0 AND course_members.user_id = ?", @user.id).distinct elsif @order == "created_at" # REDO:Extension - @courses = Course.where(is_delete: 0, is_hidden: 0, is_end: 0) + @courses = Course.where(is_delete: 0, is_hidden: 0, is_end: 0).distinct else # REDO:Extension - @courses = Course.where(is_delete: 0, is_hidden: 0) + @courses = Course.where(is_delete: 0, is_hidden: 0).distinct end # 根据搜索关键字进一步筛选 diff --git a/app/controllers/graduation_tasks_controller.rb b/app/controllers/graduation_tasks_controller.rb index 8ee803609..ab99e8d86 100644 --- a/app/controllers/graduation_tasks_controller.rb +++ b/app/controllers/graduation_tasks_controller.rb @@ -156,7 +156,7 @@ class GraduationTasksController < ApplicationController } end else - normal_status(status == -2 ? "500M" : "无附件可下载") + normal_status(status,status == -2 ? "500M" : "无附件可下载") end end end diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 0d30056ac..8fab8dad3 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -228,7 +228,7 @@ class HomeworkCommonsController < ApplicationController } end else - normal_status(status == -2 ? "500M" : "无附件可下载") + normal_status(status, status == -2 ? "500M" : "无附件可下载") end end end diff --git a/app/views/users/courses/shared/_course.json.jbuilder b/app/views/users/courses/shared/_course.json.jbuilder index 629f47264..e917033da 100644 --- a/app/views/users/courses/shared/_course.json.jbuilder +++ b/app/views/users/courses/shared/_course.json.jbuilder @@ -1,7 +1,9 @@ json.id course.id json.name course.name -json.members_count course.members_count -json.homework_commons_count course.homework_commons_count +# json.members_count course.members_count +json.members_count course.course_members_count +# json.homework_commons_count course.homework_commons_count +json.homework_commons_count get_tasks_count course json.attachments_count course.attachments.count json.first_category_url module_url(course.course_modules.where(hidden: 0).order(position: :desc).first, course) From 41723f477f1d64867ae6105de3f3286af061b8a7 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 22 Jul 2019 10:26:49 +0800 Subject: [PATCH 1015/1015] =?UTF-8?q?=E8=AE=A8=E8=AE=BA=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/messages/index.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/messages/index.json.jbuilder b/app/views/messages/index.json.jbuilder index 60d35e769..3470ed485 100644 --- a/app/views/messages/index.json.jbuilder +++ b/app/views/messages/index.json.jbuilder @@ -11,7 +11,7 @@ json.data do json.total_praises_count @praises_count_map.fetch(message.id, 0) - json.partial! "messages/message", message: message + #json.partial! "messages/message", message: message json.author do json.partial! "users/user_simple", user: message.author end