Przeglądaj źródła

每日账单新增汇总行

donglang 20 godzin temu
rodzic
commit
41f39316c1

+ 40 - 0
sckw-modules/sckw-transport/src/main/java/com/sckw/transport/service/app/WaybillOrderService.java

@@ -2230,6 +2230,13 @@ public class WaybillOrderService {
         List<WaybillOrderReportResp> resultList = new ArrayList<>();
         int serialNumber = 1; // 序号从1开始
 
+        // 用于计算全局总计的变量
+        BigDecimal globalTotalMoney = BigDecimal.ZERO;
+        BigDecimal globalTotalNetWeight = BigDecimal.ZERO;
+        BigDecimal globalTotalGrossWeight = BigDecimal.ZERO;
+        BigDecimal globalTotalTareWeight = BigDecimal.ZERO;
+        int globalTotalCount = 0;
+
         // 3. 遍历组装:【汇总行】 -> 【明细行】
         for (Map.Entry<String, List<WaybillOrderReportResp>> entry : groupedMap.entrySet()) {
             List<WaybillOrderReportResp> details = entry.getValue();
@@ -2248,7 +2255,39 @@ public class WaybillOrderService {
             WaybillOrderReportResp summaryRow = createSummaryRow(firstItem, details);
             summaryRow.setSerialNumber(null);
             resultList.add(summaryRow);
+
+            // C. 累加到全局汇总行
+            globalTotalCount += details.size();
+            if (summaryRow.getTotalPrice() != null) {
+                globalTotalMoney = globalTotalMoney.add(summaryRow.getTotalPrice());
+            }
+            if (summaryRow.getAmount() != null) {
+                globalTotalNetWeight = globalTotalNetWeight.add(summaryRow.getAmount());
+            }
+            if (summaryRow.getGrossAmount() != null) {
+                globalTotalGrossWeight = globalTotalGrossWeight.add(summaryRow.getGrossAmount());
+            }
+
+            if (summaryRow.getTareAmount() != null) {
+                globalTotalTareWeight = globalTotalTareWeight.add(summaryRow.getTareAmount());
+            }
         }
+
+        // 4. 添加全局总计行
+        if (!resultList.isEmpty()) {
+            WaybillOrderReportResp grandTotalRow = new WaybillOrderReportResp();
+            // 设置标识,区分是分组汇总还是全局总计
+            grandTotalRow.setId(-2L);
+            grandTotalRow.setProcurementEntName("总计 (" + globalTotalCount + "车)");
+            grandTotalRow.setTotalPrice(globalTotalMoney);
+            grandTotalRow.setAmount(globalTotalNetWeight);
+            grandTotalRow.setGrossAmount(globalTotalGrossWeight);
+            grandTotalRow.setTareAmount(globalTotalTareWeight);
+
+            grandTotalRow.setSerialNumber(null);
+            resultList.add(grandTotalRow);
+        }
+
         log.info("[报表]销售报表分组汇总结束!");
         return resultList;
     }
@@ -2279,6 +2318,7 @@ public class WaybillOrderService {
         }
 
         // 赋值给汇总行
+        summary.setProcurementEntName("合计(" + details.size() + "车)");
         summary.setTotalPrice(totalMoney);
         summary.setAmount(totalNetWeight);
         summary.setGrossAmount(totalGrossWeight);