WH01243 1 сар өмнө
parent
commit
2277ab530c

+ 58 - 3
clueSync/config.go

@@ -2,8 +2,12 @@ package main
 
 import (
 	"app.yhyue.com/moapp/jybase/common"
+	"context"
+	"fmt"
+	"github.com/ClickHouse/clickhouse-go/v2"
 	"gopkg.in/gomail.v2"
 	"log"
+	"time"
 )
 
 type (
@@ -46,6 +50,7 @@ type (
 		CornExp6      int64  `json:"cornexp6"`
 		CornExp7      string `json:"cornexp7"`
 		CornExp8      int64  `json:"cornexp8"`
+		CornExp9      string `json:"cornexp7"`
 		TiDb          struct {
 			Host        string `json:"host"`
 			Port        int    `json:"port"`
@@ -210,9 +215,29 @@ type (
 			MessageReturnMoney string `json:"messageReturnMoney"`
 			Admin              string `json:"admin"`
 		} `json:"keCheng"`
-		EntId int       `json:"entId"`
-		Mail  GmailAuth `json:"mail"` //邮箱配置
-
+		EntId      int          `json:"entId"`
+		Mail       GmailAuth    `json:"mail"` //邮箱配置
+		Clickhouse CHouseConfig `json:"clickhouse"`
+	}
+	LableJson struct {
+		ConditionConfig []ConditionEntity `json:"conditionConfig"`
+	}
+	ConditionEntity struct {
+		TopName      string      `json:"topName"`
+		SubName      string      `json:"subName"`
+		ConditionArr []Condition `json:"conditionArr"`
+	}
+	Condition struct {
+		Code string `json:"code"`
+		Fool bool   `json:"fool"`
+	}
+	CHouseConfig struct {
+		Addr         string
+		UserName     string
+		Password     string
+		DbName       string
+		MaxIdleConns int
+		MaxOpenConns int
 	}
 )
 type GmailAuth struct {
@@ -259,3 +284,33 @@ func InitProduct(product []string) {
 		ProductMap[v] = "dk"
 	}
 }
+func ConnectClickhouse(cHouseConfig *CHouseConfig) error {
+	var (
+		ctx = context.Background()
+		err error
+	)
+	ClickhouseConn, err = clickhouse.Open(&clickhouse.Options{
+		Addr:         []string{cHouseConfig.Addr},
+		DialTimeout:  10 * time.Second,
+		MaxIdleConns: cHouseConfig.MaxIdleConns,
+		MaxOpenConns: cHouseConfig.MaxOpenConns,
+		Auth: clickhouse.Auth{
+			Database: cHouseConfig.DbName,
+			Username: cHouseConfig.UserName,
+			Password: cHouseConfig.Password,
+		},
+		Debugf: func(format string, v ...interface{}) {
+			fmt.Printf(format, v)
+		},
+	})
+	if err != nil {
+		return err
+	}
+	if err := ClickhouseConn.Ping(ctx); err != nil {
+		if exception, ok := err.(*clickhouse.Exception); ok {
+			fmt.Printf("Exception [%d] %s \n%s\n", exception.Code, exception.Message, exception.StackTrace)
+		}
+		return err
+	}
+	return nil
+}

+ 53 - 32
clueSync/db.json

@@ -8,12 +8,24 @@
   "cornexp4": "0 0 0 */1 * ? ",
   "cornexp5": 5,
   "cornexp6": 10,
+  "cornexp7": "0 0/1 0 * * ? *",
   "cornexp7": "0 */10 * * * ?",
-  "redisServer": "bidx=192.168.3.206:1712,newother=192.168.3.149:1712",
+  "cornexp9": "0 */10 * * * ?",
+  "redisServer": "bidx=172.20.45.129:1712,newother=172.20.45.129:1712",
   "tiDb": {
-    "host": "192.168.3.149",
+    "host": "172.20.45.129",
     "port": 4000,
     "database": "jianyu_subjectdb_test",
+    "user": "root",
+    "password": "=PDT49#80Z!RVv52_z",
+    "poolsize": 20,
+    "maxidle": 40,
+    "maxleft": 40
+  },
+  "tiDb1": {
+    "host": "127.0.0.1",
+    "port": 33063,
+    "database": "jianyu_subjectdb_test",
     "user": "datagroup",
     "password": "Dgrpdb#2024@36",
     "poolsize": 20,
@@ -21,27 +33,27 @@
     "maxleft": 40
   },
   "tiDbData": {
-    "host": "192.168.3.149",
+    "host": "172.20.45.129",
     "port": 4000,
     "database": "Call_Accounting",
-    "user": "datagroup",
-    "password": "Dgrpdb#2024@36",
+    "user": "root",
+    "password": "=PDT49#80Z!RVv52_z",
     "poolsize": 20,
     "maxidle": 40,
     "maxleft": 40
   },
   "tiDbPower": {
-    "host": "192.168.3.149",
+    "host": "172.20.45.129",
     "port": 4000,
     "database": "jianyu_subjectdb_test",
-    "user": "datagroup",
-    "password": "Dgrpdb#2024@36",
+    "user": "root",
+    "password": "=PDT49#80Z!RVv52_z",
     "poolsize": 20,
     "maxidle": 40,
     "maxleft": 40
   },
   "workOrder": {
-    "host": "192.168.3.14",
+    "host": "172.20.45.129",
     "port": 4000,
     "database": "work_order",
     "user": "root",
@@ -51,7 +63,7 @@
     "maxleft": 40
   },
   "baseService": {
-    "host": "192.168.3.14",
+    "host": "172.20.45.129",
     "port": 4000,
     "database": "base_service",
     "user": "root",
@@ -61,7 +73,7 @@
     "maxleft": 40
   },
   "biService": {
-    "host": "192.168.3.14",
+    "host": "172.20.45.129",
     "port": 4000,
     "database": "bi_service",
     "user": "root",
@@ -71,7 +83,7 @@
     "maxleft": 40
   },
   "thirdParty": {
-    "host": "192.168.3.14",
+    "host": "172.20.45.129",
     "port": 4000,
     "database": "thirdparty",
     "user": "root",
@@ -81,14 +93,14 @@
     "maxleft": 40
   },
   "debrisProduct": {
-    "host": "192.168.3.14",
+    "host": "172.20.45.129",
     "port": 4000,
     "database": "debris_product",
     "user": "root",
     "password": "=PDT49#80Z!RVv52_z"
   },
   "dataAnalysis": {
-    "host": "192.168.3.14",
+    "host": "172.20.45.129",
     "port": 4000,
     "database": "data_analysis",
     "user": "root",
@@ -98,7 +110,7 @@
     "maxleft": 40
   },
   "mysql": {
-    "host": "192.168.3.14",
+    "host": "172.20.45.129",
     "port": 4000,
     "database": "jianyu",
     "user": "root",
@@ -108,26 +120,26 @@
     "maxleft": 40
   },
   "mgo": {
-    "address": "192.168.3.149:27180",
+    "address": "172.20.45.129:27002",
     "dbName": "qfw",
     "dbSize": 20
   },
   "mgoLog": {
-    "address": "192.168.3.149:27190",
+    "address": "172.20.45.129:27002",
     "dbName": "qfw",
     "dbSize": 20,
     "user": "admin",
     "password": "123456"
   },
   "mgoQyxy": {
-    "address": "192.168.3.149:27102",
+    "address": "172.20.45.129:27002",
     "dbName": "mixdata",
     "dbSize": 20,
     "user": "jyDevGroup",
     "password": "jy@DevGroup"
   },
   "es": {
-    "address": "http://192.168.3.149:9200",
+    "address": "http://172.20.45.129:9200",
     "dbSize": 20,
     "version": "v7",
     "UserName": "",
@@ -139,7 +151,8 @@
     "API接口",
     "广告服务",
     "物业专版",
-    "市场分析报告"
+    "市场分析报告",
+    "三方服务"
   ],
   "allocationCap": 400,
   "warningValue": 350,
@@ -171,19 +184,27 @@
     "user": "public03@topnet.net.cn",
     "pwd": "ue9Rg9Sf4CVtdm5a"
   },
