Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
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
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ngô Trung Hưng
venjob_nth
Commits
4a5093e8
Commit
4a5093e8
authored
Jul 29, 2020
by
Ngô Trung Hưng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix -part 5
parent
cde1c3b4
Pipeline
#733
failed with stages
in 0 seconds
Changes
15
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
58 additions
and
60 deletions
+58
-60
app/models/city.rb
+1
-1
config/database.yml
+1
-1
db/migrate/20200728020937_create_companies.rb
+1
-1
db/migrate/20200728021021_create_cities.rb
+1
-1
db/migrate/20200728021030_create_industries.rb
+1
-1
db/migrate/20200728021038_create_jobs.rb
+1
-1
db/migrate/20200728021048_create_histories.rb
+1
-1
db/migrate/20200728021110_create_favorites.rb
+1
-1
db/migrate/20200728021127_create_users.rb
+1
-1
db/migrate/20200728021254_create_city_jobs.rb
+1
-1
db/migrate/20200728021350_create_industry_jobs.rb
+1
-1
db/migrate/20200728021412_create_applied_jobs.rb
+1
-1
db/schema.rb
+10
-10
lib/service/ftp.rb
+10
-6
lib/service/import_data.rb
+26
-32
No files found.
app/models/city.rb
View file @
4a5093e8
...
...
@@ -3,5 +3,5 @@
# Description/Explanation of Person class
class
City
<
ApplicationRecord
has_many
:city_jobs
has_many
:jobs
,
through: :city_jobs
has_many
:jobs
,
through: :city_jobs
end
config/database.yml
View file @
4a5093e8
...
...
@@ -11,7 +11,7 @@
#
default
:
&default
adapter
:
mysql2
encoding
:
utf8
encoding
:
utf8
mb4
pool
:
<%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username
:
root
password
:
'
1'
...
...
db/migrate/20200728020937_create_companies.rb
View file @
4a5093e8
...
...
@@ -3,7 +3,7 @@
# Description/Explanation of Person class
class
CreateCompanies
<
ActiveRecord
::
Migration
[
5.2
]
def
change
create_table
:companies
,
options:
'COLLATE=utf8_general_ci'
do
|
t
|
create_table
:companies
do
|
t
|
t
.
string
:name
t
.
string
:address
t
.
text
:short_description
...
...
db/migrate/20200728021021_create_cities.rb
View file @
4a5093e8
...
...
@@ -3,7 +3,7 @@
# Description/Explanation of Person class
class
CreateCities
<
ActiveRecord
::
Migration
[
5.2
]
def
change
create_table
:cities
,
options:
'COLLATE=utf8_general_ci'
do
|
t
|
create_table
:cities
do
|
t
|
t
.
string
:name
t
.
boolean
:area
t
.
timestamps
...
...
db/migrate/20200728021030_create_industries.rb
View file @
4a5093e8
...
...
@@ -3,7 +3,7 @@
# Description/Explanation of Person class
class
CreateIndustries
<
ActiveRecord
::
Migration
[
5.2
]
def
change
create_table
:industries
,
options:
'COLLATE=utf8_general_ci'
do
|
t
|
create_table
:industries
do
|
t
|
t
.
string
:name
t
.
timestamps
end
...
...
db/migrate/20200728021038_create_jobs.rb
View file @
4a5093e8
...
...
@@ -3,7 +3,7 @@
# Description/Explanation of Person class
class
CreateJobs
<
ActiveRecord
::
Migration
[
5.2
]
def
change
create_table
:jobs
,
options:
'COLLATE=utf8_general_ci'
do
|
t
|
create_table
:jobs
do
|
t
|
t
.
string
:name
t
.
integer
:company_id
t
.
string
:level
...
...
db/migrate/20200728021048_create_histories.rb
View file @
4a5093e8
...
...
@@ -3,7 +3,7 @@
# Description/Explanation of Person class
class
CreateHistories
<
ActiveRecord
::
Migration
[
5.2
]
def
change
create_table
:histories
,
options:
'COLLATE=utf8_general_ci'
do
|
t
|
create_table
:histories
do
|
t
|
t
.
integer
:user_id
t
.
integer
:job_id
t
.
timestamps
...
...
db/migrate/20200728021110_create_favorites.rb
View file @
4a5093e8
...
...
@@ -3,7 +3,7 @@
# Description/Explanation of Person class
class
CreateFavorites
<
ActiveRecord
::
Migration
[
5.2
]
def
change
create_table
:favorites
,
options:
'COLLATE=utf8_general_ci'
do
|
t
|
create_table
:favorites
do
|
t
|
t
.
integer
:user_id
t
.
integer
:job_id
t
.
timestamps
...
...
db/migrate/20200728021127_create_users.rb
View file @
4a5093e8
...
...
@@ -3,7 +3,7 @@
# Description/Explanation of Person class
class
CreateUsers
<
ActiveRecord
::
Migration
[
5.2
]
def
change
create_table
:users
,
options:
'COLLATE=utf8_general_ci'
do
|
t
|
create_table
:users
do
|
t
|
t
.
string
:email
t
.
string
:name
t
.
string
:password_digest
...
...
db/migrate/20200728021254_create_city_jobs.rb
View file @
4a5093e8
...
...
@@ -3,7 +3,7 @@
# Description/Explanation of Person class
class
CreateCityJobs
<
ActiveRecord
::
Migration
[
5.2
]
def
change
create_table
:city_jobs
,
options:
'COLLATE=utf8_general_ci'
do
|
t
|
create_table
:city_jobs
do
|
t
|
t
.
references
:job
t
.
references
:city
t
.
timestamps
...
...
db/migrate/20200728021350_create_industry_jobs.rb
View file @
4a5093e8
...
...
@@ -3,7 +3,7 @@
# Description/Explanation of Person class
class
CreateIndustryJobs
<
ActiveRecord
::
Migration
[
5.2
]
def
change
create_table
:industry_jobs
,
options:
'COLLATE=utf8_general_ci'
do
|
t
|
create_table
:industry_jobs
do
|
t
|
t
.
references
:industry
t
.
references
:job
t
.
timestamps
...
...
db/migrate/20200728021412_create_applied_jobs.rb
View file @
4a5093e8
...
...
@@ -3,7 +3,7 @@
# Description/Explanation of Person class
class
CreateAppliedJobs
<
ActiveRecord
::
Migration
[
5.2
]
def
change
create_table
:applied_jobs
,
options:
'COLLATE=utf8_general_ci'
do
|
t
|
create_table
:applied_jobs
do
|
t
|
t
.
references
:user
t
.
references
:job
t
.
string
:name
...
...
db/schema.rb
View file @
4a5093e8
...
...
@@ -12,7 +12,7 @@
ActiveRecord
::
Schema
.
define
(
version:
2020_07_28_021412
)
do
create_table
"applied_jobs"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
,
force: :cascade
do
|
t
|
create_table
"applied_jobs"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8
mb4
"
,
force: :cascade
do
|
t
|
t
.
bigint
"user_id"
t
.
bigint
"job_id"
t
.
string
"name"
...
...
@@ -24,14 +24,14 @@ ActiveRecord::Schema.define(version: 2020_07_28_021412) do
t
.
index
[
"user_id"
],
name:
"index_applied_jobs_on_user_id"
end
create_table
"cities"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
,
force: :cascade
do
|
t
|
create_table
"cities"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8
mb4
"
,
force: :cascade
do
|
t
|
t
.
string
"name"
t
.
boolean
"area"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
end
create_table
"city_jobs"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
,
force: :cascade
do
|
t
|
create_table
"city_jobs"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8
mb4
"
,
force: :cascade
do
|
t
|
t
.
bigint
"job_id"
t
.
bigint
"city_id"
t
.
datetime
"created_at"
,
null:
false
...
...
@@ -40,7 +40,7 @@ ActiveRecord::Schema.define(version: 2020_07_28_021412) do
t
.
index
[
"job_id"
],
name:
"index_city_jobs_on_job_id"
end
create_table
"companies"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
,
force: :cascade
do
|
t
|
create_table
"companies"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8
mb4
"
,
force: :cascade
do
|
t
|
t
.
string
"name"
t
.
string
"address"
t
.
text
"short_description"
...
...
@@ -48,27 +48,27 @@ ActiveRecord::Schema.define(version: 2020_07_28_021412) do
t
.
datetime
"updated_at"
,
null:
false
end
create_table
"favorites"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
,
force: :cascade
do
|
t
|
create_table
"favorites"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8
mb4
"
,
force: :cascade
do
|
t
|
t
.
integer
"user_id"
t
.
integer
"job_id"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
end
create_table
"histories"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
,
force: :cascade
do
|
t
|
create_table
"histories"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8
mb4
"
,
force: :cascade
do
|
t
|
t
.
integer
"user_id"
t
.
integer
"job_id"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
end
create_table
"industries"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
,
force: :cascade
do
|
t
|
create_table
"industries"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8
mb4
"
,
force: :cascade
do
|
t
|
t
.
string
"name"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
end
create_table
"industry_jobs"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
,
force: :cascade
do
|
t
|
create_table
"industry_jobs"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8
mb4
"
,
force: :cascade
do
|
t
|
t
.
bigint
"industry_id"
t
.
bigint
"job_id"
t
.
datetime
"created_at"
,
null:
false
...
...
@@ -77,7 +77,7 @@ ActiveRecord::Schema.define(version: 2020_07_28_021412) do
t
.
index
[
"job_id"
],
name:
"index_industry_jobs_on_job_id"
end
create_table
"jobs"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
,
force: :cascade
do
|
t
|
create_table
"jobs"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8
mb4
"
,
force: :cascade
do
|
t
|
t
.
string
"name"
t
.
integer
"company_id"
t
.
string
"level"
...
...
@@ -90,7 +90,7 @@ ActiveRecord::Schema.define(version: 2020_07_28_021412) do
t
.
datetime
"updated_at"
,
null:
false
end
create_table
"users"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
,
force: :cascade
do
|
t
|
create_table
"users"
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8
mb4
"
,
force: :cascade
do
|
t
|
t
.
string
"email"
t
.
string
"name"
t
.
string
"password_digest"
...
...
lib/service/ftp.rb
View file @
4a5093e8
...
...
@@ -13,8 +13,8 @@ class FtpSever
NAME_CSV
=
'jobs.zip'
def
data_csv
do
nw
load_csv
CSV
.
parse
(
File
.
read
(
'lib/csv/jobs.csv'
),
headers:
true
)
do
wn
load_csv
CSV
.
parse
(
File
.
read
(
Rails
.
root
.
join
(
'lib'
,
'csv'
,
'jobs.csv'
)
),
headers:
true
)
end
def
logger
...
...
@@ -23,12 +23,16 @@ class FtpSever
private
def
donwload_csv
def
jobs_csv_path
Rails
.
root
.
join
(
NAME_CSV
)
end
def
download_csv
Net
::
FTP
.
open
(
CONTENT_SERVER_DOMAIN_NAME
,
CONTENT_SERVER_USER_NAME
,
CONTENT_SERVER_USER_PASSWORD
)
do
|
ftp
|
ftp
.
getbinaryfile
(
NAME_CSV
)
Unzip
.
extract_zip
(
Rails
.
root
.
join
(
NAME_CSV
),
Rails
.
root
.
join
(
'lib'
,
'csv'
))
File
.
delete
(
Rails
.
root
.
join
(
NAME_CSV
))
if
File
.
exist?
(
Rails
.
root
.
join
(
NAME_CSV
)
)
logger
.
info
'Do
nw
load & extract success'
Unzip
.
extract_zip
(
(
jobs_csv_path
),
Rails
.
root
.
join
(
'lib'
,
'csv'
))
File
.
delete
(
jobs_csv_path
)
if
File
.
exist?
(
jobs_csv_path
)
logger
.
info
'Do
wn
load & extract success'
end
end
end
lib/service/import_data.rb
View file @
4a5093e8
...
...
@@ -15,10 +15,13 @@ class ImportData
import_jobs_from
(
csv_data
)
end
def
logger
@logger
||=
Logger
.
new
(
Rails
.
root
.
join
(
'log'
,
'import_data_csv.log'
))
end
private
def
import_industries_from
(
csv
)
puts
'Import data industries . . .'
industries
=
[]
industries
+=
csv
[
'category'
].
map
(
&
:strip
)
industries
.
each
do
|
val
|
...
...
@@ -26,30 +29,30 @@ class ImportData
val
.
gsub!
(
'/'
,
' / '
)
Industry
.
find_or_create_by
(
name:
val
)
end
puts
'Done parse csv industries'
rescue
StandardError
=>
e
logger
.
error
"Import_industries:
#{
e
}
"
end
def
import_cities_from
(
csv
)
puts
'Import data cities . . .'
cities
=
csv
[
'work place'
].
uniq
.
select
(
&
:present?
)
cities
=
cities
.
map
{
|
val
|
val
.
delete
(
'[]\"'
)
}
city_names
=
csv
[
'work place'
].
uniq
.
select
(
&
:present?
)
cities
=
city_names
.
map
{
|
val
|
val
.
delete
(
'[]\"'
)
}
cities
.
each
do
|
val
|
next
if
val
.
blank?
City
.
find_or_create_by
(
name:
val
)
{
|
city
|
city
.
area
=
DOMESTIC
}
end
rescue
StandardError
=>
e
logger
.
error
"Import_cities:
#{
e
}
"
end
def
import_companies_from
(
csv
)
puts
'Import data companies . . .'
csv
[
'company name'
].
each_with_index
do
|
name
,
index
|
Company
.
find_or_create_by
(
name:
name
.
strip
)
do
|
company
|
company
.
address
=
csv
[
'company address'
][
index
]
company
.
short_description
=
csv
[
'benefit'
][
index
]
end
puts
index
rescue
StandardError
=>
e
puts
e
logger
.
error
"Import_companies:
#{
e
}
"
end
end
...
...
@@ -57,34 +60,25 @@ class ImportData
csv
[
'name'
].
each_with_index
do
|
name
,
index
|
desc
=
"
#{
csv
[
'requirement'
][
index
]
}
#{
(
csv
[
'description'
][
index
])
}
"
company
=
Company
.
find_by
name:
csv
[
'company name'
][
index
].
to_s
.
strip
company_id
=
company
.
blank?
?
COMPANY_SECURITY
:
company
.
id
company_id
=
company
.
try
(
:id
)
||
COMPANY_SECURITY
begin
job
=
Job
.
create!
(
name:
name
,
company_id:
company_id
,
level:
csv
[
'level'
][
index
],
salary:
csv
[
'salary'
][
index
],
create_date:
Time
.
now
,
description:
desc
)
make_foreign_cities_table
(
csv
[
'work place'
][
index
],
job
.
id
)
make_foreign_industries_table
(
csv
[
'category'
][
index
],
job
.
id
)
job
=
Job
.
create
(
name:
name
,
company_id:
company_id
,
level:
csv
[
'level'
][
index
],
salary:
csv
[
'salary'
][
index
],
create_date:
Time
.
now
,
description:
desc
)
city_names
=
csv
[
'work place'
][
index
].
to_s
.
delete
(
'[]\"'
)
city
=
City
.
find_or_create_by
(
name:
city_names
.
strip
)
{
|
record
|
record
.
area
=
DOMESTIC
}
job
.
cities
<<
city
industry_name
=
csv
[
'category'
][
index
].
to_s
.
gsub
(
','
,
'/'
).
gsub
(
'/'
,
' / '
)
industry
=
Industry
.
find_or_create_by
(
name:
industry_name
.
strip
)
job
.
industries
<<
industry
puts
index
rescue
StandardError
=>
e
puts
e
logger
.
error
"Import_jobs:
#{
e
}
"
end
end
end
def
make_foreign_cities_table
(
data
,
id_job
)
data
=
data
.
to_s
.
delete
(
'[]\"'
)
city
=
City
.
find_or_create_by
(
name:
data
.
strip
)
{
|
record
|
record
.
area
=
DOMESTIC
}
city_id
=
city
.
id
CityJob
.
create
(
job_id:
id_job
,
city_id:
city_id
)
end
def
make_foreign_industries_table
(
data
,
id_job
)
industry_name
=
data
.
to_s
.
gsub
(
','
,
'/'
).
gsub
(
'/'
,
' / '
)
industry
=
Industry
.
find_or_create_by
(
name:
industry_name
.
strip
)
industry_id
=
industry
.
id
IndustryJob
.
create
(
industry_id:
industry_id
,
job_id:
id_job
)
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment