|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
|
}
|