我不加size()>0只写setmealIds != null 抛异常显示当前菜品关联了套餐
@Transactional
@Override
public void delete(List<Long> ids) {
//1. 判断菜品的状态,起售中的菜品不能删除,提示错误信息
//只需要统计总记录数
Long count = dishMapper.countEnableDishByIds(ids);
if(count > 0) { //这批菜品中包含了起售菜品
throw new DeletionNotAllowedException(MessageConstant.DISH_ON_SALE);
}
//2. 判断菜品是否关联套餐,如果关联套餐,不能删除,提示错误信息
List<Long> setmealIds = setmealDishMapper.getSetmealIdsByDishIds(ids);
if(setmealIds != null && setmealIds.size() > 0) {
throw new DeletionNotAllowedException(MessageConstant.DISH_BE_RELATED_BY_SETMEAL);
}
//3. 删除菜品,并删除菜品口味
dishMapper.deleteByIds(ids);
dishFlavorMapper.deleteByDishIds(ids);
}
<select id="getSetmealIdsByDishIds" resultType="java.lang.Long">
select setmeal_id from setmeal_dish where dish_id in
<foreach collection="ids" item="id" separator="," open="(" close=")">
#{id}
</foreach>
</select>