Authored by caoyan

商品池增加排序值

1 package com.yoho.ufo.dal; 1 package com.yoho.ufo.dal;
2 2
3 -import com.yoho.ufo.model.goodsmanage.ProductPool;  
4 -import com.yoho.ufo.model.goodsmanage.ProductPoolDetails;  
5 -import com.yohobuy.ufo.model.common.PageModel; 3 +import java.util.List;
  4 +
6 import org.apache.ibatis.annotations.Param; 5 import org.apache.ibatis.annotations.Param;
7 6
8 -import java.util.List; 7 +import com.yoho.ufo.model.goodsmanage.ProductPoolDetails;
9 8
10 /** 9 /**
11 * 商品池详情mapper 10 * 商品池详情mapper
@@ -38,4 +37,16 @@ public interface UfoProductPoolDetailMapper { @@ -38,4 +37,16 @@ public interface UfoProductPoolDetailMapper {
38 * @return 37 * @return
39 */ 38 */
40 int deleteProductPoolDetail(@Param("productPoolId") Integer productPoolId, @Param("productId") Integer productId); 39 int deleteProductPoolDetail(@Param("productPoolId") Integer productPoolId, @Param("productId") Integer productId);
  40 +
  41 + /**
  42 + * 根据条件查询数据
  43 + * @param poolId
  44 + * @param productId
  45 + * @return
  46 + */
  47 + List<ProductPoolDetails> selectByPoolIdAndProductId(@Param("poolId") Integer poolId, @Param("productId") Integer productId);
  48 +
  49 + List<ProductPoolDetails> selectByPoolIdAndOrderBy(@Param("poolId") Integer poolId, @Param("orderBy") Integer orderBy);
  50 +
  51 + int updateProductOrderBy(@Param("poolId") Integer poolId, @Param("productId") Integer productId, @Param("orderBy") int orderBy);
