|
|
@@ -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));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|