分类管理模块功能-修改代码风格
This commit is contained in:
parent
2892a48608
commit
364bdecd8d
|
@ -6,17 +6,8 @@ import java.io.Serializable;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class CategoryPageQueryDTO implements Serializable {
|
public class CategoryPageQueryDTO implements Serializable {
|
||||||
|
private int page;// 页码
|
||||||
//页码
|
private int pageSize;// 每页记录数
|
||||||
private int page;
|
private String name;// 分类名称
|
||||||
|
private Integer type;//分类类型 1菜品分类 2套餐分类
|
||||||
//每页记录数
|
|
||||||
private int pageSize;
|
|
||||||
|
|
||||||
//分类名称
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
//分类类型 1菜品分类 2套餐分类
|
|
||||||
private Integer type;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,12 @@ import com.sky.entity.Category;
|
||||||
import com.sky.result.PageResult;
|
import com.sky.result.PageResult;
|
||||||
import com.sky.result.Result;
|
import com.sky.result.Result;
|
||||||
import com.sky.service.CategoryService;
|
import com.sky.service.CategoryService;
|
||||||
import io.swagger.annotations.Api;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,19 +19,19 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/admin/category")
|
@RequestMapping("/admin/category")
|
||||||
@Api(tags = "分类相关接口")
|
@Tag(name = "分类相关接口")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class CategoryController {
|
public class CategoryController {
|
||||||
|
|
||||||
@Autowired
|
@Resource
|
||||||
private CategoryService categoryService;
|
private CategoryService categoryService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增分类
|
* 新增分类
|
||||||
* @param categoryDTO
|
* @param categoryDTO CategoryDTO
|
||||||
* @return
|
* @return Result<String>
|
||||||
*/
|
*/
|
||||||
@PostMapping
|
@PostMapping("")
|
||||||
@ApiOperation("新增分类")
|
@ApiOperation("新增分类")
|
||||||
public Result<String> save(@RequestBody CategoryDTO categoryDTO){
|
public Result<String> save(@RequestBody CategoryDTO categoryDTO){
|
||||||
log.info("新增分类:{}", categoryDTO);
|
log.info("新增分类:{}", categoryDTO);
|
||||||
|
@ -40,8 +41,8 @@ public class CategoryController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分类分页查询
|
* 分类分页查询
|
||||||
* @param categoryPageQueryDTO
|
* @param categoryPageQueryDTO CategoryPageQueryDTO
|
||||||
* @return
|
* @return Result<PageResult>
|
||||||
*/
|
*/
|
||||||
@GetMapping("/page")
|
@GetMapping("/page")
|
||||||
@ApiOperation("分类分页查询")
|
@ApiOperation("分类分页查询")
|
||||||
|
@ -53,8 +54,8 @@ public class CategoryController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除分类
|
* 删除分类
|
||||||
* @param id
|
* @param id Long
|
||||||
* @return
|
* @return Result<String>
|
||||||
*/
|
*/
|
||||||
@DeleteMapping
|
@DeleteMapping
|
||||||
@ApiOperation("删除分类")
|
@ApiOperation("删除分类")
|
||||||
|
@ -66,8 +67,8 @@ public class CategoryController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改分类
|
* 修改分类
|
||||||
* @param categoryDTO
|
* @param categoryDTO CategoryDTO
|
||||||
* @return
|
* @return Result<String>
|
||||||
*/
|
*/
|
||||||
@PutMapping
|
@PutMapping
|
||||||
@ApiOperation("修改分类")
|
@ApiOperation("修改分类")
|
||||||
|
@ -78,9 +79,9 @@ public class CategoryController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启用、禁用分类
|
* 启用、禁用分类
|
||||||
* @param status
|
* @param status Integer
|
||||||
* @param id
|
* @param id Long
|
||||||
* @return
|
* @return Result<String>
|
||||||
*/
|
*/
|
||||||
@PostMapping("/status/{status}")
|
@PostMapping("/status/{status}")
|
||||||
@ApiOperation("启用禁用分类")
|
@ApiOperation("启用禁用分类")
|
||||||
|
@ -91,8 +92,8 @@ public class CategoryController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据类型查询分类
|
* 根据类型查询分类
|
||||||
* @param type
|
* @param type Integer
|
||||||
* @return
|
* @return Result<List<Category>>
|
||||||
*/
|
*/
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@ApiOperation("根据类型查询分类")
|
@ApiOperation("根据类型查询分类")
|
||||||
|
|
|
@ -14,37 +14,33 @@ public interface CategoryMapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 插入数据
|
* 插入数据
|
||||||
* @param category
|
* @param category Category
|
||||||
*/
|
*/
|
||||||
@Insert("insert into category(type, name, sort, status, create_time, update_time, create_user, update_user)" +
|
|
||||||
" VALUES" +
|
|
||||||
" (#{type}, #{name}, #{sort}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
|
|
||||||
void insert(Category category);
|
void insert(Category category);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询
|
* 分页查询
|
||||||
* @param categoryPageQueryDTO
|
* @param categoryPageQueryDTO CategoryPageQueryDTO
|
||||||
* @return
|
* @return Page<Category>
|
||||||
*/
|
*/
|
||||||
Page<Category> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);
|
Page<Category> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据id删除分类
|
* 根据id删除分类
|
||||||
* @param id
|
* @param id Long
|
||||||
*/
|
*/
|
||||||
@Delete("delete from category where id = #{id}")
|
|
||||||
void deleteById(Long id);
|
void deleteById(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据id修改分类
|
* 根据id修改分类
|
||||||
* @param category
|
* @param category Category
|
||||||
*/
|
*/
|
||||||
void update(Category category);
|
void update(Category category);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据类型查询分类
|
* 根据类型查询分类
|
||||||
* @param type
|
* @param type Integer
|
||||||
* @return
|
* @return List<Category>
|
||||||
*/
|
*/
|
||||||
List<Category> list(Integer type);
|
List<Category> list(Integer type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,5 @@ public interface DishMapper {
|
||||||
* @param categoryId Long
|
* @param categoryId Long
|
||||||
* @return Integer
|
* @return Integer
|
||||||
*/
|
*/
|
||||||
@Select("select count(id) from dish where category_id = #{categoryId}")
|
|
||||||
Integer countByCategoryId(Long categoryId);
|
Integer countByCategoryId(Long categoryId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,9 @@ public interface EmployeeMapper {
|
||||||
/**
|
/**
|
||||||
* 根据用户名查询员工
|
* 根据用户名查询员工
|
||||||
*
|
*
|
||||||
* @param username
|
* @param username String
|
||||||
* @return
|
* @return Employee
|
||||||
*/
|
*/
|
||||||
@Select("select * from employee where username = #{username}")
|
|
||||||
Employee getByUsername(String username);
|
Employee getByUsername(String username);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -8,10 +8,8 @@ public interface SetmealMapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据分类id查询套餐的数量
|
* 根据分类id查询套餐的数量
|
||||||
* @param id
|
* @param id Long
|
||||||
* @return
|
* @return Integer
|
||||||
*/
|
*/
|
||||||
@Select("select count(id) from setmeal where category_id = #{categoryId}")
|
|
||||||
Integer countByCategoryId(Long id);
|
Integer countByCategoryId(Long id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,40 +10,40 @@ public interface CategoryService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增分类
|
* 新增分类
|
||||||
* @param categoryDTO
|
* @param categoryDTO CategoryDTO
|
||||||
*/
|
*/
|
||||||
void save(CategoryDTO categoryDTO);
|
void save(CategoryDTO categoryDTO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询
|
* 分页查询
|
||||||
* @param categoryPageQueryDTO
|
* @param categoryPageQueryDTO CategoryPageQueryDTO
|
||||||
* @return
|
* @return PageResult
|
||||||
*/
|
*/
|
||||||
PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);
|
PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据id删除分类
|
* 根据id删除分类
|
||||||
* @param id
|
* @param id Long
|
||||||
*/
|
*/
|
||||||
void deleteById(Long id);
|
void deleteById(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改分类
|
* 修改分类
|
||||||
* @param categoryDTO
|
* @param categoryDTO CategoryDTO
|
||||||
*/
|
*/
|
||||||
void update(CategoryDTO categoryDTO);
|
void update(CategoryDTO categoryDTO);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启用、禁用分类
|
* 启用、禁用分类
|
||||||
* @param status
|
* @param status Integer
|
||||||
* @param id
|
* @param id Long
|
||||||
*/
|
*/
|
||||||
void startOrStop(Integer status, Long id);
|
void startOrStop(Integer status, Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据类型查询分类
|
* 根据类型查询分类
|
||||||
* @param type
|
* @param type Integer
|
||||||
* @return
|
* @return List<Category>
|
||||||
*/
|
*/
|
||||||
List<Category> list(Integer type);
|
List<Category> list(Integer type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,26 +18,26 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
// 分类业务层
|
||||||
* 分类业务层
|
|
||||||
*/
|
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class CategoryServiceImpl implements CategoryService {
|
public class CategoryServiceImpl implements CategoryService {
|
||||||
|
|
||||||
@Autowired
|
@Resource
|
||||||
private CategoryMapper categoryMapper;
|
private CategoryMapper categoryMapper;
|
||||||
@Autowired
|
@Resource
|
||||||
private DishMapper dishMapper;
|
private DishMapper dishMapper;
|
||||||
@Autowired
|
@Resource
|
||||||
private SetmealMapper setmealMapper;
|
private SetmealMapper setmealMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增分类
|
* 新增分类
|
||||||
* @param categoryDTO
|
* @param categoryDTO CategoryDTO
|
||||||
*/
|
*/
|
||||||
public void save(CategoryDTO categoryDTO) {
|
public void save(CategoryDTO categoryDTO) {
|
||||||
Category category = new Category();
|
Category category = new Category();
|
||||||
|
@ -58,8 +58,8 @@ public class CategoryServiceImpl implements CategoryService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询
|
* 分页查询
|
||||||
* @param categoryPageQueryDTO
|
* @param categoryPageQueryDTO CategoryPageQueryDTO
|
||||||
* @return
|
* @return PageResult
|
||||||
*/
|
*/
|
||||||
public PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO) {
|
public PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO) {
|
||||||
PageHelper.startPage(categoryPageQueryDTO.getPage(),categoryPageQueryDTO.getPageSize());
|
PageHelper.startPage(categoryPageQueryDTO.getPage(),categoryPageQueryDTO.getPageSize());
|
||||||
|
@ -70,7 +70,7 @@ public class CategoryServiceImpl implements CategoryService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据id删除分类
|
* 根据id删除分类
|
||||||
* @param id
|
* @param id Long
|
||||||
*/
|
*/
|
||||||
public void deleteById(Long id) {
|
public void deleteById(Long id) {
|
||||||
//查询当前分类是否关联了菜品,如果关联了就抛出业务异常
|
//查询当前分类是否关联了菜品,如果关联了就抛出业务异常
|
||||||
|
@ -93,7 +93,7 @@ public class CategoryServiceImpl implements CategoryService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改分类
|
* 修改分类
|
||||||
* @param categoryDTO
|
* @param categoryDTO CategoryDTO
|
||||||
*/
|
*/
|
||||||
public void update(CategoryDTO categoryDTO) {
|
public void update(CategoryDTO categoryDTO) {
|
||||||
Category category = new Category();
|
Category category = new Category();
|
||||||
|
@ -108,8 +108,8 @@ public class CategoryServiceImpl implements CategoryService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启用、禁用分类
|
* 启用、禁用分类
|
||||||
* @param status
|
* @param status Integer
|
||||||
* @param id
|
* @param id Long
|
||||||
*/
|
*/
|
||||||
public void startOrStop(Integer status, Long id) {
|
public void startOrStop(Integer status, Long id) {
|
||||||
Category category = Category.builder()
|
Category category = Category.builder()
|
||||||
|
@ -123,8 +123,8 @@ public class CategoryServiceImpl implements CategoryService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据类型查询分类
|
* 根据类型查询分类
|
||||||
* @param type
|
* @param type Integer
|
||||||
* @return
|
* @return List<Category>
|
||||||
*/
|
*/
|
||||||
public List<Category> list(Integer type) {
|
public List<Category> list(Integer type) {
|
||||||
return categoryMapper.list(type);
|
return categoryMapper.list(type);
|
||||||
|
|
|
@ -3,6 +3,20 @@
|
||||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
<mapper namespace="com.sky.mapper.CategoryMapper">
|
<mapper namespace="com.sky.mapper.CategoryMapper">
|
||||||
|
|
||||||
|
<!-- 插入数据 -->
|
||||||
|
<insert id="insert">
|
||||||
|
insert into category(type, name, sort, status, create_time, update_time, create_user, update_user)
|
||||||
|
VALUES (#{type}, #{name}, #{sort}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<!-- 根据id删除分类 -->
|
||||||
|
<delete id="deleteById">
|
||||||
|
delete
|
||||||
|
from category
|
||||||
|
where id = #{id}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<!-- 分页查询 -->
|
||||||
<select id="pageQuery" resultType="com.sky.entity.Category">
|
<select id="pageQuery" resultType="com.sky.entity.Category">
|
||||||
select * from category
|
select * from category
|
||||||
<where>
|
<where>
|
||||||
|
@ -16,6 +30,7 @@
|
||||||
order by sort asc , create_time desc
|
order by sort asc , create_time desc
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据id修改分类 -->
|
||||||
<update id="update" parameterType="Category">
|
<update id="update" parameterType="Category">
|
||||||
update category
|
update category
|
||||||
<set>
|
<set>
|
||||||
|
@ -41,6 +56,7 @@
|
||||||
where id = #{id}
|
where id = #{id}
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<!-- 根据类型查询分类 -->
|
||||||
<select id="list" resultType="Category">
|
<select id="list" resultType="Category">
|
||||||
select * from category
|
select * from category
|
||||||
where status = 1
|
where status = 1
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<?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.DishMapper">
|
||||||
|
|
||||||
|
<select id="countByCategoryId" resultType="java.lang.Integer">
|
||||||
|
select count(id)
|
||||||
|
from dish
|
||||||
|
where category_id = #{categoryId}
|
||||||
|
</select>
|
||||||
|
</mapper>
|
|
@ -63,4 +63,9 @@
|
||||||
from employee
|
from employee
|
||||||
where id = #{id};
|
where id = #{id};
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据用户名查询员工 -->
|
||||||
|
<select id="getByUsername" resultType="com.sky.entity.Employee">
|
||||||
|
select * from employee where username = #{username}
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?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">
|
||||||
|
|
||||||
|
<!-- 根据分类id查询套餐的数量 -->
|
||||||
|
<select id="countByCategoryId" resultType="java.lang.Integer">
|
||||||
|
select count(id)
|
||||||
|
from setmeal
|
||||||
|
where category_id = #{categoryId}
|
||||||
|
</select>
|
||||||
|
</mapper>
|
Loading…
Reference in New Issue