|
|
@@ -0,0 +1,99 @@
|
|
|
+package shop.alien.dining.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import shop.alien.entity.store.StoreCuisine;
|
|
|
+import shop.alien.entity.store.StoreCuisineCategory;
|
|
|
+import shop.alien.entity.store.StoreTable;
|
|
|
+import shop.alien.mapper.StoreCuisineCategoryMapper;
|
|
|
+import shop.alien.mapper.StoreCuisineMapper;
|
|
|
+import shop.alien.mapper.StoreTableMapper;
|
|
|
+import shop.alien.dining.service.StoreInfoService;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 门店信息查询服务实现类
|
|
|
+ *
|
|
|
+ * @author system
|
|
|
+ * @since 2025-02-02
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class StoreInfoServiceImpl implements StoreInfoService {
|
|
|
+
|
|
|
+ private final StoreTableMapper storeTableMapper;
|
|
|
+ private final StoreCuisineCategoryMapper storeCuisineCategoryMapper;
|
|
|
+ private final StoreCuisineMapper storeCuisineMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<StoreTable> getTablesByStoreId(Integer storeId) {
|
|
|
+ log.info("根据门店ID查询桌号列表, storeId={}", storeId);
|
|
|
+
|
|
|
+ LambdaQueryWrapper<StoreTable> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(StoreTable::getStoreId, storeId);
|
|
|
+ wrapper.eq(StoreTable::getDeleteFlag, 0);
|
|
|
+ wrapper.orderByAsc(StoreTable::getTableNumber);
|
|
|
+
|
|
|
+ return storeTableMapper.selectList(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<StoreCuisineCategory> getCategoriesByStoreId(Integer storeId) {
|
|
|
+ log.info("根据门店ID查询菜品种类列表, storeId={}", storeId);
|
|
|
+
|
|
|
+ LambdaQueryWrapper<StoreCuisineCategory> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(StoreCuisineCategory::getStoreId, storeId);
|
|
|
+ wrapper.eq(StoreCuisineCategory::getDeleteFlag, 0);
|
|
|
+ wrapper.eq(StoreCuisineCategory::getStatus, 1); // 只查询启用的分类
|
|
|
+ wrapper.orderByAsc(StoreCuisineCategory::getSort); // 按排序字段排序
|
|
|
+
|
|
|
+ return storeCuisineCategoryMapper.selectList(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<StoreCuisine> getCuisinesByCategoryId(Integer categoryId) {
|
|
|
+ log.info("根据菜品种类ID查询菜品信息列表, categoryId={}", categoryId);
|
|
|
+
|
|
|
+ // 先查询分类信息,获取 storeId
|
|
|
+ StoreCuisineCategory category = storeCuisineCategoryMapper.selectById(categoryId);
|
|
|
+ if (category == null) {
|
|
|
+ log.warn("菜品种类不存在, categoryId={}", categoryId);
|
|
|
+ return new java.util.ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询该门店下所有上架的菜品
|
|
|
+ LambdaQueryWrapper<StoreCuisine> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(StoreCuisine::getStoreId, category.getStoreId());
|
|
|
+ wrapper.eq(StoreCuisine::getDeleteFlag, 0);
|
|
|
+ wrapper.eq(StoreCuisine::getShelfStatus, 1); // 只查询上架的菜品
|
|
|
+
|
|
|
+ List<StoreCuisine> allCuisines = storeCuisineMapper.selectList(wrapper);
|
|
|
+
|
|
|
+ // 过滤出包含该分类ID的菜品
|
|
|
+ // categoryIds 是 JSON 数组格式,如:[1,2,3]
|
|
|
+ return allCuisines.stream()
|
|
|
+ .filter(cuisine -> {
|
|
|
+ String categoryIdsStr = cuisine.getCategoryIds();
|
|
|
+ if (StringUtils.isBlank(categoryIdsStr)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ // 解析 JSON 数组
|
|
|
+ List<Integer> categoryIds = JSON.parseArray(categoryIdsStr, Integer.class);
|
|
|
+ return categoryIds != null && categoryIds.contains(categoryId);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.warn("解析菜品分类IDs失败, cuisineId={}, categoryIds={}, error={}",
|
|
|
+ cuisine.getId(), categoryIdsStr, e.getMessage());
|
|
|
+ // 如果解析失败,使用简单的字符串匹配作为降级方案
|
|
|
+ return categoryIdsStr.contains(String.valueOf(categoryId));
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .collect(java.util.stream.Collectors.toList());
|
|
|
+ }
|
|
|
+}
|