怎么进行表格的顺序顺序重排的后台算法
标签:ntp collect prepare 编号 用户 map current new red
表格顺序重排算法思想:
主要是在java的implements层中进行转换逻辑的书写
//id是前台ajax传来点击的表格
编号值
//采用java8 Stream流
public boolean exchageTableSotred(String id){
//获取priority进行重新排序
List allStockList = stockRepository.findAll();
Optional obj = stockRepository.findByDishId(dishId);
if (obj.isPresent()) {
int currentPriority = obj.get().getPriority();
//如果用户选择的是从未插队多的菜品
if (currentPriority == 0) {
this.setNextPrepareDish(dishId);
}
//如果用户选择的是已经在排队的菜品,需要将priority重排
List ordersReloadList = new ArrayList();
Map> 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
评论