批量删除套餐、菜品起售停售(TODO)
This commit is contained in:
@@ -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