management user: add province filter

dev_trainings
p31729568 6 years ago
parent 5b07b39fb2
commit 2a6364b27e

@ -3310,83 +3310,79 @@ end
end
end
all_user_ids = User.where(:status => 1).pluck(:id)
users = User.where(nil)
if params[:trial] == "-1"
apply = ApplyAction.where(:container_type => "TrialAuthorization").pluck(:user_id)
apply_id = apply.blank? ? -1 : "(" + apply.join(",") + ")"
apply_user_id = User.where("status = 1 and certification = 0 and id not in #{apply_id} ").pluck(:id)
users = users.where(status: 1, certification: 0)
.joins('LEFT JOIN apply_actions aa ON aa.user_id = users.id AND aa.container_type = "TrialAuthorization"')
.where('aa.user_id IS NULL')
elsif params[:trial] == "-2"
apply_user_id = all_user_ids
users = users.where(status: 1)
elsif params[:trial] == "0"
apply_user_id = ApplyAction.where(:status => 0).pluck(:user_id)
users = users.joins('LEFT JOIN apply_actions apply ON apply.user_id = users.id').where(apply_actions: { status: 0 })
elsif params[:trial] == "3"
time = Time.at(Time.now.to_i - 86400)
user_cer = UserDayCertification.where("created_at > '#{time}'").pluck(:user_id)
cer_id = user_cer.blank? ? "(-1)" : "(" + user_cer.map{|a| a.user_id}.join(",") + ")"
apply_user_id = User.where("status = 1 and certification != 1 and id in #{cer_id} ").pluck(:id)
users = users.joins('LEFT JOIN user_day_certifications udc ON udc.user_id = users.id')
.where('users.certification != 1').where('udc.created_at > ?', Time.now.ago(1.days))
else
apply_user_id = User.where(:status => 1, :certification => params[:trial]).pluck(:id)
users = users.where(status: 1, certification: params[:trial])
end
if params[:school] == ""
s_user_id = all_user_ids
else
school_ids = School.where("name like '%#{params[:school]}%'").pluck(:id)
s_user_id = UserExtensions.where(:school_id => school_ids).pluck(:user_id)
users = users.joins('LEFT JOIN user_extensions ON user_extensions.user_id = users.id')
.joins('LEFT JOIN schools ON schools.id = user_extensions.school_id')
.joins('LEFT JOIN departments ON departments.id = user_extensions.department_id')
if params[:school].present?
users = users.where("schools.name LIKE ?", "%#{params[:school]}%")
end
if params[:department] == ""
d_user_id = all_user_ids
else
dep_ids = Department.where("name like '%#{params[:department]}%'").pluck(:id)
d_user_id = UserExtensions.where(:department_id => dep_ids).pluck(:user_id)
if params[:department].present?
users = users.where("departments.name LIKE ?", "%#{params[:department]}%")
end
ide_user_id = all_user_ids
if params[:identity] == "1" || (params[:identity] == "0" && params[:te_technical_title] == "0") || (params[:identity] == "2" && params[:pro_technical_title] == "0")
ide_user_id = UserExtensions.where("identity = #{params[:identity]}").pluck(:user_id)
users = users.where(user_extensions: { identity: params[:identity] })
elsif (params[:identity] == "0" && params[:te_technical_title] != "0") || (params[:identity] == "2" && params[:pro_technical_title] != "0")
technical_title = params[:identity] == "0" ? params[:te_technical_title] : params[:pro_technical_title]
ide_user_id = UserExtensions.where("identity = #{params[:identity]} and technical_title = '#{technical_title}'").pluck(:user_id)
users = users.where(user_extensions: { identity: params[:identity], technical_title: technical_title })
end
if params[:student_id] && params[:student_id] != ''
stu_user_id = UserExtensions.where("student_id like '%#{params[:student_id]}%'").pluck(:user_id)
else
stu_user_id = all_user_ids
if params[:student_id].present?
users = users.where('user_extensions.student_id like ?', "%#{params[:student_id]}%")
end
user_id = s_user_id & d_user_id & apply_user_id & stu_user_id & ide_user_id
sql = ""
sql =
if params[:research_contents].present?
keyword = "%#{params[:research_contents]}%"
if params[:research_condition] == "name"
"concat(lastname, firstname) like '%#{params[:research_contents]}%'"
users = users.where('concat(lastname, firstname) like ?', keyword)
elsif params[:research_condition] == "email"
"mail like '%#{params[:research_contents]}%'"
users = users.where("mail like ?", keyword)
elsif params[:research_condition] == "phone"
"phone like '%#{params[:research_contents]}%'"
users = users.where("phone like ?", keyword)
elsif params[:research_condition] == "nickname"
if params[:research_contents].present?
"nickname like '%#{params[:research_contents]}%'"
end
users = users.where("nickname like ?", keyword)
elsif params[:research_condition] == "login"
params[:research_contents].present? ? "login like '%#{params[:research_contents]}%'" : ""
users = users.where("login like ?", keyword)
end
end
if params[:province].present?
users = users.where(schools: { province: params[:province] })
end
@users = User.where(:id => user_id).where("#{sql}").includes(:apply_actions, user_extensions: [:department, :school]).order("last_login_on desc")
@xls_users = @users.reorder("created_on desc").limit(3000) #导出excel用户
users = users.includes(:apply_actions, user_extensions: [:department, :school]).order("last_login_on desc")
@page = (params['page'] || 1).to_i
@users_count = @users.count
@users_count = users.count
@limit = 20
@is_remote = true
@users_pages = Paginator.new @users_count, @limit, params['page'] || 1
@offset ||= @users_pages.offset
@users = paginateHelper @users, @limit
@users = paginateHelper users, @limit
respond_to do |format|
format.js
format.xls{
# @export_shixun_task = @export_shixun_task.all
@xls_users = users.reorder("created_on desc").limit(3000) #导出excel用户
filename = "用户列表.xls"
send_data(user_list_xls(@xls_users), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename))
}

