Authored by tanling

优惠券优化

... ... @@ -145,14 +145,16 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
if (CollectionUtils.isNotEmpty(coupons)){
List<Integer> couponIdList = coupons.stream().map(Coupon::getId).collect(Collectors.toList());
List<UserCouponNum> sendNumList = userCouponMapper.selectByCouponIds(couponIdList);
LOGGER.info("sendNumList is {}", sendNumList);
sendNumMap = sendNumList.stream().collect(Collectors.toMap(UserCouponNum::getCouponId, Function.identity(), (k1,k2)->k2));
List<UserCouponNum> useNumList = userCouponMapper.selectByCouponIdsAndStatus(couponIdList);
LOGGER.info("useNumList is {}", useNumList);
useNumMap = useNumList.stream().collect(Collectors.toMap(UserCouponNum::getCouponId, Function.identity(), (k1,k2)->k2));
}
List<CouponQueryResp> couponQueryResps = initCouponQueryResps(coupons,req.getCurTime());
if (MapUtils.isEmpty(sendNumMap) && MapUtils.isEmpty(useNumMap)) {
if (MapUtils.isNotEmpty(sendNumMap) || MapUtils.isNotEmpty(useNumMap)) {
Map<Integer, UserCouponNum> finalSendNumMap = sendNumMap;
Map<Integer, UserCouponNum> finalUseNumMap = useNumMap;
couponQueryResps = couponQueryResps.stream().map(x->{
... ... @@ -236,7 +238,8 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
LOGGER.info("before saveOrUpdateCoupon#deleteByCouponId,couponId is {}",req.getId());
// 已经有了优惠券的发放记录
if (coupon.getSendNum() > 0){
UserCouponNum userCouponNum = userCouponMapper.selectByCouponId(coupon.getId());
if (Objects.isNull(userCouponNum) && userCouponNum.getCnt()>0){
CouponSaveUpdateReq couponSaveUpdateReq = new CouponSaveUpdateReq();
couponSaveUpdateReq.setId(coupon.getId());
... ...
... ... @@ -17,6 +17,9 @@ public interface UserCouponMapper {
List<UserCouponNum> selectByCouponIds(@Param("couponIds") List<Integer> couponIds);
UserCouponNum selectByCouponId(@Param("couponId") Integer couponId);
List<UserCouponNum> selectByCouponIdsAndStatus(@Param("couponIds") List<Integer> couponIds);
int selectTotalByCondition(@Param("param") UserCouponQueryReq param);
... ...
package com.yoho.ufo.model.coupon;
import lombok.Data;
import lombok.ToString;
@Data
@ToString
public class UserCouponNum {
int cnt;
... ...
... ... @@ -34,6 +34,16 @@
</select>
<select id="selectByCouponId" resultType="com.yoho.ufo.model.coupon.UserCouponNum">
select
count(uid) cnt, coupon_id
from user_coupon
where
coupon_id=#{couponId,jdbcType=INTEGER}
group by coupon_id
</select>
<select id="selectByCouponIdsAndStatus" resultType="com.yoho.ufo.model.coupon.UserCouponNum">
select
count(uid) cnt, coupon_id
... ...