Authored by yangchangjiang

--task=null --user=杨长江 根据商品编号同步订单商品的图片地址和名称

1 package com.yoho.ufo.dal; 1 package com.yoho.ufo.dal;
2 2
3 import java.util.List; 3 import java.util.List;
  4 +import java.util.Map;
4 5
5 import org.apache.ibatis.annotations.Param; 6 import org.apache.ibatis.annotations.Param;
6 7
@@ -98,5 +99,5 @@ public interface ProductMapper { @@ -98,5 +99,5 @@ public interface ProductMapper {
98 @Param("start") int start, 99 @Param("start") int start,
99 @Param("rows") int rows); 100 @Param("rows") int rows);
100 101
101 - int syncOrderGoodsInfo(@Param("productCode") String productCode); 102 + int syncOrderGoodsInfo(Map<String,Object> param);
102 } 103 }
@@ -347,22 +347,18 @@ @@ -347,22 +347,18 @@
347 limit #{start}, #{rows} 347 limit #{start}, #{rows}
348 </select> 348 </select>
349 349
350 - <update id="syncOrderGoodsInfo" parameterType="string"> 350 + <update id="syncOrderGoodsInfo" parameterType="java.util.Map">
351 UPDATE 351 UPDATE
352 - ufo_product.goods g,  
353 - ufo_product.`storage` s,  
354 - ufo_order.seller_order_goods sog,  
355 - ufo_product.product p  
356 - SET  
357 - sog.image_url = g.color_image,  
358 - sog.product_name = p.product_name 352 + ufo_order.seller_order_goods sog
  353 + SET sog.image_url = #{imgUrl},
  354 + sog.product_name = #{productName}
