From cfad72d6b9d5b67920068c556819dd52bebd6935 Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期二, 24 六月 2025 14:40:07 +0800
Subject: [PATCH] 2025-06-23 采购-来票登记上传接口开发

---
 src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java |   42 ++++++++++++++++++++++++++++++++++--------
 1 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java b/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
index ac9691b..8019b76 100644
--- a/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java
@@ -12,6 +12,7 @@
 import com.ruoyi.basic.pojo.Product;
 import com.ruoyi.basic.pojo.ProductModel;
 import com.ruoyi.basic.pojo.SupplierManage;
+import com.ruoyi.common.enums.FileNameType;
 import com.ruoyi.common.exception.base.BaseException;
 import com.ruoyi.common.utils.SecurityUtils;
 import com.ruoyi.common.utils.StringUtils;
@@ -38,6 +39,7 @@
 import org.apache.commons.io.FilenameUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.stereotype.Service;
 
 import java.io.IOException;
@@ -50,6 +52,7 @@
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
+import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 /**
@@ -85,6 +88,8 @@
     private final ProductRecordMapper productRecordMapper;
 
     private final InvoiceRegistrationProductMapper invoiceRegistrationProductMapper;
+
+    private final StringRedisTemplate redisTemplate;
 
     @Value("${file.upload-dir}")
     private String uploadDir;
@@ -276,7 +281,7 @@
                 fileRecord.setName(originalFilename);
                 fileRecord.setUrl(formalFilePath.toString());
                 fileRecord.setCreateTime(LocalDateTime.now());
-                fileRecord.setType("2");
+                fileRecord.setType(FileNameType.PURCHASE.getValue());
                 commonFileMapper.insert(fileRecord);
 
                 // 鍒犻櫎涓存椂鏂囦欢璁板綍
@@ -299,7 +304,7 @@
         // 鎵归噺鍒犻櫎鍏宠仈鐨勯噰璐彴璐︿骇鍝�
         LambdaQueryWrapper<SalesLedgerProduct> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.in(SalesLedgerProduct::getSalesLedgerId, ids)
-                .eq(SalesLedgerProduct::getType, "2");
+                .eq(SalesLedgerProduct::getType, 2);
         salesLedgerProductMapper.delete(queryWrapper);
         // 鎵归噺鍒犻櫎鍏宠仈鐨勯噰璐彴璐︾殑鏉ョエ鐧昏
         LambdaQueryWrapper<TicketRegistration> ticketRegistrationLambdaQueryWrapper = new LambdaQueryWrapper<>();
@@ -420,12 +425,13 @@
     }
 
     @Override
-    public IPage<PurchaseLedger> selectPurchaseLedgerListPage(IPage ipage, PurchaseLedger purchaseLedger) {
-        LambdaQueryWrapper<PurchaseLedger> queryWrapper = new LambdaQueryWrapper<>();
-        if (StringUtils.isNotBlank(purchaseLedger.getPurchaseContractNumber())) {
-            queryWrapper.like(PurchaseLedger::getPurchaseContractNumber, purchaseLedger.getPurchaseContractNumber());
-        }
-        return purchaseLedgerMapper.selectPage(ipage, queryWrapper);
+    public IPage<PurchaseLedgerDto> selectPurchaseLedgerListPage(IPage ipage, PurchaseLedgerDto purchaseLedger) {
+        IPage<PurchaseLedgerDto> purchaseLedgerDtoIPage = purchaseLedgerMapper.selectPurchaseLedgerListPage(ipage, purchaseLedger);
+        purchaseLedgerDtoIPage.getRecords().forEach(purchaseLedgerDto -> {
+            List<CommonFile> commonFiles = commonFileMapper.selectList(new LambdaQueryWrapper<CommonFile>().eq(CommonFile::getCommonId, purchaseLedgerDto.getId()).eq(CommonFile::getType, FileNameType.PURCHASELEDGER.getValue()));
+            purchaseLedgerDto.setSalesLedgerFiles(commonFiles);
+        });
+        return purchaseLedgerDtoIPage;
     }
 
     @Override
@@ -440,6 +446,26 @@
         return invoiceRegistrationProducts;
     }
 
+    @Override
+    public String getPurchaseNo() {
+        // 鐢熸垚鏃ユ湡鍓嶇紑锛堜緥濡傦細CG20250405锛�
+        String purchaseNo = "CG" + LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
+
+        // 鏋勫缓 Redis Key锛堟寜澶╁垎闅旓級
+        String redisKey = "purchase_no:" + LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE);
+
+        // 鑾峰彇褰撳墠搴忓彿骞堕�掑锛堝師瀛愭搷浣滐級
+        Long sequence = redisTemplate.opsForValue().increment(redisKey);
+
+        // 璁剧疆杩囨湡鏃堕棿锛堟鏃ュけ鏁堬紝闃叉鍐椾綑鏁版嵁锛�
+        if (sequence == 1) {
+            redisTemplate.expire(redisKey, 1, TimeUnit.DAYS);
+        }
+
+        // 杩斿洖瀹屾暣缂栧彿锛堝 CG202504050001锛�
+        return purchaseNo + String.format("%03d", sequence);
+    }
+
     /**
      * 涓嬪垝绾垮懡鍚嶈浆椹煎嘲鍛藉悕
      */

--
Gitblit v1.9.3