|
@@ -3,6 +3,7 @@ package analysis
|
|
|
|
|
|
import (
|
|
|
. "api"
|
|
|
+ "config"
|
|
|
"db"
|
|
|
"encoding/json"
|
|
|
"entity"
|
|
@@ -11,6 +12,7 @@ import (
|
|
|
qutil "qfw/util"
|
|
|
"qfw/util/jy"
|
|
|
"qfw/util/redis"
|
|
|
+ "sort"
|
|
|
"strings"
|
|
|
"sync"
|
|
|
"time"
|
|
@@ -175,8 +177,25 @@ func (this *Analysis) CsORRsList() {
|
|
|
//客户
|
|
|
if getRes.PCOR == "C" {
|
|
|
potComQ := PCQuery(getRes.Area, getRes.Industry, getRes.BuyerClass, getRes.Business_scope, getRes.Sort_no, getRes.PCOR)
|
|
|
- list := getPCostomers(main_userId, entName, potComQ, getRes.PCOR)
|
|
|
- surpluscount := -1 //剩余数量
|
|
|
+ var list []*PTComs
|
|
|
+ if config.Config.PotentialSwitch {
|
|
|
+ list = CustomersInfo(main_userId, entName, potComQ, getRes.PCOR)
|
|
|
+ } else {
|
|
|
+ list = getPCostomers(main_userId, entName, potComQ, getRes.PCOR)
|
|
|
+ }
|
|
|
+ surpluscount := -1
|
|
|
+ //排序
|
|
|
+ if len(list) > 0 && config.Config.PotentialSwitch {
|
|
|
+ if getRes.Sort_no == 0 {
|
|
|
+ sort.Slice(list, func(i, j int) bool {
|
|
|
+ return list[i].PNCount > list[j].PNCount
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ sort.Slice(list, func(i, j int) bool {
|
|
|
+ return list[i].Budget > list[j].Budget
|
|
|
+ })
|
|
|
+ }
|
|
|
+ } //剩余数量
|
|
|
if isTrial {
|
|
|
c_limitcount = getBAmountInfo(main_userId, getRes.ServiceId)
|
|
|
if len(list) > c_limitcount {
|
|
@@ -199,7 +218,24 @@ func (this *Analysis) CsORRsList() {
|
|
|
}
|
|
|
} else if getRes.PCOR == "R" {
|
|
|
potRivQ := PCQuery(getRes.Area, getRes.Industry, getRes.BuyerClass, getRes.Business_scope, getRes.Sort_no, getRes.PCOR)
|
|
|
- list := getPRivals(main_userId, potRivQ, getRes.PCOR)
|
|
|
+ var list []*PTComs
|
|
|
+ if config.Config.PotentialSwitch {
|
|
|
+ list = PRivals(main_userId, potRivQ, getRes.PCOR)
|
|
|
+ } else {
|
|
|
+ list = getPRivals(main_userId, potRivQ, getRes.PCOR)
|
|
|
+ }
|
|
|
+ //排序
|
|
|
+ if len(list) > 0 && config.Config.PotentialSwitch {
|
|
|
+ if getRes.Sort_no == 0 {
|
|
|
+ sort.Slice(list, func(i, j int) bool {
|
|
|
+ return list[i].PNCount > list[j].PNCount
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ sort.Slice(list, func(i, j int) bool {
|
|
|
+ return list[i].Budget > list[j].Budget
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
surpluscount := -1 //剩余数量
|
|
|
if isTrial {
|
|
|
r_limitcount = getBAmountInfo(main_userId, getRes.ServiceId)
|
|
@@ -393,7 +429,31 @@ type AggregationsBucket struct {
|
|
|
} `json:"count"`
|
|
|
}
|
|
|
|
|
|
-//潜在客户
|
|
|
+//潜在竞争对手--new
|
|
|
+func PRivals(userId string, potRivQ, pcor string) []*PTComs {
|
|
|
+ var regMap = []*PTComs{}
|
|
|
+ //我关注的企业
|
|
|
+ MyFollowEnts := getMyFollowEnts(userId)
|
|
|
+ //非我的潜在竞争对手
|
|
|
+ OutLMyRivals := gerOutLMyRivals(userId)
|
|
|
+ aggs, _ := GetAggs(P_INDEX, P_TYPE, potRivQ)
|
|
|
+ if aggs != nil {
|
|
|
+ if aggsMap_g, ok := aggs.Children("group_field"); ok {
|
|
|
+ var aggsMap []*AggregationsBucket
|
|
|
+ bs, _ := aggsMap_g.Aggregations["buckets"].MarshalJSON()
|
|
|
+ if len(bs) > 0 {
|
|
|
+ json.Unmarshal(bs, &aggsMap)
|
|
|
+ if len(aggsMap) > 0 {
|
|
|
+ regMap = analysisData(aggsMap, MyFollowEnts, OutLMyRivals, pcor)
|
|
|
+ //regMap = analysisDataByWinner(aggsMap, MyFollowEnts, OutLMyRivals, pcor)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return regMap
|
|
|
+}
|
|
|
+
|
|
|
+//潜在客户--new
|
|
|
func CustomersInfo(userId, entName string, potComQ, pcor string) []*PTComs {
|
|
|
var regMap = []*PTComs{}
|
|
|
//获取用户默认企业的客户信息+手动关注的企业信息+不是我的客户信息 此三项都不展示在我的客户列表
|
|
@@ -407,7 +467,7 @@ func CustomersInfo(userId, entName string, potComQ, pcor string) []*PTComs {
|
|
|
if len(bs) > 0 {
|
|
|
json.Unmarshal(bs, &aggsMap)
|
|
|
if len(aggsMap) > 0 {
|
|
|
- regMap = analysisData(aggsMap, MyCustomers)
|
|
|
+ regMap = analysisData(aggsMap, MyCustomers, nil, pcor)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -424,13 +484,12 @@ func getPCostomers(userId, entName string, potComQ, pcor string) []*PTComs {
|
|
|
aggs, _ := GetAggs(P_INDEX, P_TYPE, potComQ)
|
|
|
if aggs != nil {
|
|
|
if aggs_g, ok := aggs.Children("group_field"); ok {
|
|
|
- var aggsMap []*AggregationsBucket
|
|
|
+ var aggsMap []map[string]interface{}
|
|
|
bs, _ := aggs_g.Aggregations["buckets"].MarshalJSON()
|
|
|
if len(bs) > 0 {
|
|
|
json.Unmarshal(bs, &aggsMap)
|
|
|
if len(aggsMap) > 0 {
|
|
|
- //regMap = analysisDataByBuyer(aggsMap, MyCustomers)
|
|
|
- regMap = analysisData(aggsMap, MyCustomers)
|
|
|
+ regMap = analysisDataByBuyer(aggsMap, MyCustomers)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -529,13 +588,14 @@ type PCInfo struct {
|
|
|
}
|
|
|
|
|
|
//采购单位
|
|
|
-func analysisData(res []*AggregationsBucket, mycs map[string]interface{}) []*PTComs {
|
|
|
+func analysisData(res []*AggregationsBucket, mycs map[string]interface{}, omyr map[string]interface{}, pcor string) []*PTComs {
|
|
|
var (
|
|
|
ADRes_r []*PTComs
|
|
|
entersFifty []string
|
|
|
+ entInfos []*entity.EnterQYXYInfo
|
|
|
wg = sync.WaitGroup{}
|
|
|
wc = make(chan bool, 10)
|
|
|
- entInfos = map[string]*entity.EnterQYXYInfo{}
|
|
|
+ entMap = map[string]*AggregationsBucket{}
|
|
|
)
|
|
|
for ak, av := range res {
|
|
|
//清洗无效数据
|
|
@@ -546,13 +606,18 @@ func analysisData(res []*AggregationsBucket, mycs map[string]interface{}) []*PTC
|
|
|
if mycs != nil && mycs[av.Key] != nil {
|
|
|
continue
|
|
|
}
|
|
|
+ //排除移除的我的潜在竞争对手
|
|
|
+ if omyr != nil && omyr[av.Key] != nil {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ entMap[av.Key] = av
|
|
|
//并发查询企业库是否包含此企业信息
|
|
|
entersFifty = append(entersFifty, av.Key)
|
|
|
if len(entersFifty)%50 == 0 || (len(res) == ak+1 && len(entersFifty) > 0) {
|
|
|
wg.Add(1)
|
|
|
wc <- true
|
|
|
go func(entersFifty []string) {
|
|
|
- entInfos = entity.GetEntInfo(entersFifty, "C")
|
|
|
+ entInfos = append(entInfos, entity.GetEntInfo(entersFifty, pcor)...)
|
|
|
wg.Done()
|
|
|
<-wc
|
|
|
}(entersFifty)
|
|
@@ -560,16 +625,28 @@ func analysisData(res []*AggregationsBucket, mycs map[string]interface{}) []*PTC
|
|
|
}
|
|
|
wg.Wait()
|
|
|
}
|
|
|
-
|
|
|
- for _, av := range res {
|
|
|
- if av.Key != "" && entInfos[av.Key] != nil {
|
|
|
- ADRes_r = append(ADRes_r, &PTComs{
|
|
|
- Budget: av.Count.Value,
|
|
|
- Buyer: av.Key,
|
|
|
- PNCount: av.Doc_count,
|
|
|
- WCity: entInfos[av.Key].City,
|
|
|
- WProvince: entInfos[av.Key].Area,
|
|
|
- })
|
|
|
+ if len(entInfos) > 0 {
|
|
|
+ for _, ev := range entInfos {
|
|
|
+ if (ev.Name != "" && entMap[ev.Name] != nil) || (len([]rune(ev.Id)) > 12 && entMap[ev.Id] != nil) {
|
|
|
+ var budget float64 = 0
|
|
|
+ pnCount := 0
|
|
|
+ if entMap[ev.Name] != nil {
|
|
|
+ budget = entMap[ev.Name].Count.Value
|
|
|
+ pnCount = entMap[ev.Name].Doc_count
|
|
|
+ }
|
|
|
+ if entMap[ev.Id] != nil {
|
|
|
+ budget = entMap[ev.Id].Count.Value
|
|
|
+ pnCount = entMap[ev.Id].Doc_count
|
|
|
+ }
|
|
|
+ ADRes_r = append(ADRes_r, &PTComs{
|
|
|
+ Budget: budget,
|
|
|
+ PNCount: pnCount,
|
|
|
+ Buyer: ev.Name,
|
|
|
+ WCity: ev.City,
|
|
|
+ WProvince: ev.Area,
|
|
|
+ EntId: ev.Id,
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
return ADRes_r
|