Browse Source

fix:更新所有的es

Roc 1 year ago
parent
commit
0ae8b89d10
3 changed files with 22 additions and 0 deletions
  1. 4 0
      controllers/base_from_baiinfo.go
  2. 11 0
      logic/edbinfo.go
  3. 7 0
      models/edb_info.go

+ 4 - 0
controllers/base_from_baiinfo.go

@@ -158,3 +158,7 @@ func (this *BaiinfoController) HandleExcelData() {
 	br.Success = true
 	br.Msg = "处理成功"
 }
+
+func init() {
+	logic.UpdateAllEdbInfoEs()
+}

+ 11 - 0
logic/edbinfo.go

@@ -1,6 +1,7 @@
 package logic
 
 import (
+	"fmt"
 	"hongze/hongze_edb_lib/models"
 	"hongze/hongze_edb_lib/services/elastic"
 	"hongze/hongze_edb_lib/utils"
@@ -13,3 +14,13 @@ func UpdateEs(edbInfoId int) {
 	itemInfo, _ := models.GetEdbInfoItemByCondition("AND edb_info_id=?", []interface{}{edbInfoId})
 	elastic.EsAddOrEditEdbInfoData(utils.DATA_INDEX_NAME, strconv.Itoa(itemInfo.EdbInfoId), itemInfo)
 }
+
+// UpdateAllEdbInfoEs 更新所有的指标ES的信息
+func UpdateAllEdbInfoEs() {
+	//添加es
+	list, _ := models.GetEdbInfoItemListByCondition()
+	for _, itemInfo := range list {
+		elastic.EsAddOrEditEdbInfoData(utils.DATA_INDEX_NAME, strconv.Itoa(itemInfo.EdbInfoId), itemInfo)
+	}
+	fmt.Println("修复完成")
+}

+ 7 - 0
models/edb_info.go

@@ -945,6 +945,13 @@ func GetEdbInfoItemByCondition(condition string, pars []interface{}) (item *EdbI
 	return
 }
 
+func GetEdbInfoItemListByCondition() (items []*EdbInfoList, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM edb_info WHERE 1=1 `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
 // EdbInfoDetailReq 指标详情请求
 type EdbInfoDetailReq struct {
 	UniqueCode string `description:"指标唯一编码"`