批量删除套餐、菜品起售停售(TODO)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
//更新菜品所关联套餐的状态
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user