Kaynağa Gözat

小需求V1.3.14

kaick 1 yıl önce
ebeveyn
işleme
e4237adb56

+ 12 - 2
src/main/java/com/caimei/www/controller/unlimited/EncyclopediaController.java

@@ -4,6 +4,7 @@ import com.caimei.www.controller.BaseController;
 import com.caimei.www.pojo.baike.BaikeHotSearch;
 import com.caimei.www.pojo.baike.BaikeProductVo;
 import com.caimei.www.pojo.baike.BaikeTypeVo;
+import com.caimei.www.pojo.page.Article;
 import com.caimei.www.service.page.ProductService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
@@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 采美百科
@@ -108,10 +110,18 @@ public class EncyclopediaController extends BaseController {
         }
         //热搜词
         List<BaikeHotSearch> hotSeracherWords=productService.getHotWords();
-        model.addAttribute("hotSeracherWords", hotSeracherWords);
-        model.addAttribute("baikeproduct", baikeproduct);
+        //相关词条
+        List<Map> articles = null;
+        if (null != baikeproduct && baikeproduct.getAutoStatus() == 0) {
+            articles = productService.getAutoBaikeRelatedLimit(id,baikeproduct.getLabelIds());
+        } else {
+            articles = productService.getBaikeRelatedLimit(id);
+        }
         //分类集合
         List<BaikeTypeVo> typeList = productService.geTypeList();
+        model.addAttribute("articles", articles);
+        model.addAttribute("hotSeracherWords", hotSeracherWords);
+        model.addAttribute("baikeproduct", baikeproduct);
         model.addAttribute("TypeList", typeList);
         //增加浏览量
         productService.encyclopediaPv(id);

+ 9 - 0
src/main/java/com/caimei/www/mapper/BaikeDao.java

@@ -5,6 +5,7 @@ import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * Description
@@ -48,6 +49,14 @@ public interface BaikeDao {
 
 
     BaikeProductVo getEntryInfoById(Integer id);
+    /**
+     * 功能描述: 自动推荐 相关词条
+     */
+    List<Map> getAutoBaikeRelatedLimit(@Param("id")Integer id,@Param("labelIds") String labelIds);
+    /**
+     * 功能描述: 手动推荐 相关词条
+     */
+    List<Map> getBaikeRelatedLimit(@Param("id")Integer id);
 
     List<BaikeImageVo> getImageListById(Integer id);
 

+ 8 - 0
src/main/java/com/caimei/www/pojo/baike/BaikeProductVo.java

@@ -167,4 +167,12 @@ public class BaikeProductVo implements Serializable {
      * 关联标签库字符串
      */
     private String relatedLabels;
+    /**
+     * 推荐方式 0自动推荐 1手动推荐
+     */
+    private Integer autoStatus;
+    /**
+     * 关联标签库Id
+     */
+    private String labelIds;
 }

+ 9 - 0
src/main/java/com/caimei/www/service/page/ProductService.java

@@ -7,6 +7,7 @@ import com.caimei.www.pojo.baike.*;
 import com.caimei.www.pojo.page.Parameter;
 import com.caimei.www.pojo.page.ProductDetail;
 import com.caimei.www.pojo.page.ProductList;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 import java.util.Map;
@@ -117,6 +118,14 @@ public interface ProductService {
 
 
     BaikeProductVo getEncyclopediaDetail(Integer id);
+    /**
+     * 功能描述: 自动推荐 相关词条
+     */
+    List<Map> getAutoBaikeRelatedLimit(Integer id,String labelIds);
+    /**
+     * 功能描述: 手动推荐 相关词条
+     */
+    List<Map> getBaikeRelatedLimit(Integer id);
 
     List<BaikeTypeVo> geTypeList();
 

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

@@ -20,6 +20,7 @@ import com.caimei.www.utils.PriceUtil;
 import com.caimei.www.utils.RequestUtil;
 import io.netty.util.internal.StringUtil;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.ibatis.annotations.Param;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
@@ -494,4 +495,18 @@ public class ProductServiceImpl implements ProductService {
         }
         return entryInfo;
     }
+    /**
+     * 功能描述: 自动推荐 相关词条
+     */
+    @Override
+    public List<Map> getAutoBaikeRelatedLimit(Integer id,  String labelIds){
+        return baikeDao.getAutoBaikeRelatedLimit(id,labelIds);
+    }
+    /**
+     * 功能描述: 手动推荐 相关词条
+     */
+    @Override
+    public List<Map> getBaikeRelatedLimit(Integer id){
+        return baikeDao.getBaikeRelatedLimit(id);
+    }
 }

+ 39 - 0
src/main/resources/mapper/BaikeMapper.xml

@@ -167,6 +167,7 @@
 			p.shopId,
 			p.basePv,
 			p.seoKeyword,
+			p.labelIds,
 			p.relatedLabels
 		from cm_baike_product p
 				 left join cm_baike_type t on p.typeId=t.id
@@ -174,6 +175,44 @@
 		where p.id=#{id}
 	</select>
 
+	<select id="getAutoBaikeRelatedLimit" resultType="map">
+		select
+		p.name,
+		p.image
+		from cm_baike_product as p
+		<where>
+			<if test="labelIds != null and labelIds != ''">
+				<foreach collection="labelIds.split(',')" item="labelId" open="(" close=")" index="index" separator="OR">
+					p.labelIds like CONCAT(CONCAT('%', #{labelId}), '%')
+				</foreach>
+			</if>
+			<if test="id != null and id != ''">
+				and p.id != #{id}
+			</if>
+			and NOW() >= p.publishTime
+			and p.status = 1
+			and p.auditStatus = 2
+		</where>
+		order by p.publishTime desc
+		limit 3
+	</select>
+
+	<select id="getBaikeRelatedLimit" resultType="map">
+		select
+		p.name,
+		p.image
+		from cm_related cr
+		left join cm_baike_product p on p.id=cr.relatedId
+		where cr.type=3
+		and cr.delFlag=0
+		and p.status = 1
+		and p.auditStatus = 2
+		and cr.authorId = #{id}
+		and NOW() >= p.publishTime
+		order by cr.sort asc, p.publishTime desc
+		limit 3
+	</select>
+
 	<select id="getImageListById"  resultType="com.caimei.www.pojo.baike.BaikeImageVo">
 		select  id,productId as entryId,image from cm_baike_product_image
 		where productId=#{id}