Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zendata
提交
55997042
Z
zendata
项目概览
易企天创
/
zendata
9 个月 前同步成功
通知
17
Star
2
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Z
zendata
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
55997042
编写于
5月 25, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
exec params
上级
b3eacc6e
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
64 addition
and
63 deletion
+64
-63
data/system/address/v1.xlsx
data/system/address/v1.xlsx
+0
-0
demo/output.txt
demo/output.txt
+14
-14
demo/test.yaml
demo/test.yaml
+1
-5
res/doc/sample.txt
res/doc/sample.txt
+5
-2
res/doc/usage.txt
res/doc/usage.txt
+10
-10
src/action/generator.go
src/action/generator.go
+5
-8
src/gen/excel.go
src/gen/excel.go
+7
-4
src/zd.go
src/zd.go
+22
-20
未找到文件。
data/system/address/v1.xlsx
浏览文件 @
55997042
无法预览此类型文件
demo/output.txt
浏览文件 @
55997042
192.168.0.1,
1
92.168.1.2,
192.168.2.3,
192.168.3.4,
192.168.4.5,
192.168.5.6,
192.168.6.7,
192.168.7.8,
192.168.8.9,
192.168.9.10,
1
92.168.10.11,
1
92.168.11.12,
1
92.168.12.13,
1
92.168.13.14,
01
1
2
23
34
45
56
67
78
89
910
1
011
1
112
1
213
1
314
demo/test.yaml
浏览文件 @
55997042
...
...
@@ -18,8 +18,4 @@ fields:
note
:
测试Excel数据
from
:
system.address.v1.city
select
:
name
where
:
state like '%山东%'
-
field
:
field4
note
:
测试Excel数据
range
:
a-z,0-9
\ No newline at end of file
where
:
state like '%山东%'
\ No newline at end of file
res/doc/sample.txt
浏览文件 @
55997042
$>ztf.exe set 根据系统提示,设置工具语言属性。
$>ztf.exe gen -d sample/test.yaml -c 15 -field field1 -o sample/output.txt -f text 执行数据生成命令。使用定义文件sample/test.yaml,生成15行数据,以text格式的输出到sample/output.txt文件中。
\ No newline at end of file
$>ztf.exe -s 根据系统提示,设置工具语言属性。
$>ztf.exe -y sample/test.yaml -c 15 -field field1 -o sample/output.txt -f text
执行数据生成命令。使用配置文件sample/test.yaml,生成15行数据,以text格式的输出到sample/output.txt文件中。
$>ztf.exe -d sample/common.yaml -y sample/test.yaml -c 15 -field field1 -o sample/output.txt -f text
执行数据生成命令。使用文件sample/test.yam覆盖默认配置sample/common.yaml中的内容。
\ No newline at end of file
res/doc/usage.txt
浏览文件 @
55997042
help -h 查看帮助信息。
set -s 设置工具语言属性。用户对当前目录需要有写权限。
gen 根据定义文件生成数据。
-d -def 指定定义文件
-c -count 指定生成数据的条数
-field 指定输入的字段,用逗号分隔
-o -out 指定输出文件
-f format 指定输出格式,支持text、json、xml和sql语句几种格式
-t -table 输出格式为table时,用于指定insert语句的表名
--verbose 增加此参数,显示详细调试信息。
-help -h 查看帮助信息。
-set -s 设置工具语言属性。用户对当前目录需要有写权限。
默认根据定义文件生成数据。
-d -def 指定定义文件
-c -count 指定生成数据的条数
-field 指定输入的字段,用逗号分隔
-o -out 指定输出文件
-f format 指定输出格式,支持text、json、xml和sql语句几种格式
-t -table 输出格式为table时,用于指定insert语句的表名
--verbose 增加此参数,显示详细调试信息。
为了方便在任意目录中执行%s命令,建议将其加入环境变量中,具体方法参照以下地址。
https://www.ztesting.net/book/ztf-doc/add-to-path-46.html
\ No newline at end of file
src/action/generator.go
浏览文件 @
55997042
...
...
@@ -9,22 +9,20 @@ import (
constant
"github.com/easysoft/zendata/src/utils/const"
i118Utils
"github.com/easysoft/zendata/src/utils/i118"
logUtils
"github.com/easysoft/zendata/src/utils/log"
stringUtils
"github.com/easysoft/zendata/src/utils/string"
"github.com/easysoft/zendata/src/utils/vari"
"os"
"path/filepath"
"strconv"
"strings"
"time"
)
func
Generate
(
def
File
string
,
total
int
,
fieldsToExportStr
string
,
out
string
,
format
string
,
table
string
)
{
func
Generate
(
def
lt
string
,
yml
string
,
total
int
,
fieldsToExportStr
string
,
out
string
,
format
string
,
table
string
)
{
startTime
:=
time
.
Now
()
.
Unix
()
vari
.
InputDir
=
filepath
.
Dir
(
defFile
)
+
string
(
os
.
PathSeparator
)
vari
.
InputDir
=
filepath
.
Dir
(
yml
)
+
string
(
os
.
PathSeparator
)
constant
.
Total
=
total
fieldsToExport
:=
strings
.
Split
(
fieldsToExportStr
,
","
)
rows
,
colTypes
:=
gen
.
GenerateForDefinition
(
defFile
,
fieldsToExport
,
total
)
rows
,
colTypes
:=
gen
.
GenerateForDefinition
(
yml
,
fieldsToExport
,
total
)
content
:=
Print
(
rows
,
format
,
table
,
colTypes
,
fieldsToExport
)
WriteToFile
(
out
,
content
)
...
...
@@ -34,7 +32,7 @@ func Generate(defFile string, total int, fieldsToExportStr string, out string, f
}
func
Print
(
rows
[][]
string
,
format
string
,
table
string
,
colTypes
[]
bool
,
fields
[]
string
)
string
{
width
:=
stringUtils
.
GetNumbWidth
(
len
(
rows
))
//
width := stringUtils.GetNumbWidth(len(rows))
content
:=
""
sql
:=
""
...
...
@@ -63,8 +61,7 @@ func Print(rows [][]string, format string, table string, colTypes []bool, fields
if
format
==
"text"
&&
i
<
len
(
rows
)
-
1
{
content
=
content
+
line
+
"
\n
"
}
idStr
:=
fmt
.
Sprintf
(
"%"
+
strconv
.
Itoa
(
width
)
+
"d"
,
i
+
1
)
logUtils
.
Screen
(
fmt
.
Sprintf
(
"%s: %s"
,
idStr
,
line
))
logUtils
.
Screen
(
fmt
.
Sprintf
(
"%s"
,
line
))
testData
.
Table
.
Rows
=
append
(
testData
.
Table
.
Rows
,
row
)
...
...
src/gen/excel.go
浏览文件 @
55997042
...
...
@@ -19,10 +19,11 @@ func GenerateFieldValuesFromExcel(path string, field *model.DefField) (map[strin
values
:=
map
[
string
][]
string
{}
idx
:=
strings
.
LastIndex
(
field
.
From
,
"."
)
arr
:=
strings
.
Split
(
field
.
From
,
"."
)
dbName
:=
arr
[
len
(
arr
)
-
2
]
tableName
:=
field
.
From
[
idx
+
1
:
]
arr
:=
strings
.
Split
(
field
.
From
,
"."
)
dbName
:=
arr
[
len
(
arr
)
-
3
]
+
"_"
+
arr
[
len
(
arr
)
-
2
]
list
:=
make
([]
string
,
0
)
selectCol
:=
""
ConvertExcelToSQLiteIfNeeded
(
dbName
,
path
)
...
...
@@ -249,9 +250,11 @@ func isExcelChanged(path string) bool {
if
changed
{
if
!
found
{
sqlStr
=
fmt
.
Sprintf
(
"INSERT INTO excel_change(name, changeTime) VALUES('%s', %d)"
,
path
,
fileChangeTime
)
sqlStr
=
fmt
.
Sprintf
(
"INSERT INTO %s(name, changeTime) VALUES('%s', %d)"
,
constant
.
SqliteTrackTable
,
path
,
fileChangeTime
)
}
else
{
sqlStr
=
fmt
.
Sprintf
(
"UPDATE excel_change SET changeTime = %d WHERE name = '%s'"
,
fileChangeTime
,
path
)
sqlStr
=
fmt
.
Sprintf
(
"UPDATE %s SET changeTime = %d WHERE name = '%s'"
,
constant
.
SqliteTrackTable
,
fileChangeTime
,
path
)
}
_
,
err
=
db
.
Exec
(
sqlStr
)
...
...
src/zd.go
浏览文件 @
55997042
...
...
@@ -9,11 +9,12 @@ import (
"github.com/fatih/color"
"os"
"os/signal"
"strings"
"syscall"
)
var
(
deflt
string
yml
string
count
int
fields
string
...
...
@@ -21,6 +22,10 @@ var (
output
string
table
=
"text"
format
=
"text"
viewRes
string
viewDetail
string
help
bool
flagSet
*
flag
.
FlagSet
...
...
@@ -37,6 +42,12 @@ func main() {
flagSet
=
flag
.
NewFlagSet
(
"zd"
,
flag
.
ContinueOnError
)
flagSet
.
StringVar
(
&
deflt
,
"d"
,
""
,
""
)
flagSet
.
StringVar
(
&
deflt
,
"deflt"
,
""
,
""
)
flagSet
.
StringVar
(
&
yml
,
"y"
,
""
,
""
)
flagSet
.
StringVar
(
&
yml
,
"yml"
,
""
,
""
)
flagSet
.
StringVar
(
&
input
,
"i"
,
""
,
""
)
flagSet
.
StringVar
(
&
input
,
"input"
,
""
,
""
)
...
...
@@ -54,14 +65,14 @@ func main() {
flagSet
.
StringVar
(
&
format
,
"f"
,
""
,
""
)
flagSet
.
StringVar
(
&
format
,
"format"
,
""
,
""
)
flagSet
.
StringVar
(
&
viewRes
,
"v"
,
""
,
""
)
flagSet
.
StringVar
(
&
viewDetail
,
"vv"
,
""
,
""
)
flagSet
.
BoolVar
(
&
vari
.
Verbose
,
"v"
,
false
,
""
)
flagSet
.
BoolVar
(
&
vari
.
Verbose
,
"verbose"
,
false
,
""
)
flagSet
.
BoolVar
(
&
help
,
"h"
,
false
,
""
)
flagSet
.
BoolVar
(
&
help
,
"help"
,
false
,
""
)
if
len
(
os
.
Args
)
==
1
{
os
.
Args
=
append
(
os
.
Args
,
"help"
)
os
.
Args
=
append
(
os
.
Args
,
"
-
help"
)
}
else
if
os
.
Args
[
1
][
0
:
1
]
==
"-"
{
args
:=
[]
string
{
os
.
Args
[
0
],
"gen"
}
args
=
append
(
args
,
os
.
Args
[
1
:
]
...
)
...
...
@@ -69,30 +80,21 @@ func main() {
}
switch
os
.
Args
[
1
]
{
case
"
set
"
,
"-set"
:
case
"
-s
"
,
"-set"
:
action
.
Set
()
case
"gen"
:
gen
(
os
.
Args
)
//case "upgrade":
// upgrade(os.Args)
default
:
case
"-h"
,
"-help"
:
logUtils
.
PrintUsage
()
default
:
gen
(
os
.
Args
)
}
}
//func upgrade(args []string) {
// if err := flagSet.Parse(args[2:]); err == nil {
// action.Upgrade()
// }
//}
func
gen
(
args
[]
string
)
{
if
err
:=
flagSet
.
Parse
(
args
[
2
:
]);
err
==
nil
{
if
strings
.
Index
(
strings
.
ToLower
(
input
),
".sql"
)
>
0
{
if
input
!=
""
{
action
.
ParseSql
(
input
,
output
)
}
else
{
action
.
Generate
(
input
,
count
,
fields
,
output
,
format
,
table
)
action
.
Generate
(
deflt
,
yml
,
count
,
fields
,
output
,
format
,
table
)
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录