Răsfoiți Sursa

商户列表

licailing 5 ani în urmă
părinte
comite
56d55ed514

+ 21 - 16
src/main/java/com/izouma/dingdong/service/merchant/MerchantService.java

@@ -274,20 +274,23 @@ public class MerchantService {
                 //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()
-        );
-
         Set<Merchant> merchants = new HashSet<>(merchantList);
-        goods.forEach(g -> {
-            Merchant merchant = merchantRepo.findById(g.getMerchantId()).orElse(null);
-            if (ObjectUtil.isNotNull(merchant) && ApplyStatus.PASS.equals(merchant.getStatus())) {
-                merchants.add(merchant);
-            }
-        });
+
+        if (StrUtil.isNotBlank(pageQuery.getSearch())) {
+            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()
+            );
+
+            goods.forEach(g -> {
+                Merchant merchant = merchantRepo.findById(g.getMerchantId()).orElse(null);
+                if (ObjectUtil.isNotNull(merchant) && ApplyStatus.PASS.equals(merchant.getStatus())) {
+                    merchants.add(merchant);
+                }
+            });
+        }
 
 /*        //所有商家要按距离排序规则
         Map<Merchant, Double> map = new HashMap<>();
@@ -312,9 +315,9 @@ public class MerchantService {
 
         Map<Merchant, Double> mers = this.distanceSorting(merchants, longitude, latitude, null);
 
-        if (popularTag == null) {
+/*        if (popularTag == null) {
             popularTag = pageQuery.getSearch();
-        }
+        }*/
 
         //转DTO
         List<MerchantDTO> merchantDTOS = CollUtil.newArrayList();
@@ -324,8 +327,8 @@ public class MerchantService {
             //  }
             // for (Merchant m : mers) {
             MerchantSettings settings = merchantSettingsRepo.findByMerchantId(m.getKey().getId()).orElseThrow(new BusinessException("商户不存在"));
+            MerchantDTO merchantDTO = new MerchantDTO(m.getKey(), settings, m.getValue());
             if (StrUtil.isNotBlank(popularTag)) {
-                MerchantDTO merchantDTO = new MerchantDTO(m.getKey(), settings, m.getValue());
                 merchantDTO.setFullReductions(fullReductionRepo.findAllByMerchantId(merchantDTO.getMid()));
                 switch (popularTag) {
                     case "首单立减":
@@ -361,6 +364,8 @@ public class MerchantService {
                         merchantDTOS.add(merchantDTO);
                         break;
                 }
+            } else {
+                merchantDTOS.add(merchantDTO);
             }
         }
 

+ 1 - 1
src/test/java/com/izouma/dingdong/service/MerchantServiceTest.java

@@ -111,7 +111,7 @@ public class MerchantServiceTest {
         pageQuery.setSize(50);
         pageQuery.setSearch("");
         pageQuery.setSort("");
-        List<MerchantDTO> list = merchantService.showAll(pageQuery, 118.738275, 31.991961, "满减优惠", 82L);
+        List<MerchantDTO> list = merchantService.showAll(pageQuery, 118.738275, 31.991961, null, 82L);
 
         System.out.println(list.get(0).getFullReductions());
     }