当前位置:网站首页>Errors made in the development of merging the quantity of data in the set according to attributes
Errors made in the development of merging the quantity of data in the set according to attributes
2022-07-07 01:51:00 【Ant HJK】
1. Let's talk about the scene first
When the applet orders, it verifies the inventory of goods , Because the collection of products transmitted from the front end is not the same sku Add the quantity of goods , So when I do inventory verification, I filter out the required product set and consolidate the data , As a result, there is one more message when saving the product information Consolidate commodity quantity data
It was written like this before
// Filter out qualified product data List<OrderGoods> goods = goodsList.stream().filter(s -> !GoodsTypeEnum.GOODS_TYPE_02.getCode().equals(s.getGoodsType()) && !GoodsTypeEnum.GOODS_TYPE_04.getCode().equals(s.getGoodsType())).collect(Collectors.toList());
// Consolidation of set data
List<OrderGoods> orderGood = new ArrayList<>(goods .stream().collect(Collectors.toMap(OrderGoods::getSku, a -> a, (o1, o2) -> {
o1.setQuantity(String.valueOf(Math.abs(Integer.parseInt(o1.getQuantity())) + Math.abs(Integer.parseInt(o2.getQuantity()))));
return o1;
})).values());
It is found that this merging will affect the original data objects
So recreate a collection
// Consolidated product quantity
List<OrderGoods> orderGoodsList = new ArrayList<>();
for (OrderGoods good : goods) {
OrderGoods orderGood = new OrderGoods();
orderGood.setSku(good.getSku());
orderGood.setQuantity(good.getQuantity());
orderGoodsList.add(orderGood);
}
// Consolidation of set data
List<OrderGoods> orderGood = new ArrayList<>(orderGoodsList.stream().collect(Collectors.toMap(OrderGoods::getSku, a -> a, (o1, o2) -> {
o1.setQuantity(String.valueOf(Math.abs(Integer.parseInt(o1.getQuantity())) + Math.abs(Integer.parseInt(o2.getQuantity()))));
return o1;
})).values());In this way, the original object will not be operated , So the problem was solved
边栏推荐
- Clickhouse fields are grouped and aggregated, and SQL is queried according to the granularity of any time period
- 编译命令行终端 swift
- Public key \ private SSH avoid password login
- Blue Bridge Cup 2022 13th provincial competition real topic - block painting
- WCF Foundation
- AcWing 1141. LAN problem solving (kruskalkruskal finding the minimum spanning tree)
- Drag to change order
- Basic introduction and use of dvajs
- AcWing 361. 观光奶牛 题解(spfa求正环)
- Google released a security update to fix 0 days that have been used in chrome
猜你喜欢
![Yiwen takes you into [memory leak]](/img/a8/bd1a57ef3bde8910eff2a5f68296df.png)
Yiwen takes you into [memory leak]

ROS学习(二十)机器人SLAM功能包——rgbdslam的安装与测试

ROS学习(26)动态参数配置

The cradle of eternity

Appium自动化测试基础 — uiautomatorviewer定位工具

JVM 内存模型

Yunna - work order management system and process, work order management specification

454-百度面经1

ROS學習(23)action通信機制

Reptile practice (VI): novel of climbing pen interesting Pavilion
随机推荐
hdu 4661 Message Passing(木DP&amp;组合数学)
Share a general compilation method of so dynamic library
454-百度面经1
swiper组件中使用video导致全屏错位
Transplant DAC chip mcp4725 to nuc980
C语言【23道】经典面试题【下】
Scenario practice: quickly build wordpress blog system based on function calculation
编译命令行终端 swift
Machine learning: the difference between random gradient descent (SGD) and gradient descent (GD) and code implementation.
AcWing 344. 观光之旅题解(floyd求无向图的最小环问题)
糊涂工具类(hutool)post请求设置body参数为json数据
The difference between Tansig and logsig. Why does BP like to use Tansig
Make DIY welding smoke extractor with lighting
盒子拉伸拉扯(左右模式)
JS how to quickly create an array with length n
刨析《C语言》【进阶】付费知识【完结】
ROS学习(21)机器人SLAM功能包——orbslam的安装与测试
AcWing 361. 观光奶牛 题解(spfa求正环)
AcWing 1141. LAN problem solving (kruskalkruskal finding the minimum spanning tree)
Right mouse button customization