dfasdfasd

This commit is contained in:
innov 2020-06-04 18:13:07 +08:00
parent 20d4796e05
commit 3fdc1a59b4
1 changed files with 36 additions and 0 deletions

36
n/search_teacher Normal file
View File

@ -0,0 +1,36 @@
require 'csv'
schools = School.where(province: ["安徽","江苏"]).select(:id)
csv_title = ["id", "学校名称", "教师列表", "教师总数", "学生总数", "课堂总数", ]
schools.each do |s|
name = school.name
teacher_user = UserExtension.where(school_id: s.id, identity: :teacher)&.first.user
teacher = "#{teacher_user.try(:show_real_name)-teacher_user.try(:phone)-teacher_user.try(:)}"
end
csv_title = ["id", "用户名称", "用户电话","最后登录时间", "用户部门", "所属高校", "高校省份", "高校城市", "高校地址"]
school_ids = School.select(:id, :province).where(province: ["安徽","江苏"]).pluck(:id)
user_items = ["users.firstname","users.lastname","users.phone","users.last_login_on","departments.name","schools.name","schools.province","schools.city", "schools.address"]
users = UserExtension.where(school_id: school_ids, identity: :teacher).joins(:user,:school,:department).pluck(user_items)
csv_string = CSV.generate(:col_sep => "\t", :row_sep => "\r\n") do |csv|
csv << csv_title
users.each_with_index do |index,user|
csv << [index+1] + user
end
end
fh = File.new("/test.csv", "wb")
fh.puts NKF.nkf("-wL",csv_string)
fh.close