Commit 06908e25 by Ivan Lan

feat: import and export add format file process

parent d08d72c1
PATH PATH
remote: . remote: .
specs: specs:
tallty_import_export (1.1.1) tallty_import_export (1.1.6)
activesupport activesupport
attr_json attr_json
caxlsx caxlsx
...@@ -15,44 +15,44 @@ PATH ...@@ -15,44 +15,44 @@ PATH
GEM GEM
remote: https://gems.ruby-china.com/ remote: https://gems.ruby-china.com/
specs: specs:
activemodel (7.0.2.4) activemodel (7.0.6)
activesupport (= 7.0.2.4) activesupport (= 7.0.6)
activerecord (7.0.2.4) activerecord (7.0.6)
activemodel (= 7.0.2.4) activemodel (= 7.0.6)
activesupport (= 7.0.2.4) activesupport (= 7.0.6)
activesupport (7.0.2.4) activesupport (7.0.6)
concurrent-ruby (~> 1.0, >= 1.0.2) concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2) i18n (>= 1.6, < 2)
minitest (>= 5.1) minitest (>= 5.1)
tzinfo (~> 2.0) tzinfo (~> 2.0)
attr_json (1.4.0) attr_json (2.0.1)
activerecord (>= 5.0.0, < 7.1) activerecord (>= 6.0.0, < 7.1)
caxlsx (3.3.0) caxlsx (3.4.1)
htmlentities (~> 4.3, >= 4.3.4) htmlentities (~> 4.3, >= 4.3.4)
marcel (~> 1.0) marcel (~> 1.0)
nokogiri (~> 1.10, >= 1.10.4) nokogiri (~> 1.10, >= 1.10.4)
rubyzip (>= 1.3.0, < 3) rubyzip (>= 1.3.0, < 3)
concurrent-ruby (1.1.10) concurrent-ruby (1.2.2)
connection_pool (2.3.0) connection_pool (2.4.1)
diff-lcs (1.4.4) diff-lcs (1.4.4)
htmlentities (4.3.4) htmlentities (4.3.4)
i18n (1.12.0) i18n (1.14.1)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
marcel (1.0.2) marcel (1.0.2)
mini_portile2 (2.8.0) mini_portile2 (2.8.2)
minitest (5.16.3) minitest (5.18.1)
nokogiri (1.13.9) nokogiri (1.15.2)
mini_portile2 (~> 2.8.0) mini_portile2 (~> 2.8.2)
racc (~> 1.4) racc (~> 1.4)
racc (1.6.0) racc (1.7.1)
rake (12.3.3) rake (12.3.3)
redis (5.0.5) redis (5.0.6)
redis-client (>= 0.9.0) redis-client (>= 0.9.0)
redis-client (0.10.0) redis-client (0.14.1)
connection_pool connection_pool
redis-objects (1.7.0) redis-objects (1.7.0)
redis redis
roo (2.9.0) roo (2.10.0)
nokogiri (~> 1) nokogiri (~> 1)
rubyzip (>= 1.3.0, < 3.0.0) rubyzip (>= 1.3.0, < 3.0.0)
roo-xls (1.2.0) roo-xls (1.2.0)
...@@ -81,7 +81,7 @@ GEM ...@@ -81,7 +81,7 @@ GEM
activesupport (>= 5.0) activesupport (>= 5.0)
tallty_form (1.0.0) tallty_form (1.0.0)
tallty_duck_record tallty_duck_record
tzinfo (2.0.5) tzinfo (2.0.6)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
zip-zip (0.3) zip-zip (0.3)
rubyzip (>= 1.0.0) rubyzip (>= 1.0.0)
......
...@@ -278,6 +278,17 @@ module TalltyImportExport ...@@ -278,6 +278,17 @@ module TalltyImportExport
data ? data.in_time_zone.strftime('%F %H:%M') : nil data ? data.in_time_zone.strftime('%F %H:%M') : nil
when 'date' when 'date'
data ? data.in_time_zone.strftime('%F') : nil 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 else
data data
end end
......
...@@ -145,6 +145,9 @@ module TalltyImportExport ...@@ -145,6 +145,9 @@ module TalltyImportExport
# handle_xxx(val, processing_line_info, raw_line_info) # handle_xxx(val, processing_line_info, raw_line_info)
val = header[:convert] ? send(header[:convert], v, h, info) : v val = header[:convert] ? send(header[:convert], v, h, info) : v
val.strip! if val.is_a?(String) val.strip! if val.is_a?(String)
val = handle_format(val, header, line_info)
if header[:json] if header[:json]
h[header[:json]] ||= {} h[header[:json]] ||= {}
h[header[:json]][k] = val h[header[:json]][k] = val
...@@ -165,6 +168,27 @@ module TalltyImportExport ...@@ -165,6 +168,27 @@ module TalltyImportExport
end.with_indifferent_access end.with_indifferent_access
end 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) def valid?(line_info)
true 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