Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
zendata
提交
0d494d7b
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 搜索 >>
提交
0d494d7b
编写于
7月 14, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
new features for 1.1
上级
853b87c2
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
72 addition
and
57 deletion
+72
-57
src/action/generator.go
src/action/generator.go
+1
-4
src/action/sql.go
src/action/sql.go
+0
-5
src/gen/definition.go
src/gen/definition.go
+22
-17
src/gen/generator.go
src/gen/generator.go
+18
-8
src/gen/res.go
src/gen/res.go
+16
-12
src/utils/const/const.go
src/utils/const/const.go
+0
-5
src/utils/file/file.go
src/utils/file/file.go
+8
-1
src/utils/vari/var.go
src/utils/vari/var.go
+6
-2
src/zd.go
src/zd.go
+1
-3
未找到文件。
src/action/generator.go
浏览文件 @
0d494d7b
...
...
@@ -10,8 +10,6 @@ import (
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"
"strings"
)
...
...
@@ -27,8 +25,7 @@ func Generate(defaultFile string, configFile string, total int, fieldsToExportSt
if
fieldsToExportStr
!=
""
{
fieldsToExport
=
strings
.
Split
(
fieldsToExportStr
,
","
)
}
abs
,
_
:=
filepath
.
Abs
(
filepath
.
Dir
(
configFile
))
vari
.
InputDir
=
abs
+
string
(
os
.
PathSeparator
)
constant
.
Total
=
total
rows
,
colTypes
:=
gen
.
GenerateForDefinition
(
defaultFile
,
configFile
,
&
fieldsToExport
,
total
)
...
...
src/action/sql.go
浏览文件 @
0d494d7b
...
...
@@ -5,19 +5,14 @@ import (
fileUtils
"github.com/easysoft/zendata/src/utils/file"
i118Utils
"github.com/easysoft/zendata/src/utils/i118"
logUtils
"github.com/easysoft/zendata/src/utils/log"
"github.com/easysoft/zendata/src/utils/vari"
"gopkg.in/yaml.v3"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"time"
)
func
ParseSql
(
file
string
,
out
string
)
{
startTime
:=
time
.
Now
()
.
Unix
()
abs
,
_
:=
filepath
.
Abs
(
filepath
.
Dir
(
file
))
vari
.
InputDir
=
abs
+
string
(
os
.
PathSeparator
)
statements
:=
getCreateStatement
(
file
)
for
tableName
,
statement
:=
range
statements
{
...
...
src/gen/definition.go
浏览文件 @
0d494d7b
...
...
@@ -10,10 +10,11 @@ import (
"strings"
)
func
Load
RootDef
(
defaultFile
,
yml
File
string
,
fieldsToExport
*
[]
string
)
model
.
DefData
{
func
Load
ConfigDef
(
defaultFile
,
config
File
string
,
fieldsToExport
*
[]
string
)
model
.
DefData
{
defaultDef
:=
model
.
DefData
{}
yml
Def
:=
model
.
DefData
{}
config
Def
:=
model
.
DefData
{}
// load defaultDef
if
defaultFile
!=
""
{
defaultContent
,
err
:=
ioutil
.
ReadFile
(
defaultFile
)
defaultContent
=
ReplaceSpecialChars
(
defaultContent
)
...
...
@@ -28,43 +29,46 @@ func LoadRootDef(defaultFile, ymlFile string, fieldsToExport *[]string) model.De
}
}
yamlContent
,
err
:=
ioutil
.
ReadFile
(
ymlFile
)
// load configDef
yamlContent
,
err
:=
ioutil
.
ReadFile
(
configFile
)
yamlContent
=
ReplaceSpecialChars
(
yamlContent
)
if
err
!=
nil
{
logUtils
.
Screen
(
i118Utils
.
I118Prt
.
Sprintf
(
"fail_to_read_file"
,
yml
File
))
return
yml
Def
logUtils
.
Screen
(
i118Utils
.
I118Prt
.
Sprintf
(
"fail_to_read_file"
,
config
File
))
return
config
Def
}
err
=
yaml
.
Unmarshal
(
yamlContent
,
&
yml
Def
)
err
=
yaml
.
Unmarshal
(
yamlContent
,
&
config
Def
)
if
err
!=
nil
{
logUtils
.
Screen
(
i118Utils
.
I118Prt
.
Sprintf
(
"fail_to_parse_file"
,
yml
File
))
return
yml
Def
logUtils
.
Screen
(
i118Utils
.
I118Prt
.
Sprintf
(
"fail_to_parse_file"
,
config
File
))
return
config
Def
}
// use all fields as default
if
len
(
*
fieldsToExport
)
==
0
{
for
_
,
field
:=
range
yml
Def
.
Fields
{
for
_
,
field
:=
range
config
Def
.
Fields
{
*
fieldsToExport
=
append
(
*
fieldsToExport
,
field
.
Field
)
}
}
MergerDefine
(
&
defaultDef
,
&
yml
Def
)
MergerDefine
(
&
defaultDef
,
&
config
Def
)
return
defaultDef
}
func
MergerDefine
(
defaultDef
,
yml
Def
*
model
.
DefData
)
{
func
MergerDefine
(
defaultDef
,
config
Def
*
model
.
DefData
)
{
defaultFieldMap
:=
map
[
string
]
*
model
.
DefField
{}
yml
FieldMap
:=
map
[
string
]
*
model
.
DefField
{}
config
FieldMap
:=
map
[
string
]
*
model
.
DefField
{}
sortedKeys
:=
make
([]
string
,
0
)
for
i
:=
range
defaultDef
.
Fields
{
CreatePathToFieldMap
(
&
defaultDef
.
Fields
[
i
],
defaultFieldMap
,
nil
)
}
for
i
:=
range
yml
Def
.
Fields
{
CreatePathToFieldMap
(
&
ymlDef
.
Fields
[
i
],
yml
FieldMap
,
&
sortedKeys
)
for
i
:=
range
config
Def
.
Fields
{
CreatePathToFieldMap
(
&
configDef
.
Fields
[
i
],
config
FieldMap
,
&
sortedKeys
)
}
for
path
,
field
:=
range
ymlFieldMap
{
// overwrite
for
path
,
field
:=
range
configFieldMap
{
parent
,
exist
:=
defaultFieldMap
[
path
]
if
exist
{
CopyField
(
*
field
,
parent
)
...
...
@@ -72,9 +76,10 @@ func MergerDefine(defaultDef, ymlDef *model.DefData) {
}
}
// append
for
_
,
key
:=
range
sortedKeys
{
field
:=
yml
FieldMap
[
key
]
if
strings
.
Index
(
field
.
Path
,
"~~"
)
>
-
1
{
continue
}
//
only for
top fields
field
:=
config
FieldMap
[
key
]
if
strings
.
Index
(
field
.
Path
,
"~~"
)
>
-
1
{
continue
}
//
ignore no-
top fields
_
,
exist
:=
defaultFieldMap
[
field
.
Path
]
if
!
exist
{
...
...
src/gen/generator.go
浏览文件 @
0d494d7b
...
...
@@ -4,27 +4,32 @@ import (
"fmt"
"github.com/easysoft/zendata/src/model"
constant
"github.com/easysoft/zendata/src/utils/const"
fileUtils
"github.com/easysoft/zendata/src/utils/file"
stringUtils
"github.com/easysoft/zendata/src/utils/string"
"github.com/easysoft/zendata/src/utils/vari"
"strconv"
"strings"
)
func
GenerateForDefinition
(
defaultFile
,
configFile
string
,
fieldsToExport
*
[]
string
,
total
int
)
([][]
string
,
[]
bool
)
{
constant
.
Def
=
LoadRootDef
(
defaultFile
,
configFile
,
fieldsToExport
)
constant
.
Res
=
LoadResDef
(
*
fieldsToExport
)
vari
.
DefaultDir
=
fileUtils
.
GetAbsDir
(
defaultFile
)
vari
.
ConfigDir
=
fileUtils
.
GetAbsDir
(
configFile
)
vari
.
Def
=
LoadConfigDef
(
defaultFile
,
configFile
,
fieldsToExport
)
vari
.
Res
=
LoadResDef
(
*
fieldsToExport
)
fieldNameToValues
:=
map
[
string
][]
string
{}
colTypes
:=
make
([]
bool
,
0
)
// 为每个field生成值列表
for
index
,
field
:=
range
constant
.
Def
.
Fields
{
for
index
,
field
:=
range
vari
.
Def
.
Fields
{
if
!
stringUtils
.
FindInArr
(
field
.
Field
,
*
fieldsToExport
)
{
continue
}
values
:=
GenerateForField
(
&
field
,
total
,
true
)
constant
.
Def
.
Fields
[
index
]
.
Precision
=
field
.
Precision
vari
.
Def
.
Fields
[
index
]
.
Precision
=
field
.
Precision
fieldNameToValues
[
field
.
Field
]
=
values
colTypes
=
append
(
colTypes
,
field
.
IsNumb
)
...
...
@@ -33,7 +38,7 @@ func GenerateForDefinition(defaultFile, configFile string, fieldsToExport *[]str
// 生成指定数量行的数据
rows
:=
make
([][]
string
,
0
)
for
i
:=
0
;
i
<
total
;
i
++
{
for
_
,
field
:=
range
constant
.
Def
.
Fields
{
for
_
,
field
:=
range
vari
.
Def
.
Fields
{
if
!
stringUtils
.
FindInArr
(
field
.
Field
,
*
fieldsToExport
)
{
continue
}
...
...
@@ -66,18 +71,23 @@ func GenerateForField(field *model.DefField, total int, withFix bool) []string {
// should be done by calling LoopSubFields func as below, so disable this line
//concat = field.Prefix + concat + field.Postfix
values
=
append
(
values
,
concat
)
}
values
=
LoopSubFields
(
field
,
values
,
total
,
true
)
}
else
if
field
.
From
!=
""
{
// refer to res
groupValues
:=
constant
.
Res
[
field
.
From
]
groupValues
:=
vari
.
Res
[
field
.
From
]
if
field
.
Use
!=
""
{
// refer to yaml
groups
:=
strings
.
Split
(
field
.
Use
,
","
)
for
_
,
group
:=
range
groups
{
values
=
append
(
values
,
groupValues
[
group
]
...
)
if
group
==
"all"
{
for
_
,
arr
:=
range
groupValues
{
// add all
values
=
append
(
values
,
arr
...
)
}
}
else
{
values
=
append
(
values
,
groupValues
[
group
]
...
)
}
}
}
else
{
// refer to excel
slct
:=
field
.
Select
...
...
src/gen/res.go
浏览文件 @
0d494d7b
...
...
@@ -12,18 +12,17 @@ import (
"gopkg.in/yaml.v3"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
func
LoadResDef
(
fieldsToExport
[]
string
)
map
[
string
]
map
[
string
][]
string
{
res
:=
map
[
string
]
map
[
string
][]
string
{}
for
_
,
field
:=
range
constant
.
Def
.
Fields
{
for
_
,
field
:=
range
vari
.
Def
.
Fields
{
if
!
stringUtils
.
FindInArr
(
field
.
Field
,
fieldsToExport
)
{
continue
}
loadResField
(
&
field
,
&
res
)
}
return
res
}
...
...
@@ -62,22 +61,27 @@ func getResProp(from string) (string, string) { // from resource
resType
=
"excel"
}
if
strings
.
Index
(
resFile
,
"system"
)
==
-
1
{
// no system resource
resPath
:=
vari
.
WorkDir
+
resFile
if
!
fileUtils
.
FileExist
(
resPath
)
{
// not in work dir
resPath
=
vari
.
InputDir
+
resFile
if
strings
.
Index
(
resFile
,
"system"
)
>
-
1
{
// system resource
resFile
=
vari
.
ExeDir
+
constant
.
ResDir
+
resFile
}
else
{
resPath
:=
resFile
if
!
filepath
.
IsAbs
(
resPath
)
{
if
!
fileUtils
.
FileExist
(
resPath
)
{
// not in input dir (same dir as yaml file in)
resPath
=
vari
.
ExeDir
+
resFile
resPath
=
vari
.
DefaultDir
+
resFile
if
!
fileUtils
.
FileExist
(
resPath
)
{
if
!
fileUtils
.
FileExist
(
resPath
)
{
// not in exe dir
resPath
=
vari
.
ConfigDir
+
resFile
if
!
fileUtils
.
FileExist
(
resPath
)
{
resPath
=
""
}
}
}
else
{
if
!
fileUtils
.
FileExist
(
resPath
)
{
resPath
=
""
}
}
resFile
=
resPath
}
else
{
// system resource
resFile
=
constant
.
ResDir
+
resFile
}
return
resFile
,
resType
...
...
src/utils/const/const.go
浏览文件 @
0d494d7b
...
...
@@ -2,7 +2,6 @@ package constant
import
(
"fmt"
"github.com/easysoft/zendata/src/model"
"os"
)
...
...
@@ -28,9 +27,6 @@ var (
Total
=
10
MaxNumb
=
100000
// max number in array
Def
=
model
.
DefData
{}
Res
=
map
[
string
]
map
[
string
][]
string
{}
FormatText
=
"text"
FormatJson
=
"json"
FormatXml
=
"xml"
...
...
@@ -44,7 +40,6 @@ var (
DefaultRoot
=
"./"
ResDir
=
"data/"
ResPath
=
ResDir
+
"system/buildin.yaml"
SqliteDriver
=
"sqlite3"
SqliteSource
=
"file:"
+
ResDir
+
".cache/.data.db"
...
...
src/utils/file/file.go
浏览文件 @
0d494d7b
...
...
@@ -163,7 +163,7 @@ func GetWorkDir() string { // where run command in
}
func
GetLogDir
()
string
{
path
:=
vari
.
Work
Dir
+
constant
.
LogDir
path
:=
vari
.
Exe
Dir
+
constant
.
LogDir
dir
,
_
:=
ioutil
.
ReadDir
(
path
)
...
...
@@ -234,3 +234,10 @@ func CopyFile(src, dst string) (int64, error) {
nBytes
,
err
:=
io
.
Copy
(
destination
,
source
)
return
nBytes
,
err
}
func
GetAbsDir
(
path
string
)
string
{
abs
,
_
:=
filepath
.
Abs
(
filepath
.
Dir
(
path
))
abs
=
UpdateDir
(
abs
)
return
abs
}
src/utils/vari/var.go
浏览文件 @
0d494d7b
...
...
@@ -11,8 +11,6 @@ var (
RunMode
constant
.
RunMode
ExeDir
string
WorkDir
string
InputDir
string
LogDir
string
ScreenWidth
int
...
...
@@ -32,4 +30,10 @@ var (
JsonResp
string
=
"[]"
Ip
string
Port
int
Def
=
model
.
DefData
{}
Res
=
map
[
string
]
map
[
string
][]
string
{}
DefaultDir
string
ConfigDir
string
)
src/zd.go
浏览文件 @
0d494d7b
...
...
@@ -133,16 +133,14 @@ func main() {
func
toGen
()
{
if
vari
.
RunMode
==
constant
.
RunModeServer
{
vari
.
ExeDir
=
fileUtils
.
GetExeDir
()
vari
.
WorkDir
=
fileUtils
.
GetWorkDir
()
StartServer
()
}
else
if
vari
.
RunMode
==
constant
.
RunModeParse
{
action
.
ParseSql
(
input
,
output
)
}
else
if
vari
.
RunMode
==
constant
.
RunModeGen
{
vari
.
ExeDir
=
fileUtils
.
GetExeDir
()
vari
.
WorkDir
=
fileUtils
.
GetWorkDir
()
if
root
!=
""
{
vari
.
Work
Dir
=
root
vari
.
Exe
Dir
=
root
}
if
vari
.
HeadSep
!=
""
{
vari
.
WithHead
=
true
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录