|
@@ -4,6 +4,7 @@ import (
|
|
|
"context"
|
|
|
"database/sql"
|
|
|
"fmt"
|
|
|
+ "log"
|
|
|
"math"
|
|
|
"strings"
|
|
|
"sync"
|
|
@@ -31,6 +32,11 @@ type networkTreeChild struct {
|
|
|
Id string
|
|
|
Type int
|
|
|
}
|
|
|
+type projectInfo struct {
|
|
|
+ BuyerCount int
|
|
|
+ ProjectCount int
|
|
|
+ ProjectAmount float64
|
|
|
+}
|
|
|
|
|
|
//人脉库-添加/修改人脉
|
|
|
func (n *network) AddOrUpdate(in *types.AddOrUpdateReq) *types.Reply {
|
|
@@ -95,44 +101,58 @@ func (n *network) AddOrUpdate(in *types.AddOrUpdateReq) *types.Reply {
|
|
|
}
|
|
|
|
|
|
//人脉库-业主名称联想
|
|
|
-func (n *network) Associate(in *types.AssociateReq) *types.Reply {
|
|
|
+func (n *network) Associate(in *types.AssociateReq) (reply *types.Reply) {
|
|
|
//类型;firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 middleman_owner:中间人-业主 middleman_project:中间人-项目 agency:招标代理机构
|
|
|
res := []map[string]interface{}{}
|
|
|
+ reply = &types.Reply{Data: res}
|
|
|
+ in.Name = strings.TrimSpace(in.Name)
|
|
|
+ if in.Name == "" {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ pageSize := 10
|
|
|
if in.Type == "adiffb" {
|
|
|
probusfors := NetworkCom.GetMyProbusfor(in.EntAccountId)
|
|
|
if len(probusfors) > 0 {
|
|
|
args := []interface{}{in.EntName}
|
|
|
wh, newArgs := NetworkCom.WhArgs(probusfors)
|
|
|
args = append(args, newArgs...)
|
|
|
- q := `select b.winner,b.winner_id from information.transaction_info a
|
|
|
- inner join information.transaction_info b on (has(a.winner, ?) and a.buyer_id=b.buyer_id and hasAny(b.property_form,[` + wh + `])`
|
|
|
- if in.Name != "" {
|
|
|
- q += ` and b.winner like ?`
|
|
|
- args = append(args, "%"+in.Name+"%")
|
|
|
- }
|
|
|
- q += `) order by b.winner`
|
|
|
+ q := `select DISTINCT b.winner_id,b.winner from information.transaction_info a
|
|
|
+ inner join information.transaction_info b on (has(a.winner, ?) and a.buyer_id<>'' and a.buyer_id=b.buyer_id and hasAny(b.property_form,[` + wh + `])) ORDER BY b.project_id`
|
|
|
rows, err := ClickhouseConn.Query(context.Background(), q, args...)
|
|
|
if err != nil {
|
|
|
logx.Error(err)
|
|
|
} else {
|
|
|
+ repeat := map[string]bool{}
|
|
|
for rows.Next() {
|
|
|
var (
|
|
|
- company_name string
|
|
|
- company_id string
|
|
|
+ winner_id []string
|
|
|
+ winner []string
|
|
|
)
|
|
|
- if err := rows.Scan(&company_name, &company_id); err != nil {
|
|
|
+ if err := rows.Scan(&winner_id, &winner); err != nil {
|
|
|
logx.Error(err)
|
|
|
continue
|
|
|
}
|
|
|
- res = append(res, map[string]interface{}{
|
|
|
- "company_name": company_name,
|
|
|
- "company_id": company_id,
|
|
|
- })
|
|
|
+ for k, v := range winner {
|
|
|
+ if repeat[v] || !strings.Contains(v, in.Name) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ repeat[v] = true
|
|
|
+ if k >= len(winner_id) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ res = append(res, map[string]interface{}{
|
|
|
+ "company_name": v,
|
|
|
+ "company_id": winner_id[k],
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
rows.Close()
|
|
|
if err := rows.Err(); err != nil {
|
|
|
logx.Error(err)
|
|
|
}
|
|
|
+ if len(res) > pageSize {
|
|
|
+ res = res[:pageSize]
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
@@ -149,7 +169,9 @@ func (n *network) Associate(in *types.AssociateReq) *types.Reply {
|
|
|
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, ",")))
|
|
|
+ q := fmt.Sprintf(`{"query":{"bool":{"must":[%s]}},"size":%d,"_source":["id","company_name"]}`, strings.Join(must, ","), pageSize)
|
|
|
+ logx.Info("人脉库-业主名称联想", q)
|
|
|
+ datas := VarEs.Get("ent_info", "ent_info", q)
|
|
|
if datas != nil {
|
|
|
for _, v := range *datas {
|
|
|
res = append(res, map[string]interface{}{
|
|
@@ -159,13 +181,12 @@ func (n *network) Associate(in *types.AssociateReq) *types.Reply {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return &types.Reply{
|
|
|
- Data: res,
|
|
|
- }
|
|
|
+ reply.Data = res
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
//人脉库-全部人脉项目
|
|
|
-func (n *network) Allproject(in *types.AllprojectReq) (reply *types.Reply) {
|
|
|
+func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
|
|
|
pool := make(chan bool, 5)
|
|
|
wait := &sync.WaitGroup{}
|
|
|
lock := &sync.Mutex{}
|
|
@@ -199,6 +220,7 @@ func (n *network) Allproject(in *types.AllprojectReq) (reply *types.Reply) {
|
|
|
logx.Error(err)
|
|
|
continue
|
|
|
}
|
|
|
+ log.Println(company_id, company_name, name)
|
|
|
if _, ok := nameIndex[name]; !ok {
|
|
|
nameIndex[name] = len(list)
|
|
|
list = append(list, &networkTree{
|
|
@@ -235,7 +257,7 @@ func (n *network) Allproject(in *types.AllprojectReq) (reply *types.Reply) {
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- q := `SELECT a.company_id,a.company_name,b.itype AS TYPE,a.contact_person AS person,a.contact_phone AS phone,COUNT(b.id) AS ipc FROM crm.connection a
|
|
|
+ q := `SELECT a.company_id,a.company_name,a.itype,COUNT(b.id) AS ipc FROM crm.connection a
|
|
|
LEFT JOIN crm.connection_introduce b ON (b.position_id=? AND b.itype=2 AND a.id=b.connection_id) WHERE a.position_id=?`
|
|
|
args := []interface{}{in.PositionId, in.PositionId}
|
|
|
if in.Name != "" {
|
|
@@ -272,7 +294,7 @@ func (n *network) Allproject(in *types.AllprojectReq) (reply *types.Reply) {
|
|
|
wait.Done()
|
|
|
}()
|
|
|
itype := IntAll(v["itype"])
|
|
|
- if itype <= 0 || itype >= len(list) {
|
|
|
+ if itype <= 0 || itype > len(list) {
|
|
|
return
|
|
|
}
|
|
|
ntc := &networkTreeChild{
|
|
@@ -295,8 +317,8 @@ func (n *network) Allproject(in *types.AllprojectReq) (reply *types.Reply) {
|
|
|
}
|
|
|
lock.Lock()
|
|
|
count += ntc.Count
|
|
|
- list[itype].Count += ntc.Count
|
|
|
- list[itype].Children = append(list[itype].Children, ntc)
|
|
|
+ list[itype-1].Count += ntc.Count
|
|
|
+ list[itype-1].Children = append(list[itype-1].Children, ntc)
|
|
|
lock.Unlock()
|
|
|
}(vt)
|
|
|
}
|
|
@@ -313,46 +335,115 @@ func (n *network) Allproject(in *types.AllprojectReq) (reply *types.Reply) {
|
|
|
|
|
|
//人脉库-列表
|
|
|
func (n *network) List(in *types.NetWorkListReq) *types.Reply {
|
|
|
- q := `select company_id,company_name,itype as type,contact_person as person,contact_phone as phone from crm.connection where position_id=?`
|
|
|
+ q := `select a.company_id,a.company_name,a.itype,a.contact_person as person,a.contact_phone as phone,count(if(b.itype=1,1,null)) as buyer_count,count(if(b.itype=2,1,null)) as project_count,GROUP_CONCAT(b.relate_id) as relate_id,a.create_time from crm.connection a
|
|
|
+ left join crm.connection_introduce b on (a.id=b.connection_id) where a.position_id=?`
|
|
|
args := []interface{}{in.PositionId}
|
|
|
if in.Type != "" {
|
|
|
- q += ` and itype=?`
|
|
|
+ q += ` and a.itype=?`
|
|
|
args = append(args, n.TypeConvert(in.Type))
|
|
|
}
|
|
|
if in.Starttime != "" {
|
|
|
- q += ` and create_time>=?`
|
|
|
+ q += ` and a.create_time>=?`
|
|
|
args = append(args, in.Starttime)
|
|
|
}
|
|
|
if in.Endtime != "" {
|
|
|
- q += ` and create_time<=?`
|
|
|
+ q += ` and a.create_time<=?`
|
|
|
args = append(args, in.Endtime)
|
|
|
}
|
|
|
if in.Name != "" {
|
|
|
- q += ` and company_name like ?`
|
|
|
+ q += ` and a.company_name like ?`
|
|
|
args = append(args, "%"+in.Name+"%")
|
|
|
}
|
|
|
- q += ` order by create_time desc`
|
|
|
- list := CrmMysql.SelectBySql(q, args...)
|
|
|
- finalList := []map[string]interface{}{}
|
|
|
- length := int64(len(*list))
|
|
|
- var pageSize int64 = 10
|
|
|
- total_page := int64(math.Ceil(float64(length) / float64(pageSize)))
|
|
|
+ q += ` GROUP BY a.id order by a.create_time desc`
|
|
|
+ listTemp := CrmMysql.SelectBySql(q, args...)
|
|
|
+ supplier_array, adiffb_array, agency_array, middleman_array := []string{}, []string{}, []string{}, []string{}
|
|
|
+ for _, v := range *listTemp {
|
|
|
+ switch Int64All(v["itype"]) {
|
|
|
+ case 2:
|
|
|
+ supplier_array = append(supplier_array, ObjToString(v["company_id"]))
|
|
|
+ case 3:
|
|
|
+ adiffb_array = append(adiffb_array, ObjToString(v["company_id"]))
|
|
|
+ case 4:
|
|
|
+ if relate_id := ObjToString(v["relate_id"]); relate_id != "" {
|
|
|
+ middleman_array = append(middleman_array, strings.Split(relate_id, ",")...)
|
|
|
+ }
|
|
|
+ case 5:
|
|
|
+ agency_array = append(agency_array, ObjToString(v["company_id"]))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //
|
|
|
firstparty_count, supplier_count, adiffb_count, middleman_count, agency_count := 0, 0, 0, 0, 0
|
|
|
- if length > 0 {
|
|
|
- for _, v := range *list {
|
|
|
- switch Int64All(v["itype"]) {
|
|
|
- case 1:
|
|
|
- firstparty_count++
|
|
|
- case 2:
|
|
|
- supplier_count++
|
|
|
- case 3:
|
|
|
- adiffb_count++
|
|
|
- case 4:
|
|
|
- middleman_count++
|
|
|
- case 5:
|
|
|
- agency_count++
|
|
|
+ list := []map[string]interface{}{}
|
|
|
+ supplier_project := n.Introduce_Agency(supplier_array)
|
|
|
+ adiffb_project := n.Introduce_Supplier(adiffb_array)
|
|
|
+ agency_project := n.Introduce_Agency(agency_array)
|
|
|
+ middleman_project := n.Introduce_Middleman(middleman_array)
|
|
|
+ for _, v := range *listTemp {
|
|
|
+ itype := ""
|
|
|
+ buyer_count, project_count, expect_amount := 0, 0, float64(0)
|
|
|
+ company_id := ObjToString(v["company_id"])
|
|
|
+ switch Int64All(v["itype"]) {
|
|
|
+ case 1:
|
|
|
+ itype = "甲方"
|
|
|
+ firstparty_count++
|
|
|
+ case 2:
|
|
|
+ itype = "供应商"
|
|
|
+ supplier_count++
|
|
|
+ if supplier_project[company_id] != nil {
|
|
|
+ buyer_count = supplier_project[company_id].BuyerCount
|
|
|
+ project_count = supplier_project[company_id].ProjectCount
|
|
|
+ expect_amount = supplier_project[company_id].ProjectAmount
|
|
|
+ }
|
|
|
+ case 3:
|
|
|
+ itype = "同甲异业渠道"
|
|
|
+ adiffb_count++
|
|
|
+ if adiffb_project[company_id] != nil {
|
|
|
+ buyer_count = adiffb_project[company_id].BuyerCount
|
|
|
+ project_count = adiffb_project[company_id].ProjectCount
|
|
|
+ expect_amount = adiffb_project[company_id].ProjectAmount
|
|
|
+ }
|
|
|
+ case 4:
|
|
|
+ itype = "中间人"
|
|
|
+ middleman_count++
|
|
|
+ buyer_count = IntAll(v["buyer_count"])
|
|
|
+ project_count = IntAll(v["project_count"])
|
|
|
+ if relate_id := ObjToString(v["relate_id"]); relate_id != "" {
|
|
|
+ for _, v := range strings.Split(relate_id, ",") {
|
|
|
+ if middleman_project[v] != nil {
|
|
|
+ expect_amount += middleman_project[v].ProjectAmount
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if middleman_project[company_id] != nil {
|
|
|
+ expect_amount = middleman_project[company_id].ProjectAmount
|
|
|
+ }
|
|
|
+ case 5:
|
|
|
+ itype = "招标代理机构"
|
|
|
+ agency_count++
|
|
|
+ if agency_project[company_id] != nil {
|
|
|
+ buyer_count = agency_project[company_id].BuyerCount
|
|
|
+ project_count = agency_project[company_id].ProjectCount
|
|
|
+ expect_amount = agency_project[company_id].ProjectAmount
|
|
|
}
|
|
|
}
|
|
|
+ list = append(list, map[string]interface{}{
|
|
|
+ "company_id": company_id,
|
|
|
+ "company_name": v["company_name"],
|
|
|
+ "type": itype,
|
|
|
+ "person": v["person"],
|
|
|
+ "phone": v["phone"],
|
|
|
+ "buyer_count": buyer_count,
|
|
|
+ "monitor_count": 0,
|
|
|
+ "expect_amount": expect_amount,
|
|
|
+ "project_count": project_count,
|
|
|
+ "create_time": v["create_time"],
|
|
|
+ })
|
|
|
+ }
|
|
|
+ length := int64(len(list))
|
|
|
+ var pageSize int64 = 10
|
|
|
+ total_page := int64(math.Ceil(float64(length) / float64(pageSize)))
|
|
|
+ finalList := []map[string]interface{}{}
|
|
|
+ if length > 0 {
|
|
|
if in.Current_page <= 0 {
|
|
|
in.Current_page = 1
|
|
|
}
|
|
@@ -364,7 +455,7 @@ func (n *network) List(in *types.NetWorkListReq) *types.Reply {
|
|
|
if end > length {
|
|
|
end = length
|
|
|
}
|
|
|
- finalList = (*list)[start:end]
|
|
|
+ finalList = list[start:end]
|
|
|
}
|
|
|
return &types.Reply{
|
|
|
Data: map[string]interface{}{
|
|
@@ -379,6 +470,115 @@ func (n *network) List(in *types.NetWorkListReq) *types.Reply {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+//
|
|
|
+func (n *network) Introduce_Supplier(values []string) map[string]*projectInfo {
|
|
|
+ vm := map[string]*projectInfo{}
|
|
|
+ for _, v := range values {
|
|
|
+ vm[v] = &projectInfo{}
|
|
|
+ }
|
|
|
+ wh, newArgs := NetworkCom.WhArgs(values)
|
|
|
+ rows, err := ClickhouseConn.Query(context.Background(), `select a.winner_id,count(a.buyer_id) AS buyer_count,count(b.project_id) AS project_count,sum(b.project_money) AS project_amount from information.transaction_info a
|
|
|
+ inner join information.transaction_info b on (hasAny(a.winner_id,[`+wh+`]) and a.buyer_id=b.buyer_id)
|
|
|
+ group by a.winner_id`, newArgs...)
|
|
|
+ if err != nil {
|
|
|
+ logx.Error(err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ for rows.Next() {
|
|
|
+ var (
|
|
|
+ winner_id []string
|
|
|
+ buyer_count uint64
|
|
|
+ project_count uint64
|
|
|
+ project_amount float64
|
|
|
+ )
|
|
|
+ if err := rows.Scan(&winner_id, &buyer_count, &project_count, &project_amount); err != nil {
|
|
|
+ logx.Error(err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ for _, v := range winner_id {
|
|
|
+ if vm[v] == nil {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ vm[v].BuyerCount += int(buyer_count)
|
|
|
+ vm[v].ProjectCount += int(project_count)
|
|
|
+ vm[v].ProjectAmount += project_amount
|
|
|
+ }
|
|
|
+ }
|
|
|
+ rows.Close()
|
|
|
+ if err := rows.Err(); err != nil {
|
|
|
+ logx.Error(err)
|
|
|
+ }
|
|
|
+ return vm
|
|
|
+}
|
|
|
+
|
|
|
+//
|
|
|
+func (n *network) Introduce_Agency(values []string) map[string]*projectInfo {
|
|
|
+ vm := map[string]*projectInfo{}
|
|
|
+ for _, v := range values {
|
|
|
+ vm[v] = &projectInfo{}
|
|
|
+ }
|
|
|
+ wh, newArgs := NetworkCom.WhArgs(values)
|
|
|
+ rows, err := ClickhouseConn.Query(context.Background(), `select a.agency_id,count(a.buyer_id) AS buyer_count,count(b.project_id) AS project_count,sum(b.project_money) AS project_amount from information.transaction_info a
|
|
|
+ inner join information.transaction_info b on (agency_id in (`+wh+`) and a.buyer_id=b.buyer_id)
|
|
|
+ group by a.agency_id`, newArgs...)
|
|
|
+ if err != nil {
|
|
|
+ logx.Error(err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ for rows.Next() {
|
|
|
+ var (
|
|
|
+ agency_id string
|
|
|
+ buyer_count uint64
|
|
|
+ project_count uint64
|
|
|
+ project_amount float64
|
|
|
+ )
|
|
|
+ if err := rows.Scan(&agency_id, &buyer_count, &project_count, &project_amount); err != nil {
|
|
|
+ logx.Error(err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ if vm[agency_id] == nil {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ vm[agency_id].BuyerCount += int(buyer_count)
|
|
|
+ vm[agency_id].ProjectCount += int(project_count)
|
|
|
+ vm[agency_id].ProjectAmount += project_amount
|
|
|
+ }
|
|
|
+ rows.Close()
|
|
|
+ if err := rows.Err(); err != nil {
|
|
|
+ logx.Error(err)
|
|
|
+ }
|
|
|
+ return vm
|
|
|
+}
|
|
|
+
|
|
|
+//
|
|
|
+func (n *network) Introduce_Middleman(values []string) map[string]*projectInfo {
|
|
|
+ vm := map[string]*projectInfo{}
|
|
|
+ wh, newArgs := NetworkCom.WhArgs(values)
|
|
|
+ rows, err := ClickhouseConn.Query(context.Background(), `select project_id,project_money from information.transaction_info where project_id in (`+wh+`)`, newArgs...)
|
|
|
+ if err != nil {
|
|
|
+ logx.Error(err)
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+ for rows.Next() {
|
|
|
+ var (
|
|
|
+ project_id string
|
|
|
+ project_money float64
|
|
|
+ )
|
|
|
+ if err := rows.Scan(&project_id, &project_money); err != nil {
|
|
|
+ logx.Error(err)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ vm[project_id] = &projectInfo{
|
|
|
+ ProjectAmount: project_money,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ rows.Close()
|
|
|
+ if err := rows.Err(); err != nil {
|
|
|
+ logx.Error(err)
|
|
|
+ }
|
|
|
+ return vm
|
|
|
+}
|
|
|
+
|
|
|
//
|
|
|
func (n *network) TypeConvert(itype string) int {
|
|
|
//firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构
|