Authored by qinchao

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

... ... @@ -35,4 +35,6 @@ public interface SellerOrderGoodsViewMapper {
@Param("limit")Integer limit);
int selectEntryCntByUidStatusGBSku(SellerOrderGoods condition);
List<SellerOrderGoods> selectCanSellByStorageId(@Param("storageId")int storageId);
}
... ...
... ... @@ -123,4 +123,11 @@
) t
</select>
<select id="selectEntryListByUidStatusGBSkc" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List" />
FROM seller_order_goods
WHERE storage_id = #{storageId,jdbcType=INTEGER} and status = 1
</select>
</mapper>
\ No newline at end of file
... ...
package com.yohoufo.order.event;
import com.yohoufo.common.alarm.Event;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Builder;
/**
* Created by craig.qin on 2019/3/20.
* 价格变动(调价、新的上架)发消息
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class SellerOrderPriceChangeEvent extends Event{
private int sellerUid;
private Integer skup;
}
... ...
package com.yohoufo.order.service.handler;
import com.google.common.eventbus.Subscribe;
import com.yoho.core.redis.cluster.annotation.Redis;
import com.yoho.core.redis.cluster.operations.nosync.YHRedisTemplate;
import com.yoho.core.redis.cluster.operations.nosync.YHSetOperations;
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
import com.yohobuy.ufo.model.order.common.SkupStatus;
import com.yohoufo.common.alarm.IEventHandler;
import com.yohoufo.common.cache.CacheKeyEnum;
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
import com.yohoufo.dal.order.SellerOrderGoodsViewMapper;
import com.yohoufo.dal.order.model.OrderOverTime;
import com.yohoufo.dal.order.model.SellerOrderGoods;
import com.yohoufo.order.event.SellerOrderPriceChangeEvent;
import com.yohoufo.order.mq.DelayTime;
import com.yohoufo.order.mq.TopicConstants;
import com.yohoufo.order.mq.producer.TradeMqSender;
import com.yohoufo.order.service.impl.OrderOverTimeService;
import com.yohoufo.order.service.proxy.InBoxFacade;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
* Created by craig
*/
@Component
public class SellerOrderPriceChangeHandler implements IEventHandler<SellerOrderPriceChangeEvent> {
final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
@Autowired
private SellerOrderGoodsViewMapper sellerOrderGoodsViewMapper;
@Autowired
private InBoxFacade inBoxFacade;
@Redis("gwNoSyncRedis")
private YHSetOperations yhSetOperations;
@Redis("gwNoSyncRedis")
YHRedisTemplate yhRedisTemplate;
private final SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
@Override
@Subscribe
public void handle(SellerOrderPriceChangeEvent event) {
logger.info("Subscribe SellerOrderPriceChangeEvent msg, event {}", event);
SellerOrderGoods sog = sellerOrderGoodsMapper.selectByPrimaryKey(event.getSkup());
if(sog==null){
logger.warn("Subscribe SellerOrderPriceChangeEvent msg return SellerOrderGoods is null, event {}", event);
return ;
}
if(SkupStatus.CAN_SELL.getCode()!=sog.getStatus()){
logger.warn("Subscribe SellerOrderPriceChangeEvent msg return SellerOrderGoods status is not can sell , event {} ,sog {}", event,sog);
return ;
}
BigDecimal changedPrice = sog.getGoodsPrice();
//根据storageId获取所有在售的卖家的订单
List<SellerOrderGoods> list= sellerOrderGoodsViewMapper.selectCanSellByStorageId(sog.getStorageId());
//把自己过滤掉,只保留价格高于当前价格
list = list.stream().filter(r->r.getGoodsPrice().compareTo(changedPrice)>0).collect(Collectors.toList());
//从redis过滤uid+storgeid+date
Date currentTime = new Date();
String dateString = formatter.format(currentTime);//2019-03-20
//发送,并记录到redis
RedisKeyBuilder redisKey = getRedisKeyBuilder(dateString);
Set<String> members = yhSetOperations.members(redisKey);
if(CollectionUtils.isNotEmpty(members)){
list = list.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()]));
yhRedisTemplate.longExpire(redisKey, 24, TimeUnit.HOURS); //24小时失效
}
}
public String getValueForSet(SellerOrderGoods r){
return r.getUid()+"-"+r.getStorageId();
}
public static RedisKeyBuilder getRedisKeyBuilder(String dateString){
return RedisKeyBuilder.newInstance().appendFixed("ufo:order:price:change:").appendVar(dateString);
}
}
... ...
... ... @@ -21,6 +21,7 @@ import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
... ... @@ -945,6 +946,36 @@ public class InBoxFacade {
}
}
/**
* 更低的出价提醒
* @param sog
*/
public void noticeSellerWhenOtherChangePriceLower(SellerOrderGoods sog,Set<Integer> noticeSellerUidList){
String prdName = sog.getProductName();
String sizeName = sog.getSizeName();
try {
executorService.execute(() -> {
// 发站内信
logger.info("record noticeSellerWhenOtherChangePriceLower for seller,noticeSellerUidList {}, sog {}", noticeSellerUidList, 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);
}
);
});
} catch (Exception e) {
logger.warn("InBoxFacade noticeSellerWhenOtherChangePriceLower error inbox msg, noticeSellerUidList {}, sog {} ", noticeSellerUidList, sog, e);
}
}
/*********************************************************************
* 其他---短信
********************************************************************/
... ...