Browse Source

采美百科

Aslee 2 years ago
parent
commit
5fd41095fa

+ 10 - 8
src/main/java/com/caimei/modules/baike/service/CmBaikeProductService.java

@@ -373,14 +373,16 @@ public class CmBaikeProductService extends CrudService<CmBaikeProductDao, CmBaik
 	public void saveRecommend(CmBaikeProduct cmBaikeProduct) {
 		cmBaikeProductDao.updateRecommendType(cmBaikeProduct.getId(), cmBaikeProduct.getRecommendType());
 		// 清除原来的推荐数据
-		cmBaikeProductRecommendDao.clearRecommendData(cmBaikeProduct.getId());
-		List<CmBaikeProductRecommend> recommendList = new ArrayList<>();
-		if (1 == cmBaikeProduct.getRecommendType() && StringUtils.isNotEmpty(cmBaikeProduct.getRecommendJson())) {
-			recommendList = JSONObject.parseArray(cmBaikeProduct.getRecommendJson(), CmBaikeProductRecommend.class);
-			recommendList.forEach(recommond->{
-				recommond.setProductId(Integer.parseInt(cmBaikeProduct.getId()));
-				cmBaikeProductRecommendDao.insert(recommond);
-			});
+		if (1 == cmBaikeProduct.getRecommendType()) {
+			cmBaikeProductRecommendDao.clearRecommendData(cmBaikeProduct.getId());
+			List<CmBaikeProductRecommend> recommendList;
+			if (StringUtils.isNotEmpty(cmBaikeProduct.getRecommendJson())) {
+				recommendList = JSONObject.parseArray(cmBaikeProduct.getRecommendJson(), CmBaikeProductRecommend.class);
+				recommendList.forEach(recommond->{
+					recommond.setProductId(Integer.parseInt(cmBaikeProduct.getId()));
+					cmBaikeProductRecommendDao.insert(recommond);
+				});
+			}
 		}
 	}
 }

+ 5 - 7
src/main/java/com/caimei/modules/baike/web/CmBaikeProductController.java

@@ -348,17 +348,14 @@ public class CmBaikeProductController extends BaseController {
 	 */
 	@RequestMapping(value = "recommend/form")
 	public String recommendForm(CmBaikeProduct cmBaikeProduct, Model model) {
-		List<CmBaikeProductRecommend> manualRecommendList = new ArrayList<>();
-		List<CmBaikeProductRecommend> autoRecommendList;
 		CmBaikeProductRecommend recommend = new CmBaikeProductRecommend();
 		recommend.setProductId(Integer.parseInt(cmBaikeProduct.getId()));
 		recommend.setRecommendType(cmBaikeProduct.getRecommendType());
 		recommend.setProductTypeId(cmBaikeProduct.getTypeId());
-		// 查询推荐列表
-		if (1 == cmBaikeProduct.getRecommendType()) {
-			manualRecommendList = cmBaikeProductRecommendDao.findList(recommend);
-		}
-		autoRecommendList = cmBaikeProductRecommendDao.findAutoRecommendList(recommend);
+		// 手动推荐列表
+        List<CmBaikeProductRecommend> manualRecommendList = cmBaikeProductRecommendDao.findList(recommend);
+        // 自动推荐
+        List<CmBaikeProductRecommend> autoRecommendList = cmBaikeProductRecommendDao.findAutoRecommendList(recommend);
 		// 商品类型
 		String commodityType = cmBaikeProduct.getCommodityType() == 1 ? "产品" : "仪器";
 		model.addAttribute("commodityType", commodityType);
@@ -383,6 +380,7 @@ public class CmBaikeProductController extends BaseController {
 	 */
 	@RequestMapping("/recommend/products")
 	public String findProductPage(CmBaikeProduct cmBaikeProduct, Model model, HttpServletRequest request, HttpServletResponse response) {
+		cmBaikeProduct.setPublishSource(1);
 		Page<CmBaikeProduct> page = cmBaikeProductService.findPage(new Page<CmBaikeProduct>(request, response), cmBaikeProduct);
 		model.addAttribute("page", page);
 		// 商品类型

+ 2 - 1
src/main/resources/mappings/modules/baike/CmBaikeProductRecommendMapper.xml

@@ -28,6 +28,7 @@
 		FROM cm_baike_product_recommend a
 		<include refid="cmBaikeProductRecommendJoins"/>
 		<where>
+		    cbp.delFlag = 0
 			<if test="productId != null">
 				and a.productId = #{productId}
 			</if>
@@ -60,7 +61,7 @@
 	<select id="findAutoRecommendList" resultType="com.caimei.modules.baike.entity.CmBaikeProductRecommend">
 		select id as recommendProductId, name as recommendProductName
 		from cm_baike_product
-		where typeId = #{productTypeId}
+		where typeId = #{productTypeId} and delFlag = 0 and onlineStatus = 2 and status = 1
 		order by addTime desc
 		limit 15
 	</select>

+ 8 - 10
src/main/webapp/WEB-INF/views/modules/baikePage/recommendForm.jsp

@@ -34,7 +34,7 @@
 	<table class="table table-striped table-bordered table-condensed">
 		<p><b>${commodityType}名称:</b>${cmBaikeProduct.name}</p>
 		<p><b>推荐列表</b><font color="red">(当前列表推荐数 <span class="recommendCount"></span>, 最多可推荐15条)</font></p>
-		<input class="btn btn-primary" id="showSelectBtn" style="width: 70px;margin-bottom: 10px"
+		<input class="btn btn-primary manualData" id="showSelectBtn" style="width: 70px;margin-bottom: 10px"
 			   onclick="showSelect()" value="添加"/>
 		<thead>
 		<tr>
@@ -72,15 +72,13 @@
 
 	$(function () {
 		//数据填充
-		if (recommendType == 1) {
-			<c:forEach items="${manualRecommendList}" var="product" varStatus="index">
-				manualImageList.push({
-					recommendProductId: "${product.recommendProductId}",
-					recommendProductName: "${product.recommendProductName}",
-					sort: "${product.sort}"
-				});
-			</c:forEach>
-		}
+		<c:forEach items="${manualRecommendList}" var="product" varStatus="index">
+			manualImageList.push({
+				recommendProductId: "${product.recommendProductId}",
+				recommendProductName: "${product.recommendProductName}",
+				sort: "${product.sort}"
+			});
+		</c:forEach>
 		<c:forEach items="${autoRecommendList}" var="product" varStatus="index">
 			autoImageList.push({
 				recommendProductId: "${product.recommendProductId}",