当前位置:网站首页>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
边栏推荐
- Clickhouse fields are grouped and aggregated, and SQL is queried according to the granularity of any time period
- Yiwen takes you into [memory leak]
- Mysqlbackup restores specific tables
- AcWing 1141. 局域网 题解(kruskalkruskal 求最小生成树)
- 编译命令行终端 swift
- ROS学习(25)rviz plugin插件
- What does security capability mean? What are the protection capabilities of different levels of ISO?
- When grep looks for a process, it ignores the grep process itself
- 鼠标右键 自定义
- hdu 4661 Message Passing(木DP&amp;组合数学)
猜你喜欢
How did partydao turn a tweet into a $200million product Dao in one year
According to the analysis of the Internet industry in 2022, how to choose a suitable position?
shell脚本快速统计项目代码行数
Baidu flying general BMN timing action positioning framework | data preparation and training guide (Part 1)
鼠标右键 自定义
LeetCode:1175. Prime permutation
设置Wordpress伪静态连接(无宝塔)
Transplant DAC chip mcp4725 to nuc980
Comparison of picture beds of free white whoring
百度飞将BMN时序动作定位框架 | 数据准备与训练指南 (上)
随机推荐
JS reverse -- ob confusion and accelerated music that poked the [hornet's nest]
Amway wave C2 tools
搭建【Redis in CentOS7.x】
字符串转成日期对象
Yunna | work order management measures, how to carry out work order management
场景实践:基于函数计算快速搭建Wordpress博客系统
WCF基金会
454 Baidu Mianjing 1
HDU 4661 message passing (wood DP & amp; Combinatorics)
JS ES5也可以創建常量?
JS ES5也可以创建常量?
Analyze "C language" [advanced] paid knowledge [End]
New job insights ~ leave the old and welcome the new~
ROS学习(25)rviz plugin插件
Instructions for using the domain analysis tool bloodhound
Start from the bottom structure to learn the customization and testing of fpga---- FIFO IP
Baidu flying general BMN timing action positioning framework | data preparation and training guide (Part 1)
一起看看matlab工具箱内部是如何实现BP神经网络的
Appium基础 — Appium Inspector定位工具(一)
js如何快速创建一个长度为 n 的数组