41 } 52 }
@@ -57,6 +57,8 @@ public class ProductDetails implements Serializable { @@ -57,6 +57,8 @@ public class ProductDetails implements Serializable {
57 * 1:已删除 57 * 1:已删除
58 */ 58 */
59 private Integer delStatus; 59 private Integer delStatus;
  60 +
  61 + private Integer orderBy;
60 62
61 public Integer getId() { 63 public Integer getId() {
62 return id; 64 return id;
@@ -130,8 +132,15 @@ public class ProductDetails implements Serializable { @@ -130,8 +132,15 @@ public class ProductDetails implements Serializable {
130 this.delStatus = delStatus; 132 this.delStatus = delStatus;
131 } 133 }
132 134
  135 + public Integer getOrderBy() {
  136 + return orderBy;
  137 + }
133 138
134 - @Override 139 + public void setOrderBy(Integer orderBy) {
  140 + this.orderBy = orderBy;
  141 + }
  142 +
  143 + @Override
135 public String toString() { 144 public String toString() {
136 return "ProductDetails{" + 145 return "ProductDetails{" +
137 "id=" + id + 146 "id=" + id +
@@ -143,6 +152,7 @@ public class ProductDetails implements Serializable { @@ -143,6 +152,7 @@ public class ProductDetails implements Serializable {
143 ", brandName='" + brandName + '\'' + 152 ", brandName='" + brandName + '\'' +
144 ", sortName='" + sortName + '\'' + 153 ", sortName='" + sortName + '\'' +
145 ", delStatus=" + delStatus + 154 ", delStatus=" + delStatus +
  155 + ", orderBy=" + orderBy +
146 '}'; 156 '}';
147 } 157 }
148 } 158 }
1 package com.yoho.ufo.model.goodsmanage; 1 package com.yoho.ufo.model.goodsmanage;
2 2
3 -import com.yoho.ufo.annotation.BatchImportField;  
4 -  
5 import java.io.Serializable; 3 import java.io.Serializable;
6 4
  5 +import com.yoho.ufo.annotation.BatchImportField;
  6 +
7 /** 7 /**
8 * 商品池详情 8 * 商品池详情
9 * @author kun.wang 9 * @author kun.wang
@@ -51,6 +51,12 @@ public class ProductPoolDetails implements Serializable { @@ -51,6 +51,12 @@ public class ProductPoolDetails implements Serializable {
51 * 分类 51 * 分类
52 */ 52 */
53 private String sortName; 53 private String sortName;
  54 +
  55 + /**
  56 + * 排序值
  57 + */
  58 + @BatchImportField(index = 1)
  59 + private Integer orderBy;
54 60
55 public Integer getId() { 61 public Integer getId() {
56 return id; 62 return id;
@@ -116,8 +122,15 @@ public class ProductPoolDetails implements Serializable { @@ -116,8 +122,15 @@ public class ProductPoolDetails implements Serializable {
116 this.sortName = sortName; 122 this.sortName = sortName;
117 } 123 }
118 124
  125 + public Integer getOrderBy() {
  126 + return orderBy;
  127 + }
  128 +
  129 + public void setOrderBy(Integer orderBy) {
  130 + this.orderBy = orderBy;
  131 + }
119 132
120 - @Override 133 + @Override
121 public String toString() { 134 public String toString() {
122 return "ProductPoolDetails{" + 135 return "ProductPoolDetails{" +
123 "id=" + id + 136 "id=" + id +
@@ -128,6 +141,7 @@ public class ProductPoolDetails implements Serializable { @@ -128,6 +141,7 @@ public class ProductPoolDetails implements Serializable {
128 ", productName='" + productName + '\'' + 141 ", productName='" + productName + '\'' +
129 ", brandName='" + brandName + '\'' + 142 ", brandName='" + brandName + '\'' +
130 ", sortName='" + sortName + '\'' + 143 ", sortName='" + sortName + '\'' +
  144 + ", orderBy='" + orderBy + '\'' +
131 '}'; 145 '}';
132 } 146 }
133 } 147 }
@@ -6,7 +6,8 @@ @@ -6,7 +6,8 @@
6 </resultMap> 6 </resultMap>
7 7
8 <sql id="queryColumns"> 8 <sql id="queryColumns">
9 - product.id, product.product_code, product.product_name, product.product_code, brand.brand_name, CONCAT(IFNULL(CONCAT(sort2.sort_name,'/'),''),sort1.sort_name) AS sortName, product.del_status 9 + product.id, product.product_code, product.product_name, product.product_code, brand.brand_name,
  10 + CONCAT(IFNULL(CONCAT(sort2.sort_name,'/'),''),sort1.sort_name) AS sortName, product.del_status, pool_detail.order_by
10 </sql> 11 </sql>
11 12
12 <select id="queryProductIdsByProductIds" parameterType="java.util.Set" resultType="integer"> 13 <select id="queryProductIdsByProductIds" parameterType="java.util.Set" resultType="integer">
@@ -59,7 +60,8 @@ @@ -59,7 +60,8 @@
59 <select id="getProductDetailsPageList" resultMap="productDetails"> 60 <select id="getProductDetailsPageList" resultMap="productDetails">
60 select <include refid="queryColumns"/> 61 select <include refid="queryColumns"/>
61 <include refid="queryTable"/> 62 <include refid="queryTable"/>
62 - <include refid="queryParam"/> 63 + <include refid="queryParam"/>
  64 + order by pool_detail.order_by desc
63 limit #{page.startIndex}, #{page.pageSize} 65 limit #{page.startIndex}, #{page.pageSize}
64 </select> 66 </select>
65 67
1 <?xml version="1.0" encoding="UTF-8" ?> 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" > 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.UfoProductPoolDetailMapper"> 3 <mapper namespace="com.yoho.ufo.dal.UfoProductPoolDetailMapper">
4 -  
5 - <resultMap id="productPoolDetails" type="com.yoho.ufo.model.goodsmanage.ProductPoolDetails"> 4 + <resultMap id="BaseResultMap" type="com.yoho.ufo.model.goodsmanage.ProductPoolDetails">
  5 + <result column="id" property="id" jdbcType="INTEGER" />
  6 + <result column="pool_id" property="poolId" jdbcType="INTEGER" />
  7 + <result column="product_id" property="productId" jdbcType="INTEGER" />
  8 + <result column="create_time" property="createTime" jdbcType="INTEGER" />
  9 + <result column="order_by" property="orderBy" jdbcType="INTEGER" />
6 </resultMap> 10 </resultMap>
7 11
8 - <sql id="queryColumns">  
9 - product.id, product.product_code, product.product_name, product.product_code, brand.brand_name, product_sort.sort_name 12 + <sql id="Base_Column_List">
  13 + id, pool_id, product_id, create_time, order_by
10 </sql> 14 </sql>
11 15
12 -  
13 -  
14 <insert id="batchInsertProductPoolDetails" parameterType="list"> 16 <insert id="batchInsertProductPoolDetails" parameterType="list">
15 - insert into product_pool_detail(pool_id, product_id, create_time) values 17 + insert into product_pool_detail(pool_id, product_id, create_time, order_by) values
16 <foreach collection="list" item="item" separator="," index="index"> 18 <foreach collection="list" item="item" separator="," index="index">
17 - (#{item.poolId}, #{item.productId}, #{item.createTime}) 19 + (#{item.poolId}, #{item.productId}, #{item.createTime}, #{item.order_by})
18 </foreach> 20 </foreach>
19 </insert> 21 </insert>
20 22
@@ -25,4 +27,31 @@ @@ -25,4 +27,31 @@
25 <delete id="deleteProductPoolDetail"> 27 <delete id="deleteProductPoolDetail">
26 DELETE FROM product_pool_detail WHERE pool_id = #{productPoolId} AND product_id = #{productId} 28 DELETE FROM product_pool_detail WHERE pool_id = #{productPoolId} AND product_id = #{productId}
27 </delete> 29 </delete>
  30 +
  31 + <select id="selectByPoolIdAndProductId" resultMap="BaseResultMap">
  32 + select <include refid="Base_Column_List" />
  33 + from product_pool_detail where 1=1
  34 + <if test="poolId != null">
  35 + and pool_id = #{poolId}
  36 + </if>
  37 + <if test="productId != null">
  38 + and product_id = #{productId}
  39 + </if>
  40 + </select>
  41 +
  42 + <select id="selectByPoolIdAndOrderBy" resultMap="BaseResultMap">
  43 + select <include refid="Base_Column_List" />
  44 + from product_pool_detail where 1=1
  45 + <if test="poolId != null">
  46 + and pool_id = #{poolId}
  47 + </if>
  48 + <if test="orderBy != null">
  49 + and order_by = #{orderBy}
  50 + </if>
  51 + </select>
  52 +
  53 + <update id="updateProductOrderBy">
  54 + update product_pool_detail set order_by=#{orderBy} where pool_id=#{poolId} and product_id=#{productId}
  55 + </update>
  56 +
28 </mapper> 57 </mapper>
1 package com.yoho.ufo.controller.productpool; 1 package com.yoho.ufo.controller.productpool;
2 2
  3 +import com.yoho.ufo.exception.PlatformException;
3 import com.yoho.ufo.service.IProductPoolDetailsService; 4 import com.yoho.ufo.service.IProductPoolDetailsService;
4 import com.yohobuy.ufo.model.common.ApiResponse; 5 import com.yohobuy.ufo.model.common.ApiResponse;
5 import com.yohobuy.ufo.model.common.PageResponseBO; 6 import com.yohobuy.ufo.model.common.PageResponseBO;
@@ -46,4 +47,38 @@ public class ProductPoolDetailsController { @@ -46,4 +47,38 @@ public class ProductPoolDetailsController {
46 LOGGER.info("getProductPoolDetailsPageList param = {}", productPoolDetailsRequestBo); 47 LOGGER.info("getProductPoolDetailsPageList param = {}", productPoolDetailsRequestBo);
47 return new ApiResponse<>(productPoolDetailsService.getProductPoolDetailsPageList(productPoolDetailsRequestBo)); 48 return new ApiResponse<>(productPoolDetailsService.getProductPoolDetailsPageList(productPoolDetailsRequestBo));
48 } 49 }
  50 +
  51 + @RequestMapping(value = "/saveProduct", method = RequestMethod.POST)
  52 + public ApiResponse<Void> saveProduct(ProductPoolDetailsRequestBo productPoolDetailsRequestBo) {
  53 + LOGGER.info("saveProduct param = {}", productPoolDetailsRequestBo);
  54 + int result =0;
  55 + try {
  56 + result= productPoolDetailsService.saveProduct(productPoolDetailsRequestBo);
  57 + } catch (PlatformException px) {
  58 + LOGGER.warn("saveProduct PlatformException.param = {}, errorMsg = {}", productPoolDetailsRequestBo, px.getMessage());
  59 + return new ApiResponse<>(400, px.getMessage(), null);
  60 + }
  61 +
  62 + if(result == 0) {
  63 + return new ApiResponse<>(500, "添加失败!", null);
  64 + }
  65 + return new ApiResponse<>();
  66 + }
  67 +
  68 + @RequestMapping(value = "/updateProductOrderBy", method = RequestMethod.POST)
  69 + public ApiResponse<Void> updateProductOrderBy(ProductPoolDetailsRequestBo productPoolDetailsRequestBo) {
  70 + LOGGER.info("updateProductOrderBy param = {}", productPoolDetailsRequestBo);
  71 + int result =0;
  72 + try {
  73 + result= productPoolDetailsService.updateProductOrderBy(productPoolDetailsRequestBo);
  74 + } catch (PlatformException px) {
  75 + LOGGER.warn("saveProduct PlatformException.param = {}, errorMsg = {}", productPoolDetailsRequestBo, px.getMessage());
  76 + return new ApiResponse<>(400, px.getMessage(), null);
  77 + }
  78 +
  79 + if(result == 0) {
  80 + return new ApiResponse<>(500, "更新失败!", null);
  81 + }
  82 + return new ApiResponse<>();
  83 + }
49 } 84 }
1 package com.yoho.ufo.service; 1 package com.yoho.ufo.service;
2 2
  3 +import com.yoho.ufo.exception.PlatformException;
3 import com.yohobuy.ufo.model.common.PageResponseBO; 4 import com.yohobuy.ufo.model.common.PageResponseBO;
4 import com.yohobuy.ufo.model.request.productpool.ProductPoolDetailsRequestBo; 5 import com.yohobuy.ufo.model.request.productpool.ProductPoolDetailsRequestBo;
5 import com.yohobuy.ufo.model.request.productpool.ProductPoolDetailsResponseBo; 6 import com.yohobuy.ufo.model.request.productpool.ProductPoolDetailsResponseBo;
@@ -28,5 +29,21 @@ public interface IProductPoolDetailsService { @@ -28,5 +29,21 @@ public interface IProductPoolDetailsService {
28 * @return 29 * @return
29 */ 30 */
30 int deleteProductById(Integer id, Integer productPoolId); 31 int deleteProductById(Integer id, Integer productPoolId);
  32 +
  33 + /**
  34 + * 添加商品
  35 + * @param requestBo
  36 + * @return
  37 + * @throws PlatformException
  38 + */
  39 + int saveProduct(ProductPoolDetailsRequestBo requestBo) throws PlatformException;
  40 +
  41 + /**
  42 + * 更新排序值
  43 + * @param requestBo
  44 + * @return
  45 + * @throws PlatformException
  46 + */
  47 + int updateProductOrderBy(ProductPoolDetailsRequestBo requestBo) throws PlatformException;
31 48
32 } 49 }
1 package com.yoho.ufo.service.impl; 1 package com.yoho.ufo.service.impl;
2 2
  3 +import com.google.common.collect.Lists;
3 import com.google.common.collect.Sets; 4 import com.google.common.collect.Sets;
4 import com.yoho.ufo.dal.UfoProductDetailsMapper; 5 import com.yoho.ufo.dal.UfoProductDetailsMapper;
5 import com.yoho.ufo.dal.UfoProductPoolDetailMapper; 6 import com.yoho.ufo.dal.UfoProductPoolDetailMapper;
@@ -52,16 +53,25 @@ public class GoodsPoolImportServiceImpl implements IBusinessImportService { @@ -52,16 +53,25 @@ public class GoodsPoolImportServiceImpl implements IBusinessImportService {
52 53
53 // 重复的商品id集合 54 // 重复的商品id集合
54 List<String> repeatProductIds = new ArrayList<>(); 55 List<String> repeatProductIds = new ArrayList<>();
  56 +
  57 + //重复的排序值orderByNum集合
  58 + List<String> repeatOrderByProductIds = Lists.newArrayList();
55 59
56 // 导入的商品id 60 // 导入的商品id
57 List<Integer> importProductIds = new ArrayList<>(); 61 List<Integer> importProductIds = new ArrayList<>();
  62 + //导入的商品排序值orderBy
  63 + List<Integer> importOrderBys = Lists.newArrayList();
58 for (int i = 0; i < dataList.size(); i++) { 64 for (int i = 0; i < dataList.size(); i++) {
59 ProductPoolDetails productPoolDetails = (ProductPoolDetails) dataList.get(i); 65 ProductPoolDetails productPoolDetails = (ProductPoolDetails) dataList.get(i);
60 // 商品id 66 // 商品id
61 Integer productId = productPoolDetails.getProductId(); 67 Integer productId = productPoolDetails.getProductId();
  68 + Integer orderBy = productPoolDetails.getOrderBy();
62 if (importProductIds.contains(productId)) { 69 if (importProductIds.contains(productId)) {
63 repeatProductIds.add(String.valueOf(productId)); 70 repeatProductIds.add(String.valueOf(productId));
64 } 71 }
  72 + if(importOrderBys.contains(orderBy)) {
  73 + repeatOrderByProductIds.add(String.valueOf(productId));
  74 + }
65 // 商品池id 75 // 商品池id
66 productPoolDetails.setPoolId(poolId); 76 productPoolDetails.setPoolId(poolId);
67 productPoolDetails.setCreateTime(DateUtil.getCurrentTimeSeconds()); 77 productPoolDetails.setCreateTime(DateUtil.getCurrentTimeSeconds());
@@ -72,6 +82,10 @@ public class GoodsPoolImportServiceImpl implements IBusinessImportService { @@ -72,6 +82,10 @@ public class GoodsPoolImportServiceImpl implements IBusinessImportService {
72 if (CollectionUtils.isNotEmpty(repeatProductIds)) { 82 if (CollectionUtils.isNotEmpty(repeatProductIds)) {
73 return "上传失败!商品编码" + String.join("、 ", repeatProductIds) + "重复,请修改后重新上传!"; 83 return "上传失败!商品编码" + String.join("、 ", repeatProductIds) + "重复,请修改后重新上传!";
74 } 84 }
  85 +
  86 + if (CollectionUtils.isNotEmpty(repeatOrderByProductIds)) {
  87 + return "上传失败!商品编码" + String.join("、 ", repeatOrderByProductIds) + "排序值重复,请修改后重新上传!";
  88 + }
75 89
76 // 每次查询数量 90 // 每次查询数量
77 Integer queryCount = 100; 91 Integer queryCount = 100;
1 package com.yoho.ufo.service.impl; 1 package com.yoho.ufo.service.impl;
2 2
  3 +import java.util.List;
  4 +
  5 +import org.apache.commons.collections.CollectionUtils;
  6 +import org.slf4j.Logger;
  7 +import org.slf4j.LoggerFactory;
  8 +import org.springframework.beans.factory.annotation.Autowired;
  9 +import org.springframework.stereotype.Service;
  10 +
  11 +import com.google.common.collect.Lists;
  12 +import com.yoho.core.common.utils.DateUtil;
3 import com.yoho.ufo.dal.UfoProductDetailsMapper; 13 import com.yoho.ufo.dal.UfoProductDetailsMapper;
4 import com.yoho.ufo.dal.UfoProductPoolDetailMapper; 14 import com.yoho.ufo.dal.UfoProductPoolDetailMapper;
  15 +import com.yoho.ufo.dal.UfoProductPoolMapper;
  16 +import com.yoho.ufo.exception.PlatformException;
5 import com.yoho.ufo.model.goodsmanage.ProductDetails; 17 import com.yoho.ufo.model.goodsmanage.ProductDetails;
  18 +import com.yoho.ufo.model.goodsmanage.ProductPool;
  19 +import com.yoho.ufo.model.goodsmanage.ProductPoolDetails;
6 import com.yoho.ufo.service.IProductPoolDetailsService; 20 import com.yoho.ufo.service.IProductPoolDetailsService;
7 import com.yoho.ufo.util.OrikaUtils; 21 import com.yoho.ufo.util.OrikaUtils;
8 import com.yohobuy.ufo.model.common.PageModel; 22 import com.yohobuy.ufo.model.common.PageModel;
9 import com.yohobuy.ufo.model.common.PageResponseBO; 23 import com.yohobuy.ufo.model.common.PageResponseBO;
10 import com.yohobuy.ufo.model.request.productpool.ProductPoolDetailsRequestBo; 24 import com.yohobuy.ufo.model.request.productpool.ProductPoolDetailsRequestBo;
11 import com.yohobuy.ufo.model.request.productpool.ProductPoolDetailsResponseBo; 25 import com.yohobuy.ufo.model.request.productpool.ProductPoolDetailsResponseBo;
12 -import org.slf4j.Logger;  
13 -import org.slf4j.LoggerFactory;  
14 -import org.springframework.beans.factory.annotation.Autowired;  
15 -import org.springframework.stereotype.Service;  
16 -  
17 -import java.util.List;  
18 26
19 /** 27 /**
20 * 商品池详情管理 28 * 商品池详情管理
@@ -32,6 +40,9 @@ public class ProductPoolDetailsServiceImpl implements IProductPoolDetailsService @@ -32,6 +40,9 @@ public class ProductPoolDetailsServiceImpl implements IProductPoolDetailsService
32 40
33 @Autowired 41 @Autowired
34 private UfoProductDetailsMapper ufoProductDetailsMapper; 42 private UfoProductDetailsMapper ufoProductDetailsMapper;
  43 +
  44 + @Autowired
  45 + private UfoProductPoolMapper ufoProductPoolMapper;
35 46
36 @Override 47 @Override
37 public PageResponseBO<ProductPoolDetailsResponseBo> getProductPoolDetailsPageList(ProductPoolDetailsRequestBo productPoolDetailsRequestBo) { 48 public PageResponseBO<ProductPoolDetailsResponseBo> getProductPoolDetailsPageList(ProductPoolDetailsRequestBo productPoolDetailsRequestBo) {
@@ -53,4 +64,61 @@ public class ProductPoolDetailsServiceImpl implements IProductPoolDetailsService @@ -53,4 +64,61 @@ public class ProductPoolDetailsServiceImpl implements IProductPoolDetailsService
53 LOGGER.info("deleteProductById productId = {}, productPoolId = {}", productId, productPoolId); 64 LOGGER.info("deleteProductById productId = {}, productPoolId = {}", productId, productPoolId);
54 return ufoProductPoolDetailMapper.deleteProductPoolDetail(productPoolId, productId); 65 return ufoProductPoolDetailMapper.deleteProductPoolDetail(productPoolId, productId);
55 } 66 }
  67 +
  68 + @Override
  69 + public int saveProduct(ProductPoolDetailsRequestBo requestBo) throws PlatformException {
  70 + //校验
  71 + if(null == requestBo) {
  72 + return 0;
  73 + }
  74 + checkParam(requestBo);
  75 +
  76 + //插入数据库
  77 + ProductPoolDetails product = new ProductPoolDetails();
  78 + product.setPoolId(requestBo.getPoolId());
  79 + product.setProductId(requestBo.getProductId());
  80 + product.setOrderBy(requestBo.getOrderBy());
  81 + product.setCreateTime(DateUtil.getCurrentTimeSecond());
  82 + List<ProductPoolDetails> productList = Lists.newArrayList(product);
  83 + return ufoProductPoolDetailMapper.batchInsertProductPoolDetails(productList);
  84 + }
  85 +
  86 + @Override
  87 + public int updateProductOrderBy(ProductPoolDetailsRequestBo requestBo) throws PlatformException {
  88 + //校验
  89 + if(null == requestBo || null == requestBo.getPoolId() || null == requestBo.getProductId()) {
  90 + return 0;
  91 + }
  92 +
  93 + //查询是否已存在
  94 + List<ProductPoolDetails> productList = ufoProductPoolDetailMapper.selectByPoolIdAndOrderBy(requestBo.getPoolId(), requestBo.getOrderBy());
  95 + if(CollectionUtils.isNotEmpty(productList)) {
  96 + throw new PlatformException("该排序值在商品池中已存在!", 400);
  97 + }
  98 +
  99 + //更新记录
  100 + return ufoProductPoolDetailMapper.updateProductOrderBy(requestBo.getPoolId(), requestBo.getProductId(), requestBo.getOrderBy());
  101 + }
  102 +
  103 + private void checkParam(ProductPoolDetailsRequestBo requestBo) throws PlatformException{
  104 + Integer poolId = requestBo.getPoolId();
  105 + Integer productId = requestBo.getProductId();
  106 + Integer orderByNum = requestBo.getOrderBy();
  107 + //判断商品池是否存在
  108 + ProductPool pool = ufoProductPoolMapper.selectOneById(poolId);
  109 + if(null == pool) {
  110 + throw new PlatformException("添加失败!商品池不存在!", 400);
  111 + }
  112 +
  113 + //判断商品是否存在
  114 + List<ProductPoolDetails> productList = ufoProductPoolDetailMapper.selectByPoolIdAndProductId(poolId, productId);
  115 + if(CollectionUtils.isNotEmpty(productList)) {
  116 + throw new PlatformException("添加失败!商品池中该商品已存在!", 400);
  117 + }
  118 +
  119 + productList = ufoProductPoolDetailMapper.selectByPoolIdAndOrderBy(poolId, orderByNum);
  120 + if(CollectionUtils.isNotEmpty(productList)) {
  121 + throw new PlatformException("添加失败!商品池中该排序值已存在!", 400);
  122 + }
  123 + }
56 } 124 }
  1 +<!DOCTYPE html>
  2 +<html lang="en">
  3 +<head>
  4 + <title>main</title>
  5 + <script src="/ufoPlatform/js/include.js"></script>
  6 +</head>
  7 +<body class="easyui-layout" fit="true">
  8 +
  9 +<div id="addDiv" region="center">
  10 + <div style="margin-left: 30px; margin-top: 20px;" >
  11 + <label>商品编码:</label><input type="text" id="productId" style="width:150px"/>
  12 + <label>排序值:</label><input type="text" id="orderBy" style="width:70px"/>
  13 + </div>
  14 +</div>
  15 +<script>
  16 + $(function () {
  17 + $("#productId").textbox({
  18 + prompt: "请输入"
  19 + });
  20 +
  21 + $("#orderBy").textbox({
  22 + prompt: "请输入"
  23 + });
  24 + });
  25 +
  26 +</script>
  27 +</body>
  28 +</html>
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 <script src="/ufoPlatform/js/ajaxfileupload.js"></script> 7 <script src="/ufoPlatform/js/ajaxfileupload.js"></script>
8 </head> 8 </head>
9 <body class="easyui-layout" fit="true"> 9 <body class="easyui-layout" fit="true">
10 -<div region="north" style="height: 230px"> 10 +<div region="north" style="height: 150px">
11 <script> 11 <script>
12 document.write(addHead('商品池详情', '')); 12 document.write(addHead('商品池详情', ''));
13 </script> 13 </script>
@@ -33,6 +33,7 @@ @@ -33,6 +33,7 @@
33 <a id="searchLinkButton" class="easyui-linkbutton btn-info" data-options="iconCls:'icon-search'">筛选</a> 33 <a id="searchLinkButton" class="easyui-linkbutton btn-info" data-options="iconCls:'icon-search'">筛选</a>
34 <a id="searchAllLinkButton" class="easyui-linkbutton btn-info" data-options="iconCls:'icon-search'">全部</a> 34 <a id="searchAllLinkButton" class="easyui-linkbutton btn-info" data-options="iconCls:'icon-search'">全部</a>
35 <a id="returnList" class="easyui-linkbutton btn-info" data-options="iconCls:'icon-search'">返回列表</a> 35 <a id="returnList" class="easyui-linkbutton btn-info" data-options="iconCls:'icon-search'">返回列表</a>
  36 + <a id="addProduct" class="easyui-linkbutton btn-info" data-options="iconCls:'icon-add'">添加商品</a>
36 </div> 37 </div>
37 </div> 38 </div>
38 <div region="center"> 39 <div region="center">
@@ -66,7 +67,14 @@ @@ -66,7 +67,14 @@
66 location.href = contextPath + "/html/commodityManage/commodityPoolManage/commodityPoolManage.html"; 67 location.href = contextPath + "/html/commodityManage/commodityPoolManage/commodityPoolManage.html";
67 } 68 }
68 }); 69 });
  70 +
69 var poolId = parseURL(window.location.href).poolId; 71 var poolId = parseURL(window.location.href).poolId;
  72 + $('#addProduct').linkbutton({
  73 + onClick: function () {
  74 + addPage(poolId);
  75 + }
  76 + });
  77 +
70 78
71 $("#id").textbox({ 79 $("#id").textbox({
72 prompt: "商品编码" 80 prompt: "商品编码"
@@ -120,6 +128,14 @@ @@ -120,6 +128,14 @@
120 width: 170, 128 width: 170,
121 align: "center" 129 align: "center"
122 }, { 130 }, {
  131 + title: "商品排序",
  132 + field: "orderBy",
  133 + width: 100,
  134 + align: "center",
  135 + formatter: function (value, rowData) {
  136 + return "<input type='text' value=" + value + " style='width:80px;text-align:center' onblur='updateOrderBy(" + rowData.id + "," + "this.value)'>";
  137 + }
  138 + }, {
123 title: "操作", 139 title: "操作",
124 field: "operations", 140 field: "operations",
125 width: 80, 141 width: 80,
@@ -175,8 +191,7 @@ @@ -175,8 +191,7 @@
175 } 191 }
176 }); 192 });
177 } 193 }
178 -  
179 - 194 +
180 /** 195 /**
181 * 提取出搜索参数 196 * 提取出搜索参数
182 */ 197 */
@@ -220,7 +235,102 @@ @@ -220,7 +235,102 @@
220 $("#productPoolDetailsTable").myDatagrid("load", param); 235 $("#productPoolDetailsTable").myDatagrid("load", param);
221 } 236 }
222 }); 237 });
  238 +
223 }); 239 });
  240 +
  241 + function addPage(poolId) {
  242 + var div = $("<div id='addDiv'>").appendTo($(document.body));
  243 + var url = contextPath + "/html/commodityManage/commodityPoolManage/addProduct.html";
  244 + $(div).myDialog({
  245 + width: "40%",
  246 + height: "30%",
  247 + title: "添加商品",
  248 + href: url,
  249 + modal: true,
  250 + collapsible: true,
  251 + cache: false,
  252 + buttons: [{
  253 + text: "取消",
  254 + iconCls: "icon-cancel",
  255 + handler: function () {
  256 + $(div).dialog("close");
  257 + }
  258 + },{
  259 + text: "确认",
  260 + id: "saveBtn",
  261 + iconCls: "icon-save",
  262 + onClick: function () {
  263 + saveProduct(poolId);
  264 + }
  265 + }]
  266 + });
  267 + }
  268 +
  269 + function saveProduct(poolId){
  270 + var productId = $("#productId").textbox("getValue");
  271 + var orderBy = $("#orderBy").textbox("getValue");
  272 + if(productId==''){
  273 + alert("商品编码不能为空!");
  274 + return;
  275 + }
  276 + if(orderBy==''){
  277 + alert("排序值不能为空!");
  278 + return;
  279 + }
  280 + if(!isIntNum(productId)){
  281 + alert("商品编码必须是全数字!")
  282 + return;
  283 + }
  284 + if(!isIntNum(orderBy)){
  285 + alert("排序值必须是全数字!")
  286 + return;
  287 + }
  288 + $.post(contextPath + "/productPoolDetails/saveProduct", {
  289 + poolId : poolId,
  290 + productId : productId,
  291 + orderBy : orderBy
  292 + }, function(data) {
  293 + if (data.code == 200) {
  294 + $("#addDiv").dialog("close");
  295 + $("#productPoolDetailsTable").datagrid("reload");
  296 + window.self.$.messager.show({
  297 + title : "提示",
  298 + msg : "添加商品成功!"
  299 + });
  300 + }else {
  301 + window.self.$.messager.alert("失败", data.message, "error");
  302 + }
  303 + });
  304 +
  305 + }
  306 +
  307 + function isIntNum(val){
  308 + var regPos = /^\d+$/; // 非负整数
  309 + if(regPos.test(val)){
  310 + return true;
  311 + }else{
  312 + return false;
  313 + }
  314 + }
  315 +
  316 + function updateOrderBy(productId, orderBy){
  317 + var poolId = parseURL(window.location.href).poolId;
  318 + $.post(contextPath + "/productPoolDetails/updateProductOrderBy", {
  319 + poolId : poolId,
  320 + productId : productId,
  321 + orderBy : orderBy
  322 + }, function(data) {
  323 + if (data.code == 200) {
  324 + $("#productPoolDetailsTable").datagrid("reload");
  325 + window.self.$.messager.show({
  326 + title : "提示",
  327 + msg : "更新排序值成功!"
  328 + });
  329 + }else {
  330 + window.self.$.messager.alert("失败", data.message, "error");
  331 + }
  332 + });
  333 + }
224 334
225 </script> 335 </script>
226 336