From 104db2c4423867a7fa4f41343213f45985ae3110 Mon Sep 17 00:00:00 2001
From: liu <2021943741@qq.com>
Date: 星期三, 19 八月 2026 18:00:35 +0800
Subject: [PATCH] 补充上传资料上传人上传时间文件附件

---
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pd/document/MesPdDocumentServiceImpl.java |   50 +++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pd/document/MesPdDocumentServiceImpl.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pd/document/MesPdDocumentServiceImpl.java
index d1d8172..18f02e4 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pd/document/MesPdDocumentServiceImpl.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pd/document/MesPdDocumentServiceImpl.java
@@ -1,18 +1,23 @@
 package cn.iocoder.yudao.module.mes.service.pd.document;
 
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.iocoder.yudao.framework.common.pojo.PageResult;
 import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
 import cn.iocoder.yudao.module.mes.controller.admin.pd.document.vo.MesPdDocumentPageReqVO;
 import cn.iocoder.yudao.module.mes.controller.admin.pd.document.vo.MesPdDocumentSaveReqVO;
 import cn.iocoder.yudao.module.mes.dal.dataobject.pd.document.MesPdDocumentDO;
 import cn.iocoder.yudao.module.mes.dal.mysql.pd.document.MesPdDocumentMapper;
 import cn.iocoder.yudao.module.mes.service.pd.project.MesPdProjectService;
 import cn.iocoder.yudao.module.system.api.storage.StorageAttachmentApi;
+import cn.iocoder.yudao.module.system.api.storage.dto.StorageBlobRespDTO;
 import jakarta.annotation.Resource;
 import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.validation.annotation.Validated;
 
+import java.time.LocalDateTime;
 import java.util.List;
 
 import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@@ -21,7 +26,7 @@
 /**
  * MES 璁捐璧勬枡 Service 瀹炵幇绫�
  *
- * @author 鑺嬮亾婧愮爜
+ * @author 瓒呯骇绠$悊鍛�
  */
 @Service
 @Validated
@@ -42,24 +47,40 @@
         projectService.validateProjectExists(createReqVO.getProjectId());
         // 鎻掑叆
         MesPdDocumentDO document = BeanUtils.toBean(createReqVO, MesPdDocumentDO.class);
+        // 琛ュ厖涓婁紶浜恒�佷笂浼犳椂闂�
+        if (document.getUploadUserId() == null) {
+            document.setUploadUserId(SecurityFrameworkUtils.getLoginUserId());
+        }
+        if (document.getUploadTime() == null) {
+            document.setUploadTime(LocalDateTime.now());
+        }
         documentMapper.insert(document);
         storageAttachmentApi.bindAttachments("file", "mes_pd_document",
                 document.getId(), createReqVO.getBlobIds());
+        // 鏈~鍐欐枃浠跺悕鏃讹紝浠庝笂浼犻檮浠惰嚜鍔ㄨˉ鍏�
+        fillFileNameIfAbsent(document);
         return document.getId();
     }
 
     @Override
     public void updateDocument(MesPdDocumentSaveReqVO updateReqVO) {
         // 鏍¢獙瀛樺湪
-        validateDocumentExists(updateReqVO.getId());
+        MesPdDocumentDO existing = validateDocumentExists(updateReqVO.getId());
         // 鏇存柊
         MesPdDocumentDO updateObj = BeanUtils.toBean(updateReqVO, MesPdDocumentDO.class);
-        documentMapper.updateById(updateObj);
-        if (updateReqVO.getBlobIds() != null) {
-            storageAttachmentApi.deleteAttachmentsByRecord("mes_pd_document", updateReqVO.getId());
-            storageAttachmentApi.bindAttachments("file", "mes_pd_document",
-                    updateReqVO.getId(), updateReqVO.getBlobIds());
+        // 淇濈暀鍘熶笂浼犱汉銆佷笂浼犳椂闂达紱鍘嗗彶鏁版嵁涓虹┖鏃惰ˉ榻�
+        if (updateObj.getUploadUserId() == null) {
+            updateObj.setUploadUserId(existing.getUploadUserId() != null
+                    ? existing.getUploadUserId() : SecurityFrameworkUtils.getLoginUserId());
         }
+        if (updateObj.getUploadTime() == null) {
+            updateObj.setUploadTime(existing.getUploadTime() != null
+                    ? existing.getUploadTime() : LocalDateTime.now());
+        }
+        documentMapper.updateById(updateObj);
+        storageAttachmentApi.updateAttachments("file", "mes_pd_document", updateReqVO.getId(), updateReqVO.getBlobIds());
+        // 鏈~鍐欐枃浠跺悕鏃讹紝浠庝笂浼犻檮浠惰嚜鍔ㄨˉ鍏�
+        fillFileNameIfAbsent(updateObj);
     }
 
     @Override
@@ -104,4 +125,19 @@
         return document;
     }
 
+    /**
+     * 鏈~鍐欐枃浠跺悕鏃讹紝浠庝笂浼犻檮浠惰嚜鍔ㄨˉ鍏ㄦ枃浠跺悕
+     *
+     * @param document 璁捐璧勬枡
+     */
+    private void fillFileNameIfAbsent(MesPdDocumentDO document) {
+        if (StrUtil.isNotEmpty(document.getFileName())) {
+            return;
+        }
+        List<StorageBlobRespDTO> attachments = storageAttachmentApi.listAttachments("mes_pd_document", document.getId());
+        if (CollUtil.isNotEmpty(attachments)) {
+            document.setFileName(attachments.get(0).getName());
+            documentMapper.updateById(document);
+        }
+    }
 }

--
Gitblit v1.9.3