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/PurchaseLedgerServiceImpl.java | 41 ++++++++++++++++++++++++++++++----------- 1 files changed, 30 insertions(+), 11 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 845b18d..01b14ff 100644 --- a/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java +++ b/src/main/java/com/ruoyi/purchase/service/impl/PurchaseLedgerServiceImpl.java @@ -12,7 +12,9 @@ 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.DateUtils; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.framework.security.LoginUser; @@ -40,6 +42,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.io.IOException; import java.math.BigDecimal; @@ -49,6 +52,7 @@ import java.nio.file.StandardCopyOption; import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.concurrent.TimeUnit; @@ -103,6 +107,7 @@ } @Override + @Transactional(rollbackFor = Exception.class) public int addOrEditPurchase(PurchaseLedgerDto purchaseLedgerDto) throws IOException { SalesLedger salesLedger = salesLedgerMapper.selectById(purchaseLedgerDto.getSalesLedgerId()); @@ -195,6 +200,7 @@ List<SalesLedgerProduct> updateList = partitionedProducts.get(true); List<SalesLedgerProduct> insertList = partitionedProducts.get(false); + PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(salesLedgerId); // 鎵ц鏇存柊鎿嶄綔 if (!updateList.isEmpty()) { @@ -207,6 +213,10 @@ if (!insertList.isEmpty()) { for (SalesLedgerProduct salesLedgerProduct : insertList) { salesLedgerProduct.setType(type); + Date entryDate = purchaseLedger.getEntryDate(); + + LocalDateTime localDateTime = entryDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(); + salesLedgerProduct.setRegisterDate(localDateTime); salesLedgerProductMapper.insert(salesLedgerProduct); } } @@ -266,12 +276,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锛� @@ -280,7 +293,7 @@ fileRecord.setName(originalFilename); fileRecord.setUrl(formalFilePath.toString()); fileRecord.setCreateTime(LocalDateTime.now()); - fileRecord.setType("2"); + fileRecord.setType(FileNameType.PURCHASE.getValue()); commonFileMapper.insert(fileRecord); // 鍒犻櫎涓存椂鏂囦欢璁板綍 @@ -303,7 +316,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<>(); @@ -371,6 +384,7 @@ } // 鍒涘缓骞跺~鍏匘TO PurchaseLedgerDto resultDto = new PurchaseLedgerDto(); + resultDto.setSalesLedgerId(purchaseLedger.getSalesLedgerId()); resultDto.setSalesContractNoId(purchaseLedger.getSalesLedgerId()); resultDto.setSalesContractNo(purchaseLedger.getSalesContractNo()); resultDto.setSupplierName(purchaseLedger.getSupplierName()); @@ -413,6 +427,7 @@ public PurchaseLedgerDto getPurchaseNoById(Long id) { PurchaseLedgerDto purchaseLedgerDto = new PurchaseLedgerDto(); PurchaseLedger purchaseLedger = purchaseLedgerMapper.selectById(id); + BeanUtils.copyProperties(purchaseLedger, purchaseLedgerDto); // TicketRegistration ticketRegistration = ticketRegistrationMapper.selectOne(new LambdaQueryWrapper<TicketRegistration>().eq(TicketRegistration::getPurchaseLedgerId, id)); // if (ticketRegistration != null) { @@ -424,9 +439,13 @@ } @Override - public IPage<PurchaseLedger> selectPurchaseLedgerListPage(IPage ipage, PurchaseLedger purchaseLedger) { - - return purchaseLedgerMapper.selectPurchaseLedgerListPage(ipage, purchaseLedger); + 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 -- Gitblit v1.9.3