Commit 06908e25 by Ivan Lan

feat: import and export add format file process

parent d08d72c1
PATH
remote: .
specs:
tallty_import_export (1.1.1)
tallty_import_export (1.1.6)
activesupport
attr_json
caxlsx
......@@ -15,44 +15,44 @@ PATH
GEM
remote: https://gems.ruby-china.com/
specs:
activemodel (7.0.2.4)
activesupport (= 7.0.2.4)
activerecord (7.0.2.4)
activemodel (= 7.0.2.4)
activesupport (= 7.0.2.4)
activesupport (7.0.2.4)
activemodel (7.0.6)
activesupport (= 7.0.6)
activerecord (7.0.6)
activemodel (= 7.0.6)
activesupport (= 7.0.6)
activesupport (7.0.6)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
attr_json (1.4.0)
activerecord (>= 5.0.0, < 7.1)
caxlsx (3.3.0)
attr_json (2.0.1)
activerecord (>= 6.0.0, < 7.1)
caxlsx (3.4.1)
htmlentities (~> 4.3, >= 4.3.4)
marcel (~> 1.0)
nokogiri (~> 1.10, >= 1.10.4)
rubyzip (>= 1.3.0, < 3)
concurrent-ruby (1.1.10)
connection_pool (2.3.0)
concurrent-ruby (1.2.2)
connection_pool (2.4.1)
diff-lcs (1.4.4)
htmlentities (4.3.4)
i18n (1.12.0)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
marcel (1.0.2)
mini_portile2 (2.8.0)
minitest (5.16.3)
nokogiri (1.13.9)
mini_portile2 (~> 2.8.0)
mini_portile2 (2.8.2)
minitest (5.18.1)
nokogiri (1.15.2)
mini_portile2 (~> 2.8.2)
racc (~> 1.4)
racc (1.6.0)
racc (1.7.1)
rake (12.3.3)
redis (5.0.5)
redis (5.0.6)
redis-client (>= 0.9.0)
redis-client (0.10.0)
redis-client (0.14.1)
connection_pool
redis-objects (1.7.0)
redis
roo (2.9.0)
roo (2.10.0)
nokogiri (~> 1)
rubyzip (>= 1.3.0, < 3.0.0)
roo-xls (1.2.0)
......@@ -81,7 +81,7 @@ GEM
activesupport (>= 5.0)
tallty_form (1.0.0)
tallty_duck_record
tzinfo (2.0.5)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
zip-zip (0.3)
rubyzip (>= 1.0.0)
......
......@@ -278,6 +278,17 @@ module TalltyImportExport
data ? data.in_time_zone.strftime('%F %H:%M') : nil
when 'date'
data ? data.in_time_zone.strftime('%F') : nil
when 'file'
if data.is_a?(Array) && !opts[:keep_array]
data.map do |item|
url = item.dig('url')
url.present? ?
"#{url}?fileName=#{URI.encode_www_form_component(item.dig('fileName'))}&fileSize=#{URI.encode_www_form_component(item.dig('fileSize'))}&fileType=#{URI.encode_www_form_component(item.dig('fileType'))}" :
nil
end.compact.join("\n")
else
data
end
else
data
end
......
......@@ -145,6 +145,9 @@ module TalltyImportExport
# handle_xxx(val, processing_line_info, raw_line_info)
val = header[:convert] ? send(header[:convert], v, h, info) : v
val.strip! if val.is_a?(String)
val = handle_format(val, header, line_info)
if header[:json]
h[header[:json]] ||= {}
h[header[:json]][k] = val
......@@ -165,6 +168,27 @@ module TalltyImportExport
end.with_indifferent_access
end
def handle_format val, header, line_info
case header[:format].to_s
when 'file'
if val.is_a?(String)
val = val.split("\n").map do |url|
params = url.include?('?') ? CGI::parse(url.split('?').last) : {}
{
url: url,
fileName: params['fileName']&.first,
fileType: params['fileType']&.first,
fileSize: params['fileSize']&.first&.to_i,
}
end
else
val
end
else
val
end
end
# 通过转换后,数据是否合法,如果不合法,则直接跳过不处理这个数据
def valid?(line_info)
true
......
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