ecs: modify student import api

dev_cs
p31729568 5 years ago
parent a94740b5b6
commit ae58131a82

@ -14,7 +14,7 @@ class Ecs::StudentsController < Ecs::BaseController
end
def import
success_count = Ecs::ImportStudentService.call(current_year, params[:attachment_id])
success_count = Ecs::ImportStudentService.call(current_year, params)
render_ok(success_count: success_count)
rescue Ecs::ImportStudentService::Error => ex
render_error(ex.message)

@ -1,18 +1,17 @@
class Ecs::ImportStudentService < ApplicationService
Error = Class.new(StandardError)
attr_reader :ec_year, :attachment
attr_reader :ec_year, :params
def initialize(ec_year, attachment_id)
@ec_year = ec_year
@attachment = Attachment.find_by(id: attachment_id)
def initialize(ec_year, params)
@ec_year = ec_year
@params = params
end
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(path)
excel = Ecs::ImportStudentExcel.new(params[:file].to_path)
success_count = 0
EcYearStudent.bulk_insert(:student_id, :name, :created_at, :updated_at) do |worker|

Loading…
Cancel
Save