|
|
@@ -23,7 +23,9 @@ import shop.alien.mapper.StoreMenuMapper;
|
|
|
import shop.alien.store.service.StoreImgService;
|
|
|
import shop.alien.store.service.StoreMenuService;
|
|
|
|
|
|
+import java.util.Collections;
|
|
|
import java.util.Comparator;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
@@ -339,7 +341,7 @@ public class StoreMenuServiceImpl extends ServiceImpl<StoreMenuMapper, StoreMenu
|
|
|
* @return 菜单列表,按排序字段升序排列,如果查询结果为空则返回空列表
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<StoreMenuVo> getClientMenuByStoreId(Integer storeId, Integer dishType, String phoneId, Integer dishMenuType) {
|
|
|
+ public Map<String, Object> getClientMenuByStoreId(Integer storeId, Integer dishType, String phoneId, Integer dishMenuType) {
|
|
|
log.info("开始获取用户端菜单,门店ID:{},菜品类型:{},用户手机号:{},菜单类型:{}",
|
|
|
storeId, dishType, phoneId, dishMenuType);
|
|
|
|
|
|
@@ -349,19 +351,68 @@ public class StoreMenuServiceImpl extends ServiceImpl<StoreMenuMapper, StoreMenu
|
|
|
throw new IllegalArgumentException("门店ID不能为空且必须大于0");
|
|
|
}
|
|
|
|
|
|
+ // 先查询该门店的所有菜单数据(不应用筛选条件),用于统计
|
|
|
+ List<StoreMenuVo> allMenuList = storeMenuMapper.getClientMenuByStoreId(storeId, null, null);
|
|
|
+
|
|
|
+ // 按照四种组合进行分组统计(基于所有菜单数据,不受筛选条件影响):
|
|
|
+ // 1. dish_menu_type = 1(菜单),dish_type = 0(全部)
|
|
|
+ // 2. dish_menu_type = 1(菜单),dish_type = 1(推荐)
|
|
|
+ // 3. dish_menu_type = 2(酒水),dish_type = 0(全部)
|
|
|
+ // 4. dish_menu_type = 2(酒水),dish_type = 1(推荐)
|
|
|
+ Map<String, Integer> countMap = new HashMap<>();
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(allMenuList)) {
|
|
|
+ // 统计:dish_menu_type = 1(菜单),dish_type = 1(推荐)
|
|
|
+ long menuRecommendCount = allMenuList.stream()
|
|
|
+ .filter(item -> "1".equals(item.getDishMenuType())
|
|
|
+ && DISH_TYPE_RECOMMEND.equals(item.getDishType()))
|
|
|
+ .count();
|
|
|
+ countMap.put("menu_recommend", (int) menuRecommendCount);
|
|
|
+
|
|
|
+ // 统计:dish_menu_type = 1(菜单),dish_type = 0(全部)
|
|
|
+ long menuAllCount = allMenuList.stream()
|
|
|
+ .filter(item -> "1".equals(item.getDishMenuType())
|
|
|
+ && (item.getDishType() == null || DISH_TYPE_NON_RECOMMEND.equals(item.getDishType())))
|
|
|
+ .count();
|
|
|
+ countMap.put("menu_all", (int) menuAllCount + (int) menuRecommendCount);
|
|
|
+
|
|
|
+ // 统计:dish_menu_type = 2(酒水),dish_type = 1(推荐)
|
|
|
+ long drinkRecommendCount = allMenuList.stream()
|
|
|
+ .filter(item -> "2".equals(item.getDishMenuType())
|
|
|
+ && DISH_TYPE_RECOMMEND.equals(item.getDishType()))
|
|
|
+ .count();
|
|
|
+ countMap.put("drink_recommend", (int) drinkRecommendCount);
|
|
|
+
|
|
|
+ // 统计:dish_menu_type = 2(酒水),dish_type = 0(全部)
|
|
|
+ long drinkAllCount = allMenuList.stream()
|
|
|
+ .filter(item -> "2".equals(item.getDishMenuType())
|
|
|
+ && (item.getDishType() == null || DISH_TYPE_NON_RECOMMEND.equals(item.getDishType())))
|
|
|
+ .count();
|
|
|
+ countMap.put("drink_all", (int) drinkAllCount + (int) drinkRecommendCount);
|
|
|
+ } else {
|
|
|
+ // 如果没有数据,返回0
|
|
|
+ countMap.put("menu_all", 0);
|
|
|
+ countMap.put("menu_recommend", 0);
|
|
|
+ countMap.put("drink_all", 0);
|
|
|
+ countMap.put("drink_recommend", 0);
|
|
|
+ }
|
|
|
+
|
|
|
// 处理菜品类型参数:当dishType为0时,转换为null以查询所有类型
|
|
|
- Integer queryDishType = (DISH_TYPE_NON_RECOMMEND.equals(dishType)) ? null : dishType;
|
|
|
+ Integer queryDishType = (dishType != null && DISH_TYPE_NON_RECOMMEND.equals(dishType)) ? null : dishType;
|
|
|
|
|
|
- // 查询菜单列表
|
|
|
+ // 根据筛选条件查询菜单列表(用于返回给前端)
|
|
|
List<StoreMenuVo> menuList = storeMenuMapper.getClientMenuByStoreId(storeId, queryDishType, dishMenuType);
|
|
|
|
|
|
- // 如果查询结果为空,直接返回空列表
|
|
|
+ // 如果查询结果为空,返回空列表但保留统计信息
|
|
|
if (CollectionUtils.isEmpty(menuList)) {
|
|
|
- log.info("获取用户端菜单完成,门店ID:{},未查询到菜单数据", storeId);
|
|
|
- return menuList;
|
|
|
+ log.info("获取用户端菜单完成,门店ID:{},未查询到符合条件的菜单数据", storeId);
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("list", Collections.emptyList());
|
|
|
+ result.put("count", countMap);
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
- log.info("获取用户端菜单,门店ID:{},查询到菜单数量:{}", storeId, menuList.size());
|
|
|
+ log.info("获取用户端菜单,门店ID:{},查询到符合条件的菜单数量:{}", storeId, menuList.size());
|
|
|
|
|
|
// 如果是推荐菜且有用户标识,批量查询并设置点赞状态
|
|
|
if (DISH_TYPE_RECOMMEND.equals(dishType) && StringUtils.isNotEmpty(phoneId)) {
|
|
|
@@ -376,9 +427,17 @@ public class StoreMenuServiceImpl extends ServiceImpl<StoreMenuMapper, StoreMenu
|
|
|
.sorted(Comparator.comparing(StoreMenuVo::getSort, Comparator.nullsLast(Integer::compareTo)))
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
- log.info("获取用户端菜单完成,门店ID:{},返回菜单数量:{}", storeId, sortedMenuList.size());
|
|
|
+ // 构建返回结果
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("list", sortedMenuList);
|
|
|
+ result.put("count", countMap);
|
|
|
+
|
|
|
+ log.info("获取用户端菜单完成,门店ID:{},返回菜单数量:{},统计信息:菜单-全部={},菜单-推荐={},酒水-全部={},酒水-推荐={}",
|
|
|
+ storeId, sortedMenuList.size(),
|
|
|
+ countMap.get("menu_all"), countMap.get("menu_recommend"),
|
|
|
+ countMap.get("drink_all"), countMap.get("drink_recommend"));
|
|
|
|
|
|
- return sortedMenuList;
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
/**
|