Authored by qinchao

Merge branch 'dev_689_更低价出售提醒' into test6.8.9

# Conflicts:
#	order/pom.xml
#	order/src/main/java/com/yohoufo/order/service/proxy/InBoxFacade.java
... ... @@ -20,10 +20,7 @@ import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
... ... @@ -69,10 +66,11 @@ public class SellerOrderPriceChangeHandler implements IEventHandler<SellerOrderP
BigDecimal changedPrice = sog.getGoodsPrice();
Integer storageId = sog.getStorageId();
//根据storageId获取所有在售的卖家的订单
List<SellerOrderGoods> list= sellerOrderGoodsViewMapper.selectCanSellByStorageId(storageId);
List<SellerOrderGoods> noticeList= sellerOrderGoodsViewMapper.selectCanSellByStorageId(storageId);
//把自己过滤掉,只保留价格高于当前价格
list = list.stream().filter(r->r.getGoodsPrice().compareTo(changedPrice)>0&&changedSellerUid!=r.getUid().intValue()).collect(Collectors.toList());
if(CollectionUtils.isEmpty(list)){
noticeList = noticeList.stream().filter(r->r.getGoodsPrice().compareTo(changedPrice)>0&&changedSellerUid!=r.getUid().intValue()).collect(Collectors.toList());
if(CollectionUtils.isEmpty(noticeList)){
logger.warn("Subscribe SellerOrderPriceChangeEvent msg return SellerOrderGoods with empty same storage id , event {} ,sog {}", event,sog);
return ;
}
//从redis过滤uid+storgeid+date
... ... @@ -83,21 +81,20 @@ public class SellerOrderPriceChangeHandler implements IEventHandler<SellerOrderP
RedisKeyBuilder redisKey = getRedisKeyBuilder(dateString, storageId);
Set<String> members = yhSetOperations.members(redisKey);
if(CollectionUtils.isNotEmpty(members)){
list = list.stream().filter(r->!members.contains(getValueForSet(r))).collect(Collectors.toList());
noticeList = noticeList.stream().filter(r->!members.contains(getValueForSet(r))).collect(Collectors.toList());
}
Set<Integer> noticeSellerUidList = new HashSet<>();
Set<String> redisSetValue = new HashSet<>();
for(SellerOrderGoods r:list){
noticeSellerUidList.add(r.getUid());
redisSetValue.add(getValueForSet(r));
}
logger.info("Subscribe SellerOrderPriceChangeEvent begin send msg, event {},noticeSellerUidList {} ,redisSetValue {}", event,noticeSellerUidList,redisSetValue);
//发消息
inBoxFacade.noticeSellerWhenOtherChangePriceLower(sog,noticeSellerUidList);
// 记录到redis
if(redisSetValue.size()>0){
yhSetOperations.add(redisKey,redisSetValue.toArray(new String[redisSetValue.size()]));
//用map保证,一个uid只有一条,防止消息多发
Map<Integer,SellerOrderGoods> noticeSellerMap = noticeList.stream().collect(Collectors.toMap(SellerOrderGoods::getUid, r -> r));
logger.info("Subscribe SellerOrderPriceChangeEvent begin send msg, event {},noticeSellerMap {} ", event,noticeSellerMap);
//发消息 and push
if(noticeSellerMap.size()>0){
//记录redis
String[] redisSetValue = noticeSellerMap.keySet().stream().map(r->String.valueOf(r)).toArray(String[]::new);
yhSetOperations.add(redisKey,redisSetValue);
yhRedisTemplate.longExpire(redisKey, 24, TimeUnit.HOURS); //24小时失效
//发消息和push
inBoxFacade.noticeSellerWhenOtherChangePriceLower(sog,noticeSellerMap);
}
}
... ...
package com.yohoufo.order.service.proxy;
import com.alibaba.fastjson.JSON;
import com.yoho.message.sdk.common.model.SendMessageRspBo;
import com.yoho.message.sdk.service.ufo.IUFOSendService;
import com.yohobuy.ufo.model.enums.InboxBusinessTypeEnum;
import com.yohobuy.ufo.model.order.common.SuperEnterStageLevel;
import com.yohoufo.dal.order.SellerOrderMapper;
import com.yohoufo.dal.order.StoredSellerMapper;
import com.yohoufo.dal.order.model.SellerOrder;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.dal.order.model.StoredSeller;
import com.yohoufo.dal.product.ProductMapper;
import com.yohoufo.dal.product.model.Product;
import com.yohoufo.inboxclient.model.InBoxResponse;
import com.yohoufo.inboxclient.model.InboxReqVO;
import com.yohoufo.inboxclient.sdk.InBoxSDK;
import com.yohoufo.order.service.impl.function.BuyerNoticeSender;
import com.yohoufo.order.utils.PaymentHelper;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -23,7 +23,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
... ... @@ -52,13 +55,10 @@ public class InBoxFacade {
private ProductMapper productMapper;
@Autowired
private IUFOSendService ufoSendService;
@Autowired
private StoredSellerMapper storedSellerMapper;
private SellerOrderMapper sellerOrderMapper;
@Autowired
private SellerOrderMapper sellerOrderMapper;
private IUFOSendService ufoSendService;
/*********************************************************************
* 买家消息 和 短信
... ... @@ -961,72 +961,86 @@ public class InBoxFacade {
* 更低的出价提醒
* @param sog
*/
public void noticeSellerWhenOtherChangePriceLower(SellerOrderGoods sog,Set<Integer> noticeSellerUidList){
public void noticeSellerWhenOtherChangePriceLower(SellerOrderGoods sog,Map<Integer,SellerOrderGoods> noticeSellerMap){
String prdName = sog.getProductName();
String sizeName = sog.getSizeName();
try {
executorService.execute(() -> {
// 发站内信
logger.info("record noticeSellerWhenOtherChangePriceLower for seller,noticeSellerUidList {}, sog {}", noticeSellerUidList, sog);
logger.info("record noticeSellerWhenOtherChangePriceLower for seller,noticeSellerMap {}, sog {}", noticeSellerMap, sog);
Product product = productMapper.selectByPrimaryKey(sog.getProductId());
String productCode = product.getProductCode();
String params = buildParams(prdName, sizeName,productCode,sog.getGoodsPrice().toPlainString());
noticeSellerUidList.stream().forEach(
sellerUid ->{
InboxReqVO req = buildInboxReqVO(sellerUid, params, InboxBusinessTypeEnum.NOTICE_SELLER_WHEN_OTHER_LOWER_PRICE);
InBoxResponse resp = inBoxSDK.addInbox(req);
logger.info("record seller sham send out inbox msg,sellerUid {}, prdName {},sizeName {} resp {}",
sellerUid, prdName, sizeName, resp);
}
);
noticeSellerUidList.stream().forEach( // 发送PUSH
sellerUid ->{
StoredSeller storedSeller = storedSellerMapper.selectValidByUid(sellerUid);
if (Objects.isNull(storedSeller)) {
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(sog.getId());
String orderCode = Optional.ofNullable(sellerOrder).map(SellerOrder::getOrderCode).map(String::valueOf).orElse(null);
/**
* 更低出售价提醒 商家未入驻
* @param uid
* @param productName 商品名称
* @param size 尺寸
* @param goodsNumber 货号
* @param salePrice 提醒的更低售价
* @param orderCode 订单编号
* @return
*/
ufoSendService.sendLessPrice(String.valueOf(sellerUid), product.getProductName(), sog.getSizeName(),
product.getProductCode(), sog.getGoodsPrice().toPlainString(), orderCode);
logger.info("personal seller record laster price send out push msg sellerUid【{}】 productName【{}】 SizeName【{}】 productCode【{}】 price【{}】 orderCode【{}】",
sellerUid, product.getProductName(), sog.getSizeName(), product.getProductCode(), sog.getGoodsPrice(), orderCode);
} else {
/**
* 更低出售价提醒 商家已入驻
* @param uid
* @param productName 商品名称
* @param size 尺寸
* @param goodsNumber 货号
* @param salePrice 提醒的更低售价
* @param productSkn 商品skn
* @return
*/
ufoSendService.sendLessPriceEnter(String.valueOf(sellerUid), product.getProductName(), sog.getSizeName(),
product.getProductCode(), sog.getGoodsPrice().toPlainString(), String.valueOf(sog.getProductId()));
logger.info("store seller record laster price send out push msg sellerUid【{}】 productName【{}】 SizeName【{}】 productCode【{}】 price【{}】 productId【{}】",
sellerUid, product.getProductName(), sog.getSizeName(), product.getProductCode(), sog.getGoodsPrice(), sog.getProductId());
}
}
);
String noticePrice = sog.getGoodsPrice().toPlainString();
String params = buildParams(prdName, sizeName,productCode,noticePrice);
for(Integer sellerUid:noticeSellerMap.keySet()){
SellerOrderGoods currSog = noticeSellerMap.get(sellerUid);
//发消息
InboxReqVO req = buildInboxReqVO(sellerUid, params, InboxBusinessTypeEnum.NOTICE_SELLER_WHEN_OTHER_LOWER_PRICE);
InBoxResponse resp = inBoxSDK.addInbox(req);
logger.info("record noticeSellerWhenOtherChangePriceLower for seller send msg ,seller uid {} resp {} noticeSellerMap {}, sog {}", sellerUid,resp,noticeSellerMap, sog);
//发push
SellerOrder currSellerOrder = sellerOrderMapper.selectBySkup(currSog.getId());
if(currSellerOrder==null){
logger.warn("InBoxFacade noticeSellerWhenOtherChangePriceLower error sellerOrder is null,skup {}, noticeSellerMap {}, sog {} ",noticeSellerMap.get(sellerUid).getId(), noticeSellerMap, sog);
return ;
}
SendMessageRspBo bo=null;
if(PaymentHelper.isWallet(currSellerOrder.getPayment())){
//入驻
bo = ufoSendService.sendLessPriceEnter(String.valueOf(sellerUid), prdName,sizeName,productCode,noticePrice, String.valueOf(currSog.getProductId()));
logger.info("record noticeSellerWhenOtherChangePriceLower push enter seller uid is {}, product id is {}, result is {}", sellerUid, currSog.getProductId(), bo);
}else{
bo = ufoSendService.sendLessPrice(String.valueOf(sellerUid), prdName,sizeName,productCode,noticePrice, String.valueOf(currSellerOrder.getOrderCode()));
logger.info("record noticeSellerWhenOtherChangePriceLower push non enter seller uid is {}, seller order code is {}, result is {}", sellerUid, currSellerOrder.getOrderCode(), bo);
}
}
logger.info("record noticeSellerWhenOtherChangePriceLower for seller end,noticeSellerMap {}, sog {}", noticeSellerMap, sog);
});
} catch (Exception e) {
logger.warn("InBoxFacade noticeSellerWhenOtherChangePriceLower error inbox msg, noticeSellerUidList {}, sog {} ", noticeSellerUidList, sog, e);
logger.warn("InBoxFacade noticeSellerWhenOtherChangePriceLower error inbox msg, noticeSellerMap {}, sog {} ", noticeSellerMap, sog, e);
}
/*noticeSellerUidList.stream().forEach( // 发送PUSH
sellerUid ->{
StoredSeller storedSeller = storedSellerMapper.selectValidByUid(sellerUid);
if (Objects.isNull(storedSeller)) {
SellerOrder sellerOrder = sellerOrderMapper.selectBySkup(sog.getId());
String orderCode = Optional.ofNullable(sellerOrder).map(SellerOrder::getOrderCode).map(String::valueOf).orElse(null);
* 更低出售价提醒 商家未入驻
* @param uid
* @param productName 商品名称
* @param size 尺寸
* @param goodsNumber 货号
* @param salePrice 提醒的更低售价
* @param orderCode 订单编号
* @return
ufoSendService.sendLessPrice(String.valueOf(sellerUid), product.getProductName(), sog.getSizeName(),
product.getProductCode(), sog.getGoodsPrice().toPlainString(), orderCode);
logger.info("personal seller record laster price send out push msg sellerUid【{}】 productName【{}】 SizeName【{}】 productCode【{}】 price【{}】 orderCode【{}】",
sellerUid, product.getProductName(), sog.getSizeName(), product.getProductCode(), sog.getGoodsPrice(), orderCode);
} else {
* 更低出售价提醒 商家已入驻
* @param uid
* @param productName 商品名称
* @param size 尺寸
* @param goodsNumber 货号
* @param salePrice 提醒的更低售价
* @param productSkn 商品skn
* @return
ufoSendService.sendLessPriceEnter(String.valueOf(sellerUid), product.getProductName(), sog.getSizeName(),
product.getProductCode(), sog.getGoodsPrice().toPlainString(), String.valueOf(sog.getProductId()));
logger.info("store seller record laster price send out push msg sellerUid【{}】 productName【{}】 SizeName【{}】 productCode【{}】 price【{}】 productId【{}】",
sellerUid, product.getProductName(), sog.getSizeName(), product.getProductCode(), sog.getGoodsPrice(), sog.getProductId());
}
}
);*/
}
/*********************************************************************
... ...