From 53bdb26a0ae994418e92d93aab23d6f5e7225f37 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期一, 19 五月 2025 16:20:56 +0800
Subject: [PATCH] 产品

---
 src/main/java/com/ruoyi/sales/service/impl/InvoiceLedgerServiceImpl.java |  174 +++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 135 insertions(+), 39 deletions(-)

diff --git a/src/main/java/com/ruoyi/sales/service/impl/InvoiceLedgerServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/InvoiceLedgerServiceImpl.java
index 46e18ea..2fc0eb7 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/InvoiceLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/InvoiceLedgerServiceImpl.java
@@ -1,22 +1,20 @@
 package com.ruoyi.sales.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.ruoyi.basic.dto.SupplierManageDto;
-import com.ruoyi.basic.excel.SupplierManageExcelDto;
-import com.ruoyi.common.constant.Constants;
-import com.ruoyi.common.utils.file.FileUploadUtils;
-import com.ruoyi.common.utils.file.FileUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.common.vo.FileVo;
 import com.ruoyi.sales.dto.InvoiceLedgerDto;
 import com.ruoyi.sales.excel.InvoiceLedgerExcelDto;
 import com.ruoyi.sales.mapper.InvoiceLedgerFileMapper;
 import com.ruoyi.sales.mapper.InvoiceLedgerMapper;
+import com.ruoyi.sales.mapper.ReceiptPaymentMapper;
 import com.ruoyi.sales.pojo.InvoiceLedger;
 import com.ruoyi.sales.pojo.InvoiceLedgerFile;
+import com.ruoyi.sales.pojo.ReceiptPayment;
 import com.ruoyi.sales.service.InvoiceLedgerService;
 import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.BeanUtils;
@@ -24,11 +22,17 @@
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.ObjectUtils;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.File;
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.YearMonth;
 import java.util.List;
+import java.util.Objects;
+import java.util.UUID;
 import java.util.stream.Collectors;
 
 @Service
@@ -43,6 +47,9 @@
     @Autowired
     private InvoiceLedgerFileMapper invoiceLedgerFileMapper;
 
