|
|
@@ -13,13 +13,10 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import shop.alien.entity.store.StoreBookingCategory;
|
|
|
-import shop.alien.entity.store.StoreBookingTable;
|
|
|
-import shop.alien.entity.store.UserReservation;
|
|
|
-import shop.alien.entity.store.UserReservationTable;
|
|
|
+import shop.alien.entity.store.StoreTable;
|
|
|
import shop.alien.entity.store.vo.StoreBookingTableVo;
|
|
|
import shop.alien.mapper.StoreBookingTableMapper;
|
|
|
import shop.alien.mapper.UserReservationMapper;
|
|
|
-import shop.alien.mapper.UserReservationTableMapper;
|
|
|
import shop.alien.store.service.StoreBookingCategoryService;
|
|
|
import shop.alien.store.service.StoreBookingTableService;
|
|
|
import shop.alien.util.common.JwtUtil;
|
|
|
@@ -38,38 +35,35 @@ import java.util.stream.Collectors;
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
@Transactional
|
|
|
-public class StoreBookingTableServiceImpl extends ServiceImpl<StoreBookingTableMapper, StoreBookingTable> implements StoreBookingTableService {
|
|
|
+public class StoreBookingTableServiceImpl extends ServiceImpl<StoreBookingTableMapper, StoreTable> implements StoreBookingTableService {
|
|
|
|
|
|
private final StoreBookingCategoryService storeBookingCategoryService;
|
|
|
- private final UserReservationTableMapper userReservationTableMapper;
|
|
|
private final UserReservationMapper userReservationMapper;
|
|
|
|
|
|
public StoreBookingTableServiceImpl(@Lazy StoreBookingCategoryService storeBookingCategoryService,
|
|
|
- UserReservationTableMapper userReservationTableMapper,
|
|
|
UserReservationMapper userReservationMapper) {
|
|
|
this.storeBookingCategoryService = storeBookingCategoryService;
|
|
|
- this.userReservationTableMapper = userReservationTableMapper;
|
|
|
this.userReservationMapper = userReservationMapper;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<StoreBookingTable> getTableList(Integer storeId, Integer categoryId) {
|
|
|
+ public List<StoreTable> getTableList(Integer storeId, Integer categoryId) {
|
|
|
log.info("StoreBookingTableServiceImpl.getTableList?storeId={}, categoryId={}", storeId, categoryId);
|
|
|
|
|
|
- LambdaQueryWrapper<StoreBookingTable> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(StoreBookingTable::getStoreId, storeId);
|
|
|
+ LambdaQueryWrapper<StoreTable> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(StoreTable::getStoreId, storeId);
|
|
|
|
|
|
// 如果指定了分类ID,则按分类筛选;否则查询全部
|
|
|
if (categoryId != null) {
|
|
|
- wrapper.eq(StoreBookingTable::getCategoryId, categoryId);
|
|
|
+ wrapper.eq(StoreTable::getCategoryId, categoryId);
|
|
|
}
|
|
|
|
|
|
// 查询所有数据,然后在Java中进行排序
|
|
|
- List<StoreBookingTable> list = this.list(wrapper);
|
|
|
+ List<StoreTable> list = this.list(wrapper);
|
|
|
|
|
|
// 自定义排序:根据类别、字母(A-Z)、数字(由小到大)顺序排列
|
|
|
list.sort(Comparator
|
|
|
- .comparing(StoreBookingTable::getCategoryId, Comparator.nullsLast(Integer::compareTo)) // 先按类别排序
|
|
|
+ .comparing(StoreTable::getCategoryId, Comparator.nullsLast(Integer::compareTo)) // 先按类别排序
|
|
|
.thenComparing(table -> parseTableNumberForSort(table.getTableNumber()))); // 再按桌号排序
|
|
|
|
|
|
return list;
|
|
|
@@ -80,7 +74,7 @@ public class StoreBookingTableServiceImpl extends ServiceImpl<StoreBookingTableM
|
|
|
log.info("StoreBookingTableServiceImpl.getTableListWithCategoryName?storeId={}, categoryId={}", storeId, categoryId);
|
|
|
|
|
|
// 先查询桌号列表
|
|
|
- List<StoreBookingTable> tableList = getTableList(storeId, categoryId);
|
|
|
+ List<StoreTable> tableList = getTableList(storeId, categoryId);
|
|
|
|
|
|
// 查询所有分类信息,构建categoryId -> categoryName的映射
|
|
|
List<StoreBookingCategory> categoryList = storeBookingCategoryService.list(
|
|
|
@@ -198,7 +192,7 @@ public class StoreBookingTableServiceImpl extends ServiceImpl<StoreBookingTableM
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean addTable(StoreBookingTable table) {
|
|
|
+ public boolean addTable(StoreTable table) {
|
|
|
log.info("StoreBookingTableServiceImpl.addTable?table={}", table);
|
|
|
|
|
|
// 从JWT获取当前登录用户ID
|
|
|
@@ -227,12 +221,12 @@ public class StoreBookingTableServiceImpl extends ServiceImpl<StoreBookingTableM
|
|
|
table.setTableNumber(tableNumber);
|
|
|
|
|
|
// 检查同一分类下是否已存在相同的桌号(不同分类可以同名)
|
|
|
- LambdaQueryWrapper<StoreBookingTable> checkWrapper = new LambdaQueryWrapper<>();
|
|
|
- checkWrapper.eq(StoreBookingTable::getStoreId, table.getStoreId())
|
|
|
- .eq(StoreBookingTable::getCategoryId, table.getCategoryId())
|
|
|
- .eq(StoreBookingTable::getTableNumber, tableNumber);
|
|
|
+ LambdaQueryWrapper<StoreTable> checkWrapper = new LambdaQueryWrapper<>();
|
|
|
+ checkWrapper.eq(StoreTable::getStoreId, table.getStoreId())
|
|
|
+ .eq(StoreTable::getCategoryId, table.getCategoryId())
|
|
|
+ .eq(StoreTable::getTableNumber, tableNumber);
|
|
|
// @TableLogic 会自动过滤已删除的记录(delete_flag=0)
|
|
|
- StoreBookingTable existingTable = this.getOne(checkWrapper);
|
|
|
+ StoreTable existingTable = this.getOne(checkWrapper);
|
|
|
if (existingTable != null) {
|
|
|
log.warn("新增预订服务桌号失败:同一分类下桌号已存在,storeId={}, categoryId={}, tableNumber={}",
|
|
|
table.getStoreId(), table.getCategoryId(), tableNumber);
|
|
|
@@ -245,7 +239,7 @@ public class StoreBookingTableServiceImpl extends ServiceImpl<StoreBookingTableM
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean batchAddTables(Integer storeId, Integer categoryId, List<StoreBookingTable> tables) {
|
|
|
+ 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);
|
|
|
|
|
|
@@ -267,7 +261,7 @@ public class StoreBookingTableServiceImpl extends ServiceImpl<StoreBookingTableM
|
|
|
}
|
|
|
|
|
|
// 验证并处理每个桌号
|
|
|
- for (StoreBookingTable table : tables) {
|
|
|
+ for (StoreTable table : tables) {
|
|
|
if (!StringUtils.hasText(table.getTableNumber())) {
|
|
|
log.warn("批量新增预订服务桌号失败:桌号不能为空");
|
|
|
throw new RuntimeException("桌号不能为空");
|
|
|
@@ -287,7 +281,7 @@ public class StoreBookingTableServiceImpl extends ServiceImpl<StoreBookingTableM
|
|
|
|
|
|
// 检查是否有重复的桌号(在本次批量添加的列表中)
|
|
|
long distinctCount = tables.stream()
|
|
|
- .map(StoreBookingTable::getTableNumber)
|
|
|
+ .map(StoreTable::getTableNumber)
|
|
|
.distinct()
|
|
|
.count();
|
|
|
if (distinctCount != tables.size()) {
|
|
|
@@ -297,19 +291,19 @@ public class StoreBookingTableServiceImpl extends ServiceImpl<StoreBookingTableM
|
|
|
|
|
|
// 检查同一分类下是否已存在相同的桌号(不同分类可以同名)
|
|
|
List<String> tableNumbers = tables.stream()
|
|
|
- .map(StoreBookingTable::getTableNumber)
|
|
|
+ .map(StoreTable::getTableNumber)
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
- LambdaQueryWrapper<StoreBookingTable> checkWrapper = new LambdaQueryWrapper<>();
|
|
|
- checkWrapper.eq(StoreBookingTable::getStoreId, storeId)
|
|
|
- .eq(StoreBookingTable::getCategoryId, categoryId)
|
|
|
- .in(StoreBookingTable::getTableNumber, tableNumbers);
|
|
|
+ LambdaQueryWrapper<StoreTable> checkWrapper = new LambdaQueryWrapper<>();
|
|
|
+ checkWrapper.eq(StoreTable::getStoreId, storeId)
|
|
|
+ .eq(StoreTable::getCategoryId, categoryId)
|
|
|
+ .in(StoreTable::getTableNumber, tableNumbers);
|
|
|
// @TableLogic 会自动过滤已删除的记录(delete_flag=0)
|
|
|
- List<StoreBookingTable> existingTables = this.list(checkWrapper);
|
|
|
+ List<StoreTable> existingTables = this.list(checkWrapper);
|
|
|
|
|
|
if (!existingTables.isEmpty()) {
|
|
|
List<String> existingNumbers = existingTables.stream()
|
|
|
- .map(StoreBookingTable::getTableNumber)
|
|
|
+ .map(StoreTable::getTableNumber)
|
|
|
.distinct()
|
|
|
.collect(Collectors.toList());
|
|
|
log.warn("批量新增预订服务桌号失败:同一分类下桌号已存在,storeId={}, categoryId={}, existingNumbers={}",
|
|
|
@@ -326,7 +320,7 @@ public class StoreBookingTableServiceImpl extends ServiceImpl<StoreBookingTableM
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public boolean updateTable(StoreBookingTable table) {
|
|
|
+ public boolean updateTable(StoreTable table) {
|
|
|
log.info("StoreBookingTableServiceImpl.updateTable?table={}", table);
|
|
|
|
|
|
// 从JWT获取当前登录用户ID
|
|
|
@@ -338,7 +332,7 @@ public class StoreBookingTableServiceImpl extends ServiceImpl<StoreBookingTableM
|
|
|
throw new RuntimeException("桌号ID不能为空");
|
|
|
}
|
|
|
|
|
|
- StoreBookingTable existingTable = this.getById(table.getId());
|
|
|
+ StoreTable existingTable = this.getById(table.getId());
|
|
|
if (existingTable == null) {
|
|
|
log.warn("更新预订服务桌号失败:桌号不存在,id={}", table.getId());
|
|
|
throw new RuntimeException("桌号不存在");
|
|
|
@@ -355,13 +349,13 @@ public class StoreBookingTableServiceImpl extends ServiceImpl<StoreBookingTableM
|
|
|
// 如果分类ID也变化了,使用新的分类ID;否则使用原有的分类ID
|
|
|
Integer checkCategoryId = table.getCategoryId() != null ? table.getCategoryId() : existingTable.getCategoryId();
|
|
|
|
|
|
- LambdaQueryWrapper<StoreBookingTable> wrapper = new LambdaQueryWrapper<>();
|
|
|
- wrapper.eq(StoreBookingTable::getStoreId, existingTable.getStoreId())
|
|
|
- .eq(StoreBookingTable::getCategoryId, checkCategoryId)
|
|
|
- .eq(StoreBookingTable::getTableNumber, tableNumber)
|
|
|
- .ne(StoreBookingTable::getId, table.getId());
|
|
|
+ LambdaQueryWrapper<StoreTable> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(StoreTable::getStoreId, existingTable.getStoreId())
|
|
|
+ .eq(StoreTable::getCategoryId, checkCategoryId)
|
|
|
+ .eq(StoreTable::getTableNumber, tableNumber)
|
|
|
+ .ne(StoreTable::getId, table.getId());
|
|
|
// @TableLogic 会自动过滤已删除的记录(delete_flag=0)
|
|
|
- StoreBookingTable duplicateTable = this.getOne(wrapper);
|
|
|
+ StoreTable duplicateTable = this.getOne(wrapper);
|
|
|
if (duplicateTable != null) {
|
|
|
log.warn("更新预订服务桌号失败:同一分类下桌号已存在,storeId={}, categoryId={}, tableNumber={}, id={}",
|
|
|
existingTable.getStoreId(), checkCategoryId, tableNumber, table.getId());
|
|
|
@@ -377,21 +371,21 @@ public class StoreBookingTableServiceImpl extends ServiceImpl<StoreBookingTableM
|
|
|
}
|
|
|
|
|
|
// 更新字段
|
|
|
- LambdaUpdateWrapper<StoreBookingTable> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- updateWrapper.eq(StoreBookingTable::getId, table.getId());
|
|
|
+ LambdaUpdateWrapper<StoreTable> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.eq(StoreTable::getId, table.getId());
|
|
|
|
|
|
if (StringUtils.hasText(table.getTableNumber())) {
|
|
|
- updateWrapper.set(StoreBookingTable::getTableNumber, table.getTableNumber());
|
|
|
+ updateWrapper.set(StoreTable::getTableNumber, table.getTableNumber());
|
|
|
}
|
|
|
if (table.getCategoryId() != null) {
|
|
|
- updateWrapper.set(StoreBookingTable::getCategoryId, table.getCategoryId());
|
|
|
+ updateWrapper.set(StoreTable::getCategoryId, table.getCategoryId());
|
|
|
}
|
|
|
if (table.getSeatingCapacity() != null) {
|
|
|
- updateWrapper.set(StoreBookingTable::getSeatingCapacity, table.getSeatingCapacity());
|
|
|
+ updateWrapper.set(StoreTable::getSeatingCapacity, table.getSeatingCapacity());
|
|
|
}
|
|
|
|
|
|
if (userId != null) {
|
|
|
- updateWrapper.set(StoreBookingTable::getUpdatedUserId, userId);
|
|
|
+ updateWrapper.set(StoreTable::getUpdatedUserId, userId);
|
|
|
}
|
|
|
|
|
|
return this.update(updateWrapper);
|
|
|
@@ -401,7 +395,7 @@ public class StoreBookingTableServiceImpl extends ServiceImpl<StoreBookingTableM
|
|
|
public boolean deleteTable(Integer id) {
|
|
|
log.info("StoreBookingTableServiceImpl.deleteTable?id={}", id);
|
|
|
|
|
|
- StoreBookingTable table = this.getById(id);
|
|
|
+ StoreTable table = this.getById(id);
|
|
|
if (table == null) {
|
|
|
log.warn("删除预订服务桌号失败:桌号不存在,id={}", id);
|
|
|
throw new RuntimeException("桌号不存在");
|