提交 f063edb1 编写于 作者: 陈琦

fix issues

上级 371b6d26
......@@ -11,7 +11,7 @@
/nohup.out
/test/ztf/conf/
/test/ztf/log/
/demo/output/
/demo/out/
/test/ztf/._config.yaml
/test/ztf/._default.yaml
/._config.yaml
......@@ -23,3 +23,5 @@
/qshell.log
/log-agent/
/data/test/
/test/out/
/log-agent/
......@@ -3,6 +3,4 @@ desc: 描述
version: 1.0
fields:
- field: first # 字段名
range: 1-5, 30 # 1,2,3,4,5,30,1,2,3,4,5
prefix: "=="
postfix: "--"
\ No newline at end of file
range: 1-5, 30 # 1,2,3,4,5,30,1,2,3,4,5
\ No newline at end of file
......@@ -23,7 +23,7 @@ func ParseSql(file string, out string) {
def.Init(tableName, "automated export", "", "1.0")
for _, col := range columns {
field := model.FieldSimple{}
field := model.FieldSimple{Range: " "}
field.Init(col)
def.Fields = append(def.Fields, field)
}
......@@ -41,7 +41,7 @@ func ParseSql(file string, out string) {
}
entTime := time.Now().Unix()
logUtils.PrintTo(i118Utils.I118Prt.Sprintf("generate_yaml", len(statements), out, entTime - startTime ))
logUtils.PrintTo(i118Utils.I118Prt.Sprintf("generate_yaml", len(statements), out, entTime-startTime))
}
func getCreateStatement(file string) map[string]string {
......@@ -85,4 +85,4 @@ func getColumnsFromCreateStatement(sent string) []string {
}
return fieldLines
}
\ No newline at end of file
}
......@@ -5,10 +5,10 @@ import (
constant "github.com/easysoft/zendata/src/utils/const"
)
func GenerateByteItems(start byte, end byte, step int, rand bool, repeat int) []interface{} {
func GenerateByteItems(start byte, end byte, step int, rand bool, repeat int, tag string) []interface{} {
if !rand {
return generateByteItemsByStep(start, end, step, repeat)
} else{
} else {
return generateByteItemsRand(start, end, step, repeat)
}
}
......@@ -19,7 +19,7 @@ func generateByteItemsByStep(start byte, end byte, step int, repeat int) []inter
total := 0
for i := 0; true; {
val := start + byte(int(i)*step)
if (val > end && step > 0) || (val < end && step < 0) {
if (val > end && step > 0) || (val < end && step < 0) {
break
}
......@@ -69,4 +69,4 @@ func generateByteItemsRand(start byte, end byte, step int, repeat int) []interfa
}
return arr
}
\ No newline at end of file
}
......@@ -6,6 +6,7 @@ import (
fileUtils "github.com/easysoft/zendata/src/utils/file"
logUtils "github.com/easysoft/zendata/src/utils/log"
"github.com/easysoft/zendata/src/utils/vari"
"github.com/mattn/go-runewidth"
"os"
"path/filepath"
"strings"
......@@ -37,7 +38,7 @@ func Decode(defaultFile, configFile, fieldsToExportStr, input, output string) {
data := fileUtils.ReadFile(input)
var ret []map[string]interface{}
LinesToMap(data, fieldsToExport, &ret)
linesToMap(data, fieldsToExport, &ret)
jsonObj, _ := json.Marshal(ret)
vari.JsonResp = string(jsonObj)
......@@ -45,7 +46,7 @@ func Decode(defaultFile, configFile, fieldsToExportStr, input, output string) {
logUtils.PrintLine(vari.JsonResp)
}
func LinesToMap(str string, fieldsToExport []string, ret *[]map[string]interface{}) {
func linesToMap(str string, fieldsToExport []string, ret *[]map[string]interface{}) {
start := 0
if vari.WithHead {
start = 1
......@@ -64,15 +65,16 @@ func LinesToMap(str string, fieldsToExport []string, ret *[]map[string]interface
}
func decodeOneLevel(line string, fields []model.DefField, rowMap *map[string]interface{}) {
left := []rune(line)
for j, field := range fields {
col := ""
if field.Length > 0 {
col = string(left[:field.Length])
left = left[field.Length:]
len := field.Length + runewidth.StringWidth(field.Prefix) + runewidth.StringWidth(field.Postfix)
col = string(left[:len])
left = left[len:]
} else {
sepStr := ""
if j < len(fields)-1 {
......@@ -94,6 +96,10 @@ func decodeOneLevel(line string, fields []model.DefField, rowMap *map[string]int
}
}
if vari.Trim {
col = strings.TrimLeft(col, field.Prefix)
col = strings.TrimRight(col, field.Postfix)
}
(*rowMap)[field.Field] = col
children := field.Fields
......
......@@ -32,7 +32,7 @@ func GenerateFieldValuesFromExcel(filePath, sheet string, field *model.DefField)
list, selectCol := ReadDataFromSQLite(*field, dbName, sheet)
// get index for data retrieve
numbs := GenerateIntItems(0, (int64)(len(list)-1), 1, false, 1)
numbs := GenerateIntItems(0, (int64)(len(list)-1), 1, false, 1, "")
// get data by index
index := 0
for _, numb := range numbs {
......
......@@ -7,10 +7,10 @@ import (
"strings"
)
func GenerateFloatItems(start float64, end float64, step interface{}, rand bool, repeat int) []interface{} {
func GenerateFloatItems(start float64, end float64, step interface{}, rand bool, repeat int, tag string) []interface{} {
if !rand {
return generateFloatItemsByStep(start, end, step.(float64), repeat)
} else{
} else {
return generateFloatItemsRand(start, end, step.(float64), repeat)
}
}
......@@ -21,8 +21,8 @@ func generateFloatItemsByStep(start float64, end float64, step float64, repeat i
total := 0
for i := 0; true; {
val := start + float64(i) * step
if (val > end && step > 0) || (val < end && step < 0) {
val := start + float64(i)*step
if (val > end && step > 0) || (val < end && step < 0) {
break
}
......@@ -54,7 +54,7 @@ func generateFloatItemsRand(start float64, end float64, step float64, repeat int
rand = rand * -1
}
val := start + float64(rand) * step
val := start + float64(rand)*step
for round := 0; round < repeat; round++ {
arr = append(arr, val)
......@@ -109,16 +109,16 @@ func InterfaceToStr(val interface{}) string {
str := "n/a"
switch val.(type) {
case int64:
str = strconv.FormatInt(val.(int64), 10)
case float64:
precision, _ := GetPrecision(val.(float64), nil)
str = strconv.FormatFloat(val.(float64), 'f', precision, 64)
case byte:
str = string(val.(byte))
case string:
str = val.(string)
default:
case int64:
str = strconv.FormatInt(val.(int64), 10)
case float64:
precision, _ := GetPrecision(val.(float64), nil)
str = strconv.FormatFloat(val.(float64), 'f', precision, 64)
case byte:
str = string(val.(byte))
case string:
str = val.(string)
default:
}
return str
}
\ No newline at end of file
}
......@@ -26,7 +26,7 @@ func GetRandFromList(list []string, repeatStr string, count int) []string {
return ret
}
func GetRandFromRange(dataType, start, end, step, repeatStr, precisionStr string, count int, format string) []string {
func GetRandFromRange(dataType, start, end, step, repeatStr, repeatTag, precisionStr string, count int, format string) []string {
repeat, _ := strconv.Atoi(repeatStr)
precision, _ := strconv.Atoi(precisionStr)
......@@ -41,7 +41,7 @@ func GetRandFromRange(dataType, start, end, step, repeatStr, precisionStr string
stepInt = stepInt * -1
}
countInRound := (endInt - startInt) / stepInt + 1
countInRound := (endInt-startInt)/stepInt + 1
for i := 0; i < count; i++ {
rand := commonUtils.RandNum64(countInRound)
......@@ -54,7 +54,9 @@ func GetRandFromRange(dataType, start, end, step, repeatStr, precisionStr string
item := strconv.FormatInt(val, 10)
if format != "" {
formatVal, success := stringUtils.FormatStr(format, val, 0)
if success { item = formatVal }
if success {
item = formatVal
}
}
for round := 0; round < repeat; round++ {
......@@ -73,7 +75,7 @@ func GetRandFromRange(dataType, start, end, step, repeatStr, precisionStr string
stepInt = stepInt * -1
}
countInRound := (int64(endChar) - int64(startChar)) / stepInt + 1
countInRound := (int64(endChar)-int64(startChar))/stepInt + 1
for i := 0; i < count; i++ {
rand := commonUtils.RandNum64(countInRound)
......@@ -86,7 +88,9 @@ func GetRandFromRange(dataType, start, end, step, repeatStr, precisionStr string
item := string(val)
if format != "" {
formatVal, success := stringUtils.FormatStr(format, val, 0)
if success { item = formatVal }
if success {
item = formatVal
}
}
for round := 0; round < repeat; round++ {
......@@ -106,7 +110,7 @@ func GetRandFromRange(dataType, start, end, step, repeatStr, precisionStr string
stepFloat = stepFloat * -1
}
countInRound := (endFloat - startFloat) / stepFloat + 1
countInRound := (endFloat-startFloat)/stepFloat + 1
for i := 0; i < count; i++ {
rand := commonUtils.RandNum64(int64(countInRound))
......@@ -121,7 +125,9 @@ func GetRandFromRange(dataType, start, end, step, repeatStr, precisionStr string
item := strconv.FormatFloat(val, 'f', precision, 64)
if format != "" {
formatVal, success := stringUtils.FormatStr(format, val, precision)
if success { item = formatVal }
if success {
item = formatVal
}
}
for round := 0; round < repeat; round++ {
......@@ -134,4 +140,4 @@ func GetRandFromRange(dataType, start, end, step, repeatStr, precisionStr string
}
return ret
}
\ No newline at end of file
}
......@@ -5,69 +5,115 @@ import (
constant "github.com/easysoft/zendata/src/utils/const"
)
func GenerateIntItems(start int64, end int64, step interface{}, rand bool, repeat int) []interface{} {
func GenerateIntItems(start int64, end int64, step interface{}, rand bool, repeat int, repeatTag string) []interface{} {
if !rand {
return generateIntItemsByStep(start, end, step.(int), repeat)
} else{
return generateIntItemsRand(start, end, step.(int), repeat)
return generateIntItemsByStep(start, end, step.(int), repeat, repeatTag)
} else {
return generateIntItemsRand(start, end, step.(int), repeat, repeatTag)
}
}
func generateIntItemsByStep(start int64, end int64, step int, repeat int) []interface{} {
func generateIntItemsByStep(start int64, end int64, step int, repeat int, repeatTag string) []interface{} {
arr := make([]interface{}, 0)
total := 0
for i := 0; true; {
val := start + int64(i * step)
if (val > end && step > 0) || (val < end && step < 0) {
break
}
if repeatTag == "" {
for i := 0; true; {
val := start + int64(i*step)
if (val > end && step > 0) || (val < end && step < 0) {
break
}
for round := 0; round < repeat; round++ {
arr = append(arr, val)
for round := 0; round < repeat; round++ {
arr = append(arr, val)
total++
if total > constant.MaxNumb {
total++
if total > constant.MaxNumb {
break
}
}
if total >= constant.MaxNumb {
break
}
i++
}
} else if repeatTag == "!" {
for round := 0; round < repeat; round++ {
for i := 0; true; {
val := start + int64(i*step)
if (val > end && step > 0) || (val < end && step < 0) {
break
}
arr = append(arr, val)
if total >= constant.MaxNumb {
break
}
i++
}
if total >= constant.MaxNumb {
break
if total >= constant.MaxNumb {
break
}
}
i++
}
return arr
}
func generateIntItemsRand(start int64, end int64, step int, repeat int) []interface{} {
func generateIntItemsRand(start int64, end int64, step int, repeat int, repeatTag string) []interface{} {
arr := make([]interface{}, 0)
countInRound := (end - start) / int64(step) + 1
countInRound := (end-start)/int64(step) + 1
total := 0
for i := int64(0); i < countInRound; {
rand := commonUtils.RandNum64(countInRound)
if step < 0 {
rand = rand * -1
}
val := start + rand
for round := 0; round < repeat; round++ {
arr = append(arr, val)
if repeatTag == "" {
for i := int64(0); i < countInRound; {
rand := commonUtils.RandNum64(countInRound)
if step < 0 {
rand = rand * -1
}
total++
val := start + rand
for round := 0; round < repeat; round++ {
arr = append(arr, val)
total++
if total > constant.MaxNumb {
break
}
}
if total > constant.MaxNumb {
break
}
i++
}
} else if repeatTag == "!" {
for round := 0; round < repeat; round++ {
for i := int64(0); i < countInRound; {
rand := commonUtils.RandNum64(countInRound)
if step < 0 {
rand = rand * -1
}
val := start + rand
arr = append(arr, val)
if total > constant.MaxNumb {
break
if total > constant.MaxNumb {
break
}
i++
}
if total > constant.MaxNumb {
break
}
}
i++
}
return arr
}
\ No newline at end of file
}
......@@ -50,7 +50,7 @@ func CreateFieldValuesFromList(field *model.DefField, fieldValue *model.FieldWit
continue
}
descStr, stepStr, repeat := ParseRangeSection(rangeSection) // parse 2
descStr, stepStr, count, countTag := ParseRangeSection(rangeSection) // parse 2
if strings.ToLower(stepStr) == "r" {
(*field).IsRand = true
}
......@@ -59,11 +59,11 @@ func CreateFieldValuesFromList(field *model.DefField, fieldValue *model.FieldWit
items := make([]interface{}, 0)
if typ == "literal" {
items = CreateValuesFromLiteral(field, desc, stepStr, repeat)
items = CreateValuesFromLiteral(field, desc, stepStr, count, countTag)
} else if typ == "interval" {
items = CreateValuesFromInterval(field, desc, stepStr, repeat)
items = CreateValuesFromInterval(field, desc, stepStr, count, countTag)
} else if typ == "yaml" { // load from a yaml
items = CreateValuesFromYaml(field, desc, stepStr, repeat)
items = CreateValuesFromYaml(field, desc, stepStr, count, countTag)
field.ReferToAnotherYaml = true
}
......@@ -160,7 +160,7 @@ func CheckRangeType(startStr string, endStr string, stepStr string) (string, int
return "string", 1, 0, false // is string
}
func CreateValuesFromLiteral(field *model.DefField, desc string, stepStr string, repeat int) (items []interface{}) {
func CreateValuesFromLiteral(field *model.DefField, desc string, stepStr string, repeat int, repeatTag string) (items []interface{}) {
elemArr := ParseDesc(desc)
step, _ := strconv.Atoi(stepStr)
if step == 0 {
......@@ -170,33 +170,37 @@ func CreateValuesFromLiteral(field *model.DefField, desc string, stepStr string,
if field.Path != "" && stepStr == "r" {
items = append(items, Placeholder(field.Path))
mp := placeholderMapForRandValues("list", elemArr, "", "", "", "", field.Format)
mp := placeholderMapForRandValues("list", elemArr, "", "", "", "", field.Format, repeatTag)
vari.RandFieldNameToValuesMap[field.Path] = mp
return
}
for i := 0; i < len(elemArr); {
idx := i
if field.Path == "" && stepStr == "r" {
idx = commonUtils.RandNum(len(elemArr)) // should set random here too
}
val := elemArr[idx]
if repeatTag == "" {
for i := 0; i < len(elemArr); {
idx := i
if field.Path == "" && stepStr == "r" {
idx = commonUtils.RandNum(len(elemArr)) // should set random here too
}
for round := 0; round < repeat; round++ {
items = append(items, val)
val := elemArr[idx]
total = appendValues(&items, val, repeat, total)
total++
if total > constant.MaxNumb {
if total >= constant.MaxNumb {
break
}
i += step
}
} else if repeatTag == "!" {
isRand := field.Path == "" && stepStr == "r"
for i := 0; i < repeat; {
total = appendArrItems(&items, elemArr, total, isRand)
if total >= constant.MaxNumb {
break
if total >= constant.MaxNumb {
break
}
i += step
}
i += step
}
if field.Path == "" && stepStr == "r" { // for ranges and instances, random
......@@ -206,7 +210,7 @@ func CreateValuesFromLiteral(field *model.DefField, desc string, stepStr string,
return
}
func CreateValuesFromInterval(field *model.DefField, desc, stepStr string, repeat int) (items []interface{}) {
func CreateValuesFromInterval(field *model.DefField, desc, stepStr string, repeat int, repeatTag string) (items []interface{}) {
elemArr := strings.Split(desc, "-")
startStr := elemArr[0]
endStr := startStr
......@@ -219,7 +223,7 @@ func CreateValuesFromInterval(field *model.DefField, desc, stepStr string, repea
if field.Path != "" && dataType != "string" && rand { // random. for res, field.Path == ""
items = append(items, Placeholder(field.Path))
mp := placeholderMapForRandValues(dataType, []string{}, startStr, endStr, stepStr, strconv.Itoa(precision), field.Format)
mp := placeholderMapForRandValues(dataType, []string{}, startStr, endStr, stepStr, strconv.Itoa(precision), field.Format, repeatTag)
vari.RandFieldNameToValuesMap[field.Path] = mp
return
......@@ -229,17 +233,17 @@ func CreateValuesFromInterval(field *model.DefField, desc, stepStr string, repea
startInt, _ := strconv.ParseInt(startStr, 0, 64)
endInt, _ := strconv.ParseInt(endStr, 0, 64)
items = GenerateIntItems(startInt, endInt, step.(int), rand, repeat)
items = GenerateIntItems(startInt, endInt, step.(int), rand, repeat, repeatTag)
} else if dataType == "float" {
startFloat, _ := strconv.ParseFloat(startStr, 64)
endFloat, _ := strconv.ParseFloat(endStr, 64)
field.Precision = precision
items = GenerateFloatItems(startFloat, endFloat, step, rand, repeat)
items = GenerateFloatItems(startFloat, endFloat, step, rand, repeat, repeatTag)
} else if dataType == "char" {
items = GenerateByteItems(startStr[0], endStr[0], step.(int), rand, repeat)
items = GenerateByteItems(startStr[0], endStr[0], step.(int), rand, repeat, repeatTag)
} else if dataType == "string" {
if repeat == 0 {
......@@ -257,7 +261,7 @@ func CreateValuesFromInterval(field *model.DefField, desc, stepStr string, repea
return
}
func CreateValuesFromYaml(field *model.DefField, yamlFile, stepStr string, repeat int) (items []interface{}) {
func CreateValuesFromYaml(field *model.DefField, yamlFile, stepStr string, repeat int, repeatTag string) (items []interface{}) {
// keep root def, since vari.ZdDef will be overwrite by refer yaml file
rootDef := vari.Def
defaultDir := vari.DefaultFileDir
......@@ -293,18 +297,52 @@ func Placeholder(str string) string {
return "${" + str + "}"
}
func placeholderMapForRandValues(tp string, list []string, start, end, step, precision, format string) map[string]interface{} {
func placeholderMapForRandValues(tp string, list []string, start, end, step, precision, format string, repeatTag string) map[string]interface{} {
ret := map[string]interface{}{}
ret["type"] = tp
ret["list"] = list // for literal values
// for literal values
ret["list"] = list
ret["start"] = start // for interval values
// for interval values
ret["start"] = start
ret["end"] = end
ret["step"] = step
ret["precision"] = precision
ret["format"] = format
ret["repeatTag"] = repeatTag
return ret
}
func appendValues(items *[]interface{}, val string, repeat int, total int) int {
for round := 0; round < repeat; round++ {
*items = append(*items, val)
total++
if total > constant.MaxNumb {
break
}
}
return total
}
func appendArrItems(items *[]interface{}, arr []string, total int, isRand bool) int {
for i := 0; i < len(arr); i++ {
idx := i
if isRand {
idx = commonUtils.RandNum(len(arr)) // should set random here too
}
*items = append(*items, arr[idx])
total++
if total > constant.MaxNumb {
break
}
}
return total
}
......@@ -83,7 +83,7 @@ func ParseDesc(desc string) (items []string) {
step =>1
repeat =>2
*/
func ParseRangeSection(item string) (entry string, step string, repeat int) {
func ParseRangeSection(item string) (entry string, step string, repeat int, repeatTag string) {
item = strings.TrimSpace(item)
if item == "" {
......@@ -103,11 +103,18 @@ func ParseRangeSection(item string) (entry string, step string, repeat int) {
return
}
regx := regexp.MustCompile(`\{(.*)\}`)
regx := regexp.MustCompile(`\{(.*)!?\}`)
arr := regx.FindStringSubmatch(item)
tag := ""
if len(arr) == 2 {
repeat, _ = strconv.Atoi(arr[1])
str := strings.TrimSpace(arr[1])
if str[len(str)-1:] == "!" {
tag = str[len(str)-1:]
str = strings.TrimSpace(str[:len(str)-1])
}
repeat, _ = strconv.Atoi(str)
}
repeatTag = tag
itemWithoutRepeat := regx.ReplaceAllString(item, "")
sectionArr := strings.Split(itemWithoutRepeat, ":")
......@@ -128,7 +135,7 @@ func ParseRangeSection(item string) (entry string, step string, repeat int) {
if repeat == 0 {
repeat = 1
}
return entry, step, repeat
return entry, step, repeat, repeatTag
}
/**
......@@ -162,7 +169,7 @@ func ParseRangeSectionDesc(str string) (typ string, desc string) {
for _, item := range arr {
if isScopeStr(item) && isCharOrNumberScope(item) { // only support a-z and 0-9 in []
tempField := model.DefField{}
values := CreateValuesFromInterval(&tempField, item, "", 1)
values := CreateValuesFromInterval(&tempField, item, "", 1, "")
for _, val := range values {
temp += InterfaceToStr(val) + ","
......
......@@ -196,27 +196,28 @@ func getValForPlaceholder(placeholderStr string, count int) []string {
}
strs := make([]string, 0)
repeatTag := mp["repeatTag"].(string)
if tp == "int" {
start := mp["start"].(string)
end := mp["end"].(string)
precision := mp["precision"].(string)
format := mp["format"].(string)
strs = helper.GetRandFromRange("int", start, end, "1", repeat, precision, count, format)
strs = helper.GetRandFromRange("int", start, end, "1", repeat, repeatTag, precision, count, format)
} else if tp == "float" {
start := mp["start"].(string)
end := mp["end"].(string)
precision := mp["precision"].(string)
format := mp["format"].(string)
strs = helper.GetRandFromRange("float", start, end, "1", repeat, precision, count, format)
strs = helper.GetRandFromRange("float", start, end, "1", repeat, repeatTag, precision, count, format)
} else if tp == "char" {
start := mp["start"].(string)
end := mp["end"].(string)
precision := mp["precision"].(string)
format := mp["format"].(string)
strs = helper.GetRandFromRange("char", start, end, "1", repeat, precision, count, format)
strs = helper.GetRandFromRange("char", start, end, "1", repeat, repeatTag, precision, count, format)
} else if tp == "list" {
list := mp["list"].([]string)
strs = helper.GetRandFromList(list, repeat, count)
......
......@@ -56,7 +56,7 @@ func CreateFieldValuesFromText(field *model.DefField, fieldValue *model.FieldWit
}
// get index for data retrieve
numbs := GenerateIntItems(0, (int64)(len(list)-1), step, rand, 1)
numbs := GenerateIntItems(0, (int64)(len(list)-1), step, rand, 1, "")
// get data by index
index := 0
for _, numb := range numbs {
......
......@@ -58,7 +58,7 @@ func createTimestampSectionValue(section string, values *[]interface{}) {
}
// get index numbers for data retrieve
numbs := GenerateIntItems(start, end, step, false, 1)
numbs := GenerateIntItems(start, end, step, false, 1, "")
// generate data by index
index := 0
......
......@@ -89,11 +89,12 @@ type ZdSection struct {
Ord int `gorm:"column:ord;default:1" json:"ord"`
// for range
Start string `gorm:"column:start" json:"start"`
End string `gorm:"column:end" json:"end"`
Step int `gorm:"column:step;default:1" json:"step"`
Repeat string `gorm:"column:repeat;default:1" json:"repeat"`
Rand bool `gorm:"column:rand;default:false" json:"rand"`
Start string `gorm:"column:start" json:"start"`
End string `gorm:"column:end" json:"end"`
Step int `gorm:"column:step;default:1" json:"step"`
Repeat string `gorm:"column:repeat;default:1" json:"repeat"`
RepeatTag string `gorm:"column:repeatTag" json:"repeatTag"`
Rand bool `gorm:"column:rand;default:false" json:"rand"`
// for arr and const
Text string `gorm:"-" json:"-"`
......@@ -117,6 +118,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"`
CountTag string `gorm:"column:countTag" json:"countTag"`
Step int `gorm:"column:step" json:"step"`
Rand bool `gorm:"column:rand" json:"rand"`
HasTitle bool `gorm:"column:hasTitle" json:"hasTitle"`
......
......@@ -39,7 +39,7 @@ func (r *SectionRepo) Remove(id uint, ownerType string) (err error) {
}
func (r *SectionRepo) SaveFieldSectionToDB(rangeSection string, ord int, fieldID uint, ownerType string) {
descStr, stepStr, count := gen.ParseRangeSection(rangeSection)
descStr, stepStr, count, countTag := gen.ParseRangeSection(rangeSection)
typ, desc := gen.ParseRangeSectionDesc(descStr)
if typ == "literal" && desc[:1] == string(constant.LeftBrackets) &&
......@@ -70,7 +70,7 @@ func (r *SectionRepo) SaveFieldSectionToDB(rangeSection string, ord int, fieldID
section := model.ZdSection{OwnerType: ownerType, OwnerID: fieldID, Type: typ,
Value: desc, Start: start, End: end, Ord: ord,
Step: step, Repeat: countStr, Rand: rand}
Step: step, Repeat: countStr, RepeatTag: countTag, Rand: rand}
r.Create(&section)
}
......
......@@ -263,9 +263,10 @@ func (s *DefService) saveFieldToDB(field *model.ZdField, def model.ZdDef, currPa
rangeSections := gen.ParseRangeProperty(field.Use)
if len(rangeSections) > 0 { // only get the first one
rangeSection := rangeSections[0]
desc, _, count := gen.ParseRangeSection(rangeSection) // medium{2}
desc, _, count, countTag := gen.ParseRangeSection(rangeSection) // medium{2!}
refer.ColName = desc
refer.Count = count
refer.CountTag = countTag
}
path := fileUtils.ConvertReferRangeToPath(field.From, currPath)
......@@ -278,8 +279,9 @@ func (s *DefService) saveFieldToDB(field *model.ZdField, def model.ZdDef, currPa
rangeSections := gen.ParseRangeProperty(field.Config) // dir/config.yaml
if len(rangeSections) > 0 { // only get the first one
rangeSection := rangeSections[0]
desc, _, count := gen.ParseRangeSection(rangeSection)
desc, _, count, countTag := gen.ParseRangeSection(rangeSection)
refer.Count = count
refer.CountTag = countTag
path := fileUtils.ConvertReferRangeToPath(desc, currPath)
refer.File = GetRelatedPathWithResDir(path)
......@@ -289,8 +291,8 @@ func (s *DefService) saveFieldToDB(field *model.ZdField, def model.ZdDef, currPa
rangeSections := gen.ParseRangeProperty(field.Range)
if len(rangeSections) > 0 {
rangeSection := rangeSections[0] // deal with yaml and text refer using range prop
desc, step, count := gen.ParseRangeSection(rangeSection) // dir/users.txt:R{3}
rangeSection := rangeSections[0] // deal with yaml and text refer using range prop
desc, step, count, countTag := gen.ParseRangeSection(rangeSection) // dir/users.txt:R{3}
if path.Ext(desc) == ".txt" || path.Ext(desc) == ".yaml" {
if path.Ext(desc) == ".txt" { // dir/users.txt:2
refer.Type = constant.ResTypeText
......@@ -305,6 +307,7 @@ func (s *DefService) saveFieldToDB(field *model.ZdField, def model.ZdDef, currPa
refer.Type = constant.ResTypeYaml
refer.Count = count
refer.CountTag = countTag
}
path := fileUtils.ConvertReferRangeToPath(desc, currPath)
......
......@@ -230,9 +230,10 @@ func (s *InstancesService) saveItemToDB(item *model.ZdInstancesItem, instances m
rangeSections := gen.ParseRangeProperty(item.Use)
if len(rangeSections) > 0 { // only get the first one
rangeSection := rangeSections[0]
desc, _, count := gen.ParseRangeSection(rangeSection) // medium{2}
desc, _, count, countTag := gen.ParseRangeSection(rangeSection) // medium{2}
refer.ColName = desc
refer.Count = count
refer.CountTag = countTag
}
path := fileUtils.ConvertReferRangeToPath(item.From, currPath)
......@@ -245,8 +246,9 @@ func (s *InstancesService) saveItemToDB(item *model.ZdInstancesItem, instances m
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)
desc, _, count, countTag := gen.ParseRangeSection(rangeSection)
refer.Count = count
refer.CountTag = countTag
path := fileUtils.ConvertReferRangeToPath(desc, currPath)
refer.File = GetRelatedPathWithResDir(path)
......@@ -257,7 +259,7 @@ func (s *InstancesService) saveItemToDB(item *model.ZdInstancesItem, instances m
rangeSections := gen.ParseRangeProperty(item.Range)
if len(rangeSections) > 0 { // only get the first one
rangeSection := rangeSections[0]
desc, step, count := gen.ParseRangeSection(rangeSection) // dir/users.txt:R{3}
desc, step, count, countTag := gen.ParseRangeSection(rangeSection) // dir/users.txt:R{3}
if path.Ext(desc) == ".txt" || path.Ext(desc) == ".yaml" {
if path.Ext(desc) == ".txt" { // dir/users.txt:2
refer.Type = constant.ResTypeText
......@@ -272,6 +274,7 @@ func (s *InstancesService) saveItemToDB(item *model.ZdInstancesItem, instances m
refer.Type = constant.ResTypeYaml
refer.Count = count
refer.CountTag = countTag
}
path := fileUtils.ConvertReferRangeToPath(desc, currPath)
......
title: range
desc: 描述
version: 1.0
fields:
- field: field_length
range: 1-3{2!}
length: 3
leftpad: 0
prefix: "+"
postfix: "-"
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册