Merge remote-tracking branch 'base-version/main' into dev

This commit is contained in:
chenbowen
2025-09-26 12:58:31 +08:00
6 changed files with 120 additions and 20 deletions

View File

@@ -32,7 +32,7 @@
<url>https://github.com/YunaiV/ruoyi-vue-pro</url>
<properties>
<revision>3.0.38</revision>
<revision>3.0.39</revision>
<!-- Maven 相关 -->
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>

View File

@@ -26,7 +26,7 @@
<url>https://github.com/YunaiV/ruoyi-vue-pro</url>
<properties>
<revision>3.0.38</revision>
<revision>3.0.39</revision>
<flatten-maven-plugin.version>1.6.0</flatten-maven-plugin.version>
<!-- 统一依赖管理 -->
<spring.boot.version>3.4.5</spring.boot.version>

View File

@@ -10,10 +10,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
@Tag(name = "RPC 服务 - 文件")
@@ -25,6 +22,16 @@ public interface FileApi {
@Operation(summary = "保存文件,并返回文件的访问路径")
CommonResult<String> createFile(@Valid @RequestBody FileCreateReqDTO createReqDTO);
/**
* 创建文件并返回完整文件信息
*
* @param createReqDTO 文件创建请求
* @return 文件完整信息
*/
@PostMapping(PREFIX + "/create-with-return")
@Operation(summary = "创建文件并返回完整文件信息")
CommonResult<FileRespDTO> createFileWithReturn(@Valid @RequestBody FileCreateReqDTO createReqDTO);
/**
* 根据文件编号获取文件信息和二进制内容
*
@@ -36,4 +43,15 @@ public interface FileApi {
CommonResult<FileRespDTO> getFile(@Parameter(description = "文件编号", required = true, example = "1024")
@RequestParam("fileId") @NotNull(message = "文件编号不能为空") Long fileId);
/**
* 删除文件
*
* @param fileId 文件编号
* @return 删除结果
*/
@DeleteMapping(PREFIX + "/delete")
@Operation(summary = "删除文件")
CommonResult<Boolean> deleteFile(@Parameter(description = "文件编号", required = true, example = "1024")
@RequestParam("fileId") @NotNull(message = "文件编号不能为空") Long fileId);
}

View File

@@ -3,6 +3,7 @@ package com.zt.plat.module.infra.api.file;
import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.module.infra.api.file.dto.FileCreateReqDTO;
import com.zt.plat.module.infra.api.file.dto.FileRespDTO;
import com.zt.plat.module.infra.controller.admin.file.vo.file.FileRespVO;
import com.zt.plat.module.infra.dal.dataobject.file.FileDO;
import com.zt.plat.module.infra.service.file.FileService;
import jakarta.annotation.Resource;
@@ -24,6 +25,32 @@ public class FileApiImpl implements FileApi {
createReqDTO.getDirectory(), createReqDTO.getType(), false));
}
@Override
public CommonResult<FileRespDTO> createFileWithReturn(FileCreateReqDTO createReqDTO) {
try {
FileRespVO fileRespVO = fileService.createFileWhitReturn(
createReqDTO.getContent(),
createReqDTO.getName(),
createReqDTO.getDirectory(),
createReqDTO.getType(),
false
);
if (fileRespVO == null) {
return CommonResult.error(500, "文件创建失败");
}
// 将 FileRespVO 转换为 FileRespDTO
FileRespDTO respDTO = convertToRespDTO(fileRespVO);
// 设置文件内容
respDTO.setContent(createReqDTO.getContent());
return success(respDTO);
} catch (Exception e) {
return CommonResult.error(500, "创建文件失败:" + e.getMessage());
}
}
@Override
public CommonResult<FileRespDTO> getFile(Long fileId) {
try {
@@ -40,19 +67,8 @@ public class FileApiImpl implements FileApi {
}
// 构建响应对象
FileRespDTO respDTO = new FileRespDTO();
respDTO.setId(fileDO.getId());
respDTO.setName(fileDO.getName());
respDTO.setType(fileDO.getType());
respDTO.setSize(fileDO.getSize());
FileRespDTO respDTO = convertToRespDTO(fileDO);
respDTO.setContent(content);
// 从文件路径或URL中提取目录信息
String path = fileDO.getPath();
if (path != null && path.contains("/")) {
String directory = path.substring(0, path.lastIndexOf("/"));
respDTO.setDirectory(directory);
}
return success(respDTO);
} catch (Exception e) {
@@ -60,4 +76,61 @@ public class FileApiImpl implements FileApi {
}
}
@Override
public CommonResult<Boolean> deleteFile(Long fileId) {
try {
// 检查文件是否存在
FileDO fileDO = fileService.getActiveFileById(fileId);
if (fileDO == null) {
return CommonResult.error(404, "文件不存在");
}
// 删除文件
fileService.deleteFile(fileId);
return success(true);
} catch (Exception e) {
return CommonResult.error(500, "删除文件失败:" + e.getMessage());
}
}
/**
* 将 FileDO 转换为 FileRespDTO
*/
private FileRespDTO convertToRespDTO(FileDO fileDO) {
FileRespDTO respDTO = new FileRespDTO();
respDTO.setId(fileDO.getId());
respDTO.setName(fileDO.getName());
respDTO.setType(fileDO.getType());
respDTO.setSize(fileDO.getSize());
// 从文件路径中提取目录信息
String path = fileDO.getPath();
if (path != null && path.contains("/")) {
String directory = path.substring(0, path.lastIndexOf("/"));
respDTO.setDirectory(directory);
}
return respDTO;
}
/**
* 将 FileRespVO 转换为 FileRespDTO
*/
private FileRespDTO convertToRespDTO(FileRespVO fileRespVO) {
FileRespDTO respDTO = new FileRespDTO();
respDTO.setId(fileRespVO.getId());
respDTO.setName(fileRespVO.getName());
respDTO.setType(fileRespVO.getType());
respDTO.setSize(fileRespVO.getSize());
// 从文件路径中提取目录信息
String path = fileRespVO.getPath();
if (path != null && path.contains("/")) {
String directory = path.substring(0, path.lastIndexOf("/"));
respDTO.setDirectory(directory);
}
return respDTO;
}
}

