|
|
@@ -0,0 +1,81 @@
|
|
|
+package com.etotem.cfc.controller.nutrition;
|
|
|
+
|
|
|
+import com.etotem.cfc.common.Result;
|
|
|
+import com.etotem.cfc.dto.NutritionRecommendDTO;
|
|
|
+import com.etotem.cfc.entity.NutritionCategory;
|
|
|
+import com.etotem.cfc.entity.NutritionPlatformListing;
|
|
|
+import com.etotem.cfc.entity.NutritionProduct;
|
|
|
+import com.etotem.cfc.service.NutritionProductService;
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 营养产品(益生菌/益生元/营养素)推荐接口
|
|
|
+ * 提供分类/品牌/产品搜索/详情/推荐/比价
|
|
|
+ */
|
|
|
+@Tag(name = "营养产品推荐")
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/api/nutrition/product")
|
|
|
+public class NutritionProductController {
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private NutritionProductService nutritionProductService;
|
|
|
+
|
|
|
+ @Operation(summary = "分类列表")
|
|
|
+ @PostMapping("/category/list")
|
|
|
+ public Result<List<NutritionCategory>> listCategories() {
|
|
|
+ return Result.success(nutritionProductService.listCategories());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "品牌列表(含产品数)")
|
|
|
+ @PostMapping("/brand/list")
|
|
|
+ public Result<List<Map<String, Object>>> listBrands() {
|
|
|
+ return Result.success(nutritionProductService.listBrands());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "产品搜索")
|
|
|
+ @PostMapping("/search")
|
|
|
+ public Result<List<NutritionProduct>> search(@RequestBody NutritionRecommendDTO.SearchQuery query) {
|
|
|
+ return Result.success(nutritionProductService.search(query));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "产品详情")
|
|
|
+ @PostMapping("/detail")
|
|
|
+ public Result<Map<String, Object>> detail(@RequestBody Map<String, Long> params) {
|
|
|
+ Long productId = params.get("productId");
|
|
|
+ if (productId == null) {
|
|
|
+ return Result.error("productId 不能为空");
|
|
|
+ }
|
|
|
+ Map<String, Object> detail = nutritionProductService.detail(productId);
|
|
|
+ if (detail == null) {
|
|
|
+ return Result.error("产品不存在");
|
|
|
+ }
|
|
|
+ return Result.success(detail);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "产品推荐")
|
|
|
+ @PostMapping("/recommend")
|
|
|
+ public Result<List<Map<String, Object>>> recommend(@RequestBody NutritionRecommendDTO.RecommendQuery query) {
|
|
|
+ return Result.success(nutritionProductService.recommend(query));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Operation(summary = "平台比价")
|
|
|
+ @PostMapping("/price-compare")
|
|
|
+ public Result<List<NutritionPlatformListing>> priceCompare(@RequestBody Map<String, Long> params) {
|
|
|
+ Long productId = params.get("productId");
|
|
|
+ if (productId == null) {
|
|
|
+ return Result.error("productId 不能为空");
|
|
|
+ }
|
|
|
+ return Result.success(nutritionProductService.priceCompare(productId));
|
|
|
+ }
|
|
|
+}
|