From bfddfbc26cac79e28149cfd7a3d3c63c623a39ef Mon Sep 17 00:00:00 2001
From: zepengdev <lzpsmith@outlook.com>
Date: Tue, 30 Sep 2025 11:46:24 +0800
Subject: [PATCH] fix: 调整审批功能比并怎加价格更新接口
---
oying-system/src/main/java/com/oying/modules/pc/product/rest/ProductMerchantController.java | 129 ++++++++++++++++++++++++++++++++++--------
1 files changed, 104 insertions(+), 25 deletions(-)
diff --git a/oying-system/src/main/java/com/oying/modules/pc/product/rest/ProductMerchantController.java b/oying-system/src/main/java/com/oying/modules/pc/product/rest/ProductMerchantController.java
index fe7a50b..1994fd3 100644
--- a/oying-system/src/main/java/com/oying/modules/pc/product/rest/ProductMerchantController.java
+++ b/oying-system/src/main/java/com/oying/modules/pc/product/rest/ProductMerchantController.java
@@ -1,25 +1,27 @@
package com.oying.modules.pc.product.rest;
+import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.ListUtil;
+import cn.hutool.core.util.ObjUtil;
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.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.domain.ProductLabel;
+import com.oying.modules.pc.product.domain.dto.*;
+import com.oying.modules.pc.product.service.ProductImageService;
+import com.oying.modules.pc.product.service.ProductLabelService;
import com.oying.modules.pc.product.service.ProductMerchantService;
import com.oying.modules.pc.product.service.ProductService;
-import com.oying.modules.pc.product.view.ProductMerchantDetailsView;
import com.oying.modules.pc.product.view.ProductMerchantSimpleView;
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 org.springframework.beans.BeanUtils;
+import org.apache.commons.lang3.ObjectUtils;
+import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
-import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@@ -39,22 +41,22 @@
private final ProductService productService;
private final ProductMerchantService productMerchantService;
+ private final ProductImageService productImageService;
+ private final ProductLabelService productLabelService;
@GetMapping(value = "/page")
@ApiOperation("获取指定商户店铺的商品列表(支持分页)")
/*@PreAuthorize("@el.check('merchant:product:page') " +
"and @storeMerchantOwnershipService.check(#storeId)")*/
- public ResponseEntity<?> query(@PathVariable Long storeId,
- ProductQueryCriteria criteria) {
-
- criteria.setStoreId(storeId);
+ public ResponseEntity<?> getProductsByPage(@PathVariable Long storeId, ProductQueryCriteria criteria) {
+ criteria.setStoreId(ObjectUtils.defaultIfNull(criteria.getStoreId(), storeId));
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<ProductMerchantSimpleView> viewPageResult = new PageResult<>(
productList.stream().map(i -> {
ProductMerchantSimpleView view = new ProductMerchantSimpleView();
- BeanUtils.copyProperties(i, view);
+ BeanUtil.copyProperties(i, view);
return view;
}).collect(Collectors.toList()),
productPageResult.getTotalElements());
@@ -65,7 +67,7 @@
@ApiOperation("查询商品")
/*@PreAuthorize("@el.check('merchant:product:byProductId') " +
"and @storeMerchantOwnershipService.check(#storeId)")*/
- public ResponseEntity<?> getById(@PathVariable Long productId) {
+ public ResponseEntity<?> getProductById(@PathVariable Long productId) {
return ResponseEntity.ok(R.success(productService.getById(productId)));
}
@@ -75,14 +77,11 @@
"and @storeMerchantOwnershipService.check(#storeId)")*/
public ResponseEntity<?> getDetailsById(@PathVariable Long productId) {
Product product = productService.getById(productId);
- ProductMerchantDetailsView view = null;
- if (product != null) {
- view = new ProductMerchantDetailsView();
- BeanUtils.copyProperties(product, view);
- view.setMainImageList(ListUtil.empty());
- view.setLabelList(ListUtil.empty());
+ if (ObjUtil.isNotEmpty(product)) {
+ product.setImages(productImageService.queryImagesByProductId(productId));
+ product.setLabels(productLabelService.queryLabelsByProductId(productId));
}
- return ResponseEntity.ok(R.success(view));
+ return ResponseEntity.ok(R.success(product));
}
@PostMapping
@@ -92,20 +91,30 @@
// "and @storeMerchantOwnershipService.check(#storeId)")
public ResponseEntity<?> createProduct(@PathVariable Long storeId,
@Validated @RequestBody ProductMerchantCreateRequest request) {
-
- productMerchantService.create(storeId, request);
- return ResponseEntity.noContent().build();
+ request.setStoreId(ObjectUtils.defaultIfNull(request.getStoreId(), storeId));
+ productMerchantService.createWithAudit(request);
+ return ResponseEntity.status(HttpStatus.CREATED).build();
}
@PutMapping(value = "/{productId}")
- @Log("修改商品")
+ //@Log("修改商品")
@ApiOperation("修改商品")
/*@PreAuthorize("@el.check('merchant:product:edit') " +
"and @storeMerchantOwnershipService.check(#storeId)")*/
public ResponseEntity<?> updateProduct(@PathVariable Long productId,
@Validated @RequestBody ProductMerchantUpdateRequest request) {
+ request.setProductId(ObjectUtils.defaultIfNull(request.getProductId(), productId));
+ productMerchantService.update(request);
+ return ResponseEntity.noContent().build();
+ }
- productMerchantService.update(productId, request);
+ @PutMapping(value = "/{productId}/price")
+ @Log("修改价格")
+ @ApiOperation("修改价格")
+ public ResponseEntity<?> updateProductPrice(@PathVariable Long productId,
+ @Validated @RequestBody ProductPriceUpdateRequest request) {
+ request.setProductId(ObjectUtils.defaultIfNull(request.getProductId(), productId));
+ productMerchantService.updatePrice(request);
return ResponseEntity.noContent().build();
}
@@ -115,6 +124,16 @@
//@PreAuthorize("@el.check('merchant:product:batchDel') " +
// "and @storeMerchantOwnershipService.check(#storeId)")
public ResponseEntity<?> deleteProduct(@ApiParam(value = "传ID数组[]") @RequestBody List<Long> ids) {
+ productMerchantService.batchDelete(ids);
+ return ResponseEntity.noContent().build();
+ }
+
+ @PostMapping(value = "/delete")
+ @Log("批量删除商品")
+ @ApiOperation("批量删除商品")
+ //@PreAuthorize("@el.check('merchant:product:batchDel') " +
+ // "and @storeMerchantOwnershipService.check(#storeId)")
+ public ResponseEntity<?> delProduct(@ApiParam(value = "传ID数组[]") @RequestBody List<Long> ids) {
productMerchantService.batchDelete(ids);
return ResponseEntity.noContent().build();
}
@@ -138,4 +157,64 @@
productMerchantService.takeOffShelf(productId);
return ResponseEntity.noContent().build();
}
+
+ @PostMapping(value = "/{productId}/images")
+ @Log("添加商品图片")
+ @ApiOperation("添加商品图片")
+ public ResponseEntity<?> batchAddImage(@PathVariable("productId") Long productId,
+ @RequestBody List<ProductImageCreateRequest> requests) {
+ requests = requests.stream().peek(i -> i.setProductId(Optional.ofNullable(i.getProductId()).orElse(productId)))
+ .collect(Collectors.toList());
+ productImageService.batchCreate(requests);
+ return ResponseEntity.status(HttpStatus.CREATED).build();
+ }
+
+ @PutMapping(value = "/{productId}/images/change")
+ @Log("商品图片变更")
+ @ApiOperation("商品图片变更")
+ public ResponseEntity<?> updateImage(@PathVariable("productId") Long productId,
+ @RequestBody ProductMerchantUpdateRequest request) {
+ request.setProductId(ObjectUtils.defaultIfNull(request.getProductId(), productId));
+ productMerchantService.updateImages(request);
+ return ResponseEntity.noContent().build();
+ }
+
+ @DeleteMapping(value = "/{productId}/images")
+ @Log("删除商品图片")
+ @ApiOperation("添加商品图片")
+ public ResponseEntity<?> deleteImage(@PathVariable("productId") Long productId,
+ @RequestBody List<Long> ids) {
+ productImageService.deleteAll(ids);
+ return ResponseEntity.noContent().build();
+ }
+
+ @PostMapping(value = "/{productId}/labels")
+ @Log("添加商品标签")
+ @ApiOperation("添加商品标签")
+ public ResponseEntity<?> batchAddLabel(@PathVariable("productId") Long productId,
+ @RequestBody List<ProductLabel> requests) {
+ requests = requests.stream().peek(i -> i.setProductId(Optional.ofNullable(i.getProductId()).orElse(productId)))
+ .collect(Collectors.toList());
+ productLabelService.batchCreate(requests);
+ return ResponseEntity.status(HttpStatus.CREATED).build();
+ }
+
+ @PutMapping(value = "/{productId}/labels/change")
+ @Log("标签变更")
+ @ApiOperation("标签变更")
+ public ResponseEntity<?> updateLabels(@PathVariable("productId") Long productId,
+ @RequestBody ProductMerchantUpdateRequest request) {
+ request.setProductId(ObjectUtils.defaultIfNull(request.getProductId(), productId));
+ productMerchantService.updateLabels(request);
+ return ResponseEntity.noContent().build();
+ }
+
+ @DeleteMapping(value = "/{productId}/labels")
+ @Log("删除商品标签")
+ @ApiOperation("添加商品标签")
+ public ResponseEntity<?> deleteLabel(@PathVariable("productId") Long productId,
+ @RequestBody List<Long> ids) {
+ productLabelService.deleteAll(ids);
+ return ResponseEntity.noContent().build();
+ }
}
--
Gitblit v1.9.3