Compare commits
4 Commits
d8b0a8a391
...
e9bdc8baeb
Author | SHA1 | Date |
---|---|---|
|
e9bdc8baeb | |
|
de3cbdf97e | |
|
3eb910ad07 | |
|
573c1d8e3c |
|
@ -2,6 +2,7 @@ package com.sky.dto;
|
||||||
|
|
||||||
import com.sky.entity.SetmealDish;
|
import com.sky.entity.SetmealDish;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -11,25 +12,18 @@ import java.util.List;
|
||||||
public class SetmealDTO implements Serializable {
|
public class SetmealDTO implements Serializable {
|
||||||
|
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
// 分类id
|
// 分类id
|
||||||
private Long categoryId;
|
private Long categoryId;
|
||||||
|
|
||||||
// 套餐名称
|
// 套餐名称
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
// 套餐价格
|
// 套餐价格
|
||||||
private BigDecimal price;
|
private BigDecimal price;
|
||||||
|
|
||||||
// 状态 0:停用 1:启用
|
// 状态 0:停用 1:启用
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
// 描述信息
|
// 描述信息
|
||||||
private String description;
|
private String description;
|
||||||
|
|
||||||
// 图片
|
// 图片
|
||||||
private String image;
|
private String image;
|
||||||
|
|
||||||
// 套餐菜品关系
|
// 套餐菜品关系
|
||||||
private List<SetmealDish> setmealDishes = new ArrayList<>();
|
private List<SetmealDish> setmealDishes = new ArrayList<>();
|
||||||
|
|
||||||
|
|
|
@ -104,6 +104,7 @@ public class CategoryController {
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@ApiOperation("根据类型查询分类")
|
@ApiOperation("根据类型查询分类")
|
||||||
public Result<List<Category>> list(Integer type) {
|
public Result<List<Category>> list(Integer type) {
|
||||||
|
log.info("根据类型查询分类 type:{}", type);
|
||||||
List<Category> list = categoryService.list(type);
|
List<Category> list = categoryService.list(type);
|
||||||
return Result.success(list);
|
return Result.success(list);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.sky.controller.admin;
|
||||||
|
|
||||||
import com.sky.dto.DishDTO;
|
import com.sky.dto.DishDTO;
|
||||||
import com.sky.dto.DishPageQueryDTO;
|
import com.sky.dto.DishPageQueryDTO;
|
||||||
|
import com.sky.entity.Dish;
|
||||||
import com.sky.result.PageResult;
|
import com.sky.result.PageResult;
|
||||||
import com.sky.result.Result;
|
import com.sky.result.Result;
|
||||||
import com.sky.service.DishService;
|
import com.sky.service.DishService;
|
||||||
|
@ -52,6 +53,7 @@ public class DishController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 菜品批量删除
|
* 菜品批量删除
|
||||||
|
*
|
||||||
* @param ids List<Long>
|
* @param ids List<Long>
|
||||||
* @return Result<String>
|
* @return Result<String>
|
||||||
*/
|
*/
|
||||||
|
@ -65,6 +67,7 @@ public class DishController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据id查询菜品
|
* 根据id查询菜品
|
||||||
|
*
|
||||||
* @param id Long
|
* @param id Long
|
||||||
* @return Result<DishVO>
|
* @return Result<DishVO>
|
||||||
*/
|
*/
|
||||||
|
@ -78,6 +81,7 @@ public class DishController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改菜品
|
* 修改菜品
|
||||||
|
*
|
||||||
* @param dishDTO DishDTO
|
* @param dishDTO DishDTO
|
||||||
* @return Result<String>
|
* @return Result<String>
|
||||||
*/
|
*/
|
||||||
|
@ -88,4 +92,31 @@ public class DishController {
|
||||||
dishService.updateWithFlavor(dishDTO);
|
dishService.updateWithFlavor(dishDTO);
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品起售停售
|
||||||
|
*
|
||||||
|
* @param status 状态
|
||||||
|
* @return Result<String>
|
||||||
|
*/
|
||||||
|
@ApiOperation("菜品起售停售")
|
||||||
|
@PostMapping("/status/{status}")
|
||||||
|
public Result<String> startOrStop(@PathVariable Integer status, Long id) {
|
||||||
|
// 1为起售,0为停售
|
||||||
|
dishService.startOrStop(status, id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据分类id查询菜品
|
||||||
|
*
|
||||||
|
* @param categoryId Long
|
||||||
|
* @return Result<List < Dish>>
|
||||||
|
*/
|
||||||
|
@ApiOperation("根据分类id查询菜品")
|
||||||
|
@GetMapping("list")
|
||||||
|
public Result<List<Dish>> list(Long categoryId) {
|
||||||
|
List<Dish> list = dishService.list(categoryId);
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.sky.controller.admin;
|
||||||
|
|
||||||
|
import com.sky.dto.SetmealDTO;
|
||||||
|
import com.sky.result.Result;
|
||||||
|
import com.sky.service.SetmealService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/admin/setmeal")
|
||||||
|
@Api(tags = "套餐相关接口")
|
||||||
|
@Slf4j
|
||||||
|
public class SetmealController {
|
||||||
|
@Resource
|
||||||
|
private SetmealService setmealService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增套餐
|
||||||
|
*
|
||||||
|
* @param setmealDTO SetmealDTO
|
||||||
|
* @return Result<String>
|
||||||
|
*/
|
||||||
|
@ApiOperation("新增套餐")
|
||||||
|
@PostMapping()
|
||||||
|
public Result<String> save(@RequestBody SetmealDTO setmealDTO) {
|
||||||
|
setmealService.saveWithDish(setmealDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,7 +7,6 @@ import com.sky.entity.Dish;
|
||||||
import com.sky.enumeration.OperationType;
|
import com.sky.enumeration.OperationType;
|
||||||
import com.sky.vo.DishVO;
|
import com.sky.vo.DishVO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -32,6 +31,7 @@ public interface DishMapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 菜品分页查询
|
* 菜品分页查询
|
||||||
|
*
|
||||||
* @param dishPageQueryDTO DishPageQueryDTO
|
* @param dishPageQueryDTO DishPageQueryDTO
|
||||||
* @return Page<DishVO>
|
* @return Page<DishVO>
|
||||||
*/
|
*/
|
||||||
|
@ -39,6 +39,7 @@ public interface DishMapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断当前菜品是否能被删除---是否存在起售菜品
|
* 判断当前菜品是否能被删除---是否存在起售菜品
|
||||||
|
*
|
||||||
* @param id Long
|
* @param id Long
|
||||||
* @return Dish
|
* @return Dish
|
||||||
*/
|
*/
|
||||||
|
@ -46,22 +47,31 @@ public interface DishMapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除菜品表中的菜品数据
|
* 删除菜品表中的菜品数据
|
||||||
|
*
|
||||||
* @param id Long
|
* @param id Long
|
||||||
*/
|
*/
|
||||||
void deleteById(Long id);
|
void deleteById(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除菜品表中的菜品数据
|
* 删除菜品表中的菜品数据
|
||||||
|
*
|
||||||
* @param ids List<Long>
|
* @param ids List<Long>
|
||||||
*/
|
*/
|
||||||
void deleteByIds(List<Long> ids);
|
void deleteByIds(List<Long> ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除原有口味数据
|
* 删除原有口味数据
|
||||||
|
*
|
||||||
* @param dish Dish
|
* @param dish Dish
|
||||||
*/
|
*/
|
||||||
@AutoFill(value = OperationType.UPDATE)
|
@AutoFill(value = OperationType.UPDATE)
|
||||||
void update(Dish dish);
|
void update(Dish dish);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 条件查询菜品和口味
|
||||||
|
*
|
||||||
|
* @param dish Dish
|
||||||
|
* @return List<Dish>
|
||||||
|
*/
|
||||||
|
List<Dish> list(Dish dish);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package com.sky.mapper;
|
package com.sky.mapper;
|
||||||
|
|
||||||
|
import com.sky.annotation.AutoFill;
|
||||||
import com.sky.entity.Setmeal;
|
import com.sky.entity.Setmeal;
|
||||||
|
import com.sky.entity.SetmealDish;
|
||||||
|
import com.sky.enumeration.OperationType;
|
||||||
import com.sky.vo.DishItemVO;
|
import com.sky.vo.DishItemVO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -25,4 +27,18 @@ public interface SetMealDishMapper {
|
||||||
*/
|
*/
|
||||||
List<DishItemVO> getDishItemBySetmealId(Long setmealId);
|
List<DishItemVO> getDishItemBySetmealId(Long setmealId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品起售停售
|
||||||
|
*
|
||||||
|
* @param setmeal Setmeal
|
||||||
|
*/
|
||||||
|
@AutoFill(OperationType.UPDATE)
|
||||||
|
void update(Setmeal setmeal);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 保存套餐和菜品的关联关系
|
||||||
|
*
|
||||||
|
* @param setmealDishes List<SetmealDish>
|
||||||
|
*/
|
||||||
|
void insertBatch(List<SetmealDish> setmealDishes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package com.sky.mapper;
|
package com.sky.mapper;
|
||||||
|
|
||||||
|
import com.sky.annotation.AutoFill;
|
||||||
import com.sky.entity.Setmeal;
|
import com.sky.entity.Setmeal;
|
||||||
|
import com.sky.enumeration.OperationType;
|
||||||
import com.sky.vo.DishItemVO;
|
import com.sky.vo.DishItemVO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -11,6 +12,7 @@ import java.util.List;
|
||||||
public interface SetmealMapper {
|
public interface SetmealMapper {
|
||||||
/**
|
/**
|
||||||
* 根据分类id查询套餐的数量
|
* 根据分类id查询套餐的数量
|
||||||
|
*
|
||||||
* @param id Long
|
* @param id Long
|
||||||
* @return Integer
|
* @return Integer
|
||||||
*/
|
*/
|
||||||
|
@ -18,6 +20,7 @@ public interface SetmealMapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 动态条件查询套餐
|
* 动态条件查询套餐
|
||||||
|
*
|
||||||
* @param setmeal Setmeal
|
* @param setmeal Setmeal
|
||||||
* @return List<Setmeal>
|
* @return List<Setmeal>
|
||||||
*/
|
*/
|
||||||
|
@ -25,8 +28,17 @@ public interface SetmealMapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据套餐id查询菜品选项
|
* 根据套餐id查询菜品选项
|
||||||
|
*
|
||||||
* @param setmealId
|
* @param setmealId
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<DishItemVO> getDishItemBySetmealId(Long setmealId);
|
List<DishItemVO> getDishItemBySetmealId(Long setmealId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 向套餐表插入数据
|
||||||
|
*
|
||||||
|
* @param setmeal Setmeal
|
||||||
|
*/
|
||||||
|
@AutoFill(OperationType.INSERT)
|
||||||
|
void insert(Setmeal setmeal);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ public interface DishService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 菜品分页查询
|
* 菜品分页查询
|
||||||
|
*
|
||||||
* @param dishPageQueryDTO DishPageQueryDTO
|
* @param dishPageQueryDTO DishPageQueryDTO
|
||||||
* @return PageResult
|
* @return PageResult
|
||||||
*/
|
*/
|
||||||
|
@ -25,12 +26,14 @@ public interface DishService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 菜品批量删除
|
* 菜品批量删除
|
||||||
|
*
|
||||||
* @param ids List<Long>
|
* @param ids List<Long>
|
||||||
*/
|
*/
|
||||||
void deleteBatch(List<Long> ids);
|
void deleteBatch(List<Long> ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据id查询菜品
|
* 根据id查询菜品
|
||||||
|
*
|
||||||
* @param id Long
|
* @param id Long
|
||||||
* @return DishVO
|
* @return DishVO
|
||||||
*/
|
*/
|
||||||
|
@ -38,14 +41,32 @@ public interface DishService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改菜品
|
* 修改菜品
|
||||||
|
*
|
||||||
* @param dishDTO DishDTO
|
* @param dishDTO DishDTO
|
||||||
*/
|
*/
|
||||||
void updateWithFlavor(DishDTO dishDTO);
|
void updateWithFlavor(DishDTO dishDTO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 条件查询菜品和口味
|
* 条件查询菜品和口味
|
||||||
* @param dish
|
*
|
||||||
* @return
|
* @param dish Dish
|
||||||
|
* @return List<DishVO>
|
||||||
*/
|
*/
|
||||||
List<DishVO> listWithFlavor(Dish dish);
|
List<DishVO> listWithFlavor(Dish dish);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品起售停售
|
||||||
|
*
|
||||||
|
* @param status 菜品状态
|
||||||
|
* @param id 菜品id
|
||||||
|
*/
|
||||||
|
void startOrStop(Integer status, Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据分类id查询菜品
|
||||||
|
*
|
||||||
|
* @param categoryId Long
|
||||||
|
* @return List<Dish>
|
||||||
|
*/
|
||||||
|
List<Dish> list(Long categoryId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +1,34 @@
|
||||||
package com.sky.service;
|
package com.sky.service;
|
||||||
|
|
||||||
import com.sky.dto.SetmealDTO;
|
import com.sky.dto.SetmealDTO;
|
||||||
import com.sky.dto.SetmealPageQueryDTO;
|
|
||||||
import com.sky.entity.Setmeal;
|
import com.sky.entity.Setmeal;
|
||||||
import com.sky.result.PageResult;
|
|
||||||
import com.sky.vo.DishItemVO;
|
import com.sky.vo.DishItemVO;
|
||||||
import com.sky.vo.SetmealVO;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface SetmealService {
|
public interface SetmealService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 条件查询
|
* 条件查询
|
||||||
* @param setmeal
|
*
|
||||||
* @return
|
* @param setmeal Setmeal
|
||||||
|
* @return List<Setmeal>
|
||||||
*/
|
*/
|
||||||
List<Setmeal> list(Setmeal setmeal);
|
List<Setmeal> list(Setmeal setmeal);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据id查询菜品选项
|
* 根据id查询菜品选项
|
||||||
|
*
|
||||||
* @param id
|
* @param id
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<DishItemVO> getDishItemById(Long id);
|
List<DishItemVO> getDishItemById(Long id);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增套餐,同时需要保存套餐和菜品的关联关系
|
||||||
|
*
|
||||||
|
* @param setmealDTO SetmealDTO
|
||||||
|
*/
|
||||||
|
void saveWithDish(SetmealDTO setmealDTO);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,20 +8,18 @@ import com.sky.dto.DishDTO;
|
||||||
import com.sky.dto.DishPageQueryDTO;
|
import com.sky.dto.DishPageQueryDTO;
|
||||||
import com.sky.entity.Dish;
|
import com.sky.entity.Dish;
|
||||||
import com.sky.entity.DishFlavor;
|
import com.sky.entity.DishFlavor;
|
||||||
|
import com.sky.entity.Setmeal;
|
||||||
import com.sky.exception.DeletionNotAllowedException;
|
import com.sky.exception.DeletionNotAllowedException;
|
||||||
import com.sky.mapper.DishFlavorMapper;
|
import com.sky.mapper.DishFlavorMapper;
|
||||||
import com.sky.mapper.DishMapper;
|
import com.sky.mapper.DishMapper;
|
||||||
import com.sky.mapper.SetMealDishMapper;
|
import com.sky.mapper.SetMealDishMapper;
|
||||||
import com.sky.result.PageResult;
|
import com.sky.result.PageResult;
|
||||||
import com.sky.result.Result;
|
|
||||||
import com.sky.service.DishService;
|
import com.sky.service.DishService;
|
||||||
import com.sky.vo.DishVO;
|
import com.sky.vo.DishVO;
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -149,8 +147,9 @@ public class DishServiceImpl implements DishService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 条件查询菜品和口味
|
* 条件查询菜品和口味
|
||||||
* @param dish
|
*
|
||||||
* @return
|
* @param dish Dish
|
||||||
|
* @return List<DishVO>
|
||||||
*/
|
*/
|
||||||
public List<DishVO> listWithFlavor(Dish dish) {
|
public List<DishVO> listWithFlavor(Dish dish) {
|
||||||
List<Dish> dishList = dishMapper.list(dish);
|
List<Dish> dishList = dishMapper.list(dish);
|
||||||
|
@ -170,4 +169,43 @@ public class DishServiceImpl implements DishService {
|
||||||
|
|
||||||
return dishVOList;
|
return dishVOList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品起售停售
|
||||||
|
*
|
||||||
|
* @param status 菜品状态
|
||||||
|
* @param id 菜品id
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void startOrStop(Integer status, Long id) {
|
||||||
|
// 菜品起售停售
|
||||||
|
Dish dish = Dish.builder().id(id).status(status).build();
|
||||||
|
dishMapper.update(dish);
|
||||||
|
// 如果当前菜品是停售,还需要将其套餐也停售
|
||||||
|
if (status.equals(StatusConstant.DISABLE)) {
|
||||||
|
ArrayList<Long> dishIds = new ArrayList<>();
|
||||||
|
dishIds.add(id);
|
||||||
|
List<Long> setMealDishIds = setMealDishMapper.getSetMealDishIds(dishIds);
|
||||||
|
if (setMealDishIds != null && !setMealDishIds.isEmpty()) {
|
||||||
|
for (Long setMealDishId : setMealDishIds) {
|
||||||
|
Setmeal setmeal = Setmeal.builder().id(setMealDishId)
|
||||||
|
.status(StatusConstant.DISABLE)
|
||||||
|
.build();
|
||||||
|
setMealDishMapper.update(setmeal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据分类id查询菜品
|
||||||
|
*
|
||||||
|
* @param categoryId Long
|
||||||
|
* @return List<Dish>
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Dish> list(Long categoryId) {
|
||||||
|
Dish dish = Dish.builder().categoryId(categoryId).status(StatusConstant.ENABLE).build();
|
||||||
|
return dishMapper.list(dish);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
package com.sky.service.impl;
|
package com.sky.service.impl;
|
||||||
|
|
||||||
|
import com.sky.dto.SetmealDTO;
|
||||||
import com.sky.entity.Setmeal;
|
import com.sky.entity.Setmeal;
|
||||||
|
import com.sky.entity.SetmealDish;
|
||||||
import com.sky.mapper.DishMapper;
|
import com.sky.mapper.DishMapper;
|
||||||
import com.sky.mapper.SetMealDishMapper;
|
import com.sky.mapper.SetMealDishMapper;
|
||||||
import com.sky.mapper.SetmealMapper;
|
import com.sky.mapper.SetmealMapper;
|
||||||
import com.sky.service.SetmealService;
|
import com.sky.service.SetmealService;
|
||||||
import com.sky.vo.DishItemVO;
|
import com.sky.vo.DishItemVO;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
@ -45,4 +48,26 @@ public class SetmealServiceImpl implements SetmealService {
|
||||||
public List<DishItemVO> getDishItemById(Long id) {
|
public List<DishItemVO> getDishItemById(Long id) {
|
||||||
return setmealMapper.getDishItemBySetmealId(id);
|
return setmealMapper.getDishItemBySetmealId(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增套餐,同时需要保存套餐和菜品的关联关系
|
||||||
|
*
|
||||||
|
* @param setmealDTO SetmealDTO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void saveWithDish(SetmealDTO setmealDTO) {
|
||||||
|
Setmeal setmeal = new Setmeal();
|
||||||
|
BeanUtils.copyProperties(setmealDTO, setmeal);
|
||||||
|
|
||||||
|
// 向套餐表插入数据
|
||||||
|
setmealMapper.insert(setmeal);
|
||||||
|
// 获取生成的套餐id
|
||||||
|
Long setmealId = setmeal.getId();
|
||||||
|
List<SetmealDish> setmealDishes = setmealDTO.getSetmealDishes();
|
||||||
|
setmealDishes.forEach(setmealDish -> {
|
||||||
|
setmealDish.setSetmealId(setmealId);
|
||||||
|
});
|
||||||
|
// 保存套餐和菜品的关联关系
|
||||||
|
setmealDishMapper.insertBatch(setmealDishes);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,4 +91,21 @@
|
||||||
from dish
|
from dish
|
||||||
where id = #{id};
|
where id = #{id};
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- 条件查询菜品和口味 -->
|
||||||
|
<select id="list" resultType="com.sky.entity.Dish" parameterType="Dish">
|
||||||
|
select * from dish
|
||||||
|
<where>
|
||||||
|
<if test="name != null">
|
||||||
|
and name like concat('%',#{name},'%')
|
||||||
|
</if>
|
||||||
|
<if test="categoryId != null">
|
||||||
|
and category_id = #{categoryId}
|
||||||
|
</if>
|
||||||
|
<if test="status != null">
|
||||||
|
and status = #{status}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
order by create_time desc
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
@ -2,6 +2,48 @@
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
<mapper namespace="com.sky.mapper.SetMealDishMapper">
|
<mapper namespace="com.sky.mapper.SetMealDishMapper">
|
||||||
|
|
||||||
|
<!-- 保存套餐和菜品的关联关系 -->
|
||||||
|
<insert id="insertBatch" parameterType="list">
|
||||||
|
insert into setmeal_dish
|
||||||
|
(setmeal_id,dish_id,name,price,copies)
|
||||||
|
values
|
||||||
|
<foreach collection="setmealDishes" item="sd" separator=",">
|
||||||
|
(#{sd.setmealId},#{sd.dishId},#{sd.name},#{sd.price},#{sd.copies})
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<!-- 菜品起售停售 -->
|
||||||
|
<update id="update" parameterType="Setmeal">
|
||||||
|
update setmeal
|
||||||
|
<set>
|
||||||
|
<if test="name != null">
|
||||||
|
name = #{name},
|
||||||
|
</if>
|
||||||
|
<if test="categoryId != null">
|
||||||
|
category_id = #{categoryId},
|
||||||
|
</if>
|
||||||
|
<if test="price != null">
|
||||||
|
price = #{price},
|
||||||
|
</if>
|
||||||
|
<if test="status != null">
|
||||||
|
status = #{status},
|
||||||
|
</if>
|
||||||
|
<if test="description != null">
|
||||||
|
description = #{description},
|
||||||
|
</if>
|
||||||
|
<if test="image != null">
|
||||||
|
image = #{image},
|
||||||
|
</if>
|
||||||
|
<if test="updateTime != null">
|
||||||
|
update_time = #{updateTime},
|
||||||
|
</if>
|
||||||
|
<if test="updateUser != null">
|
||||||
|
update_user = #{updateUser}
|
||||||
|
</if>
|
||||||
|
</set>
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
<!-- 查询对应套餐id -->
|
<!-- 查询对应套餐id -->
|
||||||
<select id="getSetMealDishIds" resultType="java.lang.Long">
|
<select id="getSetMealDishIds" resultType="java.lang.Long">
|
||||||
select *
|
select *
|
||||||
|
|
|
@ -2,6 +2,14 @@
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
<mapper namespace="com.sky.mapper.SetmealMapper">
|
<mapper namespace="com.sky.mapper.SetmealMapper">
|
||||||
|
|
||||||
|
<!-- 向套餐表插入数据 -->
|
||||||
|
<insert id="insert" parameterType="Setmeal" useGeneratedKeys="true" keyProperty="id">
|
||||||
|
insert into setmeal
|
||||||
|
(category_id, name, price, status, description, image, create_time, update_time, create_user, update_user)
|
||||||
|
values (#{categoryId}, #{name}, #{price}, #{status}, #{description}, #{image}, #{createTime}, #{updateTime},
|
||||||
|
#{createUser}, #{updateUser})
|
||||||
|
</insert>
|
||||||
|
|
||||||
<!-- 根据分类id查询套餐的数量 -->
|
<!-- 根据分类id查询套餐的数量 -->
|
||||||
<select id="countByCategoryId" resultType="java.lang.Integer">
|
<select id="countByCategoryId" resultType="java.lang.Integer">
|
||||||
select count(id)
|
select count(id)
|
||||||
|
|
Loading…
Reference in New Issue