|
@@ -1,5 +1,14 @@
|
|
|
package services
|
|
|
|
|
|
+import (
|
|
|
+ "context"
|
|
|
+ "eta/eta_forum_admin/models/mgodb"
|
|
|
+ "eta/eta_forum_admin/utils"
|
|
|
+ "fmt"
|
|
|
+
|
|
|
+ "github.com/olivere/elastic/v7"
|
|
|
+)
|
|
|
+
|
|
|
/*func GetCompanyNameByAdmins(adminIds []int) (adminCompanyMap map[int]string, err error) {
|
|
|
// 查询所有机构
|
|
|
ob := new(system.EtaBusiness)
|
|
@@ -36,3 +45,62 @@ package services
|
|
|
}
|
|
|
return
|
|
|
}*/
|
|
|
+
|
|
|
+// 写一个初始化的方法清空所有的es数据,表数据,mongodb数据
|
|
|
+func InitDeleteData() {
|
|
|
+ // 清空es数据
|
|
|
+ var err error
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println("EsDeleteEdbInfoData Err:", err.Error())
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ client := utils.EsClient
|
|
|
+ // 删除索引下的所有数据
|
|
|
+ deleteQuery := elastic.NewMatchAllQuery()
|
|
|
+
|
|
|
+ // 删除图表索引数据
|
|
|
+ _, err = client.DeleteByQuery().
|
|
|
+ Index(utils.CHART_INDEX_NAME).
|
|
|
+ Query(deleteQuery).
|
|
|
+ Refresh("true"). // 添加刷新使操作立即生效
|
|
|
+ Do(context.Background())
|
|
|
+ if err != nil {
|
|
|
+ fmt.Printf("删除图表索引(%s)失败: %v\n", utils.CHART_INDEX_NAME, err)
|
|
|
+ err = nil // 清空错误继续执行后续清理
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除指标索引数据
|
|
|
+ _, err = client.DeleteByQuery().
|
|
|
+ Index(utils.DATA_INDEX_NAME).
|
|
|
+ Query(deleteQuery).
|
|
|
+ Refresh("true").
|
|
|
+ Do(context.Background())
|
|
|
+ if err != nil {
|
|
|
+ fmt.Printf("删除指标索引(%s)失败: %v\n", utils.DATA_INDEX_NAME, err)
|
|
|
+ err = nil
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除收藏索引数据
|
|
|
+ _, err = client.DeleteByQuery().
|
|
|
+ Index(utils.CHART_COLLECT_INDEX_NAME).
|
|
|
+ Query(deleteQuery).
|
|
|
+ Refresh("true").
|
|
|
+ Do(context.Background())
|
|
|
+ if err != nil {
|
|
|
+ fmt.Printf("删除收藏索引(%s)失败: %v\n", utils.CHART_COLLECT_INDEX_NAME, err)
|
|
|
+ err = nil
|
|
|
+ }
|
|
|
+ fmt.Println("删除es数据成功")
|
|
|
+ // 删除mongodb数据
|
|
|
+ err = mgodb.DeleteEdbInfoBaseDataAll()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ err = mgodb.DeleteEdbInfoCalculateDataAll()
|
|
|
+ if err != nil {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ fmt.Println("删除mongodb数据成功")
|
|
|
+
|
|
|
+}
|