From b394df082b875856884d6d02cce2a43c49ad6704 Mon Sep 17 00:00:00 2001 From: xin <1099200748@qq.com> Date: Fri, 30 May 2025 16:44:46 +0800 Subject: [PATCH] Merge branch 'feature/pc-base' into xin --- oying-system/src/main/java/com/oying/modules/pc/product/rest/ProductCustomerController.java | 84 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 84 insertions(+), 0 deletions(-) diff --git a/oying-system/src/main/java/com/oying/modules/pc/product/rest/ProductCustomerController.java b/oying-system/src/main/java/com/oying/modules/pc/product/rest/ProductCustomerController.java new file mode 100644 index 0000000..95d701d --- /dev/null +++ b/oying-system/src/main/java/com/oying/modules/pc/product/rest/ProductCustomerController.java @@ -0,0 +1,84 @@ +package com.oying.modules.pc.product.rest; + +import cn.hutool.core.collection.ListUtil; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.oying.modules.pc.common.core.domain.R; +import com.oying.modules.pc.product.domain.Product; +import com.oying.modules.pc.product.domain.dto.ProductQueryCriteria; +import com.oying.modules.pc.product.service.ProductService; +import com.oying.modules.pc.product.view.ProductCustomerView; +import com.oying.modules.pc.product.view.ProductMerchantSimpleView; +import com.oying.utils.PageResult; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.RequiredArgsConstructor; +import org.springframework.beans.BeanUtils; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.web.bind.annotation.*; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +/* +* + * @author lzp + * @date 2025-04-30 + * +*/ +@RestController +@RequiredArgsConstructor +@Api(tags = "商品(客户端)") +@RequestMapping("/api/pc/customer/store/{storeId}/product") +public class ProductCustomerController { + + private final ProductService productService; + + @GetMapping(value = "/page") + @ApiOperation("根据商品名称模糊匹配店铺内的商品") + /*@PreAuthorize("@el.check('merchant:product:page')")*/ + public ResponseEntity<?> query(@PathVariable Long storeId, + @RequestParam(value = "categoryId", required = false) Long categoryId, + @RequestParam(value = "secondCategoryId", required = false) Long secondCategoryId, + @RequestParam(value = "blurry", required = false) String blurry) { + + ProductQueryCriteria criteria = new ProductQueryCriteria(); + criteria.setStoreId(storeId); + criteria.setCategoryId(categoryId); + criteria.setSecondCategoryId(secondCategoryId); + criteria.setBlurry(blurry); + Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize()); + PageResult<Product> productPageResult = productService.queryAll(criteria, page); + + List<Product> productList = Optional.ofNullable(productPageResult.getContent()).orElse(ListUtil.empty()); + + PageResult<ProductCustomerView> viewPageResult = new PageResult<>( + productList.stream().map(i -> { + ProductCustomerView view = new ProductCustomerView(); + BeanUtils.copyProperties(i, view); + view.setScore(5.0D); + view.setSold(0); + return view; + }).collect(Collectors.toList()), + productPageResult.getTotalElements()); + return ResponseEntity.ok(R.success(viewPageResult)); + } + + @GetMapping(value = "/{productId}/details") + @ApiOperation("查询商品") + /*@PreAuthorize("@el.check('merchant:product:byProductId')")*/ + public ResponseEntity<?> getDetails(@PathVariable Long productId) { + Product product = productService.getById(productId); + ProductCustomerView customerView = new ProductCustomerView(); + customerView.setProductId(product.getProductId()); + customerView.setTitle(product.getTitle()); + customerView.setPrice(product.getPrice()); + customerView.setScore(5.0D); + customerView.setSold(0); + customerView.setLabelList(ListUtil.empty()); + customerView.setMainImageList(ListUtil.empty()); + return ResponseEntity.ok(R.success(customerView)); + } + +} -- Gitblit v1.9.3