github.com/easysoft/zendata@v0.0.0-20240513203326-705bd5a7fd67/cmd/test/others/func/import/advert.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/easysoft/zendata/cmd/test/others/func/comm" 8 "github.com/easysoft/zendata/cmd/test/others/func/model" 9 fileUtils "github.com/easysoft/zendata/pkg/utils/file" 10 ) 11 12 func main() { 13 filePath := "/Users/aaron/work/zentao/product/zd/行业数据/广告.txt" 14 15 tableName := model.Advert{}.TableName() 16 db := comm.GetDB() 17 err := db.Exec(fmt.Sprintf(comm.TruncateTable, tableName)).Error 18 if err != nil { 19 panic(err) 20 } 21 22 content := fileUtils.ReadFile(filePath) 23 24 for _, line := range strings.Split(content, "\n") { 25 arr := strings.Split(strings.TrimSpace(line), " ") 26 col1 := arr[0] 27 28 po := model.Advert{ 29 Name: col1, 30 } 31 32 if po.Name != "" { 33 db.Save(&po) 34 } 35 } 36 }