123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- package main
- import (
- "app.yhyue.com/data_processing/common_utils/mongodb"
- "math"
- "sort"
- )
- //convertToMongoID convertToMongoID
- func convertToMongoID(query map[string]interface{}) map[string]interface{} {
- result := make(map[string]interface{})
- if query == nil {
- return result
- }
- idMap := query["_id"].(map[string]interface{})
- if idMap != nil {
- tmpQ := map[string]interface{}{}
- for c, id := range idMap {
- if idStr, ok := id.(string); ok && id != "" {
- tmpQ[c] = mongodb.StringTOBsonId(idStr)
- }
- }
- result["_id"] = tmpQ
- }
- return result
- }
- //StringSliceValuesEqual 判断切片相等
- func StringSliceValuesEqual(a, b []string) bool {
- if len(a) != len(b) {
- return false
- }
- sort.Strings(a)
- sort.Strings(b)
- for i := range a {
- if a[i] != b[i] {
- return false
- }
- }
- return true
- }
- //Float64SliceSum float64 数据求和
- func Float64SliceSum(nums []float64) float64 {
- sum := 0.0
- for _, num := range nums {
- sum += num
- }
- return sum
- }
- func Float64Equal1Precision(a, b float64) bool {
- return int(math.Round(a*10)) == int(math.Round(b*10))
- }
- //chargeType 判断mongo 字段类型和 es 字段类型相匹配
- func chargeType(ftype, etype string) bool {
- if ftype != "" {
- switch ftype {
- case "string":
- if etype == "keyword" || etype == "text" {
- return true
- } else {
- return false
- }
- case "bool":
- if etype == "boolean" {
- return true
- } else {
- return false
- }
- case "int64", "int32", "int":
- if etype == "long" || etype == "integer" {
- return true
- } else {
- return false
- }
- case "float64", "float32":
- if etype == "double" || etype == "float" {
- return true
- } else {
- return false
- }
- }
- }
- return false
- }
|