浏览代码

总条数返回

WH01243 9 月之前
父节点
当前提交
d01d7694cc
共有 1 个文件被更改,包括 14 次插入6 次删除
  1. 14 6
      api/internal/service/owner.go

+ 14 - 6
api/internal/service/owner.go

@@ -93,19 +93,22 @@ func (t *OwnerService) OwnerlList() map[string]interface{} {
 	}
 	startIndex := (t.PageIndex - 1) * t.PageSize
 	endIndex := t.PageIndex * t.PageSize
-	returnData := []BuyerProject{}
+	returnData, connectionsNumber := []BuyerProject{}, int64(0)
 	// 如果没有业务字符串,直接返回空数据
 	if businessStr == "" {
 		return map[string]interface{}{
-			"list": returnData,
+			"list":              returnData,
+			"connectionsNumber": connectionsNumber,
 		}
 	}
 	key := fmt.Sprintf("%+v", t)
 	key = fmt.Sprintf("%s%s", key, fmt.Sprintf(" business:%s", businessStr))
 	listKey := "ownerlList-" + common.GetMd5String(fmt.Sprintf("%+v", key))
+	countKey := "ownerlCount-" + common.GetMd5String(fmt.Sprintf("%+v", key))
 	// 检查 Redis 中是否存在列表缓存
 	if ok, err := redis.Exists("newother", listKey); ok && err == nil && t.SourceType != "2" {
 		returnData = handleRedisCache(listKey)
+		connectionsNumber = gconv.Int64(redis.GetInt("newother", countKey))
 		// 处理监控状态
 	}
 	log.Println("111", fmt.Sprintf("%+v", key))
@@ -142,7 +145,7 @@ func (t *OwnerService) OwnerlList() map[string]interface{} {
 		}
 		// 采购单位和项目合并
 		a1 := time.Now().Unix()
-		returnData = BuyerProjectMerge(dataMap, projectMap, t.SourceType)
+		returnData, connectionsNumber = BuyerProjectMerge(dataMap, projectMap, t.SourceType)
 		a2 := time.Now().Unix()
 		fmt.Println("组合数据", a2-a1)
 		if len(returnData) > 0 {
@@ -174,10 +177,13 @@ func (t *OwnerService) OwnerlList() map[string]interface{} {
 			}
 		}
 		redis.Put("newother", listKey, returnData, C.CacheTimeOut)
+		redis.Put("newother", countKey, connectionsNumber, C.CacheTimeOut)
+
 	}
 	// 返回数据组装
 	return map[string]interface{}{
-		"list": returnData,
+		"list":              returnData,
+		"connectionsNumber": connectionsNumber,
 	}
 }
 
@@ -585,8 +591,9 @@ func Findfirstparty(buyerArr []string, returnData []map[string]interface{}) []ma
 }
 
 // 采购单位和项目合并
-func BuyerProjectMerge(dataMap, projectMap *map[string]map[string]interface{}, sourceType string) []BuyerProject {
+func BuyerProjectMerge(dataMap, projectMap *map[string]map[string]interface{}, sourceType string) ([]BuyerProject, int64) {
 	returnData := []BuyerProject{}
+	connectionsNumber := int64(0)
 	for buyerId, buyerMap := range *dataMap {
 		buyerName := gconv.String(buyerMap["buyerName"])
 		count := int64(0)
@@ -631,8 +638,9 @@ func BuyerProjectMerge(dataMap, projectMap *map[string]map[string]interface{}, s
 			})
 
 		}
+		connectionsNumber++
 	}
-	return returnData
+	return returnData, connectionsNumber
 }
 
 // 已监控数据处理