소스 검색

feat:提交

wangkaiyue 1 년 전
부모
커밋
49cded5030
5개의 변경된 파일49개의 추가작업 그리고 49개의 파일을 삭제
  1. 8 2
      internal/service/hybgStruct.go
  2. 4 3
      internal/tags/init.go
  3. 11 12
      internal/tags/list.go
  4. 5 32
      resource/template/pc/hybg_index.html
  5. 21 0
      utility/cache.go

+ 8 - 2
internal/service/hybgStruct.go

@@ -163,7 +163,13 @@ func (root *HYBGRoot) GetDetail(ctx context.Context, detailId string) map[string
 	return queryRes.Map()
 }
 
+// GetNewKeywordList 随机获取关键词最新的一篇文章
 func (root *HYBGRoot) GetNewKeywordList() []map[string]interface{} {
-
-	return nil
+	ctx := context.Background()
+	res, err := g.DB().Query(ctx, `SELECT key_word ,MAX(id) as id  FROM analysis_report  WHERE key_word !='' group by key_word `)
+	if err != nil {
+		g.Log().Errorf(ctx, "HYBGRoot.GetNewKeywordList查询数据异常%v", err)
+		return nil
+	}
+	return res.List()
 }

+ 4 - 3
internal/tags/init.go

@@ -69,9 +69,10 @@ func init() {
 	g.View().BindFunc("GetALlLetterCode", GetALlLetterCode)                                                    //随机热门字母关键词
 	g.View().BindFunc("GetRandomLetterKeywords", service.JySeoKeyWordLetterRoot.GetRandomLetterKeywords)       //随机字母关键词
 	g.View().BindFunc("GetRandomPinyinHotKeywords", service.JySeoKeyWordPinyinRoot.GetRandomHotKeywords)
-	g.View().BindFunc("GetHyList", GetHyList)                     //获取行业列表报告
-	g.View().BindFunc("GetJyBlogList", service.GetJyBlogList)     //剑鱼博客
-	g.View().BindFunc("GetStrategyOneList", GetStrategyListCache) //获取招投标攻略某个栏目列表
+	g.View().BindFunc("GetHyList", GetHyList)                                       //获取行业列表报告
+	g.View().BindFunc("GetHyKeywordNewestDetailList", GetHyKeywordNewestDetailList) //获取行业列表报告
+	g.View().BindFunc("GetJyBlogList", service.GetJyBlogList)                       //剑鱼博客
+	g.View().BindFunc("GetStrategyOneList", GetStrategyListCache)                   //获取招投标攻略某个栏目列表
 
 	g.View().BindFunc("IdSE2Encode", func(id string) string {
 		return encrypt.SE2.Encode2Hex(id)

+ 11 - 12
internal/tags/list.go

@@ -6,6 +6,7 @@ import (
 	"github.com/gogf/gf/v2/frame/g"
 	"github.com/gogf/gf/v2/util/gconv"
 	"jyseo/internal/service"
+	"jyseo/utility"
 )
 
 // GetMiniTab 查询Tab数据
@@ -74,16 +75,14 @@ func GetHyList(hyName, areaCode string, t int, num int) []*service.InfoList {
 }
 
 func GetStrategyListCache(t, s string, num int) (rData []map[string]interface{}) {
-	ctx := context.Background()
-	redisKey := fmt.Sprintf("GetStrategyListCache_%s%s%d", t, s, num)
-	gv, err := g.Redis().Get(ctx, redisKey)
-	if !gv.IsNil() && err == nil {
-		return gv.Maps()
-	} else {
-		rData = service.GuidelineAndInformation(t, s, num)
-		if len(rData) > 0 {
-			g.Redis().SetEX(ctx, redisKey, rData, 5*60)
-		}
-	}
-	return
+	return utility.QueryCacheArrMap(context.Background(), func() []map[string]interface{} {
+		return service.GuidelineAndInformation(t, s, num)
+	}, fmt.Sprintf("GetStrategyListCache_%s%s%d", t, s, num))
+}
+
+// GetHyKeywordNewestDetailList 获取行业报告最新关键词的一篇文章
+func GetHyKeywordNewestDetailList() []map[string]interface{} {
+	return utility.QueryCacheArrMap(context.Background(), func() []map[string]interface{} {
+		return service.JySeoHYBGRoot.GetNewKeywordList()
+	}, "GetHyKeywordNewestDetailList")
 }

+ 5 - 32
resource/template/pc/hybg_index.html

@@ -58,7 +58,7 @@
       <!-- 主体内容 -->
       <section class="w report-home-content">
         <section class="report-content--main">
-          {{GetHyList "建筑行业" "" 0 5|dump}}
+          {{GetHyList "建筑工程" "" 0 5|dump}}
           {{include "pc/components/report-card-single.html" .}}
           {{include "pc/components/report-card-double.html" .}}
           {{include "pc/components/report-card-single.html" .}}
@@ -84,19 +84,13 @@
               <h3>热门专题分析报告</h3>
             </div>
             <div class="card-main">
+              {{$keywords:=GetHyKeywordNewestDetailList}}
               <ul class="hot-list">
+                {{range $v:=$keywords}}
                 <li>
-                  <a href="#" class="hot-item">智能安防</a>
-                </li>
-                <li>
-                  <a href="#" class="hot-item">可穿戴设备</a>
-                </li>
-                <li>
-                  <a href="#" class="hot-item">3D打印</a>
-                </li>
-                <li>
-                  <a href="#" class="hot-item">医药</a>
+                  <a href="/hybg/{{$v.id}}.html" class="hot-item">{{$v.key_word}}</a>
                 </li>
+                {{end}}
               </ul>
             </div>
           </section>
@@ -137,27 +131,6 @@
               </ul>
             </div>
           </section>
-          <!-- 招投标攻略 -->
-          <section class="aside-card aside-bid-strategy">
-            <div class="card-header">
-              <h3>招投标攻略</h3>
-              <a href="#">更多</a>
-            </div>
-            <div class="card-main">
-              {{$dbfx:=GetStrategyOneList "ztbgl" "zbjq" 6}}
-              <ul class="card-list">
-                {{range $v :=$dbfx}}
-                <li class="card-list-item">
-                  <a href="{{$v.url}}" class="ellipsis item-title">• {{$v.title}}</a>
-                  <p class="item-desc">
-                    <span class="desc-text">{{$v.desc}}</span>
-                    <span class="desc-time">{{$v.publish_stamp| date "Y.m.d"}}</span>
-                  </p>
-                </li>
-                {{end}}
-              </ul>
-            </div>
-          </section>
         </aside>
       </section>
     </main>

+ 21 - 0
utility/cache.go

@@ -0,0 +1,21 @@
+package utility
+
+import (
+	"context"
+	"github.com/gogf/gf/v2/frame/g"
+)
+
+func QueryCacheArrMap(ctx context.Context, query func() []map[string]interface{}, key string) []map[string]interface{} {
+	cacheValue, err := g.Redis().Get(ctx, key)
+	if err == nil && !cacheValue.IsNil() {
+		return cacheValue.Maps()
+	}
+	res := query()
+	if res == nil || len(res) == 0 {
+		res = []map[string]interface{}{}
+	}
+	if len(res) > 0 {
+		_ = g.Redis().SetEX(ctx, key, res, g.Cfg().MustGet(ctx, "cacheSeconds", 60*5).Int64())
+	}
+	return res
+}