tallty_import_export 1.0.23 → 1.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +4 -4
- data/lib/tallty_import_export/export.rb +38 -21
- data/lib/tallty_import_export/import.rb +5 -1
- data/lib/tallty_import_export/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d689c40b8f11354501a465563d14f5ab1060137fb2221180db05c8a18fe2b0d
|
4
|
+
data.tar.gz: 9cbd15c9a1eae1a0e036dd4557fb5197e3f595067b035dd01119167becee6d3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a11b8561c856588abf871fe6cac330e3a9412e468c6ff2d3480be75b8976b22a7037a655c51df7c884a367d9efa7c8b362c1c46ca3a1e5824f8777ccf0bb1204
|
7
|
+
data.tar.gz: d178c5d5ae84107a04862e7b5b929ba8546776b1400ed79bde6c518f656d6ac7c573bfaaad3d60b499ec18d1cf9df3a09962d0669c251acbc24f905939ab884e
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
tallty_import_export (1.0.
|
4
|
+
tallty_import_export (1.0.24)
|
5
5
|
activesupport
|
6
6
|
caxlsx
|
7
7
|
redis
|
@@ -22,7 +22,7 @@ GEM
|
|
22
22
|
minitest (>= 5.1)
|
23
23
|
tzinfo (~> 2.0)
|
24
24
|
zeitwerk (~> 2.3)
|
25
|
-
caxlsx (3.1.
|
25
|
+
caxlsx (3.1.1)
|
26
26
|
htmlentities (~> 4.3, >= 4.3.4)
|
27
27
|
marcel (~> 1.0)
|
28
28
|
nokogiri (~> 1.10, >= 1.10.4)
|
@@ -32,7 +32,7 @@ GEM
|
|
32
32
|
htmlentities (4.3.4)
|
33
33
|
i18n (1.8.10)
|
34
34
|
concurrent-ruby (~> 1.0)
|
35
|
-
marcel (1.0.
|
35
|
+
marcel (1.0.2)
|
36
36
|
mini_portile2 (2.6.1)
|
37
37
|
minitest (5.14.4)
|
38
38
|
nokogiri (1.12.4)
|
@@ -65,7 +65,7 @@ GEM
|
|
65
65
|
rspec-support (3.10.0)
|
66
66
|
ruby-ole (1.2.12.2)
|
67
67
|
rubyzip (2.3.2)
|
68
|
-
spreadsheet (1.
|
68
|
+
spreadsheet (1.3.0)
|
69
69
|
ruby-ole
|
70
70
|
tallty_duck_record (1.1.3)
|
71
71
|
activemodel (>= 5.0)
|
@@ -15,7 +15,7 @@ module TalltyImportExport
|
|
15
15
|
# { key: 'user_code', name: '考核人工号' },
|
16
16
|
# { key: 'user_department_name', name: '考核人部门' },
|
17
17
|
# { key: 'state', name: '考核状态', method: :state_zh },
|
18
|
-
# { key: 'score', name: '考核分' },
|
18
|
+
# { key: 'score', name: '考核分', source: true },
|
19
19
|
# ]
|
20
20
|
# export_headers_result / headers
|
21
21
|
# key: 属性的英文名,可以支持user.name这样的方式
|
@@ -28,6 +28,7 @@ module TalltyImportExport
|
|
28
28
|
# merge: true/false,默认false,某一列,如果上下行的内容相同,则直接合并单元格
|
29
29
|
# json: model_payload,代表存储在某一个列中
|
30
30
|
# select: [{ label: '已报备', value: 'submitted'}, ...],需要转换的枚举类型
|
31
|
+
# source: true,如果source为true,代表从association_record 进行属性查询
|
31
32
|
|
32
33
|
def export_xlsx records, **options
|
33
34
|
records = with_scope records
|
@@ -65,7 +66,7 @@ module TalltyImportExport
|
|
65
66
|
end
|
66
67
|
end
|
67
68
|
|
68
|
-
def export_workbook workbook,
|
69
|
+
def export_workbook workbook, association_records
|
69
70
|
# excel导出样式
|
70
71
|
alignment = { vertical: :center, horizontal: :center }
|
71
72
|
border = { color: '969696', style: :thin }
|
@@ -80,34 +81,44 @@ module TalltyImportExport
|
|
80
81
|
if respond_to?(:first_header)
|
81
82
|
row_index = Axlsx.col_ref(headers.size - 1)
|
82
83
|
sheet.merge_cells("A1:#{row_index}1")
|
83
|
-
sheet.add_row [first_header], style: title1, height:
|
84
|
+
sheet.add_row [first_header], style: title1, height: 30
|
84
85
|
end
|
85
86
|
|
86
|
-
sheet.add_row headers.map{|header| header[:name]}, style: title2, height:
|
87
|
+
sheet.add_row headers.map{|header| header[:name]}, style: title2, height: 25
|
87
88
|
|
88
89
|
last_row = nil
|
89
90
|
merge_column_hash = {}
|
90
91
|
first_content_row_index = respond_to?(:first_header) ? 2 : 1
|
91
92
|
|
92
|
-
|
93
|
-
|
93
|
+
index = 0
|
94
|
+
association_records.each do |association_record|
|
94
95
|
row = []
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
96
|
+
records = @each_method.present? ?
|
97
|
+
(try_method(association_record, @each_method) || [nil]) :
|
98
|
+
[association_record]
|
99
|
+
|
100
|
+
records.each do |record|
|
101
|
+
headers.each_with_index do |header, col_index|
|
102
|
+
index += 1
|
103
|
+
_data = header[:source] ?
|
104
|
+
handle_data(association_record, header, index) :
|
105
|
+
handle_data(record, header, index)
|
106
|
+
|
107
|
+
if header[:merge].present? && last_row.present? && _data == last_row[col_index]
|
108
|
+
# 这里使用二维数组,每个数组里都是列内容相同的各行
|
109
|
+
merge_column_hash[col_index] ||= []
|
110
|
+
if merge_column_hash[col_index].last&.last == index + first_content_row_index - 1
|
111
|
+
# 说明内容和上面的是延续的,继续加入之前的数组
|
112
|
+
merge_column_hash[col_index].last << index + first_content_row_index
|
113
|
+
else
|
114
|
+
merge_column_hash[col_index] << [index + first_content_row_index - 1, index + first_content_row_index]
|
115
|
+
end
|
105
116
|
end
|
117
|
+
row.push(_data)
|
106
118
|
end
|
107
|
-
row.
|
119
|
+
sheet.add_row row, style: title3, height: @row_height, types: headers.map{|header| header[:format]&.to_sym}
|
120
|
+
last_row = row
|
108
121
|
end
|
109
|
-
sheet.add_row row, style: title3, height: @row_height, types: headers.map{|header| header[:format]&.to_sym}
|
110
|
-
last_row = row
|
111
122
|
end
|
112
123
|
# 需要根据column进行多行的内容合并
|
113
124
|
if merge_column_hash.present?
|
@@ -123,15 +134,21 @@ module TalltyImportExport
|
|
123
134
|
end
|
124
135
|
end
|
125
136
|
|
137
|
+
# 地处整体配置信息
|
138
|
+
def export_options
|
139
|
+
{}
|
140
|
+
end
|
141
|
+
|
126
142
|
def process_options options = {}
|
127
|
-
options = options.with_indifferent_access
|
143
|
+
options = export_options.merge(options).with_indifferent_access
|
128
144
|
|
129
|
-
@row_height ||= options.delete(:row_height) ||
|
145
|
+
@row_height ||= options.delete(:row_height) || 25
|
130
146
|
@width ||= (options.delete(:width) || 20).to_f
|
131
147
|
@filename ||= options.delete(:filename)
|
132
148
|
@group_by ||= options.delete(:group_by)
|
133
149
|
@group_where = "#{@group_by}_eq" if @group_by.present?
|
134
150
|
@headers ||= options.delete(:headers)
|
151
|
+
@each_method ||= options.delete(:each_method)
|
135
152
|
end
|
136
153
|
|
137
154
|
def with_scope records
|
@@ -51,7 +51,7 @@ module TalltyImportExport
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def process_options options
|
54
|
-
options = options.with_indifferent_access
|
54
|
+
options = import_options.merge(options).with_indifferent_access
|
55
55
|
@headers = options.delete(:headers) || import_headers
|
56
56
|
@primary_keys = options.delete(:primary_keys) || @headers.map { |header| header[:primary_key] ? header[:key].to_sym : nil }.compact
|
57
57
|
@params = options
|
@@ -107,6 +107,10 @@ module TalltyImportExport
|
|
107
107
|
@headers ||= import_headers&.with_indifferent_access
|
108
108
|
end
|
109
109
|
|
110
|
+
def import_options
|
111
|
+
{}
|
112
|
+
end
|
113
|
+
|
110
114
|
def import_headers **args
|
111
115
|
@headers || klass.try(:headers) || klass.try(:model_headers) || (raise ArgumentError.new('missing import_headers'))
|
112
116
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tallty_import_export
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- liyijie
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zip-zip
|