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