当前位置:网站首页>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
边栏推荐
- AcWing 361. Sightseeing cow problem solution (SPFA seeking positive ring)
- DS-5/RVDS4.0变量初始化错误
- 拖拽改变顺序
- First experience of JSON learning - the third-party jar package realizes bean, list and map to create JSON format
- AcWing 345. Cattle station solution (nature and multiplication of Floyd)
- uva 1401 dp+Trie
- shell脚本快速统计项目代码行数
- Appium基础 — Appium Inspector定位工具(一)
- Use nodejs to determine which projects are packaged + released
- Get to know MySQL for the first time
猜你喜欢

dvajs的基础介绍及使用

ROS学习(十九)机器人SLAM功能包——cartographer

AcWing 345. Cattle station solution (nature and multiplication of Floyd)

C语言关于链表的代码看不懂?一篇文章让你拿捏二级指针并深入理解函数参数列表中传参的多种形式

蓝桥杯2022年第十三届省赛真题-积木画

Mongodb checks whether the table is imported successfully

js如何快速创建一个长度为 n 的数组

ROS learning (22) TF transformation

【唯一】的“万字配图“ | 讲透【链式存储结构】是什么?

LeetCode:1175. Prime permutation
随机推荐
mongodb查看表是否导入成功
How can I code for 8 hours without getting tired.
Golang foundation - data type
ZOJ problem set – 2563 long dominoes [e.g. pressure DP]
刨析《C语言》【进阶】付费知识【完结】
JS ES5也可以创建常量?
AcWing 1140. 最短网络 (最小生成树)
Use nodejs to determine which projects are packaged + released
Share a general compilation method of so dynamic library
Start from the bottom structure to learn the customization and testing of fpga---- FIFO IP
AcWing 344. 观光之旅题解(floyd求无向图的最小环问题)
AcWing 1142. 繁忙的都市 题解(最小生成树)
Right mouse button customization
场景实践:基于函数计算快速搭建Wordpress博客系统
ROS學習(23)action通信機制
ROS学习(二十)机器人SLAM功能包——rgbdslam的安装与测试
Mongodb checks whether the table is imported successfully
ZOJ Problem Set – 2563 Long Dominoes 【如压力dp】
AcWing 345. Cattle station solution (nature and multiplication of Floyd)
NPM install compilation times "cannot read properties of null (reading 'pickalgorithm')“