Compare commits
No commits in common. "e9bdc8baeb5656c18b1ef0b87110743467802652" and "d8b0a8a3915cf90b2676913a9bfe3e6146918d6c" have entirely different histories.
e9bdc8baeb
...
d8b0a8a391
|
@ -2,7 +2,6 @@ package com.sky.dto;
|
|||
|
||||
import com.sky.entity.SetmealDish;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
|
@ -12,19 +11,26 @@ import java.util.List;
|
|||
public class SetmealDTO implements Serializable {
|
||||
|
||||
private Long id;
|
||||
// 分类id
|
||||
|
||||
//分类id
|
||||
private Long categoryId;
|
||||
// 套餐名称
|
||||
|
||||
//套餐名称
|
||||
private String name;
|
||||
// 套餐价格
|
||||
|
||||
//套餐价格
|
||||
private BigDecimal price;
|
||||
// 状态 0:停用 1:启用
|
||||
|
||||
//状态 0:停用 1:启用
|
||||
private Integer status;
|
||||
// 描述信息
|
||||
|
||||
//描述信息
|
||||
private String description;
|
||||
// 图片
|
||||
|
||||
//图片
|
||||
private String image;
|
||||
// 套餐菜品关系
|
||||
|
||||
//套餐菜品关系
|
||||
private List<SetmealDish> setmealDishes = new ArrayList<>();
|
||||
|
||||
}
|
||||
|
|
|
@ -104,7 +104,6 @@ public class CategoryController {
|
|||
@GetMapping("/list")
|
||||
@ApiOperation("根据类型查询分类")
|
||||
public Result<List<Category>> list(Integer type) {
|
||||
log.info("根据类型查询分类 type:{}", type);
|
||||
List<Category> list = categoryService.list(type);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ 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;
|
||||
|
@ -53,7 +52,6 @@ public class DishController {
|
|||
|
||||
/**
|
||||
* 菜品批量删除
|
||||
*
|
||||
* @param ids List<Long>
|
||||
* @return Result<String>
|
||||
*/
|
||||
|
@ -67,21 +65,19 @@ public class DishController {
|
|||
|
||||
/**
|
||||
* 根据id查询菜品
|
||||
*
|
||||
* @param id Long
|
||||
* @return Result<DishVO>
|
||||
*/
|
||||
@ApiOperation("根据id查询菜品")
|
||||
@GetMapping("/{id}")
|
||||
public Result<DishVO> getBydId(@PathVariable Long id) {
|
||||
log.info("根据id查询菜品:{}", id);
|
||||
log.info("根据id查询菜品:{}",id);
|
||||
DishVO dishVO = dishService.getByIdWithFlavor(id);
|
||||
return Result.success(dishVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改菜品
|
||||
*
|
||||
* @param dishDTO DishDTO
|
||||
* @return Result<String>
|
||||
*/
|
||||
|
@ -92,31 +88,4 @@ public class DishController {
|
|||
dishService.updateWithFlavor(dishDTO);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
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,6 +7,7 @@ import com.sky.entity.Dish;
|
|||
import com.sky.enumeration.OperationType;
|
||||
import com.sky.vo.DishVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -31,7 +32,6 @@ public interface DishMapper {
|
|||
|
||||
/**
|
||||
* 菜品分页查询
|
||||
*
|
||||
* @param dishPageQueryDTO DishPageQueryDTO
|
||||
* @return Page<DishVO>
|
||||
*/
|
||||
|
@ -39,7 +39,6 @@ public interface DishMapper {
|
|||
|
||||
/**
|
||||
* 判断当前菜品是否能被删除---是否存在起售菜品
|
||||
*
|
||||
* @param id Long
|
||||
* @return Dish
|
||||
*/
|
||||
|
@ -47,31 +46,22 @@ public interface DishMapper {
|
|||
|
||||
/**
|
||||
* 删除菜品表中的菜品数据
|
||||
*
|
||||
* @param id Long
|
||||
*/
|
||||
void deleteById(Long id);
|
||||
|
||||
/**
|
||||
* 删除菜品表中的菜品数据
|
||||
*
|
||||
* @param ids List<Long>
|
||||
*/
|
||||
void deleteByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 删除原有口味数据
|
||||
*
|
||||
* @param dish Dish
|
||||
*/
|
||||
@AutoFill(value = OperationType.UPDATE)
|
||||
void update(Dish dish);
|
||||
|
||||
/**
|
||||
* 条件查询菜品和口味
|
||||
*
|
||||
* @param dish Dish
|
||||
* @return List<Dish>
|
||||
*/
|
||||
List<Dish> list(Dish dish);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
package com.sky.mapper;
|
||||
|
||||
import com.sky.annotation.AutoFill;
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.entity.SetmealDish;
|
||||
import com.sky.enumeration.OperationType;
|
||||
import com.sky.vo.DishItemVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -27,18 +25,4 @@ public interface SetMealDishMapper {
|
|||
*/
|
||||
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,10 +1,9 @@
|
|||
package com.sky.mapper;
|
||||
|
||||
import com.sky.annotation.AutoFill;
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.enumeration.OperationType;
|
||||
import com.sky.vo.DishItemVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -12,7 +11,6 @@ import java.util.List;
|
|||
public interface SetmealMapper {
|
||||
/**
|
||||
* 根据分类id查询套餐的数量
|
||||
*
|
||||
* @param id Long
|
||||
* @return Integer
|
||||
*/
|
||||
|
@ -20,7 +18,6 @@ public interface SetmealMapper {
|
|||
|
||||
/**
|
||||
* 动态条件查询套餐
|
||||
*
|
||||
* @param setmeal Setmeal
|
||||
* @return List<Setmeal>
|
||||
*/
|
||||
|
@ -28,17 +25,8 @@ public interface SetmealMapper {
|
|||
|
||||
/**
|
||||
* 根据套餐id查询菜品选项
|
||||
*
|
||||
* @param setmealId
|
||||
* @return
|
||||
*/
|
||||
List<DishItemVO> getDishItemBySetmealId(Long setmealId);
|
||||
|
||||
/**
|
||||
* 向套餐表插入数据
|
||||
*
|
||||
* @param setmeal Setmeal
|
||||
*/
|
||||
@AutoFill(OperationType.INSERT)
|
||||
void insert(Setmeal setmeal);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ public interface DishService {
|
|||
|
||||
/**
|
||||
* 菜品分页查询
|
||||
*
|
||||
* @param dishPageQueryDTO DishPageQueryDTO
|
||||
* @return PageResult
|
||||
*/
|
||||
|
@ -26,14 +25,12 @@ public interface DishService {
|
|||
|
||||
/**
|
||||
* 菜品批量删除
|
||||
*
|
||||
* @param ids List<Long>
|
||||
*/
|
||||
void deleteBatch(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 根据id查询菜品
|
||||
*
|
||||
* @param id Long
|
||||
* @return DishVO
|
||||
*/
|
||||
|
@ -41,32 +38,14 @@ public interface DishService {
|
|||
|
||||
/**
|
||||
* 修改菜品
|
||||
*
|
||||
* @param dishDTO DishDTO
|
||||
*/
|
||||
void updateWithFlavor(DishDTO dishDTO);
|
||||
|
||||
/**
|
||||
* 条件查询菜品和口味
|
||||
*
|
||||
* @param dish Dish
|
||||
* @return List<DishVO>
|
||||
* @param dish
|
||||
* @return
|
||||
*/
|
||||
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,34 +1,27 @@
|
|||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.SetmealDTO;
|
||||
import com.sky.dto.SetmealPageQueryDTO;
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.vo.DishItemVO;
|
||||
|
||||
import com.sky.vo.SetmealVO;
|
||||
import java.util.List;
|
||||
|
||||
public interface SetmealService {
|
||||
|
||||
/**
|
||||
* 条件查询
|
||||
*
|
||||
* @param setmeal Setmeal
|
||||
* @return List<Setmeal>
|
||||
* @param setmeal
|
||||
* @return
|
||||
*/
|
||||
List<Setmeal> list(Setmeal setmeal);
|
||||
|
||||
/**
|
||||
* 根据id查询菜品选项
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
List<DishItemVO> getDishItemById(Long id);
|
||||
|
||||
|
||||
/**
|
||||
* 新增套餐,同时需要保存套餐和菜品的关联关系
|
||||
*
|
||||
* @param setmealDTO SetmealDTO
|
||||
*/
|
||||
void saveWithDish(SetmealDTO setmealDTO);
|
||||
}
|
||||
|
|
|
@ -8,18 +8,20 @@ import com.sky.dto.DishDTO;
|
|||
import com.sky.dto.DishPageQueryDTO;
|
||||
import com.sky.entity.Dish;
|
||||
import com.sky.entity.DishFlavor;
|
||||
import com.sky.entity.Setmeal;
|
||||
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.result.Result;
|
||||
import com.sky.service.DishService;
|
||||
import com.sky.vo.DishVO;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
|
@ -147,9 +149,8 @@ public class DishServiceImpl implements DishService {
|
|||
|
||||
/**
|
||||
* 条件查询菜品和口味
|
||||
*
|
||||
* @param dish Dish
|
||||
* @return List<DishVO>
|
||||
* @param dish
|
||||
* @return
|
||||
*/
|
||||
public List<DishVO> listWithFlavor(Dish dish) {
|
||||
List<Dish> dishList = dishMapper.list(dish);
|
||||
|
@ -158,9 +159,9 @@ public class DishServiceImpl implements DishService {
|
|||
|
||||
for (Dish d : dishList) {
|
||||
DishVO dishVO = new DishVO();
|
||||
BeanUtils.copyProperties(d, dishVO);
|
||||
BeanUtils.copyProperties(d,dishVO);
|
||||
|
||||
// 根据菜品id查询对应的口味
|
||||
//根据菜品id查询对应的口味
|
||||
List<DishFlavor> flavors = dishFlavorMapper.getByDishId(d.getId());
|
||||
|
||||
dishVO.setFlavors(flavors);
|
||||
|
@ -169,43 +170,4 @@ public class DishServiceImpl implements DishService {
|
|||
|
||||
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,15 +1,12 @@
|
|||
package com.sky.service.impl;
|
||||
|
||||
import com.sky.dto.SetmealDTO;
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.entity.SetmealDish;
|
||||
import com.sky.mapper.DishMapper;
|
||||
import com.sky.mapper.SetMealDishMapper;
|
||||
import com.sky.mapper.SetmealMapper;
|
||||
import com.sky.service.SetmealService;
|
||||
import com.sky.vo.DishItemVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -48,26 +45,4 @@ public class SetmealServiceImpl implements SetmealService {
|
|||
public List<DishItemVO> getDishItemById(Long 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,21 +91,4 @@
|
|||
from dish
|
||||
where id = #{id};
|
||||
</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>
|
||||
|
|
|
@ -2,48 +2,6 @@
|
|||
<!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" 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 -->
|
||||
<select id="getSetMealDishIds" resultType="java.lang.Long">
|
||||
select *
|
||||
|
|
|
@ -2,14 +2,6 @@
|
|||
<!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" 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查询套餐的数量 -->
|
||||
<select id="countByCategoryId" resultType="java.lang.Integer">
|
||||
select count(id)
|
||||
|
|
Loading…
Reference in New Issue