| | |
| | | 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; |
| | |
| | | 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.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; |
| | |
| | | |
| | | @Resource |
| | | private AdminUserApi adminUserApi; |
| | | @Resource |
| | | private StorageAttachmentApi storageAttachmentApi; |
| | | |
| | | @PostMapping("/create") |
| | | @Operation(summary = "创建设计资料") |
| | |
| | | if (document == null) { |
| | | return success(null); |
| | | } |
| | | return success(buildDocumentRespVOList(Collections.singletonList(document)).get(0)); |
| | | MesPdDocumentRespVO respVO = buildDocumentRespVOList(Collections.singletonList(document)).get(0); |
| | | respVO.setAttachmentList(storageAttachmentApi.listAttachments("mes_pd_document", id)); |
| | | return success(respVO); |
| | | } |
| | | |
| | | @GetMapping("/page") |
| | |
| | | // 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; |
| | | } |
| | | |
| | | } |