importer

package
v0.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 15, 2022 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const PreviewAlways = "always"

PreviewAlways 一直显示

View Source
const PreviewAuto = "auto"

PreviewAuto 一直显示

View Source
const PreviewNever = "never"

PreviewNever 从不显示

Variables

View Source
var Importers = map[string]*Importer{}

Importers 导入器

Functions

func DataValidate

func DataValidate(row []interface{}, value interface{}, rule string) ([]interface{}, bool)

DataValidate 数值校验

func ErrorF

func ErrorF(format string, data ...interface{}) error

ErrorF 返回错误数据对象

func GetArrayString

func GetArrayString(data map[string]interface{}, key string) ([]string, error)

GetArrayString 读取字符串数组

func GetString

func GetString(data map[string]interface{}, key string, required bool) (string, error)

GetString 读取字符串格式

func Load

func Load(cfg config.Config)

Load 加载导入器

func LoadFrom

func LoadFrom(dir string, prefix string)

LoadFrom 从特定目录加载

func Open

func Open(name string) from.Source

Open 打开导入内容源

func ProcessData

func ProcessData(process *gou.Process) interface{}

ProcessData xiang.import.Data 数据预览

func ProcessDataSetting

func ProcessDataSetting(process *gou.Process) interface{}

ProcessDataSetting xiang.import.DataSetting 数据预览表格配置

func ProcessMapping

func ProcessMapping(process *gou.Process) interface{}

ProcessMapping xiang.import.Mapping 字段映射预览

func ProcessMappingSetting

func ProcessMappingSetting(process *gou.Process) interface{}

ProcessMappingSetting xiang.import.MappingSetting 字段映射表格配置

func ProcessRun

func ProcessRun(process *gou.Process) interface{}

ProcessRun xiang.import.Run 导入数据

func ProcessSetting

func ProcessSetting(process *gou.Process) interface{}

ProcessSetting xiang.import.Setting 导入配置选项

Types

type Binding

type Binding struct {
	Label string   `json:"label"` // 目标字段标签
	Field string   `json:"field"` // 目标字段名称
	Name  string   `json:"name"`  // 源关联字段名称
	Axis  string   `json:"axis"`  // 源关联字段坐标
	Value string   `json:"value"` // 示例数据
	Rules []string `json:"rules"` // 清洗规则
}

Binding 数据绑定

type Column

type Column struct {
	Label    string   `json:"label"`              // 字段标签
	Name     string   `json:"name"`               // 字段名称
	Field    string   `json:"field"`              // 字段名称(原始值)
	Match    []string `json:"match,omitempty"`    // 匹配建议
	Rules    []string `json:"rules,omitempty"`    // 清洗规则定义
	Nullable bool     `json:"nullable,omitempty"` // 是否可以为空
	Primary  bool     `json:"primary,omitempty"`  // 是否为主键

	Key      string // 字段键名 Object Only
	IsArray  bool   // 字段是否为 Array
	IsObject bool   // 字段是否为 Object
}

Column 导入字段定义

func ColumnOf

func ColumnOf(data map[string]interface{}) (*Column, error)

ColumnOf 映射表转换为字段定义

func (Column) MarshalJSON

func (column Column) MarshalJSON() ([]byte, error)

MarshalJSON for json marshalJSON

func (Column) ToMap

func (column Column) ToMap() map[string]interface{}

ToMap 转换为映射表

func (*Column) UnmarshalJSON

func (column *Column) UnmarshalJSON(source []byte) error

UnmarshalJSON for json marshalJSON

type Importer

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"`  // 许可导入规则
}

Importer 数据导入器

func Select

func Select(name string) *Importer

Select 选择已加载导入器

func (*Importer) AutoMapping

func (imp *Importer) AutoMapping(src from.Source) *Mapping

AutoMapping 根据文件信息获取字段映射表

func (*Importer) Chunk

func (imp *Importer) Chunk(src from.Source, mapping *Mapping, cb func(line int, data [][]interface{}))

Chunk 遍历数据

func (*Importer) DataClean

func (imp *Importer) DataClean(data [][]interface{}, bindings []*Binding) ([]string, [][]interface{})

DataClean 清洗数据

func (*Importer) DataGet

func (imp *Importer) DataGet(src from.Source, page int, size int, mapping *Mapping) ([]string, [][]interface{})

DataGet 读取源数据记录

func (*Importer) DataPreview

func (imp *Importer) DataPreview(src from.Source, page int, size int, mapping *Mapping) map[string]interface{}

DataPreview 预览数据

func (*Importer) DataSetting

func (imp *Importer) DataSetting() map[string]interface{}

DataSetting 预览数据表格配置

func (*Importer) Fingerprint

func (imp *Importer) Fingerprint(src from.Source) string

Fingerprint 文件结构指纹

func (*Importer) MappingPreview

func (imp *Importer) MappingPreview(src from.Source) *Mapping

MappingPreview 预览字段映射关系

func (*Importer) MappingSetting

func (imp *Importer) MappingSetting(src from.Source) map[string]interface{}

MappingSetting 预览映射数据表格配置

func (*Importer) Run

func (imp *Importer) Run(src from.Source, mapping *Mapping) interface{}

Run 运行导入

func (*Importer) SaveAsTemplate

func (imp *Importer) SaveAsTemplate(src from.Source)

SaveAsTemplate 保存为映射模板

func (*Importer) Start

func (imp *Importer) Start()

Start 运行导入(异步)

type Mapping

type Mapping struct {
	Sheet            string     `json:"sheet"`            // 数据表
	ColStart         int        `json:"colStart"`         // 第一列的位置
	RowStart         int        `json:"rowStart"`         // 第一行的位置
	Columns          []*Binding `json:"data"`             // 字段数据列表
	AutoMatching     bool       `json:"autoMatching"`     // 是否自动匹配
	TemplateMatching bool       `json:"templateMatching"` // 是否通过已传模板匹配
}

Mapping 字段映射表

type 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 不显示
}

Option 导入配置项定

func OptionOf

func OptionOf(data map[string]interface{}) (*Option, error)

OptionOf 解析配置

func (*Option) UnmarshalJSON

func (option *Option) UnmarshalJSON(source []byte) error

UnmarshalJSON for json marshalJSON

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL