• Map按日期(忽略时分秒精度 按yymmdd格式)分组求和 并排序 stream流实现


    // 在库量趋势
            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;
        }
  • 相关阅读:
    最舒适的路线(并查集)
    POJ 2411 状态压缩DP
    NYOJ 708 ones
    HUD 1024 Max Sum Plus Plus
    最长上升子序列
    HDU 4717 The Moving Points
    重新开始写随笔
    读书的意义
    读《如何阅读一本书》笔记
    读《GRAY HAT PYTHON》笔记
  • 原文地址:https://www.cnblogs.com/axibug/p/16113980.html
Copyright © 2020-2023  润新知