|
@@ -16,13 +16,18 @@ class PeopleController < ApplicationController
|
|
|
end
|
|
|
end
|
|
|
|
|
|
- def unset
|
|
|
+ def notset
|
|
|
@people = Person.left_outer_joins(:passes).distinct.where('`passes`.`person_id` IS NULL')
|
|
|
|
|
|
self.commonindex
|
|
|
end
|
|
|
|
|
|
def index
|
|
|
+ if params[:lastname].nil?
|
|
|
+ @people = Person.where(:id => -1)
|
|
|
+ return self.commonindex
|
|
|
+ end
|
|
|
+
|
|
|
if params[:lastname].nil? or params[:lastname] == ""
|
|
|
@people = Person.preload(:passes).all
|
|
|
else
|
|
@@ -86,15 +91,7 @@ class PeopleController < ApplicationController
|
|
|
redirect_to "/people/#{ @pass.person_id }"
|
|
|
end
|
|
|
|
|
|
- def download
|
|
|
- dbparam = ''
|
|
|
- unless params[:db].blank?
|
|
|
- dbparam="&db=#{params[:db]}"
|
|
|
- end
|
|
|
-
|
|
|
- require 'net/http'
|
|
|
-
|
|
|
- url_str = "https://cps.mephi.ru/?cmd=fixok_people&apiKey=#{Rails.application.config.cps_api_key}#{dbparam}"
|
|
|
+ def get_json_data_by_url(url_str)
|
|
|
#puts "#{url_str}"
|
|
|
url = URI.parse(url_str)
|
|
|
http = Net::HTTP.new(url.host, url.port)
|
|
@@ -102,15 +99,26 @@ class PeopleController < ApplicationController
|
|
|
reply = http.get(url.request_uri)
|
|
|
|
|
|
if reply.body.blank?
|
|
|
- return
|
|
|
+ return nil
|
|
|
end
|
|
|
|
|
|
- json = ActiveSupport::JSON.decode(reply.body)
|
|
|
- #puts "#{json.to_yaml}"
|
|
|
+ return ActiveSupport::JSON.decode(reply.body)
|
|
|
+ end
|
|
|
+
|
|
|
+ def download
|
|
|
+ require 'net/http'
|
|
|
+
|
|
|
+ people_jraw = get_json_data_by_url "https://api.cps.mephi.ru/people?prepareFormulars=true&apiKey=#{Rails.application.config.cps_api_key}"
|
|
|
+ return if people_jraw.nil?
|
|
|
+
|
|
|
+ passes_jraw = get_json_data_by_url "https://api.cps.mephi.ru/passes?apiKey=#{Rails.application.config.cps_api_key}"
|
|
|
+ return if passes_jraw.nil?
|
|
|
+
|
|
|
+ #puts "#{people_jraw.to_yaml}"
|
|
|
|
|
|
employees = Hash.new
|
|
|
- json["employees"].each do |id, employee|
|
|
|
- person = Person.find_by_id( employee["e_id"].to_i )
|
|
|
+ people_jraw["arg"].each do |employee|
|
|
|
+ person = Person.find_by_id( employee["EmpGUID"].to_i )
|
|
|
if person.nil?
|
|
|
person = Person.ParseEmployee(employee)
|
|
|
#puts "#{person.to_yaml}"
|
|
@@ -134,7 +142,7 @@ class PeopleController < ApplicationController
|
|
|
passes_raw = Hash.new
|
|
|
ofz_links = Hash.new
|
|
|
File.open('/tmp/cps_keys.csv', 'w') { |file|
|
|
|
- json["ofz_link_table"].each do |row|
|
|
|
+ passes_jraw["arg"].each do |row|
|
|
|
pass_id = row["UserID"].to_i
|
|
|
|
|
|
key="#{row["Lastname"]}#{row["Firstname"]}#{row["Patronymic"]}".delete(' ').delete('?').gsub('Ё', 'Е').gsub('ё', 'е').strip
|