View File

@@ -5,6 +5,7 @@ import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.DigestUtil;
import com.google.common.annotations.VisibleForTesting;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.module.infra.controller.admin.file.vo.file.FileCreateReqVO;
@@ -18,7 +19,6 @@ import com.zt.plat.module.infra.framework.file.core.client.FileClient;
import com.zt.plat.module.infra.framework.file.core.client.s3.FilePresignedUrlRespDTO;
import com.zt.plat.module.infra.framework.file.core.utils.FileTypeUtils;
import com.zt.plat.module.infra.util.VerificationCodeUtil;
import com.google.common.annotations.VisibleForTesting;
import jakarta.annotation.Resource;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
@@ -122,7 +122,8 @@ public class FileServiceImpl implements FileService {
@SneakyThrows
public String createFile(byte[] content, String name, String directory, String type, Boolean encrypt) {
FileDO entity = uploadFile(content, name, directory, type, encrypt);
return entity.getUrl();
FileRespVO fileRespVO = BeanUtils.toBean(entity, FileRespVO.class);
return fileRespVO.getUrl();
}
@SneakyThrows

View File

@@ -15,6 +15,7 @@ import com.zt.plat.module.bpm.api.task.BpmProcessInstanceApi;
import com.zt.plat.module.bpm.api.task.BpmTaskApi;
import com.zt.plat.module.infra.api.businessfile.BusinessFileApi;
import com.zt.plat.module.infra.api.file.FileApi;
import com.zt.plat.module.infra.api.file.dto.FileCreateReqDTO;
import com.zt.plat.module.infra.api.file.dto.FileRespDTO;
import com.zt.plat.module.system.api.dept.DeptApi;
import com.zt.plat.module.template.controller.admin.contract.vo.DemoContractPageReqVO;
@@ -114,6 +115,13 @@ public class DemoContractController extends AbstractFileUploadController impleme
@PreAuthorize("@ss.hasPermission('template:demo-contract:query')")
public CommonResult<PageResult<DemoContractRespVO>> getDemoContractPage(@Valid DemoContractPageReqVO pageReqVO) {
CommonResult<FileRespDTO> file = fileApi.getFile(1968928810422521857L);
FileCreateReqDTO createReqDTO = new FileCreateReqDTO();
createReqDTO.setContent(file.getCheckedData().getContent());
createReqDTO.setType(file.getCheckedData().getType());
createReqDTO.setName(file.getCheckedData().getName());
createReqDTO.setDirectory(file.getCheckedData().getDirectory());
CommonResult<FileRespDTO> fileWithReturn = fileApi.createFileWithReturn(createReqDTO);
Long id = IdWorker.getId();
System.out.println("Generated ID: " + id);
PageResult<DemoContractDO> pageResult = demoContractService.getDemoContractPage(pageReqVO);