Quellcode durchsuchen

热搜词,推荐阅读,广告位,相关阅读静态化

zhijiezhao vor 3 Jahren
Ursprung
Commit
aba01caf37

+ 12 - 0
src/main/java/com/caimei/www/controller/unlimited/ArticleController.java

@@ -40,6 +40,8 @@ public class ArticleController extends BaseController {
     public String toArticleList(@PathVariable("id") Integer id, @PathVariable("pageNum") Integer pageNum, final Model model) {
         List<BaseLink> typeList = articleService.getArticleTypes();
         List<BaseLink> data = articleService.getArticleLabels().getData();
+        List<ImageLink> Ads = articleService.getLastestInfoAds().getData();
+        model.addAttribute("ads", Ads);
         model.addAttribute("labels",data);
         model.addAttribute("articleType", typeList);
         model.addAttribute("typeId", id);
@@ -56,6 +58,8 @@ public class ArticleController extends BaseController {
     public String toArticleLabel(@PathVariable("id") Integer id, @PathVariable("pageNum") Integer pageNum, final Model model) {
         List<BaseLink> typeList = articleService.getArticleTypes();
         List<BaseLink> data = articleService.getArticleLabels().getData();
+        List<ImageLink> Ads = articleService.getLastestInfoAds().getData();
+        model.addAttribute("ads", Ads);
         model.addAttribute("labels",data);
         model.addAttribute("articleType", typeList);
         model.addAttribute("typeId", 0);
@@ -72,6 +76,8 @@ public class ArticleController extends BaseController {
     public String toArticleSearch(@PathVariable("pageNum") Integer pageNum, final Model model) {
         List<BaseLink> typeList = articleService.getArticleTypes();
         List<BaseLink> data = articleService.getArticleLabels().getData();
+        List<ImageLink> Ads = articleService.getLastestInfoAds().getData();
+        model.addAttribute("ads", Ads);
         model.addAttribute("labels",data);
         model.addAttribute("articleType", typeList);
         model.addAttribute("typeId", 0);
@@ -91,6 +97,12 @@ public class ArticleController extends BaseController {
         if(article == null){
             return super.errorPath();
         }
+        List<BaseLink> data = articleService.getArticleLabels().getData();
+        List<ImageLink> Ads = articleService.getLastestInfoAds().getData();
+        List<Article> articles=articleService.getInfoById(id);
+        model.addAttribute("articles",articles);
+        model.addAttribute("ads", Ads);
+        model.addAttribute("labels",data);
         model.addAttribute("article", article);
         model.addAttribute("articleType", typeList);
         model.addAttribute("articleId", id);

+ 2 - 0
src/main/java/com/caimei/www/mapper/ArticleDao.java

@@ -97,4 +97,6 @@ public interface ArticleDao {
      * @param infoId
      */
     void articlePv(Integer infoId);
+
+    String getLabelById(Integer id);
 }

+ 2 - 0
src/main/java/com/caimei/www/service/page/ArticleService.java

@@ -72,4 +72,6 @@ public interface ArticleService {
      * @return
      */
     JsonModel articlePv(Integer id);
+
+    List<Article> getInfoById(Integer id);
 }

+ 15 - 0
src/main/java/com/caimei/www/service/page/impl/ArticleServiceImpl.java

@@ -16,6 +16,7 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.server.reactive.ServerHttpRequest;
 import org.springframework.stereotype.Service;
 import org.springframework.web.server.ServerWebExchange;
+import org.thymeleaf.util.StringUtils;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
@@ -176,6 +177,20 @@ public class ArticleServiceImpl implements ArticleService {
         return JsonModel.success();
     }
 
+    @Override
+    public List<Article> getInfoById(Integer id) {
+        String labels=articleDao.getLabelById(id);
+        String[] strings = new String[0];
+        if(!org.jsoup.helper.StringUtil.isBlank(labels)){
+            strings = labels.split(",");
+        }
+        List<Article> relateds = articleDao.getArticleRelated(id, strings);
+        relateds.forEach(item -> {
+            item.setImage(ImageUtil.getImageURL("", item.getImage(), 0, domain));
+        });
+        return relateds;
+    }
+
     private String getIp(ServerWebExchange serverWebExchange){
        ServerHttpRequest request = serverWebExchange.getRequest();
         return Objects.requireNonNull(request.getRemoteAddress()).getAddress().toString();

+ 3 - 3
src/main/resources/config/dev/application-dev.yml

@@ -11,7 +11,7 @@ spring:
     url: jdbc:mysql://120.79.25.27:3306/caimei?characterEncoding=UTF8&serverTimezone=Asia/Shanghai
     username: developer
     password: J5p3tgOVazNl4ydf
-    #type: com.zaxxer.hikari.HikariDataSource
+    type: com.zaxxer.hikari.HikariDataSource
     hikari:
       minimum-idle: 5
       maximum-pool-size: 15
@@ -54,8 +54,8 @@ logging:
 caimei:
   siteEnv: 0 #网站环境,(2:正式环境,1:测试环境,0:开发环境)
   #spiServer: http://192.168.2.68:8008
-  coreServer: https://core-b.caimei365.com
-#  coreServer: http://192.168.2.67:18002
+#  coreServer: https://core-b.caimei365.com
+  coreServer: http://192.168.2.67:18002
 #  coreServer: http://192.168.2.75:18002
   imageDomain: https://img-b.caimei365.com
   wwwDomain: http://localhost:8009

+ 4 - 0
src/main/resources/mapper/ArticleMapper.xml

@@ -65,6 +65,7 @@
         	and a.auditStatus = 2
 		</where>
 		order by a.pubdate desc
+		limit 3
 	</select>
 	<select id="getLastestInfoADs" resultType="com.caimei.www.pojo.page.ImageLink">
 		select a.id, a.serviceObject as title, a.guidanceImage as image, a.link
@@ -137,5 +138,8 @@
 		group by name
 		order by clickRate desc
 	</select>
+	<select id="getLabelById" resultType="java.lang.String">
+		SELECT label FROM info WHERE id=#{id}
+	</select>
 
 </mapper>

+ 25 - 24
src/main/resources/static/js/article/common.js

@@ -10,20 +10,20 @@ var articleSide = new Vue({
         adList: [],
     },
     methods: {
-        getLabels: function(){
-            var _self = this;
-            $.getJSON("/article/labels", function (r) {
-                if (r.code === 0 && r.data) {
-                    _self.labelList = r.data;
-                    _self.labelList.map(function(item){
-                        if (_self.labelId === item.id) {
-                            _self.labelTxt = item.name;
-                            $("#labelTxt").text(_self.labelTxt);
-                        }
-                    })
-                }
-            });
-        },
+        // getLabels: function(){
+        //     var _self = this;
+        //     $.getJSON("/article/labels", function (r) {
+        //         if (r.code === 0 && r.data) {
+        //             _self.labelList = r.data;
+        //             _self.labelList.map(function(item){
+        //                 if (_self.labelId === item.id) {
+        //                     _self.labelTxt = item.name;
+        //                     $("#labelTxt").text(_self.labelTxt);
+        //                 }
+        //             })
+        //         }
+        //     });
+        // },
         getRecommend: function(typeId, pageNum){
             var _self = this;
             $.getJSON("/article/recommend",{
@@ -35,15 +35,16 @@ var articleSide = new Vue({
                 }
             });
         },
-        getAds: function(){
-            var _self = this;
-            $.getJSON("/article/ads", function (r) {
-                if (r.code === 0 && r.data) {
-                    _self.adList = r.data;
-                }
-            });
-        },
+        // getAds: function(){
+        //     var _self = this;
+        //     $.getJSON("/article/ads", function (r) {
+        //         if (r.code === 0 && r.data) {
+        //             _self.adList = r.data;
+        //         }
+        //     });
+        // },
         clickAD: function(id, link){
+            debugger;
             $.getJSON("/article/ad/click", {id: id}, function (r) {
                 window.open(link);
             });
@@ -53,9 +54,9 @@ var articleSide = new Vue({
         var _self = this;
         this.typeId = $("#typeId").val()*1;
         this.labelId = $("#labelId").val()*1;
-        this.getLabels();
+        // this.getLabels();
         if (isPC) {
-            this.getAds();
+            // this.getAds();
             this.getRecommend(this.typeId, 1);
             //换一批15秒请求一次
             setInterval(function(){

+ 13 - 13
src/main/resources/static/js/article/detail.js

@@ -25,25 +25,25 @@ var articleRelated = new Vue({
         related: {}
     },
     methods: {
-        getRelatedList: function () {
-            var _self = this;
-            if(this.infoId ===0){return;}
-            $.getJSON("/article/related",{
-                id: this.infoId,
-                labels: this.articleLabels
-            }).done(function (r) {
-                if (r.code === 0 && r.data) {
-                    _self.related = r.data;
-                }
-            });
-        },
+        // getRelatedList: function () {
+        //     var _self = this;
+        //     if(this.infoId ===0){return;}
+        //     $.getJSON("/article/related",{
+        //         id: this.infoId,
+        //         labels: this.articleLabels
+        //     }).done(function (r) {
+        //         if (r.code === 0 && r.data) {
+        //             _self.related = r.data;
+        //         }
+        //     });
+        // },
 
     },
     created: function () {
         this.infoId = $("#articleId").val() ? $("#articleId").val()*1 : 0;
         this.articleLabels = $("#articleLabels").val()?$("#articleLabels").val():"";
         // 获取相关阅读
-        this.getRelatedList();
+        // this.getRelatedList();
     },
     mounted: function () {
         var _self = this;

+ 6 - 4
src/main/resources/templates/article/components/article-sidebar.html

@@ -6,9 +6,8 @@
                 热搜词
             </p>
             <div class="tag">
-                <th:block th:each="label : ${labels}"  th:object="${label}">
 <!--                    <a v-for="label in labelList"  :href="'/info/label-' + label.id + '-1.html'" :style="'opacity:'+label.sort" v-text="label.name"></a>-->
-                </th:block>
+                <a th:each="label : ${labels}" th:href="'/info/label-' + ${label.id} + '-1.html'" th:text="${label.name}"></a>
             </div>
         </div>
         <a href="javascript:void(0);" class="close"></a>
@@ -35,8 +34,11 @@
         </div>
     </div>
     <div v-if="isPC" class="tui">
-        <a v-for="ad in adList" href="javascript:void(0);" class="tui-img" @click="clickAD(ad.id,ad.link)">
-            <img :src="ad.image" alt="ad.title"/>
+<!--        <a v-for="ad in adList" href="javascript:void(0);" class="tui-img" @click="clickAD(ad.id,ad.link)">-->
+<!--            <img :src="ad.image" alt="ad.title"/>-->
+<!--        </a>-->
+        <a th:each="ad : ${ads}" class="tui-img" th:href="${ad.link}" @click="clickAD(ad.id,ad.link)">
+            <img th:src="${ad.image}" th:alt="${ad.title}"></img>
         </a>
     </div>
 </div>

+ 10 - 10
src/main/resources/templates/article/detail.html

@@ -51,23 +51,23 @@
         <!--相关阅读-->
         <div class="new-list dataRousce" id="articleRelated">
             <p class="classify biaoqian">相关阅读</p>
-            <div class="row" v-for="item in related.list">
+            <div class="row" th:each="item : ${articles}">
                 <div class="new-img">
-                    <a :href="'/info/detail-'+item.id+'-1.html'" target="_blank">
-                        <img :src="item.image"/>
+                    <a th:href="'/info/detail-'+${item.id}+'-1.html'" target="_blank">
+                        <img th:src="${item.image}"/>
                     </a>
                 </div>
                 <div class="new-blurb">
-                    <a :href="'/info/detail-'+item.id+'-1.html'" target="_blank">
-                        <p class="title" v-html="item.title"></p>
+                    <a th:href="'/info/detail-'+${item.id}+'-1.html'" target="_blank">
+                        <p class="title" th:utext="${item.title}"></p>
                     </a>
                     <p class="xinxi">
-                        <em v-if="!isPC" class="pv icon mIcon" v-text="item.pv"></em>
-                        <em class="write icon mIcon" v-text="item.publisher"></em>
-                        <em  v-if="item.publishDate" class="time icon mIcon" v-text="item.publishDate.substr(0,10)"></em>
+                        <em v-if="!isPC" class="pv icon mIcon" th:utext="${item.pv}"></em>
+                        <em class="write icon mIcon" th:text="${item.publisher}"></em>
+                        <em th:if="${item.publishDate}" class="time icon mIcon" th:text="${item.publishDate}"></em>
                     </p>
-                    <p class="introduction" v-html="item.intro"></p>
-                    <p v-if="isPC" class="P_img"><em class="pv icon mIcon" v-text="item.pv"></em></p>
+                    <p class="introduction" th:utext="${item.intro}"></p>
+                    <p v-if="isPC" class="P_img"><em class="pv icon mIcon" th:text="${item.pv}"></em></p>
                 </div>
             </div>
             <div id="scrollTop">