// 在库量趋势 LambdaQueryWrapper<StockInventoryDetailEntity> stayStockWrapper = new LambdaQueryWrapper<>(); stayStockWrapper.eq(StockInventoryDetailEntity::getWarehouseCode, warehouseCode) .isNotNull(StockInventoryDetailEntity::getUpdateTime) .isNotNull(StockInventoryDetailEntity::getInventoryQuantity) .apply("DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(update_time)"); List<StockInventoryDetailEntity> list = this.list(stayStockWrapper); Map<String, Double> stayStockTempMap = list.stream().collect(Collectors.groupingBy(o -> DateUtil.dateStr(o.getUpdateTime()), Collectors.summingDouble(StockInventoryDetailEntity::getInventoryQuantity))); // 排序 LinkedHashMap<String, Double> stayStockMap = getStringDoubleLinkedHashMap(stayStockTempMap); stockTendDTO.setStayStockMap(stayStockMap);
/** * 排序 * * @param stockTempMap * @return */ private LinkedHashMap<String, Double> getStringDoubleLinkedHashMap(Map<String, Double> stockTempMap) { Object[] inStockKey = stockTempMap.keySet().toArray(); Arrays.sort(inStockKey, Collections.reverseOrder()); LinkedHashMap<String, Double> stockMap = new LinkedHashMap<>(); for (int i = 0; i < inStockKey.length; i++) { stockMap.put(String.valueOf(inStockKey[i]), stockTempMap.get(inStockKey[i])); } return stockMap; }