From df2ff592a5b9037a747032f3351836e0c61fb4f9 Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期五, 16 一月 2026 08:59:14 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_New' into dev_New

---
 src/main/java/com/ruoyi/measuringinstrumentledger/service/impl/MeasuringInstrumentLedgerServiceImpl.java |   92 ++++++++++++++++++++++++----------------------
 1 files changed, 48 insertions(+), 44 deletions(-)

diff --git a/src/main/java/com/ruoyi/measuringinstrumentledger/service/impl/MeasuringInstrumentLedgerServiceImpl.java b/src/main/java/com/ruoyi/measuringinstrumentledger/service/impl/MeasuringInstrumentLedgerServiceImpl.java
index e695b97..fbaad14 100644
--- a/src/main/java/com/ruoyi/measuringinstrumentledger/service/impl/MeasuringInstrumentLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/measuringinstrumentledger/service/impl/MeasuringInstrumentLedgerServiceImpl.java
@@ -5,14 +5,10 @@
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 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.dto.MeasuringInstrumentLedgerDto;
 import com.ruoyi.measuringinstrumentledger.mapper.MeasuringInstrumentLedgerMapper;
 import com.ruoyi.measuringinstrumentledger.mapper.MeasuringInstrumentLedgerRecordMapper;
 import com.ruoyi.measuringinstrumentledger.pojo.MeasuringInstrumentLedger;
@@ -40,12 +36,10 @@
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
-import java.util.Map;
 import java.util.UUID;
 import java.util.stream.Collectors;
