fix(shopping): 修复购物车选配件价格及金额计算问题

- 注释掉 ModelConfigSearchRequest 中 planId 的 @JsonIgnore 注解取消忽略
- 注释掉 PlanController 中根据 planId 设置请求参数的代码
- PriceConfigController 中标记价格配置是否可用字段 enable
- 将 QuotationPriceUpdateItemRequest 中 parts 重命名为 optionalParts
- 调整 QuotationUserPlanModelItemMapper 查询,优化关联表及条件
- 修复购物车金额计算,增加对children非空判断避免空指针
- 修改购物车选配件处理逻辑,支持 optionalParts 及相关购物车项更新
- 确保批量更新购物车选配和购物车本身数据
This commit is contained in:
曹鹏飞 2026-05-25 17:27:15 +08:00
parent a80015986f
commit 492f57ebbe
6 changed files with 53 additions and 35 deletions

View File

@ -28,6 +28,6 @@ public class ModelConfigSearchRequest extends PageRequest {
*/
private Long typeNumber;
@JsonIgnore
private Long planId;
// @JsonIgnore
// private Long planId;
}

View File

@ -130,6 +130,8 @@ public class PriceConfigController extends ControllerBase {
md.put("children", new ArrayList<>());
vo.getChildren().forEach(item -> convert(md, item));
}
//是否可以配置价格
md.put("enable", CollectionUtil.isEmpty(vo.getChildren()));
}
/**

View File

@ -154,9 +154,9 @@ public class PlanController extends ControllerBase {
.eq(QuotationUserPlanModel::getCreateById, AppUserUtil.getUserId())
.one();
vo.setInfo(Convert.convert(QuotationModelRatioVO.class, plan));
if (Objects.nonNull(plan)) {
request.setPlanId(plan.getId());
}
// if (Objects.nonNull(plan)) {
// request.setPlanId(plan.getId());
// }
List<PlanSearchItemVO> items = planModelItemService.search(request, AppUserUtil.isAgent() ? 1 : 0, AppUserUtil.getUserId());
int index = 0, startIndex = (request.getPage() - 1) * request.getPageSize(), endIndex = request.getPage() * request.getPageSize();
PageData<PlanSearchItemVO> pageData = new PageData<>();

View File

@ -514,15 +514,15 @@ public class ShoppingController extends ControllerBase {
List<ModelConfigEffectiveDTO> children = parts.stream()
.filter(pi -> pi.getParentId().equals(part.getId()))
.collect(Collectors.toList());
vi.setAmount(
vi.getAmount().add(
children.stream()
.map(ModelConfigEffectiveDTO::getAmount)
.filter(Objects::nonNull)
.reduce(BigDecimal::add)
.orElse(BigDecimal.ZERO)
)
);
if (CollectionUtil.isNotEmpty(children)) {
vi.setAmount(
children.stream()
.map(ModelConfigEffectiveDTO::getAmount)
.filter(Objects::nonNull)
.reduce(BigDecimal::add)
.orElse(BigDecimal.ZERO)
);
}
vi.setChildren(
children.stream()
.map(pi -> {
@ -816,15 +816,15 @@ public class ShoppingController extends ControllerBase {
List<ModelConfigEffectiveDTO> children = parts.stream()
.filter(pi -> pi.getParentId().equals(part.getId()))
.collect(Collectors.toList());
vi.setAmount(
vi.getAmount().add(
children.stream()
.filter(pi -> pi.getType() == 0)
.map(ModelConfigEffectiveDTO::getAmount)
.reduce(BigDecimal::add)
.orElse(BigDecimal.ZERO)
)
);
if (CollectionUtil.isNotEmpty(children)) {
vi.setAmount(
children.stream()
.filter(pi -> pi.getType() == 0)
.map(ModelConfigEffectiveDTO::getAmount)
.reduce(BigDecimal::add)
.orElse(BigDecimal.ZERO)
);
}
vi.setChildren(
children.stream()
.map(pi -> convert(pi, BigDecimal.ONE))
@ -1072,15 +1072,29 @@ public class ShoppingController extends ControllerBase {
.setOldFee(item.getOldStandardFee())
.setNewFee(item.getNewStandardFee())
);
if (CollectionUtil.isNotEmpty(item.getParts())) {
if (CollectionUtil.isNotEmpty(item.getOptionalParts())) {
cart.setOptionalFee(cart.getOptionalFee()
.add(item.getParts()
.add(item.getOptionalParts()
.stream()
.map(QuotationPriceUpdateItemPartRequest::getSpread)
.reduce(BigDecimal.ZERO, BigDecimal::add)
)
);
item.getParts().forEach(part -> {
List<QuotationShoppingCartItem> optionalParts = shoppingCartItemService.lambdaQuery()
.eq(QuotationShoppingCartItem::getCartId, item.getCartId())
.in(QuotationShoppingCartItem::getConfigItemId, item.getOptionalParts()
.stream()
.map(QuotationPriceUpdateItemPartRequest::getConfigItemId)
.collect(Collectors.toList())
)
.list();
item.getOptionalParts().forEach(part -> {
QuotationShoppingCartItem optionalPart = optionalParts.stream()
.filter(p -> Objects.equals(p.getConfigItemId(), part.getConfigItemId()))
.findFirst()
.get();
optionalPart.setAmount(part.getNewStandardFee());
optionalPart.setDiscount(part.getSpread());
adjustItems.add(
new QuotationShoppingOrderAdjustItem()
.setAdjustId(adjust.getId())
@ -1091,10 +1105,16 @@ public class ShoppingController extends ControllerBase {
.setNewFee(part.getNewStandardFee())
);
});
if (CollectionUtil.isNotEmpty(optionalParts)) {
shoppingCartItemService.updateBatchById(optionalParts);
}
}
});
shoppingOrderAdjustItemService.saveBatch(adjustItems);
shoppingOrderAdjustService.save(adjust);
if (CollectionUtil.isNotEmpty(carts)) {
shoppingCartService.updateBatchById(carts);
}
}
shoppingOrderService.lambdaUpdate()
.set(Objects.nonNull(request.getActualFee()), QuotationShoppingOrder::getActualFee, request.getActualFee())

View File

@ -32,5 +32,5 @@ public class QuotationPriceUpdateItemRequest {
* 选配调价
*/
@Valid
List<QuotationPriceUpdateItemPartRequest> parts;
List<QuotationPriceUpdateItemPartRequest> optionalParts;
}

