|
|
@ -1,18 +1,17 @@
|
|
|
|
class Ecs::ImportStudentService < ApplicationService
|
|
|
|
class Ecs::ImportStudentService < ApplicationService
|
|
|
|
Error = Class.new(StandardError)
|
|
|
|
Error = Class.new(StandardError)
|
|
|
|
|
|
|
|
|
|
|
|
attr_reader :ec_year, :attachment
|
|
|
|
attr_reader :ec_year, :params
|
|
|
|
|
|
|
|
|
|
|
|
def initialize(ec_year, attachment_id)
|
|
|
|
def initialize(ec_year, params)
|
|
|
|
@ec_year = ec_year
|
|
|
|
@ec_year = ec_year
|
|
|
|
@attachment = Attachment.find_by(id: attachment_id)
|
|
|
|
@params = params
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def call
|
|
|
|
def call
|
|
|
|
raise Error, '文件不存在' if attachment.blank?
|
|
|
|
raise Error, '文件不存在' if params[:file].blank? || !params[:file].is_a?(ActionDispatch::Http::UploadedFile)
|
|
|
|
|
|
|
|
|
|
|
|
path = attachment.diskfile
|
|
|
|
excel = Ecs::ImportStudentExcel.new(params[:file].path)
|
|
|
|
excel = Ecs::ImportStudentExcel.new(path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
success_count = 0
|
|
|
|
success_count = 0
|
|
|
|
EcYearStudent.bulk_insert(:student_id, :name, :created_at, :updated_at) do |worker|
|
|
|
|
EcYearStudent.bulk_insert(:student_id, :name, :created_at, :updated_at) do |worker|
|
|
|
|