From c4e2ab2c7a21e5e06a6f424a6a805be41f4c3c3f Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 18 Jan 2022 13:20:14 +0800 Subject: [PATCH] + setting API --- importer/process.go | 14 ++++++++++++++ importer/process_test.go | 7 +++++++ importer/types.go | 1 + tests/imports/order.imp.json | 3 ++- xiang/apis/import.http.json | 10 ++++++++++ 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/importer/process.go b/importer/process.go index 7c419d9d6a..87cd17a578 100644 --- a/importer/process.go +++ b/importer/process.go @@ -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) @@ -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{} { diff --git a/importer/process_test.go b/importer/process_test.go index 95fb96a11b..33ac5bc138 100644 --- a/importer/process_test.go +++ b/importer/process_test.go @@ -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() diff --git a/importer/types.go b/importer/types.go index 250e49aa49..ffeca8d985 100644 --- a/importer/types.go +++ b/importer/types.go @@ -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 不显示 diff --git a/tests/imports/order.imp.json b/tests/imports/order.imp.json index b3bb64bfbc..1fa5186b60 100644 --- a/tests/imports/order.imp.json +++ b/tests/imports/order.imp.json @@ -71,7 +71,8 @@ "chunkSize": 3, "logging": "error", "mappingPreview": "auto", - "dataPreview": "auto" + "dataPreview": "auto", + "templateLink": "/somelinke/download/xxx" }, "rules": { "scripts.rules.order_sn": "订单号验证", diff --git a/xiang/apis/import.http.json b/xiang/apis/import.http.json index e91ae810cd..ac039409b6 100644 --- a/xiang/apis/import.http.json +++ b/xiang/apis/import.http.json @@ -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",