desc "导入职位类别" namespace :job_classify do task import: :environment do jobs_xlsx =Roo::Spreadsheet.open(Rails.root.join("excel_template/jobs.xlsx").to_s) job_data = jobs_xlsx.sheet(0) last_row = job_data.last_row job = nil 2.upto(last_row) do |r| if job_data.cell(r, 1).present? job = JobClassify.new(name: job_data.cell(r, 1), parent_id: 0, position: r) job.save p "导入职位一级---#{job_data.cell(r, 1)}" end if job_data.cell(r, 2).present? children = JobClassify.new(name: job_data.cell(r, 2), parent_id: job.id, position: r) children.save p "导入职位二级---#{job_data.cell(r, 2)}" end end end end