组织教师列表sql优化

This commit is contained in:
huang 2016-05-11 16:20:55 +08:00
parent 43f06c0826
commit 52c8593b09
6 changed files with 82 additions and 36 deletions

View File

@ -102,8 +102,10 @@ class OrganizationsController < ApplicationController
if params[:org_subfield_id]
@org_subfield = OrgSubfield.find(params[:org_subfield_id])
if @org_subfield.field_type == "Comptec" || @org_subfield.field_type == "Compstu"
#@org_students = User.find_by_sql("SELECT * FROM users u, user_extensions ue where u.id = ue.user_id and ue.identity =1;")
# @org_teachers = User.find_by_sql("select u.*, ue.technical_title, ue.school_id,( SELECT `courses`.* FROM `courses` INNER JOIN `members` ON `courses`.`id` = `members`.`course_id` WHERE `members`.`user_id` = u.id AND (courses.status<>9)) as course_count
# from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 order by course_count desc")
@org_teachers = User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 order by course_count desc")
# @org_resources =
else
@org_subfield_ids = @org_subfield.org_document_comments.map(&:id) << 0
@org_activities = OrgActivity.where("(org_act_type='OrgDocumentComment'and org_act_id in (#{@org_subfield_ids.join(",")})) || (container_type='OrgSubfield' and container_id=#{@org_subfield.id})").order('updated_at desc').page(params[:page] || 1).per(10)
@ -148,6 +150,36 @@ class OrganizationsController < ApplicationController
end
def teacher_search
"SELECT homework_commons.* FROM homework_commons INNER JOIN courses ON homework_commons.course_id = courses.id where homework_type in #{type_ids} and course_id in #{visible_course_ids} and publish_time <= '#{Date.today}' and (homework_commons.name like '%#{search}%' "
teachers = User.find_by_sql("select u.*, ue.technical_title, ue.school_id,(select count(*) from courses where courses.tea_id = u.id) as course_count from users u, user_extensions ue where u.id = ue.user_id and ue.identity=0 order by course_count desc")
q = "#{params[:search].strip}"
@org_teachers = searchmember_by_name(teachers, q)
@is_remote = true
#@result_count = results.count
#@results = paginateHelper results, 10
# @results = results
# @search_name = q
end
def searchmember_by_name members, name
#searchPeopleByRoles(project, StudentRoles)
mems = []
if name != ""
name = name.to_s.downcase
members.each do |m|
username = m.user[:lastname].to_s.downcase + m.user[:firstname].to_s.downcase
if(m.user[:login].to_s.downcase.include?(name) || m.user.user_extensions[:student_id].to_s.downcase.include?(name) || username.include?(name))
mems << m
end
end
else
mems = members
end
mems
end
def get_project_message_activities_org org
project_ids = org.projects.map{|project| project.id}.join(",")
unless project_ids.blank?

View File

@ -0,0 +1,35 @@
<% @org_teachers.each do |org_teacher| %>
<% school = School.where("id =?", org_teacher.school_id).first %>
<div class="teacher-list-row">
<div>
<div class="teacher-avatar">
<%= link_to image_tag(url_to_avatar(org_teacher), :width => "90", :height => "90"), user_url_in_org(org_teacher), :alt => "用户头像" %>
</div>
<div class="fl">
<div class="ml25 mb20"><span class="teacher-name"><%= org_teacher.try(:realname).nil? ? org_teacher.try(:login) : org_teacher.try(:realname) %></span>
<% unless school.nil? %>
<span class="f12 fontGrey2 mr15"><%= school.name %></span>
<% end %>
<% unless org_teacher.nil? %>
<span class="f12 fontGrey2"><%= org_teacher.technical_title %></span></div>
<% end %>
<div class="teacher-social-block">
<div class="block-num"><%= org_teacher_course_count(org_teacher) %></div>
<div class="block-title">课程数</div>
</div>
<div class="block-slice"></div>
<div class="teacher-social-block">
<div class="block-num"><%= org_student_course_count(org_teacher) %>500</div>
<div class="block-title">学生数</div>
</div>
<div class="block-slice"></div>
<div class="teacher-social-block">
<div class="block-num"><%= org_teacher_resource_count(org_teacher) %></div>
<div class="block-title">资源数</div>
</div>
</div>
<a href="javascript:void(0);" class="fr teacher-select">添加</a>
</div>
<div class="cl"></div>
</div>
<% end %>

View File

@ -1,7 +1,14 @@
<div class="resources mt10">
<div class="function-row">
<input type="text" placeholder="搜索" class="teacher-list-search fl" />
<a href="javascript:void(0);" class="teacher-search-icon fl"></a>
<%= form_tag( url_for(:controller => 'organizations', :action => 'teacher_search'),
:remote => true , :method => 'get', :id => 'resource_search_form') do %>
<input type="text" name="search" placeholder="输入教师名进行搜索" class="teacher-list-search fl" />
<%= submit_tag '', :class => 'homepageSearchIcon', :onfocus => 'this.blur();', :style => 'border-style:none', :class => "teacher-search-icon fl" %>
<!--<a href="javascript:void(0);" onclick='this.parent.submit();return false;' class="searchIcon"></a>-->
<% end %>
<!--<a href="javascript:" class="f_l" onclick="$('#search_student').submit();">搜索</a>-->
<!--<input type="text" placeholder="搜索" class="teacher-list-search fl" />-->
<!--<a href="javascript:void(0);" class="teacher-search-icon fl"></a>-->
<select class="teacher-search-type fr">
<option>课程数</option>
<option>学生数</option>
@ -9,37 +16,7 @@
</select>
<div class="cl"></div>
</div>
<% @org_teachers.each do |org_teacher| %>
<% school = School.where("id =?", org_teacher.school_id).first %>
<div class="teacher-list-row">
<div>
<div class="teacher-avatar"><img src="images/homepageImage.jpg" width="90" height="90" /></div>
<div class="fl">
<div class="ml25 mb20"><span class="teacher-name"><%= org_teacher.try(:realname).nil? ? org_teacher.try(:login) : org_teacher.try(:realname) %></span>
<% unless school.nil? %>
<span class="f12 fontGrey2 mr15"><%= school.name %></span>
<% end %>
<% unless org_teacher.nil? %>
<span class="f12 fontGrey2"><%= org_teacher.technical_title %></span></div>
<% end %>
<div class="teacher-social-block">
<div class="block-num"><%= org_teacher_course_count(org_teacher) %></div>
<div class="block-title">课程数</div>
</div>
<div class="block-slice"></div>
<div class="teacher-social-block">
<div class="block-num"><%= org_student_course_count(org_teacher) %>500</div>
<div class="block-title">学生数</div>
</div>
<div class="block-slice"></div>
<div class="teacher-social-block">
<div class="block-num"><%= org_teacher_resource_count(org_teacher) %></div>
<div class="block-title">资源数</div>
</div>
</div>
<a href="javascript:void(0);" class="fr teacher-select">添加</a>
</div>
<div class="cl"></div>
</div>
<% end %>
<div id="org_teachers_list">
<%=render 'organizations/org_teachers_list' %>
</div>
</div>

View File

@ -0,0 +1 @@
$("#org_teachers_list").html('<%= escape_javascript( render :partial => 'organizations/org_teachers_list')%>');

View File

@ -76,6 +76,7 @@ RedmineApp::Application.routes.draw do
get 'more_org_projects'
get 'more_org_courses'
get 'search_courses'
get 'teacher_search'
post 'join_course_menu'
post 'join_courses'
get 'search_projects'

BIN
public/images/search.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB