Преглед изворни кода

桌号新增 增加类型判断

qinxuyang пре 3 недеља
родитељ
комит
b69f72e174

+ 4 - 0
alien-entity/src/main/java/shop/alien/entity/store/StoreTable.java

@@ -65,6 +65,10 @@ public class StoreTable {
     @TableField("status")
     private Integer status;
 
+    @ApiModelProperty(value = "类型(1:美食,2:通用)")
+    @TableField("type")
+    private Integer type;
+
     @ApiModelProperty(value = "当前就餐人数(就餐中时由首客填写,后续用户共用)")
     @TableField("diner_count")
     private Integer dinerCount;

+ 3 - 0
alien-entity/src/main/java/shop/alien/entity/store/dto/StoreBookingTableBatchDTO.java

@@ -22,6 +22,9 @@ public class StoreBookingTableBatchDTO {
     @ApiModelProperty(value = "分类ID(关联store_booking_category表)", required = true)
     private Integer categoryId;
 
+    @ApiModelProperty(value = "类型(1:美食,2:通用),不传默认1")
+    private Integer type;
+
     @ApiModelProperty(value = "桌号列表", required = true)
     private List<TableItem> tables;
 

+ 3 - 1
alien-entity/src/main/java/shop/alien/entity/store/vo/StoreBookingTableVo.java

@@ -1,6 +1,5 @@
 package shop.alien.entity.store.vo;
 
-import com.baomidou.mybatisplus.annotation.TableField;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -36,6 +35,9 @@ public class StoreBookingTableVo {
     @ApiModelProperty(value = "座位数")
     private Integer seatingCapacity;
 
+    @ApiModelProperty(value = "类型(1:美食,2:通用)")
+    private Integer type;
+
     @ApiModelProperty(value = "删除标记, 0:未删除, 1:已删除")
     private Integer deleteFlag;
 

+ 2 - 1
alien-entity/src/main/resources/mapper/StoreBookingTableMapper.xml

@@ -9,6 +9,7 @@
         <result column="category_id" property="categoryId" />
         <result column="table_number" property="tableNumber" />
         <result column="seating_capacity" property="seatingCapacity" />
+        <result column="type" property="type" />
         <result column="delete_flag" property="deleteFlag" />
         <result column="created_time" property="createdTime" />
         <result column="created_user_id" property="createdUserId" />
@@ -18,7 +19,7 @@
 
     <!-- 通用查询结果列 -->
     <sql id="Base_Column_List">
-        id, store_id, category_id, table_number, seating_capacity, 
+        id, store_id, category_id, table_number, seating_capacity, type,
         delete_flag, created_time, created_user_id, updated_time, updated_user_id
     </sql>
 

+ 9 - 1
alien-store/src/main/java/shop/alien/store/controller/StoreBookingTableController.java

@@ -100,6 +100,9 @@ public class StoreBookingTableController {
 
     @ApiOperationSupport(order = 3)
     @ApiOperation("新增预订服务桌号(支持批量添加)")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "type", value = "类型(1:美食,2:通用),不传默认1", dataType = "Integer", paramType = "body", required = false)
+    })
     @PostMapping("/add")
     public R<String> addTable(@RequestBody StoreBookingTableBatchDTO dto) {
         log.info("StoreBookingTableController.addTable?dto={}", dto);
@@ -125,7 +128,12 @@ public class StoreBookingTableController {
                     })
                     .collect(java.util.stream.Collectors.toList());
 
-            boolean result = storeBookingTableService.batchAddTables(dto.getStoreId(), dto.getCategoryId(), tables);
+            Integer type = dto.getType() == null ? 1 : dto.getType();
+            if (type != 1 && type != 2) {
+                return R.fail("type参数不合法");
+            }
+
+            boolean result = storeBookingTableService.batchAddTables(dto.getStoreId(), dto.getCategoryId(), type, tables);
             if (result) {
                 // 批量创建成功后,异步生成小程序二维码
                 List<String> tableNumbers = tables.stream()

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

@@ -57,10 +57,11 @@ public interface StoreBookingTableService extends IService<StoreTable> {
      *
      * @param storeId   门店ID
      * @param categoryId 分类ID
+     * @param type      类型(1:美食,2:通用)
      * @param tables    桌号列表(每个包含桌号和座位数)
      * @return boolean
      */
-    boolean batchAddTables(Integer storeId, Integer categoryId, List<StoreTable> tables);
+    boolean batchAddTables(Integer storeId, Integer categoryId, Integer type, List<StoreTable> tables);
 
     /**
      * 更新预订服务桌号

+ 55 - 40
alien-store/src/main/java/shop/alien/store/service/impl/StoreBookingTableServiceImpl.java

@@ -215,6 +215,9 @@ public class StoreBookingTableServiceImpl extends ServiceImpl<StoreBookingTableM
             log.warn("新增预订服务桌号失败:座位数必须大于0");
             throw new RuntimeException("座位数必须大于0");
         }
+        if (table.getType() == null) {
+            table.setType(1);
+        }
         
         // 处理桌号:去除前后空格
         String tableNumber = table.getTableNumber().trim();
@@ -239,9 +242,9 @@ public class StoreBookingTableServiceImpl extends ServiceImpl<StoreBookingTableM
     }
 
     @Override
-    public boolean batchAddTables(Integer storeId, Integer categoryId, List<StoreTable> tables) {
-        log.info("StoreBookingTableServiceImpl.batchAddTables?storeId={}, categoryId={}, tables.size={}", 
-                storeId, categoryId, tables != null ? tables.size() : 0);
+    public boolean batchAddTables(Integer storeId, Integer categoryId, Integer type, List<StoreTable> tables) {
+        log.info("StoreBookingTableServiceImpl.batchAddTables?storeId={}, categoryId={}, type={}, tables.size={}",
+                storeId, categoryId, type, tables != null ? tables.size() : 0);
         
         // 从JWT获取当前登录用户ID
         Integer userId = getCurrentUserId();
@@ -259,59 +262,71 @@ public class StoreBookingTableServiceImpl extends ServiceImpl<StoreBookingTableM
             log.warn("批量新增预订服务桌号失败:桌号列表不能为空");
             throw new RuntimeException("桌号列表不能为空");
         }
+
+        int actualType = type == null ? 1 : type;
+        if (actualType != 1 && actualType != 2) {
+            log.warn("批量新增预订服务桌号失败:type参数不合法,type={}", type);
+            throw new RuntimeException("type参数不合法");
+        }
         
         // 验证并处理每个桌号
         for (StoreTable table : tables) {
-            if (!StringUtils.hasText(table.getTableNumber())) {
-                log.warn("批量新增预订服务桌号失败:桌号不能为空");
-                throw new RuntimeException("桌号不能为空");
+            // type=1(美食)保留现有桌号校验;type=2(通用)放开桌号名称校验
+            if (actualType == 1) {
+                if (!StringUtils.hasText(table.getTableNumber())) {
+                    log.warn("批量新增预订服务桌号失败:桌号不能为空");
+                    throw new RuntimeException("桌号不能为空");
+                }
+                // 处理桌号:去除前后空格
+                String tableNumber = table.getTableNumber().trim();
+                table.setTableNumber(tableNumber);
             }
             if (table.getSeatingCapacity() == null || table.getSeatingCapacity() <= 0) {
                 log.warn("批量新增预订服务桌号失败:座位数必须大于0");
                 throw new RuntimeException("座位数必须大于0");
             }
             
-            // 处理桌号:去除前后空格
-            String tableNumber = table.getTableNumber().trim();
-            table.setTableNumber(tableNumber);
             table.setStoreId(storeId);
             table.setCategoryId(categoryId);
+            table.setType(actualType);
             table.setCreatedUserId(userId);
         }
-        
-        // 检查是否有重复的桌号(在本次批量添加的列表中)
-        long distinctCount = tables.stream()
-                .map(StoreTable::getTableNumber)
-                .distinct()
-                .count();
-        if (distinctCount != tables.size()) {
-            log.warn("批量新增预订服务桌号失败:本次批量添加的桌号列表中存在重复");
-            throw new RuntimeException("本次批量添加的桌号列表中存在重复");
-        }
-        
-        // 检查同一分类下是否已存在相同的桌号(不同分类可以同名)
-        List<String> tableNumbers = tables.stream()
-                .map(StoreTable::getTableNumber)
-                .collect(Collectors.toList());
-        
-        LambdaQueryWrapper<StoreTable> checkWrapper = new LambdaQueryWrapper<>();
-        checkWrapper.eq(StoreTable::getStoreId, storeId)
-                .eq(StoreTable::getCategoryId, categoryId)
-                .in(StoreTable::getTableNumber, tableNumbers);
-        // @TableLogic 会自动过滤已删除的记录(delete_flag=0)
-        List<StoreTable> existingTables = this.list(checkWrapper);
-        
-        if (!existingTables.isEmpty()) {
-            List<String> existingNumbers = existingTables.stream()
+
+        if (actualType == 1) {
+            // 检查是否有重复的桌号(在本次批量添加的列表中)
+            long distinctCount = tables.stream()
                     .map(StoreTable::getTableNumber)
                     .distinct()
+                    .count();
+            if (distinctCount != tables.size()) {
+                log.warn("批量新增预订服务桌号失败:本次批量添加的桌号列表中存在重复");
+                throw new RuntimeException("本次批量添加的桌号列表中存在重复");
+            }
+
+            // 检查同一分类下是否已存在相同的桌号(不同分类可以同名)
+            List<String> tableNumbers = tables.stream()
+                    .map(StoreTable::getTableNumber)
                     .collect(Collectors.toList());
-            log.warn("批量新增预订服务桌号失败:同一分类下桌号已存在,storeId={}, categoryId={}, existingNumbers={}", 
-                    storeId, categoryId, existingNumbers);
-            if (existingNumbers.size() == 1) {
-                throw new RuntimeException("此桌号已存在");
-            } else {
-                throw new RuntimeException("此桌号已存在:" + String.join("、", existingNumbers));
+
+            LambdaQueryWrapper<StoreTable> checkWrapper = new LambdaQueryWrapper<>();
+            checkWrapper.eq(StoreTable::getStoreId, storeId)
+                    .eq(StoreTable::getCategoryId, categoryId)
+                    .in(StoreTable::getTableNumber, tableNumbers);
+            // @TableLogic 会自动过滤已删除的记录(delete_flag=0)
+            List<StoreTable> existingTables = this.list(checkWrapper);
+
+            if (!existingTables.isEmpty()) {
+                List<String> existingNumbers = existingTables.stream()
+                        .map(StoreTable::getTableNumber)
+                        .distinct()
+                        .collect(Collectors.toList());
+                log.warn("批量新增预订服务桌号失败:同一分类下桌号已存在,storeId={}, categoryId={}, existingNumbers={}",
+                        storeId, categoryId, existingNumbers);
+                if (existingNumbers.size() == 1) {
+                    throw new RuntimeException("此桌号已存在");
+                } else {
+                    throw new RuntimeException("此桌号已存在:" + String.join("、", existingNumbers));
+                }
             }
         }