From 26cb1a9a41960727873d6f31c28226a4eccec460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=9F=91=E8=9E=82?= Date: Tue, 14 Apr 2026 19:28:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=BF=94=E5=9B=9E=E6=88=90=E6=9C=AC=E5=8F=98?= =?UTF-8?q?=E6=9B=B4=E7=9A=84=E8=A7=84=E6=A0=BCID=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - UpdateProductResultDTO 新增 data.costChangedSpecIds 字段 - ProductService.updateProduct 返回类型改为 UpdateProductResultDTO - ProductSpecServiceImpl 检测成本变更逻辑:null/0 互为等价,只有非零实际值变化才算变更 - ProductSpecVO 新增 costChanged 字段 - 前端类型 ProductVO.UpdateProductResult 同步更新 --- .../product/controller/ProductController.java | 12 +++--- .../controller/ProductSpecController.java | 6 +-- .../model/dto/UpdateProductResultDTO.java | 20 ++++++++++ .../ecom/product/model/vo/ProductSpecVO.java | 6 +++ .../ecom/product/service/ProductService.java | 5 ++- .../service/impl/ProductServiceImpl.java | 38 +++++++++++-------- .../service/impl/ProductSpecServiceImpl.java | 19 +++++++++- .../src/api/ecommerce/product/apis.ts | 2 +- .../api/ecommerce/product/types/types.vo.ts | 6 +++ 9 files changed, 86 insertions(+), 28 deletions(-) create mode 100644 ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/model/dto/UpdateProductResultDTO.java diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/controller/ProductController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/controller/ProductController.java index db1b0b42..20876baa 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/controller/ProductController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/controller/ProductController.java @@ -12,6 +12,8 @@ import top.xyquan.ecomdmbbackend.common.response.ApiResponse; import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.CreateProductDTO; import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.ProductFilterDTO; import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.UpdateProductDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.UpdateProductResultDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.UpdateProductResultDTO; import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductVO; import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductService; @@ -34,16 +36,16 @@ public class ProductController { @RequirePermission(value = "ecom:product:create", description = "创建商品", allowSuper = true) public ApiResponse createProduct(@Valid @RequestBody CreateProductDTO createProductDTO) { ProductVO productVO = productService.createProduct(createProductDTO); - return ApiResponse.success(productVO); + return ApiResponse.success("商品创建成功", productVO); } @Operation(summary = "更新商品", description = "更新现有商品信息") @PutMapping("/update/{id}") @RequirePermission(value = "ecom:product:update", description = "更新商品", allowSuper = true) - public ApiResponse updateProduct(@Valid @RequestBody UpdateProductDTO updateProductDTO, + public ApiResponse updateProduct(@Valid @RequestBody UpdateProductDTO updateProductDTO, @Parameter(description = "商品ID") @PathVariable Long id) { - ProductVO productVO = productService.updateProduct(updateProductDTO, id); - return ApiResponse.success(productVO); + UpdateProductResultDTO result = productService.updateProduct(updateProductDTO, id); + return ApiResponse.success("商品更新成功", result); } @Operation(summary = "删除商品", description = "删除指定商品") @@ -52,7 +54,7 @@ public class ProductController { public ApiResponse deleteProduct( @Parameter(description = "商品ID") @PathVariable Long id) { productService.deleteProduct(id); - return ApiResponse.success(); + return ApiResponse.success("商品删除成功", null); } @Operation(summary = "分页获取商品列表", description = "分页获取商品列表,支持条件过滤") diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/controller/ProductSpecController.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/controller/ProductSpecController.java index 082358db..dadcb4d2 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/controller/ProductSpecController.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/controller/ProductSpecController.java @@ -38,7 +38,7 @@ public class ProductSpecController { @RequirePermission(value = "ecom:product:create", description = "创建商品规格", allowSuper = true) public ApiResponse createProductSpec(@Valid @RequestBody CreateProductSpecDTO createProductSpecDTO) { ProductSpecVO productSpecVO = productSpecService.createProductSpec(createProductSpecDTO); - return ApiResponse.success(productSpecVO); + return ApiResponse.success("规格创建成功", productSpecVO); } @Operation(summary = "更新商品规格", description = "更新现有商品规格信息") @@ -47,7 +47,7 @@ public class ProductSpecController { public ApiResponse updateProductSpec(@Valid @RequestBody UpdateProductSpecDTO updateProductSpecDTO, @Parameter(description = "商品规格ID") @PathVariable Long id) { ProductSpecVO productSpecVO = productSpecService.updateProductSpec(updateProductSpecDTO, id); - return ApiResponse.success(productSpecVO); + return ApiResponse.success("规格更新成功", productSpecVO); } @Operation(summary = "删除商品规格", description = "删除指定商品规格") @@ -56,7 +56,7 @@ public class ProductSpecController { public ApiResponse deleteProductSpec( @Parameter(description = "商品规格ID") @PathVariable Long id) { productSpecService.deleteProductSpec(id); - return ApiResponse.success(); + return ApiResponse.success("规格删除成功", null); } @Operation(summary = "分页获取商品规格列表", description = "分页获取商品规格列表,支持条件过滤") diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/model/dto/UpdateProductResultDTO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/model/dto/UpdateProductResultDTO.java new file mode 100644 index 00000000..4244fc03 --- /dev/null +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/model/dto/UpdateProductResultDTO.java @@ -0,0 +1,20 @@ +package top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.util.List; + +/** + * 更新商品成功响应DTO + */ +@Data +@Schema(description = "更新商品成功响应DTO") +public class UpdateProductResultDTO { + + /** + * 本次更新中成本发生变更的规格ID列表 + */ + @Schema(description = "成本发生变更的规格ID列表") + private List costChangedSpecIds; +} \ No newline at end of file diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/model/vo/ProductSpecVO.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/model/vo/ProductSpecVO.java index d0d378c8..214ee97c 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/model/vo/ProductSpecVO.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/model/vo/ProductSpecVO.java @@ -96,4 +96,10 @@ public class ProductSpecVO { */ @Schema(description = "更新人ID", example = "1") private Long updateBy; + + /** + * 成本是否变更(本次更新中成本字段有变化) + */ + @Schema(description = "成本是否变更", example = "true") + private Boolean costChanged; } diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/service/ProductService.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/service/ProductService.java index c2cf70c9..7a9d77d1 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/service/ProductService.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/service/ProductService.java @@ -6,6 +6,7 @@ import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO; import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.CreateProductDTO; import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.ProductFilterDTO; import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.UpdateProductDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.UpdateProductResultDTO; import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductPO; import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductVO; @@ -28,9 +29,9 @@ public interface ProductService extends IService { * * @param updateProductDTO 更新商品DTO * @param id 商品ID - * @return 商品VO + * @return 更新结果(含成本变更的规格ID列表) */ - ProductVO updateProduct(UpdateProductDTO updateProductDTO, Long id); + UpdateProductResultDTO updateProduct(UpdateProductDTO updateProductDTO, Long id); /** * 删除商品 diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/service/impl/ProductServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/service/impl/ProductServiceImpl.java index 35607d3d..7bbacacc 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/service/impl/ProductServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/service/impl/ProductServiceImpl.java @@ -15,6 +15,8 @@ import top.xyquan.ecomdmbbackend.modules.ecom.product.mapper.ProductMapper; import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.CreateProductDTO; import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.ProductFilterDTO; import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.UpdateProductDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.UpdateProductResultDTO; +import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.UpdateProductSpecDTO; import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductPO; import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSpecPO; import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductVO; @@ -26,6 +28,7 @@ import top.xyquan.ecomdmbbackend.modules.sys.file.model.po.SysFilePO; import top.xyquan.ecomdmbbackend.utils.CurrentUserContext; import top.xyquan.ecomdmbbackend.utils.SysFileUtils; +import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -172,11 +175,11 @@ public class ProductServiceImpl extends ServiceImpl im * 更新商品 * @param updateProductDTO 更新商品DTO * @param id 商品ID - * @return 商品VO + * @return 更新结果(含成本变更的规格ID列表) */ @Override @Transactional - public ProductVO updateProduct(UpdateProductDTO updateProductDTO, Long id) { + public UpdateProductResultDTO updateProduct(UpdateProductDTO updateProductDTO, Long id) { // 从token中获取公司ID Long companyId = currentUserContext.getCurrentCompanyId(); @@ -223,6 +226,7 @@ public class ProductServiceImpl extends ServiceImpl im this.updateById(product); // 如果提供了规格列表,则更新对应的规格 + List costChangedSpecIds = new ArrayList<>(); if (updateProductDTO.getSpecs() != null && !updateProductDTO.getSpecs().isEmpty()) { List specDTOs = updateProductDTO.getSpecs(); for (UpdateProductDTO.ProductSpecUpdateDTO specDTO : specDTOs) { @@ -256,23 +260,25 @@ public class ProductServiceImpl extends ServiceImpl im } } - // 更新规格 - ProductSpecPO productSpec = new ProductSpecPO(); - productSpec.setId(specDTO.getId()); - productSpec.setName(specDTO.getName()); - productSpec.setSpecCode(specDTO.getSpecCode()); - productSpec.setProductCost(specDTO.getProductCost()); - productSpec.setShippingCost(specDTO.getShippingCost()); - productSpec.setOtherCost(specDTO.getOtherCost()); - productSpec.setRemark(specDTO.getRemark()); - productSpec.setUpdateBy(currentUserContext.getCurrentUserId()); - - productSpecService.updateById(productSpec); + // 更新规格(走标准更新流程,内部会检测成本是否变化) + UpdateProductSpecDTO updateSpecDto = new UpdateProductSpecDTO(); + updateSpecDto.setName(specDTO.getName()); + updateSpecDto.setSpecCode(specDTO.getSpecCode()); + updateSpecDto.setProductCost(specDTO.getProductCost()); + updateSpecDto.setShippingCost(specDTO.getShippingCost()); + updateSpecDto.setOtherCost(specDTO.getOtherCost()); + updateSpecDto.setRemark(specDTO.getRemark()); + ProductSpecVO specVO = productSpecService.updateProductSpec(updateSpecDto, specDTO.getId()); + if (Boolean.TRUE.equals(specVO.getCostChanged())) { + costChangedSpecIds.add(specDTO.getId()); + } } } - // 转换为VO并返回 - return convertToVO(product); + // 返回结果 + UpdateProductResultDTO result = new UpdateProductResultDTO(); + result.setCostChangedSpecIds(costChangedSpecIds); + return result; } /** diff --git a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/service/impl/ProductSpecServiceImpl.java b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/service/impl/ProductSpecServiceImpl.java index 96a9daac..52960451 100644 --- a/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/service/impl/ProductSpecServiceImpl.java +++ b/ecom-dmb-backend/src/main/java/top/xyquan/ecomdmbbackend/modules/ecom/product/service/impl/ProductSpecServiceImpl.java @@ -108,6 +108,21 @@ public class ProductSpecServiceImpl extends ServiceImpl isCostReallyChanged = (dbVal, dtoVal) -> { + boolean dbIsEmpty = dbVal == null || dbVal.compareTo(java.math.BigDecimal.ZERO) == 0; + boolean dtoIsEmpty = dtoVal == null || dtoVal.compareTo(java.math.BigDecimal.ZERO) == 0; + if (dbIsEmpty && dtoIsEmpty) return false; // 都是空,无变化 + if (dbIsEmpty || dtoIsEmpty) return true; // 一个是空一个有值,有变化 + return dbVal.compareTo(dtoVal) != 0; // 都有非零值,精确比较 + }; + boolean costChanged = isCostReallyChanged.apply(existingProductSpec.getProductCost(), updateProductSpecDTO.getProductCost()) + || isCostReallyChanged.apply(existingProductSpec.getShippingCost(), updateProductSpecDTO.getShippingCost()) + || isCostReallyChanged.apply(existingProductSpec.getOtherCost(), updateProductSpecDTO.getOtherCost()); + // 更新商品规格 ProductSpecPO productSpec = new ProductSpecPO(); BeanUtils.copyProperties(updateProductSpecDTO, productSpec); @@ -122,7 +137,9 @@ public class ProductSpecServiceImpl extends ServiceImpl(`/ec/product/update/${id}`, data); + return requestClient.put(`/ec/product/update/${id}`, data); } /** diff --git a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/product/types/types.vo.ts b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/product/types/types.vo.ts index ced81a16..3b5f7151 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/product/types/types.vo.ts +++ b/ecom-dmb-frontend/apps/web-antd/src/api/ecommerce/product/types/types.vo.ts @@ -27,6 +27,12 @@ export namespace ProductVO { specs?: SpecInfo[]; } + /** 更新商品响应 */ + export interface UpdateProductResult { + /** 本次更新中成本发生变更的规格ID列表 */ + costChangedSpecIds: number[]; + } + /** 商品规格信息 */ export interface SpecInfo { /** 规格ID */