Jelajahi Sumber

feat:xiugai

wangchuanjin 9 bulan lalu
induk
melakukan
142c0d9e2c

+ 116 - 203
api/internal/service/CoopHistoryService.go

@@ -9,11 +9,11 @@ import (
 
 	"app.yhyue.com/moapp/jybase/common"
 	"app.yhyue.com/moapp/jybase/encrypt"
-	elastic "app.yhyue.com/moapp/jybase/es"
 	"app.yhyue.com/moapp/jybase/redis"
 	T "bp.jydev.jianyu360.cn/CRM/networkManage/api/common"
 	"bp.jydev.jianyu360.cn/CRM/networkManage/api/internal/types"
 	"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
+	"github.com/shopspring/decimal"
 	"github.com/zeromicro/go-zero/core/logx"
 )
 
@@ -23,10 +23,6 @@ var (
 	sql_2_2   = `select id as buyer_id from ent_info where company_name=? order by id desc limit 1`
 	sql_2_1   = `SELECT project_id, project_name, zbtime FROM information.transaction_info_all WHERE buyer_id = ? AND has(winner, ?) ORDER BY zbtime DESC`
 	sql_2_1_1 = `SELECT project_id, project_name, zbtime FROM information.transaction_info_all WHERE buyer_id = ? AND agency = ? ORDER BY zbtime DESC`
-	//sql_2_2    = `select DISTINCT  b.company_id,b.company_name,a.relate_id,a.relate_name,b.contact_person   from  connection_introduce a  INNER JOIN connection b on  a.position_id= ? and a.connection_id=b.id  and   a.relate_Id = ? and  a.itype =1  and  b.itype=4 and  b.status=1 `
-	//sql_2_3    = `select a.a_id as a_id, a.b_id as b_id, a.a_name as a_name, a.b_name as b_name, a.code as code, c.legal_person as c_person, d.legal_person d_person from crm.ent_map_code a left join ent_info c on (a.a_id = ? or a.b_id = ? ) and a.code in('0101', '0201') and a.a_id = c.id left join ent_info d on (a.a_id = ? or a.b_id = ? ) and a.code in('0101', '0201') and a.b_id = d.id where (a.a_id = ? or a.b_id = ? ) and a.code in('0101', '0201')`
-	es_query  = `{"query": {"bool": {"must": [{"terms": {"buyer_id": ["%s"]}},{"exists": {"field": "winner_id"}}],"must_not": {"terms": {"topscopeclass": ["%s"]}}}},"aggs": {"winner_count": {"terms": {"field": "winner","size": 1000,"order": {"_count": "desc"}},"aggs": {"amount_all": {"sum": {"field": "project_money"}},"ent_id": {"terms": {"field": "winner_id"}},"buyer_id": {"terms": {"field": "buyer_id"}}}}},"size": 1}`
-	es_query1 = `{"query": {"bool": {"must": [{"terms": {"buyer_id": ["%s"]}}],"must_not": [{"term": {"agency_id": {"value": ""}}}]}},"aggs": {"agency_count": {"terms": {"field": "agency","size": 1000,"order": {"_count": "desc"}},"aggs": {"amount_all": {"sum": {"field": "project_money"}},"ent_id": {"terms": {"field": "agency_id"}},"buyer_id": {"terms": {"field": "buyer_id"}}}}},"size": 1}`
 )
 
 type ResultData struct {
@@ -73,25 +69,11 @@ type Cooperate struct {
 }
 
 type AggStruct struct {
-	Buckets []struct {
-		Key        string `json:"key,omitempty"`
-		Doc_count  int64  `json:"doc_count,omitempty"`
-		Amount_all struct {
-			Value float64 `json:"value,omitempty"`
-		} `json:"amount_all"`
-		EntId struct {
-			Buckets []struct {
-				Key       string `json:"key,omitempty"`
-				Doc_count int64  `json:"doc_count,omitempty"`
-			} `json:"buckets"`
-		} `json:"ent_id"`
-		BuyerId struct {
-			Buckets []struct {
-				Key       string `json:"key,omitempty"`
-				Doc_count int64  `json:"doc_count,omitempty"`
-			} `json:"buckets"`
-		} `json:"buyer_id"`
-	} `json:"buckets"`
+	Id           string          `ch:"id"`
+	Name         string          `ch:"name"`
+	Sum          uint64          `ch:"sum"`
+	ProjectMoney decimal.Decimal `ch:"project_money"`
+	Zbtime       int64           `ch:"zbtime"`
 }
 
 func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2, size_3, size_4 int64) {
@@ -104,217 +86,148 @@ func GetPrList(req *types.CoopHistoryReq) (result []*ResultData, size_1, size_2,
 	} else {
 		return
 	}
-	if err != nil {
-		return nil, 0, 0, 0, 0
+	if err != nil || pTmp.BuyerId == "" {
+		return
 	}
-	//propertyForm := T.NetworkCom.GetMyProbusfor(req.EntAccountId)
-	scopeClass := FindBusiness(req.EntId, req.EntUserId)
 	// firstparty:甲方 supplier:供应商 adiffb:同甲异业 middleman:中间人 agency:招标代理机构 sup_sub: 上下级
 	// 1、同甲异业数据/ 3、招标代理机构渠道
-	if pTmp.BuyerId != "" {
-		// 中间人可介绍业主
+	// 中间人可介绍业主
+	if req.ChannelType == "0" || req.ChannelType == "4" {
 		var r3 []map[string]interface{}
 		r3 = FindMiddleman([]string{fmt.Sprintf("'%s'", pTmp.BuyerId)}, req.PositionId, r3)
-		if r3 != nil && len(r3) > 0 {
-			size_4 = int64(len(r3))
-			if req.ChannelType == "0" || req.ChannelType == "4" {
-				for _, m := range r3 {
-					tmp := ResultData{
-						SourceType:   "middleman",
-						EntName:      common.ObjToString(m["b_name"]),
-						EntId:        common.ObjToString(m["b_id"]),
-						EntPerson:    common.ObjToString(m["personName"]),
-						Relationship: "业主的关系人",
-						BuyerId:      pTmp.BuyerId,
-					}
-					result = append(result, &tmp)
-				}
+		size_4 = int64(len(r3))
+		for _, m := range r3 {
+			tmp := ResultData{
+				SourceType:   "middleman",
+				EntName:      common.ObjToString(m["b_name"]),
+				EntId:        common.ObjToString(m["b_id"]),
+				EntPerson:    common.ObjToString(m["personName"]),
+				Relationship: "业主的关系人",
+				BuyerId:      pTmp.BuyerId,
 			}
+			result = append(result, &tmp)
 		}
-		// 关联单位
+	}
+	// 关联单位
+	if req.ChannelType == "0" || req.ChannelType == "2" {
 		var r4 []map[string]interface{}
 		r4 = Findfirstparty([]string{fmt.Sprintf("'%s'", pTmp.BuyerId)}, r4)
-		if r4 != nil && len(r4) > 0 {
-			size_2 = int64(len(r4))
-			if req.ChannelType == "0" || req.ChannelType == "2" {
-				for _, m := range r4 {
-					tmp := ResultData{
-						SourceType:   "sup_sub",
-						EntName:      common.ObjToString(m["b_name"]),
-						EntId:        common.ObjToString(m["b_id"]),
-						EntPerson:    common.ObjToString(m["personName"]),
-						Relationship: common.ObjToString(m["relationship"]),
-						BuyerId:      pTmp.BuyerId,
-					}
-					result = append(result, &tmp)
-				}
+		size_2 = int64(len(r4))
+		for _, m := range r4 {
+			tmp := ResultData{
+				SourceType:   "sup_sub",
+				EntName:      common.ObjToString(m["b_name"]),
+				EntId:        common.ObjToString(m["b_id"]),
+				EntPerson:    common.ObjToString(m["personName"]),
+				Relationship: common.ObjToString(m["relationship"]),
+				BuyerId:      pTmp.BuyerId,
 			}
+			result = append(result, &tmp)
 		}
-		r1 := GetWinnerData(strings.Split(scopeClass, ","), pTmp.BuyerId)
-		r2 := GetAgencyData(pTmp.BuyerId)
-		winners, agency := []string{}, []string{}
+	}
+	if req.ChannelType == "0" || req.ChannelType == "1" {
+		scopeClass := FindBusiness(req.EntId, req.EntUserId)
+		r1 := GetWinnerData(scopeClass, pTmp.BuyerId)
+		size_1 = int64(len(r1))
 		for _, m := range r1 {
-			winners = append(winners, common.ObjToString(m["name"]))
+			tmp := ResultData{
+				SourceType: "adiffb",
+				EntName:    m.Name,
+				ProjectNum: int(m.Sum),
+				BuyerId:    pTmp.BuyerId,
+				RecentTime: m.Zbtime,
+			}
+			tmp.TotalAmount, _ = m.ProjectMoney.Float64()
+			if time.Now().AddDate(-3, 0, 0).Unix() <= tmp.RecentTime {
+				tmp.NearlyYears = true
+			}
+			result = append(result, &tmp)
 		}
+	}
+	if req.ChannelType == "0" || req.ChannelType == "3" {
+		r2 := GetAgencyData(pTmp.BuyerId)
+		size_3 = int64(len(r2))
 		for _, m := range r2 {
-			agency = append(agency, common.ObjToString(m["name"]))
-		}
-		logx.Info("CandidateChannel LastTimeCoopBath start ", req.PositionId, " ", pTmp.BuyerId, " ", len(winners), " ", len(agency))
-		ltcs1, ltcs2 := LastTimeCoopBath(req.PositionId, pTmp.BuyerId, winners, agency)
-		logx.Info("CandidateChannel LastTimeCoopBath over ", req.PositionId)
-		if r1 != nil && len(r1) > 0 {
-			size_1 = int64(len(r1))
-			if req.ChannelType == "0" || req.ChannelType == "1" {
-				for _, m := range r1 {
-					tmp := ResultData{
-						SourceType:  "adiffb",
-						EntName:     common.ObjToString(m["name"]),
-						ProjectNum:  common.IntAll(m["coop_size"]),
-						TotalAmount: common.Float64All(m["coop_amount"]),
-						BuyerId:     pTmp.BuyerId,
-					}
-					if ltc := ltcs1[common.ObjToString(m["name"])]; ltc != nil {
-						tmp.NearlyYears = ltc.Near
-						tmp.RecentTime = ltc.ZbTime
-					}
-					result = append(result, &tmp)
-				}
+			tmp := ResultData{
+				SourceType: "agency",
+				EntName:    m.Name,
+				ProjectNum: int(m.Sum),
+				BuyerId:    pTmp.BuyerId,
+				RecentTime: m.Zbtime,
 			}
-		}
-		if r2 != nil && len(r2) > 0 {
-			size_3 = int64(len(r2))
-			if req.ChannelType == "0" || req.ChannelType == "3" {
-				for _, m := range r2 {
-					tmp := ResultData{
-						SourceType:  "agency",
-						EntName:     common.ObjToString(m["name"]),
-						ProjectNum:  common.IntAll(m["coop_size"]),
-						TotalAmount: common.Float64All(m["coop_amount"]),
-						BuyerId:     pTmp.BuyerId,
-					}
-					if ltc := ltcs2[common.ObjToString(m["name"])]; ltc != nil {
-						tmp.NearlyYears = ltc.Near
-						tmp.RecentTime = ltc.ZbTime
-					}
-					result = append(result, &tmp)
-				}
+			tmp.TotalAmount, _ = m.ProjectMoney.Float64()
+			if time.Now().AddDate(-3, 0, 0).Unix() <= tmp.RecentTime {
+				tmp.NearlyYears = true
 			}
+			result = append(result, &tmp)
 		}
 	}
 	return
 }
-func GetWinnerData(scopeClass []string, bid string) (result1 []map[string]interface{}) {
-	result1 = []map[string]interface{}{}
-	winnerKey := fmt.Sprintf("networkManage_coopHistory_winner_%s", common.GetMd5String(strings.Join(scopeClass, ",")+"_"+bid))
+func GetWinnerData(scopeClass string, bid string) []AggStruct {
+	ass := []AggStruct{}
+	if scopeClass == "" {
+		return ass
+	}
+	winnerKey := fmt.Sprintf("networkManage_coopHistory_winner_%s", common.GetMd5String(scopeClass+"_"+bid))
 	wb, err := redis.GetBytes("newother", winnerKey)
-	if err == nil {
-		json.Unmarshal(*wb, &result1)
-		return
+	if err == nil && wb != nil {
+		json.Unmarshal(*wb, &ass)
+		return ass
 	}
-	m1 := make(map[string]interface{}) //采购单位-中标单位
-	noIds := []string{}
-	if len(scopeClass) > 0 {
-		//同甲异态 中标企业
-		aggs, _, _ := elastic.GetAggs(INDEX_1, INDEX_1, fmt.Sprintf(es_query, strings.ReplaceAll(bid, ",", `","`), strings.Join(scopeClass, "\",\"")))
-		logx.Info("es聚合查询结果:", fmt.Sprintf(es_query, strings.ReplaceAll(bid, ",", `","`), strings.Join(scopeClass, "\",\"")))
-		var m1Buckets = AggStruct{}
-		if aggs != nil && aggs["winner_count"] != nil {
-			bs, err := aggs["winner_count"].MarshalJSON()
-			if err != nil {
-				logx.Info(err)
-			} else {
-				if len(bs) == 0 {
-					logx.Info(err)
-				} else {
-					err := json.Unmarshal(bs, &m1Buckets)
-					logx.Info(err)
-					if len(m1Buckets.Buckets) > 0 {
-						for _, v := range m1Buckets.Buckets {
-							if v.Key != "" && len(v.EntId.Buckets) > 0 && len(v.BuyerId.Buckets) > 0 {
-								mv := map[string]interface{}{"name": v.Key, "amount": v.Amount_all.Value, "count": v.Doc_count, "buyerId": v.BuyerId.Buckets[0].Key}
-								if len(v.EntId.Buckets) == 1 && v.EntId.Buckets[0].Key != "" {
-									mv["nameId"] = v.EntId.Buckets[0].Key
-								} else {
-									noIds = append(noIds, v.Key)
-								}
-								m1[v.Key] = mv
-							}
-						}
-					}
-				}
-			}
-		}
+	args := []interface{}{bid, bid}
+	wh, newArgs := common.WhArgs(strings.Split(scopeClass, ","))
+	args = append(args, newArgs...)
+	rows, err1 := T.ClickhouseConn.Query(context.TODO(), `select winner as name,winner_id as id,sum(1) as sum,sum(project_money) as project_money,max(zbtime) as zbtime 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_id,?) and buyer_id<>'') and winner_id<>? AND hasAny(topscopeclass,[`+wh+`])=0 group by winner,winner_id`, args...)
+	if err1 != nil {
+		logx.Error(err1)
+		return ass
 	}
-	idName := T.NetworkCom.GetEntIdByName(noIds)
-	for k, v := range m1 {
-		v1 := v.(map[string]interface{})
-		tmp := make(map[string]interface{})
-		tmp["name"] = k
-		nameId, _ := v1["nameId"].(string)
-		if nameId == "" {
-			nameId = idName[k]
+	for rows.Next() {
+		as := AggStruct{}
+		if err := rows.ScanStruct(&as); err != nil {
+			logx.Error(err)
+			continue
 		}
-		tmp["nameId"] = nameId
-		tmp["coop_size"] = v1["count"]
-		tmp["coop_amount"] = v1["amount"]
-		result1 = append(result1, tmp)
+		ass = append(ass, as)
 	}
-	redis.Put("newother", winnerKey, result1, T.C.CacheTimeOut)
-	return
+	rows.Close()
+	if err := rows.Err(); err != nil {
+		logx.Error(err)
+	}
+	redis.Put("newother", winnerKey, ass, T.C.CacheTimeOut)
+	return ass
 }
 
-func GetAgencyData(bid string) (result2 []map[string]interface{}) {
-	result2 = []map[string]interface{}{}
+//代理机构
+func GetAgencyData(bid string) []AggStruct {
+	ass := []AggStruct{}
 	agencyKey := fmt.Sprintf("networkManage_coopHistory_agency_%s", bid)
-	wb, err := redis.GetBytes("newother", agencyKey)
-	if err == nil {
-		json.Unmarshal(*wb, &result2)
-		return
+	wb, err := redis.GetNewBytes("newother", agencyKey)
+	if err == nil && wb != nil {
+		json.Unmarshal(*wb, &ass)
+		return ass
 	}
-	m2 := make(map[string]interface{}) //采购单位-代理机构
-	noIds := []string{}
-	//代理机构
-	aggs1, _, _ := elastic.GetAggs(INDEX_1, INDEX_1, fmt.Sprintf(es_query1, strings.ReplaceAll(bid, ",", `","`)))
-	var m2Buckets = AggStruct{}
-	if aggs1 != nil && aggs1["agency_count"] != nil {
-		bs, err := aggs1["agency_count"].MarshalJSON()
-		if err != nil {
-			logx.Info(err)
-		} else {
-			if len(bs) == 0 {
-				logx.Info(err)
-			} else {
-				err = json.Unmarshal(bs, &m2Buckets)
-				logx.Info(err)
-				if len(m2Buckets.Buckets) > 0 {
-					for _, v := range m2Buckets.Buckets {
-						if v.Key != "" && len(v.EntId.Buckets) > 0 && len(v.BuyerId.Buckets) > 0 {
-							if v.EntId.Buckets[0].Key == "" {
-								noIds = append(noIds, v.Key)
-							}
-							m2[v.Key] = map[string]interface{}{"name": v.Key, "amount": v.Amount_all.Value, "count": v.Doc_count, "nameId": v.EntId.Buckets[0].Key, "buyerId": v.BuyerId.Buckets[0].Key}
-						}
-					}
-				}
-			}
-		}
+	rows, err1 := T.ClickhouseConn.Query(context.TODO(), `select agency as name,agency_id as id,sum(1) as sum,sum(project_money) as project_money,max(zbtime) as zbtime from information.transaction_info_all where buyer_id=? and agency<>'' and agency_id<>'' GROUP by agency,agency_id`, bid)
+	if err1 != nil {
+		logx.Error(err1)
+		return ass
 	}
-	idName := T.NetworkCom.GetEntIdByName(noIds)
-	for k, v := range m2 {
-		v1 := v.(map[string]interface{})
-		tmp := make(map[string]interface{})
-		tmp["name"] = k
-		nameId, _ := v1["nameId"].(string)
-		if nameId == "" {
-			nameId = idName[k]
+	for rows.Next() {
+		as := AggStruct{}
+		if err := rows.ScanStruct(&as); err != nil {
+			logx.Error(err)
+			continue
 		}
-		tmp["nameId"] = nameId
-		tmp["coop_size"] = v1["count"]
-		tmp["coop_amount"] = v1["amount"]
-		result2 = append(result2, tmp)
+		ass = append(ass, as)
 	}
-	redis.Put("newother", agencyKey, result2, T.C.CacheTimeOut)
-	return
+	rows.Close()
+	if err := rows.Err(); err != nil {
+		logx.Error(err)
+	}
+	redis.Put("newother", agencyKey, ass, T.C.CacheTimeOut)
+	return ass
 }
 
 type P_History struct {

+ 20 - 24
api/internal/service/initNetwork.go

@@ -54,13 +54,12 @@ func (i *InitNetwork) Init() {
 			if buyer == "" || buyer_id == "" {
 				continue
 			}
-			cn := &Connection{
+			ids = append(ids, buyer_id)
+			array = append(array, &Connection{
 				Company_id:   buyer_id,
 				Company_name: buyer,
 				Itype:        1,
-			}
-			ids = append(ids, buyer_id)
-			array = append(array, cn)
+			})
 		}
 	}()
 	//②甲异业渠道(人脉):“当前企业曾经合作过物业项目的采购单位的中标物业企业中”与当前企业不一样业态的企业的联系人列表
@@ -68,35 +67,32 @@ func (i *InitNetwork) Init() {
 		if i.BusinessType == "" {
 			return
 		}
-		args := []interface{}{i.EntName}
+		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_id,winner from information.transaction_info_all WHERE buyer_id IN (SELECT buyer_id from information.transaction_info_all WHERE has(winner,?) and buyer_id<>'') AND hasAny(topscopeclass,[`+wh+`])=0`, args...)
+		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...)
 		if err != nil {
 			logx.Error(err)
 			return
 		}
 		for rows.Next() {
 			var (
-				winners    []string
-				winner_ids []string
+				winner    string
+				winner_id string
 			)
-			if err := rows.Scan(&winners, &winner_ids); err != nil {
+			if err := rows.Scan(&winner, &winner_id); err != nil {
 				logx.Error(err)
 				continue
 			}
-			for k, winner_id := range winner_ids {
-				if k >= len(winners) {
-					continue
-				}
-				cn := &Connection{
-					Company_id:   winner_id,
-					Company_name: winners[k],
-					Itype:        3,
-				}
-				ids = append(ids, winner_id)
-				array = append(array, cn)
+			if winner == "" || winner_id == "" {
+				continue
 			}
+			ids = append(ids, winner_id)
+			array = append(array, &Connection{
+				Company_id:   winner_id,
+				Company_name: winner,
+				Itype:        3,
+			})
 		}
 	}()
 	//③招标代理机构(人脉):当前企业曾经合作过的招标代理机构联系人信息
@@ -118,13 +114,12 @@ func (i *InitNetwork) Init() {
 			if agency == "" || agency_id == "" {
 				continue
 			}
-			cn := &Connection{
+			ids = append(ids, agency_id)
+			array = append(array, &Connection{
 				Company_id:   agency_id,
 				Company_name: agency,
 				Itype:        5,
-			}
-			ids = append(ids, agency_id)
-			array = append(array, cn)
+			})
 		}
 	}()
 	cis := i.GetContactInfo(ids)
@@ -164,6 +159,7 @@ func (i *InitNetwork) Init() {
 		CrmMysql.InsertBatch("crm.connection", fields, values)
 		values = []interface{}{}
 	}
+	Network.DeleteCache(i.PositionId)
 }
 
 //

+ 65 - 29
api/internal/service/network.go

@@ -3,18 +3,18 @@ package service
 import (
 	"context"
 	"database/sql"
+	"encoding/json"
 	"fmt"
 	"math"
 	"sort"
 	"strings"
 	"time"
 
-	"app.yhyue.com/moapp/jybase/redis"
-
 	. "app.yhyue.com/moapp/jybase/common"
 	. "app.yhyue.com/moapp/jybase/date"
 	"app.yhyue.com/moapp/jybase/encrypt"
 	. "app.yhyue.com/moapp/jybase/es"
+	"app.yhyue.com/moapp/jybase/redis"
 	. "app.yhyue.com/moapp/jybase/sort"
 	. "bp.jydev.jianyu360.cn/CRM/networkManage/api/common"
 	"bp.jydev.jianyu360.cn/CRM/networkManage/api/internal/types"
@@ -22,6 +22,11 @@ import (
 	"github.com/zeromicro/go-zero/core/logx"
 )
 
+const (
+	NetworkManageAllProjectKey = "networkManage_allProject_%d"
+	NetworkManageList          = "networkManage_list_%d_%s"
+)
+
 var Network = &network{}
 
 type network struct {
@@ -67,8 +72,8 @@ type projectInfo struct {
 	BuyerCount    int64
 	ProjectCount  int64
 	ProjectAmount float64
-	MonitorCount  int64
 	ExportId      []string
+	IdNames       []*idName
 }
 type firstpartyNetwork struct {
 	CompanyId   string
@@ -225,6 +230,7 @@ func (n *network) AddOrUpdate(in *types.AddOrUpdateReq) *types.Reply {
 			}
 		}
 	}
+	n.DeleteCache(in.PositionId)
 	return reply
 }
 
@@ -322,6 +328,12 @@ func (n *network) Associate(in *types.AssociateReq) (reply *types.Reply) {
 //人脉库-全部人脉项目
 func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 	reply = &types.Reply{}
+	key := fmt.Sprintf(NetworkManageAllProjectKey, in.PositionId)
+	rbt, rerr := redis.GetNewBytes("newother", key)
+	if rerr == nil && rbt != nil {
+		json.Unmarshal(*rbt, &reply)
+		return
+	}
 	businessType := strings.Split(FindBusiness(in.EntId, in.MgoUserId), ",")
 	var count int64
 	var list []*networkTree
@@ -330,7 +342,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{}, businessType)
+				firstparty := n.Introduce_Firstparty(fpn, businessType)
 				nameIndex := map[string]int{}
 				for _, v := range fpn[in.Id] {
 					if _, ok := nameIndex[v.Name]; !ok {
@@ -360,7 +372,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, businessType, map[string]bool{})
+		aio := n.AllIntroduceOwner(sqlAppend1, "", args, true, businessType)
 		firstpartyChild = aio.FirstpartyNetwork
 		list = []*networkTree{
 			&networkTree{
@@ -562,6 +574,7 @@ func (n *network) AllProject(in *types.AllprojectReq) (reply *types.Reply) {
 			"list":  parentConvList,
 		},
 	}
+	redis.Put("newother", key, reply, C.CacheTimeOut)
 	return reply
 }
 
@@ -641,8 +654,16 @@ func (n *network) List(in *types.NetWorkListReq) *types.Reply {
 	if len(businessType) == 0 {
 		isTjProject = false
 	}
+	redisKey := fmt.Sprintf(NetworkManageList, in.PositionId, GetMd5String(fmt.Sprintf("%+v", in)))
+	aio := &introduceOwnerProject{}
+	aioByte, aioErr := redis.GetNewBytes("newother", redisKey)
+	if aioErr == nil && aioByte != nil {
+		json.Unmarshal(*aioByte, &aio)
+	} else {
+		aio = n.AllIntroduceOwner(sqlAppend1, sqlAppend2, args, isTjProject, businessType)
+		redis.Put("newother", redisKey, aio, C.CacheTimeOut)
+	}
 	entMonitor := NetworkCom.EntMonitor(in.UserId)
-	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)
@@ -657,12 +678,14 @@ func (n *network) List(in *types.NetWorkListReq) *types.Reply {
 					jump_id += ","
 				}
 				jump_id += vv.CompanyId
+				if entMonitor[vv.CompanyName] {
+					monitor_count++
+				}
 			}
 			if aio.Firstparty[v.Company_id] != nil {
 				buyer_count = aio.Firstparty[v.Company_id].BuyerCount
 				project_count = aio.Firstparty[v.Company_id].ProjectCount
 				expect_amount = aio.Firstparty[v.Company_id].ProjectAmount
-				monitor_count = aio.Firstparty[v.Company_id].MonitorCount
 				export_id = aio.Firstparty[v.Company_id].ExportId
 			}
 		case 2:
@@ -673,8 +696,12 @@ func (n *network) List(in *types.NetWorkListReq) *types.Reply {
 				buyer_count = aio.Supplier[v.Company_id].BuyerCount
 				project_count = aio.Supplier[v.Company_id].ProjectCount
 				expect_amount = aio.Supplier[v.Company_id].ProjectAmount
-				monitor_count = aio.Supplier[v.Company_id].MonitorCount
 				export_id = aio.Supplier[v.Company_id].ExportId
+				for _, vv := range aio.Supplier[v.Company_id].IdNames {
+					if entMonitor[vv.Name] {
+						monitor_count++
+					}
+				}
 			}
 		case 3:
 			itype = "同甲异业渠道"
@@ -684,8 +711,12 @@ func (n *network) List(in *types.NetWorkListReq) *types.Reply {
 				buyer_count = aio.Adiffb[v.Company_id].BuyerCount
 				project_count = aio.Adiffb[v.Company_id].ProjectCount
 				expect_amount = aio.Adiffb[v.Company_id].ProjectAmount
-				monitor_count = aio.Adiffb[v.Company_id].MonitorCount
 				export_id = aio.Adiffb[v.Company_id].ExportId
+				for _, vv := range aio.Adiffb[v.Company_id].IdNames {
+					if entMonitor[vv.Name] {
+						monitor_count++
+					}
+				}
 			}
 		case 4:
 			itype = "中间人"
@@ -719,8 +750,12 @@ func (n *network) List(in *types.NetWorkListReq) *types.Reply {
 				buyer_count = aio.Agency[v.Company_id].BuyerCount
 				project_count = aio.Agency[v.Company_id].ProjectCount
 				expect_amount = aio.Agency[v.Company_id].ProjectAmount
-				monitor_count = aio.Agency[v.Company_id].MonitorCount
 				export_id = aio.Agency[v.Company_id].ExportId
+				for _, vv := range aio.Agency[v.Company_id].IdNames {
+					if entMonitor[vv.Name] {
+						monitor_count++
+					}
+				}
 			}
 		}
 		if buyer_count < in.Buyercount_start {
@@ -882,7 +917,7 @@ func (n *network) FirstpartyNetwork(name string, values []string) map[string][]*
 }
 
 //
-func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, entMonitor map[string]bool, businessType []string) map[string]*projectInfo {
+func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, businessType []string) map[string]*projectInfo {
 	values := []string{}
 	vm := map[string]*projectInfo{}
 	for _, v := range fpn {
@@ -937,9 +972,6 @@ func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, entM
 		}
 		result[k].BuyerCount = int64(len(v))
 		for _, vv := range v {
-			if entMonitor[vv.CompanyName] {
-				result[k].MonitorCount++
-			}
 			if vm[vv.CompanyId] == nil {
 				continue
 			}
@@ -952,7 +984,7 @@ func (n *network) Introduce_Firstparty(fpn map[string][]*firstpartyNetwork, entM
 }
 
 //
-func (n *network) Introduce_Supplier(values []string, entMonitor map[string]bool, businessType []string) map[string]*projectInfo {
+func (n *network) Introduce_Supplier(values []string, businessType []string) map[string]*projectInfo {
 	if len(values) == 0 {
 		return map[string]*projectInfo{}
 	}
@@ -1002,11 +1034,11 @@ func (n *network) Introduce_Supplier(values []string, entMonitor map[string]bool
 			logx.Error(err)
 		}
 	}
-	return n.MakeProjectInfo(buyers, vbs, businessType, entMonitor)
+	return n.MakeProjectInfo(buyers, vbs, businessType)
 }
 
 //
-func (n *network) Introduce_Agency(values []string, entMonitor map[string]bool, businessType []string) map[string]*projectInfo {
+func (n *network) Introduce_Agency(values []string, businessType []string) map[string]*projectInfo {
 	if len(values) == 0 {
 		return map[string]*projectInfo{}
 	}
@@ -1046,11 +1078,11 @@ 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, businessType, entMonitor)
+	return n.MakeProjectInfo(buyers, vbs, businessType)
 }
 
 //
-func (n *network) Introduce_Middleman(values []string, entMonitor map[string]bool, businessType []string) map[string]*projectInfo {
+func (n *network) Introduce_Middleman(values []string, businessType []string) map[string]*projectInfo {
 	result := map[string]*projectInfo{}
 	if len(values) == 0 {
 		return result
@@ -1200,12 +1232,13 @@ func (n *network) BuyerProjectInfo(ids []string, businessType []string) map[stri
 }
 
 //
-func (n *network) MakeProjectInfo(buyers []string, vbs map[string][]*idName, businessType []string, entMonitor map[string]bool) map[string]*projectInfo {
+func (n *network) MakeProjectInfo(buyers []string, vbs map[string][]*idName, businessType []string) map[string]*projectInfo {
 	pis := n.BuyerProjectInfo(buyers, businessType)
 	vm := map[string]*projectInfo{}
 	for k, v := range vbs {
 		pi := &projectInfo{
 			BuyerCount: int64(len(v)),
+			IdNames:    v,
 		}
 		re := map[string]bool{}
 		for _, vv := range v {
@@ -1220,9 +1253,6 @@ func (n *network) MakeProjectInfo(buyers []string, vbs map[string][]*idName, bus
 					re[vvv] = true
 				}
 			}
-			if entMonitor[vv.Name] {
-				pi.MonitorCount++
-			}
 		}
 		vm[k] = pi
 	}
@@ -1230,7 +1260,7 @@ func (n *network) MakeProjectInfo(buyers []string, vbs map[string][]*idName, bus
 }
 
 //
-func (n *network) AllIntroduceOwner(sqlAppend1, sqlAppend2 string, args []interface{}, isTjProject bool, businessType []string, entMonitor map[string]bool) *introduceOwnerProject {
+func (n *network) AllIntroduceOwner(sqlAppend1, sqlAppend2 string, args []interface{}, isTjProject bool, businessType []string) *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...)
@@ -1279,11 +1309,17 @@ 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, 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)
+		iop.Firstparty = n.Introduce_Firstparty(iop.FirstpartyNetwork, businessType)
+		iop.Supplier = n.Introduce_Supplier(supplier_array, businessType)
+		iop.Adiffb = n.Introduce_Supplier(adiffb_array, businessType)
+		iop.Agency = n.Introduce_Agency(agency_array, businessType)
+		iop.Middleman = n.Introduce_Middleman(middleman_project_array, businessType)
 	}
 	return iop
 }
+
+//
+func (n *network) DeleteCache(positionId int64) {
+	redis.Del("newother", fmt.Sprintf(NetworkManageAllProjectKey, positionId))
+	redis.DelByCodePattern("newother", fmt.Sprintf("networkManage_list_%d_%s", positionId, "*"))
+}