Ver Fonte

百科-相关推荐

Aslee há 3 anos atrás
pai
commit
e801a0ac21

+ 3 - 0
src/main/java/com/caimei/modules/baike/dao/CmBaikeProductDao.java

@@ -70,4 +70,7 @@ public interface CmBaikeProductDao extends CrudDao<CmBaikeProduct> {
     void updateProductFile(@Param("fileId") Integer fileId, @Param("productId") Integer productId);
 
     List<CmBaikeProductFile> findFileList(String id);
+
+    void updateRecommendType(@Param("productId") String productId, @Param("recommendType") Integer recommendType);
+
 }

+ 20 - 0
src/main/java/com/caimei/modules/baike/dao/CmBaikeProductRecommendDao.java

@@ -0,0 +1,20 @@
+package com.caimei.modules.baike.dao;
+
+import com.thinkgem.jeesite.common.persistence.CrudDao;
+import com.thinkgem.jeesite.common.persistence.annotation.MyBatisDao;
+import com.caimei.modules.baike.entity.CmBaikeProductRecommend;
+
+import java.util.List;
+
+/**
+ * 采美百科相关推荐DAO接口
+ * @author Aslee
+ * @version 2022-06-07
+ */
+@MyBatisDao
+public interface CmBaikeProductRecommendDao extends CrudDao<CmBaikeProductRecommend> {
+
+    List<CmBaikeProductRecommend> findAutoRecommendList(CmBaikeProductRecommend recommend);
+
+    void clearRecommendData(String productId);
+}

+ 27 - 0
src/main/java/com/caimei/modules/baike/entity/CmBaikeProduct.java

@@ -48,6 +48,7 @@ public class CmBaikeProduct extends DataEntity<CmBaikeProduct> {
 	private Integer auditStatus;	//百科审核状态:1待审核,2审核通过,3审核失败
 	private Integer onlineStatus;	//百科上线状态:1待上线,2已上线,3已下线
 	private String failReason;	//审核失败理由
+	private Integer recommendType;	//推荐类型:1手动推荐,2自动推荐
 	private Integer emptyNum;	//空数据条数
 	private Date addTime;		// 添加时间
 
@@ -69,6 +70,8 @@ public class CmBaikeProduct extends DataEntity<CmBaikeProduct> {
 	private Integer nmpaDay;		// nmpa日
 	private Integer auditFlag;		// 是否审核保存,1是
 	private String fileIds;			// 文件id,以,隔开
+	private String productIds;		// 产品/仪器id,以,隔开
+	private String recommendJson;	// 相关推荐产品/仪器json数据
 
 	public CmBaikeProduct() {
 		super();
@@ -479,4 +482,28 @@ public class CmBaikeProduct extends DataEntity<CmBaikeProduct> {
 	public void setVideoList(List<CmBaikeProductFile> videoList) {
 		this.videoList = videoList;
 	}
+
+	public Integer getRecommendType() {
+		return recommendType;
+	}
+
+	public void setRecommendType(Integer recommendType) {
+		this.recommendType = recommendType;
+	}
+
+	public String getProductIds() {
+		return productIds;
+	}
+
+	public void setProductIds(String productIds) {
+		this.productIds = productIds;
+	}
+
+	public String getRecommendJson() {
+		return recommendJson;
+	}
+
+	public void setRecommendJson(String recommendJson) {
+		this.recommendJson = recommendJson;
+	}
 }

+ 77 - 0
src/main/java/com/caimei/modules/baike/entity/CmBaikeProductRecommend.java

@@ -0,0 +1,77 @@
+package com.caimei.modules.baike.entity;
+
+
+import com.thinkgem.jeesite.common.persistence.DataEntity;
+
+/**
+ * 采美百科相关推荐Entity
+ * @author Aslee
+ * @version 2022-06-07
+ */
+public class CmBaikeProductRecommend extends DataEntity<CmBaikeProductRecommend> {
+	
+	private static final long serialVersionUID = 1L;
+	private Integer productId;		// 百科产品/仪器id
+	private Integer recommendProductId;		// 相关推荐产品/仪器id
+	private Integer sort;		// 排序值
+
+	private String recommendProductName;		// 相关推荐产品/仪器名称
+	private Integer recommendType;	//推荐类型:1手动推荐,2自动推荐
+	private Integer productTypeId;	//产品/仪器分类id
+	
+	public CmBaikeProductRecommend() {
+		super();
+	}
+
+	public CmBaikeProductRecommend(String id){
+		super(id);
+	}
+
+	public Integer getProductId() {
+		return productId;
+	}
+
+	public void setProductId(Integer productId) {
+		this.productId = productId;
+	}
+	
+	public Integer getRecommendProductId() {
+		return recommendProductId;
+	}
+
+	public void setRecommendProductId(Integer recommendProductId) {
+		this.recommendProductId = recommendProductId;
+	}
+	
+	public Integer getSort() {
+		return sort;
+	}
+
+	public void setSort(Integer sort) {
+		this.sort = sort;
+	}
+
+	public Integer getRecommendType() {
+		return recommendType;
+	}
+
+	public void setRecommendType(Integer recommendType) {
+		this.recommendType = recommendType;
+	}
+
+	public Integer getProductTypeId() {
+		return productTypeId;
+	}
+
+	public void setProductTypeId(Integer productTypeId) {
+		this.productTypeId = productTypeId;
+	}
+
+	public String getRecommendProductName() {
+		return recommendProductName;
+	}
+
+	public void setRecommendProductName(String recommendProductName) {
+		this.recommendProductName = recommendProductName;
+	}
+}

+ 44 - 0
src/main/java/com/caimei/modules/baike/service/CmBaikeProductRecommendService.java

@@ -0,0 +1,44 @@
+package com.caimei.modules.baike.service;
+
+import java.util.List;
+
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import com.thinkgem.jeesite.common.persistence.Page;
+import com.thinkgem.jeesite.common.service.CrudService;
+import com.caimei.modules.baike.entity.CmBaikeProductRecommend;
+import com.caimei.modules.baike.dao.CmBaikeProductRecommendDao;
+
+/**
+ * 采美百科相关推荐Service
+ * @author Aslee
+ * @version 2022-06-07
+ */
+@Service
+@Transactional(readOnly = true)
+public class CmBaikeProductRecommendService extends CrudService<CmBaikeProductRecommendDao, CmBaikeProductRecommend> {
+
+	public CmBaikeProductRecommend get(String id) {
+		return super.get(id);
+	}
+	
+	public List<CmBaikeProductRecommend> findList(CmBaikeProductRecommend cmBaikeProductRecommend) {
+		return super.findList(cmBaikeProductRecommend);
+	}
+	
+	public Page<CmBaikeProductRecommend> findPage(Page<CmBaikeProductRecommend> page, CmBaikeProductRecommend cmBaikeProductRecommend) {
+		return super.findPage(page, cmBaikeProductRecommend);
+	}
+	
+	@Transactional(readOnly = false)
+	public void save(CmBaikeProductRecommend cmBaikeProductRecommend) {
+		super.save(cmBaikeProductRecommend);
+	}
+	
+	@Transactional(readOnly = false)
+	public void delete(CmBaikeProductRecommend cmBaikeProductRecommend) {
+		super.delete(cmBaikeProductRecommend);
+	}
+	
+}

+ 22 - 4
src/main/java/com/caimei/modules/baike/service/CmBaikeProductService.java

@@ -3,11 +3,11 @@ package com.caimei.modules.baike.service;
 import java.io.File;
 import java.util.*;
 
+import com.alibaba.fastjson.JSONObject;
 import com.caimei.modules.archive.entity.CmOrderArchiveFile;
 import com.caimei.modules.archive.utils.OssArchiveUtil;
-import com.caimei.modules.baike.entity.CmBaikeProductFile;
-import com.caimei.modules.baike.entity.CmBaikeProductParam;
-import com.caimei.modules.baike.entity.CmBaikeProductQuestion;
+import com.caimei.modules.baike.dao.CmBaikeProductRecommendDao;
+import com.caimei.modules.baike.entity.*;
 import com.caimei.modules.info.entity.Info;
 import com.caimei.modules.miniprogram.utils.UploadPicUtils;
 import com.caimei.modules.oss.utils.OSSUtils;
@@ -18,7 +18,6 @@ import org.springframework.transaction.annotation.Transactional;
 
 import com.thinkgem.jeesite.common.persistence.Page;
 import com.thinkgem.jeesite.common.service.CrudService;
-import com.caimei.modules.baike.entity.CmBaikeProduct;
 import com.caimei.modules.baike.dao.CmBaikeProductDao;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -35,6 +34,9 @@ public class CmBaikeProductService extends CrudService<CmBaikeProductDao, CmBaik
 	@Resource
 	private CmBaikeProductDao cmBaikeProductDao;
 
+	@Resource
+	private CmBaikeProductRecommendDao cmBaikeProductRecommendDao;
+
 	public CmBaikeProduct get(String id) {
 		CmBaikeProduct cmBaikeProduct = super.get(id);
 		String marketTime = cmBaikeProduct.getMarketTime();
@@ -366,4 +368,20 @@ public class CmBaikeProductService extends CrudService<CmBaikeProductDao, CmBaik
 			cmBaikeProductDao.deleteProductFile(fileId);
 		}
 	}
+
+
+    @Transactional(readOnly = false)
+	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);
+			});
+		}
+	}
 }

