소스 검색

Merge branch 'feature/v1.0.4' of https://jygit.jydev.jianyu360.cn/CRM/application into feature/v1.0.4

wangchuanjin 1 년 전
부모
커밋
8c98260498
5개의 변경된 파일145개의 추가작업 그리고 180개의 파일을 삭제
  1. 1 1
      api/application.api
  2. 9 8
      api/common/initconfig.go
  3. 93 143
      api/internal/service/owner.go
  4. 41 27
      api/internal/service/plistService.go
  5. 1 1
      api/internal/types/types.go

+ 1 - 1
api/application.api

@@ -214,7 +214,7 @@ type (
 		PageNum      int    `json:"pageNum"`
 		PageSize     int    `json:"pageSize"`
 		BusinessType string `json:"businessType"`
-		SaleStatus   int    `json:"saleStatus"`
+		SaleStatus   string `json:"saleStatus"`
 		ProjectName  string `json:"projectName,optional"`
 		StartTime    int64  `json:"startTime,optional"`
 		EntTime      int64  `json:"entTime,optional"`

+ 9 - 8
api/common/initconfig.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"flag"
 	"fmt"
+	"github.com/zeromicro/go-zero/zrpc"
 	"log"
 	"time"
 
@@ -169,14 +170,14 @@ func InitConf() {
 		NewEs(DB.Es.Version, DB.Es.Addr, DB.Es.Size, DB.Es.UserName, DB.Es.Password)
 	}
 
-	//UserCenterRpc = usercenter.NewUserCenter(zrpc.MustNewClient(C.UserCenterRpc))
-	//FileCenterRpc = filecenter.NewFileCenter(zrpc.MustNewClient(C.FileCenterRpc))
-	//BaseCenterRpc = basecenter.NewBaseCenter(zrpc.MustNewClient(C.BaseCenterRpc))
-	//SocialPlatformRpc = social.NewSocial(zrpc.MustNewClient(C.SocialPlatformRpc))
-	//Middleground = middleground.NewMiddleground(C.BaseCenterRpc.Etcd.Hosts).
-	//	RegResourceCenter(C.ResourceCenterKey)
-	///*	Middleground = middleground.NewMiddleground([]string{"192.168.3.206:2379"}).
-	//	RegResourceCenter(C.ResourceCenterKey)*/
+	UserCenterRpc = usercenter.NewUserCenter(zrpc.MustNewClient(C.UserCenterRpc))
+	FileCenterRpc = filecenter.NewFileCenter(zrpc.MustNewClient(C.FileCenterRpc))
+	BaseCenterRpc = basecenter.NewBaseCenter(zrpc.MustNewClient(C.BaseCenterRpc))
+	SocialPlatformRpc = social.NewSocial(zrpc.MustNewClient(C.SocialPlatformRpc))
+	Middleground = middleground.NewMiddleground(C.BaseCenterRpc.Etcd.Hosts).
+		RegResourceCenter(C.ResourceCenterKey)
+	/*	Middleground = middleground.NewMiddleground([]string{"192.168.3.206:2379"}).
+		//	RegResourceCenter(C.ResourceCenterKey)*/
 	conf.MustLoad(*pushFile, &Push)
 	ConnectClickhouse(DB.Clickhouse)
 }

+ 93 - 143
api/internal/service/owner.go

@@ -89,19 +89,17 @@ func (t *OwnerService) OwnerlList() map[string]interface{} {
 			buyerArr = append(buyerArr, fmt.Sprintf(`"%s"`, gconv.String(value["buyerName"])))
 		}
 		//项目数量处理
