zhoushen 9 months ago
parent 4a8adf3042
commit f3daf2a6be

@ -0,0 +1,88 @@
package com.macro.mall.portal.controller; // 定义包名
// 导入所需的类
import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.PmsProduct;
import com.macro.mall.portal.domain.PmsPortalProductDetail;
import com.macro.mall.portal.domain.PmsProductCategoryNode;
import com.macro.mall.portal.service.PmsPortalProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* Controller
* Created by macro on 2020/4/6.
*/
@Controller // 标识为Spring MVC的Controller
@Api(tags = "PmsPortalProductController") // Swagger注解定义API的标签
@Tag(name = "PmsPortalProductController", description = "前台商品管理") // Swagger注解定义API的标签和描述
@RequestMapping("/product") // 定义请求的基础路径
public class PmsPortalProductController {
@Autowired // 自动注入PmsPortalProductService
private PmsPortalProductService portalProductService;
/**
*
* @param keyword
* @param brandId ID
* @param productCategoryId ID
* @param pageNum
* @param pageSize
* @param sort
* @return
*/
@ApiOperation(value = "综合搜索、筛选、排序") // Swagger注解定义API的操作描述
@ApiImplicitParam(name = "sort", value = "排序字段:0->按相关度1->按新品2->按销量3->价格从低到高4->价格从高到低",
defaultValue = "0", allowableValues = "0,1,2,3,4", paramType = "query", dataType = "integer") // Swagger注解定义API的参数
@RequestMapping(value = "/search", method = RequestMethod.GET) // 定义请求的路径和方法
@ResponseBody // 标识返回值直接作为响应体
public CommonResult<CommonPage<PmsProduct>> search(@RequestParam(required = false) String keyword,
@RequestParam(required = false) Long brandId,
@RequestParam(required = false) Long productCategoryId,
@RequestParam(required = false, defaultValue = "0") Integer pageNum,
@RequestParam(required = false, defaultValue = "5") Integer pageSize,
@RequestParam(required = false, defaultValue = "0") Integer sort) {
// 调用服务层进行商品搜索
List<PmsProduct> productList = portalProductService.search(keyword, brandId, productCategoryId, pageNum, pageSize, sort);
// 返回商品搜索结果
return CommonResult.success(CommonPage.restPage(productList));
}
/**
*
* @return
*/
@ApiOperation("以树形结构获取所有商品分类") // Swagger注解定义API的操作描述
@RequestMapping(value = "/categoryTreeList", method = RequestMethod.GET) // 定义请求的路径和方法
@ResponseBody // 标识返回值直接作为响应体
public CommonResult<List<PmsProductCategoryNode>> categoryTreeList() {
// 调用服务层获取商品分类树
List<PmsProductCategoryNode> list = portalProductService.categoryTreeList();
// 返回商品分类列表
return CommonResult.success(list);
}
/**
*
* @param id ID
* @return
*/
@ApiOperation("获取前台商品详情") // Swagger注解定义API的操作描述
@RequestMapping(value = "/detail/{id}", method = RequestMethod.GET) // 定义请求的路径和方法
@ResponseBody // 标识返回值直接作为响应体
public CommonResult<PmsPortalProductDetail> detail(@PathVariable Long id) {
// 调用服务层获取商品详情
PmsPortalProductDetail productDetail = portalProductService.detail(id);
// 返回商品详情
return CommonResult.success(productDetail);
}
}
Loading…
Cancel
Save