Authored by liangyi.chen@yoho.cn

添加推荐商品管理菜单

  1 +package com.yoho.ufo.dal;
  2 +
  3 +import com.yoho.ufo.dal.model.ProductRecommend;
  4 +import org.apache.ibatis.annotations.Param;
  5 +
  6 +import java.util.List;
  7 +
  8 +public interface ProductRecommendMapper {
  9 + int deleteByPrimaryKey(Integer id);
  10 +
  11 + int insert(ProductRecommend record);
  12 +
  13 + ProductRecommend selectByPrimaryKey(Integer id);
  14 +
  15 + ProductRecommend selectByProductId(Integer productId);
  16 +
  17 + int updateByPrimaryKeySelective(ProductRecommend record);
  18 +
  19 + int selectCount(@Param("productId") Integer productId,
  20 + @Param("productName") String productName);
  21 +
  22 + List<ProductRecommend> selectPage(@Param("productId") Integer productId,
  23 + @Param("productName") String productName,
  24 + @Param("start") Integer start,
  25 + @Param("rows") Integer rows);
  26 +
  27 + int batchInsert(List<ProductRecommend> productRecommendList);
  28 +
  29 + List<ProductRecommend> selectByProductIds(@Param("list")List<Integer> ids);
  30 +
  31 +}
