Skip to content

Commit

Permalink
数导入API 完成
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Jan 18, 2022
1 parent c4e2ab2 commit 28ad693
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
20 changes: 18 additions & 2 deletions importer/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,24 @@ func (imp *Importer) MappingPreview(src from.Source) *Mapping {
// tpl := imp.Fingerprint(src)
// 查找已有模板

// 自动匹配
return imp.AutoMapping(src)
mapping := imp.AutoMapping(src) // 自动匹配

// 预设值
columns, rows := imp.DataGet(src, 1, 1, mapping)
if len(rows) > 0 {
row := rows[0]
rs := map[string]interface{}{}
for i := range row {
key := columns[i]
value := row[i]
rs[key] = value
}
for i := range mapping.Columns {
name := mapping.Columns[i].Field
mapping.Columns[i].Value = fmt.Sprintf("%v", rs[name])
}
}
return mapping
}

// DataSetting 预览数据表格配置
Expand Down
1 change: 1 addition & 0 deletions importer/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ type Binding struct {
Field string `json:"field"` // 目标字段名称
Name string `json:"name"` // 源关联字段名称
Axis string `json:"axis"` // 源关联字段坐标
Value string `json:"value"` // 示例数据
Rules []string `json:"rules"` // 清洗规则
}
2 changes: 1 addition & 1 deletion xiang/apis/import.http.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"description": "数据分析接口API",
"group": "xiang/import",
"guard": "-",
"guard": "bearer-jwt",
"paths": [
{
"path": "/:name",
Expand Down

0 comments on commit 28ad693

Please sign in to comment.