Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tallty_import_export
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
tallty_import_export
Commits
86d7c2da
Commit
86d7c2da
authored
Nov 12, 2021
by
liyijie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 增加skip参数
parent
a2c2f5d0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
2 deletions
+4
-2
import.rb
lib/tallty_import_export/import.rb
+3
-1
version.rb
lib/tallty_import_export/version.rb
+1
-1
No files found.
lib/tallty_import_export/import.rb
View file @
86d7c2da
...
@@ -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
...
...
lib/tallty_import_export/version.rb
View file @
86d7c2da
module
TalltyImportExport
module
TalltyImportExport
VERSION
=
"1.0.
29
"
VERSION
=
"1.0.
30
"
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment