Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zendata
提交
f28b92d7
Z
zendata
项目概览
易企天创
/
zendata
10 个月 前同步成功
通知
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 搜索 >>
提交
f28b92d7
编写于
7月 15, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
new features for 1.1
上级
b90cb89a
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
124 addition
and
59 deletion
+124
-59
res/messages_en.json
res/messages_en.json
+8
-0
res/messages_zh.json
res/messages_zh.json
+8
-0
src/service/view.go
src/service/view.go
+81
-52
src/utils/file/file.go
src/utils/file/file.go
+27
-7
未找到文件。
res/messages_en.json
浏览文件 @
f28b92d7
...
...
@@ -96,6 +96,14 @@
{
"id"
:
"excel_data"
,
"translation"
:
"Excel Data."
},
{
"id"
:
"excel_data_1"
,
"translation"
:
"Excel that contains below sheet."
},
{
"id"
:
"excel_data_1"
,
"translation"
:
"Excel that contains below data."
}
]
}
\ No newline at end of file
res/messages_zh.json
浏览文件 @
f28b92d7
...
...
@@ -87,6 +87,14 @@
{
"id"
:
"excel_data"
,
"translation"
:
"Excel数据源。"
},
{
"id"
:
"excel_data_1"
,
"translation"
:
"Excel数据源,包含以下表格."
},
{
"id"
:
"excel_data_1"
,
"translation"
:
"Excel数据源,包含以下内容."
}
]
}
\ No newline at end of file
src/service/view.go
浏览文件 @
f28b92d7
...
...
@@ -2,12 +2,11 @@ package service
import
(
"fmt"
"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"
"github.com/mattn/go-runewidth"
"gopkg.in/yaml.v3"
"io/ioutil"
...
...
@@ -15,9 +14,7 @@ import (
)
func
ViewRes
(
res
string
)
{
msg
:=
""
resType
,
resPath
:=
fileUtils
.
ConvertResPath
(
res
)
resType
,
resPath
,
sheet
:=
fileUtils
.
ConvertResPath
(
res
)
if
resType
==
"yaml"
{
typ
,
inst
,
ranges
:=
readYamlData
(
resPath
)
...
...
@@ -27,18 +24,11 @@ func ViewRes(res string) {
printRanges
(
ranges
)
}
}
else
if
resType
==
"excel"
{
printExcelSheet
(
resPath
,
sheet
)
}
logUtils
.
Screen
(
msg
)
}
func
readYamlData
(
path
string
)
(
typ
string
,
insts
model
.
ResInsts
,
ranges
model
.
ResRanges
)
{
if
strings
.
Index
(
path
,
"system"
)
>
-
1
{
path
=
vari
.
ExeDir
+
"data"
+
constant
.
PthSep
+
path
}
else
{
path
=
vari
.
ExeDir
+
constant
.
PthSep
+
path
}
yamlContent
,
err
:=
ioutil
.
ReadFile
(
path
)
if
err
!=
nil
{
logUtils
.
Screen
(
i118Utils
.
I118Prt
.
Sprintf
(
"fail_to_read_file"
,
path
))
...
...
@@ -56,42 +46,6 @@ func readYamlData(path string) (typ string, insts model.ResInsts, ranges model.R
return
}
func
readExcelSheet
(
path
string
)
(
str
string
)
{
//excel, err := excelize.OpenFile(path)
//if err != nil {
// logUtils.Screen(i118Utils.I118Prt.Sprintf("fail_to_read_file", path))
// return
//}
//
//for index, sheet := range excel.GetSheetList() {
// if index > 0 {
// title = title + "|"
// }
// title = title + sheet
//}
//
//desc = i118Utils.I118Prt.Sprintf("excel_data")
return
}
func
readExcelData
(
path
string
)
(
str
string
)
{
//excel, err := excelize.OpenFile(path)
//if err != nil {
// logUtils.Screen(i118Utils.I118Prt.Sprintf("fail_to_read_file", path))
// return
//}
//
//for index, sheet := range excel.GetSheetList() {
// if index > 0 {
// title = title + "|"
// }
// title = title + sheet
//}
//
//desc = i118Utils.I118Prt.Sprintf("excel_data")
return
}
func
printInst
(
inst
model
.
ResInsts
)
{
msg
:=
""
msg
=
msg
+
inst
.
Title
+
" "
+
inst
.
Desc
+
"
\n
"
...
...
@@ -107,7 +61,7 @@ func printInst(inst model.ResInsts) {
for
idx
,
item
:=
range
inst
.
Instances
{
if
idx
>
0
{
msg
=
msg
+
"
\n
"
}
msg
=
msg
+
fmt
.
Sprintf
(
"%d. %s - %s"
,
idx
+
1
,
item
.
Instance
+
strings
.
Repeat
(
" "
,
width
-
len
(
item
.
Instance
)),
item
.
Note
)
idx
+
1
,
item
.
Instance
+
strings
.
Repeat
(
" "
,
width
-
runewidth
.
StringWidth
(
item
.
Instance
)),
item
.
Note
)
}
logUtils
.
Screen
(
msg
)
...
...
@@ -128,11 +82,86 @@ func printRanges(ranges model.ResRanges) {
i
:=
0
for
name
,
item
:=
range
ranges
.
Ranges
{
if
i
>
0
{
msg
=
msg
+
"
\n
"
}
msg
=
msg
+
fmt
.
Sprintf
(
"%d. %s - %s"
,
i
+
1
,
name
+
strings
.
Repeat
(
" "
,
width
-
len
(
name
)),
item
)
msg
=
msg
+
fmt
.
Sprintf
(
"%d. %s - %s"
,
i
+
1
,
name
+
strings
.
Repeat
(
" "
,
width
-
runewidth
.
StringWidth
(
name
)),
item
)
i
++
}
logUtils
.
Screen
(
msg
)
}
\ No newline at end of file
}
func
printExcelSheet
(
path
,
sheetName
string
)
{
excel
,
err
:=
excelize
.
OpenFile
(
path
)
if
err
!=
nil
{
logUtils
.
Screen
(
i118Utils
.
I118Prt
.
Sprintf
(
"fail_to_read_file"
,
path
))
return
}
msg
:=
i118Utils
.
I118Prt
.
Sprintf
(
"excel_data_1"
)
+
"
\n
"
if
sheetName
==
""
{
for
index
,
sheet
:=
range
excel
.
GetSheetList
()
{
msg
=
msg
+
fmt
.
Sprintf
(
"%d. %s"
,
index
+
1
,
sheet
)
+
"
\n
"
}
}
logUtils
.
Screen
(
msg
)
if
sheetName
!=
""
{
for
_
,
sheet
:=
range
excel
.
GetSheetList
()
{
if
sheet
!=
sheetName
{
continue
}
widthArr
:=
make
([]
int
,
0
)
dataArr
:=
make
([][]
string
,
0
)
dataArr
=
append
(
dataArr
,
make
([]
string
,
0
))
rows
,
_
:=
excel
.
GetRows
(
sheet
)
colCount
:=
0
for
index
,
row
:=
range
rows
{
if
index
>=
10
{
break
}
if
index
==
0
{
// deal with the title
for
_
,
col
:=
range
rows
[
index
]
{
val
:=
strings
.
TrimSpace
(
col
)
if
val
==
""
{
break
}
widthArr
=
append
(
widthArr
,
runewidth
.
StringWidth
(
val
))
dataArr
[
0
]
=
append
(
dataArr
[
0
],
val
)
colCount
++
}
}
else
{
colArr
:=
make
([]
string
,
0
)
for
idx
,
col
:=
range
row
{
if
idx
>=
colCount
{
break
}
val
:=
strings
.
TrimSpace
(
col
)
lent
:=
runewidth
.
StringWidth
(
val
)
if
widthArr
[
idx
]
<
lent
{
widthArr
[
idx
]
=
lent
}
colArr
=
append
(
colArr
,
val
)
}
dataArr
=
append
(
dataArr
,
colArr
)
}
}
for
_
,
row
:=
range
dataArr
{
line
:=
""
for
colIdx
,
col
:=
range
row
{
if
colIdx
>=
colCount
{
break
}
space
:=
widthArr
[
colIdx
]
-
runewidth
.
StringWidth
(
col
)
line
=
line
+
col
+
strings
.
Repeat
(
" "
,
space
)
+
" "
}
logUtils
.
Screen
(
line
)
}
}
}
}
src/utils/file/file.go
浏览文件 @
f28b92d7
...
...
@@ -242,7 +242,7 @@ func GetAbsDir(path string) string {
return
abs
}
func
ConvertResPath
(
path
string
)
(
resType
,
resFile
string
)
{
func
ConvertResPath
(
path
string
)
(
resType
,
resFile
,
sheet
string
)
{
index
:=
strings
.
LastIndex
(
path
,
".yaml"
)
if
index
>
-
1
{
// yaml, system.ip.v1.yaml
left
:=
path
[
:
index
]
...
...
@@ -250,15 +250,35 @@ func ConvertResPath(path string) (resType, resFile string) {
resFile
=
left
+
".yaml"
resType
=
"yaml"
}
else
{
// excel, system.address.v1.city
index
=
strings
.
LastIndex
(
path
,
"."
)
}
else
{
// excel, system.address.v1
//index = strings.LastIndex(path, ".")
//left := path[:index]
//left = strings.ReplaceAll(left, ".", constant.PthSep)
//resFile = left + ".xlsx"
resType
=
"excel"
left
:=
path
[
:
index
]
left
=
strings
.
ReplaceAll
(
left
,
"."
,
constant
.
PthSep
)
resFile
=
strings
.
ReplaceAll
(
path
,
"."
,
constant
.
PthSep
)
+
".xlsx"
}
resFile
=
left
+
".xlsx"
resType
=
"excel"
resFile
=
AddRootPath
(
resFile
)
// excel file including sheet name like system.address.v1.china
if
resType
==
"excel"
&&
!
FileExist
(
resFile
)
{
path
=
strings
.
ReplaceAll
(
path
,
"."
,
constant
.
PthSep
)
resFile
=
path
[
:
strings
.
LastIndex
(
path
,
constant
.
PthSep
)]
+
".xlsx"
resFile
=
AddRootPath
(
resFile
)
sheet
=
path
[
strings
.
LastIndex
(
path
,
constant
.
PthSep
)
+
1
:
]
}
return
}
func
AddRootPath
(
path
string
)
string
{
if
strings
.
Index
(
path
,
"system"
)
>
-
1
{
path
=
vari
.
ExeDir
+
"data"
+
constant
.
PthSep
+
path
}
else
{
path
=
vari
.
ExeDir
+
constant
.
PthSep
+
path
}
return
path
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录