|  |  | @ -26,26 +26,19 @@ class ShixunsController < ApplicationController | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	## 获取课程列表 |  |  |  | 	## 获取课程列表 | 
			
		
	
		
		
			
				
					
					|  |  |  |   def index |  |  |  |   def index | 
			
		
	
		
		
			
				
					
					|  |  |  |     ## 我的实训 |  |  |  | 		@shixuns = current_laboratory.shixuns.unhidden.publiced | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     @shixuns = |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         if params[:order_by] == 'mine' |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 					tip_exception(401, "..") unless current_user.logged? |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |           current_user.my_shixuns |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         else |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |           Shixun.unhidden |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         end |  |  |  |  | 
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		## 方向 |  |  |  | 		## 方向 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		if params[:tag_level].present? && params[:tag_id].present? |  |  |  | 		if params[:tag_level].present? && params[:tag_id].present? | 
			
		
	
		
		
			
				
					
					|  |  |  |       @shixuns = @shixuns.filter_tag(params[:tag_level].to_i, params[:tag_id].to_i) |  |  |  | 			@shixuns = @shixuns.filter_tag(params[:tag_level].to_i, params[:tag_id].to_i) | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 			case params[:tag_level].to_i |  |  |  | 			case params[:tag_level].to_i | 
			
		
	
		
		
			
				
					
					|  |  |  | 				when 1 #大类 |  |  |  | 			when 1 #大类 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 					@search_tags = Repertoire.find(params[:tag_id].to_i).name |  |  |  | 				@search_tags = Repertoire.find(params[:tag_id].to_i).name | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				when 2 #子类 |  |  |  | 			when 2 #子类 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 					@search_tags =  SubRepertoire.find(params[:tag_id].to_i).name |  |  |  | 				@search_tags =  SubRepertoire.find(params[:tag_id].to_i).name | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				when 3 #tag |  |  |  | 			when 3 #tag | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 					tag = TagRepertoire.find(params[:tag_id].to_i) |  |  |  | 				tag = TagRepertoire.find(params[:tag_id].to_i) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 					@search_tags = "#{tag.sub_repertoire.name} / #{tag.name}" |  |  |  | 				@search_tags = "#{tag.sub_repertoire.name} / #{tag.name}" | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 			end |  |  |  | 			end | 
			
		
	
		
		
			
				
					
					|  |  |  | 		end |  |  |  | 		end | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -61,27 +54,23 @@ class ShixunsController < ApplicationController | 
			
		
	
		
		
			
				
					
					|  |  |  | 		end |  |  |  | 		end | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		## 筛选 状态 |  |  |  | 		## 筛选 状态 | 
			
		
	
		
		
			
				
					
					|  |  |  |     if params[:status].present? && params[:status].to_i != 0 |  |  |  | 		if params[:status].present? && params[:status].to_i != 0 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 			params[:status] = [0, 1] if params[:status].to_i == 1 |  |  |  | 			params[:status] = [0, 1] if params[:status].to_i == 1 | 
			
		
	
		
		
			
				
					
					|  |  |  |       @shixuns = @shixuns.where(status: params[:status]) |  |  |  | 			@shixuns = @shixuns.where(status: params[:status]) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     end |  |  |  | 		end | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		## 筛选 难度 |  |  |  | 		## 筛选 难度 | 
			
		
	
		
		
			
				
					
					|  |  |  |     if params[:diff].present? && params[:diff].to_i != 0 |  |  |  | 		if params[:diff].present? && params[:diff].to_i != 0 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       @shixuns = @shixuns.where(trainee: params[:diff]) |  |  |  | 			@shixuns = @shixuns.where(trainee: params[:diff]) | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     end |  |  |  | 		end | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		## 排序参数 |  |  |  | 		## 排序参数 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		bsort = params[:sort] || 'desc' |  |  |  | 		bsort = (params[:sort] == "desc" ? "desc" : "asc") | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 		case params[:order_by] || 'publish_time' |  |  |  | 		case params[:order_by] || 'new' | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			when 'new' |  |  |  | 		when 'hot' | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				@shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.created_at #{bsort}") |  |  |  | 			@shixuns = @shixuns.order("shixuns.public = 2 desc, shixuns.myshixuns_count #{bsort}") | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 			when 'hot' |  |  |  | 		else | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  | 				@shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.myshixuns_count #{bsort}") |  |  |  | 			@shixuns = @shixuns.order("shixuns.public = 2 desc, shixuns.publish_time #{bsort}") | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |       when 'mine' |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |         @shixuns = @shixuns.order("shixuns.created_at #{bsort}") |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |       else |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 				@shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.publish_time #{bsort}") |  |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 		end |  |  |  | 		end | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		# 用id计数会快10+MS左右,对于搜索的内容随着数据的增加,性能会提升一些。 |  |  |  | 		# 用id计数会快10+MS左右,对于搜索的内容随着数据的增加,性能会提升一些。 | 
			
		
	
	
		
		
			
				
					|  |  | @ -92,12 +81,6 @@ class ShixunsController < ApplicationController | 
			
		
	
		
		
			
				
					
					|  |  |  | 		limit = params[:limit] || 16 |  |  |  | 		limit = params[:limit] || 16 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 		@shixuns = @shixuns.includes(:tag_repertoires, :challenges).page(page).per(limit) |  |  |  | 		@shixuns = @shixuns.includes(:tag_repertoires, :challenges).page(page).per(limit) | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 		@tag_name_map = TagRepertoire.joins(:shixun_tag_repertoires) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 											.where(shixun_tag_repertoires: { shixun_id: @shixuns.map(&:id) }) |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 											.group('shixun_tag_repertoires.shixun_id') |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 											.select('shixun_id, tag_repertoires.name') |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 											.each_with_object({}) { |r, obj| obj[r.shixun_id] = r.name } |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  |   end |  |  |  |   end | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 	def shixun_list |  |  |  | 	def shixun_list | 
			
		
	
	
		
		
			
				
					|  |  | 
 |