wangchuanjin 9 ヶ月 前
コミット
5dfefb2323

+ 6 - 0
api/common/network.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"fmt"
 	"strings"
+	"time"
 
 	. "app.yhyue.com/moapp/jybase/common"
 	"github.com/zeromicro/go-zero/core/logx"
@@ -119,3 +120,8 @@ func (n *networkCom) EntMonitor(userId string) map[string]bool {
 	}
 	return m
 }
+
+//最近三年
+func (n *networkCom) ProjectYearLimit() int64 {
+	return time.Now().AddDate(-C.ProjectYearLimit, 0, 0).Unix()
+}

+ 1 - 0
api/etc/networkmanage.yaml

@@ -8,6 +8,7 @@ Gateway:
     - 127.0.0.1:2379
 CacheTimeOut: 600
 BuyerBatch: 500
+ProjectYearLimit: 3
 EntNameList: ["思特威(上海)电子科技股份有限公司","浙江宇视科技有限公司","广州敏视数码科技有限公司","安徽创世科技股份有限公司","深圳市同为数码科技股份有限公司",
               "上海为旌科技有限公司","天地伟业技术有限公司","华为技术有限公司","安徽清新互联信息科技有限公司","杭州数尔安防科技股份有限公司","天津中安视通科技有限公司",
               "深圳市高斯贝尔家居智能电子有限公司","广州派宝智能安防科技有限公司","厦门力鼎光电股份有限公司","深圳市江波龙电子股份有限公司","南京恩博科技有限公司",

+ 4 - 3
api/internal/config/config.go

@@ -11,9 +11,10 @@ type Config struct {
 		ServerCode string
 		Etcd       []string
 	}
-	CacheTimeOut int
-	BuyerBatch   int
-	EntNameList  []string
+	CacheTimeOut     int
+	BuyerBatch       int
+	ProjectYearLimit int
+	EntNameList      []string
 }
 
 type Db struct {

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

@@ -71,7 +71,8 @@ func (i *InitNetwork) Init() {
 		args := []interface{}{i.EntName, i.EntName}
 		wh, newArgs := util.WhArgs(strings.Split(i.BusinessType, ","))
 		args = append(args, newArgs...)
-		rows, err := ClickhouseConn.Query(context.Background(), `select DISTINCT winner,winner_id from information.transaction_info_all ARRAY JOIN winner_id,winner WHERE buyer_id IN (SELECT buyer_id from information.transaction_info_all WHERE has(winner,?) and buyer_id<>'') and winner<>? AND hasAny(topscopeclass,[`+wh+`])=0`, args...)
+		args = append(args, NetworkCom.ProjectYearLimit())
+		rows, err := ClickhouseConn.Query(context.Background(), `select DISTINCT winner,winner_id from information.transaction_info_all ARRAY JOIN winner_id,winner WHERE buyer_id IN (SELECT buyer_id from information.transaction_info_all WHERE has(winner,?) and buyer_id<>'') and winner<>? and hasAny(topscopeclass,[`+wh+`])=0 AND zbtime>?`, args...)
 		if err != nil {
 			logx.Error(err)
 			return

+ 18 - 10
api/internal/service/network.go

@@ -516,7 +516,8 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 						}
 						cccNodes = append(cccNodes, nt)
 						cccIndexMap[vvv.Name] = len(cccNodes) - 1
-						if !hasDefaultCheck || compareId == in.ClickId {
+						if (!hasDefaultCheck && vv.Count > 0) || compareId == in.ClickId {
+							hasDefaultCheck = true
 							checkCode = append(checkCode, nt.CODE)
 						}
 					}
@@ -551,7 +552,8 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 						MYID:     vvv.CompanyId,
 						MYTYPE:   "firstparty",
 					}
-					if !hasDefaultCheck || compareId == in.ClickId {
+					if (!hasDefaultCheck && vv.Count > 0) || compareId == in.ClickId {
+						hasDefaultCheck = true
 						checkCode = append(checkCode, nt.CODE)
 					}
 					*convList = append(*convList, nt)
@@ -598,7 +600,8 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 				MYTYPE:    vv.Type,
 			}
 			//如果甲方的子节点被选中了,父节点跟着被选中,非甲方的要对比子节点可介绍业主
-			if !hasDefaultCheck || childStartCheckCodeLen != len(checkCode) || (v.Name != "甲方" && compareId == fmt.Sprint(vv.Id)) {
+			if (!hasDefaultCheck && vv.Count > 0) || childStartCheckCodeLen != len(checkCode) || (in.ClickId != "" && compareId == fmt.Sprint(vv.Id)) {
+				hasDefaultCheck = true
 				checkCode = append(checkCode, cm.CODE)
 			}
 			*convList = append(*convList, cm)
@@ -611,7 +614,6 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 		if parentStartCheckCodeLen != len(checkCode) {
 			checkCode = append(checkCode, pm.CODE)
 		}
-		hasDefaultCheck = true
 	}
 	sort.Sort(convList)
 	*parentConvList = append(*parentConvList, *convList...)
@@ -991,13 +993,14 @@ func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, busi
 		return result
 	}
 	wh, args := 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_all where buyer_id in (` + wh + `)`
+	q := `select buyer_id,count(project_id) AS project_count,sum(project_money) AS project_amount,groupUniqArray(project_id) from information.transaction_info_all where buyer_id in (` + wh + `) and zbtime>? and project_bidstatus>1`
+	args = append(args, NetworkCom.ProjectYearLimit())
 	if len(businessType) > 0 {
 		newWh, newArgs := WhArgs(businessType)
 		q += ` and hasAny(topscopeclass,[` + newWh + `])`
 		args = append(args, newArgs...)
 	}
-	q += ` and project_bidstatus>1 group by buyer_id`
+	q += ` group by buyer_id`
 	rows, err := ClickhouseConn.Query(context.Background(), q, args...)
 	if err != nil {
 		logx.Error(err)
@@ -1269,7 +1272,8 @@ func (n *network) BuyerProjectInfoBatch(ids []string, businessType []string, vm
 		return
 	}
 	wh, args := 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_all where buyer_id in (` + wh + `) and project_bidstatus>1`
