Authored by chenchao

finish user coupon query

... ... @@ -7,6 +7,7 @@ import com.yohoufo.dal.promotion.model.CouponUseDO;
import com.yohoufo.dal.promotion.model.UserCoupon;
import org.apache.ibatis.annotations.Param;
import java.util.Collection;
import java.util.List;
public interface UserCouponMapper {
... ... @@ -56,4 +57,6 @@ public interface UserCouponMapper {
*/
List<UserCoupon> selectUserCouponList(UserCouponListQueryParams params);
List<UserCoupon> selectUserCouponListByCouponIds(@Param("uid")int uid,
@Param("couponIds")Collection<Integer> couponIds);
}
\ No newline at end of file
... ...
... ... @@ -277,4 +277,15 @@
</if>
</select>
<select id="selectUserCouponListByCouponIds" resultMap="BaseResultMap" >
select
<include refid="Base_Column_List" />
from user_coupon
where uid = #{uid,jdbcType=INTEGER}
and coupon_id in
<foreach collection="couponIds" item="couponId" open="(" close=")" separator=",">
#{couponId,jdbcType=INTEGER}
</foreach>
</select>
</mapper>
\ No newline at end of file
... ...
... ... @@ -6,7 +6,8 @@ import com.yohobuy.ufo.model.promotion.request.CouponListReq;
import com.yohobuy.ufo.model.promotion.response.CouponListBo;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.annotation.IgnoreSession;
import com.yohoufo.common.cache.Cachable;
import com.yohoufo.common.annotation.IgnoreSignature;
import com.yohoufo.common.annotation.InnerApi;
import com.yohoufo.promotion.service.impl.CollectiveCouponService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -34,12 +35,15 @@ public class CouponCenterController {
@RequestMapping(params = "method=ufo.couponsInPrdDetail.list")
@ResponseBody
public ApiResponse couponListOfPrdDetail(
@RequestParam(value = "uid", required = false) Integer uid,
@RequestParam(value = "productId") Integer productId,
@RequestParam(value = "page", required = false, defaultValue = "1") int page,
@RequestParam(value = "limit", required = false, defaultValue = "20") int limit,
@RequestParam(value = "business_client", required = false,defaultValue = "ufo") String businessClient) {
CouponListReq req = CouponListReq.builder()
.uid(uid)
.showReceive(true)
.productId(productId)
.businessClient(businessClient)
.page(Math.max(1, page))
... ... @@ -51,17 +55,26 @@ public class CouponCenterController {
return new ApiResponse.ApiResponseBuilder().code(200).data(listBo).build();
}
@RequestMapping(params = "method=ufo.couponTopListOfPrdDetail.list")
@ResponseBody
/**
* 详情页聚合时使用
* @param productId
* @param page
* @param limit
* @param businessClient
* @return
*/
@IgnoreSession
@Cachable(expire = 120)
@IgnoreSignature
@InnerApi
@RequestMapping("/couponTopListOfPrdDetail")
public ApiResponse couponTopListOfPrdDetail(
@RequestParam(value = "productId") Integer productId,
@RequestParam(value = "page", required = false, defaultValue = "1") int page,
@RequestParam(value = "limit", required = false, defaultValue = "50") int limit,
@RequestParam(value = "limit", required = false, defaultValue = "2") int limit,
@RequestParam(value = "business_client", required = false,defaultValue = "ufo") String businessClient) {
CouponListReq req = CouponListReq.builder()
.showReceive(false)
.productId(productId)
.businessClient(businessClient)
.page(Math.max(1, page))
... ...
... ... @@ -15,6 +15,7 @@ import org.apache.commons.lang3.StringUtils;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
public class CouponConvert {
//3天的秒数
... ... @@ -165,9 +166,9 @@ public class CouponConvert {
}
public static CouponSimpleBo do2CouponSimpleBo(Coupon coupon){
public static CouponSimpleBo do2CouponSimpleBo(Coupon coupon, Map<Integer, UserCoupon> couponIdUserCouponMap){
CouponSimpleBo couponSimpleBo = new CouponSimpleBo();
couponSimpleBo.setCouponId(coupon.getId());
couponSimpleBo.setCouponName(coupon.getCouponName());
couponSimpleBo.setCouponAmount(coupon.getCouponAmount());
couponSimpleBo.setUseLimitType(coupon.getUseLimitType().intValue());
... ... @@ -175,8 +176,14 @@ public class CouponConvert {
couponSimpleBo.setCheckRequired(coupon.getCheckRequired());
couponSimpleBo.setCouponToken(coupon.getCouponToken());
couponSimpleBo.setCouponType(coupon.getCouponType());
couponSimpleBo.setStartTime(DateUtil.formatDate(coupon.getStartTime(), DateUtil.YYYY_MM_DD_DOT));
couponSimpleBo.setEndTime(DateUtil.formatDate(coupon.getEndTime(), DateUtil.YYYY_MM_DD_DOT));
//
if (couponIdUserCouponMap.containsKey(coupon.getId())){
couponSimpleBo.setReceive("Y");
}else{
couponSimpleBo.setReceive("N");
}
return couponSimpleBo;
}
}
... ...
... ... @@ -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);
... ...