...
|
...
|
@@ -17,6 +17,7 @@ import com.yoho.ufo.exception.PlatformException; |
|
|
import com.yoho.ufo.model.coupon.Coupon;
|
|
|
import com.yoho.ufo.model.coupon.CouponProductLimit;
|
|
|
import com.yoho.ufo.model.coupon.UserCoupon;
|
|
|
import com.yoho.ufo.model.coupon.UserCouponNum;
|
|
|
import com.yoho.ufo.model.coupon.resp.CouponQueryResp;
|
|
|
import com.yoho.ufo.model.coupon.resp.UidCouponQueryResp;
|
|
|
import com.yoho.ufo.model.coupon.resp.UserCouponQueryResp;
|
...
|
...
|
@@ -46,6 +47,7 @@ import org.springframework.web.multipart.MultipartFile; |
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -137,45 +139,40 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{ |
|
|
}
|
|
|
List<Coupon> coupons = couponMapper.selectByCondition(req);
|
|
|
|
|
|
// 获取 该券的用户领取|使用记录
|
|
|
Map<Integer, List<UserCoupon>> userCouponMap = null;
|
|
|
// 只获取使用记录
|
|
|
Map<Integer, UserCouponNum> sendNumMap = null;
|
|
|
Map<Integer, UserCouponNum> useNumMap = null;
|
|
|
if (CollectionUtils.isNotEmpty(coupons)){
|
|
|
List<Integer> couponIdList = coupons.stream().map(Coupon::getId).collect(Collectors.toList());
|
|
|
userCouponMap = getUserCouponMap(couponIdList);
|
|
|
List<UserCouponNum> sendNumList = userCouponMapper.selectByCouponIds(couponIdList);
|
|
|
sendNumMap = sendNumList.stream().collect(Collectors.toMap(UserCouponNum::getCouponId, Function.identity(), (k1,k2)->k2));
|
|
|
List<UserCouponNum> useNumList = userCouponMapper.selectByCouponIdsAndStatus(couponIdList);
|
|
|
useNumMap = useNumList.stream().collect(Collectors.toMap(UserCouponNum::getCouponId, Function.identity(), (k1,k2)->k2));
|
|
|
}
|
|
|
|
|
|
List<CouponQueryResp> couponQueryResps = initCouponQueryResps(coupons,req.getCurTime());
|
|
|
|
|
|
// 设置 已经领取数量|已经使用记录
|
|
|
if (MapUtils.isNotEmpty(userCouponMap)){
|
|
|
Map<Integer, List<UserCoupon>> finalUserCouponMap = userCouponMap;
|
|
|
if (MapUtils.isEmpty(sendNumMap) && MapUtils.isEmpty(useNumMap)) {
|
|
|
Map<Integer, UserCouponNum> finalSendNumMap = sendNumMap;
|
|
|
Map<Integer, UserCouponNum> finalUseNumMap = useNumMap;
|
|
|
couponQueryResps = couponQueryResps.stream().map(x->{
|
|
|
|
|
|
couponQueryResps = couponQueryResps.stream().map(x-> {
|
|
|
List<UserCoupon> userCouponList = finalUserCouponMap.get(x.getId());
|
|
|
if (CollectionUtils.isEmpty(userCouponList)) {
|
|
|
return x;
|
|
|
if (MapUtils.isNotEmpty(finalSendNumMap)){
|
|
|
x.setSendNum(finalSendNumMap.get(x.getId()) == null ? 0 :finalSendNumMap.get(x.getId()).getCnt());
|
|
|
}
|
|
|
x.setSendNum(userCouponList.size());
|
|
|
x.setUseNum(userCouponList.stream().filter(y->y.getStatus()== UserCouponsStatusEnum.USED.getCode()).count());
|
|
|
|
|
|
if (MapUtils.isNotEmpty(finalUseNumMap)){
|
|
|
x.setUseNum(finalUseNumMap.get(x.getId()) == null ? 0 : finalUseNumMap.get(x.getId()).getCnt());
|
|
|
}
|
|
|
|
|
|
return x;
|
|
|
}).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
jsonObject.put("coupons",couponQueryResps);
|
|
|
return new ApiResponse.ApiResponseBuilder().data(jsonObject).build();
|
|
|
}
|
|
|
|
|
|
private Map<Integer, List<UserCoupon>> getUserCouponMap(List<Integer> couponIdList) {
|
|
|
List<UserCoupon> userCouponList = userCouponMapper.selectByCouponIds(couponIdList);
|
|
|
if (CollectionUtils.isEmpty(userCouponList)){
|
|
|
return null;
|
|
|
}
|
|
|
Map<Integer, List<UserCoupon>> userCouponMap = userCouponList.stream().collect(Collectors.groupingBy(UserCoupon::getCouponId));
|
|
|
return userCouponMap;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ApiResponse saveOrUpdateCoupon(CouponSaveUpdateReq req) {
|
|
|
LOGGER.info("enter saveOrUpdateCoupon,param is {}",req);
|
...
|
...
|
@@ -522,6 +519,7 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{ |
|
|
com.yoho.ufo.util.DateUtil.int2DateStr(coupon.getEndTime(),"yyyy-MM-dd HH:mm:ss");
|
|
|
CouponQueryResp resp = new CouponQueryResp(coupon.getId(),coupon.getCouponName(),coupon.getCouponNum(),
|
|
|
useTime,coupon.getRemark(), getStatusDesc(coupon,curTime),coupon.getStatus(),coupon.getCouponToken());
|
|
|
resp.setSendNum(coupon.getSendNum());
|
|
|
resps.add(resp);
|
|
|
}
|
|
|
return resps;
|
...
|
...
|
|