From e6999da273e6b1850297ec1504d6bc16b6aed3e2 Mon Sep 17 00:00:00 2001 From: p31729568 Date: Sat, 6 Jul 2019 09:19:47 +0800 Subject: [PATCH 01/89] 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 02/89] =?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 03/89] =?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 04/89] 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 05/89] 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 06/89] 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 07/89] =?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 08/89] 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 09/89] 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 10/89] 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 11/89] =?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 12/89] =?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 13/89] =?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 14/89] 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 15/89] =?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 16/89] 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 17/89] =?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 18/89] =?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 19/89] =?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 20/89] =?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 21/89] 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 22/89] =?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 23/89] 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 24/89] 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 25/89] 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 26/89] 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 27/89] =?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 28/89] =?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 29/89] =?UTF-8?q?run=5Fcode=5Fmessages=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=B4=A2=E5=BC=95=E6=8F=90=E9=AB=98=E6=9F=A5=E8=AF=A2=E9=80=9F?= =?UTF-8?q?=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 30/89] =?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 31/89] =?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 32/89] =?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 33/89] =?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 34/89] =?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 35/89] =?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 36/89] =?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 37/89] =?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 38/89] 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 39/89] =?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 40/89] =?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 41/89] =?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 42/89] =?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 43/89] =?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 44/89] =?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 45/89] =?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 952221970b9663edddf1c65542fe945ca362587a Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 9 Jul 2019 11:38:19 +0800 Subject: [PATCH 46/89] =?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 47/89] =?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 48/89] 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 0366af3a88f0176f2eafb8e460ad5999a912fa66 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 9 Jul 2019 15:07:57 +0800 Subject: [PATCH 49/89] =?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 50/89] 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 51/89] =?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 8bee375b67a224e583b9cfe56507ee1fea7684f8 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 9 Jul 2019 17:20:11 +0800 Subject: [PATCH 52/89] =?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 53/89] 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 54/89] =?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 55/89] 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 56/89] =?UTF-8?q?=E4=BF=AE=E6=94=B9xlsx=E7=9A=84=E6=A0=B7?= =?UTF-8?q?=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 57/89] 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 58/89] 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 59/89] 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 60/89] =?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 e1864ea2f5fb92b75f35410afb2bb84deadbed25 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Wed, 10 Jul 2019 10:45:56 +0800 Subject: [PATCH 61/89] =?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 62/89] =?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 63/89] =?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 64/89] =?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 65/89] =?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 66/89] =?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 67/89] =?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 68/89] =?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 69/89] =?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 70/89] =?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 71/89] =?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 72/89] 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 73/89] 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 74/89] =?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 75/89] =?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 76/89] =?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 77/89] =?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 78/89] =?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 79/89] =?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 80/89] =?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 81/89] =?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 82/89] =?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 83/89] =?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 84/89] =?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 85/89] =?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 86/89] =?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 87/89] =?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 88/89] =?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 89/89] =?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,