+ 85 - 2
src/main/java/com/caimei/modules/baike/web/CmBaikeProductController.java

@@ -5,13 +5,19 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import com.caimei.modules.baike.dao.CmBaikeProductDao;
+import com.caimei.modules.baike.dao.CmBaikeProductRecommendDao;
+import com.caimei.modules.baike.dao.CmBaikeTypeDao;
 import com.caimei.modules.baike.entity.*;
 import com.caimei.modules.baike.service.CmBaikeTypeService;
 import com.caimei.modules.info.dao.InfoDao;
 import com.caimei.modules.opensearch.GenerateUtils;
 import com.caimei.modules.oss.utils.OSSUtils;
+import com.caimei.modules.product.entity.CmProductRecommend;
+import com.caimei.modules.product.entity.Product;
 import com.caimei.modules.user.entity.NewCmShop;
+import com.caimei.utils.AppUtils;
 import com.google.common.collect.Maps;
+import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
@@ -52,10 +58,13 @@ public class CmBaikeProductController extends BaseController {
     private CmBaikeProductDao cmBaikeProductDao;
 
 	@Resource
-	private InfoDao infoDao;
+	private CmBaikeProductRecommendDao cmBaikeProductRecommendDao;
+
+	@Resource
+	private CmBaikeTypeDao cmBaikeTypeDao;
 
 	@Resource
-	private GenerateUtils generateUtils;
+	private InfoDao infoDao;
 	
 	@ModelAttribute
 	public CmBaikeProduct get(@RequestParam(required=false) String id) {
@@ -111,10 +120,13 @@ public class CmBaikeProductController extends BaseController {
 		cmBaikeProduct.setQuestionList(questionList);
 		// 视频列表
 		List<CmBaikeProductFile> videoList = cmBaikeProductDao.findFileList(cmBaikeProduct.getId());
+		StringBuilder fileIds = new StringBuilder();
 		videoList.forEach(video->{
 			OSSUtils.getOssUrl(video.getOssName());
+			fileIds.append(video.getId()).append(",");
 		});
 		cmBaikeProduct.setVideoList(videoList);
+		cmBaikeProduct.setFileIds(fileIds.toString());
 		// 供应商列表
 		List<NewCmShop> shopList = cmBaikeProductDao.findShopList();
 		cmBaikeProduct.setShopList(shopList);
@@ -234,6 +246,12 @@ public class CmBaikeProductController extends BaseController {
 		// 问题列表
 		List<CmBaikeProductQuestion> questionList = cmBaikeProductDao.findQuestionList(cmBaikeProduct.getId());
 		cmBaikeProduct.setQuestionList(questionList);
+		// 视频列表
+		List<CmBaikeProductFile> videoList = cmBaikeProductDao.findFileList(cmBaikeProduct.getId());
+		videoList.forEach(video->{
+			OSSUtils.getOssUrl(video.getOssName());
+		});
+		cmBaikeProduct.setVideoList(videoList);
 		model.addAttribute("commodityType", commodityType);
 		return "modules/baikePage/checkBaikePage";
 	}
@@ -273,6 +291,15 @@ public class CmBaikeProductController extends BaseController {
         // 问题列表
         List<CmBaikeProductQuestion> questionList = cmBaikeProductDao.findQuestionList(cmBaikeProduct.getId());
         cmBaikeProduct.setQuestionList(questionList);
+		// 视频列表
+		List<CmBaikeProductFile> videoList = cmBaikeProductDao.findFileList(cmBaikeProduct.getId());
+		StringBuilder fileIds = new StringBuilder();
+		videoList.forEach(video->{
+			OSSUtils.getOssUrl(video.getOssName());
+			fileIds.append(video.getId()).append(",");
+		});
+		cmBaikeProduct.setVideoList(videoList);
+		cmBaikeProduct.setFileIds(fileIds.toString());
         model.addAttribute("commodityType", commodityType);
 		CmBaikeType cmBaikeType = new CmBaikeType();
 		cmBaikeType.setTypeSort(cmBaikeProduct.getCommodityType());
@@ -313,4 +340,60 @@ public class CmBaikeProductController extends BaseController {
     public void deleteFile(Integer fileId) {
         cmBaikeProductService.deleteFile(fileId);
     }
+
+	/**
+	 * 相关商品推荐
+	 *
+	 * @return
+	 */
+	@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);
+		// 商品类型
+		String commodityType = cmBaikeProduct.getCommodityType() == 1 ? "产品" : "仪器";
+		model.addAttribute("commodityType", commodityType);
+		model.addAttribute("manualRecommendList", manualRecommendList);
+		model.addAttribute("autoRecommendList", autoRecommendList);
+		return "modules/baikePage/recommendForm";
+	}
+
+	/**
+	 * 保存相关推荐
+	 *
+	 * @return
+	 */
+	@RequestMapping(value = "recommend/save")
+	public String recommendSave(CmBaikeProduct cmBaikeProduct, Model model) {
+		cmBaikeProductService.saveRecommend(cmBaikeProduct);
+		return "redirect:" + Global.getAdminPath() + "/baike/cmBaikeProduct/?repage&commodityType=" + cmBaikeProduct.getCommodityType() + "&publishSource=1";
+	}
+
+	/**
+	 * 添加推荐产品
+	 */
+	@RequestMapping("/recommend/products")
+	public String findProductPage(CmBaikeProduct cmBaikeProduct, Model model, HttpServletRequest request, HttpServletResponse response) {
+		Page<CmBaikeProduct> page = cmBaikeProductService.findPage(new Page<CmBaikeProduct>(request, response), cmBaikeProduct);
+		model.addAttribute("page", page);
+		// 商品类型
+		String commodityType = cmBaikeProduct.getCommodityType() == 1 ? "产品" : "仪器";
+		model.addAttribute("commodityType", commodityType);
+		// 分类列表
+		CmBaikeType cmBaikeType = new CmBaikeType();
+		cmBaikeType.setTypeSort(cmBaikeProduct.getCommodityType());
+		List<CmBaikeType> typeList = cmBaikeTypeDao.findList(cmBaikeType);
+		model.addAttribute("typeList", typeList);
+		return "modules/baikePage/addProductRecommend";
+	}
+
 }

+ 80 - 0
src/main/java/com/caimei/modules/baike/web/CmBaikeProductRecommendController.java

@@ -0,0 +1,80 @@
+package com.caimei.modules.baike.web;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.shiro.authz.annotation.RequiresPermissions;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.ModelAttribute;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.servlet.mvc.support.RedirectAttributes;
+
+import com.thinkgem.jeesite.common.config.Global;
+import com.thinkgem.jeesite.common.persistence.Page;
+import com.thinkgem.jeesite.common.web.BaseController;
+import com.thinkgem.jeesite.common.utils.StringUtils;
+import com.caimei.modules.baike.entity.CmBaikeProductRecommend;
+import com.caimei.modules.baike.service.CmBaikeProductRecommendService;
+
+/**
+ * 采美百科相关推荐Controller
+ * @author Aslee
+ * @version 2022-06-07
+ */
+@Controller
+@RequestMapping(value = "${adminPath}/baike/cmBaikeProductRecommend")
+public class CmBaikeProductRecommendController extends BaseController {
+
+	@Autowired
+	private CmBaikeProductRecommendService cmBaikeProductRecommendService;
+	
+	@ModelAttribute
+	public CmBaikeProductRecommend get(@RequestParam(required=false) String id) {
+		CmBaikeProductRecommend entity = null;
+		if (StringUtils.isNotBlank(id)){
+			entity = cmBaikeProductRecommendService.get(id);
+		}
+		if (entity == null){
+			entity = new CmBaikeProductRecommend();
+		}
+		return entity;
+	}
+	
+	@RequiresPermissions("baike:cmBaikeProductRecommend:view")
+	@RequestMapping(value = {"list", ""})
+	public String list(CmBaikeProductRecommend cmBaikeProductRecommend, HttpServletRequest request, HttpServletResponse response, Model model) {
+		Page<CmBaikeProductRecommend> page = cmBaikeProductRecommendService.findPage(new Page<CmBaikeProductRecommend>(request, response), cmBaikeProductRecommend); 
+		model.addAttribute("page", page);
+		return "modules/baike/cmBaikeProductRecommendList";
+	}
+
+	@RequiresPermissions("baike:cmBaikeProductRecommend:view")
+	@RequestMapping(value = "form")
+	public String form(CmBaikeProductRecommend cmBaikeProductRecommend, Model model) {
+		model.addAttribute("cmBaikeProductRecommend", cmBaikeProductRecommend);
+		return "modules/baike/cmBaikeProductRecommendForm";
+	}
+
+	@RequiresPermissions("baike:cmBaikeProductRecommend:edit")
+	@RequestMapping(value = "save")
+	public String save(CmBaikeProductRecommend cmBaikeProductRecommend, Model model, RedirectAttributes redirectAttributes) {
+		if (!beanValidator(model, cmBaikeProductRecommend)){
+			return form(cmBaikeProductRecommend, model);
+		}
+		cmBaikeProductRecommendService.save(cmBaikeProductRecommend);
+		addMessage(redirectAttributes, "保存相关推荐成功");
+		return "redirect:"+Global.getAdminPath()+"/baike/cmBaikeProductRecommend/?repage";
+	}
+	
+	@RequiresPermissions("baike:cmBaikeProductRecommend:delete")
+	@RequestMapping(value = "delete")
+	public String delete(CmBaikeProductRecommend cmBaikeProductRecommend, RedirectAttributes redirectAttributes) {
+		cmBaikeProductRecommendService.delete(cmBaikeProductRecommend);
+		addMessage(redirectAttributes, "删除相关推荐成功");
+		return "redirect:"+Global.getAdminPath()+"/baike/cmBaikeProductRecommend/?repage";
+	}
+
+}

+ 12 - 0
src/main/resources/mappings/modules/baike/CmBaikeProductMapper.xml

@@ -37,6 +37,7 @@
         a.onlineStatus,
 		a.failReason,
 		a.addTime AS "addTime",
+		a.recommendType,
 		cbt.name as "typeName"
 	</sql>
 	
@@ -103,6 +104,12 @@
             <if test="shopName != null and shopName != ''">
                 AND s.name LIKE concat('%',#{shopName},'%')
             </if>
+			<if test="productIds != null and productIds != ''">
+				and a.id not in
+				<foreach item="productId" collection="productIds.split(',')" open="(" separator="," close=")">
+					#{productId}
+				</foreach>
+			</if>
 		</where>
 		<choose>
 			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
@@ -324,6 +331,11 @@
 		set productId = #{productId}
 		where id = #{fileId}
 	</update>
+	<update id="updateRecommendType">
+		update cm_baike_product
+		set recommendType = #{recommendType}
+		where id = #{productId}
+	</update>
 
 	<delete id="delete">
 		DELETE FROM cm_baike_product

+ 98 - 0
src/main/resources/mappings/modules/baike/CmBaikeProductRecommendMapper.xml

@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.caimei.modules.baike.dao.CmBaikeProductRecommendDao">
+    
+	<sql id="cmBaikeProductRecommendColumns">
+		a.id AS "id",
+		a.productId AS "productId",
+		a.recommendProductId AS "recommendProductId",
+		a.sort AS "sort",
+		cbp.name as recommendProductName
+	</sql>
+	
+	<sql id="cmBaikeProductRecommendJoins">
+		left join cm_baike_product cbp on a.recommendProductId = cbp.id
+	</sql>
+    
+	<select id="get" resultType="CmBaikeProductRecommend">
+		SELECT 
+			<include refid="cmBaikeProductRecommendColumns"/>
+		FROM cm_baike_product_recommend a
+		<include refid="cmBaikeProductRecommendJoins"/>
+		WHERE a.id = #{id}
+	</select>
+	
+	<select id="findList" resultType="CmBaikeProductRecommend">
+		SELECT 
+			<include refid="cmBaikeProductRecommendColumns"/>
+		FROM cm_baike_product_recommend a
+		<include refid="cmBaikeProductRecommendJoins"/>
+		<where>
+			<if test="productId != null">
+				and a.productId = #{productId}
+			</if>
+		</where>
+		<choose>
+			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
+				ORDER BY ${page.orderBy}
+			</when>
+			<otherwise>
+				order by -a.sort desc
+			</otherwise>
+		</choose>
+	</select>
+	
+	<select id="findAllList" resultType="CmBaikeProductRecommend">
+		SELECT 
+			<include refid="cmBaikeProductRecommendColumns"/>
+		FROM cm_baike_product_recommend a
+		<include refid="cmBaikeProductRecommendJoins"/>
+		<where>
+		</where>		
+		<choose>
+			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
+				ORDER BY ${page.orderBy}
+			</when>
+			<otherwise>
+			</otherwise>
+		</choose>
+	</select>
+	<select id="findAutoRecommendList" resultType="com.caimei.modules.baike.entity.CmBaikeProductRecommend">
+		select id as recommendProductId, name as recommendProductName
+		from cm_baike_product
+		where typeId = #{productTypeId}
+		order by addTime desc
+		limit 15
+	</select>
+
+	<insert id="insert" parameterType="CmBaikeProductRecommend"  keyProperty="id" useGeneratedKeys="true">
+		INSERT INTO cm_baike_product_recommend(
+			productId,
+			recommendProductId,
+			sort
+		) VALUES (
+			#{productId},
+			#{recommendProductId},
+			#{sort}
+		)
+	</insert>
+	
+	<update id="update">
+		UPDATE cm_baike_product_recommend SET 	
+			productId = #{productId},
+			recommendProductId = #{recommendProductId},
+			sort = #{sort}
+		WHERE id = #{id}
+	</update>
+	
+	<delete id="delete">
+		DELETE FROM cm_baike_product_recommend
+		WHERE id = #{id}
+	</delete>
+	<delete id="clearRecommendData">
+		delete
+		from cm_baike_product_recommend
+		where productId = #{productId}
+	</delete>
+
+</mapper>

+ 134 - 0
src/main/webapp/WEB-INF/views/modules/baikePage/addProductRecommend.jsp

@@ -0,0 +1,134 @@
+<%--
+  Created by IntelliJ IDEA.
+  User: Administrator
+  Date: 2020/4/9
+  Time: 19:54
+  To change this template use File | Settings | File Templates.
+--%>
+<%@ page contentType="text/html;charset=UTF-8" %>
+<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
+<html>
+<head>
+    <title>选择商品图片</title>
+    <meta name="decorator" content="default"/>
+    <style type="text/css">
+        .table td i {
+            margin: 0 2px;
+        }
+    </style>
+
+    <script type="text/javascript">
+        $(document).ready(function () {
+            $("#searchForm").validate({
+                submitHandler: function (form) {
+                    var isSubMitFlag = true;
+                    /*var productID = $("#productID").val();
+                    if (isNaN(productID) || productID.indexOf('0') == 0) {
+                        alertx("请输入正确的商品ID");
+                        isSubMitFlag = false;
+                        return false;
+                    }*/
+                    if (isSubMitFlag) {
+                        form.submit();
+                    }
+                }
+            })
+        });
+    </script>
+</head>
+<body>
+<br/>
+<form:form id="searchForm" modelAttribute="cmBaikeProduct" action="${ctx}/baike/cmBaikeProduct/recommend/findProductPage" method="post" class="breadcrumb form-search">
+    <input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
+    <input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
+<%--    <form:hidden path="productIds"/>--%>
+    <form:hidden path="productIds"/>
+    <form:hidden path="commodityType"/>
+    <div class="ul-form">
+        <label>${commodityType}分类:</label>
+        <form:select path="typeId" class="input-medium">
+            <form:option value="" label="请选择"/>
+            <form:options items="${typeList}" itemLabel="name" itemValue="id"
+                          htmlEscape="false"/>
+        </form:select>
+        <label>${commodityType}名称:</label>
+        <form:input path="name" htmlEscape="false" class="input-medium" maxlength="20"/>
+        &nbsp;&nbsp; <input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
+        <div class="clearfix"></div>
+    </div>
+</form:form>
+<sys:message content="${message}"/>
+<table class="table table-striped table-bordered table-condensed table-hover">
+    <tr>
+        <th style="width:20px;"></th>
+        <th>ID</th>
+        <th>${commodityType}名称</th>
+        <th>排序</th>
+    </tr>
+    <tbody>
+    <c:if test="${not empty page.list}">
+        <c:forEach items="${page.list}" var="item">
+            <tr id="${item.id}" class="itemtr">
+                <th>
+                    <input class="check-item" type="checkbox" name="info" value='${fns:toJson(item)}'/>
+                </th>
+                <td>${item.id}</td>
+                <td>${item.name}</td>
+                <td>
+                    <input class="input-small sort-input" name="" value="1">
+                </td>
+            </tr>
+        </c:forEach>
+    </c:if>
+    </tbody>
+</table>
+<c:if test="${empty  page.list}">
+    <p style="text-align: center;"><font color="#1e90ff">暂无数据……</font></p>
+</c:if>
+<div class="pagination">${page}</div>
+<script type="text/javascript">
+    $(document).ready(function () {
+        //弹出框去滚动条
+        top.$('#jbox-content').css("overflow-y", "hidden");
+        show_title(30);
+    });
+
+    function page(n, s) {
+        $("#pageNo").val(n);
+        $("#pageSize").val(s);
+        $("#searchForm").submit();
+        return false;
+    }
+
+    function getCheckedItems() {
+        var items = [];
+        $('.check-item:checked').each(function(){
+            var sort = $(this).parents(".itemtr").find(".sort-input").val();
+            console.log("sort:" + sort);
+            var product = JSON.parse($(this).val());
+            var item = {
+                "recommendProductId": product.id,
+                "recommendProductName": product.name,
+                "sort": sort
+            };
+            items.push(item);
+        });
+        return items;
+    }
+
+    function clickAllSelect(ckb) {
+        var isChecked = ckb.checked;
+        $(".check-item").attr('checked', isChecked);
+    }
+
+    /**
+     * @param obj
+     * jquery控制input只能输入数字
+     */
+    function onlynum(obj) {
+        obj.value = obj.value.replace(/[^\d]/g, ""); //清除"数字"以外的字符
+    }
+</script>
+</body>
+</html>
+

+ 272 - 1
src/main/webapp/WEB-INF/views/modules/baikePage/auditBaikeProductPage.jsp

@@ -155,6 +155,111 @@
 		.select2-choice{
 			width: 200px
 		}
+
+		.upload {
+			position: relative;
+			display: inline-block;
+			background: #D0EEFF;
+			border: 1px solid #99D3F5;
+			border-radius: 4px;
+			padding: 4px 12px;
+			color: #1E88C7;
+			text-decoration: none;
+			text-indent: 0;
+			line-height: 20px;
+			margin-left: 20px;
+			cursor: pointer;
+			width: 52px;
+			height: 20px;
+		}
+
+		.upload input {
+			position: absolute;
+			width: 170px;
+			font-size: 20px;
+			right: 0;
+			top: 0;
+			opacity: 0;
+			cursor: pointer;
+		}
+
+		.upload:hover {
+			background: #AADFFD;
+			border-color: #78C3F3;
+			color: #004974;
+			text-decoration: none;
+		}
+
+		.add-submit {
+			position: relative;
+			display: inline;
+			background: #D0EEFF;
+			border: 1px solid #99D3F5;
+			border-radius: 4px;
+			padding: 4px 12px;
+			color: #1E88C7;
+			text-decoration: none;
+			text-indent: 0;
+			line-height: 20px;
+			margin-left: 20px;
+			cursor: pointer;
+			width: 52px;
+			height: 30px;
+		}
+
+		.add-submit input {
+			position: absolute;
+			width: 50px;
+			font-size: 20px;
+			right: 0;
+			top: 0;
+			opacity: 0;
+			cursor: pointer;
+		}
+
+		.add-submit:hover {
+			background: #AADFFD;
+			border-color: #78C3F3;
+			color: #004974;
+			text-decoration: none;
+		}
+
+		.upload-loading{
+			display: none;
+			width: 32px;
+			height: 32px;
+			margin-left: 10px;
+		}
+		.upload-loading img{
+			width: 16px;
+			height: 16px;
+			margin: 0 auto 0;
+		}
+
+		#file-list-display {
+			width: 600px;
+			height: auto;
+			float: left;
+			margin-left: 20px;
+		}
+
+		#file-list-display p {
+			line-height: 30px;
+			font-size: 14px;
+			color: #333333;
+			margin: 0;
+		}
+
+		#file-list-display p .del {
+			color: #2fa4e7;
+			font-size: 12px;
+			cursor: pointer;
+			margin-left: 20px;
+		}
+
+		.Main-content{
+			height: 100px;
+		}
 	</style>
 	<script type="text/javascript">
 		$(document).ready(function() {
@@ -184,6 +289,7 @@
 	</ul><br/>
 	<form:form id="inputForm" modelAttribute="cmBaikeProduct" action="${ctx}/baike/cmBaikeProduct/save?auditFlag=1" method="post" class="form-horizontal">
 		<form:hidden path="id"/>
+		<form:hidden path="fileIds"/>
 		<form:hidden path="commodityType"/>
 		<form:hidden path="shopId"/>
 		<sys:message content="${message}"/>
@@ -232,6 +338,42 @@
                 </div>
             </div>
 		</div>
+		<div class="control-group">
+			<div class="control-group">
+				<label class="control-label keyClass">相关视频(各视频大小不超过50M,最多上传6个)</label>
+			</div>
+			<div class="control-group">
+				<label class="control-label">标题:</label>
+				<div class="controls">
+					<input id="fileTitle" style="width: 457px" htmlEscape="false" >
+				</div>
+				<label class="control-label" style="margin-top:10px">视频路径:</label>
+				<div class="controls" style="margin-top:10px">
+					<input id="uploadFileName" type="text" style="display: inline;" placeholder="支持mp4" disabled="true" class="input-xlarge required" />
+					<div class="upload">
+						<input type="file" name="file" id="productFile" accept=".mp4" >选择文件
+					</div>
+					<div class="add-submit">
+						<input id="addSubmit" type="button" value="上传"/>上传&nbsp;
+					</div>
+					<div class="upload-loading">
+						<img alt="gif" src="/static/images/upload.gif" width="32px" border="none">
+					</div>
+				</div>
+			</div>
+			<div class="control-group">
+				<div id='file-list-display' style="margin-left:180px">
+					<c:if test="${not empty cmBaikeProduct.videoList}">
+						<c:forEach items="${cmBaikeProduct.videoList}" var="videoFile" varStatus="statusIndex">
+							<p>${videoFile.fileTitle}
+								<span class="del"><a onclick="previewVideo('${videoFile.ossUrl}')">预览</a></span>
+								<span class="del" onclick="dataDelete(this,'${videoFile.id}')">删除</span>
+							</p>
+						</c:forEach>
+					</c:if>
+				</div>
+			</div>
+		</div>
         <div style="${cmBaikeProduct.commodityType eq 2?'':'display:none'}" >
             <div class="control-group">
                 <label class="control-label titleClass">正品识别</label>
@@ -750,7 +892,106 @@
 			$('input[name="' + answerInput + '"]').val(answerArray[i]);
 		}
 
-		debugger
+		var fileIds = $("#fileIds").val();
+		//点击上传按钮后上传文件
+		$('#addSubmit').click(function () {
+			var fileIdArr = fileIds.split(',');
+			if (fileIdArr.length >= 7) {
+				alertx('最多上传6个视频');
+				return;
+			}
+			var filesById = document.getElementById('productFile');
+			var files = $('#productFile');
+			var fileList = files.prop('files');
+			var fileTitle = $('#fileTitle').val();
+			var fileName = $('#uploadFileName').val();
+			if (fileTitle == '') {
+				alertx('请输入视频标题')
+				return;
+			}
+			if (files === '' || files.length == 0 || fileName == '') {
+				alertx('请选择上传文件');
+				return;
+			}
+			$("#fileTitle").val("");
+			$("#uploadFileName").val("");
+			var data = new FormData();
+			var productId = $("#id").val();
+			data.append('file', fileList[0]);
+			data.append('fileTitle', fileTitle);
+			data.append('fileName', fileName);
+			data.append('productId', productId);
+			data.append('fileIds', fileIds);
+			$('.upload-loading').css("display", "inline");
+			$.ajax({
+				url: "${ctx}/baike/cmBaikeProduct/upload",
+				data: data,
+				type: "POST",
+				processData: false,
+				contentType: false,
+				dataType: "json",
+				success: function (res) {
+					if (res.success) {
+						filesById.value = '';
+						renderFileList(res.productFile);
+						$('.upload-loading').hide();
+					} else {
+						$.jBox.tip(res.msg, 'error');
+						$("#uploadFileName").val(fileName);
+						$('.upload-loading').hide();
+					}
+
+				},
+				error: function (json) {
+
+				}
+			});
+		})
+
+		var fileList = [];
+		var files = document.getElementById("productFile"), renderFileList;
+		//选择上传文件后显示文件名称
+		files.addEventListener("change", function (event) {
+			var name = event.target.files[0].name;
+			console.log(name)
+			$('#uploadFileName').val(name);
+		});
+		var fileListDisplay = document.getElementById('file-list-display');
+		renderFileList = function (data) {
+			fileIds += data.id + ',';
+			console.log(fileIds);
+			$('#fileIds').val(fileIds);
+			fileList.push({fileTitle: data.fileTitle, id: data.id, ossUrl: data.ossUrl});
+			fileList.forEach(function (file, index) {
+				var fileDisplayEl = document.createElement("p");
+				var deleteFile = document.createElement("span");
+				var viewFile = document.createElement("span");
+				var viewFileUrl = document.createElement("a");
+				//预览链接
+				viewFileUrl.innerHTML = '预览';
+				viewFileUrl.setAttribute("onclick", "previewVideo('" + file.ossUrl + "')");
+				viewFileUrl.setAttribute("target", "_blank");
+				//预览按钮
+				viewFile.className = 'viewFile';
+				console.log(viewFile);
+				viewFile.setAttribute("class","del");
+				viewFile.appendChild(viewFileUrl);
+				//删除按钮
+				deleteFile.innerHTML = '删除';
+				deleteFile.className = 'deleteFile';
+				console.log(deleteFile);
+				deleteFile.setAttribute("class","del");
+				deleteFile.setAttribute("onclick", "dataDelete(this, " + file.id + ")");
+
+				fileDisplayEl.setAttribute("id", file.id);
+				fileDisplayEl.innerHTML = file.fileTitle;
+				fileDisplayEl.appendChild(viewFile);
+				fileDisplayEl.appendChild(deleteFile);
+				fileListDisplay.appendChild(fileDisplayEl);
+			});
+			fileList.splice(0, fileList.length);
+		};
+
 		var commodityType = $("#commodityType").val();
 		var name = $("#name").val();
 		var alias = $("#alias").val();
@@ -962,6 +1203,36 @@
 	function onlynum(obj) {
 		obj.value = obj.value.replace(/[^\d]/g, ""); //清除"数字"以外的字符
 	}
+
+	//删除文件
+	function dataDelete(that, id) {
+		console.log($(that).text());
+		$(that).parent().remove();
+		var fileIds = $("#fileIds").val();
+		if (fileIds.indexOf(id)) {
+			fileIds = fileIds.replace(id + ',', '');
+			$("#fileIds").val(fileIds);
+		}
+		$.ajax({
+			url: "${ctx}/baike/cmBaikeProduct/deleteFile",
+			data: {"fileId": id},
+			async: false,
+			type: "POST"
+		});
+	}
+
+	function previewVideo(url) {
+		var url = "${ctx}/archive/cmProductArchiveContent/preview?url=" + encodeURIComponent(url);
+		var title = "视频播放";
+		top.$.jBox("iframe:" + url, {
+			iframeScrolling: 'yes',
+			width: 1000,
+			height: 750,
+			persistent: true,
+			title: title,
+			buttons: {"关闭": '-1'}
+		});
+	}
 </script>
 </body>
 </html>

+ 12 - 6
src/main/webapp/WEB-INF/views/modules/baikePage/cmBaikeProductForm.jsp

@@ -444,7 +444,7 @@
 	</ul><br/>
 	<form:form id="inputForm" modelAttribute="cmBaikeProduct" action="${ctx}/baike/cmBaikeProduct/save" method="post" class="form-horizontal">
 		<form:hidden path="id"/>
-		<form:hidden path="fileIds" id="fileIds"/>
+		<form:hidden path="fileIds"/>
 		<form:hidden path="commodityType"/>
 		<form:hidden path="emptyNum"/>
 		<sys:message content="${message}"/>
@@ -1041,8 +1041,14 @@
 			$('input[name="' + answerInput + '"]').val(answerArray[i]);
 		}
 
