|
|
@@ -4,15 +4,17 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
import shop.alien.entity.store.DrinkInfo;
|
|
|
+import shop.alien.entity.store.StoreImg;
|
|
|
+import shop.alien.entity.store.StoreMenu;
|
|
|
import shop.alien.entity.store.vo.DrinkInfoVo;
|
|
|
-import shop.alien.mapper.DrinkInfoMapper;
|
|
|
+import shop.alien.mapper.StoreImgMapper;
|
|
|
+import shop.alien.mapper.StoreMenuMapper;
|
|
|
import shop.alien.store.service.DrinkInfoService;
|
|
|
|
|
|
import java.util.List;
|
|
|
@@ -20,6 +22,8 @@ import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 酒水餐食信息表 服务实现类
|
|
|
+ * 基于 store_menu 表实现(dish_menu_type: 2=酒水,3=餐食)
|
|
|
+ * 注意:drink_info 表已废弃,现在使用 store_menu 表
|
|
|
*
|
|
|
* @author ssk
|
|
|
* @since 2025-06-13
|
|
|
@@ -28,41 +32,61 @@ import java.util.stream.Collectors;
|
|
|
@Service
|
|
|
@RequiredArgsConstructor
|
|
|
@Transactional
|
|
|
-public class DrinkInfoServiceImpl extends ServiceImpl<DrinkInfoMapper, DrinkInfo> implements DrinkInfoService {
|
|
|
+public class DrinkInfoServiceImpl implements DrinkInfoService {
|
|
|
|
|
|
- private final DrinkInfoMapper drinkInfoMapper;
|
|
|
+ private final StoreMenuMapper storeMenuMapper;
|
|
|
+ private final StoreImgMapper storeImgMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 菜单类型常量
|
|
|
+ * 1 = 菜单(菜品)
|
|
|
+ * 2 = 酒水
|
|
|
+ * 3 = 餐食
|
|
|
+ */
|
|
|
+ private static final String MENU_TYPE_DISH = "1";
|
|
|
+ private static final String MENU_TYPE_DRINK = "2";
|
|
|
+ private static final String MENU_TYPE_FOOD = "3";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 菜单图片类型
|
|
|
+ */
|
|
|
+ private static final Integer IMG_TYPE_MENU = 7;
|
|
|
|
|
|
@Override
|
|
|
- public IPage<DrinkInfoVo> getDrinkInfoPage(int page, int size, Integer storeId, String type, String category, String name, Integer createUserId) {
|
|
|
- LambdaQueryWrapper<DrinkInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- // 软删除条件
|
|
|
- queryWrapper.eq(DrinkInfo::getIsDeleted, 0);
|
|
|
+ public IPage<DrinkInfoVo> getDrinkInfoPage(int page, int size, Integer storeId, Integer type, String category, String name, Integer createUserId) {
|
|
|
+ LambdaQueryWrapper<StoreMenu> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+
|
|
|
+ // type 参数:2=酒水,3=餐食
|
|
|
+ if (type != null) {
|
|
|
+ queryWrapper.eq(StoreMenu::getDishMenuType, type.toString());
|
|
|
+ } else {
|
|
|
+ // 不传则查询酒水和餐食(排除菜品)
|
|
|
+ queryWrapper.in(StoreMenu::getDishMenuType, MENU_TYPE_DRINK, MENU_TYPE_FOOD);
|
|
|
+ }
|
|
|
+
|
|
|
// 筛选条件
|
|
|
if (createUserId != null) {
|
|
|
- queryWrapper.eq(DrinkInfo::getCreateUserId, createUserId);
|
|
|
+ queryWrapper.eq(StoreMenu::getCreatedUserId, createUserId);
|
|
|
}
|
|
|
if (storeId != null) {
|
|
|
- queryWrapper.eq(DrinkInfo::getStoreId, storeId);
|
|
|
- }
|
|
|
- if (type != null && !type.isEmpty()) {
|
|
|
- queryWrapper.eq(DrinkInfo::getType, type);
|
|
|
+ queryWrapper.eq(StoreMenu::getStoreId, storeId);
|
|
|
}
|
|
|
if (category != null && !category.isEmpty()) {
|
|
|
- queryWrapper.eq(DrinkInfo::getCategory, category);
|
|
|
+ queryWrapper.eq(StoreMenu::getCategory, category);
|
|
|
}
|
|
|
if (name != null && !name.isEmpty()) {
|
|
|
- queryWrapper.like(DrinkInfo::getName, name);
|
|
|
+ queryWrapper.like(StoreMenu::getDishName, name);
|
|
|
}
|
|
|
// 按排序和创建时间倒序
|
|
|
- queryWrapper.orderByAsc(DrinkInfo::getSort);
|
|
|
- queryWrapper.orderByDesc(DrinkInfo::getCreateTime);
|
|
|
+ queryWrapper.orderByAsc(StoreMenu::getSort);
|
|
|
+ queryWrapper.orderByDesc(StoreMenu::getCreatedTime);
|
|
|
|
|
|
- IPage<DrinkInfo> drinkInfoPage = drinkInfoMapper.selectPage(new Page<>(page, size), queryWrapper);
|
|
|
+ IPage<StoreMenu> menuPage = storeMenuMapper.selectPage(new Page<>(page, size), queryWrapper);
|
|
|
// 转换为Vo
|
|
|
IPage<DrinkInfoVo> drinkInfoVoPage = new Page<>(page, size);
|
|
|
- drinkInfoVoPage.setTotal(drinkInfoPage.getTotal());
|
|
|
- List<DrinkInfoVo> drinkInfoVoList = drinkInfoPage.getRecords().stream()
|
|
|
- .map(this::convertToVo)
|
|
|
+ drinkInfoVoPage.setTotal(menuPage.getTotal());
|
|
|
+ List<DrinkInfoVo> drinkInfoVoList = menuPage.getRecords().stream()
|
|
|
+ .map(this::convertMenuToVo)
|
|
|
.collect(Collectors.toList());
|
|
|
drinkInfoVoPage.setRecords(drinkInfoVoList);
|
|
|
|
|
|
@@ -71,102 +95,209 @@ public class DrinkInfoServiceImpl extends ServiceImpl<DrinkInfoMapper, DrinkInfo
|
|
|
|
|
|
@Override
|
|
|
public DrinkInfoVo getDrinkInfoById(Integer id) {
|
|
|
- DrinkInfo drinkInfo = drinkInfoMapper.selectById(id);
|
|
|
- if (drinkInfo == null || drinkInfo.getIsDeleted() == 1) {
|
|
|
+ StoreMenu menu = storeMenuMapper.selectById(id);
|
|
|
+ // 验证是否为酒水或餐食类型(排除菜品)
|
|
|
+ if (menu == null || MENU_TYPE_DISH.equals(menu.getDishMenuType())) {
|
|
|
return null;
|
|
|
}
|
|
|
- return convertToVo(drinkInfo);
|
|
|
+ return convertMenuToVo(menu);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean saveDrinkInfo(DrinkInfo drinkInfo) {
|
|
|
- // 设置默认值
|
|
|
- drinkInfo.setIsDeleted(0);
|
|
|
- drinkInfo.setStatus(1); // 默认上架
|
|
|
- drinkInfo.setSort(0); // 默认排序
|
|
|
- return this.save(drinkInfo);
|
|
|
+ // 转换为 StoreMenu 对象
|
|
|
+ StoreMenu menu = new StoreMenu();
|
|
|
+ menu.setStoreId(drinkInfo.getStoreId());
|
|
|
+ menu.setDishName(drinkInfo.getName());
|
|
|
+ menu.setDishPrice(drinkInfo.getPrice());
|
|
|
+ menu.setCostPrice(drinkInfo.getCostPrice());
|
|
|
+ // type: 2=酒水, 3=餐食,默认为酒水
|
|
|
+ menu.setDishMenuType(drinkInfo.getType() != null ? drinkInfo.getType().toString() : MENU_TYPE_DRINK);
|
|
|
+ menu.setCategory(drinkInfo.getCategory());
|
|
|
+ menu.setAlcoholVolume(drinkInfo.getAlcoholVolume() != null ? drinkInfo.getAlcoholVolume().toString() : "0");
|
|
|
+ menu.setFlavor(drinkInfo.getFlavor());
|
|
|
+ menu.setDescription(drinkInfo.getDescription());
|
|
|
+ menu.setDishType(drinkInfo.getIsRecommended() != null ? drinkInfo.getIsRecommended() : 0);
|
|
|
+ menu.setSort(drinkInfo.getSort() != null ? drinkInfo.getSort() : 0);
|
|
|
+ menu.setDishesUnit("份");
|
|
|
+ menu.setLikeCount(0);
|
|
|
+
|
|
|
+ // 保存菜单
|
|
|
+ int result = storeMenuMapper.insert(menu);
|
|
|
+
|
|
|
+ // 如果有图片URL,保存到 store_img 表
|
|
|
+ if (result > 0 && StringUtils.hasText(drinkInfo.getPicUrl())) {
|
|
|
+ StoreImg img = new StoreImg();
|
|
|
+ img.setStoreId(menu.getStoreId());
|
|
|
+ img.setImgType(IMG_TYPE_MENU);
|
|
|
+ img.setImgUrl(drinkInfo.getPicUrl());
|
|
|
+ img.setBusinessId(menu.getId());
|
|
|
+ img.setImgDescription((MENU_TYPE_DRINK.equals(menu.getDishMenuType()) ? "酒水" : "餐食") + "图片-" + menu.getDishName());
|
|
|
+ img.setImgSort(1);
|
|
|
+ storeImgMapper.insert(img);
|
|
|
+
|
|
|
+ // 更新菜单的 img_id
|
|
|
+ menu.setImgId(img.getId());
|
|
|
+ storeMenuMapper.updateById(menu);
|
|
|
+ }
|
|
|
+
|
|
|
+ return result > 0;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean updateDrinkInfo(DrinkInfo drinkInfo) {
|
|
|
- return this.updateById(drinkInfo);
|
|
|
+ if (drinkInfo.getId() == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证是否为酒水或餐食类型(排除菜品)
|
|
|
+ StoreMenu existMenu = storeMenuMapper.selectById(drinkInfo.getId());
|
|
|
+ if (existMenu == null || MENU_TYPE_DISH.equals(existMenu.getDishMenuType())) {
|
|
|
+ log.warn("该商品不是酒水/餐食类型,无法修改");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建更新对象
|
|
|
+ StoreMenu menu = new StoreMenu();
|
|
|
+ menu.setId(drinkInfo.getId());
|
|
|
+ if (StringUtils.hasText(drinkInfo.getName())) {
|
|
|
+ menu.setDishName(drinkInfo.getName());
|
|
|
+ }
|
|
|
+ if (drinkInfo.getPrice() != null) {
|
|
|
+ menu.setDishPrice(drinkInfo.getPrice());
|
|
|
+ }
|
|
|
+ if (drinkInfo.getCostPrice() != null) {
|
|
|
+ menu.setCostPrice(drinkInfo.getCostPrice());
|
|
|
+ }
|
|
|
+ if (drinkInfo.getType() != null) {
|
|
|
+ menu.setDishMenuType(drinkInfo.getType().toString());
|
|
|
+ }
|
|
|
+ if (StringUtils.hasText(drinkInfo.getCategory())) {
|
|
|
+ menu.setCategory(drinkInfo.getCategory());
|
|
|
+ }
|
|
|
+ if (drinkInfo.getAlcoholVolume() != null) {
|
|
|
+ menu.setAlcoholVolume(drinkInfo.getAlcoholVolume().toString());
|
|
|
+ }
|
|
|
+ if (StringUtils.hasText(drinkInfo.getFlavor())) {
|
|
|
+ menu.setFlavor(drinkInfo.getFlavor());
|
|
|
+ }
|
|
|
+ if (StringUtils.hasText(drinkInfo.getDescription())) {
|
|
|
+ menu.setDescription(drinkInfo.getDescription());
|
|
|
+ }
|
|
|
+ if (drinkInfo.getIsRecommended() != null) {
|
|
|
+ menu.setDishType(drinkInfo.getIsRecommended());
|
|
|
+ }
|
|
|
+ if (drinkInfo.getSort() != null) {
|
|
|
+ menu.setSort(drinkInfo.getSort());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理图片更新
|
|
|
+ if (StringUtils.hasText(drinkInfo.getPicUrl())) {
|
|
|
+ // 删除旧图片
|
|
|
+ if (existMenu.getImgId() != null) {
|
|
|
+ storeImgMapper.deleteById(existMenu.getImgId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存新图片
|
|
|
+ StoreImg img = new StoreImg();
|
|
|
+ img.setStoreId(existMenu.getStoreId());
|
|
|
+ img.setImgType(IMG_TYPE_MENU);
|
|
|
+ img.setImgUrl(drinkInfo.getPicUrl());
|
|
|
+ img.setBusinessId(drinkInfo.getId());
|
|
|
+ img.setImgDescription((MENU_TYPE_DRINK.equals(existMenu.getDishMenuType()) ? "酒水" : "餐食") + "图片-" + menu.getDishName());
|
|
|
+ img.setImgSort(1);
|
|
|
+ storeImgMapper.insert(img);
|
|
|
+
|
|
|
+ menu.setImgId(img.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ return storeMenuMapper.updateById(menu) > 0;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean deleteDrinkInfo(Integer id) {
|
|
|
- LambdaUpdateWrapper<DrinkInfo> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- updateWrapper.eq(DrinkInfo::getId, id)
|
|
|
- .set(DrinkInfo::getIsDeleted, 1);
|
|
|
- return this.update(updateWrapper);
|
|
|
+ // 验证是否为酒水或餐食类型(排除菜品)
|
|
|
+ StoreMenu menu = storeMenuMapper.selectById(id);
|
|
|
+ if (menu == null || MENU_TYPE_DISH.equals(menu.getDishMenuType())) {
|
|
|
+ log.warn("该商品不是酒水/餐食类型,无法删除");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 逻辑删除(由 @TableLogic 自动处理)
|
|
|
+ return storeMenuMapper.deleteById(id) > 0;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean updateStatus(Integer id, Integer status) {
|
|
|
- LambdaUpdateWrapper<DrinkInfo> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- updateWrapper.eq(DrinkInfo::getId, id)
|
|
|
- .eq(DrinkInfo::getIsDeleted, 0)
|
|
|
- .set(DrinkInfo::getStatus, status);
|
|
|
- return this.update(updateWrapper);
|
|
|
+ // 注意:store_menu 表有 status 字段了,但 StoreMenu 实体类暂未映射
|
|
|
+ LambdaUpdateWrapper<StoreMenu> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.eq(StoreMenu::getId, id)
|
|
|
+ .in(StoreMenu::getDishMenuType, MENU_TYPE_DRINK, MENU_TYPE_FOOD); // 只允许修改酒水和餐食
|
|
|
+ // TODO: 在 StoreMenu 实体类中添加 status 字段映射后启用
|
|
|
+ // .set(StoreMenu::getStatus, status);
|
|
|
+ return true; // 暂时返回 true
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean updateIsRecommended(Integer id, Integer isRecommended) {
|
|
|
- LambdaUpdateWrapper<DrinkInfo> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- updateWrapper.eq(DrinkInfo::getId, id)
|
|
|
- .eq(DrinkInfo::getIsDeleted, 0)
|
|
|
- .set(DrinkInfo::getIsRecommended, isRecommended);
|
|
|
- return this.update(updateWrapper);
|
|
|
+ LambdaUpdateWrapper<StoreMenu> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.eq(StoreMenu::getId, id)
|
|
|
+ .in(StoreMenu::getDishMenuType, MENU_TYPE_DRINK, MENU_TYPE_FOOD) // 支持酒水和餐食
|
|
|
+ .set(StoreMenu::getDishType, isRecommended);
|
|
|
+ return storeMenuMapper.update(null, updateWrapper) > 0;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean updateSort(Integer id, Integer sort) {
|
|
|
- LambdaUpdateWrapper<DrinkInfo> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- updateWrapper.eq(DrinkInfo::getId, id)
|
|
|
- .eq(DrinkInfo::getIsDeleted, 0)
|
|
|
- .set(DrinkInfo::getSort, sort);
|
|
|
- return this.update(updateWrapper);
|
|
|
+ LambdaUpdateWrapper<StoreMenu> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.eq(StoreMenu::getId, id)
|
|
|
+ .in(StoreMenu::getDishMenuType, MENU_TYPE_DRINK, MENU_TYPE_FOOD) // 支持酒水和餐食
|
|
|
+ .set(StoreMenu::getSort, sort);
|
|
|
+ return storeMenuMapper.update(null, updateWrapper) > 0;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<DrinkInfoVo> getDrinkInfoListByStoreId(Integer storeId, String type) {
|
|
|
- LambdaQueryWrapper<DrinkInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(DrinkInfo::getStoreId, storeId)
|
|
|
- .eq(DrinkInfo::getIsDeleted, 0)
|
|
|
- .eq(DrinkInfo::getStatus, 1); // 只查询上架的
|
|
|
- if (type != null && !type.isEmpty()) {
|
|
|
- queryWrapper.eq(DrinkInfo::getType, type);
|
|
|
- }
|
|
|
- queryWrapper.orderByAsc(DrinkInfo::getSort);
|
|
|
- queryWrapper.orderByDesc(DrinkInfo::getCreateTime);
|
|
|
+ public List<DrinkInfoVo> getDrinkInfoListByStoreId(Integer storeId, Integer type) {
|
|
|
+ LambdaQueryWrapper<StoreMenu> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(StoreMenu::getStoreId, storeId);
|
|
|
+
|
|
|
+ // type 参数:2=酒水,3=餐食
|
|
|
+ if (type != null) {
|
|
|
+ queryWrapper.eq(StoreMenu::getDishMenuType, type.toString());
|
|
|
+ } else {
|
|
|
+ // 不传则查询酒水和餐食(排除菜品)
|
|
|
+ queryWrapper.in(StoreMenu::getDishMenuType, MENU_TYPE_DRINK, MENU_TYPE_FOOD);
|
|
|
+ }
|
|
|
+
|
|
|
+ queryWrapper.orderByAsc(StoreMenu::getSort);
|
|
|
+ queryWrapper.orderByDesc(StoreMenu::getCreatedTime);
|
|
|
|
|
|
- List<DrinkInfo> drinkInfoList = drinkInfoMapper.selectList(queryWrapper);
|
|
|
- return drinkInfoList.stream()
|
|
|
- .map(this::convertToVo)
|
|
|
+ List<StoreMenu> menuList = storeMenuMapper.selectList(queryWrapper);
|
|
|
+ return menuList.stream()
|
|
|
+ .map(this::convertMenuToVo)
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<DrinkInfoVo> getRecommendedList(Integer storeId, Integer createUserId) {
|
|
|
- LambdaQueryWrapper<DrinkInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(DrinkInfo::getIsRecommended, 1)
|
|
|
- .eq(DrinkInfo::getIsDeleted, 0)
|
|
|
- .eq(DrinkInfo::getStatus, 1); // 只查询上架的推荐商品
|
|
|
+ LambdaQueryWrapper<StoreMenu> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(StoreMenu::getDishMenuType, MENU_TYPE_DRINK, MENU_TYPE_FOOD) // 查询酒水和餐食
|
|
|
+ .eq(StoreMenu::getDishType, 1); // 推荐
|
|
|
|
|
|
// 只查询指定用户创建的商品
|
|
|
if (createUserId != null) {
|
|
|
- queryWrapper.eq(DrinkInfo::getCreateUserId, createUserId);
|
|
|
+ queryWrapper.eq(StoreMenu::getCreatedUserId, createUserId);
|
|
|
}
|
|
|
|
|
|
if (storeId != null) {
|
|
|
- // 查询指定门店的商品,或者store_id为null的公共商品
|
|
|
- queryWrapper.and(wrapper -> wrapper.eq(DrinkInfo::getStoreId, storeId));
|
|
|
+ queryWrapper.eq(StoreMenu::getStoreId, storeId);
|
|
|
}
|
|
|
- queryWrapper.orderByAsc(DrinkInfo::getSort);
|
|
|
- queryWrapper.orderByDesc(DrinkInfo::getCreateTime);
|
|
|
+ queryWrapper.orderByAsc(StoreMenu::getSort);
|
|
|
+ queryWrapper.orderByDesc(StoreMenu::getCreatedTime);
|
|
|
|
|
|
- List<DrinkInfo> drinkInfoList = drinkInfoMapper.selectList(queryWrapper);
|
|
|
- return drinkInfoList.stream()
|
|
|
- .map(this::convertToVo)
|
|
|
+ List<StoreMenu> menuList = storeMenuMapper.selectList(queryWrapper);
|
|
|
+ return menuList.stream()
|
|
|
+ .map(this::convertMenuToVo)
|
|
|
.collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
@@ -178,11 +309,11 @@ public class DrinkInfoServiceImpl extends ServiceImpl<DrinkInfoMapper, DrinkInfo
|
|
|
try {
|
|
|
for (DrinkInfo drinkInfo : drinkInfoList) {
|
|
|
if (drinkInfo.getId() != null && drinkInfo.getSort() != null) {
|
|
|
- LambdaUpdateWrapper<DrinkInfo> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- updateWrapper.eq(DrinkInfo::getId, drinkInfo.getId())
|
|
|
- .eq(DrinkInfo::getIsDeleted, 0)
|
|
|
- .set(DrinkInfo::getSort, drinkInfo.getSort());
|
|
|
- this.update(updateWrapper);
|
|
|
+ LambdaUpdateWrapper<StoreMenu> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.eq(StoreMenu::getId, drinkInfo.getId())
|
|
|
+ .in(StoreMenu::getDishMenuType, MENU_TYPE_DRINK, MENU_TYPE_FOOD) // 支持酒水和餐食
|
|
|
+ .set(StoreMenu::getSort, drinkInfo.getSort());
|
|
|
+ storeMenuMapper.update(null, updateWrapper);
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
@@ -194,20 +325,20 @@ public class DrinkInfoServiceImpl extends ServiceImpl<DrinkInfoMapper, DrinkInfo
|
|
|
|
|
|
@Override
|
|
|
public java.util.Map<String, Long> getStatistics(Integer storeId) {
|
|
|
- LambdaQueryWrapper<DrinkInfo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
- queryWrapper.eq(DrinkInfo::getIsDeleted, 0)
|
|
|
- .eq(DrinkInfo::getStatus, 1); // 只统计上架的
|
|
|
+ LambdaQueryWrapper<StoreMenu> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(StoreMenu::getDishMenuType, MENU_TYPE_DRINK, MENU_TYPE_FOOD); // 查询酒水和餐食
|
|
|
+
|
|
|
if (storeId != null) {
|
|
|
- queryWrapper.eq(DrinkInfo::getStoreId, storeId);
|
|
|
+ queryWrapper.eq(StoreMenu::getStoreId, storeId);
|
|
|
}
|
|
|
|
|
|
- List<DrinkInfo> allList = drinkInfoMapper.selectList(queryWrapper);
|
|
|
+ List<StoreMenu> allList = storeMenuMapper.selectList(queryWrapper);
|
|
|
|
|
|
java.util.Map<String, Long> statistics = new java.util.HashMap<>();
|
|
|
statistics.put("total", (long) allList.size());
|
|
|
- statistics.put("drink", allList.stream().filter(d -> "酒水".equals(d.getType())).count());
|
|
|
- statistics.put("food", allList.stream().filter(d -> "餐食".equals(d.getType())).count());
|
|
|
- statistics.put("recommended", allList.stream().filter(d -> d.getIsRecommended() == 1).count());
|
|
|
+ statistics.put("drink", allList.stream().filter(d -> MENU_TYPE_DRINK.equals(d.getDishMenuType())).count());
|
|
|
+ statistics.put("food", allList.stream().filter(d -> MENU_TYPE_FOOD.equals(d.getDishMenuType())).count());
|
|
|
+ statistics.put("recommended", allList.stream().filter(d -> d.getDishType() != null && d.getDishType() == 1).count());
|
|
|
|
|
|
return statistics;
|
|
|
}
|
|
|
@@ -245,16 +376,40 @@ public class DrinkInfoServiceImpl extends ServiceImpl<DrinkInfoMapper, DrinkInfo
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 将DrinkInfo转换为DrinkInfoVo
|
|
|
+ * 将 StoreMenu 转换为 DrinkInfoVo
|
|
|
*
|
|
|
- * @param drinkInfo DrinkInfo对象
|
|
|
+ * @param menu StoreMenu对象
|
|
|
* @return DrinkInfoVo对象
|
|
|
*/
|
|
|
- private DrinkInfoVo convertToVo(DrinkInfo drinkInfo) {
|
|
|
- DrinkInfoVo drinkInfoVo = new DrinkInfoVo();
|
|
|
- BeanUtils.copyProperties(drinkInfo, drinkInfoVo);
|
|
|
- // 确保图片字段正确映射
|
|
|
- drinkInfoVo.setPicUrl(drinkInfo.getPicUrl());
|
|
|
- return drinkInfoVo;
|
|
|
+ private DrinkInfoVo convertMenuToVo(StoreMenu menu) {
|
|
|
+ DrinkInfoVo vo = new DrinkInfoVo();
|
|
|
+ vo.setId(menu.getId());
|
|
|
+ vo.setName(menu.getDishName());
|
|
|
+ vo.setPrice(menu.getDishPrice());
|
|
|
+ vo.setCostPrice(menu.getCostPrice());
|
|
|
+ // 转换类型为数字:2=酒水,3=餐食
|
|
|
+ vo.setType(menu.getDishMenuType() != null ? Integer.parseInt(menu.getDishMenuType()) : 2);
|
|
|
+ vo.setCategory(menu.getCategory());
|
|
|
+ vo.setAlcoholVolume(menu.getAlcoholVolume() != null ? new java.math.BigDecimal(menu.getAlcoholVolume()) : java.math.BigDecimal.ZERO);
|
|
|
+ vo.setFlavor(menu.getFlavor());
|
|
|
+ vo.setDescription(menu.getDescription());
|
|
|
+ vo.setIsRecommended(menu.getDishType());
|
|
|
+ vo.setStoreId(menu.getStoreId());
|
|
|
+ vo.setCreateUserId(menu.getCreatedUserId());
|
|
|
+ vo.setUpdateUserId(menu.getUpdatedUserId());
|
|
|
+ vo.setSort(menu.getSort());
|
|
|
+ vo.setStatus(1); // 默认上架
|
|
|
+ vo.setCreateTime(menu.getCreatedTime());
|
|
|
+ vo.setUpdateTime(menu.getUpdatedTime());
|
|
|
+
|
|
|
+ // 获取图片URL
|
|
|
+ if (menu.getImgId() != null) {
|
|
|
+ StoreImg img = storeImgMapper.selectById(menu.getImgId());
|
|
|
+ if (img != null) {
|
|
|
+ vo.setPicUrl(img.getImgUrl());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return vo;
|
|
|
}
|
|
|
}
|