tallty_import_export 1.0.13 → 1.0.18
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
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56c0a62d935867d8420680ac232d8c156c8c653b805534ede5880bc615514706
|
4
|
+
data.tar.gz: 4efe0c40688bed288036ae32f51fe6ac7d3e28a9faddb7aa0dc05f8f901cc0c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4f9e59896340ed7d75128c165d40ca8ddc4d0d584953d3953433f90bfbfe3d8cfe355cd7b4ee3182c19217a238f98c8d10b2100483b949ebc5aad1a73d31868
|
7
|
+
data.tar.gz: 0f36b4f04a2bc8759b4e835cd4dcd0e051933735322a0fefb18b5a06f438a0954d269fb9c7d3e30f436b603e94c54cfedb26e4dfcf1039d92c734874c2da838e
|
@@ -38,14 +38,15 @@ module TalltyImportExport
|
|
38
38
|
workbook = pack.workbook
|
39
39
|
|
40
40
|
if @group_by.present?
|
41
|
-
@header = nil # 因为group_by的,基本上都是export_header动态变化的,因此去掉选择
|
42
41
|
if records.is_a?(Array)
|
43
42
|
records.group_by { |record| record.send(@group_by)}.each do |key, group_records|
|
43
|
+
next unless key.present?
|
44
44
|
@group_key = key
|
45
45
|
export_workbook workbook, group_records
|
46
46
|
end
|
47
47
|
else
|
48
48
|
records.group(@group_by).count.keys.each do |key|
|
49
|
+
next unless key.present?
|
49
50
|
@group_key = key
|
50
51
|
export_workbook workbook, records.ransack("#{@group_where}" => key).result
|
51
52
|
end
|
@@ -15,6 +15,7 @@ module TalltyImportExport
|
|
15
15
|
# convert: 导入时候,把excel的内容转换成导入时候代码逻辑需要的内容
|
16
16
|
# primary_key: 是否是主键
|
17
17
|
# json: model_payload,代表存储在某一个列中
|
18
|
+
# finder: 执行代码,可以查找到相关的对象
|
18
19
|
|
19
20
|
# xlsx_file 为 file path or file object or TalltyImportExport::Excel.new
|
20
21
|
def import_xlsx xlsx_file, associations, **options
|
@@ -53,6 +54,7 @@ module TalltyImportExport
|
|
53
54
|
options = options.with_indifferent_access
|
54
55
|
@headers = options.delete(:headers) || import_headers
|
55
56
|
@primary_keys = options.delete(:primary_keys) || @headers.map { |header| header[:primary_key] ? header[:key].to_sym : nil }.compact
|
57
|
+
@params = options
|
56
58
|
|
57
59
|
@excel_hash = @headers.reduce({}) do |h, header|
|
58
60
|
h[header[:key].to_sym] = header[:name]
|
@@ -63,6 +65,8 @@ module TalltyImportExport
|
|
63
65
|
end
|
64
66
|
|
65
67
|
def process_line_info line_info, associations
|
68
|
+
# 去除空行内容
|
69
|
+
return unless line_info.values.any?(&:present?)
|
66
70
|
# 转换处理导入的数据格式
|
67
71
|
line_info = convert_data(line_info)
|
68
72
|
|
@@ -84,6 +88,11 @@ module TalltyImportExport
|
|
84
88
|
if header[:json]
|
85
89
|
h[header[:json]] ||= {}
|
86
90
|
h[header[:json]][k] = val
|
91
|
+
elsif header[:finder]
|
92
|
+
$SAFE = 2
|
93
|
+
eval_string = header[:finder] + '(val)'
|
94
|
+
eval_val = eval eval_string
|
95
|
+
h[k.to_sym] = eval_val
|
87
96
|
else
|
88
97
|
h[k.to_sym] = val
|
89
98
|
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.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- liyijie
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: zip-zip
|