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
c9271cea
Commit
c9271cea
authored
Nov 21, 2020
by
Ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复导入表头对应
parent
b7247174
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
13 deletions
+29
-13
import.rb
lib/tallty_import_export/import.rb
+8
-10
.~test1.xlsx
spec/.~test1.xlsx
+0
-0
importable_spec.rb
spec/importable_spec.rb
+21
-3
No files found.
lib/tallty_import_export/import.rb
View file @
c9271cea
...
...
@@ -85,23 +85,21 @@ module TalltyImportExport
return
end
key_to_header
=
val
.
reduce
({})
do
|
out
,
header
|
key_to_
coming_
header
=
val
.
reduce
({})
do
|
out
,
header
|
out
[
header
.
with_indifferent_access
[
:key
].
to_sym
]
=
header
.
with_indifferent_access
out
end
@headers
=
import_headers
.
map
do
|
header
|
coming_header
=
key_to_header
[
header
.
with_indifferent_access
[
:key
].
to_sym
]
if
coming_header
dup_header
=
header
.
dup
dup_header
[
:key
]
=
coming_header
[
:key
]
||
dup_header
[
:key
]
dup_header
[
:name
]
=
coming_header
[
:name
]
||
dup_header
[
:name
]
dup_header
[
:json
]
=
coming_header
[
:json
]
||
dup_header
[
:json
]
dup_header
result
=
[]
val
.
map
do
|
header
|
if
(
exist_header
=
import_headers
.
find
{
|
model_header
|
model_header
[
:key
]
===
header
[
:key
]
})
result
.
push
(
exist_header
.
merge
(
name:
header
[
:name
],
json:
header
[
:json
]))
else
header
result
.
push
({
key:
header
[
:key
],
name:
header
[
:name
],
json:
header
[
:json
]})
end
end
@headers
=
result
end
def
skip
val
,
processing_line_info
,
raw_line_info
...
...
spec/.~test1.xlsx
0 → 100644
View file @
c9271cea
File added
spec/importable_spec.rb
View file @
c9271cea
...
...
@@ -11,7 +11,7 @@ RSpec.describe TalltyImportExport::Importable do
{
key:
'sub_code'
,
name:
'副学号'
,
convert: :skip
},
{
key:
'meta1'
,
name:
'meta字段1'
,
json: :meta
},
{
key:
'meta2'
,
name:
'meta字段2'
,
json: :meta
},
{
key:
'sum'
,
name:
'累
加
值'
,
convert: :handle_sum
},
{
key:
'sum'
,
name:
'累
计
值'
,
convert: :handle_sum
},
]
end
end
...
...
@@ -40,7 +40,16 @@ RSpec.describe TalltyImportExport::Importable do
# 4 20070104 4 meta4 metaD
# 5 20070105 5 meta5 metaE
@result
=
[]
Test
.
import_xlsx
(
'./spec/test1.xlsx'
,
@result
,
headers:
[{
key:
'name'
,
name:
'名称'
}])
Test
.
import_xlsx
(
'./spec/test1.xlsx'
,
@result
,
headers:
[
{
key:
'name'
,
name:
'名称'
},
{
key:
'code'
,
name:
'学号'
},
{
key:
'sub_code'
,
name:
'副学号'
},
{
key:
'meta1'
,
name:
'meta字段1'
,
json: :meta
},
{
key:
'meta2'
,
name:
'meta字段2'
,
json: :meta
},
{
key:
'sum'
,
name:
'累加值'
},
]
)
expect
(
@result
).
to
eq
([
{
"name"
=>
1
,
"code"
=>
"20070101_1"
,
"sub_code"
=>
nil
,
"meta"
=>
{
"meta1"
=>
"meta1"
,
"meta2"
=>
"metaA"
},
"sum"
=>
1
},
...
...
@@ -63,7 +72,16 @@ RSpec.describe TalltyImportExport::Importable do
@excel
=
TalltyImportExport
::
Excel
.
new
@excel
.
load
(
'./spec/test1.xlsx'
)
Test
.
import_xlsx
(
@excel
,
@result
)
Test
.
import_xlsx
(
@excel
,
@result
,
headers:
[
{
key:
'name'
,
name:
'名称'
},
{
key:
'code'
,
name:
'学号'
},
{
key:
'sub_code'
,
name:
'副学号'
},
{
key:
'meta1'
,
name:
'meta字段1'
,
json: :meta
},
{
key:
'meta2'
,
name:
'meta字段2'
,
json: :meta
},
{
key:
'sum'
,
name:
'累加值'
},
]
)
expect
(
@result
).
to
eq
([
{
"name"
=>
1
,
"code"
=>
"20070101_1"
,
"sub_code"
=>
nil
,
"meta"
=>
{
"meta1"
=>
"meta1"
,
"meta2"
=>
"metaA"
},
"sum"
=>
1
},
...
...
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