新增套餐、套餐分页查询、根据分类id查询菜品
This commit is contained in:
@@ -6,7 +6,6 @@ import com.sky.context.BaseContext;
|
||||
import com.sky.enumeration.OperationType;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.Signature;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.sky.utils.AliOssUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Conditional;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,7 +7,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.cbor.MappingJackson2CborHttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
|
||||
@@ -8,7 +8,6 @@ import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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 org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.sky.controller.admin;
|
||||
|
||||
import com.sky.dto.DishDTO;
|
||||
import com.sky.dto.DishPageQueryDTO;
|
||||
import com.sky.entity.Dish;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.DishService;
|
||||
@@ -89,4 +90,17 @@ public class DishController {
|
||||
dishService.updateWithFlavor(dishDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类id查询菜品
|
||||
* @param categoryId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("根据分类id查询菜品")
|
||||
public Result<List> list(String categoryId){
|
||||
log.info("根据分类id查询菜品: {}",categoryId);
|
||||
List<Dish> dishes = dishService.selectByCategoryId(categoryId);
|
||||
return Result.success(dishes);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.sky.controller.admin;
|
||||
|
||||
import com.sky.dto.SetmealDTO;
|
||||
import com.sky.dto.SetmealPageQueryDTO;
|
||||
import com.sky.result.PageResult;
|
||||
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.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/setmeal")
|
||||
@Slf4j
|
||||
@Api(tags = "套餐相关接口")
|
||||
public class SetmealController {
|
||||
|
||||
@Autowired
|
||||
private SetmealService setmealService;
|
||||
|
||||
/**
|
||||
* 套餐分页查询
|
||||
* @param setmealPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("套餐分页查询")
|
||||
public Result<PageResult> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO){
|
||||
log.info("套餐分页查询: {}",setmealPageQueryDTO);
|
||||
PageResult pageResult = setmealService.pageQuery(setmealPageQueryDTO);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增套餐
|
||||
* @param setmealDTO
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
@ApiOperation("新增套餐")
|
||||
public Result insert(@RequestBody SetmealDTO setmealDTO){
|
||||
log.info("新增套餐: {}",setmealDTO);
|
||||
setmealService.insert(setmealDTO);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import com.sky.entity.Dish;
|
||||
import com.sky.enumeration.OperationType;
|
||||
import com.sky.vo.DishVO;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
@@ -61,4 +60,12 @@ public interface DishMapper {
|
||||
|
||||
@AutoFill(OperationType.UPDATE)
|
||||
void update(Dish dish);
|
||||
|
||||
/**
|
||||
* 根据分类id查询菜品
|
||||
* @param categoryId
|
||||
* @return
|
||||
*/
|
||||
@Select("select * from dish where category_id = #{categoryId}")
|
||||
List<Dish> selectByCategoryId(String categoryId);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.sky.enumeration.OperationType;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Mapper
|
||||
public interface EmployeeMapper {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.sky.entity.SetmealDish;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
@@ -12,4 +13,6 @@ public interface SetmealDishMapper {
|
||||
* @return
|
||||
*/
|
||||
List<Long> getSetmealIdsByDishIds(List<Long> ids);
|
||||
|
||||
void insertBatch(List<SetmealDish> setmealDishes);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
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 org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
@@ -14,4 +19,8 @@ public interface SetmealMapper {
|
||||
@Select("select count(id) from setmeal where category_id = #{categoryId}")
|
||||
Integer countByCategoryId(Long id);
|
||||
|
||||
Page<Setmeal> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
|
||||
|
||||
@AutoFill(OperationType.INSERT)
|
||||
void insert(Setmeal setmeal);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ 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 org.springframework.stereotype.Service;
|
||||
@@ -42,4 +43,11 @@ public interface DishService {
|
||||
* @param dishDTO
|
||||
*/
|
||||
void updateWithFlavor(DishDTO dishDTO);
|
||||
|
||||
/**
|
||||
* 根据分类id查询菜品
|
||||
* @param categoryId
|
||||
* @return
|
||||
*/
|
||||
List<Dish> selectByCategoryId(String categoryId);
|
||||
}
|
||||
|
||||
22
sky-server/src/main/java/com/sky/service/SetmealService.java
Normal file
22
sky-server/src/main/java/com/sky/service/SetmealService.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.SetmealDTO;
|
||||
import com.sky.dto.SetmealPageQueryDTO;
|
||||
import com.sky.result.PageResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public interface SetmealService {
|
||||
/**
|
||||
* 套餐分页查询
|
||||
* @param setmealPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
|
||||
|
||||
/**
|
||||
* 新增套餐
|
||||
* @param setmealDTO
|
||||
*/
|
||||
void insert(SetmealDTO setmealDTO);
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.sky.constant.MessageConstant;
|
||||
import com.sky.constant.StatusConstant;
|
||||
import com.sky.context.BaseContext;
|
||||
import com.sky.dto.CategoryDTO;
|
||||
import com.sky.dto.CategoryPageQueryDTO;
|
||||
import com.sky.entity.Category;
|
||||
@@ -18,8 +17,6 @@ import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@@ -129,7 +126,6 @@ public class CategoryServiceImpl implements CategoryService {
|
||||
*/
|
||||
@Override
|
||||
public List<Category> list(Integer type) {
|
||||
List<Category> list = categoryMapper.selectByType(type);
|
||||
return list;
|
||||
return categoryMapper.selectByType(type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@@ -153,4 +152,14 @@ public class DishServiceImpl implements DishService {
|
||||
dishFlavorMapper.insertBatch(flavors);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类id查询菜品
|
||||
* @param categoryId
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<Dish> selectByCategoryId(String categoryId) {
|
||||
return dishMapper.selectByCategoryId(categoryId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import com.github.pagehelper.PageHelper;
|
||||
import com.sky.constant.MessageConstant;
|
||||
import com.sky.constant.PasswordConstant;
|
||||
import com.sky.constant.StatusConstant;
|
||||
import com.sky.context.BaseContext;
|
||||
import com.sky.dto.EmployeeDTO;
|
||||
import com.sky.dto.EmployeeLoginDTO;
|
||||
import com.sky.dto.EmployeePageQueryDTO;
|
||||
@@ -21,7 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.sky.dto.SetmealDTO;
|
||||
import com.sky.dto.SetmealPageQueryDTO;
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.entity.SetmealDish;
|
||||
import com.sky.mapper.SetmealDishMapper;
|
||||
import com.sky.mapper.SetmealMapper;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.service.SetmealService;
|
||||
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;
|
||||
@Autowired
|
||||
private SetmealDishMapper setmealDishMapper;
|
||||
|
||||
/**
|
||||
* 套餐分页查询
|
||||
* @param setmealPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO) {
|
||||
//设置分页
|
||||
PageHelper.startPage(setmealPageQueryDTO.getPage(), setmealPageQueryDTO.getPageSize());
|
||||
Page<Setmeal> page = setmealMapper.pageQuery(setmealPageQueryDTO);
|
||||
return new PageResult(page.getTotal(),page.getResult());
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增套餐
|
||||
* @param setmealDTO
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void insert(SetmealDTO setmealDTO) {
|
||||
//插入套餐信息
|
||||
Setmeal setmeal = new Setmeal();
|
||||
BeanUtils.copyProperties(setmealDTO,setmeal);
|
||||
setmealMapper.insert(setmeal);
|
||||
|
||||
//插入套餐包含菜品的信息
|
||||
List<SetmealDish> setmealDishes = setmealDTO.getSetmealDishes();
|
||||
setmealDishMapper.insertBatch(setmealDishes);
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,13 @@
|
||||
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="setmealDishes" item="sd" separator=",">
|
||||
(#{sd.setmealId},#{sd.dishId},#{sd.name},#{sd.price},#{sd.copies})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<select id="getSetmealIdsByDishIds" resultType="java.lang.Long">
|
||||
select setmeal_id from setmeal_dish where dish_id in
|
||||
|
||||
21
sky-server/src/main/resources/mapper/SetmealMapper.xml
Normal file
21
sky-server/src/main/resources/mapper/SetmealMapper.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?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, status, description, image, create_time, update_time, create_user,
|
||||
update_user)
|
||||
VALUES (#{categoryId}, #{name}, #{price}, #{status}, #{description}, #{image}, #{createTime}, #{updateTime},
|
||||
#{createUser}, #{updateUser})
|
||||
</insert>
|
||||
|
||||
<select id="pageQuery" 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>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user