-  "kecheng":{
-    "deptId":59005,
-    "title":"客户移交客户成功组",
-    "mail":{
-      "content":"<style> *,body,html{margin:10px;font-family:tahoma,arial,'Hiragino Sans GB','Microsoft YaHei',宋体,ans-serif;font-size:16px;}p{margin:15px;font-size:18px;}table{background-color: rgb(244, 244, 249);padding:5px 15px;border:solid 1px #ddd;margin: 20px 0px 20px 50px;vertical-align:top;display:inline-block;}.tit{width:120px;}td{padding: 5px;}.clear{clear: both;}</style><p>各位好,以下订单用户已经完成支付,烦请对接后续售后服务事项,谢谢!</p>%s<div class='clear'></div>",
-      "table":"<table><tr><td class='tit'>产品名称:</td><td>%s</td></tr><tr><td class='tit'>公司名称:</td><td>%s</td></tr><tr><td class='tit'>联系方式:</td><td>%s</td></tr><tr><td class='tit'>联系人姓名:</td><td>%s</td></tr><tr><td class='tit'>订单编号:</td><td>%s</td></tr><tr><td class='tit'>合同金额:</td><td>%.2f</td></tr><tr><td class='tit'>使用起止时间:</td><td>%s</td></tr><tr><td class='tit'>分配客成:</td><td>%s</td></tr><tr><td class='tit'>签署销售:</td><td>%s</td></tr>%s</table>",
-      "serviceList":"<tr><td class='tit'>服务列表:</td><td>%s</td></tr>",
-      "returnMoney":"<tr><td class='tit'>回款金额:</td><td>%.2f</td></tr>"
+  "kecheng": {
+    "deptId": 59005,
+    "title": "客户移交客户成功组",
+    "mail": {
+      "content": "<style> *,body,html{margin:10px;font-family:tahoma,arial,'Hiragino Sans GB','Microsoft YaHei',宋体,ans-serif;font-size:16px;}p{margin:15px;font-size:18px;}table{background-color: rgb(244, 244, 249);padding:5px 15px;border:solid 1px #ddd;margin: 20px 0px 20px 50px;vertical-align:top;display:inline-block;}.tit{width:120px;}td{padding: 5px;}.clear{clear: both;}</style><p>各位好,以下订单用户已经完成支付,烦请对接后续售后服务事项,谢谢!</p>%s<div class='clear'></div>",
+      "table": "<table><tr><td class='tit'>产品名称:</td><td>%s</td></tr><tr><td class='tit'>公司名称:</td><td>%s</td></tr><tr><td class='tit'>联系方式:</td><td>%s</td></tr><tr><td class='tit'>联系人姓名:</td><td>%s</td></tr><tr><td class='tit'>订单编号:</td><td>%s</td></tr><tr><td class='tit'>合同金额:</td><td>%.2f</td></tr><tr><td class='tit'>使用起止时间:</td><td>%s</td></tr><tr><td class='tit'>分配客成:</td><td>%s</td></tr><tr><td class='tit'>签署销售:</td><td>%s</td></tr>%s</table>",
+      "serviceList": "<tr><td class='tit'>服务列表:</td><td>%s</td></tr>",
+      "returnMoney": "<tr><td class='tit'>回款金额:</td><td>%.2f</td></tr>"
     },
-    "message":"该订单用户已经完成支付,烦请对接后续售后服务事项,谢谢!\n产品名称:%s 公司名称:%s 联系方式:%s 联系人姓名:%s 订单编号:%s 合同金额:%.2f 使用起止时间:%s 分配客成:%s 签署销售:%s%s",
-    "messageServiceList":" 服务列表:%s",
-    "messageReturnMoney":" 回款金额:%.2f",
+    "message": "该订单用户已经完成支付,烦请对接后续售后服务事项,谢谢!\n产品名称:%s 公司名称:%s 联系方式:%s 联系人姓名:%s 订单编号:%s 合同金额:%.2f 使用起止时间:%s 分配客成:%s 签署销售:%s%s",
+    "messageServiceList": " 服务列表:%s",
+    "messageReturnMoney": " 回款金额:%.2f",
     "admin": "郑慧慧"
   },
-  "entId": 25917
+  "entId": 25917,
+  "clickhouse": {
+    "addr": "172.20.45.129:19000",
+    "userName": "jytop",
+    "password": "pwdTopJy123",
+    "dbName": "pub_tags",
+    "maxIdleConns": 5,
+    "maxOpenConns": 30
+  }
 }

+ 3 - 1
clueSync/go.mod

@@ -5,6 +5,7 @@ go 1.14
 require (
 	app.yhyue.com/moapp/jybase v0.0.0-20240912091212-401647f2624b
 	bp.jydev.jianyu360.cn/BaseService/pushpkg v0.0.0-20240917100248-b3a720df70c0
+	github.com/ClickHouse/clickhouse-go/v2 v2.2.0
 	github.com/go-xweb/httpsession v0.0.0-20141220075701-356d3b4d38d6 // indirect
 	github.com/go-xweb/log v0.0.0-20140701090824-270d183ad77e // indirect
 	github.com/go-xweb/uuid v0.0.0-20140604020037-d7dce341f851 // indirect
@@ -14,5 +15,6 @@ require (
 	github.com/lunny/csession v0.0.0-20130910075847-fe53c5de3dfd // indirect
 	github.com/robfig/cron v1.2.0
 	github.com/tealeg/xlsx v1.0.5
-	gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df // indirect
+	github.com/zeromicro/go-zero v1.5.2
+	gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
 )

+ 6 - 0
clueSync/go.sum

@@ -563,8 +563,10 @@ github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0
 github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
 github.com/ClickHouse/clickhouse-go v1.5.1/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI=
+github.com/ClickHouse/clickhouse-go v1.5.4 h1:cKjXeYLNWVJIx2J1K6H2CqyRmfwVJVY1OV1coaaFcI0=
 github.com/ClickHouse/clickhouse-go v1.5.4/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI=
 github.com/ClickHouse/clickhouse-go/v2 v2.0.14/go.mod h1:iq2DUGgpA4BBki2CVwrF8x43zqBjdgHtbexkFkh5a6M=
+github.com/ClickHouse/clickhouse-go/v2 v2.2.0 h1:dj00TDKY+xwuTJdbpspCSmTLFyWzRJerTHwaBxut1C0=
 github.com/ClickHouse/clickhouse-go/v2 v2.2.0/go.mod h1:8f2XZUi7XoeU+uPIytSi1cvx8fmJxi7vIgqpvYTF1+o=
 github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
 github.com/JohnCGriffin/overflow v0.0.0-20211019200055-46fa312c352c/go.mod h1:X0CRv0ky0k6m906ixxpzmDRLvX58TFUKS2eePweuyxk=
@@ -1186,6 +1188,7 @@ github.com/openzipkin/zipkin-go v0.4.0/go.mod h1:4c3sLeE8xjNqehmF5RpAFLPLJxXscc0
 github.com/openzipkin/zipkin-go v0.4.1 h1:kNd/ST2yLLWhaWrkgchya40TJabe8Hioj9udfPcEO5A=
 github.com/openzipkin/zipkin-go v0.4.1/go.mod h1:qY0VqDSN1pOBN94dBc6w2GJlWLiovAyg7Qt6/I9HecM=
 github.com/paulmach/orb v0.5.0/go.mod h1:FWRlTgl88VI1RBx/MkrwWDRhQ96ctqMCh8boXhmqB/A=
+github.com/paulmach/orb v0.7.1 h1:Zha++Z5OX/l168sqHK3k4z18LDvr+YAO/VjK0ReQ9rU=
 github.com/paulmach/orb v0.7.1/go.mod h1:FWRlTgl88VI1RBx/MkrwWDRhQ96ctqMCh8boXhmqB/A=
 github.com/paulmach/protoscan v0.2.1/go.mod h1:SpcSwydNLrxUGSDvXvO0P7g7AuhJ7lcKfDlhJCDw2gY=
 github.com/pelletier/go-toml v1.7.0 h1:7utD74fnzVc/cpcyy8sjrlFr5vYpypUixARcHIMIGuI=
@@ -1199,9 +1202,11 @@ github.com/phpdave11/gofpdf v1.4.2/go.mod h1:zpO6xFn9yxo3YLyMvW8HcKWVdbNqgIfOOp2
 github.com/phpdave11/gofpdi v1.0.12/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
 github.com/phpdave11/gofpdi v1.0.13/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI=
 github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
+github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM=
 github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
 github.com/pierrec/lz4/v4 v4.1.14/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
 github.com/pierrec/lz4/v4 v4.1.15/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
+github.com/pierrec/lz4/v4 v4.1.17 h1:kV4Ip+/hUBC+8T6+2EgburRtkE9ef4nbY3f4dFhGjMc=
 github.com/pierrec/lz4/v4 v4.1.17/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
 github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
 github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
@@ -1272,6 +1277,7 @@ github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdh
 github.com/shirou/gopsutil v2.19.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
 github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
 github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
+github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
 github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
 github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
 github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=

+ 23 - 1
clueSync/job.go

@@ -59,6 +59,26 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 				}
 			}
 		}
