提交 8e7f2a44 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

import data

上级 7f1b383d
......@@ -65,6 +65,8 @@ func GetDB() *gorm.DB {
&model.IdiomSimple{},
&model.PoetryAncient{},
&model.PoetryCategory{},
&model.Medicine{},
&model.Joke{},
)
if err != nil {
fmt.Printf(color.RedString("migrate models failed, error: %s.", err.Error()))
......
......@@ -25,9 +25,7 @@ func main() {
col1 := arr[0]
po := model.Advert{
DataComm: model.DataComm{
Name: col1,
},
Name: col1,
}
if po.Name != "" {
......
package main
import (
"encoding/json"
"fmt"
"github.com/easysoft/zendata/cmd/test/comm"
"github.com/easysoft/zendata/cmd/test/model"
fileUtils "github.com/easysoft/zendata/pkg/utils/file"
"strings"
)
func main() {
filePath := "/Users/aaron/work/zentao/product/zd/行业数据/笑话.json"
tableName := model.Joke{}.TableName()
db := comm.GetDB()
err := db.Exec(fmt.Sprintf(comm.TruncateTable, tableName)).Error
if err != nil {
panic(err)
}
content := fileUtils.ReadFileBuf(filePath)
arr := make([]string, 0)
json.Unmarshal(content, &arr)
for _, item := range arr {
item = strings.TrimSpace(item)
cate := model.Joke{
Content: item,
}
if cate.Content != "" {
db.Save(&cate)
}
}
}
package main
import (
"fmt"
"github.com/easysoft/zendata/cmd/test/comm"
"github.com/easysoft/zendata/cmd/test/model"
fileUtils "github.com/easysoft/zendata/pkg/utils/file"
"strings"
)
func main() {
filePath := "/Users/aaron/work/zentao/product/zd/行业数据/医学.txt"
tableName := model.Medicine{}.TableName()
db := comm.GetDB()
err := db.Exec(fmt.Sprintf(comm.TruncateTable, tableName)).Error
if err != nil {
panic(err)
}
content := fileUtils.ReadFile(filePath)
for _, line := range strings.Split(content, "\n") {
arr := strings.Split(strings.TrimSpace(line), " ")
col1 := arr[0]
po := model.Medicine{
Name: col1,
}
if po.Name != "" {
db.Save(&po)
}
}
}
......@@ -676,3 +676,21 @@ type PoetryCategory struct {
func (PoetryCategory) TableName() string {
return "biz_data_poetry_category"
}
type Medicine struct {
DataComm
Name string `json:"name"`
}
func (Medicine) TableName() string {
return "biz_data_medicine"
}
type Joke struct {
DataComm
Content string `json:"content"`
}
func (Joke) TableName() string {
return "biz_data_joke"
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册