当前位置:网站首页>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
边栏推荐
- Share a general compilation method of so dynamic library
- Appium foundation - appium inspector positioning tool (I)
- 我如何编码8个小时而不会感到疲倦。
- C language instance_ three
- AcWing 1141. LAN problem solving (kruskalkruskal finding the minimum spanning tree)
- Curl command
- hdu 4661 Message Passing(木DP&amp;组合数学)
- 454-百度面经1
- json学习初体验–第三者jar包实现bean、List、map创json格式
- AcWing 345. 牛站 题解(floyd的性质、倍增)
猜你喜欢
Gin introduction practice
454 Baidu Mianjing 1
Appium automation test foundation uiautomatorviewer positioning tool
刨析《C语言》【进阶】付费知识【一】
百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (下)
我如何编码8个小时而不会感到疲倦。
开发中对集合里面的数据根据属性进行合并数量时犯的错误
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
JVM 内存模型
修改px4飞控的系统时间
随机推荐
编译命令行终端 swift
百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (上)
JS es5 peut également créer des constantes?
How to prevent overfitting in cross validation
Right mouse button customization
WCF Foundation
Share a general compilation method of so dynamic library
AcWing 1148. Secret milk transportation problem solution (minimum spanning tree)
2022/0524/bookstrap
According to the analysis of the Internet industry in 2022, how to choose a suitable position?
各种语言,软件,系统的国内镜像,收藏这一个仓库就够了: Thanks-Mirror
使用nodejs完成判断哪些项目打包+发版
First experience of JSON learning - the third-party jar package realizes bean, list and map to create JSON format
ROS学习(26)动态参数配置
Yunna - work order management system and process, work order management specification
Machine learning: the difference between random gradient descent (SGD) and gradient descent (GD) and code implementation.
swiper组件中使用video导致全屏错位
ROS learning (22) TF transformation
盒子拉伸拉扯(左右模式)
Compile command line terminal swift