当前位置:网站首页>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
边栏推荐
- 新工作感悟~辞旧迎新~
- Add PDF Title floating window
- 对C语言数组的再认识
- ROS学习(二十)机器人SLAM功能包——rgbdslam的安装与测试
- [advanced C language] 8 written questions of pointer
- golang 基础 —— 数据类型
- Modify the system time of Px4 flight control
- 一文带你走进【内存泄漏】
- Blue Bridge Cup 2022 13th provincial competition real topic - block painting
- Basic introduction and use of dvajs
猜你喜欢
随机推荐
Blue Bridge Cup 2022 13th provincial competition real topic - block painting
MySQL's most basic select statement
What does front-end processor mean? What is the main function? What is the difference with fortress machine?
各种语言,软件,系统的国内镜像,收藏这一个仓库就够了: Thanks-Mirror
tansig和logsig的差异,为什么BP喜欢用tansig
ROS学习(23)action通信机制
JVM 内存模型
Yunna | work order management software, work order management software app
ROS学习(26)动态参数配置
AcWing 361. Sightseeing cow problem solution (SPFA seeking positive ring)
永久的摇篮
Ds-5/rvds4.0 variable initialization error
Make DIY welding smoke extractor with lighting
C language instance_ five
swiper组件中使用video导致全屏错位
Box stretch and pull (left-right mode)
Gin 入门实战
Golang foundation - data type
454 Baidu Mianjing 1
POJ 3177 redundant paths POJ 3352 road construction (dual connection)