parent
fe0f79100b
commit
516c9e7bec
@ -1,33 +1,19 @@
|
|||||||
class Admins::ImportUserExcel < BaseImportXlsx
|
class Admins::ImportUserExcel < BaseImportXlsx
|
||||||
UserData = Struct.new(:student_id, :name, :department_name, :identity, :technical_title, :phone)
|
UserData = Struct.new(:name, :phone, :mail, :school, :department, :identity, :student_id)
|
||||||
|
|
||||||
def read_each(&block)
|
def read_each(&block)
|
||||||
sheet.each_row_streaming(pad_cells: true, offset: 3) do |row|
|
sheet.each_row_streaming(pad_cells: true, offset: 1) do |row|
|
||||||
data = row.map(&method(:cell_value))[0..5]
|
data = row.map(&method(:cell_value))[0..7]
|
||||||
block.call UserData.new(*data)
|
block.call UserData.new(*data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def school
|
|
||||||
@school ||= begin
|
|
||||||
school_id = sheet.cell(1, 1).to_s.strip
|
|
||||||
school_name = sheet.cell(1, 2).to_s.strip
|
|
||||||
|
|
||||||
School.find_by(id: school_id, name: school_name)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def identifier
|
|
||||||
@_identifier ||= sheet.cell(2, 1).to_s.strip
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def check_sheet_valid!
|
def check_sheet_valid!
|
||||||
raise_import_error('请按照模板格式导入') if school.blank?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def cell_value(obj)
|
def cell_value(obj)
|
||||||
obj&.cell_value
|
obj&.cell_value&.presence
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in new issue