|
|
|
@ -17,17 +17,22 @@ import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 搜索商品管理Controller
|
|
|
|
|
* 搜索商品管理Controller。
|
|
|
|
|
* 该Controller负责处理与搜索商品相关的请求,包括导入商品到ES、删除商品、创建商品、搜索商品等操作。
|
|
|
|
|
* Created by macro on 2018/6/19.
|
|
|
|
|
*/
|
|
|
|
|
@Controller
|
|
|
|
|
@Api(tags = "EsProductController")
|
|
|
|
|
@Tag(name = "EsProductController",description = "搜索商品管理")
|
|
|
|
|
@RequestMapping("/esProduct")
|
|
|
|
|
@Api(tags = "EsProductController") // Swagger注解,用于生成API文档
|
|
|
|
|
@Tag(name = "EsProductController", description = "搜索商品管理") // OpenAPI 3注解,用于生成API文档
|
|
|
|
|
@RequestMapping("/esProduct") // 指定Controller的基础路径
|
|
|
|
|
public class EsProductController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private EsProductService esProductService;
|
|
|
|
|
private EsProductService esProductService; // 自动注入EsProductService服务
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 导入所有数据库中商品到ES。
|
|
|
|
|
* @return 导入成功的商品数量。
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation(value = "导入所有数据库中商品到ES")
|
|
|
|
|
@RequestMapping(value = "/importAll", method = RequestMethod.POST)
|
|
|
|
|
@ResponseBody
|
|
|
|
@ -36,6 +41,11 @@ public class EsProductController {
|
|
|
|
|
return CommonResult.success(count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据id删除商品。
|
|
|
|
|
* @param id 商品id。
|
|
|
|
|
* @return 操作结果。
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation(value = "根据id删除商品")
|
|
|
|
|
@RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
|
|
|
|
|
@ResponseBody
|
|
|
|
@ -44,6 +54,11 @@ public class EsProductController {
|
|
|
|
|
return CommonResult.success(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据id批量删除商品。
|
|
|
|
|
* @param ids 商品id列表。
|
|
|
|
|
* @return 操作结果。
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation(value = "根据id批量删除商品")
|
|
|
|
|
@RequestMapping(value = "/delete/batch", method = RequestMethod.POST)
|
|
|
|
|
@ResponseBody
|
|
|
|
@ -52,6 +67,11 @@ public class EsProductController {
|
|
|
|
|
return CommonResult.success(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据id创建商品。
|
|
|
|
|
* @param id 商品id。
|
|
|
|
|
* @return 创建的商品信息。
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation(value = "根据id创建商品")
|
|
|
|
|
@RequestMapping(value = "/create/{id}", method = RequestMethod.POST)
|
|
|
|
|
@ResponseBody
|
|
|
|
@ -64,6 +84,13 @@ public class EsProductController {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 简单搜索商品。
|
|
|
|
|
* @param keyword 搜索关键词。
|
|
|
|
|
* @param pageNum 页码。
|
|
|
|
|
* @param pageSize 每页大小。
|
|
|
|
|
* @return 搜索结果分页。
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation(value = "简单搜索")
|
|
|
|
|
@RequestMapping(value = "/search/simple", method = RequestMethod.GET)
|
|
|
|
|
@ResponseBody
|
|
|
|
@ -74,6 +101,16 @@ public class EsProductController {
|
|
|
|
|
return CommonResult.success(CommonPage.restPage(esProductPage));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 综合搜索、筛选、排序商品。
|
|
|
|
|
* @param keyword 搜索关键词。
|
|
|
|
|
* @param brandId 品牌id。
|
|
|
|
|
* @param productCategoryId 产品分类id。
|
|
|
|
|
* @param pageNum 页码。
|
|
|
|
|
* @param pageSize 每页大小。
|
|
|
|
|
* @param sort 排序字段。
|
|
|
|
|
* @return 搜索结果分页。
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation(value = "综合搜索、筛选、排序")
|
|
|
|
|
@ApiImplicitParam(name = "sort", value = "排序字段:0->按相关度;1->按新品;2->按销量;3->价格从低到高;4->价格从高到低",
|
|
|
|
|
defaultValue = "0", allowableValues = "0,1,2,3,4", paramType = "query", dataType = "integer")
|
|
|
|
@ -89,6 +126,13 @@ public class EsProductController {
|
|
|
|
|
return CommonResult.success(CommonPage.restPage(esProductPage));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据商品id推荐商品。
|
|
|
|
|
* @param id 商品id。
|
|
|
|
|
* @param pageNum 页码。
|
|
|
|
|
* @param pageSize 每页大小。
|
|
|
|
|
* @return 推荐商品分页。
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation(value = "根据商品id推荐商品")
|
|
|
|
|
@RequestMapping(value = "/recommend/{id}", method = RequestMethod.GET)
|
|
|
|
|
@ResponseBody
|
|
|
|
@ -99,6 +143,11 @@ public class EsProductController {
|
|
|
|
|
return CommonResult.success(CommonPage.restPage(esProductPage));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取搜索的相关品牌、分类及筛选属性。
|
|
|
|
|
* @param keyword 搜索关键词。
|
|
|
|
|
* @return 相关信息。
|
|
|
|
|
*/
|
|
|
|
|
@ApiOperation(value = "获取搜索的相关品牌、分类及筛选属性")
|
|
|
|
|
@RequestMapping(value = "/search/relate", method = RequestMethod.GET)
|
|
|
|
|
@ResponseBody
|
|
|
|
@ -106,4 +155,4 @@ public class EsProductController {
|
|
|
|
|
EsProductRelatedInfo productRelatedInfo = esProductService.searchRelatedInfo(keyword);
|
|
|
|
|
return CommonResult.success(productRelatedInfo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|