Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
zendata
提交
20940883
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 搜索 >>
提交
20940883
编写于
8月 20, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
close task#7692
上级
2f9bead8
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
122 addition
and
152 deletion
+122
-152
data/address/cn.v1.xlsx
data/address/cn.v1.xlsx
+0
-0
src/gen/excel.go
src/gen/excel.go
+1
-1
src/gen/res.go
src/gen/res.go
+3
-96
src/service/list.go
src/service/list.go
+38
-35
src/service/view.go
src/service/view.go
+1
-1
src/utils/const/const.go
src/utils/const/const.go
+3
-3
src/utils/file/file.go
src/utils/file/file.go
+76
-16
未找到文件。
data/address/cn.v1.xlsx
浏览文件 @
20940883
无法预览此类型文件
src/gen/excel.go
浏览文件 @
20940883
...
...
@@ -50,7 +50,7 @@ func GenerateFieldValuesFromExcel(path, sheet string, field *model.DefField) (ma
}
func
getDbName
(
path
string
)
(
dbName
string
)
{
dbName
=
strings
.
Replace
(
path
,
vari
.
WorkDir
+
constant
.
ResDirData
,
""
,
-
1
)
dbName
=
strings
.
Replace
(
path
,
vari
.
WorkDir
+
constant
.
ResDirData
+
constant
.
PthSep
,
""
,
-
1
)
dbName
=
strings
.
Replace
(
dbName
,
constant
.
PthSep
,
"_"
,
-
1
)
dbName
=
strings
.
Replace
(
dbName
,
"."
,
"_"
,
-
1
)
...
...
src/gen/res.go
浏览文件 @
20940883
...
...
@@ -2,7 +2,6 @@ package gen
import
(
"github.com/easysoft/zendata/src/model"
constant
"github.com/easysoft/zendata/src/utils/const"
fileUtils
"github.com/easysoft/zendata/src/utils/file"
i118Utils
"github.com/easysoft/zendata/src/utils/i118"
logUtils
"github.com/easysoft/zendata/src/utils/log"
...
...
@@ -11,7 +10,6 @@ import (
"github.com/jinzhu/copier"
"gopkg.in/yaml.v3"
"io/ioutil"
"strings"
)
func
LoadResDef
(
fieldsToExport
[]
string
)
map
[
string
]
map
[
string
][]
string
{
...
...
@@ -46,108 +44,17 @@ func loadResField(field *model.DefField, res *map[string]map[string][]string) {
loadResField
(
&
child
,
res
)
}
}
else
if
field
.
From
!=
""
{
resFile
,
resType
,
sheet
:=
g
etResProp
(
field
.
From
)
resFile
,
resType
,
sheet
:=
fileUtils
.
G
etResProp
(
field
.
From
)
values
,
_
:=
getResValue
(
resFile
,
resType
,
sheet
,
field
)
(
*
res
)[
field
.
From
]
=
values
}
else
if
field
.
Config
!=
""
{
resFile
,
resType
,
_
:=
g
etResProp
(
field
.
Config
)
resFile
,
resType
,
_
:=
fileUtils
.
G
etResProp
(
field
.
Config
)
values
,
_
:=
getResValue
(
resFile
,
resType
,
""
,
field
)
(
*
res
)[
field
.
Config
]
=
values
}
}
func
getResProp
(
from
string
)
(
resFile
,
resType
,
sheet
string
)
{
// from resource
index
:=
strings
.
LastIndex
(
from
,
".yaml"
)
if
index
>
-
1
{
// yaml, ip.v1.yaml
resFile
=
convertYamlPath
(
from
)
resType
=
"yaml"
}
else
{
// excel, like address.cn.v1.china
resFile
,
sheet
=
convertExcelPath
(
from
)
resType
=
"excel"
}
if
resFile
==
""
{
resPath
:=
vari
.
ConfigDir
+
resFile
if
!
fileUtils
.
FileExist
(
resPath
)
{
// in same folder with passed config file
resPath
=
vari
.
WorkDir
+
resFile
if
!
fileUtils
.
FileExist
(
resPath
)
{
// in res file
resPath
=
""
}
}
resFile
=
resPath
}
return
}
func
convertYamlPath
(
from
string
)
(
ret
string
)
{
arr
:=
strings
.
Split
(
from
,
"."
)
for
i
:=
0
;
i
<
len
(
arr
);
i
++
{
dir
:=
""
if
i
>
0
{
dir
=
strings
.
Join
(
arr
[
:
i
],
constant
.
PthSep
)
}
file
:=
strings
.
Join
(
arr
[
i
:
],
"."
)
if
dir
!=
""
{
ret
=
dir
+
constant
.
PthSep
+
file
}
else
{
ret
=
file
}
realPth1
:=
vari
.
WorkDir
+
constant
.
ResDirYaml
+
ret
realPth2
:=
vari
.
WorkDir
+
constant
.
ResDirUsers
+
ret
if
fileUtils
.
FileExist
(
realPth1
)
{
ret
=
realPth1
break
}
else
if
fileUtils
.
FileExist
(
realPth2
)
{
ret
=
realPth2
break
}
}
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
.
ResDirData
+
ret
if
fileUtils
.
FileExist
(
realPth
)
{
if
index
==
1
{
sheet
=
from
[
strings
.
LastIndex
(
from
,
"."
)
+
1
:
]
}
ret
=
realPth
return
}
}
}
return
}
func
getResValue
(
resFile
,
resType
,
sheet
string
,
field
*
model
.
DefField
)
(
map
[
string
][]
string
,
string
)
{
resName
:=
""
groupedValues
:=
map
[
string
][]
string
{}
...
...
@@ -243,7 +150,7 @@ func getResForInstances(insts model.ResInsts) map[string][]string {
}
func
getRootRangeOrInstant
(
inst
model
.
DefField
)
(
parentRanges
model
.
ResRanges
,
parentInsts
model
.
ResInsts
)
{
resFile
,
_
,
_
:=
g
etResProp
(
inst
.
From
)
resFile
,
_
,
_
:=
fileUtils
.
G
etResProp
(
inst
.
From
)
yamlContent
,
err
:=
ioutil
.
ReadFile
(
resFile
)
if
err
!=
nil
{
...
...
src/service/list.go
浏览文件 @
20940883
...
...
@@ -5,6 +5,7 @@ import (
"github.com/360EntSecGroup-Skylar/excelize/v2"
"github.com/easysoft/zendata/src/model"
constant
"github.com/easysoft/zendata/src/utils/const"
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"
...
...
@@ -20,14 +21,14 @@ const (
)
func
ListRes
()
{
orderedKeys
:=
[
2
]
string
{
"yaml"
,
"excel"
}
orderedKeys
:=
[
3
]
string
{
constant
.
ResDirData
,
constant
.
ResDirYaml
,
constant
.
ResDirUsers
}
res
:=
map
[
string
][][
size
]
string
{}
GetFilesAndDirs
(
constant
.
ResDirData
,
&
res
)
GetFilesAndDirs
(
constant
.
ResDirYaml
,
&
res
)
GetFilesAndDirs
(
constant
.
ResDirUsers
,
&
res
)
for
_
,
key
:=
range
orderedKeys
{
GetFilesAndDirs
(
key
,
key
,
&
res
)
}
names
:=
make
([]
string
,
0
)
//
names := make([]string, 0)
nameWidth
:=
0
titleWidth
:=
0
for
_
,
key
:=
range
orderedKeys
{
...
...
@@ -35,21 +36,21 @@ func ListRes() {
for
index
,
arr
:=
range
arrOfArr
{
path
:=
arr
[
0
]
if
key
==
"yaml"
{
if
key
==
constant
.
ResDirYaml
||
key
==
constant
.
ResDirUsers
{
arr
[
2
],
arr
[
3
]
=
readYamlInfo
(
path
)
}
else
if
key
==
"excel"
{
}
else
if
key
==
constant
.
ResDirData
{
arr
[
2
],
arr
[
3
]
=
readExcelInfo
(
path
)
}
res
[
key
][
index
]
=
arr
name
:=
pathToName
(
arr
[
1
])
names
=
append
(
names
,
name
)
name
:=
pathToName
(
arr
[
1
]
,
key
)
//
names = append(names, name)
lent
:=
runewidth
.
StringWidth
(
name
)
if
lent
>
nameWidth
{
nameWidth
=
lent
}
if
key
==
"excel"
{
if
key
==
constant
.
ResDirData
{
sheets
:=
strings
.
Split
(
arr
[
2
],
"|"
)
for
_
,
sheet
:=
range
sheets
{
lent2
:=
runewidth
.
StringWidth
(
sheet
)
...
...
@@ -66,27 +67,22 @@ func ListRes() {
}
}
sysMsg
:=
""
customMsg
:=
""
dataMsg
:=
""
yamlMsg
:=
""
usersMsg
:=
""
idx
:=
0
for
_
,
key
:=
range
orderedKeys
{
arrOfArr
:=
res
[
key
]
arrOfArr
=
sortByName
(
arrOfArr
)
for
_
,
arr
:=
range
arrOfArr
{
name
:=
names
[
idx
]
name
:=
pathToName
(
arr
[
1
],
key
)
titleStr
:=
arr
[
2
]
titles
:=
strings
.
Split
(
titleStr
,
"|"
)
idx2
:=
0
isBuildin
:=
false
for
_
,
title
:=
range
titles
{
if
strings
.
Index
(
name
,
"system"
)
>
-
1
{
isBuildin
=
true
}
else
{
isBuildin
=
false
}
if
idx2
>
0
{
name
=
""
}
...
...
@@ -95,10 +91,12 @@ func ListRes() {
title
=
title
+
strings
.
Repeat
(
" "
,
titleWidth
-
runewidth
.
StringWidth
(
title
))
msg
:=
fmt
.
Sprintf
(
"%s %s %s
\n
"
,
name
,
title
,
arr
[
3
])
if
isBuildin
{
sysMsg
=
sysMsg
+
msg
}
else
{
customMsg
=
customMsg
+
msg
if
key
==
constant
.
ResDirData
{
dataMsg
=
dataMsg
+
msg
}
else
if
key
==
constant
.
ResDirYaml
{
yamlMsg
=
yamlMsg
+
msg
}
else
if
key
==
constant
.
ResDirUsers
{
usersMsg
=
usersMsg
+
msg
}
idx2
++
...
...
@@ -108,33 +106,35 @@ func ListRes() {
}
}
logUtils
.
PrintTo
(
sysMsg
+
"
\n
"
+
custom
Msg
)
logUtils
.
PrintTo
(
dataMsg
+
"
\n
"
+
yamlMsg
+
"
\n
"
+
users
Msg
)
}
func
GetFilesAndDirs
(
path
string
,
res
*
map
[
string
][][
size
]
string
)
{
dir
,
err
:=
ioutil
.
ReadDir
(
vari
.
WorkDir
+
path
)
func
GetFilesAndDirs
(
path
,
typ
string
,
res
*
map
[
string
][][
size
]
string
)
{
if
!
fileUtils
.
IsAbosutePath
(
path
)
{
path
=
vari
.
WorkDir
+
path
}
dir
,
err
:=
ioutil
.
ReadDir
(
path
)
if
err
!=
nil
{
return
}
for
_
,
fi
:=
range
dir
{
if
fi
.
IsDir
()
{
GetFilesAndDirs
(
path
+
constant
.
PthSep
+
fi
.
Name
(),
res
)
GetFilesAndDirs
(
path
+
constant
.
PthSep
+
fi
.
Name
(),
typ
,
res
)
}
else
{
name
:=
fi
.
Name
()
arr
:=
[
size
]
string
{}
if
strings
.
HasSuffix
(
name
,
".yaml"
)
{
arr
[
0
]
=
path
+
constant
.
PthSep
+
name
arr
[
1
]
=
path
[
strings
.
LastIndex
(
path
,
path
)
:
]
+
constant
.
PthSep
+
name
arr
[
1
]
=
strings
.
Trim
(
arr
[
1
],
"data"
+
constant
.
PthSep
)
arr
[
1
]
=
arr
[
0
]
(
*
res
)[
"yaml"
]
=
append
((
*
res
)[
"yaml"
],
arr
)
(
*
res
)[
typ
]
=
append
((
*
res
)[
typ
],
arr
)
}
else
if
strings
.
HasSuffix
(
name
,
".xlsx"
)
{
arr
[
0
]
=
path
+
constant
.
PthSep
+
name
arr
[
1
]
=
path
[
strings
.
LastIndex
(
path
,
"data"
)
:
]
+
constant
.
PthSep
+
name
arr
[
1
]
=
strings
.
Trim
(
arr
[
1
],
"data"
+
constant
.
PthSep
)
arr
[
1
]
=
arr
[
0
]
(
*
res
)[
"excel"
]
=
append
((
*
res
)[
"excel"
],
arr
)
(
*
res
)[
typ
]
=
append
((
*
res
)[
typ
],
arr
)
}
}
...
...
@@ -178,9 +178,12 @@ func readExcelInfo(path string) (title string, desc string) {
return
}
func
pathToName
(
path
string
)
string
{
func
pathToName
(
path
,
key
string
)
string
{
name
:=
strings
.
ReplaceAll
(
path
,
constant
.
PthSep
,
"."
)
name
=
name
[
:
strings
.
LastIndex
(
name
,
"."
)]
name
=
strings
.
Split
(
name
,
"."
+
key
+
"."
)[
1
]
if
key
==
constant
.
ResDirData
{
name
=
name
[
:
strings
.
LastIndex
(
name
,
"."
)]
}
return
name
}
...
...
src/service/view.go
浏览文件 @
20940883
...
...
@@ -14,7 +14,7 @@ import (
)
func
ViewRes
(
res
string
)
{
res
Type
,
resPath
,
sheet
:=
fileUtils
.
ConvertResPath
(
res
)
res
Path
,
resType
,
sheet
:=
fileUtils
.
GetResProp
(
res
)
if
resType
==
"yaml"
{
typ
,
inst
,
ranges
:=
readYamlData
(
resPath
)
...
...
src/utils/const/const.go
浏览文件 @
20940883
...
...
@@ -50,9 +50,9 @@ var (
DefaultPort
=
8848
DefaultRoot
=
"./"
ResDirData
=
"data
/
"
ResDirYaml
=
"yaml
/
"
ResDirUsers
=
"users
/
"
ResDirData
=
"data"
ResDirYaml
=
"yaml"
ResDirUsers
=
"users"
TmpDir
=
"tmp/"
...
...
src/utils/file/file.go
浏览文件 @
20940883
...
...
@@ -153,33 +153,93 @@ func GetAbsDir(path string) string {
return
abs
}
func
ConvertResPath
(
path
string
)
(
resType
,
resFile
,
sheet
string
)
{
resName
:=
strings
.
ReplaceAll
(
path
,
"."
,
constant
.
PthSep
)
func
GetResProp
(
from
string
)
(
resFile
,
resType
,
sheet
string
)
{
// from resource
resPath
:=
AddRootPath
(
resName
)
+
".yaml"
if
FileExist
(
resPath
)
{
index
:=
strings
.
LastIndex
(
from
,
".yaml"
)
if
index
>
-
1
{
// yaml, ip.v1.yaml
resFile
=
convertYamlPath
(
from
)
resType
=
"yaml"
}
else
{
// excel, like address.cn.v1.china
resFile
,
sheet
=
convertExcelPath
(
from
)
resType
=
"excel"
}
if
resFile
==
""
{
resPath
:=
vari
.
ConfigDir
+
resFile
if
!
FileExist
(
resPath
)
{
// in same folder with passed config file
resPath
=
vari
.
WorkDir
+
resFile
if
!
FileExist
(
resPath
)
{
// in res file
resPath
=
""
}
}
resFile
=
resPath
}
}
else
{
resType
=
"excel"
return
}
func
convertYamlPath
(
from
string
)
(
ret
string
)
{
arr
:=
strings
.
Split
(
from
,
"."
)
for
i
:=
0
;
i
<
len
(
arr
);
i
++
{
dir
:=
""
if
i
>
0
{
dir
=
strings
.
Join
(
arr
[
:
i
],
constant
.
PthSep
)
}
file
:=
strings
.
Join
(
arr
[
i
:
],
"."
)
resFile
=
resName
+
".xlsx"
resFile
=
AddRootPath
(
resFile
)
if
FileExist
(
AddRootPath
(
resName
+
".xlsx"
))
{
// no sheet name
sheet
=
""
if
dir
!=
""
{
ret
=
dir
+
constant
.
PthSep
+
file
}
else
{
resFile
=
resName
[
:
strings
.
LastIndex
(
resName
,
constant
.
PthSep
)]
+
".xlsx"
resFile
=
AddRootPath
(
resFile
)
sheet
=
path
[
strings
.
LastIndex
(
resName
,
constant
.
PthSep
)
+
1
:
]
ret
=
file
}
realPth1
:=
vari
.
WorkDir
+
constant
.
ResDirYaml
+
constant
.
PthSep
+
ret
realPth2
:=
vari
.
WorkDir
+
constant
.
ResDirUsers
+
constant
.
PthSep
+
ret
if
FileExist
(
realPth1
)
{
ret
=
realPth1
break
}
else
if
FileExist
(
realPth2
)
{
ret
=
realPth2
break
}
}
return
}
func
AddRootPath
(
path
string
)
string
{
path
=
vari
.
WorkDir
+
"data"
+
constant
.
PthSep
+
path
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
.
ResDirData
+
constant
.
PthSep
+
ret
if
FileExist
(
realPth
)
{
if
index
==
1
{
sheet
=
from
[
strings
.
LastIndex
(
from
,
"."
)
+
1
:
]
}
ret
=
realPth
return
}
}
}
return
path
return
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录