浏览代码

Merge branch 'feature/v4.8.40_wky' of qmx/jy into feature/v4.8.40

wangkaiyue 2 年之前
父节点
当前提交
903110517e
共有 1 个文件被更改,包括 58 次插入68 次删除
  1. 58 68
      src/jfw/front/tags.go

+ 58 - 68
src/jfw/front/tags.go

@@ -204,6 +204,8 @@ func (this *Tags) Index(types, name string) {
 			haveList = false
 			//areaHref = fmt.Sprintf("/tags/industry/%s_%s_all.html", info[0], "%v")
 			industryHref = fmt.Sprintf("/tags/industry/%s_%s_all_%s.html", "%v", checkedArea, "%v")
+			//行业标签获取
+			this.T["industryList"] = this.GetIndustry(industryHref, checkedProvince, checkedCity) //需要根据地区获取不同的标的物
 		}
 		crumbsNav1 = map[string]interface{}{
 			"name": fmt.Sprintf("招标行业分类"),
@@ -213,8 +215,6 @@ func (this *Tags) Index(types, name string) {
 	//地区标签获取
 	this.T["areaList"] = this.GetArea(areaHref)
 
-	//行业标签获取
-	this.T["industryList"] = this.GetIndustry(industryHref, checkedProvince, checkedCity) //需要根据地区获取不同的标的物
 	//标的物标签获取
 
 	//字母表获取
@@ -410,77 +410,67 @@ func (this *Tags) GetkeysMap() []map[string][]map[string]interface{} {
 	return mar
 }
 
+const industryTagNum = 100
+
 func (this *Tags) GetIndustry(industryHref, province, city string) interface{} {
-	//rediskey := fmt.Sprintf("pcindex_getIndustry_%s", industryHref)
-	//if l := redis.Get("seoCache", rediskey); l != nil {
-	//    return l
-	//} else {
-	//data := public.BaseMysql.SelectBySql(`select a.id,a.name,b.id class_id,b.name class_1 from seo_words.seo_industry a inner join  seo_words.seo_industry_class b on a.class_1=b.name and  a.class_2 !='药品'  order by a.class_1`)
-	var filterSql string
-	if province != "" {
-
-	} else if city != "" {
-
-	}
-
-	data := public.BaseMysql.SelectBySql(fmt.Sprintf(`
-SELECT
-	fullData.id,
-	fullData.name,
-	fullData.industry as class_1,
-	fullData.total,
-	b.id AS class_id
-FROM
-	(
-	SELECT
-		industry,
-		name,
-		sum( frequ ) AS total,
-		id,
-		ROW_NUMBER() OVER ( PARTITION BY industry ORDER BY SUM( frequ ) DESC ) AS sort
-	FROM
-		seo_words.seo_hot_purchasing
-    %s
-	GROUP BY
-		industry,
-		name,
-		id
-	) AS fullData
-	INNER JOIN seo_words.seo_industry_class	b
-	on fullData.industry=b.name
-WHERE
-	sort <= %d
-ORDER BY
- class_1 `, filterSql, 20))
-
-	industryArr := []string{}
-	industryMap := map[string][]map[string]interface{}{}
-	if len(*data) > 0 && data != nil {
-		for _, v := range *data {
-			class := qu.ObjToString(v["class_1"])
-			name := qu.ObjToString(v["name"])
-			id := qu.Int64All(v["id"])
-			industryId := qu.Int64All(v["class_id"])
-			if !IsInArr(industryArr, class) {
-				industryArr = append(industryArr, class)
+	rediskey := fmt.Sprintf("pcindex_getIndustry_%s_%s_%s_%d", industryHref, province, city, industryTagNum)
+	if l := redis.Get("seoCache", rediskey); l != nil {
+		return l
+	} else {
+		//data := public.BaseMysql.SelectBySql(`select a.id,a.name,b.id class_id,b.name class_1 from seo_words.seo_industry a inner join  seo_words.seo_industry_class b on a.class_1=b.name and  a.class_2 !='药品'  order by a.class_1`)
+		var filterSql string
+
+		if city != "" {
+			filterSql += " WHERE city ='" + city + "' "
+		} else if province != "" {
+			filterSql += " WHERE province ='" + province + "' "
+		}
+		finalSql := fmt.Sprintf(`
+            SELECT ranked.industry as class_1, ranked.name, ranked.total_frequ, ranked.id,b.id AS class_id
+            FROM (
+              SELECT industry, name, SUM(frequ) AS total_frequ,
+                     MAX(id) AS id,
+                     ROW_NUMBER() OVER (PARTITION BY industry ORDER BY SUM(frequ) DESC) AS row_num
+              FROM seo_words.seo_hot_purchasing
+              %s
+              GROUP BY industry, name
+            ) AS ranked
+                INNER JOIN seo_words.seo_industry_class b
+                on ranked.industry=b.name
+            WHERE row_num <= %d
+            ORDER BY industry, total_frequ DESC;
+        `, filterSql, industryTagNum)
+		//fmt.Println("finalSql---", finalSql)
+		data := public.BaseMysql.SelectBySql(finalSql)
+
+		industryArr := []string{}
+		industryMap := map[string][]map[string]interface{}{}
+		if len(*data) > 0 && data != nil {
+			for _, v := range *data {
+				class := qu.ObjToString(v["class_1"])
+				name := qu.ObjToString(v["name"])
+				id := qu.Int64All(v["id"])
+				industryId := qu.Int64All(v["class_id"])
+				if !IsInArr(industryArr, class) {
+					industryArr = append(industryArr, class)
+				}
+				industryMap[class] = append(industryMap[class], map[string]interface{}{
+					"name": name + qu.ObjToString(config.Seoconfig["seoKeywordSuffix"]),
+					// "url":  fmt.Sprintf("/tags/industry/%v_all_all_%v.html", industryId, id),
+					"url": fmt.Sprintf(industryHref, industryId, id),
+				})
 			}
-			industryMap[class] = append(industryMap[class], map[string]interface{}{
-				"name": name + qu.ObjToString(config.Seoconfig["seoKeywordSuffix"]),
-				// "url":  fmt.Sprintf("/tags/industry/%v_all_all_%v.html", industryId, id),
-				"url": fmt.Sprintf(industryHref, industryId, id),
+		}
+		m := []map[string][]map[string]interface{}{}
+		//
+		for _, v := range industryArr {
+			m = append(m, map[string][]map[string]interface{}{
+				v: industryMap[v],
 			})
 		}
+		redis.Put("seoCache", rediskey, m, cacheTime)
+		return m
 	}
-	m := []map[string][]map[string]interface{}{}
-	//
-	for _, v := range industryArr {
-		m = append(m, map[string][]map[string]interface{}{
-			v: industryMap[v],
-		})
-	}
-	//redis.Put("seoCache", rediskey, m, cacheTime)
-	return m
-	//}
 }
 
 // 判断字符串是否再数组str内