network.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. package common
  2. import (
  3. "context"
  4. "fmt"
  5. "strings"
  6. "time"
  7. . "app.yhyue.com/moapp/jybase/common"
  8. "github.com/zeromicro/go-zero/core/logx"
  9. )
  10. //人脉通公用方法
  11. var NetworkCom = &networkCom{}
  12. type networkCom struct{}
  13. //
  14. func (n *networkCom) GetEntIdByName(names []string) map[string]string {
  15. result := map[string]string{}
  16. if len(names) == 0 {
  17. return result
  18. }
  19. var query = func(values []string) {
  20. wh, args := WhArgs(values)
  21. rows, err := ClickhouseConn.Query(context.Background(), `select id,company_name from information.ent_info where company_name in (`+wh+`)`, args...)
  22. if err != nil {
  23. logx.Error(err)
  24. return
  25. }
  26. for rows.Next() {
  27. var (
  28. id string
  29. company_name string
  30. )
  31. if err := rows.Scan(&id, &company_name); err != nil {
  32. logx.Error(err)
  33. continue
  34. }
  35. result[company_name] = id
  36. }
  37. rows.Close()
  38. if err := rows.Err(); err != nil {
  39. logx.Error(err)
  40. }
  41. }
  42. values := []string{}
  43. for _, v := range names {
  44. values = append(values, v)
  45. if len(values) == 200 {
  46. query(values)
  47. values = []string{}
  48. }
  49. }
  50. if len(values) > 0 {
  51. query(values)
  52. }
  53. return result
  54. }
  55. //根据标签类型获取标签占位
  56. func (n *networkCom) GetEntTagSeat(labelType int) []string {
  57. rows, err := ClickhouseConn.Query(context.Background(), `select bitmap_num from information.ent_label where label_type=?`, labelType)
  58. if err != nil {
  59. logx.Error(err)
  60. return nil
  61. }
  62. array := []string{}
  63. for rows.Next() {
  64. var (
  65. bitmap_num int8
  66. )
  67. if err := rows.Scan(&bitmap_num); err != nil {
  68. logx.Error(err)
  69. continue
  70. }
  71. array = append(array, fmt.Sprint(bitmap_num))
  72. }
  73. rows.Close()
  74. if err := rows.Err(); err != nil {
  75. logx.Error(err)
  76. }
  77. return array
  78. }
  79. //获取我的业态
  80. func (n *networkCom) GetMyProbusfor(entAccoutId int64) []string {
  81. datas := CrmMysql.SelectBySql(`select probusfor from crm.config_tenant where account_id=?`, entAccoutId)
  82. if datas == nil || len(*datas) == 0 {
  83. return nil
  84. }
  85. probusfor := ObjToString((*datas)[0]["probusfor"])
  86. if probusfor == "" {
  87. return nil
  88. }
  89. return strings.Split(probusfor, ",")
  90. }
  91. //获取总数封装
  92. func (n *networkCom) Count(query string, args ...interface{}) int64 {
  93. row := ClickhouseConn.QueryRow(context.Background(), query, args...)
  94. var count uint64
  95. if err := row.Scan(&count); err != nil {
  96. logx.Error(err)
  97. return 0
  98. }
  99. return int64(count)
  100. }
  101. //获取我监控的企业
  102. func (n *networkCom) EntMonitor(userId string) map[string]bool {
  103. m := map[string]bool{}
  104. list, _ := Mgo.Find("follow_customer", map[string]interface{}{"userId": userId}, nil, `{"_id":0,"name":1}`, false, -1, -1)
  105. if list == nil {
  106. return m
  107. }
  108. for _, v := range *list {
  109. name, _ := v["name"].(string)
  110. m[name] = true
  111. }
  112. return m
  113. }
  114. //最近三年
  115. func (n *networkCom) ProjectYearLimit() int64 {
  116. return time.Now().AddDate(-C.ProjectYearLimit, 0, 0).Unix()
  117. }
  118. //最近三年
  119. func (n *networkCom) CacheTimeout() int {
  120. now := time.Now()
  121. return int(time.Date(now.Year(), now.Month(), now.Day(), IntAll(strings.Split(C.CacheTimeOut, ":")[0]), IntAll(strings.Split(C.CacheTimeOut, ":")[1]), 0, 0, time.Local).AddDate(0, 1, 0).Unix() - now.Unix())
  122. }