[ADD]job use model data

This commit is contained in:
vilet.yy 2021-03-10 14:11:56 +08:00
parent 3e7ae82258
commit 8c43f74b69
1 changed files with 7 additions and 10 deletions

View File

@ -7,28 +7,25 @@ class SyncPhengleiUserJob < ApplicationJob
return if project.nil? return if project.nil?
member_count, success_count, error_count, not_exsit_count = 0, 0, 0, 0 member_count, success_count, error_count, not_exsit_count = 0, 0, 0, 0
Rails.logger.info("======begin to sync phenglei user to project#{project.owner.login + "/" + project.identifier}") Rails.logger.info("======begin to sync phenglei user to project#{project.owner.login + "/" + project.identifier}")
doc = SimpleXlsxReader.open("#{Rails.root}/public/phenglei_user.xlsx") PhengleiUser.find_each do |i|
data = doc.sheets.first.rows puts "======开始处理#{i.phone}"
data.each_with_index do |i, index| user = User.find_by(phone: i.phone)
next if index == 0 || i[1].nil?
puts "======开始处理#{i[1]}"
user = User.find_by(phone: i[1])
if user.present? if user.present?
if project.member?(user.id) if project.member?(user.id)
puts "======#{i[1]}用户已经是外围贡献者了" puts "======#{i.phone}用户已经是外围贡献者了"
member_count += 1 member_count += 1
else else
interactor = Projects::AddMemberInteractor.call(project.owner, project, user, "read", true) interactor = Projects::AddMemberInteractor.call(project.owner, project, user, "read", true)
if interactor.error.nil? if interactor.error.nil?
puts "========用户#{i[1]}成功添加为项目的外围贡献者=======" puts "========用户#{i.phone}成功添加为项目的外围贡献者======="
success_count += 1 success_count += 1
else else
puts "========用户#{i[1]}添加失败" puts "========用户#{i.phone}添加失败"
error_count += 1 error_count += 1
end end
end end
else else
puts "=====#{i[1]}用户不存在" puts "=====#{i.phone}用户不存在"
not_exsit_count += 1 not_exsit_count += 1
next next
end end