From 0eae8b354ed63204c0e1bb4c347f9b8e3f77a51a Mon Sep 17 00:00:00 2001 From: chiu Date: Fri, 26 May 2023 13:31:36 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E3=80=8Cfgu=5Fsync.rake?= =?UTF-8?q?=E3=80=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fgu_sync.rake | 51 +++++++++++++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/fgu_sync.rake b/fgu_sync.rake index 5ca0f97..cd442c7 100644 --- a/fgu_sync.rake +++ b/fgu_sync.rake @@ -4,6 +4,7 @@ namespace :fgu_sync do task :sync_plugins => :environment do MemberProfile.each do |mp| staff_id = mp.sid rescue nil + puts mp.id if !staff_id.nil? && staff_id != "" sync_fgu_journals(staff_id, mp) sync_fgu_conference(staff_id, mp) @@ -49,9 +50,9 @@ namespace :fgu_sync do journal_title = {"en" => dt["journal_title"],"zh_tw" => dt["journal_title"]} from_to = dt["from_to"].split("-") from_to[1] = "" if !from_to[1].present? - authors = [dt["author1"],dt["author2"],dt["author3"],dt["author4"]] - authors.delete("") - authors = {"en" => authors.join(", "), "zh_tw" => authors.join(", ")} + all_authors = [dt["author1"],dt["author2"],dt["author3"],dt["author4"]] + all_authors.delete("") + authors = {"en" => all_authors.join(", "), "zh_tw" => all_authors.join(", ")} note = dt["department"] + " " + dt["country"] + " " + dt["note"] if !dt["paper_level"].empty? @@ -69,19 +70,24 @@ namespace :fgu_sync do end jp = JournalPaper.where(:rss2_id => rss2id).first rescue nil + jp_data = { + :publication_date => pd, :rss2_id => rss2id, :year => pd.strftime("%Y"), + :authors_translations => authors, :paper_title_translations => paper_title, + :journal_title_translations => journal_title, :vol_no => dt["vol_no"], :issue_no => dt["issue_no"], + :note => note, :form_to_start => from_to[0], :form_to_end => from_to[1] + } if jp.nil? - jp = JournalPaper.new(:publication_date => pd, :rss2_id => rss2id, :year => pd.strftime("%Y"), :authors_translations => authors, :paper_title_translations => paper_title, :journal_title_translations => journal_title, :vol_no => dt["vol_no"], :issue_no => dt["issue_no"], :note => note, :form_to_start => from_to[0], :form_to_end => from_to[1], :member_profile => mp) - jp.journal_levels << level if !level.nil? - jp.journal_paper_type = type if !type.nil? - jp.save + jp = JournalPaper.new(jp_data) puts "Saving new journal." else - jp.update_attributes(:publication_date => pd, :rss2_id => rss2id, :year => pd.strftime("%Y"), :authors_translations => authors, :paper_title_translations => paper_title, :journal_title_translations => journal_title, :vol_no => dt["vol_no"], :issue_no => dt["issue_no"], :note => note, :form_to_start => from_to[0], :form_to_end => from_to[1]) - jp.journal_levels << level if !level.nil? - jp.journal_paper_type = type if !type.nil? - jp.save + jp.update_attributes(jp_data) puts "Updating journal #{jp.id}." end + jp_mps = MemberProfile.where("tmp_name.zh_tw" => {"$in" => all_authors}).to_a + jp.member_profiles = jp_mps.size==0 ? [mp] : jp_mps + jp.journal_levels << level if !level.nil? + jp.journal_paper_type = type if !type.nil? + jp.save end else puts "No data found." @@ -112,14 +118,16 @@ namespace :fgu_sync do note = dt["department"] + " " + dt["note"] cp = WritingConference.where(:rss2_id => rss2id).first rescue nil + cp_data = {:period_start_date => start_date, :period_end_date => end_date, :rss2_id => rss2id, :year => end_date.strftime("%Y"), :authors_translations => authors, :paper_title_translations => paper_title, :conference_title_translations => conference_title, :note => note, :location_translations => {"en" => dt["location"], "zh_tw" => dt["location"]}} if cp.nil? - cp = WritingConference.new(:period_start_date => start_date, :period_end_date => end_date, :rss2_id => rss2id, :year => end_date.strftime("%Y"), :authors_translations => authors, :paper_title_translations => paper_title, :conference_title_translations => conference_title, :note => note, :member_profile => mp, :location_translations => {"en" => dt["location"], "zh_tw" => dt["location"]}) - cp.save + cp = WritingConference.new(cp_data) puts "Saving new conference." else - cp.update_attributes(:period_start_date => start_date, :period_end_date => end_date, :rss2_id => rss2id, :year => end_date.strftime("%Y"), :authors_translations => authors, :paper_title_translations => paper_title, :conference_title_translations => conference_title, :note => note, :location_translations => {"en" => dt["location"], "zh_tw" => dt["location"]}) + cp.update_attributes(cp_data) puts "Updating conference #{cp.id}." end + cp.member_profile = mp + cp.save end else puts "No data found." @@ -163,19 +171,18 @@ namespace :fgu_sync do end book = Book.where(:rss2_id => rss2id).first rescue nil + book_data = {:publish_date => pd, :rss2_id => rss2id, :year => pd.strftime("%Y"), :authors_translations => authors, :publisher_translations => publisher, :book_title_translations => book_title, :isbn => dt["isbn"], :note => note, :language => dt["language"], :member_profile => mp} if book.nil? - book = Book.new(:publish_date => pd, :rss2_id => rss2id, :year => pd.strftime("%Y"), :authors_translations => authors, :publisher_translations => publisher, :book_title_translations => book_title, :isbn => dt["isbn"], :note => note, :language => dt["language"], :member_profile => mp) - book.book_author_types << authortype if !authortype.nil? - book.book_type = type if !type.nil? - book.save + book = Book.new(book_data) puts "Saving new book." else - book.update_attributes(:publish_date => pd, :rss2_id => rss2id, :year => pd.strftime("%Y"), :authors_translations => authors, :publisher_translations => publisher, :book_title_translations => book_title, :isbn => dt["isbn"], :note => note, :language => dt["language"], :member_profile => mp) - book.book_author_types << authortype if !authortype.nil? - book.book_type = type if !type.nil? - book.save + book.update_attributes(book_data) puts "Updating book #{book.id}." end + book.book_author_types << authortype if !authortype.nil? + book.book_type = type if !type.nil? + book.member_profile = mp + book.save end else puts "No data found."