Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
LinuxSuRen
zendata
提交
22aec936
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 搜索 >>
提交
22aec936
编写于
5月 12, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add crc column
上级
0e35d947
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
156 addition
and
80 deletion
+156
-80
src/action/upgrade.go
src/action/upgrade.go
+11
-1
src/gen/excel.go
src/gen/excel.go
+67
-0
src/gen/list.go
src/gen/list.go
+2
-66
src/gen/text.go
src/gen/text.go
+74
-0
xdoc/data.yaml
xdoc/data.yaml
+2
-13
未找到文件。
src/action/upgrade.go
浏览文件 @
22aec936
...
...
@@ -8,6 +8,7 @@ import (
logUtils
"github.com/easysoft/zendata/src/utils/log"
numbUtils
"github.com/easysoft/zendata/src/utils/numb"
_
"github.com/mattn/go-sqlite3"
"hash/crc32"
"strconv"
)
...
...
@@ -32,7 +33,7 @@ func Upgrade() {
sheet
:=
"Sheet1"
excel
:=
excelize
.
NewFile
()
headerData
:=
[]
interface
{}{
"seq"
,
"name"
,
"state"
,
"zipCode"
,
"cityCode"
}
headerData
:=
[]
interface
{}{
"seq"
,
"name"
,
"state"
,
"zipCode"
,
"cityCode"
,
"crc"
}
colNumb
:=
AddExcelRow
(
excel
,
sheet
,
1
,
headerData
)
rowIndex
:=
1
...
...
@@ -86,11 +87,20 @@ func Upgrade() {
func
AddExcelRow
(
excel
*
excelize
.
File
,
sheet
string
,
rowIndex
int
,
cols
[]
interface
{})
string
{
start
:=
byte
(
'A'
)
var
numb
string
line
:=
""
for
index
,
col
:=
range
cols
{
numb
=
string
(
start
+
byte
(
index
))
colNumb
:=
numb
+
strconv
.
Itoa
(
rowIndex
)
excel
.
SetCellValue
(
sheet
,
colNumb
,
col
)
line
=
line
+
col
.
(
string
)
}
// 校验位
if
rowIndex
>
1
{
numb
=
string
(
start
+
byte
(
len
(
cols
)))
crcField
:=
crc32
.
ChecksumIEEE
([]
byte
(
line
))
excel
.
SetCellValue
(
sheet
,
numb
+
strconv
.
Itoa
(
rowIndex
),
crcField
)
}
return
numb
...
...
src/gen/excel.go
0 → 100644
浏览文件 @
22aec936
package
gen
import
(
"github.com/easysoft/zendata/src/model"
constant
"github.com/easysoft/zendata/src/utils/const"
"strconv"
"strings"
)
func
GenerateFieldValuesFromExcel
(
field
*
model
.
Field
,
fieldValue
*
model
.
FieldValue
,
level
int
)
{
// get file and step string
rang
:=
strings
.
TrimSpace
(
field
.
Range
)
sectionArr
:=
strings
.
Split
(
rang
,
":"
)
file
:=
sectionArr
[
0
]
stepStr
:=
"1"
if
len
(
sectionArr
)
==
2
{
stepStr
=
sectionArr
[
1
]
}
// read from file
list
:=
make
([]
string
,
0
)
relaPath
:=
constant
.
DataDir
+
file
list
=
strings
.
Split
(
"str"
+
relaPath
,
"
\n
"
)
// get step and rand
rand
:=
false
step
:=
1
if
strings
.
ToLower
(
strings
.
TrimSpace
(
stepStr
))
!=
"r"
{
stepInt
,
err
:=
strconv
.
Atoi
(
stepStr
)
if
err
==
nil
{
step
=
stepInt
}
}
else
{
rand
=
true
}
// get index for data retrieve
numbs
:=
GenerateIntItems
(
0
,
(
int64
)(
len
(
list
)
-
1
),
step
,
rand
)
// get data by index
index
:=
0
for
_
,
numb
:=
range
numbs
{
item
:=
list
[
numb
.
(
int64
)]
if
index
>=
constant
.
MaxNumb
{
break
}
if
strings
.
TrimSpace
(
item
)
==
""
{
continue
}
fieldValue
.
Values
=
append
(
fieldValue
.
Values
,
item
)
index
=
index
+
1
}
if
len
(
fieldValue
.
Values
)
==
0
{
fieldValue
.
Values
=
append
(
fieldValue
.
Values
,
"N/A"
)
}
}
func
ConvertExcelToSQLite
(
file
string
)
{
}
func
ReadDataSQLite
(
table
string
)
[]
string
{
list
:=
make
([]
string
,
0
)
return
list
}
\ No newline at end of file
src/gen/list.go
浏览文件 @
22aec936
...
...
@@ -3,9 +3,6 @@ package gen
import
(
"github.com/easysoft/zendata/src/model"
constant
"github.com/easysoft/zendata/src/utils/const"
logUtils
"github.com/easysoft/zendata/src/utils/log"
"io/ioutil"
"os"
"strconv"
"strings"
)
...
...
@@ -40,6 +37,8 @@ func GenerateFieldChildren(field *model.Field, fieldValue *model.FieldValue, lev
func
GenerateFieldValues
(
field
*
model
.
Field
,
fieldValue
*
model
.
FieldValue
,
level
int
)
{
if
strings
.
Index
(
field
.
Range
,
".txt"
)
>
-
1
{
GenerateFieldValuesFromText
(
field
,
fieldValue
,
level
)
}
else
if
strings
.
Index
(
field
.
Range
,
".xlsx"
)
>
-
1
{
GenerateFieldValuesFromExcel
(
field
,
fieldValue
,
level
)
}
else
{
GenerateFieldValuesFromList
(
field
,
fieldValue
,
level
)
}
...
...
@@ -98,69 +97,6 @@ func GenerateFieldValuesFromList(field *model.Field, fieldValue *model.FieldValu
}
}
func
GenerateFieldValuesFromText
(
field
*
model
.
Field
,
fieldValue
*
model
.
FieldValue
,
level
int
)
{
// get file and step string
rang
:=
strings
.
TrimSpace
(
field
.
Range
)
sectionArr
:=
strings
.
Split
(
rang
,
":"
)
file
:=
sectionArr
[
0
]
stepStr
:=
"1"
if
len
(
sectionArr
)
==
2
{
stepStr
=
sectionArr
[
1
]
}
// read from file
list
:=
make
([]
string
,
0
)
relaPath
:=
constant
.
ResDir
+
file
content
,
err
:=
ioutil
.
ReadFile
(
relaPath
)
if
err
!=
nil
{
logUtils
.
Screen
(
"fail to read "
+
relaPath
+
", try to use global config"
)
relaPath
=
"def"
+
string
(
os
.
PathSeparator
)
+
file
content
,
err
=
ioutil
.
ReadFile
(
relaPath
)
if
err
!=
nil
{
logUtils
.
Screen
(
"fail to read "
+
relaPath
+
", will return"
)
fieldValue
.
Values
=
append
(
fieldValue
.
Values
,
"N/A"
)
return
}
else
{
logUtils
.
Screen
(
"success to read "
+
relaPath
)
}
}
else
{
logUtils
.
Screen
(
"success to read "
+
relaPath
)
}
str
:=
string
(
content
)
str
=
strings
.
Replace
(
str
,
"
\\
r
\\
n"
,
"
\\
n"
,
-
1
)
list
=
strings
.
Split
(
str
,
"
\n
"
)
// get step and rand
rand
:=
false
step
:=
1
if
strings
.
ToLower
(
strings
.
TrimSpace
(
stepStr
))
!=
"r"
{
stepInt
,
err
:=
strconv
.
Atoi
(
stepStr
)
if
err
==
nil
{
step
=
stepInt
}
}
else
{
rand
=
true
}
// get index for data retrieve
numbs
:=
GenerateIntItems
(
0
,
(
int64
)(
len
(
list
)
-
1
),
step
,
rand
)
// get data by index
index
:=
0
for
_
,
numb
:=
range
numbs
{
item
:=
list
[
numb
.
(
int64
)]
if
index
>=
constant
.
MaxNumb
{
break
}
if
strings
.
TrimSpace
(
item
)
==
""
{
continue
}
fieldValue
.
Values
=
append
(
fieldValue
.
Values
,
item
)
index
=
index
+
1
}
if
len
(
fieldValue
.
Values
)
==
0
{
fieldValue
.
Values
=
append
(
fieldValue
.
Values
,
"N/A"
)
}
}
func
CheckRangeType
(
startStr
string
,
endStr
string
,
stepStr
string
)
(
string
,
interface
{},
int
,
bool
)
{
rand
:=
false
...
...
src/gen/text.go
0 → 100644
浏览文件 @
22aec936
package
gen
import
(
"github.com/easysoft/zendata/src/model"
constant
"github.com/easysoft/zendata/src/utils/const"
logUtils
"github.com/easysoft/zendata/src/utils/log"
"io/ioutil"
"os"
"strconv"
"strings"
)
func
GenerateFieldValuesFromText
(
field
*
model
.
Field
,
fieldValue
*
model
.
FieldValue
,
level
int
)
{
// get file and step string
rang
:=
strings
.
TrimSpace
(
field
.
Range
)
sectionArr
:=
strings
.
Split
(
rang
,
":"
)
file
:=
sectionArr
[
0
]
stepStr
:=
"1"
if
len
(
sectionArr
)
==
2
{
stepStr
=
sectionArr
[
1
]
}
// read from file
list
:=
make
([]
string
,
0
)
relaPath
:=
constant
.
ResDir
+
file
content
,
err
:=
ioutil
.
ReadFile
(
relaPath
)
if
err
!=
nil
{
logUtils
.
Screen
(
"fail to read "
+
relaPath
+
", try to use global config"
)
relaPath
=
"def"
+
string
(
os
.
PathSeparator
)
+
file
content
,
err
=
ioutil
.
ReadFile
(
relaPath
)
if
err
!=
nil
{
logUtils
.
Screen
(
"fail to read "
+
relaPath
+
", will return"
)
fieldValue
.
Values
=
append
(
fieldValue
.
Values
,
"N/A"
)
return
}
else
{
logUtils
.
Screen
(
"success to read "
+
relaPath
)
}
}
else
{
logUtils
.
Screen
(
"success to read "
+
relaPath
)
}
str
:=
string
(
content
)
str
=
strings
.
Replace
(
str
,
"
\\
r
\\
n"
,
"
\\
n"
,
-
1
)
list
=
strings
.
Split
(
str
,
"
\n
"
)
// get step and rand
rand
:=
false
step
:=
1
if
strings
.
ToLower
(
strings
.
TrimSpace
(
stepStr
))
!=
"r"
{
stepInt
,
err
:=
strconv
.
Atoi
(
stepStr
)
if
err
==
nil
{
step
=
stepInt
}
}
else
{
rand
=
true
}
// get index for data retrieve
numbs
:=
GenerateIntItems
(
0
,
(
int64
)(
len
(
list
)
-
1
),
step
,
rand
)
// get data by index
index
:=
0
for
_
,
numb
:=
range
numbs
{
item
:=
list
[
numb
.
(
int64
)]
if
index
>=
constant
.
MaxNumb
{
break
}
if
strings
.
TrimSpace
(
item
)
==
""
{
continue
}
fieldValue
.
Values
=
append
(
fieldValue
.
Values
,
item
)
index
=
index
+
1
}
if
len
(
fieldValue
.
Values
)
==
0
{
fieldValue
.
Values
=
append
(
fieldValue
.
Values
,
"N/A"
)
}
}
\ No newline at end of file
xdoc/data.yaml
浏览文件 @
22aec936
...
...
@@ -79,18 +79,7 @@ fields:
type
:
custom
range
:
custom.yaml
-
name
:
id
note
:
数字
type
:
list
range
:
1-10000
isNumb
:
true
-
name
:
field6
note
:
复合字段的某一个字段,指定查询条件。
type
:
user.name
range
:
age>10
-
name
:
field7
note
:
复合字段取多个字段。
type
:
user
range
:
age>10
format
:
$name-$age-$sex
type
:
address.city
range
:
select name from address_city where state like '%山东%'
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录