From 0da945da9f19f45d849fe8b14dc06bb59c5e4283 Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期五, 22 五月 2026 14:36:24 +0800
Subject: [PATCH] feat(purchase): 完善采购报表及增值税比对功能

---
 src/main/java/com/ruoyi/account/mapper/AccountStatementMapper.java           |    3 
 src/main/resources/mapper/account/AccountStatementMapper.xml                 |   35 ++++++++
 src/main/java/com/ruoyi/purchase/dto/VatDto.java                             |   17 ++-
 src/main/resources/mapper/sales/SalesLedgerMapper.xml                        |   16 ++++
 src/main/java/com/ruoyi/purchase/service/impl/PurchaseReportServiceImpl.java |   32 ++++++++
 src/main/java/com/ruoyi/purchase/controller/AccountingReportController.java  |   26 ++++-
 src/main/java/com/ruoyi/purchase/service/PurchaseReportService.java          |   14 +++
 src/main/java/com/ruoyi/sales/mapper/SalesLedgerMapper.java                  |    4 +
 src/main/java/com/ruoyi/purchase/vo/PurchaseReportVo.java                    |   44 +++++++++++
 src/main/resources/application.yml                                           |    2 
 10 files changed, 178 insertions(+), 15 deletions(-)

diff --git a/src/main/java/com/ruoyi/account/mapper/AccountStatementMapper.java b/src/main/java/com/ruoyi/account/mapper/AccountStatementMapper.java
index 307cf1a..89730cb 100644
--- a/src/main/java/com/ruoyi/account/mapper/AccountStatementMapper.java
+++ b/src/main/java/com/ruoyi/account/mapper/AccountStatementMapper.java
@@ -6,6 +6,7 @@
 import com.ruoyi.account.bean.dto.StatementAccountDto;
 import com.ruoyi.account.bean.vo.StatementAccountVo;
 import com.ruoyi.account.pojo.AccountStatement;
+import com.ruoyi.purchase.dto.VatDto;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -22,4 +23,6 @@
 
 
     IPage<StatementAccountVo> listPageAccountStatement(Page page, @Param("req") StatementAccountDto statementAccountDto);
+
+    IPage<VatDto> selectVatDtoPage(Page page, @Param("month") String month);
 }
diff --git a/src/main/java/com/ruoyi/purchase/controller/AccountingReportController.java b/src/main/java/com/ruoyi/purchase/controller/AccountingReportController.java
index f265ab0..798112b 100644
--- a/src/main/java/com/ruoyi/purchase/controller/AccountingReportController.java
+++ b/src/main/java/com/ruoyi/purchase/controller/AccountingReportController.java
@@ -2,10 +2,13 @@
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.basic.service.ISupplierService;
+import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.framework.aspectj.lang.annotation.Log;
 import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
-import com.ruoyi.framework.web.domain.AjaxResult;
 import com.ruoyi.framework.web.domain.R;
+import com.ruoyi.purchase.dto.VatDto;
+import com.ruoyi.purchase.service.PurchaseReportService;
+import com.ruoyi.purchase.vo.PurchaseReportVo;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import jakarta.servlet.http.HttpServletResponse;
@@ -15,6 +18,8 @@
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.util.List;
+
 @RestController
 @Tag(name = "閲囪喘鎶ヨ〃")
 @RequestMapping("/purchase/report")
