info.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package ent_util
  2. import (
  3. "fmt"
  4. "go.mongodb.org/mongo-driver/bson/primitive"
  5. qu "jygit.jydev.jianyu360.cn/data_processing/common_utils"
  6. "runtime"
  7. "strconv"
  8. "strings"
  9. "unicode/utf8"
  10. )
  11. type Info struct {
  12. Contact map[string]*Contact
  13. }
  14. type Contact struct {
  15. Per string
  16. Tel string
  17. Buyer bool
  18. Agency bool
  19. Winner bool
  20. Owner bool
  21. }
  22. // 处理地域代码
  23. func CalculateRegionCode(area string, city string, district string) (area_code string, city_code string, district_code string) {
  24. area_code, city_code, district_code = "000000", "", ""
  25. if district != "" {
  26. key := area + "~" + city + "~" + district + "~"
  27. code := RegionCodeData[key]
  28. if code != "" {
  29. district_code = code
  30. city_code = code[:4] + "00"
  31. area_code = code[:2] + "0000"
  32. return
  33. }
  34. }
  35. if city != "" {
  36. key := area + "~" + city + "~" + "" + "~"
  37. code := RegionCodeData[key]
  38. if code != "" {
  39. city_code = code
  40. area_code = city_code[:2] + "0000"
  41. return
  42. }
  43. }
  44. if area != "" {
  45. key := area + "~" + "" + "~" + "" + "~"
  46. code := RegionCodeData[key]
  47. if code != "" {
  48. area_code = code
  49. return
  50. }
  51. }
  52. return
  53. }
  54. // 单位分割~去重 中标单位
  55. func SegmentationEntName(name_1 string, name_2 string) ([]string, []bool) {
  56. new_arr := []string{}
  57. new_bool := []bool{}
  58. key_str := map[string]string{}
  59. if name_1 != "" {
  60. arr_1 := strings.Split(name_1, ",")
  61. if len(arr_1) == 1 {
  62. arr_1 = strings.Split(name_1, ",")
  63. }
  64. for _, v := range arr_1 {
  65. if v != "" && utf8.RuneCountInString(v) > 2 && utf8.RuneCountInString(v) < 30 {
  66. if key_str[v] == "" {
  67. new_arr = append(new_arr, v)
  68. key_str[v] = v
  69. new_bool = append(new_bool, true)
  70. }
  71. }
  72. }
  73. }
  74. if name_2 != "" {
  75. arr_2 := strings.Split(name_2, ",")
  76. if len(arr_2) == 1 {
  77. arr_2 = strings.Split(name_2, ",")
  78. }
  79. for _, v := range arr_2 {
  80. if v != "" && utf8.RuneCountInString(v) > 2 && utf8.RuneCountInString(v) < 30 {
  81. if key_str[v] == "" {
  82. new_arr = append(new_arr, v)
  83. key_str[v] = v
  84. new_bool = append(new_bool, false)
  85. }
  86. }
  87. }
  88. }
  89. return new_arr, new_bool
  90. }
  91. // 转二进制
  92. func Str2DEC(s string) (num int) {
  93. l := len(s)
  94. for i := l - 1; i >= 0; i-- {
  95. num += (int(s[l-i-1]) & 0xf) << uint8(i)
  96. }
  97. return
  98. }
  99. func ConvertToBin(num int) string {
  100. s := ""
  101. if num == 0 {
  102. return "0"
  103. }
  104. for ; num > 0; num /= 2 {
  105. lsb := num % 2
  106. s = strconv.Itoa(lsb) + s
  107. }
  108. return s
  109. }
  110. func toMegaBytes(bytes uint64) float64 {
  111. return float64(bytes) / 1024 / 1024
  112. }
  113. func traceMemStats() {
  114. var ms runtime.MemStats
  115. runtime.ReadMemStats(&ms)
  116. var result = make([]float64, 7)
  117. result[0] = float64(ms.HeapObjects)
  118. result[1] = toMegaBytes(ms.HeapAlloc)
  119. result[2] = toMegaBytes(ms.TotalAlloc)
  120. result[3] = toMegaBytes(ms.HeapSys)
  121. result[4] = toMegaBytes(ms.HeapIdle)
  122. result[5] = toMegaBytes(ms.HeapReleased)
  123. result[6] = toMegaBytes(ms.HeapIdle - ms.HeapReleased)
  124. for _, v := range result {
  125. fmt.Printf("%.2f\t", v)
  126. }
  127. fmt.Printf("\n")
  128. }
  129. func IsMarkInterfaceArr(t interface{}) []string {
  130. sub_list := []string{}
  131. if list_3, ok_3 := t.([]string); ok_3 {
  132. sub_list = list_3
  133. return sub_list
  134. }
  135. if list_1, ok_1 := t.(primitive.A); ok_1 {
  136. sub_list = qu.ObjArrToStringArr(list_1)
  137. } else {
  138. if list_2, ok_2 := t.([]interface{}); ok_2 {
  139. sub_list = qu.ObjArrToStringArr(list_2)
  140. }
  141. }
  142. return sub_list
  143. }