|
|
@@ -1,6 +1,9 @@
|
|
|
package com.lingyue.project.attachment.controller;
|
|
|
|
|
|
import com.lingyue.common.core.Result;
|
|
|
+import com.lingyue.common.security.UserContext;
|
|
|
+import com.lingyue.file.dto.FileUploadVO;
|
|
|
+import com.lingyue.file.service.FileStorageService;
|
|
|
import com.lingyue.project.attachment.dto.AttachmentUploadVO;
|
|
|
import com.lingyue.project.attachment.dto.AttachmentVO;
|
|
|
import com.lingyue.project.attachment.service.AttachmentService;
|
|
|
@@ -23,20 +26,24 @@ public class AttachmentController {
|
|
|
|
|
|
private final AttachmentService attachmentService;
|
|
|
private final DocxParseService docxParseService;
|
|
|
+ private final FileStorageService fileStorageService;
|
|
|
|
|
|
@Operation(summary = "上传附件")
|
|
|
@PostMapping("/api/v1/projects/{projectId}/attachments/upload")
|
|
|
public Result<AttachmentUploadVO> upload(@PathVariable Long projectId,
|
|
|
@RequestParam("file") MultipartFile file,
|
|
|
@RequestParam(required = false) String displayName) {
|
|
|
- // TODO: 调用file-service上传文件,获取filePath
|
|
|
+ // 1. 上传文件到文件存储服务
|
|
|
+ Long userId = UserContext.currentUserId();
|
|
|
+ FileUploadVO fileVO = fileStorageService.uploadFile(file, userId);
|
|
|
+
|
|
|
+ // 2. 创建附件记录,使用文件服务返回的 fileKey
|
|
|
String fileName = file.getOriginalFilename();
|
|
|
String fileType = fileName != null && fileName.contains(".")
|
|
|
? fileName.substring(fileName.lastIndexOf(".") + 1) : "unknown";
|
|
|
- String filePath = "/uploads/" + fileName;
|
|
|
|
|
|
AttachmentUploadVO vo = attachmentService.uploadAttachment(
|
|
|
- projectId, displayName, fileName, filePath, fileType, file.getSize());
|
|
|
+ projectId, displayName, fileName, fileVO.getFileKey(), fileType, file.getSize());
|
|
|
return Result.ok(vo);
|
|
|
}
|
|
|
|