Authored by wangshusheng

砍价推送

... ... @@ -189,7 +189,7 @@
<dependency>
<groupId>com.yoho.dsf</groupId>
<artifactId>yoho-message-sdk</artifactId>
<version>1.1.1-SNAPSHOT</version>
<version>1.0.6-SNAPSHOT</version>
</dependency>
</dependencies>
... ...
... ... @@ -13,18 +13,17 @@ import com.yoho.activity.dal.model.CutDownPriceUserRecord;
import com.yoho.activity.queue.service.ICutDownPriceActivityService;
import com.yoho.activity.queue.service.ICutDownPriceProductService;
import com.yoho.activity.queue.service.ICutDownPriceService;
import com.yoho.activity.queue.service.IDrawlineList2MapService;
import com.yoho.activity.queue.wrapper.CutDownPriceProductHelpUserWrapper;
import com.yoho.core.rest.client.ServiceCaller;
import com.yoho.core.rest.client.hystrix.AsyncFuture;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yoho.message.sdk.common.model.SendMessageRspBo;
import com.yoho.message.sdk.service.order.IGroupOrderService;
import com.yoho.product.model.ProductBo;
import com.yoho.product.request.BatchBaseRequest;
import com.yoho.product.response.PageResponseBo;
import com.yoho.service.model.activity.*;
import com.yoho.service.model.activity.drawline.request.CutPriceHelpUserRequestBO;
import com.yoho.service.model.activity.drawline.response.UserBaseRspBO;
import com.yoho.service.model.social.request.UicUserReqBO;
import com.yoho.service.model.social.response.UserInfoRspBO;
import org.apache.commons.collections.CollectionUtils;
... ... @@ -39,6 +38,9 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
... ... @@ -60,12 +62,16 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
private ICutDownPriceActivityService cutDownActivityService;
@Autowired
private ICutDownPriceProductService cutDownPriceProductService;
@Autowired
private IDrawlineList2MapService drawlineList2MapService;
@Resource
ServiceCaller serviceCaller;
@Autowired
private BeanConvert convert;
@Autowired
private IGroupOrderService groupOrderService;
private static final int DEFAULT_QUEUECAPACITY = 2000;
private ExecutorService executorService = new ThreadPoolExecutor(5, 10, 10L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>(DEFAULT_QUEUECAPACITY));
@Override
public CutDownPriceActivityBo queryEffectCutPriceActivity() {
... ... @@ -144,9 +150,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
// 查询已砍价记录
List<CutDownPriceProductHelpUserBo> helpUserBos = this.queryHelpInfo(cutPriceHelpUserRequestBO);
// 调product接口查询商品信息
BatchBaseRequest<Integer> request = new BatchBaseRequest<Integer>();
request.setParams(Lists.newArrayList(productSkn));
ProductBo[] productBoArray = serviceCaller.call("product.batchQueryNamesAndImageBySkns", request, ProductBo[].class);
ProductBo[] productBoArray = invokeBatchQueryNamesAndImageBySkns(Lists.newArrayList(productSkn));
// 组装信息
CutDownPriceActivityProductBo bo = buildCutDownPriceActivityProductBo(activityBo, cutDownPriceProductBo, helpUserBos, productBoArray);
bo.setCanUseCount(selectCutdownPriceOrderRecordCount(cutPriceHelpUserRequestBO));
... ... @@ -227,9 +231,7 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
List<CutPriceHelpUserRequestBO> userRequestList = convert.convertFromList(cutPriceUserRecordList, CutPriceHelpUserRequestBO.class);
List<CutDownPriceProductHelpUserBo> helpUserBoList = this.queryHelpInfoList(uid, userRequestList);
// 根据skn列表查询商品信息
BatchBaseRequest<Integer> productRequest = new BatchBaseRequest<Integer>();
productRequest.setParams(Lists.newArrayList(productSkns));
ProductBo[] productBoArray = serviceCaller.call("product.batchQueryNamesAndImageBySkns", productRequest, ProductBo[].class);
ProductBo[] productBoArray = invokeBatchQueryNamesAndImageBySkns(Lists.newArrayList(productSkns));
// 组装返回值
response.setList(buildCutDownPriceActivityProductBoList(cutPriceUserRecordList, activityBoList, cutProductBoList, helpUserBoList, productBoArray));
//设置缓存
... ... @@ -267,6 +269,10 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
Integer userId = cutPriceHelpUserRequestBO.getUserId();
Integer helpUserId = cutPriceHelpUserRequestBO.getHelpUserId();
// 查询活动信息是否有效
CutDownPriceActivityBo activityBo = cutDownActivityService.queryActivityInfo(activityId);
checkValidActivity(activityBo, activityId);
//判断用户是否已经帮助砍价
Integer count = cutPriceUserHelpMapper.selectExistHelpInfo(userId, helpUserId, activityId, productSkn);
if (count>0){
... ... @@ -306,6 +312,10 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
}
// 清理缓存,用户帮砍记录列表、商品详情页
clearCache(activityId, productSkn, userId);
// 砍价成功时,给用户推送砍价成功消息
if(helpUsers!=null && (helpUsers.size()+1) == cutDownPriceProductBo.getJoinNum()){
pushSuccessMessage(userId, activityBo, cutDownPriceProductBo);
}
return cutPrice;
}
... ... @@ -447,6 +457,23 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
return userInfoBoArray;
}
private ProductBo[] invokeBatchQueryNamesAndImageBySkns(List<Integer> productSkns) {
if(CollectionUtils.isEmpty(productSkns)){
return new ProductBo[0];
}
ProductBo[] productBoArray = null;
BatchBaseRequest<Integer> productRequest = new BatchBaseRequest<Integer>();
productRequest.setParams(productSkns);
try{
logger.info("start invoke product.batchQueryNamesAndImageBySkns, productSkns is {}", productSkns);
productBoArray = serviceCaller.call("product.batchQueryNamesAndImageBySkns", productRequest, ProductBo[].class);
}catch(Exception e){
logger.warn("invoke product.batchQueryNamesAndImageBySkns failed, productSkns is {}, exception is{}", productSkns, e);
productBoArray = new ProductBo[0];
}
return productBoArray;
}
private CutDownPriceActivityProductBo buildCutDownPriceActivityProductBo(CutDownPriceActivityBo activityBo,
CutDownPriceProductBo cutDownPriceProductBo,
List<CutDownPriceProductHelpUserBo> helpUserBos,
... ... @@ -522,6 +549,30 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService {
return cutDownPriceProductBo;
}
private void pushSuccessMessage(Integer userId, CutDownPriceActivityBo activityBo, CutDownPriceProductBo cutDownPriceProductBo) {
executorService.execute(new Runnable() {
@Override
public void run()
{
Integer activityId = activityBo.getActivityId();
Integer productSkn = cutDownPriceProductBo.getProductSkn();
String productName = "";
ProductBo[] productBoArray = invokeBatchQueryNamesAndImageBySkns(Lists.newArrayList(productSkn));
for(ProductBo bo : productBoArray){
if(bo.getErpProductId().equals(productSkn)){
productName = bo.getProductName();
break;
}
}
// 商品名称、商品原价、当前价格、activityId、productSkn、uid
logger.info("cutprice success pushSuccessMessage, uid is{}, activityId is {}, productSkn is {}", userId, activityId,
productSkn);
SendMessageRspBo sendMessageRsp = groupOrderService.cutPriceSuccess(String.valueOf(userId), productName, String.valueOf(cutDownPriceProductBo.getHighPrice()), String.valueOf(cutDownPriceProductBo.getLowPrice()));
logger.info("pushSuccessMessage push message code is {}, message is {}, uid is{}, activityId is {}, productSkn is {}", sendMessageRsp.getCode(), sendMessageRsp.getMessage(), userId, activityId, productSkn);
}
});
}
public <T> T getFromRedis(CacheKeyEnum keyEnum, Integer uid, Class<T> clazz, String... param) {
return redisHashCache.get(keyEnum.getCacheKey(), uid, keyEnum.getHashKey(param), clazz);
... ...