Преглед на файлове

feat:增加模糊查询

刘云鑫 преди 2 седмици
родител
ревизия
1acb9a1920

+ 6 - 4
alien-store/src/main/java/shop/alien/store/controller/StoreBookingTableController.java

@@ -248,16 +248,18 @@ public class StoreBookingTableController {
     @ApiOperationSupport(order = 7)
     @ApiOperation("按商户查询桌号并按分类分组(商户ID 同门店ID)")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "merchantId", value = "商户ID(门店ID)", dataType = "Integer", paramType = "query", required = true)
+            @ApiImplicitParam(name = "merchantId", value = "商户ID(门店ID)", dataType = "Integer", paramType = "query", required = true),
+            @ApiImplicitParam(name = "tableName", value = "桌子名称(桌号)模糊查询,可选", dataType = "String", paramType = "query", required = false)
     })
     @GetMapping("/listGroupedByMerchant")
-    public R<List<StoreBookingTableGroupVo>> listGroupedByMerchant(@RequestParam Integer merchantId) {
-        log.info("StoreBookingTableController.listGroupedByMerchant?merchantId={}", merchantId);
+    public R<List<StoreBookingTableGroupVo>> listGroupedByMerchant(@RequestParam Integer merchantId,
+                                                                  @RequestParam(required = false) String tableName) {
+        log.info("StoreBookingTableController.listGroupedByMerchant?merchantId={}&tableName={}", merchantId, tableName);
         if (merchantId == null) {
             return R.fail("商户ID不能为空");
         }
         try {
-            return R.data(storeBookingTableService.listTablesGroupedByMerchant(merchantId));
+            return R.data(storeBookingTableService.listTablesGroupedByMerchant(merchantId, tableName));
         } catch (Exception e) {
             log.error("按商户查询桌号分组失败", e);
             return R.fail("查询失败:" + e.getMessage());

+ 2 - 1
alien-store/src/main/java/shop/alien/store/service/StoreBookingTableService.java

@@ -49,9 +49,10 @@ public interface StoreBookingTableService extends IService<StoreTable> {
      * 按商户查询全部桌号,并按预订分类分组(商户ID 即门店 store_id)
      *
      * @param merchantId 商户ID(门店ID)
+     * @param tableName  桌子名称(桌号)模糊条件,传空或空白则不过滤
      * @return 按分类分组的桌号列表
      */
-    List<StoreBookingTableGroupVo> listTablesGroupedByMerchant(Integer merchantId);
+    List<StoreBookingTableGroupVo> listTablesGroupedByMerchant(Integer merchantId, String tableName);
 
     /**
      * 新增预订服务桌号

+ 17 - 3
alien-store/src/main/java/shop/alien/store/service/impl/StoreBookingTableServiceImpl.java

@@ -149,15 +149,29 @@ public class StoreBookingTableServiceImpl extends ServiceImpl<StoreBookingTableM
      */
     private static final int UNCATEGORIZED_CATEGORY_GROUP_KEY = Integer.MIN_VALUE;
 
+    /**
+     * 按桌号(桌子名称)子串模糊过滤;{@code tableName} 为空或仅空白时返回原列表。
+     */
+    private static List<StoreBookingTableVo> filterBookingTablesByNameLike(List<StoreBookingTableVo> vos, String tableName) {
+        if (!StringUtils.hasText(tableName)) {
+            return vos;
+        }
+        String needle = tableName.trim();
+        return vos.stream()
+                .filter(vo -> vo != null && vo.getTableNumber() != null && vo.getTableNumber().contains(needle))
+                .collect(Collectors.toList());
+    }
+
     @Override
-    public List<StoreBookingTableGroupVo> listTablesGroupedByMerchant(Integer merchantId) {
+    public List<StoreBookingTableGroupVo> listTablesGroupedByMerchant(Integer merchantId, String tableName) {
         if (merchantId == null) {
             log.warn("listTablesGroupedByMerchant: merchantId 为空(应对应门店 storeId)");
         }
-        log.info("listTablesGroupedByMerchant 开始 merchantId={}", merchantId);
+        log.info("listTablesGroupedByMerchant 开始 merchantId={} tableName={}", merchantId, tableName);
         try {
             // merchantId 在本项目中与门店 storeId 语义一致
             List<StoreBookingTableVo> all = getTableListWithCategoryName(merchantId, null);
+            all = filterBookingTablesByNameLike(all, tableName);
             Map<Integer, List<StoreBookingTableVo>> byCategory = groupTableVosByCategoryPreserveOrder(all);
             Map<Integer, String> categoryNameMap = loadCategoryNamesForStoreAndGroupKeys(merchantId, byCategory.keySet());
             Map<Integer, List<UserReservationVo>> reservationListByTableId = buildSortedReservationsByTableId(merchantId);
@@ -171,7 +185,7 @@ public class StoreBookingTableServiceImpl extends ServiceImpl<StoreBookingTableM
                     reservationListByTableId.size(), reservationRowTotal);
             return result;
         } catch (Exception e) {
-            log.error("listTablesGroupedByMerchant 失败 merchantId={}", merchantId, e);
+            log.error("listTablesGroupedByMerchant 失败 merchantId={} tableName={}", merchantId, tableName, e);
             throw e;
         }
     }