From d1903c17568e1c373ca37a8baddbefbc330d12bf Mon Sep 17 00:00:00 2001
From: chenrui <1187576398@qq.com>
Date: 星期一, 26 五月 2025 16:31:35 +0800
Subject: [PATCH] 开票台账功能修改

---
 src/main/java/com/ruoyi/sales/controller/SalesLedgerController.java |  167 ++++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 115 insertions(+), 52 deletions(-)

diff --git a/src/main/java/com/ruoyi/sales/controller/SalesLedgerController.java b/src/main/java/com/ruoyi/sales/controller/SalesLedgerController.java
index 1f871d6..c7b7ccf 100644
--- a/src/main/java/com/ruoyi/sales/controller/SalesLedgerController.java
+++ b/src/main/java/com/ruoyi/sales/controller/SalesLedgerController.java
@@ -1,49 +1,78 @@
 package com.ruoyi.sales.controller;
 
-import java.util.List;
-import javax.servlet.http.HttpServletResponse;
-
 import com.ruoyi.common.utils.poi.ExcelUtil;
-import com.ruoyi.sales.pojo.SalesLedger;
-import com.ruoyi.sales.service.ISalesLedgerService;
-import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
 import com.ruoyi.framework.aspectj.lang.annotation.Log;
 import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
 import com.ruoyi.framework.web.controller.BaseController;
 import com.ruoyi.framework.web.domain.AjaxResult;
 import com.ruoyi.framework.web.page.TableDataInfo;
+import com.ruoyi.sales.dto.InvoiceLedgerDto;
+import com.ruoyi.sales.dto.SalesLedgerDto;
+import com.ruoyi.sales.mapper.InvoiceLedgerMapper;
+import com.ruoyi.sales.pojo.SalesLedger;
+import com.ruoyi.sales.service.ICommonFileService;
+import com.ruoyi.sales.service.ISalesLedgerService;
+import lombok.AllArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.CollectionUtils;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletResponse;
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * 閿�鍞彴璐ontroller
- * 
+ *
  * @author ruoyi
  * @date 2025-05-08
  */
 @RestController
 @RequestMapping("/sales/ledger")
