同步用户数,项目数,实训数,学校数到trustie

dev_sync_trustie
SylorHuang 5 years ago
parent ca5bb884ae
commit 621c035260

@ -0,0 +1,25 @@
require 'uri'
require 'net/http'
class SyncTrustieJob < ApplicationJob
queue_as :default
def perform(type, count)
Rails.logger.info("#######_________response__sync__start__#########")
configs_content = Rails.application.config_for(:configuration)
token = configs_content["sync_token"]
token_url = configs_content["sync_url"]
url = "#{token_url}/api/v1/homes/sync_count"
sync_json = {
"token": token,
"type": type,
"number": count
}
uri = URI.parse(url)
http = Net::HTTP.new(uri.hostname, uri.port)
http.send_request('PUT', uri.path, sync_json.to_json, {'Content-Type' => 'application/json'})
Rails.logger.info("#######_________response__sync__end_____#########")
end
end

@ -8,6 +8,8 @@ class Project < ApplicationRecord
has_many :issues
has_many :user_grades, dependent: :destroy
after_create :sync_project_trustie #同步到trustie
# 创建者
def creator
User.find(user_id).full_name
@ -20,4 +22,8 @@ class Project < ApplicationRecord
def member?(user)
members.exists?(user_id: user.id)
end
def sync_project_trustie
SyncTrustieJob.perform_later("project", 1)
end
end

@ -19,6 +19,8 @@ class School < ApplicationRecord
has_many :apply_add_departments, dependent: :destroy
has_many :user_extensions, dependent: :nullify
after_create :sync_school_trustie #同步到trustie
# 学校管理员
def manager?(user)
ec_school_users.exists?(user_id: user.id)
@ -39,4 +41,8 @@ class School < ApplicationRecord
def manage_permission?(user)
manager?(user) || major_manager?(user) || course_manager?(user)
end
def sync_school_trustie
SyncTrustieJob.perform_later("school", 1)
end
end

@ -75,7 +75,7 @@ class Shixun < ApplicationRecord
scope :field_for_recommend, lambda{ select([:id, :name, :identifier, :myshixuns_count]) }
scope :find_by_ids,lambda{|k| where(id:k)}
after_create :send_tiding
after_create :send_tiding, :sync_shixun_trustie #同步到trustie
# REDO: 
def propaedeutics
@ -290,6 +290,10 @@ class Shixun < ApplicationRecord
subjects.where(hidden: 0).uniq
end
def sync_shixun_trustie
SyncTrustieJob.perform_later("practical_training_project", 1)
end
private
def send_tiding

@ -156,6 +156,7 @@ class User < ApplicationRecord
delegate :gender, :department_id, :school_id, :location, :location_city, :technical_title, to: :user_extension, allow_nil: true
before_save :update_hashed_password
after_create :sync_user_trustie #同步到trustie
#
# validations
@ -313,6 +314,10 @@ class User < ApplicationRecord
shixun.shixun_members.exists?(role: 2, user_id: id)
end
def sync_user_trustie
SyncTrustieJob.perform_later("user", 1)
end
# TPI的创建者
def creator_of_game?(game)
id == game.user_id

@ -0,0 +1,22 @@
#初始化同步educoder的人数项目数高校数实训数到Trustie平台只需运行一次
class SyncTrustieTask
def sync_format
Rails.logger.info("########________sync_to_trustie_start_________###########")
users_count = User.all.size
projects_count = Project.all.size
shixuns_count = Shixun.all.size
schools_count = School.all.size
SyncTrustieJob.perform_later("user", users_count)
SyncTrustieJob.perform_later("project", projects_count)
SyncTrustieJob.perform_later("practical_training_project", shixuns_count)
SyncTrustieJob.perform_later("school", schools_count)
Rails.logger.info("########________sync_to_trustie_end_________###########")
end
end
Loading…
Cancel
Save