Created
October 9, 2018 08:54
-
-
Save kkuprikov/32afd48610b2b244f13505c0bfcc73bb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def import_from_csv | |
existing_with_another_tn = [] | |
correct_users = [] | |
staffing_item_not_found = [] | |
extra = [] | |
total_count = 0 | |
CSV.read('./func_import_delim.csv').each do |row| | |
tn = row[0] | |
name = row[1] | |
staffing_item_id = row[2] | |
email = row[6] | |
u = User.find_by email: email.downcase | |
if u.present? | |
if u.pernr == tn | |
correct_users << u | |
else | |
# existing_with_another_tn << u | |
u.update!(pernr: tn) | |
correct_users << u | |
end | |
next | |
end | |
company = StaffingItem.with_deleted.find_by(ext_id: staffing_item_id)&.company | |
company = StaffingItem.with_deleted.find_by(ext_id: staffing_item_id[1..-1])&.company if staffing_item_id.first == '0' | |
puts 'Company not found' unless company | |
create_service.new( | |
nil, | |
company, | |
{ | |
name: name, | |
email: email, | |
role_id: role_id(company), | |
pernr: tn | |
} | |
).process if company | |
staffing_item_not_found << email unless company | |
extra << [row, company.id] if company | |
end | |
puts "EXISTING #{ existing_with_another_tn.map(&:email) }, count #{ existing_with_another_tn.size }" | |
puts "no staffing item #{ staffing_item_not_found }, count #{ staffing_item_not_found.size }" | |
puts "correct_users #{ correct_users.map(&:email) }, count #{ correct_users.size }" | |
puts "TOTAL #{total_count}" | |
puts "EXTRA #{extra}" | |
end | |
def create_service | |
ClientBasedLogic::Severgroup::Services::User::CreateService | |
end | |
def role_id(company) | |
company.roles.client.first.id | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment