mapping_rule.go
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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
}