|
@@ -1,28 +1,28 @@
|
|
|
package service
|
|
|
|
|
|
import (
|
|
|
+ "context"
|
|
|
+ "encoding/json"
|
|
|
+ "fmt"
|
|
|
+ "sort"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+
|
|
|
"app.yhyue.com/moapp/jybase/common"
|
|
|
"app.yhyue.com/moapp/jybase/encrypt"
|
|
|
"app.yhyue.com/moapp/jybase/redis"
|
|
|
. "bp.jydev.jianyu360.cn/CRM/networkManage/api/common"
|
|
|
T "bp.jydev.jianyu360.cn/CRM/networkManage/api/common"
|
|
|
"bp.jydev.jianyu360.cn/CRM/networkManage/entity"
|
|
|
- "context"
|
|
|
- "encoding/json"
|
|
|
- "fmt"
|
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
|
"github.com/shopspring/decimal"
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
- "sort"
|
|
|
- "strings"
|
|
|
- "time"
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
- EntINDEX = "ent_info"
|
|
|
- EntTYPE = "ent_info"
|
|
|
- NetworkManageOwnerlList = "networkManage_ownerlList_%d_%s"
|
|
|
- NetworkManageOwnerlCount = "networkManage_ownerlCount_%d_%s"
|
|
|
+ EntINDEX = "ent_info"
|
|
|
+ EntTYPE = "ent_info"
|
|
|
+ NetworkManageOwnerlList = "networkManage_ownerlList_%d_%s"
|
|
|
)
|
|
|
|
|
|
type OwnerService struct {
|
|
@@ -77,12 +77,15 @@ type Project struct {
|
|
|
Money decimal.Decimal `ch:"money"`
|
|
|
}
|
|
|
|
|
|
+type OwnerlListRes struct {
|
|
|
+ ReturnData []BuyerProject
|
|
|
+ ConnectionsNumber int64
|
|
|
+}
|
|
|
+
|
|
|
// OwnerlList 执行主要的业务逻辑
|
|
|
-func (t *OwnerService) OwnerlList() map[string]interface{} {
|
|
|
+func (t *OwnerService) OwnerlList() *OwnerlListRes {
|
|
|
// 先查询采购单位列表
|
|
|
startTime := time.Now().Unix()
|
|
|
- dataMap := &map[string]map[string]interface{}{}
|
|
|
- projectMap := &map[string]map[string]interface{}{}
|
|
|
businessStr := FindBusiness(t.EntId, t.UserId)
|
|
|
// 初始化分页参数
|
|
|
if t.PageSize == 0 {
|
|
@@ -92,51 +95,50 @@ func (t *OwnerService) OwnerlList() map[string]interface{} {
|
|
|
t.PageIndex = 1
|
|
|
}
|
|
|
startIndex := (t.PageIndex - 1) * t.PageSize
|
|
|
- returnData, connectionsNumber := []BuyerProject{}, int64(0)
|
|
|
+ olr := &OwnerlListRes{
|
|
|
+ ReturnData: []BuyerProject{},
|
|
|
+ }
|
|
|
// 如果没有业务字符串,直接返回空数据
|
|
|
if businessStr == "" {
|
|
|
- return map[string]interface{}{
|
|
|
- "list": returnData,
|
|
|
- "connectionsNumber": connectionsNumber,
|
|
|
- }
|
|
|
+ return olr
|
|
|
}
|
|
|
+ //监控状态处理
|
|
|
+ monitorMap := NetworkCom.EntMonitor(gconv.String(t.PositionId))
|
|
|
comKey := common.GetMd5String(fmt.Sprintf("%+v business:%s", t, businessStr))
|
|
|
listKey := fmt.Sprintf(NetworkManageOwnerlList, t.PositionId, comKey)
|
|
|
- countKey := fmt.Sprintf(NetworkManageOwnerlCount, t.PositionId, comKey)
|
|
|
// 检查 Redis 中是否存在列表缓存
|
|
|
if ok, err := redis.Exists("newother", listKey); ok && err == nil && t.SourceType != "2" {
|
|
|
- returnData = handleRedisCache(listKey)
|
|
|
- connectionsNumber = gconv.Int64(redis.GetInt("newother", countKey))
|
|
|
- // 处理监控状态
|
|
|
+ olr = handleRedisCache(listKey)
|
|
|
} else {
|
|
|
// 没有缓存时的处理逻辑
|
|
|
- if t.PartyA != "" || t.Supplier != "" || t.Heterotophy != "" || t.Intermediary != "" || t.Agency != "" {
|
|
|
- dataMap = BuyerList(t.PartyA, t.Supplier, t.Heterotophy, t.Intermediary, t.Agency, t.PositionId)
|
|
|
- if len(*dataMap) == 0 {
|
|
|
- return map[string]interface{}{
|
|
|
- "connectionsNumber": 0,
|
|
|
- "highSuccessNumber": 0,
|
|
|
- "monitorNumber": 0,
|
|
|
- "list": []BuyerProject{},
|
|
|
+ if t.PartyA == "" && t.Supplier == "" && t.Heterotophy == "" && t.Intermediary == "" && t.Agency == "" {
|
|
|
+ return olr
|
|
|
+ }
|
|
|
+ dataMap := BuyerList(t.PartyA, t.Supplier, t.Heterotophy, t.Intermediary, t.Agency, t.PositionId)
|
|
|
+ // 监控状态处理
|
|
|
+ if t.SourceType == "2" {
|
|
|
+ for k, v := range *dataMap {
|
|
|
+ if _, ok1 := monitorMap[gconv.String(v["buyerName"])]; !ok1 {
|
|
|
+ delete(*dataMap, k)
|
|
|
}
|
|
|
}
|
|
|
- // 监控状态处理
|
|
|
- MonitorStatusInit(t.PositionId, dataMap, t.SourceType)
|
|
|
- // 项目数量查询
|
|
|
- buyerArr := getBuyerArr(dataMap)
|
|
|
- // 项目数量处理
|
|
|
- projectMap, connectionsNumber = ProjectHandle(buyerArr, t.Area, businessStr, dataMap, startIndex, t.PageSize, t.SourceType)
|
|
|
- } else {
|
|
|
- return map[string]interface{}{}
|
|
|
}
|
|
|
+ if len(*dataMap) == 0 {
|
|
|
+ return olr
|
|
|
+ }
|
|
|
+ // 项目数量查询
|
|
|
+ buyerArr := getBuyerArr(dataMap)
|
|
|
+ // 项目数量处理
|
|
|
+ projectMap, connectionsNumber := ProjectHandle(buyerArr, t.Area, businessStr, dataMap, startIndex, t.PageSize, t.SourceType)
|
|
|
endTime := time.Now().Unix()
|
|
|
fmt.Println("用时时间:", endTime-startTime)
|
|
|
if len(*projectMap) == 0 {
|
|
|
- return map[string]interface{}{}
|
|
|
+ return olr
|
|
|
}
|
|
|
+ olr.ConnectionsNumber = connectionsNumber
|
|
|
// 采购单位和项目合并
|
|
|
a1 := time.Now().Unix()
|
|
|
- returnData = BuyerProjectMerge(dataMap, projectMap)
|
|
|
+ olr.ReturnData = BuyerProjectMerge(dataMap, projectMap)
|
|
|
a2 := time.Now().Unix()
|
|
|
fmt.Println("组合数据", a2-a1)
|
|
|
/*if len(returnData) > 0 {
|
|
@@ -147,54 +149,46 @@ func (t *OwnerService) OwnerlList() map[string]interface{} {
|
|
|
return aa > bb
|
|
|
})
|
|
|
}*/
|
|
|
- }
|
|
|
- if ok, err := redis.Exists("newother", listKey); !ok || err != nil || t.SourceType == "2" {
|
|
|
- buyerIdArr := getBuyerIdArr(returnData)
|
|
|
+ buyerIdArr := getBuyerIdArr(olr.ReturnData)
|
|
|
// 可介绍业主人脉处理
|
|
|
a3 := time.Now().Unix()
|
|
|
routeList := ConnectionsHandle(buyerIdArr, t.PositionId, false)
|
|
|
a4 := time.Now().Unix()
|
|
|
fmt.Println("组合数1111据", a4-a3)
|
|
|
- updateReturnDataWithRoutes(returnData, routeList)
|
|
|
+ updateReturnDataWithRoutes(olr.ReturnData, routeList)
|
|
|
}
|
|
|
- if len(returnData) > 0 {
|
|
|
- //监控状态处理
|
|
|
- monitorMap := NetworkCom.EntMonitor(gconv.String(t.PositionId))
|
|
|
- for k, value := range returnData {
|
|
|
+ if len(olr.ReturnData) > 0 {
|
|
|
+ for k, value := range olr.ReturnData {
|
|
|
if _, ok := monitorMap[value.BuyerName]; ok {
|
|
|
- returnData[k].IsMonitor = true
|
|
|
+ olr.ReturnData[k].IsMonitor = true
|
|
|
} else {
|
|
|
- returnData[k].IsMonitor = false
|
|
|
+ olr.ReturnData[k].IsMonitor = false
|
|
|
}
|
|
|
}
|
|
|
- redis.Put("newother", listKey, returnData, C.CacheTimeOut)
|
|
|
- redis.Put("newother", countKey, connectionsNumber, C.CacheTimeOut)
|
|
|
+ redis.Put("newother", listKey, olr, C.CacheTimeOut)
|
|
|
}
|
|
|
// 返回数据组装
|
|
|
- return map[string]interface{}{
|
|
|
- "list": returnData,
|
|
|
- "connectionsNumber": connectionsNumber,
|
|
|
- }
|
|
|
+ return olr
|
|
|
}
|
|
|
|
|
|
// handleRedisCache 处理从 Redis 中获取缓存数据的逻辑
|
|
|
-func handleRedisCache(key string) []BuyerProject {
|
|
|
- returnData := []BuyerProject{}
|
|
|
- if bytes, err := redis.GetBytes("newother", key); err == nil && bytes != nil {
|
|
|
- err = json.Unmarshal(*bytes, &returnData)
|
|
|
+func handleRedisCache(key string) *OwnerlListRes {
|
|
|
+ ols := &OwnerlListRes{}
|
|
|
+ if bytes, err := redis.GetNewBytes("newother", key); err == nil && bytes != nil {
|
|
|
+ err = json.Unmarshal(*bytes, &ols)
|
|
|
if err != nil {
|
|
|
// 处理解组错误
|
|
|
fmt.Println("Error unmarshaling from Redis:", err)
|
|
|
}
|
|
|
}
|
|
|
- return returnData
|
|
|
+ return ols
|
|
|
}
|
|
|
|
|
|
// getBuyerArr 从数据映射中获取买家数组
|
|
|
func getBuyerArr(dataMap *map[string]map[string]interface{}) []string {
|
|
|
buyerArr := []string{}
|
|
|
- for _, value := range *dataMap {
|
|
|
- buyerArr = append(buyerArr, fmt.Sprintf(`%s`, gconv.String(value["buyerName"])))
|
|
|
+ for k, _ := range *dataMap {
|
|
|
+ buyerArr = append(buyerArr, k)
|
|
|
}
|
|
|
return buyerArr
|
|
|
}
|
|
@@ -593,40 +587,6 @@ func BuyerProjectMerge(dataMap, projectMap *map[string]map[string]interface{}) [
|
|
|
return returnData
|
|
|
}
|
|
|
|
|
|
-// 已监控数据处理
|
|
|
-func MonitorStatusInit(positionId int64, dataMap *map[string]map[string]interface{}, sourceType string) {
|
|
|
- monitorMap := map[string]bool{}
|
|
|
- query := map[string]interface{}{
|
|
|
- "userId": gconv.String(positionId),
|
|
|
- }
|
|
|
- clist, ok := Mgo.Find("follow_customer", query, ``, `{"name":1}`, false, -1, -1)
|
|
|
- if ok && clist != nil && len(*clist) > 0 {
|
|
|
- for _, v := range *clist {
|
|
|
- monitorMap[gconv.String(v["name"])] = true
|
|
|
- }
|
|
|
- }
|
|
|
- //采购单位和自己监控的对比
|
|
|
- newMap := &map[string]map[string]interface{}{}
|
|
|
- for k, v := range *dataMap {
|
|
|
- buyerName := gconv.String(v["buyerName"])
|
|
|
- if _, ok1 := monitorMap[gconv.String(buyerName)]; ok1 {
|
|
|
- v["isMonitor"] = true
|
|
|
- (*newMap)[k] = v
|
|
|
- } else {
|
|
|
- if sourceType != "2" {
|
|
|
- v["isMonitor"] = false
|
|
|
- (*newMap)[k] = v
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- if sourceType == "2" {
|
|
|
- *dataMap = *newMap
|
|
|
- return
|
|
|
- }
|
|
|
- if newMap != nil {
|
|
|
- *dataMap = *newMap
|
|
|
- }
|
|
|
-}
|
|
|
func FindStatus(positionId int64) (map[string]bool, map[string]bool, map[string]bool) {
|
|
|
//未处理
|
|
|
untreatedMap := map[string]bool{}
|
|
@@ -663,16 +623,21 @@ func BuyerList(partyA, supplier, heterotophy, intermediary, agency string, posit
|
|
|
dataMap := &map[string]map[string]interface{}{}
|
|
|
//甲方
|
|
|
if partyA != "" {
|
|
|
- intermediaryArr := []string{}
|
|
|
for _, v := range strings.Split(partyA, ",") {
|
|
|
- if v != "" {
|
|
|
- intermediaryArr = append(intermediaryArr, fmt.Sprintf("'%s'", v))
|
|
|
+ (*dataMap)[v] = map[string]interface{}{
|
|
|
+ "buyerType": "firstparty",
|
|
|
}
|
|
|
}
|
|
|
- if len(partyA) > 0 {
|
|
|
- partyASql := fmt.Sprintf(`select id as buyer_id,company_name as buyer from ent_info where id in (%s)`, strings.Join(intermediaryArr, ","))
|
|
|
- FindHandle(partyASql, dataMap, "firstparty")
|
|
|
- }
|
|
|
+ // intermediaryArr := []string{}
|
|
|
+ // for _, v := range strings.Split(partyA, ",") {
|
|
|
+ // if v != "" {
|
|
|
+ // intermediaryArr = append(intermediaryArr, fmt.Sprintf("'%s'", v))
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // if len(partyA) > 0 {
|
|
|
+ // partyASql := fmt.Sprintf(`select id as buyer_id,company_name as buyer from ent_info where id in (%s)`, strings.Join(intermediaryArr, ","))
|
|
|
+ // FindHandle(partyASql, dataMap, "firstparty")
|
|
|
+ // }
|
|
|
}
|
|
|
//供应商 //同甲异业
|
|
|
findInSetArr := []string{}
|
|
@@ -733,28 +698,27 @@ func BuyerList(partyA, supplier, heterotophy, intermediary, agency string, posit
|
|
|
func ProjectHandle(buyerArr []string, area, businessStr string, dataMap *map[string]map[string]interface{}, startIndex, PageSize int64, sourceType string) (*map[string]map[string]interface{}, int64) {
|
|
|
projectMap := &map[string]map[string]interface{}{}
|
|
|
count := int64(0)
|
|
|
- sqlStr := "select buyer,buyer_id,groupUniqArray(area) as area,count(1) as ocount,SUM(project_money) as project_money ,MAX(zbtime) as zbtime from transaction_info_all " +
|
|
|
- "where"
|
|
|
- countSql := "select count(1) as count from (%s) b "
|
|
|
+ sqlStr := "select buyer,buyer_id,groupUniqArray(area) as area,count(1) as ocount,SUM(project_money) as project_money ,MAX(zbtime) as zbtime from transaction_info_all where"
|
|
|
+ countSql := "select count(1) as count from (%s) b "
|
|
|
if len(buyerArr) > 0 {
|
|
|
buyer, buyerArgs := ConditionHandle(buyerArr)
|
|
|
- sqlStr += fmt.Sprintf(fmt.Sprintf(" buyer in (%s)", buyer), buyerArgs...)
|
|
|
+ sqlStr += fmt.Sprintf(fmt.Sprintf(" buyer_id in (%s)", buyer), buyerArgs...)
|
|
|
}
|
|
|
if len(area) > 0 && area != "" {
|
|
|
areaStr, areaArgs := ConditionHandle(strings.Split(area, ","))
|
|
|
- sqlStr += fmt.Sprintf(fmt.Sprintf(" area in (%s)", areaStr), areaArgs...)
|
|
|
+ sqlStr += fmt.Sprintf(fmt.Sprintf(" area in (%s)", areaStr), areaArgs...)
|
|
|
}
|
|
|
if len(businessStr) > 0 {
|
|
|
business, businessArgs := ConditionHandle(strings.Split(businessStr, ","))
|
|
|
- sqlStr += fmt.Sprintf(fmt.Sprintf(" and hasAny(topscopeclass,[%s])>0", business), businessArgs...)
|
|
|
+ sqlStr += fmt.Sprintf(fmt.Sprintf(" and hasAny(topscopeclass,[%s])>0", business), businessArgs...)
|
|
|
}
|
|
|
- sqlStr += " GROUP by buyer,buyer_id "
|
|
|
+ sqlStr += " and project_bidstatus>1 GROUP by buyer,buyer_id "
|
|
|
if sourceType == "1" {
|
|
|
- sqlStr += " HAVING ocount>2 "
|
|
|
+ sqlStr += " HAVING ocount>2 "
|
|
|
}
|
|
|
- sqlStr += " order by zbtime desc"
|
|
|
+ sqlStr += " order by zbtime desc"
|
|
|
countSql = fmt.Sprintf(countSql, sqlStr)
|
|
|
- sqlStr += " limit ?,? "
|
|
|
+ sqlStr += " limit ?,?"
|
|
|
//总数查询
|
|
|
rows, err1 := ClickhouseConn.Query(context.TODO(), sqlStr, startIndex, PageSize)
|
|
|
count = T.NetworkCom.Count(countSql)
|