|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
class ShixunsController < ApplicationController
|
|
|
|
|
before_action :require_login, except: [:download_file, :index, :menus]
|
|
|
|
|
before_action :check_auth, except: [:download_file, :index]
|
|
|
|
|
before_action :require_login, :check_auth, except: [:download_file, :index, :menus]
|
|
|
|
|
before_action :check_auth, except: [:download_file, :index, :menus]
|
|
|
|
|
|
|
|
|
|
before_action :find_shixun, :shixun_access_allowed, except: [:index, :new, :create, :menus, :get_recommend_shixuns,
|
|
|
|
|
:propaedeutics, :departments, :apply_shixun_mirror,
|
|
|
|
@ -44,11 +44,12 @@ class ShixunsController < ApplicationController
|
|
|
|
|
## 搜索关键字 匹配关卡名, 用户名, 实训名 和 空格多搜索
|
|
|
|
|
if params[:keyword].present?
|
|
|
|
|
keyword = params[:keyword].strip
|
|
|
|
|
@shixuns = @shixuns.joins(:users, 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
|
|
|
|
|
@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 :name",
|
|
|
|
|
keyword: "%#{keyword}%", name: "%#{keyword.split(" ").join("%")}%").distinct
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
## 筛选 状态
|
|
|
|
@ -68,15 +69,15 @@ class ShixunsController < ApplicationController
|
|
|
|
|
when 'new'
|
|
|
|
|
@shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.created_at #{bsort}")
|
|
|
|
|
when 'hot'
|
|
|
|
|
@shixuns = @shixuns.order("shixuns.status = 2 desc, myshixuns_count #{bsort}")
|
|
|
|
|
@shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.myshixuns_count #{bsort}")
|
|
|
|
|
when 'mine'
|
|
|
|
|
@shixuns = @shixuns.order("shixuns.created_at #{bsort}")
|
|
|
|
|
else
|
|
|
|
|
@shixuns = @shixuns.order("shixuns.status = 2 desc, publish_time #{bsort}")
|
|
|
|
|
@shixuns = @shixuns.order("shixuns.status = 2 desc, shixuns.publish_time #{bsort}")
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@total_count = @shixuns.count
|
|
|
|
|
# 用id计数会快10+MS左右,对于搜索的内容随着数据的增加,性能会提升一些。
|
|
|
|
|
@total_count = @shixuns.count("shixuns.id")
|
|
|
|
|
|
|
|
|
|
## 分页参数
|
|
|
|
|
page = params[:page] || 1
|
|
|
|
@ -128,7 +129,7 @@ class ShixunsController < ApplicationController
|
|
|
|
|
select m.user_id, u.login, u.lastname, m.updated_at,
|
|
|
|
|
(select sum(cost_time) from games g where g.myshixun_id = m.id) as time,
|
|
|
|
|
(select sum(final_score) from games g where g.myshixun_id = m.id) as score
|
|
|
|
|
from (myshixuns m join users u on m.user_id = u.id) where m.shixun_id = #{@shixun.id} and m.status = 1
|
|
|
|
|
from (users u left join myshixuns m on m.user_id = u.id) where m.shixun_id = #{@shixun.id} and m.status = 1
|
|
|
|
|
order by score desc, time asc limit 10
|
|
|
|
|
"
|
|
|
|
|
@myshixuns = Myshixun.find_by_sql(sql)
|
|
|
|
|