Commit 86d7c2da by liyijie

feat: 增加skip参数

parent a2c2f5d0
...@@ -17,6 +17,7 @@ module TalltyImportExport ...@@ -17,6 +17,7 @@ module TalltyImportExport
# json: model_payload,代表存储在某一个列中 # json: model_payload,代表存储在某一个列中
# finder: 执行代码,可以查找到相关的对象 # finder: 执行代码,可以查找到相关的对象
# proc: proc或者lamda,支持call,传入 val 和 context # proc: proc或者lamda,支持call,传入 val 和 context
# skip: 用来综合使用的数据,但是不导入
# xlsx_file 为 file path or file object or TalltyImportExport::Excel.new # xlsx_file 为 file path or file object or TalltyImportExport::Excel.new
def import_xlsx xlsx_file, associations, **options def import_xlsx xlsx_file, associations, **options
...@@ -55,6 +56,7 @@ module TalltyImportExport ...@@ -55,6 +56,7 @@ module TalltyImportExport
options = import_options.merge(options).with_indifferent_access options = import_options.merge(options).with_indifferent_access
@headers = options.delete(:headers) || import_headers @headers = options.delete(:headers) || import_headers
@primary_keys = options.delete(:primary_keys) || @headers.map { |header| header[:primary_key] ? header[:key].to_sym : nil }.compact @primary_keys = options.delete(:primary_keys) || @headers.map { |header| header[:primary_key] ? header[:key].to_sym : nil }.compact
@skip_keys = options.delete(:skip_keys) || @headers.map { |header| header[:skip] ? header[:key].to_sym : nil }.compact
@params = options @params = options
context.params = @params context.params = @params
...@@ -152,7 +154,7 @@ module TalltyImportExport ...@@ -152,7 +154,7 @@ module TalltyImportExport
def import_record line_info, associations def import_record line_info, associations
if primary_keys.present? if primary_keys.present?
_record = associations.find_or_initialize_by(line_info.clone.extract!(*primary_keys)) _record = associations.find_or_initialize_by(line_info.clone.extract!(*primary_keys))
_record.update!(line_info.clone.except!(*primary_keys)) _record.update!(line_info.clone.except!(*primary_keys, *@skip_keys))
else else
associations.create!(line_info) associations.create!(line_info)
end end
......
module TalltyImportExport module TalltyImportExport
VERSION = "1.0.29" VERSION = "1.0.30"
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment