|
|
|
@ -1,94 +1,282 @@
|
|
|
|
|
// 声明该类所在的包,此包为 com.ew.gerocomium.controller
|
|
|
|
|
package com.ew.gerocomium.controller;
|
|
|
|
|
|
|
|
|
|
// 导入自定义的常量类,一般包含项目里固定的常量信息,像开发者名字等
|
|
|
|
|
import com.ew.gerocomium.common.constant.Constant;
|
|
|
|
|
// 导入自定义的基础结果类,用于封装接口返回的结果,包含操作是否成功、数据等
|
|
|
|
|
import com.ew.gerocomium.dao.base.Result;
|
|
|
|
|
// 导入操作菜品的查询实体类,用于封装新增、编辑菜品时的请求数据
|
|
|
|
|
import com.ew.gerocomium.dao.query.OperateDishesQuery;
|
|
|
|
|
// 导入操作菜品类型的查询实体类,用于封装新增、编辑菜品类型时的请求数据
|
|
|
|
|
import com.ew.gerocomium.dao.query.OperateDishesTypeQuery;
|
|
|
|
|
// 导入分页查询菜品的查询实体类,用于封装分页查询菜品时的请求数据,含查询条件和分页信息
|
|
|
|
|
import com.ew.gerocomium.dao.query.PageDishesByKeyQuery;
|
|
|
|
|
// 导入菜品业务逻辑服务类,用于处理菜品相关的具体业务逻辑
|
|
|
|
|
import com.ew.gerocomium.service.DishesService;
|
|
|
|
|
// 导入 Swagger 相关注解,用于生成 API 文档,方便接口的管理和展示
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
|
|
// 导入 Spring Security 的权限控制注解,用于控制对接口的访问权限
|
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
|
// 导入 Spring MVC 相关注解,用于处理 HTTP 请求和定义接口
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
// 导入 Spring 的资源注入注解,用于实现依赖注入
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 菜品管理控制器,负责处理与菜品和菜品分类相关的 HTTP 请求。
|
|
|
|
|
*/
|
|
|
|
|
// 使用 Swagger 注解,标记该控制器的标签为“菜品管理”,方便在生成 API 文档时进行分类展示
|
|
|
|
|
@Api(tags = "菜品管理")
|
|
|
|
|
// 标记该类为 RESTful 风格的控制器,用于处理 HTTP 请求并返回 JSON 等格式的响应
|
|
|
|
|
@RestController
|
|
|
|
|
// 定义该控制器的基础请求路径为 /dishes,该控制器下的所有请求都以此为前缀
|
|
|
|
|
@RequestMapping("/dishes")
|
|
|
|
|
// 权限控制注解,只有拥有指定权限('/food/dish')的用户才能访问该控制器的方法
|
|
|
|
|
@PreAuthorize("@AuthorityAssert.hasAuthority('/food/dish')")
|
|
|
|
|
public class DishesController {
|
|
|
|
|
// 通过依赖注入的方式获取 DishesService 的实例,用于调用该服务类的方法处理业务逻辑
|
|
|
|
|
@Resource
|
|
|
|
|
private DishesService dishesService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取菜品分类列表。
|
|
|
|
|
*
|
|
|
|
|
* @param dishesTypeName 可选的菜品分类名称,用于筛选特定名称的分类,可为空。
|
|
|
|
|
* @param token 接口访问请求头中的令牌,用于身份验证。
|
|
|
|
|
* @return 包含菜品分类列表的结果对象。
|
|
|
|
|
*/
|
|
|
|
|
// 处理 HTTP GET 请求,请求路径为 /dishes/listDishesType,用于获取菜品分类列表
|
|
|
|
|
@GetMapping("/listDishesType")
|
|
|
|
|
// 使用 Swagger 注解描述该接口的功能和开发者信息
|
|
|
|
|
@ApiOperation(value = "获取菜品分类", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
|
|
|
|
|
public Result listDishesType(@ApiParam(value = "获取菜品分类请求参数", required = false) String dishesTypeName,
|
|
|
|
|
@ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
|
|
|
|
|
public Result listDishesType(
|
|
|
|
|
// 使用 Swagger 注解描述该参数的作用,该参数为可选的菜品分类名称,用于筛选特定名称的分类
|
|
|
|
|
@ApiParam(value = "获取菜品分类请求参数", required = false)
|
|
|
|
|
// 接收菜品分类名称参数
|
|
|
|
|
String dishesTypeName,
|
|
|
|
|
// 使用 Swagger 注解描述该参数的作用,并标记为必需参数,该参数为接口访问请求头中的令牌
|
|
|
|
|
@ApiParam(value = "接口访问请求头", required = true)
|
|
|
|
|
// 从请求头中获取令牌
|
|
|
|
|
@RequestHeader String token) {
|
|
|
|
|
// 调用菜品服务类的获取菜品分类列表方法,并返回操作结果
|
|
|
|
|
return dishesService.listDishesType(dishesTypeName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分页查询菜品信息。
|
|
|
|
|
*
|
|
|
|
|
* @param pageDishesByKeyQuery 分页查询菜品的请求实体,包含查询条件和分页信息。
|
|
|
|
|
* @param token 接口访问请求头中的令牌,用于身份验证。
|
|
|
|
|
* @return 包含分页查询结果的结果对象。
|
|
|
|
|
*/
|
|
|
|
|
// 处理 HTTP GET 请求,请求路径为 /dishes/pageDishesByKey,用于分页查询菜品信息
|
|
|
|
|
@GetMapping("/pageDishesByKey")
|
|
|
|
|
// 使用 Swagger 注解描述该接口的功能和开发者信息
|
|
|
|
|
@ApiOperation(value = "分页查询菜品", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
|
|
|
|
|
public Result pageDishesByKey(@ApiParam(value = "分页查询菜品请求实体", required = true) PageDishesByKeyQuery pageDishesByKeyQuery,
|
|
|
|
|
@ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
|
|
|
|
|
public Result pageDishesByKey(
|
|
|
|
|
// 使用 Swagger 注解描述该参数的作用,并标记为必需参数,该参数为分页查询菜品的请求实体
|
|
|
|
|
@ApiParam(value = "分页查询菜品请求实体", required = true)
|
|
|
|
|
// 接收分页查询菜品的请求实体
|
|
|
|
|
PageDishesByKeyQuery pageDishesByKeyQuery,
|
|
|
|
|
// 使用 Swagger 注解描述该参数的作用,并标记为必需参数,该参数为接口访问请求头中的令牌
|
|
|
|
|
@ApiParam(value = "接口访问请求头", required = true)
|
|
|
|
|
// 从请求头中获取令牌
|
|
|
|
|
@RequestHeader String token) {
|
|
|
|
|
// 调用菜品服务类的分页查询菜品方法,并返回操作结果
|
|
|
|
|
return dishesService.pageDishesByKey(pageDishesByKeyQuery);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增菜品分类。
|
|
|
|
|
*
|
|
|
|
|
* @param operateDishesTypeQuery 新增菜品分类的请求实体,包含菜品分类的详细信息。
|
|
|
|
|
* @param token 接口访问请求头中的令牌,用于身份验证。
|
|
|
|
|
* @return 包含新增操作结果的结果对象。
|
|
|
|
|
*/
|
|
|
|
|
// 处理 HTTP POST 请求,请求路径为 /dishes/addDishesType,用于新增菜品分类
|
|
|
|
|
@PostMapping("/addDishesType")
|
|
|
|
|
// 使用 Swagger 注解描述该接口的功能和开发者信息
|
|
|
|
|
@ApiOperation(value = "新增菜品分类", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
|
|
|
|
|
public Result addDishesType(@ApiParam(value = "新增菜品分类请求实体", required = true) @RequestBody OperateDishesTypeQuery operateDishesTypeQuery,
|
|
|
|
|
@ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
|
|
|
|
|
public Result addDishesType(
|
|
|
|
|
// 使用 Swagger 注解描述该参数的作用,并标记为必需参数,该参数为新增菜品分类的请求实体
|
|
|
|
|
@ApiParam(value = "新增菜品分类请求实体", required = true)
|
|
|
|
|
// 从请求体中接收新增菜品分类的请求实体
|
|
|
|
|
@RequestBody OperateDishesTypeQuery operateDishesTypeQuery,
|
|
|
|
|
// 使用 Swagger 注解描述该参数的作用,并标记为必需参数,该参数为接口访问请求头中的令牌
|
|
|
|
|
@ApiParam(value = "接口访问请求头", required = true)
|
|
|
|
|
// 从请求头中获取令牌
|
|
|
|
|
@RequestHeader String token) {
|
|
|
|
|
// 调用菜品服务类的新增菜品分类方法,并返回操作结果
|
|
|
|
|
return dishesService.addDishesType(operateDishesTypeQuery);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据编号查询菜品分类信息。
|
|
|
|
|
*
|
|
|
|
|
* @param dishesTypeId 要查询的菜品分类的编号。
|
|
|
|
|
* @param token 接口访问请求头中的令牌,用于身份验证。
|
|
|
|
|
* @return 包含查询到的菜品分类信息的结果对象。
|
|
|
|
|
*/
|
|
|
|
|
// 处理 HTTP GET 请求,请求路径为 /dishes/getDishesTypeById,用于根据编号查询菜品分类信息
|
|
|
|
|
@GetMapping("/getDishesTypeById")
|
|
|
|
|
// 使用 Swagger 注解描述该接口的功能和开发者信息
|
|
|
|
|
@ApiOperation(value = "根据编号查询菜品分类", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
|
|
|
|
|
public Result getDishesTypeById(@ApiParam(value = "根据编号查询菜品分类请求参数", required = true) @RequestParam Long dishesTypeId,
|
|
|
|
|
@ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
|
|
|
|
|
public Result getDishesTypeById(
|
|
|
|
|
// 使用 Swagger 注解描述该参数的作用,并标记为必需参数,该参数为要查询的菜品分类的编号
|
|
|
|
|
@ApiParam(value = "根据编号查询菜品分类请求参数", required = true)
|
|
|
|
|
// 从请求参数中获取菜品分类编号
|
|
|
|
|
@RequestParam Long dishesTypeId,
|
|
|
|
|
// 使用 Swagger 注解描述该参数的作用,并标记为必需参数,该参数为接口访问请求头中的令牌
|
|
|
|
|
@ApiParam(value = "接口访问请求头", required = true)
|
|
|
|
|
// 从请求头中获取令牌
|
|
|
|
|
@RequestHeader String token) {
|
|
|
|
|
// 调用菜品服务类的根据编号查询菜品分类方法,并返回操作结果
|
|
|
|
|
return dishesService.getDishesTypeById(dishesTypeId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 编辑菜品分类信息。
|
|
|
|
|
*
|
|
|
|
|
* @param operateDishesTypeQuery 编辑菜品分类的请求实体,包含要修改的菜品分类信息。
|
|
|
|
|
* @param token 接口访问请求头中的令牌,用于身份验证。
|
|
|
|
|
* @return 包含编辑操作结果的结果对象。
|
|
|
|
|
*/
|
|
|
|
|
// 处理 HTTP PUT 请求,请求路径为 /dishes/editDishesType,用于编辑菜品分类信息
|
|
|
|
|
@PutMapping("/editDishesType")
|
|
|
|
|
// 使用 Swagger 注解描述该接口的功能和开发者信息
|
|
|
|
|
@ApiOperation(value = "编辑菜品分类", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
|
|
|
|
|
public Result editDishesType(@ApiParam(value = "编辑菜品分类请求实体", required = true) @RequestBody OperateDishesTypeQuery operateDishesTypeQuery,
|
|
|
|
|
@ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
|
|
|
|
|
public Result editDishesType(
|
|
|
|
|
// 使用 Swagger 注解描述该参数的作用,并标记为必需参数,该参数为编辑菜品分类的请求实体
|
|
|
|
|
@ApiParam(value = "编辑菜品分类请求实体", required = true)
|
|
|
|
|
// 从请求体中接收编辑菜品分类的请求实体
|
|
|
|
|
@RequestBody OperateDishesTypeQuery operateDishesTypeQuery,
|
|
|
|
|
// 使用 Swagger 注解描述该参数的作用,并标记为必需参数,该参数为接口访问请求头中的令牌
|
|
|
|
|
@ApiParam(value = "接口访问请求头", required = true)
|
|
|
|
|
// 从请求头中获取令牌
|
|
|
|
|
@RequestHeader String token) {
|
|
|
|
|
// 调用菜品服务类的编辑菜品分类方法,并返回操作结果
|
|
|
|
|
return dishesService.editDishesType(operateDishesTypeQuery);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除菜品分类信息。
|
|
|
|
|
*
|
|
|
|
|
* @param dishesTypeId 要删除的菜品分类的编号。
|
|
|
|
|
* @param token 接口访问请求头中的令牌,用于身份验证。
|
|
|
|
|
* @return 包含删除操作结果的结果对象。
|
|
|
|
|
*/
|
|
|
|
|
// 处理 HTTP DELETE 请求,请求路径为 /dishes/deleteDishesType,用于删除菜品分类信息
|
|
|
|
|
@DeleteMapping("/deleteDishesType")
|
|
|
|
|
// 使用 Swagger 注解描述该接口的功能和开发者信息
|
|
|
|
|
@ApiOperation(value = "删除菜品分类", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
|
|
|
|
|
public Result deleteDishesType(@ApiParam(value = "删除菜品分类请求参数", required = true) @RequestParam Long dishesTypeId,
|
|
|
|
|
@ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
|
|
|
|
|
public Result deleteDishesType(
|
|
|
|
|
// 使用 Swagger 注解描述该参数的作用,并标记为必需参数,该参数为要删除的菜品分类的编号
|
|
|
|
|
@ApiParam(value = "删除菜品分类请求参数", required = true)
|
|
|
|
|
// 从请求参数中获取菜品分类编号
|
|
|
|
|
@RequestParam Long dishesTypeId,
|
|
|
|
|
// 使用 Swagger 注解描述该参数的作用,并标记为必需参数,该参数为接口访问请求头中的令牌
|
|
|
|
|
@ApiParam(value = "接口访问请求头", required = true)
|
|
|
|
|
// 从请求头中获取令牌
|
|
|
|
|
@RequestHeader String token) {
|
|
|
|
|
// 调用菜品服务类的删除菜品分类方法,并返回操作结果
|
|
|
|
|
return dishesService.deleteDishesType(dishesTypeId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增菜品信息。
|
|
|
|
|
*
|
|
|
|
|
* @param operateDishesQuery 新增菜品的请求实体,包含菜品的详细信息。
|
|
|
|
|
* @param token 接口访问请求头中的令牌,用于身份验证。
|
|
|
|
|
* @return 包含新增操作结果的结果对象。
|
|
|
|
|
*/
|
|
|
|
|
// 处理 HTTP POST 请求,请求路径为 /dishes/addDishes,用于新增菜品信息
|
|
|
|
|
@PostMapping("/addDishes")
|
|
|
|
|
// 使用 Swagger 注解描述该接口的功能和开发者信息
|
|
|
|
|
@ApiOperation(value = "新增菜品", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
|
|
|
|
|
public Result addDishes(@ApiParam(value = "新增菜品请求实体", required = true) @RequestBody OperateDishesQuery operateDishesQuery,
|
|
|
|
|
@ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
|
|
|
|
|
public Result addDishes(
|
|
|
|
|
// 使用 Swagger 注解描述该参数的作用,并标记为必需参数,该参数为新增菜品的请求实体
|
|
|
|
|
@ApiParam(value = "新增菜品请求实体", required = true)
|
|
|
|
|
// 从请求体中接收新增菜品的请求实体
|
|
|
|
|
@RequestBody OperateDishesQuery operateDishesQuery,
|
|
|
|
|
// 使用 Swagger 注解描述该参数的作用,并标记为必需参数,该参数为接口访问请求头中的令牌
|
|
|
|
|
@ApiParam(value = "接口访问请求头", required = true)
|
|
|
|
|
// 从请求头中获取令牌
|
|
|
|
|
@RequestHeader String token) {
|
|
|
|
|
// 调用菜品服务类的新增菜品方法,并返回操作结果
|
|
|
|
|
return dishesService.addDishes(operateDishesQuery);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据编号查询菜品信息。
|
|
|
|
|
*
|
|
|
|
|
* @param dishesId 要查询的菜品的编号。
|
|
|
|
|
* @param token 接口访问请求头中的令牌,用于身份验证。
|
|
|
|
|
* @return 包含查询到的菜品信息的结果对象。
|
|
|
|
|
*/
|
|
|
|
|
// 处理 HTTP GET 请求,请求路径为 /dishes/getDishesById,用于根据编号查询菜品信息
|
|
|
|
|
@GetMapping("/getDishesById")
|
|
|
|
|
// 使用 Swagger 注解描述该接口的功能和开发者信息
|
|
|
|
|
@ApiOperation(value = "根据编号查询菜品", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
|
|
|
|
|
public Result getDishesById(@ApiParam(value = "根据编号查询菜品请求参数", required = true) @RequestParam Long dishesId,
|
|
|
|
|
@ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
|
|
|
|
|
public Result getDishesById(
|
|
|
|
|
// 使用 Swagger 注解描述该参数的作用,并标记为必需参数,该参数为要查询的菜品的编号
|
|
|
|
|
@ApiParam(value = "根据编号查询菜品请求参数", required = true)
|
|
|
|
|
// 从请求参数中获取菜品编号
|
|
|
|
|
@RequestParam Long dishesId,
|
|
|
|
|
// 使用 Swagger 注解描述该参数的作用,并标记为必需参数,该参数为接口访问请求头中的令牌
|
|
|
|
|
@ApiParam(value = "接口访问请求头", required = true)
|
|
|
|
|
// 从请求头中获取令牌
|
|
|
|
|
@RequestHeader String token) {
|
|
|
|
|
// 调用菜品服务类的根据编号查询菜品方法,并返回操作结果
|
|
|
|
|
return dishesService.getDishesById(dishesId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 编辑菜品信息。
|
|
|
|
|
*
|
|
|
|
|
* @param operateDishesQuery 编辑菜品的请求实体,包含要修改的菜品信息。
|
|
|
|
|
* @param token 接口访问请求头中的令牌,用于身份验证。
|
|
|
|
|
* @return 包含编辑操作结果的结果对象。
|
|
|
|
|
*/
|
|
|
|
|
// 处理 HTTP PUT 请求,请求路径为 /dishes/editDishes,用于编辑菜品信息
|
|
|
|
|
@PutMapping("/editDishes")
|
|
|
|
|
// 使用 Swagger 注解描述该接口的功能和开发者信息
|
|
|
|
|
@ApiOperation(value = "编辑菜品", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
|
|
|
|
|
public Result editDishes(@ApiParam(value = "编辑菜品请求实体", required = true) @RequestBody OperateDishesQuery operateDishesQuery,
|
|
|
|
|
@ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
|
|
|
|
|
public Result editDishes(
|
|
|
|
|
// 使用 Swagger 注解描述该参数的作用,并标记为必需参数,该参数为编辑菜品的请求实体
|
|
|
|
|
@ApiParam(value = "编辑菜品请求实体", required = true)
|
|
|
|
|
// 从请求体中接收编辑菜品的请求实体
|
|
|
|
|
@RequestBody OperateDishesQuery operateDishesQuery,
|
|
|
|
|
// 使用 Swagger 注解描述该参数的作用,并标记为必需参数,该参数为接口访问请求头中的令牌
|
|
|
|
|
@ApiParam(value = "接口访问请求头", required = true)
|
|
|
|
|
// 从请求头中获取令牌
|
|
|
|
|
@RequestHeader String token) {
|
|
|
|
|
// 调用菜品服务类的编辑菜品方法,并返回操作结果
|
|
|
|
|
return dishesService.editDishes(operateDishesQuery);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 删除菜品信息。
|
|
|
|
|
*
|
|
|
|
|
* @param dishesId 要删除的菜品的编号。
|
|
|
|
|
* @param token 接口访问请求头中的令牌,用于身份验证。
|
|
|
|
|
* @return 包含删除操作结果的结果对象。
|
|
|
|
|
*/
|
|
|
|
|
// 处理 HTTP DELETE 请求,请求路径为 /dishes/deleteDishes,用于删除菜品信息
|
|
|
|
|
@DeleteMapping("/deleteDishes")
|
|
|
|
|
// 使用 Swagger 注解描述该接口的功能和开发者信息
|
|
|
|
|
@ApiOperation(value = "删除菜品", notes = Constant.DEVELOPER + Constant.EMPEROR_WEN)
|
|
|
|
|
public Result deleteDishes(@ApiParam(value = "删除菜品请求参数", required = true) @RequestParam Long dishesId,
|
|
|
|
|
@ApiParam(value = "接口访问请求头", required = true) @RequestHeader String token) {
|
|
|
|
|
public Result deleteDishes(
|
|
|
|
|
// 使用 Swagger 注解描述该参数的作用,并标记为必需参数,该参数为要删除的菜品的编号
|
|
|
|
|
@ApiParam(value = "删除菜品请求参数", required = true)
|
|
|
|
|
// 从请求参数中获取菜品编号
|
|
|
|
|
@RequestParam Long dishesId,
|
|
|
|
|
// 使用 Swagger 注解描述该参数的作用,并标记为必需参数,该参数为接口访问请求头中的令牌
|
|
|
|
|
@ApiParam(value = "接口访问请求头", required = true)
|
|
|
|
|
// 从请求头中获取令牌
|
|
|
|
|
@RequestHeader String token) {
|
|
|
|
|
// 调用菜品服务类的删除菜品方法,并返回操作结果
|
|
|
|
|
return dishesService.deleteDishes(dishesId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|