[add] importer output process
This commit is contained in:
parent
4d497dd980
commit
1043ba0f0d
3 changed files with 16 additions and 3 deletions
|
|
@ -382,7 +382,7 @@ func (imp *Importer) SaveAsTemplate(src from.Source) {
|
|||
}
|
||||
|
||||
// Run 运行导入
|
||||
func (imp *Importer) Run(src from.Source, mapping *Mapping) map[string]int {
|
||||
func (imp *Importer) Run(src from.Source, mapping *Mapping) interface{} {
|
||||
if mapping == nil {
|
||||
mapping = imp.AutoMapping(src)
|
||||
}
|
||||
|
|
@ -424,12 +424,24 @@ func (imp *Importer) Run(src from.Source, mapping *Mapping) map[string]int {
|
|||
|
||||
log.With(log.F{"line": line, "response": response, "length": length}).Error("导入处理器未返回失败结果")
|
||||
})
|
||||
return map[string]int{
|
||||
|
||||
output := map[string]int{
|
||||
"total": total,
|
||||
"success": total - failed - ignore,
|
||||
"failure": failed,
|
||||
"ignore": ignore,
|
||||
}
|
||||
|
||||
if imp.Output != "" {
|
||||
res, err := gou.NewProcess(imp.Output, output).Exec()
|
||||
if err != nil {
|
||||
log.With(log.F{"output": imp.Output}).Error(err.Error())
|
||||
return output
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
// Start 运行导入(异步)
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ func TestRunSimple(t *testing.T) {
|
|||
|
||||
imp := Select("order")
|
||||
mapping := imp.AutoMapping(file)
|
||||
res := imp.Run(file, mapping)
|
||||
res := imp.Run(file, mapping).(map[string]int)
|
||||
assert.Equal(t, 1, res["ignore"])
|
||||
assert.Equal(t, 1, res["failure"])
|
||||
assert.Equal(t, 2, res["success"])
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ const PreviewNever = "never"
|
|||
type Importer struct {
|
||||
Title string `json:"title,omitempty"` // 导入名称
|
||||
Process string `json:"process"` // 处理器名称
|
||||
Output string `json:"output,omitempty"` // The process import output
|
||||
Columns []Column `json:"columns"` // 字段列表
|
||||
Option Option `json:"option,omitempty"` // 导入配置项
|
||||
Rules map[string]string `json:"rules,omitempty"` // 许可导入规则
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue