From 234cdbeab907804f42b9a358fd356a30c1f6779d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 09:28:37 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E7=82=B9=E8=B5=9E?= =?UTF-8?q?=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0190705011739_add_praises_count_for_challenges.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 db/migrate/20190705011739_add_praises_count_for_challenges.rb diff --git a/db/migrate/20190705011739_add_praises_count_for_challenges.rb b/db/migrate/20190705011739_add_praises_count_for_challenges.rb new file mode 100644 index 000000000..6455f1f10 --- /dev/null +++ b/db/migrate/20190705011739_add_praises_count_for_challenges.rb @@ -0,0 +1,12 @@ +class AddPraisesCountForChallenges < ActiveRecord::Migration[5.2] + def change + add_column :challenges, :praises_count, :integer, :default => 0 + + challenges = Challenge.where(nil) + challenges.each do |c| + praises_count = c.praise_tread.where(praise_or_tread: 1).count + c.update_column(:praises_count, praises_count) + end + + end +end From fbcf9b77f53245d163aec43c78076422308d443f Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 09:32:29 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190705011739_add_praises_count_for_challenges.rb | 9 +-------- ...20190705013203_modify_praises_count_for_challenges.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 db/migrate/20190705013203_modify_praises_count_for_challenges.rb diff --git a/db/migrate/20190705011739_add_praises_count_for_challenges.rb b/db/migrate/20190705011739_add_praises_count_for_challenges.rb index 6455f1f10..2bf246277 100644 --- a/db/migrate/20190705011739_add_praises_count_for_challenges.rb +++ b/db/migrate/20190705011739_add_praises_count_for_challenges.rb @@ -1,12 +1,5 @@ class AddPraisesCountForChallenges < ActiveRecord::Migration[5.2] def change - add_column :challenges, :praises_count, :integer, :default => 0 - - challenges = Challenge.where(nil) - challenges.each do |c| - praises_count = c.praise_tread.where(praise_or_tread: 1).count - c.update_column(:praises_count, praises_count) - end - + #add_column :challenges, :praises_count, :integer, :default => 0 end end diff --git a/db/migrate/20190705013203_modify_praises_count_for_challenges.rb b/db/migrate/20190705013203_modify_praises_count_for_challenges.rb new file mode 100644 index 000000000..d2441d948 --- /dev/null +++ b/db/migrate/20190705013203_modify_praises_count_for_challenges.rb @@ -0,0 +1,9 @@ +class ModifyPraisesCountForChallenges < ActiveRecord::Migration[5.2] + def change + challenges = Challenge.where(nil) + challenges.each do |c| + praises_count = c.praise_tread.where(praise_or_tread: 1).count + c.update_column(:praises_count, praises_count) + end + end +end From 6f1d84eecc41ef8cf4c6529d0f60c9e4009c39b1 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 09:34:32 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/migrate/20190705011739_add_praises_count_for_challenges.rb | 2 +- .../20190705013203_modify_praises_count_for_challenges.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/db/migrate/20190705011739_add_praises_count_for_challenges.rb b/db/migrate/20190705011739_add_praises_count_for_challenges.rb index 2bf246277..6ae1d8420 100644 --- a/db/migrate/20190705011739_add_praises_count_for_challenges.rb +++ b/db/migrate/20190705011739_add_praises_count_for_challenges.rb @@ -1,5 +1,5 @@ class AddPraisesCountForChallenges < ActiveRecord::Migration[5.2] def change - #add_column :challenges, :praises_count, :integer, :default => 0 + add_column :challenges, :praises_count, :integer, :default => 0 end end diff --git a/db/migrate/20190705013203_modify_praises_count_for_challenges.rb b/db/migrate/20190705013203_modify_praises_count_for_challenges.rb index d2441d948..35711027a 100644 --- a/db/migrate/20190705013203_modify_praises_count_for_challenges.rb +++ b/db/migrate/20190705013203_modify_praises_count_for_challenges.rb @@ -1,7 +1,7 @@ class ModifyPraisesCountForChallenges < ActiveRecord::Migration[5.2] def change - challenges = Challenge.where(nil) - challenges.each do |c| + challenges = Challenge.where(nil).unscope + challenges.find_each do |c| praises_count = c.praise_tread.where(praise_or_tread: 1).count c.update_column(:praises_count, praises_count) end From f0b6c04e5fa9c2a958fc1e2ec7a970c36f66fdb4 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 09:36:27 +0800 Subject: [PATCH 04/10] =?UTF-8?q?=E8=BF=81=E7=A7=BB=E7=82=B9=E8=B5=9E?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...rb => 20190705013204_modify_praises_count_for_challenges.rb} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename db/migrate/{20190705013203_modify_praises_count_for_challenges.rb => 20190705013204_modify_praises_count_for_challenges.rb} (84%) diff --git a/db/migrate/20190705013203_modify_praises_count_for_challenges.rb b/db/migrate/20190705013204_modify_praises_count_for_challenges.rb similarity index 84% rename from db/migrate/20190705013203_modify_praises_count_for_challenges.rb rename to db/migrate/20190705013204_modify_praises_count_for_challenges.rb index 35711027a..4cf975f3d 100644 --- a/db/migrate/20190705013203_modify_praises_count_for_challenges.rb +++ b/db/migrate/20190705013204_modify_praises_count_for_challenges.rb @@ -1,6 +1,6 @@ class ModifyPraisesCountForChallenges < ActiveRecord::Migration[5.2] def change - challenges = Challenge.where(nil).unscope + challenges = Challenge.where(nil).unscoped challenges.find_each do |c| praises_count = c.praise_tread.where(praise_or_tread: 1).count c.update_column(:praises_count, praises_count) From 3d7284525f64849b7f8364c0fbf0f5165cfe4987 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 09:53:23 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E7=82=B9=E8=B5=9E=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index ea09b9003..e54d5c34f 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -40,10 +40,8 @@ class GamesController < ApplicationController next_game = @game.next_of_current_game(@shixun.id, @game.myshixun_id, game_challenge.position) # 关卡点赞数, praise_or_tread = 1则表示赞过 - praise_count = PraiseTread.where(praise_tread_object_id: game_challenge.id, praise_tread_object_type: "Challenge", - praise_or_tread: 1).count - user_praise = PraiseTread.where(praise_tread_object_id: game_challenge.id, praise_tread_object_type: "Challenge", - user_id: current_user.id, praise_or_tread: 1).present? ? true : false + praise_count = game_challenge.praises_count + user_praise = game_challenge.praise_tread.exists?(user_id:current_user.id, praise_or_tread: 1) # 实训的最大评测次数,这个值是为了优化查询,每次只取最新的最新一次评测的结果集 max_query_index = @game.query_index.to_i From db69b3737c93c98ca962672e12e42a6029c54dea Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 09:55:30 +0800 Subject: [PATCH 06/10] =?UTF-8?q?TPI=E7=82=B9=E8=B5=9E=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/challenge.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/challenge.rb b/app/models/challenge.rb index a4fd71830..e4524a69a 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -20,7 +20,7 @@ class Challenge < ApplicationRecord # acts_as_attachable scope :base_attrs, -> { select([:id, :subject, :position, :shixun_id, :st, :score, :path, :task_pass, :modify_time, - :web_route, :answer, :exec_time]) } + :web_route, :answer, :exec_time, :praises_count]) } scope :choose_type, -> { where(st: 1) } scope :practice_type, -> { where(st: 0) } From 7d81be96a5b6f00b06f58228a409fed174109dfe Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 09:57:38 +0800 Subject: [PATCH 07/10] =?UTF-8?q?zip=E5=AF=BC=E5=87=BA=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/exercises_controller.rb | 4 +- app/controllers/zips_controller.rb | 61 ++++++++++--------- .../batch_export_shixun_report_service.rb | 14 +---- 3 files changed, 36 insertions(+), 43 deletions(-) diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 07113792d..e6f9876bc 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -1300,7 +1300,9 @@ class ExercisesController < ApplicationController if params[:format] == "xlsx" if @user_course_identity > Course::ASSISTANT_PROFESSOR tip_exception(403,"无权限操作") - elsif (@exercise_status == 1) || (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) + elsif @exercise_status == 1 + normal_status(-1,"试卷未发布") + elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) normal_status(-1,"暂无用户提交") else respond_to do |format| diff --git a/app/controllers/zips_controller.rb b/app/controllers/zips_controller.rb index 8553cbb44..4089e5231 100644 --- a/app/controllers/zips_controller.rb +++ b/app/controllers/zips_controller.rb @@ -6,12 +6,9 @@ class ZipsController < ApplicationController before_action :require_admin_or_teacher def shixun_report - # student_work_ids = Array.wrap(params[:student_work_ids]) - # service = BatchExportShixunReportService.new(@homework, @student_work_ids) service = BatchExportShixunReportService.new(@homework, @all_student_works) - filename = filename_for_content_disposition(service.filename) send_file service.zip, filename: filename, type: 'application/zip' rescue BatchExportShixunReportService::Error => ex @@ -23,8 +20,8 @@ class ZipsController < ApplicationController exercises = ExportExercisesService.new(@exercise,@ex_users,@request_url) file_name = filename_for_content_disposition(exercises.filename) - send_file exercises.ex_zip, filename: file_name, type: 'application/zip' + send_file exercises.ex_zip, filename: file_name, type: 'application/zip' rescue Exception => e normal_status(-1, e.message) end @@ -44,7 +41,7 @@ class ZipsController < ApplicationController ActiveRecord::Base.transaction do begin @exercise = Exercise.includes(:exercise_users,:exercise_questions).find_by(id:params[:exercise_id]) - @exercise_status = @exercise.get_exercise_status(current_user.id) + @exercise_status = @exercise.present? ? @exercise.get_exercise_status(current_user.id) : 1 group_id = params[:exercise_group_id] if @exercise.blank? normal_status(-1,"试卷不存在") @@ -101,34 +98,40 @@ class ZipsController < ApplicationController def load_homework @homework = HomeworkCommon.find(params[:homework_common_id]) + @homework_status = @homework.present? ? @homework.homework_detail_manual.comment_status : 0 + if @homework.blank? + normal_status(-1,"该作业不存在") + elsif @homework_status == 0 + normal_status(-1,"该作业未发布") + else + @course = @homework.course + ##7。2 -hs新增 + @member = @course.course_member(current_user.id) + + @all_student_works = @homework.teacher_works(@member).where("work_status > 0") + work_status = params[:work_status] + group_id = params[:course_group] + + if work_status.present? + @all_student_works = @all_student_works.where(work_status:work_status) + end + if group_id.present? + group_user_ids = @course.students.where(course_group_id: params[:course_group]).pluck(:user_id) + @all_student_works = @all_student_works.where(user_id: group_user_ids) + end - @course = @homework.course - ##7。2 -hs新增 - @member = @course.course_member(current_user.id) - @all_student_works = @homework.teacher_works(@member).where("work_status > 0") - work_status = params[:work_status] - group_id = params[:course_group] - - if work_status.present? - @all_student_works = @all_student_works.where(work_status:work_status) - end - - if group_id.present? - group_user_ids = @course.students.where(course_group_id: params[:course_group]).pluck(:user_id) - @all_student_works = @all_student_works.where(user_id: group_user_ids) - end - - unless params[:search].blank? - @all_student_works = @all_student_works.joins(user: :user_extension).where("concat(lastname, firstname) like ? + unless params[:search].blank? + @all_student_works = @all_student_works.joins(user: :user_extension).where("concat(lastname, firstname) like ? or student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%") - end + end - student_work_sizes = @all_student_works&.size - if student_work_sizes.blank? || student_work_sizes == 0 - normal_status(-1,"暂无用户提交") - elsif student_work_sizes > 100 - normal_status(-2,"100") + student_work_sizes = @all_student_works&.size + if student_work_sizes.blank? || student_work_sizes == 0 + normal_status(-1,"暂无用户提交") + elsif student_work_sizes > 100 + normal_status(-2,"100") + end end end end diff --git a/app/services/batch_export_shixun_report_service.rb b/app/services/batch_export_shixun_report_service.rb index ebb273a87..90c8fb2af 100644 --- a/app/services/batch_export_shixun_report_service.rb +++ b/app/services/batch_export_shixun_report_service.rb @@ -3,7 +3,6 @@ class BatchExportShixunReportService MAX_BATCH_LIMIT = 20 - # attr_reader :homework, :student_work_ids attr_reader :homework, :all_student_works @@ -15,7 +14,7 @@ class BatchExportShixunReportService end def filename - @_filename ||= "#{Time.now.strftime('%Y%m%d%H%M%S')}-#{homework.name}.zip" + @_filename ||= "#{homework.name}-#{Time.now.strftime('%Y%m%d%H%M%S')}.zip" end def zip @@ -45,15 +44,4 @@ class BatchExportShixunReportService end end - # private - # - # def validate! - # if student_work_ids.size.zero? - # raise Error, '请选择学生实训作业' - # end - # - # if student_work_ids.size > MAX_BATCH_LIMIT - # raise Error, '导出实训报告太多,请分批导出' - # end - # end end From 155e9a0a37b635a7d99e8d616ecae257d90a611a Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 10:40:16 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E7=82=B9=E8=B5=9E?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/discusses_controller.rb | 4 ++-- app/models/challenge.rb | 2 +- app/models/discuss.rb | 2 +- app/services/shixuns_service.rb | 10 +++++----- app/views/discusses/_discuss.json.jbuilder | 4 ++-- ...190705013204_modify_praises_count_for_challenges.rb | 2 +- .../20190705022502_add_praises_count_for_discuess.rb | 5 +++++ ...20190705022737_modify_praises_count_for_discuess.rb | 9 +++++++++ 8 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 db/migrate/20190705022502_add_praises_count_for_discuess.rb create mode 100644 db/migrate/20190705022737_modify_praises_count_for_discuess.rb diff --git a/app/controllers/discusses_controller.rb b/app/controllers/discusses_controller.rb index 1d3b524f4..db3047e74 100644 --- a/app/controllers/discusses_controller.rb +++ b/app/controllers/discusses_controller.rb @@ -10,13 +10,13 @@ class DiscussesController < ApplicationController if current_user.admin? @disscuss_count = Discuss.where(:dis_id => @container.id, :dis_type => @container.class.to_s, :root_id => nil).count @discusses = Discuss.limit(LIMIT).where(:dis_id => @container.id, :dis_type => @container.class.to_s, - :root_id => nil).includes(:user, :praise_tread).offset(offset) + :root_id => nil).includes(:user, :praise_treads).offset(offset) else disscusses = Discuss.where("dis_id = :dis_id and dis_type = :dis_type and root_id is null and (hidden = :hidden or user_id = :user_id)", {dis_id: @container.id, dis_type: @container.class.to_s, hidden: false, user_id: current_user.id}) @disscuss_count = disscusses.count - @discusses = disscusses.limit(LIMIT).includes(:user, :praise_tread).offset(offset) + @discusses = disscusses.limit(LIMIT).includes(:user, :praise_treads).offset(offset) end @current_user = current_user diff --git a/app/models/challenge.rb b/app/models/challenge.rb index e4524a69a..7afb919a0 100644 --- a/app/models/challenge.rb +++ b/app/models/challenge.rb @@ -10,7 +10,7 @@ class Challenge < ApplicationRecord has_many :games, :dependent => :destroy has_many :challenge_chooses, :dependent => :destroy has_many :homework_challenge_settings, :dependent => :destroy - has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_many :praise_treads, as: :praise_tread_object, dependent: :destroy has_one :praise_tread_cache, as: :object, dependent: :destroy has_many :tidings # 参考答案 diff --git a/app/models/discuss.rb b/app/models/discuss.rb index 93f0d62cd..737a89ec1 100644 --- a/app/models/discuss.rb +++ b/app/models/discuss.rb @@ -5,7 +5,7 @@ class Discuss < ApplicationRecord belongs_to :parent, class_name: 'Discuss', foreign_key: :parent_id, optional: true has_many :children, -> { reorder(created_at: :asc) }, class_name: 'Discuss', foreign_key: :parent_id - has_many :praise_tread, as: :praise_tread_object, dependent: :destroy + has_many :praise_treads, as: :praise_tread_object, dependent: :destroy has_many :tidings, as: :container, dependent: :destroy has_one :praise_tread_cache, as: :object, dependent: :destroy diff --git a/app/services/shixuns_service.rb b/app/services/shixuns_service.rb index 83d61b352..4efefd4c2 100644 --- a/app/services/shixuns_service.rb +++ b/app/services/shixuns_service.rb @@ -47,7 +47,7 @@ class ShixunsService if current_user.admin? disscuss_count = Discuss.where(dis_id: dis_id, dis_type: dis_type, root_id: nil).count discusses = Discuss.where(dis_id: dis_id, dis_type: dis_type, root_id: nil) - .includes(:user, :praise_tread).limit(LIMIT).offset(offset) + .includes(:user, :praise_treads).limit(LIMIT).offset(offset) else disscusses = Discuss.where( 'dis_id = :dis_id and dis_type = :dis_type and root_id is null and (hidden = :hidden or user_id = :user_id)', @@ -55,7 +55,7 @@ class ShixunsService ) disscuss_count = disscusses.count - discusses = disscusses.includes(:user, :praise_tread).limit(LIMIT).offset(offset) + discusses = disscusses.includes(:user, :praise_treads).limit(LIMIT).offset(offset) end base_data discusses, dis, current_user @@ -81,7 +81,7 @@ class ShixunsService offset = page * LIMIT find_status = true if position end - discusses = Discuss.limit(LIMIT).where(:dis_id => dis_id, :dis_type => dis_type, :root_id => nil).includes(:user, :praise_tread).offset(offset) + discusses = Discuss.limit(LIMIT).where(:dis_id => dis_id, :dis_type => dis_type, :root_id => nil).includes(:user, :praise_treads).offset(offset) base_data discusses, dis, current_user Myshixun.find(params[:myshixun_id]).update_attribute(:onclick_time, Time.now) @@ -109,8 +109,8 @@ class ShixunsService if discusses.present? discusses.each do |d| # 总点赞数 - praise_count = d.praise_tread.where(:praise_or_tread => 1).count - user_praise= d.praise_tread.select{|pt| pt.user_id == current_user.id}.length > 0 ? true : false + praise_count = d.praises_count + user_praise= d.praise_treads.select{|pt| pt.user_id == current_user.id}.length > 0 ? true : false manager = current_user.manager_of_shixun?(dis, current_user) game_url = if manager diff --git a/app/views/discusses/_discuss.json.jbuilder b/app/views/discusses/_discuss.json.jbuilder index e7e6e425f..992466559 100644 --- a/app/views/discusses/_discuss.json.jbuilder +++ b/app/views/discusses/_discuss.json.jbuilder @@ -14,8 +14,8 @@ json.game_url discuss.game_url(container, current_user) if discuss.parent_id json.can_delete discuss.can_deleted?(current_user) else - json.praise_count discuss.praise_tread.where(praise_or_tread: 1).count - json.user_praise discuss.praise_tread.select{|pt| pt.user_id == current_user.id}.length > 0 ? true : false + json.praise_count discuss.praises_count + json.user_praise discuss.praise_treads.select{|pt| pt.user_id == current_user.id}.length > 0 end diff --git a/db/migrate/20190705013204_modify_praises_count_for_challenges.rb b/db/migrate/20190705013204_modify_praises_count_for_challenges.rb index 4cf975f3d..59aa6ca53 100644 --- a/db/migrate/20190705013204_modify_praises_count_for_challenges.rb +++ b/db/migrate/20190705013204_modify_praises_count_for_challenges.rb @@ -2,7 +2,7 @@ class ModifyPraisesCountForChallenges < ActiveRecord::Migration[5.2] def change challenges = Challenge.where(nil).unscoped challenges.find_each do |c| - praises_count = c.praise_tread.where(praise_or_tread: 1).count + praises_count = c.praise_treads.where(praise_or_tread: 1).count c.update_column(:praises_count, praises_count) end end diff --git a/db/migrate/20190705022502_add_praises_count_for_discuess.rb b/db/migrate/20190705022502_add_praises_count_for_discuess.rb new file mode 100644 index 000000000..47fd5ec1a --- /dev/null +++ b/db/migrate/20190705022502_add_praises_count_for_discuess.rb @@ -0,0 +1,5 @@ +class AddPraisesCountForDiscuess < ActiveRecord::Migration[5.2] + def change + add_column :discusses, :praises_count, :integer, :default => 0 + end +end diff --git a/db/migrate/20190705022737_modify_praises_count_for_discuess.rb b/db/migrate/20190705022737_modify_praises_count_for_discuess.rb new file mode 100644 index 000000000..4d5b6ca97 --- /dev/null +++ b/db/migrate/20190705022737_modify_praises_count_for_discuess.rb @@ -0,0 +1,9 @@ +class ModifyPraisesCountForDiscuess < ActiveRecord::Migration[5.2] + def change + discusses = Discuss.includes(:praise_treads).unscoped + discusses.find_each do |d| + praises_count = d.praise_treads.liker.count + d.update_column(:praises_count, praises_count) + end + end +end From 5666a3564e5199b2ac84a2110eb6c11cdcc0390d Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Fri, 5 Jul 2019 10:41:38 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E7=82=B9=E8=B5=9E=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/games_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/games_controller.rb b/app/controllers/games_controller.rb index e54d5c34f..c36be012f 100644 --- a/app/controllers/games_controller.rb +++ b/app/controllers/games_controller.rb @@ -41,7 +41,7 @@ class GamesController < ApplicationController # 关卡点赞数, praise_or_tread = 1则表示赞过 praise_count = game_challenge.praises_count - user_praise = game_challenge.praise_tread.exists?(user_id:current_user.id, praise_or_tread: 1) + user_praise = game_challenge.praise_treads.exists?(user_id:current_user.id, praise_or_tread: 1) # 实训的最大评测次数,这个值是为了优化查询,每次只取最新的最新一次评测的结果集 max_query_index = @game.query_index.to_i From 20657ff933180557e7d20eb746c6a45bda9e4662 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Fri, 5 Jul 2019 10:47:15 +0800 Subject: [PATCH 10/10] fix bug --- app/services/batch_export_shixun_report_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/batch_export_shixun_report_service.rb b/app/services/batch_export_shixun_report_service.rb index 90c8fb2af..2c294395d 100644 --- a/app/services/batch_export_shixun_report_service.rb +++ b/app/services/batch_export_shixun_report_service.rb @@ -36,7 +36,7 @@ class BatchExportShixunReportService rescue => ex Rails.logger.error(ex.message) - zip.get_output_stream('FILE_NOTICE.txt'){|os| os.write('文件重复') } + zip.get_output_stream('FILE_NOTICE.txt'){|os| os.write("文件重复:#{export.filename}") } next end end