|
@@ -11,11 +11,12 @@ import shop.alien.entity.store.dto.CartDTO;
|
|
|
import shop.alien.entity.store.dto.CartItemDTO;
|
|
import shop.alien.entity.store.dto.CartItemDTO;
|
|
|
import shop.alien.entity.store.vo.*;
|
|
import shop.alien.entity.store.vo.*;
|
|
|
import shop.alien.mapper.*;
|
|
import shop.alien.mapper.*;
|
|
|
-import shop.alien.dining.config.BaseRedisService;
|
|
|
|
|
import shop.alien.dining.service.CartService;
|
|
import shop.alien.dining.service.CartService;
|
|
|
import shop.alien.dining.service.DiningService;
|
|
import shop.alien.dining.service.DiningService;
|
|
|
import shop.alien.dining.support.DiningOrderServiceFeeCalculator;
|
|
import shop.alien.dining.support.DiningOrderServiceFeeCalculator;
|
|
|
-import shop.alien.dining.support.StoreBusinessSectionOrdering;
|
|
|
|
|
|
|
+import shop.alien.dining.support.DiningFirstVisitDinerCount;
|
|
|
|
|
+import shop.alien.dining.support.DiningOrderingTableGuard;
|
|
|
|
|
+import shop.alien.dining.support.DiningSearchText;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
@@ -36,30 +37,23 @@ public class DiningServiceImpl implements DiningService {
|
|
|
private final StoreTableMapper storeTableMapper;
|
|
private final StoreTableMapper storeTableMapper;
|
|
|
private final StoreInfoMapper storeInfoMapper;
|
|
private final StoreInfoMapper storeInfoMapper;
|
|
|
private final StoreCuisineMapper storeCuisineMapper;
|
|
private final StoreCuisineMapper storeCuisineMapper;
|
|
|
- private final StoreCuisineCategoryMapper storeCuisineCategoryMapper;
|
|
|
|
|
private final StoreCuisineComboMapper storeCuisineComboMapper;
|
|
private final StoreCuisineComboMapper storeCuisineComboMapper;
|
|
|
private final StoreOrderDetailMapper storeOrderDetailMapper;
|
|
private final StoreOrderDetailMapper storeOrderDetailMapper;
|
|
|
private final LifeDiscountCouponMapper lifeDiscountCouponMapper;
|
|
private final LifeDiscountCouponMapper lifeDiscountCouponMapper;
|
|
|
private final LifeDiscountCouponUserMapper lifeDiscountCouponUserMapper;
|
|
private final LifeDiscountCouponUserMapper lifeDiscountCouponUserMapper;
|
|
|
private final CartService cartService;
|
|
private final CartService cartService;
|
|
|
- private final BaseRedisService baseRedisService;
|
|
|
|
|
private final shop.alien.dining.service.StoreOrderService storeOrderService;
|
|
private final shop.alien.dining.service.StoreOrderService storeOrderService;
|
|
|
- private final shop.alien.mapper.StoreOrderMapper storeOrderMapper;
|
|
|
|
|
private final shop.alien.dining.service.OrderLockService orderLockService;
|
|
private final shop.alien.dining.service.OrderLockService orderLockService;
|
|
|
private final DiningOrderServiceFeeCalculator diningOrderServiceFeeCalculator;
|
|
private final DiningOrderServiceFeeCalculator diningOrderServiceFeeCalculator;
|
|
|
|
|
+ private final DiningOrderingTableGuard diningOrderingTableGuard;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public DiningServiceFeeEstimateVO estimateServiceFee(Integer storeId, Integer tableId, Integer dinerCount, BigDecimal goodsSubtotal) {
|
|
public DiningServiceFeeEstimateVO estimateServiceFee(Integer storeId, Integer tableId, Integer dinerCount, BigDecimal goodsSubtotal) {
|
|
|
if (storeId == null || tableId == null) {
|
|
if (storeId == null || tableId == null) {
|
|
|
throw new RuntimeException("门店ID与桌号ID不能为空");
|
|
throw new RuntimeException("门店ID与桌号ID不能为空");
|
|
|
}
|
|
}
|
|
|
- StoreTable table = storeTableMapper.selectById(tableId);
|
|
|
|
|
- if (table == null) {
|
|
|
|
|
- throw new RuntimeException("桌号不存在");
|
|
|
|
|
- }
|
|
|
|
|
- if (table.getStoreId() == null || !table.getStoreId().equals(storeId)) {
|
|
|
|
|
- throw new RuntimeException("桌号与门店不匹配");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ StoreTable table = diningOrderingTableGuard.requireTable(tableId);
|
|
|
|
|
+ diningOrderingTableGuard.assertTableBelongsToStore(table, storeId);
|
|
|
return diningOrderServiceFeeCalculator.estimate(storeId, tableId, new Date(), dinerCount, goodsSubtotal);
|
|
return diningOrderServiceFeeCalculator.estimate(storeId, tableId, new Date(), dinerCount, goodsSubtotal);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -87,37 +81,23 @@ public class DiningServiceImpl implements DiningService {
|
|
|
@Override
|
|
@Override
|
|
|
public DiningPageInfoVO getDiningPageInfo(Integer tableId, Integer dinerCount) {
|
|
public DiningPageInfoVO getDiningPageInfo(Integer tableId, Integer dinerCount) {
|
|
|
log.info("获取点餐页面信息, tableId={}, dinerCount={}", tableId, dinerCount);
|
|
log.info("获取点餐页面信息, tableId={}, dinerCount={}", tableId, dinerCount);
|
|
|
- StoreTable table = storeTableMapper.selectById(tableId);
|
|
|
|
|
- if (table == null) {
|
|
|
|
|
- throw new RuntimeException("桌号不存在");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ StoreTable table = diningOrderingTableGuard.requireTable(tableId);
|
|
|
|
|
+ StoreInfo storeInfo = diningOrderingTableGuard.requireStore(table);
|
|
|
|
|
+ diningOrderingTableGuard.assertCuisineMenuAllowed(storeInfo, table);
|
|
|
|
|
|
|
|
- StoreInfo storeInfo = storeInfoMapper.selectById(table.getStoreId());
|
|
|
|
|
- if (storeInfo == null) {
|
|
|
|
|
- throw new RuntimeException("门店不存在");
|
|
|
|
|
- }
|
|
|
|
|
- if (!StoreBusinessSectionOrdering.allowsCuisinePricing(storeInfo, table)) {
|
|
|
|
|
- throw new RuntimeException("当前门店适用通用价目点餐,请使用通用价目入口");
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 选择人数:只落库就餐人数,不把餐桌置为就餐中;开台在提交到店/用餐信息(walk-in)时处理
|
|
|
|
|
- if (dinerCount != null && dinerCount > 0) {
|
|
|
|
|
- table.setDinerCount(dinerCount);
|
|
|
|
|
|
|
+ int resolvedDinerCount = DiningFirstVisitDinerCount.resolveOrThrow(table, dinerCount);
|
|
|
|
|
+ if (DiningFirstVisitDinerCount.shouldPersistToDatabase(dinerCount)) {
|
|
|
storeTableMapper.updateById(table);
|
|
storeTableMapper.updateById(table);
|
|
|
- log.info("首客填写用餐人数(餐桌状态不变,未开台), tableId={}, dinerCount={}", tableId, dinerCount);
|
|
|
|
|
|
|
+ log.info("首客填写用餐人数(餐桌状态不变,未开台), tableId={}, dinerCount={}", tableId, resolvedDinerCount);
|
|
|
} else {
|
|
} else {
|
|
|
- if (table.getDinerCount() != null && table.getDinerCount() > 0) {
|
|
|
|
|
- dinerCount = table.getDinerCount();
|
|
|
|
|
- log.info("使用已保存的就餐人数, tableId={}, dinerCount={}, tableStatus={}", tableId, dinerCount, table.getStatus());
|
|
|
|
|
- } else {
|
|
|
|
|
- throw new RuntimeException("请选择用餐人数");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ log.info("使用已保存的就餐人数, tableId={}, dinerCount={}, tableStatus={}",
|
|
|
|
|
+ tableId, resolvedDinerCount, table.getStatus());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
DiningPageInfoVO vo = new DiningPageInfoVO();
|
|
DiningPageInfoVO vo = new DiningPageInfoVO();
|
|
|
vo.setStoreName(storeInfo.getStoreName());
|
|
vo.setStoreName(storeInfo.getStoreName());
|
|
|
vo.setTableNumber(table.getTableNumber());
|
|
vo.setTableNumber(table.getTableNumber());
|
|
|
- vo.setDinerCount(dinerCount);
|
|
|
|
|
|
|
+ vo.setDinerCount(resolvedDinerCount);
|
|
|
vo.setStoreId(table.getStoreId());
|
|
vo.setStoreId(table.getStoreId());
|
|
|
vo.setTableId(tableId);
|
|
vo.setTableId(tableId);
|
|
|
|
|
|
|
@@ -128,22 +108,11 @@ public class DiningServiceImpl implements DiningService {
|
|
|
public List<CuisineListVO> searchCuisines(Integer storeId, String keyword, Integer tableId) {
|
|
public List<CuisineListVO> searchCuisines(Integer storeId, String keyword, Integer tableId) {
|
|
|
log.info("搜索菜品, storeId={}, keyword={}, tableId={}", storeId, keyword, tableId);
|
|
log.info("搜索菜品, storeId={}, keyword={}, tableId={}", storeId, keyword, tableId);
|
|
|
|
|
|
|
|
- StoreTable table = storeTableMapper.selectById(tableId);
|
|
|
|
|
- if (table == null) {
|
|
|
|
|
- throw new RuntimeException("桌号不存在");
|
|
|
|
|
- }
|
|
|
|
|
- if (!Objects.equals(table.getStoreId(), storeId)) {
|
|
|
|
|
- throw new RuntimeException("门店与桌台不匹配");
|
|
|
|
|
- }
|
|
|
|
|
- StoreInfo storeInfoForTable = storeInfoMapper.selectById(storeId);
|
|
|
|
|
- if (!StoreBusinessSectionOrdering.allowsCuisinePricing(storeInfoForTable, table)) {
|
|
|
|
|
- throw new RuntimeException("当前门店适用通用价目点餐,请使用通用价目入口");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ StoreTable table = diningOrderingTableGuard.requireTable(tableId);
|
|
|
|
|
+ diningOrderingTableGuard.assertTableBelongsToStore(table, storeId);
|
|
|
|
|
+ diningOrderingTableGuard.assertCuisineMenuAllowed(table);
|
|
|
|
|
|
|
|
- // 限制搜索关键词长度
|
|
|
|
|
- if (StringUtils.hasText(keyword) && keyword.length() > 10) {
|
|
|
|
|
- keyword = keyword.substring(0, 10);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ keyword = DiningSearchText.clampKeyword(keyword);
|
|
|
|
|
|
|
|
LambdaQueryWrapper<StoreCuisine> wrapper = new LambdaQueryWrapper<>();
|
|
LambdaQueryWrapper<StoreCuisine> wrapper = new LambdaQueryWrapper<>();
|
|
|
wrapper.eq(StoreCuisine::getStoreId, storeId);
|
|
wrapper.eq(StoreCuisine::getStoreId, storeId);
|
|
@@ -162,17 +131,9 @@ public class DiningServiceImpl implements DiningService {
|
|
|
public List<CuisineListVO> getCuisinesByCategory(Integer storeId, Integer categoryId, Integer tableId, Integer page, Integer size) {
|
|
public List<CuisineListVO> getCuisinesByCategory(Integer storeId, Integer categoryId, Integer tableId, Integer page, Integer size) {
|
|
|
log.info("根据分类获取菜品列表, storeId={}, categoryId={}, tableId={}, page={}, size={}", storeId, categoryId, tableId, page, size);
|
|
log.info("根据分类获取菜品列表, storeId={}, categoryId={}, tableId={}, page={}, size={}", storeId, categoryId, tableId, page, size);
|
|
|
|
|
|
|
|
- StoreTable table = storeTableMapper.selectById(tableId);
|
|
|
|
|
- if (table == null) {
|
|
|
|
|
- throw new RuntimeException("桌号不存在");
|
|
|
|
|
- }
|
|
|
|
|
- if (!Objects.equals(table.getStoreId(), storeId)) {
|
|
|
|
|
- throw new RuntimeException("门店与桌台不匹配");
|
|
|
|
|
- }
|
|
|
|
|
- StoreInfo storeInfoForTable = storeInfoMapper.selectById(storeId);
|
|
|
|
|
- if (!StoreBusinessSectionOrdering.allowsCuisinePricing(storeInfoForTable, table)) {
|
|
|
|
|
- throw new RuntimeException("当前门店适用通用价目点餐,请使用通用价目入口");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ StoreTable table = diningOrderingTableGuard.requireTable(tableId);
|
|
|
|
|
+ diningOrderingTableGuard.assertTableBelongsToStore(table, storeId);
|
|
|
|
|
+ diningOrderingTableGuard.assertCuisineMenuAllowed(table);
|
|
|
|
|
|
|
|
if (page == null || page < 1) {
|
|
if (page == null || page < 1) {
|
|
|
page = 1;
|
|
page = 1;
|
|
@@ -208,17 +169,11 @@ public class DiningServiceImpl implements DiningService {
|
|
|
throw new RuntimeException("菜品不存在");
|
|
throw new RuntimeException("菜品不存在");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- StoreTable table = storeTableMapper.selectById(tableId);
|
|
|
|
|
- if (table == null) {
|
|
|
|
|
- throw new RuntimeException("桌号不存在");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ StoreTable table = diningOrderingTableGuard.requireTable(tableId);
|
|
|
if (!Objects.equals(cuisine.getStoreId(), table.getStoreId())) {
|
|
if (!Objects.equals(cuisine.getStoreId(), table.getStoreId())) {
|
|
|
throw new RuntimeException("菜品与桌台门店不匹配");
|
|
throw new RuntimeException("菜品与桌台门店不匹配");
|
|
|
}
|
|
}
|
|
|
- StoreInfo storeInfoForTable = storeInfoMapper.selectById(table.getStoreId());
|
|
|
|
|
- if (!StoreBusinessSectionOrdering.allowsCuisinePricing(storeInfoForTable, table)) {
|
|
|
|
|
- throw new RuntimeException("当前门店适用通用价目点餐,请使用通用价目入口");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ diningOrderingTableGuard.assertCuisineMenuAllowed(table);
|
|
|
|
|
|
|
|
CuisineDetailVO vo = new CuisineDetailVO();
|
|
CuisineDetailVO vo = new CuisineDetailVO();
|
|
|
// 手动映射所有字段,确保所有属性都被正确复制
|
|
// 手动映射所有字段,确保所有属性都被正确复制
|