-		projectMap = ProjectHandle(buyerArr, "", t.Area)
+		_, projectMap = ProjectHandle(buyerArr, t.PositionId, t.SearchEntName, t.Area, t.SourceType, t.ProcessingStatus)
 		logx.Info(projectMap)
 	} else if t.SearchEntName != "" {
 		//1 只看转介绍成功率高2只看已监控的
-		if t.SourceType == "2" {
-			buyerArr := FindMonitor(t.PositionId, t.SearchEntName)
-			if len(buyerArr) > 0 {
-				projectMap = ProjectHandle(buyerArr, "", t.Area)
-			}
-		} else {
-			projectMap = ProjectHandle([]string{}, t.SearchEntName, t.Area)
+		//先查找采购单位数据
+		dataMap, projectMap = ProjectHandle([]string{}, t.PositionId, t.SearchEntName, t.Area, t.SourceType, t.ProcessingStatus)
+		if t.ProcessingStatus != "" {
+			ProcessingStatusInit(t.PositionId, dataMap, t.ProcessingStatus)
 		}
-		dataMap = FindBuyer(t.SearchEntName)
+		//监控状态处理
+		MonitorStatusInit(t.PositionId, dataMap, t.SourceType)
 	}
 	if len(*dataMap) == 0 {
 		return map[string]interface{}{}
@@ -240,6 +238,9 @@ func ConnectionsHandle(buyerArr []string, positionId int64, isAll bool) []map[st
 			}
 		}
 	}
