github.com/easysoft/zendata@v0.0.0-20240513203326-705bd5a7fd67/cmd/test/others/func/import/bank.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  	"github.com/easysoft/zendata/cmd/test/others/func/comm"
    12  	"github.com/easysoft/zendata/cmd/test/others/func/model"
    13  	fileUtils "github.com/easysoft/zendata/pkg/utils/file"
    14  )
    15  
    16  func main() {
    17  	filePath := "/Users/aaron/work/zentao/product/zd/行业数据/银行.txt"
    18  
    19  	tableName := model.Bank{}.TableName()
    20  	db := comm.GetDB()
    21  	err := db.Exec(fmt.Sprintf(comm.TruncateTable, tableName)).Error
    22  	if err != nil {
    23  		panic(err)
    24  	}
    25  
    26  	content := fileUtils.ReadFile(filePath)
    27  
    28  	for _, line := range strings.Split(content, "\n") {
    29  		arr := strings.Split(strings.TrimSpace(line), " ")
    30  		col1 := arr[0]
    31  
    32  		po := model.Bank{
    33  			DataComm: model.DataComm{
    34  				Name: col1,
    35  			},
    36  		}
    37  
    38  		if po.Name != "" {
    39  			db.Save(&po)
    40  		}
    41  	}
    42  }