@@ -22,31 +27,38 @@
 public class AccountingReportController {
 
     private final ISupplierService supplierService;
+    private final PurchaseReportService purchaseReportService;
 
 
     @GetMapping("/list")
     @Log(title = "閲囪喘鎶ヨ〃-椤圭洰鍒╂鼎", businessType = BusinessType.OTHER)
-    public AjaxResult list(Page page) {
-        return AjaxResult.success();
+    public R list(Page page, String customerName) {
+        return R.ok(purchaseReportService.list(page,customerName));
     }
 
     @Log(title = "閲囪喘鎶ヨ〃-椤圭洰鍒╂鼎瀵煎嚭", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
     @Operation(summary = "閲囪喘鎶ヨ〃-椤圭洰鍒╂鼎瀵煎嚭")
-    public void export(HttpServletResponse response) {
+    public void export(HttpServletResponse response, String customerName) {
+        List<PurchaseReportVo> list = purchaseReportService.list(new Page(1,-1),customerName).getRecords();
+        ExcelUtil<PurchaseReportVo> util = new ExcelUtil<>(PurchaseReportVo.class);
+        util.exportExcel(response, list , "椤圭洰鍒╂鼎");
 
     }
 
     @Log(title = "閲囪喘鎶ヨ〃-澧炲�肩◣姣斿", businessType = BusinessType.OTHER)
     @GetMapping("/listVat")
-    public AjaxResult listVat(Page page,String month) {
-        return AjaxResult.success();
+    public R listVat(Page page,String month) {
+        return R.ok(purchaseReportService.listVat(page,month));
     }
 
     @Log(title = "閲囪喘鎶ヨ〃-澧炲�肩◣姣斿", businessType = BusinessType.EXPORT)
     @PostMapping("/exportTwo")
     @Operation(summary = "閲囪喘鎶ヨ〃-澧炲�肩◣姣斿")
-    public void exportTwo(HttpServletResponse response) {
+    public void exportTwo(HttpServletResponse response,String month) {
+        List<VatDto> list = purchaseReportService.listVat(new Page(1,-1),month).getRecords();
+        ExcelUtil<VatDto> util = new ExcelUtil<>(VatDto.class);
+        util.exportExcel(response, list , "澧炲�肩◣姣斿");
     }
 
     @GetMapping("/supplierTransactions")
diff --git a/src/main/java/com/ruoyi/purchase/dto/VatDto.java b/src/main/java/com/ruoyi/purchase/dto/VatDto.java
index c70ebeb..3564183 100644
--- a/src/main/java/com/ruoyi/purchase/dto/VatDto.java
+++ b/src/main/java/com/ruoyi/purchase/dto/VatDto.java
@@ -1,27 +1,30 @@
 package com.ruoyi.purchase.dto;
 
+import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
 import com.ruoyi.framework.aspectj.lang.annotation.Excel;
+import io.swagger.v3.oas.annotations.media.Schema;
 import lombok.Data;
 
 import java.math.BigDecimal;
-import java.time.LocalDate;
-
 @Data
+@Schema(name = "VatDto", description = "绠$悊椹鹃┒鑸�--澧炲�肩◣姣斿鍙傛暟")
+@ExcelIgnoreUnannotated
 public class VatDto {
 
-    //鏈堜唤
     @Excel(name = "鏈堜唤")
+    @Schema(description = "鏈堜唤")
     private String month ;
 
-    //杩涢」绋�
-    @Excel(name = "杩涢」绋庨")
+    @Excel(name = "閿�椤圭◣棰�")
+    @Schema(description = "閿�椤圭◣棰�")
     private BigDecimal jTaxAmount;
 
-    //閿�椤圭◣
-    @Excel(name = "閿�椤圭◣棰�")
+    @Excel(name = "杩涢」绋庨")
+    @Schema(description = "杩涢」绋庨")
     private BigDecimal xTaxAmount;
 
     @Excel(name = "閿�-杩�")
+    @Schema(description = "閿�-杩�")
     private BigDecimal taxAmount;
 
 }
diff --git a/src/main/java/com/ruoyi/purchase/service/PurchaseReportService.java b/src/main/java/com/ruoyi/purchase/service/PurchaseReportService.java
new file mode 100644
index 0000000..4ec6522
--- /dev/null
+++ b/src/main/java/com/ruoyi/purchase/service/PurchaseReportService.java
@@ -0,0 +1,14 @@
+package com.ruoyi.purchase.service;
+
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.purchase.dto.VatDto;
+import com.ruoyi.purchase.vo.PurchaseReportVo;
+
+public interface PurchaseReportService {
+
+    IPage<PurchaseReportVo> list(Page page, String customerName);
+
+    IPage<VatDto> listVat(Page page, String month);
+}
diff --git a/src/main/java/com/ruoyi/purchase/service/impl/PurchaseReportServiceImpl.java b/src/main/java/com/ruoyi/purchase/service/impl/PurchaseReportServiceImpl.java
new file mode 100644
index 0000000..676cf46
--- /dev/null
+++ b/src/main/java/com/ruoyi/purchase/service/impl/PurchaseReportServiceImpl.java
@@ -0,0 +1,32 @@
+package com.ruoyi.purchase.service.impl;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.account.mapper.AccountStatementMapper;
+import com.ruoyi.purchase.dto.VatDto;
+import com.ruoyi.purchase.service.PurchaseReportService;
+import com.ruoyi.purchase.vo.PurchaseReportVo;
+import com.ruoyi.sales.mapper.SalesLedgerMapper;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+
+@Service
+@Slf4j
+@RequiredArgsConstructor
+public class PurchaseReportServiceImpl implements PurchaseReportService {
+
+    private final SalesLedgerMapper salesLedgerMapper;
+    private final AccountStatementMapper accountStatementMapper;
+
+    @Override
+    public IPage<PurchaseReportVo> list(Page page, String customerName) {
+        return salesLedgerMapper.selectPurchaseReportVoPage(page, customerName);
+    }
+
+    @Override
+    public IPage<VatDto> listVat(Page page, String month) {
+        return accountStatementMapper.selectVatDtoPage(page, month);
+    }
+}
diff --git a/src/main/java/com/ruoyi/purchase/vo/PurchaseReportVo.java b/src/main/java/com/ruoyi/purchase/vo/PurchaseReportVo.java
new file mode 100644
index 0000000..afe7f98
--- /dev/null
+++ b/src/main/java/com/ruoyi/purchase/vo/PurchaseReportVo.java
@@ -0,0 +1,44 @@
+package com.ruoyi.purchase.vo;
+
+import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
+import com.ruoyi.framework.aspectj.lang.annotation.Excel;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+@Schema(name = "PurchaseReportVo", description = "绠$悊椹鹃┒鑸�--椤圭洰鍒╂鼎鍙傛暟")
+@ExcelIgnoreUnannotated
+public class PurchaseReportVo {
+
+    @Schema(description = "閿�鍞悎鍚屽彿")
+    @Excel(name = "閿�鍞悎鍚屽彿")
+    private String customerContractNo;
+
+    @Schema(description = "瀹㈡埛鍚嶇О")
+    @Excel(name = "瀹㈡埛鍚嶇О")
+    private String customerName;
+
+    @Schema(description = "椤圭洰鍚嶇О")
+    @Excel(name = "椤圭洰鍚嶇О")
+    private String projectName;
+
+    @Excel(name = "鍚堝悓閲戦")
+    @Schema(description = "鍚堝悓閲戦")
+    private BigDecimal contractAmount;
+
+    @Excel(name = "閲囪喘閲戦")
+    @Schema(description = "閲囪喘閲戦")
+    private BigDecimal purchaseAmount;
+
+    @Schema(description = "鍒╂鼎")
+    @Excel(name = "鍒╂鼎")
+    private BigDecimal balance;
+
+    @Schema(description = "鍒╂鼎鐜�")
+    @Excel(name = "鍒╂鼎鐜�")
+    private BigDecimal balanceRatio;
+
+
+}
diff --git a/src/main/java/com/ruoyi/sales/mapper/SalesLedgerMapper.java b/src/main/java/com/ruoyi/sales/mapper/SalesLedgerMapper.java
index 9f49265..5518290 100644
--- a/src/main/java/com/ruoyi/sales/mapper/SalesLedgerMapper.java
+++ b/src/main/java/com/ruoyi/sales/mapper/SalesLedgerMapper.java
@@ -6,6 +6,7 @@
 import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.ruoyi.home.dto.IncomeExpenseAnalysisDto;
+import com.ruoyi.purchase.vo.PurchaseReportVo;
 import com.ruoyi.sales.dto.SalesLedgerDto;
 import com.ruoyi.sales.dto.SalesTrendDto;
 import com.ruoyi.sales.dto.StatisticsTableDto;
@@ -86,4 +87,7 @@
     List<SalesTrendDto> statisticsTable(@Param("statisticsTableDto")StatisticsTableDto statisticsTableDto);
 
     IPage<SalesLedgerDto> listSalesLedgerAndShipped(Page page, @Param("ew") SalesLedgerDto salesLedgerDto);
+
+    IPage<PurchaseReportVo> selectPurchaseReportVoPage(Page page, @Param("customerName") String customerName);
+
 }
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 70324c6..ad66a65 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -3,7 +3,7 @@
   main:
     allow-circular-references: true
   profiles:
-    active: dev
+    active: dev-pro
 langchain4j:
   mcp:
     # MCP 鏈嶅姟绔湴鍧�锛堟牴鎹疄闄呴儴缃茬殑 MCP 鏈嶅姟璋冩暣锛�
diff --git a/src/main/resources/mapper/account/AccountStatementMapper.xml b/src/main/resources/mapper/account/AccountStatementMapper.xml
index 331c61b..32b1621 100644
--- a/src/main/resources/mapper/account/AccountStatementMapper.xml
+++ b/src/main/resources/mapper/account/AccountStatementMapper.xml
@@ -40,4 +40,39 @@
             </if>
     ORDER BY lj.statement_month DESC
     </select>
+    <select id="selectVatDtoPage" resultType="com.ruoyi.purchase.dto.VatDto">
+    SELECT
+        month,
+        jTaxAmount,
+        xTaxAmount,
+        (jTaxAmount - xTaxAmount) AS taxAmount
+    FROM (
+        SELECT
+            month,
+            SUM(IF(type = 'purchase', tax_price, 0)) AS xTaxAmount,
+            SUM(IF(type = 'sales', tax_price, 0)) AS jTaxAmount
+        FROM (
+            SELECT
+                DATE_FORMAT(issue_date, '%Y-%m') AS month,
+                tax_price,
+                'sales' AS type
+            FROM account_sales_invoice
+            WHERE status != 1
+            UNION ALL
+            SELECT
+                DATE_FORMAT(issue_date, '%Y-%m') AS month,
+                tax_price,
+                'purchase' AS type
+            FROM account_purchase_invoice
+            WHERE status != 1
+        ) AS all_data
+    GROUP BY month
+    ) AS TT
+     <where>
+            <if test="month != null">
+                and TT.month = #{month}
+            </if>
+     </where>
+    ORDER BY TT.month
+    </select>
 </mapper>
diff --git a/src/main/resources/mapper/sales/SalesLedgerMapper.xml b/src/main/resources/mapper/sales/SalesLedgerMapper.xml
index e08632a..c145e0a 100644
--- a/src/main/resources/mapper/sales/SalesLedgerMapper.xml
+++ b/src/main/resources/mapper/sales/SalesLedgerMapper.xml
@@ -121,5 +121,21 @@
         </if>
         order by sl.execution_date desc
     </select>
+    <select id="selectPurchaseReportVoPage" resultType="com.ruoyi.purchase.vo.PurchaseReportVo">
+        select sl.sales_contract_no customerContractNo,
+               c.customer_name,
+               sl.project_name,
+               sl.contract_amount contractAmount,
+               pl.contract_amount purchaseAmount,
+               sl.contract_amount-pl.contract_amount balance,
+               (sl.contract_amount-pl.contract_amount)/sl.contract_amount balanceRatio
+        from sales_ledger sl
+        left join purchase_ledger pl on sl.id = pl.sales_ledger_id
+        left join customer c on sl.customer_id = c.id
+        where 1=1
+        <if test="customerName != null and customerName != '' ">
+            and c.customer_name like concat('%',#{customerName},'%')
+        </if>
+    </select>
 
 </mapper>

--
Gitblit v1.9.3