|
|
@@ -15,6 +15,7 @@ import shop.alien.store.service.StoreBookingTableService;
|
|
|
import shop.alien.util.common.JwtUtil;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 预订服务桌号表 服务实现类
|
|
|
@@ -75,17 +76,16 @@ public class StoreBookingTableServiceImpl extends ServiceImpl<StoreBookingTableM
|
|
|
String tableNumber = table.getTableNumber().trim();
|
|
|
table.setTableNumber(tableNumber);
|
|
|
|
|
|
- // 检查当前门店下该分类是否已存在相同的桌号
|
|
|
+ // 检查当前门店下是否已存在相同的桌号(不限制分类)
|
|
|
LambdaQueryWrapper<StoreBookingTable> checkWrapper = new LambdaQueryWrapper<>();
|
|
|
checkWrapper.eq(StoreBookingTable::getStoreId, table.getStoreId())
|
|
|
- .eq(StoreBookingTable::getCategoryId, table.getCategoryId())
|
|
|
.eq(StoreBookingTable::getTableNumber, tableNumber);
|
|
|
// @TableLogic 会自动过滤已删除的记录(delete_flag=0)
|
|
|
StoreBookingTable existingTable = this.getOne(checkWrapper);
|
|
|
if (existingTable != null) {
|
|
|
- log.warn("新增预订服务桌号失败:当前分类下桌号已存在,storeId={}, categoryId={}, tableNumber={}",
|
|
|
- table.getStoreId(), table.getCategoryId(), tableNumber);
|
|
|
- throw new RuntimeException("此桌号已存在");
|
|
|
+ log.warn("新增预订服务桌号失败:当前门店下桌号已存在,storeId={}, tableNumber={}",
|
|
|
+ table.getStoreId(), tableNumber);
|
|
|
+ throw new RuntimeException("该桌号已存在不能添加");
|
|
|
}
|
|
|
|
|
|
table.setCreatedUserId(userId);
|
|
|
@@ -94,6 +94,86 @@ public class StoreBookingTableServiceImpl extends ServiceImpl<StoreBookingTableM
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public boolean batchAddTables(Integer storeId, Integer categoryId, List<StoreBookingTable> tables) {
|
|
|
+ log.info("StoreBookingTableServiceImpl.batchAddTables?storeId={}, categoryId={}, tables.size={}",
|
|
|
+ storeId, categoryId, tables != null ? tables.size() : 0);
|
|
|
+
|
|
|
+ // 从JWT获取当前登录用户ID
|
|
|
+ Integer userId = getCurrentUserId();
|
|
|
+
|
|
|
+ // 参数验证
|
|
|
+ if (storeId == null) {
|
|
|
+ log.warn("批量新增预订服务桌号失败:门店ID不能为空");
|
|
|
+ throw new RuntimeException("门店ID不能为空");
|
|
|
+ }
|
|
|
+ if (categoryId == null) {
|
|
|
+ log.warn("批量新增预订服务桌号失败:分类ID不能为空");
|
|
|
+ throw new RuntimeException("分类ID不能为空");
|
|
|
+ }
|
|
|
+ if (tables == null || tables.isEmpty()) {
|
|
|
+ log.warn("批量新增预订服务桌号失败:桌号列表不能为空");
|
|
|
+ throw new RuntimeException("桌号列表不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证并处理每个桌号
|
|
|
+ for (StoreBookingTable table : tables) {
|
|
|
+ if (!StringUtils.hasText(table.getTableNumber())) {
|
|
|
+ log.warn("批量新增预订服务桌号失败:桌号不能为空");
|
|
|
+ throw new RuntimeException("桌号不能为空");
|
|
|
+ }
|
|
|
+ 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.setCreatedUserId(userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查是否有重复的桌号(在本次批量添加的列表中)
|
|
|
+ long distinctCount = tables.stream()
|
|
|
+ .map(StoreBookingTable::getTableNumber)
|
|
|
+ .distinct()
|
|
|
+ .count();
|
|
|
+ if (distinctCount != tables.size()) {
|
|
|
+ log.warn("批量新增预订服务桌号失败:本次批量添加的桌号列表中存在重复");
|
|
|
+ throw new RuntimeException("本次批量添加的桌号列表中存在重复");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查当前门店下是否已存在相同的桌号(不限制分类)
|
|
|
+ List<String> tableNumbers = tables.stream()
|
|
|
+ .map(StoreBookingTable::getTableNumber)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ LambdaQueryWrapper<StoreBookingTable> checkWrapper = new LambdaQueryWrapper<>();
|
|
|
+ checkWrapper.eq(StoreBookingTable::getStoreId, storeId)
|
|
|
+ .in(StoreBookingTable::getTableNumber, tableNumbers);
|
|
|
+ // @TableLogic 会自动过滤已删除的记录(delete_flag=0)
|
|
|
+ List<StoreBookingTable> existingTables = this.list(checkWrapper);
|
|
|
+
|
|
|
+ if (!existingTables.isEmpty()) {
|
|
|
+ List<String> existingNumbers = existingTables.stream()
|
|
|
+ .map(StoreBookingTable::getTableNumber)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ log.warn("批量新增预订服务桌号失败:当前门店下桌号已存在,storeId={}, existingNumbers={}",
|
|
|
+ storeId, existingNumbers);
|
|
|
+ if (existingNumbers.size() == 1) {
|
|
|
+ throw new RuntimeException("该桌号已存在不能添加");
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("以下桌号已存在不能添加:" + String.join("、", existingNumbers));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量保存
|
|
|
+ return this.saveBatch(tables);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public boolean updateTable(StoreBookingTable table) {
|
|
|
log.info("StoreBookingTableServiceImpl.updateTable?table={}", table);
|
|
|
|
|
|
@@ -118,23 +198,18 @@ public class StoreBookingTableServiceImpl extends ServiceImpl<StoreBookingTableM
|
|
|
String tableNumber = table.getTableNumber().trim();
|
|
|
table.setTableNumber(tableNumber);
|
|
|
|
|
|
- // 如果桌号有变化,检查当前门店下该分类是否已存在相同的桌号
|
|
|
- if (!tableNumber.equals(existingTable.getTableNumber()) ||
|
|
|
- (table.getCategoryId() != null && !table.getCategoryId().equals(existingTable.getCategoryId()))) {
|
|
|
- // 确定要检查的分类ID(如果传入了新的分类ID,使用新的;否则使用原有的)
|
|
|
- Integer checkCategoryId = table.getCategoryId() != null ? table.getCategoryId() : existingTable.getCategoryId();
|
|
|
-
|
|
|
+ // 如果桌号有变化,检查当前门店下是否已存在相同的桌号(不限制分类,排除当前记录)
|
|
|
+ if (!tableNumber.equals(existingTable.getTableNumber())) {
|
|
|
LambdaQueryWrapper<StoreBookingTable> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(StoreBookingTable::getStoreId, existingTable.getStoreId())
|
|
|
- .eq(StoreBookingTable::getCategoryId, checkCategoryId)
|
|
|
.eq(StoreBookingTable::getTableNumber, tableNumber)
|
|
|
.ne(StoreBookingTable::getId, table.getId());
|
|
|
// @TableLogic 会自动过滤已删除的记录(delete_flag=0)
|
|
|
StoreBookingTable duplicateTable = this.getOne(wrapper);
|
|
|
if (duplicateTable != null) {
|
|
|
- log.warn("更新预订服务桌号失败:当前分类下桌号已存在,storeId={}, categoryId={}, tableNumber={}, id={}",
|
|
|
- existingTable.getStoreId(), checkCategoryId, tableNumber, table.getId());
|
|
|
- throw new RuntimeException("此桌号已存在");
|
|
|
+ log.warn("更新预订服务桌号失败:当前门店下桌号已存在,storeId={}, tableNumber={}, id={}",
|
|
|
+ existingTable.getStoreId(), tableNumber, table.getId());
|
|
|
+ throw new RuntimeException("该桌号已存在不能编辑");
|
|
|
}
|
|
|
}
|
|
|
}
|