Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_forum
daiao 5 years ago
commit 3c8fc504c6

@ -0,0 +1,11 @@
class DepartmentsController < ApplicationController
def for_option
render_ok(departments: Department.cached_names_data(current_school))
end
private
def current_school
@_current_school ||= School.find(params[:id])
end
end

@ -1278,14 +1278,8 @@ class ExercisesController < ApplicationController
#搜索
if params[:search].present?
search_content = params[:search]
#搜索用户的nickname,如果存在则返回,否则继续查询用户的真实姓名或学生号
nick_name_search = @exercise_users_list.where(user_id: User.where('CONCAT(users.lastname, users.firstname) like ?',"%#{search_content}%"))
if nick_name_search.present?
@exercise_users_list = nick_name_search
else
@exercise_users_list = @exercise_users_list.joins(user: [:user_extension]).where('user_extensions.student_id like ? OR user_extensions.student_realname like ?',"%#{search_content}%","%#{search_content}%")
end
@exercise_users_list = @exercise_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%")
end
@export_ex_users = @exercise_users_list

@ -953,12 +953,16 @@ class PollsController < ApplicationController
@poll_publish_count = get_user_permission_course(poll_ids,2).count
@poll_unpublish_count = get_user_permission_course(poll_ids,1).count
@course_all_members = @course.students
logger.info("#######F___________poll_user_ids________________####{@poll.poll_users.pluck(:id)}")
@poll_group_counts = @course.course_groups_count
if @user_course_identity < Course::STUDENT #当前为老师,而且老师只能查看自己班级的/课堂的问卷
@poll_current_user_status = 0
@poll_users_list = @poll.all_poll_users(current_user.id).distinct #该老师分班的全部学生
@poll_users_list = @poll.all_poll_users(current_user.id) #该老师分班的全部学生
get_poll_answers(@poll_users_list)
logger.info("#######F__________@poll_users_list________________####{@poll_users_list.pluck(:id)}")
logger.info("#######F__________@users_ids________________####{PollUser.where(id:@poll_users_list.pluck(:id)).pluck(:user_id)}")
if @poll_list_status == 1
@poll_course_groups =[]
@ -1026,20 +1030,18 @@ class PollsController < ApplicationController
#搜索
if search_content.present?
#搜索用户的nickname,如果存在则返回,否则继续查询用户的真实姓名或学生号
nick_name_search = @poll_users_list.where(user_id: User.where('CONCAT(users.lastname, users.firstname) like ?',"%#{search_content}%"))
if nick_name_search.present?
@poll_users_list = nick_name_search
else
@poll_users_list = @poll_users_list.joins(user: [:user_extension]).where('user_extensions.student_id like ? OR user_extensions.student_realname like ?',"%#{search_content}%","%#{search_content}%")
end
@poll_users_list = @poll_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{search_content}%", "%#{search_content}%")
end
logger.info("#######F_______@poll_users_list_last___@users_ids________________####{@poll_users_list.pluck(:id)}")
@poll_users_size = @poll_users_list.count
# 分页
@page = params[:page] || 1
@limit = params[:limit] || 20
@poll_users_list = @poll_users_list.page(@page).per(@limit)
page = params[:page] || 1
limit = params[:limit] || 20
@poll_users_list = @poll_users_list.page(page).per(limit)
logger.info("#######F_______@poll_users_list_after_page___@users_ids________________####{@poll_users_list.pluck(:id)}")
else
@poll_users_list = []
@poll_users_size = 0

@ -9,4 +9,8 @@ class SchoolsController < ApplicationController
render_ok(school_names: schools.pluck(:name))
end
def for_option
render_ok(schools: School.cached_names_data)
end
end

@ -2,4 +2,26 @@ class Department < ApplicationRecord
belongs_to :school
has_many :department_members, dependent: :destroy
after_create_commit :reset_data_cache
after_update_commit :reset_data_cache
def self.cached_names_data(school)
Rails.cache.fetch(names_data_cache_key(school.id), expires_in: 7.days) do
school.departments.select(:id, :name).as_json
end
end
private
def reset_data_cache
# 清除部门名称缓存
if new_record? || name_previously_changed?
Rails.cache.delete(self.class.names_data_cache_key(school_id))
end
end
def self.names_data_cache_key(school_id)
"schools/#{school_id}/department_names_data"
end
end

@ -52,12 +52,12 @@ class Poll < ApplicationRecord
# 统一设置,为当前老师有权限的分班学生,分班设置,也为当前老师有权限的分班的学生
def all_poll_users(user_id)
poll_users = self.poll_users
poll_all_users = poll_users
group_ids = poll_published_ids(user_id)
if group_ids.present?
poll_users = poll_users.where(user_id: course.students.where(course_group_id: group_ids).pluck(:user_id))
poll_all_users = poll_all_users.where(user_id: course.students.where(course_group_id: group_ids).pluck(:user_id).uniq)
end
poll_users
poll_all_users
end
#当前用户已发布的班级id和试卷分组已发布的班级id的交集

@ -1,4 +1,6 @@
class School < ApplicationRecord
has_many :departments, dependent: :destroy
has_many :shixun_schools, :dependent => :destroy
has_many :shixuns, :through => :shixun_schools
@ -8,6 +10,9 @@ class School < ApplicationRecord
has_many :ec_major_schools, :dependent => :destroy
has_many :ec_majors, :through => :ec_major_schools
after_create_commit :reset_data_cache
after_update_commit :reset_data_cache
# 学校管理员
def manager?(user)
ec_school_users.exists?(user_id: user.id)
@ -28,4 +33,23 @@ class School < ApplicationRecord
def manage_permission?(user)
manager?(user) || major_manager?(user) || course_manager?(user)
end
def self.cached_names_data
Rails.cache.fetch(names_data_cache_key, expires_in: 7.days) do
School.select(:id, :name).as_json
end
end
private
def reset_data_cache
# 清除学校名称缓存
if new_record? || name_previously_changed?
Rails.cache.delete(self.class.names_data_cache_key)
end
end
def self.names_data_cache_key
'schools/names_data'
end
end

@ -576,9 +576,13 @@ Rails.application.routes.draw do
resources :schools do
member do
resources :departments, only: [] do
get :for_option, on: :collection
end
end
collection do
get "school_list"
get :school_list
get :for_option
end
scope module: :ecs do

Loading…
Cancel
Save