| | |
| | | .le(CouponInfo::getSendStartTime, now) |
| | | .ge(CouponInfo::getSendEndTime, now) |
| | | .eq(CouponInfo::getPersonType, 1) |
| | | .eq(CouponInfo::getDelFlag, 0) |
| | | .eq(CouponInfo::getShelfStatus, 1) |
| | | .list(); |
| | | //查出指定人员可领取优惠券 |
| | | List<CouponInfo> list1 = couponInfoService.lambdaQuery() |
| | | .le(CouponInfo::getSendStartTime, now) |
| | | .ge(CouponInfo::getSendEndTime, now) |
| | | .eq(CouponInfo::getPersonType, 2) |
| | | .eq(CouponInfo::getDelFlag, 0) |
| | | .eq(CouponInfo::getShelfStatus, 1) |
| | | .apply("FIND_IN_SET('" + appUserById.getId() + "', person_ids)") |
| | | .list(); |
| | | //查出指定会员可领取优惠劵 |
| | | List<CouponInfo> list2 = couponInfoService.lambdaQuery().le(CouponInfo::getSendStartTime, now).ge(CouponInfo::getSendEndTime, now).eq(CouponInfo::getPersonType, 3).apply("FIND_IN_SET('" + appUserById.getVipId() + "', vip_ids)").list(); |
| | | List<CouponInfo> list2 = couponInfoService.lambdaQuery() |
| | | .le(CouponInfo::getSendStartTime, now) |
| | | .ge(CouponInfo::getSendEndTime, now) |
| | | .eq(CouponInfo::getPersonType, 3) |
| | | .eq(CouponInfo::getDelFlag, 0) |
| | | .eq(CouponInfo::getShelfStatus, 1) |
| | | .apply("FIND_IN_SET('" + appUserById.getVipId() + "', vip_ids)").list(); |
| | | List<CouponInfo> returnList = new ArrayList<>(); |
| | | count(userid, list, returnList); |
| | | count(userid, list1, returnList); |
| | | count(userid, list2, returnList); |
| | | return R.ok(returnList); |
| | | returnList.addAll(list); |
| | | returnList.addAll(list1); |
| | | returnList.addAll(list2); |
| | | |
| | | List<CouponInfo> collect = returnList.stream().filter(couponInfo -> { |
| | | Integer couponInfoId = couponInfo.getId(); |
| | | Integer sendNum = couponInfo.getSendNum(); |
| | | Integer maxNum = couponInfo.getMaxNum(); |
| | | Long count = appUserClient.getCouponCount(-1L, couponInfoId).getData(); |
| | | Long count2 = appUserClient.getCouponCount(userid, couponInfoId).getData(); |
| | | return count < sendNum && count2 < maxNum; |
| | | }).collect(Collectors.toList()); |
| | | |
| | | return R.ok(collect); |
| | | } |
| | | |
| | | private void count(Long userid, List<CouponInfo> list1, List<CouponInfo> returnList) { |
| | | for (CouponInfo couponInfo : list1) { |
| | | Long count = appUserClient.getCouponCount(-1L, couponInfo.getId()).getData(); |
| | | if(count >= couponInfo.getSendNum()){ |
| | | Integer couponInfoId = couponInfo.getId(); |
| | | Integer sendNum = couponInfo.getSendNum(); |
| | | Integer maxNum = couponInfo.getMaxNum(); |
| | | Long count = appUserClient.getCouponCount(-1L, couponInfoId).getData(); |
| | | if(count >= sendNum){ |
| | | continue; |
| | | } |
| | | count = appUserClient.getCouponCount(userid, couponInfo.getId()).getData(); |
| | | couponInfo.setMaxNum(couponInfo.getMaxNum() - count.intValue()); |
| | | if((couponInfo.getSendNum() - count) >= couponInfo.getMaxNum()){ |
| | | for (int i = 0; i < couponInfo.getMaxNum(); i++) { |
| | | returnList.add(couponInfo); |
| | | } |
| | | }else{ |
| | | for (int i = 0; i < (couponInfo.getSendNum() - count); i++) { |
| | | returnList.add(couponInfo); |
| | | } |
| | | |
| | | count = appUserClient.getCouponCount(userid, couponInfoId).getData(); |
| | | couponInfo.setMaxNum(maxNum - count.intValue()); |
| | | if(count < maxNum){ |
| | | continue; |
| | | } |
| | | |
| | | for (int i = 0; i < maxNum; i++) { |
| | | returnList.add(couponInfo); |
| | | } |
| | | } |
| | | } |
| | | |