123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- package common
- import (
- "context"
- "fmt"
- "strings"
- "time"
- . "app.yhyue.com/moapp/jybase/common"
- "github.com/zeromicro/go-zero/core/logx"
- )
- //人脉通公用方法
- var NetworkCom = &networkCom{}
- type networkCom struct{}
- //
- func (n *networkCom) GetEntIdByName(names []string) map[string]string {
- result := map[string]string{}
- if len(names) == 0 {
- return result
- }
- var query = func(values []string) {
- wh, args := WhArgs(values)
- rows, err := ClickhouseConn.Query(context.Background(), `select id,company_name from information.ent_info where company_name in (`+wh+`)`, args...)
- if err != nil {
- logx.Error(err)
- return
- }
- for rows.Next() {
- var (
- id string
- company_name string
- )
- if err := rows.Scan(&id, &company_name); err != nil {
- logx.Error(err)
- continue
- }
- result[company_name] = id
- }
- rows.Close()
- if err := rows.Err(); err != nil {
- logx.Error(err)
- }
- }
- values := []string{}
- for _, v := range names {
- values = append(values, v)
- if len(values) == 200 {
- query(values)
- values = []string{}
- }
- }
- if len(values) > 0 {
- query(values)
- }
- return result
- }
- //根据标签类型获取标签占位
- func (n *networkCom) GetEntTagSeat(labelType int) []string {
- rows, err := ClickhouseConn.Query(context.Background(), `select bitmap_num from information.ent_label where label_type=?`, labelType)
- if err != nil {
- logx.Error(err)
- return nil
- }
- array := []string{}
- for rows.Next() {
- var (
- bitmap_num int8
- )
- if err := rows.Scan(&bitmap_num); err != nil {
- logx.Error(err)
- continue
- }
- array = append(array, fmt.Sprint(bitmap_num))
- }
- rows.Close()
- if err := rows.Err(); err != nil {
- logx.Error(err)
- }
- return array
- }
- //获取我的业态
- func (n *networkCom) GetMyProbusfor(entAccoutId int64) []string {
- datas := CrmMysql.SelectBySql(`select probusfor from crm.config_tenant where account_id=?`, entAccoutId)
- if datas == nil || len(*datas) == 0 {
- return nil
- }
- probusfor := ObjToString((*datas)[0]["probusfor"])
- if probusfor == "" {
- return nil
- }
- return strings.Split(probusfor, ",")
- }
- //获取总数封装
- func (n *networkCom) Count(query string, args ...interface{}) int64 {
- row := ClickhouseConn.QueryRow(context.Background(), query, args...)
- var count uint64
- if err := row.Scan(&count); err != nil {
- logx.Error(err)
- return 0
- }
- return int64(count)
- }
- //获取我监控的企业
- func (n *networkCom) EntMonitor(userId string) map[string]bool {
- m := map[string]bool{}
- list, _ := Mgo.Find("follow_customer", map[string]interface{}{"userId": userId}, nil, `{"_id":0,"name":1}`, false, -1, -1)
- if list == nil {
- return m
- }
- for _, v := range *list {
- name, _ := v["name"].(string)
- m[name] = true
- }
- return m
- }
- //最近三年
- func (n *networkCom) ProjectYearLimit() int64 {
- return time.Now().AddDate(-C.ProjectYearLimit, 0, 0).Unix()
- }
- //最近三年
- func (n *networkCom) CacheTimeout() int {
- now := time.Now()
- 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())
- }
|