|
|
@@ -266,16 +266,27 @@ public class MerchantService {
|
|
|
|
|
|
// Specification<Merchant> specification = toSpecification(pageQuery, Merchant.class);
|
|
|
|
|
|
- List<Merchant> merchantList = merchantRepo.findAll(((root, criteriaQuery, criteriaBuilder) -> criteriaQuery.where(
|
|
|
- criteriaBuilder.like(root.get("name"), "%" + pageQuery.getSearch() + "%")).getRestriction()
|
|
|
- ));
|
|
|
+ List<Merchant> merchantList = merchantRepo.findAll((root, criteriaQuery, criteriaBuilder) ->
|
|
|
+ criteriaQuery.where(
|
|
|
+ criteriaBuilder.and(
|
|
|
+ criteriaBuilder.like(root.get("name"), "%" + pageQuery.getSearch() + "%")),
|
|
|
+ criteriaBuilder.equal(root.get("status"), ApplyStatus.PASS)).getRestriction()
|
|
|
+ //criteriaBuilder.like(root.get("name"), "%" + pageQuery.getSearch() + "%")).getRestriction()
|
|
|
+ );
|
|
|
+
|
|
|
+ List<Goods> goods = goodsRepo.findAll((root, criteriaQuery, criteriaBuilder) ->
|
|
|
+ criteriaQuery.where(
|
|
|
+ criteriaBuilder.and(
|
|
|
+ criteriaBuilder.like(root.get("name"), "%" + pageQuery.getSearch() + "%")),
|
|
|
+ criteriaBuilder.equal(root.get("status"), ApplyStatus.PASS)).getRestriction()
|
|
|
+ );
|
|
|
|
|
|
- List<Goods> goods = goodsRepo.findAll(((root, criteriaQuery, criteriaBuilder) -> criteriaQuery.where(
|
|
|
- criteriaBuilder.like(root.get("name"), "%" + pageQuery.getSearch() + "%")).getRestriction()
|
|
|
- ));
|
|
|
Set<Merchant> merchants = new HashSet<>(merchantList);
|
|
|
goods.forEach(g -> {
|
|
|
- merchants.add(merchantRepo.findById(g.getMerchantId()).orElse(null));
|
|
|
+ Merchant merchant = merchantRepo.findById(g.getMerchantId()).orElse(null);
|
|
|
+ if (ObjectUtil.isNotNull(merchant) && ApplyStatus.PASS.equals(merchant.getStatus())) {
|
|
|
+ merchants.add(merchant);
|
|
|
+ }
|
|
|
});
|
|
|
|
|
|
/* //所有商家要按距离排序规则
|
|
|
@@ -297,7 +308,9 @@ public class MerchantService {
|
|
|
}*/
|
|
|
|
|
|
//距离排序
|
|
|
- List<Merchant> mers = this.distanceSorting(merchants, longitude, latitude, null);
|
|
|
+ //List<Merchant> mers = this.distanceSorting(merchants, longitude, latitude, null);
|
|
|
+
|
|
|
+ Map<Merchant, Double> mers = this.distanceSorting(merchants, longitude, latitude, null);
|
|
|
|
|
|
if (popularTag == null) {
|
|
|
popularTag = pageQuery.getSearch();
|
|
|
@@ -305,41 +318,47 @@ public class MerchantService {
|
|
|
|
|
|
//转DTO
|
|
|
List<MerchantDTO> merchantDTOS = CollUtil.newArrayList();
|
|
|
- for (Merchant m : mers) {
|
|
|
- MerchantSettings settings = merchantSettingsRepo.findByMerchantId(m.getId()).orElseThrow(new BusinessException("商户不存在"));
|
|
|
+
|
|
|
+ for (Map.Entry<Merchant, Double> m : mers.entrySet()) {
|
|
|
+
|
|
|
+ // }
|
|
|
+ // for (Merchant m : mers) {
|
|
|
+ MerchantSettings settings = merchantSettingsRepo.findByMerchantId(m.getKey().getId()).orElseThrow(new BusinessException("商户不存在"));
|
|
|
if (StrUtil.isNotBlank(popularTag)) {
|
|
|
+ MerchantDTO merchantDTO = new MerchantDTO(m.getKey(), settings, m.getValue());
|
|
|
+ merchantDTO.setFullReductions(fullReductionRepo.findAllByMerchantId(merchantDTO.getMid()));
|
|
|
switch (popularTag) {
|
|
|
case "首单立减":
|
|
|
if ((settings.getFirstOrder() != null ? settings.getFirstOrder().compareTo(BigDecimal.ZERO) : 0) > 0) {
|
|
|
- merchantDTOS.add(new MerchantDTO(m, settings));
|
|
|
+ merchantDTOS.add(merchantDTO);
|
|
|
}
|
|
|
break;
|
|
|
case "满减优惠":
|
|
|
- if (CollUtil.isNotEmpty(fullReductionRepo.findAllByMerchantId(m.getId()))) {
|
|
|
- merchantDTOS.add(new MerchantDTO(m, settings));
|
|
|
+ if (CollUtil.isNotEmpty(fullReductionRepo.findAllByMerchantId(m.getKey().getId()))) {
|
|
|
+ merchantDTOS.add(merchantDTO);
|
|
|
}
|
|
|
break;
|
|
|
case "折扣商家":
|
|
|
- if (StrUtil.isNotEmpty(merchantClassificationRepo.findByMerchantIdAndType(m.getId(), 2).getGoodsIds())) {
|
|
|
- merchantDTOS.add(new MerchantDTO(m, settings));
|
|
|
+ if (StrUtil.isNotEmpty(merchantClassificationRepo.findByMerchantIdAndType(m.getKey().getId(), 2).getGoodsIds())) {
|
|
|
+ merchantDTOS.add(merchantDTO);
|
|
|
}
|
|
|
break;
|
|
|
case "下单返红包":
|
|
|
- if (CollUtil.isNotEmpty(couponRepo.findAllByMerchantIdAndEnabledTrue(m.getId()))) {
|
|
|
- merchantDTOS.add(new MerchantDTO(m, settings));
|
|
|
+ if (CollUtil.isNotEmpty(couponRepo.findAllByMerchantIdAndEnabledTrue(m.getKey().getId()))) {
|
|
|
+ merchantDTOS.add(merchantDTO);
|
|
|
}
|
|
|
break;
|
|
|
case "可用红包":
|
|
|
List<UserCoupon> coupons = userCouponRepo.findAllByUserIdAndIsUsedFalse(userId);
|
|
|
List<UserCoupon> collect = coupons.stream().filter(c ->
|
|
|
- !c.getCoupon().getEndDate().isBefore(LocalDate.now()) && (c.getCoupon().getMerchantId() == null || c.getCoupon().getMerchantId().equals(m.getId()))
|
|
|
+ !c.getCoupon().getEndDate().isBefore(LocalDate.now()) && (c.getCoupon().getMerchantId() == null || c.getCoupon().getMerchantId().equals(m.getKey().getId()))
|
|
|
).collect(Collectors.toList());
|
|
|
if (CollUtil.isNotEmpty(collect)) {
|
|
|
- merchantDTOS.add(new MerchantDTO(m, settings));
|
|
|
+ merchantDTOS.add(merchantDTO);
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
|
- merchantDTOS.add(new MerchantDTO(m, settings));
|
|
|
+ merchantDTOS.add(merchantDTO);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
@@ -389,14 +408,14 @@ public class MerchantService {
|
|
|
/*
|
|
|
距离排序,如果有范围,范围内进行排序
|
|
|
*/
|
|
|
- public List<Merchant> distanceSorting(Set<Merchant> merchants, Double longitude, Double latitude, Double range) {
|
|
|
+ public Map<Merchant, Double> distanceSorting(Set<Merchant> merchants, Double longitude, Double latitude, Double range) {
|
|
|
//List<Merchant> merchants = merchantRepo.findAll();
|
|
|
|
|
|
//所有商家要按距离排序规则
|
|
|
Map<Merchant, Double> map = new HashMap<>();
|
|
|
//算距离
|
|
|
for (Merchant m : merchants) {
|
|
|
- if (m.getLatitude() != null && m.getLongitude() != null) {
|
|
|
+ if (ObjectUtil.isNotNull(m.getLatitude()) && ObjectUtil.isNotNull(m.getLongitude())) {
|
|
|
Double distance = MapUtils.distance(m.getLongitude(), m.getLatitude(), longitude, latitude);
|
|
|
if (range != null) {
|
|
|
if (distance < range) {
|
|
|
@@ -411,12 +430,17 @@ public class MerchantService {
|
|
|
//排序
|
|
|
List<Map.Entry<Merchant, Double>> list = new ArrayList<>(map.entrySet());
|
|
|
list.sort(Comparator.comparing(Map.Entry<Merchant, Double>::getValue));
|
|
|
- List<Merchant> mers = new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ //List<Merchant> mers = new ArrayList<>();
|
|
|
+
|
|
|
+ Map<Merchant, Double> map1 = new HashMap<>();
|
|
|
for (Map.Entry<Merchant, Double> m : list) {
|
|
|
- mers.add(m.getKey());
|
|
|
+ //mers.add(m.getKey());
|
|
|
+ map1.put(m.getKey(), m.getValue());
|
|
|
}
|
|
|
|
|
|
- return mers;
|
|
|
+ return map1;
|
|
|
}
|
|
|
|
|
|
}
|