Compare commits
3 Commits
ed298ec39b
...
a9fdc30d10
Author | SHA1 | Date |
---|---|---|
|
a9fdc30d10 | |
|
7d09b5abac | |
|
af53702e96 |
|
@ -1,17 +1,17 @@
|
||||||
package com.sky.controller.admin;
|
package com.sky.controller.admin;
|
||||||
|
|
||||||
import com.sky.dto.DishDTO;
|
import com.sky.dto.DishDTO;
|
||||||
|
import com.sky.dto.DishPageQueryDTO;
|
||||||
|
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;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
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 javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/admin/dish")
|
@RequestMapping("/admin/dish")
|
||||||
|
@ -34,4 +34,31 @@ public class DishController {
|
||||||
dishService.saveWithFlavor(dishDTO);
|
dishService.saveWithFlavor(dishDTO);
|
||||||
return Result.success();
|
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,4 +11,16 @@ public interface DishFlavorMapper {
|
||||||
* @param flavors List<DishFlavor>
|
* @param flavors List<DishFlavor>
|
||||||
*/
|
*/
|
||||||
void insertBatch(List<DishFlavor> flavors);
|
void insertBatch(List<DishFlavor> flavors);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除菜品关联的口味数据
|
||||||
|
* @param id Long
|
||||||
|
*/
|
||||||
|
void deleteByDishId(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除菜品关联的口味数据
|
||||||
|
* @param dishIds List<Long>
|
||||||
|
*/
|
||||||
|
void deleteByDishIds(List<Long> dishIds);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
package com.sky.mapper;
|
package com.sky.mapper;
|
||||||
|
|
||||||
|
import com.github.pagehelper.Page;
|
||||||
import com.sky.annotation.AutoFill;
|
import com.sky.annotation.AutoFill;
|
||||||
|
import com.sky.dto.DishPageQueryDTO;
|
||||||
import com.sky.entity.Dish;
|
import com.sky.entity.Dish;
|
||||||
import com.sky.enumeration.OperationType;
|
import com.sky.enumeration.OperationType;
|
||||||
|
import com.sky.vo.DishVO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface DishMapper {
|
public interface DishMapper {
|
||||||
|
|
||||||
|
@ -24,4 +29,30 @@ public interface DishMapper {
|
||||||
*/
|
*/
|
||||||
@AutoFill(value = OperationType.INSERT)
|
@AutoFill(value = OperationType.INSERT)
|
||||||
void insert(Dish dish);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
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,6 +1,10 @@
|
||||||
package com.sky.service;
|
package com.sky.service;
|
||||||
|
|
||||||
import com.sky.dto.DishDTO;
|
import com.sky.dto.DishDTO;
|
||||||
|
import com.sky.dto.DishPageQueryDTO;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface DishService {
|
public interface DishService {
|
||||||
/**
|
/**
|
||||||
|
@ -9,4 +13,17 @@ public interface DishService {
|
||||||
* @param dishDTO DishDTO
|
* @param dishDTO DishDTO
|
||||||
*/
|
*/
|
||||||
void saveWithFlavor(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,11 +1,20 @@
|
||||||
package com.sky.service.impl;
|
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.DishDTO;
|
||||||
|
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.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.result.PageResult;
|
||||||
import com.sky.service.DishService;
|
import com.sky.service.DishService;
|
||||||
|
import com.sky.vo.DishVO;
|
||||||
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;
|
||||||
|
@ -21,6 +30,8 @@ public class DishServiceImpl implements DishService {
|
||||||
private DishMapper dishMapper;
|
private DishMapper dishMapper;
|
||||||
@Resource
|
@Resource
|
||||||
private DishFlavorMapper dishFlavorMapper;
|
private DishFlavorMapper dishFlavorMapper;
|
||||||
|
@Resource
|
||||||
|
private SetMealDishMapper setMealDishMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增菜品和口味
|
* 新增菜品和口味
|
||||||
|
@ -46,4 +57,44 @@ public class DishServiceImpl implements DishService {
|
||||||
dishFlavorMapper.insertBatch(flavors);
|
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,4 +10,21 @@
|
||||||
( #{df.dishId},#{df.name},#{df.value})
|
( #{df.dishId},#{df.name},#{df.value})
|
||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</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>
|
</mapper>
|
||||||
|
|
|
@ -10,10 +10,53 @@
|
||||||
#{updateTime}, #{createUser}, #{updateUser});
|
#{updateTime}, #{createUser}, #{updateUser});
|
||||||
</insert>
|
</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查询菜品数量 -->
|
<!-- 根据分类id查询菜品数量 -->
|
||||||
<select id="countByCategoryId" resultType="java.lang.Integer">
|
<select id="countByCategoryId" resultType="java.lang.Integer">
|
||||||
select count(id)
|
select count(id)
|
||||||
from dish
|
from dish
|
||||||
where category_id = #{categoryId}
|
where category_id = #{categoryId}
|
||||||
</select>
|
</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>
|
</mapper>
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?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