批量删除菜品
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.DishDTO;
|
||||
import com.sky.dto.DishPageQueryDTO;
|
||||
import com.sky.result.PageResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public interface DishService {
|
||||
|
||||
@@ -11,4 +15,17 @@ public interface DishService {
|
||||
* @param dishDTO
|
||||
*/
|
||||
void saveWithFlavor(DishDTO dishDTO);
|
||||
|
||||
/**
|
||||
* 菜品分页查询
|
||||
* @param pageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
PageResult pageQuery(DishPageQueryDTO pageQueryDTO);
|
||||
|
||||
/**
|
||||
* 菜品批量删除
|
||||
* @param ids
|
||||
*/
|
||||
void deleteBatch(List<Long> ids);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
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.DishDTO;
|
||||
import com.sky.dto.DishPageQueryDTO;
|
||||
import com.sky.entity.Dish;
|
||||
import com.sky.entity.DishFlavor;
|
||||
import com.sky.exception.DeletionNotAllowedException;
|
||||
import com.sky.mapper.DishFlavorMapper;
|
||||
import com.sky.mapper.DishMapper;
|
||||
import com.sky.mapper.SetmealDishMapper;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.service.DishService;
|
||||
import com.sky.vo.DishVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -23,6 +32,8 @@ public class DishServiceImpl implements DishService {
|
||||
private DishMapper dishMapper;
|
||||
@Autowired
|
||||
private DishFlavorMapper dishFlavorMapper;
|
||||
@Autowired
|
||||
private SetmealDishMapper setmealDishMapper;
|
||||
|
||||
/**
|
||||
* 新增菜品
|
||||
@@ -50,4 +61,45 @@ public class DishServiceImpl implements DishService {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜品分页查询
|
||||
* @param pageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PageResult pageQuery(DishPageQueryDTO pageQueryDTO) {
|
||||
//设置分页
|
||||
PageHelper.startPage(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||
Page<DishVO> page = dishMapper.pageQuery(pageQueryDTO);
|
||||
return new PageResult(page.getTotal(),page.getResult());
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜品批量删除
|
||||
* @param ids
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteBatch(List<Long> ids) {
|
||||
//判断菜品是否能够删除
|
||||
//是否有起售中菜品
|
||||
for (Long id : ids) {
|
||||
Dish dish = dishMapper.selectById(id);
|
||||
if (dish.getStatus().equals(StatusConstant.ENABLE)){
|
||||
throw new DeletionNotAllowedException(MessageConstant.DISH_ON_SALE);
|
||||
}
|
||||
}
|
||||
//是否关联套餐
|
||||
List<Long> setmealIds = setmealDishMapper.getSetmealIdsByDishIds(ids);
|
||||
if (setmealIds != null && !setmealIds.isEmpty()){
|
||||
throw new DeletionNotAllowedException(MessageConstant.DISH_BE_RELATED_BY_SETMEAL);
|
||||
}
|
||||
//删除菜品
|
||||
for (Long id : ids) {
|
||||
dishMapper.deleteById(id);
|
||||
//删除菜品口味
|
||||
dishFlavorMapper.deleteByDishId(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user