mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 18:29:20 +08:00
feat: 更新商品接口返回成本变更的规格ID列表
- UpdateProductResultDTO 新增 data.costChangedSpecIds 字段 - ProductService.updateProduct 返回类型改为 UpdateProductResultDTO - ProductSpecServiceImpl 检测成本变更逻辑:null/0 互为等价,只有非零实际值变化才算变更 - ProductSpecVO 新增 costChanged 字段 - 前端类型 ProductVO.UpdateProductResult 同步更新
This commit is contained in:
+7
-5
@@ -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.CreateProductDTO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.ProductFilterDTO;
|
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.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.model.vo.ProductVO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductService;
|
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductService;
|
||||||
|
|
||||||
@@ -34,16 +36,16 @@ public class ProductController {
|
|||||||
@RequirePermission(value = "ecom:product:create", description = "创建商品", allowSuper = true)
|
@RequirePermission(value = "ecom:product:create", description = "创建商品", allowSuper = true)
|
||||||
public ApiResponse<ProductVO> createProduct(@Valid @RequestBody CreateProductDTO createProductDTO) {
|
public ApiResponse<ProductVO> createProduct(@Valid @RequestBody CreateProductDTO createProductDTO) {
|
||||||
ProductVO productVO = productService.createProduct(createProductDTO);
|
ProductVO productVO = productService.createProduct(createProductDTO);
|
||||||
return ApiResponse.success(productVO);
|
return ApiResponse.success("商品创建成功", productVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "更新商品", description = "更新现有商品信息")
|
@Operation(summary = "更新商品", description = "更新现有商品信息")
|
||||||
@PutMapping("/update/{id}")
|
@PutMapping("/update/{id}")
|
||||||
@RequirePermission(value = "ecom:product:update", description = "更新商品", allowSuper = true)
|
@RequirePermission(value = "ecom:product:update", description = "更新商品", allowSuper = true)
|
||||||
public ApiResponse<ProductVO> updateProduct(@Valid @RequestBody UpdateProductDTO updateProductDTO,
|
public ApiResponse<UpdateProductResultDTO> updateProduct(@Valid @RequestBody UpdateProductDTO updateProductDTO,
|
||||||
@Parameter(description = "商品ID") @PathVariable Long id) {
|
@Parameter(description = "商品ID") @PathVariable Long id) {
|
||||||
ProductVO productVO = productService.updateProduct(updateProductDTO, id);
|
UpdateProductResultDTO result = productService.updateProduct(updateProductDTO, id);
|
||||||
return ApiResponse.success(productVO);
|
return ApiResponse.success("商品更新成功", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "删除商品", description = "删除指定商品")
|
@Operation(summary = "删除商品", description = "删除指定商品")
|
||||||
@@ -52,7 +54,7 @@ public class ProductController {
|
|||||||
public ApiResponse<Void> deleteProduct(
|
public ApiResponse<Void> deleteProduct(
|
||||||
@Parameter(description = "商品ID") @PathVariable Long id) {
|
@Parameter(description = "商品ID") @PathVariable Long id) {
|
||||||
productService.deleteProduct(id);
|
productService.deleteProduct(id);
|
||||||
return ApiResponse.success();
|
return ApiResponse.success("商品删除成功", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "分页获取商品列表", description = "分页获取商品列表,支持条件过滤")
|
@Operation(summary = "分页获取商品列表", description = "分页获取商品列表,支持条件过滤")
|
||||||
|
|||||||
+3
-3
@@ -38,7 +38,7 @@ public class ProductSpecController {
|
|||||||
@RequirePermission(value = "ecom:product:create", description = "创建商品规格", allowSuper = true)
|
@RequirePermission(value = "ecom:product:create", description = "创建商品规格", allowSuper = true)
|
||||||
public ApiResponse<ProductSpecVO> createProductSpec(@Valid @RequestBody CreateProductSpecDTO createProductSpecDTO) {
|
public ApiResponse<ProductSpecVO> createProductSpec(@Valid @RequestBody CreateProductSpecDTO createProductSpecDTO) {
|
||||||
ProductSpecVO productSpecVO = productSpecService.createProductSpec(createProductSpecDTO);
|
ProductSpecVO productSpecVO = productSpecService.createProductSpec(createProductSpecDTO);
|
||||||
return ApiResponse.success(productSpecVO);
|
return ApiResponse.success("规格创建成功", productSpecVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "更新商品规格", description = "更新现有商品规格信息")
|
@Operation(summary = "更新商品规格", description = "更新现有商品规格信息")
|
||||||
@@ -47,7 +47,7 @@ public class ProductSpecController {
|
|||||||
public ApiResponse<ProductSpecVO> updateProductSpec(@Valid @RequestBody UpdateProductSpecDTO updateProductSpecDTO,
|
public ApiResponse<ProductSpecVO> updateProductSpec(@Valid @RequestBody UpdateProductSpecDTO updateProductSpecDTO,
|
||||||
@Parameter(description = "商品规格ID") @PathVariable Long id) {
|
@Parameter(description = "商品规格ID") @PathVariable Long id) {
|
||||||
ProductSpecVO productSpecVO = productSpecService.updateProductSpec(updateProductSpecDTO, id);
|
ProductSpecVO productSpecVO = productSpecService.updateProductSpec(updateProductSpecDTO, id);
|
||||||
return ApiResponse.success(productSpecVO);
|
return ApiResponse.success("规格更新成功", productSpecVO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "删除商品规格", description = "删除指定商品规格")
|
@Operation(summary = "删除商品规格", description = "删除指定商品规格")
|
||||||
@@ -56,7 +56,7 @@ public class ProductSpecController {
|
|||||||
public ApiResponse<Void> deleteProductSpec(
|
public ApiResponse<Void> deleteProductSpec(
|
||||||
@Parameter(description = "商品规格ID") @PathVariable Long id) {
|
@Parameter(description = "商品规格ID") @PathVariable Long id) {
|
||||||
productSpecService.deleteProductSpec(id);
|
productSpecService.deleteProductSpec(id);
|
||||||
return ApiResponse.success();
|
return ApiResponse.success("规格删除成功", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Operation(summary = "分页获取商品规格列表", description = "分页获取商品规格列表,支持条件过滤")
|
@Operation(summary = "分页获取商品规格列表", description = "分页获取商品规格列表,支持条件过滤")
|
||||||
|
|||||||
+20
@@ -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<Long> costChangedSpecIds;
|
||||||
|
}
|
||||||
+6
@@ -96,4 +96,10 @@ public class ProductSpecVO {
|
|||||||
*/
|
*/
|
||||||
@Schema(description = "更新人ID", example = "1")
|
@Schema(description = "更新人ID", example = "1")
|
||||||
private Long updateBy;
|
private Long updateBy;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成本是否变更(本次更新中成本字段有变化)
|
||||||
|
*/
|
||||||
|
@Schema(description = "成本是否变更", example = "true")
|
||||||
|
private Boolean costChanged;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -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.CreateProductDTO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.ProductFilterDTO;
|
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.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.po.ProductPO;
|
||||||
|
|
||||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductVO;
|
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductVO;
|
||||||
@@ -28,9 +29,9 @@ public interface ProductService extends IService<ProductPO> {
|
|||||||
*
|
*
|
||||||
* @param updateProductDTO 更新商品DTO
|
* @param updateProductDTO 更新商品DTO
|
||||||
* @param id 商品ID
|
* @param id 商品ID
|
||||||
* @return 商品VO
|
* @return 更新结果(含成本变更的规格ID列表)
|
||||||
*/
|
*/
|
||||||
ProductVO updateProduct(UpdateProductDTO updateProductDTO, Long id);
|
UpdateProductResultDTO updateProduct(UpdateProductDTO updateProductDTO, Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除商品
|
* 删除商品
|
||||||
|
|||||||
+22
-16
@@ -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.CreateProductDTO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.dto.ProductFilterDTO;
|
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.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.ProductPO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSpecPO;
|
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.po.ProductSpecPO;
|
||||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductVO;
|
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.CurrentUserContext;
|
||||||
import top.xyquan.ecomdmbbackend.utils.SysFileUtils;
|
import top.xyquan.ecomdmbbackend.utils.SysFileUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -172,11 +175,11 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
|
|||||||
* 更新商品
|
* 更新商品
|
||||||
* @param updateProductDTO 更新商品DTO
|
* @param updateProductDTO 更新商品DTO
|
||||||
* @param id 商品ID
|
* @param id 商品ID
|
||||||
* @return 商品VO
|
* @return 更新结果(含成本变更的规格ID列表)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public ProductVO updateProduct(UpdateProductDTO updateProductDTO, Long id) {
|
public UpdateProductResultDTO updateProduct(UpdateProductDTO updateProductDTO, Long id) {
|
||||||
// 从token中获取公司ID
|
// 从token中获取公司ID
|
||||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
|
|
||||||
@@ -223,6 +226,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
|
|||||||
this.updateById(product);
|
this.updateById(product);
|
||||||
|
|
||||||
// 如果提供了规格列表,则更新对应的规格
|
// 如果提供了规格列表,则更新对应的规格
|
||||||
|
List<Long> costChangedSpecIds = new ArrayList<>();
|
||||||
if (updateProductDTO.getSpecs() != null && !updateProductDTO.getSpecs().isEmpty()) {
|
if (updateProductDTO.getSpecs() != null && !updateProductDTO.getSpecs().isEmpty()) {
|
||||||
List<UpdateProductDTO.ProductSpecUpdateDTO> specDTOs = updateProductDTO.getSpecs();
|
List<UpdateProductDTO.ProductSpecUpdateDTO> specDTOs = updateProductDTO.getSpecs();
|
||||||
for (UpdateProductDTO.ProductSpecUpdateDTO specDTO : specDTOs) {
|
for (UpdateProductDTO.ProductSpecUpdateDTO specDTO : specDTOs) {
|
||||||
@@ -256,23 +260,25 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新规格
|
// 更新规格(走标准更新流程,内部会检测成本是否变化)
|
||||||
ProductSpecPO productSpec = new ProductSpecPO();
|
UpdateProductSpecDTO updateSpecDto = new UpdateProductSpecDTO();
|
||||||
productSpec.setId(specDTO.getId());
|
updateSpecDto.setName(specDTO.getName());
|
||||||
productSpec.setName(specDTO.getName());
|
updateSpecDto.setSpecCode(specDTO.getSpecCode());
|
||||||
productSpec.setSpecCode(specDTO.getSpecCode());
|
updateSpecDto.setProductCost(specDTO.getProductCost());
|
||||||
productSpec.setProductCost(specDTO.getProductCost());
|
updateSpecDto.setShippingCost(specDTO.getShippingCost());
|
||||||
productSpec.setShippingCost(specDTO.getShippingCost());
|
updateSpecDto.setOtherCost(specDTO.getOtherCost());
|
||||||
productSpec.setOtherCost(specDTO.getOtherCost());
|
updateSpecDto.setRemark(specDTO.getRemark());
|
||||||
productSpec.setRemark(specDTO.getRemark());
|
ProductSpecVO specVO = productSpecService.updateProductSpec(updateSpecDto, specDTO.getId());
|
||||||
productSpec.setUpdateBy(currentUserContext.getCurrentUserId());
|
if (Boolean.TRUE.equals(specVO.getCostChanged())) {
|
||||||
|
costChangedSpecIds.add(specDTO.getId());
|
||||||
productSpecService.updateById(productSpec);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 转换为VO并返回
|
// 返回结果
|
||||||
return convertToVO(product);
|
UpdateProductResultDTO result = new UpdateProductResultDTO();
|
||||||
|
result.setCostChangedSpecIds(costChangedSpecIds);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+18
-1
@@ -108,6 +108,21 @@ public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, Produ
|
|||||||
throw new BusinessException("规格名称已存在");
|
throw new BusinessException("规格名称已存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检测成本字段是否有变化(只有成本字段参与判断,名称和备注不参与)
|
||||||
|
// 辅助方法:检测成本是否有实际变化
|
||||||
|
// 规则:null 和 0 都视为"未填成本",互为等价;只有非零值才算有效成本
|
||||||
|
// 使用 compareTo 替代 equals 避免 BigDecimal scale 不同导致误判(如 100 vs 100.00)
|
||||||
|
java.util.function.BiFunction<java.math.BigDecimal, java.math.BigDecimal, Boolean> 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();
|
ProductSpecPO productSpec = new ProductSpecPO();
|
||||||
BeanUtils.copyProperties(updateProductSpecDTO, productSpec);
|
BeanUtils.copyProperties(updateProductSpecDTO, productSpec);
|
||||||
@@ -122,7 +137,9 @@ public class ProductSpecServiceImpl extends ServiceImpl<ProductSpecMapper, Produ
|
|||||||
this.updateById(productSpec);
|
this.updateById(productSpec);
|
||||||
|
|
||||||
// 转换为VO并返回
|
// 转换为VO并返回
|
||||||
return convertToVO(productSpec);
|
ProductSpecVO vo = convertToVO(productSpec);
|
||||||
|
vo.setCostChanged(costChanged);
|
||||||
|
return vo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export async function createProductApi(data: ProductDTO.Create) {
|
|||||||
* 更新商品
|
* 更新商品
|
||||||
*/
|
*/
|
||||||
export async function updateProductApi(id: number, data: ProductDTO.Update) {
|
export async function updateProductApi(id: number, data: ProductDTO.Update) {
|
||||||
return requestClient.put<ProductVO.Info>(`/ec/product/update/${id}`, data);
|
return requestClient.put<ProductVO.UpdateProductResult>(`/ec/product/update/${id}`, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -27,6 +27,12 @@ export namespace ProductVO {
|
|||||||
specs?: SpecInfo[];
|
specs?: SpecInfo[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 更新商品响应 */
|
||||||
|
export interface UpdateProductResult {
|
||||||
|
/** 本次更新中成本发生变更的规格ID列表 */
|
||||||
|
costChangedSpecIds: number[];
|
||||||
|
}
|
||||||
|
|
||||||
/** 商品规格信息 */
|
/** 商品规格信息 */
|
||||||
export interface SpecInfo {
|
export interface SpecInfo {
|
||||||
/** 规格ID */
|
/** 规格ID */
|
||||||
|
|||||||
Reference in New Issue
Block a user