|
|
@@ -49,27 +49,6 @@ public class StoreMenuServiceImpl extends ServiceImpl<StoreMenuMapper, StoreMenu
|
|
|
private final LifeGroupBuyThaliMapper lifeGroupBuyThaliMapper;
|
|
|
|
|
|
/**
|
|
|
- * 菜品类型:非推荐
|
|
|
- */
|
|
|
- private static final Integer DISH_TYPE_NON_RECOMMEND = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * 菜品类型:推荐
|
|
|
- */
|
|
|
- private static final Integer DISH_TYPE_RECOMMEND = 1;
|
|
|
-
|
|
|
- /**
|
|
|
- * 点赞状态:未点赞
|
|
|
- */
|
|
|
- private static final Integer LIKE_STATUS_NO = 0;
|
|
|
-
|
|
|
- /**
|
|
|
- * 点赞状态:已点赞
|
|
|
- */
|
|
|
- private static final Integer LIKE_STATUS_YES = 1;
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
* 获取门店菜单
|
|
|
*
|
|
|
* @param storeId 门店id
|
|
|
@@ -270,7 +249,7 @@ public class StoreMenuServiceImpl extends ServiceImpl<StoreMenuMapper, StoreMenu
|
|
|
if (dishType == 0) {
|
|
|
List<LifeGroupBuyThali> lifeGroupBuyThaliList = lifeGroupBuyThaliMapper.selectList(new LambdaQueryWrapper<LifeGroupBuyThali>().in(LifeGroupBuyThali::getDetailId, ids));
|
|
|
if (CollectionUtil.isNotEmpty(lifeGroupBuyThaliList)) {
|
|
|
- return R.fail("该菜品已被团购套餐引用,不能删除");
|
|
|
+ return R.fail("当前菜品存在于团购中,不可删除");
|
|
|
}
|
|
|
flag = this.removeByIds(ids);
|
|
|
} else {
|
|
|
@@ -323,120 +302,4 @@ public class StoreMenuServiceImpl extends ServiceImpl<StoreMenuMapper, StoreMenu
|
|
|
public boolean getMenuLikeStatus(String userId, Integer menuId) {
|
|
|
return lifeLikeRecordMapper.selectCount(new QueryWrapper<LifeLikeRecord>().eq("dianzan_id", userId).eq("huifu_id", menuId).eq("delete_flag", 0)) > 0;
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取门店菜单(客户端)
|
|
|
- * <p>
|
|
|
- * 根据门店ID查询菜单列表,支持按菜品类型和菜单类型筛选。
|
|
|
- * 当查询推荐菜且提供用户手机号时,会批量查询并设置用户的点赞状态。
|
|
|
- * 最终结果按排序字段升序排列。
|
|
|
- * </p>
|
|
|
- *
|
|
|
- * @param storeId 门店ID,必填,必须大于0
|
|
|
- * @param dishType 菜品类型,可选,0:全部, 1:推荐
|
|
|
- * @param phoneId 用户手机号,可选,用于查询用户对推荐菜的点赞状态
|
|
|
- * @param dishMenuType 菜单类型,可选,1-菜单,2-酒水
|
|
|
- * @return 菜单列表,按排序字段升序排列,如果查询结果为空则返回空列表
|
|
|
- */
|
|
|
- @Override
|
|
|
- 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");
|
|
|
- }
|
|
|
-
|
|
|
- // 处理菜品类型参数:当dishType为0时,转换为null以查询所有类型
|
|
|
- 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);
|
|
|
- return menuList;
|
|
|
- }
|
|
|
-
|
|
|
- log.info("获取用户端菜单,门店ID:{},查询到菜单数量:{}", storeId, menuList.size());
|
|
|
-
|
|
|
- // 如果是推荐菜且有用户标识,批量查询并设置点赞状态
|
|
|
- if (DISH_TYPE_RECOMMEND.equals(dishType) && StringUtils.isNotEmpty(phoneId)) {
|
|
|
- setLikeStatusForMenuList(menuList, phoneId);
|
|
|
- } else {
|
|
|
- // 非推荐菜或未提供用户手机号时,设置默认未点赞状态
|
|
|
- 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());
|
|
|
-
|
|
|
- log.info("获取用户端菜单完成,门店ID:{},返回菜单数量:{}", storeId, sortedMenuList.size());
|
|
|
-
|
|
|
- return sortedMenuList;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 批量设置菜单的点赞状态
|
|
|
- * <p>
|
|
|
- * 根据用户手机号和菜单ID列表,批量查询点赞记录,并设置每个菜单的点赞状态
|
|
|
- * </p>
|
|
|
- *
|
|
|
- * @param menuList 菜单列表
|
|
|
- * @param phoneId 用户手机号
|
|
|
- */
|
|
|
- private void setLikeStatusForMenuList(List<StoreMenuVo> menuList, String phoneId) {
|
|
|
- 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("查询到点赞记录数量:{},已点赞菜单数量:{}",
|
|
|
- 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);
|
|
|
- } else {
|
|
|
- item.setIsLike(LIKE_STATUS_NO);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
}
|