tallty_import_export 1.0.26 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97dc753652b3c88b46d47c337cb8efacd3b225d464a9fcedb6ec9addb99a1656
4
- data.tar.gz: c918a6587726e31a4855f56384708e6d94235f015c08e68e295870731266fb9c
3
+ metadata.gz: 7d689c40b8f11354501a465563d14f5ab1060137fb2221180db05c8a18fe2b0d
4
+ data.tar.gz: 9cbd15c9a1eae1a0e036dd4557fb5197e3f595067b035dd01119167becee6d3c
5
5
  SHA512:
6
- metadata.gz: a614d1219e135cbedde925238313c0b5b256166df53e0633151674e3dc50ec4b15552582c11707db24cefcf6e989b9301a562288ae58d87d8df2a2e17caf8208
7
- data.tar.gz: 47db4f8d0ca88bac82d5398bd9987ee991393bc9103067754e53995ecc82155e4b52a8b298ce8d85b7568633a0baff6d7524baeb470f097992c28b4291fde143
6
+ metadata.gz: a11b8561c856588abf871fe6cac330e3a9412e468c6ff2d3480be75b8976b22a7037a655c51df7c884a367d9efa7c8b362c1c46ca3a1e5824f8777ccf0bb1204
7
+ data.tar.gz: d178c5d5ae84107a04862e7b5b929ba8546776b1400ed79bde6c518f656d6ac7c573bfaaad3d60b499ec18d1cf9df3a09962d0669c251acbc24f905939ab884e
@@ -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, records
69
+ def export_workbook workbook, association_records
69
70
  # excel导出样式
70
71
  alignment = { vertical: :center, horizontal: :center }
71
72
  border = { color: '969696', style: :thin }
@@ -89,25 +90,35 @@ module TalltyImportExport
89
90
  merge_column_hash = {}
90
91
  first_content_row_index = respond_to?(:first_header) ? 2 : 1
91
92
 
92
- each_method = @each_method || :each
93
- records.try_method(each_method).with_index do |record, index|
93
+ index = 0
94
+ association_records.each do |association_record|
94
95
  row = []
95
- headers.each_with_index do |header, col_index|
96
- _data = handle_data(record, header, index)
97
- if header[:merge].present? && last_row.present? && _data == last_row[col_index]
98
- # 这里使用二维数组,每个数组里都是列内容相同的各行
99
- merge_column_hash[col_index] ||= []
100
- if merge_column_hash[col_index].last&.last == index + first_content_row_index - 1
101
- # 说明内容和上面的是延续的,继续加入之前的数组
102
- merge_column_hash[col_index].last << index + first_content_row_index
103
- else
104
- merge_column_hash[col_index] << [index + first_content_row_index - 1, index + first_content_row_index]
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.push(_data)
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?
@@ -1,3 +1,3 @@
1
1
  module TalltyImportExport
2
- VERSION = "1.0.26"
2
+ VERSION = "1.0.28"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tallty_import_export
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.26
4
+ version: 1.0.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - liyijie