-public class SalesLedgerController extends BaseController
-{
-    @Autowired
+@AllArgsConstructor
+public class SalesLedgerController extends BaseController {
+
     private ISalesLedgerService salesLedgerService;
+
+    private ICommonFileService commonFileService;
+
+    @Autowired
+    private InvoiceLedgerMapper invoiceLedgerMapper;
 
     /**
      * 鏌ヨ閿�鍞彴璐﹀垪琛�
      */
     @GetMapping("/list")
-    public TableDataInfo list(SalesLedger salesLedger)
-    {
+    public TableDataInfo list(SalesLedgerDto salesLedgerDto) {
         startPage();
-        List<SalesLedger> list = salesLedgerService.selectSalesLedgerList(salesLedger);
+        List<SalesLedger> list = salesLedgerService.selectSalesLedgerList(salesLedgerDto);
+        // 璁$畻宸插紑绁ㄩ噾棰�/鏈紑绁ㄩ噾棰�(宸插~鍐欏彂绁ㄩ噾棰濅负鍑�)
+        if(CollectionUtils.isEmpty(list)){
+            return getDataTable(list);
+        }
+        List<Long> salesLedgerIds = list.stream().map(SalesLedger::getId).collect(Collectors.toList());
+        List<InvoiceLedgerDto> invoiceLedgerDtoList = invoiceLedgerMapper.invoicedTotal(salesLedgerIds);
+        if(CollectionUtils.isEmpty(invoiceLedgerDtoList)){
+            return getDataTable(list);
+        }
+        for (SalesLedger salesLedger : list) {
+            for (InvoiceLedgerDto invoiceLedgerDto : invoiceLedgerDtoList) {
+                if (salesLedger.getId().intValue() == invoiceLedgerDto.getSalesLedgerId()) {
+                    BigDecimal noInvoiceAmountTotal = salesLedger.getContractAmount().subtract(invoiceLedgerDto.getInvoiceTotal());
+                    salesLedger.setNoInvoiceAmountTotal(noInvoiceAmountTotal);
+                }
+            }
+        }
         return getDataTable(list);
+    }
+
+    /**
+     * 鏌ヨ閿�鍞彴璐﹀拰浜у搧鐖跺瓙鍒楄〃
+     */
+    @GetMapping("/getSalesLedgerWithProducts")
+    public SalesLedgerDto getSalesLedgerWithProducts(SalesLedgerDto salesLedgerDto) {
+        return salesLedgerService.getSalesLedgerWithProducts(salesLedgerDto);
     }
 
     /**
@@ -51,49 +80,83 @@
      */
     @Log(title = "閿�鍞彴璐�", businessType = BusinessType.EXPORT)
     @PostMapping("/export")
-    public void export(HttpServletResponse response, SalesLedger salesLedger)
-    {
-        List<SalesLedger> list = salesLedgerService.selectSalesLedgerList(salesLedger);
+    public void export(HttpServletResponse response, SalesLedgerDto salesLedgerDto) {
+        List<SalesLedger> list = salesLedgerService.selectSalesLedgerList(salesLedgerDto);
         ExcelUtil<SalesLedger> util = new ExcelUtil<SalesLedger>(SalesLedger.class);
         util.exportExcel(response, list, "閿�鍞彴璐︽暟鎹�");
     }
 
     /**
-     * 鑾峰彇閿�鍞彴璐﹁缁嗕俊鎭�
-     */
-    @GetMapping(value = "/{id}")
-    public AjaxResult getInfo(@PathVariable("id") Long id)
-    {
-        return success(salesLedgerService.selectSalesLedgerById(id));
-    }
-
-    /**
-     * 鏂板閿�鍞彴璐�
+     * 鏂板淇敼閿�鍞彴璐�
      */
     @Log(title = "閿�鍞彴璐�", businessType = BusinessType.INSERT)
-    @PostMapping ("/insertSalesLedger")
-    public AjaxResult add(@RequestBody SalesLedger salesLedger)
-    {
-        return toAjax(salesLedgerService.insertSalesLedger(salesLedger));
-    }
-
-    /**
-     * 淇敼閿�鍞彴璐�
-     */
-    @Log(title = "閿�鍞彴璐�", businessType = BusinessType.UPDATE)
-    @PostMapping ("/updateSalesLedger")
-    public AjaxResult edit(@RequestBody SalesLedger salesLedger)
-    {
-        return toAjax(salesLedgerService.updateSalesLedger(salesLedger));
+    @PostMapping("/addOrUpdateSalesLedger")
+    public AjaxResult add(@RequestBody SalesLedgerDto salesLedgerDto) {
+        return toAjax(salesLedgerService.addOrUpdateSalesLedger(salesLedgerDto));
     }
 
     /**
      * 鍒犻櫎閿�鍞彴璐�
      */
     @Log(title = "閿�鍞彴璐�", businessType = BusinessType.DELETE)
-	@DeleteMapping("/{ids}")
-    public AjaxResult remove(@PathVariable Long[] ids)
-    {
+    @DeleteMapping("/delLedger")
+    public AjaxResult remove(@RequestBody Long[] ids) {
+        if (ids == null || ids.length == 0) {
+            return AjaxResult.error("璇蜂紶鍏ヨ鍒犻櫎鐨処D");
+        }
         return toAjax(salesLedgerService.deleteSalesLedgerByIds(ids));
     }
+
+    /**
+     * 鏌ヨ閿�鍞彴璐︿笉鍒嗛〉
+     *
+     * @param salesLedgerDto
+     * @return
+     */
+    @GetMapping("/listNoPage")
+    public AjaxResult listNoPage(SalesLedgerDto salesLedgerDto) {
+        List<SalesLedger> list = salesLedgerService.selectSalesLedgerList(salesLedgerDto);
+        return AjaxResult.success(list);
+    }
+
+    /**
+     * 閿�鍞彴璐﹂檮浠跺垹闄�
+     */
+    @Log(title = "閿�鍞彴璐﹂檮浠跺垹闄�", businessType = BusinessType.DELETE)
+    @DeleteMapping("/delLedgerFile")
+    public AjaxResult delLedgerFile(@RequestBody Long[] ids) {
+        if (ids == null || ids.length == 0) {
+            return AjaxResult.error("璇蜂紶鍏ヨ鍒犻櫎鐨処D");
+        }
+        return toAjax(commonFileService.deleteSalesLedgerByIds(ids));
+    }
+
+    /**
+     * 鏈湀閿�鍞悎鍚岄噾棰�
+     */
+    @GetMapping("/getContractAmount")
+    public AjaxResult getContractAmount() {
+        try {
+            BigDecimal contractAmount = salesLedgerService.getContractAmount();
+            return AjaxResult.success(contractAmount != null ? contractAmount : BigDecimal.ZERO);
+        } catch (Exception e) {
+            return AjaxResult.error("鑾峰彇鍚堝悓閲戦澶辫触锛�" + e.getMessage());
+        }
+    }
+
+    /**
+     * 瀹㈡埛鍚堝悓閲戦TOP5缁熻
+     */
+    @GetMapping("/getTopFiveList")
+    public AjaxResult getTopFiveList() {
+        return AjaxResult.success(salesLedgerService.getTopFiveList());
+    }
+
+    /**
+     * 杩戝崐骞村紑绁�,鍥炴閲戦
+     */
+    @GetMapping("/getAmountHalfYear")
+    public AjaxResult getAmountHalfYear() {
+        return AjaxResult.success(salesLedgerService.getAmountHalfYear());
+    }
 }

--
Gitblit v1.9.3