From ab0637e981ab4c85120ccde35ee24ec4abbe3e24 Mon Sep 17 00:00:00 2001
From: xin <1099200748@qq.com>
Date: Fri, 17 Oct 2025 17:20:15 +0800
Subject: [PATCH] Merge branch 'refs/heads/master' into xin
---
oying-system/src/main/java/com/oying/modules/pc/product/rest/ProductController.java | 130 +++++++++++++++++++++++++++++++++----------
1 files changed, 100 insertions(+), 30 deletions(-)
diff --git a/oying-system/src/main/java/com/oying/modules/pc/product/rest/ProductController.java b/oying-system/src/main/java/com/oying/modules/pc/product/rest/ProductController.java
index fed2f9c..a0a2299 100644
--- a/oying-system/src/main/java/com/oying/modules/pc/product/rest/ProductController.java
+++ b/oying-system/src/main/java/com/oying/modules/pc/product/rest/ProductController.java
@@ -1,73 +1,143 @@
package com.oying.modules.pc.product.rest;
+import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.oying.annotation.Log;
-import com.oying.modules.pc.common.core.domain.R;
import com.oying.modules.pc.product.domain.Product;
-import com.oying.modules.pc.product.service.ProductService;
+import com.oying.modules.pc.product.domain.dto.ProductMerchantCreateRequest;
+import com.oying.modules.pc.product.domain.dto.ProductMerchantUpdateRequest;
import com.oying.modules.pc.product.domain.dto.ProductQueryCriteria;
+import com.oying.modules.pc.product.service.ProductAdminService;
+import com.oying.modules.pc.product.service.ProductImageService;
+import com.oying.modules.pc.product.service.ProductLabelService;
+import com.oying.modules.pc.product.service.ProductService;
+import com.oying.utils.PageResult;
+import com.oying.utils.R;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
-import java.util.List;
-
-import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
-import io.swagger.annotations.*;
-import java.io.IOException;
+
import javax.servlet.http.HttpServletResponse;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
-import com.oying.utils.PageResult;
+import java.io.IOException;
+import java.util.List;
/**
-* @author lzp
-* @date 2025-04-30
-**/
+ * @author lzp
+ * @date 2025-04-30
+ **/
@RestController
@RequiredArgsConstructor
@Api(tags = "商品")
-@RequestMapping("/api/product")
+@RequestMapping("/api/pc/product")
public class ProductController {
private final ProductService productService;
+ private final ProductAdminService productAdminService;
+ private final ProductImageService productImageService;
+ private final ProductLabelService productLabelService;
@ApiOperation("导出数据")
@GetMapping(value = "/download")
- @PreAuthorize("@el.check('product:list')")
+ // @PreAuthorize("@el.check('product:list')")
public void exportProduct(HttpServletResponse response, ProductQueryCriteria criteria) throws IOException {
productService.download(productService.queryAll(criteria), response);
}
- @GetMapping
+ @GetMapping(value = "/list")
@ApiOperation("查询商品")
- @PreAuthorize("@el.check('product:list')")
- public R<PageResult<Product>> queryProduct(ProductQueryCriteria criteria){
+ // @PreAuthorize("@el.check('product:list')")
+ public ResponseEntity<?> getProducts(ProductQueryCriteria criteria) {
+ return ResponseEntity.ok(R.success(productService.queryAll(criteria)));
+ }
+
+ @GetMapping(value = "/batch")
+ @ApiOperation("查询商品(批量)")
+ // @PreAuthorize("@el.check('product:list')")
+ public ResponseEntity<?> getProductsByIds(@RequestParam(value = "ids") List<Long> ids) {
+ return ResponseEntity.ok(R.success(productService.listByIds(ids)));
+ }
+
+ @GetMapping(value = "/page")
+ @ApiOperation("查询商品")
+ // @PreAuthorize("@el.check('product:list')")
+ public ResponseEntity<?> getProductsByPage(ProductQueryCriteria criteria) {
Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
- return R.success(productService.queryAll(criteria,page));
+ PageResult<Product> pageResult = productService.queryAll(criteria, page);
+ pageResult.getContent().forEach(product -> {
+ Long productId = product.getProductId();
+ product.setImages(productImageService.queryImagesByProductId(productId));
+ product.setLabels(productLabelService.queryLabelsByProductId(productId));
+ });
+ return ResponseEntity.ok(R.success(pageResult));
+ }
+
+ @GetMapping(value = "/{productId}")
+ @ApiOperation("查询商品")
+ // @PreAuthorize("@el.check('product:list')")
+ public ResponseEntity<?> getProduct(@PathVariable Long productId) {
+ Product product = productService.getById(productId);
+ if (ObjectUtil.isNotEmpty(product)) {
+ product.setLabels(productLabelService.queryLabelsByProductId(productId));
+ }
+ return ResponseEntity.ok(R.success(product));
+ }
+
+ @GetMapping(value = "/{productId}/details")
+ @ApiOperation("查询商品详情")
+ // @PreAuthorize("@el.check('product:list')")
+ public ResponseEntity<?> getProductDetails(@PathVariable Long productId) {
+ Product product = productService.getById(productId);
+ if (ObjectUtil.isNotEmpty(product)) {
+ product.setImages(productImageService.queryImagesByProductId(productId));
+ product.setLabels(productLabelService.queryLabelsByProductId(productId));
+ }
+ return ResponseEntity.ok(R.success(product));
+ }
+
+ @GetMapping(value = "/{productId}/images")
+ @ApiOperation("查询商品图片")
+ // @PreAuthorize("@el.check('product:list')")
+ public ResponseEntity<?> getProductImages(@PathVariable Long productId) {
+ return ResponseEntity.ok(R.success(productImageService.queryImagesByProductId(productId)));
+ }
+
+
+ @GetMapping(value = "/{productId}/labels")
+ @ApiOperation("查询商品标签信息")
+ // @PreAuthorize("@el.check('product:list')")
+ public ResponseEntity<?> getProductLabels(@PathVariable Long productId) {
+ return ResponseEntity.ok(R.success(productLabelService.queryLabelsByProductId(productId)));
}
@PostMapping
@Log("新增商品")
@ApiOperation("新增商品")
- @PreAuthorize("@el.check('product:add')")
- public R<?> createProduct(@Validated @RequestBody Product resources){
- productService.create(resources);
- return R.success();
+ //@PreAuthorize("@el.check('merchant:product:add')")
+ public ResponseEntity<?> createProduct(@Validated @RequestBody ProductMerchantCreateRequest request) {
+ productAdminService.create(request);
+ return ResponseEntity.status(HttpStatus.CREATED).build();
}
@PutMapping
@Log("修改商品")
@ApiOperation("修改商品")
- @PreAuthorize("@el.check('product:edit')")
- public R<?> updateProduct(@Validated @RequestBody Product resources){
- productService.update(resources);
- return R.success();
+ // @PreAuthorize("@el.check('product:edit')")
+ public ResponseEntity<?> updateProduct(@Validated @RequestBody ProductMerchantUpdateRequest request) {
+ productAdminService.update(request);
+ return ResponseEntity.noContent().build();
}
@DeleteMapping
@Log("删除商品")
@ApiOperation("删除商品")
- @PreAuthorize("@el.check('product:del')")
- public R<?> deleteProduct(@ApiParam(value = "传ID数组[]") @RequestBody List<Long> ids) {
- productService.deleteAll(ids);
- return R.success();
+ // @PreAuthorize("@el.check('product:del')")
+ public ResponseEntity<?> deleteProduct(@ApiParam(value = "传ID数组[]") @RequestBody List<Long> ids) {
+ productAdminService.delete(ids);
+ return ResponseEntity.noContent().build();
}
}
--
Gitblit v1.9.3