+		var fileIds = $("#fileIds").val();
 		//点击上传按钮后上传文件
 		$('#addSubmit').click(function () {
+			var fileIdArr = fileIds.split(',');
+			if (fileIdArr.length >= 7) {
+				alertx('最多上传6个视频');
+				return;
+			}
 			var filesById = document.getElementById('productFile');
 			var files = $('#productFile');
 			var fileList = files.prop('files');
@@ -1056,10 +1062,10 @@
 				alertx('请选择上传文件');
 				return;
 			}
+			$("#fileTitle").val("");
 			$("#uploadFileName").val("");
 			var data = new FormData();
 			var productId = $("#id").val();
-			var fileIds = $("#fileIds").val();
 			data.append('file', fileList[0]);
 			data.append('fileTitle', fileTitle);
 			data.append('fileName', fileName);
@@ -1092,7 +1098,6 @@
 		})
 
 		var fileList = [];
-		var fileIds = '';
 		var files = document.getElementById("productFile"), renderFileList;
 		//选择上传文件后显示文件名称
 		files.addEventListener("change", function (event) {
@@ -1269,10 +1274,11 @@
 	function dataDelete(that, id) {
 		console.log($(that).text());
 		$(that).parent().remove();
-		/*var fileIds = $("#fileIds").val();
+		var fileIds = $("#fileIds").val();
 		if (fileIds.indexOf(id)) {
-			fileIds.replace(id + ",", "");
-		}*/
+			fileIds = fileIds.replace(id + ',', '');
+			$("#fileIds").val(fileIds);
+		}
 		$.ajax({
 			url: "${ctx}/baike/cmBaikeProduct/deleteFile",
 			data: {"fileId": id},

+ 1 - 0
src/main/webapp/WEB-INF/views/modules/baikePage/cmBaikeProductList.jsp

@@ -143,6 +143,7 @@
 							</tbody>
 						</table>
 					</div>
+					<a href="${ctx}/baike/cmBaikeProduct/recommend/form?id=${cmBaikeProduct.id}">相关推荐</a>
 				</td>
 			</tr>
 		</c:forEach>

+ 58 - 0
src/main/webapp/WEB-INF/views/modules/baikePage/cmBaikeProductRecommendList.jsp

@@ -0,0 +1,58 @@
+<%@ page contentType="text/html;charset=UTF-8" %>
+<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
+<html>
+<head>
+	<title>相关推荐管理</title>
+	<meta name="decorator" content="default"/>
+	<style type="text/css">
+		.table th{text-align: center;}
+		.table td{text-align: center;}
+	</style>
+	<script type="text/javascript">
+		$(document).ready(function() {
+			
+		});
+		function page(n,s){
+			$("#pageNo").val(n);
+			$("#pageSize").val(s);
+			$("#searchForm").submit();
+        	return false;
+        }
+	</script>
+</head>
+<body>
+	<ul class="nav nav-tabs">
+		<li class="active"><a href="${ctx}/baike/cmBaikeProductRecommend/">相关推荐列表</a></li>
+		<shiro:hasPermission name="baike:cmBaikeProductRecommend:edit"><li><a href="${ctx}/baike/cmBaikeProductRecommend/form">相关推荐添加</a></li></shiro:hasPermission>
+	</ul>
+	<form:form id="searchForm" modelAttribute="cmBaikeProductRecommend" action="${ctx}/baike/cmBaikeProductRecommend/" method="post" class="breadcrumb form-search">
+		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
+		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
+		<div class="ul-form">
+			&nbsp;&nbsp;<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
+			<div class="clearfix"></div>
+		</div>
+	</form:form>
+	<sys:message content="${message}"/>
+	<table id="contentTable" class="table table-striped table-bordered table-condensed">
+		<thead>
+			<tr>
+				<shiro:hasPermission name="baike:cmBaikeProductRecommend:edit"><th>操作</th></shiro:hasPermission>
+			</tr>
+		</thead>
+		<tbody>
+		<c:forEach items="${page.list}" var="cmBaikeProductRecommend">
+			<tr>
+				<shiro:hasPermission name="baike:cmBaikeProductRecommend:edit"><td>
+    				<a href="${ctx}/baike/cmBaikeProductRecommend/form?id=${cmBaikeProductRecommend.id}">编辑</a>
+    				<shiro:hasPermission name="baike:cmBaikeProductRecommend:delete">
+					<a href="${ctx}/baike/cmBaikeProductRecommend/delete?id=${cmBaikeProductRecommend.id}" onclick="return confirmx('确认要删除该相关推荐吗?', this.href)">删除</a>
+					</shiro:hasPermission>
+				</td></shiro:hasPermission>
+			</tr>
+		</c:forEach>
+		</tbody>
+	</table>
+	<div class="pagination">${page}</div>
+</body>
+</html>

+ 237 - 0
src/main/webapp/WEB-INF/views/modules/baikePage/recommendForm.jsp

@@ -0,0 +1,237 @@
+<%@ page import="java.util.Date" %>
+<%@ page contentType="text/html;charset=UTF-8" %>
+<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
+<html>
+<head>
+	<title>相关推荐管理</title>
+	<meta name="decorator" content="default"/>
+	<script type="text/javascript">
+		$(document).ready(function() {
+			//$("#name").focus();
+			$("#inputForm").validate({
+				submitHandler: function(form){
+					loading('正在提交,请稍等...');
+					form.submit();
+				},
+				errorContainer: "#messageBox",
+				errorPlacement: function(error, element) {
+					$("#messageBox").text("输入有误,请先更正。");
+					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
+						error.appendTo(element.parent().parent());
+					} else {
+						error.insertAfter(element);
+					}
+				}
+			});
+		});
+	</script>
+</head>
+<body>
+	<ul class="nav nav-tabs">
+		<li><a href="${ctx}/baike/cmBaikeProduct/?commodityType=${cmBaikeProduct.commodityType}">${commodityType}</a></li>
+		<li class="active"><a href="${ctx}/baike/cmBaikeProduct/recommend/form?id=${cmBaikeProduct.id}">相关推荐编辑</a></li>
+	</ul><br/>
+	<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"
+			   onclick="showSelect()" value="添加"/>
+		<thead>
+		<tr>
+			<th>ID</th>
+			<th>${commodityType}名称</th>
+			<th class="manualData" style="${cmBaikeProduct.recommendType ne 1?'display:none':''}">排序</th>
+			<th class="manualData" style="${cmBaikeProduct.recommendType ne 1?'display:none':''}">操作</th>
+		</tr>
+		</thead>
+		<tbody id="productTbody">
+		</tbody>
+	</table>
+	<div class="flex-wrap">
+		<div class="item">
+			<label><font color="red">*</font><b>设置类型:</b></label>
+			<input type="radio" name="recommendType" value="1"  onchange="changeRecommendType()" ${cmBaikeProduct.recommendType == 1 ? "checked" : ""} />手动选择<b class="line">|</b>
+			<input type="radio" name="recommendType" value="2" onchange="changeRecommendType()" ${cmBaikeProduct.recommendType == 2 ? "checked" : ""} />自动选择
+			<span style="color:#D0D0D0;">(设置自动选择后,系统将自动推荐相同分类中的排序前15个进行推荐)</span>
+		</div>
+	</div>
+	<div class="form-actions">
+		<input id="btnSubmit" class="btn btn-primary" type="submit" value="保 存"/>&nbsp;
+		<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
+	</div>
+<script>
+
+	var productImageList = [];
+	// 手动列表
+	var manualImageList = [];
+	// 自动列表
+	var autoImageList = [];
+	var productIds = '';
+	var recommendCount = 0;
+	var recommendType = ${cmBaikeProduct.recommendType};
+
+	$(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="${autoRecommendList}" var="product" varStatus="index">
+			autoImageList.push({
+				recommendProductId: "${product.recommendProductId}",
+				recommendProductName: "${product.recommendProductName}",
+				sort: 0,
+				createDate: '<fmt:formatDate value="<%=new Date()%>" pattern="yyyy-MM-dd HH:mm:ss"/>'
+			});
+		</c:forEach>
+		batchSaveSort()
+	})
+
+	//点击添加
+	function showSelect() {
+		if (recommendCount >= 15) {
+			alertx('最多只能推荐15条');
+			return;
+		}
+		var commodityType = '${cmBaikeProduct.commodityType}';
+		var url = "${ctx}/baike/cmBaikeProduct/recommend/products?productIds=" + productIds + "&commodityType=" + commodityType;
+		title = '添加${commodityType}';
+		width = 700;
+		height = 600;
+		top.$.jBox("iframe:" + url, {
+			iframeScrolling: 'yes',
+			width: width,
+			height: height,
+			persistent: true,
+			title: title,
+			buttons: {"确定": '1', "取消": '-1'},
+			submit: function (v, h, f) {
+				//确定
+				var $jboxFrame = top.$('#jbox-iframe');
+				var $mainFrame = top.$('#mainFrame');
+				if ('1' == v && 1 == $jboxFrame.size() && 1 == $mainFrame.size()) {
+					var items = $jboxFrame[0].contentWindow.getCheckedItems();
+					console.log(items);
+					items.forEach(item =>{
+						items.createDate = '<fmt:formatDate value="<%=new Date()%>" pattern="yyyy-MM-dd HH:mm:ss"/>';
+						manualImageList.push(item);
+					})
+					batchSaveSort();
+				}
+				return true;
+			}
+		});
+	}
+
+	/**
+	 * 一键排序
+	 */
+	function batchSaveSort() {
+		if (recommendType == 1) {
+			productImageList = manualImageList;
+		} else {
+			productImageList = autoImageList;
+		}
+		productImageList.sort(sort);
+		insertHtml();
+	}
+
+	//根据sort值 从小到大排序
+	function sort(a, b) {
+		return ((a.sort - b.sort) == 0 ? (a.createDate > b.createDate ? -1 : 1) : (a.sort - b.sort));
+	}
+
+	function insertHtml() {
+		var html = '';
+		productIds = '';
+		recommendCount = 0;
+		productImageList.forEach(function (item, index) {
+			recommendCount++;
+			html += appendProductHtml(item, index);
+			productIds += item.recommendProductId + ",";
+		});
+		$(".recommendCount").text(recommendCount);
+		$("#productTbody").html(html);
+	}
+
+
+
+	//相关图片列表数据
+	function appendProductHtml(data, index) {
+		var html = '<tr>' +
+				'<td>' +
+				data.recommendProductId +
+				'</td>' +
+				'<td>' + data.recommendProductName + '</td>' +
+				(recommendType == 1?
+				'<td>' +
+				'<input name="sort" style="width:50px;" value="' + data.sort + '"  onkeyup="onlynum(this)"  onchange="changeSort(' + index + ',this)"></td>' +
+				'</td>' +
+				'<td>' +
+				'   <a href="javascript:;" onclick="delect(' + index + ')">删除</a>' +
+				'</td>':'') +
+				'</tr>';
+		return html;
+	}
+
+	/**
+	 * 删除操作
+	 */
+	function delect(index) {
+		return confirmx("确定删除该数据吗?", function () {
+			var image = getImage(index);
+			if (image.recommendProductId != '') {
+				productIds = productIds.replace(image.recommendProductId, "");
+			}
+			productImageList.splice(index, 1);
+			insertHtml();
+		});
+	}
+
+	function changeSort(index, sortThis) {
+		var sort = sortThis.value;
+		var image = getImage(index);
+		image.sort = sort;
+	}
+
+	function getImage(index) {
+		var image = productImageList[index];
+		return image;
+	}
+
+	$('body').on('click','#btnSubmit',function () {
+		if (recommendCount > 15) {
+			alertx("最多只能添加15条相关商品");
+			return;
+		}
+		var url = "${ctx}/baike/cmBaikeProduct/recommend/save?id=" + ${cmBaikeProduct.id} + "&recommendType=" + recommendType;
+		if (recommendType == 1) {
+			//只有选择了手动推荐相关商品单选框才修改相关商品数据
+			var recommendJson = JSON.stringify(manualImageList);
+			url += "&recommendJson=" + recommendJson;
+		}
+		//保留搜索条件
+		<%--url += "&searchName=${product.searchName}&searchShopID=${product.searchShopID}&searchShopName=${product.searchShopName}&searchBigTypeID=${product.searchBigTypeID}&searchSmallTypeID=${product.searchSmallTypeID}&searchTinyTypeID=${product.searchTinyTypeID}&searchValidFlag=${product.searchValidFlag}&searchActStatus=${product.searchActStatus}&searchProductType=${product.searchProductType}&searchBrandID=${product.searchBrandID}&searchPreferredFlag=${product.searchPreferredFlag}";--%>
+		window.location.href = url;
+	});
+
+
+	function changeRecommendType(){
+		recommendType = $("input[name='recommendType']:checked").val();
+		if (recommendType == 1) {
+			$(".manualData").css('display', 'table-cell');
+			productImageList = manualImageList;
+		} else if (recommendType == 2) {
+			$(".manualData").css('display', 'none');
+			productImageList = autoImageList;
+		}
+		batchSaveSort();
+	}
+</script>
+</body>
+</html>

+ 1 - 1
src/main/webapp/WEB-INF/views/modules/product-new/recommend.jsp

@@ -84,7 +84,7 @@
 			<label><font color="red">*</font><b>设置类型:</b></label>
 			<input type="radio" name="recommendType" value="1"  onchange="changeRecommendType()" ${recommendType == "1" ? "checked" : ""} />手动选择<b class="line">|</b>
 			<input type="radio" name="recommendType" value="0" onchange="changeRecommendType()" ${(recommendType == "0" || recommendType == ""|| recommendType == null) ? "checked" : ""} />自动选择
-			<span style="color:#D0D0D0;">(设置自动选择后,系统将会选择该商品所属相同二级分类中销量前7名的商品进行推荐)<span/>
+			<span style="color:#D0D0D0;">(设置自动选择后,系统将会选择该商品所属相同二级分类中销量前7名的商品进行推荐)</span>
 		</div>
 	</div>
 	<div id="p-list" style="display:none;">