wangchuanjin преди 9 месеца
родител
ревизия
e770fad56d
променени са 5 файла, в които са добавени 276 реда и са изтрити 83 реда
  1. 12 1
      api/internal/logic/updateinitinfologic.go
  2. 225 0
      api/internal/service/initNetwork.go
  3. 14 67
      api/internal/service/network_test.go
  4. 7 0
      api/internal/types/types.go
  5. 18 15
      api/networkmanage.api

+ 12 - 1
api/internal/logic/updateinitinfologic.go

@@ -1,9 +1,10 @@
 package logic
 
 import (
+	"context"
+
 	"app.yhyue.com/moapp/jybase/common"
 	"bp.jydev.jianyu360.cn/CRM/networkManage/api/internal/service"
-	"context"
 	"github.com/gogf/gf/v2/util/gconv"
 
 	"bp.jydev.jianyu360.cn/CRM/networkManage/api/internal/svc"
@@ -37,6 +38,16 @@ func (l *UpdateInitInfoLogic) UpdateInitInfo(req *types.UpdateInitInfoReq) (resp
 		EntUserId:    req.EntUserId,
 	}
 	fool := initInfoService.UpdateInitInfo(req.Company, req.Business)
+	if fool {
+		(&service.InitNetwork{
+			PositionId:   req.PositionId,
+			EntId:        req.EntId,
+			DeptId:       req.EntDeptId,
+			UserId:       req.NewUserId,
+			EntName:      req.EntName,
+			BusinessType: req.Business,
+		}).Init()
+	}
 	resp.Data = map[string]interface{}{
 		"status": gconv.Int64(common.If(fool, 1, 0)),
 	}

+ 225 - 0
api/internal/service/initNetwork.go

@@ -0,0 +1,225 @@
+package service
+
+import (
+	"context"
+	"fmt"
+	"strings"
+
+	util "app.yhyue.com/moapp/jybase/common"
+	. "app.yhyue.com/moapp/jybase/date"
+	. "bp.jydev.jianyu360.cn/CRM/networkManage/api/common"
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type ContactInfo struct {
+	Name  string
+	Phone string
+}
+type Connection struct {
+	Company_id   string
+	Company_name string
+	Itype        int
+	QyxyId       string
+	*ContactInfo
+}
+type InitNetwork struct {
+	PositionId   int64
+	EntId        int64
+	DeptId       int64
+	UserId       int64
+	EntName      string
+	BusinessType string
+}
+
+func (i *InitNetwork) Init() {
+	array := []*Connection{}
+	ids := []string{}
+	//①业主人脉:当前企业曾经合作过物业项目的采购单位的联系人作为业主人脉
+	func() {
+		rows, err := ClickhouseConn.Query(context.Background(), `select DISTINCT buyer,buyer_id from information.transaction_info where has(winner,?)`, i.EntName)
+		if err != nil {
+			logx.Error(err)
+			return
+		}
+		for rows.Next() {
+			var (
+				buyer    string
+				buyer_id string
+			)
+			if err := rows.Scan(&buyer, &buyer_id); err != nil {
+				logx.Error(err)
+				continue
+			}
+			if buyer == "" || buyer_id == "" {
+				continue
+			}
+			cn := &Connection{
+				Company_id:   buyer_id,
+				Company_name: buyer,
+				Itype:        1,
+			}
+			ids = append(ids, buyer_id)
+			array = append(array, cn)
+		}
+	}()
+	//②甲异业渠道(人脉):“当前企业曾经合作过物业项目的采购单位的中标物业企业中”与当前企业不一样业态的企业的联系人列表
+	func() {
+		if i.BusinessType == "" {
+			return
+		}
+		m := map[string]*Connection{}
+		args := []interface{}{i.EntName}
+		wh, newArgs := util.WhArgs(strings.Split(i.BusinessType, ","))
+		args = append(args, newArgs...)
+		rows, err := ClickhouseConn.Query(context.Background(), `select DISTINCT winner_id,winner from information.transaction_info WHERE buyer_id IN (SELECT buyer_id from information.transaction_info WHERE has(winner,?) and buyer_id<>'') AND hasAny(property_form,[`+wh+`])`, args...)
+		if err != nil {
+			logx.Error(err)
+			return
+		}
+		for rows.Next() {
+			var (
+				winners    []string
+				winner_ids []string
+			)
+			if err := rows.Scan(&winners, &winner_ids); err != nil {
+				logx.Error(err)
+				continue
+			}
+			for k, winner_id := range winner_ids {
+				if k >= len(winners) {
+					continue
+				}
+				cn := &Connection{
+					Company_id:   winner_id,
+					Company_name: winners[k],
+					Itype:        3,
+				}
+				if m[winner_id] != nil {
+					continue
+				}
+				ids = append(ids, winner_id)
+				array = append(array, cn)
+			}
+		}
+	}()
+	//③招标代理机构(人脉):当前企业曾经合作过的招标代理机构联系人信息
+	func() {
+		rows, err := ClickhouseConn.Query(context.Background(), `select DISTINCT agency,agency_id from information.transaction_info where buyer=? or has(winner,?)`, i.EntName, i.EntName)
+		if err != nil {
+			logx.Error(err)
+			return
+		}
+		for rows.Next() {
+			var (
+				agency    string
+				agency_id string
+			)
+			if err := rows.Scan(&agency, &agency_id); err != nil {
+				logx.Error(err)
+				continue
+			}
+			if agency == "" || agency_id == "" {
+				continue
+			}
+			cn := &Connection{
+				Company_id:   agency_id,
+				Company_name: agency,
+				Itype:        5,
+			}
+			ids = append(ids, agency_id)
+			array = append(array, cn)
+		}
+	}()
+	cis := i.GetContactInfo(ids)
+	cids := i.GetCompanyId(ids)
+	for _, v := range array {
+		if cis[v.Company_id] != nil {
+			v.ContactInfo = cis[v.Company_id]
+		}
+		v.QyxyId = cids[v.Company_id]
+	}
+	//
+	nowFormat := NowFormat(Date_Full_Layout)
+	values := []interface{}{}
+	fields := []string{"position_id", "ent_id", "ent_dept_id", "ent_user_id", "itype", "company_name", "company_id", "qyxy_id", "contact_person", "contact_phone", "status", "create_time", "update_time"}
+	index := 0
+	for _, v := range array {
+		if v.ContactInfo == nil || v.ContactInfo.Phone == "" || v.ContactInfo.Name == "" {
+			continue
+		}
+		if CrmMysql.CountBySql(`select count(1) from crm.connection where position_id=? and company_id=? and itype=?`, i.PositionId, v.Company_id, v.Itype) == 0 {
+			logx.Info("保存人脉", fmt.Sprintf("%+v", v))
+			values = append(values, i.PositionId, i.EntId, i.DeptId, i.UserId, v.Itype, v.Company_name, v.Company_id, v.QyxyId, v.ContactInfo.Name, v.ContactInfo.Phone, 1, nowFormat, nowFormat)
+		} else {
+			logx.Info("过滤掉已存在的人脉", fmt.Sprintf("%+v", v))
+		}
+		index++
+		if index == 200 {
+			CrmMysql.InsertBatch("crm.connection", fields, values)
+			values = []interface{}{}
+		}
+	}
+	if len(values) > 0 {
+		CrmMysql.InsertBatch("crm.connection", fields, values)
+		values = []interface{}{}
+	}
+}
+
+//
+func (i *InitNetwork) GetCompanyId(ids []string) map[string]string {
+	m := map[string]string{}
+	if len(ids) == 0 {
+		return m
+	}
+	wh, args := util.WhArgs(ids)
+	rows, err := ClickhouseConn.Query(context.Background(), `select id,company_id from information.ent_info where id in(`+wh+`)`, args...)
+	if err != nil {
+		logx.Error(err)
+		return m
+	}
+	for rows.Next() {
+		var (
+			id         string
+			company_id string
+		)
+		if err := rows.Scan(&id, &company_id); err != nil {
+			logx.Error(err)
+			continue
+		}
+		m[id] = company_id
+	}
+	return m
+}
+
+//
+func (i *InitNetwork) GetContactInfo(ids []string) map[string]*ContactInfo {
+	m := map[string]*ContactInfo{}
+	if len(ids) == 0 {
+		return m
+	}
+	wh, args := util.WhArgs(ids)
+	rows, err := ClickhouseConn.Query(context.Background(), `select id,phone,name from information.ent_contact where id in (`+wh+`)`, args...)
+	if err != nil {
+		logx.Error(err)
+		return m
+	}
+	for rows.Next() {
+		var (
+			id    string
+			phone string
+			name  string
+		)
+		if err := rows.Scan(&id, &phone, &name); err != nil {
+			logx.Error(err)
+			continue
+		}
+		if phone == "" || name == "" {
+			continue
+		}
+		m[id] = &ContactInfo{
+			Name:  name,
+			Phone: phone,
+		}
+	}
+	return m
+}

+ 14 - 67
api/internal/service/network_test.go

@@ -1,7 +1,6 @@
 package service
 
 import (
-	"context"
 	"encoding/json"
 	"fmt"
 	"log"
@@ -10,7 +9,6 @@ import (
 	. "app.yhyue.com/moapp/jybase/common"
 	. "bp.jydev.jianyu360.cn/CRM/networkManage/api/common"
 	"bp.jydev.jianyu360.cn/CRM/networkManage/api/internal/types"
-	"bp.jydev.jianyu360.cn/CRM/networkManage/service"
 )
 
 //go test -test.run=TestAddCustomService -fs=../../etc/crmapplication.yaml -lf=../../etc/logs.yaml -df=../../etc/db.yaml -pf=../../etc/push.yaml
@@ -82,9 +80,9 @@ func TestNetWorkList(t *testing.T) {
 	res := Network.List(&types.NetWorkListReq{
 		EntAccountId: 64,
 		UserId:       "1205591997",
-		PositionId:   1205591997,
+		//PositionId:   1205591997,
 		//PositionId: 1205592003,
-		//PositionId:   935,
+		PositionId:   935,
 		Current_page: 1,
 		Page_size:    10,
 		//PositionId: 935,
@@ -96,7 +94,7 @@ func TestNetWorkList(t *testing.T) {
 		//Starttime: "2024-04-23",
 		//Endtime:   "2024-04-23",
 		//Type: "middleman",
-		Name: "新疆",
+		//Name: "新疆",
 	})
 	for k, v := range res.Data.(map[string]interface{}) {
 		if k == "list" {
@@ -135,49 +133,6 @@ func TestOwner(t *testing.T) {
 	log.Println(string(b))
 }
 
-func TestAddCustomService(t *testing.T) {
-	InitConf()
-	cs := &service.CustomService{
-		PositionId:           1205591997,
-		AppId:                "10000",
-		CustomType:           35,
-		Summary:              "1",
-		CustomAllName:        "1",
-		CustomAbbreviation:   "1",
-		CustomLevel:          1,
-		CustomIndustry:       11,
-		CustomDetailIndustry: 24,
-		Province:             "000000",
-		NextfollowUpTime:     1714406400,
-		Types:                1,
-		User:                 []int64{1205591997},
-		CreateName:           "刘苗苗",
-		OwnerId:              "875037a55d374627b1bc919c3cd84668",
-	}
-	cs.Add(context.Background())
-}
-func TestCandidateChannel(t *testing.T) {
-	InitConf()
-	ownerService := &OwnerService{
-		PartyA: "15e4d804ce194a029e9fba645fda0cf0,90e9db9308024d3782a1a03e11ccd684,ed856df4ac4f4eb78a8d1ae9a5a98006,009c313ef8e740e59d57432aea777102,9df7aa60510d45a6875205c2069d550b,2c5ecd5d2a0d4c62884c30e472c95ffe",
-		//Supplier: "0d732efa7adc40529100609e6096baad",
-		//Intermediary: "30154",
-		//Heterotophy:  req.Heterotophy,
-		//Agency:       req.Agency,
-		Type:         "adiffb",
-		EntAccountId: 64,
-		PositionId:   1205591999,
-	}
-	data, a1, a2, a3, a4 := ownerService.CandidateChannel()
-	for _, v := range *data {
-		log.Println(fmt.Sprintf("%+v", v))
-	}
-	log.Println(a1)
-	log.Println(a2)
-	log.Println(a3)
-	log.Println(a4)
-}
-
 func TestProjectHistory(t *testing.T) {
 	InitConf()
 	data := GetData3("2", "128a81f9facb4aefb817244dc2c0e655", "北京城市之光生态环境有限公司")
@@ -185,24 +140,16 @@ func TestProjectHistory(t *testing.T) {
 		log.Println(fmt.Sprintf("%+v", v))
 	}
 }
-func TestChanceAdd(t *testing.T) {
-	chance := &service.SaleChanceService{
-		PositionId:        935,
-		AppId:             "10000",
-		ChanceName:        "王传进的销售机会5",  //机会名称
-		Summary:           "王传进的销售机会5",  //概要信息
-		ChanceClassify:    30,           //机会分类
-		ExpectedOrderTime: 0,            //最初预计落单段时间 时间戳
-		CustomName:        "王传进测试",      //客户全称
-		BusinessType:      3,            //业务类型
-		NextfollowUpTime:  1715097600,   //下次跟进时间戳
-		Types:             1,            //处理方式 1自办;2转办
-		User:              []int64{935}, //企业用户id
-		CustomId:          300069,       //客户id
-		CreateName:        "企业管理员",
-		ChanceSource:      54,
-		BusinessId:        "",
+
+func TestInitNetwork(t *testing.T) {
+	InitConf()
+	inw := InitNetwork{
+		PositionId:   935,
+		EntId:        221,
+		DeptId:       498,
+		UserId:       195,
+		EntName:      "安徽公共资源交易集团项目管理有限公司",
+		BusinessType: "",
 	}
-	status, _ := chance.Add(context.Background())
-	log.Println(status)
+	inw.Init()
 }

+ 7 - 0
api/internal/types/types.go

@@ -149,15 +149,22 @@ type UpdateInitInfoReq struct {
 	Company      string `json:"company,optional"`
 	EntId        int64  `header:"entId,optional"`
 	MgoUserId    string `header:"mgoUserId,optional"` //原userId
+	NewUserId    int64  `header:"newUserId"`
+	AccountId    int64  `header:"accountId,optional"`
 	PositionId   int64  `header:"positionId,optional"`
 	PositionType int64  `header:"positionType,optional"`
 	EntUserId    int64  `header:"entUserId,optional"`
+	EntRole      int64  `header:"entRole,optional"`
+	EntName      string `header:"entName,optional"`
+	EntDeptId    int64  `header:"entDeptId,optional"`
 }
 
 type FindInitInfoReq struct {
 	EntId        int64  `header:"entId,optional"`
 	MgoUserId    string `header:"mgoUserId,optional"` //原userId
 	PositionType int64  `header:"positionType,optional"`
+	NewUserId    int64  `header:"newUserId"`
+	AccountId    int64  `header:"accountId,optional"`
 	PositionId   int64  `header:"positionId,optional"`
 	EntUserId    int64  `header:"entUserId,optional"`
 }

+ 18 - 15
api/networkmanage.api

@@ -141,6 +141,9 @@ type (
 		PositionId   int64  `header:"positionId,optional"`
 		PositionType int64  `header:"positionType,optional"`
 		EntUserId    int64  `header:"entUserId,optional"`
+		EntRole      int64  `header:"entRole,optional"`
+		EntName      string `header:"entName,optional"`
+		EntDeptId    int64  `header:"entDeptId,optional"`
 	}
 	FindInitInfoReq {
 		EntId        int64  `header:"entId,optional"`
@@ -172,63 +175,63 @@ service networkManage {
 	@doc "人脉可达潜客业主列表"
 	@handler ownerList
 	post /networkManage/owner/list (OwnerListReq) returns (Reply)
-
+	
 	@doc "人脉可达商机列表"
 	@handler projectList
 	post /networkManage/network/project/list (ProjectListReq) returns (Reply)
-
+	
 	@doc "项目公关渠道分析-项目名称联想"
 	@handler PrPnameAss
 	post /networkManage/pr/pname/ass (PnameAssReq) returns (Reply)
-
+	
 	@doc "项目公关渠道分析-与业主合作历史"
 	@handler CoopHistoryList
 	post /networkManage/pr/project/analyse (CoopHistoryReq) returns (Reply)
-
+	
 	@doc "人脉库-添加/修改人脉"
 	@handler addOrUpdate
 	post /networkManage/network/addOrUpdate (AddOrUpdateReq) returns (Reply)
-
+	
 	@doc "人脉库-业主名称联想"
 	@handler associate
 	post /networkManage/network/associate (AssociateReq) returns (Reply)
-
+	
 	@doc "人脉库-全部人脉项目"
 	@handler allProject
 	post /networkManage/network/allProject (AllprojectReq) returns (Reply)
-
+	
 	@doc "人脉库-列表"
 	@handler networkList
 	post /networkManage/network/networkList (NetWorkListReq) returns (Reply)
-
+	
 	@doc "情报详情"
 	@handler infoDetail
 	post /networkManage/infomation/detail (InfoDetailReq) returns (Reply)
-
+	
 	@doc "人脉项目分析-业主合作历史"
 	@handler projectHistory
 	post /networkManage/pr/project/history (PrjectHistoryReq) returns (Reply)
-
+	
 	@doc "可介绍业主路径"
 	@handler ownerRoute
 	post /networkManage/owner/route (RouteOwnerListReq) returns (Reply)
-
+	
 	@doc "可介绍业主合作次数"
 	@handler ownerCooperate
 	post /networkManage/owner/cooperate (CooperateOwnerListReq) returns (Reply)
-
+	
 	@doc "公关渠道-业主监控项目找人脉"
 	@handler PrMonitorList
 	post /networkManage/pr/monitor/list (PrMonitorListReq) returns (Reply)
-
+	
 	@doc "公关渠道-标讯收藏项目找人脉"
 	@handler PrCollectList
 	post /networkManage/pr/collect/list (PrCollectListReq) returns (Reply)
-
+	
 	@doc "初始化设置查看"
 	@handler findInitInfo
 	post /networkManage/init/findInitInfo (FindInitInfoReq) returns (Reply)
-
+	
 	@doc "初始化设置"
 	@handler updateInitInfo
 	post /networkManage/init/updateInitInfo (UpdateInitInfoReq) returns (Reply)