network.go 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package common
  2. import (
  3. "context"
  4. "fmt"
  5. "strings"
  6. . "app.yhyue.com/moapp/jybase/common"
  7. "github.com/zeromicro/go-zero/core/logx"
  8. )
  9. //人脉通公用方法
  10. var NetworkCom = &networkCom{}
  11. type networkCom struct{}
  12. //根据标签类型获取标签占位
  13. func (n *networkCom) GetEntTagSeat(labelType int) []string {
  14. rows, err := ClickhouseConn.Query(context.Background(), `select bitmap_num from information.ent_label where label_type=?`, labelType)
  15. if err != nil {
  16. logx.Error(err)
  17. return nil
  18. }
  19. array := []string{}
  20. for rows.Next() {
  21. var (
  22. bitmap_num int8
  23. )
  24. if err := rows.Scan(&bitmap_num); err != nil {
  25. logx.Error(err)
  26. continue
  27. }
  28. array = append(array, fmt.Sprint(bitmap_num))
  29. }
  30. rows.Close()
  31. if err := rows.Err(); err != nil {
  32. logx.Error(err)
  33. }
  34. return array
  35. }
  36. //获取我的业态
  37. func (n *networkCom) GetMyProbusfor(entAccoutId int64) []string {
  38. datas := CrmMysql.SelectBySql(`select probusfor from crm.config_tenant where account_id=?`, entAccoutId)
  39. if datas == nil || len(*datas) == 0 {
  40. return nil
  41. }
  42. probusfor := ObjToString((*datas)[0]["probusfor"])
  43. if probusfor == "" {
  44. return nil
  45. }
  46. return strings.Split(probusfor, ",")
  47. }
  48. //获取总数封装
  49. func (n *networkCom) Count(query string, args ...interface{}) int64 {
  50. row := ClickhouseConn.QueryRow(context.Background(), query, args...)
  51. var count uint64
  52. if err := row.Scan(&count); err != nil {
  53. logx.Error(err)
  54. return 0
  55. }
  56. return int64(count)
  57. }
  58. //获取我监控的企业
  59. func (n *networkCom) EntMonitor(positionId int64) map[string]bool {
  60. m := map[string]bool{}
  61. list := CrmMysql.SelectBySql(`select * from base_service.follow_ent_monitor where s_userid=?`, positionId)
  62. for _, v := range *list {
  63. if entName := ObjToString(v["s_entname"]); entName != "" {
  64. m[entName] = true
  65. }
  66. }
  67. return m
  68. }
  69. //获取问号占位符数量及对应的参数值
  70. func (n *networkCom) WhArgs(args []string) (string, []interface{}) {
  71. newArgs := make([]interface{}, len(args))
  72. wh := make([]string, len(args))
  73. for k, v := range args {
  74. newArgs[k] = v
  75. wh[k] = "?"
  76. }
  77. return strings.Join(wh, ","), newArgs
  78. }