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

parse refer to res

上级 0d0006ce
......@@ -52,8 +52,8 @@ fields:
postfix: "]\t"
froms:
- from: zentao.number.v1.yaml
use: small{2} # 指定引用个数
use: small{2} # 指定引用个数
postfix: "-"
- from: zentao.number.v1.yaml
use: large{3} # 指定引用个数
use: large{3} # 指定引用个数
......@@ -112,6 +112,7 @@ type ZdRefer struct {
ColIndex int `gorm:"column:colIndex" json:"colIndex"`
Condition string `gorm:"column:condition" json:"condition"`
Count int `gorm:"column:count" json:"count"`
Step int `gorm:"column:step" json:"step"`
Rand bool `gorm:"column:rand" json:"rand"`
HasTitle bool `gorm:"column:hasTitle" json:"hasTitle"`
}
......
......@@ -69,7 +69,7 @@ func genFieldFromZdField(treeNode model.ZdField, field *model.DefField) () {
field.Limit = treeNode.Limit
}
func FileToPath(f, currFile string) (path string) {
func ConvertReferRangeToPath(f, currFile string) (path string) {
path = fileUtils.ConvertResYamlPath(f)
if path == "" {
resPath := fileUtils.GetAbsDir(currFile) + f
......@@ -85,7 +85,7 @@ func FileToPath(f, currFile string) (path string) {
return
}
func GetPathRelatedWithResDir(p string) (ret string) {
func GetRelatedPathWithResDir(p string) (ret string) {
rpl := vari.WorkDir + constant.ResDirYaml + constant.PthSep
ret = strings.Replace(p, rpl, "", 1)
......
......@@ -14,6 +14,7 @@ import (
"gopkg.in/yaml.v3"
"io/ioutil"
"path"
"strconv"
"strings"
)
......@@ -188,44 +189,56 @@ func (s *DefService) saveFieldToDB(item *model.ZdField, currPath string, parentI
refer.File = item.From
refer.Sheet = sheet
} else if item.Use != "" { // refer to ranges or instances
refer.File = item.From
refer.ColName, _, refer.Count = gen.ParseRangeSection(item.Use)
} else if item.Use != "" { // refer to ranges or instances, need to read yaml to get the type
rangeSections := gen.ParseRangeProperty(item.Use)
if len(rangeSections) > 0 { // only get the first one
rangeSection := rangeSections[0]
desc, _, count := gen.ParseRangeSection(rangeSection) // medium{2}
refer.ColName = desc
refer.Count = count
}
path := FileToPath(item.From, currPath)
path := ConvertReferRangeToPath(item.From, currPath)
_, _, refer.Type = service.ReadYamlInfo(path)
refer.File = item.From
} else if item.Config != "" { // refer to config
refer.Type = constant.ResTypeConfig
item.Config = strings.TrimSpace(item.Config)
rangeSections := gen.ParseRangeProperty(item.Config)
if len(rangeSections) == 1 {
rangeSections := gen.ParseRangeProperty(item.Config) // dir/config.yaml
if len(rangeSections) > 0 { // only get the first one
rangeSection := rangeSections[0]
desc, _, count := gen.ParseRangeSection(rangeSection)
refer.Count = count
path := FileToPath(desc, currPath)
refer.File = GetPathRelatedWithResDir(path)
path := ConvertReferRangeToPath(desc, currPath)
refer.File = GetRelatedPathWithResDir(path)
}
} else if item.Range != "" { // deal with yaml and text refer using range prop
item.Range = strings.TrimSpace(item.Range)
rangeSections := gen.ParseRangeProperty(item.Range)
if len(rangeSections) == 1 {
if len(rangeSections) > 0 { // only get the first one
rangeSection := rangeSections[0]
desc, _, count := gen.ParseRangeSection(rangeSection)
desc, step, count := gen.ParseRangeSection(rangeSection) // dir/users.txt:R{3}
if path.Ext(desc) == ".txt" {
if path.Ext(desc) == ".txt" { // dir/users.txt:2
refer.Type = constant.ResTypeText
} else if path.Ext(desc) == ".yaml" {
if strings.ToLower(step) == "r" {
refer.Rand = true
} else {
refer.Step, _ = strconv.Atoi(step)
}
} else if path.Ext(desc) == ".yaml" { // dir/content.yaml{3}
refer.Type = constant.ResTypeYaml
refer.Count = count
}
if path.Ext(desc) == ".txt" || path.Ext(desc) == ".yaml" {
refer.Count = count
path := FileToPath(desc, currPath)
refer.File = GetPathRelatedWithResDir(path)
path := ConvertReferRangeToPath(desc, currPath)
refer.File = GetRelatedPathWithResDir(path)
}
}
}
......
无法预览此类型文件
......@@ -4,7 +4,7 @@ fields:
- field: field_with_children
fields:
# - field: child1
# range: a-z
# range: a-z:2
# prefix: "part1_\t"
# postfix: '|'
# loop: "3"
......@@ -18,31 +18,31 @@ fields:
# - field: field_grandson
# range: 10-20
# prefix: int_
- field: field_text # 从一个文件中随机读取。
range: dir/users.txt:R # 相对当前文件路径。
- field: field_text
range: dir/users.txt:2
postfix: "\t"
- field: field_yaml # 引用其他的定义文件整体内容。
range: dir/content.yaml{3} # 相对当前文件路径。
- field: field_yaml
range: dir/content.yaml{3}
postfix: "\t"
- field: field_use_config # 引用其他的config定义文件。
config: dir/config.yaml{2} # 相对当前文件路径,config内包含单个字段。
- field: field_use_config
config: dir/config.yaml
postfix: "\t"
- field: field_use_ranges # 引用內置的定义文件,该文件定义了多个range,他们共享了一些field层面的属性。
from: zentao.number.v1.yaml # 引用yaml/zentao/number/v1.yaml文件里面的ranges定义。
use: medium{2} # 使用该文件中定义的medium分组。
- field: field_use_ranges
from: zentao.number.v1.yaml
use: medium{2}
postfix: "\t"
- field: field_use_instance # 引用其他的定义文件,该文件定义了多个实例。
from: ip.v1.yaml # yaml/ip/v1.yaml
use: privateC{1},privateB{2} # 使用该文件中定义的privateC和privateB两个实例。
- field: field_use_instance
from: ip.v1.yaml
use: privateC{2}
postfix: "\t"
- field: field_use_excel # 从excel数据源里面取数据。
from: address.cn.v1.china # 从data/address/v1.xlsx文件中读取名为china的工作簿。
select: city # 查询city字段。
where: state like '%山东%' # 条件是省份包含山东。
rand: true # 随机取数据
- field: field_use_excel
from: address.cn.v1.china
select: city
where: state like '%山东%'
rand: true
postfix: "\t"
aaron
ben
carl
1aaron
2ben
3carl
4
5
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册