From f80eee649f269eb61f15c7d0d2e282146eaaf9ef Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期一, 01 六月 2026 14:01:18 +0800
Subject: [PATCH] feat(home): 新增上月销售采购金额统计功能

---
 doc/20260601_home_business_上月数据_前端联调文档.md                      |  101 +++++++++++++++++++++++++++++++++
 src/main/java/com/ruoyi/home/dto/HomeBusinessDto.java          |    6 ++
 src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java |   28 +++++++++
 3 files changed, 135 insertions(+), 0 deletions(-)

diff --git "a/doc/20260601_home_business_\344\270\212\346\234\210\346\225\260\346\215\256_\345\211\215\347\253\257\350\201\224\350\260\203\346\226\207\346\241\243.md" "b/doc/20260601_home_business_\344\270\212\346\234\210\346\225\260\346\215\256_\345\211\215\347\253\257\350\201\224\350\260\203\346\226\207\346\241\243.md"
new file mode 100644
index 0000000..19c4f60
--- /dev/null
+++ "b/doc/20260601_home_business_\344\270\212\346\234\210\346\225\260\346\215\256_\345\211\215\347\253\257\350\201\224\350\260\203\346\226\207\346\241\243.md"
@@ -0,0 +1,101 @@
+# /home/business 鎺ュ彛鏂板涓婃湀鏁版嵁 鈥� 鍓嶇鑱旇皟鏂囨。
+
+## 鍙樻洿姒傝堪
+
+`GET /home/business` 鎺ュ彛鍦ㄥ師鏈夊瓧娈靛熀纭�涓婃柊澧� **涓婃湀閿�鍞噾棰�** 鍜� **涓婃湀閲囪喘閲戦** 涓や釜瀛楁锛屽墠绔彲鐩存帴鐢ㄤ簬灞曠ず鐜瘮瓒嬪娍銆�
+
+---
+
+## 鎺ュ彛淇℃伅
+
+| 椤圭洰 | 鍐呭 |
+|------|------|
+| 鎺ュ彛鍦板潃 | `/home/business` |
+| 璇锋眰鏂瑰紡 | `GET` |
+| 鏄惁璁よ瘉 | 鏄� |
+
+---
+
+## 鍝嶅簲鍙傛暟
+
+### 鏂板瀛楁
+
+| 瀛楁鍚� | 绫诲瀷 | 璇存槑 |
+|--------|------|------|
+| `lastMonthSaleMoney` | `String` | 涓婃湀閿�鍞悎鍚岄噾棰濓紙鍏冿級锛屼繚鐣欎袱浣嶅皬鏁帮紝濡� `"150000.00"` |
+| `lastMonthPurchaseMoney` | `String` | 涓婃湀閲囪喘鍚堝悓閲戦锛堝厓锛夛紝淇濈暀涓や綅灏忔暟锛屽 `"80000.00"` |
+
+### 瀹屾暣鍝嶅簲
+
+```json
+{
+  "code": 200,
+  "msg": "鎿嶄綔鎴愬姛",
+  "data": {
+    "monthSaleMoney": "200000.00",
+    "lastMonthSaleMoney": "150000.00",
+    "monthSaleHaveMoney": "0.00",
+    "monthPurchaseMoney": "100000.00",
+    "lastMonthPurchaseMoney": "80000.00",
+    "monthPurchaseHaveMoney": "0.00",
+    "inventoryNum": "5000.00",
+    "todayInventoryNum": "120.00"
+  }
+}
+```
+
+### 鎵�鏈夊瓧娈典竴瑙�
+
+| 瀛楁鍚� | 绫诲瀷 | 璇存槑 |
+|--------|------|------|
+| `monthSaleMoney` | `String` | 鏈湀閿�鍞噾棰� |
+| `lastMonthSaleMoney` | **`String`锛堟柊澧烇級** | 涓婃湀閿�鍞噾棰� |
+| `monthSaleHaveMoney` | `String` | 鏈湀閿�鍞湭寮�绁ㄩ噾棰濓紙褰撳墠鍥哄畾 `0.00`锛� |
+| `monthPurchaseMoney` | `String` | 鏈湀閲囪喘閲戦 |
+| `lastMonthPurchaseMoney` | **`String`锛堟柊澧烇級** | 涓婃湀閲囪喘閲戦 |
+| `monthPurchaseHaveMoney` | `String` | 鏈湀閲囪喘鏈紑绁ㄩ噾棰濓紙褰撳墠鍥哄畾 `0.00`锛� |
+| `inventoryNum` | `String` | 褰撳墠搴撳瓨鎬婚噺 |
+| `todayInventoryNum` | `String` | 浠婃棩鍏ュ簱鏁伴噺 |
+
+---
+
+## 鏁版嵁鍙e緞
+
+| 瀛楁 | 鏁版嵁鏉ユ簮 | 缁熻鍙e緞 |
+|------|---------|---------|
+| `monthSaleMoney` | `sales_ledger` 琛� | `entry_date` 鍦ㄦ湰鏈�1鏃涓嬫湀1鏃ヤ箣闂寸殑 `contract_amount` 鍚堣 |
+| `lastMonthSaleMoney` | `sales_ledger` 琛� | `entry_date` 鍦ㄤ笂鏈�1鏃鏈湀1鏃ヤ箣闂寸殑 `contract_amount` 鍚堣 |
+| `monthPurchaseMoney` | `purchase_ledger` 琛� | `entry_date` 鍦ㄦ湰鏈�1鏃涓嬫湀1鏃ヤ箣闂寸殑 `contract_amount` 鍚堣 |
+| `lastMonthPurchaseMoney` | `purchase_ledger` 琛� | `entry_date` 鍦ㄤ笂鏈�1鏃鏈湀1鏃ヤ箣闂寸殑 `contract_amount` 鍚堣 |
+
+---
+
+## 鍓嶇浣跨敤寤鸿
+
+### 鐜瘮灞曠ず
+
+```javascript
+// 璁$畻鐜瘮鍙樺寲
+const saleGrowth = lastMonthSaleMoney > 0
+  ? ((monthSaleMoney - lastMonthSaleMoney) / lastMonthSaleMoney * 100).toFixed(1)
+  : 100;
+
+const purchaseGrowth = lastMonthPurchaseMoney > 0
+  ? ((monthPurchaseMoney - lastMonthPurchaseMoney) / lastMonthPurchaseMoney * 100).toFixed(1)
+  : 100;
+```
+
+### 瓒嬪娍绠ご
+
+- `saleGrowth > 0` 鈫� 绾㈣壊鍚戜笂绠ご (鈫�)
+- `saleGrowth < 0` 鈫� 缁胯壊鍚戜笅绠ご (鈫�)
+- `saleGrowth === 0` 鈫� 鐏拌壊鎸佸钩 (鈫�)
+
+---
+
+## 娉ㄦ剰浜嬮」
+
+1. **绫诲瀷涓� String**锛氶噾棰濆瓧娈靛潎涓哄瓧绗︿覆锛屼繚鐣欎袱浣嶅皬鏁帮紝璁$畻鐜瘮鏃堕渶鐢� `parseFloat()` 杞崲
+2. **榛樿鍊�**锛氭棤鏁版嵁鏃惰繑鍥� `"0.00"`锛屼笉浼氳繑鍥� `null`
+3. **鏈紑绁ㄥ瓧娈�**锛歚monthSaleHaveMoney` 鍜� `monthPurchaseHaveMoney` 褰撳墠鍥哄畾杩斿洖 `"0.00"`锛屽悗缁凯浠d細鎺ュ叆瀹為檯鏁版嵁
+4. **鍚戝悗鍏煎**锛氫粎鏂板瀛楁锛屽師鏈夊瓧娈典笉鍙橈紝宸叉湁鍓嶇鍔熻兘涓嶅彈褰卞搷
\ No newline at end of file
diff --git a/src/main/java/com/ruoyi/home/dto/HomeBusinessDto.java b/src/main/java/com/ruoyi/home/dto/HomeBusinessDto.java
index 6e968a0..19346b2 100644
--- a/src/main/java/com/ruoyi/home/dto/HomeBusinessDto.java
+++ b/src/main/java/com/ruoyi/home/dto/HomeBusinessDto.java
@@ -16,12 +16,18 @@
     @Schema(description = "鏈湀閿�鍞噾棰�")
     private String monthSaleMoney = "0.00";
 
+    @Schema(description = "涓婃湀閿�鍞噾棰�")
+    private String lastMonthSaleMoney = "0.00";
+
     @Schema(description = "鏈湀閿�鍞湭寮�绁ㄩ噾棰�")
     private String monthSaleHaveMoney = "0.00";
 
     @Schema(description = "鏈湀閲囪喘閲戦")
     private String monthPurchaseMoney = "0.00";
 
+    @Schema(description = "涓婃湀閲囪喘閲戦")
+    private String lastMonthPurchaseMoney = "0.00";
+
     @Schema(description = "鏈湀閲囪喘鏈紑绁ㄩ噾棰�")
     private String monthPurchaseHaveMoney = "0.00";
 
diff --git a/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java b/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
index d3c21a2..affc030 100644
--- a/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
+++ b/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
@@ -179,6 +179,34 @@
             homeBusinessDto.setMonthPurchaseMoney(receiveAmount.setScale(2, RoundingMode.HALF_UP).toString());
             homeBusinessDto.setMonthPurchaseHaveMoney(BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP).toString());
         }
+
+        // 涓婃湀閿�鍞噾棰�
+        YearMonth lastMonth = currentMonth.minusMonths(1);
+        LambdaQueryWrapper<SalesLedger> lastMonthSalesWrapper = new LambdaQueryWrapper<>();
+        lastMonthSalesWrapper.ge(SalesLedger::getEntryDate, lastMonth.atDay(1).atStartOfDay())
+                .lt(SalesLedger::getEntryDate, lastMonth.plusMonths(1).atDay(1).atStartOfDay());
+        List<SalesLedger> lastMonthSalesLedgers = salesLedgerMapper.selectList(lastMonthSalesWrapper);
+        if (!CollectionUtils.isEmpty(lastMonthSalesLedgers)) {
+            BigDecimal lastMonthContractAmount = lastMonthSalesLedgers.stream()
+                    .map(SalesLedger::getContractAmount)
+                    .filter(Objects::nonNull)
+                    .reduce(BigDecimal.ZERO, BigDecimal::add);
+            homeBusinessDto.setLastMonthSaleMoney(lastMonthContractAmount.setScale(2, RoundingMode.HALF_UP).toString());
+        }
+
+        // 涓婃湀閲囪喘閲戦
+        LambdaQueryWrapper<PurchaseLedger> lastMonthPurchaseWrapper = new LambdaQueryWrapper<>();
+        lastMonthPurchaseWrapper.ge(PurchaseLedger::getEntryDate, lastMonth.atDay(1).atStartOfDay())
+                .lt(PurchaseLedger::getEntryDate, lastMonth.plusMonths(1).atDay(1).atStartOfDay());
+        List<PurchaseLedger> lastMonthPurchaseLedgers = purchaseLedgerMapper.selectList(lastMonthPurchaseWrapper);
+        if (!CollectionUtils.isEmpty(lastMonthPurchaseLedgers)) {
+            BigDecimal lastMonthPurchaseAmount = lastMonthPurchaseLedgers.stream()
+                    .map(PurchaseLedger::getContractAmount)
+                    .filter(Objects::nonNull)
+                    .reduce(BigDecimal.ZERO, BigDecimal::add);
+            homeBusinessDto.setLastMonthPurchaseMoney(lastMonthPurchaseAmount.setScale(2, RoundingMode.HALF_UP).toString());
+        }
+
         // 缁熻搴撳瓨
         BigDecimal stockQuantityTotal = stockInventoryMapper.selectTotal();
         homeBusinessDto.setInventoryNum(stockQuantityTotal.setScale(2, RoundingMode.HALF_UP).toString());

--
Gitblit v1.9.3