+	} else if item == "tag" {
+		userMapping := TiDb.FindOne("dwd_f_userbase_id_mapping", map[string]interface{}{"base_user_id": common.Int64All(data["baseUserId"])}, "", "")
+		if userMapping != nil && len(*userMapping) > 0 {
+			userId = gconv.String((*userMapping)["userid"])
+			positionId = fmt.Sprint((*userMapping)["position_id"])
+		}
+		query["userid"] = userId
+		userInfo := TiDb.FindOne("dwd_f_userbase_baseinfo", query, "", "")
+		if userInfo != nil && len(*userInfo) > 0 {
+			uId = gconv.String((*userInfo)["uid"])
+			source = gconv.String((*userInfo)["source"])
+			belong_to = gconv.String((*userInfo)["belong_to"])
+			phone = gconv.String((*userInfo)["phone"])
+			if phone != "" {
+				phoneMapping := TiDb.FindOne("dwd_f_crm_clue_info", map[string]interface{}{"phone": phone}, "", "")
+				if phoneMapping != nil && len(*phoneMapping) > 0 {
+					cluename = gconv.String((*phoneMapping)["cluename"])
+				}
+			}
+		}
 	} else if item == "users" || item == "xcxusers" { //注册用户
 		if Mgo.Count("user_share", map[string]interface{}{
 			"shared_uid": userId,
@@ -256,7 +276,9 @@ func FormatData(data map[string]interface{}, item string) (bool, bool, bool) {
 		log.Println(sourceCode)
 	}
 	log.Println(222, cluename)
-	if cluename == "" && item != "message" && item != "orders" && item != "readClue" && item != "rebind" && item != "allocation" && item != "activity" {
+	if cluename == "" && item != "message" && item != "orders" && item != "readClue" &&
+		item != "rebind" && item != "allocation" && item != "tag" &&
+		item != "activity" {
 		cluename = phone //没有线索名,手机号代替
 	}
 	log.Println(333, cluename)

+ 12 - 0
clueSync/jobutil.go

@@ -1006,6 +1006,18 @@ func getClueType(item string, data map[string]interface{}, sourceCode string, so
 				topname = common.ObjToString((*pcodeData)["name"])
 			}
 		}
+	} else if item == "tag" {
+		pcodeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"name": gconv.String(data["topName"]), "level": 1}, "", "")
+		if pcodeData != nil && len(*pcodeData) > 0 {
+			pcode = common.ObjToString((*pcodeData)["code"])
+			topname = common.ObjToString((*pcodeData)["name"])
+			codeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"name": gconv.String(data["subName"]), "level": 2}, "", "")
+			if codeData != nil && len(*codeData) > 0 {
+				subname = common.ObjToString((*codeData)["name"])
+				level = common.ObjToString((*codeData)["clue_level"])
+				code = common.ObjToString((*codeData)["code"])
+			}
+		}
 	} else {
 		if sourceCode != "" {
 			codeData := TiDb.FindOne("dwd_d_crm_cluetype_code", map[string]interface{}{"source": sourceCode}, "", "")

+ 13 - 1
clueSync/main.go

@@ -10,6 +10,7 @@ import (
 	"bp.jydev.jianyu360.cn/BaseService/pushpkg/p"
 	"flag"
 	"fmt"
+	"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
 	"github.com/robfig/cron"
 	"log"
 )
@@ -17,8 +18,10 @@ import (
 var (
 	cfg                 = new(Config)
 	db                  = new(DB)
+	lableJson           = new(LableJson)
 	Mysql               *mysql.Mysql
 	TiDb                *mysql.Mysql
+	ClickhouseConn      driver.Conn
 	TiDbData            *mysql.Mysql
 	TiDbPower           *mysql.Mysql
 	WorkOrder           *mysql.Mysql
@@ -43,6 +46,8 @@ func main() {
 	log.Println("cfg ", cfg)
 	common.ReadConfig("./db.json", &db)
 	log.Println("db ", db)
+	common.ReadConfig("./lable.json", &lableJson)
+	log.Println("lableJson ", lableJson)
 	Gmail = mail.GmailAuth{
 		SmtpHost: db.Mail.SmtpHost,
 		SmtpPort: db.Mail.SmtpPort,
@@ -146,13 +151,16 @@ func main() {
 		MaxIdleConns: db.DataAnalysis.MaxIdle,
 	}
 	DataAnalysisService.Init()
-	Es = elastic.NewEs(db.Es.Version, db.Es.Address, db.Es.DbSize, db.Es.UserName, db.Es.Password)
+	ConnectClickhouse(&db.Clickhouse)
+	//Es = elastic.NewEs(db.Es.Version, db.Es.Address, db.Es.DbSize, db.Es.UserName, db.Es.Password)
 	redis.InitRedis(db.RedisServer)
 	Mgo = mongodb.NewMgo(db.Mgo.Address, db.Mgo.DbName, db.Mgo.DbSize)
 	MgoLog = mongodb.NewMgoWithUser(db.MgoLog.Address, db.MgoLog.DbName, db.MgoLog.User, db.MgoLog.Password, db.MgoLog.DbSize)
 	MgoQyxy = mongodb.NewMgoWithUser(db.MgoQyxy.Address, db.MgoQyxy.DbName, db.MgoQyxy.User, db.MgoQyxy.Password, db.MgoQyxy.DbSize)
 	InitArea()
 	InitProduct(db.ProductArr)
+	LabelToClue()
+	return
 	if *mode == 1 {
 		go ordersClue() //后台订单进线索
 		//一秒钟一次
@@ -225,6 +233,10 @@ func main() {
 			autoTasks()  //按照下次跟进时间提前一天加入任务车
 			ClueToDxTask()
 		})
+		f := cron.New()
+		f.AddFunc(db.CornExp9, func() {
+			LabelToClue()
+		})
 		g.Start()
 		log.Println("个人邮件告警查询开始")
 		WarningPerl() // 个人

+ 82 - 2
clueSync/tag.go

@@ -1,14 +1,15 @@
 package main
 
 import (
+	"app.yhyue.com/moapp/jybase/common"
+	"context"
 	"fmt"
 	"github.com/gogf/gf/v2/util/gconv"
+	"github.com/zeromicro/go-zero/core/logx"
 	"log"
 	"regexp"
 	"strings"
 	"time"
-
-	"app.yhyue.com/moapp/jybase/common"
 )
 
 func tagAllSync() {
@@ -389,3 +390,82 @@ func customerButton() {
 	common.WriteSysConfig(&cfg)
 	log.Println("在线客服按钮定时任务结束")
 }
+func LabelToClue() {
+	log.Println("735需求 标签进线索开始")
+	for _, v := range lableJson.ConditionConfig {
+		log.Println("735标签用户sql:", v.SubName)
+		dataArr := getBitmapIntersection(v.ConditionArr)
+		log.Println("735标签用户sql:", v.SubName, len(dataArr))
+		if len(dataArr) == 0 {
+			continue
+		}
+
+		for _, baseUserId := range dataArr {
+			log.Println("735标签用户:", baseUserId)
+			if baseUserId == 0 {
+				continue
+			}
+			/*FormatData(map[string]interface{}{
+				"baseUserId": baseUserId,
+				"topName":    v.TopName,
+				"subName":    v.SubName,
+			}, "tag")*/
+		}
+	}
+	log.Println("735需求 标签进线索结束")
+}
+
+type AggStruct struct {
+	Intersection []int `ch:"intersection"`
+}
+
+func getBitmapIntersection(ids []Condition) []int {
+	// 构建查询的 SELECT 和 JOIN 部分
+	joinParts := []string{}
+	for i := len(ids); i > 0; i-- {
+		joinParts = append(joinParts, fmt.Sprintf(`
+            SELECT bitobj AS bit%d
+            FROM dwd_d_tag
+            WHERE code = '%v'`, i, ids[i-1].Code))
+	}
+	selectParts := ""
+	for i := 0; i < len(ids); i++ {
+		if i == 0 {
+			if gconv.Bool(ids[i+1].Fool) {
+				selectParts = fmt.Sprintf("bitmapAnd( bit%d,bit%d)", i+2, i+1)
+			} else {
+				selectParts = fmt.Sprintf("bitmapAndnot( bit%d,bit%d)", i+1, i+2)
+			}
+			i++
+		} else {
+			if gconv.Bool(ids[i].Fool) {
+				selectParts = fmt.Sprintf("bitmapAnd( bit%d,%s)", i+1, selectParts)
+			} else {
+				selectParts = fmt.Sprintf("bitmapAndnot( %s,bit%d)", selectParts, i+1)
+			}
+		}
+	}
+	// 构建 SQL 查询
+	query := fmt.Sprintf(`
+        SELECT bitmapToArray(%s) AS intersection
+        FROM (%s) AS t1`,
+		selectParts, // 连接 SELECT 部分
+		strings.Join(joinParts, ") AS t%d CROSS JOIN (")) // 连接 JOIN 部分
+	// 修正 CROSS JOIN 部分
+	for i := 1; i < len(ids); i++ {
+		query = strings.Replace(query, "AS t%d", fmt.Sprintf("AS t%d", i+1), 1)
+	}
+	log.Println("p735标签接口:", query)
+	rows, _ := ClickhouseConn.Query(context.TODO(), query)
+	ass := []int{}
+	for rows.Next() {
+		as := AggStruct{}
+		if err := rows.ScanStruct(&as); err != nil {
+			logx.Error(err)
+			continue
+		}
+		ass = as.Intersection
+	}
+	rows.Close()
+	return ass
+}