zoukankan      html  css  js  c++  java
  • 怎么进行表格的顺序顺序重排的后台算法

    表格顺序重排算法思想:

    主要是在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; 
    }
     
    

      笔记后面继续添加

  • 相关阅读:
    JPA各种类型映射处理
    HTML URL编码
    C# 温故而知新:Stream篇(二)
    数据集
    C#可调用API接口来获取窗口句柄,代码如下:
    C# 温故而知新:Stream篇(三)
    SQL的主键和外键约束
    C# 温故而知新: 线程篇(三)
    C# 温故而知新:Stream篇(四)
    C# 温故而知新:Stream篇(—)
  • 原文地址:https://www.cnblogs.com/666boyun/p/14312799.html
Copyright © 2011-2022 走看看