From b12c93dbaeaf316e7845178e040d345d91469e2d Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期二, 02 九月 2025 17:55:08 +0800
Subject: [PATCH] yys  将文件迁移改为复制+删除

---
 src/main/java/com/ruoyi/purchase/service/impl/TicketRegistrationServiceImpl.java |   71 ++++++++++++++++++++++++++++++-----
 1 files changed, 60 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/ruoyi/purchase/service/impl/TicketRegistrationServiceImpl.java b/src/main/java/com/ruoyi/purchase/service/impl/TicketRegistrationServiceImpl.java
index 08bbf4b..8fc333d 100644
--- a/src/main/java/com/ruoyi/purchase/service/impl/TicketRegistrationServiceImpl.java
+++ b/src/main/java/com/ruoyi/purchase/service/impl/TicketRegistrationServiceImpl.java
@@ -30,7 +30,6 @@
 import com.ruoyi.sales.pojo.CommonFile;
 import com.ruoyi.sales.pojo.SalesLedgerProduct;
 import com.ruoyi.sales.service.ISalesLedgerProductService;
-import com.ruoyi.sales.service.impl.SalesLedgerProductServiceImpl;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.FilenameUtils;
@@ -223,12 +222,15 @@
 
             try {
                 // 鎵ц鏂囦欢杩佺Щ锛堜娇鐢ㄥ師瀛愭搷浣滅‘淇濆畨鍏ㄦ�э級
-                Files.move(
-                        Paths.get(tempFile.getTempPath()),
-                        formalFilePath,
-                        StandardCopyOption.REPLACE_EXISTING,
-                        StandardCopyOption.ATOMIC_MOVE
-                );
+//                Files.move(
+//                        Paths.get(tempFile.getTempPath()),
+//                        formalFilePath,
+//                        StandardCopyOption.REPLACE_EXISTING,
+//                        StandardCopyOption.ATOMIC_MOVE
+//                );
+                // 鍘熷瓙绉诲姩澶辫触锛屼娇鐢ㄥ鍒�+鍒犻櫎
+                Files.copy(Paths.get(tempFile.getTempPath()), formalFilePath, StandardCopyOption.REPLACE_EXISTING);
+                Files.deleteIfExists(Paths.get(tempFile.getTempPath()));
                 log.info("鏂囦欢杩佺Щ鎴愬姛: {} -> {}", tempFile.getTempPath(), formalFilePath);
 
                 // 鏇存柊鏂囦欢璁板綍锛堝叧鑱斿埌涓氬姟ID锛�
@@ -252,7 +254,43 @@
 
     @Override
     public int delRegistration(Long[] ids) {
-        return ticketRegistrationMapper.deleteBatchIds(Arrays.asList(ids));
+        // 鍒犻櫎閲囪喘鍙拌处浜у搧寮�绁ㄨ褰曞璞�
+        LambdaQueryWrapper<ProductRecord> productRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        productRecordLambdaQueryWrapper.in(ProductRecord::getId, Arrays.asList(ids));
+        List<ProductRecord> productRecords = productRecordMapper.selectList(productRecordLambdaQueryWrapper);
+        if(CollectionUtils.isEmpty(productRecords)){
+            return 0;
+        }
+        LambdaQueryWrapper<TicketRegistration> ticketRegistrationLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        ticketRegistrationLambdaQueryWrapper.in(TicketRegistration::getId, productRecords.stream().map(ProductRecord::getTicketRegistrationId).collect(Collectors.toList()));
+        List<TicketRegistration> ticketRegistrations = ticketRegistrationMapper.selectList(ticketRegistrationLambdaQueryWrapper);
+
+        // 淇敼浜у搧淇℃伅
+        for (ProductRecord productRecord : productRecords) {
+            BigDecimal subtract = ticketRegistrations.get(0).getInvoiceAmount().subtract(productRecords.get(0).getTicketsAmount());
+            // 灏忎簬绛変簬0鍒犻櫎 锛屽ぇ浜�0淇敼
+            if(subtract.compareTo(BigDecimal.ZERO) <= 0){
+                ticketRegistrationMapper.deleteById(ticketRegistrations.get(0));
+            }else if(subtract.compareTo(BigDecimal.ZERO) > 0){
+                ticketRegistrations.get(0).setInvoiceAmount(subtract);
+                ticketRegistrationMapper.updateById(ticketRegistrations.get(0));
+            }
+            LambdaQueryWrapper<SalesLedgerProduct> salesLedgerProductLambdaQueryWrapper = new LambdaQueryWrapper<>();
+            salesLedgerProductLambdaQueryWrapper.eq(SalesLedgerProduct::getId, productRecord.getSaleLedgerProjectId())
+                    .eq(SalesLedgerProduct::getType, 2);
+            List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectList(salesLedgerProductLambdaQueryWrapper);
+            if(!CollectionUtils.isEmpty(salesLedgerProducts)){
+                for (SalesLedgerProduct salesLedgerProduct : salesLedgerProducts) {
+                    salesLedgerProduct.setFutureTickets(salesLedgerProduct.getFutureTickets().add(productRecord.getTicketsNum()));
+                    salesLedgerProduct.setFutureTicketsAmount(salesLedgerProduct.getFutureTicketsAmount().add(productRecord.getTicketsAmount()));
+                    salesLedgerProductMapper.updateById(salesLedgerProduct);
+
+                }
+            }
+        }
+        // 鍒犻櫎閲囪喘鍙拌处浜у搧寮�绁ㄨ褰�
+        productRecordMapper.delete(productRecordLambdaQueryWrapper);
+        return 1;
     }
 
     @Override
@@ -294,9 +332,13 @@
     @Override
     public IPage<TicketRegistration> selectTicketRegistrationListPage(Page page, TicketRegistration ticketRegistration) {
         LambdaQueryWrapper<TicketRegistration> queryWrapper = new LambdaQueryWrapper<>();
-        if (StringUtils.isNotBlank(ticketRegistration.getPurchaseContractNumber())) {
-            queryWrapper.like(TicketRegistration::getPurchaseContractNumber, ticketRegistration.getPurchaseContractNumber())
-                    .like(TicketRegistration::getSupplierName, ticketRegistration.getSupplierName());
+        if (StringUtils.isNotBlank(ticketRegistration.getSupplierNameOrContractNo())) {
+            queryWrapper.and(wrapper -> wrapper
+                    .like(TicketRegistration::getPurchaseContractNumber, ticketRegistration.getSupplierNameOrContractNo())
+                    .or()
+                    .like(TicketRegistration::getSupplierName, ticketRegistration.getSupplierNameOrContractNo())
+                    .or()
+                    .like(TicketRegistration::getSalesContractNo, ticketRegistration.getSupplierNameOrContractNo()));
         }
         if (!ObjectUtils.isEmpty(ticketRegistration.getIssueDateStart()) && !ObjectUtils.isEmpty(ticketRegistration.getIssueDateEnd())) {
             queryWrapper.between(TicketRegistration::getIssueDate, LocalDate.parse(ticketRegistration.getIssueDateStart(), DateTimeFormatter.ofPattern("yyyy-MM-dd")), LocalDate.parse(ticketRegistration.getIssueDateEnd(), DateTimeFormatter.ofPattern("yyyy-MM-dd")));
@@ -324,6 +366,7 @@
 
             if (ticketRegistration.getStatus()) {
                 ticketRegistrationIPage.getRecords().removeIf(receiptPaymentDto1 -> new BigDecimal("0.00").equals(receiptPaymentDto1.getUnPaymentAmountTotal()));
+                ticketRegistrationIPage.setTotal(ticketRegistrationIPage.getRecords().size());
             }
         }
         return ticketRegistrationIPage;
@@ -346,6 +389,12 @@
         return purchaseLedgerDto;
     }
 
+    @Override
+    public List<PaymentRegistrationDto> getPaymentRegistrationDtoById(Long id) {
+        List<PaymentRegistrationDto> paymentRegistrationDtos =purchaseLedgerMapper.getPaymentRegistrationDtoById(id);
+        return paymentRegistrationDtos;
+    }
+
     private void handleSalesLedgerProducts(Long salesLedgerId, List<SalesLedgerProduct> products, Integer type) {
         if (products == null || products.isEmpty()) {
             return;

--
Gitblit v1.9.3