mapping_rule.go 1.7 KB
package domain

import "time"

// 匹配规则配置
type MappingRule struct {
	// 匹配规则ID
	MappingRuleId int `json:"mappingRuleId"`
	// 名称
	Name string `json:"name"`
	// 表Id
	TableId int `json:"tableId"`
	// 文件ID
	FileId int `json:"fileId"`
	// 主表列
	MainTableFields []*Field `json:"mainTableFields"`
	// 校验文件列
	VerifiedFileFields []*Field `json:"verifiedFileFields"`
	// 校验文件列
	MappingFields []*MappingField `json:"mappingFields"`
	// 创建时间
	CreatedAt time.Time `json:"createdAt"`
	// 更新时间
	UpdatedAt time.Time `json:"updatedAt"`
	// 删除时间
	DeletedAt time.Time `json:"deletedAt"`
	// 扩展
	Context *Context `json:"context"`
}

type MappingRuleRepository interface {
	Save(mappingRule *MappingRule) (*MappingRule, error)
	Remove(mappingRule *MappingRule) (*MappingRule, error)
	FindOne(queryOptions map[string]interface{}) (*MappingRule, error)
	Find(queryOptions map[string]interface{}) (int64, []*MappingRule, error)
}

func (mappingRule *MappingRule) Identify() interface{} {
	if mappingRule.MappingRuleId == 0 {
		return nil
	}
	return mappingRule.MappingRuleId
}

func (mappingRule *MappingRule) Update(data map[string]interface{}) error {
	return nil
}

type MappingField struct {
	MainTableField        *Field `json:"mainTableField"`
	VerifiedFileFieldName string `json:"verifiedFileFieldName"`
}

func NewMappingFields(all []*Field, some []*Field) []*MappingField {
	var result []*MappingField
	//allMap :=(Fields)(all).ToMap()
	someMap := (Fields)(some).ToMap()
	for _, f := range all {
		item := &MappingField{
			MainTableField: f,
		}
		if v, ok := someMap[f.Name]; ok {
			item.VerifiedFileFieldName = v.Name
		}
		result = append(result, item)
	}
	return result
}