分类管理
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package com.sky.controller.category;
|
||||
package com.sky.controller.admin;
|
||||
|
||||
import com.sky.dto.CategoryDTO;
|
||||
import com.sky.dto.CategoryPageQueryDTO;
|
||||
@@ -7,9 +7,7 @@ import com.sky.result.PageResult;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.CategoryService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.models.auth.In;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
17
sky-server/src/main/java/com/sky/mapper/DishMapper.java
Normal file
17
sky-server/src/main/java/com/sky/mapper/DishMapper.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
@Mapper
|
||||
public interface DishMapper {
|
||||
|
||||
/**
|
||||
* 根据分类id查询菜品数量
|
||||
* @param categoryId
|
||||
* @return
|
||||
*/
|
||||
@Select("select count(id) from dish where category_id = #{categoryId}")
|
||||
Integer countByCategoryId(Long categoryId);
|
||||
|
||||
}
|
||||
17
sky-server/src/main/java/com/sky/mapper/SetmealMapper.java
Normal file
17
sky-server/src/main/java/com/sky/mapper/SetmealMapper.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
@Mapper
|
||||
public interface SetmealMapper {
|
||||
|
||||
/**
|
||||
* 根据分类id查询套餐的数量
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Select("select count(id) from setmeal where category_id = #{categoryId}")
|
||||
Integer countByCategoryId(Long id);
|
||||
|
||||
}
|
||||
@@ -2,12 +2,16 @@ 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.context.BaseContext;
|
||||
import com.sky.dto.CategoryDTO;
|
||||
import com.sky.dto.CategoryPageQueryDTO;
|
||||
import com.sky.entity.Category;
|
||||
import com.sky.exception.DeletionNotAllowedException;
|
||||
import com.sky.mapper.CategoryMapper;
|
||||
import com.sky.mapper.DishMapper;
|
||||
import com.sky.mapper.SetmealMapper;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.service.CategoryService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -23,7 +27,10 @@ public class CategoryServiceImpl implements CategoryService {
|
||||
|
||||
@Autowired
|
||||
private CategoryMapper categoryMapper;
|
||||
|
||||
@Autowired
|
||||
private DishMapper dishMapper;
|
||||
@Autowired
|
||||
private SetmealMapper setmealMapper;
|
||||
/**
|
||||
* 分类分页查询
|
||||
*
|
||||
@@ -70,7 +77,17 @@ public class CategoryServiceImpl implements CategoryService {
|
||||
*/
|
||||
@Override
|
||||
public void deleteById(long id) {
|
||||
//查询是否关联套餐
|
||||
if (setmealMapper.countByCategoryId(id) > 0){
|
||||
throw new DeletionNotAllowedException(MessageConstant.CATEGORY_BE_RELATED_BY_SETMEAL);
|
||||
}
|
||||
//查询是否关联菜品
|
||||
if (dishMapper.countByCategoryId(id) > 0){
|
||||
throw new DeletionNotAllowedException(MessageConstant.CATEGORY_BE_RELATED_BY_DISH);
|
||||
}
|
||||
//删除分类数据
|
||||
categoryMapper.deleteById(id);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user