Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
zendata
提交
88c9cec2
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 搜索 >>
提交
88c9cec2
编写于
8月 18, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
close task#7670,7671,7674
上级
f964a1d6
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
73 addition
and
31 deletion
+73
-31
data/.cache/.data.db
data/.cache/.data.db
+0
-0
data/address/cn.v1.xlsx
data/address/cn.v1.xlsx
+0
-0
demo/advanced.yaml
demo/advanced.yaml
+4
-1
demo/default.yaml
demo/default.yaml
+1
-1
src/gen/excel.go
src/gen/excel.go
+19
-9
src/gen/res.go
src/gen/res.go
+49
-20
未找到文件。
data/.cache/.data.db
浏览文件 @
88c9cec2
无法预览此类型文件
data/
system/address/
v1.xlsx
→
data/
address/cn.
v1.xlsx
浏览文件 @
88c9cec2
无法预览此类型文件
demo/advanced.yaml
浏览文件 @
88c9cec2
...
...
@@ -36,4 +36,7 @@ fields:
use
:
small{2}
postfix
:
"
\t
"
-
from
:
custom.test.number.v1.yaml
use
:
large{3}
\ No newline at end of file
use
:
large{3}
-
field
:
field_blank
range
:
[
user-1
,]
\ No newline at end of file
demo/default.yaml
浏览文件 @
88c9cec2
...
...
@@ -118,7 +118,7 @@ fields:
postfix
:
"
}"
-
field
:
field_use_excel
# 从excel数据源里面取数据。
from
:
system.address.v1.china
# 从data/system/address/v1.xlsx文件中读取名为china的工作簿
。
from
:
address.cn.v1.china
# 从data/address/cn.v1.xlsx文件中读取名为china的工作表
。
select
:
city
# 查询city字段。
where
:
state like '%山东%'
# 条件是省份包含山东。
limit
:
10
...
...
src/gen/excel.go
浏览文件 @
88c9cec2
...
...
@@ -15,20 +15,19 @@ import (
"time"
)
func
GenerateFieldValuesFromExcel
(
path
string
,
field
*
model
.
DefField
)
(
map
[
string
][]
string
,
string
)
{
func
GenerateFieldValuesFromExcel
(
path
,
sheet
string
,
field
*
model
.
DefField
)
(
map
[
string
][]
string
,
string
)
{
values
:=
map
[
string
][]
string
{}
idx
:=
strings
.
LastIndex
(
field
.
From
,
"."
)
tableName
:=
field
.
From
[
idx
+
1
:
]
arr
:=
strings
.
Split
(
field
.
From
,
"."
)
dbName
:=
arr
[
len
(
arr
)
-
3
]
+
"_"
+
arr
[
len
(
arr
)
-
2
]
dbName
:=
getDbName
(
path
)
list
:=
make
([]
string
,
0
)
selectCol
:=
""
ConvertExcelToSQLiteIfNeeded
(
dbName
,
path
)
firstSheet
:=
ConvertExcelToSQLiteIfNeeded
(
dbName
,
path
)
if
sheet
==
""
{
sheet
=
firstSheet
}
list
,
selectCol
=
ReadDataFromSQLite
(
*
field
,
dbName
,
tableName
)
list
,
selectCol
=
ReadDataFromSQLite
(
*
field
,
dbName
,
sheet
)
// get index for data retrieve
numbs
:=
GenerateIntItems
(
0
,
(
int64
)(
len
(
list
)
-
1
),
1
,
false
,
1
)
// get data by index
...
...
@@ -50,13 +49,22 @@ func GenerateFieldValuesFromExcel(path string, field *model.DefField) (map[strin
return
values
,
dbName
}
func
ConvertExcelToSQLiteIfNeeded
(
dbName
string
,
path
string
)
{
func
getDbName
(
path
string
)
(
dbName
string
)
{
dbName
=
strings
.
Replace
(
path
,
vari
.
WorkDir
+
constant
.
ResDir
,
""
,
-
1
)
dbName
=
strings
.
Replace
(
dbName
,
constant
.
PthSep
,
"_"
,
-
1
)
dbName
=
strings
.
Replace
(
dbName
,
"."
,
"_"
,
-
1
)
return
}
func
ConvertExcelToSQLiteIfNeeded
(
dbName
string
,
path
string
)
(
firstSheet
string
)
{
excel
,
err
:=
excelize
.
OpenFile
(
path
)
if
err
!=
nil
{
logUtils
.
PrintTo
(
i118Utils
.
I118Prt
.
Sprintf
(
"fail_to_read_file"
,
path
))
return
}
firstSheet
=
excel
.
GetSheetList
()[
0
]
if
!
isExcelChanged
(
path
)
{
return
}
...
...
@@ -148,6 +156,8 @@ func ConvertExcelToSQLiteIfNeeded(dbName string, path string) {
return
}
}
return
}
func
ReadDataFromSQLite
(
field
model
.
DefField
,
dbName
string
,
tableName
string
)
([]
string
,
string
)
{
...
...
src/gen/res.go
浏览文件 @
88c9cec2
...
...
@@ -47,19 +47,17 @@ func loadResField(field *model.DefField, res *map[string]map[string][]string) {
loadResField
(
&
child
,
res
)
}
}
else
if
field
.
From
!=
""
{
resFile
,
resType
:=
getResProp
(
field
.
From
)
values
,
_
:=
getResValue
(
resFile
,
resType
,
field
)
resFile
,
resType
,
sheet
:=
getResProp
(
field
.
From
)
values
,
_
:=
getResValue
(
resFile
,
resType
,
sheet
,
field
)
(
*
res
)[
field
.
From
]
=
values
}
else
if
field
.
Config
!=
""
{
resFile
,
resType
:=
getResProp
(
field
.
Config
)
values
,
_
:=
getResValue
(
resFile
,
resType
,
field
)
resFile
,
resType
,
_
:=
getResProp
(
field
.
Config
)
values
,
_
:=
getResValue
(
resFile
,
resType
,
""
,
field
)
(
*
res
)[
field
.
Config
]
=
values
}
}
func
getResProp
(
from
string
)
(
string
,
string
)
{
// from resource
resFile
:=
""
resType
:=
""
func
getResProp
(
from
string
)
(
resFile
,
resType
,
sheet
string
)
{
// from resource
index
:=
strings
.
LastIndex
(
from
,
".yaml"
)
if
index
>
-
1
{
// yaml, system.ip.v1.yaml
...
...
@@ -68,13 +66,8 @@ func getResProp(from string) (string, string) { // from resource
resFile
=
left
+
".yaml"
resType
=
"yaml"
}
else
{
// excel, system.address.v1.city
index
=
strings
.
LastIndex
(
from
,
"."
)
left
:=
from
[
:
index
]
left
=
strings
.
ReplaceAll
(
left
,
"."
,
constant
.
PthSep
)
resFile
=
left
+
".xlsx"
}
else
{
// excel, like address.cn.v1.china
resFile
,
sheet
=
convertExcelPath
(
from
)
resType
=
"excel"
}
...
...
@@ -101,24 +94,60 @@ func getResProp(from string) (string, string) { // from resource
resFile
=
resPath
}
return
resFile
,
resType
return
}
func
convertExcelPath
(
from
string
)
(
ret
,
sheet
string
)
{
path1
:=
from
// address.cn.v1
index
:=
strings
.
LastIndex
(
from
,
"."
)
path2
:=
from
[
:
index
]
// address.cn.v1.china
paths
:=
[
2
]
string
{
path1
,
path2
}
for
index
,
path
:=
range
paths
{
arr
:=
strings
.
Split
(
path
,
"."
)
for
i
:=
0
;
i
<
len
(
arr
);
i
++
{
dir
:=
""
if
i
>
0
{
dir
=
strings
.
Join
(
arr
[
:
i
],
constant
.
PthSep
)
}
file
:=
strings
.
Join
(
arr
[
i
:
],
"."
)
+
".xlsx"
if
dir
!=
""
{
ret
=
dir
+
constant
.
PthSep
+
file
}
else
{
ret
=
file
}
realPth
:=
vari
.
WorkDir
+
constant
.
ResDir
+
ret
if
fileUtils
.
FileExist
(
realPth
)
{
if
index
==
1
{
sheet
=
from
[
strings
.
LastIndex
(
from
,
"."
)
+
1
:
]
}
ret
=
realPth
return
}
}
}
return
}
func
getResValue
(
resFile
string
,
resType
string
,
field
*
model
.
DefField
)
(
map
[
string
][]
string
,
string
)
{
func
getResValue
(
resFile
,
resType
,
sheet
string
,
field
*
model
.
DefField
)
(
map
[
string
][]
string
,
string
)
{
resName
:=
""
groupedValues
:=
map
[
string
][]
string
{}
if
resType
==
"yaml"
{
groupedValues
,
resName
=
getResForYaml
(
resFile
)
}
else
if
resType
==
"excel"
{
groupedValues
,
resName
=
getResForExcel
(
resFile
,
field
)
groupedValues
,
resName
=
getResForExcel
(
resFile
,
sheet
,
field
)
}
return
groupedValues
,
resName
}
func
getResForExcel
(
resFile
string
,
field
*
model
.
DefField
)
(
map
[
string
][]
string
,
string
)
{
valueMap
,
resName
:=
GenerateFieldValuesFromExcel
(
resFile
,
field
)
func
getResForExcel
(
resFile
,
sheet
string
,
field
*
model
.
DefField
)
(
map
[
string
][]
string
,
string
)
{
valueMap
,
resName
:=
GenerateFieldValuesFromExcel
(
resFile
,
sheet
,
field
)
return
valueMap
,
resName
}
...
...
@@ -199,7 +228,7 @@ func getResForInstances(insts model.ResInsts) map[string][]string {
}
func
getRootRangeOrInstant
(
inst
model
.
DefField
)
(
parentRanges
model
.
ResRanges
,
parentInsts
model
.
ResInsts
)
{
resFile
,
_
:=
getResProp
(
inst
.
From
)
resFile
,
_
,
_
:=
getResProp
(
inst
.
From
)
yamlContent
,
err
:=
ioutil
.
ReadFile
(
resFile
)
if
err
!=
nil
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录