diff --git a/imports/imports.go b/imports/imports.go new file mode 100644 index 00000000..dd3e4a86 --- /dev/null +++ b/imports/imports.go @@ -0,0 +1 @@ +package imports diff --git a/imports/types.go b/imports/types.go new file mode 100644 index 00000000..3ac22386 --- /dev/null +++ b/imports/types.go @@ -0,0 +1,41 @@ +package imports + +import "github.com/yaoapp/gou" + +// PreviewAuto 一直显示 +const PreviewAuto = "auto" + +// PreviewAlways 一直显示 +const PreviewAlways = "always" + +// PreviewNever 从不显示 +const PreviewNever = "never" + +// Imports 数据导入 +type Imports struct { + Title string `json:"title,omitempty"` // 导入名称 + Process *gou.Process `json:"process"` // 处理器名称 + Columns []Column `json:"columns"` // 字段列表 + Option Option `json:"option,omitempty"` // 导入配置项 +} + +// Column 导入字段定义 +type Column struct { + Label string `json:"label"` // 字段标签 + Name string `json:"name"` // 字段名称 + Match []string `json:"match,omitempty"` // 匹配建议 + Rules []gou.Process `json:"rules,omitempty"` // 清洗规则定义 + Nullable bool `json:"nullable,omitempty"` // 是否可以为空 + + Key string // 字段键名 Object Only + IsArray bool // 字段是否为 Array + IsObject bool // 字段是否为 Object +} + +// Option 导入配置项定 +type Option struct { + AutoMatching bool `json:"autoMatching,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/assets/multiple-columns.xlsx b/tests/imports/assets/multiple-columns.xlsx new file mode 100644 index 00000000..fa6ad9c8 Binary files /dev/null and b/tests/imports/assets/multiple-columns.xlsx differ diff --git a/tests/imports/assets/multiple.xlsx b/tests/imports/assets/multiple.xlsx new file mode 100644 index 00000000..b8f0456c Binary files /dev/null and b/tests/imports/assets/multiple.xlsx differ diff --git a/tests/imports/assets/simple.csv b/tests/imports/assets/simple.csv new file mode 100644 index 00000000..61c45121 --- /dev/null +++ b/tests/imports/assets/simple.csv @@ -0,0 +1,5 @@ +订单号,姓名,手机,性别,年龄,商品名称,数量,单价,总价,备注 +SN202101120018,张三,13211000011,男,26,彩绘湖北地图,3,65.5,196.5, +,李四,13211000011,男,42,景祐遁甲符应经,1,34.8,34.8, +SN202101120019,王二麻子,13410001998,男,51,太极先天后天三图说,1,24.35,72.85,孔夫子二手交易 +SN202101120019,王二麻子,13410001998,男,51,五要奇书,1,48.5,72.85,孔夫子二手交易 diff --git a/tests/imports/assets/simple.xlsx b/tests/imports/assets/simple.xlsx new file mode 100644 index 00000000..279a7ee0 Binary files /dev/null and b/tests/imports/assets/simple.xlsx differ diff --git a/tests/imports/manu.imp.json b/tests/imports/manu.imp.json new file mode 100644 index 00000000..794fbf14 --- /dev/null +++ b/tests/imports/manu.imp.json @@ -0,0 +1,76 @@ +{ + "title": "导入订单数据", + "process": "flows.order.Import", + "columns": [ + { + "label": "订单号", + "name": "order_sn", + "match": ["订单号", "订单", "order_sn", "id"], + "rules": ["scripts.rules.order_sn"], + "primary": true + }, + { + "label": "用户", + "name": "user.name", + "match": ["用户名称", "姓名", "user_id"], + "rules": ["scripts.rules.FmtUser"], + "nullable": true + }, + { + "label": "性别", + "name": "user.sex", + "match": ["性别", "gender", "sex"], + "rules": ["scripts.rules.FmtUser"], + "nullable": true + }, + { + "label": "年龄", + "name": "user.age", + "match": ["年龄", "age"], + "rules": ["scripts.rules.FmtUser"], + "nullable": true + }, + { + "label": "手机号", + "name": "mobile", + "match": ["手机号", "手机", "mobile"], + "rules": ["scripts.rules.mobile"] + }, + { + "label": "商品", + "name": "skus[*].name", + "match": ["商品", "商品名称", "goods", "skus", "sku_id", "goods_id"], + "rules": ["scripts.rules.FmtGoods"] + }, + { + "label": "数量", + "name": "skus[*].amount", + "match": ["数量", "amount"], + "rules": ["scripts.rules.FmtGoods"] + }, + { + "label": "单价", + "name": "skus[*].price", + "match": ["单价", "price", "价格"], + "rules": ["scripts.rules.FmtGoods"] + }, + { + "label": "总价", + "name": "total", + "match": ["总价", "total", "total_price"], + "rules": ["scripts.rules.FmtGoods"] + }, + { + "label": "备注", + "name": "remark", + "match": ["备注", "说明", "其他"] + } + ], + "option": { + "autoMatching": true, + "chunkSize": 500, + "logging": "error", + "mappingPreview": "auto", + "dataPreview": "auto" + } +}