wangchuanjin hai 1 ano
pai
achega
8ae0eca86a

+ 2 - 2
api/common/initconfig.go

@@ -179,9 +179,9 @@ func InitConf() {
 	/*	Middleground = middleground.NewMiddleground([]string{"192.168.3.206:2379"}).
 		RegResourceCenter(C.ResourceCenterKey)*/
 	conf.MustLoad(*pushFile, &Push)
-	connectClickhouse(DB.Clickhouse)
+	ConnectClickhouse(DB.Clickhouse)
 }
-func connectClickhouse(cHouseConfig *config.CHouseConfig) error {
+func ConnectClickhouse(cHouseConfig *config.CHouseConfig) error {
 	var (
 		ctx = context.Background()
 		err error

+ 37 - 0
api/common/network.go

@@ -0,0 +1,37 @@
+package common
+
+import (
+	"context"
+	"fmt"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+//人脉通公用方法
+var NetworkCom = &networkCom{}
+
+type networkCom struct{}
+
+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
+}

+ 40 - 11
api/internal/service/network.go

@@ -2,20 +2,23 @@ package service
 
 import (
 	"database/sql"
+	"fmt"
 	"strings"
 
+	. "app.yhyue.com/moapp/jybase/common"
 	. "app.yhyue.com/moapp/jybase/date"
+	. "app.yhyue.com/moapp/jybase/es"
 	. "bp.jydev.jianyu360.cn/CRM/application/api/common"
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
 )
 
-var VarNetwork = &Network{}
+var Network = &network{}
 
-type Network struct {
+type network struct {
 }
 
 //人脉库-添加/修改人脉
-func (n *Network) AddOrUpdate(in *types.AddOrUpdateReq) *types.Reply {
+func (n *network) AddOrUpdate(in *types.AddOrUpdateReq) *types.Reply {
 	reply := &types.Reply{}
 	itype := 0
 	//firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构
@@ -46,14 +49,14 @@ func (n *Network) AddOrUpdate(in *types.AddOrUpdateReq) *types.Reply {
 		}
 		var r3 int64
 		if len(values) > 0 {
-			_, r3 = CrmMysql.InsertBatchByTx(tx, "connection_introduce", []string{"position_id", "ent_id", "ent_dept_id", "ent_user_id", "connection_id", "relate_id", "relate_name", "itype", "create_time"}, values)
+			_, r3 = CrmMysql.InsertBatchByTx(tx, "crm.connection_introduce", []string{"position_id", "ent_id", "ent_dept_id", "ent_user_id", "connection_id", "relate_id", "relate_name", "itype", "create_time"}, values)
 		}
 		return r3
 	}
 	if in.Id > 0 {
 		if CrmMysql.ExecTx("更新人脉", func(tx *sql.Tx) bool {
-			r1 := CrmMysql.UpdateOrDeleteBySqlByTx(tx, `update connection set company_name=?,company_id=?,contact_person=?,contact_phone=?,update_time=? where id=? and position_id=?`, in.Company_name, in.Company_id, in.Contact_person, in.Contact_phone, nowFormat, in.Id, in.PositionId)
-			r2 := CrmMysql.UpdateOrDeleteBySqlByTx(tx, `delete from connection_introduce where connection_id=? and position_id=?`, in.Id, in.PositionId)
+			r1 := CrmMysql.UpdateOrDeleteBySqlByTx(tx, `update crm.connection set company_name=?,company_id=?,contact_person=?,contact_phone=?,update_time=? where id=? and position_id=?`, in.Company_name, in.Company_id, in.Contact_person, in.Contact_phone, nowFormat, in.Id, in.PositionId)
+			r2 := CrmMysql.UpdateOrDeleteBySqlByTx(tx, `delete from crm.connection_introduce where connection_id=? and position_id=?`, in.Id, in.PositionId)
 			return r1 > 0 && r2 >= 0 && saveIntroduce(tx, in.Id) >= 0
 		}) {
 			reply.Data = map[string]interface{}{
@@ -67,7 +70,7 @@ func (n *Network) AddOrUpdate(in *types.AddOrUpdateReq) *types.Reply {
 	} else {
 		id := 0
 		if CrmMysql.ExecTx("新增人脉", func(tx *sql.Tx) bool {
-			_, r1 := CrmMysql.InsertBatchByTx(tx, "connection", []string{"position_id", "ent_id", "ent_dept_id", "ent_user_id", "itype", "company_name", "company_id", "contact_person", "contact_phone", "status", "create_time", "update_time"}, []interface{}{in.PositionId, in.EntId, in.EntDeptId, in.EntUserId, itype, in.Company_name, in.Company_id, in.Contact_person, in.Contact_phone, 1, nowFormat, nowFormat})
+			_, r1 := CrmMysql.InsertBatchByTx(tx, "crm.connection", []string{"position_id", "ent_id", "ent_dept_id", "ent_user_id", "itype", "company_name", "company_id", "contact_person", "contact_phone", "status", "create_time", "update_time"}, []interface{}{in.PositionId, in.EntId, in.EntDeptId, in.EntUserId, itype, in.Company_name, in.Company_id, in.Contact_person, in.Contact_phone, 1, nowFormat, nowFormat})
 			return r1 > 0 && saveIntroduce(tx, r1) >= 0
 		}) {
 			reply.Data = map[string]interface{}{
@@ -84,16 +87,42 @@ func (n *Network) AddOrUpdate(in *types.AddOrUpdateReq) *types.Reply {
 }
 
 //人脉库-业主名称联想
-func (n *Network) Associate(in *types.AssociateReq) *types.Reply {
-	return nil
+func (n *network) Associate(in *types.AssociateReq) *types.Reply {
+	//类型;firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 middleman_owner:中间人-业主 middleman_project:中间人-项目 agency:招标代理机构
+	res := []map[string]interface{}{}
+	must := []string{fmt.Sprintf(`{"multi_match":{"query":"%s","type":"phrase","fields":["company_name"]}}`, in.Name)}
+	switch in.Type {
+	case "firstparty":
+		must = append(must, fmt.Sprintf(`{"terms":{"company_label":["%s"]}}`, strings.Join(NetworkCom.GetEntTagSeat(2), `","`)))
+		must = append(must, `{"terms":{"company_unit_type":[1,2]}}`)
+	case "supplier":
+		must = append(must, fmt.Sprintf(`{"terms":{"company_label":["%s"]}}`, strings.Join(NetworkCom.GetEntTagSeat(2), `","`)))
+		must = append(must, `{"term":{"company_unit_type":3}}`)
+	case "middleman_owner":
+		must = append(must, `{"terms":{"company_unit_type":[1,2]}}`)
+	case "agency":
+		must = append(must, `{"term":{"company_unit_type":4}}`)
+	}
+	datas := VarEs.Get("ent_info", "ent_info", fmt.Sprintf(`{"query":{"bool":{"must":[%s]}},"size":10,"_source":["id","company_name"]}`, strings.Join(must, ",")))
+	if datas != nil {
+		for _, v := range *datas {
+			res = append(res, map[string]interface{}{
+				"company_name": ObjToString(v["company_name"]),
+				"company_id":   ObjToString(v["id"]),
+			})
+		}
+	}
+	return &types.Reply{
+		Data: datas,
+	}
 }
 
 //人脉库-全部人脉项目
-func (n *Network) Allproject(in *types.AllprojectReq) *types.Reply {
+func (n *network) Allproject(in *types.AllprojectReq) *types.Reply {
 	return nil
 }
 
 //人脉库-列表
-func (n *Network) List(in *types.NetWorkListReq) *types.Reply {
+func (n *network) List(in *types.NetWorkListReq) *types.Reply {
 	return nil
 }

+ 23 - 1
api/internal/service/network_test.go

@@ -4,8 +4,10 @@ import (
 	"log"
 	"testing"
 
+	"app.yhyue.com/moapp/jybase/es"
 	"app.yhyue.com/moapp/jybase/mysql"
 	. "bp.jydev.jianyu360.cn/CRM/application/api/common"
+	"bp.jydev.jianyu360.cn/CRM/application/api/internal/config"
 	"bp.jydev.jianyu360.cn/CRM/application/api/internal/types"
 )
 
@@ -19,10 +21,19 @@ func initDb() {
 		MaxIdleConns: 5,
 	}
 	CrmMysql.Init()
+	ConnectClickhouse(&config.CHouseConfig{
+		Addr:         "192.168.3.207:19000",
+		UserName:     "jytop",
+		Password:     "pwdTopJy123",
+		DbName:       "jianyu",
+		MaxIdleConns: 2,
+		MaxOpenConns: 2,
+	})
+	es.NewEs("v7", "http://192.168.3.149:9200", 5, "", "")
 }
 func TestAddOrUpdate(t *testing.T) {
 	initDb()
-	res := VarNetwork.AddOrUpdate(&types.AddOrUpdateReq{
+	res := Network.AddOrUpdate(&types.AddOrUpdateReq{
 		PositionId:             943,
 		Company_id:             "112233445566",
 		Company_name:           "王传进的测试企业1",
@@ -37,3 +48,14 @@ func TestAddOrUpdate(t *testing.T) {
 	})
 	log.Println(res)
 }
+
+func TestAssociate(t *testing.T) {
+	initDb()
+	//log.Println(NetworkCom.GetEntTagSeat(2))
+	//类型;firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 middleman_owner:中间人-业主 middleman_project:中间人-项目 agency:招标代理机构
+	res := Network.Associate(&types.AssociateReq{
+		Name: "郑州",
+		Type: "firstparty",
+	})
+	log.Println(res.Data)
+}