@ -81,4 +81,10 @@ class School < ActiveRecord::Base
courses.id LEFT JOIN user_extensions ON courses.tea_id=user_extensions.user_id WHERE
user_extensions.`school_id` = #{self.id}").first.try(:max_update)
end
def self.provinces
Rails.cache.fetch('china_province_cache', expires_in: 1.days) do
School.pluck('distinct province').select(&:present?)
end
end
end

@ -19,20 +19,20 @@
<div class="fl with20 mr10">
<input type="text" name="department" class="fl task-form-100 task-height-40 panel-box-sizing" placeholder="子单位">
</div>
<select id="user_identity" name="identity" class="fl winput-240-40 mr10">
<select id="user_identity" name="identity" class="fl winput-120-40 mr10">
<option value="-1">请选择职业</option>
<option value="0">教师</option>
<option value="1">学生</option>
<option value="2">专业人士</option>
</select>
<select id="te_technical_title" name="te_technical_title" class="fl winput-240-40">
<select id="te_technical_title" name="te_technical_title" class="fl winput-200-40">
<option value="0">请选择职称</option>
<option value="教授">教授</option>
<option value="副教授">副教授</option>
<option value="讲师">讲师</option>
<option value="助教">助教</option>
</select>
<select id="pro_technical_title" name="pro_technical_title" class="fl winput-240-40 none">
<select id="pro_technical_title" name="pro_technical_title" class="fl winput-200-40 none">
<option value="0">请选择职称</option>
<option value="企业管理者">企业管理者</option>
<option value="部门管理者">部门管理者</option>
@ -41,6 +41,8 @@
<option value="助理工程师">助理工程师</option>
</select>
<%= select_tag :province, options_for_select(School.provinces.unshift(['请选择地区', ''])), class: 'fr winput-200-40'%>
<div class="cl mb15"></div>
<div class="edu-position edu-admin-select fl mr10" style="width:140px;">
<p>真实姓名搜索<i class="fa fa-caret-down ml10"></i></p>

@ -0,0 +1,5 @@
class AddIndexToApplyActions < ActiveRecord::Migration
def change
add_index :apply_actions, :user_id
end
end
Loading…
Cancel
Save