当前位置:网站首页>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
边栏推荐
- 长按按钮执行函数
- Right mouse button customization
- AcWing 1140. Shortest network (minimum spanning tree)
- When grep looks for a process, it ignores the grep process itself
- AcWing 904. 虫洞 题解(spfa求负环)
- 蓝桥杯2022年第十三届省赛真题-积木画
- Telnet,SSH1,SSH2,Telnet/SSL,Rlogin,Serial,TAPI,RAW
- Google released a security update to fix 0 days that have been used in chrome
- The difference between Tansig and logsig. Why does BP like to use Tansig
- JS reverse -- ob confusion and accelerated music that poked the [hornet's nest]
猜你喜欢

sql中批量删除数据---实体中的集合

dvajs的基础介绍及使用

Instructions for using the domain analysis tool bloodhound

How can I code for 8 hours without getting tired.

shell脚本快速统计项目代码行数

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

刨析《C语言》【进阶】付费知识【二】

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

AcWing 361. 观光奶牛 题解(spfa求正环)

Appium foundation - appium inspector positioning tool (I)
随机推荐
永久的摇篮
Machine learning: the difference between random gradient descent (SGD) and gradient descent (GD) and code implementation.
POJ 3177 redundant paths POJ 3352 road construction (dual connection)
grep查找进程时,忽略grep进程本身
AcWing 346. 走廊泼水节 题解(推公式、最小生成树)
Public key \ private SSH avoid password login
今日问题-2022/7/4 lambda体中修改String引用类型变量
Can't you understand the code of linked list in C language? An article allows you to grasp the secondary pointer and deeply understand the various forms of parameter passing in the function parameter
ZOJ Problem Set – 2563 Long Dominoes 【如压力dp】
PartyDAO如何在1年内把一篇推文变成了2亿美金的产品DAO
Google released a security update to fix 0 days that have been used in chrome
JS es5 peut également créer des constantes?
设置Wordpress伪静态连接(无宝塔)
JVM 内存模型
ZOJ problem set – 2563 long dominoes [e.g. pressure DP]
AcWing 1148. 秘密的牛奶运输 题解(最小生成树)
sql中批量删除数据---实体中的集合
字符串的相关编程题
2022/0524/bookstrap
shell脚本快速统计项目代码行数