...
|
...
|
@@ -4,6 +4,7 @@ package com.yohoufo.promotion.service.impl; |
|
|
import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import com.yoho.core.redis.cluster.operations.serializer.RedisKeyBuilder;
|
|
|
import com.yohobuy.ufo.model.promotion.request.ProductLimitValueBo;
|
|
|
import com.yohoufo.common.cache.CacheClient;
|
|
|
import com.yohoufo.dal.promotion.CouponMapper;
|
|
|
import com.yohoufo.dal.promotion.CouponProductLimitMapper;
|
...
|
...
|
@@ -111,6 +112,77 @@ public class CouponCacheServiceImpl implements ICouponCacheService { |
|
|
return coupon;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取couponId对应的productLimitValue
|
|
|
* @param productLimitCouponIds
|
|
|
* @return
|
|
|
*/
|
|
|
public Map<Integer, List<ProductLimitValueBo>> getLimitProductValueWithCache(List<Integer> productLimitCouponIds) {
|
|
|
Map<Integer, List<ProductLimitValueBo>> result = Maps.newHashMap();
|
|
|
|
|
|
List<Integer> missCouponIdList = Lists.newArrayList();
|
|
|
|
|
|
for (Integer couponId : productLimitCouponIds){
|
|
|
List<ProductLimitValueBo> productIds = cacheClient.range(KeyBuilder.buildCouponLimitProductValueCacheKey(couponId), ProductLimitValueBo.class,0, -1);
|
|
|
|
|
|
if (CollectionUtils.isEmpty(productIds)){
|
|
|
missCouponIdList.add(couponId);
|
|
|
}else{
|
|
|
result.put(couponId, productIds);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (CollectionUtils.isEmpty(missCouponIdList)){
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
Map<Integer, List<ProductLimitValueBo>> resultCache = getAssociatedProductLimitValueMap(missCouponIdList);
|
|
|
result.putAll(resultCache);
|
|
|
|
|
|
for (Integer key : resultCache.keySet()){
|
|
|
cacheClient.rightPushAll(KeyBuilder.buildCouponLimitProductValueCacheKey(key), resultCache.get(key), ExpiredTime.COUPON_PRODUCT_LIMIT_CACHE_TIME);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* key=couponId, value=(type, productIdlist)
|
|
|
* @param couponIdList
|
|
|
* @return
|
|
|
*/
|
|
|
private Map<Integer, List<ProductLimitValueBo>> getAssociatedProductLimitValueMap(List<Integer> couponIdList){
|
|
|
|
|
|
|
|
|
List<CouponProductLimit> couponProductLimitList = couponProductLimitMapper.selectByCouponIds(couponIdList);
|
|
|
|
|
|
Map<Integer, List<CouponProductLimit>> map = couponProductLimitList.stream().collect(Collectors.groupingBy(CouponProductLimit::getCouponId));
|
|
|
|
|
|
// key=couponId, value=
|
|
|
Map<Integer, List<ProductLimitValueBo>> productLimitValueBoMap = Maps.newHashMap();
|
|
|
|
|
|
for (Integer couponId : map.keySet()){
|
|
|
|
|
|
List<ProductLimitValueBo> productLimitValueBos = Lists.newArrayList();
|
|
|
|
|
|
// key=limitType, value=
|
|
|
Map<Integer, List<CouponProductLimit>> typeToItem = map.get(couponId).stream().collect(Collectors.groupingBy(CouponProductLimit::getLimitType));
|
|
|
for (Integer type : typeToItem.keySet()){
|
|
|
productLimitValueBos.add(ProductLimitValueBo.builder()
|
|
|
.limitType(type)
|
|
|
.productIds(typeToItem.get(type).stream().map(CouponProductLimit::getProductId).collect(Collectors.toList())).build());
|
|
|
}
|
|
|
|
|
|
productLimitValueBoMap.put(couponId, productLimitValueBos);
|
|
|
|
|
|
}
|
|
|
|
|
|
return productLimitValueBoMap;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取couponId对应的productIds
|
|
|
* @param productLimitCouponIds
|
...
|
...
|
|