forked from YaoApp/yao
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
210 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,42 @@ | ||
package from | ||
|
||
const ( | ||
// TUnknown 未知 | ||
TUnknown byte = iota | ||
// TBool bool | ||
TBool | ||
// TDatetime 日期时间 | ||
TDatetime | ||
// TError 错误 | ||
TError | ||
// TNumber 数字 | ||
TNumber | ||
// TString 字符串 | ||
TString | ||
) | ||
|
||
// Source 导入文件接口 | ||
type Source interface { | ||
Data(page int, size int) []map[string]interface{} | ||
Columns() []Column | ||
Bind(mapping Mapping) | ||
Inspect() Inspect | ||
Bind() | ||
Close() error | ||
} | ||
|
||
// Column 源数据列 | ||
type Column struct { | ||
Name string | ||
Type string | ||
Type byte | ||
Col int | ||
Row int | ||
Pos string | ||
Axis string | ||
} | ||
|
||
// Mapping 数值映射表 | ||
type Mapping struct{} | ||
// Inspect 基础信息 | ||
type Inspect struct { | ||
SheetName string | ||
SheetIndex int | ||
ColStart int | ||
RowStart int | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,34 @@ | ||
package importer | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/yaoapp/kun/utils" | ||
"github.com/yaoapp/xiang/config" | ||
"github.com/yaoapp/xiang/importer/xlsx" | ||
) | ||
|
||
func TestLoad(t *testing.T) { | ||
LoadFrom("not a path", "404.") | ||
assert.IsType(t, &Importer{}, Select("manu")) | ||
assert.IsType(t, &Importer{}, Select("order")) | ||
} | ||
func TestFingerprint(t *testing.T) { | ||
func TestFingerprintSimple(t *testing.T) { | ||
simple := filepath.Join(config.Conf.Root, "imports", "assets", "simple.xlsx") | ||
file := xlsx.Open(simple) | ||
defer file.Close() | ||
imp := Select("manu") | ||
fp := imp.Fingerprint(file) | ||
fmt.Println(fp) | ||
imp := Select("order") | ||
fingerprint := imp.Fingerprint(file) | ||
assert.Equal(t, "3451ca87d71801687abba8993e5a69af79482914435d7cc064236fd93160f999", fingerprint) | ||
} | ||
|
||
func TestAutoMappingSimple(t *testing.T) { | ||
simple := filepath.Join(config.Conf.Root, "imports", "assets", "simple.xlsx") | ||
file := xlsx.Open(simple) | ||
defer file.Close() | ||
|
||
imp := Select("order") | ||
mapping := imp.AutoMapping(file) | ||
utils.Dump(mapping) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.