From 3f2d4ba07ee9e1e0ddba97b43dc70af09f0e39a2 Mon Sep 17 00:00:00 2001
From: chenhj <1263187585@qq.com>
Date: 星期四, 30 四月 2026 17:40:30 +0800
Subject: [PATCH] 审核附件修改

---
 src/main/java/com/ruoyi/measuringinstrumentledger/service/impl/MeasuringInstrumentLedgerServiceImpl.java |  199 +++++++++++--------------------------------------
 1 files changed, 45 insertions(+), 154 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..4025d75 100644
--- a/src/main/java/com/ruoyi/measuringinstrumentledger/service/impl/MeasuringInstrumentLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/measuringinstrumentledger/service/impl/MeasuringInstrumentLedgerServiceImpl.java
@@ -5,47 +5,28 @@
 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;
 import com.ruoyi.measuringinstrumentledger.pojo.MeasuringInstrumentLedgerRecord;
 import com.ruoyi.measuringinstrumentledger.service.MeasuringInstrumentLedgerService;
-import com.ruoyi.other.mapper.TempFileMapper;
-import com.ruoyi.other.pojo.TempFile;
 import com.ruoyi.project.system.domain.SysUser;
 import com.ruoyi.project.system.mapper.SysUserMapper;
 import com.ruoyi.sales.mapper.CommonFileMapper;
 import com.ruoyi.sales.pojo.CommonFile;
+import jakarta.servlet.http.HttpServletResponse;
+import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.io.FilenameUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
-import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.StandardCopyOption;
-import java.time.LocalDate;
-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
@@ -53,71 +34,58 @@
  */
 @Service
 @Slf4j
+@RequiredArgsConstructor
 public class MeasuringInstrumentLedgerServiceImpl extends ServiceImpl<MeasuringInstrumentLedgerMapper, MeasuringInstrumentLedger> implements MeasuringInstrumentLedgerService {
 
-    @Autowired
-    private MeasuringInstrumentLedgerMapper measuringInstrumentLedgerMapper;
-
-    @Autowired
-    private MeasuringInstrumentLedgerRecordMapper measuringInstrumentLedgerRecordMapper;
-
-    @Autowired
-    private TempFileMapper tempFileMapper;
-
-    @Autowired
-    private CommonFileMapper commonFileMapper;
-
-    @Autowired
-    private SysUserMapper sysUserMapper;
-
-    @Autowired
-    private StorageAttachmentService attachmentService;
-
-    @Value("${file.upload-dir}")
-    private String uploadDir;
+    private final MeasuringInstrumentLedgerMapper measuringInstrumentLedgerMapper;
+    private final MeasuringInstrumentLedgerRecordMapper measuringInstrumentLedgerRecordMapper;
+    private final SysUserMapper sysUserMapper;
 
     @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());
+        });
+        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);
-            }
-            attachmentService.saveStorageAttachment(attachments, req.getId(), StorageAttachmentRecordType.MeasuringInstrumentLedgerRecord, StorageAttachmentFile);
+        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());
+//            }
+            return true;
         }
-        return true;
+        return false;
     }
 
     @Override
@@ -135,84 +103,7 @@
         }
         measuringInstrumentLedger.setUserName(sysUser.getUserName());
         measuringInstrumentLedgerMapper.insert(measuringInstrumentLedger);
-        if(!CollectionUtils.isEmpty(measuringInstrumentLedger.getTempFileIds())){
-            migrateTempFilesToFormal(measuringInstrumentLedger.getId(), measuringInstrumentLedger.getTempFileIds(), FileNameType.MEASURING.getValue());
-        }
         return true;
     }
 
-
-    /**
-     * 灏嗕复鏃舵枃浠惰縼绉诲埌姝e紡鐩綍
-     *
-     * @param businessId  涓氬姟ID锛堥攢鍞彴璐D锛�
-     * @param tempFileIds 涓存椂鏂囦欢ID鍒楄〃
-     * @throws IOException 鏂囦欢鎿嶄綔寮傚父
-     */
-    private void migrateTempFilesToFormal(Long businessId, List<String> tempFileIds,Integer fileType) throws IOException {
-        if (CollectionUtils.isEmpty(tempFileIds)) {
-            return;
-        }
-
-        // 鏋勫缓姝e紡鐩綍璺緞锛堟寜涓氬姟绫诲瀷鍜屾棩鏈熷垎缁勶級
-        String formalDir = uploadDir + LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE);
-
-        Path formalDirPath = Paths.get(formalDir);
-
-        // 纭繚姝e紡鐩綍瀛樺湪锛堥�掑綊鍒涘缓锛�
-        if (!Files.exists(formalDirPath)) {
-            Files.createDirectories(formalDirPath);
-        }
-
-        for (String tempFileId : tempFileIds) {
-            // 鏌ヨ涓存椂鏂囦欢璁板綍
-            TempFile tempFile = tempFileMapper.selectById(tempFileId);
-            if (tempFile == null) {
-                log.warn("涓存椂鏂囦欢涓嶅瓨鍦紝璺宠繃澶勭悊: {}", tempFileId);
-                continue;
-            }
-
-            // 鏋勫缓姝e紡鏂囦欢鍚嶏紙鍖呭惈涓氬姟ID鍜屾椂闂存埑锛岄伩鍏嶅啿绐侊級
-            String originalFilename = tempFile.getOriginalName();
-            String fileExtension = FilenameUtils.getExtension(originalFilename);
-            String formalFilename = businessId + "_" +
-                    System.currentTimeMillis() + "_" +
-                    UUID.randomUUID().toString().substring(0, 8) +
-                    (StringUtils.hasText(fileExtension) ? "." + fileExtension : "");
-
-            Path formalFilePath = formalDirPath.resolve(formalFilename);
-
-            try {
-                // 鎵ц鏂囦欢杩佺Щ锛堜娇鐢ㄥ師瀛愭搷浣滅‘淇濆畨鍏ㄦ�э級
-//                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锛�
-                CommonFile fileRecord = new CommonFile();
-                fileRecord.setCommonId(businessId);
-                fileRecord.setName(originalFilename);
-                fileRecord.setUrl(formalFilePath.toString());
-                fileRecord.setCreateTime(LocalDateTime.now());
-                fileRecord.setType(fileType);
-                commonFileMapper.insert(fileRecord);
-
-                // 鍒犻櫎涓存椂鏂囦欢璁板綍
-                tempFileMapper.deleteById(tempFile);
-
-                log.info("鏂囦欢杩佺Щ鎴愬姛: {} -> {}", tempFile.getTempPath(), formalFilePath);
-            } catch (IOException e) {
-                log.error("鏂囦欢杩佺Щ澶辫触: {}", tempFile.getTempPath(), e);
-                // 鍙�夋嫨鍥炴粴浜嬪姟鎴栬褰曞け璐ユ枃浠�
-                throw new IOException("鏂囦欢杩佺Щ寮傚父", e);
-            }
-        }
-    }
 }

--
Gitblit v1.9.3