Authored by yangchangjiang

--task=null --user=杨长江 根据货品编号更新订单商品名称和图片

... ... @@ -2,6 +2,7 @@ package com.yoho.order.dal;
import java.util.List;
import com.yoho.product.model.ProductNameAndImgReq;
import org.apache.ibatis.annotations.Param;
import com.yoho.order.model.BuyerOrder;
... ... @@ -43,4 +44,8 @@ public interface BuyerOrderMapper {
int selectCountByStatusForFastDelivery(@Param("currentSecondMinus36Hours")Integer currentSecondMinus24Hours);
List<BuyerOrder> selectMinFalultList(@Param("buyerOrderReq") BuyerOrderReq req);
int updateOrderGoodsNameAndImg(ProductNameAndImgReq productNameAndImgReq);
int countByOrderGoodsNameAndImg(ProductNameAndImgReq productNameAndImgReq);
}
... ...
package com.yoho.product.model;
import lombok.Data;
import java.util.List;
/**
* @Author: 杨长江
* @Date: 2019-11-15 19:01
* @Description: 同步订单商品名称和图片请求类
*/
@Data
public class ProductNameAndImgReq {
/**
* 名称
*/
private String productName;
/**
* 图片地址
*/
private String imgUrl;
/**
* storages
*/
private List<Integer> storages;
}
... ...
... ... @@ -99,5 +99,4 @@ public interface ProductMapper {
@Param("start") int start,
@Param("rows") int rows);
int syncOrderGoodsInfo(Map<String,Object> param);
}
\ No newline at end of file
... ...
... ... @@ -358,5 +358,37 @@
limit #{buyerOrderReq.start},#{buyerOrderReq.size}
</if>
</select>
<update id="updateOrderGoodsNameAndImg" parameterType="com.yoho.product.model.ProductNameAndImgReq">
UPDATE
seller_order_goods sog
SET sog.image_url = #{imgUrl},
sog.product_name = #{productName}
WHERE
(sog.image_url != #{imgUrl} OR sog.product_name != #{productName} )
AND sog.attributes NOT IN ( 5, 6 )
AND sog.is_del = 1
AND sog.status in ('0','1')
AND sog.storage_id IN
<foreach collection="storages" close=")" open="(" item="item" separator=",">
#{item}
</foreach>
ORDER BY sog.id ASC
LIMIT 100
</update>
<select id="countByOrderGoodsNameAndImg" parameterType="com.yoho.product.model.ProductNameAndImgReq" resultType="int">
SELECT
count(1)
FROM seller_order_goods sog
WHERE
(sog.image_url != #{imgUrl} OR sog.product_name != #{productName} )
AND sog.attributes NOT IN ( 5, 6 )
AND sog.is_del = 1
AND sog.status in ('0','1')
AND sog.storage_id IN
<foreach collection="storages" close=")" open="(" item="item" separator=",">
#{item}
</foreach>
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -346,19 +346,4 @@
</if>
limit #{start}, #{rows}
</select>
<update id="syncOrderGoodsInfo" parameterType="java.util.Map">
UPDATE
ufo_order.seller_order_goods sog
SET sog.image_url = #{imgUrl},
sog.product_name = #{productName}
WHERE
(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
... ...
... ... @@ -200,8 +200,8 @@ public class ProductController {
* @param productId 商品编码
* @return ApiResponse
*/
@RequestMapping(value = "/syncOrderGoodsInfo",method = RequestMethod.POST)
public ApiResponse syncOrderGoodsInfo(Integer productId){
return productService.syncOrderGoodsInfo(productId);
@RequestMapping(value = "/updateOrderGoodsNameAndImg",method = RequestMethod.POST)
public ApiResponse updateOrderGoodsNameAndImg(Integer productId){
return productService.updateOrderGoodsNameAndImg(productId);
}
}
... ...
... ... @@ -50,5 +50,5 @@ public interface IProductService {
Map<Integer, Integer> queryBatchProductStorageCount(List<Integer> productIdList);
ApiResponse<Integer> syncOrderGoodsInfo(Integer productId);
ApiResponse<Integer> updateOrderGoodsNameAndImg(Integer productId);
}
... ...
... ... @@ -8,6 +8,8 @@ import java.util.stream.Collectors;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yoho.order.dal.BuyerOrderMapper;
import com.yoho.product.model.ProductNameAndImgReq;
import com.yoho.ufo.dal.model.*;
import com.yohobuy.ufo.model.order.bo.SellerBo;
import org.apache.commons.collections.CollectionUtils;
... ... @@ -112,7 +114,10 @@ public class ProductServiceImpl implements IProductService, ApplicationContextAw
@Autowired
private BatchService batchService;
@Autowired
private BuyerOrderMapper buyerOrderMapper;
private static final Integer NOT_SYN_CALENDER = 0;
@Override
... ... @@ -1462,7 +1467,7 @@ public class ProductServiceImpl implements IProductService, ApplicationContextAw
}
@Override
public ApiResponse<Integer> syncOrderGoodsInfo(Integer productId) {
public ApiResponse<Integer> updateOrderGoodsNameAndImg(Integer productId) {
if(productId == null){
return new ApiResponse<>(400,"商品编号不能为空");
}
... ... @@ -1490,15 +1495,23 @@ public class ProductServiceImpl implements IProductService, ApplicationContextAw
//仓库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);
//封装请求实体
ProductNameAndImgReq productNameAndImgReq = new ProductNameAndImgReq();
productNameAndImgReq.setProductName(product.getProductName());
productNameAndImgReq.setImgUrl(goods.getColorImage());
productNameAndImgReq.setStorages(storageIds);
int count = buyerOrderMapper.countByOrderGoodsNameAndImg(productNameAndImgReq);
int n = 0;
//批次更新,每次更新100行,防止一次更新的数据量太大,占用锁时间太长
while(count > 0){
n += buyerOrderMapper.updateOrderGoodsNameAndImg(productNameAndImgReq);
count = count - 100;
}
LOGGER.info("synchronize seller_order_goods image_url and product_name Affected rows----------->{}",n);
return new ApiResponse<>(200,"同步成功");
return new ApiResponse<>(200,"同步成功",n);
}
private String getMaxLen(String str, int len) {
... ...
... ... @@ -42,21 +42,21 @@
$("#syncButton").linkbutton({
onClick: function () {
var param = getParams();
syncOrderGoodsInfo(param);
updateOrderGoodsNameAndImg(param);
}
});
//同步订单商品的图片地址和商品名称
function syncOrderGoodsInfo(param) {
function updateOrderGoodsNameAndImg(param) {
$.ajax({
type: 'POST',
url: contextPath + '/product/syncOrderGoodsInfo',
url: contextPath + '/product/updateOrderGoodsNameAndImg',
data: param,
success: function (result) {
if(result.code == 200){
window.self.$.messager.show({
title : "提示",
msg : result.message
msg : "更新完成,共更新" + result.data + "条数据"
});
$("#productId").textbox('setValue', '');
}else {
... ...