Skip to content

  • Projects
  • Groups
  • Snippets
  • Help
  • This project
    • Loading...
  • Sign in / Register
V
venjob_nth
  • Overview
    • Overview
    • Details
    • Activity
    • Cycle Analytics
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Charts
  • Issues 0
    • Issues 0
    • List
    • Board
    • Labels
    • Milestones
  • Merge Requests 3
    • Merge Requests 3
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Charts
  • Wiki
    • Wiki
  • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Ngô Trung Hưng
  • venjob_nth
  • Merge Requests
  • !3

Merged
Opened Jul 28, 2020 by Ngô Trung Hưng@hungnt 
  • Report abuse
Report abuse

create import csv function

Chức năng: Tải file CSV từ FTP Server vể, tự giải nén, parse data và import data vào db

×

Check out, review, and merge locally

Step 1. Fetch and check out the branch for this merge request

git fetch origin
git checkout -b csv origin/csv

Step 2. Review the changes locally

Step 3. Merge the branch and fix any conflicts that come up

git checkout master
git merge --no-ff csv

Step 4. Push the result of the merge to GitLab

git push origin master

Note that pushing to GitLab requires write access to this repository.

Tip: You can also checkout merge requests locally by following these guidelines.

  • Discussion 47
  • Commits 11
  • Pipelines 11
  • Changes 20
{{ resolvedDiscussionCount }}/{{ discussionCount }} {{ resolvedCountText }} resolved
  • Ngô Trung Hưng @hungnt

    added 1 commit

    • 12437310 - fix nhe

    Compare with previous version

    Jul 28, 2020

    added 1 commit

    • 12437310 - fix nhe

    Compare with previous version

    added 1 commit * 12437310 - fix nhe [Compare with previous version](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4870&start_sha=8780eb6b7dee131c2acedf73da72ddd0bab57403)
    Toggle commit list
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 28, 2020
    Last updated by Ngô Trung Hưng Jul 29, 2020
    lib/service/ftp.rb 0 → 100644
    1 # frozen_string_literal: true
    2
    3 require 'service/unzip'
    4 require 'net/ftp'
    5 require 'csv'
    6
    7 # Access Ftp Server get file & extract file
    8 class FtpSever
    9 CONTENT_SERVER_DOMAIN_NAME = '192.168.1.156'
    10 CONTENT_SERVER_USER_NAME = 'training'
    11 CONTENT_SERVER_USER_PASSWORD = 'training'
    12 def self.donwload_csv
    • Hoang Phuc Do @phucdh commented Jul 28, 2020
      Master

      Có thể dùng cách khác để khai báo class methods:

      Đặt các method giữa: class << self

      class A
        class << self
          def method_a; end
          def method_b; end
        end
      
        def method_a; end
      end
      Edited Jul 29, 2020
      Có thể dùng cách khác để khai báo class methods: Đặt các method giữa: `class << self` ```ruby class A class << self def method_a; end def method_b; end end def method_a; end end ```
    • Ngô Trung Hưng @hungnt commented Jul 29, 2020
      Master

      Dạ anh

      Dạ anh
    • Ngô Trung Hưng @hungnt

      changed this line in version 4 of the diff

      Jul 29, 2020

      changed this line in version 4 of the diff

      changed this line in [version 4 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4877&start_sha=0f57f980cfcc2063222cfb2bff46f93d364b80d7#be323995e1d126ac08c5f0e850661b3809f8d098_15_15)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 28, 2020
    Last updated by Ngô Trung Hưng Jul 28, 2020
    lib/service/ftp.rb 0 → 100644
    5 require 'csv'
    6
    7 # Access Ftp Server get file & extract file
    8 class FtpSever
    9 CONTENT_SERVER_DOMAIN_NAME = '192.168.1.156'
    10 CONTENT_SERVER_USER_NAME = 'training'
    11 CONTENT_SERVER_USER_PASSWORD = 'training'
    12 def self.donwload_csv
    13 Net::FTP.open(CONTENT_SERVER_DOMAIN_NAME, CONTENT_SERVER_USER_NAME, CONTENT_SERVER_USER_PASSWORD) do |ftp|
    14 begin
    15 ftp.getbinaryfile('jobs.zip')
    16 extract_zip('./jobs.zip', 'lib/csv')
    17 File.delete('./jobs.zip') if File.exist?('./jobs.zip')
    18 puts 'Extract file done'
    19 rescue StandardError => e
    20 puts "#{e} File not found"
    • Hoang Phuc Do @phucdh commented Jul 28, 2020
      Master

      Nên ghi vào log để tiện theo dõi vì các rake task này sẽ được chạy bằng crontab

      Sử dụng puts chỉ in ra màn hình console, khó theo dõi khi chạy bằng crontab

      Edited Jul 29, 2020
      Nên ghi vào log để tiện theo dõi vì các rake task này sẽ được chạy bằng crontab Sử dụng `puts` chỉ in ra màn hình console, khó theo dõi khi chạy bằng crontab
    • Ngô Trung Hưng @hungnt commented Jul 28, 2020
      Master

      Dạ anh

      Dạ anh
    • Ngô Trung Hưng @hungnt

      changed this line in version 3 of the diff

      Jul 28, 2020

      changed this line in version 3 of the diff

      changed this line in [version 3 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4876&start_sha=12437310c9623b87f7735b9c318a36d41fb68887#be323995e1d126ac08c5f0e850661b3809f8d098_20_21)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 28, 2020
    Last updated by Ngô Trung Hưng Jul 28, 2020
    lib/service/import_data.rb 0 → 100644
    1 # frozen_string_literal: true
    2
    3 require 'service/ftp'
    4
    5 # Import data from CSV
    6 class ImportDataCSV
    • Hoang Phuc Do @phucdh commented Jul 28, 2020
      Master

      Tên class và tên file phải tương ứng với nhau

      Tên file đặt theo định dạng snake_case

      Tên class đặt theo định dạng CamelCase

      import_data.rb => class ImportData

      Edited Jul 29, 2020 by Hoang Phuc Do
      Tên class và tên file phải tương ứng với nhau Tên file đặt theo định dạng snake_case Tên class đặt theo định dạng CamelCase `import_data.rb` => `class ImportData`
    • Ngô Trung Hưng @hungnt commented Jul 28, 2020
      Master

      Dạ

      Dạ
    • Ngô Trung Hưng @hungnt

      changed this line in version 3 of the diff

      Jul 28, 2020

      changed this line in version 3 of the diff

      changed this line in [version 3 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4876&start_sha=12437310c9623b87f7735b9c318a36d41fb68887#fb47c56e27671d261a144b62e44604e1e9e53666_6_6)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 28, 2020
    Last updated by Ngô Trung Hưng Jul 28, 2020
    lib/service/unzip.rb 0 → 100644
    1 # frozen_string_literal: true
    2
    3 require 'zip'
    4
    5 # Description/Explanation of Person class
    6 def extract_zip(file, destination)
    • Hoang Phuc Do @phucdh commented Jul 28, 2020
      Master

      Đặt method này bên trong một module hoặc class

      Đặt method này bên trong một module hoặc class
    • Ngô Trung Hưng @hungnt

      changed this line in version 3 of the diff

      Jul 28, 2020

      changed this line in version 3 of the diff

      changed this line in [version 3 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4876&start_sha=12437310c9623b87f7735b9c318a36d41fb68887#2904aedcccf44850d5aada46fc7ebef4d42bcb31_6_6)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 28, 2020
    Last updated by Ngô Trung Hưng Jul 28, 2020
    lib/service/ftp.rb 0 → 100644
    4 require 'net/ftp'
    5 require 'csv'
    6
    7 # Access Ftp Server get file & extract file
    8 class FtpSever
    9 CONTENT_SERVER_DOMAIN_NAME = '192.168.1.156'
    10 CONTENT_SERVER_USER_NAME = 'training'
    11 CONTENT_SERVER_USER_PASSWORD = 'training'
    12 def self.donwload_csv
    13 Net::FTP.open(CONTENT_SERVER_DOMAIN_NAME, CONTENT_SERVER_USER_NAME, CONTENT_SERVER_USER_PASSWORD) do |ftp|
    14 begin
    15 ftp.getbinaryfile('jobs.zip')
    16 extract_zip('./jobs.zip', 'lib/csv')
    17 File.delete('./jobs.zip') if File.exist?('./jobs.zip')
    18 puts 'Extract file done'
    19 rescue StandardError => e
    • Hoang Phuc Do @phucdh commented Jul 28, 2020
      Master

      StandardError là lỗi tổng quát, không chỉ là File not found

      `StandardError` là lỗi tổng quát, không chỉ là File not found
    • Ngô Trung Hưng @hungnt

      changed this line in version 3 of the diff

      Jul 28, 2020

      changed this line in version 3 of the diff

      changed this line in [version 3 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4876&start_sha=12437310c9623b87f7735b9c318a36d41fb68887#be323995e1d126ac08c5f0e850661b3809f8d098_19_21)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 28, 2020
    Last updated by Ngô Trung Hưng Jul 28, 2020
    lib/service/import_data.rb 0 → 100644
    43 def parse_csv_companies(data)
    44 puts 'Import data companies . . .'
    45 data['company name'].each_with_index do |name, index|
    46 Company.find_or_create_by(name: name.strip) do |company|
    47 company.address = data['company address'][index]
    48 company.short_description = data['benefit'][index]
    49 end
    50 puts index
    51 rescue StandardError => e
    52 puts e
    53 end
    54 end
    55
    56 def parse_csv_jobs(data)
    57 data['name'].each_with_index do |name, index|
    58 desc = (data['requirement'][index]).to_s << (data['description'][index]).to_s
    • Hoang Phuc Do @phucdh commented Jul 28, 2020
      Master

      Nối chuỗi dùng string interpolation

      "#{data['requirement'][index]} #{data['description'][index]}"
      Nối chuỗi dùng string interpolation ```ruby "#{data['requirement'][index]} #{data['description'][index]}" ```
    • Ngô Trung Hưng @hungnt

      changed this line in version 3 of the diff

      Jul 28, 2020

      changed this line in version 3 of the diff

      changed this line in [version 3 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4876&start_sha=12437310c9623b87f7735b9c318a36d41fb68887#fb47c56e27671d261a144b62e44604e1e9e53666_58_56)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 28, 2020
    Last updated by Ngô Trung Hưng Jul 28, 2020
    lib/service/import_data.rb 0 → 100644
    44 puts 'Import data companies . . .'
    45 data['company name'].each_with_index do |name, index|
    46 Company.find_or_create_by(name: name.strip) do |company|
    47 company.address = data['company address'][index]
    48 company.short_description = data['benefit'][index]
    49 end
    50 puts index
    51 rescue StandardError => e
    52 puts e
    53 end
    54 end
    55
    56 def parse_csv_jobs(data)
    57 data['name'].each_with_index do |name, index|
    58 desc = (data['requirement'][index]).to_s << (data['description'][index]).to_s
    59 id_company = Company.find_by name: data['company name'][index].to_s.strip
    • Hoang Phuc Do @phucdh commented Jul 28, 2020
      Master

      Đặt tên variable không chính xác, Company.find_by trả về một ActiveRecord object

      Có thể đặt là company

      Đặt tên variable không chính xác, `Company.find_by` trả về một ActiveRecord object Có thể đặt là `company`
    • Ngô Trung Hưng @hungnt

      changed this line in version 3 of the diff

      Jul 28, 2020

      changed this line in version 3 of the diff

      changed this line in [version 3 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4876&start_sha=12437310c9623b87f7735b9c318a36d41fb68887#fb47c56e27671d261a144b62e44604e1e9e53666_59_56)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 28, 2020
    Last updated by Ngô Trung Hưng Jul 28, 2020
    lib/service/import_data.rb 0 → 100644
    45 data['company name'].each_with_index do |name, index|
    46 Company.find_or_create_by(name: name.strip) do |company|
    47 company.address = data['company address'][index]
    48 company.short_description = data['benefit'][index]
    49 end
    50 puts index
    51 rescue StandardError => e
    52 puts e
    53 end
    54 end
    55
    56 def parse_csv_jobs(data)
    57 data['name'].each_with_index do |name, index|
    58 desc = (data['requirement'][index]).to_s << (data['description'][index]).to_s
    59 id_company = Company.find_by name: data['company name'][index].to_s.strip
    60 id_company = id_company.blank? ? COMPANY_SECURITY : id_company.id
    • Hoang Phuc Do @phucdh commented Jul 28, 2020
      Master

      => company_id

      => `company_id`
    • Ngô Trung Hưng @hungnt

      changed this line in version 3 of the diff

      Jul 28, 2020

      changed this line in version 3 of the diff

      changed this line in [version 3 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4876&start_sha=12437310c9623b87f7735b9c318a36d41fb68887#fb47c56e27671d261a144b62e44604e1e9e53666_60_56)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 28, 2020
    Last updated by Ngô Trung Hưng Jul 28, 2020
    lib/service/import_data.rb 0 → 100644
    47 company.address = data['company address'][index]
    48 company.short_description = data['benefit'][index]
    49 end
    50 puts index
    51 rescue StandardError => e
    52 puts e
    53 end
    54 end
    55
    56 def parse_csv_jobs(data)
    57 data['name'].each_with_index do |name, index|
    58 desc = (data['requirement'][index]).to_s << (data['description'][index]).to_s
    59 id_company = Company.find_by name: data['company name'][index].to_s.strip
    60 id_company = id_company.blank? ? COMPANY_SECURITY : id_company.id
    61 begin
    62 id_job = Job.create!(name: name,
    • Hoang Phuc Do @phucdh commented Jul 28, 2020
      Master

      id_job => job

      `id_job` => `job`
    • Ngô Trung Hưng @hungnt

      changed this line in version 3 of the diff

      Jul 28, 2020

      changed this line in version 3 of the diff

      changed this line in [version 3 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4876&start_sha=12437310c9623b87f7735b9c318a36d41fb68887#fb47c56e27671d261a144b62e44604e1e9e53666_62_62)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 28, 2020
    Last updated by Ngô Trung Hưng Jul 28, 2020
    lib/service/import_data.rb 0 → 100644
    50 puts index
    51 rescue StandardError => e
    52 puts e
    53 end
    54 end
    55
    56 def parse_csv_jobs(data)
    57 data['name'].each_with_index do |name, index|
    58 desc = (data['requirement'][index]).to_s << (data['description'][index]).to_s
    59 id_company = Company.find_by name: data['company name'][index].to_s.strip
    60 id_company = id_company.blank? ? COMPANY_SECURITY : id_company.id
    61 begin
    62 id_job = Job.create!(name: name,
    63 company_id: id_company,
    64 level: data['level'][index],
    65 experience: '',
    • Hoang Phuc Do @phucdh commented Jul 28, 2020
      Master

      Nếu không có giá trị có thể bỏ experience khỏi tham số được không ?

      Nếu không có giá trị có thể bỏ `experience` khỏi tham số được không ?
    • Ngô Trung Hưng @hungnt commented Jul 28, 2020
      Master

      Dạ được anh, để e sửa lại

      Dạ được anh, để e sửa lại
    • Ngô Trung Hưng @hungnt

      changed this line in version 3 of the diff

      Jul 28, 2020

      changed this line in version 3 of the diff

      changed this line in [version 3 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4876&start_sha=12437310c9623b87f7735b9c318a36d41fb68887#fb47c56e27671d261a144b62e44604e1e9e53666_65_62)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 28, 2020
    Last updated by Ngô Trung Hưng Jul 28, 2020
    lib/service/import_data.rb 0 → 100644
    53 end
    54 end
    55
    56 def parse_csv_jobs(data)
    57 data['name'].each_with_index do |name, index|
    58 desc = (data['requirement'][index]).to_s << (data['description'][index]).to_s
    59 id_company = Company.find_by name: data['company name'][index].to_s.strip
    60 id_company = id_company.blank? ? COMPANY_SECURITY : id_company.id
    61 begin
    62 id_job = Job.create!(name: name,
    63 company_id: id_company,
    64 level: data['level'][index],
    65 experience: '',
    66 salary: data['salary'][index],
    67 create_date: Time.now,
    68 expiration_date: '',
    • Hoang Phuc Do @phucdh commented Jul 28, 2020
      Master

      Nếu không có giá trị có thể bỏ expiration_date khỏi tham số được không ?

      Nếu không có giá trị có thể bỏ `expiration_date` khỏi tham số được không ?
    • Ngô Trung Hưng @hungnt

      changed this line in version 3 of the diff

      Jul 28, 2020

      changed this line in version 3 of the diff

      changed this line in [version 3 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4876&start_sha=12437310c9623b87f7735b9c318a36d41fb68887#fb47c56e27671d261a144b62e44604e1e9e53666_68_62)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 28, 2020
    Last updated by Ngô Trung Hưng Jul 28, 2020
    lib/service/import_data.rb 0 → 100644
    5 # Import data from CSV
    6 class ImportDataCSV
    7 DOMESTIC = 1
    8 COMPANY_SECURITY = 1
    9
    10 def import_data
    11 csv_data = FtpSever.data_csv
    12 parse_csv_industries(csv_data)
    13 parse_csv_cities(csv_data)
    14 parse_csv_companies(csv_data)
    15 parse_csv_jobs(csv_data)
    16 end
    17
    18 private
    19
    20 def parse_csv_industries(data)
    • Hoang Phuc Do @phucdh commented Jul 28, 2020
      Master

      parse_csv_industries(data) => import_industries_from(csv)

      `parse_csv_industries(data)` => `import_industries_from(csv)`
    • Ngô Trung Hưng @hungnt

      changed this line in version 3 of the diff

      Jul 28, 2020

      changed this line in version 3 of the diff

      changed this line in [version 3 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4876&start_sha=12437310c9623b87f7735b9c318a36d41fb68887#fb47c56e27671d261a144b62e44604e1e9e53666_20_20)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 28, 2020
    Resolved by Hoang Phuc Do Jul 29, 2020
    lib/service/import_data.rb 0 → 100644
    17
    18 private
    19
    20 def parse_csv_industries(data)
    21 puts 'Import data industries . . .'
    22 industries = []
    23 industries += data['category'].map(&:strip)
    24 industries.each do |val|
    25 val.gsub!(',', '/') if val.include?(',')
    26 val.gsub!('/', ' / ')
    27 Industry.find_or_create_by(name: val)
    28 end
    29 puts 'Done parse csv industries'
    30 end
    31
    32 def parse_csv_cities(data)
    • Hoang Phuc Do @phucdh commented Jul 28, 2020
      Master

      parse_csv_cities(data) => import_cities_from(csv)

      Đặt tên là import vì hàm này lưu thông tin từ CSV vào DB

      Edited Jul 29, 2020
      `parse_csv_cities(data)` => `import_cities_from(csv)` Đặt tên là import vì hàm này lưu thông tin từ CSV vào DB
    • Ngô Trung Hưng @hungnt

      changed this line in version 3 of the diff

      Jul 28, 2020

      changed this line in version 3 of the diff

      changed this line in [version 3 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4876&start_sha=12437310c9623b87f7735b9c318a36d41fb68887#fb47c56e27671d261a144b62e44604e1e9e53666_32_32)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 28, 2020
    Resolved by Hoang Phuc Do Jul 29, 2020
    lib/service/import_data.rb 0 → 100644
    28 end
    29 puts 'Done parse csv industries'
    30 end
    31
    32 def parse_csv_cities(data)
    33 puts 'Import data cities . . .'
    34 cities = data['work place'].uniq.select(&:present?)
    35 cities = cities.map { |val| val.delete('[]\"') }
    36 cities.each do |val|
    37 next if val.blank?
    38
    39 City.find_or_create_by(name: val) { |city| city.area = DOMESTIC }
    40 end
    41 end
    42
    43 def parse_csv_companies(data)
    • Hoang Phuc Do @phucdh commented Jul 28, 2020
      Master

      parse_csv_companies(data) => import_companies_from(csv)

      Edited Jul 29, 2020
      `parse_csv_companies(data)` => `import_companies_from(csv)`
    • Ngô Trung Hưng @hungnt

      changed this line in version 3 of the diff

      Jul 28, 2020

      changed this line in version 3 of the diff

      changed this line in [version 3 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4876&start_sha=12437310c9623b87f7735b9c318a36d41fb68887#fb47c56e27671d261a144b62e44604e1e9e53666_43_43)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 28, 2020
    Last updated by Ngô Trung Hưng Jul 28, 2020
    lib/service/import_data.rb 0 → 100644
    41 end
    42
    43 def parse_csv_companies(data)
    44 puts 'Import data companies . . .'
    45 data['company name'].each_with_index do |name, index|
    46 Company.find_or_create_by(name: name.strip) do |company|
    47 company.address = data['company address'][index]
    48 company.short_description = data['benefit'][index]
    49 end
    50 puts index
    51 rescue StandardError => e
    52 puts e
    53 end
    54 end
    55
    56 def parse_csv_jobs(data)
    • Hoang Phuc Do @phucdh commented Jul 28, 2020
      Master

      parse_csv_jobs(data) => import_jobs_from(csv)

      `parse_csv_jobs(data)` => `import_jobs_from(csv)`
    • Ngô Trung Hưng @hungnt

      changed this line in version 3 of the diff

      Jul 28, 2020

      changed this line in version 3 of the diff

      changed this line in [version 3 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4876&start_sha=12437310c9623b87f7735b9c318a36d41fb68887#fb47c56e27671d261a144b62e44604e1e9e53666_56_56)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 28, 2020
    Resolved by Hoang Phuc Do Jul 29, 2020
    lib/service/import_data.rb 0 → 100644
    66 salary: data['salary'][index],
    67 create_date: Time.now,
    68 expiration_date: '',
    69 description: desc)
    70 make_foreign_cities_table(data['work place'][index], id_job.id)
    71 make_foreign_industries_table(data['category'][index], id_job.id)
    72 puts index
    73 rescue StandardError => e
    74 puts e
    75 end
    76 end
    77 end
    78
    79 def make_foreign_cities_table(data, id_job)
    80 data = data.to_s.delete('[]\"')
    81 id_city = City.find_by name: data.strip
    • Hoang Phuc Do @phucdh commented Jul 28, 2020
      Master

      id_city => city

      Edited Jul 29, 2020
      `id_city` => `city`
    • Ngô Trung Hưng @hungnt

      changed this line in version 3 of the diff

      Jul 28, 2020

      changed this line in version 3 of the diff

      changed this line in [version 3 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4876&start_sha=12437310c9623b87f7735b9c318a36d41fb68887#fb47c56e27671d261a144b62e44604e1e9e53666_81_79)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 28, 2020
    Resolved by Hoang Phuc Do Jul 29, 2020
    lib/service/import_data.rb 0 → 100644
    67 create_date: Time.now,
    68 expiration_date: '',
    69 description: desc)
    70 make_foreign_cities_table(data['work place'][index], id_job.id)
    71 make_foreign_industries_table(data['category'][index], id_job.id)
    72 puts index
    73 rescue StandardError => e
    74 puts e
    75 end
    76 end
    77 end
    78
    79 def make_foreign_cities_table(data, id_job)
    80 data = data.to_s.delete('[]\"')
    81 id_city = City.find_by name: data.strip
    82 id_city = id_city.blank? ? City.create!(name: data.strip, area: DOMESTIC).id : id_city.id
    • Hoang Phuc Do @phucdh commented Jul 28, 2020
      Master

      Có thể refactor lại như sau:

      city = City.find_or_create_by(name: data.strip) {|record| record.area = DOMESTIC}
      city_id = city.id
      Edited Jul 29, 2020
      Có thể refactor lại như sau: ```ruby city = City.find_or_create_by(name: data.strip) {|record| record.area = DOMESTIC} city_id = city.id ```
    • Ngô Trung Hưng @hungnt

      changed this line in version 3 of the diff

      Jul 28, 2020

      changed this line in version 3 of the diff

      changed this line in [version 3 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4876&start_sha=12437310c9623b87f7735b9c318a36d41fb68887#fb47c56e27671d261a144b62e44604e1e9e53666_82_79)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 28, 2020
    Last updated by Ngô Trung Hưng Jul 29, 2020
    lib/service/import_data.rb 0 → 100644
    1 # frozen_string_literal: true
    2
    3 require 'service/ftp'
    4
    5 # Import data from CSV
    6 class ImportDataCSV
    7 DOMESTIC = 1
    • Hoang Phuc Do @phucdh commented Jul 28, 2020
      Master

      Giá trị này thuộc phần xử lý của model City

      => Chuyển giá trị này vào app/models/city.rb

      Tham khảo cách sử dụng enum trong Rails

      Edited Jul 28, 2020 by Hoang Phuc Do
      Giá trị này thuộc phần xử lý của model City => Chuyển giá trị này vào `app/models/city.rb` Tham khảo cách sử dụng `enum trong Rails`
    • Ngô Trung Hưng @hungnt

      changed this line in version 7 of the diff

      Jul 29, 2020

      changed this line in version 7 of the diff

      changed this line in [version 7 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4883&start_sha=4a5093e8b766b3ad3354ee974008fb8b3573613a#fb47c56e27671d261a144b62e44604e1e9e53666_7_7)
      Toggle commit list
    Please register or sign in to reply
  • Thanh Hung Pham
    @hungpt started a discussion on an old version of the diff Jul 28, 2020
    Last updated by Ngô Trung Hưng Jul 28, 2020
    lib/service/ftp.rb 0 → 100644
    1 # frozen_string_literal: true
    2
    3 require 'service/unzip'
    4 require 'net/ftp'
    5 require 'csv'
    6
    7 # Access Ftp Server get file & extract file
    8 class FtpSever
    9 CONTENT_SERVER_DOMAIN_NAME = '192.168.1.156'
    10 CONTENT_SERVER_USER_NAME = 'training'
    11 CONTENT_SERVER_USER_PASSWORD = 'training'
    12 def self.donwload_csv
    13 Net::FTP.open(CONTENT_SERVER_DOMAIN_NAME, CONTENT_SERVER_USER_NAME, CONTENT_SERVER_USER_PASSWORD) do |ftp|
    14 begin
    15 ftp.getbinaryfile('jobs.zip')
    16 extract_zip('./jobs.zip', 'lib/csv')
    • Thanh Hung Pham @hungpt commented Jul 28, 2020

      @hungnt ./jobss.zip anh thấy dùng lại nhiều. có thể khai báo constant nè em.

      @hungnt `./jobss.zip` anh thấy dùng lại nhiều. có thể khai báo constant nè em.
    • Ngô Trung Hưng @hungnt

      changed this line in version 3 of the diff

      Jul 28, 2020

      changed this line in version 3 of the diff

      changed this line in [version 3 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4876&start_sha=12437310c9623b87f7735b9c318a36d41fb68887#be323995e1d126ac08c5f0e850661b3809f8d098_16_19)
      Toggle commit list
    • Ngô Trung Hưng @hungnt commented Jul 28, 2020
      Master

      Dạ anh

      Dạ anh
    Please register or sign in to reply
  • Ngô Trung Hưng @hungnt

    added 1 commit

    • 0f57f980 - fix import data from csv

    Compare with previous version

    Jul 28, 2020

    added 1 commit

    • 0f57f980 - fix import data from csv

    Compare with previous version

    added 1 commit * 0f57f980 - fix import data from csv [Compare with previous version](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4876&start_sha=12437310c9623b87f7735b9c318a36d41fb68887)
    Toggle commit list
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 29, 2020
    Resolved by Hoang Phuc Do Jul 29, 2020
    lib/service/ftp.rb 0 → 100644
    4 require 'net/ftp'
    5 require 'logger'
    6 require 'csv'
    7
    8 # Access Ftp Server get file & extract file
    9 class FtpSever
    10 CONTENT_SERVER_DOMAIN_NAME = '192.168.1.156'
    11 CONTENT_SERVER_USER_NAME = 'training'
    12 CONTENT_SERVER_USER_PASSWORD = 'training'
    13
    14 @logger ||= Logger.new("#{Rails.root}/log/csv.log")
    15 def self.donwload_csv
    16 Net::FTP.open(CONTENT_SERVER_DOMAIN_NAME, CONTENT_SERVER_USER_NAME, CONTENT_SERVER_USER_PASSWORD) do |ftp|
    17 begin
    18 ftp.getbinaryfile('jobs.zip')
    19 Unzip.extract_zip('./jobs.zip', 'lib/csv')
    • Hoang Phuc Do @phucdh commented Jul 29, 2020
      Master
      Unzip.extract_zip(Rails.root.join('jobs.zip'), Rails.root.join('lib', 'csv'))
      Edited Jul 29, 2020
      ```ruby Unzip.extract_zip(Rails.root.join('jobs.zip'), Rails.root.join('lib', 'csv')) ```
    • Ngô Trung Hưng @hungnt

      changed this line in version 4 of the diff

      Jul 29, 2020

      changed this line in version 4 of the diff

      changed this line in [version 4 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4877&start_sha=0f57f980cfcc2063222cfb2bff46f93d364b80d7#be323995e1d126ac08c5f0e850661b3809f8d098_19_15)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 29, 2020
    Resolved by Hoang Phuc Do Jul 29, 2020
    lib/service/ftp.rb 0 → 100644
    5 require 'logger'
    6 require 'csv'
    7
    8 # Access Ftp Server get file & extract file
    9 class FtpSever
    10 CONTENT_SERVER_DOMAIN_NAME = '192.168.1.156'
    11 CONTENT_SERVER_USER_NAME = 'training'
    12 CONTENT_SERVER_USER_PASSWORD = 'training'
    13
    14 @logger ||= Logger.new("#{Rails.root}/log/csv.log")
    15 def self.donwload_csv
    16 Net::FTP.open(CONTENT_SERVER_DOMAIN_NAME, CONTENT_SERVER_USER_NAME, CONTENT_SERVER_USER_PASSWORD) do |ftp|
    17 begin
    18 ftp.getbinaryfile('jobs.zip')
    19 Unzip.extract_zip('./jobs.zip', 'lib/csv')
    20 File.delete('./jobs.zip') if File.exist?('./jobs.zip')
    • Hoang Phuc Do @phucdh commented Jul 29, 2020
      Master
      File.delete(Rails.root.join('jobs.zip')) if File.exist?(Rails.root.join('jobs.zip'))
      Edited Jul 29, 2020
      ```ruby File.delete(Rails.root.join('jobs.zip')) if File.exist?(Rails.root.join('jobs.zip')) ```
    • Ngô Trung Hưng @hungnt

      changed this line in version 4 of the diff

      Jul 29, 2020

      changed this line in version 4 of the diff

      changed this line in [version 4 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4877&start_sha=0f57f980cfcc2063222cfb2bff46f93d364b80d7#be323995e1d126ac08c5f0e850661b3809f8d098_20_15)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 29, 2020
    Last updated by Ngô Trung Hưng Jul 29, 2020
    lib/service/import_data.rb 0 → 100644
    70 puts index
    71 rescue StandardError => e
    72 puts e
    73 end
    74 end
    75 end
    76
    77 def make_foreign_cities_table(data, id_job)
    78 data = data.to_s.delete('[]\"')
    79 city = City.find_or_create_by(name: data.strip) { |record| record.area = DOMESTIC }
    80 city_id = city.id
    81 CityJob.create!(job_id: id_job, city_id: city_id)
    82 end
    83
    84 def make_foreign_industries_table(data, id_job)
    85 data = data.to_s.gsub(',', '/').gsub('/', ' / ')
    • Hoang Phuc Do @phucdh commented Jul 29, 2020
      Master

      Giá trị này có vẻ được dùng để làm industry name. Tên biến data có nghĩa khá rộng và không phản ảnh được mục đích sử dụng

      data => industry_name

      Ngoài ra, hạn chế đặt tên biến trùng với tham số của method.

      Giá trị này có vẻ được dùng để làm industry name. Tên biến `data` có nghĩa khá rộng và không phản ảnh được mục đích sử dụng `data` => `industry_name` Ngoài ra, hạn chế đặt tên biến trùng với tham số của method.
    • Ngô Trung Hưng @hungnt

      changed this line in version 5 of the diff

      Jul 29, 2020

      changed this line in version 5 of the diff

      changed this line in [version 5 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4878&start_sha=a3ce51adef9704cfe3f6f358ce67bfe1a6f8363d#fb47c56e27671d261a144b62e44604e1e9e53666_85_85)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 29, 2020
    Last updated by Ngô Trung Hưng Jul 29, 2020
    lib/service/import_data.rb 0 → 100644
    73 end
    74 end
    75 end
    76
    77 def make_foreign_cities_table(data, id_job)
    78 data = data.to_s.delete('[]\"')
    79 city = City.find_or_create_by(name: data.strip) { |record| record.area = DOMESTIC }
    80 city_id = city.id
    81 CityJob.create!(job_id: id_job, city_id: city_id)
    82 end
    83
    84 def make_foreign_industries_table(data, id_job)
    85 data = data.to_s.gsub(',', '/').gsub('/', ' / ')
    86 industry = Industry.find_or_create_by(name: data.strip)
    87 industry_id = industry.id
    88 IndustryJob.create!(industry_id: industry_id, job_id: id_job)
    • Hoang Phuc Do @phucdh commented Jul 29, 2020
      Master

      Sử dụng create! sẽ raise lỗi khi không lưu được record xuống DB.

      Việc raise lỗi ở đây nhằm mục đích gì ?

      Edited Jul 29, 2020 by Hoang Phuc Do
      Sử dụng `create!` sẽ raise lỗi khi không lưu được record xuống DB. Việc raise lỗi ở đây nhằm mục đích gì ?
    • Ngô Trung Hưng @hungnt

      changed this line in version 5 of the diff

      Jul 29, 2020

      changed this line in version 5 of the diff

      changed this line in [version 5 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4878&start_sha=a3ce51adef9704cfe3f6f358ce67bfe1a6f8363d#fb47c56e27671d261a144b62e44604e1e9e53666_88_88)
      Toggle commit list
    Please register or sign in to reply
  • Ngô Trung Hưng @hungnt

    added 1 commit

    • a3ce51ad - fix bug

    Compare with previous version

    Jul 29, 2020

    added 1 commit

    • a3ce51ad - fix bug

    Compare with previous version

    added 1 commit * a3ce51ad - fix bug [Compare with previous version](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4877&start_sha=0f57f980cfcc2063222cfb2bff46f93d364b80d7)
    Toggle commit list
  • Ngô Trung Hưng @hungnt

    added 1 commit

    • cde1c3b4 - fix -part4

    Compare with previous version

    Jul 29, 2020

    added 1 commit

    • cde1c3b4 - fix -part4

    Compare with previous version

    added 1 commit * cde1c3b4 - fix -part4 [Compare with previous version](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4878&start_sha=a3ce51adef9704cfe3f6f358ce67bfe1a6f8363d)
    Toggle commit list
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 29, 2020
    Last updated by Ngô Trung Hưng Jul 29, 2020
    lib/service/ftp.rb 0 → 100644
    2
    3 require 'service/unzip'
    4 require 'net/ftp'
    5 require 'logger'
    6 require 'csv'
    7
    8 # Access Ftp Server get file & extract file
    9 class FtpSever
    10 CONTENT_SERVER_DOMAIN_NAME = '192.168.1.156'
    11 CONTENT_SERVER_USER_NAME = 'training'
    12 CONTENT_SERVER_USER_PASSWORD = 'training'
    13 NAME_CSV = 'jobs.zip'
    14
    15 def data_csv
    16 donwload_csv
    17 CSV.parse(File.read('lib/csv/jobs.csv'), headers: true)
    • Hoang Phuc Do @phucdh commented Jul 29, 2020
      Master
      CSV.parse(File.read(Rails.root.join('lib', 'csv', 'jobs.csv')), headers: true)
      ```ruby CSV.parse(File.read(Rails.root.join('lib', 'csv', 'jobs.csv')), headers: true) ```
    • Ngô Trung Hưng @hungnt

      changed this line in version 6 of the diff

      Jul 29, 2020

      changed this line in version 6 of the diff

      changed this line in [version 6 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4879&start_sha=cde1c3b479ed1325e63a124014d791188b0a31fd#be323995e1d126ac08c5f0e850661b3809f8d098_17_16)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 29, 2020
    Last updated by Ngô Trung Hưng Jul 29, 2020
    lib/service/ftp.rb 0 → 100644
    11 CONTENT_SERVER_USER_NAME = 'training'
    12 CONTENT_SERVER_USER_PASSWORD = 'training'
    13 NAME_CSV = 'jobs.zip'
    14
    15 def data_csv
    16 donwload_csv
    17 CSV.parse(File.read('lib/csv/jobs.csv'), headers: true)
    18 end
    19
    20 def logger
    21 @logger ||= Logger.new(Rails.root.join('log', 'csv.log'))
    22 end
    23
    24 private
    25
    26 def donwload_csv
    • Hoang Phuc Do @phucdh commented Jul 29, 2020
      Master

      donwload_csv => download_csv

      `donwload_csv` => `download_csv`
    • Ngô Trung Hưng @hungnt

      changed this line in version 6 of the diff

      Jul 29, 2020

      changed this line in version 6 of the diff

      changed this line in [version 6 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4879&start_sha=cde1c3b479ed1325e63a124014d791188b0a31fd#be323995e1d126ac08c5f0e850661b3809f8d098_26_26)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 29, 2020
    Last updated by Ngô Trung Hưng Jul 29, 2020
    lib/service/ftp.rb 0 → 100644
    16 donwload_csv
    17 CSV.parse(File.read('lib/csv/jobs.csv'), headers: true)
    18 end
    19
    20 def logger
    21 @logger ||= Logger.new(Rails.root.join('log', 'csv.log'))
    22 end
    23
    24 private
    25
    26 def donwload_csv
    27 Net::FTP.open(CONTENT_SERVER_DOMAIN_NAME, CONTENT_SERVER_USER_NAME, CONTENT_SERVER_USER_PASSWORD) do |ftp|
    28 ftp.getbinaryfile(NAME_CSV)
    29 Unzip.extract_zip(Rails.root.join(NAME_CSV), Rails.root.join('lib', 'csv'))
    30 File.delete(Rails.root.join(NAME_CSV)) if File.exist?(Rails.root.join(NAME_CSV))
    31 logger.info 'Donwload & extract success'
    • Hoang Phuc Do @phucdh commented Jul 29, 2020
      Master
      logger.info 'Download & extract success'
      ```ruby logger.info 'Download & extract success' ```
    • Ngô Trung Hưng @hungnt

      changed this line in version 6 of the diff

      Jul 29, 2020

      changed this line in version 6 of the diff

      changed this line in [version 6 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4879&start_sha=cde1c3b479ed1325e63a124014d791188b0a31fd#be323995e1d126ac08c5f0e850661b3809f8d098_31_33)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 29, 2020
    Last updated by Ngô Trung Hưng Jul 29, 2020
    lib/service/ftp.rb 0 → 100644
    15 def data_csv
    16 donwload_csv
    17 CSV.parse(File.read('lib/csv/jobs.csv'), headers: true)
    18 end
    19
    20 def logger
    21 @logger ||= Logger.new(Rails.root.join('log', 'csv.log'))
    22 end
    23
    24 private
    25
    26 def donwload_csv
    27 Net::FTP.open(CONTENT_SERVER_DOMAIN_NAME, CONTENT_SERVER_USER_NAME, CONTENT_SERVER_USER_PASSWORD) do |ftp|
    28 ftp.getbinaryfile(NAME_CSV)
    29 Unzip.extract_zip(Rails.root.join(NAME_CSV), Rails.root.join('lib', 'csv'))
    30 File.delete(Rails.root.join(NAME_CSV)) if File.exist?(Rails.root.join(NAME_CSV))
    • Hoang Phuc Do @phucdh commented Jul 29, 2020
      Master

      Rails.root.join(NAME_CSV) bị lặp lại

      Có thể gán thành một biến hoặc một method

      `Rails.root.join(NAME_CSV)` bị lặp lại Có thể gán thành một biến hoặc một method
    • Ngô Trung Hưng @hungnt commented Jul 29, 2020
      Master

      Rails.root.join(NAME_CSV) e sẽ cho nó vào method, anh gợi ý cho e 1 cái tên method đi

      Rails.root.join(NAME_CSV) e sẽ cho nó vào method, anh gợi ý cho e 1 cái tên method đi
    • Hoang Phuc Do @phucdh commented Jul 29, 2020
      Master

      Có thể dựa vào các tiêu chí sau để đặt tên phù hợp:

      • Kiểu dữ liệu trả về
      • Ngữ cảnh sử dụng

      Trong trường hợp này, có thể phân tích như sau:

      • Giá trị là đường dẫn của file csv
      • Chứa các dữ liệu dành cho job

      => Tên phù hợp có thể là jobs_csv_path

      Có thể dựa vào các tiêu chí sau để đặt tên phù hợp: - Kiểu dữ liệu trả về - Ngữ cảnh sử dụng Trong trường hợp này, có thể phân tích như sau: - Giá trị là đường dẫn của file csv - Chứa các dữ liệu dành cho job => Tên phù hợp có thể là `jobs_csv_path`
    • Ngô Trung Hưng @hungnt

      changed this line in version 6 of the diff

      Jul 29, 2020

      changed this line in version 6 of the diff

      changed this line in [version 6 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4879&start_sha=cde1c3b479ed1325e63a124014d791188b0a31fd#be323995e1d126ac08c5f0e850661b3809f8d098_30_33)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 29, 2020
    Last updated by Ngô Trung Hưng Jul 29, 2020
    lib/service/import_data.rb 0 → 100644
    14 import_companies_from(csv_data)
    15 import_jobs_from(csv_data)
    16 end
    17
    18 private
    19
    20 def import_industries_from(csv)
    21 puts 'Import data industries . . .'
    22 industries = []
    23 industries += csv['category'].map(&:strip)
    24 industries.each do |val|
    25 val.gsub!(',', '/') if val.include?(',')
    26 val.gsub!('/', ' / ')
    27 Industry.find_or_create_by(name: val)
    28 end
    29 puts 'Done parse csv industries'
    • Hoang Phuc Do @phucdh commented Jul 29, 2020
      Master

      Trong này cũng nên sử dụng logger

      Trong này cũng nên sử dụng logger
    • Ngô Trung Hưng @hungnt

      changed this line in version 6 of the diff

      Jul 29, 2020

      changed this line in version 6 of the diff

      changed this line in [version 6 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4879&start_sha=cde1c3b479ed1325e63a124014d791188b0a31fd#fb47c56e27671d261a144b62e44604e1e9e53666_29_32)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 29, 2020
    Last updated by Ngô Trung Hưng Jul 29, 2020
    lib/service/import_data.rb 0 → 100644
    66 create_date: Time.now,
    67 description: desc)
    68 make_foreign_cities_table(csv['work place'][index], job.id)
    69 make_foreign_industries_table(csv['category'][index], job.id)
    70 puts index
    71 rescue StandardError => e
    72 puts e
    73 end
    74 end
    75 end
    76
    77 def make_foreign_cities_table(data, id_job)
    78 data = data.to_s.delete('[]\"')
    79 city = City.find_or_create_by(name: data.strip) { |record| record.area = DOMESTIC }
    80 city_id = city.id
    81 CityJob.create(job_id: id_job, city_id: city_id)
    • Hoang Phuc Do @phucdh commented Jul 29, 2020
      Master

      Ngoài cách gán job_id trực tiếp, có thể tạo dữ liệu cho association thông qua object job không ?

      Ngoài cách gán `job_id` trực tiếp, có thể tạo dữ liệu cho association thông qua object `job` không ?
    • Ngô Trung Hưng @hungnt

      changed this line in version 6 of the diff

      Jul 29, 2020

      changed this line in version 6 of the diff

      changed this line in [version 6 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4879&start_sha=cde1c3b479ed1325e63a124014d791188b0a31fd#fb47c56e27671d261a144b62e44604e1e9e53666_81_84)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 29, 2020
    Last updated by Ngô Trung Hưng Jul 29, 2020
    lib/service/import_data.rb 0 → 100644
    47 company.address = csv['company address'][index]
    48 company.short_description = csv['benefit'][index]
    49 end
    50 puts index
    51 rescue StandardError => e
    52 puts e
    53 end
    54 end
    55
    56 def import_jobs_from(csv)
    57 csv['name'].each_with_index do |name, index|
    58 desc = "#{csv['requirement'][index]} #{(csv['description'][index])}"
    59 company = Company.find_by name: csv['company name'][index].to_s.strip
    60 company_id = company.blank? ? COMPANY_SECURITY : company.id
    61 begin
    62 job = Job.create!(name: name,
    • Hoang Phuc Do @phucdh commented Jul 29, 2020
      Master

      Nếu ở đây việc tạo job bị fail thì sẽ ngừng luôn việc xử lý.

      Có thể xử lý để tiếp tục thực hiện import tiếp các job khác không ?

      Nếu ở đây việc tạo job bị fail thì sẽ ngừng luôn việc xử lý. Có thể xử lý để tiếp tục thực hiện import tiếp các job khác không ?
    • Ngô Trung Hưng @hungnt

      changed this line in version 6 of the diff

      Jul 29, 2020

      changed this line in version 6 of the diff

      changed this line in [version 6 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4879&start_sha=cde1c3b479ed1325e63a124014d791188b0a31fd#fb47c56e27671d261a144b62e44604e1e9e53666_62_65)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 29, 2020
    Last updated by Ngô Trung Hưng Jul 29, 2020
    lib/service/import_data.rb 0 → 100644
    19
    20 def import_industries_from(csv)
    21 puts 'Import data industries . . .'
    22 industries = []
    23 industries += csv['category'].map(&:strip)
    24 industries.each do |val|
    25 val.gsub!(',', '/') if val.include?(',')
    26 val.gsub!('/', ' / ')
    27 Industry.find_or_create_by(name: val)
    28 end
    29 puts 'Done parse csv industries'
    30 end
    31
    32 def import_cities_from(csv)
    33 puts 'Import data cities . . .'
    34 cities = csv['work place'].uniq.select(&:present?)
    • Hoang Phuc Do @phucdh commented Jul 29, 2020
      Master

      Tên phù hợp hơn có thể là city_names

      Tên phù hợp hơn có thể là `city_names`
    • Ngô Trung Hưng @hungnt

      changed this line in version 6 of the diff

      Jul 29, 2020

      changed this line in version 6 of the diff

      changed this line in [version 6 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4879&start_sha=cde1c3b479ed1325e63a124014d791188b0a31fd#fb47c56e27671d261a144b62e44604e1e9e53666_34_37)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 29, 2020
    Last updated by Ngô Trung Hưng Jul 29, 2020
    lib/service/import_data.rb 0 → 100644
    51 rescue StandardError => e
    52 puts e
    53 end
    54 end
    55
    56 def import_jobs_from(csv)
    57 csv['name'].each_with_index do |name, index|
    58 desc = "#{csv['requirement'][index]} #{(csv['description'][index])}"
    59 company = Company.find_by name: csv['company name'][index].to_s.strip
    60 company_id = company.blank? ? COMPANY_SECURITY : company.id
    61 begin
    62 job = Job.create!(name: name,
    63 company_id: company_id,
    64 level: csv['level'][index],
    65 salary: csv['salary'][index],
    66 create_date: Time.now,
    • Hoang Phuc Do @phucdh commented Jul 29, 2020
      Master

      Time.now và Time.current, có sự khác biệt gì không ?

      `Time.now` và `Time.current`, có sự khác biệt gì không ?
    • Ngô Trung Hưng @hungnt commented Jul 29, 2020
      Master

      Time.current sẽ trả về Time.zone.now khi Time.zone hoặc config.time_zone được đặt Time.now trả về thời gian hiện tại

      Time.current sẽ trả về Time.zone.now khi Time.zone hoặc config.time_zone được đặt Time.now trả về thời gian hiện tại
    • Ngô Trung Hưng @hungnt

      changed this line in version 6 of the diff

      Jul 29, 2020

      changed this line in version 6 of the diff

      changed this line in [version 6 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4879&start_sha=cde1c3b479ed1325e63a124014d791188b0a31fd#fb47c56e27671d261a144b62e44604e1e9e53666_66_65)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 29, 2020
    Last updated by Ngô Trung Hưng Jul 29, 2020
    lib/service/import_data.rb 0 → 100644
    53 end
    54 end
    55
    56 def import_jobs_from(csv)
    57 csv['name'].each_with_index do |name, index|
    58 desc = "#{csv['requirement'][index]} #{(csv['description'][index])}"
    59 company = Company.find_by name: csv['company name'][index].to_s.strip
    60 company_id = company.blank? ? COMPANY_SECURITY : company.id
    61 begin
    62 job = Job.create!(name: name,
    63 company_id: company_id,
    64 level: csv['level'][index],
    65 salary: csv['salary'][index],
    66 create_date: Time.now,
    67 description: desc)
    68 make_foreign_cities_table(csv['work place'][index], job.id)
    • Hoang Phuc Do @phucdh commented Jul 29, 2020
      Master

      Tên phù hợp có thể là create_city_relation

      Tên phù hợp có thể là `create_city_relation`
    • Ngô Trung Hưng @hungnt

      changed this line in version 6 of the diff

      Jul 29, 2020

      changed this line in version 6 of the diff

      changed this line in [version 6 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4879&start_sha=cde1c3b479ed1325e63a124014d791188b0a31fd#fb47c56e27671d261a144b62e44604e1e9e53666_68_65)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 29, 2020
    Last updated by Ngô Trung Hưng Jul 29, 2020
    lib/service/import_data.rb 0 → 100644
    54 end
    55
    56 def import_jobs_from(csv)
    57 csv['name'].each_with_index do |name, index|
    58 desc = "#{csv['requirement'][index]} #{(csv['description'][index])}"
    59 company = Company.find_by name: csv['company name'][index].to_s.strip
    60 company_id = company.blank? ? COMPANY_SECURITY : company.id
    61 begin
    62 job = Job.create!(name: name,
    63 company_id: company_id,
    64 level: csv['level'][index],
    65 salary: csv['salary'][index],
    66 create_date: Time.now,
    67 description: desc)
    68 make_foreign_cities_table(csv['work place'][index], job.id)
    69 make_foreign_industries_table(csv['category'][index], job.id)
    • Hoang Phuc Do @phucdh commented Jul 29, 2020
      Master

      Tên phù hợp có thể là create_industry_relation

      Tên phù hợp có thể là `create_industry_relation`
    • Ngô Trung Hưng @hungnt

      changed this line in version 6 of the diff

      Jul 29, 2020

      changed this line in version 6 of the diff

      changed this line in [version 6 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4879&start_sha=cde1c3b479ed1325e63a124014d791188b0a31fd#fb47c56e27671d261a144b62e44604e1e9e53666_69_65)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 29, 2020
    Last updated by Ngô Trung Hưng Jul 29, 2020
    lib/service/import_data.rb 0 → 100644
    45 csv['company name'].each_with_index do |name, index|
    46 Company.find_or_create_by(name: name.strip) do |company|
    47 company.address = csv['company address'][index]
    48 company.short_description = csv['benefit'][index]
    49 end
    50 puts index
    51 rescue StandardError => e
    52 puts e
    53 end
    54 end
    55
    56 def import_jobs_from(csv)
    57 csv['name'].each_with_index do |name, index|
    58 desc = "#{csv['requirement'][index]} #{(csv['description'][index])}"
    59 company = Company.find_by name: csv['company name'][index].to_s.strip
    60 company_id = company.blank? ? COMPANY_SECURITY : company.id
    • Hoang Phuc Do @phucdh commented Jul 29, 2020
      Master

      Một số cách khác

      company_id = company.try(:id) || COMPANY_SECURITY
      company_id = company&.id || COMPANY_SECURITY

      Có gì khác giữa try(:id) và &.id

      Một số cách khác ```ruby company_id = company.try(:id) || COMPANY_SECURITY ``` ```ruby company_id = company&.id || COMPANY_SECURITY ``` Có gì khác giữa `try(:id)` và `&.id`
    • Ngô Trung Hưng @hungnt

      changed this line in version 6 of the diff

      Jul 29, 2020

      changed this line in version 6 of the diff

      changed this line in [version 6 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4879&start_sha=cde1c3b479ed1325e63a124014d791188b0a31fd#fb47c56e27671d261a144b62e44604e1e9e53666_60_63)
      Toggle commit list
    Please register or sign in to reply
  • Ngô Trung Hưng @hungnt

    added 1 commit

    • 4a5093e8 - fix -part 5

    Compare with previous version

    Jul 29, 2020

    added 1 commit

    • 4a5093e8 - fix -part 5

    Compare with previous version

    added 1 commit * 4a5093e8 - fix -part 5 [Compare with previous version](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4879&start_sha=cde1c3b479ed1325e63a124014d791188b0a31fd)
    Toggle commit list
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 29, 2020
    Last updated by Ngô Trung Hưng Jul 29, 2020
    lib/service/import_data.rb 0 → 100644
    27 industries.each do |val|
    28 val.gsub!(',', '/') if val.include?(',')
    29 val.gsub!('/', ' / ')
    30 Industry.find_or_create_by(name: val)
    31 end
    32 rescue StandardError => e
    33 logger.error "Import_industries: #{e}"
    34 end
    35
    36 def import_cities_from(csv)
    37 city_names = csv['work place'].uniq.select(&:present?)
    38 cities = city_names.map { |val| val.delete('[]\"') }
    39 cities.each do |val|
    40 next if val.blank?
    41
    42 City.find_or_create_by(name: val) { |city| city.area = DOMESTIC }
    • Hoang Phuc Do @phucdh commented Jul 29, 2020
      Master

      area của city luôn cố định là DOMESTIC

      Vậy có thể chuyển thành như vậy không ?

      City.find_or_create_by(name: val, area: DOMESTIC)
      area của city luôn cố định là `DOMESTIC` Vậy có thể chuyển thành như vậy không ? ```ruby City.find_or_create_by(name: val, area: DOMESTIC) ```
    • Ngô Trung Hưng @hungnt

      changed this line in version 7 of the diff

      Jul 29, 2020

      changed this line in version 7 of the diff

      changed this line in [version 7 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4883&start_sha=4a5093e8b766b3ad3354ee974008fb8b3573613a#fb47c56e27671d261a144b62e44604e1e9e53666_42_41)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 29, 2020
    Last updated by Ngô Trung Hưng Aug 05, 2020
    lib/service/import_data.rb 0 → 100644
    50 Company.find_or_create_by(name: name.strip) do |company|
    51 company.address = csv['company address'][index]
    52 company.short_description = csv['benefit'][index]
    53 end
    54 rescue StandardError => e
    55 logger.error "Import_companies: #{e}"
    56 end
    57 end
    58
    59 def import_jobs_from(csv)
    60 csv['name'].each_with_index do |name, index|
    61 desc = "#{csv['requirement'][index]} #{(csv['description'][index])}"
    62 company = Company.find_by name: csv['company name'][index].to_s.strip
    63 company_id = company.try(:id) || COMPANY_SECURITY
    64 begin
    65 job = Job.create(name: name,
    • Hoang Phuc Do @phucdh commented Jul 29, 2020
      Master

      Với cách khai báo như dưới đây thì có khác gì khác biệt so với cách trên về cách lưu dữ liệu vào DB

      job = Job.new(name: name, ...)
      job.cities << city
      job.industries << industry
      job.save
      Với cách khai báo như dưới đây thì có khác gì khác biệt so với cách trên về cách lưu dữ liệu vào DB ```ruby job = Job.new(name: name, ...) job.cities << city job.industries << industry job.save ```
    • Ngô Trung Hưng @hungnt

      changed this line in version 8 of the diff

      Aug 05, 2020

      changed this line in version 8 of the diff

      changed this line in [version 8 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4940&start_sha=56cba0abef7d828237434dfec53234465052491e#fb47c56e27671d261a144b62e44604e1e9e53666_64_33)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 29, 2020
    Last updated by Ngô Trung Hưng Aug 05, 2020
    lib/service/import_data.rb 0 → 100644
    57 end
    58
    59 def import_jobs_from(csv)
    60 csv['name'].each_with_index do |name, index|
    61 desc = "#{csv['requirement'][index]} #{(csv['description'][index])}"
    62 company = Company.find_by name: csv['company name'][index].to_s.strip
    63 company_id = company.try(:id) || COMPANY_SECURITY
    64 begin
    65 job = Job.create(name: name,
    66 company_id: company_id,
    67 level: csv['level'][index],
    68 salary: csv['salary'][index],
    69 create_date: Time.now,
    70 description: desc)
    71 city_names = csv['work place'][index].to_s.delete('[]\"')
    72 city = City.find_or_create_by(name: city_names.strip) { |record| record.area = DOMESTIC }
    • Hoang Phuc Do @phucdh commented Jul 29, 2020
      Master

      Có thể chuyển thành một method nếu dùng nhiều chỗ

      Có thể chuyển thành một method nếu dùng nhiều chỗ
    • Ngô Trung Hưng @hungnt

      changed this line in version 8 of the diff

      Aug 05, 2020

      changed this line in version 8 of the diff

      changed this line in [version 8 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4940&start_sha=56cba0abef7d828237434dfec53234465052491e#fb47c56e27671d261a144b62e44604e1e9e53666_71_33)
      Toggle commit list
    Please register or sign in to reply
  • Hoang Phuc Do
    @phucdh started a discussion on an old version of the diff Jul 29, 2020
    Last updated by Ngô Trung Hưng Aug 05, 2020
    lib/service/import_data.rb 0 → 100644
    57 end
    58
    59 def import_jobs_from(csv)
    60 csv['name'].each_with_index do |name, index|
    61 desc = "#{csv['requirement'][index]} #{(csv['description'][index])}"
    62 company = Company.find_by name: csv['company name'][index].to_s.strip
    63 company_id = company.try(:id) || COMPANY_SECURITY
    64 begin
    65 job = Job.create(name: name,
    66 company_id: company_id,
    67 level: csv['level'][index],
    68 salary: csv['salary'][index],
    69 create_date: Time.now,
    70 description: desc)
    71 city_names = csv['work place'][index].to_s.delete('[]\"')
    72 city = City.find_or_create_by(name: city_names.strip) { |record| record.area = DOMESTIC }
    • Hoang Phuc Do @phucdh commented Jul 29, 2020
      Master

      Có thể chuyển thành một method nếu dùng nhiều chỗ

      Có thể chuyển thành một method nếu dùng nhiều chỗ
    • Ngô Trung Hưng @hungnt

      changed this line in version 8 of the diff

      Aug 05, 2020

      changed this line in version 8 of the diff

      changed this line in [version 8 of the diff](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4940&start_sha=56cba0abef7d828237434dfec53234465052491e#fb47c56e27671d261a144b62e44604e1e9e53666_71_33)
      Toggle commit list
    Please register or sign in to reply
  • Ngô Trung Hưng @hungnt

    added 1 commit

    • 56cba0ab - fix bug

    Compare with previous version

    Jul 29, 2020

    added 1 commit

    • 56cba0ab - fix bug

    Compare with previous version

    added 1 commit * 56cba0ab - fix bug [Compare with previous version](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4883&start_sha=4a5093e8b766b3ad3354ee974008fb8b3573613a)
    Toggle commit list
  • Ngô Trung Hưng @hungnt

    added 1 commit

    • 0924d8d3 - fix bug import csv

    Compare with previous version

    Aug 05, 2020

    added 1 commit

    • 0924d8d3 - fix bug import csv

    Compare with previous version

    added 1 commit * 0924d8d3 - fix bug import csv [Compare with previous version](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4940&start_sha=56cba0abef7d828237434dfec53234465052491e)
    Toggle commit list
  • Ngô Trung Hưng @hungnt

    added 1 commit

    • 4c77e3c8 - fix bug

    Compare with previous version

    Aug 05, 2020

    added 1 commit

    • 4c77e3c8 - fix bug

    Compare with previous version

    added 1 commit * 4c77e3c8 - fix bug [Compare with previous version](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4943&start_sha=0924d8d360759a91f075c01e3e595f3e538c9b0b)
    Toggle commit list
  • Ngô Trung Hưng @hungnt

    added 1 commit

    • ba6efd34 - validate relationship

    Compare with previous version

    Aug 05, 2020

    added 1 commit

    • ba6efd34 - validate relationship

    Compare with previous version

    added 1 commit * ba6efd34 - validate relationship [Compare with previous version](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4946&start_sha=4c77e3c8bfee321abed234279b0de27e1fab4d3c)
    Toggle commit list
  • Ngô Trung Hưng @hungnt

    added 31 commits

    • ba6efd34...c6b99ebd - 30 commits from branch master
    • 1fb23a64 - Merge branch 'master' into 'csv'

    Compare with previous version

    Aug 05, 2020

    added 31 commits

    • ba6efd34...c6b99ebd - 30 commits from branch master
    • 1fb23a64 - Merge branch 'master' into 'csv'

    Compare with previous version

    added 31 commits * ba6efd34...c6b99ebd - 30 commits from branch `master` * 1fb23a64 - Merge branch &#x27;master&#x27; into &#x27;csv&#x27; [Compare with previous version](https://gitlab.zigexn.vn/hungnt/venjob_nth/merge_requests/3/diffs?diff_id=4951&start_sha=ba6efd3410ff91ee5f12f9de7e09e5e495a9c7bc)
    Toggle commit list
  • Hoang Phuc Do @phucdh

    mentioned in commit c5992cdd

    Aug 05, 2020

    mentioned in commit c5992cdd

    mentioned in commit c5992cdd55361f6cdf47f7bb12440ec4e8ee5f1a
    Toggle commit list
  • Hoang Phuc Do @phucdh

    merged

    Aug 05, 2020

    merged

    merged
    Toggle commit list
  • Write
  • Preview
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment
Assignee
No assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
3
3 participants
Reference: hungnt/venjob_nth!3
×

Revert this merge request

Switch branch
Cancel
A new branch will be created in your fork and a new merge request will be started.
×

Cherry-pick this merge request

Switch branch
Cancel
A new branch will be created in your fork and a new merge request will be started.