...
|
...
|
@@ -14,11 +14,12 @@ import com.yoho.activity.queue.constant.CutPriceConstant; |
|
|
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.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;
|
...
|
...
|
@@ -38,6 +39,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;
|
|
|
|
...
|
...
|
@@ -61,12 +65,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() {
|
...
|
...
|
@@ -145,9 +153,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));
|
...
|
...
|
@@ -251,9 +257,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));
|
|
|
//设置缓存
|
...
|
...
|
@@ -301,6 +305,9 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
throw new ServiceException(ServiceError.ACTIVITY_CUTDOWNPRICE_YOU_HAVE_EXCEED_MAX_CUTDOWNNUM_ERROR);
|
|
|
}
|
|
|
}
|
|
|
// 查询活动信息是否有效
|
|
|
CutDownPriceActivityBo activityBo = cutDownActivityService.queryActivityInfo(activityId);
|
|
|
checkValidActivity(activityBo, activityId);
|
|
|
|
|
|
//判断用户是否已经针对该skn帮助砍价
|
|
|
Integer count = cutPriceUserHelpMapper.selectExistHelpInfo(helpUserId, activityId, productSkn);
|
...
|
...
|
@@ -348,6 +355,10 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
}
|
|
|
// 清理缓存,用户帮砍记录列表、商品详情页
|
|
|
clearCache(activityId, productSkn, userId);
|
|
|
// 砍价成功时,给用户推送砍价成功消息
|
|
|
if(helpUsers!=null && (helpUsers.size()+1) == cutDownPriceProductBo.getJoinNum()){
|
|
|
pushSuccessMessage(userId, activityBo, cutDownPriceProductBo);
|
|
|
}
|
|
|
return cutPrice;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -499,6 +510,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,
|
...
|
...
|
@@ -596,13 +624,40 @@ public class CutDownPriceServiceImpl implements ICutDownPriceService { |
|
|
|
|
|
private void buildCurrentTime(PageResponseBo<CutDownPriceActivityProductBo> cacheResult) {
|
|
|
List<CutDownPriceActivityProductBo> productList = cacheResult.getList();
|
|
|
if(CollectionUtils.isNotEmpty(productList)){
|
|
|
for(CutDownPriceActivityProductBo bo : productList){
|
|
|
if (CollectionUtils.isNotEmpty(productList)) {
|
|
|
for (CutDownPriceActivityProductBo bo : productList) {
|
|
|
bo.setCurrentTime(DateUtils.getCurrentTimeSecond());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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()),
|
|
|
activityId, String.valueOf(productSkn));
|
|
|
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);
|
...
|
...
|
|