| | |
| | | @PostMapping("/base/coupon/getAllCoupons") |
| | | public List<Coupon> getAllCoupons(@RequestBody CommodityRequest request){ |
| | | List<Coupon> couponList = new ArrayList<>(); |
| | | // String provinceCode = ""; |
| | | // String cityCode = ""; |
| | | // if (ToolUtil.isEmpty(request.getLat()) && ToolUtil.isEmpty(request.getLon())){ |
| | | // return couponList; |
| | | // } |
| | | // try { |
| | | // Map<String, String> geocode = gdMapGeocodingUtil.geocode(request.getLon(), request.getLat()); |
| | | // provinceCode = geocode.get("provinceCode"); |
| | | // cityCode = geocode.get("cityCode"); |
| | | // }catch (Exception e){ |
| | | // e.printStackTrace(); |
| | | // } |
| | | String provinceCode = ""; |
| | | String cityCode = ""; |
| | | if (ToolUtil.isEmpty(request.getLat()) && ToolUtil.isEmpty(request.getLon())){ |
| | | return couponList; |
| | | } |
| | | try { |
| | | Map<String, String> geocode = gdMapGeocodingUtil.geocode(request.getLon(), request.getLat()); |
| | | provinceCode = geocode.get("provinceCode"); |
| | | cityCode = geocode.get("cityCode"); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | try { |
| | | LocalDateTime currentDate = LocalDateTime.now(); |
| | | |
| | |
| | | .eq("status",1) |
| | | .le("startTime", currentDate) |
| | | .ge("endTime", currentDate)); |
| | | // if (couponList.size() > 0 ){ |
| | | // Iterator<Coupon> iterator = couponList.iterator(); |
| | | // while (iterator.hasNext()) { |
| | | // Coupon merchandise = iterator.next(); |
| | | // if (merchandise.getUseScope() == 2){ |
| | | // List<CouponCity> couponCities = cityService.list(new LambdaQueryWrapper<CouponCity>() |
| | | // .eq(CouponCity::getCouponId,merchandise.getId())); |
| | | // if (couponCities.size() > 0){ |
| | | // for (CouponCity couponCity : couponCities) { |
| | | // if (!Objects.equals(couponCity.getCityCode(), cityCode) && !Objects.equals(couponCity.getProvinceCode(), provinceCode)){ |
| | | // iterator.remove(); // 移除符合条件的商品 |
| | | // break; |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | // } |
| | | if (couponList.size() > 0 ){ |
| | | Iterator<Coupon> iterator = couponList.iterator(); |
| | | while (iterator.hasNext()) { |
| | | Coupon merchandise = iterator.next(); |
| | | if (merchandise.getUseScope() == 2){ |
| | | List<CouponCity> couponCities = cityService.list(new LambdaQueryWrapper<CouponCity>() |
| | | .eq(CouponCity::getCouponId,merchandise.getId())); |
| | | if (couponCities.size() > 0){ |
| | | for (CouponCity couponCity : couponCities) { |
| | | if (!Objects.equals(couponCity.getCityCode(), cityCode) && !Objects.equals(couponCity.getProvinceCode(), provinceCode)){ |
| | | iterator.remove(); // 移除符合条件的商品 |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return couponList; |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |