fix journal paper member_profiles

This commit is contained in:
邱博亞 2024-01-20 10:24:14 +08:00
parent 63158ad9b3
commit a2ae017eb8
1 changed files with 11 additions and 2 deletions

View File

@ -53,8 +53,9 @@ module AsiaSyncPlugin
def self.sync_journal_papers(query_result, member)
puts "Journal Paper for user: #{self.user_id(member)}"
journal_papers = query_result["journal"].to_a
jps = JournalPaper.where(member_profile_id: member.id,:rss2_id.ne=>nil).where(:rss2_id.nin=>journal_papers.map{|v| v["ukey"]})
if !query_result['emp'].blank?
JournalPaper.where(member_profile_id: member.id,:rss2_id.ne=>nil).where(:rss2_id.nin=>journal_papers.map{|v| v["ukey"]}).destroy
jps.update_all({"$pull" => {member_profile_id: member.id}})
end
return if journal_papers.count == 0
journal_papers.each do |journal_paper|
@ -74,11 +75,18 @@ module AsiaSyncPlugin
journal_paper_type = JournalPaperType.create(:title_translations=>localize_data(journal_paper["J_class"]))
end
jp.journal_paper_type = journal_paper_type
jp.member_profile_id = [member.id]
if (jp.member_profile_id.nil?)
jp.member_profile_id = []
end
jp.member_profile_id << member.id
puts "Journal Paper #{jp.id} saved" if jp.save
end
end
def self.clear_empty_journal_papers
JournalPaper.where(member_profile_id: [],:rss2_id.ne=>nil).delete
end
# 研討會論文
def self.sync_conference_papers(query_result, member)
puts "Conference Paper for user: #{self.user_id(member)}"
@ -413,6 +421,7 @@ namespace :sync_asia_personal_plugins do
AsiaSyncPlugin.sync_tec_transfers(query_result, member)
AsiaSyncPlugin.sync_college_projects(query_result, member)
end
AsiaSyncPlugin.clear_empty_journal_papers
end
def net_http_get_response(uri,headers={})
http = Net::HTTP.new(uri.host, uri.port)