package ent_util import ( "fmt" "go.mongodb.org/mongo-driver/bson/primitive" qu "jygit.jydev.jianyu360.cn/data_processing/common_utils" "runtime" "strconv" "strings" "unicode/utf8" ) type Info struct { Contact map[string]*Contact } type Contact struct { Per string Tel string Buyer bool Agency bool Winner bool Owner bool } // 处理地域代码 func CalculateRegionCode(area string, city string, district string) (area_code string, city_code string, district_code string) { area_code, city_code, district_code = "000000", "", "" if district != "" { key := area + "~" + city + "~" + district + "~" code := RegionCodeData[key] if code != "" { district_code = code city_code = code[:4] + "00" area_code = code[:2] + "0000" return } } if city != "" { key := area + "~" + city + "~" + "" + "~" code := RegionCodeData[key] if code != "" { city_code = code area_code = city_code[:2] + "0000" return } } if area != "" { key := area + "~" + "" + "~" + "" + "~" code := RegionCodeData[key] if code != "" { area_code = code return } } return } // 单位分割~去重 中标单位 func SegmentationEntName(name_1 string, name_2 string) ([]string, []bool) { new_arr := []string{} new_bool := []bool{} key_str := map[string]string{} if name_1 != "" { arr_1 := strings.Split(name_1, ",") if len(arr_1) == 1 { arr_1 = strings.Split(name_1, ",") } for _, v := range arr_1 { if v != "" && utf8.RuneCountInString(v) > 2 && utf8.RuneCountInString(v) < 30 { if key_str[v] == "" { new_arr = append(new_arr, v) key_str[v] = v new_bool = append(new_bool, true) } } } } if name_2 != "" { arr_2 := strings.Split(name_2, ",") if len(arr_2) == 1 { arr_2 = strings.Split(name_2, ",") } for _, v := range arr_2 { if v != "" && utf8.RuneCountInString(v) > 2 && utf8.RuneCountInString(v) < 30 { if key_str[v] == "" { new_arr = append(new_arr, v) key_str[v] = v new_bool = append(new_bool, false) } } } } return new_arr, new_bool } // 转二进制 func Str2DEC(s string) (num int) { l := len(s) for i := l - 1; i >= 0; i-- { num += (int(s[l-i-1]) & 0xf) << uint8(i) } return } func ConvertToBin(num int) string { s := "" if num == 0 { return "0" } for ; num > 0; num /= 2 { lsb := num % 2 s = strconv.Itoa(lsb) + s } return s } func toMegaBytes(bytes uint64) float64 { return float64(bytes) / 1024 / 1024 } func traceMemStats() { var ms runtime.MemStats runtime.ReadMemStats(&ms) var result = make([]float64, 7) result[0] = float64(ms.HeapObjects) result[1] = toMegaBytes(ms.HeapAlloc) result[2] = toMegaBytes(ms.TotalAlloc) result[3] = toMegaBytes(ms.HeapSys) result[4] = toMegaBytes(ms.HeapIdle) result[5] = toMegaBytes(ms.HeapReleased) result[6] = toMegaBytes(ms.HeapIdle - ms.HeapReleased) for _, v := range result { fmt.Printf("%.2f\t", v) } fmt.Printf("\n") } func IsMarkInterfaceArr(t interface{}) []string { sub_list := []string{} if list_3, ok_3 := t.([]string); ok_3 { sub_list = list_3 return sub_list } if list_1, ok_1 := t.(primitive.A); ok_1 { sub_list = qu.ObjArrToStringArr(list_1) } else { if list_2, ok_2 := t.([]interface{}); ok_2 { sub_list = qu.ObjArrToStringArr(list_2) } } return sub_list }