Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
zendata
提交
7b95dc44
Z
zendata
项目概览
LinuxSuRen
/
zendata
与 Fork 源项目一致
Fork自
易企天创 / zendata
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Z
zendata
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
7b95dc44
编写于
6月 04, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support literal and interval field definition
上级
3042ed3a
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
211 addition
and
82 deletion
+211
-82
demo/roll.yaml
demo/roll.yaml
+14
-0
demo/test.yaml
demo/test.yaml
+14
-5
src/gen/charVal.go
src/gen/charVal.go
+14
-11
src/gen/definition.go
src/gen/definition.go
+21
-1
src/gen/floatVal.go
src/gen/floatVal.go
+15
-11
src/gen/intVal.go
src/gen/intVal.go
+14
-13
src/gen/list.go
src/gen/list.go
+111
-37
src/utils/const/const.go
src/utils/const/const.go
+3
-0
test/script/_debug.php
test/script/_debug.php
+5
-4
未找到文件。
demo/roll.yaml
0 → 100644
浏览文件 @
7b95dc44
title
:
test
desc
:
This is a test file.
author
:
zentao
version
:
1.0
fields
:
-
field
:
objectype
range
:
[
bug
,
task
]
:2{3},story{2}
-
field
:
objectid
range
:
[
1-9
]
:R{2},[a,b1,c]:R{2}
-
field
:
action
range
:
[
create
,
resolve
,
close
]{
10
}
,
[
create
,
finish
,
close
]{
10
}
\ No newline at end of file
demo/test.yaml
浏览文件 @
7b95dc44
...
...
@@ -40,21 +40,30 @@ fields:
expect
:
青岛、济南 ...
-
field
:
field4
node
:
嵌套字段
fields
:
-
field
:
field
1
.1
-
field
:
field
4
.1
type
:
list
range
:
1-9
postfix
:
"
.
"
-
field
:
field
1
.2
-
field
:
field
4
.2
prefix
:
'
['
postfix
:
'
]'
loop
:
2
loopfix
:
"
,"
fields
:
-
field
:
field
1
.2.1
-
field
:
field
4
.2.1
type
:
list
range
:
X-Z
-
field
:
field
1
.2.2
-
field
:
field
4
.2.2
type
:
list
range
:
1-9
loop
:
2
\ No newline at end of file
loop
:
2
-
field
:
field5
note
:
滚动字段
range
:
abc*5,123,456
loop
:
3
loopfix
:
"
,"
prefix
:
"
'"
postfix
:
"
'"
src/gen/charVal.go
浏览文件 @
7b95dc44
...
...
@@ -5,21 +5,21 @@ import (
"math/rand"
)
func
GenerateByteItems
(
start
byte
,
end
byte
,
step
interface
{},
rand
bool
)
[]
interface
{}
{
func
GenerateByteItems
(
start
byte
,
end
byte
,
step
interface
{},
rand
bool
,
limit
int
)
[]
interface
{}
{
if
!
rand
{
return
GenerateByteItemsByStep
(
start
,
end
,
step
.
(
int
))
return
GenerateByteItemsByStep
(
start
,
end
,
step
.
(
int
)
,
limit
)
}
else
{
return
GenerateByteItemsRand
(
start
,
end
,
step
.
(
int
))
return
GenerateByteItemsRand
(
start
,
end
,
step
.
(
int
)
,
limit
)
}
}
func
GenerateByteItemsByStep
(
start
byte
,
end
byte
,
step
int
)
[]
interface
{}
{
func
GenerateByteItemsByStep
(
start
byte
,
end
byte
,
step
int
,
limit
int
)
[]
interface
{}
{
arr
:=
make
([]
interface
{},
0
)
count
:=
constant
.
MaxNumb
for
i
:=
0
;
i
<
constant
.
MaxNumb
;
{
val
:=
start
+
byte
(
int
(
i
)
*
step
)
if
val
>
end
{
if
val
>
end
||
i
>
limit
{
break
}
...
...
@@ -31,16 +31,19 @@ func GenerateByteItemsByStep(start byte, end byte, step int) []interface{} {
return
arr
}
func
GenerateByteItemsRand
(
start
byte
,
end
byte
,
step
int
)
[]
interface
{}
{
func
GenerateByteItemsRand
(
start
byte
,
end
byte
,
step
int
,
limit
int
)
[]
interface
{}
{
arr
:=
make
([]
interface
{},
0
)
genCount
:=
int
(
end
-
start
)
/
step
+
1
if
genCount
>
constant
.
MaxNumb
{
genCount
=
constant
.
MaxNumb
count
:=
int
(
end
-
start
)
/
step
+
1
if
count
>
limit
{
count
=
limit
}
if
count
>
constant
.
MaxNumb
{
count
=
constant
.
MaxNumb
}
for
i
:=
0
;
i
<
genC
ount
;
{
ran
:=
rand
.
Intn
(
genC
ount
)
for
i
:=
0
;
i
<
c
ount
;
{
ran
:=
rand
.
Intn
(
c
ount
)
val
:=
start
+
byte
(
ran
)
arr
=
append
(
arr
,
val
)
...
...
src/gen/definition.go
浏览文件 @
7b95dc44
...
...
@@ -2,6 +2,7 @@ package gen
import
(
"github.com/easysoft/zendata/src/model"
constant
"github.com/easysoft/zendata/src/utils/const"
i118Utils
"github.com/easysoft/zendata/src/utils/i118"
logUtils
"github.com/easysoft/zendata/src/utils/log"
"gopkg.in/yaml.v3"
...
...
@@ -15,6 +16,7 @@ func LoadRootDef(defaultFile, ymlFile string, fieldsToExport *[]string) model.De
if
defaultFile
!=
""
{
defaultContent
,
err
:=
ioutil
.
ReadFile
(
defaultFile
)
defaultContent
=
replaceSpecialChars
(
defaultContent
)
if
err
!=
nil
{
logUtils
.
Screen
(
i118Utils
.
I118Prt
.
Sprintf
(
"fail_to_read_file"
,
defaultFile
))
return
defaultDef
...
...
@@ -27,13 +29,14 @@ func LoadRootDef(defaultFile, ymlFile string, fieldsToExport *[]string) model.De
}
yamlContent
,
err
:=
ioutil
.
ReadFile
(
ymlFile
)
yamlContent
=
replaceSpecialChars
(
yamlContent
)
if
err
!=
nil
{
logUtils
.
Screen
(
i118Utils
.
I118Prt
.
Sprintf
(
"fail_to_read_file"
,
ymlFile
))
return
ymlDef
}
err
=
yaml
.
Unmarshal
(
yamlContent
,
&
ymlDef
)
if
err
!=
nil
{
logUtils
.
Screen
(
i118Utils
.
I118Prt
.
Sprintf
(
"fail_to_
read
_file"
,
ymlFile
))
logUtils
.
Screen
(
i118Utils
.
I118Prt
.
Sprintf
(
"fail_to_
parse
_file"
,
ymlFile
))
return
ymlDef
}
...
...
@@ -142,3 +145,20 @@ func CopyField(child model.DefField, parent *model.DefField) {
(
*
parent
)
.
Precision
=
child
.
Precision
}
}
func
replaceSpecialChars
(
bytes
[]
byte
)
[]
byte
{
str
:=
string
(
bytes
)
ret
:=
""
for
_
,
line
:=
range
strings
.
Split
(
str
,
"
\n
"
)
{
if
strings
.
Index
(
strings
.
TrimSpace
(
line
),
"range"
)
==
0
{
line
=
strings
.
ReplaceAll
(
line
,
"["
,
string
(
constant
.
LeftChar
))
line
=
strings
.
ReplaceAll
(
line
,
"]"
,
string
(
constant
.
RightChar
))
}
ret
+=
line
+
"
\n
"
}
return
[]
byte
(
ret
)
}
src/gen/floatVal.go
浏览文件 @
7b95dc44
...
...
@@ -7,21 +7,21 @@ import (
"strings"
)
func
GenerateFloatItems
(
start
float64
,
end
float64
,
step
interface
{},
rand
bool
)
[]
interface
{}
{
func
GenerateFloatItems
(
start
float64
,
end
float64
,
step
interface
{},
rand
bool
,
limit
int
)
[]
interface
{}
{
if
!
rand
{
return
GenerateFloatItemsByStep
(
start
,
end
,
step
.
(
float64
))
return
GenerateFloatItemsByStep
(
start
,
end
,
step
.
(
float64
)
,
limit
)
}
else
{
return
GenerateFloatItemsRand
(
start
,
end
,
step
.
(
float64
))
return
GenerateFloatItemsRand
(
start
,
end
,
step
.
(
float64
)
,
limit
)
}
}
func
GenerateFloatItemsByStep
(
start
float64
,
end
float64
,
step
interface
{})
[]
interface
{}
{
func
GenerateFloatItemsByStep
(
start
float64
,
end
float64
,
step
interface
{}
,
limit
int
)
[]
interface
{}
{
arr
:=
make
([]
interface
{},
0
)
for
i
:=
0
;
i
<
constant
.
MaxNumb
;
{
gap
:=
float64
(
i
)
*
step
.
(
float64
)
val
:=
start
+
gap
if
val
>
end
{
if
val
>
end
||
i
>
limit
{
break
}
...
...
@@ -32,15 +32,19 @@ func GenerateFloatItemsByStep(start float64, end float64, step interface{}) []in
return
arr
}
func
GenerateFloatItemsRand
(
start
float64
,
end
float64
,
step
float64
)
[]
interface
{}
{
func
GenerateFloatItemsRand
(
start
float64
,
end
float64
,
step
float64
,
limit
int
)
[]
interface
{}
{
arr
:=
make
([]
interface
{},
0
)
genC
ount
:=
(
end
-
start
)
/
step
if
genCount
>
float64
(
constant
.
MaxNumb
)
{
genCount
=
float64
(
constant
.
MaxNumb
)
c
ount
:=
(
end
-
start
)
/
step
if
count
>
float64
(
limit
)
{
count
=
float64
(
limit
)
}
for
i
:=
float64
(
0
);
i
<
genCount
;
{
val
:=
start
+
float64
(
rand
.
Int63n
(
int64
(
genCount
)))
*
step
if
count
>
float64
(
constant
.
MaxNumb
)
{
count
=
float64
(
constant
.
MaxNumb
)
}
for
i
:=
float64
(
0
);
i
<
count
;
{
val
:=
start
+
float64
(
rand
.
Int63n
(
int64
(
count
)))
*
step
arr
=
append
(
arr
,
val
)
i
++
...
...
src/gen/intVal.go
浏览文件 @
7b95dc44
...
...
@@ -5,42 +5,43 @@ import (
"math/rand"
)
func
GenerateIntItems
(
start
int64
,
end
int64
,
step
interface
{},
rand
bool
)
[]
interface
{}
{
func
GenerateIntItems
(
start
int64
,
end
int64
,
step
interface
{},
rand
bool
,
limit
int
)
[]
interface
{}
{
if
!
rand
{
return
GenerateIntItemsByStep
(
start
,
end
,
step
.
(
int
))
return
GenerateIntItemsByStep
(
start
,
end
,
step
.
(
int
)
,
limit
)
}
else
{
return
GenerateIntItemsRand
(
start
,
end
,
step
.
(
int
))
return
GenerateIntItemsRand
(
start
,
end
,
step
.
(
int
)
,
limit
)
}
}
func
GenerateIntItemsByStep
(
start
int64
,
end
int64
,
step
int
)
[]
interface
{}
{
func
GenerateIntItemsByStep
(
start
int64
,
end
int64
,
step
int
,
limit
int
)
[]
interface
{}
{
arr
:=
make
([]
interface
{},
0
)
count
:=
0
for
i
:=
0
;
i
<
constant
.
MaxNumb
;
{
val
:=
start
+
int64
(
i
*
step
)
if
val
>
end
{
if
val
>
end
||
i
>
limit
{
break
}
arr
=
append
(
arr
,
val
)
count
++
i
++
}
return
arr
}
func
GenerateIntItemsRand
(
start
int64
,
end
int64
,
step
int
)
[]
interface
{}
{
func
GenerateIntItemsRand
(
start
int64
,
end
int64
,
step
int
,
limit
int
)
[]
interface
{}
{
arr
:=
make
([]
interface
{},
0
)
genCount
:=
(
end
-
start
)
/
int64
(
step
)
+
1
if
genCount
>
int64
(
constant
.
MaxNumb
)
{
genCount
=
int64
(
constant
.
MaxNumb
)
count
:=
(
end
-
start
)
/
int64
(
step
)
+
1
if
count
>
int64
(
limit
)
{
count
=
int64
(
limit
)
}
if
count
>
int64
(
constant
.
MaxNumb
)
{
count
=
int64
(
constant
.
MaxNumb
)
}
for
i
:=
int64
(
0
);
i
<
genC
ount
;
{
val
:=
start
+
int64
(
rand
.
Int63n
(
genCount
)
)
for
i
:=
int64
(
0
);
i
<
c
ount
;
{
val
:=
start
+
rand
.
Int63n
(
count
)
arr
=
append
(
arr
,
val
)
i
++
...
...
src/gen/list.go
浏览文件 @
7b95dc44
package
gen
import
(
"fmt"
"github.com/easysoft/zendata/src/model"
constant
"github.com/easysoft/zendata/src/utils/const"
"regexp"
"strconv"
"strings"
)
...
...
@@ -34,54 +36,31 @@ func GenerateFieldValues(field *model.DefField, fieldValue *model.FieldValue) {
}
else
{
GenerateFieldValuesFromList
(
field
,
fieldValue
)
}
//else if strings.Index(field.Range, ".xlsx") > -1 {
// GenerateFieldValuesFromExcel(field, fieldValue)
//}
}
func
GenerateFieldValuesFromList
(
field
*
model
.
DefField
,
fieldValue
*
model
.
FieldValue
)
{
//rang := strings.TrimSpace(field.Range)
rang
:=
field
.
Range
rangeItems
:=
strings
.
Split
(
rang
,
","
)
rangeItems
:=
ParseRange
(
rang
)
index
:=
0
for
_
,
i
tem
:=
range
rangeItems
{
for
_
,
rangeI
tem
:=
range
rangeItems
{
if
index
>=
constant
.
MaxNumb
{
break
}
if
item
==
""
{
continue
}
sectionArr
:=
strings
.
Split
(
item
,
":"
)
if
len
(
sectionArr
)
==
0
{
continue
}
stepStr
:=
"1"
if
len
(
sectionArr
)
==
2
{
stepStr
=
sectionArr
[
1
]
}
if
rangeItem
==
""
{
continue
}
elemArr
:=
strings
.
Split
(
sectionArr
[
0
],
"-"
)
startStr
:=
elemArr
[
0
]
endStr
:=
startStr
if
len
(
elemArr
)
>
1
{
endStr
=
elemArr
[
1
]
}
entry
,
stepStr
,
limit
:=
ParseRangeItem
(
rangeItem
)
typ
,
desc
:=
ParseEntry
(
entry
)
items
:=
make
([]
interface
{},
0
)
dataType
,
step
,
precision
,
rand
:=
CheckRangeType
(
startStr
,
endStr
,
stepStr
)
if
dataType
==
"int"
{
startInt
,
_
:=
strconv
.
ParseInt
(
startStr
,
0
,
64
)
endInt
,
_
:=
strconv
.
ParseInt
(
endStr
,
0
,
64
)
items
=
GenerateIntItems
(
startInt
,
endInt
,
step
,
rand
)
}
else
if
dataType
==
"float"
{
startFloat
,
_
:=
strconv
.
ParseFloat
(
startStr
,
64
)
endFloat
,
_
:=
strconv
.
ParseFloat
(
endStr
,
64
)
field
.
Precision
=
precision
items
=
GenerateFloatItems
(
startFloat
,
endFloat
,
step
.
(
float64
),
rand
)
}
else
if
dataType
==
"char"
{
items
=
GenerateByteItems
(
byte
(
startStr
[
0
]),
byte
(
endStr
[
0
]),
step
,
rand
)
}
else
if
dataType
==
"string"
{
items
=
append
(
items
,
startStr
)
if
startStr
!=
endStr
{
items
=
append
(
items
,
endStr
)
}
if
typ
==
"literal"
{
}
else
if
typ
==
"interval"
{
elemArr
:=
strings
.
Split
(
desc
,
"-"
)
startStr
:=
elemArr
[
0
]
endStr
:=
startStr
if
len
(
elemArr
)
>
1
{
endStr
=
elemArr
[
1
]
}
items
=
GenerateValuesFromInterval
(
field
,
startStr
,
endStr
,
stepStr
,
limit
)
}
fieldValue
.
Values
=
append
(
fieldValue
.
Values
,
items
...
)
...
...
@@ -145,4 +124,99 @@ func CheckRangeType(startStr string, endStr string, stepStr string) (string, int
}
return
"string"
,
1
,
0
,
false
}
func
ParseRange
(
rang
string
)
[]
string
{
items
:=
make
([]
string
,
0
)
tagOpen
:=
false
temp
:=
""
for
i
:=
0
;
i
<
len
(
rang
);
i
++
{
c
:=
rang
[
i
]
if
int32
(
c
)
==
constant
.
RightChar
{
tagOpen
=
false
}
else
if
int32
(
c
)
==
constant
.
LeftChar
{
tagOpen
=
true
}
if
i
==
len
(
rang
)
-
1
{
temp
+=
fmt
.
Sprintf
(
"%c"
,
c
)
items
=
append
(
items
,
temp
)
}
else
if
!
tagOpen
&&
c
==
','
{
items
=
append
(
items
,
temp
)
temp
=
""
tagOpen
=
false
}
else
{
temp
+=
fmt
.
Sprintf
(
"%c"
,
c
)
}
}
return
items
}
func
ParseRangeItem
(
item
string
)
(
string
,
string
,
int
)
{
entry
:=
""
step
:=
"1"
limit
:=
-
1
regx
:=
regexp
.
MustCompile
(
`\{(.*)\}`
)
arr
:=
regx
.
FindStringSubmatch
(
item
)
if
len
(
arr
)
==
2
{
limit
,
_
=
strconv
.
Atoi
(
arr
[
1
])
}
item
=
regx
.
ReplaceAllString
(
item
,
""
)
sectionArr
:=
strings
.
Split
(
item
,
":"
)
entry
=
sectionArr
[
0
]
if
len
(
sectionArr
)
==
2
{
step
=
sectionArr
[
1
]
}
return
entry
,
step
,
limit
}
func
GenerateValuesFromInterval
(
field
*
model
.
DefField
,
startStr
string
,
endStr
string
,
stepStr
string
,
limit
int
)
[]
interface
{}
{
items
:=
make
([]
interface
{},
0
)
dataType
,
step
,
precision
,
rand
:=
CheckRangeType
(
startStr
,
endStr
,
stepStr
)
if
dataType
==
"int"
{
startInt
,
_
:=
strconv
.
ParseInt
(
startStr
,
0
,
64
)
endInt
,
_
:=
strconv
.
ParseInt
(
endStr
,
0
,
64
)
items
=
GenerateIntItems
(
startInt
,
endInt
,
step
,
rand
,
limit
)
}
else
if
dataType
==
"float"
{
startFloat
,
_
:=
strconv
.
ParseFloat
(
startStr
,
64
)
endFloat
,
_
:=
strconv
.
ParseFloat
(
endStr
,
64
)
field
.
Precision
=
precision
items
=
GenerateFloatItems
(
startFloat
,
endFloat
,
step
.
(
float64
),
rand
,
limit
)
}
else
if
dataType
==
"char"
{
items
=
GenerateByteItems
(
byte
(
startStr
[
0
]),
byte
(
endStr
[
0
]),
step
,
rand
,
limit
)
}
else
if
dataType
==
"string"
{
items
=
append
(
items
,
startStr
)
if
startStr
!=
endStr
{
items
=
append
(
items
,
endStr
)
}
}
return
items
}
func
ParseEntry
(
str
string
)
(
string
,
string
)
{
typ
:=
""
desc
:=
""
str
=
strings
.
TrimSpace
(
str
)
if
int32
(
str
[
0
])
==
constant
.
LeftChar
{
typ
=
"literal"
desc
=
strings
.
ReplaceAll
(
str
,
string
(
constant
.
LeftChar
),
""
)
desc
=
strings
.
ReplaceAll
(
desc
,
string
(
constant
.
RightChar
),
""
)
}
else
{
typ
=
"interval"
desc
=
str
}
return
typ
,
desc
}
\ No newline at end of file
src/utils/const/const.go
浏览文件 @
7b95dc44
...
...
@@ -31,6 +31,9 @@ var (
Def
=
model
.
DefData
{}
Res
=
map
[
string
]
map
[
string
][]
string
{}
LeftChar
=
'('
RightChar
=
')'
ResDir
=
"data/"
ResPath
=
ResDir
+
"system/buildin.yaml"
...
...
test/script/_debug.php
浏览文件 @
7b95dc44
#!/usr/bin/env php
<?php
$xml
=
simplexml_load_file
(
'../test/output/output.xml'
);
$val
=
$xml
->
table
->
row
->
col
[
0
];
print
(
">>
$val
\n
"
);
\ No newline at end of file
if
(
!
function_exists
(
'simplexml_load_file'
))
{
$xml
=
simplexml_load_file
(
'../test/output/output.xml'
);
$val
=
$xml
->
table
->
row
->
col
[
0
];
print
(
">>
$val
\n
"
);
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录