liu
2 天以前 104db2c4423867a7fa4f41343213f45985ae3110
补充上传资料上传人上传时间文件附件
已修改3个文件
61 ■■■■■ 文件已修改
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pd/document/MesPdDocumentController.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/controller/admin/pd/document/vo/MesPdDocumentRespVO.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/pd/document/MesPdDocumentServiceImpl.java 42 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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;
    }
}
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;
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);
        }
    }
}