提交 a6de72f3 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

convert refer to nested fields

上级 be73531a
package gen
import (
"fmt"
"github.com/easysoft/zendata/src/model"
constant "github.com/easysoft/zendata/src/utils/const"
stringUtils "github.com/easysoft/zendata/src/utils/string"
"regexp"
"strconv"
"strings"
)
......@@ -45,6 +47,8 @@ func GenerateForDefinition(total int, fieldsToExport string, out string, table s
}
func GenerateForField(field *model.Field, total int) []string {
convertFieldReferToNestedIfNeeded(field)
values := make([]string, 0)
if field.Type == "custom" {
......@@ -179,4 +183,26 @@ func GetFieldValStr(field model.Field, val interface{}) string {
}
return str
}
func convertFieldReferToNestedIfNeeded(field *model.Field) {
regx := regexp.MustCompile(`\$\{([a-zA-z0-9_]+)\}`)
arr := regx.FindAllStringSubmatch(field.Range, -1)
fmt.Println(arr)
if len(arr) > 0 {
for _, a := range arr {
name := a[1]
child := model.Field{}
if constant.LoadedFields[name].Name != "" {
child = constant.LoadedFields[name]
} else {
child.Name = a[1]
child.Type = "custom"
}
field.Fields = append(field.Fields, child)
}
}
}
\ No newline at end of file
......@@ -4,8 +4,8 @@ author: zentao
version: 1.0
fields:
- name: custom_field
note: 自定义
- name: numb
note: 数字
type: list
range: 1-99:R
format: "%05d"
\ No newline at end of file
format: "%03d"
\ No newline at end of file
......@@ -56,7 +56,7 @@ fields:
- name: domain
note: 域名,全局定义
type: custom
- name: custom_field
- name: numb
note: 从文件读定义
type: custom
range: custom.yaml
......@@ -64,12 +64,15 @@ fields:
- name: field4
note: 引用。
type: list
range: ${user_name}${numb}@${domain}.com
range: ${user_name}_${numb}@${domain}
- name: user_name
note: 用户名
fields:
- name: first_name
type: custom
- name: separator
type: list
range: "_"
- name: last_name
type: custom
- name: numb
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册