unidom-position 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1645f47e2078c818ae2521a0fa4e2621ddcc112a
4
- data.tar.gz: e3300b3cf9f605a7c9844157142fce0a2555a638
3
+ metadata.gz: afc0bf6e11bdf01c9a08281323e491af07e9be04
4
+ data.tar.gz: 3295a37894a71f6a53716851c33c433b83b5225f
5
5
  SHA512:
6
- metadata.gz: 4f67b7a15021ba82e057f6c8c5a0dbff3eb4f29d05ae8f40ddf8ddc22d1f29b04eabdde53ab2fa0e04d1403d2a8d42f2e4eb244bd65e65448df46a5a51d40c80
7
- data.tar.gz: 14c43856faaeaf8b44c66dd484711eaec3a260212bf9ab634401d3cb5f3061bcf26d665fd80ed880c429e044b65256eee6cd63b24cf9b079bb13201b6fbf5cef
6
+ metadata.gz: 082985ba3c2628b465d8193b3afb50173a8708a1baee92ad40d6e6defad5a52751b60cda54b9800e9d80360df1a02a434eb806ae207ed55c23d79ce4fe223f8c
7
+ data.tar.gz: 622f6171cd2c65eae430f6d1a6a01070b668d78be9c61735a705743310dffcdc684368fb6035434e0351a8da49a7e23ed7aafa3a3a63d5ab98bb8f82e5b7718e
data/README.md CHANGED
@@ -36,3 +36,8 @@ erlang_developer = Unidom::Position::Post.create! name: 'Erlang Developer', posi
36
36
  Unidom::Position::PostReportingStructure.report!(superior_post: chief_programmer, inferior_post: erlang_developer, opened_at: Time.now, elemental: true)
37
37
 
38
38
  ```
39
+
40
+ ## Rake Task
41
+ ```shell
42
+ bundle exec rake unidom:position:occupation:import file=/data.csv from_date=2009-11-01 thru_date=2015-10-01 scheme_id= scheme_type=
43
+ ```
@@ -13,4 +13,8 @@ class Unidom::Position::Occupation < ActiveRecord::Base
13
13
  has_many :positions, class_name: 'Unidom::Position::Position'
14
14
  has_many :posts, through: :positions, source: :posts
15
15
 
16
+ scope :scheme_is, ->(scheme) { where scheme: scheme }
17
+ scope :scheme_id_is, ->(scheme_id) { where scheme_id: scheme_id }
18
+ scope :scheme_type_is, ->(scheme_type) { where scheme_type: scheme_type }
19
+
16
20
  end
@@ -0,0 +1,65 @@
1
+ desc 'unidom:position:occupation:import Rake Task imports occupations from the given CSV file.'
2
+
3
+ namespace :unidom do
4
+ namespace :position do
5
+
6
+ namespace :occupation do
7
+
8
+ # bundle exec rake unidom:position:occupation:import
9
+ # file=/data.csv
10
+ # from_date=2020-01-01
11
+ # scheme_id=
12
+ # scheme_type=
13
+ task import: :environment do
14
+
15
+ include Unidom::Common::DataHelper
16
+
17
+ file_name = ENV['file']
18
+ scheme_id = ENV['scheme_id']||Unidom::Common::NULL_UUID
19
+ scheme_type = ENV['scheme_type']||''
20
+ opened_at = parse_time ENV['from_date']
21
+
22
+ updated_count = 0
23
+ created_count = 0
24
+
25
+ occupation_entities = Unidom::Position::Occupation.scheme_id_is(scheme_id).scheme_type_is(scheme_type).to_a
26
+
27
+ each_csv_row file_name do |occupation|
28
+
29
+ code = occupation['code']
30
+ name = occupation['name']
31
+
32
+ attributes = { name: occupation['name'], scheme_id: scheme_id, scheme_type: scheme_type, opened_at: opened_at }
33
+
34
+ if occupation_entities.present?
35
+ found_occupation_entities = occupation_entities.select { |occupation_entity| occupation_entity.code==code }
36
+ if found_occupation_entities.present?
37
+ found_occupation_entities.each do |found_occupation_entity|
38
+ found_occupation_entity.assign_attributes attributes
39
+ if found_occupation_entity.changed?
40
+ found_occupation_entity.save!
41
+ updated_count += 1
42
+ end
43
+ end
44
+ else
45
+ attributes[:code] = code
46
+ Unidom::Position::Occupation.create! attributes
47
+ created_count += 1
48
+ end
49
+ else
50
+ attributes[:code] = code
51
+ Unidom::Position::Occupation.create! attributes
52
+ created_count += 1
53
+ end
54
+
55
+ end
56
+
57
+ puts "#{created_count} Occupations were created. #{updated_count} Occupations were updated per CSV."
58
+ puts "#{created_count+updated_count} Occupations were handled totally."
59
+
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+ end
@@ -1,5 +1,5 @@
1
1
  module Unidom
2
2
  module Position
3
- VERSION = '1.0'.freeze
3
+ VERSION = '1.1'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unidom-position
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Topbit Du
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-25 00:00:00.000000000 Z
11
+ date: 2016-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unidom-common
@@ -50,7 +50,7 @@ files:
50
50
  - db/migrate/20040211000000_create_unidom_positions.rb
51
51
  - db/migrate/20040212000000_create_unidom_posts.rb
52
52
  - db/migrate/20040221000000_create_unidom_post_reporting_structures.rb
53
- - lib/tasks/position_tasks.rake
53
+ - lib/tasks/data_tasks.rake
54
54
  - lib/unidom/position.rb
55
55
  - lib/unidom/position/engine.rb
56
56
  - lib/unidom/position/version.rb
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :position do
3
- # # Task goes here
4
- # end