Fix bug.
This commit is contained in:
parent
5dd0bb747c
commit
ce36d284e6
|
@ -4,7 +4,7 @@ namespace :fgu_sync do
|
||||||
task :sync_plugins => :environment do
|
task :sync_plugins => :environment do
|
||||||
MemberProfile.each do |mp|
|
MemberProfile.each do |mp|
|
||||||
staff_id = mp.sid rescue nil
|
staff_id = mp.sid rescue nil
|
||||||
puts mp.id
|
# puts mp.id
|
||||||
if !staff_id.nil? && staff_id != ""
|
if !staff_id.nil? && staff_id != ""
|
||||||
sync_fgu_journals(staff_id, mp)
|
sync_fgu_journals(staff_id, mp)
|
||||||
sync_fgu_conference(staff_id, mp)
|
sync_fgu_conference(staff_id, mp)
|
||||||
|
@ -15,6 +15,9 @@ namespace :fgu_sync do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
def parse_date(d)
|
||||||
|
(d.present? ? (Date.parse(d) rescue Date.today) : nil)
|
||||||
|
end
|
||||||
def camelize(str)
|
def camelize(str)
|
||||||
str.split('_').map{|v| v.capitalize}.join(' ')
|
str.split('_').map{|v| v.capitalize}.join(' ')
|
||||||
end
|
end
|
||||||
|
@ -45,7 +48,7 @@ namespace :fgu_sync do
|
||||||
data["data"].each_with_index do |dt, idx|
|
data["data"].each_with_index do |dt, idx|
|
||||||
rss2id = dt["journal_id"]
|
rss2id = dt["journal_id"]
|
||||||
|
|
||||||
pd = Date.parse(dt["publication_date"]) rescue Date.today
|
pd = parse_date(dt["publication_date"])
|
||||||
paper_title = {"en" => dt["paper_title"],"zh_tw" => dt["paper_title"]}
|
paper_title = {"en" => dt["paper_title"],"zh_tw" => dt["paper_title"]}
|
||||||
journal_title = {"en" => dt["journal_title"],"zh_tw" => dt["journal_title"]}
|
journal_title = {"en" => dt["journal_title"],"zh_tw" => dt["journal_title"]}
|
||||||
from_to = dt["from_to"].split("-")
|
from_to = dt["from_to"].split("-")
|
||||||
|
@ -108,8 +111,8 @@ namespace :fgu_sync do
|
||||||
data["data"].each_with_index do |dt, idx|
|
data["data"].each_with_index do |dt, idx|
|
||||||
rss2id = dt["conf_id"]
|
rss2id = dt["conf_id"]
|
||||||
|
|
||||||
start_date = Date.parse(dt["start_date"]) rescue Date.today
|
start_date = parse_date(dt["start_date"])
|
||||||
end_date = Date.parse(dt["end_date"]) rescue Date.today
|
end_date = parse_date(dt["end_date"])
|
||||||
paper_title = {"en" => dt["paper_title"],"zh_tw" => dt["paper_title"]}
|
paper_title = {"en" => dt["paper_title"],"zh_tw" => dt["paper_title"]}
|
||||||
conference_title = {"en" => dt["conference_name"],"zh_tw" => dt["conference_name"]}
|
conference_title = {"en" => dt["conference_name"],"zh_tw" => dt["conference_name"]}
|
||||||
authors = [dt["author1"],dt["author2"],dt["author3"],dt["author4"]]
|
authors = [dt["author1"],dt["author2"],dt["author3"],dt["author4"]]
|
||||||
|
@ -148,7 +151,7 @@ namespace :fgu_sync do
|
||||||
data["data"].each_with_index do |dt, idx|
|
data["data"].each_with_index do |dt, idx|
|
||||||
rss2id = dt["book_id"]
|
rss2id = dt["book_id"]
|
||||||
|
|
||||||
pd = Date.parse(dt["date_of_publication"]) rescue Date.today
|
pd = parse_date(dt["date_of_publication"])
|
||||||
book_title = {"en" => dt["book_title"],"zh_tw" => dt["book_title"]}
|
book_title = {"en" => dt["book_title"],"zh_tw" => dt["book_title"]}
|
||||||
publisher = {"en" => dt["publisher"],"zh_tw" => dt["publisher"]}
|
publisher = {"en" => dt["publisher"],"zh_tw" => dt["publisher"]}
|
||||||
authors = [dt["author1"],dt["author2"],dt["author3"],dt["author4"]]
|
authors = [dt["author1"],dt["author2"],dt["author3"],dt["author4"]]
|
||||||
|
@ -202,8 +205,8 @@ namespace :fgu_sync do
|
||||||
puts "Deleting old data"
|
puts "Deleting old data"
|
||||||
Diploma.where(:member_profile_id => mp.id).destroy_all
|
Diploma.where(:member_profile_id => mp.id).destroy_all
|
||||||
data["data"].each_with_index do |dt, idx|
|
data["data"].each_with_index do |dt, idx|
|
||||||
start_date = Date.parse(dt["start_date"]) rescue Date.today
|
start_date = parse_date(dt["start_date"])
|
||||||
end_date = Date.parse(dt["end_date"]) rescue Date.today
|
end_date = parse_date(dt["end_date"])
|
||||||
school_name = {"en" => dt["school_name"], "zh_tw" => dt["school_name"]}
|
school_name = {"en" => dt["school_name"], "zh_tw" => dt["school_name"]}
|
||||||
department = {"en" => dt["department"], "zh_tw" => dt["department"]}
|
department = {"en" => dt["department"], "zh_tw" => dt["department"]}
|
||||||
degree = {"en" => dt["degree"], "zh_tw" => dt["degree"]}
|
degree = {"en" => dt["degree"], "zh_tw" => dt["degree"]}
|
||||||
|
@ -226,8 +229,8 @@ namespace :fgu_sync do
|
||||||
puts "Deleting old data"
|
puts "Deleting old data"
|
||||||
Experience.where(:member_profile_id => mp.id).destroy_all
|
Experience.where(:member_profile_id => mp.id).destroy_all
|
||||||
data["data"].each_with_index do |dt, idx|
|
data["data"].each_with_index do |dt, idx|
|
||||||
start_date = Date.parse(dt["start_date"]) rescue Date.today
|
start_date = parse_date(dt["start_date"])
|
||||||
end_date = Date.parse(dt["end_date"]) rescue Date.today
|
end_date = parse_date(dt["end_date"])
|
||||||
organization_title = {"en" => dt["organization_title"], "zh_tw" => dt["organization_title"]}
|
organization_title = {"en" => dt["organization_title"], "zh_tw" => dt["organization_title"]}
|
||||||
job_title = {"en" => dt["job_title"], "zh_tw" => dt["job_title"]}
|
job_title = {"en" => dt["job_title"], "zh_tw" => dt["job_title"]}
|
||||||
if !dt["emp_type"].blank?
|
if !dt["emp_type"].blank?
|
||||||
|
@ -265,7 +268,7 @@ namespace :fgu_sync do
|
||||||
role = Role.where(:key => "teacher").first
|
role = Role.where(:key => "teacher").first
|
||||||
end
|
end
|
||||||
if !role.nil?
|
if !role.nil?
|
||||||
puts "Assigning role #{role.key}"
|
# puts "Assigning role #{role.key}"
|
||||||
case dt["job_status"]
|
case dt["job_status"]
|
||||||
when "專任"
|
when "專任"
|
||||||
role_status = role.role_statuses.select{|v| v.title_translations[:en].upcase == "Full-Time".upcase}.first
|
role_status = role.role_statuses.select{|v| v.title_translations[:en].upcase == "Full-Time".upcase}.first
|
||||||
|
@ -275,16 +278,16 @@ namespace :fgu_sync do
|
||||||
role_status = nil
|
role_status = nil
|
||||||
end
|
end
|
||||||
if role.key == "teacher"
|
if role.key == "teacher"
|
||||||
puts dt
|
# puts dt
|
||||||
af = fetch_key(role.attribute_fields,"job_title")
|
af = fetch_key(role.attribute_fields,"job_title")
|
||||||
if !af.nil?
|
if !af.nil?
|
||||||
options = af.option_list.values
|
options = af.option_list.values
|
||||||
job_title = options.index(options.find{|x| x["zh_tw"] == dt["job_title"]})
|
job_title = options.index(options.find{|x| x["zh_tw"] == dt["job_title"]})
|
||||||
puts job_title.to_s
|
# puts job_title.to_s
|
||||||
if job_title.blank?
|
if job_title.blank?
|
||||||
job_title = af.option_list.keys.last.to_i + 1
|
job_title = af.option_list.keys.last.to_i + 1
|
||||||
af.option_list[job_title] = {"en" => dt["job_title"], "zh_tw" => dt["job_title"]}
|
af.option_list[job_title] = {"en" => dt["job_title"], "zh_tw" => dt["job_title"]}
|
||||||
puts af.option_list.to_s
|
# puts af.option_list.to_s
|
||||||
af.save
|
af.save
|
||||||
else
|
else
|
||||||
job_title = af.option_list.keys[job_title].to_i
|
job_title = af.option_list.keys[job_title].to_i
|
||||||
|
@ -349,7 +352,7 @@ namespace :fgu_sync do
|
||||||
all_role_status_ids << role_status.id
|
all_role_status_ids << role_status.id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
puts [staff_id,all_role_ids.inspect]
|
# puts [staff_id,all_role_ids.inspect]
|
||||||
if !all_role_ids.blank?
|
if !all_role_ids.blank?
|
||||||
mp.role_ids = all_role_ids
|
mp.role_ids = all_role_ids
|
||||||
all_role_ids.each do |r_id|
|
all_role_ids.each do |r_id|
|
||||||
|
|
Loading…
Reference in New Issue