View File

@ -10,16 +10,12 @@
</select>
<select id="search" resultType="com.nflg.mobilebroken.common.pojo.vo.PlanSearchItemVO">
SELECT qupmi.id,qupmi.plan_id,pm.batch_number as 'modelId',pm.`no` as
'modelNo',qupmi.`name`,qupmi.ratio,qupmi.is_default,qupmi.area_id
SELECT vqupm.id,vqupm.plan_id,pm.batch_number as 'modelId',pm.`no` as 'modelNo',vqupm.`name`,vqupm.ratio
,vqupm.is_default,vqupm.area_id
FROM v_quotation_model_price vqmp
inner join product_model pm on vqmp.model_id=pm.batch_number
LEFT JOIN quotation_user_plan_model_item qupmi ON qupmi.model_id=pm.batch_number
left join quotation_user_plan_model qupm on qupmi.plan_id=qupm.id and qupm.create_by_type=#{userType} and qupm.create_by_id=#{userId}
WHERE pm.state=1 and qupm.`status`=1
<if test="request.planId!=null">
and qupmi.plan_id=#{request.planId}
</if>
LEFT JOIN v_quotation_user_plan_model vqupm ON vqupm.model_id=pm.batch_number and vqupm.create_by_type=1 and vqupm.create_by_id=14
WHERE pm.state=1
<if test="request.no!=null and request.no!=''">
and pm.no like CONCAT('%', #{request.no}, '%')
</if>