Skip to content

Commit

Permalink
+ setting API
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Jan 18, 2022
1 parent b9b6a52 commit c4e2ab2
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
14 changes: 14 additions & 0 deletions importer/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ func init() {
// 注册处理器
gou.RegisterProcessHandler("xiang.import.Run", ProcessRun)
gou.RegisterProcessHandler("xiang.import.Data", ProcessData)
gou.RegisterProcessHandler("xiang.import.Setting", ProcessSetting)
gou.RegisterProcessHandler("xiang.import.DataSetting", ProcessDataSetting)
gou.RegisterProcessHandler("xiang.import.Mapping", ProcessMapping)
gou.RegisterProcessHandler("xiang.import.MappingSetting", ProcessMappingSetting)
Expand All @@ -28,6 +29,19 @@ func ProcessRun(process *gou.Process) interface{} {
return imp.Run(src, mapping)
}

// ProcessSetting xiang.import.Setting
// 导入配置选项
func ProcessSetting(process *gou.Process) interface{} {
process.ValidateArgNums(1)
name := process.ArgsString(0)
imp := Select(name)
return map[string]interface{}{
"mappingPreview": imp.Option.MappingPreview,
"dataPreview": imp.Option.DataPreview,
"title": imp.Title,
}
}

// ProcessData xiang.import.Data
// 数据预览
func ProcessData(process *gou.Process) interface{} {
Expand Down
7 changes: 7 additions & 0 deletions importer/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ func TestProcessDataSetting(t *testing.T) {
assert.True(t, ok)
}

func TestProcessSetting(t *testing.T) {
args := []interface{}{"order"}
response := gou.NewProcess("xiang.import.Setting", args...).Run()
_, ok := response.(map[string]interface{})
assert.True(t, ok)
}

func TestProcessRun(t *testing.T) {
simple := filepath.Join(config.Conf.Root, "imports", "assets", "simple.xlsx")
mapping := gou.NewProcess("xiang.import.Mapping", "order", simple).Run()
Expand Down
1 change: 1 addition & 0 deletions importer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Column struct {
// Option 导入配置项定
type Option struct {
UseTemplate bool `json:"useTemplate,omitempty"` // 使用已匹配过的模板
TemplateLink string `json:"templateLink,omitempty"` // 默认数据模板链接
ChunkSize int `json:"chunkSize,omitempty"` // 每次处理记录数量
MappingPreview string `json:"mappingPreview,omitempty"` // 显示字段映射界面方式 auto 匹配模板失败显示, always 一直显示, never 不显示
DataPreview string `json:"dataPreview,omitempty"` // 数据预览界面方式 auto 有异常数据时显示, always 一直显示, never 不显示
Expand Down
3 changes: 2 additions & 1 deletion tests/imports/order.imp.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
"chunkSize": 3,
"logging": "error",
"mappingPreview": "auto",
"dataPreview": "auto"
"dataPreview": "auto",
"templateLink": "/somelinke/download/xxx"
},
"rules": {
"scripts.rules.order_sn": "订单号验证",
Expand Down
10 changes: 10 additions & 0 deletions xiang/apis/import.http.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
"type": "application/json"
}
},
{
"path": "/:name/setting",
"method": "GET",
"process": "xiang.import.Setting",
"in": ["$param.name"],
"out": {
"status": 200,
"type": "application/json"
}
},
{
"path": "/:name/data",
"method": "POST",
Expand Down

0 comments on commit c4e2ab2

Please sign in to comment.