删除套餐

This commit is contained in:
Bunny 2024-01-09 09:57:39 +08:00
parent 612a929ddf
commit 25cf3769ec
7 changed files with 90 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List;
@RestController @RestController
@RequestMapping("/admin/setmeal") @RequestMapping("/admin/setmeal")
@ -59,4 +60,17 @@ public class SetmealController {
setmealService.startOrStop(status, id); setmealService.startOrStop(status, id);
return Result.success(); return Result.success();
} }
/**
* 批量删除套餐
*
* @param ids 删除集合
* @return Null
*/
@ApiOperation("批量删除套餐")
@DeleteMapping("")
public Result delete(@RequestParam List<Long> ids) {
setmealService.delete(ids);
return Result.success();
}
} }

View File

@ -52,4 +52,11 @@ public interface SetMealDishMapper {
* @return Page<SetmealVO> * @return Page<SetmealVO>
*/ */
Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO); Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
/**
* 根据套餐id删除套餐和菜品的关联关系
*
* @param setmealId Long
*/
void deleteBySetmealId(Long setmealId);
} }

View File

@ -49,4 +49,20 @@ public interface SetmealMapper {
*/ */
@AutoFill(OperationType.UPDATE) @AutoFill(OperationType.UPDATE)
void update(Setmeal setmeal); void update(Setmeal setmeal);
/**
* 根据id获取套餐
*
* @param id Long
* @return Setmeal
*/
Setmeal getById(Long id);
/**
* 删除套餐表中的数据
*
* @param setmealId Long
*/
void deleteById(Long setmealId);
} }

View File

@ -49,4 +49,11 @@ public interface SetmealService {
* @param id Long * @param id Long
*/ */
void startOrStop(Integer status, Long id); void startOrStop(Integer status, Long id);
/**
* 批量删除套餐
*
* @param ids List<Long>
*/
void delete(List<Long> ids);
} }

View File

@ -9,6 +9,7 @@ import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Dish; import com.sky.entity.Dish;
import com.sky.entity.Setmeal; import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish; import com.sky.entity.SetmealDish;
import com.sky.exception.DeletionNotAllowedException;
import com.sky.exception.SetmealEnableFailedException; import com.sky.exception.SetmealEnableFailedException;
import com.sky.mapper.DishMapper; import com.sky.mapper.DishMapper;
import com.sky.mapper.SetMealDishMapper; import com.sky.mapper.SetMealDishMapper;
@ -119,4 +120,28 @@ public class SetmealServiceImpl implements SetmealService {
Setmeal setmeal = Setmeal.builder().id(id).status(status).build(); Setmeal setmeal = Setmeal.builder().id(id).status(status).build();
setmealMapper.update(setmeal); setmealMapper.update(setmeal);
} }
/**
* 批量删除套餐
*
* @param ids List<Long>
*/
@Override
public void delete(List<Long> ids) {
ids.forEach(id -> {
// 根据id获取套餐
Setmeal setmeal = setmealMapper.getById(id);
// 起售中商品不能删除
if (setmeal.getStatus().equals(StatusConstant.ENABLE)) {
throw new DeletionNotAllowedException(MessageConstant.SETMEAL_ON_SALE);
}
});
ids.forEach(setmealId -> {
// 删除套餐表中的数据
setmealMapper.deleteById(setmealId);
// 删除套餐菜品关系表中的数据
setmealDishMapper.deleteBySetmealId(setmealId);
});
}
} }

View File

@ -44,6 +44,13 @@
where id = #{id} where id = #{id}
</update> </update>
<!-- 根据套餐id删除套餐和菜品的关联关系 -->
<delete id="deleteBySetmealId">
delete
from setmeal_dish
where setmeal_id = #{setmealId}
</delete>
<!-- 查询对应套餐id --> <!-- 查询对应套餐id -->
<select id="getSetMealDishIds" resultType="java.lang.Long"> <select id="getSetMealDishIds" resultType="java.lang.Long">
select * select *

View File

@ -48,6 +48,13 @@
where id = #{id}; where id = #{id};
</update> </update>
<!-- 根据套餐id删除套餐和菜品的关联关系 -->
<delete id="deleteById">
delete
from setmeal
where id = #{id}
</delete>
<!-- 根据分类id查询套餐的数量 --> <!-- 根据分类id查询套餐的数量 -->
<select id="countByCategoryId" resultType="java.lang.Integer"> <select id="countByCategoryId" resultType="java.lang.Integer">
select count(id) select count(id)
@ -78,4 +85,11 @@
left join dish d on sd.dish_id = d.id left join dish d on sd.dish_id = d.id
where sd.setmeal_id = #{setmealId} where sd.setmeal_id = #{setmealId}
</select> </select>
<!-- 根据id获取套餐 -->
<select id="getById" resultType="com.sky.entity.Setmeal">
select *
from setmeal
where id = #{id}
</select>
</mapper> </mapper>