+    @Autowired
+    private ReceiptPaymentMapper receiptPaymentMapper;
+
     /**
      * 寮�绁ㄥ彴璐︽柊澧�
      * @param invoiceLedgerDto
@@ -50,10 +57,19 @@
      */
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public int invoiceLedgerAdd(InvoiceLedgerDto invoiceLedgerDto) {
+    public int invoiceLedgerSaveOrUpdate(InvoiceLedgerDto invoiceLedgerDto) {
         InvoiceLedger invoiceLedger = new InvoiceLedger();
         BeanUtils.copyProperties(invoiceLedgerDto, invoiceLedger);
-        int result = invoiceLedgerMapper.insert(invoiceLedger);
+        int result;
+        if(invoiceLedgerDto.getId() == null){
+            result = invoiceLedgerMapper.insert(invoiceLedger);
+        }else {
+            result = invoiceLedgerMapper.updateById(invoiceLedger);
+            //鍒犻櫎鎵�鏈夐檮浠跺叧鑱�
+            LambdaQueryWrapper<InvoiceLedgerFile> delWrapper = new LambdaQueryWrapper<>();
+            delWrapper.eq(InvoiceLedgerFile::getInvoiceLedgerId, invoiceLedgerDto.getId());
+            invoiceLedgerFileMapper.delete(delWrapper);
+        }
         List<FileVo> fileList = invoiceLedgerDto.getFileList();
         if(CollectionUtils.isNotEmpty(fileList)){
             fileList.forEach(fileVo -> {
@@ -76,34 +92,6 @@
         LambdaQueryWrapper<InvoiceLedger> delWrapper = new LambdaQueryWrapper<>();
         delWrapper.in(InvoiceLedger::getId, ids);
         return invoiceLedgerMapper.delete(delWrapper);
-    }
-
-    /**
-     * 寮�绁ㄥ彴璐︿慨鏀�
-     * @param invoiceLedgerDto
-     * @return
-     */
-    @Override
-    @Transactional(rollbackFor = Exception.class)
-    public int invoiceLedgerUpdate(InvoiceLedgerDto invoiceLedgerDto) {
-        InvoiceLedger invoiceLedger = new InvoiceLedger();
-        BeanUtils.copyProperties(invoiceLedgerDto, invoiceLedger);
-        int result = invoiceLedgerMapper.updateById(invoiceLedger);
-        // 鍒犻櫎鍏宠仈闄勪欢
-        LambdaQueryWrapper<InvoiceLedgerFile> delWrapper = new LambdaQueryWrapper<>();
-        delWrapper.eq(InvoiceLedgerFile::getInvoiceLedgerId, invoiceLedger.getId());
-        invoiceLedgerFileMapper.delete(delWrapper);
-        // 閲嶆柊鎻掑叆闄勪欢鍏宠仈琛�
-        List<FileVo> fileList = invoiceLedgerDto.getFileList();
-        if(CollectionUtils.isNotEmpty(fileList)){
-            fileList.forEach(fileVo -> {
-                InvoiceLedgerFile invoiceLedgerFile = new InvoiceLedgerFile();
-                BeanUtils.copyProperties(fileVo, invoiceLedgerFile);
-                invoiceLedgerFile.setInvoiceLedgerId(invoiceLedger.getId());
-                invoiceLedgerFileMapper.insert(invoiceLedgerFile);
-            });
-        }
-        return result;
     }
 
     /**
@@ -139,9 +127,14 @@
         FileVo fileVo = new FileVo();
         try {
             String baseDir = uploadFile + File.separatorChar + "invoiceLedger";
-            String filePath = FileUploadUtils.upload(baseDir, file);
-            fileVo.setFileName(file.getOriginalFilename());
-            fileVo.setFilePath(filePath);
+            File dirFile = new File(baseDir);
+            if(!dirFile.exists()){
+                dirFile.mkdirs();
+            }
+            String filePath = baseDir + File.separatorChar + UUID.randomUUID() + "_" + file.getOriginalFilename();
+            file.transferTo(new File(filePath));
+            fileVo.setName(file.getOriginalFilename());
+            fileVo.setUrl(filePath);
             fileVo.setFileSize((int)file.getSize());
         }catch (Exception e){
             e.printStackTrace();
@@ -157,7 +150,7 @@
      * @return
      */
     @Override
-    public void invoiceLedgerDownload(HttpServletResponse response, InvoiceLedgerDto invoiceLedgerDto) {
+    public void invoiceLedgerExport(HttpServletResponse response, InvoiceLedgerDto invoiceLedgerDto) {
         List<InvoiceLedgerDto> invoiceLedgerDtoList = invoiceLedgerMapper.invoiceLedgerList(invoiceLedgerDto);
         List<InvoiceLedgerExcelDto> invoiceLedgerExcelDtoList = invoiceLedgerDtoList.stream().map(item -> {
             InvoiceLedgerExcelDto invoiceLedgerExcelDto = new InvoiceLedgerExcelDto();
@@ -168,4 +161,107 @@
         util.exportExcel(response, invoiceLedgerExcelDtoList, "渚涘簲鍟嗗鍑�");
     }
 
+    /**
+     * 寮�绁ㄥ彴璐﹁鎯�
+     * @param id
+     * @return
+     */
+    @Override
+    public InvoiceLedgerDto invoiceLedgerDetail(Integer id) {
+        InvoiceLedgerDto invoiceLedgerDto  = invoiceLedgerMapper.invoiceLedgerInfo(id);
+        if(ObjectUtils.isEmpty(invoiceLedgerDto)){
+            throw new RuntimeException("寮�绁ㄥ彴璐︽煡鎵惧け璐�");
+        }
+        // 鏌ヨ闄勪欢
+        QueryWrapper<InvoiceLedgerFile> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("invoice_ledger_id", id);
+        List<InvoiceLedgerFile> invoiceLedgerFileList = invoiceLedgerFileMapper.selectList(queryWrapper);
+        List<FileVo> fileList = invoiceLedgerFileList.stream().map(item -> {
+            FileVo fileVo = new FileVo();
+            BeanUtils.copyProperties(item, fileVo);
+            return fileVo;
+        }).collect(Collectors.toList());
+        invoiceLedgerDto.setFileList(fileList);
+        return invoiceLedgerDto;
+    }
+
+    /**
+     * 闄勪欢鎻愪氦
+     * @param invoiceLedgerDto
+     * @return
+     */
+    @Override
+    public void invoiceLedgerCommitFile(InvoiceLedgerDto invoiceLedgerDto) {
+        if(null == invoiceLedgerDto.getId()){
+            throw new RuntimeException("缂哄皯鍙戠エ鍙拌处涓婚敭");
+        }
+        if(CollectionUtils.isEmpty(invoiceLedgerDto.getFileList())){
+            throw new RuntimeException("缂哄皯鏂囦欢淇℃伅");
+        }
+        List<FileVo> fileList = invoiceLedgerDto.getFileList();
+        fileList.forEach(fileVo -> {
+            InvoiceLedgerFile invoiceLedgerFile = new InvoiceLedgerFile();
+            BeanUtils.copyProperties(fileVo, invoiceLedgerFile);
+            invoiceLedgerFile.setInvoiceLedgerId(invoiceLedgerDto.getId());
+            invoiceLedgerFileMapper.insert(invoiceLedgerFile);
+        });
+    }
+
+    /**
+     * 寮�绁ㄥ彴璐︽煡璇�
+     * @param invoiceLedgerDto
+     * @return
+     */
+    @Override
+    public List<InvoiceLedgerDto> invoiceLedgerList(InvoiceLedgerDto invoiceLedgerDto) {
+        return invoiceLedgerMapper.invoiceLedgerList(invoiceLedgerDto);
+    }
+
+    /**
+     * 瀹㈡埛閿�鍞褰�
+     * @param page
+     * @param invoiceLedgerDto
+     * @return
+     */
+    @Override
+    public IPage<InvoiceLedgerDto> invoiceLedgerSalesAccount(Page page, InvoiceLedgerDto invoiceLedgerDto) {
+        IPage<InvoiceLedgerDto> invoiceLedgerDtoIPage = invoiceLedgerMapper.invoiceLedgerSalesAccount(page, invoiceLedgerDto);
+        for (InvoiceLedgerDto record : invoiceLedgerDtoIPage.getRecords()) {
+            QueryWrapper<ReceiptPayment> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("customer_id", record.getCustomerId());
+            List<ReceiptPayment> receiptPaymentList = receiptPaymentMapper.selectList(queryWrapper);
+            BigDecimal totalAmount = BigDecimal.ZERO;
+            if(!CollectionUtils.isEmpty(receiptPaymentList)){
+                for (ReceiptPayment receiptPayment : receiptPaymentList) {
+                    totalAmount = totalAmount.add(receiptPayment.getInvoiceAmount());
+                }
+            }
+            BigDecimal unReceiptPaymentAmount = record.getInvoiceAmount().subtract(totalAmount);
+            record.setReceiptPaymentAmount(totalAmount);
+            record.setUnReceiptPaymentAmount(unReceiptPaymentAmount);
+        }
+        return invoiceLedgerDtoIPage;
+    }
+
+    @Override
+    public BigDecimal getInvoiceAmount() {
+        LocalDate now = LocalDate.now();
+        YearMonth currentMonth = YearMonth.from(now);
+
+        // 鍒涘缓LambdaQueryWrapper
+        LambdaQueryWrapper<InvoiceLedger> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.ge(InvoiceLedger::getInvoiceDate, currentMonth.atDay(1).atStartOfDay())  // 澶т簬绛変簬鏈湀绗竴澶�
+                .lt(InvoiceLedger::getInvoiceDate, currentMonth.plusMonths(1).atDay(1).atStartOfDay()); // 灏忎簬涓嬫湀绗竴澶�
+
+        // 鎵ц鏌ヨ骞惰绠楁�诲拰
+        List<InvoiceLedger> invoiceLedgers = invoiceLedgerMapper.selectList(queryWrapper);
+
+        BigDecimal totalContractAmount = invoiceLedgers.stream()
+                .map(InvoiceLedger::getInvoiceAmount)
+                .filter(Objects::nonNull)
+                .reduce(BigDecimal.ZERO, BigDecimal::add);
+
+        return totalContractAmount;
+    }
+
 }

--
Gitblit v1.9.3