-
-import static com.ruoyi.common.constant.StorageAttachmentConstants.StorageAttachmentFile;
 
 /**
  * @author :yys
@@ -70,54 +64,64 @@
     @Autowired
     private SysUserMapper sysUserMapper;
 
-    @Autowired
-    private StorageAttachmentService attachmentService;
-
     @Value("${file.upload-dir}")
     private String uploadDir;
 
     @Override
     public IPage<MeasuringInstrumentLedger> listPage(Page page, MeasuringInstrumentLedger measuringInstrumentLedger) {
-        IPage<MeasuringInstrumentLedger> iPage = measuringInstrumentLedgerMapper.listPage(page, measuringInstrumentLedger);
-        List<MeasuringInstrumentLedger> records = iPage.getRecords();
-        List<Long> ids = records.stream().map(MeasuringInstrumentLedger::getId).collect(Collectors.toList());
-
-        List<MeasuringInstrumentLedgerRecord> measuringInstrumentLedgerRecords = measuringInstrumentLedgerRecordMapper.selectList(new LambdaQueryWrapper<MeasuringInstrumentLedgerRecord>()
-                .in(MeasuringInstrumentLedgerRecord::getMeasuringInstrumentLedgerId, ids)
-                .orderByDesc(MeasuringInstrumentLedgerRecord::getCreateTime));
-        if (!CollectionUtils.isEmpty(measuringInstrumentLedgerRecords)) {
-            Map<Long, List<MeasuringInstrumentLedgerRecord>> collect = measuringInstrumentLedgerRecords.stream().collect(Collectors.groupingBy(MeasuringInstrumentLedgerRecord::getMeasuringInstrumentLedgerId));
-            for (MeasuringInstrumentLedger ledger : records) {
-                if (collect.containsKey(ledger.getId())) {
-                    ledger.setMostDate(collect.get(ledger.getId()).get(0).getRecordDate());
-                }
+        IPage<MeasuringInstrumentLedger> measuringInstrumentLedgerIPage = measuringInstrumentLedgerMapper.listPage(page, measuringInstrumentLedger);
+        List<Integer>  types = new ArrayList<>();
+        types.add(FileNameType.MEASURING.getValue());
+        types.add(FileNameType.MEASURINGRecord.getValue());
+        measuringInstrumentLedgerIPage.getRecords().forEach(item -> {
+            LambdaQueryWrapper<MeasuringInstrumentLedgerRecord> measuringInstrumentLedgerRecordLambdaQueryWrapper = new LambdaQueryWrapper<>();
+            measuringInstrumentLedgerRecordLambdaQueryWrapper.eq(MeasuringInstrumentLedgerRecord::getMeasuringInstrumentLedgerId, item.getId());
+            List<MeasuringInstrumentLedgerRecord> measuringInstrumentLedgerRecords = measuringInstrumentLedgerRecordMapper.selectList(measuringInstrumentLedgerRecordLambdaQueryWrapper);
+            List<Long> collect = new ArrayList<>();
+            if(!CollectionUtils.isEmpty(measuringInstrumentLedgerRecords)){
+                collect = measuringInstrumentLedgerRecords.stream().map(MeasuringInstrumentLedgerRecord::getId).collect(Collectors.toList());
             }
-        }
-        return iPage;
+            collect.add(item.getId());
+            LambdaQueryWrapper<CommonFile> salesLedgerFileWrapper = new LambdaQueryWrapper<>();
+            salesLedgerFileWrapper.in(CommonFile::getCommonId, collect)
+                    .in(CommonFile::getType,types);
+            List<CommonFile> commonFiles = commonFileMapper.selectList(salesLedgerFileWrapper);
+            item.setCommonFiles(commonFiles);
+
+        });
+        return measuringInstrumentLedgerIPage;
     }
 
     @Override
-    public boolean verifying(MeasuringInstrumentLedgerRecordDTO req) throws IOException {
-        MeasuringInstrumentLedger measuringInstrumentLedger = measuringInstrumentLedgerMapper.selectById(req.getMeasuringInstrumentLedgerId());
-        if (measuringInstrumentLedger == null) {
-            throw new RuntimeException("璁¢噺鍣ㄥ叿鍙拌处涓嶅瓨鍦�");
+    public boolean verifying(MeasuringInstrumentLedgerDto req) throws IOException {
+        MeasuringInstrumentLedger measuringInstrumentLedger = measuringInstrumentLedgerMapper.selectById(req.getId());
+        if(measuringInstrumentLedger == null) {
+            return false;
         }
-        measuringInstrumentLedgerRecordMapper.insert(req);
-        if (req.getBlobs() != null && !req.getBlobs().isEmpty()) {
-            List<StorageAttachment> attachments = new ArrayList<>();
-
-            for (StorageBlobDTO storageBlobDTO : req.getBlobs()) {
-                StorageAttachment storageAttachment = new StorageAttachment(
-                        StorageAttachmentFile,
-                        (long) StorageAttachmentRecordType.MeasuringInstrumentLedgerRecord.ordinal(),
-                        req.getId()
-                );
-                storageAttachment.setStorageBlobDTO(storageBlobDTO);
-                attachments.add(storageAttachment);
+        SysUser sysUser = sysUserMapper.selectUserById(measuringInstrumentLedger.getUserId());
+        measuringInstrumentLedger.setValid(req.getValid());
+        measuringInstrumentLedger.setMostDate(req.getRecordDate());
+        measuringInstrumentLedger.setNextDate(new Date(req.getRecordDate().getTime() + 1000L * 60 * 60 * 24 * req.getValid()));
+        MeasuringInstrumentLedgerRecord measuringInstrumentLedgerRecord = new MeasuringInstrumentLedgerRecord();
+        if(measuringInstrumentLedgerMapper.updateById(measuringInstrumentLedger) > 0) {
+            measuringInstrumentLedgerRecord.setMeasuringInstrumentLedgerId(req.getId());
+            measuringInstrumentLedgerRecord.setRecordDate(req.getRecordDate());
+            measuringInstrumentLedgerRecord.setEntryDate(req.getEntryDate());
+            measuringInstrumentLedgerRecord.setValid(req.getValid());
+            measuringInstrumentLedgerRecord.setUserId(req.getUserId());
+            measuringInstrumentLedgerRecord.setUserName(sysUser.getUserName());
+            measuringInstrumentLedgerRecordMapper.insert(measuringInstrumentLedgerRecord);
+            // 鍙拌处缁戝畾涓�娆�
+//            if(!CollectionUtils.isEmpty(req.getTempFileIds())){
+//                migrateTempFilesToFormal(measuringInstrumentLedger.getId(), req.getTempFileIds(), FileNameType.MEASURING.getValue());
+//            }
+            // 鍙拌处璁板綍缁戝畾涓�娆�
+            if(!CollectionUtils.isEmpty(req.getTempFileIds())){
+                migrateTempFilesToFormal(measuringInstrumentLedgerRecord.getId(), req.getTempFileIds(), FileNameType.MEASURINGRecord.getValue());
             }
-            attachmentService.saveStorageAttachment(attachments, req.getId(), StorageAttachmentRecordType.MeasuringInstrumentLedgerRecord, StorageAttachmentFile);
+            return true;
         }
-        return true;
+        return false;
     }
 
     @Override

--
Gitblit v1.9.3