Add an English data sheet for diplomas to crawl.

This commit is contained in:
chiu 2026-03-03 11:43:58 +00:00
parent fd7ee09275
commit 36604a928e
1 changed files with 41 additions and 35 deletions

View File

@ -451,12 +451,17 @@ module NccuSyncPlugin
'reli_dt'=>'end_date'
},
'rss_paedu_vw' => { # 學歷 diploma
'paedu_num' => 'paedu_num',
'nat_cod' => 'country',
'edulvl_cod' => 'degree',
'edudep_cod' => 'dept',
'bgn_dt' => 'start_date',
'end_dt' => 'end_date',
'sch_cod' => 'school'
'sch_cod' => 'school',
'sch_nam' => 'dis_sch_nam',
'sch_nam_en' => 'dis_sch_nam_en',
'dep_nam' => 'dis_dep_nam',
'edudep_nam_en' => 'dis_edudep_nam_en'
},
'zz_nat' => { # 國家對照表
'nat_chi' => 'zh_tw',
@ -480,6 +485,19 @@ module NccuSyncPlugin
},
'rss_pautlst_view' => { # 教師資料
},
'paedu' => {
'paedu_num' => 'paedu_num',
'nccu_id' => 'nccu_id',
'nat_cod' => 'nat_cod',
'edulvl_cod'=> 'edulvl_cod',
'sch_cod' => 'sch_cod',
'sch_nam' => 'sch_nam',
'sch_nam_en'=> 'sch_nam_en',
'dep_nam' => 'dep_nam',
'edudep_nam_en' => 'edudep_nam_en',
'bgn_dt' => 'start_date',
'end_dt' => 'end_date'
}
}
result = @client.execute(sql).to_a
@ -655,42 +673,30 @@ module NccuSyncPlugin
def self.get_diplomas(staff_id)
nccu_id = @sta_num_to_nccu_id_mapping[staff_id]
if nccu_id.nil?
puts "No nccu_id for staff: #{staff_id}"
return []
end
result = query_db('rss_paedu_vw', {:nccu_id=>nccu_id})
return [] if nccu_id.nil?
result = query_db('rss_paedu_vw', {:nccu_id => nccu_id})
raw_data = query_db('paedu', {:nccu_id => nccu_id})
result.each do |h|
# 確保能找到 Raw 表資料
raw_item = raw_data.find { |r| r['paedu_num'] == h['paedu_num'] } || {}
h['country'] = @country_mapping[h['country']]
h['degree'] = @degree_mapping[h['degree']]
h['dept'] = @dept_mapping[h['dept']]
h['school'] = @school_mapping[h['school']]
if h['school'].blank?
school_chi = h['sch_nam']
school_eng = h['sch_nam_en']
if school_eng.blank?
school_eng = school_chi
elsif school_chi.blank?
school_chi = school_eng
end
h['school'] = {
'zh_tw' => school_chi,
'en' => school_eng
}
end
if h['dept'].blank?
dept_chi = h['dep_nam']
dept_eng = h['edudep_nam_en']
if dept_eng.blank?
dept_eng = dept_chi
elsif school_chi.blank?
dept_chi = dept_eng
end
h['dept'] = {
'zh_tw' => dept_chi,
'en' => dept_eng
}
end
# --- 學校名稱 (核心修正) ---
m_school = @school_mapping[h['school']] || {}
# 中文 View 的 dis_sch_nam 通常最準
s_chi = h['dis_sch_nam'].presence || m_school['zh_tw'].presence || raw_item['sch_nam'].presence
# 英文 View 常常是空的,一定要優先拿 Raw 表的 sch_nam_en
s_eng = raw_item['sch_nam_en'].presence || h['dis_sch_nam_en'].presence || m_school['en'].presence
s_eng ||= s_chi
s_chi ||= s_eng
h['school'] = { 'zh_tw' => s_chi, 'en' => s_eng }
# --- 系所名稱 ---
m_dept = @dept_mapping[h['dept']] || {}
d_chi = h['dis_dep_nam'].presence || m_dept['zh_tw'].presence || raw_item['dep_nam'].presence
d_eng = raw_item['edudep_nam_en'].presence || h['dis_edudep_nam_en'].presence || m_dept['en'].presence
d_eng ||= d_chi
d_chi ||= d_eng
h['dept'] = { 'zh_tw' => d_chi, 'en' => d_eng }
end
result
end
@ -762,4 +768,4 @@ namespace :sync_nccu_personal_plugins do
end
NccuSyncPlugin.close
end
end
end