|
@@ -234,73 +234,48 @@ func Findwinner(buyerArr []string) []map[string]interface{} {
|
|
|
wh1, args1 := common.WhArgs(buyerArr)
|
|
|
args1 = append(args1, args1...)
|
|
|
//供应商 采购单位 供应商 招标代理机构 采购单位 招标代理机构 需要计算合作次数
|
|
|
- winnerSql := `select * from (select
|
|
|
- zbtime,
|
|
|
- project_id,
|
|
|
- project_name,
|
|
|
- buyer_id,
|
|
|
- buyer,
|
|
|
- entId,
|
|
|
- 'supplier' as entType
|
|
|
-from
|
|
|
- transaction_info_all ARRAY
|
|
|
-JOIN winner_id as entId
|
|
|
-where
|
|
|
- buyer_id in (` + wh1 + `)
|
|
|
-UNION ALL
|
|
|
- select
|
|
|
- zbtime,
|
|
|
- project_id,
|
|
|
- project_name,
|
|
|
- buyer_id,
|
|
|
- buyer,
|
|
|
- agency_id as entId,
|
|
|
- 'agent' as entType
|
|
|
-from
|
|
|
- transaction_info_all
|
|
|
-where
|
|
|
- buyer_id in (` + wh1 + `) and agency_id!='') order by zbtime DESC,project_id DESC`
|
|
|
+ winnerSql := `select zbtime,project_id,project_name,buyer_id,buyer,winner_id,winner,agency_id,agency from transaction_info_all ARRAY JOIN winner_id,winner where buyer_id in (` + wh1 + `) order by zbtime DESC,project_id DESC`
|
|
|
winnerArr := SupplierFindConnectionsHandle(winnerSql, args1...)
|
|
|
if winnerArr != nil && len(winnerArr) > 0 {
|
|
|
//企业联系人处理
|
|
|
entIdArr := []string{}
|
|
|
+ entIdMap := map[string]bool{}
|
|
|
for _, v := range winnerArr {
|
|
|
- if v.EntId != "" {
|
|
|
- entIdArr = append(entIdArr, v.EntId)
|
|
|
+ if v.Winner_id != "" {
|
|
|
+ if !entIdMap[v.Winner_id] {
|
|
|
+ entIdArr = append(entIdArr, v.Winner_id)
|
|
|
+ }
|
|
|
+ entIdMap[v.Winner_id] = true
|
|
|
+ }
|
|
|
+ if v.Agency_id != "" {
|
|
|
+ if !entIdMap[v.Agency_id] {
|
|
|
+ entIdArr = append(entIdArr, v.Agency_id)
|
|
|
+ }
|
|
|
+ entIdMap[v.Agency_id] = true
|
|
|
}
|
|
|
}
|
|
|
personMap := map[string]string{}
|
|
|
- entNameMap := map[string]string{}
|
|
|
if len(entIdArr) > 0 {
|
|
|
wh2, args2 := common.WhArgs(entIdArr)
|
|
|
- personSql := `select id,name as personName from ent_contact where id in (` + wh2 + `) ORDER by name`
|
|
|
+ personSql := `select id,name as personName from ent_contact where id in (` + wh2 + `) ORDER by name`
|
|
|
personArr := PersonFindConnectionsHandle(personSql, args2...)
|
|
|
//联系人处理
|
|
|
for _, v := range personArr {
|
|
|
personMap[v.Id] = v.PersonName
|
|
|
}
|
|
|
- entSql := `select id ,company_name as personName from ent_info where id in (` + wh2 + `) ORDER by company_name`
|
|
|
- entNameArr := PersonFindConnectionsHandle(entSql, args2...)
|
|
|
- for _, v := range entNameArr {
|
|
|
- entNameMap[v.Id] = v.PersonName
|
|
|
- }
|
|
|
}
|
|
|
-
|
|
|
winnerMap := map[string]map[string]interface{}{}
|
|
|
agencyMap := map[string]map[string]interface{}{}
|
|
|
agencyIdMap := map[string]bool{}
|
|
|
for _, m := range winnerArr {
|
|
|
- if m.EntId == "" {
|
|
|
+ if m.Winner_id == "" && m.Agency_id == "" {
|
|
|
continue
|
|
|
}
|
|
|
projectId := encrypt.EncodeArticleId2ByCheck(m.Project_id)
|
|
|
projectName := m.Project_name
|
|
|
zbtime := m.Zbtime
|
|
|
- key := fmt.Sprintf("%s_%s", m.Buyer_id, m.EntId)
|
|
|
- if m.EntType == "supplier" {
|
|
|
- buyerId := m.Buyer_id
|
|
|
- winner := entNameMap[m.EntId]
|
|
|
- buyer := m.Buyer
|
|
|
+ if m.Winner_id != "" {
|
|
|
+ key := fmt.Sprintf("%s_%s", m.Buyer_id, m.Winner_id)
|
|
|
if _, ok := winnerMap[key]; ok {
|
|
|
data := winnerMap[key]
|
|
|
data["count"] = gconv.Int64(data["count"]) + 1
|
|
@@ -315,27 +290,27 @@ where
|
|
|
winnerMap[key] = data
|
|
|
} else {
|
|
|
winnerMap[key] = map[string]interface{}{
|
|
|
- "b_id": m.EntId,
|
|
|
- "b_name": entNameMap[m.EntId],
|
|
|
- "a_name": buyer,
|
|
|
- "a_id": buyerId,
|
|
|
+ "b_id": m.Winner_id,
|
|
|
+ "b_name": m.Winner,
|
|
|
+ "a_name": m.Buyer,
|
|
|
+ "a_id": m.Buyer_id,
|
|
|
"sourceType": "supplier",
|
|
|
"zbtime": zbtime,
|
|
|
- "personName": personMap[m.EntId],
|
|
|
+ "personName": personMap[m.Winner_id],
|
|
|
"count": 1,
|
|
|
"list": []map[string]interface{}{
|
|
|
{
|
|
|
"zbtime": zbtime,
|
|
|
- "entName": winner,
|
|
|
+ "entName": m.Winner,
|
|
|
"projectId": projectId,
|
|
|
"projectName": projectName,
|
|
|
},
|
|
|
},
|
|
|
}
|
|
|
}
|
|
|
- } else {
|
|
|
- agencyId := m.EntId
|
|
|
- key = fmt.Sprintf("%s_%s", m.Buyer_id, agencyId)
|
|
|
+ }
|
|
|
+ if m.Agency_id != "" {
|
|
|
+ key := fmt.Sprintf("%s_%s", m.Buyer_id, m.Agency_id)
|
|
|
if _, ok := agencyIdMap[key]; ok {
|
|
|
data := agencyMap[key]
|
|
|
data["count"] = gconv.Int64(data["count"]) + 1
|
|
@@ -351,14 +326,14 @@ where
|
|
|
} else {
|
|
|
agencyIdMap[key] = true
|
|
|
agencyMap[key] = map[string]interface{}{
|
|
|
- "b_id": m.EntId,
|
|
|
- "b_name": entNameMap[m.EntId],
|
|
|
+ "b_id": m.Agency_id,
|
|
|
+ "b_name": m.Agency,
|
|
|
"a_name": m.Buyer,
|
|
|
"a_id": m.Buyer_id,
|
|
|
"sourceType": "agency",
|
|
|
"count": 1,
|
|
|
"zbtime": zbtime,
|
|
|
- "personName": gconv.String(personMap[agencyId]),
|
|
|
+ "personName": gconv.String(personMap[m.Agency_id]),
|
|
|
"list": []map[string]interface{}{
|
|
|
{
|
|
|
"zbtime": zbtime,
|
|
@@ -481,7 +456,7 @@ func Findfirstparty(buyerArr []string, returnData []map[string]interface{}) []ma
|
|
|
personMap := map[string]string{}
|
|
|
if len(entIdArr) > 0 {
|
|
|
wh2, args2 := common.WhArgs(entIdArr)
|
|
|
- personSql := `select id,name as personName from ent_contact where id in (` + wh2 + `) ORDER by name`
|
|
|
+ personSql := `select id,name as personName from ent_contact where id in (` + wh2 + `) ORDER by name`
|
|
|
personArr := PersonFindConnectionsHandle(personSql, args2...)
|
|
|
//联系人处理
|
|
|
for _, v := range personArr {
|
|
@@ -686,9 +661,9 @@ func (t *OwnerService) ProjectHandle(buyerArr []string, businessStr string, moni
|
|
|
startIndex := (t.PageIndex - 1) * t.PageSize
|
|
|
whBs, allArgs := common.WhArgs(strings.Split(businessStr, ","))
|
|
|
allArgs = append(allArgs, allArgs...)
|
|
|
- sqlStr := `select buyer,buyer_id,groupUniqArray(area) as areaStr,count(if(hasAny(topscopeclass,[`
|
|
|
- sqlStr += whBs + `])=1 and project_bidstatus>1,1,null)) as ocount,SUM(if(hasAny(topscopeclass,[`
|
|
|
- sqlStr += whBs + `])=1 and project_bidstatus>1,project_money,0)) as project_money,MAX(zbtime) as zbtime from transaction_info_all`
|
|
|
+ sqlStr := `select buyer,buyer_id,groupUniqArray(area) as areaStr,count(if(project_bidstatus>1 and hasAny(topscopeclass,[`
|
|
|
+ sqlStr += whBs + `])=1,1,null)) as ocount,SUM(if(project_bidstatus>1 and hasAny(topscopeclass,[`
|
|
|
+ sqlStr += whBs + `])=1,project_money,0)) as project_money,MAX(zbtime) as maxzbtime from transaction_info_all`
|
|
|
ors1 := []string{}
|
|
|
if len(buyerArr) > 0 {
|
|
|
wh, args := common.WhArgs(buyerArr)
|
|
@@ -729,6 +704,7 @@ func (t *OwnerService) ProjectHandle(buyerArr []string, businessStr string, moni
|
|
|
if len(ors2) > 0 {
|
|
|
ors1 = append(ors1, `(buyer_id in (select DISTINCT buyer_id from transaction_info_all where (`+strings.Join(ors2, " or ")+`) and buyer_id<>''))`)
|
|
|
}
|
|
|
+ allArgs = append(allArgs, NetworkCom.ProjectYearLimit())
|
|
|
ands := []string{}
|
|
|
if len(monitorBuyers) > 0 {
|
|
|
wh, args := common.WhArgs(monitorBuyers)
|
|
@@ -740,12 +716,16 @@ func (t *OwnerService) ProjectHandle(buyerArr []string, businessStr string, moni
|
|
|
ands = append(ands, `area in (`+wh+`)`)
|
|
|
allArgs = append(allArgs, args...)
|
|
|
}
|
|
|
- sqlStr += " where (" + strings.Join(ors1, " or ") + ") " + strings.Join(ands, " and ") + " GROUP by buyer,buyer_id"
|
|
|
+ sqlStr += " where (" + strings.Join(ors1, " or ") + ") and zbtime>?"
|
|
|
+ if len(ands) > 0 {
|
|
|
+ sqlStr += " and " + strings.Join(ands, " and ")
|
|
|
+ }
|
|
|
+ sqlStr += " GROUP by buyer,buyer_id"
|
|
|
if t.SourceType == "1" {
|
|
|
sqlStr += " HAVING ocount>2 "
|
|
|
}
|
|
|
countSql := fmt.Sprintf("select count(1) as count from (%s) b ", sqlStr)
|
|
|
- sqlStr += fmt.Sprintf(" order by zbtime desc limit %d,%d", startIndex, t.PageSize)
|
|
|
+ sqlStr += fmt.Sprintf(" order by maxzbtime desc limit %d,%d", startIndex, t.PageSize)
|
|
|
logx.Info("查询列表sql", sqlStr, allArgs)
|
|
|
//总数查询
|
|
|
ass := []BuyerAggStruct{}
|
|
@@ -769,7 +749,7 @@ func (t *OwnerService) ProjectHandle(buyerArr []string, businessStr string, moni
|
|
|
projectMoney, _ := object.ProjectMoney.Float64()
|
|
|
(*projectMap)[buyerName] = map[string]interface{}{
|
|
|
"area": strings.Join(object.Area, ","),
|
|
|
- "zbtime": object.Zbtime,
|
|
|
+ "zbtime": object.MaxZbtime,
|
|
|
"money": common.RetainDecimal(projectMoney/10000, 2),
|
|
|
"count": object.Ocount,
|
|
|
"buyerId": buyerId,
|
|
@@ -784,7 +764,7 @@ type BuyerAggStruct struct {
|
|
|
BuyerId string `ch:"buyer_id"`
|
|
|
Area []string `ch:"areaStr"`
|
|
|
ProjectMoney decimal.Decimal `ch:"project_money"`
|
|
|
- Zbtime int64 `ch:"zbtime"`
|
|
|
+ MaxZbtime int64 `ch:"maxzbtime"`
|
|
|
Ocount uint64 `ch:"ocount"`
|
|
|
}
|
|
|
|
|
@@ -826,17 +806,10 @@ type SupplierConnectionsEntity struct {
|
|
|
Project_name string `ch:"project_name"`
|
|
|
Buyer_id string `ch:"buyer_id"`
|
|
|
Buyer string `ch:"buyer"`
|
|
|
- EntId string `ch:"entId"`
|
|
|
- EntType string `ch:"entType"`
|
|
|
-}
|
|
|
-type SupplierConnectionsEntitys struct {
|
|
|
- Zbtime int64
|
|
|
- Project_id string
|
|
|
- Project_name string
|
|
|
- Buyer_id string
|
|
|
- Buyer string
|
|
|
- EntId string
|
|
|
- EntType string
|
|
|
+ Winner_id string `ch:"winner_id"`
|
|
|
+ Winner string `ch:"winner"`
|
|
|
+ Agency_id string `ch:"agency_id"`
|
|
|
+ Agency string `ch:"agency"`
|
|
|
}
|
|
|
type TimeConnectionsEntity struct {
|
|
|
Zbtime int64 `ch:"zbtime"`
|
|
@@ -874,8 +847,8 @@ func PersonFindConnectionsHandle(sqlStr string, args ...interface{}) []PersonEnt
|
|
|
}
|
|
|
|
|
|
// 供应商
|
|
|
-func SupplierFindConnectionsHandle(sqlStr string, args ...interface{}) []SupplierConnectionsEntitys {
|
|
|
- returnData := []SupplierConnectionsEntitys{}
|
|
|
+func SupplierFindConnectionsHandle(sqlStr string, args ...interface{}) []SupplierConnectionsEntity {
|
|
|
+ returnData := []SupplierConnectionsEntity{}
|
|
|
rows, err := ClickhouseConn.Query(context.Background(), sqlStr, args...)
|
|
|
if err != nil {
|
|
|
logx.Error("查询失败", sqlStr, err)
|
|
@@ -886,15 +859,7 @@ func SupplierFindConnectionsHandle(sqlStr string, args ...interface{}) []Supplie
|
|
|
if err != nil {
|
|
|
logx.Error(err)
|
|
|
}
|
|
|
- returnData = append(returnData, SupplierConnectionsEntitys{
|
|
|
- Zbtime: data.Zbtime,
|
|
|
- Project_id: data.Project_id,
|
|
|
- Project_name: data.Project_name,
|
|
|
- Buyer_id: data.Buyer_id,
|
|
|
- Buyer: data.Buyer,
|
|
|
- EntId: data.EntId,
|
|
|
- EntType: data.EntType,
|
|
|
- })
|
|
|
+ returnData = append(returnData, data)
|
|
|
}
|
|
|
return returnData
|
|
|
}
|