标签:ntp collect prepare 编号 用户 map current new red
主要是在java的implements层中进行转换逻辑的书写 //id是前台ajax传来点击的表格 编号值 //采用java8 Stream流 public boolean exchageTableSotred(String id){ //获取priority进行重新排序 List<StockEntity> allStockList = stockRepository.findAll(); Optional<StockEntity> obj = stockRepository.findByDishId(dishId); if (obj.isPresent()) { int currentPriority = obj.get().getPriority(); //如果用户选择的是从未插队多的菜品 if (currentPriority == 0) { this.setNextPrepareDish(dishId); } //如果用户选择的是已经在排队的菜品,需要将priority重排 List<StockEntity> ordersReloadList = new ArrayList<>(); Map<Boolean, List<StockEntity>> partitionMap = allStockList.stream().collect(Collectors.partitioningBy(s -> currentPriority > (s.getPriority()))); partitionMap.get(true).stream().forEach(a -> a.setPriority(a.getPriority() + 1)); //前置第一位的菜品在false条件中 StockEntity fisrstDish = partitionMap.get(false).stream().filter(a -> a.getPriority() == currentPriority).limit(1).collect(Collectors.toList()).get(0); fisrstDish.setPriority(1); ordersReloadList.addAll(partitionMap.get(true)); ordersReloadList.add(fisrstDish); ordersReloadList.addAll(partitionMap.get(false).stream().filter(a -> a.getPriority() != currentPriority).collect(Collectors.toList())); stockRepository.saveAll(ordersReloadList); return true; } return false; }
笔记后面继续添加
标签:ntp collect prepare 编号 用户 map current new red
原文地址:https://www.cnblogs.com/666boyun/p/14312799.html