对菜品套餐模块相关接口功能补充和注释描述

main
Artyom 7 months ago
parent 2a7d2572ad
commit c9c036c244

@ -17,9 +17,9 @@
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="sky-common" options="" />
<module name="sky-pojo" options="" />
<module name="sky-server" options="" />
<module name="sky-common" options="-parameters" />
<module name="sky-pojo" options="-parameters" />
<module name="sky-server" options="-parameters" />
</option>
</component>
</project>

@ -1,6 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="http://maven.aliyun.com/nexus/content/groups/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />

@ -14,7 +14,7 @@
</set>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/sky-take-out.iml" filepath="$PROJECT_DIR$/sky-take-out.iml" />
</modules>
</component>
</project>

@ -1,10 +1,7 @@
package com.sky.controller.admin;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.constant.StatusConstant;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
@ -13,97 +10,48 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Set;
/*
*
* */
@RestController
@RequestMapping("/admin/dish")
@Api(tags = "菜品相关接口")
@RestController("userDishController")
@RequestMapping("/user/dish")
@Slf4j
@Api(tags = "C端-菜品浏览接口")
public class DishController {
@Autowired
private DishService dishService;
@Autowired
private RedisTemplate redisTemplate;
@PostMapping
@ApiOperation("新增菜品")
public Result save(@RequestBody DishDTO dishDTO){
log.info("新增菜品:{}",dishDTO);
dishService.saveWithFlavor(dishDTO);
//清理缓存数据
String key = "dish_" + dishDTO.getCategoryId();
redisTemplate.delete(key);
return Result.success();
}
@GetMapping("/page")
@ApiOperation("菜品分页查询")
public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO){
log.info("菜品分页查询:{}",dishPageQueryDTO);
PageResult pageResult = dishService.pageQuery(dishPageQueryDTO);
return Result.success(pageResult);
}
@DeleteMapping
@ApiOperation("批量删除菜品")
public Result delete(@RequestParam List<Long> ids){
log.info("菜品批量删除:{}",ids);
dishService.deleteBatch(ids);
//将所有菜品缓存数据清理掉所有以dish_开头的key
cleanCache("dish_*");
return Result.success();
}
@GetMapping("/{id}")
@ApiOperation("根据菜品id获取信息")
public Result<DishVO> getById(@PathVariable Long id){
log.info("根据id获取菜品{}",id);
DishVO dishVO = dishService.getById(id);
return Result.success(dishVO);
}
@PutMapping
@ApiOperation("修改菜品")
public Result update(@RequestBody DishDTO dishDTO){
log.info("修改菜品:{}",dishDTO);
dishService.updateWithFlavor(dishDTO);
//将所有菜品缓存数据清理掉所有以dish_开头的key
cleanCache("dish_*");
return Result.success();
}
@ApiOperation("起售停售菜品")
@PostMapping("/status/{status}")
public Result StartOrStop(@PathVariable Integer status,Integer id){
log.info("起售停售菜品:{}",status == 1 ? "起售" : "停售");
dishService.startOrStop(status,id);
//将所有菜品缓存数据清理掉所有以dish_开头的key
cleanCache("dish_*");
return Result.success();
}
/**
* id
*
* @param categoryId
* @return
*/
@GetMapping("/list")
@ApiOperation("根据分类id查询菜品")
public Result<List<Dish>> getByCategoryId(Long categoryId){
log.info("根据分类id查询菜品{}",categoryId);
List<Dish> list = dishService.getByCategoryId(categoryId);
public Result<List<DishVO>> list(Long categoryId) {
//构造redis中的key规则 dish_key分类id
String key = "dish_" + categoryId;
//查询redis中是否存在菜品数据
List<DishVO> list = (List<DishVO>) redisTemplate.opsForValue().get(key);
if(list != null && list.size() >0){
//如果存在,直接返回,无须查询数据库
return Result.success(list);
}
//如果不存在查询数据库将查询到的数据放入redis中
Dish dish = new Dish();
dish.setCategoryId(categoryId);
dish.setStatus(StatusConstant.ENABLE);//查询起售中的菜品
list = dishService.listWithFlavor(dish);
redisTemplate.opsForValue().set(key,list);
/*
*
* */
private void cleanCache(String pattern){
Set keys = redisTemplate.keys(pattern);
redisTemplate.delete(keys);
return Result.success(list);
}
}

@ -0,0 +1,55 @@
package com.sky.controller.admin;
import com.sky.constant.StatusConstant;
import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController("userSetmealController") // 定义一个REST控制器并指定其bean名称为"userSetmealController"
@RequestMapping("/user/setmeal") // 设置请求路径前缀为"/user/setmeal"
@Api(tags = "C端-套餐浏览接口") // 使用Swagger注解标记该控制器的API文档标签
public class SetmealController {
@Autowired // 自动注入SetmealService实例
private SetmealService setmealService;
/**
* id
*
* @param categoryId ID
* @return Result
*/
@GetMapping("/list") // 映射HTTP GET请求到该方法
@ApiOperation("根据分类id查询套餐") // 使用Swagger注解描述该操作的功能
@Cacheable(cacheNames = "setmealCache", key = "#categoryId") // 启用缓存,缓存名为"setmealCache"键为方法参数categoryId的值
public Result<List<Setmeal>> list(Long categoryId) {
Setmeal setmeal = new Setmeal(); // 创建一个新的Setmeal对象
setmeal.setCategoryId(categoryId); // 设置Setmeal对象的分类ID
setmeal.setStatus(StatusConstant.ENABLE); // 设置Setmeal对象的状态为启用状态
List<Setmeal> list = setmealService.list(setmeal); // 调用服务层方法获取符合条件的套餐列表
return Result.success(list); // 返回包含查询结果的成功响应
}
/**
* id
*
* @param id ID
* @return Result
*/
@GetMapping("/dish/{id}") // 映射HTTP GET请求到该方法URL中包含动态参数id
@ApiOperation("根据套餐id查询包含的菜品列表") // 使用Swagger注解描述该操作的功能
public Result<List<DishItemVO>> dishList(@PathVariable("id") Long id) { // 从URL路径中提取id参数
List<DishItemVO> list = setmealService.getDishItemById(id); // 调用服务层方法获取指定套餐包含的菜品列表
return Result.success(list); // 返回包含查询结果的成功响应
}
}

@ -0,0 +1,34 @@
package com.sky.mapper;
import com.sky.entity.DishFlavor;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;
@Mapper
public interface DishFlavorMapper {
/*
*
* */
void insertBatch(List<DishFlavor> flavors);
/*
* id
* */
@Delete("delete from dish_flavor where dish_id = #{dishId}")
void deleteByDishId(Long dishId);
/*
* id
* */
void deleteByDishIds(List<Long> dishIds);
/*
* id
* */
@Select("select * from dish_flavor where dish_id = #{dishId}")
List<DishFlavor> getByDishId(Long dishId);
}

@ -1,7 +1,76 @@
package com.sky.mapper;
import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;
import java.util.Map;
@Mapper
public interface SetmealMapper {
Setmeal getById(Long setmealId);
/**
* id
* @param id
* @return
*/
@Select("select count(id) from setmeal where category_id = #{categoryId}")
Integer countByCategoryId(Long id);
/*
*
* */
@AutoFill(OperationType.INSERT)
void insert(Setmeal setmeal);
Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
/*
* id
* */
@Select("select * from setmeal where id = #{id}")
Setmeal getById(Long Id);
void deleteBatch(List<Long> ids);
@AutoFill(OperationType.UPDATE)
void updateWithDish(Setmeal setmeal);
@Update("update setmeal set status = #{status} where id = #{id}")
void startOrStop(Setmeal setmeal);
/**
*
* @param setmeal
* @return
*/
List<Setmeal> list(Setmeal setmeal);
/**
* id
* @param setmealId
* @return
*/
@Select("select sd.name, sd.copies, d.image, d.description " +
"from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
"where sd.setmeal_id = #{setmealId}")
List<DishItemVO> getDishItemBySetmealId(Long setmealId);
/**
*
* @param map
* @return
*/
Integer countByMap(Map map);
}

@ -0,0 +1,50 @@
package com.sky.service;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.vo.DishVO;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
public interface DishService {
/*
*
* */
void saveWithFlavor(DishDTO dishDTO);
/*
*
* */
PageResult pageQuery(DishPageQueryDTO dishPageQueryDTO);
void deleteBatch(List<Long> ids);
/*
* id
* */
DishVO getById(Long id);
/*
* id
* */
void updateWithFlavor(DishDTO dishDTO);
List<Dish> getByCategoryId(Long categoryId);
/**
*
* @param dish
* @return
*/
List<DishVO> listWithFlavor(Dish dish);
void startOrStop(Integer status, Integer id);
}

@ -0,0 +1,65 @@
package com.sky.service;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import com.sky.entity.Setmeal;
import java.util.List;
public interface SetmealService {
/**
*
* @param setmealDTO
*/
public void saveWithDishes(SetmealDTO setmealDTO);
/**
*
* @param setmealPageQueryDTO
* @return
*/
PageResult page(SetmealPageQueryDTO setmealPageQueryDTO);
/**
* ID
* @param ids ID
*/
void delete(List<Long> ids);
/**
* ID
* @param id ID
* @return
*/
SetmealVO getById(Long id);
/**
*
* @param setmealDTO
*/
void updateWithDish(SetmealDTO setmealDTO);
/**
* ID
* @param status 10
* @param id ID
*/
void startOrStop(Integer status, Long id);
/**
*
* @param setmeal
* @return
*/
List<Setmeal> list(Setmeal setmeal);
/**
* ID
* @param id ID
* @return
*/
List<DishItemVO> getDishItemById(Long id);
}

@ -0,0 +1,190 @@
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 io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
@Service
@Slf4j
public class DishServiceImpl implements DishService {
@Autowired
private DishMapper dishMapper;
@Autowired
private DishFlavorMapper dishFlavorMapper;
@Autowired
private SetmealDishMapper setmealDishMapper;
/**
*
* @param dishDTO
*/
@Transactional
public void saveWithFlavor(DishDTO dishDTO) {
// 创建一个新的Dish对象并从DishDTO中复制属性
Dish dish = new Dish();
BeanUtils.copyProperties(dishDTO, dish);
// 向菜品表插入1条数据
dishMapper.insert(dish);
// 获取insert语句生成的主键值
Long dishId = dish.getId();
// 向口味表插入n条数据
List<DishFlavor> flavors = dishDTO.getFlavors();
if (flavors != null && flavors.size() > 0) {
flavors.forEach(dishFlavor -> {
dishFlavor.setDishId(dishId); // 设置口味的菜品ID为新插入的菜品ID
});
// 向口味表插入n条数据
dishFlavorMapper.insertBatch(flavors);
}
}
/**
*
* @param dishPageQueryDTO
* @return
*/
@Override
public PageResult pageQuery(DishPageQueryDTO dishPageQueryDTO) {
// 开启分页查询,设置当前页和每页显示的记录数
PageHelper.startPage(dishPageQueryDTO.getPage(), dishPageQueryDTO.getPageSize());
// 根据条件查询菜品数据,返回分页结果
Page<DishVO> page = dishMapper.pageQuery(dishPageQueryDTO);
return new PageResult(page.getTotal(), page.getResult());
}
/**
*
* @param ids ID
*/
@Transactional
public void deleteBatch(List<Long> ids) {
// 判断当前菜品是否能删除 -- 起售状态检查
for (Long id : ids) {
Dish dish = dishMapper.getById(id);
if (dish.getStatus() == StatusConstant.ENABLE) {
throw new DeletionNotAllowedException(MessageConstant.DISH_ON_SALE);
}
}
// 检查菜品是否被套餐关联
List<Long> setmealIds = setmealDishMapper.getSetmealIdsByDishIds(ids);
if (setmealIds != null && setmealIds.size() > 0) {
// 当前菜品被套餐关联,抛出异常
throw new DeletionNotAllowedException(MessageConstant.DISH_BE_RELATED_BY_SETMEAL);
}
// 根据菜品id集合批量删除菜品数据
dishMapper.deleteByIds(ids);
// 根据菜品id集合批量删除关联的口味数据
dishFlavorMapper.deleteByDishIds(ids);
}
/**
* ID
* @param id ID
* @return
*/
@Override
public DishVO getById(Long id) {
// 根据id查询菜品数据
Dish dish = dishMapper.getById(id);
// 查询口味数据
List<DishFlavor> dishFlavors = dishFlavorMapper.getByDishId(id);
// 封装到vo对象
DishVO dishVO = new DishVO();
BeanUtils.copyProperties(dish, dishVO);
dishVO.setFlavors(dishFlavors);
return dishVO;
}
/**
*
* @param dishDTO
*/
@Override
public void updateWithFlavor(DishDTO dishDTO) {
// 修改菜品表基本信息
Dish dish = new Dish();
BeanUtils.copyProperties(dishDTO, dish);
dishMapper.update(dish);
// 删除再插入口味数据
dishFlavorMapper.deleteByDishId(dishDTO.getId());
List<DishFlavor> flavors = dishDTO.getFlavors();
if (flavors != null && flavors.size() > 0) {
flavors.forEach(dishFlavor -> {
dishFlavor.setDishId(dishDTO.getId()); // 设置口味的菜品ID为更新后的菜品ID
});
// 向口味表插入n条数据
dishFlavorMapper.insertBatch(flavors);
}
}
/**
* ID
* @param categoryId ID
* @return
*/
@Override
public List<Dish> getByCategoryId(Long categoryId) {
Dish dish = Dish.builder()
.categoryId(categoryId)
.status(StatusConstant.ENABLE)
.build();
return dishMapper.getByCategoryId(dish);
}
/**
*
* @param dish
* @return
*/
public List<DishVO> listWithFlavor(Dish dish) {
List<Dish> dishList = dishMapper.getByCategoryId(dish); // 根据分类ID查询菜品列表
List<DishVO> dishVOList = new ArrayList<>(); // 用于存储最终的菜品视图对象列表
for (Dish d : dishList) { // 遍历查询到的菜品列表
DishVO dishVO = new DishVO(); // 创建新的菜品视图对象
BeanUtils.copyProperties(d, dishVO); // 将菜品对象的属性复制到视图对象中
// 根据菜品id查询对应的口味
List<DishFlavor> flavors = dishFlavorMapper.getByDishId(d.getId()); // 查询口味列表
dishVO.setFlavors(flavors); // 设置视图对象的口味列表属性
dishVOList.add(dishVO); // 将视图对象添加到最终列表中
}
return dishVOList; // 返回最终的菜品视图对象列表
}
/**
*
* @param status
* @param id ID
*/
@Override
public void startOrStop(Integer status, Integer id) {
dishMapper.startOrStop(status, id); // 更新菜品的销售状态
}
}

@ -0,0 +1,162 @@
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.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.Employee;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.exception.DeletionNotAllowedException;
import com.sky.mapper.DishMapper;
import com.sky.mapper.SetmealDishMapper;
import com.sky.mapper.SetmealMapper;
import com.sky.result.PageResult;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
public class SetmealServiceImpl implements SetmealService {
@Autowired
private SetmealMapper setmealMapper; // 注入套餐Mapper
@Autowired
private DishMapper dishMapper; // 注入菜品Mapper
@Autowired
private SetmealDishMapper setmealDishMapper; // 注入套餐菜品关系Mapper
/*
*
* */
@Override
@Transactional
public void saveWithDishes(SetmealDTO setmealDTO) {
// 创建套餐对象并复制属性
Setmeal setmeal = new Setmeal();
BeanUtils.copyProperties(setmealDTO, setmeal);
// 向套餐表插入一条数据
setmealMapper.insert(setmeal);
// 获取新插入的套餐ID
Long setmealId = setmealDTO.getId();
// 获取套餐中的菜品列表
List<SetmealDish> setmealDishes = setmealDTO.getSetmealDishes();
// 为每个菜品设置对应的套餐ID
setmealDishes.forEach(setmealDish -> {
setmealDish.setSetmealId(setmealId);
});
// 向套餐菜品关系表插入多条数据
setmealDishMapper.insertBatch(setmealDishes);
}
@Override
public PageResult page(SetmealPageQueryDTO setmealPageQueryDTO) {
// 开启分页查询,设置当前页和每页显示记录数
PageHelper.startPage(setmealPageQueryDTO.getPage(), setmealPageQueryDTO.getPageSize());
// 执行分页查询,获取结果集
Page<SetmealVO> page = setmealMapper.pageQuery(setmealPageQueryDTO);
// 返回分页结果,包含总记录数和当前页数据
return new PageResult(page.getTotal(), page.getResult());
}
@Transactional
public void delete(List<Long> ids) {
// 遍历要删除的套餐ID列表
for (Long id : ids) {
// 根据ID查询套餐信息
Setmeal setmeal = setmealMapper.getById(id);
// 如果套餐正在销售中,则抛出异常,不允许删除
if (setmeal.getStatus() == StatusConstant.ENABLE) {
throw new DeletionNotAllowedException(MessageConstant.SETMEAL_ON_SALE);
}
}
// 批量删除套餐表中的数据
setmealMapper.deleteBatch(ids);
// 批量删除套餐菜品关系表中的数据
setmealDishMapper.deleteBySetmealIds(ids);
}
/*
* id
*
* */
@Override
public SetmealVO getById(Long id) {
// 根据ID查询套餐信息
Setmeal setmeal = setmealMapper.getById(id);
// 创建套餐视图对象并复制属性
SetmealVO setmealVO = new SetmealVO();
BeanUtils.copyProperties(setmeal, setmealVO);
// 根据套餐ID查询关联的菜品列表
List<SetmealDish> setmealDishes = setmealDishMapper.getBySetmealId(id);
// 将菜品列表设置到套餐视图对象中
setmealVO.setSetmealDishes(setmealDishes);
// 返回套餐视图对象
return setmealVO;
}
@Transactional
public void updateWithDish(SetmealDTO setmealDTO) {
// 创建套餐对象并复制属性
Setmeal setmeal = new Setmeal();
BeanUtils.copyProperties(setmealDTO, setmeal);
// 更新套餐表中的数据
setmealMapper.updateWithDish(setmeal);
// 获取套餐ID
Long setmealId = setmealDTO.getId();
// 删除旧的套餐菜品关系数据
setmealDishMapper.deleteBySetmealId(setmealId);
// 获取新的套餐菜品列表
List<SetmealDish> setmealDishes = setmealDTO.getSetmealDishes();
// 为每个新的菜品设置对应的套餐ID
for (SetmealDish setmealDish : setmealDishes) {
setmealDish.setSetmealId(setmealDTO.getId());
}
// 向套餐菜品关系表插入新的数据
setmealDishMapper.insertBatch(setmealDishes);
}
@Override
public void startOrStop(Integer status, Long id) {
// 构建套餐对象并设置状态和ID
Setmeal setmeal = Setmeal.builder()
.status(status)
.id(id)
.build();
// 更新套餐表中的销售状态
setmealMapper.startOrStop(setmeal);
}
/**
*
* @param setmeal
* @return
*/
public List<Setmeal> list(Setmeal setmeal) {
// 根据条件查询套餐列表
List<Setmeal> list = setmealMapper.list(setmeal);
// 返回查询结果
return list;
}
/**
* id
* @param id ID
* @return
*/
public List<DishItemVO> getDishItemById(Long id) {
// 根据套餐ID查询菜品选项列表
return setmealMapper.getDishItemBySetmealId(id);
}
}

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.sky.mapper.DishFlavorMapper">
<insert id="insertBatch">
insert into dish_flavor (dish_id, name, value) values
<foreach collection="list" item="flavor" separator=",">
(#{flavor.dishId},#{flavor.name},#{flavor.value})
</foreach>
</insert>
<delete id="deleteByDishIds">
delete from dish_flavor where dish_id in
<foreach collection="dishIds" open="(" close=")" separator="," item="dishId">
#{dishId}
</foreach>
</delete>
</mapper>

@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.sky.mapper.DishMapper">
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
insert into dish (name, category_id, price, image, description, create_time, update_time, create_user, update_user, status)
values
(#{name},#{categoryId},#{price},#{image},#{description},#{createTime},#{updateTime},#{createUser},#{updateUser},#{status})
</insert>
<delete id="deleteByIds">
delete from dish where id in
<foreach collection="ids" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</delete>
<select id="pageQuery" resultType="com.sky.vo.DishVO" parameterType="com.sky.dto.DishPageQueryDTO">
select d.*,cg.name categoryName from dish d,category cg
<where>
d.category_id = cg.id
<if test="name !=null">
and d.name like concat('%',#{name},'%')
</if>
<if test="categoryId !=null">
and d.category_id = #{categoryId}
</if>
<if test="status != null">
and d.status = #{status}
</if>
</where>
order by d.create_time desc
</select>
<select id="getByCategoryId" resultType="com.sky.entity.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>
<update id="update" parameterType="com.sky.entity.Dish">
update dish
<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="image != null">
image = #{image},
</if>
<if test="description != null">
description = #{description},
</if>
<if test="status != null">
status = #{status},
</if>
<if test="updateTime != null">
update_time = #{updateTime},
</if>
<if test="updateUser != null">
update_user = #{updateUser},
</if>
</set>
where id = #{id}
</update>
<select id="countByMap" resultType="java.lang.Integer">
select count(id) from dish
<where>
<if test="status != null">
and status = #{status}
</if>
<if test="categoryId != null">
and category_id = #{categoryId}
</if>
</where>
</select>
</mapper>

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.sky.mapper.SetmealDishMapper">
<insert id="insertBatch">
insert into setmeal_dish(setmeal_id, dish_id, name, price, copies)
values
<foreach collection="list" item="setmealDish" separator=",">
(#{setmealDish.setmealId},#{setmealDish.dishId},#{setmealDish.name},#{setmealDish.price},#{setmealDish.copies})
</foreach>
</insert>
<delete id="deleteBySetmealIds">
delete from setmeal_dish
where setmeal_id in
<foreach collection="setmealIds" item="setmealId" open="(" close=")" separator=",">
#{setmealId}
</foreach>
</delete>
<select id="getSetmealIdsByDishIds" resultType="java.lang.Long">
select setmeal_id from setmeal_dish
where dish_id in
<foreach collection="dishIds" item="dishId" separator="," open="(" close=")">
#{dishId}
</foreach>
</select>
</mapper>

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.sky.mapper.SetmealMapper">
<insert id="insert">
insert into setmeal(category_id, name, price, description, image, create_time, update_time, create_user, update_user,status)
values(#{categoryId},#{name},#{price},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser},#{status})
</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.vo.SetmealVO">
select s.*,c.name categoryName from setmeal s,category c
<where>
s.category_id = c.id
<if test="name !=null">
and s.name like concat('%',#{name},'%')
</if>
<if test="categoryId !=null">
and s.category_id = #{categoryId}
</if>
<if test="status != null">
and s.status = #{status}
</if>
</where>
order by s.create_time desc
</select>
<update id="updateWithDish">
update setmeal
<set>
<if test="categoryId != null">category_id = #{categoryId},</if>
<if test="name != null">name = #{name},</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>
<select id="list" parameterType="Setmeal" resultType="com.sky.entity.Setmeal">
select * from setmeal
<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>
</select>
<select id="countByMap" resultType="java.lang.Integer">
select count(id) from setmeal
<where>
<if test="status != null">
and status = #{status}
</if>
<if test="categoryId != null">
and category_id = #{categoryId}
</if>
</where>
</select>
</mapper>
Loading…
Cancel
Save