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         |   42 ++++++++++++++++++++
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pd/document/vo/MesPdDocumentRespVO.java  |    3 +
 yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pd/document/MesPdDocumentController.java |   16 +++++++
 3 files changed, 59 insertions(+), 2 deletions(-)

diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pd/document/MesPdDocumentController.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pd/document/MesPdDocumentController.java
index d5ef60b..26d88c8 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pd/document/MesPdDocumentController.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pd/document/MesPdDocumentController.java
@@ -1,6 +1,7 @@
 package cn.iocoder.yudao.module.mes.controller.admin.pd.document;
 
 import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
 import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
 import cn.iocoder.yudao.framework.common.pojo.CommonResult;
 import cn.iocoder.yudao.framework.common.pojo.PageParam;
@@ -14,6 +15,7 @@
 import cn.iocoder.yudao.module.mes.dal.dataobject.pd.document.MesPdDocumentDO;
 import cn.iocoder.yudao.module.mes.service.pd.document.MesPdDocumentService;
 import cn.iocoder.yudao.module.system.api.storage.StorageAttachmentApi;
+import cn.iocoder.yudao.module.system.api.storage.dto.StorageBlobRespDTO;
 import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
 import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
 import io.swagger.v3.oas.annotations.Operation;
@@ -117,10 +119,22 @@
         // 1.1 鎵归噺鑾峰彇鍏宠仈鏁版嵁锛堜笂浼犱汉锛�
         Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(convertSet(list, MesPdDocumentDO::getUploadUserId));
         // 2. 鎷兼帴 VO
-        return BeanUtils.toBean(list, MesPdDocumentRespVO.class, vo -> {
+        List<MesPdDocumentRespVO> voList = BeanUtils.toBean(list, MesPdDocumentRespVO.class, vo -> {
             MapUtils.findAndThen(userMap, vo.getUploadUserId(),
                     user -> vo.setUploadUserNickname(user.getNickname()));
         });
+        // 3. 鎷兼帴鏂囦欢淇℃伅锛氫紭鍏堝彇绗竴涓檮浠剁殑鍦板潃浣滀负 fileUrl锛屽苟鍦ㄦ湭濉枃浠跺悕鏃惰嚜鍔ㄨˉ鍏�
+        for (MesPdDocumentRespVO vo : voList) {
+            List<StorageBlobRespDTO> attachments = storageAttachmentApi.listAttachments("mes_pd_document", vo.getId());
+            if (CollUtil.isNotEmpty(attachments)) {
+                StorageBlobRespDTO first = attachments.get(0);
+                vo.setFileUrl(first.getUrl());
+                if (StrUtil.isEmpty(vo.getFileName())) {
+                    vo.setFileName(first.getName());
+                }
+            }
+        }
+        return voList;
     }
 
 }
diff --git a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pd/document/vo/MesPdDocumentRespVO.java b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pd/document/vo/MesPdDocumentRespVO.java
index f462b80..5defe5e 100644
--- a/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pd/document/vo/MesPdDocumentRespVO.java
+++ b/yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pd/document/vo/MesPdDocumentRespVO.java
@@ -41,6 +41,9 @@
     @ExcelProperty("鏂囦欢鍚�")
     private String fileName;
 
+    @Schema(description = "鏂囦欢鍦板潃", example = "https://www.iocoder.cn/design_v1.pdf")
+    private String fileUrl;
+
     @Schema(description = "涓婁紶浜�", example = "1")
     private Long uploadUserId;
 
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 8ef2a53..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;
@@ -42,20 +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);
+        // 淇濈暀鍘熶笂浼犱汉銆佷笂浼犳椂闂达紱鍘嗗彶鏁版嵁涓虹┖鏃惰ˉ榻�
+        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
@@ -100,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