批量删除套餐、菜品起售停售(TODO)
This commit is contained in:
@@ -98,9 +98,22 @@ public class DishController {
|
|||||||
*/
|
*/
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@ApiOperation("根据分类id查询菜品")
|
@ApiOperation("根据分类id查询菜品")
|
||||||
public Result<List> list(String categoryId){
|
public Result<List> list(Long categoryId){
|
||||||
log.info("根据分类id查询菜品: {}",categoryId);
|
log.info("根据分类id查询菜品: {}",categoryId);
|
||||||
List<Dish> dishes = dishService.selectByCategoryId(categoryId);
|
List<Dish> dishes = dishService.selectByCategoryId(categoryId);
|
||||||
return Result.success(dishes);
|
return Result.success(dishes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品起售停售
|
||||||
|
* @param status
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/status/{status}")
|
||||||
|
@ApiOperation("菜品起售停售")
|
||||||
|
public Result startOrStop(@PathVariable Integer status,Long id){
|
||||||
|
dishService.startOrStop(status,id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/admin/setmeal")
|
@RequestMapping("/admin/setmeal")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -45,4 +47,17 @@ public class SetmealController {
|
|||||||
setmealService.insert(setmealDTO);
|
setmealService.insert(setmealDTO);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除套餐
|
||||||
|
* @param ids
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@DeleteMapping
|
||||||
|
@ApiOperation("批量删除套餐")
|
||||||
|
public Result delete(@RequestParam List<Long> ids){
|
||||||
|
log.info("批量删除套餐: {}",ids);
|
||||||
|
setmealService.deleteBatch(ids);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,5 +67,5 @@ public interface DishMapper {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Select("select * from dish where category_id = #{categoryId}")
|
@Select("select * from dish where category_id = #{categoryId}")
|
||||||
List<Dish> selectByCategoryId(String categoryId);
|
List<Dish> selectByCategoryId(Long categoryId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,4 +15,6 @@ public interface SetmealDishMapper {
|
|||||||
List<Long> getSetmealIdsByDishIds(List<Long> ids);
|
List<Long> getSetmealIdsByDishIds(List<Long> ids);
|
||||||
|
|
||||||
void insertBatch(List<SetmealDish> setmealDishes);
|
void insertBatch(List<SetmealDish> setmealDishes);
|
||||||
|
|
||||||
|
void deleteBySetmealIds(List<Long> setmealIds);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import com.sky.enumeration.OperationType;
|
|||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface SetmealMapper {
|
public interface SetmealMapper {
|
||||||
|
|
||||||
@@ -23,4 +25,9 @@ public interface SetmealMapper {
|
|||||||
|
|
||||||
@AutoFill(OperationType.INSERT)
|
@AutoFill(OperationType.INSERT)
|
||||||
void insert(Setmeal setmeal);
|
void insert(Setmeal setmeal);
|
||||||
|
|
||||||
|
@Select("select * from setmeal where id = #{id}")
|
||||||
|
Setmeal selectById(Long id);
|
||||||
|
|
||||||
|
void deleteBatch(List<Long> ids);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,5 +49,12 @@ public interface DishService {
|
|||||||
* @param categoryId
|
* @param categoryId
|
||||||
* @return
|
* @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 com.sky.result.PageResult;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public interface SetmealService {
|
public interface SetmealService {
|
||||||
/**
|
/**
|
||||||
@@ -19,4 +21,10 @@ public interface SetmealService {
|
|||||||
* @param setmealDTO
|
* @param setmealDTO
|
||||||
*/
|
*/
|
||||||
void insert(SetmealDTO setmealDTO);
|
void insert(SetmealDTO setmealDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除套餐
|
||||||
|
* @param ids
|
||||||
|
*/
|
||||||
|
void deleteBatch(List<Long> ids);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,7 +159,26 @@ public class DishServiceImpl implements DishService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Dish> selectByCategoryId(String categoryId) {
|
public List<Dish> selectByCategoryId(Long categoryId) {
|
||||||
return dishMapper.selectByCategoryId(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.Page;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.sky.constant.MessageConstant;
|
||||||
|
import com.sky.constant.StatusConstant;
|
||||||
import com.sky.dto.SetmealDTO;
|
import com.sky.dto.SetmealDTO;
|
||||||
import com.sky.dto.SetmealPageQueryDTO;
|
import com.sky.dto.SetmealPageQueryDTO;
|
||||||
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.mapper.SetmealDishMapper;
|
import com.sky.mapper.SetmealDishMapper;
|
||||||
import com.sky.mapper.SetmealMapper;
|
import com.sky.mapper.SetmealMapper;
|
||||||
import com.sky.result.PageResult;
|
import com.sky.result.PageResult;
|
||||||
@@ -52,6 +55,30 @@ public class SetmealServiceImpl implements SetmealService {
|
|||||||
|
|
||||||
//插入套餐包含菜品的信息
|
//插入套餐包含菜品的信息
|
||||||
List<SetmealDish> setmealDishes = setmealDTO.getSetmealDishes();
|
List<SetmealDish> setmealDishes = setmealDTO.getSetmealDishes();
|
||||||
|
//设置setmealId
|
||||||
|
setmealDishes.forEach(setmealDish -> setmealDish.setSetmealId(setmeal.getId()));
|
||||||
setmealDishMapper.insertBatch(setmealDishes);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,12 @@
|
|||||||
(#{sd.setmealId},#{sd.dishId},#{sd.name},#{sd.price},#{sd.copies})
|
(#{sd.setmealId},#{sd.dishId},#{sd.name},#{sd.price},#{sd.copies})
|
||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</insert>
|
||||||
|
<delete id="deleteBySetmealIds">
|
||||||
|
delete from setmeal_dish where setmeal_id in
|
||||||
|
<foreach collection="setmealIds" item="setmealId" separator="," open="(" close=")">
|
||||||
|
#{setmealId}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
|
||||||
<select id="getSetmealIdsByDishIds" resultType="java.lang.Long">
|
<select id="getSetmealIdsByDishIds" resultType="java.lang.Long">
|
||||||
select setmeal_id from setmeal_dish where dish_id in
|
select setmeal_id from setmeal_dish where dish_id in
|
||||||
|
|||||||
@@ -3,12 +3,18 @@
|
|||||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
<mapper namespace="com.sky.mapper.SetmealMapper">
|
<mapper namespace="com.sky.mapper.SetmealMapper">
|
||||||
<insert id="insert">
|
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||||
insert into setmeal(category_id, name, price, status, description, image, create_time, update_time, create_user,
|
insert into setmeal(category_id, name, price, status, description, image, create_time, update_time, create_user,
|
||||||
update_user)
|
update_user)
|
||||||
VALUES (#{categoryId}, #{name}, #{price}, #{status}, #{description}, #{image}, #{createTime}, #{updateTime},
|
VALUES (#{categoryId}, #{name}, #{price}, #{status}, #{description}, #{image}, #{createTime}, #{updateTime},
|
||||||
#{createUser}, #{updateUser})
|
#{createUser}, #{updateUser})
|
||||||
</insert>
|
</insert>
|
||||||
|
<delete id="deleteBatch">
|
||||||
|
delete from setmeal where id in
|
||||||
|
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
|
||||||
<select id="pageQuery" resultType="com.sky.entity.Setmeal">
|
<select id="pageQuery" resultType="com.sky.entity.Setmeal">
|
||||||
select * from setmeal
|
select * from setmeal
|
||||||
|
|||||||
Reference in New Issue
Block a user