Authored by caoyan

自助上架货号优化

1 package com.yohoufo.dal.product; 1 package com.yohoufo.dal.product;
2 2
3 3
  4 +import java.util.List;
  5 +
4 import org.apache.ibatis.annotations.Param; 6 import org.apache.ibatis.annotations.Param;
5 7
6 import com.yohoufo.dal.product.model.ProductSelfShelves; 8 import com.yohoufo.dal.product.model.ProductSelfShelves;
@@ -8,5 +10,7 @@ import com.yohoufo.dal.product.model.ProductSelfShelves; @@ -8,5 +10,7 @@ import com.yohoufo.dal.product.model.ProductSelfShelves;
8 public interface ProductSelfShelvesMapper { 10 public interface ProductSelfShelvesMapper {
9 11
10 int insert(@Param("record")ProductSelfShelves record); 12 int insert(@Param("record")ProductSelfShelves record);
  13 +
  14 + List<ProductSelfShelves> selectByProductCode(@Param("productCode") String productCode);
11 15
12 } 16 }
@@ -147,4 +147,11 @@ @@ -147,4 +147,11 @@
147 update_time = #{updateTime,jdbcType=INTEGER} 147 update_time = #{updateTime,jdbcType=INTEGER}
148 where id = #{id,jdbcType=INTEGER} 148 where id = #{id,jdbcType=INTEGER}
149 </update> 149 </update>
  150 +
  151 + <select id="selectByProductCode" resultMap="BaseResultMap" parameterType="java.lang.String" >
  152 + select
  153 + <include refid="Base_Column_List" />
  154 + from product_self_shelves
  155 + where product_code = #{productCode,jdbcType=VARCHAR}
  156 + </select>
150 </mapper> 157 </mapper>
@@ -12,7 +12,9 @@ import org.springframework.web.bind.annotation.RequestParam; @@ -12,7 +12,9 @@ import org.springframework.web.bind.annotation.RequestParam;
12 import org.springframework.web.bind.annotation.ResponseBody; 12 import org.springframework.web.bind.annotation.ResponseBody;
13 import org.springframework.web.bind.annotation.RestController; 13 import org.springframework.web.bind.annotation.RestController;
14 14
  15 +import com.yoho.error.exception.ServiceException;
15 import com.yohoufo.common.ApiResponse; 16 import com.yohoufo.common.ApiResponse;
  17 +import com.yohoufo.dal.product.ProductSelfShelvesMapper;
16 import com.yohoufo.dal.product.model.ProductSelfShelves; 18 import com.yohoufo.dal.product.model.ProductSelfShelves;
17 import com.yohoufo.product.service.SelfShelvesService; 19 import com.yohoufo.product.service.SelfShelvesService;
18 20
@@ -23,6 +25,8 @@ public class SelfShelvesController { @@ -23,6 +25,8 @@ public class SelfShelvesController {
23 25
24 @Autowired 26 @Autowired
25 private SelfShelvesService selfShelvesService; 27 private SelfShelvesService selfShelvesService;
  28 + @Autowired
  29 + private ProductSelfShelvesMapper productSelfShelvesMapper;
26 30
27 @RequestMapping(params = "method=ufo.selfShelves.save") 31 @RequestMapping(params = "method=ufo.selfShelves.save")
28 @ResponseBody 32 @ResponseBody
@@ -42,6 +46,12 @@ public class SelfShelvesController { @@ -42,6 +46,12 @@ public class SelfShelvesController {
42 if(null == uid || 0 == uid.intValue()) { 46 if(null == uid || 0 == uid.intValue()) {
43 return new ApiResponse.ApiResponseBuilder().code(401).message("uid为空,请登录").build(); 47 return new ApiResponse.ApiResponseBuilder().code(401).message("uid为空,请登录").build();
44 } 48 }
  49 + //校验货号是否已存在
  50 + List<ProductSelfShelves> list = productSelfShelvesMapper.selectByProductCode(productCode);
  51 + if(CollectionUtils.isNotEmpty(list)) {
  52 + return new ApiResponse.ApiResponseBuilder().code(500).message("商品货号信息已存在,您可以直接通过搜索功能查询货号找到商品后进行出售").build();
  53 + }
  54 +
45 ProductSelfShelves pss = new ProductSelfShelves(); 55 ProductSelfShelves pss = new ProductSelfShelves();
46 pss.setUid(uid); 56 pss.setUid(uid);
47 pss.setBrand(brand); 57 pss.setBrand(brand);