@@ -33,6 +33,4 @@ public interface Yoho2ufoProductMapper { @@ -33,6 +33,4 @@ public interface Yoho2ufoProductMapper {
33 33
34 int deleteBatchBySkns(@Param("skns")String skns); 34 int deleteBatchBySkns(@Param("skns")String skns);
35 35
36 - int batchInsert(List<Yoho2ufoProduct> yoho2ufoProductList);  
37 -  
38 } 36 }
  1 +package com.yoho.ufo.dal.model;
  2 +
  3 +import lombok.Data;
  4 +
  5 +@Data
  6 +public class ProductRecommend {
  7 + private Integer id;
  8 +
  9 + private String productName;
  10 +
  11 + private Integer productId;
  12 +
  13 + private Integer orderBy;
  14 +
  15 + private Integer updateTime;
  16 +
  17 +}
  1 +<?xml version="1.0" encoding="UTF-8" ?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
  3 +<mapper namespace="com.yoho.ufo.dal.ProductRecommendMapper" >
  4 + <resultMap id="BaseResultMap" type="com.yoho.ufo.dal.model.ProductRecommend" >
  5 + <id column="id" property="id" jdbcType="INTEGER" />
  6 + <result column="product_name" property="productName" jdbcType="VARCHAR" />
  7 + <result column="product_id" property="productId" jdbcType="INTEGER" />
  8 + <result column="order_by" property="orderBy" jdbcType="INTEGER" />
  9 + <result column="update_time" property="updateTime" jdbcType="INTEGER" />
  10 + </resultMap>
  11 + <sql id="Base_Column_List" >
  12 + id, product_name, product_id, order_by, update_time
  13 + </sql>
  14 +
  15 + <sql id="pageCondition" >
  16 + <if test="productId != null and productId > 0">
  17 + and product_id like concat('%', #{productId}, '%')
  18 + </if>
  19 + <if test="productName != null and productName !=''">
  20 + and product_name like concat('%', #{productName}, '%')
  21 + </if>
  22 + </sql>
  23 +
  24 + <select id="selectCount" resultType="java.lang.Integer">
  25 + select count(*) from product_recommend where 1=1 <include refid="pageCondition" />
  26 + </select>
  27 +
  28 + <select id="selectPage" resultMap="BaseResultMap">
  29 + select
  30 + <include refid="Base_Column_List" />
  31 + from product_recommend
  32 + where 1=1 <include refid="pageCondition" /> order by update_time desc limit #{start},#{rows}
  33 + </select>
  34 +
  35 + <select id="selectByProductId" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  36 + select
  37 + <include refid="Base_Column_List" />
  38 + from product_recommend
  39 + where product_id = #{productId,jdbcType=INTEGER}
  40 + </select>
  41 +
  42 + <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
  43 + select
  44 + <include refid="Base_Column_List" />
  45 + from product_recommend
  46 + where id = #{id,jdbcType=INTEGER}
  47 + </select>
  48 +
  49 + <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
  50 + delete from product_recommend
  51 + where id = #{id,jdbcType=INTEGER}
  52 + </delete>
  53 + <insert id="insert" parameterType="com.yoho.ufo.dal.model.ProductRecommend" >
  54 + insert into product_recommend (id, product_name, product_id,
  55 + order_by, update_time)
  56 + values (#{id,jdbcType=INTEGER}, #{productName,jdbcType=VARCHAR}, #{productId,jdbcType=INTEGER},
  57 + #{orderBy,jdbcType=INTEGER}, #{updateTime,jdbcType=INTEGER})
  58 + </insert>
  59 + <update id="updateByPrimaryKeySelective" parameterType="com.yoho.ufo.dal.model.ProductRecommend" >
  60 + update product_recommend
  61 + <set>
  62 + <if test="productName != null" >
  63 + product_name = #{productName,jdbcType=VARCHAR},
  64 + </if>
  65 + <if test="productId != null" >
  66 + product_id = #{productId,jdbcType=INTEGER},
  67 + </if>
  68 + <if test="orderBy != null" >
  69 + order_by = #{orderBy,jdbcType=INTEGER},
  70 + </if>
  71 + <if test="updateTime != null" >
  72 + update_time = #{updateTime,jdbcType=INTEGER},
  73 + </if>
  74 + </set>
  75 + where id = #{id,jdbcType=INTEGER}
  76 + </update>
  77 +
  78 + <insert id="batchInsert" parameterType="java.util.List">
  79 + insert into product_recommend(product_name,product_id, order_by,update_time) values
  80 + <foreach collection="list" item="item" index="index" separator=",">
  81 + (#{item.productName,jdbcType=VARCHAR},#{item.productId,jdbcType=INTEGER},
  82 + #{item.orderBy,jdbcType=INTEGER},#{item.updateTime,jdbcType=INTEGER})
  83 + </foreach>
  84 + </insert>
  85 +
  86 + <select id="selectByProductIds" resultMap="BaseResultMap">
  87 + select
  88 + <include refid="Base_Column_List" />
  89 + from product_recommend
  90 + where product_id in
  91 + <foreach item="item" collection="list" open="(" separator="," close=")">
  92 + #{item}
  93 + </foreach>
  94 + </select>
  95 +
  96 +</mapper>
@@ -137,13 +137,5 @@ @@ -137,13 +137,5 @@
137 </foreach> 137 </foreach>
138 </delete> 138 </delete>
139 139
140 - <insert id="batchInsert" parameterType="java.util.List">  
141 - insert into (id, product_skn, product_name,brand_name, yoho_image, ufo_image,update_time) values  
142 - <foreach collection="list" item="item" index="index" separator=",">  
143 - (#{id,jdbcType=INTEGER}, #{productSkn,jdbcType=INTEGER}, #{productName,jdbcType=VARCHAR},  
144 - #{brandName,jdbcType=VARCHAR}, #{yohoImage,jdbcType=VARCHAR}, #{ufoImage,jdbcType=VARCHAR},  
145 - #{updateTime,jdbcType=INTEGER})  
146 - </foreach>  
147 - </insert>  
148 140
149 </mapper> 141 </mapper>
  1 +package com.yoho.ufo.controller.product;
  2 +
  3 +import com.yoho.ufo.dal.model.ProductRecommend;
  4 +import com.yoho.ufo.service.impl.ProductRecommendService;
  5 +import com.yohobuy.ufo.model.common.ApiResponse;
  6 +import com.yohobuy.ufo.model.common.PageResponseBO;
  7 +import com.yohobuy.ufo.model.request.productrecommend.ProductRecommendReqBo;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +import org.springframework.web.bind.annotation.RequestMapping;
  11 +import org.springframework.web.bind.annotation.RequestMethod;
  12 +import org.springframework.web.bind.annotation.RestController;
  13 +
  14 +import javax.annotation.Resource;
  15 +
  16 +@RestController
  17 +@RequestMapping(value = "/productRecommend")
  18 +public class ProductRecommendController {
  19 +
  20 + private static final Logger LOGGER = LoggerFactory.getLogger(ProductRecommendController.class);
  21 +
  22 + @Resource
  23 + private ProductRecommendService productRecommendService;
  24 +
  25 + @RequestMapping(value = "/addOrUpdate" , method = RequestMethod.POST)
  26 + public ApiResponse<Void> addOrUpdate(ProductRecommend bo) {
  27 + LOGGER.info("productRecommend.addOrUpdate param = {}", bo);
  28 + return productRecommendService.addOrUpdate(bo);
  29 + }
  30 +
  31 + @RequestMapping(value = "/getProductRecommendById")
  32 + public ApiResponse<ProductRecommend> getProductRecommendById(Integer id) {
  33 + LOGGER.info("productRecommend.getProductRecommendById id = {}", id);
  34 + return productRecommendService.getProductRecommendById(id);
  35 + }
  36 +
  37 + @RequestMapping(value = "/list")
  38 + public ApiResponse<PageResponseBO<ProductRecommend>> list(ProductRecommendReqBo bo) {
  39 + LOGGER.info("productRecommend.list param = {}", bo);
  40 + return productRecommendService.list(bo);
  41 + }
  42 +
  43 + @RequestMapping(value = "/deleteProductRecommendById")
  44 + public ApiResponse<Void> deleteProductRecommendById(Integer id) {
  45 + LOGGER.info("productRecommend.deleteProductRecommendById param = {}", id);
  46 + return productRecommendService.deleteProductRecommendById(id);
  47 + }
  48 +
  49 +
  50 + @RequestMapping(value = "/insertBatch")
  51 + public ApiResponse<Void> insertBatch(String idStr) {
  52 + LOGGER.info("productRecommend.insertBatch param = {}", idStr);
  53 + return productRecommendService.insertBatch(idStr);
  54 + }
  55 +
  56 +}
@@ -53,12 +53,6 @@ public class Yoho2ufoProductController { @@ -53,12 +53,6 @@ public class Yoho2ufoProductController {
53 return yoho2ufoProductService.deleteBatchYoho2ufoProduct(skns); 53 return yoho2ufoProductService.deleteBatchYoho2ufoProduct(skns);
54 } 54 }
55 55
56 - @RequestMapping(value = "/insertBatch")  
57 - public ApiResponse<Void> insertBatch(String sknStr) {  
58 - LOGGER.info("Yoho2ufoProduct.insertBatch param = {}", sknStr);  
59 - return yoho2ufoProductService.insertBatch(sknStr);  
60 - }  
61 -  
62 @RequestMapping(value = "/getYoho2ufoProductById") 56 @RequestMapping(value = "/getYoho2ufoProductById")
63 public ApiResponse<Yoho2ufoProductRespBo> getYoho2ufoProductById(Integer id) { 57 public ApiResponse<Yoho2ufoProductRespBo> getYoho2ufoProductById(Integer id) {
64 LOGGER.info("Yoho2ufoProduct.getYoho2ufoProductById id = {}", id); 58 LOGGER.info("Yoho2ufoProduct.getYoho2ufoProductById id = {}", id);
@@ -18,8 +18,6 @@ public interface Yoho2ufoProductService { @@ -18,8 +18,6 @@ public interface Yoho2ufoProductService {
18 18
19 ApiResponse<Void> addOrUpdate(Yoho2ufoProduct bo); 19 ApiResponse<Void> addOrUpdate(Yoho2ufoProduct bo);
20 20
21 - ApiResponse<Void> insertBatch(String sknStr);  
22 -  
23 ApiResponse<Yoho2ufoProductRespBo> getYoho2ufoProductById(Integer id); 21 ApiResponse<Yoho2ufoProductRespBo> getYoho2ufoProductById(Integer id);
24 22
25 23
  1 +package com.yoho.ufo.service.impl;
  2 +
  3 +import com.yoho.ufo.dal.ProductMapper;
  4 +import com.yoho.ufo.dal.ProductRecommendMapper;
  5 +import com.yoho.ufo.dal.model.Product;
  6 +import com.yoho.ufo.dal.model.ProductRecommend;
  7 +import com.yohobuy.ufo.model.common.ApiResponse;
  8 +import com.yohobuy.ufo.model.common.PageResponseBO;
  9 +import com.yohobuy.ufo.model.request.productrecommend.ProductRecommendReqBo;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +import org.springframework.stereotype.Service;
  13 +import org.springframework.util.CollectionUtils;
  14 +
  15 +import javax.annotation.Resource;
  16 +import java.util.ArrayList;
  17 +import java.util.Arrays;
  18 +import java.util.List;
  19 +import java.util.stream.Collectors;
  20 +
  21 +@Service
  22 +public class ProductRecommendService {
  23 +
  24 +
  25 + @Resource
  26 + ProductRecommendMapper productRecommendMapper;
  27 +
  28 + @Resource
  29 + ProductMapper productMapper;
  30 +
  31 + private static final int MAX_PRODUCT_RECOMMEND_NUM = 20;//UFO推荐产品ID最大数量
  32 +
  33 + private static final Logger logger = LoggerFactory.getLogger(ProductRecommendService.class);
  34 +
  35 + public ApiResponse<PageResponseBO<ProductRecommend>> list(ProductRecommendReqBo bo) {
  36 + int count = productRecommendMapper.selectCount(bo.getProductId(), bo.getProductName());
  37 + if (count > 0) {
  38 + List<ProductRecommend> productList = productRecommendMapper.selectPage(bo.getProductId(),
  39 + bo.getProductName(),
  40 + bo.getStartIndex(),
  41 + bo.getRows());
  42 + PageResponseBO<ProductRecommend> pageBo = new PageResponseBO<>(count, productList, bo.getPage(), bo.getRows());
  43 + return new ApiResponse<>(pageBo);
  44 + }
  45 + return new ApiResponse<>();
  46 + }
  47 +
  48 +
  49 + public ApiResponse<Void> deleteProductRecommendById(Integer id) {
  50 + productRecommendMapper.deleteByPrimaryKey(id);
  51 + return new ApiResponse<>();
  52 + }
  53 +
  54 + public ApiResponse<Void> addOrUpdate(ProductRecommend reqBo) {
  55 + Integer productId = reqBo.getProductId();
  56 + Product product = productMapper.selectByPrimaryKey(productId);
  57 + int count = productRecommendMapper.selectCount(null,null);
  58 + if(product != null){
  59 + reqBo.setProductName(product.getProductName());
  60 + reqBo.setUpdateTime((int) (System.currentTimeMillis() / 1000));
  61 + ProductRecommend productRecommendFromDB = productRecommendMapper.selectByProductId(reqBo.getProductId());
  62 + if(reqBo.getId() != null && reqBo.getId() > 0){//更新操作
  63 + productRecommendMapper.updateByPrimaryKeySelective(reqBo);
  64 + }else if(productRecommendFromDB != null){
  65 + return new ApiResponse<>(202,"该产品Id数据库已存在");
  66 + }else{
  67 + if(count >= MAX_PRODUCT_RECOMMEND_NUM){
  68 + return new ApiResponse<>(204,"推荐商品数量不能超过上限");
  69 + }
  70 + productRecommendMapper.insert(reqBo);
  71 + }
  72 + }else{
  73 + return new ApiResponse<>(201,"该产品不存在");
  74 + }
  75 +
  76 + return new ApiResponse<>();
  77 + }
  78 +
  79 + public ApiResponse<Void> insertBatch(String productIdStr) {
  80 + int count = productRecommendMapper.selectCount(null,null);
  81 + List<ProductRecommend> ufoProductRecommendList = new ArrayList<>();
  82 + String productIds = productIdStr.trim();
  83 + String addIds = productIds.replaceAll("\\s*", "");
  84 + String[] addIdArray = addIds.split(",");
  85 + List<String> idStrList = Arrays.asList(addIdArray);
  86 + List<Integer> idList = idStrList.stream().map(Integer::valueOf).collect(Collectors.toList());
  87 + List<ProductRecommend> productExsit = productRecommendMapper.selectByProductIds(idList);
  88 + if(!CollectionUtils.isEmpty(productExsit)){
  89 + List<Integer> exsitProductIds = productExsit.stream().map(ProductRecommend::getProductId)
  90 + .collect(Collectors.toList());
  91 + idList = idList.stream().filter(item -> !exsitProductIds.contains(item))
  92 + .collect(Collectors.toList());
  93 + }
  94 + if(idList.size() > MAX_PRODUCT_RECOMMEND_NUM - count){
  95 + return new ApiResponse<>(204,"推荐商品数量不能超过上限");
  96 + }
  97 + List<Product> productInfoList = productMapper.selectProductListByIds(idList);
  98 + if (productInfoList != null && productInfoList.size() > 0) {
  99 + productInfoList.forEach(product -> {
  100 + ProductRecommend productRecommend = new ProductRecommend();
  101 + productRecommend.setProductId(product.getId());
  102 + productRecommend.setProductName(product.getProductName());
  103 + productRecommend.setOrderBy(1);//批量新增时默认的order都是1
  104 + productRecommend.setUpdateTime((int) (System.currentTimeMillis() / 1000));
  105 + ufoProductRecommendList.add(productRecommend);
  106 + });
  107 + productRecommendMapper.batchInsert(ufoProductRecommendList);
  108 + }
  109 + return new ApiResponse<>();
  110 + }
  111 +
  112 + public ApiResponse<ProductRecommend> getProductRecommendById(Integer id) {
  113 + ProductRecommend productRecommend = productRecommendMapper.selectByPrimaryKey(id);
  114 + if(productRecommend != null){
  115 + return new ApiResponse<>(productRecommend);
  116 + }
  117 + return new ApiResponse<>();
  118 + }
  119 +
  120 +}
@@ -27,7 +27,6 @@ import org.springframework.util.StringUtils; @@ -27,7 +27,6 @@ import org.springframework.util.StringUtils;
27 27
28 import javax.annotation.Resource; 28 import javax.annotation.Resource;
29 import java.util.*; 29 import java.util.*;
30 -import java.util.stream.Collectors;  
31 30
32 @Service 31 @Service
33 public class Yoho2ufoProductServiceImpl implements Yoho2ufoProductService { 32 public class Yoho2ufoProductServiceImpl implements Yoho2ufoProductService {
@@ -269,42 +268,6 @@ public class Yoho2ufoProductServiceImpl implements Yoho2ufoProductService { @@ -269,42 +268,6 @@ public class Yoho2ufoProductServiceImpl implements Yoho2ufoProductService {
269 } 268 }
270 269
271 @Override 270 @Override
272 - public ApiResponse<Void> insertBatch(String sknStr) {  
273 - Map<Integer, YohoProductInfo> productBoMap;  
274 - List<Yoho2ufoProduct> yoho2ufoProductList = new ArrayList<>();  
275 - String skns = sknStr.trim();  
276 - String addskns = skns.replaceAll("\\s*", "");  
277 - String[] addSknArray = addskns.split(",");  
278 - List<String> sknStrList = Arrays.asList(addSknArray);  
279 - List<Integer> sknList = sknStrList.stream().map(Integer::valueOf).collect(Collectors.toList());  
280 - List<Yoho2ufoProduct> yoho2ufoProductExsit = yoho2ufoProductMapper.selectByProductSkns(sknList);  
281 - if(!CollectionUtils.isEmpty(yoho2ufoProductExsit)){  
282 - List<Integer> exsitSkns = yoho2ufoProductExsit.stream().map(Yoho2ufoProduct::getProductSkn)  
283 - .collect(Collectors.toList());  
284 - sknList = sknList.stream().filter(item -> !exsitSkns.contains(item))  
285 - .collect(Collectors.toList());  
286 - }  
287 - List<YohoProductInfo> productBoList = getProductBoBySknList(sknList);  
288 - if (productBoList != null && productBoList.size() > 0) {  
289 - productBoMap = CollectionUtil.extractMap  
290 - (productBoList, YohoProductInfo::getProductSkn);  
291 -  
292 - sknList.forEach(skn -> {  
293 - YohoProductInfo yohoProductBo = productBoMap.get(skn);  
294 - Yoho2ufoProduct yoho2ufoProduct = new Yoho2ufoProduct();  
295 - yoho2ufoProduct.setProductSkn(skn);  
296 - yoho2ufoProduct.setProductName(yohoProductBo.getProductName());  
297 - yoho2ufoProduct.setBrandName(yohoProductBo.getBrandName());  
298 - yoho2ufoProduct.setYohoImage(yohoProductBo.getImageUrl());  
299 - yoho2ufoProduct.setUpdateTime((int) (System.currentTimeMillis() / 1000));  
300 - yoho2ufoProductList.add(yoho2ufoProduct);  
301 - });  
302 - yoho2ufoProductMapper.batchInsert(yoho2ufoProductList);  
303 - }  
304 - return new ApiResponse<>();  
305 - }  
306 -  
307 - @Override  
308 public ApiResponse<Yoho2ufoProductRespBo> getYoho2ufoProductById(Integer id) { 271 public ApiResponse<Yoho2ufoProductRespBo> getYoho2ufoProductById(Integer id) {
309 Yoho2ufoProduct yoho2ufoProduct = yoho2ufoProductMapper.selectByPrimaryKey(id); 272 Yoho2ufoProduct yoho2ufoProduct = yoho2ufoProductMapper.selectByPrimaryKey(id);
310 if(yoho2ufoProduct != null){ 273 if(yoho2ufoProduct != null){
  1 +<!DOCTYPE html>
  2 +<div id="tt" class="easyui-layout" fit="true" style="overflow-y: scroll">
  3 + <form name="productEditForm" id="productEditForm" method="post" enctype="multipart/form-data">
  4 + <input type="hidden" name="id" id="id"/>
  5 + <div style="margin-top: 20px;margin-left: 30px">
  6 + <table border="0" style="width:95%;margin-top:5px;line-height:30px;" id="tab">
  7 + <tr style="height: 60px">
  8 + <td width="12%">产品ID<span class="requriedInput">*</span></td>
  9 + <td width="50%">
  10 + <input id="productId" name="productId" class="easyui-numberbox" style="width: 100px"/>
  11 + </td>
  12 + </tr>
  13 +
  14 + <tr style="height: 60px" id="orderByTR">
  15 + <td width="12%">排序值<span class="requriedInput">*</span></td>
  16 + <td width="20%">
  17 + <input id="orderBy" name="orderBy" class="easyui-numberbox" style="width: 200px;" required="required"/>
  18 + </td>
  19 + </tr>
  20 + </table>
  21 + </div>
  22 + </form>
  23 +</div>
  24 +<script>
  25 + $(function () {
  26 +
  27 + // 隐藏域赋值
  28 + $('#productEditForm #id').val(editId);
  29 + if (editId > 0) {
  30 + $.post(contextPath + "/productRecommend/getProductRecommendById", {
  31 + id: editId
  32 + }, function (data) {
  33 + $("#productEditForm #productId").numberbox('readonly', true);
  34 + $("#productEditForm").form("load", data.data);
  35 + });
  36 + }
  37 + });
  38 +
  39 +</script>
  1 +<!DOCTYPE html>
  2 +<html>
  3 +<head>
  4 + <meta charset="UTF-8" />
  5 + <title>Yoho!Buy运营平台</title>
  6 + <script src="/ufoPlatform/js/include.js"></script>
  7 +</head>
  8 +<body class="easyui-layout" fit="true">
  9 +<div id="infoDivId">
  10 + <form id="insertBatchForm" name="insertBatchForm" method="post">
  11 + <table id="insertBatchTable" border="0" align="center" style="line-height: 30px;width:95%">
  12 + <tr id="pageContentTr">
  13 + <td>
  14 + <textarea id="idStr" name="idStr" style="height:100px;width:280px;" onKeyUp="javascript:this.value=this.value.replace(/[^\r\n0-9\,]/g,'');"/>
  15 + <span>&nbsp;(productId,逗号分隔)</span>
  16 + </td>
  17 + </tr>
  18 + <!--<tr id="normalBoostTr" >
  19 + <td width="10%" align="right"><span style="font-weight:bold;">score:</span></td>
  20 + <td>
  21 + <input id="score" name="score" placeholder="请输入百分比" type="text"/>
  22 + </td>
  23 + </tr>-->
  24 + </table>
  25 + </form>
  26 +</div>
  27 +</body>
  28 +</html>
  1 +<!DOCTYPE html>
  2 +<html>
  3 +<head>
  4 + <meta charset="UTF-8"/>
  5 + <title>Yoho!Buy运营平台</title>
  6 + <script src="/ufoPlatform/js/include.js"></script>
  7 + <script src="/ufoPlatform/js/ajaxfileupload.js"></script>
  8 +</head>
  9 +<body class="easyui-layout" fit="true">
  10 +<div region="north" style="height: 230px">
  11 + <script>
  12 + document.write(addHead('UFO推荐商品配置', ''));
  13 + </script>
  14 + <style>
  15 + .div_search input {
  16 + margin-top: 20px;
  17 + }
  18 +
  19 + .div_search .textbox {
  20 + margin-top: 20px;
  21 + }
  22 +
  23 + .div_search .easyui-linkbutton {
  24 + margin-top: 20px;
  25 + }
  26 + </style>
  27 + <div style="margin-left: 30px;" class="div_search">
  28 + <input id="productId" type="text">
  29 + <input id="productName" type="text">
  30 + <a id="searchLinkButton" class="easyui-linkbutton btn-info" data-options="iconCls:'icon-search'">筛选</a>
  31 + <a id="searchAllLinkButton" class="easyui-linkbutton btn-info" data-options="iconCls:'icon-search'">全部</a>
  32 + <a id="addProduct" class="easyui-linkbutton btn-success" data-options="iconCls:'icon-search'">新增</a>
  33 + <a id="addProductBatch" class="easyui-linkbutton btn-success" style="margin-left: 50px">批量新增</a>
  34 + </div>
  35 +</div>
  36 +<div region="center">
  37 + <div style="margin-left: 30px;margin-top: 20px;height: 660px">
  38 + <table id="productRecommendListTable"></table>
  39 + </div>
  40 +</div>
  41 +
  42 +<script type="text/javascript">
  43 + var editId;
  44 + function getEditDialog(){
  45 + var title="批量新增";
  46 + var url = contextPath + "/productRecommend/insertBatch";
  47 + var div = $("<div>").appendTo($(window.self.document.body));
  48 + window.self.$(div).myDialog({
  49 + title: title,
  50 + width: "30%",
  51 + height: "30%",
  52 + resizable:true,
  53 + buttons:[{
  54 + id : "saveBtn",
  55 + text:'保存',
  56 + iconCls : "icon-save",
  57 + handler:function(){
  58 + window.self.$("#insertBatchForm").form("submit", {
  59 + url : url,
  60 + onSubmit : function(param) {
  61 +
  62 + },
  63 + success : function(data) {
  64 + $.messager.progress("close");
  65 + data = JSON.parse(data);
  66 + if (data.code == 200) {
  67 + $(div).dialog("close");
  68 + $("#productRecommendListTable").myDatagrid("reload");
  69 + $.messager.show({
  70 + title: "提示",
  71 + msg: title + "成功!",
  72 + height: 120
  73 + });
  74 + } else {
  75 + $.messager.alert("失败", data.message, "error");
  76 + }
  77 + }
  78 + });
  79 + }
  80 + },{
  81 + id : "closeBtn",
  82 + text:'取消',
  83 + iconCls : "icon-cancel",
  84 + handler:function(){
  85 + window.self.$(div).dialog('close');
  86 + }
  87 + }],
  88 + modal: true,
  89 + href: contextPath + "/html/productRecommend/productRecommendAddBatch.html",
  90 + onOpen : function() {
  91 + window.setTimeout(function() {
  92 + $("#saveBtn").addClass("btn-success");
  93 + $("#closeBtn").addClass("btn-danger");
  94 + }, 100);
  95 + }
  96 + });
  97 + }
  98 +
  99 + $(function () {
  100 + $("#productId").textbox({
  101 + prompt: "商品Id"
  102 + });
  103 + $("#productName").textbox({
  104 + prompt: "商品名称"
  105 + });
  106 +
  107 + $('#addProduct').linkbutton({
  108 + iconCls: "icon-edit",
  109 + onClick: function () {
  110 + editRow(0);
  111 + }
  112 + });
  113 +
  114 + $("#addProductBatch").linkbutton({
  115 + text : "批量新增",
  116 + iconCls : "icon-del",
  117 + onClick : function() {
  118 + getEditDialog(null);
  119 + }
  120 + });
  121 +
  122 +
  123 +
  124 + $("#productRecommendListTable").myDatagrid({
  125 + fit: true,
  126 + fitColumns: true,
  127 + nowrap: false,
  128 + url: contextPath + "/productRecommend/list",
  129 + method: 'POST',
  130 + loadFilter: function (data) {
  131 + var temp = defaultLoadFilter(data);
  132 + temp.rows = temp.list;
  133 + return temp;
  134 + },
  135 + columns: [[{
  136 + title: "ID",
  137 + field: "id",
  138 + align: "center",
  139 + hidden: true
  140 + }, {
  141 + title: "商品Id",
  142 + field: "productId",
  143 + width: 80,
  144 + align: "center"
  145 + }, {
  146 + title: "商品名称",
  147 + field: "productName",
  148 + width: 120,
  149 + align: "center",
  150 + },{
  151 + title: "次序",
  152 + field: "orderBy",
  153 + width: 80,
  154 + align: "center"
  155 + },{
  156 + title: "操作",
  157 + field: "operations",
  158 + width: 80,
  159 + align: "center",
  160 + formatter: function (value, rowData) {
  161 + var str = "<a role='edit' dataId='" + rowData.id + "' style='margin-left:10px;background-color: #5bc0de'>编辑</a>";
  162 + str += "<a role='del' dataId='" + rowData.id + "' style='margin-left:10px;background-color: red'>删除</a>";
  163 + return str;
  164 + }
  165 + }]],
  166 + cache: false,
  167 + pagination: true,
  168 + pageSize: 20,
  169 + pageList: [20],
  170 + idField: "id",
  171 + singleSelect: false,
  172 + checkOnSelect: false,
  173 + onLoadSuccess: function () {
  174 + // 编辑
  175 + $(this).myDatagrid("getPanel").find("a[role='edit']").linkbutton({
  176 + iconCls: "icon-edit",
  177 + onClick: function () {
  178 + var id = $(this).attr("dataId");
  179 + editRow(id);
  180 + }
  181 + });
  182 + // 删除
  183 + $(this).myDatagrid("getPanel").find("a[role='del']").linkbutton({
  184 + iconCls: "icon-more",
  185 + onClick: function () {
  186 + del($(this).attr("dataId"));
  187 + }
  188 + });
  189 + }
  190 + });
  191 +
  192 +
  193 + // 搜索
  194 + $("#searchLinkButton").linkbutton({
  195 + onClick: function () {
  196 + var param = getParams();
  197 + $("#productRecommendListTable").myDatagrid("load", param);
  198 + }
  199 + });
  200 +
  201 + // 搜索全部
  202 + $("#searchAllLinkButton").linkbutton({
  203 + onClick: function () {
  204 + $('#productId').textbox('clear');
  205 + $('#productName').textbox('clear');
  206 + var param = {};
  207 + $("#productRecommendListTable").myDatagrid("load", param);
  208 + }
  209 + });
  210 +
  211 + /**
  212 + * 提取出搜索参数
  213 + */
  214 + function getParams() {
  215 + // id
  216 + var productId = $('#productId').textbox('getText');
  217 +
  218 + // 产品名称
  219 + var productName = $('#productName').textbox('getText');
  220 + var param = {};
  221 + if (undefined !== productId && null !== productId && "" !== productId) {
  222 + param.productId = productId;
  223 + }
  224 + if (undefined !== productName && null !== productName && "" !== productName) {
  225 + param.productName = productName;
  226 + }
  227 + return param;
  228 + }
  229 +
  230 +
  231 + function editRow(id) {
  232 + editId = id;
  233 + var div = $("<div>").appendTo($(document.body));
  234 + var title = "编辑";
  235 + var message = "确认修改吗?";
  236 + if (id == 0) {
  237 + title = "添加";
  238 + message = "确认添加吗?";
  239 + }
  240 + $(div).myDialog({
  241 + width: "600px",
  242 + height: "400px",
  243 + title: title,
  244 + href: contextPath + "/html/productRecommend/editProductRecommend.html",
  245 + queryParams: {
  246 + id: id
  247 + },
  248 + modal: true,
  249 + collapsible: true,
  250 + cache: false,
  251 + buttons: [{
  252 + id: "saveBtn",
  253 + text: "保存",
  254 + handler: function () {
  255 + $.messager.confirm("确认", message, function (flag) {
  256 + if (flag) {
  257 + var url = contextPath + "/productRecommend/addOrUpdate";
  258 + $("#productEditForm").form("submit", {
  259 + url: url,
  260 + onSubmit: function () {
  261 + if (!$("#productEditForm").form("validate")) {
  262 + return false;
  263 + }
  264 + $.messager.progress({
  265 + title: "正在执行",
  266 + msg: "正在执行,请稍后..."
  267 + });
  268 + return true;
  269 + },
  270 + success: function (data) {
  271 + $.messager.progress("close");
  272 + data = JSON.parse(data);
  273 + if (data.code == 200) {
  274 + $(div).dialog("close");
  275 + $("#productRecommendListTable").myDatagrid("reload");
  276 + $.messager.show({
  277 + title: "提示",
  278 + msg: title + "成功!",
  279 + height: 120
  280 + });
  281 + } else {
  282 + $.messager.alert("失败", data.message, "error");
  283 + }
  284 + }
  285 + });
  286 + }
  287 + });
  288 + }
  289 + }, {
  290 + text: "关闭",
  291 + iconCls: "icon-cancel",
  292 + handler: function () {
  293 + $(div).dialog("close");
  294 + }
  295 + }]
  296 + });
  297 + }
  298 +
  299 + function del(id) {
  300 + var message = "确定要删除吗?";
  301 + var msg = "删除成功";
  302 + $.messager.confirm("确认", message, function (flag) {
  303 + if (flag) {
  304 + $.messager.progress({
  305 + title: "正在执行",
  306 + msg: "正在执行,请稍后...",
  307 + interval: 500,
  308 + text: ""
  309 + });
  310 + $.post(contextPath + "/productRecommend/deleteProductRecommendById", {
  311 + "id": id
  312 + }, function (data) {
  313 + $.messager.progress("close");
  314 + if (data.code == 200) {
  315 + $("#productRecommendListTable").myDatagrid("reload");
  316 + $.messager.show({
  317 + title: "提示",
  318 + msg: msg,
  319 + height: 120
  320 + });
  321 + } else {
  322 + $.messager.alert("失败", data.message, "error");
  323 + }
  324 + }, "json");
  325 + }
  326 + });
  327 + }
  328 +
  329 + });
  330 +
  331 +
  332 +</script>
  333 +
  334 +</body>
  335 +</html>