wangchuanjin 9 meses atrás
pai
commit
f68a574de0

+ 5 - 1
api/internal/service/initNetwork.go

@@ -71,7 +71,7 @@ func (i *InitNetwork) Init() {
 		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...)
+		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(topscopeclass,[`+wh+`])`, args...)
 		if err != nil {
 			logx.Error(err)
 			return
@@ -143,11 +143,15 @@ func (i *InitNetwork) Init() {
 	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
+	typeLimit := map[int]int{}
 	for _, v := range array {
 		if v.ContactInfo == nil || v.ContactInfo.Phone == "" || v.ContactInfo.Name == "" {
 			continue
+		} else if typeLimit[v.Itype] >= 100 {
+			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 {
+			typeLimit[v.Itype] = typeLimit[v.Itype] + 1
 			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 {

+ 36 - 35
api/internal/service/network.go

@@ -239,12 +239,12 @@ func (n *network) Associate(in *types.AssociateReq) (reply *types.Reply) {
 	}
 	pageSize := 10
 	if in.Type == "adiffb" {
-		probusfors := NetworkCom.GetMyProbusfor(in.EntAccountId)
-		if len(probusfors) > 0 {
+		businessType := strings.Split(FindBusiness(in.EntId, in.MgoUserId), ",")
+		if len(businessType) > 0 {
 			args := []interface{}{in.EntName}
-			wh, newArgs := NetworkCom.WhArgs(probusfors)
+			wh, newArgs := NetworkCom.WhArgs(businessType)
 			args = append(args, newArgs...)
-			q := `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 + `])=0 ORDER BY project_id`
+			q := `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(topscopeclass,[` + wh + `])=0 ORDER BY project_id`
 			rows, err := ClickhouseConn.Query(context.Background(), q, args...)
 			if err != nil {
 				logx.Error(err)
@@ -322,7 +322,7 @@ func (n *network) Associate(in *types.AssociateReq) (reply *types.Reply) {
 //人脉库-全部人脉项目
 func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 	reply = &types.Reply{}
-	probusfors := NetworkCom.GetMyProbusfor(in.EntAccountId)
+	businessType := strings.Split(FindBusiness(in.EntId, in.MgoUserId), ",")
 	var count int64
 	var list []*networkTree
 	firstpartyChild := map[string][]*firstpartyNetwork{}
@@ -330,7 +330,7 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 		if in.Type == "firstparty" {
 			fpn := n.FirstpartyNetwork(in.Name, []string{in.Id})
 			if fpn[in.Id] != nil {
-				firstparty := n.Introduce_Firstparty(fpn, map[string]bool{}, probusfors)
+				firstparty := n.Introduce_Firstparty(fpn, map[string]bool{}, businessType)
 				nameIndex := map[string]int{}
 				for _, v := range fpn[in.Id] {
 					if _, ok := nameIndex[v.Name]; !ok {
@@ -360,7 +360,7 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 			sqlAppend1 += ` and a.company_name like ?`
 			args = append(args, "%"+in.Name+"%")
 		}
-		aio := n.AllIntroduceOwner(sqlAppend1, "", args, true, probusfors, map[string]bool{})
+		aio := n.AllIntroduceOwner(sqlAppend1, "", args, true, businessType, map[string]bool{})
 		firstpartyChild = aio.FirstpartyNetwork
 		list = []*networkTree{
 			&networkTree{
@@ -567,6 +567,7 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 
 //人脉库-列表
 func (n *network) List(in *types.NetWorkListReq) *types.Reply {
+	in.Project_matchme = 1
 	if in.Page_size <= 0 {
 		in.Page_size = 10
 	}
@@ -636,16 +637,16 @@ func (n *network) List(in *types.NetWorkListReq) *types.Reply {
 	//
 	list := []*map[string]interface{}{}
 	isTjProject := true
-	probusfors := []string{}
+	businessType := []string{}
 	if in.Project_matchme == 1 {
-		probusfors = NetworkCom.GetMyProbusfor(in.EntAccountId)
-		if len(probusfors) == 0 {
+		businessType = strings.Split(FindBusiness(in.EntId, in.MgoUserId), ",")
+		if len(businessType) == 0 {
 			isTjProject = false
 		}
 	}
 	if isTjProject {
 		entMonitor := NetworkCom.EntMonitor(in.UserId)
-		aio := n.AllIntroduceOwner(sqlAppend1, sqlAppend2, args, isTjProject, probusfors, entMonitor)
+		aio := n.AllIntroduceOwner(sqlAppend1, sqlAppend2, args, isTjProject, businessType, entMonitor)
 		for _, v := range aio.Networks {
 			itype := ""
 			buyer_count, project_count, expect_amount, monitor_count := int64(0), int64(0), float64(0), int64(0)
@@ -888,7 +889,7 @@ func (n *network) FirstpartyNetwork(name string, values []string) map[string][]*
 }
 
 //
-func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, entMonitor map[string]bool, probusfors []string) map[string]*projectInfo {
+func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, entMonitor map[string]bool, businessType []string) map[string]*projectInfo {
 	values := []string{}
 	vm := map[string]*projectInfo{}
 	for _, v := range fpn {
@@ -903,9 +904,9 @@ func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, entM
 	}
 	wh, args := NetworkCom.WhArgs(values)
 	q := `select buyer_id,count(project_id) AS project_count,sum(project_money) AS project_amount,groupUniqArray(project_id) from information.transaction_info where buyer_id in (` + wh + `)`
-	if len(probusfors) > 0 {
-		newWh, newArgs := NetworkCom.WhArgs(probusfors)
-		q += ` and hasAny(property_form,[` + newWh + `])`
+	if len(businessType) > 0 {
+		newWh, newArgs := NetworkCom.WhArgs(businessType)
+		q += ` and hasAny(topscopeclass,[` + newWh + `])`
 		args = append(args, newArgs...)
 	}
 	q += ` and project_bidstatus>1 group by buyer_id`
@@ -958,7 +959,7 @@ func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, entM
 }
 
 //
-func (n *network) Introduce_Supplier(values []string, entMonitor map[string]bool, probusfors []string) map[string]*projectInfo {
+func (n *network) Introduce_Supplier(values []string, entMonitor map[string]bool, businessType []string) map[string]*projectInfo {
 	if len(values) == 0 {
 		return map[string]*projectInfo{}
 	}
@@ -1008,11 +1009,11 @@ func (n *network) Introduce_Supplier(values []string, entMonitor map[string]bool
 			logx.Error(err)
 		}
 	}
-	return n.MakeProjectInfo(buyers, vbs, probusfors, entMonitor)
+	return n.MakeProjectInfo(buyers, vbs, businessType, entMonitor)
 }
 
 //
-func (n *network) Introduce_Agency(values []string, entMonitor map[string]bool, probusfors []string) map[string]*projectInfo {
+func (n *network) Introduce_Agency(values []string, entMonitor map[string]bool, businessType []string) map[string]*projectInfo {
 	if len(values) == 0 {
 		return map[string]*projectInfo{}
 	}
@@ -1052,20 +1053,20 @@ func (n *network) Introduce_Agency(values []string, entMonitor map[string]bool,
 	if err := rows.Err(); err != nil {
 		logx.Error(err)
 	}
-	return n.MakeProjectInfo(buyers, vbs, probusfors, entMonitor)
+	return n.MakeProjectInfo(buyers, vbs, businessType, entMonitor)
 }
 
 //
-func (n *network) Introduce_Middleman(values []string, entMonitor map[string]bool, probusfors []string) map[string]*projectInfo {
+func (n *network) Introduce_Middleman(values []string, entMonitor map[string]bool, businessType []string) map[string]*projectInfo {
 	result := map[string]*projectInfo{}
 	if len(values) == 0 {
 		return result
 	}
 	wh, args := NetworkCom.WhArgs(values)
 	q := `select DISTINCT project_id,project_money from information.transaction_info where project_id in (` + wh + `) and project_bidstatus>1`
-	if len(probusfors) > 0 {
-		newWh, newArgs := NetworkCom.WhArgs(probusfors)
-		q += ` and hasAny(property_form,[` + newWh + `])`
+	if len(businessType) > 0 {
+		newWh, newArgs := NetworkCom.WhArgs(businessType)
+		q += ` and hasAny(topscopeclass,[` + newWh + `])`
 		args = append(args, newArgs...)
 	}
 	rows, err := ClickhouseConn.Query(context.Background(), q, args...)
@@ -1162,16 +1163,16 @@ func (n *network) GetQyxyId(ids []string) map[string]string {
 }
 
 //
-func (n *network) BuyerProjectInfo(ids []string, probusfors []string) map[string]*projectInfo {
+func (n *network) BuyerProjectInfo(ids []string, businessType []string) map[string]*projectInfo {
 	vm := map[string]*projectInfo{}
 	if len(ids) == 0 {
 		return vm
 	}
 	wh, args := NetworkCom.WhArgs(ids)
 	q := `select buyer_id,count(DISTINCT project_id) AS project_count,sum(project_money) AS project_amount,groupUniqArray(project_id) from information.transaction_info where buyer_id in (` + wh + `) and project_bidstatus>1`
-	if len(probusfors) > 0 {
-		newWh, newArgs := NetworkCom.WhArgs(probusfors)
-		q += ` and hasAny(property_form,[` + newWh + `])`
+	if len(businessType) > 0 {
+		newWh, newArgs := NetworkCom.WhArgs(businessType)
+		q += ` and hasAny(topscopeclass,[` + newWh + `])`
 		args = append(args, newArgs...)
 	}
 	q += ` group by buyer_id`
@@ -1206,8 +1207,8 @@ func (n *network) BuyerProjectInfo(ids []string, probusfors []string) map[string
 }
 
 //
-func (n *network) MakeProjectInfo(buyers []string, vbs map[string][]*idName, probusfors []string, entMonitor map[string]bool) map[string]*projectInfo {
-	pis := n.BuyerProjectInfo(buyers, probusfors)
+func (n *network) MakeProjectInfo(buyers []string, vbs map[string][]*idName, businessType []string, entMonitor map[string]bool) map[string]*projectInfo {
+	pis := n.BuyerProjectInfo(buyers, businessType)
 	vm := map[string]*projectInfo{}
 	for k, v := range vbs {
 		pi := &projectInfo{
@@ -1236,7 +1237,7 @@ func (n *network) MakeProjectInfo(buyers []string, vbs map[string][]*idName, pro
 }
 
 //
-func (n *network) AllIntroduceOwner(sqlAppend1, sqlAppend2 string, args []interface{}, isTjProject bool, probusfors []string, entMonitor map[string]bool) *introduceOwnerProject {
+func (n *network) AllIntroduceOwner(sqlAppend1, sqlAppend2 string, args []interface{}, isTjProject bool, businessType []string, entMonitor map[string]bool) *introduceOwnerProject {
 	q := `select a.id,a.company_id,a.company_name,a.qyxy_id,a.itype,a.contact_person as person,a.contact_phone as phone,count(DISTINCT if(b.itype=1,b.relate_id,null)) as buyer_count,count(DISTINCT if(b.itype=2,b.relate_id,null)) as project_count,GROUP_CONCAT(IF(b.itype=1,b.relate_id,NULL)) AS relate_buyer_id,GROUP_CONCAT(IF(b.itype=1,b.relate_name,NULL)) AS relate_buyer_name,GROUP_CONCAT(IF(b.itype=2,b.relate_id,NULL)) AS relate_project_id,a.create_time from crm.connection a 
 		left join crm.connection_introduce b on (a.position_id=? and b.position_id=? and a.id=b.connection_id) where a.position_id=?` + sqlAppend1 + ` GROUP BY a.id order by a.create_time desc` + sqlAppend2
 	listTemp := CrmMysql.SelectBySql(q, args...)
@@ -1285,11 +1286,11 @@ func (n *network) AllIntroduceOwner(sqlAppend1, sqlAppend2 string, args []interf
 	}
 	if isTjProject {
 		iop.FirstpartyNetwork = n.FirstpartyNetwork("", firstparty_array)
-		iop.Firstparty = n.Introduce_Firstparty(iop.FirstpartyNetwork, entMonitor, probusfors)
-		iop.Supplier = n.Introduce_Supplier(supplier_array, entMonitor, probusfors)
-		iop.Adiffb = n.Introduce_Supplier(adiffb_array, entMonitor, probusfors)
-		iop.Agency = n.Introduce_Agency(agency_array, entMonitor, probusfors)
-		iop.Middleman = n.Introduce_Middleman(middleman_project_array, entMonitor, probusfors)
+		iop.Firstparty = n.Introduce_Firstparty(iop.FirstpartyNetwork, entMonitor, businessType)
+		iop.Supplier = n.Introduce_Supplier(supplier_array, entMonitor, businessType)
+		iop.Adiffb = n.Introduce_Supplier(adiffb_array, entMonitor, businessType)
+		iop.Agency = n.Introduce_Agency(agency_array, entMonitor, businessType)
+		iop.Middleman = n.Introduce_Middleman(middleman_project_array, entMonitor, businessType)
 	}
 	return iop
 }

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

@@ -86,6 +86,8 @@ type AddOrUpdateReq struct {
 }
 
 type AssociateReq struct {
+	EntId        int64  `header:"entId"`
+	MgoUserId    string `header:"mgoUserId"`
 	EntAccountId int64  `header:"entAccountId"`
 	EntName      string `header:"entName"`
 	Name         string `json:"name"`
@@ -93,6 +95,8 @@ type AssociateReq struct {
 }
 
 type AllprojectReq struct {
+	EntId        int64  `header:"entId"`
+	MgoUserId    string `header:"mgoUserId"`
 	EntAccountId int64  `header:"entAccountId"`
 	PositionId   int64  `header:"positionId"`
 	Name         string `json:"name,optional"`
@@ -104,6 +108,8 @@ type NetWorkListReq struct {
 	UserId             string `header:"userId"`
 	EntAccountId       int64  `header:"entAccountId"`
 	PositionId         int64  `header:"positionId"`
+	EntId              int64  `header:"entId"`
+	MgoUserId          string `header:"mgoUserId"`
 	Type               string `json:"type,optional"`
 	Name               string `json:"name,optional"`
 	Monitor            int64  `json:"monitor,optional"`

+ 6 - 0
api/networkmanage.api

@@ -80,12 +80,16 @@ type (
 		Type                    string `json:"type"`
 	}
 	AssociateReq {
+		EntId        int64  `header:"entId"`
+		MgoUserId    string `header:"mgoUserId"`
 		EntAccountId int64  `header:"entAccountId"`
 		EntName      string `header:"entName"`
 		Name         string `json:"name"`
 		Type         string `json:"type"`
 	}
 	AllprojectReq {
+		EntId        int64  `header:"entId"`
+		MgoUserId    string `header:"mgoUserId"`
 		EntAccountId int64  `header:"entAccountId"`
 		PositionId   int64  `header:"positionId"`
 		Name         string `json:"name,optional"`
@@ -96,6 +100,8 @@ type (
 		UserId             string `header:"userId"`
 		EntAccountId       int64  `header:"entAccountId"`
 		PositionId         int64  `header:"positionId"`
+		EntId              int64  `header:"entId"`
+		MgoUserId          string `header:"mgoUserId"`
 		Type               string `json:"type,optional"`
 		Name               string `json:"name,optional"`
 		Monitor            int64  `json:"monitor,optional"`