Authored by yangchangjiang

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

package com.yoho.ufo.dal;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Param;
... ... @@ -98,5 +99,5 @@ public interface ProductMapper {
@Param("start") int start,
@Param("rows") int rows);
int syncOrderGoodsInfo(@Param("productCode") String productCode);
int syncOrderGoodsInfo(Map<String,Object> param);
}
\ No newline at end of file
... ...
... ... @@ -347,22 +347,18 @@
limit #{start}, #{rows}
</select>
<update id="syncOrderGoodsInfo" parameterType="string">
<update id="syncOrderGoodsInfo" parameterType="java.util.Map">
UPDATE
ufo_product.goods g,
ufo_product.`storage` s,
ufo_order.seller_order_goods sog,
ufo_product.product p
SET
sog.image_url = g.color_image,
sog.product_name = p.product_name
ufo_order.seller_order_goods sog
SET sog.image_url = #{imgUrl},
sog.product_name = #{productName}
WHERE
sog.storage_id = s.id
AND s.goods_id = g.id
AND p.id = g.product_id
AND sog.attributes NOT IN (5,6)
AND (g.color_image != sog.image_url OR p.product_name != sog.product_name)
AND p.product_code IN ( #{productCode} )
(sog.image_url != #{imgUrl} OR sog.product_name != #{productName} )
AND sog.attributes NOT IN ( 5, 6 )
AND sog.storage_id IN
<foreach collection="storages" close=")" open="(" item="item" separator=",">
#{item}
</foreach>
</update>
</mapper>
\ No newline at end of file
... ...
... ... @@ -196,12 +196,12 @@ public class ProductController {
/**
* 同步订单商品信息
* @param productCode 商品编码
* @return 影响行数
* 同步订单商品信息(订单商品的名称和图片)
* @param productId 商品编码
* @return ApiResponse
*/
@RequestMapping(value = "/syncOrderGoodsInfo",method = RequestMethod.POST)
public ApiResponse syncOrderGoodsInfo(String productCode){
return productService.syncOrderGoodsInfo(productCode);
public ApiResponse syncOrderGoodsInfo(Integer productId){
return productService.syncOrderGoodsInfo(productId);
}
}
... ...
... ... @@ -50,5 +50,5 @@ public interface IProductService {
Map<Integer, Integer> queryBatchProductStorageCount(List<Integer> productIdList);
ApiResponse<Integer> syncOrderGoodsInfo(String productCode);
ApiResponse<Integer> syncOrderGoodsInfo(Integer productId);
}
... ...
... ... @@ -1462,11 +1462,42 @@ public class ProductServiceImpl implements IProductService, ApplicationContextAw
}
@Override
public ApiResponse<Integer> syncOrderGoodsInfo(String productCode) {
if(StringUtils.isEmpty(productCode)){
public ApiResponse<Integer> syncOrderGoodsInfo(Integer productId) {
if(productId == null){
return new ApiResponse<>(400,"商品编号不能为空");
}
productMapper.syncOrderGoodsInfo(productCode);
//根据productId获取货品信息
Product product = productMapper.selectByPrimaryKey(productId);
if(Objects.isNull(product)){
return new ApiResponse<>(400,"货品不存在");
}
//根据货品id获取商品
List<Integer> productIds = new ArrayList<>(2);
productIds.add(product.getId());
List<Goods> goodsList = goodsMapper.selectByProductId(productIds);
if(goodsList.isEmpty()){
return new ApiResponse<>(400,"商品不存在");
}
Goods goods = goodsList.get(0);
//根据goodsId获取仓库列表
List<Storage> storageList = storageMapper.selectByGoodsId(goods.getId());
if(storageList.isEmpty()){
return new ApiResponse<>(400,"仓库不存在");
}
//仓库id集合
List<Integer> storageIds = storageList.stream().map(Storage::getId).collect(Collectors.toList());
//构造参数
Map<String,Object> param = new HashMap<>(8);
param.put("productName",product.getProductName());
param.put("imgUrl",goods.getColorImage());
param.put("storages",storageIds);
int n = productMapper.syncOrderGoodsInfo(param);
LOGGER.info("synchronize seller_order_goods image_url and product_name Affected rows----------->{}",n);
return new ApiResponse<>(200,"同步成功");
}
... ...
... ... @@ -24,7 +24,7 @@
}
</style>
<div style="margin-left: 30px;" class="div_search">
<input id="productCode" type="text"/>
<input id="productId" type="text"/>
<a id="syncButton" class="easyui-linkbutton btn-info" data-options="iconCls:'icon-search'">同步订单商品信息</a>
</div>
... ... @@ -32,11 +32,10 @@
<script type="text/javascript">
var productPoolId;
$(function () {
$("#productCode").textbox({
prompt: "商品编号"
$("#productId").textbox({
prompt: "货品编号"
});
// 同步
... ... @@ -59,7 +58,7 @@
title : "提示",
msg : result.message
});
$("#productCode").val('');
$("#productId").val('');
}else {
window.self.$.messager.alert("失败", result.message, "error");
}
... ... @@ -70,10 +69,10 @@
* 提取参数
*/
function getParams() {
var productCode = $('#productCode').textbox('getValue');
var productId = $('#productId').textbox('getValue');
var param = {};
if (undefined !== productCode && null !== productCode && "" !== productCode) {
param.productCode = productCode;
if (undefined !== productId && null !== productId && "" !== productId) {
param.productId = productId;
}
return param;
}
... ...