Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zendata
提交
c614d12c
Z
zendata
项目概览
易企天创
/
zendata
11 个月 前同步成功
通知
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 搜索 >>
提交
c614d12c
编写于
5月 19, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
generate output
上级
ee2b50fb
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
184 addition
and
19 deletion
+184
-19
src/gen/generator.go
src/gen/generator.go
+8
-8
src/gen/res.go
src/gen/res.go
+165
-0
src/model/definition.go
src/model/definition.go
+7
-7
src/utils/const/const.go
src/utils/const/const.go
+4
-4
未找到文件。
src/gen/generator.go
浏览文件 @
c614d12c
...
...
@@ -10,21 +10,21 @@ import (
)
func
GenerateForDefinition
(
defFile
string
,
fieldsToExport
[]
string
,
total
int
)
([][]
string
,
[]
bool
)
{
constant
.
Root
Def
=
LoadRootDef
(
defFile
)
constant
.
Re
feredValues
=
LoadClsDef
(
defFile
,
fieldsToExport
)
constant
.
Def
=
LoadRootDef
(
defFile
)
constant
.
Re
s
=
LoadResDef
(
fieldsToExport
)
fieldNameToValues
:=
map
[
string
][]
string
{}
colTypes
:=
make
([]
bool
,
0
)
// 为每个field生成值列表
for
index
,
field
:=
range
constant
.
Root
Def
.
Fields
{
for
index
,
field
:=
range
constant
.
Def
.
Fields
{
if
!
stringUtils
.
FindInArr
(
field
.
Field
,
fieldsToExport
)
{
continue
}
values
:=
GenerateForField
(
&
field
,
total
)
constant
.
Root
Def
.
Fields
[
index
]
.
Precision
=
field
.
Precision
constant
.
Def
.
Fields
[
index
]
.
Precision
=
field
.
Precision
fieldNameToValues
[
field
.
Field
]
=
values
colTypes
=
append
(
colTypes
,
field
.
IsNumb
)
...
...
@@ -33,7 +33,7 @@ func GenerateForDefinition(defFile string, fieldsToExport []string, total int) (
// 生成指定数量行的数据
rows
:=
make
([][]
string
,
0
)
for
i
:=
0
;
i
<
total
;
i
++
{
for
_
,
field
:=
range
constant
.
Root
Def
.
Fields
{
for
_
,
field
:=
range
constant
.
Def
.
Fields
{
if
!
stringUtils
.
FindInArr
(
field
.
Field
,
fieldsToExport
)
{
continue
}
...
...
@@ -69,10 +69,10 @@ func GenerateForField(field *model.DefField, total int) []string {
}
values
=
LoopSubFields
(
field
,
values
,
total
)
}
else
if
field
.
From
!=
""
{
// refer
field
groupValues
:=
constant
.
Re
feredValue
s
[
field
.
From
]
}
else
if
field
.
From
!=
""
{
// refer
to res
groupValues
:=
constant
.
Res
[
field
.
From
]
if
field
.
Use
!=
""
{
// refer to
cls
if
field
.
Use
!=
""
{
// refer to
yaml
groups
:=
strings
.
Split
(
field
.
Use
,
","
)
for
_
,
group
:=
range
groups
{
values
=
append
(
values
,
groupValues
[
group
]
...
)
...
...
src/gen/
cl
s.go
→
src/gen/
re
s.go
浏览文件 @
c614d12c
...
...
@@ -14,33 +14,33 @@ import (
"strings"
)
func
Load
ClsDef
(
file
string
,
fieldsToExport
[]
string
)
map
[
string
]
map
[
string
][]
string
{
re
ferFieldValueMap
:=
map
[
string
]
map
[
string
][]
string
{}
func
Load
ResDef
(
fieldsToExport
[]
string
)
map
[
string
]
map
[
string
][]
string
{
re
s
:=
map
[
string
]
map
[
string
][]
string
{}
for
_
,
field
:=
range
constant
.
Root
Def
.
Fields
{
for
_
,
field
:=
range
constant
.
Def
.
Fields
{
if
!
stringUtils
.
FindInArr
(
field
.
Field
,
fieldsToExport
)
{
continue
}
load
ClsField
(
&
field
,
&
referFieldValueMap
)
load
ResField
(
&
field
,
&
res
)
}
return
re
ferFieldValueMap
return
re
s
}
func
load
ClsField
(
field
*
model
.
DefField
,
referFieldValueMap
*
map
[
string
]
map
[
string
][]
string
)
{
func
load
ResField
(
field
*
model
.
DefField
,
res
*
map
[
string
]
map
[
string
][]
string
)
{
if
len
(
field
.
Fields
)
>
0
{
for
_
,
child
:=
range
field
.
Fields
{
load
ClsField
(
&
child
,
referFieldValueMap
)
load
ResField
(
&
child
,
res
)
}
}
else
if
field
.
From
!=
""
{
re
ferFile
,
referType
:=
getRefer
Prop
(
field
.
From
)
values
,
_
:=
getRe
ferFieldValue
(
referFile
,
refer
Type
,
field
)
(
*
re
ferFieldValueMap
)[
field
.
From
]
=
values
re
sFile
,
resType
:=
getRes
Prop
(
field
.
From
)
values
,
_
:=
getRe
sValue
(
resFile
,
res
Type
,
field
)
(
*
re
s
)[
field
.
From
]
=
values
}
}
func
getRe
fer
Prop
(
from
string
)
(
string
,
string
)
{
re
fer
File
:=
""
re
fer
Type
:=
""
func
getRe
s
Prop
(
from
string
)
(
string
,
string
)
{
re
s
File
:=
""
re
s
Type
:=
""
sep
:=
string
(
os
.
PathSeparator
)
...
...
@@ -49,100 +49,108 @@ func getReferProp(from string) (string, string) {
left
:=
from
[
:
index
]
left
=
strings
.
ReplaceAll
(
left
,
"."
,
sep
)
re
fer
File
=
left
+
".yaml"
re
fer
Type
=
"yaml"
re
s
File
=
left
+
".yaml"
re
s
Type
=
"yaml"
}
else
{
// excel, system.address.china
index
=
strings
.
LastIndex
(
from
,
"."
)
left
:=
from
[
:
index
]
left
=
strings
.
ReplaceAll
(
left
,
"."
,
sep
)
re
fer
File
=
left
+
".xlsx"
re
fer
Type
=
"excel"
re
s
File
=
left
+
".xlsx"
re
s
Type
=
"excel"
}
if
strings
.
Index
(
re
fer
File
,
"system"
)
==
-
1
{
// no system cls
re
ferFile
=
vari
.
InputDir
+
refer
File
if
strings
.
Index
(
re
s
File
,
"system"
)
==
-
1
{
// no system cls
re
sFile
=
vari
.
InputDir
+
res
File
if
!
fileUtils
.
FileExist
(
re
fer
File
)
{
// not in input dir
re
ferFile
=
vari
.
ExeDir
+
refer
File
if
!
fileUtils
.
FileExist
(
re
s
File
)
{
// not in input dir
re
sFile
=
vari
.
ExeDir
+
res
File
if
!
fileUtils
.
FileExist
(
re
fer
File
)
{
// not in exe dir
re
fer
File
=
""
if
!
fileUtils
.
FileExist
(
re
s
File
)
{
// not in exe dir
re
s
File
=
""
}
}
}
else
{
re
ferFile
=
constant
.
ResDir
+
refer
File
re
sFile
=
constant
.
ResDir
+
res
File
}
return
re
ferFile
,
refer
Type
return
re
sFile
,
res
Type
}
func
getRe
ferFieldValue
(
referFile
string
,
refer
Type
string
,
field
*
model
.
DefField
)
(
map
[
string
][]
string
,
string
)
{
n
ame
:=
""
v
alues
:=
map
[
string
][]
string
{}
func
getRe
sValue
(
resFile
string
,
res
Type
string
,
field
*
model
.
DefField
)
(
map
[
string
][]
string
,
string
)
{
resN
ame
:=
""
groupedV
alues
:=
map
[
string
][]
string
{}
if
re
fer
Type
==
"yaml"
{
values
,
name
=
getReferFieldValueForYaml
(
refer
File
)
}
else
if
re
fer
Type
==
"excel"
{
values
,
name
=
getReferFieldValueForExcel
(
refer
File
,
field
)
if
re
s
Type
==
"yaml"
{
groupedValues
,
resName
=
getResForYaml
(
res
File
)
}
else
if
re
s
Type
==
"excel"
{
groupedValues
,
resName
=
getResForExcel
(
res
File
,
field
)
}
return
values
,
n
ame
return
groupedValues
,
resN
ame
}
func
getReferFieldValueForYaml
(
referFile
string
)
(
map
[
string
][]
string
,
string
)
{
name
:=
""
func
getResForExcel
(
resFile
string
,
field
*
model
.
DefField
)
(
map
[
string
][]
string
,
string
)
{
valueMap
,
resName
:=
GenerateFieldValuesFromExcel
(
resFile
,
field
)
return
valueMap
,
resName
}
func
getResForYaml
(
resFile
string
)
(
map
[
string
][]
string
,
string
)
{
resName
:=
""
valueMap
:=
map
[
string
][]
string
{}
ranges
:=
model
.
Cl
sRanges
{}
ranges
:=
model
.
Re
sRanges
{}
yamlContent
,
err
:=
ioutil
.
ReadFile
(
re
fer
File
)
yamlContent
,
err
:=
ioutil
.
ReadFile
(
re
s
File
)
if
err
!=
nil
{
logUtils
.
Screen
(
"fail to read "
+
re
fer
File
)
logUtils
.
Screen
(
"fail to read "
+
re
s
File
)
return
valueMap
,
""
}
err
=
yaml
.
Unmarshal
(
yamlContent
,
&
ranges
)
if
err
!=
nil
||
ranges
.
Ranges
==
nil
||
len
(
ranges
.
Ranges
)
==
0
{
// instances
logUtils
.
Screen
(
"not
ClsRanges "
+
referFile
+
", try to parse as Cl
sInsts"
)
logUtils
.
Screen
(
"not
ResRanges "
+
resFile
+
", try to parse as Re
sInsts"
)
insts
:=
model
.
Cl
sInsts
{}
insts
:=
model
.
Re
sInsts
{}
err
=
yaml
.
Unmarshal
(
yamlContent
,
&
insts
)
if
err
!=
nil
{
return
valueMap
,
""
}
else
{
valueMap
=
getRe
ferFieldValue
ForInstances
(
insts
)
valueMap
=
getRe
s
ForInstances
(
insts
)
}
n
ame
=
insts
.
Field
resN
ame
=
insts
.
Field
}
else
{
// ranges
valueMap
=
getRe
ferFieldValue
ForRanges
(
ranges
)
n
ame
=
ranges
.
Field
valueMap
=
getRe
s
ForRanges
(
ranges
)
resN
ame
=
ranges
.
Field
}
return
valueMap
,
n
ame
return
valueMap
,
resN
ame
}
func
getRe
ferFieldValueForRanges
(
ranges
model
.
Cl
sRanges
)
map
[
string
][]
string
{
values
:=
map
[
string
][]
string
{}
func
getRe
sForRanges
(
ranges
model
.
Re
sRanges
)
map
[
string
][]
string
{
groupedValue
:=
map
[
string
][]
string
{}
for
name
,
exp
:=
range
ranges
.
Ranges
{
// convert ranges
refer
to standard field
for
group
,
exp
:=
range
ranges
.
Ranges
{
// convert ranges
field
to standard field
tempField
:=
model
.
DefField
{
Field
:
ranges
.
Field
,
Range
:
exp
,
Type
:
"cls"
}
values
[
name
]
=
GenerateFieldItemsFromDefinition
(
&
tempField
)
groupedValue
[
group
]
=
GenerateFieldItemsFromDefinition
(
&
tempField
)
}
return
values
return
groupedValue
}
func
getRe
ferFieldValueForInstances
(
insts
model
.
Cl
sInsts
)
map
[
string
][]
string
{
values
:=
map
[
string
][]
string
{}
func
getRe
sForInstances
(
insts
model
.
Re
sInsts
)
map
[
string
][]
string
{
groupedValue
:=
map
[
string
][]
string
{}
for
_
,
inst
:=
range
insts
.
Instances
{
// convert ranges refer to standard field
group
:=
inst
.
Instance
// convert instant field to standard field
tempField
:=
model
.
DefField
{
Field
:
insts
.
Field
,
Type
:
"cls"
}
child
:=
model
.
DefField
{
Field
:
inst
.
Instance
}
...
...
@@ -150,14 +158,8 @@ func getReferFieldValueForInstances(insts model.ClsInsts) map[string][]string {
tempField
.
Fields
=
append
(
tempField
.
Fields
,
child
)
values
[
inst
.
Instance
]
=
GenerateForField
(
&
tempField
,
constant
.
Total
)
groupedValue
[
group
]
=
GenerateForField
(
&
tempField
,
constant
.
Total
)
}
return
values
}
func
getReferFieldValueForExcel
(
referFile
string
,
field
*
model
.
DefField
)
(
map
[
string
][]
string
,
string
)
{
values
,
dbName
:=
GenerateFieldValuesFromExcel
(
referFile
,
field
)
return
values
,
dbName
return
groupedValue
}
\ No newline at end of file
src/model/definition.go
浏览文件 @
c614d12c
...
...
@@ -7,20 +7,20 @@ type ClsBase struct {
Version
string
`yaml:"version"`
}
// range re
fer
type
Cl
sRanges
struct
{
// range re
s
type
Re
sRanges
struct
{
ClsBase
`yaml:",inline"`
FieldBase
`yaml:",inline"`
Field
string
`yaml:"field"`
Ranges
map
[
string
]
string
`yaml:"ranges"`
}
// instance re
fer
type
Cl
sInsts
struct
{
// instance re
s
type
Re
sInsts
struct
{
ClsBase
`yaml:",inline"`
Field
string
`yaml:"field"`
Instances
[]
Cl
sInst
`yaml:"instances,flow"`
Field
string
`yaml:"field"`
Instances
[]
Re
sInst
`yaml:"instances,flow"`
}
type
Cl
sInst
struct
{
type
Re
sInst
struct
{
FieldBase
`yaml:",inline"`
Instance
string
`yaml:"instance"`
Range
string
`yaml:"range"`
...
...
src/utils/const/const.go
浏览文件 @
c614d12c
...
...
@@ -28,11 +28,11 @@ var (
Total
=
10
MaxNumb
=
100000
// max number in array
RootDef
=
model
.
DefData
{}
Re
feredValue
s
=
map
[
string
]
map
[
string
][]
string
{}
Def
=
model
.
DefData
{}
Res
=
map
[
string
]
map
[
string
][]
string
{}
ResDir
=
"data/"
Res
BuildIn
=
ResDir
+
"system/buildin.yaml"
ResDir
=
"data/"
Res
Path
=
ResDir
+
"system/buildin.yaml"
SqliteDriver
=
"sqlite3"
SqliteSource
=
"file:"
+
ResDir
+
".cache/.data.db"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录