批量删除套餐、菜品起售停售(TODO)

This commit is contained in:
slhaf
2024-09-12 20:55:15 +08:00
parent e223fbb1a8
commit a65c9e0c69
11 changed files with 115 additions and 5 deletions

View File

@@ -49,5 +49,12 @@ public interface DishService {
* @param categoryId
* @return
*/
List<Dish> selectByCategoryId(String categoryId);
List<Dish> selectByCategoryId(Long categoryId);
/**
* 菜品起售停售
* @param status
* @param id
*/
void startOrStop(Integer status, Long id);
}

View File

@@ -5,6 +5,8 @@ import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public interface SetmealService {
/**
@@ -19,4 +21,10 @@ public interface SetmealService {
* @param setmealDTO
*/
void insert(SetmealDTO setmealDTO);
/**
* 批量删除套餐
* @param ids
*/
void deleteBatch(List<Long> ids);
}

View File

@@ -159,7 +159,26 @@ public class DishServiceImpl implements DishService {
* @return
*/
@Override
public List<Dish> selectByCategoryId(String categoryId) {
public List<Dish> selectByCategoryId(Long categoryId) {
return dishMapper.selectByCategoryId(categoryId);
}
/**
* 菜品起售停售
* @param status
* @param id
*/
@Override
@Transactional
//TODO 菜品关联套餐状态
public void startOrStop(Integer status, Long id) {
//更新菜品状态
Dish dish = Dish.builder()
.id(id)
.status(status)
.build();
dishMapper.update(dish);
//更新菜品所关联套餐的状态
}
}

View File

@@ -2,10 +2,13 @@ package com.sky.service.impl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.constant.MessageConstant;
import com.sky.constant.StatusConstant;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.exception.DeletionNotAllowedException;
import com.sky.mapper.SetmealDishMapper;
import com.sky.mapper.SetmealMapper;
import com.sky.result.PageResult;
@@ -52,6 +55,30 @@ public class SetmealServiceImpl implements SetmealService {
//插入套餐包含菜品的信息
List<SetmealDish> setmealDishes = setmealDTO.getSetmealDishes();
//设置setmealId
setmealDishes.forEach(setmealDish -> setmealDish.setSetmealId(setmeal.getId()));
setmealDishMapper.insertBatch(setmealDishes);
}
/**
* 批量删除套餐
* @param ids
*/
@Override
@Transactional
public void deleteBatch(List<Long> ids) {
//查看套餐是否有在售状态
for (Long id : ids) {
Setmeal setmeal = setmealMapper.selectById(id);
if (setmeal.getStatus().equals(StatusConstant.ENABLE)) {
throw new DeletionNotAllowedException(MessageConstant.SETMEAL_ON_SALE);
}
}
//批量删除套餐动态SQL
//删除setmeal数据
setmealMapper.deleteBatch(ids);
//删除setmeal_dish数据
setmealDishMapper.deleteBySetmealIds(ids);
}
}