41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
// Package tool ...
|
|
//
|
|
// Description : 对比两个数据是否相同 + 构建不同数据的前后值
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 2024-03-08 11:03
|
|
package tool
|
|
|
|
import (
|
|
"git.zhangdeman.cn/zhangdeman/wrapper"
|
|
"git.zhangdeman.cn/zhangdeman/wrapper/tool/define"
|
|
)
|
|
|
|
var (
|
|
Diff = &diff{}
|
|
)
|
|
|
|
type diff struct {
|
|
}
|
|
|
|
// Compare 比较两个数据源的指定字段
|
|
//
|
|
// Author : go_developer@163.com<白茶清欢>
|
|
//
|
|
// Date : 15:53 2024/3/8
|
|
func (d *diff) Compare(fieldList []string, input wrapper.Map, storage wrapper.Map, option *define.DiffOption) map[string]*define.DiffResult {
|
|
if nil == option {
|
|
option = define.NewDiffOption()
|
|
}
|
|
res := make(map[string]*define.DiffResult)
|
|
for _, itemField := range fieldList {
|
|
if compareFunc, exist := option.CustomDiffFuncTable[itemField]; exist && nil != compareFunc {
|
|
res[itemField] = compareFunc(itemField, input, storage, option)
|
|
} else {
|
|
res[itemField] = define.DefaultDiffFunc(itemField, input, storage, option)
|
|
}
|
|
}
|
|
return res
|
|
}
|