From 9ffdccdd976414f834cb4b56fbe5fd58a7450b52 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Wed, 24 May 2017 16:57:46 +0800 Subject: [PATCH] old id update hps member --- app/models/hps_member.rb | 1 + lib/tasks/hps_task.rake | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/app/models/hps_member.rb b/app/models/hps_member.rb index 5996946..ea35480 100644 --- a/app/models/hps_member.rb +++ b/app/models/hps_member.rb @@ -18,6 +18,7 @@ class HpsMember field :score, type: Integer, :default => 0 field :enabled, :type => Boolean, :default => true field :user_type, type: Integer + field :old_id # school type diff --git a/lib/tasks/hps_task.rake b/lib/tasks/hps_task.rake index 0cba683..4b2d6f3 100644 --- a/lib/tasks/hps_task.rake +++ b/lib/tasks/hps_task.rake @@ -49,4 +49,32 @@ namespace :hps_task do hpsschool.save end end + + task :import_school_users => :environment do + file = File.join(Rails.root, "public", "hps", "school_user.json") + data = File.read(file) + users = JSON.parse(data) + users.each do |user| + hpsm = HpsMember.where(:old_id => user["old_id"]).first rescue nil + if !hpsm.nil? + hpsm = HpsMember.new + end + hpsm.old_id = user["old_id"] + hpsm.account = user["account"] + hpsm.password = user["password"] + hpsm.name = user["name"] + hpsm.telephone = user["telephone"] + hpsm.mobile = user["mobile"] + hpsm.email = user["email"] + hpsm.address = user["address"] + hpsm.title = user["title"] + school = HpsSchool.where(:old_id => user["SchoolID"]).first + hpsm.hps_school_id = school.id.to_s + city = HpsCity.where(:old_id => user["my_county"]).first + hpsm.hps_city_id = city.id.to_s + county = HpsCounty.where(:old_id => user["cityzip"]).first + hpsm.hps_county_id = county.id.to_s + hpsm.save + end + end end \ No newline at end of file