| | |
| | | |
| | | public AjaxResult total() { |
| | | List<SalesLedger> salesLedgers = salesLedgerMapper.selectList(null); |
| | | if(CollectionUtils.isEmpty(salesLedgers)) return AjaxResult.success(salesLedgers); |
| | | if (CollectionUtils.isEmpty(salesLedgers)) { |
| | | return AjaxResult.success(salesLedgers); |
| | | } |
| | | |
| | | Map<String, Object> map = new HashMap<>(); |
| | | // 销售额 |
| | | map.put("contractAmountTotal", salesLedgers.stream().map(SalesLedger::getContractAmount).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | BigDecimal contractAmountTotal = salesLedgers.stream() |
| | | .map(SalesLedger::getContractAmount) |
| | | .filter(Objects::nonNull) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | map.put("contractAmountTotal", contractAmountTotal); |
| | | |
| | | // 订单数量 |
| | | map.put("total", new BigDecimal(salesLedgers.size())); |
| | | int totalOrders = salesLedgers.size(); |
| | | map.put("total", new BigDecimal(totalOrders)); |
| | | map.put("shipRate", "0.00%"); |
| | | |
| | | // 发货率 |
| | | List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>() |
| | | List<SalesLedgerProduct> products = salesLedgerProductMapper.selectList(new LambdaQueryWrapper<SalesLedgerProduct>() |
| | | .eq(SalesLedgerProduct::getType, 1)); |
| | | map.put("shipRate", "0%"); |
| | | if(CollectionUtils.isEmpty(salesLedgerProducts)) return AjaxResult.success(map); |
| | | // 发货数量 |
| | | long count = shippingInfoMapper.selectCount(new LambdaQueryWrapper<ShippingInfo>() |
| | | .in(ShippingInfo::getSalesLedgerProductId, salesLedgerProducts.stream().map(SalesLedgerProduct::getId).collect(Collectors.toList())) |
| | | if (CollectionUtils.isEmpty(products)) { |
| | | return AjaxResult.success(map); |
| | | } |
| | | |
| | | Map<Long, Long> productIdToLedgerIdMap = products.stream() |
| | | .filter(p -> p.getId() != null && p.getSalesLedgerId() != null) |
| | | .collect(Collectors.toMap(SalesLedgerProduct::getId, SalesLedgerProduct::getSalesLedgerId, (k1, k2) -> k1)); |
| | | |
| | | List<ShippingInfo> shippingInfos = shippingInfoMapper.selectList(new LambdaQueryWrapper<ShippingInfo>() |
| | | .eq(ShippingInfo::getStatus,"审核通过")); |
| | | map.put("shipRate", String.format("%.2f", count * 100.0 / salesLedgerProducts.size()) + "%"); |
| | | |
| | | long shippedOrderCount = shippingInfos.stream() |
| | | .filter(info -> productIdToLedgerIdMap.containsKey(info.getSalesLedgerProductId())) |
| | | .map(info -> { |
| | | if (info.getSalesLedgerId() != null) { |
| | | return info.getSalesLedgerId(); |
| | | } |
| | | return productIdToLedgerIdMap.get(info.getSalesLedgerProductId()); |
| | | }) |
| | | .filter(Objects::nonNull) |
| | | .distinct() |
| | | .count(); |
| | | |
| | | map.put("shipRate", String.format("%.2f", shippedOrderCount * 100.0 / totalOrders) + "%"); |
| | | return AjaxResult.success(map); |
| | | } |
| | | |