...
|
...
|
@@ -7,7 +7,9 @@ import com.yohobuy.ufo.model.promotion.response.CouponListBo; |
|
|
import com.yohoufo.common.utils.DateUtil;
|
|
|
import com.yohoufo.common.utils.PageHelper;
|
|
|
import com.yohoufo.dal.promotion.CouponViewMapper;
|
|
|
import com.yohoufo.dal.promotion.UserCouponMapper;
|
|
|
import com.yohoufo.dal.promotion.model.Coupon;
|
|
|
import com.yohoufo.dal.promotion.model.UserCoupon;
|
|
|
import com.yohoufo.promotion.convert.CouponConvert;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.slf4j.Logger;
|
...
|
...
|
@@ -15,8 +17,8 @@ import org.slf4j.LoggerFactory; |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -33,6 +35,9 @@ public class CollectiveCouponService { |
|
|
@Autowired
|
|
|
private CouponHelperService couponHelperService;
|
|
|
|
|
|
@Autowired
|
|
|
private UserCouponMapper userCouponMapper;
|
|
|
|
|
|
public CouponListBo queryCouponListOfPrdDetail(CouponListReq req){
|
|
|
int pageNum = req.getPage();
|
|
|
int limit = req.getLimit();
|
...
|
...
|
@@ -55,8 +60,22 @@ public class CollectiveCouponService { |
|
|
int totalPage = PageHelper.getPageTotal(total, limit);
|
|
|
final int offset = PageHelper.getOffsetOfMysql(pageNum, limit);
|
|
|
List<Coupon> datas= couponViewMapper.selectByAssociatedPrd(prdId, positionType,currentDT,offset,limit);
|
|
|
//when user login, show user coupon
|
|
|
final Map<Integer, UserCoupon> couponIdUserCouponMap = new HashMap<>(datas.size());
|
|
|
Integer uid;
|
|
|
if (req.isShowReceive() && Objects.nonNull(uid=req.getUid())){
|
|
|
|
|
|
List<CouponSimpleBo> couponInfoListBo = datas.stream().map(coupon -> CouponConvert.do2CouponSimpleBo(coupon))
|
|
|
Set<Integer> couponIds = datas.stream().map(Coupon::getId).collect(Collectors.toSet());
|
|
|
List<UserCoupon> userCoupons = userCouponMapper.selectUserCouponListByCouponIds(uid, couponIds);
|
|
|
Set<Integer> couponIdOfUser = null;
|
|
|
if (CollectionUtils.isNotEmpty(userCoupons)){
|
|
|
userCoupons.forEach(uc-> couponIdUserCouponMap.put(uc.getCouponId(), uc));
|
|
|
couponIdOfUser = couponIdUserCouponMap.keySet();
|
|
|
}
|
|
|
logger.info("queryCouponListOfPrdDetail selectUserCouponListByCouponIds find couponIdOfUser {} uid {} couponIds {}",
|
|
|
couponIdOfUser, uid,couponIds);
|
|
|
}
|
|
|
List<CouponSimpleBo> couponInfoListBo = datas.stream().map(coupon -> CouponConvert.do2CouponSimpleBo(coupon, couponIdUserCouponMap))
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
couponInfoListBo = couponHelperService.filter(couponInfoListBo);
|
...
|
...
|
|