+	q := `select buyer_id,count(DISTINCT project_id) AS project_count,sum(project_money) AS project_amount,groupUniqArray(project_id) from information.transaction_info_all where buyer_id in (` + wh + `) and zbtime>? and project_bidstatus>1`
+	args = append(args, NetworkCom.ProjectYearLimit())
 	if len(businessType) > 0 {
 		newWh, newArgs := WhArgs(businessType)
 		q += ` and hasAny(topscopeclass,[` + newWh + `])`
@@ -1317,18 +1321,22 @@ func (n *network) TjProject(agencyIds, winnerIds []string, vbs map[string][]*idN
 	if len(agencyIds) == 0 && len(winnerIds) == 0 {
 		return vm
 	}
+	yearLimit := NetworkCom.ProjectYearLimit()
 	allArgs := []interface{}{}
 	q := `select buyer_id,count(DISTINCT project_id) AS project_count,sum(project_money) AS project_amount,groupUniqArray(project_id) from information.transaction_info_all where buyer_id in (select DISTINCT buyer_id from information.transaction_info_all where `
 	if len(agencyIds) > 0 {
 		wh, args := WhArgs(agencyIds)
 		allArgs = append(allArgs, args...)
-		q += `agency_id in (` + wh + `) and buyer_id<>''`
+		allArgs = append(allArgs, yearLimit)
+		q += `agency_id in (` + wh + `) and buyer_id<>'' and zbtime>?`
 	} else if len(winnerIds) > 0 {
 		wh, args := WhArgs(winnerIds)
 		allArgs = append(allArgs, args...)
-		q += `hasAny(winner_id,[` + wh + `]) and buyer_id<>''`
+		allArgs = append(allArgs, yearLimit)
+		q += `hasAny(winner_id,[` + wh + `]) and buyer_id<>'' and zbtime>?`
 	}
-	q += `) and project_bidstatus>1`
+	q += `) and zbtime>? and project_bidstatus>1`
+	allArgs = append(allArgs, yearLimit)
 	if len(businessType) > 0 {
 		newWh, newArgs := WhArgs(businessType)
 		q += ` and hasAny(topscopeclass,[` + newWh + `])`

+ 49 - 84
api/internal/service/owner.go

@@ -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
 }

+ 5 - 2
api/internal/service/plistService.go

@@ -171,6 +171,7 @@ func getQuerySql(req *types.ProjectListReq, plist []string, businessStr string)
 	}
 	wm := map[string]bool{}
 	winner_ids := []string{}
+	yearLimit := T.NetworkCom.ProjectYearLimit()
 	if req.Supplier != "" {
 		for _, v := range strings.Split(req.Supplier, ",") {
 			if wm[v] {
@@ -201,8 +202,10 @@ func getQuerySql(req *types.ProjectListReq, plist []string, businessStr string)
 		allArgs = append(allArgs, args...)
 	}
 	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<>''))`)
+		ors1 = append(ors1, `(buyer_id in (select DISTINCT buyer_id from transaction_info_all where (`+strings.Join(ors2, " or ")+`) and buyer_id<>'' and zbtime>?))`)
+		allArgs = append(allArgs, yearLimit)
 	}
+	allArgs = append(allArgs, yearLimit)
 	ands := []string{}
 	//业务类型
 	if businessStr != "" {
@@ -243,7 +246,7 @@ func getQuerySql(req *types.ProjectListReq, plist []string, businessStr string)
 		}
 	}
 	//过滤掉已中标的招标项目数据
-	sqlAppend := " where (" + strings.Join(ors1, " or ") + ") and " + strings.Join(ands, " and ") + "and project_bidstatus>1"
+	sqlAppend := " where (" + strings.Join(ors1, " or ") + ") and project_bidstatus>1 and zbtime>? and " + strings.Join(ands, " and ")
 	countSql += sqlAppend
 	findSql += fmt.Sprintf(sqlAppend+" order by zbtime desc limit %d,%d", (req.PageNum-1)*req.PageSize, req.PageSize)
 	return