|
|
|
@ -31,6 +31,10 @@ import org.springframework.web.bind.annotation.*; |
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.concurrent.ConcurrentHashMap; |
|
|
|
|
import java.util.function.Function; |
|
|
|
|
import java.util.function.Predicate; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
@Controller |
|
|
|
|
@RequestMapping(value="/discount") |
|
|
|
@ -78,32 +82,45 @@ public class DiscountController { |
|
|
|
|
// 用户session
|
|
|
|
|
UserSessionObject userSession = userCenter.getSessionModel(UserSessionObject.class); |
|
|
|
|
|
|
|
|
|
Map<String, Object> mapSpecs = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
mapSpecs.put("specsIds", specsIds); |
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
map.put("userId", userSession.getUser().getId()); |
|
|
|
|
map.put("status", 1); |
|
|
|
|
|
|
|
|
|
List<CouponDiscountUserRel> list = discountUserRelService.getList(map); |
|
|
|
|
|
|
|
|
|
// 查询规格可用优惠券
|
|
|
|
|
List<CouponDiscountGoodsRel> couponDiscountGoodsRel = couponDiscountService.getListGoodsRel(mapSpecs); |
|
|
|
|
List<CouponDiscountUserRel> listDiscount = list.stream().filter(distinctByKey(CouponDiscountUserRel::getDiscountId)).collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
if (couponDiscountGoodsRel == null) { |
|
|
|
|
return ResponseMsgUtil.success(null); |
|
|
|
|
} |
|
|
|
|
List<CouponDiscountUserRel> listFind = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
listDiscount.forEach(d -> { |
|
|
|
|
Map<String, Object> mapSpecs = new HashMap<>(); |
|
|
|
|
mapSpecs.put("discountId", d.getDiscountId()); |
|
|
|
|
// 查询规格可用优惠券
|
|
|
|
|
List<CouponDiscountGoodsRel> couponDiscountGoodsRel = couponDiscountService.getListGoodsRel(mapSpecs); |
|
|
|
|
List<Long> specsIdList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
List<CouponDiscountUserRel> list = new ArrayList<>(); |
|
|
|
|
couponDiscountGoodsRel.forEach(dg -> { |
|
|
|
|
specsIdList.add(dg.getSpecsId()); |
|
|
|
|
}); |
|
|
|
|
String specsIdsStr = StringUtils.join(specsIdList, ","); |
|
|
|
|
|
|
|
|
|
for(CouponDiscountGoodsRel rel : couponDiscountGoodsRel) { |
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
|
if (specsIdsStr.contains(specsIds)) { |
|
|
|
|
listFind.add(d); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
map.put("userId", userSession.getUser().getId()); |
|
|
|
|
map.put("status", 1); |
|
|
|
|
map.put("discountId", rel.getDiscountId()); |
|
|
|
|
CouponDiscountUserRel couponDiscountUserRel = discountUserRelService.getRel(map); |
|
|
|
|
list.add(couponDiscountUserRel); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
List<CouponDiscountUserRel> filteredList = list.stream() |
|
|
|
|
.filter(obj -> listFind.stream() |
|
|
|
|
.map(CouponDiscountUserRel::getDiscountId) |
|
|
|
|
.collect(Collectors.toList()) |
|
|
|
|
.contains(obj.getDiscountId())) |
|
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
|
|
return ResponseMsgUtil.success(list); |
|
|
|
|
|
|
|
|
|
return ResponseMsgUtil.success(filteredList); |
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("GoodsDetailController --> getListUser() error!", e); |
|
|
|
@ -111,6 +128,11 @@ public class DiscountController { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) { |
|
|
|
|
Set<Object> seen = ConcurrentHashMap.newKeySet(); |
|
|
|
|
return t -> seen.add(keyExtractor.apply(t)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|