359 WHERE 355 WHERE
360 - sog.storage_id = s.id  
361 - AND s.goods_id = g.id  
362 - AND p.id = g.product_id  
363 - AND sog.attributes NOT IN (5,6)  
364 - AND (g.color_image != sog.image_url OR p.product_name != sog.product_name)  
365 - AND p.product_code IN ( #{productCode} ) 356 + (sog.image_url != #{imgUrl} OR sog.product_name != #{productName} )
  357 + AND sog.attributes NOT IN ( 5, 6 )
  358 + AND sog.storage_id IN
  359 + <foreach collection="storages" close=")" open="(" item="item" separator=",">
  360 + #{item}
  361 + </foreach>
366 </update> 362 </update>
367 363
368 </mapper> 364 </mapper>
@@ -196,12 +196,12 @@ public class ProductController { @@ -196,12 +196,12 @@ public class ProductController {
196 196
197 197
198 /** 198 /**
199 - * 同步订单商品信息  
200 - * @param productCode 商品编码  
201 - * @return 影响行数 199 + * 同步订单商品信息(订单商品的名称和图片)
  200 + * @param productId 商品编码
  201 + * @return ApiResponse
202 */ 202 */
203 @RequestMapping(value = "/syncOrderGoodsInfo",method = RequestMethod.POST) 203 @RequestMapping(value = "/syncOrderGoodsInfo",method = RequestMethod.POST)
204 - public ApiResponse syncOrderGoodsInfo(String productCode){  
205 - return productService.syncOrderGoodsInfo(productCode); 204 + public ApiResponse syncOrderGoodsInfo(Integer productId){
  205 + return productService.syncOrderGoodsInfo(productId);
206 } 206 }
207 } 207 }
@@ -50,5 +50,5 @@ public interface IProductService { @@ -50,5 +50,5 @@ public interface IProductService {
50 50
51 Map<Integer, Integer> queryBatchProductStorageCount(List<Integer> productIdList); 51 Map<Integer, Integer> queryBatchProductStorageCount(List<Integer> productIdList);
52 52
53 - ApiResponse<Integer> syncOrderGoodsInfo(String productCode); 53 + ApiResponse<Integer> syncOrderGoodsInfo(Integer productId);
54 } 54 }
@@ -1462,11 +1462,42 @@ public class ProductServiceImpl implements IProductService, ApplicationContextAw @@ -1462,11 +1462,42 @@ public class ProductServiceImpl implements IProductService, ApplicationContextAw
1462 } 1462 }
1463 1463
1464 @Override 1464 @Override
1465 - public ApiResponse<Integer> syncOrderGoodsInfo(String productCode) {  
1466 - if(StringUtils.isEmpty(productCode)){ 1465 + public ApiResponse<Integer> syncOrderGoodsInfo(Integer productId) {
  1466 + if(productId == null){
1467 return new ApiResponse<>(400,"商品编号不能为空"); 1467 return new ApiResponse<>(400,"商品编号不能为空");
1468 } 1468 }
1469 - productMapper.syncOrderGoodsInfo(productCode); 1469 + //根据productId获取货品信息
  1470 + Product product = productMapper.selectByPrimaryKey(productId);
  1471 + if(Objects.isNull(product)){
  1472 + return new ApiResponse<>(400,"货品不存在");
  1473 + }
  1474 + //根据货品id获取商品
  1475 + List<Integer> productIds = new ArrayList<>(2);
  1476 + productIds.add(product.getId());
  1477 + List<Goods> goodsList = goodsMapper.selectByProductId(productIds);
  1478 + if(goodsList.isEmpty()){
  1479 + return new ApiResponse<>(400,"商品不存在");
  1480 + }
  1481 +
  1482 + Goods goods = goodsList.get(0);
  1483 +
  1484 + //根据goodsId获取仓库列表
  1485 + List<Storage> storageList = storageMapper.selectByGoodsId(goods.getId());
  1486 + if(storageList.isEmpty()){
  1487 + return new ApiResponse<>(400,"仓库不存在");
  1488 + }
  1489 +
  1490 + //仓库id集合
  1491 + List<Integer> storageIds = storageList.stream().map(Storage::getId).collect(Collectors.toList());
  1492 +
  1493 + //构造参数
  1494 + Map<String,Object> param = new HashMap<>(8);
  1495 + param.put("productName",product.getProductName());
  1496 + param.put("imgUrl",goods.getColorImage());
  1497 + param.put("storages",storageIds);
  1498 + int n = productMapper.syncOrderGoodsInfo(param);
  1499 +
  1500 + LOGGER.info("synchronize seller_order_goods image_url and product_name Affected rows----------->{}",n);
1470 return new ApiResponse<>(200,"同步成功"); 1501 return new ApiResponse<>(200,"同步成功");
1471 } 1502 }
1472 1503
@@ -24,7 +24,7 @@ @@ -24,7 +24,7 @@
24 } 24 }
25 </style> 25 </style>
26 <div style="margin-left: 30px;" class="div_search"> 26 <div style="margin-left: 30px;" class="div_search">
27 - <input id="productCode" type="text"/> 27 + <input id="productId" type="text"/>
28 28
29 <a id="syncButton" class="easyui-linkbutton btn-info" data-options="iconCls:'icon-search'">同步订单商品信息</a> 29 <a id="syncButton" class="easyui-linkbutton btn-info" data-options="iconCls:'icon-search'">同步订单商品信息</a>
30 </div> 30 </div>
@@ -32,11 +32,10 @@ @@ -32,11 +32,10 @@
32 32
33 <script type="text/javascript"> 33 <script type="text/javascript">
34 34
35 - var productPoolId;  
36 $(function () { 35 $(function () {
37 36
38 - $("#productCode").textbox({  
39 - prompt: "商品编号" 37 + $("#productId").textbox({
  38 + prompt: "货品编号"
40 }); 39 });
41 40
42 // 同步 41 // 同步
@@ -59,7 +58,7 @@ @@ -59,7 +58,7 @@
59 title : "提示", 58 title : "提示",
60 msg : result.message 59 msg : result.message
61 }); 60 });
62 - $("#productCode").val(''); 61 + $("#productId").val('');
63 }else { 62 }else {
64 window.self.$.messager.alert("失败", result.message, "error"); 63 window.self.$.messager.alert("失败", result.message, "error");
65 } 64 }
@@ -70,10 +69,10 @@ @@ -70,10 +69,10 @@
70 * 提取参数 69 * 提取参数
71 */ 70 */
72 function getParams() { 71 function getParams() {
73 - var productCode = $('#productCode').textbox('getValue'); 72 + var productId = $('#productId').textbox('getValue');
74 var param = {}; 73 var param = {};
75 - if (undefined !== productCode && null !== productCode && "" !== productCode) {  
76 - param.productCode = productCode; 74 + if (undefined !== productId && null !== productId && "" !== productId) {
  75 + param.productId = productId;
77 } 76 }
78 return param; 77 return param;
79 } 78 }