|
@@ -1,21 +1,21 @@
|
|
|
package util
|
|
|
|
|
|
import (
|
|
|
+ "app.yhyue.com/moapp/jybase/common"
|
|
|
+ "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
+ elastic "app.yhyue.com/moapp/jybase/es"
|
|
|
+ "app.yhyue.com/moapp/jybase/log"
|
|
|
"cmplatform/models"
|
|
|
sql "cmplatform/util/sqlmodel"
|
|
|
"context"
|
|
|
"encoding/json"
|
|
|
"errors"
|
|
|
"fmt"
|
|
|
- "log"
|
|
|
+ "go.mongodb.org/mongo-driver/bson"
|
|
|
+ "go.uber.org/zap"
|
|
|
"regexp"
|
|
|
"strings"
|
|
|
"time"
|
|
|
-
|
|
|
- "app.yhyue.com/moapp/jybase/common"
|
|
|
- "app.yhyue.com/moapp/jybase/encrypt"
|
|
|
- elastic "app.yhyue.com/moapp/jybase/es"
|
|
|
- "go.mongodb.org/mongo-driver/bson"
|
|
|
)
|
|
|
|
|
|
const (
|
|
@@ -205,8 +205,8 @@ func searchData(index, esquery, sdataid string, i_maxnum int64, tags map[string]
|
|
|
searchResult, err := client.Search(index).Query(cc).Size(int(i_maxnum)).Do(ctx)
|
|
|
if err == nil && searchResult.Hits != nil {
|
|
|
datas := make([]map[string]interface{}, 0)
|
|
|
- log.Println("es查询到的数量:", searchResult.Hits.TotalHits.Value)
|
|
|
- log.Println("es查询数据数量:", len(searchResult.Hits.Hits))
|
|
|
+ log.Info(fmt.Sprintf("es查询到的数量:%d", searchResult.Hits.TotalHits.Value))
|
|
|
+ log.Info(fmt.Sprintf("es查询数据数量:%d", len(searchResult.Hits.Hits)))
|
|
|
for _, v := range searchResult.Hits.Hits {
|
|
|
item := make(map[string]interface{})
|
|
|
if json.Unmarshal(v.Source, &item) == nil {
|
|
@@ -298,14 +298,14 @@ func searchData(index, esquery, sdataid string, i_maxnum int64, tags map[string]
|
|
|
}
|
|
|
}
|
|
|
counts := Es.Count(index, Itype, esquery)
|
|
|
- log.Println("esCount查询的数据量 ", counts)
|
|
|
+ log.Info(fmt.Sprintf("esCount查询的数据量 %d", counts))
|
|
|
Mgo.Update("cuserdepartrule", bson.M{"_id": tags["_id"]}, bson.M{
|
|
|
"$set": bson.M{
|
|
|
"i_estotal": counts,
|
|
|
}}, false, false)
|
|
|
return UtilEsSaveData(sdataid, index, &datas), counts
|
|
|
} else {
|
|
|
- log.Println("err", err)
|
|
|
+ log.Error("err", zap.Error(err))
|
|
|
return err, 0
|
|
|
}
|
|
|
}
|
|
@@ -346,7 +346,7 @@ func FilterTimeSql(esquery string, startTime, endTime int64) (string, error) {
|
|
|
if err == nil {
|
|
|
return string(strQuery), nil
|
|
|
} else {
|
|
|
- log.Println("失败", err)
|
|
|
+ log.Error("失败", zap.Error(err))
|
|
|
return esquery, err
|
|
|
}
|
|
|
} else {
|
|
@@ -356,7 +356,7 @@ func FilterTimeSql(esquery string, startTime, endTime int64) (string, error) {
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- log.Println(json.Unmarshal([]byte(esquery), &query), "err")
|
|
|
+ log.Error("err", zap.Error(json.Unmarshal([]byte(esquery), &query)))
|
|
|
return esquery, errors.New("err")
|
|
|
}
|
|
|
return esquery, nil
|
|
@@ -403,7 +403,7 @@ func UtilEsFind2(tags map[string]interface{}, n int) (error, int64) {
|
|
|
//}
|
|
|
// 获取分隔区间
|
|
|
timeList := GetTimeInterval(time.Unix(common.Int64All(tags["i_starttime"]), 0), time.Unix(common.Int64All(tags["i_endtime"]), 0), n)
|
|
|
- log.Println(timeList, "分隔后的时间===================")
|
|
|
+ log.Info("分隔后的时间===================", zap.Any("", timeList))
|
|
|
esQueryList := []string{}
|
|
|
//esquery = esquery[:len(esquery)-1] + `,"size":` + fmt.Sprintf("%d", i_maxnum) + `}`
|
|
|
// log.Println(esquery)
|
|
@@ -423,7 +423,7 @@ func UtilEsFind2(tags map[string]interface{}, n int) (error, int64) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- log.Println("timeList================", timeList)
|
|
|
+ log.Info("timeList================", zap.Any("", timeList))
|
|
|
// 生成新的es语句
|
|
|
for _, v := range timeList {
|
|
|
tmpRange_ := bson.M{
|
|
@@ -445,36 +445,36 @@ func UtilEsFind2(tags map[string]interface{}, n int) (error, int64) {
|
|
|
esQuery := string(strQuery)
|
|
|
esQueryList = append(esQueryList, esQuery)
|
|
|
} else {
|
|
|
- log.Println("失败", err)
|
|
|
+ log.Error("失败", zap.Error(err))
|
|
|
return err, 0
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- log.Println(json.Unmarshal([]byte(esquery), &query), "err")
|
|
|
+ log.Error("err", zap.Error(json.Unmarshal([]byte(esquery), &query)))
|
|
|
}
|
|
|
// for _, v := range esQueryList {
|
|
|
// log.Println("es语句", v)
|
|
|
// }
|
|
|
- log.Println("重新生成的es语句", esQueryList)
|
|
|
+ log.Info("重新生成的es语句", zap.Any("", esQueryList))
|
|
|
var totalCount int64
|
|
|
datas := make([]map[string]interface{}, 0)
|
|
|
for _, esSql := range esQueryList {
|
|
|
// 查询
|
|
|
esSql = esSql[:len(esSql)-1] + `,"size":` + fmt.Sprintf("%d", i_maxnum) + `}`
|
|
|
- log.Println("本次查询==", esSql)
|
|
|
+ log.Info("本次查询==" + esSql)
|
|
|
index := EsIndex
|
|
|
if strings.Contains(esSql, "site") { //选择网站名称,使用全量数据索引
|
|
|
index = EsAllIndex
|
|
|
}
|
|
|
- log.Println("es索引-------------------- ", index)
|
|
|
+ log.Info("es索引-------------------- " + index)
|
|
|
cc := &MySource{
|
|
|
Querys: esSql,
|
|
|
}
|
|
|
searchResult, err := client.Search(index).Query(cc).Do(ctx)
|
|
|
if err == nil && searchResult.Hits != nil {
|
|
|
- log.Println("es查询到的数量:", searchResult.Hits.TotalHits)
|
|
|
- log.Println("开始处理")
|
|
|
+ log.Info("es查询到的数量:", zap.Int64("", searchResult.Hits.TotalHits.Value))
|
|
|
+ log.Info("开始处理")
|
|
|
|
|
|
for _, v := range searchResult.Hits.Hits {
|
|
|
item := make(map[string]interface{})
|
|
@@ -579,12 +579,12 @@ func UtilEsFind2(tags map[string]interface{}, n int) (error, int64) {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
- log.Println("处理完成", len(datas))
|
|
|
+ log.Info("处理完成", zap.Int("count", len(datas)))
|
|
|
|
|
|
count := searchResult.Hits.TotalHits.Value
|
|
|
totalCount += count
|
|
|
} else {
|
|
|
- log.Println(err)
|
|
|
+ log.Error("err", zap.Error(err))
|
|
|
return err, 0
|
|
|
}
|
|
|
}
|