Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
zendata
提交
ee2b50fb
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 搜索 >>
提交
ee2b50fb
编写于
5月 19, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
generate output
上级
85c56f48
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
40 addition
and
86 deletion
+40
-86
project1/test.yaml
project1/test.yaml
+6
-2
src/action/generator.go
src/action/generator.go
+1
-5
src/gen/cls.go
src/gen/cls.go
+1
-14
src/gen/definition.go
src/gen/definition.go
+5
-28
src/gen/generator.go
src/gen/generator.go
+18
-28
src/utils/const/const.go
src/utils/const/const.go
+9
-9
未找到文件。
project1/test.yaml
浏览文件 @
ee2b50fb
...
@@ -12,10 +12,14 @@ fields:
...
@@ -12,10 +12,14 @@ fields:
-
field
:
field2
-
field
:
field2
note
:
测试系统字段
note
:
测试系统字段
from
:
system.ip.yaml
from
:
system.ip.yaml
use
:
private
c,privateb
use
:
private
C,privateB
-
field
:
field3
-
field
:
field3
note
:
测试Excel数据
note
:
测试Excel数据
from
:
system.address.city
from
:
system.address.city
select
:
name
select
:
name
where
:
state like '%山东%'
where
:
state like '%山东%'
\ No newline at end of file
-
field
:
field4
note
:
测试Excel数据
range
:
a-z,0-9
\ No newline at end of file
src/action/generator.go
浏览文件 @
ee2b50fb
...
@@ -23,11 +23,7 @@ func Generate(defFile string, total int, fieldsToExportStr string, out string, f
...
@@ -23,11 +23,7 @@ func Generate(defFile string, total int, fieldsToExportStr string, out string, f
constant
.
Total
=
total
constant
.
Total
=
total
fieldsToExport
:=
strings
.
Split
(
fieldsToExportStr
,
","
)
fieldsToExport
:=
strings
.
Split
(
fieldsToExportStr
,
","
)
rows
,
colTypes
:=
gen
.
GenerateForDefinition
(
defFile
,
fieldsToExport
,
total
)
referFieldValueMap
:=
gen
.
LoadClsDef
(
defFile
,
fieldsToExport
)
referFieldValueMap
=
referFieldValueMap
rows
,
colTypes
:=
gen
.
GenerateForDefinition
(
total
,
fieldsToExport
)
content
:=
Print
(
rows
,
format
,
table
,
colTypes
,
fieldsToExport
)
content
:=
Print
(
rows
,
format
,
table
,
colTypes
,
fieldsToExport
)
WriteToFile
(
out
,
content
)
WriteToFile
(
out
,
content
)
...
...
src/gen/cls.go
浏览文件 @
ee2b50fb
...
@@ -17,20 +17,7 @@ import (
...
@@ -17,20 +17,7 @@ import (
func
LoadClsDef
(
file
string
,
fieldsToExport
[]
string
)
map
[
string
]
map
[
string
][]
string
{
func
LoadClsDef
(
file
string
,
fieldsToExport
[]
string
)
map
[
string
]
map
[
string
][]
string
{
referFieldValueMap
:=
map
[
string
]
map
[
string
][]
string
{}
referFieldValueMap
:=
map
[
string
]
map
[
string
][]
string
{}
yamlContent
,
err
:=
ioutil
.
ReadFile
(
file
)
for
_
,
field
:=
range
constant
.
RootDef
.
Fields
{
if
err
!=
nil
{
logUtils
.
Screen
(
"fail to read "
+
file
)
return
referFieldValueMap
}
def
:=
model
.
DefData
{}
err
=
yaml
.
Unmarshal
(
yamlContent
,
&
def
)
if
err
!=
nil
{
logUtils
.
Screen
(
"fail to parse "
+
file
)
return
referFieldValueMap
}
for
_
,
field
:=
range
def
.
Fields
{
if
!
stringUtils
.
FindInArr
(
field
.
Field
,
fieldsToExport
)
{
continue
}
if
!
stringUtils
.
FindInArr
(
field
.
Field
,
fieldsToExport
)
{
continue
}
loadClsField
(
&
field
,
&
referFieldValueMap
)
loadClsField
(
&
field
,
&
referFieldValueMap
)
...
...
src/gen/definition.go
浏览文件 @
ee2b50fb
...
@@ -2,48 +2,25 @@ package gen
...
@@ -2,48 +2,25 @@ package gen
import
(
import
(
"github.com/easysoft/zendata/src/model"
"github.com/easysoft/zendata/src/model"
constant
"github.com/easysoft/zendata/src/utils/const"
logUtils
"github.com/easysoft/zendata/src/utils/log"
logUtils
"github.com/easysoft/zendata/src/utils/log"
stringUtils
"github.com/easysoft/zendata/src/utils/string"
"gopkg.in/yaml.v2"
"gopkg.in/yaml.v2"
"io/ioutil"
"io/ioutil"
)
)
func
LoadRootDef
(
file
string
,
fieldsToExport
[]
string
)
([]
model
.
ClsRanges
,
[]
model
.
ClsInst
)
{
func
LoadRootDef
(
file
string
)
model
.
DefData
{
referRangeFields
:=
make
([]
model
.
ClsRanges
,
0
)
def
:=
model
.
DefData
{}
referInstFields
:=
make
([]
model
.
ClsInst
,
0
)
yamlContent
,
err
:=
ioutil
.
ReadFile
(
file
)
yamlContent
,
err
:=
ioutil
.
ReadFile
(
file
)
if
err
!=
nil
{
if
err
!=
nil
{
logUtils
.
Screen
(
"fail to read "
+
file
)
logUtils
.
Screen
(
"fail to read "
+
file
)
return
referRangeFields
,
referInstFields
return
def
}
}
def
:=
model
.
DefData
{}
err
=
yaml
.
Unmarshal
(
yamlContent
,
&
def
)
err
=
yaml
.
Unmarshal
(
yamlContent
,
&
def
)
if
err
!=
nil
{
if
err
!=
nil
{
logUtils
.
Screen
(
"fail to parse "
+
file
)
logUtils
.
Screen
(
"fail to parse "
+
file
)
return
referRangeFields
,
referInstFields
return
def
}
constant
.
RootDef
=
def
//constant.ResMap =
for
_
,
field
:=
range
def
.
Fields
{
if
!
stringUtils
.
FindInArr
(
field
.
Field
,
fieldsToExport
)
{
continue
}
if
field
.
From
!=
""
{
if
field
.
Select
!=
""
{
// excel
}
else
if
field
.
Use
!=
""
{
// range or instance format
//referFile, referType := getReferProp(field.From)
// init const.ResMap
}
}
// TODO:
}
}
return
referRangeFields
,
referInstFields
return
def
}
}
src/gen/generator.go
浏览文件 @
ee2b50fb
...
@@ -9,21 +9,22 @@ import (
...
@@ -9,21 +9,22 @@ import (
"strings"
"strings"
)
)
func
GenerateForDefinition
(
total
int
,
fieldsToExport
[]
string
)
([][]
string
,
[]
bool
)
{
func
GenerateForDefinition
(
defFile
string
,
fieldsToExport
[]
string
,
total
int
)
([][]
string
,
[]
bool
)
{
def
:=
constant
.
RootDef
constant
.
RootDef
=
LoadRootDef
(
defFile
)
constant
.
ReferedValues
=
LoadClsDef
(
defFile
,
fieldsToExport
)
fieldNameToValues
:=
map
[
string
][]
string
{}
fieldNameToValues
:=
map
[
string
][]
string
{}
colTypes
:=
make
([]
bool
,
0
)
colTypes
:=
make
([]
bool
,
0
)
// 为每个field生成值列表
// 为每个field生成值列表
for
index
,
field
:=
range
d
ef
.
Fields
{
for
index
,
field
:=
range
constant
.
RootD
ef
.
Fields
{
if
!
stringUtils
.
FindInArr
(
field
.
Field
,
fieldsToExport
)
{
if
!
stringUtils
.
FindInArr
(
field
.
Field
,
fieldsToExport
)
{
continue
continue
}
}
values
:=
GenerateForField
(
&
field
,
total
)
values
:=
GenerateForField
(
&
field
,
total
)
d
ef
.
Fields
[
index
]
.
Precision
=
field
.
Precision
constant
.
RootD
ef
.
Fields
[
index
]
.
Precision
=
field
.
Precision
fieldNameToValues
[
field
.
Field
]
=
values
fieldNameToValues
[
field
.
Field
]
=
values
colTypes
=
append
(
colTypes
,
field
.
IsNumb
)
colTypes
=
append
(
colTypes
,
field
.
IsNumb
)
...
@@ -32,7 +33,7 @@ func GenerateForDefinition(total int, fieldsToExport []string) ([][]string, []bo
...
@@ -32,7 +33,7 @@ func GenerateForDefinition(total int, fieldsToExport []string) ([][]string, []bo
// 生成指定数量行的数据
// 生成指定数量行的数据
rows
:=
make
([][]
string
,
0
)
rows
:=
make
([][]
string
,
0
)
for
i
:=
0
;
i
<
total
;
i
++
{
for
i
:=
0
;
i
<
total
;
i
++
{
for
_
,
field
:=
range
d
ef
.
Fields
{
for
_
,
field
:=
range
constant
.
RootD
ef
.
Fields
{
if
!
stringUtils
.
FindInArr
(
field
.
Field
,
fieldsToExport
)
{
if
!
stringUtils
.
FindInArr
(
field
.
Field
,
fieldsToExport
)
{
continue
continue
}
}
...
@@ -60,7 +61,7 @@ func GenerateForField(field *model.DefField, total int) []string {
...
@@ -60,7 +61,7 @@ func GenerateForField(field *model.DefField, total int) []string {
for
i
:=
0
;
i
<
total
;
i
++
{
for
i
:=
0
;
i
<
total
;
i
++
{
concat
:=
""
concat
:=
""
for
_
,
row
:=
range
arr
{
for
_
,
row
:=
range
arr
{
concat
=
concat
+
row
[
i
]
// a1 or b2
concat
=
concat
+
row
[
i
]
//
get one item from each child, grouped as
a1 or b2
}
}
concat
=
field
.
Prefix
+
concat
+
field
.
Postfix
concat
=
field
.
Prefix
+
concat
+
field
.
Postfix
...
@@ -68,32 +69,21 @@ func GenerateForField(field *model.DefField, total int) []string {
...
@@ -68,32 +69,21 @@ func GenerateForField(field *model.DefField, total int) []string {
}
}
values
=
LoopSubFields
(
field
,
values
,
total
)
values
=
LoopSubFields
(
field
,
values
,
total
)
}
else
if
field
.
From
!=
""
&&
field
.
Select
!=
""
{
// refer to excel
}
else
if
field
.
From
!=
""
{
// refer field
arr
:=
strings
.
Split
(
field
.
From
,
"."
)
groupValues
:=
constant
.
ReferedValues
[
field
.
From
]
referField
:=
constant
.
ResMap
[
arr
[
0
]]
referField
.
From
=
field
.
From
if
field
.
Use
!=
""
{
// refer to cls
referField
.
Select
=
field
.
Select
groups
:=
strings
.
Split
(
field
.
Use
,
","
)
referField
.
Where
=
field
.
Where
for
_
,
group
:=
range
groups
{
values
=
append
(
values
,
groupValues
[
group
]
...
)
referField
.
Format
=
field
.
Format
}
referField
.
Prefix
=
field
.
Prefix
referField
.
Postfix
=
field
.
Postfix
referField
.
Loop
=
field
.
Loop
referField
.
Loopfix
=
field
.
Loopfix
//values = GenerateFieldItemsFromDefinition(&referField, total)
}
else
if
field
.
From
!=
""
&&
field
.
Range
!=
""
{
// refer to yaml file
}
else
{
// refer to excel
if
field
.
Range
!=
""
{
// specific custom file
slct
:=
field
.
Select
//LoadRootDef(constant.InputDir + field.Range
)
values
=
append
(
values
,
groupValues
[
slct
]
...
)
}
}
//referField := constant.ResMap[field.Field]
}
else
{
// basic field
//values = GenerateForField(&referField, total)
// TODO: 需要处理range: small,large等逻辑
}
else
{
values
=
GenerateFieldItemsFromDefinition
(
field
)
values
=
GenerateFieldItemsFromDefinition
(
field
)
}
}
...
...
src/utils/const/const.go
浏览文件 @
ee2b50fb
...
@@ -28,17 +28,17 @@ var (
...
@@ -28,17 +28,17 @@ var (
Total
=
10
Total
=
10
MaxNumb
=
100000
// max number in array
MaxNumb
=
100000
// max number in array
RootDef
model
.
DefData
=
model
.
DefData
{}
RootDef
=
model
.
DefData
{}
Re
sMap
map
[
string
]
model
.
FieldValue
=
map
[
string
]
model
.
FieldValue
{}
Re
feredValues
=
map
[
string
]
map
[
string
][]
string
{}
ResDir
string
=
"data/"
ResDir
=
"data/"
ResBuildIn
string
=
ResDir
+
"system/buildin.yaml"
ResBuildIn
=
ResDir
+
"system/buildin.yaml"
SqliteDriver
string
=
"sqlite3"
SqliteDriver
=
"sqlite3"
SqliteSource
string
=
"file:"
+
ResDir
+
".cache/.data.db"
SqliteSource
=
"file:"
+
ResDir
+
".cache/.data.db"
SqliteTrackTable
string
=
"excel_update"
SqliteTrackTable
=
"excel_update"
ExcelBorder
string
=
`{"border": [{"type":"left","color":"999999","style":1}, {"type":"top","color":"999999","style":1},
ExcelBorder
=
`{"border": [{"type":"left","color":"999999","style":1}, {"type":"top","color":"999999","style":1},
{"type":"bottom","color":"999999","style":1}, {"type":"right","color":"999999","style":1}]}`
{"type":"bottom","color":"999999","style":1}, {"type":"right","color":"999999","style":1}]}`
ExcelHeader
string
=
`{"fill":{"type":"pattern","pattern":1,"color":["E0EBF5"]}}`
ExcelHeader
=
`{"fill":{"type":"pattern","pattern":1,"color":["E0EBF5"]}}`
)
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录