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