mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:59:20 +08:00
feat: 成本同步提示仅返回有关联订单的规格;新增 specIdsHavingOrders 查询接口
- OrderService: 新增 specIdsHavingOrders(),返回指定规格中有关联订单的 ID 列表 - UpdateProductResultDTO: costChangedSpecIds → specIdsCostChangedWithLinkedOrders,仅返回「成本已变更且存在关联订单」的规格 - ProductServiceImpl: 更新商品时,只在成本变更且有关联订单时才填入 specIdsCostChangedWithLinkedOrders - ProductController: 更新接口描述补充说明字段含义 - 前端同步适配字段重命名
This commit is contained in:
+9
@@ -108,4 +108,13 @@ public interface OrderService extends IService<OrderPO> {
|
||||
*/
|
||||
long countOrdersForCostSync(Long companyId, java.util.List<Long> specIds,
|
||||
java.time.LocalDateTime startTime, java.time.LocalDateTime endTime);
|
||||
|
||||
/**
|
||||
* 在指定公司下,返回传入规格 ID 中存在至少一条订单的子集(无顺序保证,调用方可再与期望顺序求交)
|
||||
*
|
||||
* @param companyId 公司ID
|
||||
* @param specIds 待检测的规格ID列表
|
||||
* @return 存在关联订单的规格ID列表(去重)
|
||||
*/
|
||||
java.util.List<Long> specIdsHavingOrders(Long companyId, java.util.List<Long> specIds);
|
||||
}
|
||||
|
||||
+17
@@ -37,6 +37,7 @@ import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -501,4 +502,20 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
|
||||
return cnt == null ? 0L : cnt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> specIdsHavingOrders(Long companyId, List<Long> specIds) {
|
||||
if (specIds == null || specIds.isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
List<OrderPO> rows = list(new LambdaQueryWrapper<OrderPO>()
|
||||
.eq(OrderPO::getCompanyId, companyId)
|
||||
.in(OrderPO::getProductSpecId, specIds)
|
||||
.select(OrderPO::getProductSpecId));
|
||||
return rows.stream()
|
||||
.map(OrderPO::getProductSpecId)
|
||||
.filter(Objects::nonNull)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-2
@@ -13,7 +13,6 @@ 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;
|
||||
|
||||
@@ -39,7 +38,7 @@ public class ProductController {
|
||||
return ApiResponse.success("商品创建成功", productVO);
|
||||
}
|
||||
|
||||
@Operation(summary = "更新商品", description = "更新现有商品信息")
|
||||
@Operation(summary = "更新商品", description = "更新现有商品信息;响应中的 specIdsCostChangedWithLinkedOrders 为「成本已变更且存在关联订单」的规格ID,用于提示同步成本")
|
||||
@PutMapping("/update/{id}")
|
||||
@RequirePermission(value = "ecom:product:update", description = "更新商品", allowSuper = true)
|
||||
public ApiResponse<UpdateProductResultDTO> updateProduct(@Valid @RequestBody UpdateProductDTO updateProductDTO,
|
||||
|
||||
+3
-3
@@ -14,10 +14,10 @@ import java.util.List;
|
||||
public class UpdateProductResultDTO {
|
||||
|
||||
/**
|
||||
* 本次更新中成本发生变更的规格ID列表
|
||||
* 本次更新中成本发生变更、且当前公司在库中存在关联订单的规格ID列表(用于提示将成本同步到订单)
|
||||
*/
|
||||
@Schema(description = "成本发生变更的规格ID列表")
|
||||
private List<Long> costChangedSpecIds;
|
||||
@Schema(description = "成本已变更且存在关联订单的规格ID列表,用于同步成本提示")
|
||||
private List<Long> specIdsCostChangedWithLinkedOrders;
|
||||
|
||||
/**
|
||||
* 更新后的商品完整信息
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ public interface ProductService extends IService<ProductPO> {
|
||||
*
|
||||
* @param updateProductDTO 更新商品DTO
|
||||
* @param id 商品ID
|
||||
* @return 更新结果(含成本变更的规格ID列表)
|
||||
* @return 更新结果(含「成本已变更且存在关联订单」的规格ID列表,用于同步成本提示)
|
||||
*/
|
||||
UpdateProductResultDTO updateProduct(UpdateProductDTO updateProductDTO, Long id);
|
||||
|
||||
|
||||
+18
-7
@@ -22,6 +22,7 @@ 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;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.model.vo.ProductSpecVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.order.service.OrderService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.product.service.ProductSpecService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ecom.category.service.CategoryService;
|
||||
@@ -46,13 +47,16 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
|
||||
private final SysFileMapper sysFileMapper;
|
||||
private final ProductSpecService productSpecService;
|
||||
private final CategoryService categoryService;
|
||||
private final OrderService orderService;
|
||||
|
||||
public ProductServiceImpl(CurrentUserContext currentUserContext, SysFileMapper sysFileMapper,
|
||||
@Lazy ProductSpecService productSpecService, @Lazy CategoryService categoryService) {
|
||||
@Lazy ProductSpecService productSpecService, @Lazy CategoryService categoryService,
|
||||
@Lazy OrderService orderService) {
|
||||
this.currentUserContext = currentUserContext;
|
||||
this.sysFileMapper = sysFileMapper;
|
||||
this.productSpecService = productSpecService;
|
||||
this.categoryService = categoryService;
|
||||
this.orderService = orderService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -214,7 +218,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
|
||||
* 更新商品
|
||||
* @param updateProductDTO 更新商品DTO
|
||||
* @param id 商品ID
|
||||
* @return 更新结果(含成本变更的规格ID列表)
|
||||
* @return 更新结果(specIdsCostChangedWithLinkedOrders:成本已变更且本公司在库中存在关联订单的规格ID)
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
@@ -257,7 +261,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
|
||||
this.updateById(product);
|
||||
|
||||
// 先删除规格(须属于本商品),再更新已有规格,最后新增规格
|
||||
List<Long> costChangedSpecIds = new ArrayList<>();
|
||||
List<Long> rawCostChangedSpecIds = new ArrayList<>();
|
||||
if (updateProductDTO.getRemovedSpecIds() != null && !updateProductDTO.getRemovedSpecIds().isEmpty()) {
|
||||
for (Long specId : updateProductDTO.getRemovedSpecIds()) {
|
||||
if (specId == null) {
|
||||
@@ -326,7 +330,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
|
||||
updateSpecDto.setRemark(specDTO.getRemark());
|
||||
ProductSpecVO specVO = productSpecService.updateProductSpec(updateSpecDto, specDTO.getId());
|
||||
if (Boolean.TRUE.equals(specVO.getCostChanged())) {
|
||||
costChangedSpecIds.add(specDTO.getId());
|
||||
rawCostChangedSpecIds.add(specDTO.getId());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -358,14 +362,21 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, ProductPO> im
|
||||
}
|
||||
ProductSpecVO createdVo = productSpecService.createProductSpec(createDto);
|
||||
if (Boolean.TRUE.equals(createdVo.getCostChanged()) && createdVo.getId() != null) {
|
||||
costChangedSpecIds.add(createdVo.getId());
|
||||
rawCostChangedSpecIds.add(createdVo.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
// 返回结果:仅当成本变更且库中存在该规格的订单时,才提示同步(顺序与成本检测顺序一致)
|
||||
UpdateProductResultDTO result = new UpdateProductResultDTO();
|
||||
result.setCostChangedSpecIds(costChangedSpecIds);
|
||||
List<Long> specIdsForSyncPrompt = List.of();
|
||||
if (!rawCostChangedSpecIds.isEmpty()) {
|
||||
Set<Long> withOrders = new HashSet<>(orderService.specIdsHavingOrders(companyId, rawCostChangedSpecIds));
|
||||
specIdsForSyncPrompt = rawCostChangedSpecIds.stream()
|
||||
.filter(withOrders::contains)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
result.setSpecIdsCostChangedWithLinkedOrders(specIdsForSyncPrompt);
|
||||
|
||||
// 重新查询更新后的商品完整信息
|
||||
ProductPO updatedProduct = this.getById(id);
|
||||
|
||||
Reference in New Issue
Block a user