|
|
@@ -23,9 +23,7 @@ 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;
|
|
|
@@ -232,7 +230,6 @@ public class StoreMenuServiceImpl extends ServiceImpl<StoreMenuMapper, StoreMenu
|
|
|
return R.success("新增菜品成功");
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 菜品排序信息
|
|
|
*
|
|
|
@@ -290,6 +287,7 @@ public class StoreMenuServiceImpl extends ServiceImpl<StoreMenuMapper, StoreMenu
|
|
|
}
|
|
|
return R.success("删除成功");
|
|
|
}
|
|
|
+
|
|
|
@Override
|
|
|
public StoreMenuVo getMenuCountByStoreId(int storeId) {
|
|
|
StoreMenuVo storeMenuVo = new StoreMenuVo();
|
|
|
@@ -341,79 +339,30 @@ public class StoreMenuServiceImpl extends ServiceImpl<StoreMenuMapper, StoreMenu
|
|
|
* @return 菜单列表,按排序字段升序排列,如果查询结果为空则返回空列表
|
|
|
*/
|
|
|
@Override
|
|
|
- public Map<String, Object> getClientMenuByStoreId(Integer storeId, Integer dishType, String phoneId, Integer dishMenuType) {
|
|
|
- log.info("开始获取用户端菜单,门店ID:{},菜品类型:{},用户手机号:{},菜单类型:{}",
|
|
|
+ public List<StoreMenuVo> getClientMenuByStoreId(Integer storeId, Integer dishType, String phoneId, Integer dishMenuType) {
|
|
|
+ log.info("开始获取用户端菜单,门店ID:{},菜品类型:{},用户手机号:{},菜单类型:{}",
|
|
|
storeId, dishType, phoneId, dishMenuType);
|
|
|
-
|
|
|
+
|
|
|
// 参数校验
|
|
|
if (storeId == null || storeId <= 0) {
|
|
|
log.warn("获取用户端菜单失败,门店ID无效:{}", storeId);
|
|
|
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 = (dishType != null && DISH_TYPE_NON_RECOMMEND.equals(dishType)) ? null : dishType;
|
|
|
+ Integer queryDishType = (DISH_TYPE_NON_RECOMMEND.equals(dishType)) ? null : dishType;
|
|
|
|
|
|
- // 根据筛选条件查询菜单列表(用于返回给前端)
|
|
|
+ // 查询菜单列表
|
|
|
List<StoreMenuVo> menuList = storeMenuMapper.getClientMenuByStoreId(storeId, queryDishType, dishMenuType);
|
|
|
-
|
|
|
- // 如果查询结果为空,返回空列表但保留统计信息
|
|
|
+
|
|
|
+ // 如果查询结果为空,直接返回空列表
|
|
|
if (CollectionUtils.isEmpty(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);
|
|
|
+ return menuList;
|
|
|
}
|
|
|
-
|
|
|
- log.info("获取用户端菜单,门店ID:{},查询到符合条件的菜单数量:{}", storeId, menuList.size());
|
|
|
-
|
|
|
+
|
|
|
+ log.info("获取用户端菜单,门店ID:{},查询到菜单数量:{}", storeId, menuList.size());
|
|
|
+
|
|
|
// 如果是推荐菜且有用户标识,批量查询并设置点赞状态
|
|
|
if (DISH_TYPE_RECOMMEND.equals(dishType) && StringUtils.isNotEmpty(phoneId)) {
|
|
|
setLikeStatusForMenuList(menuList, phoneId);
|
|
|
@@ -421,23 +370,15 @@ public class StoreMenuServiceImpl extends ServiceImpl<StoreMenuMapper, StoreMenu
|
|
|
// 非推荐菜或未提供用户手机号时,设置默认未点赞状态
|
|
|
menuList.forEach(item -> item.setIsLike(LIKE_STATUS_NO));
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 按排序字段升序排序
|
|
|
List<StoreMenuVo> sortedMenuList = menuList.stream()
|
|
|
.sorted(Comparator.comparing(StoreMenuVo::getSort, Comparator.nullsLast(Integer::compareTo)))
|
|
|
.collect(Collectors.toList());
|
|
|
-
|
|
|
- // 构建返回结果
|
|
|
- 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 result;
|
|
|
+
|
|
|
+ log.info("获取用户端菜单完成,门店ID:{},返回菜单数量:{}", storeId, sortedMenuList.size());
|
|
|
+
|
|
|
+ return sortedMenuList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -453,43 +394,43 @@ public class StoreMenuServiceImpl extends ServiceImpl<StoreMenuMapper, StoreMenu
|
|
|
if (CollectionUtils.isEmpty(menuList) || StringUtils.isEmpty(phoneId)) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
log.debug("开始批量查询点赞状态,用户手机号:{},菜单数量:{}", phoneId, menuList.size());
|
|
|
-
|
|
|
+
|
|
|
// 将菜单ID转换为String集合,用于查询点赞记录
|
|
|
Set<String> menuIdStrSet = menuList.stream()
|
|
|
.map(item -> String.valueOf(item.getId()))
|
|
|
.filter(id -> id != null && !"null".equals(id))
|
|
|
.collect(Collectors.toSet());
|
|
|
-
|
|
|
+
|
|
|
if (menuIdStrSet.isEmpty()) {
|
|
|
log.warn("菜单ID集合为空,无法查询点赞状态");
|
|
|
menuList.forEach(item -> item.setIsLike(LIKE_STATUS_NO));
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 批量查询点赞记录
|
|
|
LambdaQueryWrapper<LifeLikeRecord> likeQuery = new LambdaQueryWrapper<>();
|
|
|
likeQuery.eq(LifeLikeRecord::getDianzanId, phoneId)
|
|
|
.in(LifeLikeRecord::getHuifuId, menuIdStrSet);
|
|
|
List<LifeLikeRecord> likeRecordList = lifeLikeRecordMapper.selectList(likeQuery);
|
|
|
-
|
|
|
+
|
|
|
// 构建已点赞的菜单ID集合
|
|
|
Set<String> likedMenuIdSet = likeRecordList.stream()
|
|
|
.map(LifeLikeRecord::getHuifuId)
|
|
|
.filter(id -> id != null)
|
|
|
.collect(Collectors.toSet());
|
|
|
-
|
|
|
- log.debug("查询到点赞记录数量:{},已点赞菜单数量:{}",
|
|
|
+
|
|
|
+ log.debug("查询到点赞记录数量:{},已点赞菜单数量:{}",
|
|
|
likeRecordList.size(), likedMenuIdSet.size());
|
|
|
-
|
|
|
+
|
|
|
// 设置点赞状态
|
|
|
menuList.forEach(item -> {
|
|
|
if (item.getId() == null) {
|
|
|
item.setIsLike(LIKE_STATUS_NO);
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
String menuIdStr = String.valueOf(item.getId());
|
|
|
if (likedMenuIdSet.contains(menuIdStr)) {
|
|
|
item.setIsLike(LIKE_STATUS_YES);
|