Compare commits
No commits in common. "a9fdc30d107ff5306847e79ba9d2cefff5f47570" and "ed298ec39b38129f63ec6b19353340f9a459a754" have entirely different histories.
a9fdc30d10
...
ed298ec39b
|
@ -1,17 +1,17 @@
|
|||
package com.sky.controller.admin;
|
||||
|
||||
import com.sky.dto.DishDTO;
|
||||
import com.sky.dto.DishPageQueryDTO;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.DishService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
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;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/dish")
|
||||
|
@ -29,36 +29,9 @@ public class DishController {
|
|||
*/
|
||||
@ApiOperation("新增菜品")
|
||||
@PostMapping("")
|
||||
public Result<String> save(@RequestBody DishDTO dishDTO) {
|
||||
public Result<String > save(@RequestBody DishDTO dishDTO) {
|
||||
log.info("新增菜品:{}", dishDTO);
|
||||
dishService.saveWithFlavor(dishDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜品分页查询
|
||||
*
|
||||
* @param dishPageQueryDTO DishPageQueryDTO
|
||||
* @return Result<PageResult>
|
||||
*/
|
||||
@ApiOperation("菜品分页查询")
|
||||
@GetMapping("/page")
|
||||
public Result<PageResult> pageResultResult(DishPageQueryDTO dishPageQueryDTO) {
|
||||
log.info("菜品分页查询:{}", dishPageQueryDTO);
|
||||
PageResult pageResult = dishService.pageQuery(dishPageQueryDTO);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜品批量删除
|
||||
* @param ids List<Long>
|
||||
* @return Result<String>
|
||||
*/
|
||||
@ApiOperation("菜品批量删除")
|
||||
@DeleteMapping()
|
||||
public Result<String> delete(@RequestParam List<Long> ids) {
|
||||
log.info("菜品批量删除:{}", ids);
|
||||
dishService.deleteBatch(ids);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,16 +11,4 @@ public interface DishFlavorMapper {
|
|||
* @param flavors List<DishFlavor>
|
||||
*/
|
||||
void insertBatch(List<DishFlavor> flavors);
|
||||
|
||||
/**
|
||||
* 删除菜品关联的口味数据
|
||||
* @param id Long
|
||||
*/
|
||||
void deleteByDishId(Long id);
|
||||
|
||||
/**
|
||||
* 删除菜品关联的口味数据
|
||||
* @param dishIds List<Long>
|
||||
*/
|
||||
void deleteByDishIds(List<Long> dishIds);
|
||||
}
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
package com.sky.mapper;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.sky.annotation.AutoFill;
|
||||
import com.sky.dto.DishPageQueryDTO;
|
||||
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;
|
||||
|
||||
@Mapper
|
||||
public interface DishMapper {
|
||||
|
||||
|
@ -29,30 +24,4 @@ public interface DishMapper {
|
|||
*/
|
||||
@AutoFill(value = OperationType.INSERT)
|
||||
void insert(Dish dish);
|
||||
|
||||
/**
|
||||
* 菜品分页查询
|
||||
* @param dishPageQueryDTO DishPageQueryDTO
|
||||
* @return Page<DishVO>
|
||||
*/
|
||||
Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);
|
||||
|
||||
/**
|
||||
* 判断当前菜品是否能被删除---是否存在起售菜品
|
||||
* @param id Long
|
||||
* @return Dish
|
||||
*/
|
||||
Dish getById(Long id);
|
||||
|
||||
/**
|
||||
* 删除菜品表中的菜品数据
|
||||
* @param id Long
|
||||
*/
|
||||
void deleteById(Long id);
|
||||
|
||||
/**
|
||||
* 删除菜品表中的菜品数据
|
||||
* @param ids List<Long>
|
||||
*/
|
||||
void deleteByIds(List<Long> ids);
|
||||
}
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
package com.sky.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface SetMealDishMapper {
|
||||
/**
|
||||
* 查询对应套餐id
|
||||
* @param dishIds List<Long>
|
||||
* @return List<Long>
|
||||
*/
|
||||
List<Long> getSetMealDishIds(List<Long> dishIds);
|
||||
}
|
|
@ -1,10 +1,6 @@
|
|||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.DishDTO;
|
||||
import com.sky.dto.DishPageQueryDTO;
|
||||
import com.sky.result.PageResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DishService {
|
||||
/**
|
||||
|
@ -13,17 +9,4 @@ public interface DishService {
|
|||
* @param dishDTO DishDTO
|
||||
*/
|
||||
void saveWithFlavor(DishDTO dishDTO);
|
||||
|
||||
/**
|
||||
* 菜品分页查询
|
||||
* @param dishPageQueryDTO DishPageQueryDTO
|
||||
* @return PageResult
|
||||
*/
|
||||
PageResult pageQuery(DishPageQueryDTO dishPageQueryDTO);
|
||||
|
||||
/**
|
||||
* 菜品批量删除
|
||||
* @param ids List<Long>
|
||||
*/
|
||||
void deleteBatch(List<Long> ids);
|
||||
}
|
||||
|
|
|
@ -1,20 +1,11 @@
|
|||
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 lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -30,8 +21,6 @@ public class DishServiceImpl implements DishService {
|
|||
private DishMapper dishMapper;
|
||||
@Resource
|
||||
private DishFlavorMapper dishFlavorMapper;
|
||||
@Resource
|
||||
private SetMealDishMapper setMealDishMapper;
|
||||
|
||||
/**
|
||||
* 新增菜品和口味
|
||||
|
@ -57,44 +46,4 @@ public class DishServiceImpl implements DishService {
|
|||
dishFlavorMapper.insertBatch(flavors);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜品分页查询
|
||||
*
|
||||
* @param dishPageQueryDTO DishPageQueryDTO
|
||||
* @return PageResult
|
||||
*/
|
||||
@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 List<Long>
|
||||
*/
|
||||
@Override
|
||||
public void deleteBatch(List<Long> ids) {
|
||||
// 判断当前菜品是否能被删除---是否存在起售菜品
|
||||
for (Long id : ids) {
|
||||
Dish dish = dishMapper.getById(id);
|
||||
if (dish.getStatus().equals(StatusConstant.ENABLE)) {
|
||||
throw new DeletionNotAllowedException(MessageConstant.DISH_ON_SALE);
|
||||
}
|
||||
}
|
||||
// 判断当前菜品是否能够删除--是否被套餐关联
|
||||
List<Long> setMealDishIds = setMealDishMapper.getSetMealDishIds(ids);
|
||||
if (setMealDishIds != null && !setMealDishIds.isEmpty()) {
|
||||
// 当前菜品被关联了
|
||||
throw new DeletionNotAllowedException(MessageConstant.DISH_BE_RELATED_BY_SETMEAL);
|
||||
}
|
||||
|
||||
// 删除菜品表中的菜品数据
|
||||
dishMapper.deleteByIds(ids);
|
||||
// 删除菜品关联的口味数据
|
||||
dishFlavorMapper.deleteByDishIds(ids);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,21 +10,4 @@
|
|||
( #{df.dishId},#{df.name},#{df.value})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
<!-- 删除菜品关联的口味数据 -->
|
||||
<delete id="deleteByDishId">
|
||||
delete
|
||||
from dish_flavor
|
||||
where dish_id = #{dishId};
|
||||
</delete>
|
||||
|
||||
<!-- 删除菜品关联的口味数据 -->
|
||||
<delete id="deleteByDishIds">
|
||||
delete
|
||||
from dish_flavor
|
||||
where dish_id in
|
||||
<foreach collection="dishIds" open="(" close=")" item="dishId">
|
||||
#{dishId}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
|
|
|
@ -10,53 +10,10 @@
|
|||
#{updateTime}, #{createUser}, #{updateUser});
|
||||
</insert>
|
||||
|
||||
<!-- 删除菜品表中的菜品数据 -->
|
||||
<delete id="deleteById">
|
||||
delete
|
||||
from dish
|
||||
where id = #{id}
|
||||
</delete>
|
||||
|
||||
<!-- 删除菜品表中的菜品数据 -->
|
||||
<delete id="deleteByIds">
|
||||
delete
|
||||
from dish
|
||||
where id in
|
||||
<foreach collection="ids" open="(" close=")" separator="," item="id">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<!-- 根据分类id查询菜品数量 -->
|
||||
<select id="countByCategoryId" resultType="java.lang.Integer">
|
||||
<select id="countByCategoryId" resultType="java.lang.Integer" >
|
||||
select count(id)
|
||||
from dish
|
||||
where category_id = #{categoryId}
|
||||
</select>
|
||||
|
||||
<!-- 菜品分页查询 -->
|
||||
<select id="pageQuery" resultType="com.sky.vo.DishVO">
|
||||
select d.*, c.name as categoryName
|
||||
from dish d
|
||||
left OUTER join category c on d.category_id = c.id
|
||||
<where>
|
||||
<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="getById" resultType="com.sky.entity.Dish">
|
||||
select *
|
||||
from dish
|
||||
where id = #{id};
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
<?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">
|
||||
|
||||
<!-- 查询对应套餐id -->
|
||||
<select id="getSetMealDishIds" resultType="java.lang.Long">
|
||||
select *
|
||||
from setmeal_dish where dish_id in
|
||||
<foreach collection="dishIds" item="dishId" separator="," open="(" close=")">
|
||||
#{dishId}
|
||||
</foreach>
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue