当前位置:网站首页>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
边栏推荐
- Comparison of picture beds of free white whoring
- 场景实践:基于函数计算快速搭建Wordpress博客系统
- AcWing 346. 走廊泼水节 题解(推公式、最小生成树)
- ZOJ Problem Set – 2563 Long Dominoes 【如压力dp】
- Instructions for using the domain analysis tool bloodhound
- MySQL's most basic select statement
- When grep looks for a process, it ignores the grep process itself
- sql中批量删除数据---实体中的集合
- 搭建【Redis in CentOS7.x】
- What does front-end processor mean? What is the main function? What is the difference with fortress machine?
猜你喜欢
随机推荐
mysqlbackup 还原特定的表
Reptile practice (VI): novel of climbing pen interesting Pavilion
使用nodejs完成判断哪些项目打包+发版
Shell script quickly counts the number of lines of project code
What does front-end processor mean? What is the main function? What is the difference with fortress machine?
ROS学习(22)TF变换
AcWing 361. Sightseeing cow problem solution (SPFA seeking positive ring)
AcWing 345. Cattle station solution (nature and multiplication of Floyd)
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
When grep looks for a process, it ignores the grep process itself
鼠标右键 自定义
刨析《C语言》【进阶】付费知识【完结】
DS-5/RVDS4.0变量初始化错误
golang 基础 —— 数据类型
Scenario practice: quickly build wordpress blog system based on function calculation
AcWing 361. 观光奶牛 题解(spfa求正环)
增加 pdf 标题浮窗
Public key \ private SSH avoid password login
Golang foundation - data type
一起看看matlab工具箱内部是如何实现BP神经网络的