List couponIssues = new ArrayList<>(); List failCouponList = new ArrayList<>(); for (Long productId : productIds) { //根据商品id查询发布的商品优惠券和通用券 List couponIssueUsersList = localCache.get(productId); if (CollectionUtil.isEmpty(couponIssueUsersList)) { couponIssueUsersList = this.baseMapper.productCoupon(productId); } if (CollectionUtil.isNotEmpty(couponIssueUsersList)) { couponIssues.addAll(couponIssueUsersList); } } //去除重复的优惠券 List distinctCouponIssues = couponIssues.stream() .collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(YxStoreCouponIssue::getId))), ArrayList::new)); //查询已经使用、过期、失效的优惠券 failCouponList = couponUserService.lambdaQuery() .eq(YxStoreCouponUser::getUid, userId) .eq(YxStoreCouponUser::getIsDel, CommonEnum.DEL_STATUS_0.getValue()) .eq(YxStoreCouponUser::getIsFail, CouponEnum.FALI_0.getValue()) .ge(YxStoreCouponUser::getEndTime, new Date()) .list(); List validCouponIssues = distinctCouponIssues.stream() .filter(couponIssue -> failCouponList.stream().noneMatch(couponUser -> couponUser.getCid().equals(couponIssue.getId()))) .sorted(Comparator.comparing(YxStoreCouponIssue::getCouponPrice).reversed()) .collect(Collectors.toList()); //区分商品券还是通用券 List commonCouponList = validCouponIssues.stream() .filter(couponIssue -> couponIssue.getCtype().equals(CouponEnum.TYPE_0.getValue())) .collect(Collectors.toList()); List productCouponList = validCouponIssues.stream() .filter(couponIssue -> couponIssue.getCtype().equals(CouponEnum.TYPE_1.getValue())) .collect(Collectors.toList()); CouponConfirmOrderVo couponConfirmOrderVo = new CouponConfirmOrderVo(); couponConfirmOrderVo.setCommonCouponList(commonCouponList); couponConfirmOrderVo.setProductCouponList(productCouponList); return couponConfirmOrderVo

优化以下代码 ListYxStoreCouponIssue couponIssueUsersLists = new ArrayList; for Long productId productIds 根据商品id查询发布的商品优惠券和通用券 ListYxStoreCouponIssue couponIssueUsersList = lo

原文地址: https://www.cveoy.top/t/topic/gpuj 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录