|
|
@@ -230,16 +230,32 @@ public class StoreBookingCategoryServiceImpl extends ServiceImpl<StoreBookingCat
|
|
|
throw new RuntimeException("分类不存在");
|
|
|
}
|
|
|
|
|
|
- // 校验:检查当前分类下是否有桌号,如果有则不允许删除
|
|
|
+ // 查询当前分类下的所有桌号
|
|
|
LambdaQueryWrapper<StoreBookingTable> tableWrapper = new LambdaQueryWrapper<>();
|
|
|
tableWrapper.eq(StoreBookingTable::getCategoryId, id);
|
|
|
- long tableCount = storeBookingTableService.count(tableWrapper);
|
|
|
- if (tableCount > 0) {
|
|
|
- log.warn("删除预订服务分类失败:当前分类下存在桌号,需要先删除桌号才能删除该分类,categoryId={}, tableCount={}", id, tableCount);
|
|
|
- throw new RuntimeException("当前分类下存在桌号,需要先删除桌号才能删除该分类");
|
|
|
+ // @TableLogic 会自动过滤已删除的记录(delete_flag=0)
|
|
|
+ List<StoreBookingTable> tables = storeBookingTableService.list(tableWrapper);
|
|
|
+
|
|
|
+ // 如果存在桌号,先批量删除这些桌号
|
|
|
+ if (tables != null && !tables.isEmpty()) {
|
|
|
+ List<Integer> tableIds = tables.stream()
|
|
|
+ .map(StoreBookingTable::getId)
|
|
|
+ .collect(java.util.stream.Collectors.toList());
|
|
|
+
|
|
|
+ log.info("删除分类时同时删除该分类下的所有桌号,categoryId={}, tableCount={}, tableIds={}",
|
|
|
+ id, tables.size(), tableIds);
|
|
|
+
|
|
|
+ // 批量逻辑删除桌号
|
|
|
+ boolean deleteTablesResult = storeBookingTableService.removeByIds(tableIds);
|
|
|
+ if (!deleteTablesResult) {
|
|
|
+ log.warn("删除分类下的桌号失败,categoryId={}, tableIds={}", id, tableIds);
|
|
|
+ throw new RuntimeException("删除分类下的桌号失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("成功删除分类下的所有桌号,categoryId={}, tableCount={}", id, tables.size());
|
|
|
}
|
|
|
|
|
|
- // 逻辑删除
|
|
|
+ // 逻辑删除分类
|
|
|
return this.removeById(id);
|
|
|
}
|
|
|
|