From 8c8f19c87c9dfa7576f04ad80d864b37d0617786 Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期四, 15 一月 2026 09:38:46 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_New' into dev_New

---
 src/main/java/com/ruoyi/measuringinstrumentledger/service/impl/MeasuringInstrumentLedgerRecordServiceImpl.java |   53 +++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 41 insertions(+), 12 deletions(-)

diff --git a/src/main/java/com/ruoyi/measuringinstrumentledger/service/impl/MeasuringInstrumentLedgerRecordServiceImpl.java b/src/main/java/com/ruoyi/measuringinstrumentledger/service/impl/MeasuringInstrumentLedgerRecordServiceImpl.java
index 0dbdc71..840a15a 100644
--- a/src/main/java/com/ruoyi/measuringinstrumentledger/service/impl/MeasuringInstrumentLedgerRecordServiceImpl.java
+++ b/src/main/java/com/ruoyi/measuringinstrumentledger/service/impl/MeasuringInstrumentLedgerRecordServiceImpl.java
@@ -4,9 +4,14 @@
 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.StorageBlobDTO;
+import com.ruoyi.basic.pojo.StorageAttachment;
+import com.ruoyi.basic.service.StorageAttachmentService;
 import com.ruoyi.common.enums.FileNameType;
+import com.ruoyi.common.enums.StorageAttachmentRecordType;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.poi.ExcelUtil;
+import com.ruoyi.measuringinstrumentledger.dto.MeasuringInstrumentLedgerRecordDTO;
 import com.ruoyi.measuringinstrumentledger.mapper.MeasuringInstrumentLedgerMapper;
 import com.ruoyi.measuringinstrumentledger.mapper.MeasuringInstrumentLedgerRecordMapper;
 import com.ruoyi.measuringinstrumentledger.pojo.MeasuringInstrumentLedger;
@@ -18,10 +23,10 @@
 import com.ruoyi.sales.pojo.CommonFile;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.FilenameUtils;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
-import org.springframework.util.CollectionUtils;
 
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
@@ -34,7 +39,11 @@
 import java.time.format.DateTimeFormatter;
 import java.util.Date;
 import java.util.List;
+import java.util.Objects;
 import java.util.UUID;
+import java.util.stream.Collectors;
+
+import static com.ruoyi.common.constant.StorageAttachmentConstants.StorageAttachmentFile;
 
 /**
  * @author :yys
@@ -56,6 +65,9 @@
     @Autowired
     private TempFileMapper tempFileMapper;
 
+    @Autowired
+    private StorageAttachmentService storageAttachmentService;
+
     @Value("${file.upload-dir}")
     private String uploadDir;
 
@@ -64,7 +76,8 @@
         IPage<MeasuringInstrumentLedgerRecord> measuringInstrumentLedgerRecordIPage = measuringInstrumentLedgerRecordMapper.listPage(page, measuringInstrumentLedgerRecord);
         measuringInstrumentLedgerRecordIPage.getRecords().forEach(item -> {
             LambdaQueryWrapper<CommonFile> salesLedgerFileWrapper = new LambdaQueryWrapper<>();
-            salesLedgerFileWrapper.eq(CommonFile::getCommonId, item.getId());
+            salesLedgerFileWrapper.eq(CommonFile::getCommonId, item.getId())
+                    .eq(CommonFile::getType, FileNameType.MEASURINGRecord.getValue());
             List<CommonFile> commonFiles = commonFileMapper.selectList(salesLedgerFileWrapper);
             item.setCommonFiles(commonFiles);
         });
@@ -88,14 +101,12 @@
         if(!measuringInstrumentLedgerRecord1.getValid().equals(measuringInstrumentLedgerRecord.getValid())){
             MeasuringInstrumentLedger measuringInstrumentLedger = measuringInstrumentLedgerMapper.selectById(measuringInstrumentLedgerRecord1.getMeasuringInstrumentLedgerId());
             if(measuringInstrumentLedger != null){
+                measuringInstrumentLedger.setValid(measuringInstrumentLedgerRecord.getValid());
                 measuringInstrumentLedger.setNextDate(new Date(measuringInstrumentLedger.getMostDate().getTime() + measuringInstrumentLedgerRecord.getValid() * 24 * 60 * 60 * 1000L));
             }
             measuringInstrumentLedgerMapper.updateById(measuringInstrumentLedger);
         }
-        // 鍒犻櫎闄勪欢
-        LambdaQueryWrapper<CommonFile> delWrapper = new LambdaQueryWrapper<>();
-        delWrapper.eq(CommonFile::getCommonId, measuringInstrumentLedgerRecord.getId());
-        commonFileMapper.delete(delWrapper);
+        measuringInstrumentLedgerRecordMapper.updateById(measuringInstrumentLedgerRecord);
         // 璁板綍闄勪欢缁戝畾
         migrateTempFilesToFormal(measuringInstrumentLedgerRecord.getId(), measuringInstrumentLedgerRecord.getTempFileIds(), FileNameType.MEASURINGRecord.getValue());
         return true;
@@ -144,12 +155,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锛�
@@ -172,4 +186,19 @@
             }
         }
     }
+
+    @Override
+    public MeasuringInstrumentLedgerRecordDTO getById(Long id) {
+        MeasuringInstrumentLedgerRecord measuringInstrumentLedgerRecord = measuringInstrumentLedgerRecordMapper.selectById(id);
+        List<StorageAttachment> storageAttachments = storageAttachmentService.selectStorageAttachments(measuringInstrumentLedgerRecord.getId(), StorageAttachmentRecordType.MeasuringInstrumentLedgerRecord, StorageAttachmentFile);
+        List<StorageBlobDTO> storageBlobDTOList =
+                storageAttachments.stream()
+                        .map(StorageAttachment::getStorageBlobDTO)
+                        .filter(Objects::nonNull)
+                        .collect(Collectors.toList());
+        MeasuringInstrumentLedgerRecordDTO measuringInstrumentLedgerRecordDTO = new MeasuringInstrumentLedgerRecordDTO();
+        BeanUtils.copyProperties(measuringInstrumentLedgerRecord, measuringInstrumentLedgerRecordDTO);
+        measuringInstrumentLedgerRecordDTO.setBlobs(storageBlobDTOList);
+        return measuringInstrumentLedgerRecordDTO;
+    }
 }

--
Gitblit v1.9.3