github.com/easysoft/zendata@v0.0.0-20240513203326-705bd5a7fd67/cmd/test/others/func/import/place.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.Place{}.TableName()
    16  
    17  	db := comm.GetDB()
    18  	err := db.Exec(fmt.Sprintf(comm.TruncateTable, tableName)).Error
    19  	if err != nil {
    20  		panic(err)
    21  	}
    22  
    23  	content := fileUtils.ReadFile(filePath)
    24  
    25  	for _, line := range strings.Split(content, "\r") {
    26  		arr := strings.Split(strings.TrimSpace(line), " ")
    27  		col1 := arr[0]
    28  
    29  		po := model.Place{
    30  			Name: col1,
    31  		}
    32  
    33  		if po.Name != "" {
    34  			db.Save(&po)
    35  		}
    36  	}
    37  }