1. 升级 3.0.39
新增 FileApi 获取到完整 fileDO 信息接口
This commit is contained in:
@@ -10,10 +10,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
|||||||
import jakarta.validation.Valid;
|
import jakarta.validation.Valid;
|
||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestParam;
|
|
||||||
|
|
||||||
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿:fallbackFactory =
|
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿:fallbackFactory =
|
||||||
@Tag(name = "RPC 服务 - 文件")
|
@Tag(name = "RPC 服务 - 文件")
|
||||||
@@ -25,6 +22,16 @@ public interface FileApi {
|
|||||||
@Operation(summary = "保存文件,并返回文件的访问路径")
|
@Operation(summary = "保存文件,并返回文件的访问路径")
|
||||||
CommonResult<String> createFile(@Valid @RequestBody FileCreateReqDTO createReqDTO);
|
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")
|
CommonResult<FileRespDTO> getFile(@Parameter(description = "文件编号", required = true, example = "1024")
|
||||||
@RequestParam("fileId") @NotNull(message = "文件编号不能为空") Long fileId);
|
@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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.zt.plat.module.infra.api.file;
|
|||||||
import com.zt.plat.framework.common.pojo.CommonResult;
|
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.FileCreateReqDTO;
|
||||||
import com.zt.plat.module.infra.api.file.dto.FileRespDTO;
|
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.dal.dataobject.file.FileDO;
|
||||||
import com.zt.plat.module.infra.service.file.FileService;
|
import com.zt.plat.module.infra.service.file.FileService;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
@@ -24,6 +25,32 @@ public class FileApiImpl implements FileApi {
|
|||||||
createReqDTO.getDirectory(), createReqDTO.getType(), false));
|
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
|
@Override
|
||||||
public CommonResult<FileRespDTO> getFile(Long fileId) {
|
public CommonResult<FileRespDTO> getFile(Long fileId) {
|
||||||
try {
|
try {
|
||||||
@@ -40,24 +67,70 @@ public class FileApiImpl implements FileApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 构建响应对象
|
// 构建响应对象
|
||||||
FileRespDTO respDTO = new FileRespDTO();
|
FileRespDTO respDTO = convertToRespDTO(fileDO);
|
||||||
respDTO.setId(fileDO.getId());
|
|
||||||
respDTO.setName(fileDO.getName());
|
|
||||||
respDTO.setType(fileDO.getType());
|
|
||||||
respDTO.setSize(fileDO.getSize());
|
|
||||||
respDTO.setContent(content);
|
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);
|
return success(respDTO);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return CommonResult.error(500, "获取文件失败:" + e.getMessage());
|
return CommonResult.error(500, "获取文件失败:" + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import cn.hutool.core.io.FileUtil;
|
|||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.crypto.digest.DigestUtil;
|
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.pojo.PageResult;
|
||||||
import com.zt.plat.framework.common.util.object.BeanUtils;
|
import com.zt.plat.framework.common.util.object.BeanUtils;
|
||||||
import com.zt.plat.module.infra.controller.admin.file.vo.file.FileCreateReqVO;
|
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.client.s3.FilePresignedUrlRespDTO;
|
||||||
import com.zt.plat.module.infra.framework.file.core.utils.FileTypeUtils;
|
import com.zt.plat.module.infra.framework.file.core.utils.FileTypeUtils;
|
||||||
import com.zt.plat.module.infra.util.VerificationCodeUtil;
|
import com.zt.plat.module.infra.util.VerificationCodeUtil;
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@@ -122,7 +122,8 @@ public class FileServiceImpl implements FileService {
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public String createFile(byte[] content, String name, String directory, String type, Boolean encrypt) {
|
public String createFile(byte[] content, String name, String directory, String type, Boolean encrypt) {
|
||||||
FileDO entity = uploadFile(content, name, directory, type, encrypt);
|
FileDO entity = uploadFile(content, name, directory, type, encrypt);
|
||||||
return entity.getUrl();
|
FileRespVO fileRespVO = BeanUtils.toBean(entity, FileRespVO.class);
|
||||||
|
return fileRespVO.getUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
|
|||||||
@@ -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.bpm.api.task.BpmTaskApi;
|
||||||
import com.zt.plat.module.infra.api.businessfile.BusinessFileApi;
|
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.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.infra.api.file.dto.FileRespDTO;
|
||||||
import com.zt.plat.module.system.api.dept.DeptApi;
|
import com.zt.plat.module.system.api.dept.DeptApi;
|
||||||
import com.zt.plat.module.template.controller.admin.contract.vo.DemoContractPageReqVO;
|
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')")
|
@PreAuthorize("@ss.hasPermission('template:demo-contract:query')")
|
||||||
public CommonResult<PageResult<DemoContractRespVO>> getDemoContractPage(@Valid DemoContractPageReqVO pageReqVO) {
|
public CommonResult<PageResult<DemoContractRespVO>> getDemoContractPage(@Valid DemoContractPageReqVO pageReqVO) {
|
||||||
CommonResult<FileRespDTO> file = fileApi.getFile(1968928810422521857L);
|
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();
|
Long id = IdWorker.getId();
|
||||||
System.out.println("Generated ID: " + id);
|
System.out.println("Generated ID: " + id);
|
||||||
PageResult<DemoContractDO> pageResult = demoContractService.getDemoContractPage(pageReqVO);
|
PageResult<DemoContractDO> pageResult = demoContractService.getDemoContractPage(pageReqVO);
|
||||||
|
|||||||
Reference in New Issue
Block a user