+	if isAll && len(returnData) > 0 {
+		return returnData
+	}
 	//供应商  采购单位 供应商     招标代理机构  采购单位  招标代理机构  需要计算合作次数
 	winnerSql := fmt.Sprintf(`SELECT DISTINCT a.project_name as  project_name,a.project_id as project_id , a.zbtime as zbtime ,a.buyer_id as buyer_id,a.buyer as  buyer,a.agency_id as agency_id,a.agency as  agency,c.company_name as company_name ,b.name as personName ,a.winnerId  as awinnerId
 	FROM 
@@ -371,8 +372,8 @@ func BuyerProjectMerge(dataMap, projectMap *map[string]map[string]interface{}, s
 	monitorNumber := int64(0)
 	for buyerId, buyerMap := range *dataMap {
 		buyerName := gconv.String(buyerMap["buyerName"])
-		if _, ok := (*projectMap)[buyerId]; ok {
-			projectMap := (*projectMap)[buyerId]
+		if _, ok := (*projectMap)[buyerName]; ok {
+			projectMap := (*projectMap)[buyerName]
 			if isMonitor := gconv.Bool(buyerMap["isMonitor"]); isMonitor {
 				monitorNumber++
 			}
@@ -462,19 +463,48 @@ func MonitorStatusInit(positionId int64, dataMap *map[string]map[string]interfac
 }
 
 // 监控数据查询初始化
-func FindMonitor(positionId int64, entName string) []string {
-	nameArr := []string{}
+func FindMonitor(positionId int64, entName string) map[string]bool {
+	nameMap := map[string]bool{}
 	clist, ok := Mgo.Find("", map[string]interface{}{
 		"userId": positionId,
 		"name":   fmt.Sprintf(" /.*%s.*/i", entName),
 	}, "", `{"name":1}`, false, -1, -1)
 	if ok && clist != nil && len(*clist) > 0 {
 		for _, v := range *clist {
-			nameArr = append(nameArr, fmt.Sprintf(`"%s"`, gconv.String(v["name"])))
+			nameMap[gconv.String(v)] = true
 		}
-
 	}
-	return nameArr
+	return nameMap
+}
+func FindProcessingStatus(positionId int64) (map[string]bool, map[string]bool, map[string]bool) {
+	//未处理
+	untreatedMap := map[string]bool{}
+	//已忽略
+	ignoredMap := map[string]bool{}
+	//已创建
+	createdMap := map[string]bool{}
+	processingArr := CrmMysql.Find(entity.CONNECTION_STATUS, map[string]interface{}{
+		"type":        1,
+		"position id": positionId,
+	}, "relate_id,is_handle,is_ignore,is_create", "", -1, -1)
+	if len(*processingArr) > 0 {
+		for _, v := range *processingArr {
+			entId := gconv.String(v["relate_id"])
+			handle := gconv.Int64(v["is_handle"])
+			ignore := gconv.Int64(v["is_ignore"])
+			create := gconv.Int64(v["is_create"])
+			if handle == 1 {
+				untreatedMap[entId] = true
+			}
+			if ignore == 1 {
+				ignoredMap[entId] = true
+			}
+			if create == 1 {
+				createdMap[entId] = true
+			}
+		}
+	}
+	return untreatedMap, ignoredMap, createdMap
 }
 
 // 处理状态初始化
@@ -581,149 +611,83 @@ func BuyerList(partyA, supplier, heterotophy, intermediary, agency string) *map[
 }
 
 // 项目数量查询
-func ProjectHandle(buyerArr []string, entName, area string) *map[string]map[string]interface{} {
+func ProjectHandle(buyerArr []string, positionId int64, entName, area, sourceType, processingStatus string) (*map[string]map[string]interface{}, *map[string]map[string]interface{}) {
+
 	projectMap := &map[string]map[string]interface{}{}
+	returnMap := &map[string]map[string]interface{}{}
 	sql := ""
 	sqlStr := ""
 	if entName != "" {
-		sql = `{"query":{"bool":{"must":[{"terms":{"buyer":[%s]%s}}]}},"aggs":{"buyer_count":{"terms":{"field":"buyer","size":1000,"order":{"_count":"desc"}},"aggs":{"project_count":{"terms":{"field":"winner"}}}},"area_count":{"terms":{"field":"buyer","size":1000,"order":{"_count":"desc"}},"aggs":{"area_count":{"terms":{"field":"area"}}}},"money_count":{"terms":{"field":"buyer","size":1000,"order":{"_count":"desc"}},"aggs":{"money_count":{"sum":{"field":"bidendtime"}}}},"zbtime_count":{"terms":{"field":"buyer","size":1000,"order":{"_count":"desc"}},"aggs":{"zbtime_count":{"max":{"field":"bidendtime"}}}}},"size":%d}`
-		sqlStr = fmt.Sprintf(sql, strings.Join(buyerArr, ","), common.If(area != "", fmt.Sprintf(`,{"term":{"area":"%s"}}`, area), ""), len(buyerArr))
-
+		sql = `{"query":{"bool":{"must":[{"multi_match":{"query":"%s","type":"phrase","fields":["buyer.mbuyer"]}}%s]}},"aggs":{"buyer_count":{"terms":{"field":"buyer","size":1000,"order":{"zbtime_count":"desc"}},"aggs":{"area_count":{"terms":{"field":"area"}},"buyer_id":{"terms":{"field":"id"}},"money_count":{"sum":{"field":"bidendtime"}},"zbtime_count":{"max":{"field":"bidendtime"}}}}},"size":0}`
+		sqlStr = fmt.Sprintf(sql, entName, common.If(area != "", fmt.Sprintf(`,{"term":{"area":"%s"}}`, area), ""))
 	} else {
-		sql = `{"query":{"bool":{"must":[{"terms":{"buyer":[%s]%s}}]}},"aggs":{"buyer_count":{"terms":{"field":"buyer","size":1000,"order":{"_count":"desc"}},"aggs":{"project_count":{"terms":{"field":"winner"}}}},"area_count":{"terms":{"field":"buyer","size":1000,"order":{"_count":"desc"}},"aggs":{"area_count":{"terms":{"field":"area"}}}},"money_count":{"terms":{"field":"buyer","size":1000,"order":{"_count":"desc"}},"aggs":{"money_count":{"sum":{"field":"bidendtime"}}}},"zbtime_count":{"terms":{"field":"buyer","size":1000,"order":{"_count":"desc"}},"aggs":{"zbtime_count":{"max":{"field":"bidendtime"}}}}},"size":%d}`
-		sqlStr = fmt.Sprintf(sql, strings.Join(buyerArr, ","), common.If(area != "", fmt.Sprintf(`,{"term":{"area":"%s"}}`, area), ""), len(buyerArr))
-
+		sql = `{"query":{"bool":{"must":[{"terms":{"buyer":[%s]}}%s]}},"aggs":{"buyer_count":{"terms":{"field":"buyer","size":1000,"order":{"zbtime_count":"desc"}},"aggs":{"area_count":{"terms":{"field":"area"}},"buyer_id":{"terms":{"field":"id"}},"money_count":{"sum":{"field":"bidendtime"}},"zbtime_count":{"max":{"field":"bidendtime"}}}}},"size":0}`
+		sqlStr = fmt.Sprintf(sql, strings.Join(buyerArr, ","), common.If(area != "", fmt.Sprintf(`,{"term":{"area":"%s"}}`, area), ""))
 	}
 	data, _, _ := elastic.GetAggs(INDEX, TYPE, sqlStr)
-	for name, object := range data {
-		switch name {
-		case "buyer_count":
-			buyerArr := BuyerAggStruct{}
-			bs, ok := object.MarshalJSON()
-			if ok != nil {
-				logx.Error("解析项目数据失败", object)
-				continue
-			}
-			json.Unmarshal(bs, &buyerArr)
-			for _, v := range buyerArr.Buckets {
-				key := v.Key
-				if (*projectMap)[key] != nil {
-					value := (*projectMap)[key]
-					value["count"] = v.Doc_count
-					(*projectMap)[key] = value
-				} else {
-					(*projectMap)[key] = map[string]interface{}{
-						"count": v.Doc_count,
-					}
-				}
-			}
-		case "area_count":
-			areaArr := AreaAggStruct{}
-			bs, ok := object.MarshalJSON()
-			if ok != nil {
-				logx.Error("解析项目数据失败", object)
-				continue
-			}
-			json.Unmarshal(bs, &areaArr)
-			logx.Info(areaArr)
-			for _, v := range areaArr.Buckets {
-				key := v.Key
-				area := ""
-				for _, v1 := range v.Area_count.Buckets {
-					area = Deduplication(area, v1.Key)
-				}
-				if (*projectMap)[key] != nil {
-					value := (*projectMap)[key]
-					value["area"] = area
-					(*projectMap)[key] = value
-				} else {
-
-					(*projectMap)[key] = map[string]interface{}{
-						"area": area,
-					}
-				}
-			}
-		case "money_count":
-			moneyArr := MoneyAggStruct{}
-			bs, ok := object.MarshalJSON()
-			if ok != nil {
-				logx.Error("解析项目数据失败", object)
-				continue
+	if len(data) == 0 {
+		return projectMap, returnMap
+	}
+	for _, object := range data {
+		buyerArr := BuyerAggStruct{}
+		bs, ok := object.MarshalJSON()
+		if ok != nil {
+			logx.Error("解析项目数据失败", object)
+			continue
+		}
+		A := gconv.Map(bs)
+		logx.Info(A)
+		err := json.Unmarshal(bs, &buyerArr)
+		logx.Info(err)
+		for _, v := range buyerArr.Buckets {
+			buyerName := v.Key
+			area := ""
+			buyerId := ""
+			for _, areaEntity := range v.Area_count.Buckets {
+				area = Deduplication(area, areaEntity.Key)
 			}
-			json.Unmarshal(bs, &moneyArr)
-			logx.Info(moneyArr)
-			for _, v := range moneyArr.Buckets {
-				key := v.Key
-				if (*projectMap)[key] != nil {
-					value := (*projectMap)[key]
-					value["money"] = v.Money_count.Value
-					(*projectMap)[key] = value
-				} else {
-					(*projectMap)[key] = map[string]interface{}{
-						"money": v.Money_count.Value,
-					}
+			for _, buyerIdEntity := range v.Buyer_id.Buckets {
+				if buyerIdEntity.Key != "" {
+					buyerId = buyerIdEntity.Key
 				}
 			}
-		case "zbtime_count":
-			timeArr := TimeAggStruct{}
-			bs, ok := object.MarshalJSON()
-			if ok != nil {
-				logx.Error("解析项目数据失败", object)
-				continue
+			(*projectMap)[buyerName] = map[string]interface{}{
+				"area":    area,
+				"zbtime":  v.Zbtime_count.Value,
+				"money":   v.Money_count.Value,
+				"count":   v.Doc_count,
+				"buyerId": buyerId,
 			}
-			a := json.Unmarshal(bs, &timeArr)
-			logx.Info(timeArr, a)
-			for _, v := range timeArr.Buckets {
-				key := v.Key
-				if (*projectMap)[key] != nil {
-					value := (*projectMap)[key]
-					value["zbtime"] = v.Zbtime_count.Value
-					(*projectMap)[key] = value
-				} else {
-					(*projectMap)[key] = map[string]interface{}{
-						"zbtime": v.Zbtime_count.Value,
-					}
-				}
+			(*returnMap)[buyerId] = map[string]interface{}{
+				"buyerName": buyerName,
 			}
 		}
 	}
-	return projectMap
+	return projectMap, returnMap
 }
 
-type TimeAggStruct struct {
+type BuyerAggStruct struct {
 	Buckets []struct {
 		Key          string `json:"key,omitempty"`
+		Doc_count    int64  `json:"doc_count,omitempty"`
 		Zbtime_count struct {
 			Value interface{} `json:"value,omitempty"`
 		} `json:"zbtime_count,omitempty"`
-	}
-}
-type MoneyAggStruct struct {
-	Buckets []struct {
-		Key         string `json:"key,omitempty"`
 		Money_count struct {
 			Value interface{} `json:"value,omitempty"`
 		} `json:"money_count,omitempty"`
-	}
-}
-type BuyerAggStruct struct {
-	Buckets []struct {
-		Key         string `json:"key,omitempty"`
-		Doc_count   int64  `json:"doc_count,omitempty"`
-		Buyer_count struct {
-			value string `json:"value,omitempty"`
-		} `json:"buyer_count,omitempty"`
-	}
-}
-type AreaAggStruct struct {
-	Buckets []struct {
-		Key        string `json:"key,omitempty"`
 		Area_count struct {
 			Buckets []struct {
 				Key       string `json:"key,omitempty"`
 				Doc_count int64  `json:"doc_count,omitempty"`
 			}
 		} `json:"area_count"`
+		Buyer_id struct {
+			Buckets []struct {
+				Key       string `json:"key,omitempty"`
+				Doc_count int64  `json:"doc_count,omitempty"`
+			}
+		} `json:"buyer_id"`
 	}
 }
 
@@ -830,20 +794,6 @@ func Deduplication(a, b string) string {
 	}
 	return strings.Join(newArr, ",")
 }
-func FindBuyer(searchName string) *map[string]map[string]interface{} {
-	sql := `{"query":{"bool":{"must":[{"match":{"company_name":"%s"}}]}},"sort":[{"_id":"asc"}],"_source":["id","company_name"],"from":0,"size":10}`
-	sqlStr := fmt.Sprintf(sql, searchName)
-	data := elastic.Get(EntINDEX, EntTYPE, sqlStr)
-	dataMap := &map[string]map[string]interface{}{}
-	for _, m := range *data {
-		id := gconv.String(m["id"])
-		name := gconv.String(m["company_name"])
-		(*dataMap)[id] = map[string]interface{}{
-			"buyerName": name,
-		}
-	}
-	return dataMap
-}
 
 // 路径列表
 func (t *OwnerService) OwnerRoute() []map[string]interface{} {

+ 41 - 27
api/internal/service/plistService.go

@@ -55,7 +55,7 @@ func GetProjectList(req *types.ProjectListReq) (resultList []*ProjectEntry, hasN
 
 	preSales := preSalesStatus(req.PositionId)
 	isSqlPage := false
-	if req.SaleStatus == 0 {
+	if req.SaleStatus == "0" {
 		isSqlPage = true // 是否sql分页
 	}
 	countSql, findSql := getQuerySql(req, isSqlPage, buyerArr)
@@ -70,16 +70,18 @@ func GetProjectList(req *types.ProjectListReq) (resultList []*ProjectEntry, hasN
 		resultList = append(resultList, &project)
 	}
 
-	filterData(req, resultList, preSales, isSqlPage)
+	resultList = filterData(req, resultList, preSales, isSqlPage)
 	if !isSqlPage {
-		start := (req.PageNum - 1) * req.PageSize
-		end := start + req.PageSize
-		if req.PageNum > 1 {
-			resultList = resultList[start:end]
-		} else {
-			resultList = resultList[:req.PageSize]
-		}
 		total = len(resultList)
+		if total > req.PageSize {
+			start := (req.PageNum - 1) * req.PageSize
+			end := start + req.PageSize
+			if req.PageNum > 1 {
+				resultList = resultList[start:end]
+			} else {
+				resultList = resultList[:req.PageSize]
+			}
+		}
 	} else {
 		total = int(T.NetworkCom.Count(countSql))
 	}
@@ -115,10 +117,10 @@ func getQuerySql(req *types.ProjectListReq, isPage bool, buyerArr []string) (cou
 	}
 	//	商机类型
 	if req.BusinessType != "" && req.BusinessType != "全部" {
-		querys = append(querys, fmt.Sprintf(" a.business_type in ('%s') ", req.BusinessType))
+		querys = append(querys, fmt.Sprintf(" a.business_type in ('%s') ", strings.Join(strings.Split(req.BusinessType, ","), "', '")))
 	}
 	if req.ProjectName != "" {
-		querys = append(querys, " a.projectname like '% "+req.ProjectName+"%'")
+		querys = append(querys, " a.project_name like '%"+req.ProjectName+"%'")
 	}
 	if req.StartTime > 0 && req.EntTime > 0 {
 		st := req.StartTime + 90*24*60*60
@@ -216,33 +218,45 @@ func getQuerySql(req *types.ProjectListReq, isPage bool, buyerArr []string) (cou
 // @Author jianghan
 // @Description 过滤数据/补充销售机会状态信息,返回分页结果数据
 // @Date 2024/4/18
-func filterData(req *types.ProjectListReq, resultList []*ProjectEntry, preSales map[string]interface{}, isSqlPage bool) {
+func filterData(req *types.ProjectListReq, resultList []*ProjectEntry, preSales map[string]interface{}, isSqlPage bool) []*ProjectEntry {
 	var newList []*ProjectEntry
-	f := ""
-	v := 0
-	if req.SaleStatus == 1 {
-		f = "is_handle"
-		v = 0
-	} else if req.SaleStatus == 2 {
-		f = "is_ignore"
-		v = 0
-	} else if req.SaleStatus == 3 {
-		f = "is_create"
-		v = 1
+	f := make(map[string]int, 3)
+	if strings.Contains(req.SaleStatus, "1") {
+		f["is_handle"] = 0
+	} else if strings.Contains(req.SaleStatus, "2") {
+		f["is_ignore"] = 1
+	} else if strings.Contains(req.SaleStatus, "3") {
+		f["is_create"] = 1
 	}
 	for _, m := range resultList {
 		if m1, ok := preSales[m.ProjectId].(map[string]interface{}); ok {
 			m.IsHandle = common.IntAll(m1["is_handle"])
 			m.IsIgnore = common.IntAll(m1["is_ignore"])
 			m.IsCreate = common.IntAll(m1["is_create"])
-			if !isSqlPage && m1[f] == v {
-				newList = append(newList, m)
+		}
+		if !isSqlPage {
+			for k, v := range f {
+				if k == "is_handle" && m.IsHandle == v {
+					newList = append(newList, m)
+					break
+				} else if k == "is_ignore" && m.IsIgnore == v {
+					newList = append(newList, m)
+					break
+				} else if k == "is_create" && m.IsCreate == v {
+					newList = append(newList, m)
+					break
+				}
 			}
 		}
 	}
-	if len(newList) > 0 {
-		resultList = newList
+	if !isSqlPage {
+		if newList == nil {
+			resultList = make([]*ProjectEntry, 0)
+		} else {
+			resultList = newList
+		}
 	}
+	return resultList
 }
 
 // @Author jianghan

+ 1 - 1
api/internal/types/types.go

@@ -272,7 +272,7 @@ type ProjectListReq struct {
 	PageNum      int    `json:"pageNum"`
 	PageSize     int    `json:"pageSize"`
 	BusinessType string `json:"businessType"`
-	SaleStatus   int    `json:"saleStatus"`
+	SaleStatus   string `json:"saleStatus"`
 	ProjectName  string `json:"projectName,optional"`
 	StartTime    int64  `json:"startTime,optional"`
 	EntTime      int64  `json:"entTime,optional"`