实训课程详情页的优化

dev_forum
cxt 6 years ago
parent d292f7b6d0
commit 8f343bc3f2

@ -11,7 +11,8 @@ class CoursesController < ApplicationController
render_error(ex.model.errors.full_messages.join(','))
end
before_action :require_login, :check_auth, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups, :left_banner, :top_banner]
before_action :require_login, :check_auth, except: [:index, :show, :students, :teachers, :board_list, :mine, :all_course_groups,
:left_banner, :top_banner, :apply_to_join_course]
before_action :set_course, :user_course_identity, only: [:show, :update, :destroy, :settings, :set_invite_code_halt,
:set_public_or_private, :search_teacher_candidate, :teachers, :apply_teachers,
:top_banner, :left_banner, :add_teacher_popup, :add_teacher,

@ -7,6 +7,7 @@ class SubjectsController < ApplicationController
:up_member_position, :down_member_position]
include ApplicationHelper
include SubjectsHelper
def index
@tech_system = Repertoire.where(nil).order("updated_at desc")
@ -81,11 +82,13 @@ class SubjectsController < ApplicationController
@is_creator = current_user.creator_of_subject?(@subject)
# 合作团队
@members = @subject.subject_members.includes(:user)
challenge_ids = Challenge.where(shixun_id: @subject.shixuns.published.pluck(:id)).pluck(:id)
shixun_ids = @subject.shixuns.published.pluck(:id)
challenge_ids = Challenge.where(shixun_id: shixun_ids).pluck(:id)
# 实训路径中的所有实训标签
@tags = ChallengeTag.where(challenge_id: challenge_ids).pluck(:name).uniq
# 用户获取的实训标签
@user_tags = @subject.shixuns.map(&:user_tags_name).flatten.uniq
# @user_tags = @subject.shixuns.map(&:user_tags_name).flatten.uniq
@user_tags = user_shixun_tags challenge_ids, @user.id
# 访问数变更
@subject.increment!(:visits)

@ -10,4 +10,9 @@ module SubjectsHelper
end
status
end
# 实训路径的所有用户获得的标签
def user_shixun_tags challenge_ids, user_id
ChallengeTag.joins(challenge: [:games]).where(games: {status: 2, user_id: user_id}, challenges: {id:challenge_ids}).pluck("challenge_tags.name").uniq
end
end

@ -1,5 +1,5 @@
class ChallengeChoose < ApplicationRecord
default_scope {order("position asc")}
default_scope {order("challenge_chooses.position asc")}
belongs_to :challenge, optional: true
has_many :challenge_tags, :dependent => :destroy
has_many :challenge_questions, dependent: :destroy

@ -56,6 +56,7 @@ class Shixun < ApplicationRecord
scope :visible, -> { where.not(status: -1) }
scope :published, lambda{ where(status: 2) }
scope :published_closed, lambda{ where(status: [2, 3]) }
scope :unhidden, lambda{ where(hidden: 0, status: 2) }
scope :field_for_recommend, lambda{ select([:id, :name, :identifier, :myshixuns_count]) }
scope :find_by_ids,lambda{|k| where(id:k)}

@ -53,11 +53,13 @@ class Subject < ApplicationRecord
end
def my_subject_score
shixuns_id = self.stage_shixuns.map(&:shixun_id)
shixuns_id = Shixun.where(:id => shixuns_id, :status =>[2, 3]).map(&:id)
shixuns_id = shixuns_id.present? ? shixuns_id.join(",") : -1
my_shixun_score = Challenge.find_by_sql("select sum(c.score) as score FROM challenges c join games g on g.challenge_id = c.id where g.status = 2 and g.user_id = #{User.current.id} and c.shixun_id in(#{shixuns_id})").first.try(:score)
my_choose_score = ChallengeChoose.find_by_sql("SELECT sum(g.final_score) score FROM (`challenge_chooses` cc join challenges c on cc.challenge_id = c.id) join games g on g.challenge_id = c.id where g.status = 2 and g.user_id = #{User.current.id} and c.shixun_id in(#{shixuns_id})").first.try(:score)
# shixuns_id = @subject.shixuns.published_closed.pluck(:id)
# shixuns_id = shixuns_id.present? ? shixuns_id.join(",") : -1
shixuns_id = shixuns.published_closed.pluck(:id)
my_shixun_score = Challenge.joins(:games).where(games: {status: 2, user_id: User.current.id}, shixun_id: shixuns_id).pluck(:score).sum
# my_shixun_score = Challenge.find_by_sql("select sum(c.score) as score FROM challenges c join games g on g.challenge_id = c.id where g.status = 2 and g.user_id = #{User.current.id} and c.shixun_id in(#{shixuns_id})").first.try(:score)
my_choose_score = ChallengeChoose.joins(challenge: :games).where(games: {status: 2, user_id: User.current.id}, challenges: {shixun_id: shixuns_id}).pluck(:score).sum
# my_choose_score = ChallengeChoose.find_by_sql("SELECT sum(g.final_score) score FROM (`challenge_chooses` cc join challenges c on cc.challenge_id = c.id) join games g on g.challenge_id = c.id where g.status = 2 and g.user_id = #{User.current.id} and c.shixun_id in(#{shixuns_id})").first.try(:score)
return my_shixun_score.to_i + my_choose_score.to_i
end

Loading…
Cancel
Save