zhijiezhao 3 gadi atpakaļ
vecāks
revīzija
93cd44e913

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

@@ -99,4 +99,6 @@ public interface ArticleDao {
     void articlePv(Integer infoId);
 
     String getLabelById(Integer id);
+
+    List<Article> getArticleRelatedLimit(@Param("id")Integer id, @Param("labels")String[] strings);
 }

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

@@ -184,7 +184,7 @@ public class ArticleServiceImpl implements ArticleService {
         if(!org.jsoup.helper.StringUtil.isBlank(labels)){
             strings = labels.split(",");
         }
-        List<Article> relateds = articleDao.getArticleRelated(id, strings);
+        List<Article> relateds = articleDao.getArticleRelatedLimit(id, strings);
         relateds.forEach(item -> {
             item.setImage(ImageUtil.getImageURL("", item.getImage(), 0, domain));
         });

+ 30 - 1
src/main/resources/mapper/ArticleMapper.xml

@@ -65,7 +65,6 @@
         	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
@@ -141,5 +140,35 @@
 	<select id="getLabelById" resultType="java.lang.String">
 		SELECT label FROM info WHERE id=#{id}
 	</select>
+	<select id="getArticleRelatedLimit" resultType="com.caimei.www.pojo.page.Article">
+		select
+		a.id as id,
+		a.title as title,
+		a.guidanceImage as image,
+		a.publisher as publisher,
+		a.pubdate as publishDate,
+		a.recommendContent as intro,
+		a.infoContent as content,
+		(IFNULL(c.pv, 0) + IFNULL(a.basePv, 0) + IFNULL((c.num + a.basePraise), 0)) as pv,
+		a.label as label,
+		a.typeId as typeId
+		from info as a
+		left join info_praise c on a.id = c.infoId
+		<where>
+			<if test="labels != null and labels != ''">
+				<foreach collection="labels" item="label" open="(" close=")" index="index" separator="OR">
+					a.label like CONCAT(CONCAT('%', #{label}), '%')
+				</foreach>
+			</if>
+			<if test="id != null and id != ''">
+				and a.id != #{id}
+			</if>
+			and NOW() >= a.pubdate
+			and a.enabledStatus = 1
+			and a.auditStatus = 2
+		</where>
+		order by a.pubdate desc
+		limit 3
+	</select>
 
 </mapper>