refactor(shopping): 优化购物车部件数据结构和分组逻辑
- 修改获取用户方案参数空格格式,提升代码一致性 - 优化购物车部件映射逻辑,减少重复流操作 - 按父部件ID筛选子部件,提高过滤效率 - 为购物车部件设置子项列表,并按组名分组 - 对组内部件按类型降序排序,组按组名排序 - 提升购物车视图模型数据结构清晰度和可维护性
This commit is contained in:
parent
fd8b061bf0
commit
fa133ab4ce
|
|
@ -225,7 +225,7 @@ public class ShoppingController extends ControllerBase {
|
|||
if (!request.getShowLowestPrice()) {
|
||||
//方案
|
||||
QuotationUserPlanModelItem planModelItem = userPlanModelItemService.getEffectiveForUser(request.getModelId()
|
||||
, AppUserUtil.isAgent() ? 1 : 0, AppUserUtil.getUserId(),categoryId);
|
||||
, AppUserUtil.isAgent() ? 1 : 0, AppUserUtil.getUserId(), categoryId);
|
||||
if (Objects.nonNull(planModelItem)) {
|
||||
log.debug("机型【{}】方案为{},系数:{}", request.getModelNo(), planModelItem.getName(), planModelItem.getRatio());
|
||||
standardRatio = NumberUtil.multiply(standardRatio, planModelItem.getRatio());
|
||||
|
|
@ -776,15 +776,35 @@ public class ShoppingController extends ControllerBase {
|
|||
.filter(part -> part.getParentId() == 0L && part.getType() == 1)
|
||||
.map(part -> {
|
||||
ShoppingCartPartVO vi = Convert.convert(ShoppingCartPartVO.class, part);
|
||||
List<ModelConfigEffectiveDTO> children = parts.stream()
|
||||
.filter(pi -> pi.getParentId().equals(part.getId()))
|
||||
.collect(Collectors.toList());
|
||||
vi.setAmount(
|
||||
vi.getAmount().add(
|
||||
parts.stream()
|
||||
.filter(pi -> pi.getParentId().equals(part.getId()) && pi.getType() == 0)
|
||||
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))
|
||||
.collect(Collectors.groupingBy(ShoppingCartPartVO::getGroupName))
|
||||
.entrySet()
|
||||
.stream()
|
||||
.map(kv -> new ShoppingCartPartGroupVO()
|
||||
.setGroupName(kv.getKey())
|
||||
.setItems(kv.getValue()
|
||||
.stream()
|
||||
.sorted(Comparator.comparing(ShoppingCartPartVO::getType).reversed())
|
||||
.collect(Collectors.toList())
|
||||
)
|
||||
)
|
||||
.sorted(Comparator.comparing(ShoppingCartPartGroupVO::getGroupName))
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
return vi;
|
||||
}
|
||||
).collect(Collectors.toList())
|
||||
|
|
@ -793,15 +813,35 @@ public class ShoppingController extends ControllerBase {
|
|||
.filter(part -> part.getParentId() == 0L && part.getType() == 0)
|
||||
.map(part -> {
|
||||
ShoppingCartPartVO vi = Convert.convert(ShoppingCartPartVO.class, part);
|
||||
List<ModelConfigEffectiveDTO> children = parts.stream()
|
||||
.filter(pi -> pi.getParentId().equals(part.getId()))
|
||||
.collect(Collectors.toList());
|
||||
vi.setAmount(
|
||||
vi.getAmount().add(
|
||||
parts.stream()
|
||||
.filter(pi -> pi.getParentId().equals(part.getId()) && pi.getType() == 0)
|
||||
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))
|
||||
.collect(Collectors.groupingBy(ShoppingCartPartVO::getGroupName))
|
||||
.entrySet()
|
||||
.stream()
|
||||
.map(kv -> new ShoppingCartPartGroupVO()
|
||||
.setGroupName(kv.getKey())
|
||||
.setItems(kv.getValue()
|
||||
.stream()
|
||||
.sorted(Comparator.comparing(ShoppingCartPartVO::getType).reversed())
|
||||
.collect(Collectors.toList())
|
||||
)
|
||||
)
|
||||
.sorted(Comparator.comparing(ShoppingCartPartGroupVO::getGroupName))
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
return vi;
|
||||
}
|
||||
).collect(Collectors.toList())
|
||||
|
|
|
|||
Loading…
Reference in New Issue