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