From 9c71c7b0229cdcd4d32f5f28deb771ac91c62d37 Mon Sep 17 00:00:00 2001 From: zcy <290198252@qq.com> Date: Sun, 25 Jul 2021 02:05:35 +0800 Subject: [PATCH] no message --- db/sqlManager.go | 1 + model/port.go | 18 ++---------------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/db/sqlManager.go b/db/sqlManager.go index 660cfd0..9697e6d 100644 --- a/db/sqlManager.go +++ b/db/sqlManager.go @@ -127,6 +127,7 @@ func InitELK() { } } + func initMysql(mysqlconf *config.MysqlConfig) *sql.DB { cnn := fmt.Sprintf("%s:%s@tcp(%s:3306)/%s?charset=utf8", mysqlconf.UserName, mysqlconf.Password, mysqlconf.Addr, mysqlconf.Db) diff --git a/model/port.go b/model/port.go index dca2687..10d0376 100644 --- a/model/port.go +++ b/model/port.go @@ -81,7 +81,7 @@ func InsertDocToElaticSearch(doc Doc) error { matchPhraseQuery := elastic.NewMatchQuery("title", doc.Title) existedHardware, e := QueryHardwares(matchPhraseQuery, 10, 0) log.Print(e, existedHardware) - + for _, v := range existedHardware { if v.Name == doc.Title { log.Print(v.ID) @@ -144,27 +144,13 @@ func PortDocumentToElasticsearch(tblname string) error { if nil != e { log.Print(e.Error()) } - insert, err := json.Marshal(ret) - if nil != err { - log.Print(err) - } - log.Print(len(ret)) - log.Print(string(insert)) - columns := []Field{} e = db.GetMysqlClient().Query2("describe "+tblname, &columns) if nil != e { logger.Debug(e.Error()) return e } - if existed, _ := db.GetElastic().IndexExisted(tblname); existed { - for _, v := range ret { - e := InsertDocToElaticSearch(v) - if nil != e { - log.Print(e.Error()) - } - } - } else { + if existed, _ := db.GetElastic().IndexExisted(tblname); !existed { props := map[string]interface{}{} mapping := map[string]interface{}{ "settings": map[string]interface{}{