Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zendata
提交
0ebea09e
Z
zendata
项目概览
易企天创
/
zendata
9 个月 前同步成功
通知
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 搜索 >>
提交
0ebea09e
编写于
5月 09, 2022
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
import data from excel
上级
1710d1f8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
43 addition
and
2 deletion
+43
-2
src/test/import/comm/dao.go
src/test/import/comm/dao.go
+6
-2
src/test/import/import-country.go
src/test/import/import-country.go
+30
-0
src/test/import/model/model.go
src/test/import/model/model.go
+1
-0
src/utils/string/string.go
src/utils/string/string.go
+6
-0
未找到文件。
src/test/import/comm/dao.go
浏览文件 @
0ebea09e
...
...
@@ -6,6 +6,7 @@ import (
"github.com/fatih/color"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"gorm.io/plugin/dbresolver"
"time"
)
...
...
@@ -44,7 +45,7 @@ func GetDB() *gorm.DB {
&
model
.
DataCity
{},
&
model
.
DataColor
{},
&
model
.
DataCo
lor
{},
&
model
.
DataCo
untry
{},
&
model
.
DataChineseFamily
{},
&
model
.
DataChineseGiven
{},
&
model
.
DataEnglishFamily
{},
...
...
@@ -68,7 +69,10 @@ func GormMySQL() *gorm.DB {
DontSupportRenameColumn
:
true
,
// 用 `change` 重命名列,MySQL 8 之前的数据库和 MariaDB 不支持重命名列
SkipInitializeWithVersion
:
false
,
// 根据版本自动配置
}
if
db
,
err
:=
gorm
.
Open
(
mysql
.
New
(
mysqlConfig
));
err
!=
nil
{
if
db
,
err
:=
gorm
.
Open
(
mysql
.
New
(
mysqlConfig
),
&
gorm
.
Config
{
Logger
:
logger
.
Default
.
LogMode
(
logger
.
Info
),
});
err
!=
nil
{
return
nil
}
else
{
sqlDB
,
_
:=
db
.
DB
()
...
...
src/test/import/import-country.go
0 → 100644
浏览文件 @
0ebea09e
package
main
import
(
"github.com/easysoft/zendata/src/test/import/comm"
"github.com/easysoft/zendata/src/test/import/model"
stringUtils
"github.com/easysoft/zendata/src/utils/string"
)
func
main
()
{
filePath
:=
"data/country/v1.xlsx"
sheetName
:=
"country"
db
:=
comm
.
GetDB
()
records
:=
comm
.
GetExcelTable
(
filePath
,
sheetName
)
for
_
,
record
:=
range
records
{
po
:=
model
.
DataCountry
{
ContinentId
:
stringUtils
.
ParseInt
(
record
[
"continent_id"
]
.
(
string
)),
Continent
:
record
[
"continent"
]
.
(
string
),
AreaCode
:
record
[
"areacode"
]
.
(
string
),
EnglishShort
:
record
[
"enshort"
]
.
(
string
),
EnglishFull
:
record
[
"enfull"
]
.
(
string
),
ChineseShort
:
record
[
"cnshort"
]
.
(
string
),
ChineseFull
:
record
[
"cnfull"
]
.
(
string
),
}
db
.
Save
(
&
po
)
}
}
src/test/import/model/model.go
浏览文件 @
0ebea09e
...
...
@@ -38,6 +38,7 @@ type BaseModel struct {
type
DataCountry
struct
{
BaseModel
ContinentId
int
`json:"continentId"`
Continent
string
`json:"continent"`
AreaCode
string
`json:"areaCode"`
EnglishShort
string
`json:"englishShort"`
...
...
src/utils/string/string.go
浏览文件 @
0ebea09e
...
...
@@ -288,3 +288,9 @@ func ConvertYamlStringToMapFormat(bytes []byte) (ret string) {
//}
return
}
func
ParseInt
(
str
string
)
(
ret
int
)
{
ret
,
_
=
strconv
.
Atoi
(
str
)
return
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录